Official Codebase of 3DCodeVerse
Python
frames gate: "the camera named for a hero" is the host's rule, carried in the census as hero_for
gaoypeng06d43496bc10
diff --git a/harness/codeverse3d/spatial/frame_metrics.py b/harness/codeverse3d/spatial/frame_metrics.pyindex ca5b46ca..a1f803e1 100644--- a/harness/codeverse3d/spatial/frame_metrics.py+++ b/harness/codeverse3d/spatial/frame_metrics.py@@ -344,11 +344,6 @@ HERO_MIN_FRAC = 0.005 # of the frame, best authored camera: below itHERO_DETAIL_MIN_FRAC = 0.02 # of the frame, in the camera NAMED for the hero-def _hero_key(url: str) -> str:- """``/assets/longcase_clock.glb`` → ``longcaseclock`` (the plan's snake name, joined)."""- return "".join(ch for ch in url.rsplit("/", 1)[-1].rsplit(".", 1)[0].lower() if ch.isalnum())--def _hero_findings(checks: list[dict[str, Any]], census: dict[str, Any]) -> list[GateFinding]:"""A Blender hero that is IN the scene but in no authored frame — or nearly absent fromthe camera named for it. ``camera_checks[].glb_frac`` (``glbCoverage``: a mask render@@ -360,6 +355,9 @@ def _hero_findings(checks: list[dict[str, Any]], census: dict[str, Any]) -> listif not isinstance(rows, list):return []authored = [c for c in checks if _view_kind(c) == "authored"]+ # which camera is NAMED for which hero is the host's rule (scene_host.mjs namesHero — the one+ # camera repair re-aims by); a census from before 2026-09-23 carries no hero_for+ named = {str(c.get("name", "?")): c.get("hero_for") or [] for c in authored}out: list[GateFinding] = []for r in rows:if not isinstance(r, dict) or not r.get("in_scene"):@@ -387,9 +385,8 @@ def _hero_findings(checks: list[dict[str, Any]], census: dict[str, Any]) -> list"frames never show cannot pass its must-have",kind="hero_unseen", url=url, best_frac=best, per_camera=seen))continue- key = _hero_key(url)for cam, v in seen.items():- if key and key in "".join(ch for ch in cam.lower() if ch.isalnum()) and v < HERO_DETAIL_MIN_FRAC:+ if url in named.get(cam, ()) and v < HERO_DETAIL_MIN_FRAC:out.append(_f(Severity.WARN, cam,f"{cam} is named for {base} but shows it at {v:.1%} of the frame (its best view is {best:.1%})","a detail shot fills 10-40% of the frame with its subject: move the camera closer along "diff --git a/harness/runtime_js/lib/scene_host.mjs b/harness/runtime_js/lib/scene_host.mjsindex c79c2d38..8669322d 100644--- a/harness/runtime_js/lib/scene_host.mjs+++ b/harness/runtime_js/lib/scene_host.mjs@@ -165,14 +165,20 @@ function heroWords(url) {.map((w) => w.toLowerCase()).filter((w) => w.length >= 4 && !GENERIC_HERO_WORDS.has(w));}-/** The loaded GLB a camera is named for (a name word of the file in the camera's name), with its- * world box as placed — or null. */+/** THE "camera named for a hero" rule: a name word of the GLB's file is in the camera's name.+ * Camera repair re-aims by it, and the census carries it (`camera_checks[].hero_for`) for the+ * frames gate (frame_metrics._hero_findings), which has no copy of its own. */+function namesHero(cameraName, url) {+ const lower = String(cameraName || '').toLowerCase();+ return heroWords(url).some((w) => lower.includes(w));+}++/** The loaded GLB a camera is named for, with its world box as placed — or null. */function heroForCamera(name) {if (!loadedGlbs.length) return null;- const lower = String(name || '').toLowerCase();let boxes = null;for (const g of loadedGlbs) {- if (!heroWords(g.url).some((w) => lower.includes(w))) continue;+ if (!namesHero(name, g.url)) continue;if (!boxes) { try { boxes = geometryBoxes(state.scene); } catch (e) { return null; } }const all = new THREE.Box3();for (const u of g.geometry_uuids) { const b = boxes.get(u); if (b && !b.isEmpty()) all.union(b); }@@ -597,7 +603,8 @@ function cameraChecks(spec) {} finally {for (const o of hiddenLayers) o.visible = true;}- return { name: spec.name, ...near, ...stats, ...coverage, glb_frac: glbFrac };+ const heroFor = loadedGlbs.filter((g) => namesHero(spec.name, g.url)).map((g) => g.url);+ return { name: spec.name, ...near, ...stats, ...coverage, glb_frac: glbFrac, hero_for: heroFor };}/** Force-compile every material as seen from spec (or the first camera). */diff --git a/harness/tests/scene_gates/test_frame_metrics.py b/harness/tests/scene_gates/test_frame_metrics.pyindex 6932c525..b179a2ad 100644--- a/harness/tests/scene_gates/test_frame_metrics.py+++ b/harness/tests/scene_gates/test_frame_metrics.py@@ -151,10 +151,17 @@ def test_a_hero_in_the_scene_but_in_no_authored_frame_is_an_error():msg = next(f.message for f in unseen.findings if f.data["kind"] == "hero_unseen")assert "AthanorDetail 0.0%" in msg and "no camera sees the hero" in msgassert "(2.2 m across as placed)" in msg and "not small" in msg # loop 23: 0.3 % read as "microscopic" without the size- # seen well in one shot, but the camera NAMED for it barely shows it → WARN on that camera+ # seen well in one shot, but the camera NAMED for it (the host's hero_for) barely shows it → WARN on that camerasmall = frame_findings({"census": census, "camera_checks": [- _chk("AthanorDetail", glb_frac={url: 0.004}), _chk("StairsPushIn", glb_frac={url: 0.12})]})+ _chk("AthanorDetail", glb_frac={url: 0.004}, hero_for=[url]), _chk("StairsPushIn", glb_frac={url: 0.12})]})assert [(k, s, t) for k, s, t in _kinds(small)] == [("hero_small_in_its_camera", Severity.WARN, "AthanorDetail")]+ # the host's rule is the one rule: a name WORD of the file (lantern_room.glb → LanternDetail), which the+ # gate's own whole-stem match missed in 24 of 25 recorded camera/hero pairs+ lamp = "/assets/lantern_room.glb"+ lcensus = {"glb_assets": [{"url": lamp, "meshes": 3, "meshes_in_scene": 3, "in_scene": True}]}+ word = frame_findings({"census": lcensus, "camera_checks": [+ _chk("LanternDetail", glb_frac={lamp: 0.004}, hero_for=[lamp]), _chk("Harbour", glb_frac={lamp: 0.2})]})+ assert [(k, t) for k, _, t in _kinds(word)] == [("hero_small_in_its_camera", "LanternDetail")]# a well-framed hero, and an older census without glb_frac, say nothingfine = frame_findings({"census": census, "camera_checks": [_chk("AthanorDetail", glb_frac={url: 0.2})]})old = frame_findings({"census": census, "camera_checks": [_chk("AthanorDetail")]})diff --git a/harness/tests/scene_gates/test_live_hero_in_frame.py b/harness/tests/scene_gates/test_live_hero_in_frame.pyindex 4264ecfa..79c47693 100644--- a/harness/tests/scene_gates/test_live_hero_in_frame.py+++ b/harness/tests/scene_gates/test_live_hero_in_frame.py@@ -95,6 +95,8 @@ def test_a_camera_named_for_the_hero_is_re_aimed_when_the_hero_is_out_of_its_fram = read_json_or_none(out / "metrics.json")chk = {c["name"]: c for c in m["camera_checks"]}assert chk["HeroCubeDetail"]["glb_frac"].get(URL, 0.0) > 0.01, chk["HeroCubeDetail"]["glb_frac"]+ # the census carries the host's naming rule for the gate (one rule, scene_host.mjs namesHero)+ assert chk["HeroCubeDetail"]["hero_for"] == [URL] and all(c["hero_for"] == [] for n, c in chk.items() if n != "HeroCubeDetail")aimed = [r for r in m["census"]["camera_repair"] if r.get("aimed_at")]assert aimed and aimed[0]["name"] == "HeroCubeDetail" and aimed[0]["aimed_at"] == URL, m["census"]["camera_repair"]# the other authored cameras are not named for it and keep their shots