|  |  |  | 
|---|
|  |  |  | 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;//间隔多少库位有一个主支架 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // let binHolderPlane=new THREE.BoxGeometry(this.binLength,2,this.binWidth);//定义一个跟库位长宽相同的几何体,作为托盘 | 
|---|
|  |  |  | // 材质 | 
|---|
|  |  |  | let shelfMat = new THREE.MeshPhysicalMaterial({ | 
|---|
|  |  |  | color: 0x175EC0, | 
|---|
|  |  |  | transparent: true, | 
|---|
|  |  |  | opacity: 0.7 | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | //定义一个组合体 | 
|---|
|  |  |  | let group = new THREE.Group(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //定义支架和托盘的材质 | 
|---|
|  |  |  | 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. | 
|---|
|  |  |  | // 这模拟了非金属材料的反射率。 当metalness为1.0时无效 | 
|---|
|  |  |  | // reflectivity: 0.5, | 
|---|
|  |  |  | }) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | let group = new THREE.Group();//定义一个组合体 | 
|---|
|  |  |  | //合并模型,则使用merge方法合并 | 
|---|
|  |  |  | let combineGeometry = new THREE.BufferGeometry(); | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 支架的高=最底层的高度+(库位数-1)*库位的高度 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | let shelfHeight=this.bottomHight+(this.binYNum-1)*this.binHeight; | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 支架的宽=库位数乘以库位的宽度 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | // 货架总高 | 
|---|
|  |  |  | let shelfHeight=this.bottomHight+(this.binYNum)*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 ); | 
|---|
|  |  |  | // 支架模型 + 材质 | 
|---|
|  |  |  | let rackBoxGeometry=new THREE.BoxGeometry(this.rackLengh,shelfHeight,this.rackWidth); | 
|---|
|  |  |  | let rackObject=new THREE.Mesh(rackBoxGeometry, shelfMat, 0); | 
|---|
|  |  |  | // 托板模型 + 材质 | 
|---|
|  |  |  | let planeBoxGeometry = new THREE.BoxGeometry(this.binLength, 2, this.binWidth+this.rackWidth);  // 覆盖多一根支架宽度 | 
|---|
|  |  |  | let planeObject=new THREE.Mesh(planeBoxGeometry, shelfMat, 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | let plane = new THREE.BoxGeometry(this.binLength, 2, this.binWidth); | 
|---|
|  |  |  | let holderObject = new THREE.Mesh(plane, shlefMat,0); | 
|---|
|  |  |  | // Y轴定位 | 
|---|
|  |  |  | let positionY = this.positionY + shelfHeight / 2; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | let leftPositionX=this.positionX-this.binLength/2+this.rackLengh/2;//左侧支架柱的X轴条码 | 
|---|
|  |  |  | let rightPositionX=this.positionX+this.binLength/2-this.rackLengh/2;//右侧支架柱的X轴条码 | 
|---|
|  |  |  | //左侧支架柱的X轴定位 | 
|---|
|  |  |  | let leftPositionX=this.positionX-this.binLength/2; | 
|---|
|  |  |  | //右侧支架柱的X轴定位 | 
|---|
|  |  |  | let rightPositionX=this.positionX+this.binLength/2 - this.rackLengh;    // 缩进支架长度 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | let geometries = []; | 
|---|
|  |  |  | let transform = new THREE.Object3D(); | 
|---|
|  |  |  | // 初始化支架模型 | 
|---|
|  |  |  | for(let i=0;i<=this.binZNum;i++) { | 
|---|
|  |  |  | // let leftRack = rackObject.clone(); | 
|---|
|  |  |  | // let positionZ = - ( this.positionZ + i*this.binWidth ); | 
|---|
|  |  |  | // leftRack.position.set(leftPositionX,positionY,positionZ); | 
|---|
|  |  |  | // leftRack.updateMatrix(); | 
|---|
|  |  |  | // group.add(leftRack); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // let rightRack = rackObject.clone(); | 
|---|
|  |  |  | // rightRack.position.set(rightPositionX,positionY,positionZ); | 
|---|
|  |  |  | // rightRack.updateMatrix(); | 
|---|
|  |  |  | // group.add(rightRack); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | let positionY=this.positionY-this.binHeight/2;//支架柱的Y轴坐标 | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 = 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++) { | 
|---|
|  |  |  | // let plane = planeObject.clone(); | 
|---|
|  |  |  | // let positionY= this.positionY + this.bottomHight + j*this.binHeight + 1; | 
|---|
|  |  |  | // let positionZ= - ( this.positionZ + i * this.binWidth + this.binWidth/2 ); | 
|---|
|  |  |  | // plane.position.set(this.positionX-this.rackLengh/2,positionY,positionZ); | 
|---|
|  |  |  | // plane.updateMatrix(); | 
|---|
|  |  |  | // group.add(plane); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //创建托板 | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | return  new THREE.Mesh(mergedGeometry, shelfMat); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export {StoreShelf} | 
|---|