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
/**
 * 立方体类
 * 我们生活中很多的物体都可以归结为立方体类,比如墙体,地板,窗户等都可看成是立方体类
 * @param option
 * @constructor
 */
function Cube(option) {
    this.length = option.length || 1;
    this.width = option.width || 1;
    this.height = option.height || 1;
    this.Name = option.objName;
 
    this.positionX = option.position.x || 0;
    this.positionY = option.position.y || 0;
    this.positionZ = option.position.z || 0;
    this.style = option.style || {color: 0xFF0000};
    this.stypeType = this.style.type || 0;
 
    let curmaterial = CommonFunction.createMaterial(this.width, this.height, this.style);
    //如果六个面需要单独处理材质的话
 
    if (this.stypeType == 1) {
        curmaterial = [];
        curmaterial.push(CommonFunction.createMaterial(this.width, this.height, this.style.up));
        curmaterial.push(CommonFunction.createMaterial(this.width, this.height, this.style.down));
        curmaterial.push(CommonFunction.createMaterial(this.width, this.height, this.style.right));
        curmaterial.push(CommonFunction.createMaterial(this.width, this.height, this.style.left));
        curmaterial.push(CommonFunction.createMaterial(this.width, this.height, this.style.fore));
        curmaterial.push(CommonFunction.createMaterial(this.width, this.height, this.style.behind));
    }
    let cubeGeometry = new THREE.BoxGeometry(this.length, this.height, this.width);
 
    let cube = new THREE.Mesh(cubeGeometry, curmaterial);
    cube.name = this.Name;
    cube.position.x = this.positionX;
    cube.position.y = this.positionY;
    cube.position.z = this.positionZ;
    return cube;
}