Official Codebase of 3DCodeVerse
Python
ground tolerance: one conventions.GROUND_TOL_M, the contract gate's 1 cm, asserted by the Blender skeleton
gaoypengbb3537280b3b
diff --git a/harness/codeverse3d/conventions.py b/harness/codeverse3d/conventions.pyindex 6de380c0..b7de7257 100644--- a/harness/codeverse3d/conventions.py+++ b/harness/codeverse3d/conventions.py@@ -271,5 +271,9 @@ MAX_TRIS_OBJECT = 600_000MAX_TRIS_SCENE = 3_000_000#: Default tolerance for bbox contract checks, in meters.BBOX_TOLERANCE_M = 0.01+#: "Stands on the ground": the lowest point within this of up = 0 (meters). The contract gate+#: WARNs past it (ERRORs past 3x) and the Blender skeleton's self-check asserts it; texts say+#: "at up = 0" without the number (D93/D98).+GROUND_TOL_M = 0.01#: Parts are "touching" when the surface gap is below this (meters).CONTACT_GAP_M = 0.002diff --git a/harness/codeverse3d/languages/blender/__init__.py b/harness/codeverse3d/languages/blender/__init__.pyindex fc3bbe0d..93c7a85e 100644--- a/harness/codeverse3d/languages/blender/__init__.py+++ b/harness/codeverse3d/languages/blender/__init__.py@@ -12,7 +12,14 @@ 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, fmt3, to_pascal, to_snake+from codeverse3d.conventions import (+ GROUND_TOL_M,+ MAX_TRIS_OBJECT,+ PASCAL_RE,+ fmt3,+ to_pascal,+ to_snake,+)from codeverse3d.languages._ast_lint import (BASE_FORBIDDEN_IMPORTS,check_imports,@@ -640,12 +647,12 @@ def part_file_source(p: PartPlan) -> str:return doc + IMPORTS + "\n" + _constants(p) + HELPERS + "\n# ----------------------------------------------------------------------------- part\n" + _part_function(p)-def selfcheck_source(ground_tol_m: float = 0.002) -> str:+def selfcheck_source(ground_tol_m: float = GROUND_TOL_M) -> str:"""The entry's self-check with its "stands on z=0" tolerance filled in."""return SELFCHECK.replace("__GROUND_TOL__", f"{ground_tol_m:g}")-def model_file_source(plan: StaticPlan, *, ground_tol_m: float = 0.002) -> str:+def model_file_source(plan: StaticPlan, *, ground_tol_m: float = GROUND_TOL_M) -> str:"""Complete multi-file entry ``src/model.py``: imports, ordered calls, self-check."""imports = "\n".join(f"from {PARTS_DIR}.{to_snake(p.name)} import {build_fn_name(p.name)}" for p in plan.parts)calls = "\n".join(f" {build_fn_name(p.name)}()" for p in plan.parts)@@ -659,11 +666,11 @@ def model_file_source(plan: StaticPlan, *, ground_tol_m: float = 0.002) -> str:)-def write_blender_skeleton(ws: Workspace, plan: StaticPlan, *, ground_tol_m: float = 0.002) -> list[Path]:+def write_blender_skeleton(ws: Workspace, plan: StaticPlan, *, ground_tol_m: float = GROUND_TOL_M) -> list[Path]:"""Write the starter files (overwrites) and return the written paths (entry first).- ``ground_tol_m`` is the self-check's "stands on z=0" tolerance: 2 mm for an object- (the contract's ±1 mm, measured by check_contract), looser for a scene hero, which+ ``ground_tol_m`` is the self-check's "stands on z=0" tolerance: ``conventions.GROUND_TOL_M``+ for an object (the contract gate's own line), looser for a scene hero, whichthe scene seats anyway (`lib/place.js seat`) and whose module twin is allowed 20 mm."""ws.src.mkdir(parents=True, exist_ok=True)entry = ws.src / "model.py"diff --git a/harness/codeverse3d/prompts/blender/contract.md b/harness/codeverse3d/prompts/blender/contract.mdindex 2d0ed09f..fa68d927 100644--- a/harness/codeverse3d/prompts/blender/contract.md+++ b/harness/codeverse3d/prompts/blender/contract.md@@ -19,7 +19,7 @@## Frame, units, placement* **Z is up, -Y is the front, +X is the right. Meters.** (glTF export maps this toY-up / +Z-front automatically — do not pre-rotate.) The object stands on z = 0 (lowest- vertex at z = 0 ± 1 mm), footprint centred on the Z axis; real-world dimensions.+ vertex at z = 0), footprint centred on the Z axis; real-world dimensions.## Naming and structure* One Blender **object per plan part**, `obj.name = "<PartName>"` in PascalCase exactly as thediff --git a/harness/codeverse3d/prompts/system/harness_contract.md b/harness/codeverse3d/prompts/system/harness_contract.mdindex 942b0f77..627d61e0 100644--- a/harness/codeverse3d/prompts/system/harness_contract.md+++ b/harness/codeverse3d/prompts/system/harness_contract.md@@ -43,7 +43,7 @@ artifacts/ harness output (object.glb, renders/, gates/, measurement.json). RENo piece may hover. The connectivity gate hard-fails on any island with a positive gap.* **Weld by overlap, not by rods**: fix a floating piece by extending / embedding it≥ 2 mm into its neighbour, never by adding thin connector sticks.-* **Ground contact**: the lowest point of the object is at up = 0 (± 1 mm); footprint+* **Ground contact**: the lowest point of the object is at up = 0; footprintcentred on the up-axis. Scenes: bounds as declared in the plan.* **No concealed interpenetration**: neighbours that are not welded keep ≥ 15 mmclearance; limbs do not sink into bodies; rings wrap cores, they do not intersect them.diff --git a/harness/codeverse3d/prompts/threejs/contract.md b/harness/codeverse3d/prompts/threejs/contract.mdindex 2fc5aa06..854d9127 100644--- a/harness/codeverse3d/prompts/threejs/contract.md+++ b/harness/codeverse3d/prompts/threejs/contract.md@@ -55,7 +55,7 @@ are sure about (the contract gate measures the GLB anyway).```jsexport function selfcheck(THREE, root) {const box = new THREE.Box3().setFromObject(root);- if (!(box.min.y > -0.002 && box.min.y < 0.002)) throw new Error(`object not on ground: min.y=${box.min.y}`);+ if (Math.abs(box.min.y) > 0.01) throw new Error(`object not on ground: min.y=${box.min.y}`);return box;}```diff --git a/harness/codeverse3d/prompts/threejs/cookbook.md b/harness/codeverse3d/prompts/threejs/cookbook.mdindex 53aeda7f..13187e86 100644--- a/harness/codeverse3d/prompts/threejs/cookbook.md+++ b/harness/codeverse3d/prompts/threejs/cookbook.md@@ -459,7 +459,7 @@ export function selfcheck(THREE, root, expectedNames = [], extentsHint = null) {const missing = expectedNames.filter(n => !names.has(n));if (missing.length) throw new Error(`missing parts: ${missing.join(', ')}`);const box = new THREE.Box3().setFromObject(root); const size = box.getSize(new THREE.Vector3());- if (Math.abs(box.min.y) > 0.002) throw new Error(`lowest point y=${box.min.y.toFixed(4)} (expected 0)`);+ if (Math.abs(box.min.y) > 0.01) throw new Error(`lowest point y=${box.min.y.toFixed(4)} (expected 0)`);if (extentsHint) extentsHint.forEach((e, i) => { if (Math.abs(size.getComponent(i) - e) > 0.05) throw new Error(`extents ${size.toArray()} vs plan ${extentsHint}`); });console.log(`[selfcheck] parts=${names.size} tris=${tris} extents=${size.toArray().map(v => v.toFixed(3))}`);return { tris, size };diff --git a/harness/codeverse3d/prompts/urdf/cookbook.md b/harness/codeverse3d/prompts/urdf/cookbook.mdindex ba9fce62..d7850dc9 100644--- a/harness/codeverse3d/prompts/urdf/cookbook.md+++ b/harness/codeverse3d/prompts/urdf/cookbook.md@@ -421,7 +421,7 @@ def urdf_selfcheck(expected_links):assert n in PIVOT, f"no pivot recorded for {n}"bpy.context.view_layer.update()zmin = min((o.matrix_world @ Vector(c)).z for o in bpy.data.objects if o.type == 'MESH' for c in o.bound_box)- assert abs(zmin) < 0.002, f"lowest point z={zmin:.4f}"+ assert abs(zmin) < 0.01, f"lowest point z={zmin:.4f}"print("[selfcheck] links", names, "pivots ok")urdf_selfcheck(["carcass", "door", "door_handle", "drawer", "base", "lid",diff --git a/harness/codeverse3d/skills/_claims/c3d-bbox-contract.toml b/harness/codeverse3d/skills/_claims/c3d-bbox-contract.tomlindex f66cee96..9c2c6222 100644--- a/harness/codeverse3d/skills/_claims/c3d-bbox-contract.toml+++ b/harness/codeverse3d/skills/_claims/c3d-bbox-contract.toml@@ -1,5 +1,5 @@# Numbers this bundle quotes, pinned to the constants the contract gate actually reads.-# Move BBOX_TOLERANCE_M / REL_TOL / ERROR_FACTOR and the test that ships this skill fails.+# Move BBOX_TOLERANCE_M / GROUND_TOL_M / REL_TOL / ERROR_FACTOR and the test that ships this skill fails.[[claim]]key = "bbox_tolerance_m"@@ -8,6 +8,13 @@ python = "codeverse3d.conventions:BBOX_TOLERANCE_M"scale = 100format = "{:.0f} cm"+[[claim]]+key = "ground_tol_m"+text = "a gap beyond 1 cm"+python = "codeverse3d.conventions:GROUND_TOL_M"+scale = 100+format = "a gap beyond {:.0f} cm"+[[claim]]key = "bbox_rel_tol"text = "0.10"diff --git a/harness/codeverse3d/spatial/contract.py b/harness/codeverse3d/spatial/contract.pyindex f69cfc88..46ee5921 100644--- a/harness/codeverse3d/spatial/contract.py+++ b/harness/codeverse3d/spatial/contract.py@@ -16,7 +16,8 @@ Severity policy (``tol = max(tol_m, REL_TOL × plan extent)`` per axis):* overall extents are the plan's with up swapped for a horizontal axis → ERROR``data["kind"] == "orientation"`` (lying down / stood on end); the two horizontalextents swapped → WARN "turned" (the az-0 view then shows a side, not the front)-* not standing on the ground / footprint off-centre → WARN+* lowest point off up = 0 by > ``GROUND_TOL_M`` → WARN (> ``ERROR_FACTOR ×`` → ERROR);+ footprint off-centre → WARN* GLB parts the plan never mentioned → INFOEvery WARN/ERROR carries ``data["kind"]`` (missing_part · instance_count · part_bbox ·@@ -43,6 +44,7 @@ from codeverse3d.conventions import (BBOX_TOLERANCE_M,CONTACT_GAP_M,FRAME_AXES,+ GROUND_TOL_M,Frame,split_instance,to_authoring_frame,@@ -349,10 +351,10 @@ def _check_object_plan(m: Measurement, plan: StaticPlan, language: str, tol_m: fif (orient := _orientation_finding(m, plan, language)) is not None:findings.append(orient)# ground + footprint- if abs(m.ground_gap_m) > tol_m:+ if abs(m.ground_gap_m) > GROUND_TOL_M:where = "above" if m.ground_gap_m > 0 else "below"findings.append(GateFinding(- gate=GATE, severity=Severity.WARN if abs(m.ground_gap_m) <= ERROR_FACTOR * tol_m else Severity.ERROR,+ gate=GATE, severity=Severity.WARN if abs(m.ground_gap_m) <= ERROR_FACTOR * GROUND_TOL_M else Severity.ERROR,target="overall", message=f"object floats {abs(m.ground_gap_m) * 1000:.1f} mm {where} the ground",fix_hint=f"translate everything by {-m.ground_gap_m:+.4f} m along the up axis so the lowest point is at 0",data={"kind": "ground_gap", "ground_gap_m": m.ground_gap_m},diff --git a/harness/tests/blender_cadquery/test_blender_runtime.py b/harness/tests/blender_cadquery/test_blender_runtime.pyindex f166c32e..fdb138dd 100644--- a/harness/tests/blender_cadquery/test_blender_runtime.py+++ b/harness/tests/blender_cadquery/test_blender_runtime.py@@ -81,15 +81,16 @@ def test_live_timeout_and_memory_cap(tmp_ws, blender_bin) -> None:@pytest.mark.blenderdef test_live_selfcheck_skips_hidden_cutters(tmp_ws, blender_bin) -> None:"""Audit 2026-09-24 N6a: the skeleton's self-check measured a hidden boolean cutter- (`Cutter.001`, reaching z = -0.5) and failed a build whose GLB stands exactly on z = 0."""+ (`Cutter.001`, reaching z = -0.5) and failed a build whose GLB stands exactly on z = 0.+ N6c: it asserts the contract gate's `GROUND_TOL_M`, so a 5 mm lift the gate accepts builds."""from codeverse3d.languages.blender import selfcheck_source(tmp_ws.src / "model.py").write_text("import bpy\nfrom mathutils import Vector\n" + selfcheck_source() +- "bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 0.5)); body = bpy.context.object; body.name = 'Body'\n"+ "bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 0.505)); body = bpy.context.object; body.name = 'Body'\n""bpy.ops.mesh.primitive_cylinder_add(radius=0.2, depth=2, location=(0, 0, 0.5)); cut = bpy.context.object\n""cut.name = 'Cutter.001'; body.modifiers.new('Hole', 'BOOLEAN').object = cut\n""cut.hide_set(True); cut.hide_render = True\n_selfcheck()\n")r = BlenderRuntime(blender=blender_bin).build(tmp_ws, timeout_s=120)assert r.ok, (r.error_type, r.error_message)- assert "[selfcheck] 1 mesh objects, z_min=0.0000" in r.stdout_tail+ assert "[selfcheck] 1 mesh objects, z_min=0.0050" in r.stdout_tail