1.在加载模型时修改颜色
loader.load(url, function(object){
let obj = object.children;
for(let i = 0; i <= obj.length; i++){
if(你的条件判断){
let clonedMaterial = obj[i].material.clone();
clonedMaterial.color.setHex(0x00ff00);
obj[i].material = clonedMaterial;
}
}
})
2.点击模型时修改颜色
function onCanvasClick(event) {
var mouse = new THREE.Vector2();
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
var raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObjects(scene.children, true);
if (intersects.length > 0) {
var Mesh= intersects[0].object;
Mesh.material.color.set(selectedColor);
}
}