diff options
author | Gordon MacPherson <gordon@gordonite.tech> | 2021-03-30 02:33:06 +0100 |
---|---|---|
committer | Gordon MacPherson <gordon@gordonite.tech> | 2021-04-15 05:54:50 +0100 |
commit | 061b77e5e6c6e3f446734bf214e395e7e6f1a4b4 (patch) | |
tree | 809e3660221e0bc6d9bb119d0fa8591c3bbdb233 /modules/fbx/fbx_parser/FBXDocument.h | |
parent | a86e7c3bb7d9238e664be8a7c63d1cc19bde0d8c (diff) |
This stops using FBXPropertyTable as a pointer.
The base object will inherit the property table, for every FBX object, if it doesn't exist it will be ignored.
The previous code was dangerous and not simple to understand, this makes the code simpler and should result in no leaks with PropertyTable.
Features/Fixes:
Adds ability for multiple millions of polygons to be loaded.
Fixes memory leaks with tokens
Fixes memory leaks with property table
Fixes loading some corrupt files
Fixes meshes not having a unique name to the mesh node.
Opens up loading for two more versions: 7100 and 7200, up to 2020.
Preliminary support for Cinema4D files in parser now, before this was not possible it would cause memory corruption, which is gone now.
FBXProperties not being pointers presented simpler challenges in the long run also, fixed a bunch of bugs.
Diffstat (limited to 'modules/fbx/fbx_parser/FBXDocument.h')
-rw-r--r-- | modules/fbx/fbx_parser/FBXDocument.h | 125 |
1 files changed, 29 insertions, 96 deletions
diff --git a/modules/fbx/fbx_parser/FBXDocument.h b/modules/fbx/fbx_parser/FBXDocument.h index 20e635a6a4..49b7c11c31 100644 --- a/modules/fbx/fbx_parser/FBXDocument.h +++ b/modules/fbx/fbx_parser/FBXDocument.h @@ -130,7 +130,7 @@ private: }; /** Base class for in-memory (DOM) representations of FBX objects */ -class Object { +class Object : public PropertyTable { public: Object(uint64_t id, const ElementPtr element, const std::string &name); @@ -149,9 +149,9 @@ public: } protected: - const ElementPtr element; + const ElementPtr element = nullptr; const std::string name; - const uint64_t id = 0; + const uint64_t id; }; /** DOM class for generic FBX NoteAttribute blocks. NoteAttribute's just hold a property table, @@ -159,22 +159,13 @@ protected: class NodeAttribute : public Object { public: NodeAttribute(uint64_t id, const ElementPtr element, const Document &doc, const std::string &name); - virtual ~NodeAttribute(); - - const PropertyTable *Props() const { - return props; - } - -private: - const PropertyTable *props; }; /** DOM base class for FBX camera settings attached to a node */ class CameraSwitcher : public NodeAttribute { public: CameraSwitcher(uint64_t id, const ElementPtr element, const Document &doc, const std::string &name); - virtual ~CameraSwitcher(); int CameraID() const { @@ -190,26 +181,26 @@ public: } private: - int cameraId; + int cameraId = 0; std::string cameraName; std::string cameraIndexName; }; #define fbx_stringize(a) #a -#define fbx_simple_property(name, type, default_value) \ - type name() const { \ - return PropertyGet<type>(Props(), fbx_stringize(name), (default_value)); \ +#define fbx_simple_property(name, type, default_value) \ + type name() const { \ + return PropertyGet<type>(this, fbx_stringize(name), (default_value)); \ } // XXX improve logging -#define fbx_simple_enum_property(name, type, default_value) \ - type name() const { \ - const int ival = PropertyGet<int>(Props(), fbx_stringize(name), static_cast<int>(default_value)); \ - if (ival < 0 || ival >= AI_CONCAT(type, _MAX)) { \ - return static_cast<type>(default_value); \ - } \ - return static_cast<type>(ival); \ +#define fbx_simple_enum_property(name, type, default_value) \ + type name() const { \ + const int ival = PropertyGet<int>(this, fbx_stringize(name), static_cast<int>(default_value)); \ + if (ival < 0 || ival >= AI_CONCAT(type, _MAX)) { \ + return static_cast<type>(default_value); \ + } \ + return static_cast<type>(ival); \ } class FbxPoseNode; @@ -256,7 +247,7 @@ public: } private: - uint64_t target_id; + uint64_t target_id = 0; Transform transform; }; @@ -264,7 +255,6 @@ private: class Camera : public NodeAttribute { public: Camera(uint64_t id, const ElementPtr element, const Document &doc, const std::string &name); - virtual ~Camera(); fbx_simple_property(Position, Vector3, Vector3(0, 0, 0)); @@ -380,7 +370,6 @@ public: }; Model(uint64_t id, const ElementPtr element, const Document &doc, const std::string &name); - virtual ~Model(); fbx_simple_property(QuaternionInterpolate, int, 0); @@ -466,10 +455,6 @@ public: return culling; } - const PropertyTable *Props() const { - return props; - } - /** Get material links */ const std::vector<const Material *> &GetMaterials() const { return materials; @@ -498,13 +483,11 @@ private: std::string shading; std::string culling; - const PropertyTable *props = nullptr; }; class ModelLimbNode : public Model { public: ModelLimbNode(uint64_t id, const ElementPtr element, const Document &doc, const std::string &name); - virtual ~ModelLimbNode(); }; @@ -512,7 +495,6 @@ public: class Texture : public Object { public: Texture(uint64_t id, const ElementPtr element, const Document &doc, const std::string &name); - virtual ~Texture(); const std::string &Type() const { @@ -539,10 +521,6 @@ public: return uvScaling; } - const PropertyTable *Props() const { - return props; - } - // return a 4-tuple const unsigned int *Crop() const { return crop; @@ -560,10 +538,8 @@ private: std::string relativeFileName; std::string fileName; std::string alphaSource; - const PropertyTable *props = nullptr; unsigned int crop[4] = { 0 }; - const Video *media = nullptr; }; @@ -626,8 +602,8 @@ public: private: std::vector<const Texture *> textures; - BlendMode blendMode; - float alpha; + BlendMode blendMode = BlendMode::BlendMode_Additive; + float alpha = 0; }; typedef std::map<std::string, const Texture *> TextureMap; @@ -656,10 +632,6 @@ public: return relativeFileName; } - const PropertyTable *Props() const { - return props; - } - const uint8_t *Content() const { return content; } @@ -687,7 +659,6 @@ private: std::string type; std::string relativeFileName; std::string fileName; - const PropertyTable *props = nullptr; uint64_t contentLength = 0; uint8_t *content = nullptr; @@ -708,10 +679,6 @@ public: return multilayer; } - const PropertyTable *Props() const { - return props; - } - const TextureMap &Textures() const { return textures; } @@ -722,8 +689,7 @@ public: private: std::string shading; - bool multilayer; - const PropertyTable *props; + bool multilayer = false; TextureMap textures; LayeredTextureMap layeredTextures; @@ -791,10 +757,6 @@ public: virtual ~AnimationCurveNode(); - const PropertyTable *Props() const { - return props; - } - const AnimationMap &Curves() const; /** Object the curve is assigned to, this can be NULL if the @@ -819,7 +781,6 @@ public: private: Object *target = nullptr; - const PropertyTable *props; mutable AnimationMap curves; std::string prop; const Document &doc; @@ -837,18 +798,12 @@ public: AnimationLayer(uint64_t id, const ElementPtr element, const std::string &name, const Document &doc); virtual ~AnimationLayer(); - const PropertyTable *Props() const { - //ai_assert(props.get()); - return props; - } - /* the optional white list specifies a list of property names for which the caller wants animations for. Curves not matching this list will not be added to the animation layer. */ const AnimationCurveNodeList Nodes(const char *const *target_prop_whitelist = nullptr, size_t whitelist_size = 0) const; private: - const PropertyTable *props; const Document &doc; }; @@ -863,16 +818,11 @@ public: fbx_simple_property(ReferenceStart, int64_t, 0L); fbx_simple_property(ReferenceStop, int64_t, 0L); - const PropertyTable *Props() const { - return props; - } - const AnimationLayerList &Layers() const { return layers; } private: - const PropertyTable *props = nullptr; AnimationLayerList layers; }; @@ -881,14 +831,6 @@ class Deformer : public Object { public: Deformer(uint64_t id, const ElementPtr element, const Document &doc, const std::string &name); virtual ~Deformer(); - - const PropertyTable *Props() const { - //ai_assert(props.get()); - return props; - } - -private: - const PropertyTable *props; }; /** Constraints are from Maya they can help us with BoneAttachments :) **/ @@ -896,9 +838,6 @@ class Constraint : public Object { public: Constraint(uint64_t id, const ElementPtr element, const Document &doc, const std::string &name); virtual ~Constraint(); - -private: - const PropertyTable *props; }; typedef std::vector<float> WeightArray; @@ -924,7 +863,7 @@ public: } private: - float percent; + float percent = 0; WeightArray fullWeights; std::vector<const ShapeGeometry *> shapeGeometries; }; @@ -1006,7 +945,7 @@ private: Transform transformLink; Transform transformAssociateModel; SkinLinkMode link_mode; - bool valid_transformAssociateModel; + bool valid_transformAssociateModel = false; const Model *node = nullptr; }; @@ -1037,8 +976,8 @@ public: } private: - float accuracy; - SkinType skinType; + float accuracy = 0; + SkinType skinType = SkinType::Skin_Linear; std::vector<const Cluster *> clusters; }; @@ -1087,10 +1026,10 @@ public: } public: - uint64_t insertionOrder; + uint64_t insertionOrder = 0; const std::string prop; - uint64_t src, dest; + uint64_t src = 0, dest = 0; const Document &doc; }; @@ -1105,15 +1044,10 @@ typedef std::multimap<uint64_t, const Connection *> ConnectionMap; /** DOM class for global document settings, a single instance per document can * be accessed via Document.Globals(). */ -class FileGlobalSettings { +class FileGlobalSettings : public PropertyTable { public: - FileGlobalSettings(const Document &doc, const PropertyTable *props); - - ~FileGlobalSettings(); - - const PropertyTable *Props() const { - return props; - } + FileGlobalSettings(const Document &doc); + virtual ~FileGlobalSettings(); const Document &GetDocument() const { return doc; @@ -1158,7 +1092,6 @@ public: fbx_simple_property(CustomFrameRate, float, -1.0f); private: - const PropertyTable *props = nullptr; const Document &doc; }; @@ -1196,7 +1129,7 @@ public: return globals.get(); } - const PropertyTable *GetMetadataProperties() const { + const PropertyTable &GetMetadataProperties() const { return metadata_properties; } @@ -1293,7 +1226,7 @@ private: std::vector<uint64_t> materials; std::vector<uint64_t> skins; mutable std::vector<const AnimationStack *> animationStacksResolved; - PropertyTable *metadata_properties = nullptr; + PropertyTable metadata_properties; std::shared_ptr<FileGlobalSettings> globals = nullptr; }; } // namespace FBXDocParser |