updated vehicle

This commit is contained in:
2025-08-29 10:27:44 +05:30
parent 6182862296
commit c9536a13e0
2 changed files with 16 additions and 9 deletions

View File

@@ -156,7 +156,6 @@ export default function VehicleInstance2({
const allPoints = useMemo(() => { const allPoints = useMemo(() => {
const points: PointData[] = []; const points: PointData[] = [];
const seen = new Set<string>(); const seen = new Set<string>();
paths?.forEach((path: PathDataInterface) => { paths?.forEach((path: PathDataInterface) => {
path.pathPoints.forEach((p) => { path.pathPoints.forEach((p) => {
if (!seen.has(p.pointId)) { if (!seen.has(p.pointId)) {
@@ -197,9 +196,9 @@ export default function VehicleInstance2({
if (prev.length === 1) { if (prev.length === 1) {
const prevPoint = allPoints[prev[0]]; const prevPoint = allPoints[prev[0]];
console.log("prevPoint: ", prevPoint);
const newPoint = allPoints[pointIndex]; const newPoint = allPoints[pointIndex];
console.log("newPoint: ", newPoint); //
//
if (prevPoint.pointId === newPoint.pointId) return prev; if (prevPoint.pointId === newPoint.pointId) return prev;
@@ -215,18 +214,24 @@ export default function VehicleInstance2({
setTimeout(() => { setTimeout(() => {
const modelUuid = selectedEventSphere?.userData?.modelUuid; const modelUuid = selectedEventSphere?.userData?.modelUuid;
const index = vehiclesData.findIndex( const index = vehiclesDataRef.current.findIndex(
(v) => v.vehicleId === modelUuid (v) => v.vehicleId === modelUuid
); );
console.log(
"vehiclesDataRef.current: ",
vehiclesDataRef.current,
modelUuid
);
if (index !== -1) { if (index !== -1) {
const updatedVehicles = [...vehiclesData]; const updatedVehicles = [...vehiclesDataRef.current];
updatedVehicles[index] = { updatedVehicles[index] = {
...updatedVehicles[index], ...vehiclesDataRef.current[index],
startPoint: prevPoint.position, startPoint: prevPoint.position,
endPoint: newPoint.position, endPoint: newPoint.position,
route: edges, route: edges,
}; };
setVehiclesData(updatedVehicles); setVehiclesData(updatedVehicles);
} }
}, 0); }, 0);
@@ -247,7 +252,7 @@ export default function VehicleInstance2({
return () => { return () => {
canvasElement.removeEventListener("contextmenu", handleContextMenu); canvasElement.removeEventListener("contextmenu", handleContextMenu);
}; };
}, [raycaster]); }, [raycaster, setVehiclesData, vehiclesData]);
return null; return null;
} }

View File

@@ -20,10 +20,12 @@ function VehicleInstances() {
endPoint: null, endPoint: null,
selectedPointId: val.point.uuid, selectedPointId: val.point.uuid,
})); }));
console.log("updatedVehicles: ", updatedVehicles);
setVehiclesData(updatedVehicles); setVehiclesData(updatedVehicles);
}, [vehicles]); }, [vehicles]);
useEffect(() => {
console.log("vehiclesData", vehiclesData);
}, [vehiclesData]);
return ( return (
<> <>