Skip to content

Official Codebase of 3DCodeVerse

Python

scene starter: the library's sun rig and its environment map light every scene; a small thing kilometres away is backdrop

gaoypengc4addd392e67
diff --git a/harness/codeverse/languages/scene_threejs/starter/src/env.js b/harness/codeverse/languages/scene_threejs/starter/src/env.js
index 1c22d2b0..616de1b3 100644
--- a/harness/codeverse/languages/scene_threejs/starter/src/env.js
+++ b/harness/codeverse/languages/scene_threejs/starter/src/env.js
@@ -3,6 +3,7 @@
// export function heightAt(x, z) → ground height (m) so zones can seat objects.
import * as THREE from 'three';
import { makeSkyMaterial } from './shaders/sky.js';
+import { sunRig } from './lib/environment.js';
export const SUN_AZIMUTH_DEG = 60; // where the sun is (0 = +Z front, CCW from above); cameras on the sun side are front-lit
export const SUN_ELEVATION_DEG = 38;
@@ -48,19 +49,16 @@ export function buildEnv(ctx) {
sky.frustumCulled = false;
group.add(sky);
- // --- lights: one shadow-casting sun + hemisphere fill (sky/ground colours)
- const sun = new THREE.DirectionalLight(0xfff1d6, 2.6);
- sun.position.set(Math.sin(az) * Math.cos(el) * 80, Math.sin(el) * 80, Math.cos(az) * Math.cos(el) * 80);
- sun.castShadow = true;
- sun.shadow.mapSize.set(2048, 2048);
- sun.shadow.camera.near = 10; sun.shadow.camera.far = 220;
- sun.shadow.camera.left = -45; sun.shadow.camera.right = 45;
- sun.shadow.camera.top = 45; sun.shadow.camera.bottom = -45;
- sun.shadow.bias = -0.0005; sun.shadow.normalBias = 0.02;
- sun.target.position.set(0, 0, 0);
- group.add(sun, sun.target);
- const hemi = new THREE.HemisphereLight(0xbcd7ff, 0x4a5a2a, 0.9);
- group.add(hemi);
+ // --- lights + the baked environment: the library's rig — sun, hemisphere fill, the env map
+ // metals read from, the visible disc. Measured 2026-09-07 on this renderer: a metalness-0.9
+ // sphere renders near black under hand-rolled sun + hemi (no scene.environment) and reads as
+ // metal with this rig; every recorded Blender hero carried metalness 0.7-0.9 into a scene
+ // whose env.js set no environment map (0 of 127).
+ const rig = sunRig({ azimuth: SUN_AZIMUTH_DEG, elevation: SUN_ELEVATION_DEG, bounds: 45 });
+ const sun = rig.sun, hemi = rig.fill;
+ group.add(sun, sun.target, hemi);
+ if (rig.sunDisc) group.add(rig.sunDisc);
+ scene.environment = rig.envTex;
// --- fog + background matched to the sky horizon colour
scene.fog = new THREE.Fog(0xcfdcec, FOG_NEAR, FOG_FAR);
diff --git a/harness/codeverse/prompts/tracks/scene_env.j2 b/harness/codeverse/prompts/tracks/scene_env.j2
index d9edfdb6..87cc0938 100644
--- a/harness/codeverse/prompts/tracks/scene_env.j2
+++ b/harness/codeverse/prompts/tracks/scene_env.j2
@@ -63,6 +63,10 @@ The chapters behind these rules are printed in full at the end of this brief
and trip the `unlit_or_blown` defect (cap 0.60). Add 3-4 haze bands
(`depthWrite:false`, opacity 0.04-0.10, fog colour) for aerial perspective, and light shafts
if the brief mentions sun through something.
+4b. **Keep `scene.environment`.** The skeleton lights the scene with `sunRig()` from
+ `lib/environment.js` and assigns its `envTex` to `scene.environment`; metals and glass read
+ from that map and render near black without it. Change the mood/azimuth through the rig's
+ options, not by replacing it with bare lights.
5. **Shadows must not be jagged.** Shadow texel = `2 x shadowSpan / mapSize` <= 0.05 m: fit the
shadow camera to the BOUNDS (not the whole ground), then pick mapSize 2048 (span <= 30 m) /
3072 (<= 60 m) / 4096 (larger). `bias = -0.0004`, `normalBias = 0.02`.
diff --git a/harness/runtime_js/lib/backdrop.mjs b/harness/runtime_js/lib/backdrop.mjs
index cef3d565..a72fa126 100644
--- a/harness/runtime_js/lib/backdrop.mjs
+++ b/harness/runtime_js/lib/backdrop.mjs
@@ -54,6 +54,12 @@ export function classifyBackdrop(obj, box, contentSpan = 0) {
const span = Math.max(sx, sz);
if (SKY_NAME_RE.test(name) && span > 50) return 'sky';
if (span > 2000 || (sy > 300 && span > 300)) return 'sky';
+ // a small thing kilometres from the origin is a backdrop whatever it is called: the sun/moon
+ // disc `sunRig` parks at 0.9 × the sky radius ('SunDisc' — no word boundary for the regex)
+ // blew the content bbox to 2.5 km and put the overview rig 5 km up (measured 2026-09-07)
+ const far = Math.max(Math.abs(box.min.x), Math.abs(box.max.x), Math.abs(box.min.y), Math.abs(box.max.y),
+ Math.abs(box.min.z), Math.abs(box.max.z));
+ if (far > 1500 && span < 0.1 * far) return 'sky';
if (obj.isInstancedMesh) return 'content'; // scattered instances span the map but are not ground
if (span > 20 && sy < 0.06 * span && GROUND_NAME_RE.test(name)) return 'ground';
if (span > 40 && sy < 0.02 * span) return 'ground';
diff --git a/harness/tests/scene_gates/test_live_frames.py b/harness/tests/scene_gates/test_live_frames.py
index 74d8b6f1..7a3db91c 100644
--- a/harness/tests/scene_gates/test_live_frames.py
+++ b/harness/tests/scene_gates/test_live_frames.py
@@ -29,8 +29,11 @@ pytestmark = [pytest.mark.node, needs_browser]
def _darken(ws: Workspace) -> None:
env = ws.src / "env.js"
text = env.read_text()
- text = text.replace("new THREE.DirectionalLight(0xfff1d6, 2.6)", "new THREE.DirectionalLight(0xfff1d6, 0.05)")
- text = text.replace("new THREE.HemisphereLight(0xbcd7ff, 0x4a5a2a, 0.9)", "new THREE.HemisphereLight(0x101018, 0x000000, 0.02)")
+ # the starter lights through lib/environment.js sunRig (2026-09-07): crush the rig's sun and
+ # fill AFTER it is built (its `fill` option is clamped UP to a readability floor) and drop
+ # the env map, which lights metals and glass on its own
+ text = text.replace(" scene.environment = rig.envTex;",
+ " scene.environment = null; sun.intensity = 0.05; hemi.intensity = 0.02; hemi.color.set(0x101018); hemi.groundColor.set(0x000000);")
text = text.replace("scene.background = new THREE.Color(0xcfdcec)", "scene.background = new THREE.Color(0x000000)")
assert "0.05" in text and "0x000000" in text
env.write_text(text)
diff --git a/harness/tests/scene_runtime/test_backdrop.py b/harness/tests/scene_runtime/test_backdrop.py
index 5a02202d..853724b6 100644
--- a/harness/tests/scene_runtime/test_backdrop.py
+++ b/harness/tests/scene_runtime/test_backdrop.py
@@ -49,6 +49,18 @@ def test_classifier_rule_table():
assert got == [c[4] for c in CASES], list(zip([c[0] for c in CASES], got, strict=True))
+def test_a_small_thing_kilometres_away_is_sky_whatever_its_name():
+ """`sunRig` parks its 'SunDisc' (no word boundary for SKY_NAME_RE) at 3 600 m: content by
+ name, and it blew the content bbox to 2.5 km — the overview rig then framed the sun."""
+ body = f"""
+import {{ classifyBackdrop }} from '{RUNTIME_JS}/lib/backdrop.mjs';
+const disc = classifyBackdrop({{ name: 'SunDisc' }}, {{ min: {{ x: 2100, y: 2600, z: 1800 }}, max: {{ x: 2148, y: 2648, z: 1848 }} }}, 40);
+const near = classifyBackdrop({{ name: 'SunDisc' }}, {{ min: {{ x: 10, y: 20, z: 10 }}, max: {{ x: 58, y: 68, z: 58 }} }}, 40);
+console.log(JSON.stringify([disc, near]));
+"""
+ assert run_node_json(body) == ["sky", "content"]
+
+
def test_the_rules_live_in_exactly_one_file():
hits = []
for p in sorted((RUNTIME_JS / "lib").rglob("*.mjs")) + sorted((RUNTIME_JS / "lib").rglob("*.js")):