UNPKG

@tresjs/cientos

Version:

Collection of useful helpers and fully functional, ready-made abstractions for Tres

1,444 lines (1,437 loc) 738 kB
/** * name: @tresjs/cientos * version: v4.3.1 * (c) 2025 * description: Collection of useful helpers and fully functional, ready-made abstractions for Tres * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/) */ var Ml = Object.defineProperty; var Sl = (r, e, t) => e in r ? Ml(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; var pe = (r, e, t) => Sl(r, typeof e != "symbol" ? e + "" : e, t); import * as Jn from "three"; import { TextureLoader as ai, DoubleSide as on, WebGLCubeRenderTarget as aa, HalfFloatType as Lt, CubeCamera as la, Group as Zt, Quaternion as je, Euler as vt, AudioListener as ca, Audio as Al, AudioLoader as ua, MathUtils as Ye, ShaderMaterial as bt, UniformsUtils as Dn, Vector2 as ve, Color as be, FrontSide as ss, REVISION as Ts, Vector3 as $, BufferAttribute as ut, TrianglesDrawMode as Pl, TriangleFanDrawMode as oo, TriangleStripDrawMode as ha, CompressedTexture as mi, Texture as es, RGBAFormat as ei, PropertyBinding as rn, InterpolateDiscrete as fa, Matrix4 as Ie, Scene as xs, PlaneGeometry as jt, Uniform as Se, Mesh as de, PerspectiveCamera as kt, WebGLRenderer as Rl, NearestFilter as Kn, NearestMipmapNearestFilter as da, NearestMipmapLinearFilter as pa, LinearFilter as wt, LinearMipmapNearestFilter as ma, LinearMipmapLinearFilter as Eo, ClampToEdgeWrapping as Wt, RepeatWrapping as Ln, MirroredRepeatWrapping as ga, InterpolateLinear as Mo, Plane as bs, Vector4 as at, WebGLRenderTarget as Xt, NoToneMapping as Cl, MeshBasicMaterial as $t, DataTexture as ti, RawShaderMaterial as gi, AdditiveBlending as So, Box2 as va, BufferGeometry as ht, InterleavedBuffer as Ao, InterleavedBufferAttribute as nn, UniformsLib as ni, BoxGeometry as Ht, BackSide as li, Triangle as Il, Object3D as Rt, Raycaster as ya, LineBasicMaterial as ws, CylinderGeometry as Ct, Float32BufferAttribute as gt, Line as ke, OctahedronGeometry as Mn, SphereGeometry as Ol, TorusGeometry as Ds, EventDispatcher as _a, MOUSE as Dt, TOUCH as Vt, Spherical as si, OrthographicCamera as _n, Ray as Dl, Loader as Un, LoaderUtils as qn, FileLoader as kn, MeshPhysicalMaterial as Kt, SpotLight as xa, PointLight as ro, DirectionalLight as wa, InstancedMesh as Ta, InstancedBufferAttribute as Ll, ImageBitmapLoader as kl, PointsMaterial as Nl, Material as vi, MeshStandardMaterial as Es, SkinnedMesh as Po, LineSegments as Bl, LineLoop as Ul, Points as ba, Skeleton as Ea, AnimationClip as Ma, Bone as ao, VectorKeyframeTrack as lo, NumberKeyframeTrack as co, QuaternionKeyframeTrack as uo, Interpolant as Fl, Box3 as _t, Sphere as Ms, ExtrudeGeometry as zl, Curve as Gl, MeshPhongMaterial as yi, MeshLambertMaterial as Hl, EquirectangularReflectionMapping as ho, AmbientLight as jl, Uint16BufferAttribute as Vl, Matrix3 as Cn, ShapePath as pn, DataTextureLoader as Yl, FloatType as qs, DataUtils as Ls, ShapeUtils as Wl, Shape as Xl, Path as _i, InstancedBufferGeometry as $l, InstancedInterleavedBuffer as fo, WireframeGeometry as Zl, Line3 as Kl, AlwaysStencilFunc as ql, ReplaceStencilOp as xi, AnimationMixer as Ql, KeepStencilOp as wi, NotEqualStencilFunc as $o, EqualStencilFunc as Zo, DepthTexture as Sa, EdgesGeometry as Jl, CubeTextureLoader as ec, CubeReflectionMapping as tc, ShapeGeometry as nc, DefaultLoadingManager as ks, VideoTexture as sc, Clock as ic, NoBlending as oc, Camera as rc, TangentSpaceNormalMap as ac, CatmullRomCurve3 as lc, QuadraticBezierCurve3 as cc, MeshDepthMaterial as Ko, ShaderChunk as Ti, UnsignedByteType as uc, UVMapping as hc, IcosahedronGeometry as fc } from "three"; import { defineComponent as ue, watch as J, ref as me, shallowRef as re, withAsyncContext as Tn, onUnmounted as tt, createElementBlock as ce, openBlock as ae, renderSlot as Ne, createElementVNode as ye, unref as F, getCurrentScope as dc, onScopeDispose as pc, onMounted as bn, nextTick as Ro, getCurrentInstance as Aa, isRef as ii, computed as Pe, reactive as ts, watchEffect as et, toValue as ze, isReactive as po, createVNode as ms, mergeProps as $e, toRefs as Le, shallowReactive as Pa, onBeforeUnmount as Co, useSlots as Io, createCommentVNode as an, createBlock as Oo, Fragment as Ra, renderList as Ca, useAttrs as mc, render as gc, triggerRef as vc, toRaw as qo } from "vue"; import { useLogger as xt, useLoader as Nn, useTresContext as xe, useLoop as Ve, normalizeVectorFlexibleParam as Ia, useTres as xn, extend as Oa, useTexture as Bn, normalizeColor as tn } from "@tresjs/core"; function yc(r) { const e = _c(r), t = []; for (const { startFrame: n, endFrame: s, duration: i } of e) if (!(i <= 0)) if (s < 0 || n === s) { for (let o = 0; o < i; o++) t.push(n); continue; } else { const o = Math.sign(s - n); for (let a = n; a !== s + o; a += o) for (let l = 0; l < i; l++) t.push(a); } return t; } function _c(r) { let e = "START_FRAME_IN"; const t = []; for (const { name: n, value: s, startI: i } of xc(r)) e === "START_FRAME_IN" ? n === "NUMBER" ? (t.push({ startFrame: s, endFrame: s, duration: 1 }), e = "START_FRAME_OUT") : Sn( "number", n, r, i ) : e === "START_FRAME_OUT" ? n === "COMMA" ? e = "START_FRAME_IN" : n === "HYPHEN" ? e = "END_FRAME_IN" : n === "OPEN_PAREN" ? e = "DURATION_IN" : Sn( '",", "-", "("', n, r, i ) : e === "END_FRAME_IN" ? n === "NUMBER" ? (t[t.length - 1].endFrame = s, e = "END_FRAME_OUT") : Sn( "number", n, r, i ) : e === "END_FRAME_OUT" ? n === "COMMA" ? e = "START_FRAME_IN" : n === "OPEN_PAREN" ? e = "DURATION_IN" : Sn( "',' or '('", n, r, i ) : e === "DURATION_IN" ? n === "NUMBER" ? (t[t.length - 1].duration = s, e = "DURATION_OUT") : Sn( "number", n, r, i ) : e === "DURATION_OUT" ? n === "CLOSE_PAREN" ? e = "NEXT_OR_DONE" : Sn('"("', n, r, i) : e === "NEXT_OR_DONE" && (n === "COMMA" ? e = "START_FRAME_IN" : Sn('","', n, r, i)); return t; } function xc(r) { const e = []; for (let t = 0; t < r.length; t++) { const n = r[t]; if ("0123456789".includes(n)) e.length && e[e.length - 1].name === "NUMBER" ? (e[e.length - 1].value *= 10, e[e.length - 1].value += Number.parseInt(n)) : e.push({ name: "NUMBER", value: Number.parseInt(n), startI: t }); else { if (n === " ") continue; n === "," ? e.push({ name: "COMMA", value: -1, startI: t }) : n === "(" ? e.push({ name: "OPEN_PAREN", value: -1, startI: t }) : n === ")" ? e.push({ name: "CLOSE_PAREN", value: -1, startI: t }) : n === "-" ? e.push({ name: "HYPHEN", value: -1, startI: t }) : wc("0123456789,-()", n, r, t); } } return e; } function wc(r, e, t, n) { xt().logError( `Cientos AnimationDefinitionParser: Unexpected character while processing animation definition: expected ${r}, got ${e}. ${t} ${Array.from({ length: n + 1 }).join(" ")}^` ); } function Sn(r, e, t, n) { xt().logError( `Cientos AnimationDefinitionParser: Syntax error while processing animation definition: expected ${r}, got ${e}. ${t} ${Array.from({ length: n + 1 }).join(" ")}^` ); } const Tc = /\d*$/, bc = /_*\d*$/; function Ec(r) { return r.replace(bc, ""); } function Mc(r) { const e = r.match(Tc); return e ? Number.parseInt(e[e.length - 1]) : null; } async function Sc(r, e) { const t = Nn( ai, r ), n = typeof e != "string" ? new Promise((s) => s(e)) : fetch(e).then((s) => s.json()).catch((s) => xt().logError(`Cientos Atlas - ${s}`)); return Promise.all([t, n]).then( ([s, i]) => { const o = Ac( i, s.image.width, s.image.height ); return [s, o]; } ); } function Ac(r, e, t) { const n = typeof r == "number" || Array.isArray(r) ? Ic(r, e, t) : Pc( r, e, t ); return { frames: n, animations: Da(n) }; } function gs(r, e, t) { let n; return typeof e == "string" ? n = Dc(r, e) : typeof e == "number" ? n = Qo( r, e, e ) : n = Qo( r, e[0], e[1] ), t ? n.toReversed() : n; } function Do() { return { name: "null", width: 0, height: 0, offsetX: 0, offsetY: 0, repeatX: 0, repeatY: 0 }; } function Pc(r, e, t) { return Array.isArray(r.frames) ? Rc( r, e, t ) : Cc( r, e, t ); } function Rc(r, e, t) { const n = 1 / e, s = 1 / t; return r.frames.map((i) => ({ name: i.filename, offsetX: i.frame.x * n, offsetY: 1 - (i.frame.y + i.frame.h) * s, repeatX: i.frame.w * n, repeatY: i.frame.h * s, width: i.frame.w, height: i.frame.h })); } function Cc(r, e, t) { const n = 1 / e, s = 1 / t; return Object.entries(r.frames).map(([i, o]) => ({ name: i, offsetX: o.frame.x * n, offsetY: 1 - (o.frame.y + o.frame.h) * s, repeatX: o.frame.w * n, repeatY: o.frame.h * s, width: o.frame.w, height: o.frame.h })); } function Ic(r, e, t, n = "default") { const [s, i] = Array.isArray(r) ? r : [r, 1], o = e / s, a = t / i, l = (s * i).toString().length, c = 1 / s, f = 1 / i, u = []; let d = 0; for (let h = i - 1; h >= 0; h--) for (let m = 0; m < s; m++) d++, u.push({ name: n + String(d).padStart(l, "0"), offsetX: m * c, offsetY: h * f, repeatX: c, repeatY: f, width: o, height: a }); return u; } function Oc(r, e = {}) { const t = Da(r.frames); for (const [n, s] of Object.entries(e)) { const i = gs(r, n, !1), o = yc(s); for (const a of o) (a < 0 || i.length <= a) && xt().logError( `Cientos Atlas: Attempting to access frame index ${a} in animation ${n}, but it does not exist.` ); t[n] = o.map((a) => i[a]); } r.animations = t; } function Dc(r, e) { if (!(e in r.animations)) { const t = Object.keys(r.animations).map((n) => `* ${n} `).join(""); return xt().logError( `Cientos Atlas: getAtlasFramesByAnimationName The animation name "${e}" does not exist in this atlas. Available names: ${t}` ), [Do()]; } return r.animations[e]; } function Qo(r, e, t) { if (e < 0 || r.frames.length <= e || t < 0 || r.frames.length <= t) return xt().logError( `Cientos Atlas: getFramesByIndex – [${e}, ${t}] is out of bounds.` ), [Do()]; const n = [], s = Math.sign(t - e); if (s === 0) return [r.frames[e]]; for (let i = e; i !== t + s; i += s) n.push(r.frames[i]); return n; } function Da(r) { const e = {}; for (const t of r) if (Mc(t.name) !== null) { const n = Ec(t.name); Object.prototype.hasOwnProperty.call(e, n) ? e[n].push(t) : e[n] = [t]; } for (const t of Object.values(e)) t.sort((n, s) => n.name.localeCompare(s.name)); return e; } const Lc = ["scale", "position"], kc = ["map", "alphaTest"], Nc = ["scale", "position"], Bc = ["side", "map", "alphaTest", "depthWrite", "depthTest"], Ns = 0.01, Ag = /* @__PURE__ */ ue({ __name: "component", props: { image: {}, atlas: {}, definitions: {}, fps: { default: 30 }, loop: { type: Boolean, default: !0 }, animation: { default: 0 }, paused: { type: Boolean, default: !1 }, reversed: { type: Boolean, default: !1 }, flipX: { type: Boolean, default: !1 }, resetOnEnd: { type: Boolean, default: !1 }, asSprite: { type: Boolean, default: !0 }, center: { default: () => [0.5, 0.5] }, alphaTest: { default: 0 }, depthTest: { type: Boolean, default: !0 }, depthWrite: { type: Boolean, default: !0 } }, emits: ["frame", "end", "loop"], async setup(r, { expose: e, emit: t }) { let n, s; const i = r, o = t, { invalidate: a } = xe(); J(i, () => { a(); }); const l = me(0), c = me(0), f = me(0), u = me(0), d = re(); e({ instance: d }); const [h, m] = ([n, s] = Tn(() => Sc(i.image, i.atlas)), n = await n, s(), n); h.matrixAutoUpdate = !1; let g = gs(m, i.animation, i.reversed), v = 0.5, p = 0.5, b = 1, _ = Do(), M = null, R = 0, w = !1, E = !0; Ve().onBeforeRender(({ delta: T }) => { for (!i.paused && !w && (b -= T * i.fps); b <= 0; ) b++, R++, i.loop ? (R >= g.length && o("loop", g[g.length - 1].name), R %= g.length) : R >= g.length && (w = !0, R = i.resetOnEnd ? 0 : g.length - 1, o("end", g[g.length - 1].name)); g[R] !== _ && (_ = g[R], M = _.name, x()), E && (E = !1, h.offset.x = _.offsetX + (i.flipX ? _.repeatX : 0), h.offset.y = _.offsetY, h.repeat.x = _.repeatX * (i.flipX ? -1 : 1), h.repeat.y = _.repeatY, h.updateMatrix(), f.value = _.width * Ns, u.value = _.height * Ns, l.value = (0.5 - v) * _.width * Ns, c.value = (0.5 - p) * _.height * Ns), M && (o("frame", M), M = null); }); function x() { E = !0; } return J(() => i.animation, (T, y) => { JSON.stringify(T) !== JSON.stringify(y) && (g = gs(m, i.animation, i.reversed), R = 0, b = 1, w = !1, x()); }, { immediate: !0 }), J(() => i.reversed, () => { R = (g.length - R - 1) % g.length, g = gs(m, i.animation, i.reversed), w && (R = i.resetOnEnd ? 0 : g.length - 1), x(); }), J(() => i.paused, () => { w = !1; }), J(() => i.loop, () => { w && i.loop && (w = !1); }), J(() => i.resetOnEnd, () => { w && (R = i.resetOnEnd ? 0 : g.length - 1, x()); }), J(() => i.flipX, x), J(() => [i.center], () => { [v, p] = Ia(i.center), x(); }, { immediate: !0 }), J(() => [i.definitions], () => { Oc(m, i.definitions), g = gs(m, i.animation, i.reversed), b = 1, R = 0, x(); }, { immediate: !0 }), tt(() => { h.dispose(); }), (T, y) => (ae(), ce("TresGroup", { ref_key: "groupRef", ref: d }, [ i.asSprite ? (ae(), ce("TresSprite", { key: 0, scale: [f.value, u.value, 1], position: [l.value, c.value, 0] }, [ ye("TresSpriteMaterial", { toneMapped: !1, map: F(h), transparent: !0, alphaTest: i.alphaTest }, null, 8, kc) ], 8, Lc)) : (ae(), ce("TresMesh", { key: 1, scale: [f.value, u.value, 1], position: [l.value, c.value, 0] }, [ y[0] || (y[0] = ye("TresPlaneGeometry", { args: [1, 1] }, null, -1)), ye("TresMeshBasicMaterial", { toneMapped: !1, side: F(on), map: F(h), transparent: !0, alphaTest: i.alphaTest, depthWrite: i.depthWrite, depthTest: i.depthTest }, null, 8, Bc) ], 8, Nc)), Ne(T.$slots, "default") ], 512)); } }); function ci(r) { return dc() ? (pc(r), !0) : !1; } function ct(r) { return typeof r == "function" ? r() : F(r); } const Uc = typeof window < "u" && typeof document < "u"; typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope; const Fc = Object.prototype.toString, zc = (r) => Fc.call(r) === "[object Object]", wn = () => { }; function Lo(r, e) { function t(...n) { return new Promise((s, i) => { Promise.resolve(r(() => e.apply(this, n), { fn: e, thisArg: this, args: n })).then(s).catch(i); }); } return t; } const Gc = (r) => r(); function Hc(r, e = {}) { let t, n, s = wn; const i = (a) => { clearTimeout(a), s(), s = wn; }; return (a) => { const l = ct(r), c = ct(e.maxWait); return t && i(t), l <= 0 || c !== void 0 && c <= 0 ? (n && (i(n), n = null), Promise.resolve(a())) : new Promise((f, u) => { s = e.rejectOnCancel ? u : f, c && !n && (n = setTimeout(() => { t && i(t), n = null, f(a()); }, c)), t = setTimeout(() => { n && i(n), n = null, f(a()); }, l); }); }; } function La(...r) { let e = 0, t, n = !0, s = wn, i, o, a, l, c; !ii(r[0]) && typeof r[0] == "object" ? { delay: o, trailing: a = !0, leading: l = !0, rejectOnCancel: c = !1 } = r[0] : [o, a = !0, l = !0, c = !1] = r; const f = () => { t && (clearTimeout(t), t = void 0, s(), s = wn); }; return (d) => { const h = ct(o), m = Date.now() - e, g = () => i = d(); return f(), h <= 0 ? (e = Date.now(), g()) : (m > h && (l || !n) ? (e = Date.now(), g()) : a && (i = new Promise((v, p) => { s = c ? p : v, t = setTimeout(() => { e = Date.now(), n = !0, v(g()), f(); }, Math.max(0, h - m)); })), !l && !t && (t = setTimeout(() => n = !0, h)), n = !1, i); }; } function jc(r) { return Aa(); } function Vc(r, e = 200, t = {}) { return Lo( Hc(e, t), r ); } function Yc(r, e = 200, t = !1, n = !0, s = !1) { return Lo( La(e, t, n, s), r ); } function Wc(r, e, t = {}) { const { eventFilter: n = Gc, ...s } = t; return J( r, Lo( n, e ), s ); } function ko(r, e = !0, t) { jc() ? bn(r, t) : e ? r() : Ro(r); } function Xc(r, e, t = {}) { const { throttle: n = 0, trailing: s = !0, leading: i = !0, ...o } = t; return Wc( r, e, { ...o, eventFilter: La(n, s, i) } ); } const ln = Uc ? window : void 0; function gn(r) { var e; const t = ct(r); return (e = t == null ? void 0 : t.$el) != null ? e : t; } function Xe(...r) { let e, t, n, s; if (typeof r[0] == "string" || Array.isArray(r[0]) ? ([t, n, s] = r, e = ln) : [e, t, n, s] = r, !e) return wn; Array.isArray(t) || (t = [t]), Array.isArray(n) || (n = [n]); const i = [], o = () => { i.forEach((f) => f()), i.length = 0; }, a = (f, u, d, h) => (f.addEventListener(u, d, h), () => f.removeEventListener(u, d, h)), l = J( () => [gn(e), ct(s)], ([f, u]) => { if (o(), !f) return; const d = zc(u) ? { ...u } : u; i.push( ...t.flatMap((h) => n.map((m) => a(f, h, m, d))) ); }, { immediate: !0, flush: "post" } ), c = () => { l(), o(); }; return ci(c), c; } function $c() { const r = me(!1), e = Aa(); return e && bn(() => { r.value = !0; }, e), r; } function ka(r) { const e = $c(); return Pe(() => (e.value, !!r())); } function Zc(r, e = {}) { const { window: t = ln } = e, n = ka(() => t && "matchMedia" in t && typeof t.matchMedia == "function"); let s; const i = me(!1), o = (c) => { i.value = c.matches; }, a = () => { s && ("removeEventListener" in s ? s.removeEventListener("change", o) : s.removeListener(o)); }, l = et(() => { n.value && (a(), s = t.matchMedia(ct(r)), "addEventListener" in s ? s.addEventListener("change", o) : s.addListener(o), i.value = s.matches); }); return ci(() => { l(), a(), s = void 0; }), i; } function Kc(r, e, t = {}) { const { window: n = ln, ...s } = t; let i; const o = ka(() => n && "ResizeObserver" in n), a = () => { i && (i.disconnect(), i = void 0); }, l = Pe(() => { const u = ct(r); return Array.isArray(u) ? u.map((d) => gn(d)) : [gn(u)]; }), c = J( l, (u) => { if (a(), o.value && n) { i = new ResizeObserver(e); for (const d of u) d && i.observe(d, s); } }, { immediate: !0, flush: "post" } ), f = () => { a(), c(); }; return ci(f), { isSupported: o, stop: f }; } function qc(r, e = { width: 0, height: 0 }, t = {}) { const { window: n = ln, box: s = "content-box" } = t, i = Pe(() => { var u, d; return (d = (u = gn(r)) == null ? void 0 : u.namespaceURI) == null ? void 0 : d.includes("svg"); }), o = me(e.width), a = me(e.height), { stop: l } = Kc( r, ([u]) => { const d = s === "border-box" ? u.borderBoxSize : s === "content-box" ? u.contentBoxSize : u.devicePixelContentBoxSize; if (n && i.value) { const h = gn(r); if (h) { const m = h.getBoundingClientRect(); o.value = m.width, a.value = m.height; } } else if (d) { const h = Array.isArray(d) ? d : [d]; o.value = h.reduce((m, { inlineSize: g }) => m + g, 0), a.value = h.reduce((m, { blockSize: g }) => m + g, 0); } else o.value = u.contentRect.width, a.value = u.contentRect.height; }, t ); ko(() => { const u = gn(r); u && (o.value = "offsetWidth" in u ? u.offsetWidth : e.width, a.value = "offsetHeight" in u ? u.offsetHeight : e.height); }); const c = J( () => gn(r), (u) => { o.value = u ? e.width : 0, a.value = u ? e.height : 0; } ); function f() { l(), c(); } return { width: o, height: a, stop: f }; } const Jo = 1; function Qc(r, e = {}) { const { throttle: t = 0, idle: n = 200, onStop: s = wn, onScroll: i = wn, offset: o = { left: 0, right: 0, top: 0, bottom: 0 }, eventListenerOptions: a = { capture: !1, passive: !0 }, behavior: l = "auto", window: c = ln, onError: f = (E) => { console.error(E); } } = e, u = me(0), d = me(0), h = Pe({ get() { return u.value; }, set(E) { g(E, void 0); } }), m = Pe({ get() { return d.value; }, set(E) { g(void 0, E); } }); function g(E, x) { var T, y, A, C; if (!c) return; const N = ct(r); if (!N) return; (A = N instanceof Document ? c.document.body : N) == null || A.scrollTo({ top: (T = ct(x)) != null ? T : m.value, left: (y = ct(E)) != null ? y : h.value, behavior: ct(l) }); const U = ((C = N == null ? void 0 : N.document) == null ? void 0 : C.documentElement) || (N == null ? void 0 : N.documentElement) || N; h != null && (u.value = U.scrollLeft), m != null && (d.value = U.scrollTop); } const v = me(!1), p = ts({ left: !0, right: !1, top: !0, bottom: !1 }), b = ts({ left: !1, right: !1, top: !1, bottom: !1 }), _ = (E) => { v.value && (v.value = !1, b.left = !1, b.right = !1, b.top = !1, b.bottom = !1, s(E)); }, M = Vc(_, t + n), R = (E) => { var x; if (!c) return; const T = ((x = E == null ? void 0 : E.document) == null ? void 0 : x.documentElement) || (E == null ? void 0 : E.documentElement) || gn(E), { display: y, flexDirection: A } = getComputedStyle(T), C = T.scrollLeft; b.left = C < u.value, b.right = C > u.value; const N = Math.abs(C) <= (o.left || 0), U = Math.abs(C) + T.clientWidth >= T.scrollWidth - (o.right || 0) - Jo; y === "flex" && A === "row-reverse" ? (p.left = U, p.right = N) : (p.left = N, p.right = U), u.value = C; let Y = T.scrollTop; E === c.document && !Y && (Y = c.document.body.scrollTop), b.top = Y < d.value, b.bottom = Y > d.value; const V = Math.abs(Y) <= (o.top || 0), ne = Math.abs(Y) + T.clientHeight >= T.scrollHeight - (o.bottom || 0) - Jo; y === "flex" && A === "column-reverse" ? (p.top = ne, p.bottom = V) : (p.top = V, p.bottom = ne), d.value = Y; }, w = (E) => { var x; if (!c) return; const T = (x = E.target.documentElement) != null ? x : E.target; R(T), v.value = !0, M(E), i(E); }; return Xe( r, "scroll", t ? Yc(w, t, !0, !1) : w, a ), ko(() => { try { const E = ct(r); if (!E) return; R(E); } catch (E) { f(E); } }), Xe( r, "scrollend", _, a ), { x: h, y: m, isScrolling: v, arrivedState: p, directions: b, measure() { const E = ct(r); c && E && R(E); } }; } const Jc = { ctrl: "control", command: "meta", cmd: "meta", option: "alt", up: "arrowup", down: "arrowdown", left: "arrowleft", right: "arrowright" }; function eu(r = {}) { const { reactive: e = !1, target: t = ln, aliasMap: n = Jc, passive: s = !0, onEventFired: i = wn } = r, o = ts(/* @__PURE__ */ new Set()), a = { toJSON() { return {}; }, current: o }, l = e ? ts(a) : a, c = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set(); function u(g, v) { g in l && (e ? l[g] = v : l[g].value = v); } function d() { o.clear(); for (const g of f) u(g, !1); } function h(g, v) { var p, b; const _ = (p = g.key) == null ? void 0 : p.toLowerCase(), R = [(b = g.code) == null ? void 0 : b.toLowerCase(), _].filter(Boolean); _ && (v ? o.add(_) : o.delete(_)); for (const w of R) f.add(w), u(w, v); _ === "meta" && !v ? (c.forEach((w) => { o.delete(w), u(w, !1); }), c.clear()) : typeof g.getModifierState == "function" && g.getModifierState("Meta") && v && [...o, ...R].forEach((w) => c.add(w)); } Xe(t, "keydown", (g) => (h(g, !0), i(g)), { passive: s }), Xe(t, "keyup", (g) => (h(g, !1), i(g)), { passive: s }), Xe("blur", d, { passive: !0 }), Xe("focus", d, { passive: !0 }); const m = new Proxy( l, { get(g, v, p) { if (typeof v != "string") return Reflect.get(g, v, p); if (v = v.toLowerCase(), v in n && (v = n[v]), !(v in l)) if (/[+_-]/.test(v)) { const _ = v.split(/[+_-]/g).map((M) => M.trim()); l[v] = Pe(() => _.every((M) => ct(m[M]))); } else l[v] = me(!1); const b = Reflect.get(g, v, p); return e ? ct(b) : b; } } ); return m; } const tu = { page: (r) => [r.pageX, r.pageY], client: (r) => [r.clientX, r.clientY], screen: (r) => [r.screenX, r.screenY], movement: (r) => r instanceof Touch ? null : [r.movementX, r.movementY] }; function nu(r = {}) { const { type: e = "page", touch: t = !0, resetOnTouchEnds: n = !1, initialValue: s = { x: 0, y: 0 }, window: i = ln, target: o = i, scroll: a = !0, eventFilter: l } = r; let c = null, f = 0, u = 0; const d = me(s.x), h = me(s.y), m = me(null), g = typeof e == "function" ? e : tu[e], v = (E) => { const x = g(E); c = E, x && ([d.value, h.value] = x, m.value = "mouse"), i && (f = i.scrollX, u = i.scrollY); }, p = (E) => { if (E.touches.length > 0) { const x = g(E.touches[0]); x && ([d.value, h.value] = x, m.value = "touch"); } }, b = () => { if (!c || !i) return; const E = g(c); c instanceof MouseEvent && E && (d.value = E[0] + i.scrollX - f, h.value = E[1] + i.scrollY - u); }, _ = () => { d.value = s.x, h.value = s.y; }, M = l ? (E) => l(() => v(E), {}) : (E) => v(E), R = l ? (E) => l(() => p(E), {}) : (E) => p(E), w = l ? () => l(() => b(), {}) : () => b(); if (o) { const E = { passive: !0 }; Xe(o, ["mousemove", "dragover"], M, E), t && e !== "movement" && (Xe(o, ["touchstart", "touchmove"], R, E), n && Xe(o, "touchend", _, E)), a && e === "page" && Xe(i, "scroll", w, { passive: !0 }); } return { x: d, y: h, sourceType: m }; } function su(r = {}) { const { window: e = ln, behavior: t = "auto" } = r; if (!e) return { x: me(0), y: me(0) }; const n = me(e.scrollX), s = me(e.scrollY), i = Pe({ get() { return n.value; }, set(a) { scrollTo({ left: a, behavior: t }); } }), o = Pe({ get() { return s.value; }, set(a) { scrollTo({ top: a, behavior: t }); } }); return Xe( e, "scroll", () => { n.value = e.scrollX, s.value = e.scrollY; }, { capture: !1, passive: !0 } ), { x: i, y: o }; } function Na(r = {}) { const { window: e = ln, initialWidth: t = Number.POSITIVE_INFINITY, initialHeight: n = Number.POSITIVE_INFINITY, listenOrientation: s = !0, includeScrollbar: i = !0, type: o = "inner" } = r, a = me(t), l = me(n), c = () => { e && (o === "outer" ? (a.value = e.outerWidth, l.value = e.outerHeight) : i ? (a.value = e.innerWidth, l.value = e.innerHeight) : (a.value = e.document.documentElement.clientWidth, l.value = e.document.documentElement.clientHeight)); }; if (c(), ko(c), Xe("resize", c, { passive: !0 }), s) { const f = Zc("(orientation: portrait)"); J(f, () => c()); } return { width: a, height: l }; } function iu(r) { let { resolution: e, renderer: t, scene: n, envMap: s, fog: i, near: o, far: a } = r; t = t ?? xn().renderer, n = n ?? xn().scene, et(() => { e = ze(r.resolution) ?? 255, o = ze(r.near) ?? 0.1, a = ze(r.far) ?? 1e3, s = ze(r.envMap) ?? void 0, i = ze(r.fog) ?? void 0, t = ze(r.renderer) ?? t, n = ze(r.scene) ?? n; }); const c = Pe(() => new aa(ze(e))); c.value.texture.type = Lt, ci(() => { c.value.dispose(); }); const f = Pe(() => new la(ze(o), ze(a), ze(c))), u = () => { const d = ze(n), h = d.fog, m = d.background; d.background = ze(s) || m, d.fog = ze(i) || h, f.value.update(ze(t), d), d.fog = h, d.background = m; }; return et(u), { fbo: c, camera: f, update: u }; } const ou = ["object"], Pg = /* @__PURE__ */ ue({ __name: "component", props: { frames: { default: 1 / 0 }, resolution: {}, near: {}, far: {}, envMap: {}, fog: {}, renderer: {}, scene: {} }, setup(r, { expose: e }) { const t = r, n = re(), { fbo: s, camera: i, update: o } = iu(t); let a = 0; return Ve().onBeforeRender(() => { n.value && (t.frames === 1 / 0 || a < ze(t.frames)) && (n.value.visible = !1, o(), n.value.visible = !0, n.value && n.value.traverse((l) => { "material" in l && typeof l.material == "object" && l.material && "envMap" in l.material && (l.material.envMap = s.value.texture); }), a++); }), e({ instance: n, fbo: s, camera: i, update: o }), (l, c) => (ae(), ce("TresGroup", { ref_key: "groupRef", ref: n }, [ ye("primitive", { object: F(i) }, null, 8, ou), Ne(l.$slots, "default") ], 512)); } }), Rg = /* @__PURE__ */ ue({ __name: "Billboard", props: { autoUpdate: { type: Boolean, default: !0 }, lockX: { type: Boolean, default: !1 }, lockY: { type: Boolean, default: !1 }, lockZ: { type: Boolean, default: !1 } }, setup(r, { expose: e }) { const t = r, n = re(new Zt()), s = re(new Zt()), i = new je(), o = new vt(); function a(l) { n.value && (!l && (l = xn().camera.value, !l) || (s.value.rotation.copy(o), n.value.updateMatrix(), n.value.updateWorldMatrix(!1, !1), n.value.getWorldQuaternion(i), l.getWorldQuaternion(s.value.quaternion).premultiply(i.invert()), t.lockX && (s.value.rotation.x = o.x), t.lockY && (s.value.rotation.y = o.y), t.lockZ && (s.value.rotation.z = o.z))); } return Ve().onBeforeRender(({ camera: l }) => { t.autoUpdate && a(l); }), e({ instance: n, update: a }), (l, c) => (ae(), ce("TresGroup", { ref_key: "outerRef", ref: n }, [ ye("TresGroup", { ref_key: "innerRef", ref: s }, [ Ne(l.$slots, "default") ], 512) ], 512)); } }), Cg = ue({ name: "GlobalAudio", props: [ "src", "loop", "volume", "playbackRate", "playTrigger", "stopTrigger" ], async setup(r, { expose: e, emit: t }) { var u; const { camera: n, renderer: s } = xe(), i = new ca(); (u = n.value) == null || u.add(i); const o = new Al(i), a = new ua(); e({ instance: o }), tt(() => { o && o.disconnect(); }), J(() => [r.playbackRate], () => o.setPlaybackRate(r.playbackRate ?? 1), { immediate: !0 }), J(() => [r.volume], () => o.setVolume(r.volume ?? 0.5), { immediate: !0 }), J(() => [r.loop], () => o.setLoop(r.loop ?? !1), { immediate: !0 }), J(() => [r.src], async () => { const d = await a.loadAsync(r.src); o.setBuffer(d); }, { immediate: !0 }); const c = document.getElementById(r.playTrigger ?? "") || s.value.domElement; Xe(c, "click", () => { o.isPlaying ? o.pause() : o.play(), t("isPlaying", o.isPlaying); }); const f = document.getElementById(r.stopTrigger ?? ""); return f && Xe(f, "click", () => { o.stop(), t("isPlaying", o.isPlaying); }), null; } }), ru = ["color-space", "args", "attach"], Ig = /* @__PURE__ */ ue({ __name: "GradientTexture", props: { stops: {}, colors: {}, attach: { default: "map" }, height: { default: 1024 }, width: { default: 16 }, type: { default: "linear" }, innerCircleRadius: { default: 0 }, outerCircleRadius: { default: "auto" } }, setup(r, { expose: e }) { const t = r, n = re(), s = document.createElement("canvas"); function i(a) { const l = a.getContext("2d"); a.width = t.width, a.height = t.height; let c; if (t.type === "linear") c = l.createLinearGradient(0, 0, 0, t.height); else { const d = a.width / 2, h = a.height / 2, m = t.outerCircleRadius !== "auto" ? Math.abs(Number(t.outerCircleRadius)) : Math.sqrt(d ** 2 + h ** 2); c = l.createRadialGradient( d, h, Math.abs(t.innerCircleRadius), d, h, m ); } const f = new Jn.Color(); let u = t.stops.length; for (; u--; ) c.addColorStop(t.stops[u], f.set(t.colors[u]).getStyle()); l.save(), l.fillStyle = c, l.fillRect(0, 0, t.width, t.height), l.restore(), n.value && (n.value.needsUpdate = !0); } const o = xn().renderer; return J(() => [t.colors, t.stops, t.height, t.width, t.type, t.innerCircleRadius, t.outerCircleRadius], () => { i(s); }, { immediate: !0 }), po(t.colors) && J(t.colors, () => i(s)), po(t.stops) && J(t.stops, () => i(s)), e({ instance: n }), (a, l) => (ae(), ce("TresCanvasTexture", { ref_key: "textureRef", ref: n, "color-space": F(o).outputColorSpace, args: [F(s)], attach: t.attach }, null, 8, ru)); } }); function No(r, e, t, n) { const s = class extends bt { constructor(o = {}) { const a = Object.entries(r); super({ uniforms: a.reduce((l, [c, f]) => { const u = Dn.clone({ [c]: { value: f } }); return { ...l, ...u }; }, {}), vertexShader: e, fragmentShader: t }); pe(this, "key", ""); a.forEach( ([l]) => Object.defineProperty(this, l, { get: () => this.uniforms[l].value, set: (c) => this.uniforms[l].value = c }) ), Object.assign(this, o); } }; return s.key = Ye.generateUUID(), s; } const au = No( { color: /* @__PURE__ */ new be("white"), scale: /* @__PURE__ */ new ve(1, 1), imageBounds: /* @__PURE__ */ new ve(1, 1), resolution: 1024, map: null, zoom: 1, radius: 0, grayscale: 0, opacity: 1 }, /* glsl */ ` varying vec2 vUv; varying vec2 vPos; void main() { gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.); vUv = uv; vPos = position.xy; } `, /* glsl */ ` // mostly from https://gist.github.com/statico/df64c5d167362ecf7b34fca0b1459a44 varying vec2 vUv; varying vec2 vPos; uniform vec2 scale; uniform vec2 imageBounds; uniform float resolution; uniform vec3 color; uniform sampler2D map; uniform float radius; uniform float zoom; uniform float grayscale; uniform float opacity; const vec3 luma = vec3(.299, 0.587, 0.114); vec4 toGrayscale(vec4 color, float intensity) { return vec4(mix(color.rgb, vec3(dot(color.rgb, luma)), intensity), color.a); } vec2 aspect(vec2 size) { return size / min(size.x, size.y); } const float PI = 3.14159265; // from https://iquilezles.org/articles/distfunctions float udRoundBox( vec2 p, vec2 b, float r ) { return length(max(abs(p)-b+r,0.0))-r; } void main() { vec2 s = aspect(scale); vec2 i = aspect(imageBounds); float rs = s.x / s.y; float ri = i.x / i.y; vec2 new = rs < ri ? vec2(i.x * s.y / i.y, s.y) : vec2(s.x, i.y * s.x / i.x); vec2 offset = (rs < ri ? vec2((new.x - s.x) / 2.0, 0.0) : vec2(0.0, (new.y - s.y) / 2.0)) / new; vec2 uv = vUv * s / new + offset; vec2 zUv = (uv - vec2(0.5, 0.5)) / zoom + vec2(0.5, 0.5); vec2 res = vec2(scale * resolution); vec2 halfRes = 0.5 * res; float b = udRoundBox(vUv.xy * res - halfRes, halfRes, resolution * radius); vec3 a = mix(vec3(1.0,0.0,0.0), vec3(0.0,0.0,0.0), smoothstep(0.0, 1.0, b)); gl_FragColor = toGrayscale(texture2D(map, zUv) * vec4(color, opacity * a), grayscale); #include <tonemapping_fragment> #include <colorspace_fragment> } ` ), lu = /* @__PURE__ */ ue({ __name: "ImageMaterial", setup(r, { expose: e }) { Oa({ ImageMaterial: au }); const t = re(); return e({ instance: t }), (n, s) => (ae(), ce("TresImageMaterial", { ref_key: "materialRef", ref: t }, null, 512)); } }), cu = ["scale"], uu = ["args"], Og = /* @__PURE__ */ ue({ __name: "component", props: { segments: { default: 1 }, scale: { default: 1 }, color: { default: () => new be("white") }, zoom: { default: 1 }, radius: { default: 0 }, grayscale: { default: 0 }, toneMapped: { type: Boolean, default: !0 }, transparent: { type: Boolean, default: !1 }, opacity: { default: 1 }, side: { default: ss }, texture: {}, url: {} }, setup(r, { expose: e }) { const t = r, n = re(), s = re(t.texture ?? null), i = xn().sizes, o = Pe(() => Array.isArray(t.scale) ? [t.scale[0], t.scale[1]] : [t.scale, t.scale]), a = Pe(() => { var f, u; return [((f = s.value) == null ? void 0 : f.image.width) ?? 0, ((u = s.value) == null ? void 0 : u.image.height) ?? 0]; }), l = Pe(() => Math.max(i.width.value, i.height.value)); et(() => { t.texture ? s.value = t.texture : Bn([t.url]).then((f) => s.value = f); }); const c = Pe( () => Array.isArray(t.scale) ? [...t.scale, 1] : t.scale ); return e({ instance: n }), (f, u) => (ae(), ce("TresMesh", { ref_key: "imageRef", ref: n, scale: c.value }, [ Ne(f.$slots, "default", {}, () => [ ye("TresPlaneGeometry", { args: [1, 1, t.segments, t.segments] }, null, 8, uu) ]), ms(lu, { color: t.color, map: s.value, zoom: t.zoom, grayscale: t.grayscale, opacity: t.opacity, scale: o.value, imageBounds: a.value, resolution: l.value, radius: f.radius, toneMapped: f.toneMapped, transparent: f.transparent, side: f.side }, null, 8, ["color", "map", "zoom", "grayscale", "opacity", "scale", "imageBounds", "resolution", "radius", "toneMapped", "transparent", "side"]) ], 8, cu)); } }), Ss = parseInt(Ts.replace(/\D+/g, "")), Bo = Ss >= 125 ? "uv1" : "uv2"; function er(r, e) { if (e === Pl) return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), r; if (e === oo || e === ha) { let t = r.getIndex(); if (t === null) { const o = [], a = r.getAttribute("position"); if (a !== void 0) { for (let l = 0; l < a.count; l++) o.push(l); r.setIndex(o), t = r.getIndex(); } else return console.error( "THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible." ), r; } const n = t.count - 2, s = []; if (t) if (e === oo) for (let o = 1; o <= n; o++) s.push(t.getX(0)), s.push(t.getX(o)), s.push(t.getX(o + 1)); else for (let o = 0; o < n; o++) o % 2 === 0 ? (s.push(t.getX(o)), s.push(t.getX(o + 1)), s.push(t.getX(o + 2))) : (s.push(t.getX(o + 2)), s.push(t.getX(o + 1)), s.push(t.getX(o))); s.length / 3 !== n && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles."); const i = r.clone(); return i.setIndex(s), i.clearGroups(), i; } else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", e), r; } function hu(r, e = Math.PI / 3) { const t = Math.cos(e), n = (1 + 1e-10) * 100, s = [new $(), new $(), new $()], i = new $(), o = new $(), a = new $(), l = new $(); function c(g) { const v = ~~(g.x * n), p = ~~(g.y * n), b = ~~(g.z * n); return `${v},${p},${b}`; } const f = r.index ? r.toNonIndexed() : r, u = f.attributes.position, d = {}; for (let g = 0, v = u.count / 3; g < v; g++) { const p = 3 * g, b = s[0].fromBufferAttribute(u, p + 0), _ = s[1].fromBufferAttribute(u, p + 1), M = s[2].fromBufferAttribute(u, p + 2); i.subVectors(M, _), o.subVectors(b, _); const R = new $().crossVectors(i, o).normalize(); for (let w = 0; w < 3; w++) { const E = s[w], x = c(E); x in d || (d[x] = []), d[x].push(R); } } const h = new Float32Array(u.count * 3), m = new ut(h, 3, !1); for (let g = 0, v = u.count / 3; g < v; g++) { const p = 3 * g, b = s[0].fromBufferAttribute(u, p + 0), _ = s[1].fromBufferAttribute(u, p + 1), M = s[2].fromBufferAttribute(u, p + 2); i.subVectors(M, _), o.subVectors(b, _), a.crossVectors(i, o).normalize(); for (let R = 0; R < 3; R++) { const w = s[R], E = c(w), x = d[E]; l.set(0, 0, 0); for (let T = 0, y = x.length; T < y; T++) { const A = x[T]; a.dot(A) > t && l.add(A); } l.normalize(), m.setXYZ(p + R, l.x, l.y, l.z); } } return f.setAttribute("normal", m), f; } var fu = Object.defineProperty, du = (r, e, t) => e in r ? fu(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, pu = (r, e, t) => (du(r, e + "", t), t); async function tr(r) { const e = await r.arrayBuffer(), t = btoa(String.fromCharCode(...new Uint8Array(e))); return `data:${r.type || ""};base64,${t}`; } let Bs, bi, Fn, Us; function Ei(r, e = 1 / 0, t = null) { bi || (bi = new jt(2, 2, 1, 1)), Fn || (Fn = new bt({ uniforms: { blitTexture: new Se(r) }, vertexShader: ( /* glsl */ ` varying vec2 vUv; void main(){ vUv = uv; gl_Position = vec4(position.xy * 1.0,0.,.999999); } ` ), fragmentShader: ( /* glsl */ ` uniform sampler2D blitTexture; varying vec2 vUv; void main(){ gl_FragColor = vec4(vUv.xy, 0, 1); #ifdef IS_SRGB gl_FragColor = LinearTosRGB( texture2D( blitTexture, vUv) ); #else gl_FragColor = texture2D( blitTexture, vUv); #endif } ` ) })), Fn.uniforms.blitTexture.value = r, Fn.defines.IS_SRGB = "colorSpace" in r ? r.colorSpace === "srgb" : r.encoding === 3001, Fn.needsUpdate = !0, Us || (Us = new de(bi, Fn), Us.frustrumCulled = !1); const n = new kt(), s = new xs(); s.add(Us), t || (t = Bs = new Rl({ antialias: !1 })), t.setSize(Math.min(r.image.width, e), Math.min(r.image.height, e)), t.clear(), t.render(s, n); const i = new es(t.domElement); return i.minFilter = r.minFilter, i.magFilter = r.magFilter, i.wrapS = r.wrapS, i.wrapT = r.wrapT, i.name = r.name, Bs && (Bs.dispose(), Bs = null), i; } const nr = { POSITION: [ "byte", "byte normalized", "unsigned byte", "unsigned byte normalized", "short", "short normalized", "unsigned short", "unsigned short normalized" ], NORMAL: ["byte normalized", "short normalized"], TANGENT: ["byte normalized", "short normalized"], TEXCOORD: ["byte", "byte normalized", "unsigned byte", "short", "short normalized", "unsigned short"] }; class Uo { constructor() { this.pluginCallbacks = [], this.register(function(e) { return new Eu(e); }), this.register(function(e) { return new Mu(e); }), this.register(function(e) { return new Pu(e); }), this.register(function(e) { return new Ru(e); }), this.register(function(e) { return new Cu(e); }), this.register(function(e) { return new Iu(e); }), this.register(function(e) { return new Su(e); }), this.register(function(e) { return new Au(e); }), this.register(function(e) { return new Ou(e); }), this.register(function(e) { return new Du(e); }), this.register(function(e) { return new Lu(e); }); } register(e) { return this.pluginCallbacks.indexOf(e) === -1 && this.pluginCallbacks.push(e), this; } unregister(e) { return this.pluginCallbacks.indexOf(e) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e), 1), this; } /** * Parse scenes and generate GLTF output * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes * @param {Function} onDone Callback on completed * @param {Function} onError Callback on errors * @param {Object} options options */ parse(e, t, n, s) { const i = new bu(), o = []; for (let a = 0, l = this.pluginCallbacks.length; a < l; a++) o.push(this.pluginCallbacks[a](i)); i.setPlugins(o), i.write(e, t, s).catch(n); } parseAsync(e, t) { const n = this; return new Promise(function(s, i) { n.parse(e, s, i, t); }); } } pu(Uo, "Utils", { insertKeyframe: function(r, e) { const n = r.getValueSize(), s = new r.TimeBufferType(r.times.length + 1), i = new r.ValueBufferType(r.values.length + n), o = r.createInterpolant(new r.ValueBufferType(n)); let a; if (r.times.length === 0) { s[0] = e; for (let l = 0; l < n; l++) i[l] = 0; a = 0; } else if (e < r.times[0]) { if (Math.abs(r.times[0] - e) < 1e-3) return 0; s[0] = e, s.set(r.times, 1), i.set(o.evaluate(e), 0), i.set(r.values, n), a = 0; } else if (e > r.times[r.times.length - 1]) { if (Math.abs(r.times[r.times.length - 1] - e) < 1e-3) return r.times.length - 1; s[s.length - 1] = e, s.set(r.times, 0), i.set(r.values, 0), i.set(o.evaluate(e), r.values.length), a = s.length - 1; } else for (let l = 0; l < r.times.length; l++) { if (Math.abs(r.times[l] - e) < 1e-3) return l; if (r.times[l] < e && r.times[l + 1] > e) { s.set(r.times.slice(0, l + 1), 0), s[l + 1] = e, s.set(r.times.slice(l + 1), l + 2), i.set(r.values.slice(0, (l + 1) * n), 0), i.set(o.evaluate(e), (l + 1) * n), i.set(r.values.slice((l + 1) * n), (l + 2) * n), a = l + 1; break; } } return r.times = s, r.values = i, a; }, mergeMorphTargetTracks: function(r, e) { const t = [], n = {}, s = r.tracks; for (let i = 0; i < s.length; ++i) { let o = s[i]; const a = rn.parseTrackName(o.name), l = rn.findNode(e, a.nodeName); if (a.propertyName !== "morphTargetInfluences" || a.propertyIndex === void 0) { t.push(o); continue; } if (o.createInterpolant !== o.InterpolantFactoryMethodDiscrete && o.createInterpolant !== o.InterpolantFactoryMethodLinear) { if (o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation."); console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."), o = o.clone(), o.setInterpolation(Mo); } const c = l.morphTargetInfluences.length, f = l.morphTargetDictionary[a.propertyIndex]; if (f === void 0) throw new Error("THREE.GLTFExporter: Morph target name not found: " + a.propertyIndex); let u; if (n[l.uuid] === void 0) { u = o.clone(); const h = new u.ValueBufferType(c * u.times.length); for (let m = 0; m < u.times.length; m++) h[m * c + f] = u.values[m]; u.name = (a.nodeName || "") + ".morphTargetInfluences", u.values = h, n[l.uuid] = u, t.push(u); continue; } const d = o.createInterpolant(new o.ValueBufferType(1)); u = n[l.uuid]; for (let h = 0; h < u.times.length; h++) u.values[h * c + f] = d.evaluate(u.times[h]); for (let h = 0; h < o.times.length; h++) { const m = this.insertKeyframe(u, o.times[h]); u.values[m * c + f] = o.values[h]; } } return r.tracks = t, r; } }); const De = { POINTS: 0, LINES: 1, LINE_LOOP: 2, LINE_STRIP: 3, TRIANGLES: 4, BYTE: 5120, UNSIGNED_BYTE: 5121, SHORT: 5122, UNSIGNED_SHORT: 5123, INT: 5124, UNSIGNED_INT: 5125, FLOAT: 5126, ARRAY_BUFFER: 34962, ELEMENT_ARRAY_BUFFER: 34963, NEAREST: 9728, LINEAR: 9729, NEAREST_MIPMAP_NEAREST: 9984, LINEAR_MIPMAP_NEAREST: 9985, NEAREST_MIPMAP_LINEAR: 9986, LINEAR_MIPMAP_LINEAR: 9987, CLAMP_TO_EDGE: 33071, MIRRORED_REPEAT: 33648, REPEAT: 10497 }, Mi = "KHR_mesh_quantization", Tt = {}; Tt[Kn] = De.NEAREST; Tt[da] = De.NEAREST_MIPMAP_NEAREST; Tt[pa] = De.NEAREST_MIPMAP_LINEAR; Tt[wt] = De.LINEAR; Tt[ma] = De.LINEAR_MIPMAP_NEAREST; Tt[Eo] = De.LINEAR_MIPMAP_LINEAR; Tt[Wt] = De.CLAMP_TO_EDGE; Tt[Ln] = De.REPEAT; Tt[ga] = De.MIRRORED_REPEAT; const sr = { scale: "scale", position: "translation", quaternion: "rotation", morphTargetInfluences: "weights" }, mu = new be(), ir = 12, gu = 1179937895, vu = 2, or = 8, yu = 1313821514, _u = 5130562; function vs(r, e) { return r.length === e.length && r.every(function(t, n) { return t === e[n]; }); } function xu(r) { return new TextEncoder().encode(r).buffer; } function wu(r) { return vs(r.elements, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); } function Tu(r, e, t) { const n = { min: new Array(r.itemSize).fill(Number.POSITIVE_INFINITY), max: new Array(r.itemSize).fill(Number.NEGATIVE_INFINITY) }; for (let s = e; s < e + t; s++) for (let i = 0; i < r.itemSize; i++) { let o; r.itemSize > 4 ? o = r.array[s * r.itemSize + i] : (i === 0 ? o = r.getX(s) : i === 1 ? o = r.getY(s) : i === 2 ? o = r.getZ(s) : i === 3 && (o = r.getW(s)), r.normalized === !0 && (o = Ye.normalize(o, r.array))), n.min[i] = Math.min(n.min[i], o), n.max[i] = Math.max(n.max[i], o); } return n; } function Ba(r) { return Math.ceil(r / 4) * 4; } function Si(r, e = 0) { const t = Ba(r.by