Skip to content

Official Codebase of 3DCodeVerse

Python

scene runtime: render_asset — a procedural module is judged on the rig a hero's GLB gets

gaoypeng15c8e7c5e0a8
diff --git a/harness/codeverse/languages/scene_threejs/__init__.py b/harness/codeverse/languages/scene_threejs/__init__.py
index ec7c6835..298983df 100644
--- a/harness/codeverse/languages/scene_threejs/__init__.py
+++ b/harness/codeverse/languages/scene_threejs/__init__.py
@@ -11,7 +11,7 @@ from typing import Any
from pydantic import BaseModel, Field
from codeverse.config import get_settings
-from codeverse.contracts.artifacts import BuildResult, GateFinding, GateReport, Severity
+from codeverse.contracts.artifacts import BuildResult, GateFinding, GateReport, RenderSet, Severity
from codeverse.contracts.common import ENTRY_FILE, Language
from codeverse.contracts.plan import AssetPlan, CameraPlan, Plan, ScenePlan, ZonePlan
from codeverse.conventions import to_pascal, to_snake
@@ -676,6 +676,35 @@ class SceneThreeJsRuntime(RuntimeDocs):
def lint(self, ws: Workspace) -> GateReport:
return lint(ws) # the module-level gates function (class ns is not in method scope)
+ def render_asset(self, ws: Workspace, name: str, out_dir: Path, *, timeout_s: float = 180.0) -> RenderSet:
+ """Quick sheet of ONE procedural asset module, on the rig a Blender hero's GLB gets.
+
+ ``src/assets/<snake>.js`` is exported to a GLB by ``runtime_js/export_glb.mjs`` (the
+ object track's exporter, through a two-line entry that calls ``build<Pascal>``) and
+ rendered with ``spatial.render.render_glb``. This is the hook ``scene_assets`` looks
+ for before judging a threejs asset; nothing defined it until 2026-09-07, so no
+ procedural asset was ever judged (0 of 860 recorded) while every hero was.
+ """
+ from codeverse.conventions import OBJECT_VIEWS_QUICK
+ from codeverse.spatial.node import run_node, runtime_js_dir
+ from codeverse.spatial.render import RenderError, render_glb
+
+ snake, pascal = to_snake(name), to_pascal(name)
+ tmp = ws.artifacts / "asset_export" / snake
+ (tmp / "src").mkdir(parents=True, exist_ok=True)
+ module = (ws.src / "assets" / f"{snake}.js").resolve().as_posix()
+ (tmp / "src" / "object.js").write_text(
+ f"import {{ build{pascal} }} from '{module}';\n"
+ f"export function build(THREE) {{ return build{pascal}(THREE, {{}}); }}\n")
+ (tmp / "package.json").write_text('{"type": "module"}\n')
+ glb = tmp / "object.glb"
+ res = run_node(runtime_js_dir() / "export_glb.mjs",
+ ["--ws", str(tmp), "--entry", "src/object.js", "--out", str(glb), "--census", str(tmp / "census.json")],
+ cwd=tmp, three_hook=True, timeout_s=timeout_s, check=False)
+ if not glb.is_file():
+ raise RenderError(f"asset export failed for {name}: {(res.stderr or res.stdout or '')[-600:]}")
+ return render_glb(glb, out_dir, views=list(OBJECT_VIEWS_QUICK), width=512, height=512, sheet=True)
+
def build(self, ws: Workspace, *, timeout_s: int | None = None) -> BuildResult:
"""Probe + shader preflight (one browser boot); ok iff the module loads
and no shader errors. External contract unchanged: the same two
diff --git a/harness/tests/scene_runtime/test_glb_asset_naming.py b/harness/tests/scene_runtime/test_glb_asset_naming.py
index c17eb792..07ed4c66 100644
--- a/harness/tests/scene_runtime/test_glb_asset_naming.py
+++ b/harness/tests/scene_runtime/test_glb_asset_naming.py
@@ -100,3 +100,22 @@ def test_the_clone_the_zone_places_carries_the_name_too(loaded):
def test_a_plan_without_glb_assets_emits_no_loader():
src = render_scene_js(["z"], [], [], env_ok=False)
assert "assetFiles" not in src and "loadAsync" not in src
+
+
+def test_a_procedural_asset_is_rendered_on_the_hero_rig(tmp_ws):
+ """`render_asset` is the hook `scene_assets` judges a threejs asset through: the module is
+ exported by the object track's exporter and rendered on the quick rig a hero's GLB gets.
+ Nothing defined it until 2026-09-07, so 0 of 860 recorded procedural assets were judged."""
+ from codeverse.languages.scene_threejs import SceneThreeJsRuntime
+
+ (tmp_ws.src / "assets").mkdir(parents=True, exist_ok=True)
+ (tmp_ws.src / "assets" / "crate.js").write_text(
+ "import * as THREE from 'three';\n"
+ "export function buildCrate(THREE, opts = {}) {\n"
+ " const g = new THREE.Group(); g.name = 'Crate';\n"
+ " const box = new THREE.Mesh(new THREE.BoxGeometry(0.6, 0.4, 0.3), new THREE.MeshStandardMaterial({ color: 0x886644 }));\n"
+ " box.position.y = 0.2; box.name = 'Body'; g.add(box); return g;\n}\n")
+ out = tmp_ws.artifacts / "renders" / "assets" / "crate"
+ rs = SceneThreeJsRuntime().render_asset(tmp_ws, "Crate", out)
+ assert rs.contact_sheet and (out / "sheet.png").is_file() and len(rs.views) >= 4
+ assert (tmp_ws.artifacts / "asset_export" / "crate" / "object.glb").is_file()