implemented the splineIK in animSplineIK.cpp, todo: disable animinversekinematic.cpp

This commit is contained in:
amantley 2019-01-16 18:31:52 -08:00
parent 33ff5188c1
commit e5b16ef174
6 changed files with 35 additions and 16 deletions

View file

@ -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 ]

View file

@ -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);

View file

@ -14,6 +14,8 @@
#include <DebugDraw.h>
#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<SplineJointInfo>* 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];

View file

@ -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());

View file

@ -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;

View file

@ -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);
}