This commit is contained in:
2025-07-17 14:31:57 +05:30
parent 2fd1cf352c
commit 9d3365ae86
3 changed files with 34 additions and 72 deletions

View File

@@ -88,14 +88,14 @@ export function useHumanEventManager() {
human.currentLoad < currentAction.loadCapacity human.currentLoad < currentAction.loadCapacity
); );
// if (human.totalLoadCount >= currentAction.loadCount) { if (human.totalLoadCount >= currentAction.loadCount && actionUuid === human.currentAction?.actionUuid) {
// queue.shift(); queue.shift();
// actionQueue.shift(); actionQueue.shift();
// if (queue.length === 0) { if (queue.length === 0) {
// removeHumanFromMonitor(humanId); removeHumanFromMonitor(humanId);
// } }
// return; return;
// } }
if (conditionMet && actionUuid !== human.currentAction?.actionUuid) { if (conditionMet && actionUuid !== human.currentAction?.actionUuid) {
setCurrentPhase(human.modelUuid, 'init'); setCurrentPhase(human.modelUuid, 'init');
@@ -152,7 +152,7 @@ export function useHumanEventManager() {
} }
} }
}); });
},10); }, 0);
useEffect(() => { useEffect(() => {
return () => { return () => {

View File

@@ -56,27 +56,28 @@ function HumanInstance({ human }: { human: HumanStatus }) {
isSpeedRef.current = speed; isSpeedRef.current = speed;
}, [speed]); }, [speed]);
const computePath = useCallback( const computePath = useCallback((start: [number, number, number], end: [number, number, number]) => {
(start: any, end: any) => { try {
try { const navMeshQuery = new NavMeshQuery(navMesh);
const navMeshQuery = new NavMeshQuery(navMesh); let startPoint = new THREE.Vector3(start[0], start[1], start[2]);
const { path: segmentPath } = navMeshQuery.computePath(start, end); let endPoint = new THREE.Vector3(end[0], end[1], end[2]);
if ( const { path: segmentPath } = navMeshQuery.computePath(startPoint, endPoint);
segmentPath.length > 0 && if (
Math.round(segmentPath[segmentPath.length - 1].x) == Math.round(end.x) && segmentPath.length > 0 &&
Math.round(segmentPath[segmentPath.length - 1].z) == Math.round(end.z) Math.round(segmentPath[segmentPath.length - 1].x) == Math.round(endPoint.x) &&
) { Math.round(segmentPath[segmentPath.length - 1].z) == Math.round(endPoint.z)
return segmentPath?.map(({ x, y, z }) => [x, 0, z] as [number, number, number]) || []; ) {
} else { return segmentPath?.map(({ x, y, z }) => [x, 0, z] as [number, number, number]) || [];
console.log("There is no path here...Choose valid path") } else {
const { path: segmentPaths } = navMeshQuery.computePath(start, start); console.log("There is no path here...Choose valid path")
return segmentPaths.map(({ x, y, z }) => [x, 0, z] as [number, number, number]) || []; const { path: segmentPaths } = navMeshQuery.computePath(startPoint, startPoint);
} return segmentPaths.map(({ x, y, z }) => [x, 0, z] as [number, number, number]) || [];
} catch {
console.error("Failed to compute path");
return [];
} }
}, [navMesh]); } catch {
console.error("Failed to compute path");
return [];
}
}, [navMesh]);
function humanStatus(modelId: string, status: string) { function humanStatus(modelId: string, status: string) {
// console.log(`${modelId} , ${status}`); // console.log(`${modelId} , ${status}`);
@@ -128,14 +129,7 @@ function HumanInstance({ human }: { human: HumanStatus }) {
const humanMesh = scene.getObjectByProperty('uuid', human.modelUuid); const humanMesh = scene.getObjectByProperty('uuid', human.modelUuid);
if (!humanMesh) return; if (!humanMesh) return;
const toPickupPath = computePath( const toPickupPath = computePath(humanMesh.position.toArray(), (action as HumanAction)?.assemblyPoint?.position || [0, 0, 0]);
new THREE.Vector3(...humanMesh.position.toArray()),
new THREE.Vector3(
(action as HumanAction)?.assemblyPoint?.position?.[0] ?? 0,
(action as HumanAction)?.assemblyPoint?.position?.[1] ?? 0,
(action as HumanAction)?.assemblyPoint?.position?.[2] ?? 0
)
);
setPath(toPickupPath); setPath(toPickupPath);
setHumanState(human.modelUuid, 'idle'); setHumanState(human.modelUuid, 'idle');
setCurrentPhase(human.modelUuid, 'init-assembly'); setCurrentPhase(human.modelUuid, 'init-assembly');
@@ -239,14 +233,7 @@ function HumanInstance({ human }: { human: HumanStatus }) {
const humanMesh = scene.getObjectByProperty('uuid', human.modelUuid); const humanMesh = scene.getObjectByProperty('uuid', human.modelUuid);
if (!humanMesh) return; if (!humanMesh) return;
const toPickupPath = computePath( const toPickupPath = computePath(humanMesh.position.toArray(), action?.pickUpPoint?.position || [0, 0, 0]);
new THREE.Vector3(...humanMesh.position.toArray()),
new THREE.Vector3(
action?.pickUpPoint?.position?.[0] ?? 0,
action?.pickUpPoint?.position?.[1] ?? 0,
action?.pickUpPoint?.position?.[2] ?? 0
)
);
setPath(toPickupPath); setPath(toPickupPath);
setCurrentPhase(human.modelUuid, 'init-pickup'); setCurrentPhase(human.modelUuid, 'init-pickup');
setHumanState(human.modelUuid, 'running'); setHumanState(human.modelUuid, 'running');
@@ -257,18 +244,7 @@ function HumanInstance({ human }: { human: HumanStatus }) {
} else if (!human.isActive && human.state === 'idle' && human.currentPhase === 'picking') { } else if (!human.isActive && human.state === 'idle' && human.currentPhase === 'picking') {
if (humanAsset && human.currentLoad === action.loadCapacity && human.currentMaterials.length > 0 && humanAsset.animationState?.current === 'pickup' && humanAsset.animationState?.isCompleted) { if (humanAsset && human.currentLoad === action.loadCapacity && human.currentMaterials.length > 0 && humanAsset.animationState?.current === 'pickup' && humanAsset.animationState?.isCompleted) {
if (action.pickUpPoint && action.dropPoint) { if (action.pickUpPoint && action.dropPoint) {
const toDrop = computePath( const toDrop = computePath(action.pickUpPoint.position || [0, 0, 0], action.dropPoint.position || [0, 0, 0]);
new THREE.Vector3(
action.pickUpPoint.position?.[0] ?? 0,
action.pickUpPoint.position?.[1] ?? 0,
action.pickUpPoint.position?.[2] ?? 0
),
new THREE.Vector3(
action.dropPoint.position?.[0] ?? 0,
action.dropPoint.position?.[1] ?? 0,
action.dropPoint.position?.[2] ?? 0
)
);
setPath(toDrop); setPath(toDrop);
setCurrentPhase(human.modelUuid, 'pickup-drop'); setCurrentPhase(human.modelUuid, 'pickup-drop');
setHumanState(human.modelUuid, 'running'); setHumanState(human.modelUuid, 'running');
@@ -283,18 +259,7 @@ function HumanInstance({ human }: { human: HumanStatus }) {
} }
} else if (!human.isActive && human.state === 'idle' && human.currentPhase === 'dropping' && human.currentLoad === 0) { } else if (!human.isActive && human.state === 'idle' && human.currentPhase === 'dropping' && human.currentLoad === 0) {
if (action.pickUpPoint && action.dropPoint) { if (action.pickUpPoint && action.dropPoint) {
const dropToPickup = computePath( const dropToPickup = computePath(action.dropPoint.position || [0, 0, 0], action.pickUpPoint.position || [0, 0, 0]);
new THREE.Vector3(
action.dropPoint.position?.[0] ?? 0,
action.dropPoint.position?.[1] ?? 0,
action.dropPoint.position?.[2] ?? 0
),
new THREE.Vector3(
action.pickUpPoint.position?.[0] ?? 0,
action.pickUpPoint.position?.[1] ?? 0,
action.pickUpPoint.position?.[2] ?? 0
)
);
setPath(dropToPickup); setPath(dropToPickup);
setCurrentPhase(human.modelUuid, 'drop-pickup'); setCurrentPhase(human.modelUuid, 'drop-pickup');
setHumanState(human.modelUuid, 'running'); setHumanState(human.modelUuid, 'running');
@@ -333,7 +298,6 @@ function HumanInstance({ human }: { human: HumanStatus }) {
humanStatus(human.modelUuid, 'Reached drop point'); humanStatus(human.modelUuid, 'Reached drop point');
setPath([]); setPath([]);
} else if (human.currentPhase === 'drop-pickup') { } else if (human.currentPhase === 'drop-pickup') {
console.log('human: ', human);
setCurrentPhase(human.modelUuid, 'picking'); setCurrentPhase(human.modelUuid, 'picking');
setHumanState(human.modelUuid, 'idle'); setHumanState(human.modelUuid, 'idle');
setHumanActive(human.modelUuid, false); setHumanActive(human.modelUuid, false);

View File

@@ -273,7 +273,6 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
loopMaterialDropToHuman( loopMaterialDropToHuman(
agvDetail, agvDetail,
model.modelUuid, model.modelUuid,
agvDetail.point.action,
action.actionUuid action.actionUuid
); );
}, action.actionUuid || '') }, action.actionUuid || '')
@@ -284,7 +283,6 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
function loopMaterialDropToHuman( function loopMaterialDropToHuman(
vehicle: VehicleStatus, vehicle: VehicleStatus,
humanId: string, humanId: string,
vehicleAction: VehicleAction,
humanActionId: string humanActionId: string
) { ) {
let currentVehicleLoad = vehicle.currentLoad; let currentVehicleLoad = vehicle.currentLoad;