{"id":31770231,"url":"https://github.com/champi-dev/universesim","last_synced_at":"2025-10-10T02:58:41.990Z","repository":{"id":298068384,"uuid":"998738676","full_name":"champi-dev/universesim","owner":"champi-dev","description":"🌎","archived":false,"fork":false,"pushed_at":"2025-07-07T13:48:56.000Z","size":4297,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-19T02:42:38.363Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://universesim.lat","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/champi-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-09T07:06:24.000Z","updated_at":"2025-07-10T16:22:46.000Z","dependencies_parsed_at":"2025-06-09T08:40:56.749Z","dependency_job_id":"d9b9cc10-2dac-41a1-a8a2-1104e781add8","html_url":"https://github.com/champi-dev/universesim","commit_stats":null,"previous_names":["champi-dev/universesim"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/champi-dev/universesim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/champi-dev%2Funiversesim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/champi-dev%2Funiversesim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/champi-dev%2Funiversesim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/champi-dev%2Funiversesim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/champi-dev","download_url":"https://codeload.github.com/champi-dev/universesim/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/champi-dev%2Funiversesim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002522,"owners_count":26083404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-10T02:58:38.009Z","updated_at":"2025-10-10T02:58:41.984Z","avatar_url":"https://github.com/champi-dev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌌 Universe Simulation\n\n\u003e A powerful JavaScript library for creating interactive universe simulations with Three.js\n\n\u003e [Live Demo](https://universesim.vercel.app/) | [GitHub](https://github.com/champi-dev/universesim) | [NPM](https://www.npmjs.com/package/universe-simulation)\n\n![NPM Version](https://img.shields.io/npm/v/universe-simulation?style=for-the-badge)\n![NPM Downloads](https://img.shields.io/npm/dm/universe-simulation?style=for-the-badge)\n![License](https://img.shields.io/npm/l/universe-simulation?style=for-the-badge)\n![Three.js](https://img.shields.io/badge/Three.js-r178-black?style=for-the-badge\u0026logo=three.js\u0026logoColor=white)\n\n## 📦 Installation\n\n```bash\nnpm install universe-simulation\n```\n\n## 🚀 Quick Start\n\n```javascript\nimport UniverseSimulation from 'universe-simulation';\n\n// Create simulation instance\nconst universe = new UniverseSimulation({\n  container: document.getElementById('canvas-container'),\n  width: window.innerWidth,\n  height: window.innerHeight\n});\n\n// Initialize\nawait universe.init();\n\n// Add a sun\nawait universe.addSun({\n  radius: 10,\n  position: new THREE.Vector3(0, 0, 0)\n});\n\n// Add Earth\nawait universe.addPlanet({\n  name: 'earth',\n  radius: 1,\n  distance: 50,\n  speed: 0.001,\n  color: 0x2233ff\n});\n\n// Start the simulation\nuniverse.start();\n```\n\n## 🎯 Features\n\n- **🌟 Full Universe Scale**: From planetary surfaces to the edge of the observable universe\n- **⚡ High Performance**: Optimized with Nanite-like LOD system and Web Workers\n- **🎨 Stunning Visuals**: JWST-inspired nebulae, HDR rendering, custom shaders\n- **📱 Mobile Ready**: Touch controls and performance optimizations\n- **🔧 Fully Customizable**: Complete API control over all simulation aspects\n\n## 📖 API Documentation\n\n### Core Class: `UniverseSimulation`\n\n#### Constructor Options\n\n```javascript\nconst universe = new UniverseSimulation({\n  container: HTMLElement,     // DOM element to render to (default: document.body)\n  width: Number,             // Canvas width (default: window.innerWidth)\n  height: Number,            // Canvas height (default: window.innerHeight)\n  mobile: Boolean,           // Force mobile mode (auto-detected by default)\n  renderOptions: {           // Additional Three.js renderer options\n    antialias: Boolean,\n    logarithmicDepthBuffer: Boolean\n  }\n});\n```\n\n#### Methods\n\n##### `async init()`\nInitialize the simulation. Must be called before adding any objects.\n\n```javascript\nawait universe.init();\n```\n\n##### `async addSun(options)`\nAdd a star to the simulation.\n\n```javascript\nawait universe.addSun({\n  name: 'sol',                          // Unique identifier\n  position: new THREE.Vector3(0, 0, 0), // Position in space\n  radius: 10,                           // Size of the sun\n  color: STAR_COLORS['G'],              // Star color (G-type by default)\n  intensity: 3                          // Light intensity\n});\n```\n\n##### `async addPlanet(options)`\nAdd a planet to the simulation.\n\n```javascript\nawait universe.addPlanet({\n  name: 'earth',\n  radius: 1,\n  distance: 50,        // Orbital distance from center\n  speed: 0.001,        // Orbital speed\n  texture: null,       // THREE.Texture for planet surface\n  color: 0x4444ff      // Color if no texture provided\n});\n```\n\n##### `async addGalaxy(options)`\nAdd a galaxy to the simulation.\n\n```javascript\nawait universe.addGalaxy({\n  name: 'andromeda',\n  position: new THREE.Vector3(1000, 0, 0),\n  type: 'spiral',      // 'spiral', 'elliptical', or 'irregular'\n  scale: 1,\n  starCount: 50000     // Number of stars (auto-reduced on mobile)\n});\n```\n\n##### `addNebula(options)`\nAdd a nebula with JWST-inspired visuals.\n\n```javascript\nuniverse.addNebula({\n  name: 'orion',\n  position: new THREE.Vector3(100, 50, -200),\n  scale: 100,\n  type: 'emission'     // Visual style preset\n});\n```\n\n##### `createObservableUniverse()`\nGenerate the entire observable universe with galaxies, clusters, and cosmic web.\n\n```javascript\nuniverse.createObservableUniverse();\n```\n\n##### `focusOn(name, options)`\nSmoothly focus the camera on a celestial object.\n\n```javascript\nuniverse.focusOn('earth', {\n  distance: 10,        // Distance from object\n  duration: 2000       // Animation duration in ms\n});\n```\n\n##### `start()` / `stop()`\nControl simulation playback.\n\n```javascript\nuniverse.start();  // Begin animation loop\nuniverse.stop();   // Pause animation loop\n```\n\n##### `togglePause()`\nToggle simulation pause state.\n\n```javascript\nconst isPaused = universe.togglePause();\n```\n\n##### `setTimeScale(scale)`\nControl simulation speed.\n\n```javascript\nuniverse.setTimeScale(10);  // 10x speed\n```\n\n##### `resize(width, height)`\nHandle window resizing.\n\n```javascript\nwindow.addEventListener('resize', () =\u003e {\n  universe.resize(window.innerWidth, window.innerHeight);\n});\n```\n\n##### `dispose()`\nClean up all resources.\n\n```javascript\nuniverse.dispose();\n```\n\n##### `getInternals()`\nAccess Three.js internals for advanced usage.\n\n```javascript\nconst { scene, camera, renderer, THREE } = universe.getInternals();\n```\n\n## 🎨 Visual Constants\n\n### Star Colors\n```javascript\nimport { STAR_COLORS } from 'universe-simulation';\n\n// Available star types\nSTAR_COLORS['O']  // Blue\nSTAR_COLORS['B']  // Blue-white\nSTAR_COLORS['A']  // White\nSTAR_COLORS['F']  // Yellow-white\nSTAR_COLORS['G']  // Yellow (Sun-like)\nSTAR_COLORS['K']  // Orange\nSTAR_COLORS['M']  // Red\n```\n\n### Nebula Colors\n```javascript\nimport { NEBULA_COLORS } from 'universe-simulation';\n\n// Emission, reflection, and other nebula color presets\n```\n\n## 📚 Examples\n\n### Complete Solar System\n\n```javascript\nimport UniverseSimulation, { AU_SCALE } from 'universe-simulation';\n\nasync function createSolarSystem() {\n  const universe = new UniverseSimulation({\n    container: document.getElementById('universe')\n  });\n  \n  await universe.init();\n  \n  // Add Sun\n  await universe.addSun({\n    name: 'sun',\n    radius: 10\n  });\n  \n  // Add planets\n  const planets = [\n    { name: 'mercury', radius: 0.4, distance: 0.39 * AU_SCALE, speed: 0.002 },\n    { name: 'venus', radius: 0.9, distance: 0.72 * AU_SCALE, speed: 0.0015 },\n    { name: 'earth', radius: 1, distance: 1 * AU_SCALE, speed: 0.001 },\n    { name: 'mars', radius: 0.5, distance: 1.52 * AU_SCALE, speed: 0.0008 },\n    { name: 'jupiter', radius: 11, distance: 5.2 * AU_SCALE, speed: 0.0004 },\n    { name: 'saturn', radius: 9, distance: 9.5 * AU_SCALE, speed: 0.0003 },\n    { name: 'uranus', radius: 4, distance: 19.2 * AU_SCALE, speed: 0.0002 },\n    { name: 'neptune', radius: 3.8, distance: 30 * AU_SCALE, speed: 0.0001 }\n  ];\n  \n  for (const planet of planets) {\n    await universe.addPlanet(planet);\n  }\n  \n  universe.start();\n  \n  // Focus on Earth after 2 seconds\n  setTimeout(() =\u003e {\n    universe.focusOn('earth', { distance: 20 });\n  }, 2000);\n}\n\ncreateSolarSystem();\n```\n\n### Galaxy Cluster Visualization\n\n```javascript\nasync function createGalaxyCluster() {\n  const universe = new UniverseSimulation();\n  await universe.init();\n  \n  // Create multiple galaxies\n  for (let i = 0; i \u003c 10; i++) {\n    const angle = (i / 10) * Math.PI * 2;\n    const distance = 5000 + Math.random() * 5000;\n    \n    await universe.addGalaxy({\n      name: `galaxy-${i}`,\n      position: new THREE.Vector3(\n        Math.cos(angle) * distance,\n        (Math.random() - 0.5) * 1000,\n        Math.sin(angle) * distance\n      ),\n      type: ['spiral', 'elliptical', 'irregular'][Math.floor(Math.random() * 3)],\n      scale: 0.5 + Math.random() * 1.5\n    });\n  }\n  \n  universe.start();\n}\n```\n\n### Using with React\n\n```javascript\nimport React, { useEffect, useRef } from 'react';\nimport UniverseSimulation from 'universe-simulation';\n\nfunction UniverseComponent() {\n  const containerRef = useRef();\n  const universeRef = useRef();\n  \n  useEffect(() =\u003e {\n    async function init() {\n      const universe = new UniverseSimulation({\n        container: containerRef.current\n      });\n      \n      await universe.init();\n      await universe.addSun();\n      await universe.addPlanet({ name: 'earth', distance: 50 });\n      \n      universe.start();\n      universeRef.current = universe;\n    }\n    \n    init();\n    \n    return () =\u003e {\n      if (universeRef.current) {\n        universeRef.current.dispose();\n      }\n    };\n  }, []);\n  \n  return \u003cdiv ref={containerRef} style={{ width: '100vw', height: '100vh' }} /\u003e;\n}\n```\n\n## 🎮 Controls\n\nThe simulation includes built-in navigation controls:\n\n### Desktop\n- **WASD** - Movement\n- **Mouse** - Look around\n- **Space/Shift** - Up/Down\n- **Scroll** - Adjust speed\n\n### Mobile\n- **Touch** - Look around\n- **Pinch** - Zoom\n- **Double tap** - Move forward\n\n## ⚡ Performance Optimization\n\n### Nanite-like LOD System\nThe library includes an advanced LOD system that automatically adjusts object detail based on distance.\n\n### Web Workers\nHeavy computations are offloaded to Web Workers for smooth performance.\n\n### Mobile Optimization\n```javascript\n// The library automatically detects and optimizes for mobile\nconst universe = new UniverseSimulation({\n  mobile: true  // Force mobile optimizations\n});\n```\n\n## 🛠️ Advanced Usage\n\n### Custom Shaders\n```javascript\nconst customMaterial = new THREE.ShaderMaterial({\n  uniforms: {\n    time: { value: 0 },\n    color: { value: new THREE.Color(0xff0000) }\n  },\n  vertexShader: `...`,\n  fragmentShader: `...`\n});\n\nawait universe.addPlanet({\n  name: 'custom-planet',\n  radius: 2,\n  distance: 100,\n  material: customMaterial  // Use custom material\n});\n```\n\n### Accessing Three.js\n```javascript\nconst { scene, camera, renderer, THREE } = universe.getInternals();\n\n// Add custom objects directly\nconst customMesh = new THREE.Mesh(\n  new THREE.BoxGeometry(1, 1, 1),\n  new THREE.MeshBasicMaterial({ color: 0xff0000 })\n);\nscene.add(customMesh);\n```\n\n## 🛠️ Development\n\n### Clone the repository\n```bash\ngit clone https://github.com/champi-dev/universesim.git\ncd universesim\nnpm install\n```\n\n### Run the demo locally\n```bash\nnpm start\n```\n\n### Build the library\n```bash\nnpm run build:lib\n```\n\n## 📄 License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request to the [GitHub repository](https://github.com/champi-dev/universesim).\n\n## 🐛 Issues\n\nFound a bug or have a feature request? Please open an issue on [GitHub](https://github.com/champi-dev/universesim/issues).\n\n## 🙏 Acknowledgments\n\n- NASA for astronomical data\n- Three.js community\n- JWST team for visual inspiration\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\n**Build your own universe, one star at a time** ⭐\n\n\u003c/div\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchampi-dev%2Funiversesim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchampi-dev%2Funiversesim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchampi-dev%2Funiversesim/lists"}