From 452eb9be47f0ceacd2d117530ba734e53f53eb58 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 24 Sep 2013 16:50:38 -0700 Subject: [PATCH] Extract the pivot points from the limb nodes, make sure we extract the vector elements in the right order. --- interface/src/renderer/FBXReader.cpp | 28 ++++++++++++++++++++++++++-- interface/src/renderer/FBXReader.h | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/interface/src/renderer/FBXReader.cpp b/interface/src/renderer/FBXReader.cpp index 67ead61d0c..0c74e14527 100644 --- a/interface/src/renderer/FBXReader.cpp +++ b/interface/src/renderer/FBXReader.cpp @@ -189,7 +189,10 @@ FBXNode parseFBX(QIODevice* device) { QVector createVec3Vector(const QVector& doubleVector) { QVector values; for (const double* it = doubleVector.constData(), *end = it + doubleVector.size(); it != end; ) { - values.append(glm::vec3(*it++, *it++, *it++)); + float x = *it++; + float y = *it++; + float z = *it++; + values.append(glm::vec3(x, y, z)); } return values; } @@ -270,6 +273,8 @@ FBXGeometry extractFBXGeometry(const FBXNode& node) { QHash meshes; QVector blendshapes; QHash parentMap; + QMultiHash childMap; + QHash pivots; foreach (const FBXNode& child, node.children) { if (child.name == "Objects") { @@ -355,12 +360,21 @@ FBXGeometry extractFBXGeometry(const FBXNode& node) { blendshapes.append(extracted); } + } else if (object.name == "Deformer" && object.properties.at(2) == "Cluster") { + foreach (const FBXNode& subobject, object.children) { + if (subobject.name == "TransformLink") { + QVector values = subobject.properties.at(0).value >(); + pivots.insert(object.properties.at(0).value(), + glm::vec3(values.at(12), values.at(13), values.at(14))); // matrix translation component + } + } } } } else if (child.name == "Connections") { foreach (const FBXNode& connection, child.children) { if (connection.name == "C") { parentMap.insert(connection.properties.at(1).value(), connection.properties.at(2).value()); + childMap.insert(connection.properties.at(2).value(), connection.properties.at(1).value()); } } } @@ -379,7 +393,17 @@ FBXGeometry extractFBXGeometry(const FBXNode& node) { // as a temporary hack, put the mesh with the most blendshapes on top; assume it to be the face FBXGeometry geometry; int mostBlendshapes = 0; - foreach (const FBXMesh& mesh, meshes) { + for (QHash::iterator it = meshes.begin(); it != meshes.end(); it++) { + FBXMesh& mesh = it.value(); + + // look for a limb pivot + foreach (qint64 childID, childMap.values(it.key())) { + qint64 clusterID = childMap.value(childID); + if (pivots.contains(clusterID)) { + mesh.pivot = pivots.value(clusterID); + } + } + if (mesh.blendshapes.size() > mostBlendshapes) { geometry.meshes.prepend(mesh); mostBlendshapes = mesh.blendshapes.size(); diff --git a/interface/src/renderer/FBXReader.h b/interface/src/renderer/FBXReader.h index db67c6b54a..fbaad6868e 100644 --- a/interface/src/renderer/FBXReader.h +++ b/interface/src/renderer/FBXReader.h @@ -47,6 +47,8 @@ public: QVector vertices; QVector normals; + glm::vec3 pivot; + QVector blendshapes; };