added undo redo for builder (not for simulation data)
This commit is contained in:
@@ -32,7 +32,8 @@ function RotateControls3D({
|
||||
const { socket } = useSocketStore();
|
||||
const { userId, organization } = getUserData();
|
||||
const { projectId } = useParams();
|
||||
const { assetStore, eventStore, productStore } = useSceneContext();
|
||||
const { assetStore, eventStore, productStore, undoRedo3DStore } = useSceneContext();
|
||||
const { push3D } = undoRedo3DStore();
|
||||
const { updateAsset } = assetStore();
|
||||
const { selectedVersionStore } = useVersionContext();
|
||||
const { selectedVersion } = selectedVersionStore();
|
||||
@@ -222,12 +223,43 @@ function RotateControls3D({
|
||||
const placeRotatedAssets = useCallback(() => {
|
||||
if (rotatedObjects.length === 0) return;
|
||||
|
||||
const undoActions: UndoRedo3DAction[] = [];
|
||||
const assetsToUpdate: AssetData[] = [];
|
||||
|
||||
rotatedObjects.forEach((obj: THREE.Object3D) => {
|
||||
if (obj && obj.userData.modelUuid) {
|
||||
const asset = assetStore.getState().getAssetById(obj.userData.modelUuid);
|
||||
if (!asset) return;
|
||||
|
||||
const rotationArray: [number, number, number] = [obj.rotation.x, obj.rotation.y, obj.rotation.z];
|
||||
|
||||
const positionArray: [number, number, number] = [obj.position.x, obj.position.y, obj.position.z];
|
||||
|
||||
if (initialRotations[obj.uuid] && initialPositions[obj.uuid]) {
|
||||
assetsToUpdate.push({
|
||||
type: "Asset",
|
||||
assetData: {
|
||||
...asset,
|
||||
position: [
|
||||
initialPositions[obj.uuid].x,
|
||||
initialPositions[obj.uuid].y,
|
||||
initialPositions[obj.uuid].z
|
||||
],
|
||||
rotation: [
|
||||
initialRotations[obj.uuid].x,
|
||||
initialRotations[obj.uuid].y,
|
||||
initialRotations[obj.uuid].z
|
||||
]
|
||||
},
|
||||
newData: {
|
||||
...asset,
|
||||
position: positionArray,
|
||||
rotation: rotationArray
|
||||
},
|
||||
timeStap: new Date().toISOString()
|
||||
});
|
||||
}
|
||||
|
||||
const newFloorItem: Types.FloorItemType = {
|
||||
modelUuid: obj.userData.modelUuid,
|
||||
modelName: obj.userData.modelName,
|
||||
@@ -305,6 +337,27 @@ function RotateControls3D({
|
||||
}
|
||||
});
|
||||
|
||||
if (assetsToUpdate.length > 0) {
|
||||
if (assetsToUpdate.length === 1) {
|
||||
undoActions.push({
|
||||
module: "builder",
|
||||
actionType: "Asset-Update",
|
||||
asset: assetsToUpdate[0]
|
||||
});
|
||||
} else {
|
||||
undoActions.push({
|
||||
module: "builder",
|
||||
actionType: "Assets-Update",
|
||||
assets: assetsToUpdate
|
||||
});
|
||||
}
|
||||
|
||||
push3D({
|
||||
type: 'Scene',
|
||||
actions: undoActions
|
||||
});
|
||||
}
|
||||
|
||||
setIsRotating(false);
|
||||
clearSelection();
|
||||
}, [rotatedObjects, eventStore, productStore, selectedProduct, updateBackend, projectId, updateAsset, organization, socket, selectedVersion, userId]);
|
||||
|
||||
Reference in New Issue
Block a user