From 08426fbd9c862369cc73c28f5341659213c3e6f6 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 4 Oct 2013 17:49:18 -0700 Subject: [PATCH 1/2] Handle index-to-direct normals (exported by the Faceshift rig FBX). --- interface/src/renderer/FBXReader.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/interface/src/renderer/FBXReader.cpp b/interface/src/renderer/FBXReader.cpp index 1c24f8b6c6..e03b862f20 100644 --- a/interface/src/renderer/FBXReader.cpp +++ b/interface/src/renderer/FBXReader.cpp @@ -402,6 +402,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) QVector polygonIndices; QVector normals; + QVector normalIndices; QVector texCoords; QVector texCoordIndices; foreach (const FBXNode& data, object.children) { @@ -417,6 +418,9 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) if (subdata.name == "Normals") { normals = createVec3Vector(subdata.properties.at(0).value >()); + } else if (subdata.name == "NormalsIndex") { + normalIndices = subdata.properties.at(0).value >(); + } else if (subdata.name == "MappingInformationType" && subdata.properties.at(0) == "ByVertice") { byVertex = true; @@ -440,10 +444,20 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) // convert normals from per-index to per-vertex if necessary if (mesh.normals.isEmpty()) { mesh.normals.resize(mesh.vertices.size()); - for (int i = 0, n = polygonIndices.size(); i < n; i++) { - int index = polygonIndices.at(i); - mesh.normals[index < 0 ? (-index - 1) : index] = normals.at(i); - } + if (normalIndices.isEmpty()) { + for (int i = 0, n = polygonIndices.size(); i < n; i++) { + int index = polygonIndices.at(i); + mesh.normals[index < 0 ? (-index - 1) : index] = normals.at(i); + } + } else { + for (int i = 0, n = polygonIndices.size(); i < n; i++) { + int index = polygonIndices.at(i); + int normalIndex = normalIndices.at(i); + if (normalIndex >= 0) { + mesh.normals[index < 0 ? (-index - 1) : index] = normals.at(normalIndex); + } + } + } } // same with the tex coords From a704a29864d18e79b4c30a6f4c2a889c1248f024 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 4 Oct 2013 17:56:36 -0700 Subject: [PATCH 2/2] Include a mapping for the names generated by the FBX export. --- interface/src/renderer/FBXReader.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/renderer/FBXReader.cpp b/interface/src/renderer/FBXReader.cpp index e03b862f20..afacc86204 100644 --- a/interface/src/renderer/FBXReader.cpp +++ b/interface/src/renderer/FBXReader.cpp @@ -382,6 +382,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) } QList mappings = blendshapeMappings.values(blendshapeName); if (mappings.isEmpty()) { + blendshapeIndices.insert(blendshapeName, QPair(i, 1.0f)); blendshapeIndices.insert("ExpressionBlendshapes." + blendshapeName, QPair(i, 1.0f)); } else { foreach (const QVariant& mapping, mappings) {