|  |  |  | 
|---|
|  |  |  | import * as THREE from '../three.module.js'; | 
|---|
|  |  |  | import * as BufferGeometryUtils from '../utils/BufferGeometryUtils.js'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const palletX = -2; | 
|---|
|  |  |  | const palletY = 0; | 
|---|
|  |  |  | const palletZ = -25; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const goodsX = -2; | 
|---|
|  |  |  | const goodsY = 22; | 
|---|
|  |  |  | const goodsZ = -25; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取类 | 
|---|
|  |  |  | * @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) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | let palletMat = new THREE.MeshPhysicalMaterial({ | 
|---|
|  |  |  | color: 0x637e97, | 
|---|
|  |  |  | transparent: false, | 
|---|
|  |  |  | opacity: 0.7 | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | let transform = new THREE.Object3D(); | 
|---|
|  |  |  | let geometries = []; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.no=optionBin.No; | 
|---|
|  |  |  | this.name=optionBin.Name; | 
|---|
|  |  |  | let palletGeometry = new THREE.BoxGeometry(30 ,2,40); | 
|---|
|  |  |  | transform.position.set(0 ,7, 0); | 
|---|
|  |  |  | transform.updateMatrix(); | 
|---|
|  |  |  | palletGeometry.applyMatrix4(transform.matrix); | 
|---|
|  |  |  | geometries.push(palletGeometry) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.length=optionGroup.BinLength-6; | 
|---|
|  |  |  | this.width=optionGroup.BinWidth-6; | 
|---|
|  |  |  | this.height=optionGroup.BinHeight-6; | 
|---|
|  |  |  | let palletLeftGeometry = new THREE.BoxGeometry(30 ,5,2); | 
|---|
|  |  |  | transform.position.set(0 ,5, -15); | 
|---|
|  |  |  | transform.updateMatrix(); | 
|---|
|  |  |  | palletLeftGeometry.applyMatrix4(transform.matrix); | 
|---|
|  |  |  | geometries.push(palletLeftGeometry) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | let palletRightGeometry = new THREE.BoxGeometry(30 ,5,2); | 
|---|
|  |  |  | transform.position.set(0 ,5, 15); | 
|---|
|  |  |  | transform.updateMatrix(); | 
|---|
|  |  |  | palletRightGeometry.applyMatrix4(transform.matrix); | 
|---|
|  |  |  | geometries.push(palletRightGeometry) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(optionBin.State=="1") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | this.color=0x46C191; | 
|---|
|  |  |  | this.opacity=0.8; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | let mergedGeometry = BufferGeometryUtils.mergeBufferGeometries(geometries); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | let palletObj = new THREE.Mesh(mergedGeometry, palletMat, 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | palletList.map(item => { | 
|---|
|  |  |  | let clone = palletObj.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 + "-" + "Pallet"; | 
|---|
|  |  |  | 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 + "-" + "Pallet"; | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 初始化货物模型 | 
|---|
|  |  |  | * @param scene 场景 | 
|---|
|  |  |  | * @param goodsList 货物数据列表 | 
|---|
|  |  |  | * @param ref 参照物 | 
|---|
|  |  |  | * @param type 参照物类型:1 - 货架;    2 - 输送线 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | function InitGoods(scene, goodsList, ref, type) { | 
|---|
|  |  |  | let goodsMat = new THREE.MeshPhysicalMaterial({ | 
|---|
|  |  |  | color: 0x93710c, | 
|---|
|  |  |  | transparent: false, | 
|---|
|  |  |  | opacity: 0.7 | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | let goodsGeometry = new THREE.BoxGeometry(27 ,30,35); | 
|---|
|  |  |  | let goodsObj = new THREE.Mesh(goodsGeometry, goodsMat, 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | goodsList.map(item => { | 
|---|
|  |  |  | let clone = goodsObj.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"; | 
|---|
|  |  |  | 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"; | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | }) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | init(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export {StoreGoods, InitPallet, InitGoods} | 
|---|