From 6388a153b6070423a7c13681cc5975cefe12a279 Mon Sep 17 00:00:00 2001 From: Lux Date: Thu, 27 Jun 2024 18:34:04 -0400 Subject: [PATCH] Fixed regression that scrambled FBX blendshape order. --- code/AssetLib/3DS/3DSHelper.h | 4 ++-- code/AssetLib/FBX/FBXDeformer.cpp | 16 +++++++++++----- code/AssetLib/FBX/FBXDocument.h | 8 ++++---- code/AssetLib/FBX/FBXMeshGeometry.cpp | 9 ++++++--- code/AssetLib/FBX/FBXMeshGeometry.h | 4 ++-- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/code/AssetLib/3DS/3DSHelper.h b/code/AssetLib/3DS/3DSHelper.h index 2279d105c3..063939aa3d 100644 --- a/code/AssetLib/3DS/3DSHelper.h +++ b/code/AssetLib/3DS/3DSHelper.h @@ -306,6 +306,8 @@ namespace Discreet3DS { }; } +#include // Reset packing alignment + // --------------------------------------------------------------------------- /** Helper structure representing a 3ds mesh face */ struct Face : public FaceWithSmoothingGroup { @@ -360,8 +362,6 @@ struct Texture { int iUVSrc; }; -#include - #ifdef _MSC_VER #pragma warning(pop) #endif // _MSC_VER diff --git a/code/AssetLib/FBX/FBXDeformer.cpp b/code/AssetLib/FBX/FBXDeformer.cpp index 1aab55ea92..88dd563bcd 100644 --- a/code/AssetLib/FBX/FBXDeformer.cpp +++ b/code/AssetLib/FBX/FBXDeformer.cpp @@ -45,6 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER +#include + #include "FBXParser.h" #include "FBXDocument.h" #include "FBXMeshGeometry.h" @@ -154,8 +156,10 @@ BlendShape::BlendShape(uint64_t id, const Element& element, const Document& doc, for (const Connection* con : conns) { const BlendShapeChannel* const bspc = ProcessSimpleConnection(*con, false, "BlendShapeChannel -> BlendShape", element); if (bspc) { - auto pr = blendShapeChannels.insert(bspc); - if (!pr.second) { + // Only add a channel if it doesn't exist already + if (std::find(blendShapeChannels.begin(), blendShapeChannels.end(), bspc) == blendShapeChannels.end()) { + blendShapeChannels.push_back(bspc); + } else { FBXImporter::LogWarn("there is the same blendShapeChannel id ", bspc->ID()); } } @@ -181,9 +185,11 @@ BlendShapeChannel::BlendShapeChannel(uint64_t id, const Element& element, const for (const Connection* con : conns) { const ShapeGeometry* const sg = ProcessSimpleConnection(*con, false, "Shape -> BlendShapeChannel", element); if (sg) { - auto pr = shapeGeometries.insert(sg); - if (!pr.second) { - FBXImporter::LogWarn("there is the same shapeGeometrie id ", sg->ID()); + // Only add a geometry if it doesn't exist already + if (std::find(shapeGeometries.begin(), shapeGeometries.end(), sg) == shapeGeometries.end()) { + shapeGeometries.push_back(sg); + } else { + FBXImporter::LogWarn("there is the same blendShape id ", sg->ID()); } } } diff --git a/code/AssetLib/FBX/FBXDocument.h b/code/AssetLib/FBX/FBXDocument.h index 3af757a19a..65bcfa900a 100644 --- a/code/AssetLib/FBX/FBXDocument.h +++ b/code/AssetLib/FBX/FBXDocument.h @@ -865,14 +865,14 @@ class BlendShapeChannel : public Deformer { return fullWeights; } - const std::unordered_set& GetShapeGeometries() const { + const std::vector& GetShapeGeometries() const { return shapeGeometries; } private: float percent; WeightArray fullWeights; - std::unordered_set shapeGeometries; + std::vector shapeGeometries; }; /** DOM class for BlendShape deformers */ @@ -882,12 +882,12 @@ class BlendShape : public Deformer { virtual ~BlendShape(); - const std::unordered_set& BlendShapeChannels() const { + const std::vector& BlendShapeChannels() const { return blendShapeChannels; } private: - std::unordered_set blendShapeChannels; + std::vector blendShapeChannels; }; /** DOM class for skin deformer clusters (aka sub-deformers) */ diff --git a/code/AssetLib/FBX/FBXMeshGeometry.cpp b/code/AssetLib/FBX/FBXMeshGeometry.cpp index fcbaac1696..ee543901d3 100644 --- a/code/AssetLib/FBX/FBXMeshGeometry.cpp +++ b/code/AssetLib/FBX/FBXMeshGeometry.cpp @@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER +#include #include #include "FBXMeshGeometry.h" @@ -69,8 +70,10 @@ Geometry::Geometry(uint64_t id, const Element& element, const std::string& name, } const BlendShape* const bsp = ProcessSimpleConnection(*con, false, "BlendShape -> Geometry", element); if (bsp) { - auto pr = blendShapes.insert(bsp); - if (!pr.second) { + // Only add a blendshape if it doesn't exist already + if (std::find(blendShapes.begin(), blendShapes.end(), bsp) == blendShapes.end()) { + blendShapes.push_back(bsp); + } else { FBXImporter::LogWarn("there is the same blendShape id ", bsp->ID()); } } @@ -78,7 +81,7 @@ Geometry::Geometry(uint64_t id, const Element& element, const std::string& name, } // ------------------------------------------------------------------------------------------------ -const std::unordered_set& Geometry::GetBlendShapes() const { +const std::vector& Geometry::GetBlendShapes() const { return blendShapes; } diff --git a/code/AssetLib/FBX/FBXMeshGeometry.h b/code/AssetLib/FBX/FBXMeshGeometry.h index 3d67ec567b..6d0efe8b38 100644 --- a/code/AssetLib/FBX/FBXMeshGeometry.h +++ b/code/AssetLib/FBX/FBXMeshGeometry.h @@ -72,11 +72,11 @@ class Geometry : public Object { /// @brief Get the BlendShape attached to this geometry or nullptr /// @return The blendshape arrays. - const std::unordered_set& GetBlendShapes() const; + const std::vector& GetBlendShapes() const; private: const Skin* skin; - std::unordered_set blendShapes; + std::vector blendShapes; };