mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 16:38:27 +02:00
Merge pull request #5910 from hyperlogic/tony/small-anim-debug-improvements
Fix for Head when switching between HMD and Desktop mode
This commit is contained in:
commit
e6b9cbacf7
5 changed files with 82 additions and 29 deletions
|
@ -246,33 +246,36 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
|
||||||
Hand* hand = _owningAvatar->getHand();
|
Hand* hand = _owningAvatar->getHand();
|
||||||
hand->getLeftRightPalmIndices(leftPalmIndex, rightPalmIndex);
|
hand->getLeftRightPalmIndices(leftPalmIndex, rightPalmIndex);
|
||||||
|
|
||||||
const float HAND_RESTORATION_RATE = 0.25f;
|
// Don't Relax toward hand positions when in animGraph mode.
|
||||||
if (leftPalmIndex == -1 && rightPalmIndex == -1) {
|
if (!_rig->getEnableAnimGraph()) {
|
||||||
// palms are not yet set, use mouse
|
const float HAND_RESTORATION_RATE = 0.25f;
|
||||||
if (_owningAvatar->getHandState() == HAND_STATE_NULL) {
|
if (leftPalmIndex == -1 && rightPalmIndex == -1) {
|
||||||
restoreRightHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY);
|
// palms are not yet set, use mouse
|
||||||
} else {
|
if (_owningAvatar->getHandState() == HAND_STATE_NULL) {
|
||||||
// transform into model-frame
|
restoreRightHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY);
|
||||||
glm::vec3 handPosition = glm::inverse(_rotation) * (_owningAvatar->getHandPosition() - _translation);
|
} else {
|
||||||
applyHandPosition(geometry.rightHandJointIndex, handPosition);
|
// transform into model-frame
|
||||||
}
|
glm::vec3 handPosition = glm::inverse(_rotation) * (_owningAvatar->getHandPosition() - _translation);
|
||||||
restoreLeftHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY);
|
applyHandPosition(geometry.rightHandJointIndex, handPosition);
|
||||||
|
}
|
||||||
} else if (leftPalmIndex == rightPalmIndex) {
|
|
||||||
// right hand only
|
|
||||||
applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[leftPalmIndex]);
|
|
||||||
restoreLeftHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (leftPalmIndex != -1) {
|
|
||||||
applyPalmData(geometry.leftHandJointIndex, hand->getPalms()[leftPalmIndex]);
|
|
||||||
} else {
|
|
||||||
restoreLeftHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY);
|
restoreLeftHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY);
|
||||||
}
|
|
||||||
if (rightPalmIndex != -1) {
|
} else if (leftPalmIndex == rightPalmIndex) {
|
||||||
applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]);
|
// right hand only
|
||||||
|
applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[leftPalmIndex]);
|
||||||
|
restoreLeftHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
restoreRightHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY);
|
if (leftPalmIndex != -1) {
|
||||||
|
applyPalmData(geometry.leftHandJointIndex, hand->getPalms()[leftPalmIndex]);
|
||||||
|
} else {
|
||||||
|
restoreLeftHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY);
|
||||||
|
}
|
||||||
|
if (rightPalmIndex != -1) {
|
||||||
|
applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]);
|
||||||
|
} else {
|
||||||
|
restoreRightHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,6 +173,7 @@ void AnimSkeleton::dump() const {
|
||||||
qCDebug(animation) << "[";
|
qCDebug(animation) << "[";
|
||||||
for (int i = 0; i < getNumJoints(); i++) {
|
for (int i = 0; i < getNumJoints(); i++) {
|
||||||
qCDebug(animation) << " {";
|
qCDebug(animation) << " {";
|
||||||
|
qCDebug(animation) << " index =" << i;
|
||||||
qCDebug(animation) << " name =" << getJointName(i);
|
qCDebug(animation) << " name =" << getJointName(i);
|
||||||
qCDebug(animation) << " absBindPose =" << getAbsoluteBindPose(i);
|
qCDebug(animation) << " absBindPose =" << getAbsoluteBindPose(i);
|
||||||
qCDebug(animation) << " relBindPose =" << getRelativeBindPose(i);
|
qCDebug(animation) << " relBindPose =" << getRelativeBindPose(i);
|
||||||
|
@ -188,6 +189,7 @@ void AnimSkeleton::dump(const AnimPoseVec& poses) const {
|
||||||
qCDebug(animation) << "[";
|
qCDebug(animation) << "[";
|
||||||
for (int i = 0; i < getNumJoints(); i++) {
|
for (int i = 0; i < getNumJoints(); i++) {
|
||||||
qCDebug(animation) << " {";
|
qCDebug(animation) << " {";
|
||||||
|
qCDebug(animation) << " index =" << i;
|
||||||
qCDebug(animation) << " name =" << getJointName(i);
|
qCDebug(animation) << " name =" << getJointName(i);
|
||||||
qCDebug(animation) << " absBindPose =" << getAbsoluteBindPose(i);
|
qCDebug(animation) << " absBindPose =" << getAbsoluteBindPose(i);
|
||||||
qCDebug(animation) << " relBindPose =" << getRelativeBindPose(i);
|
qCDebug(animation) << " relBindPose =" << getRelativeBindPose(i);
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <glm/gtx/quaternion.hpp>
|
#include <glm/gtx/quaternion.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include "AnimationLogging.h"
|
||||||
|
|
||||||
class AnimVariant {
|
class AnimVariant {
|
||||||
public:
|
public:
|
||||||
|
@ -46,6 +47,7 @@ public:
|
||||||
bool isQuat() const { return _type == Type::Quat; }
|
bool isQuat() const { return _type == Type::Quat; }
|
||||||
bool isMat4() const { return _type == Type::Mat4; }
|
bool isMat4() const { return _type == Type::Mat4; }
|
||||||
bool isString() const { return _type == Type::String; }
|
bool isString() const { return _type == Type::String; }
|
||||||
|
Type getType() const { return _type; }
|
||||||
|
|
||||||
void setBool(bool value) { assert(_type == Type::Bool); _val.boolVal = value; }
|
void setBool(bool value) { assert(_type == Type::Bool); _val.boolVal = value; }
|
||||||
void setInt(int value) { assert(_type == Type::Int); _val.intVal = value; }
|
void setInt(int value) { assert(_type == Type::Int); _val.intVal = value; }
|
||||||
|
@ -156,6 +158,37 @@ public:
|
||||||
|
|
||||||
bool hasKey(const QString& key) const { return _map.find(key) != _map.end(); }
|
bool hasKey(const QString& key) const { return _map.find(key) != _map.end(); }
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
void dump() const {
|
||||||
|
qCDebug(animation) << "AnimVariantMap =";
|
||||||
|
for (auto& pair : _map) {
|
||||||
|
switch (pair.second.getType()) {
|
||||||
|
case AnimVariant::Type::Bool:
|
||||||
|
qCDebug(animation) << " " << pair.first << "=" << pair.second.getBool();
|
||||||
|
break;
|
||||||
|
case AnimVariant::Type::Int:
|
||||||
|
qCDebug(animation) << " " << pair.first << "=" << pair.second.getInt();
|
||||||
|
break;
|
||||||
|
case AnimVariant::Type::Float:
|
||||||
|
qCDebug(animation) << " " << pair.first << "=" << pair.second.getFloat();
|
||||||
|
break;
|
||||||
|
case AnimVariant::Type::Vec3:
|
||||||
|
qCDebug(animation) << " " << pair.first << "=" << pair.second.getVec3();
|
||||||
|
break;
|
||||||
|
case AnimVariant::Type::Quat:
|
||||||
|
qCDebug(animation) << " " << pair.first << "=" << pair.second.getQuat();
|
||||||
|
break;
|
||||||
|
case AnimVariant::Type::Mat4:
|
||||||
|
qCDebug(animation) << " " << pair.first << "=" << pair.second.getMat4();
|
||||||
|
break;
|
||||||
|
case AnimVariant::Type::String:
|
||||||
|
qCDebug(animation) << " " << pair.first << "=" << pair.second.getString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::map<QString, AnimVariant> _map;
|
std::map<QString, AnimVariant> _map;
|
||||||
std::set<QString> _triggers;
|
std::set<QString> _triggers;
|
||||||
|
|
|
@ -145,16 +145,20 @@ AnimationHandlePointer Rig::addAnimationByRole(const QString& role, const QStrin
|
||||||
}
|
}
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float FADE_FRAMES = 30.0f;
|
||||||
|
const float FRAMES_PER_SECOND = 30.0f;
|
||||||
|
|
||||||
void Rig::startAnimationByRole(const QString& role, const QString& url, float fps, float priority,
|
void Rig::startAnimationByRole(const QString& role, const QString& url, float fps, float priority,
|
||||||
bool loop, bool hold, float firstFrame, float lastFrame, const QStringList& maskedJoints) {
|
bool loop, bool hold, float firstFrame, float lastFrame, const QStringList& maskedJoints) {
|
||||||
AnimationHandlePointer handle = addAnimationByRole(role, url, fps, priority, loop, hold, firstFrame, lastFrame, maskedJoints, true);
|
AnimationHandlePointer handle = addAnimationByRole(role, url, fps, priority, loop, hold, firstFrame, lastFrame, maskedJoints, true);
|
||||||
handle->setFadePerSecond(1.0f); // For now. Could be individualized later.
|
handle->setFadePerSecond(FRAMES_PER_SECOND / FADE_FRAMES); // For now. Could be individualized later.
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rig::stopAnimationByRole(const QString& role) {
|
void Rig::stopAnimationByRole(const QString& role) {
|
||||||
foreach (const AnimationHandlePointer& handle, getRunningAnimations()) {
|
foreach (const AnimationHandlePointer& handle, getRunningAnimations()) {
|
||||||
if (handle->getRole() == role) {
|
if (handle->getRole() == role) {
|
||||||
handle->setFadePerSecond(-1.0f); // For now. Could be individualized later.
|
handle->setFadePerSecond(-(FRAMES_PER_SECOND / FADE_FRAMES)); // For now. Could be individualized later.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +167,7 @@ void Rig::stopAnimation(const QString& url) {
|
||||||
foreach (const AnimationHandlePointer& handle, getRunningAnimations()) {
|
foreach (const AnimationHandlePointer& handle, getRunningAnimations()) {
|
||||||
if (handle->getURL() == url) {
|
if (handle->getURL() == url) {
|
||||||
handle->setFade(0.0f); // right away. Will be remove during updateAnimations, without locking
|
handle->setFade(0.0f); // right away. Will be remove during updateAnimations, without locking
|
||||||
handle->setFadePerSecond(-1.0f); // so that the updateAnimation code notices
|
handle->setFadePerSecond(-(FRAMES_PER_SECOND / FADE_FRAMES)); // so that the updateAnimation code notices
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -587,10 +591,12 @@ void Rig::updateAnimations(float deltaTime, glm::mat4 rootTransform) {
|
||||||
_animVars.setTrigger(trigger);
|
_animVars.setTrigger(trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearJointStatePriorities();
|
||||||
|
|
||||||
// copy poses into jointStates
|
// copy poses into jointStates
|
||||||
const float PRIORITY = 1.0f;
|
const float PRIORITY = 1.0f;
|
||||||
for (size_t i = 0; i < poses.size(); i++) {
|
for (size_t i = 0; i < poses.size(); i++) {
|
||||||
setJointRotationInConstrainedFrame((int)i, glm::inverse(_animSkeleton->getRelativeBindPose(i).rot) * poses[i].rot, PRIORITY, false);
|
setJointRotationInConstrainedFrame((int)i, glm::inverse(_animSkeleton->getRelativeBindPose(i).rot) * poses[i].rot, PRIORITY, false, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -926,6 +932,12 @@ void Rig::updateVisibleJointStates() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Rig::clearJointStatePriorities() {
|
||||||
|
for (int i = 0; i < _jointStates.size(); i++) {
|
||||||
|
_jointStates[i].setAnimationPriority(0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Rig::setJointVisibleTransform(int jointIndex, glm::mat4 newTransform) {
|
void Rig::setJointVisibleTransform(int jointIndex, glm::mat4 newTransform) {
|
||||||
if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
|
if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
|
||||||
return;
|
return;
|
||||||
|
@ -950,6 +962,8 @@ glm::quat Rig::getJointDefaultRotationInParentFrame(int jointIndex) {
|
||||||
void Rig::updateFromHeadParameters(const HeadParameters& params, float dt) {
|
void Rig::updateFromHeadParameters(const HeadParameters& params, float dt) {
|
||||||
if (params.enableLean) {
|
if (params.enableLean) {
|
||||||
updateLeanJoint(params.leanJointIndex, params.leanSideways, params.leanForward, params.torsoTwist);
|
updateLeanJoint(params.leanJointIndex, params.leanSideways, params.leanForward, params.torsoTwist);
|
||||||
|
} else {
|
||||||
|
_animVars.unset("lean");
|
||||||
}
|
}
|
||||||
updateNeckJoint(params.neckJointIndex, params);
|
updateNeckJoint(params.neckJointIndex, params);
|
||||||
updateEyeJoints(params.leftEyeJointIndex, params.rightEyeJointIndex, params.modelTranslation, params.modelRotation,
|
updateEyeJoints(params.leftEyeJointIndex, params.rightEyeJointIndex, params.modelTranslation, params.modelRotation,
|
||||||
|
|
|
@ -172,6 +172,7 @@ public:
|
||||||
bool getJointRotationInConstrainedFrame(int jointIndex, glm::quat& rotOut) const;
|
bool getJointRotationInConstrainedFrame(int jointIndex, glm::quat& rotOut) const;
|
||||||
glm::quat getJointDefaultRotationInParentFrame(int jointIndex);
|
glm::quat getJointDefaultRotationInParentFrame(int jointIndex);
|
||||||
void updateVisibleJointStates();
|
void updateVisibleJointStates();
|
||||||
|
void clearJointStatePriorities();
|
||||||
|
|
||||||
virtual void updateJointState(int index, glm::mat4 rootTransform) = 0;
|
virtual void updateJointState(int index, glm::mat4 rootTransform) = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue