问题描述
考虑到 BufferGeometry ,我可以像这样设置Float32Array
类型数组的顶点:
geometry.setAttribute( 'position',new THREE.BufferAttribute( vertices,3 ) );
是否有一种使用类型Int32Array
的数组以类似方式设置BufferGeometry的面的方法?我想避免这种情况:
geometry.faces.push(
new THREE.Face3(0,3,2),new THREE.Face3(0,1,3),new THREE.Face3(1,7,5,7),...
);
解决方法
是的,您要寻找的是BufferGeometry.setIndex()
,它可以将顶点重新用于多个三角形,例如outlined in the docs。这是the official working demo。
您基本上可以创建一个数组,然后推入3个顶点索引的集合(基于其他属性的顺序):
var indices = [];
indices.push( 0,3,2); // face one
indices.push( 0,1,3 ); // face two
geometry.setIndex( indices );