Official Codebase of 3DCodeVerse
Python
views: one LEGACY_VIEW_ALIASES map — no preference list keeps its own subset of the pre-D47 names
gaoypengfb895b996b22
diff --git a/harness/codeverse3d/addons/gallery/index.py b/harness/codeverse3d/addons/gallery/index.pyindex f294ec67..3ae07432 100644--- a/harness/codeverse3d/addons/gallery/index.py+++ b/harness/codeverse3d/addons/gallery/index.py@@ -27,6 +27,7 @@ from codeverse3d.addons.gallery.model import (humanize_view,)from codeverse3d.contracts.run import RunId, RunRecord+from codeverse3d.conventions import views_by_preferencefrom codeverse3d.proc import read_json_or_nonefrom codeverse3d.record.deliverable import round_outputs, texture_shipped_forfrom codeverse3d.record.record import (@@ -96,10 +97,9 @@ def picked_sheet(ws: Workspace, rec: RunRecord, picked: int | None) -> str:#: view names that make the best single thumbnail, most telling first. A ¾ view-#: shows silhouette *and* depth; a flat orthographic front hides both. The ``*_34``-#: names are the pre-D47 rig, kept because the gallery serves stored runs.-HERO_PREFERENCE = ("front_right_high", "back_left_high", "front_right_low",- "front_right_34", "back_left_34", "low_front_left", "front")+#: shows silhouette *and* depth; a flat orthographic front hides both. A stored pre-D47+#: run matches through ``conventions.view_key``.+HERO_PREFERENCE = ("front_right_high", "back_left_high", "front_right_low", "front_left_low", "front")def hero_view(ws: Workspace, rec: RunRecord, picked: int | None) -> tuple[str, str, int]:@@ -114,8 +114,7 @@ def hero_view(ws: Workspace, rec: RunRecord, picked: int | None) -> tuple[str, sviews = [v for v in rnd.renders.views if not v.name.startswith(("pose_", "articulation"))]if not views:return "", "", 0- by_name = {v.name: v for v in views}- chosen = next((by_name[n] for n in HERO_PREFERENCE if n in by_name), views[0])+ chosen = next(iter(views_by_preference(views, HERO_PREFERENCE)), views[0])rel = run_rel(ws, chosen.path)if not rel or not (ws.root / rel).is_file():return "", "", len(views)diff --git a/harness/codeverse3d/conventions.py b/harness/codeverse3d/conventions.pyindex 96a96b2d..6de380c0 100644--- a/harness/codeverse3d/conventions.py+++ b/harness/codeverse3d/conventions.py@@ -145,15 +145,35 @@ ARTICULATION_VIEWS: tuple[ViewPreset, ...] = tuple(_OBJECT_VIEW_BY_NAME[n] for n in ("front_right_high", "back_left_high", "front"))-#: the view a one-camera comparison (the reference silhouette) takes, in preference order;-#: ``*_34`` are pre-D47 stored runs-FRONT_VIEW_NAMES: tuple[str, ...] = ("front", "front_right_high", "front_left_high",- "front_right_34", "front_left_34")+#: the pre-D47 8-view rig's names → their twin in the 14-view rig. Stored runs carry them,+#: and the clay cameras (``OBJECT_CLAY_VIEWS``) still use them. Every view preference list+#: is written in rig names and matches a view by :func:`view_key`, so no list keeps its own+#: subset of the old names.+LEGACY_VIEW_ALIASES: dict[str, str] = {+ "front_right_34": "front_right_high",+ "back_left_34": "back_left_high",+ "low_front_left": "front_left_low",+}+++def view_key(name: str) -> str:+ """A view's rig name: ``front_right_34`` → ``front_right_high``; anything else unchanged."""+ return LEGACY_VIEW_ALIASES.get(name, name)+++def views_by_preference(views: Sequence[RenderView], names: Sequence[str]) -> list[RenderView]:+ """The ``views`` whose :func:`view_key` is in ``names``, in the order of ``names``."""+ rank = {n: i for i, n in enumerate(names)}+ return sorted((v for v in views if view_key(v.name) in rank), key=lambda v: rank[view_key(v.name)])+++#: the view a one-camera comparison (the reference silhouette) takes, in preference order+FRONT_VIEW_NAMES: tuple[str, ...] = ("front", "front_right_high", "front_left_high")def front_view(views: Sequence[RenderView]) -> RenderView | None:"""The first of ``FRONT_VIEW_NAMES`` among ``views``, else the first view."""- return next((v for n in FRONT_VIEW_NAMES for v in views if v.name == n), views[0] if views else None)+ return next(iter(views_by_preference(views, FRONT_VIEW_NAMES)), views[0] if views else None)#: Scene overview rig (scenes sit on ground: aerial + eye level, no underside).diff --git a/harness/codeverse3d/judges/prompt_builder.py b/harness/codeverse3d/judges/prompt_builder.pyindex 7d099c87..e27b124d 100644--- a/harness/codeverse3d/judges/prompt_builder.py+++ b/harness/codeverse3d/judges/prompt_builder.py@@ -37,7 +37,13 @@ from codeverse3d.contracts.artifacts import (from codeverse3d.contracts.chat import ChatMessage, ImagePart, TextPartfrom codeverse3d.contracts.plan import AcceptanceItemfrom codeverse3d.contracts.spec import Spec-from codeverse3d.conventions import OBJECT_CLAY_VIEWS, OBJECT_VIEWS, SCENE_VIEWS, ViewPreset+from codeverse3d.conventions import (+ OBJECT_CLAY_VIEWS,+ OBJECT_VIEWS,+ SCENE_VIEWS,+ ViewPreset,+ view_key,+)from codeverse3d.judges.rubrics import VETO_PENETRATION_DEPTH_M, Rubric, wire_schemafrom codeverse3d.proc import unique_tmpfrom codeverse3d.prompts import prompt_hash@@ -137,13 +143,10 @@ GEOMETRY_MODES = tuple(m for m in RENDER_MODES if m != "shaded")#: montage 1 = {front_right_high, back_left_high, top, bottom}, so a montage-cap#: truncation still sees the underside; then the eye ring, then the remaining rings.OBJECT_RANK = (- # legacy pre-D47 names ride beside their D47 twins so a STORED 8-view run- # re-judges with the same montage shape the in-run judge saw (3/4 heroes first)- # — DIFF_VIEW_NAMES / CANDIDATE_VIEWS / FRONT_VIEW_NAMES / HERO_PREFERENCE all- # kept them; this one had forgotten (review of PR #3)- "front_right_high", "front_right_34", "back_left_high", "back_left_34", "top", "bottom",+ # a STORED pre-D47 run (and a clay tile) ranks by its rig twin, ``conventions.view_key``+ "front_right_high", "back_left_high", "top", "bottom","front", "right", "back", "left",- "front_right_low", "low_front_left", "back_left_low", "front_left_high", "back_right_high",+ "front_right_low", "back_left_low", "front_left_high", "back_right_high","front_left_low", "back_right_low",)#: scene rig: authored cameras first (graded for composition), then the overview rig.@@ -209,7 +212,8 @@ def rank_views(views: list[RenderView], *, scene: bool) -> list[RenderView]:else:def key(iv: tuple[int, RenderView]) -> tuple[int, int, int]:i, v = iv- return (0, OBJECT_RANK.index(v.name), i) if v.name in OBJECT_RANK else (1, 0, i)+ name = view_key(v.name)+ return (0, OBJECT_RANK.index(name), i) if name in OBJECT_RANK else (1, 0, i)return [v for _, v in sorted(enumerate(views), key=key)]diff --git a/harness/codeverse3d/judges/vlm_judge.py b/harness/codeverse3d/judges/vlm_judge.pyindex 9e6561df..e655469d 100644--- a/harness/codeverse3d/judges/vlm_judge.py+++ b/harness/codeverse3d/judges/vlm_judge.py@@ -30,7 +30,7 @@ from codeverse3d.config import get_settingsfrom codeverse3d.contracts.artifacts import Judgment, RenderViewfrom codeverse3d.contracts.chat import ChatRequest, ChatResponsefrom codeverse3d.contracts.common import TRACK_INFO, Track, Usage-from codeverse3d.conventions import front_view+from codeverse3d.conventions import front_view, views_by_preferencefrom codeverse3d.judges.base import SLICE_TRACKS, JudgeInputfrom codeverse3d.judges.prompt_builder import (_key,@@ -341,10 +341,9 @@ IOU_LOW, IOU_HIGH = 0.25, 0.85#: (unreliable mask, or a reference whose proportions contradict the brief)NEUTRAL_SCORE = 0.5-#: views handed to the mismatch pass (front-ish first, then a 3/4 and a side);-#: ``*_34`` names are the pre-D47 rig, kept for re-judging stored runs.-DIFF_VIEW_NAMES: tuple[str, ...] = ("front", "front_right_high", "front_left_high", "right", "left",- "front_right_34", "front_left_34")+#: views handed to the mismatch pass (front-ish first, then a 3/4 and a side); a stored+#: pre-D47 run matches through ``conventions.view_key``.+DIFF_VIEW_NAMES: tuple[str, ...] = ("front", "front_right_high", "front_left_high", "right", "left")def iou_to_score(iou: float) -> float:@@ -481,8 +480,7 @@ class ReferenceJudge(VlmJudge):def diff_views(self, views: list[RenderView]) -> list[str]:"""Up to 3 shaded views for the diff, front-ish first."""- by_name = {v.name: v for v in views}- picked = [by_name[n].path for n in DIFF_VIEW_NAMES if n in by_name]+ picked = [v.path for v in views_by_preference(views, DIFF_VIEW_NAMES)]for v in views:if len(picked) >= 3:breakdiff --git a/harness/codeverse3d/spatial/silhouette.py b/harness/codeverse3d/spatial/silhouette.pyindex da23ed2c..ccbdb707 100644--- a/harness/codeverse3d/spatial/silhouette.py+++ b/harness/codeverse3d/spatial/silhouette.py@@ -30,6 +30,7 @@ import numpy as npfrom PIL import Imagefrom codeverse3d.contracts.artifacts import RenderView+from codeverse3d.conventions import views_by_preferenceMASK_SIZE = 256#: colour-distance tolerance (0-441) from the border colour: adaptive between these bounds@@ -206,11 +207,9 @@ def silhouette_aspect(path: Path | str) -> float:#: render views a reference photo could plausibly have been shot from — a straight-on#: studio elevation matches ``front``/``right``/``left``/``back``, a 3/4 product shot#: matches the ``*_high`` ring. ``top``, ``bottom`` and the low ring are never a-#: product-shot camera. The ``*_34`` names are the pre-D47 rig, kept so stored runs-#: (``3dcode judge <old-slug>``, calibration replays) still match their own cameras.+#: product-shot camera. A stored pre-D47 run matches through ``conventions.view_key``.CANDIDATE_VIEWS: tuple[str, ...] = ("front", "front_right_high", "front_left_high", "right", "left", "back", "back_left_high",- "front_right_34", "back_left_34", # legacy pre-D47 runs)@@ -231,29 +230,24 @@ def best_view_match(Returns the :func:`compare_silhouette` dict plus ``view`` (the winning view name)and ``per_view`` (name → IoU). ``{"error": ...}`` when nothing could be compared."""- named = {v.name: v for v in renders}- order = [n for n in candidates if n in named] or [v.name for v in renders]per_view: dict[str, float] = {}- best: tuple[float, str, dict[str, Any]] | None = None- for name in order:- view = named.get(name) or next((v for v in renders if v.name == name), None)- if view is None or not Path(view.path).is_file():+ best: tuple[float, RenderView, dict[str, Any]] | None = None+ for view in views_by_preference(renders, candidates) or list(renders):+ if not Path(view.path).is_file():continuetry:res = compare_silhouette(view.path, reference)except (OSError, ValueError):continue- per_view[name] = res["iou"]+ per_view[view.name] = res["iou"]if best is None or res["iou"] > best[0]:- best = (res["iou"], name, res)+ best = (res["iou"], view, res)if best is None:return {"error": "no comparable render view"}- _, name, res = best+ _, view, res = bestout = dict(res)- out["view"] = nameout["per_view"] = {k: round(v, 4) for k, v in per_view.items()}if diff_png is not None:- view = named[name] if name in named else next(v for v in renders if v.name == name)out.update(compare_silhouette(view.path, reference, diff_png=diff_png))- out["view"] = name+ out["view"] = view.namereturn outdiff --git a/harness/tests/reference/test_silhouette_best_view.py b/harness/tests/reference/test_silhouette_best_view.pyindex 83a64962..469a14b2 100644--- a/harness/tests/reference/test_silhouette_best_view.py+++ b/harness/tests/reference/test_silhouette_best_view.py@@ -28,9 +28,7 @@ def _views(tmp: Path) -> list[RenderView]:def test_best_view_skips_top_and_low_cameras_and_writes_the_diff(tmp_path: Path) -> None:assert "top" not in CANDIDATE_VIEWS and "bottom" not in CANDIDATE_VIEWS- assert "low_front_left" not in CANDIDATE_VIEWS and "front_right_low" not in CANDIDATE_VIEWS- # pre-D47 stored runs must still match their own cameras- assert "front_right_34" in CANDIDATE_VIEWS and "back_left_34" in CANDIDATE_VIEWS+ assert "front_right_low" not in CANDIDATE_VIEWSviews = _views(tmp_path / "r")views.append(RenderView(name="top", path=views[0].path, width=256, height=256))ref = _shape(tmp_path / "ref.png", (20, 95, 236, 165))@@ -38,3 +36,12 @@ def test_best_view_skips_top_and_low_cameras_and_writes_the_diff(tmp_path: Path)assert "top" not in res["per_view"]assert (tmp_path / "d.png").is_file() and res["view"] == "right"assert "error" in best_view_match([], ref)+++def test_a_pre_d47_run_matches_its_own_cameras_through_one_alias_map(tmp_path: Path) -> None:+ """N62: four lists each kept a different subset of the old ``*_34`` names; now+ ``conventions.LEGACY_VIEW_ALIASES`` maps them, and the old low camera stays out as its twin does."""+ views = _views(tmp_path / "r")+ old = [RenderView(name=n, path=views[2].path, width=256, height=256) for n in ("front_right_34", "low_front_left")]+ res = best_view_match(old, _shape(tmp_path / "ref.png", (20, 95, 236, 165)))+ assert res["view"] == "front_right_34" and set(res["per_view"]) == {"front_right_34"}