feat: Add human action handling with animation and animated travel capabilities
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
import { useCallback } from "react";
|
||||||
|
import { useSceneContext } from "../../../../scene/sceneContext";
|
||||||
|
import { useProductContext } from "../../../products/productContext";
|
||||||
|
|
||||||
|
export function useAnimatedTravelHandler() {
|
||||||
|
const { materialStore, humanStore, productStore } = useSceneContext();
|
||||||
|
const { getMaterialById } = materialStore();
|
||||||
|
const { } = humanStore();
|
||||||
|
const { getModelUuidByActionUuid } = productStore();
|
||||||
|
const { selectedProductStore } = useProductContext();
|
||||||
|
const { selectedProduct } = selectedProductStore();
|
||||||
|
|
||||||
|
const animatedTravelLogStatus = (materialUuid: string, status: string) => {
|
||||||
|
echo.info(`${materialUuid}, ${status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleAnimatedTravel = useCallback((action: HumanAction, materialId?: string) => {
|
||||||
|
if (!action || action.actionType !== 'animatedTravel' || !materialId) return;
|
||||||
|
|
||||||
|
const material = getMaterialById(materialId);
|
||||||
|
if (!material) return;
|
||||||
|
|
||||||
|
const modelUuid = getModelUuidByActionUuid(selectedProduct.productUuid, action.actionUuid);
|
||||||
|
if (!modelUuid) return;
|
||||||
|
|
||||||
|
|
||||||
|
animatedTravelLogStatus(material.materialName, `performing animatedTravel`);
|
||||||
|
|
||||||
|
}, [getMaterialById]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
handleAnimatedTravel,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { useCallback } from "react";
|
||||||
|
import { useSceneContext } from "../../../../scene/sceneContext";
|
||||||
|
import { useProductContext } from "../../../products/productContext";
|
||||||
|
|
||||||
|
export function useAnimationHandler() {
|
||||||
|
const { materialStore, humanStore, productStore } = useSceneContext();
|
||||||
|
const { getMaterialById } = materialStore();
|
||||||
|
const { } = humanStore();
|
||||||
|
const { getModelUuidByActionUuid } = productStore();
|
||||||
|
const { selectedProductStore } = useProductContext();
|
||||||
|
const { selectedProduct } = selectedProductStore();
|
||||||
|
|
||||||
|
const animationLogStatus = (materialUuid: string, status: string) => {
|
||||||
|
echo.info(`${materialUuid}, ${status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleAnimation = useCallback((action: HumanAction, materialId?: string) => {
|
||||||
|
if (!action || action.actionType !== 'animation' || !materialId) return;
|
||||||
|
|
||||||
|
const material = getMaterialById(materialId);
|
||||||
|
if (!material) return;
|
||||||
|
|
||||||
|
const modelUuid = getModelUuidByActionUuid(selectedProduct.productUuid, action.actionUuid);
|
||||||
|
if (!modelUuid) return;
|
||||||
|
|
||||||
|
|
||||||
|
animationLogStatus(material.materialName, `performing animation`);
|
||||||
|
|
||||||
|
}, [getMaterialById]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
handleAnimation,
|
||||||
|
};
|
||||||
|
}
|
||||||
45
app/src/modules/simulation/actions/human/useHumanActions.ts
Normal file
45
app/src/modules/simulation/actions/human/useHumanActions.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { useEffect, useCallback } from 'react';
|
||||||
|
import { useAnimationHandler } from './actionHandler/useAnimationHandler';
|
||||||
|
import { useAnimatedTravelHandler } from './actionHandler/useAnimatedTravelHandler';
|
||||||
|
|
||||||
|
export function useHumanActions() {
|
||||||
|
const { handleAnimation } = useAnimationHandler();
|
||||||
|
const { handleAnimatedTravel } = useAnimatedTravelHandler();
|
||||||
|
|
||||||
|
const handleAnimationAction = useCallback((action: HumanAction, materialId: string) => {
|
||||||
|
handleAnimation(action, materialId);
|
||||||
|
}, [handleAnimation]);
|
||||||
|
|
||||||
|
const handleAnimatedTravelAction = useCallback((action: HumanAction) => {
|
||||||
|
handleAnimatedTravel(action);
|
||||||
|
}, [handleAnimatedTravel]);
|
||||||
|
|
||||||
|
const handleHumanAction = useCallback((action: HumanAction, materialId: string) => {
|
||||||
|
if (!action) return;
|
||||||
|
|
||||||
|
switch (action.actionType) {
|
||||||
|
case 'animation':
|
||||||
|
handleAnimationAction(action, materialId);
|
||||||
|
break;
|
||||||
|
case 'animatedTravel':
|
||||||
|
handleAnimatedTravelAction(action);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.warn(`Unknown Human action type: ${action.actionType}`);
|
||||||
|
}
|
||||||
|
}, [handleAnimationAction, handleAnimatedTravelAction]);
|
||||||
|
|
||||||
|
const cleanup = useCallback(() => {
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
cleanup();
|
||||||
|
};
|
||||||
|
}, [cleanup]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
handleHumanAction,
|
||||||
|
cleanup
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -27,7 +27,7 @@ export function useStorageActions() {
|
|||||||
default:
|
default:
|
||||||
console.warn(`Unknown storage action type: ${action.actionType}`);
|
console.warn(`Unknown storage action type: ${action.actionType}`);
|
||||||
}
|
}
|
||||||
}, [handleStoreAction]);
|
}, [handleStoreAction, handleRetrieveAction]);
|
||||||
|
|
||||||
const cleanup = useCallback(() => {
|
const cleanup = useCallback(() => {
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { useMachineActions } from "./machine/useMachineActions";
|
|||||||
import { useRoboticArmActions } from "./roboticArm/useRoboticArmActions";
|
import { useRoboticArmActions } from "./roboticArm/useRoboticArmActions";
|
||||||
import { useStorageActions } from "./storageUnit/useStorageUnitActions";
|
import { useStorageActions } from "./storageUnit/useStorageUnitActions";
|
||||||
import { useVehicleActions } from "./vehicle/useVehicleActions";
|
import { useVehicleActions } from "./vehicle/useVehicleActions";
|
||||||
|
import { useHumanActions } from "./human/useHumanActions";
|
||||||
import { useCallback, useEffect } from "react";
|
import { useCallback, useEffect } from "react";
|
||||||
|
|
||||||
export function useActionHandler() {
|
export function useActionHandler() {
|
||||||
@@ -17,6 +18,7 @@ export function useActionHandler() {
|
|||||||
const { handleRoboticArmAction, cleanup: cleanupRoboticArm } = useRoboticArmActions();
|
const { handleRoboticArmAction, cleanup: cleanupRoboticArm } = useRoboticArmActions();
|
||||||
const { handleMachineAction, cleanup: cleanupMachine } = useMachineActions();
|
const { handleMachineAction, cleanup: cleanupMachine } = useMachineActions();
|
||||||
const { handleStorageAction, cleanup: cleanupStorage } = useStorageActions();
|
const { handleStorageAction, cleanup: cleanupStorage } = useStorageActions();
|
||||||
|
const { handleHumanAction, cleanup: cleanupHuman } = useHumanActions();
|
||||||
|
|
||||||
const handleAction = useCallback((action: Action, materialId?: string) => {
|
const handleAction = useCallback((action: Action, materialId?: string) => {
|
||||||
if (!action) return;
|
if (!action) return;
|
||||||
@@ -37,6 +39,9 @@ export function useActionHandler() {
|
|||||||
case 'store': case 'retrieve':
|
case 'store': case 'retrieve':
|
||||||
handleStorageAction(action as StorageAction, materialId as string);
|
handleStorageAction(action as StorageAction, materialId as string);
|
||||||
break;
|
break;
|
||||||
|
case 'animation': case 'animatedTravel':
|
||||||
|
handleHumanAction(action as HumanAction, materialId as string);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn(`Unknown action type: ${(action as Action).actionType}`);
|
console.warn(`Unknown action type: ${(action as Action).actionType}`);
|
||||||
}
|
}
|
||||||
@@ -44,7 +49,7 @@ export function useActionHandler() {
|
|||||||
echo.error("Failed to handle action");
|
echo.error("Failed to handle action");
|
||||||
console.error("Error handling action:", error);
|
console.error("Error handling action:", error);
|
||||||
}
|
}
|
||||||
}, [handleConveyorAction, handleVehicleAction, handleRoboticArmAction, handleMachineAction, handleStorageAction,]);
|
}, [handleConveyorAction, handleVehicleAction, handleRoboticArmAction, handleMachineAction, handleStorageAction, handleHumanAction]);
|
||||||
|
|
||||||
const cleanup = useCallback(() => {
|
const cleanup = useCallback(() => {
|
||||||
cleanupConveyor();
|
cleanupConveyor();
|
||||||
@@ -52,7 +57,8 @@ export function useActionHandler() {
|
|||||||
cleanupRoboticArm();
|
cleanupRoboticArm();
|
||||||
cleanupMachine();
|
cleanupMachine();
|
||||||
cleanupStorage();
|
cleanupStorage();
|
||||||
}, [cleanupConveyor, cleanupVehicle, cleanupRoboticArm, cleanupMachine, cleanupStorage,]);
|
cleanupHuman();
|
||||||
|
}, [cleanupConveyor, cleanupVehicle, cleanupRoboticArm, cleanupMachine, cleanupStorage, cleanupHuman]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user