Removal of hips offset shifting from AnimInverseKinematics node

With the addition of the hips IK target, the hips offset shifting code is no longer necessary.
This PR should not effect any behavior, but it removes this unused code from the animation system.
This commit is contained in:
Anthony J. Thibault 2018-01-31 17:56:33 -08:00
parent 59a088f226
commit b23f98b311
6 changed files with 0 additions and 138 deletions

View file

@ -3238,8 +3238,6 @@ bool MyAvatar::pinJoint(int index, const glm::vec3& position, const glm::quat& o
slamPosition(position);
setWorldOrientation(orientation);
_skeletonModel->getRig().setMaxHipsOffsetLength(0.05f);
auto it = std::find(_pinnedJoints.begin(), _pinnedJoints.end(), index);
if (it == _pinnedJoints.end()) {
_pinnedJoints.push_back(index);
@ -3259,12 +3257,6 @@ bool MyAvatar::clearPinOnJoint(int index) {
auto it = std::find(_pinnedJoints.begin(), _pinnedJoints.end(), index);
if (it != _pinnedJoints.end()) {
_pinnedJoints.erase(it);
auto hipsIndex = getJointIndex("Hips");
if (index == hipsIndex) {
_skeletonModel->getRig().setMaxHipsOffsetLength(FLT_MAX);
}
return true;
}
return false;

View file

@ -43,8 +43,6 @@ static AnimPose computeHipsInSensorFrame(MyAvatar* myAvatar, bool isFlying) {
AnimPose result = AnimPose(worldToSensorMat * avatarTransform.getMatrix() * Matrices::Y_180);
result.scale() = glm::vec3(1.0f, 1.0f, 1.0f);
return result;
} else {
DebugDraw::getInstance().removeMarker("pinnedHips");
}
glm::mat4 hipsMat = myAvatar->deriveBodyFromHMDSensor();

View file

@ -880,25 +880,6 @@ const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVar
return _relativePoses;
}
AnimPose AnimInverseKinematics::applyHipsOffset() const {
glm::vec3 hipsOffset = _hipsOffset;
AnimPose relHipsPose = _relativePoses[_hipsIndex];
float offsetLength = glm::length(hipsOffset);
const float MIN_HIPS_OFFSET_LENGTH = 0.03f;
if (offsetLength > MIN_HIPS_OFFSET_LENGTH) {
float scaleFactor = ((offsetLength - MIN_HIPS_OFFSET_LENGTH) / offsetLength);
glm::vec3 scaledHipsOffset = scaleFactor * hipsOffset;
if (_hipsParentIndex == -1) {
relHipsPose.trans() = _relativePoses[_hipsIndex].trans() + scaledHipsOffset;
} else {
AnimPose absHipsPose = _skeleton->getAbsolutePose(_hipsIndex, _relativePoses);
absHipsPose.trans() += scaledHipsOffset;
relHipsPose = _skeleton->getAbsolutePose(_hipsParentIndex, _relativePoses).inverse() * absHipsPose;
}
}
return relHipsPose;
}
//virtual
const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars, const AnimContext& context, float dt, Triggers& triggersOut, const AnimPoseVec& underPoses) {
// allows solutionSource to be overridden by an animVar
@ -996,27 +977,6 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
_relativePoses[_hipsIndex] = parentAbsPose.inverse() * absPose;
_relativePoses[_hipsIndex].scale() = glm::vec3(1.0f);
_hipsOffset = Vectors::ZERO;
} else if (_hipsIndex >= 0) {
// if there is no hips target, shift hips according to the _hipsOffset from the previous frame
AnimPose relHipsPose = applyHipsOffset();
// determine if we should begin interpolating the hips.
for (size_t i = 0; i < targets.size(); i++) {
if (_prevJointChainInfoVec[i].target.getIndex() == _hipsIndex) {
if (_prevJointChainInfoVec[i].timer > 0.0f) {
// smoothly lerp in hipsOffset
float alpha = (JOINT_CHAIN_INTERP_TIME - _prevJointChainInfoVec[i].timer) / JOINT_CHAIN_INTERP_TIME;
AnimPose prevRelHipsPose(_prevJointChainInfoVec[i].jointInfoVec[0].rot, _prevJointChainInfoVec[i].jointInfoVec[0].trans);
::blend(1, &prevRelHipsPose, &relHipsPose, alpha, &relHipsPose);
}
break;
}
}
_relativePoses[_hipsIndex] = relHipsPose;
}
// if there is an active jointChainInfo for the hips store the post shifted hips into it.
@ -1084,11 +1044,6 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
solve(context, targets, dt, jointChainInfoVec);
}
if (_hipsTargetIndex < 0) {
PROFILE_RANGE_EX(simulation_animation, "ik/measureHipsOffset", 0xffff00ff, 0);
_hipsOffset = computeHipsOffset(targets, underPoses, dt, _hipsOffset);
}
}
if (context.getEnableDebugDrawIKConstraints()) {
@ -1099,69 +1054,6 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
return _relativePoses;
}
glm::vec3 AnimInverseKinematics::computeHipsOffset(const std::vector<IKTarget>& targets, const AnimPoseVec& underPoses, float dt, glm::vec3 prevHipsOffset) const {
// measure new _hipsOffset for next frame
// by looking for discrepancies between where a targeted endEffector is
// and where it wants to be (after IK solutions are done)
glm::vec3 hipsOffset = prevHipsOffset;
glm::vec3 newHipsOffset = Vectors::ZERO;
for (auto& target: targets) {
int targetIndex = target.getIndex();
if (targetIndex == _headIndex && _headIndex != -1) {
// special handling for headTarget
if (target.getType() == IKTarget::Type::RotationOnly) {
// we want to shift the hips to bring the underPose closer
// to where the head happens to be (overpose)
glm::vec3 under = _skeleton->getAbsolutePose(_headIndex, underPoses).trans();
glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans();
const float HEAD_OFFSET_SLAVE_FACTOR = 0.65f;
newHipsOffset += HEAD_OFFSET_SLAVE_FACTOR * (actual - under);
} else if (target.getType() == IKTarget::Type::HmdHead) {
// we want to shift the hips to bring the head to its designated position
glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans();
hipsOffset += target.getTranslation() - actual;
// and ignore all other targets
newHipsOffset = hipsOffset;
break;
} else if (target.getType() == IKTarget::Type::RotationAndPosition) {
glm::vec3 actualPosition = _skeleton->getAbsolutePose(targetIndex, _relativePoses).trans();
glm::vec3 targetPosition = target.getTranslation();
newHipsOffset += targetPosition - actualPosition;
// Add downward pressure on the hips
const float PRESSURE_SCALE_FACTOR = 0.95f;
const float PRESSURE_TRANSLATION_OFFSET = 1.0f;
newHipsOffset *= PRESSURE_SCALE_FACTOR;
newHipsOffset -= PRESSURE_TRANSLATION_OFFSET;
}
} else if (target.getType() == IKTarget::Type::RotationAndPosition) {
glm::vec3 actualPosition = _skeleton->getAbsolutePose(targetIndex, _relativePoses).trans();
glm::vec3 targetPosition = target.getTranslation();
newHipsOffset += targetPosition - actualPosition;
}
}
// smooth transitions by relaxing hipsOffset toward the new value
const float HIPS_OFFSET_SLAVE_TIMESCALE = 0.10f;
float tau = dt < HIPS_OFFSET_SLAVE_TIMESCALE ? dt / HIPS_OFFSET_SLAVE_TIMESCALE : 1.0f;
hipsOffset += (newHipsOffset - hipsOffset) * tau;
// clamp the hips offset
float hipsOffsetLength = glm::length(hipsOffset);
if (hipsOffsetLength > _maxHipsOffsetLength) {
hipsOffset *= _maxHipsOffsetLength / hipsOffsetLength;
}
return hipsOffset;
}
void AnimInverseKinematics::setMaxHipsOffsetLength(float maxLength) {
// manually adjust scale here
const float METERS_TO_CENTIMETERS = 100.0f;
_maxHipsOffsetLength = METERS_TO_CENTIMETERS * maxLength;
}
void AnimInverseKinematics::clearIKJointLimitHistory() {
for (auto& pair : _constraints) {
pair.second->clearHistory();

View file

@ -57,8 +57,6 @@ public:
void clearIKJointLimitHistory();
void setMaxHipsOffsetLength(float maxLength);
float getMaxErrorOnLastSolve() { return _maxErrorOnLastSolve; }
enum class SolutionSource {
@ -92,7 +90,6 @@ protected:
void blendToPoses(const AnimPoseVec& targetPoses, const AnimPoseVec& underPose, float blendFactor);
void preconditionRelativePosesToAvoidLimbLock(const AnimContext& context, const std::vector<IKTarget>& targets);
void setSecondaryTargets(const AnimContext& context);
AnimPose applyHipsOffset() const;
// used to pre-compute information about each joint influeced by a spline IK target.
struct SplineJointInfo {
@ -111,7 +108,6 @@ protected:
void clearConstraints();
void initConstraints();
void initLimitCenterPoses();
glm::vec3 computeHipsOffset(const std::vector<IKTarget>& targets, const AnimPoseVec& underPoses, float dt, glm::vec3 prevHipsOffset) const;
// no copies
AnimInverseKinematics(const AnimInverseKinematics&) = delete;
@ -150,9 +146,6 @@ protected:
mutable std::map<int, std::vector<SplineJointInfo>> _splineJointInfoMap;
// experimental data for moving hips during IK
glm::vec3 _hipsOffset { Vectors::ZERO };
float _maxHipsOffsetLength{ FLT_MAX };
int _headIndex { -1 };
int _hipsIndex { -1 };
int _hipsParentIndex { -1 };

View file

@ -372,18 +372,6 @@ void Rig::clearIKJointLimitHistory() {
}
}
void Rig::setMaxHipsOffsetLength(float maxLength) {
_maxHipsOffsetLength = maxLength;
auto ikNode = getAnimInverseKinematicsNode();
if (ikNode) {
ikNode->setMaxHipsOffsetLength(_maxHipsOffsetLength);
}
}
float Rig::getMaxHipsOffsetLength() const {
return _maxHipsOffsetLength;
}
float Rig::getIKErrorOnLastSolve() const {
float result = 0.0f;

View file

@ -346,7 +346,6 @@ protected:
bool _enabledAnimations { true };
mutable uint32_t _jointNameWarningCount { 0 };
float _maxHipsOffsetLength { 1.0f };
bool _enableDebugDrawIKTargets { false };
bool _enableDebugDrawIKConstraints { false };