update RenderableModelEntityItem::_model during simulate rather than during render

This commit is contained in:
Seth Alves 2015-11-23 15:51:43 -08:00
parent eecb5b91b2
commit 7b70562a1b
3 changed files with 49 additions and 45 deletions

View file

@ -210,6 +210,53 @@ void RenderableModelEntityItem::removeFromScene(EntityItemPointer self, std::sha
}
}
void RenderableModelEntityItem::simulate(const quint64& now) {
EntityItem::simulate(now);
if (_model) {
// handle animations..
if (hasAnimation()) {
if (!jointsMapped()) {
QStringList modelJointNames = _model->getJointNames();
mapJoints(modelJointNames);
}
if (jointsMapped()) {
bool newFrame;
QVector<glm::quat> frameDataRotations;
QVector<glm::vec3> frameDataTranslations;
getAnimationFrame(newFrame, frameDataRotations, frameDataTranslations);
assert(frameDataRotations.size() == frameDataTranslations.size());
if (newFrame) {
for (int i = 0; i < frameDataRotations.size(); i++) {
_model->setJointState(i, true, frameDataRotations[i], frameDataTranslations[i], 1.0f);
}
}
}
}
bool movingOrAnimating = isMoving() || isAnimatingSomething();
if ((movingOrAnimating ||
_needsInitialSimulation ||
_model->getTranslation() != getPosition() ||
_model->getRotation() != getRotation() ||
_model->getRegistrationPoint() != getRegistrationPoint())
&& _model->isActive() && _dimensionsInitialized) {
_model->setScaleToFit(true, getDimensions());
_model->setSnapModelToRegistrationPoint(true, getRegistrationPoint());
_model->setRotation(getRotation());
_model->setTranslation(getPosition());
// make sure to simulate so everything gets set up correctly for rendering
{
PerformanceTimer perfTimer("_model->simulate");
_model->simulate(0.0f);
}
_needsInitialSimulation = false;
}
}
}
// NOTE: this only renders the "meta" portion of the Model, namely it renders debugging items, and it handles
// the per frame simulation/update that might be required if the models properties changed.
@ -259,50 +306,6 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
EntityTreeRenderer* renderer = static_cast<EntityTreeRenderer*>(args->_renderer);
getModel(renderer);
}
if (_model) {
// handle animations..
if (hasAnimation()) {
if (!jointsMapped()) {
QStringList modelJointNames = _model->getJointNames();
mapJoints(modelJointNames);
}
if (jointsMapped()) {
bool newFrame;
QVector<glm::quat> frameDataRotations;
QVector<glm::vec3> frameDataTranslations;
getAnimationFrame(newFrame, frameDataRotations, frameDataTranslations);
assert(frameDataRotations.size() == frameDataTranslations.size());
if (newFrame) {
for (int i = 0; i < frameDataRotations.size(); i++) {
_model->setJointState(i, true, frameDataRotations[i], frameDataTranslations[i], 1.0f);
}
}
}
}
bool movingOrAnimating = isMoving() || isAnimatingSomething();
if ((movingOrAnimating ||
_needsInitialSimulation ||
_model->getTranslation() != getPosition() ||
_model->getRotation() != getRotation() ||
_model->getRegistrationPoint() != getRegistrationPoint())
&& _model->isActive() && _dimensionsInitialized) {
_model->setScaleToFit(true, getDimensions());
_model->setSnapModelToRegistrationPoint(true, getRegistrationPoint());
_model->setRotation(getRotation());
_model->setTranslation(getPosition());
// make sure to simulate so everything gets set up correctly for rendering
{
PerformanceTimer perfTimer("_model->simulate");
_model->simulate(0.0f);
}
_needsInitialSimulation = false;
}
}
}
} else {
static glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f);

View file

@ -47,6 +47,7 @@ public:
virtual bool addToScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges);
virtual void removeFromScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges);
virtual void simulate(const quint64& now);
virtual void render(RenderArgs* args);
virtual bool supportsDetailedRayIntersection() const { return true; }

View file

@ -183,7 +183,7 @@ public:
quint64 getLastUpdated() const { return _lastUpdated; }
// perform linear extrapolation for SimpleEntitySimulation
void simulate(const quint64& now);
virtual void simulate(const quint64& now);
void simulateKinematicMotion(float timeElapsed, bool setFlags=true);
virtual bool needsToCallUpdate() const { return false; }