luxiaotao1123
2021-11-17 85d878b12d6988ca2275d60e7da0ec31814f8fc8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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.rackLengh = 3;//支架的长度,默认设动为3
    this.rackWidth = 3;//支架的宽度,默认设定为3
    this.intervalRackNum=2;//间隔多少库位有一个主支架
 
    let binHolderPlane=new THREE.BoxGeometry(this.binLength,2,this.binWidth);//定义一个跟库位长宽相同的几何体,作为托盘
 
    let shlefMat = new THREE.MeshLambertMaterial({color:0x175EC0});//定义支架和托盘的材质
 
    let group = new THREE.Group();//定义一个组合体
    //合并模型,则使用merge方法合并
    let combineGeometry = new THREE.Geometry();
    /*
     支架的高=最底层的高度+(库位数-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 );
 
    let plane = new THREE.BoxGeometry(this.binLength, 2, this.binWidth);
    let holderObject = new THREE.Mesh(plane, shlefMat,0);
 
    let leftPositionX=this.positionX-this.binLength/2+this.rackLengh/2;//左侧支架柱的X轴条码
    let rightPositionX=this.positionX+this.binLength/2-this.rackLengh/2;//右侧支架柱的X轴条码
 
 
    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 leftRack=rackObject.clone();
            leftRack.position.set(leftPositionX,positionY,PositionZ);
            leftRack.updateMatrix();
            combineGeometry.merge(leftRack.geometry, leftRack.matrix);
            let rightRack=rackObject.clone();
            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();
            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 shelf;
}