feat: added Basic Rotation / Motion for r3f in task4

This commit is contained in:
anshk 2026-03-30 20:23:17 +05:30
parent d9fb575564
commit 8571b300b9
5 changed files with 76 additions and 3 deletions

View 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>

View File

@ -2,11 +2,23 @@
"name": "week-1-task-4-r3f",
"private": true,
"version": "0.0.0",
"type": "module",
"packageManager": "yarn@1.22.22",
"scripts": {
"dev": "echo 'Add your React Three Fiber dev script here'",
"build": "echo 'Add your React Three Fiber build script here'",
"lint": "echo 'Add your lint script here'",
"dev": "vite",
"build": "vite build",
"lint": "echo 'Lint not configured yet'",
"preview": "vite preview",
"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"
}
}

View 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>
)
}

View 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>,
)

View File

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