|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取类 | 
|---|
|  |  |  | * @param optionGroup | 
|---|
|  |  |  | * @param optionBin | 
|---|
|  |  |  | * @constructor | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | function StoreGoods(optionGroup,optionBin) { | 
|---|
|  |  |  | import {MTLLoader} from "../lib/MTLLoader.js"; | 
|---|
|  |  |  | import {OBJLoader} from "../lib/OBJLoader.js"; | 
|---|
|  |  |  | import * as THREE from '../three.module.js'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | const palletX = -18; | 
|---|
|  |  |  | const palletY = 2; | 
|---|
|  |  |  | const palletZ = -46; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | const goodsX = -17; | 
|---|
|  |  |  | const goodsY = 5; | 
|---|
|  |  |  | const goodsZ = -6; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.no=optionBin.No; | 
|---|
|  |  |  | this.name=optionBin.Name; | 
|---|
|  |  |  | function StoreGoods(object, data, shelf) { | 
|---|
|  |  |  | let that = this; | 
|---|
|  |  |  | that.data = data; | 
|---|
|  |  |  | that.object = object; | 
|---|
|  |  |  | that.shelf = shelf; | 
|---|
|  |  |  | let palletList = []; | 
|---|
|  |  |  | let goodsList = []; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.length=optionGroup.BinLength-6; | 
|---|
|  |  |  | this.width=optionGroup.BinWidth-6; | 
|---|
|  |  |  | this.height=optionGroup.BinHeight-6; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | palletList.map(item => { | 
|---|
|  |  |  | let clone = obj.clone(); | 
|---|
|  |  |  | let positionX = that.shelf.positionX || 0; | 
|---|
|  |  |  | let positionY = that.shelf.bottomHight + (item.lev1-1)*that.shelf.binHeight || 0; | 
|---|
|  |  |  | let positionZ = (item.bay1-1)*-that.shelf.binHeight || 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | clone.name = item.loc_no + "-" + "Pallet"; | 
|---|
|  |  |  | clone.position.x = palletX + positionX; | 
|---|
|  |  |  | clone.position.y = palletY + positionY; | 
|---|
|  |  |  | clone.position.z = palletZ + positionZ; | 
|---|
|  |  |  | that.object.addObject(clone); | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 = that.shelf.positionX || 0; | 
|---|
|  |  |  | let positionY = that.shelf.bottomHight + (item.lev1-1)*that.shelf.binHeight || 0; | 
|---|
|  |  |  | let positionZ = (item.bay1-1)*-that.shelf.binHeight || 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | clone.name = item.loc_no + "-" + "Goods"; | 
|---|
|  |  |  | clone.position.x = goodsX + positionX; | 
|---|
|  |  |  | clone.position.y = goodsY + positionY; | 
|---|
|  |  |  | clone.position.z = goodsZ + positionZ; | 
|---|
|  |  |  | that.object.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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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} | 
|---|