From 37be87b0bda5eba3f9b1967f3aa29a857da8b0cb Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 19 Apr 2022 23:37:16 +0200 Subject: [PATCH] Some minor findings --- code/AssetLib/FBX/FBXCommon.h | 3 ++- code/AssetLib/FBX/FBXCompileConfig.h | 1 - code/AssetLib/FBX/FBXConverter.cpp | 33 +++++++++++++++++---------- code/AssetLib/FBX/FBXDeformer.cpp | 7 ++---- code/AssetLib/FBX/FBXDocumentUtil.h | 12 ++++------ code/AssetLib/FBX/FBXExporter.cpp | 2 +- code/AssetLib/FBX/FBXMeshGeometry.cpp | 24 ++++--------------- code/AssetLib/FBX/FBXMeshGeometry.h | 20 ++++++++-------- code/AssetLib/FBX/FBXParser.cpp | 12 ---------- code/AssetLib/FBX/FBXParser.h | 4 ++-- 10 files changed, 48 insertions(+), 70 deletions(-) diff --git a/code/AssetLib/FBX/FBXCommon.h b/code/AssetLib/FBX/FBXCommon.h index ec7459c9e..c592c5649 100644 --- a/code/AssetLib/FBX/FBXCommon.h +++ b/code/AssetLib/FBX/FBXCommon.h @@ -50,7 +50,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { namespace FBX { -const std::string NULL_RECORD = { // 25 null bytes in 64-bit and 13 null bytes in 32-bit +static constexpr size_t NumNullRecords = 25; +const char NULL_RECORD[NumNullRecords] = { // 25 null bytes in 64-bit and 13 null bytes in 32-bit '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; // who knows why, it looks like two integers 32/64 bit (compressed and uncompressed sizes?) + 1 byte (might be compression type?) diff --git a/code/AssetLib/FBX/FBXCompileConfig.h b/code/AssetLib/FBX/FBXCompileConfig.h index 75787d303..927a3c5f6 100644 --- a/code/AssetLib/FBX/FBXCompileConfig.h +++ b/code/AssetLib/FBX/FBXCompileConfig.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, diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index c79d43cbf..e8cfe1dc0 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -1439,9 +1439,20 @@ void ConvertWeightsToSkeleton(const MeshGeometry &geo, const aiMatrix4x4 &absolu std::vector *outputVertStartIndices) { ai_assert(geo.DeformerSkin() != nullptr); + aiSkeleton *skeleton = new aiSkeleton; const Skin &sk = *geo.DeformerSkin(); - for (auto &cluster : sk.Clusters()) { - cluster->Transform(); + try { + for (auto &cluster : sk.Clusters()) { + const WeightIndexArray &indices = cluster->GetIndices(); + const MatIndexArray &mats = geo.GetMaterialIndices(); + + aiMatrix4x4 transform = cluster->Transform(); + for (WeightIndexArray::value_type index : indices) { + unsigned int count = 0; + const unsigned int *out_idx = geo.ToOutputVertexIndex(index, count); + } + } + } catch (...) { } } @@ -1451,14 +1462,11 @@ void FBXConverter::ConvertWeights(aiMesh *out, const MeshGeometry &geo, std::vector *outputVertStartIndices) { ai_assert(geo.DeformerSkin()); - std::vector out_indices; - std::vector index_out_indices; - std::vector count_out_indices; + std::vector out_indices, index_out_indices, count_out_indices; const Skin &sk = *geo.DeformerSkin(); - std::vector bones; - + std::vector bones; const bool no_mat_check = materialIndex == NO_MATERIAL_SEPARATION; ai_assert(no_mat_check || outputVertStartIndices); @@ -1539,12 +1547,13 @@ void FBXConverter::ConvertWeights(aiMesh *out, const MeshGeometry &geo, } } -void FBXConverter::ConvertCluster(std::vector &local_mesh_bones, const Cluster *cl, +void FBXConverter::ConvertCluster(std::vector &local_mesh_bones, const Cluster *cluster, std::vector &out_indices, std::vector &index_out_indices, std::vector &count_out_indices, const aiMatrix4x4 &absolute_transform, aiNode *) { - ai_assert(cl); // make sure cluster valid - std::string deformer_name = cl->TargetNode()->Name(); + ai_assert(cluster != nullptr); // make sure cluster valid + + std::string deformer_name = cluster->TargetNode()->Name(); aiString bone_name = aiString(FixNodeName(deformer_name)); aiBone *bone = nullptr; @@ -1558,7 +1567,7 @@ void FBXConverter::ConvertCluster(std::vector &local_mesh_bones, const bone->mName = bone_name; // store local transform link for post processing - bone->mOffsetMatrix = cl->TransformLink(); + bone->mOffsetMatrix = cluster->TransformLink(); bone->mOffsetMatrix.Inverse(); aiMatrix4x4 matrix = (aiMatrix4x4)absolute_transform; @@ -1575,7 +1584,7 @@ void FBXConverter::ConvertCluster(std::vector &local_mesh_bones, const cursor = bone->mWeights = new aiVertexWeight[out_indices.size()]; const size_t no_index_sentinel = std::numeric_limits::max(); - const WeightArray &weights = cl->GetWeights(); + const WeightArray &weights = cluster->GetWeights(); const size_t c = index_out_indices.size(); for (size_t i = 0; i < c; ++i) { diff --git a/code/AssetLib/FBX/FBXDeformer.cpp b/code/AssetLib/FBX/FBXDeformer.cpp index ba245ed6d..ed6330666 100644 --- a/code/AssetLib/FBX/FBXDeformer.cpp +++ b/code/AssetLib/FBX/FBXDeformer.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, @@ -58,16 +57,14 @@ namespace FBX { using namespace Util; // ------------------------------------------------------------------------------------------------ -Deformer::Deformer(uint64_t id, const Element& element, const Document& doc, const std::string& name) - : Object(id,element,name) -{ +Deformer::Deformer(uint64_t id, const Element& element, const Document& doc, const std::string& name) : + Object(id,element,name) { const Scope& sc = GetRequiredScope(element); const std::string& classname = ParseTokenAsString(GetRequiredToken(element,2)); props = GetPropertyTable(doc,"Deformer.Fbx" + classname,element,sc,true); } - // ------------------------------------------------------------------------------------------------ Deformer::~Deformer() { diff --git a/code/AssetLib/FBX/FBXDocumentUtil.h b/code/AssetLib/FBX/FBXDocumentUtil.h index 2d76ee031..d32c12e1a 100644 --- a/code/AssetLib/FBX/FBXDocumentUtil.h +++ b/code/AssetLib/FBX/FBXDocumentUtil.h @@ -74,13 +74,11 @@ std::shared_ptr GetPropertyTable(const Document& doc, // ------------------------------------------------------------------------------------------------ template -inline -const T* ProcessSimpleConnection(const Connection& con, - bool is_object_property_conn, - const char* name, - const Element& element, - const char** propNameOut = nullptr) -{ +inline const T* ProcessSimpleConnection(const Connection& con, + bool is_object_property_conn, + const char* name, + const Element& element, + const char** propNameOut = nullptr) { if (is_object_property_conn && !con.PropertyName().length()) { DOMWarning("expected incoming " + std::string(name) + " link to be an object-object connection, ignoring", diff --git a/code/AssetLib/FBX/FBXExporter.cpp b/code/AssetLib/FBX/FBXExporter.cpp index 695672883..563ac68f0 100644 --- a/code/AssetLib/FBX/FBXExporter.cpp +++ b/code/AssetLib/FBX/FBXExporter.cpp @@ -255,7 +255,7 @@ void FBXExporter::WriteBinaryHeader() void FBXExporter::WriteBinaryFooter() { - outfile->Write(NULL_RECORD.c_str(), NULL_RECORD.size(), 1); + outfile->Write(NULL_RECORD, NumNullRecords, 1); outfile->Write(GENERIC_FOOTID.c_str(), GENERIC_FOOTID.size(), 1); diff --git a/code/AssetLib/FBX/FBXMeshGeometry.cpp b/code/AssetLib/FBX/FBXMeshGeometry.cpp index 1f92fa1a7..a0fb0e57e 100644 --- a/code/AssetLib/FBX/FBXMeshGeometry.cpp +++ b/code/AssetLib/FBX/FBXMeshGeometry.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, @@ -54,18 +53,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "FBXImportSettings.h" #include "FBXDocumentUtil.h" - namespace Assimp { namespace FBX { using namespace Util; // ------------------------------------------------------------------------------------------------ -Geometry::Geometry(uint64_t id, const Element& element, const std::string& name, const Document& doc) - : Object(id, element, name) - , skin() -{ - const std::vector& conns = doc.GetConnectionsByDestinationSequenced(ID(),"Deformer"); +Geometry::Geometry(uint64_t id, const Element& element, const std::string& name, const Document& doc) : + Object(id, element, name), skin() { + const std::vector &conns = doc.GetConnectionsByDestinationSequenced(ID(),"Deformer"); for(const Connection* con : conns) { const Skin* const sk = ProcessSimpleConnection(*con, false, "Skin -> Geometry", element); if(sk) { @@ -78,12 +74,6 @@ Geometry::Geometry(uint64_t id, const Element& element, const std::string& name, } } -// ------------------------------------------------------------------------------------------------ -Geometry::~Geometry() -{ - // empty -} - // ------------------------------------------------------------------------------------------------ const std::vector& Geometry::GetBlendShapes() const { return blendShapes; @@ -183,18 +173,12 @@ MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::strin if(doc.Settings().readAllLayers || index == 0) { const Scope& layer = GetRequiredScope(*(*it).second); ReadLayer(layer); - } - else { + } else { FBXImporter::LogWarn("ignoring additional geometry layers"); } } } -// ------------------------------------------------------------------------------------------------ -MeshGeometry::~MeshGeometry() { - // empty -} - // ------------------------------------------------------------------------------------------------ const std::vector& MeshGeometry::GetVertices() const { return m_vertices; diff --git a/code/AssetLib/FBX/FBXMeshGeometry.h b/code/AssetLib/FBX/FBXMeshGeometry.h index 3cca38aa5..3eb279bed 100644 --- a/code/AssetLib/FBX/FBXMeshGeometry.h +++ b/code/AssetLib/FBX/FBXMeshGeometry.h @@ -55,22 +55,25 @@ namespace FBX { /** * DOM base class for all kinds of FBX geometry */ -class Geometry : public Object -{ +class Geometry : public Object { public: + /// @brief The class constructor with all parameters. + /// @param id The id. + /// @param element + /// @param name + /// @param doc Geometry( uint64_t id, const Element& element, const std::string& name, const Document& doc ); - virtual ~Geometry(); + virtual ~Geometry() = default; - /** Get the Skin attached to this geometry or nullptr */ + /// Get the Skin attached to this geometry or nullptr const Skin* DeformerSkin() const; - /** Get the BlendShape attached to this geometry or nullptr */ + /// Get the BlendShape attached to this geometry or nullptr const std::vector& GetBlendShapes() const; private: const Skin* skin; std::vector blendShapes; - }; typedef std::vector MatIndexArray; @@ -79,14 +82,13 @@ typedef std::vector MatIndexArray; /** * DOM class for FBX geometry of type "Mesh" */ -class MeshGeometry : public Geometry -{ +class MeshGeometry : public Geometry { public: /** The class constructor */ MeshGeometry( uint64_t id, const Element& element, const std::string& name, const Document& doc ); /** The class destructor */ - virtual ~MeshGeometry(); + virtual ~MeshGeometry() = default; /** Get a list of all vertex points, non-unique*/ const std::vector& GetVertices() const; diff --git a/code/AssetLib/FBX/FBXParser.cpp b/code/AssetLib/FBX/FBXParser.cpp index e20377a3c..7cb7ae739 100644 --- a/code/AssetLib/FBX/FBXParser.cpp +++ b/code/AssetLib/FBX/FBXParser.cpp @@ -162,12 +162,6 @@ Element::Element(const Token& key_token, Parser& parser) : key_token(key_token) while(n->Type() != TokenType_KEY && n->Type() != TokenType_CLOSE_BRACKET); } -// ------------------------------------------------------------------------------------------------ -Element::~Element() -{ - // no need to delete tokens, they are owned by the parser -} - // ------------------------------------------------------------------------------------------------ Scope::Scope(Parser& parser,bool topLevel) { @@ -226,12 +220,6 @@ Parser::Parser (const TokenList& tokens, bool is_binary) root.reset(new Scope(*this,true)); } -// ------------------------------------------------------------------------------------------------ -Parser::~Parser() -{ - // empty -} - // ------------------------------------------------------------------------------------------------ TokenPtr Parser::AdvanceToNextToken() { diff --git a/code/AssetLib/FBX/FBXParser.h b/code/AssetLib/FBX/FBXParser.h index 314481e42..6aeedb211 100644 --- a/code/AssetLib/FBX/FBXParser.h +++ b/code/AssetLib/FBX/FBXParser.h @@ -87,7 +87,7 @@ class Element { public: Element(const Token& key_token, Parser& parser); - ~Element(); + ~Element() = default; const Scope* Compound() const { return compound.get(); @@ -160,7 +160,7 @@ public: /** Parse given a token list. Does not take ownership of the tokens - * the objects must persist during the entire parser lifetime */ Parser (const TokenList& tokens,bool is_binary); - ~Parser(); + ~Parser() = default; const Scope& GetRootScope() const { return *root.get();