From ea2edd0ac9d3da020abe193111d3f515b0e90327 Mon Sep 17 00:00:00 2001 From: divyap Date: Thu, 2 Apr 2026 01:37:37 +0530 Subject: [PATCH] feat: added material variant switcher for task 1 in r3f --- Week-2/Task-1/r3f/src/App.css | 41 ++++++++++++++++++++++++ Week-2/Task-1/r3f/src/App.jsx | 56 +++++++++++++++++++++++++++++++-- Week-2/Task-1/r3f/src/index.css | 12 ------- Week-2/Task-1/r3f/src/main.jsx | 4 +-- 4 files changed, 95 insertions(+), 18 deletions(-) delete mode 100644 Week-2/Task-1/r3f/src/index.css diff --git a/Week-2/Task-1/r3f/src/App.css b/Week-2/Task-1/r3f/src/App.css index e69de29..d87f28f 100644 --- a/Week-2/Task-1/r3f/src/App.css +++ b/Week-2/Task-1/r3f/src/App.css @@ -0,0 +1,41 @@ +.app-container { + width: 100vw; + height: 100vh; + position: relative; + background-color: white; + overflow: hidden; +} + +#controls { + position: absolute; + top: 20px; + left: 20px; + z-index: 10; + display: flex; + gap: 10px; +} + +button { + padding: 8px 16px; + cursor: pointer; + background: #f0f0f0; + border: 1px solid #ccc; + border-radius: 4px; + font-weight: 500; + transition: all 0.2s; +} + +button:hover { + background: #e0e0e0; +} + +button.active { + background: #333; + color: white; + border-color: #333; +} + +.canvas-wrapper { + width: 100%; + height: 100%; +} diff --git a/Week-2/Task-1/r3f/src/App.jsx b/Week-2/Task-1/r3f/src/App.jsx index 71ffef9..557d2f4 100644 --- a/Week-2/Task-1/r3f/src/App.jsx +++ b/Week-2/Task-1/r3f/src/App.jsx @@ -1,5 +1,55 @@ +import React, { useState } from 'react'; +import { Canvas } from '@react-three/fiber'; +import { OrbitControls, PerspectiveCamera } from '@react-three/drei'; +import './App.css'; + +const materials = { + black: { color: "black", roughness: 1, metalness: 0 }, + silver: { color: "#C0C0C0", roughness: 0.3, metalness: 1 }, + gold: { color: "#FFD700", roughness: 0.4, metalness: 1 }, +}; + +function Scene({ variant }) { + return ( + <> + + + + + + + + + + + + + ); +} + export default function App() { - return ( - <> - ) + const [activeVariant, setActiveVariant] = useState('black'); + + return ( +
+
+ {Object.keys(materials).map((variant) => ( + + ))} +
+ +
+ + + + +
+
+ ); } \ No newline at end of file diff --git a/Week-2/Task-1/r3f/src/index.css b/Week-2/Task-1/r3f/src/index.css deleted file mode 100644 index 7ee6713..0000000 --- a/Week-2/Task-1/r3f/src/index.css +++ /dev/null @@ -1,12 +0,0 @@ -* { - box-sizing: border-box; -} - -body, html, #root { - margin: 0; - padding: 0; - width: 100%; - height: 100%; - overflow: hidden; - background-color: #111; -} \ No newline at end of file diff --git a/Week-2/Task-1/r3f/src/main.jsx b/Week-2/Task-1/r3f/src/main.jsx index 9347e15..e42f191 100644 --- a/Week-2/Task-1/r3f/src/main.jsx +++ b/Week-2/Task-1/r3f/src/main.jsx @@ -1,10 +1,8 @@ import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import './index.css' import App from './App.jsx' - createRoot(document.getElementById('root')).render( , -) \ No newline at end of file +) \ No newline at end of file