reset function updated

This commit is contained in:
Gomathi 2025-05-05 11:25:06 +05:30
parent f888c2798c
commit be8f937759
4 changed files with 264 additions and 238 deletions

View File

@ -38,9 +38,17 @@ const SimulationPlayer: React.FC = () => {
const { isReset, setReset } = useResetButtonStore();
const { subModule } = useSubModuleStore();
useEffect(() => {
if (isReset) {
setTimeout(()=>{
setReset(false);
},0)
}
}, [isReset])
// Button functions
const handleReset = () => {
setReset(!isReset);
setReset(true);
setSpeed(1);
};
const handlePlayStop = () => {
@ -271,8 +279,7 @@ const SimulationPlayer: React.FC = () => {
</div>
{index < intervals.length - 1 && (
<div
className={`line ${
progress >= ((index + 1) / totalSegments) * 100
className={`line ${progress >= ((index + 1) / totalSegments) * 100
? "filled"
: ""
}`}
@ -314,8 +321,7 @@ const SimulationPlayer: React.FC = () => {
<div className="custom-slider-wrapper">
<div className="custom-slider">
<button
className={`slider-handle ${
isDragging ? "dragging" : ""
className={`slider-handle ${isDragging ? "dragging" : ""
}`}
style={{ left: `${calculateHandlePosition()}%` }}
onMouseDown={handleMouseDown}

View File

@ -44,8 +44,9 @@ function RoboticArmAnimator({
setCirclePoints(points);
}, [armBot.position]);
//Handle Reset Animation
useEffect(() => {
if (isReset || !isPlaying) {
if (isReset ) {
progressRef.current = 0;
curveRef.current = null;
setCurrentPath([]);
@ -53,11 +54,15 @@ function RoboticArmAnimator({
totalDistanceRef.current = 0;
startTimeRef.current = null;
segmentDistancesRef.current = [];
setReset(false);
if (!ikSolver) return
const bone = ikSolver.mesh.skeleton.bones.find((b: any) => b.name === targetBone);
if (!bone) return;
bone.position.copy(restPosition)
ikSolver.update();
}
}, [isReset, isPlaying])
//Generate Circle Points
function generateRingPoints(radius: any, segments: any) {
const points: [number, number, number][] = [];
for (let i = 0; i < segments; i++) {
@ -70,7 +75,7 @@ function RoboticArmAnimator({
}
return points;
}
// Function for find nearest Circlepoints Index
const findNearestIndex = (nearestPoint: [number, number, number], points: [number, number, number][], epsilon = 1e-6) => {
for (let i = 0; i < points.length; i++) {
const [x, y, z] = points[i];
@ -85,6 +90,15 @@ function RoboticArmAnimator({
return -1; // Not found
};
//function to find nearest Circlepoints
const findNearest = (target: [number, number, number]) => {
return circlePoints.reduce((nearest, point) => {
const distance = Math.hypot(target[0] - point[0], target[1] - point[1], target[2] - point[2]);
const nearestDistance = Math.hypot(target[0] - nearest[0], target[1] - nearest[1], target[2] - nearest[2]);
return distance < nearestDistance ? point : nearest;
}, circlePoints[0]);
};
// Handle nearest points and final path (including arc points)
useEffect(() => {
if (circlePoints.length > 0 && currentPath.length > 0) {
@ -95,13 +109,13 @@ function RoboticArmAnimator({
const raisedStart = [start[0], start[1] + 0.5, start[2]] as [number, number, number];
const raisedEnd = [end[0], end[1] + 0.5, end[2]] as [number, number, number];
const findNearest = (target: [number, number, number]) => {
return circlePoints.reduce((nearest, point) => {
const distance = Math.hypot(target[0] - point[0], target[1] - point[1], target[2] - point[2]);
const nearestDistance = Math.hypot(target[0] - nearest[0], target[1] - nearest[1], target[2] - nearest[2]);
return distance < nearestDistance ? point : nearest;
}, circlePoints[0]);
};
// const findNearest = (target: [number, number, number]) => {
// return circlePoints.reduce((nearest, point) => {
// const distance = Math.hypot(target[0] - point[0], target[1] - point[1], target[2] - point[2]);
// const nearestDistance = Math.hypot(target[0] - nearest[0], target[1] - nearest[1], target[2] - nearest[2]);
// return distance < nearestDistance ? point : nearest;
// }, circlePoints[0]);
// };
const nearestToStart = findNearest(raisedStart);
const nearestToEnd = findNearest(raisedEnd);
@ -176,8 +190,13 @@ function RoboticArmAnimator({
if (!bone) return;
if (isPlaying) {
if (isReset) {
bone.position.copy(restPosition);
setCustomCurvePoints([]);
ikSolver.update();
}
if (!isPaused && customCurvePoints && customCurvePoints.length > 0) {
const distances = segmentDistancesRef.current; // distances between each pair of points
const distances = segmentDistancesRef.current;
const totalDistance = totalDistanceRef.current;
progressRef.current += delta * (speed * armBot.speed);
@ -186,11 +205,11 @@ function RoboticArmAnimator({
let index = 0;
let accumulatedDistance = 0;
// Find which segment we are currently in
while (index < distances.length && coveredDistance > accumulatedDistance + distances[index]) {
accumulatedDistance += distances[index];
index++;
}
if (index < distances.length) {
const startPoint = customCurvePoints[index];
const endPoint = customCurvePoints[index + 1];
@ -201,6 +220,7 @@ function RoboticArmAnimator({
bone.position.copy(position);
}
}
if (progressRef.current >= totalDistance) {
HandleCallback();
setCurrentPath([]);
@ -212,13 +232,13 @@ function RoboticArmAnimator({
ikSolver.update();
}
} else if ((!isPlaying && currentPath.length === 0) || isReset) {
} else if (!isPlaying && currentPath.length === 0) {
bone.position.copy(restPosition);
ikSolver.update();
}
ikSolver.update();
});
return (
<>
{customCurvePoints && customCurvePoints?.length >= 2 && currentPath && isPlaying && (

View File

@ -97,25 +97,25 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
useEffect(() => {
if (isReset || !isPlaying) {
logStatus(armBot.modelUuid, "Simulation Play Reset Successfully")
removeCurrentAction(armBot.modelUuid)
setArmBotActive(armBot.modelUuid, false)
setArmBotState(armBot.modelUuid, "idle")
setCurrentPhase("init");
setPath([])
removeCurrentAction(armBot.modelUuid)
isPausedRef.current = false
pauseTimeRef.current = null
startTime = 0
const targetBones = ikSolver?.mesh.skeleton.bones.find(
(b: any) => b.name === targetBone
const targetBones = ikSolver?.mesh.skeleton.bones.find((b: any) => b.name === targetBone
);
if (targetBones) {
if (targetBones && isPlaying) {
let curve = createCurveBetweenTwoPoints(targetBones.position, restPosition)
if (curve) {
setPath(curve.points.map(point => [point.x, point.y, point.z]));
}
}
setReset(false);
logStatus(armBot.modelUuid, "Moving armBot from initial point to rest position.")
}
}
// setReset(false);
}
}, [isReset, isPlaying])
useEffect(() => {
@ -127,7 +127,6 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
(b: any) => b.name === targetBone
);
if (isPlaying) {
//Moving armBot from initial point to rest position.
if (!armBot?.isActive && armBot?.state == "idle" && currentPhase == "init") {
@ -204,16 +203,16 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
// logStatus(armBot.modelUuid, "Moving armBot from end point to rest position.")
}
} else {
logStatus(armBot.modelUuid, "Simulation Play Exited")
setArmBotActive(armBot.modelUuid, false)
setArmBotState(armBot.modelUuid, "idle")
setCurrentPhase("init");
setPath([])
isPausedRef.current = false
pauseTimeRef.current = null
isPausedRef.current = false
startTime = 0
removeCurrentAction(armBot.modelUuid)
// logStatus(armBot.modelUuid, "Simulation Play Exited")
// setArmBotActive(armBot.modelUuid, false)
// setArmBotState(armBot.modelUuid, "idle")
// setCurrentPhase("init");
// setPath([])
// isPausedRef.current = false
// pauseTimeRef.current = null
// isPausedRef.current = false
// startTime = 0
// removeCurrentAction(armBot.modelUuid)
}
}, [currentPhase, armBot, isPlaying, ikSolver])
@ -260,6 +259,7 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
}
const logStatus = (id: string, status: string) => {
//
}

View File

@ -7,7 +7,7 @@ function Simulator() {
const executionOrder = determineExecutionOrder(products);
executionOrder.forEach(point => {
useActionHandler(point);
// useActionHandler(point);
});
function determineExecutionSequences(products: productsSchema): PointsScheme[][] {