Refactor mouse button handling and key event logic in MoveControls3D for improved clarity
This commit is contained in:
@@ -46,10 +46,7 @@ function MoveControls3D({
|
||||
const [initialPositions, setInitialPositions] = useState<Record<string, THREE.Vector3>>({});
|
||||
const [initialStates, setInitialStates] = useState<Record<string, { position: THREE.Vector3; rotation?: THREE.Euler; }>>({});
|
||||
const [isMoving, setIsMoving] = useState(false);
|
||||
const mouseButtonsDown = useRef<{ left: boolean; right: boolean }>({
|
||||
left: false,
|
||||
right: false,
|
||||
});
|
||||
const mouseButtonsDown = useRef<{ left: boolean; right: boolean }>({ left: false, right: false, });
|
||||
|
||||
const updateBackend = (
|
||||
productName: string,
|
||||
@@ -79,9 +76,9 @@ function MoveControls3D({
|
||||
};
|
||||
|
||||
const onKeyUp = (event: KeyboardEvent) => {
|
||||
const isModifierKey = event.key === "Control" || event.key === "Shift";
|
||||
const isModifierKey = (!event.shiftKey && !event.ctrlKey);
|
||||
|
||||
if (isModifierKey) {
|
||||
if (isModifierKey && keyEvent !== "") {
|
||||
setKeyEvent("");
|
||||
}
|
||||
};
|
||||
@@ -196,7 +193,6 @@ function MoveControls3D({
|
||||
raycaster.setFromCamera(pointer, camera);
|
||||
const hit = raycaster.ray.intersectPlane(plane, intersectionPoint);
|
||||
|
||||
|
||||
if (hit) {
|
||||
if (mouseButtonsDown.current.left || mouseButtonsDown.current.right) {
|
||||
if (movedObjects[0]) {
|
||||
@@ -209,18 +205,18 @@ function MoveControls3D({
|
||||
if (dragOffset) {
|
||||
const rawBasePosition = new THREE.Vector3().addVectors(intersectionPoint, dragOffset);
|
||||
|
||||
let moveSpeed = keyEvent.includes("Shift") ? 0.05 : 1;
|
||||
let moveDistance = keyEvent.includes("Shift") ? 0.05 : 1;
|
||||
|
||||
const initialBasePosition = initialPositions[movedObjects[0].uuid];
|
||||
const positionDifference = new THREE.Vector3().subVectors(rawBasePosition, initialBasePosition);
|
||||
|
||||
const adjustedDifference = positionDifference.multiplyScalar(moveSpeed);
|
||||
const adjustedDifference = positionDifference.multiplyScalar(moveDistance);
|
||||
|
||||
const baseNewPosition = new THREE.Vector3().addVectors(initialBasePosition, adjustedDifference);
|
||||
|
||||
if (keyEvent.includes("Ctrl")) {
|
||||
baseNewPosition.x = snapControls(baseNewPosition.x, "Ctrl");
|
||||
baseNewPosition.z = snapControls(baseNewPosition.z, "Ctrl");
|
||||
baseNewPosition.x = snapControls(baseNewPosition.x, keyEvent);
|
||||
baseNewPosition.z = snapControls(baseNewPosition.z, keyEvent);
|
||||
}
|
||||
|
||||
movedObjects.forEach((movedAsset: THREE.Object3D) => {
|
||||
|
||||
Reference in New Issue
Block a user