-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathPhysicsText.js
More file actions
87 lines (49 loc) · 1.67 KB
/
PhysicsText.js
File metadata and controls
87 lines (49 loc) · 1.67 KB
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
86
87
function PhysicsText( particles , ss , uniforms ){
this.active = false;
this.sim = ss;
this.particles = G.text.createTextParticles( this.string );
this.uniforms = this.particles.material.uniforms;
this.size = this.particles.size;
this.physics = new PhysicsRenderer( this.size , this.sim , G.renderer );
this.physics.setUniform( 't_to' , {
type:"t",
value:this.uniforms.t_lookup.value
});
this.physics.setUniforms( uniforms );
this.physics.addBoundTexture( this.particles , 't_lookup' , 'output' );
}
PhysicsText.prototype.transport = function( position , randomSize ){
var randomSize = randomSize || 3;
var data = new Float32Array( this.size * this.size * 4 );
var positionsTexture = new THREE.DataTexture(
data,
this.size,
this.size,
THREE.RGBAFormat,
THREE.FloatType
);
positionsTexture.minFilter = THREE.NearestFilter;
positionsTexture.magFilter = THREE.NearestFilter;
positionsTexture.generateMipmaps = false;
positionsTexture.needsUpdate = true;
// giving some randomness, so that objects splay out properly
for( var i = 0; i < data.length; i += 4 ){
data[ i + 0 ] = position.x + Math.random() * randomSize;
data[ i + 1 ] = position.y + Math.random() * randomSize;
data[ i + 2 ] = position.z + Math.random() * randomSize;
data[ i + 3 ] = 0;
}
positionsTexture.needsUpdate = true;
this.physics.reset( positionsTexture );
}
PhysicsText.prototype.activate = function(){
this.active = true;
}
PhysicsText.prototype.deactivate = function(){
this.active = false;
}
PhysicsText.prototype.update = function(){
if( this.active === true ){
this.physics.update();
}
}