bug fix
This commit is contained in:
@@ -88,14 +88,14 @@ export function useHumanEventManager() {
|
||||
human.currentLoad < currentAction.loadCapacity
|
||||
);
|
||||
|
||||
// if (human.totalLoadCount >= currentAction.loadCount) {
|
||||
// queue.shift();
|
||||
// actionQueue.shift();
|
||||
// if (queue.length === 0) {
|
||||
// removeHumanFromMonitor(humanId);
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
if (human.totalLoadCount >= currentAction.loadCount && actionUuid === human.currentAction?.actionUuid) {
|
||||
queue.shift();
|
||||
actionQueue.shift();
|
||||
if (queue.length === 0) {
|
||||
removeHumanFromMonitor(humanId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (conditionMet && actionUuid !== human.currentAction?.actionUuid) {
|
||||
setCurrentPhase(human.modelUuid, 'init');
|
||||
@@ -152,7 +152,7 @@ export function useHumanEventManager() {
|
||||
}
|
||||
}
|
||||
});
|
||||
},10);
|
||||
}, 0);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
|
||||
@@ -56,27 +56,28 @@ function HumanInstance({ human }: { human: HumanStatus }) {
|
||||
isSpeedRef.current = speed;
|
||||
}, [speed]);
|
||||
|
||||
const computePath = useCallback(
|
||||
(start: any, end: any) => {
|
||||
try {
|
||||
const navMeshQuery = new NavMeshQuery(navMesh);
|
||||
const { path: segmentPath } = navMeshQuery.computePath(start, end);
|
||||
if (
|
||||
segmentPath.length > 0 &&
|
||||
Math.round(segmentPath[segmentPath.length - 1].x) == Math.round(end.x) &&
|
||||
Math.round(segmentPath[segmentPath.length - 1].z) == Math.round(end.z)
|
||||
) {
|
||||
return segmentPath?.map(({ x, y, z }) => [x, 0, z] as [number, number, number]) || [];
|
||||
} else {
|
||||
console.log("There is no path here...Choose valid path")
|
||||
const { path: segmentPaths } = navMeshQuery.computePath(start, start);
|
||||
return segmentPaths.map(({ x, y, z }) => [x, 0, z] as [number, number, number]) || [];
|
||||
}
|
||||
} catch {
|
||||
console.error("Failed to compute path");
|
||||
return [];
|
||||
const computePath = useCallback((start: [number, number, number], end: [number, number, number]) => {
|
||||
try {
|
||||
const navMeshQuery = new NavMeshQuery(navMesh);
|
||||
let startPoint = new THREE.Vector3(start[0], start[1], start[2]);
|
||||
let endPoint = new THREE.Vector3(end[0], end[1], end[2]);
|
||||
const { path: segmentPath } = navMeshQuery.computePath(startPoint, endPoint);
|
||||
if (
|
||||
segmentPath.length > 0 &&
|
||||
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 {
|
||||
console.log("There is no path here...Choose valid path")
|
||||
const { path: segmentPaths } = navMeshQuery.computePath(startPoint, startPoint);
|
||||
return segmentPaths.map(({ x, y, z }) => [x, 0, z] as [number, number, number]) || [];
|
||||
}
|
||||
}, [navMesh]);
|
||||
} catch {
|
||||
console.error("Failed to compute path");
|
||||
return [];
|
||||
}
|
||||
}, [navMesh]);
|
||||
|
||||
function humanStatus(modelId: string, status: string) {
|
||||
// console.log(`${modelId} , ${status}`);
|
||||
@@ -128,14 +129,7 @@ function HumanInstance({ human }: { human: HumanStatus }) {
|
||||
const humanMesh = scene.getObjectByProperty('uuid', human.modelUuid);
|
||||
if (!humanMesh) return;
|
||||
|
||||
const toPickupPath = computePath(
|
||||
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
|
||||
)
|
||||
);
|
||||
const toPickupPath = computePath(humanMesh.position.toArray(), (action as HumanAction)?.assemblyPoint?.position || [0, 0, 0]);
|
||||
setPath(toPickupPath);
|
||||
setHumanState(human.modelUuid, 'idle');
|
||||
setCurrentPhase(human.modelUuid, 'init-assembly');
|
||||
@@ -239,14 +233,7 @@ function HumanInstance({ human }: { human: HumanStatus }) {
|
||||
const humanMesh = scene.getObjectByProperty('uuid', human.modelUuid);
|
||||
if (!humanMesh) return;
|
||||
|
||||
const toPickupPath = computePath(
|
||||
new THREE.Vector3(...humanMesh.position.toArray()),
|
||||
new THREE.Vector3(
|
||||
action?.pickUpPoint?.position?.[0] ?? 0,
|
||||
action?.pickUpPoint?.position?.[1] ?? 0,
|
||||
action?.pickUpPoint?.position?.[2] ?? 0
|
||||
)
|
||||
);
|
||||
const toPickupPath = computePath(humanMesh.position.toArray(), action?.pickUpPoint?.position || [0, 0, 0]);
|
||||
setPath(toPickupPath);
|
||||
setCurrentPhase(human.modelUuid, 'init-pickup');
|
||||
setHumanState(human.modelUuid, 'running');
|
||||
@@ -257,18 +244,7 @@ function HumanInstance({ human }: { human: HumanStatus }) {
|
||||
} 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 (action.pickUpPoint && action.dropPoint) {
|
||||
const toDrop = computePath(
|
||||
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
|
||||
)
|
||||
);
|
||||
const toDrop = computePath(action.pickUpPoint.position || [0, 0, 0], action.dropPoint.position || [0, 0, 0]);
|
||||
setPath(toDrop);
|
||||
setCurrentPhase(human.modelUuid, 'pickup-drop');
|
||||
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) {
|
||||
if (action.pickUpPoint && action.dropPoint) {
|
||||
const dropToPickup = computePath(
|
||||
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
|
||||
)
|
||||
);
|
||||
const dropToPickup = computePath(action.dropPoint.position || [0, 0, 0], action.pickUpPoint.position || [0, 0, 0]);
|
||||
setPath(dropToPickup);
|
||||
setCurrentPhase(human.modelUuid, 'drop-pickup');
|
||||
setHumanState(human.modelUuid, 'running');
|
||||
@@ -333,7 +298,6 @@ function HumanInstance({ human }: { human: HumanStatus }) {
|
||||
humanStatus(human.modelUuid, 'Reached drop point');
|
||||
setPath([]);
|
||||
} else if (human.currentPhase === 'drop-pickup') {
|
||||
console.log('human: ', human);
|
||||
setCurrentPhase(human.modelUuid, 'picking');
|
||||
setHumanState(human.modelUuid, 'idle');
|
||||
setHumanActive(human.modelUuid, false);
|
||||
|
||||
@@ -273,7 +273,6 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
|
||||
loopMaterialDropToHuman(
|
||||
agvDetail,
|
||||
model.modelUuid,
|
||||
agvDetail.point.action,
|
||||
action.actionUuid
|
||||
);
|
||||
}, action.actionUuid || '')
|
||||
@@ -284,7 +283,6 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
|
||||
function loopMaterialDropToHuman(
|
||||
vehicle: VehicleStatus,
|
||||
humanId: string,
|
||||
vehicleAction: VehicleAction,
|
||||
humanActionId: string
|
||||
) {
|
||||
let currentVehicleLoad = vehicle.currentLoad;
|
||||
|
||||
Reference in New Issue
Block a user