Model not showing castShadow. How to fix the problem?

import { useGLTF, ContactShadows } from ‘@react-three/drei’;
import { useEffect, useRef } from “react”;
import { Environment, OrbitControls, useHelper } from ‘@react-three/drei’;
import { Group,PerspectiveCamera, SpotLight ,DirectionalLight} from “three”;
const Model = () => {
console.log(“mainscene”)
const gltf = useGLTF(‘src/assets/model/GirlLoop.glb’);
const group = useRef()
gltf.scene.traverse( function( node ) {
if ( node.isMesh ) { node.castShadow = true; }
} );

const camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)

useEffect(() => {
gltf.scene.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
}
});
}, [gltf.scene]);

useEffect(() => {
camera.position.set(5,5,5)
camera.lookAt(0,-3.5,-0.2)

}, [camera]);

return (<>
<OrbitControls
enableZoom={true}
maxDistance={15}
minDistance={1}
minAzimuthAngle={-Math.PI / 8} // Limit to 45 degrees to the left
maxAzimuthAngle={Math.PI / 8}
/>
<primitive object={gltf.scene} ref={group} scale={[0.8, 0.8, 0.8]} position={[0,-2,-0.16]} rotation={[0, -Math.PI / 2, 0]} castShadow/>



   <directionalLight position={[2,3,-0.16]} intensity={5} castShadow shadow-mapSize-width={1024}
   shadow-mapSize-height={1024}
  />
   <ambientLight intensity={1}/>
   <ContactShadows position={[0,-2,-0.16]} rotation={[0,-Math.PI/2,0]} scale={0.8} opacity={0.1} blur={0.5} color='black'/>
   
</>

);
}

export default Model;

Is there anything in the scene that also has .receiveShadow set to true? Otherwise the model may be casting shadows, but there’s nothing to show them on

the whole model shadow is showing on the floor. But i want girl shadow on the table. both of the part of same model.

Aren’t these (both floor and under the girl sitting on the chair) shadows baked?

They don’t seem consistent with that a single DirectionalLight would produce (let alone that reflection underneath her feet.)

the shadow of her thumb is not showing on the table.

I dont know, but maybe i see shadow under left hand on table and its very bright.
Try move camera to table hand.

Is your ambientLight overwhelming the directionalLight?

The light is coming from the front, i think her hand is casting a shadow on the chair or on the floor. If you put the light behind her, she should cast the shadow on the desk. If you have a spotlight on your phone you can try this in the real world.

1 Like