added useframe

This commit is contained in:
Poovizhi99 2025-04-23 12:31:37 +05:30
parent 4ad5e1255b
commit 71effecb32
2 changed files with 28 additions and 9 deletions

View File

@ -10,29 +10,48 @@ interface VehicleAnimatorProps {
function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid }: VehicleAnimatorProps) {
const [progress, setProgress] = useState<number>(0)
const [currentPath, setCurrentPath] = useState<[number, number, number][]>([]);
const { scene } = useThree();
useEffect(() => {
if (currentPhase === 'stationed-pickup' && path.length > 0) {
setCurrentPath(path);
}
}, [currentPhase, path])
useFrame((_, delta) => {
if (!path || path.length < 2) return;
useFrame(() => {
if (currentPath.length === 0) return;
const object = scene.getObjectByProperty("uuid", agvUuid);
const object = scene.getObjectByProperty("uuid", agvUuid)
if (!object) return;
setProgress(prev => {
const next = prev + delta * 0.1; // speed
return next >= 1 ? 1 : next;
});
const totalSegments = path.length - 1;
const segmentIndex = Math.floor(progress * totalSegments);
const t = progress * totalSegments - segmentIndex;
const start = path[segmentIndex];
const end = path[segmentIndex + 1] || start;
// Directly set position without creating a new Vector3
object.position.x = start[0] + (end[0] - start[0]) * t;
object.position.y = start[1] + (end[1] - start[1]) * t;
object.position.z = start[2] + (end[2] - start[2]) * t;
});
// useFrame(() => {
// if (currentPath.length === 0) return;
// const object = scene.getObjectByProperty("uuid", agvUuid);
// if (!object) return;
})
// })
return (
<>
</>

View File

@ -58,7 +58,7 @@ function VehicleInstance({ agvDetails }: any) {
return (
<>
<VehicleAnimator path={path} handleCallBack={handleCallBack} currentPhase={currentPhase} agvUuid={agvDetails?.modelUUID} />
<VehicleAnimator path={path} handleCallBack={handleCallBack} currentPhase={currentPhase} agvUuid={agvDetails?.modelUuid} />
</>
)