Spaces:
Running
Running
3D asset viewer
Browse files- README.md +17 -5
- config.json +8 -0
- index.html +154 -17
README.md
CHANGED
|
@@ -1,10 +1,22 @@
|
|
| 1 |
---
|
| 2 |
-
title: 3D Assets Viewer
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: "3D Assets Viewer"
|
| 3 |
+
emoji: 📦
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
license: cc-by-4.0
|
| 9 |
+
short_description: "True-scale GLB models: industrial storage units and more"
|
| 10 |
+
datasets:
|
| 11 |
+
- danielrosehill/Modular-Storage-3D-Models
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# 3D Assets Viewer
|
| 15 |
+
|
| 16 |
+
True-scale GLB models: industrial storage units and more
|
| 17 |
+
|
| 18 |
+
Interactive viewer for 3D assets published as Hugging Face datasets: search, filter, and open any model in a 3D view (`<model-viewer>`, AR on mobile) with its metadata and a download link. Assets load straight from:
|
| 19 |
+
|
| 20 |
+
- [danielrosehill/Modular-Storage-3D-Models](https://huggingface.co/datasets/danielrosehill/Modular-Storage-3D-Models)
|
| 21 |
+
|
| 22 |
+
Deep link to one asset: append `#<code or id>` to the Space URL.
|
config.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"title": "3D Assets Viewer",
|
| 3 |
+
"description": "True-scale GLB models: industrial storage units and more",
|
| 4 |
+
"datasets": [
|
| 5 |
+
"danielrosehill/Modular-Storage-3D-Models"
|
| 6 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>3D asset viewer</title>
|
| 7 |
+
<script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/4.0.0/model-viewer.min.js"></script>
|
| 8 |
+
<style>
|
| 9 |
+
:root { --bg:#0f1115; --card:#181b22; --line:#2a2f3a; --fg:#e8eaed; --mute:#9aa0aa; --acc:#4f8cff; }
|
| 10 |
+
* { box-sizing: border-box; }
|
| 11 |
+
body { margin:0; font:15px/1.45 system-ui, sans-serif; background:var(--bg); color:var(--fg); }
|
| 12 |
+
header { padding:20px 24px 8px; }
|
| 13 |
+
h1 { margin:0 0 4px; font-size:22px; }
|
| 14 |
+
header p { margin:0; color:var(--mute); }
|
| 15 |
+
header a { color:var(--acc); }
|
| 16 |
+
.bar { display:flex; gap:10px; flex-wrap:wrap; padding:12px 24px; position:sticky; top:0; background:var(--bg); z-index:2; border-bottom:1px solid var(--line); }
|
| 17 |
+
input, select { background:var(--card); color:var(--fg); border:1px solid var(--line); border-radius:8px; padding:8px 10px; font:inherit; }
|
| 18 |
+
input { flex:1; min-width:200px; }
|
| 19 |
+
#count { color:var(--mute); align-self:center; }
|
| 20 |
+
.grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(210px, 1fr)); gap:14px; padding:18px 24px 40px; }
|
| 21 |
+
.card { background:var(--card); border:1px solid var(--line); border-radius:12px; overflow:hidden; cursor:pointer; transition:border-color .15s; }
|
| 22 |
+
.card:hover { border-color:var(--acc); }
|
| 23 |
+
.card img { width:100%; aspect-ratio:1; object-fit:cover; display:block; background:#222; }
|
| 24 |
+
.card .t { padding:9px 11px; }
|
| 25 |
+
.card .n { font-weight:600; font-size:14px; }
|
| 26 |
+
.card .s { color:var(--mute); font-size:12px; }
|
| 27 |
+
dialog { width:min(1100px, 96vw); height:min(760px, 92vh); padding:0; border:1px solid var(--line); border-radius:14px; background:var(--card); color:var(--fg); }
|
| 28 |
+
dialog::backdrop { background:rgba(0,0,0,.65); }
|
| 29 |
+
.dlg { display:grid; grid-template-columns:1fr 340px; height:100%; }
|
| 30 |
+
model-viewer { width:100%; height:100%; background:radial-gradient(#3a3f4a, #1a1d23); }
|
| 31 |
+
.side { padding:18px; overflow:auto; border-left:1px solid var(--line); }
|
| 32 |
+
.side h2 { margin:0 0 10px; font-size:18px; }
|
| 33 |
+
.side table { width:100%; border-collapse:collapse; font-size:13px; }
|
| 34 |
+
.side td { border-top:1px solid var(--line); padding:5px 4px; vertical-align:top; word-break:break-word; }
|
| 35 |
+
.side td:first-child { color:var(--mute); width:38%; }
|
| 36 |
+
.btns { display:flex; gap:8px; margin:12px 0; flex-wrap:wrap; }
|
| 37 |
+
.btns a, .btns button { background:var(--acc); color:#fff; border:0; border-radius:8px; padding:8px 12px; text-decoration:none; font:inherit; cursor:pointer; }
|
| 38 |
+
.btns button { background:#333a46; }
|
| 39 |
+
@media (max-width:800px) { .dlg { grid-template-columns:1fr; grid-template-rows:60% 40%; } .side { border-left:0; border-top:1px solid var(--line); } }
|
| 40 |
+
</style>
|
| 41 |
+
</head>
|
| 42 |
+
<body>
|
| 43 |
+
<header>
|
| 44 |
+
<h1 id="title">3D assets</h1>
|
| 45 |
+
<p id="desc"></p>
|
| 46 |
+
</header>
|
| 47 |
+
<div class="bar">
|
| 48 |
+
<input id="q" type="search" placeholder="Search name, code, tags…">
|
| 49 |
+
<select id="group"></select>
|
| 50 |
+
<span id="count"></span>
|
| 51 |
+
</div>
|
| 52 |
+
<div class="grid" id="grid"></div>
|
| 53 |
+
|
| 54 |
+
<dialog id="dlg">
|
| 55 |
+
<div class="dlg">
|
| 56 |
+
<model-viewer id="mv" camera-controls auto-rotate shadow-intensity="1" exposure="1" environment-image="neutral" ar touch-action="pan-y"></model-viewer>
|
| 57 |
+
<div class="side">
|
| 58 |
+
<h2 id="mname"></h2>
|
| 59 |
+
<div class="btns">
|
| 60 |
+
<a id="mdl" download>Download</a>
|
| 61 |
+
<a id="msf" target="_blank" rel="noopener">Sketchfab</a>
|
| 62 |
+
<button onclick="document.getElementById('dlg').close()">Close</button>
|
| 63 |
+
</div>
|
| 64 |
+
<table id="mmeta"></table>
|
| 65 |
+
</div>
|
| 66 |
+
</div>
|
| 67 |
+
</dialog>
|
| 68 |
+
|
| 69 |
+
<script type="module">
|
| 70 |
+
// config.json is written by `hf3d space`: {title, description, datasets: ["owner/name", ...], group_by}
|
| 71 |
+
const cfg = await (await fetch('config.json')).json();
|
| 72 |
+
document.getElementById('title').textContent = cfg.title;
|
| 73 |
+
document.title = cfg.title;
|
| 74 |
+
const links = cfg.datasets.map(d => `<a href="https://huggingface.co/datasets/${d}" target="_blank">${d}</a>`).join(', ');
|
| 75 |
+
document.getElementById('desc').innerHTML = (cfg.description ? cfg.description + ' · ' : '') + 'Data: ' + links;
|
| 76 |
+
|
| 77 |
+
const base = d => `https://huggingface.co/datasets/${d}/resolve/main/`;
|
| 78 |
+
const HIDE = new Set(['file_name']);
|
| 79 |
+
let items = [];
|
| 80 |
+
for (const d of cfg.datasets) {
|
| 81 |
+
const txt = await (await fetch(base(d) + 'metadata.jsonl')).text();
|
| 82 |
+
for (const line of txt.split('\n')) {
|
| 83 |
+
if (!line.trim()) continue;
|
| 84 |
+
const r = JSON.parse(line);
|
| 85 |
+
const asset = r.asset || r.glb;
|
| 86 |
+
if (!asset) continue;
|
| 87 |
+
items.push({ ...r, _ds: d, _asset: base(d) + asset, _img: r.file_name ? base(d) + r.file_name : '' });
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// group-by options: configured field first, then low-cardinality string fields
|
| 92 |
+
const fields = {};
|
| 93 |
+
for (const it of items) for (const [k, v] of Object.entries(it))
|
| 94 |
+
if (!k.startsWith('_') && typeof v === 'string' && !HIDE.has(k)) (fields[k] ??= new Set()).add(v);
|
| 95 |
+
const groupable = Object.keys(fields).filter(k => fields[k].size > 1 && fields[k].size <= 24);
|
| 96 |
+
const gsel = document.getElementById('group');
|
| 97 |
+
gsel.innerHTML = '<option value="">All</option>';
|
| 98 |
+
for (const k of groupable) for (const v of [...fields[k]].sort())
|
| 99 |
+
gsel.insertAdjacentHTML('beforeend', `<option value="${k}=${v}">${k}: ${v}</option>`);
|
| 100 |
+
if (cfg.group_by && !groupable.includes(cfg.group_by)) console.warn('group_by not groupable', cfg.group_by);
|
| 101 |
+
|
| 102 |
+
const fmt = v => typeof v === 'object' && v !== null
|
| 103 |
+
? (Array.isArray(v) ? v.join(', ') : Object.entries(v).map(([k, x]) => `${k} ${x}`).join(' × '))
|
| 104 |
+
: String(v);
|
| 105 |
+
|
| 106 |
+
function render() {
|
| 107 |
+
const q = document.getElementById('q').value.toLowerCase();
|
| 108 |
+
const [gk, gv] = gsel.value ? gsel.value.split('=') : [];
|
| 109 |
+
const grid = document.getElementById('grid');
|
| 110 |
+
grid.innerHTML = '';
|
| 111 |
+
let n = 0;
|
| 112 |
+
for (const it of items) {
|
| 113 |
+
if (gk && it[gk] !== gv) continue;
|
| 114 |
+
if (q && !JSON.stringify(it).toLowerCase().includes(q)) continue;
|
| 115 |
+
n++;
|
| 116 |
+
const sub = it.code || it.id || '';
|
| 117 |
+
const dims = it.outer_mm ? fmt(it.outer_mm) + ' mm' : (it.bbox_m ? it.bbox_m.join(' × ') + ' m' : '');
|
| 118 |
+
const el = document.createElement('div');
|
| 119 |
+
el.className = 'card';
|
| 120 |
+
el.innerHTML = `<img loading="lazy" src="${it._img}" alt="">
|
| 121 |
+
<div class="t"><div class="n"></div><div class="s">${sub}${dims ? ' · ' + dims : ''}</div></div>`;
|
| 122 |
+
el.querySelector('.n').textContent = it.name;
|
| 123 |
+
el.onclick = () => open(it);
|
| 124 |
+
grid.appendChild(el);
|
| 125 |
+
}
|
| 126 |
+
document.getElementById('count').textContent = `${n} of ${items.length}`;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
function open(it) {
|
| 130 |
+
const mv = document.getElementById('mv');
|
| 131 |
+
mv.src = it._asset;
|
| 132 |
+
mv.poster = it._img;
|
| 133 |
+
document.getElementById('mname').textContent = it.name;
|
| 134 |
+
document.getElementById('mdl').href = it._asset;
|
| 135 |
+
const sf = document.getElementById('msf');
|
| 136 |
+
sf.style.display = it.sketchfab_url ? '' : 'none';
|
| 137 |
+
if (it.sketchfab_url) sf.href = it.sketchfab_url;
|
| 138 |
+
const t = document.getElementById('mmeta');
|
| 139 |
+
t.innerHTML = '';
|
| 140 |
+
for (const [k, v] of Object.entries(it)) {
|
| 141 |
+
if (k.startsWith('_') || HIDE.has(k) || v === null || v === '' || k === 'name') continue;
|
| 142 |
+
const tr = t.insertRow();
|
| 143 |
+
tr.insertCell().textContent = k;
|
| 144 |
+
tr.insertCell().textContent = fmt(v);
|
| 145 |
+
}
|
| 146 |
+
document.getElementById('dlg').showModal();
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
document.getElementById('q').oninput = render;
|
| 150 |
+
gsel.onchange = render;
|
| 151 |
+
const hash = decodeURIComponent(location.hash.slice(1));
|
| 152 |
+
render();
|
| 153 |
+
if (hash) { const it = items.find(i => (i.code || i.id) === hash); if (it) open(it); }
|
| 154 |
+
</script>
|
| 155 |
+
</body>
|
| 156 |
</html>
|