From 76e10b96fc67b919e17d984b460ea780e122ffdd Mon Sep 17 00:00:00 2001 From: kimkulling Date: Wed, 9 Mar 2022 10:51:37 +0100 Subject: [PATCH 1/2] Fix missing members and do some small refactorings. --- code/AssetLib/FBX/FBXDocument.cpp | 125 ++++++++---------------------- code/AssetLib/FBX/FBXDocument.h | 52 ++++++------- code/AssetLib/FBX/FBXMaterial.cpp | 23 +++++- code/AssetLib/FBX/FBXModel.cpp | 5 -- 4 files changed, 76 insertions(+), 129 deletions(-) diff --git a/code/AssetLib/FBX/FBXDocument.cpp b/code/AssetLib/FBX/FBXDocument.cpp index f228b1749..b49ee625a 100644 --- a/code/AssetLib/FBX/FBXDocument.cpp +++ b/code/AssetLib/FBX/FBXDocument.cpp @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -68,23 +67,13 @@ namespace FBX { using namespace Util; // ------------------------------------------------------------------------------------------------ -LazyObject::LazyObject(uint64_t id, const Element& element, const Document& doc) -: doc(doc) -, element(element) -, id(id) -, flags() { +LazyObject::LazyObject(uint64_t id, const Element& element, const Document& doc) : + doc(doc), element(element), id(id), flags() { // empty } // ------------------------------------------------------------------------------------------------ -LazyObject::~LazyObject() -{ - // empty -} - -// ------------------------------------------------------------------------------------------------ -const Object* LazyObject::Get(bool dieOnError) -{ +const Object* LazyObject::Get(bool dieOnError) { if(IsBeingConstructed() || FailedToConstruct()) { return nullptr; } @@ -234,17 +223,8 @@ const Object* LazyObject::Get(bool dieOnError) } // ------------------------------------------------------------------------------------------------ -Object::Object(uint64_t id, const Element& element, const std::string& name) -: element(element) -, name(name) -, id(id) -{ - // empty -} - -// ------------------------------------------------------------------------------------------------ -Object::~Object() -{ +Object::Object(uint64_t id, const Element& element, const std::string& name) : + element(element), name(name), id(id) { // empty } @@ -255,16 +235,8 @@ FileGlobalSettings::FileGlobalSettings(const Document &doc, std::shared_ptrCompound() ) { @@ -370,8 +340,7 @@ void Document::ReadGlobalSettings() } // ------------------------------------------------------------------------------------------------ -void Document::ReadObjects() -{ +void Document::ReadObjects() { // read ID objects from "Objects" section const Scope& sc = parser.GetRootScope(); const Element* const eobjects = sc["Objects"]; @@ -418,8 +387,7 @@ void Document::ReadObjects() } // ------------------------------------------------------------------------------------------------ -void Document::ReadPropertyTemplates() -{ +void Document::ReadPropertyTemplates() { const Scope& sc = parser.GetRootScope(); // read property templates from "Definitions" section const Element* const edefs = sc["Definitions"]; @@ -476,8 +444,7 @@ void Document::ReadPropertyTemplates() } // ------------------------------------------------------------------------------------------------ -void Document::ReadConnections() -{ +void Document::ReadConnections() { const Scope& sc = parser.GetRootScope(); // read property templates from "Definitions" section const Element* const econns = sc["Connections"]; @@ -524,8 +491,7 @@ void Document::ReadConnections() } // ------------------------------------------------------------------------------------------------ -const std::vector& Document::AnimationStacks() const -{ +const std::vector& Document::AnimationStacks() const { if (!animationStacksResolved.empty() || animationStacks.empty()) { return animationStacksResolved; } @@ -545,17 +511,15 @@ const std::vector& Document::AnimationStacks() const } // ------------------------------------------------------------------------------------------------ -LazyObject* Document::GetObject(uint64_t id) const -{ +LazyObject* Document::GetObject(uint64_t id) const { ObjectMap::const_iterator it = objects.find(id); return it == objects.end() ? nullptr : (*it).second; } -#define MAX_CLASSNAMES 6 +constexpr size_t MAX_CLASSNAMES = 6; // ------------------------------------------------------------------------------------------------ -std::vector Document::GetConnectionsSequenced(uint64_t id, const ConnectionMap& conns) const -{ +std::vector Document::GetConnectionsSequenced(uint64_t id, const ConnectionMap& conns) const { std::vector temp; const std::pair range = @@ -573,11 +537,9 @@ std::vector Document::GetConnectionsSequenced(uint64_t id, co // ------------------------------------------------------------------------------------------------ std::vector Document::GetConnectionsSequenced(uint64_t id, bool is_src, - const ConnectionMap& conns, - const char* const* classnames, - size_t count) const - -{ + const ConnectionMap& conns, + const char* const* classnames, + size_t count) const { ai_assert(classnames); ai_assert( count != 0 ); ai_assert( count <= MAX_CLASSNAMES); @@ -622,95 +584,72 @@ std::vector Document::GetConnectionsSequenced(uint64_t id, bo } // ------------------------------------------------------------------------------------------------ -std::vector Document::GetConnectionsBySourceSequenced(uint64_t source) const -{ +std::vector Document::GetConnectionsBySourceSequenced(uint64_t source) const { return GetConnectionsSequenced(source, ConnectionsBySource()); } // ------------------------------------------------------------------------------------------------ -std::vector Document::GetConnectionsBySourceSequenced(uint64_t src, const char* classname) const -{ +std::vector Document::GetConnectionsBySourceSequenced(uint64_t src, const char* classname) const { const char* arr[] = {classname}; return GetConnectionsBySourceSequenced(src, arr,1); } // ------------------------------------------------------------------------------------------------ std::vector Document::GetConnectionsBySourceSequenced(uint64_t source, - const char* const* classnames, size_t count) const -{ + const char* const* classnames, size_t count) const { return GetConnectionsSequenced(source, true, ConnectionsBySource(),classnames, count); } // ------------------------------------------------------------------------------------------------ std::vector Document::GetConnectionsByDestinationSequenced(uint64_t dest, - const char* classname) const -{ + const char* classname) const { const char* arr[] = {classname}; return GetConnectionsByDestinationSequenced(dest, arr,1); } // ------------------------------------------------------------------------------------------------ -std::vector Document::GetConnectionsByDestinationSequenced(uint64_t dest) const -{ +std::vector Document::GetConnectionsByDestinationSequenced(uint64_t dest) const { return GetConnectionsSequenced(dest, ConnectionsByDestination()); } // ------------------------------------------------------------------------------------------------ std::vector Document::GetConnectionsByDestinationSequenced(uint64_t dest, - const char* const* classnames, size_t count) const - -{ + const char* const* classnames, size_t count) const { return GetConnectionsSequenced(dest, false, ConnectionsByDestination(),classnames, count); } // ------------------------------------------------------------------------------------------------ Connection::Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop, - const Document& doc) - -: insertionOrder(insertionOrder) -, prop(prop) -, src(src) -, dest(dest) -, doc(doc) -{ + const Document& doc) : + insertionOrder(insertionOrder), prop(prop), src(src), dest(dest), doc(doc) { ai_assert(doc.Objects().find(src) != doc.Objects().end()); // dest may be 0 (root node) ai_assert(!dest || doc.Objects().find(dest) != doc.Objects().end()); } // ------------------------------------------------------------------------------------------------ -Connection::~Connection() -{ - // empty -} - -// ------------------------------------------------------------------------------------------------ -LazyObject& Connection::LazySourceObject() const -{ +LazyObject& Connection::LazySourceObject() const { LazyObject* const lazy = doc.GetObject(src); ai_assert(lazy); return *lazy; } // ------------------------------------------------------------------------------------------------ -LazyObject& Connection::LazyDestinationObject() const -{ +LazyObject& Connection::LazyDestinationObject() const { LazyObject* const lazy = doc.GetObject(dest); ai_assert(lazy); return *lazy; } // ------------------------------------------------------------------------------------------------ -const Object* Connection::SourceObject() const -{ +const Object* Connection::SourceObject() const { LazyObject* const lazy = doc.GetObject(src); ai_assert(lazy); return lazy->Get(); } // ------------------------------------------------------------------------------------------------ -const Object* Connection::DestinationObject() const -{ +const Object* Connection::DestinationObject() const { LazyObject* const lazy = doc.GetObject(dest); ai_assert(lazy); return lazy->Get(); @@ -719,4 +658,4 @@ const Object* Connection::DestinationObject() const } // !FBX } // !Assimp -#endif +#endif // ASSIMP_BUILD_NO_FBX_IMPORTER diff --git a/code/AssetLib/FBX/FBXDocument.h b/code/AssetLib/FBX/FBXDocument.h index bac7e7769..04da83c06 100644 --- a/code/AssetLib/FBX/FBXDocument.h +++ b/code/AssetLib/FBX/FBXDocument.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -89,7 +88,7 @@ class LazyObject { public: LazyObject(uint64_t id, const Element& element, const Document& doc); - ~LazyObject(); + ~LazyObject() = default; const Object* Get(bool dieOnError = false); @@ -139,7 +138,7 @@ class Object { public: Object(uint64_t id, const Element& element, const std::string& name); - virtual ~Object(); + virtual ~Object() = default; const Element& SourceElement() const { return element; @@ -267,8 +266,7 @@ public: Light(uint64_t id, const Element& element, const Document& doc, const std::string& name); virtual ~Light(); - enum Type - { + enum Type { Type_Point, Type_Directional, Type_Spot, @@ -278,8 +276,7 @@ public: Type_MAX // end-of-enum sentinel }; - enum Decay - { + enum Decay { Decay_None, Decay_Linear, Decay_Quadratic, @@ -578,31 +575,27 @@ public: BlendMode_BlendModeCount }; - const Texture* getTexture(int index=0) const - { + const Texture* getTexture(int index=0) const { return textures[index]; - } int textureCount() const { return static_cast(textures.size()); } - BlendMode GetBlendMode() const - { + BlendMode GetBlendMode() const { return blendMode; } - float Alpha() - { + float Alpha() { return alpha; } + private: std::vector textures; BlendMode blendMode; float alpha; }; -typedef std::fbx_unordered_map TextureMap; -typedef std::fbx_unordered_map LayeredTextureMap; - +using TextureMap = std::fbx_unordered_map; +using LayeredTextureMap = std::fbx_unordered_map; /** DOM class for generic FBX videos */ class Video : public Object { @@ -690,8 +683,8 @@ private: LayeredTextureMap layeredTextures; }; -typedef std::vector KeyTimeList; -typedef std::vector KeyValueList; +using KeyTimeList = std::vector; +using KeyValueList = std::vector; /** Represents a FBX animation curve (i.e. a 1-dimensional set of keyframes and values therefore) */ class AnimationCurve : public Object { @@ -727,7 +720,7 @@ private: }; // property-name -> animation curve -typedef std::map AnimationCurveMap; +using AnimationCurveMap = std::map; /** Represents a FBX animation curve (i.e. a mapping from single animation curves to nodes) */ class AnimationCurveNode : public Object { @@ -777,7 +770,7 @@ private: const Document& doc; }; -typedef std::vector AnimationCurveNodeList; +using AnimationCurveNodeList = std::vector; /** Represents a FBX animation layer (i.e. a list of node animations) */ class AnimationLayer : public Object { @@ -800,7 +793,7 @@ private: const Document& doc; }; -typedef std::vector AnimationLayerList; +using AnimationLayerList = std::vector; /** Represents a FBX animation stack (i.e. a list of animation layers) */ class AnimationStack : public Object { @@ -843,8 +836,8 @@ private: std::shared_ptr props; }; -typedef std::vector WeightArray; -typedef std::vector WeightIndexArray; +using WeightArray = std::vector; +using WeightIndexArray = std::vector; /** DOM class for BlendShapeChannel deformers */ @@ -956,7 +949,7 @@ class Connection { public: Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop, const Document& doc); - ~Connection(); + ~Connection() = default; // note: a connection ensures that the source and dest objects exist, but // not that they have DOM representations, so the return value of one of @@ -1011,10 +1004,9 @@ public: // during their entire lifetime (Document). FBX files have // up to many thousands of objects (most of which we never use), // so the memory overhead for them should be kept at a minimum. -typedef std::fbx_unordered_map ObjectMap; -typedef std::fbx_unordered_map > PropertyTemplateMap; - -typedef std::fbx_unordered_multimap ConnectionMap; +using ObjectMap = std::fbx_unordered_map ; +using PropertyTemplateMap = std::fbx_unordered_map > ; +using ConnectionMap = std::fbx_unordered_multimap; /** DOM class for global document settings, a single instance per document can * be accessed via Document.Globals(). */ @@ -1022,7 +1014,7 @@ class FileGlobalSettings { public: FileGlobalSettings(const Document& doc, std::shared_ptr props); - ~FileGlobalSettings(); + ~FileGlobalSettings() = default; const PropertyTable& Props() const { ai_assert(props.get()); diff --git a/code/AssetLib/FBX/FBXMaterial.cpp b/code/AssetLib/FBX/FBXMaterial.cpp index 8849179f3..2162670f8 100644 --- a/code/AssetLib/FBX/FBXMaterial.cpp +++ b/code/AssetLib/FBX/FBXMaterial.cpp @@ -140,11 +140,32 @@ Material::~Material() { // empty } + aiVector2D uvTrans; + aiVector2D uvScaling; + ai_real uvRotation; + + std::string type; + std::string relativeFileName; + std::string fileName; + std::string alphaSource; + std::shared_ptr props; + + unsigned int crop[4]{}; + + const Video* media; + // ------------------------------------------------------------------------------------------------ Texture::Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name) : Object(id,element,name), + uvTrans(0.0f, 0.0f), uvScaling(1.0f,1.0f), - media(0) { + uvRotation(0.0f), + type(), + relativeFileName(), + fileName(), + alphaSource(), + props(), + media(nullptr) { const Scope& sc = GetRequiredScope(element); const Element* const Type = sc["Type"]; diff --git a/code/AssetLib/FBX/FBXModel.cpp b/code/AssetLib/FBX/FBXModel.cpp index 9fe4cd5f8..d731d2e29 100644 --- a/code/AssetLib/FBX/FBXModel.cpp +++ b/code/AssetLib/FBX/FBXModel.cpp @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2022, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -76,10 +75,6 @@ Model::Model(uint64_t id, const Element &element, const Document &doc, const std ResolveLinks(element, doc); } -// ------------------------------------------------------------------------------------------------ -Model::~Model() { -} - // ------------------------------------------------------------------------------------------------ void Model::ResolveLinks(const Element&, const Document &doc) { const char *const arr[] = { "Geometry", "Material", "NodeAttribute" }; From 26598dc6bdf11ebf1328c0907461b8da1dde8571 Mon Sep 17 00:00:00 2001 From: kimkulling Date: Wed, 9 Mar 2022 11:00:05 +0100 Subject: [PATCH 2/2] Forget to save file. --- code/AssetLib/FBX/FBXDocument.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/FBX/FBXDocument.h b/code/AssetLib/FBX/FBXDocument.h index 04da83c06..c61a47410 100644 --- a/code/AssetLib/FBX/FBXDocument.h +++ b/code/AssetLib/FBX/FBXDocument.h @@ -344,7 +344,7 @@ public: Model(uint64_t id, const Element& element, const Document& doc, const std::string& name); - virtual ~Model(); + virtual ~Model() = default; fbx_simple_property(QuaternionInterpolate, int, 0)