Okay there is another error here.
I thought useFrame would be useful to use a getposition everytime orbit controls move but its not…Here is the code, can anyone help me? Thanks.
const cameraRef = useRef(null)
const {
camera, gl:{domElement},
} = useThree()
useEffect(() => {
camera.position.set(5,2,0)
cameraRef.current = camera
console.log("Camera",cameraRef.current.position)
},[camera])
useFrame(() => {
// console.log(cameraRef.current.position)
})
useEffect(() => {
console.log(cameraRef.current.position)
},[cameraRef])
let positions = useMemo(() => {
if (cameraRef.current) {
let pos = [
{x:-2,y:0,z:0},
{x:2,y:0,z:0},
{x:0,y:2,z:0},
{x:0,y:-2,z:0},
{x:0,y:0,z:2},
{x:0,y:0,z:-2}
].map(pos =>
[
(cameraRef.current?.position.x - 5)+ pos.x,
(cameraRef.current?.position.y - 2) + pos.y,
(cameraRef.current?.position.z) + pos.z
]
)
console.log(pos)
return pos
}
},[cameraRef])
And here is the display
<OrbitControls
ref={cameraRef}
target={[0,0,0]}
args={[camera,domElement]}
// onUpdate={
// () => {
// }
// }
/>
<color attach={"background"} args={[0,0,0]}></color>
{/* Initializing Point Light Of the Box Created */}
{/* This six point lights should follow where-ever the camera goes to make it look like
a normal map effect in lights
*/}
{positions?.map((position, index) => {
console.log(position)
return (
<pointLight key={index} color={"white"} intensity="5" position={position} />
)
})}
As you see there is useFrame wherein I can see the updates in the cameraRef.position but I cannot pass it in my positions (x,y,z) and I don’t know why…I don’t understand, what I am missing here guys?