|
12 | 12 |
|
13 | 13 | this.texture = this.font.texture;
|
14 | 14 |
|
15 |
| - this.letterWidth = params.letterWidth || .02; |
| 15 | + this.letterWidth = params.letterWidth || 2.; |
16 | 16 | this.lineLength = params.lineLength || 50;
|
17 | 17 |
|
18 | 18 | this.lineHeight = this.letterWidth * 2.4;
|
|
31 | 31 |
|
32 | 32 | var particles = this.createParticles( string );
|
33 | 33 | var lookup = this.createLookupTexture( particles );
|
34 |
| - // var textCoord = this.createTextCoordTexture( particles ); |
35 | 34 | var geometry = this.createGeometry( particles , true );
|
36 | 35 |
|
37 | 36 | var material = this.createMaterial( lookup , params );
|
|
43 | 42 |
|
44 | 43 | particleSystem.size = lookup.size;
|
45 | 44 | particleSystem.lookup = lookup;
|
46 |
| - particleSystem.debug = new THREE.Mesh( |
47 |
| - new THREE.PlaneBufferGeometry( 1 , 1 ) , |
48 |
| - new THREE.MeshBasicMaterial({ |
49 |
| - map: lookup |
50 |
| - }) |
51 |
| - ); |
52 |
| - |
| 45 | + |
53 | 46 | var lines = Math.ceil( particles.length / this.lineLength );
|
54 |
| - |
55 | 47 |
|
56 | 48 | particleSystem.totalWidth = this.width;
|
57 | 49 | particleSystem.totalHeight = lines * this.lineHeight;
|
|
100 | 92 | // Makes sure we don't go over line width
|
101 | 93 | var newL = counter[0] + l;
|
102 | 94 | if( newL > this.lineLength ){
|
103 |
| - console.log( 'new line'); |
104 | 95 | counter[0] = 0;
|
105 | 96 | counter[1] ++;
|
106 | 97 | }
|
|
139 | 130 |
|
140 | 131 | var data = new Float32Array( size * size * 4 );
|
141 | 132 |
|
142 |
| - console.log( this.letterWidth ); |
143 |
| - |
144 |
| - console.log( size ); |
145 |
| - |
146 |
| - for( var i = 0; i < particles.length; i++ ){ |
147 |
| - var p1 = particles[i] |
148 |
| - for( var j = i+1; j < particles.length; j++ ){ |
149 |
| - var p2 = particles[j]; |
150 |
| - |
151 |
| - if( p1[1] == p2[1] && p1[2] == p2[2] ){ |
152 |
| - console.log( 'WTF' ); |
153 |
| - console.log( p1 ); |
154 |
| - console.log( p2 ); |
155 |
| - } |
156 |
| - |
157 |
| - } |
158 |
| - } |
| 133 | + |
159 | 134 | for( var i = 0; i < size * size; i++ ){
|
160 | 135 |
|
161 | 136 | if( particles[i] ){
|
162 | 137 |
|
163 |
| - |
164 |
| - data[ i * 4 + 0 ] = particles[i][1] * this.letterWidth * .8; |
| 138 | + data[ i * 4 + 0 ] = particles[i][1] * this.letterWidth; |
165 | 139 | data[ i * 4 + 1 ] = -particles[i][2] * this.lineHeight;
|
166 | 140 |
|
167 |
| - data[ i * 4 + 2 ] = 0; // packing in textCoord |
168 |
| - data[ i * 4 + 3 ] = 0; // just cuz! |
| 141 | + data[ i * 4 + 2 ] = 0; |
| 142 | + data[ i * 4 + 3 ] = 0; |
169 | 143 |
|
170 | 144 | }
|
171 | 145 |
|
172 | 146 | }
|
173 | 147 |
|
| 148 | + |
174 | 149 | var f = THREE.RGBAFormat;
|
175 | 150 | var t = THREE.FloatType;
|
176 | 151 |
|
|
196 | 171 | var uvs = new Float32Array( particles.length * 3 * 2 * 2 );
|
197 | 172 | var ids = new Float32Array( particles.length * 3 * 2 * 1 );
|
198 | 173 | var textCoords = new Float32Array( particles.length * 3 * 2 * 4 );
|
199 |
| - var textOffsets = new Float32Array( particles.length * 3 * 2 * 2 ); |
200 | 174 | var lookups = new Float32Array( particles.length * 3 * 2 * 2 );
|
201 | 175 |
|
202 | 176 |
|
203 | 177 | var uvA = new THREE.BufferAttribute( uvs , 2 );
|
204 | 178 | var idA = new THREE.BufferAttribute( ids , 1 );
|
205 | 179 | var posA = new THREE.BufferAttribute( positions , 3 );
|
206 | 180 | var coordA = new THREE.BufferAttribute( textCoords , 4 );
|
207 |
| - var offsetA = new THREE.BufferAttribute( textOffsets , 2 ); |
208 | 181 | var lookupA = new THREE.BufferAttribute( lookups , 2 );
|
209 | 182 |
|
210 | 183 | geometry.addAttribute( 'id' , idA );
|
211 | 184 | geometry.addAttribute( 'uv' , uvA );
|
212 | 185 | geometry.addAttribute( 'lookup' , lookupA );
|
213 | 186 | geometry.addAttribute( 'position' , posA );
|
214 | 187 | geometry.addAttribute( 'textCoord' , coordA );
|
215 |
| - geometry.addAttribute( 'textOffset' , offsetA ); |
216 | 188 |
|
217 | 189 | var lookupWidth = Math.ceil( Math.sqrt( particles.length ) );
|
218 | 190 |
|
|
236 | 208 | // top is y offset + height
|
237 | 209 | var t = tc[5] ;
|
238 | 210 |
|
239 |
| - |
240 |
| - |
241 |
| - /*var l = -1 * .04; |
242 |
| - var r = 1 * .04; |
243 |
| - var t = 1 * .04; |
244 |
| - var b = -1 * .04;*/ |
245 |
| - |
246 | 211 | ids[ index + 0 ] = i;
|
247 | 212 | ids[ index + 1 ] = i;
|
248 | 213 | ids[ index + 2 ] = i;
|
|
303 | 268 | x += .5;
|
304 | 269 | y += .5;
|
305 | 270 |
|
306 |
| - |
307 | 271 | lookups[ index * 2 + 0 ] = x / lookupWidth;
|
308 | 272 | lookups[ index * 2 + 1 ] = y / lookupWidth;
|
309 | 273 |
|
|
354 | 318 | textCoords[ index * 4 + 22 ] = tc[2];
|
355 | 319 | textCoords[ index * 4 + 23 ] = tc[3];
|
356 | 320 |
|
357 |
| - |
358 |
| - textOffsets[ index * 2 + 0 ] = tc[4]; |
359 |
| - textOffsets[ index * 2 + 1 ] = tc[5]; |
360 |
| - |
361 |
| - textOffsets[ index * 2 + 2 ] = tc[4]; |
362 |
| - textOffsets[ index * 2 + 3 ] = tc[5]; |
363 |
| - |
364 |
| - textOffsets[ index * 2 + 4 ] = tc[4]; |
365 |
| - textOffsets[ index * 2 + 5 ] = tc[5]; |
366 |
| - |
367 |
| - textOffsets[ index * 2 + 6 ] = tc[4]; |
368 |
| - textOffsets[ index * 2 + 7 ] = tc[5]; |
369 |
| - |
370 |
| - textOffsets[ index * 2 + 8 ] = tc[4]; |
371 |
| - textOffsets[ index * 2 + 9 ] = tc[5]; |
372 |
| - |
373 |
| - textOffsets[ index * 2 + 10 ] = tc[4]; |
374 |
| - textOffsets[ index * 2 + 11 ] = tc[5]; |
375 |
| - |
376 | 321 | }
|
377 | 322 |
|
378 | 323 | return geometry;
|
|
440 | 385 | */
|
441 | 386 | TextParticles.prototype.createMaterial = function( lookup , params ){
|
442 | 387 |
|
443 |
| - var params = params || {}; |
444 |
| - var dpr = window.devicePixelRatio || 1; |
| 388 | + var params = params || {}; |
445 | 389 |
|
446 | 390 | var texture = params.texture || this.texture;
|
447 | 391 | var lookup = params.lookup || lookup;
|
448 | 392 | var color = params.color || this.color;
|
449 |
| - var letterWidth = params.letterWidth || this.letterWidth ; |
450 | 393 | var opacity = params.opacity || 1;
|
451 |
| - var side = params.side || THREE.DoubleSide; |
452 | 394 |
|
453 | 395 | var attributes = {
|
| 396 | + |
| 397 | + id: { type:"f" , value: null }, |
| 398 | + lookup: { type:"v2" , value: null }, |
454 | 399 | textCoord: { type:"v4" , value: null },
|
455 |
| - textOffset: { type:"v2" , value: null }, |
456 |
| - lookup: { type:"v2" , value: null }, |
457 |
| - id: { type:"f" , value: null }, |
| 400 | + |
458 | 401 | }
|
459 | 402 |
|
460 | 403 |
|
461 | 404 | var c = new THREE.Color( color );
|
462 | 405 |
|
463 |
| - var windowSize = new THREE.Vector2( window.innerWidth , window.innerHeight ); |
464 |
| - |
465 |
| - var glyphWidth = this.font.glyphWidth / 1024; |
466 |
| - var glyphHeight = this.font.glyphHeight / 1024; |
467 |
| - var glyphBelow = this.font.glyphBelow / 1024; |
468 | 406 |
|
469 | 407 | var uniforms = {
|
| 408 | + |
| 409 | + color: { type:"c" , value: c }, |
470 | 410 |
|
471 |
| - dpr: { type:"f" , value: dpr }, |
472 | 411 | t_lookup: { type:"t" , value: lookup },
|
473 | 412 | t_text: { type:"t" , value: texture },
|
474 |
| - color: { type:"c" , value: c }, |
475 |
| - textureSize: { type:"f" , value: lookup.size }, |
476 |
| - windowSize: { type:"v2" , value: windowSize }, |
477 |
| - letterWidth: { type:"f" , value: letterWidth }, |
478 | 413 | opacity: { type:"f" , value: opacity },
|
479 |
| - glyphWidth: { type:"f" , value: glyphWidth }, |
480 |
| - glyphHeight: { type:"f" , value: glyphHeight }, |
481 |
| - glyphBelow: { type:"f" , value: glyphBelow }, |
482 |
| - |
| 414 | + |
| 415 | + //time: { type:"f" ,value : 1} |
| 416 | + |
483 | 417 | }
|
| 418 | + |
| 419 | + |
| 420 | + if( params.uniforms ){ |
| 421 | + for( var propt in params.uniforms ){ |
| 422 | + console.log( params.uniforms ); |
| 423 | + uniforms[ propt ] = params.uniforms[ propt ]; |
| 424 | + } |
| 425 | + } |
| 426 | + |
| 427 | + console.log( uniforms ); |
| 428 | + |
| 429 | + var attr = attributes; |
484 | 430 |
|
485 | 431 | var vert = this.vertexShader;
|
486 | 432 | var frag = this.fragmentShader;
|
487 |
| - var attr = attributes; |
488 | 433 |
|
489 | 434 | var blend = params.blending || THREE.AdditiveBlending;
|
490 | 435 | var depth = params.depthWrite || false;
|
491 | 436 | var trans = params.transparent || true;
|
| 437 | + var side = params.side || THREE.DoubleSide; |
492 | 438 |
|
493 |
| - material = new THREE.ShaderMaterial({ |
| 439 | + var material = new THREE.ShaderMaterial({ |
| 440 | + |
| 441 | + attributes: attr, |
494 | 442 |
|
495 | 443 | uniforms: uniforms,
|
496 |
| - attributes: attr, |
| 444 | + |
497 | 445 | vertexShader: vert,
|
498 | 446 | fragmentShader: frag,
|
499 | 447 |
|
500 | 448 | transparent: trans,
|
501 | 449 | depthWrite: depth,
|
502 | 450 | blending: blend,
|
503 | 451 |
|
504 |
| - // side: side |
505 |
| - |
506 | 452 | });
|
507 | 453 |
|
508 | 454 |
|
|
0 commit comments