THREE.BufferGeometry - accessing face indices and face normals

牧云@^-^@ 提交于 2020-01-05 08:05:29

问题


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

The geometry at hand is a SphereBufferGeometry created by the threejs editor.

I only need to read face indices and normals, not modify them.


回答1:


BufferGeometry is either "indexed" or "non-indexed". SphereBufferGeometry is of the indexed type.

You can access the face normals in the geometry data structure like so:

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



来源:https://stackoverflow.com/questions/41540313/three-buffergeometry-accessing-face-indices-and-face-normals

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!