With complex models, Sharing EdgesRenderer on Instances fails (also at random progress)

For simple Models this works, but for more complex models, I get an error while rendering, when I enable “shareEdgesWithInstances” on the original meshes, shown in this very short Demo:

https://playground.babylonjs.com/#303G1F#2
Then I get “Uncaught TypeError: Cannot set property ‘0’ of undefined” while rendering.

I have also included a simpler model - commented out - consisting of just a few boxes. that one works fine every time. So it has to be something with the complexity that triggers this error.

When I looked at this in the npm project (currently not availably) it was something about copying a 16-values Array somewhere in “instancesData” but this array was undefined (hence the error). So some incances - or base meshes - don’t carry the infomation needed for instance edges rendering like it seems.

Currently I circumvent this problem by calculating the edges even for the instances which almost doubles the time for preparation.

Welcome aboard!

This PR will fix the problem:

Hi Evgeni,

thank you very much for looking into the issue!

I copied the parts of your pull request into the source in my NPM (which is JS, but I found all the right places).
The crash now doesn’t happen anymore. BUT a lot of the instanced meshes just don’t have the EdgesRenderer applied as they should have. So maybe there is another problem in the GLTF-Loader that doesn’t give the instances all the data they need to be recognized as such by the EdgesRenderer?

I can see the same rendering when node.edgesShareWithInstances = false and when node.edgesShareWithInstances = true with the fix.

Do you mean you don’t see all the edges you would like even when node.edgesShareWithInstances = false? If that is so, you can try to change the epsilon value of the enableEdgesRendering call to make more edges visible.

It’s not the epsilon, it’s instances of the same mesh not having edges at all while the original has all the edges.

image

The crazy thing is that this seems to work on the smaller model I used in the sandbox. The bigger, more complex model I sadly can’t disclose openly yet (which a small part can bee seen in the screenshot), but it has this phenomenon, that only the original has edges and the instances don’t (even they both go through the same routine of using “edgesShareWithInstances”).

To make things even more complex, the smaller model - in my environment - sometimes fails with
effect.ts:412 Uncaught TypeError: Cannot read property '0' of undefined at Effect2.getAttributeLocation (effect.ts:412) at Engine2.ThinEngine2._bindVertexBuffersAttributes (thinEngine.ts:1834) at Engine2.ThinEngine2.bindBuffers (thinEngine.ts:1979) at EdgesRenderer2.render (edgesRenderer.ts:936)
But when not failing like this, it renders acutally as expected. This works almost every time I have loaded the bigger model before and fails almost every time I didn’t.

Just to give you an idea what I’m working on:
https://showroom.proxes.com - the model I used in the sandbox is in the “UMX5 box”.
…and now there’s a second big box waiting that I can’t reveal yet openly in a forum :wink:

I think the fix I did will also fix the error you showed above: does it still happen after you applied the fix locally?

Also, does the edge renderer work when edgesShareWithInstances = false for your bigger object? I would like to know if the problem comes from sharing the renderer or not.

Yes, with “edgesShareWithInstances=false”, it works like expected. I then just enable the renderer on each instance seperately (which means the edges for every instance have to be calculated anew), and then it works:
image

I also do the loading “on the fly” while the renderer is already running.

I think we will need a repro in the Playground as I don’t see what could lead to this problem…

Another thing you can test: use thin instances instead of regular instances. In a gltf file, thin instances are supported through the extension EXT_mesh_gpu_instancing. I think Blender is supporting it, though I don’t know how (meaning, what you must do for an object in blender to be tagged with the EXT_mesh_gpu_instancing extension at export time).

Thanks for the suggestion! I looked into the blender exporter, there is no option for instances (yet?). I use Blender 2.91.2 because the .step and also the gltf exporter don’t work in the newer 2.92.0 version and spit out all kinds of python errors.

I also looked at “gltfpack”, that seems to have an option for using instances, maybe that will help.

You’re right, it seems Blender does not support the extension out of the box. People are directing to gltfpack when discussing the topic.