问题
I want to add castShadow
and receiveShadow
on a object. But what do I wrong with the following code?...
var mtlLoader = new THREE.MTLLoader();
mtlLoader.setPath("objects/Tree/");
mtlLoader.load("tree.mtl", function(materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath("objects/Tree/");
objLoader.load("tree.obj", function(gate) {
var positionX = 0;
var positionY = 4;
var positionZ = 0;
gate.position.x = positionX;
gate.position.y = positionY;
gate.position.z = positionZ;
gate.scale.x = 2
gate.scale.y = 2;
gate.scale.z = 2;
scene.add(gate);
gate.castShadow = true;
gate.receiveShadow = true;
});
});
回答1:
I think you need to traverse through the child and then set castShadow as given below.
gate.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.castShadow = true;
}
});
Here is the working sample http://jsfiddle.net/4Txgp/703/
I think really it should be helpful
来源:https://stackoverflow.com/questions/42399613/three-js-shadow-to-object