Skip to content
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

Introduces angularVelocity/spread for spinning particles #25

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ var particleEmitter = new ShaderParticleEmitter({
// [OPTIONAL] Acceleration variance.
accelerationSpread: new THREE.Vector3(0, 0, 0),

// [OPTIONAL] The intial angle of each particle
angle: 0,

// [OPTIONAL] How fast each particle is spinning
angularVelocity: 0,

// [OPTIONAL] Particle spin velocity variance
angularVelocitySpread: 0,

// [OPTIONAL] Align the particles in the direciton they are moving
angleAlignVelocity: true


// [OPTIONAL] Velocity base vector.
velocity: new THREE.Vector3(0, 0, 0),
Expand Down Expand Up @@ -269,4 +281,4 @@ See the [issues page](https://github.com/squarefeet/ShaderParticleEngine/issues)

Thanks
======
Huge thanks are extended to [Stemkoski](http://stemkoski.github.io/Three.js/) for his initial particle engine, and to [Mr Doob, AlteredQualia, et. al](https://github.com/mrdoob/three.js/graphs/contributors) for their awesome work on [THREE.js](http://threejs.org/).
Huge thanks are extended to [Stemkoski](http://stemkoski.github.io/Three.js/) for his initial particle engine, and to [Mr Doob, AlteredQualia, et. al](https://github.com/mrdoob/three.js/graphs/contributors) for their awesome work on [THREE.js](http://threejs.org/).
9 changes: 8 additions & 1 deletion build/ShaderParticles.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ function ShaderParticleGroup( options ) {
sizeEnd: { type: 'f', value: [] },

angle: { type: 'f', value: [] },
angularVelocity: { type: 'f', value: [] },
angleAlignVelocity: { type: 'f', value: [] },

colorStart: { type: 'c', value: [] },
Expand Down Expand Up @@ -444,6 +445,7 @@ ShaderParticleGroup.prototype = {
sizeStart = a.sizeStart.value,
sizeEnd = a.sizeEnd.value,
angle = a.angle.value,
angularVelocity = a.angularVelocity.value,
angleAlignVelocity = a.angleAlignVelocity.value,
colorStart = a.colorStart.value,
colorMiddle = a.colorMiddle.value,
Expand Down Expand Up @@ -477,6 +479,7 @@ ShaderParticleGroup.prototype = {
sizeEnd[i] = emitter.sizeEnd;

angle[i] = that._randomFloat( emitter.angle, emitter.angleSpread );
angularVelocity[i] = that._randomFloat( emitter.angularVelocity, emitter.angularVelocitySpread );
angleAlignVelocity[i] = emitter.angleAlignVelocity ? 1.0 : 0.0;

age[i] = 0.0;
Expand Down Expand Up @@ -723,6 +726,7 @@ ShaderParticleGroup.shaders = {
'attribute float sizeStart;',
'attribute float sizeEnd;',
'attribute float angle;',
'attribute float angularVelocity;',
'attribute float angleAlignVelocity;',

// values to be passed to the fragment shader
Expand Down Expand Up @@ -779,7 +783,7 @@ ShaderParticleGroup.shaders = {
'vAngle = -atan(pos.y, pos.x);',
'}',
'else {',
'vAngle = 0.0;',
'vAngle = angle + ( angularVelocity * age );',
'}',

// Determine point size .
Expand Down Expand Up @@ -880,6 +884,9 @@ function ShaderParticleEmitter( options ) {
that.angleSpread = parseFloat( typeof options.angleSpread === 'number' ? options.angleSpread : 0 );
that.angleAlignVelocity = options.angleAlignVelocity || false;

that.angularVelocity = parseFloat( typeof options.angularVelocity === 'number' ? options.angularVelocity : 0 );
that.angularVelocitySpread = parseFloat( typeof options.angularVelocitySpread === 'number' ? options.angularVelocitySpread : 0 );

that.colorStart = options.colorStart instanceof THREE.Color ? options.colorStart : new THREE.Color( 'white' );
that.colorStartSpread = options.colorStartSpread instanceof THREE.Vector3 ? options.colorStartSpread : new THREE.Vector3(0,0,0);
that.colorEnd = options.colorEnd instanceof THREE.Color ? options.colorEnd : that.colorStart.clone();
Expand Down
Loading