diff --git a/apps/editor/components/editor/custom-camera-controls.tsx b/apps/editor/components/editor/custom-camera-controls.tsx new file mode 100644 index 00000000..4666a7bc --- /dev/null +++ b/apps/editor/components/editor/custom-camera-controls.tsx @@ -0,0 +1,49 @@ +"use client"; + +import { sceneRegistry } from "@pascal-app/core"; +import { useViewer } from "@pascal-app/viewer"; +import { CameraControls, CameraControlsImpl } from "@react-three/drei"; +import { useEffect, useMemo, useRef } from "react"; +import { Vector3 } from "three"; + +export const CustomCameraControls = () => { + const controls = useRef(null!); + const currentLevelId = useViewer((state) => state.currentLevelId); + + useEffect(() => { + let targetY = 0; + if (currentLevelId) { + const levelMesh = sceneRegistry.nodes.get(currentLevelId); + if (levelMesh) { + targetY = levelMesh.position.y; + } + } + const currentTarget = new Vector3(); + (controls.current as CameraControlsImpl).getTarget(currentTarget); + (controls.current as CameraControlsImpl).moveTo( + currentTarget.x, + targetY, + currentTarget.z, + true, + ); + }, [currentLevelId]); + + // Configure mouse buttons based on control mode and camera mode + const mouseButtons = useMemo(() => { + // Use ZOOM for orthographic camera, DOLLY for perspective camera + // const wheelAction = + // cameraMode === 'orthographic' + // ? CameraControlsImpl.ACTION.ZOOM + // : CameraControlsImpl.ACTION.DOLLY + const wheelAction = CameraControlsImpl.ACTION.DOLLY; + + return { + left: CameraControlsImpl.ACTION.NONE, + middle: CameraControlsImpl.ACTION.SCREEN_PAN, + right: CameraControlsImpl.ACTION.ROTATE, + wheel: wheelAction, + }; + }, []); + + return ; +}; diff --git a/apps/editor/components/editor.tsx b/apps/editor/components/editor/index.tsx similarity index 89% rename from apps/editor/components/editor.tsx rename to apps/editor/components/editor/index.tsx index 9bf63d68..4d22aaab 100644 --- a/apps/editor/components/editor.tsx +++ b/apps/editor/components/editor/index.tsx @@ -10,10 +10,10 @@ import { WallNode, } from "@pascal-app/core"; import { useGridEvents, useViewer, Viewer } from "@pascal-app/viewer"; -import { CameraControls, CameraControlsImpl, Stats } from "@react-three/drei"; + import { useFrame, useThree } from "@react-three/fiber"; import { useEffect, useMemo, useRef } from "react"; -import { Color, MathUtils, Mesh, Object3D } from "three"; +import { Color, MathUtils, Mesh, Object3D, Vector3 } from "three"; import { outline } from "three/addons/tsl/display/OutlineNode.js"; import { color, @@ -28,10 +28,11 @@ import { uniform, } from "three/tsl"; import { MeshBasicNodeMaterial, PostProcessing } from "three/webgpu"; -import { ActionMenu } from "./ui/action-menu"; -import { ToolManager } from "./tools/tool-manager"; -import { AppSidebar } from "./ui/sidebar/app-sidebar"; -import { SidebarProvider } from "./ui/primitives/sidebar"; +import { ActionMenu } from "../ui/action-menu"; +import { ToolManager } from "../tools/tool-manager"; +import { AppSidebar } from "../ui/sidebar/app-sidebar"; +import { SidebarProvider } from "../ui/primitives/sidebar"; +import { CustomCameraControls } from "./custom-camera-controls"; const selectedObjects: Object3D[] = []; @@ -40,7 +41,7 @@ useScene.getState().loadScene(); export default function Editor() { return ( -
+
{/* */} @@ -55,37 +56,11 @@ export default function Editor() { - +
); } -const EditorCameraManager = () => { - const controls = useRef(null!); - const currentLevelId = useViewer((state) => state.currentLevelId); - - useEffect(() => { - let targetY = 0; - if (currentLevelId) { - const levelMesh = sceneRegistry.nodes.get(currentLevelId); - if (levelMesh) { - targetY = levelMesh.position.y; - } - } - const { position } = controls.current.camera; - controls.current.setLookAt( - position.x, - targetY + 5, - position.z, - 0, - targetY, - 0, - true, - ); - }, [currentLevelId]); - - return ; -}; const TestUndo = () => { const { undo, redo, futureStates, pastStates } = useScene.temporal.getState();