Skip to content

Commit

Permalink
Merge pull request #1 from lxw404/master
Browse files Browse the repository at this point in the history
Fixed regression that scrambled FBX blendshape order
  • Loading branch information
Frooxius authored Jul 1, 2024
2 parents aae9369 + 6388a15 commit 6a80c13
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions code/AssetLib/3DS/3DSHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ namespace Discreet3DS {
};
}

#include <assimp/Compiler/poppack1.h> // Reset packing alignment

// ---------------------------------------------------------------------------
/** Helper structure representing a 3ds mesh face */
struct Face : public FaceWithSmoothingGroup {
Expand Down Expand Up @@ -360,8 +362,6 @@ struct Texture {
int iUVSrc;
};

#include <assimp/Compiler/poppack1.h>

#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER
Expand Down
16 changes: 11 additions & 5 deletions code/AssetLib/FBX/FBXDeformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER

#include <algorithm>

#include "FBXParser.h"
#include "FBXDocument.h"
#include "FBXMeshGeometry.h"
Expand Down Expand Up @@ -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<BlendShapeChannel>(*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());
}
}
Expand All @@ -181,9 +185,11 @@ BlendShapeChannel::BlendShapeChannel(uint64_t id, const Element& element, const
for (const Connection* con : conns) {
const ShapeGeometry* const sg = ProcessSimpleConnection<ShapeGeometry>(*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());
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions code/AssetLib/FBX/FBXDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -865,14 +865,14 @@ class BlendShapeChannel : public Deformer {
return fullWeights;
}

const std::unordered_set<const ShapeGeometry*>& GetShapeGeometries() const {
const std::vector<const ShapeGeometry*>& GetShapeGeometries() const {
return shapeGeometries;
}

private:
float percent;
WeightArray fullWeights;
std::unordered_set<const ShapeGeometry*> shapeGeometries;
std::vector<const ShapeGeometry*> shapeGeometries;
};

/** DOM class for BlendShape deformers */
Expand All @@ -882,12 +882,12 @@ class BlendShape : public Deformer {

virtual ~BlendShape();

const std::unordered_set<const BlendShapeChannel*>& BlendShapeChannels() const {
const std::vector<const BlendShapeChannel*>& BlendShapeChannels() const {
return blendShapeChannels;
}

private:
std::unordered_set<const BlendShapeChannel*> blendShapeChannels;
std::vector<const BlendShapeChannel*> blendShapeChannels;
};

/** DOM class for skin deformer clusters (aka sub-deformers) */
Expand Down
9 changes: 6 additions & 3 deletions code/AssetLib/FBX/FBXMeshGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER

#include <algorithm>
#include <functional>

#include "FBXMeshGeometry.h"
Expand All @@ -69,16 +70,18 @@ Geometry::Geometry(uint64_t id, const Element& element, const std::string& name,
}
const BlendShape* const bsp = ProcessSimpleConnection<BlendShape>(*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());
}
}
}
}

// ------------------------------------------------------------------------------------------------
const std::unordered_set<const BlendShape*>& Geometry::GetBlendShapes() const {
const std::vector<const BlendShape*>& Geometry::GetBlendShapes() const {
return blendShapes;
}

Expand Down
4 changes: 2 additions & 2 deletions code/AssetLib/FBX/FBXMeshGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const BlendShape*>& GetBlendShapes() const;
const std::vector<const BlendShape*>& GetBlendShapes() const;

private:
const Skin* skin;
std::unordered_set<const BlendShape*> blendShapes;
std::vector<const BlendShape*> blendShapes;

};

Expand Down

0 comments on commit 6a80c13

Please sign in to comment.