Skip to content

Commit

Permalink
change api, remove start() / stop(), add hide()
Browse files Browse the repository at this point in the history
  • Loading branch information
hongfaqiu committed Jul 30, 2021
1 parent c2f5148 commit 54e60f9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cesium-particle",
"version": "0.4.4",
"version": "0.5.0",
"description": "cesium particle system module",
"main": "src/index.js",
"scripts": {
Expand Down
16 changes: 8 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ var particleObj2 = new Particle3D(viewer, {
});

particleObj.init().then(res => {
particleObj.start(); // 开始运行粒子系统
particleObj.show(); // 开始运行粒子系统
})

systemOptions.fadeOpacity = 0.900;
particleObj.optionsChange(systemOptions); // 更新粒子系统配置

particleObj.stop(); // 停止粒子系统
particleObj.hide(); // 停止粒子系统
particleObj.remove(); // 移除粒子系统
```

Expand Down Expand Up @@ -157,19 +157,19 @@ defaultColorTable = [[1.0, 1.0, 1.0]];

### ``init()``

粒子系统初始化(异步),若未初始化,直接调用start(),将自动初始化
粒子系统初始化(异步)

### ``start()``
### ``show()``

粒子系统开始运行,在窗口移动、大小变更、地球缩放、视点相机移动时粒子系统会暂停,停止操作后继续运行

### ``optinsChange(options)``
### ``hide()``

传入粒子系统配置参数,更新粒子运行状态
暂停运行粒子系统

### ``stop()``
### ``optinsChange(options)``

暂停运行粒子系统
传入粒子系统配置参数,更新粒子运行状态

### ``remove()``

Expand Down
42 changes: 27 additions & 15 deletions src/modules/particle3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class Particle3D {
this.type = type;
this.fields = fields;
this.colorTable = colorTable;
this.primitives = [];

this.viewerParameters = {
lonRange: new Cesium.Cartesian2(),
Expand All @@ -53,7 +54,6 @@ export default class Particle3D {
lonDisplayRange: new Cesium.Cartesian2(),
latDisplayRange: new Cesium.Cartesian2()
};
this.ok = false;
// use a smaller earth radius to make sure distance to camera > 0
this.globeBoundingSphere = new Cesium.BoundingSphere(Cesium.Cartesian3.ZERO, 0.99 * 6378137.0);
}
Expand All @@ -66,7 +66,6 @@ export default class Particle3D {
this.particleSystem = new ParticleSystem(this.scene.context, data,
this.userInput, this.viewerParameters, this.colour);
this.addPrimitives();
this.ok = true;
} catch (e) {
console.error(e)
throw (e);
Expand All @@ -75,13 +74,24 @@ export default class Particle3D {

addPrimitives() {
// the order of primitives.add() should respect the dependency of primitives
this.scene.primitives.add(this.particleSystem.particlesComputing.primitives.calculateSpeed);
this.primitives = [
this.particleSystem.particlesComputing.primitives.calculateSpeed,
this.particleSystem.particlesComputing.primitives.updatePosition,
this.particleSystem.particlesComputing.primitives.postProcessingPosition,
this.particleSystem.particlesRendering.primitives.segments,
this.particleSystem.particlesRendering.primitives.trails,
this.particleSystem.particlesRendering.primitives.screen,
]
for (let primitive of this.primitives) {
this.scene.primitives.add(primitive);
}
/* this.scene.primitives.add(this.particleSystem.particlesComputing.primitives.calculateSpeed);
this.scene.primitives.add(this.particleSystem.particlesComputing.primitives.updatePosition);
this.scene.primitives.add(this.particleSystem.particlesComputing.primitives.postProcessingPosition);
this.scene.primitives.add(this.particleSystem.particlesRendering.primitives.segments);
this.scene.primitives.add(this.particleSystem.particlesRendering.primitives.trails);
this.scene.primitives.add(this.particleSystem.particlesRendering.primitives.screen);
this.scene.primitives.add(this.particleSystem.particlesRendering.primitives.screen); */
}

updateViewerParameters() {
Expand Down Expand Up @@ -123,13 +133,12 @@ export default class Particle3D {
}
}

start() {
if (!this.ok) {
this.init();
show() {
let that = this;
for (let primitive of that.primitives) {
primitive.show = true;
}
const that = this;
that.scene.primitives.show = true;
this.setupEventListeners();
that.setupEventListeners();
var animate = function () {
that.viewer.resize();
that.viewer.scene.requestRender();
Expand All @@ -138,16 +147,19 @@ export default class Particle3D {
animate();
}

stop() {
this.scene.primitives.show = false;
hide() {
for (let primitive of this.primitives) {
primitive.show = false;
}
this.viewer.scene.requestRender();
this.removeEventListeners();
window.cancelAnimationFrame(this.animate);
}

remove() {
this.stop();
this.scene.primitives.removeAll();
this.ok = false;
this.hide();
for (let primitive of this.primitives) {
this.scene.primitives.remove(primitive);
}
}
}

0 comments on commit 54e60f9

Please sign in to comment.