added rough material for agv vehicle
This commit is contained in:
parent
c9949c98c0
commit
7247443e38
|
@ -58,6 +58,7 @@ function MachineInstance({ machineDetail }: any) {
|
|||
return (
|
||||
<>
|
||||
<MachineAnimator processingTime={machineDetail.point.action.processTime} handleCallBack={handleCallBack} currentPhase={currentPhase} machineUuid={machineDetail.modelUuid} machineStatus={machineStatus} reset={reset} />
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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;
|
|
@ -5,6 +5,7 @@ import { NavMeshQuery } from '@recast-navigation/core';
|
|||
import { useNavMesh } from '../../../../../store/store';
|
||||
import { usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
|
||||
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore';
|
||||
import MaterialAnimator from '../animator/materialAnimator';
|
||||
|
||||
function VehicleInstance({ agvDetail }: any) {
|
||||
const { navMesh } = useNavMesh();
|
||||
|
@ -132,6 +133,7 @@ function VehicleInstance({ agvDetail }: any) {
|
|||
agvDetail={agvDetail}
|
||||
reset={reset}
|
||||
/>
|
||||
<MaterialAnimator agvDetail={agvDetail} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue