new TransformControls3D bug fix
This commit is contained in:
@@ -37,6 +37,7 @@ function RotateControls3D() {
|
|||||||
const [initialRotations, setInitialRotations] = useState<Record<string, THREE.Euler>>({});
|
const [initialRotations, setInitialRotations] = useState<Record<string, THREE.Euler>>({});
|
||||||
const [initialPositions, setInitialPositions] = useState<Record<string, THREE.Vector3>>({});
|
const [initialPositions, setInitialPositions] = useState<Record<string, THREE.Vector3>>({});
|
||||||
const [isRotating, setIsRotating] = useState(false);
|
const [isRotating, setIsRotating] = useState(false);
|
||||||
|
const [isIndividualRotating, setIsIndividualRotating] = useState(false);
|
||||||
const prevPointerPosition = useRef<THREE.Vector2 | null>(null);
|
const prevPointerPosition = useRef<THREE.Vector2 | null>(null);
|
||||||
const rotationCenter = useRef<THREE.Vector3 | null>(null);
|
const rotationCenter = useRef<THREE.Vector3 | null>(null);
|
||||||
const mouseButtonsDown = useRef<{ left: boolean; right: boolean }>({ left: false, right: false, });
|
const mouseButtonsDown = useRef<{ left: boolean; right: boolean }>({ left: false, right: false, });
|
||||||
@@ -120,6 +121,12 @@ function RotateControls3D() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.key.toLowerCase() === 'i') {
|
||||||
|
if (rotatedObjects.length > 0) {
|
||||||
|
setIsIndividualRotating(!isIndividualRotating);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (event.key.toLowerCase() === "escape") {
|
if (event.key.toLowerCase() === "escape") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
resetToInitialRotations();
|
resetToInitialRotations();
|
||||||
@@ -155,7 +162,7 @@ function RotateControls3D() {
|
|||||||
canvasElement.removeEventListener("keydown", onKeyDown);
|
canvasElement.removeEventListener("keydown", onKeyDown);
|
||||||
canvasElement?.removeEventListener("keyup", onKeyUp);
|
canvasElement?.removeEventListener("keyup", onKeyUp);
|
||||||
};
|
};
|
||||||
}, [camera, scene, toggleView, toolMode, selectedAssets, rotatedObjects, pastedObjects, duplicatedObjects, movedObjects, keyEvent, initialPositions, initialRotations]);
|
}, [camera, scene, toggleView, toolMode, selectedAssets, rotatedObjects, pastedObjects, duplicatedObjects, movedObjects, keyEvent, initialPositions, initialRotations, isIndividualRotating]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeModule !== "builder" || toolMode !== 'cursor' || toggleView) {
|
if (activeModule !== "builder" || toolMode !== 'cursor' || toggleView) {
|
||||||
@@ -214,10 +221,12 @@ function RotateControls3D() {
|
|||||||
wasShiftHeldRef
|
wasShiftHeldRef
|
||||||
});
|
});
|
||||||
|
|
||||||
const relativePosition = new THREE.Vector3().subVectors(obj.position, center);
|
if (!isIndividualRotating) {
|
||||||
const rotationMatrix = new THREE.Matrix4().makeRotationY(angleDelta);
|
const relativePosition = new THREE.Vector3().subVectors(obj.position, center);
|
||||||
relativePosition.applyMatrix4(rotationMatrix);
|
const rotationMatrix = new THREE.Matrix4().makeRotationY(angleDelta);
|
||||||
obj.position.copy(center).add(relativePosition);
|
relativePosition.applyMatrix4(rotationMatrix);
|
||||||
|
obj.position.copy(center).add(relativePosition);
|
||||||
|
}
|
||||||
|
|
||||||
const rotationQuat = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), angleDelta);
|
const rotationQuat = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), angleDelta);
|
||||||
obj.quaternion.multiply(rotationQuat);
|
obj.quaternion.multiply(rotationQuat);
|
||||||
|
|||||||
@@ -226,11 +226,11 @@ function TransformControls3D() {
|
|||||||
const delta = new THREE.Vector3().copy(temp.position).sub(initialPivotPositionRef.current);
|
const delta = new THREE.Vector3().copy(temp.position).sub(initialPivotPositionRef.current);
|
||||||
obj.position.copy(initialPos).add(delta);
|
obj.position.copy(initialPos).add(delta);
|
||||||
} else if (controls.mode === 'rotate') {
|
} else if (controls.mode === 'rotate') {
|
||||||
const deltaQuat = new THREE.Quaternion().setFromEuler(temp.rotation);
|
const deltaQuat = temp.quaternion.clone();
|
||||||
const relPos = initialPos.clone().sub(initialPivotPositionRef.current);
|
const relPos = initialPos.clone().sub(initialPivotPositionRef.current);
|
||||||
relPos.applyQuaternion(deltaQuat);
|
relPos.applyQuaternion(deltaQuat);
|
||||||
obj.position.copy(initialPivotPositionRef.current).add(relPos);
|
obj.position.copy(initialPivotPositionRef.current).add(relPos);
|
||||||
obj.quaternion.copy(initialQuat).multiply(deltaQuat);
|
obj.quaternion.copy(deltaQuat).multiply(initialQuat);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user