Spaces:
Running
Running
3D viewer: expand button for a full-window view
Browse filesFiles changed (4)
- app.js+47-5
- index.html+2-2
- style.css+13-1
- viewer.js+27-1
60 unmodified lines61626364656636 unmodified lines103104105106107108109110111112124 unmodified lines237238239240241242243120 unmodified lines36436536636736836939 unmodified lines40941041141241341463 unmodified lines47847948048148248396 unmodified lines58058158258358458558660 unmodified linesconst TERMINAL = "M5 7l4 4-4 4M11 16h8";const EXTERNAL = "M14 5h5v5M19 5l-8 8M18 14v5H5V6h5";const FFLATE = "https://cdn.jsdelivr.net/npm/fflate@0.8.2/esm/browser.js";let DATA = null;const state = { q: "", group: null, category: null, facets: {}, sort: "name", asset: null, open: new Set() };36 unmodified lines// ---- urls ---------------------------------------------------------------------function fileUrl(a, path) { return `${HF}/datasets/${DATA.dataset}/resolve/${DATA.commit}/${a.id}/${path}`; }// 640 px studio render from this Space (transparent, works on both themes); the dataset's// 256 px package thumbnail is the fallback.function thumbUrl(a, variant) {if (a.thumb) return signed(`previews/thumbs/${a.id}.webp?v=${encodeURIComponent((a.version || "") + "-" + (DATA.thumbs_rev || ""))}`);const suffix = variant === "light" ? "_light" : variant === "transparent" ? "_transparent" : "";return fileUrl(a, `simready_usd/.thumbs/256x256/${a.id}.usd${suffix}.png`);}124 unmodified linesasync function getViewer() {if (viewer || viewerFailed) return viewer;try {const { createViewer } = await import(signed("./viewer.js?v=25"));viewer = createViewer();viewer.setTheme(theme());} catch (e) {120 unmodified lines}});// Fallback when the 3D view can't run: the package thumbnail.function imageView(a) {const variant = theme();39 unmodified linesconst pane = $("detail");document.querySelector(".layout").classList.toggle("has-detail", !!a);pane.hidden = !a;renderFoot(a);if (!a) { loadedId = null; return; }const mode = a.preview && !viewerFailed ? "3d" : "image";63 unmodified linesif (state.asset !== a.id) return;box.prepend(v.element);v.resize();let rig;if (loadedId === a.id && rigState.length) {rig = rigState.map((r) => ({ ...r }));96 unmodified lines});systemLight.addEventListener("change", () => { applyTheme(); renderGrid(); });document.addEventListener("keydown", (e) => {if (e.key === "Escape") { if (state.asset) openAsset(null); else closeSideOnPhone(); }if (e.key === "/" && document.activeElement !== $("q")) { e.preventDefault(); $("q").focus(); }});refresh();60 unmodified lines616263646566676836 unmodified lines105106107108109110111112113114115116117124 unmodified lines242243244245246247248120 unmodified lines36937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640739 unmodified lines44744844945045145245363 unmodified lines51751851952052152252352452596 unmodified lines62262362462562662762860 unmodified linesconst TERMINAL = "M5 7l4 4-4 4M11 16h8";const EXTERNAL = "M14 5h5v5M19 5l-8 8M18 14v5H5V6h5";const FFLATE = "https://cdn.jsdelivr.net/npm/fflate@0.8.2/esm/browser.js";const EXPAND = "M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5";const COLLAPSE = "M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5";let DATA = null;const state = { q: "", group: null, category: null, facets: {}, sort: "name", asset: null, open: new Set() };36 unmodified lines// ---- urls ---------------------------------------------------------------------function fileUrl(a, path) { return `${HF}/datasets/${DATA.dataset}/resolve/${DATA.commit}/${a.id}/${path}`; }// 640 px Isaac Sim renders from this Space (tools/isaac_thumbs.py), one per theme:// previews/thumbs/ on the dark card colour, previews/thumbs-light/ on a grey studio floor.// The dataset's 256 px package thumbnail is the fallback.function thumbUrl(a, variant) {const rev = `?v=${encodeURIComponent((a.version || "") + "-" + (DATA.thumbs_rev || ""))}`;if (variant === "light" && a.thumb_light) return signed(`previews/thumbs-light/${a.id}.webp${rev}`);if (a.thumb) return signed(`previews/thumbs/${a.id}.webp${rev}`);const suffix = variant === "light" ? "_light" : variant === "transparent" ? "_transparent" : "";return fileUrl(a, `simready_usd/.thumbs/256x256/${a.id}.usd${suffix}.png`);}124 unmodified linesasync function getViewer() {if (viewer || viewerFailed) return viewer;try {const { createViewer } = await import(signed("./viewer.js?v=27"));viewer = createViewer();viewer.setTheme(theme());} catch (e) {120 unmodified lines}});// Expanded 3D view: the viewer moves into a full-window layer above the whole page and back// again on close (button or Esc). It keeps its state: camera, joint positions, dots.let expanded = null; // { layer, box, view }function expandViewer(a, box, hint) {if (!viewer || expanded) return;const close = el("button", { class: "icon-button", type: "button", "aria-label": "Close expanded view", title: "Close (Esc)",onclick: collapseViewer }, icon(COLLAPSE));const stage = el("div", { class: "viewer-full-stage" });const layer = el("div", { class: "viewer-full", role: "dialog", "aria-modal": "true", "aria-label": `${a.name}: 3D view` },el("div", { class: "viewer-full-head" }, el("strong", {}, a.name), el("span", { class: "hint" }, hint || ""), close),stage);const view = viewer.getView();stage.append(viewer.element);document.body.append(layer);document.documentElement.classList.add("viewer-open");expanded = { layer, box, view };requestAnimationFrame(() => viewer.fit()); // after the layer has its sizeclose.focus();}function collapseViewer() {if (!expanded) return;const { layer, box, view } = expanded;expanded = null;if (box.isConnected) {box.prepend(viewer.element);viewer.resize();viewer.setView(view); // the panel gets back the camera it had}layer.remove();document.documentElement.classList.remove("viewer-open");box.querySelector(".viewer-expand")?.focus();}// Fallback when the 3D view can't run: the package thumbnail.function imageView(a) {const variant = theme();39 unmodified linesconst pane = $("detail");document.querySelector(".layout").classList.toggle("has-detail", !!a);pane.hidden = !a;collapseViewer();renderFoot(a);if (!a) { loadedId = null; return; }const mode = a.preview && !viewerFailed ? "3d" : "image";63 unmodified linesif (state.asset !== a.id) return;box.prepend(v.element);v.resize();const hint = bar.querySelector(".hint")?.textContent;box.append(el("button", { class: "viewer-expand", type: "button", "aria-label": "Expand 3D view", title: "Expand",onclick: () => expandViewer(a, box, hint) }, icon(EXPAND)));let rig;if (loadedId === a.id && rigState.length) {rig = rigState.map((r) => ({ ...r }));96 unmodified lines});systemLight.addEventListener("change", () => { applyTheme(); renderGrid(); });document.addEventListener("keydown", (e) => {if (e.key === "Escape") { if (expanded) collapseViewer(); else if (state.asset) openAsset(null); else closeSideOnPhone(); }if (e.key === "/" && document.activeElement !== $("q")) { e.preventDefault(); $("q").focus(); }});refresh();
7 unmodified lines89101112131469 unmodified lines8485868788897 unmodified lines<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Fira+Code:wght@400;500&display=swap"><link rel="stylesheet" href="style.css?v=25"><script type="importmap">{ "imports": {"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",69 unmodified lines</aside></div><script src="app.js?v=25"></script></body></html>7 unmodified lines89101112131469 unmodified lines8485868788897 unmodified lines<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Fira+Code:wght@400;500&display=swap"><link rel="stylesheet" href="style.css?v=27"><script type="importmap">{ "imports": {"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",69 unmodified lines</aside></div><script src="app.js?v=27"></script></body></html>
130 unmodified lines13113213313413513613713 unmodified lines151152153154155156130 unmodified lines.detail-head h2 { margin: 0; font-size: 20px; line-height: 1.25; text-wrap: balance; flex: 1; }.detail-head .icon-button { width: 32px; height: 32px; }.detail-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }.viewer { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--thumb); }.viewer .thumb { aspect-ratio: 4 / 3; }.viewer .thumb.light { background: #f0f0f0; }.viewer .thumb.dark { background: #1a1a1a; }13 unmodified lines.viewer3d-toggle::after { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2.5px solid #f29b38; background: #1d1e20; opacity: 0; }.viewer3d-toggle[aria-pressed="true"]::after { opacity: 1; }.viewer3d-toggle:hover { border-color: #ffffff; }.viewer3d-status { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px; font-size: 13px; color: var(--muted); pointer-events: none; }.joints { display: grid; gap: 8px; }.joint { display: grid; gap: 2px; }130 unmodified lines13113213313413513613713 unmodified lines151152153154155156157158159160161162163164165166167168130 unmodified lines.detail-head h2 { margin: 0; font-size: 20px; line-height: 1.25; text-wrap: balance; flex: 1; }.detail-head .icon-button { width: 32px; height: 32px; }.detail-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }.viewer { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--thumb); }.viewer .thumb { aspect-ratio: 4 / 3; }.viewer .thumb.light { background: #f0f0f0; }.viewer .thumb.dark { background: #1a1a1a; }13 unmodified lines.viewer3d-toggle::after { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2.5px solid #f29b38; background: #1d1e20; opacity: 0; }.viewer3d-toggle[aria-pressed="true"]::after { opacity: 1; }.viewer3d-toggle:hover { border-color: #ffffff; }/* Expand button (top right, mirrors the dots toggle) and the full-window 3D view */.viewer-expand { position: absolute; top: 10px; right: 10px; z-index: 2; width: 28px; height: 28px; padding: 0; border-radius: 6px; border: 2px solid rgba(255, 255, 255, 0.75); background: rgba(20, 21, 23, 0.35); color: #fff; cursor: pointer; display: grid; place-items: center; }.viewer-expand:hover { border-color: #ffffff; background: rgba(20, 21, 23, 0.6); }.viewer-expand svg, .viewer-full-head svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }.viewer-full { position: fixed; inset: 0; z-index: 100; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 10px; padding: calc(12px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px)); background: rgba(10, 10, 11, 0.92); }.viewer-full-head { display: flex; align-items: center; gap: 12px; min-width: 0; color: #f3eee8; }.viewer-full-head strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }.viewer-full-head .hint { flex: 1; min-width: 0; font-size: 12px; color: #a59d94; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }.viewer-full-stage { min-height: 0; border-radius: var(--radius); overflow: hidden; border: 1px solid #3a3735; }.viewer-full-stage .viewer3d, .viewer-full-stage .viewer3d-stage { width: 100%; height: 100%; aspect-ratio: auto; }:root.viewer-open, :root.viewer-open body { overflow: hidden; }@media (max-width: 600px) { .viewer-full-head .hint { display: none; } }.viewer3d-status { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px; font-size: 13px; color: var(--muted); pointer-events: none; }.joints { display: grid; gap: 8px; }.joint { display: grid; gap: 2px; }
182 unmodified lines18318418518618718818939 unmodified lines229230231232233234145 unmodified lines380381382383384385126 unmodified lines512513514515516517182 unmodified linesdraco.setDecoderPath("https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/draco/");loader.setDRACOLoader(draco);let model = null, grid = null, rig = [], grabMeshes = [], drag = null, gen = 0, theme = "dark", sizeM = 1;let onJoint = () => {};function setTheme(t) { theme = t === "light" ? "light" : "dark"; } // the studio is the same grey in both39 unmodified lines}new ResizeObserver(resize).observe(stage);// Joint dots (HTML overlay, like NVIDIA's viewer): one per moving part, at its joint.// Hover a dot or a part to highlight the part and see its state; drag either to move it.const overlay = document.createElement("div");145 unmodified linesconst dims = box.getSize(new THREE.Vector3());const size = Math.max(dims.length(), 0.02);camera.near = size / 400; camera.far = size * 80;camera.fov = opts.interior ? 68 : 35; // a room needs a wide, photo-like lensif (opts.interior) {const eye = box.min.y + Math.min(1.6, dims.y * 0.55);126 unmodified linesopenJoints: () => rig.forEach((r) => setJoint(r, r.free ? r.val : r.lo + (r.hi - r.lo) * (Math.abs(r.hi) >= Math.abs(r.lo) ? 0.85 : 0.15))),onJoint: (fn) => { onJoint = fn; },resize,dispose: () => { running = false; clear(); renderer.dispose(); },};}182 unmodified lines18318418518618718818939 unmodified lines229230231232233234235236237238239240241242243244245246247248249250251252253254255256145 unmodified lines402403404405406407408126 unmodified lines535536537538539540541542543182 unmodified linesdraco.setDecoderPath("https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/libs/draco/");loader.setDRACOLoader(draco);let model = null, grid = null, rig = [], grabMeshes = [], drag = null, gen = 0, theme = "dark", sizeM = 1, interior = false;let onJoint = () => {};function setTheme(t) { theme = t === "light" ? "light" : "dark"; } // the studio is the same grey in both39 unmodified lines}new ResizeObserver(resize).observe(stage);// Back the camera up along its current direction until the whole model fits the frame// (used when the view is expanded). Rooms are viewed from inside, so they're left alone.function fit(margin = 1.08) {if (!model || interior) return;resize();const sphere = new THREE.Box3().setFromObject(model).getBoundingSphere(new THREE.Sphere());const vfov = THREE.MathUtils.degToRad(camera.fov);const hfov = 2 * Math.atan(Math.tan(vfov / 2) * camera.aspect);const dist = (sphere.radius * margin) / Math.sin(Math.min(vfov, hfov) / 2);const dir = camera.position.clone().sub(controls.target).normalize();controls.target.copy(sphere.center);camera.position.copy(sphere.center).addScaledVector(dir, dist);controls.update();}const getView = () => ({ position: camera.position.clone(), target: controls.target.clone() });function setView(v) {if (!v) return;camera.position.copy(v.position);controls.target.copy(v.target);controls.update();}// Joint dots (HTML overlay, like NVIDIA's viewer): one per moving part, at its joint.// Hover a dot or a part to highlight the part and see its state; drag either to move it.const overlay = document.createElement("div");145 unmodified linesconst dims = box.getSize(new THREE.Vector3());const size = Math.max(dims.length(), 0.02);camera.near = size / 400; camera.far = size * 80;interior = !!opts.interior;camera.fov = opts.interior ? 68 : 35; // a room needs a wide, photo-like lensif (opts.interior) {const eye = box.min.y + Math.min(1.6, dims.y * 0.55);126 unmodified linesopenJoints: () => rig.forEach((r) => setJoint(r, r.free ? r.val : r.lo + (r.hi - r.lo) * (Math.abs(r.hi) >= Math.abs(r.lo) ? 0.85 : 0.15))),onJoint: (fn) => { onJoint = fn; },resize,fit,getView,setView,dispose: () => { running = false; clear(); renderer.dispose(); },};}
app.js+47-5
index.html+2-2
style.css+13-1
viewer.js+27-1