Debugged agv and conveyor interaction.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user