-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbmfont.js
1151 lines (983 loc) · 30.6 KB
/
bmfont.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
var createLayout = require('layout-bmfont-text')
var inherits = require('inherits')
var createIndices = require('quad-indices')
var buffer = require('three-buffer-vertex-data')
var assign = require('object-assign')
var vertices = require('./lib/vertices')
var utils = require('./lib/utils')
var Base = THREE.BufferGeometry
window.createTextGeometry = function createTextGeometry (opt) {
// module.exports = function createTextGeometry (opt) {
return new TextGeometry(opt)
}
function TextGeometry (opt) {
Base.call(this)
if (typeof opt === 'string') {
opt = { text: opt }
}
// use these as default values for any subsequent
// calls to update()
this._opt = assign({}, opt)
// also do an initial setup...
if (opt) this.update(opt)
}
inherits(TextGeometry, Base)
TextGeometry.prototype.update = function (opt) {
if (typeof opt === 'string') {
opt = { text: opt }
}
// use constructor defaults
opt = assign({}, this._opt, opt)
if (!opt.font) {
throw new TypeError('must specify a { font } in options')
}
this.layout = createLayout(opt)
// get vec2 texcoords
var flipY = opt.flipY !== false
// the desired BMFont data
var font = opt.font
// determine texture size from font file
var texWidth = font.common.scaleW
var texHeight = font.common.scaleH
// get visible glyphs
var glyphs = this.layout.glyphs.filter(function (glyph) {
var bitmap = glyph.data
return bitmap.width * bitmap.height > 0
})
// provide visible glyphs for convenience
this.visibleGlyphs = glyphs
// get common vertex data
var positions = vertices.positions(glyphs)
var uvs = vertices.uvs(glyphs, texWidth, texHeight, flipY)
var indices = createIndices({
clockwise: true,
type: 'uint16',
count: glyphs.length
})
// update vertex data
buffer.index(this, indices, 1, 'uint16')
buffer.attr(this, 'position', positions, 2)
buffer.attr(this, 'uv', uvs, 2)
// update multipage data
if (!opt.multipage && 'page' in this.attributes) {
// disable multipage rendering
this.removeAttribute('page')
} else if (opt.multipage) {
var pages = vertices.pages(glyphs)
// enable multipage rendering
buffer.attr(this, 'page', pages, 1)
}
}
TextGeometry.prototype.computeBoundingSphere = function () {
if (this.boundingSphere === null) {
this.boundingSphere = new THREE.Sphere()
}
var positions = this.attributes.position.array
var itemSize = this.attributes.position.itemSize
if (!positions || !itemSize || positions.length < 2) {
this.boundingSphere.radius = 0
this.boundingSphere.center.set(0, 0, 0)
return
}
utils.computeSphere(positions, this.boundingSphere)
if (isNaN(this.boundingSphere.radius)) {
console.error('THREE.BufferGeometry.computeBoundingSphere(): ' +
'Computed radius is NaN. The ' +
'"position" attribute is likely to have NaN values.')
}
}
TextGeometry.prototype.computeBoundingBox = function () {
if (this.boundingBox === null) {
this.boundingBox = new THREE.Box3()
}
var bbox = this.boundingBox
var positions = this.attributes.position.array
var itemSize = this.attributes.position.itemSize
if (!positions || !itemSize || positions.length < 2) {
bbox.makeEmpty()
return
}
utils.computeBox(positions, bbox)
}
},{"./lib/utils":2,"./lib/vertices":3,"inherits":8,"layout-bmfont-text":10,"object-assign":11,"quad-indices":12,"three-buffer-vertex-data":13}],2:[function(require,module,exports){
var itemSize = 2
var box = { min: [0, 0], max: [0, 0] }
function bounds (positions) {
var count = positions.length / itemSize
box.min[0] = positions[0]
box.min[1] = positions[1]
box.max[0] = positions[0]
box.max[1] = positions[1]
for (var i = 0; i < count; i++) {
var x = positions[i * itemSize + 0]
var y = positions[i * itemSize + 1]
box.min[0] = Math.min(x, box.min[0])
box.min[1] = Math.min(y, box.min[1])
box.max[0] = Math.max(x, box.max[0])
box.max[1] = Math.max(y, box.max[1])
}
}
module.exports.computeBox = function (positions, output) {
bounds(positions)
output.min.set(box.min[0], box.min[1], 0)
output.max.set(box.max[0], box.max[1], 0)
}
module.exports.computeSphere = function (positions, output) {
bounds(positions)
var minX = box.min[0]
var minY = box.min[1]
var maxX = box.max[0]
var maxY = box.max[1]
var width = maxX - minX
var height = maxY - minY
var length = Math.sqrt(width * width + height * height)
output.center.set(minX + width / 2, minY + height / 2, 0)
output.radius = length / 2
}
},{}],3:[function(require,module,exports){
module.exports.pages = function pages (glyphs) {
var pages = new Float32Array(glyphs.length * 4 * 1)
var i = 0
glyphs.forEach(function (glyph) {
var id = glyph.data.page || 0
pages[i++] = id
pages[i++] = id
pages[i++] = id
pages[i++] = id
})
return pages
}
module.exports.uvs = function uvs (glyphs, texWidth, texHeight, flipY) {
var uvs = new Float32Array(glyphs.length * 4 * 2)
var i = 0
glyphs.forEach(function (glyph) {
var bitmap = glyph.data
var bw = (bitmap.x + bitmap.width)
var bh = (bitmap.y + bitmap.height)
// top left position
var u0 = bitmap.x / texWidth
var v1 = bitmap.y / texHeight
var u1 = bw / texWidth
var v0 = bh / texHeight
if (flipY) {
v1 = (texHeight - bitmap.y) / texHeight
v0 = (texHeight - bh) / texHeight
}
// BL
uvs[i++] = u0
uvs[i++] = v1
// TL
uvs[i++] = u0
uvs[i++] = v0
// TR
uvs[i++] = u1
uvs[i++] = v0
// BR
uvs[i++] = u1
uvs[i++] = v1
})
return uvs
}
module.exports.positions = function positions (glyphs) {
var positions = new Float32Array(glyphs.length * 4 * 2)
var i = 0
glyphs.forEach(function (glyph) {
var bitmap = glyph.data
// bottom left position
var x = glyph.position[0] + bitmap.xoffset
var y = glyph.position[1] + bitmap.yoffset
// quad size
var w = bitmap.width
var h = bitmap.height
// BL
positions[i++] = x
positions[i++] = y
// TL
positions[i++] = x
positions[i++] = y + h
// TR
positions[i++] = x + w
positions[i++] = y + h
// BR
positions[i++] = x + w
positions[i++] = y
})
return positions
}
},{}],4:[function(require,module,exports){
var str = Object.prototype.toString
module.exports = anArray
function anArray(arr) {
return (
arr.BYTES_PER_ELEMENT
&& str.call(arr.buffer) === '[object ArrayBuffer]'
|| Array.isArray(arr)
)
}
},{}],5:[function(require,module,exports){
module.exports = function numtype(num, def) {
return typeof num === 'number'
? num
: (typeof def === 'number' ? def : 0)
}
},{}],6:[function(require,module,exports){
module.exports = function(dtype) {
switch (dtype) {
case 'int8':
return Int8Array
case 'int16':
return Int16Array
case 'int32':
return Int32Array
case 'uint8':
return Uint8Array
case 'uint16':
return Uint16Array
case 'uint32':
return Uint32Array
case 'float32':
return Float32Array
case 'float64':
return Float64Array
case 'array':
return Array
case 'uint8_clamped':
return Uint8ClampedArray
}
}
},{}],7:[function(require,module,exports){
/*eslint new-cap:0*/
var dtype = require('dtype')
module.exports = flattenVertexData
function flattenVertexData (data, output, offset) {
if (!data) throw new TypeError('must specify data as first parameter')
offset = +(offset || 0) | 0
if (Array.isArray(data) && (data[0] && typeof data[0][0] === 'number')) {
var dim = data[0].length
var length = data.length * dim
var i, j, k, l
// no output specified, create a new typed array
if (!output || typeof output === 'string') {
output = new (dtype(output || 'float32'))(length + offset)
}
var dstLength = output.length - offset
if (length !== dstLength) {
throw new Error('source length ' + length + ' (' + dim + 'x' + data.length + ')' +
' does not match destination length ' + dstLength)
}
for (i = 0, k = offset; i < data.length; i++) {
for (j = 0; j < dim; j++) {
output[k++] = data[i][j] === null ? NaN : data[i][j]
}
}
} else {
if (!output || typeof output === 'string') {
// no output, create a new one
var Ctor = dtype(output || 'float32')
// handle arrays separately due to possible nulls
if (Array.isArray(data) || output === 'array') {
output = new Ctor(data.length + offset)
for (i = 0, k = offset, l = output.length; k < l; k++, i++) {
output[k] = data[i] === null ? NaN : data[i]
}
} else {
if (offset === 0) {
output = new Ctor(data)
} else {
output = new Ctor(data.length + offset)
output.set(data, offset)
}
}
} else {
// store output in existing array
output.set(data, offset)
}
}
return output
}
},{"dtype":6}],8:[function(require,module,exports){
if (typeof Object.create === 'function') {
// implementation from standard node.js 'util' module
module.exports = function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
})
}
};
} else {
// old school shim for old browsers
module.exports = function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor
var TempCtor = function () {}
TempCtor.prototype = superCtor.prototype
ctor.prototype = new TempCtor()
ctor.prototype.constructor = ctor
}
}
}
},{}],9:[function(require,module,exports){
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
// The _isBuffer check is for Safari 5-7 support, because it's missing
// Object.prototype.constructor. Remove this eventually
module.exports = function (obj) {
return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
}
function isBuffer (obj) {
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
}
// For Node v0.10 support. Remove this eventually.
function isSlowBuffer (obj) {
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
}
},{}],10:[function(require,module,exports){
var wordWrap = require('word-wrapper')
var xtend = require('xtend')
var number = require('as-number')
var X_HEIGHTS = ['x', 'e', 'a', 'o', 'n', 's', 'r', 'c', 'u', 'm', 'v', 'w', 'z']
var M_WIDTHS = ['m', 'w']
var CAP_HEIGHTS = ['H', 'I', 'N', 'E', 'F', 'K', 'L', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
var TAB_ID = '\t'.charCodeAt(0)
var SPACE_ID = ' '.charCodeAt(0)
var ALIGN_LEFT = 0,
ALIGN_CENTER = 1,
ALIGN_RIGHT = 2
module.exports = function createLayout(opt) {
return new TextLayout(opt)
}
function TextLayout(opt) {
this.glyphs = []
this._measure = this.computeMetrics.bind(this)
this.update(opt)
}
TextLayout.prototype.update = function(opt) {
opt = xtend({
measure: this._measure
}, opt)
this._opt = opt
this._opt.tabSize = number(this._opt.tabSize, 4)
if (!opt.font)
throw new Error('must provide a valid bitmap font')
var glyphs = this.glyphs
var text = opt.text||''
var font = opt.font
this._setupSpaceGlyphs(font)
var lines = wordWrap.lines(text, opt)
var minWidth = opt.width || 0
//clear glyphs
glyphs.length = 0
//get max line width
var maxLineWidth = lines.reduce(function(prev, line) {
return Math.max(prev, line.width, minWidth)
}, 0)
//the pen position
var x = 0
var y = 0
var lineHeight = number(opt.lineHeight, font.common.lineHeight)
var baseline = font.common.base
var descender = lineHeight-baseline
var letterSpacing = opt.letterSpacing || 0
var height = lineHeight * lines.length - descender
var align = getAlignType(this._opt.align)
//draw text along baseline
y -= height
//the metrics for this text layout
this._width = maxLineWidth
this._height = height
this._descender = lineHeight - baseline
this._baseline = baseline
this._xHeight = getXHeight(font)
this._capHeight = getCapHeight(font)
this._lineHeight = lineHeight
this._ascender = lineHeight - descender - this._xHeight
//layout each glyph
var self = this
lines.forEach(function(line, lineIndex) {
var start = line.start
var end = line.end
var lineWidth = line.width
var lastGlyph
//for each glyph in that line...
for (var i=start; i<end; i++) {
var id = text.charCodeAt(i)
var glyph = self.getGlyph(font, id)
if (glyph) {
if (lastGlyph)
x += getKerning(font, lastGlyph.id, glyph.id)
var tx = x
if (align === ALIGN_CENTER)
tx += (maxLineWidth-lineWidth)/2
else if (align === ALIGN_RIGHT)
tx += (maxLineWidth-lineWidth)
glyphs.push({
position: [tx, y],
data: glyph,
index: i,
line: lineIndex,
x
})
//move pen forward
x += glyph.xadvance + letterSpacing
lastGlyph = glyph
}
}
//next line down
y += lineHeight
x = 0
})
this._linesTotal = lines.length;
}
TextLayout.prototype._setupSpaceGlyphs = function(font) {
//These are fallbacks, when the font doesn't include
//' ' or '\t' glyphs
this._fallbackSpaceGlyph = null
this._fallbackTabGlyph = null
if (!font.chars || font.chars.length === 0)
return
//try to get space glyph
//then fall back to the 'm' or 'w' glyphs
//then fall back to the first glyph available
var space = getGlyphById(font, SPACE_ID)
|| getMGlyph(font)
|| font.chars[0]
//and create a fallback for tab
var tabWidth = this._opt.tabSize * space.xadvance
this._fallbackSpaceGlyph = space
this._fallbackTabGlyph = xtend(space, {
x: 0, y: 0, xadvance: tabWidth, id: TAB_ID,
xoffset: 0, yoffset: 0, width: 0, height: 0
})
}
TextLayout.prototype.getGlyph = function(font, id) {
var glyph = getGlyphById(font, id)
if (glyph)
return glyph
else if (id === TAB_ID)
return this._fallbackTabGlyph
else if (id === SPACE_ID)
return this._fallbackSpaceGlyph
return null
}
TextLayout.prototype.computeMetrics = function(text, start, end, width) {
var letterSpacing = this._opt.letterSpacing || 0
var font = this._opt.font
var curPen = 0
var curWidth = 0
var count = 0
var glyph
var lastGlyph
if (!font.chars || font.chars.length === 0) {
return {
start: start,
end: start,
width: 0
}
}
end = Math.min(text.length, end)
for (var i=start; i < end; i++) {
var id = text.charCodeAt(i)
var glyph = this.getGlyph(font, id)
if (glyph) {
//move pen forward
var xoff = glyph.xoffset
var kern = lastGlyph ? getKerning(font, lastGlyph.id, glyph.id) : 0
curPen += kern
var nextPen = curPen + glyph.xadvance + letterSpacing
var nextWidth = curPen + glyph.width
//we've hit our limit; we can't move onto the next glyph
if (nextWidth >= width || nextPen >= width)
break
//otherwise continue along our line
curPen = nextPen
curWidth = nextWidth
lastGlyph = glyph
}
count++
}
//make sure rightmost edge lines up with rendered glyphs
if (lastGlyph)
curWidth += lastGlyph.xoffset
return {
start: start,
end: start + count,
width: curWidth
}
}
//getters for the private vars
;['width', 'height',
'descender', 'ascender',
'xHeight', 'baseline',
'capHeight',
'lineHeight' ].forEach(addGetter)
function addGetter(name) {
Object.defineProperty(TextLayout.prototype, name, {
get: wrapper(name),
configurable: true
})
}
//create lookups for private vars
function wrapper(name) {
return (new Function([
'return function '+name+'() {',
' return this._'+name,
'}'
].join('\n')))()
}
function getGlyphById(font, id) {
if (!font.chars || font.chars.length === 0)
return null
var glyphIdx = findChar(font.chars, id)
if (glyphIdx >= 0)
return font.chars[glyphIdx]
return null
}
function getXHeight(font) {
for (var i=0; i<X_HEIGHTS.length; i++) {
var id = X_HEIGHTS[i].charCodeAt(0)
var idx = findChar(font.chars, id)
if (idx >= 0)
return font.chars[idx].height
}
return 0
}
function getMGlyph(font) {
for (var i=0; i<M_WIDTHS.length; i++) {
var id = M_WIDTHS[i].charCodeAt(0)
var idx = findChar(font.chars, id)
if (idx >= 0)
return font.chars[idx]
}
return 0
}
function getCapHeight(font) {
for (var i=0; i<CAP_HEIGHTS.length; i++) {
var id = CAP_HEIGHTS[i].charCodeAt(0)
var idx = findChar(font.chars, id)
if (idx >= 0)
return font.chars[idx].height
}
return 0
}
function getKerning(font, left, right) {
if (!font.kernings || font.kernings.length === 0)
return 0
var table = font.kernings
for (var i=0; i<table.length; i++) {
var kern = table[i]
if (kern.first === left && kern.second === right)
return kern.amount
}
return 0
}
function getAlignType(align) {
if (align === 'center')
return ALIGN_CENTER
else if (align === 'right')
return ALIGN_RIGHT
return ALIGN_LEFT
}
function findChar (array, value, start) {
start = start || 0
for (var i = start; i < array.length; i++) {
if (array[i].id === value) {
return i
}
}
return -1
}
},{"as-number":5,"word-wrapper":14,"xtend":15}],11:[function(require,module,exports){
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
'use strict';
/* eslint-disable no-unused-vars */
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
function toObject(val) {
if (val === null || val === undefined) {
throw new TypeError('Object.assign cannot be called with null or undefined');
}
return Object(val);
}
function shouldUseNative() {
try {
if (!Object.assign) {
return false;
}
// Detect buggy property enumeration order in older V8 versions.
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
test1[5] = 'de';
if (Object.getOwnPropertyNames(test1)[0] === '5') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test2 = {};
for (var i = 0; i < 10; i++) {
test2['_' + String.fromCharCode(i)] = i;
}
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
return test2[n];
});
if (order2.join('') !== '0123456789') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test3 = {};
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
test3[letter] = letter;
});
if (Object.keys(Object.assign({}, test3)).join('') !==
'abcdefghijklmnopqrst') {
return false;
}
return true;
} catch (err) {
// We don't expect any of the above to throw, but better to be safe.
return false;
}
}
module.exports = shouldUseNative() ? Object.assign : function (target, source) {
var from;
var to = toObject(target);
var symbols;
for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}
if (getOwnPropertySymbols) {
symbols = getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
to[symbols[i]] = from[symbols[i]];
}
}
}
}
return to;
};
},{}],12:[function(require,module,exports){
var dtype = require('dtype')
var anArray = require('an-array')
var isBuffer = require('is-buffer')
var CW = [0, 2, 3]
var CCW = [2, 1, 3]
module.exports = function createQuadElements(array, opt) {
//if user didn't specify an output array
if (!array || !(anArray(array) || isBuffer(array))) {
opt = array || {}
array = null
}
if (typeof opt === 'number') //backwards-compatible
opt = { count: opt }
else
opt = opt || {}
var type = typeof opt.type === 'string' ? opt.type : 'uint16'
var count = typeof opt.count === 'number' ? opt.count : 1
var start = (opt.start || 0)
var dir = opt.clockwise !== false ? CW : CCW,
a = dir[0],
b = dir[1],
c = dir[2]
var numIndices = count * 6
var indices = array || new (dtype(type))(numIndices)
for (var i = 0, j = 0; i < numIndices; i += 6, j += 4) {
var x = i + start
indices[x + 0] = j + 0
indices[x + 1] = j + 1
indices[x + 2] = j + 2
indices[x + 3] = j + a
indices[x + 4] = j + b
indices[x + 5] = j + c
}
return indices
}
},{"an-array":4,"dtype":6,"is-buffer":9}],13:[function(require,module,exports){
var flatten = require('flatten-vertex-data')
var warned = false;
module.exports.attr = setAttribute
module.exports.index = setIndex
function setIndex (geometry, data, itemSize, dtype) {
if (typeof itemSize !== 'number') itemSize = 1
if (typeof dtype !== 'string') dtype = 'uint16'
var isR69 = !geometry.index && typeof geometry.setIndex !== 'function'
var attrib = isR69 ? geometry.getAttribute('index') : geometry.index
var newAttrib = updateAttribute(attrib, data, itemSize, dtype)
if (newAttrib) {
if (isR69) geometry.addAttribute('index', newAttrib)
else geometry.index = newAttrib
}
}
function setAttribute (geometry, key, data, itemSize, dtype) {
if (typeof itemSize !== 'number') itemSize = 3
if (typeof dtype !== 'string') dtype = 'float32'
if (Array.isArray(data) &&
Array.isArray(data[0]) &&
data[0].length !== itemSize) {
throw new Error('Nested vertex array has unexpected size; expected ' +
itemSize + ' but found ' + data[0].length)
}
var attrib = geometry.getAttribute(key)
var newAttrib = updateAttribute(attrib, data, itemSize, dtype)
if (newAttrib) {
geometry.addAttribute(key, newAttrib)
}
}
function updateAttribute (attrib, data, itemSize, dtype) {
data = data || []
if (!attrib || rebuildAttribute(attrib, data, itemSize)) {
// create a new array with desired type
data = flatten(data, dtype)
var needsNewBuffer = attrib && typeof attrib.setArray !== 'function'
if (!attrib || needsNewBuffer) {
// We are on an old version of ThreeJS which can't
// support growing / shrinking buffers, so we need
// to build a new buffer
if (needsNewBuffer && !warned) {
warned = true
console.warn([
'A WebGL buffer is being updated with a new size or itemSize, ',
'however this version of ThreeJS only supports fixed-size buffers.',
'\nThe old buffer may still be kept in memory.\n',
'To avoid memory leaks, it is recommended that you dispose ',
'your geometries and create new ones, or update to ThreeJS r82 or newer.\n',
'See here for discussion:\n',
'https://github.com/mrdoob/three.js/pull/9631'
].join(''))
}
// Build a new attribute
attrib = new THREE.BufferAttribute(data, itemSize);
}
attrib.itemSize = itemSize
attrib.needsUpdate = true
// New versions of ThreeJS suggest using setArray
// to change the data. It will use bufferData internally,
// so you can change the array size without any issues
if (typeof attrib.setArray === 'function') {
attrib.setArray(data)
}
return attrib
} else {
// copy data into the existing array
flatten(data, attrib.array)
attrib.needsUpdate = true
return null
}
}
// Test whether the attribute needs to be re-created,
// returns false if we can re-use it as-is.
function rebuildAttribute (attrib, data, itemSize) {
if (attrib.itemSize !== itemSize) return true
if (!attrib.array) return true
var attribLength = attrib.array.length
if (Array.isArray(data) && Array.isArray(data[0])) {
// [ [ x, y, z ] ]
return attribLength !== data.length * itemSize
} else {
// [ x, y, z ]
return attribLength !== data.length
}
return false
}
},{"flatten-vertex-data":7}],14:[function(require,module,exports){
var newline = /\n/
var newlineChar = '\n'
var whitespace = /\s/
module.exports = function(text, opt) {
var lines = module.exports.lines(text, opt)
return lines.map(function(line) {
return text.substring(line.start, line.end)
}).join('\n')
}
module.exports.lines = function wordwrap(text, opt) {
opt = opt||{}
//zero width results in nothing visible
if (opt.width === 0 && opt.mode !== 'nowrap')
return []
text = text||''
var width = typeof opt.width === 'number' ? opt.width : Number.MAX_VALUE
var start = Math.max(0, opt.start||0)
var end = typeof opt.end === 'number' ? opt.end : text.length
var mode = opt.mode
var measure = opt.measure || monospace
if (mode === 'pre')
return pre(measure, text, start, end, width)
else
return greedy(measure, text, start, end, width, mode)
}
function idxOf(text, chr, start, end) {
var idx = text.indexOf(chr, start)
if (idx === -1 || idx > end)
return end
return idx
}
function isWhitespace(chr) {
return whitespace.test(chr)
}
function pre(measure, text, start, end, width) {
var lines = []
var lineStart = start
for (var i=start; i<end && i<text.length; i++) {
var chr = text.charAt(i)
var isNewline = newline.test(chr)
//If we've reached a newline, then step down a line
//Or if we've reached the EOF
if (isNewline || i===end-1) {
var lineEnd = isNewline ? i : i+1
var measured = measure(text, lineStart, lineEnd, width)
lines.push(measured)
lineStart = i+1
}
}
return lines