@needle-tools/engine 5.0.0 → 5.1.0-experimental.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/components.needle.json +1 -1
- package/dist/generateMeshBVH.worker-DT9A2Hrc.js +1 -0
- package/dist/gltf-progressive-3BwW4ETO.min.js +10 -0
- package/dist/gltf-progressive-ByD1UX0A.umd.cjs +10 -0
- package/dist/{gltf-progressive-Cl167Vjx.js → gltf-progressive-DwWaVr0o.js} +412 -394
- package/dist/gltf-progressive.worker-DpfUjn1n.js +3 -0
- package/dist/{materialx-qPScBWhj.min.js → materialx-9KHBidZa.min.js} +1 -1
- package/dist/{materialx-4ApD6Vz5.js → materialx-BBDu8W5P.js} +1 -1
- package/dist/{materialx-D0XUnhBY.umd.cjs → materialx-hLP3E8AA.umd.cjs} +2 -2
- package/dist/{needle-engine.bundle-BAYLGumK.umd.cjs → needle-engine.bundle-BOAJ6UPK.umd.cjs} +123 -123
- package/dist/{needle-engine.bundle-CoEvMwYM.min.js → needle-engine.bundle-CVsBkUR2.min.js} +110 -110
- package/dist/{needle-engine.bundle-BDIyvCV6.js → needle-engine.bundle-TgPY0fGG.js} +2143 -2088
- package/dist/needle-engine.d.ts +80 -22
- package/dist/needle-engine.js +480 -476
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-B_9sKVU7.min.js → postprocessing-BZfyAdCY.min.js} +1 -1
- package/dist/{postprocessing-WDc9WwI3.js → postprocessing-CXlA3QA6.js} +1 -1
- package/dist/{postprocessing-B2wb6pzI.umd.cjs → postprocessing-Dwy7Hz_T.umd.cjs} +38 -38
- package/dist/three-examples.js +4760 -3641
- package/dist/three-examples.min.js +17 -35
- package/dist/three-examples.umd.cjs +16 -34
- package/dist/three.js +48533 -28562
- package/dist/three.min.js +716 -502
- package/dist/three.umd.cjs +720 -506
- package/dist/{vendor-CntUvmJu.umd.cjs → vendor-BI4TX0aC.umd.cjs} +9 -9
- package/dist/{vendor-DPbfJJ4d.min.js → vendor-BgzAK9of.min.js} +1 -1
- package/dist/{vendor-vHLk8sXu.js → vendor-CwL-uvVy.js} +1 -1
- package/lib/engine/engine_animation.js +1 -1
- package/lib/engine/engine_animation.js.map +1 -1
- package/lib/engine/engine_audio.js.map +1 -1
- package/lib/engine/engine_context.js +3 -6
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_create_objects.js +0 -1
- package/lib/engine/engine_create_objects.js.map +1 -1
- package/lib/engine/engine_element.d.ts +113 -0
- package/lib/engine/engine_element.js +833 -0
- package/lib/engine/engine_element.js.map +1 -0
- package/lib/engine/engine_element_attributes.d.ts +72 -0
- package/lib/engine/engine_element_attributes.js +2 -0
- package/lib/engine/engine_element_attributes.js.map +1 -0
- package/lib/engine/engine_element_extras.d.ts +6 -0
- package/lib/engine/engine_element_extras.js +14 -0
- package/lib/engine/engine_element_extras.js.map +1 -0
- package/lib/engine/engine_element_loading.d.ts +44 -0
- package/lib/engine/engine_element_loading.js +350 -0
- package/lib/engine/engine_element_loading.js.map +1 -0
- package/lib/engine/engine_element_overlay.d.ts +21 -0
- package/lib/engine/engine_element_overlay.js +167 -0
- package/lib/engine/engine_element_overlay.js.map +1 -0
- package/lib/engine/engine_license.js.map +1 -1
- package/lib/engine/engine_pmrem.js +2 -2
- package/lib/engine/engine_pmrem.js.map +1 -1
- package/lib/engine/engine_scenetools.d.ts +62 -0
- package/lib/engine/engine_scenetools.js +337 -0
- package/lib/engine/engine_scenetools.js.map +1 -0
- package/lib/engine/engine_serialization_builtin_serializer.d.ts +1 -1
- package/lib/engine/engine_test_utils.d.ts +39 -0
- package/lib/engine/engine_test_utils.js +84 -0
- package/lib/engine/engine_test_utils.js.map +1 -0
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/engine_time.js +4 -3
- package/lib/engine/engine_time.js.map +1 -1
- package/lib/engine/engine_ui.d.ts +25 -0
- package/lib/engine/engine_ui.dummy_canvas.d.ts +2 -0
- package/lib/engine/engine_ui.dummy_canvas.js +55 -0
- package/lib/engine/engine_ui.dummy_canvas.js.map +1 -0
- package/lib/engine/engine_ui.js +168 -0
- package/lib/engine/engine_ui.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_lightmaps.js +2 -2
- package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_pmrem.d.ts +1 -1
- package/lib/engine/webcomponents/icons.js +3 -2
- package/lib/engine/webcomponents/icons.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.attributes.d.ts +69 -0
- package/lib/engine/webcomponents/needle-engine.attributes.js +2 -0
- package/lib/engine/webcomponents/needle-engine.attributes.js.map +1 -0
- package/lib/engine-components/AudioSource.js +1 -1
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/Light.d.ts +3 -0
- package/lib/engine-components/Light.js +39 -31
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +2 -1
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/SpriteRenderer.d.ts +1 -1
- package/lib/engine-components/VideoPlayer.d.ts +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/Animation.js +1 -0
- package/lib/engine-components/export/usdz/extensions/Animation.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.d.ts +1 -1
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -1
- package/lib/engine-components/particlesystem/ParticleSystem.d.ts +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
- package/lib/engine-components/ui/BaseUIComponent_Uikit.d.ts +54 -0
- package/lib/engine-components/ui/BaseUIComponent_Uikit.js +114 -0
- package/lib/engine-components/ui/BaseUIComponent_Uikit.js.map +1 -0
- package/lib/engine-components/ui/BaseUikitComponent.d.ts +54 -0
- package/lib/engine-components/ui/BaseUikitComponent.js +114 -0
- package/lib/engine-components/ui/BaseUikitComponent.js.map +1 -0
- package/lib/engine-components/ui/Button.legacy.d.ts +68 -0
- package/lib/engine-components/ui/Button.legacy.js +320 -0
- package/lib/engine-components/ui/Button.legacy.js.map +1 -0
- package/lib/engine-components/ui/ButtonUikit.d.ts +51 -0
- package/lib/engine-components/ui/ButtonUikit.js +187 -0
- package/lib/engine-components/ui/ButtonUikit.js.map +1 -0
- package/lib/engine-components/ui/Canvas.js +2 -2
- package/lib/engine-components/ui/Canvas.js.map +1 -1
- package/lib/engine-components/ui/Canvas.legacy.d.ts +76 -0
- package/lib/engine-components/ui/Canvas.legacy.js +409 -0
- package/lib/engine-components/ui/Canvas.legacy.js.map +1 -0
- package/lib/engine-components/ui/CanvasUikit.d.ts +68 -0
- package/lib/engine-components/ui/CanvasUikit.js +289 -0
- package/lib/engine-components/ui/CanvasUikit.js.map +1 -0
- package/lib/engine-components/ui/Graphic.d.ts +3 -3
- package/lib/engine-components/ui/Graphic.js +6 -2
- package/lib/engine-components/ui/Graphic.js.map +1 -1
- package/lib/engine-components/ui/Graphic.legacy.d.ts +55 -0
- package/lib/engine-components/ui/Graphic.legacy.js +268 -0
- package/lib/engine-components/ui/Graphic.legacy.js.map +1 -0
- package/lib/engine-components/ui/GraphicUikit.d.ts +21 -0
- package/lib/engine-components/ui/GraphicUikit.js +65 -0
- package/lib/engine-components/ui/GraphicUikit.js.map +1 -0
- package/lib/engine-components/ui/Image.js.map +1 -1
- package/lib/engine-components/ui/Image.legacy.d.ts +39 -0
- package/lib/engine-components/ui/Image.legacy.js +121 -0
- package/lib/engine-components/ui/Image.legacy.js.map +1 -0
- package/lib/engine-components/ui/ImageUikit.d.ts +22 -0
- package/lib/engine-components/ui/ImageUikit.js +97 -0
- package/lib/engine-components/ui/ImageUikit.js.map +1 -0
- package/lib/engine-components/ui/RenderMode.d.ts +14 -0
- package/lib/engine-components/ui/RenderMode.js +16 -0
- package/lib/engine-components/ui/RenderMode.js.map +1 -0
- package/lib/engine-components/ui/Text.d.ts +64 -11
- package/lib/engine-components/ui/Text.js +154 -45
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components/ui/Text.legacy.d.ts +81 -0
- package/lib/engine-components/ui/Text.legacy.js +548 -0
- package/lib/engine-components/ui/Text.legacy.js.map +1 -0
- package/lib/engine-components/ui/TextUikit.d.ts +42 -0
- package/lib/engine-components/ui/TextUikit.js +164 -0
- package/lib/engine-components/ui/TextUikit.js.map +1 -0
- package/lib/engine-components/ui/index.d.ts +1 -0
- package/lib/engine-components/ui/index.js +1 -0
- package/lib/engine-components/ui/index.js.map +1 -1
- package/lib/engine-components/webxr/WebARCameraBackground.d.ts +1 -1
- package/lib/include/three/EXT_mesh_gpu_instancing_exporter.d.ts +6 -0
- package/lib/include/three/EXT_mesh_gpu_instancing_exporter.js +46 -0
- package/lib/include/three/EXT_mesh_gpu_instancing_exporter.js.map +1 -0
- package/package.json +4 -4
- package/plugins/common/buildinfo.d.ts +6 -0
- package/plugins/vite/ai.d.ts +7 -8
- package/plugins/vite/ai.js +95 -20
- package/plugins/vite/alias.js +6 -0
- package/plugins/vite/dependencies.js +7 -0
- package/src/engine/engine_animation.ts +1 -1
- package/src/engine/engine_audio.ts +1 -1
- package/src/engine/engine_context.ts +3 -6
- package/src/engine/engine_create_objects.ts +0 -1
- package/src/engine/engine_license.ts +0 -2
- package/src/engine/engine_pmrem.ts +3 -3
- package/src/engine/engine_three_utils.ts +2 -2
- package/src/engine/engine_time.ts +4 -3
- package/src/engine/extensions/NEEDLE_lightmaps.ts +3 -3
- package/src/engine/webcomponents/icons.ts +3 -2
- package/src/engine-components/AudioSource.ts +1 -1
- package/src/engine-components/Light.ts +39 -31
- package/src/engine-components/OrbitControls.ts +2 -2
- package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +2 -2
- package/src/engine-components/export/usdz/extensions/Animation.ts +6 -5
- package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +1 -1
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +3 -3
- package/src/engine-components/timeline/TimelineTracks.ts +2 -2
- package/src/engine-components/ui/Canvas.ts +2 -2
- package/src/engine-components/ui/Graphic.ts +7 -3
- package/src/engine-components/ui/Image.ts +1 -1
- package/src/engine-components/ui/Text.ts +170 -52
- package/src/engine-components/ui/index.ts +2 -1
- package/dist/generateMeshBVH.worker-DiCnZlf3.js +0 -21
- package/dist/gltf-progressive-BryRjllq.min.js +0 -10
- package/dist/gltf-progressive-DJBMx-zB.umd.cjs +0 -10
- package/dist/gltf-progressive.worker-BqODMeeW.js +0 -23
|
@@ -1,86 +1,104 @@
|
|
|
1
|
-
import { BufferGeometry as V, Mesh as
|
|
2
|
-
import { DRACOLoader as
|
|
3
|
-
const
|
|
4
|
-
globalThis.GLTF_PROGRESSIVE_VERSION =
|
|
1
|
+
import { RedFormat as ze, RedIntegerFormat as qe, RGFormat as Ne, RGIntegerFormat as Ee, RGBFormat as Ve, RGBAFormat as je, RGBAIntegerFormat as Xe, BufferGeometry as V, Mesh as j, Box3 as pe, Vector3 as A, Sphere as Ae, CompressedTexture as Ke, Texture as F, Matrix3 as Ye, InterleavedBuffer as He, InterleavedBufferAttribute as Qe, BufferAttribute as Je, TextureLoader as Ze, Matrix4 as be, Timer as et, MeshStandardMaterial as tt } from "./three.js";
|
|
2
|
+
import { DRACOLoader as st, KTX2Loader as rt, MeshoptDecoder as nt, GLTFLoader as _e } from "./three-examples.js";
|
|
3
|
+
const ot = "";
|
|
4
|
+
globalThis.GLTF_PROGRESSIVE_VERSION = ot;
|
|
5
5
|
console.debug("[gltf-progressive] version -");
|
|
6
|
-
let I = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/",
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
fetch(
|
|
6
|
+
let I = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", X = "https://cdn.needle.tools/static/three/0.179.1/basis2/";
|
|
7
|
+
const it = I, at = X, Re = new URL(I + "draco_decoder.js");
|
|
8
|
+
Re.searchParams.append("range", "true");
|
|
9
|
+
fetch(Re, {
|
|
10
10
|
method: "GET",
|
|
11
11
|
headers: {
|
|
12
12
|
Range: "bytes=0-1"
|
|
13
13
|
}
|
|
14
|
-
}).catch((
|
|
15
|
-
console.debug(`Failed to fetch remote Draco decoder from ${I} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), I ===
|
|
14
|
+
}).catch((i) => {
|
|
15
|
+
console.debug(`Failed to fetch remote Draco decoder from ${I} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), I === it && ut("./include/draco/"), X === at && ct("./include/ktx2/");
|
|
16
16
|
}).finally(() => {
|
|
17
|
-
|
|
17
|
+
Ie();
|
|
18
18
|
});
|
|
19
|
-
const
|
|
19
|
+
const lt = () => ({
|
|
20
20
|
dracoDecoderPath: I,
|
|
21
|
-
ktx2TranscoderPath:
|
|
21
|
+
ktx2TranscoderPath: X
|
|
22
22
|
});
|
|
23
|
-
function
|
|
24
|
-
I =
|
|
23
|
+
function ut(i) {
|
|
24
|
+
I = i, C && C[me] != I ? (console.debug("Updating Draco decoder path to " + i), C[me] = I, C.setDecoderPath(I), C.preload()) : console.debug("Setting Draco decoder path to " + i);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
26
|
+
function ct(i) {
|
|
27
|
+
X = i, $ && $.transcoderPath != X ? (console.debug("Updating KTX2 transcoder path to " + i), $.setTranscoderPath(X), $.init()) : console.debug("Setting KTX2 transcoder path to " + i);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
return
|
|
29
|
+
function Me(i) {
|
|
30
|
+
return Ie(), i ? $.detectSupport(i) : i !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: C, ktx2Loader: $, meshoptDecoder: oe };
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
32
|
+
function ke(i) {
|
|
33
|
+
i.dracoLoader || i.setDRACOLoader(C), i.ktx2Loader || i.setKTX2Loader($), i.meshoptDecoder || i.setMeshoptDecoder(oe);
|
|
34
34
|
}
|
|
35
35
|
const me = /* @__PURE__ */ Symbol("dracoDecoderPath");
|
|
36
|
-
let C,
|
|
37
|
-
function
|
|
38
|
-
C || (C = new
|
|
36
|
+
let C, oe, $;
|
|
37
|
+
function Ie() {
|
|
38
|
+
C || (C = new st(), C[me] = I, C.setDecoderPath(I), C.setDecoderConfig({ type: "js" }), C.preload()), $ || ($ = new rt(), $.setTranscoderPath(X), $.init()), oe || (oe = nt);
|
|
39
39
|
}
|
|
40
40
|
const ye = /* @__PURE__ */ new WeakMap();
|
|
41
|
-
function
|
|
42
|
-
let e = ye.get(
|
|
43
|
-
e ? e = Object.assign(e, t) : e = t, ye.set(
|
|
41
|
+
function $e(i, t) {
|
|
42
|
+
let e = ye.get(i);
|
|
43
|
+
e ? e = Object.assign(e, t) : e = t, ye.set(i, e);
|
|
44
44
|
}
|
|
45
|
-
const
|
|
46
|
-
function
|
|
45
|
+
const dt = _e.prototype.load;
|
|
46
|
+
function ft(...i) {
|
|
47
47
|
const t = ye.get(this);
|
|
48
|
-
let e =
|
|
48
|
+
let e = i[0];
|
|
49
49
|
const s = new URL(e, window.location.href);
|
|
50
50
|
if (s.hostname.endsWith("needle.tools")) {
|
|
51
|
-
const
|
|
52
|
-
|
|
51
|
+
const n = t?.progressive !== void 0 ? t.progressive : !0, o = t?.usecase ? t.usecase : "default";
|
|
52
|
+
n ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${o}` : this.requestHeader.Accept = `*/*;usecase=${o}`, e = s.toString();
|
|
53
53
|
}
|
|
54
|
-
return
|
|
54
|
+
return i[0] = e, dt?.call(this, ...i);
|
|
55
|
+
}
|
|
56
|
+
_e.prototype.load = ft;
|
|
57
|
+
function Oe(i) {
|
|
58
|
+
return i != null && i.data != null;
|
|
59
|
+
}
|
|
60
|
+
function xe(i) {
|
|
61
|
+
const t = i.source?.data;
|
|
62
|
+
return t != null && typeof t == "object" ? t : null;
|
|
63
|
+
}
|
|
64
|
+
function ht(i) {
|
|
65
|
+
const t = i.image;
|
|
66
|
+
return t != null && typeof t == "object" ? t : null;
|
|
67
|
+
}
|
|
68
|
+
function we(i) {
|
|
69
|
+
const t = ht(i), e = xe(i);
|
|
70
|
+
return {
|
|
71
|
+
width: t?.width || e?.width || 0,
|
|
72
|
+
height: t?.height || e?.height || 0
|
|
73
|
+
};
|
|
55
74
|
}
|
|
56
|
-
we.prototype.load = st;
|
|
57
75
|
q("debugprogressive");
|
|
58
|
-
function q(
|
|
76
|
+
function q(i) {
|
|
59
77
|
if (typeof window > "u") return !1;
|
|
60
|
-
const e = new URL(window.location.href).searchParams.get(
|
|
78
|
+
const e = new URL(window.location.href).searchParams.get(i);
|
|
61
79
|
return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
|
|
62
80
|
}
|
|
63
|
-
function
|
|
64
|
-
if (t === void 0 ||
|
|
81
|
+
function gt(i, t) {
|
|
82
|
+
if (t === void 0 || i === void 0 || t.startsWith("./") || t.startsWith("http") || t.startsWith("data:") || t.startsWith("blob:"))
|
|
65
83
|
return t;
|
|
66
|
-
const e =
|
|
84
|
+
const e = i.lastIndexOf("/");
|
|
67
85
|
if (e >= 0) {
|
|
68
|
-
const s =
|
|
86
|
+
const s = i.substring(0, e + 1);
|
|
69
87
|
for (; s.endsWith("/") && t.startsWith("/"); ) t = t.substring(1);
|
|
70
88
|
return s + t;
|
|
71
89
|
}
|
|
72
90
|
return t;
|
|
73
91
|
}
|
|
74
|
-
function
|
|
92
|
+
function ve() {
|
|
75
93
|
return H !== void 0 || (H = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), q("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", H)), H;
|
|
76
94
|
}
|
|
77
95
|
let H;
|
|
78
|
-
function
|
|
96
|
+
function Se() {
|
|
79
97
|
if (typeof window > "u") return !1;
|
|
80
|
-
const
|
|
81
|
-
return
|
|
98
|
+
const i = new URL(window.location.href), t = i.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(i.hostname);
|
|
99
|
+
return i.hostname === "127.0.0.1" || t;
|
|
82
100
|
}
|
|
83
|
-
class
|
|
101
|
+
class pt {
|
|
84
102
|
constructor(t, e = {}) {
|
|
85
103
|
this.maxConcurrent = t, this.debug = e.debug ?? !1, window.requestAnimationFrame(this.tick);
|
|
86
104
|
}
|
|
@@ -109,97 +127,97 @@ class it {
|
|
|
109
127
|
this.debug && console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);
|
|
110
128
|
const { key: s, resolve: r } = this._queue.shift();
|
|
111
129
|
r({
|
|
112
|
-
use: (
|
|
130
|
+
use: (n) => this.add(s, n)
|
|
113
131
|
});
|
|
114
132
|
}
|
|
115
133
|
}
|
|
116
134
|
}
|
|
117
|
-
function
|
|
118
|
-
const t =
|
|
119
|
-
return
|
|
135
|
+
function mt(i) {
|
|
136
|
+
const t = i.image, e = t?.width ?? 0, s = t?.height ?? 0, r = t?.depth ?? 1, n = Math.floor(Math.log2(Math.max(e, s, r))) + 1, o = yt(i);
|
|
137
|
+
return e * s * r * o * (1 - Math.pow(0.25, n)) / (1 - 0.25);
|
|
120
138
|
}
|
|
121
|
-
function
|
|
139
|
+
function yt(i) {
|
|
122
140
|
let t = 4;
|
|
123
|
-
const e =
|
|
124
|
-
e ===
|
|
141
|
+
const e = i.format;
|
|
142
|
+
e === ze || e === qe ? t = 1 : e === Ne || e === Ee ? t = 2 : e === Ve || e === 1029 ? t = 3 : (e === je || e === Xe) && (t = 4);
|
|
125
143
|
let s = 1;
|
|
126
|
-
const r =
|
|
144
|
+
const r = i.type;
|
|
127
145
|
return r === 1009 || r === 1010 ? s = 1 : r === 1011 || r === 1012 ? s = 2 : r === 1013 || r === 1014 || r === 1015 ? s = 4 : r === 1016 && (s = 2), t * s;
|
|
128
146
|
}
|
|
129
|
-
const
|
|
130
|
-
function ee(
|
|
131
|
-
return
|
|
147
|
+
const xt = typeof window > "u" && typeof document > "u", Le = /* @__PURE__ */ Symbol("needle:raycast-mesh");
|
|
148
|
+
function ee(i) {
|
|
149
|
+
return i?.[Le] instanceof V ? i[Le] : null;
|
|
132
150
|
}
|
|
133
|
-
function
|
|
134
|
-
if ((
|
|
135
|
-
const s =
|
|
136
|
-
s.userData = { isRaycastMesh: !0 },
|
|
151
|
+
function wt(i, t) {
|
|
152
|
+
if ((i.type === "Mesh" || i.type === "SkinnedMesh") && !ee(i)) {
|
|
153
|
+
const s = _t(t);
|
|
154
|
+
s.userData = { isRaycastMesh: !0 }, i[Le] = s;
|
|
137
155
|
}
|
|
138
156
|
}
|
|
139
|
-
function
|
|
140
|
-
if (
|
|
157
|
+
function Lt(i = !0) {
|
|
158
|
+
if (i) {
|
|
141
159
|
if (Q) return;
|
|
142
|
-
const t = Q =
|
|
143
|
-
|
|
144
|
-
const r = this,
|
|
145
|
-
let
|
|
146
|
-
|
|
160
|
+
const t = Q = j.prototype.raycast;
|
|
161
|
+
j.prototype.raycast = function(e, s) {
|
|
162
|
+
const r = this, n = ee(r);
|
|
163
|
+
let o;
|
|
164
|
+
n && r.isMesh && (o = r.geometry, r.geometry = n), t.call(this, e, s), o && (r.geometry = o);
|
|
147
165
|
};
|
|
148
166
|
} else {
|
|
149
167
|
if (!Q) return;
|
|
150
|
-
|
|
168
|
+
j.prototype.raycast = Q, Q = null;
|
|
151
169
|
}
|
|
152
170
|
}
|
|
153
171
|
let Q = null;
|
|
154
|
-
function
|
|
172
|
+
function _t(i) {
|
|
155
173
|
const t = new V();
|
|
156
|
-
for (const e in
|
|
157
|
-
t.setAttribute(e,
|
|
158
|
-
return t.setIndex(
|
|
174
|
+
for (const e in i.attributes)
|
|
175
|
+
t.setAttribute(e, i.getAttribute(e));
|
|
176
|
+
return t.setIndex(i.getIndex()), t;
|
|
159
177
|
}
|
|
160
178
|
const z = new Array(), f = q("debugprogressive");
|
|
161
179
|
let Z, E = -1;
|
|
162
180
|
if (f) {
|
|
163
|
-
let
|
|
181
|
+
let i = function() {
|
|
164
182
|
E += 1, E >= t && (E = -1), console.log(`Toggle LOD level [${E}]`);
|
|
165
183
|
}, t = 6;
|
|
166
184
|
window.addEventListener("keyup", (e) => {
|
|
167
|
-
e.key === "p" &&
|
|
185
|
+
e.key === "p" && i(), e.key === "w" && (Z = !Z, console.log(`Toggle wireframe [${Z}]`));
|
|
168
186
|
const s = parseInt(e.key);
|
|
169
187
|
!isNaN(s) && s >= 0 && (E = s, console.log(`Set LOD level to [${E}]`));
|
|
170
188
|
});
|
|
171
189
|
}
|
|
172
|
-
function
|
|
190
|
+
function Be(i) {
|
|
173
191
|
if (f && Z !== void 0)
|
|
174
|
-
if (Array.isArray(
|
|
175
|
-
for (const t of
|
|
176
|
-
|
|
177
|
-
else
|
|
192
|
+
if (Array.isArray(i))
|
|
193
|
+
for (const t of i)
|
|
194
|
+
Be(t);
|
|
195
|
+
else i && "wireframe" in i && (i.wireframe = Z === !0);
|
|
178
196
|
}
|
|
179
197
|
const J = new Array();
|
|
180
|
-
let
|
|
181
|
-
const
|
|
182
|
-
function
|
|
183
|
-
if (J.length <
|
|
198
|
+
let Mt = 0;
|
|
199
|
+
const vt = ve() ? 2 : 10;
|
|
200
|
+
function Dt(i) {
|
|
201
|
+
if (J.length < vt) {
|
|
184
202
|
const s = J.length;
|
|
185
203
|
f && console.warn(`[Worker] Creating new worker #${s}`);
|
|
186
|
-
const r =
|
|
204
|
+
const r = De.createWorker(i || {});
|
|
187
205
|
return J.push(r), r;
|
|
188
206
|
}
|
|
189
|
-
const t =
|
|
207
|
+
const t = Mt++ % J.length;
|
|
190
208
|
return J[t];
|
|
191
209
|
}
|
|
192
|
-
class
|
|
210
|
+
class De {
|
|
193
211
|
constructor(t, e) {
|
|
194
212
|
this.worker = t, this._debug = e.debug ?? !1, t.onmessage = (s) => {
|
|
195
213
|
const r = s.data;
|
|
196
214
|
switch (this._debug && console.log("[Worker] EVENT", r), r.type) {
|
|
197
215
|
case "loaded-gltf":
|
|
198
|
-
for (const
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
216
|
+
for (const n of this._running)
|
|
217
|
+
if (n.url === r.result.url) {
|
|
218
|
+
bt(r.result), n.resolve(r.result);
|
|
219
|
+
const o = n.url;
|
|
220
|
+
o.startsWith("blob:") && URL.revokeObjectURL(o);
|
|
203
221
|
}
|
|
204
222
|
}
|
|
205
223
|
}, t.onerror = (s) => {
|
|
@@ -209,21 +227,21 @@ class Me {
|
|
|
209
227
|
});
|
|
210
228
|
}
|
|
211
229
|
static async createWorker(t) {
|
|
212
|
-
const e = /* new-worker */ new Worker(URL.createObjectURL(new Blob(["import '" + `${new URL('./gltf-progressive.worker-
|
|
230
|
+
const e = /* new-worker */ new Worker(URL.createObjectURL(new Blob(["import '" + `${new URL('./gltf-progressive.worker-DpfUjn1n.js', import.meta.url).toString()}` + "';"], { type: 'text/javascript' })), {
|
|
213
231
|
type: "module"
|
|
214
232
|
});
|
|
215
|
-
return new
|
|
233
|
+
return new De(e, t);
|
|
216
234
|
}
|
|
217
235
|
_running = [];
|
|
218
236
|
_webglRenderer = null;
|
|
219
237
|
async load(t, e) {
|
|
220
|
-
const s =
|
|
238
|
+
const s = lt();
|
|
221
239
|
let r = e?.renderer;
|
|
222
240
|
r || (this._webglRenderer ??= (async () => {
|
|
223
241
|
const { WebGLRenderer: u } = await import("./three.js").then((c) => c.THREE);
|
|
224
242
|
return new u();
|
|
225
243
|
})(), r = await this._webglRenderer);
|
|
226
|
-
const l =
|
|
244
|
+
const l = Me(r).ktx2Loader.workerConfig;
|
|
227
245
|
t instanceof URL ? t = t.toString() : t.startsWith("file:") ? t = URL.createObjectURL(new Blob([t])) : !t.startsWith("blob:") && !t.startsWith("http:") && !t.startsWith("https:") && (t = new URL(t, window.location.href).toString());
|
|
228
246
|
const a = {
|
|
229
247
|
type: "load",
|
|
@@ -241,21 +259,21 @@ class Me {
|
|
|
241
259
|
}
|
|
242
260
|
_debug = !1;
|
|
243
261
|
}
|
|
244
|
-
function
|
|
245
|
-
for (const t of
|
|
262
|
+
function bt(i) {
|
|
263
|
+
for (const t of i.geometries) {
|
|
246
264
|
const e = t.geometry, s = new V();
|
|
247
265
|
if (s.name = e.name || "", e.index) {
|
|
248
266
|
const r = e.index;
|
|
249
267
|
s.setIndex(ue(r));
|
|
250
268
|
}
|
|
251
269
|
for (const r in e.attributes) {
|
|
252
|
-
const
|
|
253
|
-
s.setAttribute(r,
|
|
270
|
+
const n = e.attributes[r], o = ue(n);
|
|
271
|
+
s.setAttribute(r, o);
|
|
254
272
|
}
|
|
255
273
|
if (e.morphAttributes)
|
|
256
274
|
for (const r in e.morphAttributes) {
|
|
257
|
-
const
|
|
258
|
-
s.morphAttributes[r] =
|
|
275
|
+
const o = e.morphAttributes[r].map((l) => ue(l));
|
|
276
|
+
s.morphAttributes[r] = o;
|
|
259
277
|
}
|
|
260
278
|
if (s.morphTargetsRelative = e.morphTargetsRelative ?? !1, s.boundingBox = new pe(), s.boundingBox.min = new A(
|
|
261
279
|
e.boundingBox?.min.x,
|
|
@@ -265,7 +283,7 @@ function gt(o) {
|
|
|
265
283
|
e.boundingBox?.max.x,
|
|
266
284
|
e.boundingBox?.max.y,
|
|
267
285
|
e.boundingBox?.max.z
|
|
268
|
-
), s.boundingSphere = new
|
|
286
|
+
), s.boundingSphere = new Ae(
|
|
269
287
|
new A(
|
|
270
288
|
e.boundingSphere?.center.x,
|
|
271
289
|
e.boundingSphere?.center.y,
|
|
@@ -277,15 +295,15 @@ function gt(o) {
|
|
|
277
295
|
s.addGroup(r.start, r.count, r.materialIndex);
|
|
278
296
|
e.userData && (s.userData = e.userData), t.geometry = s;
|
|
279
297
|
}
|
|
280
|
-
for (const t of
|
|
298
|
+
for (const t of i.textures) {
|
|
281
299
|
const e = t.texture;
|
|
282
300
|
let s = null;
|
|
283
301
|
if (e.isCompressedTexture) {
|
|
284
|
-
const r = e.mipmaps,
|
|
285
|
-
s = new
|
|
302
|
+
const r = e.mipmaps, { width: n, height: o } = we(e);
|
|
303
|
+
s = new Ke(
|
|
286
304
|
r,
|
|
287
|
-
i,
|
|
288
305
|
n,
|
|
306
|
+
o,
|
|
289
307
|
e.format,
|
|
290
308
|
e.type,
|
|
291
309
|
e.mapping,
|
|
@@ -308,30 +326,30 @@ function gt(o) {
|
|
|
308
326
|
e.type,
|
|
309
327
|
e.anisotropy,
|
|
310
328
|
e.colorSpace
|
|
311
|
-
), s.mipmaps = e.mipmaps, s.channel = e.channel, s.source.data = e.source.data, s.flipY = e.flipY, s.premultiplyAlpha = e.premultiplyAlpha, s.unpackAlignment = e.unpackAlignment, s.matrix = new
|
|
329
|
+
), s.mipmaps = e.mipmaps, s.channel = e.channel, s.source.data = e.source.data, s.flipY = e.flipY, s.premultiplyAlpha = e.premultiplyAlpha, s.unpackAlignment = e.unpackAlignment, s.matrix = new Ye(...e.matrix.elements);
|
|
312
330
|
if (!s) {
|
|
313
331
|
console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");
|
|
314
332
|
continue;
|
|
315
333
|
}
|
|
316
334
|
t.texture = s;
|
|
317
335
|
}
|
|
318
|
-
return
|
|
336
|
+
return i;
|
|
319
337
|
}
|
|
320
|
-
function ue(
|
|
321
|
-
let t =
|
|
322
|
-
if ("isInterleavedBufferAttribute" in
|
|
323
|
-
const e =
|
|
324
|
-
t = new
|
|
325
|
-
} else "isBufferAttribute" in
|
|
338
|
+
function ue(i) {
|
|
339
|
+
let t = i;
|
|
340
|
+
if ("isInterleavedBufferAttribute" in i && i.isInterleavedBufferAttribute) {
|
|
341
|
+
const e = i.data, s = e.array, r = new He(s, e.stride);
|
|
342
|
+
t = new Qe(r, i.itemSize, s.byteOffset, i.normalized), t.offset = i.offset;
|
|
343
|
+
} else "isBufferAttribute" in i && i.isBufferAttribute && (t = new Je(i.array, i.itemSize, i.normalized), t.usage = i.usage, t.gpuType = i.gpuType, t.updateRanges = i.updateRanges);
|
|
326
344
|
return t;
|
|
327
345
|
}
|
|
328
|
-
const
|
|
346
|
+
const Ot = q("gltf-progressive-worker");
|
|
329
347
|
q("gltf-progressive-reduce-mipmaps");
|
|
330
|
-
const K = q("gltf-progressive-gc"), ce = /* @__PURE__ */ Symbol("needle-progressive-texture"),
|
|
348
|
+
const K = q("gltf-progressive-gc"), ce = /* @__PURE__ */ Symbol("needle-progressive-texture"), U = "NEEDLE_progressive";
|
|
331
349
|
class m {
|
|
332
350
|
/** The name of the extension */
|
|
333
351
|
get name() {
|
|
334
|
-
return
|
|
352
|
+
return U;
|
|
335
353
|
}
|
|
336
354
|
// #region PUBLIC API
|
|
337
355
|
static getMeshLODExtension(t) {
|
|
@@ -343,8 +361,8 @@ class m {
|
|
|
343
361
|
return e ?? -1;
|
|
344
362
|
}
|
|
345
363
|
static getMaterialMinMaxLODsCount(t, e) {
|
|
346
|
-
const s = this, r = "LODS:minmax",
|
|
347
|
-
if (
|
|
364
|
+
const s = this, r = "LODS:minmax", n = t[r];
|
|
365
|
+
if (n != null) return n;
|
|
348
366
|
if (e || (e = {
|
|
349
367
|
min_count: 1 / 0,
|
|
350
368
|
max_count: 0,
|
|
@@ -358,17 +376,17 @@ class m {
|
|
|
358
376
|
const l = t;
|
|
359
377
|
for (const a of Object.keys(l.uniforms)) {
|
|
360
378
|
const u = l.uniforms[a].value;
|
|
361
|
-
u?.isTexture === !0 &&
|
|
379
|
+
u?.isTexture === !0 && o(u, e);
|
|
362
380
|
}
|
|
363
381
|
} else if (t.isMaterial)
|
|
364
382
|
for (const l of Object.keys(t)) {
|
|
365
383
|
const a = t[l];
|
|
366
|
-
a?.isTexture === !0 &&
|
|
384
|
+
a?.isTexture === !0 && o(a, e);
|
|
367
385
|
}
|
|
368
386
|
else
|
|
369
387
|
f && console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${t.type}`);
|
|
370
388
|
return t[r] = e, e;
|
|
371
|
-
function
|
|
389
|
+
function o(l, a) {
|
|
372
390
|
const u = s.getAssignedLODInformation(l);
|
|
373
391
|
if (u) {
|
|
374
392
|
const c = s.lodInfos.get(u.key);
|
|
@@ -389,26 +407,26 @@ class m {
|
|
|
389
407
|
*/
|
|
390
408
|
static hasLODLevelAvailable(t, e) {
|
|
391
409
|
if (Array.isArray(t)) {
|
|
392
|
-
for (const
|
|
393
|
-
if (this.hasLODLevelAvailable(
|
|
410
|
+
for (const n of t)
|
|
411
|
+
if (this.hasLODLevelAvailable(n, e)) return !0;
|
|
394
412
|
return !1;
|
|
395
413
|
}
|
|
396
414
|
if (t.isMaterial === !0) {
|
|
397
|
-
for (const
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
415
|
+
for (const n of Object.keys(t)) {
|
|
416
|
+
const o = t[n];
|
|
417
|
+
if (o && o.isTexture && this.hasLODLevelAvailable(o, e))
|
|
400
418
|
return !0;
|
|
401
419
|
}
|
|
402
420
|
return !1;
|
|
403
421
|
} else if (t.isGroup === !0) {
|
|
404
|
-
for (const
|
|
405
|
-
if (
|
|
422
|
+
for (const n of t.children)
|
|
423
|
+
if (n.isMesh === !0 && this.hasLODLevelAvailable(n, e))
|
|
406
424
|
return !0;
|
|
407
425
|
}
|
|
408
426
|
let s, r;
|
|
409
427
|
if (t.isMesh ? s = t.geometry : (t.isBufferGeometry || t.isTexture) && (s = t), s && s?.userData?.LODS) {
|
|
410
|
-
const
|
|
411
|
-
if (r = this.lodInfos.get(
|
|
428
|
+
const n = s.userData.LODS;
|
|
429
|
+
if (r = this.lodInfos.get(n.key), e === void 0) return r != null;
|
|
412
430
|
if (r)
|
|
413
431
|
return Array.isArray(r.lods) ? e < r.lods.length : e === 0;
|
|
414
432
|
}
|
|
@@ -430,19 +448,19 @@ class m {
|
|
|
430
448
|
*/
|
|
431
449
|
static assignMeshLOD(t, e) {
|
|
432
450
|
if (!t) return Promise.resolve(null);
|
|
433
|
-
if (t instanceof
|
|
451
|
+
if (t instanceof j || t.isMesh === !0) {
|
|
434
452
|
const s = t.geometry, r = this.getAssignedLODInformation(s);
|
|
435
453
|
if (!r)
|
|
436
454
|
return Promise.resolve(null);
|
|
437
|
-
for (const
|
|
438
|
-
|
|
439
|
-
return t["LOD:requested level"] = e, m.getOrLoadLOD(s, e).then((
|
|
440
|
-
if (Array.isArray(
|
|
441
|
-
const
|
|
442
|
-
|
|
455
|
+
for (const n of z)
|
|
456
|
+
n.onBeforeGetLODMesh?.(t, e);
|
|
457
|
+
return t["LOD:requested level"] = e, m.getOrLoadLOD(s, e).then((n) => {
|
|
458
|
+
if (Array.isArray(n)) {
|
|
459
|
+
const o = r.index || 0;
|
|
460
|
+
n = n[o];
|
|
443
461
|
}
|
|
444
|
-
return t["LOD:requested level"] === e && (delete t["LOD:requested level"],
|
|
445
|
-
}).catch((
|
|
462
|
+
return t["LOD:requested level"] === e && (delete t["LOD:requested level"], n && s != n && (n?.isBufferGeometry ? t.geometry = n : f && console.error("Invalid LOD geometry", n))), n;
|
|
463
|
+
}).catch((n) => (console.error("Error loading mesh LOD", t, n), null));
|
|
446
464
|
} else f && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
|
|
447
465
|
return Promise.resolve(null);
|
|
448
466
|
}
|
|
@@ -452,42 +470,42 @@ class m {
|
|
|
452
470
|
const s = t;
|
|
453
471
|
if (Array.isArray(s.material)) {
|
|
454
472
|
const r = new Array();
|
|
455
|
-
for (const
|
|
456
|
-
const
|
|
457
|
-
r.push(
|
|
473
|
+
for (const n of s.material) {
|
|
474
|
+
const o = this.assignTextureLOD(n, e);
|
|
475
|
+
r.push(o);
|
|
458
476
|
}
|
|
459
|
-
return Promise.all(r).then((
|
|
460
|
-
const
|
|
461
|
-
for (const l of
|
|
462
|
-
Array.isArray(l) &&
|
|
463
|
-
return
|
|
477
|
+
return Promise.all(r).then((n) => {
|
|
478
|
+
const o = new Array();
|
|
479
|
+
for (const l of n)
|
|
480
|
+
Array.isArray(l) && o.push(...l);
|
|
481
|
+
return o;
|
|
464
482
|
});
|
|
465
483
|
} else
|
|
466
484
|
return this.assignTextureLOD(s.material, e);
|
|
467
485
|
}
|
|
468
486
|
if (t.isMaterial === !0) {
|
|
469
|
-
const s = t, r = [],
|
|
487
|
+
const s = t, r = [], n = new Array();
|
|
470
488
|
if (s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
|
|
471
|
-
const
|
|
472
|
-
for (const l of Object.keys(
|
|
473
|
-
const a =
|
|
489
|
+
const o = s;
|
|
490
|
+
for (const l of Object.keys(o.uniforms)) {
|
|
491
|
+
const a = o.uniforms[l].value;
|
|
474
492
|
if (a?.isTexture === !0) {
|
|
475
|
-
const u = this.assignTextureLODForSlot(a, e, s, l).then((c) => (c &&
|
|
476
|
-
r.push(u),
|
|
493
|
+
const u = this.assignTextureLODForSlot(a, e, s, l).then((c) => (c && o.uniforms[l].value != c && (o.uniforms[l].value = c, o.uniformsNeedUpdate = !0), c));
|
|
494
|
+
r.push(u), n.push(l);
|
|
477
495
|
}
|
|
478
496
|
}
|
|
479
497
|
} else
|
|
480
|
-
for (const
|
|
481
|
-
const l = s[
|
|
498
|
+
for (const o of Object.keys(s)) {
|
|
499
|
+
const l = s[o];
|
|
482
500
|
if (l?.isTexture === !0) {
|
|
483
|
-
const a = this.assignTextureLODForSlot(l, e, s,
|
|
484
|
-
r.push(a),
|
|
501
|
+
const a = this.assignTextureLODForSlot(l, e, s, o);
|
|
502
|
+
r.push(a), n.push(o);
|
|
485
503
|
}
|
|
486
504
|
}
|
|
487
|
-
return Promise.all(r).then((
|
|
505
|
+
return Promise.all(r).then((o) => {
|
|
488
506
|
const l = new Array();
|
|
489
|
-
for (let a = 0; a <
|
|
490
|
-
const u =
|
|
507
|
+
for (let a = 0; a < o.length; a++) {
|
|
508
|
+
const u = o[a], c = n[a];
|
|
491
509
|
u && u.isTexture === !0 ? l.push({ material: s, slot: c, texture: u, level: e }) : l.push({ material: s, slot: c, texture: null, level: e });
|
|
492
510
|
}
|
|
493
511
|
return l;
|
|
@@ -511,27 +529,27 @@ class m {
|
|
|
511
529
|
}
|
|
512
530
|
// #region INTERNAL
|
|
513
531
|
static assignTextureLODForSlot(t, e, s, r) {
|
|
514
|
-
return t?.isTexture !== !0 ? Promise.resolve(null) : r === "glyphMap" ? Promise.resolve(t) : m.getOrLoadLOD(t, e).then((
|
|
515
|
-
if (Array.isArray(
|
|
532
|
+
return t?.isTexture !== !0 ? Promise.resolve(null) : r === "glyphMap" ? Promise.resolve(t) : m.getOrLoadLOD(t, e).then((n) => {
|
|
533
|
+
if (Array.isArray(n))
|
|
516
534
|
return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."), null;
|
|
517
|
-
if (
|
|
518
|
-
if (
|
|
519
|
-
const
|
|
520
|
-
if (
|
|
521
|
-
const l = this.getAssignedLODInformation(
|
|
535
|
+
if (n?.isTexture === !0) {
|
|
536
|
+
if (n != t && s && r) {
|
|
537
|
+
const o = s[r];
|
|
538
|
+
if (o && !f) {
|
|
539
|
+
const l = this.getAssignedLODInformation(o);
|
|
522
540
|
if (l && l?.level < e)
|
|
523
|
-
return f === "verbose" && console.warn("Assigned texture level is already higher: ", l.level, e, s,
|
|
541
|
+
return f === "verbose" && console.warn("Assigned texture level is already higher: ", l.level, e, s, o, n), n && n !== o && ((f || K) && console.log(`[gltf-progressive] Disposing rejected lower-quality texture LOD ${e} (assigned is ${l.level})`, n.uuid), n.dispose()), null;
|
|
524
542
|
}
|
|
525
|
-
if (this.trackTextureUsage(
|
|
526
|
-
const a = this.getAssignedLODInformation(
|
|
527
|
-
console.log(`[gltf-progressive] Disposed old texture LOD ${a?.level ?? "?"} → ${e} for ${s.name || s.type}.${r}`,
|
|
543
|
+
if (this.trackTextureUsage(n), o && o !== n && this.untrackTextureUsage(o) && (f || K)) {
|
|
544
|
+
const a = this.getAssignedLODInformation(o);
|
|
545
|
+
console.log(`[gltf-progressive] Disposed old texture LOD ${a?.level ?? "?"} → ${e} for ${s.name || s.type}.${r}`, o.uuid);
|
|
528
546
|
}
|
|
529
|
-
s[r] =
|
|
547
|
+
s[r] = n;
|
|
530
548
|
}
|
|
531
|
-
return
|
|
549
|
+
return n;
|
|
532
550
|
} else f == "verbose" && console.warn("No LOD found for", t, e);
|
|
533
551
|
return null;
|
|
534
|
-
}).catch((
|
|
552
|
+
}).catch((n) => (console.error("Error loading LOD", t, n), null));
|
|
535
553
|
}
|
|
536
554
|
parser;
|
|
537
555
|
url;
|
|
@@ -542,7 +560,7 @@ class m {
|
|
|
542
560
|
_isLoadingMesh;
|
|
543
561
|
loadMesh = (t) => {
|
|
544
562
|
if (this._isLoadingMesh) return null;
|
|
545
|
-
const e = this.parser.json.meshes[t]?.extensions?.[
|
|
563
|
+
const e = this.parser.json.meshes[t]?.extensions?.[U];
|
|
546
564
|
return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((s) => (this._isLoadingMesh = !1, s && m.registerMesh(this.url, e.guid, s, e.lods?.length, 0, e), s))) : null;
|
|
547
565
|
};
|
|
548
566
|
// private _isLoadingTexture;
|
|
@@ -562,28 +580,28 @@ class m {
|
|
|
562
580
|
afterRoot(t) {
|
|
563
581
|
return f && console.log("AFTER", this.url, t), this.parser.json.textures?.forEach((e, s) => {
|
|
564
582
|
if (e?.extensions) {
|
|
565
|
-
const r = e?.extensions[
|
|
583
|
+
const r = e?.extensions[U];
|
|
566
584
|
if (r) {
|
|
567
585
|
if (!r.lods) {
|
|
568
586
|
f && console.warn("Texture has no LODs", r);
|
|
569
587
|
return;
|
|
570
588
|
}
|
|
571
|
-
let
|
|
572
|
-
for (const
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
589
|
+
let n = !1;
|
|
590
|
+
for (const o of this.parser.associations.keys())
|
|
591
|
+
o.isTexture === !0 && this.parser.associations.get(o)?.textures === s && (n = !0, m.registerTexture(this.url, o, r.lods?.length, s, r));
|
|
592
|
+
n || this.parser.getDependency("texture", s).then((o) => {
|
|
593
|
+
o && m.registerTexture(this.url, o, r.lods?.length, s, r);
|
|
576
594
|
});
|
|
577
595
|
}
|
|
578
596
|
}
|
|
579
597
|
}), this.parser.json.meshes?.forEach((e, s) => {
|
|
580
598
|
if (e?.extensions) {
|
|
581
|
-
const r = e?.extensions[
|
|
599
|
+
const r = e?.extensions[U];
|
|
582
600
|
if (r && r.lods) {
|
|
583
|
-
for (const
|
|
584
|
-
if (
|
|
585
|
-
const
|
|
586
|
-
|
|
601
|
+
for (const n of this.parser.associations.keys())
|
|
602
|
+
if (n.isMesh) {
|
|
603
|
+
const o = this.parser.associations.get(n);
|
|
604
|
+
o?.meshes === s && m.registerMesh(this.url, r.guid, n, r.lods.length, o.primitives, r);
|
|
587
605
|
}
|
|
588
606
|
}
|
|
589
607
|
}
|
|
@@ -592,33 +610,33 @@ class m {
|
|
|
592
610
|
/**
|
|
593
611
|
* Register a texture with LOD information
|
|
594
612
|
*/
|
|
595
|
-
static registerTexture = (t, e, s, r,
|
|
613
|
+
static registerTexture = (t, e, s, r, n) => {
|
|
596
614
|
if (!e) {
|
|
597
615
|
f && console.error("!! gltf-progressive: Called register texture without texture");
|
|
598
616
|
return;
|
|
599
617
|
}
|
|
600
618
|
if (f) {
|
|
601
|
-
const
|
|
602
|
-
console.log(`> gltf-progressive: register texture[${r}] "${e.name || e.uuid}", Current: ${l}x${a}, Max: ${
|
|
619
|
+
const { width: l, height: a } = we(e);
|
|
620
|
+
console.log(`> gltf-progressive: register texture[${r}] "${e.name || e.uuid}", Current: ${l}x${a}, Max: ${n.lods[0]?.width}x${n.lods[0]?.height}, uuid: ${e.uuid}`, n, e);
|
|
603
621
|
}
|
|
604
|
-
e.source && (e.source[ce] =
|
|
605
|
-
const
|
|
606
|
-
m.assignLODInformation(t, e,
|
|
622
|
+
e.source && (e.source[ce] = n);
|
|
623
|
+
const o = n.guid;
|
|
624
|
+
m.assignLODInformation(t, e, o, s, r), m.lodInfos.set(o, n), m.lowresCache.set(o, new WeakRef(e));
|
|
607
625
|
};
|
|
608
626
|
/**
|
|
609
627
|
* Register a mesh with LOD information
|
|
610
628
|
*/
|
|
611
|
-
static registerMesh = (t, e, s, r,
|
|
629
|
+
static registerMesh = (t, e, s, r, n, o) => {
|
|
612
630
|
const l = s.geometry;
|
|
613
631
|
if (!l) {
|
|
614
632
|
f && console.warn("gltf-progressive: Register mesh without geometry");
|
|
615
633
|
return;
|
|
616
634
|
}
|
|
617
|
-
l.userData || (l.userData = {}), f && console.log("> Progressive: register mesh " + s.name, { index:
|
|
635
|
+
l.userData || (l.userData = {}), f && console.log("> Progressive: register mesh " + s.name, { index: n, uuid: s.uuid }, o, s), m.assignLODInformation(t, l, e, r, n), m.lodInfos.set(e, o);
|
|
618
636
|
let u = m.lowresCache.get(e)?.deref();
|
|
619
|
-
u ? u.push(s.geometry) : u = [s.geometry], m.lowresCache.set(e, new WeakRef(u)), r > 0 && !ee(s) &&
|
|
637
|
+
u ? u.push(s.geometry) : u = [s.geometry], m.lowresCache.set(e, new WeakRef(u)), r > 0 && !ee(s) && wt(s, l);
|
|
620
638
|
for (const c of z)
|
|
621
|
-
c.onRegisteredNewMesh?.(s,
|
|
639
|
+
c.onRegisteredNewMesh?.(s, o);
|
|
622
640
|
};
|
|
623
641
|
/**
|
|
624
642
|
* Dispose cached resources to free memory.
|
|
@@ -710,16 +728,16 @@ ${t}`), e instanceof WeakRef && (e.deref() || (m.cache.delete(t), (f || K) && co
|
|
|
710
728
|
static untrackTextureUsage(t) {
|
|
711
729
|
const e = t.uuid, s = this.textureRefCounts.get(e);
|
|
712
730
|
if (!s)
|
|
713
|
-
return (f === "verbose" || K) &&
|
|
731
|
+
return (f === "verbose" || K) && n("[gltf-progressive] Memory: Untrack untracked texture (dispose immediately)", 0), t.dispose(), !0;
|
|
714
732
|
const r = s - 1;
|
|
715
733
|
if (r <= 0)
|
|
716
|
-
return this.textureRefCounts.delete(e), (f || K) &&
|
|
717
|
-
return this.textureRefCounts.set(e, r), f === "verbose" &&
|
|
718
|
-
function
|
|
719
|
-
let
|
|
734
|
+
return this.textureRefCounts.delete(e), (f || K) && n("[gltf-progressive] Memory: Dispose texture", r), t.dispose(), !0;
|
|
735
|
+
return this.textureRefCounts.set(e, r), f === "verbose" && n("[gltf-progressive] Memory: Untrack texture", r), !1;
|
|
736
|
+
function n(o, l) {
|
|
737
|
+
let { width: a, height: u } = we(t);
|
|
720
738
|
const c = a && u ? `${a}x${u}` : "N/A";
|
|
721
739
|
let y = "N/A";
|
|
722
|
-
a && u && (y = `~${(
|
|
740
|
+
a && u && (y = `~${(mt(t) / (1024 * 1024)).toFixed(2)} MB`), console.log(`${o} — ${t.name} ${c} (${y}), refCount: ${s} → ${l}
|
|
723
741
|
${e}`);
|
|
724
742
|
}
|
|
725
743
|
}
|
|
@@ -729,73 +747,73 @@ ${e}`);
|
|
|
729
747
|
const s = f == "verbose", r = this.getAssignedLODInformation(t);
|
|
730
748
|
if (!r)
|
|
731
749
|
return f && console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`, t), null;
|
|
732
|
-
const
|
|
733
|
-
let
|
|
750
|
+
const n = r?.key;
|
|
751
|
+
let o;
|
|
734
752
|
if (t.isTexture === !0) {
|
|
735
753
|
const a = t;
|
|
736
|
-
a.source && a.source[ce] && (
|
|
754
|
+
a.source && a.source[ce] && (o = a.source[ce]);
|
|
737
755
|
}
|
|
738
|
-
if (
|
|
739
|
-
f && console.warn(`Can not load LOD ${e}: no LOD info found for "${
|
|
756
|
+
if (o || (o = m.lodInfos.get(n)), !o)
|
|
757
|
+
f && console.warn(`Can not load LOD ${e}: no LOD info found for "${n}" ${t.name}`, t.type, m.lodInfos);
|
|
740
758
|
else {
|
|
741
759
|
if (e > 0) {
|
|
742
760
|
let c = !1;
|
|
743
|
-
const y = Array.isArray(
|
|
744
|
-
if (y && e >=
|
|
745
|
-
const w = this.lowresCache.get(
|
|
761
|
+
const y = Array.isArray(o.lods);
|
|
762
|
+
if (y && e >= o.lods.length ? c = !0 : y || (c = !0), c) {
|
|
763
|
+
const w = this.lowresCache.get(n);
|
|
746
764
|
if (w) {
|
|
747
765
|
const L = w.deref();
|
|
748
766
|
if (L) return L;
|
|
749
|
-
this.lowresCache.delete(
|
|
767
|
+
this.lowresCache.delete(n), f && console.log(`[gltf-progressive] Lowres cache entry was GC'd: ${n}`);
|
|
750
768
|
}
|
|
751
769
|
return null;
|
|
752
770
|
}
|
|
753
771
|
}
|
|
754
|
-
const a = Array.isArray(
|
|
772
|
+
const a = Array.isArray(o.lods) ? o.lods[e]?.path : o.lods;
|
|
755
773
|
if (!a)
|
|
756
|
-
return f && !
|
|
757
|
-
const u =
|
|
774
|
+
return f && !o["missing:uri"] && (o["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, o)), null;
|
|
775
|
+
const u = gt(r.url, a);
|
|
758
776
|
if (u.endsWith(".glb") || u.endsWith(".gltf")) {
|
|
759
|
-
if (!
|
|
760
|
-
return console.warn("missing pointer for glb/gltf texture",
|
|
761
|
-
const c = u + "_" +
|
|
777
|
+
if (!o.guid)
|
|
778
|
+
return console.warn("missing pointer for glb/gltf texture", o), null;
|
|
779
|
+
const c = u + "_" + o.guid, y = await this.queue.slot(u), w = this.cache.get(c);
|
|
762
780
|
if (w !== void 0)
|
|
763
781
|
if (s && console.log(`LOD ${e} was already loading/loaded: ${c}`), w instanceof WeakRef) {
|
|
764
782
|
const d = w.deref();
|
|
765
783
|
if (d) {
|
|
766
784
|
let g = d, M = !1;
|
|
767
|
-
if (g instanceof F && t instanceof F ? g.image
|
|
785
|
+
if (g instanceof F && t instanceof F ? Oe(g.image) || xe(g) ? g = this.copySettings(t, g) : M = !0 : g instanceof V && t instanceof V && (g.attributes.position?.array || (M = !0)), !M)
|
|
768
786
|
return g;
|
|
769
787
|
}
|
|
770
788
|
this.cache.delete(c), f && console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${c}`);
|
|
771
789
|
} else {
|
|
772
790
|
let d = await w.catch((M) => (console.error(`Error loading LOD ${e} from ${u}
|
|
773
791
|
`, M), null)), g = !1;
|
|
774
|
-
if (d == null || (d instanceof F && t instanceof F ? d.image
|
|
792
|
+
if (d == null || (d instanceof F && t instanceof F ? Oe(d.image) || xe(d) ? d = this.copySettings(t, d) : (g = !0, this.cache.delete(c)) : d instanceof V && t instanceof V && (d.attributes.position?.array || (g = !0, this.cache.delete(c)))), !g)
|
|
775
793
|
return d;
|
|
776
794
|
}
|
|
777
795
|
if (!y.use)
|
|
778
796
|
return f && console.log(`LOD ${e} was aborted: ${u}`), null;
|
|
779
|
-
const L =
|
|
780
|
-
if (
|
|
781
|
-
const x = await (await
|
|
797
|
+
const L = o, R = new Promise(async (d, g) => {
|
|
798
|
+
if (Ot) {
|
|
799
|
+
const x = await (await Dt({})).load(u);
|
|
782
800
|
if (x.textures.length > 0)
|
|
783
801
|
for (const h of x.textures) {
|
|
784
802
|
let p = h.texture;
|
|
785
|
-
return m.assignLODInformation(r.url, p,
|
|
803
|
+
return m.assignLODInformation(r.url, p, n, e, void 0), t instanceof F && (p = this.copySettings(t, p)), p && (p.guid = L.guid), d(p);
|
|
786
804
|
}
|
|
787
805
|
if (x.geometries.length > 0) {
|
|
788
806
|
const h = new Array();
|
|
789
807
|
for (const p of x.geometries) {
|
|
790
808
|
const b = p.geometry;
|
|
791
|
-
m.assignLODInformation(r.url, b,
|
|
809
|
+
m.assignLODInformation(r.url, b, n, e, p.primitiveIndex), h.push(b);
|
|
792
810
|
}
|
|
793
811
|
return d(h);
|
|
794
812
|
}
|
|
795
813
|
return d(null);
|
|
796
814
|
}
|
|
797
|
-
const M = new
|
|
798
|
-
|
|
815
|
+
const M = new _e();
|
|
816
|
+
ke(M), f && (await new Promise((_) => setTimeout(_, 1e3)), s && console.warn("Start loading (delayed) " + u, L.guid));
|
|
799
817
|
let B = u;
|
|
800
818
|
if (L && Array.isArray(L.lods)) {
|
|
801
819
|
const _ = L.lods[e];
|
|
@@ -812,7 +830,7 @@ ${e}`);
|
|
|
812
830
|
let _ = !1;
|
|
813
831
|
for (const x of D.parser.json.textures) {
|
|
814
832
|
if (x?.extensions) {
|
|
815
|
-
const h = x?.extensions[
|
|
833
|
+
const h = x?.extensions[U];
|
|
816
834
|
if (h?.guid && h.guid === L.guid) {
|
|
817
835
|
_ = !0;
|
|
818
836
|
break;
|
|
@@ -822,14 +840,14 @@ ${e}`);
|
|
|
822
840
|
}
|
|
823
841
|
if (_) {
|
|
824
842
|
let x = await N.getDependency("texture", T);
|
|
825
|
-
return x && m.assignLODInformation(r.url, x,
|
|
843
|
+
return x && m.assignLODInformation(r.url, x, n, e, void 0), s && console.log('change "' + t.name + '" → "' + x.name + '"', u, T, x, c), t instanceof F && (x = this.copySettings(t, x)), x && (x.guid = L.guid), d(x);
|
|
826
844
|
} else f && console.warn("Could not find texture with guid", L.guid, D.parser.json);
|
|
827
845
|
}
|
|
828
846
|
if (T = 0, D.parser.json.meshes) {
|
|
829
847
|
let _ = !1;
|
|
830
848
|
for (const x of D.parser.json.meshes) {
|
|
831
849
|
if (x?.extensions) {
|
|
832
|
-
const h = x?.extensions[
|
|
850
|
+
const h = x?.extensions[U];
|
|
833
851
|
if (h?.guid && h.guid === L.guid) {
|
|
834
852
|
_ = !0;
|
|
835
853
|
break;
|
|
@@ -841,14 +859,14 @@ ${e}`);
|
|
|
841
859
|
const x = await N.getDependency("mesh", T);
|
|
842
860
|
if (s && console.log(`Loaded Mesh "${x.name}"`, u, T, x, c), x.isMesh === !0) {
|
|
843
861
|
const h = x.geometry;
|
|
844
|
-
return m.assignLODInformation(r.url, h,
|
|
862
|
+
return m.assignLODInformation(r.url, h, n, e, 0), d(h);
|
|
845
863
|
} else {
|
|
846
864
|
const h = new Array();
|
|
847
865
|
for (let p = 0; p < x.children.length; p++) {
|
|
848
866
|
const b = x.children[p];
|
|
849
867
|
if (b.isMesh === !0) {
|
|
850
868
|
const S = b.geometry;
|
|
851
|
-
m.assignLODInformation(r.url, S,
|
|
869
|
+
m.assignLODInformation(r.url, S, n, e, p), h.push(S);
|
|
852
870
|
}
|
|
853
871
|
}
|
|
854
872
|
return d(h);
|
|
@@ -857,23 +875,23 @@ ${e}`);
|
|
|
857
875
|
}
|
|
858
876
|
return d(null);
|
|
859
877
|
});
|
|
860
|
-
this.cache.set(c,
|
|
861
|
-
const v = await
|
|
878
|
+
this.cache.set(c, R), y.use(R);
|
|
879
|
+
const v = await R;
|
|
862
880
|
return v != null ? v instanceof F ? (this.cache.set(c, new WeakRef(v)), m._resourceRegistry.register(v, c)) : Array.isArray(v) ? this.cache.set(c, Promise.resolve(v)) : this.cache.set(c, Promise.resolve(v)) : this.cache.set(c, Promise.resolve(null)), v;
|
|
863
881
|
} else if (t instanceof F) {
|
|
864
882
|
s && console.log("Load texture from uri: " + u);
|
|
865
|
-
const y = await new
|
|
866
|
-
return y ? (y.guid =
|
|
883
|
+
const y = await new Ze().loadAsync(u);
|
|
884
|
+
return y ? (y.guid = o.guid, y.flipY = !1, y.needsUpdate = !0, y.colorSpace = t.colorSpace, s && console.log(o, y)) : f && console.warn("failed loading", u), y;
|
|
867
885
|
}
|
|
868
886
|
}
|
|
869
887
|
return null;
|
|
870
888
|
}
|
|
871
|
-
static queue = new
|
|
872
|
-
static assignLODInformation(t, e, s, r,
|
|
889
|
+
static queue = new pt(ve() ? 20 : 50, { debug: f != !1 });
|
|
890
|
+
static assignLODInformation(t, e, s, r, n) {
|
|
873
891
|
if (!e) return;
|
|
874
892
|
e.userData || (e.userData = {});
|
|
875
|
-
const
|
|
876
|
-
e.userData.LODS =
|
|
893
|
+
const o = new St(t, s, r, n);
|
|
894
|
+
e.userData.LODS = o, "source" in e && typeof e.source == "object" && (e.source.LODS = o);
|
|
877
895
|
}
|
|
878
896
|
static getAssignedLODInformation(t) {
|
|
879
897
|
return t ? t.userData?.LODS ? t.userData.LODS : "source" in t && t.source?.LODS ? t.source.LODS : null : null;
|
|
@@ -885,7 +903,7 @@ ${e}`);
|
|
|
885
903
|
`, e.uuid), e = e.clone(), e.offset = t.offset, e.repeat = t.repeat, e.colorSpace = t.colorSpace, e.magFilter = t.magFilter, e.minFilter = t.minFilter, e.wrapS = t.wrapS, e.wrapT = t.wrapT, e.flipY = t.flipY, e.anisotropy = t.anisotropy, e.mipmaps || (e.generateMipmaps = t.generateMipmaps), e) : t;
|
|
886
904
|
}
|
|
887
905
|
}
|
|
888
|
-
class
|
|
906
|
+
class St {
|
|
889
907
|
url;
|
|
890
908
|
/** the key to lookup the LOD information */
|
|
891
909
|
key;
|
|
@@ -898,8 +916,8 @@ class mt {
|
|
|
898
916
|
}
|
|
899
917
|
class de {
|
|
900
918
|
static addPromise = (t, e, s, r) => {
|
|
901
|
-
r.forEach((
|
|
902
|
-
|
|
919
|
+
r.forEach((n) => {
|
|
920
|
+
n.add(t, e, s);
|
|
903
921
|
});
|
|
904
922
|
};
|
|
905
923
|
ready;
|
|
@@ -930,8 +948,8 @@ class de {
|
|
|
930
948
|
_maxPromisesPerObject = 1;
|
|
931
949
|
constructor(t, e) {
|
|
932
950
|
const r = Math.max(e.frames ?? 2, 2);
|
|
933
|
-
this._frame_start = e.waitForFirstCapture ? void 0 : t, this._frames_to_capture = r, this.ready = new Promise((
|
|
934
|
-
this._resolve =
|
|
951
|
+
this._frame_start = e.waitForFirstCapture ? void 0 : t, this._frames_to_capture = r, this.ready = new Promise((n) => {
|
|
952
|
+
this._resolve = n;
|
|
935
953
|
}), this.ready.finally(() => {
|
|
936
954
|
this._resolved = !0, this._awaiting.length = 0;
|
|
937
955
|
}), this._signal = e.signal, this._signal?.addEventListener("abort", () => {
|
|
@@ -972,8 +990,8 @@ class de {
|
|
|
972
990
|
});
|
|
973
991
|
}
|
|
974
992
|
}
|
|
975
|
-
const
|
|
976
|
-
let
|
|
993
|
+
const k = q("debugprogressive"), Tt = q("noprogressive"), fe = /* @__PURE__ */ Symbol("Needle:LODSManager"), he = /* @__PURE__ */ Symbol("Needle:LODState"), W = /* @__PURE__ */ Symbol("Needle:CurrentLOD"), P = { mesh_lod: -1, texture_lod: -1 };
|
|
994
|
+
let ie = class O {
|
|
977
995
|
/**
|
|
978
996
|
* Assign a function to draw debug lines for the LODs. This function will be called with the start and end position of the line and the color of the line when the `debugprogressive` query parameter is set.
|
|
979
997
|
*/
|
|
@@ -1005,7 +1023,7 @@ let oe = class O {
|
|
|
1005
1023
|
}
|
|
1006
1024
|
renderer;
|
|
1007
1025
|
context;
|
|
1008
|
-
projectionScreenMatrix = new
|
|
1026
|
+
projectionScreenMatrix = new be();
|
|
1009
1027
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
1010
1028
|
get plugins() {
|
|
1011
1029
|
return z;
|
|
@@ -1053,8 +1071,8 @@ let oe = class O {
|
|
|
1053
1071
|
this._newPromiseGroups.push(s);
|
|
1054
1072
|
const r = performance.now();
|
|
1055
1073
|
return s.ready.finally(() => {
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1074
|
+
const n = this._newPromiseGroups.indexOf(s);
|
|
1075
|
+
n >= 0 && (this._newPromiseGroups.splice(n, 1), Se() && performance.measure("LODsManager:awaitLoading", {
|
|
1058
1076
|
start: r,
|
|
1059
1077
|
detail: { id: e, name: t?.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
|
|
1060
1078
|
}));
|
|
@@ -1080,10 +1098,10 @@ let oe = class O {
|
|
|
1080
1098
|
this.renderer = t, this.context = { ...e };
|
|
1081
1099
|
}
|
|
1082
1100
|
#t;
|
|
1083
|
-
#
|
|
1101
|
+
#o = new et();
|
|
1084
1102
|
#r = 0;
|
|
1103
|
+
#n = 0;
|
|
1085
1104
|
#i = 0;
|
|
1086
|
-
#o = 0;
|
|
1087
1105
|
#s = 0;
|
|
1088
1106
|
_fpsBuffer = [60, 60, 60, 60, 60];
|
|
1089
1107
|
/**
|
|
@@ -1095,11 +1113,11 @@ let oe = class O {
|
|
|
1095
1113
|
let t = 0;
|
|
1096
1114
|
this.#t = this.renderer.render;
|
|
1097
1115
|
const e = this;
|
|
1098
|
-
|
|
1099
|
-
const
|
|
1100
|
-
(
|
|
1101
|
-
const
|
|
1102
|
-
e.#t.call(this, s, r), e.onAfterRender(s, r,
|
|
1116
|
+
Me(this.renderer), this.renderer.render = function(s, r) {
|
|
1117
|
+
const n = e.renderer.getRenderTarget();
|
|
1118
|
+
(n == null || "isXRRenderTarget" in n && n.isXRRenderTarget) && (t = 0, e.#r += 1, e.#o.update(), e.#n = e.#o.getDelta(), e.#i += e.#n, e._fpsBuffer.shift(), e._fpsBuffer.push(1 / e.#n), e.#s = e._fpsBuffer.reduce((l, a) => l + a) / e._fpsBuffer.length, k && e.#r % 200 === 0 && console.log("FPS", Math.round(e.#s), "Interval:", e.#e));
|
|
1119
|
+
const o = t++;
|
|
1120
|
+
e.#t.call(this, s, r), e.onAfterRender(s, r, o);
|
|
1103
1121
|
};
|
|
1104
1122
|
}
|
|
1105
1123
|
disable() {
|
|
@@ -1110,14 +1128,14 @@ let oe = class O {
|
|
|
1110
1128
|
}
|
|
1111
1129
|
onAfterRender(t, e, s) {
|
|
1112
1130
|
if (this.pause) return;
|
|
1113
|
-
const
|
|
1114
|
-
let
|
|
1115
|
-
if (
|
|
1116
|
-
const l =
|
|
1117
|
-
(l.name === "EffectMaterial" || l.name === "CopyShader") && (
|
|
1131
|
+
const n = this.renderer.renderLists.get(t, 0).opaque;
|
|
1132
|
+
let o = !0;
|
|
1133
|
+
if (n.length === 1) {
|
|
1134
|
+
const l = n[0].material;
|
|
1135
|
+
(l.name === "EffectMaterial" || l.name === "CopyShader") && (o = !1);
|
|
1118
1136
|
}
|
|
1119
|
-
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (
|
|
1120
|
-
if (
|
|
1137
|
+
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (o = !1), o) {
|
|
1138
|
+
if (Tt || (this.updateInterval === "auto" ? this.#s < 40 && this.#e < 10 ? (this.#e += 1, k && console.warn("↓ Reducing LOD updates", this.#e, this.#s.toFixed(0))) : this.#s >= 60 && this.#e > 1 && (this.#e -= 1, k && console.warn("↑ Increasing LOD updates", this.#e, this.#s.toFixed(0))) : this.#e = this.updateInterval, this.#e > 0 && this.#r % this.#e != 0))
|
|
1121
1139
|
return;
|
|
1122
1140
|
this.internalUpdate(t, e), this._postprocessPromiseGroups();
|
|
1123
1141
|
}
|
|
@@ -1128,10 +1146,10 @@ let oe = class O {
|
|
|
1128
1146
|
internalUpdate(t, e) {
|
|
1129
1147
|
const s = this.renderer.renderLists.get(t, 0), r = s.opaque;
|
|
1130
1148
|
this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse);
|
|
1131
|
-
const
|
|
1149
|
+
const n = this.targetTriangleDensity;
|
|
1132
1150
|
for (const a of r) {
|
|
1133
1151
|
if (a.material && (a.geometry?.type === "BoxGeometry" || a.geometry?.type === "BufferGeometry") && (a.material.name === "SphericalGaussianBlur" || a.material.name == "BackgroundCubeMaterial" || a.material.name === "CubemapFromEquirect" || a.material.name === "EquirectangularToCubeUV")) {
|
|
1134
|
-
|
|
1152
|
+
k && (a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", a, a.material.name, a.material.type)));
|
|
1135
1153
|
continue;
|
|
1136
1154
|
}
|
|
1137
1155
|
switch (a.material.type) {
|
|
@@ -1143,38 +1161,38 @@ let oe = class O {
|
|
|
1143
1161
|
case "MeshDepthMaterial":
|
|
1144
1162
|
continue;
|
|
1145
1163
|
}
|
|
1146
|
-
if (
|
|
1164
|
+
if (k === "color" && a.material && !a.object.progressive_debug_color) {
|
|
1147
1165
|
a.object.progressive_debug_color = !0;
|
|
1148
|
-
const c = Math.random() * 16777215, y = new
|
|
1166
|
+
const c = Math.random() * 16777215, y = new tt({ color: c });
|
|
1149
1167
|
a.object.material = y;
|
|
1150
1168
|
}
|
|
1151
1169
|
const u = a.object;
|
|
1152
|
-
(u instanceof
|
|
1170
|
+
(u instanceof j || u.isMesh) && this.updateLODs(t, e, u, n);
|
|
1153
1171
|
}
|
|
1154
|
-
const
|
|
1155
|
-
for (const a of
|
|
1172
|
+
const o = s.transparent;
|
|
1173
|
+
for (const a of o) {
|
|
1156
1174
|
const u = a.object;
|
|
1157
|
-
(u instanceof
|
|
1175
|
+
(u instanceof j || u.isMesh) && this.updateLODs(t, e, u, n);
|
|
1158
1176
|
}
|
|
1159
1177
|
const l = s.transmissive;
|
|
1160
1178
|
for (const a of l) {
|
|
1161
1179
|
const u = a.object;
|
|
1162
|
-
(u instanceof
|
|
1180
|
+
(u instanceof j || u.isMesh) && this.updateLODs(t, e, u, n);
|
|
1163
1181
|
}
|
|
1164
1182
|
}
|
|
1165
1183
|
/** Update the LOD levels for the renderer. */
|
|
1166
1184
|
updateLODs(t, e, s, r) {
|
|
1167
1185
|
s.userData || (s.userData = {});
|
|
1168
|
-
let
|
|
1169
|
-
if (
|
|
1186
|
+
let n = s[he];
|
|
1187
|
+
if (n || (n = new Pt(), s[he] = n), n.frames++ < 2)
|
|
1170
1188
|
return;
|
|
1171
1189
|
for (const l of z)
|
|
1172
1190
|
l.onBeforeUpdateLOD?.(this.renderer, t, e, s);
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1191
|
+
const o = this.overrideLodLevel !== void 0 ? this.overrideLodLevel : E;
|
|
1192
|
+
o >= 0 ? (P.mesh_lod = o, P.texture_lod = o) : (this.calculateLodLevel(e, s, n, r, P), P.mesh_lod = Math.round(P.mesh_lod), P.texture_lod = Math.round(P.texture_lod)), P.mesh_lod >= 0 && this.loadProgressiveMeshes(s, P.mesh_lod), s.material && P.texture_lod >= 0 && this.loadProgressiveTextures(s.material, P.texture_lod, o), f && s.material && !s.isGizmo && Be(s.material);
|
|
1175
1193
|
for (const l of z)
|
|
1176
1194
|
l.onAfterUpdatedLOD?.(this.renderer, t, e, s, P);
|
|
1177
|
-
|
|
1195
|
+
n.lastLodLevel_Mesh = P.mesh_lod, n.lastLodLevel_Texture = P.texture_lod;
|
|
1178
1196
|
}
|
|
1179
1197
|
/** Load progressive textures for the given material
|
|
1180
1198
|
* @param material the material to load the textures for
|
|
@@ -1184,17 +1202,17 @@ let oe = class O {
|
|
|
1184
1202
|
loadProgressiveTextures(t, e, s) {
|
|
1185
1203
|
if (!t) return;
|
|
1186
1204
|
if (Array.isArray(t)) {
|
|
1187
|
-
for (const
|
|
1188
|
-
this.loadProgressiveTextures(
|
|
1205
|
+
for (const n of t)
|
|
1206
|
+
this.loadProgressiveTextures(n, e);
|
|
1189
1207
|
return;
|
|
1190
1208
|
}
|
|
1191
1209
|
let r = !1;
|
|
1192
|
-
if ((t[
|
|
1193
|
-
t[
|
|
1194
|
-
const
|
|
1210
|
+
if ((t[W] === void 0 || e < t[W]) && (r = !0), s !== void 0 && s >= 0 && (r = t[W] != s, e = s), r) {
|
|
1211
|
+
t[W] = e;
|
|
1212
|
+
const n = m.assignTextureLOD(t, e).then((o) => {
|
|
1195
1213
|
this._lodchangedlisteners.forEach((l) => l({ type: "texture", level: e, object: t }));
|
|
1196
1214
|
});
|
|
1197
|
-
de.addPromise("texture", t,
|
|
1215
|
+
de.addPromise("texture", t, n, this._newPromiseGroups);
|
|
1198
1216
|
}
|
|
1199
1217
|
}
|
|
1200
1218
|
/** Load progressive meshes for the given mesh
|
|
@@ -1205,20 +1223,20 @@ let oe = class O {
|
|
|
1205
1223
|
*/
|
|
1206
1224
|
loadProgressiveMeshes(t, e) {
|
|
1207
1225
|
if (!t) return Promise.resolve(null);
|
|
1208
|
-
let s = t[
|
|
1226
|
+
let s = t[W] !== e;
|
|
1209
1227
|
const r = t["DEBUG:LOD"];
|
|
1210
|
-
if (r != null && (s = t[
|
|
1211
|
-
t[
|
|
1212
|
-
const
|
|
1213
|
-
return de.addPromise("mesh", t,
|
|
1228
|
+
if (r != null && (s = t[W] != r, e = r), s) {
|
|
1229
|
+
t[W] = e;
|
|
1230
|
+
const n = t.geometry, o = m.assignMeshLOD(t, e).then((l) => (l && t[W] == e && n != t.geometry && this._lodchangedlisteners.forEach((a) => a({ type: "mesh", level: e, object: t })), l));
|
|
1231
|
+
return de.addPromise("mesh", t, o, this._newPromiseGroups), o;
|
|
1214
1232
|
}
|
|
1215
1233
|
return Promise.resolve(null);
|
|
1216
1234
|
}
|
|
1217
1235
|
// private testIfLODLevelsAreAvailable() {
|
|
1218
|
-
_sphere = new
|
|
1236
|
+
_sphere = new Ae();
|
|
1219
1237
|
_tempBox = new pe();
|
|
1220
1238
|
_tempBox2 = new pe();
|
|
1221
|
-
tempMatrix = new
|
|
1239
|
+
tempMatrix = new be();
|
|
1222
1240
|
_tempWorldPosition = new A();
|
|
1223
1241
|
_tempBoxSize = new A();
|
|
1224
1242
|
_tempBox2Size = new A();
|
|
@@ -1228,31 +1246,31 @@ let oe = class O {
|
|
|
1228
1246
|
static corner3 = new A();
|
|
1229
1247
|
static _tempPtInside = new A();
|
|
1230
1248
|
static isInside(t, e) {
|
|
1231
|
-
const s = t.min, r = t.max,
|
|
1232
|
-
return this._tempPtInside.set(
|
|
1249
|
+
const s = t.min, r = t.max, n = (s.x + r.x) * 0.5, o = (s.y + r.y) * 0.5;
|
|
1250
|
+
return this._tempPtInside.set(n, o, s.z).applyMatrix4(e).z < 0;
|
|
1233
1251
|
}
|
|
1234
1252
|
static skinnedMeshBoundsFrameOffsetCounter = 0;
|
|
1235
1253
|
static $skinnedMeshBoundsOffset = /* @__PURE__ */ Symbol("gltf-progressive-skinnedMeshBoundsOffset");
|
|
1236
1254
|
// #region calculateLodLevel
|
|
1237
|
-
calculateLodLevel(t, e, s, r,
|
|
1255
|
+
calculateLodLevel(t, e, s, r, n) {
|
|
1238
1256
|
if (!e) {
|
|
1239
|
-
|
|
1257
|
+
n.mesh_lod = -1, n.texture_lod = -1;
|
|
1240
1258
|
return;
|
|
1241
1259
|
}
|
|
1242
1260
|
if (!t) {
|
|
1243
|
-
|
|
1261
|
+
n.mesh_lod = -1, n.texture_lod = -1;
|
|
1244
1262
|
return;
|
|
1245
1263
|
}
|
|
1246
1264
|
let l = 10 + 1, a = !1;
|
|
1247
|
-
if (
|
|
1265
|
+
if (k && e["DEBUG:LOD"] != null)
|
|
1248
1266
|
return e["DEBUG:LOD"];
|
|
1249
1267
|
const u = m.getMeshLODExtension(e.geometry)?.lods, c = m.getPrimitiveIndex(e.geometry), y = u && u.length > 0, w = m.getMaterialMinMaxLODsCount(e.material), L = w.min_count !== 1 / 0 && w.min_count >= 0 && w.max_count >= 0;
|
|
1250
1268
|
if (!y && !L) {
|
|
1251
|
-
|
|
1269
|
+
n.mesh_lod = 0, n.texture_lod = 0;
|
|
1252
1270
|
return;
|
|
1253
1271
|
}
|
|
1254
1272
|
y || (a = !0, l = 0);
|
|
1255
|
-
const
|
|
1273
|
+
const R = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
1256
1274
|
let v = e.geometry.boundingBox;
|
|
1257
1275
|
if (e.type === "SkinnedMesh") {
|
|
1258
1276
|
const d = e;
|
|
@@ -1277,12 +1295,12 @@ let oe = class O {
|
|
|
1277
1295
|
this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
|
|
1278
1296
|
const h = t.getWorldPosition(this._tempWorldPosition);
|
|
1279
1297
|
if (this._sphere.containsPoint(h)) {
|
|
1280
|
-
|
|
1298
|
+
n.mesh_lod = 0, n.texture_lod = 0;
|
|
1281
1299
|
return;
|
|
1282
1300
|
}
|
|
1283
1301
|
}
|
|
1284
1302
|
if (this._tempBox.copy(v), this._tempBox.applyMatrix4(e.matrixWorld), d.isPerspectiveCamera && O.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
1285
|
-
|
|
1303
|
+
n.mesh_lod = 0, n.texture_lod = 0;
|
|
1286
1304
|
return;
|
|
1287
1305
|
}
|
|
1288
1306
|
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && d.isPerspectiveCamera && d.fov > 70) {
|
|
@@ -1290,16 +1308,16 @@ let oe = class O {
|
|
|
1290
1308
|
let b = h.x, S = h.y, G = p.x, Y = p.y;
|
|
1291
1309
|
const te = 2, ae = 1.5, se = (h.x + p.x) * 0.5, re = (h.y + p.y) * 0.5;
|
|
1292
1310
|
b = (b - se) * te + se, S = (S - re) * te + re, G = (G - se) * te + se, Y = (Y - re) * te + re;
|
|
1293
|
-
const
|
|
1311
|
+
const Ue = b < 0 && G > 0 ? 0 : Math.min(Math.abs(h.x), Math.abs(p.x)), We = S < 0 && Y > 0 ? 0 : Math.min(Math.abs(h.y), Math.abs(p.y)), le = Math.max(Ue, We);
|
|
1294
1312
|
s.lastCentrality = (ae - le) * (ae - le) * (ae - le);
|
|
1295
1313
|
} else
|
|
1296
1314
|
s.lastCentrality = 1;
|
|
1297
1315
|
const g = this._tempBox.getSize(this._tempBoxSize);
|
|
1298
|
-
g.multiplyScalar(0.5), screen.availHeight > 0 &&
|
|
1316
|
+
g.multiplyScalar(0.5), screen.availHeight > 0 && R > 0 && g.multiplyScalar(R / screen.availHeight), t.isPerspectiveCamera ? g.x *= t.aspect : t.isOrthographicCamera;
|
|
1299
1317
|
const M = t.matrixWorldInverse, B = this._tempBox2;
|
|
1300
1318
|
B.copy(v), B.applyMatrix4(e.matrixWorld), B.applyMatrix4(M);
|
|
1301
1319
|
const D = B.getSize(this._tempBox2Size), N = Math.max(D.x, D.y);
|
|
1302
|
-
if (Math.max(g.x, g.y) != 0 && N != 0 && (g.z = D.z / Math.max(D.x, D.y) * Math.max(g.x, g.y)), s.lastScreenCoverage = Math.max(g.x, g.y, g.z), s.lastScreenspaceVolume.copy(g), s.lastScreenCoverage *= s.lastCentrality,
|
|
1320
|
+
if (Math.max(g.x, g.y) != 0 && N != 0 && (g.z = D.z / Math.max(D.x, D.y) * Math.max(g.x, g.y)), s.lastScreenCoverage = Math.max(g.x, g.y, g.z), s.lastScreenspaceVolume.copy(g), s.lastScreenCoverage *= s.lastCentrality, k && O.debugDrawLine) {
|
|
1303
1321
|
const h = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
1304
1322
|
h.invert();
|
|
1305
1323
|
const p = O.corner0, b = O.corner1, S = O.corner2, G = O.corner3;
|
|
@@ -1311,36 +1329,36 @@ let oe = class O {
|
|
|
1311
1329
|
if (u && s.lastScreenCoverage > 0)
|
|
1312
1330
|
for (let h = 0; h < u.length; h++) {
|
|
1313
1331
|
const p = u[h], S = (p.densities?.[c] || p.density || 1e-5) / s.lastScreenCoverage;
|
|
1314
|
-
if (c > 0 &&
|
|
1332
|
+
if (c > 0 && Se() && !p.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), S < r) {
|
|
1315
1333
|
_ = h;
|
|
1316
1334
|
break;
|
|
1317
1335
|
}
|
|
1318
1336
|
}
|
|
1319
1337
|
_ < l && (l = _, a = !0);
|
|
1320
1338
|
}
|
|
1321
|
-
if (a ?
|
|
1322
|
-
const g = u?.[
|
|
1323
|
-
g && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${
|
|
1339
|
+
if (a ? n.mesh_lod = l : n.mesh_lod = s.lastLodLevel_Mesh, k && n.mesh_lod != s.lastLodLevel_Mesh) {
|
|
1340
|
+
const g = u?.[n.mesh_lod];
|
|
1341
|
+
g && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${n.mesh_lod} (density: ${g.densities?.[c].toFixed(0)}) | ${e.name}`);
|
|
1324
1342
|
}
|
|
1325
1343
|
if (L) {
|
|
1326
1344
|
const d = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
1327
1345
|
if (s.lastLodLevel_Texture < 0) {
|
|
1328
|
-
if (
|
|
1346
|
+
if (n.texture_lod = w.max_count - 1, k) {
|
|
1329
1347
|
const g = w.lods[w.max_count - 1];
|
|
1330
|
-
|
|
1348
|
+
k && console.log(`First Texture LOD ${n.texture_lod} (${g.max_height}px) - ${e.name}`);
|
|
1331
1349
|
}
|
|
1332
1350
|
} else {
|
|
1333
1351
|
const g = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
1334
1352
|
let M = s.lastScreenCoverage * 4;
|
|
1335
1353
|
this.context?.engine === "model-viewer" && (M *= 1.5);
|
|
1336
|
-
const D =
|
|
1354
|
+
const D = R / window.devicePixelRatio * M;
|
|
1337
1355
|
let N = !1;
|
|
1338
1356
|
for (let T = w.lods.length - 1; T >= 0; T--) {
|
|
1339
1357
|
const _ = w.lods[T];
|
|
1340
|
-
if (!(d && _.max_height >= 2048) && !(
|
|
1341
|
-
if (N = !0,
|
|
1358
|
+
if (!(d && _.max_height >= 2048) && !(ve() && _.max_height > 4096) && (_.max_height > D || !N && T === 0)) {
|
|
1359
|
+
if (N = !0, n.texture_lod = T, k && n.texture_lod < s.lastLodLevel_Texture) {
|
|
1342
1360
|
const x = _.max_height;
|
|
1343
|
-
console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${
|
|
1361
|
+
console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${n.texture_lod} = ${x}px
|
|
1344
1362
|
Screensize: ${D.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${g.toFixed(1)}
|
|
1345
1363
|
${e.name}`);
|
|
1346
1364
|
}
|
|
@@ -1349,10 +1367,10 @@ ${e.name}`);
|
|
|
1349
1367
|
}
|
|
1350
1368
|
}
|
|
1351
1369
|
} else
|
|
1352
|
-
|
|
1370
|
+
n.texture_lod = 0;
|
|
1353
1371
|
}
|
|
1354
1372
|
};
|
|
1355
|
-
class
|
|
1373
|
+
class Pt {
|
|
1356
1374
|
frames = 0;
|
|
1357
1375
|
lastLodLevel_Mesh = -1;
|
|
1358
1376
|
lastLodLevel_Texture = -1;
|
|
@@ -1360,72 +1378,72 @@ class xt {
|
|
|
1360
1378
|
lastScreenspaceVolume = new A();
|
|
1361
1379
|
lastCentrality = 0;
|
|
1362
1380
|
}
|
|
1363
|
-
const
|
|
1381
|
+
const Te = /* @__PURE__ */ Symbol("NEEDLE_mesh_lod"), ne = /* @__PURE__ */ Symbol("NEEDLE_texture_lod");
|
|
1364
1382
|
let ge = null;
|
|
1365
|
-
function
|
|
1366
|
-
const
|
|
1367
|
-
|
|
1368
|
-
return
|
|
1369
|
-
}),
|
|
1383
|
+
function Ge() {
|
|
1384
|
+
const i = Ct();
|
|
1385
|
+
i && (i.mapURLs(function(t) {
|
|
1386
|
+
return Pe(), t;
|
|
1387
|
+
}), Pe(), ge?.disconnect(), ge = new MutationObserver((t) => {
|
|
1370
1388
|
t.forEach((e) => {
|
|
1371
1389
|
e.addedNodes.forEach((s) => {
|
|
1372
|
-
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" &&
|
|
1390
|
+
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Fe(s);
|
|
1373
1391
|
});
|
|
1374
1392
|
});
|
|
1375
1393
|
}), ge.observe(document, { childList: !0, subtree: !0 }));
|
|
1376
1394
|
}
|
|
1377
|
-
function
|
|
1395
|
+
function Ct() {
|
|
1378
1396
|
if (typeof customElements > "u") return null;
|
|
1379
|
-
const
|
|
1380
|
-
return
|
|
1381
|
-
console.debug("[gltf-progressive] model-viewer defined"),
|
|
1397
|
+
const i = customElements.get("model-viewer");
|
|
1398
|
+
return i || (customElements.whenDefined("model-viewer").then(() => {
|
|
1399
|
+
console.debug("[gltf-progressive] model-viewer defined"), Ge();
|
|
1382
1400
|
}), null);
|
|
1383
1401
|
}
|
|
1384
|
-
function
|
|
1402
|
+
function Pe() {
|
|
1385
1403
|
if (typeof document > "u") return;
|
|
1386
1404
|
document.querySelectorAll("model-viewer").forEach((t) => {
|
|
1387
|
-
|
|
1405
|
+
Fe(t);
|
|
1388
1406
|
});
|
|
1389
1407
|
}
|
|
1390
|
-
const
|
|
1391
|
-
let
|
|
1392
|
-
function
|
|
1393
|
-
if (!
|
|
1408
|
+
const Ce = /* @__PURE__ */ new WeakSet();
|
|
1409
|
+
let At = 0;
|
|
1410
|
+
function Fe(i) {
|
|
1411
|
+
if (!i || Ce.has(i))
|
|
1394
1412
|
return null;
|
|
1395
|
-
|
|
1396
|
-
`,
|
|
1413
|
+
Ce.add(i), console.debug("[gltf-progressive] found new model-viewer..." + ++At + `
|
|
1414
|
+
`, i.getAttribute("src"));
|
|
1397
1415
|
let t = null, e = null, s = null;
|
|
1398
|
-
for (let r =
|
|
1399
|
-
const
|
|
1400
|
-
!t &&
|
|
1416
|
+
for (let r = i; r != null; r = Object.getPrototypeOf(r)) {
|
|
1417
|
+
const n = Object.getOwnPropertySymbols(r), o = n.find((u) => u.toString() == "Symbol(renderer)"), l = n.find((u) => u.toString() == "Symbol(scene)"), a = n.find((u) => u.toString() == "Symbol(needsRender)");
|
|
1418
|
+
!t && o != null && (t = i[o].threeRenderer), !e && l != null && (e = i[l]), !s && a != null && (s = i[a]);
|
|
1401
1419
|
}
|
|
1402
1420
|
if (t && e) {
|
|
1403
1421
|
let r = function() {
|
|
1404
1422
|
if (s) {
|
|
1405
|
-
let
|
|
1406
|
-
if (
|
|
1423
|
+
let o = 0, l = setInterval(() => {
|
|
1424
|
+
if (o++ > 5) {
|
|
1407
1425
|
clearInterval(l);
|
|
1408
1426
|
return;
|
|
1409
1427
|
}
|
|
1410
|
-
s?.call(
|
|
1428
|
+
s?.call(i);
|
|
1411
1429
|
}, 300);
|
|
1412
1430
|
}
|
|
1413
1431
|
};
|
|
1414
1432
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
1415
|
-
const
|
|
1416
|
-
return
|
|
1417
|
-
s?.call(
|
|
1418
|
-
}),
|
|
1419
|
-
|
|
1420
|
-
}),
|
|
1433
|
+
const n = ie.get(t, { engine: "model-viewer" });
|
|
1434
|
+
return ie.addPlugin(new Rt()), n.enable(), n.addEventListener("changed", () => {
|
|
1435
|
+
s?.call(i);
|
|
1436
|
+
}), i.addEventListener("model-visibility", (o) => {
|
|
1437
|
+
o.detail.visible && s?.call(i);
|
|
1438
|
+
}), i.addEventListener("load", () => {
|
|
1421
1439
|
r();
|
|
1422
1440
|
}), () => {
|
|
1423
|
-
|
|
1441
|
+
n.disable();
|
|
1424
1442
|
};
|
|
1425
1443
|
}
|
|
1426
1444
|
return null;
|
|
1427
1445
|
}
|
|
1428
|
-
class
|
|
1446
|
+
class Rt {
|
|
1429
1447
|
_didWarnAboutMissingUrl = !1;
|
|
1430
1448
|
onBeforeUpdateLOD(t, e, s, r) {
|
|
1431
1449
|
this.tryParseMeshLOD(e, r), this.tryParseTextureLOD(e, r);
|
|
@@ -1443,95 +1461,95 @@ class _t {
|
|
|
1443
1461
|
return t.element;
|
|
1444
1462
|
}
|
|
1445
1463
|
tryParseTextureLOD(t, e) {
|
|
1446
|
-
if (e[
|
|
1447
|
-
e[
|
|
1448
|
-
const s = this.tryGetCurrentGLTF(t), r = this.tryGetCurrentModelViewer(t),
|
|
1449
|
-
if (
|
|
1450
|
-
let
|
|
1451
|
-
if (a[
|
|
1452
|
-
a[
|
|
1464
|
+
if (e[ne] == !0) return;
|
|
1465
|
+
e[ne] = !0;
|
|
1466
|
+
const s = this.tryGetCurrentGLTF(t), r = this.tryGetCurrentModelViewer(t), n = this.getUrl(r);
|
|
1467
|
+
if (n && s && e.material) {
|
|
1468
|
+
let o = function(a) {
|
|
1469
|
+
if (a[ne] == !0) return;
|
|
1470
|
+
a[ne] = !0, a.userData && (a.userData.LOD = -1);
|
|
1453
1471
|
const u = Object.keys(a);
|
|
1454
1472
|
for (let c = 0; c < u.length; c++) {
|
|
1455
1473
|
const y = u[c], w = a[y];
|
|
1456
1474
|
if (w?.isTexture === !0) {
|
|
1457
1475
|
const L = w.userData?.associations?.textures;
|
|
1458
1476
|
if (L == null) continue;
|
|
1459
|
-
const
|
|
1460
|
-
if (!
|
|
1477
|
+
const R = s.parser.json.textures[L];
|
|
1478
|
+
if (!R) {
|
|
1461
1479
|
console.warn("Texture data not found for texture index " + L);
|
|
1462
1480
|
continue;
|
|
1463
1481
|
}
|
|
1464
|
-
if (
|
|
1465
|
-
const v =
|
|
1466
|
-
v &&
|
|
1482
|
+
if (R?.extensions?.[U]) {
|
|
1483
|
+
const v = R.extensions[U];
|
|
1484
|
+
v && n && m.registerTexture(n, w, v.lods.length, L, v);
|
|
1467
1485
|
}
|
|
1468
1486
|
}
|
|
1469
1487
|
}
|
|
1470
1488
|
};
|
|
1471
1489
|
const l = e.material;
|
|
1472
|
-
if (Array.isArray(l)) for (const a of l)
|
|
1473
|
-
else
|
|
1490
|
+
if (Array.isArray(l)) for (const a of l) o(a);
|
|
1491
|
+
else o(l);
|
|
1474
1492
|
}
|
|
1475
1493
|
}
|
|
1476
1494
|
tryParseMeshLOD(t, e) {
|
|
1477
|
-
if (e[
|
|
1478
|
-
e[
|
|
1495
|
+
if (e[Te] == !0) return;
|
|
1496
|
+
e[Te] = !0;
|
|
1479
1497
|
const s = this.tryGetCurrentModelViewer(t), r = this.getUrl(s);
|
|
1480
1498
|
if (!r)
|
|
1481
1499
|
return;
|
|
1482
|
-
const
|
|
1483
|
-
if (
|
|
1484
|
-
const
|
|
1485
|
-
m.registerMesh(r,
|
|
1500
|
+
const n = e.userData?.gltfExtensions?.[U];
|
|
1501
|
+
if (n && r) {
|
|
1502
|
+
const o = e.uuid;
|
|
1503
|
+
m.registerMesh(r, o, e, 0, n.lods.length, n);
|
|
1486
1504
|
}
|
|
1487
1505
|
}
|
|
1488
1506
|
}
|
|
1489
|
-
function
|
|
1507
|
+
function kt(...i) {
|
|
1490
1508
|
let t, e, s, r;
|
|
1491
|
-
switch (
|
|
1509
|
+
switch (i.length) {
|
|
1492
1510
|
case 2:
|
|
1493
|
-
[s, e] =
|
|
1511
|
+
[s, e] = i, r = {};
|
|
1494
1512
|
break;
|
|
1495
1513
|
case 3:
|
|
1496
|
-
[s, e, r] =
|
|
1514
|
+
[s, e, r] = i;
|
|
1497
1515
|
break;
|
|
1498
1516
|
case 4:
|
|
1499
|
-
[t, e, s, r] =
|
|
1517
|
+
[t, e, s, r] = i;
|
|
1500
1518
|
break;
|
|
1501
1519
|
default:
|
|
1502
1520
|
throw new Error("Invalid arguments");
|
|
1503
1521
|
}
|
|
1504
|
-
|
|
1522
|
+
Me(e), ke(s), $e(s, {
|
|
1505
1523
|
progressive: !0,
|
|
1506
1524
|
...r?.hints
|
|
1507
|
-
}), s.register((
|
|
1508
|
-
const
|
|
1509
|
-
return r?.enableLODsManager !== !1 &&
|
|
1525
|
+
}), s.register((o) => new m(o));
|
|
1526
|
+
const n = ie.get(e);
|
|
1527
|
+
return r?.enableLODsManager !== !1 && n.enable(), n;
|
|
1510
1528
|
}
|
|
1511
|
-
|
|
1512
|
-
if (!
|
|
1513
|
-
const
|
|
1529
|
+
Ge();
|
|
1530
|
+
if (!xt) {
|
|
1531
|
+
const i = {
|
|
1514
1532
|
gltfProgressive: {
|
|
1515
|
-
useNeedleProgressive:
|
|
1516
|
-
LODsManager:
|
|
1517
|
-
configureLoader:
|
|
1533
|
+
useNeedleProgressive: kt,
|
|
1534
|
+
LODsManager: ie,
|
|
1535
|
+
configureLoader: $e,
|
|
1518
1536
|
getRaycastMesh: ee,
|
|
1519
|
-
useRaycastMeshes:
|
|
1537
|
+
useRaycastMeshes: Lt
|
|
1520
1538
|
}
|
|
1521
1539
|
};
|
|
1522
1540
|
if (!globalThis.Needle)
|
|
1523
|
-
globalThis.Needle =
|
|
1541
|
+
globalThis.Needle = i;
|
|
1524
1542
|
else
|
|
1525
|
-
for (const t in
|
|
1526
|
-
globalThis.Needle[t] =
|
|
1543
|
+
for (const t in i)
|
|
1544
|
+
globalThis.Needle[t] = i[t];
|
|
1527
1545
|
}
|
|
1528
1546
|
export {
|
|
1529
|
-
|
|
1547
|
+
ie as LODsManager,
|
|
1530
1548
|
m as NEEDLE_progressive,
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1549
|
+
ke as addDracoAndKTX2Loaders,
|
|
1550
|
+
$e as configureLoader,
|
|
1551
|
+
Me as createLoaders,
|
|
1534
1552
|
ee as getRaycastMesh,
|
|
1535
|
-
|
|
1536
|
-
|
|
1553
|
+
ut as setDracoDecoderLocation,
|
|
1554
|
+
ct as setKTX2TranscoderLocation
|
|
1537
1555
|
};
|