Merge remote-tracking branch 'origin/dev-simulation/human' into main-demo

This commit is contained in:
2025-07-10 11:08:30 +05:30
10 changed files with 270 additions and 149 deletions

View File

@@ -16,7 +16,7 @@ import { getUserData } from '../../../../../functions/getUserData';
import { useSceneContext } from '../../../../scene/sceneContext';
import { useVersionContext } from '../../../version/versionContext';
import { SkeletonUtils } from 'three-stdlib';
import { useAnimationPlaySpeed } from '../../../../../store/usePlayButtonStore';
import { useAnimationPlaySpeed, usePauseButtonStore } from '../../../../../store/usePlayButtonStore';
import { upsertProductOrEventApi } from '../../../../../services/simulation/products/UpsertProductOrEventApi';
import { getAssetIksApi } from '../../../../../services/simulation/ik/getAssetIKs';
@@ -29,6 +29,7 @@ function Model({ asset }: { readonly asset: Asset }) {
const { subModule } = useSubModuleStore();
const { activeModule } = useModuleStore();
const { speed } = useAnimationPlaySpeed();
const { isPaused } = usePauseButtonStore();
const { assetStore, eventStore, productStore } = useSceneContext();
const { removeAsset, setAnimations, resetAnimation, setAnimationComplete } = assetStore();
const { setTop } = useTopData();
@@ -81,7 +82,8 @@ function Model({ asset }: { readonly asset: Asset }) {
if (!ikData && asset.eventData && asset.eventData.type === 'ArmBot') {
getAssetIksApi(asset.assetId).then((data) => {
if (data.iks) {
setIkData(data.iks);
const iks: IK[] = data.iks;
setIkData(iks);
}
})
}
@@ -385,7 +387,7 @@ function Model({ asset }: { readonly asset: Asset }) {
const currentAction = actions.current[current];
const previousAction = previousAnimation ? actions.current[previousAnimation] : null;
if (isPlaying && currentAction) {
if (isPlaying && currentAction && activeModule === 'simulation' && !isPaused) {
blendFactor.current = 0;
currentAction.reset();
@@ -408,7 +410,7 @@ function Model({ asset }: { readonly asset: Asset }) {
mixerRef.current.removeEventListener('finished', handleAnimationComplete);
}
};
}, [asset.animationState?.current, asset.animationState?.isPlaying]);
}, [asset.animationState?.current, asset.animationState?.isPlaying, isPaused, activeModule]);
useEffect(() => {
const canvasElement = gl.domElement;
@@ -463,7 +465,7 @@ function Model({ asset }: { readonly asset: Asset }) {
position={asset.position}
rotation={asset.rotation}
visible={asset.isVisible}
userData={asset}
userData={{ ...asset, iks: ikData }}
onDoubleClick={(e) => {
e.stopPropagation();
if (!toggleView) {

View File

@@ -3,76 +3,97 @@ import { useFrame } from '@react-three/fiber';
import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore';
import { useSceneContext } from '../../../scene/sceneContext';
type HumanCallback = {
humanId: string;
callback: () => void;
};
export function useHumanEventManager() {
const { humanStore } = useSceneContext();
const { getHumanById } = humanStore();
const callbacksRef = useRef<HumanCallback[]>([]);
const callbacksRef = useRef<Map<string, (() => void)[]>>(new Map());
const isMonitoringRef = useRef(false);
const isCooldownRef = useRef<Map<string, boolean>>(new Map());
const { isPlaying } = usePlayButtonStore();
const { isPaused } = usePauseButtonStore();
const { isReset } = useResetButtonStore();
useEffect(() => {
if (isReset) {
callbacksRef.current = [];
callbacksRef.current.clear();
isCooldownRef.current.clear();
}
}, [isReset])
}, [isReset]);
// Add a new human to monitor
const addHumanToMonitor = (humanId: string, callback: () => void) => {
// Avoid duplicates
if (!callbacksRef.current.some((entry) => entry.humanId === humanId)) {
callbacksRef.current.push({ humanId, callback });
if (!callbacksRef.current.has(humanId)) {
callbacksRef.current.set(humanId, []);
}
callbacksRef.current.get(humanId)!.push(callback);
// Start monitoring if not already running
if (!isMonitoringRef.current) {
isMonitoringRef.current = true;
}
};
// Remove a human from monitoring
const removeHumanFromMonitor = (humanId: string) => {
callbacksRef.current = callbacksRef.current.filter(
(entry) => entry.humanId !== humanId
);
callbacksRef.current.delete(humanId);
isCooldownRef.current.delete(humanId);
// Stop monitoring if no more humans to track
if (callbacksRef.current.length === 0) {
if (callbacksRef.current.size === 0) {
isMonitoringRef.current = false;
}
};
// Check human states every frame
useFrame(() => {
if (!isMonitoringRef.current || callbacksRef.current.length === 0 || !isPlaying || isPaused) return;
callbacksRef.current.forEach(({ humanId, callback }) => {
if (!isMonitoringRef.current || !isPlaying || isPaused) return;
callbacksRef.current.forEach((queue, humanId) => {
if (queue.length === 0 || isCooldownRef.current.get(humanId)) return;
const human = getHumanById(humanId);
if (human?.point.action.actionType === 'worker') {
if (human && human.isActive === false && human.state === 'idle' && human.isPicking && human.currentLoad < human.point.action.loadCapacity) {
const actionType = human?.point.action.actionType;
let conditionMet = false;
if (actionType === 'worker') {
conditionMet = Boolean(
human &&
human.isActive === false &&
human.state === 'idle' &&
human.isScheduled === false &&
human.currentLoad < human.point.action.loadCapacity
);
} else if (actionType === 'assembly') {
conditionMet = Boolean(
human &&
human.isActive === false &&
human.state === 'idle' &&
human.isScheduled === false
);
}
if (conditionMet) {
const callback = queue.shift();
if (callback) {
callback();
removeHumanFromMonitor(humanId); // Remove after triggering
}
} else if (human?.point.action.actionType === 'assembly') {
if (human && human.isActive === false && human.state === 'idle') {
callback();
removeHumanFromMonitor(humanId); // Remove after triggering
if (queue.length === 0) {
removeHumanFromMonitor(humanId);
} else {
isCooldownRef.current.set(humanId, true);
setTimeout(() => {
isCooldownRef.current.set(humanId, false);
}, 1000);
}
}
}
});
});
// Cleanup on unmount
useEffect(() => {
return () => {
callbacksRef.current = [];
callbacksRef.current.clear();
isMonitoringRef.current = false;
isCooldownRef.current.clear();
};
}, []);
@@ -80,4 +101,4 @@ export function useHumanEventManager() {
addHumanToMonitor,
removeHumanFromMonitor,
};
}
}

View File

@@ -27,7 +27,7 @@ function HumanInstance({ human }: { human: HumanStatus }) {
const { getActionByUuid, getEventByModelUuid, getTriggerByUuid } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { setHumanActive, setHumanState, setHumanPicking, clearCurrentMaterials, setHumanLoad, decrementHumanLoad, removeLastMaterial, incrementIdleTime, incrementActiveTime, resetTime } = humanStore();
const { setHumanActive, setHumanState, clearCurrentMaterials, setHumanLoad, setHumanScheduled, decrementHumanLoad, removeLastMaterial, incrementIdleTime, incrementActiveTime, resetTime } = humanStore();
const [currentPhase, setCurrentPhase] = useState<string>('init');
const [path, setPath] = useState<[number, number, number][]>([]);
@@ -86,8 +86,8 @@ function HumanInstance({ human }: { human: HumanStatus }) {
function reset() {
setCurrentPhase('init');
setHumanActive(human.modelUuid, false);
setHumanPicking(human.modelUuid, false);
setHumanState(human.modelUuid, 'idle');
setHumanScheduled(human.modelUuid, false);
setHumanLoad(human.modelUuid, 0);
resetAnimation(human.modelUuid);
setPath([]);
@@ -125,7 +125,6 @@ function HumanInstance({ human }: { human: HumanStatus }) {
if (!human.isActive && human.state === 'idle' && currentPhase === 'init') {
setHumanState(human.modelUuid, 'idle');
setCurrentPhase('waiting');
setHumanPicking(human.modelUuid, false);
setHumanActive(human.modelUuid, false);
setCurrentAnimation(human.modelUuid, 'idle', true, true, true);
humanStatus(human.modelUuid, 'Human is waiting for material in assembly');
@@ -134,7 +133,6 @@ function HumanInstance({ human }: { human: HumanStatus }) {
setCurrentAnimation(human.modelUuid, 'working_standing', true, true, false);
setHumanState(human.modelUuid, 'running');
setCurrentPhase('assembling');
setHumanPicking(human.modelUuid, true);
setHumanActive(human.modelUuid, true);
processStartTimeRef.current = performance.now();
@@ -152,8 +150,8 @@ function HumanInstance({ human }: { human: HumanStatus }) {
if (human.point.action.assemblyPoint && currentPhase === 'assembling') {
setHumanState(human.modelUuid, 'idle');
setCurrentPhase('waiting');
setHumanPicking(human.modelUuid, false);
setHumanActive(human.modelUuid, false);
setHumanScheduled(human.modelUuid, false);
setCurrentAnimation(human.modelUuid, 'idle', true, true, true);
humanStatus(human.modelUuid, 'Human is waiting for material in assembly');
@@ -230,7 +228,6 @@ function HumanInstance({ human }: { human: HumanStatus }) {
setPath(toPickupPath);
setCurrentPhase('init-pickup');
setHumanState(human.modelUuid, 'running');
setHumanPicking(human.modelUuid, false);
setHumanActive(human.modelUuid, true);
setCurrentAnimation(human.modelUuid, 'walking', true, true, true);
humanStatus(human.modelUuid, 'Started from init, heading to pickup');
@@ -253,8 +250,6 @@ function HumanInstance({ human }: { human: HumanStatus }) {
setPath(toDrop);
setCurrentPhase('pickup-drop');
setHumanState(human.modelUuid, 'running');
setHumanPicking(human.modelUuid, false);
setHumanPicking(human.modelUuid, true);
setCurrentAnimation(human.modelUuid, 'walk_with_box', true, true, true);
humanStatus(human.modelUuid, 'Started from pickup point, heading to drop point');
}
@@ -278,7 +273,6 @@ function HumanInstance({ human }: { human: HumanStatus }) {
setPath(dropToPickup);
setCurrentPhase('drop-pickup');
setHumanState(human.modelUuid, 'running');
setHumanPicking(human.modelUuid, false);
setHumanActive(human.modelUuid, true);
setCurrentAnimation(human.modelUuid, 'walking', true, true, true);
humanStatus(human.modelUuid, 'Started from dropping point, heading to pickup point');
@@ -295,7 +289,6 @@ function HumanInstance({ human }: { human: HumanStatus }) {
if (currentPhase === 'init-pickup') {
setCurrentPhase('picking');
setHumanState(human.modelUuid, 'idle');
setHumanPicking(human.modelUuid, true);
setHumanActive(human.modelUuid, false);
setCurrentAnimation(human.modelUuid, 'idle', true, true, true);
humanStatus(human.modelUuid, 'Reached pickup point, waiting for material');
@@ -303,7 +296,6 @@ function HumanInstance({ human }: { human: HumanStatus }) {
} else if (currentPhase === 'pickup-drop') {
setCurrentPhase('dropping');
setHumanState(human.modelUuid, 'idle');
setHumanPicking(human.modelUuid, false);
setHumanActive(human.modelUuid, false);
setCurrentAnimation(human.modelUuid, 'drop', true, false, false);
humanStatus(human.modelUuid, 'Reached drop point');
@@ -311,8 +303,8 @@ function HumanInstance({ human }: { human: HumanStatus }) {
} else if (currentPhase === 'drop-pickup') {
setCurrentPhase('picking');
setHumanState(human.modelUuid, 'idle');
setHumanPicking(human.modelUuid, true);
setHumanActive(human.modelUuid, false);
setHumanScheduled(human.modelUuid, false);
setPath([]);
clearCurrentMaterials(human.modelUuid);
setCurrentAnimation(human.modelUuid, 'idle', true, true, true);

View File

@@ -22,7 +22,7 @@ function IKInstance({ setIkSolver, armBot }: IKInstanceProps) {
const trySetup = () => {
const targetMesh = scene?.getObjectByProperty("uuid", armBot.modelUuid);
if (!targetMesh) {
if (!targetMesh || !targetMesh.userData.iks || targetMesh.userData.iks.length < 1) {
retryId = setTimeout(trySetup, 100);
return;
}
@@ -33,34 +33,23 @@ function IKInstance({ setIkSolver, armBot }: IKInstanceProps) {
if (n.name === skinnedMeshName) OOI.Skinned_Mesh = n;
});
if (!OOI.Target_Bone || !OOI.Skinned_Mesh) return;
const iks = [
{
target: 7,
effector: 6,
links: [
{
index: 5,
enabled: true,
rotationMin: new THREE.Vector3(-Math.PI / 2, 0, 0),
rotationMax: new THREE.Vector3(Math.PI / 2, 0, 0),
},
{
index: 4,
enabled: true,
rotationMin: new THREE.Vector3(-Math.PI / 2, 0, 0),
rotationMax: new THREE.Vector3(0, 0, 0),
},
{
index: 3,
enabled: true,
rotationMin: new THREE.Vector3(0, 0, 0),
rotationMax: new THREE.Vector3(2, 0, 0),
},
{ index: 1, enabled: true, limitation: new THREE.Vector3(0, 1, 0) },
{ index: 0, enabled: false, limitation: new THREE.Vector3(0, 0, 0) },
],
},
];
const rawIks: IK[] = targetMesh.userData.iks;
const iks = rawIks.map((ik) => ({
target: ik.target,
effector: ik.effector,
links: ik.links.map((link) => ({
index: link.index,
enabled: link.enabled,
rotationMin: link.rotationMin ? new THREE.Vector3(...link.rotationMin) : undefined,
rotationMax: link.rotationMax ? new THREE.Vector3(...link.rotationMax) : undefined,
limitation: link.limitation ? new THREE.Vector3(...link.limitation) : undefined,
})),
minDistance: ik.minDistance,
maxDistance: ik.maxDistance,
maxheight: ik.maxheight,
minheight: ik.minheight,
}));
const solver = new CCDIKSolver(OOI.Skinned_Mesh, iks);
setIkSolver(solver);

View File

@@ -171,11 +171,22 @@ const ArmBotUI = () => {
}
}
const { handlePointerDown } = useDraggableGLTF(updatePointToState);
const targetMesh = scene?.getObjectByProperty("uuid", selectedArmBotData?.modelUuid || '');
const { handlePointerDown } = useDraggableGLTF(
updatePointToState,
{
minDistance: targetMesh?.userData?.iks[0]?.minDistance || 1.2,
maxDistance: targetMesh?.userData?.iks[0]?.maxDistance || 2,
maxheight: targetMesh?.userData?.iks[0]?.maxheight || 0.6,
minheight: targetMesh?.userData?.iks[0]?.minheight || 1.9,
}
);
if (!selectedArmBotData || !Array.isArray(selectedArmBotData.point?.actions)) {
return null; // avoid rendering if no data yet
return null;
}
return (
<>
{selectedArmBotData.point.actions.map((action: any) => {

View File

@@ -1,15 +1,26 @@
import { useRef, useState } from "react";
import * as THREE from "three";
import { ThreeEvent, useThree } from "@react-three/fiber";
import {
useSelectedEventData,
} from "../../../../store/simulation/useSimulationStore";
import { useSelectedEventData } from "../../../../store/simulation/useSimulationStore";
import { useProductContext } from "../../products/productContext";
import { useSceneContext } from "../../../scene/sceneContext";
type OnUpdateCallback = (object: THREE.Object3D) => void;
export default function useDraggableGLTF(onUpdate: OnUpdateCallback) {
export default function useDraggableGLTF(
onUpdate: OnUpdateCallback,
constraints: {
minDistance?: number;
maxDistance?: number;
maxheight?: number;
minheight?: number;
} = {
minDistance: 1.2,
maxDistance: 2,
minheight: 0.6,
maxheight: 1.9
}
) {
const { productStore } = useSceneContext();
const { getEventByModelUuid } = productStore();
const { selectedEventData } = useSelectedEventData();
@@ -120,8 +131,10 @@ export default function useDraggableGLTF(onUpdate: OnUpdateCallback) {
// CONSTRAIN MOVEMENT HERE:
const centerX = selectedArmBot.position[0];
const centerZ = selectedArmBot.position[2];
const minDistance = 1.2;
const maxDistance = 2;
const minDistance = constraints.minDistance ?? 1.2;
const maxDistance = constraints.maxDistance ?? 2;
const minHeight = constraints.minheight ?? 0.6;
const maxHeight = constraints.maxheight ?? 1.9;
const delta = new THREE.Vector3(targetPosition.x - centerX, 0, targetPosition.z - centerZ);
@@ -169,9 +182,8 @@ export default function useDraggableGLTF(onUpdate: OnUpdateCallback) {
targetPosition.x = centerX + finalLocal.x;
targetPosition.z = centerZ + finalLocal.z;
// Clamp Y axis if needed
targetPosition.y = Math.min(Math.max(targetPosition.y, 0.6), 1.9);
// Clamp Y axis using variables
targetPosition.y = Math.min(Math.max(targetPosition.y, minHeight), maxHeight);
// Convert to local if parent exists
if (parent) {

View File

@@ -22,7 +22,7 @@ export function useTriggerHandler() {
const { addMachineToMonitor } = useMachineEventManager();
const { addHumanToMonitor } = useHumanEventManager();
const { getVehicleById } = vehicleStore();
const { getHumanById } = humanStore();
const { getHumanById, setHumanScheduled } = humanStore();
const { getMachineById } = machineStore();
const { getStorageUnitById } = storageUnitStore();
const { getMaterialById, setCurrentLocation, setNextLocation, setPreviousLocation, setIsPaused, setIsVisible, setEndTime } = materialStore();
@@ -334,12 +334,14 @@ export function useTriggerHandler() {
setIsVisible(materialId, false);
}
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId);
} else {
// Handle current action using Event Manager
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
addVehicleToMonitor(vehicle.modelUuid,
() => {
@@ -362,12 +364,14 @@ export function useTriggerHandler() {
setIsVisible(materialId, false);
}
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId);
} else {
// Handle current action using Event Manager
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
addVehicleToMonitor(vehicle.modelUuid,
() => {
@@ -386,24 +390,29 @@ export function useTriggerHandler() {
const human = getHumanById(trigger.triggeredAsset?.triggeredModel.modelUuid);
if (human) {
if (human.isActive === false && human.state === 'idle') {
if (human && human.modelUuid === "cc62adae-7000-447b-b845-6d4910de503a") {
console.log(human);
}
const conveyor = getConveyorById(action.triggers[0]?.triggeredAsset?.triggeredModel.modelUuid);
if (conveyor) {
if (!conveyor.isPaused) {
// Handle current action from vehicle
if (action.actionType === 'worker') {
setIsVisible(materialId, false);
// Handle current action using Event Manager
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
addConveyorToMonitor(conveyor.modelUuid,
() => {
if (action.actionType === 'worker') {
setIsVisible(materialId, false);
}
handleAction(action, materialId);
}
setIsPaused(materialId, true);
handleAction(action, materialId);
} else {
)
}
} else {
setIsPaused(materialId, true);
addHumanToMonitor(human.modelUuid, () => {
const conveyor = getConveyorById(action.triggers[0]?.triggeredAsset?.triggeredModel.modelUuid || '');
if (conveyor) {
// Handle current action using Event Manager
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
addConveyorToMonitor(conveyor.modelUuid,
() => {
@@ -414,35 +423,6 @@ export function useTriggerHandler() {
}
)
}
}
} else {
setIsPaused(materialId, true);
addHumanToMonitor(human.modelUuid, () => {
const conveyor = getConveyorById(action.triggers[0]?.triggeredAsset?.triggeredModel.modelUuid || '');
if (conveyor) {
if (!conveyor.isPaused) {
// Handle current action from vehicle
if (action.actionType === 'worker') {
setIsVisible(materialId, false);
}
setIsPaused(materialId, true);
handleAction(action, materialId);
} else {
// Handle current action using Event Manager
setIsPaused(materialId, true);
addConveyorToMonitor(conveyor.modelUuid,
() => {
if (action.actionType === 'worker') {
setIsVisible(materialId, false);
}
handleAction(action, materialId);
}
)
}
}
})
}
}
@@ -457,11 +437,13 @@ export function useTriggerHandler() {
if (action.actionType === 'worker') {
setIsVisible(materialId, false);
}
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId);
} else {
// Handle current action using Event Manager
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
addMachineToMonitor(machine.modelUuid,
() => {
@@ -483,11 +465,13 @@ export function useTriggerHandler() {
if (action.actionType === 'worker') {
setIsVisible(materialId, false);
}
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId);
} else {
// Handle current action using Event Manager
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
addMachineToMonitor(machine.modelUuid,
() => {
@@ -536,12 +520,14 @@ export function useTriggerHandler() {
if (action.actionType === 'worker') {
setIsVisible(materialId, false);
}
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId);
} else {
// Handle current action using Event Manager
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
addHumanToMonitor(human.modelUuid,
() => {
if (action.actionType === 'worker') {
@@ -711,7 +697,6 @@ export function useTriggerHandler() {
setNextLocation(material.materialId, null);
if (action && human) {
if (human.isActive === false && human.state === 'idle') {
@@ -719,10 +704,13 @@ export function useTriggerHandler() {
// Handle current action from arm bot
setIsVisible(materialId, false);
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId);
} else {
setHumanScheduled(human.modelUuid, true);
addHumanToMonitor(human.modelUuid,
() => {
setIsVisible(materialId, false);
@@ -879,8 +867,10 @@ export function useTriggerHandler() {
const previousModel = getEventByModelUuid(selectedProduct.productUuid, material.previous?.modelUuid || '');
if (previousModel) {
if (previousModel.type === 'transfer' && previousModel.modelUuid === model.modelUuid) {
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId)
} else {
setHumanScheduled(human.modelUuid, true);
addConveyorToMonitor(conveyor.modelUuid,
() => {
handleAction(action, materialId)
@@ -888,6 +878,7 @@ export function useTriggerHandler() {
)
}
} else {
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId)
}
// handleAction(action, materialId)
@@ -898,12 +889,14 @@ export function useTriggerHandler() {
if (vehicle.isActive === false && vehicle.state === 'idle' && vehicle.isPicking && vehicle.currentLoad < vehicle.point.action.loadCapacity) {
// Handle current action from vehicle
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId);
} else {
// Handle current action using Event Manager
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
addVehicleToMonitor(vehicle.modelUuid,
() => {
@@ -913,6 +906,7 @@ export function useTriggerHandler() {
}
}
} else {
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId)
}
@@ -928,8 +922,11 @@ export function useTriggerHandler() {
const previousModel = getEventByModelUuid(selectedProduct.productUuid, material.previous?.modelUuid || '');
if (previousModel) {
if (previousModel.type === 'transfer' && previousModel.modelUuid === model.modelUuid) {
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId)
} else {
setHumanScheduled(human.modelUuid, true);
addConveyorToMonitor(conveyor.modelUuid,
() => {
handleAction(action, materialId)
@@ -937,6 +934,7 @@ export function useTriggerHandler() {
)
}
} else {
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId)
}
}
@@ -946,12 +944,14 @@ export function useTriggerHandler() {
if (vehicle.isActive === false && vehicle.state === 'idle' && vehicle.isPicking && vehicle.currentLoad < vehicle.point.action.loadCapacity) {
// Handle current action from vehicle
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId);
} else {
// Handle current action using Event Manager
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
addVehicleToMonitor(vehicle.modelUuid,
() => {
@@ -961,6 +961,7 @@ export function useTriggerHandler() {
}
}
} else {
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId)
}
}
@@ -1259,7 +1260,7 @@ export function useTriggerHandler() {
if (human) {
if (human.isActive === false && human.state === 'idle' && human.isPicking && human.currentLoad < human.point.action.loadCapacity) {
if (human.isActive === false && human.state === 'idle' && !human.isScheduled && human.currentLoad < human.point.action.loadCapacity) {
setIsVisible(materialId, false);
@@ -1276,6 +1277,7 @@ export function useTriggerHandler() {
});
// Handle current action from human
setHumanScheduled(human.modelUuid, true);
handleAction(action, materialId);
} else {
@@ -1460,14 +1462,60 @@ export function useTriggerHandler() {
actionUuid: material.current.actionUuid,
});
setNextLocation(material.materialId, {
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid,
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid,
})
setIsPaused(material.materialId, false);
setIsPaused(material.materialId, true);
setIsVisible(material.materialId, true);
const action = getActionByUuid(selectedProduct.productUuid, trigger.triggeredAsset.triggeredAction.actionUuid);
if (action && action.triggers.length > 0 &&
action.triggers[0]?.triggeredAsset?.triggeredModel.modelUuid &&
action.triggers[0]?.triggeredAsset?.triggeredAction?.actionUuid &&
action.triggers[0]?.triggeredAsset?.triggeredPoint?.pointUuid) {
const model = getEventByModelUuid(selectedProduct.productUuid, action.triggers[0]?.triggeredAsset?.triggeredModel.modelUuid);
if (model?.type === 'roboticArm') {
addArmBotToMonitor(model.modelUuid, () => {
setNextLocation(material.materialId, {
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
})
setIsPaused(material.materialId, false);
})
} else if (model?.type === 'vehicle') {
addVehicleToMonitor(model.modelUuid, () => {
setNextLocation(material.materialId, {
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
})
setIsPaused(material.materialId, false);
})
} else if (model?.type === 'transfer') {
setNextLocation(material.materialId, {
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
})
setIsPaused(material.materialId, false);
} else if (model?.type === 'human') {
addHumanToMonitor(model.modelUuid, () => {
setNextLocation(material.materialId, {
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
})
setIsPaused(material.materialId, false);
})
} else {
setNextLocation(material.materialId, {
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
})
setIsPaused(material.materialId, false);
}
}
}
}
@@ -1510,8 +1558,31 @@ export function useTriggerHandler() {
} else {
// Event Manager Needed
setIsPaused(materialId, true);
addVehicleToMonitor(vehicle.modelUuid,
() => {
setIsPaused(materialId, false);
setIsVisible(materialId, false);
setPreviousLocation(material.materialId, {
modelUuid: material.current.modelUuid,
pointUuid: material.current.pointUuid,
actionUuid: material.current.actionUuid,
})
setCurrentLocation(material.materialId, {
modelUuid: trigger?.triggeredAsset?.triggeredModel.modelUuid || '',
pointUuid: trigger?.triggeredAsset?.triggeredPoint?.pointUuid || '',
actionUuid: trigger.triggeredAsset?.triggeredAction?.actionUuid || '',
});
setNextLocation(material.materialId, null);
// Handle current action from vehicle
handleAction(action, materialId);
}
)
}
}
}

View File

@@ -5,6 +5,7 @@ import { generateSoloNavMesh } from "@recast-navigation/generators";
import { init as initRecastNavigation } from "@recast-navigation/core";
import { DebugDrawer, getPositionsAndIndices } from "@recast-navigation/three";
import { useSceneContext } from "../../../scene/sceneContext";
import { useToggleView } from "../../../../store/builder/store";
interface NavMeshDetailsProps {
setNavMesh: (navMesh: any) => void;
@@ -19,8 +20,10 @@ export default function NavMeshDetails({
const { aisles } = aisleStore();
const { scene } = useThree();
const { walls } = wallStore();
const { toggleView } = useToggleView();
useEffect(() => {
if (toggleView) return;
const initializeNavigation = async () => {
try {
await initRecastNavigation();
@@ -64,7 +67,7 @@ export default function NavMeshDetails({
};
initializeNavigation();
}, [scene, groupRef, aisles, walls]);
}, [scene, groupRef, aisles, walls, toggleView]);
return null;
}

View File

@@ -13,7 +13,7 @@ interface HumansStore {
clearHumans: () => void;
setHumanActive: (modelUuid: string, isActive: boolean) => void;
setHumanPicking: (modelUuid: string, isPicking: boolean) => void;
setHumanScheduled: (modelUuid: string, isPicking: boolean) => void;
setHumanLoad: (modelUuid: string, load: number) => void;
setHumanState: (
modelUuid: string,
@@ -51,7 +51,7 @@ export const createHumanStore = () => {
...event,
productUuid,
isActive: false,
isPicking: false,
isScheduled: false,
idleTime: 0,
activeTime: 0,
currentLoad: 0,
@@ -92,11 +92,11 @@ export const createHumanStore = () => {
});
},
setHumanPicking: (modelUuid, isPicking) => {
setHumanScheduled: (modelUuid, isScheduled) => {
set((state) => {
const human = state.humans.find(h => h.modelUuid === modelUuid);
if (human) {
human.isPicking = isPicking;
human.isScheduled = isScheduled;
}
});
},

View File

@@ -224,7 +224,7 @@ interface StorageUnitStatus extends StorageEventSchema {
interface HumanStatus extends HumanEventSchema {
productUuid: string;
isActive: boolean;
isPicking: boolean;
isScheduled: boolean;
idleTime: number;
activeTime: number;
currentLoad: number;
@@ -286,4 +286,24 @@ interface MaterialHistoryEntry {
removedAt: string;
}
type MaterialHistorySchema = MaterialHistoryEntry[];
type MaterialHistorySchema = MaterialHistoryEntry[];
//IK
type Link = {
index: number;
enabled: boolean;
rotationMin?: [number, number, number];
rotationMax?: [number, number, number];
limitation?: [number, number, number];
};
type IK = {
target: number;
effector: number;
links: Link[];
minDistance?: number;
maxDistance?: number;
maxheight?: number;
minheight?: number;
} ;