@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in
1,400 lines (1,392 loc) • 1.75 MB
JavaScript
var Tx = Object.defineProperty;
var Ax = (s, t, e) => t in s ? Tx(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
var r = (s, t, e) => (Ax(s, typeof t != "symbol" ? t + "" : t, e), e), Of = (s, t, e) => {
if (!t.has(s))
throw TypeError("Cannot " + e);
};
var fe = (s, t, e) => (Of(s, t, "read from private field"), e ? e.call(s) : t.get(s)), zi = (s, t, e) => {
if (t.has(s))
throw TypeError("Cannot add the same private member more than once");
t instanceof WeakSet ? t.add(s) : t.set(s, e);
}, ln = (s, t, e, i) => (Of(s, t, "write to private field"), i ? i.call(s, e) : t.set(s, e), e);
var Pl = (s, t, e) => (Of(s, t, "access private method"), e);
import { Vector2 as oe, Vector3 as v, Vector4 as ge, Quaternion as W, PlaneGeometry as Gn, PerspectiveCamera as be, Scene as Mi, ShaderMaterial as bn, Uniform$1 as fo, Mesh as q, WebGLRenderer as Rr, Texture as Fe, Euler as jt, Box3 as Pi, MeshStandardMaterial as It, Color as ce, ShadowMaterial as Jb, Box3Helper as e0, GridHelper as og, Material as Se, Matrix3 as t0, Matrix4 as se, Layers as So, Object3D as L, Ray as Co, MathUtils as Ss, AxesHelper as Oi, MeshBasicMaterial as Me, DoubleSide as Ri, BufferGeometry as Cs, Group as po, SphereGeometry as wu, BoxGeometry as La, SpriteMaterial as Ex, Sprite as Ix, Shape as Lx, ExtrudeGeometry as Dx, Fog as i0, DirectionalLight as Zp, PointLight as rg, Line as Ec, BufferAttribute as pt, CylinderGeometry as jx, EdgesGeometry as Bx, LineSegments as n0, LineBasicMaterial as s0, Sphere as xu, Plane as vr, Raycaster as Su, ArrayCamera as Fx, SkinnedMesh as Ps, InterleavedBufferAttribute as o0, Skeleton as zx, Bone as Ux, Source as Nx, WebGLCubeRenderTarget as $x, CubeCamera as Wx, AnimationClip as mo, TextureLoader as wa, PropertyBinding as Da, LinearSRGBColorSpace as As, ShaderChunk as Jt, UniformsLib as Vx, FileLoader as r0, DataTexture as ag, RGBAFormat as Cu, EquirectangularReflectionMapping as Os, SRGBColorSpace as Es, Clock as Hx, NoToneMapping as ja, PCFSoftShadowMap$1 as Gx, BasicNodeLibrary as qx, WebGLRenderTarget as Is, DepthTexture as Xx, NearestFilter as Ld, LoopRepeat as Qx, LoopOnce as Jp, AnimationMixer as lg, CompressedTexture as Yx, FrontSide as Po, Frustum as Fy, OrthographicCamera as cg, AudioListener as Kx, PositionalAudio as Zx, AudioLoader as em, EventDispatcher as hg, BackSide as Pu, MeshDepthMaterial as Jx, CustomBlending as e1, MaxEquation as t1, AmbientLight as i1, HemisphereLight as n1, InvertStencilOp as s1, DecrementWrapStencilOp as o1, IncrementWrapStencilOp as r1, DecrementStencilOp as a1, IncrementStencilOp as l1, ReplaceStencilOp as c1, ZeroStencilOp as h1, KeepStencilOp as d1, AlwaysStencilFunc as u1, GreaterEqualStencilFunc as f1, NotEqualStencilFunc as p1, GreaterStencilFunc as m1, LessEqualStencilFunc as g1, EqualStencilFunc as y1, LessStencilFunc as _1, NeverStencilFunc as zy, RawShaderMaterial as a0, GLSL3 as b1, AlwaysDepth as v1, GreaterEqualDepth as w1, GreaterDepth as x1, LessEqualDepth as S1, LessDepth as C1, NotEqualDepth as P1, EqualDepth as O1, BatchedMesh as Uy, MeshPhysicalMaterial as tm, UnsignedByteType as M1, LinearFilter as Ny, RingGeometry as R1, Line3 as k1, AdditiveBlending as l0, BoxHelper as T1, SpotLight as A1, DirectionalLightHelper as E1, CameraHelper as I1, LOD as L1, Triangle as D1, NormalBlending as j1, NeutralToneMapping as Ic, AgXToneMapping as Ou, ACESFilmicToneMapping as dg, ReinhardToneMapping as ug, LinearToneMapping as Mu, HalfFloatType as B1, VideoTexture as F1, CubeTexture as z1, CompressedCubeTexture as U1, EquirectangularRefractionMapping as N1, VectorKeyframeTrack as $1, QuaternionKeyframeTrack as W1, Audio as V1, MirroredRepeatWrapping as $y, UniformsUtils as c0, ShaderLib as Dd, MeshNormalMaterial as H1, AudioContext as G1, PMREMGenerator$1 as q1 } from "./three.light.js";
import { createLoaders as fg, getRaycastMesh as h0, LODsManager as Vr, NEEDLE_progressive as Ke, addDracoAndKTX2Loaders as X1, configureLoader as Q1, setDracoDecoderLocation as Y1, setKTX2TranscoderLocation as K1 } from "./gltf-progressive.light.js";
import { GroundedSkybox as Ba, Font as Z1, TextGeometry as J1, FontLoader as eS, GLTFLoader as wr, TransformControlsGizmo as d0, EXRLoader as jd, RGBELoader as im, Stats as tS, nodeFrame as iS, OrbitControls as u0, PositionalAudioHelper as nS, HorizontalBlurShader as sS, VerticalBlurShader as oS, GLTFExporter as f0, strToU8 as p0, zipSync as rS, XRControllerModelFactory as aS, XRHandMeshModel as lS, Line2 as cS, LineGeometry as hS, LineMaterial as dS, KTX2Loader as uS, TransformControls as fS, InteractiveGroup as pS, HTMLMesh as mS, VertexNormalsHelper as gS, OBJLoader as pg, FBXLoader as m0, mergeVertices as yS } from "./three-examples.light.js";
import { fetchProfile as _S, MotionController as bS, $70d766613f57b014$export$2e2bcd8739ae039 as Wy, ByteBuffer as vS, v5 as Vy, md5 as Hy, SIZE_PREFIX_LENGTH as g0, Builder as mg, createNoise4D as wS, Matrix4 as Mf, BatchedParticleRenderer as xS, ParticleSystem as SS, RenderMode as us, TrailParticle as Gy, ConstantColor as CS, Vector4 as PS, ConstantValue as OS, WorkerBase as MS, MeshBVH as RS } from "./vendor.light.js";
import { __webpack_exports__default as Te, __webpack_exports__Text as y0, __webpack_exports__Block as _0, __webpack_exports__update as kS, SimpleStateBehavior as TS, __webpack_exports__Inline as Rf, __webpack_exports__FontLibrary as qy, ThreeMeshUI as Xy } from "./three-mesh-ui.light.js";
let b0, Qy = null;
function Wn() {
return b0;
}
function v0(s) {
if (s == null) {
console.warn("Oh no: someone tried registering a non-existend gltf-loader. When you see this log it might mean that needle-engine is being imported multiple times. Please check your project setup.");
return;
}
Qy !== s && (Qy = s, b0 = new s());
}
const kf = /* @__PURE__ */ new Map();
function ui(s = ((t) => (t = globalThis.location) == null ? void 0 : t.hostname)()) {
if (kf.has(s))
return kf.get(s);
const e = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|localhost/.test(s);
return kf.set(s, e), e === !0;
}
function AS() {
return window.location.hostname.includes("glitch.me");
}
const Yy = typeof window !== void 0 ? window.location.search.includes("debugcontext") : !1;
var me = /* @__PURE__ */ ((s) => (s.ContextRegistered = "ContextRegistered", s.ContextCreationStart = "ContextCreationStart", s.ContextCreated = "ContextCreated", s.ContextFirstFrameRendered = "ContextFirstFrameRendered", s.ContextDestroying = "ContextDestroying", s.ContextDestroyed = "ContextDestroyed", s.MissingCamera = "MissingCamera", s.ContextClearing = "ContextClearing", s.ContextCleared = "ContextCleared", s))(me || {});
class pe {
/** The currently active (rendering) Needle Engine context */
static get Current() {
return globalThis["NeedleEngine.Context.Current"];
}
/** @internal */
static set Current(t) {
globalThis["NeedleEngine.Context.Current"] = t;
}
/** Returns the array of all registered Needle Engine contexts. Do not modify */
static get All() {
return this.Registered;
}
/** @internal Internal use only */
static register(t) {
this.Registered.indexOf(t) === -1 && (Yy && console.warn("Registering context"), this.Registered.push(t), this.dispatchCallback("ContextRegistered", t));
}
/** @internal Internal use only */
static unregister(t) {
const e = this.Registered.indexOf(t);
e !== -1 && (Yy && console.warn("Unregistering context"), this.Registered.splice(e, 1));
}
/**
* Register a callback to be called when the given event occurs
*/
static registerCallback(t, e) {
this._callbacks[t] || (this._callbacks[t] = []), this._callbacks[t].push(e);
}
/** Unregister a callback */
static unregisterCallback(t, e) {
if (!this._callbacks[t])
return;
const i = this._callbacks[t].indexOf(e);
i !== -1 && this._callbacks[t].splice(i, 1);
}
/** @internal */
static dispatchCallback(t, e, i) {
if (!this._callbacks[t])
return !0;
const n = { event: t, context: e };
if (i)
for (const a in i)
n[a] = i[a];
const o = new Array();
return this._callbacks[t].forEach((a) => {
const l = a(n);
l instanceof Promise && o.push(l);
}), Promise.all(o);
}
/**
* Register a callback to be called when a context is created
*/
static addContextCreatedCallback(t) {
this.registerCallback("ContextCreated", t);
}
/**
* Register a callback to be called when a context is registered
*/
static addContextDestroyedCallback(t) {
this.registerCallback("ContextDestroyed", t);
}
}
/** All currently registered Needle Engine contexts. Do not modify */
r(pe, "Registered", []), r(pe, "_callbacks", {});
const ES = () => (s) => s;
function WI(s) {
return ES()(s);
}
function VI() {
return !!x("debug");
}
class tn {
constructor(t, e) {
r(this, "_factory");
r(this, "_cache", []);
r(this, "_maxSize");
r(this, "_index", 0);
this._factory = t, this._maxSize = e;
}
get() {
const t = this._index % this._maxSize;
return this._index++, this._cache.length <= t && (this._cache[t] = this._factory()), this._cache[t];
}
}
let Yo = !1;
const nm = new Array();
typeof window < "u" && setTimeout(() => {
if (Yo) {
const s = {}, t = new URL(window.location.href), e = new URL(t);
e.searchParams.append("console", "");
const i = e.toString().replace(/=$|=(?=&)/g, "");
for (const o of nm) {
const a = new URL(t);
a.searchParams.append(o, ""), s[o] = a.toString().replace(/=$|=(?=&)/g, "");
}
console.log(
`🌵 ?help: Debug Options for Needle Engine.
Append any of these parameters to the URL to enable specific debug options.
Example: ${i} will show an onscreen console window.`
);
const n = Yo === !0 ? "" : ` (containing "${Yo}")`;
console.group("Available URL parameters:" + n);
for (const o of Object.keys(s).sort())
typeof Yo == "string" && !o.toLowerCase().includes(Yo.toLowerCase()) || (console.groupCollapsed(o), console.log("Reload with this flag enabled:"), console.log(s[o]), console.groupEnd());
console.groupEnd();
}
}, 100);
function Ru() {
var s;
return new URLSearchParams((s = globalThis.location) == null ? void 0 : s.search);
}
function x(s) {
Yo && !nm.includes(s) && nm.push(s);
const t = Ru();
if (t.has(s)) {
const e = t.get(s);
if (e) {
const i = Number(e);
return isNaN(i) ? e : i;
} else
return !0;
}
return !1;
}
Yo = x("help");
function HI(s, t) {
const e = Ru();
e.has(s) ? e.set(s, t) : e.append(s, t), document.location.search = e.toString();
}
function Bd(s, t, e = !0) {
const i = Ru();
i.has(s) ? t === null ? i.delete(s) : i.set(s, t) : t !== null && i.append(s, t), e ? IS(s, i) : w0(s, i);
}
function Ky(s, t, e) {
s.has(t) ? s.set(t, e.toString()) : s.append(t, e.toString());
}
function IS(s, t, e) {
window.history.pushState(e, s, "?" + t.toString());
}
function w0(s, t, e) {
window.history.replaceState(e, s, "?" + t.toString());
}
function GI(s) {
for (var t = "", e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", i = e.length, n = 0; n < s; n++)
t += e.charAt(Math.floor(Math.random() * i));
return t;
}
function qI(s, t) {
return Math.floor(Math.random() * (t - s + 1)) + s;
}
const Zy = ["smol", "tiny", "giant", "interesting", "smart", "bright", "dull", "extreme", "beautiful", "pretty", "dark", "epic", "salty", "silly", "funny", "lame", "lazy", "loud", "lucky", "mad", "mean", "mighty", "mysterious", "nasty", "odd", "old", "powerful", "quiet", "rapid", "scary", "shiny", "shy", "silly", "smooth", "sour", "spicy", "stupid", "sweet", "tasty", "terrible", "ugly", "unusual", "vast", "wet", "wild", "witty", "wrong", "zany", "zealous", "zippy", "zombie", "zorro"], Jy = ["cat", "dog", "mouse", "pig", "cow", "horse", "sheep", "chicken", "duck", "goat", "panda", "tiger", "lion", "elephant", "monkey", "bird", "fish", "snake", "frog", "turtle", "hamster", "penguin", "kangaroo", "whale", "dolphin", "crocodile", "snail", "ant", "bee", "beetle", "butterfly", "dragon", "eagle", "fish", "giraffe", "lizard", "panda", "penguin", "rabbit", "snake", "spider", "tiger", "zebra"];
function LS() {
const s = Zy[Math.floor(Math.random() * Zy.length)], t = Jy[Math.floor(Math.random() * Jy.length)];
return s + "_" + t;
}
function DS(s) {
return s = s.replace(/[^a-z0-9áéÃóúñü \.,_-]/gim, ""), s.trim();
}
function Lc(s, t, e = !0, i = !1) {
var n;
if (t == null)
return null;
if (t.userData && t.userData.guid === s)
return t;
if (t.guid == s)
return t;
if (i && (n = t.userData) != null && n.components) {
for (const o of t.userData.components)
if (o.guid === s)
return o;
}
if (e) {
if (t.scenes)
for (const o in t.scenes) {
const a = t.scenes[o], l = Lc(s, a, e, i);
if (l)
return l;
}
if (t.children)
for (const o in t.children) {
const a = t.children[o], l = Lc(s, a, e, i);
if (l)
return l;
}
}
}
function ku(s, t) {
if (s != null && typeof s == "object") {
let e;
Array.isArray(s) ? e = [] : (e = Object.create(s), Object.assign(e, s));
for (const i of Object.keys(s)) {
const n = s[i];
t && !t(s, i, n) ? e[i] = n : (n == null ? void 0 : n.clone) !== void 0 && typeof n.clone == "function" ? e[i] = n.clone() : e[i] = ku(n, t);
}
return e;
}
return s;
}
function Vn(s) {
return new Promise((t, e) => {
setTimeout(t, s);
});
}
function Tu(s, t) {
if (s <= 0)
return Promise.resolve();
if (t || (t = pe.Current), !t)
return Promise.reject("No context");
const e = t.time.frameCount + s;
return new Promise((i, n) => {
if (!t)
return n("No context");
const o = () => {
t.time.frameCount >= e && (t.pre_update_callbacks.splice(t.pre_update_callbacks.indexOf(o), 1), i());
};
t.pre_update_callbacks.push(o);
});
}
const Rh = x("debugresolveurl"), jS = "rel:";
function XI(s, t) {
return kr(s, t);
}
function kr(s, t) {
if (t === void 0)
return Rh && console.warn("getPath: uri is undefined, returning uri", t), t;
if (t.startsWith("./"))
return t;
if (t.startsWith("http"))
return Rh && console.warn("getPath: uri is absolute, returning uri", t), t;
if (s === void 0)
return Rh && console.warn("getPath: source is undefined, returning uri", t), t;
t.startsWith(jS) && (t = t.substring(4));
const e = s.lastIndexOf("/");
if (e >= 0) {
const i = s.substring(0, e + 1);
for (; i.endsWith("/") && t.startsWith("/"); )
t = t.substring(1);
const n = i + t;
return Rh && console.log("source:", s, `changed uri
from`, t, `
to `, n, `
basePath: ` + i), n;
}
return t;
}
class BS {
constructor(t, e) {
r(this, "writeCallbacks", []);
r(this, "_applied", !1);
r(this, "_object");
r(this, "_prop");
r(this, "_wrapperProp");
this._object = t, this._prop = e, this._wrapperProp = Symbol("$" + e), this.apply();
}
subscribeWrite(t) {
this.writeCallbacks.push(t);
}
unsubscribeWrite(t) {
const e = this.writeCallbacks.indexOf(t);
e !== -1 && this.writeCallbacks.splice(e, 1);
}
apply() {
if (this._applied || !this._object)
return;
const t = this._object, e = this._prop;
if (t[e] === void 0)
return;
this._applied = !0, t[this._wrapperProp] !== void 0 && console.warn("Watcher is being applied to an object that already has a wrapper property. This is not (yet) supported");
const i = t[e];
t[this._wrapperProp] = i, Object.defineProperty(t, e, {
get: () => t[this._wrapperProp],
set: (a) => {
t[this._wrapperProp] = a;
for (const l of this.writeCallbacks)
l(a, this._prop);
}
});
}
revoke() {
if (!this._applied || !this._object)
return;
this._applied = !1;
const t = this._object, e = this._prop;
Reflect.deleteProperty(t, e);
const i = t[this._wrapperProp];
t[e] = i, Reflect.deleteProperty(t, this._wrapperProp);
}
dispose() {
this.revoke(), this.writeCallbacks.length = 0, this._object = null;
}
}
class go {
constructor(t, e) {
r(this, "_watches", []);
if (Array.isArray(e))
for (const i of e)
this._watches.push(new go(t, i));
else
this._watches.push(new BS(t, e));
}
subscribeWrite(t) {
for (const e of this._watches)
e.subscribeWrite(t);
}
unsubscribeWrite(t) {
for (const e of this._watches)
e.unsubscribeWrite(t);
}
apply() {
for (const t of this._watches)
t.apply();
}
revoke() {
for (const t of this._watches)
t.revoke();
}
dispose() {
for (const t of this._watches)
t.dispose();
this._watches.length = 0;
}
}
const na = Symbol("needle:watches");
function gg(s, t) {
if (!s[na])
if (s instanceof oe)
s[na] = new go(s, ["x", "y"]);
else if (s instanceof v)
s[na] = new go(s, ["x", "y", "z"]);
else if (s instanceof ge || s instanceof W)
s[na] = new go(s, ["x", "y", "z", "w"]);
else
return !1;
return s[na].subscribeWrite(t), !0;
}
function x0(s, t) {
if (!s)
return;
const e = s[na];
e && e.unsubscribeWrite(t);
}
var X;
((s) => {
let t;
function e() {
if (t !== void 0)
return t;
const D = window.navigator.userAgent, H = /Windows|MacOS|Mac OS/.test(D), Y = /Windows NT/.test(D) && /Edg/.test(D) && !/Win64/.test(D);
return t = H && !Y && !w();
}
s.isDesktop = e;
let i;
function n() {
return i !== void 0 ? i : typeof window.orientation < "u" || navigator.userAgent.indexOf("IEMobile") !== -1 ? i = !0 : i = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent);
}
s.isMobileDevice = n;
function o() {
return l();
}
s.isIPad = o;
let a;
function l() {
return a !== void 0 ? a : a = /iPad/.test(navigator.userAgent);
}
s.isiPad = l;
let c;
function h() {
return c !== void 0 ? c : c = /Android/.test(navigator.userAgent);
}
s.isAndroidDevice = h;
let d;
function u() {
return d !== void 0 ? d : d = /WebXRViewer\//i.test(navigator.userAgent);
}
s.isMozillaXR = u;
let p;
function m() {
if (p !== void 0)
return p;
if (navigator.userAgentData)
return p = navigator.userAgentData.platform === "macOS";
{
const D = navigator.userAgent.toLowerCase();
return p = D.includes("mac os x") || D.includes("macintosh");
}
}
s.isMacOS = m;
let g;
function y() {
return g !== void 0 ? g : g = m() && "xr" in navigator;
}
s.isVisionOS = y;
let _;
const b = ["iPad Simulator", "iPhone Simulator", "iPod Simulator", "iPad", "iPhone", "iPod"];
function w() {
return _ !== void 0 ? _ : _ = b.includes(navigator.platform) || navigator.userAgent.includes("Mac") && "ontouchend" in document;
}
s.isiOS = w;
let P;
function k() {
return P !== void 0 || (P = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)), P;
}
s.isSafari = k;
let O;
function M() {
return O !== void 0 ? O : O = navigator.userAgent.includes("OculusBrowser");
}
s.isQuest = M;
let E;
function B() {
return E !== void 0 || (E = document.createElement("a").relList.supports("ar")), E;
}
s.supportsQuickLookAR = B;
async function A() {
try {
return (await navigator.permissions.query({ name: "microphone" })).state !== "denied";
} catch (D) {
return console.error("Error querying `microphone` permissions.", D), !1;
}
}
s.microphonePermissionsGranted = A;
let F;
function U() {
if (F !== void 0)
return F;
const D = navigator.userAgent.match(/iPhone OS (\d+_\d+)/);
if (D && (F = D[1].replace("_", ".")), !F) {
const H = navigator.userAgent.match(/(?:\(Macintosh;|iPhone;|iPad;).*Version\/(\d+\.\d+)/);
H && (F = H[1]);
}
return F || (F = null), F;
}
s.getiOSVersion = U;
let Z;
function T() {
if (Z !== void 0)
return Z;
const D = navigator.userAgent.match(/(?:CriOS|Chrome)\/(\d+\.\d+\.\d+\.\d+)/);
return D ? Z = D[1].replace("_", ".") : Z = null, Z;
}
s.getChromeVersion = T;
})(X || (X = {}));
function QI() {
return X.isDesktop();
}
function YI() {
return X.isMobileDevice();
}
function KI() {
return X.isiPad();
}
function ZI() {
return X.isiPad();
}
function JI() {
return X.isAndroidDevice();
}
function eL() {
return X.isMozillaXR();
}
function tL() {
return X.isMacOS();
}
function iL() {
return X.isiOS();
}
function nL() {
return X.isSafari();
}
function sL() {
return X.isQuest();
}
async function oL() {
return X.microphonePermissionsGranted();
}
const FS = /ip=(?<ip>.+?)\n/s;
async function rL() {
const t = await (await fetch("https://www.cloudflare.com/cdn-cgi/trace")).text(), e = FS.exec(t);
return e ? e[1] : null;
}
async function aL() {
const s = await fetch("https://api.db-ip.com/v2/free/self").catch(() => null);
return s ? (await s.json()).ipAddress : void 0;
}
async function lL() {
const s = await fetch("https://api.db-ip.com/v2/free/self").catch(() => null);
return s ? await s.json() : void 0;
}
const lo = /* @__PURE__ */ new WeakMap();
function zS(s, t, e) {
if (!lo.get(s)) {
const n = new MutationObserver((o) => {
NS(s, o);
});
lo.set(s, {
observer: n,
attributeChangedListeners: /* @__PURE__ */ new Map()
}), n.observe(s, { attributes: !0 });
}
const i = lo.get(s).attributeChangedListeners;
i.has(t) || i.set(t, []), i.get(t).push(e);
}
function US(s, t, e) {
if (!lo.get(s))
return;
const i = lo.get(s).attributeChangedListeners;
if (!i.has(t))
return;
const n = i.get(t), o = n.indexOf(e);
if (o !== -1 && (n.splice(o, 1), n.length <= 0)) {
i.delete(t);
const a = lo.get(s);
a == null || a.observer.disconnect(), lo.delete(s);
}
}
function NS(s, t) {
const e = lo.get(s).attributeChangedListeners;
for (const i of t)
if (i.type === "attributes") {
const n = i.attributeName, o = s.getAttribute(n);
if (e.has(n))
for (const a of e.get(n))
a(o);
}
}
class e_ {
constructor(t) {
r(this, "reason");
this.reason = t;
}
}
async function S0(s) {
const t = await Promise.allSettled(s).catch((n) => [
new e_(n.message)
]);
let e = !1;
const i = t.map((n) => "value" in n ? n.value : (e = !0, new e_(n.reason)));
return {
anyFailed: e,
results: i
};
}
async function $S(s) {
if (!globalThis.QRCode) {
const i = "https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js";
let n = document.head.querySelector(`script[src="${i}"]`);
n || (n = document.createElement("script"), n.src = i, document.head.appendChild(n)), await new Promise((o, a) => {
n.addEventListener("load", () => {
o(!0);
});
});
}
const t = globalThis.QRCode, e = s.domElement ?? document.createElement("div");
return new t(e, {
width: s.width ?? 256,
height: s.height ?? 256,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: t.CorrectLevel.M,
...s
}), e;
}
const C0 = x("debugdebug");
let Dc = !1;
(x("noerrors") || x("nooverlaymessages")) && (Dc = !0);
const Tf = "needle_engine_global_error_container";
var Zi = /* @__PURE__ */ ((s) => (s[s.Log = 0] = "Log", s[s.Warn = 1] = "Warn", s[s.Error = 2] = "Error", s))(Zi || {});
function yg() {
return M0;
}
const sm = new Array();
function WS(s) {
sm.push(s);
}
let Af = !1;
function VS(...s) {
if (!Af) {
Af = !0;
try {
for (let t = 0; t < sm.length; t++)
sm[t](...s);
} catch (t) {
console.error(t);
}
Af = !1;
}
}
const P0 = console.error, O0 = function(...s) {
P0.apply(console, s), qS(s), jn(2, s), om(...s);
};
function HS(s) {
Dc = !s, s ? console.error = O0 : console.error = P0;
}
function cL(s) {
return HS(s);
}
function GS() {
Dc || (C0 && console.warn("Patch console", window.location.hostname), console.error = O0, window.addEventListener("error", (s) => {
if (!s)
return;
const t = s.error;
if (t === void 0) {
ui() && console.warn("Received unknown error", s, s.target);
return;
}
jn(2, t, s.filename, s.lineno), om(s);
}, !0), window.addEventListener("unhandledrejection", (s) => {
Dc || s && (s.reason ? jn(2, s.reason.message, s.reason.stack) : jn(2, "unhandled rejection"), om(s));
}));
}
let M0 = 0;
function om(...s) {
M0 += 1, VS(...s);
}
function qS(s) {
if (Array.isArray(s))
for (let t = 0; t < s.length; t++) {
const e = s[t];
typeof e == "string" && e.startsWith("THREE.PropertyBinding: Trying to update node for track:") && (s[t] = "Some animated objects couldn't be found: see console for details");
}
}
function jn(s, t, e, i) {
if (Dc)
return;
const n = pe.Current, o = (n == null ? void 0 : n.domElement) ?? document.querySelector("needle-engine");
if (o) {
if (Array.isArray(t)) {
let a = "";
for (let l = 0; l < t.length; l++) {
let c = t[l];
c instanceof Error && (c = c.message), typeof c != "object" && (l > 0 && (a += " "), a += c);
}
t = a;
}
!t || t.length <= 0 || XS(s, o, t);
}
}
const ac = /* @__PURE__ */ new Map();
function XS(s, t, e) {
if (e == null)
return;
const i = YS(t);
if (i.childElementCount >= 20) {
const l = i.lastElementChild;
t_(l);
}
e.length > 400 && (e = e.substring(0, 400) + "...");
const n = e;
if (ac.has(n))
return;
const o = KS(s, e);
i.prepend(o);
const a = () => {
ac.delete(n), t_(o);
};
ac.set(n, a), setTimeout(a, 1e4);
}
function hL() {
C0 && console.log("Clearing messages");
for (const s of ac.values())
s == null || s.call(s);
ac.clear();
}
const QS = `
@import url('https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap');
div[data-needle_engine_debug_overlay] {
font-family: 'Roboto Flex', sans-serif;
font-weight: 400;
font-size: 16px;
}
div[data-needle_engine_debug_overlay] strong {
font-weight: 700;
}
div[data-needle_engine_debug_overlay] a {
color: white;
text-decoration: none;
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}
div[data-needle_engine_debug_overlay] a:hover {
text-decoration: none;
border: none;
}
div[data-needle_engine_debug_overlay] .log strong {
color: rgba(200,200,200,.9);
}
div[data-needle_engine_debug_overlay] .warn strong {
color: rgba(255,255,230, 1);
}
div[data-needle_engine_debug_overlay] .error strong {
color: rgba(255,100,120, 1);
}
`;
function YS(s) {
globalThis[Tf] || (globalThis[Tf] = /* @__PURE__ */ new Map());
const t = globalThis[Tf];
if (t.has(s))
return t.get(s);
{
const e = document.createElement("div");
t.set(s, e), e.setAttribute("data-needle_engine_debug_overlay", ""), e.classList.add("debug-container"), e.style.cssText = `
position: absolute;
top: 0;
right: 5px;
padding-top: 0px;
max-width: 70%;
max-height: calc(100% - 5px);
z-index: 9999999999;
pointer-events: scroll;
display: flex;
align-items: end;
flex-direction: column;
color: white;
overflow: auto;
word-break: break-word;
`, s.shadowRoot ? s.shadowRoot.appendChild(e) : s.appendChild(e);
const i = document.createElement("style");
return i.innerHTML = QS, e.appendChild(i), e;
}
}
const R0 = Symbol("logtype"), Fd = /* @__PURE__ */ new Map();
function t_(s) {
s.remove();
const t = s[R0], e = Fd.get(t) ?? [];
e.push(s), Fd.set(t, e);
}
function KS(s, t) {
if (Fd.has(s)) {
const i = Fd.get(s);
if (i.length > 0) {
const n = i.pop();
return n.innerHTML = t, n;
}
}
const e = document.createElement("div");
switch (e.setAttribute("data-id", "__needle_engine_debug_overlay"), e.style.marginRight = "5px", e.style.padding = ".5em", e.style.backgroundColor = "rgba(0,0,0,.9)", e.style.marginTop = "5px", e.style.marginBottom = "3px", e.style.borderRadius = "8px", e.style.pointerEvents = "all", e.style.userSelect = "text", e.style.maxWidth = "250px", e.style.whiteSpace = "pre-wrap", e.style["backdrop-filter"] = "blur(10px)", e.style["-webkit-backdrop-filter"] = "blur(10px)", e.style.backgroundColor = "rgba(20,20,20,.8)", e.style.boxShadow = "inset 0 0 80px rgba(0,0,0,.2), 0 0 5px rgba(0,0,0,.2)", e.style.border = "1px solid rgba(160,160,160,.2)", e[R0] = s, s) {
case 0:
e.classList.add("log"), e.style.color = "rgba(200,200,200,.7)", e.style.backgroundColor = "rgba(40,40,40,.7)";
break;
case 1:
e.classList.add("warn"), e.style.color = "rgb(255, 255, 150)", e.style.backgroundColor = "rgba(50,50,20,.8)";
break;
case 2:
e.classList.add("error"), e.style.color = "rgb(255, 50, 50", e.style.backgroundColor = "rgba(50,20,20,.8)";
break;
}
return e.title = "Open the browser console (F12) for more information", e.innerHTML = t, e;
}
class ZS {
constructor() {
r(this, "Rad2Deg", 180 / Math.PI);
r(this, "Deg2Rad", Math.PI / 180);
r(this, "Epsilon", 1e-5);
}
random(t, e) {
return Array.isArray(t) ? t.length <= 0 ? null : t[Math.floor(Math.random() * t.length)] : t !== void 0 && e !== void 0 ? Math.random() * (e - t) + t : Math.random();
}
randomVector3(t, e = 0, i = 1) {
t.x = this.random(e, i), t.y = this.random(e, i), t.z = this.random(e, i);
}
clamp(t, e, i) {
return t < e ? e : t > i ? i : t;
}
clamp01(t) {
return this.clamp(t, 0, 1);
}
/**
* Linear interpolate
*/
lerp(t, e, i) {
return i = i < 0 ? 0 : i, i = i > 1 ? 1 : i, t + (e - t) * i;
}
/**
*
*/
inverseLerp(t, e, i) {
return (i - t) / (e - t);
}
/**
* Remaps a value from one range to another.
* @param value The value to remap.
* @param min1 The minimum value of the current range.
* @param max1 The maximum value of the current range.
* @param min2 The minimum value of the target range.
* @param max2 The maximum value of the target range.
*/
remap(t, e, i, n, o) {
return n + (o - n) * (t - e) / (i - e);
}
moveTowards(t, e, i) {
return t += i, (i < 0 && t < e || i > 0 && t > e) && (t = e), t;
}
/**
* Converts radians to degrees
*/
toDegrees(t) {
return t * 180 / Math.PI;
}
/**
* Converts degrees to radians
*/
toRadians(t) {
return t * Math.PI / 180;
}
tan(t) {
return Math.tan(t);
}
gammaToLinear(t) {
return Math.pow(t, 2.2);
}
linearToGamma(t) {
return Math.pow(t, 1 / 2.2);
}
approximately(t, e, i = Number.EPSILON) {
for (const n of JS) {
const o = t[n], a = e[n];
if (o === void 0 || a === void 0)
break;
if (Math.abs(o - a) > i)
return !1;
}
return !0;
}
easeInOutCubic(t) {
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
}
}
const JS = ["x", "y", "z", "w"], $ = new ZS();
class i_ {
constructor(t) {
r(this, "y");
r(this, "s");
r(this, "alpha", 0);
this.setAlpha(t), this.y = null, this.s = null;
}
setAlpha(t) {
if (t <= 0 || t > 1)
throw new Error();
this.alpha = t;
}
filter(t, e) {
e && this.setAlpha(e);
let i;
return this.y ? i = this.alpha * t + (1 - this.alpha) * this.s : i = t, this.y = t, this.s = i, i;
}
lastValue() {
return this.y;
}
reset(t) {
this.y = t, this.s = t;
}
}
class Ef {
/** Create a new OneEuroFilter
* @param freq - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
* @param minCutOff - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
* @param beta - Parameter to reduce latency (> 0). Higher values make the filter react faster to changes.
* @param dCutOff - Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
*/
constructor(t, e = 1, i = 0, n = 1) {
/**
* An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
*/
r(this, "freq");
/**
* Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
*/
r(this, "minCutOff");
/**
* Parameter to reduce latency (> 0). Higher values make the filter react faster to changes.
*/
r(this, "beta");
/**
* Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
*/
r(this, "dCutOff");
/**
* The low-pass filter for the signal.
*/
r(this, "x");
/**
* The low-pass filter for the derivates.
*/
r(this, "dx");
/**
* The last time the filter was called.
*/
r(this, "lasttime");
if (t <= 0 || e <= 0 || n <= 0)
throw new Error();
this.freq = t, this.minCutOff = e, this.beta = i, this.dCutOff = n, this.x = new i_(this.alpha(this.minCutOff)), this.dx = new i_(this.alpha(this.dCutOff)), this.lasttime = null;
}
alpha(t) {
const e = 1 / this.freq;
return 1 / (1 + 1 / (2 * Math.PI * t) / e);
}
/** Filter your value: call with your value and the current timestamp (e.g. from this.context.time.time) */
filter(t, e = null) {
this.lasttime && e && (this.freq = 1 / (e - this.lasttime)), this.lasttime = e;
const i = this.x.lastValue(), n = i ? (t - i) * this.freq : 0, o = this.dx.filter(n, this.alpha(this.dCutOff)), a = this.minCutOff + this.beta * Math.abs(o);
return this.x.filter(t, this.alpha(a));
}
reset(t) {
t != null && this.x.reset(t), this.x.alpha = this.alpha(this.minCutOff), this.dx.alpha = this.alpha(this.dCutOff), this.lasttime = null;
}
}
class k0 {
/** Create a new OneEuroFilter
* @param freq - An estimate of the frequency in Hz of the signal (> 0), if timestamps are not available.
* @param minCutOff - Min cutoff frequency in Hz (> 0). Lower values allow to remove more jitter.
* @param beta - Parameter to reduce latency (> 0). Higher values make the filter react faster to changes.
* @param dCutOff - Used to filter the derivates. 1 Hz by default. Change this parameter if you know what you are doing.
*/
constructor(t, e = 1, i = 0, n = 1) {
r(this, "x");
r(this, "y");
r(this, "z");
this.x = new Ef(t, e, i, n), this.y = new Ef(t, e, i, n), this.z = new Ef(t, e, i, n);
}
filter(t, e, i = null) {
e.x = this.x.filter(t.x, i), e.y = this.y.filter(t.y, i), e.z = this.z.filter(t.z, i);
}
reset(t) {
this.x.reset(t == null ? void 0 : t.x), this.y.reset(t == null ? void 0 : t.y), this.z.reset(t == null ? void 0 : t.z);
}
}
const ud = "needle:cameraController";
function eC(s) {
return s[ud];
}
function n_(s, t, e) {
e ? s[ud] = t : s[ud] === t && (s[ud] = null);
}
const rm = "needle:autofit";
function tC(s) {
return s[rm] === void 0 ? !0 : s[rm] !== !1;
}
function am(s, t) {
s[rm] = t;
}
function dL(s, t, e) {
const i = s.length(), n = t.length(), o = $.lerp(i, n, e);
return s.lerp(t, e).normalize().multiplyScalar(o);
}
const If = new W(), T0 = new W().setFromAxisAngle(new v(0, 1, 0), Math.PI);
function uL(s, t) {
s.lookAt(t), s.quaternion.multiply(T0);
}
function Au(s, t, e = !0, i = !1) {
if (s === t)
return;
If.copy(s.quaternion);
const n = ie(t), o = ie(s);
if (i) {
if (vn(s, Ce(t)), e) {
const a = o.y, l = o.sub(hC(s));
l.y = a, s.lookAt(l), s.quaternion.multiply(T0);
}
Number.isNaN(s.quaternion.x) && s.quaternion.copy(If);
return;
}
e && (n.y = o.y), s.lookAt(n), Number.isNaN(s.quaternion.x) && s.quaternion.copy(If);
}
function fL(s, t, e, i = 1) {
if (e) {
const n = G(0, 0, 0), o = t.x / window.innerWidth * 2 - 1, a = -(t.y / window.innerHeight) * 2 + 1;
n.set(
o,
a,
0
), n.unproject(e);
const l = e.worldPosition, c = s.worldPosition.distanceTo(l), h = n.sub(l);
h.multiplyScalar(i * 3.6 * c);
const d = e.worldPosition.add(h);
return s.lookAt(d), d;
}
return null;
}
const iC = new tn(() => new v(), 100);
function G(s, t, e) {
const i = iC.get();
return i.set(0, 0, 0), s instanceof v ? i.copy(s) : Array.isArray(s) ? i.set(s[0], s[1], s[2]) : s instanceof DOMPointReadOnly ? i.set(s.x, s.y, s.z) : typeof s == "number" ? (i.x = s, i.y = t !== void 0 ? t : i.x, i.z = e !== void 0 ? e : i.x) : typeof s == "object" && (i.x = s.x, i.y = s.y, i.z = s.z), i;
}
const nC = new tn(() => new ce(), 30);
function sC(s) {
const t = nC.get();
return s ? t.copy(s) : t.set(0, 0, 0), t;
}
const oC = new tn(() => new W(), 100);
function An(s) {
const t = oC.get();
return t.identity(), s instanceof W ? t.copy(s) : s instanceof DOMPointReadOnly && t.set(s.x, s.y, s.z, s.w), t;
}
const _g = new tn(() => new v(), 100), s_ = Symbol("lastMatrixWorldUpdateKey");
function ie(s, t = null, e = !0) {
const i = t ?? _g.get();
return s ? s.parent ? (e && s.updateWorldMatrix(!0, !1), s.matrixWorldNeedsUpdate && s[s_] !== Date.now() && (s[s_] = Date.now(), s.updateMatrixWorld()), i.setFromMatrixPosition(s.matrixWorld), i) : i.copy(s.position) : i.set(0, 0, 0);
}
function yt(s, t) {
if (!s)
return s;
const e = _g.get();
return t !== e && e.copy(t), ((s == null ? void 0 : s.parent) ?? s).worldToLocal(e), s.position.set(e.x, e.y, e.z), s;
}
function Fa(s, t, e, i) {
const n = _g.get();
return n.set(t, e, i), yt(s, n), s;
}
const zd = new tn(() => new W(), 100), dr = new W(), Lf = new W();
function Ce(s, t = null) {
if (!s)
return zd.get().identity();
const e = t ?? zd.get();
return s.parent ? (s.getWorldQuaternion(e), e) : e.copy(s.quaternion);
}
function vn(s, t) {
if (!s)
return;
t !== dr && dr.copy(t);
const e = dr, i = s == null ? void 0 : s.parent;
i == null || i.getWorldQuaternion(Lf), Lf.invert();
const n = Lf.multiply(e);
s.quaternion.set(n.x, n.y, n.z, n.w);
}
function A0(s, t, e, i, n) {
dr.set(t, e, i, n), vn(s, dr);
}
const rC = new tn(() => new v(), 100), aC = new v();
function Ye(s, t = null) {
return t || (t = rC.get()), s ? s.parent ? (s.getWorldScale(t), t) : t.copy(s.scale) : t.set(0, 0, 0);
}
function jc(s, t) {
if (!s)
return;
if (!s.parent) {
s.scale.copy(t);
return;
}
const e = aC;
s.parent.getWorldScale(e), s.scale.copy(t), s.scale.divide(e);
}
const lC = new v(), o_ = new W();
function pL(s) {
return Ce(s, o_), lC.set(0, 0, 1).applyQuaternion(o_);
}
const cC = new tn(() => new v(), 100), r_ = new W();
function hC(s, t) {
return t || (t = cC.get().set(0, 0, 1)), Ce(s, r_), t.applyQuaternion(r_);
}
const a_ = new jt(), l_ = new jt(), dC = new v();
function E0(s) {
const t = zd.get();
return s.getWorldQuaternion(t), l_.setFromQuaternion(t), l_;
}
function I0(s, t) {
const e = zd.get();
vn(s, e.setFromEuler(t));
}
function Eu(s) {
const t = E0(s), e = dC;
return e.set(t.x, t.y, t.z), e.x = $.toDegrees(e.x), e.y = $.toDegrees(e.y), e.z = $.toDegrees(e.z), e;
}
function L0(s, t) {
Iu(s, t.x, t.y, t.z, !0);
}
function Iu(s, t, e, i, n = !0) {
n && (t = $.toRadians(t), e = $.toRadians(e), i = $.toRadians(i)), a_.set(t, e, i), dr.setFromEuler(a_), vn(s, dr);
}
function lm(s, t = !0) {
s && (t ? function e(i) {
console.groupCollapsed((i.name ? i.name : "(no name : " + i.type + ")") + " %o", i), i.children.forEach(e), console.groupEnd();
}(s) : s.traverse(function(e) {
for (var i = "|___", n = e; n.parent !== null; )
i = " " + i, n = n.parent;
console.log(i + e.name + " <" + e.type + ">");
}));
}
function mL(s) {
let t = (s == null ? void 0 : s.name) || "";
if (!s)
return t;
let e = s.parent;
for (; e; )
t = e.name + "/" + t, e = e.parent;
return t;
}
function uC(s) {
if (s) {
const t = s;
return t.blendMode !== void 0 && t.clampWhenFinished !== void 0 && t.enabled !== void 0 && t.fadeIn !== void 0 && t.getClip !== void 0;
}
return !1;
}
class pn {
/**
* Create a blit material for copying textures
*/
static createBlitMaterial(t) {
return new bn({
uniforms: { map: new fo(null) },
vertexShader: this.vertex,
fragmentShader: t
});
}
/**
* Copy a texture to a new texture
* @param texture the texture to copy
* @param blitMaterial the material to use for copying (optional)
* @returns the newly created, copied texture
*/
static copyTexture(t, e) {
this.blitMaterial || (this.blitMaterial = new bn({
uniforms: { map: new fo(null) },
vertexShader: this.vertex,
fragmentShader: this.fragment
}));
const i = e || this.blitMaterial;
i.uniforms.map.value = t, i.needsUpdate = !0, i.uniformsNeedUpdate = !0;
const n = i.vertexShader;
i.vertexShader = this.vertex, this.mesh || (this.mesh = new q(this.planeGeometry, this.blitMaterial));
const o = this.mesh;
o.material = i, o.frustumCulled = !1, this.scene.children.length = 0, this.scene.add(o), this.renderer || (this.renderer = new Rr({ antialias: !1 })), this.renderer.setSize(t.image.width, t.image.height), this.renderer.clear(), this.renderer.render(this.scene, this.perspectiveCam);
const a = new Fe(this.renderer.domElement);
return a.name = "Copy", a.needsUpdate = !0, i.vertexShader = n, a;
}
// static blit(src: Texture, target: Texture, blitMaterial?: ShaderMaterial) {
// let material = blitMaterial ?? this.blipMaterial;
// material.uniforms.map.value = src;
// this.mesh.material = material;
// this.mesh.frustumCulled = false;
// this.mesh.matrix.identity();
// this.scene.children.length = 0;
// this.scene.add(this.mesh);
// this.renderer.setSize(src.image.width, src.image.height);
// this.renderer.clear();
// this.renderer.render(this.scene, this.perspectiveCam);
// return new Texture(this.renderer.domElement);
// }
/**
* Copy a texture to a HTMLCanvasElement
* @param texture the texture convert
* @param force if true the texture will be copied to a new texture before converting
* @returns the HTMLCanvasElement with the texture or null if the texture could not be copied
*/
static textureToCanvas(t, e = !1) {
if (!t)
return null;
(e === !0 || t.isCompressedTexture === !0) && (t = fC(t));
const i = t.image;
if (pC(i)) {
const n = document.createElement("canvas");
n.width = i.width, n.height = i.height;
const o = n.getContext("2d");
return o ? (o.drawImage(i, 0, 0, i.width, i.height, 0, 0, n.width, n.height), n) : (console.error("Failed getting canvas 2d context"), null);
}
return null;
}
}
r(pn, "planeGeometry", new Gn(2, 2, 1, 1)), r(pn, "renderer"), r(pn, "perspectiveCam", new be()), r(pn, "scene", new Mi()), r(pn, "vertex", `
varying vec2 vUv;
void main(){
vUv = uv;
gl_Position = vec4(position.xy * 1.0,0.,.999999);
}`), r(pn, "fragment", `
uniform sampler2D map;
varying vec2 vUv;
void main(){
vec2 uv = vUv;
uv.y = 1.0 - uv.y;
gl_FragColor = texture2D( map, uv);
// gl_FragColor = vec4(uv.xy, 0, 1);
}`), r(pn, "blitMaterial"), r(pn, "mesh");
function fC(s) {
return pn.copyTexture(s);
}
function gL(s, t = !1) {
return pn.textureToCanvas(s, t);
}
function pC(s) {
return typeof HTMLImageElement < "u" && s instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && s instanceof HTMLCanvasElement || typeof OffscreenCanvas < "u" && s instanceof OffscreenCanvas || typeof ImageBitmap < "u" && s instanceof ImageBitmap;
}
function mC(s) {
const t = s.type;
return t === "Mesh" || t === "SkinnedMesh";
}
function D0(s, t) {
t ? s["needle:rendercustomshadow"] = !0 : s["needle:rendercustomshadow"] = !1;
}
function gC(s) {
if (s) {
if (s["needle:rendercustomshadow"] === !0)
return !0;
if (s["needle:rendercustomshadow"] == null)
return !0;
}
return !1;
}
function ki(s, t = void 0, e = void 0, i = void 0) {
const n = i || new Pi();
n.makeEmpty();
const o = [];
function a(c) {
let h = !0;
if (c.visible && tC(c) !== !1 && !(c.type === "TransformControlsGizmo" || c.type === "TransformControlsPlane")) {
if (c instanceof e0 && (h = !1), c instanceof og && (h = !1), c instanceof Ba && (h = !1), c.isGizmo === !0 && (h = !1), c.material instanceof Jb && (h = !1), mC(c) || (h = !1), e && c.layers.test(e) === !1 && (h = !1), h) {
if (t && Array.isArray(t) && (t != null && t.includes(c)))
return;
if (typeof t == "function" && t(c) === !0)
return;
}
if (c.isUI !== !0) {
if (h) {
const d = c.children;
c.children = o;
const u = c.position, p = c.scale;
if (Number.isNaN(u.x) || Number.isNaN(u.y) || Number.isNaN(u.z)) {
console.warn(`Object "${c.name}" has NaN values in position or scale.... will ignore it`, u, p);
return;
}
n.expandByObject(c, !0), c.children = d;
}
for (const d of c.children)
a(d);
}
}
}
let l = !1;
Array.isArray(s) || (s = [s]);
for (const c of s)
c && (l = !0, c.updateMatrixWorld(), a(c));
return l || console.warn("No objects to fit camera to..."), n;
}
function yC(s, t, e) {
const i = ki([s], e == null ? void 0 : e.ignore), n = new v();
i.getSize(n);
const o = new v();
i.getCenter(o);
const a = new v();
t.getSize(a);
const l = new v();
t.getCenter(l);
const c = new v();
c.set(a.x / n.x, a.y / n.y, a.z / n.z);
const h = Math.min(c.x, c.y, c.z), d = (e == null ? void 0 : e.scale) !== !1;
if (d && jc(s, Ye(s).multiplyScalar(h)), (e == null ? void 0 : e.position) !== !1) {
const u = new v();
i.getCenter(u), u.y = i.min.y;
const p = new v();
t.getCenter(p), p.y = t.min.y;
const m = p.clone().sub(u);
d && m.multiplyScalar(h), yt(s, ie(s).add(m));
}
return {
boundsBefore: i,
scale: c
};
}
function _C(s, t) {
const e = ki([s]), i = new v();
e.getCenter(i), i.y = e.min.y;
const n = t.clone().sub(i), o = ie(s);
return yt(s, o.add(n)), {
offset: n,
bounds: e
};
}
function j0(s, t, e, i) {
if (Array.isArray(t)) {
let a = !0;
for (let l = 0; l < t.length; l++)
j0(s, t[l], l, t) || (a = !1);
return a;
}
if (t.type === "MeshStandardMaterial" || t.type === "MeshBasicMaterial")
return !1;
if (t["material:fbx"] != null)
return !0;
const n = new It();
n["material:fbx"] = t;
const o = t;
return o && (o.map ? n.color.set(1, 1, 1) : n.color.copyLinearToSRGB(o.color), n.emissive.copyLinearToSRGB(o.emissive), n.emissiveIntensity = o.emissiveIntensity, n.opacity = o.opacity, n.displacementScale = o.displacementScale, n.transparent = o.transparent, n.bumpMap = o.bumpMap, n.aoMap = o.aoMap, n.map = o.map, n.displacementMap = o.displacementMap, n.emissiveMap = o.emissiveMap, n.normalMap = o.normalMap, n.envMap = o.envMap, n.alphaMap = o.alphaMap, n.metalness = o.reflectivity, n.vertexColors = o.vertexColors, o.shininess && (n.roughness = 1 - Math.sqrt(o.shininess) / 10), n.needsUpdate = !0), e === void 0 ? s.material = n : i[e] = n, !0;
}
let kh = !1;
WS((...s) => {
var t;
z() && ((t = pe.Current) != null && t.isInXR) && (xa(!0), B0("error", ...s));
});
function xa(s) {
if (s) {
if (kh)
return;
kh = !0, vC();
} else {
if (!kh)
return;
kh = !1, wC();
}
}
const lc = {
log: void 0,
warn: void 0,
error: void 0
};
class bC {
constructor() {
r(this, "familyName", "needle-xr");
r(this, "root", null);
r(this, "context", null);
r(this, "defaultFontSize", 0.06);
r(this, "targetObject", new L());
/** this is a point in forward view of the user */
r(this, "userForwardViewPoint", new v());
r(this, "oneEuroFilter", new k0(90, 0.8));
r(this, "_lastElementRemoveTime", 0);
r(this, "onBeforeRender", () => {
var e, i;
const t = (e = this.context) == null ? void 0 : e.mainCamera;
if (this.context && t instanceof be) {
const n = this.getRoot();
Number.isNaN(n.position.x) && n.position.set(0, 0, 0), Number.isNaN(n.quaternion.x) && n.quaternion.set(0, 0, 0, 1), this.context.scene.add(this.targetObject);
const o = ((i = this.context.xr) == null ? void 0 : i.rigScale) ?? 1, a = 3.5 * o, l = t.worldForward;
l.y = 0, l.normalize().multiplyScalar(a), this.userForwardViewPoint.copy(t.worldPosition).sub(l), this.targetObject.position.distanceTo(this.userForwardViewPoint) > 2 * o && (this.targetObject.position.copy(this.userForwardViewPoint), Au(this.targetObject, t, !0, !0), this.targetObject.rotateY(Math.PI)), this.oneEuroFilter.filter(this.targetObject.position, n.position, this.context.time.time);
const h = this.context.time.deltaTime;
if (n.quaternion.slerp(this.targetObject.quaternion, h * 5), n.scale.setScalar(o), this.targetObject.removeFromParent(), this.context.scene.add(n), this.context.time.time - this._lastElementRemoveTime > 0.1) {
this._lastElementRemoveTime = this.context.time.time;
const d = Date.now();
for (let u = 0; u < this._activeTexts.length; u++) {
const p = this._activeTexts[u];
if (p instanceof Te.Text && d - p._activatedTime > 2e4) {
p.removeFromParent(), this._textBuffer.push(p), this._activeTexts.splice(u, 1);
break;
}
}
}
}
});
r(this, "textOptions", {
fontSize: this.defaultFontSize,
fontFamily: this.familyName,
padding: 0.03,
margin: 5e-3,
color: 0,
backgroundColor: 16777215,
backgroundOpacity: 0.4,
borderRadius: 0.03,
offset: 0.025
});
r(this, "_textBuffer", []);
r(this, "_activeTexts", []);
this.ensureFont();
}
onEnable() {
this.context = pe.Curr