multiple action state updated
This commit is contained in:
parent
39c86b6fc1
commit
0e4005f31e
|
@ -31,8 +31,6 @@ function PointsCreator() {
|
||||||
selectedEventSphere.userData.modelUuid
|
selectedEventSphere.userData.modelUuid
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (eventData) {
|
if (eventData) {
|
||||||
setSelectedEventData(eventData, selectedEventSphere.userData.pointUuid);
|
setSelectedEventData(eventData, selectedEventSphere.userData.pointUuid);
|
||||||
} else {
|
} else {
|
||||||
|
@ -215,7 +213,6 @@ function PointsCreator() {
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
onPointerMissed={() => {
|
onPointerMissed={() => {
|
||||||
// clearSelectedEventSphere();
|
|
||||||
setTransformMode(null);
|
setTransformMode(null);
|
||||||
}}
|
}}
|
||||||
position={new THREE.Vector3(...event.point.position)}
|
position={new THREE.Vector3(...event.point.position)}
|
||||||
|
|
|
@ -55,11 +55,9 @@ function RoboticArmAnimator({
|
||||||
for (let i = 0; i < segments; i++) {
|
for (let i = 0; i < segments; i++) {
|
||||||
// Calculate angle for current segment
|
// Calculate angle for current segment
|
||||||
const angle = (i / segments) * Math.PI * 2;
|
const angle = (i / segments) * Math.PI * 2;
|
||||||
|
|
||||||
// Calculate x and z coordinates (y remains the same for a flat ring)
|
// Calculate x and z coordinates (y remains the same for a flat ring)
|
||||||
const x = Math.cos(angle) * radius;
|
const x = Math.cos(angle) * radius;
|
||||||
const z = Math.sin(angle) * radius;
|
const z = Math.sin(angle) * radius;
|
||||||
|
|
||||||
points.push([x, 1.5, z]);
|
points.push([x, 1.5, z]);
|
||||||
}
|
}
|
||||||
return points;
|
return points;
|
||||||
|
|
|
@ -8,7 +8,9 @@ import { useThree } from "@react-three/fiber";
|
||||||
import { useFloorItems } from '../../../../../store/store';
|
import { useFloorItems } from '../../../../../store/store';
|
||||||
import useModuleStore from '../../../../../store/useModuleStore';
|
import useModuleStore from '../../../../../store/useModuleStore';
|
||||||
import * as THREE from "three";
|
import * as THREE from "three";
|
||||||
import { useSelectedAction } from '../../../../../store/simulation/useSimulationStore';
|
import { useSelectedAction, useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
|
||||||
|
import { useProductStore } from '../../../../../store/simulation/useProductStore';
|
||||||
|
|
||||||
|
|
||||||
function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
|
|
||||||
|
@ -24,6 +26,8 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
let startTime: number;
|
let startTime: number;
|
||||||
//zustand
|
//zustand
|
||||||
const { addCurrentAction, setArmBotActive, setArmBotState, removeCurrentAction } = useArmBotStore();
|
const { addCurrentAction, setArmBotActive, setArmBotState, removeCurrentAction } = useArmBotStore();
|
||||||
|
const { products, getActionByUuid } = useProductStore();
|
||||||
|
const { selectedProduct } = useSelectedProduct();
|
||||||
const { floorItems } = useFloorItems();
|
const { floorItems } = useFloorItems();
|
||||||
const { activeModule } = useModuleStore();
|
const { activeModule } = useModuleStore();
|
||||||
const { isPlaying } = usePlayButtonStore();
|
const { isPlaying } = usePlayButtonStore();
|
||||||
|
@ -54,12 +58,12 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
requestAnimationFrame(step);
|
requestAnimationFrame(step);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(currentPhase==="picking"){
|
if (currentPhase === "picking") {
|
||||||
|
|
||||||
setArmBotActive(armBot.modelUuid, true);
|
setArmBotActive(armBot.modelUuid, true);
|
||||||
setArmBotState(armBot.modelUuid, "running");
|
setArmBotState(armBot.modelUuid, "running");
|
||||||
setCurrentPhase("start-to-end");
|
setCurrentPhase("start-to-end");
|
||||||
startTime=0
|
startTime = 0
|
||||||
const startPoint = armBot.point.actions[0].process.startPoint;
|
const startPoint = armBot.point.actions[0].process.startPoint;
|
||||||
const endPoint = armBot.point.actions[0].process.endPoint;
|
const endPoint = armBot.point.actions[0].process.endPoint;
|
||||||
if (startPoint && endPoint) {
|
if (startPoint && endPoint) {
|
||||||
|
@ -72,12 +76,12 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logStatus(armBot.modelUuid, "Moving armBot from start point to end position.")
|
logStatus(armBot.modelUuid, "Moving armBot from start point to end position.")
|
||||||
}else if(currentPhase==="dropping"){
|
} else if (currentPhase === "dropping") {
|
||||||
|
|
||||||
setArmBotActive(armBot.modelUuid, true);
|
setArmBotActive(armBot.modelUuid, true);
|
||||||
setArmBotState(armBot.modelUuid, "running");
|
setArmBotState(armBot.modelUuid, "running");
|
||||||
setCurrentPhase("end-to-rest");
|
setCurrentPhase("end-to-rest");
|
||||||
startTime=0;
|
startTime = 0;
|
||||||
const endPoint = armBot.point.actions[0].process.endPoint;
|
const endPoint = armBot.point.actions[0].process.endPoint;
|
||||||
if (endPoint) {
|
if (endPoint) {
|
||||||
|
|
||||||
|
@ -112,12 +116,12 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
setArmBotActive(armBot.modelUuid, true)
|
setArmBotActive(armBot.modelUuid, true)
|
||||||
setArmBotState(armBot.modelUuid, "running")
|
setArmBotState(armBot.modelUuid, "running")
|
||||||
setCurrentPhase("init-to-rest");
|
setCurrentPhase("init-to-rest");
|
||||||
isPausedRef.current=false
|
isPausedRef.current = false
|
||||||
pauseTimeRef.current=null
|
pauseTimeRef.current = null
|
||||||
isPausedRef.current=false
|
isPausedRef.current = false
|
||||||
startTime=0
|
startTime = 0
|
||||||
if (targetBones) {
|
if (targetBones) {
|
||||||
let curve = createCurveBetweenTwoPoints(targetBones.position, restPosition)
|
let curve = createCurveBetweenTwoPoints(targetBones.position, targetBones.position)
|
||||||
if (curve) {
|
if (curve) {
|
||||||
setPath(curve.points.map(point => [point.x, point.y, point.z]));
|
setPath(curve.points.map(point => [point.x, point.y, point.z]));
|
||||||
}
|
}
|
||||||
|
@ -145,9 +149,8 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
else if (armBot && !armBot.isActive && armBot.state === "idle" && currentPhase === "rest" && !armBot.currentAction) {
|
else if (armBot && !armBot.isActive && armBot.state === "idle" && currentPhase === "rest" && !armBot.currentAction) {
|
||||||
logStatus(armBot.modelUuid, "Waiting to trigger CurrentAction")
|
logStatus(armBot.modelUuid, "Waiting to trigger CurrentAction")
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
let actionId=armBot.point.actions[0].actionUuid
|
addCurrentAction(armBot.modelUuid, selectedAction?.actionId);
|
||||||
addCurrentAction(armBot.modelUuid,actionId);
|
console.log('selectedAction?.actionId: ', selectedAction?.actionId);
|
||||||
// addCurrentAction(armBot.modelUuid, selectedAction?.actionId);
|
|
||||||
}, 3000);
|
}, 3000);
|
||||||
return () => clearTimeout(timeoutId);
|
return () => clearTimeout(timeoutId);
|
||||||
}
|
}
|
||||||
|
@ -157,6 +160,8 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
setArmBotActive(armBot.modelUuid, true);
|
setArmBotActive(armBot.modelUuid, true);
|
||||||
setArmBotState(armBot.modelUuid, "running");
|
setArmBotState(armBot.modelUuid, "running");
|
||||||
setCurrentPhase("rest-to-start");
|
setCurrentPhase("rest-to-start");
|
||||||
|
let actiondata = getActionByUuid(selectedProduct.productId, selectedAction.actionId)
|
||||||
|
console.log('actiondata: ', actiondata);
|
||||||
const startPoint = armBot.point.actions[0].process.startPoint;
|
const startPoint = armBot.point.actions[0].process.startPoint;
|
||||||
if (startPoint) {
|
if (startPoint) {
|
||||||
let curve = createCurveBetweenTwoPoints(restPosition, new THREE.Vector3(startPoint[0], startPoint[1], startPoint[2]));
|
let curve = createCurveBetweenTwoPoints(restPosition, new THREE.Vector3(startPoint[0], startPoint[1], startPoint[2]));
|
||||||
|
@ -265,7 +270,7 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
||||||
<>
|
<>
|
||||||
<IKInstance modelUrl={armModel} setIkSolver={setIkSolver} ikSolver={ikSolver} armBot={armBot} groupRef={groupRef} />
|
<IKInstance modelUrl={armModel} setIkSolver={setIkSolver} ikSolver={ikSolver} armBot={armBot} groupRef={groupRef} />
|
||||||
<RoboticArmAnimator HandleCallback={HandleCallback} restPosition={restPosition} ikSolver={ikSolver} targetBone={targetBone} armBot={armBot}
|
<RoboticArmAnimator HandleCallback={HandleCallback} restPosition={restPosition} ikSolver={ikSolver} targetBone={targetBone} armBot={armBot}
|
||||||
logStatus={logStatus} path={path}currentPhase={currentPhase} />
|
logStatus={logStatus} path={path} currentPhase={currentPhase} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,6 @@ function RoboticArm() {
|
||||||
}, [selectedProduct, products]);
|
}, [selectedProduct, products]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
}, [armBots])
|
}, [armBots])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -24,10 +24,7 @@ const PickDropPoints: React.FC<PickDropProps> = ({
|
||||||
handlePointerDown,
|
handlePointerDown,
|
||||||
isSelected,
|
isSelected,
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
|
|
||||||
const groupRef = useRef<THREE.Group>(null);
|
const groupRef = useRef<THREE.Group>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<group
|
<group
|
||||||
ref={groupRef}
|
ref={groupRef}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { useSelectedEventData, useSelectedEventSphere, useSelectedProduct } from '../../../../store/simulation/useSimulationStore';
|
import { useSelectedAction, useSelectedEventData, useSelectedEventSphere, useSelectedProduct } from '../../../../store/simulation/useSimulationStore';
|
||||||
import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
|
import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
|
||||||
import { useGLTF } from '@react-three/drei';
|
import { useGLTF } from '@react-three/drei';
|
||||||
import { useThree } from '@react-three/fiber';
|
import { useThree } from '@react-three/fiber';
|
||||||
|
@ -24,6 +24,7 @@ const ArmBotUI = () => {
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
const { armBots, updateStartPoint, updateEndPoint } = useArmBotStore();
|
const { armBots, updateStartPoint, updateEndPoint } = useArmBotStore();
|
||||||
const { scene } = useThree();
|
const { scene } = useThree();
|
||||||
|
const { selectedAction } = useSelectedAction();
|
||||||
|
|
||||||
const armUiPick = useGLTF(armPick) as any;
|
const armUiPick = useGLTF(armPick) as any;
|
||||||
const armUiDrop = useGLTF(armDrop) as any;
|
const armUiDrop = useGLTF(armDrop) as any;
|
||||||
|
@ -37,32 +38,29 @@ const ArmBotUI = () => {
|
||||||
if (selectedEventData?.data.type === "roboticArm") {
|
if (selectedEventData?.data.type === "roboticArm") {
|
||||||
const selectedArmBot = getEventByModelUuid(selectedProduct.productId, selectedEventData.data.modelUuid);
|
const selectedArmBot = getEventByModelUuid(selectedProduct.productId, selectedEventData.data.modelUuid);
|
||||||
|
|
||||||
if (selectedArmBot) {
|
if (selectedArmBot?.type === "roboticArm") {
|
||||||
if (selectedArmBot.type === "roboticArm") {
|
|
||||||
|
|
||||||
setSelectedArmBotData(selectedArmBot);
|
setSelectedArmBotData(selectedArmBot);
|
||||||
|
|
||||||
const defaultPositions = getDefaultPositions(selectedArmBot.modelUuid);
|
const defaultPositions = getDefaultPositions(selectedArmBot.modelUuid);
|
||||||
|
const matchingAction = armBots?.flatMap((robot: ArmBotStatus) => robot.point.actions)
|
||||||
selectedArmBot?.point?.actions?.forEach((action: any) => {
|
.find((action) => action.actionUuid === selectedAction.actionId);
|
||||||
if (action.actionType === "pickAndPlace") {
|
if (matchingAction) {
|
||||||
const startPoint = action.process.startPoint;
|
const startPoint = matchingAction.process.startPoint;
|
||||||
const pickPosition = (!startPoint || (Array.isArray(startPoint) && startPoint.every(v => v === 0)))
|
const pickPosition = (!startPoint || (Array.isArray(startPoint) && startPoint.every(v => v === 0)))
|
||||||
? defaultPositions.pick
|
? defaultPositions.pick
|
||||||
: startPoint;
|
: startPoint;
|
||||||
const endPoint = action.process.endPoint;
|
|
||||||
|
const endPoint = matchingAction.process.endPoint;
|
||||||
const dropPosition = (!endPoint || (Array.isArray(endPoint) && endPoint.every(v => v === 0)))
|
const dropPosition = (!endPoint || (Array.isArray(endPoint) && endPoint.every(v => v === 0)))
|
||||||
? defaultPositions.drop
|
? defaultPositions.drop
|
||||||
: endPoint;
|
: endPoint;
|
||||||
setStartPosition(pickPosition);
|
|
||||||
setEndPosition(dropPosition)
|
|
||||||
|
|
||||||
}
|
setStartPosition(pickPosition);
|
||||||
});
|
setEndPosition(dropPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [selectedEventData, selectedProduct, getEventByModelUuid]);
|
}, [selectedEventData, selectedProduct, getEventByModelUuid, selectedAction]);
|
||||||
|
|
||||||
|
|
||||||
function getDefaultPositions(modelUuid: string): Positions {
|
function getDefaultPositions(modelUuid: string): Positions {
|
||||||
const modelData = getEventByModelUuid(selectedProduct.productId, modelUuid);
|
const modelData = getEventByModelUuid(selectedProduct.productId, modelUuid);
|
||||||
|
@ -72,8 +70,8 @@ const ArmBotUI = () => {
|
||||||
const baseY = modelData.point.position?.[1] || 0;;
|
const baseY = modelData.point.position?.[1] || 0;;
|
||||||
const baseZ = modelData.point.position?.[2] || 0;
|
const baseZ = modelData.point.position?.[2] || 0;
|
||||||
return {
|
return {
|
||||||
pick: [baseX, baseY , baseZ + 0.5],
|
pick: [baseX, baseY, baseZ + 0.5],
|
||||||
drop: [baseX, baseY , baseZ - 0.5],
|
drop: [baseX, baseY, baseZ - 0.5],
|
||||||
default: [baseX, baseY, baseZ],
|
default: [baseX, baseY, baseZ],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -118,13 +116,10 @@ const ArmBotUI = () => {
|
||||||
|
|
||||||
if (actionType === "pick") {
|
if (actionType === "pick") {
|
||||||
updatedProcess.startPoint = getLocalPosition(modelUuid, worldPositionArray);
|
updatedProcess.startPoint = getLocalPosition(modelUuid, worldPositionArray);
|
||||||
// updatedProcess.startPoint = worldPositionArray
|
|
||||||
setStartPosition(updatedProcess.startPoint)
|
setStartPosition(updatedProcess.startPoint)
|
||||||
|
|
||||||
updateStartPoint(modelUuid, actionUuid, updatedProcess.startPoint);
|
updateStartPoint(modelUuid, actionUuid, updatedProcess.startPoint);
|
||||||
} else if (actionType === "drop") {
|
} else if (actionType === "drop") {
|
||||||
updatedProcess.endPoint = getLocalPosition(modelUuid, worldPositionArray);
|
updatedProcess.endPoint = getLocalPosition(modelUuid, worldPositionArray);
|
||||||
// updatedProcess.endPoint = worldPositionArray
|
|
||||||
setEndPosition(updatedProcess.endPoint)
|
setEndPosition(updatedProcess.endPoint)
|
||||||
updateEndPoint(modelUuid, actionUuid, updatedProcess.endPoint);
|
updateEndPoint(modelUuid, actionUuid, updatedProcess.endPoint);
|
||||||
}
|
}
|
||||||
|
@ -143,17 +138,18 @@ const ArmBotUI = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
|
|
||||||
}, [armBots])
|
}, [armBots])
|
||||||
|
|
||||||
const { handlePointerDown } = useDraggableGLTF(updatePointToState);
|
const { handlePointerDown } = useDraggableGLTF(updatePointToState);
|
||||||
|
|
||||||
if (!selectedArmBotData || !Array.isArray(selectedArmBotData.point?.actions)) {
|
if (!selectedArmBotData || !Array.isArray(selectedArmBotData.point?.actions)) {
|
||||||
return null; // avoid rendering if no data yet
|
return null; // avoid rendering if no data yet
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{selectedArmBotData.point.actions.map((action: any) => (
|
{selectedArmBotData.point.actions.map((action: any) => {
|
||||||
|
if (action.actionUuid === selectedAction.actionId) {
|
||||||
|
return (
|
||||||
<React.Fragment key={action.actionUuid}>
|
<React.Fragment key={action.actionUuid}>
|
||||||
<group
|
<group
|
||||||
position={new THREE.Vector3(...selectedArmBotData.position)}
|
position={new THREE.Vector3(...selectedArmBotData.position)}
|
||||||
|
@ -181,9 +177,14 @@ const ArmBotUI = () => {
|
||||||
/>
|
/>
|
||||||
</group>
|
</group>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))}
|
);
|
||||||
|
} else {
|
||||||
|
return null; // important! must return something
|
||||||
|
}
|
||||||
|
})}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ArmBotUI;
|
export default ArmBotUI;
|
||||||
|
|
Loading…
Reference in New Issue