|
|
|
|
@@ -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);
|
|
|
|
|
|
|
|
|
|
|