Skip to content

A free, open-source framework for cinematic, interactive 3D websites with AI-generated assets (Nano Banana 2 + Meshy 7.1 on fal). 20 example sites.

1.7 KB
Raw Blame
import { Engine, THREE, studioEnvironment, normalize, prepModel } from '../../src/core/engine.js';
import { Assets } from '../../src/core/assets.js';
const q = new URLSearchParams(location.search);
const eng = new Engine({ canvas: document.getElementById('c'), background: 0x0b0b0d, post: { bloom: { intensity: 0.3 }, noise: 0.02 } });
const { scene, camera, renderer } = eng;
scene.environment = studioEnvironment(renderer);
scene.environmentIntensity = +(q.get('env') ?? 1);
const key = new THREE.DirectionalLight(0xffffff, +(q.get('key') ?? 2.5));
key.position.set(3, 5, 4); key.castShadow = true; key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = key.shadow.camera.bottom = -2; key.shadow.camera.right = key.shadow.camera.top = 2; key.shadow.bias = -0.0005;
scene.add(key);
const floor = new THREE.Mesh(new THREE.CircleGeometry(4, 64), new THREE.MeshStandardMaterial({ color: 0x151517, roughness: 0.9 }));
floor.rotation.x = -Math.PI / 2; floor.receiveShadow = true; scene.add(floor);
const assets = new Assets();
const g = await assets.gltf(q.get('m'));
const m = g.scene; normalize(m, 2); prepModel(m, renderer); scene.add(m);
const rot = +(q.get('rot') ?? 0) * Math.PI / 180;
m.rotation.y = rot;
const dist = +(q.get('d') ?? 4.2);
camera.position.set(0, +(q.get('h') ?? 1.4), dist); camera.lookAt(0, 0.9, 0);
let tris = 0; m.traverse(o => { if (o.isMesh) tris += o.geometry.index.count / 3; });
document.getElementById('i').textContent = `${q.get('m')} — ${Math.round(tris)} tris`;
if (q.get('spin')) eng.onTick(dt => { m.rotation.y += dt * 0.4; });
if (q.get('wire')) m.traverse(o => { if (o.isMesh) o.material = new THREE.MeshStandardMaterial({ color: 0x999999, roughness: 0.6, flatShading: false }); });
eng.start();