有没有办法通过更改object.material的atttribute .type而不是用新材料重新加载整个对象,将材质类型从Lambert更改为Phong(和反向)?
答案 0 :(得分:1)
你不必丢失属性。如果您正在使用THREE.BufferGeometry
,则可以改为使用群组。
<强>组强>
var boxGeo = new THREE.BoxBufferGeometry(10, 10, 10);
// set up your groups
boxGeo.clearGroups();
boxGeo.addGroup(0, boxGeo.index.count, 0);
<强>材料强>
在THREE.js r85之前
您将使用THREE.MultiMaterial
。
// add both of your materials to a multi-material
var mm = new THREE.MultiMaterial([
new THREE.MeshLambertMaterial({color: "red"}),
new THREE.MeshPhongMaterial({color: "red"}),
]);
var mesh = new THREE.Mesh(boxGeo, mm);
对于THREE.js r85及以上
您只需将一系列材料传递给THREE.Mesh
。
// add both of your materials to a multi-material
var mm = [
new THREE.MeshLambertMaterial({color: "red"}),
new THREE.MeshPhongMaterial({color: "red"}),
];
var mesh = new THREE.Mesh(boxGeo, mm);
交换材料
然后当你想要交换材料时:
if(mesh.geometry.groups[0].materialIndex === 0){
mesh.geometry.groups[0].materialIndex = 1;
}
else{
mesh.geometry.groups[0].materialIndex = 0
}