Replies: 4 comments
-
All you need for shadows is shadowMap on the canvas, receiveShadow + castShadow on the mesh, castShadow on the light source. There is otherwise nothing different, you make shadows as you normally would in three js. Three js has lots of helpers. You get the canvas object via i think youre mixing up r3f and three, what you ask for (helpers, making shadows project correctly, etc) is not the scope of this lib, you need to know threejs, there's no way around it. if you know how to make shadows in three, there is nothing that would be different over here, other than maybe an optional shortcut like |
Beta Was this translation helpful? Give feedback.
-
example 1: https://codesandbox.io/s/r3f-contact-shadow-q23sw?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
-
ps. the way you put objects into the scene via usememo looks strange to me, you can simply do and the reason your code doesn't produce shadows: gltfLoader.load(`${name}.gltf`, o => {
o.castShadow = true // <--- this does nothing at all
o.receiveShadow = true // <--- this does nothing at all or var material = new THREE.MeshPhongMaterial(materialProps)
material.receiveShadow = true // <--- this does nothing at all
material.needsUpdate = true // <--- this does nothing at all that's wrong. cast/receiveShadow is only valid for object3d's (mesh, line, etc). you're putting it onto the loader-data, which is just a random object, and materials, where it doesn't belong. |
Beta Was this translation helpful? Give feedback.
-
@bionicles drop this project into https://codesandbox.io and I will take a look. I'd be interested to see what's going on here. |
Beta Was this translation helpful? Give feedback.
-
Ive been having a nightmare time trying to get simple shadows to work for a project to help addiction medicine docs do exposure therapy for their patients. Have tried all sorts of demos etc. Yes, shadowMap, castShadow, and receiveShadow are True. I'm not sure how to inspect the frustrum of the camera, and it seems really hard to debug this in general, because you can't really see where the lights are located in the scene
The "Canvas" seems critical but if I try to give it a ref and console.log the current value of Canvas, it crashes. Please let us inspect the canvas element (or document how that's done)
A "debug" mode would be cool. Shadows work on other demos on my computer (18.04 ubuntu geforce 1070 ti, intel 12core cpu). Want me to provide obj/mtl files in a codepen?
Beta Was this translation helpful? Give feedback.
All reactions