added rough material for agv vehicle

This commit is contained in:
Poovizhi99 2025-05-05 14:28:34 +05:30
parent c9949c98c0
commit 7247443e38
3 changed files with 46 additions and 0 deletions

View File

@ -58,6 +58,7 @@ function MachineInstance({ machineDetail }: any) {
return ( return (
<> <>
<MachineAnimator processingTime={machineDetail.point.action.processTime} handleCallBack={handleCallBack} currentPhase={currentPhase} machineUuid={machineDetail.modelUuid} machineStatus={machineStatus} reset={reset} /> <MachineAnimator processingTime={machineDetail.point.action.processTime} handleCallBack={handleCallBack} currentPhase={currentPhase} machineUuid={machineDetail.modelUuid} machineStatus={machineStatus} reset={reset} />
</> </>
) )
} }

View File

@ -0,0 +1,43 @@
import { useEffect, useRef, useState } from 'react';
import { useThree, useFrame } from '@react-three/fiber';
import * as THREE from 'three';
type MaterialAnimatorProps = {
agvDetail: VehicleStatus;
};
const MaterialAnimator = ({ agvDetail }: MaterialAnimatorProps) => {
const meshRef = useRef<THREE.Mesh>(null!);
const [hasLoad, setHasLoad] = useState<boolean>(false);
const { scene } = useThree();
const loadWorldPosition = new THREE.Vector3();
const offset = new THREE.Vector3(0, 1.1, 0);
useEffect(() => {
setHasLoad(agvDetail.currentLoad > 0);
}, [agvDetail]);
useFrame(() => {
if (!hasLoad) return;
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as THREE.Object3D;
if (agvModel && meshRef.current) {
loadWorldPosition.copy(offset).applyMatrix4(agvModel.matrixWorld);
meshRef.current.position.copy(loadWorldPosition);
meshRef.current.rotation.copy(agvModel.rotation);
}
});
return (
<>
{hasLoad && (
<mesh ref={meshRef}>
<boxGeometry args={[0.5, 0.5, 0.5]} />
<meshStandardMaterial color="green" />
</mesh>
)}
</>
);
};
export default MaterialAnimator;

View File

@ -5,6 +5,7 @@ import { NavMeshQuery } from '@recast-navigation/core';
import { useNavMesh } from '../../../../../store/store'; import { useNavMesh } from '../../../../../store/store';
import { usePlayButtonStore } from '../../../../../store/usePlayButtonStore'; import { usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore'; import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore';
import MaterialAnimator from '../animator/materialAnimator';
function VehicleInstance({ agvDetail }: any) { function VehicleInstance({ agvDetail }: any) {
const { navMesh } = useNavMesh(); const { navMesh } = useNavMesh();
@ -132,6 +133,7 @@ function VehicleInstance({ agvDetail }: any) {
agvDetail={agvDetail} agvDetail={agvDetail}
reset={reset} reset={reset}
/> />
<MaterialAnimator agvDetail={agvDetail} />
</> </>
); );
} }