Renderer: WebGL2 · Export: WebCodecs · Sandbox: Isolated ES Module
import * as THREE from 'three';
export async function buildScene({ scene, camera, helpers, params }) {
const clamp01 = (v) => (v < 0 ? 0 : v > 1 ? 1 : v);
const smoothstep = (a, b, x) => {
const t = clamp01((x - a) / (b - a || 1e-6));
return t * t * (3 - 2 * t);
};
/* ---------------------------------------------------------------- stage */
const studio = helpers.setupStudioLighting({ preset: 'dark-rim', envIntensity: 1.42 });
const stage = helpers.createStageBackdrop({
style: 'infinite-cyc',
topColor: '#040404',
bottomColor: '#0B0805',
accentColor: '#FFB25E',
groundY: -1.75,
shadowOpacity: 0.88
});
scene.add(stage.object);
/* ------------------------------------------------------------ materials */
const brushed = helpers.createBrushedMetalMaps({ direction: 'horizontal', grain: 0.9 });
const titaniumMat = new THREE.MeshPhysicalMaterial({
color: new THREE.Color('#C9CDD2'),
metalness: 1.0,
roughness: 0.24,
roughnessMap: brushed.roughnessMap,
bumpMap: brushed.bumpMap,
bumpScale: 0.01,
clearcoat: 0.3,
clearcoatRoughness: 0.32,
envMapIntensity: 1.5
});
const glassMat = helpers.createGlassMaterial({
color: '#FFB25E',
attenuationColor: '#8A5A2B',
attenuationDistance: 1.15,
thickness: 0.6,
ior: 1.45,
roughness: 0.06,
transmission: 0.93,
dispersion: 0.32,
iridescence: 0.14,
clearcoat: 1.0
});
if (glassMat.emissive) glassMat.emissive.set('#FFB25E');
else glassMat.emissive = new THREE.Color('#FFB25E');
glassMat.emissiveIntensity = 0.04;
/* ---------------------------------------------------------------- text */
const heroText = (params && params.text) || 'AURELIA';
const TARGET_W = 4.4;
const glassText = await helpers.createText3D(heroText, {
font: 'Bodoni Moda',
fontWeight: 600,
depth: 0.5,
bevelSize: 0.026,
material: glassMat,
splitByChar: true,
targetWidth: TARGET_W,
inflate: { resolution: 128, maxDepth: 0.3, initialInflation: 0.0 }
});
scene.add(glassText.object);
const titaniumText = await helpers.createText3D(heroText, {
font: 'Bodoni Moda',
fontWeight: 600,
depth: 0.24,
bevelSize: 0.018,
material: titaniumMat,
splitByChar: true,
targetWidth: TARGET_W
});
scene.add(titaniumText.object);
/* centre both plates on the world origin, metal sits behind as bevel rim */
const boxG = new THREE.Box3().setFromObject(glassText.object);
const cG = boxG.getCenter(new THREE.Vector3());
glassText.object.position.set(-cG.x, -cG.y + 0.05, 0);
const boxT = new THREE.Box3().setFromObject(titaniumText.object);
const cT = boxT.getCenter(new THREE.Vector3());
const METAL_SCALE = 1.045;
titaniumText.object.scale.setScalar(METAL_SCALE);
titaniumText.object.position.set(-cT.x * METAL_SCALE, -cT.y * METAL_SCALE + 0.05, -0.62);
const gChars = glassText.object.children;
const mChars = titaniumText.object.children;
const gBase = gChars.map((c) => c.position.clone());
const mBase = mChars.map((c) => c.position.clone());
/* -------------------------------------------------- contour sweep halo */
let sweepHandle = null;
let sweepMat = null;
try {
sweepMat = new THREE.MeshBasicMaterial({
color: new THREE.Color('#FFB25E'),
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
});
sweepHandle = await helpers.createContourSweep(heroText, {
font: 'Bodoni Moda',
radius: 0.018,
material: sweepMat
});
const sBox = new THREE.Box3().setFromObject(sweepHandle.object);
const sSize = sBox.getSize(new THREE.Vector3());
const sCenter = sBox.getCenter(new THREE.Vector3());
const k = sSize.x > 1e-4 ? (TARGET_W * 1.3) / sSize.x : 1;
sweepHandle.object.scale.setScalar(k);
sweepHandle.object.position.set(-sCenter.x * k, -sCenter.y * k + 0.05, -2.15);
scene.add(sweepHandle.object);
} catch (err) {
sweepHandle = null;
}
/* ------------------------------------------------------- ambient dust */
const dustGeo = new THREE.IcosahedronGeometry(0.03, 0);
const dustMat = new THREE.MeshBasicMaterial({
color: new THREE.Color('#FFB25E'),
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const dust = helpers.createArray(dustGeo, dustMat, {
layout: 'sphere',
count: 90,
radius: 3.6,
seed: 7
});
dust.object.position.set(0, 0.25, -5.4);
scene.add(dust.object);
/* ------------------------------------------------------------- camera */
const rig = helpers.createCameraRig({
waypoints: [
[-0.95, -0.30, 6.40],
[-0.38, -0.22, 5.85],
[0.42, -0.12, 5.25],
[0.55, -0.04, 4.95],
[0.18, 0.18, 5.05],
[0.00, 0.30, 5.15]
],
target: [0, 0.05, 0],
shakeAmplitude: 0.012,
shakeFrequency: 0.85,
fov: 34
});
const post = helpers.setupPostProcessing({
bloom: { strength: 0.34, radius: 0.62, threshold: 0.82 },
dof: { focus: 5.4, aperture: 0.0007, maxblur: 0.006 }
});
const focusTarget = new THREE.Vector3(0, 0.05, 0);
/* ------------------------------------------------------------- update */
return {
controls: {
glow: { type: 'number', label: 'Amber Glow', value: 1.0, min: 0, max: 2.5, step: 0.05 },
camShake: { type: 'number', label: 'Handheld', value: 1.0, min: 0, max: 2.5, step: 0.05 }
},
update(progress, time, duration, ctrls) {
const glow = ctrls && typeof ctrls.glow === 'number' ? ctrls.glow : 1;
const tSweep = smoothstep(0.18, 0.55, progress);
const tFinal = smoothstep(0.82, 1.0, progress);
/* --- material choreography (pure functions of progress) --- */
glassMat.ior = 1.45 + 0.07 * tSweep;
glassMat.thickness = 0.55 + 0.75 * smoothstep(0.0, 0.5, progress);
glassMat.roughness = 0.078 - 0.02 * tFinal;
glassMat.emissiveIntensity =
(0.035 + 0.20 * tSweep + 0.55 * tFinal) *
glow *
(1 + 0.05 * Math.sin(time * 2.1));
titaniumMat.roughness = 0.34 - 0.10 * tSweep - 0.045 * tFinal;
titaniumMat.bumpScale = 0.007 + 0.008 * tSweep;
/* --- tension compress + snap --- */
const snapS = helpers.spring(clamp01((progress - 0.79) / 0.12), {
stiffness: 240,
damping: 13
});
const compressAmt = 0.015 * smoothstep(0.55, 0.79, progress) * (1 - snapS);
const comp = 1 - Math.max(-0.008, Math.min(0.02, compressAmt));
/* --- glass inflation --- */
if (typeof glassText.setInflation === 'function') {
const infl = 0.32 * smoothstep(0.02, 0.62, progress);
glassText.setInflation(infl, 0.06 * Math.sin(time * 1.4));
}
/* --- per-glyph rhythm --- */
const n = Math.max(gChars.length, mChars.length);
for (let i = 0; i < n; i++) {
const p = helpers.stagger(progress, i, n, {
start: 0.01,
end: 0.30,
from: 'center',
overlap: 0.55
});
const sp = helpers.spring(clamp01(p), { stiffness: 150, damping: 15 });
const rise = 1 - sp;
const g = gChars[i];
const gb = gBase[i];
if (g && gb) {
const dir = gb.x === 0 ? 1 : Math.sign(gb.x);
const bob = Math.sin(time * 1.55 + i * 0.6) * 0.032 * sp;
g.position.set(gb.x, gb.y + bob - rise * 0.5, gb.z - rise * 1.6);
const s = (0.02 + 0.98 * sp) * comp;
g.scale.set(s, s, s);
g.rotation.set(0, -rise * 0.5 * dir, Math.sin(time * 1.2 + i) * 0.008 * sp);
}
const m = mChars[i];
const mb = mBase[i];
if (m && mb) {
const dir = mb.x === 0 ? 1 : Math.sign(mb.x);
const bob = Math.sin(time * 1.55 + i * 0.6) * 0.032 * sp;
m.position.set(mb.x, mb.y + bob - rise * 0.5, mb.z - rise * 1.6);
const s = (0.02 + 0.98 * sp) * comp;
m.scale.set(s, s, s);
m.rotation.set(0, -rise * 0.5 * dir, Math.sin(time * 1.2 + i) * 0.008 * sp);
}
}
/* --- contour halo --- */
if (sweepMat && sweepHandle) {
const reveal = smoothstep(0.14, 0.44, progress);
const fade = 1 - 0.55 * smoothstep(0.78, 0.99, progress);
sweepMat.opacity =
(0.08 + 0.52 * reveal) * fade * (0.72 + 0.28 * Math.sin(time * 1.7)) * glow;
}
/* --- dust --- */
dustMat.opacity =
0.45 * smoothstep(0.03, 0.35, progress) * (0.55 + 0.45 * Math.sin(progress * Math.PI));
const drift = time * 0.22;
dust.setTransform((i, basePos, baseQuat, dummy) => {
const ph = i * 1.618;
dummy.position.set(
basePos.x + Math.cos(drift * 0.8 + ph * 1.3) * 0.35,
basePos.y + Math.sin(drift + ph) * 0.42,
basePos.z + Math.sin(drift * 0.6 + ph * 0.7) * 0.3
);
dummy.quaternion.copy(baseQuat);
const sc = 0.7 + 0.45 * Math.sin(ph * 2.3 + drift * 1.6);
dummy.scale.setScalar(sc);
dummy.updateMatrix();
});
/* --- camera --- */
rig.update(progress, time);
if (post && camera) {
post.setFocus(camera.position.distanceTo(focusTarget));
}
},
dispose() {
studio.dispose();
stage.dispose();
glassText.dispose();
titaniumText.dispose();
if (sweepHandle) sweepHandle.dispose();
if (sweepMat) sweepMat.dispose();
dust.dispose();
dustGeo.dispose();
dustMat.dispose();
titaniumMat.dispose();
glassMat.dispose();
brushed.dispose();
post.dispose();
}
};
}