I am currently creating an editor using R3F (React Three Fiber). I am visualizing the light using the useHelper from the Drei library, but how can I capture the specified DirectionalLightHelper with an OnClick event? Is it practical to implement this with the mouse and raycasting?
Sample code:
import { DirectionalLightHelper } from "three";
import { useRef } from "react";
const myLight = () => {
const ref = useRef();
// I want to attach onClickEvent in this lightHelper.
useHelper(ref, DirectionalLightHelper);
return (
<>
<directionalLight
ref={ref}
position={[5, 5, 5]}
/>
</>
)
}
I’m not sure if this is an elegant solution, but for now, I set up an invisible box and added onPointerDown and OnPointerMissed to handle it. If there’s a more precise and elegant way to incorporate it with useHelper, I would appreciate any feedback.
this is fine, though you probably want it to be a <planeGeometry>, the position isn’t enough, you also need the orientation/rotation and scale. you can copy this over from the useHelper ref.