bug fix human

This commit is contained in:
2025-08-05 13:10:36 +05:30
parent c03e524b99
commit 169e098024
8 changed files with 183 additions and 134 deletions

View File

@@ -6,12 +6,13 @@ import { useProductContext } from "../../../products/productContext";
import { useHumanEventManager } from "../../../human/eventManager/useHumanEventManager";
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 { addMaterial } = materialStore();
const { getModelUuidByActionUuid, getPointUuidByActionUuid, getEventByModelUuid, getActionByUuid } = productStore();
const { getStorageUnitById, getLastMaterial, updateCurrentLoad, removeLastMaterial } = storageUnitStore();
const { getVehicleById, incrementVehicleLoad, addCurrentMaterial } = vehicleStore();
const { getConveyorById } = conveyorStore();
const { getHumanById, incrementHumanLoad, addCurrentMaterial: addCurrentMaterialToHuman } = humanStore();
const { getAssetById, setCurrentAnimation } = assetStore();
const { selectedProduct } = selectedProductStore();
@@ -371,6 +372,32 @@ export function useRetrieveHandler() {
}
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') {
const machine = getMachineById(triggeredModel.modelUuid);
if (machine && !machine.isActive && machine.state === 'idle' && !machine.currentAction) {

View File

@@ -182,31 +182,23 @@ function TriggerConnector() {
const canvasElement = gl.domElement;
let drag = false;
let isRightMouseDown = false;
let isLeftMouseDown = false;
const onMouseDown = (evt: MouseEvent) => {
if (selectedAsset) {
clearSelectedAsset();
}
if (evt.button === 2) {
isRightMouseDown = true;
if (evt.button === 0) {
isLeftMouseDown = true;
drag = false;
}
};
const onMouseUp = (evt: MouseEvent) => {
if (evt.button === 2) {
isRightMouseDown = false;
if (evt.button === 0) {
isLeftMouseDown = false;
}
}
const onMouseMove = () => {
if (isRightMouseDown) {
drag = true;
}
};
const handleRightClick = (evt: MouseEvent) => {
if (drag) return;
evt.preventDefault();
@@ -368,13 +360,16 @@ function TriggerConnector() {
} else if (firstSelectedPoint) {
setFirstSelectedPoint(null);
}
}
const onMouseMove = () => {
drag = true;
};
if (subModule === 'mechanics' && toolMode === 'cursor' && selectedAction.actionId && selectedAction.actionName) {
canvasElement.addEventListener("mousedown", onMouseDown);
canvasElement.addEventListener("mouseup", onMouseUp);
canvasElement.addEventListener("mousemove", onMouseMove);
canvasElement.addEventListener('contextmenu', handleRightClick);
} else {
setFirstSelectedPoint(null);
}
@@ -383,7 +378,6 @@ function TriggerConnector() {
canvasElement.removeEventListener("mousedown", onMouseDown);
canvasElement.removeEventListener("mouseup", onMouseUp);
canvasElement.removeEventListener("mousemove", onMouseMove);
canvasElement.removeEventListener('contextmenu', handleRightClick);
};
}, [gl, subModule, selectedProduct, firstSelectedPoint, toolMode, selectedAction]);

View File

@@ -1,6 +1,6 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
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 { useIsDragging, useIsRotating, useSelectedAction, useSelectedEventSphere } from '../../../../../store/simulation/useSimulationStore';
import { useProductContext } from '../../../products/productContext';
@@ -395,13 +395,12 @@ const MarkerPrimitive = ({
setIsRotating: (val: any) => void;
handlePointerDown: any;
}) => {
const { controls, scene } = useThree();
const { controls, scene, camera } = useThree();
const [hitPoint, setHitPoint] = useState<THREE.Vector3 | null>(null);
const lineRef = useRef<THREE.BufferGeometry>(null);
const [curve, setCurve] = useState<THREE.CatmullRomCurve3 | null>(null);
useFrame(() => {
if (!refProp.current || !outerGroupRef.current) return;
if (!refProp.current || !outerGroupRef.current || !scene) return;
const worldPos = new THREE.Vector3();
refProp.current.getWorldPosition(worldPos);
@@ -410,6 +409,7 @@ const MarkerPrimitive = ({
const rayOrigin = worldPos.clone();
const direction = new THREE.Vector3(0, -1, 0);
const raycaster = new THREE.Raycaster(rayOrigin, direction, 0.1, 1000);
raycaster.camera = camera;
const intersects = raycaster.intersectObjects(scene.children, true);
const hit = intersects.find(i => i.object.name !== name);
@@ -418,13 +418,14 @@ const MarkerPrimitive = ({
const localHit = outerGroupRef.current.worldToLocal(hit.point.clone());
setHitPoint(localHit);
if (lineRef.current) {
const positions = new Float32Array([localMarkerPos.x, localMarkerPos.y, localMarkerPos.z, localHit.x, localHit.y, localHit.z]);
lineRef.current.setAttribute('position', new THREE.BufferAttribute(positions, 3));
lineRef.current.attributes.position.needsUpdate = true;
}
const newCurve = new THREE.CatmullRomCurve3([
localMarkerPos.clone(),
localHit.clone(),
]);
setCurve(newCurve);
} else {
setHitPoint(null);
setCurve(null);
}
});
@@ -450,15 +451,16 @@ const MarkerPrimitive = ({
<>
<mesh name={name} position={hitPoint} rotation={[-Math.PI / 2, 0, 0]}>
<torusGeometry args={[0.15, 0.02, 3, 32]} />
<meshBasicMaterial color={color} transparent opacity={0.8} depthWrite={false} />
<meshBasicMaterial color={color} depthWrite={false} />
</mesh>
<line>
<bufferGeometry ref={lineRef} />
<lineBasicMaterial color={color} />
</line>
{curve && (
<Tube args={[curve, 20, 0.01, 8, true]} >
<meshBasicMaterial color={color} depthWrite={false} />
</Tube>
)}
</>
)}
</>
);
};
};

View File

@@ -200,7 +200,7 @@ function RoboticArmAnimator({ HandleCallback, restPosition, ikSolver, targetBone
}
}
} else if (prevModel && prevModel.type === 'storageUnit') {
const position = getMaterialPosition(currentMaterial);
const position = getMaterialPosition(prevModel.modelUuid, currentMaterial);
const armbotModel = scene.getObjectByProperty("uuid", armBot.modelUuid);
if (armbotModel) {

View File

@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from "react";
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 { useFrame, useThree } from "@react-three/fiber";
import { useSelectedEventSphere, useIsDragging, useIsRotating, } from "../../../../store/simulation/useSimulationStore";
@@ -17,8 +17,6 @@ import { useVersionContext } from "../../../builder/version/versionContext";
const VehicleUI = () => {
const { scene: startScene } = useGLTF(startPoint) 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 { selectedEventSphere } = useSelectedEventSphere();
const { selectedProductStore } = useProductContext();
@@ -163,7 +161,7 @@ const VehicleUI = () => {
let globalStartPosition = null;
let globalEndPosition = null;
if (outerGroup.current && startMarker.current && endMarker.current) {
if (outerGroup.current) {
const worldPosStart = new Vector3(...startPosition);
globalStartPosition = outerGroup.current.localToWorld(
worldPosStart.clone()
@@ -278,24 +276,19 @@ const VehicleUI = () => {
const currentPointerX = state.pointer.x;
const deltaX = currentPointerX - prevMousePos.current.x;
prevMousePos.current.x = currentPointerX;
const marker =
isRotating === "start" ? startMarker.current : endMarker.current;
if (marker) {
const rotationSpeed = 10;
marker.rotation.y += deltaX * rotationSpeed;
if (isRotating === "start") {
setStartRotation([
marker.rotation.x,
marker.rotation.y,
marker.rotation.z,
]);
} else {
setEndRotation([
marker.rotation.x,
marker.rotation.y,
marker.rotation.z,
]);
}
const rotationSpeed = 10;
if (isRotating === "start") {
setStartRotation([
startRotation[0],
startRotation[1] + deltaX * rotationSpeed,
startRotation[2],
]);
} else {
setEndRotation([
endRotation[0],
endRotation[1] + deltaX * rotationSpeed,
endRotation[2],
]);
}
});
@@ -362,7 +355,7 @@ const VehicleUI = () => {
position={endPosition}
rotation={endRotation}
outerGroupRef={outerGroup}
color="red"
color="orange"
handlePointerDown={handlePointerDown}
setIsDragging={setIsDragging}
setIsRotating={setIsRotating}
@@ -394,10 +387,10 @@ export const VehicleMarkerPrimitive = ({
setIsDragging: (val: any) => void;
setIsRotating: (val: any) => void;
}) => {
const { scene } = useThree();
const { scene, camera } = useThree();
const markerRef = useRef<THREE.Group>(null);
const lineRef = useRef<THREE.BufferGeometry>(null);
const [hitPoint, setHitPoint] = useState<THREE.Vector3 | null>(null);
const [curve, setCurve] = useState<THREE.CatmullRomCurve3 | null>(null);
useFrame(() => {
if (!markerRef.current || !outerGroupRef.current) return;
@@ -409,6 +402,7 @@ export const VehicleMarkerPrimitive = ({
const rayOrigin = worldPos.clone();
const direction = new THREE.Vector3(0, -1, 0);
const raycaster = new THREE.Raycaster(rayOrigin, direction, 0.1, 1000);
raycaster.camera = camera;
const intersects = raycaster.intersectObjects(scene.children, true);
const hit = intersects.find(i => i.object.name !== name);
@@ -416,16 +410,14 @@ export const VehicleMarkerPrimitive = ({
const localHit = outerGroupRef.current.worldToLocal(hit.point.clone());
setHitPoint(localHit);
if (lineRef.current) {
const positions = new Float32Array([
localMarkerPos.x, localMarkerPos.y, localMarkerPos.z,
localHit.x, localHit.y, localHit.z
]);
lineRef.current.setAttribute('position', new THREE.BufferAttribute(positions, 3));
lineRef.current.attributes.position.needsUpdate = true;
}
const newCurve = new THREE.CatmullRomCurve3([
localMarkerPos.clone(),
localHit.clone(),
]);
setCurve(newCurve);
} else {
setHitPoint(null);
setCurve(null);
}
});
@@ -437,7 +429,13 @@ export const VehicleMarkerPrimitive = ({
object={object}
position={position}
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={() => {
setIsDragging(null);
setIsRotating(null);
@@ -446,15 +444,20 @@ export const VehicleMarkerPrimitive = ({
{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]} />
<meshBasicMaterial color={color} transparent opacity={0.8} depthWrite={false} />
<meshBasicMaterial color={color} depthWrite={false} />
</mesh>
<line>
<bufferGeometry ref={lineRef} />
<lineBasicMaterial color={color} />
</line>
{curve && (
<Tube args={[curve, 20, 0.01, 8, true]}>
<meshBasicMaterial color={color} depthWrite={false} />
</Tube>
)}
</>
)}
</>

View File

@@ -20,7 +20,7 @@ const MaterialAnimator = ({
useEffect(() => {
if (!storageModel || storage.currentMaterials.length === 0) {
setMaterialPositions([]);
setMaterialPositions(storage.modelUuid, []);
return;
}
@@ -59,12 +59,12 @@ const MaterialAnimator = ({
};
});
setMaterialPositions(newMaterials);
}, [storageModel, storage.currentMaterials, setMaterialPositions]);
setMaterialPositions(storage.modelUuid, newMaterials);
}, [storageModel, storage.currentMaterials]);
return (
<group position={[0, -padding, 0]}>
{materialPositions.map(({ materialId, position }) => {
{(materialPositions[storage.modelUuid] || []).map(({ materialId, position }) => {
const mat = storage.currentMaterials.find((m) => m.materialId === materialId);
return (
<MaterialModel
@@ -78,6 +78,7 @@ const MaterialAnimator = ({
})}
</group>
);
};
export default MaterialAnimator;

View File

@@ -370,40 +370,18 @@ export function useTriggerHandler() {
}
}
} 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);
handleAction(action, materialId);
} else {
// Handle current action using Event Manager
setIsPaused(materialId, true);
setHumanScheduled(human.modelUuid, true);
addHumanToMonitor(human.modelUuid, () => {
handleAction(action, materialId)
}, 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,
})
setCurrentLocation(material.materialId, {
modelUuid: material.current.modelUuid,
pointUuid: material.current.pointUuid,
actionUuid: material.current.actionUuid,
});
setIsPaused(material.materialId, true);
setIsVisible(material.materialId, true);
@@ -1279,6 +1251,13 @@ export function useTriggerHandler() {
if (model?.type === 'roboticArm') {
addArmBotToMonitor(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 || '',
@@ -1288,6 +1267,13 @@ export function useTriggerHandler() {
})
} else if (model?.type === 'vehicle') {
addVehicleToMonitor(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 || '',
@@ -1296,6 +1282,13 @@ export function useTriggerHandler() {
setIsPaused(material.materialId, false);
})
} else if (model?.type === 'transfer') {
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 || '',
@@ -1303,15 +1296,48 @@ export function useTriggerHandler() {
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 || '',
})
if (fromEvent.modelUuid === model.modelUuid) {
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 {
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 || '',

View File

@@ -8,18 +8,21 @@ interface MaterialPosition {
position: THREE.Vector3;
}
type MaterialPositionsMap = Record<string, MaterialPosition[]>;
type MaterialsStore = {
materials: MaterialsSchema;
materialHistory: MaterialHistorySchema;
materialPositions: MaterialPosition[];
materialPositions: MaterialPositionsMap;
addMaterial: (material: MaterialSchema) => MaterialSchema | undefined;
removeMaterial: (materialId: string) => MaterialSchema | undefined;
clearMaterials: () => void;
updateMaterial: (materialId: string, updates: Partial<MaterialSchema>) => MaterialSchema | undefined;
setMaterialPositions: (materialPosition: MaterialPosition[]) => void;
getMaterialPosition: (materialId: string) => THREE.Vector3 | undefined;
setMaterialPositions: (modelUuid: string, materialPositions: MaterialPosition[]) => void;
getMaterialPosition: (modelUuid: string, materialId: string) => THREE.Vector3 | undefined;
setPreviousLocation: (
materialId: string,
@@ -72,7 +75,7 @@ export const createMaterialStore = () => {
immer((set, get) => ({
materials: [],
materialHistory: [],
materialPositions: [],
materialPositions: {},
addMaterial: (material) => {
let updatedMaterial: MaterialSchema | undefined;
@@ -274,21 +277,14 @@ export const createMaterialStore = () => {
return updatedMaterial;
},
setMaterialPositions: (materials) => {
setMaterialPositions: (modelUuid, positions) => {
set((state) => {
state.materialPositions = materials;
state.materialPositions[modelUuid] = positions;
});
},
getMaterialPosition: (materialid) => {
let position: THREE.Vector3 | undefined;
set((state) => {
const material = state.materialPositions.find(m => m.materialId === materialid);
if (material) {
position = material.position;
}
});
return position;
getMaterialPosition: (modelUuid, materialId) => {
return get().materialPositions[modelUuid]?.find(p => p.materialId === materialId)?.position;
},
getMaterialById: (materialId) => {