How mgvez/jsorrery works
Based on our analysis of the file tree and the README, jsOrrery is a WebGL/JavaScript-based simulation that models the solar system with accurate orbital mechanics. The project is primarily a client-side application which renders a dynamic orrery (a mechanical model of the solar system) through computed positions of the planets and moons based on real date inputs.
Main Components
• Simulation/Core Engine:
• This consists of the code in the “src/core” folder (including Universe, CelestialBody, and constants) that drives the simulation's state.
• The “src/algorithm” directory (Gravity, MoveAlgorithm, OrbitalElements, Quadratic, Ticker) handles the mathematical and physics-based calculations required to update positions.
• Graphics/Rendering Modules:
• The rendering is split between “src/graphics2d” and “src/graphics3d”. These modules manage drawing labels, orbits, 3D bodies, cameras, particles (MilkyWayParticles) and related visual effects.
• Assets (shaders, images, data files) and “src/three” (custom Three.js classes, like RingGeometry2) support the WebGL-based rendering pipeline.
• User Interface (GUI):
• Found in “src/gui”, this component offers interactive features such as input fields, buttons, sliders, and date pickers that allow configuration of the simulation. It also includes auxiliary modules like ExportValues and Preloader.
• Scenario Management:
• The “src/scenario” folder includes a loader and multiple pre-defined simulation scenarios (for the Solar System, Apollo missions, satellite simulations, etc.), plus scenario-specific data and additional celestial body definitions.
• Resource Loading and Utilities:
• “src/loaders” (ResourceLoader) is responsible for asynchronously loading assets and initializing resources.
Recognize Build/Deployment Components
• The build process is managed through webpack (webpack.config.js) with configurations that compile the source into the “dist” directory.
• The “package.json” file indicates dependencies and scripts (like npm start for local development) and “server.js” suggests there’s a lightweight local server for development or testing.
Interactions Between Components
• The simulation engine (core and algorithm) feeds computed positions and orbital data to the rendering modules.
• The rendering modules, using Three.js and WebGL, display the simulation visually; they interact with shader files (stated in “assets/shaders”) to achieve specific visual effects.
• The GUI collects user input which allows dynamic control (e.g., changing dates or simulation parameters) modifying the simulation engine’s behavior.
• Scenario management modules load predefined configurations that set up initial states for the simulation engine.
• The resource loader ensures that all required assets (from “assets/data”, images, and shader files) are available before initializing the simulation.
Key Architectural Patterns/Design Principles
• Separation of Concerns – Different directories handle simulation logic, rendering (2D/3D), GUI, and scenario configurations, reflecting a modular structure.
• Data Flow – The simulation calculates positions (via the algorithm modules) which then get rendered in 3D/2D; the GUI and scenarios serve as configuration layers that modify this behavior.
• Use of External Technologies – WebGL (for rendering), Three.js (for 3D graphics and camera handling), and webpack (for build automation) are central to the architecture.