|
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);
|
}
|