Official Codebase of 3DCodeVerse
Python
scene starter: the outdoor world ships from the library — terrain ground, world shell, outskirts (D71); terrain.ground() lattice wrap fixed
gaoypeng41826710ae68
diff --git a/harness/codeverse/languages/scene_threejs/__init__.py b/harness/codeverse/languages/scene_threejs/__init__.pyindex 7e6f4cc5..2a3217ee 100644--- a/harness/codeverse/languages/scene_threejs/__init__.py+++ b/harness/codeverse/languages/scene_threejs/__init__.py@@ -210,10 +210,9 @@ def _env_for_plan(plan: ScenePlan) -> str:ex = plan.bounds.extentsspan = max(ex[0], ex[2], 40.0)ground = int(max(120, span * 2.5))- fog_near, fog_far = int(span * 0.8), int(max(span * 3.0, 200))text = re.sub(r"export const GROUND_SIZE = \d+;", f"export const GROUND_SIZE = {ground};", text)- text = re.sub(r"const FOG_NEAR = \d+, FOG_FAR = \d+;", f"const FOG_NEAR = {fog_near}, FOG_FAR = {fog_far};", text)- text = re.sub(r"const SKY_RADIUS = \d+;", f"const SKY_RADIUS = {int(max(600, ground * 3))};", text)+ # level ground inside the plan's radius (its cameras were written for y ≈ 0), rolling beyond+ text = re.sub(r"export const CONTENT_RADIUS = \d+;", f"export const CONTENT_RADIUS = {int(max(20, span / 2))};", text)if plan.interior:c = [round(float(v), 2) for v in plan.bounds.center]e = [round(float(v), 2) for v in ex]diff --git a/harness/codeverse/languages/scene_threejs/starter/src/env.js b/harness/codeverse/languages/scene_threejs/starter/src/env.jsindex f1d3f507..0a2925a1 100644--- a/harness/codeverse/languages/scene_threejs/starter/src/env.js+++ b/harness/codeverse/languages/scene_threejs/starter/src/env.js@@ -1,32 +1,43 @@// src/env.js — environment owned by the scene: ground, sky, sun, fog, heightAt.// export function buildEnv(ctx) → { ground, sky, sun, hemi, update(t, dt) }// export function heightAt(x, z) → ground height (m) so zones can seat objects.+//+// The outdoor world ships from the harness-owned library (D71, 2026-09-08): a textured,+// displaced ground that is LEVEL inside the content radius and rolls beyond it, the sky+// gradient + horizon ridge + matched fog of `worldShell`, the relief / fields / copses of+// `makeOutskirts` between the content and that ridge, and the sun rig with its baked+// environment. Measured over the day's exteriors: with a flat one-colour plane and a bare+// dome as the default, every env session that under-delivered (or died) shipped "flat+// untextured ground", "no aerial perspective", "hard world edge" — the three most frequent+// defects of the tally. TUNE these (palette, mood, relief, flat areas, the path); do not+// replace them with a plane.import * as THREE from 'three';-import { makeSkyMaterial } from './shaders/sky.js';-import { roomShell, sunRig } from './lib/environment.js';+import { makeOutskirts, roomShell, sunRig, worldShell } from './lib/environment.js';+import { mulberry32 } from './lib/noise.js';+import { ground } from './lib/terrain.js';export const SUN_AZIMUTH_DEG = 60; // where the sun is (0 = +Z front, CCW from above); cameras on the sun side are front-litexport const SUN_ELEVATION_DEG = 38;-export const GROUND_SIZE = 160; // ground plane extent (m); fog is tuned to it+export const MOOD = 'day'; // day | golden | night | overcast — the rig, the shell and the fog agree on it+export const GROUND_SIZE = 160; // ground plane extent (m); the outskirts start at its edge+export const CONTENT_RADIUS = 45; // the plan bounds' radius (m): level ground inside, rolling beyond; the shadow frustum// An INTERIOR plan (the skeleton fills this from plan.bounds): the room shell — floor is the// ground, walls and ceiling on the bounds' faces. Cut the plan's windows and doors as// `openings` (see lib/environment.js roomShell) and light the inside; never delete it.export const INTERIOR = null; // e.g. { center: [0, 3, 0], extents: [14, 6, 16], openings: [{ face: 'west', center: [8, 2.5], size: [6, 3] }] }-const FOG_NEAR = 60, FOG_FAR = 260;-const SKY_RADIUS = 600;+const SEED = 7;-/** Gentle rolling meadow; deterministic, cheap (called per placed object). */-export function heightAt(x, z) {- return 0.35 * Math.sin(x * 0.13) * Math.cos(z * 0.11) + 0.18 * Math.sin((x + z) * 0.27);-}+// The ground and its height function are ONE thing (terrain.js): built at module load with a+// seeded PRNG, so `heightAt` is exactly the field the mesh was displaced with. Level inside+// CONTENT_RADIUS (the plan's cameras were written for y ≈ 0), rolling out to the outskirts.+const GROUND = ground({+ size: GROUND_SIZE, segments: 128, rand: mulberry32(SEED), relief: 3, scale: 60,+ flat: (x, z) => 1 - Math.min(1, Math.max(0, (Math.hypot(x, z) - CONTENT_RADIUS) / CONTENT_RADIUS)),+});-function groundGeometry(size, segs) {- const g = new THREE.PlaneGeometry(size, size, segs, segs);- g.rotateX(-Math.PI / 2); // PlaneGeometry lies in XY → rotate to XZ- const pos = g.attributes.position;- for (let i = 0; i < pos.count; i++) pos.setY(i, heightAt(pos.getX(i), pos.getZ(i)));- g.computeVertexNormals();- return g;+/** Ground height at (x, z) — every placement seats on this. */+export function heightAt(x, z) {+ return GROUND.height(x, z);}export function buildEnv(ctx) {@@ -34,43 +45,34 @@ export function buildEnv(ctx) {const group = new THREE.Group();group.name = 'Environment';- // --- ground (receives shadows; vertex colour variation = cheap "grass")- const ground = new THREE.Mesh(- groundGeometry(GROUND_SIZE, 96),- new THREE.MeshStandardMaterial({ color: 0x5f8a3c, roughness: 0.95, metalness: 0.0 }),- );- ground.name = 'Ground';- ground.receiveShadow = true;+ // --- ground (textured, receives shadows) and, for an interior, the enclosure on the bounds+ const ground = GROUND.mesh;group.add(ground);if (INTERIOR) group.add(roomShell(INTERIOR)); // the enclosure exists before anyone dresses the room- const az = (SUN_AZIMUTH_DEG * Math.PI) / 180, el = (SUN_ELEVATION_DEG * Math.PI) / 180;-- // --- sky: big inverted sphere with a gradient ShaderMaterial (custom GLSL, no lighting needed)- const skyMat = makeSkyMaterial(THREE);- skyMat.uniforms.uSunDir.value.set(Math.sin(az) * Math.cos(el), Math.sin(el), Math.cos(az) * Math.cos(el));- const sky = new THREE.Mesh(new THREE.SphereGeometry(SKY_RADIUS, 32, 16), skyMat);- sky.name = 'Sky';- sky.frustumCulled = false;- group.add(sky);+ // --- the world beyond: sky gradient + horizon ridge + fog the colour of the horizon, and the+ // land between the content and that ridge (relief, field patchwork, distant copses)+ const shell = worldShell({ rand: mulberry32(SEED + 1), mood: MOOD, bounds: CONTENT_RADIUS });+ group.add(shell.group);+ if (!INTERIOR) group.add(makeOutskirts({ inner: GROUND_SIZE / 2, shellRadius: shell.radius, heightAt, seed: SEED }));// --- 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 rig = sunRig({ mood: MOOD, azimuth: SUN_AZIMUTH_DEG, elevation: SUN_ELEVATION_DEG, bounds: CONTENT_RADIUS });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);- scene.background = new THREE.Color(0xcfdcec);+ // --- fog + background: the shell's, matched to its horizon colour+ scene.fog = shell.fog;+ scene.background = new THREE.Color(shell.fog.color);scene.add(group);- const update = (t) => { skyMat.uniforms.uTime.value = t; };+ const update = () => {};const sunDir = sun.position.clone().normalize();- return { ground, sky, sun, sunDir, hemi, group, update };+ return { ground, sky: shell.group, sun, sunDir, hemi, group, update };}diff --git a/harness/codeverse/languages/scene_threejs/starter/src/lib/terrain.js b/harness/codeverse/languages/scene_threejs/starter/src/lib/terrain.jsindex 213b46d5..d4ee569d 100644--- a/harness/codeverse/languages/scene_threejs/starter/src/lib/terrain.js+++ b/harness/codeverse/languages/scene_threejs/starter/src/lib/terrain.js@@ -35,8 +35,11 @@ export function ground(opts = {}) {const lat = new Float32Array(N * N);for (let i = 0; i < N * N; i++) lat[i] = rand();const sample = (x, z) => {- const u = (x / scale) % N, v = (z / scale) % N;- const uu = u < 0 ? u + N : u, vv = v < 0 ? v + N : v;+ // wrap into [0, N): `u + N` for a u of -1e-16 rounds to N itself (below one ulp of 32),+ // and lat[j * N + N] is the next row or undefined — measured 2026-09-08, 15 NaN vertices+ // in an outskirts ring where the polar grid's x came out as -1.5e-14 (D71)+ const wrap = (t) => { let w = t % N; if (w < 0) w += N; return w >= N ? w - N : w; };+ const uu = wrap(x / scale), vv = wrap(z / scale);const i0 = Math.floor(uu), j0 = Math.floor(vv);const fx = uu - i0, fz = vv - j0;const i1 = (i0 + 1) % N, j1 = (j0 + 1) % N;diff --git a/harness/codeverse/prompts/tracks/scene_env.j2 b/harness/codeverse/prompts/tracks/scene_env.j2index 14fb0560..327bb389 100644--- a/harness/codeverse/prompts/tracks/scene_env.j2+++ b/harness/codeverse/prompts/tracks/scene_env.j2@@ -45,14 +45,18 @@ So `src/env.js` must export exactly:The chapters behind these rules are printed in full at the end of this brief(**Recipes**) — copy their numbers and snippets; do not invent your own.-1. **Ground must not be one flat colour.** One displaced plane, ~1 segment per metre, vertex- colours blending 3-4 palette colours by height, slope and noise, plus the path carved by- `distToPath` in both height and colour. A single-colour `MeshStandardMaterial` plane is a- scored defect (`flat_ground`).-2. **No world edge.** Ground size >= 2.4 x fog far; `scene.fog` colour == the sky's HORIZON- colour == `scene.background`; a silhouette ring (24-40 instanced hills / rooftops / mesas /- treeline) at radius ~ 0.6 x fog far, height 0.06-0.12 x that radius. Scale fog to THIS- scene, not to a 100 m default.+1. **Ground must not be one flat colour.** The skeleton already ships the library's ground+ (`ground()` from `lib/terrain.js`: textured, displaced, level inside `CONTENT_RADIUS` and+ rolling beyond, and `heightAt` IS its height function): tune its material, relief, scale and+ `flat` areas and carve the path in both height and colour — never replace it with a+ single-colour `MeshStandardMaterial` plane, a scored defect (`flat_ground`).+2. **No world edge.** The skeleton already closes the world: `worldShell()` (sky gradient, the+ horizon's silhouette ring, fog the colour of the horizon — `scene.fog` and `scene.background` are its)+ and `makeOutskirts()` (relief, fields and copses between the content and the ridge). Set+ `MOOD`, the shell's `zenith` / `horizon` and the outskirts' `colors` to the brief; replace+ the ridge only with something of the brief's own (rooftops, mesas, a treeline) and keep+ fog == horizon == background, the land reaching past fog far. Scale fog to THIS scene, not+ to a 100 m default.Two rules decide whether that ring reads as a hazy horizon or as cardboard:- Build it from SOLID geometry (cones, boxes, mesas). Flat `PlaneGeometry` cut-outs areinstantly readable as cardboard from every oblique and overview camera.diff --git a/harness/docs/DECISIONS.md b/harness/docs/DECISIONS.mdindex ac3940d1..6d816926 100644--- a/harness/docs/DECISIONS.md+++ b/harness/docs/DECISIONS.md@@ -1147,6 +1147,26 @@ written) that were accepted because the code works that way and the tests pin itconstants as the control. The bare one-file scene is no longer ahead on interiors; theharness keeps its heroes, gates, library and rounds on top of that.+* **D71 The starter's outdoor world ships from the library (2026-09-08).** The starter's+ `env.js` was a one-colour plane under a bare shader dome with linear fog: whatever the env+ session did not build, the scene did not have. Over the day's exterior runs the three most+ frequent defects of the tally — "flat untextured ground", "no aerial perspective / hard+ world edge", pyramid or cone backdrops — were exactly what that default leaves, and the+ loop-19 exteriors under D70 (observatory 0.53, temple 0.60, windmill 0.34 at round 0) were+ judged on them while their zones were fine. The starter now builds its ground from+ `terrain.ground()` (textured, displaced; LEVEL inside `CONTENT_RADIUS` — the plan's cameras+ were written for y ≈ 0 — and rolling beyond; `heightAt` IS that function, built once at+ module load with a seeded PRNG so the mesh and the seat cannot drift), its sky, horizon+ ridge and fog from `worldShell()`, the middle distance from `makeOutskirts()`, the light+ from `sunRig()` (D65) and, for an interior, the enclosure from `roomShell()` (D69); `MOOD`+ keeps the rig, the shell and the fog agreeing. The skeleton fills `CONTENT_RADIUS` from the+ plan bounds; the env brief's first two rules now say tune, never replace. Found on the+ way: `terrain.ground()` wrapped a coordinate of −1.5e-14 to exactly N and read past the+ lattice row — 15 NaN vertices in the outskirts ring and a NaN bounding box in the render+ console; fixed at the source. Measured next as loop 20 (the four exterior briefs of loop 19+ on this starter). Harness-owned starter geometry the agent edits, as `worldShell` and+ `roomShell` are; nothing here re-centres or grounds an authored object (L7).+## Rejected / deferred* A versioned `Spec`/`RunRecord`/`RunState` load-normaliser (rejected 2026-08-30: of the sevendiff --git a/harness/tests/scene_gates/test_live_frames.py b/harness/tests/scene_gates/test_live_frames.pyindex 906cfec2..16aee0d8 100644--- a/harness/tests/scene_gates/test_live_frames.py+++ b/harness/tests/scene_gates/test_live_frames.py@@ -34,8 +34,11 @@ def _darken(ws: Workspace) -> None:# the env map, which lights metals and glass on its owntext = 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+ # the world shell's sky is unlit (D71): black it out too, or half the frame stays bright sky+ text = text.replace("worldShell({ rand: mulberry32(SEED + 1), mood: MOOD,",+ "worldShell({ rand: mulberry32(SEED + 1), mood: 'night', zenith: 0x000000, horizon: 0x000000, ridgeColor: 0x000000,")+ text = text.replace("scene.background = new THREE.Color(shell.fog.color)", "scene.background = new THREE.Color(0x000000)")+ assert "0.05" in text and text.count("0x000000") >= 4env.write_text(text)sky = ws.src / "shaders" / "sky.js"if sky.is_file():diff --git a/harness/tests/scene_runtime/lib/test_exterior_starter.py b/harness/tests/scene_runtime/lib/test_exterior_starter.pynew file mode 100644index 00000000..209e560a--- /dev/null+++ b/harness/tests/scene_runtime/lib/test_exterior_starter.py@@ -0,0 +1,76 @@+"""The starter's outdoor world ships from the library (D71, 2026-09-08).++Measured over the day's exterior runs: with a flat one-colour plane and a bare dome as the+default, every env session that under-delivered (or died in the 503 storm) shipped "flat+untextured ground", "no aerial perspective", "hard world edge" — the three most frequent+defects of the tally over 43 judged rounds. The starter now builds its ground from+`terrain.ground()` (level inside CONTENT_RADIUS, rolling beyond), its sky / ridge / fog+from `worldShell()` and the middle distance from `makeOutskirts()`.+"""+from __future__ import annotations++from pathlib import Path++from _probe import measure++from codeverse.contracts.common import Track+from codeverse.contracts.plan import ScenePlan+from codeverse.languages.scene_threejs import STARTER_DIR, _env_for_plan+from codeverse.tracks.planner import plan_example++_LIBS = ("environment.js", "terrain.js", "noise.js", "materials.js", "sky.js", "shader.js")+++def _probe_script() -> str:+ env = (STARTER_DIR / "env.js").read_text()+ body = env.replace("import * as THREE from 'three';", "").replace("export function", "function").replace("export const", "const")+ return f"""+import * as THREE from 'three';+{body}+const scene = new THREE.Scene();+const out = buildEnv({{ scene, THREE }});+const names = [];+scene.traverse((o) => {{ if (o.name) names.push(o.name); }});+const h = (x, z) => heightAt(x, z);+console.log(JSON.stringify({{+ names: names.filter((n) => ['Environment', 'Ground', 'WorldShell', 'SkyGradient', 'HorizonRidge', 'Outskirts', 'SunRigSun', 'SunRigFill'].includes(n)),+ fogExp2: scene.fog && scene.fog.isFogExp2 === true,+ bgIsFog: scene.background.getHex() === scene.fog.color.getHex(),+ insideMax: Math.max(...[[0, 0], [20, 10], [-30, 25], [40, -15]].map(([x, z]) => Math.abs(h(x, z)))),+ outsideSpread: Math.max(...[[70, 0], [0, -75], [60, 60]].map(([x, z]) => h(x, z))) - Math.min(...[[70, 0], [0, -75], [60, 60]].map(([x, z]) => h(x, z))),+ groundTextured: !!(out.ground.material.map),+ envMap: !!scene.environment,+}}));+"""+++def test_the_starter_world_is_the_librarys_ground_shell_and_outskirts():+ got = measure(_probe_script(), _LIBS)+ for n in ("Ground", "WorldShell", "SkyGradient", "HorizonRidge", "Outskirts", "SunRigSun", "SunRigFill"):+ assert n in got["names"], (n, got["names"])+ assert got["fogExp2"] and got["bgIsFog"] and got["groundTextured"] and got["envMap"], got+ assert got["insideMax"] < 0.05, got # level where the plan's cameras were written for y ≈ 0+ assert got["outsideSpread"] > 0.5, got # and rolling beyond the content radius+++def test_the_skeleton_fills_the_content_radius_from_the_plan_bounds():+ plan = ScenePlan.model_validate(plan_example(Track.SCENE))+ env = _env_for_plan(plan)+ span = max(plan.bounds.extents[0], plan.bounds.extents[2], 40.0)+ assert f"export const CONTENT_RADIUS = {int(max(20, span / 2))};" in env+ assert "FOG_NEAR" not in env and "SKY_RADIUS" not in env+ assert Path(STARTER_DIR / "env.js").read_text().count("export const CONTENT_RADIUS = 45;") == 1+++def test_the_ground_height_is_finite_for_a_signed_zero_column():+ """terrain.ground(): a coordinate of -1.5e-14 wrapped to exactly N and read past the lattice+ row — 15 NaN vertices in the outskirts ring, a NaN bounding box in the render console."""+ got = measure("""+import * as THREE from 'three';+import { mulberry32 } from './lib/noise.js';+import { ground } from './lib/terrain.js';+const G = ground({ size: 160, segments: 16, rand: mulberry32(7), relief: 3, scale: 60 });+console.log(JSON.stringify({ tiny: G.height(-1.5e-14, -80), zero: G.height(0, -80), far: G.height(-1.5e-14, -84.73), neg: G.height(-160.00000001, 12) }));+""", ("terrain.js", "noise.js", "materials.js", "shader.js"))+ assert all(isinstance(v, (int, float)) and v == v for v in got.values()), got+ assert abs(got["tiny"] - got["zero"]) < 1e-6diff --git a/harness/tests/scene_runtime/test_runtime.py b/harness/tests/scene_runtime/test_runtime.pyindex da2a9462..52362fc9 100644--- a/harness/tests/scene_runtime/test_runtime.py+++ b/harness/tests/scene_runtime/test_runtime.py@@ -42,12 +42,15 @@ def test_build_ok_on_example(starter_ws):@pytest.mark.node@needs_browserdef test_build_fails_with_file_line_on_shader_error(starter_ws):- p = starter_ws.src / "shaders" / "sky.js"- text = p.read_text().replace("float h = clamp(vWorldDir.y, -0.2, 1.0);", "float h = clamp(vWorldDir.y, -0.2, 1.0) + nope;")+ # the pond's water shader: a file the example scene compiles (the starter's sky comes+ # from lib/environment.js worldShell since D71, so shaders/sky.js is no longer loaded)+ p = starter_ws.src / "shaders" / "water.js"+ text = p.read_text().replace("float fres = pow(1.0 - max(dot(N, V), 0.0), 3.0);", "float fres = pow(1.0 - max(dot(N, V), 0.0), 3.0) + nope;")+ assert "nope" in textp.write_text(text)res = SceneThreeJsRuntime().build(starter_ws)assert not res.ok- assert res.error_file == "src/shaders/sky.js" and res.error_line+ assert res.error_file == "src/shaders/water.js" and res.error_lineassert "nope" in res.error_messageassert "shader_preflight: FAILED" in res.stdout_tail