I\'ve been using the fromGeometry method to make BufferGeometry objects from regular Geometry objects, and I\'ve found that it seems the number of vertices increases during the
Lets take the simple case of a BoxGeometry(80,80,80,1,1,1)
, For the box BufferGeometry
we get 36 vertices and for the box Geometry
we get 8 vertices. How is this possible? Lets do the math:
To define a box we only need 8 vertices to define 12 triangles that make up that shape; but for each vertex of the box you have 6 triangles sharing it. Keep in mind that each face of the cube has 2 triangles.
If you unroll all the triangles of the box Geometry
into a box BufferGeometry
you have: 6 faces x 2 triangles per face x 3 vertices per triangle x 3 floats per vertex
= 108 floats
The best way to find out the answer to these questions is just to look at the three.js code. It is very accessible and generally easy to follow.
First we can look up the BufferGeometry.fromGeometry method:
fromGeometry: function ( geometry ) {
geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
return this.fromDirectGeometry( geometry.__directGeometry );
}
Which you can see is calling DirectGeometry.fromGeometry
fromGeometry: function ( geometry ) {
// ...
var vertices = geometry.vertices;
// ...
for ( var i = 0; i < faces.length; i ++ ) {
// ...
this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
// ...
}
// ...
}
And here you can clearly see that it is adding additional vertices that come from the geometry faces property. The answer by gaitat gives a great example as to why that is!