实际我在系统上工作,用鼠标点击来改变对象的纹理。
我的对象是用这个构建的:
var cubeGeometry = new THREE.CubeGeometry( 25, 200, 50 );
wall = new THREE.Mesh( cubeGeometry, holzMaterial );
wall.position.set(-150.5,0,0);
wall.castShadow = true;
wall.receiveShadow = true;
wall.name = "Mauer";
collidableMeshListwand.push(wall);
scene.add(wall);
纹理编码为:
var holzTexture = new THREE.ImageUtils.loadTexture( 'textures/holz.jpg' );
holzTexture.wrapS = holzTexture.wrapT = THREE.RepeatWrapping;
holzTexture.repeat.set( 1, 1 );
var holzMaterial = new THREE.MeshLambertMaterial( { map: holzTexture } );
var himmelTexture = new THREE.ImageUtils.loadTexture( 'textures/himmel.jpg' );
himmelTexture.wrapS = himmelTexture.wrapT = THREE.RepeatWrapping;
himmelTexture.repeat.set( 1, 1 );
var himmelMaterial = new THREE.MeshLambertMaterial( { map: himmelTexture } );
所以最后我写了一个函数,它在鼠标下识别元素并在点击时更改它。例如,更改阴影适用于:
if (intersects[ 0 ].object.castShadow == true) {
intersects[ 0 ].object.castShadow = false;
}
else {
intersects[ 0 ].object.castShadow = true;
}
现在我想改变纹理,同时使用:
intersects[ 0 ].object.mesh.material.uniforms.texture.value(himmelMaterial);
intersects[ 0 ].object.mesh.material.uniforms.texture.needsUpdate = true;
但这不起作用。
如果有人可以帮助我,那将是很棒的。 :)