Skip to content

Commit

Permalink
fix: GizmoHelper - Check if default controls is OrbitControls before …
Browse files Browse the repository at this point in the history
…resetting UP vector (#1083)
  • Loading branch information
FarazzShaikh committed Oct 6, 2022
1 parent a630d37 commit e7daabd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/GizmoHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from 'three'
import { OrthographicCamera } from './OrthographicCamera'
import { useCamera } from './useCamera'
import { OrbitControls as OrbitControlsType } from 'three-stdlib'

type GizmoHelperContext = {
tweenCamera: (direction: Vector3) => void
Expand Down Expand Up @@ -56,6 +57,10 @@ export type GizmoHelperProps = JSX.IntrinsicElements['group'] & {
onTarget?: () => Vector3 // return the target to rotate around
}

const isOrbitControls = (controls: ControlsProto): controls is OrbitControlsType => {
return 'minPolarAngle' in (controls as OrbitControlsType)
}

export const GizmoHelper = ({
alignment = 'bottom-right',
margin = [80, 80],
Expand Down Expand Up @@ -126,7 +131,13 @@ export const GizmoHelper = ({
if (animating.current) {
if (q1.angleTo(q2) < 0.01) {
animating.current = false
mainCamera.up.copy(defaultUp.current)

// Orbit controls uses UP vector as the orbit axes,
// so we need to reset it after the animation is done
// moving it around for the controls to work correctly
if (isOrbitControls(defaultControls)) {
mainCamera.up.copy(defaultUp.current)
}
} else {
const step = delta * turnRate
// animate position by doing a slerp and then scaling the position on the unit sphere
Expand Down

1 comment on commit e7daabd

@vercel
Copy link

@vercel vercel bot commented on e7daabd Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.