Refactor aisle API services: remove createAisleApi, update deleteAisleApi to include versionId, and modify wall asset APIs for consistency in endpoint naming. Enhance floor and wall store functionality with new setters and methods for managing floors and walls, including decal handling. Introduce FloorInstance and FloorInstances components for rendering floor data, and implement FloorCreator for interactive floor creation. Add reference floor visualization with snapping capabilities. Update wall API services for improved error handling and response management.

This commit is contained in:
2025-06-26 17:47:32 +05:30
parent b4745451d2
commit 1e88006780
28 changed files with 1442 additions and 122 deletions

View File

@@ -16,6 +16,14 @@ interface BuilderState {
outsideMaterial: string;
insideMaterial: string;
// Floor Settings
selectedFloor: Object3D | null;
floorDepth: number;
isBeveled: boolean;
bevelStrength: number;
sideMaterial: string;
topMaterial: string;
// Decal Settings
selectedDecal: Object3D | null;
@@ -44,6 +52,13 @@ interface BuilderState {
setWallHeight: (height: number) => void;
setWallMaterial: (material: string, side: 'inside' | 'outside') => void;
// Setters - Floor
setSelectedFloor: (floor: Object3D | null) => void;
setFloorDepth: (depth: number) => void;
setBeveled: (isBeveled: boolean) => void;
setBevelStrength: (strength: number) => void;
setFloorMaterial: (material: string, side: 'side' | 'top') => void;
// Setters - Decal
setSelectedDecal: (decal: Object3D | null) => void;
@@ -81,6 +96,13 @@ export const useBuilderStore = create<BuilderState>()(
outsideMaterial: 'Default Material',
insideMaterial: 'Material 1',
selectedFloor: null,
floorDepth: 0.3,
isBeveled: false,
bevelStrength: 0.05,
sideMaterial: 'Default Side',
topMaterial: 'Default Top',
selectedDecal: null,
selectedAisle: null,
@@ -147,6 +169,38 @@ export const useBuilderStore = create<BuilderState>()(
});
},
// === Setters: Floor ===
setSelectedFloor: (floor: Object3D | null) => {
set((state) => {
state.selectedFloor = floor;
});
},
setFloorDepth: (depth: number) => {
set((state) => {
state.floorDepth = depth;
});
},
setBeveled: (isBeveled: boolean) => {
set((state) => {
state.isBeveled = isBeveled;
});
},
setBevelStrength: (strength: number) => {
set((state) => {
state.bevelStrength = strength;
});
},
setFloorMaterial: (material: string, side: 'side' | 'top') => {
set((state) => {
if (side === 'side') state.sideMaterial = material;
else state.topMaterial = material;
});
},
// === Setters: Decal ===
setSelectedDecal: (decal: Object3D | null) => {

View File

@@ -7,14 +7,29 @@ interface FloorStore {
addFloor: (floor: Floor) => void;
updateFloor: (uuid: string, updated: Partial<Floor>) => void;
removeFloor: (uuid: string) => void;
removePointFromFloors: (pointUuid: string) => void;
removePoint: (pointUuid: string) => Floor[];
removeFloorByPoints: (Points: [Point, Point]) => Floor[];
clearFloors: () => void;
setPosition: (
pointUuid: string,
position: [number, number, number]
) => Floor | undefined;
setIsBeveled: (uuid: string, isBeveled: boolean) => void;
setBevelStrength: (uuid: string, strength: number) => void;
setDepth: (uuid: string, depth: number) => void;
setMaterial: (uuid: string, sideMaterial: string, topMaterial: string) => void;
addDecal: (floors: string, decal: Decal) => void;
updateDecal: (decalUuid: string, decal: Decal) => void;
removeDecal: (decalUuid: string) => void;
updateDecalPosition: (decalUuid: string, position: [number, number, number]) => void;
updateDecalRotation: (decalUuid: string, rotation: number) => void;
updateDecalScale: (decalUuid: string, scale: number) => void;
getFloorById: (uuid: string) => Floor | undefined;
getFloorsByPointId: (uuid: string) => Floor | undefined;
getFloorByPoints: (points: Point[]) => Floor | undefined;
getFloorPointById: (uuid: string) => Point | undefined;
getConnectedPoints: (uuid: string) => Point[];
}
export const createFloorStore = () => {
@@ -41,16 +56,98 @@ export const createFloorStore = () => {
state.floors = state.floors.filter(f => f.floorUuid !== uuid);
}),
removePointFromFloors: (pointUuid) => set(state => {
for (const floor of state.floors) {
floor.points = floor.points.filter(p => p.pointUuid !== pointUuid);
}
}),
removePoint: (pointUuid) => {
const removedFloors: Floor[] = [];
set(state => {
const updatedFloors: Floor[] = [];
for (const floor of state.floors) {
const hasPoint = floor.points.some(p => p.pointUuid === pointUuid);
if (!hasPoint) {
updatedFloors.push(floor);
continue;
}
const remainingPoints = floor.points.filter(p => p.pointUuid !== pointUuid);
if (remainingPoints.length > 2) {
floor.points = remainingPoints;
updatedFloors.push(floor);
} else {
removedFloors.push(floor);
}
}
state.floors = updatedFloors;
});
return removedFloors;
},
removeFloorByPoints: ([pointA, pointB]) => {
const removedFloors: Floor[] = [];
set(state => {
const updatedFloors: Floor[] = [];
for (const floor of state.floors) {
const indices = floor.points
.map((p, i) => ({ uuid: p.pointUuid, index: i }));
const idxA = indices.find(i => i.uuid === pointA.pointUuid)?.index ?? -1;
const idxB = indices.find(i => i.uuid === pointB.pointUuid)?.index ?? -1;
if (idxA === -1 || idxB === -1) {
updatedFloors.push(floor);
continue;
}
const areAdjacent =
Math.abs(idxA - idxB) === 1 ||
(idxA === 0 && idxB === floor.points.length - 1) ||
(idxB === 0 && idxA === floor.points.length - 1);
if (!areAdjacent) {
updatedFloors.push(floor);
continue;
}
const remainingPoints = floor.points.filter(
p => p.pointUuid !== pointA.pointUuid && p.pointUuid !== pointB.pointUuid
);
if (remainingPoints.length > 2) {
floor.points = remainingPoints;
updatedFloors.push(floor);
} else {
removedFloors.push(floor);
}
}
state.floors = updatedFloors;
});
return removedFloors;
},
clearFloors: () => set(state => {
state.floors = [];
}),
setPosition: (pointUuid, position) => {
let updatedFloor: Floor | undefined;
set((state) => {
for (const floor of state.floors) {
const point = floor.points.find((p) => p.pointUuid === pointUuid);
if (point) {
point.position = position;
updatedFloor = JSON.parse(JSON.stringify(floor));
break;
}
}
});
return updatedFloor;
},
setIsBeveled: (uuid, isBeveled) => set(state => {
const floor = state.floors.find(f => f.floorUuid === uuid);
if (floor) {
@@ -80,9 +177,97 @@ export const createFloorStore = () => {
}
}),
addDecal: (floorUuid, decal) => set(state => {
const floor = state.floors.find(f => f.floorUuid === floorUuid);
if (floor) {
floor.decals.push(decal);
}
}),
updateDecal: (decalUuid, updatedDecal) => set(state => {
for (const floor of state.floors) {
const index = floor.decals.findIndex(d => d.decalUuid === decalUuid);
if (index !== -1) {
floor.decals[index] = updatedDecal;
break;
}
}
}),
removeDecal: (decalUuid) => set(state => {
for (const floor of state.floors) {
floor.decals = floor.decals.filter(d => d.decalUuid !== decalUuid);
}
}),
updateDecalPosition: (decalUuid, position) => set(state => {
for (const floor of state.floors) {
const decal = floor.decals.find(d => d.decalUuid === decalUuid);
if (decal) {
decal.decalPosition = position;
break;
}
}
}),
updateDecalRotation: (decalUuid, rotation) => set(state => {
for (const floor of state.floors) {
const decal = floor.decals.find(d => d.decalUuid === decalUuid);
if (decal) {
decal.decalRotation = rotation;
break;
}
}
}),
updateDecalScale: (decalUuid, scale) => set(state => {
for (const floor of state.floors) {
const decal = floor.decals.find(d => d.decalUuid === decalUuid);
if (decal) {
decal.decalScale = scale;
break;
}
}
}),
getFloorById: (uuid) => {
return get().floors.find(f => f.floorUuid === uuid);
},
getFloorsByPointId: (pointUuid) => {
return get().floors.find(floor =>
floor.points.some(p => p.pointUuid === pointUuid)
);
},
getFloorByPoints: (points) => {
return get().floors.find(floor => {
const floorPointIds = new Set(floor.points.map(p => p.pointUuid));
const givenPointIds = new Set(points.map(p => p.pointUuid));
return floorPointIds.size === givenPointIds.size &&
[...floorPointIds].every(id => givenPointIds.has(id));
});
},
getFloorPointById: (pointUuid) => {
for (const floor of get().floors) {
const point = floor.points.find(p => p.pointUuid === pointUuid);
if (point) return point;
}
return undefined;
},
getConnectedPoints: (pointUuid) => {
const connected: Point[] = [];
for (const floor of get().floors) {
if (floor.points.some(p => p.pointUuid === pointUuid)) {
connected.push(...floor.points.filter(p => p.pointUuid !== pointUuid));
}
}
return connected;
}
}))
);
};

View File

@@ -5,7 +5,7 @@ interface WallStore {
walls: Wall[];
setWalls: (walls: Wall[]) => void;
addWall: (wall: Wall) => void;
updateWall: (uuid: string, updated: Partial<Wall>) => void;
updateWall: (uuid: string, updated: Partial<Wall>) => Wall | undefined;
removeWall: (uuid: string) => void;
clearWalls: () => void;
removeWallByPoints: (Points: [Point, Point]) => Wall | undefined;
@@ -17,11 +17,11 @@ interface WallStore {
updateDecalScale: (decalUuid: string, scale: number) => void;
removePoint: (pointUuid: string) => Wall[];
setPosition: (pointUuid: string, position: [number, number, number]) => void;
setPosition: (pointUuid: string, position: [number, number, number]) => Wall[] | [];
setLayer: (pointUuid: string, layer: number) => void;
getWallById: (uuid: string) => Wall | undefined;
getWallByPointId: (uuid: string) => Wall | undefined;
getWallsByPointId: (uuid: string) => Wall[] | [];
getWallByPoints: (points: Point[]) => Wall | undefined;
getWallPointById: (uuid: string) => Point | undefined;
getConnectedPoints: (uuid: string) => Point[];
@@ -40,12 +40,17 @@ export const createWallStore = () => {
state.walls.push(wall);
}),
updateWall: (uuid, updated) => set((state) => {
const wall = state.walls.find(w => w.wallUuid === uuid);
if (wall) {
Object.assign(wall, updated);
}
}),
updateWall: (uuid, updated) => {
let updatedWall: Wall | undefined;
set((state) => {
const wall = state.walls.find(w => w.wallUuid === uuid);
if (wall) {
Object.assign(wall, updated);
updatedWall = JSON.parse(JSON.stringify(wall));
}
});
return updatedWall;
},
removeWall: (uuid) => set((state) => {
state.walls = state.walls.filter(w => w.wallUuid !== uuid);
@@ -144,14 +149,19 @@ export const createWallStore = () => {
return removedWalls;
},
setPosition: (pointUuid, position) => set((state) => {
for (const wall of state.walls) {
const point = wall.points.find(p => p.pointUuid === pointUuid);
if (point) {
point.position = position;
setPosition: (pointUuid, position) => {
let updatedWalls: Wall[] = [];
set((state) => {
for (const wall of state.walls) {
const point = wall.points.find(p => p.pointUuid === pointUuid);
if (point) {
point.position = position;
updatedWalls.push(wall);
}
}
}
}),
});
return updatedWalls;
},
setLayer: (pointUuid, layer) => set((state) => {
for (const wall of state.walls) {
@@ -166,13 +176,10 @@ export const createWallStore = () => {
return get().walls.find(w => w.wallUuid === uuid);
},
getWallByPointId: (uuid) => {
for (const wall of get().walls) {
if (wall.points.some(p => p.pointUuid === uuid)) {
return wall;
}
}
return undefined;
getWallsByPointId: (uuid) => {
return get().walls.filter((a) => {
return a.points.some((p) => p.pointUuid === uuid);
})
},
getWallByPoints: (point) => {