Remove 3D background and guard WebGL usage

This commit is contained in:
2026-06-30 20:58:44 +00:00
parent 111da8904c
commit fe6c0f93fa
4 changed files with 33 additions and 5 deletions
+1
View File
@@ -6,6 +6,7 @@
height: 100%; height: 100%;
z-index: -1; z-index: -1;
pointer-events: none; pointer-events: none;
background-color: var(--scene-bg);
} }
.scene-container :global(canvas) { .scene-container :global(canvas) {
+23 -1
View File
@@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import { onMount } from 'svelte';
import { Canvas } from '@threlte/core'; import { Canvas } from '@threlte/core';
import { T } from '@threlte/core'; import { T } from '@threlte/core';
import ParticleField from './ParticleField.svelte'; import ParticleField from './ParticleField.svelte';
@@ -8,9 +9,29 @@
// Reactive theme colors // Reactive theme colors
const bgColor = $derived($themeColors.background); const bgColor = $derived($themeColors.background);
const primaryColor = $derived($themeColors.primary); const primaryColor = $derived($themeColors.primary);
let webglAvailable = $state(false);
function isWebGLAvailable() {
try {
const testCanvas = document.createElement('canvas');
const context =
testCanvas.getContext('webgl2') ||
testCanvas.getContext('webgl') ||
testCanvas.getContext('experimental-webgl');
return !!(window.WebGLRenderingContext && context);
} catch {
return false;
}
}
onMount(() => {
webglAvailable = isWebGLAvailable();
});
</script> </script>
<div class="scene-container"> <div class="scene-container" style="--scene-bg: {bgColor};">
{#if webglAvailable}
<Canvas> <Canvas>
<T.PerspectiveCamera <T.PerspectiveCamera
makeDefault makeDefault
@@ -36,4 +57,5 @@
<!-- Background color --> <!-- Background color -->
<T.Color args={[bgColor]} attach="background" /> <T.Color args={[bgColor]} attach="background" />
</Canvas> </Canvas>
{/if}
</div> </div>
+9 -2
View File
@@ -385,8 +385,15 @@
onMount(() => { onMount(() => {
if (container) { if (container) {
initScene(); try {
animate(); initScene();
animate();
} catch (err) {
console.error("WebGL unavailable:", err);
loadError = "3D viewer unavailable (WebGL not supported)";
isLoading = false;
return;
}
window.addEventListener("resize", handleResize); window.addEventListener("resize", handleResize);
window.addEventListener("keydown", handleKeydown); window.addEventListener("keydown", handleKeydown);
} }
-2
View File
@@ -1,6 +1,5 @@
<script lang="ts"> <script lang="ts">
import './layout.css'; import './layout.css';
import Background3D from '$lib/components/Background3D.svelte';
import { themeColors, mode, colorTheme, toggleMode, setColorTheme, themeOptions } from '$lib/stores/theme'; import { themeColors, mode, colorTheme, toggleMode, setColorTheme, themeOptions } from '$lib/stores/theme';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { navigation } from '$lib/config'; import { navigation } from '$lib/config';
@@ -76,7 +75,6 @@
<NavbarWaybar /> <NavbarWaybar />
<!-- <Navbar /> --> <!-- <Navbar /> -->
<main class="main-content"> <main class="main-content">
<Background3D />
{@render children()} {@render children()}
</main> </main>
</div> </div>