duheng
2024-11-03 28402b6df09de5e106422878246f7ac814d353b0
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 
let _flowAnimationContainer;//水流动画容器
let _flowImgSrc = "https://static.bimface.com/attach/34d0d3aeb2e348aea5f3203b760ca667_flow5.png";//水流材质图片
let _flowImgLocal = "../img/flowEffect.png";//本地水流材质图片
let _flowEffectList = new Set();//水流动画列表
 
 
 
 
//加载水流动画
function loadFlowEffect(item) {
    unloadFlowMaterial();
    let flowMaterial = createFlowMaterial(item);
    let flowEffect = createFlowEffect(flowMaterial, item);
    flowEffect.play();
    renderFlowEffect();
}
 
//加载水流动画列表
function loadFlowEffectList(data) {
    unloadFlowMaterial();
    if (data != null && data.length > 0) {
        data.forEach((x, index) => {
            let flowMaterial = createFlowMaterial(x);
            createFlowEffect(flowMaterial, x);
        });
        playFlowEffect();
        renderFlowEffect();
    }
}
 
//通过id卸载水流材质
function unloadFlowMaterialById(id) {
    if (_flowEffectList.size > 0) {
        let flowEffectId = getFlowEffectId(id);
        let flowEffect = null;
        _flowEffectList.forEach(x => {
            if (x.getId() == flowEffectId) {
                flowEffect = x;
            }
        });
        if (flowEffect != null) {
            //flowEffect.stop();
            _flowEffectList.delete(flowEffect);
            let flowMaterialId = getFlowMaterialId(id);
            initialFlowAnimationContainer();
            let flowMaterial = _flowAnimationContainer.getMaterialById(flowMaterialId)
            if (flowMaterial != null) {
                flowMaterial.clearOverrideComponentsMaterial();
                _flowAnimationContainer.removeMaterialById(flowMaterialId)
            }
        }
    }
}
 
//卸载水流材质
function unloadFlowMaterial() {
    if (_flowEffectList.size > 0) {
        //_flowEffectList.forEach(x => {
        //    x.stop();
        //});
        _flowEffectList.clear();
        initialFlowAnimationContainer();
        let allMaterialList = _flowAnimationContainer.getAllMaterials();
        if (allMaterialList != null && allMaterialList.length > 0) {
            allMaterialList.foreach(x => {
                x.clearOverrideComponentsMaterial();
            });
        }
        _flowAnimationContainer.clear();
    }
}
 
//初始化水流动画容器
function initialFlowAnimationContainer() {
    if (_flowAnimationContainer == null) {
        // 构造水流材质容器
        _flowAnimationContainer = new Glodon.Bimface.Plugins.Material.MaterialContainer();
    }
}
 
//创建水流材质
function createFlowMaterial(item) {
    initialFlowAnimationContainer();
    // 构造材质配置 
    let flowMaterialConfig = new Glodon.Bimface.Plugins.Material.MaterialConfig();
    flowMaterialConfig.viewer = _viewer;
    flowMaterialConfig.src = _flowImgSrc;
    flowMaterialConfig.rotation = item.rotation;
    flowMaterialConfig.offset = [0, 0];
    flowMaterialConfig.scale = [0.1524, 0.1524];
    flowMaterialConfig.id = getFlowMaterialId(item.id);
    // 构造材质对象 
    let flowMaterial = new Glodon.Bimface.Plugins.Material.Material(flowMaterialConfig);
    _flowAnimationContainer.addMaterial(flowMaterial);
    flowMaterial.overrideComponentsMaterialById([item.id]);//数组
    return flowMaterial;
}
 
//创建水流动画
function createFlowEffect(material, item) {
    // 构造水流动画配置
    let flowEffectConfig = new Glodon.Bimface.Plugins.Animation.FlowEffectConfig();
    flowEffectConfig.material = material;
    flowEffectConfig.speed = [item.speed, 0];
    flowEffectConfig.viewer = _viewer;
    flowEffectConfig.id = getFlowEffectId(item.id);
    //构造水流动画
    let flowEffect = new Glodon.Bimface.Plugins.Animation.FlowEffect(flowEffectConfig);
    _flowEffectList.add(flowEffect);
    return flowEffect;
}
 
//获取水流动画id
function getFlowEffectId(id) {
    return "flow-effect-" + id;
}
 
//获取水流材质id
function getFlowMaterialId(id) {
    return "flow-material-" + id;
}
 
//开始水流动画
function playFlowEffect() {
    if (_flowEffectList.size > 0) {
        _flowEffectList.forEach(x => x.play());
    }
}
 
//停止水流动画
function stopFlowEffect() {
    if (_flowEffectList.size > 0) {
        _flowEffectList.forEach(x => x.stop());
    }
}
 
//重绘水流动画 
function renderFlowEffect() {
    // 渲染三维模型,加载图片资源需要时间,此处设定了500ms的延迟
    setTimeout("_viewer.render()", 500);
}