#
whycq
2021-12-08 4336201eb607f90a0011efdfee3a3f5928f94e4b
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
85
86
87
88
89
90
91
92
93
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.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 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();
            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);
        }
    }
    //创建托板
    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;
}