@tarsis/toolkit 0.3.1 → 0.4.0

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