Skip to content

Commit

Permalink
FBX Blendshapes: Do not require normals (assimp#5776)
Browse files Browse the repository at this point in the history
Some blendshapes don't have normal transformations, but Assimp currently requires that normals
be present. This removes that, and won't populate the normal field.

Co-authored-by: Kim Kulling <[email protected]>
  • Loading branch information
JulianKnodt and kimkulling authored Sep 24, 2024
1 parent f636252 commit 17399d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 6 additions & 6 deletions code/AssetLib/FBX/FBXConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,9 +1254,9 @@ unsigned int FBXConverter::ConvertMeshSingleMaterial(const MeshGeometry &mesh, c
for (const BlendShapeChannel *blendShapeChannel : blendShape->BlendShapeChannels()) {
const auto& shapeGeometries = blendShapeChannel->GetShapeGeometries();
for (const ShapeGeometry *shapeGeometry : shapeGeometries) {
aiAnimMesh *animMesh = aiCreateAnimMesh(out_mesh);
const auto &curVertices = shapeGeometry->GetVertices();
const auto &curNormals = shapeGeometry->GetNormals();
aiAnimMesh *animMesh = aiCreateAnimMesh(out_mesh, true, !curNormals.empty());
const auto &curVertices = shapeGeometry->GetVertices();
const auto &curIndices = shapeGeometry->GetIndices();
//losing channel name if using shapeGeometry->Name()
// if blendShapeChannel Name is empty or doesn't have a ".", add geoMetryName;
Expand All @@ -1272,7 +1272,7 @@ unsigned int FBXConverter::ConvertMeshSingleMaterial(const MeshGeometry &mesh, c
for (size_t j = 0; j < curIndices.size(); j++) {
const unsigned int curIndex = curIndices.at(j);
aiVector3D vertex = curVertices.at(j);
aiVector3D normal = curNormals.at(j);
aiVector3D normal = curNormals.empty() ? aiVector3D() : curNormals.at(j);
unsigned int count = 0;
const unsigned int *outIndices = mesh.ToOutputVertexIndex(curIndex, count);
for (unsigned int k = 0; k < count; k++) {
Expand Down Expand Up @@ -1492,15 +1492,15 @@ unsigned int FBXConverter::ConvertMeshMultiMaterial(const MeshGeometry &mesh, co
for (const BlendShapeChannel *blendShapeChannel : blendShape->BlendShapeChannels()) {
const auto& shapeGeometries = blendShapeChannel->GetShapeGeometries();
for (const ShapeGeometry *shapeGeometry : shapeGeometries) {
aiAnimMesh *animMesh = aiCreateAnimMesh(out_mesh);
const auto& curVertices = shapeGeometry->GetVertices();
const auto& curNormals = shapeGeometry->GetNormals();
aiAnimMesh *animMesh = aiCreateAnimMesh(out_mesh, true, !curNormals.empty());
const auto& curVertices = shapeGeometry->GetVertices();
const auto& curIndices = shapeGeometry->GetIndices();
animMesh->mName.Set(FixAnimMeshName(shapeGeometry->Name()));
for (size_t j = 0; j < curIndices.size(); j++) {
unsigned int curIndex = curIndices.at(j);
aiVector3D vertex = curVertices.at(j);
aiVector3D normal = curNormals.at(j);
aiVector3D normal = curNormals.empty() ? aiVector3D() : curNormals.at(j);
unsigned int count = 0;
const unsigned int *outIndices = mesh.ToOutputVertexIndex(curIndex, count);
for (unsigned int k = 0; k < count; k++) {
Expand Down
7 changes: 5 additions & 2 deletions code/AssetLib/FBX/FBXMeshGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,14 @@ ShapeGeometry::ShapeGeometry(uint64_t id, const Element& element, const std::str
DOMError("failed to read Geometry object (class: Shape), no data scope found");
}
const Element& Indexes = GetRequiredElement(*sc, "Indexes", &element);
const Element& Normals = GetRequiredElement(*sc, "Normals", &element);
const Element& Vertices = GetRequiredElement(*sc, "Vertices", &element);
ParseVectorDataArray(m_indices, Indexes);
ParseVectorDataArray(m_vertices, Vertices);
ParseVectorDataArray(m_normals, Normals);

if ((*sc)["Normals"]) {
const Element& Normals = GetRequiredElement(*sc, "Normals", &element);
ParseVectorDataArray(m_normals, Normals);
}
}

// ------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 17399d1

Please sign in to comment.