cleaning up the _hipsIndex references, cleaning in general

This commit is contained in:
amantley 2019-01-28 11:50:23 -08:00
parent 2679a3a30d
commit f8bfef6dbd
4 changed files with 85 additions and 100 deletions

View file

@ -194,8 +194,8 @@
"enabledVar": "splineIKEnabled", "enabledVar": "splineIKEnabled",
"endEffectorRotationVarVar": "splineIKRotationVar", "endEffectorRotationVarVar": "splineIKRotationVar",
"endEffectorPositionVarVar": "splineIKPositionVar", "endEffectorPositionVarVar": "splineIKPositionVar",
"primaryFlexCoefficients": "1.0, 1.0, 1.0, 1.0, 1.0", "tipTargetFlexCoefficients": "1.0, 1.0, 1.0, 1.0, 1.0",
"secondaryFlexCoefficients": "1.0, 1.0, 1.0" "midTargetFlexCoefficients": "1.0, 1.0, 1.0"
}, },
"children": [ "children": [
{ {

View file

@ -596,14 +596,14 @@ static AnimNode::Pointer loadSplineIKNode(const QJsonObject& jsonObj, const QStr
READ_STRING(enabledVar, jsonObj, id, jsonUrl, nullptr); READ_STRING(enabledVar, jsonObj, id, jsonUrl, nullptr);
READ_STRING(endEffectorRotationVarVar, jsonObj, id, jsonUrl, nullptr); READ_STRING(endEffectorRotationVarVar, jsonObj, id, jsonUrl, nullptr);
READ_STRING(endEffectorPositionVarVar, jsonObj, id, jsonUrl, nullptr); READ_STRING(endEffectorPositionVarVar, jsonObj, id, jsonUrl, nullptr);
READ_STRING(primaryFlexCoefficients, jsonObj, id, jsonUrl, nullptr); READ_STRING(tipTargetFlexCoefficients, jsonObj, id, jsonUrl, nullptr);
READ_STRING(secondaryFlexCoefficients, jsonObj, id, jsonUrl, nullptr); READ_STRING(midTargetFlexCoefficients, jsonObj, id, jsonUrl, nullptr);
auto node = std::make_shared<AnimSplineIK>(id, alpha, enabled, interpDuration, auto node = std::make_shared<AnimSplineIK>(id, alpha, enabled, interpDuration,
baseJointName, midJointName, tipJointName, baseJointName, midJointName, tipJointName,
alphaVar, enabledVar, endEffectorRotationVarVar, endEffectorPositionVarVar, alphaVar, enabledVar, endEffectorRotationVarVar, endEffectorPositionVarVar,
basePositionVar, baseRotationVar, midPositionVar, midRotationVar, basePositionVar, baseRotationVar, midPositionVar, midRotationVar,
tipPositionVar, tipRotationVar, primaryFlexCoefficients, secondaryFlexCoefficients); tipPositionVar, tipRotationVar, tipTargetFlexCoefficients, midTargetFlexCoefficients);
return node; return node;
} }

View file

@ -29,8 +29,8 @@ AnimSplineIK::AnimSplineIK(const QString& id, float alpha, bool enabled, float i
const QString& midRotationVar, const QString& midRotationVar,
const QString& tipPositionVar, const QString& tipPositionVar,
const QString& tipRotationVar, const QString& tipRotationVar,
const QString& primaryFlexCoefficients, const QString& tipTargetFlexCoefficients,
const QString& secondaryFlexCoefficients) : const QString& midTargetFlexCoefficients) :
AnimNode(AnimNode::Type::SplineIK, id), AnimNode(AnimNode::Type::SplineIK, id),
_alpha(alpha), _alpha(alpha),
_enabled(enabled), _enabled(enabled),
@ -52,22 +52,22 @@ AnimSplineIK::AnimSplineIK(const QString& id, float alpha, bool enabled, float i
_tipRotationVar(tipRotationVar) _tipRotationVar(tipRotationVar)
{ {
QStringList flexCoefficientsValues = primaryFlexCoefficients.split(',', QString::SkipEmptyParts); QStringList tipTargetFlexCoefficientsValues = tipTargetFlexCoefficients.split(',', QString::SkipEmptyParts);
for (int i = 0; i < flexCoefficientsValues.size(); i++) { for (int i = 0; i < tipTargetFlexCoefficientsValues.size(); i++) {
if (i < MAX_NUMBER_FLEX_VARIABLES) { if (i < MAX_NUMBER_FLEX_VARIABLES) {
qCDebug(animation) << "flex value " << flexCoefficientsValues[i].toDouble(); qCDebug(animation) << "tip target flex value " << tipTargetFlexCoefficientsValues[i].toDouble();
_primaryFlexCoefficients[i] = (float)flexCoefficientsValues[i].toDouble(); _tipTargetFlexCoefficients[i] = (float)tipTargetFlexCoefficientsValues[i].toDouble();
} }
} }
_numPrimaryFlexCoefficients = std::min(flexCoefficientsValues.size(), MAX_NUMBER_FLEX_VARIABLES); _numTipTargetFlexCoefficients = std::min(tipTargetFlexCoefficientsValues.size(), MAX_NUMBER_FLEX_VARIABLES);
QStringList secondaryFlexCoefficientsValues = secondaryFlexCoefficients.split(',', QString::SkipEmptyParts); QStringList midTargetFlexCoefficientsValues = midTargetFlexCoefficients.split(',', QString::SkipEmptyParts);
for (int i = 0; i < secondaryFlexCoefficientsValues.size(); i++) { for (int i = 0; i < midTargetFlexCoefficientsValues.size(); i++) {
if (i < MAX_NUMBER_FLEX_VARIABLES) { if (i < MAX_NUMBER_FLEX_VARIABLES) {
qCDebug(animation) << "secondaryflex value " << secondaryFlexCoefficientsValues[i].toDouble(); qCDebug(animation) << "mid target flex value " << midTargetFlexCoefficientsValues[i].toDouble();
_secondaryFlexCoefficients[i] = (float)secondaryFlexCoefficientsValues[i].toDouble(); _midTargetFlexCoefficients[i] = (float)midTargetFlexCoefficientsValues[i].toDouble();
} }
} }
_numSecondaryFlexCoefficients = std::min(secondaryFlexCoefficientsValues.size(), MAX_NUMBER_FLEX_VARIABLES); _numMidTargetFlexCoefficients = std::min(midTargetFlexCoefficientsValues.size(), MAX_NUMBER_FLEX_VARIABLES);
} }
@ -130,86 +130,79 @@ const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const
AnimChain underChain; AnimChain underChain;
underChain.buildFromRelativePoses(_skeleton, underPoses, _tipJointIndex); underChain.buildFromRelativePoses(_skeleton, underPoses, _tipJointIndex);
glm::quat hipsTargetRotation; glm::quat baseTargetRotation;
glm::vec3 hipsTargetTranslation; glm::vec3 baseTargetTranslation;
// now we override the hips with the hips target pose. // now we override the hips with the hips target pose.
// if there is a baseJoint ik target in animvars then use that
// otherwise use the underpose
if (_poses.size() > 0) { if (_poses.size() > 0) {
AnimPose hipsUnderPose = _skeleton->getAbsolutePose(_hipsIndex, _poses); AnimPose baseJointUnderPose = _skeleton->getAbsolutePose(_baseJointIndex, _poses);
hipsTargetRotation = animVars.lookupRigToGeometry("hipsRotation", hipsUnderPose.rot()); baseTargetRotation = animVars.lookupRigToGeometry(_baseRotationVar, baseJointUnderPose.rot());
hipsTargetTranslation = animVars.lookupRigToGeometry("hipsPosition", hipsUnderPose.trans()); baseTargetTranslation = animVars.lookupRigToGeometry(_basePositionVar, baseJointUnderPose.trans());
AnimPose absHipsTargetPose(hipsTargetRotation, hipsTargetTranslation); AnimPose absBaseTargetPose(baseTargetRotation, baseTargetTranslation);
int hipsParentIndex = _skeleton->getParentIndex(_hipsIndex); int baseParentIndex = _skeleton->getParentIndex(_baseJointIndex);
AnimPose hipsParentAbsPose = _skeleton->getAbsolutePose(hipsParentIndex, _poses); AnimPose baseParentAbsPose(Quaternions::IDENTITY,glm::vec3());
if (baseParentIndex >= 0) {
baseParentAbsPose = _skeleton->getAbsolutePose(baseParentIndex, _poses);
}
_poses[_hipsIndex] = hipsParentAbsPose.inverse() * absHipsTargetPose; _poses[_baseJointIndex] = baseParentAbsPose.inverse() * absBaseTargetPose;
_poses[_hipsIndex].scale() = glm::vec3(1.0f); _poses[_baseJointIndex].scale() = glm::vec3(1.0f);
} }
AnimPoseVec absolutePoses; IKTarget tipTarget;
absolutePoses.resize(_poses.size());
computeAbsolutePoses(absolutePoses);
IKTarget target;
if (_tipJointIndex != -1) { if (_tipJointIndex != -1) {
target.setType((int)IKTarget::Type::Spline); tipTarget.setType((int)IKTarget::Type::Spline);
target.setIndex(_tipJointIndex); tipTarget.setIndex(_tipJointIndex);
AnimPose absPose = _skeleton->getAbsolutePose(_tipJointIndex, _poses); AnimPose absPose = _skeleton->getAbsolutePose(_tipJointIndex, _poses);
glm::quat rotation = animVars.lookupRigToGeometry(_tipRotationVar, absPose.rot()); glm::quat rotation = animVars.lookupRigToGeometry(_tipRotationVar, absPose.rot());
glm::vec3 translation = animVars.lookupRigToGeometry(_tipPositionVar, absPose.trans()); glm::vec3 translation = animVars.lookupRigToGeometry(_tipPositionVar, absPose.trans());
float weight = 1.0f; tipTarget.setPose(rotation, translation);
tipTarget.setWeight(1.0f);
target.setPose(rotation, translation); tipTarget.setFlexCoefficients(_numTipTargetFlexCoefficients, _tipTargetFlexCoefficients);
target.setWeight(weight);
const float* flexCoefficients = new float[5]{ 1.0f, 0.5f, 0.25f, 0.2f, 0.1f };
target.setFlexCoefficients(_numPrimaryFlexCoefficients, _primaryFlexCoefficients);
} }
AnimChain jointChain; AnimChain jointChain;
AnimPose updatedSecondaryTarget;
AnimPoseVec absolutePoses2;
absolutePoses2.resize(_poses.size());
if (_poses.size() > 0) { if (_poses.size() > 0) {
jointChain.buildFromRelativePoses(_skeleton, _poses, target.getIndex()); AnimPoseVec absolutePoses;
solveTargetWithSpline(context, target, absolutePoses, false, jointChain); absolutePoses.resize(_poses.size());
computeAbsolutePoses(absolutePoses);
jointChain.buildFromRelativePoses(_skeleton, _poses, tipTarget.getIndex());
solveTargetWithSpline(context, tipTarget, absolutePoses, false, jointChain);
jointChain.buildDirtyAbsolutePoses(); jointChain.buildDirtyAbsolutePoses();
qCDebug(animation) << "the jointChain Result for head " << jointChain.getAbsolutePoseFromJointIndex(_tipJointIndex);
qCDebug(animation) << "the orig target pose for head " << target.getPose();
jointChain.outputRelativePoses(_poses); jointChain.outputRelativePoses(_poses);
AnimPose afterSolveSecondaryTarget = _skeleton->getAbsolutePose(_midJointIndex, _poses);
glm::quat secondaryTargetRotation = animVars.lookupRigToGeometry(_midRotationVar, afterSolveSecondaryTarget.rot());
updatedSecondaryTarget = AnimPose(secondaryTargetRotation, afterSolveSecondaryTarget.trans());
//updatedSecondaryTarget = AnimPose(afterSolveSecondaryTarget.rot(), afterSolveSecondaryTarget.trans());
} }
IKTarget secondaryTarget; IKTarget midTarget;
computeAbsolutePoses(absolutePoses2);
if (_midJointIndex != -1) { if (_midJointIndex != -1) {
secondaryTarget.setType((int)IKTarget::Type::Spline); midTarget.setType((int)IKTarget::Type::Spline);
secondaryTarget.setIndex(_midJointIndex); midTarget.setIndex(_midJointIndex);
float weight2 = 1.0f; // set the middle joint to the position that is determined by the base-tip spline.
secondaryTarget.setPose(updatedSecondaryTarget.rot(), updatedSecondaryTarget.trans()); AnimPose afterSolveMidTarget = _skeleton->getAbsolutePose(_midJointIndex, _poses);
secondaryTarget.setWeight(weight2); glm::quat midTargetRotation = animVars.lookupRigToGeometry(_midRotationVar, afterSolveMidTarget.rot());
AnimPose updatedMidTarget = AnimPose(midTargetRotation, afterSolveMidTarget.trans());
const float* flexCoefficients2 = new float[3]{ 1.0f, 0.5f, 0.25f }; midTarget.setPose(updatedMidTarget.rot(), updatedMidTarget.trans());
secondaryTarget.setFlexCoefficients(_numSecondaryFlexCoefficients, _secondaryFlexCoefficients); midTarget.setWeight(1.0f);
midTarget.setFlexCoefficients(_numMidTargetFlexCoefficients, _midTargetFlexCoefficients);
} }
AnimChain secondaryJointChain; AnimChain midJointChain;
AnimPose beforeSolveChestNeck; AnimPose beforeSolveChestNeck;
int startJoint; int startJoint;
AnimPose correctJoint; AnimPose correctJoint;
if (_poses.size() > 0) { if (_poses.size() > 0) {
AnimPoseVec absolutePoses2;
absolutePoses2.resize(_poses.size());
computeAbsolutePoses(absolutePoses2);
// start at the tip // start at the tip
for (startJoint = _tipJointIndex; _skeleton->getParentIndex(startJoint) != _midJointIndex; startJoint = _skeleton->getParentIndex(startJoint)) { for (startJoint = _tipJointIndex; _skeleton->getParentIndex(startJoint) != _midJointIndex; startJoint = _skeleton->getParentIndex(startJoint)) {
// find the child of the midJoint // find the child of the midJoint
} }
@ -218,25 +211,25 @@ const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const
// fix this to deal with no neck AA // fix this to deal with no neck AA
beforeSolveChestNeck = _skeleton->getAbsolutePose(_skeleton->nameToJointIndex("Neck"), _poses); beforeSolveChestNeck = _skeleton->getAbsolutePose(_skeleton->nameToJointIndex("Neck"), _poses);
secondaryJointChain.buildFromRelativePoses(_skeleton, _poses, secondaryTarget.getIndex()); midJointChain.buildFromRelativePoses(_skeleton, _poses, midTarget.getIndex());
solveTargetWithSpline(context, secondaryTarget, absolutePoses2, false, secondaryJointChain); solveTargetWithSpline(context, midTarget, absolutePoses2, false, midJointChain);
secondaryJointChain.outputRelativePoses(_poses); midJointChain.outputRelativePoses(_poses);
} }
// set the tip/head rotation to match the absolute rotation of the target. // set the tip/head rotation to match the absolute rotation of the target.
int tipParent = _skeleton->getParentIndex(_tipJointIndex); int tipParent = _skeleton->getParentIndex(_tipJointIndex);
int secondaryTargetParent = _skeleton->getParentIndex(_midJointIndex); int midTargetParent = _skeleton->getParentIndex(_midJointIndex);
if ((secondaryTargetParent != -1) && (tipParent != -1) && (_poses.size() > 0)) { if ((midTargetParent != -1) && (tipParent != -1) && (_poses.size() > 0)) {
AnimPose secondaryTargetPose(secondaryTarget.getRotation(), secondaryTarget.getTranslation()); AnimPose midTargetPose(midTarget.getRotation(), midTarget.getTranslation());
//AnimPose neckAbsolute = _skeleton->getAbsolutePose(tipParent, _poses); //AnimPose neckAbsolute = _skeleton->getAbsolutePose(tipParent, _poses);
//_poses[tipParent] = secondaryTargetPose.inverse() * beforeSolveChestNeck; //_poses[tipParent] = midTargetPose.inverse() * beforeSolveChestNeck;
_poses[startJoint] = secondaryTargetPose.inverse() * correctJoint; _poses[startJoint] = midTargetPose.inverse() * correctJoint;
//AnimPose tipTarget(target.getRotation(),target.getTranslation()); //AnimPose tipTargetPose(tipTarget.getRotation(),tipTarget.getTranslation());
//AnimPose tipRelativePose = _skeleton->getAbsolutePose(tipParent,_poses).inverse() * tipTarget; //AnimPose tipRelativePose = _skeleton->getAbsolutePose(tipParent,_poses).inverse() * tipTargetPose;
//_poses[_tipJointIndex] = tipRelativePose; //_poses[_tipJointIndex] = tipRelativePose;
} }
@ -286,31 +279,31 @@ const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const
const vec4 GREEN(0.0f, 1.0f, 0.0f, 1.0f); const vec4 GREEN(0.0f, 1.0f, 0.0f, 1.0f);
glm::mat4 rigToAvatarMat = createMatFromQuatAndPos(Quaternions::Y_180, glm::vec3()); glm::mat4 rigToAvatarMat = createMatFromQuatAndPos(Quaternions::Y_180, glm::vec3());
glm::mat4 geomTargetMat = createMatFromQuatAndPos(target.getRotation(), target.getTranslation()); glm::mat4 geomTargetMat = createMatFromQuatAndPos(tipTarget.getRotation(), tipTarget.getTranslation());
glm::mat4 avatarTargetMat = rigToAvatarMat * context.getGeometryToRigMatrix() * geomTargetMat; glm::mat4 avatarTargetMat = rigToAvatarMat * context.getGeometryToRigMatrix() * geomTargetMat;
QString name = QString("ikTargetHead"); 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(secondaryTarget.getRotation(), secondaryTarget.getTranslation()); glm::mat4 geomTargetMat2 = createMatFromQuatAndPos(midTarget.getRotation(), midTarget.getTranslation());
glm::mat4 avatarTargetMat2 = rigToAvatarMat * context.getGeometryToRigMatrix() * geomTargetMat2; glm::mat4 avatarTargetMat2 = rigToAvatarMat * context.getGeometryToRigMatrix() * geomTargetMat2;
QString name2 = QString("ikTargetSpine2"); QString name2 = QString("ikTargetSplineMid");
DebugDraw::getInstance().addMyAvatarMarker(name2, glmExtractRotation(avatarTargetMat2), extractTranslation(avatarTargetMat2), WHITE); DebugDraw::getInstance().addMyAvatarMarker(name2, glmExtractRotation(avatarTargetMat2), extractTranslation(avatarTargetMat2), WHITE);
glm::mat4 geomTargetMat3 = createMatFromQuatAndPos(hipsTargetRotation, hipsTargetTranslation); glm::mat4 geomTargetMat3 = createMatFromQuatAndPos(baseTargetRotation,baseTargetTranslation);
glm::mat4 avatarTargetMat3 = rigToAvatarMat * context.getGeometryToRigMatrix() * geomTargetMat3; glm::mat4 avatarTargetMat3 = rigToAvatarMat * context.getGeometryToRigMatrix() * geomTargetMat3;
QString name3 = QString("ikTargetHips"); QString name3 = QString("ikTargetSplineBase");
DebugDraw::getInstance().addMyAvatarMarker(name3, glmExtractRotation(avatarTargetMat3), extractTranslation(avatarTargetMat3), WHITE); DebugDraw::getInstance().addMyAvatarMarker(name3, glmExtractRotation(avatarTargetMat3), extractTranslation(avatarTargetMat3), WHITE);
} else if (context.getEnableDebugDrawIKTargets() != _previousEnableDebugIKTargets) { } else if (context.getEnableDebugDrawIKTargets() != _previousEnableDebugIKTargets) {
// remove markers if they were added last frame. // remove markers if they were added last frame.
QString name = QString("ikTargetHead"); QString name = QString("ikTargetSplineTip");
DebugDraw::getInstance().removeMyAvatarMarker(name); DebugDraw::getInstance().removeMyAvatarMarker(name);
QString name2 = QString("ikTargetSpine2"); QString name2 = QString("ikTargetSplineMid");
DebugDraw::getInstance().removeMyAvatarMarker(name2); DebugDraw::getInstance().removeMyAvatarMarker(name2);
QString name3 = QString("ikTargetHips"); QString name3 = QString("ikTargetSplineBase");
DebugDraw::getInstance().removeMyAvatarMarker(name3); DebugDraw::getInstance().removeMyAvatarMarker(name3);
} }
@ -356,8 +349,6 @@ const AnimPoseVec& AnimSplineIK::getPosesInternal() const {
void AnimSplineIK::setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) { void AnimSplineIK::setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) {
AnimNode::setSkeletonInternal(skeleton); AnimNode::setSkeletonInternal(skeleton);
//_headIndex = _skeleton->nameToJointIndex("Head");
_hipsIndex = _skeleton->nameToJointIndex("Hips");
lookUpIndices(); lookUpIndices();
} }

View file

@ -19,14 +19,12 @@
class AnimSplineIK : public AnimNode { class AnimSplineIK : public AnimNode {
public: public:
AnimSplineIK(const QString& id, float alpha, bool enabled, float interpDuration, AnimSplineIK(const QString& id, float alpha, bool enabled, float interpDuration,
const QString& baseJointName, const QString& tipJointName, const QString& baseJointName, const QString& midJointName, const QString& tipJointName,
const QString& alphaVar, const QString& enabledVar, const QString& alphaVar, const QString& enabledVar,
const QString& endEffectorRotationVarVar, const QString& endEffectorPositionVarVar, const QString& endEffectorRotationVarVar, const QString& endEffectorPositionVarVar,
const QString& basePositionVar, const QString& baseRotationVar, const QString& basePositionVar, const QString& baseRotationVar,
const QString& midPositionVar, const QString& midRotationVar,
const QString& tipPositionVar, const QString& tipRotationVar, const QString& tipPositionVar, const QString& tipRotationVar,
const QString& secondaryTargetJointName,
const QString& secondaryTargetPositionVar,
const QString& secondaryTargetRotationVar,
const QString& primaryFlexCoefficients, const QString& primaryFlexCoefficients,
const QString& secondaryFlexCoefficients); const QString& secondaryFlexCoefficients);
@ -69,19 +67,15 @@ protected:
QString _tipRotationVar; QString _tipRotationVar;
static const int MAX_NUMBER_FLEX_VARIABLES = 10; static const int MAX_NUMBER_FLEX_VARIABLES = 10;
float _primaryFlexCoefficients[MAX_NUMBER_FLEX_VARIABLES]; float _tipTargetFlexCoefficients[MAX_NUMBER_FLEX_VARIABLES];
float _secondaryFlexCoefficients[MAX_NUMBER_FLEX_VARIABLES]; float _midTargetFlexCoefficients[MAX_NUMBER_FLEX_VARIABLES];
int _numPrimaryFlexCoefficients { 0 }; int _numTipTargetFlexCoefficients { 0 };
int _numSecondaryFlexCoefficients { 0 }; int _numMidTargetFlexCoefficients { 0 };
int _baseParentJointIndex { -1 }; int _baseParentJointIndex { -1 };
int _baseJointIndex { -1 }; int _baseJointIndex { -1 };
int _midJointIndex { -1 }; int _midJointIndex { -1 };
int _tipJointIndex { -1 }; int _tipJointIndex { -1 };
int _headIndex { -1 };
int _hipsIndex { -1 };
int _spine2Index { -1 };
int _hipsTargetIndex { -1 };
QString _alphaVar; // float - (0, 1) 0 means underPoses only, 1 means IK only. QString _alphaVar; // float - (0, 1) 0 means underPoses only, 1 means IK only.
QString _enabledVar; // bool QString _enabledVar; // bool