From a4be5aac0bb44b102e8a7806c15d2b0f2e84e8b1 Mon Sep 17 00:00:00 2001 From: julianknodt Date: Mon, 9 Sep 2024 18:24:05 -0700 Subject: [PATCH] FBX Blendshapes: Do not require normals 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. --- code/AssetLib/FBX/FBXConverter.cpp | 12 ++++++------ code/AssetLib/FBX/FBXMeshGeometry.cpp | 7 +++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 6ce00bb85..bf6f30190 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -1250,9 +1250,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; @@ -1268,7 +1268,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++) { @@ -1488,15 +1488,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++) { diff --git a/code/AssetLib/FBX/FBXMeshGeometry.cpp b/code/AssetLib/FBX/FBXMeshGeometry.cpp index 67488f53a..7deaa5be7 100644 --- a/code/AssetLib/FBX/FBXMeshGeometry.cpp +++ b/code/AssetLib/FBX/FBXMeshGeometry.cpp @@ -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); + } } // ------------------------------------------------------------------------------------------------