mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 15:49:51 +02:00
More work on animation configuration.
This commit is contained in:
parent
5da656e3f5
commit
62e7a31602
5 changed files with 71 additions and 3 deletions
|
@ -217,6 +217,7 @@ public:
|
|||
|
||||
QNetworkAccessManager* getNetworkAccessManager() { return _networkAccessManager; }
|
||||
GeometryCache* getGeometryCache() { return &_geometryCache; }
|
||||
AnimationCache* getAnimationCache() { return &_animationCache; }
|
||||
TextureCache* getTextureCache() { return &_textureCache; }
|
||||
GlowEffect* getGlowEffect() { return &_glowEffect; }
|
||||
ControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; }
|
||||
|
|
|
@ -599,7 +599,10 @@ AttachmentData MyAvatar::loadAttachmentData(const QUrl& modelURL, const QString&
|
|||
}
|
||||
|
||||
void MyAvatar::setAnimationData(const QVector<AnimationData>& animationData) {
|
||||
_animationData = animationData;
|
||||
// exit early if no change
|
||||
if (_animationData != animationData) {
|
||||
_animationData = animationData;
|
||||
}
|
||||
}
|
||||
|
||||
int MyAvatar::parseDataAtOffset(const QByteArray& packet, int offset) {
|
||||
|
@ -1570,3 +1573,7 @@ void MyAvatar::applyCollision(const glm::vec3& contactPoint, const glm::vec3& pe
|
|||
AnimationData::AnimationData() :
|
||||
fps(30.0f) {
|
||||
}
|
||||
|
||||
bool AnimationData::operator==(const AnimationData& other) const {
|
||||
return url == other.url && fps == other.fps;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include <QSettings>
|
||||
|
||||
#include <AnimationCache.h>
|
||||
|
||||
#include "Avatar.h"
|
||||
|
||||
class AnimationData;
|
||||
|
@ -158,6 +160,15 @@ private:
|
|||
|
||||
QVector<AnimationData> _animationData;
|
||||
|
||||
class AnimationState {
|
||||
public:
|
||||
AnimationPointer animation;
|
||||
QVector<int> jointMappings;
|
||||
float frameIndex;
|
||||
};
|
||||
|
||||
QVector<AnimationState> _animationStates;
|
||||
|
||||
// private methods
|
||||
void updateOrientation(float deltaTime);
|
||||
void updateMotorFromKeyboard(float deltaTime, bool walking);
|
||||
|
@ -181,6 +192,8 @@ public:
|
|||
float fps;
|
||||
|
||||
AnimationData();
|
||||
|
||||
bool operator==(const AnimationData& other) const;
|
||||
};
|
||||
|
||||
#endif // hifi_MyAvatar_h
|
||||
|
|
|
@ -594,6 +594,14 @@ QStringList Model::getJointNames() const {
|
|||
return isActive() ? _geometry->getFBXGeometry().getJointNames() : QStringList();
|
||||
}
|
||||
|
||||
void Model::startAnimation(const QUrl& url, float fps, bool loop, float offset) {
|
||||
AnimationState state = { Application::getInstance()->getAnimationCache()->getAnimation(url), fps, loop, offset };
|
||||
_animationStates.append(state);
|
||||
}
|
||||
|
||||
void Model::stopAnimation() {
|
||||
_animationStates.clear();
|
||||
}
|
||||
|
||||
void Model::clearShapes() {
|
||||
for (int i = 0; i < _jointShapes.size(); ++i) {
|
||||
|
@ -1006,6 +1014,22 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
|
|||
}
|
||||
|
||||
void Model::simulateInternal(float deltaTime) {
|
||||
// update animations
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
for (int i = 0; i < _animationStates.size(); i++) {
|
||||
AnimationState& state = _animationStates[i];
|
||||
if (!(state.animation && state.animation->isLoaded())) {
|
||||
continue;
|
||||
}
|
||||
const FBXGeometry& animationGeometry = state.animation->getGeometry();
|
||||
if (state.jointMappings.isEmpty()) {
|
||||
for (int j = 0; j < geometry.joints.size(); j++) {
|
||||
state.jointMappings.append(animationGeometry.jointIndices.value(geometry.joints.at(j).name) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// NOTE: this is a recursive call that walks all attachments, and their attachments
|
||||
// update the world space transforms for all joints
|
||||
for (int i = 0; i < _jointStates.size(); i++) {
|
||||
|
@ -1013,8 +1037,6 @@ void Model::simulateInternal(float deltaTime) {
|
|||
}
|
||||
_shapesAreDirty = true;
|
||||
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
|
||||
// update the attachment transforms and simulate them
|
||||
for (int i = 0; i < _attachments.size(); i++) {
|
||||
const FBXAttachment& attachment = geometry.attachments.at(i);
|
||||
|
@ -1426,6 +1448,10 @@ void Model::deleteGeometry() {
|
|||
_meshStates.clear();
|
||||
clearShapes();
|
||||
|
||||
for (int i = 0; i < _animationStates.size(); i++) {
|
||||
_animationStates[i].jointMappings.clear();
|
||||
}
|
||||
|
||||
if (_geometry) {
|
||||
_geometry->clearLoadPriority(this);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include <CapsuleShape.h>
|
||||
|
||||
#include <AnimationCache.h>
|
||||
|
||||
#include "GeometryCache.h"
|
||||
#include "InterfaceConfig.h"
|
||||
#include "ProgramObject.h"
|
||||
|
@ -185,6 +187,23 @@ public:
|
|||
|
||||
QStringList getJointNames() const;
|
||||
|
||||
class AnimationState {
|
||||
public:
|
||||
AnimationPointer animation;
|
||||
float fps;
|
||||
bool loop;
|
||||
float offset;
|
||||
QVector<int> jointMappings;
|
||||
};
|
||||
|
||||
const QVector<AnimationState>& getAnimationStates() const { return _animationStates; }
|
||||
|
||||
/// Starts playing the animation at the specified URL.
|
||||
void startAnimation(const QUrl& url, float fps = 30.0f, bool loop = true, float offset = 0.0f);
|
||||
|
||||
/// Stops playing all animations.
|
||||
void stopAnimation();
|
||||
|
||||
void clearShapes();
|
||||
void rebuildShapes();
|
||||
void resetShapePositions();
|
||||
|
@ -260,6 +279,8 @@ protected:
|
|||
|
||||
QVector<MeshState> _meshStates;
|
||||
|
||||
QVector<AnimationState> _animationStates;
|
||||
|
||||
// returns 'true' if needs fullUpdate after geometry change
|
||||
bool updateGeometry();
|
||||
|
||||
|
|
Loading…
Reference in a new issue