rayzee 7.25.0 → 7.26.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/dist/rayzee.es.js +319 -205
- package/dist/rayzee.umd.js +4 -4
- package/package.json +1 -1
- package/src/PathTracerApp.js +193 -15
- package/src/Processor/AssetLoader.js +11 -1
- package/src/Processor/SceneMetadata.js +123 -0
- package/src/index.js +3 -0
- package/src/managers/EnvironmentManager.js +34 -2
package/dist/rayzee.es.js
CHANGED
|
@@ -2010,11 +2010,17 @@ var ea = class {
|
|
|
2010
2010
|
let e = this.scene.environment, t = this.callbacks.getSceneTextureNodes?.();
|
|
2011
2011
|
t && e && t.envTex && (t.envTex.value = e), e && !e._isGeneratedProcedural && this.uniforms.set("hasSun", 0);
|
|
2012
2012
|
}
|
|
2013
|
-
async setEnvironmentMap(e) {
|
|
2014
|
-
let
|
|
2015
|
-
e &&
|
|
2016
|
-
let
|
|
2017
|
-
|
|
2013
|
+
async setEnvironmentMap(e, { buildCDF: t = !0 } = {}) {
|
|
2014
|
+
let n = this.environmentTexture;
|
|
2015
|
+
e && n && n !== e && n !== this._envPlaceholder && n !== this._previousHDRI && n.dispose?.(), this.scene.environment = e, this.setEnvironmentTexture(e), e ? t && await this.buildEnvironmentCDF() : (this._updateCDFTexture(), this.uniforms.set("envTotalSum", 0), this.uniforms.set("envCompensationDelta", 0));
|
|
2016
|
+
let r = this.callbacks.getSceneTextureNodes?.();
|
|
2017
|
+
r && e && r.envTex && (r.envTex.value = e), e && !e._isGeneratedProcedural && this.uniforms.set("hasSun", 0), this._notifyReset();
|
|
2018
|
+
}
|
|
2019
|
+
beginHDRI(e = null) {
|
|
2020
|
+
this._previousHDRI && this._previousHDRI !== e && this._previousHDRI.dispose?.(), this._previousHDRI = null, this.envParams.mode = "hdri";
|
|
2021
|
+
}
|
|
2022
|
+
async applyHDRI(e, { buildCDF: t = !0 } = {}) {
|
|
2023
|
+
this.beginHDRI(e), await this.setEnvironmentMap(e, { buildCDF: t });
|
|
2018
2024
|
}
|
|
2019
2025
|
async generateGradientTexture() {
|
|
2020
2026
|
this.simpleSkyRenderer ||= new ta(512, 256);
|
|
@@ -14335,8 +14341,62 @@ async function kp(e) {
|
|
|
14335
14341
|
};
|
|
14336
14342
|
}
|
|
14337
14343
|
//#endregion
|
|
14344
|
+
//#region src/Processor/SceneMetadata.js
|
|
14345
|
+
var Ap = [
|
|
14346
|
+
"sourceFile",
|
|
14347
|
+
"url",
|
|
14348
|
+
"file"
|
|
14349
|
+
];
|
|
14350
|
+
function jp(e) {
|
|
14351
|
+
if (typeof e == "string") try {
|
|
14352
|
+
let t = JSON.parse(e);
|
|
14353
|
+
return t && typeof t == "object" ? t : null;
|
|
14354
|
+
} catch {
|
|
14355
|
+
return null;
|
|
14356
|
+
}
|
|
14357
|
+
return e && typeof e == "object" ? e : null;
|
|
14358
|
+
}
|
|
14359
|
+
function Mp(e) {
|
|
14360
|
+
let t = typeof e == "string" ? parseFloat(e) : e;
|
|
14361
|
+
return Number.isFinite(t) ? t : void 0;
|
|
14362
|
+
}
|
|
14363
|
+
function Np(e) {
|
|
14364
|
+
let t = jp(e);
|
|
14365
|
+
if (!t) return null;
|
|
14366
|
+
let n = jp(t.rayzee);
|
|
14367
|
+
return n && n.environment !== void 0 ? n : t.environment === void 0 ? null : t;
|
|
14368
|
+
}
|
|
14369
|
+
function Pp(e) {
|
|
14370
|
+
let t = jp(e);
|
|
14371
|
+
if (!t) return null;
|
|
14372
|
+
let n = Ap.map((e) => t[e]).find((e) => typeof e == "string" && e.trim());
|
|
14373
|
+
if (!n) return null;
|
|
14374
|
+
let r = Mp(t.rotation), i = Mp(t.intensity), a = { sourceFile: n.trim() };
|
|
14375
|
+
return r !== void 0 && (a.rotation = r), i !== void 0 && (a.intensity = Math.max(0, i)), a;
|
|
14376
|
+
}
|
|
14377
|
+
function Fp(e) {
|
|
14378
|
+
let t = Np(e);
|
|
14379
|
+
if (!t) return null;
|
|
14380
|
+
let n = Pp(t.environment);
|
|
14381
|
+
return n ? { environment: n } : null;
|
|
14382
|
+
}
|
|
14383
|
+
function Ip(e) {
|
|
14384
|
+
if (!e) return null;
|
|
14385
|
+
let t = [
|
|
14386
|
+
e.userData,
|
|
14387
|
+
e.asset?.extras,
|
|
14388
|
+
e.scene?.userData
|
|
14389
|
+
];
|
|
14390
|
+
Array.isArray(e.scenes) && t.push(...e.scenes.map((e) => e?.userData));
|
|
14391
|
+
for (let e of t) {
|
|
14392
|
+
let t = Fp(e);
|
|
14393
|
+
if (t) return t;
|
|
14394
|
+
}
|
|
14395
|
+
return null;
|
|
14396
|
+
}
|
|
14397
|
+
//#endregion
|
|
14338
14398
|
//#region src/Processor/AssetLoader.js
|
|
14339
|
-
var
|
|
14399
|
+
var Lp = {
|
|
14340
14400
|
glb: {
|
|
14341
14401
|
type: "model",
|
|
14342
14402
|
name: "GLB (GLTF Binary)"
|
|
@@ -14413,9 +14473,9 @@ var Ap = {
|
|
|
14413
14473
|
type: "archive",
|
|
14414
14474
|
name: "ZIP Archive"
|
|
14415
14475
|
}
|
|
14416
|
-
},
|
|
14476
|
+
}, Rp = /\.(usd|usda|usdc)$/i, zp = /\.(png|jpg|jpeg|avif)$/i, Bp = class e extends lt {
|
|
14417
14477
|
constructor(e, t, n) {
|
|
14418
|
-
super(), this.scene = e, this.camera = t, this.controls = n, this.targetModel = null, this._externalModel = null, this.floorPlane = null, this.sceneScale = 1, this.loaderCache = {}, this.uploadedFileInfo = null, this.animations = [], this.renderer = null, this._loadingManager = new _t(), this._loadCancelled = !1;
|
|
14478
|
+
super(), this.scene = e, this.camera = t, this.controls = n, this.targetModel = null, this._externalModel = null, this.floorPlane = null, this.sceneScale = 1, this.loaderCache = {}, this.uploadedFileInfo = null, this.animations = [], this.renderer = null, this.sceneMetadata = null, this._loadingManager = new _t(), this._loadCancelled = !1;
|
|
14419
14479
|
}
|
|
14420
14480
|
cancelActiveLoad() {
|
|
14421
14481
|
this._loadCancelled = !0, this._loadingManager.abort();
|
|
@@ -14453,13 +14513,13 @@ var Ap = {
|
|
|
14453
14513
|
return typeof e == "string" && /^https?:/i.test(e);
|
|
14454
14514
|
}
|
|
14455
14515
|
releaseTargetModel() {
|
|
14456
|
-
this.targetModel && (this.targetModel === this._externalModel ? this.targetModel.parent?.remove(this.targetModel) : Cr(this.targetModel), this.targetModel = null, this._externalModel = null, this.animations = []);
|
|
14516
|
+
this.sceneMetadata = null, this.targetModel && (this.targetModel === this._externalModel ? this.targetModel.parent?.remove(this.targetModel) : Cr(this.targetModel), this.targetModel = null, this._externalModel = null, this.animations = []);
|
|
14457
14517
|
}
|
|
14458
14518
|
setRenderer(e) {
|
|
14459
14519
|
this.renderer = e;
|
|
14460
14520
|
}
|
|
14461
14521
|
getFileFormat(e) {
|
|
14462
|
-
return
|
|
14522
|
+
return Lp[e.split(".").pop().toLowerCase()] || null;
|
|
14463
14523
|
}
|
|
14464
14524
|
readFileAsArrayBuffer(e) {
|
|
14465
14525
|
return new Promise((t, n) => {
|
|
@@ -14556,7 +14616,9 @@ var Ap = {
|
|
|
14556
14616
|
}
|
|
14557
14617
|
return t.generateMipmaps = !0, this.applyEnvironmentToScene(t), this.dispatchEvent({
|
|
14558
14618
|
type: "load",
|
|
14559
|
-
texture: t
|
|
14619
|
+
texture: t,
|
|
14620
|
+
url: e,
|
|
14621
|
+
filename: e.split(/[?#]/)[0].split("/").pop()
|
|
14560
14622
|
}), t;
|
|
14561
14623
|
} catch (t) {
|
|
14562
14624
|
throw this._isCancellation(t) ? this._cancellationError() : (console.error("Error loading environment:", t), this.dispatchEvent({
|
|
@@ -14710,24 +14772,24 @@ var Ap = {
|
|
|
14710
14772
|
}
|
|
14711
14773
|
for (let t in e) {
|
|
14712
14774
|
let n = t.split(".").pop().toLowerCase();
|
|
14713
|
-
if (
|
|
14775
|
+
if (Lp[n] && Lp[n].type === "model") return Rp.test(t) ? await this.loadUSDHierarchyFromZip(e) : (console.log(`Loading model file from ZIP: ${t}`), await this.loadModelFromZipEntry(e[t], t, n, e));
|
|
14714
14776
|
}
|
|
14715
14777
|
throw Error("No supported model files found in the ZIP archive");
|
|
14716
14778
|
}
|
|
14717
14779
|
async loadUSDHierarchyFromZip(t) {
|
|
14718
|
-
let n = Object.keys(t).filter((e) =>
|
|
14780
|
+
let n = Object.keys(t).filter((e) => Rp.test(e));
|
|
14719
14781
|
if (n.length === 0) throw Error("No USD layers found in the ZIP archive");
|
|
14720
14782
|
let r = e._pickUSDRootLayer(n);
|
|
14721
14783
|
console.log(`Loading USD scene from ZIP: ${r} (${n.length} layers)`);
|
|
14722
14784
|
let i = { [r]: [t[r], { level: 0 }] };
|
|
14723
|
-
for (let e of Object.keys(t)) e !== r && (
|
|
14785
|
+
for (let e of Object.keys(t)) e !== r && (Rp.test(e) || zp.test(e)) && (i[e] = [t[e], { level: 0 }]);
|
|
14724
14786
|
return await this.loadUSDFromArrayBuffer(yn(i), r);
|
|
14725
14787
|
}
|
|
14726
14788
|
static _pickUSDRootLayer(e) {
|
|
14727
14789
|
let t = (e) => e.split("/").length, n = Math.min(...e.map(t)), r = e.filter((e) => t(e) === n);
|
|
14728
14790
|
return r.find((e) => {
|
|
14729
14791
|
let t = e.split("/");
|
|
14730
|
-
return t.length > 1 && t[t.length - 1].replace(
|
|
14792
|
+
return t.length > 1 && t[t.length - 1].replace(Rp, "") === t[t.length - 2];
|
|
14731
14793
|
}) || r[0];
|
|
14732
14794
|
}
|
|
14733
14795
|
async loadModelFromZipEntry(e, t, n, r) {
|
|
@@ -14794,7 +14856,7 @@ var Ap = {
|
|
|
14794
14856
|
try {
|
|
14795
14857
|
return await new Promise((t, n) => {
|
|
14796
14858
|
o.parse(e, "", (e) => {
|
|
14797
|
-
this.releaseTargetModel(), this.targetModel = e.scene, this.onModelLoad(this.targetModel).then(() => t(e));
|
|
14859
|
+
this.releaseTargetModel(), this.targetModel = e.scene, this.sceneMetadata = Ip(e), this.onModelLoad(this.targetModel).then(() => t(e));
|
|
14798
14860
|
}, (e) => n(e));
|
|
14799
14861
|
});
|
|
14800
14862
|
} finally {
|
|
@@ -14922,7 +14984,7 @@ var Ap = {
|
|
|
14922
14984
|
totalBytes: 0
|
|
14923
14985
|
});
|
|
14924
14986
|
let e = await n.loadAsync(t, this._downloadProgress("Downloading Model...", r));
|
|
14925
|
-
return this._downloadComplete(), this.releaseTargetModel(), this.targetModel = e.scene, this.animations = e.animations || [], await this.onModelLoad(this.targetModel), this.dispatchEvent({
|
|
14987
|
+
return this._downloadComplete(), this.releaseTargetModel(), this.targetModel = e.scene, this.animations = e.animations || [], this.sceneMetadata = Ip(e), await this.onModelLoad(this.targetModel), this.dispatchEvent({
|
|
14926
14988
|
type: "load",
|
|
14927
14989
|
model: e.scene,
|
|
14928
14990
|
filename: t.split("/").pop()
|
|
@@ -14978,7 +15040,7 @@ var Ap = {
|
|
|
14978
15040
|
progress: 5
|
|
14979
15041
|
}), await new Promise((e) => setTimeout(e, 0));
|
|
14980
15042
|
let r = await n.parseAsync(e, "");
|
|
14981
|
-
return this.releaseTargetModel(), this.targetModel = r.scene, this.animations = r.animations || [], gr({
|
|
15043
|
+
return this.releaseTargetModel(), this.targetModel = r.scene, this.animations = r.animations || [], this.sceneMetadata = Ip(r), gr({
|
|
14982
15044
|
isLoading: !0,
|
|
14983
15045
|
status: "Processing Data...",
|
|
14984
15046
|
progress: 10
|
|
@@ -15291,10 +15353,10 @@ var Ap = {
|
|
|
15291
15353
|
getSupportedFormats(e = null) {
|
|
15292
15354
|
if (e) {
|
|
15293
15355
|
let t = {};
|
|
15294
|
-
for (let [n, r] of Object.entries(
|
|
15356
|
+
for (let [n, r] of Object.entries(Lp)) r.type === e && (t[n] = r);
|
|
15295
15357
|
return t;
|
|
15296
15358
|
}
|
|
15297
|
-
return
|
|
15359
|
+
return Lp;
|
|
15298
15360
|
}
|
|
15299
15361
|
dispose() {
|
|
15300
15362
|
for (let e in this.loaderCache) {
|
|
@@ -15306,7 +15368,7 @@ var Ap = {
|
|
|
15306
15368
|
removeAllEventListeners() {
|
|
15307
15369
|
this._listeners = void 0;
|
|
15308
15370
|
}
|
|
15309
|
-
},
|
|
15371
|
+
}, Vp = {
|
|
15310
15372
|
maxBounces: {
|
|
15311
15373
|
uniform: "maxBounces",
|
|
15312
15374
|
reset: !0
|
|
@@ -15497,10 +15559,10 @@ var Ap = {
|
|
|
15497
15559
|
},
|
|
15498
15560
|
renderMode: { handler: "handleRenderMode" },
|
|
15499
15561
|
environmentRotation: { handler: "handleEnvironmentRotation" }
|
|
15500
|
-
},
|
|
15562
|
+
}, Hp = {
|
|
15501
15563
|
bounces: "maxBounces",
|
|
15502
15564
|
debugMode: "visMode"
|
|
15503
|
-
},
|
|
15565
|
+
}, Up = class extends lt {
|
|
15504
15566
|
constructor(e = Y) {
|
|
15505
15567
|
super(), this._values = /* @__PURE__ */ new Map(), this._pathTracer = null, this._resetCallback = null, this._handlers = {}, this._delegates = {}, this._initDefaults(e);
|
|
15506
15568
|
}
|
|
@@ -15558,7 +15620,7 @@ var Ap = {
|
|
|
15558
15620
|
let i = this._values.get(e);
|
|
15559
15621
|
if (i === t) return;
|
|
15560
15622
|
this._values.set(e, t);
|
|
15561
|
-
let a =
|
|
15623
|
+
let a = Vp[e];
|
|
15562
15624
|
a && (this._applyRoute(a, t, i), (n === void 0 ? a.reset ?? !0 : n) && this._resetCallback?.(), r || this.dispatchEvent({
|
|
15563
15625
|
type: dr.SETTING_CHANGED,
|
|
15564
15626
|
key: e,
|
|
@@ -15572,7 +15634,7 @@ var Ap = {
|
|
|
15572
15634
|
let e = this._values.get(n);
|
|
15573
15635
|
if (e === i) continue;
|
|
15574
15636
|
this._values.set(n, i);
|
|
15575
|
-
let a =
|
|
15637
|
+
let a = Vp[n];
|
|
15576
15638
|
a && (this._applyRoute(a, i, e), (a.reset ?? !0) && (r = !0), t || this.dispatchEvent({
|
|
15577
15639
|
type: dr.SETTING_CHANGED,
|
|
15578
15640
|
key: n,
|
|
@@ -15590,7 +15652,7 @@ var Ap = {
|
|
|
15590
15652
|
}
|
|
15591
15653
|
applyAll() {
|
|
15592
15654
|
for (let [e, t] of this._values) {
|
|
15593
|
-
let n =
|
|
15655
|
+
let n = Vp[e];
|
|
15594
15656
|
n && this._applyRoute(n, t, void 0);
|
|
15595
15657
|
}
|
|
15596
15658
|
}
|
|
@@ -15598,10 +15660,10 @@ var Ap = {
|
|
|
15598
15660
|
e.uniform ? (this._pathTracer?.setUniform(e.uniform, t), e.after && this._pathTracer?.[e.after]?.()) : e.handler ? this._handlers[e.handler]?.(t, n) : e.delegate && this._delegates[e.delegate]?.updateParam?.(e.param, t);
|
|
15599
15661
|
}
|
|
15600
15662
|
_initDefaults(e) {
|
|
15601
|
-
for (let t of Object.keys(
|
|
15602
|
-
for (let [t, n] of Object.entries(
|
|
15663
|
+
for (let t of Object.keys(Vp)) t in e && this._values.set(t, e[t]);
|
|
15664
|
+
for (let [t, n] of Object.entries(Hp)) t in e && this._values.set(n, e[t]);
|
|
15603
15665
|
}
|
|
15604
|
-
},
|
|
15666
|
+
}, Wp = class extends lt {
|
|
15605
15667
|
constructor(e) {
|
|
15606
15668
|
super();
|
|
15607
15669
|
let t = e.clientWidth, n = e.clientHeight;
|
|
@@ -15767,7 +15829,7 @@ var Ap = {
|
|
|
15767
15829
|
dispose() {
|
|
15768
15830
|
this.controls?.dispose();
|
|
15769
15831
|
}
|
|
15770
|
-
},
|
|
15832
|
+
}, Gp = class extends lt {
|
|
15771
15833
|
constructor(e, t, n, r = {}) {
|
|
15772
15834
|
super(), this.scene = e, this.sceneHelpers = t, this.pathTracer = n, this._onReset = r.onReset || null;
|
|
15773
15835
|
}
|
|
@@ -15927,14 +15989,14 @@ var Ap = {
|
|
|
15927
15989
|
], n.distance = e.distance ?? 0, n.penumbra = e.penumbra ?? 0, n.decay = e.decay ?? 2) : e.type === "PointLight" && (n.distance = e.distance ?? 0, n.decay = e.decay ?? 2);
|
|
15928
15990
|
return (e.type === "SpotLight" || e.type === "DirectionalLight") && e.userData?.gobo && (n.gobo = e.userData.gobo.name, n.goboIntensity = e.userData.gobo.intensity, n.goboInverted = !!e.userData.gobo.inverted, e.type === "DirectionalLight" && (n.goboScale = e.userData.gobo.scale ?? 5)), e.type === "SpotLight" && e.userData?.ies && (n.ies = e.userData.ies.name, n.iesIntensity = e.userData.ies.intensity ?? 1, n.fixtureLumens = e.userData.ies.fixtureLumens ?? null), n;
|
|
15929
15991
|
}
|
|
15930
|
-
},
|
|
15992
|
+
}, Kp = class {
|
|
15931
15993
|
constructor(e, t = {}) {
|
|
15932
15994
|
this.pathTracer = e, this._onReset = t.onReset || null, this.texture = null, this.entries = [], this._size = 256;
|
|
15933
15995
|
}
|
|
15934
15996
|
async loadLibrary(e, { size: t = 256 } = {}) {
|
|
15935
15997
|
if (!Array.isArray(e) || e.length === 0) return [];
|
|
15936
15998
|
this._size = t;
|
|
15937
|
-
let n = await Promise.all(e.map((e) =>
|
|
15999
|
+
let n = await Promise.all(e.map((e) => qp(e.url))), r = t, i = t, a = n.length, o = new Uint8Array(r * i * a * 4), s = document.createElement("canvas");
|
|
15938
16000
|
s.width = r, s.height = i;
|
|
15939
16001
|
let c = s.getContext("2d", { willReadFrequently: !0 });
|
|
15940
16002
|
for (let e = 0; e < a; e++) {
|
|
@@ -15963,7 +16025,7 @@ var Ap = {
|
|
|
15963
16025
|
o.userData.gobo = {
|
|
15964
16026
|
name: e.name,
|
|
15965
16027
|
index: e.index,
|
|
15966
|
-
intensity:
|
|
16028
|
+
intensity: Jp(r),
|
|
15967
16029
|
inverted: !!i,
|
|
15968
16030
|
scale: Math.max(1e-4, a)
|
|
15969
16031
|
};
|
|
@@ -16005,28 +16067,28 @@ var Ap = {
|
|
|
16005
16067
|
return t && t.isSpotLight ? t : null;
|
|
16006
16068
|
}
|
|
16007
16069
|
};
|
|
16008
|
-
function
|
|
16070
|
+
function qp(e) {
|
|
16009
16071
|
return new Promise((t, n) => {
|
|
16010
16072
|
let r = new Image();
|
|
16011
16073
|
r.crossOrigin = "anonymous", r.onload = () => t(r), r.onerror = () => n(/* @__PURE__ */ Error(`Failed to load gobo image: ${e}`)), r.src = e;
|
|
16012
16074
|
});
|
|
16013
16075
|
}
|
|
16014
|
-
function
|
|
16076
|
+
function Jp(e) {
|
|
16015
16077
|
return Math.max(0, Math.min(1, e));
|
|
16016
16078
|
}
|
|
16017
16079
|
//#endregion
|
|
16018
16080
|
//#region src/Processor/IESParser.js
|
|
16019
|
-
function
|
|
16081
|
+
function Yp(e, t = "ies") {
|
|
16020
16082
|
let n = e.search(/TILT\s*=/i);
|
|
16021
16083
|
if (n < 0) throw Error(`IES (${t}): missing TILT line`);
|
|
16022
16084
|
let r = e.indexOf("\n", n);
|
|
16023
16085
|
if (r < 0) throw Error(`IES (${t}): truncated TILT line`);
|
|
16024
16086
|
let i = e.slice(n, r).match(/TILT\s*=\s*(\w+)/i), a = i ? i[1].toUpperCase() : "NONE", o = e.slice(r);
|
|
16025
16087
|
if (a === "INCLUDE") {
|
|
16026
|
-
let e =
|
|
16027
|
-
o =
|
|
16088
|
+
let e = $p(o), t = 2 + 2 * Number(e[1]);
|
|
16089
|
+
o = em(o, t);
|
|
16028
16090
|
}
|
|
16029
|
-
let s =
|
|
16091
|
+
let s = $p(o), c = 0, l = () => Number(s[c++]), u = l(), d = l(), f = l(), p = l(), m = l(), h = l();
|
|
16030
16092
|
l(), l(), l(), l();
|
|
16031
16093
|
let g = l();
|
|
16032
16094
|
if (l(), l(), !Number.isFinite(p) || p <= 0) throw Error(`IES (${t}): invalid vertical angle count ${p}`);
|
|
@@ -16052,18 +16114,18 @@ function Hp(e, t = "ies") {
|
|
|
16052
16114
|
name: t
|
|
16053
16115
|
};
|
|
16054
16116
|
}
|
|
16055
|
-
function
|
|
16117
|
+
function Xp(e, t, n) {
|
|
16056
16118
|
let r = new Uint8Array(t * n), { verticalAngles: i, horizontalAngles: a, candela: o, maxCandela: s } = e;
|
|
16057
16119
|
if (s <= 0) return r;
|
|
16058
16120
|
let c = i[i.length - 1], l = a[a.length - 1], u = a[0], d = a.length === 1 || l === u;
|
|
16059
16121
|
for (let e = 0; e < n; e++) {
|
|
16060
|
-
let f = (e + .5) / n * c, p =
|
|
16122
|
+
let f = (e + .5) / n * c, p = tm(i, f), m = Math.min(p + 1, i.length - 1), h = i[m] - i[p], g = h > 0 ? (f - i[p]) / h : 0;
|
|
16061
16123
|
for (let n = 0; n < t; n++) {
|
|
16062
16124
|
let i;
|
|
16063
|
-
if (d) i =
|
|
16125
|
+
if (d) i = nm(o[p][0], o[m][0], g);
|
|
16064
16126
|
else {
|
|
16065
|
-
let e = u + (n + .5) / t * (l - u), r =
|
|
16066
|
-
i =
|
|
16127
|
+
let e = u + (n + .5) / t * (l - u), r = tm(a, e), s = Math.min(r + 1, a.length - 1), c = a[s] - a[r], d = c > 0 ? (e - a[r]) / c : 0, f = o[p][r], h = o[p][s], _ = o[m][r], v = o[m][s];
|
|
16128
|
+
i = nm(nm(f, h, d), nm(_, v, d), g);
|
|
16067
16129
|
}
|
|
16068
16130
|
let c = Math.min(1, Math.max(0, i / s));
|
|
16069
16131
|
r[e * t + n] = Math.round(c * 255);
|
|
@@ -16071,7 +16133,7 @@ function Up(e, t, n) {
|
|
|
16071
16133
|
}
|
|
16072
16134
|
return r;
|
|
16073
16135
|
}
|
|
16074
|
-
function
|
|
16136
|
+
function Zp(e, t = .1) {
|
|
16075
16137
|
let { verticalAngles: n, horizontalAngles: r, candela: i, maxCandela: a } = e, o = Math.PI / 4;
|
|
16076
16138
|
if (a <= 0 || !n?.length) return o;
|
|
16077
16139
|
let s = a * t, c = r.length, l = n[n.length - 1], u = !1;
|
|
@@ -16086,7 +16148,7 @@ function Wp(e, t = .1) {
|
|
|
16086
16148
|
let d = l * Math.PI / 180;
|
|
16087
16149
|
return Math.min(Math.max(d, 5 * Math.PI / 180), 89 * Math.PI / 180);
|
|
16088
16150
|
}
|
|
16089
|
-
function
|
|
16151
|
+
function Qp(e, t, n = .7) {
|
|
16090
16152
|
let { verticalAngles: r, horizontalAngles: i, candela: a, maxCandela: o } = e;
|
|
16091
16153
|
if (o <= 0 || !r?.length || t <= 0) return 0;
|
|
16092
16154
|
let s = o * n, c = i.length, l = 0;
|
|
@@ -16099,15 +16161,15 @@ function Gp(e, t, n = .7) {
|
|
|
16099
16161
|
let u = t * 180 / Math.PI, d = u > 0 ? 1 - l / u : 0;
|
|
16100
16162
|
return Math.min(Math.max(d, 0), 1);
|
|
16101
16163
|
}
|
|
16102
|
-
function
|
|
16164
|
+
function $p(e) {
|
|
16103
16165
|
return e.split(/\s+/).filter((e) => e.length > 0);
|
|
16104
16166
|
}
|
|
16105
|
-
function
|
|
16167
|
+
function em(e, t) {
|
|
16106
16168
|
let n = /\S+/g, r = 0;
|
|
16107
16169
|
for (; n.exec(e) !== null;) if (r++, r === t) return e.slice(n.lastIndex);
|
|
16108
16170
|
return "";
|
|
16109
16171
|
}
|
|
16110
|
-
function
|
|
16172
|
+
function tm(e, t) {
|
|
16111
16173
|
if (t <= e[0]) return 0;
|
|
16112
16174
|
if (t >= e[e.length - 1]) return e.length - 1;
|
|
16113
16175
|
let n = 0, r = e.length - 1;
|
|
@@ -16117,12 +16179,12 @@ function Jp(e, t) {
|
|
|
16117
16179
|
}
|
|
16118
16180
|
return n;
|
|
16119
16181
|
}
|
|
16120
|
-
function
|
|
16182
|
+
function nm(e, t, n) {
|
|
16121
16183
|
return e + (t - e) * n;
|
|
16122
16184
|
}
|
|
16123
16185
|
//#endregion
|
|
16124
16186
|
//#region src/managers/IESManager.js
|
|
16125
|
-
var
|
|
16187
|
+
var rm = class {
|
|
16126
16188
|
constructor(e, t = {}) {
|
|
16127
16189
|
this.pathTracer = e, this._onReset = t.onReset || null, this.texture = null, this.entries = [], this._gridWidth = 128, this._gridHeight = 128;
|
|
16128
16190
|
}
|
|
@@ -16133,11 +16195,11 @@ var Xp = class {
|
|
|
16133
16195
|
try {
|
|
16134
16196
|
let r = await fetch(e.url);
|
|
16135
16197
|
if (!r.ok) throw Error(`HTTP ${r.status}`);
|
|
16136
|
-
let i =
|
|
16198
|
+
let i = Yp(await r.text(), e.name);
|
|
16137
16199
|
return {
|
|
16138
16200
|
it: e,
|
|
16139
16201
|
profile: i,
|
|
16140
|
-
grid:
|
|
16202
|
+
grid: Xp(i, t, n)
|
|
16141
16203
|
};
|
|
16142
16204
|
} catch (t) {
|
|
16143
16205
|
return console.warn(`IESManager: failed to load "${e.name}": ${t.message}`), null;
|
|
@@ -16151,14 +16213,14 @@ var Xp = class {
|
|
|
16151
16213
|
let r = t[e];
|
|
16152
16214
|
o[n + e * 4 + 0] = r, o[n + e * 4 + 1] = r, o[n + e * 4 + 2] = r, o[n + e * 4 + 3] = 255;
|
|
16153
16215
|
}
|
|
16154
|
-
let i = r[e].profile, c =
|
|
16216
|
+
let i = r[e].profile, c = Zp(i);
|
|
16155
16217
|
s.push({
|
|
16156
16218
|
name: r[e].it.name,
|
|
16157
16219
|
index: e,
|
|
16158
16220
|
maxCandela: i.maxCandela,
|
|
16159
16221
|
photometricType: i.photometricType,
|
|
16160
16222
|
suggestedAngle: c,
|
|
16161
|
-
suggestedPenumbra:
|
|
16223
|
+
suggestedPenumbra: Qp(i, c),
|
|
16162
16224
|
lumens: i.lumens
|
|
16163
16225
|
});
|
|
16164
16226
|
}
|
|
@@ -16191,7 +16253,7 @@ var Xp = class {
|
|
|
16191
16253
|
l = Number.isFinite(e.lumens) ? e.lumens : null, i.userData.ies = {
|
|
16192
16254
|
name: e.name,
|
|
16193
16255
|
index: e.index,
|
|
16194
|
-
intensity:
|
|
16256
|
+
intensity: im(n),
|
|
16195
16257
|
fixtureLumens: l
|
|
16196
16258
|
}, r && (Number.isFinite(e.suggestedAngle) && (i.angle = e.suggestedAngle, o = e.suggestedAngle), Number.isFinite(e.suggestedPenumbra) && (i.penumbra = e.suggestedPenumbra, s = e.suggestedPenumbra), i.decay = 2, c = 2);
|
|
16197
16259
|
}
|
|
@@ -16214,44 +16276,44 @@ var Xp = class {
|
|
|
16214
16276
|
return t && t.isSpotLight ? t : null;
|
|
16215
16277
|
}
|
|
16216
16278
|
};
|
|
16217
|
-
function
|
|
16279
|
+
function im(e) {
|
|
16218
16280
|
return Math.max(0, Math.min(1, e));
|
|
16219
16281
|
}
|
|
16220
16282
|
//#endregion
|
|
16221
16283
|
//#region src/Processor/ToneMapCPU.js
|
|
16222
|
-
var
|
|
16223
|
-
function
|
|
16224
|
-
i[0] =
|
|
16284
|
+
var am = (e) => Math.min(Math.max(e, 0), 1);
|
|
16285
|
+
function om(e, t, n, r, i) {
|
|
16286
|
+
i[0] = am(e), i[1] = am(t), i[2] = am(n);
|
|
16225
16287
|
}
|
|
16226
|
-
function
|
|
16227
|
-
i[0] =
|
|
16288
|
+
function sm(e, t, n, r, i) {
|
|
16289
|
+
i[0] = am(e * r), i[1] = am(t * r), i[2] = am(n * r);
|
|
16228
16290
|
}
|
|
16229
|
-
function
|
|
16230
|
-
e *= r, t *= r, n *= r, i[0] =
|
|
16291
|
+
function cm(e, t, n, r, i) {
|
|
16292
|
+
e *= r, t *= r, n *= r, i[0] = am(e / (e + 1)), i[1] = am(t / (t + 1)), i[2] = am(n / (n + 1));
|
|
16231
16293
|
}
|
|
16232
|
-
function
|
|
16294
|
+
function lm(e, t, n, r, i) {
|
|
16233
16295
|
e = Math.max(e * r - .004, 0), t = Math.max(t * r - .004, 0), n = Math.max(n * r - .004, 0);
|
|
16234
16296
|
let a = (e) => (e * (6.2 * e + .5) / (e * (6.2 * e + 1.7) + .06)) ** 2.2;
|
|
16235
16297
|
i[0] = a(e), i[1] = a(t), i[2] = a(n);
|
|
16236
16298
|
}
|
|
16237
|
-
function
|
|
16299
|
+
function um(e, t, n, r, i) {
|
|
16238
16300
|
e = e * r / .6, t = t * r / .6, n = n * r / .6;
|
|
16239
16301
|
let a = .59719 * e + .35458 * t + .04823 * n, o = .076 * e + .90834 * t + .01566 * n, s = .0284 * e + .13383 * t + .83777 * n, c = (e) => (e * (e + .0245786) - 90537e-9) / (e * (.983729 * e + .432951) + .238081);
|
|
16240
|
-
a = c(a), o = c(o), s = c(s), i[0] =
|
|
16302
|
+
a = c(a), o = c(o), s = c(s), i[0] = am(1.60475 * a - .53108 * o - .07367 * s), i[1] = am(-.10208 * a + 1.10813 * o - .00605 * s), i[2] = am(-.00327 * a - .07276 * o + 1.07602 * s);
|
|
16241
16303
|
}
|
|
16242
|
-
function
|
|
16304
|
+
function dm(e, t, n, r, i) {
|
|
16243
16305
|
e *= r, t *= r, n *= r;
|
|
16244
16306
|
let a = .6274 * e + .3293 * t + .0433 * n, o = .0691 * e + .9195 * t + .0113 * n, s = .0164 * e + .088 * t + .8956 * n, c = .856627153315983 * a + .0951212405381588 * o + .0482516061458583 * s, l = .137318972929847 * a + .761241990602591 * o + .101439036467562 * s, u = .11189821299995 * a + .0767994186031903 * o + .811302368396859 * s, d = -12.47393, f = 4.026069 - d;
|
|
16245
|
-
c =
|
|
16307
|
+
c = am((Math.log2(Math.max(c, 1e-10)) - d) / f), l = am((Math.log2(Math.max(l, 1e-10)) - d) / f), u = am((Math.log2(Math.max(u, 1e-10)) - d) / f);
|
|
16246
16308
|
let p = (e) => {
|
|
16247
16309
|
let t = e * e, n = t * t;
|
|
16248
16310
|
return 15.5 * n * t - 40.14 * n * e + 31.96 * n - 6.868 * t * e + .4298 * t + .1191 * e - .00232;
|
|
16249
16311
|
};
|
|
16250
16312
|
c = p(c), l = p(l), u = p(u);
|
|
16251
16313
|
let m = 1.1271005818144368 * c - .11060664309660323 * l - .016493938717834573 * u, h = -.1413297634984383 * c + 1.157823702216272 * l - .016493938717834257 * u, g = -.14132976349843826 * c - .11060664309660294 * l + 1.2519364065950405 * u;
|
|
16252
|
-
m = Math.max(0, m) ** 2.2, h = Math.max(0, h) ** 2.2, g = Math.max(0, g) ** 2.2, i[0] =
|
|
16314
|
+
m = Math.max(0, m) ** 2.2, h = Math.max(0, h) ** 2.2, g = Math.max(0, g) ** 2.2, i[0] = am(1.6605 * m - .5876 * h - .0728 * g), i[1] = am(-.1246 * m + 1.1329 * h - .0083 * g), i[2] = am(-.0182 * m - .1006 * h + 1.1187 * g);
|
|
16253
16315
|
}
|
|
16254
|
-
function
|
|
16316
|
+
function fm(e, t, n, r, i) {
|
|
16255
16317
|
let a = .76;
|
|
16256
16318
|
e *= r, t *= r, n *= r;
|
|
16257
16319
|
let o = Math.min(e, Math.min(t, n)), s = o < .08 ? o - 6.25 * o * o : .04;
|
|
@@ -16266,34 +16328,34 @@ function am(e, t, n, r, i) {
|
|
|
16266
16328
|
let f = 1 - 1 / (.15 * (c - u) + 1);
|
|
16267
16329
|
i[0] = e + (u - e) * f, i[1] = t + (u - t) * f, i[2] = n + (u - n) * f;
|
|
16268
16330
|
}
|
|
16269
|
-
var
|
|
16270
|
-
[At, om
|
|
16271
|
-
[J,
|
|
16272
|
-
[Gt,
|
|
16273
|
-
[Ze,
|
|
16274
|
-
[He,
|
|
16275
|
-
[We,
|
|
16276
|
-
[Ot,
|
|
16277
|
-
]),
|
|
16278
|
-
function
|
|
16331
|
+
var pm = (e) => (t, n, r, i, a) => e(t > 0 ? t : 0, n > 0 ? n : 0, r > 0 ? r : 0, i, a), mm = new Map([
|
|
16332
|
+
[At, pm(om)],
|
|
16333
|
+
[J, pm(sm)],
|
|
16334
|
+
[Gt, pm(cm)],
|
|
16335
|
+
[Ze, pm(lm)],
|
|
16336
|
+
[He, pm(um)],
|
|
16337
|
+
[We, pm(dm)],
|
|
16338
|
+
[Ot, pm(fm)]
|
|
16339
|
+
]), hm = 1 / 2.2;
|
|
16340
|
+
function gm(e) {
|
|
16279
16341
|
return e <= .0031308 ? 12.92 * e : 1.055 * e ** (1 / 2.4) - .055;
|
|
16280
16342
|
}
|
|
16281
|
-
function
|
|
16343
|
+
function _m(e, t) {
|
|
16282
16344
|
return t === At ? 1 : e;
|
|
16283
16345
|
}
|
|
16284
|
-
var
|
|
16285
|
-
function
|
|
16346
|
+
var vm = .2126, ym = .7152, bm = .0722;
|
|
16347
|
+
function xm(e, t) {
|
|
16286
16348
|
if (t === 1) return;
|
|
16287
|
-
let n = e[0] *
|
|
16349
|
+
let n = e[0] * vm + e[1] * ym + e[2] * bm;
|
|
16288
16350
|
e[0] = n + (e[0] - n) * t, e[1] = n + (e[1] - n) * t, e[2] = n + (e[2] - n) * t;
|
|
16289
16351
|
}
|
|
16290
16352
|
//#endregion
|
|
16291
16353
|
//#region src/Passes/OIDNDenoiser.js
|
|
16292
|
-
var
|
|
16293
|
-
async function
|
|
16294
|
-
return
|
|
16354
|
+
var Sm = ci("oidn"), Cm = null;
|
|
16355
|
+
async function wm() {
|
|
16356
|
+
return Cm ||= (await import("oidn-web")).initUNetFromURL, Cm;
|
|
16295
16357
|
}
|
|
16296
|
-
var
|
|
16358
|
+
var Tm = new Float32Array(3), Em = {
|
|
16297
16359
|
QUALITY_MODELS: {
|
|
16298
16360
|
fast: {
|
|
16299
16361
|
model: "rt_hdr_alb_nrm_small",
|
|
@@ -16318,17 +16380,17 @@ var vm = new Float32Array(3), ym = {
|
|
|
16318
16380
|
debugGbufferMaps: !0,
|
|
16319
16381
|
tileSize: 1024
|
|
16320
16382
|
}
|
|
16321
|
-
},
|
|
16322
|
-
function
|
|
16383
|
+
}, Dm = "\n@group(0) @binding(0) var<storage, read_write> col: array<vec4<f32>>;\n@group(0) @binding(1) var<uniform> scale: f32;\n\n@compute @workgroup_size(64)\nfn main( @builtin(global_invocation_id) gid: vec3<u32>,\n @builtin(num_workgroups) nwg: vec3<u32> ) {\n let i = gid.y * nwg.x * 64u + gid.x;\n if ( i >= arrayLength( &col ) ) { return; }\n let c = col[ i ];\n col[ i ] = vec4<f32>( c.xyz * scale, c.w );\n}\n", Om = 64, km = 32768, Am = .18;
|
|
16384
|
+
function jm(e, t) {
|
|
16323
16385
|
let n = 0;
|
|
16324
16386
|
for (let r = 0; r < t; r++) {
|
|
16325
16387
|
let t = r * 4, i = .212671 * e[t] + .71516 * e[t + 1] + .072169 * e[t + 2];
|
|
16326
16388
|
n += Math.log2(Math.max(i, 0) + 1e-4);
|
|
16327
16389
|
}
|
|
16328
|
-
let r =
|
|
16390
|
+
let r = Am / 2 ** (n / t);
|
|
16329
16391
|
return Number.isFinite(r) && r > 0 ? r : 1;
|
|
16330
16392
|
}
|
|
16331
|
-
var
|
|
16393
|
+
var Mm = class extends lt {
|
|
16332
16394
|
constructor(e, t, n, r, i = {}) {
|
|
16333
16395
|
if (super(), !e || !t || !n || !r) throw Error("OIDNDenoiser requires output canvas, renderer, scene, and camera");
|
|
16334
16396
|
this.renderer = t, this.scene = n, this.camera = r, this.input = t.domElement, this.output = e, this.extractGBufferData = i.extractGBufferData || null, this.getMRTRenderTarget = i.getMRTRenderTarget || null, this.backendParamsGetter = i.backendParams || null, this.getGPUTextures = i.getGPUTextures || null, this.refreshInput = i.refreshInput || null, this.getExposure = i.getExposure || (() => 1), this.getToneMapping = i.getToneMapping || (() => He), this.getSaturation = i.getSaturation || (() => 1), this.getTransparentBackground = i.getTransparentBackground || (() => !1), this.isGPUMode = !!this.backendParamsGetter, this.gpuDevice = null, this._gpuInputBuffers = {
|
|
@@ -16339,14 +16401,14 @@ var Tm = class extends lt {
|
|
|
16339
16401
|
width: 0,
|
|
16340
16402
|
height: 0
|
|
16341
16403
|
}, this._gpuInputPadBuffer = null, this._gpuInputPaddedRowBytes = 0, this._colorScalePipeline = null, this._colorScaleBindGroup = null, this._colorScaleUniform = null, this._oidnInputScale = 1, this._alphaReadbackBuffer = null, this._alphaReadbackMapped = !1, this._cachedAlpha = null, this._cachedAlphaWidth = 0, this.config = {
|
|
16342
|
-
...
|
|
16404
|
+
...Em.DEFAULT_OPTIONS,
|
|
16343
16405
|
...i
|
|
16344
16406
|
}, this.enabled = this.config.enableOIDN, this.quality = this.config.oidnQuality, this.debugGbufferMaps = this.config.debugGbufferMaps, this.maxTileSize = this.config.tileSize, this._activeTileSize = 0, this.state = {
|
|
16345
16407
|
isDenoising: !1,
|
|
16346
16408
|
isLoading: !1,
|
|
16347
16409
|
abortController: null
|
|
16348
16410
|
}, this._pendingStagingBuffers = /* @__PURE__ */ new Set(), this._pendingTileBlits = [], this.currentTZAUrl = null, this.unet = null, this._pendingStart = !1, this._initialize().catch((e) => {
|
|
16349
|
-
|
|
16411
|
+
Sm.error("init failed:", e), this.dispatchEvent({
|
|
16350
16412
|
type: "error",
|
|
16351
16413
|
error: e
|
|
16352
16414
|
});
|
|
@@ -16375,7 +16437,7 @@ var Tm = class extends lt {
|
|
|
16375
16437
|
});
|
|
16376
16438
|
}
|
|
16377
16439
|
expectsCleanAux(e = this.quality) {
|
|
16378
|
-
let { QUALITY_MODELS: t } =
|
|
16440
|
+
let { QUALITY_MODELS: t } = Em;
|
|
16379
16441
|
return (t[e] || t.balance).cleanAux;
|
|
16380
16442
|
}
|
|
16381
16443
|
getRuntimeInfo() {
|
|
@@ -16409,14 +16471,14 @@ var Tm = class extends lt {
|
|
|
16409
16471
|
let e = this.backendParamsGetter();
|
|
16410
16472
|
this.gpuDevice = e?.device ?? null, n = e?.device ? e : void 0;
|
|
16411
16473
|
}
|
|
16412
|
-
this.unet = await (await
|
|
16474
|
+
this.unet = await (await wm())(e, n, {
|
|
16413
16475
|
aux: !0,
|
|
16414
16476
|
hdr: !0,
|
|
16415
16477
|
maxTileSize: t,
|
|
16416
16478
|
dynamicTile: !1
|
|
16417
|
-
}), this.currentTZAUrl = e, this._activeTileSize = t, this.dispatchEvent({ type: "loaded" }),
|
|
16479
|
+
}), this.currentTZAUrl = e, this._activeTileSize = t, this.dispatchEvent({ type: "loaded" }), Sm.debug("UNet weights loaded:", e);
|
|
16418
16480
|
} catch (e) {
|
|
16419
|
-
|
|
16481
|
+
Sm.error("UNet weights failed to load:", e), this.dispatchEvent({
|
|
16420
16482
|
type: "error",
|
|
16421
16483
|
error: /* @__PURE__ */ Error(`Denoiser loading failed: ${e.message}`)
|
|
16422
16484
|
});
|
|
@@ -16425,14 +16487,14 @@ var Tm = class extends lt {
|
|
|
16425
16487
|
}
|
|
16426
16488
|
}
|
|
16427
16489
|
_generateTzaUrl() {
|
|
16428
|
-
let { oidnWeightsBaseUrl: e } = ml(), { QUALITY_MODELS: t } =
|
|
16490
|
+
let { oidnWeightsBaseUrl: e } = ml(), { QUALITY_MODELS: t } = Em;
|
|
16429
16491
|
return `${e}${(t[this.quality] || t.balance).model}.tza`;
|
|
16430
16492
|
}
|
|
16431
16493
|
async updateConfiguration(e) {
|
|
16432
16494
|
Object.keys(e).some((t) => this.config[t] !== e[t]) && (Object.assign(this.config, e), this.quality = this.config.oidnQuality, this.debugGbufferMaps = this.config.debugGbufferMaps, this.maxTileSize = this.config.tileSize, await this._setupUNetDenoiser());
|
|
16433
16495
|
}
|
|
16434
16496
|
async updateQuality(e) {
|
|
16435
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
16497
|
+
if (!Object.prototype.hasOwnProperty.call(Em.QUALITY_MODELS, e)) throw Error(`Invalid quality setting: ${e}. Must be one of: ${Object.keys(Em.QUALITY_MODELS).join(", ")}`);
|
|
16436
16498
|
await this.updateConfiguration({ oidnQuality: e });
|
|
16437
16499
|
}
|
|
16438
16500
|
async start() {
|
|
@@ -16443,7 +16505,7 @@ var Tm = class extends lt {
|
|
|
16443
16505
|
if (t) {
|
|
16444
16506
|
this.renderer?.resetState?.(), this.input.style.opacity = "0";
|
|
16445
16507
|
let t = performance.now() - e;
|
|
16446
|
-
|
|
16508
|
+
Sm.debug(`denoise complete in ${Q.ms(t)} · quality ${this.quality}`);
|
|
16447
16509
|
}
|
|
16448
16510
|
return t;
|
|
16449
16511
|
}
|
|
@@ -16456,7 +16518,7 @@ var Tm = class extends lt {
|
|
|
16456
16518
|
try {
|
|
16457
16519
|
return await this._executeUNet(), !0;
|
|
16458
16520
|
} catch (e) {
|
|
16459
|
-
return e.name === "AbortError" ?
|
|
16521
|
+
return e.name === "AbortError" ? Sm.debug("denoise aborted") : Sm.error("denoise error:", e), this.input.style.opacity = "1", !1;
|
|
16460
16522
|
} finally {
|
|
16461
16523
|
this.state.isDenoising = !1, this.state.abortController = null, this.dispatchEvent({ type: "end" });
|
|
16462
16524
|
}
|
|
@@ -16466,11 +16528,11 @@ var Tm = class extends lt {
|
|
|
16466
16528
|
}
|
|
16467
16529
|
async _executeUNetGPU() {
|
|
16468
16530
|
let { width: e, height: t } = this.output;
|
|
16469
|
-
if (!this.getGPUTextures) return
|
|
16531
|
+
if (!this.getGPUTextures) return Sm.warn("GPU mode enabled but getGPUTextures not provided"), !1;
|
|
16470
16532
|
let n = this.getGPUTextures();
|
|
16471
|
-
if (!n?.color) return
|
|
16533
|
+
if (!n?.color) return Sm.warn("GPU textures not ready yet"), !1;
|
|
16472
16534
|
let r = this.gpuDevice;
|
|
16473
|
-
if (!r) return
|
|
16535
|
+
if (!r) return Sm.warn("gpuDevice not available"), !1;
|
|
16474
16536
|
this.refreshInput?.(), this.ctx.drawImage(this.input, 0, 0, e, t), this._revealOutput(), this._ensureGPUInputBuffers(e, t);
|
|
16475
16537
|
let i = r.createCommandEncoder({ label: "oidn-tex-to-buf" }), a = e * 16, o = this._gpuInputPaddedRowBytes, s = o > a, c = this._gpuInputPadBuffer, l = (n, r) => {
|
|
16476
16538
|
if (!s) i.copyTextureToBuffer({
|
|
@@ -16580,7 +16642,7 @@ var Tm = class extends lt {
|
|
|
16580
16642
|
return;
|
|
16581
16643
|
}
|
|
16582
16644
|
let o = new Float32Array(i.getMappedRange()), s = t * n;
|
|
16583
|
-
this._oidnInputScale =
|
|
16645
|
+
this._oidnInputScale = jm(o, s);
|
|
16584
16646
|
let c = null;
|
|
16585
16647
|
if (this.getTransparentBackground()) {
|
|
16586
16648
|
c = new Uint8Array(s);
|
|
@@ -16589,13 +16651,13 @@ var Tm = class extends lt {
|
|
|
16589
16651
|
i.unmap(), this._alphaReadbackMapped = !1, this._cachedAlpha = c, this._cachedAlphaWidth = t;
|
|
16590
16652
|
}
|
|
16591
16653
|
_outputExposure() {
|
|
16592
|
-
return
|
|
16654
|
+
return _m(this.getExposure(), this.getToneMapping()) / this._oidnInputScale;
|
|
16593
16655
|
}
|
|
16594
16656
|
_applyColorScale(e, t) {
|
|
16595
16657
|
let n = this._oidnInputScale;
|
|
16596
16658
|
if (!this._ensureColorScalePipeline(e)) return;
|
|
16597
16659
|
e.queue.writeBuffer(this._colorScaleUniform, 0, new Float32Array([n]));
|
|
16598
|
-
let r = Math.ceil(t /
|
|
16660
|
+
let r = Math.ceil(t / Om), i = Math.min(r, km), a = Math.ceil(r / i), o = e.createCommandEncoder({ label: "oidn-color-scale" }), s = o.beginComputePass({ label: "oidn-color-scale" });
|
|
16599
16661
|
s.setPipeline(this._colorScalePipeline), s.setBindGroup(0, this._colorScaleBindGroup), s.dispatchWorkgroups(i, a, 1), s.end(), e.queue.submit([o.finish()]);
|
|
16600
16662
|
}
|
|
16601
16663
|
_ensureColorScalePipeline(e) {
|
|
@@ -16606,7 +16668,7 @@ var Tm = class extends lt {
|
|
|
16606
16668
|
compute: {
|
|
16607
16669
|
module: e.createShaderModule({
|
|
16608
16670
|
label: "oidn-color-scale",
|
|
16609
|
-
code:
|
|
16671
|
+
code: Dm
|
|
16610
16672
|
}),
|
|
16611
16673
|
entryPoint: "main"
|
|
16612
16674
|
}
|
|
@@ -16663,10 +16725,10 @@ var Tm = class extends lt {
|
|
|
16663
16725
|
}
|
|
16664
16726
|
r.queue.submit([d.finish()]);
|
|
16665
16727
|
let f = u.mapAsync(GPUMapMode.READ).then(() => {
|
|
16666
|
-
let e = new Float32Array(u.getMappedRange()), t = new ImageData(o, s), r = this._outputExposure(), c = this.getSaturation(), l =
|
|
16728
|
+
let e = new Float32Array(u.getMappedRange()), t = new ImageData(o, s), r = this._outputExposure(), c = this.getSaturation(), l = mm.get(this.getToneMapping()) || mm.get(He), d = this._cachedAlpha, f = this._cachedAlphaWidth;
|
|
16667
16729
|
for (let i = 0, a = e.length; i < a; i += 4) {
|
|
16668
16730
|
let a = e[i] * r, s = e[i + 1] * r, u = e[i + 2] * r;
|
|
16669
|
-
if (c !== 1 && (
|
|
16731
|
+
if (c !== 1 && (Tm[0] = a, Tm[1] = s, Tm[2] = u, xm(Tm, c), a = Tm[0], s = Tm[1], u = Tm[2]), l(a, s, u, 1, Tm), t.data[i] = gm(Tm[0]) * 255 + .5 | 0, t.data[i + 1] = gm(Tm[1]) * 255 + .5 | 0, t.data[i + 2] = gm(Tm[2]) * 255 + .5 | 0, d) {
|
|
16670
16732
|
let e = (i >> 2) % o, r = (i >> 2) / o | 0;
|
|
16671
16733
|
t.data[i + 3] = d[(n.y + r) * f + n.x + e];
|
|
16672
16734
|
} else t.data[i + 3] = 255;
|
|
@@ -16693,7 +16755,7 @@ var Tm = class extends lt {
|
|
|
16693
16755
|
async _displayGPUOutput({ data: e, width: t, height: n }) {
|
|
16694
16756
|
let r = this.gpuDevice;
|
|
16695
16757
|
if (!r) {
|
|
16696
|
-
|
|
16758
|
+
Sm.error("gpuDevice not available for output readback");
|
|
16697
16759
|
return;
|
|
16698
16760
|
}
|
|
16699
16761
|
let i = t * n * 4 * 4, a = r.createBuffer({
|
|
@@ -16704,10 +16766,10 @@ var Tm = class extends lt {
|
|
|
16704
16766
|
try {
|
|
16705
16767
|
let o = r.createCommandEncoder({ label: "oidn-readback" });
|
|
16706
16768
|
o.copyBufferToBuffer(e, 0, a, 0, i), r.queue.submit([o.finish()]), await a.mapAsync(GPUMapMode.READ);
|
|
16707
|
-
let s = new Float32Array(a.getMappedRange()), c = new ImageData(t, n), l = this._outputExposure(), u = this.getSaturation(), d =
|
|
16769
|
+
let s = new Float32Array(a.getMappedRange()), c = new ImageData(t, n), l = this._outputExposure(), u = this.getSaturation(), d = mm.get(this.getToneMapping()) || mm.get(He), f = this._cachedAlpha;
|
|
16708
16770
|
for (let e = 0, t = s.length; e < t; e += 4) {
|
|
16709
16771
|
let t = s[e] * l, n = s[e + 1] * l, r = s[e + 2] * l;
|
|
16710
|
-
u !== 1 && (
|
|
16772
|
+
u !== 1 && (Tm[0] = t, Tm[1] = n, Tm[2] = r, xm(Tm, u), t = Tm[0], n = Tm[1], r = Tm[2]), d(t, n, r, 1, Tm), c.data[e] = gm(Tm[0]) * 255 + .5 | 0, c.data[e + 1] = gm(Tm[1]) * 255 + .5 | 0, c.data[e + 2] = gm(Tm[2]) * 255 + .5 | 0, c.data[e + 3] = f ? f[e >> 2] : 255;
|
|
16711
16773
|
}
|
|
16712
16774
|
a.unmap(), this.ctx.putImageData(c, 0, 0);
|
|
16713
16775
|
} finally {
|
|
@@ -16715,12 +16777,12 @@ var Tm = class extends lt {
|
|
|
16715
16777
|
}
|
|
16716
16778
|
}
|
|
16717
16779
|
abort() {
|
|
16718
|
-
this._pendingStart = !1, !(!this.enabled || !this.state.isDenoising) && (this.state.abortController?.abort(), this._destroyPendingStagingBuffers(), this.input.style.opacity = "1", this.state.isDenoising = !1, this.dispatchEvent({ type: "end" }),
|
|
16780
|
+
this._pendingStart = !1, !(!this.enabled || !this.state.isDenoising) && (this.state.abortController?.abort(), this._destroyPendingStagingBuffers(), this.input.style.opacity = "1", this.state.isDenoising = !1, this.dispatchEvent({ type: "end" }), Sm.debug("denoise aborted"));
|
|
16719
16781
|
}
|
|
16720
16782
|
setSize(e, t) {
|
|
16721
16783
|
if (e <= 0 || t <= 0) throw Error(`Invalid dimensions: ${e}x${t}`);
|
|
16722
16784
|
this.output.width = e, this.output.height = t, this._setupUNetDenoiser().catch((e) => {
|
|
16723
|
-
|
|
16785
|
+
Sm.error("reinitialize after size change failed:", e);
|
|
16724
16786
|
});
|
|
16725
16787
|
}
|
|
16726
16788
|
_destroyPendingStagingBuffers() {
|
|
@@ -16728,13 +16790,13 @@ var Tm = class extends lt {
|
|
|
16728
16790
|
this._pendingStagingBuffers.clear();
|
|
16729
16791
|
}
|
|
16730
16792
|
dispose() {
|
|
16731
|
-
this.abort(), this._destroyPendingStagingBuffers(), this.unet?.dispose(), this._destroyGPUInputBuffers(), this._colorScalePipeline = null, this.output?.parentNode && this.output.remove(), this.unet = null, this.ctx = null, this.state.abortController = null, this.removeAllListeners?.(),
|
|
16793
|
+
this.abort(), this._destroyPendingStagingBuffers(), this.unet?.dispose(), this._destroyGPUInputBuffers(), this._colorScalePipeline = null, this.output?.parentNode && this.output.remove(), this.unet = null, this.ctx = null, this.state.abortController = null, this.removeAllListeners?.(), Sm.debug("disposed");
|
|
16732
16794
|
}
|
|
16733
|
-
},
|
|
16734
|
-
function
|
|
16795
|
+
}, Nm = "let e={ortRuntimeUrl:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/ort.webgpu.bundle.min.mjs`,ortWasmPaths:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.3/dist/`,cacheNamespace:`rayzee`},t=null;async function n(){return t||(t=await import(e.ortRuntimeUrl),t.env.wasm.wasmPaths=e.ortWasmPaths,t.env.logLevel=`error`,t)}function r(){return`${e.cacheNamespace}:ai-upscaler-models`}const i=`models`;let a=null,o=null;function s(){return new Promise((e,t)=>{let n=indexedDB.open(r(),1);n.onupgradeneeded=()=>n.result.createObjectStore(i),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}async function c(e){try{let t=await s();return await new Promise((n,r)=>{let a=t.transaction(i,`readonly`).objectStore(i).get(e);a.onsuccess=()=>n(a.result||null),a.onerror=()=>r(a.error)})}catch{return null}}async function l(e,t){try{let n=await s();await new Promise((r,a)=>{let o=n.transaction(i,`readwrite`);o.objectStore(i).put(t,e),o.oncomplete=()=>r(),o.onerror=()=>a(o.error)})}catch{}}async function u(e){let t=await c(e);if(t)return console.log(`AI Upscaler Worker: model loaded from cache (${(t.byteLength/1024/1024).toFixed(1)}MB)`),t;let n=await fetch(e);if(!n.ok)throw Error(`Failed to fetch model: ${n.status}`);let r=await n.arrayBuffer();return l(e,r.slice(0)),r}async function d(e,t){if(a&&o===e){self.postMessage({type:`loaded`,backend:`webgpu`});return}a&&=(await a.release(),null);let[r,i]=await Promise.all([u(e),n()]);a=await i.InferenceSession.create(r,t),o=e;let s=512;try{let e=await navigator.gpu?.requestAdapter(),t=await e?.requestAdapterInfo?.()||e?.info,n=/apple|swiftshader|llvmpipe/i.test(t?.vendor||``)||/apple|swiftshader/i.test(t?.architecture||``),r=t?.device?.toLowerCase?.()?.includes(`integrated`)||/intel.*iris|intel.*uhd|intel.*hd|amd.*vega|radeon.*graphics/i.test(t?.description||``);s=n?128:r?256:512,console.log(`AI Upscaler Worker: GPU=\"${t?.description||t?.device||`unknown`}\", tileSize=${s}`)}catch{}let c=(r.byteLength/1024/1024).toFixed(1);console.log(`AI Upscaler Worker: model loaded (${c}MB), backend: webgpu`),self.postMessage({type:`loaded`,backend:`webgpu`,tileSize:s})}async function f(e,t,r,i){let o=await n(),s=a.inputNames[0],c=a.outputNames[0],l=new o.Tensor(`float32`,e,[1,3,r,t]),u=(await a.run({[s]:l}))[c].data;self.postMessage({type:`inferred`,outputData:u,id:i},[u.buffer])}self.onmessage=async t=>{let{type:n}=t.data;try{n===`load`?(t.data.ortRuntimeUrl&&(e.ortRuntimeUrl=t.data.ortRuntimeUrl),t.data.ortWasmPaths&&(e.ortWasmPaths=t.data.ortWasmPaths),t.data.cacheNamespace&&(e.cacheNamespace=t.data.cacheNamespace),await d(t.data.url,t.data.sessionOptions)):n===`infer`?await f(t.data.tileData,t.data.width,t.data.height,t.data.id):n===`dispose`&&a&&(await a.release(),a=null,o=null)}catch(e){self.postMessage({type:`error`,message:e.message,id:t.data?.id})}};", Pm = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", Nm], { type: "text/javascript;charset=utf-8" });
|
|
16796
|
+
function Fm(e) {
|
|
16735
16797
|
let t;
|
|
16736
16798
|
try {
|
|
16737
|
-
if (t =
|
|
16799
|
+
if (t = Pm && (self.URL || self.webkitURL).createObjectURL(Pm), !t) throw "";
|
|
16738
16800
|
let n = new Worker(t, {
|
|
16739
16801
|
type: "module",
|
|
16740
16802
|
name: e?.name
|
|
@@ -16743,7 +16805,7 @@ function Om(e) {
|
|
|
16743
16805
|
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
16744
16806
|
}), n;
|
|
16745
16807
|
} catch {
|
|
16746
|
-
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
16808
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(Nm), {
|
|
16747
16809
|
type: "module",
|
|
16748
16810
|
name: e?.name
|
|
16749
16811
|
});
|
|
@@ -16751,7 +16813,7 @@ function Om(e) {
|
|
|
16751
16813
|
}
|
|
16752
16814
|
//#endregion
|
|
16753
16815
|
//#region src/Passes/AIUpscaler.js
|
|
16754
|
-
var
|
|
16816
|
+
var Im = {
|
|
16755
16817
|
fast: {
|
|
16756
16818
|
2: "2x-spanx2-ch48.onnx",
|
|
16757
16819
|
4: "4xNomos8k_span_otf_strong_fp32_opset17.onnx"
|
|
@@ -16765,17 +16827,17 @@ var km = {
|
|
|
16765
16827
|
4: "4xNomos2_hq_mosr_fp32.onnx"
|
|
16766
16828
|
}
|
|
16767
16829
|
};
|
|
16768
|
-
function
|
|
16830
|
+
function Lm() {
|
|
16769
16831
|
let { upscalerModelBaseUrl: e } = ml(), t = {};
|
|
16770
|
-
for (let n in
|
|
16832
|
+
for (let n in Im) {
|
|
16771
16833
|
t[n] = {};
|
|
16772
|
-
for (let r in
|
|
16834
|
+
for (let r in Im[n]) t[n][r] = e + Im[n][r];
|
|
16773
16835
|
}
|
|
16774
16836
|
return t;
|
|
16775
16837
|
}
|
|
16776
|
-
var
|
|
16838
|
+
var Rm = {
|
|
16777
16839
|
get QUALITY_PRESETS() {
|
|
16778
|
-
return
|
|
16840
|
+
return Lm();
|
|
16779
16841
|
},
|
|
16780
16842
|
TILE_SIZE: 512,
|
|
16781
16843
|
TILE_OVERLAP: 16,
|
|
@@ -16786,17 +16848,17 @@ var jm = {
|
|
|
16786
16848
|
}],
|
|
16787
16849
|
graphOptimizationLevel: "all"
|
|
16788
16850
|
}
|
|
16789
|
-
},
|
|
16851
|
+
}, zm = class extends lt {
|
|
16790
16852
|
constructor(e, t, n = {}) {
|
|
16791
16853
|
if (super(), !e || !t) throw Error("AIUpscaler requires output canvas and renderer");
|
|
16792
|
-
this.renderer = t, this.input = t.domElement, this.output = e, this.getSourceCanvas = n.getSourceCanvas || null, this.getGPUTextures = n.getGPUTextures || null, this.getExposure = n.getExposure || (() => 1), this.getToneMapping = n.getToneMapping || (() => He), this.getSaturation = n.getSaturation || (() => 1), this.enabled = !1, this.hdr = !1, this.scaleFactor = n.scaleFactor || 2, this.quality = n.quality || "fast", this.refreshInput = n.refreshInput || null, this.tileSize = n.tileSize ||
|
|
16854
|
+
this.renderer = t, this.input = t.domElement, this.output = e, this.getSourceCanvas = n.getSourceCanvas || null, this.getGPUTextures = n.getGPUTextures || null, this.getExposure = n.getExposure || (() => 1), this.getToneMapping = n.getToneMapping || (() => He), this.getSaturation = n.getSaturation || (() => 1), this.enabled = !1, this.hdr = !1, this.scaleFactor = n.scaleFactor || 2, this.quality = n.quality || "fast", this.refreshInput = n.refreshInput || null, this.tileSize = n.tileSize || Rm.TILE_SIZE, this._tileSizeOverride = !!n.tileSize, this.state = {
|
|
16793
16855
|
isUpscaling: !1,
|
|
16794
16856
|
isLoading: !1,
|
|
16795
16857
|
abortController: null
|
|
16796
16858
|
}, this._worker = null, this._currentModelUrl = null, this._tileId = 0, this._pendingWorkerHandlers = /* @__PURE__ */ new Set(), this._upscaledAlpha = null, this._upscaledAlphaWidth = 0, this._backupCanvas = null, this._baseWidth = e.width, this._baseHeight = e.height, this._hdrStagingBuffer = null, this._hdrStagingWidth = 0, this._hdrStagingHeight = 0;
|
|
16797
16859
|
}
|
|
16798
16860
|
async _ensureSession() {
|
|
16799
|
-
let e =
|
|
16861
|
+
let e = Rm.QUALITY_PRESETS[this.quality];
|
|
16800
16862
|
if (!e) throw Error(`Unknown quality preset: ${this.quality}`);
|
|
16801
16863
|
let t = e[this.scaleFactor];
|
|
16802
16864
|
if (!t) throw Error(`No model for ${this.quality}/${this.scaleFactor}x`);
|
|
@@ -16806,14 +16868,14 @@ var jm = {
|
|
|
16806
16868
|
message: `Loading ${this.scaleFactor}x upscale model...`
|
|
16807
16869
|
});
|
|
16808
16870
|
try {
|
|
16809
|
-
this._worker ||= new
|
|
16871
|
+
this._worker ||= new Fm(), await new Promise((e, n) => {
|
|
16810
16872
|
let r = (t) => {
|
|
16811
16873
|
t.data.type === "loaded" ? (this._worker.removeEventListener("message", r), t.data.tileSize && !this._tileSizeOverride && (this.tileSize = t.data.tileSize), console.log(`AI Upscaler: ${this.scaleFactor}x model loaded, backend: ${t.data.backend}, tileSize: ${this.tileSize}`), e()) : t.data.type === "error" && (this._worker.removeEventListener("message", r), n(Error(t.data.message)));
|
|
16812
16874
|
}, { ortRuntimeUrl: i, ortWasmPaths: a, cacheNamespace: o } = ml();
|
|
16813
16875
|
this._worker.addEventListener("message", r), this._worker.postMessage({
|
|
16814
16876
|
type: "load",
|
|
16815
16877
|
url: t,
|
|
16816
|
-
sessionOptions:
|
|
16878
|
+
sessionOptions: Rm.SESSION_OPTIONS,
|
|
16817
16879
|
ortRuntimeUrl: i,
|
|
16818
16880
|
ortWasmPaths: a,
|
|
16819
16881
|
cacheNamespace: o
|
|
@@ -16886,8 +16948,8 @@ var jm = {
|
|
|
16886
16948
|
willReadFrequently: !0,
|
|
16887
16949
|
alpha: !0
|
|
16888
16950
|
});
|
|
16889
|
-
this._cacheUpscaledAlpha(t, n * i, r * i), t.isHDR && (this._hdrToneMapFn =
|
|
16890
|
-
let o =
|
|
16951
|
+
this._cacheUpscaledAlpha(t, n * i, r * i), t.isHDR && (this._hdrToneMapFn = mm.get(this.getToneMapping()) || mm.get(He), this._hdrExposure = _m(this.getExposure(), this.getToneMapping()), this._hdrSaturation = this.getSaturation(), this._tmOut = new Float32Array(3));
|
|
16952
|
+
let o = Rm.TILE_OVERLAP, s = this.tileSize, c = s - o * 2, l = Math.ceil(n / c), u = Math.ceil(r / c), d = l * u, f = 0;
|
|
16891
16953
|
for (let o = 0; o < u; o++) for (let u = 0; u < l; u++) {
|
|
16892
16954
|
if (e.aborted) throw new DOMException("Aborted", "AbortError");
|
|
16893
16955
|
let l = Math.min(u * c, Math.max(0, n - s)), p = Math.min(o * c, Math.max(0, r - s)), m = Math.min(s, n - l), h = Math.min(s, r - p), g = this._extractTile(t, l, p, m, h), _ = await this._inferTile(g, m, h), v = l * i, y = p * i, b = m * i, x = h * i, S = this._tensorToImageData(_, b, x, v, y);
|
|
@@ -16961,7 +17023,7 @@ var jm = {
|
|
|
16961
17023
|
let u = ((n + e) * o + (t + i)) * 4, d = e * r + i;
|
|
16962
17024
|
if (s) {
|
|
16963
17025
|
let e = this._hdrToneMapFn, t = this._hdrExposure, n = this._hdrSaturation, r = a[u] * t, i = a[u + 1] * t, o = a[u + 2] * t;
|
|
16964
|
-
n !== 1 && (this._tmOut[0] = r, this._tmOut[1] = i, this._tmOut[2] = o,
|
|
17026
|
+
n !== 1 && (this._tmOut[0] = r, this._tmOut[1] = i, this._tmOut[2] = o, xm(this._tmOut, n), r = this._tmOut[0], i = this._tmOut[1], o = this._tmOut[2]), e(r, i, o, 1, this._tmOut), l[d] = this._tmOut[0] ** +hm, l[c + d] = this._tmOut[1] ** +hm, l[2 * c + d] = this._tmOut[2] ** +hm;
|
|
16965
17027
|
} else l[d] = a[u] / 255, l[c + d] = a[u + 1] / 255, l[2 * c + d] = a[u + 2] / 255;
|
|
16966
17028
|
}
|
|
16967
17029
|
return l;
|
|
@@ -17019,10 +17081,10 @@ var jm = {
|
|
|
17019
17081
|
this._backupCanvas = document.createElement("canvas"), this._backupCanvas.width = e.width, this._backupCanvas.height = e.height;
|
|
17020
17082
|
let t = this._backupCanvas.getContext("2d");
|
|
17021
17083
|
if (e.isHDR) {
|
|
17022
|
-
let { data: n, width: r, height: i } = e, a = t.createImageData(r, i), o = a.data, s =
|
|
17084
|
+
let { data: n, width: r, height: i } = e, a = t.createImageData(r, i), o = a.data, s = mm.get(this.getToneMapping()) || mm.get(He), c = _m(this.getExposure(), this.getToneMapping()), l = this.getSaturation(), u = new Float32Array(3);
|
|
17023
17085
|
for (let e = 0, t = r * i; e < t; e++) {
|
|
17024
17086
|
let t = e * 4, r = n[t] * c, i = n[t + 1] * c, a = n[t + 2] * c;
|
|
17025
|
-
l !== 1 && (u[0] = r, u[1] = i, u[2] = a,
|
|
17087
|
+
l !== 1 && (u[0] = r, u[1] = i, u[2] = a, xm(u, l), r = u[0], i = u[1], a = u[2]), s(r, i, a, 1, u), o[t] = u[0] ** +hm * 255 + .5 | 0, o[t + 1] = u[1] ** +hm * 255 + .5 | 0, o[t + 2] = u[2] ** +hm * 255 + .5 | 0, o[t + 3] = 255;
|
|
17026
17088
|
}
|
|
17027
17089
|
t.putImageData(a, 0, 0);
|
|
17028
17090
|
} else t.putImageData(e, 0, 0);
|
|
@@ -17034,7 +17096,7 @@ var jm = {
|
|
|
17034
17096
|
this.hdr = !!e;
|
|
17035
17097
|
}
|
|
17036
17098
|
setQuality(e) {
|
|
17037
|
-
if (!
|
|
17099
|
+
if (!Rm.QUALITY_PRESETS[e]) {
|
|
17038
17100
|
console.warn(`AIUpscaler: Invalid quality "${e}", must be fast/balanced/quality`);
|
|
17039
17101
|
return;
|
|
17040
17102
|
}
|
|
@@ -17057,7 +17119,7 @@ var jm = {
|
|
|
17057
17119
|
async dispose() {
|
|
17058
17120
|
this.abort(), this._cleanupPendingWorkerHandlers(), this._worker &&= (this._worker.postMessage({ type: "dispose" }), this._worker.terminate(), null), this._currentModelUrl = null, this._backupCanvas = null, this._upscaledAlpha = null, this.state.abortController = null, this._hdrStagingBuffer?.destroy(), this._hdrStagingBuffer = null, this._hdrStagingWidth = 0, this._hdrStagingHeight = 0, console.log("AIUpscaler disposed");
|
|
17059
17121
|
}
|
|
17060
|
-
},
|
|
17122
|
+
}, Bm = class extends lt {
|
|
17061
17123
|
constructor({ renderer: e, mainCanvas: t, scene: n, camera: r, stages: i, pipeline: a, getExposure: o, getSaturation: s, getTransparentBg: c }) {
|
|
17062
17124
|
super(), this.renderer = e, this.mainCanvas = t, this.denoiserCanvas = this._createDenoiserCanvas(t), this.scene = n, this.camera = r, this.pipeline = a, this._stages = i, this._getExposure = o, this._getSaturation = s, this._getTransparentBg = c, this.denoiser = null, this.upscaler = null, this._onReset = null, this._onPostProcessRefresh = null, this._lastRenderWidth = 0, this._lastRenderHeight = 0, this._pendingStartUpscaler = null, this._denoiserStartHandler = null, this._denoiserEndHandler = null, this._upscalerResChangedHandler = null, this._upscalerStartHandler = null, this._upscalerProgressHandler = null, this._upscalerEndHandler = null;
|
|
17063
17125
|
}
|
|
@@ -17078,7 +17140,7 @@ var jm = {
|
|
|
17078
17140
|
setupDenoiser() {
|
|
17079
17141
|
if (!this.denoiserCanvas) return;
|
|
17080
17142
|
let e = this._stages.pathTracer;
|
|
17081
|
-
this.denoiser = new
|
|
17143
|
+
this.denoiser = new Mm(this.denoiserCanvas, this.renderer, this.scene, this.camera, {
|
|
17082
17144
|
...Y,
|
|
17083
17145
|
backendParams: () => ({
|
|
17084
17146
|
device: this.renderer.backend.device,
|
|
@@ -17107,7 +17169,7 @@ var jm = {
|
|
|
17107
17169
|
setupUpscaler() {
|
|
17108
17170
|
if (!this.denoiserCanvas) return;
|
|
17109
17171
|
let e = this._stages.pathTracer;
|
|
17110
|
-
this.upscaler = new
|
|
17172
|
+
this.upscaler = new zm(this.denoiserCanvas, this.renderer, {
|
|
17111
17173
|
scaleFactor: Y.upscalerScale || 2,
|
|
17112
17174
|
quality: Y.upscalerQuality || "fast",
|
|
17113
17175
|
getSourceCanvas: () => this.denoiser?.enabled ? null : this.renderer.domElement,
|
|
@@ -17262,7 +17324,7 @@ var jm = {
|
|
|
17262
17324
|
let t = jr[e];
|
|
17263
17325
|
t && (this._stages.asvgf?.updateParameters(t), this._stages.bilateralFilter?.updateParameters(t), this._stages.variance && t.varianceBoost !== void 0 && (this._stages.variance.varianceBoost.value = t.varianceBoost));
|
|
17264
17326
|
}
|
|
17265
|
-
},
|
|
17327
|
+
}, Vm = class {
|
|
17266
17328
|
constructor() {
|
|
17267
17329
|
this.layer = "hud", this.visible = !1, this._tileBounds = null, this._imageWidth = 1, this._imageHeight = 1, this.enabled = !0, this._borderColor = "rgba(255, 0, 0, 0.6)", this._borderWidthRatio = 1 / 540, this._borderWidthMin = 1.5, this._borderWidthMax = 4;
|
|
17268
17330
|
}
|
|
@@ -17286,7 +17348,7 @@ var jm = {
|
|
|
17286
17348
|
dispose() {
|
|
17287
17349
|
this.visible = !1;
|
|
17288
17350
|
}
|
|
17289
|
-
},
|
|
17351
|
+
}, Hm = class {
|
|
17290
17352
|
constructor(n, r) {
|
|
17291
17353
|
this.layer = "scene", this._enabled = !0, this._outlineNode = xn(n, r, {
|
|
17292
17354
|
selectedObjects: [],
|
|
@@ -17317,11 +17379,11 @@ var jm = {
|
|
|
17317
17379
|
this._enabled = !1, this._outlineNode?.dispose(), this._material?.dispose(), this._quad = null;
|
|
17318
17380
|
}
|
|
17319
17381
|
};
|
|
17320
|
-
function
|
|
17382
|
+
function Um(e = !1) {
|
|
17321
17383
|
let t = document.createElement("canvas");
|
|
17322
17384
|
return t.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;" + (e ? "display:none;" : ""), t;
|
|
17323
17385
|
}
|
|
17324
|
-
function
|
|
17386
|
+
function Wm(e, t = Infinity) {
|
|
17325
17387
|
let n = e?.getBoundingClientRect();
|
|
17326
17388
|
if (!n || n.width === 0 || n.height === 0) return null;
|
|
17327
17389
|
let r = Math.min(window.devicePixelRatio || 1, 2), i = Math.round(n.width * r), a = Math.round(n.height * r), o = t / Math.max(i, a);
|
|
@@ -17332,9 +17394,9 @@ function Lm(e, t = Infinity) {
|
|
|
17332
17394
|
}
|
|
17333
17395
|
//#endregion
|
|
17334
17396
|
//#region src/managers/helpers/ViewOverlayRenderer.js
|
|
17335
|
-
var
|
|
17397
|
+
var Gm = 4096, Km = class {
|
|
17336
17398
|
constructor() {
|
|
17337
|
-
this.canvas =
|
|
17399
|
+
this.canvas = Um(!0), this._visible = !1, this.renderer = null, this._sizeSource = null;
|
|
17338
17400
|
}
|
|
17339
17401
|
async init({ device: e, sizeSource: t }) {
|
|
17340
17402
|
this._sizeSource = t;
|
|
@@ -17351,7 +17413,7 @@ var Rm = 4096, zm = class {
|
|
|
17351
17413
|
}
|
|
17352
17414
|
syncSize() {
|
|
17353
17415
|
if (!this.renderer) return;
|
|
17354
|
-
let e =
|
|
17416
|
+
let e = Wm(this._sizeSource, Gm);
|
|
17355
17417
|
!e || e.width === this.canvas.width && e.height === this.canvas.height || this.renderer.setSize(e.width, e.height, !1);
|
|
17356
17418
|
}
|
|
17357
17419
|
begin() {
|
|
@@ -17363,18 +17425,18 @@ var Rm = 4096, zm = class {
|
|
|
17363
17425
|
dispose() {
|
|
17364
17426
|
Sr(this.renderer), this.renderer = null, this.canvas.parentElement?.removeChild(this.canvas);
|
|
17365
17427
|
}
|
|
17366
|
-
},
|
|
17428
|
+
}, qm = ci("overlay"), Jm = (e, t) => e.visible && e.layer === t && e.render, Ym = class {
|
|
17367
17429
|
constructor(e) {
|
|
17368
|
-
this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas =
|
|
17430
|
+
this.camera = e, this._helpers = /* @__PURE__ */ new Map(), this._hudCanvas = Um(), this._hudCtx = this._hudCanvas.getContext("2d"), this._helperScene = null, this._viewOverlay = null;
|
|
17369
17431
|
}
|
|
17370
17432
|
async initViewRenderer({ device: e, sizeSource: t }) {
|
|
17371
17433
|
if (!(!e || !t)) try {
|
|
17372
|
-
this._viewOverlay = await new
|
|
17434
|
+
this._viewOverlay = await new Km().init({
|
|
17373
17435
|
device: e,
|
|
17374
17436
|
sizeSource: t
|
|
17375
17437
|
});
|
|
17376
17438
|
} catch (e) {
|
|
17377
|
-
|
|
17439
|
+
qm.error("overlay surface unavailable — light gizmos, transform gizmo and outlines are disabled", e), this._viewOverlay = null;
|
|
17378
17440
|
}
|
|
17379
17441
|
}
|
|
17380
17442
|
setHelperScene(e) {
|
|
@@ -17390,11 +17452,11 @@ var Rm = 4096, zm = class {
|
|
|
17390
17452
|
}
|
|
17391
17453
|
setupDefaultHelpers({ helperScene: e, meshScene: t, pipeline: n, denoisingManager: r, app: i, renderWidth: a, renderHeight: o }) {
|
|
17392
17454
|
this.setHelperScene(e);
|
|
17393
|
-
let s = new
|
|
17455
|
+
let s = new Vm();
|
|
17394
17456
|
this.register("tiles", s), s.setRenderSize(a || 1, o || 1), i.addEventListener("resolution_changed", (e) => {
|
|
17395
17457
|
s.setRenderSize(e.width, e.height);
|
|
17396
17458
|
}), n.eventBus.on("pipeline:reset", () => s.hide()), this._wireDenoiserTileEvents(s, r);
|
|
17397
|
-
let c = new
|
|
17459
|
+
let c = new Hm(t, this.camera);
|
|
17398
17460
|
this.register("outline", c);
|
|
17399
17461
|
}
|
|
17400
17462
|
_wireDenoiserTileEvents(e, t) {
|
|
@@ -17406,7 +17468,7 @@ var Rm = 4096, zm = class {
|
|
|
17406
17468
|
}));
|
|
17407
17469
|
}
|
|
17408
17470
|
register(e, t) {
|
|
17409
|
-
this._helpers.has(e) && (
|
|
17471
|
+
this._helpers.has(e) && (qm.warn(`helper "${e}" already registered — replacing.`), this._helpers.get(e).dispose?.()), this._helpers.set(e, t);
|
|
17410
17472
|
}
|
|
17411
17473
|
unregister(e) {
|
|
17412
17474
|
let t = this._helpers.get(e);
|
|
@@ -17444,16 +17506,16 @@ var Rm = 4096, zm = class {
|
|
|
17444
17506
|
}
|
|
17445
17507
|
_renderSceneLayer(e) {
|
|
17446
17508
|
this._helperScene?.render(e, this.camera);
|
|
17447
|
-
for (let t of this._helpers.values())
|
|
17509
|
+
for (let t of this._helpers.values()) Jm(t, "scene") && t.render(e, this.camera);
|
|
17448
17510
|
}
|
|
17449
17511
|
_hasVisibleSceneOverlay() {
|
|
17450
17512
|
if (this._helperScene?.isDrawing) return !0;
|
|
17451
|
-
for (let e of this._helpers.values()) if (
|
|
17513
|
+
for (let e of this._helpers.values()) if (Jm(e, "scene")) return !0;
|
|
17452
17514
|
return !1;
|
|
17453
17515
|
}
|
|
17454
17516
|
refreshHUD() {
|
|
17455
17517
|
let e = this._hudCanvas, t = this._hudCtx, n = !1;
|
|
17456
|
-
for (let e of this._helpers.values()) if (
|
|
17518
|
+
for (let e of this._helpers.values()) if (Jm(e, "hud")) {
|
|
17457
17519
|
n = !0;
|
|
17458
17520
|
break;
|
|
17459
17521
|
}
|
|
@@ -17462,10 +17524,10 @@ var Rm = 4096, zm = class {
|
|
|
17462
17524
|
return;
|
|
17463
17525
|
}
|
|
17464
17526
|
e.style.display !== "" && (e.style.display = "");
|
|
17465
|
-
let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ?
|
|
17527
|
+
let r = e.clientWidth, i = e.clientHeight, a = r > 0 && i > 0 ? Wm(e) : null;
|
|
17466
17528
|
if (a) {
|
|
17467
17529
|
(e.width !== a.width || e.height !== a.height) && (e.width = a.width, e.height = a.height), t.clearRect(0, 0, a.width, a.height), t.save(), t.scale(a.width / r, a.height / i);
|
|
17468
|
-
for (let e of this._helpers.values())
|
|
17530
|
+
for (let e of this._helpers.values()) Jm(e, "hud") && e.render(t, r, i);
|
|
17469
17531
|
t.restore(), e.style.display !== "" && (e.style.display = "");
|
|
17470
17532
|
}
|
|
17471
17533
|
}
|
|
@@ -17473,7 +17535,7 @@ var Rm = 4096, zm = class {
|
|
|
17473
17535
|
for (let e of this._helpers.values()) e.dispose?.();
|
|
17474
17536
|
this._helpers.clear(), this._viewOverlay?.dispose(), this._viewOverlay = null, this._hudCanvas.parentElement && this._hudCanvas.parentElement.removeChild(this._hudCanvas);
|
|
17475
17537
|
}
|
|
17476
|
-
},
|
|
17538
|
+
}, Xm = class extends lt {
|
|
17477
17539
|
constructor() {
|
|
17478
17540
|
super(), this.mixer = null, this.timer = new tn(), this.actions = [], this.isPlaying = !1, this._scene = null, this._mixerRoot = null, this._meshes = null, this._meshTriRanges = null, this._posBuffer = null, this._tempVec = new sn(), this._skinnedCache = null, this._clipsCache = null, this._savedTimeScale = 1, this.onFinished = null, this.wakeCallback = null;
|
|
17479
17541
|
}
|
|
@@ -17573,7 +17635,7 @@ var Rm = 4096, zm = class {
|
|
|
17573
17635
|
dispose() {
|
|
17574
17636
|
this.mixer &&= (this.mixer.stopAllAction(), this.mixer.uncacheRoot(this._mixerRoot), null), this.actions = [], this.isPlaying = !1, this.timer.reset(), this._scene = null, this._mixerRoot = null, this._meshes = null, this._meshTriRanges = null, this._posBuffer = null, this._skinnedCache = null, this._clipsCache = null;
|
|
17575
17637
|
}
|
|
17576
|
-
},
|
|
17638
|
+
}, Zm = new sn(0, 0, -1), Qm = class {
|
|
17577
17639
|
constructor({ camera: e, canvas: t, orbitControls: n, app: r }) {
|
|
17578
17640
|
this._app = r, this._orbitControls = n, this._camera = e, this._controls = new Sn(e, t), this._gizmoScene = new Jt(), this._gizmoScene.add(this._controls.getHelper()), this._attached = null, this._isDragging = !1, this._meshes = null, this._meshTriRanges = null, this._posBuffer = null, this._normalBuffer = null, this._skinnedCache = null, this._normalCache = null, this._tempVec = new sn(), this._normalMatrix = new xt(), this._refitInFlight = !1, this._baselineComputed = !1, this._tempForward = new sn(), this._lightTargetDistance = null, this._lastLightPosition = null, this._onDraggingChanged = this._onDraggingChanged.bind(this), this._onObjectChange = this._onObjectChange.bind(this), this._controls.addEventListener("dragging-changed", this._onDraggingChanged), this._controls.addEventListener("objectChange", this._onObjectChange);
|
|
17579
17641
|
}
|
|
@@ -17594,7 +17656,7 @@ var Rm = 4096, zm = class {
|
|
|
17594
17656
|
attach(e) {
|
|
17595
17657
|
if (this._attached !== e && (this._controls.attach(e), this._attached = e, this._lightTargetDistance = null, this._lastLightPosition = null, e.isLight && e.target)) {
|
|
17596
17658
|
let t = e.target.position.clone().sub(e.position), n = t.length();
|
|
17597
|
-
n > 1e-4 ? (e.quaternion.setFromUnitVectors(
|
|
17659
|
+
n > 1e-4 ? (e.quaternion.setFromUnitVectors(Zm, t.normalize()), this._lightTargetDistance = n) : this._lightTargetDistance = 1, this._lastLightPosition = e.position.clone();
|
|
17598
17660
|
}
|
|
17599
17661
|
}
|
|
17600
17662
|
detach() {
|
|
@@ -17706,7 +17768,7 @@ var Rm = 4096, zm = class {
|
|
|
17706
17768
|
dispose() {
|
|
17707
17769
|
this._controls.removeEventListener("dragging-changed", this._onDraggingChanged), this._controls.removeEventListener("objectChange", this._onObjectChange), this.detach(), this._gizmoScene.remove(this._controls.getHelper()), this._controls.dispose(), this._meshes = null, this._meshTriRanges = null, this._posBuffer = null, this._normalBuffer = null, this._skinnedCache = null, this._normalCache = null, this._baselineComputed = !1, this._tempForward = null, this._lightTargetDistance = null, this._lastLightPosition = null, this._app = null, this._orbitControls = null, this._camera = null, this._controls = null, this._gizmoScene = null;
|
|
17708
17770
|
}
|
|
17709
|
-
},
|
|
17771
|
+
}, $m = class {
|
|
17710
17772
|
constructor(e) {
|
|
17711
17773
|
this.layer = "scene", this._transformManager = e, this._enabled = !0;
|
|
17712
17774
|
}
|
|
@@ -17725,21 +17787,21 @@ var Rm = 4096, zm = class {
|
|
|
17725
17787
|
dispose() {
|
|
17726
17788
|
this._enabled = !1;
|
|
17727
17789
|
}
|
|
17728
|
-
},
|
|
17729
|
-
function
|
|
17790
|
+
}, eh = /* @__PURE__ */ new WeakMap(), th = ci("engine");
|
|
17791
|
+
function nh(e, t) {
|
|
17730
17792
|
e.lost.then((e) => {
|
|
17731
17793
|
t.app && t.app._handleDeviceLost(e);
|
|
17732
17794
|
});
|
|
17733
17795
|
}
|
|
17734
|
-
var
|
|
17796
|
+
var rh = class extends lt {
|
|
17735
17797
|
constructor(e, t = {}) {
|
|
17736
17798
|
super();
|
|
17737
17799
|
try {
|
|
17738
|
-
|
|
17800
|
+
eh.get(e)?.dispose();
|
|
17739
17801
|
} catch (e) {
|
|
17740
|
-
|
|
17802
|
+
th.warn("prior canvas owner dispose failed", e);
|
|
17741
17803
|
}
|
|
17742
|
-
|
|
17804
|
+
eh.set(e, this), this.canvas = e, this._autoResize = t.autoResize !== !1, this._container = t.container || null, this._applySceneMetadataEnabled = t.applySceneMetadata !== !1, this._applyingSceneMetadata = !1, this.settings = new Up(Y), this.renderer = null, this.scene = null, this.meshScene = null, this._sceneHelpers = null, this.assetLoader = null, this._sdf = null, this._animRefitInFlight = !1, this._maxTextureSize = Y.maxTextureSize, this.pipeline = null, this._pendingReservedRenderSize = null, this.stages = {}, this.cameraManager = null, this.lightManager = null, this.goboManager = null, this.iesManager = null, this.denoisingManager = null, this.overlayManager = null, this.interactionManager = null, this.transformManager = null, this.animationManager = new Xm(), this.environmentManager = null, this.isInitialized = !1, this.pauseRendering = !1, this._pathTracerEnabled = !0, this._rasterPrecompile = null, this.animationManagerId = null, this.needsReset = !1, this._loadingInProgress = !1, this._needsDisplayRefresh = !1, this._paused = !1, this._emissiveSamplingUserSet = !1, this.completion = new Yf(), this._resizeDebounceTimer = null, this._trackedListeners = [], this._disposed = !1, this._deviceLost = !1, this._gpuDevice = null, this._deviceLostHolder = null, this._deterministic = !1, this._dispatchPinned = !1, this._deterministicRestore = null;
|
|
17743
17805
|
}
|
|
17744
17806
|
_addTrackedListener(e, t, n) {
|
|
17745
17807
|
e && (e.addEventListener(t, n), this._trackedListeners.push({
|
|
@@ -17752,12 +17814,12 @@ var Xm = class extends lt {
|
|
|
17752
17814
|
for (let { target: e, type: t, handler: n } of this._trackedListeners) try {
|
|
17753
17815
|
e.removeEventListener(t, n);
|
|
17754
17816
|
} catch (e) {
|
|
17755
|
-
|
|
17817
|
+
th.warn("failed to remove listener", t, e);
|
|
17756
17818
|
}
|
|
17757
17819
|
this._trackedListeners.length = 0;
|
|
17758
17820
|
}
|
|
17759
17821
|
async init() {
|
|
17760
|
-
return await this._initRenderer(), this._applyPendingReservedRenderSize(), this._initCameraManager(), this._initScenes(), this._initAssetPipeline(), this._initPipeline(), await this._initManagers(), this._wireEvents(), this.stages.pathTracer.setTriangleData(new Float32Array(32), 0), this.stages.pathTracer.setBVHData(new Float32Array(16)), this.stages.pathTracer.materialData.setMaterialData(new Float32Array(16)), this.stages.pathTracer.setupMaterial(), this.isInitialized = !0,
|
|
17822
|
+
return await this._initRenderer(), this._applyPendingReservedRenderSize(), this._initCameraManager(), this._initScenes(), this._initAssetPipeline(), this._initPipeline(), await this._initManagers(), this._wireEvents(), this.stages.pathTracer.setTriangleData(new Float32Array(32), 0), this.stages.pathTracer.setBVHData(new Float32Array(16)), this.stages.pathTracer.materialData.setMaterialData(new Float32Array(16)), this.stages.pathTracer.setupMaterial(), this.isInitialized = !0, th.debug("WebGPU path tracer app initialized"), this;
|
|
17761
17823
|
}
|
|
17762
17824
|
animate() {
|
|
17763
17825
|
if (!this._deviceLost) {
|
|
@@ -17767,7 +17829,7 @@ var Xm = class extends lt {
|
|
|
17767
17829
|
}
|
|
17768
17830
|
if (this.cameraManager.controls && this.cameraManager.controls.update(), this.animationManager?.isPlaying && !this._animRefitInFlight) {
|
|
17769
17831
|
let e = this.animationManager.update();
|
|
17770
|
-
e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) =>
|
|
17832
|
+
e && (this._animRefitInFlight = !0, this.refitBVH(e).catch((e) => th.error("animation refit error:", e)).finally(() => {
|
|
17771
17833
|
this._animRefitInFlight = !1;
|
|
17772
17834
|
}));
|
|
17773
17835
|
}
|
|
@@ -17815,7 +17877,7 @@ var Xm = class extends lt {
|
|
|
17815
17877
|
this.animationManagerId &&= (cancelAnimationFrame(this.animationManagerId), null);
|
|
17816
17878
|
}
|
|
17817
17879
|
_handleDeviceLost(e) {
|
|
17818
|
-
this._deviceLost || (this._deviceLost = !0,
|
|
17880
|
+
this._deviceLost || (this._deviceLost = !0, th.error(`WebGPU device lost (${e?.reason || "unknown"}): ${e?.message || ""}`), this.stopAnimation(), this.dispatchEvent({
|
|
17819
17881
|
type: dr.DEVICE_LOST,
|
|
17820
17882
|
reason: e?.reason,
|
|
17821
17883
|
message: e?.message
|
|
@@ -17845,9 +17907,9 @@ var Xm = class extends lt {
|
|
|
17845
17907
|
let e = Ae().value, t = k().value;
|
|
17846
17908
|
e?._listeners?.dispose && (e._listeners.dispose.length = 0), t?._listeners?.dispose && (t._listeners.dispose.length = 0);
|
|
17847
17909
|
} catch (e) {
|
|
17848
|
-
|
|
17910
|
+
th.warn("failed to clear TSL texture singleton listeners", e);
|
|
17849
17911
|
}
|
|
17850
|
-
this.canvas &&
|
|
17912
|
+
this.canvas && eh.get(this.canvas) === this && eh.delete(this.canvas), this._gpuDevice &&= (this._gpuDevice.onuncapturederror = null, null), this._deviceLostHolder &&= (this._deviceLostHolder.app = null, null), Sr(this.renderer), this.renderer = null, this.stages = {}, this.isInitialized = !1;
|
|
17851
17913
|
}
|
|
17852
17914
|
}
|
|
17853
17915
|
unloadScene() {
|
|
@@ -17868,8 +17930,12 @@ var Xm = class extends lt {
|
|
|
17868
17930
|
name: t
|
|
17869
17931
|
});
|
|
17870
17932
|
}
|
|
17933
|
+
_busyError(e) {
|
|
17934
|
+
let t = /* @__PURE__ */ Error(`${e}: another load is already in progress`);
|
|
17935
|
+
return t.code = "LOAD_IN_PROGRESS", t;
|
|
17936
|
+
}
|
|
17871
17937
|
async loadEnvironment(e) {
|
|
17872
|
-
if (this._loadingInProgress) throw
|
|
17938
|
+
if (this._loadingInProgress) throw this._busyError("PathTracerApp.loadEnvironment");
|
|
17873
17939
|
this._loadingInProgress = !0;
|
|
17874
17940
|
try {
|
|
17875
17941
|
await this.assetLoader.loadEnvironment(e);
|
|
@@ -17882,6 +17948,29 @@ var Xm = class extends lt {
|
|
|
17882
17948
|
this._loadingInProgress = !1;
|
|
17883
17949
|
}
|
|
17884
17950
|
}
|
|
17951
|
+
async loadFile(e) {
|
|
17952
|
+
let t = this.assetLoader?.getFileFormat(e?.name || "");
|
|
17953
|
+
if (!t) throw Error(`Unsupported file format: ${e?.name}`);
|
|
17954
|
+
if (t.type !== "environment" && t.type !== "image") {
|
|
17955
|
+
await this._loadWithSceneRebuild(() => this.assetLoader.loadAssetFromFile(e), {
|
|
17956
|
+
type: "ModelLoaded",
|
|
17957
|
+
filename: e.name
|
|
17958
|
+
});
|
|
17959
|
+
return;
|
|
17960
|
+
}
|
|
17961
|
+
if (this._loadingInProgress) throw this._busyError("PathTracerApp.loadFile");
|
|
17962
|
+
this._loadingInProgress = !0;
|
|
17963
|
+
try {
|
|
17964
|
+
await this.assetLoader.loadAssetFromFile(e);
|
|
17965
|
+
let t = this.meshScene.environment;
|
|
17966
|
+
t && this.stages.pathTracer && await this.stages.pathTracer.environment.applyHDRI(t), this.pipeline?.eventBus.emit("autoexposure:resetHistory"), this.reset(), this.dispatchEvent({
|
|
17967
|
+
type: "EnvironmentLoaded",
|
|
17968
|
+
filename: e.name
|
|
17969
|
+
});
|
|
17970
|
+
} finally {
|
|
17971
|
+
this._loadingInProgress = !1;
|
|
17972
|
+
}
|
|
17973
|
+
}
|
|
17885
17974
|
async loadExampleModels(e, t) {
|
|
17886
17975
|
await this._loadWithSceneRebuild(() => this.assetLoader.loadExampleModels(e, t), {
|
|
17887
17976
|
type: "ModelLoaded",
|
|
@@ -17906,37 +17995,62 @@ var Xm = class extends lt {
|
|
|
17906
17995
|
}
|
|
17907
17996
|
}
|
|
17908
17997
|
async _loadWithSceneRebuild(e, t) {
|
|
17909
|
-
if (this._loadingInProgress) throw
|
|
17998
|
+
if (this._loadingInProgress) throw this._busyError("PathTracerApp");
|
|
17910
17999
|
this._loadingInProgress = !0;
|
|
17911
18000
|
try {
|
|
17912
|
-
await e(), this._emissiveSamplingUserSet = !1, this._clearAppendedModels(), this._syncControlsAfterLoad(), await this.loadSceneData(), this.pipeline?.eventBus.emit("autoexposure:resetHistory"), this.reset(), this.cameraManager.currentCameraIndex = 0, this.dispatchEvent(t), this._dispatchCamerasUpdated();
|
|
18001
|
+
await e(), this._emissiveSamplingUserSet = !1, this._clearAppendedModels(), this._syncControlsAfterLoad(), await this.loadSceneData({ pendingEnvironment: this._beginSceneMetadataEnvironment() }), this.pipeline?.eventBus.emit("autoexposure:resetHistory"), this.reset(), this.cameraManager.currentCameraIndex = 0, this.dispatchEvent(t), this._dispatchCamerasUpdated();
|
|
17913
18002
|
} finally {
|
|
17914
18003
|
this._loadingInProgress = !1;
|
|
17915
18004
|
}
|
|
17916
18005
|
}
|
|
17917
|
-
|
|
18006
|
+
get sceneMetadata() {
|
|
18007
|
+
return this.assetLoader?.sceneMetadata ?? null;
|
|
18008
|
+
}
|
|
18009
|
+
_beginSceneMetadataEnvironment() {
|
|
18010
|
+
let e = this.sceneMetadata?.environment;
|
|
18011
|
+
return !this._applySceneMetadataEnabled || !e?.sourceFile || !this.stages.pathTracer ? null : (this.stages.pathTracer.environment.beginHDRI(), this._applyingSceneMetadata = !0, this.assetLoader.loadEnvironment(e.sourceFile).catch((t) => (th.warn(`scene metadata: environment "${e.sourceFile}" failed to load`, t), null)).finally(() => {
|
|
18012
|
+
this._applyingSceneMetadata = !1;
|
|
18013
|
+
}));
|
|
18014
|
+
}
|
|
18015
|
+
_applySceneMetadataSettings(e) {
|
|
18016
|
+
let t = this.sceneMetadata, n = t?.environment;
|
|
18017
|
+
if (!n) return;
|
|
18018
|
+
let r = {
|
|
18019
|
+
enableEnvironment: !0,
|
|
18020
|
+
showBackground: !0,
|
|
18021
|
+
transparentBackground: !1
|
|
18022
|
+
};
|
|
18023
|
+
n.intensity !== void 0 && (r.environmentIntensity = n.intensity, r.backgroundIntensity = n.intensity), n.rotation !== void 0 && (r.environmentRotation = n.rotation), this.settings.setMany(r, { reset: !1 }), this.scene && (this.scene.background = e), this.dispatchEvent({
|
|
18024
|
+
type: "SceneMetadataApplied",
|
|
18025
|
+
metadata: t,
|
|
18026
|
+
environment: { ...n }
|
|
18027
|
+
});
|
|
18028
|
+
}
|
|
18029
|
+
async loadSceneData({ pendingEnvironment: e = null } = {}) {
|
|
17918
18030
|
this._preserveSelectionOnRebuild || this.interactionManager?.deselect(), this.animationManager.dispose(), this._animRefitInFlight = !1, this._tagPrimarySceneObject();
|
|
17919
|
-
let
|
|
18031
|
+
let t = new $c("", {
|
|
17920
18032
|
namespace: "scene",
|
|
17921
18033
|
level: "info"
|
|
17922
|
-
}),
|
|
17923
|
-
if (
|
|
18034
|
+
}), n = this.meshScene.environment, r = null;
|
|
18035
|
+
if (e ? (t.start("Environment fetch + CDF (concurrent)"), r = e.then(async (e) => {
|
|
18036
|
+
e && (await this.stages.pathTracer.environment.applyHDRI(e), this._applySceneMetadataSettings(e));
|
|
18037
|
+
}).catch((e) => th.warn("scene metadata: environment install failed", e)).finally(() => t.end("Environment fetch + CDF (concurrent)"))) : n?.image?.data && (t.start("Environment CDF build (worker)"), this.stages.pathTracer.scene.environment = n, r = this.stages.pathTracer.environment.buildEnvironmentCDF().then(() => t.end("Environment CDF build (worker)"))), t.start("BVH build (SceneProcessor)"), this._sdf.setMaxTextureSize(this._maxTextureSize), await this._sdf.buildBVH(this.meshScene), t.end("BVH build (SceneProcessor)"), gr({
|
|
17924
18038
|
status: "Transferring data to GPU...",
|
|
17925
18039
|
progress: 86
|
|
17926
|
-
}), await new Promise((e) => setTimeout(e, 0)),
|
|
17927
|
-
this.stages.pathTracer._meshRefs = this.stages.pathTracer._collectMeshRefs(this.meshScene), this.stages.pathTracer.setMeshVisibilityData(this.stages.pathTracer._meshRefs), this._refreshEmissiveForVisibility(),
|
|
18040
|
+
}), await new Promise((e) => setTimeout(e, 0)), t.start("GPU data transfer"), !this._sdf.uploadToPathTracer(this.stages.pathTracer, this.lightManager, this.meshScene, this.meshScene.environment)) return !1;
|
|
18041
|
+
this.stages.pathTracer._meshRefs = this.stages.pathTracer._collectMeshRefs(this.meshScene), this.stages.pathTracer.setMeshVisibilityData(this.stages.pathTracer._meshRefs), this._refreshEmissiveForVisibility(), t.end("GPU data transfer"), gr({
|
|
17928
18042
|
status: "Compiling shaders...",
|
|
17929
18043
|
progress: 90
|
|
17930
|
-
}), await new Promise((e) => setTimeout(e, 0)),
|
|
18044
|
+
}), await new Promise((e) => setTimeout(e, 0)), t.start("Material setup (TSL compile)"), this.stages.pathTracer.setupMaterial(), t.end("Material setup (TSL compile)"), this._rasterPrecompile = null, this._pathTracerEnabled || (t.start("Pipeline precompile"), await this.precompileRaster(), t.end("Pipeline precompile")), r && (gr({
|
|
17931
18045
|
status: "Finalizing environment map...",
|
|
17932
18046
|
progress: 95
|
|
17933
|
-
}), await
|
|
17934
|
-
let
|
|
17935
|
-
if (this.settings.set("groundProjectionLevel",
|
|
18047
|
+
}), await r, this.stages.pathTracer.environment.applyCDFResults());
|
|
18048
|
+
let i = this.getSceneMinY();
|
|
18049
|
+
if (this.settings.set("groundProjectionLevel", i, { reset: !1 }), this.settings.set("groundCatcherHeight", i, { reset: !1 }), !this._emissiveSamplingUserSet) {
|
|
17936
18050
|
let e = (this._sdf?.emissiveTriangleBuilder?.emissiveTriangles?.length ?? this._sdf?.emissiveTriangleCount ?? 0) > 0;
|
|
17937
18051
|
this.settings.set("enableEmissiveTriangleSampling", e, { reset: !1 });
|
|
17938
18052
|
}
|
|
17939
|
-
return
|
|
18053
|
+
return t.start("Apply settings"), this.settings.applyAll(), this.stages.compositor.setTransparentBackground(this.settings.get("transparentBackground")), t.end("Apply settings"), t.print(this._sceneSummaryParts()), hr(), this._initAnimationAndTransforms(), this.dispatchEvent({ type: "SceneRebuild" }), !0;
|
|
17940
18054
|
}
|
|
17941
18055
|
_sceneSummaryParts() {
|
|
17942
18056
|
let e = this.stages.pathTracer, t = this._sdf?.instanceTable?.entries?.filter(Boolean).length ?? 0, n = this._sdf?.geometryExtractor?.maps?.length ?? 0;
|
|
@@ -18069,7 +18183,7 @@ var Xm = class extends lt {
|
|
|
18069
18183
|
if (!e) return;
|
|
18070
18184
|
this._pendingReservedRenderSize = null;
|
|
18071
18185
|
let t = this.setReservedRenderResolution(e.requestedPx, { allowLower: e.allowLower });
|
|
18072
|
-
t < e.requestedPx &&
|
|
18186
|
+
t < e.requestedPx && th.warn(`reserved render size ${Q.n(e.requestedPx)}px was capped to ${Q.n(t)}px by this device's limits — renders above ${Q.n(t)}px will be declined.`), this.dispatchEvent({
|
|
18073
18187
|
type: "reserved_render_size_changed",
|
|
18074
18188
|
size: t
|
|
18075
18189
|
});
|
|
@@ -18078,7 +18192,7 @@ var Xm = class extends lt {
|
|
|
18078
18192
|
return kr;
|
|
18079
18193
|
}
|
|
18080
18194
|
_isRenderSizeSupported(e, t) {
|
|
18081
|
-
return e > kr || t > kr ? (
|
|
18195
|
+
return e > kr || t > kr ? (th.warn(`render resolution ${e}×${t} exceeds the ${kr}px reserve (compute storage textures are pre-allocated at ${kr}px). Ignoring resize — raise the reserve with setReservedRenderResolution( ${Math.max(e, t)} ) first, or use a resolution ≤ ${kr}.`), !1) : !0;
|
|
18082
18196
|
}
|
|
18083
18197
|
onResize() {
|
|
18084
18198
|
let e = this.canvas.clientWidth, t = this.canvas.clientHeight;
|
|
@@ -18272,7 +18386,7 @@ var Xm = class extends lt {
|
|
|
18272
18386
|
this._pathTracerEnabled = e, e || this.precompileRaster();
|
|
18273
18387
|
}
|
|
18274
18388
|
precompileRaster() {
|
|
18275
|
-
return !this.renderer || !this.meshScene ? Promise.resolve() : (this._rasterPrecompile ??= this.renderer.compileAsync(this.meshScene, this.cameraManager.camera).catch((e) =>
|
|
18389
|
+
return !this.renderer || !this.meshScene ? Promise.resolve() : (this._rasterPrecompile ??= this.renderer.compileAsync(this.meshScene, this.cameraManager.camera).catch((e) => th.warn("raster fallback precompile failed", e)), this._rasterPrecompile);
|
|
18276
18390
|
}
|
|
18277
18391
|
get isLoading() {
|
|
18278
18392
|
return this._loadingInProgress;
|
|
@@ -18380,16 +18494,16 @@ var Xm = class extends lt {
|
|
|
18380
18494
|
}
|
|
18381
18495
|
}), await this.renderer.init();
|
|
18382
18496
|
let n = this.renderer.backend?.device;
|
|
18383
|
-
n?.lost && (this._gpuDevice = n, this._deviceLostHolder = { app: this },
|
|
18497
|
+
n?.lost && (this._gpuDevice = n, this._deviceLostHolder = { app: this }, nh(n, this._deviceLostHolder), n.onuncapturederror = (e) => th.error("WebGPU uncaptured error:", e.error)), r.setLTC(cn.init()), this.renderer.outputColorSpace = a, this.renderer.toneMapping = He, this.renderer.toneMappingExposure = 1, this.renderer.setPixelRatio(1);
|
|
18384
18498
|
}
|
|
18385
18499
|
_initCameraManager() {
|
|
18386
|
-
this.cameraManager = new
|
|
18500
|
+
this.cameraManager = new Wp(this.canvas);
|
|
18387
18501
|
}
|
|
18388
18502
|
_initScenes() {
|
|
18389
18503
|
this.scene = new Jt(), this.meshScene = new Jt(), this._sceneHelpers = new Pn();
|
|
18390
18504
|
}
|
|
18391
18505
|
_initAssetPipeline() {
|
|
18392
|
-
this._sdf = new il(), this.assetLoader = new
|
|
18506
|
+
this._sdf = new il(), this.assetLoader = new Bp(this.meshScene, this.cameraManager.camera, this.cameraManager.controls), this.assetLoader.setRenderer(this.renderer), this.assetLoader.createFloorPlane(), this._addTrackedListener(this.cameraManager.controls, "change", () => {
|
|
18393
18507
|
this.needsReset = !0, this.wake();
|
|
18394
18508
|
});
|
|
18395
18509
|
}
|
|
@@ -18408,12 +18522,12 @@ var Xm = class extends lt {
|
|
|
18408
18522
|
assetLoader: this.assetLoader,
|
|
18409
18523
|
pathTracer: null,
|
|
18410
18524
|
floorPlane: this.assetLoader.floorPlane
|
|
18411
|
-
}), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.lightManager = new
|
|
18525
|
+
}), this.interactionManager.wireAppEvents(this), this.cameraManager.setInteractionManager(this.interactionManager), this.lightManager = new Gp(this.scene, this._sceneHelpers, this.stages.pathTracer, { onReset: () => this.reset() }), this.goboManager = new Kp(this.stages.pathTracer, { onReset: () => this.reset() }), this.iesManager = new rm(this.stages.pathTracer, { onReset: () => this.reset() }), this._setupDenoisingManager(), await this._setupOverlayManager(), this.transformManager = new Qm({
|
|
18412
18526
|
camera: this.cameraManager.camera,
|
|
18413
18527
|
canvas: this.canvas,
|
|
18414
18528
|
orbitControls: this.cameraManager.controls,
|
|
18415
18529
|
app: this
|
|
18416
|
-
}), this.overlayManager.register("transform", new
|
|
18530
|
+
}), this.overlayManager.register("transform", new $m(this.transformManager)), this.interactionManager.setDependencies({
|
|
18417
18531
|
overlayManager: this.overlayManager,
|
|
18418
18532
|
transformManager: this.transformManager,
|
|
18419
18533
|
appDispatch: (e) => this.dispatchEvent(e),
|
|
@@ -18461,8 +18575,8 @@ var Xm = class extends lt {
|
|
|
18461
18575
|
denoisingManager: this.denoisingManager,
|
|
18462
18576
|
cameraManager: this.cameraManager
|
|
18463
18577
|
}), this.renderer.toneMappingExposure = this.settings.get("exposure") ?? 1, this.onResize(), this.resizeHandler = () => this.onResize(), this._autoResize && this._addTrackedListener(window, "resize", this.resizeHandler), this._onAssetLoaded = async (e) => {
|
|
18464
|
-
if (!this._loadingInProgress) {
|
|
18465
|
-
if (e.model) this._clearAppendedModels(), await this.loadSceneData();
|
|
18578
|
+
if (!this._loadingInProgress && !(this._applyingSceneMetadata && e.texture)) {
|
|
18579
|
+
if (e.model) this._clearAppendedModels(), await this.loadSceneData({ pendingEnvironment: this._beginSceneMetadataEnvironment() });
|
|
18466
18580
|
else if (e.texture) {
|
|
18467
18581
|
let e = this.meshScene.environment;
|
|
18468
18582
|
e && this.stages.pathTracer && await this.stages.pathTracer.environment.setEnvironmentMap(e), hr();
|
|
@@ -18491,7 +18605,7 @@ var Xm = class extends lt {
|
|
|
18491
18605
|
});
|
|
18492
18606
|
}
|
|
18493
18607
|
_setupDenoisingManager() {
|
|
18494
|
-
this.denoisingManager = new
|
|
18608
|
+
this.denoisingManager = new Bm({
|
|
18495
18609
|
renderer: this.renderer,
|
|
18496
18610
|
mainCanvas: this.canvas,
|
|
18497
18611
|
scene: this.scene,
|
|
@@ -18534,7 +18648,7 @@ var Xm = class extends lt {
|
|
|
18534
18648
|
this.scene.updateMatrixWorld(), this.overlayManager?.render();
|
|
18535
18649
|
}
|
|
18536
18650
|
async _setupOverlayManager() {
|
|
18537
|
-
this.overlayManager = new
|
|
18651
|
+
this.overlayManager = new Ym(this.cameraManager.camera), this.overlayManager.setupDefaultHelpers({
|
|
18538
18652
|
helperScene: this._sceneHelpers,
|
|
18539
18653
|
meshScene: this.meshScene,
|
|
18540
18654
|
pipeline: this.pipeline,
|
|
@@ -18565,7 +18679,7 @@ var Xm = class extends lt {
|
|
|
18565
18679
|
_forwardEvents(e, t) {
|
|
18566
18680
|
if (e) for (let n of t) this._addTrackedListener(e, n, (e) => this.dispatchEvent(e));
|
|
18567
18681
|
}
|
|
18568
|
-
},
|
|
18682
|
+
}, ih = class {
|
|
18569
18683
|
constructor(e) {
|
|
18570
18684
|
this._app = e, this._cancelled = !1, this._rendering = !1;
|
|
18571
18685
|
}
|
|
@@ -18663,4 +18777,4 @@ var Xm = class extends lt {
|
|
|
18663
18777
|
}
|
|
18664
18778
|
};
|
|
18665
18779
|
//#endregion
|
|
18666
|
-
export { Ir as AF_DEFAULTS, jr as ASVGF_QUALITY_PRESETS, Fr as AUTO_FOCUS_MODES,
|
|
18780
|
+
export { Ir as AF_DEFAULTS, jr as ASVGF_QUALITY_PRESETS, Fr as AUTO_FOCUS_MODES, Xm as AnimationManager, Rr as BVH_LEAF_MARKERS, Pr as CAMERA_PRESETS, Mr as CAMERA_RANGES, Wp as CameraManager, Ur as DEFAULT_TEXTURE_MATRIX, Bm as DenoisingManager, Y as ENGINE_DEFAULTS, dr as EngineEvents, Kp as GoboManager, rm as IESManager, Gr as INTERACTIVE_RENDER_CONFIG, Xf as InteractionManager, qr as LOG_LEVELS, Gp as LightManager, si as Logger, Or as MAX_RESERVABLE_RENDER_SIZE, Kr as MEMORY_CONSTANTS, Ym as OverlayManager, Wr as PRODUCTION_RENDER_CONFIG, rh as PathTracerApp, Ff as PipelineContext, qf as RenderPipeline, Up as RenderSettings, lr as RenderStage, Nr as SKY_PRESETS, cr as StageExecutionMode, zr as TEXTURE_CONSTANTS, X as TRIANGLE_DATA_LAYOUT, Qm as TransformManager, gu as VRAMTracker, ih as VideoRenderManager, mu as bufferBytes, Hf as clearBindingAuditFindings, pl as configureAssets, ci as createLogger, Ip as extractSceneMetadata, Q as fmt, ml as getAssetConfig, Vf as getBindingAuditFindings, Fp as parseSceneMetadata, Bf as setBindingAudit, hu as textureBytes };
|