added global speed for agv
This commit is contained in:
parent
1256f33342
commit
3eecf30541
|
@ -1,4 +1,4 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Line } from "@react-three/drei";
|
||||
import {
|
||||
useNavMesh,
|
||||
|
@ -6,7 +6,7 @@ import {
|
|||
useSimulationStates,
|
||||
} from "../../../store/store";
|
||||
import PathNavigator from "./pathNavigator";
|
||||
import { usePlayButtonStore, useResetButtonStore } from "../../../store/usePlayButtonStore";
|
||||
import { useAnimationPlaySpeed, usePlayButtonStore, useResetButtonStore } from "../../../store/usePlayButtonStore";
|
||||
|
||||
type PathPoints = {
|
||||
modelUuid: string;
|
||||
|
@ -31,6 +31,10 @@ const Agv: React.FC<ProcessContainerProps> = ({
|
|||
const { navMesh } = useNavMesh();
|
||||
const { isPlaying } = usePlayButtonStore();
|
||||
const { isReset, setReset } = useResetButtonStore();
|
||||
const { speed } = useAnimationPlaySpeed();
|
||||
const globalSpeed = useRef(1);
|
||||
|
||||
useEffect(() => { globalSpeed.current = speed }, [speed])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPlaying || isReset) {
|
||||
|
@ -81,6 +85,7 @@ const Agv: React.FC<ProcessContainerProps> = ({
|
|||
pathPoints={pair.points}
|
||||
id={pair.modelUuid}
|
||||
speed={pair.modelSpeed}
|
||||
globalSpeed={globalSpeed.current}
|
||||
bufferTime={pair.bufferTime}
|
||||
hitCount={pair.hitCount}
|
||||
processes={processes}
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as THREE from "three";
|
|||
import { useFrame, useThree } from "@react-three/fiber";
|
||||
import { NavMeshQuery } from "@recast-navigation/core";
|
||||
import { Line } from "@react-three/drei";
|
||||
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
||||
import { useAnimationPlaySpeed, usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
||||
import { usePlayAgv } from "../../../store/store";
|
||||
|
||||
interface PathNavigatorProps {
|
||||
|
@ -11,6 +11,7 @@ interface PathNavigatorProps {
|
|||
pathPoints: any;
|
||||
id: string;
|
||||
speed: number;
|
||||
globalSpeed: number,
|
||||
bufferTime: number;
|
||||
hitCount: number;
|
||||
processes: any[];
|
||||
|
@ -30,6 +31,7 @@ export default function PathNavigator({
|
|||
pathPoints,
|
||||
id,
|
||||
speed,
|
||||
globalSpeed,
|
||||
bufferTime,
|
||||
hitCount,
|
||||
processes,
|
||||
|
@ -344,7 +346,7 @@ export default function PathNavigator({
|
|||
): boolean {
|
||||
if (path.length < 2) return false;
|
||||
|
||||
progressRef.current += delta * speed;
|
||||
progressRef.current += delta * (speed * globalSpeed);
|
||||
let covered = progressRef.current;
|
||||
let accumulated = 0;
|
||||
let index = 0;
|
||||
|
|
|
@ -377,8 +377,7 @@ const ProcessAnimator: React.FC<ProcessContainerProps> = ({
|
|||
|
||||
if (!isLastPoint) {
|
||||
const nextPoint = path[nextPointIdx];
|
||||
const distance =
|
||||
path[stateRef.currentIndex].distanceTo(nextPoint);
|
||||
const distance = path[stateRef.currentIndex].distanceTo(nextPoint);
|
||||
const effectiveSpeed = stateRef.speed * speedRef.current;
|
||||
const movement = effectiveSpeed * delta;
|
||||
|
||||
|
|
Loading…
Reference in New Issue