Debugged agv and conveyor interaction.

This commit is contained in:
2025-04-11 17:52:07 +05:30
parent 8ed035b969
commit 1256f33342
14 changed files with 906 additions and 858 deletions

View File

@@ -26,6 +26,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
}) => {
const gltf = useLoader(GLTFLoader, crate) as GLTF;
const groupRef = useRef<THREE.Group>(null);
const tempStackedObjectsRef = useRef<Record<string, boolean>>({});
const {
animationStates,
@@ -43,27 +44,19 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
checkAndCountTriggers,
} = useProcessAnimation(processes, setProcesses, agvRef);
const baseMaterials = useMemo(
() => ({
Box: new THREE.MeshStandardMaterial({ color: 0x8b4513 }),
Crate: new THREE.MeshStandardMaterial({ color: 0x00ff00 }),
// Default: new THREE.MeshStandardMaterial({ color: 0x00ff00 }),
Default: new THREE.MeshStandardMaterial(),
}),
[]
);
const baseMaterials = useMemo(() => ({
Box: new THREE.MeshStandardMaterial({ color: 0x8b4513 }),
Crate: new THREE.MeshStandardMaterial({ color: 0x00ff00 }),
Default: new THREE.MeshStandardMaterial(),
}), []);
useEffect(() => {
// Update material references for all spawned objects
Object.entries(animationStates).forEach(([processId, processState]) => {
Object.keys(processState.spawnedObjects).forEach((objectId) => {
const entry = {
processId,
objectId,
};
const entry = { processId, objectId, };
const materialType =
processState.spawnedObjects[objectId]?.currentMaterialType;
const materialType = processState.spawnedObjects[objectId]?.currentMaterialType;
if (!materialType) {
return;
@@ -72,17 +65,13 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
const matRefArray = MaterialRef.current;
// Find existing material group
const existing = matRefArray.find(
(entryGroup: { material: string; objects: any[] }) =>
entryGroup.material === materialType
const existing = matRefArray.find((entryGroup: { material: string; objects: any[] }) =>
entryGroup.material === materialType
);
if (existing) {
// Check if this processId + objectId already exists
const alreadyExists = existing.objects.some(
(o: any) =>
o.processId === entry.processId && o.objectId === entry.objectId
);
const alreadyExists = existing.objects.some((o: any) => o.processId === entry.processId && o.objectId === entry.objectId);
if (!alreadyExists) {
existing.objects.push(entry);
@@ -102,8 +91,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
useFrame(() => {
// Spawn logic frame
const currentTime =
clockRef.current.getElapsedTime() - elapsedBeforePauseRef.current;
const currentTime = clockRef.current.getElapsedTime() - elapsedBeforePauseRef.current;
setAnimationStates((prev) => {
const newStates = { ...prev };
@@ -131,10 +119,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
: parseFloat(spawnAction.spawnInterval as string) || 0;
// Check if this is a zero interval spawn and we already spawned an object
if (
spawnInterval === 0 &&
processState.hasSpawnedZeroIntervalObject === true
) {
if (spawnInterval === 0 && processState.hasSpawnedZeroIntervalObject === true) {
return; // Don't spawn more objects for zero interval
}
@@ -312,28 +297,81 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
// }
// }
// if (isLastPoint) {
// if (currentPointData?.actions) {
// const hasNonInherit = hasNonInheritActions(
// currentPointData.actions
// );
// if (!hasNonInherit) {
// // Remove the object if all actions are inherit
// updatedObjects[objectId] = {
// ...obj,
// visible: false,
// state: { ...stateRef, isAnimating: false },
// };
// return;
// }
// } else {
// // No actions at last point - remove the object
// updatedObjects[objectId] = {
// ...obj,
// visible: false,
// state: { ...stateRef, isAnimating: false },
// };
// return;
// }
// }
if (isLastPoint) {
if (currentPointData?.actions) {
const hasNonInherit = hasNonInheritActions(
currentPointData.actions
);
if (!hasNonInherit) {
// Remove the object if all actions are inherit
const isAgvPicking = agvRef.current.some(
(agv: any) => agv.processId === process.id && agv.status === "picking"
);
const shouldHide = !currentPointData?.actions || !hasNonInheritActions(currentPointData.actions);
if (shouldHide) {
if (isAgvPicking) {
updatedObjects[objectId] = {
...obj,
visible: false,
state: { ...stateRef, isAnimating: false },
state: {
...stateRef,
isAnimating: false,
},
};
} else {
tempStackedObjectsRef.current[objectId] = true;
updatedObjects[objectId] = {
...obj,
visible: true,
state: {
...stateRef,
isAnimating: true,
},
};
return;
}
} else {
// No actions at last point - remove the object
return;
}
}
if (tempStackedObjectsRef.current[objectId]) {
const isAgvPicking = agvRef.current.some(
(agv: any) => agv.processId === process.id && agv.status === "picking"
);
if (isAgvPicking) {
delete tempStackedObjectsRef.current[objectId];
updatedObjects[objectId] = {
...obj,
visible: false,
state: { ...stateRef, isAnimating: false },
state: {
...stateRef,
isAnimating: false,
},
};
return;
}
}

View File

@@ -57,7 +57,7 @@
// pointActions: PointAction[][];
// pointTriggers: PointTrigger[][];
// speed: number;
// isplaying: boolean;
// isActive: boolean;
// }
// interface ProcessCreatorProps {
@@ -147,7 +147,7 @@
// pointActions: [],
// pointTriggers: [], // Added point triggers array
// speed: 1,
// isplaying: false,
// isActive: false,
// });
// // Enhanced connection checking function
@@ -283,7 +283,7 @@
// pointActions,
// pointTriggers,
// speed: processSpeed,
// isplaying: false,
// isActive: false,
// };
// },
// [scene]
@@ -410,7 +410,7 @@
// p.connections.targets.map((t: { modelUUID: string }) => t.modelUUID)
// )
// .join(","),
// isplaying: false,
// isActive: false,
// }));
// }, [convertedPaths]);
@@ -459,6 +459,7 @@ import {
ConveyorEventsSchema,
VehicleEventsSchema,
} from "../../../types/world/worldTypes";
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
// Type definitions
export interface PointAction {
@@ -495,7 +496,7 @@ export interface SimulationPath {
points: PathPoint[];
pathPosition: [number, number, number];
speed?: number;
isplaying: boolean;
isActive: boolean;
}
export interface Process {
@@ -505,7 +506,7 @@ export interface Process {
pointActions: PointAction[][];
pointTriggers: PointTrigger[][];
speed: number;
isplaying: boolean;
isActive: boolean;
}
interface ProcessCreatorProps {
@@ -538,13 +539,13 @@ function convertToSimulationPath(
actions: Array.isArray(point.actions)
? point.actions.map(normalizeAction)
: point.actions
? [normalizeAction(point.actions)]
: [],
? [normalizeAction(point.actions)]
: [],
triggers: Array.isArray(point.triggers)
? point.triggers.map(normalizeTrigger)
: point.triggers
? [normalizeTrigger(point.triggers)]
: [],
? [normalizeTrigger(point.triggers)]
: [],
connections: {
targets: point.connections.targets.map((target) => ({
modelUUID: target.modelUUID,
@@ -556,7 +557,7 @@ function convertToSimulationPath(
typeof path.speed === "string"
? parseFloat(path.speed) || 1
: path.speed || 1,
isplaying: false, // Added missing property
isActive: false, // Added missing property
};
} else {
// For vehicle paths, handle the case where triggers might not exist
@@ -570,8 +571,8 @@ function convertToSimulationPath(
actions: Array.isArray(path.points.actions)
? path.points.actions.map(normalizeAction)
: path.points.actions
? [normalizeAction(path.points.actions)]
: [],
? [normalizeAction(path.points.actions)]
: [],
triggers: [],
connections: {
targets: path.points.connections.targets.map((target) => ({
@@ -582,7 +583,7 @@ function convertToSimulationPath(
],
pathPosition: path.position,
speed: path.points.speed || 1,
isplaying: false,
isActive: false,
};
}
}
@@ -595,7 +596,7 @@ const createEmptyProcess = (): Process => ({
pointActions: [],
pointTriggers: [], // Added point triggers array
speed: 1,
isplaying: false,
isActive: false,
});
// Enhanced connection checking function
@@ -731,7 +732,7 @@ export function useProcessCreation() {
pointActions,
pointTriggers,
speed: processSpeed,
isplaying: false,
isActive: false,
};
},
[scene]
@@ -824,6 +825,7 @@ const ProcessCreator: React.FC<ProcessCreatorProps> = React.memo(
const { createProcessesFromPaths } = useProcessCreation();
const prevPathsRef = useRef<SimulationPath[]>([]);
const prevProcessesRef = useRef<Process[]>([]);
const { isPlaying } = usePlayButtonStore();
const convertedPaths = useMemo((): SimulationPath[] => {
if (!simulationStates) return [];
@@ -858,7 +860,7 @@ const ProcessCreator: React.FC<ProcessCreatorProps> = React.memo(
p.connections.targets.map((t: { modelUUID: string }) => t.modelUUID)
)
.join(","),
isplaying: false,
isActive: false,
}));
}, [convertedPaths]);

View File

@@ -39,7 +39,7 @@ export interface ProcessPath {
pathRotation: number[];
speed: number;
type: "Conveyor" | "Vehicle";
isplaying: boolean
isActive: boolean
}
export interface ProcessData {

File diff suppressed because it is too large Load Diff

View File

@@ -15,7 +15,6 @@ import Agv from "../builder/agv/agv";
function Simulation() {
const { activeModule } = useModuleStore();
const pathsGroupRef = useRef() as React.MutableRefObject<THREE.Group>;
const { simulationStates, setSimulationStates } = useSimulationStates();
const [processes, setProcesses] = useState<any[]>([]);
const agvRef = useRef([]);
const MaterialRef = useRef([]);