Enhance vehicle material management: add removeLastMaterial function to useVehicleStore, update useTravelHandler and VehicleAnimator for improved material handling, and refine MaterialAnimator rendering logic.
This commit is contained in:
@@ -38,10 +38,12 @@ const MaterialAnimator = ({ agvDetail }: MaterialAnimatorProps) => {
|
||||
<>
|
||||
{hasLoad && (
|
||||
<>
|
||||
<MaterialModel
|
||||
matRef={meshRef}
|
||||
materialType={agvDetail.currentMaterials[0].materialType || 'Default material'}
|
||||
/>
|
||||
{agvDetail.currentMaterials.length > 0 &&
|
||||
<MaterialModel
|
||||
matRef={meshRef}
|
||||
materialType={agvDetail.currentMaterials[0].materialType || 'Default material'}
|
||||
/>
|
||||
}
|
||||
|
||||
<Html
|
||||
position={htmlPosition}
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as THREE from 'three';
|
||||
import { Line } from '@react-three/drei';
|
||||
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore';
|
||||
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore';
|
||||
import { useMaterialStore } from '../../../../../store/simulation/useMaterialStore';
|
||||
|
||||
interface VehicleAnimatorProps {
|
||||
path: [number, number, number][];
|
||||
@@ -15,7 +16,8 @@ interface VehicleAnimatorProps {
|
||||
}
|
||||
|
||||
function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset }: VehicleAnimatorProps) {
|
||||
const { decrementVehicleLoad, getVehicleById } = useVehicleStore();
|
||||
const { decrementVehicleLoad, getVehicleById, removeLastMaterial } = useVehicleStore();
|
||||
const { removeMaterial } = useMaterialStore();
|
||||
const { isPaused } = usePauseButtonStore();
|
||||
const { isPlaying } = usePlayButtonStore();
|
||||
const { speed } = useAnimationPlaySpeed();
|
||||
@@ -188,6 +190,10 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
|
||||
if (elapsedTime >= fixedInterval) {
|
||||
let droppedMat = droppedMaterial - 1;
|
||||
decrementVehicleLoad(agvDetail.modelUuid, 1);
|
||||
const materialId = removeLastMaterial(agvDetail.modelUuid);
|
||||
if (materialId) {
|
||||
removeMaterial(materialId);
|
||||
}
|
||||
if (droppedMat > 0) {
|
||||
startTime = performance.now();
|
||||
requestAnimationFrame(() => step(droppedMat));
|
||||
|
||||
@@ -10,10 +10,9 @@ import MaterialAnimator from '../animator/materialAnimator';
|
||||
function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) {
|
||||
const { navMesh } = useNavMesh();
|
||||
const { isPlaying } = usePlayButtonStore();
|
||||
const { vehicles, setVehicleActive, setVehicleState, incrementVehicleLoad, addCurrentMaterial, clearCurrentMaterials, setVehicleLoad } = useVehicleStore();
|
||||
const { vehicles, setVehicleActive, setVehicleState, clearCurrentMaterials, setVehicleLoad } = useVehicleStore();
|
||||
const [currentPhase, setCurrentPhase] = useState<string>('stationed');
|
||||
const [path, setPath] = useState<[number, number, number][]>([]);
|
||||
let isIncrememtable = useRef<boolean>(true);
|
||||
|
||||
const computePath = useCallback(
|
||||
(start: any, end: any) => {
|
||||
@@ -44,14 +43,6 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) {
|
||||
setPath([]);
|
||||
}
|
||||
|
||||
const increment = () => {
|
||||
if (isIncrememtable.current) {
|
||||
incrementVehicleLoad(agvDetail.modelUuid, 10);
|
||||
addCurrentMaterial(agvDetail.modelUuid, 'Material 1', '123');
|
||||
isIncrememtable.current = false;
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (isPlaying) {
|
||||
if (!agvDetail.point.action.unLoadPoint || !agvDetail.point.action.pickUpPoint) return;
|
||||
@@ -97,8 +88,6 @@ function VehicleInstance({ agvDetail }: { agvDetail: VehicleStatus }) {
|
||||
setVehicleState(agvDetail.modelUuid, 'running');
|
||||
setVehicleActive(agvDetail.modelUuid, true);
|
||||
vehicleStatus(agvDetail.modelUuid, 'Started from dropping point, heading to pickup point');
|
||||
|
||||
isIncrememtable.current = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -28,10 +28,13 @@ function Vehicles() {
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
<VehicleInstances />
|
||||
|
||||
{isVehicleSelected && selectedEventSphere && !isPlaying &&
|
||||
<VehicleUI />
|
||||
}
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user