Files
space-game/apps/viewer/src/viewerGalaxyLayer.ts

43 lines
1.4 KiB
TypeScript

import * as THREE from "three";
import type { Selectable, SystemVisual } from "./viewerTypes";
/**
* Galaxy rendering layer — the galaxy map.
* Scene coordinate unit: display-unit (light-year scale).
* Only visible in galaxy POV, rendered on top of the universe backdrop.
* Contains star dots and shell reticles for each system.
*/
export class GalaxyLayer {
readonly scene = new THREE.Scene();
readonly camera = new THREE.PerspectiveCamera(50, 1, 0.1, 600000);
/** Star dots and shell reticles, one per system. */
readonly systemGroup = new THREE.Group();
readonly selectableTargets = new Map<THREE.Object3D, Selectable>();
readonly systemVisuals = new Map<string, SystemVisual>();
constructor() {
this.scene.fog = new THREE.FogExp2(0x040912, 0.000035);
this.scene.add(new THREE.AmbientLight(0x90a6c0, 0.55));
const keyLight = new THREE.DirectionalLight(0xdcecff, 1.3);
keyLight.position.set(1000, 1200, 800);
this.scene.add(keyLight);
this.scene.add(this.systemGroup);
}
updateCamera(focus: THREE.Vector3, orbitOffset: THREE.Vector3) {
this.camera.position.copy(focus).add(orbitOffset);
this.camera.lookAt(focus);
}
onResize(aspect: number) {
this.camera.aspect = aspect;
this.camera.updateProjectionMatrix();
}
render(renderer: THREE.WebGLRenderer) {
renderer.render(this.scene, this.camera);
}
}