Why wireframe mode does not work when using setVerticesBuffer and setIndexBuffer? (webgpu)

See the example here: Mesh.setVerticesBuffer webGPU test6 | Babylon.js Playground (babylonjs.com)

If you set material.wireframe = true; everything disappears. No mesh is shown. Why? How to fix it?

Wireframe rendering relies on the fact that indices can be retrieved for the mesh (through a call to Mesh.getIndices(), because it needs to create the lines used by the wireframe rendering). In your case, this call will return an empty array, because you directly set an index buffer, so the system is unable to retrieve the index data.

You can get around this problem by overwriting the getIndices method:

2 Likes

Thanks @Evgeni_Popov, indeed it works.

However, I wonder how to handle the case where a compute shader updates the indices buffer.

I that case, would it be possible to read the indices buffer asynchrously? Are the lines computed by the CPU?

The index buffer used to draw lines is built by SubMesh._getLinesIndexBuffer:

You could try to override this function and create the index buffer yourself (as a storage buffer). Then, you could use a compute shader to fill this buffer, avoiding the read back to the CPU.

1 Like