I am trying to export the models information to another application, the issue is I cannot recreate the mesh unless I know how the faces are positioned. The geometry has the following but nothing about the face values, thank you for your time.
When using BufferGeometry
, there is no separate faces data structure. Considering a mesh geometry, faces are defined by the order of vertices in the position buffer attribute. If the geometry has an index, three consecutive indices define a face. I suggest you read some resources about BufferGeometry
like the following to get a better understanding of the class as well as indexed and non-indexed geometries.
Thank you I marked this post the solution but I wouldnt have been able to figure it out without your help .
(“Spoon Fed”)
Basically if you want faces you have to follow this formula
var totalVertices = geometry.attributes.positions / 3;
var triangles = [];
for (i = 0; i < totalVertices; i++)
{
triangles.push(i);
}
now you should have your faces I did this to export a model out to Unity3D an it worked like a charm.
Your code only works for a non-indexed geometry however. For indexed geometries, you have to iterate over BufferGeometry.index.
Besides, there is a mistake in your code. You can’t divide through geometry.attributes.positions
since it is an object. It should be:
var positionAttribute = geometry.getAttribute( 'position' );
var vertex1 = new THREE.Vector3();
var vertex2 = new THREE.Vector3();
var vertex3 = new THREE.Vector3();
for ( var i = 0; i < positionAttribute.count; i += 3) {
vertex1.fromBufferAttribute( positionAttribute, i + 0 );
vertex2.fromBufferAttribute( positionAttribute, i + 1 );
vertex3.fromBufferAttribute( positionAttribute, i + 2 );
//vertex1/2/3 represent a single face now
}