This document provides comprehensive API documentation for the PLANETARY 3D Solar System Visualization project.
- Core Classes
- Celestial Bodies
- Physics System
- Rendering System
- Utilities
- Event System
- Configuration Options
Main application controller that orchestrates all subsystems.
import { Engine } from './src/core/Engine.js';const engine = new Engine(options);Parameters:
options(Object) - Configuration optionscontainer(HTMLElement) - DOM container for the 3D canvasenablePhysics(boolean) - Enable N-body physics simulation (default:true)timeAcceleration(number) - Time acceleration factor (default:1)physics(Object) - Physics configurationrendering(Object) - Rendering configurationcamera(Object) - Camera configuration
Starts the simulation and rendering loop.
engine.start();Pauses the simulation.
engine.pause();Resumes a paused simulation.
engine.resume();Sets the time acceleration factor.
engine.setTimeAcceleration(1000); // 1000x real-timeParameters:
factor(number) - Time acceleration multiplier
Adds a celestial body to the simulation.
engine.addBody(celestialBody);Parameters:
body(CelestialBody) - The celestial body to add
Returns current performance metrics.
const metrics = engine.getPerformanceMetrics();
// { fps: 60, memoryUsage: 45.2, drawCalls: 123 }Manages collections of celestial bodies and their interactions.
import { SolarSystem } from './src/celestial/SolarSystem.js';const solarSystem = new SolarSystem(options);Parameters:
options(Object) - Configuration optionsenablePhysics(boolean) - Enable N-body physics (default:true)timeStep(number) - Physics time step in seconds (default:3600)
Loads the default solar system bodies (Sun, planets, moons).
await solarSystem.loadDefaultBodies();Returns: Promise that resolves when all bodies are loaded.
Adds a celestial body to the system.
solarSystem.addBody(celestialBody);Removes a celestial body by ID.
solarSystem.removeBody('earth');Retrieves a celestial body by ID.
const earth = solarSystem.getBody('earth');Retrieves all bodies of a specific type.
const planets = solarSystem.getBodiesByType('planet');
const moons = solarSystem.getBodiesByType('moon');Updates all celestial bodies and their physics.
solarSystem.update(deltaTime);Base class for all astronomical objects.
import { CelestialBody } from './src/celestial/CelestialBody.js';const body = new CelestialBody(options);Parameters:
options(Object) - Body configurationname(string) - Body namemass(number) - Mass in kilogramsradius(number) - Radius in metersposition(Object) - Initial position{x, y, z}in metersvelocity(Object) - Initial velocity{x, y, z}in m/scolor(number) - Body color (hex)texture(string) - Texture URL (optional)
id(string) - Unique identifiername(string) - Display nametype(string) - Body type ('star', 'planet', 'moon', etc.)mass(number) - Mass in kgradius(number) - Radius in metersposition(Object) - Current position{x, y, z}velocity(Object) - Current velocity{x, y, z}acceleration(Object) - Current acceleration{x, y, z}
Updates the body's physics and rendering.
body.update(deltaTime, true); // Use N-body physicsCalculates gravitational force with another body.
const force = body.calculateGravitationalForce(otherBody);Calculates distance to another body.
const distance = earth.getDistanceTo(moon);Represents a planet with additional planetary properties.
import { Planet } from './src/celestial/Planet.js';const planet = new Planet(options);Additional Properties:
albedo(number) - Surface reflectivity (0-1)surfaceTemperature(number) - Surface temperature in Kelvinatmosphere(Object) - Atmospheric propertiesmoons(Array) - Array of moon objects
Adds a moon to the planet.
planet.addMoon(moonObject);Removes a moon by ID.
planet.removeMoon('luna');Determines if the planet is in its star's habitable zone.
const habitable = planet.isInHabitableZone();Represents a star with stellar properties.
import { Star } from './src/celestial/Star.js';luminosity(number) - Luminosity in wattstemperature(number) - Surface temperature in KelvinspectralClass(string) - Spectral classification (O, B, A, F, G, K, M)stellarClass(string) - Stellar classification
Calculates the habitable zone boundaries.
const hz = star.getHabitableZone();
// { inner: 1.4e11, outer: 1.6e11 } // in metersRepresents an asteroid with specific asteroid properties.
import { Asteroid } from './src/celestial/Asteroid.js';orbitalClass(string) - Orbital classificationcomposition(Object) - Compositional datarotationPeriod(number) - Rotation period in seconds
Determines if the asteroid is potentially hazardous to Earth.
const hazardous = asteroid.isPotentiallyHazardous();Handles N-body gravitational physics integration.
import { NBodyIntegrator } from './src/physics/NBodyIntegrator.js';const integrator = new NBodyIntegrator(config);Parameters:
config(Object) - Integration configurationG(number) - Gravitational constant (default:6.67430e-11)softening(number) - Softening parameter (default:1e6)method(string) - Integration method ('euler', 'rk4', 'verlet')
Adds a body to the integration system.
integrator.addBody(celestialBody);Performs one integration step.
const updatedBodies = integrator.integrate(bodies, deltaTime);Handles Keplerian orbital mechanics calculations.
import { KeplerianOrbit } from './src/physics/KeplerianOrbit.js';const orbit = new KeplerianOrbit(elements);Parameters:
elements(Object) - Orbital elementssemiMajorAxis(number) - Semi-major axis in meterseccentricity(number) - Orbital eccentricityinclination(number) - Inclination in radianslongitudeOfAscendingNode(number) - LOAN in radiansargumentOfPeriapsis(number) - Argument of periapsis in radiansmeanAnomalyAtEpoch(number) - Mean anomaly at epoch in radiansepoch(Date) - Epoch time
Calculates position at a given time.
const position = orbit.getPositionAtTime(new Date());Calculates velocity at a given time.
const velocity = orbit.getVelocityAtTime(new Date());Manages 3D rendering operations.
import { RenderingManager } from './src/rendering/RenderingManager.js';Sets rendering quality level.
renderer.setQuality('high'); // 'low', 'medium', 'high', 'ultra'Enables or disables shadow rendering.
renderer.enableShadows(true);Provides event handling capabilities.
import { EventSystem } from './src/utils/EventSystem.js';Registers an event listener.
eventSystem.on('bodySelected', (body) => {
console.log('Selected:', body.name);
});Emits an event.
eventSystem.emit('bodySelected', celestialBody);Removes an event listener.
eventSystem.off('bodySelected', callback);Monitors application performance.
import { PerformanceMonitor } from './src/utils/PerformanceMonitor.js';Starts performance monitoring.
monitor.start();Returns current performance metrics.
const metrics = monitor.getMetrics();
// { fps: 60, memoryUsage: 45.2, frameTime: 16.7 }const engine = new Engine({
container: document.getElementById('app'),
// Physics settings
physics: {
integrator: 'rk4', // Integration method
timeStep: 3600, // Time step in seconds
enablePerturbations: true, // Include orbital perturbations
softening: 1e6, // Gravitational softening
useRelativistic: false // Relativistic effects
},
// Rendering settings
rendering: {
antialias: true, // Anti-aliasing
shadows: true, // Shadow rendering
postProcessing: true, // Post-processing effects
quality: 'high', // Quality level
maxObjects: 10000, // Maximum rendered objects
lodDistances: { // Level of detail distances
high: 5, // AU
medium: 20,
low: 100
}
},
// Camera settings
camera: {
mode: 'orbit', // Camera mode
target: 'earth', // Target object
distance: 10, // Distance in AU
fov: 60, // Field of view
near: 0.1, // Near clipping plane
far: 1e15 // Far clipping plane
},
// Performance settings
performance: {
adaptiveQuality: true, // Adaptive quality adjustment
targetFPS: 60, // Target frame rate
memoryLimit: 1024, // Memory limit in MB
enableWorkers: true // Use web workers
}
});// Time acceleration factors
const timeFactors = {
REAL_TIME: 1,
MINUTE_PER_SECOND: 60,
HOUR_PER_SECOND: 3600,
DAY_PER_SECOND: 86400,
WEEK_PER_SECOND: 604800,
MONTH_PER_SECOND: 2592000,
YEAR_PER_SECOND: 31536000
};
engine.setTimeAcceleration(timeFactors.DAY_PER_SECOND);const qualityLevels = {
LOW: {
textureSize: 512,
shadows: false,
postProcessing: false,
antialiasing: false,
particleCount: 100
},
MEDIUM: {
textureSize: 1024,
shadows: true,
postProcessing: false,
antialiasing: true,
particleCount: 500
},
HIGH: {
textureSize: 2048,
shadows: true,
postProcessing: true,
antialiasing: true,
particleCount: 1000
},
ULTRA: {
textureSize: 4096,
shadows: true,
postProcessing: true,
antialiasing: true,
particleCount: 2000
}
};All API methods that can fail return promises or throw descriptive errors:
try {
await solarSystem.loadDefaultBodies();
engine.start();
} catch (error) {
console.error('Failed to initialize:', error.message);
}The system emits various events for different states:
// Body selection
engine.on('bodySelected', (body) => {
console.log('Selected body:', body.name);
});
// Performance warnings
engine.on('performanceWarning', (metrics) => {
console.warn('Performance issue:', metrics);
});
// Simulation state changes
engine.on('simulationPaused', () => {
console.log('Simulation paused');
});
engine.on('simulationResumed', () => {
console.log('Simulation resumed');
});For TypeScript users, type definitions are available:
interface CelestialBodyOptions {
name: string;
mass: number;
radius: number;
position: Vector3;
velocity: Vector3;
color?: number;
texture?: string;
}
interface Vector3 {
x: number;
y: number;
z: number;
}
interface OrbitalElements {
semiMajorAxis: number;
eccentricity: number;
inclination: number;
longitudeOfAscendingNode: number;
argumentOfPeriapsis: number;
meanAnomalyAtEpoch: number;
epoch: Date;
}For more examples and advanced usage, see the examples/ directory.