From ae74235d8d7776d4db335c460529c929b0c00eb7 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期四, 07 四月 2022 15:26:38 +0800
Subject: [PATCH] #

---
 static/js/object/StoreGoods.js |  245 ++++++++++++++++++++++++++++++++++--------------
 1 files changed, 171 insertions(+), 74 deletions(-)

diff --git a/static/js/object/StoreGoods.js b/static/js/object/StoreGoods.js
index 4ff4fbf..fff753f 100644
--- a/static/js/object/StoreGoods.js
+++ b/static/js/object/StoreGoods.js
@@ -1,85 +1,182 @@
+import {MTLLoader} from "../lib/MTLLoader.js";
+import {OBJLoader} from "../lib/OBJLoader.js";
+import * as THREE from '../three.module.js';
+
+const palletX = -18;
+const palletY = 2;
+const palletZ = -46;
+
+const goodsX = -17;
+const goodsY = 5;
+const goodsZ = -6;
+
 /**
- * 鑾峰彇绫�
- * @param optionGroup
- * @param optionBin
- * @constructor
+ * 鍒濆鍖栨墭鐩樻ā鍨�
+ * @param scene 鍦烘櫙
+ * @param palletList 鎵樼洏鏁版嵁鍒楄〃
+ * @param ref 鍙傜収鐗�
+ * @param type 鍙傜収鐗╃被鍨嬶細1 - 璐ф灦锛�    2 - 杈撻�佺嚎
  */
-function StoreGoods(optionGroup,optionBin) {
+function InitPallet(scene, palletList, ref, type) {
+    const manager = new THREE.LoadingManager();
+    new OBJLoader( manager )
+        .setPath( '../static/model/obj/' )
+        .load( 'pallet.obj', function ( obj ) {
+            obj.traverse (function (child) {
+                child.castShadow = true;
+                if (child instanceof THREE.Mesh) {
+                    child.material = new THREE.MeshLambertMaterial({
+                        color: 0x708090
+                    });
+                }
+            });
+            obj.scale.set(4, 4, 3.5);
 
-    if(!CommonFunction.hasObj(optionGroup)||!CommonFunction.hasObj(optionBin))
-        return;
-    let col=optionBin.Col;
-    let layer=optionBin.Layer;
-    /*
-        鏀灦鐨勯珮=鏈�搴曞眰鐨勯珮搴�+(搴撲綅鏁�-1)*搴撲綅鐨勯珮搴�
-     */
-    let shelfHeight=optionGroup.BottomHeight+(optionGroup.BinYNum)*optionGroup.BinHeight;
-    /*
-     鏀灦鐨勫=搴撲綅鏁颁箻浠ュ簱浣嶇殑瀹藉害
-     */
-    let shelfWidth=optionGroup.BinZNum*optionGroup.BinWidth;
+            palletList.map(item => {
+                let clone = obj.clone();
+                let positionX;
+                let positionY;
+                let positionZ;
+                switch (type) {
+                    case 1:
+                        positionX = ref.positionX || 0;
+                        positionY = ref.bottomHight + (item.lev1-1)*ref.binHeight || 0;
+                        positionZ = (item.bay1-1)*-ref.binHeight || 0;
 
-    this.positionX=optionGroup.Position.X;
-    this.positionY=optionGroup.Position.Y-shelfHeight/2+optionGroup.BinHeight/2+(layer-1)*optionGroup.BinHeight+optionGroup.BottomHeight;
-    this.positionZ=optionGroup.Position.Z+shelfWidth/2-optionGroup.BinWidth/2-(col-1)*optionGroup.BinWidth;
+                        clone.name = item.loc_no + "-" + "Pallet";
+                        clone.traverse (function (child) {
+                            if (child instanceof THREE.Mesh) {
+                                child.name = item.loc_no + "-" + child.name;
+                            }
+                        })
+                        break;
+                    case 2:
+                        positionX = ref.position.x || 0;
+                        positionY = ref.position.y || 0;
+                        positionZ = ref.position.z || 0;
 
-    this.no=optionBin.No;
-    this.name=optionBin.Name;
+                        positionX -= 48 - 1;
+                        positionY += 20;
+                        positionZ -= 138 + 20;
 
-    this.length=optionGroup.BinLength-6;
-    this.width=optionGroup.BinWidth-6;
-    this.height=optionGroup.BinHeight-6;
+                        clone.name = item.wrkNo + "-" + "Pallet";
+                        clone.traverse (function (child) {
+                            if (child instanceof THREE.Mesh) {
+                                child.name = item.wrkNo + "-" + child.name;
+                            }
+                        })
+                        break;
+                    default:
+                        console.error("InitPallet param[type] error ===>> " + type);
+                }
 
+                clone.position.x = palletX + positionX;
+                clone.position.y = palletY + positionY;
+                clone.position.z = palletZ + positionZ;
+                scene.addObject(clone);
+            })
+        });
+}
 
-    if(optionBin.State=="1")
-    {
-        this.color=0x46C191;
-        this.opacity=0.8;
+/**
+ * 鍒濆鍖栬揣鐗╂ā鍨�
+ * @param scene 鍦烘櫙
+ * @param goodsList 璐х墿鏁版嵁鍒楄〃
+ * @param ref 鍙傜収鐗�
+ * @param type 鍙傜収鐗╃被鍨嬶細1 - 璐ф灦锛�    2 - 杈撻�佺嚎
+ */
+function InitGoods(scene, goodsList, ref, type) {
+    const manager = new THREE.LoadingManager();
+    const goodsWrapImg = new THREE.TextureLoader( manager ).load( '../static/img/goodsWrap.jpg' );
+    const goodsImg = new THREE.TextureLoader( manager ).load( '../static/img/goods.jpg' );
+    new OBJLoader( manager ).load( '../static/model/obj/goods.obj', function ( obj ) {
+        obj.traverse (function (child) {
+            child.castShadow = true;
+            if (child instanceof THREE.Mesh) {
+                if (child.name === 'goods') {
+                    child.material.map = goodsImg;
+                } else if (child.name === "goods_wrap") {
+                    child.material.map = goodsWrapImg;
+                }
+            }
+        });
+        obj.scale.set(1, 1.2, 1.2);
+
+        goodsList.map(item => {
+            let clone = obj.clone();
+            let positionX;
+            let positionY;
+            let positionZ;
+            switch (type) {
+                case 1:
+                    positionX = ref.positionX || 0;
+                    positionY = ref.bottomHight + (item.lev1-1)*ref.binHeight || 0;
+                    positionZ = (item.bay1-1)*-ref.binHeight || 0;
+
+                    clone.name = item.loc_no + "-" + "Goods";
+                    clone.traverse (function (child) {
+                        if (child instanceof THREE.Mesh) {
+                            child.name = item.loc_no + "-" + child.name;
+                        }
+                    })
+                    break;
+                case 2:
+                    positionX = ref.position.x || 0;
+                    positionY = ref.position.y || 0;
+                    positionZ = ref.position.z || 0;
+
+                    positionX -= 48 - 1;
+                    positionY += 20;
+                    positionZ -= 138 + 20;
+
+                    clone.name = item.wrkNo + "-" + "Goods";
+                    clone.traverse (function (child) {
+                        if (child instanceof THREE.Mesh) {
+                            child.name = item.wrkNo + "-" + child.name;
+                        }
+                    })
+                    break;
+                default:
+                    console.error("InitGoods param[type] error ===>> " + type);
+            }
+
+            clone.position.x = goodsX + positionX;
+            clone.position.y = goodsY + positionY;
+            clone.position.z = goodsZ + positionZ;
+            scene.addObject(clone);
+        })
+    });
+}
+
+function StoreGoods(object, data, shelf) {
+    let that = this;
+
+    that.data = data;
+    that.object = object;
+    that.shelf = shelf;
+
+    let palletList = [];
+    let goodsList = [];
+
+    let init = function () {
+        for (let i=0;i<that.data.length;i++) {
+            let obj = that.data[i];
+            if (obj.loc_sts === 'D') {
+                palletList.push(obj);
+            } else if (obj.loc_sts === 'F') {
+                palletList.push(obj);
+                goodsList.push(obj);
+            }
+        }
+        if (palletList.length > 0) {
+            InitPallet(that.object, palletList, that.shelf, 1);
+        }
+        if (goodsList.length > 0) {
+            InitGoods(that.object, goodsList, that.shelf, 1);
+        }
     }
-    else if(optionBin.State=="2")
-    {
-        this.color=0xF0CD3F;
-        this.opacity=0.8;
-    }
-    else if(optionBin.State=="3")
-    {
-        this.color=0xF55E35;
-        this.opacity=0.8;
-    }
-    else
-    {
-        this.color=0x46C191;
-        this.opacity=0.1;
-    }
+    init();
 
 }
-StoreGoods.prototype.create=function () {
-    let optionCube = {
-        length: this.length,
-        width: this.width,
-        height: this.height,
-        position: {
-            x: this.positionX,
-            y: this.positionY,
-            z: this.positionZ
-        },
-        style: {
-            transparent:1,
-            opacity:this.opacity,
-            color: this.color,
-            depthTest:1
-        },
-    };
-    let cube = new Cube(optionCube);
-    cube.uuid=this.no;
-    cube.name=this.name;
-    cube.type="StoreGoods";
-    return cube;
-}
-StoreGoods.prototype.clone=function (object) {
-   let goods=object.clone();
-   goods.position.set(this.positionX,this.positionY,this.positionZ);
-   goods.uuid=this.no;
-   goods.name=this.name;
-   return goods;
-}
\ No newline at end of file
+
+export {StoreGoods, InitPallet, InitGoods}

--
Gitblit v1.9.1