1 |
|
---|
2 | function snow() {
|
---|
3 |
|
---|
4 | this.isInit = false;
|
---|
5 | this.MASS = 0.005;
|
---|
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 = 6000,
|
---|
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.9
|
---|
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
|
---|
35 | var pX = (Math.random() * 10000) - 5000,
|
---|
36 | pY = Math.random() * window.innerHeight * 6 - window.innerHeight,
|
---|
37 | pZ = (Math.random() * 10000) - 5000;
|
---|
38 | this.particle = new THREE.Vector3(pX, pY, pZ);
|
---|
39 |
|
---|
40 | // create a velocity vector
|
---|
41 | this.particle.velocity = new THREE.Vector3(
|
---|
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;
|
---|
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
|
---|
76 | if(this.particle.y < -10) {
|
---|
77 | this.particle.y = (window.innerHeight*6)+(Math.random() * 100);
|
---|
78 | this.particle.velocity.y = 0;
|
---|
79 | this.particle.x = (Math.random() * 10000) - 5000;
|
---|
80 | this.particle.z = (Math.random() * 10000) - 5000;
|
---|
81 |
|
---|
82 | }
|
---|
83 |
|
---|
84 | // update the velocity
|
---|
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 |
|
---|
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 | } |
---|