source: other-projects/nz-flag-design/trunk/render-3d/weather/rain.js@ 29475

Last change on this file since 29475 was 29475, checked in by davidb, 9 years ago

Initial set of files

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