@woosh/meep-engine 2.100.0 → 2.100.2

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.
Files changed (58) hide show
  1. package/build/meep.cjs +574 -19
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +574 -19
  4. package/package.json +1 -1
  5. package/src/core/color/Color.d.ts.map +1 -1
  6. package/src/core/color/Color.js +39 -8
  7. package/src/core/color/oklab/Okhsv.spec.d.ts +2 -0
  8. package/src/core/color/oklab/Okhsv.spec.d.ts.map +1 -0
  9. package/src/core/color/oklab/Okhsv.spec.js +17 -0
  10. package/src/core/color/oklab/XYZ.spec.js +2 -2
  11. package/src/core/color/oklab/compute_max_saturation.d.ts +11 -0
  12. package/src/core/color/oklab/compute_max_saturation.d.ts.map +1 -0
  13. package/src/core/color/oklab/compute_max_saturation.js +84 -0
  14. package/src/core/color/oklab/find_cusp.d.ts +10 -0
  15. package/src/core/color/oklab/find_cusp.d.ts.map +1 -0
  16. package/src/core/color/oklab/find_cusp.js +27 -0
  17. package/src/core/color/oklab/find_gamut_intersection.d.ts +15 -0
  18. package/src/core/color/oklab/find_gamut_intersection.d.ts.map +1 -0
  19. package/src/core/color/oklab/find_gamut_intersection.js +101 -0
  20. package/src/core/color/oklab/linear_srgb_to_okhsv.d.ts +9 -0
  21. package/src/core/color/oklab/linear_srgb_to_okhsv.d.ts.map +1 -0
  22. package/src/core/color/oklab/linear_srgb_to_okhsv.js +74 -0
  23. package/src/core/color/oklab/linear_srgb_to_oklab.d.ts +9 -0
  24. package/src/core/color/oklab/linear_srgb_to_oklab.d.ts.map +1 -0
  25. package/src/core/color/oklab/linear_srgb_to_oklab.js +20 -0
  26. package/src/core/color/oklab/okhsv_to_linear_srgb.d.ts +9 -0
  27. package/src/core/color/oklab/okhsv_to_linear_srgb.d.ts.map +1 -0
  28. package/src/core/color/oklab/okhsv_to_linear_srgb.js +59 -0
  29. package/src/core/color/oklab/oklab_to_linear_srgb.d.ts +10 -0
  30. package/src/core/color/oklab/oklab_to_linear_srgb.d.ts.map +1 -0
  31. package/src/core/color/oklab/oklab_to_linear_srgb.js +21 -0
  32. package/src/core/color/oklab/oklab_to_xyz.d.ts +5 -2
  33. package/src/core/color/oklab/oklab_to_xyz.d.ts.map +1 -1
  34. package/src/core/color/oklab/oklab_to_xyz.js +5 -5
  35. package/src/core/color/oklab/oklab_to_xyz.spec.js +4 -4
  36. package/src/core/color/oklab/toe.d.ts +13 -0
  37. package/src/core/color/oklab/toe.d.ts.map +1 -0
  38. package/src/core/color/oklab/toe.js +22 -0
  39. package/src/core/color/oklab/xyz_to_oklab.d.ts +5 -2
  40. package/src/core/color/oklab/xyz_to_oklab.d.ts.map +1 -1
  41. package/src/core/color/oklab/xyz_to_oklab.js +5 -5
  42. package/src/core/color/oklab/xyz_to_oklab.spec.js +4 -4
  43. package/src/engine/animation/async/prototypeAsyncAnimation.d.ts +2 -0
  44. package/src/engine/animation/async/prototypeAsyncAnimation.d.ts.map +1 -0
  45. package/src/engine/animation/async/prototypeAsyncAnimation.js +344 -0
  46. package/src/engine/asset/AssetManager.d.ts.map +1 -1
  47. package/src/engine/asset/AssetManager.js +17 -0
  48. package/src/engine/asset/loaders/ArrayBufferLoader.d.ts.map +1 -1
  49. package/src/engine/asset/loaders/ArrayBufferLoader.js +22 -2
  50. package/src/engine/ecs/Entity.d.ts.map +1 -1
  51. package/src/engine/ecs/Entity.js +1 -0
  52. package/src/engine/ecs/terrain/ecs/TerrainSystem.d.ts.map +1 -1
  53. package/src/engine/ecs/terrain/ecs/TerrainSystem.js +3 -3
  54. package/src/engine/input/ecs/systems/InputControllerSystem.d.ts.map +1 -1
  55. package/src/engine/input/ecs/systems/InputControllerSystem.js +4 -8
  56. package/src/engine/intelligence/behavior/util/RandomDelayBehavior.d.ts +46 -0
  57. package/src/engine/intelligence/behavior/util/RandomDelayBehavior.d.ts.map +1 -0
  58. package/src/engine/intelligence/behavior/util/RandomDelayBehavior.js +85 -0
@@ -41384,6 +41384,133 @@ class FileLoader extends Loader {
41384
41384
 
41385
41385
  }
41386
41386
 
41387
+ /**
41388
+ * Abstract Base class to block based textures loader (dds, pvr, ...)
41389
+ *
41390
+ * Sub classes have to implement the parse() method which will be used in load().
41391
+ */
41392
+
41393
+ class CompressedTextureLoader extends Loader {
41394
+
41395
+ constructor( manager ) {
41396
+
41397
+ super( manager );
41398
+
41399
+ }
41400
+
41401
+ load( url, onLoad, onProgress, onError ) {
41402
+
41403
+ const scope = this;
41404
+
41405
+ const images = [];
41406
+
41407
+ const texture = new CompressedTexture();
41408
+
41409
+ const loader = new FileLoader( this.manager );
41410
+ loader.setPath( this.path );
41411
+ loader.setResponseType( 'arraybuffer' );
41412
+ loader.setRequestHeader( this.requestHeader );
41413
+ loader.setWithCredentials( scope.withCredentials );
41414
+
41415
+ let loaded = 0;
41416
+
41417
+ function loadTexture( i ) {
41418
+
41419
+ loader.load( url[ i ], function ( buffer ) {
41420
+
41421
+ const texDatas = scope.parse( buffer, true );
41422
+
41423
+ images[ i ] = {
41424
+ width: texDatas.width,
41425
+ height: texDatas.height,
41426
+ format: texDatas.format,
41427
+ mipmaps: texDatas.mipmaps
41428
+ };
41429
+
41430
+ loaded += 1;
41431
+
41432
+ if ( loaded === 6 ) {
41433
+
41434
+ if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
41435
+
41436
+ texture.image = images;
41437
+ texture.format = texDatas.format;
41438
+ texture.needsUpdate = true;
41439
+
41440
+ if ( onLoad ) onLoad( texture );
41441
+
41442
+ }
41443
+
41444
+ }, onProgress, onError );
41445
+
41446
+ }
41447
+
41448
+ if ( Array.isArray( url ) ) {
41449
+
41450
+ for ( let i = 0, il = url.length; i < il; ++ i ) {
41451
+
41452
+ loadTexture( i );
41453
+
41454
+ }
41455
+
41456
+ } else {
41457
+
41458
+ // compressed cubemap texture stored in a single DDS file
41459
+
41460
+ loader.load( url, function ( buffer ) {
41461
+
41462
+ const texDatas = scope.parse( buffer, true );
41463
+
41464
+ if ( texDatas.isCubemap ) {
41465
+
41466
+ const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
41467
+
41468
+ for ( let f = 0; f < faces; f ++ ) {
41469
+
41470
+ images[ f ] = { mipmaps: [] };
41471
+
41472
+ for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
41473
+
41474
+ images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
41475
+ images[ f ].format = texDatas.format;
41476
+ images[ f ].width = texDatas.width;
41477
+ images[ f ].height = texDatas.height;
41478
+
41479
+ }
41480
+
41481
+ }
41482
+
41483
+ texture.image = images;
41484
+
41485
+ } else {
41486
+
41487
+ texture.image.width = texDatas.width;
41488
+ texture.image.height = texDatas.height;
41489
+ texture.mipmaps = texDatas.mipmaps;
41490
+
41491
+ }
41492
+
41493
+ if ( texDatas.mipmapCount === 1 ) {
41494
+
41495
+ texture.minFilter = LinearFilter;
41496
+
41497
+ }
41498
+
41499
+ texture.format = texDatas.format;
41500
+ texture.needsUpdate = true;
41501
+
41502
+ if ( onLoad ) onLoad( texture );
41503
+
41504
+ }, onProgress, onError );
41505
+
41506
+ }
41507
+
41508
+ return texture;
41509
+
41510
+ }
41511
+
41512
+ }
41513
+
41387
41514
  class ImageLoader extends Loader {
41388
41515
 
41389
41516
  constructor( manager ) {
@@ -53659,14 +53786,15 @@ function sRGB_to_linear(
53659
53786
  }
53660
53787
 
53661
53788
  /**
53789
+ * @extends {Array.<number>}
53662
53790
  * @class
53663
53791
  */
53664
53792
  class Color {
53665
53793
  /**
53666
53794
  *
53667
- * @param {number} r value from 0 to 1
53668
- * @param {number} g value from 0 to 1
53669
- * @param {number} b value from 0 to 1
53795
+ * @param {number} [r] Red from 0 to 1
53796
+ * @param {number} [g] Green from 0 to 1
53797
+ * @param {number} [b] Blue from 0 to 1
53670
53798
  * @param {number} [a] value from 0 to 1 Alpha channel (transparency)
53671
53799
  */
53672
53800
  constructor(r = 0, g = 0, b = 0, a = 1) {
@@ -53786,6 +53914,20 @@ class Color {
53786
53914
  this.set(r, g, b, this.a);
53787
53915
  }
53788
53916
 
53917
+ /**
53918
+ *
53919
+ * @param {number} r
53920
+ * @param {number} g
53921
+ * @param {number} b
53922
+ */
53923
+ setRGBUint8(r, g, b) {
53924
+ this.setRGB(
53925
+ uint82float(r),
53926
+ uint82float(g),
53927
+ uint82float(b),
53928
+ );
53929
+ }
53930
+
53789
53931
  /**
53790
53932
  * set alpha
53791
53933
  * @param {number} a
@@ -53803,11 +53945,23 @@ class Color {
53803
53945
  */
53804
53946
  set(r, g, b, a) {
53805
53947
 
53948
+ // remember old values
53806
53949
  const _r = this.r;
53807
53950
  const _g = this.g;
53808
53951
  const _b = this.b;
53809
53952
  const _a = this.a;
53810
53953
 
53954
+ if (
53955
+ _r === r
53956
+ && _g === g
53957
+ && _b === b
53958
+ && _a === a
53959
+ ) {
53960
+ // no change
53961
+ return;
53962
+ }
53963
+
53964
+ // set new values
53811
53965
  this.r = r;
53812
53966
  this.g = g;
53813
53967
  this.b = b;
@@ -54049,7 +54203,7 @@ class Color {
54049
54203
  const g = (value >> 8) & 0xFF;
54050
54204
  const b = (value) & 0xFF;
54051
54205
 
54052
- this.setRGB(r / 255, g / 255, b / 255);
54206
+ this.setRGBUint8(r, g, b);
54053
54207
  }
54054
54208
 
54055
54209
  /**
@@ -54114,8 +54268,7 @@ class Color {
54114
54268
  }
54115
54269
 
54116
54270
  fromJSON({ r, g, b, a = 1 }) {
54117
- this.setRGB(r, g, b);
54118
- this.a = a;
54271
+ this.set(r, g, b, a);
54119
54272
  }
54120
54273
 
54121
54274
  toJSON() {
@@ -54169,8 +54322,7 @@ class Color {
54169
54322
  const b = buffer.readFloat32();
54170
54323
  const a = buffer.readFloat32();
54171
54324
 
54172
- this.setRGB(r, g, b);
54173
- this.a = a;
54325
+ this.set(r, g, b, a);
54174
54326
  }
54175
54327
 
54176
54328
  /**
@@ -67673,13 +67825,17 @@ class ArrayBufferLoader extends AssetLoader {
67673
67825
 
67674
67826
  }
67675
67827
 
67828
+ /**
67829
+ * @type {ReadableStreamDefaultReader<Uint8Array>}
67830
+ */
67676
67831
  const reader = response.body.getReader();
67832
+
67677
67833
  const contentLength = response.headers.get('Content-Length');
67678
67834
  const total = contentLength ? parseInt(contentLength) : 0;
67679
67835
  let loaded = 0;
67680
67836
 
67681
67837
  // periodically read data into the new stream tracking while download progress
67682
- const stream = new ReadableStream({
67838
+ const stream_prototype = {
67683
67839
  type: "bytes",
67684
67840
  start(controller) {
67685
67841
 
@@ -67708,7 +67864,22 @@ class ArrayBufferLoader extends AssetLoader {
67708
67864
 
67709
67865
  }
67710
67866
 
67711
- });
67867
+ };
67868
+
67869
+ /**
67870
+ * @type {ReadableStream}
67871
+ */
67872
+ let stream;
67873
+
67874
+ try {
67875
+ stream = new ReadableStream(stream_prototype);
67876
+ } catch (e) {
67877
+ /*
67878
+ Workaround for Safari bug: "TypeError: ReadableByteStreamController is not implemented"
67879
+ By not wrapping the response we lose the ability to track progress, but that's not a critical issue in most cases
67880
+ */
67881
+ return response;
67882
+ }
67712
67883
 
67713
67884
  return new Response(stream);
67714
67885
  }
@@ -68174,6 +68345,377 @@ class ImageRGBADataLoader extends AssetLoader {
68174
68345
  }
68175
68346
  }
68176
68347
 
68348
+ class DDSLoader extends CompressedTextureLoader {
68349
+
68350
+ constructor( manager ) {
68351
+
68352
+ super( manager );
68353
+
68354
+ }
68355
+
68356
+ parse( buffer, loadMipmaps ) {
68357
+
68358
+ const dds = { mipmaps: [], width: 0, height: 0, format: null, mipmapCount: 1 };
68359
+
68360
+ // Adapted from @toji's DDS utils
68361
+ // https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js
68362
+
68363
+ // All values and structures referenced from:
68364
+ // http://msdn.microsoft.com/en-us/library/bb943991.aspx/
68365
+
68366
+ const DDS_MAGIC = 0x20534444;
68367
+
68368
+ // let DDSD_CAPS = 0x1;
68369
+ // let DDSD_HEIGHT = 0x2;
68370
+ // let DDSD_WIDTH = 0x4;
68371
+ // let DDSD_PITCH = 0x8;
68372
+ // let DDSD_PIXELFORMAT = 0x1000;
68373
+ const DDSD_MIPMAPCOUNT = 0x20000;
68374
+ // let DDSD_LINEARSIZE = 0x80000;
68375
+ // let DDSD_DEPTH = 0x800000;
68376
+
68377
+ // let DDSCAPS_COMPLEX = 0x8;
68378
+ // let DDSCAPS_MIPMAP = 0x400000;
68379
+ // let DDSCAPS_TEXTURE = 0x1000;
68380
+
68381
+ const DDSCAPS2_CUBEMAP = 0x200;
68382
+ const DDSCAPS2_CUBEMAP_POSITIVEX = 0x400;
68383
+ const DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800;
68384
+ const DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000;
68385
+ const DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000;
68386
+ const DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000;
68387
+ const DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000;
68388
+ // let DDSCAPS2_VOLUME = 0x200000;
68389
+
68390
+ // let DDPF_ALPHAPIXELS = 0x1;
68391
+ // let DDPF_ALPHA = 0x2;
68392
+ const DDPF_FOURCC = 0x4;
68393
+ // let DDPF_RGB = 0x40;
68394
+ // let DDPF_YUV = 0x200;
68395
+ // let DDPF_LUMINANCE = 0x20000;
68396
+
68397
+ function fourCCToInt32( value ) {
68398
+
68399
+ return value.charCodeAt( 0 ) +
68400
+ ( value.charCodeAt( 1 ) << 8 ) +
68401
+ ( value.charCodeAt( 2 ) << 16 ) +
68402
+ ( value.charCodeAt( 3 ) << 24 );
68403
+
68404
+ }
68405
+
68406
+ function loadARGBMip( buffer, dataOffset, width, height ) {
68407
+
68408
+ const dataLength = width * height * 4;
68409
+ const srcBuffer = new Uint8Array( buffer, dataOffset, dataLength );
68410
+ const byteArray = new Uint8Array( dataLength );
68411
+ let dst = 0;
68412
+ let src = 0;
68413
+ for ( let y = 0; y < height; y ++ ) {
68414
+
68415
+ for ( let x = 0; x < width; x ++ ) {
68416
+
68417
+ const b = srcBuffer[ src ]; src ++;
68418
+ const g = srcBuffer[ src ]; src ++;
68419
+ const r = srcBuffer[ src ]; src ++;
68420
+ const a = srcBuffer[ src ]; src ++;
68421
+ byteArray[ dst ] = r; dst ++; //r
68422
+ byteArray[ dst ] = g; dst ++; //g
68423
+ byteArray[ dst ] = b; dst ++; //b
68424
+ byteArray[ dst ] = a; dst ++; //a
68425
+
68426
+ }
68427
+
68428
+ }
68429
+
68430
+ return byteArray;
68431
+
68432
+ }
68433
+
68434
+ const FOURCC_DXT1 = fourCCToInt32( 'DXT1' );
68435
+ const FOURCC_DXT3 = fourCCToInt32( 'DXT3' );
68436
+ const FOURCC_DXT5 = fourCCToInt32( 'DXT5' );
68437
+ const FOURCC_ETC1 = fourCCToInt32( 'ETC1' );
68438
+
68439
+ const headerLengthInt = 31; // The header length in 32 bit ints
68440
+
68441
+ // Offsets into the header array
68442
+
68443
+ const off_magic = 0;
68444
+
68445
+ const off_size = 1;
68446
+ const off_flags = 2;
68447
+ const off_height = 3;
68448
+ const off_width = 4;
68449
+
68450
+ const off_mipmapCount = 7;
68451
+
68452
+ const off_pfFlags = 20;
68453
+ const off_pfFourCC = 21;
68454
+ const off_RGBBitCount = 22;
68455
+ const off_RBitMask = 23;
68456
+ const off_GBitMask = 24;
68457
+ const off_BBitMask = 25;
68458
+ const off_ABitMask = 26;
68459
+
68460
+ // let off_caps = 27;
68461
+ const off_caps2 = 28;
68462
+ // let off_caps3 = 29;
68463
+ // let off_caps4 = 30;
68464
+
68465
+ // Parse header
68466
+
68467
+ const header = new Int32Array( buffer, 0, headerLengthInt );
68468
+
68469
+ if ( header[ off_magic ] !== DDS_MAGIC ) {
68470
+ return dds;
68471
+
68472
+ }
68473
+
68474
+ if ( ! header[ off_pfFlags ] & DDPF_FOURCC ) {
68475
+ return dds;
68476
+
68477
+ }
68478
+
68479
+ let blockBytes;
68480
+
68481
+ const fourCC = header[ off_pfFourCC ];
68482
+
68483
+ let isRGBAUncompressed = false;
68484
+
68485
+ switch ( fourCC ) {
68486
+
68487
+ case FOURCC_DXT1:
68488
+
68489
+ blockBytes = 8;
68490
+ dds.format = RGB_S3TC_DXT1_Format;
68491
+ break;
68492
+
68493
+ case FOURCC_DXT3:
68494
+
68495
+ blockBytes = 16;
68496
+ dds.format = RGBA_S3TC_DXT3_Format;
68497
+ break;
68498
+
68499
+ case FOURCC_DXT5:
68500
+
68501
+ blockBytes = 16;
68502
+ dds.format = RGBA_S3TC_DXT5_Format;
68503
+ break;
68504
+
68505
+ case FOURCC_ETC1:
68506
+
68507
+ blockBytes = 8;
68508
+ dds.format = RGB_ETC1_Format;
68509
+ break;
68510
+
68511
+ default:
68512
+
68513
+ if ( header[ off_RGBBitCount ] === 32
68514
+ && header[ off_RBitMask ] & 0xff0000
68515
+ && header[ off_GBitMask ] & 0xff00
68516
+ && header[ off_BBitMask ] & 0xff
68517
+ && header[ off_ABitMask ] & 0xff000000 ) {
68518
+
68519
+ isRGBAUncompressed = true;
68520
+ blockBytes = 64;
68521
+ dds.format = RGBAFormat;
68522
+
68523
+ } else {
68524
+ return dds;
68525
+
68526
+ }
68527
+
68528
+ }
68529
+
68530
+ dds.mipmapCount = 1;
68531
+
68532
+ if ( header[ off_flags ] & DDSD_MIPMAPCOUNT && loadMipmaps !== false ) {
68533
+
68534
+ dds.mipmapCount = Math.max( 1, header[ off_mipmapCount ] );
68535
+
68536
+ }
68537
+
68538
+ const caps2 = header[ off_caps2 ];
68539
+ dds.isCubemap = caps2 & DDSCAPS2_CUBEMAP ? true : false;
68540
+ if ( dds.isCubemap && (
68541
+ ! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEX ) ||
68542
+ ! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX ) ||
68543
+ ! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEY ) ||
68544
+ ! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY ) ||
68545
+ ! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ ) ||
68546
+ ! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ )
68547
+ ) ) {
68548
+ return dds;
68549
+
68550
+ }
68551
+
68552
+ dds.width = header[ off_width ];
68553
+ dds.height = header[ off_height ];
68554
+
68555
+ let dataOffset = header[ off_size ] + 4;
68556
+
68557
+ // Extract mipmaps buffers
68558
+
68559
+ const faces = dds.isCubemap ? 6 : 1;
68560
+
68561
+ for ( let face = 0; face < faces; face ++ ) {
68562
+
68563
+ let width = dds.width;
68564
+ let height = dds.height;
68565
+
68566
+ for ( let i = 0; i < dds.mipmapCount; i ++ ) {
68567
+
68568
+ let byteArray, dataLength;
68569
+
68570
+ if ( isRGBAUncompressed ) {
68571
+
68572
+ byteArray = loadARGBMip( buffer, dataOffset, width, height );
68573
+ dataLength = byteArray.length;
68574
+
68575
+ } else {
68576
+
68577
+ dataLength = Math.max( 4, width ) / 4 * Math.max( 4, height ) / 4 * blockBytes;
68578
+ byteArray = new Uint8Array( buffer, dataOffset, dataLength );
68579
+
68580
+ }
68581
+
68582
+ const mipmap = { 'data': byteArray, 'width': width, 'height': height };
68583
+ dds.mipmaps.push( mipmap );
68584
+
68585
+ dataOffset += dataLength;
68586
+
68587
+ width = Math.max( width >> 1, 1 );
68588
+ height = Math.max( height >> 1, 1 );
68589
+
68590
+ }
68591
+
68592
+ }
68593
+
68594
+ return dds;
68595
+
68596
+ }
68597
+
68598
+ }
68599
+
68600
+ /**
68601
+ *
68602
+ * @param {Texture} t
68603
+ * @returns {Texture}
68604
+ */
68605
+ function cloneTexture(t) {
68606
+ const clone = t.clone();
68607
+
68608
+ //apparently cloned textures need this trick to work
68609
+ clone.needsUpdate = true;
68610
+
68611
+ return clone;
68612
+ }
68613
+
68614
+ function loadDDSTexture(path, success, failure, progress) {
68615
+ function computeByteSize(texture) {
68616
+ let result = 0;
68617
+ const images = texture.image;
68618
+ for (let i = 0; i < images.length; i++) {
68619
+ const image = images[i];
68620
+ const mipmaps = image.mipmaps;
68621
+ for (let j = 0; j < mipmaps.length; j++) {
68622
+ const mipmap = mipmaps[j];
68623
+ /**
68624
+ * @type {Uint8Array}
68625
+ */
68626
+ const data = mipmap.data;
68627
+ result += data.length;
68628
+ }
68629
+ }
68630
+ return result;
68631
+ }
68632
+
68633
+ const loader = new DDSLoader();
68634
+ loader.load(path, function (texture) {
68635
+ const byteSize = computeByteSize(texture);
68636
+
68637
+ function factory() {
68638
+ return cloneTexture(texture);
68639
+ }
68640
+
68641
+ const asset = new Asset(factory, byteSize);
68642
+
68643
+ success(asset);
68644
+
68645
+ }, progress, failure);
68646
+ }
68647
+
68648
+ const textureLoader = new TextureLoader();
68649
+
68650
+ /**
68651
+ *
68652
+ * @param {Texture} texture
68653
+ * @return {number}
68654
+ */
68655
+ function computeTextureByteSize(texture) {
68656
+ const image = texture.image;
68657
+ if (image instanceof ImageData) {
68658
+ return image.array.length;
68659
+ } else {
68660
+ //TODO do actual computation
68661
+ //don't know
68662
+ return 1;
68663
+ }
68664
+ }
68665
+ function loadStandardImageTexture(path, success, failure, progress) {
68666
+
68667
+
68668
+
68669
+ textureLoader.load(path, function (texture) {
68670
+
68671
+ texture.flipY = false;
68672
+
68673
+ const byteSize = computeTextureByteSize(texture);
68674
+
68675
+ const asset = new Asset(function () {
68676
+ return cloneTexture(texture);
68677
+ }, byteSize);
68678
+
68679
+ success(asset);
68680
+ }, progress, failure);
68681
+ }
68682
+
68683
+ class TextureAssetLoader extends AssetLoader {
68684
+ load(scope, path, success, failure, progress) {
68685
+ //figure out what kind of a texture it is
68686
+ let fileExtension = computeFileExtension(path);
68687
+
68688
+ if (fileExtension === null) {
68689
+ //check if it's a data path
68690
+
68691
+ const match = path.match(/^data\:image\/([a-zA-Z0-9]+)\;/);
68692
+
68693
+ if (match === null) {
68694
+ throw new Error(`no file extension on path '${path}'`);
68695
+
68696
+ } else {
68697
+ //seems ok
68698
+ fileExtension = match[1];
68699
+ }
68700
+
68701
+ }
68702
+
68703
+ const lowerCaseExtension = fileExtension.toLowerCase();
68704
+ switch (lowerCaseExtension) {
68705
+ case 'dds':
68706
+ loadDDSTexture(path, success, failure, progress);
68707
+ break;
68708
+ case 'png':
68709
+ case 'jpg':
68710
+ loadStandardImageTexture(path, success, failure, progress);
68711
+ break;
68712
+ default:
68713
+ throw new Error(`Unsupported texture file format: '${lowerCaseExtension}'`);
68714
+
68715
+ }
68716
+ }
68717
+ }
68718
+
68177
68719
  /**
68178
68720
  * Utility class for managing connection between listeners to signals
68179
68721
  */
@@ -69744,9 +70286,8 @@ class TerrainSystem extends System {
69744
70286
 
69745
70287
  const am = this.assetManager;
69746
70288
 
69747
- if (!am.hasLoaderForType('image')) {
69748
- await am.registerLoader('image', new ImageRGBADataLoader());
69749
- }
70289
+ await am.tryRegisterLoader('image', new ImageRGBADataLoader());
70290
+ await am.tryRegisterLoader('texture', new TextureAssetLoader());
69750
70291
 
69751
70292
  readyCallback();
69752
70293
  }
@@ -72773,6 +73314,7 @@ class Entity {
72773
73314
 
72774
73315
  /**
72775
73316
  * Similar to {@link #getComponent}, instead of returning null - throws an exception
73317
+ * @template T
72776
73318
  * @param {Class<T>} klass
72777
73319
  * @returns {T}
72778
73320
  */
@@ -85823,6 +86365,23 @@ class AssetManager {
85823
86365
  return true;
85824
86366
  }
85825
86367
 
86368
+ /**
86369
+ * Will register loader only if none exists for this type
86370
+ * @template T
86371
+ * @param {string} type
86372
+ * @param {AssetLoader<T>} loader
86373
+ * @returns {Promise<boolean>} true if registered , false otherwise
86374
+ */
86375
+ async tryRegisterLoader(type, loader) {
86376
+ if (this.hasLoaderForType(type)) {
86377
+ return false;
86378
+ }
86379
+
86380
+ await this.registerLoader(type, loader);
86381
+
86382
+ return true;
86383
+ }
86384
+
85826
86385
  /**
85827
86386
  * @template T
85828
86387
  * @param {string} type
@@ -114120,12 +114679,8 @@ function getOrCreateProxy(proxies, path, signal) {
114120
114679
  * @param {InputControllerBinding} binding
114121
114680
  */
114122
114681
  Proxy.prototype.add = function (binding) {
114123
- if (this.signal.isDispatching()) {
114124
- // handler is currently running, adding the binding could trigger it immediately. Deferring the registration allows us to avoid this
114125
- this.deferred.push(binding);
114126
- } else {
114127
- this.registerBinding(binding);
114128
- }
114682
+ //TODO handle case where binding is added mid-dispatch
114683
+ this.registerBinding(binding);
114129
114684
  };
114130
114685
 
114131
114686
  /**
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.100.0",
8
+ "version": "2.100.2",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {