@woosh/meep-engine 2.100.2 → 2.101.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.
- package/build/meep.cjs +109 -97
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +109 -97
- package/package.json +1 -1
- package/src/core/binary/downloadUrlAsFile.d.ts.map +1 -1
- package/src/core/binary/downloadUrlAsFile.js +3 -1
- package/src/engine/asset/AssetManager.d.ts.map +1 -1
- package/src/engine/asset/AssetManager.js +6 -1
- package/src/engine/asset/loaders/ArrayBufferLoader.d.ts +2 -1
- package/src/engine/asset/loaders/ArrayBufferLoader.d.ts.map +1 -1
- package/src/engine/asset/loaders/ArrayBufferLoader.js +107 -99
- package/src/engine/graphics/FrameRunner.d.ts +5 -13
- package/src/engine/graphics/FrameRunner.d.ts.map +1 -1
- package/src/engine/graphics/FrameRunner.js +31 -25
- package/src/engine/graphics/texture/sampler/HarmonicDiffusionGrid.d.ts +1 -1
- package/src/engine/graphics/texture/sampler/HarmonicDiffusionGrid.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/HarmonicDiffusionGrid.js +4 -4
- package/src/engine/graphics/texture/sampler/Sampler2D2Canvas.d.ts +1 -2
- package/src/engine/graphics/texture/sampler/Sampler2D2Canvas.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/Sampler2D2Canvas.js +1 -2
- package/src/engine/graphics/texture/sampler/sampler2d_to_uint8_RGBA.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/sampler2d_to_uint8_RGBA.js +8 -0
package/build/meep.module.js
CHANGED
|
@@ -67746,6 +67746,83 @@ class AssetLoader {
|
|
|
67746
67746
|
}
|
|
67747
67747
|
}
|
|
67748
67748
|
|
|
67749
|
+
/**
|
|
67750
|
+
*
|
|
67751
|
+
* @param {Response} input
|
|
67752
|
+
* @param {function} progress
|
|
67753
|
+
* @return {Response}
|
|
67754
|
+
*/
|
|
67755
|
+
function observeResponseProgress(input, progress) {
|
|
67756
|
+
let response = input;
|
|
67757
|
+
|
|
67758
|
+
|
|
67759
|
+
if (typeof ReadableStream === 'undefined' || response.body.getReader === undefined) {
|
|
67760
|
+
|
|
67761
|
+
return response;
|
|
67762
|
+
|
|
67763
|
+
}
|
|
67764
|
+
|
|
67765
|
+
/**
|
|
67766
|
+
* @type {ReadableStreamDefaultReader<Uint8Array>}
|
|
67767
|
+
*/
|
|
67768
|
+
const reader = response.body.getReader();
|
|
67769
|
+
|
|
67770
|
+
const contentLength = response.headers.get('Content-Length');
|
|
67771
|
+
const total = contentLength ? parseInt(contentLength) : 0;
|
|
67772
|
+
let loaded = 0;
|
|
67773
|
+
|
|
67774
|
+
// periodically read data into the new stream tracking while download progress
|
|
67775
|
+
const stream_prototype = {
|
|
67776
|
+
type: "bytes",
|
|
67777
|
+
start(controller) {
|
|
67778
|
+
|
|
67779
|
+
pump();
|
|
67780
|
+
|
|
67781
|
+
function pump() {
|
|
67782
|
+
|
|
67783
|
+
reader.read().then(({ done, value }) => {
|
|
67784
|
+
|
|
67785
|
+
if (done) {
|
|
67786
|
+
// no more data, we're done
|
|
67787
|
+
controller.close();
|
|
67788
|
+
return;
|
|
67789
|
+
}
|
|
67790
|
+
|
|
67791
|
+
loaded += value.byteLength;
|
|
67792
|
+
|
|
67793
|
+
progress(loaded, total);
|
|
67794
|
+
|
|
67795
|
+
controller.enqueue(value);
|
|
67796
|
+
pump();
|
|
67797
|
+
|
|
67798
|
+
});
|
|
67799
|
+
|
|
67800
|
+
}
|
|
67801
|
+
|
|
67802
|
+
}
|
|
67803
|
+
|
|
67804
|
+
};
|
|
67805
|
+
|
|
67806
|
+
/**
|
|
67807
|
+
* @type {ReadableStream}
|
|
67808
|
+
*/
|
|
67809
|
+
let stream;
|
|
67810
|
+
|
|
67811
|
+
try {
|
|
67812
|
+
stream = new ReadableStream(stream_prototype);
|
|
67813
|
+
|
|
67814
|
+
response = new Response(stream);
|
|
67815
|
+
} catch (e) {
|
|
67816
|
+
/*
|
|
67817
|
+
Workaround for Safari bug: "TypeError: ReadableByteStreamController is not implemented"
|
|
67818
|
+
By not wrapping the response we lose the ability to track progress, but that's not a critical issue in most cases
|
|
67819
|
+
*/
|
|
67820
|
+
}
|
|
67821
|
+
|
|
67822
|
+
return response;
|
|
67823
|
+
|
|
67824
|
+
}
|
|
67825
|
+
|
|
67749
67826
|
class ArrayBufferLoader extends AssetLoader {
|
|
67750
67827
|
/**
|
|
67751
67828
|
*
|
|
@@ -67764,7 +67841,13 @@ class ArrayBufferLoader extends AssetLoader {
|
|
|
67764
67841
|
this.__fetch_priority = fetch_priority;
|
|
67765
67842
|
}
|
|
67766
67843
|
|
|
67767
|
-
load(
|
|
67844
|
+
async load(
|
|
67845
|
+
scope,
|
|
67846
|
+
path,
|
|
67847
|
+
success,
|
|
67848
|
+
failure = console.error,
|
|
67849
|
+
progress = noop
|
|
67850
|
+
) {
|
|
67768
67851
|
const coc = this.assetManager !== null ? this.assetManager.crossOriginConfig : CrossOriginConfig.default;
|
|
67769
67852
|
|
|
67770
67853
|
const headers = new Headers();
|
|
@@ -67779,112 +67862,36 @@ class ArrayBufferLoader extends AssetLoader {
|
|
|
67779
67862
|
request.priority = this.__fetch_priority;
|
|
67780
67863
|
}
|
|
67781
67864
|
|
|
67782
|
-
fetch(request)
|
|
67783
|
-
.then(handle_response)
|
|
67784
|
-
.then(response_to_asset)
|
|
67785
|
-
.catch(failure);
|
|
67865
|
+
let response = await fetch(request);
|
|
67786
67866
|
|
|
67787
|
-
|
|
67788
|
-
*
|
|
67789
|
-
* @param {Response} response
|
|
67790
|
-
* @return {Promise<void>}
|
|
67791
|
-
*/
|
|
67792
|
-
async function response_to_asset(response) {
|
|
67793
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
67867
|
+
if (!(response.status === 200 || response.status === 0)) {
|
|
67794
67868
|
|
|
67795
|
-
|
|
67796
|
-
function () {
|
|
67797
|
-
return arrayBuffer;
|
|
67798
|
-
},
|
|
67799
|
-
arrayBuffer.byteSize
|
|
67800
|
-
);
|
|
67869
|
+
throw Error(`fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`);
|
|
67801
67870
|
|
|
67802
|
-
success(asset);
|
|
67803
67871
|
}
|
|
67804
67872
|
|
|
67805
|
-
|
|
67806
|
-
|
|
67807
|
-
* @param {Response} response
|
|
67808
|
-
* @return {Response}
|
|
67809
|
-
*/
|
|
67810
|
-
function handle_response(response) {
|
|
67811
|
-
if (!(response.status === 200 || response.status === 0)) {
|
|
67812
|
-
|
|
67813
|
-
throw Error(`fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`);
|
|
67814
|
-
|
|
67815
|
-
}
|
|
67816
|
-
|
|
67817
|
-
// Some browsers return HTTP Status 0 when using non-http protocol
|
|
67818
|
-
// e.g. 'file://' or 'data://'. Handle as success.
|
|
67819
|
-
|
|
67820
|
-
if (response.status === 0) ;
|
|
67821
|
-
|
|
67822
|
-
if (typeof ReadableStream === 'undefined' || response.body.getReader === undefined) {
|
|
67823
|
-
|
|
67824
|
-
return response;
|
|
67825
|
-
|
|
67826
|
-
}
|
|
67827
|
-
|
|
67828
|
-
/**
|
|
67829
|
-
* @type {ReadableStreamDefaultReader<Uint8Array>}
|
|
67830
|
-
*/
|
|
67831
|
-
const reader = response.body.getReader();
|
|
67832
|
-
|
|
67833
|
-
const contentLength = response.headers.get('Content-Length');
|
|
67834
|
-
const total = contentLength ? parseInt(contentLength) : 0;
|
|
67835
|
-
let loaded = 0;
|
|
67836
|
-
|
|
67837
|
-
// periodically read data into the new stream tracking while download progress
|
|
67838
|
-
const stream_prototype = {
|
|
67839
|
-
type: "bytes",
|
|
67840
|
-
start(controller) {
|
|
67841
|
-
|
|
67842
|
-
pump();
|
|
67843
|
-
|
|
67844
|
-
function pump() {
|
|
67845
|
-
|
|
67846
|
-
reader.read().then(({ done, value }) => {
|
|
67847
|
-
|
|
67848
|
-
if (done) {
|
|
67849
|
-
// no more data, we're done
|
|
67850
|
-
controller.close();
|
|
67851
|
-
return;
|
|
67852
|
-
}
|
|
67853
|
-
|
|
67854
|
-
loaded += value.byteLength;
|
|
67873
|
+
// Some browsers return HTTP Status 0 when using non-http protocol
|
|
67874
|
+
// e.g. 'file://' or 'data://'. Handle as success.
|
|
67855
67875
|
|
|
67856
|
-
|
|
67876
|
+
if (response.status === 0) ;
|
|
67857
67877
|
|
|
67858
|
-
|
|
67859
|
-
|
|
67860
|
-
|
|
67861
|
-
|
|
67862
|
-
|
|
67863
|
-
}
|
|
67864
|
-
|
|
67865
|
-
}
|
|
67866
|
-
|
|
67867
|
-
};
|
|
67868
|
-
|
|
67869
|
-
/**
|
|
67870
|
-
* @type {ReadableStream}
|
|
67871
|
-
*/
|
|
67872
|
-
let stream;
|
|
67878
|
+
try {
|
|
67879
|
+
response = observeResponseProgress(response, progress);
|
|
67880
|
+
} catch (e) {
|
|
67881
|
+
}
|
|
67873
67882
|
|
|
67874
|
-
|
|
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
|
-
}
|
|
67883
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
67883
67884
|
|
|
67884
|
-
|
|
67885
|
-
|
|
67885
|
+
const asset = new Asset(
|
|
67886
|
+
function () {
|
|
67887
|
+
return arrayBuffer;
|
|
67888
|
+
},
|
|
67889
|
+
arrayBuffer.byteSize
|
|
67890
|
+
);
|
|
67886
67891
|
|
|
67892
|
+
success(asset);
|
|
67887
67893
|
|
|
67894
|
+
return asset;
|
|
67888
67895
|
}
|
|
67889
67896
|
}
|
|
67890
67897
|
|
|
@@ -86242,7 +86249,12 @@ class AssetManager {
|
|
|
86242
86249
|
try {
|
|
86243
86250
|
|
|
86244
86251
|
|
|
86245
|
-
loader.load(scope, full_path, success, failure, progress);
|
|
86252
|
+
const result = loader.load(scope, full_path, success, failure, progress);
|
|
86253
|
+
|
|
86254
|
+
if (result instanceof Promise) {
|
|
86255
|
+
// allow promise responses
|
|
86256
|
+
result.catch(failure);
|
|
86257
|
+
}
|
|
86246
86258
|
|
|
86247
86259
|
} catch (e) {
|
|
86248
86260
|
failure(e);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadUrlAsFile.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/downloadUrlAsFile.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,uCAHW,MAAM,YACN,MAAM,
|
|
1
|
+
{"version":3,"file":"downloadUrlAsFile.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/downloadUrlAsFile.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,uCAHW,MAAM,YACN,MAAM,QAWhB"}
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
* @param {string} filename
|
|
5
5
|
*/
|
|
6
6
|
export function downloadUrlAsFile(url, filename) {
|
|
7
|
-
const elem =
|
|
7
|
+
const elem = document.createElement('a');
|
|
8
8
|
elem.href = url;
|
|
9
9
|
elem.download = filename;
|
|
10
|
+
|
|
11
|
+
// only elements on the dom are clickable, so we add it
|
|
10
12
|
document.body.appendChild(elem);
|
|
11
13
|
elem.click();
|
|
12
14
|
document.body.removeChild(elem);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/asset/AssetManager.js"],"names":[],"mappings":"AAiDA;;;;GAIG;AACH;IAgII;;;;;OAKG;IACH,oCAJW,GAAG,EAYb;IA7ID;;;;OAIG;IACH,eAEG;IAEH;;;OAGG;IACH,aAFU,YAAY,gBAAgB,EAAE,YAAY,CAAC,CAER;IAe7C;;;;;;OAMG;IACH,kBAFU,MAAM,CAEY;IAyB5B;;;;OAIG;IACH,iBAAc;IAEd;;;OAGG;IACH,mBAFU,iBAAiB,CAEiB;IAwE5C,gBAQC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACL,QAAQ,IAAI,CAAC,CAexB;IAED;;;;;OAKG;IACH,oCAFa,OAAO,CAOnB;IAED;;OAEG;IACH,cAEC;IAED,8BAEC;IAED;;;;;;OAMG;IACH,4DAJW,iBAAiB,GAEf,cAAc,CAY1B;IAED;;;;;;;;;OASG;IACH,qFAsCC;IAED;;;;;OAKG;IACH,aAJW,MAAM,QACN,MAAM,sBAehB;
|
|
1
|
+
{"version":3,"file":"AssetManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/asset/AssetManager.js"],"names":[],"mappings":"AAiDA;;;;GAIG;AACH;IAgII;;;;;OAKG;IACH,oCAJW,GAAG,EAYb;IA7ID;;;;OAIG;IACH,eAEG;IAEH;;;OAGG;IACH,aAFU,YAAY,gBAAgB,EAAE,YAAY,CAAC,CAER;IAe7C;;;;;;OAMG;IACH,kBAFU,MAAM,CAEY;IAyB5B;;;;OAIG;IACH,iBAAc;IAEd;;;OAGG;IACH,mBAFU,iBAAiB,CAEiB;IAwE5C,gBAQC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACL,QAAQ,IAAI,CAAC,CAexB;IAED;;;;;OAKG;IACH,oCAFa,OAAO,CAOnB;IAED;;OAEG;IACH,cAEC;IAED,8BAEC;IAED;;;;;;OAMG;IACH,4DAJW,iBAAiB,GAEf,cAAc,CAY1B;IAED;;;;;;;;;OASG;IACH,qFAsCC;IAED;;;;;OAKG;IACH,aAJW,MAAM,QACN,MAAM,sBAehB;IA2QD;;;;;OAKG;IACH,sBA2BC;IAGD;;;;OAIG;IACH,uBAHW,MAAM,GACL,OAAO,CAIlB;IAED;;;;OAIG;IACH,sBAHW,MAAM,GACJ,wBAAY,SAAS,CAMjC;IAaD;;;;OAIG;IACH,+BAHW,MAAM,4CAqBhB;IAED;;;;OAIG;IACH,iCAHW,MAAM,+CAyBhB;IAED;;;;;;OAMG;IACH,6BAJW,MAAM,kCAEJ,QAAQ,OAAO,CAAC,CAU5B;IAED;;;;;OAKG;IACH,0BAJW,MAAM,iEAwChB;IAED;;;OAGG;IACH,uBAFW,MAAM,iBAkBhB;IAED;;;;;;OAMG;IACH,yCAFa,aAAS,IAAI,CAYzB;IAED;;;;;OAKG;IACH,eAJW,MAAM,QACN,MAAM,GACJ,OAAO,CAMnB;IAED;;;;OAIG;IACH,2BAHW,MAAM,GACL,mBAAiB,CAa5B;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACL,gBAAgB,GAAC,SAAS,CAQrC;IAED;;;;;OAKG;IACH,mBAJW,MAAM,QACN,MAAM,QACN,MAAM,QAUhB;IAGL;;;OAGG;IACH,yBAFU,OAAO,CAEoB;;CANpC;4BA72B2B,0CAA0C;iCAOrC,uBAAuB;6BAM3B,mBAAmB;kCAFd,6BAA6B;kCAD7B,wBAAwB;4BAE9B,0BAA0B"}
|
|
@@ -591,7 +591,12 @@ export class AssetManager {
|
|
|
591
591
|
try {
|
|
592
592
|
|
|
593
593
|
|
|
594
|
-
loader.load(scope, full_path, success, failure, progress);
|
|
594
|
+
const result = loader.load(scope, full_path, success, failure, progress);
|
|
595
|
+
|
|
596
|
+
if (result instanceof Promise) {
|
|
597
|
+
// allow promise responses
|
|
598
|
+
result.catch(failure);
|
|
599
|
+
}
|
|
595
600
|
|
|
596
601
|
} catch (e) {
|
|
597
602
|
console.error(`Loader failed on invocation. path=${path}, type=${type}`, 'Loader exception: ', e);
|
|
@@ -13,8 +13,9 @@ export class ArrayBufferLoader extends AssetLoader<any, any> {
|
|
|
13
13
|
load(scope: any, path: any, success: any, failure?: {
|
|
14
14
|
(...data: any[]): void;
|
|
15
15
|
(message?: any, ...optionalParams: any[]): void;
|
|
16
|
-
}, progress?: typeof noop):
|
|
16
|
+
}, progress?: typeof noop): Promise<Asset<any>>;
|
|
17
17
|
}
|
|
18
18
|
import { AssetLoader } from "./AssetLoader.js";
|
|
19
19
|
import { noop } from "../../../core/function/noop.js";
|
|
20
|
+
import { Asset } from "../Asset.js";
|
|
20
21
|
//# sourceMappingURL=ArrayBufferLoader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArrayBufferLoader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/loaders/ArrayBufferLoader.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ArrayBufferLoader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/loaders/ArrayBufferLoader.js"],"names":[],"mappings":"AAoFA;IACI;;;OAGG;IACH,iCAFW,MAAM,GAAC,KAAK,GAAC,MAAM,EAa7B;IANG;;;;OAIG;IACH,yBAAsC;IAG1C;;;oDAwDC;CACJ;4BA3J2B,kBAAkB;qBAJzB,gCAAgC;sBAC/B,aAAa"}
|
|
@@ -4,6 +4,84 @@ import { CrossOriginConfig } from "../CORS/CrossOriginConfig.js";
|
|
|
4
4
|
import { CrossOriginKind } from "../CORS/CrossOriginKind.js";
|
|
5
5
|
import { AssetLoader } from "./AssetLoader.js";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {Response} input
|
|
10
|
+
* @param {function} progress
|
|
11
|
+
* @return {Response}
|
|
12
|
+
*/
|
|
13
|
+
function observeResponseProgress(input, progress) {
|
|
14
|
+
let response = input
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
if (typeof ReadableStream === 'undefined' || response.body.getReader === undefined) {
|
|
18
|
+
|
|
19
|
+
return response;
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @type {ReadableStreamDefaultReader<Uint8Array>}
|
|
25
|
+
*/
|
|
26
|
+
const reader = response.body.getReader();
|
|
27
|
+
|
|
28
|
+
const contentLength = response.headers.get('Content-Length');
|
|
29
|
+
const total = contentLength ? parseInt(contentLength) : 0;
|
|
30
|
+
let loaded = 0;
|
|
31
|
+
|
|
32
|
+
// periodically read data into the new stream tracking while download progress
|
|
33
|
+
const stream_prototype = {
|
|
34
|
+
type: "bytes",
|
|
35
|
+
start(controller) {
|
|
36
|
+
|
|
37
|
+
pump();
|
|
38
|
+
|
|
39
|
+
function pump() {
|
|
40
|
+
|
|
41
|
+
reader.read().then(({ done, value }) => {
|
|
42
|
+
|
|
43
|
+
if (done) {
|
|
44
|
+
// no more data, we're done
|
|
45
|
+
controller.close();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
loaded += value.byteLength;
|
|
50
|
+
|
|
51
|
+
progress(loaded, total);
|
|
52
|
+
|
|
53
|
+
controller.enqueue(value);
|
|
54
|
+
pump();
|
|
55
|
+
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @type {ReadableStream}
|
|
66
|
+
*/
|
|
67
|
+
let stream;
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
stream = new ReadableStream(stream_prototype);
|
|
71
|
+
|
|
72
|
+
response = new Response(stream);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
/*
|
|
75
|
+
Workaround for Safari bug: "TypeError: ReadableByteStreamController is not implemented"
|
|
76
|
+
By not wrapping the response we lose the ability to track progress, but that's not a critical issue in most cases
|
|
77
|
+
*/
|
|
78
|
+
console.warn(e);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return response;
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
7
85
|
export class ArrayBufferLoader extends AssetLoader {
|
|
8
86
|
/**
|
|
9
87
|
*
|
|
@@ -22,7 +100,13 @@ export class ArrayBufferLoader extends AssetLoader {
|
|
|
22
100
|
this.__fetch_priority = fetch_priority;
|
|
23
101
|
}
|
|
24
102
|
|
|
25
|
-
load(
|
|
103
|
+
async load(
|
|
104
|
+
scope,
|
|
105
|
+
path,
|
|
106
|
+
success,
|
|
107
|
+
failure = console.error,
|
|
108
|
+
progress = noop
|
|
109
|
+
) {
|
|
26
110
|
const coc = this.assetManager !== null ? this.assetManager.crossOriginConfig : CrossOriginConfig.default;
|
|
27
111
|
|
|
28
112
|
const headers = new Headers();
|
|
@@ -37,116 +121,40 @@ export class ArrayBufferLoader extends AssetLoader {
|
|
|
37
121
|
request.priority = this.__fetch_priority;
|
|
38
122
|
}
|
|
39
123
|
|
|
40
|
-
fetch(request)
|
|
41
|
-
.then(handle_response)
|
|
42
|
-
.then(response_to_asset)
|
|
43
|
-
.catch(failure);
|
|
124
|
+
let response = await fetch(request);
|
|
44
125
|
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
* @param {Response} response
|
|
48
|
-
* @return {Promise<void>}
|
|
49
|
-
*/
|
|
50
|
-
async function response_to_asset(response) {
|
|
51
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
126
|
+
if (!(response.status === 200 || response.status === 0)) {
|
|
52
127
|
|
|
53
|
-
|
|
54
|
-
function () {
|
|
55
|
-
return arrayBuffer;
|
|
56
|
-
},
|
|
57
|
-
arrayBuffer.byteSize
|
|
58
|
-
);
|
|
128
|
+
throw Error(`fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`);
|
|
59
129
|
|
|
60
|
-
success(asset);
|
|
61
130
|
}
|
|
62
131
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
* @param {Response} response
|
|
66
|
-
* @return {Response}
|
|
67
|
-
*/
|
|
68
|
-
function handle_response(response) {
|
|
69
|
-
if (!(response.status === 200 || response.status === 0)) {
|
|
70
|
-
|
|
71
|
-
throw Error(`fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`);
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Some browsers return HTTP Status 0 when using non-http protocol
|
|
76
|
-
// e.g. 'file://' or 'data://'. Handle as success.
|
|
77
|
-
|
|
78
|
-
if (response.status === 0) {
|
|
79
|
-
|
|
80
|
-
console.warn('HTTP Status 0 received.');
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (typeof ReadableStream === 'undefined' || response.body.getReader === undefined) {
|
|
85
|
-
|
|
86
|
-
return response;
|
|
87
|
-
|
|
88
|
-
}
|
|
132
|
+
// Some browsers return HTTP Status 0 when using non-http protocol
|
|
133
|
+
// e.g. 'file://' or 'data://'. Handle as success.
|
|
89
134
|
|
|
90
|
-
|
|
91
|
-
* @type {ReadableStreamDefaultReader<Uint8Array>}
|
|
92
|
-
*/
|
|
93
|
-
const reader = response.body.getReader();
|
|
135
|
+
if (response.status === 0) {
|
|
94
136
|
|
|
95
|
-
|
|
96
|
-
const total = contentLength ? parseInt(contentLength) : 0;
|
|
97
|
-
let loaded = 0;
|
|
137
|
+
console.warn('HTTP Status 0 received.');
|
|
98
138
|
|
|
99
|
-
|
|
100
|
-
const stream_prototype = {
|
|
101
|
-
type: "bytes",
|
|
102
|
-
start(controller) {
|
|
103
|
-
|
|
104
|
-
pump();
|
|
105
|
-
|
|
106
|
-
function pump() {
|
|
107
|
-
|
|
108
|
-
reader.read().then(({ done, value }) => {
|
|
109
|
-
|
|
110
|
-
if (done) {
|
|
111
|
-
// no more data, we're done
|
|
112
|
-
controller.close();
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
loaded += value.byteLength;
|
|
117
|
-
|
|
118
|
-
progress(loaded, total);
|
|
119
|
-
|
|
120
|
-
controller.enqueue(value);
|
|
121
|
-
pump();
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
};
|
|
139
|
+
}
|
|
130
140
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
try {
|
|
142
|
+
response = observeResponseProgress(response, progress);
|
|
143
|
+
} catch (e) {
|
|
144
|
+
console.warn('Failed to wrap response');
|
|
145
|
+
}
|
|
135
146
|
|
|
136
|
-
|
|
137
|
-
stream = new ReadableStream(stream_prototype);
|
|
138
|
-
} catch (e) {
|
|
139
|
-
/*
|
|
140
|
-
Workaround for Safari bug: "TypeError: ReadableByteStreamController is not implemented"
|
|
141
|
-
By not wrapping the response we lose the ability to track progress, but that's not a critical issue in most cases
|
|
142
|
-
*/
|
|
143
|
-
console.warn(e);
|
|
144
|
-
return response;
|
|
145
|
-
}
|
|
147
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
146
148
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
const asset = new Asset(
|
|
150
|
+
function () {
|
|
151
|
+
return arrayBuffer;
|
|
152
|
+
},
|
|
153
|
+
arrayBuffer.byteSize
|
|
154
|
+
);
|
|
149
155
|
|
|
156
|
+
success(asset);
|
|
150
157
|
|
|
158
|
+
return asset;
|
|
151
159
|
}
|
|
152
160
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Fires a given function every frame. Typical usage is to create an instance, invoke {@link #startup} and once no longer required - invoke {@link #shutdown}
|
|
3
|
+
* Wraps {@link requestAnimationFrame}
|
|
3
4
|
*/
|
|
4
5
|
export class FrameRunner {
|
|
5
6
|
/**
|
|
@@ -13,22 +14,12 @@ export class FrameRunner {
|
|
|
13
14
|
*/
|
|
14
15
|
action: Function;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @type {boolean}
|
|
18
|
-
*/
|
|
19
|
-
running: boolean;
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* @type {number}
|
|
23
|
-
*/
|
|
24
|
-
animationFrameId: number;
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
17
|
+
* Begins animation loop. Does nothing and returns false if already running.
|
|
27
18
|
* @returns {boolean}
|
|
28
19
|
*/
|
|
29
20
|
startup(): boolean;
|
|
30
21
|
/**
|
|
31
|
-
*
|
|
22
|
+
* Stops animation loop. Does nothing and returns false if not currently running.
|
|
32
23
|
* @returns {boolean}
|
|
33
24
|
*/
|
|
34
25
|
shutdown(): boolean;
|
|
@@ -37,5 +28,6 @@ export class FrameRunner {
|
|
|
37
28
|
* @returns {boolean}
|
|
38
29
|
*/
|
|
39
30
|
isRunning(): boolean;
|
|
31
|
+
#private;
|
|
40
32
|
}
|
|
41
33
|
//# sourceMappingURL=FrameRunner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrameRunner.d.ts","sourceRoot":"","sources":["../../../../src/engine/graphics/FrameRunner.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FrameRunner.d.ts","sourceRoot":"","sources":["../../../../src/engine/graphics/FrameRunner.js"],"names":[],"mappings":"AAMA;;;GAGG;AACH;IAYI;;;OAGG;IACH,8BAMC;IALG;;;OAGG;IACH,iBAAoB;IAGxB;;;OAGG;IACH,WAFa,OAAO,CA2BnB;IAED;;;OAGG;IACH,YAFa,OAAO,CAiBnB;IAED;;;OAGG;IACH,aAFa,OAAO,CAInB;;CACJ"}
|