From 1f72a26085899f3e642094094014ca59472030c6 Mon Sep 17 00:00:00 2001 From: divyap Date: Sun, 12 Apr 2026 12:54:46 +0530 Subject: [PATCH] feat: implement multi-object selection behavior audit for week 3 task 4 in r3f --- Week-3/Task-4/r3f/src/App.css | 28 +++++++++++++++++ Week-3/Task-4/r3f/src/App.jsx | 59 ++++++++++++++++++++++++----------- 2 files changed, 69 insertions(+), 18 deletions(-) diff --git a/Week-3/Task-4/r3f/src/App.css b/Week-3/Task-4/r3f/src/App.css index dc48fc7..cb56a66 100644 --- a/Week-3/Task-4/r3f/src/App.css +++ b/Week-3/Task-4/r3f/src/App.css @@ -4,6 +4,34 @@ position: relative; background-color: white; overflow: hidden; + font-family: 'Inter', system-ui, -apple-system, sans-serif; +} + +#instructions { + position: absolute; + top: 20px; + left: 20px; + background: rgba(255, 255, 255, 0.85); + backdrop-filter: blur(12px); + padding: 24px; + border-radius: 16px; + box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08); + border: 1px solid rgba(255, 255, 255, 0.3); + max-width: 300px; + z-index: 100; +} + +h2 { + margin: 0 0 12px 0; + font-size: 1.25rem; + color: #1a1a1a; +} + +p { + margin: 0 0 12px 0; + font-size: 0.95rem; + color: #4a4a4a; + line-height: 1.5; } .canvas-wrapper { diff --git a/Week-3/Task-4/r3f/src/App.jsx b/Week-3/Task-4/r3f/src/App.jsx index 7e37115..7cf7374 100644 --- a/Week-3/Task-4/r3f/src/App.jsx +++ b/Week-3/Task-4/r3f/src/App.jsx @@ -3,42 +3,65 @@ import { Canvas } from '@react-three/fiber'; import { OrbitControls, PerspectiveCamera } from '@react-three/drei'; import './App.css'; -function InteractiveObject() { - const [selected, setSelected] = useState(false); +function Selectable({ id, position, color, geometry, selectedId, onSelect }) { + const isSelected = selectedId === id; return ( setSelected(!selected)} - scale={selected ? 1.2 : 1} - rotation={[0, 0, 0]} + position={position} + onClick={(e) => { + e.stopPropagation(); + onSelect(isSelected ? null : id); + }} + scale={isSelected ? 1.2 : 1} > - - ); } export default function App() { + const [selectedId, setSelectedId] = useState(null); + + const objects = [ + { id: 'box', position: [-4, 0, 0], color: "#ff4f4f", geometry: }, + { id: 'sphere', position: [0, 0, 0], color: "#4f8cff", geometry: }, + { id: 'torus', position: [4, 0, 0], color: "#4fff8c", geometry: } + ]; + return (
-
-

Interaction Pattern — Click on the object

+
+

Task 4 Audit (R3F)

+

Click objects to select/deselect them. State managed via React.

+

Selected: {selectedId || 'None'}

- + setSelectedId(null)} + > - + - - + + - + {objects.map((obj) => ( + + ))}