@woosh/meep-engine 2.100.0 → 2.100.1
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.
- package/build/meep.cjs +553 -17
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +553 -17
- package/package.json +1 -1
- package/src/core/color/Color.d.ts.map +1 -1
- package/src/core/color/Color.js +39 -8
- package/src/engine/animation/async/prototypeAsyncAnimation.d.ts +2 -0
- package/src/engine/animation/async/prototypeAsyncAnimation.d.ts.map +1 -0
- package/src/engine/animation/async/prototypeAsyncAnimation.js +344 -0
- package/src/engine/asset/AssetManager.d.ts.map +1 -1
- package/src/engine/asset/AssetManager.js +17 -0
- package/src/engine/ecs/Entity.d.ts.map +1 -1
- package/src/engine/ecs/Entity.js +1 -0
- package/src/engine/ecs/terrain/ecs/TerrainSystem.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/TerrainSystem.js +3 -3
- package/src/engine/input/ecs/systems/InputControllerSystem.d.ts.map +1 -1
- package/src/engine/input/ecs/systems/InputControllerSystem.js +4 -8
- package/src/engine/intelligence/behavior/util/RandomDelayBehavior.d.ts +46 -0
- package/src/engine/intelligence/behavior/util/RandomDelayBehavior.d.ts.map +1 -0
- package/src/engine/intelligence/behavior/util/RandomDelayBehavior.js +85 -0
package/build/meep.cjs
CHANGED
|
@@ -41386,6 +41386,133 @@ class FileLoader extends Loader {
|
|
|
41386
41386
|
|
|
41387
41387
|
}
|
|
41388
41388
|
|
|
41389
|
+
/**
|
|
41390
|
+
* Abstract Base class to block based textures loader (dds, pvr, ...)
|
|
41391
|
+
*
|
|
41392
|
+
* Sub classes have to implement the parse() method which will be used in load().
|
|
41393
|
+
*/
|
|
41394
|
+
|
|
41395
|
+
class CompressedTextureLoader extends Loader {
|
|
41396
|
+
|
|
41397
|
+
constructor( manager ) {
|
|
41398
|
+
|
|
41399
|
+
super( manager );
|
|
41400
|
+
|
|
41401
|
+
}
|
|
41402
|
+
|
|
41403
|
+
load( url, onLoad, onProgress, onError ) {
|
|
41404
|
+
|
|
41405
|
+
const scope = this;
|
|
41406
|
+
|
|
41407
|
+
const images = [];
|
|
41408
|
+
|
|
41409
|
+
const texture = new CompressedTexture();
|
|
41410
|
+
|
|
41411
|
+
const loader = new FileLoader( this.manager );
|
|
41412
|
+
loader.setPath( this.path );
|
|
41413
|
+
loader.setResponseType( 'arraybuffer' );
|
|
41414
|
+
loader.setRequestHeader( this.requestHeader );
|
|
41415
|
+
loader.setWithCredentials( scope.withCredentials );
|
|
41416
|
+
|
|
41417
|
+
let loaded = 0;
|
|
41418
|
+
|
|
41419
|
+
function loadTexture( i ) {
|
|
41420
|
+
|
|
41421
|
+
loader.load( url[ i ], function ( buffer ) {
|
|
41422
|
+
|
|
41423
|
+
const texDatas = scope.parse( buffer, true );
|
|
41424
|
+
|
|
41425
|
+
images[ i ] = {
|
|
41426
|
+
width: texDatas.width,
|
|
41427
|
+
height: texDatas.height,
|
|
41428
|
+
format: texDatas.format,
|
|
41429
|
+
mipmaps: texDatas.mipmaps
|
|
41430
|
+
};
|
|
41431
|
+
|
|
41432
|
+
loaded += 1;
|
|
41433
|
+
|
|
41434
|
+
if ( loaded === 6 ) {
|
|
41435
|
+
|
|
41436
|
+
if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
|
|
41437
|
+
|
|
41438
|
+
texture.image = images;
|
|
41439
|
+
texture.format = texDatas.format;
|
|
41440
|
+
texture.needsUpdate = true;
|
|
41441
|
+
|
|
41442
|
+
if ( onLoad ) onLoad( texture );
|
|
41443
|
+
|
|
41444
|
+
}
|
|
41445
|
+
|
|
41446
|
+
}, onProgress, onError );
|
|
41447
|
+
|
|
41448
|
+
}
|
|
41449
|
+
|
|
41450
|
+
if ( Array.isArray( url ) ) {
|
|
41451
|
+
|
|
41452
|
+
for ( let i = 0, il = url.length; i < il; ++ i ) {
|
|
41453
|
+
|
|
41454
|
+
loadTexture( i );
|
|
41455
|
+
|
|
41456
|
+
}
|
|
41457
|
+
|
|
41458
|
+
} else {
|
|
41459
|
+
|
|
41460
|
+
// compressed cubemap texture stored in a single DDS file
|
|
41461
|
+
|
|
41462
|
+
loader.load( url, function ( buffer ) {
|
|
41463
|
+
|
|
41464
|
+
const texDatas = scope.parse( buffer, true );
|
|
41465
|
+
|
|
41466
|
+
if ( texDatas.isCubemap ) {
|
|
41467
|
+
|
|
41468
|
+
const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
|
|
41469
|
+
|
|
41470
|
+
for ( let f = 0; f < faces; f ++ ) {
|
|
41471
|
+
|
|
41472
|
+
images[ f ] = { mipmaps: [] };
|
|
41473
|
+
|
|
41474
|
+
for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
|
|
41475
|
+
|
|
41476
|
+
images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
|
|
41477
|
+
images[ f ].format = texDatas.format;
|
|
41478
|
+
images[ f ].width = texDatas.width;
|
|
41479
|
+
images[ f ].height = texDatas.height;
|
|
41480
|
+
|
|
41481
|
+
}
|
|
41482
|
+
|
|
41483
|
+
}
|
|
41484
|
+
|
|
41485
|
+
texture.image = images;
|
|
41486
|
+
|
|
41487
|
+
} else {
|
|
41488
|
+
|
|
41489
|
+
texture.image.width = texDatas.width;
|
|
41490
|
+
texture.image.height = texDatas.height;
|
|
41491
|
+
texture.mipmaps = texDatas.mipmaps;
|
|
41492
|
+
|
|
41493
|
+
}
|
|
41494
|
+
|
|
41495
|
+
if ( texDatas.mipmapCount === 1 ) {
|
|
41496
|
+
|
|
41497
|
+
texture.minFilter = LinearFilter;
|
|
41498
|
+
|
|
41499
|
+
}
|
|
41500
|
+
|
|
41501
|
+
texture.format = texDatas.format;
|
|
41502
|
+
texture.needsUpdate = true;
|
|
41503
|
+
|
|
41504
|
+
if ( onLoad ) onLoad( texture );
|
|
41505
|
+
|
|
41506
|
+
}, onProgress, onError );
|
|
41507
|
+
|
|
41508
|
+
}
|
|
41509
|
+
|
|
41510
|
+
return texture;
|
|
41511
|
+
|
|
41512
|
+
}
|
|
41513
|
+
|
|
41514
|
+
}
|
|
41515
|
+
|
|
41389
41516
|
class ImageLoader extends Loader {
|
|
41390
41517
|
|
|
41391
41518
|
constructor( manager ) {
|
|
@@ -53661,14 +53788,15 @@ function sRGB_to_linear(
|
|
|
53661
53788
|
}
|
|
53662
53789
|
|
|
53663
53790
|
/**
|
|
53791
|
+
* @extends {Array.<number>}
|
|
53664
53792
|
* @class
|
|
53665
53793
|
*/
|
|
53666
53794
|
class Color {
|
|
53667
53795
|
/**
|
|
53668
53796
|
*
|
|
53669
|
-
* @param {number} r
|
|
53670
|
-
* @param {number} g
|
|
53671
|
-
* @param {number} b
|
|
53797
|
+
* @param {number} [r] Red from 0 to 1
|
|
53798
|
+
* @param {number} [g] Green from 0 to 1
|
|
53799
|
+
* @param {number} [b] Blue from 0 to 1
|
|
53672
53800
|
* @param {number} [a] value from 0 to 1 Alpha channel (transparency)
|
|
53673
53801
|
*/
|
|
53674
53802
|
constructor(r = 0, g = 0, b = 0, a = 1) {
|
|
@@ -53788,6 +53916,20 @@ class Color {
|
|
|
53788
53916
|
this.set(r, g, b, this.a);
|
|
53789
53917
|
}
|
|
53790
53918
|
|
|
53919
|
+
/**
|
|
53920
|
+
*
|
|
53921
|
+
* @param {number} r
|
|
53922
|
+
* @param {number} g
|
|
53923
|
+
* @param {number} b
|
|
53924
|
+
*/
|
|
53925
|
+
setRGBUint8(r, g, b) {
|
|
53926
|
+
this.setRGB(
|
|
53927
|
+
uint82float(r),
|
|
53928
|
+
uint82float(g),
|
|
53929
|
+
uint82float(b),
|
|
53930
|
+
);
|
|
53931
|
+
}
|
|
53932
|
+
|
|
53791
53933
|
/**
|
|
53792
53934
|
* set alpha
|
|
53793
53935
|
* @param {number} a
|
|
@@ -53805,11 +53947,23 @@ class Color {
|
|
|
53805
53947
|
*/
|
|
53806
53948
|
set(r, g, b, a) {
|
|
53807
53949
|
|
|
53950
|
+
// remember old values
|
|
53808
53951
|
const _r = this.r;
|
|
53809
53952
|
const _g = this.g;
|
|
53810
53953
|
const _b = this.b;
|
|
53811
53954
|
const _a = this.a;
|
|
53812
53955
|
|
|
53956
|
+
if (
|
|
53957
|
+
_r === r
|
|
53958
|
+
&& _g === g
|
|
53959
|
+
&& _b === b
|
|
53960
|
+
&& _a === a
|
|
53961
|
+
) {
|
|
53962
|
+
// no change
|
|
53963
|
+
return;
|
|
53964
|
+
}
|
|
53965
|
+
|
|
53966
|
+
// set new values
|
|
53813
53967
|
this.r = r;
|
|
53814
53968
|
this.g = g;
|
|
53815
53969
|
this.b = b;
|
|
@@ -54051,7 +54205,7 @@ class Color {
|
|
|
54051
54205
|
const g = (value >> 8) & 0xFF;
|
|
54052
54206
|
const b = (value) & 0xFF;
|
|
54053
54207
|
|
|
54054
|
-
this.
|
|
54208
|
+
this.setRGBUint8(r, g, b);
|
|
54055
54209
|
}
|
|
54056
54210
|
|
|
54057
54211
|
/**
|
|
@@ -54116,8 +54270,7 @@ class Color {
|
|
|
54116
54270
|
}
|
|
54117
54271
|
|
|
54118
54272
|
fromJSON({ r, g, b, a = 1 }) {
|
|
54119
|
-
this.
|
|
54120
|
-
this.a = a;
|
|
54273
|
+
this.set(r, g, b, a);
|
|
54121
54274
|
}
|
|
54122
54275
|
|
|
54123
54276
|
toJSON() {
|
|
@@ -54171,8 +54324,7 @@ class Color {
|
|
|
54171
54324
|
const b = buffer.readFloat32();
|
|
54172
54325
|
const a = buffer.readFloat32();
|
|
54173
54326
|
|
|
54174
|
-
this.
|
|
54175
|
-
this.a = a;
|
|
54327
|
+
this.set(r, g, b, a);
|
|
54176
54328
|
}
|
|
54177
54329
|
|
|
54178
54330
|
/**
|
|
@@ -68176,6 +68328,377 @@ class ImageRGBADataLoader extends AssetLoader {
|
|
|
68176
68328
|
}
|
|
68177
68329
|
}
|
|
68178
68330
|
|
|
68331
|
+
class DDSLoader extends CompressedTextureLoader {
|
|
68332
|
+
|
|
68333
|
+
constructor( manager ) {
|
|
68334
|
+
|
|
68335
|
+
super( manager );
|
|
68336
|
+
|
|
68337
|
+
}
|
|
68338
|
+
|
|
68339
|
+
parse( buffer, loadMipmaps ) {
|
|
68340
|
+
|
|
68341
|
+
const dds = { mipmaps: [], width: 0, height: 0, format: null, mipmapCount: 1 };
|
|
68342
|
+
|
|
68343
|
+
// Adapted from @toji's DDS utils
|
|
68344
|
+
// https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js
|
|
68345
|
+
|
|
68346
|
+
// All values and structures referenced from:
|
|
68347
|
+
// http://msdn.microsoft.com/en-us/library/bb943991.aspx/
|
|
68348
|
+
|
|
68349
|
+
const DDS_MAGIC = 0x20534444;
|
|
68350
|
+
|
|
68351
|
+
// let DDSD_CAPS = 0x1;
|
|
68352
|
+
// let DDSD_HEIGHT = 0x2;
|
|
68353
|
+
// let DDSD_WIDTH = 0x4;
|
|
68354
|
+
// let DDSD_PITCH = 0x8;
|
|
68355
|
+
// let DDSD_PIXELFORMAT = 0x1000;
|
|
68356
|
+
const DDSD_MIPMAPCOUNT = 0x20000;
|
|
68357
|
+
// let DDSD_LINEARSIZE = 0x80000;
|
|
68358
|
+
// let DDSD_DEPTH = 0x800000;
|
|
68359
|
+
|
|
68360
|
+
// let DDSCAPS_COMPLEX = 0x8;
|
|
68361
|
+
// let DDSCAPS_MIPMAP = 0x400000;
|
|
68362
|
+
// let DDSCAPS_TEXTURE = 0x1000;
|
|
68363
|
+
|
|
68364
|
+
const DDSCAPS2_CUBEMAP = 0x200;
|
|
68365
|
+
const DDSCAPS2_CUBEMAP_POSITIVEX = 0x400;
|
|
68366
|
+
const DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800;
|
|
68367
|
+
const DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000;
|
|
68368
|
+
const DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000;
|
|
68369
|
+
const DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000;
|
|
68370
|
+
const DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000;
|
|
68371
|
+
// let DDSCAPS2_VOLUME = 0x200000;
|
|
68372
|
+
|
|
68373
|
+
// let DDPF_ALPHAPIXELS = 0x1;
|
|
68374
|
+
// let DDPF_ALPHA = 0x2;
|
|
68375
|
+
const DDPF_FOURCC = 0x4;
|
|
68376
|
+
// let DDPF_RGB = 0x40;
|
|
68377
|
+
// let DDPF_YUV = 0x200;
|
|
68378
|
+
// let DDPF_LUMINANCE = 0x20000;
|
|
68379
|
+
|
|
68380
|
+
function fourCCToInt32( value ) {
|
|
68381
|
+
|
|
68382
|
+
return value.charCodeAt( 0 ) +
|
|
68383
|
+
( value.charCodeAt( 1 ) << 8 ) +
|
|
68384
|
+
( value.charCodeAt( 2 ) << 16 ) +
|
|
68385
|
+
( value.charCodeAt( 3 ) << 24 );
|
|
68386
|
+
|
|
68387
|
+
}
|
|
68388
|
+
|
|
68389
|
+
function loadARGBMip( buffer, dataOffset, width, height ) {
|
|
68390
|
+
|
|
68391
|
+
const dataLength = width * height * 4;
|
|
68392
|
+
const srcBuffer = new Uint8Array( buffer, dataOffset, dataLength );
|
|
68393
|
+
const byteArray = new Uint8Array( dataLength );
|
|
68394
|
+
let dst = 0;
|
|
68395
|
+
let src = 0;
|
|
68396
|
+
for ( let y = 0; y < height; y ++ ) {
|
|
68397
|
+
|
|
68398
|
+
for ( let x = 0; x < width; x ++ ) {
|
|
68399
|
+
|
|
68400
|
+
const b = srcBuffer[ src ]; src ++;
|
|
68401
|
+
const g = srcBuffer[ src ]; src ++;
|
|
68402
|
+
const r = srcBuffer[ src ]; src ++;
|
|
68403
|
+
const a = srcBuffer[ src ]; src ++;
|
|
68404
|
+
byteArray[ dst ] = r; dst ++; //r
|
|
68405
|
+
byteArray[ dst ] = g; dst ++; //g
|
|
68406
|
+
byteArray[ dst ] = b; dst ++; //b
|
|
68407
|
+
byteArray[ dst ] = a; dst ++; //a
|
|
68408
|
+
|
|
68409
|
+
}
|
|
68410
|
+
|
|
68411
|
+
}
|
|
68412
|
+
|
|
68413
|
+
return byteArray;
|
|
68414
|
+
|
|
68415
|
+
}
|
|
68416
|
+
|
|
68417
|
+
const FOURCC_DXT1 = fourCCToInt32( 'DXT1' );
|
|
68418
|
+
const FOURCC_DXT3 = fourCCToInt32( 'DXT3' );
|
|
68419
|
+
const FOURCC_DXT5 = fourCCToInt32( 'DXT5' );
|
|
68420
|
+
const FOURCC_ETC1 = fourCCToInt32( 'ETC1' );
|
|
68421
|
+
|
|
68422
|
+
const headerLengthInt = 31; // The header length in 32 bit ints
|
|
68423
|
+
|
|
68424
|
+
// Offsets into the header array
|
|
68425
|
+
|
|
68426
|
+
const off_magic = 0;
|
|
68427
|
+
|
|
68428
|
+
const off_size = 1;
|
|
68429
|
+
const off_flags = 2;
|
|
68430
|
+
const off_height = 3;
|
|
68431
|
+
const off_width = 4;
|
|
68432
|
+
|
|
68433
|
+
const off_mipmapCount = 7;
|
|
68434
|
+
|
|
68435
|
+
const off_pfFlags = 20;
|
|
68436
|
+
const off_pfFourCC = 21;
|
|
68437
|
+
const off_RGBBitCount = 22;
|
|
68438
|
+
const off_RBitMask = 23;
|
|
68439
|
+
const off_GBitMask = 24;
|
|
68440
|
+
const off_BBitMask = 25;
|
|
68441
|
+
const off_ABitMask = 26;
|
|
68442
|
+
|
|
68443
|
+
// let off_caps = 27;
|
|
68444
|
+
const off_caps2 = 28;
|
|
68445
|
+
// let off_caps3 = 29;
|
|
68446
|
+
// let off_caps4 = 30;
|
|
68447
|
+
|
|
68448
|
+
// Parse header
|
|
68449
|
+
|
|
68450
|
+
const header = new Int32Array( buffer, 0, headerLengthInt );
|
|
68451
|
+
|
|
68452
|
+
if ( header[ off_magic ] !== DDS_MAGIC ) {
|
|
68453
|
+
return dds;
|
|
68454
|
+
|
|
68455
|
+
}
|
|
68456
|
+
|
|
68457
|
+
if ( ! header[ off_pfFlags ] & DDPF_FOURCC ) {
|
|
68458
|
+
return dds;
|
|
68459
|
+
|
|
68460
|
+
}
|
|
68461
|
+
|
|
68462
|
+
let blockBytes;
|
|
68463
|
+
|
|
68464
|
+
const fourCC = header[ off_pfFourCC ];
|
|
68465
|
+
|
|
68466
|
+
let isRGBAUncompressed = false;
|
|
68467
|
+
|
|
68468
|
+
switch ( fourCC ) {
|
|
68469
|
+
|
|
68470
|
+
case FOURCC_DXT1:
|
|
68471
|
+
|
|
68472
|
+
blockBytes = 8;
|
|
68473
|
+
dds.format = RGB_S3TC_DXT1_Format;
|
|
68474
|
+
break;
|
|
68475
|
+
|
|
68476
|
+
case FOURCC_DXT3:
|
|
68477
|
+
|
|
68478
|
+
blockBytes = 16;
|
|
68479
|
+
dds.format = RGBA_S3TC_DXT3_Format;
|
|
68480
|
+
break;
|
|
68481
|
+
|
|
68482
|
+
case FOURCC_DXT5:
|
|
68483
|
+
|
|
68484
|
+
blockBytes = 16;
|
|
68485
|
+
dds.format = RGBA_S3TC_DXT5_Format;
|
|
68486
|
+
break;
|
|
68487
|
+
|
|
68488
|
+
case FOURCC_ETC1:
|
|
68489
|
+
|
|
68490
|
+
blockBytes = 8;
|
|
68491
|
+
dds.format = RGB_ETC1_Format;
|
|
68492
|
+
break;
|
|
68493
|
+
|
|
68494
|
+
default:
|
|
68495
|
+
|
|
68496
|
+
if ( header[ off_RGBBitCount ] === 32
|
|
68497
|
+
&& header[ off_RBitMask ] & 0xff0000
|
|
68498
|
+
&& header[ off_GBitMask ] & 0xff00
|
|
68499
|
+
&& header[ off_BBitMask ] & 0xff
|
|
68500
|
+
&& header[ off_ABitMask ] & 0xff000000 ) {
|
|
68501
|
+
|
|
68502
|
+
isRGBAUncompressed = true;
|
|
68503
|
+
blockBytes = 64;
|
|
68504
|
+
dds.format = RGBAFormat;
|
|
68505
|
+
|
|
68506
|
+
} else {
|
|
68507
|
+
return dds;
|
|
68508
|
+
|
|
68509
|
+
}
|
|
68510
|
+
|
|
68511
|
+
}
|
|
68512
|
+
|
|
68513
|
+
dds.mipmapCount = 1;
|
|
68514
|
+
|
|
68515
|
+
if ( header[ off_flags ] & DDSD_MIPMAPCOUNT && loadMipmaps !== false ) {
|
|
68516
|
+
|
|
68517
|
+
dds.mipmapCount = Math.max( 1, header[ off_mipmapCount ] );
|
|
68518
|
+
|
|
68519
|
+
}
|
|
68520
|
+
|
|
68521
|
+
const caps2 = header[ off_caps2 ];
|
|
68522
|
+
dds.isCubemap = caps2 & DDSCAPS2_CUBEMAP ? true : false;
|
|
68523
|
+
if ( dds.isCubemap && (
|
|
68524
|
+
! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEX ) ||
|
|
68525
|
+
! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX ) ||
|
|
68526
|
+
! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEY ) ||
|
|
68527
|
+
! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY ) ||
|
|
68528
|
+
! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ ) ||
|
|
68529
|
+
! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ )
|
|
68530
|
+
) ) {
|
|
68531
|
+
return dds;
|
|
68532
|
+
|
|
68533
|
+
}
|
|
68534
|
+
|
|
68535
|
+
dds.width = header[ off_width ];
|
|
68536
|
+
dds.height = header[ off_height ];
|
|
68537
|
+
|
|
68538
|
+
let dataOffset = header[ off_size ] + 4;
|
|
68539
|
+
|
|
68540
|
+
// Extract mipmaps buffers
|
|
68541
|
+
|
|
68542
|
+
const faces = dds.isCubemap ? 6 : 1;
|
|
68543
|
+
|
|
68544
|
+
for ( let face = 0; face < faces; face ++ ) {
|
|
68545
|
+
|
|
68546
|
+
let width = dds.width;
|
|
68547
|
+
let height = dds.height;
|
|
68548
|
+
|
|
68549
|
+
for ( let i = 0; i < dds.mipmapCount; i ++ ) {
|
|
68550
|
+
|
|
68551
|
+
let byteArray, dataLength;
|
|
68552
|
+
|
|
68553
|
+
if ( isRGBAUncompressed ) {
|
|
68554
|
+
|
|
68555
|
+
byteArray = loadARGBMip( buffer, dataOffset, width, height );
|
|
68556
|
+
dataLength = byteArray.length;
|
|
68557
|
+
|
|
68558
|
+
} else {
|
|
68559
|
+
|
|
68560
|
+
dataLength = Math.max( 4, width ) / 4 * Math.max( 4, height ) / 4 * blockBytes;
|
|
68561
|
+
byteArray = new Uint8Array( buffer, dataOffset, dataLength );
|
|
68562
|
+
|
|
68563
|
+
}
|
|
68564
|
+
|
|
68565
|
+
const mipmap = { 'data': byteArray, 'width': width, 'height': height };
|
|
68566
|
+
dds.mipmaps.push( mipmap );
|
|
68567
|
+
|
|
68568
|
+
dataOffset += dataLength;
|
|
68569
|
+
|
|
68570
|
+
width = Math.max( width >> 1, 1 );
|
|
68571
|
+
height = Math.max( height >> 1, 1 );
|
|
68572
|
+
|
|
68573
|
+
}
|
|
68574
|
+
|
|
68575
|
+
}
|
|
68576
|
+
|
|
68577
|
+
return dds;
|
|
68578
|
+
|
|
68579
|
+
}
|
|
68580
|
+
|
|
68581
|
+
}
|
|
68582
|
+
|
|
68583
|
+
/**
|
|
68584
|
+
*
|
|
68585
|
+
* @param {Texture} t
|
|
68586
|
+
* @returns {Texture}
|
|
68587
|
+
*/
|
|
68588
|
+
function cloneTexture(t) {
|
|
68589
|
+
const clone = t.clone();
|
|
68590
|
+
|
|
68591
|
+
//apparently cloned textures need this trick to work
|
|
68592
|
+
clone.needsUpdate = true;
|
|
68593
|
+
|
|
68594
|
+
return clone;
|
|
68595
|
+
}
|
|
68596
|
+
|
|
68597
|
+
function loadDDSTexture(path, success, failure, progress) {
|
|
68598
|
+
function computeByteSize(texture) {
|
|
68599
|
+
let result = 0;
|
|
68600
|
+
const images = texture.image;
|
|
68601
|
+
for (let i = 0; i < images.length; i++) {
|
|
68602
|
+
const image = images[i];
|
|
68603
|
+
const mipmaps = image.mipmaps;
|
|
68604
|
+
for (let j = 0; j < mipmaps.length; j++) {
|
|
68605
|
+
const mipmap = mipmaps[j];
|
|
68606
|
+
/**
|
|
68607
|
+
* @type {Uint8Array}
|
|
68608
|
+
*/
|
|
68609
|
+
const data = mipmap.data;
|
|
68610
|
+
result += data.length;
|
|
68611
|
+
}
|
|
68612
|
+
}
|
|
68613
|
+
return result;
|
|
68614
|
+
}
|
|
68615
|
+
|
|
68616
|
+
const loader = new DDSLoader();
|
|
68617
|
+
loader.load(path, function (texture) {
|
|
68618
|
+
const byteSize = computeByteSize(texture);
|
|
68619
|
+
|
|
68620
|
+
function factory() {
|
|
68621
|
+
return cloneTexture(texture);
|
|
68622
|
+
}
|
|
68623
|
+
|
|
68624
|
+
const asset = new Asset(factory, byteSize);
|
|
68625
|
+
|
|
68626
|
+
success(asset);
|
|
68627
|
+
|
|
68628
|
+
}, progress, failure);
|
|
68629
|
+
}
|
|
68630
|
+
|
|
68631
|
+
const textureLoader = new TextureLoader();
|
|
68632
|
+
|
|
68633
|
+
/**
|
|
68634
|
+
*
|
|
68635
|
+
* @param {Texture} texture
|
|
68636
|
+
* @return {number}
|
|
68637
|
+
*/
|
|
68638
|
+
function computeTextureByteSize(texture) {
|
|
68639
|
+
const image = texture.image;
|
|
68640
|
+
if (image instanceof ImageData) {
|
|
68641
|
+
return image.array.length;
|
|
68642
|
+
} else {
|
|
68643
|
+
//TODO do actual computation
|
|
68644
|
+
//don't know
|
|
68645
|
+
return 1;
|
|
68646
|
+
}
|
|
68647
|
+
}
|
|
68648
|
+
function loadStandardImageTexture(path, success, failure, progress) {
|
|
68649
|
+
|
|
68650
|
+
|
|
68651
|
+
|
|
68652
|
+
textureLoader.load(path, function (texture) {
|
|
68653
|
+
|
|
68654
|
+
texture.flipY = false;
|
|
68655
|
+
|
|
68656
|
+
const byteSize = computeTextureByteSize(texture);
|
|
68657
|
+
|
|
68658
|
+
const asset = new Asset(function () {
|
|
68659
|
+
return cloneTexture(texture);
|
|
68660
|
+
}, byteSize);
|
|
68661
|
+
|
|
68662
|
+
success(asset);
|
|
68663
|
+
}, progress, failure);
|
|
68664
|
+
}
|
|
68665
|
+
|
|
68666
|
+
class TextureAssetLoader extends AssetLoader {
|
|
68667
|
+
load(scope, path, success, failure, progress) {
|
|
68668
|
+
//figure out what kind of a texture it is
|
|
68669
|
+
let fileExtension = computeFileExtension(path);
|
|
68670
|
+
|
|
68671
|
+
if (fileExtension === null) {
|
|
68672
|
+
//check if it's a data path
|
|
68673
|
+
|
|
68674
|
+
const match = path.match(/^data\:image\/([a-zA-Z0-9]+)\;/);
|
|
68675
|
+
|
|
68676
|
+
if (match === null) {
|
|
68677
|
+
throw new Error(`no file extension on path '${path}'`);
|
|
68678
|
+
|
|
68679
|
+
} else {
|
|
68680
|
+
//seems ok
|
|
68681
|
+
fileExtension = match[1];
|
|
68682
|
+
}
|
|
68683
|
+
|
|
68684
|
+
}
|
|
68685
|
+
|
|
68686
|
+
const lowerCaseExtension = fileExtension.toLowerCase();
|
|
68687
|
+
switch (lowerCaseExtension) {
|
|
68688
|
+
case 'dds':
|
|
68689
|
+
loadDDSTexture(path, success, failure, progress);
|
|
68690
|
+
break;
|
|
68691
|
+
case 'png':
|
|
68692
|
+
case 'jpg':
|
|
68693
|
+
loadStandardImageTexture(path, success, failure, progress);
|
|
68694
|
+
break;
|
|
68695
|
+
default:
|
|
68696
|
+
throw new Error(`Unsupported texture file format: '${lowerCaseExtension}'`);
|
|
68697
|
+
|
|
68698
|
+
}
|
|
68699
|
+
}
|
|
68700
|
+
}
|
|
68701
|
+
|
|
68179
68702
|
/**
|
|
68180
68703
|
* Utility class for managing connection between listeners to signals
|
|
68181
68704
|
*/
|
|
@@ -69746,9 +70269,8 @@ class TerrainSystem extends System {
|
|
|
69746
70269
|
|
|
69747
70270
|
const am = this.assetManager;
|
|
69748
70271
|
|
|
69749
|
-
|
|
69750
|
-
|
|
69751
|
-
}
|
|
70272
|
+
await am.tryRegisterLoader('image', new ImageRGBADataLoader());
|
|
70273
|
+
await am.tryRegisterLoader('texture', new TextureAssetLoader());
|
|
69752
70274
|
|
|
69753
70275
|
readyCallback();
|
|
69754
70276
|
}
|
|
@@ -72775,6 +73297,7 @@ class Entity {
|
|
|
72775
73297
|
|
|
72776
73298
|
/**
|
|
72777
73299
|
* Similar to {@link #getComponent}, instead of returning null - throws an exception
|
|
73300
|
+
* @template T
|
|
72778
73301
|
* @param {Class<T>} klass
|
|
72779
73302
|
* @returns {T}
|
|
72780
73303
|
*/
|
|
@@ -85825,6 +86348,23 @@ class AssetManager {
|
|
|
85825
86348
|
return true;
|
|
85826
86349
|
}
|
|
85827
86350
|
|
|
86351
|
+
/**
|
|
86352
|
+
* Will register loader only if none exists for this type
|
|
86353
|
+
* @template T
|
|
86354
|
+
* @param {string} type
|
|
86355
|
+
* @param {AssetLoader<T>} loader
|
|
86356
|
+
* @returns {Promise<boolean>} true if registered , false otherwise
|
|
86357
|
+
*/
|
|
86358
|
+
async tryRegisterLoader(type, loader) {
|
|
86359
|
+
if (this.hasLoaderForType(type)) {
|
|
86360
|
+
return false;
|
|
86361
|
+
}
|
|
86362
|
+
|
|
86363
|
+
await this.registerLoader(type, loader);
|
|
86364
|
+
|
|
86365
|
+
return true;
|
|
86366
|
+
}
|
|
86367
|
+
|
|
85828
86368
|
/**
|
|
85829
86369
|
* @template T
|
|
85830
86370
|
* @param {string} type
|
|
@@ -114122,12 +114662,8 @@ function getOrCreateProxy(proxies, path, signal) {
|
|
|
114122
114662
|
* @param {InputControllerBinding} binding
|
|
114123
114663
|
*/
|
|
114124
114664
|
Proxy.prototype.add = function (binding) {
|
|
114125
|
-
|
|
114126
|
-
|
|
114127
|
-
this.deferred.push(binding);
|
|
114128
|
-
} else {
|
|
114129
|
-
this.registerBinding(binding);
|
|
114130
|
-
}
|
|
114665
|
+
//TODO handle case where binding is added mid-dispatch
|
|
114666
|
+
this.registerBinding(binding);
|
|
114131
114667
|
};
|
|
114132
114668
|
|
|
114133
114669
|
/**
|