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 doesn't respect camera up direction #522

Open
Irev-Dev opened this issue Aug 22, 2021 · 5 comments
Open

GizmoHelper doesn't respect camera up direction #522

Irev-Dev opened this issue Aug 22, 2021 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Irev-Dev
Copy link

versions

image

Problem description:

Setting the camera up position to something other than the default (e.g. [0, 0, 1]) works until the gizmo is used at which point it snaps back to the default up direction.

Steps to reproduce

I hope that describes the problem, its pretty obvious one you try it. Here's a video (at the end you can see I drag the mouse horizontally but the orbit doesn't match)

Screen.Recording.2021-08-22.at.3.28.24.pm.mov

I had a very quick go at debugging but am really not sure what I'm doing, I could see in https://github.com/pmndrs/drei/blob/master/src/core/GizmoHelper.tsx the line
mainCamera.up.set(0, 1, 0).applyQuaternion(q1).normalize()
which I thought might be related but am not sure.

Having a lot of fun using r3f :)

@Irev-Dev Irev-Dev added the bug Something isn't working label Aug 22, 2021
@joshuaellis
Copy link
Member

GizmoHelper came in as a contribution, as such we'll need the community to resolve issues like this. Thank you for the report!

@joshuaellis joshuaellis added the help wanted Extra attention is needed label Sep 18, 2021
@JulesBlm
Copy link

This bug seems to have been introduced in pull request #496 (commit). I tried removing the .set(0, 1, 0) in mainCamera.up.set(0, 1, 0).applyQuaternion(q1).normalize() line 102 in GizmoHelper.tsx but that did not work.

@cjimmy
Copy link

cjimmy commented Dec 21, 2021

I'm not an expert here by any means, but I was able to get GizmoHelper to have Z be up without touching the PerspectiveCamera up prop.

You can change the global default up with

  THREE.Object3D.DefaultUp.set(0, 0, 1)

and wrap it in a useEffect so it only happens once

  useEffect(() => {
    THREE.Object3D.DefaultUp.set(0, 0, 1)
  }, [])

However, there's still something wrong with how the GLTF loads. I had to rotate it. But! GizmoHelper works as expected.

See forked version of your sandbox:
https://codesandbox.io/s/gizmohelper-doesnt-respect-camera-axis-forked-3rs9p?file=/src/App.tsx:565-636

@aboss-developer
Copy link

aboss-developer commented Oct 16, 2022

Setting camera direction z-axis up [0,0,1] is not getting applied to GizmoViewcube.

const DefaultControls = (props) => {
return (
    <>
      <PerspectiveCamera ref={cameraRef} position={[0, 0, 10]} up={[0,0,1]} makeDefault/>
      <OrbitControls ref={orbitRef} camera={camera} maxPolarAngle={Math.PI / 2} makeDefault onChange={onChange} enableDamping={false}/>
      <GizmoHelper
        alignment="top-right"
        margin={[50, 50]}
        onTarget={() => orbitRef?.current?.target0 as Vector3}
        onUpdate={() => {
          if (orbitRef.current) {
            orbitRef.current.update();
          }
        }}
      >
         {/* <GizmoViewport axisColors={['red', 'green', 'blue']} labelColor={'black'} /> */}
        <GizmoViewcube {...{color:'white', faces}} />
      </GizmoHelper>
    </>
  )
}
}

const CCanvas = (props) => {
    return (
    <Canvas gl={{ preserveDrawingBuffer: true }}  >
      <axesHelper/>
      <Environment />
      <DefaultControls setOrbit={setOrbit} />
      <Floor />
    </Canvas>)
}

@mdtusz
Copy link
Contributor

mdtusz commented Mar 3, 2023

This seems to be sorta fixed if you have orbit controls with makeDefault set, but the animation when orbiting from a GizmoViewcube doesn't respect the orbit controls UP.

I think this should be a straightforwards fix though by just modifying animation block to check for the orbit "up", or alternatively it may be easier to just allow users to provide an UP prop direclty - it isn't really something that changes in applications where you want to use a gizmo cube (i.e. CAD type tools).

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

No branches or pull requests

6 participants