mirror of
https://github.com/lubosz/overte.git
synced 2025-04-26 22:56:02 +02:00
Merge pull request #12620 from ctrlaltdavid/21778
Fix rotation and position of avatar meshes attached to eye joints
This commit is contained in:
commit
615c98816f
4 changed files with 41 additions and 0 deletions
libraries/animation/src
|
@ -78,6 +78,20 @@ int AnimSkeleton::getParentIndex(int jointIndex) const {
|
|||
return _joints[jointIndex].parentIndex;
|
||||
}
|
||||
|
||||
std::vector<int> AnimSkeleton::getChildrenOfJoint(int jointIndex) const {
|
||||
// Children and grandchildren, etc.
|
||||
std::vector<int> result;
|
||||
if (jointIndex != -1) {
|
||||
for (int i = jointIndex + 1; i < (int)_joints.size(); i++) {
|
||||
if (_joints[i].parentIndex == jointIndex
|
||||
|| (std::find(result.begin(), result.end(), _joints[i].parentIndex) != result.end())) {
|
||||
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;
|
||||
std::vector<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 < (int)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 };
|
||||
std::vector<int> _leftEyeJointChildren;
|
||||
std::vector<int> _rightEyeJointChildren;
|
||||
|
||||
int _leftHandJointIndex { -1 };
|
||||
int _leftElbowJointIndex { -1 };
|
||||
int _leftShoulderJointIndex { -1 };
|
||||
|
|
Loading…
Reference in a new issue