mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
Merge branch 'update-model-during-simulate' of github.com:sethalves/hifi into no-physics-until-ready
This commit is contained in:
commit
47df744552
1 changed files with 79 additions and 55 deletions
|
@ -253,60 +253,6 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
||||||
|
|
||||||
|
|
||||||
remapTextures();
|
remapTextures();
|
||||||
{
|
|
||||||
// float alpha = getLocalRenderAlpha();
|
|
||||||
|
|
||||||
if (!_model || _needsModelReload) {
|
|
||||||
// TODO: this getModel() appears to be about 3% of model render time. We should optimize
|
|
||||||
PerformanceTimer perfTimer("getModel");
|
|
||||||
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 {
|
} 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);
|
||||||
gpu::Batch& batch = *args->_batch;
|
gpu::Batch& batch = *args->_batch;
|
||||||
|
@ -361,7 +307,35 @@ Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderableModelEntityItem::needsToCallUpdate() const {
|
bool RenderableModelEntityItem::needsToCallUpdate() const {
|
||||||
return !_dimensionsInitialized || _needsInitialSimulation || ModelEntityItem::needsToCallUpdate();
|
if (!_dimensionsInitialized || _needsInitialSimulation || ModelEntityItem::needsToCallUpdate()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_dimensionsInitialized && _model && _model->isActive()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_myRenderer && (!_model || _needsModelReload)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_model) {
|
||||||
|
if (hasAnimation() || jointsMapped()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool movingOrAnimating = isMoving() || isAnimatingSomething();
|
||||||
|
if ((movingOrAnimating ||
|
||||||
|
_needsInitialSimulation ||
|
||||||
|
_model->getTranslation() != getPosition() ||
|
||||||
|
_model->getRotation() != getRotation() ||
|
||||||
|
_model->getRegistrationPoint() != getRegistrationPoint())
|
||||||
|
&& _model->isActive() && _dimensionsInitialized) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderableModelEntityItem::update(const quint64& now) {
|
void RenderableModelEntityItem::update(const quint64& now) {
|
||||||
|
@ -377,6 +351,56 @@ void RenderableModelEntityItem::update(const quint64& now) {
|
||||||
Q_ARG(EntityItemProperties, properties));
|
Q_ARG(EntityItemProperties, properties));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_myRenderer && (!_model || _needsModelReload)) {
|
||||||
|
// TODO: this getModel() appears to be about 3% of model render time. We should optimize
|
||||||
|
PerformanceTimer perfTimer("getModel");
|
||||||
|
getModel(_myRenderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ModelEntityItem::update(now);
|
ModelEntityItem::update(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue