| | |
| | | |
| | | let _flowAnimationContainer;//水流动画容器 |
| | | let _flowImgSrc = "https://static.bimface.com/attach/34d0d3aeb2e348aea5f3203b760ca667_flow5.png";//水流材质图片 |
| | | let _flowImgLocal = "../img/flowEffect.png";//本地水流材质图片 |
| | | let _flowEffectList = new Set();//水流动画列表 |
| | | |
| | | //初始化水流动画容器 |
| | | function initialFlowAnimationContainer() { |
| | | if (_flowAnimationContainer == null) { |
| | | // 构造水流材质容器 |
| | | _flowAnimationContainer = new Glodon.Bimface.Plugins.Material.MaterialContainer(); |
| | | } |
| | | } |
| | | |
| | | //创建水流材质 |
| | | function createFlowMaterial(data) { |
| | | initialFlowAnimationContainer(); |
| | | // 构造材质配置 |
| | | let flowMaterialConfig = new Glodon.Bimface.Plugins.Material.MaterialConfig(); |
| | | flowMaterialConfig.viewer = _viewer; |
| | | flowMaterialConfig.src = _flowImgSrc; |
| | | flowMaterialConfig.rotation = data.rotation; |
| | | flowMaterialConfig.offset = [0, 0]; |
| | | flowMaterialConfig.scale = [0.1524, 0.1524]; |
| | | flowMaterialConfig.id = "flow-material-" + data.id; |
| | | // 构造材质对象 |
| | | let flowMaterial = new Glodon.Bimface.Plugins.Material.Material(flowMaterialConfig); |
| | | _flowAnimationContainer.addMaterial(flowMaterial); |
| | | flowMaterial.overrideComponentsMaterialById([data.id]);//数组 |
| | | return flowMaterial; |
| | | } |
| | | |
| | | //创建水流动画 |
| | | function createFlowEffect(material, data) { |
| | | // 构造水流动画配置 |
| | | let flowEffectConfig = new Glodon.Bimface.Plugins.Animation.FlowEffectConfig(); |
| | | flowEffectConfig.material = material; |
| | | flowEffectConfig.speed = [data.speed, 0]; |
| | | flowEffectConfig.viewer = _viewer; |
| | | flowEffectConfig.id = "flow-effect-" + data.id; |
| | | //构造水流动画 |
| | | let flowEffect = new Glodon.Bimface.Plugins.Animation.FlowEffect(flowEffectConfig); |
| | | _flowEffectList.add(flowEffect); |
| | | return flowEffect; |
| | | } |
| | | |
| | | //重绘水流动画 |
| | | function renderFlowEffect() { |
| | | // 渲染三维模型,加载图片资源需要时间,此处设定了500ms的延迟 |
| | | setTimeout("_viewer.render()", 500); |
| | | } |
| | | |
| | | //开始所有水流动画 |
| | | function playAllFlowEffectList() { |
| | | if (_flowEffectList.size > 0) { |
| | | _flowEffectList.forEach(x => x.play()); |
| | | } |
| | | } |
| | | |
| | | //停止所有水流动画 |
| | | function stopAllFlowEffectList() { |
| | | if (_flowEffectList.size > 0) { |
| | | _flowEffectList.forEach(x => x.stop()); |
| | | } |
| | | } |
| | | |
| | | //加载水流材质 |
| | | function loadFlowMaterial(data) { |
| | | unloadAllFlowMaterialList(); |
| | | let flowMaterial = createFlowMaterial(data); |
| | | let flowEffect = createFlowEffect(flowMaterial, data); |
| | | //加载水流动画 |
| | | function loadFlowEffect(item) { |
| | | unloadFlowMaterial(); |
| | | let flowMaterial = createFlowMaterial(item); |
| | | let flowEffect = createFlowEffect(flowMaterial, item); |
| | | flowEffect.play(); |
| | | renderFlowEffect(); |
| | | } |
| | | |
| | | //加载所有水流材质 |
| | | function loadAllFlowMaterialList(data) { |
| | | unloadAllFlowMaterialList(); |
| | | //加载水流动画列表 |
| | | function loadFlowEffectList(data) { |
| | | unloadFlowMaterial(); |
| | | if (data != null && data.length > 0) { |
| | | data.foreach(x => { |
| | | data.forEach((x, index) => { |
| | | let flowMaterial = createFlowMaterial(x); |
| | | let flowEffect = createFlowEffect(flowMaterial, x); |
| | | createFlowEffect(flowMaterial, x); |
| | | }); |
| | | playAllFlowEffectList(); |
| | | playFlowEffect(); |
| | | renderFlowEffect(); |
| | | } |
| | | } |
| | | |
| | | //通过id卸载水流材质 |
| | | function uploadFlowMaterialById(id) { |
| | | function unloadFlowMaterialById(id) { |
| | | if (_flowEffectList.size > 0) { |
| | | let flowEffectId = "flow-effect-" + id; |
| | | let flowEffectId = getFlowEffectId(id); |
| | | let flowEffect = null; |
| | | _flowEffectList.forEach(x => { |
| | | if (x.getId() == flowEffectId) { |
| | |
| | | } |
| | | }); |
| | | if (flowEffect != null) { |
| | | flowEffect.stop(); |
| | | //flowEffect.stop(); |
| | | _flowEffectList.delete(flowEffect); |
| | | let flowMaterialId = "flow-material-" + id; |
| | | let flowMaterialId = getFlowMaterialId(id); |
| | | initialFlowAnimationContainer(); |
| | | let flowMaterial = _flowAnimationContainer.getMaterialById(flowMaterialId) |
| | | if (flowMaterial != null) { |
| | |
| | | } |
| | | |
| | | //卸载水流材质 |
| | | function unloadAllFlowMaterialList() { |
| | | function unloadFlowMaterial() { |
| | | if (_flowEffectList.size > 0) { |
| | | _flowEffectList.forEach(x => { |
| | | x.stop(); |
| | | }); |
| | | //_flowEffectList.forEach(x => { |
| | | // x.stop(); |
| | | //}); |
| | | _flowEffectList.clear(); |
| | | clearFlowMaterial(); |
| | | } |
| | | initialFlowAnimationContainer(); |
| | | let flowMaterial = _flowAnimationContainer.getMaterialById(id) |
| | | if (flowMaterial != null) { |
| | | flowMaterial.clearOverrideComponentsMaterial(); |
| | | _flowAnimationContainer.removeMaterialById(id) |
| | | initialFlowAnimationContainer(); |
| | | let allMaterialList = _flowAnimationContainer.getAllMaterials(); |
| | | if (allMaterialList != null && allMaterialList.length > 0) { |
| | | allMaterialList.foreach(x => { |
| | | x.clearOverrideComponentsMaterial(); |
| | | }); |
| | | } |
| | | _flowAnimationContainer.clear(); |
| | | } |
| | | } |
| | | |
| | | //清除流量水质 |
| | | function clearFlowMaterial() { |
| | | initialFlowAnimationContainer(); |
| | | var allMaterialList = _flowAnimationContainer.getAllMaterials(); |
| | | if (allMaterialList != null && allMaterialList.length > 0) { |
| | | allMaterialList.foreach(x => { |
| | | x.clearOverrideComponentsMaterial(); |
| | | }); |
| | | //初始化水流动画容器 |
| | | function initialFlowAnimationContainer() { |
| | | if (_flowAnimationContainer == null) { |
| | | // 构造水流材质容器 |
| | | _flowAnimationContainer = new Glodon.Bimface.Plugins.Material.MaterialContainer(); |
| | | } |
| | | _flowAnimationContainer.clear(); |
| | | } |
| | | |
| | | //创建水流材质 |
| | | 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); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |