mirror of
https://github.com/overte-org/overte.git
synced 2025-07-16 23:56:48 +02:00
Add the joint mapping necessary for playing animations in the rig.
This commit is contained in:
parent
f9f8b0ffc1
commit
4e298d815d
4 changed files with 33 additions and 4 deletions
|
@ -103,6 +103,15 @@ void AnimationHandle::setJointMappings(QVector<int> jointMappings) {
|
||||||
_jointMappings = jointMappings;
|
_jointMappings = jointMappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<int> AnimationHandle::getJointMappings() {
|
||||||
|
if (_jointMappings.isEmpty()) {
|
||||||
|
QVector<FBXJoint> animationJoints = _animation->getGeometry().joints;
|
||||||
|
for (int i = 0; i < animationJoints.count(); i++) {
|
||||||
|
_jointMappings.append(_rig->indexOfJoint(animationJoints.at(i).name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _jointMappings;
|
||||||
|
}
|
||||||
|
|
||||||
void AnimationHandle::simulate(float deltaTime) {
|
void AnimationHandle::simulate(float deltaTime) {
|
||||||
if (!_animation || !_animation->isLoaded()) {
|
if (!_animation || !_animation->isLoaded()) {
|
||||||
|
@ -111,7 +120,7 @@ void AnimationHandle::simulate(float deltaTime) {
|
||||||
|
|
||||||
_animationLoop.simulate(deltaTime);
|
_animationLoop.simulate(deltaTime);
|
||||||
|
|
||||||
if (_jointMappings.isEmpty()) {
|
if (getJointMappings().isEmpty()) {
|
||||||
qDebug() << "AnimationHandle::simulate -- _jointMappings.isEmpty()";
|
qDebug() << "AnimationHandle::simulate -- _jointMappings.isEmpty()";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ inline uint qHash(const std::weak_ptr<AnimationHandle>& a, uint seed) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Represents a handle to a model animation.
|
/// Represents a handle to a model animation. I.e., an Animation in use by a given Rig.
|
||||||
class AnimationHandle : public QObject, public std::enable_shared_from_this<AnimationHandle> {
|
class AnimationHandle : public QObject, public std::enable_shared_from_this<AnimationHandle> {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ public:
|
||||||
void setAnimationDetails(const AnimationDetails& details);
|
void setAnimationDetails(const AnimationDetails& details);
|
||||||
|
|
||||||
void setJointMappings(QVector<int> jointMappings);
|
void setJointMappings(QVector<int> jointMappings);
|
||||||
|
QVector<int> getJointMappings(); // computing if necessary
|
||||||
void simulate(float deltaTime);
|
void simulate(float deltaTime);
|
||||||
void applyFrame(float frameIndex);
|
void applyFrame(float frameIndex);
|
||||||
void replaceMatchingPriorities(float newPriority);
|
void replaceMatchingPriorities(float newPriority);
|
||||||
|
@ -125,7 +126,6 @@ private:
|
||||||
AnimationLoop _animationLoop;
|
AnimationLoop _animationLoop;
|
||||||
|
|
||||||
static QHash<QWeakPointer<Animation>, QVector<int>> _jointMappingsCache;
|
static QHash<QWeakPointer<Animation>, QVector<int>> _jointMappingsCache;
|
||||||
static QVector<int> getJointMappings(const AnimationPointer& animation);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,17 @@ float Rig::initJointStates(QVector<JointState> states, glm::mat4 parentTransform
|
||||||
return radius;
|
return radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We could build and cache a dictionary, too....
|
||||||
|
// Should we be using .fst mapping instead/also?
|
||||||
|
int Rig::indexOfJoint(const QString& jointName) {
|
||||||
|
for (int i = 0; i < _jointStates.count(); i++) {
|
||||||
|
if (_jointStates[i].getFBXJoint().name == jointName) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Rig::initJointTransforms(glm::mat4 parentTransform) {
|
void Rig::initJointTransforms(glm::mat4 parentTransform) {
|
||||||
// compute model transforms
|
// compute model transforms
|
||||||
|
|
|
@ -10,7 +10,15 @@
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
/* TBD:
|
/*
|
||||||
|
Things we want to be able to do, that I think we cannot do now:
|
||||||
|
* Stop an animation at a given time so that it can be examined visually or in a test harness. (I think we can already stop animation and set frame to a computed float? But does that move the bones?)
|
||||||
|
* Play two animations, blending between them. (Current structure just has one, under script control.)
|
||||||
|
* Fade in an animation over another.
|
||||||
|
* Apply IK, lean, head pointing or other overrides relative to previous position.
|
||||||
|
All of this depends on coordinated state.
|
||||||
|
|
||||||
|
TBD:
|
||||||
- What are responsibilities of Animation/AnimationPointer/AnimationCache/AnimationDetails/AnimationObject/AnimationLoop?
|
- What are responsibilities of Animation/AnimationPointer/AnimationCache/AnimationDetails/AnimationObject/AnimationLoop?
|
||||||
Is there common/copied code (e.g., ScriptableAvatar::update)?
|
Is there common/copied code (e.g., ScriptableAvatar::update)?
|
||||||
- How do attachments interact with the physics of the attached entity? E.g., do hand joints need to reflect held object
|
- How do attachments interact with the physics of the attached entity? E.g., do hand joints need to reflect held object
|
||||||
|
@ -58,6 +66,7 @@ public:
|
||||||
float initJointStates(QVector<JointState> states, glm::mat4 parentTransform, int neckJointIndex);
|
float initJointStates(QVector<JointState> states, glm::mat4 parentTransform, int neckJointIndex);
|
||||||
bool jointStatesEmpty() { return _jointStates.isEmpty(); };
|
bool jointStatesEmpty() { return _jointStates.isEmpty(); };
|
||||||
int getJointStateCount() const { return _jointStates.size(); }
|
int getJointStateCount() const { return _jointStates.size(); }
|
||||||
|
int indexOfJoint(const QString& jointName) ;
|
||||||
|
|
||||||
void initJointTransforms(glm::mat4 parentTransform);
|
void initJointTransforms(glm::mat4 parentTransform);
|
||||||
void clearJointTransformTranslation(int jointIndex);
|
void clearJointTransformTranslation(int jointIndex);
|
||||||
|
|
Loading…
Reference in a new issue