make sure render with zones works on models on restart/reload

This commit is contained in:
HifiExperiments 2020-07-21 12:06:38 -07:00
parent 84bee76968
commit aa6eedf0fe
3 changed files with 17 additions and 13 deletions

View file

@ -1337,7 +1337,7 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
_model->setCullWithParent(_cullWithParent); _model->setCullWithParent(_cullWithParent);
_model->setRenderWithZones(_renderWithZones); _model->setRenderWithZones(_renderWithZones);
emit requestRenderUpdate(); emit requestRenderUpdate();
if(didVisualGeometryRequestSucceed) { if (didVisualGeometryRequestSucceed) {
emit DependencyManager::get<scriptable::ModelProviderFactory>()-> emit DependencyManager::get<scriptable::ModelProviderFactory>()->
modelAddedToScene(entity->getEntityItemID(), NestableType::Entity, _model); modelAddedToScene(entity->getEntityItemID(), NestableType::Entity, _model);
} }

View file

@ -226,6 +226,7 @@ void Model::updateRenderItems() {
modelTransform.setScale(glm::vec3(1.0f)); modelTransform.setScale(glm::vec3(1.0f));
PrimitiveMode primitiveMode = self->getPrimitiveMode(); PrimitiveMode primitiveMode = self->getPrimitiveMode();
auto renderWithZones = self->getRenderWithZones();
auto renderItemKeyGlobalFlags = self->getRenderItemKeyGlobalFlags(); auto renderItemKeyGlobalFlags = self->getRenderItemKeyGlobalFlags();
bool cauterized = self->isCauterized(); bool cauterized = self->isCauterized();
@ -241,7 +242,8 @@ void Model::updateRenderItems() {
bool useDualQuaternionSkinning = self->getUseDualQuaternionSkinning(); bool useDualQuaternionSkinning = self->getUseDualQuaternionSkinning();
transaction.updateItem<ModelMeshPartPayload>(itemID, [modelTransform, meshState, useDualQuaternionSkinning, transaction.updateItem<ModelMeshPartPayload>(itemID, [modelTransform, meshState, useDualQuaternionSkinning,
invalidatePayloadShapeKey, primitiveMode, renderItemKeyGlobalFlags, cauterized](ModelMeshPartPayload& data) { invalidatePayloadShapeKey, primitiveMode, renderItemKeyGlobalFlags,
cauterized, renderWithZones](ModelMeshPartPayload& data) {
if (useDualQuaternionSkinning) { if (useDualQuaternionSkinning) {
data.updateClusterBuffer(meshState.clusterDualQuaternions); data.updateClusterBuffer(meshState.clusterDualQuaternions);
data.computeAdjustedLocalBound(meshState.clusterDualQuaternions); data.computeAdjustedLocalBound(meshState.clusterDualQuaternions);
@ -268,6 +270,7 @@ void Model::updateRenderItems() {
data.updateTransformForSkinnedMesh(renderTransform, modelTransform); data.updateTransformForSkinnedMesh(renderTransform, modelTransform);
data.setCauterized(cauterized); data.setCauterized(cauterized);
data.setRenderWithZones(renderWithZones);
data.updateKey(renderItemKeyGlobalFlags); data.updateKey(renderItemKeyGlobalFlags);
data.setShapeKey(invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning); data.setShapeKey(invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning);
}); });
@ -282,11 +285,6 @@ void Model::setRenderItemsNeedUpdate() {
emit requestRenderUpdate(); emit requestRenderUpdate();
} }
void Model::setPrimitiveMode(PrimitiveMode primitiveMode) {
_primitiveMode = primitiveMode;
setRenderItemsNeedUpdate();
}
void Model::reset() { void Model::reset() {
if (isLoaded()) { if (isLoaded()) {
const HFMModel& hfmModel = getHFMModel(); const HFMModel& hfmModel = getHFMModel();
@ -960,6 +958,13 @@ void Model::setCauterized(bool cauterized, const render::ScenePointer& scene) {
} }
} }
void Model::setPrimitiveMode(PrimitiveMode primitiveMode) {
if (_primitiveMode != primitiveMode) {
_primitiveMode = primitiveMode;
setRenderItemsNeedUpdate();
}
}
void Model::setCullWithParent(bool cullWithParent) { void Model::setCullWithParent(bool cullWithParent) {
if (_cullWithParent != cullWithParent) { if (_cullWithParent != cullWithParent) {
_cullWithParent = cullWithParent; _cullWithParent = cullWithParent;
@ -977,13 +982,10 @@ void Model::setCullWithParent(bool cullWithParent) {
} }
void Model::setRenderWithZones(const QVector<QUuid>& renderWithZones) { void Model::setRenderWithZones(const QVector<QUuid>& renderWithZones) {
render::Transaction transaction; if (_renderWithZones != renderWithZones) {
for (auto item : _modelMeshRenderItemIDs) { _renderWithZones = renderWithZones;
transaction.updateItem<ModelMeshPartPayload>(item, [renderWithZones](ModelMeshPartPayload& data) { setRenderItemsNeedUpdate();
data.setRenderWithZones(renderWithZones);
});
} }
AbstractViewStateInterface::instance()->getMain3DScene()->enqueueTransaction(transaction);
} }
const render::ItemKey Model::getRenderItemKeyGlobalFlags() const { const render::ItemKey Model::getRenderItemKeyGlobalFlags() const {

View file

@ -121,6 +121,7 @@ public:
void setCullWithParent(bool value); void setCullWithParent(bool value);
void setRenderWithZones(const QVector<QUuid>& renderWithZones); void setRenderWithZones(const QVector<QUuid>& renderWithZones);
const QVector<QUuid>& getRenderWithZones() const { return _renderWithZones; }
// Access the current RenderItemKey Global Flags used by the model and applied to the render items representing the parts of the model. // Access the current RenderItemKey Global Flags used by the model and applied to the render items representing the parts of the model.
const render::ItemKey getRenderItemKeyGlobalFlags() const; const render::ItemKey getRenderItemKeyGlobalFlags() const;
@ -499,6 +500,7 @@ protected:
render::ItemKey _renderItemKeyGlobalFlags; render::ItemKey _renderItemKeyGlobalFlags;
bool _cauterized { false }; bool _cauterized { false };
bool _cullWithParent { false }; bool _cullWithParent { false };
QVector<QUuid> _renderWithZones;
bool shouldInvalidatePayloadShapeKey(int meshIndex); bool shouldInvalidatePayloadShapeKey(int meshIndex);