mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 16:52:10 +02:00
disable mid joint when not valid. more work on this tomorrow
This commit is contained in:
parent
dffd41ecb0
commit
1919cc3b1a
2 changed files with 49 additions and 38 deletions
|
@ -182,7 +182,7 @@
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"interpDuration": 15,
|
"interpDuration": 15,
|
||||||
"baseJointName": "Hips",
|
"baseJointName": "Hips",
|
||||||
"midJointName": "Spine2",
|
"midJointName": "none",
|
||||||
"tipJointName": "Head",
|
"tipJointName": "Head",
|
||||||
"basePositionVar": "hipsPosition",
|
"basePositionVar": "hipsPosition",
|
||||||
"baseRotationVar": "hipsRotation",
|
"baseRotationVar": "hipsRotation",
|
||||||
|
|
|
@ -163,40 +163,48 @@ const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const
|
||||||
jointChain.buildDirtyAbsolutePoses();
|
jointChain.buildDirtyAbsolutePoses();
|
||||||
jointChain.outputRelativePoses(_poses);
|
jointChain.outputRelativePoses(_poses);
|
||||||
|
|
||||||
// initialize the middle joint target
|
|
||||||
IKTarget midTarget;
|
IKTarget midTarget;
|
||||||
midTarget.setType((int)IKTarget::Type::Spline);
|
if (_midJointIndex != -1) {
|
||||||
midTarget.setIndex(_midJointIndex);
|
|
||||||
// set the middle joint to the position that was just determined by the base-tip spline.
|
|
||||||
AnimPose afterSolveMidTarget = _skeleton->getAbsolutePose(_midJointIndex, _poses);
|
|
||||||
// use the rotation from the ik target value, if there is one.
|
|
||||||
glm::quat midTargetRotation = animVars.lookupRigToGeometry(_midRotationVar, afterSolveMidTarget.rot());
|
|
||||||
AnimPose updatedMidTarget = AnimPose(midTargetRotation, afterSolveMidTarget.trans());
|
|
||||||
midTarget.setPose(updatedMidTarget.rot(), updatedMidTarget.trans());
|
|
||||||
midTarget.setWeight(1.0f);
|
|
||||||
midTarget.setFlexCoefficients(_numMidTargetFlexCoefficients, _midTargetFlexCoefficients);
|
|
||||||
|
|
||||||
AnimChain midJointChain;
|
// initialize the middle joint target
|
||||||
// Find the pose of the middle target's child. This is to correct the mid to tip
|
midTarget.setType((int)IKTarget::Type::Spline);
|
||||||
// after the base to mid spline is set.
|
midTarget.setIndex(_midJointIndex);
|
||||||
int childOfMiddleJointIndex = -1;
|
// set the middle joint to the position that was just determined by the base-tip spline.
|
||||||
AnimPose childOfMiddleJointAbsolutePoseAfterBaseTipSpline;
|
AnimPose afterSolveMidTarget = _skeleton->getAbsolutePose(_midJointIndex, _poses);
|
||||||
childOfMiddleJointIndex = _tipJointIndex;
|
// use the rotation from the ik target value, if there is one.
|
||||||
while (_skeleton->getParentIndex(childOfMiddleJointIndex) != _midJointIndex) {
|
glm::quat midTargetRotation = animVars.lookupRigToGeometry(_midRotationVar, afterSolveMidTarget.rot());
|
||||||
childOfMiddleJointIndex = _skeleton->getParentIndex(childOfMiddleJointIndex);
|
AnimPose updatedMidTarget = AnimPose(midTargetRotation, afterSolveMidTarget.trans());
|
||||||
|
midTarget.setPose(updatedMidTarget.rot(), updatedMidTarget.trans());
|
||||||
|
midTarget.setWeight(1.0f);
|
||||||
|
midTarget.setFlexCoefficients(_numMidTargetFlexCoefficients, _midTargetFlexCoefficients);
|
||||||
|
|
||||||
|
AnimChain midJointChain;
|
||||||
|
// Find the pose of the middle target's child. This is to correct the mid to tip
|
||||||
|
// after the base to mid spline is set.
|
||||||
|
int childOfMiddleJointIndex = -1;
|
||||||
|
AnimPose childOfMiddleJointAbsolutePoseAfterBaseTipSpline;
|
||||||
|
childOfMiddleJointIndex = _tipJointIndex;
|
||||||
|
while ((_skeleton->getParentIndex(childOfMiddleJointIndex) != _midJointIndex) && (childOfMiddleJointIndex != -1)) {
|
||||||
|
childOfMiddleJointIndex = _skeleton->getParentIndex(childOfMiddleJointIndex);
|
||||||
|
}
|
||||||
|
// if the middle joint is not actually between the base and the tip then don't create spline for it
|
||||||
|
if (childOfMiddleJointIndex != -1) {
|
||||||
|
childOfMiddleJointAbsolutePoseAfterBaseTipSpline = _skeleton->getAbsolutePose(childOfMiddleJointIndex, _poses);
|
||||||
|
|
||||||
|
AnimPoseVec absolutePosesAfterBaseTipSpline;
|
||||||
|
absolutePosesAfterBaseTipSpline.resize(_poses.size());
|
||||||
|
computeAbsolutePoses(absolutePosesAfterBaseTipSpline);
|
||||||
|
midJointChain.buildFromRelativePoses(_skeleton, _poses, midTarget.getIndex());
|
||||||
|
solveTargetWithSpline(context, midTarget, absolutePosesAfterBaseTipSpline, context.getEnableDebugDrawIKChains(), midJointChain);
|
||||||
|
midJointChain.outputRelativePoses(_poses);
|
||||||
|
|
||||||
|
// set the mid to tip segment to match the absolute rotation of the tip target.
|
||||||
|
AnimPose midTargetPose(midTarget.getRotation(), midTarget.getTranslation());
|
||||||
|
_poses[childOfMiddleJointIndex] = midTargetPose.inverse() * childOfMiddleJointAbsolutePoseAfterBaseTipSpline;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
childOfMiddleJointAbsolutePoseAfterBaseTipSpline = _skeleton->getAbsolutePose(childOfMiddleJointIndex, _poses);
|
|
||||||
|
|
||||||
AnimPoseVec absolutePosesAfterBaseTipSpline;
|
|
||||||
absolutePosesAfterBaseTipSpline.resize(_poses.size());
|
|
||||||
computeAbsolutePoses(absolutePosesAfterBaseTipSpline);
|
|
||||||
midJointChain.buildFromRelativePoses(_skeleton, _poses, midTarget.getIndex());
|
|
||||||
solveTargetWithSpline(context, midTarget, absolutePosesAfterBaseTipSpline, context.getEnableDebugDrawIKChains(), midJointChain);
|
|
||||||
midJointChain.outputRelativePoses(_poses);
|
|
||||||
|
|
||||||
// set the mid to tip segment to match the absolute rotation of the target.
|
|
||||||
AnimPose midTargetPose(midTarget.getRotation(), midTarget.getTranslation());
|
|
||||||
_poses[childOfMiddleJointIndex] = midTargetPose.inverse() * childOfMiddleJointAbsolutePoseAfterBaseTipSpline;
|
|
||||||
|
|
||||||
// compute chain
|
// compute chain
|
||||||
AnimChain ikChain;
|
AnimChain ikChain;
|
||||||
|
@ -249,11 +257,12 @@ const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const
|
||||||
QString name = QString("ikTargetSplineTip");
|
QString name = QString("ikTargetSplineTip");
|
||||||
DebugDraw::getInstance().addMyAvatarMarker(name, glmExtractRotation(avatarTargetMat), extractTranslation(avatarTargetMat), WHITE);
|
DebugDraw::getInstance().addMyAvatarMarker(name, glmExtractRotation(avatarTargetMat), extractTranslation(avatarTargetMat), WHITE);
|
||||||
|
|
||||||
glm::mat4 geomTargetMat2 = createMatFromQuatAndPos(midTarget.getRotation(), midTarget.getTranslation());
|
if (_midJointIndex != -1) {
|
||||||
glm::mat4 avatarTargetMat2 = rigToAvatarMat * context.getGeometryToRigMatrix() * geomTargetMat2;
|
glm::mat4 geomTargetMat2 = createMatFromQuatAndPos(midTarget.getRotation(), midTarget.getTranslation());
|
||||||
QString name2 = QString("ikTargetSplineMid");
|
glm::mat4 avatarTargetMat2 = rigToAvatarMat * context.getGeometryToRigMatrix() * geomTargetMat2;
|
||||||
DebugDraw::getInstance().addMyAvatarMarker(name2, glmExtractRotation(avatarTargetMat2), extractTranslation(avatarTargetMat2), WHITE);
|
QString name2 = QString("ikTargetSplineMid");
|
||||||
|
DebugDraw::getInstance().addMyAvatarMarker(name2, glmExtractRotation(avatarTargetMat2), extractTranslation(avatarTargetMat2), WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
glm::mat4 geomTargetMat3 = createMatFromQuatAndPos(baseTargetAbsolutePose.rot(), baseTargetAbsolutePose.trans());
|
glm::mat4 geomTargetMat3 = createMatFromQuatAndPos(baseTargetAbsolutePose.rot(), baseTargetAbsolutePose.trans());
|
||||||
glm::mat4 avatarTargetMat3 = rigToAvatarMat * context.getGeometryToRigMatrix() * geomTargetMat3;
|
glm::mat4 avatarTargetMat3 = rigToAvatarMat * context.getGeometryToRigMatrix() * geomTargetMat3;
|
||||||
|
@ -266,8 +275,10 @@ const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const
|
||||||
|
|
||||||
QString name = QString("ikTargetSplineTip");
|
QString name = QString("ikTargetSplineTip");
|
||||||
DebugDraw::getInstance().removeMyAvatarMarker(name);
|
DebugDraw::getInstance().removeMyAvatarMarker(name);
|
||||||
QString name2 = QString("ikTargetSplineMid");
|
if (_midJointIndex != -1) {
|
||||||
DebugDraw::getInstance().removeMyAvatarMarker(name2);
|
QString name2 = QString("ikTargetSplineMid");
|
||||||
|
DebugDraw::getInstance().removeMyAvatarMarker(name2);
|
||||||
|
}
|
||||||
QString name3 = QString("ikTargetSplineBase");
|
QString name3 = QString("ikTargetSplineBase");
|
||||||
DebugDraw::getInstance().removeMyAvatarMarker(name3);
|
DebugDraw::getInstance().removeMyAvatarMarker(name3);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue