Replies: 4 comments 4 replies
-
you do it the exact same way you would layer objects in plain threejs. i would suggest useEffect (executes after the graph renders and is committed) or useLayoutEffect (executes after render, but before commit to threejs) const ref = useRef()
useLayoutEffect(() => {
ref.current.layers.enable(layer)
...
}, [layer])
return <mesh ref={ref} /> otherwise doing as for materials, i don't think you can set layers on them in threejs. |
Beta Was this translation helpful? Give feedback.
-
I see that this example was made with three.js r 100dev is there any workaround to the same with newest release of three.js - I done some test's and this didn't work https://codesandbox.io/s/caustics-forked-xy3cgn?file=/src/App.js:815-827 |
Beta Was this translation helpful? Give feedback.
-
I have also faced the problem, any update? |
Beta Was this translation helpful? Give feedback.
-
i have faced the same problem with like solar system i want sun to be ambiant and the other planets spot from the sun |
Beta Was this translation helpful? Give feedback.
-
Hey everyone! I'm trying to implement selective lights with layers in my scene as i have multiple materials and some of them need more light and some don't need it.
I found this example in threeJs and I'm trying to make it work in r3f.
Here is the light:
<spotLight layers={0} ref={lightRef} intensity={0.5} position={[40, 30, 40]} penumbra={0.5} shadow-mapSize-width={5120} shadow-mapSize-height={5120}/>
here is one mesh in a diffrent layer:
<mesh layers={1} position={position} scale={[0.7, 0.7, 0.7]} geometry={geometry} rotation={[-Math.PI / 2, 0, 0]} onClick={onApplicationClick} > <meshStandardMaterial attach="material" {...material} layers={1} /> </mesh>
So, I've tried with the camera to see if the layers work. They work, i can render which layer I want and only the objects in that layer are rendered. Done this with
camera.layers.enable(0);
/camera.layers.enable(1);
, because i can get the camera from the useThree hook.But I'm searching a way to light only layer 0 meshes.
Done this in the spotLight component:
useFrame(() => { lightRef.current.layers.enable(0); });
but it doesn't work. :(
I think I need to do something like this:
spotLight = new THREE.SpotLight(0xffffff, 1); spotLight.layers.enable(0);
based on that threeJs example but I don't know how to implement it with r3f.
Any help will be appreciated, big time appreciated! :)
Beta Was this translation helpful? Give feedback.
All reactions