feat: added a sun and earth orbiting it in r3f.
This commit is contained in:
parent
a4044c47a3
commit
9f0f74617d
24
Week-1/Task-1/r3f/solar-system/.gitignore
vendored
Normal file
24
Week-1/Task-1/r3f/solar-system/.gitignore
vendored
Normal 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?
|
||||
16
Week-1/Task-1/r3f/solar-system/README.md
Normal file
16
Week-1/Task-1/r3f/solar-system/README.md
Normal 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.
|
||||
29
Week-1/Task-1/r3f/solar-system/eslint.config.js
Normal file
29
Week-1/Task-1/r3f/solar-system/eslint.config.js
Normal 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_]' }],
|
||||
},
|
||||
},
|
||||
])
|
||||
13
Week-1/Task-1/r3f/solar-system/index.html
Normal file
13
Week-1/Task-1/r3f/solar-system/index.html
Normal 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>
|
||||
30
Week-1/Task-1/r3f/solar-system/package.json
Normal file
30
Week-1/Task-1/r3f/solar-system/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
13
Week-1/Task-1/r3f/solar-system/src/App.jsx
Normal file
13
Week-1/Task-1/r3f/solar-system/src/App.jsx
Normal 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
|
||||
31
Week-1/Task-1/r3f/solar-system/src/SolarSystem.jsx
Normal file
31
Week-1/Task-1/r3f/solar-system/src/SolarSystem.jsx
Normal 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
|
||||
15
Week-1/Task-1/r3f/solar-system/src/index.css
Normal file
15
Week-1/Task-1/r3f/solar-system/src/index.css
Normal file
@ -0,0 +1,15 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
#root {
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
overflow: hidden;
|
||||
}
|
||||
10
Week-1/Task-1/r3f/solar-system/src/main.jsx
Normal file
10
Week-1/Task-1/r3f/solar-system/src/main.jsx
Normal 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>,
|
||||
)
|
||||
7
Week-1/Task-1/r3f/solar-system/vite.config.js
Normal file
7
Week-1/Task-1/r3f/solar-system/vite.config.js
Normal file
@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
||||
1292
Week-1/Task-1/r3f/solar-system/yarn.lock
Normal file
1292
Week-1/Task-1/r3f/solar-system/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user