1 |
|
---|
2 | function snow() {
|
---|
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.6);
|
---|
12 |
|
---|
13 | if(this.isInit === true) return;
|
---|
14 |
|
---|
15 | // create the particle variables
|
---|
16 | this.particleCount = 1000,
|
---|
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,
|
---|
27 | opacity: 0.5
|
---|
28 | });
|
---|
29 |
|
---|
30 | // now create the individual particles
|
---|
31 | for (var p = 0; p < this.particleCount; p++) {
|
---|
32 |
|
---|
33 | // create a particle with random
|
---|
34 | // position values, -250 -> 250
|
---|
35 | var pX = Math.random() * window.innerWidth * 2 - window.innerWidth,
|
---|
36 | pY = Math.random() * window.innerHeight * 3 - window.innerHeight,
|
---|
37 | pZ = Math.random() * window.innerWidth * 2 - window.innerWidth;
|
---|
38 | this.particle = new THREE.Vector3(pX, pY, pZ);
|
---|
39 |
|
---|
40 | // create a velocity vector
|
---|
41 | this.particle.velocity = new THREE.Vector3(
|
---|
42 | 0, // x
|
---|
43 | -Math.random(), // y
|
---|
44 | 0); // z
|
---|
45 |
|
---|
46 | // add it to the geometry
|
---|
47 | this.particles.vertices.push(this.particle);
|
---|
48 |
|
---|
49 | }
|
---|
50 |
|
---|
51 | // create the particle system
|
---|
52 | this.particleSystem = new THREE.ParticleSystem(
|
---|
53 | this.particles,
|
---|
54 | this.pMaterial);
|
---|
55 |
|
---|
56 | this.particleSystem.sortParticles = true;
|
---|
57 |
|
---|
58 | this.isInit = true;
|
---|
59 | }
|
---|
60 |
|
---|
61 | this.system = function(){
|
---|
62 | return this.particleSystem;
|
---|
63 | }
|
---|
64 |
|
---|
65 | this.update = function() {
|
---|
66 | // add some rotation to the system
|
---|
67 | //particleSystem.rotation.y += 0.01;
|
---|
68 |
|
---|
69 | var pCount = this.particleCount;
|
---|
70 | while(pCount--) {
|
---|
71 | // get the particle
|
---|
72 | this.particle = this.particles.vertices[pCount];
|
---|
73 |
|
---|
74 | // check if we need to reset
|
---|
75 | if(this.particle.y < -200) {
|
---|
76 | this.particle.y = Math.random() * window.innerHeight+10;
|
---|
77 | this.particle.velocity.y = 0;
|
---|
78 | }
|
---|
79 |
|
---|
80 | // update the velocity
|
---|
81 | this.particle.velocity.y -= Math.random() * this.Mass;
|
---|
82 |
|
---|
83 | // and the position
|
---|
84 | this.particle.addVectors(
|
---|
85 | this.particle,
|
---|
86 | this.particle.velocity);
|
---|
87 | }
|
---|
88 |
|
---|
89 | // flag to the particle system that we've
|
---|
90 | // changed its vertices.
|
---|
91 | this.particleSystem.geometry.__dirtyVertices = true;
|
---|
92 | }
|
---|
93 | } |
---|