mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 22:51:20 +02:00
minor optimizations in updateModelBounds()
This commit is contained in:
parent
e109101acc
commit
23bb8608b1
4 changed files with 60 additions and 26 deletions
|
@ -124,10 +124,11 @@ void RenderableModelEntityItem::doInitialModelSimulation() {
|
||||||
model->setSnapModelToRegistrationPoint(true, getRegistrationPoint());
|
model->setSnapModelToRegistrationPoint(true, getRegistrationPoint());
|
||||||
model->setRotation(getRotation());
|
model->setRotation(getRotation());
|
||||||
model->setTranslation(getPosition());
|
model->setTranslation(getPosition());
|
||||||
{
|
|
||||||
|
if (_needsInitialSimulation) {
|
||||||
model->simulate(0.0f);
|
model->simulate(0.0f);
|
||||||
|
_needsInitialSimulation = false;
|
||||||
}
|
}
|
||||||
_needsInitialSimulation = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableModelEntityItem::autoResizeJointArrays() {
|
void RenderableModelEntityItem::autoResizeJointArrays() {
|
||||||
|
@ -179,13 +180,59 @@ bool RenderableModelEntityItem::needsUpdateModelBounds() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return model->needsReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableModelEntityItem::updateModelBounds() {
|
void RenderableModelEntityItem::updateModelBounds() {
|
||||||
PROFILE_RANGE(simulation_physics, "updateModelBounds");
|
PROFILE_RANGE(simulation_physics, "updateModelBounds");
|
||||||
if (needsUpdateModelBounds()) {
|
|
||||||
doInitialModelSimulation();
|
if (!_dimensionsInitialized || !hasModel()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelPointer model = getModel();
|
||||||
|
if (!model || !model->isLoaded()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* adebug TODO: figure out if we need to DO anything when isAnimatingSomething()
|
||||||
|
if (isAnimatingSomething()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (model->needsReload()) {
|
||||||
|
model->updateGeometry();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model->getScaleToFitDimensions() != getDimensions() ||
|
||||||
|
model->getRegistrationPoint() != getRegistrationPoint()) {
|
||||||
|
// The machinery for updateModelBounds will give existing models the opportunity to fix their
|
||||||
|
// translation/rotation/scale/registration. The first two are straightforward, but the latter two
|
||||||
|
// have guards to make sure they don't happen after they've already been set. Here we reset those guards.
|
||||||
|
// This doesn't cause the entity values to change -- it just allows the model to match once it comes in.
|
||||||
|
model->setScaleToFit(false, getDimensions());
|
||||||
|
model->setSnapModelToRegistrationPoint(false, getRegistrationPoint());
|
||||||
|
|
||||||
|
// now recalculate the bounds and registration
|
||||||
|
model->setScaleToFit(true, getDimensions());
|
||||||
|
model->setSnapModelToRegistrationPoint(true, getRegistrationPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success;
|
||||||
|
auto transform = getTransform(success);
|
||||||
|
if (success) {
|
||||||
|
if (model->getTranslation() != transform.getTranslation()) {
|
||||||
|
model->setTranslation(transform.getTranslation());
|
||||||
|
}
|
||||||
|
if (model->getRotation() != transform.getRotation()) {
|
||||||
|
model->setRotation(transform.getRotation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_needsInitialSimulation || _needsJointSimulation) {
|
||||||
|
model->simulate(0.0f);
|
||||||
|
_needsInitialSimulation = false;
|
||||||
_needsJointSimulation = false;
|
_needsJointSimulation = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -899,10 +946,6 @@ void RenderableModelEntityItem::copyAnimationJointDataToModel() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderableModelEntityItem::isAnimatingSomething() const {
|
|
||||||
return !getAnimationURL().isEmpty() && getAnimationIsPlaying() && getAnimationFPS() != 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace render;
|
using namespace render;
|
||||||
using namespace render::entities;
|
using namespace render::entities;
|
||||||
|
|
||||||
|
@ -1205,9 +1248,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity->needsUpdateModelBounds()) {
|
entity->updateModelBounds();
|
||||||
entity->updateModelBounds();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (model->isVisible() != _visible) {
|
if (model->isVisible() != _visible) {
|
||||||
// FIXME: this seems like it could be optimized if we tracked our last known visible state in
|
// FIXME: this seems like it could be optimized if we tracked our last known visible state in
|
||||||
|
@ -1215,6 +1256,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
|
||||||
// so most of the time we don't do anything in this function.
|
// so most of the time we don't do anything in this function.
|
||||||
model->setVisibleInScene(_visible, scene);
|
model->setVisibleInScene(_visible, scene);
|
||||||
}
|
}
|
||||||
|
// TODO? early exit here when not visible?
|
||||||
|
|
||||||
{
|
{
|
||||||
PROFILE_RANGE(simulation_physics, "Fixup");
|
PROFILE_RANGE(simulation_physics, "Fixup");
|
||||||
|
|
|
@ -108,7 +108,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool needsUpdateModelBounds() const;
|
bool needsUpdateModelBounds() const;
|
||||||
bool isAnimatingSomething() const;
|
|
||||||
void autoResizeJointArrays();
|
void autoResizeJointArrays();
|
||||||
void copyAnimationJointDataToModel();
|
void copyAnimationJointDataToModel();
|
||||||
|
|
||||||
|
|
|
@ -557,12 +557,6 @@ void ModelEntityItem::setAnimationLoop(bool loop) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelEntityItem::getAnimationLoop() const {
|
|
||||||
return resultWithReadLock<bool>([&] {
|
|
||||||
return _animationProperties.getLoop();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelEntityItem::setAnimationHold(bool hold) {
|
void ModelEntityItem::setAnimationHold(bool hold) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
_animationProperties.setHold(hold);
|
_animationProperties.setHold(hold);
|
||||||
|
@ -610,8 +604,10 @@ float ModelEntityItem::getAnimationCurrentFrame() const {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
float ModelEntityItem::getAnimationFPS() const {
|
bool ModelEntityItem::isAnimatingSomething() const {
|
||||||
return resultWithReadLock<float>([&] {
|
return resultWithReadLock<float>([&] {
|
||||||
return _animationProperties.getFPS();
|
return !_animationProperties.getURL().isEmpty() &&
|
||||||
});
|
_animationProperties.getRunning() &&
|
||||||
|
(_animationProperties.getFPS() != 0.0f);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,6 @@ public:
|
||||||
bool getAnimationAllowTranslation() const { return _animationProperties.getAllowTranslation(); };
|
bool getAnimationAllowTranslation() const { return _animationProperties.getAllowTranslation(); };
|
||||||
|
|
||||||
void setAnimationLoop(bool loop);
|
void setAnimationLoop(bool loop);
|
||||||
bool getAnimationLoop() const;
|
|
||||||
|
|
||||||
void setAnimationHold(bool hold);
|
void setAnimationHold(bool hold);
|
||||||
bool getAnimationHold() const;
|
bool getAnimationHold() const;
|
||||||
|
@ -101,10 +100,9 @@ public:
|
||||||
void setAnimationLastFrame(float lastFrame);
|
void setAnimationLastFrame(float lastFrame);
|
||||||
float getAnimationLastFrame() const;
|
float getAnimationLastFrame() const;
|
||||||
|
|
||||||
|
|
||||||
bool getAnimationIsPlaying() const;
|
bool getAnimationIsPlaying() const;
|
||||||
float getAnimationCurrentFrame() const;
|
float getAnimationCurrentFrame() const;
|
||||||
float getAnimationFPS() const;
|
bool isAnimatingSomething() const;
|
||||||
|
|
||||||
static const QString DEFAULT_TEXTURES;
|
static const QString DEFAULT_TEXTURES;
|
||||||
const QString getTextures() const;
|
const QString getTextures() const;
|
||||||
|
@ -123,7 +121,6 @@ public:
|
||||||
QVector<bool> getJointRotationsSet() const;
|
QVector<bool> getJointRotationsSet() const;
|
||||||
QVector<glm::vec3> getJointTranslations() const;
|
QVector<glm::vec3> getJointTranslations() const;
|
||||||
QVector<bool> getJointTranslationsSet() const;
|
QVector<bool> getJointTranslationsSet() const;
|
||||||
bool isAnimatingSomething() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setAnimationSettings(const QString& value); // only called for old bitstream format
|
void setAnimationSettings(const QString& value); // only called for old bitstream format
|
||||||
|
|
Loading…
Reference in a new issue