[29475] | 1 |
|
---|
| 2 | function rain() {
|
---|
| 3 |
|
---|
| 4 | this.isInit = false;
|
---|
[29721] | 5 | this.MASS = 0.9;
|
---|
[29475] | 6 |
|
---|
| 7 | this.init = function() {
|
---|
| 8 |
|
---|
| 9 | // modify lighting
|
---|
| 10 | this.HSL = light.color.getHSL();
|
---|
| 11 | light.color.setHSL(this.HSL.h, this.HSL.s, 0.2);
|
---|
| 12 |
|
---|
| 13 | if(this.isInit === true) return;
|
---|
| 14 |
|
---|
| 15 | // create the particle variables
|
---|
[29721] | 16 | this.particleCount = 8000,
|
---|
[29475] | 17 | this.particles = new THREE.Geometry(),
|
---|
| 18 | this.pMaterial = new THREE.ParticleBasicMaterial({
|
---|
| 19 | color: 0xFFFFFF,
|
---|
| 20 | size: 15,
|
---|
| 21 | map: THREE.ImageUtils.loadTexture(
|
---|
| 22 | "./images/raindrop.png"
|
---|
| 23 | ),
|
---|
| 24 | blending: THREE.AdditiveBlending,
|
---|
| 25 | transparent: true,
|
---|
| 26 | opacity: 1
|
---|
| 27 | });
|
---|
| 28 |
|
---|
| 29 | // now create the individual particles
|
---|
| 30 | for (var p = 0; p < this.particleCount; p++) {
|
---|
| 31 |
|
---|
| 32 | // create a particle with random
|
---|
| 33 | // position values, -250 -> 250
|
---|
[29694] | 34 | var pX = (Math.random() * 10000) - 5000,
|
---|
| 35 | pY = Math.random() * window.innerHeight * 6 - window.innerHeight,
|
---|
| 36 | pZ = (Math.random() * 10000) - 5000;
|
---|
[29634] | 37 | this.particle = new THREE.Vector3(pX, pY, pZ);
|
---|
[29475] | 38 |
|
---|
| 39 | // create a velocity vector
|
---|
[29634] | 40 | this.particle.velocity = new THREE.Vector3(
|
---|
[29721] | 41 | (windForce.x * this.MASS), // x
|
---|
| 42 | -Math.random() * this.MASS, // y
|
---|
| 43 | (windForce.z * this.MASS) // z
|
---|
| 44 | );
|
---|
[29475] | 45 |
|
---|
| 46 | // add it to the geometry
|
---|
| 47 | this.particles.vertices.push(this.particle);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | // create the particle system
|
---|
| 51 | this.particleSystem = new THREE.ParticleSystem(
|
---|
| 52 | this.particles,
|
---|
| 53 | this.pMaterial);
|
---|
| 54 |
|
---|
| 55 | this.particleSystem.sortParticles = true;
|
---|
| 56 | this.isInit = true;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | this.system = function(){
|
---|
| 60 | return this.particleSystem;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | this.update = function() {
|
---|
| 64 |
|
---|
| 65 | // add some rotation to the system
|
---|
| 66 | //particleSystem.rotation.y += 0.01;
|
---|
| 67 |
|
---|
| 68 | var pCount = this.particleCount;
|
---|
| 69 | while(pCount--) {
|
---|
| 70 | // get the particle
|
---|
| 71 | this.particle = this.particles.vertices[pCount];
|
---|
| 72 |
|
---|
| 73 | // check if we need to reset
|
---|
[29634] | 74 | if(this.particle.y < -10) {
|
---|
[29694] | 75 | this.particle.y = (window.innerHeight*6)+(Math.random() * 100);
|
---|
[29475] | 76 | this.particle.velocity.y = 0;
|
---|
[29694] | 77 | this.particle.x = (Math.random() * 10000) - 5000;
|
---|
| 78 | this.particle.z = (Math.random() * 10000) - 5000;
|
---|
[29475] | 79 | }
|
---|
| 80 |
|
---|
| 81 | // update the velocity
|
---|
[29634] | 82 | this.particle.velocity.y -= Math.random() * 0.01;
|
---|
[29719] | 83 | this.particle.velocity.x = windForce.x * (1-this.MASS);
|
---|
| 84 | this.particle.velocity.z = windForce.z * (1-this.MASS)
|
---|
[29475] | 85 |
|
---|
| 86 | // and the position
|
---|
| 87 | this.particle.addVectors(
|
---|
| 88 | this.particle,
|
---|
| 89 | this.particle.velocity);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | // flag to the particle system that we've
|
---|
| 93 | // changed its vertices.
|
---|
| 94 | this.particleSystem.geometry.__dirtyVertices = true;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | } |
---|