Creating Custom Mesh - Unexpected Behaviour

I’m creating a custom mesh of a pole (somewhat rectangular in shape). The points are generated by another program and I am translating them into a babylon friendly format.

When I clean the array of indices (remove -1s, convert to triangles and remove unnecessary values etc), the shape rendered is not what it should be.

However, when I convert the indices from references to values instead of points (i.e.
//from indiceArr[i] => (x,y,z) //to indiceArr[i] => x indiceArr[i+1] => y indiceArr[i+2] => z) the shape renders perfectly (minus some texture issues).

How is this so? By expanding the indices am I not creating 3 triangles for every 1 in the position array? Shouldn’t this expansion result in out of bounds reads within babylon?

Here is a playground demonstrating the issue:

The indices are expanded as follows:
var newIndices = []
for(var i in indices){

Building a mesh from indices / positions can be tricky when we can’t see what happens.
I suggest you to use a material in wireframe mode so you could better see where things are missing

And unless special need, you could also consider using a Ribbon from a geometry (paths) so the mesh would be built directly for you (positions/indices + uvs computation)


I’m new to babylon so haven’t seen Ribbons before. They look like just what I need! I’ll play around with them and get back to you.