From 18bd54d17c3d09e48b14fcb0cc0fc74758a920b2 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期四, 30 六月 2022 16:51:43 +0800
Subject: [PATCH] #

---
 static/js/object/StoreShelf.js |  160 +++++++++++++++++++++++++++--------------------------
 1 files changed, 82 insertions(+), 78 deletions(-)

diff --git a/static/js/object/StoreShelf.js b/static/js/object/StoreShelf.js
index d5d039a..cf49404 100644
--- a/static/js/object/StoreShelf.js
+++ b/static/js/object/StoreShelf.js
@@ -1,93 +1,97 @@
+import * as BufferGeometryUtils from '../utils/BufferGeometryUtils.js';
+
 function StoreShelf(option) {
-    this.binLength = option.BinLength||50;//搴撲綅闀垮害
-    this.binWidth = option.BinWidth||50;//搴撲綅瀹�
-    this.binHeight = option.BinHeight||50;//搴撲綅楂�
-    this.binXNum = option.BinXNum||1;//搴撲綅X杞存柟鍚戝簱浣嶆暟閲�
-    this.binZNum = option.BinZNum||10;//搴撲綅Z杞存柟鍚戝簱浣嶆暟閲�
-    this.binYNum = option.BinYNum||10;//搴撲綅Y杞村簱浣嶆暟閲�
-    this.bottomHight = option.BottomHeight||20;//搴曞眰楂樺害锛屽簳灞�
-    this.positionX = option.Position.X||0;//搴撲綅浣嶇疆
-    this.positionY = option.Position.Y||0;//搴撲綅浣嶇疆
-    this.positionZ = option.Position.Z||0;//搴撲綅浣嶇疆
+    this.binLength = option.binLength||50;//搴撲綅闀垮害
+    this.binWidth = option.binWidth||50;//搴撲綅瀹�
+    this.binHeight = option.binHeight||50;//搴撲綅楂�
+    this.binXNum = option.binXNum||1;//搴撲綅X杞存柟鍚戝簱浣嶆暟閲�
+    this.binZNum = option.binZNum||10;//搴撲綅Z杞存柟鍚戝簱浣嶆暟閲�
+    this.binYNum = option.binYNum||10;//搴撲綅Y杞村簱浣嶆暟閲�
+    this.bottomHight = option.bottomHeight||20;//搴曞眰楂樺害锛屽簳灞�
+    this.positionX = option.position.x||0;//搴撲綅浣嶇疆
+    this.positionY = option.position.y||0;//搴撲綅浣嶇疆
+    this.positionZ = option.position.z||0;//搴撲綅浣嶇疆
     this.rackLengh = 3;//鏀灦鐨勯暱搴︼紝榛樿璁惧姩涓�3
     this.rackWidth = 3;//鏀灦鐨勫搴︼紝榛樿璁惧畾涓�3
-    this.intervalRackNum=2;//闂撮殧澶氬皯搴撲綅鏈変竴涓富鏀灦
+    this.mesh = null;
 
-    // let binHolderPlane=new THREE.BoxGeometry(this.binLength,2,this.binWidth);//瀹氫箟涓�涓窡搴撲綅闀垮鐩稿悓鐨勫嚑浣曚綋锛屼綔涓烘墭鐩�
+    // 鏉愯川
+    let shelfMat = new THREE.MeshPhysicalMaterial({
+        color: 0x175EC0,
+        transparent: false,
+        opacity: 0.7
+    });
 
-    //瀹氫箟鏀灦鍜屾墭鐩樼殑鏉愯川
-    let shlefMat = new THREE.MeshPhysicalMaterial({
-        color:0xff0000,
-        // 鏉愯川鍍忛噾灞炵殑绋嬪害. 闈為噾灞炴潗鏂欙紝濡傛湪鏉愭垨鐭虫潗锛屼娇鐢�0.0锛岄噾灞炰娇鐢�1.0锛屼腑闂存病鏈夛紙閫氬父锛�.
-        // 榛樿 0.5. 0.0鍒�1.0涔嬮棿鐨勫�煎彲鐢ㄤ簬鐢熼攬鐨勯噾灞炲瑙�
-        metalness: 1.0,
-        // 鏉愭枡鐨勭矖绯欑▼搴�. 0.0琛ㄧず骞虫粦鐨勯暅闈㈠弽灏勶紝1.0琛ㄧず瀹屽叏婕弽灏�. 榛樿 0.5
-        roughness: 0.6,
-        // 璁剧疆鐜璐村浘
-        // 鍙嶅皠绋嬪害, 浠� 0.0 鍒�1.0.榛樿0.5.
-        // 杩欐ā鎷熶簡闈為噾灞炴潗鏂欑殑鍙嶅皠鐜囥�� 褰搈etalness涓�1.0鏃舵棤鏁�
-        // reflectivity: 0.5,
-    })
+    // 璐ф灦鎬婚珮
+    let shelfHeight=this.bottomHight+(this.binYNum)*this.binHeight;
+    // 鏀灦妯″瀷 + 鏉愯川
+    let rackBoxGeometry=new THREE.BoxGeometry(this.rackLengh,shelfHeight,this.rackWidth);
+    // 鎵樻澘妯″瀷 + 鏉愯川
+    let planeBoxGeometry = new THREE.BoxGeometry(this.binLength, 2, this.binWidth+this.rackWidth);  // 瑕嗙洊澶氫竴鏍规敮鏋跺搴�
+    let planeRackBoxGeometry = new THREE.BoxGeometry(3, 2, this.binWidth+this.rackWidth);
 
-    let group = new THREE.Group();//瀹氫箟涓�涓粍鍚堜綋
-    //鍚堝苟妯″瀷锛屽垯浣跨敤merge鏂规硶鍚堝苟
-    let combineGeometry = new THREE.BufferGeometry();
-    /*
-     鏀灦鐨勯珮=鏈�搴曞眰鐨勯珮搴�+(搴撲綅鏁�-1)*搴撲綅鐨勯珮搴�
-     */
-    let shelfHeight=this.bottomHight+(this.binYNum-1)*this.binHeight;
-    /*
-     鏀灦鐨勫=搴撲綅鏁颁箻浠ュ簱浣嶇殑瀹藉害
-     */
-    let shelfWidth=this.binZNum*this.binWidth;
-    let rackBoxGeometry=new THREE.BoxGeometry(this.rackLengh,shelfHeight,this.rackWidth);//瀹氫箟涓�涓敮鏋剁綉鏍�
-    let rackObject=new THREE.Mesh( rackBoxGeometry, shlefMat, 0 );
+    // Y杞村畾浣�
+    let positionY = this.positionY + shelfHeight / 2;
 
-    let plane = new THREE.BoxGeometry(this.binLength, 2, this.binWidth);
-    let holderObject = new THREE.Mesh(plane, shlefMat,0);
+    //宸︿晶鏀灦鏌辩殑X杞村畾浣�
+    let leftPositionX=this.positionX-this.binLength/2;
+    //鍙充晶鏀灦鏌辩殑X杞村畾浣�
+    let rightPositionX=this.positionX+this.binLength/2 - this.rackLengh;    // 缂╄繘鏀灦闀垮害
 
-    let leftPositionX=this.positionX-this.binLength/2+this.rackLengh/2;//宸︿晶鏀灦鏌辩殑X杞存潯鐮�
-    let rightPositionX=this.positionX+this.binLength/2-this.rackLengh/2;//鍙充晶鏀灦鏌辩殑X杞存潯鐮�
+    let geometries = [];
+    let transform = new THREE.Object3D();
+    // 鍒濆鍖栨敮鏋舵ā鍨�
+    for(let i=0;i<=this.binZNum;i++) {
+        let positionZ = - ( this.positionZ + i*this.binWidth );
+        // -----
+        let leftClone = rackBoxGeometry.clone();
+        transform.position.set(leftPositionX,positionY,positionZ);
+        transform.updateMatrix();
+        leftClone.applyMatrix4(transform.matrix);
+        geometries.push(leftClone);
 
+        let rightClone = rackBoxGeometry.clone();
+        transform.position.set(rightPositionX,positionY,positionZ);
+        transform.updateMatrix();
+        rightClone.applyMatrix4(transform.matrix);
+        geometries.push(rightClone);
+    }
+    // 鍒濆鍖栨墭鏉挎ā鍨�
+    for(let i = 0;i < this.binZNum;i++) {
+        for (let j = 0;j <= this.binYNum;j++) {
+            if (j !== this.binYNum) {
+                let leftClone = planeRackBoxGeometry.clone();
+                let positionY = this.positionY + this.bottomHight + j*this.binHeight + 1;
+                let positionZ = - ( this.positionZ + i * this.binWidth + this.binWidth/2 );
+                transform.position.set(this.positionX - 16, positionY, positionZ);
+                transform.updateMatrix();
+                leftClone.applyMatrix4(transform.matrix);
+                geometries.push(leftClone);
 
-    let positionY=this.positionY-this.binHeight/2;//鏀灦鏌辩殑Y杞村潗鏍�
-
-    for(let i=0;i<this.binZNum+this.intervalRackNum;i++) {
-        let isRack=i%this.intervalRackNum;
-        if(isRack===0) {
-            let PositionZ=this.positionZ-shelfWidth/2+i*this.binWidth+this.rackWidth/2;
-            if(i>=this.binZNum) {
-                PositionZ=PositionZ-this.rackWidth;
+                let rightClone = planeRackBoxGeometry.clone();
+                positionY = this.positionY + this.bottomHight + j*this.binHeight + 1;
+                positionZ = - ( this.positionZ + i * this.binWidth + this.binWidth/2 );
+                transform.position.set(this.positionX + 13, positionY, positionZ);
+                transform.updateMatrix();
+                rightClone.applyMatrix4(transform.matrix);
+                geometries.push(rightClone);
+            } else {
+                let clone = planeBoxGeometry.clone();
+                let positionY= this.positionY + this.bottomHight + j*this.binHeight + 1;
+                let positionZ= - ( this.positionZ + i * this.binWidth + this.binWidth/2 );
+                transform.position.set(this.positionX-this.rackLengh/2,positionY,positionZ);
+                transform.updateMatrix();
+                clone.applyMatrix4(transform.matrix);
+                geometries.push(clone);
             }
-
-            let leftRack=rackObject.clone();
-            group.add(leftRack);
-            leftRack.position.set(leftPositionX,positionY,PositionZ);
-            leftRack.updateMatrix();
-            combineGeometry.merge(leftRack.geometry, leftRack.matrix);
-            let rightRack=rackObject.clone();
-            group.add(rightRack);
-            rightRack.position.set(rightPositionX,positionY,PositionZ);
-            rightRack.updateMatrix();
-            combineGeometry.merge(rightRack.geometry, rightRack.matrix);
         }
     }
-    //鍒涘缓鎵樻澘
-    for(let i=0;i<this.binZNum;i++) {
-        for (let j = 0; j < this.binYNum; j++) {
 
-            let positionY=this.positionY-this.binHeight/2-shelfHeight/2+this.bottomHight+j*this.binHeight;
-            let positionZ=this.positionZ-shelfWidth/2+this.binWidth/2 + i * this.binWidth
-            let holderObj= holderObject.clone();
-            group.add(holderObj);
-            holderObj.position.set(this.positionX,positionY,positionZ);
-            holderObj.updateMatrix();
-            combineGeometry.merge(holderObj.geometry, holderObj.matrix);
-        }
-    }
-    let shelf= new THREE.Mesh(combineGeometry, shlefMat);
-    shelf.uuid=option.No;
-    shelf.name=option.Name;
-    shelf.type="StoreShelf";
-    return group;
+    let mergedGeometry = BufferGeometryUtils.mergeBufferGeometries(geometries);
+    let mesh = new THREE.Mesh(mergedGeometry, shelfMat);
+    mesh.castShadow = true;
+    this.mesh = mesh;
+    return this;
 }
+
+export {StoreShelf}

--
Gitblit v1.9.1