bug fix human
This commit is contained in:
@@ -6,12 +6,13 @@ import { useProductContext } from "../../../products/productContext";
|
|||||||
import { useHumanEventManager } from "../../../human/eventManager/useHumanEventManager";
|
import { useHumanEventManager } from "../../../human/eventManager/useHumanEventManager";
|
||||||
|
|
||||||
export function useRetrieveHandler() {
|
export function useRetrieveHandler() {
|
||||||
const { materialStore, armBotStore, machineStore, vehicleStore, storageUnitStore, productStore, humanStore, assetStore } = useSceneContext();
|
const { materialStore, armBotStore, machineStore, vehicleStore, storageUnitStore, conveyorStore, 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 { getConveyorById } = conveyorStore();
|
||||||
const { getHumanById, incrementHumanLoad, addCurrentMaterial: addCurrentMaterialToHuman } = humanStore();
|
const { getHumanById, incrementHumanLoad, addCurrentMaterial: addCurrentMaterialToHuman } = humanStore();
|
||||||
const { getAssetById, setCurrentAnimation } = assetStore();
|
const { getAssetById, setCurrentAnimation } = assetStore();
|
||||||
const { selectedProduct } = selectedProductStore();
|
const { selectedProduct } = selectedProductStore();
|
||||||
@@ -371,6 +372,32 @@ export function useRetrieveHandler() {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (triggeredModel?.type === 'transfer') {
|
||||||
|
const model = getConveyorById(triggeredModel.modelUuid);
|
||||||
|
if (model && !model.isPaused) {
|
||||||
|
if (humanAsset?.animationState?.current === 'idle') {
|
||||||
|
setCurrentAnimation(human.modelUuid, 'pickup', true, false, false);
|
||||||
|
} else if (humanAsset?.animationState?.current === 'pickup' && humanAsset.animationState.isCompleted) {
|
||||||
|
const lastMaterial = getLastMaterial(storageUnit.modelUuid);
|
||||||
|
if (lastMaterial) {
|
||||||
|
const material = createNewMaterial(
|
||||||
|
lastMaterial.materialId,
|
||||||
|
lastMaterial.materialType,
|
||||||
|
storageUnit.point.action
|
||||||
|
);
|
||||||
|
if (material) {
|
||||||
|
removeLastMaterial(storageUnit.modelUuid);
|
||||||
|
updateCurrentLoad(storageUnit.modelUuid, -1);
|
||||||
|
incrementHumanLoad(human.modelUuid, 1);
|
||||||
|
addCurrentMaterialToHuman(human.modelUuid, material.materialType, material.materialId);
|
||||||
|
retrieveLogStatus(material.materialName, `is picked by ${human.modelName}`);
|
||||||
|
|
||||||
|
retrievalCountRef.current.set(actionUuid, currentCount + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else if (triggeredModel?.type === 'machine') {
|
} else if (triggeredModel?.type === 'machine') {
|
||||||
const machine = getMachineById(triggeredModel.modelUuid);
|
const machine = getMachineById(triggeredModel.modelUuid);
|
||||||
if (machine && !machine.isActive && machine.state === 'idle' && !machine.currentAction) {
|
if (machine && !machine.isActive && machine.state === 'idle' && !machine.currentAction) {
|
||||||
|
|||||||
@@ -182,31 +182,23 @@ function TriggerConnector() {
|
|||||||
const canvasElement = gl.domElement;
|
const canvasElement = gl.domElement;
|
||||||
|
|
||||||
let drag = false;
|
let drag = false;
|
||||||
let isRightMouseDown = false;
|
let isLeftMouseDown = false;
|
||||||
|
|
||||||
const onMouseDown = (evt: MouseEvent) => {
|
const onMouseDown = (evt: MouseEvent) => {
|
||||||
if (selectedAsset) {
|
if (selectedAsset) {
|
||||||
clearSelectedAsset();
|
clearSelectedAsset();
|
||||||
}
|
}
|
||||||
if (evt.button === 2) {
|
if (evt.button === 0) {
|
||||||
isRightMouseDown = true;
|
isLeftMouseDown = true;
|
||||||
drag = false;
|
drag = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onMouseUp = (evt: MouseEvent) => {
|
const onMouseUp = (evt: MouseEvent) => {
|
||||||
if (evt.button === 2) {
|
if (evt.button === 0) {
|
||||||
isRightMouseDown = false;
|
isLeftMouseDown = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const onMouseMove = () => {
|
|
||||||
if (isRightMouseDown) {
|
|
||||||
drag = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRightClick = (evt: MouseEvent) => {
|
|
||||||
if (drag) return;
|
if (drag) return;
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
@@ -368,13 +360,16 @@ function TriggerConnector() {
|
|||||||
} else if (firstSelectedPoint) {
|
} else if (firstSelectedPoint) {
|
||||||
setFirstSelectedPoint(null);
|
setFirstSelectedPoint(null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onMouseMove = () => {
|
||||||
|
drag = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (subModule === 'mechanics' && toolMode === 'cursor' && selectedAction.actionId && selectedAction.actionName) {
|
if (subModule === 'mechanics' && toolMode === 'cursor' && selectedAction.actionId && selectedAction.actionName) {
|
||||||
canvasElement.addEventListener("mousedown", onMouseDown);
|
canvasElement.addEventListener("mousedown", onMouseDown);
|
||||||
canvasElement.addEventListener("mouseup", onMouseUp);
|
canvasElement.addEventListener("mouseup", onMouseUp);
|
||||||
canvasElement.addEventListener("mousemove", onMouseMove);
|
canvasElement.addEventListener("mousemove", onMouseMove);
|
||||||
canvasElement.addEventListener('contextmenu', handleRightClick);
|
|
||||||
} else {
|
} else {
|
||||||
setFirstSelectedPoint(null);
|
setFirstSelectedPoint(null);
|
||||||
}
|
}
|
||||||
@@ -383,7 +378,6 @@ function TriggerConnector() {
|
|||||||
canvasElement.removeEventListener("mousedown", onMouseDown);
|
canvasElement.removeEventListener("mousedown", onMouseDown);
|
||||||
canvasElement.removeEventListener("mouseup", onMouseUp);
|
canvasElement.removeEventListener("mouseup", onMouseUp);
|
||||||
canvasElement.removeEventListener("mousemove", onMouseMove);
|
canvasElement.removeEventListener("mousemove", onMouseMove);
|
||||||
canvasElement.removeEventListener('contextmenu', handleRightClick);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}, [gl, subModule, selectedProduct, firstSelectedPoint, toolMode, selectedAction]);
|
}, [gl, subModule, selectedProduct, firstSelectedPoint, toolMode, selectedAction]);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
import { Line, useGLTF } from '@react-three/drei';
|
import { Tube, useGLTF } from '@react-three/drei';
|
||||||
import { useFrame, useThree } from '@react-three/fiber';
|
import { useFrame, useThree } from '@react-three/fiber';
|
||||||
import { useIsDragging, useIsRotating, useSelectedAction, useSelectedEventSphere } from '../../../../../store/simulation/useSimulationStore';
|
import { useIsDragging, useIsRotating, useSelectedAction, useSelectedEventSphere } from '../../../../../store/simulation/useSimulationStore';
|
||||||
import { useProductContext } from '../../../products/productContext';
|
import { useProductContext } from '../../../products/productContext';
|
||||||
@@ -395,13 +395,12 @@ const MarkerPrimitive = ({
|
|||||||
setIsRotating: (val: any) => void;
|
setIsRotating: (val: any) => void;
|
||||||
handlePointerDown: any;
|
handlePointerDown: any;
|
||||||
}) => {
|
}) => {
|
||||||
const { controls, scene } = useThree();
|
const { controls, scene, camera } = useThree();
|
||||||
const [hitPoint, setHitPoint] = useState<THREE.Vector3 | null>(null);
|
const [hitPoint, setHitPoint] = useState<THREE.Vector3 | null>(null);
|
||||||
|
const [curve, setCurve] = useState<THREE.CatmullRomCurve3 | null>(null);
|
||||||
const lineRef = useRef<THREE.BufferGeometry>(null);
|
|
||||||
|
|
||||||
useFrame(() => {
|
useFrame(() => {
|
||||||
if (!refProp.current || !outerGroupRef.current) return;
|
if (!refProp.current || !outerGroupRef.current || !scene) return;
|
||||||
|
|
||||||
const worldPos = new THREE.Vector3();
|
const worldPos = new THREE.Vector3();
|
||||||
refProp.current.getWorldPosition(worldPos);
|
refProp.current.getWorldPosition(worldPos);
|
||||||
@@ -410,6 +409,7 @@ const MarkerPrimitive = ({
|
|||||||
const rayOrigin = worldPos.clone();
|
const rayOrigin = worldPos.clone();
|
||||||
const direction = new THREE.Vector3(0, -1, 0);
|
const direction = new THREE.Vector3(0, -1, 0);
|
||||||
const raycaster = new THREE.Raycaster(rayOrigin, direction, 0.1, 1000);
|
const raycaster = new THREE.Raycaster(rayOrigin, direction, 0.1, 1000);
|
||||||
|
raycaster.camera = camera;
|
||||||
const intersects = raycaster.intersectObjects(scene.children, true);
|
const intersects = raycaster.intersectObjects(scene.children, true);
|
||||||
|
|
||||||
const hit = intersects.find(i => i.object.name !== name);
|
const hit = intersects.find(i => i.object.name !== name);
|
||||||
@@ -418,13 +418,14 @@ const MarkerPrimitive = ({
|
|||||||
const localHit = outerGroupRef.current.worldToLocal(hit.point.clone());
|
const localHit = outerGroupRef.current.worldToLocal(hit.point.clone());
|
||||||
setHitPoint(localHit);
|
setHitPoint(localHit);
|
||||||
|
|
||||||
if (lineRef.current) {
|
const newCurve = new THREE.CatmullRomCurve3([
|
||||||
const positions = new Float32Array([localMarkerPos.x, localMarkerPos.y, localMarkerPos.z, localHit.x, localHit.y, localHit.z]);
|
localMarkerPos.clone(),
|
||||||
lineRef.current.setAttribute('position', new THREE.BufferAttribute(positions, 3));
|
localHit.clone(),
|
||||||
lineRef.current.attributes.position.needsUpdate = true;
|
]);
|
||||||
}
|
setCurve(newCurve);
|
||||||
} else {
|
} else {
|
||||||
setHitPoint(null);
|
setHitPoint(null);
|
||||||
|
setCurve(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -450,13 +451,14 @@ const MarkerPrimitive = ({
|
|||||||
<>
|
<>
|
||||||
<mesh name={name} position={hitPoint} rotation={[-Math.PI / 2, 0, 0]}>
|
<mesh name={name} position={hitPoint} rotation={[-Math.PI / 2, 0, 0]}>
|
||||||
<torusGeometry args={[0.15, 0.02, 3, 32]} />
|
<torusGeometry args={[0.15, 0.02, 3, 32]} />
|
||||||
<meshBasicMaterial color={color} transparent opacity={0.8} depthWrite={false} />
|
<meshBasicMaterial color={color} depthWrite={false} />
|
||||||
</mesh>
|
</mesh>
|
||||||
|
|
||||||
<line>
|
{curve && (
|
||||||
<bufferGeometry ref={lineRef} />
|
<Tube args={[curve, 20, 0.01, 8, true]} >
|
||||||
<lineBasicMaterial color={color} />
|
<meshBasicMaterial color={color} depthWrite={false} />
|
||||||
</line>
|
</Tube>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ function RoboticArmAnimator({ HandleCallback, restPosition, ikSolver, targetBone
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (prevModel && prevModel.type === 'storageUnit') {
|
} else if (prevModel && prevModel.type === 'storageUnit') {
|
||||||
const position = getMaterialPosition(currentMaterial);
|
const position = getMaterialPosition(prevModel.modelUuid, currentMaterial);
|
||||||
const armbotModel = scene.getObjectByProperty("uuid", armBot.modelUuid);
|
const armbotModel = scene.getObjectByProperty("uuid", armBot.modelUuid);
|
||||||
|
|
||||||
if (armbotModel) {
|
if (armbotModel) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import * as Types from "../../../../types/world/worldTypes";
|
import * as Types from "../../../../types/world/worldTypes";
|
||||||
import { useGLTF } from "@react-three/drei";
|
import { Tube, useGLTF } from "@react-three/drei";
|
||||||
import * as THREE from "three";
|
import * as THREE from "three";
|
||||||
import { useFrame, useThree } from "@react-three/fiber";
|
import { useFrame, useThree } from "@react-three/fiber";
|
||||||
import { useSelectedEventSphere, useIsDragging, useIsRotating, } from "../../../../store/simulation/useSimulationStore";
|
import { useSelectedEventSphere, useIsDragging, useIsRotating, } from "../../../../store/simulation/useSimulationStore";
|
||||||
@@ -17,8 +17,6 @@ import { useVersionContext } from "../../../builder/version/versionContext";
|
|||||||
const VehicleUI = () => {
|
const VehicleUI = () => {
|
||||||
const { scene: startScene } = useGLTF(startPoint) as any;
|
const { scene: startScene } = useGLTF(startPoint) as any;
|
||||||
const { scene: endScene } = useGLTF(startEnd) as any;
|
const { scene: endScene } = useGLTF(startEnd) as any;
|
||||||
const startMarker = useRef<Group>(null);
|
|
||||||
const endMarker = useRef<Group>(null);
|
|
||||||
const prevMousePos = useRef({ x: 0, y: 0 });
|
const prevMousePos = useRef({ x: 0, y: 0 });
|
||||||
const { selectedEventSphere } = useSelectedEventSphere();
|
const { selectedEventSphere } = useSelectedEventSphere();
|
||||||
const { selectedProductStore } = useProductContext();
|
const { selectedProductStore } = useProductContext();
|
||||||
@@ -163,7 +161,7 @@ const VehicleUI = () => {
|
|||||||
let globalStartPosition = null;
|
let globalStartPosition = null;
|
||||||
let globalEndPosition = null;
|
let globalEndPosition = null;
|
||||||
|
|
||||||
if (outerGroup.current && startMarker.current && endMarker.current) {
|
if (outerGroup.current) {
|
||||||
const worldPosStart = new Vector3(...startPosition);
|
const worldPosStart = new Vector3(...startPosition);
|
||||||
globalStartPosition = outerGroup.current.localToWorld(
|
globalStartPosition = outerGroup.current.localToWorld(
|
||||||
worldPosStart.clone()
|
worldPosStart.clone()
|
||||||
@@ -278,24 +276,19 @@ const VehicleUI = () => {
|
|||||||
const currentPointerX = state.pointer.x;
|
const currentPointerX = state.pointer.x;
|
||||||
const deltaX = currentPointerX - prevMousePos.current.x;
|
const deltaX = currentPointerX - prevMousePos.current.x;
|
||||||
prevMousePos.current.x = currentPointerX;
|
prevMousePos.current.x = currentPointerX;
|
||||||
const marker =
|
const rotationSpeed = 10;
|
||||||
isRotating === "start" ? startMarker.current : endMarker.current;
|
if (isRotating === "start") {
|
||||||
if (marker) {
|
setStartRotation([
|
||||||
const rotationSpeed = 10;
|
startRotation[0],
|
||||||
marker.rotation.y += deltaX * rotationSpeed;
|
startRotation[1] + deltaX * rotationSpeed,
|
||||||
if (isRotating === "start") {
|
startRotation[2],
|
||||||
setStartRotation([
|
]);
|
||||||
marker.rotation.x,
|
} else {
|
||||||
marker.rotation.y,
|
setEndRotation([
|
||||||
marker.rotation.z,
|
endRotation[0],
|
||||||
]);
|
endRotation[1] + deltaX * rotationSpeed,
|
||||||
} else {
|
endRotation[2],
|
||||||
setEndRotation([
|
]);
|
||||||
marker.rotation.x,
|
|
||||||
marker.rotation.y,
|
|
||||||
marker.rotation.z,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -362,7 +355,7 @@ const VehicleUI = () => {
|
|||||||
position={endPosition}
|
position={endPosition}
|
||||||
rotation={endRotation}
|
rotation={endRotation}
|
||||||
outerGroupRef={outerGroup}
|
outerGroupRef={outerGroup}
|
||||||
color="red"
|
color="orange"
|
||||||
handlePointerDown={handlePointerDown}
|
handlePointerDown={handlePointerDown}
|
||||||
setIsDragging={setIsDragging}
|
setIsDragging={setIsDragging}
|
||||||
setIsRotating={setIsRotating}
|
setIsRotating={setIsRotating}
|
||||||
@@ -394,10 +387,10 @@ export const VehicleMarkerPrimitive = ({
|
|||||||
setIsDragging: (val: any) => void;
|
setIsDragging: (val: any) => void;
|
||||||
setIsRotating: (val: any) => void;
|
setIsRotating: (val: any) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const { scene } = useThree();
|
const { scene, camera } = useThree();
|
||||||
const markerRef = useRef<THREE.Group>(null);
|
const markerRef = useRef<THREE.Group>(null);
|
||||||
const lineRef = useRef<THREE.BufferGeometry>(null);
|
|
||||||
const [hitPoint, setHitPoint] = useState<THREE.Vector3 | null>(null);
|
const [hitPoint, setHitPoint] = useState<THREE.Vector3 | null>(null);
|
||||||
|
const [curve, setCurve] = useState<THREE.CatmullRomCurve3 | null>(null);
|
||||||
|
|
||||||
useFrame(() => {
|
useFrame(() => {
|
||||||
if (!markerRef.current || !outerGroupRef.current) return;
|
if (!markerRef.current || !outerGroupRef.current) return;
|
||||||
@@ -409,6 +402,7 @@ export const VehicleMarkerPrimitive = ({
|
|||||||
const rayOrigin = worldPos.clone();
|
const rayOrigin = worldPos.clone();
|
||||||
const direction = new THREE.Vector3(0, -1, 0);
|
const direction = new THREE.Vector3(0, -1, 0);
|
||||||
const raycaster = new THREE.Raycaster(rayOrigin, direction, 0.1, 1000);
|
const raycaster = new THREE.Raycaster(rayOrigin, direction, 0.1, 1000);
|
||||||
|
raycaster.camera = camera;
|
||||||
const intersects = raycaster.intersectObjects(scene.children, true);
|
const intersects = raycaster.intersectObjects(scene.children, true);
|
||||||
|
|
||||||
const hit = intersects.find(i => i.object.name !== name);
|
const hit = intersects.find(i => i.object.name !== name);
|
||||||
@@ -416,16 +410,14 @@ export const VehicleMarkerPrimitive = ({
|
|||||||
const localHit = outerGroupRef.current.worldToLocal(hit.point.clone());
|
const localHit = outerGroupRef.current.worldToLocal(hit.point.clone());
|
||||||
setHitPoint(localHit);
|
setHitPoint(localHit);
|
||||||
|
|
||||||
if (lineRef.current) {
|
const newCurve = new THREE.CatmullRomCurve3([
|
||||||
const positions = new Float32Array([
|
localMarkerPos.clone(),
|
||||||
localMarkerPos.x, localMarkerPos.y, localMarkerPos.z,
|
localHit.clone(),
|
||||||
localHit.x, localHit.y, localHit.z
|
]);
|
||||||
]);
|
setCurve(newCurve);
|
||||||
lineRef.current.setAttribute('position', new THREE.BufferAttribute(positions, 3));
|
|
||||||
lineRef.current.attributes.position.needsUpdate = true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setHitPoint(null);
|
setHitPoint(null);
|
||||||
|
setCurve(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -437,7 +429,13 @@ export const VehicleMarkerPrimitive = ({
|
|||||||
object={object}
|
object={object}
|
||||||
position={position}
|
position={position}
|
||||||
rotation={rotation}
|
rotation={rotation}
|
||||||
onPointerDown={(e: any) => handlePointerDown(e, name === "startMarker" ? "start" : "end", name === "startMarker" ? "start" : "end")}
|
onPointerDown={(e: any) =>
|
||||||
|
handlePointerDown(
|
||||||
|
e,
|
||||||
|
name === "startMarker" ? "start" : "end",
|
||||||
|
name === "startMarker" ? "start" : "end"
|
||||||
|
)
|
||||||
|
}
|
||||||
onPointerMissed={() => {
|
onPointerMissed={() => {
|
||||||
setIsDragging(null);
|
setIsDragging(null);
|
||||||
setIsRotating(null);
|
setIsRotating(null);
|
||||||
@@ -446,15 +444,20 @@ export const VehicleMarkerPrimitive = ({
|
|||||||
|
|
||||||
{hitPoint && (
|
{hitPoint && (
|
||||||
<>
|
<>
|
||||||
<mesh name={`${name}-torus`} position={hitPoint} rotation={[-Math.PI / 2, 0, 0]}>
|
<mesh
|
||||||
|
name={`${name}-torus`}
|
||||||
|
position={hitPoint}
|
||||||
|
rotation={[-Math.PI / 2, 0, 0]}
|
||||||
|
>
|
||||||
<torusGeometry args={[0.15, 0.02, 3, 32]} />
|
<torusGeometry args={[0.15, 0.02, 3, 32]} />
|
||||||
<meshBasicMaterial color={color} transparent opacity={0.8} depthWrite={false} />
|
<meshBasicMaterial color={color} depthWrite={false} />
|
||||||
</mesh>
|
</mesh>
|
||||||
|
|
||||||
<line>
|
{curve && (
|
||||||
<bufferGeometry ref={lineRef} />
|
<Tube args={[curve, 20, 0.01, 8, true]}>
|
||||||
<lineBasicMaterial color={color} />
|
<meshBasicMaterial color={color} depthWrite={false} />
|
||||||
</line>
|
</Tube>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const MaterialAnimator = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!storageModel || storage.currentMaterials.length === 0) {
|
if (!storageModel || storage.currentMaterials.length === 0) {
|
||||||
setMaterialPositions([]);
|
setMaterialPositions(storage.modelUuid, []);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,12 +59,12 @@ const MaterialAnimator = ({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
setMaterialPositions(newMaterials);
|
setMaterialPositions(storage.modelUuid, newMaterials);
|
||||||
}, [storageModel, storage.currentMaterials, setMaterialPositions]);
|
}, [storageModel, storage.currentMaterials]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<group position={[0, -padding, 0]}>
|
<group position={[0, -padding, 0]}>
|
||||||
{materialPositions.map(({ materialId, position }) => {
|
{(materialPositions[storage.modelUuid] || []).map(({ materialId, position }) => {
|
||||||
const mat = storage.currentMaterials.find((m) => m.materialId === materialId);
|
const mat = storage.currentMaterials.find((m) => m.materialId === materialId);
|
||||||
return (
|
return (
|
||||||
<MaterialModel
|
<MaterialModel
|
||||||
@@ -78,6 +78,7 @@ const MaterialAnimator = ({
|
|||||||
})}
|
})}
|
||||||
</group>
|
</group>
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MaterialAnimator;
|
export default MaterialAnimator;
|
||||||
|
|||||||
@@ -370,40 +370,18 @@ export function useTriggerHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (human.isActive === false && human.state === 'idle') {
|
|
||||||
|
|
||||||
// Handle current action from arm bot
|
|
||||||
setIsPaused(materialId, true);
|
|
||||||
handleAction(action, materialId);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Handle current action using Event Manager
|
|
||||||
setHumanScheduled(human.modelUuid, true);
|
|
||||||
setIsPaused(materialId, true);
|
|
||||||
addHumanToMonitor(human.modelUuid, () => {
|
|
||||||
handleAction(action, materialId)
|
|
||||||
}, action.actionUuid);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (human.isActive === false && human.state === 'idle') {
|
|
||||||
|
|
||||||
// Handle current action from arm bot
|
|
||||||
setIsPaused(materialId, true);
|
|
||||||
setHumanScheduled(human.modelUuid, true);
|
setHumanScheduled(human.modelUuid, true);
|
||||||
handleAction(action, materialId);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Handle current action using Event Manager
|
|
||||||
setIsPaused(materialId, true);
|
setIsPaused(materialId, true);
|
||||||
setHumanScheduled(human.modelUuid, true);
|
|
||||||
addHumanToMonitor(human.modelUuid, () => {
|
addHumanToMonitor(human.modelUuid, () => {
|
||||||
handleAction(action, materialId)
|
handleAction(action, materialId)
|
||||||
}, action.actionUuid);
|
}, action.actionUuid);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
setHumanScheduled(human.modelUuid, true);
|
||||||
|
setIsPaused(materialId, true);
|
||||||
|
addHumanToMonitor(human.modelUuid, () => {
|
||||||
|
handleAction(action, materialId)
|
||||||
|
}, action.actionUuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1260,12 +1238,6 @@ export function useTriggerHandler() {
|
|||||||
actionUuid: material.current.actionUuid,
|
actionUuid: material.current.actionUuid,
|
||||||
})
|
})
|
||||||
|
|
||||||
setCurrentLocation(material.materialId, {
|
|
||||||
modelUuid: material.current.modelUuid,
|
|
||||||
pointUuid: material.current.pointUuid,
|
|
||||||
actionUuid: material.current.actionUuid,
|
|
||||||
});
|
|
||||||
|
|
||||||
setIsPaused(material.materialId, true);
|
setIsPaused(material.materialId, true);
|
||||||
setIsVisible(material.materialId, true);
|
setIsVisible(material.materialId, true);
|
||||||
|
|
||||||
@@ -1279,6 +1251,13 @@ export function useTriggerHandler() {
|
|||||||
|
|
||||||
if (model?.type === 'roboticArm') {
|
if (model?.type === 'roboticArm') {
|
||||||
addArmBotToMonitor(model.modelUuid, () => {
|
addArmBotToMonitor(model.modelUuid, () => {
|
||||||
|
|
||||||
|
setCurrentLocation(material.materialId, {
|
||||||
|
modelUuid: material.current.modelUuid,
|
||||||
|
pointUuid: material.current.pointUuid,
|
||||||
|
actionUuid: material.current.actionUuid,
|
||||||
|
});
|
||||||
|
|
||||||
setNextLocation(material.materialId, {
|
setNextLocation(material.materialId, {
|
||||||
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
||||||
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
||||||
@@ -1288,6 +1267,13 @@ export function useTriggerHandler() {
|
|||||||
})
|
})
|
||||||
} else if (model?.type === 'vehicle') {
|
} else if (model?.type === 'vehicle') {
|
||||||
addVehicleToMonitor(model.modelUuid, () => {
|
addVehicleToMonitor(model.modelUuid, () => {
|
||||||
|
|
||||||
|
setCurrentLocation(material.materialId, {
|
||||||
|
modelUuid: material.current.modelUuid,
|
||||||
|
pointUuid: material.current.pointUuid,
|
||||||
|
actionUuid: material.current.actionUuid,
|
||||||
|
});
|
||||||
|
|
||||||
setNextLocation(material.materialId, {
|
setNextLocation(material.materialId, {
|
||||||
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
||||||
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
||||||
@@ -1296,6 +1282,13 @@ export function useTriggerHandler() {
|
|||||||
setIsPaused(material.materialId, false);
|
setIsPaused(material.materialId, false);
|
||||||
})
|
})
|
||||||
} else if (model?.type === 'transfer') {
|
} else if (model?.type === 'transfer') {
|
||||||
|
|
||||||
|
setCurrentLocation(material.materialId, {
|
||||||
|
modelUuid: material.current.modelUuid,
|
||||||
|
pointUuid: material.current.pointUuid,
|
||||||
|
actionUuid: material.current.actionUuid,
|
||||||
|
});
|
||||||
|
|
||||||
setNextLocation(material.materialId, {
|
setNextLocation(material.materialId, {
|
||||||
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
||||||
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
||||||
@@ -1303,15 +1296,48 @@ export function useTriggerHandler() {
|
|||||||
|
|
||||||
setIsPaused(material.materialId, false);
|
setIsPaused(material.materialId, false);
|
||||||
} else if (model?.type === 'human') {
|
} else if (model?.type === 'human') {
|
||||||
addHumanToMonitor(model.modelUuid, () => {
|
if (fromEvent.modelUuid === model.modelUuid) {
|
||||||
setNextLocation(material.materialId, {
|
|
||||||
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
|
||||||
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
|
||||||
})
|
|
||||||
|
|
||||||
setIsPaused(material.materialId, false);
|
setIsPaused(material.materialId, false);
|
||||||
}, action.actionUuid)
|
|
||||||
|
setCurrentLocation(material.materialId, {
|
||||||
|
modelUuid: material.current.modelUuid,
|
||||||
|
pointUuid: material.current.pointUuid,
|
||||||
|
actionUuid: material.current.actionUuid,
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setIsPaused(material.materialId, false);
|
||||||
|
setNextLocation(material.materialId, {
|
||||||
|
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
||||||
|
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
||||||
|
})
|
||||||
|
}, 0)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
addHumanToMonitor(model.modelUuid, () => {
|
||||||
|
|
||||||
|
setCurrentLocation(material.materialId, {
|
||||||
|
modelUuid: material.current.modelUuid,
|
||||||
|
pointUuid: material.current.pointUuid,
|
||||||
|
actionUuid: material.current.actionUuid,
|
||||||
|
});
|
||||||
|
|
||||||
|
setNextLocation(material.materialId, {
|
||||||
|
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
||||||
|
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
||||||
|
})
|
||||||
|
|
||||||
|
setIsPaused(material.materialId, false);
|
||||||
|
}, action.actionUuid)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
setCurrentLocation(material.materialId, {
|
||||||
|
modelUuid: material.current.modelUuid,
|
||||||
|
pointUuid: material.current.pointUuid,
|
||||||
|
actionUuid: material.current.actionUuid,
|
||||||
|
});
|
||||||
|
|
||||||
setNextLocation(material.materialId, {
|
setNextLocation(material.materialId, {
|
||||||
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
modelUuid: trigger.triggeredAsset?.triggeredModel.modelUuid || '',
|
||||||
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
pointUuid: trigger.triggeredAsset?.triggeredPoint?.pointUuid || '',
|
||||||
|
|||||||
@@ -8,18 +8,21 @@ interface MaterialPosition {
|
|||||||
position: THREE.Vector3;
|
position: THREE.Vector3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MaterialPositionsMap = Record<string, MaterialPosition[]>;
|
||||||
|
|
||||||
type MaterialsStore = {
|
type MaterialsStore = {
|
||||||
materials: MaterialsSchema;
|
materials: MaterialsSchema;
|
||||||
materialHistory: MaterialHistorySchema;
|
materialHistory: MaterialHistorySchema;
|
||||||
materialPositions: MaterialPosition[];
|
materialPositions: MaterialPositionsMap;
|
||||||
|
|
||||||
|
|
||||||
addMaterial: (material: MaterialSchema) => MaterialSchema | undefined;
|
addMaterial: (material: MaterialSchema) => MaterialSchema | undefined;
|
||||||
removeMaterial: (materialId: string) => MaterialSchema | undefined;
|
removeMaterial: (materialId: string) => MaterialSchema | undefined;
|
||||||
clearMaterials: () => void;
|
clearMaterials: () => void;
|
||||||
updateMaterial: (materialId: string, updates: Partial<MaterialSchema>) => MaterialSchema | undefined;
|
updateMaterial: (materialId: string, updates: Partial<MaterialSchema>) => MaterialSchema | undefined;
|
||||||
|
|
||||||
setMaterialPositions: (materialPosition: MaterialPosition[]) => void;
|
setMaterialPositions: (modelUuid: string, materialPositions: MaterialPosition[]) => void;
|
||||||
getMaterialPosition: (materialId: string) => THREE.Vector3 | undefined;
|
getMaterialPosition: (modelUuid: string, materialId: string) => THREE.Vector3 | undefined;
|
||||||
|
|
||||||
setPreviousLocation: (
|
setPreviousLocation: (
|
||||||
materialId: string,
|
materialId: string,
|
||||||
@@ -72,7 +75,7 @@ export const createMaterialStore = () => {
|
|||||||
immer((set, get) => ({
|
immer((set, get) => ({
|
||||||
materials: [],
|
materials: [],
|
||||||
materialHistory: [],
|
materialHistory: [],
|
||||||
materialPositions: [],
|
materialPositions: {},
|
||||||
|
|
||||||
addMaterial: (material) => {
|
addMaterial: (material) => {
|
||||||
let updatedMaterial: MaterialSchema | undefined;
|
let updatedMaterial: MaterialSchema | undefined;
|
||||||
@@ -274,21 +277,14 @@ export const createMaterialStore = () => {
|
|||||||
return updatedMaterial;
|
return updatedMaterial;
|
||||||
},
|
},
|
||||||
|
|
||||||
setMaterialPositions: (materials) => {
|
setMaterialPositions: (modelUuid, positions) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
state.materialPositions = materials;
|
state.materialPositions[modelUuid] = positions;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getMaterialPosition: (materialid) => {
|
getMaterialPosition: (modelUuid, materialId) => {
|
||||||
let position: THREE.Vector3 | undefined;
|
return get().materialPositions[modelUuid]?.find(p => p.materialId === materialId)?.position;
|
||||||
set((state) => {
|
|
||||||
const material = state.materialPositions.find(m => m.materialId === materialid);
|
|
||||||
if (material) {
|
|
||||||
position = material.position;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return position;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getMaterialById: (materialId) => {
|
getMaterialById: (materialId) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user