2012-09-18 41 views
7

Có cách nào để thay đổi materialIndex trên khuôn mặt của một Lưới hiện có không? Điều này không được thảo luận trong tài liệu How to Update Things, vì vậy tôi không chắc chắn nếu nó có thể. Tôi đang sử dụng ngữ cảnh WebGLRenderer cho việc này.three.js cập nhật khuôn mặt hình học materialindex

này về cơ bản là những gì tôi đang cố gắng để làm:

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

Trả lời

13

Hành vi này đã thay đổi.

Nếu bạn đang sử dụng THREE.Geometry, bạn có thể sử dụng mô hình sau để thay đổi một số nguyên liệu mặt:

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

Nếu hình học đã được trước đó trả lại, bạn cũng phải thiết lập

mesh.geometry.groupsNeedUpdate = true; 

ba.js r.88

+0

Ah, điều đó có ý nghĩa. Cảm ơn bạn đã giải thích lý do đằng sau hành vi. – JDS

Các vấn đề liên quan