Babylon.js onBeforeRenderObservable works with scene, not with a mesh

115 Views Asked by At

I'm trying to cut off part of a sophisticated mesh. I've decided best way to do it is to use "onBeforeRenderObservable" on mesh and add clipPlane to the scene before rendering specific part of mesh. After the mesh is rendered the clipPlane is removed with onAfterRenderObservable. The observable seems not to trigger at all when added to mesh. When added to the scene itself it cuts the whole scene at desired position.

What I have: meshInfo.mesh.onBeforeRenderObservable.add((() => { this.scene.clipPlane = (new Plane(a, b, c, d)); console.log("before"); }).bind(this));

The "before" is never drawn to console.

What works but for the whole scene: this.scene.onBeforeRenderObservable.add((() => { this.scene.clipPlane = (new Plane(a, b, c, d)); console.log("before"); }).bind(this));

And the code used to remove clipPlane: meshInfo.mesh.onAfterRenderObservable.add(() => { this.scene.clipPlane = null; });

I have tried looking for a place in code later on that would somehow remove the onBeforeRenderObservable from mesh but I'm certain it's there when the scene is drawn.

Edit 06.11.2023: I've managed to solve my issue with applying the onBeforeRenderObservable and onAfterRenderObservable on each child mesh of my meshInfo.mesh. The parent object was only used as a container holding meshes that were drawn. It seems like the events above are per-mesh only and not for all of the children of the mesh.

0

There are 0 best solutions below