From b3133aae0e0ab070a7a905b179750472d9132dcf Mon Sep 17 00:00:00 2001 From: divyap Date: Thu, 2 Apr 2026 19:16:29 +0530 Subject: [PATCH] feat: added texture switcher for task 2 in r3f --- Week-2/Task-2/r3f/src/App.css | 47 ++++++++++++++++++++++++------ Week-2/Task-2/r3f/src/App.jsx | 54 +++++++++++++++++++++++++++++++++-- 2 files changed, 90 insertions(+), 11 deletions(-) diff --git a/Week-2/Task-2/r3f/src/App.css b/Week-2/Task-2/r3f/src/App.css index a83e564..659e4e5 100644 --- a/Week-2/Task-2/r3f/src/App.css +++ b/Week-2/Task-2/r3f/src/App.css @@ -1,10 +1,41 @@ -* { - margin: 0; - padding: 0; - box-sizing: border-box; +.app-container { + width: 100vw; + height: 100vh; + position: relative; + background-color: white; + overflow: hidden; } -body { - overflow: hidden; - background-color: #111; - font-family: sans-serif; \ No newline at end of file +#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%; +} \ No newline at end of file diff --git a/Week-2/Task-2/r3f/src/App.jsx b/Week-2/Task-2/r3f/src/App.jsx index 71ffef9..a6f9066 100644 --- a/Week-2/Task-2/r3f/src/App.jsx +++ b/Week-2/Task-2/r3f/src/App.jsx @@ -1,5 +1,53 @@ +import React, { useState} from 'react'; +import { Canvas } from '@react-three/fiber'; +import { OrbitControls, PerspectiveCamera, useTexture } from '@react-three/drei'; +import './App.css'; + +const planetUrls = { + earth: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQZVsp7bSmsdGhM1GouOYgZ6l06Za__Z1ZY8A&s', + moon: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcROh1go667NHsMdzLyvI-0tt9Mn0eugRp0xhQ&s', + sun: 'https://upload.wikimedia.org/wikipedia/commons/a/a4/Solarsystemscope_texture_8k_sun.jpg', +}; + +function Planet({ variant }) { + const textures = useTexture(planetUrls); + + return ( + + + + + ); +} + export default function App() { - return ( - <> - ) + const [activeVariant, setActiveVariant] = useState('earth'); + + return ( +
+
+ {Object.keys(planetUrls).map((variant) => ( + + ))} +
+ +
+ + + + + + + + + +
+
+ ); } \ No newline at end of file