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