added rest based on socket call

This commit is contained in:
2025-09-22 13:05:48 +05:30
parent daa23241d7
commit eb4ef77599
4 changed files with 263 additions and 195 deletions

View File

@@ -39,7 +39,7 @@ const CopyPasteControls3D = () => {
rotatedObjects, rotatedObjects,
setRotatedObjects, setRotatedObjects,
} = assetStore(); } = assetStore();
const { updateAssetInScene } = useAssetResponseHandler(); const { updateAssetInScene, removeAssetFromScene } = useAssetResponseHandler();
const { selectedVersion } = versionStore(); const { selectedVersion } = versionStore();
const { userId, organization } = getUserData(); const { userId, organization } = getUserData();
@@ -502,6 +502,7 @@ const CopyPasteControls3D = () => {
projectId, projectId,
}; };
removeAssetFromScene(data.modelUuid, () => {
if (!builderSocket?.connected) { if (!builderSocket?.connected) {
// REST // REST
@@ -552,6 +553,7 @@ const CopyPasteControls3D = () => {
builderSocket.emit("v1:model-asset:copy", data); builderSocket.emit("v1:model-asset:copy", data);
} }
});
} else { } else {
const data = { const data = {
organization, organization,
@@ -568,6 +570,7 @@ const CopyPasteControls3D = () => {
userId, userId,
}; };
removeAssetFromScene(data.modelUuid, () => {
if (!builderSocket?.connected) { if (!builderSocket?.connected) {
// REST // REST
@@ -616,6 +619,7 @@ const CopyPasteControls3D = () => {
builderSocket.emit("v1:model-asset:copy", data); builderSocket.emit("v1:model-asset:copy", data);
} }
});
} }
assetsToCopy.push({ assetsToCopy.push({

View File

@@ -38,7 +38,7 @@ const DuplicationControls3D = () => {
rotatedObjects, rotatedObjects,
setRotatedObjects, setRotatedObjects,
} = assetStore(); } = assetStore();
const { updateAssetInScene } = useAssetResponseHandler(); const { updateAssetInScene, removeAssetFromScene } = useAssetResponseHandler();
const { selectedVersion } = versionStore(); const { selectedVersion } = versionStore();
const { userId, organization } = getUserData(); const { userId, organization } = getUserData();
@@ -93,9 +93,7 @@ const DuplicationControls3D = () => {
if (!isPointerMoving && duplicatedObjects.length > 0 && event.button === 2) { if (!isPointerMoving && duplicatedObjects.length > 0 && event.button === 2) {
event.preventDefault(); event.preventDefault();
clearSelection(); clearSelection();
duplicatedObjects.forEach((obj: THREE.Object3D) => { clearDuplication();
removeAsset(obj.userData.modelUuid);
});
} }
setKeyEvent(""); setKeyEvent("");
}; };
@@ -130,9 +128,7 @@ const DuplicationControls3D = () => {
if (keyCombination === "ESCAPE" && duplicatedObjects.length > 0) { if (keyCombination === "ESCAPE" && duplicatedObjects.length > 0) {
event.preventDefault(); event.preventDefault();
clearSelection(); clearSelection();
duplicatedObjects.forEach((obj: THREE.Object3D) => { clearDuplication();
removeAsset(obj.userData.modelUuid);
});
} }
}; };
@@ -233,6 +229,12 @@ const DuplicationControls3D = () => {
} }
}, [axisConstraint, camera, duplicatedObjects]); }, [axisConstraint, camera, duplicatedObjects]);
const clearDuplication = useCallback(() => {
duplicatedObjects.forEach((obj: THREE.Object3D) => {
removeAsset(obj.userData.modelUuid);
});
}, [duplicatedObjects, removeAsset]);
const duplicateSelection = useCallback(() => { const duplicateSelection = useCallback(() => {
if (selectedAssets.length > 0 && duplicatedObjects.length === 0) { if (selectedAssets.length > 0 && duplicatedObjects.length === 0) {
const positions: Record<string, THREE.Vector3> = {}; const positions: Record<string, THREE.Vector3> = {};
@@ -564,6 +566,7 @@ const DuplicationControls3D = () => {
projectId, projectId,
}; };
removeAssetFromScene(data.modelUuid, () => {
if (!builderSocket?.connected) { if (!builderSocket?.connected) {
// REST // REST
@@ -614,6 +617,7 @@ const DuplicationControls3D = () => {
builderSocket.emit("v1:model-asset:duplicate", data); builderSocket.emit("v1:model-asset:duplicate", data);
} }
});
} else { } else {
const data = { const data = {
organization, organization,
@@ -630,6 +634,7 @@ const DuplicationControls3D = () => {
userId, userId,
}; };
removeAssetFromScene(data.modelUuid, () => {
if (!builderSocket?.connected) { if (!builderSocket?.connected) {
// REST // REST
@@ -678,6 +683,7 @@ const DuplicationControls3D = () => {
builderSocket.emit("v1:model-asset:duplicate", data); builderSocket.emit("v1:model-asset:duplicate", data);
} }
});
} }
assetsToDuplicate.push({ assetsToDuplicate.push({

View File

@@ -221,6 +221,36 @@ function MoveControls3D({ boundingBoxRef }: any) {
}, 50); }, 50);
}, [movedObjects, initialStates, updateAsset]); }, [movedObjects, initialStates, updateAsset]);
const resetToInitialPosition = useCallback(
(modelUuid: string, callBack?: () => void) => {
setTimeout(() => {
const movedObject = movedObjects.find((obj: THREE.Object3D) => obj.userData.modelUuid === modelUuid);
if (!movedObject) return;
const initialState = initialStates[movedObject.uuid];
if (!initialState) return;
const positionArray: [number, number, number] = [initialState.position.x, initialState.position.y, initialState.position.z];
updateAsset(modelUuid, {
position: positionArray,
rotation: [initialState.rotation?.x || 0, initialState.rotation?.y || 0, initialState.rotation?.z || 0],
});
movedObject.position.copy(initialState.position);
if (initialState.rotation) {
movedObject.rotation.copy(initialState.rotation);
}
setAxisConstraint(null);
if (callBack) callBack();
}, 50);
},
[movedObjects, initialStates, updateAsset]
);
useEffect(() => { useEffect(() => {
if (movedObjects.length > 0) { if (movedObjects.length > 0) {
const intersectionPoint = new THREE.Vector3(); const intersectionPoint = new THREE.Vector3();
@@ -413,7 +443,7 @@ function MoveControls3D({ boundingBoxRef }: any) {
.then((data) => { .then((data) => {
if (!data.message || !data.data) { if (!data.message || !data.data) {
echo.error(`Error moving asset: ${newFloorItem.modelUuid}`); echo.error(`Error moving asset: ${newFloorItem.modelUuid}`);
resetToInitialPositions(); resetToInitialPosition(newFloorItem.modelUuid);
clearSelection(); clearSelection();
return; return;
} }
@@ -437,13 +467,13 @@ function MoveControls3D({ boundingBoxRef }: any) {
}); });
} else { } else {
echo.error(`Error moving asset: ${newFloorItem.modelUuid}`); echo.error(`Error moving asset: ${newFloorItem.modelUuid}`);
resetToInitialPositions(); resetToInitialPosition(newFloorItem.modelUuid);
clearSelection(); clearSelection();
} }
}) })
.catch(() => { .catch(() => {
echo.error(`Error moving asset: ${newFloorItem.modelUuid}`); echo.error(`Error moving asset: ${newFloorItem.modelUuid}`);
resetToInitialPositions(); resetToInitialPosition(newFloorItem.modelUuid);
clearSelection(); clearSelection();
}); });
} else { } else {

View File

@@ -202,6 +202,34 @@ function RotateControls3D() {
}, 50); }, 50);
}, [rotatedObjects, initialRotations, initialPositions, updateAsset]); }, [rotatedObjects, initialRotations, initialPositions, updateAsset]);
const resetToInitialRotation = useCallback(
(modelUuid: string) => {
setTimeout(() => {
const obj = rotatedObjects.find((o: THREE.Object3D) => o.userData.modelUuid === modelUuid);
if (!obj) return;
const uuid = obj.uuid;
const initialRotation = initialRotations[uuid];
const initialPosition = initialPositions[uuid];
if (initialRotation && initialPosition) {
const rotationArray: [number, number, number] = [initialRotation.x, initialRotation.y, initialRotation.z];
const positionArray: [number, number, number] = [initialPosition.x, initialPosition.y, initialPosition.z];
updateAsset(modelUuid, {
rotation: rotationArray,
position: positionArray,
});
obj.rotation.copy(initialRotation);
obj.position.copy(initialPosition);
}
}, 50);
},
[rotatedObjects, initialRotations, initialPositions, updateAsset]
);
useFrame(() => { useFrame(() => {
if (!isRotating || rotatedObjects.length === 0) return; if (!isRotating || rotatedObjects.length === 0) return;