makepad/libs/game/assets/examples/scale.rs
Admin 5f83480ae3 Arcade assets: full Kenney 3D catalogue (4442 models) + ranking fixes
52 packs, 4442 GLB models, 136 MB on disk — fetched sequentially with resume
(a hash-valid pack is skipped, so an interrupted run costs nothing) via
kenney.nl's content-hashed URLs with per-zip sha256. MIRROR.toml records
every pack's canonical URL, sha256, size and file count, so a mirror is
reproducible; --mirror=/ARCADE_ASSET_MIRROR redirects the base URL and fetch()
verifies the digest identically whatever host served the bytes — a mirror we
control is never trusted more than upstream. --packs= keeps a fresh clone from
being forced to pull everything.

Aliases restructured to survive the scale: per-pack theme rows (55) so every
model in a pack inherits its setting, filename-token parsing with variant-
marker stripping as the workhorse, and ~240 hand-curated query-time synonyms —
the layer whose curation compounds across the whole catalogue. 82-query suite
reports misses instead of being tuned green; the list is down to 2, both
defensible (a floor IS somewhere to stand; a bell IS a metal clang).

Three ranking bugs root-caused, not patched:
- No stemming, so "smashing" never reached the alias "smash" and "glass
  smashing" returned glass PIPES. Added a conservative stemmer probed at
  synonym strength (only ever adds matches), which refuses to mangle
  glass/grass/class and routes "trees" to "tree", not "tre"
- An overreaching alias: `spaceship` sat on four spaceEngine SOUND families.
  An engine hum is not a spaceship. Removed; "spaceship engine" still resolves
- Kind confusion on ties: spacecraft models tied with spaceTrash sounds and
  lost the alphabetical tie-break. Added kind-aware tie-breaking driven by
  query intent — deliberately a TIE-BREAK, not a score bonus, so it cannot
  drag a weak model above a strong sound (laser gun / explosion / coins scores
  verified unchanged)

Repo-policy violation fixed: all three asset .gitignore files were deny-lists
covering only .glb/.png/.jpg, leaving 302 .gltf files from 3d-road-tiles fully
committable. Converted to allow-lists — 4,744 asset files are now unstageable
by accident.

Scale at 4,999 entries: build 120 ms, search ~0.2 ms, 2.1 MB heap, and the
prompt summary still 479 chars — flat as the catalogue grows, which is what
keeps it affordable in every AI turn.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-03 09:17:03 +02:00

28 lines
1.6 KiB
Rust

use makepad_game_assets::{agent, AssetIndex, AssetKind};
use std::time::Instant;
fn main() {
let t = Instant::now();
let idx = AssetIndex::build(std::path::Path::new("apps/arcade/resources"));
let build_ms = t.elapsed().as_millis();
let kw: usize = idx.entries().iter().map(|e| e.keywords.len()).sum();
let bytes: usize = idx.entries().iter().map(|e|
e.id.len()+e.name.len()+e.path.as_os_str().len()+e.pack.len()
+ e.keywords.iter().map(|k| k.len()+24).sum::<usize>()
+ e.categories.iter().map(|c| c.len()+24).sum::<usize>() + 160).sum();
println!("build: {build_ms} ms | entries {} ({} models, {} sounds, {} music)",
idx.len(), idx.count_of(AssetKind::Model), idx.count_of(AssetKind::Sound), idx.count_of(AssetKind::Music));
println!("keywords total {kw} (avg {:.1}/entry) | approx heap {:.1} MB", kw as f32/idx.len() as f32, bytes as f32/1048576.0);
let s = agent::library_summary(&idx);
println!("summary {} chars:\n{s}\n", s.len());
let t2 = Instant::now();
for q in ["truck","tree","something to drive"] { let _ = idx.find(q); }
println!("3 queries: {} us", t2.elapsed().as_micros());
for q in std::env::args().skip(1) {
let (q, kind) = match q.split_once('#') { Some((a,b))=>(a.to_string(),Some(b.to_string())), None=>(q,None) };
let mut p = agent::FindParams::new(&q);
if let Some(k)=&kind { p = p.with_kind_str(k); }
let r = agent::execute(&idx, &p);
let top: Vec<String> = r.iter().take(3).map(|x| x.id.clone()).collect();
println!("{:34} -> {}", q, if top.is_empty(){"(none)".into()}else{top.join(" | ")});
}
}