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%;
z-index: -1;
pointer-events: none;
background-color: var(--scene-bg);
}
.scene-container :global(canvas) {
+23 -1
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import { onMount } from 'svelte';
import { Canvas } from '@threlte/core';
import { T } from '@threlte/core';
import ParticleField from './ParticleField.svelte';
@@ -8,9 +9,29 @@
// Reactive theme colors
const bgColor = $derived($themeColors.background);
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>
<div class="scene-container">
<div class="scene-container" style="--scene-bg: {bgColor};">
{#if webglAvailable}
<Canvas>
<T.PerspectiveCamera
makeDefault
@@ -36,4 +57,5 @@
<!-- Background color -->
<T.Color args={[bgColor]} attach="background" />
</Canvas>
{/if}
</div>
+9 -2
View File
@@ -385,8 +385,15 @@
onMount(() => {
if (container) {
initScene();
animate();
try {
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("keydown", handleKeydown);
}