使用 Float32Array 绘制顶点位置时,发现只有逆时针写的才会生效,顺时针写的不行。
Float32Array:类型数组,固定长度,用来存储浮点类型数据的数组
只能存储Number数字型数据,其他数据不允许会赋值为NaN
引用: (32条消息) Float32Array基础用法_杨大大28的博客-CSDN博客
// 添加物体---几何体--矩形
const geometry = new THREE.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
])
//设置属性。--顶点位置,已三个为一组作为坐标
geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
const Material = new THREE.MeshBasicMaterial({ color: 0xffff00 }); //设置几何体的材质,并设置其颜色
const mesh = new THREE.Mesh(geometry, Material);
scene.add(mesh)