我有很多相同的网格。它们具有相同的材料,但颜色不同。有没有办法可以在一个bufferGeometry中合并它们的几何,并为它设置一种材料?
是的,我可以将所有材质添加到材质数组,将几何图形合并到bufferGeometry,添加索引并创建一个网格物体。但是通过这种方式,我会有尽可能多的绘制调用作为材料,但我只需要一个。
答案 0 :(得分:0)
您可以为此
使用顶点颜色const myMeshes = [...]
//first go through all the meshes, and tell them that they have another attibute
//in addition to whatever they already have
myMeshes.forEach( mesh=>{
const thisMeshColor = new THREE.Color().copy(mesh.material.color) //the color you want to distribute
//expand the data to match the vertices
mesh.colors = mesh.vertices.map(vert=>thisMeshColor)
}
//merge here
//apply this to material and it should "work"
myMerges.material.vertexColors = THREE.VertexColors
有点伪代码,没有经过测试。三个R92