mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-16 08:13:44 +02:00
add JointState::updateWorldTransform()
This commit is contained in:
parent
b15b0fd96c
commit
ec25982a58
2 changed files with 18 additions and 21 deletions
|
@ -162,19 +162,13 @@ QVector<JointState> Model::createJointStates(const FBXGeometry& geometry) {
|
|||
int parentIndex = joint.parentIndex;
|
||||
if (parentIndex == -1) {
|
||||
_rootIndex = i;
|
||||
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;
|
||||
glm::mat4 baseTransform = glm::mat4_cast(_rotation) * glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
|
||||
state.updateWorldTransform(baseTransform, _rotation);
|
||||
++numJointsSet;
|
||||
jointIsSet[i] = true;
|
||||
} else if (jointIsSet[parentIndex]) {
|
||||
const JointState& parentState = jointStates.at(parentIndex);
|
||||
glm::quat combinedRotation = joint.preRotation * state._rotation * joint.postRotation;
|
||||
state._transform = parentState._transform * glm::translate(state._translation) * joint.preTransform *
|
||||
glm::mat4_cast(combinedRotation) * joint.postTransform;
|
||||
state._combinedRotation = parentState._combinedRotation * combinedRotation;
|
||||
state.updateWorldTransform(parentState._transform, parentState._combinedRotation);
|
||||
++numJointsSet;
|
||||
jointIsSet[i] = true;
|
||||
}
|
||||
|
@ -1129,17 +1123,11 @@ void Model::updateJointState(int index) {
|
|||
|
||||
if (joint.parentIndex == -1) {
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
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;
|
||||
glm::mat4 baseTransform = glm::mat4_cast(_rotation) * glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
|
||||
state.updateWorldTransform(baseTransform, _rotation);
|
||||
} else {
|
||||
const JointState& parentState = _jointStates.at(joint.parentIndex);
|
||||
glm::quat combinedRotation = joint.preRotation * state._rotation * joint.postRotation;
|
||||
state._transform = parentState._transform * glm::translate(state._translation) * joint.preTransform *
|
||||
glm::mat4_cast(combinedRotation) * joint.postTransform;
|
||||
state._combinedRotation = parentState._combinedRotation * combinedRotation;
|
||||
state.updateWorldTransform(parentState._transform, parentState._combinedRotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1908,3 +1896,9 @@ void JointState::setFBXJoint(const FBXJoint& joint) {
|
|||
_rotation = joint.rotation;
|
||||
_fbxJoint = &joint;
|
||||
}
|
||||
|
||||
void JointState::updateWorldTransform(const glm::mat4& baseTransform, const glm::quat& parentRotation) {
|
||||
glm::quat combinedRotation = _fbxJoint->preRotation * _rotation * _fbxJoint->postRotation;
|
||||
_transform = baseTransform * glm::translate(_translation) * _fbxJoint->preTransform * glm::mat4_cast(combinedRotation) * _fbxJoint->postTransform;
|
||||
_combinedRotation = parentRotation * combinedRotation;
|
||||
}
|
||||
|
|
|
@ -34,15 +34,18 @@ typedef QWeakPointer<AnimationHandle> WeakAnimationHandlePointer;
|
|||
class JointState {
|
||||
public:
|
||||
JointState();
|
||||
|
||||
void setFBXJoint(const FBXJoint& joint);
|
||||
const FBXJoint& getFBXJoint() const { return *_fbxJoint; }
|
||||
|
||||
void updateWorldTransform(const glm::mat4& baseTransform, const glm::quat& parentRotation);
|
||||
|
||||
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
|
||||
glm::quat _combinedRotation; // rotation from joint local to world frame
|
||||
float _animationPriority; // the priority of the animation affecting this joint
|
||||
|
||||
void setFBXJoint(const FBXJoint& joint);
|
||||
const FBXJoint& getFBXJoint() const { return *_fbxJoint; }
|
||||
|
||||
private:
|
||||
const FBXJoint* _fbxJoint; // JointState does not own its FBXJoint
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue