-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: polish visualizer zoom and controls (#929)
* feat: polish zoom to fit tangle & limit user controls * feat: add sinusodial to tangle distances * chore: add comments for the tangle mesh * chore: remove unnecessary export * chore: remove unnecessary files * fix: initial movement of camera
- Loading branch information
Showing
8 changed files
with
198 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { CameraControls as DreiCameraControls } from "@react-three/drei"; | ||
import { getCameraAngles } from "./utils"; | ||
import React, { useEffect } from "react"; | ||
import { useThree } from "@react-three/fiber"; | ||
import { CanvasElement } from "./enums"; | ||
import { useTangleStore } from "./store"; | ||
import { VISUALIZER_PADDINGS } from "./constants"; | ||
|
||
const CameraControls = () => { | ||
const [shouldLockZoom, setShouldLockZoom] = React.useState<boolean>(false); | ||
const controls = React.useRef<DreiCameraControls>(null); | ||
|
||
const CAMERA_ANGLES = getCameraAngles(); | ||
|
||
const zoom = useTangleStore((s) => s.zoom); | ||
const get = useThree((state) => state.get); | ||
const mesh = get().scene.getObjectByName(CanvasElement.TangleWrapperMesh); | ||
|
||
// Set fixed zoom | ||
useEffect(() => { | ||
if (controls.current && shouldLockZoom) { | ||
controls.current.maxZoom = zoom; | ||
controls.current.minZoom = zoom; | ||
} | ||
}, [controls, zoom, shouldLockZoom]); | ||
|
||
// Fix to TangleMesh | ||
useEffect(() => { | ||
if (controls.current && mesh) { | ||
controls.current.fitToBox(mesh, false, { ...VISUALIZER_PADDINGS }); | ||
controls.current.setOrbitPoint(0, 0, 0); | ||
setShouldLockZoom(true); | ||
} | ||
}, [controls, mesh]); | ||
|
||
return <DreiCameraControls ref={controls} makeDefault {...CAMERA_ANGLES} />; | ||
}; | ||
|
||
export default CameraControls; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface ICameraAngles { | ||
minAzimuthAngle: number | ||
minPolarAngle: number | ||
maxPolarAngle: number | ||
maxAzimuthAngle: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.