THREE.BufferGeometry - access to face indices and face normal

In BufferGeometry, is there a way to access face indices and normals without converting to Geometry?

Geometry at hand is SphereBufferGeometry created by the threejs editor.

I only need to read the indices and normals of the face, and not change them.

+1
source share
1 answer

BufferGeometryeither "indexed" or "not indexed." SphereBufferGeometryhas an index type.

You can access the face normals in the geometry data structure as follows:

var normal = new THREE.Vector3(); // create once and reuse

...

// specify the desired face index
var faceIndex = 15; // [ 0 ... num_faces-1 ]

// specify which face vertex you want
var vertexNumber = 2; // [ 0, 1, or 2 ]

// compute the index where the data is stored
var index = geometry.index.array[ 3 * faceIndex + vertexNumber ];

// get the vertex normal from the attribute data
normal.fromBufferAttribute( geometry.attributes.normal, index );
console.log( normal );

three.js r.83

+3
source

Source: https://habr.com/ru/post/1669287/


All Articles