@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
65 lines (64 loc) • 2.08 kB
JavaScript
;
import { CoreUserAgent } from "../UserAgent";
import { CoreBaseLoader } from "./_Base";
export var GeometryFormat = /* @__PURE__ */ ((GeometryFormat2) => {
GeometryFormat2["AUTO"] = "auto";
GeometryFormat2["JSON"] = "json";
return GeometryFormat2;
})(GeometryFormat || {});
export const GEOMETRY_FORMATS = ["auto" /* AUTO */, "json" /* JSON */];
const _CoreLoaderGeometry = class extends CoreBaseLoader {
constructor(_options, _node) {
super(_options.url, _node);
this._options = _options;
this._node = _node;
}
static setMaxConcurrentLoadsCount(method) {
this._maxConcurrentLoadsCountMethod = method;
}
static _initMaxConcurrentLoadsCount() {
if (this._maxConcurrentLoadsCountMethod) {
return this._maxConcurrentLoadsCountMethod();
}
return CoreUserAgent.isChrome() ? 4 : 1;
}
static _initConcurrentLoadsDelay() {
return CoreUserAgent.isChrome() ? 1 : 10;
}
// public static override_max_concurrent_loads_count(count: number) {
// this.MAX_CONCURRENT_LOADS_COUNT = count;
// }
static incrementInProgressLoadsCount() {
this._inProgressLoadsCount++;
}
static decrementInProgressLoadsCount(url, object) {
this._inProgressLoadsCount--;
const queuedResolve = this._queue.pop();
if (queuedResolve) {
const delay = this.CONCURRENT_LOADS_DELAY;
setTimeout(() => {
queuedResolve();
}, delay);
}
this._runOnAssetLoadedCallbacks(url, object);
}
static async waitForMaxConcurrentLoadsQueueFreed() {
if (this._inProgressLoadsCount <= this.MAX_CONCURRENT_LOADS_COUNT) {
return;
} else {
return new Promise((resolve) => {
this._queue.push(resolve);
});
}
}
};
export let CoreLoaderGeometry = _CoreLoaderGeometry;
//
//
// CONCURRENT LOADS
//
//
CoreLoaderGeometry.MAX_CONCURRENT_LOADS_COUNT = _CoreLoaderGeometry._initMaxConcurrentLoadsCount();
CoreLoaderGeometry.CONCURRENT_LOADS_DELAY = _CoreLoaderGeometry._initConcurrentLoadsDelay();
CoreLoaderGeometry._inProgressLoadsCount = 0;
CoreLoaderGeometry._queue = [];