robotic arm and storage unit bug fix

This commit is contained in:
2025-09-09 17:06:10 +05:30
parent 5482e185cd
commit 6e5f00657d
4 changed files with 30 additions and 16 deletions

View File

@@ -73,7 +73,7 @@ export function useRetrieveHandler() {
if (isPlaying && !initialDelayComplete) {
delayTimerRef.current = setTimeout(() => {
setInitialDelayComplete(true);
}, 3000);
}, 100);
}
return () => {

View File

@@ -26,6 +26,7 @@ function RoboticArmAnimator({ HandleCallback, restPosition, ikSolver, targetBone
const totalDistanceRef = useRef(0);
const startTimeRef = useRef<number | null>(null);
const segmentDistancesRef = useRef<number[]>([]);
const clockRef = useRef(new THREE.Clock());
const [currentPath, setCurrentPath] = useState<[number, number, number][]>([]);
const [circlePoints, setCirclePoints] = useState<[number, number, number][]>([]);
const [circlePointsWithDegrees, setCirclePointsWithDegrees] = useState<PointWithDegree[]>([]);
@@ -72,7 +73,7 @@ function RoboticArmAnimator({ HandleCallback, restPosition, ikSolver, targetBone
bone.position.copy(restPosition);
ikSolver.update();
}
}, [isReset, isPlaying]);
}, [isReset, isPlaying, ikSolver]);
//Generate Circle Points
function generateRingPoints(radius: any, segments: any) {
@@ -156,7 +157,7 @@ function RoboticArmAnimator({ HandleCallback, restPosition, ikSolver, targetBone
// Handle nearest points and final path (including arc points)
useEffect(() => {
if (circlePoints.length > 0 && currentPath.length > 0 && ikSolver.mesh) {
if (ikSolver && circlePoints.length > 0 && currentPath.length > 0 && ikSolver.mesh) {
let start = currentPath[0];
let end = currentPath[currentPath.length - 1];
const bone = ikSolver.mesh.skeleton.bones.find((b: any) => b.name === targetBone);
@@ -171,7 +172,11 @@ function RoboticArmAnimator({ HandleCallback, restPosition, ikSolver, targetBone
const triggeringModel = getTriggeringModels(selectedProduct.productUuid, currentAction.actionUuid);
const prevModel = triggeringModel[0] || null;
const nextModel = getEventByModelUuid(selectedProduct.productUuid, currentAction?.triggers[0]?.triggeredAsset?.triggeredModel?.modelUuid || "");
const nextPoint = getPointByUuid(selectedProduct.productUuid, currentAction?.triggers[0]?.triggeredAsset?.triggeredModel?.modelUuid || "", currentAction?.triggers[0]?.triggeredAsset?.triggeredPoint?.pointUuid || "");
const nextPoint = getPointByUuid(
selectedProduct.productUuid,
currentAction?.triggers[0]?.triggeredAsset?.triggeredModel?.modelUuid || "",
currentAction?.triggers[0]?.triggeredAsset?.triggeredPoint?.pointUuid || ""
);
if (prevModel && prevModel.type === "transfer") {
const material = scene.getObjectByProperty("uuid", currentMaterial);
@@ -280,7 +285,15 @@ function RoboticArmAnimator({ HandleCallback, restPosition, ikSolver, targetBone
arcPoints = arcCounterClockwise;
}
const pathVectors = [new THREE.Vector3(start[0], start[1], start[2]), new THREE.Vector3(start[0], curveHeight, start[2]), new THREE.Vector3(nearestToStart[0], curveHeight, nearestToStart[2]), ...arcPoints.map((point) => new THREE.Vector3(point[0], curveHeight, point[2])), new THREE.Vector3(nearestToEnd[0], curveHeight, nearestToEnd[2]), new THREE.Vector3(end[0], curveHeight, end[2]), new THREE.Vector3(end[0], end[1], end[2])];
const pathVectors = [
new THREE.Vector3(start[0], start[1], start[2]),
new THREE.Vector3(start[0], curveHeight, start[2]),
new THREE.Vector3(nearestToStart[0], curveHeight, nearestToStart[2]),
...arcPoints.map((point) => new THREE.Vector3(point[0], curveHeight, point[2])),
new THREE.Vector3(nearestToEnd[0], curveHeight, nearestToEnd[2]),
new THREE.Vector3(end[0], curveHeight, end[2]),
new THREE.Vector3(end[0], end[1], end[2]),
];
const pathSegments: [THREE.Vector3, THREE.Vector3][] = [];
for (let i = 0; i < pathVectors.length - 1; i++) {
@@ -297,8 +310,9 @@ function RoboticArmAnimator({ HandleCallback, restPosition, ikSolver, targetBone
}, [circlePoints, currentPath]);
// Frame update for animation
useFrame((_, delta) => {
useFrame(() => {
if (!ikSolver) return;
const delta = clockRef.current.getDelta();
const bone = ikSolver.mesh.skeleton.bones.find((b: any) => b.name === targetBone);

View File

@@ -109,6 +109,7 @@ function RoboticArmInstance({ armBot }: { readonly armBot: ArmBotStatus }) {
useEffect(() => {
if (isReset || !isPlaying) {
console.log('hii');
logStatus(armBot.modelUuid, "Simulation Play Reset Successfully");
setArmBotActive(armBot.modelUuid, false);
setArmBotState(armBot.modelUuid, "idle");

View File

@@ -1,11 +1,11 @@
import { useEffect } from 'react'
import { useEffect } from "react";
import * as THREE from "three";
import { useThree } from "@react-three/fiber";
import { CCDIKSolver, CCDIKHelper } from "three/examples/jsm/animation/CCDIKSolver";
import { usePlayButtonStore, useResetButtonStore } from '../../../../../store/ui/usePlayButtonStore';
import { usePlayButtonStore, useResetButtonStore } from "../../../../../store/ui/usePlayButtonStore";
type IKInstanceProps = {
setIkSolver: any
setIkSolver: any;
armBot: ArmBotStatus;
};
@@ -58,17 +58,16 @@ function IKInstance({ setIkSolver, armBot }: Readonly<IKInstanceProps>) {
// scene.add(helper);
};
trySetup();
setTimeout(() => {
trySetup();
}, 100);
return () => {
if (retryId) clearTimeout(retryId);
};
}, [isPlaying, isReset]);
}, [isPlaying, isReset, armBot.modelUuid]);
return (
<>
</>
)
return <></>;
}
export default IKInstance;
export default IKInstance;