mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 22:08:40 +00:00
Shader pipeline (carve, FSSM unpack, gfx1013 disassembly, RDNA2 to SPIR-V), asset export via rpf9-explorer's Core (submodule), PE loader and shim skeleton, and make_game.py, which builds from the user's own copy of the game. No game data, keys or executables are included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
214 lines
11 KiB
HTML
214 lines
11 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Map Viewer</title>
|
|
<style>
|
|
:root { --bg: #0d1014; --fg: #e6e8eb; --dim: #8b929b; --accent: #5fb3ff; --warn: #ffb454; --panel: rgba(13,16,20,.82); }
|
|
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 13px/1.45 ui-monospace, Consolas, monospace; overflow: hidden; }
|
|
canvas { display: block; }
|
|
#hud { position: fixed; top: 12px; left: 12px; background: var(--panel); padding: 10px 12px; border-radius: 8px; min-width: 250px; pointer-events: none; }
|
|
#hud b { color: var(--accent); font-weight: 600; }
|
|
#banner { position: fixed; top: 12px; right: 12px; max-width: 360px; background: var(--panel); border-left: 3px solid var(--warn); padding: 10px 12px; border-radius: 8px; }
|
|
#banner.hidden { display: none; }
|
|
#help { position: fixed; bottom: 12px; left: 12px; background: var(--panel); padding: 10px 12px; border-radius: 8px; color: var(--dim); }
|
|
#help kbd { color: var(--fg); background: #1c2129; padding: 0 5px; border-radius: 3px; }
|
|
#start { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); cursor: pointer; font-size: 15px; }
|
|
#start.hidden { display: none; }
|
|
@media (max-width: 760px) {
|
|
#hud { right: 12px; min-width: 0; }
|
|
#banner { top: auto; bottom: 104px; left: 12px; max-width: none; }
|
|
#help { right: 12px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="hud"></div>
|
|
<div id="banner"></div>
|
|
<div id="help">
|
|
<kbd>W A S D</kbd> move · <kbd>Q</kbd>/<kbd>E</kbd> down/up · <kbd>Shift</kbd> fast · <kbd>Ctrl</kbd> slow · wheel: speed<br>
|
|
<kbd>F</kbd> wireframe · <kbd>G</kbd> chunk bounds · <kbd>R</kbd> back to spawn · <kbd>Esc</kbd> release mouse
|
|
</div>
|
|
<div id="start">Click to fly</div>
|
|
|
|
<script type="importmap">
|
|
{ "imports": {
|
|
"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
|
|
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"
|
|
} }
|
|
</script>
|
|
<script type="module">
|
|
import * as THREE from "three";
|
|
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
|
|
|
|
// ---------- world description ----------
|
|
// world/world.json: { "spawn": [x,y,z], "chunks": [ { "id", "url", "bounds": [minx,miny,minz,maxx,maxy,maxz] } ] }
|
|
// Each chunk is a .glb in world space (Y up, metres). When no world.json exists the viewer
|
|
// generates TEST terrain locally and says so on screen.
|
|
async function loadWorld() {
|
|
if (new URLSearchParams(location.search).has("test")) return testWorld();
|
|
try {
|
|
const r = await fetch("world/world.json", { cache: "no-store" });
|
|
if (!r.ok) throw new Error(r.status);
|
|
const w = await r.json();
|
|
w.test = false;
|
|
return w;
|
|
} catch { return testWorld(); }
|
|
}
|
|
|
|
function testWorld() {
|
|
const size = 256, n = 24, chunks = [];
|
|
for (let z = -n / 2; z < n / 2; z++)
|
|
for (let x = -n / 2; x < n / 2; x++)
|
|
chunks.push({ id: `test_${x}_${z}`, test: [x, z, size],
|
|
bounds: [x * size, -50, z * size, (x + 1) * size, 200, (z + 1) * size] });
|
|
return { test: true, spawn: [0, 120, 0], chunks };
|
|
}
|
|
|
|
// Deterministic test terrain: rolling hills plus a grid of boxes. Nothing here comes from the game.
|
|
function hash(x, z) { const s = Math.sin(x * 127.1 + z * 311.7) * 43758.5453; return s - Math.floor(s); }
|
|
function noise(x, z) {
|
|
const xi = Math.floor(x), zi = Math.floor(z), xf = x - xi, zf = z - zi;
|
|
const u = xf * xf * (3 - 2 * xf), v = zf * zf * (3 - 2 * zf);
|
|
const a = hash(xi, zi), b = hash(xi + 1, zi), c = hash(xi, zi + 1), d = hash(xi + 1, zi + 1);
|
|
return a + (b - a) * u + (c - a) * v + (a - b - c + d) * u * v;
|
|
}
|
|
function height(x, z) {
|
|
return 60 * noise(x / 900, z / 900) + 18 * noise(x / 210, z / 210) + 4 * noise(x / 40, z / 40) - 30;
|
|
}
|
|
function buildTestChunk([cx, cz, size]) {
|
|
const g = new THREE.Group(), seg = 32;
|
|
const geo = new THREE.PlaneGeometry(size, size, seg, seg);
|
|
geo.rotateX(-Math.PI / 2);
|
|
const pos = geo.attributes.position, col = [];
|
|
for (let i = 0; i < pos.count; i++) {
|
|
const x = pos.getX(i) + cx * size + size / 2, z = pos.getZ(i) + cz * size + size / 2, y = height(x, z);
|
|
pos.setXYZ(i, x, y, z);
|
|
const t = THREE.MathUtils.clamp((y + 30) / 90, 0, 1);
|
|
col.push(0.22 + 0.35 * t, 0.36 + 0.25 * t, 0.24 + 0.1 * t);
|
|
}
|
|
geo.setAttribute("color", new THREE.Float32BufferAttribute(col, 3));
|
|
geo.computeVertexNormals();
|
|
g.add(new THREE.Mesh(geo, new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.95 })));
|
|
const box = new THREE.BoxGeometry(1, 1, 1); box.translate(0, 0.5, 0);
|
|
const count = 18, inst = new THREE.InstancedMesh(box, new THREE.MeshStandardMaterial({ color: 0x9aa4b1, roughness: 0.7 }), count);
|
|
const m = new THREE.Matrix4();
|
|
for (let i = 0; i < count; i++) {
|
|
const x = cx * size + hash(cx * 31 + i, cz) * size, z = cz * size + hash(cx, cz * 17 + i) * size;
|
|
const w = 8 + 22 * hash(i, cx + cz), h = 6 + 70 * hash(cz + i, cx) ** 3;
|
|
m.compose(new THREE.Vector3(x, height(x, z) - 1, z), new THREE.Quaternion(), new THREE.Vector3(w, h, w));
|
|
inst.setMatrixAt(i, m);
|
|
}
|
|
g.add(inst);
|
|
return g;
|
|
}
|
|
|
|
// ---------- scene ----------
|
|
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
|
|
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.5));
|
|
renderer.setSize(innerWidth, innerHeight);
|
|
document.body.prepend(renderer.domElement);
|
|
const scene = new THREE.Scene();
|
|
scene.background = new THREE.Color(0x9cc3e6);
|
|
scene.fog = new THREE.Fog(0x9cc3e6, 900, 2600);
|
|
const camera = new THREE.PerspectiveCamera(70, innerWidth / innerHeight, 0.5, 6000);
|
|
scene.add(new THREE.HemisphereLight(0xdfefff, 0x4a4030, 1.1));
|
|
const sun = new THREE.DirectionalLight(0xfff2dd, 1.6); sun.position.set(0.4, 1, 0.3); scene.add(sun);
|
|
addEventListener("resize", () => { camera.aspect = innerWidth / innerHeight; camera.updateProjectionMatrix(); renderer.setSize(innerWidth, innerHeight); });
|
|
|
|
// ---------- freecam ----------
|
|
const keys = new Set(); let yaw = 0, pitch = -0.25, speed = 40, locked = false;
|
|
// Pointer lock when the browser allows it; embedded views (iframes, preview panes) fall back to drag-to-look.
|
|
const start = document.getElementById("start");
|
|
let dragLook = false, dragging = false;
|
|
start.onclick = async () => {
|
|
try { await renderer.domElement.requestPointerLock(); }
|
|
catch { dragLook = true; start.classList.add("hidden"); document.getElementById("help").insertAdjacentHTML("beforeend", "<br>mouse lock unavailable here: drag to look"); }
|
|
};
|
|
document.addEventListener("pointerlockchange", () => { locked = document.pointerLockElement === renderer.domElement; start.classList.toggle("hidden", locked || dragLook); });
|
|
renderer.domElement.addEventListener("mousedown", () => { dragging = true; });
|
|
addEventListener("mouseup", () => { dragging = false; });
|
|
addEventListener("mousemove", e => {
|
|
if (!locked && !(dragLook && dragging)) return;
|
|
yaw -= e.movementX * 0.0022; pitch = THREE.MathUtils.clamp(pitch - e.movementY * 0.0022, -1.55, 1.55);
|
|
});
|
|
addEventListener("wheel", e => { speed = THREE.MathUtils.clamp(speed * (e.deltaY < 0 ? 1.15 : 1 / 1.15), 1, 3000); }, { passive: true });
|
|
addEventListener("keydown", e => {
|
|
keys.add(e.code);
|
|
if (e.code === "KeyF") wire = !wire, applyWire();
|
|
if (e.code === "KeyG") showBounds = !showBounds, boundsGroup.visible = showBounds;
|
|
if (e.code === "KeyR") camera.position.fromArray(world.spawn);
|
|
});
|
|
addEventListener("keyup", e => keys.delete(e.code));
|
|
addEventListener("blur", () => keys.clear());
|
|
|
|
// ---------- chunk streaming ----------
|
|
const LOAD_R = 1400, UNLOAD_R = 2000, MAX_INFLIGHT = 4;
|
|
const loader = new GLTFLoader();
|
|
const live = new Map(); let inflight = 0, wire = false, showBounds = false, failed = 0;
|
|
const boundsGroup = new THREE.Group(); boundsGroup.visible = false; scene.add(boundsGroup);
|
|
function applyWire(root) {
|
|
(root ? [root] : [...live.values()].map(c => c.obj).filter(Boolean)).forEach(o =>
|
|
o.traverse(n => { if (n.material) [].concat(n.material).forEach(m => m.wireframe = wire); }));
|
|
}
|
|
function dist(c, p) {
|
|
const b = c.bounds;
|
|
const dx = Math.max(b[0] - p.x, 0, p.x - b[3]), dy = Math.max(b[1] - p.y, 0, p.y - b[4]), dz = Math.max(b[2] - p.z, 0, p.z - b[5]);
|
|
return Math.hypot(dx, dy, dz);
|
|
}
|
|
function drop(id) {
|
|
const c = live.get(id); if (!c) return;
|
|
if (c.obj) { scene.remove(c.obj); c.obj.traverse(n => { n.geometry?.dispose(); [].concat(n.material || []).forEach(m => { m.map?.dispose(); m.dispose(); }); }); }
|
|
live.delete(id);
|
|
}
|
|
function stream() {
|
|
const p = camera.position;
|
|
for (const [id, c] of live) if (c.obj && dist(c.def, p) > UNLOAD_R) drop(id);
|
|
const want = world.chunks.filter(c => !live.has(c.id) && dist(c, p) < LOAD_R).sort((a, b) => dist(a, p) - dist(b, p));
|
|
for (const def of want) {
|
|
if (inflight >= MAX_INFLIGHT) break;
|
|
const entry = { def, obj: null }; live.set(def.id, entry);
|
|
if (def.test) { entry.obj = buildTestChunk(def.test); scene.add(entry.obj); applyWire(entry.obj); continue; }
|
|
inflight++;
|
|
loader.load(def.url, g => { inflight--; if (live.get(def.id) !== entry) return; entry.obj = g.scene; scene.add(g.scene); applyWire(g.scene); },
|
|
undefined, () => { inflight--; failed++; });
|
|
}
|
|
}
|
|
|
|
// ---------- main loop ----------
|
|
const world = await loadWorld();
|
|
camera.position.fromArray(world.spawn);
|
|
const banner = document.getElementById("banner");
|
|
if (world.test) banner.innerHTML = "<b>TEST TERRAIN</b>: generated in the browser. No game geometry has been decoded yet. " +
|
|
"Put <code>world/world.json</code> and .glb chunks beside this page to view real data.";
|
|
else banner.classList.add("hidden");
|
|
for (const c of world.chunks) {
|
|
const b = c.bounds, box = new THREE.Box3(new THREE.Vector3(b[0], b[1], b[2]), new THREE.Vector3(b[3], b[4], b[5]));
|
|
boundsGroup.add(new THREE.Box3Helper(box, 0x5fb3ff));
|
|
}
|
|
const hud = document.getElementById("hud"), clock = new THREE.Clock();
|
|
let fpsT = 0, fpsN = 0, fps = 0;
|
|
const fwd = new THREE.Vector3(), right = new THREE.Vector3(), up = new THREE.Vector3(0, 1, 0);
|
|
renderer.setAnimationLoop(() => {
|
|
const dt = Math.min(clock.getDelta(), 0.1);
|
|
camera.quaternion.setFromEuler(new THREE.Euler(pitch, yaw, 0, "YXZ"));
|
|
camera.getWorldDirection(fwd); right.crossVectors(fwd, up).normalize();
|
|
const v = new THREE.Vector3(), s = speed * (keys.has("ShiftLeft") || keys.has("ShiftRight") ? 5 : 1) * (keys.has("ControlLeft") ? 0.2 : 1);
|
|
if (keys.has("KeyW")) v.add(fwd); if (keys.has("KeyS")) v.sub(fwd);
|
|
if (keys.has("KeyD")) v.add(right); if (keys.has("KeyA")) v.sub(right);
|
|
if (keys.has("KeyE")) v.y += 1; if (keys.has("KeyQ")) v.y -= 1;
|
|
if (v.lengthSq()) camera.position.addScaledVector(v.normalize(), s * dt);
|
|
stream();
|
|
renderer.render(scene, camera);
|
|
fpsN++; fpsT += dt; if (fpsT > 0.5) { fps = fpsN / fpsT; fpsN = 0; fpsT = 0; }
|
|
const p = camera.position, loaded = [...live.values()].filter(c => c.obj).length;
|
|
hud.innerHTML = `<b>${world.test ? "test terrain" : "world"}</b><br>pos ${p.x.toFixed(1)}, ${p.y.toFixed(1)}, ${p.z.toFixed(1)}<br>` +
|
|
`speed ${speed.toFixed(0)} m/s · ${fps.toFixed(0)} fps<br>chunks ${loaded}/${world.chunks.length} loaded, ${inflight} loading` +
|
|
(failed ? `, <span style="color:var(--warn)">${failed} failed</span>` : "") +
|
|
`<br>draw calls ${renderer.info.render.calls}, tris ${(renderer.info.render.triangles / 1000).toFixed(0)}k`;
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|