#
luxiaotao1123
2022-06-28 9d2fb8eb69b8ec958ef9ea20f135f8ef8bd73a74
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
94
95
96
97
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.rackLengh = 3;//支架的长度,默认设动为3
    this.rackWidth = 3;//支架的宽度,默认设定为3
    this.mesh = null;
 
    // 材质
    let shelfMat = new THREE.MeshPhysicalMaterial({
        color: 0x175EC0,
        transparent: false,
        opacity: 0.7
    });
 
    // 货架总高
    let shelfHeight=this.bottomHight+(this.binYNum)*this.binHeight;
    // 支架模型 + 材质
    let rackBoxGeometry=new THREE.BoxGeometry(this.rackLengh,shelfHeight,this.rackWidth);
    // 托板模型 + 材质
    let planeBoxGeometry = new THREE.BoxGeometry(this.binLength, 2, this.binWidth+this.rackWidth);  // 覆盖多一根支架宽度
    let planeRackBoxGeometry = new THREE.BoxGeometry(3, 2, this.binWidth+this.rackWidth);
 
    // Y轴定位
    let positionY = this.positionY + shelfHeight / 2;
 
    //左侧支架柱的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 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);
 
        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++) {
            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 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);
    let mesh = new THREE.Mesh(mergedGeometry, shelfMat);
    mesh.castShadow = true;
    this.mesh = mesh;
    return this;
}
 
export {StoreShelf}