chore: deploy private lightloom build
Browse files- app.py +122 -1
- frontend/js/stage-corridor.js +237 -0
- scripts/shoot-corridor.cjs +57 -0
app.py
CHANGED
|
@@ -144,7 +144,7 @@ def health() -> dict[str, Any]:
|
|
| 144 |
"privacy_mode": os.getenv("LIGHTLOOM_PRIVACY_MODE", "1") == "1",
|
| 145 |
"cpu_count": os.cpu_count(),
|
| 146 |
"director_backend": CONFIG.director_backend,
|
| 147 |
-
"build": "
|
| 148 |
}
|
| 149 |
|
| 150 |
|
|
@@ -408,6 +408,127 @@ def pano_world_frame(session: str, name: str):
|
|
| 408 |
return FileResponse(path)
|
| 409 |
|
| 410 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
@app.post("/internal/bench/director-probe")
|
| 412 |
def director_probe_endpoint(backend: str = "transformers", threads: int = 8) -> dict[str, Any]:
|
| 413 |
if os.getenv("LIGHTLOOM_ENABLE_INTERNAL_BENCH", "0") != "1":
|
|
|
|
| 144 |
"privacy_mode": os.getenv("LIGHTLOOM_PRIVACY_MODE", "1") == "1",
|
| 145 |
"cpu_count": os.cpu_count(),
|
| 146 |
"director_backend": CONFIG.director_backend,
|
| 147 |
+
"build": "corridor-1",
|
| 148 |
}
|
| 149 |
|
| 150 |
|
|
|
|
| 408 |
return FileResponse(path)
|
| 409 |
|
| 410 |
|
| 411 |
+
# --- THE INFINITE 3D CORRIDOR (the live experience). Each phrase the narrator
|
| 412 |
+
# speaks becomes a vivid, forward-facing scene: the Director (MiniCPM) turns the
|
| 413 |
+
# phrase into a shot, a content-driven style is chosen per scene, the fast 4-step
|
| 414 |
+
# klein painter renders it, Depth-Anything gives it relief, and each scene streams
|
| 415 |
+
# into the browser's corridor where the camera flies forward through the growing
|
| 416 |
+
# world. "speak, and your world unrolls ahead of you." ---
|
| 417 |
+
_CORRIDOR_QUALITY = (
|
| 418 |
+
"highly detailed, rich vivid saturated color, breathtaking, masterpiece, sharp focus, "
|
| 419 |
+
"wide establishing view, volumetric light"
|
| 420 |
+
)
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
def _corridor_style(shot: Any) -> str:
|
| 424 |
+
"""Pick a per-scene art style from the Director's content/lighting so each scene
|
| 425 |
+
has its own colorful look (the Director decides via what it described)."""
|
| 426 |
+
text = f"{getattr(shot, 'lighting', '')} {getattr(shot, 'image_prompt_en', '')}".lower()
|
| 427 |
+
|
| 428 |
+
def has(*ks: str) -> bool:
|
| 429 |
+
return any(k in text for k in ks)
|
| 430 |
+
|
| 431 |
+
if has("storm", "dusk", "night", "dark", "rain", "thunder"):
|
| 432 |
+
return "dramatic moody cinematic concept art, deep shadows, glowing accents"
|
| 433 |
+
if has("morning", "dawn", "sunrise", "golden", "warm", "sunset"):
|
| 434 |
+
return "warm golden-hour illustration, glowing vibrant color"
|
| 435 |
+
if has("snow", "ice", "winter", "cold", "frost"):
|
| 436 |
+
return "crisp luminous winter concept art, cool blue-and-white palette"
|
| 437 |
+
if has("market", "city", "street", "village", "town", "harbor"):
|
| 438 |
+
return "vibrant colorful illustration, bustling saturated detail"
|
| 439 |
+
if has("forest", "garden", "meadow", "jungle", "flower", "tree", "green"):
|
| 440 |
+
return "lush verdant fantasy concept art, vivid greens, dappled light"
|
| 441 |
+
if has("sea", "ocean", "water", "wave", "river", "lake"):
|
| 442 |
+
return "cinematic seascape concept art, luminous water, dramatic sky"
|
| 443 |
+
if has("desert", "sand", "dune"):
|
| 444 |
+
return "surreal desert dreamscape, warm amber tones, vast scale"
|
| 445 |
+
return "vivid cinematic concept art, rich saturated color, dramatic light"
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
def _split_phrases(text: str, cap: int = 6) -> list[str]:
|
| 449 |
+
import re
|
| 450 |
+
|
| 451 |
+
text = (text or "").strip()
|
| 452 |
+
if not text:
|
| 453 |
+
return []
|
| 454 |
+
parts = re.split(r"(?<=[.!?…])\s+|\n+", text)
|
| 455 |
+
phrases: list[str] = []
|
| 456 |
+
for raw in parts:
|
| 457 |
+
p = raw.strip()
|
| 458 |
+
if not p:
|
| 459 |
+
continue
|
| 460 |
+
if phrases and len(p) < 18: # glue stray fragments to the prior phrase
|
| 461 |
+
phrases[-1] = (phrases[-1] + " " + p)[:240]
|
| 462 |
+
else:
|
| 463 |
+
phrases.append(p[:240])
|
| 464 |
+
return phrases[:cap]
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
@spaces.GPU(duration=170)
|
| 468 |
+
def _corridor_world(text: str, session: str):
|
| 469 |
+
import numpy as np
|
| 470 |
+
from PIL import Image
|
| 471 |
+
|
| 472 |
+
from lightloom.depth.depth import estimate_depth, load_depth_pipeline
|
| 473 |
+
from lightloom.director.director import generate_shot_transformers, load_director_transformers
|
| 474 |
+
from lightloom.director.state import initial_state
|
| 475 |
+
from lightloom.paint.klein import load_klein_pipeline, paint
|
| 476 |
+
|
| 477 |
+
out_dir = Path("/tmp/lightloom/world") / session
|
| 478 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 479 |
+
phrases = _split_phrases(text) or ["a luminous world at the edge of the world"]
|
| 480 |
+
yield {"stage": "warming", "scenes": len(phrases)}
|
| 481 |
+
|
| 482 |
+
tokenizer, model = load_director_transformers()
|
| 483 |
+
klein = load_klein_pipeline()
|
| 484 |
+
depth_pipe = load_depth_pipeline()
|
| 485 |
+
state = initial_state().model_dump()
|
| 486 |
+
|
| 487 |
+
for i, phrase in enumerate(phrases):
|
| 488 |
+
yield {"stage": "directing", "index": i, "text": phrase}
|
| 489 |
+
try:
|
| 490 |
+
shot, _m = generate_shot_transformers(tokenizer, model, phrase, state)
|
| 491 |
+
style = _corridor_style(shot)
|
| 492 |
+
scene_prompt = f"{shot.image_prompt_en}, {shot.lighting}. {style}, {_CORRIDOR_QUALITY}"
|
| 493 |
+
yield {"stage": "painting", "index": i, "scene": scene_prompt[:150]}
|
| 494 |
+
img = paint(klein, scene_prompt, width=1024, height=576, steps=4, seed=1900 + i * 7)
|
| 495 |
+
img.save(out_dir / f"scene-{i}.webp", "WEBP", quality=90)
|
| 496 |
+
yield {
|
| 497 |
+
"stage": "scene",
|
| 498 |
+
"index": i,
|
| 499 |
+
"image": f"/frames-world/{session}/scene-{i}.webp",
|
| 500 |
+
"caption": phrase[:160],
|
| 501 |
+
"shot": shot.model_dump(),
|
| 502 |
+
}
|
| 503 |
+
dmap = estimate_depth(depth_pipe, img)
|
| 504 |
+
Image.fromarray((dmap * 255).astype(np.uint8)).save(out_dir / f"scene-{i}-depth.png")
|
| 505 |
+
yield {"stage": "depth", "index": i, "depth": f"/frames-world/{session}/scene-{i}-depth.png"}
|
| 506 |
+
except Exception as exc: # noqa: BLE001 - one bad scene must not end the journey.
|
| 507 |
+
yield {"stage": "scene_error", "index": i, "error": str(exc)[:160]}
|
| 508 |
+
yield {"stage": "done", "session": session, "count": len(phrases)}
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
@app.api(name="world", concurrency_id="gpu", concurrency_limit=1, stream_every=0.05)
|
| 512 |
+
def world_api(text: str = "", lang: str = "en") -> dict:
|
| 513 |
+
# default resolves at call time (when _GOLDEN_RECITAL, defined later, exists)
|
| 514 |
+
session = uuid.uuid4().hex[:8]
|
| 515 |
+
try:
|
| 516 |
+
for event in _corridor_world((text or _GOLDEN_RECITAL).strip(), session):
|
| 517 |
+
yield event
|
| 518 |
+
except Exception as exc: # noqa: BLE001 - quota guard.
|
| 519 |
+
message = str(exc).lower()
|
| 520 |
+
stage = "quota_exceeded" if any(t in message for t in ("gpu", "quota", "zerogpu", "exceeded")) else "error"
|
| 521 |
+
yield {"stage": stage, "error": str(exc)[:200]}
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
@app.get("/frames-world/{session}/{name}")
|
| 525 |
+
def world_frame(session: str, name: str):
|
| 526 |
+
path = Path("/tmp/lightloom/world") / Path(session).name / Path(name).name
|
| 527 |
+
if not path.is_file():
|
| 528 |
+
return JSONResponse({"error": "not found"}, status_code=404)
|
| 529 |
+
return FileResponse(path)
|
| 530 |
+
|
| 531 |
+
|
| 532 |
@app.post("/internal/bench/director-probe")
|
| 533 |
def director_probe_endpoint(backend: str = "transformers", threads: int = 8) -> dict[str, Any]:
|
| 534 |
if os.getenv("LIGHTLOOM_ENABLE_INTERNAL_BENCH", "0") != "1":
|
frontend/js/stage-corridor.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Lightloom · frontend/js/stage-corridor.js
|
| 2 |
+
* ============================================================================
|
| 3 |
+
* THE INFINITE 3D CORRIDOR — "speak, and your world unrolls ahead of you."
|
| 4 |
+
*
|
| 5 |
+
* Each phrase you narrate becomes a depth-displaced, curved scene panel placed
|
| 6 |
+
* further down a forward-flying corridor. The camera continuously travels toward
|
| 7 |
+
* the newest scene, passing THROUGH the older ones (which fade into atmosphere),
|
| 8 |
+
* so the world literally grows ahead of you as you keep speaking. Every panel has
|
| 9 |
+
* real relief from its depth map (near things loom as you approach) — Voice
|
| 10 |
+
* Scroll's real-time unrolling + WonderWorld's explorable, connected 3D scenes.
|
| 11 |
+
*
|
| 12 |
+
* window.LL.corridor = {
|
| 13 |
+
* init(canvas), addScene({imageUrl, depthUrl}), reset(), dispose(),
|
| 14 |
+
* setReducedMotion(flag), get ready, get count
|
| 15 |
+
* }
|
| 16 |
+
* addScene() resolves once the panel's textures are loaded and it has been queued.
|
| 17 |
+
* ==========================================================================*/
|
| 18 |
+
"use strict";
|
| 19 |
+
import * as THREE from "three";
|
| 20 |
+
|
| 21 |
+
window.LL = window.LL || {};
|
| 22 |
+
|
| 23 |
+
const Corridor = (() => {
|
| 24 |
+
let renderer = null, scene = null, camera = null, canvas = null;
|
| 25 |
+
let raf = 0, t0 = 0, lastT = 0, ok = false, reduced = false;
|
| 26 |
+
const panels = []; // { mesh, z, born } in arrival order
|
| 27 |
+
let frontZ = 0; // z of the most recently added panel (grows negative)
|
| 28 |
+
let camZ = 0, targetZ = 0; // camera travel along -Z
|
| 29 |
+
const loader = new THREE.TextureLoader();
|
| 30 |
+
loader.crossOrigin = "anonymous";
|
| 31 |
+
|
| 32 |
+
// Geometry constants (world units). Tuned for a roomy, immersive corridor.
|
| 33 |
+
const START_Z = -56; // first panel sits here, ahead of the camera at z=0
|
| 34 |
+
const SPACING = 58; // distance between consecutive scenes
|
| 35 |
+
const APPROACH = 52; // camera settles this far in front of the newest panel
|
| 36 |
+
// Forward-facing 16:9 scene panels (NOT equirectangular), generously oversized so
|
| 37 |
+
// they always OVERFILL the view (no black borders), with a very gentle concave
|
| 38 |
+
// curve so the world wraps the periphery without distorting the frame.
|
| 39 |
+
const PANEL_W = 234, PANEL_H = 134, CURVE_R = 480;
|
| 40 |
+
|
| 41 |
+
const VERT = `
|
| 42 |
+
varying vec2 vUv;
|
| 43 |
+
varying float vFog;
|
| 44 |
+
uniform sampler2D uDepth;
|
| 45 |
+
uniform float uRelief;
|
| 46 |
+
void main() {
|
| 47 |
+
vUv = uv;
|
| 48 |
+
float d = texture2D(uDepth, uv).r; // white = near
|
| 49 |
+
// push the surface toward the camera (+Z local) by the depth -> real relief
|
| 50 |
+
vec3 p = position + vec3(0.0, 0.0, 1.0) * (uRelief * d);
|
| 51 |
+
vec4 mv = modelViewMatrix * vec4(p, 1.0);
|
| 52 |
+
vFog = -mv.z; // view-space distance for fog
|
| 53 |
+
gl_Position = projectionMatrix * mv;
|
| 54 |
+
}`;
|
| 55 |
+
const FRAG = `
|
| 56 |
+
varying vec2 vUv;
|
| 57 |
+
varying float vFog;
|
| 58 |
+
uniform sampler2D uTex;
|
| 59 |
+
uniform float uOpacity;
|
| 60 |
+
uniform float uExposure;
|
| 61 |
+
uniform vec3 uFogColor;
|
| 62 |
+
uniform float uFogNear;
|
| 63 |
+
uniform float uFogFar;
|
| 64 |
+
void main() {
|
| 65 |
+
vec3 c = texture2D(uTex, vUv).rgb * uExposure;
|
| 66 |
+
// atmospheric depth: blend distant panels into the corridor haze
|
| 67 |
+
float fog = clamp((vFog - uFogNear) / (uFogFar - uFogNear), 0.0, 1.0);
|
| 68 |
+
c = mix(c, uFogColor, fog * 0.9);
|
| 69 |
+
// linear -> sRGB (raw ShaderMaterial is not auto-encoded by three.js)
|
| 70 |
+
c = max(c, vec3(0.0));
|
| 71 |
+
vec3 lo = c * 12.92;
|
| 72 |
+
vec3 hi = 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055;
|
| 73 |
+
c = mix(lo, hi, step(vec3(0.0031308), c));
|
| 74 |
+
// soft edge vignette on alpha: melt the panel borders into atmosphere, which
|
| 75 |
+
// also hides depth-displacement smear at the frame edges (a dream-frame look).
|
| 76 |
+
float vig = smoothstep(0.0, 0.13, vUv.x) * smoothstep(1.0, 0.87, vUv.x)
|
| 77 |
+
* smoothstep(0.0, 0.12, vUv.y) * smoothstep(1.0, 0.88, vUv.y);
|
| 78 |
+
gl_FragColor = vec4(c, uOpacity * vig);
|
| 79 |
+
}`;
|
| 80 |
+
|
| 81 |
+
const FOG_COLOR = new THREE.Color(0x0b0d12);
|
| 82 |
+
|
| 83 |
+
function curvedPanelGeo() {
|
| 84 |
+
const geo = new THREE.PlaneGeometry(PANEL_W, PANEL_H, 96, 56);
|
| 85 |
+
const pos = geo.attributes.position;
|
| 86 |
+
for (let i = 0; i < pos.count; i++) {
|
| 87 |
+
const x = pos.getX(i);
|
| 88 |
+
const theta = x / CURVE_R;
|
| 89 |
+
pos.setX(i, Math.sin(theta) * CURVE_R);
|
| 90 |
+
pos.setZ(i, (Math.cos(theta) - 1.0) * CURVE_R); // edges curl toward camera
|
| 91 |
+
}
|
| 92 |
+
pos.needsUpdate = true;
|
| 93 |
+
geo.computeVertexNormals();
|
| 94 |
+
return geo;
|
| 95 |
+
}
|
| 96 |
+
let GEO = null; // shared geometry (cloned per panel is unnecessary; reuse)
|
| 97 |
+
|
| 98 |
+
function loadTex(url) {
|
| 99 |
+
return new Promise((resolve) => {
|
| 100 |
+
if (!url) return resolve(null);
|
| 101 |
+
loader.load(url, (t) => { t.colorSpace = THREE.SRGBColorSpace; resolve(t); }, undefined, () => resolve(null));
|
| 102 |
+
});
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
function init(cv) {
|
| 106 |
+
if (ok) return;
|
| 107 |
+
try {
|
| 108 |
+
canvas = cv;
|
| 109 |
+
renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: false });
|
| 110 |
+
renderer.setPixelRatio(Math.min(devicePixelRatio || 1, 2));
|
| 111 |
+
scene = new THREE.Scene();
|
| 112 |
+
scene.background = FOG_COLOR.clone();
|
| 113 |
+
camera = new THREE.PerspectiveCamera(72, 1, 0.1, 600);
|
| 114 |
+
camera.position.set(0, 0, 0);
|
| 115 |
+
GEO = curvedPanelGeo();
|
| 116 |
+
resize();
|
| 117 |
+
window.addEventListener("resize", resize);
|
| 118 |
+
ok = true;
|
| 119 |
+
t0 = performance.now();
|
| 120 |
+
loop();
|
| 121 |
+
} catch (e) { ok = false; }
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function resize() {
|
| 125 |
+
if (!renderer || !canvas) return;
|
| 126 |
+
const w = canvas.clientWidth || canvas.parentElement?.clientWidth || 1280;
|
| 127 |
+
const h = canvas.clientHeight || canvas.parentElement?.clientHeight || 720;
|
| 128 |
+
renderer.setSize(w, h, false);
|
| 129 |
+
if (camera) { camera.aspect = w / h; camera.updateProjectionMatrix(); }
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
function reducedNow() {
|
| 133 |
+
return reduced || (document.body && document.body.classList.contains("reduced-motion")) ||
|
| 134 |
+
(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
async function addScene({ imageUrl, depthUrl } = {}) {
|
| 138 |
+
if (!ok) return null;
|
| 139 |
+
const [tex, depthTex] = await Promise.all([loadTex(imageUrl), loadTex(depthUrl)]);
|
| 140 |
+
if (!tex) return null;
|
| 141 |
+
const mat = new THREE.ShaderMaterial({
|
| 142 |
+
uniforms: {
|
| 143 |
+
uTex: { value: tex },
|
| 144 |
+
uDepth: { value: depthTex || tex },
|
| 145 |
+
uRelief: { value: reducedNow() ? 3.0 : 12.0 },
|
| 146 |
+
uOpacity: { value: 0.0 },
|
| 147 |
+
uExposure: { value: 1.12 },
|
| 148 |
+
uFogColor: { value: FOG_COLOR.clone() },
|
| 149 |
+
uFogNear: { value: 60.0 },
|
| 150 |
+
uFogFar: { value: 230.0 },
|
| 151 |
+
},
|
| 152 |
+
vertexShader: VERT, fragmentShader: FRAG, transparent: true, depthWrite: false, depthTest: false,
|
| 153 |
+
});
|
| 154 |
+
const mesh = new THREE.Mesh(GEO, mat);
|
| 155 |
+
frontZ = panels.length ? frontZ - SPACING : START_Z;
|
| 156 |
+
mesh.position.z = frontZ;
|
| 157 |
+
mesh.renderOrder = -frontZ; // draw far panels first (painter's order for blending)
|
| 158 |
+
scene.add(mesh);
|
| 159 |
+
panels.push({ mesh, z: frontZ, born: performance.now() });
|
| 160 |
+
targetZ = frontZ + APPROACH; // travel to just in front of the newest scene
|
| 161 |
+
return { index: panels.length - 1 };
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
function reset() {
|
| 165 |
+
for (const p of panels) { scene.remove(p.mesh); p.mesh.material.dispose(); }
|
| 166 |
+
panels.length = 0;
|
| 167 |
+
frontZ = 0; camZ = 0; targetZ = 0;
|
| 168 |
+
if (camera) camera.position.set(0, 0, 0);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
function loop() {
|
| 172 |
+
raf = requestAnimationFrame(loop);
|
| 173 |
+
if (!renderer || !scene || !camera) return;
|
| 174 |
+
const now = performance.now();
|
| 175 |
+
const dt = Math.min(0.05, (now - (lastT || now)) / 1000);
|
| 176 |
+
lastT = now;
|
| 177 |
+
const t = (now - t0) / 1000;
|
| 178 |
+
const rm = reducedNow();
|
| 179 |
+
|
| 180 |
+
// Continuous forward travel toward the newest scene; always drifting, never a
|
| 181 |
+
// dead stop, so even a single scene feels alive (the camera eases in, parallax).
|
| 182 |
+
const baseGlide = rm ? 0 : 2.2 * dt; // gentle constant push deeper
|
| 183 |
+
camZ += (targetZ - camZ) * (rm ? 0.06 : 0.022);
|
| 184 |
+
if (panels.length && camZ > targetZ + 0.2) camZ -= baseGlide;
|
| 185 |
+
camera.position.z = camZ;
|
| 186 |
+
// subtle handheld life
|
| 187 |
+
camera.position.x = rm ? 0 : Math.sin(t * 0.13) * 1.4;
|
| 188 |
+
camera.position.y = rm ? 0 : Math.sin(t * 0.10) * 0.8;
|
| 189 |
+
camera.rotation.set(rm ? 0 : Math.sin(t * 0.08) * 0.015, rm ? 0 : Math.sin(t * 0.06) * 0.02, 0, "YXZ");
|
| 190 |
+
|
| 191 |
+
// Per-panel opacity envelope: emerge from the far haze, hold full through the
|
| 192 |
+
// viewing band, then DISSOLVE before the camera arrives — so we never fly into
|
| 193 |
+
// a panel's warped close-up; each scene melts into atmosphere as the next rises.
|
| 194 |
+
for (let i = panels.length - 1; i >= 0; i--) {
|
| 195 |
+
const p = panels[i];
|
| 196 |
+
const ahead = camera.position.z - p.z; // >0 while the panel is in front
|
| 197 |
+
const fadeIn = smoothstep(160.0, 92.0, ahead); // far haze -> visible
|
| 198 |
+
const fadeOut = smoothstep(30.0, 50.0, ahead); // fully dissolved well before arrival
|
| 199 |
+
let op = Math.min(fadeIn, fadeOut);
|
| 200 |
+
// gentle birth fade so a freshly streamed scene doesn't pop
|
| 201 |
+
const age = (now - p.born) / 1000;
|
| 202 |
+
op *= Math.min(1, age / 0.7);
|
| 203 |
+
p.mesh.material.uniforms.uOpacity.value = op;
|
| 204 |
+
if (ahead < 28.0) { // dissolved: recycle before the camera can reach it
|
| 205 |
+
scene.remove(p.mesh); p.mesh.material.dispose(); panels.splice(i, 1);
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
renderer.render(scene, camera);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
function smoothstep(edge0, edge1, x) {
|
| 212 |
+
const t = Math.max(0, Math.min(1, (x - edge0) / (edge1 - edge0)));
|
| 213 |
+
return t * t * (3 - 2 * t);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
function setReducedMotion(flag) {
|
| 217 |
+
reduced = !!flag;
|
| 218 |
+
for (const p of panels) p.mesh.material.uniforms.uRelief.value = reducedNow() ? 3.0 : 12.0;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
function dispose() {
|
| 222 |
+
cancelAnimationFrame(raf);
|
| 223 |
+
window.removeEventListener("resize", resize);
|
| 224 |
+
reset();
|
| 225 |
+
if (renderer) renderer.dispose();
|
| 226 |
+
ok = false;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
return {
|
| 230 |
+
init, addScene, reset, dispose, setReducedMotion,
|
| 231 |
+
get ready() { return ok; },
|
| 232 |
+
get count() { return panels.length; },
|
| 233 |
+
};
|
| 234 |
+
})();
|
| 235 |
+
|
| 236 |
+
LL.corridor = Corridor;
|
| 237 |
+
export default LL.corridor;
|
scripts/shoot-corridor.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Validate the 3D corridor renderer (stage-corridor.js): feed the 4 existing
|
| 2 |
+
// showcase worlds as streamed scenes and screenshot the camera flying forward
|
| 3 |
+
// through the growing corridor. Usage: node scripts/shoot-corridor.cjs
|
| 4 |
+
const { chromium } = require("playwright");
|
| 5 |
+
const http = require("http");
|
| 6 |
+
const fs = require("fs");
|
| 7 |
+
const path = require("path");
|
| 8 |
+
const ROOT = process.cwd();
|
| 9 |
+
const PORT = 8805;
|
| 10 |
+
const CT = { ".html": "text/html", ".js": "application/javascript", ".css": "text/css", ".woff2": "font/woff2", ".webp": "image/webp", ".png": "image/png" };
|
| 11 |
+
|
| 12 |
+
const TEST_HTML = `<!doctype html><html><head>
|
| 13 |
+
<script type="importmap">{"imports":{"three":"/frontend/vendor/three.module.js"}}</script>
|
| 14 |
+
<style>html,body{margin:0;background:#0b0d12;overflow:hidden}#c{width:100vw;height:100vh;display:block}</style>
|
| 15 |
+
</head><body><canvas id="c"></canvas>
|
| 16 |
+
<script type="module">
|
| 17 |
+
import "/frontend/js/stage-corridor.js";
|
| 18 |
+
const SC = window.LL.corridor;
|
| 19 |
+
SC.init(document.getElementById('c'));
|
| 20 |
+
const worlds = [0,1,2,0,1].map(i => ({
|
| 21 |
+
imageUrl: '/shots/corr/scene-'+i+'.png',
|
| 22 |
+
depthUrl: '/shots/corr/scene-'+i+'-depth.png',
|
| 23 |
+
}));
|
| 24 |
+
window.__added = 0;
|
| 25 |
+
(async () => {
|
| 26 |
+
for (const w of worlds) { await SC.addScene(w); window.__added++; await new Promise(r=>setTimeout(r, 4000)); }
|
| 27 |
+
window.__done = true;
|
| 28 |
+
})();
|
| 29 |
+
</script></body></html>`;
|
| 30 |
+
|
| 31 |
+
const server = http.createServer((req, res) => {
|
| 32 |
+
let p = decodeURIComponent(req.url.split("?")[0]);
|
| 33 |
+
if (p === "/_corridor.html") { res.writeHead(200, { "content-type": "text/html" }); res.end(TEST_HTML); return; }
|
| 34 |
+
if (p.startsWith("/shots/")) p = "/.shots/" + p.slice(7);
|
| 35 |
+
const file = path.join(ROOT, p);
|
| 36 |
+
fs.readFile(file, (e, d) => { if (e) { res.writeHead(404); res.end("nf"); } else { res.writeHead(200, { "content-type": CT[path.extname(file)] || "application/octet-stream" }); res.end(d); } });
|
| 37 |
+
});
|
| 38 |
+
|
| 39 |
+
(async () => {
|
| 40 |
+
const SHOTS = path.join(ROOT, ".shots"); fs.mkdirSync(SHOTS, { recursive: true });
|
| 41 |
+
await new Promise((r) => server.listen(PORT, r));
|
| 42 |
+
const browser = await chromium.launch({ args: ["--use-gl=angle", "--use-angle=swiftshader", "--ignore-gpu-blocklist", "--enable-webgl"] });
|
| 43 |
+
const page = await browser.newPage({ viewport: { width: 1280, height: 720 } });
|
| 44 |
+
const errs = []; page.on("pageerror", (e) => errs.push(e.message.slice(0, 200)));
|
| 45 |
+
page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); });
|
| 46 |
+
await page.goto(`http://localhost:${PORT}/_corridor.html`, { waitUntil: "networkidle", timeout: 25000 }).catch((e) => errs.push("goto:" + e.message));
|
| 47 |
+
// capture across the fly-through (scenes stream every 1.8s; camera advances)
|
| 48 |
+
const caps = [2500, 6500, 10500, 14500, 18500];
|
| 49 |
+
let prev = 0;
|
| 50 |
+
for (let i = 0; i < caps.length; i++) {
|
| 51 |
+
await page.waitForTimeout(caps[i] - prev); prev = caps[i];
|
| 52 |
+
await page.screenshot({ path: path.join(SHOTS, `corridor-${i}.png`) });
|
| 53 |
+
}
|
| 54 |
+
const st = await page.evaluate(() => ({ ready: window.LL.corridor.ready, count: window.LL.corridor.count, added: window.__added }));
|
| 55 |
+
console.log("CORRIDOR:", JSON.stringify(st), "ERRS:", JSON.stringify(errs.slice(0, 8)));
|
| 56 |
+
await browser.close(); server.close();
|
| 57 |
+
})().catch((e) => { console.error("ERR:", e.message); process.exit(1); });
|