-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle.js
53 lines (49 loc) · 1.95 KB
/
particle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Particle = function(){
var geom = new THREE.PlaneGeometry(2,2,2,2);
var mat = new THREE.MeshPhongMaterial({
color:0x009999,
shininess:0,
specular:0xffffff,
shading:THREE.FlatShading
});
this.mesh = new THREE.Mesh(geom,mat);
}
Particle.prototype.explode = function(pos, color, scale){
var _this = this;
var _p = this.mesh.parent;
this.mesh.material.color = new THREE.Color( color);
this.mesh.material.needsUpdate = true;
this.mesh.scale.set(scale, scale, scale);
var targetX = pos.x + (-1 + Math.random()*2)*50;
var targetY = pos.y + (-1 + Math.random()*2)*50;
var speed = .6+Math.random()*.2;
TweenMax.to(this.mesh.rotation, speed, {x:Math.random()*12, y:Math.random()*12});
TweenMax.to(this.mesh.scale, speed, {x:.1, y:.1, z:.1});
TweenMax.to(this.mesh.position, speed, {x:targetX, y:targetY, delay:Math.random() *.1, ease:Power2.easeOut, onComplete:function(){
if(_p) _p.remove(_this.mesh);
_this.mesh.scale.set(1,1,1);
particlesPool.unshift(_this);
}});
}
ParticlesHolder = function (){
this.mesh = new THREE.Object3D();
this.particlesInUse = [];
}
ParticlesHolder.prototype.spawnParticles = function(pos, density, color, scale){
var nPArticles = density;
for (var i=0; i<nPArticles; i++){
var particle;
if (particlesPool.length) {
particle = particlesPool.pop();
}else{
particle = new Particle();
}
this.mesh.add(particle.mesh);
particle.mesh.visible = true;
var _this = this;
particle.mesh.position.y = pos.y;
particle.mesh.position.x = pos.x;
//particle.mesh.position.z = pos.z;
particle.explode(pos,color, scale);
}
}