-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0907e9e
commit 6d2174f
Showing
9 changed files
with
608 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require './lib/GPUParticleSystem.js' | ||
|
||
_ = Framer._ | ||
|
||
{BaseClass} = require './_BaseClass.coffee' | ||
{Animation} = require './_Animation.coffee' | ||
{States} = require './_States.coffee' | ||
|
||
class exports.ParticleSystem extends BaseClass | ||
constructor: (properties={}) -> | ||
super() | ||
|
||
_.defaults properties, | ||
position: new THREE.Vector3() | ||
positionRandomness: .3 | ||
velocity: new THREE.Vector3() | ||
velocityRandomness: .5 | ||
color: 0xaa88ff | ||
colorRandomness: .2 | ||
turbulence: .5 | ||
lifetime: 2 | ||
size: 5 | ||
sizeRandomness: 1 | ||
spawnRate: 15000 | ||
horizontalSpeed: 1.5 | ||
verticalSpeed: 1.33 | ||
timeScale: 1 | ||
particleNoiseTexture: './modules/form/lib/textures/perlin-512.png' | ||
particleSpriteTexture: './modules/form/lib/textures/particle2.png' | ||
|
||
@properties = properties | ||
|
||
@clock = new THREE.Clock | ||
@tick = 0 | ||
@textureLoader = new THREE.TextureLoader() | ||
|
||
@particleSystem = new THREE.GPUParticleSystem | ||
maxParticles: 250000 | ||
particleNoiseTex: @textureLoader.load properties.particleNoiseTexture | ||
particleSpriteTex: @textureLoader.load properties.particleSpriteTexture | ||
|
||
@addToRenderingInstance properties.parent | ||
|
||
Framer.CurrentContext.on 'reset', => | ||
cancelAnimationFrame @animationLoopRequestId | ||
|
||
@animationLoopRequestId = requestAnimationFrame @loop | ||
|
||
addToRenderingInstance: (parent) -> | ||
if parent.scene then parent.scene.add @particleSystem | ||
else parent.add @particleSystem | ||
|
||
loop: () => | ||
|
||
@animationLoopRequestId = requestAnimationFrame @loop | ||
|
||
delta = @clock.getDelta() * @properties.timeScale | ||
@tick += delta | ||
|
||
if @tick < 0 | ||
@tick = 0 | ||
|
||
if delta > 0 | ||
|
||
@properties.position.x = Math.sin( @tick * @properties.horizontalSpeed ) * 20 | ||
@properties.position.y = Math.sin( @tick * @properties.verticalSpeed ) * 10 | ||
@properties.position.z = Math.sin( @tick * @properties.horizontalSpeed + @properties.verticalSpeed ) * 5 | ||
|
||
|
||
for [0..@properties.spawnRate * delta] | ||
@particleSystem.spawnParticle | ||
position: @properties.position | ||
positionRandomness: @properties.positionRandomness | ||
velocity: @properties.velocity | ||
velocityRandomness: @properties.velocityRandomness | ||
color: @properties.color | ||
colorRandomness: @properties.colorRandomness | ||
turbulence: @properties.turbulence | ||
lifetime: @properties.lifetime | ||
size: @properties.size | ||
sizeRandomness: @properties.sizeRandomness | ||
|
||
@particleSystem.update @tick |
Oops, something went wrong.