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