From 86d6fd45de95962b23d2c30c33da242666e838fb Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 29 May 2014 08:19:43 -0700 Subject: [PATCH] safe copy of JointState data --- interface/src/renderer/Model.cpp | 26 +++++++++++++++++++------- interface/src/renderer/Model.h | 6 ++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 215678dedc..1a857ff811 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -138,8 +138,9 @@ void Model::initSkinProgram(ProgramObject& program, Model::SkinLocations& locati QVector Model::createJointStates(const FBXGeometry& geometry) { QVector jointStates; foreach (const FBXJoint& joint, geometry.joints) { + // NOTE: the state keeps a pointer to an FBXJoint JointState state; - state.setFBXJoint(joint); + state.setFBXJoint(&joint); jointStates.append(state); } @@ -408,7 +409,7 @@ bool Model::updateGeometry() { int oldIndex = it.value() - 1; int newIndex = newGeometry.getJointIndex(it.key()); if (newIndex != -1) { - newJointStates[newIndex] = _jointStates.at(oldIndex); + newJointStates[newIndex].copyState(_jointStates[oldIndex]); } } } @@ -1890,15 +1891,26 @@ JointState::JointState() : _fbxJoint(NULL) { } -void JointState::setFBXJoint(const FBXJoint& joint) { - assert(&joint != NULL); - _translation = joint.translation; - _rotation = joint.rotation; - _fbxJoint = &joint; +void JointState::setFBXJoint(const FBXJoint* joint) { + assert(joint != NULL); + _translation = joint->translation; + _rotation = joint->rotation; + // NOTE: JointState does not own the FBXJoint to which it points. + _fbxJoint = joint; } void JointState::updateWorldTransform(const glm::mat4& baseTransform, const glm::quat& parentRotation) { + assert(_fbxJoint != NULL); glm::quat combinedRotation = _fbxJoint->preRotation * _rotation * _fbxJoint->postRotation; _transform = baseTransform * glm::translate(_translation) * _fbxJoint->preTransform * glm::mat4_cast(combinedRotation) * _fbxJoint->postTransform; _combinedRotation = parentRotation * combinedRotation; } + +void JointState::copyState(const JointState& state) { + _translation = state._translation; + _rotation = state._rotation; + _transform = state._transform; + _combinedRotation = state._combinedRotation; + _animationPriority = state._animationPriority; + // DO NOT copy _fbxJoint +} diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 349e8305c4..b8a5de5902 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -35,11 +35,13 @@ class JointState { public: JointState(); - void setFBXJoint(const FBXJoint& joint); + void setFBXJoint(const FBXJoint* joint); const FBXJoint& getFBXJoint() const { return *_fbxJoint; } void updateWorldTransform(const glm::mat4& baseTransform, const glm::quat& parentRotation); + void copyState(const JointState& state); + glm::vec3 _translation; // translation relative to parent glm::quat _rotation; // rotation relative to parent glm::mat4 _transform; // rotation to world frame + translation in model frame @@ -47,7 +49,7 @@ public: float _animationPriority; // the priority of the animation affecting this joint private: - const FBXJoint* _fbxJoint; // JointState does not own its FBXJoint + const FBXJoint* _fbxJoint; // JointState does NOT own its FBXJoint }; /// A generic 3D model displaying geometry loaded from a URL.