forked from nxxcxx/Neural-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticlePool.js
85 lines (59 loc) · 1.9 KB
/
particlePool.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Particle Pool ---------------------------------------------------------
function ParticlePool( poolSize ) {
this.spriteTextureSignal = TEXTURES.electric;
this.poolSize = poolSize;
this.pGeom = new THREE.Geometry();
this.particles = this.pGeom.vertices;
this.offScreenPos = new THREE.Vector3( 9999, 9999, 9999 );
this.pColor = '#00ffff';
this.pSize = 0.6;
for ( var ii = 0; ii < this.poolSize; ii++ ) {
this.particles[ ii ] = new Particle( this );
}
this.meshComponents = new THREE.Object3D();
// inner particle
this.pMat = new THREE.PointCloudMaterial( {
map: this.spriteTextureSignal,
size: this.pSize,
color: this.pColor,
blending: THREE.AdditiveBlending,
depthTest: false,
transparent: true
} );
this.pMesh = new THREE.PointCloud( this.pGeom, this.pMat );
this.pMesh.frustumCulled = false;
this.meshComponents.add( this.pMesh );
// outer particle glow
this.pMat_outer = this.pMat.clone();
this.pMat_outer.size = this.pSize * 10;
this.pMat_outer.opacity = 0.04;
this.pMesh_outer = new THREE.PointCloud( this.pGeom, this.pMat_outer );
this.pMesh_outer.frustumCulled = false;
this.meshComponents.add( this.pMesh_outer );
}
ParticlePool.prototype.getAvgExecutionTime = function () {
return this.profTime / this.itt;
};
ParticlePool.prototype.getParticle = function () {
for ( var ii = 0; ii < this.poolSize; ii++ ) {
var p = this.particles[ ii ];
if ( p.available ) {
this.lastAvailableIdx = ii;
p.available = false;
return p;
}
}
console.error( "ParticlePool.prototype.getParticle return null" );
return null;
};
ParticlePool.prototype.update = function () {
this.pGeom.verticesNeedUpdate = true;
};
ParticlePool.prototype.updateSettings = function () {
// inner particle
this.pMat.color.setStyle( this.pColor );
this.pMat.size = this.pSize;
// outer particle
this.pMat_outer.color.setStyle( this.pColor );
this.pMat_outer.size = this.pSize * 10;
};