|  |  |  | 
|---|
|  |  |  | this.positionZ = option.position.z||0;//库位位置 | 
|---|
|  |  |  | this.rackLengh = 3;//支架的长度,默认设动为3 | 
|---|
|  |  |  | this.rackWidth = 3;//支架的宽度,默认设定为3 | 
|---|
|  |  |  | this.mesh = null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 材质 | 
|---|
|  |  |  | let shelfMat = new THREE.MeshPhysicalMaterial({ | 
|---|
|  |  |  | 
|---|
|  |  |  | transparent: false, | 
|---|
|  |  |  | opacity: 0.7 | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | //定义一个组合体 | 
|---|
|  |  |  | let group = new THREE.Group(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 货架总高 | 
|---|
|  |  |  | 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, shelfMat, 0); | 
|---|
|  |  |  | // 托板模型 + 材质 | 
|---|
|  |  |  | let planeBoxGeometry = new THREE.BoxGeometry(this.binLength, 2, this.binWidth+this.rackWidth);  // 覆盖多一根支架宽度 | 
|---|
|  |  |  | let planeObject=new THREE.Mesh(planeBoxGeometry, shelfMat, 0); | 
|---|
|  |  |  | let planeRackBoxGeometry = new THREE.BoxGeometry(3, 2, this.binWidth+this.rackWidth); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // Y轴定位 | 
|---|
|  |  |  | let positionY = this.positionY + shelfHeight / 2; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 positionZ = - ( this.positionZ + i*this.binWidth ); | 
|---|
|  |  |  | // ----- | 
|---|
|  |  |  | let leftClone = rackBoxGeometry.clone(); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 初始化托板模型 | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 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 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 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 mergedGeometry = BufferGeometryUtils.mergeBufferGeometries(geometries); | 
|---|
|  |  |  | var mesh = new THREE.Mesh(mergedGeometry, shelfMat); | 
|---|
|  |  |  | let mesh = new THREE.Mesh(mergedGeometry, shelfMat); | 
|---|
|  |  |  | mesh.castShadow = true; | 
|---|
|  |  |  | return mesh; | 
|---|
|  |  |  | this.mesh = mesh; | 
|---|
|  |  |  | return this; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export {StoreShelf} | 
|---|