Merge remote-tracking branch 'origin/main-dev' into main-demo
This commit is contained in:
@@ -164,7 +164,7 @@ function MoveControls2D({
|
||||
return new THREE.Vector3().subVectors(pointPosition, hitPoint);
|
||||
}, []);
|
||||
|
||||
const movePoints = useCallback(() => {
|
||||
const movePoints = (() => {
|
||||
if (selectedPoints.length === 0) return;
|
||||
|
||||
const states: Record<string, { position: THREE.Vector3; rotation?: THREE.Euler; }> = {};
|
||||
@@ -192,9 +192,9 @@ function MoveControls2D({
|
||||
|
||||
setMovedObjects(selectedPoints);
|
||||
setIsMoving(true);
|
||||
}, [selectedPoints, camera, pointer, plane, raycaster, calculateDragOffset]);
|
||||
});
|
||||
|
||||
const resetToInitialPositions = useCallback(() => {
|
||||
const resetToInitialPositions = () => {
|
||||
setTimeout(() => {
|
||||
movedObjects.forEach((movedPoint: THREE.Object3D) => {
|
||||
if (movedPoint.userData.pointUuid && initialStates[movedPoint.uuid]) {
|
||||
@@ -218,7 +218,7 @@ function MoveControls2D({
|
||||
}
|
||||
});
|
||||
}, 0)
|
||||
}, [movedObjects, initialStates, setAislePosition, setWallPosition, setFloorPosition, setZonePosition]);
|
||||
};
|
||||
|
||||
const placeMovedAssets = () => {
|
||||
if (movedObjects.length === 0) return;
|
||||
|
||||
@@ -42,8 +42,8 @@ const DuplicationControls3D = ({
|
||||
right: false,
|
||||
});
|
||||
|
||||
const calculateDragOffset = useCallback((point: THREE.Vector3, hitPoint: THREE.Vector3) => {
|
||||
const pointPosition = new THREE.Vector3().copy(point);
|
||||
const calculateDragOffset = useCallback((point: THREE.Object3D, hitPoint: THREE.Vector3) => {
|
||||
const pointPosition = new THREE.Vector3().copy(point.position);
|
||||
return new THREE.Vector3().subVectors(pointPosition, hitPoint);
|
||||
}, []);
|
||||
|
||||
@@ -120,11 +120,9 @@ const DuplicationControls3D = ({
|
||||
|
||||
if (hit) {
|
||||
if (mouseButtonsDown.current.left || mouseButtonsDown.current.right) {
|
||||
const assetUuid = duplicatedObjects[0].userData.modelUuid;
|
||||
const asset = getAssetById(assetUuid);
|
||||
if (!asset) return;
|
||||
if (duplicatedObjects[0]) {
|
||||
const newOffset = calculateDragOffset(new THREE.Vector3(...asset.position), intersectionPoint);
|
||||
const model = scene.getObjectByProperty("uuid", duplicatedObjects[0].userData.modelUuid);
|
||||
if (model) {
|
||||
const newOffset = calculateDragOffset(model, intersectionPoint);
|
||||
setDragOffset(newOffset);
|
||||
}
|
||||
return;
|
||||
@@ -177,7 +175,7 @@ const DuplicationControls3D = ({
|
||||
const hit = raycaster.ray.intersectPlane(plane, intersectionPoint);
|
||||
|
||||
if (hit) {
|
||||
const offset = calculateDragOffset(selectedAssets[0].position, hit);
|
||||
const offset = calculateDragOffset(selectedAssets[0], hit);
|
||||
setDragOffset(offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
let 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