diff --git a/app/src/modules/builder/asset/models/model/model.tsx b/app/src/modules/builder/asset/models/model/model.tsx index fa9b2fd..2b5df51 100644 --- a/app/src/modules/builder/asset/models/model/model.tsx +++ b/app/src/modules/builder/asset/models/model/model.tsx @@ -18,10 +18,13 @@ import { useVersionContext } from '../../../version/versionContext'; import { SkeletonUtils } from 'three-stdlib'; import { useAnimationPlaySpeed } from '../../../../../store/usePlayButtonStore'; import { upsertProductOrEventApi } from '../../../../../services/simulation/products/UpsertProductOrEventApi'; +import { getAssetIksApi } from '../../../../../services/simulation/ik/getAssetIKs'; function Model({ asset }: { readonly asset: Asset }) { + const url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`; const { camera, controls, gl } = useThree(); const { activeTool } = useActiveTool(); + const { toolMode } = useToolMode(); const { toggleView } = useToggleView(); const { subModule } = useSubModuleStore(); const { activeModule } = useModuleStore(); @@ -40,25 +43,24 @@ function Model({ asset }: { readonly asset: Asset }) { const { selectedFloorItem, setSelectedFloorItem } = useSelectedFloorItem(); const { limitDistance } = useLimitDistance(); const { renderDistance } = useRenderDistance(); - const [isRendered, setIsRendered] = useState(false); - const url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`; - const [gltfScene, setGltfScene] = useState(null); - const [boundingBox, setBoundingBox] = useState(null); - const groupRef = useRef(null); - const { toolMode } = useToolMode(); const leftDrag = useRef(false); const isLeftMouseDown = useRef(false); const rightDrag = useRef(false); const isRightMouseDown = useRef(false); - const { selectedVersionStore } = useVersionContext(); - const { selectedVersion } = selectedVersionStore(); - const { projectId } = useParams(); - const { userId, organization } = getUserData(); + const [isRendered, setIsRendered] = useState(false); + const [gltfScene, setGltfScene] = useState(null); + const [boundingBox, setBoundingBox] = useState(null); + const groupRef = useRef(null); const mixerRef = useRef(); const actions = useRef<{ [name: string]: THREE.AnimationAction }>({}); const [previousAnimation, setPreviousAnimation] = useState(null); + const [ikData, setIkData] = useState(); const blendFactor = useRef(0); const blendDuration = 0.5; + const { selectedVersionStore } = useVersionContext(); + const { selectedVersion } = selectedVersionStore(); + const { userId, organization } = getUserData(); + const { projectId } = useParams(); const updateBackend = ( productName: string, @@ -75,6 +77,16 @@ function Model({ asset }: { readonly asset: Asset }) { }); }; + useEffect(() => { + if (!ikData && asset.eventData && asset.eventData.type === 'ArmBot') { + getAssetIksApi(asset.assetId).then((data) => { + if (data.iks) { + setIkData(data.iks); + } + }) + } + }, [asset.modelUuid, ikData]) + useEffect(() => { setDeletableFloorItem(null); if (selectedFloorItem === null || selectedFloorItem.userData.modelUuid !== asset.modelUuid) { diff --git a/app/src/modules/simulation/human/eventManager/useHumanEventManager.ts b/app/src/modules/simulation/human/eventManager/useHumanEventManager.ts index 94ce8b3..4851c1c 100644 --- a/app/src/modules/simulation/human/eventManager/useHumanEventManager.ts +++ b/app/src/modules/simulation/human/eventManager/useHumanEventManager.ts @@ -54,9 +54,16 @@ export function useHumanEventManager() { callbacksRef.current.forEach(({ humanId, callback }) => { const human = getHumanById(humanId); - if (human && human.isActive === false && human.state === 'idle' && human.isPicking && human.currentLoad < human.point.action.loadCapacity) { - callback(); - removeHumanFromMonitor(humanId); // Remove after triggering + if (human?.point.action.actionType === 'worker') { + if (human && human.isActive === false && human.state === 'idle' && human.isPicking && human.currentLoad < human.point.action.loadCapacity) { + callback(); + removeHumanFromMonitor(humanId); // Remove after triggering + } + } else if (human?.point.action.actionType === 'assembly') { + if (human && human.isActive === false && human.state === 'idle') { + callback(); + removeHumanFromMonitor(humanId); // Remove after triggering + } } }); }); diff --git a/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx b/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx index db8cda2..b41bef8 100644 --- a/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx +++ b/app/src/modules/simulation/roboticArm/instances/armInstance/roboticArmInstance.tsx @@ -212,7 +212,6 @@ function RoboticArmInstance({ armBot }: { readonly armBot: ArmBotStatus }) { } }, [isReset, isPlaying]) - function animate(currentTime: number) { if (previousTimeRef.current === null) { previousTimeRef.current = currentTime; diff --git a/app/src/services/simulation/ik/getAssetIKs.ts b/app/src/services/simulation/ik/getAssetIKs.ts new file mode 100644 index 0000000..cfc6ad5 --- /dev/null +++ b/app/src/services/simulation/ik/getAssetIKs.ts @@ -0,0 +1,36 @@ +let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`; + +export const getAssetIksApi = async (assetId: string) => { + try { + const response = await fetch( + `${url_Backend_dwinzo}/api/v2/getAssetIks/${assetId}`, + { + method: "GET", + headers: { + Authorization: "Bearer ", + "Content-Type": "application/json", + token: localStorage.getItem("token") || "", + refresh_token: localStorage.getItem("refreshToken") || "", + }, + } + ); + const newAccessToken = response.headers.get("x-access-token"); + if (newAccessToken) { + localStorage.setItem("token", newAccessToken); + } + + if (!response.ok) { + console.error("Failed to fetch assetIks"); + } + + const result = await response.json(); + return result; + } catch (error) { + echo.error("Failed to get assetIks"); + if (error instanceof Error) { + console.log(error.message); + } else { + console.log("An unknown error occurred"); + } + } +};