mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 17:56:43 +02:00
Merge pull request #7662 from zzmp/fix/model-anim-cache
Use AnimationCache for models
This commit is contained in:
commit
c9b0531f55
5 changed files with 13 additions and 39 deletions
|
@ -1238,8 +1238,6 @@ Application::~Application() {
|
||||||
|
|
||||||
_physicsEngine->setCharacterController(nullptr);
|
_physicsEngine->setCharacterController(nullptr);
|
||||||
|
|
||||||
ModelEntityItem::cleanupLoadedAnimations();
|
|
||||||
|
|
||||||
// remove avatars from physics engine
|
// remove avatars from physics engine
|
||||||
DependencyManager::get<AvatarManager>()->clearOtherAvatars();
|
DependencyManager::get<AvatarManager>()->clearOtherAvatars();
|
||||||
VectorOfMotionStates motionStates;
|
VectorOfMotionStates motionStates;
|
||||||
|
|
|
@ -274,11 +274,11 @@ bool RenderableModelEntityItem::getAnimationFrame() {
|
||||||
if (!hasRenderAnimation() || !_jointMappingCompleted) {
|
if (!hasRenderAnimation() || !_jointMappingCompleted) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
AnimationPointer myAnimation = getAnimation(getRenderAnimationURL()); // FIXME: this could be optimized
|
|
||||||
if (myAnimation && myAnimation->isLoaded()) {
|
|
||||||
|
|
||||||
const QVector<FBXAnimationFrame>& frames = myAnimation->getFramesReference(); // NOTE: getFrames() is too heavy
|
if (_animation && _animation->isLoaded()) {
|
||||||
auto& fbxJoints = myAnimation->getGeometry().joints;
|
|
||||||
|
const QVector<FBXAnimationFrame>& frames = _animation->getFramesReference(); // NOTE: getFrames() is too heavy
|
||||||
|
auto& fbxJoints = _animation->getGeometry().joints;
|
||||||
|
|
||||||
int frameCount = frames.size();
|
int frameCount = frames.size();
|
||||||
if (frameCount > 0) {
|
if (frameCount > 0) {
|
||||||
|
|
|
@ -82,7 +82,7 @@ public:
|
||||||
virtual int getJointIndex(const QString& name) const override;
|
virtual int getJointIndex(const QString& name) const override;
|
||||||
virtual QStringList getJointNames() const override;
|
virtual QStringList getJointNames() const override;
|
||||||
|
|
||||||
// These operate on a copy of the renderAnimationProperties, so they can be accessed
|
// These operate on a copy of the animationProperties, so they can be accessed
|
||||||
// without having the entityTree lock.
|
// without having the entityTree lock.
|
||||||
bool hasRenderAnimation() const { return !_renderAnimationProperties.getURL().isEmpty(); }
|
bool hasRenderAnimation() const { return !_renderAnimationProperties.getURL().isEmpty(); }
|
||||||
const QString& getRenderAnimationURL() const { return _renderAnimationProperties.getURL(); }
|
const QString& getRenderAnimationURL() const { return _renderAnimationProperties.getURL(); }
|
||||||
|
|
|
@ -205,37 +205,18 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QMap<QString, AnimationPointer> ModelEntityItem::_loadedAnimations; // TODO: improve cleanup by leveraging the AnimationPointer(s)
|
|
||||||
|
|
||||||
void ModelEntityItem::cleanupLoadedAnimations() {
|
|
||||||
foreach(AnimationPointer animation, _loadedAnimations) {
|
|
||||||
animation.clear();
|
|
||||||
}
|
|
||||||
_loadedAnimations.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
AnimationPointer ModelEntityItem::getAnimation(const QString& url) {
|
|
||||||
AnimationPointer animation;
|
|
||||||
|
|
||||||
// if we don't already have this model then create it and initialize it
|
|
||||||
if (_loadedAnimations.find(url) == _loadedAnimations.end()) {
|
|
||||||
animation = DependencyManager::get<AnimationCache>()->getAnimation(url);
|
|
||||||
_loadedAnimations[url] = animation;
|
|
||||||
} else {
|
|
||||||
animation = _loadedAnimations[url];
|
|
||||||
}
|
|
||||||
return animation;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelEntityItem::mapJoints(const QStringList& modelJointNames) {
|
void ModelEntityItem::mapJoints(const QStringList& modelJointNames) {
|
||||||
// if we don't have animation, or we're already joint mapped then bail early
|
// if we don't have animation, or we're already joint mapped then bail early
|
||||||
if (!hasAnimation() || jointsMapped()) {
|
if (!hasAnimation() || jointsMapped()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationPointer myAnimation = getAnimation(_animationProperties.getURL());
|
if (!_animation || _animation->getURL().toString() != getAnimationURL()) {
|
||||||
if (myAnimation && myAnimation->isLoaded()) {
|
_animation = DependencyManager::get<AnimationCache>()->getAnimation(getAnimationURL());
|
||||||
QStringList animationJointNames = myAnimation->getJointNames();
|
}
|
||||||
|
|
||||||
|
if (_animation && _animation->isLoaded()) {
|
||||||
|
QStringList animationJointNames = _animation->getJointNames();
|
||||||
|
|
||||||
if (modelJointNames.size() > 0 && animationJointNames.size() > 0) {
|
if (modelJointNames.size() > 0 && animationJointNames.size() > 0) {
|
||||||
_jointMapping.resize(modelJointNames.size());
|
_jointMapping.resize(modelJointNames.size());
|
||||||
|
|
|
@ -105,6 +105,7 @@ public:
|
||||||
void mapJoints(const QStringList& modelJointNames);
|
void mapJoints(const QStringList& modelJointNames);
|
||||||
bool jointsMapped() const { return _jointMappingURL == getAnimationURL() && _jointMappingCompleted; }
|
bool jointsMapped() const { return _jointMappingURL == getAnimationURL() && _jointMappingCompleted; }
|
||||||
|
|
||||||
|
AnimationPointer getAnimation() const { return _animation; }
|
||||||
bool getAnimationIsPlaying() const { return _animationLoop.getRunning(); }
|
bool getAnimationIsPlaying() const { return _animationLoop.getRunning(); }
|
||||||
float getAnimationCurrentFrame() const { return _animationLoop.getCurrentFrame(); }
|
float getAnimationCurrentFrame() const { return _animationLoop.getCurrentFrame(); }
|
||||||
float getAnimationFPS() const { return _animationLoop.getFPS(); }
|
float getAnimationFPS() const { return _animationLoop.getFPS(); }
|
||||||
|
@ -115,8 +116,6 @@ public:
|
||||||
|
|
||||||
virtual bool shouldBePhysical() const;
|
virtual bool shouldBePhysical() const;
|
||||||
|
|
||||||
static void cleanupLoadedAnimations();
|
|
||||||
|
|
||||||
virtual glm::vec3 getJointPosition(int jointIndex) const { return glm::vec3(); }
|
virtual glm::vec3 getJointPosition(int jointIndex) const { return glm::vec3(); }
|
||||||
virtual glm::quat getJointRotation(int jointIndex) const { return glm::quat(); }
|
virtual glm::quat getJointRotation(int jointIndex) const { return glm::quat(); }
|
||||||
|
|
||||||
|
@ -156,6 +155,7 @@ protected:
|
||||||
QUrl _parsedModelURL;
|
QUrl _parsedModelURL;
|
||||||
QString _compoundShapeURL;
|
QString _compoundShapeURL;
|
||||||
|
|
||||||
|
AnimationPointer _animation;
|
||||||
AnimationPropertyGroup _animationProperties;
|
AnimationPropertyGroup _animationProperties;
|
||||||
AnimationLoop _animationLoop;
|
AnimationLoop _animationLoop;
|
||||||
|
|
||||||
|
@ -168,11 +168,6 @@ protected:
|
||||||
bool _jointMappingCompleted;
|
bool _jointMappingCompleted;
|
||||||
QVector<int> _jointMapping; // domain is index into model-joints, range is index into animation-joints
|
QVector<int> _jointMapping; // domain is index into model-joints, range is index into animation-joints
|
||||||
QString _jointMappingURL;
|
QString _jointMappingURL;
|
||||||
|
|
||||||
static AnimationPointer getAnimation(const QString& url);
|
|
||||||
static QMap<QString, AnimationPointer> _loadedAnimations;
|
|
||||||
static AnimationCache _animationCache;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ModelEntityItem_h
|
#endif // hifi_ModelEntityItem_h
|
||||||
|
|
Loading…
Reference in a new issue