diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-01-30 11:31:24 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-01-30 13:05:48 +0100 |
| commit | 0d4b61993cba37c180ac91e40a0fb362711de8de (patch) | |
| tree | f41dd68420b51766c1ca6fc1ee2c20dc5df830d1 /src/components/SceneBackground.tsx | |
Initial implementation
Diffstat (limited to 'src/components/SceneBackground.tsx')
| -rw-r--r-- | src/components/SceneBackground.tsx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/components/SceneBackground.tsx b/src/components/SceneBackground.tsx new file mode 100644 index 0000000..c2dd2e2 --- /dev/null +++ b/src/components/SceneBackground.tsx @@ -0,0 +1,33 @@ +import React, { useEffect } from "react"; +import { useThree } from "@react-three/fiber"; +import * as THREE from "three"; +import { useStore } from "../store/store.ts"; + +const textureLoader = new THREE.TextureLoader(); + +const SceneBackgroundInner: React.FC = () => { + const backdropUrl = useStore((state) => state.backdropUrl); + const { scene } = useThree(); + + useEffect(() => { + if (backdropUrl) { + textureLoader.load(backdropUrl, (texture) => { + texture.colorSpace = THREE.SRGBColorSpace; + scene.background = texture; + }); + } else { + scene.background = new THREE.Color(0x4a4a4a); + } + + return () => { + if (scene.background instanceof THREE.Texture) { + scene.background.dispose(); + } + }; + }, [backdropUrl, scene]); + + return null; +}; + +export const SceneBackground = React.memo(SceneBackgroundInner); +SceneBackground.displayName = "SceneBackground"; |