Official Codebase of 3DCodeVerse
Python
conventions: fmt3 (metres, 3 decimals) lives with the other units rules; blender's private _fmt — the same join in parentheses, imported by cadquery — goes
gaoypengfd535054bbf6
diff --git a/harness/codeverse3d/conventions.py b/harness/codeverse3d/conventions.pyindex 7e56f921..31777050 100644--- a/harness/codeverse3d/conventions.py+++ b/harness/codeverse3d/conventions.py@@ -206,6 +206,11 @@ def slugify(text: str, max_len: int = 48) -> str:return s or "run"+def fmt3(vec: Sequence[float]) -> str:+ """A vector as the prompts print it: ``0.100, 0.250, -0.030`` (metres, 3 decimals)."""+ return ", ".join(f"{float(x):.3f}" for x in vec)++# --------------------------------------------------------------------------- limits#: Triangle budgets used by gates/prompts (soft caps; judge sees the count).MAX_TRIS_OBJECT = 600_000diff --git a/harness/codeverse3d/languages/blender/__init__.py b/harness/codeverse3d/languages/blender/__init__.pyindex 1e8ad237..e6b06621 100644--- a/harness/codeverse3d/languages/blender/__init__.py+++ b/harness/codeverse3d/languages/blender/__init__.py@@ -12,7 +12,7 @@ from codeverse3d.config import Settings, get_settingsfrom codeverse3d.contracts.artifacts import BuildResult, GateFinding, GateReport, Severityfrom codeverse3d.contracts.common import ENTRY_FILE, Languagefrom codeverse3d.contracts.plan import BBox, PartPlan, Plan, StaticPlan-from codeverse3d.conventions import MAX_TRIS_OBJECT, PASCAL_RE, to_pascal, to_snake+from codeverse3d.conventions import MAX_TRIS_OBJECT, PASCAL_RE, fmt3, to_pascal, to_snakefrom codeverse3d.languages._ast_lint import (BASE_FORBIDDEN_IMPORTS,check_imports,@@ -448,10 +448,6 @@ def instance_centers(bbox: BBox, n: int, symmetry: str) -> list[tuple[float, floreturn [(cx, cy, cz) for _ in range(n)]-def _fmt(v: tuple[float, float, float]) -> str:- return "(" + ", ".join(f"{x:.3f}" for x in v) + ")"--def _bevel(bbox: BBox) -> float:return max(0.0, min(0.01, 0.08 * min(bbox.extents)))@@ -516,10 +512,10 @@ def _constants(p: PartPlan) -> str:pre = to_snake(p.name).upper()return (f"# ---- plan numbers (metres) for {to_pascal(p.name)} — keep the finished part inside this bbox\n"- f"{pre}_CENTER = {_fmt(p.bbox.center)}\n"- f"{pre}_EXTENTS = {_fmt(p.bbox.extents)}\n"- f"{pre}_MIN = {_fmt(mn)}\n"- f"{pre}_MAX = {_fmt(mx)}\n"+ f"{pre}_CENTER = ({fmt3(p.bbox.center)})\n"+ f"{pre}_EXTENTS = ({fmt3(p.bbox.extents)})\n"+ f"{pre}_MIN = ({fmt3(mn)})\n"+ f"{pre}_MAX = ({fmt3(mx)})\n"f"{pre}_INSTANCES = {p.instances}\n")@@ -535,7 +531,7 @@ def _part_function(p: PartPlan) -> str:f' """{pascal} — {p.role}',f" {p.description}",f" Material: {p.material or 'n/a'}",- f" Plan bbox: center {_fmt(p.bbox.center)} extents {_fmt(p.bbox.extents)}",+ f" Plan bbox: center ({fmt3(p.bbox.center)}) extents ({fmt3(p.bbox.extents)})",f" x in [{mn[0]:.3f}, {mx[0]:.3f}] y in [{mn[1]:.3f}, {mx[1]:.3f}] z in [{mn[2]:.3f}, {mx[2]:.3f}]",]if p.attach_to:@@ -544,7 +540,7 @@ def _part_function(p: PartPlan) -> str:lines.append(f" Instances: {p.instances} ({p.symmetry}) -> named {pascal}_0..{pascal}_{p.instances - 1}, "f"each TOP-LEVEL (no parent Empty — it would merge them into one measured part); returns the list")lines += [' Returns the object(s) at WORLD pose (Z up, -Y front, metres).', ' """']- lines.append(f" mat = make_material(\"{pascal}Mat\", {_fmt(rgb)}, roughness={rough}, metallic={metal})")+ lines.append(f" mat = make_material(\"{pascal}Mat\", ({fmt3(rgb)}), roughness={rough}, metallic={metal})")if p.instances == 1:lines += [" # TODO: replace this placeholder box with the real geometry (keep the name + bbox)",@@ -565,8 +561,8 @@ def _part_function(p: PartPlan) -> str:def _plan_header(plan: StaticPlan) -> str:ob = plan.overall_bboxparts_doc = "\n".join(- f" - {to_pascal(p.name)}{'' if p.instances == 1 else f' x{p.instances}'}: {p.role}; bbox center {_fmt(p.bbox.center)} "- f"extents {_fmt(p.bbox.extents)} [{part_file_rel(p.name)}]"+ f" - {to_pascal(p.name)}{'' if p.instances == 1 else f' x{p.instances}'}: {p.role}; bbox center ({fmt3(p.bbox.center)}) "+ f"extents ({fmt3(p.bbox.extents)}) [{part_file_rel(p.name)}]"for p in plan.parts)accept = "\n".join(f" - [{a.id}] {a.text}" for a in plan.acceptance) or " (none listed)"@@ -582,7 +578,7 @@ Style: {plan.style_notes or "n/a"}CONTRACT (the harness runs this file in an EMPTY scene with `blender -b --factory-startup`):* Z is up, -Y is the FRONT, units are METERS. Object stands on z=0, footprint centred on Z.- * Overall bbox: center {_fmt(ob.center)} extents {_fmt(ob.extents)}+ * Overall bbox: center ({fmt3(ob.center)}) extents ({fmt3(ob.extents)})-> x in [{ob.min[0]:.3f}, {ob.max[0]:.3f}] y in [{ob.min[1]:.3f}, {ob.max[1]:.3f}] z in [{ob.min[2]:.3f}, {ob.max[2]:.3f}]* One mesh object per part, named EXACTLY as below (PascalCase); instances Name_0..Name_N-1,each TOP-LEVEL (never parented under an Empty — that merges them into ONE measured part).diff --git a/harness/codeverse3d/languages/cadquery/__init__.py b/harness/codeverse3d/languages/cadquery/__init__.pyindex 5e4ecbcf..50818014 100644--- a/harness/codeverse3d/languages/cadquery/__init__.py+++ b/harness/codeverse3d/languages/cadquery/__init__.py@@ -13,7 +13,7 @@ from codeverse3d.config import Settings, get_settingsfrom codeverse3d.contracts.artifacts import BuildResult, GateFinding, GateReport, Severityfrom codeverse3d.contracts.common import ENTRY_FILE, Languagefrom codeverse3d.contracts.plan import PartPlan, Plan, StaticPlan-from codeverse3d.conventions import MAX_TRIS_OBJECT, PASCAL_RE, to_pascal, to_snake+from codeverse3d.conventions import MAX_TRIS_OBJECT, PASCAL_RE, fmt3, to_pascal, to_snakefrom codeverse3d.languages._ast_lint import (BASE_FORBIDDEN_IMPORTS,ImportCollector,@@ -24,7 +24,7 @@ from codeverse3d.languages._ast_lint import ()from codeverse3d.languages._common import run_wrapper_buildfrom codeverse3d.languages.base import RuntimeLayout-from codeverse3d.languages.blender import _fmt, finish_for, instance_centers+from codeverse3d.languages.blender import finish_for, instance_centersfrom codeverse3d.proc import scrub_secretsfrom codeverse3d.workspace import Workspace@@ -221,7 +221,7 @@ def _part_function(p: PartPlan) -> str:f' """{pascal} — {p.role}',f" {p.description}",f" Material: {p.material or 'n/a'}",- f" Plan bbox (world, Z-up): center {_fmt(p.bbox.center)} extents {_fmt(p.bbox.extents)}",+ f" Plan bbox (world, Z-up): center ({fmt3(p.bbox.center)}) extents ({fmt3(p.bbox.extents)})",f" x in [{mn[0]:.3f}, {mx[0]:.3f}] y in [{mn[1]:.3f}, {mx[1]:.3f}] z in [{mn[2]:.3f}, {mx[2]:.3f}]",]if p.attach_to:@@ -234,7 +234,7 @@ def _part_function(p: PartPlan) -> str:else:lines.append(' """')lines.append(" # TODO: replace the placeholder box with the real geometry (keep the name + bbox)")- lines.append(f" return cq.Workplane(\"XY\").box({ex:.3f}, {ey:.3f}, {ez:.3f}).translate({_fmt(p.bbox.center)})")+ lines.append(f" return cq.Workplane(\"XY\").box({ex:.3f}, {ey:.3f}, {ez:.3f}).translate(({fmt3(p.bbox.center)}))")lines += ["", ""]return "\n".join(lines)@@ -260,7 +260,7 @@ def cadquery_skeleton_source(plan: StaticPlan) -> str:"""Return the complete starter ``model.py`` text for ``plan``."""ob = plan.overall_bboxparts_doc = "\n".join(- f" - {to_pascal(p.name)}{'' if p.instances == 1 else f' x{p.instances}'}: {p.role}; bbox center {_fmt(p.bbox.center)} extents {_fmt(p.bbox.extents)}"+ f" - {to_pascal(p.name)}{'' if p.instances == 1 else f' x{p.instances}'}: {p.role}; bbox center ({fmt3(p.bbox.center)}) extents ({fmt3(p.bbox.extents)})"for p in plan.parts)accept = "\n".join(f" - [{a.id}] {a.text}" for a in plan.acceptance) or " (none listed)"@@ -271,7 +271,7 @@ Style: {plan.style_notes or "n/a"}CONTRACT (the harness imports this file and exports `result` to GLB/STEP/STL itself):* Z is up, -Y is the FRONT, units are METERS. Object stands on z=0, footprint centred on Z.- * Overall bbox: center {_fmt(ob.center)} extents {_fmt(ob.extents)}+ * Overall bbox: center ({fmt3(ob.center)}) extents ({fmt3(ob.extents)})-> x in [{ob.min[0]:.3f}, {ob.max[0]:.3f}] y in [{ob.min[1]:.3f}, {ob.max[1]:.3f}] z in [{ob.min[2]:.3f}, {ob.max[2]:.3f}]* `result` = cq.Assembly; one `.add(shape, name="PascalName", color=cq.Color(r, g, b))` per part,instances Name_0..Name_N-1 (a shape built at the origin + `loc=cq.Location(cq.Vector(x, y, z))`).diff --git a/harness/codeverse3d/tracks/depth.py b/harness/codeverse3d/tracks/depth.pyindex 8186f5d7..4192732f 100644--- a/harness/codeverse3d/tracks/depth.py+++ b/harness/codeverse3d/tracks/depth.py@@ -38,7 +38,7 @@ from dataclasses import dataclassfrom typing import Anyfrom codeverse3d.config import get_settings-from codeverse3d.conventions import MAX_TRIS_OBJECT, to_pascal, to_snake+from codeverse3d.conventions import MAX_TRIS_OBJECT, fmt3, to_pascal, to_snakelog = logging.getLogger(__name__)@@ -282,11 +282,6 @@ def interfaces_text(plan: Any, scope: PartScope) -> str:return head + "\n" + "\n".join(rows)-def fmt3(vec: Sequence[float]) -> str:- """A vector as the prompts print it: ``0.100, 0.250, -0.030`` (metres, 3 decimals)."""- return ", ".join(f"{float(x):.3f}" for x in vec)--# --------------------------------------------------------------------------- the budget gateBUDGET_GATE = "detail_budget"diff --git a/harness/codeverse3d/tracks/prompting.py b/harness/codeverse3d/tracks/prompting.pyindex 52c5a3aa..2354bb4d 100644--- a/harness/codeverse3d/tracks/prompting.py+++ b/harness/codeverse3d/tracks/prompting.py@@ -17,7 +17,7 @@ from codeverse3d.contracts.chat import ImagePartfrom codeverse3d.contracts.common import HARNESS_OWNED_SRC, Language, Track, is_harness_ownedfrom codeverse3d.contracts.plan import Plan, StaticPlanfrom codeverse3d.contracts.run import RoundRecord-from codeverse3d.conventions import LANGUAGE_FRAME, frame_doc, to_authoring_frame, to_snake+from codeverse3d.conventions import LANGUAGE_FRAME, fmt3, frame_doc, to_authoring_frame, to_snakefrom codeverse3d.prompts import renderfrom codeverse3d.prompts.catalog import language_prompt, language_textfrom codeverse3d.tracks.common import RunContext@@ -26,7 +26,6 @@ from codeverse3d.tracks.depth import (DepthBudget,PartScope,depth_budget,- fmt3,interfaces_text,)from codeverse3d.tracks.generation import SINGLE_SHOT_FORMAT