2012-09-18 11 views
7

Czy istnieje sposób na zmianę indeksu materiału na powierzchni istniejącej siatki? Nie jest to omówione w dokumentacji How to Update Things, więc nie jestem pewien, czy jest to możliwe. Używam do tego kontekstu WebGLRenderer.three.js aktualizowanie materiału geometrii faceindex

To jest w zasadzie to, co usiłuję zrobić:

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

Odpowiedz

13

Takie zachowanie nie zmieniło.

Jeśli używasz THREE.Geometry, można użyć następującego wzoru zmienić indeks materiał wierzchni:

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

Jeżeli geometria została wcześniej wydanego, należy również ustawić

mesh.geometry.groupsNeedUpdate = true; 

three.js r.88

+0

Ach, to ma sens. Dziękuję za wyjaśnienie przyczyny tego zachowania. – JDS

Powiązane problemy