Recreate-AAA / scripts /splat /page.html
CharlieDreemur's picture
RecreateAAA 0.1.0 from Recreate-AAA/Recreate-AAA@7da1a3d
966b234 verified
Raw History Blame Contribute Delete
2.67 kB
<!doctype html>
<meta charset="utf-8">
<title>Reconstructed place</title>
<style>html, body { margin: 0; height: 100%; background: #000; overflow: hidden } canvas { display: block }</style>
<script type="importmap">{ "imports": { "three": "./lib/three.module.js" } }</script>
<script type="module">
// The place the recording shows, walked with the recording's own controller. A game is built by adding to
// this scene: see splats.js and controller.js.
import * as THREE from 'three';
import { loadSplats } from './splats.js';
import { loadController } from './controller.js';
import { loadMoving } from './moving.js';
import { loadActors } from './actors.js';
import { loadOverlays } from './overlays.js';
const [splats, player] = await Promise.all([loadSplats(THREE), loadController()]);
const renderer = new THREE.WebGLRenderer({ antialias: false });
renderer.setPixelRatio(1); renderer.setSize(innerWidth, innerHeight);
const scene = new THREE.Scene(); scene.add(splats);
const moving = await loadMoving(THREE); if (moving) scene.add(moving); // what moved in the recording, as it was filmed
const actors = await loadActors(THREE, player, moving); if (actors) scene.add(actors); // the figures among them that have a body: moved as the recording moved them
const overlays = await loadOverlays(THREE); // what the recording drew on the screen: a HUD, a banner
const AT = new URLSearchParams(location.search).get('t'); // ?t=seconds holds them at one moment (with ?pose=)
const sky = await new THREE.TextureLoader().loadAsync('./sky.jpg').catch(() => null); // the sky as the frames show it, where there is one
if (sky) { sky.mapping = THREE.EquirectangularReflectionMapping; sky.colorSpace = THREE.SRGBColorSpace; scene.background = sky; }
const aspect = innerWidth / innerHeight;
const camera = new THREE.PerspectiveCamera(2 * Math.atan(Math.tan(player.numbers.hfov_deg * Math.PI / 360) / aspect) * 180 / Math.PI, aspect, 0.05, 2000);
document.body.appendChild(renderer.domElement); // only now: the first frame anyone sees has the place in it
let last = null, clock = 0;
function frame(now) {
const dt = last === null ? 0 : Math.min(0.05, (now - last) / 1000); last = now; clock += dt;
player.step(dt);
const seconds = AT !== null ? +AT : clock + (player.numbers.page_lead_frames || 0) / 30;
if (moving) moving.show(seconds);
if (actors) actors.show(seconds, dt, camera);
player.apply(camera); renderer.render(scene, camera);
if (overlays) { overlays.show(seconds); overlays.draw(renderer); }
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
</script>