From 28f9d6aadef16cafb888ff6bcc97f99bde971d8d Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 10 五月 2024 13:58:20 +0800
Subject: [PATCH] #

---
 src/components/box.jsx |   83 ++++++++++++++++++++++++++++++-----------
 1 files changed, 60 insertions(+), 23 deletions(-)

diff --git a/src/components/box.jsx b/src/components/box.jsx
index 5ca3bba..351575b 100644
--- a/src/components/box.jsx
+++ b/src/components/box.jsx
@@ -2,47 +2,84 @@
 import { useFrame } from '@react-three/fiber';
 import { useFBX, useAnimations } from '@react-three/drei';
 import * as THREE from 'three';
+import {
+    MODEL_BOX_SCALE,
+    SHELF_BAY_GROUP_COUNT,
+    SHELF_BAY_UNIT_SEPARTE_DISTANCE,
+    SHELF_LEV_UNIT_SEPARTE_DISTANCE,
+    SHELF_HEIGHT_FROM_GROUND
+} from '@/config/setting'
+import * as Common from '../utils/common';
+import { useStore } from '@/store';
 
-const setShadow = (obj) => {
-    obj.castShadow = true;
-    obj.receiveShadow = true;
+const getShelfRow = (row) => {
+    return row;
+}
 
-    if (obj.children) {
-        obj.children.forEach((child) => {
-            setShadow(child);
-        });
-    }
-};
+const getShelfBay = (bay) => {
+    return bay - (bay - 1) % SHELF_BAY_GROUP_COUNT;
+}
 
-const setColor = (obj) => {
-    if (obj.material) {
-        obj.material.color.set(0x4680BF);
-    }
-    if (obj.children) {
-        obj.children.forEach((child) => {
-            setColor(child);
-        });
-    }
-};
+const getShelfLev = (lev) => {
+    return 1;
+}
+
+const getShelfNo = (row, bay, lev) => {
+    return Common.generateLocNo(getShelfRow(row), getShelfBay(bay), getShelfLev(lev));
+}
 
 const Box = (props) => {
-    const { position = [0, 300, 0] } = props;
+    const { row, bay, lev, position = [0, 300, 0], rotationY = 0 } = props;
+    const state = useStore();
+
+    const [pos, setPos] = useState([]);
+    const [rotaY, setRotaY] = useState(0);
 
     const boxModel = useMemo(() => {
         const fbx = useFBX('/models/box/box.fbx');
         if (!fbx.castShadow) {
-            setShadow(fbx);
+            Common.setShadow(fbx);
         }
+        fbx.scale.set(MODEL_BOX_SCALE, MODEL_BOX_SCALE, MODEL_BOX_SCALE);
         return fbx.clone();
     }, [])
 
     useEffect(() => {
+        if (row && bay && lev) {
+            // from shelf
+            const shelfNo = getShelfNo(row, bay, lev);
+            const shelfPos = state.shelfList[shelfNo];
+            if (!shelfPos) { return }
+            const { row: shelfRow, bay: shelfBay, lev: shelfLev } = Common.parseLocNo(shelfNo);
 
-    }, []);
+            // cal bay position
+            let posZByLev = shelfPos[2];
+            if (bay === shelfBay) {
+                posZByLev = shelfPos[2] + SHELF_BAY_UNIT_SEPARTE_DISTANCE;
+            }
+            if (bay === shelfBay + 1) {
+                posZByLev = shelfPos[2];
+            }
+            if (bay === shelfBay + 2) {
+                posZByLev = shelfPos[2] - SHELF_BAY_UNIT_SEPARTE_DISTANCE;
+            }
+
+            setPos([
+                shelfPos[0],
+                shelfPos[1] + SHELF_HEIGHT_FROM_GROUND + (lev - shelfLev) * SHELF_LEV_UNIT_SEPARTE_DISTANCE,
+                posZByLev
+            ]);
+            setRotaY(Math.PI / 2);
+        } else {
+            // from agv
+            setPos(position);
+            setRotaY(rotationY);
+        }
+    }, [props]);
 
     return (
         <>
-            <group rotation={[0, 0, 0]} scale={0.5} position={position}>
+            <group rotation-y={rotaY} position={pos}>
                 <primitive object={boxModel} castShadow />
             </group>
         </>

--
Gitblit v1.9.1