From e5b16ef17466d2dae88a31704f5994bf3dc45192 Mon Sep 17 00:00:00 2001 From: amantley Date: Wed, 16 Jan 2019 18:31:52 -0800 Subject: [PATCH] implemented the splineIK in animSplineIK.cpp, todo: disable animinversekinematic.cpp --- .../resources/avatar/avatar-animation.json | 2 +- .../animation/src/AnimInverseKinematics.cpp | 13 ++++++-- libraries/animation/src/AnimSplineIK.cpp | 32 +++++++++++++------ libraries/animation/src/AnimStateMachine.cpp | 1 - libraries/animation/src/AnimTwoBoneIK.cpp | 2 -- libraries/fbx/src/FBXSerializer.cpp | 1 + 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/interface/resources/avatar/avatar-animation.json b/interface/resources/avatar/avatar-animation.json index 88ee1ff06b..16523afba3 100644 --- a/interface/resources/avatar/avatar-animation.json +++ b/interface/resources/avatar/avatar-animation.json @@ -173,7 +173,7 @@ "jointName": "Head", "positionVar": "headPosition", "rotationVar": "headRotation", - "typeVar": "headType", + "typeVar": "spine2Type", "weightVar": "headWeight", "weight": 4.0, "flexCoefficients": [ 1, 0.5, 0.25, 0.2, 0.1 ] diff --git a/libraries/animation/src/AnimInverseKinematics.cpp b/libraries/animation/src/AnimInverseKinematics.cpp index a6dcf5b2d9..e5509dc43d 100644 --- a/libraries/animation/src/AnimInverseKinematics.cpp +++ b/libraries/animation/src/AnimInverseKinematics.cpp @@ -237,12 +237,19 @@ void AnimInverseKinematics::solve(const AnimContext& context, const std::vector< // solve all targets for (size_t i = 0; i < targets.size(); i++) { - qCDebug(animation) << "target id: " << targets[i].getIndex() << " and type " << (int)targets[i].getType(); + // qCDebug(animation) << "target id: " << targets[i].getIndex() << " and type " << (int)targets[i].getType(); switch (targets[i].getType()) { case IKTarget::Type::Unknown: break; case IKTarget::Type::Spline: solveTargetWithSpline(context, targets[i], absolutePoses, debug, jointChainInfoVec[i]); + //if (jointChainInfoVec[i].target.getIndex() == _skeleton->nameToJointIndex("Head")) { + // qCDebug(animation) << "AnimIK spline index is " << targets[i].getIndex() << " and chain info size is " << jointChainInfoVec[i].jointInfoVec.size(); + for (int w = 0; w < jointChainInfoVec[i].jointInfoVec.size(); w++) { + // qCDebug(animation) << "joint " << jointChainInfoVec[i].jointInfoVec[w].jointIndex << " rotation is " << jointChainInfoVec[i].jointInfoVec[w].rot; + // qCDebug(animation) << "joint " << jointChainInfoVec[i].jointInfoVec[w].jointIndex << " translation is " << jointChainInfoVec[i].jointInfoVec[w].trans; + } + //} break; default: solveTargetWithCCD(context, targets[i], absolutePoses, debug, jointChainInfoVec[i]); @@ -259,6 +266,7 @@ void AnimInverseKinematics::solve(const AnimContext& context, const std::vector< // ease in expo alpha = 1.0f - powf(2.0f, -10.0f * alpha); + qCDebug(animation) << "the alpha for joint chains is " << alpha; size_t chainSize = std::min(_prevJointChainInfoVec[i].jointInfoVec.size(), jointChainInfoVec[i].jointInfoVec.size()); @@ -361,6 +369,7 @@ void AnimInverseKinematics::solve(const AnimContext& context, const std::vector< // copy jointChainInfoVec into _prevJointChainInfoVec, and update timers for (size_t i = 0; i < jointChainInfoVec.size(); i++) { _prevJointChainInfoVec[i].timer = _prevJointChainInfoVec[i].timer - dt; + //qCDebug(animation) << "the alpha for joint chains is " << _prevJointChainInfoVec[i].timer; if (_prevJointChainInfoVec[i].timer <= 0.0f) { _prevJointChainInfoVec[i] = jointChainInfoVec[i]; _prevJointChainInfoVec[i].target = targets[i]; @@ -860,7 +869,6 @@ void AnimInverseKinematics::solveTargetWithSpline(const AnimContext& context, co //virtual const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut) { // don't call this function, call overlay() instead - qCDebug(animation) << "called evaluate for inverse kinematics"; assert(false); return _relativePoses; } @@ -871,7 +879,6 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars // disable IK on android return underPoses; #endif - qCDebug(animation) << "called overlay for inverse kinematics"; // allows solutionSource to be overridden by an animVar auto solutionSource = animVars.lookup(_solutionSourceVar, (int)_solutionSource); diff --git a/libraries/animation/src/AnimSplineIK.cpp b/libraries/animation/src/AnimSplineIK.cpp index 65d7bfc821..442112e8f0 100644 --- a/libraries/animation/src/AnimSplineIK.cpp +++ b/libraries/animation/src/AnimSplineIK.cpp @@ -14,6 +14,8 @@ #include #include "AnimUtil.h" +static const float JOINT_CHAIN_INTERP_TIME = 0.5f; + AnimSplineIK::AnimSplineIK(const QString& id, float alpha, bool enabled, float interpDuration, const QString& baseJointName, const QString& tipJointName, @@ -39,7 +41,6 @@ AnimSplineIK::~AnimSplineIK() { } const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut) { - qCDebug(animation) << "evaluating the spline function"; assert(_children.size() == 1); if (_children.size() != 1) { return _poses; @@ -56,7 +57,7 @@ const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const IKTarget target; int jointIndex = _skeleton->nameToJointIndex("Head"); if (jointIndex != -1) { - target.setType(animVars.lookup("HeadType", (int)IKTarget::Type::RotationAndPosition)); + target.setType(animVars.lookup("headType", (int)IKTarget::Type::RotationAndPosition)); target.setIndex(jointIndex); AnimPose absPose = _skeleton->getAbsolutePose(jointIndex, _poses); glm::quat rotation = animVars.lookupRigToGeometry("headRotation", absPose.rot()); @@ -74,15 +75,30 @@ const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const } } if (_poses.size() > 0) { - AnimChain jointChain; - jointChain.buildFromRelativePoses(_skeleton, _poses, target.getIndex()); + AnimChain jointChain; + _snapshotChain.buildFromRelativePoses(_skeleton, _poses, target.getIndex()); + jointChain.buildFromRelativePoses(_skeleton, _poses, target.getIndex()); - // for each target solve target with spline - + // for each target solve target with spline solveTargetWithSpline(context, target, absolutePoses, false, jointChain); - qCDebug(animation) << "made it past the spline solve code"; + + // qCDebug(animation) << "AnimSpline Joint chain length " << jointChain.size(); + // jointChain.dump(); + jointChain.outputRelativePoses(_poses); + } + + const float FRAMES_PER_SECOND = 30.0f; + _interpAlphaVel = FRAMES_PER_SECOND / _interpDuration; + _alpha = _interpAlphaVel * dt; // we need to blend the old joint chain with the current joint chain, otherwise known as: _snapShotChain + // we blend the chain info then we accumulate it then we assign to relative poses then we return the value. + // make the alpha + // make the prevchain + // interp from the previous chain to the new chain/or underposes if the ik is disabled. + // update the relative poses and then we are done + + /**/ return _poses; } @@ -162,14 +178,12 @@ void AnimSplineIK::solveTargetWithSpline(const AnimContext& context, const IKTar if (glm::dot(halfRot * Vectors::UNIT_Z, basePose.rot() * Vectors::UNIT_Z) < 0.0f) { tipPose.rot() = -tipPose.rot(); } - qCDebug(animation) << "spot 1"; // find or create splineJointInfo for this target const std::vector* splineJointInfoVec = findOrCreateSplineJointInfo(context, target); if (splineJointInfoVec && splineJointInfoVec->size() > 0) { const int baseParentIndex = _skeleton->getParentIndex(baseIndex); AnimPose parentAbsPose = (baseParentIndex >= 0) ? absolutePoses[baseParentIndex] : AnimPose(); - qCDebug(animation) << "spot 2"; // go thru splineJointInfoVec backwards (base to tip) for (int i = (int)splineJointInfoVec->size() - 1; i >= 0; i--) { const SplineJointInfo& splineJointInfo = (*splineJointInfoVec)[i]; diff --git a/libraries/animation/src/AnimStateMachine.cpp b/libraries/animation/src/AnimStateMachine.cpp index 3042ad20f0..2c5d4ad0f3 100644 --- a/libraries/animation/src/AnimStateMachine.cpp +++ b/libraries/animation/src/AnimStateMachine.cpp @@ -22,7 +22,6 @@ AnimStateMachine::~AnimStateMachine() { } const AnimPoseVec& AnimStateMachine::evaluate(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut) { - qCDebug(animation) << "evaluating state machine"; float parentDebugAlpha = context.getDebugAlpha(_id); QString desiredStateID = animVars.lookup(_currentStateVar, _currentState->getID()); diff --git a/libraries/animation/src/AnimTwoBoneIK.cpp b/libraries/animation/src/AnimTwoBoneIK.cpp index d970e6b862..6334f6c4fd 100644 --- a/libraries/animation/src/AnimTwoBoneIK.cpp +++ b/libraries/animation/src/AnimTwoBoneIK.cpp @@ -46,8 +46,6 @@ AnimTwoBoneIK::~AnimTwoBoneIK() { const AnimPoseVec& AnimTwoBoneIK::evaluate(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut) { - qCDebug(animation) << "evaluating the 2 bone IK"; - assert(_children.size() == 1); if (_children.size() != 1) { return _poses; diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index 68019c2f4b..5e7258f069 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1308,6 +1308,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr joint.inverseBindRotation = joint.inverseDefaultRotation; joint.name = fbxModel.name; if (hfmModel.hfmToHifiJointNameMapping.contains(hfmModel.hfmToHifiJointNameMapping.key(joint.name))) { + // qCDebug(modelformat) << "joint name " << joint.name << " hifi name " << hfmModel.hfmToHifiJointNameMapping.key(fbxModel.name); joint.name = hfmModel.hfmToHifiJointNameMapping.key(fbxModel.name); }