lixiaojun
2025-04-09 9aa8106d88fc3070498493e2819922f7ac31746e
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
let _flowImgSrc = "https://static.bimface.com/attach/34d0d3aeb2e348aea5f3203b760ca667_flow5.png";//水流材质图片
let _flowImgLocal = _base64_flow_effect.FlowEffect;//本地水流材质图片,测试没有通过
let _flowEffectList = new Set();//水流动画列表
let _flowMaterialContainer;//水流材质容器
 
 
//加载水流动画列表
function loadFlowEffectList(data) {
    unloadFlowEffect();
    if (data != null && data.length > 0) {
        data.forEach(x => {
            let flowMaterial = createFlowMaterial(x);
            createFlowEffect(flowMaterial, x);
        });
        playFlowEffect();
    }
}
 
//加载水流动画
function loadFlowEffect(item) {
    unloadFlowEffect();
    let flowMaterial = createFlowMaterial(item);
    var flowEffect = createFlowEffect(flowMaterial, x);
    flowEffect.play();
}
 
//更新水流动画列表
function updateFlowEffectList(data) {
    if (data != null && data.length > 0) {
        if (_flowEffectList.size > 0) {
            let flowEffectId = getFlowEffectId(item.id);
            _flowEffectList.forEach(x => {
                if (x.getId() == flowEffectId) {
                    x.setSpeed([item.speedx, item.speedy]);
                }
            });
        }
    }
}
 
//更新水流动画
function updateFlowEffect(item) {
    if (_flowEffectList.size > 0) {
        let flowEffectId = getFlowEffectId(item.id);
        _flowEffectList.forEach(x => {
            if (x.getId() == flowEffectId) {
                x.setSpeed([item.speedx, item.speedy]);
            }
        });
    }
}
 
//卸载水流动画
function unloadFlowEffect() {
    if (_flowEffectList.size > 0) {
        _flowEffectList.forEach(x => x.stop());
        _flowEffectList.clear();
        if (_flowMaterialContainer != null) {
            let allMaterialList = _flowMaterialContainer.getAllMaterials();
            if (allMaterialList != null && allMaterialList.length > 0) {
                allMaterialList.forEach(x => {
                    x.clearOverrideComponentsMaterial();
                });
            }
        }
    }
}
 
//通过id卸载水流动画
function unloadFlowEffectById(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);
            if (_flowMaterialContainer != null) {
                let flowMaterialId = getFlowMaterialId(id);
                let flowMaterial = _flowMaterialContainer.getMaterialById(flowMaterialId)
                if (flowMaterial != null) {
                    flowMaterial.clearOverrideComponentsMaterial();
                }
            }
        }
    }
}
 
//创建水流动画
function createFlowEffect(material, item) {
    // 构造水流动画配置
    let flowEffectConfig = new Glodon.Bimface.Plugins.Animation.FlowEffectConfig();
    flowEffectConfig.material = material;
    flowEffectConfig.speed = [item.speedx, item.speedy];
    flowEffectConfig.viewer = _viewer;
    flowEffectConfig.id = getFlowEffectId(item.id);
    //构造水流动画
    let flowEffect = new Glodon.Bimface.Plugins.Animation.FlowEffect(flowEffectConfig);
    _flowEffectList.add(flowEffect);
    return flowEffect;
}
 
//创建水流材质
function createFlowMaterial(item) {
    //初始化水流材质容器
    initialFlowMaterialContainer();
    var flowMaterialId = getFlowMaterialId(item.id);
    let flowMaterial = _flowMaterialContainer.getMaterialById(flowMaterialId);
    if (flowMaterial == null) {
        // 构造材质配置 
        let flowMaterialConfig = new Glodon.Bimface.Plugins.Material.MaterialConfig();
        flowMaterialConfig.viewer = _viewer;
        flowMaterialConfig.src = _flowImgLocal;
        flowMaterialConfig.rotation = item.rotation;
        flowMaterialConfig.offset = [0, 0];
        flowMaterialConfig.scale = [0.1524, 0.1524];
        flowMaterialConfig.id = flowMaterialId;
        // 构造材质对象 
        flowMaterial = new Glodon.Bimface.Plugins.Material.Material(flowMaterialConfig);
        _flowMaterialContainer.addMaterial(flowMaterial);
    }
    flowMaterial.overrideComponentsMaterialById([item.id]);//数组
    return flowMaterial;
}
 
//初始化水流材质容器
function initialFlowMaterialContainer() {
    if (_flowMaterialContainer == null) {
        // 构造水流材质容器
        _flowMaterialContainer = new Glodon.Bimface.Plugins.Material.MaterialContainer();
    }
}
 
//获取水流动画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);
}