The problem is that the hex tiles are loaded from a .glb file, meaning the geometry is in a right-handed system: the indices have to be inverted to convert to a left handed system.
I have updated the addMesh
method to pass a flag that indicates a mesh has its geometry in a right handed system:
https://playground.babylonjs.com/#STN960#14
Note that meshes without thin instances are also supported in ComposeMesh
, so you don’t need to do:
hexTilePrefab.thinInstanceEnablePicking = true;
hexTilePrefab.thinInstanceAddSelf();
I think the code is quite straightforward once you know the layout of the arrays used to build a mesh from scratch. This doc should help you:
The code is simply creating the arrays that hold the data (positions, normals, uvs) of all the meshes/thin instances you pass in:
-
rebuildGeometry
computes the size of the arrays and create them (empty) -
update
set the data into the array by basically copying the data from the original mesh arrays. The positions/normals are transformed according to the mesh world matrix, and if the mesh has also thin instances we must factor in the thin instance matrix (meaning, we simply multiply the mesh world matrix with the thin instance matrix)