#
luxiaotao1123
2021-12-15 4d317e08d281b9e5e2cf742788c3d4b5b6bb9b38
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
function CommonFunction() {
}
 
/**
 * 判断当前对象是否为空对象
 */
CommonFunction.hasObj = function (obj) {
    if (obj != null && typeof (obj) != "undefined") {
        return true;
    } else {
        return false;
    }
},
    /**
     * 创建材质
     * length:材质的长
     * width:材质宽度
     * style:材质特性
     */
    CommonFunction.createMaterial = function (length, width, style) {
        var color = 0xFF0000;//材质的颜色
        var image = null;//才是是否有贴图
        var texture = null;
        var allowRepeat = 0;//贴图是否设置重复显示
        var transparent = 0;//材质是否透明
        var opacity = 0;//材质透明度
        var depthTest = 1;//材质深度测试
        if (CommonFunction.hasObj(style)) {
            color = style.color || 0xFF0000;
            image = style.image || null;
            allowRepeat = style.allowRepeat || 0;
            transparent = style.transparent || 0;
            opacity = style.opacity || 0;
            depthTest = style.depthTest;
        }
        let material = new THREE.MeshPhongMaterial({map: texture, color: color});
        if (image != null) {
            texture = new THREE.TextureLoader().load(image);
            if (allowRepeat == 1) {
                texture.repeat.x = length / 128;
                texture.repeat.y = width / 128;
                texture.repeat.y = 5;
                texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
 
            }
            material = new THREE.MeshPhongMaterial({map: texture});
        }
        if (transparent == 1) {
            material.transparent = true;
        }
        if (depthTest == 0) {
            material.depthTest = false;
        }
        material.opacity = opacity;
        return material;
    }
/**
 * 转换坐标
 * positionOri:原始坐标
 * positionTrans:转换坐标
 */
 
CommonFunction.transPosition=function(positionOri,positionTrans)
{
 
    positionOri.X = positionOri.X + positionTrans.X;
    positionOri.Y = positionOri.Y + positionTrans.Y;
    positionOri.Z = positionOri.Z + positionTrans.Z;
    return positionOri;
}