From 65ab695aadfac96fa121986cf1b53966aeab7c2f Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期五, 26 四月 2024 15:34:10 +0800 Subject: [PATCH] # --- src/utils/common.js | 16 ++++++++++++++++ src/components/box.jsx | 17 ++++++++++++----- src/config/setting.js | 10 +++++++++- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/components/box.jsx b/src/components/box.jsx index a3dd4dc..af0d2d7 100644 --- a/src/components/box.jsx +++ b/src/components/box.jsx @@ -2,7 +2,7 @@ import { useFrame } from '@react-three/fiber'; import { useFBX, useAnimations } from '@react-three/drei'; import * as THREE from 'three'; -import { MODEL_BOX_SCALE } from '@/config/setting' +import { MODEL_BOX_SCALE, SHELF_BAY_GROUP_COUNT } from '@/config/setting' import * as Common from '../utils/common'; import { useStore } from '@/store'; @@ -11,7 +11,7 @@ } const getShelfBay = (bay) => { - return bay - (bay - 1) % 3; + return bay - (bay - 1) % SHELF_BAY_GROUP_COUNT; } const getShelfLev = (lev) => { @@ -19,7 +19,7 @@ } const getShelfNo = (row, bay, lev) => { - return getShelfRow(row) + '-' + getShelfBay(bay) + '-' + getShelfLev(lev); + return Common.generateLocNo(getShelfRow(row), getShelfBay(bay), getShelfLev(lev)); } const Box = (props) => { @@ -27,6 +27,7 @@ const state = useStore(); const [pos, setPos] = useState([]); + const [rotaY, setRotaY] = useState(0); const boxModel = useMemo(() => { const fbx = useFBX('/models/box/box.fbx'); @@ -42,16 +43,22 @@ // from shelf const shelfNo = getShelfNo(row, bay, lev); const shelfPos = state.shelfList[shelfNo]; - setPos(shelfPos); + const { row: shelfRow, bay: shelfBay, lev: shelfLev } = Common.parseLocNo(shelfNo); + + console.log([shelfPos[0], shelfPos[1] + (bay - shelfBay) * 100, shelfPos[2] + (lev - shelfLev) * 100]); + + setPos([shelfPos[0], shelfPos[1] + (bay - shelfBay) * 10, shelfPos[2] + (lev - shelfLev) * 100]); + setRotaY(Math.PI / 2); } else { // from agv setPos(position); + setRotaY(rotationY); } }, [props]); return ( <> - <group rotation-y={rotationY} position={pos}> + <group rotation-y={rotaY} position={pos}> <primitive object={boxModel} castShadow /> </group> </> diff --git a/src/config/setting.js b/src/config/setting.js index cf4fad5..cde926b 100644 --- a/src/config/setting.js +++ b/src/config/setting.js @@ -8,14 +8,22 @@ export const INTERVAL_TIME = 500; +// model scale rate + export const MODEL_AGV_SCALE = .5; export const MODEL_BOX_SCALE = .5; export const MODEL_SHELF_SCALE = 1; +// shelf scale & offset + export const REAL_COMPARE_MAP_SCALE = .1; export const REAL_COMPARE_MAP_OFFSET_X = -200; -export const REAL_COMPARE_MAP_OFFSET_Z = -600; \ No newline at end of file +export const REAL_COMPARE_MAP_OFFSET_Z = -600; + +// shelf setting + +export const SHELF_BAY_GROUP_COUNT = 3; \ No newline at end of file diff --git a/src/utils/common.js b/src/utils/common.js index 5c5c8df..50bfdb4 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -76,4 +76,20 @@ } } return true; +} + +export const parseLocNo = (locNo) => { + if (!locNo || typeof locNo !== 'string') { + return null; + } + const locParseArr = locNo.split('-'); + return { + row: locParseArr?.[0], + bay: locParseArr?.[1], + lev: locParseArr?.[2], + } +} + +export const generateLocNo = (row, bay, lev) => { + return row + '-' + bay + '-' + lev; } \ No newline at end of file -- Gitblit v1.9.1