feat: added a sun and earth orbiting it in r3f.

This commit is contained in:
anshk 2026-03-26 19:39:49 +05:30
parent a4044c47a3
commit 9f0f74617d
11 changed files with 1480 additions and 0 deletions

View File

@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@ -0,0 +1,16 @@
# React + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
## React Compiler
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
## Expanding the ESLint configuration
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.

View File

@ -0,0 +1,29 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import { defineConfig, globalIgnores } from 'eslint/config'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{js,jsx}'],
extends: [
js.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
rules: {
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
},
},
])

View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>solar-system</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>

View File

@ -0,0 +1,30 @@
{
"name": "solar-system",
"private": true,
"version": "0.0.0",
"type": "module",
"packageManager": "yarn@1.22.22",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@react-three/fiber": "^9.5.0",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"three": "^0.183.2"
},
"devDependencies": {
"@eslint/js": "^9.39.4",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.0",
"eslint": "^9.39.4",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.5.2",
"globals": "^17.4.0",
"vite": "^8.0.0"
}
}

View File

@ -0,0 +1,13 @@
import { Canvas } from '@react-three/fiber'
import SolarSystem from './SolarSystem'
function App() {
return (
<Canvas camera={{ position: [0, 4, 10], fov: 50 }}>
<color attach="background" args={['white']} />
<SolarSystem />
</Canvas>
)
}
export default App

View File

@ -0,0 +1,31 @@
import { useFrame } from '@react-three/fiber'
import { useRef } from 'react'
function SolarSystem() {
const orbitRef = useRef()
useFrame((_, delta) => {
orbitRef.current.rotation.y += delta * 0.8
})
return (
<>
<ambientLight intensity={0.2} />
<pointLight position={[0, 0, 0]} intensity={50} />
<mesh>
<sphereGeometry args={[1, 32, 32]} />
<meshStandardMaterial color="orange" emissive="orange" emissiveIntensity={2} />
<group ref={orbitRef}>
<mesh position={[6, 0, 0]}>
<sphereGeometry args={[0.4, 32, 32]} />
<meshStandardMaterial color="royalblue" />
</mesh>
</group>
</mesh>
</>
)
}
export default SolarSystem

View File

@ -0,0 +1,15 @@
* {
box-sizing: border-box;
}
html,
body,
#root {
margin: 0;
width: 100%;
height: 100%;
}
body {
overflow: hidden;
}

View File

@ -0,0 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>,
)

View File

@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
})

File diff suppressed because it is too large Load Diff