removed bug in wall asset dynamic position updation

This commit is contained in:
2025-08-23 17:02:21 +05:30
parent 760344b783
commit f8197a6d49
4 changed files with 192 additions and 20 deletions

View File

@@ -9,6 +9,7 @@ import { useSceneContext } from "../../../sceneContext";
import { useVersionContext } from "../../../../builder/version/versionContext";
import { useSelectedPoints } from "../../../../../store/simulation/useSimulationStore";
import useModuleStore from "../../../../../store/useModuleStore";
import { calculateAssetTransformationOnWall } from "../../../../builder/wallAsset/Instances/Instance/functions/calculateAssetTransformationOnWall";
// import { upsertAisleApi } from "../../../../../services/factoryBuilder/aisle/upsertAisleApi";
// import { upsertWallApi } from "../../../../../services/factoryBuilder/wall/upsertWallApi";
@@ -36,7 +37,8 @@ function MoveControls2D({
const { projectId } = useParams();
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
const { aisleStore, wallStore, floorStore, zoneStore, undoRedo2DStore } = useSceneContext();
const { aisleStore, wallStore, floorStore, zoneStore, undoRedo2DStore, wallAssetStore } = useSceneContext();
const { getWallAssetsByWall, updateWallAsset } = wallAssetStore();
const { push2D } = undoRedo2DStore();
const { setPosition: setAislePosition, getAislesByPointId, getAisleById } = aisleStore();
const { setPosition: setWallPosition, getWallsByPointId, getWallById } = wallStore();
@@ -45,6 +47,12 @@ function MoveControls2D({
const [dragOffset, setDragOffset] = useState<THREE.Vector3 | null>(null);
const [initialPositions, setInitialPositions] = useState<Record<string, THREE.Vector3>>({});
const [initialStates, setInitialStates] = useState<Record<string, { position: THREE.Vector3; rotation?: THREE.Euler; }>>({});
const [initial, setInitial] = useState<{
aisles?: Aisle[],
walls?: Wall[],
floors?: Floor[],
zones?: Zone[]
}>({});
const [isMoving, setIsMoving] = useState(false);
useEffect(() => {
@@ -110,7 +118,7 @@ function MoveControls2D({
canvasElement.removeEventListener("pointerup", onPointerUp);
canvasElement.removeEventListener("keydown", onKeyDown);
};
}, [camera, controls, scene, toggleView, selectedPoints, socket, pastedObjects, duplicatedObjects, movedObjects, rotatedObjects]);
}, [camera, controls, scene, toggleView, selectedPoints, socket, pastedObjects, duplicatedObjects, movedObjects, rotatedObjects, initial]);
useEffect(() => {
if (toolMode !== 'move' || !toggleView) {
@@ -169,13 +177,35 @@ function MoveControls2D({
if (selectedPoints.length === 0) return;
const states: Record<string, { position: THREE.Vector3; rotation?: THREE.Euler; }> = {};
const initials: {
aisles?: Aisle[] | undefined;
walls?: Wall[];
floors?: Floor[];
zones?: Zone[];
} = {}
selectedPoints.forEach((point: THREE.Object3D) => {
states[point.uuid] = {
position: new THREE.Vector3().copy(point.position),
rotation: point.rotation ? new THREE.Euler().copy(point.rotation) : undefined
};
if (point.userData.pointType === "Aisle") {
const aisles = getAislesByPointId(point.userData.pointUuid);
initials.aisles = [...(initials.aisles ?? []), ...aisles,].filter((aisle, index, self) => index === self.findIndex((a) => a.aisleUuid === aisle.aisleUuid));
} else if (point.userData.pointType === "Wall") {
const walls = getWallsByPointId(point.userData.pointUuid);
initials.walls = [...(initials.walls ?? []), ...walls,].filter((wall, index, self) => index === self.findIndex((w) => w.wallUuid === wall.wallUuid));
} else if (point.userData.pointType === "Floor") {
const floors = getFloorsByPointId(point.userData.pointUuid);
initials.floors = [...(initials.floors ?? []), ...floors,].filter((floor, index, self) => index === self.findIndex((f) => f.floorUuid === floor.floorUuid));
} else if (point.userData.pointType === "Zone") {
const zones = getZonesByPointId(point.userData.pointUuid);
initials.zones = [...(initials.zones ?? []), ...zones,].filter((zone, index, self) => index === self.findIndex((z) => z.zoneUuid === zone.zoneUuid));
}
});
setInitial(initials)
setInitialStates(states);
const positions: Record<string, THREE.Vector3> = {};
@@ -229,6 +259,7 @@ function MoveControls2D({
const processedWalls: UndoRedo2DDataTypeSchema[] = [];
const processedFloors: UndoRedo2DDataTypeSchema[] = [];
const processedZones: UndoRedo2DDataTypeSchema[] = [];
const wallAssetUpdates: WallAsset[] = [];
movedObjects.forEach((movedObject: THREE.Object3D) => {
if (movedObject.userData.pointUuid) {
@@ -281,6 +312,24 @@ function MoveControls2D({
if (updatedWalls?.length && projectId) {
updatedWalls.forEach(updatedWall => {
const initialWall = initial.walls?.find(w => w.wallUuid === updatedWall.wallUuid);
if (initialWall) {
const assetsOnWall = getWallAssetsByWall(updatedWall.wallUuid);
assetsOnWall.forEach((asset) => {
const { position, rotation } = calculateAssetTransformationOnWall(asset, initialWall, updatedWall);
const updatedWallAsset: WallAsset = {
...asset,
position: [position[0], asset.position[1], position[2]],
rotation,
};
wallAssetUpdates.push(updatedWallAsset);
});
}
// API
// upsertWallApi(projectId, selectedVersion?.versionId || '', updatedWall);
@@ -399,6 +448,36 @@ function MoveControls2D({
});
setTimeout(() => {
if (wallAssetUpdates.length > 0) {
wallAssetUpdates.filter((wallAssets, index, self) => index === self.findIndex((w) => w.modelUuid === wallAssets.modelUuid));
wallAssetUpdates.forEach((updatedWallAsset) => {
if (projectId && updatedWallAsset) {
updateWallAsset(updatedWallAsset.modelUuid, {
position: updatedWallAsset.position,
rotation: updatedWallAsset.rotation
});
// API
// upsertWallAssetApi(projectId, selectedVersion?.versionId || '', updatedWallAsset);
// SOCKET
const data = {
wallAssetData: updatedWallAsset,
projectId: projectId,
versionId: selectedVersion?.versionId || '',
userId: userId,
organization: organization
}
socket.emit('v1:wall-asset:add', data);
}
});
}
if (processedWalls.length > 0) {
const wallMap = new Map<string, UndoRedo2DDataTypeSchema[]>();