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