fix: format
This commit is contained in:
+2269
-10129
File diff suppressed because it is too large
Load Diff
@@ -107,7 +107,8 @@ export function EditorPage(): React.JSX.Element {
|
|||||||
setTransformMode(mode);
|
setTransformMode(mode);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const applySnapshot = useCallback((snapshot: ObjectTransform[]) => {
|
const applySnapshot = useCallback(
|
||||||
|
(snapshot: ObjectTransform[]) => {
|
||||||
if (!sceneData) return;
|
if (!sceneData) return;
|
||||||
setSceneData((prev) => {
|
setSceneData((prev) => {
|
||||||
if (!prev) return null;
|
if (!prev) return null;
|
||||||
@@ -116,16 +117,30 @@ export function EditorPage(): React.JSX.Element {
|
|||||||
if (transform) {
|
if (transform) {
|
||||||
return {
|
return {
|
||||||
...node,
|
...node,
|
||||||
position: [transform.position.x, transform.position.y, transform.position.z] as [number, number, number],
|
position: [
|
||||||
rotation: [transform.rotation.x, transform.rotation.y, transform.rotation.z] as [number, number, number],
|
transform.position.x,
|
||||||
scale: [transform.scale.x, transform.scale.y, transform.scale.z] as [number, number, number],
|
transform.position.y,
|
||||||
|
transform.position.z,
|
||||||
|
] as [number, number, number],
|
||||||
|
rotation: [
|
||||||
|
transform.rotation.x,
|
||||||
|
transform.rotation.y,
|
||||||
|
transform.rotation.z,
|
||||||
|
] as [number, number, number],
|
||||||
|
scale: [
|
||||||
|
transform.scale.x,
|
||||||
|
transform.scale.y,
|
||||||
|
transform.scale.z,
|
||||||
|
] as [number, number, number],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
});
|
});
|
||||||
return { ...prev, mapNodes: newMapNodes };
|
return { ...prev, mapNodes: newMapNodes };
|
||||||
});
|
});
|
||||||
}, [sceneData]);
|
},
|
||||||
|
[sceneData],
|
||||||
|
);
|
||||||
|
|
||||||
const handleUndo = useCallback(() => {
|
const handleUndo = useCallback(() => {
|
||||||
const snapshot = historyManager.current.undo();
|
const snapshot = historyManager.current.undo();
|
||||||
@@ -192,8 +207,16 @@ export function EditorPage(): React.JSX.Element {
|
|||||||
if (!sceneData) return;
|
if (!sceneData) return;
|
||||||
const snapshot = sceneData.mapNodes.map((node, index) => ({
|
const snapshot = sceneData.mapNodes.map((node, index) => ({
|
||||||
uuid: `node-${index}`,
|
uuid: `node-${index}`,
|
||||||
position: { x: node.position[0], y: node.position[1], z: node.position[2] },
|
position: {
|
||||||
rotation: { x: node.rotation[0], y: node.rotation[1], z: node.rotation[2] },
|
x: node.position[0],
|
||||||
|
y: node.position[1],
|
||||||
|
z: node.position[2],
|
||||||
|
},
|
||||||
|
rotation: {
|
||||||
|
x: node.rotation[0],
|
||||||
|
y: node.rotation[1],
|
||||||
|
z: node.rotation[2],
|
||||||
|
},
|
||||||
scale: { x: node.scale[0], y: node.scale[1], z: node.scale[2] },
|
scale: { x: node.scale[0], y: node.scale[1], z: node.scale[2] },
|
||||||
}));
|
}));
|
||||||
historyManager.current.saveSnapshot(snapshot);
|
historyManager.current.saveSnapshot(snapshot);
|
||||||
@@ -203,8 +226,16 @@ export function EditorPage(): React.JSX.Element {
|
|||||||
if (!sceneData) return;
|
if (!sceneData) return;
|
||||||
const snapshot = sceneData.mapNodes.map((node, index) => ({
|
const snapshot = sceneData.mapNodes.map((node, index) => ({
|
||||||
uuid: `node-${index}`,
|
uuid: `node-${index}`,
|
||||||
position: { x: node.position[0], y: node.position[1], z: node.position[2] },
|
position: {
|
||||||
rotation: { x: node.rotation[0], y: node.rotation[1], z: node.rotation[2] },
|
x: node.position[0],
|
||||||
|
y: node.position[1],
|
||||||
|
z: node.position[2],
|
||||||
|
},
|
||||||
|
rotation: {
|
||||||
|
x: node.rotation[0],
|
||||||
|
y: node.rotation[1],
|
||||||
|
z: node.rotation[2],
|
||||||
|
},
|
||||||
scale: { x: node.scale[0], y: node.scale[1], z: node.scale[2] },
|
scale: { x: node.scale[0], y: node.scale[1], z: node.scale[2] },
|
||||||
}));
|
}));
|
||||||
historyManager.current.saveSnapshot(snapshot);
|
historyManager.current.saveSnapshot(snapshot);
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
import { useRef, useEffect, useCallback, forwardRef, useImperativeHandle } from 'react';
|
import {
|
||||||
import { useFrame, useThree } from '@react-three/fiber';
|
useRef,
|
||||||
import { OrbitControls } from '@react-three/drei';
|
useEffect,
|
||||||
import * as THREE from 'three';
|
useCallback,
|
||||||
|
forwardRef,
|
||||||
|
useImperativeHandle,
|
||||||
|
} from "react";
|
||||||
|
import { useFrame, useThree } from "@react-three/fiber";
|
||||||
|
import { OrbitControls } from "@react-three/drei";
|
||||||
|
import * as THREE from "three";
|
||||||
|
|
||||||
interface FlyControllerProps {
|
interface FlyControllerProps {
|
||||||
speed?: number;
|
speed?: number;
|
||||||
@@ -14,12 +20,11 @@ export interface FlyControllerRef {
|
|||||||
controls: any;
|
controls: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FlyControllerInner = forwardRef<FlyControllerRef, FlyControllerProps>(({
|
const FlyControllerInner = forwardRef<FlyControllerRef, FlyControllerProps>(
|
||||||
speed = 10,
|
(
|
||||||
verticalSpeed = 5,
|
{ speed = 10, verticalSpeed = 5, onPositionChange, disabled = false },
|
||||||
onPositionChange,
|
ref,
|
||||||
disabled = false
|
) => {
|
||||||
}, ref) => {
|
|
||||||
const { camera } = useThree();
|
const { camera } = useThree();
|
||||||
const keys = useRef<{ [key: string]: boolean }>({});
|
const keys = useRef<{ [key: string]: boolean }>({});
|
||||||
const controlsRef = useRef<any>(null);
|
const controlsRef = useRef<any>(null);
|
||||||
@@ -38,11 +43,11 @@ const FlyControllerInner = forwardRef<FlyControllerRef, FlyControllerProps>(({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.addEventListener('keydown', handleKeyDown);
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
window.addEventListener('keyup', handleKeyUp);
|
window.addEventListener("keyup", handleKeyUp);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('keydown', handleKeyDown);
|
window.removeEventListener("keydown", handleKeyDown);
|
||||||
window.removeEventListener('keyup', handleKeyUp);
|
window.removeEventListener("keyup", handleKeyUp);
|
||||||
};
|
};
|
||||||
}, [handleKeyDown, handleKeyUp]);
|
}, [handleKeyDown, handleKeyUp]);
|
||||||
|
|
||||||
@@ -54,14 +59,26 @@ const FlyControllerInner = forwardRef<FlyControllerRef, FlyControllerProps>(({
|
|||||||
|
|
||||||
// ZQSD (AZERTY): Z=forward, S=backward, Q=left, D=right
|
// ZQSD (AZERTY): Z=forward, S=backward, Q=left, D=right
|
||||||
// Support aussi QWERTY et flèches
|
// Support aussi QWERTY et flèches
|
||||||
const isForward = keys.current['KeyW'] || keys.current['KeyZ'] || keys.current['ArrowUp'];
|
const isForward =
|
||||||
const isBackward = keys.current['KeyS'] || keys.current['ArrowDown'];
|
keys.current["KeyW"] || keys.current["KeyZ"] || keys.current["ArrowUp"];
|
||||||
const isLeft = keys.current['KeyQ'] || keys.current['KeyA'] || keys.current['ArrowLeft'];
|
const isBackward = keys.current["KeyS"] || keys.current["ArrowDown"];
|
||||||
const isRight = keys.current['KeyD'] || keys.current['ArrowRight'];
|
const isLeft =
|
||||||
|
keys.current["KeyQ"] ||
|
||||||
|
keys.current["KeyA"] ||
|
||||||
|
keys.current["ArrowLeft"];
|
||||||
|
const isRight = keys.current["KeyD"] || keys.current["ArrowRight"];
|
||||||
|
|
||||||
const direction = new THREE.Vector3();
|
const direction = new THREE.Vector3();
|
||||||
const frontVector = new THREE.Vector3(0, 0, Number(isBackward) - Number(isForward));
|
const frontVector = new THREE.Vector3(
|
||||||
const sideVector = new THREE.Vector3(Number(isRight) - Number(isLeft), 0, 0);
|
0,
|
||||||
|
0,
|
||||||
|
Number(isBackward) - Number(isForward),
|
||||||
|
);
|
||||||
|
const sideVector = new THREE.Vector3(
|
||||||
|
Number(isRight) - Number(isLeft),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
direction.subVectors(frontVector, sideVector);
|
direction.subVectors(frontVector, sideVector);
|
||||||
if (direction.lengthSq() > 0) {
|
if (direction.lengthSq() > 0) {
|
||||||
@@ -71,10 +88,10 @@ const FlyControllerInner = forwardRef<FlyControllerRef, FlyControllerProps>(({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Space = monter, Shift = descendre
|
// Space = monter, Shift = descendre
|
||||||
if (keys.current['Space']) {
|
if (keys.current["Space"]) {
|
||||||
camera.position.y += verticalSpeed * delta;
|
camera.position.y += verticalSpeed * delta;
|
||||||
}
|
}
|
||||||
if (keys.current['ShiftLeft'] || keys.current['ShiftRight']) {
|
if (keys.current["ShiftLeft"] || keys.current["ShiftRight"]) {
|
||||||
camera.position.y -= verticalSpeed * delta;
|
camera.position.y -= verticalSpeed * delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +114,7 @@ const FlyControllerInner = forwardRef<FlyControllerRef, FlyControllerProps>(({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export default FlyControllerInner;
|
export default FlyControllerInner;
|
||||||
@@ -92,7 +92,7 @@ export default function MapViewer({
|
|||||||
<axesHelper args={[10]} />
|
<axesHelper args={[10]} />
|
||||||
|
|
||||||
<group
|
<group
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (!(window as any).isTransforming) {
|
if (!(window as any).isTransforming) {
|
||||||
onSelectNode(null);
|
onSelectNode(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user