feat: added Basic Rotation / Motion for r3f in task4
This commit is contained in:
parent
d9fb575564
commit
8571b300b9
15
Week-1/Task-4/r3f/index.html
Normal file
15
Week-1/Task-4/r3f/index.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Task 4 R3F - Vanilla Match</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.jsx"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@ -2,11 +2,23 @@
|
|||||||
"name": "week-1-task-4-r3f",
|
"name": "week-1-task-4-r3f",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
"packageManager": "yarn@1.22.22",
|
"packageManager": "yarn@1.22.22",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "echo 'Add your React Three Fiber dev script here'",
|
"dev": "vite",
|
||||||
"build": "echo 'Add your React Three Fiber build script here'",
|
"build": "vite build",
|
||||||
"lint": "echo 'Add your lint script here'",
|
"lint": "echo 'Lint not configured yet'",
|
||||||
|
"preview": "vite preview",
|
||||||
"clean": "rm -rf dist build .next"
|
"clean": "rm -rf dist build .next"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@react-three/fiber": "^9.5.0",
|
||||||
|
"react": "^19.2.4",
|
||||||
|
"react-dom": "^19.2.4",
|
||||||
|
"three": "^0.183.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@vitejs/plugin-react": "^6.0.0",
|
||||||
|
"vite": "^8.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
30
Week-1/Task-4/r3f/src/App.jsx
Normal file
30
Week-1/Task-4/r3f/src/App.jsx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { Canvas, useFrame } from '@react-three/fiber'
|
||||||
|
import { useRef } from 'react'
|
||||||
|
|
||||||
|
function RotatingCube() {
|
||||||
|
const cubeRef = useRef()
|
||||||
|
|
||||||
|
useFrame((state) => {
|
||||||
|
const seconds = state.clock.elapsedTime
|
||||||
|
|
||||||
|
if (!cubeRef.current) return
|
||||||
|
|
||||||
|
cubeRef.current.rotation.x = seconds / 2
|
||||||
|
cubeRef.current.rotation.y = seconds
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<mesh ref={cubeRef}>
|
||||||
|
<boxGeometry args={[1, 1, 1]} />
|
||||||
|
<meshBasicMaterial color={0x00ff00} />
|
||||||
|
</mesh>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
return (
|
||||||
|
<Canvas camera={{ fov: 75, near: 0.1, far: 1000, position: [0, 0, 5] }}>
|
||||||
|
<RotatingCube />
|
||||||
|
</Canvas>
|
||||||
|
)
|
||||||
|
}
|
||||||
10
Week-1/Task-4/r3f/src/main.jsx
Normal file
10
Week-1/Task-4/r3f/src/main.jsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { StrictMode } from 'react'
|
||||||
|
import { createRoot } from 'react-dom/client'
|
||||||
|
import App from './App.jsx'
|
||||||
|
import './index.css'
|
||||||
|
|
||||||
|
createRoot(document.getElementById('root')).render(
|
||||||
|
<StrictMode>
|
||||||
|
<App />
|
||||||
|
</StrictMode>,
|
||||||
|
)
|
||||||
6
Week-1/Task-4/r3f/vite.config.js
Normal file
6
Week-1/Task-4/r3f/vite.config.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import react from '@vitejs/plugin-react'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user