Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sand3D Explorer
Browse files- README.md +45 -4
- app/catalog.py +219 -47
- app/main.py +45 -13
- app/search.py +10 -0
- config.json +42 -2
- requirements.txt +1 -0
- static/app.css +1 -0
- static/app.js +52 -29
- static/img/banner-830.webp +0 -0
- static/img/banner.webp +2 -2
- static/index.html +7 -6
- static/viewer.js +2 -1
README.md
CHANGED
|
@@ -15,14 +15,55 @@ the short [sand3d](https://github.com/Sandflow-ai/sand3d) program that builds it
|
|
| 15 |
dataset, family or joints, search by words or by look, read and copy a program, and open the
|
| 16 |
object in 3D where a GLB was built for it.
|
| 17 |
|
| 18 |
-
The programs
|
| 19 |
-
|
| 20 |
|
| 21 |
## How it runs
|
| 22 |
|
| 23 |
A FastAPI process serves one static page and a JSON API, on the free CPU tier. At start it
|
| 24 |
-
downloads the datasets listed in `config.json`
|
| 25 |
-
|
| 26 |
`Sandflow/sand3d-explorer-assets`: one GLB per object for a varied sample, and one image
|
| 27 |
embedding per render. A text query is encoded on CPU by the same open image-text model the
|
| 28 |
renders were embedded with.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
dataset, family or joints, search by words or by look, read and copy a program, and open the
|
| 16 |
object in 3D where a GLB was built for it.
|
| 17 |
|
| 18 |
+
The programs are run under sand3d in a fresh process. Reconstructed objects are checked against
|
| 19 |
+
their source geometry. Nature assets are scored against their original prompt.
|
| 20 |
|
| 21 |
## How it runs
|
| 22 |
|
| 23 |
A FastAPI process serves one static page and a JSON API, on the free CPU tier. At start it
|
| 24 |
+
downloads the datasets listed in `config.json`, keeps their metadata and programs in memory
|
| 25 |
+
and packs the grid images into one file on disk. It then reads
|
| 26 |
`Sandflow/sand3d-explorer-assets`: one GLB per object for a varied sample, and one image
|
| 27 |
embedding per render. A text query is encoded on CPU by the same open image-text model the
|
| 28 |
renders were embedded with.
|
| 29 |
+
|
| 30 |
+
## Nature dataset
|
| 31 |
+
|
| 32 |
+
`Sandflow/sand3d-nature` uses one row per asset in `data/nature/train-*.parquet` and
|
| 33 |
+
`data/nature/validation-*.parquet`. Paths are relative to the repository root.
|
| 34 |
+
|
| 35 |
+
| Fields | Values |
|
| 36 |
+
| --- | --- |
|
| 37 |
+
| `id` | Globally unique, URL-safe object id, also used by the GLB manifest |
|
| 38 |
+
| `asset_id` | `nature:<original prompt id>`, used to match the published geometry |
|
| 39 |
+
| `source`, `source_group`, `family`, `split` | `nature` for both source fields, taxonomy family, `train` or `val` |
|
| 40 |
+
| `prompt`, `domain`, `subject`, `style` | Original prompt and taxonomy strings |
|
| 41 |
+
| `semantic_score`, `triangles` | Score in [0, 1], integer triangle count |
|
| 42 |
+
| `sand3d_version`, `license`, `n_joints` | `1.7.0`, `CC-BY-4.0`, zero |
|
| 43 |
+
| `f_score`, `source_license`, `attribution` | Null |
|
| 44 |
+
| `program`, `entry`, `render` | Program text, optional entry function, and standard render as an embedded Hub Image |
|
| 45 |
+
| `usda_path`, `usda_bytes` | USD path under `usda/<shard>/` and file size |
|
| 46 |
+
| `cycles_path` | Optional 512 px WebP in `cycles/<shard>/<id>.webp`, encoded from the Cycles PNG by the Hub staging step. The Space derives a 256 px grid thumbnail when loading and uses the standard PNG if the WebP is missing or unreadable. |
|
| 47 |
+
|
| 48 |
+
The gallery shows assets at or above 0.8 first. Within each score band it sorts by descending
|
| 49 |
+
complexity, then descending score. Complexity is the floor of log₂ of the mesh-node count,
|
| 50 |
+
capped at 32 nodes. If the count is unavailable, each 1,024 triangles counts as one estimated
|
| 51 |
+
node, with a minimum of one for any positive triangle count. Assets with neither count come
|
| 52 |
+
last within the complexity sort. At equal complexity and score, the order takes one asset per
|
| 53 |
+
family per round. Unscored assets follow scored assets.
|
| 54 |
+
|
| 55 |
+
The first 48 positions in the unfiltered Nature gallery rotate domains among assets with equal complexity and score,
|
| 56 |
+
using the family order within each domain. A coral leads the marine domain when one shares that
|
| 57 |
+
tier. Edit `showcase_demote_families` in `config.json` to place named families after the showcase.
|
| 58 |
+
Their assets remain in Nature and in search. The base order resumes after the showcase.
|
| 59 |
+
|
| 60 |
+
All interleaves above-floor Nature assets with the reconstructed objects. The Nature search matches
|
| 61 |
+
words and quoted phrases in the original prompt and subject. All includes these text matches
|
| 62 |
+
when Nature image embeddings are unavailable.
|
| 63 |
+
|
| 64 |
+
`default_dataset` in `config.json` selects the tab at the home URL. Set it to `""` for All.
|
| 65 |
+
|
| 66 |
+
For local development, set `EXPLORER_LOCAL_HUB` to a directory containing one subdirectory per
|
| 67 |
+
dataset repository name (for example, `sand3d-nature`). Run `uvicorn app.main:app --port 7860`
|
| 68 |
+
from this directory containing the Space app. `EXPLORER_DATA` holds the generated image blob,
|
| 69 |
+
and `EXPLORER_ASSETS_DIR` can point to a local set of GLBs.
|
app/catalog.py
CHANGED
|
@@ -10,6 +10,7 @@ so the tests import this module anywhere.
|
|
| 10 |
"""
|
| 11 |
from __future__ import annotations
|
| 12 |
|
|
|
|
| 13 |
import json
|
| 14 |
import math
|
| 15 |
import os
|
|
@@ -17,9 +18,11 @@ import random
|
|
| 17 |
import re
|
| 18 |
import threading
|
| 19 |
import time
|
| 20 |
-
from collections import Counter
|
|
|
|
| 21 |
from dataclasses import dataclass, field
|
| 22 |
-
from
|
|
|
|
| 23 |
|
| 24 |
#: An entry function's names that say nothing of the object.
|
| 25 |
GENERIC = {"build", "main", "make", "model", "asset", "part", "object", "create", "result", "body", "shape",
|
|
@@ -46,8 +49,9 @@ def title(attribution: str | None) -> str | None:
|
|
| 46 |
|
| 47 |
|
| 48 |
def display_name(row: dict) -> str:
|
| 49 |
-
"""
|
| 50 |
-
|
|
|
|
| 51 |
entry = row.get("entry")
|
| 52 |
if entry and entry.lower() not in GENERIC:
|
| 53 |
return humanize(entry)
|
|
@@ -69,7 +73,7 @@ def family_label(group: str, family: str) -> str:
|
|
| 69 |
|
| 70 |
|
| 71 |
SOURCES = {"objaverse": "Objaverse", "simready": "NVIDIA SimReady", "articraft": "Articraft",
|
| 72 |
-
"zero-to-cad": "Zero-To-CAD", "cadfs": "CADFS", "automate": "AutoMate"}
|
| 73 |
|
| 74 |
|
| 75 |
def glb_paths(manifest: dict) -> dict[str, str]:
|
|
@@ -80,13 +84,16 @@ def glb_paths(manifest: dict) -> dict[str, str]:
|
|
| 80 |
return {i: f"glb/{g}/{i}.glb" for g, ids in manifest.get("glb", {}).items() for i in ids}
|
| 81 |
|
| 82 |
|
| 83 |
-
#: The
|
| 84 |
#: by parts, on a log2 scale capped at 2**PART_CAP (32 parts and 300 rank alike: one source's
|
| 85 |
#: hundred-part objects do not take the first page); then by F, in steps of F_STEP (1.0 with 0.98);
|
| 86 |
#: within such a tier, each source in a seeded order and the sources taken in turn.
|
| 87 |
F_FLOOR = 0.95
|
| 88 |
PART_CAP = 5
|
| 89 |
F_STEP = 0.02
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
def tier(f: float | None, parts: int | None) -> tuple:
|
|
@@ -97,18 +104,80 @@ def tier(f: float | None, parts: int | None) -> tuple:
|
|
| 97 |
return (f >= F_FLOOR, b, math.floor(min(f, 0.999) / F_STEP))
|
| 98 |
|
| 99 |
|
| 100 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
"""Row indices in the explorer's order (`tier`, then the sources in turn within a tier, each
|
| 102 |
in a seeded order). `rows` carry `id`, `source`, `f_score` and `_parts`."""
|
| 103 |
rng = random.Random(seed)
|
| 104 |
-
|
| 105 |
-
|
|
|
|
| 106 |
turn, seen = {}, Counter()
|
| 107 |
-
for i in sorted(
|
| 108 |
k = (tiers[i], rows[i]["source"])
|
| 109 |
turn[i] = seen[k]
|
| 110 |
seen[k] += 1
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
|
| 114 |
@dataclass
|
|
@@ -120,10 +189,80 @@ class Dataset:
|
|
| 120 |
parts_group: str | None = None # a group whose rows are parts of the others, shown on request
|
| 121 |
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
@dataclass
|
| 124 |
class Catalog:
|
| 125 |
datasets: list[Dataset]
|
| 126 |
root: Path
|
|
|
|
| 127 |
status: dict = field(default_factory=lambda: {"ready": False, "stage": "starting", "loaded": 0})
|
| 128 |
rows: list[dict] = field(default_factory=list)
|
| 129 |
by_id: dict[str, int] = field(default_factory=dict)
|
|
@@ -131,9 +270,8 @@ class Catalog:
|
|
| 131 |
|
| 132 |
# ------------------------------------------------------------------ load
|
| 133 |
def load(self, token: str | None, assets_repo: str | None, splits: tuple[str, ...] | None = None,
|
| 134 |
-
assets_dir: Path | None = None) -> None:
|
| 135 |
import numpy as np # noqa: PLC0415
|
| 136 |
-
import pyarrow.parquet as pq # noqa: PLC0415
|
| 137 |
from huggingface_hub import snapshot_download # noqa: PLC0415
|
| 138 |
t0 = time.time()
|
| 139 |
self.root.mkdir(parents=True, exist_ok=True)
|
|
@@ -145,35 +283,52 @@ class Catalog:
|
|
| 145 |
for ds in self.datasets:
|
| 146 |
self.status.update(stage=f"downloading {ds.label}")
|
| 147 |
pats = [f"data/*/{s}-*.parquet" for s in splits] if splits else ["data/*/*.parquet"]
|
|
|
|
|
|
|
| 148 |
try:
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
except RepositoryNotFoundError: # listed before it is published: shown once it is
|
| 152 |
self.status.setdefault("missing", []).append(ds.repo)
|
| 153 |
continue
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
self.status.update(stage=f"reading {ds.label}")
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
r["_row"] = position.get(split, 0)
|
| 174 |
-
position[split] = r["_row"] + 1
|
| 175 |
-
rows.append(r)
|
| 176 |
self.status["loaded"] = len(rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
self.datasets = present
|
| 178 |
# the explorer's own assets
|
| 179 |
self.status.update(stage="reading assets")
|
|
@@ -215,17 +370,19 @@ class Catalog:
|
|
| 215 |
r["_glb"] = glb.get(r["id"])
|
| 216 |
r["_parts"] = parts.get(r["id"])
|
| 217 |
r["_meta"] = " ".join([r["_name"], r["_family"], SOURCES.get(r["source"], r["source"]),
|
| 218 |
-
r.get("attribution") or "", r["id"]
|
|
|
|
| 219 |
r["_code"] = (r.get("program") or "").lower()
|
| 220 |
by_id = {r["id"]: i for i, r in enumerate(rows)}
|
| 221 |
-
order = ranked(rows)
|
| 222 |
keys = [d.key for d in self.datasets]
|
| 223 |
self.group = np.array([keys.index(r["_dataset"]) for r in rows], dtype=np.int16)
|
| 224 |
fams = sorted({(r["_dataset"], r["family"]) for r in rows})
|
| 225 |
self.fam_index = {f: i for i, f in enumerate(fams)}
|
| 226 |
self.fam = np.array([self.fam_index[(r["_dataset"], r["family"])] for r in rows], dtype=np.int32)
|
|
|
|
| 227 |
self.joints = np.array([r.get("n_joints") or 0 for r in rows], dtype=np.int32)
|
| 228 |
-
self.has_glb = np.array([bool(r["_glb"]) for r in rows])
|
| 229 |
self.part = np.array([r["_part"] for r in rows], dtype=bool)
|
| 230 |
self.order = np.array(order, dtype=np.int64)
|
| 231 |
# embeddings aligned on rows; a row with none scores -inf
|
|
@@ -268,8 +425,8 @@ class Catalog:
|
|
| 268 |
for r in self.rows:
|
| 269 |
r["_glb"] = glb.get(r["id"])
|
| 270 |
r["_parts"] = parts.get(r["id"])
|
| 271 |
-
self.has_glb = np.array([bool(r["_glb"]) for r in self.rows])
|
| 272 |
-
self.order = np.array(ranked(self.rows), dtype=np.int64)
|
| 273 |
self.assets_rev = rev
|
| 274 |
self.status["glb"] = int(self.has_glb.sum())
|
| 275 |
return True
|
|
@@ -287,29 +444,41 @@ class Catalog:
|
|
| 287 |
revision=self.assets_rev, local_dir=self.assets_dir)
|
| 288 |
return local if local.is_file() else None
|
| 289 |
|
| 290 |
-
def render(self, i: int) -> bytes:
|
| 291 |
-
off, n = self.rows[i][
|
| 292 |
with open(self.blob_path, "rb") as fh:
|
| 293 |
return os.pread(fh.fileno(), n, off)
|
| 294 |
|
| 295 |
def facets(self) -> dict:
|
| 296 |
"""Every count the page shows, off the rows: per dataset its objects (parts apart), the
|
| 297 |
articulated, the GLBs, its families."""
|
| 298 |
-
import collections # noqa: PLC0415
|
| 299 |
out = []
|
| 300 |
whole = ~self.part
|
| 301 |
for k, d in enumerate(self.datasets):
|
| 302 |
mask = (self.group == k) & whole
|
| 303 |
-
|
|
|
|
| 304 |
out.append({"key": d.key, "label": d.label, "repo": d.repo, "blurb": d.blurb, "count": int(mask.sum()),
|
| 305 |
"parts": int(((self.group == k) & self.part).sum()),
|
| 306 |
"articulated": int(((self.joints > 0) & mask).sum()), "glb": int((self.has_glb & mask).sum()),
|
| 307 |
"families": sorted(([f, family_label(d.key, f) or "Unclassified", n] for f, n in fams.items()),
|
| 308 |
key=lambda x: (-x[2], x[1]))})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
return {"datasets": out, "total": int(whole.sum()), "parts": int(self.part.sum()),
|
| 310 |
"glb": int((self.has_glb & whole).sum()), "semantic": self.emb is not None}
|
| 311 |
|
| 312 |
-
def mask(self, dataset: str | None, family: str | None, articulated: bool, glb: bool, parts: bool = False
|
|
|
|
| 313 |
"""The rows a view shows: parts only when asked for, and then only parts."""
|
| 314 |
m = self.part.copy() if parts else ~self.part
|
| 315 |
keys = [d.key for d in self.datasets]
|
|
@@ -322,10 +491,13 @@ class Catalog:
|
|
| 322 |
m &= self.joints > 0
|
| 323 |
if glb:
|
| 324 |
m &= self.has_glb
|
|
|
|
|
|
|
| 325 |
return m
|
| 326 |
|
| 327 |
def card(self, i: int) -> dict:
|
| 328 |
r = self.rows[i]
|
| 329 |
return {"id": r["id"], "name": r["_name"], "dataset": r["_dataset"], "family": r["_family"],
|
| 330 |
"joints": r.get("n_joints") or 0, "glb": bool(r["_glb"]), "loc": r["_loc"], "part": r["_part"],
|
| 331 |
-
"parts": r.get("_parts") or 0
|
|
|
|
|
|
| 10 |
"""
|
| 11 |
from __future__ import annotations
|
| 12 |
|
| 13 |
+
import io
|
| 14 |
import json
|
| 15 |
import math
|
| 16 |
import os
|
|
|
|
| 18 |
import re
|
| 19 |
import threading
|
| 20 |
import time
|
| 21 |
+
from collections import Counter, deque
|
| 22 |
+
from collections.abc import Iterator
|
| 23 |
from dataclasses import dataclass, field
|
| 24 |
+
from itertools import groupby, islice
|
| 25 |
+
from pathlib import Path, PurePosixPath
|
| 26 |
|
| 27 |
#: An entry function's names that say nothing of the object.
|
| 28 |
GENERIC = {"build", "main", "make", "model", "asset", "part", "object", "create", "result", "body", "shape",
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
def display_name(row: dict) -> str:
|
| 52 |
+
"""A taxonomy subject when available, else the program's entry, first part, source title or family."""
|
| 53 |
+
if row.get("subject"):
|
| 54 |
+
return humanize(row["subject"])
|
| 55 |
entry = row.get("entry")
|
| 56 |
if entry and entry.lower() not in GENERIC:
|
| 57 |
return humanize(entry)
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
SOURCES = {"objaverse": "Objaverse", "simready": "NVIDIA SimReady", "articraft": "Articraft",
|
| 76 |
+
"zero-to-cad": "Zero-To-CAD", "cadfs": "CADFS", "automate": "AutoMate", "nature": "Nature"}
|
| 77 |
|
| 78 |
|
| 79 |
def glb_paths(manifest: dict) -> dict[str, str]:
|
|
|
|
| 84 |
return {i: f"glb/{g}/{i}.glb" for g, ids in manifest.get("glb", {}).items() for i in ids}
|
| 85 |
|
| 86 |
|
| 87 |
+
#: The reconstruction order with no query. Above the F floor first; then
|
| 88 |
#: by parts, on a log2 scale capped at 2**PART_CAP (32 parts and 300 rank alike: one source's
|
| 89 |
#: hundred-part objects do not take the first page); then by F, in steps of F_STEP (1.0 with 0.98);
|
| 90 |
#: within such a tier, each source in a seeded order and the sources taken in turn.
|
| 91 |
F_FLOOR = 0.95
|
| 92 |
PART_CAP = 5
|
| 93 |
F_STEP = 0.02
|
| 94 |
+
NATURE_FLOOR = 0.8
|
| 95 |
+
TRIANGLES_PER_PART = 1024
|
| 96 |
+
SHOWCASE_SIZE = 48
|
| 97 |
|
| 98 |
|
| 99 |
def tier(f: float | None, parts: int | None) -> tuple:
|
|
|
|
| 104 |
return (f >= F_FLOOR, b, math.floor(min(f, 0.999) / F_STEP))
|
| 105 |
|
| 106 |
|
| 107 |
+
def semantic_score(row: dict) -> float | None:
|
| 108 |
+
value = row.get("semantic_score")
|
| 109 |
+
return value if isinstance(value, (int, float)) and 0 <= value <= 1 else None
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def nature_complexity(row: dict) -> int:
|
| 113 |
+
"""Log₂ of the mesh-node count or its triangle-based estimate, capped at 32 parts."""
|
| 114 |
+
parts = row.get("_parts")
|
| 115 |
+
if not isinstance(parts, int) or parts <= 0:
|
| 116 |
+
triangles = row.get("triangles")
|
| 117 |
+
parts = max(1, triangles // TRIANGLES_PER_PART) if isinstance(triangles, int) and triangles > 0 else 0
|
| 118 |
+
return min(parts.bit_length() - 1, PART_CAP)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def nature_showcase(rows: list[dict], nature: list[tuple], demote_families: tuple[str, ...]) -> Iterator[tuple]:
|
| 122 |
+
"""Offer one asset per domain in each round over a tied Nature tier."""
|
| 123 |
+
demoted = {label.casefold() for label in demote_families}
|
| 124 |
+
for _, group in groupby(nature, key=lambda entry: entry[:3]):
|
| 125 |
+
domains = {}
|
| 126 |
+
for entry in group:
|
| 127 |
+
row = rows[entry[-1]]
|
| 128 |
+
if family_label("nature", row["family"]).casefold() not in demoted:
|
| 129 |
+
domains.setdefault(row.get("domain"), deque()).append(entry)
|
| 130 |
+
if marine := domains.get("algae-seaweed-corals"):
|
| 131 |
+
coral = next((entry for entry in marine if "corals" in rows[entry[-1]]["family"].split("-")), None)
|
| 132 |
+
if coral is not None:
|
| 133 |
+
marine.remove(coral)
|
| 134 |
+
marine.appendleft(coral)
|
| 135 |
+
while domains:
|
| 136 |
+
for domain, queue in list(domains.items()):
|
| 137 |
+
yield queue.popleft()
|
| 138 |
+
if not queue:
|
| 139 |
+
del domains[domain]
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def ranked(rows: list[dict], seed: int = 0, *, showcase_demote_families: tuple[str, ...] = ()) -> list[int]:
|
| 143 |
"""Row indices in the explorer's order (`tier`, then the sources in turn within a tier, each
|
| 144 |
in a seeded order). `rows` carry `id`, `source`, `f_score` and `_parts`."""
|
| 145 |
rng = random.Random(seed)
|
| 146 |
+
legacy = [i for i, r in enumerate(rows) if r["source"] != "nature"]
|
| 147 |
+
shuffle = {i: rng.random() for i in legacy}
|
| 148 |
+
tiers = {i: tier(rows[i].get("f_score"), rows[i].get("_parts")) for i in legacy}
|
| 149 |
turn, seen = {}, Counter()
|
| 150 |
+
for i in sorted(legacy, key=shuffle.get):
|
| 151 |
k = (tiers[i], rows[i]["source"])
|
| 152 |
turn[i] = seen[k]
|
| 153 |
seen[k] += 1
|
| 154 |
+
ordered = sorted(legacy, key=lambda i: (tuple(-x for x in tiers[i]), turn[i], shuffle[i]))
|
| 155 |
+
# At equal complexity and score, take one per family per round.
|
| 156 |
+
seen.clear()
|
| 157 |
+
nature = []
|
| 158 |
+
candidates = sorted((i for i, r in enumerate(rows) if r["source"] == "nature"), key=lambda i: rows[i]["id"])
|
| 159 |
+
for i in candidates:
|
| 160 |
+
r = rows[i]
|
| 161 |
+
score = semantic_score(r)
|
| 162 |
+
band = 2 if score is None else int(score < NATURE_FLOOR)
|
| 163 |
+
nature_tier = (band, -nature_complexity(r), -(score or 0))
|
| 164 |
+
key = (nature_tier, r["family"])
|
| 165 |
+
nature.append((*nature_tier, seen[key], r["id"], i))
|
| 166 |
+
seen[key] += 1
|
| 167 |
+
nature.sort()
|
| 168 |
+
featured = list(islice(nature_showcase(rows, nature, showcase_demote_families), SHOWCASE_SIZE))
|
| 169 |
+
used = {entry[-1] for entry in featured}
|
| 170 |
+
nature = featured + [entry for entry in nature if entry[-1] not in used]
|
| 171 |
+
split = next((n for n, entry in enumerate(nature) if entry[0] != 0), len(nature))
|
| 172 |
+
above = iter(entry[-1] for entry in nature[:split])
|
| 173 |
+
mixed = []
|
| 174 |
+
# All takes one Nature asset per round of the existing dataset groups.
|
| 175 |
+
group_count = max(1, len({rows[i].get("_dataset", rows[i]["source"]) for i in legacy}))
|
| 176 |
+
for n, i in enumerate(ordered, 1):
|
| 177 |
+
mixed.append(i)
|
| 178 |
+
if n % group_count == 0 and (organic := next(above, None)) is not None:
|
| 179 |
+
mixed.append(organic)
|
| 180 |
+
return mixed + list(above) + [entry[-1] for entry in nature[split:]]
|
| 181 |
|
| 182 |
|
| 183 |
@dataclass
|
|
|
|
| 189 |
parts_group: str | None = None # a group whose rows are parts of the others, shown on request
|
| 190 |
|
| 191 |
|
| 192 |
+
def hub_rel(value: str | None, directory: str, suffix: str) -> str | None:
|
| 193 |
+
"""A relative path belonging to a published media tree."""
|
| 194 |
+
if not isinstance(value, str) or any(c in value for c in "\\%?#\0"):
|
| 195 |
+
return None
|
| 196 |
+
path = PurePosixPath(value)
|
| 197 |
+
if len(path.parts) >= 2 and path.parts[0] == directory and ".." not in path.parts and path.suffix == suffix:
|
| 198 |
+
return path.as_posix()
|
| 199 |
+
return None
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def cycles_file(repo: Path, value: str | None) -> Path | None:
|
| 203 |
+
if rel := hub_rel(value, "cycles", ".webp"):
|
| 204 |
+
try:
|
| 205 |
+
path = (repo / rel).resolve()
|
| 206 |
+
except (OSError, RuntimeError): # unavailable file or symlink loop
|
| 207 |
+
return None
|
| 208 |
+
if path.is_relative_to(repo.resolve()) and path.is_file():
|
| 209 |
+
return path
|
| 210 |
+
return None
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def read_rows(ds: Dataset, local: Path, splits: tuple[str, ...] | None):
|
| 214 |
+
"""Yield the Hub row, the Hub split name, standard PNG and optional full-size Cycles path."""
|
| 215 |
+
import pyarrow.parquet as pq # noqa: PLC0415
|
| 216 |
+
position = Counter()
|
| 217 |
+
for f in sorted(local.glob("data/*/*.parquet")):
|
| 218 |
+
split = f.name.split("-", 1)[0]
|
| 219 |
+
if splits and split not in splits:
|
| 220 |
+
continue
|
| 221 |
+
for batch in pq.ParquetFile(f).iter_batches():
|
| 222 |
+
for r in batch.to_pylist():
|
| 223 |
+
r["_row"] = position[split]
|
| 224 |
+
position[split] += 1
|
| 225 |
+
cycles = None
|
| 226 |
+
if ds.key == "nature":
|
| 227 |
+
if not isinstance(r.get("id"), str) or not r["id"].strip() or not isinstance(r.get("program"), str):
|
| 228 |
+
continue
|
| 229 |
+
for field in ("prompt", "domain", "subject", "style", "family", "entry", "attribution",
|
| 230 |
+
"license", "license_status", "source_license", "asset_id", "sand3d_version"):
|
| 231 |
+
value = r.get(field)
|
| 232 |
+
r[field] = (value.strip() or None) if isinstance(value, str) else None
|
| 233 |
+
for field in ("triangles", "n_joints", "usda_bytes"):
|
| 234 |
+
value = r.get(field)
|
| 235 |
+
r[field] = value if isinstance(value, int) and value >= 0 else None
|
| 236 |
+
r.update(source="nature", source_group="nature", semantic_score=semantic_score(r),
|
| 237 |
+
split="val" if split == "validation" else "train", f_score=None,
|
| 238 |
+
usda_path=hub_rel(r.get("usda_path"), "usda", ".usda"))
|
| 239 |
+
cycles = cycles_file(local, r.get("cycles_path"))
|
| 240 |
+
render = r.pop("render", None)
|
| 241 |
+
png = render.get("bytes") if isinstance(render, dict) else b""
|
| 242 |
+
png = png if isinstance(png, bytes) else b""
|
| 243 |
+
if ds.key != "nature" or png or cycles is not None:
|
| 244 |
+
yield r, split, png, cycles
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def thumbnail(path: Path) -> bytes | None:
|
| 248 |
+
from PIL import Image # noqa: PLC0415
|
| 249 |
+
try:
|
| 250 |
+
with Image.open(path) as im:
|
| 251 |
+
if im.format != "WEBP" or im.size != (512, 512):
|
| 252 |
+
return None
|
| 253 |
+
im.thumbnail((256, 256), Image.Resampling.LANCZOS)
|
| 254 |
+
out = io.BytesIO()
|
| 255 |
+
im.save(out, "WEBP", quality=85)
|
| 256 |
+
return out.getvalue()
|
| 257 |
+
except (OSError, Image.DecompressionBombError):
|
| 258 |
+
return None
|
| 259 |
+
|
| 260 |
+
|
| 261 |
@dataclass
|
| 262 |
class Catalog:
|
| 263 |
datasets: list[Dataset]
|
| 264 |
root: Path
|
| 265 |
+
showcase_demote_families: tuple[str, ...] = ()
|
| 266 |
status: dict = field(default_factory=lambda: {"ready": False, "stage": "starting", "loaded": 0})
|
| 267 |
rows: list[dict] = field(default_factory=list)
|
| 268 |
by_id: dict[str, int] = field(default_factory=dict)
|
|
|
|
| 270 |
|
| 271 |
# ------------------------------------------------------------------ load
|
| 272 |
def load(self, token: str | None, assets_repo: str | None, splits: tuple[str, ...] | None = None,
|
| 273 |
+
assets_dir: Path | None = None, local_hub: Path | None = None) -> None:
|
| 274 |
import numpy as np # noqa: PLC0415
|
|
|
|
| 275 |
from huggingface_hub import snapshot_download # noqa: PLC0415
|
| 276 |
t0 = time.time()
|
| 277 |
self.root.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 283 |
for ds in self.datasets:
|
| 284 |
self.status.update(stage=f"downloading {ds.label}")
|
| 285 |
pats = [f"data/*/{s}-*.parquet" for s in splits] if splits else ["data/*/*.parquet"]
|
| 286 |
+
if ds.key == "nature":
|
| 287 |
+
pats.append("cycles/*/*.webp")
|
| 288 |
try:
|
| 289 |
+
if local_hub is not None:
|
| 290 |
+
local = local_hub / ds.repo.split("/")[-1]
|
| 291 |
+
if not local.is_dir():
|
| 292 |
+
continue
|
| 293 |
+
else:
|
| 294 |
+
local = Path(snapshot_download(ds.repo, repo_type="dataset", token=token,
|
| 295 |
+
local_dir=self.root / "hub" / ds.key, allow_patterns=pats))
|
| 296 |
except RepositoryNotFoundError: # listed before it is published: shown once it is
|
| 297 |
self.status.setdefault("missing", []).append(ds.repo)
|
| 298 |
continue
|
| 299 |
+
except Exception as exc: # noqa: BLE001 — a failed Nature download leaves the other datasets usable
|
| 300 |
+
if ds.key != "nature":
|
| 301 |
+
raise
|
| 302 |
+
self.status["nature_error"] = f"{type(exc).__name__}: {exc}"[:300]
|
| 303 |
+
continue
|
| 304 |
self.status.update(stage=f"reading {ds.label}")
|
| 305 |
+
start, offset = len(rows), blob.tell()
|
| 306 |
+
try:
|
| 307 |
+
for r, split, png, cycles in read_rows(ds, local, splits):
|
| 308 |
+
r["_render"] = (blob.tell(), len(png))
|
| 309 |
+
blob.write(png)
|
| 310 |
+
if cycles is not None:
|
| 311 |
+
if thumb := thumbnail(cycles):
|
| 312 |
+
r["_thumb"] = (blob.tell(), len(thumb))
|
| 313 |
+
r["_cycles"] = cycles
|
| 314 |
+
blob.write(thumb)
|
| 315 |
+
elif not png:
|
| 316 |
+
continue
|
| 317 |
+
r["_dataset"] = ds.key
|
| 318 |
+
r["family"] = r.get("family") or ""
|
| 319 |
+
r["_part"] = bool(ds.parts_group) and r.get("source_group") == ds.parts_group
|
| 320 |
+
r["_split_name"] = split
|
| 321 |
+
rows.append(r)
|
|
|
|
|
|
|
|
|
|
| 322 |
self.status["loaded"] = len(rows)
|
| 323 |
+
except (OSError, ValueError) as exc:
|
| 324 |
+
if ds.key != "nature":
|
| 325 |
+
raise
|
| 326 |
+
del rows[start:]
|
| 327 |
+
blob.seek(offset)
|
| 328 |
+
blob.truncate()
|
| 329 |
+
self.status.update(nature_error=f"{type(exc).__name__}: {exc}"[:300], loaded=len(rows))
|
| 330 |
+
if len(rows) > start or ds.key != "nature":
|
| 331 |
+
present.append(ds)
|
| 332 |
self.datasets = present
|
| 333 |
# the explorer's own assets
|
| 334 |
self.status.update(stage="reading assets")
|
|
|
|
| 370 |
r["_glb"] = glb.get(r["id"])
|
| 371 |
r["_parts"] = parts.get(r["id"])
|
| 372 |
r["_meta"] = " ".join([r["_name"], r["_family"], SOURCES.get(r["source"], r["source"]),
|
| 373 |
+
r.get("attribution") or "", r["id"], r.get("subject") or "",
|
| 374 |
+
r.get("prompt") or ""]).lower()
|
| 375 |
r["_code"] = (r.get("program") or "").lower()
|
| 376 |
by_id = {r["id"]: i for i, r in enumerate(rows)}
|
| 377 |
+
order = ranked(rows, showcase_demote_families=self.showcase_demote_families)
|
| 378 |
keys = [d.key for d in self.datasets]
|
| 379 |
self.group = np.array([keys.index(r["_dataset"]) for r in rows], dtype=np.int16)
|
| 380 |
fams = sorted({(r["_dataset"], r["family"]) for r in rows})
|
| 381 |
self.fam_index = {f: i for i, f in enumerate(fams)}
|
| 382 |
self.fam = np.array([self.fam_index[(r["_dataset"], r["family"])] for r in rows], dtype=np.int32)
|
| 383 |
+
self.domain = np.array([r.get("domain") or "" for r in rows], dtype=str)
|
| 384 |
self.joints = np.array([r.get("n_joints") or 0 for r in rows], dtype=np.int32)
|
| 385 |
+
self.has_glb = np.array([bool(r["_glb"]) for r in rows], dtype=bool)
|
| 386 |
self.part = np.array([r["_part"] for r in rows], dtype=bool)
|
| 387 |
self.order = np.array(order, dtype=np.int64)
|
| 388 |
# embeddings aligned on rows; a row with none scores -inf
|
|
|
|
| 425 |
for r in self.rows:
|
| 426 |
r["_glb"] = glb.get(r["id"])
|
| 427 |
r["_parts"] = parts.get(r["id"])
|
| 428 |
+
self.has_glb = np.array([bool(r["_glb"]) for r in self.rows], dtype=bool)
|
| 429 |
+
self.order = np.array(ranked(self.rows, showcase_demote_families=self.showcase_demote_families), dtype=np.int64)
|
| 430 |
self.assets_rev = rev
|
| 431 |
self.status["glb"] = int(self.has_glb.sum())
|
| 432 |
return True
|
|
|
|
| 444 |
revision=self.assets_rev, local_dir=self.assets_dir)
|
| 445 |
return local if local.is_file() else None
|
| 446 |
|
| 447 |
+
def render(self, i: int, field: str = "_render") -> bytes:
|
| 448 |
+
off, n = self.rows[i][field]
|
| 449 |
with open(self.blob_path, "rb") as fh:
|
| 450 |
return os.pread(fh.fileno(), n, off)
|
| 451 |
|
| 452 |
def facets(self) -> dict:
|
| 453 |
"""Every count the page shows, off the rows: per dataset its objects (parts apart), the
|
| 454 |
articulated, the GLBs, its families."""
|
|
|
|
| 455 |
out = []
|
| 456 |
whole = ~self.part
|
| 457 |
for k, d in enumerate(self.datasets):
|
| 458 |
mask = (self.group == k) & whole
|
| 459 |
+
records = [r for r in self.rows if r["_dataset"] == d.key and not r["_part"]]
|
| 460 |
+
fams = Counter(r["family"] for r in records)
|
| 461 |
out.append({"key": d.key, "label": d.label, "repo": d.repo, "blurb": d.blurb, "count": int(mask.sum()),
|
| 462 |
"parts": int(((self.group == k) & self.part).sum()),
|
| 463 |
"articulated": int(((self.joints > 0) & mask).sum()), "glb": int((self.has_glb & mask).sum()),
|
| 464 |
"families": sorted(([f, family_label(d.key, f) or "Unclassified", n] for f, n in fams.items()),
|
| 465 |
key=lambda x: (-x[2], x[1]))})
|
| 466 |
+
if d.key == "nature":
|
| 467 |
+
domains = {}
|
| 468 |
+
for r in records:
|
| 469 |
+
if domain := r.get("domain"):
|
| 470 |
+
domains.setdefault(domain, Counter())[r["family"]] += 1
|
| 471 |
+
out[-1]["domains"] = [
|
| 472 |
+
{"key": domain, "label": humanize(domain), "count": sum(families.values()),
|
| 473 |
+
"families": sorted(([f, family_label(d.key, f), n] for f, n in families.items()),
|
| 474 |
+
key=lambda x: (-x[2], x[1]))}
|
| 475 |
+
for domain, families in sorted(domains.items())
|
| 476 |
+
]
|
| 477 |
return {"datasets": out, "total": int(whole.sum()), "parts": int(self.part.sum()),
|
| 478 |
"glb": int((self.has_glb & whole).sum()), "semantic": self.emb is not None}
|
| 479 |
|
| 480 |
+
def mask(self, dataset: str | None, family: str | None, articulated: bool, glb: bool, parts: bool = False,
|
| 481 |
+
domain: str | None = None):
|
| 482 |
"""The rows a view shows: parts only when asked for, and then only parts."""
|
| 483 |
m = self.part.copy() if parts else ~self.part
|
| 484 |
keys = [d.key for d in self.datasets]
|
|
|
|
| 491 |
m &= self.joints > 0
|
| 492 |
if glb:
|
| 493 |
m &= self.has_glb
|
| 494 |
+
if dataset == "nature" and domain:
|
| 495 |
+
m &= self.domain == domain
|
| 496 |
return m
|
| 497 |
|
| 498 |
def card(self, i: int) -> dict:
|
| 499 |
r = self.rows[i]
|
| 500 |
return {"id": r["id"], "name": r["_name"], "dataset": r["_dataset"], "family": r["_family"],
|
| 501 |
"joints": r.get("n_joints") or 0, "glb": bool(r["_glb"]), "loc": r["_loc"], "part": r["_part"],
|
| 502 |
+
"parts": r.get("_parts") or 0,
|
| 503 |
+
"image_url": f"/cycles/{r['id']}/256.webp" if "_thumb" in r else f"/r/{r['id']}.png"}
|
app/main.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
Environment: `HF_TOKEN` (a Space secret, read access to the private datasets), `EXPLORER_DATA`
|
| 4 |
(where the catalog is written, default /tmp/sand3d-explorer), `EXPLORER_SPLITS` (comma list, to
|
| 5 |
load only some splits while developing), `EXPLORER_ASSETS_DIR` (a local copy of the assets
|
| 6 |
-
instead of the Hub's).
|
| 7 |
"""
|
| 8 |
from __future__ import annotations
|
| 9 |
|
|
@@ -25,7 +25,8 @@ STATIC = HERE / "static"
|
|
| 25 |
PAGE = 60
|
| 26 |
|
| 27 |
cat = Catalog([Dataset(**d) for d in CONFIG["datasets"]],
|
| 28 |
-
Path(os.environ.get("EXPLORER_DATA", "/tmp/sand3d-explorer"))
|
|
|
|
| 29 |
encoder = search.Encoder(None)
|
| 30 |
cache = search.Cache()
|
| 31 |
|
|
@@ -34,7 +35,9 @@ def _load() -> None:
|
|
| 34 |
try:
|
| 35 |
splits = tuple(s for s in os.environ.get("EXPLORER_SPLITS", "").split(",") if s) or None
|
| 36 |
adir = os.environ.get("EXPLORER_ASSETS_DIR")
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
if cat.emb is not None:
|
| 39 |
encoder.spec = getattr(cat, "model", None)
|
| 40 |
cat.status["stage"] = "loading the text encoder"
|
|
@@ -84,22 +87,29 @@ def status():
|
|
| 84 |
@app.get("/api/facets")
|
| 85 |
def facets():
|
| 86 |
_ready()
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
@app.get("/api/search")
|
| 91 |
def do_search(q: str = "", mode: str = "meaning", dataset: str = "", family: str = "",
|
| 92 |
-
|
|
|
|
| 93 |
limit: int = Query(PAGE, ge=1, le=200)):
|
| 94 |
_ready()
|
| 95 |
q = q.strip()[:200]
|
| 96 |
-
used = "
|
| 97 |
-
|
|
|
|
|
|
|
| 98 |
|
| 99 |
def make():
|
| 100 |
-
m = cat.mask(dataset or None, family or None, articulated, glb, parts)
|
| 101 |
if used == "meaning":
|
| 102 |
-
return search.
|
| 103 |
return search.words(cat, q, m)
|
| 104 |
|
| 105 |
hits = cache.get(key, make)
|
|
@@ -116,15 +126,21 @@ def obj(oid: str):
|
|
| 116 |
r = cat.rows[i]
|
| 117 |
ds = next(d for d in cat.datasets if d.key == r["_dataset"])
|
| 118 |
split = r["_split_name"]
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
"source_label": SOURCES.get(r["source"], r["source"]), "family_raw": r["family"],
|
| 121 |
"split": r["split"], "f_score": r.get("f_score"), "license": r.get("license"),
|
| 122 |
"source_license": r.get("source_license"), "license_status": r.get("license_status"),
|
| 123 |
"attribution": r.get("attribution"), "asset_id": r.get("asset_id"),
|
| 124 |
"sand3d_version": r.get("sand3d_version"), "usda_bytes": r.get("usda_bytes"),
|
| 125 |
-
"dataset_label": ds.label, "repo": ds.repo,
|
| 126 |
-
"row_url":
|
| 127 |
-
"usda_url": f"{
|
|
|
|
| 128 |
"glb_url": _glb_url(r), "assembly": _assembly(r), "library_url": CONFIG["library_url"], "has_similar": bool(cat.emb is not None and cat.emb_present[i])}
|
| 129 |
|
| 130 |
|
|
@@ -173,6 +189,22 @@ def glb(oid: str):
|
|
| 173 |
return FileResponse(path, media_type="model/gltf-binary", headers={"Cache-Control": "private, max-age=86400"})
|
| 174 |
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
#: the page itself is always revalidated: its assets carry a version (`?v=`), the page does not
|
| 177 |
PAGE_HEADERS = {"Cache-Control": "no-cache"}
|
| 178 |
|
|
|
|
| 3 |
Environment: `HF_TOKEN` (a Space secret, read access to the private datasets), `EXPLORER_DATA`
|
| 4 |
(where the catalog is written, default /tmp/sand3d-explorer), `EXPLORER_SPLITS` (comma list, to
|
| 5 |
load only some splits while developing), `EXPLORER_ASSETS_DIR` (a local copy of the assets
|
| 6 |
+
instead of the Hub's), `EXPLORER_LOCAL_HUB` (local dataset directories instead of Hub downloads).
|
| 7 |
"""
|
| 8 |
from __future__ import annotations
|
| 9 |
|
|
|
|
| 25 |
PAGE = 60
|
| 26 |
|
| 27 |
cat = Catalog([Dataset(**d) for d in CONFIG["datasets"]],
|
| 28 |
+
Path(os.environ.get("EXPLORER_DATA", "/tmp/sand3d-explorer")),
|
| 29 |
+
showcase_demote_families=tuple(CONFIG.get("showcase_demote_families", ())))
|
| 30 |
encoder = search.Encoder(None)
|
| 31 |
cache = search.Cache()
|
| 32 |
|
|
|
|
| 35 |
try:
|
| 36 |
splits = tuple(s for s in os.environ.get("EXPLORER_SPLITS", "").split(",") if s) or None
|
| 37 |
adir = os.environ.get("EXPLORER_ASSETS_DIR")
|
| 38 |
+
local = os.environ.get("EXPLORER_LOCAL_HUB")
|
| 39 |
+
cat.load(os.environ.get("HF_TOKEN"), None if local else CONFIG.get("assets_repo"), splits,
|
| 40 |
+
Path(adir) if adir else None, Path(local) if local else None)
|
| 41 |
if cat.emb is not None:
|
| 42 |
encoder.spec = getattr(cat, "model", None)
|
| 43 |
cat.status["stage"] = "loading the text encoder"
|
|
|
|
| 87 |
@app.get("/api/facets")
|
| 88 |
def facets():
|
| 89 |
_ready()
|
| 90 |
+
info = cat.facets()
|
| 91 |
+
default = CONFIG.get("default_dataset", "")
|
| 92 |
+
return {**info, "semantic": encoder.model is not None, "library_url": CONFIG["library_url"],
|
| 93 |
+
"hub_url": CONFIG["hub_url"],
|
| 94 |
+
"default_dataset": default if any(d["key"] == default for d in info["datasets"]) else ""}
|
| 95 |
|
| 96 |
|
| 97 |
@app.get("/api/search")
|
| 98 |
def do_search(q: str = "", mode: str = "meaning", dataset: str = "", family: str = "",
|
| 99 |
+
domain: str = "", articulated: bool = False, glb: bool = False, parts: bool = False,
|
| 100 |
+
offset: int = Query(0, ge=0),
|
| 101 |
limit: int = Query(PAGE, ge=1, le=200)):
|
| 102 |
_ready()
|
| 103 |
q = q.strip()[:200]
|
| 104 |
+
used = "all" if not q else "words"
|
| 105 |
+
if q and mode == "meaning" and dataset != "nature" and encoder.model is not None:
|
| 106 |
+
used = "meaning"
|
| 107 |
+
key = (used, q.lower(), dataset, domain, family, articulated, glb, parts)
|
| 108 |
|
| 109 |
def make():
|
| 110 |
+
m = cat.mask(dataset or None, family or None, articulated, glb, parts, domain or None)
|
| 111 |
if used == "meaning":
|
| 112 |
+
return search.meaning(cat, q, encoder.encode(q), m)
|
| 113 |
return search.words(cat, q, m)
|
| 114 |
|
| 115 |
hits = cache.get(key, make)
|
|
|
|
| 126 |
r = cat.rows[i]
|
| 127 |
ds = next(d for d in cat.datasets if d.key == r["_dataset"])
|
| 128 |
split = r["_split_name"]
|
| 129 |
+
hub = f"{CONFIG['hub_url']}/{ds.repo}"
|
| 130 |
+
row_url = f"{hub}/viewer/default/{split}?row={r['_row']}"
|
| 131 |
+
card = cat.card(i)
|
| 132 |
+
nature = {k: r.get(k) for k in ("prompt", "domain", "subject", "style", "semantic_score", "triangles")} \
|
| 133 |
+
if ds.key == "nature" else {}
|
| 134 |
+
return {**card, **nature, "program": r["program"], "entry": r.get("entry"), "source": r["source"],
|
| 135 |
"source_label": SOURCES.get(r["source"], r["source"]), "family_raw": r["family"],
|
| 136 |
"split": r["split"], "f_score": r.get("f_score"), "license": r.get("license"),
|
| 137 |
"source_license": r.get("source_license"), "license_status": r.get("license_status"),
|
| 138 |
"attribution": r.get("attribution"), "asset_id": r.get("asset_id"),
|
| 139 |
"sand3d_version": r.get("sand3d_version"), "usda_bytes": r.get("usda_bytes"),
|
| 140 |
+
"dataset_label": ds.label, "repo": ds.repo, "dataset_url": hub,
|
| 141 |
+
"row_url": row_url, "row_label": "Row on the Hub",
|
| 142 |
+
"usda_url": f"{hub}/blob/main/{r['usda_path']}" if r.get("usda_path") else None,
|
| 143 |
+
"render_url": f"/cycles/{oid}/512.webp" if "_cycles" in r else card["image_url"],
|
| 144 |
"glb_url": _glb_url(r), "assembly": _assembly(r), "library_url": CONFIG["library_url"], "has_similar": bool(cat.emb is not None and cat.emb_present[i])}
|
| 145 |
|
| 146 |
|
|
|
|
| 189 |
return FileResponse(path, media_type="model/gltf-binary", headers={"Cache-Control": "private, max-age=86400"})
|
| 190 |
|
| 191 |
|
| 192 |
+
@app.get("/cycles/{oid}/{size}.webp")
|
| 193 |
+
def cycles_render(oid: str, size: int):
|
| 194 |
+
_ready()
|
| 195 |
+
i = cat.by_id.get(oid)
|
| 196 |
+
if i is None or "_cycles" not in cat.rows[i] or size not in (256, 512):
|
| 197 |
+
raise HTTPException(404)
|
| 198 |
+
headers = {"Cache-Control": "private, max-age=3600"}
|
| 199 |
+
if size == 512:
|
| 200 |
+
path = cat.rows[i]["_cycles"]
|
| 201 |
+
if path.is_file():
|
| 202 |
+
return FileResponse(path, media_type="image/webp", headers=headers)
|
| 203 |
+
if png := cat.render(i):
|
| 204 |
+
return Response(png, media_type="image/png", headers=headers)
|
| 205 |
+
return Response(cat.render(i, "_thumb"), media_type="image/webp", headers=headers)
|
| 206 |
+
|
| 207 |
+
|
| 208 |
#: the page itself is always revalidated: its assets carry a version (`?v=`), the page does not
|
| 209 |
PAGE_HEADERS = {"Cache-Control": "no-cache"}
|
| 210 |
|
app/search.py
CHANGED
|
@@ -89,6 +89,16 @@ def ranked(cat, vec, mask, exclude: int | None = None) -> list[int]:
|
|
| 89 |
return [int(i) for i in idx[np.argsort(-s, kind="stable")]]
|
| 90 |
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
class Cache:
|
| 93 |
"""The last results by query, so paging a result is a slice."""
|
| 94 |
|
|
|
|
| 89 |
return [int(i) for i in idx[np.argsort(-s, kind="stable")]]
|
| 90 |
|
| 91 |
|
| 92 |
+
def meaning(cat, query: str, vec, mask) -> list[int]:
|
| 93 |
+
"""Keep exact Nature matches searchable while their image embeddings are being prepared."""
|
| 94 |
+
named = next((i for i, dataset in enumerate(cat.datasets) if dataset.key == "nature"), None)
|
| 95 |
+
visual = ranked(cat, vec, mask)
|
| 96 |
+
if named is None:
|
| 97 |
+
return visual
|
| 98 |
+
textual = words(cat, query, mask & (cat.group == named) & ~cat.emb_present)
|
| 99 |
+
return textual + visual
|
| 100 |
+
|
| 101 |
+
|
| 102 |
class Cache:
|
| 103 |
"""The last results by query, so paging a result is a slice."""
|
| 104 |
|
config.json
CHANGED
|
@@ -10,11 +10,51 @@
|
|
| 10 |
"blurb": "NVIDIA SimReady assets, some with their mechanisms."},
|
| 11 |
{"key": "automate", "repo": "Sandflow/sand3d-automate", "label": "AutoMate",
|
| 12 |
"blurb": "Mechanical assemblies from AutoMate, each part a function of its program.",
|
| 13 |
-
"parts_group": "automate-parts"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
],
|
| 15 |
"glb_policy": {
|
| 16 |
"objaverse": "all", "cad": "all",
|
| 17 |
-
"articraft": "all", "simready": "all", "automate": "all", "automate-parts": "all"
|
| 18 |
},
|
| 19 |
"assets_repo": "Sandflow/sand3d-explorer-assets",
|
| 20 |
"library_url": "https://github.com/Sandflow-ai/sand3d",
|
|
|
|
| 10 |
"blurb": "NVIDIA SimReady assets, some with their mechanisms."},
|
| 11 |
{"key": "automate", "repo": "Sandflow/sand3d-automate", "label": "AutoMate",
|
| 12 |
"blurb": "Mechanical assemblies from AutoMate, each part a function of its program.",
|
| 13 |
+
"parts_group": "automate-parts"},
|
| 14 |
+
{"key": "nature", "repo": "Sandflow/sand3d-nature", "label": "Nature",
|
| 15 |
+
"blurb": "Plants, terrain and other organic assets generated from text prompts."}
|
| 16 |
+
],
|
| 17 |
+
"default_dataset": "nature",
|
| 18 |
+
"showcase_demote_families": [
|
| 19 |
+
"Beds and soft furnishings",
|
| 20 |
+
"Building parts and fixtures",
|
| 21 |
+
"Camping gear",
|
| 22 |
+
"Clocks and gauges",
|
| 23 |
+
"Clothing and headwear",
|
| 24 |
+
"Containers and packaging",
|
| 25 |
+
"Cookware",
|
| 26 |
+
"Electronics and optics",
|
| 27 |
+
"Farm and orchard equipment",
|
| 28 |
+
"Footwear and bags",
|
| 29 |
+
"Garden ornaments",
|
| 30 |
+
"Garden tools and equipment",
|
| 31 |
+
"Hand tools",
|
| 32 |
+
"Home appliances",
|
| 33 |
+
"Jewellery and personal care",
|
| 34 |
+
"Lighting",
|
| 35 |
+
"Machines",
|
| 36 |
+
"Musical instruments",
|
| 37 |
+
"Office and signage",
|
| 38 |
+
"Outdoor furniture",
|
| 39 |
+
"Paths steps and walls",
|
| 40 |
+
"Playground and park equipment",
|
| 41 |
+
"Power tools",
|
| 42 |
+
"Road vehicles",
|
| 43 |
+
"Ruins and fragments",
|
| 44 |
+
"Seating",
|
| 45 |
+
"Sporting equipment",
|
| 46 |
+
"Storage furniture",
|
| 47 |
+
"Street and park fixtures",
|
| 48 |
+
"Tables and desks",
|
| 49 |
+
"Tableware",
|
| 50 |
+
"Toys and games",
|
| 51 |
+
"Watercraft and aircraft",
|
| 52 |
+
"Weapons and armour",
|
| 53 |
+
"Wells pumps and fountains"
|
| 54 |
],
|
| 55 |
"glb_policy": {
|
| 56 |
"objaverse": "all", "cad": "all",
|
| 57 |
+
"articraft": "all", "simready": "all", "automate": "all", "automate-parts": "all", "nature": "all"
|
| 58 |
},
|
| 59 |
"assets_repo": "Sandflow/sand3d-explorer-assets",
|
| 60 |
"library_url": "https://github.com/Sandflow-ai/sand3d",
|
requirements.txt
CHANGED
|
@@ -4,4 +4,5 @@ uvicorn==0.54.0
|
|
| 4 |
pyarrow==26.0.1
|
| 5 |
numpy==2.4.6
|
| 6 |
huggingface_hub==2.4.0
|
|
|
|
| 7 |
open_clip_torch==3.3.0
|
|
|
|
| 4 |
pyarrow==26.0.1
|
| 5 |
numpy==2.4.6
|
| 6 |
huggingface_hub==2.4.0
|
| 7 |
+
Pillow==12.3.0
|
| 8 |
open_clip_torch==3.3.0
|
static/app.css
CHANGED
|
@@ -220,6 +220,7 @@ button, input, select { font: inherit; color: inherit; }
|
|
| 220 |
.ilabel { display: none; }
|
| 221 |
.product { display: none; }
|
| 222 |
.toolbar { position: static; } /* on a phone only the header stays: the toolbar would take a third of the screen */
|
|
|
|
| 223 |
}
|
| 224 |
@media (max-width: 900px) {
|
| 225 |
.hero, .obj-head { grid-template-columns: 1fr; }
|
|
|
|
| 220 |
.ilabel { display: none; }
|
| 221 |
.product { display: none; }
|
| 222 |
.toolbar { position: static; } /* on a phone only the header stays: the toolbar would take a third of the screen */
|
| 223 |
+
.stage-nature .still, .stage-nature .three { height: min(64vh, 100vw); }
|
| 224 |
}
|
| 225 |
@media (max-width: 900px) {
|
| 226 |
.hero, .obj-head { grid-template-columns: 1fr; }
|
static/app.js
CHANGED
|
@@ -8,7 +8,7 @@ const PAGE = 60;
|
|
| 8 |
|
| 9 |
const S = {
|
| 10 |
facets: null, labels: {},
|
| 11 |
-
q: "", mode: "meaning", dataset: "", family: "", articulated: false, glb: false, parts: false,
|
| 12 |
offset: 0, total: 0, loading: false, seq: 0, done: false,
|
| 13 |
objects: new Map(), homeScroll: 0,
|
| 14 |
};
|
|
@@ -49,9 +49,11 @@ function readURL() {
|
|
| 49 |
const p = new URLSearchParams(location.search);
|
| 50 |
S.q = p.get("q") || "";
|
| 51 |
S.mode = p.get("by") === "words" ? "words" : "meaning";
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
S.family = p.get("family") || "";
|
| 54 |
-
S.articulated = p.get("articulated") === "1";
|
| 55 |
S.glb = p.get("glb") === "1";
|
| 56 |
S.parts = p.get("parts") === "1";
|
| 57 |
}
|
|
@@ -60,11 +62,14 @@ function writeURL() {
|
|
| 60 |
const p = new URLSearchParams();
|
| 61 |
if (S.q) p.set("q", S.q);
|
| 62 |
if (S.q && S.mode === "words") p.set("by", "words");
|
| 63 |
-
if (S.
|
| 64 |
if (S.family) p.set("family", S.family);
|
| 65 |
if (S.articulated) p.set("articulated", "1");
|
| 66 |
if (S.glb) p.set("glb", "1");
|
| 67 |
if (S.parts) p.set("parts", "1");
|
|
|
|
|
|
|
|
|
|
| 68 |
const qs = p.toString();
|
| 69 |
history.replaceState(null, "", "/" + (qs ? "?" + qs : ""));
|
| 70 |
}
|
|
@@ -74,7 +79,7 @@ function drawFacets() {
|
|
| 74 |
const F = S.facets;
|
| 75 |
const art = F.datasets.reduce((a, d) => a + d.articulated, 0);
|
| 76 |
$("#stats").innerHTML = `${fmt(F.total)} objects · ${fmt(art)} articulated · ${fmt(F.glb)} viewable in 3D` +
|
| 77 |
-
(F.parts ? ` · ${fmt(F.parts)} parts
|
| 78 |
const chips = [`<button class="chip" data-ds="" aria-pressed="${!S.dataset}">All <span class="n">${fmt(F.total)}</span></button>`]
|
| 79 |
.concat(F.datasets.map((d) => `<button class="chip" data-ds="${esc(d.key)}" aria-pressed="${S.dataset === d.key}">${esc(d.label)} <span class="n">${fmt(d.count)}</span></button>`));
|
| 80 |
$("#datasets").innerHTML = chips.join("");
|
|
@@ -82,8 +87,8 @@ function drawFacets() {
|
|
| 82 |
$("#ds-list").innerHTML = F.datasets.map((d) => `
|
| 83 |
<div class="ds"><h3>${esc(d.label)} <span>${fmt(d.count)}</span></h3>
|
| 84 |
<p>${esc(d.blurb)}</p>
|
| 85 |
-
<p>${fmt(d.articulated)} articulated · ${fmt(d.families.length)} families · ${fmt(d.glb)} in 3D${d.parts ? ` · ${fmt(d.parts)} parts` : ""}</p>
|
| 86 |
-
<a href="
|
| 87 |
$("#q").value = S.q;
|
| 88 |
$("#articulated").checked = S.articulated;
|
| 89 |
$("#glb").checked = S.glb;
|
|
@@ -94,9 +99,14 @@ function drawFacets() {
|
|
| 94 |
function drawFamilies() {
|
| 95 |
const sel = $("#family");
|
| 96 |
const d = S.facets.datasets.find((x) => x.key === S.dataset);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
sel.disabled = !d;
|
| 98 |
sel.innerHTML = `<option value="">${d ? "All families" : "Pick a dataset first"}</option>` +
|
| 99 |
-
|
| 100 |
}
|
| 101 |
|
| 102 |
function drawParts() {
|
|
@@ -109,6 +119,11 @@ function drawParts() {
|
|
| 109 |
}
|
| 110 |
|
| 111 |
function drawMode() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
for (const b of $("#mode").querySelectorAll("button")) {
|
| 113 |
b.setAttribute("aria-checked", String(b.dataset.mode === S.mode));
|
| 114 |
if (b.dataset.mode === "meaning" && !S.facets.semantic) { b.disabled = true; b.title = "Semantic search is not available"; }
|
|
@@ -125,12 +140,14 @@ function bind() {
|
|
| 125 |
});
|
| 126 |
$("#datasets").addEventListener("click", (e) => {
|
| 127 |
const b = e.target.closest(".chip"); if (!b) return;
|
| 128 |
-
S.dataset = b.dataset.ds; S.family = "";
|
|
|
|
| 129 |
for (const c of $("#datasets").querySelectorAll(".chip")) c.setAttribute("aria-pressed", String(c === b));
|
| 130 |
-
drawFamilies(); drawParts(); refresh();
|
| 131 |
});
|
| 132 |
$("#parts").addEventListener("change", (e) => { S.parts = e.target.checked; S.family = ""; drawFamilies(); refresh(); });
|
| 133 |
$("#family").addEventListener("change", (e) => { S.family = e.target.value; refresh(); });
|
|
|
|
| 134 |
$("#articulated").addEventListener("change", (e) => { S.articulated = e.target.checked; refresh(); });
|
| 135 |
$("#glb").addEventListener("change", (e) => { S.glb = e.target.checked; refresh(); });
|
| 136 |
document.addEventListener("click", (e) => {
|
|
@@ -166,9 +183,9 @@ function route() {
|
|
| 166 |
$("#object").hidden = true; $("#object").innerHTML = "";
|
| 167 |
$("#home").hidden = false;
|
| 168 |
document.title = "Sand3D Explorer · Sandflow";
|
| 169 |
-
const before = JSON.stringify([S.q, S.mode, S.dataset, S.family, S.articulated, S.glb, S.parts]);
|
| 170 |
readURL(); if (!S.facets.semantic) S.mode = "words";
|
| 171 |
-
const after = JSON.stringify([S.q, S.mode, S.dataset, S.family, S.articulated, S.glb, S.parts]);
|
| 172 |
if (!$("#grid").children.length || before !== after) { drawFacets(); refresh(); }
|
| 173 |
else requestAnimationFrame(() => scrollTo(0, S.homeScroll));
|
| 174 |
}
|
|
@@ -186,7 +203,7 @@ async function more(first) {
|
|
| 186 |
if ((S.loading && !first) || S.done) return;
|
| 187 |
S.loading = true;
|
| 188 |
const seq = S.seq;
|
| 189 |
-
const p = new URLSearchParams({ q: S.q, mode: S.mode, dataset: S.dataset, family: S.family,
|
| 190 |
articulated: S.articulated, glb: S.glb, parts: S.parts, offset: S.offset, limit: PAGE });
|
| 191 |
try {
|
| 192 |
const r = await api("/api/search?" + p);
|
|
@@ -194,7 +211,7 @@ async function more(first) {
|
|
| 194 |
if (first) $("#grid").innerHTML = "";
|
| 195 |
S.total = r.total; S.offset += r.items.length; S.done = S.offset >= r.total;
|
| 196 |
$("#grid").insertAdjacentHTML("beforeend", r.items.map((c) => card(c)).join(""));
|
| 197 |
-
if (!r.total) $("#grid").innerHTML = `<p class="empty"><b>No object matches.</b> Try fewer words
|
| 198 |
const how = "containing";
|
| 199 |
$("#count").innerHTML = r.mode === "all" ? `<b>${fmt(r.total)}</b> objects`
|
| 200 |
: r.mode === "meaning" ? `Closest renders to “${esc(S.q)}”, out of <b>${fmt(r.total)}</b> objects`
|
|
@@ -213,7 +230,7 @@ function card(c, small) {
|
|
| 213 |
if (c.joints) tags.push(`<span class="tag">${c.joints} joint${c.joints > 1 ? "s" : ""}</span>`);
|
| 214 |
if (c.glb) tags.push(`<span class="tag violet">3D</span>`);
|
| 215 |
return `<a class="card" href="/o/${encodeURIComponent(c.id)}" data-id="${esc(c.id)}">
|
| 216 |
-
<div class="thumb"><img loading="lazy" decoding="async" src="
|
| 217 |
<div class="body"><div class="name" title="${esc(c.name)}">${esc(c.name)}</div>
|
| 218 |
<div class="meta">${esc(S.labels[c.dataset] || c.dataset)}${c.part ? " part" : ""}${c.family ? ` · ${esc(c.family)}` : ""}</div>
|
| 219 |
${small ? "" : `<div class="tags">${tags.join("")}</div>`}</div></a>`;
|
|
@@ -258,38 +275,43 @@ async function showObject(id) {
|
|
| 258 |
el.innerHTML = `<button class="back" data-back>${ICON.back} Back to the gallery</button><p class="empty"><b>No object ${esc(id)}.</b></p>`;
|
| 259 |
return bindBack(el);
|
| 260 |
}
|
|
|
|
| 261 |
document.title = `${o.name} · Sand3D Explorer`;
|
|
|
|
|
|
|
| 262 |
const lic = o.license_status && o.license_status !== "ok" ? ` <span class="pending">(source licence ${esc(o.license_status)})</span>` : "";
|
| 263 |
const rows = [
|
| 264 |
-
["Dataset", `<a href="
|
| 265 |
-
["Source", esc(o.source_label)],
|
| 266 |
...(o.assembly ? [["Assembly", `<a href="/o/${encodeURIComponent(o.assembly.id)}" data-nav>${esc(o.assembly.name)}</a>`]] : []),
|
| 267 |
["Family", esc(o.family || "Unclassified")],
|
| 268 |
-
["
|
| 269 |
-
|
| 270 |
["Entry", o.entry ? `<span class="mono">${esc(o.entry)}()</span>` : "The program builds the object as it runs"],
|
| 271 |
["Split", esc(o.split === "val" ? "validation" : o.split)],
|
| 272 |
-
["
|
|
|
|
| 273 |
["Licence", `${esc(o.license)}${o.source_license && o.source_license !== o.license ? `, source under ${esc(o.source_license)}` : ""}${lic}`],
|
| 274 |
-
["Attribution", esc(o.attribution)],
|
| 275 |
["Library", `sand3d ${esc(o.sand3d_version)}`],
|
| 276 |
["Id", `<span class="mono">${esc(o.id)}</span>`],
|
| 277 |
];
|
| 278 |
el.innerHTML = `
|
| 279 |
<button class="back" data-back>${ICON.back} Back to the gallery</button>
|
| 280 |
<div class="obj-head">
|
| 281 |
-
<div class="stage" id="stage">
|
| 282 |
-
${o.glb ? `<div class="stage-tabs"><button data-view="3d" aria-pressed="
|
| 283 |
<div id="stage-body"></div>
|
| 284 |
</div>
|
| 285 |
<div class="obj-info">
|
| 286 |
<p class="repere">${esc(o.dataset_label)}${o.part ? " · part" : ""}</p>
|
| 287 |
<h1>${esc(o.name)}</h1>
|
| 288 |
<p class="sub">${o.loc} lines of Python${o.joints ? ` · ${o.joints} joint${o.joints > 1 ? "s" : ""}` : ""}</p>
|
|
|
|
| 289 |
<table class="facts">${rows.map(([k, v]) => `<tr><th>${k}</th><td>${v}</td></tr>`).join("")}</table>
|
| 290 |
<div class="actions">
|
| 291 |
-
<a class="btn" href="${esc(o.row_url)}" target="_blank" rel="noopener">${ICON.ext}
|
| 292 |
-
<a class="btn" href="${esc(o.usda_url)}" target="_blank" rel="noopener">${ICON.ext} USD file</a>
|
| 293 |
<a class="btn" href="${esc(o.library_url)}" target="_blank" rel="noopener">${ICON.ext} sand3d on GitHub</a>
|
| 294 |
</div>
|
| 295 |
</div>
|
|
@@ -303,7 +325,7 @@ async function showObject(id) {
|
|
| 303 |
<div class="grid" id="similar-grid"></div>
|
| 304 |
</section>`;
|
| 305 |
bindBack(el);
|
| 306 |
-
drawStage(o,
|
| 307 |
for (const b of el.querySelectorAll(".stage-tabs button")) b.addEventListener("click", () => {
|
| 308 |
for (const x of el.querySelectorAll(".stage-tabs button")) x.setAttribute("aria-pressed", String(x === b));
|
| 309 |
drawStage(o, b.dataset.view);
|
|
@@ -329,7 +351,7 @@ function dropViewer() { if (viewer) { viewer.dispose(); viewer = null; } }
|
|
| 329 |
|
| 330 |
function drawStage(o, view) {
|
| 331 |
const body = $("#stage-body");
|
| 332 |
-
const img =
|
| 333 |
dropViewer();
|
| 334 |
if (view === "3d" && o.glb) {
|
| 335 |
body.innerHTML = `<div class="three" id="three"><img class="still poster" src="${img}" alt="${esc(o.name)}"><div class="three-loading"><div></div></div></div>
|
|
@@ -342,8 +364,8 @@ function drawStage(o, view) {
|
|
| 342 |
<span class="three-info" id="three-info"></span>
|
| 343 |
</div>`;
|
| 344 |
const host = $("#three");
|
| 345 |
-
import("/static/viewer.js?v=
|
| 346 |
-
if (
|
| 347 |
viewer = new Viewer(host, {
|
| 348 |
onReady: ({ parts }) => {
|
| 349 |
host.classList.add("ready");
|
|
@@ -359,6 +381,7 @@ function drawStage(o, view) {
|
|
| 359 |
});
|
| 360 |
return viewer.load(o.glb_url);
|
| 361 |
}).catch((e) => {
|
|
|
|
| 362 |
host.classList.add("failed");
|
| 363 |
$("#three-info") && ($("#three-info").textContent = "");
|
| 364 |
body.insertAdjacentHTML("beforeend", `<span class="stage-hint">The 3D view could not load (${esc(e.message || e)}): the render is shown instead</span>`);
|
|
|
|
| 8 |
|
| 9 |
const S = {
|
| 10 |
facets: null, labels: {},
|
| 11 |
+
q: "", mode: "meaning", dataset: "", domain: "", family: "", articulated: false, glb: false, parts: false,
|
| 12 |
offset: 0, total: 0, loading: false, seq: 0, done: false,
|
| 13 |
objects: new Map(), homeScroll: 0,
|
| 14 |
};
|
|
|
|
| 49 |
const p = new URLSearchParams(location.search);
|
| 50 |
S.q = p.get("q") || "";
|
| 51 |
S.mode = p.get("by") === "words" ? "words" : "meaning";
|
| 52 |
+
const dataset = p.get("dataset") ?? (p.size ? "" : S.facets.default_dataset);
|
| 53 |
+
S.dataset = Object.hasOwn(S.labels, dataset) ? dataset : "";
|
| 54 |
+
S.domain = p.get("domain") || "";
|
| 55 |
S.family = p.get("family") || "";
|
| 56 |
+
S.articulated = S.dataset !== "nature" && p.get("articulated") === "1";
|
| 57 |
S.glb = p.get("glb") === "1";
|
| 58 |
S.parts = p.get("parts") === "1";
|
| 59 |
}
|
|
|
|
| 62 |
const p = new URLSearchParams();
|
| 63 |
if (S.q) p.set("q", S.q);
|
| 64 |
if (S.q && S.mode === "words") p.set("by", "words");
|
| 65 |
+
if (S.domain) p.set("domain", S.domain);
|
| 66 |
if (S.family) p.set("family", S.family);
|
| 67 |
if (S.articulated) p.set("articulated", "1");
|
| 68 |
if (S.glb) p.set("glb", "1");
|
| 69 |
if (S.parts) p.set("parts", "1");
|
| 70 |
+
if (S.dataset !== S.facets.default_dataset || (S.dataset && p.size)) {
|
| 71 |
+
p.set("dataset", S.dataset || "all");
|
| 72 |
+
}
|
| 73 |
const qs = p.toString();
|
| 74 |
history.replaceState(null, "", "/" + (qs ? "?" + qs : ""));
|
| 75 |
}
|
|
|
|
| 79 |
const F = S.facets;
|
| 80 |
const art = F.datasets.reduce((a, d) => a + d.articulated, 0);
|
| 81 |
$("#stats").innerHTML = `${fmt(F.total)} objects · ${fmt(art)} articulated · ${fmt(F.glb)} viewable in 3D` +
|
| 82 |
+
(F.parts ? ` · ${fmt(F.parts)} standalone part${F.parts === 1 ? "" : "s"}` : "");
|
| 83 |
const chips = [`<button class="chip" data-ds="" aria-pressed="${!S.dataset}">All <span class="n">${fmt(F.total)}</span></button>`]
|
| 84 |
.concat(F.datasets.map((d) => `<button class="chip" data-ds="${esc(d.key)}" aria-pressed="${S.dataset === d.key}">${esc(d.label)} <span class="n">${fmt(d.count)}</span></button>`));
|
| 85 |
$("#datasets").innerHTML = chips.join("");
|
|
|
|
| 87 |
$("#ds-list").innerHTML = F.datasets.map((d) => `
|
| 88 |
<div class="ds"><h3>${esc(d.label)} <span>${fmt(d.count)}</span></h3>
|
| 89 |
<p>${esc(d.blurb)}</p>
|
| 90 |
+
<p>${d.domains ? `${fmt(d.domains.length)} domains` : `${fmt(d.articulated)} articulated`} · ${fmt(d.families.length)} families · ${fmt(d.glb)} in 3D${d.parts ? ` · ${fmt(d.parts)} parts` : ""}</p>
|
| 91 |
+
<a href="${esc(F.hub_url)}/${esc(d.repo)}" target="_blank" rel="noopener">${esc(d.repo)}</a></div>`).join("");
|
| 92 |
$("#q").value = S.q;
|
| 93 |
$("#articulated").checked = S.articulated;
|
| 94 |
$("#glb").checked = S.glb;
|
|
|
|
| 99 |
function drawFamilies() {
|
| 100 |
const sel = $("#family");
|
| 101 |
const d = S.facets.datasets.find((x) => x.key === S.dataset);
|
| 102 |
+
const domains = d?.domains;
|
| 103 |
+
$("#domain-filter").hidden = !domains;
|
| 104 |
+
$("#domain").innerHTML = '<option value="">All domains</option>' +
|
| 105 |
+
(domains || []).map((x) => `<option value="${esc(x.key)}"${x.key === S.domain ? " selected" : ""}>${esc(x.label)} (${fmt(x.count)})</option>`).join("");
|
| 106 |
+
const families = domains?.find((x) => x.key === S.domain)?.families || d?.families || [];
|
| 107 |
sel.disabled = !d;
|
| 108 |
sel.innerHTML = `<option value="">${d ? "All families" : "Pick a dataset first"}</option>` +
|
| 109 |
+
families.map(([raw, label, n]) => `<option value="${esc(raw)}"${raw === S.family ? " selected" : ""}>${esc(label)} (${fmt(n)})</option>`).join("");
|
| 110 |
}
|
| 111 |
|
| 112 |
function drawParts() {
|
|
|
|
| 119 |
}
|
| 120 |
|
| 121 |
function drawMode() {
|
| 122 |
+
const nature = S.dataset === "nature";
|
| 123 |
+
$("#mode").hidden = nature;
|
| 124 |
+
$("#articulated-filter").hidden = nature;
|
| 125 |
+
$("#q").placeholder = nature ? "Search Nature by prompt or subject…" : "Search objects: office chair, hinge, bracket with holes…";
|
| 126 |
+
$("#q").setAttribute("aria-label", nature ? "Search Nature by prompt or subject" : "Search objects");
|
| 127 |
for (const b of $("#mode").querySelectorAll("button")) {
|
| 128 |
b.setAttribute("aria-checked", String(b.dataset.mode === S.mode));
|
| 129 |
if (b.dataset.mode === "meaning" && !S.facets.semantic) { b.disabled = true; b.title = "Semantic search is not available"; }
|
|
|
|
| 140 |
});
|
| 141 |
$("#datasets").addEventListener("click", (e) => {
|
| 142 |
const b = e.target.closest(".chip"); if (!b) return;
|
| 143 |
+
S.dataset = b.dataset.ds; S.family = ""; S.domain = "";
|
| 144 |
+
if (S.dataset === "nature") S.articulated = $("#articulated").checked = false;
|
| 145 |
for (const c of $("#datasets").querySelectorAll(".chip")) c.setAttribute("aria-pressed", String(c === b));
|
| 146 |
+
drawFamilies(); drawParts(); drawMode(); refresh();
|
| 147 |
});
|
| 148 |
$("#parts").addEventListener("change", (e) => { S.parts = e.target.checked; S.family = ""; drawFamilies(); refresh(); });
|
| 149 |
$("#family").addEventListener("change", (e) => { S.family = e.target.value; refresh(); });
|
| 150 |
+
$("#domain").addEventListener("change", (e) => { S.domain = e.target.value; S.family = ""; drawFamilies(); refresh(); });
|
| 151 |
$("#articulated").addEventListener("change", (e) => { S.articulated = e.target.checked; refresh(); });
|
| 152 |
$("#glb").addEventListener("change", (e) => { S.glb = e.target.checked; refresh(); });
|
| 153 |
document.addEventListener("click", (e) => {
|
|
|
|
| 183 |
$("#object").hidden = true; $("#object").innerHTML = "";
|
| 184 |
$("#home").hidden = false;
|
| 185 |
document.title = "Sand3D Explorer · Sandflow";
|
| 186 |
+
const before = JSON.stringify([S.q, S.mode, S.dataset, S.domain, S.family, S.articulated, S.glb, S.parts]);
|
| 187 |
readURL(); if (!S.facets.semantic) S.mode = "words";
|
| 188 |
+
const after = JSON.stringify([S.q, S.mode, S.dataset, S.domain, S.family, S.articulated, S.glb, S.parts]);
|
| 189 |
if (!$("#grid").children.length || before !== after) { drawFacets(); refresh(); }
|
| 190 |
else requestAnimationFrame(() => scrollTo(0, S.homeScroll));
|
| 191 |
}
|
|
|
|
| 203 |
if ((S.loading && !first) || S.done) return;
|
| 204 |
S.loading = true;
|
| 205 |
const seq = S.seq;
|
| 206 |
+
const p = new URLSearchParams({ q: S.q, mode: S.mode, dataset: S.dataset, domain: S.domain, family: S.family,
|
| 207 |
articulated: S.articulated, glb: S.glb, parts: S.parts, offset: S.offset, limit: PAGE });
|
| 208 |
try {
|
| 209 |
const r = await api("/api/search?" + p);
|
|
|
|
| 211 |
if (first) $("#grid").innerHTML = "";
|
| 212 |
S.total = r.total; S.offset += r.items.length; S.done = S.offset >= r.total;
|
| 213 |
$("#grid").insertAdjacentHTML("beforeend", r.items.map((c) => card(c)).join(""));
|
| 214 |
+
if (!r.total) $("#grid").innerHTML = `<p class="empty"><b>No object matches.</b> Try fewer words or clear a filter.</p>`;
|
| 215 |
const how = "containing";
|
| 216 |
$("#count").innerHTML = r.mode === "all" ? `<b>${fmt(r.total)}</b> objects`
|
| 217 |
: r.mode === "meaning" ? `Closest renders to “${esc(S.q)}”, out of <b>${fmt(r.total)}</b> objects`
|
|
|
|
| 230 |
if (c.joints) tags.push(`<span class="tag">${c.joints} joint${c.joints > 1 ? "s" : ""}</span>`);
|
| 231 |
if (c.glb) tags.push(`<span class="tag violet">3D</span>`);
|
| 232 |
return `<a class="card" href="/o/${encodeURIComponent(c.id)}" data-id="${esc(c.id)}">
|
| 233 |
+
<div class="thumb"><img loading="lazy" decoding="async" src="${esc(c.image_url)}" alt="${esc(c.name)}">${small ? "" : `<pre class="code-peek"></pre>`}</div>
|
| 234 |
<div class="body"><div class="name" title="${esc(c.name)}">${esc(c.name)}</div>
|
| 235 |
<div class="meta">${esc(S.labels[c.dataset] || c.dataset)}${c.part ? " part" : ""}${c.family ? ` · ${esc(c.family)}` : ""}</div>
|
| 236 |
${small ? "" : `<div class="tags">${tags.join("")}</div>`}</div></a>`;
|
|
|
|
| 275 |
el.innerHTML = `<button class="back" data-back>${ICON.back} Back to the gallery</button><p class="empty"><b>No object ${esc(id)}.</b></p>`;
|
| 276 |
return bindBack(el);
|
| 277 |
}
|
| 278 |
+
if (S.current !== id) return;
|
| 279 |
document.title = `${o.name} · Sand3D Explorer`;
|
| 280 |
+
const nature = o.dataset === "nature";
|
| 281 |
+
const initialView = o.glb && !nature ? "3d" : "render";
|
| 282 |
const lic = o.license_status && o.license_status !== "ok" ? ` <span class="pending">(source licence ${esc(o.license_status)})</span>` : "";
|
| 283 |
const rows = [
|
| 284 |
+
["Dataset", `<a href="${esc(o.dataset_url)}" target="_blank" rel="noopener">${esc(o.repo)}</a>`],
|
| 285 |
+
...(nature ? [["Domain", esc(o.domain || "—")]] : [["Source", esc(o.source_label)]]),
|
| 286 |
...(o.assembly ? [["Assembly", `<a href="/o/${encodeURIComponent(o.assembly.id)}" data-nav>${esc(o.assembly.name)}</a>`]] : []),
|
| 287 |
["Family", esc(o.family || "Unclassified")],
|
| 288 |
+
...(nature ? [["Subject", esc(o.subject || "—")], ["Style", esc(o.style || "—")], ["Triangles", o.triangles == null ? "—" : fmt(o.triangles)]]
|
| 289 |
+
: [["Parts", o.parts ? fmt(o.parts) : "—"], ["Joints", o.joints ? `${o.joints}, declared in the program` : "None"]]),
|
| 290 |
["Entry", o.entry ? `<span class="mono">${esc(o.entry)}()</span>` : "The program builds the object as it runs"],
|
| 291 |
["Split", esc(o.split === "val" ? "validation" : o.split)],
|
| 292 |
+
nature ? ["Semantic score", o.semantic_score == null ? "—" : Number(o.semantic_score).toFixed(3)]
|
| 293 |
+
: ["Fidelity", o.f_score != null ? `F-score ${Number(o.f_score).toFixed(3)} against the source object` : "—"],
|
| 294 |
["Licence", `${esc(o.license)}${o.source_license && o.source_license !== o.license ? `, source under ${esc(o.source_license)}` : ""}${lic}`],
|
| 295 |
+
...(nature ? [] : [["Attribution", esc(o.attribution)]]),
|
| 296 |
["Library", `sand3d ${esc(o.sand3d_version)}`],
|
| 297 |
["Id", `<span class="mono">${esc(o.id)}</span>`],
|
| 298 |
];
|
| 299 |
el.innerHTML = `
|
| 300 |
<button class="back" data-back>${ICON.back} Back to the gallery</button>
|
| 301 |
<div class="obj-head">
|
| 302 |
+
<div class="stage${nature ? " stage-nature" : ""}" id="stage">
|
| 303 |
+
${o.glb ? `<div class="stage-tabs"><button data-view="3d" aria-pressed="${initialView === "3d"}">3D</button><button data-view="render" aria-pressed="${initialView === "render"}">Render</button></div>` : ""}
|
| 304 |
<div id="stage-body"></div>
|
| 305 |
</div>
|
| 306 |
<div class="obj-info">
|
| 307 |
<p class="repere">${esc(o.dataset_label)}${o.part ? " · part" : ""}</p>
|
| 308 |
<h1>${esc(o.name)}</h1>
|
| 309 |
<p class="sub">${o.loc} lines of Python${o.joints ? ` · ${o.joints} joint${o.joints > 1 ? "s" : ""}` : ""}</p>
|
| 310 |
+
${nature ? `<p class="sub"><strong>Prompt</strong><br>${esc(o.prompt)}</p>` : ""}
|
| 311 |
<table class="facts">${rows.map(([k, v]) => `<tr><th>${k}</th><td>${v}</td></tr>`).join("")}</table>
|
| 312 |
<div class="actions">
|
| 313 |
+
<a class="btn" href="${esc(o.row_url)}" target="_blank" rel="noopener">${ICON.ext} ${esc(o.row_label)}</a>
|
| 314 |
+
${o.usda_url ? `<a class="btn" href="${esc(o.usda_url)}" target="_blank" rel="noopener">${ICON.ext} USD file</a>` : ""}
|
| 315 |
<a class="btn" href="${esc(o.library_url)}" target="_blank" rel="noopener">${ICON.ext} sand3d on GitHub</a>
|
| 316 |
</div>
|
| 317 |
</div>
|
|
|
|
| 325 |
<div class="grid" id="similar-grid"></div>
|
| 326 |
</section>`;
|
| 327 |
bindBack(el);
|
| 328 |
+
drawStage(o, initialView);
|
| 329 |
for (const b of el.querySelectorAll(".stage-tabs button")) b.addEventListener("click", () => {
|
| 330 |
for (const x of el.querySelectorAll(".stage-tabs button")) x.setAttribute("aria-pressed", String(x === b));
|
| 331 |
drawStage(o, b.dataset.view);
|
|
|
|
| 351 |
|
| 352 |
function drawStage(o, view) {
|
| 353 |
const body = $("#stage-body");
|
| 354 |
+
const img = esc(o.render_url);
|
| 355 |
dropViewer();
|
| 356 |
if (view === "3d" && o.glb) {
|
| 357 |
body.innerHTML = `<div class="three" id="three"><img class="still poster" src="${img}" alt="${esc(o.name)}"><div class="three-loading"><div></div></div></div>
|
|
|
|
| 364 |
<span class="three-info" id="three-info"></span>
|
| 365 |
</div>`;
|
| 366 |
const host = $("#three");
|
| 367 |
+
import("/static/viewer.js?v=5").then(({ Viewer }) => {
|
| 368 |
+
if (!host.isConnected) return;
|
| 369 |
viewer = new Viewer(host, {
|
| 370 |
onReady: ({ parts }) => {
|
| 371 |
host.classList.add("ready");
|
|
|
|
| 381 |
});
|
| 382 |
return viewer.load(o.glb_url);
|
| 383 |
}).catch((e) => {
|
| 384 |
+
if (!host.isConnected) return;
|
| 385 |
host.classList.add("failed");
|
| 386 |
$("#three-info") && ($("#three-info").textContent = "");
|
| 387 |
body.insertAdjacentHTML("beforeend", `<span class="stage-hint">The 3D view could not load (${esc(e.message || e)}): the render is shown instead</span>`);
|
static/img/banner-830.webp
CHANGED
|
|
static/img/banner.webp
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
static/index.html
CHANGED
|
@@ -8,10 +8,10 @@
|
|
| 8 |
<link rel="icon" href="/static/img/favicon.png">
|
| 9 |
<link rel="preload" href="/static/fonts/Inter-Regular.woff2" as="font" type="font/woff2" crossorigin>
|
| 10 |
<link rel="preload" href="/static/fonts/Inter-Light.woff2" as="font" type="font/woff2" crossorigin>
|
| 11 |
-
<link rel="stylesheet" href="/static/app.css?v=
|
| 12 |
<script type="importmap">{"imports": {"three": "https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.min.js", "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/"}}</script>
|
| 13 |
<script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.10.0/highlight.min.js" defer></script>
|
| 14 |
-
<script src="/static/app.js?v=
|
| 15 |
</head>
|
| 16 |
<body>
|
| 17 |
<header class="top" id="top">
|
|
@@ -44,7 +44,7 @@
|
|
| 44 |
<p class="lead">Every object here comes with the short Python program that builds it. Read the code, copy it, open the object in 3D.</p>
|
| 45 |
<p class="stats" id="stats"> </p>
|
| 46 |
</div>
|
| 47 |
-
<figure class="hero-art"><img src="/static/img/banner-830.webp" srcset="/static/img/banner-830.webp 830w, /static/img/banner.webp 1660w" sizes="(max-width: 900px) 100vw, 50vw" alt="Objects from the Sand3D dataset"></figure>
|
| 48 |
</section>
|
| 49 |
|
| 50 |
<section class="toolbar" id="toolbar">
|
|
@@ -53,13 +53,14 @@
|
|
| 53 |
<input id="q" type="search" placeholder="Search objects: office chair, hinge, bracket with holes…" autocomplete="off" spellcheck="false">
|
| 54 |
<div class="mode" id="mode" role="radiogroup" aria-label="Search by">
|
| 55 |
<button type="button" data-mode="meaning" role="radio" title="Ranks every object by how much its render looks like your words">By look</button>
|
| 56 |
-
<button type="button" data-mode="words" role="radio" title="
|
| 57 |
</div>
|
| 58 |
</form>
|
| 59 |
<div class="filters">
|
| 60 |
<div class="chips" id="datasets"></div>
|
|
|
|
| 61 |
<label class="select"><span>Family</span><select id="family"><option value="">All families</option></select></label>
|
| 62 |
-
<label class="toggle"><input type="checkbox" id="articulated"><span>Articulated</span></label>
|
| 63 |
<label class="toggle"><input type="checkbox" id="glb"><span>With 3D view</span></label>
|
| 64 |
<label class="toggle" id="parts-toggle" hidden><input type="checkbox" id="parts"><span id="parts-label">Parts</span></label>
|
| 65 |
</div>
|
|
@@ -72,7 +73,7 @@
|
|
| 72 |
<section class="about" id="about-datasets">
|
| 73 |
<h2 id="datasets-title">The datasets</h2>
|
| 74 |
<div class="ds-list" id="ds-list"></div>
|
| 75 |
-
<p class="note">The programs
|
| 76 |
</section>
|
| 77 |
</section>
|
| 78 |
|
|
|
|
| 8 |
<link rel="icon" href="/static/img/favicon.png">
|
| 9 |
<link rel="preload" href="/static/fonts/Inter-Regular.woff2" as="font" type="font/woff2" crossorigin>
|
| 10 |
<link rel="preload" href="/static/fonts/Inter-Light.woff2" as="font" type="font/woff2" crossorigin>
|
| 11 |
+
<link rel="stylesheet" href="/static/app.css?v=10">
|
| 12 |
<script type="importmap">{"imports": {"three": "https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.min.js", "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/"}}</script>
|
| 13 |
<script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.10.0/highlight.min.js" defer></script>
|
| 14 |
+
<script src="/static/app.js?v=13" defer></script>
|
| 15 |
</head>
|
| 16 |
<body>
|
| 17 |
<header class="top" id="top">
|
|
|
|
| 44 |
<p class="lead">Every object here comes with the short Python program that builds it. Read the code, copy it, open the object in 3D.</p>
|
| 45 |
<p class="stats" id="stats"> </p>
|
| 46 |
</div>
|
| 47 |
+
<figure class="hero-art"><img src="/static/img/banner-830.webp?v=3" srcset="/static/img/banner-830.webp?v=3 830w, /static/img/banner.webp?v=3 1660w" sizes="(max-width: 900px) 100vw, 50vw" alt="Objects from the Sand3D dataset"></figure>
|
| 48 |
</section>
|
| 49 |
|
| 50 |
<section class="toolbar" id="toolbar">
|
|
|
|
| 53 |
<input id="q" type="search" placeholder="Search objects: office chair, hinge, bracket with holes…" autocomplete="off" spellcheck="false">
|
| 54 |
<div class="mode" id="mode" role="radiogroup" aria-label="Search by">
|
| 55 |
<button type="button" data-mode="meaning" role="radio" title="Ranks every object by how much its render looks like your words">By look</button>
|
| 56 |
+
<button type="button" data-mode="words" role="radio" title="Search names, prompts, subjects and other catalog text">By words</button>
|
| 57 |
</div>
|
| 58 |
</form>
|
| 59 |
<div class="filters">
|
| 60 |
<div class="chips" id="datasets"></div>
|
| 61 |
+
<label class="select" id="domain-filter" hidden><span>Domain</span><select id="domain"></select></label>
|
| 62 |
<label class="select"><span>Family</span><select id="family"><option value="">All families</option></select></label>
|
| 63 |
+
<label class="toggle" id="articulated-filter"><input type="checkbox" id="articulated"><span>Articulated</span></label>
|
| 64 |
<label class="toggle"><input type="checkbox" id="glb"><span>With 3D view</span></label>
|
| 65 |
<label class="toggle" id="parts-toggle" hidden><input type="checkbox" id="parts"><span id="parts-label">Parts</span></label>
|
| 66 |
</div>
|
|
|
|
| 73 |
<section class="about" id="about-datasets">
|
| 74 |
<h2 id="datasets-title">The datasets</h2>
|
| 75 |
<div class="ds-list" id="ds-list"></div>
|
| 76 |
+
<p class="note">The programs are run under sand3d in a fresh process. Reconstructed objects are checked against their source geometry. Nature assets are scored against their original prompt.</p>
|
| 77 |
</section>
|
| 78 |
</section>
|
| 79 |
|
static/viewer.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
// part's name under the pointer.
|
| 4 |
import * as THREE from "three";
|
| 5 |
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
|
|
|
|
| 6 |
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
| 7 |
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
|
| 8 |
|
|
@@ -63,7 +64,7 @@ export class Viewer {
|
|
| 63 |
dirty() { this._dirty = true; }
|
| 64 |
|
| 65 |
async load(url) {
|
| 66 |
-
const gltf = await new GLTFLoader().loadAsync(url);
|
| 67 |
if (!this._alive) return;
|
| 68 |
const root = gltf.scene;
|
| 69 |
this.root = root;
|
|
|
|
| 3 |
// part's name under the pointer.
|
| 4 |
import * as THREE from "three";
|
| 5 |
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
|
| 6 |
+
import { MeshoptDecoder } from "three/addons/libs/meshopt_decoder.module.js";
|
| 7 |
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
| 8 |
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
|
| 9 |
|
|
|
|
| 64 |
dirty() { this._dirty = true; }
|
| 65 |
|
| 66 |
async load(url) {
|
| 67 |
+
const gltf = await new GLTFLoader().setMeshoptDecoder(MeshoptDecoder).loadAsync(url);
|
| 68 |
if (!this._alive) return;
|
| 69 |
const root = gltf.scene;
|
| 70 |
this.root = root;
|