Refactor floor management APIs: implement getFloorsApi, deleteFloorApi, and upsertFloorApi for enhanced floor data handling. Update FloorCreator for improved point snapping and floor creation logic. Modify ReferencePoint to include UUID and user data. Adjust usePointSnapping to handle temporary points more effectively.

This commit is contained in:
2025-06-26 18:23:01 +05:30
parent 1e88006780
commit 5003dc3504
9 changed files with 157 additions and 33 deletions

View File

@@ -18,7 +18,7 @@ function FloorCreator() {
const { addFloor, removeDecal, getFloorPointById, getFloorByPoints } = floorStore();
const drag = useRef(false);
const isLeftMouseDown = useRef(false);
const [tempPoints, setTempPoints] = useState<Point[]>([]);
const [isCreating, setIsCreating] = useState(false);
const { floorDepth, isBeveled, bevelStrength, sideMaterial, topMaterial, snappedPosition, snappedPoint } = useBuilderStore();
@@ -80,30 +80,34 @@ function FloorCreator() {
newPoint.position = snappedPosition;
}
if (pointIntersects && !snappedPoint) {
if (tempPoints.length > 2 && isCreating && pointIntersects.object.userData.pointUuid === tempPoints[0].pointUuid) {
if (tempPoints.length >= 3) {
const floor: Floor = {
floorUuid: THREE.MathUtils.generateUUID(),
points: tempPoints,
topMaterial,
sideMaterial,
floorDepth,
isBeveled,
bevelStrength,
decals: [],
};
if (pointIntersects) {
if (tempPoints.length > 2 && isCreating && pointIntersects.object.uuid === tempPoints[0].pointUuid) {
const floor: Floor = {
floorUuid: THREE.MathUtils.generateUUID(),
points: tempPoints,
topMaterial,
sideMaterial,
floorDepth,
isBeveled,
bevelStrength,
decals: [],
};
addFloor(floor);
}
addFloor(floor);
setTempPoints([]);
setIsCreating(false);
} else if (tempPoints.length === 0) {
tempPoints.push(pointIntersects.object.userData as Point);
setIsCreating(true);
} else {
setTempPoints([]);
setIsCreating(false);
}
} else {
setTempPoints(prev => [...prev, newPoint]);
setIsCreating(true);
}
setTempPoints(prev => [...prev, newPoint]);
setIsCreating(true);
};
const onContext = (event: any) => {
@@ -157,7 +161,7 @@ function FloorCreator() {
<>
{toggleView &&
<>
<group name='Wall-Reference-Points-Group'>
<group name='Floor-Reference-Points-Group'>
{tempPoints.map((point) => (
<ReferencePoint key={point.pointUuid} point={point} />
))}

View File

@@ -201,10 +201,13 @@ export const usePointSnapping = (currentPoint: { uuid: string, pointType: string
);
}, [floors, currentPoint]);
const snapFloorPoint = useCallback((position: [number, number, number], tempPoints: Point[] | []) => {
const snapFloorPoint = useCallback((position: [number, number, number], tempPoints?: Point[] | []) => {
if (!currentPoint || !CAN_POINT_SNAP) return { position: position, isSnapped: false, snappedPoint: null };
const otherPoints = [...getAllOtherFloorPoints(), ...tempPoints];
const otherPoints = getAllOtherFloorPoints();
if (tempPoints) {
otherPoints.concat(tempPoints);
}
const currentVec = new THREE.Vector3(...position);
for (const point of otherPoints) {

View File

@@ -12,8 +12,8 @@ import { useSceneContext } from '../../scene/sceneContext';
import { upsertAisleApi } from '../../../services/factoryBuilder/aisle/upsertAisleApi';
import { deleteAisleApi } from '../../../services/factoryBuilder/aisle/deleteAisleApi';
import { upsertWallApi } from '../../../services/factoryBuilder/wall/upsertWallApi';
import { deleteWallApi } from '../../../services/factoryBuilder/wall/deleteWallApi';
// import { upsertWallApi } from '../../../services/factoryBuilder/wall/upsertWallApi';
// import { deleteWallApi } from '../../../services/factoryBuilder/wall/deleteWallApi';
import { getUserData } from '../../../functions/getUserData';
function Point({ point }: { readonly point: Point }) {
@@ -28,7 +28,7 @@ function Point({ point }: { readonly point: Point }) {
const { setPosition: setAislePosition, removePoint: removeAislePoint, getAislesByPointId } = aisleStore();
const { setPosition: setWallPosition, removePoint: removeWallPoint, getWallsByPointId } = wallStore();
const { setPosition: setFloorPosition, removePoint: removeFloorPoint } = floorStore();
const { snapAislePoint, snapAisleAngle, snapWallPoint, snapWallAngle } = usePointSnapping({ uuid: point.pointUuid, pointType: point.pointType, position: point.position });
const { snapAislePoint, snapAisleAngle, snapWallPoint, snapWallAngle, snapFloorPoint, snapFloorAngle } = usePointSnapping({ uuid: point.pointUuid, pointType: point.pointType, position: point.position });
const { hoveredPoint, setHoveredPoint } = useBuilderStore();
const { userId, organization } = getUserData();
const { selectedVersionStore } = useVersionContext();
@@ -121,8 +121,8 @@ function Point({ point }: { readonly point: Point }) {
const finalSnapped = snapWallPoint(wallSnapped.position);
setWallPosition(point.pointUuid, finalSnapped.position);
} else if (point.pointType === 'Floor') {
const floorSnapped = snapWallAngle(newPosition);
const finalSnapped = snapWallPoint(floorSnapped.position);
const floorSnapped = snapFloorAngle(newPosition);
const finalSnapped = snapFloorPoint(floorSnapped.position);
setFloorPosition(point.pointUuid, finalSnapped.position);
}
}

View File

@@ -30,6 +30,8 @@ function ReferencePoint({ point }: { readonly point: Point }) {
<mesh
position={new THREE.Vector3(...point.position)}
name={pointName}
uuid={point.pointUuid}
userData={point}
>
<boxGeometry args={boxScale} />
<shaderMaterial