Spaces:
Running
Running
Move linked joints together in the 3D view (Isaac mimic joints, e.g. the accordion coat rack)
Browse filesFiles changed (7)
43 unmodified lines44454647484943 unmodified lines- `tools/make_previews.py` makes `previews/<asset>.glb` (a small Draco GLB made withBlender from the USD, textures at 1024 px) and `previews/<asset>.json` (each hinge andslider: the part it moves, pivot, axis and range). Cached in `tools/preview_cache.json`.- Scenes (the **Scenes** group) come from the gated dataset[projectsim/scenes-and-worlds](https://huggingface.co/datasets/projectsim/scenes-and-worlds),listed in `tools/scenes.json`. `tools/make_scene_previews.py` downloads each scene's GLB and43 unmodified lines44454647484950515243 unmodified lines- `tools/make_previews.py` makes `previews/<asset>.glb` (a small Draco GLB made withBlender from the USD, textures at 1024 px) and `previews/<asset>.json` (each hinge andslider: the part it moves, pivot, axis and range). Cached in `tools/preview_cache.json`.Joints linked in Isaac Sim (PhysX mimic joints, e.g. the accordion coat rack's scissorlinks) also record the joint they follow and the ratio, so the 3D view moves them together.`--rig-only` rewrites just the `.json` files (no Blender) when only joint data changes.- Scenes (the **Scenes** group) come from the gated dataset[projectsim/scenes-and-worlds](https://huggingface.co/datasets/projectsim/scenes-and-worlds),listed in `tools/scenes.json`. `tools/make_scene_previews.py` downloads each scene's GLB and
239 unmodified lines240241242243244245246197 unmodified lines444445446447448449239 unmodified linesasync function getViewer() {if (viewer || viewerFailed) return viewer;try {const { createViewer } = await import(signed("./viewer.js?v=30"));viewer = createViewer();} catch (e) {console.error("3D viewer failed to start", e);197 unmodified linesconst step = r.type === "hinge" ? 1 : Math.max((r.hi - r.lo) / 200, 0.0005);const input = el("input", { type: "range", min: r.lo, max: r.hi, step, value: r.val, "aria-label": `${r.name} position` });input.addEventListener("input", () => viewer.setJoint(i, parseFloat(input.value)));row.append(input);row._input = input;r.row = row;239 unmodified lines240241242243244245246197 unmodified lines444445446447448449450239 unmodified linesasync function getViewer() {if (viewer || viewerFailed) return viewer;try {const { createViewer } = await import(signed("./viewer.js?v=31"));viewer = createViewer();} catch (e) {console.error("3D viewer failed to start", e);197 unmodified linesconst step = r.type === "hinge" ? 1 : Math.max((r.hi - r.lo) / 200, 0.0005);const input = el("input", { type: "range", min: r.lo, max: r.hi, step, value: r.val, "aria-label": `${r.name} position` });input.addEventListener("input", () => viewer.setJoint(i, parseFloat(input.value)));if (r.follows) row.append(el("div", { class: "joint-link" }, `Linked: moves with ${r.follows}`));row.append(input);row._input = input;r.row = row;
7 unmodified lines89101112131468 unmodified lines8384858687887 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=31"><script type="importmap">{ "imports": {"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",68 unmodified lines</aside></div><script src="app.js?v=32"></script></body></html>7 unmodified lines89101112131468 unmodified lines8384858687887 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=32"><script type="importmap">{ "imports": {"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",68 unmodified lines</aside></div><script src="app.js?v=33"></script></body></html>
1{"joints":[{"name":"pivot_a","type":"hinge","parent":"mount","child":"a","pivot":[-0.37,0.525,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-11.459156,"upper":17.188734},{"name":"pivot_b","type":"hinge","parent":"mount","child":"b","pivot":[-0.37,0.525,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-17.188734,"upper":11.459156},{"name":"pivot_c","type":"hinge","parent":"b","child":"c","pivot":[-0.185,0.29,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-22.918312,"upper":34.377468},{"name":"pivot_d","type":"hinge","parent":"a","child":"d","pivot":[-0.555,0.29,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-34.377468,"upper":22.918312},{"name":"pivot_e","type":"hinge","parent":"b","child":"e","pivot":[0.0,0.055,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-22.918312,"upper":34.377468},{"name":"pivot_f","type":"hinge","parent":"c","child":"f","pivot":[0.0,0.525,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-34.377468,"upper":22.918312},{"name":"pivot_g","type":"hinge","parent":"f","child":"g","pivot":[0.37,0.055,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-22.918312,"upper":34.377468},{"name":"pivot_h","type":"hinge","parent":"g","child":"h","pivot":[0.555,0.29,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-34.377468,"upper":22.918312}]}1{"joints":[{"name":"pivot_a","type":"hinge","parent":"mount","child":"a","pivot":[-0.37,0.525,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-11.459156,"upper":17.188734},{"name":"pivot_b","type":"hinge","parent":"mount","child":"b","pivot":[-0.37,0.525,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-17.188734,"upper":11.459156,"mimic":{"ref":"pivot_a","gearing":1.0,"offset":0.0}},{"name":"pivot_c","type":"hinge","parent":"b","child":"c","pivot":[-0.185,0.29,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-22.918312,"upper":34.377468,"mimic":{"ref":"pivot_a","gearing":-2.0,"offset":0.0}},{"name":"pivot_d","type":"hinge","parent":"a","child":"d","pivot":[-0.555,0.29,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-34.377468,"upper":22.918312,"mimic":{"ref":"pivot_a","gearing":2.0,"offset":0.0}},{"name":"pivot_e","type":"hinge","parent":"b","child":"e","pivot":[0.0,0.055,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-22.918312,"upper":34.377468,"mimic":{"ref":"pivot_a","gearing":-2.0,"offset":0.0}},{"name":"pivot_f","type":"hinge","parent":"c","child":"f","pivot":[0.0,0.525,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-34.377468,"upper":22.918312,"mimic":{"ref":"pivot_a","gearing":2.0,"offset":0.0}},{"name":"pivot_g","type":"hinge","parent":"f","child":"g","pivot":[0.37,0.055,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-22.918312,"upper":34.377468,"mimic":{"ref":"pivot_a","gearing":-2.0,"offset":0.0}},{"name":"pivot_h","type":"hinge","parent":"g","child":"h","pivot":[0.555,0.29,-0.0],"axis":[-0.0,-0.0,-1.0],"lower":-34.377468,"upper":22.918312,"mimic":{"ref":"pivot_a","gearing":2.0,"offset":0.0}}]}
173 unmodified lines174175176177178179173 unmodified lines.joint-head code { font: 12px/1.3 var(--mono); overflow-wrap: anywhere; }.joint-head output { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }.joint input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0; }.joint-actions { display: flex; gap: 6px; }.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; align-items: baseline; }.facts dt { color: var(--muted); }173 unmodified lines174175176177178179180173 unmodified lines.joint-head code { font: 12px/1.3 var(--mono); overflow-wrap: anywhere; }.joint-head output { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }.joint input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0; }.joint-link { color: var(--muted); font-size: 12px; }.joint-actions { display: flex; gap: 6px; }.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; align-items: baseline; }.facts dt { color: var(--muted); }
8 unmodified lines910111213141516171819202122232444 unmodified lines697071727374751 unmodified line77787980818251 unmodified lines1341351361371381393 unmodified lines1431441451461471488 unmodified lines1571581591601611628 unmodified linesthe USD to a small Draco GLB with Blender (tools/blender_glb.py), and writes the rig: oneentry per hinge or slider joint with its parent and child part, pivot, axis and range,in the GLB's Y-up metres. Parts are matched to GLB nodes by USD prim name.Previews are cached in tools/preview_cache.json by package id, so a rerun only convertsnew or changed packages.Run from the Space folder: HF_TOKEN=$(hf auth token) uv run tools/make_previews.py [asset ...](the token only raises Hugging Face's download rate limit; nothing is uploaded)"""import argparseimport jsonimport osimport reimport struct44 unmodified lineslo, hi = typed.GetLowerLimitAttr().Get(), typed.GetUpperLimitAttr().Get()limited = lo is not None and hi is not None and abs(hi - lo) < 1e6scale = 1.0 if kind == "hinge" else mpujoints.append({"name": prim.GetName(), "type": kind,"parent": b0[0].name if b0 else None, "child": b1[0].name,"pivot": [round(x, 6) for x in to_gltf(pivot)],1 unmodified line"lower": round(lo * scale, 6) if limited else None,"upper": round(hi * scale, 6) if limited else None,})# parents before children, so the viewer can chain joints in one passorder, placed = [], set()while len(order) < len(joints):51 unmodified linesreturn {"bytes": os.path.getsize(glb), "joints": len(joints), "missing_parts": missing}def main():ap = argparse.ArgumentParser()ap.add_argument("assets", nargs="*", help="only these assets (default: all that need a preview)")3 unmodified linesap.add_argument("--blender", default=BLENDER)ap.add_argument("--max-texture", type=int, default=1024)ap.add_argument("--workers", type=int, default=4)args = ap.parse_args()os.makedirs(args.out, exist_ok=True)8 unmodified linesdef package_id(a):return get_json(f"{HF}/datasets/{args.dataset}/resolve/{sha}/{a}/com.nvidia.simready.packaging.json")["package_id"]with ThreadPoolExecutor(args.workers) as pool:ids = dict(zip(wanted, pool.map(package_id, wanted)))todo = [a for a in wanted if args.assets or ids[a] not in cache8 unmodified lines910111213141516171819202122232425262728293044 unmodified lines75767778798081828384858687888990911 unmodified line9394959697989910010110210310410510651 unmodified lines1581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871883 unmodified lines1921931941951961971988 unmodified lines2072082092102112122132142152168 unmodified linesthe USD to a small Draco GLB with Blender (tools/blender_glb.py), and writes the rig: oneentry per hinge or slider joint with its parent and child part, pivot, axis and range,in the GLB's Y-up metres. Parts are matched to GLB nodes by USD prim name.A joint that follows another one in Isaac (a PhysX mimic joint, as on scissor andaccordion linkages) gets "mimic": {ref, gearing, offset} in the viewer's units(degrees, metres): its position is -(gearing * ref + offset), as PhysX defines it.Previews are cached in tools/preview_cache.json by package id, so a rerun only convertsnew or changed packages.Run from the Space folder: HF_TOKEN=$(hf auth token) uv run tools/make_previews.py [asset ...](the token only raises Hugging Face's download rate limit; nothing is uploaded)--rig-only rewrites just the .json files from each package's root USD layer (no Blender,the GLBs stay as they are), for when only the joint data changes."""import argparseimport jsonimport mathimport osimport reimport struct44 unmodified lineslo, hi = typed.GetLowerLimitAttr().Get(), typed.GetUpperLimitAttr().Get()limited = lo is not None and hi is not None and abs(hi - lo) < 1e6scale = 1.0 if kind == "hinge" else mpumimic = None # PhysxMimicJointAPI:<axis>: this joint follows another onefor attr in prim.GetAttributes():m = re.fullmatch(r"physxMimicJoint:(\w+):gearing", attr.GetName())ref = prim.GetRelationship(f"physxMimicJoint:{m.group(1)}:referenceJoint") if m else Noneif ref and ref.GetTargets() and attr.Get() is not None:off = prim.GetAttribute(f"physxMimicJoint:{m.group(1)}:offset")mimic = {"ref": ref.GetTargets()[0].name, "gearing": float(attr.Get()),"offset": float((off.Get() if off else 0) or 0)}breakjoints.append({"_mimic": mimic,"name": prim.GetName(), "type": kind,"parent": b0[0].name if b0 else None, "child": b1[0].name,"pivot": [round(x, 6) for x in to_gltf(pivot)],1 unmodified line"lower": round(lo * scale, 6) if limited else None,"upper": round(hi * scale, 6) if limited else None,})# mimic links in the viewer's units: PhysX positions are radians (hinge) or stage units (slider)kinds = {jt["name"]: jt["type"] for jt in joints}native = lambda kind: math.pi / 180 if kind == "hinge" else 1 / mpu # viewer value -> PhysX positionfor jt in joints:m = jt.pop("_mimic")if m and m["ref"] in kinds and m["ref"] != jt["name"]:kr, kf = native(kinds[m["ref"]]), native(jt["type"])jt["mimic"] = {"ref": m["ref"], "gearing": round(m["gearing"] * kr / kf, 6), "offset": round(m["offset"] / kf, 6)}# parents before children, so the viewer can chain joints in one passorder, placed = [], set()while len(order) < len(joints):51 unmodified linesreturn {"bytes": os.path.getsize(glb), "joints": len(joints), "missing_parts": missing}def rig_only(args, sha, assets):"""Rewrite previews/<asset>.json from the root USD layer alone; report linked (mimic) joints."""def work(a):try:with tempfile.TemporaryDirectory() as tmp:usd = os.path.join(tmp, f"{a}.usd")download(f"{HF}/datasets/{args.dataset}/resolve/{sha}/{a}/simready_usd/{a}.usd", usd)joints = rig(usd)json.dump({"joints": joints}, open(os.path.join(args.out, f"{a}.json"), "w"), separators=(",", ":"))return a, sum("mimic" in j for j in joints), Noneexcept Exception as e: # keep going; report at the endreturn a, None, str(e)print(f"{len(assets)} joint files to rewrite", file=sys.stderr)with ThreadPoolExecutor(args.workers) as pool:results = list(pool.map(work, assets))for a, n, err in results:if err:print(f" FAILED {a}: {err[:300]}", file=sys.stderr)elif n:print(f" {a}: {n} linked joint(s)", file=sys.stderr)print(f"done: {sum(1 for r in results if not r[2])} rewritten, {sum(1 for r in results if r[1])} with linked joints",file=sys.stderr)def main():ap = argparse.ArgumentParser()ap.add_argument("assets", nargs="*", help="only these assets (default: all that need a preview)")3 unmodified linesap.add_argument("--blender", default=BLENDER)ap.add_argument("--max-texture", type=int, default=1024)ap.add_argument("--workers", type=int, default=4)ap.add_argument("--rig-only", action="store_true", help="only rewrite the .json joint files (no Blender)")args = ap.parse_args()os.makedirs(args.out, exist_ok=True)8 unmodified linesdef package_id(a):return get_json(f"{HF}/datasets/{args.dataset}/resolve/{sha}/{a}/com.nvidia.simready.packaging.json")["package_id"]if args.rig_only:rig_only(args, sha, [a for a in wanted if args.assets or os.path.exists(os.path.join(args.out, f"{a}.glb"))])returnwith ThreadPoolExecutor(args.workers) as pool:ids = dict(zip(wanted, pool.map(package_id, wanted)))todo = [a for a in wanted if args.assets or ids[a] not in cache
275 unmodified lines27627727827928028156 unmodified lines33833934034134234334434534634734834965 unmodified lines41541641741841942042118 unmodified lines440441442443444445446105 unmodified lines552553554555556557558559275 unmodified linesconst HIGHLIGHT = new THREE.Color(0xf29b38);let hot = null;function highlight(r, on) {for (const mesh of r.meshes) for (const m of [].concat(mesh.material)) {if (!m.emissive) continue;if (on) {56 unmodified linesfunction setLook(l) { look = l || null; applyLook(); }const clean = (s) => String(s || "").replace(/[\s.:/[\]]/g, "");function setJoint(r, v) {v = Math.min(r.hi, Math.max(r.lo, v));r.val = v;if (r.type === "hinge") r.group.quaternion.setFromAxisAngle(r.axis, THREE.MathUtils.degToRad(v));else r.group.position.copy(r.base).addScaledVector(r.axis, v);onJoint(r.index, v);}// opts.interior: a room. Start inside at eye height, no shadows; opts.enclosed keeps the camera inside the walls.65 unmodified linesr.dot = dot;rig.push(r);}rig.forEach((r) => setJoint(r, rest(r)));const box = new THREE.Box3().setFromObject(model);const c = box.getCenter(new THREE.Vector3());18 unmodified linesplaceGrid();status.hidden = true;toggle.hidden = !rig.length;return rig.map((r) => ({ name: r.name, type: r.type, lo: r.lo, hi: r.hi, free: r.free, val: r.val }));}// Drag a part or its dot: hinges swing around their axis (following the pointer around105 unmodified linessetLook,setTheme,setJoint: (i, v) => rig[i] && setJoint(rig[i], v),resetJoints: () => rig.forEach((r) => setJoint(r, rest(r))),openJoints: () => 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,275 unmodified lines27627727827928028128228328456 unmodified lines34134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438565 unmodified lines45145245345445545645745818 unmodified lines477478479480481482483484105 unmodified lines590591592593594595596597275 unmodified linesconst HIGHLIGHT = new THREE.Color(0xf29b38);let hot = null;function highlight(r, on) {for (const g of r.linked || [r]) highlightOne(g, on);}function highlightOne(r, on) {for (const mesh of r.meshes) for (const m of [].concat(mesh.material)) {if (!m.emissive) continue;if (on) {56 unmodified linesfunction setLook(l) { look = l || null; applyLook(); }const clean = (s) => String(s || "").replace(/[\s.:/[\]]/g, "");// Linked joints (PhysX mimic joints, e.g. a scissor or accordion linkage) follow a// reference joint: follower = -(gearing * reference + offset), as Isaac Sim applies it.// Moving any of them moves the reference, which places every joint linked to it.function place(r, v, depth = 0) {r.val = v;if (r.type === "hinge") r.group.quaternion.setFromAxisAngle(r.axis, THREE.MathUtils.degToRad(v));else r.group.position.copy(r.base).addScaledVector(r.axis, v);onJoint(r.index, v);if (depth < 8) for (const f of r.followers || []) place(f, -(f.mimic.gearing * v + f.mimic.offset), depth + 1);}function setJoint(r, v) {for (let n = 0; r.mimic && n < 8; n++) { v = -(v + r.mimic.offset) / r.mimic.gearing; r = r.mimic.ref; }place(r, Math.min(r.hi, Math.max(r.lo, v)));}const leaders = () => rig.filter((r) => !r.mimic);function linkJoints(joints) {const byName = Object.fromEntries(rig.map((r) => [r.name, r]));for (const j of joints) {const r = byName[j.name], ref = j.mimic && byName[j.mimic.ref];if (!r || !ref || ref === r || !j.mimic.gearing) continue;r.mimic = { ref, gearing: j.mimic.gearing, offset: j.mimic.offset || 0 };(ref.followers = ref.followers || []).push(r);}const top = (r, n = 0) => (r.mimic && n < 8 ? top(r.mimic.ref, n + 1) : r);for (const r of rig) {if (!r.mimic) continue;const t = top(r);t.linked = t.linked || [t];t.linked.push(r);r.linked = t.linked;// the reference can only go as far as its followers' limits allowif (r.free) continue;const { ref, gearing: g, offset: o } = r.mimic;const ends = [r.lo, r.hi].map((x) => -(x + o) / g);ref.lo = Math.max(ref.free ? -Infinity : ref.lo, Math.min(...ends));ref.hi = Math.min(ref.free ? Infinity : ref.hi, Math.max(...ends));ref.free = false;if (ref.lo > ref.hi) ref.lo = ref.hi = (ref.lo + ref.hi) / 2; // contradictory limits: hold still rather than tear apart}}// opts.interior: a room. Start inside at eye height, no shadows; opts.enclosed keeps the camera inside the walls.65 unmodified linesr.dot = dot;rig.push(r);}linkJoints(data.joints || []);leaders().forEach((r) => setJoint(r, rest(r)));const box = new THREE.Box3().setFromObject(model);const c = box.getCenter(new THREE.Vector3());18 unmodified linesplaceGrid();status.hidden = true;toggle.hidden = !rig.length;return rig.map((r) => ({ name: r.name, type: r.type, lo: r.lo, hi: r.hi, free: r.free, val: r.val,follows: r.mimic ? r.mimic.ref.name : null }));}// Drag a part or its dot: hinges swing around their axis (following the pointer around105 unmodified linessetLook,setTheme,setJoint: (i, v) => rig[i] && setJoint(rig[i], v),resetJoints: () => leaders().forEach((r) => setJoint(r, rest(r))),openJoints: () => leaders().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,
README.md+3
app.js+2-1
index.html+2-2
previews/accordion_coat_rack.json+1-1
style.css+1
tools/make_previews.py+54
viewer.js+44-6