-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Particle Systems #5212
Particle Systems #5212
Changes from 1 commit
6103848
dccaaeb
b69ecc6
58c41ca
994fe50
1c07d77
0245f40
9644b85
eaf1cbd
8184286
adc2cc7
0d5b5b6
867c69c
2297924
1876ad6
4555cfb
1840d19
917c78a
80ad97a
fb4affd
7b475ac
a2ec79b
2f11ce0
ddb464f
f6baa2a
00406de
034a4f3
d165f45
2ecfa59
617c317
f64422f
d2959ba
64be343
fbc3ffc
6720615
98b1601
e52c608
de432ab
fc0493d
c2996a2
431ef2d
982fd09
4f5279b
72d8a5c
f34760f
64f782f
72bb6d7
2185bb4
4bd4cc4
54962e8
7a6b1d4
8de7a3b
ebc1427
c05f581
1a33efb
251bb1c
f76b890
e5e0998
dcacd47
a475545
3fc0e0b
c980b70
9821d5e
e372fa0
acd31e7
388f2d3
879e610
223ec9c
d16ab77
001d92c
2fb8637
ac6d4e0
5a46750
0a36b48
bbb128d
8a8626c
7e2a965
788d422
47c7a6d
76d6ccf
5b95fa2
f2b0a7b
319b9ce
de1dbcf
b49f8cd
ae54804
5be6977
d0d71b6
501abf5
8abd935
4789ff1
5fd4e4d
fda2fdb
b4806bb
4eeb893
e91de94
985498e
5d4d333
d37d322
def17e1
e3af3ea
b17adcf
08bd544
baddc32
ec341c6
cd4ffd8
41390b9
116d515
ce18cf8
f8de4ea
129772f
95fc96f
0e44fbd
70c191e
ec59d9f
2e5e510
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- workspaces
- pre-template-literals
- pre-prettier-v3
- pre-prettier
- pre-let-const
- post-workspaces
- post-template-literals
- post-prettier-v3
- post-prettier
- post-let-const
- cesium-workspaces
- 1.127
- 1.126
- 1.125
- 1.124
- 1.123.1
- 1.123
- 1.122
- 1.121.1
- 1.121
- 1.120
- 1.119
- 1.118.2
- 1.118.1
- 1.118
- 1.117
- 1.116
- 1.115
- 1.114
- 1.113
- 1.112
- 1.111
- 1.111-release
- 1.110.1
- 1.110
- 1.109
- 1.108
- 1.107.2
- 1.107.1
- 1.107
- 1.106.1
- 1.106
- 1.105.2
- 1.105.1
- 1.105
- 1.104
- 1.103
- 1.102
- 1.101
- 1.100
- 1.99
- 1.98.1
- 1.98
- 1.97
- 1.96
- 1.95
- 1.94.3
- 1.94.2
- 1.94.1
- 1.94
- 1.93
- 1.92
- 1.91
- 1.90
- 1.89
- 1.88
- 1.87.1
- 1.87
- 1.86.1
- 1.86
- 1.85
- 1.84
- 1.83
- 1.82
- 1.81
- 1.80
- 1.79.1
- 1.79
- 1.78
- 1.77
- 1.76
- 1.75
- 1.74
- 1.73
- 1.72
- 1.71
- 1.70.1
- 1.70
- 1.69
- 1.68
- 1.67
- 1.66
- 1.65
- 1.64
- 1.63.1
- 1.63
- 1.62
- 1.61
- 1.60
- 1.59
- 1.58.1
- 1.58
- 1.57
- 1.56.1
- 1.56
- 1.55
- 1.54
- 1.53
- 1.52
- 1.51
- 1.50
- 1.49
- 1.48
- 1.47
- 1.46
- 1.45
- 1.44
- 1.43
- 1.42.1
- 1.42
- 1.41
- 1.40
- 1.39
- 1.38
- 1.37
- 1.36
- 1.35.2
- 1.35
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ define([ | |
'../Core/defined', | ||
'../Core/Cartesian2', | ||
'../Core/Cartesian3', | ||
'../Core/Event', | ||
'../Core/Matrix4', | ||
'../Core/Math', | ||
'../Core/JulianDate', | ||
|
@@ -15,6 +16,7 @@ define([ | |
defined, | ||
Cartesian2, | ||
Cartesian3, | ||
Event, | ||
Matrix4, | ||
CesiumMath, | ||
JulianDate, | ||
|
@@ -39,6 +41,9 @@ define([ | |
this.startScale = defaultValue(options.startScale, 1.0); | ||
this.endScale = defaultValue(options.endScale, 1.0); | ||
|
||
this.rate = defaultValue(options.rate, 5); | ||
this.bursts = defaultValue(options.bursts, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made this change along with a few others in acd31e7 that removed the unnecessary use of defaultValue. |
||
|
||
var speed = defaultValue(options.speed, undefined); | ||
if (speed) { | ||
this.minSpeed = speed; | ||
|
@@ -91,8 +96,14 @@ define([ | |
this.maxHeight = defaultValue(options.maxHeight, 1.0); | ||
} | ||
|
||
this._billboardCollection = undefined; | ||
this.lifeTime = defaultValue(options.lifeTime, Number.MAX_VALUE); | ||
|
||
this.complete = new Event(); | ||
this.isComplete = false; | ||
|
||
this.carryOver = 0.0; | ||
this.currentTime = 0.0; | ||
this._billboardCollection = undefined; | ||
this._previousTime = null; | ||
}; | ||
|
||
|
@@ -144,6 +155,40 @@ define([ | |
this.particles.push(particle); | ||
}; | ||
|
||
ParticleSystem.prototype.calcNumberToEmit = function(dt) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this would be part of the public API, spell out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll rename it, but also mark it as @Private. It's not something that an external user should be calling. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually ended up making these local file scoped functions like mentioned here |
||
// This emitter is finished if it exceeds it's lifetime. | ||
if (this.isComplete) { | ||
return 0; | ||
} | ||
|
||
// Compute the number of particles to emit based on the rate. | ||
var v = dt * this.rate; | ||
var numToEmit = Math.floor(v); | ||
this.carryOver += (v-numToEmit); | ||
if (this.carryOver>1.0) | ||
{ | ||
numToEmit++; | ||
this.carryOver -= 1.0; | ||
} | ||
|
||
|
||
var i = 0; | ||
|
||
// Apply any bursts | ||
if (this.bursts) { | ||
for (i = 0; i < this.bursts.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally, we would assign this outside of the loop var length = this.bursts.length; |
||
var burst = this.bursts[i]; | ||
if ((!defined(burst, "complete") || !burst.complete) && this.currentTime > burst.time) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
var count = burst.min + random(0.0, 1.0) * burst.max; | ||
numToEmit += count; | ||
burst.complete = true; | ||
} | ||
} | ||
} | ||
|
||
return numToEmit; | ||
}; | ||
|
||
ParticleSystem.prototype.update = function(frameState) { | ||
if (!defined(this._billboardCollection)) { | ||
this._billboardCollection = new BillboardCollection(); | ||
|
@@ -178,14 +223,24 @@ define([ | |
} | ||
particles.length = length; | ||
|
||
// emit new particles if an emitter is attached. | ||
// the emission counts as the particle "update" | ||
emitter.modelMatrix = this.modelMatrix; | ||
emitter.emit(this, dt); | ||
|
||
var numToEmit = this.calcNumberToEmit(dt); | ||
|
||
if (numToEmit > 0 && emitter) { | ||
emitter.modelMatrix = this.modelMatrix; | ||
emitter.emit(this, numToEmit); | ||
} | ||
|
||
this._billboardCollection.update(frameState); | ||
|
||
this._previousTime = JulianDate.clone(frameState.time, this._previousTime); | ||
|
||
this.currentTime += dt; | ||
|
||
if (this.lifeTime !== Number.MAX_VALUE && this.currentTime > this.lifeTime) { | ||
this.isComplete = true; | ||
this.complete.raiseEvent(this); | ||
} | ||
}; | ||
|
||
return ParticleSystem; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the bounds on all these? Do any of these need explicit
set
functions to throwDeveloperError
s?