【问题标题】:Add array of faces to BufferGeometry in three.js在 three.js 中将面数组添加到 BufferGeometry
【发布时间】:2021-01-15 15:34:43
【问题描述】:

给定一个 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, 3),
  new THREE.Face3(1, 5, 7),
  ...
);

【问题讨论】:

标签: javascript three.js geometry vertices


【解决方案1】:

是的,您正在寻找的是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 );

【讨论】:

  • 就是这样!谢谢。
  • 这可以在数组之前不创建三个缓冲区属性的情况下工作吗?
猜你喜欢
  • 2016-07-26
  • 2021-05-22
  • 2016-01-22
  • 2015-04-01
  • 1970-01-01
  • 2020-12-05
  • 2020-07-11
  • 1970-01-01
  • 2019-08-23
相关资源
最近更新 更多