playcanvas / engine

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
https://playcanvas.com
MIT License
9.59k stars 1.34k forks source link

GLB parser incorrect index buffer construction #5869

Open LeXXik opened 10 months ago

LeXXik commented 10 months ago

When GLB parser creates an index buffer, it passes a typed array to the constructor, instead of an array buffer. This results in view being a storage in the index buffer, instead of array buffer.

https://github.com/playcanvas/engine/blob/dc20e8e6c4555bd6a3418ee313a6fc57ca7c1d58/src/framework/parsers/glb-parser.js#L835

LeXXik commented 10 months ago

For background:

I am generating a mesh collider. To avoid copying the indices, I don't use Mesh API, but use the index buffer directly. In order to avoid copying the buffer when sending to web worker, I am sending the underlying Array Buffer. This bug makes it accessing the buffer differently, depending on if the mesh was generated by procedural.js or from GLB parser:

indexBuffer.storage
vs
indexBuffer.storage.buffer