"updated arm logic"
This commit is contained in:
@@ -3,7 +3,10 @@ import * as THREE from "three";
|
||||
import { useFrame, useThree } from "@react-three/fiber";
|
||||
import { NavMeshQuery } from "@recast-navigation/core";
|
||||
import { Line } from "@react-three/drei";
|
||||
import { useAnimationPlaySpeed, usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
||||
import {
|
||||
useAnimationPlaySpeed,
|
||||
usePlayButtonStore,
|
||||
} from "../../../store/usePlayButtonStore";
|
||||
import { usePlayAgv } from "../../../store/store";
|
||||
|
||||
interface PathNavigatorProps {
|
||||
@@ -11,7 +14,7 @@ interface PathNavigatorProps {
|
||||
pathPoints: any;
|
||||
id: string;
|
||||
speed: number;
|
||||
globalSpeed: number,
|
||||
globalSpeed: number;
|
||||
bufferTime: number;
|
||||
hitCount: number;
|
||||
processes: any[];
|
||||
@@ -40,11 +43,21 @@ export default function PathNavigator({
|
||||
}: PathNavigatorProps) {
|
||||
const [currentPhase, setCurrentPhase] = useState<Phase>("initial");
|
||||
const [path, setPath] = useState<[number, number, number][]>([]);
|
||||
const [toPickupPath, setToPickupPath] = useState<[number, number, number][]>([]);
|
||||
const [pickupDropPath, setPickupDropPath] = useState<[number, number, number][]>([]);
|
||||
const [dropPickupPath, setDropPickupPath] = useState<[number, number, number][]>([]);
|
||||
const [initialPosition, setInitialPosition] = useState<THREE.Vector3 | null>(null);
|
||||
const [initialRotation, setInitialRotation] = useState<THREE.Euler | null>(null);
|
||||
const [toPickupPath, setToPickupPath] = useState<[number, number, number][]>(
|
||||
[]
|
||||
);
|
||||
const [pickupDropPath, setPickupDropPath] = useState<
|
||||
[number, number, number][]
|
||||
>([]);
|
||||
const [dropPickupPath, setDropPickupPath] = useState<
|
||||
[number, number, number][]
|
||||
>([]);
|
||||
const [initialPosition, setInitialPosition] = useState<THREE.Vector3 | null>(
|
||||
null
|
||||
);
|
||||
const [initialRotation, setInitialRotation] = useState<THREE.Euler | null>(
|
||||
null
|
||||
);
|
||||
const [boxVisible, setBoxVisible] = useState(false);
|
||||
|
||||
const distancesRef = useRef<number[]>([]);
|
||||
@@ -61,11 +74,14 @@ export default function PathNavigator({
|
||||
|
||||
const boxRef = useRef<THREE.Mesh | null>(null);
|
||||
|
||||
const baseMaterials = useMemo(() => ({
|
||||
Box: new THREE.MeshStandardMaterial({ color: 0x8b4513 }),
|
||||
Crate: new THREE.MeshStandardMaterial({ color: 0x00ff00 }),
|
||||
Default: new THREE.MeshStandardMaterial({ color: 0xcccccc })
|
||||
}), []);
|
||||
const baseMaterials = useMemo(
|
||||
() => ({
|
||||
Box: new THREE.MeshStandardMaterial({ color: 0x8b4513 }),
|
||||
Crate: new THREE.MeshStandardMaterial({ color: 0x00ff00 }),
|
||||
Default: new THREE.MeshStandardMaterial({ color: 0xcccccc }),
|
||||
}),
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const object = scene.getObjectByProperty("uuid", id);
|
||||
@@ -135,7 +151,11 @@ export default function PathNavigator({
|
||||
const pickupToDropPath = computePath(pickup, drop);
|
||||
const dropToPickupPath = computePath(drop, pickup);
|
||||
|
||||
if (toPickupPath.length && pickupToDropPath.length && dropToPickupPath.length) {
|
||||
if (
|
||||
toPickupPath.length &&
|
||||
pickupToDropPath.length &&
|
||||
dropToPickupPath.length
|
||||
) {
|
||||
setPickupDropPath(pickupToDropPath);
|
||||
setDropPickupPath(dropToPickupPath);
|
||||
setToPickupPath(toPickupPath);
|
||||
@@ -163,7 +183,10 @@ export default function PathNavigator({
|
||||
}, [path]);
|
||||
|
||||
function logAgvStatus(id: string, status: string) {
|
||||
// console.log(`AGV ${id}: ${status}`);
|
||||
// console.log(
|
||||
// `AGV ${id}: ${status}`
|
||||
|
||||
// );
|
||||
}
|
||||
|
||||
function findProcessByTargetModelUUID(processes: any, targetModelUUID: any) {
|
||||
@@ -223,7 +246,9 @@ export default function PathNavigator({
|
||||
}, [processes, MaterialRef, boxVisible, scene, id, baseMaterials]);
|
||||
|
||||
useFrame((_, delta) => {
|
||||
const currentAgv = (agvRef.current || []).find((agv: AGVData) => agv.vehicleId === id);
|
||||
const currentAgv = (agvRef.current || []).find(
|
||||
(agv: AGVData) => agv.vehicleId === id
|
||||
);
|
||||
|
||||
if (!scene || !id || !isPlaying) return;
|
||||
|
||||
@@ -243,6 +268,7 @@ export default function PathNavigator({
|
||||
const isAgvReady = () => {
|
||||
if (!agvRef.current || agvRef.current.length === 0) return false;
|
||||
if (!currentAgv) return false;
|
||||
|
||||
return currentAgv.isActive && hitCount >= currentAgv.maxHitCount;
|
||||
};
|
||||
|
||||
@@ -266,12 +292,19 @@ export default function PathNavigator({
|
||||
}
|
||||
|
||||
if (isPlaying && currentPhase === "initial" && !hasReachedPickup.current) {
|
||||
const reached = moveAlongPath(object, path, distancesRef.current, speed, delta, progressRef);
|
||||
const reached = moveAlongPath(
|
||||
object,
|
||||
path,
|
||||
distancesRef.current,
|
||||
speed,
|
||||
delta,
|
||||
progressRef
|
||||
);
|
||||
|
||||
if (reached) {
|
||||
hasReachedPickup.current = true;
|
||||
if (currentAgv) {
|
||||
currentAgv.status = 'picking';
|
||||
currentAgv.status = "picking";
|
||||
}
|
||||
logAgvStatus(id, "Reached pickup point, Waiting for material");
|
||||
}
|
||||
@@ -287,20 +320,28 @@ export default function PathNavigator({
|
||||
progressRef.current = 0;
|
||||
logAgvStatus(id, "Started from pickup point, heading to drop point");
|
||||
if (currentAgv) {
|
||||
currentAgv.status = 'toDrop';
|
||||
currentAgv.status = "toDrop";
|
||||
}
|
||||
}, 0)
|
||||
}, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPlaying && currentPhase === "toDrop") {
|
||||
const reached = moveAlongPath(object, path, distancesRef.current, speed, delta, progressRef);
|
||||
const reached = moveAlongPath(
|
||||
object,
|
||||
path,
|
||||
distancesRef.current,
|
||||
speed,
|
||||
delta,
|
||||
progressRef
|
||||
);
|
||||
|
||||
if (reached && !isWaiting.current) {
|
||||
isWaiting.current = true;
|
||||
logAgvStatus(id, "Reached drop point");
|
||||
if (currentAgv) {
|
||||
currentAgv.status = 'droping';
|
||||
currentAgv.status = "droping";
|
||||
currentAgv.hitCount = currentAgv.hitCount--;
|
||||
}
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
setPath([...dropPickupPath]);
|
||||
@@ -309,16 +350,26 @@ export default function PathNavigator({
|
||||
isWaiting.current = false;
|
||||
setBoxVisible(false);
|
||||
if (currentAgv) {
|
||||
currentAgv.status = 'toPickup';
|
||||
currentAgv.status = "toPickup";
|
||||
}
|
||||
logAgvStatus(id, "Started from droping point, heading to pickup point");
|
||||
logAgvStatus(
|
||||
id,
|
||||
"Started from droping point, heading to pickup point"
|
||||
);
|
||||
}, bufferTime * 1000);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPlaying && currentPhase === "toPickup") {
|
||||
const reached = moveAlongPath(object, path, distancesRef.current, speed, delta, progressRef);
|
||||
const reached = moveAlongPath(
|
||||
object,
|
||||
path,
|
||||
distancesRef.current,
|
||||
speed,
|
||||
delta,
|
||||
progressRef
|
||||
);
|
||||
|
||||
if (reached) {
|
||||
if (currentAgv) {
|
||||
@@ -326,14 +377,21 @@ export default function PathNavigator({
|
||||
}
|
||||
setCurrentPhase("initial");
|
||||
if (currentAgv) {
|
||||
currentAgv.status = 'picking';
|
||||
currentAgv.status = "picking";
|
||||
}
|
||||
logAgvStatus(id, "Reached pickup point again, cycle complete");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
moveAlongPath(object, path, distancesRef.current, speed, delta, progressRef);
|
||||
moveAlongPath(
|
||||
object,
|
||||
path,
|
||||
distancesRef.current,
|
||||
speed,
|
||||
delta,
|
||||
progressRef
|
||||
);
|
||||
});
|
||||
|
||||
function moveAlongPath(
|
||||
@@ -379,7 +437,11 @@ export default function PathNavigator({
|
||||
const targetRotationY = Math.atan2(targetDirection.x, targetDirection.z);
|
||||
|
||||
const rotationSpeed = Math.min(5 * delta, 1);
|
||||
object.rotation.y = THREE.MathUtils.lerp(object.rotation.y, targetRotationY, rotationSpeed);
|
||||
object.rotation.y = THREE.MathUtils.lerp(
|
||||
object.rotation.y,
|
||||
targetRotationY,
|
||||
rotationSpeed
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user