From b0c3655076ce3bf1b482c9da55fb728ebf7a7f59 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 22 May 2014 11:40:36 -0700 Subject: [PATCH] Fix for bad bounding shape for multi-root models. --- interface/src/renderer/Model.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 900d7ff951..2b50b6d19c 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -682,7 +682,6 @@ void Model::computeBoundingShape(const FBXGeometry& geometry) { shapeIsSet.fill(false, numJoints); int numShapesSet = 0; int lastNumShapesSet = -1; - glm::vec3 rootOffset(0.0f); while (numShapesSet < numJoints && numShapesSet != lastNumShapesSet) { lastNumShapesSet = numShapesSet; for (int i = 0; i < numJoints; i++) { @@ -692,9 +691,11 @@ void Model::computeBoundingShape(const FBXGeometry& geometry) { if (parentIndex == -1) { glm::mat4 baseTransform = glm::scale(_scale) * glm::translate(_offset); glm::quat combinedRotation = joint.preRotation * joint.rotation * joint.postRotation; - transforms[i] = baseTransform * geometry.offset * glm::translate(joint.translation) + glm::mat4 rootTransform = baseTransform * geometry.offset * glm::translate(joint.translation) * joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform; - rootOffset = extractTranslation(transforms[i]); + // remove the tranlsation part before we save the root transform + transforms[i] = glm::translate(- extractTranslation(rootTransform)) * rootTransform; + finalRotations[i] = combinedRotation; ++numShapesSet; shapeIsSet[i] = true; @@ -715,7 +716,7 @@ void Model::computeBoundingShape(const FBXGeometry& geometry) { for (int i = 0; i < _jointShapes.size(); i++) { const FBXJoint& joint = geometry.joints[i]; glm::vec3 jointToShapeOffset = uniformScale * (finalRotations[i] * joint.shapePosition); - glm::vec3 localPosition = extractTranslation(transforms[i]) + jointToShapeOffset- rootOffset; + glm::vec3 localPosition = extractTranslation(transforms[i]) + jointToShapeOffset; Shape* shape = _jointShapes[i]; shape->setPosition(localPosition); shape->setRotation(finalRotations[i] * joint.shapeRotation); @@ -1078,12 +1079,10 @@ void Model::updateJointState(int index) { if (joint.parentIndex == -1) { glm::mat4 baseTransform = glm::mat4_cast(_rotation) * glm::scale(_scale) * glm::translate(_offset); - glm::quat combinedRotation = joint.preRotation * state.rotation * joint.postRotation; state.transform = baseTransform * geometry.offset * glm::translate(state.translation) * joint.preTransform * glm::mat4_cast(combinedRotation) * joint.postTransform; state.combinedRotation = _rotation * combinedRotation; - } else { const JointState& parentState = _jointStates.at(joint.parentIndex); if (index == geometry.leanJointIndex) {