I’ve been struggling with this for quite a while now.
I am building a project using some .obj files on a plane. I have a bit of ambient light and a directional light pointed on the building. I’ve set the castShadow and receiveShadow options to true on all objects. I’ve tried some different light settings etc. But I can’t get my dropshadows to work.
Edit:
Got a codepen to work https://codepen.io/vincentbosch7/pen/XWmNGyp
Your ground material is an instance of MeshBasicMaterial
which is unlit and can’t receive shadows. Use a lit material like MeshPhongMaterial
.
The shadow camera of your directional light is not configured properly. Try it with this code:
var light = new THREE.DirectionalLight(0xFFFFFF, 1.25);
light.position.set(320, 400, 425);
light.target.position.set(0, 10, 0);
light.shadow.camera.top = 2000;
light.shadow.camera.bottom = - 2000;
light.shadow.camera.left = - 2000;
light.shadow.camera.right = 2000;
light.shadow.camera.near = 1;
light.shadow.camera.far = 2000;
light.castShadow = true;
scene.add(light);
// scene.add( new THREE.CameraHelper( light.shadow.camera ) );
Always use CameraHelper
for debugging the light’s shadow camera.
Thank you! This fixed it for the plane, but the models don’t cast shadow at each other, only at the plane. Is it possible to make this work?
When traversing through your OBJ models, you also have to set receiveShadow
to true
, not just castShadow
.
I already had this turned on for all OBJ models, or did I do it wrong?
E.g. instead of:
A3.traverse(function(child) {
if (child instanceof THREE.Mesh) {
child.castShadow = true;
child.callback = objectClickA3;
}
});
do this:
A3.traverse(function(child) {
if (child instanceof THREE.Mesh) {
child.castShadow = true;
child.receiveShadow = true;
child.callback = objectClickA3;
}
});
Ah I forgot to apply it to the children, instead I applied it to the model. Thank You!
Now the shadow casts on the objects, but a weird type of other shadow occurred as well. Could this have a specific reason or could there be something wrong with the 3d model?
That’s perfect, thank you very much!