Merge branch 'dev-simulation/human' into main-dev
This commit is contained in:
@@ -16,10 +16,9 @@ import { getUserData } from '../../../../../functions/getUserData';
|
|||||||
import { useSceneContext } from '../../../../scene/sceneContext';
|
import { useSceneContext } from '../../../../scene/sceneContext';
|
||||||
import { useVersionContext } from '../../../version/versionContext';
|
import { useVersionContext } from '../../../version/versionContext';
|
||||||
import { SkeletonUtils } from 'three-stdlib';
|
import { SkeletonUtils } from 'three-stdlib';
|
||||||
import { useAnimationPlaySpeed, usePauseButtonStore } from '../../../../../store/usePlayButtonStore';
|
|
||||||
|
|
||||||
import { upsertProductOrEventApi } from '../../../../../services/simulation/products/UpsertProductOrEventApi';
|
import { upsertProductOrEventApi } from '../../../../../services/simulation/products/UpsertProductOrEventApi';
|
||||||
import { getAssetIksApi } from '../../../../../services/simulation/ik/getAssetIKs';
|
import { getAssetIksApi } from '../../../../../services/simulation/ik/getAssetIKs';
|
||||||
|
import { ModelAnimator } from './animator/modelAnimator';
|
||||||
|
|
||||||
const distanceWorker = new Worker(new URL("../../../../../services/factoryBuilder/webWorkers/distanceWorker.js", import.meta.url));
|
const distanceWorker = new Worker(new URL("../../../../../services/factoryBuilder/webWorkers/distanceWorker.js", import.meta.url));
|
||||||
|
|
||||||
@@ -32,10 +31,8 @@ function Model({ asset }: { readonly asset: Asset }) {
|
|||||||
const { toggleView } = useToggleView();
|
const { toggleView } = useToggleView();
|
||||||
const { subModule } = useSubModuleStore();
|
const { subModule } = useSubModuleStore();
|
||||||
const { activeModule } = useModuleStore();
|
const { activeModule } = useModuleStore();
|
||||||
const { speed } = useAnimationPlaySpeed();
|
|
||||||
const { isPaused } = usePauseButtonStore();
|
|
||||||
const { assetStore, eventStore, productStore } = useSceneContext();
|
const { assetStore, eventStore, productStore } = useSceneContext();
|
||||||
const { removeAsset, setAnimations, resetAnimation, setAnimationComplete } = assetStore();
|
const { removeAsset, resetAnimation } = assetStore();
|
||||||
const { setTop } = useTopData();
|
const { setTop } = useTopData();
|
||||||
const { setLeft } = useLeftData();
|
const { setLeft } = useLeftData();
|
||||||
const { getIsEventInProduct, addPoint } = productStore();
|
const { getIsEventInProduct, addPoint } = productStore();
|
||||||
@@ -57,12 +54,7 @@ function Model({ asset }: { readonly asset: Asset }) {
|
|||||||
const [boundingBox, setBoundingBox] = useState<THREE.Box3 | null>(null);
|
const [boundingBox, setBoundingBox] = useState<THREE.Box3 | null>(null);
|
||||||
const [isSelected, setIsSelected] = useState(false);
|
const [isSelected, setIsSelected] = useState(false);
|
||||||
const groupRef = useRef<THREE.Group>(null);
|
const groupRef = useRef<THREE.Group>(null);
|
||||||
const mixerRef = useRef<THREE.AnimationMixer>();
|
|
||||||
const actions = useRef<{ [name: string]: THREE.AnimationAction }>({});
|
|
||||||
const [previousAnimation, setPreviousAnimation] = useState<string | null>(null);
|
|
||||||
const [ikData, setIkData] = useState<any>();
|
const [ikData, setIkData] = useState<any>();
|
||||||
const blendFactor = useRef(0);
|
|
||||||
const blendDuration = 0.5;
|
|
||||||
const { selectedVersionStore } = useVersionContext();
|
const { selectedVersionStore } = useVersionContext();
|
||||||
const { selectedVersion } = selectedVersionStore();
|
const { selectedVersion } = selectedVersionStore();
|
||||||
const { userId, organization } = getUserData();
|
const { userId, organization } = getUserData();
|
||||||
@@ -142,16 +134,6 @@ function Model({ asset }: { readonly asset: Asset }) {
|
|||||||
clone.animations = cachedModel.animations || [];
|
clone.animations = cachedModel.animations || [];
|
||||||
setGltfScene(clone);
|
setGltfScene(clone);
|
||||||
calculateBoundingBox(clone);
|
calculateBoundingBox(clone);
|
||||||
if (cachedModel.animations && clone.animations.length > 0) {
|
|
||||||
const animationName = clone.animations.map((clip: any) => clip.name);
|
|
||||||
setAnimations(asset.modelUuid, animationName)
|
|
||||||
mixerRef.current = new THREE.AnimationMixer(clone);
|
|
||||||
|
|
||||||
clone.animations.forEach((animation: any) => {
|
|
||||||
const action = mixerRef.current!.clipAction(animation);
|
|
||||||
actions.current[animation.name] = action;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,50 +358,6 @@ function Model({ asset }: { readonly asset: Asset }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleAnimationComplete = useCallback(() => {
|
|
||||||
if (asset.animationState) {
|
|
||||||
setAnimationComplete(asset.modelUuid, true);
|
|
||||||
}
|
|
||||||
}, [asset.animationState]);
|
|
||||||
|
|
||||||
useFrame((_, delta) => {
|
|
||||||
if (mixerRef.current) {
|
|
||||||
mixerRef.current.update(delta * (activeModule === 'simulation' ? speed : 1));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!asset.animationState || !mixerRef.current) return;
|
|
||||||
|
|
||||||
const { current, loopAnimation, isPlaying } = asset.animationState;
|
|
||||||
const currentAction = actions.current[current];
|
|
||||||
const previousAction = previousAnimation ? actions.current[previousAnimation] : null;
|
|
||||||
|
|
||||||
if (isPlaying && currentAction && activeModule === 'simulation' && !isPaused) {
|
|
||||||
blendFactor.current = 0;
|
|
||||||
|
|
||||||
currentAction.reset();
|
|
||||||
currentAction.setLoop(loopAnimation ? THREE.LoopRepeat : THREE.LoopOnce, loopAnimation ? Infinity : 1);
|
|
||||||
currentAction.clampWhenFinished = true;
|
|
||||||
|
|
||||||
if (previousAction && previousAction !== currentAction) {
|
|
||||||
previousAction.crossFadeTo(currentAction, blendDuration, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentAction.play();
|
|
||||||
mixerRef.current.addEventListener('finished', handleAnimationComplete);
|
|
||||||
setPreviousAnimation(current);
|
|
||||||
} else {
|
|
||||||
Object.values(actions.current).forEach((action) => action.stop());
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (mixerRef.current) {
|
|
||||||
mixerRef.current.removeEventListener('finished', handleAnimationComplete);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [asset.animationState?.current, asset.animationState?.isCompleted, asset.animationState?.isPlaying, isPaused, activeModule]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const canvasElement = gl.domElement;
|
const canvasElement = gl.domElement;
|
||||||
|
|
||||||
@@ -520,7 +458,13 @@ function Model({ asset }: { readonly asset: Asset }) {
|
|||||||
{gltfScene && (
|
{gltfScene && (
|
||||||
<>
|
<>
|
||||||
{isRendered ? (
|
{isRendered ? (
|
||||||
<primitive object={gltfScene} />
|
<>
|
||||||
|
|
||||||
|
<primitive object={gltfScene} />
|
||||||
|
|
||||||
|
<ModelAnimator asset={asset} gltfScene={gltfScene} />
|
||||||
|
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<AssetBoundingBox name='Asset Fallback' boundingBox={boundingBox} color='gray' lineWidth={1} />
|
<AssetBoundingBox name='Asset Fallback' boundingBox={boundingBox} color='gray' lineWidth={1} />
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -3,17 +3,15 @@ import { useFrame } from "@react-three/fiber";
|
|||||||
import { usePlayButtonStore, usePauseButtonStore, useResetButtonStore, useAnimationPlaySpeed } from "../../../../../store/usePlayButtonStore";
|
import { usePlayButtonStore, usePauseButtonStore, useResetButtonStore, useAnimationPlaySpeed } from "../../../../../store/usePlayButtonStore";
|
||||||
import { useSceneContext } from "../../../../scene/sceneContext";
|
import { useSceneContext } from "../../../../scene/sceneContext";
|
||||||
import { useProductContext } from "../../../products/productContext";
|
import { useProductContext } from "../../../products/productContext";
|
||||||
import { useHumanEventManager } from "../../../human/eventManager/useHumanEventManager";
|
|
||||||
|
|
||||||
export function useRetrieveHandler() {
|
export function useRetrieveHandler() {
|
||||||
const { materialStore, armBotStore, vehicleStore, storageUnitStore, productStore, humanStore, assetStore, humanEventManagerRef } = useSceneContext();
|
const { materialStore, armBotStore, vehicleStore, storageUnitStore, productStore, humanStore, assetStore } = useSceneContext();
|
||||||
const { selectedProductStore } = useProductContext();
|
const { selectedProductStore } = useProductContext();
|
||||||
const { addMaterial } = materialStore();
|
const { addMaterial } = materialStore();
|
||||||
const { getModelUuidByActionUuid, getPointUuidByActionUuid, getEventByModelUuid, getActionByUuid } = productStore();
|
const { getModelUuidByActionUuid, getPointUuidByActionUuid, getEventByModelUuid, getActionByUuid } = productStore();
|
||||||
const { getStorageUnitById, getLastMaterial, updateCurrentLoad, removeLastMaterial } = storageUnitStore();
|
const { getStorageUnitById, getLastMaterial, updateCurrentLoad, removeLastMaterial } = storageUnitStore();
|
||||||
const { getVehicleById, incrementVehicleLoad, addCurrentMaterial } = vehicleStore();
|
const { getVehicleById, incrementVehicleLoad, addCurrentMaterial } = vehicleStore();
|
||||||
const { getHumanById, incrementHumanLoad, addCurrentMaterial: addCurrentMaterialToHuman } = humanStore();
|
const { getHumanById, incrementHumanLoad, addCurrentMaterial: addCurrentMaterialToHuman } = humanStore();
|
||||||
const { addHumanToMonitor } = useHumanEventManager();
|
|
||||||
const { getAssetById, setCurrentAnimation } = assetStore();
|
const { getAssetById, setCurrentAnimation } = assetStore();
|
||||||
const { selectedProduct } = selectedProductStore();
|
const { selectedProduct } = selectedProductStore();
|
||||||
const { getArmBotById, addCurrentAction } = armBotStore();
|
const { getArmBotById, addCurrentAction } = armBotStore();
|
||||||
@@ -303,19 +301,10 @@ export function useRetrieveHandler() {
|
|||||||
const humanAsset = getAssetById(triggeredModel.modelUuid);
|
const humanAsset = getAssetById(triggeredModel.modelUuid);
|
||||||
const action = getActionByUuid(selectedProduct.productUuid, human?.currentAction?.actionUuid || '');
|
const action = getActionByUuid(selectedProduct.productUuid, human?.currentAction?.actionUuid || '');
|
||||||
|
|
||||||
if (!action || action.actionType !== 'worker' || !humanEventManagerRef.current) return;
|
if (!action || action.actionType !== 'worker') return;
|
||||||
|
|
||||||
let state = humanEventManagerRef.current.humanStates.find(h => h.humanId === triggeredModel.modelUuid);
|
|
||||||
console.log('state: ', state);
|
|
||||||
console.log('human: ', human);
|
|
||||||
const currentCount = retrievalCountRef.current.get(actionUuid) ?? 0;
|
const currentCount = retrievalCountRef.current.get(actionUuid) ?? 0;
|
||||||
|
|
||||||
let conditionMet = false;
|
|
||||||
if (state) {
|
|
||||||
console.log('state.actionQueue: ', state.actionQueue);
|
|
||||||
// state.actionQueue[0].count
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentCount >= action.loadCount) {
|
if (currentCount >= action.loadCount) {
|
||||||
completedActions.push(actionUuid);
|
completedActions.push(actionUuid);
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
@@ -337,12 +326,10 @@ export function useRetrieveHandler() {
|
|||||||
removeLastMaterial(storageUnit.modelUuid);
|
removeLastMaterial(storageUnit.modelUuid);
|
||||||
updateCurrentLoad(storageUnit.modelUuid, -1);
|
updateCurrentLoad(storageUnit.modelUuid, -1);
|
||||||
incrementHumanLoad(human.modelUuid, 1);
|
incrementHumanLoad(human.modelUuid, 1);
|
||||||
addHumanToMonitor(human.modelUuid, () => {
|
addCurrentMaterialToHuman(human.modelUuid, material.materialType, material.materialId);
|
||||||
addCurrentMaterialToHuman(human.modelUuid, material.materialType, material.materialId);
|
retrieveLogStatus(material.materialName, `is picked by ${human.modelName}`);
|
||||||
retrieveLogStatus(material.materialName, `is picked by ${human.modelName}`);
|
|
||||||
|
|
||||||
retrievalCountRef.current.set(actionUuid, currentCount + 1);
|
retrievalCountRef.current.set(actionUuid, currentCount + 1);
|
||||||
}, actionUuid)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user