diff --git a/Week-2/Task-2/r3f/sceene/src/App.jsx b/Week-2/Task-2/r3f/sceene/src/App.jsx
index 194eb0b..717f1ba 100644
--- a/Week-2/Task-2/r3f/sceene/src/App.jsx
+++ b/Week-2/Task-2/r3f/sceene/src/App.jsx
@@ -1,7 +1,147 @@
+import { useEffect, useMemo, useRef, useState } from 'react'
+import { Canvas, useFrame } from '@react-three/fiber'
+import * as THREE from 'three'
+
+const SCENE_STATES = {
+ state1: {
+ center: { position: [0, 0, 0], rotation: [0, 0, 0], visible: true },
+ left: { position: [0, 0, 0], rotation: [0, 0, 0], visible: false },
+ right: { position: [0, 0, 0], rotation: [0, 0, 0], visible: false },
+ },
+ state2: {
+ center: { position: [0, 0, 0], rotation: [0.25, 0.4, 0], visible: true },
+ left: { position: [-2.1, 0, 0.2], rotation: [0, 0.2, 0], visible: true },
+ right: { position: [2.1, 0, -0.2], rotation: [0, -0.2, 0], visible: true },
+ },
+ state3: {
+ center: { position: [0, 1.3, 0], rotation: [0.6, 0.9, 0], visible: true },
+ left: { position: [-1.2, -1, 1.2], rotation: [0.3, 0.3, 0.1], visible: true },
+ right: { position: [0, 0, 0], rotation: [0, 0, 0], visible: false },
+ },
+}
+
+function SceneObjects({ stateKey }) {
+ const centerRef = useRef()
+ const leftRef = useRef()
+ const rightRef = useRef()
+
+ const targets = useMemo(
+ () => ({
+ center: { position: new THREE.Vector3(), rotation: new THREE.Euler() },
+ left: { position: new THREE.Vector3(), rotation: new THREE.Euler() },
+ right: { position: new THREE.Vector3(), rotation: new THREE.Euler() },
+ }),
+ []
+ )
+
+ useEffect(() => {
+ const state = SCENE_STATES[stateKey]
+ const refs = {
+ center: centerRef.current,
+ left: leftRef.current,
+ right: rightRef.current,
+ }
+
+ Object.keys(refs).forEach((name) => {
+ const object = refs[name]
+ if (!object) return
+
+ const config = state[name]
+ targets[name].position.set(...config.position)
+ targets[name].rotation.set(...config.rotation)
+ object.visible = config.visible
+ })
+ }, [stateKey, targets])
+
+ useFrame(() => {
+ const refs = {
+ center: centerRef.current,
+ left: leftRef.current,
+ right: rightRef.current,
+ }
+
+ Object.keys(refs).forEach((name) => {
+ const object = refs[name]
+ if (!object) return
+
+ const target = targets[name]
+ object.position.lerp(target.position, 0.1)
+ object.rotation.x += (target.rotation.x - object.rotation.x) * 0.1
+ object.rotation.y += (target.rotation.y - object.rotation.y) * 0.1
+ object.rotation.z += (target.rotation.z - object.rotation.z) * 0.1
+ })
+ })
+
+ return (
+ <>
+
Press 1, 2, or 3 to switch state.
+