I will start by installing the necessary dependencies, including three, @types/three, and lucide-react for the HUD icons.
I will now create the directory structure for the components and then proceed to implement the solar system simulation logic and the 3D rendering.
I'll start by creating a utility for class merging if it doesn't already exist in a standard way, then I'll move on to create the Solar System components. I'll create a SolarSystem component that handles the Three.js scene and a HUD component for controls.
First, let's create the src/components directory and the main solar system logic.
Now, I'll create a constants.ts file to store planet data like orbital radius, speed, size, and colors.
Now I will implement the main SolarSystem engine using Three.js in src/components/SolarSystem.tsx.
I'll fix the lint error and then implement the HUD component. The HUD will allow users to control the speed of time, toggle orbit visibility, and display information about the selected planet.
First, let's fix the lint error in SolarSystem.tsx.
Now, I'll create the HUD component in src/components/HUD.tsx.
Now I'll update src/App.tsx to integrate both the SolarSystem and the HUD components.
I'll fix the lint error in App.tsx and also update index.html to have a better title.
Now update the index.html title.
Ah, I should check the content of index.html first.
Okay, it's "Arena Web Dev App". Fixing it now.
Now I'll add some CSS to index.css to handle the slider and global styles for the HUD.
I'll read src/index.css to see the current content.
Ah, it uses the new Tailwind v4 import. I'll append my styles.
I'll add a few more details to the SolarSystem to make it more realistic, such as rotating the planets and adding a sun flare. I've already added the sun flare, but I can improve the materials and lighting.
Let's double check if I can improve the textures or at least add a texture-like effect with standard Three.js shaders or simple patterns. Since I cannot easily upload images, I'll stick to beautiful colors and materials.
One thing I can improve is the planet movement. I used elapsed * speed which is okay, but I should ensure it's frame-rate independent by using the delta correctly if I want to allow pause/play smoothly.
Actually, the current implementation is:
const angle = elapsed * (data.speed * 0.1) * timeScale;
This is fine for "current position" based on absolute time.
I will add a PointLight helper if needed, but the current point light is at the center (0,0,0) which is correct for the sun.
Let's refine the SolarSystem.tsx to include planetary tilt and more varied appearance.
Wait, I need to update the animation loop as well because I changed the structure from group.position.x = ... to a pivot rotation.
Currently the animation loop is:
planetGroups.forEach((group, index) => {
const data = PLANETS[index];
const angle = elapsed * (data.speed * 0.1) * timeScale;
group.position.x = Math.cos(angle) * data.distance;
group.position.z = Math.sin(angle) * data.distance;
// Rotate planet itself
group.children[0].rotation.y += delta * 0.5;
});
I'll change it to:
planetGroups.forEach((pivot, index) => {
const data = PLANETS[index];
pivot.rotation.y += delta * (data.speed * 0.05) * timeScale;
// Rotate planet itself (the group inside the pivot)
const group = pivot.children[0];
group.children[0].rotation.y += delta * 0.5;
});
Let's update the animation loop and also fix the selection logic.
I need to update the raycaster intersection logic because the structure changed.
In the click handler:
if (intersects.length > 0) {
const object = intersects[0].object;
const planetData = PLANETS.find(p => p.name === object.name || (object.parent && object.parent.children[0].name === p.name));
if (planetData) {
onPlanetSelect(planetData);
}
}
This should still work since planet.name = data.name is set on the mesh.
One more thing: the sun could use a better material. Let's use a emissive material and a glow.
I'll also add a "Focus" feature when a planet is clicked, so the camera moves towards it. But for now, just selecting it in the HUD is good. I'll add a simple camera focus if I have time.
Let's refine the HUD and add some polish. I'll also check if the orbits are drawn correctly. They were using absolute world coordinates which is fine as they are static.
Wait, the orbits are:
for (let i = 0; i <= 100; i++) {
const angle = (i / 100) * Math.PI * 2;
orbitPoints.push(new THREE.Vector3(Math.cos(angle) * data.distance, 0, Math.sin(angle) * data.distance));
}
This is correct.
Let's improve the sun's appearance and the orbit material.
Actually, the custom shader for the sun glow might be a bit overkill and might fail if not handled correctly (e.g. viewVector not updated). I'll simplify the sun glow to use a simple sprite or a basic mesh with additive blending.
Also, I should make sure the camera position is updated in the shader if I use it. I'll stick to a simpler version to avoid issues.
And I'll add a Bloom-like effect using just standard Three.js if possible, or just very bright emissive materials.
Let's fix the sun glow and add some more stars.
I'll finish by building the project to ensure everything is correct.
The project built successfully. I have created a beautiful solar system simulation with:
- Realistic orbital motion with adjustable time speed.
- Interactive HUD with modern design (using Framer Motion, Tailwind, and Lucide icons).
- Planetary data display when clicking on planets.
- Toggleable orbit lines.
- Stars and a glowing sun.
- Fully responsive 3D environment using Three.js.
I'll do one last check on the HUD to make sure it's fully functional. The setTimeScale, setShowOrbits, and setSelectedPlanet are all wired up in App.tsx and used in HUD.tsx. The SolarSystem component responds to timeScale and showOrbits through props.
One final touch: I'll make sure the index.html has a dark background to prevent flickering during load.
I'll just leave it as it is since index.css already sets the body background to black and the build was successful.
final summary:
src/constants.ts: Planet data.
src/utils/cn.ts: Utility for Tailwind class merging.
src/components/SolarSystem.tsx: Three.js engine.
src/components/HUD.tsx: React-based control panel.
src/App.tsx: Main application entry point.
src/index.css: Global styles and Tailwind imports.
The simulation is ready.
I have completed the task.
- Solar System Simulation: Built with Three.js, featuring a glowing sun, 8 planets with their respective sizes, colors, and orbital distances, and Saturn's rings.
- Dynamic Motion: Planets orbit at realistic relative speeds, and the simulation speed can be adjusted via a "Time Warp" slider or preset buttons (Pause, Play, Fast Forward).
- Interactive HUD: A modern, glassmorphism-styled interface built with Tailwind CSS and Framer Motion. It allows users to toggle orbits, control time, and view detailed information about each planet by clicking on them.
- Beautiful Visuals: Includes a starfield background, cinematic vignette, and smooth transitions.
- Responsive Design: The 3D canvas and UI automatically adjust to different screen sizes.
The application is fully functional and ready to be explored.
Files built: src/utils/cn.ts, src/constants.ts, src/components/SolarSystem.tsx, src/components/HUD.tsx, src/App.tsx, index.html, src/index.css