Remove 3D background and guard WebGL usage
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
height: 100%;
|
||||
z-index: -1;
|
||||
pointer-events: none;
|
||||
background-color: var(--scene-bg);
|
||||
}
|
||||
|
||||
.scene-container :global(canvas) {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import './layout.css';
|
||||
import Background3D from '$lib/components/Background3D.svelte';
|
||||
import { themeColors, mode, colorTheme, toggleMode, setColorTheme, themeOptions } from '$lib/stores/theme';
|
||||
import { goto } from '$app/navigation';
|
||||
import { navigation } from '$lib/config';
|
||||
@@ -76,7 +75,6 @@
|
||||
<NavbarWaybar />
|
||||
<!-- <Navbar /> -->
|
||||
<main class="main-content">
|
||||
<Background3D />
|
||||
{@render children()}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user