From f302667eca6b40019f789acfe9419bce23e2369d Mon Sep 17 00:00:00 2001 From: Dhruv Arora Date: Fri, 28 Jun 2024 11:57:38 -0700 Subject: [PATCH] Adding requested changes to skybox to utlize useTheme() method from ThemeContext avoiding the use of 'any' --- fission/src/systems/scene/SceneRenderer.ts | 9 ++++++--- fission/src/ui/components/Skybox.tsx | 7 +++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fission/src/systems/scene/SceneRenderer.ts b/fission/src/systems/scene/SceneRenderer.ts index 7dee08eb32..dc7b630aff 100644 --- a/fission/src/systems/scene/SceneRenderer.ts +++ b/fission/src/systems/scene/SceneRenderer.ts @@ -80,7 +80,7 @@ class SceneRenderer extends WorldSystem { ground.castShadow = true; this._scene.add(ground); - // skybox + // Adding spherical skybox mesh const geometry = new THREE.SphereGeometry(1000); const material = new THREE.ShaderMaterial({ vertexShader: vertexShader, @@ -92,8 +92,6 @@ class SceneRenderer extends WorldSystem { bColor: { value: 1.0 }, } }); - - this._skybox = new THREE.Mesh(geometry, material); this._skybox.receiveShadow = false; this._skybox.castShadow = false; @@ -164,6 +162,11 @@ class SceneRenderer extends WorldSystem { }) } + /* + * Updates the skybox colors based on the current theme + + * @param currentTheme: current theme from ThemeContext.useTheme() + */ public updateSkyboxColors(currentTheme: Theme) { if (!this._skybox) return; if (this._skybox.material instanceof THREE.ShaderMaterial) { diff --git a/fission/src/ui/components/Skybox.tsx b/fission/src/ui/components/Skybox.tsx index 7bfd1f539b..a01ac09b81 100644 --- a/fission/src/ui/components/Skybox.tsx +++ b/fission/src/ui/components/Skybox.tsx @@ -1,10 +1,9 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ - import World from "@/systems/World"; +import { useTheme } from "../ThemeContext"; const Skybox = () => { - const currentTheme = (window as any).getTheme(); - if (World.SceneRenderer) { World.SceneRenderer.updateSkyboxColors(currentTheme); } + const { currentTheme, themes } = useTheme(); + if (World.SceneRenderer) { World.SceneRenderer.updateSkyboxColors(themes[currentTheme]) } return ( <> );