有没有办法在现有Mesh的面上更改materialIndex? How to Update Things文档中未对此进行讨论,因此我不确定是否可行。我正在使用WebGLRenderer上下文。
这基本上就是我要做的事情:
// Make a mesh with two materials
var texture = THREE.ImageUtils.loadTexture(IMAGE_URL);
var geometry = new THREE.Geometry();
geometry.materials.push(new THREE.MeshBasicMaterial({ wireframe: true, vertexColors: THREE.FaceColors}));
geometry.materials.push(new THREE.MeshBasicMaterial({ map: texture, overdraw: true}));
whatever.forEach(function(w, i) {
geometry.vertices.push(makeVerts(w));
var materialIndex = 0;
var color = new THREE.Color(i);
geometry.faces.push(new THREE.Face4(i*4+0, i*4+1, i*4+2, i*4+3,
null, color, materialIndex));
});
var mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial());
scene.add(mesh)
// Later on, change some faces to a different material
geometry.faces.filter(someFilter).forEach(function(face) {
face.color = someOtherColor;
face.materialIndex = 1;
}
geometry.colorsNeedUpdate = true; // This is how to update the color, and it works.
//geometry.materialsNeedUpdate = true; // This isn't a thing, is it?
答案 0 :(得分:13)
此行为已更改。
如果您使用的是THREE.Geometry
,则可以使用以下模式更改面料索引:
mesh.geometry.faces[ 0 ].materialIndex = 1;
如果先前已渲染几何体,则还必须设置
mesh.geometry.groupsNeedUpdate = true;
three.js r.88