mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 14:47:51 +02:00
update RenderableModelEntityItem::_model during simulate rather than during render
This commit is contained in:
parent
eecb5b91b2
commit
7b70562a1b
3 changed files with 49 additions and 45 deletions
|
@ -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
|
// 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.
|
// 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);
|
EntityTreeRenderer* renderer = static_cast<EntityTreeRenderer*>(args->_renderer);
|
||||||
getModel(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 {
|
} else {
|
||||||
static glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f);
|
static glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f);
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
virtual bool addToScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges);
|
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 removeFromScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges);
|
||||||
|
|
||||||
|
virtual void simulate(const quint64& now);
|
||||||
|
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||||
|
|
|
@ -183,7 +183,7 @@ public:
|
||||||
quint64 getLastUpdated() const { return _lastUpdated; }
|
quint64 getLastUpdated() const { return _lastUpdated; }
|
||||||
|
|
||||||
// perform linear extrapolation for SimpleEntitySimulation
|
// perform linear extrapolation for SimpleEntitySimulation
|
||||||
void simulate(const quint64& now);
|
virtual void simulate(const quint64& now);
|
||||||
void simulateKinematicMotion(float timeElapsed, bool setFlags=true);
|
void simulateKinematicMotion(float timeElapsed, bool setFlags=true);
|
||||||
|
|
||||||
virtual bool needsToCallUpdate() const { return false; }
|
virtual bool needsToCallUpdate() const { return false; }
|
||||||
|
|
Loading…
Reference in a new issue