From 01883c7d5eca26efb7f844773cae50e5154b9f8b Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期二, 20 八月 2024 15:30:06 +0800 Subject: [PATCH] # --- src/components/agv.jsx | 65 +++++++++++++++++++++++++++----- 1 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/components/agv.jsx b/src/components/agv.jsx index 6ecf7a0..856455b 100644 --- a/src/components/agv.jsx +++ b/src/components/agv.jsx @@ -5,9 +5,11 @@ import Box from './box'; import * as Common from '../utils/common'; import * as TWEEN from "@tweenjs/tween.js"; +import { useStore } from '@/store'; import { INTERVAL_TIME, MODEL_AGV_SCALE, + MODEL_AGV_COLOR, REAL_COMPARE_MAP_SCALE, REAL_COMPARE_MAP_OFFSET_X, REAL_COMPARE_MAP_OFFSET_Z, @@ -127,8 +129,41 @@ } } +const getMajorPos = (position, bodyAngle, offset) => { + const majorAngle = Common.positiveAngle(bodyAngle); + // console.log(position, majorAngle, offset); + if (majorAngle > 360 - 10 || majorAngle < 0 + 10) { + return { + x: (position?.[2] + offset) * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, + y: position?.[1] * REAL_COMPARE_MAP_SCALE, + z: position?.[0] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z, + } + } + if (majorAngle > 180 - 10 && majorAngle < 180 + 10) { + return { + x: (position?.[2] - offset) * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, + y: position?.[1] * REAL_COMPARE_MAP_SCALE, + z: position?.[0] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z, + } + } + if (majorAngle > 90 - 10 && majorAngle < 90 + 10) { + return { + x: position?.[2] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, + y: position?.[1] * REAL_COMPARE_MAP_SCALE, + z: (position?.[0] - offset) * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z, + } + } + if (majorAngle > 270 - 10 && majorAngle < 270 + 10) { + return { + x: position?.[2] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, + y: position?.[1] * REAL_COMPARE_MAP_SCALE, + z: (position?.[0] + offset) * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z, + } + } +} + const Agv = (props) => { - const { agvNo, position, trayList, hasBox, finger1, finger2, finger3, finger4, inOutFlag } = props; + const { agvNo, position, trayList, hasBox, finger1, finger2, finger3, finger4, inOutFlag, offset } = props; const theta = -props.theta; const height = props.height * 0.0655; @@ -138,20 +173,28 @@ const [loaderAngle, setLoaderAngle] = useState(0); const [forkDis, setForkDis] = useState(0); const [realTrayList, setRealTrayList] = useState([]); + const store = useStore(); + + useEffect(() => { + if (store.autoCruise && agvNo === store.cruiseAgvNo) { + // store.lookAt = groupPos; + + store.lookAt.x = groupPos.x; + store.lookAt.y = loaderHeight; + store.lookAt.z = groupPos.z; + } + }, [groupPos, loaderHeight]) useEffect(() => { if (!props || Object.keys(props).length === 0) { return; } - console.log(props.taskShelfBarcode); - + // group theta + const targetTheta = Common.normalizeAngle(theta - groupTheta) + groupTheta; // group position - const pos = { - x: position?.[2] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, - y: position?.[1] * REAL_COMPARE_MAP_SCALE, - z: position?.[0] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z, - } + const pos = getMajorPos(position, targetTheta, offset); + if (!Common.deepEqual(groupPos, pos) && props.position !== null) { new TWEEN.Tween(groupPos) .to(pos, INTERVAL_TIME) @@ -166,7 +209,6 @@ // group theta if (groupTheta !== theta && props.theta !== null) { - const targetTheta = Common.normalizeAngle(theta - groupTheta) + groupTheta; new TWEEN.Tween({ value: groupTheta }) .to({ value: targetTheta }, INTERVAL_TIME) .easing(TWEEN.Easing.Linear.None) @@ -179,7 +221,7 @@ } // loader height - if (loaderHeight !== height && props.height !== null) { + if (loaderHeight !== height && props.height !== null && props.height > 1) { new TWEEN.Tween({ value: loaderHeight }) .to({ value: height }, INTERVAL_TIME) .easing(TWEEN.Easing.Linear.None) @@ -235,6 +277,7 @@ const fbx = useFBX('/models/agv/body.fbx'); if (!fbx.castShadow) { Common.setShadow(fbx); + Common.setColor(fbx, MODEL_AGV_COLOR); } fbx.scale.set(MODEL_AGV_SCALE, MODEL_AGV_SCALE * 0.97, MODEL_AGV_SCALE); return fbx.clone(); @@ -244,6 +287,7 @@ const fbx = useFBX('/models/agv/loader.fbx'); if (!fbx.castShadow) { Common.setShadow(fbx); + Common.setColor(fbx, MODEL_AGV_COLOR); } fbx.scale.set(MODEL_AGV_SCALE, MODEL_AGV_SCALE, MODEL_AGV_SCALE); return fbx.clone(); @@ -253,6 +297,7 @@ const fbx = useFBX('/models/agv/fork.fbx'); if (!fbx.castShadow) { Common.setShadow(fbx); + Common.setColor(fbx, MODEL_AGV_COLOR); } fbx.scale.set(MODEL_AGV_SCALE, MODEL_AGV_SCALE, MODEL_AGV_SCALE); return fbx.clone(); -- Gitblit v1.9.1