Hi! I have an issue. When I create/remove objects sometimes my pooled(visually hidden) objects appear on the screen. And it only disappeared if I manually call scene.unfreezeActiveMeshes();
.
There are bushes around the yellow arrow:
After scene.unfreezeActiveMeshes();
bushes disappeared:
But it appears again after some time…
My frozen Scene constructor:
this.performancePriority = BABYLON.ScenePerformancePriority.Aggressive;
this.skipFrustumClipping = true;
this.autoClearDepthAndStencil = false;
When I change object’s transform or create a new instance, I call this method:
forceModelToUpdate(model: BABYLON.AbstractMesh): void {
scene.renderingManager.maintainStateBetweenFrames = false;
model._unFreeze();
if (model.isAnInstance) {
(model as BABYLON.InstancedMesh).sourceMesh._unFreeze();
}
}
This is how I put the object in my pool (to make it “visually” hidden):
pool.push(model);
model.unfreezeWorldMatrix();
model.position.y = 10000; // <--- this way
model.scaling.setAll(1);
model.freezeWorldMatrix();
scene.forceModelToUpdate(model);
This is how I create new instance:
modelInstance = (model as BABYLON.Mesh).createInstance(id);
modelInstance.setParent(model.parent);
scene.unfreezeActiveMeshes();
scene.forceModelToUpdate(modelInstance);
scene.render(false, true);
scene.freezeActiveMeshes(true);
scene.forceModelToUpdate(modelInstance);
I think I just doing something wrong with mesh’s freeze
/ unfree
or I forgot about some buffers clearing… IDK.
I have questions:
- Do I use freeze/unFreeze right?
- How to properly add a new instance when I apply freezing to scene with aggressive mode?
- How to visually hide objects? Right now I use
model.position.y = 10000;
but maybe there is more suitable way.
Please, help me to investigate and fix the issue.