feat: Add getAssetIksApi service for fetching asset IKs and update Model component to utilize it
This commit is contained in:
@@ -18,10 +18,13 @@ import { useVersionContext } from '../../../version/versionContext';
|
|||||||
import { SkeletonUtils } from 'three-stdlib';
|
import { SkeletonUtils } from 'three-stdlib';
|
||||||
import { useAnimationPlaySpeed } from '../../../../../store/usePlayButtonStore';
|
import { useAnimationPlaySpeed } from '../../../../../store/usePlayButtonStore';
|
||||||
import { upsertProductOrEventApi } from '../../../../../services/simulation/products/UpsertProductOrEventApi';
|
import { upsertProductOrEventApi } from '../../../../../services/simulation/products/UpsertProductOrEventApi';
|
||||||
|
import { getAssetIksApi } from '../../../../../services/simulation/ik/getAssetIKs';
|
||||||
|
|
||||||
function Model({ asset }: { readonly asset: Asset }) {
|
function Model({ asset }: { readonly asset: Asset }) {
|
||||||
|
const url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`;
|
||||||
const { camera, controls, gl } = useThree();
|
const { camera, controls, gl } = useThree();
|
||||||
const { activeTool } = useActiveTool();
|
const { activeTool } = useActiveTool();
|
||||||
|
const { toolMode } = useToolMode();
|
||||||
const { toggleView } = useToggleView();
|
const { toggleView } = useToggleView();
|
||||||
const { subModule } = useSubModuleStore();
|
const { subModule } = useSubModuleStore();
|
||||||
const { activeModule } = useModuleStore();
|
const { activeModule } = useModuleStore();
|
||||||
@@ -40,25 +43,24 @@ function Model({ asset }: { readonly asset: Asset }) {
|
|||||||
const { selectedFloorItem, setSelectedFloorItem } = useSelectedFloorItem();
|
const { selectedFloorItem, setSelectedFloorItem } = useSelectedFloorItem();
|
||||||
const { limitDistance } = useLimitDistance();
|
const { limitDistance } = useLimitDistance();
|
||||||
const { renderDistance } = useRenderDistance();
|
const { renderDistance } = useRenderDistance();
|
||||||
const [isRendered, setIsRendered] = useState(false);
|
|
||||||
const url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`;
|
|
||||||
const [gltfScene, setGltfScene] = useState<GLTF["scene"] | null>(null);
|
|
||||||
const [boundingBox, setBoundingBox] = useState<THREE.Box3 | null>(null);
|
|
||||||
const groupRef = useRef<THREE.Group>(null);
|
|
||||||
const { toolMode } = useToolMode();
|
|
||||||
const leftDrag = useRef(false);
|
const leftDrag = useRef(false);
|
||||||
const isLeftMouseDown = useRef(false);
|
const isLeftMouseDown = useRef(false);
|
||||||
const rightDrag = useRef(false);
|
const rightDrag = useRef(false);
|
||||||
const isRightMouseDown = useRef(false);
|
const isRightMouseDown = useRef(false);
|
||||||
const { selectedVersionStore } = useVersionContext();
|
const [isRendered, setIsRendered] = useState(false);
|
||||||
const { selectedVersion } = selectedVersionStore();
|
const [gltfScene, setGltfScene] = useState<GLTF["scene"] | null>(null);
|
||||||
const { projectId } = useParams();
|
const [boundingBox, setBoundingBox] = useState<THREE.Box3 | null>(null);
|
||||||
const { userId, organization } = getUserData();
|
const groupRef = useRef<THREE.Group>(null);
|
||||||
const mixerRef = useRef<THREE.AnimationMixer>();
|
const mixerRef = useRef<THREE.AnimationMixer>();
|
||||||
const actions = useRef<{ [name: string]: THREE.AnimationAction }>({});
|
const actions = useRef<{ [name: string]: THREE.AnimationAction }>({});
|
||||||
const [previousAnimation, setPreviousAnimation] = useState<string | null>(null);
|
const [previousAnimation, setPreviousAnimation] = useState<string | null>(null);
|
||||||
|
const [ikData, setIkData] = useState<any>();
|
||||||
const blendFactor = useRef(0);
|
const blendFactor = useRef(0);
|
||||||
const blendDuration = 0.5;
|
const blendDuration = 0.5;
|
||||||
|
const { selectedVersionStore } = useVersionContext();
|
||||||
|
const { selectedVersion } = selectedVersionStore();
|
||||||
|
const { userId, organization } = getUserData();
|
||||||
|
const { projectId } = useParams();
|
||||||
|
|
||||||
const updateBackend = (
|
const updateBackend = (
|
||||||
productName: string,
|
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(() => {
|
useEffect(() => {
|
||||||
setDeletableFloorItem(null);
|
setDeletableFloorItem(null);
|
||||||
if (selectedFloorItem === null || selectedFloorItem.userData.modelUuid !== asset.modelUuid) {
|
if (selectedFloorItem === null || selectedFloorItem.userData.modelUuid !== asset.modelUuid) {
|
||||||
|
|||||||
@@ -54,10 +54,17 @@ export function useHumanEventManager() {
|
|||||||
|
|
||||||
callbacksRef.current.forEach(({ humanId, callback }) => {
|
callbacksRef.current.forEach(({ humanId, callback }) => {
|
||||||
const human = getHumanById(humanId);
|
const human = getHumanById(humanId);
|
||||||
|
if (human?.point.action.actionType === 'worker') {
|
||||||
if (human && human.isActive === false && human.state === 'idle' && human.isPicking && human.currentLoad < human.point.action.loadCapacity) {
|
if (human && human.isActive === false && human.state === 'idle' && human.isPicking && human.currentLoad < human.point.action.loadCapacity) {
|
||||||
callback();
|
callback();
|
||||||
removeHumanFromMonitor(humanId); // Remove after triggering
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,6 @@ function RoboticArmInstance({ armBot }: { readonly armBot: ArmBotStatus }) {
|
|||||||
}
|
}
|
||||||
}, [isReset, isPlaying])
|
}, [isReset, isPlaying])
|
||||||
|
|
||||||
|
|
||||||
function animate(currentTime: number) {
|
function animate(currentTime: number) {
|
||||||
if (previousTimeRef.current === null) {
|
if (previousTimeRef.current === null) {
|
||||||
previousTimeRef.current = currentTime;
|
previousTimeRef.current = currentTime;
|
||||||
|
|||||||
36
app/src/services/simulation/ik/getAssetIKs.ts
Normal file
36
app/src/services/simulation/ik/getAssetIKs.ts
Normal file
@@ -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 <access_token>",
|
||||||
|
"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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user