我想使用react-three-fiber制作自定义几何体。 我刚接触three.js,最初完成了这个很棒的教程:https://threejsfundamentals.org/threejs/lessons/threejs-custom-buffergeometry.html 一切都进展顺利,但后来我决定使用react改善我的应用程序。 我无法找到如何声明式地创建自定义形状。 在官方API中,我找到了以下内容:
<bufferGeometry attach="geometry">
<bufferAttribute attachObject={['attributes', 'position']} count={v.length / 3} array={v} itemSize={3} />
我尝试使用这个基本示例:https://threejs.org/docs/#api/en/core/BufferGeometry
const vertices = new Float32Array( [
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
-1.0, -1.0, 1.0
] );
以上代码位于自定义函数组件内,该组件被放置在画布上。返回语句如下:
return (
<mesh>
<bufferGeometry>
<bufferAttribute
attachObject={["attributes", "position"]}
array={vertices}
itemSize={3}
/>
</bufferGeometry>
<meshNormalMaterial />
</mesh>
);
但是没有任何东西显示出来。 如何使用react-three-fiber从坐标和法线数组创建自定义几何体?
new BufferGeometry()
直接放入useState
或useMemo
中,也可以像之前那样声明式地创建它。不过我觉得缺少了count
属性。 - hpalucount
属性了。 还有一个错误是没有将我另一个测试位置数组转换为Float32Array
。 但我有另一个问题。 如果我提供自己的法向量集,一切都很好。 但在声明式工作时如何调用geometry.computeVertexNormals()
? - agt-ru