mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 16:43:33 +02:00
optimize ModelEntityItem::getAnimationFrame()
This commit is contained in:
parent
f4c3c30f6a
commit
cec0f8ed1d
5 changed files with 30 additions and 14 deletions
|
@ -91,6 +91,10 @@ QVector<FBXAnimationFrame> Animation::getFrames() const {
|
|||
return _geometry.animationFrames;
|
||||
}
|
||||
|
||||
const QVector<FBXAnimationFrame>& Animation::getFramesReference() const {
|
||||
return _geometry.animationFrames;
|
||||
}
|
||||
|
||||
void Animation::setGeometry(const FBXGeometry& geometry) {
|
||||
_geometry = geometry;
|
||||
finishedLoading(true);
|
||||
|
|
|
@ -57,6 +57,8 @@ public:
|
|||
Q_INVOKABLE QStringList getJointNames() const;
|
||||
|
||||
Q_INVOKABLE QVector<FBXAnimationFrame> getFrames() const;
|
||||
|
||||
const QVector<FBXAnimationFrame>& getFramesReference() const;
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
|||
}
|
||||
|
||||
if (jointsMapped()) {
|
||||
QVector<glm::quat> frameData = getAnimationFrame();
|
||||
auto frameData = getAnimationFrame();
|
||||
for (int i = 0; i < frameData.size(); i++) {
|
||||
_model->setJointState(i, true, frameData[i]);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityI
|
|||
setProperties(properties);
|
||||
_lastAnimated = usecTimestampNow();
|
||||
_jointMappingCompleted = false;
|
||||
_lastKnownFrameIndex = -1;
|
||||
_color[0] = _color[1] = _color[2] = 0;
|
||||
}
|
||||
|
||||
|
@ -217,15 +218,17 @@ void ModelEntityItem::mapJoints(const QStringList& modelJointNames) {
|
|||
}
|
||||
}
|
||||
|
||||
QVector<glm::quat> ModelEntityItem::getAnimationFrame() {
|
||||
QVector<glm::quat> frameData;
|
||||
const QVector<glm::quat>& ModelEntityItem::getAnimationFrame() {
|
||||
|
||||
if (!hasAnimation() || !_jointMappingCompleted) {
|
||||
return frameData;
|
||||
return _lastKnownFrameData;
|
||||
}
|
||||
|
||||
AnimationPointer myAnimation = getAnimation(_animationURL);
|
||||
AnimationPointer myAnimation = getAnimation(_animationURL); // FIXME: this could be optimized
|
||||
if (myAnimation && myAnimation->isLoaded()) {
|
||||
QVector<FBXAnimationFrame> frames = myAnimation->getFrames();
|
||||
|
||||
const QVector<FBXAnimationFrame>& frames = myAnimation->getFramesReference(); // NOTE: getFrames() is too heavy
|
||||
|
||||
int frameCount = frames.size();
|
||||
if (frameCount > 0) {
|
||||
int animationFrameIndex = (int)(glm::floor(getAnimationFrameIndex())) % frameCount;
|
||||
|
@ -233,18 +236,22 @@ QVector<glm::quat> ModelEntityItem::getAnimationFrame() {
|
|||
animationFrameIndex = 0;
|
||||
}
|
||||
|
||||
QVector<glm::quat> rotations = frames[animationFrameIndex].rotations;
|
||||
if (animationFrameIndex != _lastKnownFrameIndex) {
|
||||
_lastKnownFrameIndex = animationFrameIndex;
|
||||
|
||||
const QVector<glm::quat>& rotations = frames[animationFrameIndex].rotations;
|
||||
|
||||
frameData.resize(_jointMapping.size());
|
||||
for (int j = 0; j < _jointMapping.size(); j++) {
|
||||
int rotationIndex = _jointMapping[j];
|
||||
if (rotationIndex != -1 && rotationIndex < rotations.size()) {
|
||||
frameData[j] = rotations[rotationIndex];
|
||||
_lastKnownFrameData.resize(_jointMapping.size());
|
||||
for (int j = 0; j < _jointMapping.size(); j++) {
|
||||
int rotationIndex = _jointMapping[j];
|
||||
if (rotationIndex != -1 && rotationIndex < rotations.size()) {
|
||||
_lastKnownFrameData[j] = rotations[rotationIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return frameData;
|
||||
return _lastKnownFrameData;
|
||||
}
|
||||
|
||||
bool ModelEntityItem::isAnimatingSomething() const {
|
||||
|
|
|
@ -106,7 +106,7 @@ public:
|
|||
float getAnimationLastFrame() const { return _animationLoop.getLastFrame(); }
|
||||
|
||||
void mapJoints(const QStringList& modelJointNames);
|
||||
QVector<glm::quat> getAnimationFrame();
|
||||
const QVector<glm::quat>& getAnimationFrame();
|
||||
bool jointsMapped() const { return _jointMappingCompleted; }
|
||||
|
||||
bool getAnimationIsPlaying() const { return _animationLoop.isRunning(); }
|
||||
|
@ -123,6 +123,9 @@ public:
|
|||
static void cleanupLoadedAnimations();
|
||||
|
||||
protected:
|
||||
QVector<glm::quat> _lastKnownFrameData;
|
||||
int _lastKnownFrameIndex;
|
||||
|
||||
|
||||
bool isAnimatingSomething() const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue