added material types for vehicle Model
This commit is contained in:
parent
dd402184e4
commit
2a132b7f9f
|
@ -1,43 +1,61 @@
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { useThree, useFrame } from '@react-three/fiber';
|
import { useThree, useFrame } from '@react-three/fiber';
|
||||||
import * as THREE from 'three';
|
import * as THREE from 'three';
|
||||||
|
import { MaterialModel } from '../../../materials/instances/material/materialModel';
|
||||||
|
import { Html } from '@react-three/drei';
|
||||||
|
|
||||||
type MaterialAnimatorProps = {
|
type MaterialAnimatorProps = {
|
||||||
agvDetail: VehicleStatus;
|
agvDetail: VehicleStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const MaterialAnimator = ({ agvDetail }: MaterialAnimatorProps) => {
|
const MaterialAnimator = ({ agvDetail }: MaterialAnimatorProps) => {
|
||||||
const meshRef = useRef<THREE.Mesh>(null!);
|
const meshRef = useRef<any>(null!);
|
||||||
const [hasLoad, setHasLoad] = useState<boolean>(false);
|
const [hasLoad, setHasLoad] = useState(false);
|
||||||
const { scene } = useThree();
|
const { scene } = useThree();
|
||||||
const loadWorldPosition = new THREE.Vector3();
|
const offset = new THREE.Vector3(0, 0.85, 0);
|
||||||
const offset = new THREE.Vector3(0, 1.1, 0);
|
const [htmlPosition, setHtmlPosition] = useState<[number, number, number]>([0, 0, 0]);
|
||||||
|
const [htmlRotation, setHtmlRotation] = useState<[number, number, number]>([0, 0, 0]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setHasLoad(agvDetail.currentLoad > 0);
|
setHasLoad(agvDetail.currentLoad > 0);
|
||||||
}, [agvDetail]);
|
}, [agvDetail.currentLoad]);
|
||||||
|
|
||||||
useFrame(() => {
|
useFrame(() => {
|
||||||
if (!hasLoad) return;
|
if (!hasLoad || !meshRef.current) return;
|
||||||
|
|
||||||
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as THREE.Object3D;
|
const agvModel = scene.getObjectByProperty("uuid", agvDetail.modelUuid) as THREE.Object3D;
|
||||||
if (agvModel && meshRef.current) {
|
if (agvModel) {
|
||||||
loadWorldPosition.copy(offset).applyMatrix4(agvModel.matrixWorld);
|
const worldPosition = offset.clone().applyMatrix4(agvModel.matrixWorld);
|
||||||
meshRef.current.position.copy(loadWorldPosition);
|
meshRef.current.position.copy(worldPosition);
|
||||||
|
setHtmlPosition([worldPosition.x, worldPosition.y, worldPosition.z]);
|
||||||
meshRef.current.rotation.copy(agvModel.rotation);
|
meshRef.current.rotation.copy(agvModel.rotation);
|
||||||
|
setHtmlRotation([agvModel.rotation.x, agvModel.rotation.y, agvModel.rotation.z]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{hasLoad && (
|
{hasLoad && (
|
||||||
<mesh ref={meshRef}>
|
<>
|
||||||
<boxGeometry args={[0.5, 0.5, 0.5]} />
|
<MaterialModel
|
||||||
<meshStandardMaterial color="green" />
|
matRef={meshRef}
|
||||||
</mesh>
|
materialType={agvDetail.materialType || 'Default material'}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Html
|
||||||
|
position={htmlPosition}
|
||||||
|
rotation={htmlRotation}
|
||||||
|
style={{ backgroundColor: "pink", padding: "4px", borderRadius: "4px" }}
|
||||||
|
>
|
||||||
|
{agvDetail.currentLoad}
|
||||||
|
</Html>
|
||||||
|
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default MaterialAnimator;
|
export default MaterialAnimator;
|
||||||
|
|
|
@ -199,7 +199,7 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{currentPath.length > 0 && (
|
{currentPath.length > 0 && (
|
||||||
<>
|
<group visible={false}>
|
||||||
<Line points={currentPath} color="blue" lineWidth={3} />
|
<Line points={currentPath} color="blue" lineWidth={3} />
|
||||||
{currentPath.map((point, index) => (
|
{currentPath.map((point, index) => (
|
||||||
<mesh key={index} position={point}>
|
<mesh key={index} position={point}>
|
||||||
|
@ -207,7 +207,7 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
|
||||||
<meshStandardMaterial color="red" />
|
<meshStandardMaterial color="red" />
|
||||||
</mesh>
|
</mesh>
|
||||||
))}
|
))}
|
||||||
</>
|
</group>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,8 +9,9 @@ import MaterialAnimator from '../animator/materialAnimator';
|
||||||
|
|
||||||
function VehicleInstance({ agvDetail }: any) {
|
function VehicleInstance({ agvDetail }: any) {
|
||||||
const { navMesh } = useNavMesh();
|
const { navMesh } = useNavMesh();
|
||||||
|
const vehicleRef: any = useRef();
|
||||||
const { isPlaying } = usePlayButtonStore();
|
const { isPlaying } = usePlayButtonStore();
|
||||||
const { vehicles, setVehicleActive, setVehicleState, incrementVehicleLoad } = useVehicleStore();
|
const { vehicles, setVehicleActive, setVehicleState, incrementVehicleLoad, setMaterialType } = useVehicleStore();
|
||||||
const [currentPhase, setCurrentPhase] = useState<string>('stationed');
|
const [currentPhase, setCurrentPhase] = useState<string>('stationed');
|
||||||
const [path, setPath] = useState<[number, number, number][]>([]);
|
const [path, setPath] = useState<[number, number, number][]>([]);
|
||||||
let isIncrememtable = useRef<boolean>(true);
|
let isIncrememtable = useRef<boolean>(true);
|
||||||
|
@ -45,8 +46,8 @@ function VehicleInstance({ agvDetail }: any) {
|
||||||
|
|
||||||
const increment = () => {
|
const increment = () => {
|
||||||
if (isIncrememtable.current) {
|
if (isIncrememtable.current) {
|
||||||
|
|
||||||
incrementVehicleLoad(agvDetail.modelUuid, 10);
|
incrementVehicleLoad(agvDetail.modelUuid, 10);
|
||||||
|
setMaterialType(agvDetail.modelUuid, 'Material 1')
|
||||||
isIncrememtable.current = false;
|
isIncrememtable.current = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +73,7 @@ function VehicleInstance({ agvDetail }: any) {
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
|
|
||||||
if (agvDetail.currentLoad === agvDetail.point.action.loadCapacity) {
|
if (agvDetail.currentLoad === agvDetail.point.action.loadCapacity && agvDetail.materialType) {
|
||||||
const toDrop = computePath(
|
const toDrop = computePath(
|
||||||
agvDetail.point.action.pickUpPoint.position,
|
agvDetail.point.action.pickUpPoint.position,
|
||||||
agvDetail.point.action.unLoadPoint.position
|
agvDetail.point.action.unLoadPoint.position
|
||||||
|
@ -119,6 +120,7 @@ function VehicleInstance({ agvDetail }: any) {
|
||||||
setVehicleState(agvDetail.modelUuid, 'idle');
|
setVehicleState(agvDetail.modelUuid, 'idle');
|
||||||
setVehicleActive(agvDetail.modelUuid, false);
|
setVehicleActive(agvDetail.modelUuid, false);
|
||||||
setPath([]);
|
setPath([]);
|
||||||
|
setMaterialType(agvDetail.modelUuid, null)
|
||||||
vehicleStatus(agvDetail.modelUuid, 'Reached pickup point again, cycle complete');
|
vehicleStatus(agvDetail.modelUuid, 'Reached pickup point again, cycle complete');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue