The first idea is to use
getVerticesData. However, it returns more vertices than is practically needed (24 instead of 8 for a cube), also it returns them in local coordinates.
I think I still can handle it with the following steps:
- Get the array returned by
getVerticesData and group entries by 3.
- After grouping remove duplicate groups.
- Get mesh absolute position and add to it vertex local position to find the absolute position of the vertex.
But this approach makes me feel like I am overcomplicating things and missing something that probably is already implemented somewhere in BabylonJS. Is there an easier way to find all vertices global coordinates?
let data = BABYLON.VertexData.ExtractFromMesh(mesh)
About removing duplicate vertices.
If you don’t mind affecting the source mesh, you can add it before.
If you don’t want to affect the source mesh, you can copy a new mesh, here is an example of copying a new mesh and doing it
Checking the console, you can see that the length of the array is 24
and the number of vertices is 24/3 = 8.
Regarding your second post,
I came up with my own “clean up” algorithm, so I don’t need to deal with meshes.
a) group the coordinates by 3.
b) sort by z, then by x, then by y in ascending order (required for solving my next problem).
c) remove duplicates.
I found out that approach
is very destructive.
Practically, if you had
box.checkCollisions = true, then collisons will stop working and you will be able to walk through walls.
Instead, it should be done like following: