@tarsis/toolkit 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3021 +0,0 @@
1
- import { g as getDefaultExportFromCjs, c as commonjsGlobal, a as getAugmentedNamespace, W as WebGLRenderer, P as PerspectiveCamera, S as Scene, T as THREE$1, C as Clock, b as TextureLoader, R as RawShaderMaterial, D as DoubleSide, d as WebGLRenderTarget, e as Color, M as Mesh, f as TorusKnotGeometry, h as ShaderMaterial } from './index-DqlD5uPx.js';
2
-
3
- /*
4
- object-assign
5
- (c) Sindre Sorhus
6
- @license MIT
7
- */
8
-
9
- var objectAssign;
10
- var hasRequiredObjectAssign;
11
-
12
- function requireObjectAssign () {
13
- if (hasRequiredObjectAssign) return objectAssign;
14
- hasRequiredObjectAssign = 1;
15
- /* eslint-disable no-unused-vars */
16
- var getOwnPropertySymbols = Object.getOwnPropertySymbols;
17
- var hasOwnProperty = Object.prototype.hasOwnProperty;
18
- var propIsEnumerable = Object.prototype.propertyIsEnumerable;
19
-
20
- function toObject(val) {
21
- if (val === null || val === undefined) {
22
- throw new TypeError('Object.assign cannot be called with null or undefined');
23
- }
24
-
25
- return Object(val);
26
- }
27
-
28
- function shouldUseNative() {
29
- try {
30
- if (!Object.assign) {
31
- return false;
32
- }
33
-
34
- // Detect buggy property enumeration order in older V8 versions.
35
-
36
- // https://bugs.chromium.org/p/v8/issues/detail?id=4118
37
- var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
38
- test1[5] = 'de';
39
- if (Object.getOwnPropertyNames(test1)[0] === '5') {
40
- return false;
41
- }
42
-
43
- // https://bugs.chromium.org/p/v8/issues/detail?id=3056
44
- var test2 = {};
45
- for (var i = 0; i < 10; i++) {
46
- test2['_' + String.fromCharCode(i)] = i;
47
- }
48
- var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
49
- return test2[n];
50
- });
51
- if (order2.join('') !== '0123456789') {
52
- return false;
53
- }
54
-
55
- // https://bugs.chromium.org/p/v8/issues/detail?id=3056
56
- var test3 = {};
57
- 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
58
- test3[letter] = letter;
59
- });
60
- if (Object.keys(Object.assign({}, test3)).join('') !==
61
- 'abcdefghijklmnopqrst') {
62
- return false;
63
- }
64
-
65
- return true;
66
- } catch (err) {
67
- // We don't expect any of the above to throw, but better to be safe.
68
- return false;
69
- }
70
- }
71
-
72
- objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
73
- var from;
74
- var to = toObject(target);
75
- var symbols;
76
-
77
- for (var s = 1; s < arguments.length; s++) {
78
- from = Object(arguments[s]);
79
-
80
- for (var key in from) {
81
- if (hasOwnProperty.call(from, key)) {
82
- to[key] = from[key];
83
- }
84
- }
85
-
86
- if (getOwnPropertySymbols) {
87
- symbols = getOwnPropertySymbols(from);
88
- for (var i = 0; i < symbols.length; i++) {
89
- if (propIsEnumerable.call(from, symbols[i])) {
90
- to[symbols[i]] = from[symbols[i]];
91
- }
92
- }
93
- }
94
- }
95
-
96
- return to;
97
- };
98
- return objectAssign;
99
- }
100
-
101
- var threeOrbitControls = function( THREE ) {
102
- /**
103
- * @author qiao / https://github.com/qiao
104
- * @author mrdoob / http://mrdoob.com
105
- * @author alteredq / http://alteredqualia.com/
106
- * @author WestLangley / http://github.com/WestLangley
107
- * @author erich666 / http://erichaines.com
108
- */
109
-
110
- // This set of controls performs orbiting, dollying (zooming), and panning.
111
- // Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
112
- //
113
- // Orbit - left mouse / touch: one finger move
114
- // Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
115
- // Pan - right mouse, or arrow keys / touch: three finter swipe
116
-
117
- function OrbitControls( object, domElement ) {
118
-
119
- this.object = object;
120
-
121
- this.domElement = ( domElement !== undefined ) ? domElement : document;
122
-
123
- // Set to false to disable this control
124
- this.enabled = true;
125
-
126
- // "target" sets the location of focus, where the object orbits around
127
- this.target = new THREE.Vector3();
128
-
129
- // How far you can dolly in and out ( PerspectiveCamera only )
130
- this.minDistance = 0;
131
- this.maxDistance = Infinity;
132
-
133
- // How far you can zoom in and out ( OrthographicCamera only )
134
- this.minZoom = 0;
135
- this.maxZoom = Infinity;
136
-
137
- // How far you can orbit vertically, upper and lower limits.
138
- // Range is 0 to Math.PI radians.
139
- this.minPolarAngle = 0; // radians
140
- this.maxPolarAngle = Math.PI; // radians
141
-
142
- // How far you can orbit horizontally, upper and lower limits.
143
- // If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
144
- this.minAzimuthAngle = - Infinity; // radians
145
- this.maxAzimuthAngle = Infinity; // radians
146
-
147
- // Set to true to enable damping (inertia)
148
- // If damping is enabled, you must call controls.update() in your animation loop
149
- this.enableDamping = false;
150
- this.dampingFactor = 0.25;
151
-
152
- // This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
153
- // Set to false to disable zooming
154
- this.enableZoom = true;
155
- this.zoomSpeed = 1.0;
156
-
157
- // Set to false to disable rotating
158
- this.enableRotate = true;
159
- this.rotateSpeed = 1.0;
160
-
161
- // Set to false to disable panning
162
- this.enablePan = true;
163
- this.keyPanSpeed = 7.0; // pixels moved per arrow key push
164
-
165
- // Set to true to automatically rotate around the target
166
- // If auto-rotate is enabled, you must call controls.update() in your animation loop
167
- this.autoRotate = false;
168
- this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
169
-
170
- // Set to false to disable use of the keys
171
- this.enableKeys = true;
172
-
173
- // The four arrow keys
174
- this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
175
-
176
- // Mouse buttons
177
- this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
178
-
179
- // for reset
180
- this.target0 = this.target.clone();
181
- this.position0 = this.object.position.clone();
182
- this.zoom0 = this.object.zoom;
183
-
184
- //
185
- // public methods
186
- //
187
-
188
- this.getPolarAngle = function () {
189
-
190
- return spherical.phi;
191
-
192
- };
193
-
194
- this.getAzimuthalAngle = function () {
195
-
196
- return spherical.theta;
197
-
198
- };
199
-
200
- this.reset = function () {
201
-
202
- scope.target.copy( scope.target0 );
203
- scope.object.position.copy( scope.position0 );
204
- scope.object.zoom = scope.zoom0;
205
-
206
- scope.object.updateProjectionMatrix();
207
- scope.dispatchEvent( changeEvent );
208
-
209
- scope.update();
210
-
211
- state = STATE.NONE;
212
-
213
- };
214
-
215
- // this method is exposed, but perhaps it would be better if we can make it private...
216
- this.update = function() {
217
-
218
- var offset = new THREE.Vector3();
219
-
220
- // so camera.up is the orbit axis
221
- var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
222
- var quatInverse = quat.clone().inverse();
223
-
224
- var lastPosition = new THREE.Vector3();
225
- var lastQuaternion = new THREE.Quaternion();
226
-
227
- return function update () {
228
-
229
- var position = scope.object.position;
230
-
231
- offset.copy( position ).sub( scope.target );
232
-
233
- // rotate offset to "y-axis-is-up" space
234
- offset.applyQuaternion( quat );
235
-
236
- // angle from z-axis around y-axis
237
- spherical.setFromVector3( offset );
238
-
239
- if ( scope.autoRotate && state === STATE.NONE ) {
240
-
241
- rotateLeft( getAutoRotationAngle() );
242
-
243
- }
244
-
245
- spherical.theta += sphericalDelta.theta;
246
- spherical.phi += sphericalDelta.phi;
247
-
248
- // restrict theta to be between desired limits
249
- spherical.theta = Math.max( scope.minAzimuthAngle, Math.min( scope.maxAzimuthAngle, spherical.theta ) );
250
-
251
- // restrict phi to be between desired limits
252
- spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
253
-
254
- spherical.makeSafe();
255
-
256
-
257
- spherical.radius *= scale;
258
-
259
- // restrict radius to be between desired limits
260
- spherical.radius = Math.max( scope.minDistance, Math.min( scope.maxDistance, spherical.radius ) );
261
-
262
- // move target to panned location
263
- scope.target.add( panOffset );
264
-
265
- offset.setFromSpherical( spherical );
266
-
267
- // rotate offset back to "camera-up-vector-is-up" space
268
- offset.applyQuaternion( quatInverse );
269
-
270
- position.copy( scope.target ).add( offset );
271
-
272
- scope.object.lookAt( scope.target );
273
-
274
- if ( scope.enableDamping === true ) {
275
-
276
- sphericalDelta.theta *= ( 1 - scope.dampingFactor );
277
- sphericalDelta.phi *= ( 1 - scope.dampingFactor );
278
-
279
- } else {
280
-
281
- sphericalDelta.set( 0, 0, 0 );
282
-
283
- }
284
-
285
- scale = 1;
286
- panOffset.set( 0, 0, 0 );
287
-
288
- // update condition is:
289
- // min(camera displacement, camera rotation in radians)^2 > EPS
290
- // using small-angle approximation cos(x/2) = 1 - x^2 / 8
291
-
292
- if ( zoomChanged ||
293
- lastPosition.distanceToSquared( scope.object.position ) > EPS ||
294
- 8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
295
-
296
- scope.dispatchEvent( changeEvent );
297
-
298
- lastPosition.copy( scope.object.position );
299
- lastQuaternion.copy( scope.object.quaternion );
300
- zoomChanged = false;
301
-
302
- return true;
303
-
304
- }
305
-
306
- return false;
307
-
308
- };
309
-
310
- }();
311
-
312
- this.dispose = function() {
313
-
314
- scope.domElement.removeEventListener( 'contextmenu', onContextMenu, false );
315
- scope.domElement.removeEventListener( 'mousedown', onMouseDown, false );
316
- scope.domElement.removeEventListener( 'wheel', onMouseWheel, false );
317
-
318
- scope.domElement.removeEventListener( 'touchstart', onTouchStart, false );
319
- scope.domElement.removeEventListener( 'touchend', onTouchEnd, false );
320
- scope.domElement.removeEventListener( 'touchmove', onTouchMove, false );
321
-
322
- document.removeEventListener( 'mousemove', onMouseMove, false );
323
- document.removeEventListener( 'mouseup', onMouseUp, false );
324
-
325
- window.removeEventListener( 'keydown', onKeyDown, false );
326
-
327
- //scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
328
-
329
- };
330
-
331
- //
332
- // internals
333
- //
334
-
335
- var scope = this;
336
-
337
- var changeEvent = { type: 'change' };
338
- var startEvent = { type: 'start' };
339
- var endEvent = { type: 'end' };
340
-
341
- var STATE = { NONE : - 1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 };
342
-
343
- var state = STATE.NONE;
344
-
345
- var EPS = 0.000001;
346
-
347
- // current position in spherical coordinates
348
- var spherical = new THREE.Spherical();
349
- var sphericalDelta = new THREE.Spherical();
350
-
351
- var scale = 1;
352
- var panOffset = new THREE.Vector3();
353
- var zoomChanged = false;
354
-
355
- var rotateStart = new THREE.Vector2();
356
- var rotateEnd = new THREE.Vector2();
357
- var rotateDelta = new THREE.Vector2();
358
-
359
- var panStart = new THREE.Vector2();
360
- var panEnd = new THREE.Vector2();
361
- var panDelta = new THREE.Vector2();
362
-
363
- var dollyStart = new THREE.Vector2();
364
- var dollyEnd = new THREE.Vector2();
365
- var dollyDelta = new THREE.Vector2();
366
-
367
- function getAutoRotationAngle() {
368
-
369
- return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
370
-
371
- }
372
-
373
- function getZoomScale() {
374
-
375
- return Math.pow( 0.95, scope.zoomSpeed );
376
-
377
- }
378
-
379
- function rotateLeft( angle ) {
380
-
381
- sphericalDelta.theta -= angle;
382
-
383
- }
384
-
385
- function rotateUp( angle ) {
386
-
387
- sphericalDelta.phi -= angle;
388
-
389
- }
390
-
391
- var panLeft = function() {
392
-
393
- var v = new THREE.Vector3();
394
-
395
- return function panLeft( distance, objectMatrix ) {
396
-
397
- v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
398
- v.multiplyScalar( - distance );
399
-
400
- panOffset.add( v );
401
-
402
- };
403
-
404
- }();
405
-
406
- var panUp = function() {
407
-
408
- var v = new THREE.Vector3();
409
-
410
- return function panUp( distance, objectMatrix ) {
411
-
412
- v.setFromMatrixColumn( objectMatrix, 1 ); // get Y column of objectMatrix
413
- v.multiplyScalar( distance );
414
-
415
- panOffset.add( v );
416
-
417
- };
418
-
419
- }();
420
-
421
- // deltaX and deltaY are in pixels; right and down are positive
422
- var pan = function() {
423
-
424
- var offset = new THREE.Vector3();
425
-
426
- return function pan ( deltaX, deltaY ) {
427
-
428
- var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
429
-
430
- if ( scope.object instanceof THREE.PerspectiveCamera ) {
431
-
432
- // perspective
433
- var position = scope.object.position;
434
- offset.copy( position ).sub( scope.target );
435
- var targetDistance = offset.length();
436
-
437
- // half of the fov is center to top of screen
438
- targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
439
-
440
- // we actually don't use screenWidth, since perspective camera is fixed to screen height
441
- panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix );
442
- panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix );
443
-
444
- } else if ( scope.object instanceof THREE.OrthographicCamera ) {
445
-
446
- // orthographic
447
- panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom / element.clientWidth, scope.object.matrix );
448
- panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom / element.clientHeight, scope.object.matrix );
449
-
450
- } else {
451
-
452
- // camera neither orthographic nor perspective
453
- console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
454
- scope.enablePan = false;
455
-
456
- }
457
-
458
- };
459
-
460
- }();
461
-
462
- function dollyIn( dollyScale ) {
463
-
464
- if ( scope.object instanceof THREE.PerspectiveCamera ) {
465
-
466
- scale /= dollyScale;
467
-
468
- } else if ( scope.object instanceof THREE.OrthographicCamera ) {
469
-
470
- scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom * dollyScale ) );
471
- scope.object.updateProjectionMatrix();
472
- zoomChanged = true;
473
-
474
- } else {
475
-
476
- console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
477
- scope.enableZoom = false;
478
-
479
- }
480
-
481
- }
482
-
483
- function dollyOut( dollyScale ) {
484
-
485
- if ( scope.object instanceof THREE.PerspectiveCamera ) {
486
-
487
- scale *= dollyScale;
488
-
489
- } else if ( scope.object instanceof THREE.OrthographicCamera ) {
490
-
491
- scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / dollyScale ) );
492
- scope.object.updateProjectionMatrix();
493
- zoomChanged = true;
494
-
495
- } else {
496
-
497
- console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
498
- scope.enableZoom = false;
499
-
500
- }
501
-
502
- }
503
-
504
- //
505
- // event callbacks - update the object state
506
- //
507
-
508
- function handleMouseDownRotate( event ) {
509
-
510
- //console.log( 'handleMouseDownRotate' );
511
-
512
- rotateStart.set( event.clientX, event.clientY );
513
-
514
- }
515
-
516
- function handleMouseDownDolly( event ) {
517
-
518
- //console.log( 'handleMouseDownDolly' );
519
-
520
- dollyStart.set( event.clientX, event.clientY );
521
-
522
- }
523
-
524
- function handleMouseDownPan( event ) {
525
-
526
- //console.log( 'handleMouseDownPan' );
527
-
528
- panStart.set( event.clientX, event.clientY );
529
-
530
- }
531
-
532
- function handleMouseMoveRotate( event ) {
533
-
534
- //console.log( 'handleMouseMoveRotate' );
535
-
536
- rotateEnd.set( event.clientX, event.clientY );
537
- rotateDelta.subVectors( rotateEnd, rotateStart );
538
-
539
- var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
540
-
541
- // rotating across whole screen goes 360 degrees around
542
- rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
543
-
544
- // rotating up and down along whole screen attempts to go 360, but limited to 180
545
- rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
546
-
547
- rotateStart.copy( rotateEnd );
548
-
549
- scope.update();
550
-
551
- }
552
-
553
- function handleMouseMoveDolly( event ) {
554
-
555
- //console.log( 'handleMouseMoveDolly' );
556
-
557
- dollyEnd.set( event.clientX, event.clientY );
558
-
559
- dollyDelta.subVectors( dollyEnd, dollyStart );
560
-
561
- if ( dollyDelta.y > 0 ) {
562
-
563
- dollyIn( getZoomScale() );
564
-
565
- } else if ( dollyDelta.y < 0 ) {
566
-
567
- dollyOut( getZoomScale() );
568
-
569
- }
570
-
571
- dollyStart.copy( dollyEnd );
572
-
573
- scope.update();
574
-
575
- }
576
-
577
- function handleMouseMovePan( event ) {
578
-
579
- //console.log( 'handleMouseMovePan' );
580
-
581
- panEnd.set( event.clientX, event.clientY );
582
-
583
- panDelta.subVectors( panEnd, panStart );
584
-
585
- pan( panDelta.x, panDelta.y );
586
-
587
- panStart.copy( panEnd );
588
-
589
- scope.update();
590
-
591
- }
592
-
593
- function handleMouseWheel( event ) {
594
-
595
- //console.log( 'handleMouseWheel' );
596
-
597
- if ( event.deltaY < 0 ) {
598
-
599
- dollyOut( getZoomScale() );
600
-
601
- } else if ( event.deltaY > 0 ) {
602
-
603
- dollyIn( getZoomScale() );
604
-
605
- }
606
-
607
- scope.update();
608
-
609
- }
610
-
611
- function handleKeyDown( event ) {
612
-
613
- //console.log( 'handleKeyDown' );
614
-
615
- switch ( event.keyCode ) {
616
-
617
- case scope.keys.UP:
618
- pan( 0, scope.keyPanSpeed );
619
- scope.update();
620
- break;
621
-
622
- case scope.keys.BOTTOM:
623
- pan( 0, - scope.keyPanSpeed );
624
- scope.update();
625
- break;
626
-
627
- case scope.keys.LEFT:
628
- pan( scope.keyPanSpeed, 0 );
629
- scope.update();
630
- break;
631
-
632
- case scope.keys.RIGHT:
633
- pan( - scope.keyPanSpeed, 0 );
634
- scope.update();
635
- break;
636
-
637
- }
638
-
639
- }
640
-
641
- function handleTouchStartRotate( event ) {
642
-
643
- //console.log( 'handleTouchStartRotate' );
644
-
645
- rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
646
-
647
- }
648
-
649
- function handleTouchStartDolly( event ) {
650
-
651
- //console.log( 'handleTouchStartDolly' );
652
-
653
- var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
654
- var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
655
-
656
- var distance = Math.sqrt( dx * dx + dy * dy );
657
-
658
- dollyStart.set( 0, distance );
659
-
660
- }
661
-
662
- function handleTouchStartPan( event ) {
663
-
664
- //console.log( 'handleTouchStartPan' );
665
-
666
- panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
667
-
668
- }
669
-
670
- function handleTouchMoveRotate( event ) {
671
-
672
- //console.log( 'handleTouchMoveRotate' );
673
-
674
- rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
675
- rotateDelta.subVectors( rotateEnd, rotateStart );
676
-
677
- var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
678
-
679
- // rotating across whole screen goes 360 degrees around
680
- rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
681
-
682
- // rotating up and down along whole screen attempts to go 360, but limited to 180
683
- rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
684
-
685
- rotateStart.copy( rotateEnd );
686
-
687
- scope.update();
688
-
689
- }
690
-
691
- function handleTouchMoveDolly( event ) {
692
-
693
- //console.log( 'handleTouchMoveDolly' );
694
-
695
- var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
696
- var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
697
-
698
- var distance = Math.sqrt( dx * dx + dy * dy );
699
-
700
- dollyEnd.set( 0, distance );
701
-
702
- dollyDelta.subVectors( dollyEnd, dollyStart );
703
-
704
- if ( dollyDelta.y > 0 ) {
705
-
706
- dollyOut( getZoomScale() );
707
-
708
- } else if ( dollyDelta.y < 0 ) {
709
-
710
- dollyIn( getZoomScale() );
711
-
712
- }
713
-
714
- dollyStart.copy( dollyEnd );
715
-
716
- scope.update();
717
-
718
- }
719
-
720
- function handleTouchMovePan( event ) {
721
-
722
- //console.log( 'handleTouchMovePan' );
723
-
724
- panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
725
-
726
- panDelta.subVectors( panEnd, panStart );
727
-
728
- pan( panDelta.x, panDelta.y );
729
-
730
- panStart.copy( panEnd );
731
-
732
- scope.update();
733
-
734
- }
735
-
736
- //
737
- // event handlers - FSM: listen for events and reset state
738
- //
739
-
740
- function onMouseDown( event ) {
741
-
742
- if ( scope.enabled === false ) return;
743
-
744
- event.preventDefault();
745
-
746
- if ( event.button === scope.mouseButtons.ORBIT ) {
747
-
748
- if ( scope.enableRotate === false ) return;
749
-
750
- handleMouseDownRotate( event );
751
-
752
- state = STATE.ROTATE;
753
-
754
- } else if ( event.button === scope.mouseButtons.ZOOM ) {
755
-
756
- if ( scope.enableZoom === false ) return;
757
-
758
- handleMouseDownDolly( event );
759
-
760
- state = STATE.DOLLY;
761
-
762
- } else if ( event.button === scope.mouseButtons.PAN ) {
763
-
764
- if ( scope.enablePan === false ) return;
765
-
766
- handleMouseDownPan( event );
767
-
768
- state = STATE.PAN;
769
-
770
- }
771
-
772
- if ( state !== STATE.NONE ) {
773
-
774
- document.addEventListener( 'mousemove', onMouseMove, false );
775
- document.addEventListener( 'mouseup', onMouseUp, false );
776
-
777
- scope.dispatchEvent( startEvent );
778
-
779
- }
780
-
781
- }
782
-
783
- function onMouseMove( event ) {
784
-
785
- if ( scope.enabled === false ) return;
786
-
787
- event.preventDefault();
788
-
789
- if ( state === STATE.ROTATE ) {
790
-
791
- if ( scope.enableRotate === false ) return;
792
-
793
- handleMouseMoveRotate( event );
794
-
795
- } else if ( state === STATE.DOLLY ) {
796
-
797
- if ( scope.enableZoom === false ) return;
798
-
799
- handleMouseMoveDolly( event );
800
-
801
- } else if ( state === STATE.PAN ) {
802
-
803
- if ( scope.enablePan === false ) return;
804
-
805
- handleMouseMovePan( event );
806
-
807
- }
808
-
809
- }
810
-
811
- function onMouseUp( event ) {
812
-
813
- if ( scope.enabled === false ) return;
814
-
815
- document.removeEventListener( 'mousemove', onMouseMove, false );
816
- document.removeEventListener( 'mouseup', onMouseUp, false );
817
-
818
- scope.dispatchEvent( endEvent );
819
-
820
- state = STATE.NONE;
821
-
822
- }
823
-
824
- function onMouseWheel( event ) {
825
-
826
- if ( scope.enabled === false || scope.enableZoom === false || ( state !== STATE.NONE && state !== STATE.ROTATE ) ) return;
827
-
828
- event.preventDefault();
829
- event.stopPropagation();
830
-
831
- handleMouseWheel( event );
832
-
833
- scope.dispatchEvent( startEvent ); // not sure why these are here...
834
- scope.dispatchEvent( endEvent );
835
-
836
- }
837
-
838
- function onKeyDown( event ) {
839
-
840
- if ( scope.enabled === false || scope.enableKeys === false || scope.enablePan === false ) return;
841
-
842
- handleKeyDown( event );
843
-
844
- }
845
-
846
- function onTouchStart( event ) {
847
-
848
- if ( scope.enabled === false ) return;
849
-
850
- switch ( event.touches.length ) {
851
-
852
- case 1: // one-fingered touch: rotate
853
-
854
- if ( scope.enableRotate === false ) return;
855
-
856
- handleTouchStartRotate( event );
857
-
858
- state = STATE.TOUCH_ROTATE;
859
-
860
- break;
861
-
862
- case 2: // two-fingered touch: dolly
863
-
864
- if ( scope.enableZoom === false ) return;
865
-
866
- handleTouchStartDolly( event );
867
-
868
- state = STATE.TOUCH_DOLLY;
869
-
870
- break;
871
-
872
- case 3: // three-fingered touch: pan
873
-
874
- if ( scope.enablePan === false ) return;
875
-
876
- handleTouchStartPan( event );
877
-
878
- state = STATE.TOUCH_PAN;
879
-
880
- break;
881
-
882
- default:
883
-
884
- state = STATE.NONE;
885
-
886
- }
887
-
888
- if ( state !== STATE.NONE ) {
889
-
890
- scope.dispatchEvent( startEvent );
891
-
892
- }
893
-
894
- }
895
-
896
- function onTouchMove( event ) {
897
-
898
- if ( scope.enabled === false ) return;
899
-
900
- event.preventDefault();
901
- event.stopPropagation();
902
-
903
- switch ( event.touches.length ) {
904
-
905
- case 1: // one-fingered touch: rotate
906
-
907
- if ( scope.enableRotate === false ) return;
908
- if ( state !== STATE.TOUCH_ROTATE ) return; // is this needed?...
909
-
910
- handleTouchMoveRotate( event );
911
-
912
- break;
913
-
914
- case 2: // two-fingered touch: dolly
915
-
916
- if ( scope.enableZoom === false ) return;
917
- if ( state !== STATE.TOUCH_DOLLY ) return; // is this needed?...
918
-
919
- handleTouchMoveDolly( event );
920
-
921
- break;
922
-
923
- case 3: // three-fingered touch: pan
924
-
925
- if ( scope.enablePan === false ) return;
926
- if ( state !== STATE.TOUCH_PAN ) return; // is this needed?...
927
-
928
- handleTouchMovePan( event );
929
-
930
- break;
931
-
932
- default:
933
-
934
- state = STATE.NONE;
935
-
936
- }
937
-
938
- }
939
-
940
- function onTouchEnd( event ) {
941
-
942
- if ( scope.enabled === false ) return;
943
-
944
- scope.dispatchEvent( endEvent );
945
-
946
- state = STATE.NONE;
947
-
948
- }
949
-
950
- function onContextMenu( event ) {
951
-
952
- event.preventDefault();
953
-
954
- }
955
-
956
- //
957
-
958
- scope.domElement.addEventListener( 'contextmenu', onContextMenu, false );
959
-
960
- scope.domElement.addEventListener( 'mousedown', onMouseDown, false );
961
- scope.domElement.addEventListener( 'wheel', onMouseWheel, false );
962
-
963
- scope.domElement.addEventListener( 'touchstart', onTouchStart, false );
964
- scope.domElement.addEventListener( 'touchend', onTouchEnd, false );
965
- scope.domElement.addEventListener( 'touchmove', onTouchMove, false );
966
-
967
- window.addEventListener( 'keydown', onKeyDown, false );
968
-
969
- // force an update at start
970
-
971
- this.update();
972
-
973
- }
974
- OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
975
- OrbitControls.prototype.constructor = OrbitControls;
976
-
977
- Object.defineProperties( OrbitControls.prototype, {
978
-
979
- center: {
980
-
981
- get: function () {
982
-
983
- console.warn( 'THREE.OrbitControls: .center has been renamed to .target' );
984
- return this.target;
985
-
986
- }
987
-
988
- },
989
-
990
- // backward compatibility
991
-
992
- noZoom: {
993
-
994
- get: function () {
995
-
996
- console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
997
- return ! this.enableZoom;
998
-
999
- },
1000
-
1001
- set: function ( value ) {
1002
-
1003
- console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
1004
- this.enableZoom = ! value;
1005
-
1006
- }
1007
-
1008
- },
1009
-
1010
- noRotate: {
1011
-
1012
- get: function () {
1013
-
1014
- console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
1015
- return ! this.enableRotate;
1016
-
1017
- },
1018
-
1019
- set: function ( value ) {
1020
-
1021
- console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
1022
- this.enableRotate = ! value;
1023
-
1024
- }
1025
-
1026
- },
1027
-
1028
- noPan: {
1029
-
1030
- get: function () {
1031
-
1032
- console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
1033
- return ! this.enablePan;
1034
-
1035
- },
1036
-
1037
- set: function ( value ) {
1038
-
1039
- console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
1040
- this.enablePan = ! value;
1041
-
1042
- }
1043
-
1044
- },
1045
-
1046
- noKeys: {
1047
-
1048
- get: function () {
1049
-
1050
- console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
1051
- return ! this.enableKeys;
1052
-
1053
- },
1054
-
1055
- set: function ( value ) {
1056
-
1057
- console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
1058
- this.enableKeys = ! value;
1059
-
1060
- }
1061
-
1062
- },
1063
-
1064
- staticMoving : {
1065
-
1066
- get: function () {
1067
-
1068
- console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
1069
- return ! this.enableDamping;
1070
-
1071
- },
1072
-
1073
- set: function ( value ) {
1074
-
1075
- console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
1076
- this.enableDamping = ! value;
1077
-
1078
- }
1079
-
1080
- },
1081
-
1082
- dynamicDampingFactor : {
1083
-
1084
- get: function () {
1085
-
1086
- console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
1087
- return this.dampingFactor;
1088
-
1089
- },
1090
-
1091
- set: function ( value ) {
1092
-
1093
- console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
1094
- this.dampingFactor = value;
1095
-
1096
- }
1097
-
1098
- }
1099
-
1100
- } );
1101
-
1102
- return OrbitControls;
1103
- };
1104
-
1105
- const OrbitControls = /*@__PURE__*/getDefaultExportFromCjs(threeOrbitControls);
1106
-
1107
- var xhr$1 = {exports: {}};
1108
-
1109
- var win;
1110
-
1111
- if (typeof window !== "undefined") {
1112
- win = window;
1113
- } else if (typeof commonjsGlobal !== "undefined") {
1114
- win = commonjsGlobal;
1115
- } else if (typeof self !== "undefined"){
1116
- win = self;
1117
- } else {
1118
- win = {};
1119
- }
1120
-
1121
- var window_1 = win;
1122
-
1123
- var isFunction_1 = isFunction$1;
1124
-
1125
- var toString = Object.prototype.toString;
1126
-
1127
- function isFunction$1 (fn) {
1128
- if (!fn) {
1129
- return false
1130
- }
1131
- var string = toString.call(fn);
1132
- return string === '[object Function]' ||
1133
- (typeof fn === 'function' && string !== '[object RegExp]') ||
1134
- (typeof window !== 'undefined' &&
1135
- // IE8 and below
1136
- (fn === window.setTimeout ||
1137
- fn === window.alert ||
1138
- fn === window.confirm ||
1139
- fn === window.prompt))
1140
- }
1141
-
1142
- var trim = function(string) {
1143
- return string.replace(/^\s+|\s+$/g, '');
1144
- }
1145
- , isArray = function(arg) {
1146
- return Object.prototype.toString.call(arg) === '[object Array]';
1147
- };
1148
-
1149
- var parseHeaders$1 = function (headers) {
1150
- if (!headers)
1151
- return {}
1152
-
1153
- var result = {};
1154
-
1155
- var headersArr = trim(headers).split('\n');
1156
-
1157
- for (var i = 0; i < headersArr.length; i++) {
1158
- var row = headersArr[i];
1159
- var index = row.indexOf(':')
1160
- , key = trim(row.slice(0, index)).toLowerCase()
1161
- , value = trim(row.slice(index + 1));
1162
-
1163
- if (typeof(result[key]) === 'undefined') {
1164
- result[key] = value;
1165
- } else if (isArray(result[key])) {
1166
- result[key].push(value);
1167
- } else {
1168
- result[key] = [ result[key], value ];
1169
- }
1170
- }
1171
-
1172
- return result
1173
- };
1174
-
1175
- var immutable = extend;
1176
-
1177
- var hasOwnProperty = Object.prototype.hasOwnProperty;
1178
-
1179
- function extend() {
1180
- var target = {};
1181
-
1182
- for (var i = 0; i < arguments.length; i++) {
1183
- var source = arguments[i];
1184
-
1185
- for (var key in source) {
1186
- if (hasOwnProperty.call(source, key)) {
1187
- target[key] = source[key];
1188
- }
1189
- }
1190
- }
1191
-
1192
- return target
1193
- }
1194
-
1195
- var window$1 = window_1;
1196
- var isFunction = isFunction_1;
1197
- var parseHeaders = parseHeaders$1;
1198
- var xtend$2 = immutable;
1199
-
1200
- xhr$1.exports = createXHR;
1201
- // Allow use of default import syntax in TypeScript
1202
- xhr$1.exports.default = createXHR;
1203
- createXHR.XMLHttpRequest = window$1.XMLHttpRequest || noop$1;
1204
- createXHR.XDomainRequest = "withCredentials" in (new createXHR.XMLHttpRequest()) ? createXHR.XMLHttpRequest : window$1.XDomainRequest;
1205
-
1206
- forEachArray(["get", "put", "post", "patch", "head", "delete"], function(method) {
1207
- createXHR[method === "delete" ? "del" : method] = function(uri, options, callback) {
1208
- options = initParams(uri, options, callback);
1209
- options.method = method.toUpperCase();
1210
- return _createXHR(options)
1211
- };
1212
- });
1213
-
1214
- function forEachArray(array, iterator) {
1215
- for (var i = 0; i < array.length; i++) {
1216
- iterator(array[i]);
1217
- }
1218
- }
1219
-
1220
- function isEmpty(obj){
1221
- for(var i in obj){
1222
- if(obj.hasOwnProperty(i)) return false
1223
- }
1224
- return true
1225
- }
1226
-
1227
- function initParams(uri, options, callback) {
1228
- var params = uri;
1229
-
1230
- if (isFunction(options)) {
1231
- callback = options;
1232
- if (typeof uri === "string") {
1233
- params = {uri:uri};
1234
- }
1235
- } else {
1236
- params = xtend$2(options, {uri: uri});
1237
- }
1238
-
1239
- params.callback = callback;
1240
- return params
1241
- }
1242
-
1243
- function createXHR(uri, options, callback) {
1244
- options = initParams(uri, options, callback);
1245
- return _createXHR(options)
1246
- }
1247
-
1248
- function _createXHR(options) {
1249
- if(typeof options.callback === "undefined"){
1250
- throw new Error("callback argument missing")
1251
- }
1252
-
1253
- var called = false;
1254
- var callback = function cbOnce(err, response, body){
1255
- if(!called){
1256
- called = true;
1257
- options.callback(err, response, body);
1258
- }
1259
- };
1260
-
1261
- function readystatechange() {
1262
- if (xhr.readyState === 4) {
1263
- setTimeout(loadFunc, 0);
1264
- }
1265
- }
1266
-
1267
- function getBody() {
1268
- // Chrome with requestType=blob throws errors arround when even testing access to responseText
1269
- var body = undefined;
1270
-
1271
- if (xhr.response) {
1272
- body = xhr.response;
1273
- } else {
1274
- body = xhr.responseText || getXml(xhr);
1275
- }
1276
-
1277
- if (isJson) {
1278
- try {
1279
- body = JSON.parse(body);
1280
- } catch (e) {}
1281
- }
1282
-
1283
- return body
1284
- }
1285
-
1286
- function errorFunc(evt) {
1287
- clearTimeout(timeoutTimer);
1288
- if(!(evt instanceof Error)){
1289
- evt = new Error("" + (evt || "Unknown XMLHttpRequest Error") );
1290
- }
1291
- evt.statusCode = 0;
1292
- return callback(evt, failureResponse)
1293
- }
1294
-
1295
- // will load the data & process the response in a special response object
1296
- function loadFunc() {
1297
- if (aborted) return
1298
- var status;
1299
- clearTimeout(timeoutTimer);
1300
- if(options.useXDR && xhr.status===undefined) {
1301
- //IE8 CORS GET successful response doesn't have a status field, but body is fine
1302
- status = 200;
1303
- } else {
1304
- status = (xhr.status === 1223 ? 204 : xhr.status);
1305
- }
1306
- var response = failureResponse;
1307
- var err = null;
1308
-
1309
- if (status !== 0){
1310
- response = {
1311
- body: getBody(),
1312
- statusCode: status,
1313
- method: method,
1314
- headers: {},
1315
- url: uri,
1316
- rawRequest: xhr
1317
- };
1318
- if(xhr.getAllResponseHeaders){ //remember xhr can in fact be XDR for CORS in IE
1319
- response.headers = parseHeaders(xhr.getAllResponseHeaders());
1320
- }
1321
- } else {
1322
- err = new Error("Internal XMLHttpRequest Error");
1323
- }
1324
- return callback(err, response, response.body)
1325
- }
1326
-
1327
- var xhr = options.xhr || null;
1328
-
1329
- if (!xhr) {
1330
- if (options.cors || options.useXDR) {
1331
- xhr = new createXHR.XDomainRequest();
1332
- }else {
1333
- xhr = new createXHR.XMLHttpRequest();
1334
- }
1335
- }
1336
-
1337
- var key;
1338
- var aborted;
1339
- var uri = xhr.url = options.uri || options.url;
1340
- var method = xhr.method = options.method || "GET";
1341
- var body = options.body || options.data;
1342
- var headers = xhr.headers = options.headers || {};
1343
- var sync = !!options.sync;
1344
- var isJson = false;
1345
- var timeoutTimer;
1346
- var failureResponse = {
1347
- body: undefined,
1348
- headers: {},
1349
- statusCode: 0,
1350
- method: method,
1351
- url: uri,
1352
- rawRequest: xhr
1353
- };
1354
-
1355
- if ("json" in options && options.json !== false) {
1356
- isJson = true;
1357
- headers["accept"] || headers["Accept"] || (headers["Accept"] = "application/json"); //Don't override existing accept header declared by user
1358
- if (method !== "GET" && method !== "HEAD") {
1359
- headers["content-type"] || headers["Content-Type"] || (headers["Content-Type"] = "application/json"); //Don't override existing accept header declared by user
1360
- body = JSON.stringify(options.json === true ? body : options.json);
1361
- }
1362
- }
1363
-
1364
- xhr.onreadystatechange = readystatechange;
1365
- xhr.onload = loadFunc;
1366
- xhr.onerror = errorFunc;
1367
- // IE9 must have onprogress be set to a unique function.
1368
- xhr.onprogress = function () {
1369
- // IE must die
1370
- };
1371
- xhr.onabort = function(){
1372
- aborted = true;
1373
- };
1374
- xhr.ontimeout = errorFunc;
1375
- xhr.open(method, uri, !sync, options.username, options.password);
1376
- //has to be after open
1377
- if(!sync) {
1378
- xhr.withCredentials = !!options.withCredentials;
1379
- }
1380
- // Cannot set timeout with sync request
1381
- // not setting timeout on the xhr object, because of old webkits etc. not handling that correctly
1382
- // both npm's request and jquery 1.x use this kind of timeout, so this is being consistent
1383
- if (!sync && options.timeout > 0 ) {
1384
- timeoutTimer = setTimeout(function(){
1385
- if (aborted) return
1386
- aborted = true;//IE9 may still call readystatechange
1387
- xhr.abort("timeout");
1388
- var e = new Error("XMLHttpRequest timeout");
1389
- e.code = "ETIMEDOUT";
1390
- errorFunc(e);
1391
- }, options.timeout );
1392
- }
1393
-
1394
- if (xhr.setRequestHeader) {
1395
- for(key in headers){
1396
- if(headers.hasOwnProperty(key)){
1397
- xhr.setRequestHeader(key, headers[key]);
1398
- }
1399
- }
1400
- } else if (options.headers && !isEmpty(options.headers)) {
1401
- throw new Error("Headers cannot be set on an XDomainRequest object")
1402
- }
1403
-
1404
- if ("responseType" in options) {
1405
- xhr.responseType = options.responseType;
1406
- }
1407
-
1408
- if ("beforeSend" in options &&
1409
- typeof options.beforeSend === "function"
1410
- ) {
1411
- options.beforeSend(xhr);
1412
- }
1413
-
1414
- // Microsoft Edge browser sends "undefined" when send is called with undefined value.
1415
- // XMLHttpRequest spec says to pass null as body to indicate no body
1416
- // See https://github.com/naugtur/xhr/issues/100.
1417
- xhr.send(body || null);
1418
-
1419
- return xhr
1420
-
1421
-
1422
- }
1423
-
1424
- function getXml(xhr) {
1425
- // xhr.responseXML will throw Exception "InvalidStateError" or "DOMException"
1426
- // See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseXML.
1427
- try {
1428
- if (xhr.responseType === "document") {
1429
- return xhr.responseXML
1430
- }
1431
- var firefoxBugTakenEffect = xhr.responseXML && xhr.responseXML.documentElement.nodeName === "parsererror";
1432
- if (xhr.responseType === "" && !firefoxBugTakenEffect) {
1433
- return xhr.responseXML
1434
- }
1435
- } catch (e) {}
1436
-
1437
- return null
1438
- }
1439
-
1440
- function noop$1() {}
1441
-
1442
- var xhrExports = xhr$1.exports;
1443
-
1444
- var parseBmfontAscii = function parseBMFontAscii(data) {
1445
- if (!data)
1446
- throw new Error('no data provided')
1447
- data = data.toString().trim();
1448
-
1449
- var output = {
1450
- pages: [],
1451
- chars: [],
1452
- kernings: []
1453
- };
1454
-
1455
- var lines = data.split(/\r\n?|\n/g);
1456
-
1457
- if (lines.length === 0)
1458
- throw new Error('no data in BMFont file')
1459
-
1460
- for (var i = 0; i < lines.length; i++) {
1461
- var lineData = splitLine(lines[i], i);
1462
- if (!lineData) //skip empty lines
1463
- continue
1464
-
1465
- if (lineData.key === 'page') {
1466
- if (typeof lineData.data.id !== 'number')
1467
- throw new Error('malformed file at line ' + i + ' -- needs page id=N')
1468
- if (typeof lineData.data.file !== 'string')
1469
- throw new Error('malformed file at line ' + i + ' -- needs page file="path"')
1470
- output.pages[lineData.data.id] = lineData.data.file;
1471
- } else if (lineData.key === 'chars' || lineData.key === 'kernings') ; else if (lineData.key === 'char') {
1472
- output.chars.push(lineData.data);
1473
- } else if (lineData.key === 'kerning') {
1474
- output.kernings.push(lineData.data);
1475
- } else {
1476
- output[lineData.key] = lineData.data;
1477
- }
1478
- }
1479
-
1480
- return output
1481
- };
1482
-
1483
- function splitLine(line, idx) {
1484
- line = line.replace(/\t+/g, ' ').trim();
1485
- if (!line)
1486
- return null
1487
-
1488
- var space = line.indexOf(' ');
1489
- if (space === -1)
1490
- throw new Error("no named row at line " + idx)
1491
-
1492
- var key = line.substring(0, space);
1493
-
1494
- line = line.substring(space + 1);
1495
- //clear "letter" field as it is non-standard and
1496
- //requires additional complexity to parse " / = symbols
1497
- line = line.replace(/letter=[\'\"]\S+[\'\"]/gi, '');
1498
- line = line.split("=");
1499
- line = line.map(function(str) {
1500
- return str.trim().match((/(".*?"|[^"\s]+)+(?=\s*|\s*$)/g))
1501
- });
1502
-
1503
- var data = [];
1504
- for (var i = 0; i < line.length; i++) {
1505
- var dt = line[i];
1506
- if (i === 0) {
1507
- data.push({
1508
- key: dt[0],
1509
- data: ""
1510
- });
1511
- } else if (i === line.length - 1) {
1512
- data[data.length - 1].data = parseData(dt[0]);
1513
- } else {
1514
- data[data.length - 1].data = parseData(dt[0]);
1515
- data.push({
1516
- key: dt[1],
1517
- data: ""
1518
- });
1519
- }
1520
- }
1521
-
1522
- var out = {
1523
- key: key,
1524
- data: {}
1525
- };
1526
-
1527
- data.forEach(function(v) {
1528
- out.data[v.key] = v.data;
1529
- });
1530
-
1531
- return out
1532
- }
1533
-
1534
- function parseData(data) {
1535
- if (!data || data.length === 0)
1536
- return ""
1537
-
1538
- if (data.indexOf('"') === 0 || data.indexOf("'") === 0)
1539
- return data.substring(1, data.length - 1)
1540
- if (data.indexOf(',') !== -1)
1541
- return parseIntList$1(data)
1542
- return parseInt(data, 10)
1543
- }
1544
-
1545
- function parseIntList$1(data) {
1546
- return data.split(',').map(function(val) {
1547
- return parseInt(val, 10)
1548
- })
1549
- }
1550
-
1551
- //Some versions of GlyphDesigner have a typo
1552
- //that causes some bugs with parsing.
1553
- //Need to confirm with recent version of the software
1554
- //to see whether this is still an issue or not.
1555
- var GLYPH_DESIGNER_ERROR = 'chasrset';
1556
-
1557
- var parseAttribs = function parseAttributes(obj) {
1558
- obj = Object.assign({}, obj);
1559
- if (GLYPH_DESIGNER_ERROR in obj) {
1560
- obj['charset'] = obj[GLYPH_DESIGNER_ERROR];
1561
- delete obj[GLYPH_DESIGNER_ERROR];
1562
- }
1563
-
1564
- for (var k in obj) {
1565
- if (k === 'face' || k === 'charset')
1566
- continue
1567
- else if (k === 'padding' || k === 'spacing')
1568
- obj[k] = parseIntList(obj[k]);
1569
- else
1570
- obj[k] = parseInt(obj[k], 10);
1571
- }
1572
- return obj
1573
- };
1574
-
1575
- function parseIntList(data) {
1576
- return data.split(',').map(function(val) {
1577
- return parseInt(val, 10)
1578
- })
1579
- }
1580
-
1581
- var xmlParseFromString = (function xmlparser() {
1582
- //common browsers
1583
- if (typeof self.DOMParser !== 'undefined') {
1584
- return function(str) {
1585
- var parser = new self.DOMParser();
1586
- return parser.parseFromString(str, 'application/xml')
1587
- }
1588
- }
1589
-
1590
- //IE8 fallback
1591
- if (typeof self.ActiveXObject !== 'undefined'
1592
- && new self.ActiveXObject('Microsoft.XMLDOM')) {
1593
- return function(str) {
1594
- var xmlDoc = new self.ActiveXObject("Microsoft.XMLDOM");
1595
- xmlDoc.async = "false";
1596
- xmlDoc.loadXML(str);
1597
- return xmlDoc
1598
- }
1599
- }
1600
-
1601
- //last resort fallback
1602
- return function(str) {
1603
- var div = document.createElement('div');
1604
- div.innerHTML = str;
1605
- return div
1606
- }
1607
- })();
1608
-
1609
- var parseAttributes = parseAttribs;
1610
- var parseFromString = xmlParseFromString;
1611
-
1612
- //In some cases element.attribute.nodeName can return
1613
- //all lowercase values.. so we need to map them to the correct
1614
- //case
1615
- var NAME_MAP = {
1616
- scaleh: 'scaleH',
1617
- scalew: 'scaleW',
1618
- stretchh: 'stretchH',
1619
- lineheight: 'lineHeight',
1620
- alphachnl: 'alphaChnl',
1621
- redchnl: 'redChnl',
1622
- greenchnl: 'greenChnl',
1623
- bluechnl: 'blueChnl'
1624
- };
1625
-
1626
- var browser$1 = function parse(data) {
1627
- data = data.toString();
1628
-
1629
- var xmlRoot = parseFromString(data);
1630
- var output = {
1631
- pages: [],
1632
- chars: [],
1633
- kernings: []
1634
- }
1635
-
1636
- //get config settings
1637
- ;['info', 'common'].forEach(function(key) {
1638
- var element = xmlRoot.getElementsByTagName(key)[0];
1639
- if (element)
1640
- output[key] = parseAttributes(getAttribs(element));
1641
- });
1642
-
1643
- //get page info
1644
- var pageRoot = xmlRoot.getElementsByTagName('pages')[0];
1645
- if (!pageRoot)
1646
- throw new Error('malformed file -- no <pages> element')
1647
- var pages = pageRoot.getElementsByTagName('page');
1648
- for (var i=0; i<pages.length; i++) {
1649
- var p = pages[i];
1650
- var id = parseInt(p.getAttribute('id'), 10);
1651
- var file = p.getAttribute('file');
1652
- if (isNaN(id))
1653
- throw new Error('malformed file -- page "id" attribute is NaN')
1654
- if (!file)
1655
- throw new Error('malformed file -- needs page "file" attribute')
1656
- output.pages[parseInt(id, 10)] = file;
1657
- }
1658
- ['chars', 'kernings'].forEach(function(key) {
1659
- var element = xmlRoot.getElementsByTagName(key)[0];
1660
- if (!element)
1661
- return
1662
- var childTag = key.substring(0, key.length-1);
1663
- var children = element.getElementsByTagName(childTag);
1664
- for (var i=0; i<children.length; i++) {
1665
- var child = children[i];
1666
- output[key].push(parseAttributes(getAttribs(child)));
1667
- }
1668
- });
1669
- return output
1670
- };
1671
-
1672
- function getAttribs(element) {
1673
- var attribs = getAttribList(element);
1674
- return attribs.reduce(function(dict, attrib) {
1675
- var key = mapName(attrib.nodeName);
1676
- dict[key] = attrib.nodeValue;
1677
- return dict
1678
- }, {})
1679
- }
1680
-
1681
- function getAttribList(element) {
1682
- //IE8+ and modern browsers
1683
- var attribs = [];
1684
- for (var i=0; i<element.attributes.length; i++)
1685
- attribs.push(element.attributes[i]);
1686
- return attribs
1687
- }
1688
-
1689
- function mapName(nodeName) {
1690
- return NAME_MAP[nodeName.toLowerCase()] || nodeName
1691
- }
1692
-
1693
- var HEADER$1 = [66, 77, 70];
1694
-
1695
- var parseBmfontBinary = function readBMFontBinary(buf) {
1696
- if (buf.length < 6)
1697
- throw new Error('invalid buffer length for BMFont')
1698
-
1699
- var header = HEADER$1.every(function(byte, i) {
1700
- return buf.readUInt8(i) === byte
1701
- });
1702
-
1703
- if (!header)
1704
- throw new Error('BMFont missing BMF byte header')
1705
-
1706
- var i = 3;
1707
- var vers = buf.readUInt8(i++);
1708
- if (vers > 3)
1709
- throw new Error('Only supports BMFont Binary v3 (BMFont App v1.10)')
1710
-
1711
- var target = { kernings: [], chars: [] };
1712
- for (var b=0; b<5; b++)
1713
- i += readBlock(target, buf, i);
1714
- return target
1715
- };
1716
-
1717
- function readBlock(target, buf, i) {
1718
- if (i > buf.length-1)
1719
- return 0
1720
-
1721
- var blockID = buf.readUInt8(i++);
1722
- var blockSize = buf.readInt32LE(i);
1723
- i += 4;
1724
-
1725
- switch(blockID) {
1726
- case 1:
1727
- target.info = readInfo(buf, i);
1728
- break
1729
- case 2:
1730
- target.common = readCommon(buf, i);
1731
- break
1732
- case 3:
1733
- target.pages = readPages(buf, i, blockSize);
1734
- break
1735
- case 4:
1736
- target.chars = readChars(buf, i, blockSize);
1737
- break
1738
- case 5:
1739
- target.kernings = readKernings(buf, i, blockSize);
1740
- break
1741
- }
1742
- return 5 + blockSize
1743
- }
1744
-
1745
- function readInfo(buf, i) {
1746
- var info = {};
1747
- info.size = buf.readInt16LE(i);
1748
-
1749
- var bitField = buf.readUInt8(i+2);
1750
- info.smooth = (bitField >> 7) & 1;
1751
- info.unicode = (bitField >> 6) & 1;
1752
- info.italic = (bitField >> 5) & 1;
1753
- info.bold = (bitField >> 4) & 1;
1754
-
1755
- //fixedHeight is only mentioned in binary spec
1756
- if ((bitField >> 3) & 1)
1757
- info.fixedHeight = 1;
1758
-
1759
- info.charset = buf.readUInt8(i+3) || '';
1760
- info.stretchH = buf.readUInt16LE(i+4);
1761
- info.aa = buf.readUInt8(i+6);
1762
- info.padding = [
1763
- buf.readInt8(i+7),
1764
- buf.readInt8(i+8),
1765
- buf.readInt8(i+9),
1766
- buf.readInt8(i+10)
1767
- ];
1768
- info.spacing = [
1769
- buf.readInt8(i+11),
1770
- buf.readInt8(i+12)
1771
- ];
1772
- info.outline = buf.readUInt8(i+13);
1773
- info.face = readStringNT(buf, i+14);
1774
- return info
1775
- }
1776
-
1777
- function readCommon(buf, i) {
1778
- var common = {};
1779
- common.lineHeight = buf.readUInt16LE(i);
1780
- common.base = buf.readUInt16LE(i+2);
1781
- common.scaleW = buf.readUInt16LE(i+4);
1782
- common.scaleH = buf.readUInt16LE(i+6);
1783
- common.pages = buf.readUInt16LE(i+8);
1784
- buf.readUInt8(i+10);
1785
- common.packed = 0;
1786
- common.alphaChnl = buf.readUInt8(i+11);
1787
- common.redChnl = buf.readUInt8(i+12);
1788
- common.greenChnl = buf.readUInt8(i+13);
1789
- common.blueChnl = buf.readUInt8(i+14);
1790
- return common
1791
- }
1792
-
1793
- function readPages(buf, i, size) {
1794
- var pages = [];
1795
- var text = readNameNT(buf, i);
1796
- var len = text.length+1;
1797
- var count = size / len;
1798
- for (var c=0; c<count; c++) {
1799
- pages[c] = buf.slice(i, i+text.length).toString('utf8');
1800
- i += len;
1801
- }
1802
- return pages
1803
- }
1804
-
1805
- function readChars(buf, i, blockSize) {
1806
- var chars = [];
1807
-
1808
- var count = blockSize / 20;
1809
- for (var c=0; c<count; c++) {
1810
- var char = {};
1811
- var off = c*20;
1812
- char.id = buf.readUInt32LE(i + 0 + off);
1813
- char.x = buf.readUInt16LE(i + 4 + off);
1814
- char.y = buf.readUInt16LE(i + 6 + off);
1815
- char.width = buf.readUInt16LE(i + 8 + off);
1816
- char.height = buf.readUInt16LE(i + 10 + off);
1817
- char.xoffset = buf.readInt16LE(i + 12 + off);
1818
- char.yoffset = buf.readInt16LE(i + 14 + off);
1819
- char.xadvance = buf.readInt16LE(i + 16 + off);
1820
- char.page = buf.readUInt8(i + 18 + off);
1821
- char.chnl = buf.readUInt8(i + 19 + off);
1822
- chars[c] = char;
1823
- }
1824
- return chars
1825
- }
1826
-
1827
- function readKernings(buf, i, blockSize) {
1828
- var kernings = [];
1829
- var count = blockSize / 10;
1830
- for (var c=0; c<count; c++) {
1831
- var kern = {};
1832
- var off = c*10;
1833
- kern.first = buf.readUInt32LE(i + 0 + off);
1834
- kern.second = buf.readUInt32LE(i + 4 + off);
1835
- kern.amount = buf.readInt16LE(i + 8 + off);
1836
- kernings[c] = kern;
1837
- }
1838
- return kernings
1839
- }
1840
-
1841
- function readNameNT(buf, offset) {
1842
- var pos=offset;
1843
- for (; pos<buf.length; pos++) {
1844
- if (buf[pos] === 0x00)
1845
- break
1846
- }
1847
- return buf.slice(offset, pos)
1848
- }
1849
-
1850
- function readStringNT(buf, offset) {
1851
- return readNameNT(buf, offset).toString('utf8')
1852
- }
1853
-
1854
- const __viteBrowserExternal = {};
1855
-
1856
- const __viteBrowserExternal$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1857
- __proto__: null,
1858
- default: __viteBrowserExternal
1859
- }, Symbol.toStringTag, { value: 'Module' }));
1860
-
1861
- const require$$0 = /*@__PURE__*/getAugmentedNamespace(__viteBrowserExternal$1);
1862
-
1863
- var Buffer$1 = require$$0.Buffer; // for use with browserify
1864
-
1865
- var bufferEqual = function (a, b) {
1866
- if (!Buffer$1.isBuffer(a)) return undefined;
1867
- if (!Buffer$1.isBuffer(b)) return undefined;
1868
- if (typeof a.equals === 'function') return a.equals(b);
1869
- if (a.length !== b.length) return false;
1870
-
1871
- for (var i = 0; i < a.length; i++) {
1872
- if (a[i] !== b[i]) return false;
1873
- }
1874
-
1875
- return true;
1876
- };
1877
-
1878
- var equal = bufferEqual;
1879
- var HEADER = Buffer.from([66, 77, 70, 3]);
1880
-
1881
- var isBinary = function(buf) {
1882
- if (typeof buf === 'string')
1883
- return buf.substring(0, 3) === 'BMF'
1884
- return buf.length > 4 && equal(buf.slice(0, 4), HEADER)
1885
- };
1886
-
1887
- var xhr = xhrExports;
1888
- var noop = function(){};
1889
- var parseASCII = parseBmfontAscii;
1890
- var parseXML = browser$1;
1891
- var readBinary = parseBmfontBinary;
1892
- var isBinaryFormat = isBinary;
1893
- var xtend$1 = immutable;
1894
-
1895
- var xml2 = (function hasXML2() {
1896
- return self.XMLHttpRequest && "withCredentials" in new XMLHttpRequest
1897
- })();
1898
-
1899
- var browser = function(opt, cb) {
1900
- cb = typeof cb === 'function' ? cb : noop;
1901
-
1902
- if (typeof opt === 'string')
1903
- opt = { uri: opt };
1904
- else if (!opt)
1905
- opt = {};
1906
-
1907
- var expectBinary = opt.binary;
1908
- if (expectBinary)
1909
- opt = getBinaryOpts(opt);
1910
-
1911
- xhr(opt, function(err, res, body) {
1912
- if (err)
1913
- return cb(err)
1914
- if (!/^2/.test(res.statusCode))
1915
- return cb(new Error('http status code: '+res.statusCode))
1916
- if (!body)
1917
- return cb(new Error('no body result'))
1918
-
1919
- var binary = false;
1920
-
1921
- //if the response type is an array buffer,
1922
- //we need to convert it into a regular Buffer object
1923
- if (isArrayBuffer(body)) {
1924
- var array = new Uint8Array(body);
1925
- body = Buffer.from(array, 'binary');
1926
- }
1927
-
1928
- //now check the string/Buffer response
1929
- //and see if it has a binary BMF header
1930
- if (isBinaryFormat(body)) {
1931
- binary = true;
1932
- //if we have a string, turn it into a Buffer
1933
- if (typeof body === 'string')
1934
- body = Buffer.from(body, 'binary');
1935
- }
1936
-
1937
- //we are not parsing a binary format, just ASCII/XML/etc
1938
- if (!binary) {
1939
- //might still be a buffer if responseType is 'arraybuffer'
1940
- if (Buffer.isBuffer(body))
1941
- body = body.toString(opt.encoding);
1942
- body = body.trim();
1943
- }
1944
-
1945
- var result;
1946
- try {
1947
- var type = res.headers['content-type'];
1948
- if (binary)
1949
- result = readBinary(body);
1950
- else if (/json/.test(type) || body.charAt(0) === '{')
1951
- result = JSON.parse(body);
1952
- else if (/xml/.test(type) || body.charAt(0) === '<')
1953
- result = parseXML(body);
1954
- else
1955
- result = parseASCII(body);
1956
- } catch (e) {
1957
- cb(new Error('error parsing font '+e.message));
1958
- cb = noop;
1959
- }
1960
- cb(null, result);
1961
- });
1962
- };
1963
-
1964
- function isArrayBuffer(arr) {
1965
- var str = Object.prototype.toString;
1966
- return str.call(arr) === '[object ArrayBuffer]'
1967
- }
1968
-
1969
- function getBinaryOpts(opt) {
1970
- //IE10+ and other modern browsers support array buffers
1971
- if (xml2)
1972
- return xtend$1(opt, { responseType: 'arraybuffer' })
1973
-
1974
- if (typeof self.XMLHttpRequest === 'undefined')
1975
- throw new Error('your browser does not support XHR loading')
1976
-
1977
- //IE9 and XML1 browsers could still use an override
1978
- var req = new self.XMLHttpRequest();
1979
- req.overrideMimeType('text/plain; charset=x-user-defined');
1980
- return xtend$1({
1981
- xhr: req
1982
- }, opt)
1983
- }
1984
-
1985
- const loadFont = /*@__PURE__*/getDefaultExportFromCjs(browser);
1986
-
1987
- var wordWrapper = {exports: {}};
1988
-
1989
- (function (module) {
1990
- var newline = /\n/;
1991
- var newlineChar = '\n';
1992
- var whitespace = /\s/;
1993
-
1994
- module.exports = function(text, opt) {
1995
- var lines = module.exports.lines(text, opt);
1996
- return lines.map(function(line) {
1997
- return text.substring(line.start, line.end)
1998
- }).join('\n')
1999
- };
2000
-
2001
- module.exports.lines = function wordwrap(text, opt) {
2002
- opt = opt||{};
2003
-
2004
- //zero width results in nothing visible
2005
- if (opt.width === 0 && opt.mode !== 'nowrap')
2006
- return []
2007
-
2008
- text = text||'';
2009
- var width = typeof opt.width === 'number' ? opt.width : Number.MAX_VALUE;
2010
- var start = Math.max(0, opt.start||0);
2011
- var end = typeof opt.end === 'number' ? opt.end : text.length;
2012
- var mode = opt.mode;
2013
-
2014
- var measure = opt.measure || monospace;
2015
- if (mode === 'pre')
2016
- return pre(measure, text, start, end, width)
2017
- else
2018
- return greedy(measure, text, start, end, width, mode)
2019
- };
2020
-
2021
- function idxOf(text, chr, start, end) {
2022
- var idx = text.indexOf(chr, start);
2023
- if (idx === -1 || idx > end)
2024
- return end
2025
- return idx
2026
- }
2027
-
2028
- function isWhitespace(chr) {
2029
- return whitespace.test(chr)
2030
- }
2031
-
2032
- function pre(measure, text, start, end, width) {
2033
- var lines = [];
2034
- var lineStart = start;
2035
- for (var i=start; i<end && i<text.length; i++) {
2036
- var chr = text.charAt(i);
2037
- var isNewline = newline.test(chr);
2038
-
2039
- //If we've reached a newline, then step down a line
2040
- //Or if we've reached the EOF
2041
- if (isNewline || i===end-1) {
2042
- var lineEnd = isNewline ? i : i+1;
2043
- var measured = measure(text, lineStart, lineEnd, width);
2044
- lines.push(measured);
2045
-
2046
- lineStart = i+1;
2047
- }
2048
- }
2049
- return lines
2050
- }
2051
-
2052
- function greedy(measure, text, start, end, width, mode) {
2053
- //A greedy word wrapper based on LibGDX algorithm
2054
- //https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/BitmapFontCache.java
2055
- var lines = [];
2056
-
2057
- var testWidth = width;
2058
- //if 'nowrap' is specified, we only wrap on newline chars
2059
- if (mode === 'nowrap')
2060
- testWidth = Number.MAX_VALUE;
2061
-
2062
- while (start < end && start < text.length) {
2063
- //get next newline position
2064
- var newLine = idxOf(text, newlineChar, start, end);
2065
-
2066
- //eat whitespace at start of line
2067
- while (start < newLine) {
2068
- if (!isWhitespace( text.charAt(start) ))
2069
- break
2070
- start++;
2071
- }
2072
-
2073
- //determine visible # of glyphs for the available width
2074
- var measured = measure(text, start, newLine, testWidth);
2075
-
2076
- var lineEnd = start + (measured.end-measured.start);
2077
- var nextStart = lineEnd + newlineChar.length;
2078
-
2079
- //if we had to cut the line before the next newline...
2080
- if (lineEnd < newLine) {
2081
- //find char to break on
2082
- while (lineEnd > start) {
2083
- if (isWhitespace(text.charAt(lineEnd)))
2084
- break
2085
- lineEnd--;
2086
- }
2087
- if (lineEnd === start) {
2088
- if (nextStart > start + newlineChar.length) nextStart--;
2089
- lineEnd = nextStart; // If no characters to break, show all.
2090
- } else {
2091
- nextStart = lineEnd;
2092
- //eat whitespace at end of line
2093
- while (lineEnd > start) {
2094
- if (!isWhitespace(text.charAt(lineEnd - newlineChar.length)))
2095
- break
2096
- lineEnd--;
2097
- }
2098
- }
2099
- }
2100
- if (lineEnd >= start) {
2101
- var result = measure(text, start, lineEnd, testWidth);
2102
- lines.push(result);
2103
- }
2104
- start = nextStart;
2105
- }
2106
- return lines
2107
- }
2108
-
2109
- //determines the visible number of glyphs within a given width
2110
- function monospace(text, start, end, width) {
2111
- var glyphs = Math.min(width, end-start);
2112
- return {
2113
- start: start,
2114
- end: start+glyphs
2115
- }
2116
- }
2117
- } (wordWrapper));
2118
-
2119
- var wordWrapperExports = wordWrapper.exports;
2120
-
2121
- var asNumber = function numtype(num, def) {
2122
- return typeof num === 'number'
2123
- ? num
2124
- : (typeof def === 'number' ? def : 0)
2125
- };
2126
-
2127
- var wordWrap = wordWrapperExports;
2128
- var xtend = immutable;
2129
- var number = asNumber;
2130
-
2131
- var X_HEIGHTS = ['x', 'e', 'a', 'o', 'n', 's', 'r', 'c', 'u', 'm', 'v', 'w', 'z'];
2132
- var M_WIDTHS = ['m', 'w'];
2133
- var CAP_HEIGHTS = ['H', 'I', 'N', 'E', 'F', 'K', 'L', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
2134
-
2135
-
2136
- var TAB_ID = '\t'.charCodeAt(0);
2137
- var SPACE_ID = ' '.charCodeAt(0);
2138
- var ALIGN_LEFT = 0,
2139
- ALIGN_CENTER = 1,
2140
- ALIGN_RIGHT = 2;
2141
-
2142
- var layoutBmfontText = function createLayout(opt) {
2143
- return new TextLayout(opt)
2144
- };
2145
-
2146
- function TextLayout(opt) {
2147
- this.glyphs = [];
2148
- this._measure = this.computeMetrics.bind(this);
2149
- this.update(opt);
2150
- }
2151
-
2152
- TextLayout.prototype.update = function(opt) {
2153
- opt = xtend({
2154
- measure: this._measure
2155
- }, opt);
2156
- this._opt = opt;
2157
- this._opt.tabSize = number(this._opt.tabSize, 4);
2158
-
2159
- if (!opt.font)
2160
- throw new Error('must provide a valid bitmap font')
2161
-
2162
- var glyphs = this.glyphs;
2163
- var text = opt.text||'';
2164
- var font = opt.font;
2165
- this._setupSpaceGlyphs(font);
2166
-
2167
- var lines = wordWrap.lines(text, opt);
2168
- var minWidth = opt.width || 0;
2169
-
2170
- //clear glyphs
2171
- glyphs.length = 0;
2172
-
2173
- //get max line width
2174
- var maxLineWidth = lines.reduce(function(prev, line) {
2175
- return Math.max(prev, line.width, minWidth)
2176
- }, 0);
2177
-
2178
- //the pen position
2179
- var x = 0;
2180
- var y = 0;
2181
- var lineHeight = number(opt.lineHeight, font.common.lineHeight);
2182
- var baseline = font.common.base;
2183
- var descender = lineHeight-baseline;
2184
- var letterSpacing = opt.letterSpacing || 0;
2185
- var height = lineHeight * lines.length - descender;
2186
- var align = getAlignType(this._opt.align);
2187
-
2188
- //draw text along baseline
2189
- y -= height;
2190
-
2191
- //the metrics for this text layout
2192
- this._width = maxLineWidth;
2193
- this._height = height;
2194
- this._descender = lineHeight - baseline;
2195
- this._baseline = baseline;
2196
- this._xHeight = getXHeight(font);
2197
- this._capHeight = getCapHeight(font);
2198
- this._lineHeight = lineHeight;
2199
- this._ascender = lineHeight - descender - this._xHeight;
2200
-
2201
- //layout each glyph
2202
- var self = this;
2203
- lines.forEach(function(line, lineIndex) {
2204
- var start = line.start;
2205
- var end = line.end;
2206
- var lineWidth = line.width;
2207
- var lastGlyph;
2208
-
2209
- //for each glyph in that line...
2210
- for (var i=start; i<end; i++) {
2211
- var id = text.charCodeAt(i);
2212
- var glyph = self.getGlyph(font, id);
2213
- if (glyph) {
2214
- if (lastGlyph)
2215
- x += getKerning(font, lastGlyph.id, glyph.id);
2216
-
2217
- var tx = x;
2218
- if (align === ALIGN_CENTER)
2219
- tx += (maxLineWidth-lineWidth)/2;
2220
- else if (align === ALIGN_RIGHT)
2221
- tx += (maxLineWidth-lineWidth);
2222
-
2223
- glyphs.push({
2224
- position: [tx, y],
2225
- data: glyph,
2226
- index: i,
2227
- line: lineIndex
2228
- });
2229
-
2230
- //move pen forward
2231
- x += glyph.xadvance + letterSpacing;
2232
- lastGlyph = glyph;
2233
- }
2234
- }
2235
-
2236
- //next line down
2237
- y += lineHeight;
2238
- x = 0;
2239
- });
2240
- this._linesTotal = lines.length;
2241
- };
2242
-
2243
- TextLayout.prototype._setupSpaceGlyphs = function(font) {
2244
- //These are fallbacks, when the font doesn't include
2245
- //' ' or '\t' glyphs
2246
- this._fallbackSpaceGlyph = null;
2247
- this._fallbackTabGlyph = null;
2248
-
2249
- if (!font.chars || font.chars.length === 0)
2250
- return
2251
-
2252
- //try to get space glyph
2253
- //then fall back to the 'm' or 'w' glyphs
2254
- //then fall back to the first glyph available
2255
- var space = getGlyphById(font, SPACE_ID)
2256
- || getMGlyph(font)
2257
- || font.chars[0];
2258
-
2259
- //and create a fallback for tab
2260
- var tabWidth = this._opt.tabSize * space.xadvance;
2261
- this._fallbackSpaceGlyph = space;
2262
- this._fallbackTabGlyph = xtend(space, {
2263
- x: 0, y: 0, xadvance: tabWidth, id: TAB_ID,
2264
- xoffset: 0, yoffset: 0, width: 0, height: 0
2265
- });
2266
- };
2267
-
2268
- TextLayout.prototype.getGlyph = function(font, id) {
2269
- var glyph = getGlyphById(font, id);
2270
- if (glyph)
2271
- return glyph
2272
- else if (id === TAB_ID)
2273
- return this._fallbackTabGlyph
2274
- else if (id === SPACE_ID)
2275
- return this._fallbackSpaceGlyph
2276
- return null
2277
- };
2278
-
2279
- TextLayout.prototype.computeMetrics = function(text, start, end, width) {
2280
- var letterSpacing = this._opt.letterSpacing || 0;
2281
- var font = this._opt.font;
2282
- var curPen = 0;
2283
- var curWidth = 0;
2284
- var count = 0;
2285
- var glyph;
2286
- var lastGlyph;
2287
-
2288
- if (!font.chars || font.chars.length === 0) {
2289
- return {
2290
- start: start,
2291
- end: start,
2292
- width: 0
2293
- }
2294
- }
2295
-
2296
- end = Math.min(text.length, end);
2297
- for (var i=start; i < end; i++) {
2298
- var id = text.charCodeAt(i);
2299
- var glyph = this.getGlyph(font, id);
2300
-
2301
- if (glyph) {
2302
- //move pen forward
2303
- glyph.xoffset;
2304
- var kern = lastGlyph ? getKerning(font, lastGlyph.id, glyph.id) : 0;
2305
- curPen += kern;
2306
-
2307
- var nextPen = curPen + glyph.xadvance + letterSpacing;
2308
- var nextWidth = curPen + glyph.width;
2309
-
2310
- //we've hit our limit; we can't move onto the next glyph
2311
- if (nextWidth >= width || nextPen >= width)
2312
- break
2313
-
2314
- //otherwise continue along our line
2315
- curPen = nextPen;
2316
- curWidth = nextWidth;
2317
- lastGlyph = glyph;
2318
- }
2319
- count++;
2320
- }
2321
-
2322
- //make sure rightmost edge lines up with rendered glyphs
2323
- if (lastGlyph)
2324
- curWidth += lastGlyph.xoffset;
2325
-
2326
- return {
2327
- start: start,
2328
- end: start + count,
2329
- width: curWidth
2330
- }
2331
- }
2332
-
2333
- //getters for the private vars
2334
- ;['width', 'height',
2335
- 'descender', 'ascender',
2336
- 'xHeight', 'baseline',
2337
- 'capHeight',
2338
- 'lineHeight' ].forEach(addGetter);
2339
-
2340
- function addGetter(name) {
2341
- Object.defineProperty(TextLayout.prototype, name, {
2342
- get: wrapper(name),
2343
- configurable: true
2344
- });
2345
- }
2346
-
2347
- //create lookups for private vars
2348
- function wrapper(name) {
2349
- return (new Function([
2350
- 'return function '+name+'() {',
2351
- ' return this._'+name,
2352
- '}'
2353
- ].join('\n')))()
2354
- }
2355
-
2356
- function getGlyphById(font, id) {
2357
- if (!font.chars || font.chars.length === 0)
2358
- return null
2359
-
2360
- var glyphIdx = findChar(font.chars, id);
2361
- if (glyphIdx >= 0)
2362
- return font.chars[glyphIdx]
2363
- return null
2364
- }
2365
-
2366
- function getXHeight(font) {
2367
- for (var i=0; i<X_HEIGHTS.length; i++) {
2368
- var id = X_HEIGHTS[i].charCodeAt(0);
2369
- var idx = findChar(font.chars, id);
2370
- if (idx >= 0)
2371
- return font.chars[idx].height
2372
- }
2373
- return 0
2374
- }
2375
-
2376
- function getMGlyph(font) {
2377
- for (var i=0; i<M_WIDTHS.length; i++) {
2378
- var id = M_WIDTHS[i].charCodeAt(0);
2379
- var idx = findChar(font.chars, id);
2380
- if (idx >= 0)
2381
- return font.chars[idx]
2382
- }
2383
- return 0
2384
- }
2385
-
2386
- function getCapHeight(font) {
2387
- for (var i=0; i<CAP_HEIGHTS.length; i++) {
2388
- var id = CAP_HEIGHTS[i].charCodeAt(0);
2389
- var idx = findChar(font.chars, id);
2390
- if (idx >= 0)
2391
- return font.chars[idx].height
2392
- }
2393
- return 0
2394
- }
2395
-
2396
- function getKerning(font, left, right) {
2397
- if (!font.kernings || font.kernings.length === 0)
2398
- return 0
2399
-
2400
- var table = font.kernings;
2401
- for (var i=0; i<table.length; i++) {
2402
- var kern = table[i];
2403
- if (kern.first === left && kern.second === right)
2404
- return kern.amount
2405
- }
2406
- return 0
2407
- }
2408
-
2409
- function getAlignType(align) {
2410
- if (align === 'center')
2411
- return ALIGN_CENTER
2412
- else if (align === 'right')
2413
- return ALIGN_RIGHT
2414
- return ALIGN_LEFT
2415
- }
2416
-
2417
- function findChar (array, value, start) {
2418
- start = start || 0;
2419
- for (var i = start; i < array.length; i++) {
2420
- if (array[i].id === value) {
2421
- return i
2422
- }
2423
- }
2424
- return -1
2425
- }
2426
-
2427
- var inherits_browser = {exports: {}};
2428
-
2429
- if (typeof Object.create === 'function') {
2430
- // implementation from standard node.js 'util' module
2431
- inherits_browser.exports = function inherits(ctor, superCtor) {
2432
- if (superCtor) {
2433
- ctor.super_ = superCtor;
2434
- ctor.prototype = Object.create(superCtor.prototype, {
2435
- constructor: {
2436
- value: ctor,
2437
- enumerable: false,
2438
- writable: true,
2439
- configurable: true
2440
- }
2441
- });
2442
- }
2443
- };
2444
- } else {
2445
- // old school shim for old browsers
2446
- inherits_browser.exports = function inherits(ctor, superCtor) {
2447
- if (superCtor) {
2448
- ctor.super_ = superCtor;
2449
- var TempCtor = function () {};
2450
- TempCtor.prototype = superCtor.prototype;
2451
- ctor.prototype = new TempCtor();
2452
- ctor.prototype.constructor = ctor;
2453
- }
2454
- };
2455
- }
2456
-
2457
- var inherits_browserExports = inherits_browser.exports;
2458
-
2459
- var dtype$1 = function(dtype) {
2460
- switch (dtype) {
2461
- case 'int8':
2462
- return Int8Array
2463
- case 'int16':
2464
- return Int16Array
2465
- case 'int32':
2466
- return Int32Array
2467
- case 'uint8':
2468
- return Uint8Array
2469
- case 'uint16':
2470
- return Uint16Array
2471
- case 'uint32':
2472
- return Uint32Array
2473
- case 'float32':
2474
- return Float32Array
2475
- case 'float64':
2476
- return Float64Array
2477
- case 'array':
2478
- return Array
2479
- case 'uint8_clamped':
2480
- return Uint8ClampedArray
2481
- }
2482
- };
2483
-
2484
- var str = Object.prototype.toString;
2485
-
2486
- var anArray_1 = anArray$1;
2487
-
2488
- function anArray$1(arr) {
2489
- return (
2490
- arr.BYTES_PER_ELEMENT
2491
- && str.call(arr.buffer) === '[object ArrayBuffer]'
2492
- || Array.isArray(arr)
2493
- )
2494
- }
2495
-
2496
- /*!
2497
- * Determine if an object is a Buffer
2498
- *
2499
- * @author Feross Aboukhadijeh <https://feross.org>
2500
- * @license MIT
2501
- */
2502
-
2503
- // The _isBuffer check is for Safari 5-7 support, because it's missing
2504
- // Object.prototype.constructor. Remove this eventually
2505
- var isBuffer_1 = function (obj) {
2506
- return obj != null && (isBuffer$1(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
2507
- };
2508
-
2509
- function isBuffer$1 (obj) {
2510
- return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
2511
- }
2512
-
2513
- // For Node v0.10 support. Remove this eventually.
2514
- function isSlowBuffer (obj) {
2515
- return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer$1(obj.slice(0, 0))
2516
- }
2517
-
2518
- var dtype = dtype$1;
2519
- var anArray = anArray_1;
2520
- var isBuffer = isBuffer_1;
2521
-
2522
- var CW = [0, 2, 3];
2523
- var CCW = [2, 1, 3];
2524
-
2525
- var quadIndices = function createQuadElements(array, opt) {
2526
- //if user didn't specify an output array
2527
- if (!array || !(anArray(array) || isBuffer(array))) {
2528
- opt = array || {};
2529
- array = null;
2530
- }
2531
-
2532
- if (typeof opt === 'number') //backwards-compatible
2533
- opt = { count: opt };
2534
- else
2535
- opt = opt || {};
2536
-
2537
- var type = typeof opt.type === 'string' ? opt.type : 'uint16';
2538
- var count = typeof opt.count === 'number' ? opt.count : 1;
2539
- var start = (opt.start || 0);
2540
-
2541
- var dir = opt.clockwise !== false ? CW : CCW,
2542
- a = dir[0],
2543
- b = dir[1],
2544
- c = dir[2];
2545
-
2546
- var numIndices = count * 6;
2547
-
2548
- var indices = array || new (dtype(type))(numIndices);
2549
- for (var i = 0, j = 0; i < numIndices; i += 6, j += 4) {
2550
- var x = i + start;
2551
- indices[x + 0] = j + 0;
2552
- indices[x + 1] = j + 1;
2553
- indices[x + 2] = j + 2;
2554
- indices[x + 3] = j + a;
2555
- indices[x + 4] = j + b;
2556
- indices[x + 5] = j + c;
2557
- }
2558
- return indices
2559
- };
2560
-
2561
- var vertices$1 = {};
2562
-
2563
- vertices$1.pages = function pages (glyphs) {
2564
- var pages = new Float32Array(glyphs.length * 4 * 1);
2565
- var i = 0;
2566
- glyphs.forEach(function (glyph) {
2567
- var id = glyph.data.page || 0;
2568
- pages[i++] = id;
2569
- pages[i++] = id;
2570
- pages[i++] = id;
2571
- pages[i++] = id;
2572
- });
2573
- return pages
2574
- };
2575
-
2576
- vertices$1.uvs = function uvs (glyphs, texWidth, texHeight, flipY) {
2577
- var uvs = new Float32Array(glyphs.length * 4 * 2);
2578
- var i = 0;
2579
- glyphs.forEach(function (glyph) {
2580
- var bitmap = glyph.data;
2581
- var bw = (bitmap.x + bitmap.width);
2582
- var bh = (bitmap.y + bitmap.height);
2583
-
2584
- // top left position
2585
- var u0 = bitmap.x / texWidth;
2586
- var v1 = bitmap.y / texHeight;
2587
- var u1 = bw / texWidth;
2588
- var v0 = bh / texHeight;
2589
-
2590
- if (flipY) {
2591
- v1 = (texHeight - bitmap.y) / texHeight;
2592
- v0 = (texHeight - bh) / texHeight;
2593
- }
2594
-
2595
- // BL
2596
- uvs[i++] = u0;
2597
- uvs[i++] = v1;
2598
- // TL
2599
- uvs[i++] = u0;
2600
- uvs[i++] = v0;
2601
- // TR
2602
- uvs[i++] = u1;
2603
- uvs[i++] = v0;
2604
- // BR
2605
- uvs[i++] = u1;
2606
- uvs[i++] = v1;
2607
- });
2608
- return uvs
2609
- };
2610
-
2611
- vertices$1.positions = function positions (glyphs) {
2612
- var positions = new Float32Array(glyphs.length * 4 * 2);
2613
- var i = 0;
2614
- glyphs.forEach(function (glyph) {
2615
- var bitmap = glyph.data;
2616
-
2617
- // bottom left position
2618
- var x = glyph.position[0] + bitmap.xoffset;
2619
- var y = glyph.position[1] + bitmap.yoffset;
2620
-
2621
- // quad size
2622
- var w = bitmap.width;
2623
- var h = bitmap.height;
2624
-
2625
- // BL
2626
- positions[i++] = x;
2627
- positions[i++] = y;
2628
- // TL
2629
- positions[i++] = x;
2630
- positions[i++] = y + h;
2631
- // TR
2632
- positions[i++] = x + w;
2633
- positions[i++] = y + h;
2634
- // BR
2635
- positions[i++] = x + w;
2636
- positions[i++] = y;
2637
- });
2638
- return positions
2639
- };
2640
-
2641
- var utils$1 = {};
2642
-
2643
- var itemSize = 2;
2644
- var box = { min: [0, 0], max: [0, 0] };
2645
-
2646
- function bounds (positions) {
2647
- var count = positions.length / itemSize;
2648
- box.min[0] = positions[0];
2649
- box.min[1] = positions[1];
2650
- box.max[0] = positions[0];
2651
- box.max[1] = positions[1];
2652
-
2653
- for (var i = 0; i < count; i++) {
2654
- var x = positions[i * itemSize + 0];
2655
- var y = positions[i * itemSize + 1];
2656
- box.min[0] = Math.min(x, box.min[0]);
2657
- box.min[1] = Math.min(y, box.min[1]);
2658
- box.max[0] = Math.max(x, box.max[0]);
2659
- box.max[1] = Math.max(y, box.max[1]);
2660
- }
2661
- }
2662
-
2663
- utils$1.computeBox = function (positions, output) {
2664
- bounds(positions);
2665
- output.min.set(box.min[0], box.min[1], 0);
2666
- output.max.set(box.max[0], box.max[1], 0);
2667
- };
2668
-
2669
- utils$1.computeSphere = function (positions, output) {
2670
- bounds(positions);
2671
- var minX = box.min[0];
2672
- var minY = box.min[1];
2673
- var maxX = box.max[0];
2674
- var maxY = box.max[1];
2675
- var width = maxX - minX;
2676
- var height = maxY - minY;
2677
- var length = Math.sqrt(width * width + height * height);
2678
- output.center.set(minX + width / 2, minY + height / 2, 0);
2679
- output.radius = length / 2;
2680
- };
2681
-
2682
- var createLayout = layoutBmfontText;
2683
- var inherits = inherits_browserExports;
2684
- var createIndices = quadIndices;
2685
-
2686
- var vertices = vertices$1;
2687
- var utils = utils$1;
2688
-
2689
- var Base = THREE.BufferGeometry;
2690
-
2691
- var threeBmfontText = function createTextGeometry (opt) {
2692
- return new TextGeometry(opt)
2693
- };
2694
-
2695
- function TextGeometry (opt) {
2696
- Base.call(this);
2697
-
2698
- if (typeof opt === 'string') {
2699
- opt = { text: opt };
2700
- }
2701
-
2702
- // use these as default values for any subsequent
2703
- // calls to update()
2704
- this._opt = Object.assign({}, opt);
2705
-
2706
- // also do an initial setup...
2707
- if (opt) this.update(opt);
2708
- }
2709
-
2710
- inherits(TextGeometry, Base);
2711
-
2712
- TextGeometry.prototype.update = function (opt) {
2713
- if (typeof opt === 'string') {
2714
- opt = { text: opt };
2715
- }
2716
-
2717
- // use constructor defaults
2718
- opt = Object.assign({}, this._opt, opt);
2719
-
2720
- if (!opt.font) {
2721
- throw new TypeError('must specify a { font } in options')
2722
- }
2723
-
2724
- this.layout = createLayout(opt);
2725
-
2726
- // get vec2 texcoords
2727
- var flipY = opt.flipY !== false;
2728
-
2729
- // the desired BMFont data
2730
- var font = opt.font;
2731
-
2732
- // determine texture size from font file
2733
- var texWidth = font.common.scaleW;
2734
- var texHeight = font.common.scaleH;
2735
-
2736
- // get visible glyphs
2737
- var glyphs = this.layout.glyphs.filter(function (glyph) {
2738
- var bitmap = glyph.data;
2739
- return bitmap.width * bitmap.height > 0
2740
- });
2741
-
2742
- // provide visible glyphs for convenience
2743
- this.visibleGlyphs = glyphs;
2744
-
2745
- // get common vertex data
2746
- var positions = vertices.positions(glyphs);
2747
- var uvs = vertices.uvs(glyphs, texWidth, texHeight, flipY);
2748
- var indices = createIndices([], {
2749
- clockwise: true,
2750
- type: 'uint16',
2751
- count: glyphs.length
2752
- });
2753
-
2754
- // update vertex data
2755
- this.setIndex(indices);
2756
- this.setAttribute('position', new THREE.BufferAttribute(positions, 2));
2757
- this.setAttribute('uv', new THREE.BufferAttribute(uvs, 2));
2758
-
2759
- // update multipage data
2760
- if (!opt.multipage && 'page' in this.attributes) {
2761
- // disable multipage rendering
2762
- this.removeAttribute('page');
2763
- } else if (opt.multipage) {
2764
- // enable multipage rendering
2765
- var pages = vertices.pages(glyphs);
2766
- this.setAttribute('page', new THREE.BufferAttribute(pages, 1));
2767
- }
2768
- };
2769
-
2770
- TextGeometry.prototype.computeBoundingSphere = function () {
2771
- if (this.boundingSphere === null) {
2772
- this.boundingSphere = new THREE.Sphere();
2773
- }
2774
-
2775
- var positions = this.attributes.position.array;
2776
- var itemSize = this.attributes.position.itemSize;
2777
- if (!positions || !itemSize || positions.length < 2) {
2778
- this.boundingSphere.radius = 0;
2779
- this.boundingSphere.center.set(0, 0, 0);
2780
- return
2781
- }
2782
- utils.computeSphere(positions, this.boundingSphere);
2783
- if (isNaN(this.boundingSphere.radius)) {
2784
- console.error('THREE.BufferGeometry.computeBoundingSphere(): ' +
2785
- 'Computed radius is NaN. The ' +
2786
- '"position" attribute is likely to have NaN values.');
2787
- }
2788
- };
2789
-
2790
- TextGeometry.prototype.computeBoundingBox = function () {
2791
- if (this.boundingBox === null) {
2792
- this.boundingBox = new THREE.Box3();
2793
- }
2794
-
2795
- var bbox = this.boundingBox;
2796
- var positions = this.attributes.position.array;
2797
- var itemSize = this.attributes.position.itemSize;
2798
- if (!positions || !itemSize || positions.length < 2) {
2799
- bbox.makeEmpty();
2800
- return
2801
- }
2802
- utils.computeBox(positions, bbox);
2803
- };
2804
-
2805
- const createGeometry = /*@__PURE__*/getDefaultExportFromCjs(threeBmfontText);
2806
-
2807
- var assign = requireObjectAssign();
2808
-
2809
- var msdf = function createMSDFShader (opt) {
2810
- opt = opt || {};
2811
- var opacity = typeof opt.opacity === 'number' ? opt.opacity : 1;
2812
- var alphaTest = typeof opt.alphaTest === 'number' ? opt.alphaTest : 0.0001;
2813
- var precision = opt.precision || 'highp';
2814
- var color = opt.color;
2815
- var map = opt.map;
2816
- var negate = typeof opt.negate === 'boolean' ? opt.negate : true;
2817
-
2818
- // remove to satisfy r73
2819
- delete opt.map;
2820
- delete opt.color;
2821
- delete opt.precision;
2822
- delete opt.opacity;
2823
- delete opt.negate;
2824
-
2825
- return assign({
2826
- uniforms: {
2827
- opacity: { type: 'f', value: opacity },
2828
- map: { type: 't', value: map || new THREE.Texture() },
2829
- color: { type: 'c', value: new THREE.Color(color) }
2830
- },
2831
- vertexShader: [
2832
- 'attribute vec2 uv;',
2833
- 'attribute vec4 position;',
2834
- 'uniform mat4 projectionMatrix;',
2835
- 'uniform mat4 modelViewMatrix;',
2836
- 'varying vec2 vUv;',
2837
- 'void main() {',
2838
- 'vUv = uv;',
2839
- 'gl_Position = projectionMatrix * modelViewMatrix * position;',
2840
- '}'
2841
- ].join('\n'),
2842
- fragmentShader: [
2843
- '#ifdef GL_OES_standard_derivatives',
2844
- '#extension GL_OES_standard_derivatives : enable',
2845
- '#endif',
2846
- 'precision ' + precision + ' float;',
2847
- 'uniform float opacity;',
2848
- 'uniform vec3 color;',
2849
- 'uniform sampler2D map;',
2850
- 'varying vec2 vUv;',
2851
-
2852
- 'float median(float r, float g, float b) {',
2853
- ' return max(min(r, g), min(max(r, g), b));',
2854
- '}',
2855
-
2856
- 'void main() {',
2857
- ' vec3 sample = ' + (negate ? '1.0 - ' : '') + 'texture2D(map, vUv).rgb;',
2858
- ' float sigDist = median(sample.r, sample.g, sample.b) - 0.5;',
2859
- ' float alpha = clamp(sigDist/fwidth(sigDist) + 0.5, 0.0, 1.0);',
2860
- ' gl_FragColor = vec4(color.xyz, alpha * opacity);',
2861
- alphaTest === 0
2862
- ? ''
2863
- : ' if (gl_FragColor.a < ' + alphaTest + ') discard;',
2864
- '}'
2865
- ].join('\n')
2866
- }, opt);
2867
- };
2868
-
2869
- const MSDFShader = /*@__PURE__*/getDefaultExportFromCjs(msdf);
2870
-
2871
- const vertexShader = `
2872
- varying vec2 vUv;
2873
- varying vec3 vPos;
2874
-
2875
- void main() {
2876
- vUv = uv;
2877
- vPos = position;
2878
-
2879
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.);
2880
- }
2881
- `;
2882
- const fragmentShader = `
2883
- varying vec2 vUv;
2884
- varying vec3 vPos;
2885
-
2886
- uniform sampler2D uTexture;
2887
- uniform float uTime;
2888
-
2889
- void main() {
2890
- float time = uTime * 0.5;
2891
- vec2 repeat = -vec2(12., 3.);
2892
- // To repeat the uvs we need to multiply them by a scalar
2893
- // and then get the fractional part of it so they from 0 to 1
2894
- // To move them continuously we have to add time
2895
- // to the x or y component, to change the direction
2896
- vec2 uv = fract(vUv * repeat - vec2(time, 0.)); // The sign of time change direction of movement
2897
-
2898
- // Fake shadow
2899
- float shadow = clamp(vPos.z / 5., 0., 1.);
2900
-
2901
- vec3 texture = texture2D(uTexture, uv).rgb;
2902
- // texture *= vec3(uv.x, uv.y, 1.); // To help visualize the repeated uvs
2903
-
2904
- gl_FragColor = vec4(texture * shadow, 1.);
2905
- }
2906
- `;
2907
-
2908
- class GL {
2909
- renderer;
2910
- camera;
2911
- scene;
2912
- controls;
2913
- clock;
2914
- rt;
2915
- rtCamera;
2916
- rtScene;
2917
- text;
2918
- mesh;
2919
- geometry;
2920
- material;
2921
- fontGeometry;
2922
- fontMaterial;
2923
- loader;
2924
- constructor() {
2925
- this.renderer = new WebGLRenderer({
2926
- alpha: true
2927
- });
2928
- this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
2929
- this.renderer.setSize(window.innerWidth, window.innerHeight);
2930
- this.renderer.setClearColor(0, 1);
2931
- document.body.appendChild(this.renderer.domElement);
2932
- this.camera = new PerspectiveCamera(
2933
- 45,
2934
- window.innerWidth / window.innerHeight,
2935
- 1,
2936
- 1e3
2937
- );
2938
- this.camera.position.z = 60;
2939
- this.scene = new Scene();
2940
- this.controls = new (OrbitControls(THREE$1))(
2941
- this.camera,
2942
- this.renderer.domElement
2943
- );
2944
- this.clock = new Clock();
2945
- }
2946
- init() {
2947
- loadFont("/fonts/orbitron/orbitron-black.fnt", (_, font) => {
2948
- this.fontGeometry = createGeometry({
2949
- font,
2950
- text: "ENDLESS"
2951
- });
2952
- this.loader = new TextureLoader();
2953
- this.loader.load("/fonts/orbitron/orbitron-black.png", (texture) => {
2954
- this.fontMaterial = new RawShaderMaterial(
2955
- MSDFShader({
2956
- map: texture,
2957
- side: DoubleSide,
2958
- transparent: true,
2959
- negate: false,
2960
- color: 16777215
2961
- })
2962
- );
2963
- this.createRenderTarget();
2964
- this.createMesh();
2965
- this.animate();
2966
- this.addEvents();
2967
- });
2968
- });
2969
- }
2970
- createRenderTarget() {
2971
- this.rt = new WebGLRenderTarget(window.innerWidth, window.innerHeight);
2972
- this.rtCamera = new PerspectiveCamera(45, 1, 0.1, 1e3);
2973
- this.rtCamera.position.z = 2.5;
2974
- this.rtScene = new Scene();
2975
- this.rtScene.background = new Color("#000000");
2976
- this.text = new Mesh(this.fontGeometry, this.fontMaterial);
2977
- this.text.position.set(-0.965, -0.525, 0);
2978
- this.text.rotation.set(Math.PI, 0, 0);
2979
- this.text.scale.set(8e-3, 0.04, 1);
2980
- this.rtScene.add(this.text);
2981
- }
2982
- createMesh() {
2983
- if (!this.rt) return;
2984
- this.geometry = new TorusKnotGeometry(9, 3, 768, 3, 4, 3);
2985
- this.material = new ShaderMaterial({
2986
- vertexShader,
2987
- fragmentShader,
2988
- uniforms: {
2989
- uTime: { value: 0 },
2990
- uTexture: { value: this.rt.texture }
2991
- }
2992
- });
2993
- this.mesh = new Mesh(this.geometry, this.material);
2994
- this.scene.add(this.mesh);
2995
- }
2996
- animate() {
2997
- requestAnimationFrame(this.animate.bind(this));
2998
- this.render();
2999
- }
3000
- render() {
3001
- if (!this.material || !this.rt || !this.rtScene || !this.rtCamera) return;
3002
- this.controls.update();
3003
- this.material.uniforms.uTime.value = this.clock.getElapsedTime();
3004
- this.renderer.setRenderTarget(this.rt);
3005
- this.renderer.render(this.rtScene, this.rtCamera);
3006
- this.renderer.setRenderTarget(null);
3007
- this.renderer.render(this.scene, this.camera);
3008
- }
3009
- addEvents() {
3010
- window.addEventListener("resize", this.resize.bind(this));
3011
- }
3012
- resize() {
3013
- const width = window.innerWidth;
3014
- const height = window.innerHeight;
3015
- this.camera.aspect = width / height;
3016
- this.camera.updateProjectionMatrix();
3017
- this.renderer.setSize(width, height);
3018
- }
3019
- }
3020
-
3021
- export { GL };