Skip to content

Commit

Permalink
Fixed ESLint issue + updated so theme pulls background colors properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhruv-0-Arora committed Jun 27, 2024
1 parent d037118 commit 1f93a25
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
2 changes: 2 additions & 0 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import ManageAssembliesModal from '@/modals/spawning/ManageAssembliesModal.tsx';
import World from '@/systems/World.ts';
import { AddRobotsModal, AddFieldsModal, SpawningModal } from '@/modals/spawning/SpawningModals.tsx';
import ImportMirabufModal from '@/modals/mirabuf/ImportMirabufModal.tsx';
import Skybox from './ui/components/Skybox.tsx';

const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira"

Expand Down Expand Up @@ -130,6 +131,7 @@ function Synthesis() {

return (
<AnimatePresence>
<Skybox key="123"/>
<TooltipControlProvider
showTooltip={(type: TooltipType, controls?: TooltipControl[], duration: number = TOOLTIP_DURATION) => {
showTooltip(type, controls, duration)
Expand Down
3 changes: 3 additions & 0 deletions fission/src/Window.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Theme } from "@mui/material"

declare interface Window {
setAuthCode(code: string): void
getTheme(): Theme;
}
26 changes: 16 additions & 10 deletions fission/src/systems/scene/SceneRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import WorldSystem from '../WorldSystem';

import vertexShader from '@/shaders/vertex.glsl';
import fragmentShader from '@/shaders/fragment.glsl';
import { Theme } from '@/ui/ThemeContext';

const CLEAR_COLOR = 0x121212
const GROUND_COLOR = 0x73937e
Expand Down Expand Up @@ -80,27 +81,23 @@ class SceneRenderer extends WorldSystem {
this._scene.add(ground);

// skybox
const currentTheme = (window as any).getTheme();
console.log('Current Theme:', currentTheme['Background']['color']['r']);

const geometry = new THREE.SphereGeometry(1000);
const material = new THREE.ShaderMaterial({
vertexShader: vertexShader,
fragmentShader: fragmentShader,
side: THREE.BackSide,
uniforms: {
rColor: { value: currentTheme['Background']['color']['r']},
gColor: { value: currentTheme['Background']['color']['g']},
bColor: { value: currentTheme['Background']['color']['b'] },
rColor: { value: 1.0 },
gColor: { value: 1.0 },
bColor: { value: 1.0 },
}
});

this._skybox = new THREE.Mesh(geometry, material);

this._skybox = new THREE.Mesh(geometry, material);
this._skybox.receiveShadow = false;
this._skybox.castShadow = false;
this.scene.add(this._skybox);


}

public UpdateCanvasSize() {
Expand Down Expand Up @@ -167,6 +164,15 @@ class SceneRenderer extends WorldSystem {
})
}

public updateSkyboxColors(currentTheme: Theme) {
if (!this._skybox) return;
if (this._skybox.material instanceof THREE.ShaderMaterial) {
this._skybox.material.uniforms.rColor.value = currentTheme['Background']['color']['r'];
this._skybox.material.uniforms.gColor.value = currentTheme['Background']['color']['g'];
this._skybox.material.uniforms.bColor.value = currentTheme['Background']['color']['b'];
}
}

}

export default SceneRenderer
export default SceneRenderer;
13 changes: 13 additions & 0 deletions fission/src/ui/components/Skybox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import World from "@/systems/World";

const Skybox = () => {
const currentTheme = (window as any).getTheme();
if (World.SceneRenderer) { World.SceneRenderer.updateSkyboxColors(currentTheme); }
return (
<></>
);
}

export default Skybox;

0 comments on commit 1f93a25

Please sign in to comment.