# CastShadow and receiveShadow problem for imported 3d objects in three.js

**URL:** <https://discourse.threejs.org/t/castshadow-and-receiveshadow-problem-for-imported-3d-objects-in-three-js/47445>\
**Category:** Questions\
**Tags:** shadows, 3ds-max, gltf-loader, blender, threejs\
**Created:** [January 30, 2023, 5:34pm UTC](https://discourse.threejs.org/t/castshadow-and-receiveshadow-problem-for-imported-3d-objects-in-three-js/47445 "2023-01-30T17:34:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohammadreza\_Aalaei](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mohammadreza_aalaei/32/32952_2.png) [@mohammadreza\_Aalaei](https://discourse.threejs.org/u/mohammadreza_Aalaei)\
**Post date:** [January 30, 2023, 5:34pm UTC](https://discourse.threejs.org/t/castshadow-and-receiveshadow-problem-for-imported-3d-objects-in-three-js/47445/1 "2023-01-30T17:34:58Z")

</div>

Whenever I import a 3d object from 3dsMax or blender into three.js as GLTF files, I can’t see any shadows received or cast by the object. While loading, I set the castShadow and receiveShadow properties both to true, but, as seen in the picture, none of them work.

 ![castShadow](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/f/2/f24eb3e1eb056cbc425a254b6499008ff602838c.jpeg)

Here is the code I write to import the model:

```javascript
let gltf = new GLTFLoader()
gltf.load("../src/box8.glb", (gltf) => {
    let loader = gltf.scene;
    loader.castShadow = true
    loader.receiveShadow = true
    loader.position.y = 1.5
    loader.position.z = 0
    loader.position.x = -0.05
    scene.add(loader)
})

```

---

<div class="post-metadata">

**Author:** ![PavelBoytchev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/pavelboytchev/32/38639_2.png) [@PavelBoytchev](https://discourse.threejs.org/u/PavelBoytchev)\
**Post date:** [January 30, 2023, 6:23pm UTC](https://discourse.threejs.org/t/castshadow-and-receiveshadow-problem-for-imported-3d-objects-in-three-js/47445/2 "2023-01-30T18:23:18Z")

</div>

You might have to traverse the children meshes of the scene and set their `castShadow` and `receiveShadow`. Something like:

```javascript
gltf.scene.traverse ( function ( child )
{
    if ( child.isMesh )
    {
        child.castShadow = true;
        child.receiveShadow = true;
    }
});

```

---

<div class="post-metadata">

**Author:** ![Lawrence3DPK](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lawrence3dpk/32/29184_2.png) [@Lawrence3DPK](https://discourse.threejs.org/u/Lawrence3DPK)\
**Post date:** [January 31, 2023, 10:24am UTC](https://discourse.threejs.org/t/castshadow-and-receiveshadow-problem-for-imported-3d-objects-in-three-js/47445/3 "2023-01-31T10:24:38Z")

</div>

You’ll also have to enable shadow Map on the renderer, set directionalLight.castShadow to true and setup the directional lights shadow camera to contain the objects needed to cast shadows, take a look at [this example in the documentation](https://threejs.org/docs/#api/en/lights/shadows/DirectionalLightShadow) for a better understanding of how shadows are typically achieved

---

<div class="post-metadata">

**Author:** ![drcmda](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@drcmda](https://discourse.threejs.org/u/drcmda)\
**Post date:** [January 31, 2023, 1:42pm UTC](https://discourse.threejs.org/t/castshadow-and-receiveshadow-problem-for-imported-3d-objects-in-three-js/47445/4 "2023-01-31T13:42:32Z")

</div>

> [@mohammadreza\_Aalaei](#):
>
> `gltf.load("../src/box8.glb", (gltf) => {`

and just to fix your next problem, because this will blow, that’s not a valid path. if this works at all it’s accidental, but it won’t run in production. you can’t leave /src and you can’t fetch any asset from within /src. assets are in /public. if you have /public/box8.glb the path is “/box8.glb”.

---

<div class="post-metadata">

**Author:** ![mohammadreza\_Aalaei](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mohammadreza_aalaei/32/32952_2.png) [@mohammadreza\_Aalaei](https://discourse.threejs.org/u/mohammadreza_Aalaei)\
**Post date:** [January 31, 2023, 6:17pm UTC](https://discourse.threejs.org/t/castshadow-and-receiveshadow-problem-for-imported-3d-objects-in-three-js/47445/5 "2023-01-31T18:17:58Z")

</div>

Thanks for your suggestion, it worked 👌
