mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-16 06:57:04 +02:00
Fix rotation and position of meshes attached to eye joints
This commit is contained in:
parent
8d047184bb
commit
957d39b0b1
4 changed files with 38 additions and 0 deletions
|
@ -78,6 +78,17 @@ int AnimSkeleton::getParentIndex(int jointIndex) const {
|
|||
return _joints[jointIndex].parentIndex;
|
||||
}
|
||||
|
||||
QVector<int> AnimSkeleton::getChildrenOfJoint(int jointIndex) const {
|
||||
// Children and grandchildren, etc.
|
||||
QVector<int> result;
|
||||
for (int i = jointIndex + 1; i < _joints.size(); i++) {
|
||||
if (_joints[i].parentIndex == jointIndex || result.contains(_joints[i].parentIndex)) {
|
||||
result.push_back(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const QString& AnimSkeleton::getJointName(int jointIndex) const {
|
||||
return _joints[jointIndex].name;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
const AnimPose& getPostRotationPose(int jointIndex) const;
|
||||
|
||||
int getParentIndex(int jointIndex) const;
|
||||
QVector<int> getChildrenOfJoint(int jointIndex) const;
|
||||
|
||||
AnimPose getAbsolutePose(int jointIndex, const AnimPoseVec& relativePoses) const;
|
||||
|
||||
|
|
|
@ -199,6 +199,8 @@ void Rig::destroyAnimGraph() {
|
|||
_internalPoseSet._overridePoses.clear();
|
||||
_internalPoseSet._overrideFlags.clear();
|
||||
_numOverrides = 0;
|
||||
_leftEyeJointChildren.clear();
|
||||
_rightEyeJointChildren.clear();
|
||||
}
|
||||
|
||||
void Rig::initJointStates(const FBXGeometry& geometry, const glm::mat4& modelOffset) {
|
||||
|
@ -225,12 +227,17 @@ void Rig::initJointStates(const FBXGeometry& geometry, const glm::mat4& modelOff
|
|||
buildAbsoluteRigPoses(_animSkeleton->getRelativeDefaultPoses(), _absoluteDefaultPoses);
|
||||
|
||||
_rootJointIndex = geometry.rootJointIndex;
|
||||
_leftEyeJointIndex = geometry.leftEyeJointIndex;
|
||||
_rightEyeJointIndex = geometry.rightEyeJointIndex;
|
||||
_leftHandJointIndex = geometry.leftHandJointIndex;
|
||||
_leftElbowJointIndex = _leftHandJointIndex >= 0 ? geometry.joints.at(_leftHandJointIndex).parentIndex : -1;
|
||||
_leftShoulderJointIndex = _leftElbowJointIndex >= 0 ? geometry.joints.at(_leftElbowJointIndex).parentIndex : -1;
|
||||
_rightHandJointIndex = geometry.rightHandJointIndex;
|
||||
_rightElbowJointIndex = _rightHandJointIndex >= 0 ? geometry.joints.at(_rightHandJointIndex).parentIndex : -1;
|
||||
_rightShoulderJointIndex = _rightElbowJointIndex >= 0 ? geometry.joints.at(_rightElbowJointIndex).parentIndex : -1;
|
||||
|
||||
_leftEyeJointChildren = _animSkeleton->getChildrenOfJoint(geometry.leftEyeJointIndex);
|
||||
_rightEyeJointChildren = _animSkeleton->getChildrenOfJoint(geometry.rightEyeJointIndex);
|
||||
}
|
||||
|
||||
void Rig::reset(const FBXGeometry& geometry) {
|
||||
|
@ -253,6 +260,8 @@ void Rig::reset(const FBXGeometry& geometry) {
|
|||
buildAbsoluteRigPoses(_animSkeleton->getRelativeDefaultPoses(), _absoluteDefaultPoses);
|
||||
|
||||
_rootJointIndex = geometry.rootJointIndex;
|
||||
_leftEyeJointIndex = geometry.leftEyeJointIndex;
|
||||
_rightEyeJointIndex = geometry.rightEyeJointIndex;
|
||||
_leftHandJointIndex = geometry.leftHandJointIndex;
|
||||
_leftElbowJointIndex = _leftHandJointIndex >= 0 ? geometry.joints.at(_leftHandJointIndex).parentIndex : -1;
|
||||
_leftShoulderJointIndex = _leftElbowJointIndex >= 0 ? geometry.joints.at(_leftElbowJointIndex).parentIndex : -1;
|
||||
|
@ -260,6 +269,9 @@ void Rig::reset(const FBXGeometry& geometry) {
|
|||
_rightElbowJointIndex = _rightHandJointIndex >= 0 ? geometry.joints.at(_rightHandJointIndex).parentIndex : -1;
|
||||
_rightShoulderJointIndex = _rightElbowJointIndex >= 0 ? geometry.joints.at(_rightElbowJointIndex).parentIndex : -1;
|
||||
|
||||
_leftEyeJointChildren = _animSkeleton->getChildrenOfJoint(geometry.leftEyeJointIndex);
|
||||
_rightEyeJointChildren = _animSkeleton->getChildrenOfJoint(geometry.rightEyeJointIndex);
|
||||
|
||||
if (!_animGraphURL.isEmpty()) {
|
||||
_animNode.reset();
|
||||
initAnimGraph(_animGraphURL);
|
||||
|
@ -1430,6 +1442,15 @@ void Rig::updateEyeJoint(int index, const glm::vec3& modelTranslation, const glm
|
|||
|
||||
// directly set absolutePose rotation
|
||||
_internalPoseSet._absolutePoses[index].rot() = deltaQuat * headQuat;
|
||||
|
||||
// Update eye joint's children.
|
||||
auto children = index == _leftEyeJointIndex ? _leftEyeJointChildren : _rightEyeJointChildren;
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
int jointIndex = children[i];
|
||||
int parentIndex = _animSkeleton->getParentIndex(jointIndex);
|
||||
_internalPoseSet._absolutePoses[jointIndex] =
|
||||
_internalPoseSet._absolutePoses[parentIndex] * _internalPoseSet._relativePoses[jointIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -267,6 +267,11 @@ protected:
|
|||
|
||||
int _rootJointIndex { -1 };
|
||||
|
||||
int _leftEyeJointIndex { -1 };
|
||||
int _rightEyeJointIndex { -1 };
|
||||
QVector<int> _leftEyeJointChildren;
|
||||
QVector<int> _rightEyeJointChildren;
|
||||
|
||||
int _leftHandJointIndex { -1 };
|
||||
int _leftElbowJointIndex { -1 };
|
||||
int _leftShoulderJointIndex { -1 };
|
||||
|
|
Loading…
Reference in a new issue