1 |
|
---|
2 | function rain() {
|
---|
3 |
|
---|
4 | this.isInit = false;
|
---|
5 | this.MASS = 0.01;
|
---|
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 = 10000,
|
---|
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 * (1-this.MASS)), // x
|
---|
42 | -Math.random() * 0.01, // y
|
---|
43 | (windForce.z * (1-this.MASS))); // z
|
---|
44 |
|
---|
45 | // add it to the geometry
|
---|
46 | this.particles.vertices.push(this.particle);
|
---|
47 | }
|
---|
48 |
|
---|
49 | // create the particle system
|
---|
50 | this.particleSystem = new THREE.ParticleSystem(
|
---|
51 | this.particles,
|
---|
52 | this.pMaterial);
|
---|
53 |
|
---|
54 | this.particleSystem.sortParticles = true;
|
---|
55 | this.isInit = true;
|
---|
56 | }
|
---|
57 |
|
---|
58 | this.system = function(){
|
---|
59 | return this.particleSystem;
|
---|
60 | }
|
---|
61 |
|
---|
62 | this.update = function() {
|
---|
63 |
|
---|
64 | // add some rotation to the system
|
---|
65 | //particleSystem.rotation.y += 0.01;
|
---|
66 |
|
---|
67 | var pCount = this.particleCount;
|
---|
68 | while(pCount--) {
|
---|
69 | // get the particle
|
---|
70 | this.particle = this.particles.vertices[pCount];
|
---|
71 |
|
---|
72 | // check if we need to reset
|
---|
73 | if(this.particle.y < -10) {
|
---|
74 | this.particle.y = (window.innerHeight*6)+(Math.random() * 100);
|
---|
75 | this.particle.velocity.y = 0;
|
---|
76 | this.particle.x = (Math.random() * 10000) - 5000;
|
---|
77 | this.particle.z = (Math.random() * 10000) - 5000;
|
---|
78 | }
|
---|
79 |
|
---|
80 | // update the velocity
|
---|
81 | this.particle.velocity.y -= Math.random() * 0.01;
|
---|
82 | this.particle.velocity.x = windForce.x * (1-this.MASS);
|
---|
83 | this.particle.velocity.z = windForce.z * (1-this.MASS)
|
---|
84 |
|
---|
85 | // and the position
|
---|
86 | this.particle.addVectors(
|
---|
87 | this.particle,
|
---|
88 | this.particle.velocity);
|
---|
89 | }
|
---|
90 |
|
---|
91 | // flag to the particle system that we've
|
---|
92 | // changed its vertices.
|
---|
93 | this.particleSystem.geometry.__dirtyVertices = true;
|
---|
94 | }
|
---|
95 |
|
---|
96 | } |
---|