corrected steering rotation for vehicle

This commit is contained in:
Poovizhi99 2025-05-08 13:42:05 +05:30
parent c5bf98a534
commit d329fe3eef
2 changed files with 19 additions and 45 deletions

View File

@ -85,8 +85,6 @@ const VehicleUI = () => {
);
if (selectedVehicle) {
setSelectedVechicleData({ position: selectedVehicle.position, rotation: selectedVehicle.rotation });
setPoint(selectedVehicle.point.position)
}
@ -105,10 +103,7 @@ const VehicleUI = () => {
const localPosition = outerGroup.current.worldToLocal(worldPos.clone());
setStartPosition([
localPosition.x,
selectedVehicle.point.position[1],
localPosition.z,
setStartPosition([localPosition.x, selectedVehicle.point.position[1], localPosition.z,
]);
setStartRotation([pickUpPoint.rotation.x, pickUpPoint.rotation.y, pickUpPoint.rotation.z,])
} else {
@ -121,10 +116,7 @@ const VehicleUI = () => {
const localPosition = outerGroup.current.worldToLocal(worldPos);
setEndPosition([localPosition.x, selectedVehicle.point.position[1], localPosition.z]);
setEndRotation([
unLoadPoint.rotation.x,
unLoadPoint.rotation.y,
unLoadPoint.rotation.z,
setEndRotation([unLoadPoint.rotation.x, unLoadPoint.rotation.y, unLoadPoint.rotation.z,
]);
} else {
setEndPosition([0, selectedVehicle.point.position[1] + 0.1, -1.5]);

View File

@ -25,6 +25,7 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
const completedRef = useRef<boolean>(false);
const isPausedRef = useRef<boolean>(false);
const pauseTimeRef = useRef<number | null>(null);
const [objectRotation, setObjectRotation] = useState<{ x: number; y: number; z: number } | undefined>(agvDetail.point?.action?.pickUpPoint?.rotation || { x: 0, y: 0, z: 0 })
const [progress, setProgress] = useState<number>(0);
const [restRotation, setRestingRotation] = useState<boolean>(true);
const [currentPath, setCurrentPath] = useState<[number, number, number][]>([]);
@ -32,21 +33,19 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
let startTime: number;
let fixedInterval: number;
let coveredDistance = progressRef.current;
let objectRotation = (agvDetail.point?.action?.pickUpPoint?.rotation || { x: 0, y: 0, z: 0 }) as { x: number; y: number; z: number } | undefined;
const [rotatingToSteering, setRotatingToSteering] = useState(false);
useEffect(() => {
if (currentPhase === 'stationed-pickup' && path.length > 0) {
setCurrentPath(path);
objectRotation = agvDetail.point.action?.pickUpPoint?.rotation
setObjectRotation(agvDetail.point.action?.pickUpPoint?.rotation)
} else if (currentPhase === 'pickup-drop' && path.length > 0) {
objectRotation = agvDetail.point.action?.unLoadPoint?.rotation
setObjectRotation(agvDetail.point.action?.unLoadPoint?.rotation)
setCurrentPath(path);
} else if (currentPhase === 'drop-pickup' && path.length > 0) {
objectRotation = agvDetail.point.action?.pickUpPoint?.rotation
setObjectRotation(agvDetail.point.action?.pickUpPoint?.rotation)
setCurrentPath(path);
}
}, [currentPhase, path]);
}, [currentPhase, path, objectRotation]);
useEffect(() => {
setProgress(0);
@ -125,43 +124,26 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
if (isAligned) {
progressRef.current += delta * (speed * agvDetail.speed);
coveredDistance = progressRef.current;
const t = (coveredDistance - accumulatedDistance) / segmentDistance;
const position = start.clone().lerp(end, t);
object.position.copy(position);
}
}
if (progressRef.current >= totalDistance) {
const restQuaternion = objectRotation ?
new THREE.Quaternion().setFromEuler(new THREE.Euler(objectRotation.x, objectRotation.y, objectRotation.z)) :
object.quaternion.clone();
const steeringQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(objectRotation ? objectRotation.x : object.rotation.x,
agvDetail.point.action.steeringAngle,
objectRotation ? objectRotation.z : object.rotation.z)
);
if (restRotation) {
object.quaternion.slerp(restQuaternion, delta * 2);
const restAngleDiff = object.quaternion.angleTo(restQuaternion);
if (restAngleDiff < 0.01) {
if (restRotation && objectRotation) {
const targetEuler = new THREE.Euler(
objectRotation.x,
objectRotation.y - (agvDetail.point.action.steeringAngle),
objectRotation.z
);
const targetQuaternion = new THREE.Quaternion().setFromEuler(targetEuler);
object.quaternion.slerp(targetQuaternion, delta * 2);
if (object.quaternion.angleTo(targetQuaternion) < 0.01) {
object.quaternion.copy(targetQuaternion);
object.rotation.copy(targetEuler);
setRestingRotation(false);
setRotatingToSteering(true);
}
return;
}
else if (rotatingToSteering) {
object.quaternion.slerp(steeringQuaternion, delta * 2);
const steeringAngleDiff = object.quaternion.angleTo(steeringQuaternion);
if (steeringAngleDiff < 0.01) {
object.rotation.set(
objectRotation ? objectRotation.x : object.rotation.x,
agvDetail.point.action.steeringAngle,
objectRotation ? objectRotation.z : object.rotation.z
);
setRotatingToSteering(false);
}
return;
}