Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GizmoHelper along with CameraControls not working #1935

Open
Russo-creation opened this issue Apr 23, 2024 · 1 comment
Open

GizmoHelper along with CameraControls not working #1935

Russo-creation opened this issue Apr 23, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Russo-creation
Copy link

Russo-creation commented Apr 23, 2024

"three": "^0.163.0",
"@react-three/fiber": "^8.16.2",
"@react-three/drei": "^9.105.4",

Problem description:

Trying use both components (GizmoHelper and CameraControls) along gives an error while clicking on gizmo's cube (Gizmo with other components like OrbitControls, Perspective Camera works fine):

ERROR
Cannot use 'in' operator to search for 'minPolarAngle' in null
TypeError: Cannot use 'in' operator to search for 'minPolarAngle' in null
    at isOrbitControls (http://localhost:3000/static/js/bundle.js:44459:26)
    at Object.current (http://localhost:3000/static/js/bundle.js:44508:15)
    at render$1 (http://localhost:3000/static/js/bundle.js:46735:22)
    at loop (http://localhost:3000/static/js/bundle.js:46764:19)
GizmoHelper.js:18 Uncaught TypeError: Cannot use 'in' operator to search for 'minPolarAngle' in null
    at isOrbitControls (GizmoHelper.js:18:1)
    at Object.current (GizmoHelper.js:67:1)
    at render$1 (index-c636ef6d.esm.js:1542:1)
    at loop (index-c636ef6d.esm.js:1571:1)

When trying to set makedefault then getting different error while cliking on gizmo cube:

Uncaught TypeError: Cannot read properties of undefined (reading 'x')
    at Vector3.add (three.module.js:3930:1)
    at Object.current (GizmoHelper.js:75:1)
    at render$1 (index-c636ef6d.esm.js:1542:1)
    at loop (index-c636ef6d.esm.js:1571:1)

code:

<Canvas>
<PerspectiveCamera
        ref={refCamera}
        makeDefault
        near={200}
        far={150000}
        position={[60, 90, 1000]}
        fov={fov_camera}
 />
<CameraControls
        setTarget={[60, 90, 0]}
        minPolarAngle={1}
/>
<GizmoHelper margin={[60, 60]} >
      <GizmoViewcube />
</GizmoHelper>
</Canvas>

https://codesandbox.io/p/sandbox/cameracontrols-basic-sew669?file=%2Fsrc%2FApp.js%3A119%2C5-119%2C12

@Russo-creation Russo-creation added the bug Something isn't working label Apr 23, 2024
@geon
Copy link

geon commented Apr 24, 2024

I get the same second error. My CameraControls tag has the makeDefault={true} attribute set.

When I debug it, I can see that in gizmo-helper.tsx in the function tweenCamera, focusPoint.current gets set to undefined:

if (defaultControls || onTarget) focusPoint.current = defaultControls?.target || onTarget?.()

It happens because defaultControls is defined, but defaultControls.target is not. I think this object comes from the camera-controls npm package: https://github.com/yomotsu/camera-controls/blob/cf392955edfec75e45c6a2dc36f53891319f3918/src/CameraControls.ts#L380

In the GizmoHelper, that object is just cast to an interface. Dangerous!

const defaultControls = useThree((state) => state.controls) as ControlsProto

type ControlsProto = { update(): void; target: Vector3 }

I haven't managed to fix the bug. Perhaps it is a clue for someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants