通过顶点和顶点索引创建集合体
- 效果图
- 1、创建顶点数据
- 2、创建顶点属性
- 3、创建材质
- 4、创建网格
- 5、改变网格的位置并添加到场景中
- 6、通过顶点索引创建几何图形
效果图
1、创建顶点数据
const vertices = new Float32Array([
-1.0, -1.0, 0.0, 1.0, -1.0, 0.0, 1.0, 1.0, 0.0,
1.0, 1.0, 0.0, -1.0, 1.0, 0.0, -1.0, -1.0, 0.0
])
2、创建顶点属性
geomentryBuff.setAttribute('position', new THREE.BufferAttribute(vertices, 3))
3、创建材质
const material01 = new THREE.MeshBasicMaterial({color: 0x00ff00,side: THREE.DoubleSide,wireframe:true
})
4、创建网格
const plane = new THREE.Mesh(geomentryBuff, material01)
5、改变网格的位置并添加到场景中
plane.position.set(3, 0, 0)
scene.add(plane)
6、通过顶点索引创建几何图形
const vertices = new Float32Array([-1.0, -1.0, 0.0, 1.0, -1.0, 0.0, 1.0, 1.0, 0.0, -1.0, 1.0, 0.0
])
geomentryBuff.setAttribute('position', new THREE.BufferAttribute(vertices, 3))
const indices = new Uint16Array([0, 1, 2, 2, 3, 0])
geomentryBuff.setIndex(new THREE.BufferAttribute(indices, 1))
const material01 = new THREE.MeshBasicMaterial({color: 0x00ff00,side: THREE.DoubleSide,wireframe:true
})
const plane = new THREE.Mesh(geomentryBuff, material01)
plane.position.set(3, 0, 0)
scene.add(plane)