Merge remote-tracking branch 'origin/merge/wall-collab' into main-dev

This commit is contained in:
2025-07-02 11:14:18 +05:30
16 changed files with 304 additions and 341 deletions

View File

@@ -1,5 +1,5 @@
import { useEffect, useRef } from 'react';
import { useDfxUpload, useSocketStore, useToggleView, useUpdateScene } from '../../../store/builder/store';
import { useActiveLayer, useDfxUpload, useSocketStore, useToggleView, useUpdateScene } from '../../../store/builder/store';
import { LineBasicMaterial, Line } from 'three';
import { TransformControls } from '@react-three/drei';
import { getWallPointsFromBlueprint } from './functions/getWallPointsFromBlueprint';
@@ -7,6 +7,8 @@ import * as Types from '../../../types/world/worldTypes';
import { useParams } from 'react-router-dom';
import { getUserData } from '../../../functions/getUserData';
import { useVersionContext } from '../version/versionContext';
import { useBuilderStore } from '../../../store/builder/useBuilderStore';
import { useSceneContext } from '../../scene/sceneContext';
/**
* DxfFile component handles the rendering and manipulation of DXf file data in a 3D scene.
@@ -15,48 +17,44 @@ import { useVersionContext } from '../version/versionContext';
*/
const DxfFile = () => {
// State management hooks
const { dfxuploaded, dfxWallGenerate, setObjValue, objValue } = useDfxUpload();
const { dfxuploaded, dfxWallGenerate, setObjValue, objValue, setDfxUploaded } = useDfxUpload();
const { toggleView } = useToggleView();
const { socket } = useSocketStore();
const { selectedVersionStore } = useVersionContext();
const { selectedVersion } = selectedVersionStore();
const { projectId } = useParams();
const { userId, organization } = getUserData();
const { activeLayer } = useActiveLayer();
const { wallThickness, wallHeight, insideMaterial, outsideMaterial, } = useBuilderStore();
// Refs for storing line objects
const lineRefs = useRef<Line[]>([]);
const { wallStore } = useSceneContext();
const { addWall, } = wallStore();
const { walls } = wallStore();
/**
* Effect hook that runs when DXF wall generation is triggered.
* Loads initial points and lines from the DXF data and updates the scene.
*/
useEffect(() => {
if (dfxWallGenerate) {
// Store generated lines in ref
// lines.current.push(...dfxWallGenerate);
// dfxWallGenerate.map((line: any) => {
// const lineData = arrayLineToObject(line as Types.Line);
dfxWallGenerate.map((wall: Wall) => {
const data = {
wallData: wall,
projectId: projectId,
versionId: selectedVersion?.versionId || '',
userId: userId,
organization: organization
}
addWall(wall);
socket.emit('v1:model-Wall:add', data);
// API
// //REST
// // setLine(organization, lineData.layer!, lineData.line!, lineData.type!);
// //SOCKET
// const input = {
// organization,
// layer: lineData.layer,
// line: lineData.line,
// type: lineData.type,
// socketId: socket.id,
// versionId: selectedVersion?.versionId || '',
// projectId,
// userId
// }
// socket.emit('v1:Line:create', input);
// })
// if (projectId) {
// upsertWallApi(projectId, selectedVersion?.versionId || '', wall);
// }
})
}
}, [dfxWallGenerate]);
@@ -78,10 +76,15 @@ const DxfFile = () => {
// Recalculate wall points based on new position
getWallPointsFromBlueprint({
objValue: { x: position.x, y: position.y, z: position.z },
setDfxGenerate: () => { },
setDxfWallGenerate: () => { },
wallThickness, wallHeight, outsideMaterial, insideMaterial, activeLayer, addWall, walls
});
};
useEffect(() => {
if (!toggleView) {
setDfxUploaded([])
}
}, [toggleView])
return (
<>
{/* Render DXF lines with transform controls when DXF data is available and view is toggled */}

View File

@@ -1,11 +1,21 @@
import { MathUtils, Vector3, BufferGeometry } from "three";
import { useActiveLayer } from "../../../../store/builder/store";
import { useBuilderStore } from "../../../../store/builder/useBuilderStore";
import { wait } from "@testing-library/user-event/dist/utils";
type DXFData = any; // Replace with actual DXF data type
type DXFEntity = any; // Replace with actual DXF entity type
type WallLineVertex = [Vector3, string, number, string]; // Represents a wall segment with start point, ID, weight, and type
interface Props {
parsedData?: DXFData; // Parsed DXF file data
setDfxGenerate?: (walls: WallLineVertex[][]) => void; // Callback to set generated walls
setDxfWallGenerate?: any; // Callback to set generated walls
objValue: any; // Object position values for offset calculation
wallThickness: number;
wallHeight: number;
outsideMaterial: string;
insideMaterial: string;
activeLayer: number; // Active layer for wall points
addWall: (wall: Wall) => void; // Function to add a wall to the scene
walls: Wall[]; // Array of walls to be processed
}
/**
@@ -15,20 +25,36 @@ interface Props {
*
* @param {Props} params - Configuration parameters
* @param {DXFData} params.parsedData - Parsed DXF file data
* @param {Function} params.setDfxGenerate - Callback to store generated walls
* @param {Function} params.setDxfWallGenerate - Callback to store generated walls
* @param {Object} params.objValue - Contains x,y,z offsets for position adjustment
*/
export function getWallPointsFromBlueprint({
parsedData,
setDfxGenerate,
setDxfWallGenerate,
objValue,
wallThickness,
wallHeight,
outsideMaterial,
insideMaterial,
activeLayer,
addWall,
walls,
}: Props) {
// Early return if no data is provided
if (!parsedData) return;
if (!parsedData.entities) return;
const unit = 1000; // Conversion factor from millimeters to meters
const wallVertex: WallLineVertex[][] = []; // Stores all generated wall segments
const wallVertex: any[] = []; // Array to store wall vertices
const findExistingPoint = (vec: Vector3): Point | undefined => {
for (const wall of wallVertex) {
for (const pt of wall.points) {
const pos = new Vector3(...pt.position);
if (pos.equals(vec)) return pt;
}
}
return undefined;
};
// Process each entity in the DXF file
parsedData.entities.forEach((entity: DXFEntity) => {
@@ -47,31 +73,41 @@ export function getWallPointsFromBlueprint({
-entity.vertices[1].y / unit
).add(new Vector3(objValue.x, 0, objValue.z));
// Check if points already exist to avoid duplicates
const existingStart = wallVertex
.flat()
.find((v) => v[0].equals(startVec));
const startPoint: WallLineVertex = existingStart || [
startVec,
MathUtils.generateUUID(), // Generate unique ID for new points
1, // Default weight
"WallLine", // Type identifier
];
// Create start and end points
const existingStart = findExistingPoint(startVec);
const startPoint: Point = existingStart || {
pointUuid: MathUtils.generateUUID(),
pointType: "Wall",
position: [startVec.x, startVec.y, startVec.z],
layer: activeLayer,
};
const existingEnd = wallVertex.flat().find((v) => v[0].equals(endVec));
const endPoint: WallLineVertex = existingEnd || [
endVec,
MathUtils.generateUUID(),
1,
"WallLine",
];
const existingEnd = findExistingPoint(endVec);
const endPoint: Point = existingEnd || {
pointUuid: MathUtils.generateUUID(),
pointType: "Wall",
position: [endVec.x, endVec.y, endVec.z],
layer: activeLayer,
};
// Add the line segment to our collection
wallVertex.push([startPoint, endPoint]);
// Create the wall
const wallSet: Wall = {
wallUuid: MathUtils.generateUUID(),
points: [startPoint, endPoint], // Store start and end points
outsideMaterial: insideMaterial,
insideMaterial: outsideMaterial,
wallThickness: wallThickness,
wallHeight: wallHeight,
decals: [],
};
wallVertex.push(wallSet); // Store wall segment in array
// Add the wall to the scene
// addWall(wallSet);
}
// Handle LWPOLYLINE entities (connected line segments)
else if (entity.type === "LWPOLYLINE" && entity.vertices) {
let firstPoint: WallLineVertex | undefined; // Store first point for closing the polyline
let firstPoint: Point | undefined; // Store first point for closing the polyline
// Process each vertex pair in the polyline
for (let i = 0; i < entity.vertices.length - 1; i++) {
@@ -88,37 +124,60 @@ export function getWallPointsFromBlueprint({
-entity.vertices[i + 1].y / unit
).add(new Vector3(objValue.x, 0, objValue.z));
// Check for existing points
const existingStart = wallVertex
.flat()
.find((v) => v[0].equals(startVec));
const startPoint: WallLineVertex = existingStart || [
startVec,
MathUtils.generateUUID(),
1,
"WallLine",
];
// Create start and end points
const existingStart = findExistingPoint(startVec);
const startPoint: Point = existingStart || {
pointUuid: MathUtils.generateUUID(), // Generate unique ID for new points
pointType: "Wall", // Type identifier
position: [startVec.x, startVec.y, startVec.z], // Position in 3D space
layer: activeLayer,
};
const existingEnd = wallVertex.flat().find((v) => v[0].equals(endVec));
const endPoint: WallLineVertex = existingEnd || [
endVec,
MathUtils.generateUUID(),
1,
"WallLine",
];
const existingEnd = findExistingPoint(endVec);
const endPoint: Point = existingEnd || {
pointUuid: MathUtils.generateUUID(), // Generate unique ID for new points
pointType: "Wall", // Type identifier
position: [endVec.x, endVec.y, endVec.z], // Position in 3D space
layer: activeLayer,
};
wallVertex.push([startPoint, endPoint]);
// Create the wall segment
const wallSet: Wall = {
wallUuid: MathUtils.generateUUID(),
points: [startPoint, endPoint], // Store start and end points
outsideMaterial: insideMaterial,
insideMaterial: outsideMaterial,
wallThickness: wallThickness,
wallHeight: wallHeight,
decals: [],
};
// Add the wall segment
// addWall(wallSet);
wallVertex.push(wallSet);
// Store first point and create closing segment if this is the last vertex
if (i === 0) firstPoint = startPoint;
if (i === entity.vertices.length - 2 && firstPoint) {
wallVertex.push([endPoint, firstPoint]);
const closingWallSet: Wall = {
wallUuid: MathUtils.generateUUID(),
points: [endPoint, firstPoint], // Create closing segment
outsideMaterial: insideMaterial,
insideMaterial: outsideMaterial,
wallThickness: wallThickness,
wallHeight: wallHeight,
decals: [],
};
// Add the closing wall
wallVertex.push(closingWallSet);
// addWall(closingWallSet);
}
}
}
// Handle ARC entities
else if (entity.type === "ARC") {
const { center, radius, startAngle, endAngle } = entity;
// Validate required ARC properties
if (
!center ||
@@ -154,34 +213,46 @@ export function getWallPointsFromBlueprint({
const startVec = arcPoints[i];
const endVec = arcPoints[i + 1];
// Check for existing points
const existingStart = wallVertex
.flat()
.find((v) => v[0].equals(startVec));
const startPoint: WallLineVertex = existingStart || [
startVec,
MathUtils.generateUUID(),
1,
"WallLine",
];
// Create start and end points
const existingStart = findExistingPoint(startVec);
const startPoint: Point = existingStart || {
pointUuid: MathUtils.generateUUID(),
pointType: "Wall",
position: [startVec.x, startVec.y, startVec.z],
layer: activeLayer,
};
const existingEnd = wallVertex.flat().find((v) => v[0].equals(endVec));
const endPoint: WallLineVertex = existingEnd || [
endVec,
MathUtils.generateUUID(),
1,
"WallLine",
];
const existingEnd = findExistingPoint(endVec);
const endPoint: Point = existingEnd || {
pointUuid: MathUtils.generateUUID(),
pointType: "Wall",
position: [endVec.x, endVec.y, endVec.z],
layer: activeLayer,
};
wallVertex.push([startPoint, endPoint]);
// Create the wall segment
const wallSet: Wall = {
wallUuid: MathUtils.generateUUID(),
points: [startPoint, endPoint],
outsideMaterial: insideMaterial,
insideMaterial: outsideMaterial,
wallThickness: wallThickness,
wallHeight: wallHeight,
decals: [],
};
// Add the wall segment
// addWall(wallSet);
wallVertex.push(wallSet);
}
}
// Log unsupported entity types
else {
console.error("Unsupported entity type:", entity.type);
}
});
console.log("wallVertex: ", wallVertex);
// Return the generated walls through callback if provided
setDfxGenerate && setDfxGenerate(wallVertex);
}
setDxfWallGenerate && setDxfWallGenerate(wallVertex);
}

View File

@@ -71,6 +71,7 @@ function WallCreator() {
if (wallIntersect && !pointIntersects) {
const wall = getWallByPoints(wallIntersect.object.userData.points);
console.log('wall: ', wall);
if (wall) {
const ThroughPoint = wallIntersect.object.userData.path.getPoints(Constants.lineConfig.lineIntersectionPoints);
let intersectionPoint = getClosestIntersection(ThroughPoint, wallIntersect.point);
@@ -294,7 +295,9 @@ function WallCreator() {
position: [position.x, position.y, position.z],
layer: activeLayer
};
console.log('newPoint: ', newPoint);
console.log('snappedPoint: ', snappedPoint);
if (snappedPosition && snappedPoint) {
newPoint.pointUuid = snappedPoint.pointUuid;
newPoint.position = snappedPosition;
@@ -316,6 +319,7 @@ function WallCreator() {
}
}
console.log('tempPoints: ', tempPoints);
if (tempPoints.length === 0) {
setTempPoints([newPoint]);
setIsCreating(true);
@@ -330,6 +334,7 @@ function WallCreator() {
decals: []
};
addWall(wall);
console.log('wall: ', wall);
// API

View File

@@ -12,13 +12,12 @@ interface PolygonGeneratorProps {
export default function PolygonGenerator({
groupRef,
}: PolygonGeneratorProps) {
const { aisleStore } = useSceneContext();
const { aisleStore, wallStore } = useSceneContext();
const { aisles } = aisleStore();
const { scene } = useThree();
const { walls } = wallStore();
useEffect(() => {
// let allLines = arrayLinesToObject(lines.current);
// const wallLines = allLines?.filter((line) => line?.type === "WallLine");
const result = aisles
.filter(
(aisle) =>
@@ -61,9 +60,12 @@ export default function PolygonGenerator({
});
});
// const wallPoints = wallLines
// .map((pair) => pair?.line.map((vals) => vals.position))
// .filter((wall): wall is THREE.Vector3[] => !!wall);
const wallPoints: THREE.Vector3[][] = walls
.map((wall) =>
wall.points.map((pt) => new THREE.Vector3(pt.position[0], pt.position[1], pt.position[2]))
)
.filter(points => points.length === 2);
if (!result || result.some((line) => !line)) {
@@ -81,7 +83,7 @@ export default function PolygonGenerator({
const polygons = turf.polygonize(turf.featureCollection(validLineFeatures));
// renderWallGeometry(wallPoints);
renderWallGeometry(wallPoints);
if (polygons.features.length > 0) {
polygons.features.forEach((feature) => {
@@ -116,7 +118,7 @@ export default function PolygonGenerator({
});
}
}, [ aisles, scene]);
}, [aisles, scene, walls]);
const renderWallGeometry = (walls: THREE.Vector3[][]) => {
walls.forEach((wall) => {