Shadow not working

I am trying to add shadows to gltf model, I’ve tried some solutions that I saw in the forum.

renderer.shadowMap = true
scene.traverse( function( child ) { 
    if ( child.isMesh ) {
        child.castShadow = true;
        child.receiveShadow = true;
    }
} );

But it doesn’t seem to work. Is there anything else that i should’ve done?

Thanks,
Binoy

what kind of lights do you have in your scene?
and what kind of materials is your model using?
you need to show more code.

I use THREE.DirectionalLights, materials are THREE.MeshStandardMaterial

here is a directional ligh shadow example that shows that directional light shadows do work.
Directional Light Shadow - Three.js Tutorials (sbcode.net)

2 Likes

What is this plane your shadows are appearing on ? I think mine doesn’t have anything like that

the code for the plane is in the source code of the example I linked earlier.
Press the <> in the working example to see the un obfuscated inline JavaScript.
or look at lines 40-45 in the TypeScript example.
Nothing is hidden from you.
And also, in the TypeScript version there actually isn’t any TypeScript in there, since all the types are auto inferred by the usage of each variable as they are declared or instantiated.

Also, check this example.
Raycaster Measurements - Three.js Tutorials (sbcode.net)
It loads a glTF into the scene with the plane already included in the model.
The model is traversed, and shadows are set to receive and cast appropriately

1 Like