2012-09-18 13 views
7

¿Hay alguna manera de cambiar el materialIndex en una cara de una malla existente? Esto no se trata en la documentación de How to Update Things, por lo que no estoy seguro de si es posible. Estoy usando un contexto WebGLRenderer para esto.three.js actualización geometría face materialindex

Esto es básicamente lo que estoy tratando de hacer:

// 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? 

Respuesta

13

Este comportamiento ha cambiado.

Si está utilizando THREE.Geometry, puede utilizar el siguiente patrón para cambiar un índice de material de la cara:

mesh.geometry.faces[ 0 ].materialIndex = 1; 

Si la geometría se ha prestado previamente, también debe establecer

mesh.geometry.groupsNeedUpdate = true; 

three.js r.88

+0

Ah, eso tiene sentido. Gracias por explicar la razón detrás del comportamiento. – JDS