Possible reasons for mesh rendered but not drawn?

Looking at the great diagram (Whats the difference between onBeforeDrawObservable and onBeforeRenderObservable - #5 by carolhmj) by @carolhmj, what could be reasons for onBeforeRender triggered, but onBeforeBind and onBeforeDraw not triggered?

I am debugging a case where my mesh does not appear.

Hello and welcome!

The easiest way for people to help you is to provide a Playground example with your question.
Otherwise we can only guess what is wrong with you code :slight_smile:

1 Like

I cannot reproduce it on PG because it only appears with rendering on-demand, not a continuous render loop.

In this case you may provide the part of relevant code or even give the link to Github etc.
At least, it would be good to have as much information as possible about your use case, otherwise it is hard to pinpoint the problem.

1 Like

image

Sorry, I am asked to keep my code confidential, but I can show you the console logs where I named everything with BabylonJS APIs and provided some outputs, so you can understand the flow of my code.

Note that I have 35 meshes.

The only reason I can see onBeforeRenderObservable being triggered for your mesh and not material.onBindObservable is that there is a null material assigned to your mesh or that for some reason your material is never ready (material.isReadyForSubMesh always returns false).

2 Likes

Thanks! I have not checked for the material yet, but

mesh.isReady(/* completeCheck: */ true) returns false,

and apparantly has some side-effect, that causes my mesh and material to be ready and visible afterwards.

UPDATE:

mesh.material.isReady(mesh) returns false indeed, which always causes the mesh not to be drawn.

I solved my issue by checking if mesh and material are completely ready, and if not trigger another render on-demand, until actually ready.

Honestly I think the BabylonJS API could be improved here: For example SceneLoader.ImportMesh onSuccess callback should wait until materials are ready.

Here’s the updated diagram: