Skip to content

Official Codebase of 3DCodeVerse

Python

scene assembler: a placed GLB clone's clips play by themselves; clipPlayer deleted

gaoypeng5230e3062e00
diff --git a/harness/codeverse/languages/scene_threejs/__init__.py b/harness/codeverse/languages/scene_threejs/__init__.py
index 3d4b8579..ec7c6835 100644
--- a/harness/codeverse/languages/scene_threejs/__init__.py
+++ b/harness/codeverse/languages/scene_threejs/__init__.py
@@ -594,6 +594,18 @@ export async function createScene({{ renderer, loaders }}) {{
}};
{calls}
+ // a placed GLB clone that carries clips (a keyframed Blender part; `.clone()` copies them)
+ // plays them here, driven by ABSOLUTE time so t=0 / t=1.5 are deterministic frames; a zone
+ // de-phases copies with `clone.userData.clipOffset` (seconds). Measured 2026-09-07: told
+ // how to play a clip itself, the windmill zone placed the clone and played nothing.
+ const players = [];
+ scene.traverse((o) => {{
+ if (!o.animations || !o.animations.length) return;
+ const mixer = new THREE.AnimationMixer(o);
+ for (const clip of o.animations) mixer.clipAction(clip).play();
+ players.push([mixer, +(o.userData.clipOffset || 0)]);
+ }});
+
const cameras = [
{cams}
];
@@ -601,6 +613,7 @@ export async function createScene({{ renderer, loaders }}) {{
function update(t, dt) {{
if (env.update) env.update(t, dt);
for (const z of zones) if (z.userData.update) z.userData.update(t, dt);
+ for (const [mixer, offset] of players) mixer.setTime(t + offset);
}}
return {{ scene, cameras, update }};
}}
diff --git a/harness/codeverse/languages/scene_threejs/starter/src/lib/place.js b/harness/codeverse/languages/scene_threejs/starter/src/lib/place.js
index ae9b9864..8769ded2 100644
--- a/harness/codeverse/languages/scene_threejs/starter/src/lib/place.js
+++ b/harness/codeverse/languages/scene_threejs/starter/src/lib/place.js
@@ -16,23 +16,6 @@ const _v = new THREE.Vector3();
const _t = new THREE.Vector3();
const DEG = Math.PI / 180;
-/**
- * Play the clips a Blender hero carries (`obj.animations`, exported from its
- * keyframes and kept by `.clone()`). Returns `tick(t)` for the zone's `update(t)`,
- * or null when the object has no clip. The mixer is set to ABSOLUTE time, so the
- * same t always gives the same pose (the harness samples t = 0 and 1.5 s).
- * const cart = ctx.assets.donkey_cart.clone(); const tick = clipPlayer(cart, { offset: 0.7 });
- * zone.userData.update = (t) => { if (tick) tick(t); };
- */
-export function clipPlayer(obj, opts = {}) {
- const clips = obj.animations || [];
- if (!clips.length) return null;
- const mixer = new THREE.AnimationMixer(obj);
- for (const c of clips) mixer.clipAction(c).play();
- const speed = opts.speed ?? 1, offset = opts.offset ?? 0;
- return (t) => { mixer.setTime((t + offset) * speed); };
-}
-
/** Unit vector for a `forward` string as reported by assets_api.json. */
function fwdVec(forward) {
switch (forward) {
diff --git a/harness/codeverse/prompts/scene_threejs/effects_catalog.md b/harness/codeverse/prompts/scene_threejs/effects_catalog.md
index 930e8fa8..610070a2 100644
--- a/harness/codeverse/prompts/scene_threejs/effects_catalog.md
+++ b/harness/codeverse/prompts/scene_threejs/effects_catalog.md
@@ -39,7 +39,7 @@ says `import { makeGrass } from '../lib/grass.js';`, `src/scene.js` says
| placing a camera or a prop by intent | `seat` · `establishingShot` · `faceToward` · `alongPath` · `crowdOn` — `lib/place.js` |
| a cliff that reads as rock | `patchRockStrata` · `patchErosionStreaks` — `lib/strata.js`; bedding by world altitude, so every cliff in a scene shares one bedding plane |
| the land between the content and the horizon | `makeOutskirts({ inner, baseY, heightAt, shellRadius, colors, seed })` — `lib/environment.js`; seam-matched relief, field patchwork and wooded clusters. A bare oversized ground plane measured as "a diorama on a vast, empty flat plane" |
-| a Blender hero's own keyframed motion (the GLB carries a clip) | `clipPlayer(clone, { offset })` — `lib/place.js`; returns `tick(t)`, call it from the zone's `update(t)` |
+| a Blender hero's own keyframed motion (the GLB carries a clip) | nothing to call — the assembled scene plays every clone's clips; `clone.userData.clipOffset = 0.7` de-phases a copy |
| the sun, the fill and the baked environment | `sunRig({ azimuth, elevation })` — `lib/environment.js`; returns `{ sun, fill, sunDisc, envTex, sunDir }`. Add the lights, assign `scene.environment = rig.envTex` |
| the sky itself | `makeSky(scene, { rig })` — `lib/sky.js`; the dome IS the backdrop, so `scene.background` stays null |
| cloud, cirrus | `makeClouds({ preset, sunDir })` · `makeCirrus()` — `lib/clouds.js` |
diff --git a/harness/codeverse/prompts/tracks/scene_zone.j2 b/harness/codeverse/prompts/tracks/scene_zone.j2
index 01b7fddb..cde35577 100644
--- a/harness/codeverse/prompts/tracks/scene_zone.j2
+++ b/harness/codeverse/prompts/tracks/scene_zone.j2
@@ -25,8 +25,8 @@ Those paths are written relative to `src/`; **from `src/zones/` prefix them with
(`import { buildStoneLantern } from '../assets/stone_lantern.js';`). Shared materials and the
terrain come from the environment: `import { MATS, heightAt } from '../env.js';` (or use
`ctx.heightAt`). A GLB asset is already loaded for you at `ctx.assets['<snake_name>']` — add
-`.clone()` of it, never `loaders.gltf` again. A clone that carries clips (`clone.animations.length`) is
-played with `clipPlayer(clone)` from '../lib/place.js': call the returned `tick(t)` from this zone's `update(t)`. There is no `ctx.rand` and no `ctx.MATS`.
+`.clone()` of it, never `loaders.gltf` again. A clone that carries clips (a keyframed Blender part) plays
+them by itself; set `clone.userData.clipOffset = <seconds>` to de-phase copies. There is no `ctx.rand` and no `ctx.MATS`.
## Contract
{{ frame_doc }}
diff --git a/harness/codeverse/tracks/scene_assets.py b/harness/codeverse/tracks/scene_assets.py
index 16dd566e..de87a838 100644
--- a/harness/codeverse/tracks/scene_assets.py
+++ b/harness/codeverse/tracks/scene_assets.py
@@ -128,7 +128,7 @@ def asset_api_summary(plan: ScenePlan, results: dict[str, AssetResult], alias: d
elif a.kind == "threejs":
lines.append(f"- {a.name}: `import {{ build{to_pascal(a.name)} }} from './assets/{to_snake(a.name)}.js'` → Group, base at y=0, {s}{status}")
else:
- motion = f", carries {r.clips} motion clip(s): `clipPlayer(clone)` from '../lib/place.js' in the zone's update" if r and r.clips else ""
+ motion = f", carries {r.clips} motion clip(s) (played automatically; `clone.userData.clipOffset` de-phases copies)" if r and r.clips else ""
lines.append(f"- {a.name}: preloaded at `ctx.assets['{to_snake(a.name)}']` (clone it; GLB public/assets/{to_snake(a.name)}.glb), "
f"base at y=0, {s}{motion}{status}")
return "\n".join(lines) or "(no assets)"
diff --git a/harness/tests/scene_runtime/lib/test_place_clips.py b/harness/tests/scene_runtime/lib/test_place_clips.py
deleted file mode 100644
index ece96e41..00000000
--- a/harness/tests/scene_runtime/lib/test_place_clips.py
+++ /dev/null
@@ -1,39 +0,0 @@
-"""place.js clipPlayer — a Blender hero's keyframed motion reaches the scene (2026-09-07).
-
-The Blender wrapper exports keyframes as a glTF clip, the preload keeps it on the root
-(`root.animations`), `.clone()` copies it, and `clipPlayer` drives a mixer by ABSOLUTE time
-so the harness's t = 0 / 1.5 s frames are deterministic. Proven here without Blender: a
-synthetic clip (a 2 s rotation loop) on a cloned group.
-"""
-from __future__ import annotations
-
-import pytest
-from _probe import measure
-
-pytestmark = pytest.mark.node
-
-PROBE = r"""
-import * as THREE from 'three';
-import { clipPlayer } from './lib/place.js';
-const root = new THREE.Group(); root.name = 'Lantern';
-const lamp = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.3, 0.3), new THREE.MeshStandardMaterial()); lamp.name = 'Lamp';
-root.add(lamp);
-const track = new THREE.NumberKeyframeTrack('Lamp.rotation[x]', [0, 1, 2], [-0.35, 0.35, -0.35]);
-root.animations = [new THREE.AnimationClip('Swing', 2, [track])];
-const clone = root.clone();
-const tick = clipPlayer(clone, { offset: 0 });
-const lampC = clone.getObjectByName('Lamp');
-const at = (t) => { tick(t); return +lampC.rotation.x.toFixed(3); };
-const a0 = at(0), a1 = at(1.0), a15 = at(1.5), again0 = at(0), a4 = at(4.0);
-const none = clipPlayer(new THREE.Group());
-console.log(JSON.stringify({ kept: clone.animations.length, a0, a1, a15, again0, a4, none: none === null }));
-"""
-
-
-def test_a_clone_keeps_the_clip_and_the_player_is_deterministic_in_t():
- m = measure(PROBE, libs=("place.js",))
- assert m["kept"] == 1 and m["none"] is True, m
- assert m["a0"] == pytest.approx(-0.35, abs=0.02) and m["a1"] == pytest.approx(0.35, abs=0.02), m
- assert abs(m["a15"] - m["a0"]) > 0.15, "the harness's second sample (1.5 s) must differ from t=0"
- assert m["again0"] == m["a0"], "absolute time: the same t gives the same pose"
- assert m["a4"] == pytest.approx(m["a0"], abs=0.02), "a 2 s clip loops"
diff --git a/harness/tests/scene_runtime/test_glb_asset_naming.py b/harness/tests/scene_runtime/test_glb_asset_naming.py
index a06966f9..c17eb792 100644
--- a/harness/tests/scene_runtime/test_glb_asset_naming.py
+++ b/harness/tests/scene_runtime/test_glb_asset_naming.py
@@ -45,11 +45,22 @@ export function build(ctx) {
DRIVER_JS = """
import * as THREE from 'three';
import { createScene } from './src/scene.js';
-const loaders = { gltf: { loadAsync: async () => ({ scene: new THREE.Group() }) } };
-const { scene } = await createScene({ renderer: null, loaders });
+const loaders = { gltf: { loadAsync: async () => {
+ // a Blender export whose one keyframed part became a clip: a 2 s swing on 'Lid'
+ const root = new THREE.Group(); const lid = new THREE.Group(); lid.name = 'Lid'; root.add(lid);
+ const track = new THREE.NumberKeyframeTrack('Lid.rotation[x]', [0, 1, 2], [-0.35, 0.35, -0.35]);
+ return { scene: root, animations: [new THREE.AnimationClip('Swing', 2, [track])] };
+} } };
+const { scene, update } = await createScene({ renderer: null, loaders });
+const lids = []; scene.traverse((o) => { if (o.name === 'Lid') lids.push(o); });
+update(0, 0); const at0 = lids.map((l) => +l.rotation.x.toFixed(3));
+update(1.0, 0.016); const at1 = lids.map((l) => +l.rotation.x.toFixed(3));
+update(0, 0); const again0 = lids.map((l) => +l.rotation.x.toFixed(3));
console.log(JSON.stringify({
zoneSees: scene.children.map((c) => c.userData.sofaName),
cloneNames: scene.children.flatMap((c) => c.children.map((k) => k.name)),
+ clipsOnClone: scene.children.flatMap((c) => c.children.map((k) => (k.animations || []).length)),
+ at0, at1, again0,
}));
"""
@@ -72,6 +83,14 @@ def test_the_zone_sees_the_asset_under_its_planned_name(loaded):
assert loaded["zoneSees"] == ["LoungeSofa"], "a glTF root is called 'Scene' until someone names it"
+def test_the_clone_plays_its_blender_clip_by_absolute_time(loaded):
+ """A keyframed Blender part arrives as a clip on the preloaded root, `.clone()` keeps it,
+ and the assembled scene plays it from `update(t)` with no zone code — the same t gives
+ the same pose (the harness samples t = 0 and 1.5 s)."""
+ assert loaded["clipsOnClone"] == [1]
+ assert loaded["at0"] == [-0.35] and loaded["at1"] == [0.35] and loaded["again0"] == loaded["at0"]
+
+
def test_the_clone_the_zone_places_carries_the_name_too(loaded):
"""`.clone()` copies the name, so the object actually standing in the zone — the
one `scene_placement` matches against the plan — carries it as well."""