/** * Main 3D Scene component */ import { Canvas } from '@react-three/fiber'; import { OrbitControls, Stars as BackgroundStars } from '@react-three/drei'; import { useMemo } from 'react'; import { CelestialBody } from './CelestialBody'; import { Probe } from './Probe'; import { CameraController } from './CameraController'; import { Trajectory } from './Trajectory'; import { Orbit } from './Orbit'; import { Stars } from './Stars'; import { Constellations } from './Constellations'; import { Galaxies } from './Galaxies'; import { scalePosition } from '../utils/scaleDistance'; import type { CelestialBody as CelestialBodyType, Position } from '../types'; interface SceneProps { bodies: CelestialBodyType[]; selectedBody: CelestialBodyType | null; trajectoryPositions?: Position[]; } export function Scene({ bodies, selectedBody, trajectoryPositions = [] }: SceneProps) { // Separate planets/stars from probes const planets = bodies.filter((b) => b.type !== 'probe'); const probes = bodies.filter((b) => b.type === 'probe'); // Filter probes to display based on focus const visibleProbes = selectedBody?.type === 'probe' ? probes.filter((p) => p.id === selectedBody.id) // Only show focused probe : []; // In overview mode, hide all probes // Calculate target position for OrbitControls const controlsTarget = useMemo(() => { if (selectedBody) { const pos = selectedBody.positions[0]; const scaledPos = scalePosition(pos.x, pos.y, pos.z); return [scaledPos.x, scaledPos.z, scaledPos.y] as [number, number, number]; } return [0, 0, 0] as [number, number, number]; }, [selectedBody]); return (
{ gl.sortObjects = true; // Enable object sorting by renderOrder camera.lookAt(0, 0, 0); // Look at the Sun (center) }} > {/* Camera controller for smooth transitions */} {/* Increase ambient light to see textures better */} {/* Additional directional light to illuminate planets */} {/* Stars background (procedural) */} {/* Nearby stars (real data) */} {/* Major constellations */} {/* Distant galaxies */} {/* Render planets and stars */} {planets.map((body) => ( ))} {/* Render planet orbits */} {planets.map((body) => { const pos = body.positions[0]; const distance = Math.sqrt(pos.x ** 2 + pos.y ** 2 + pos.z ** 2); // Only render orbits for planets (not Sun or Moon) // Moon is too close to Earth, skip its orbit if (body.type === 'planet' && distance > 0.1 && body.name !== 'Moon') { return ; } return null; })} {/* Render visible probes with 3D models */} {visibleProbes.map((body) => ( ))} {/* Render trajectory for selected probe */} {selectedBody?.type === 'probe' && trajectoryPositions.length > 1 && ( )} {/* Camera controls */}
); }