繁体   English   中英

在 Three.js 中将面数组添加到 BufferGeometry

[英]Add array of faces to BufferGeometry in three.js

给定一个BufferGeometry ,我可以从一个Float32Array类型的数组中设置它的顶点, 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, 3),
  new THREE.Face3(1, 5, 7),
  ...
);

是的,您正在寻找的是BufferGeometry.setIndex() ,它允许在多个三角形中重复使用顶点,如文档中所述 是官方的工作演示

您基本上可以创建一个数组,然后推送一组 3 个顶点索引(基于其他属性的顺序):

var indices = [];

indices.push( 0, 3, 2); // face one
indices.push( 0, 1, 3 ); // face two

geometry.setIndex( indices );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM