Handle index-to-direct normals (exported by the Faceshift rig FBX).

This commit is contained in:
Andrzej Kapolka 2013-10-04 17:49:18 -07:00
parent e3f830ec09
commit 08426fbd9c

View file

@ -402,6 +402,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
QVector<int> polygonIndices;
QVector<glm::vec3> normals;
QVector<int> normalIndices;
QVector<glm::vec2> texCoords;
QVector<int> 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<QVector<double> >());
} else if (subdata.name == "NormalsIndex") {
normalIndices = subdata.properties.at(0).value<QVector<int> >();
} 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