import { i as e, r as t, t as n } from "./rafScheduler-CgXFF8Cr.js";
import { t as r } from "./messageBus-D2dmTOBd.js";
import { n as i, t as a } from "./defaults-CrWOF-m4.js";
import { a as o, i as s, n as c, r as l, t as u } from "./renderables-8UouVdKi.js";
import { a as d, c as f, f as p, i as m, l as h, n as g, o as _, r as v, s as y, t as b } from "./r3fZUpSceneChrome-DIN90jzU.js";
import x, { Suspense as S, useCallback as C, useEffect as w, useMemo as T, useRef as E, useState as D } from "react";
import { Fragment as O, jsx as k, jsxs as A } from "react/jsx-runtime";
import { Canvas as j, useThree as M } from "@react-three/fiber";
import * as N from "three";
import "three/examples/jsm/controls/OrbitControls.js";
//#region src/shared/utils/pointCloud.ts
function ee(e) {
	if (!e || typeof e != "object") return !1;
	let t = e;
	return typeof t.name == "string" && typeof t.offset == "number";
}
function te(e) {
	return e instanceof Uint8Array;
}
function ne(e) {
	if (!e || typeof e != "object") return null;
	let { fields: t, data: n, point_step: r, width: i, height: a } = e;
	if (!Array.isArray(t) || !te(n) || typeof r != "number" || typeof i != "number" || typeof a != "number") return null;
	let o = i * a, s = new Float32Array(o * 3), c = t.filter(ee), l = c.find((e) => e.name === "x"), u = c.find((e) => e.name === "y"), d = c.find((e) => e.name === "z");
	if (!l || !u || !d) return null;
	let f = new DataView(n.buffer, n.byteOffset, n.byteLength);
	for (let e = 0; e < o; e++) {
		let t = e * r;
		s[e * 3] = f.getFloat32(t + l.offset, !0), s[e * 3 + 1] = f.getFloat32(t + u.offset, !0), s[e * 3 + 2] = f.getFloat32(t + d.offset, !0);
	}
	return { positions: s };
}
//#endregion
//#region src/shared/bvh/coordinates.ts
function P(e, t) {
	let [n, r, i] = e;
	if (n *= t.scale, r *= t.scale, i *= t.scale, t.yUpToZUp) {
		let e = -i, t = r;
		r = e, i = t;
	}
	return t.flipY && (r = -r), [
		n,
		r,
		i
	];
}
//#endregion
//#region src/features/panels/ThreeD/ThreeDPanel.tsx
var re = 5, F = 8;
function ie(e, t) {
	return BigInt(e) * 1000000000n + BigInt(t);
}
var I = new N.Mesh(new N.BoxGeometry(1, 1, 1)), L = new N.Box3(), ae = new N.BoxGeometry(1, 1, 1), R = new N.SphereGeometry(.5, 16, 12);
function oe(e) {
	if (e.length === 0) return null;
	let t = new N.Box3(), n = !1, r = new N.Vector3(), i = new N.Vector3(), a = new N.Quaternion(), o = new N.Vector3();
	for (let s of e) {
		if (s.kind === "line") {
			for (let e of s.points) o.set(e[0], e[1], e[2]), n ? t.expandByPoint(o) : (t.setFromCenterAndSize(o, new N.Vector3(1e-4, 1e-4, 1e-4)), n = !0);
			continue;
		}
		if (s.kind === "orientedBox") {
			I.position.set(s.position[0], s.position[1], s.position[2]), I.scale.set(s.scale[0], s.scale[1], s.scale[2]), a.set(s.quaternion[0], s.quaternion[1], s.quaternion[2], s.quaternion[3]), I.quaternion.copy(a), I.updateMatrixWorld(!0), L.setFromObject(I), n ? t.union(L) : (t.copy(L), n = !0);
			continue;
		}
		r.set(s.position[0], s.position[1], s.position[2]), i.set(s.scale[0], s.scale[1], s.scale[2]), L.setFromCenterAndSize(r, i), n ? t.union(L) : (t.copy(L), n = !0);
	}
	return n ? (t.expandByScalar(.02), t) : null;
}
function z(e) {
	return e.map((e) => e.toFixed(3)).join(",");
}
function B(e, t) {
	let n = t[0], r = t[t.length - 1], i = [String(e), String(t.length)], a = t.find((e) => typeof e.frameIndex == "number")?.frameIndex;
	typeof a == "number" && i.push(String(a));
	for (let e of [n, r]) if (e) if (i.push(e.key), e.kind === "line") {
		let t = e.points[0], n = e.points[e.points.length - 1];
		t && i.push(z(t)), n && i.push(z(n));
	} else i.push(z(e.position));
	return i.join("|");
}
function se(e, t) {
	return !e || t.size > e.size ? !0 : Math.abs(t.position[0] - e.position[0]) > .05 || Math.abs(t.position[1] - e.position[1]) > .05 || Math.abs(t.position[2] - e.position[2]) > .05;
}
var V = {
	clearTracks: !0,
	clearMarkerPrimitives: !0,
	clearSkeletonPrimitives: !1,
	clearLaserScanCloud: !0,
	clearOccupancyCloud: !0
}, ce = ({ bvhTopic: e, skeletonPrimitives: t, resetVersion: n, onGroundLayout: r }) => {
	let { camera: i, controls: a, invalidate: o } = M(), s = E(null), c = E(null), l = E(null), u = E(null), d = E(0), f = E(r);
	return w(() => {
		f.current = r;
	}, [r]), w(() => {
		e || (s.current = null, c.current = null, l.current = null, u.current = null, d.current = 0);
	}, [e]), w(() => {
		c.current = null, l.current = null, u.current = null, d.current = 0, s.current = null;
	}, [n]), w(() => {
		if (!e) return;
		let r = t.filter((e) => e.key.startsWith("bvh:"));
		if (r.length === 0) return;
		let p = B(n, r);
		if (u.current === p) return;
		let m = s.current !== n;
		if (!m && (d.current += 1, d.current % F !== 0)) return;
		u.current = p;
		let h = oe(r);
		if (!h || h.isEmpty()) return;
		let g = c.current;
		g ? g.union(h) : c.current = h.clone();
		let _ = c.current, v = new N.Vector3(), b = new N.Vector3();
		_.getCenter(v), _.getSize(b);
		let x = !1;
		if (m) {
			s.current = n;
			let e = i, t = Math.max(b.x, b.y, 2), r = Math.max(20, Math.ceil(t * 1.6)), o = new N.Vector3(v.x, v.y, 0);
			y(e, o, r);
			let c = a;
			c && (c.target.copy(o), c.update()), x = !0;
		}
		let S = Math.max(b.x, b.y, 2), C = {
			size: Math.max(20, Math.ceil(S * 1.6)),
			divisions: 10,
			position: [
				v.x,
				v.y,
				0
			]
		};
		se(l.current, C) && (l.current = C, f.current?.(C), x = !0), x && o();
	}, [
		e,
		t,
		n,
		i,
		a,
		o
	]), null;
}, le = ({ colors: e, size: t = 20, divisions: n = 10, position: r = [
	0,
	0,
	0
] }) => /* @__PURE__ */ k("group", {
	position: r,
	children: /* @__PURE__ */ k("gridHelper", {
		rotation: [
			Math.PI / 2,
			0,
			0
		],
		args: [
			t,
			n,
			e.gridPrimary,
			e.gridSecondary
		]
	})
}), ue = ({ data: e, color: t, size: n }) => {
	let r = E(null), [i, a] = D(null);
	return w(() => {
		let t = new N.BufferGeometry();
		t.setAttribute("position", new N.BufferAttribute(e.positions, 3));
		let n = r.current;
		return r.current = t, a(t), n && n.dispose(), () => {
			r.current === t && (r.current = null, t.dispose());
		};
	}, [e]), i ? /* @__PURE__ */ k("points", {
		geometry: i,
		children: /* @__PURE__ */ k("pointsMaterial", {
			size: n,
			color: t,
			sizeAttenuation: !0
		})
	}) : null;
};
function de(e) {
	let { material: t } = e;
	if (Array.isArray(t)) for (let e of t) e.dispose();
	else t.dispose();
}
var fe = ({ track: e }) => {
	let t = T(() => {
		let t = new N.BufferGeometry();
		return t.setAttribute("position", new N.Float32BufferAttribute(e.points.flat(), 3)), new N.Line(t, new N.LineBasicMaterial({ color: e.color }));
	}, [e.points, e.color]);
	if (w(() => () => {
		t.geometry.dispose(), de(t);
	}, [t]), e.points.length === 0) return null;
	if (e.mode === "pose") {
		let t = e.points[e.points.length - 1];
		return /* @__PURE__ */ A("mesh", {
			position: t,
			children: [/* @__PURE__ */ k("sphereGeometry", { args: [
				.08,
				16,
				12
			] }), /* @__PURE__ */ k("meshStandardMaterial", { color: e.color })]
		});
	}
	return /* @__PURE__ */ k("primitive", { object: t });
}, H = x.memo(({ primitive: e }) => {
	let t = T(() => {
		let t = new N.BufferGeometry();
		return t.setAttribute("position", new N.Float32BufferAttribute(e.points.flat(), 3)), t;
	}, [e.points]), n = T(() => new N.LineBasicMaterial({ color: e.color }), [e.color]), r = T(() => new N.Line(t, n), [t, n]);
	return w(() => () => {
		t.dispose();
	}, [t]), w(() => () => n.dispose(), [n]), /* @__PURE__ */ k("primitive", { object: r });
});
H.displayName = "MarkerLinePrimitiveView";
var U = x.memo(({ primitive: e }) => {
	let t = T(() => new N.MeshStandardMaterial({
		color: e.color,
		roughness: .58,
		metalness: .04
	}), [e.color]);
	return w(() => () => t.dispose(), [t]), e.kind === "orientedBox" ? /* @__PURE__ */ k("mesh", {
		geometry: ae,
		material: t,
		position: e.position,
		scale: e.scale,
		quaternion: e.quaternion
	}) : /* @__PURE__ */ k("mesh", {
		geometry: e.kind === "cube" ? ae : R,
		material: t,
		position: e.position,
		scale: e.scale
	});
});
U.displayName = "MeshPrimitiveView";
var pe = x.memo(({ primitive: e }) => e.kind === "line" ? /* @__PURE__ */ k(H, { primitive: e }) : /* @__PURE__ */ k(U, { primitive: e }));
pe.displayName = "MarkerPrimitiveView";
function me(e, t = "#38bdf8") {
	if (!e || typeof e != "object") return t;
	let n = e, r = typeof n.r == "number" ? Math.max(0, Math.min(1, n.r)) : .22, i = typeof n.g == "number" ? Math.max(0, Math.min(1, n.g)) : .74, a = typeof n.b == "number" ? Math.max(0, Math.min(1, n.b)) : .97;
	return `rgb(${Math.round(r * 255)}, ${Math.round(i * 255)}, ${Math.round(a * 255)})`;
}
function he(e, t) {
	return typeof e == "string" || typeof e == "number" || typeof e == "bigint" ? String(e) : t;
}
function W(e) {
	if (!e || typeof e != "object") return null;
	let t = e.position;
	if (t && typeof t == "object" && typeof t.x == "number" && typeof t.y == "number") {
		let e = t;
		return [
			e.x,
			e.y,
			typeof e.z == "number" ? e.z : 0
		];
	}
	return null;
}
function ge(e, t) {
	if (!e || typeof e != "object") return [];
	let n = e, r = Array.isArray(n.markers) ? n.markers : [e], i = [];
	for (let e of r) {
		if (!e || typeof e != "object") continue;
		let n = e, r = he(n.id, String(i.length)), a = `${he(n.ns, "marker")}:${r}`, o = me(n.color, t), s = n.scale && typeof n.scale == "object" ? n.scale : {}, c = [
			typeof s.x == "number" && s.x > 0 ? s.x : .2,
			typeof s.y == "number" && s.y > 0 ? s.y : .2,
			typeof s.z == "number" && s.z > 0 ? s.z : .2
		];
		if (n.type === 4 && Array.isArray(n.points)) {
			let e = n.points.map((e) => p({ position: e })).filter((e) => e != null);
			e.length >= 2 && i.push({
				kind: "line",
				key: a,
				points: e,
				color: o
			});
			continue;
		}
		let l = W(n.pose) ?? W({ position: n.position }) ?? [
			0,
			0,
			0
		], u = n.type === 1 ? "cube" : "sphere";
		i.push({
			kind: u,
			key: a,
			position: l,
			scale: c,
			color: o
		});
	}
	return i;
}
function G(e) {
	return /Thumb|Index|Middle|Ring|Pinky|InHand/i.test(e) ? .018 : /Hand|Foot|Neck|Head/i.test(e) ? .035 : .045;
}
function K(e, t) {
	let n = e.parentIndex >= 0 ? t[e.parentIndex] : void 0;
	if (e.name === "End Site" && /^Head$/i.test(n?.name ?? "")) return;
	if (/^Head$/i.test(e.name)) return [
		.093,
		.073,
		.1
	];
	let r = G(e.name);
	return /Thumb|Index|Middle|Ring|Pinky|InHand/i.test(e.name) ? [
		r * 1.6,
		r,
		r * 1.1
	] : /Hand|Foot/i.test(e.name) ? [
		r * 1.8,
		r * 1.2,
		r * .9
	] : /Shoulder|UpLeg|Hips/i.test(e.name) ? [
		r * 2,
		r * 1.2,
		r * 1.2
	] : /Spine|Neck/i.test(e.name) ? [
		r * 1.4,
		r * 1.2,
		r * 1.8
	] : [
		r * 1.6,
		r * 1.1,
		r * 1.2
	];
}
function q(e, t) {
	let n = `${t}:${e}`;
	return /Thumb|Index|Middle|Ring|Pinky|InHand/i.test(n) ? .012 : /Hand|Foot|Neck|Head/i.test(n) ? .03 : /Spine|Hips/i.test(n) ? .07 : .045;
}
function J(e, t = "") {
	let n = `${t}:${e}`;
	return /Head|Neck/i.test(n) ? "#f8c7a3" : /Thumb|Index|Middle|Ring|Pinky|InHand/i.test(n) ? "#f6d365" : /Right.*(Shoulder|Arm|ForeArm|Hand)/i.test(n) ? "#60a5fa" : /Left.*(Shoulder|Arm|ForeArm|Hand)/i.test(n) ? "#f59e0b" : /Right.*(UpLeg|Leg|Foot)/i.test(n) ? "#f87171" : /Left.*(UpLeg|Leg|Foot)/i.test(n) ? "#34d399" : /Spine|Hips/i.test(n) ? "#a78bfa" : "#94a3b8";
}
function Y(e, t, n, r) {
	let i = new N.Vector3(...t.position), a = new N.Vector3(...n.position), o = a.clone().sub(i), s = o.length();
	if (s <= 1e-6) return;
	o.normalize();
	let c = i.add(a).multiplyScalar(.5), l = new N.Quaternion().setFromUnitVectors(_, o), u = /^Head$/i.test(t.name) && n.name === "End Site" ? Math.min(Math.max(s * .45, .08), .14) : Math.min(q(n.name, t.name), Math.max(s * .35, .006));
	return {
		kind: "orientedBox",
		key: e,
		frameIndex: r,
		position: [
			c.x,
			c.y,
			c.z
		],
		scale: [
			u,
			u,
			s
		],
		quaternion: [
			l.x,
			l.y,
			l.z,
			l.w
		],
		color: J(n.name, t.name)
	};
}
function _e(e, t) {
	if (!e || typeof e != "object") return [];
	let n = e, r = typeof n.frame_index == "number" && Number.isFinite(n.frame_index) ? n.frame_index : void 0, i = n.joints;
	if (!Array.isArray(i)) return [];
	let a = i.map((e) => {
		if (!e || typeof e != "object") return;
		let n = e, r = Number(n.x), i = Number(n.y), a = Number(n.z), o = Number(n.parent_index);
		if ([
			r,
			i,
			a,
			o
		].every((e) => Number.isFinite(e))) return {
			name: typeof n.name == "string" ? n.name : "",
			position: P([
				r,
				i,
				a
			], t),
			parentIndex: o
		};
	}).filter((e) => e != null), o = [];
	if (t.renderMode === "stick") {
		let e = /* @__PURE__ */ new Set();
		for (let t = 0; t < a.length; t++) {
			let n = a[t];
			if (!n) continue;
			if (!e.has(t)) {
				e.add(t);
				let i = K(n, a);
				i && o.push({
					kind: "cube",
					key: `bvh:joint:${t}`,
					frameIndex: r,
					position: n.position,
					scale: i,
					color: J(n.name)
				});
			}
			if (n.parentIndex < 0 || n.parentIndex >= a.length) continue;
			let i = a[n.parentIndex];
			if (!i) continue;
			let s = Y(`bvh:bone:${n.parentIndex}->${t}`, i, n, r);
			s && o.push(s);
		}
		return o;
	}
	for (let e = 0; e < a.length; e++) {
		let n = a[e];
		if (!n || n.parentIndex < 0 || n.parentIndex >= a.length) continue;
		let i = a[n.parentIndex];
		i && o.push({
			kind: "line",
			key: `bvh:line:${n.parentIndex}->${e}`,
			frameIndex: r,
			points: [i.position, n.position],
			color: t.color
		});
	}
	return o;
}
function ve(e) {
	if (!e || typeof e != "object") return null;
	let t = e;
	if (!Array.isArray(t.ranges) || typeof t.angle_min != "number" || typeof t.angle_increment != "number") return null;
	let n = [], r = t.ranges;
	for (let e = 0; e < r.length; e += 1) {
		let i = r[e];
		if (typeof i != "number" || !Number.isFinite(i) || i <= 0) continue;
		let a = t.angle_min + e * t.angle_increment;
		n.push(Math.cos(a) * i, Math.sin(a) * i, 0);
	}
	return n.length === 0 ? null : { positions: new Float32Array(n) };
}
function ye(e) {
	if (!e || typeof e != "object") return null;
	let t = e, n = t.info;
	if (!n || typeof n != "object" || !Array.isArray(t.data)) return null;
	let r = n, i = typeof r.width == "number" ? r.width : 0, a = typeof r.height == "number" ? r.height : 0, o = typeof r.resolution == "number" ? r.resolution : 0;
	if (i <= 0 || a <= 0 || o <= 0) return null;
	let s = W(r.origin) ?? [
		0,
		0,
		0
	], c = [], l = t.data;
	for (let e = 0; e < a; e += 1) for (let t = 0; t < i; t += 1) {
		let n = l[e * i + t];
		typeof n != "number" || n < 50 || c.push(s[0] + t * o, s[1] + e * o, s[2]);
	}
	return c.length === 0 ? null : { positions: new Float32Array(c) };
}
var X = /* @__PURE__ */ new Set(), Z = "https://assets.embodiflow.com/resources";
function Q(e) {
	return e.endsWith("/") ? e.slice(0, -1) : e;
}
function $(e, t) {
	return /\/resources\/?$/i.test(e) ? t.replace(/^resources\/+/i, "") : t;
}
function be(e) {
	if (/^https?:\/\//i.test(e)) return e;
	let t = window, n = Q(t.__ROSVIEW_URDF_PACKAGE_BASE__ || t.__ROS_STUDIO_URDF_PACKAGE_BASE__ || Z);
	if (e.startsWith("/")) return `${n}/${$(n, e.replace(/^\/+/, ""))}`;
	if (!e.startsWith("package://")) return e;
	let r = e.slice(10), i = r.indexOf("/"), a = i >= 0 ? r.slice(0, i) : r, o = i >= 0 ? r.slice(i + 1) : "", s = t.__ROSVIEW_URDF_PACKAGE_BASES__?.[a] ?? t.__ROS_STUDIO_URDF_PACKAGE_BASES__?.[a];
	if (s) {
		let e = Q(s);
		return o ? `${e}/${o}` : e;
	}
	return `${n}/${$(n, r)}`;
}
function xe(e, t) {
	let n = `${e}|${t}`;
	X.has(n) || (X.add(n), console.warn(`ROSView 3D: skip mesh ${e}. ${t}`));
}
var Se = 512, Ce = x.memo(({ player: e, urdf: t, jointState: r, tfMessagesRef: i, tfVersion: a, resetVersion: d, startTime: f, urdfRootScale: p, fallbackMeshColor: m, meshOutlineColor: h, onMeshLoadProgressChange: g }) => {
	let [_, v] = D(null), y = E(0), b = f ? ie(f.sec, f.nsec) : 0n, x = E(b), S = E(r), T = E(!1), O = E(!1), A = E(null), { invalidate: j } = M();
	w(() => {
		S.current = r;
	}, [r]);
	let N = C(() => {
		!_ || O.current || (O.current = !0, A.current = n(() => {
			O.current = !1, A.current = null, T.current && (T.current = !1, c(_, S.current)), u(_, x.current), j();
		}));
	}, [_, j]);
	return w(() => {
		x.current = b, N();
	}, [b, N]), w(() => () => {
		A.current?.(), A.current = null, O.current = !1;
	}, [_]), w(() => {
		let t = e.subscribeCurrentTime((e) => {
			x.current = BigInt(e.sec) * 1000000000n + BigInt(e.nsec), N();
		});
		return () => {
			t();
		};
	}, [e, N]), w(() => {
		let e = !1;
		return y.current = 0, g?.(null), (async () => {
			try {
				let n = await s(t, {
					resolveMeshUrl: be,
					warn: xe,
					fallbackMeshColor: m,
					outlineColor: h,
					onMeshLoadProgress: (t) => {
						e || g?.(t);
					}
				});
				if (e) {
					o(n);
					return;
				}
				for (let e of i.current) l(n, e), y.current += 1;
				c(n, r), u(n, x.current), v(n), g?.(null);
			} catch (e) {
				let t = e instanceof Error ? e.message : String(e);
				console.warn(`ROS View 3D: URDF parse failed. ${t}`), g?.(null);
			}
		})(), () => {
			e = !0, g?.(null), v((e) => (o(e), null));
		};
	}, [
		t,
		d,
		m,
		h,
		g
	]), w(() => {
		if (!_) return;
		let e = i.current, t = y.current, n = e.length;
		for (let r = t; r < n; r++) {
			let t = e[r];
			t && l(_, t);
		}
		t = n, t >= Se && (e.splice(0, t), t = 0), y.current = t, N();
	}, [
		_,
		i,
		a,
		N
	]), w(() => {
		_ && (T.current = !0, N());
	}, [
		_,
		r,
		N
	]), _ ? /* @__PURE__ */ k("group", {
		scale: [
			p,
			p,
			p
		],
		children: /* @__PURE__ */ k("primitive", { object: _.root })
	}) : null;
}), we = ({ player: t, panelId: n, colors: i, showGrid: a, showAxes: o, showPlaceholder: s, pointSize: c, skeleton: l, urdf: u, topicSettings: d, onMeshLoadProgressChange: f }) => {
	let [p, m] = D(null), [_, y] = D([]), [b, x] = D([]), [S, j] = D([]), [M, N] = D(null), [ee, te] = D(null), [P, F] = D(null), I = E(null), [L, ae] = D(null), R = E([]), [oe, z] = D(0), [B, se] = D(0), de = E(0n), [H, U] = D(null), me = C((e) => {
		U((t) => t && e.size <= t.size ? t : e);
	}, []), he = T(() => re * ((H?.size ?? 20) / 20), [H]), W = e((e) => e.sortedTopics), G = e((e) => e.playerState.activeData?.startTime), K = T(() => W.find((e) => e.type.includes("PointCloud2"))?.name, [W]), q = T(() => d.filter((e) => e.enabled && e.topic.length > 0), [d]), J = T(() => {
		if (u.sourceType === "topic") return u.topic && u.topic.length > 0 ? u.topic : W.find((e) => e.name.includes("robot_description"))?.name;
	}, [
		W,
		u.sourceType,
		u.topic
	]), [Y, X] = D(null);
	w(() => {
		Y && console.warn(`ROS View 3D: ${Y}`);
	}, [Y]);
	let Z = T(() => W.find((e) => e.type === "sensor_msgs/msg/JointState")?.name, [W]), Q = T(() => W.find((e) => e.type.includes("BvhSkeletonFrame"))?.name, [W]);
	w(() => {
		U(null);
	}, [B]), w(() => {
		Q || U(null);
	}, [Q]), w(() => {
		if (u.sourceType === "topic") {
			I.current && !J && (I.current = null, F(null)), X(null);
			return;
		}
		if (u.sourceType === "file") {
			let e = u.fileContent;
			e && e !== I.current ? (I.current = e, F(e)) : !e && I.current && (I.current = null, F(null)), X(null);
			return;
		}
		if (u.sourceType === "url") {
			if (!u.url) {
				I.current && (I.current = null, F(null)), X(null);
				return;
			}
			let e = new AbortController();
			return X(null), (async () => {
				try {
					let t = await fetch(u.url, { signal: e.signal });
					if (!t.ok) throw Error(`HTTP ${t.status}`);
					let n = await t.text();
					if (e.signal.aborted) return;
					n !== I.current && (I.current = n, F(n));
				} catch (t) {
					if (e.signal.aborted) return;
					X(`Failed to load URDF: ${t instanceof Error ? t.message : String(t)}`);
				}
			})(), () => e.abort();
		}
	}, [
		u.sourceType,
		u.topic,
		u.url,
		u.fileContent,
		J
	]);
	let $ = T(() => W.filter((e) => e.type.includes("TFMessage") || e.type.includes("tf2_msgs") || e.type.includes("tf/tfMessage")).map((e) => e.name), [W]);
	w(() => {
		let e = [];
		J && e.push({
			topic: J,
			subscriberId: n
		}), Z && e.push({
			topic: Z,
			subscriberId: n
		}), Q && e.push({
			topic: Q,
			subscriberId: n
		});
		for (let t of q) e.push({
			topic: t.topic,
			subscriberId: n
		});
		for (let t of $) e.push({
			topic: t,
			subscriberId: n
		});
		return e.length > 0 && t.registerSubscriptions(n, e), () => t.unregisterSubscriptions(n);
	}, [
		t,
		n,
		J,
		Z,
		Q,
		q,
		$
	]), w(() => {
		if (!K) return;
		let e = `${n}:pointcloud`;
		return t.registerHighFrequencyConsumer(e, {
			topic: K,
			lane: "pointcloud",
			mode: "latest",
			onLatestMessage: (e) => {
				let t = ne(e.message);
				t && m(t);
			}
		}), () => t.unregisterHighFrequencyConsumer(e);
	}, [
		t,
		n,
		K
	]);
	let be = T(() => new Set($), [$]), xe = T(() => new Map(q.map((e) => [e.topic, e])), [q]);
	w(() => t.subscribeCurrentTime((e) => {
		let t = ie(e.sec, e.nsec), n = de.current, r = G ? ie(G.sec, G.nsec) : void 0, i = r != null && t <= r + 5000000n && n > t, a = n > t + 5000000n;
		(i || a) && (R.current = [], z(0), V.clearTracks && y([]), V.clearMarkerPrimitives && x([]), V.clearSkeletonPrimitives && j([]), V.clearLaserScanCloud && N(null), V.clearOccupancyCloud && te(null), se((e) => e + 1)), de.current = t;
	}), [t, G]);
	let Se = C(() => {
		let e = r.getSubscriberMessages(n);
		if (!e || e.length === 0) return;
		let t, i, a = 0, o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c, u, d, f = R.current;
		for (let n of e) {
			let e = n.message, r = typeof e == "object" && e ? e : null;
			if (n.topic === J) {
				if (!r) continue;
				typeof r.data == "string" && (t = r.data);
			} else if (n.topic === Z) {
				if (!r) continue;
				let e = r.name, t = r.position;
				Array.isArray(e) && Array.isArray(t) && e.every((e) => typeof e == "string") && (i = {
					name: e,
					position: t
				});
			} else if (n.topic === Q) l.enabled && (d = _e(e, l));
			else if (be.has(n.topic)) {
				if (!r) continue;
				Array.isArray(r.transforms) && (f.push(e), a++);
			} else {
				let t = xe.get(n.topic);
				if (!t) continue;
				let i = t.renderMode;
				if (i === "pose" || i === "path") {
					let r = h(e);
					r.length > 0 && o.set(n.topic, {
						topic: n.topic,
						color: t.color,
						points: r,
						mode: i
					});
					continue;
				}
				if (i === "skeleton") {
					d = _e(e, {
						...l,
						color: t.color || l.color
					});
					continue;
				}
				if (i === "marker" || i === "auto" && r && (Array.isArray(r.markers) || typeof r.type == "number")) {
					let n = ge(e, t.color);
					for (let e of n) s.set(e.key, e);
					continue;
				}
				if (i === "laserScan" || i === "auto" && r && Array.isArray(r.ranges) && typeof r.angle_increment == "number") {
					let t = ve(e);
					t && (c = t);
					continue;
				}
				if (i === "depth" || i === "auto" && r && Array.isArray(r.data) && r.info && typeof r.info == "object") {
					let t = ye(e);
					t && (u = t);
				}
			}
		}
		t !== void 0 && t !== I.current && (I.current = t, F(t)), i !== void 0 && ae(i), o.size > 0 && y((e) => {
			let t = new Map(e.map((e) => [e.topic, e]));
			for (let [e, n] of o) t.set(e, n);
			return Array.from(t.values());
		}), s.size > 0 && x((e) => {
			let t = new Map(e.map((e) => [e.key, e]));
			for (let [e, n] of s) t.set(e, n);
			return Array.from(t.values());
		}), d && j(d), c && N(c), u && te(u), a > 0 && z((e) => e + 1);
	}, [
		n,
		J,
		Z,
		Q,
		l,
		be,
		xe
	]);
	return w(() => {
		let e = r.subscribeToMessages(n, Se);
		return Se(), e;
	}, [n, Se]), /* @__PURE__ */ A(O, { children: [
		/* @__PURE__ */ k(g, { background: i.sceneBackground }),
		/* @__PURE__ */ k(v, {}),
		/* @__PURE__ */ k(ce, {
			bvhTopic: Q,
			skeletonPrimitives: S,
			resetVersion: B,
			onGroundLayout: me
		}),
		/* @__PURE__ */ k("ambientLight", { intensity: i.ambientLightIntensity }),
		/* @__PURE__ */ k("hemisphereLight", { args: [
			"#ffffff",
			"#6b7280",
			i.hemisphereLightIntensity
		] }),
		/* @__PURE__ */ k("directionalLight", {
			position: [
				6,
				-4,
				8
			],
			intensity: i.keyLightIntensity
		}),
		/* @__PURE__ */ k("directionalLight", {
			position: [
				-6,
				4,
				5
			],
			intensity: i.fillLightIntensity
		}),
		/* @__PURE__ */ k("directionalLight", {
			position: [
				-2,
				-7,
				6
			],
			intensity: i.rimLightIntensity
		}),
		a && (Q && H ? /* @__PURE__ */ k(le, {
			colors: i,
			size: H.size,
			divisions: H.divisions,
			position: H.position
		}) : /* @__PURE__ */ k(le, { colors: i })),
		o && /* @__PURE__ */ k("axesHelper", { args: [1] }),
		p && /* @__PURE__ */ k(ue, {
			data: p,
			color: i.pointCloudColor,
			size: c
		}),
		M && /* @__PURE__ */ k(ue, {
			data: M,
			color: "#f97316",
			size: .02
		}),
		ee && /* @__PURE__ */ k(ue, {
			data: ee,
			color: "#a855f7",
			size: .04
		}),
		_.map((e) => /* @__PURE__ */ k(fe, { track: e }, e.topic)),
		b.map((e) => /* @__PURE__ */ k(pe, { primitive: e }, e.key)),
		S.map((e) => /* @__PURE__ */ k(pe, { primitive: e }, e.key)),
		P && /* @__PURE__ */ k(Ce, {
			player: t,
			urdf: P,
			jointState: L,
			tfMessagesRef: R,
			tfVersion: oe,
			resetVersion: B,
			startTime: G,
			urdfRootScale: he,
			fallbackMeshColor: i.fallbackMeshColor,
			meshOutlineColor: i.meshOutlineColor,
			onMeshLoadProgressChange: f
		}),
		s && !p && !P && S.length === 0 && /* @__PURE__ */ A("mesh", {
			position: [
				0,
				0,
				.5
			],
			children: [/* @__PURE__ */ k("boxGeometry", { args: [
				1,
				1,
				1
			] }), /* @__PURE__ */ k("meshStandardMaterial", { color: i.placeholderColor })]
		})
	] });
}, Te = ({ player: e, panelId: n, showGrid: r = !0, showAxes: o = !1, showPlaceholder: s = !0, pointSize: c = .05, skeleton: l = a().skeleton, urdf: u, topicSettings: p = [] }) => {
	let { resolvedTheme: h } = t(), g = T(() => f(h), [h]), _ = u ?? i(), [v, y] = D(null), x = v !== null && v.total > 0 && v.loaded < v.total, C = x ? Math.round(v.loaded / v.total * 100) : 0;
	return /* @__PURE__ */ A("div", {
		className: `relative h-full w-full overflow-hidden [contain:strict] ${g.panelBackgroundClassName}`,
		children: [/* @__PURE__ */ k("div", {
			className: `absolute top-2 left-2 z-10 px-2 py-1 rounded text-[10px] font-mono pointer-events-none ${x ? "animate-pulse" : ""} ${g.overlayClassName}`,
			children: x ? `Loading Mesh ${v.loaded}/${v.total} (${C}%)` : "3D View"
		}), /* @__PURE__ */ k(j, {
			shadows: !0,
			frameloop: "demand",
			camera: m,
			gl: d,
			children: /* @__PURE__ */ A(S, {
				fallback: null,
				children: [/* @__PURE__ */ k(we, {
					player: e,
					panelId: n,
					colors: g,
					showGrid: r,
					showAxes: o,
					showPlaceholder: s,
					pointSize: c,
					skeleton: l,
					urdf: _,
					topicSettings: p,
					onMeshLoadProgressChange: y
				}), /* @__PURE__ */ k(b, { labelColor: g.gizmoLabelColor })]
			})
		})]
	});
};
//#endregion
export { Te as ThreeDPanel };
