Skip to content

Official Codebase of 3DCodeVerse

Python

URDF link names: one conventions.LINK_NAME_RE (snake_case, PascalCase accepted); agents may ground their own object

gaoypengfe54c85c93ad
diff --git a/harness/codeverse3d/conventions.py b/harness/codeverse3d/conventions.py
index 0058d9d8..03844867 100644
--- a/harness/codeverse3d/conventions.py
+++ b/harness/codeverse3d/conventions.py
@@ -211,6 +211,14 @@ def to_snake(name: str) -> str:
PASCAL_RE = re.compile(r"^[A-Z][A-Za-z0-9]*(?:_\d+)?$")
+#: a URDF link name — also its Blender object name and its ``meshes/<link>.glb`` stem. The
+#: skeleton writes the plan part's snake_case key (``DoorHandle`` → ``door_handle``); the plan's
+#: PascalCase spelling is accepted too, because every gate matches parts by :func:`to_snake`.
+#: Either way a plain identifier — never ``Door.001``, a space or a path. The Blender-run link
+#: wrapper keeps a copy (``run_bpy_links._SAFE_LINK``); ``tests/core/test_names.py`` pins them.
+LINK_NAME_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_]*$")
+
+
#: how an instance name maps to its part: ``Leg_2`` (the contract's ``Name_N``), Blender's
#: auto-suffix ``Leg.001`` and ``Leg-2`` all read as part ``Leg``; up to three digits, so a
#: scene asset's hex id that happens to be all digits (``DonkeyCart_800006``) is no index.
diff --git a/harness/codeverse3d/languages/urdf/__init__.py b/harness/codeverse3d/languages/urdf/__init__.py
index 0fa442b0..de164e07 100644
--- a/harness/codeverse3d/languages/urdf/__init__.py
+++ b/harness/codeverse3d/languages/urdf/__init__.py
@@ -7,7 +7,6 @@ import ast
import contextlib
import math
import os
-import re
import shutil
import time
import xml.etree.ElementTree as ET
@@ -21,7 +20,7 @@ from codeverse3d.config import Settings, get_settings
from codeverse3d.contracts.artifacts import BuildResult, GateFinding, GateReport, Severity
from codeverse3d.contracts.common import ENTRY_FILE, Language, MimicSpec, mimic_issues
from codeverse3d.contracts.plan import ArticulatedPlan, JointPlan, PartPlan, Plan
-from codeverse3d.conventions import to_snake
+from codeverse3d.conventions import LINK_NAME_RE, to_snake
from codeverse3d.languages._ast_lint import dotted, safe_parse
from codeverse3d.languages._common import compose_build_result, missing_entry, strip_blender_noise
from codeverse3d.languages.base import RuntimeLayout
@@ -102,9 +101,6 @@ GATE = "lint:urdf"
URDF_REL = "src/robot.urdf"
MODEL_REL = ENTRY_FILE[Language.URDF_BLENDER]
_STATE_WORDS = ("open", "closed", "opened", "extended", "retracted", "raised", "lowered", "folded", "unfolded")
-#: link names double as Blender object names and ``meshes/<link>.glb`` stems: plain
-#: identifiers only (``door``, ``handle_left``, ``DoorHandle``) — never ``Door.001`` / spaces.
-_IDENT = re.compile(r"^[A-Za-z][A-Za-z0-9_]*$")
#: model.py runs in the SAME Blender python as the blender language's model.py, so it is linted
#: by that language's rules (``lint_blender_source``: imports, harness-owned and removed bpy APIs,
@@ -260,7 +256,7 @@ def _lint_link(el: ET.Element, name: str, out: list[GateFinding]) -> None:
if name in RESERVED_LINK_NAMES:
out.append(_f(Severity.ERROR, f"link name '{name}' is reserved by the GLB scene graph (glTF readers use it as the base frame)",
target=name, fix="Rename the link (e.g. 'base' or the part's name) in BOTH robot.urdf and model.py."))
- if not _IDENT.match(name):
+ if not LINK_NAME_RE.match(name):
out.append(_f(Severity.WARN, f"link name '{name}' is not a plain identifier (letters/digits/underscore)", target=name,
fix=f"Rename to '{to_snake(name)}' in BOTH robot.urdf and model.py (object names are case-sensitive; "
"Blender's auto-suffix '.001' means two objects shared a name)."))
diff --git a/harness/codeverse3d/languages/wrappers/run_bpy_links.py b/harness/codeverse3d/languages/wrappers/run_bpy_links.py
index 97c6f65b..94dd2377 100644
--- a/harness/codeverse3d/languages/wrappers/run_bpy_links.py
+++ b/harness/codeverse3d/languages/wrappers/run_bpy_links.py
@@ -53,7 +53,7 @@ def _snake(name: str) -> str:
#: link names double as ``meshes/<link>.glb`` filename stems: plain identifiers only.
-#: The lint layer states the same rule (``languages/urdf/lint._IDENT``) but only WARNs,
+#: The lint layer states the same rule (``conventions.LINK_NAME_RE``) but only WARNs,
#: so the wrapper enforces it — ``../evil`` must be a build error, never a file written
#: outside ``meshes/``.
_SAFE_LINK = re.compile(r"[A-Za-z][A-Za-z0-9_]*")
diff --git a/harness/codeverse3d/prompts/blender/system.md b/harness/codeverse3d/prompts/blender/system.md
index 04d42781..b586cb1d 100644
--- a/harness/codeverse3d/prompts/blender/system.md
+++ b/harness/codeverse3d/prompts/blender/system.md
@@ -42,8 +42,10 @@ Rules that survive every brief:
never by eyeballing a scale factor.
* **Name every object exactly as the plan names it**, and give it nothing else: no
`.001` duplicates, no leftover `Cube`, no empties. The gates match on names.
-* **Do not re-centre or ground the object.** Export it as authored. The harness measures
- where you put it, and a helpful `origin_set` destroys the thing being measured.
+* **You place the object; the harness exports it as authored.** It never re-centres or
+ grounds it and measures where you put it, so seating the whole assembly on the ground
+ yourself (the cookbook's `drop_to_ground`) is fine — a helpful `origin_set` is not: it
+ destroys the thing being measured.
* **Build parts as separate objects**, joined only where the plan says they are one part.
A single merged mesh cannot be checked, cannot be isolated, and scores worse.
diff --git a/harness/codeverse3d/prompts/cadquery/system.md b/harness/codeverse3d/prompts/cadquery/system.md
index 4b289b09..df474358 100644
--- a/harness/codeverse3d/prompts/cadquery/system.md
+++ b/harness/codeverse3d/prompts/cadquery/system.md
@@ -45,7 +45,8 @@ Rules that survive every brief:
chair is 0.45 m to the seat. State the unit conversion once, explicitly.
* **Prefer a boolean to a fillet** when you need a soft edge on a thin wall. The kernel
will do a `cut` with a rounded tool where it refuses a `fillet`.
-* **Do not re-centre or ground the object.** Export it as authored.
+* **You place the object; the harness exports it as authored.** It never re-centres or
+ grounds it, so seating the whole assembly on the ground yourself is fine.
A clean simpler solid beats a richer one whose fillets silently failed. Get the build
clean first, then add the detail the brief asked for.
diff --git a/harness/codeverse3d/prompts/system/harness_contract.md b/harness/codeverse3d/prompts/system/harness_contract.md
index 627d61e0..829cb524 100644
--- a/harness/codeverse3d/prompts/system/harness_contract.md
+++ b/harness/codeverse3d/prompts/system/harness_contract.md
@@ -29,8 +29,10 @@ artifacts/ harness output (object.glb, renders/, gates/, measurement.json). RE
meters, attach_to, instances. **Use those numbers literally** in your code (as named
constants at the top of the file). If you disagree with a number, keep the plan's value
and note why in a comment — do not silently drift.
-* Part names are PascalCase and unique (`SeatCushion`, `LeftFrontLeg`); object / node /
- link names in the exported artifact must equal the plan's part names exactly.
+* Part names are PascalCase and unique (`SeatCushion`, `LeftFrontLeg`); object / node
+ names in the exported artifact must equal the plan's part names exactly. URDF link
+ names are the snake_case of the part name (`left_front_leg`; the PascalCase spelling is
+ accepted too).
* Deterministic: seed every random source (`random.seed(0)`, a hash-based `rand(i)`), no
time-dependent geometry. Two builds of the same code must produce identical geometry.
* Real-world scale: a chair seat is 0.45 m high, a door 2.0 m, a mug 0.09 m. Check your
diff --git a/harness/codeverse3d/prompts/threejs/system.md b/harness/codeverse3d/prompts/threejs/system.md
index 9a87aaac..04015ffb 100644
--- a/harness/codeverse3d/prompts/threejs/system.md
+++ b/harness/codeverse3d/prompts/threejs/system.md
@@ -44,7 +44,8 @@ Rules that survive every brief:
in this corpus are that one term.
* **Give every part real material properties** but no lights and no environment — the
harness lights the scene, and a light you add is a light it did not expect.
-* **Do not re-centre or ground the object.** Export it as authored.
+* **You place the object; the harness exports it as authored.** It never re-centres or
+ grounds it, so seating the whole assembly on the ground yourself is fine.
A clean simpler object beats a richer one carrying a visible defect. Clear connectivity
and contract first, then spend what is left on the detail the brief asked for.
diff --git a/harness/codeverse3d/prompts/tracks/generate_articulated.j2 b/harness/codeverse3d/prompts/tracks/generate_articulated.j2
index 22c3aad2..8cc2fc0f 100644
--- a/harness/codeverse3d/prompts/tracks/generate_articulated.j2
+++ b/harness/codeverse3d/prompts/tracks/generate_articulated.j2
@@ -26,7 +26,8 @@ Cookbook excerpt:
Overall bbox (rest pose): {{ overall_bbox }}
Style: {{ style_notes }}
-Links (one bpy object each, named EXACTLY like the `part` column):
+Links (one bpy object each; link name = the snake_case of the `part` column, `DoorHandle` →
+`door_handle`, as the skeleton writes it — the PascalCase spelling is accepted too):
{{ parts_table }}
Link construction notes:
diff --git a/harness/codeverse3d/prompts/urdf/system.md b/harness/codeverse3d/prompts/urdf/system.md
index 92464ff8..35d5ba48 100644
--- a/harness/codeverse3d/prompts/urdf/system.md
+++ b/harness/codeverse3d/prompts/urdf/system.md
@@ -46,8 +46,8 @@ Rules that survive every brief:
modelling error the sweep will find.
* **The kinematic tree is a tree.** One root, every other link reachable through exactly
one parent. No cycles, no orphans, no link named in a joint that does not exist.
-* **Author in metres at real scale**, and do not re-centre or ground the assembly. Export
- it as authored.
+* **Author in metres at real scale.** The harness exports the assembly as authored and
+ never re-centres or grounds it, so seating it on the ground yourself is fine.
A mechanism that moves cleanly through its whole range beats a more detailed one that
jams. Clear `joint_sweep` first; spend what is left on the geometry.
diff --git a/harness/tests/core/test_names.py b/harness/tests/core/test_names.py
index a3484a92..67b0cd6a 100644
--- a/harness/tests/core/test_names.py
+++ b/harness/tests/core/test_names.py
@@ -10,10 +10,10 @@ from pathlib import Path
from codeverse3d.contracts.common import Track
from codeverse3d.contracts.plan import StaticPlan
+from codeverse3d.conventions import LINK_NAME_RE as URDF_LINK_RE
from codeverse3d.conventions import PASCAL_RE, part_key, split_instance, to_pascal, to_snake
from codeverse3d.languages.blender import lint_blender_source
from codeverse3d.languages.cadquery import lint_cadquery_source
-from codeverse3d.languages.urdf import _IDENT as URDF_LINK_RE
from codeverse3d.texturing.materials import family_for
from codeverse3d.tracks.planner import normalise_names, plan_example
@@ -85,7 +85,12 @@ def test_the_part_name_lints_accept_acronyms():
assert not any("not PascalCase" in f.message for f in lint_cadquery_source(src).findings)
rep = lint_blender_source("import bpy\nobj = bpy.context.object\nobj.name = 'USBPort'\n")
assert any("named objects" in f.message and "USBPort" in f.message for f in rep.findings)
- assert all(URDF_LINK_RE.match(n) for n in ("TVStand", "LED", "CPU_2", "A"))
+ # N47o: a URDF link is the part's snake key, the PascalCase spelling accepted — one rule, and
+ # the Blender-run link wrapper's copy of it is the same pattern
+ assert all(URDF_LINK_RE.match(n) for n in ("TVStand", "LED", "CPU_2", "A", "door_handle", "DoorHandle"))
+ assert not any(URDF_LINK_RE.match(n) for n in ("Door.001", "door handle", "../evil", "9lives"))
+ safe = _wrapper_assign("run_bpy_links.py", "_SAFE_LINK")
+ assert f"^{ast.literal_eval(safe.value.args[0])}$" == URDF_LINK_RE.pattern # type: ignore[attr-defined]
def test_material_words_split_acronyms():