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

Last change on this file was 29721, checked in by bmt11, 9 years ago

Tooltip is now polished and finished

File size: 2.6 KB
Line 
1
2function rain() {
3
4 this.isInit = false;
5 this.MASS = 0.9;
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
16 this.particleCount = 8000,
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
34 var pX = (Math.random() * 10000) - 5000,
35 pY = Math.random() * window.innerHeight * 6 - window.innerHeight,
36 pZ = (Math.random() * 10000) - 5000;
37 this.particle = new THREE.Vector3(pX, pY, pZ);
38
39 // create a velocity vector
40 this.particle.velocity = new THREE.Vector3(
41 (windForce.x * this.MASS), // x
42 -Math.random() * this.MASS, // y
43 (windForce.z * this.MASS) // z
44 );
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
74 if(this.particle.y < -10) {
75 this.particle.y = (window.innerHeight*6)+(Math.random() * 100);
76 this.particle.velocity.y = 0;
77 this.particle.x = (Math.random() * 10000) - 5000;
78 this.particle.z = (Math.random() * 10000) - 5000;
79 }
80
81 // update the velocity
82 this.particle.velocity.y -= Math.random() * 0.01;
83 this.particle.velocity.x = windForce.x * (1-this.MASS);
84 this.particle.velocity.z = windForce.z * (1-this.MASS)
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}
Note: See TracBrowser for help on using the repository browser.