Geometry of a Box

If I create a very simple box like this :

        let box = BABYLON.MeshBuilder.CreateBox("box", { height: 1, width: 1, depth: 1 }, this.scene);
        box.position = new BABYLON.Vector3(0, 0, 0);

When I get the geometry I get a strange ‘Indices’ array. The array is 36 long. I was expecting 24 since I’m getting 72 positions/normals. ( 24 Vectors )
The Indices array is not ordered and I don’t understand why. At the end is a very basic box.
How can I order the Positions/Normals and create a 36 index ? I need ordered because I’m creating a UV mapping and with the index messed up it is tricky. I tried to insert a 24 array, but the view goes in crash with the error : glDrawElements: attempt to access out of range vertices in attribute 0

Another thing that I don’t understand is that if I get the facet positions the coordinates are different from the positions array. Why ?


a cube is made of 6 facets. Each facets is made of 2 faces. Each faces is made of 3 vertices.
so 6 * 2 * 3 = 6 * 6 = 36 :slight_smile:

Each face has independent vertices so you can control UV or normal per face

Perhaps something that can also help you: Apply Material to Individual Faces - Babylon.js Documentation


Remember that we are always rendering triangles… not quads.


This may also help Vertex Normals - Babylon.js Documentation

Thank you guys, I’m starting to understand and I was able to map the UV vertices.

1 Like

That’s why we are here!