@@ -43,34 +43,46 @@ let animationFrameId = 0
4343let lineSegments: THREE .LineSegments <THREE .BufferGeometry , THREE .LineBasicMaterial > | null = null
4444let resizeHandler: (() => void ) | null = null
4545let pointerHandler: (() => void ) | null = null
46+ let enabled = true
4647
4748function initScene() {
4849 if (! canvasContainer .value ) {
4950 return
5051 }
5152
52- scene = new THREE .Scene ()
53- scene .fog = new THREE .FogExp2 (COLORS .bg , 0.023 )
54-
55- camera = new THREE .PerspectiveCamera (60 , window .innerWidth / window .innerHeight , 0.1 , 1000 )
56- camera .position .set (0 , 0 , 39 )
57-
58- renderer = new THREE .WebGLRenderer ({ alpha: true , antialias: true })
59- renderer .setSize (window .innerWidth , window .innerHeight )
60- renderer .setPixelRatio (Math .min (window .devicePixelRatio , 2 ))
61- renderer .setClearAlpha (0 )
62- canvasContainer .value .appendChild (renderer .domElement )
63-
64- controls = new OrbitControls (camera , renderer .domElement )
65- controls .enableDamping = true
66- controls .enablePan = false
67- controls .enableZoom = false
68- controls .autoRotate = true
69- controls .autoRotateSpeed = 0.4
53+ try {
54+ scene = new THREE .Scene ()
55+ scene .fog = new THREE .FogExp2 (COLORS .bg , 0.023 )
56+
57+ camera = new THREE .PerspectiveCamera (60 , window .innerWidth / window .innerHeight , 0.1 , 1000 )
58+ camera .position .set (0 , 0 , 39 )
59+
60+ renderer = new THREE .WebGLRenderer ({ alpha: true , antialias: true })
61+ renderer .setSize (window .innerWidth , window .innerHeight )
62+ renderer .setPixelRatio (Math .min (window .devicePixelRatio , 2 ))
63+ renderer .setClearAlpha (0 )
64+ canvasContainer .value .appendChild (renderer .domElement )
65+
66+ controls = new OrbitControls (camera , renderer .domElement )
67+ controls .enableDamping = true
68+ controls .enablePan = false
69+ controls .enableZoom = false
70+ controls .autoRotate = true
71+ controls .autoRotateSpeed = 0.4
72+ } catch (error ) {
73+ enabled = false
74+ scene = null
75+ camera = null
76+ renderer = null
77+ controls = null
78+ if (import .meta .env .DEV ) {
79+ console .warn (' NeuralBackground disabled:' , error )
80+ }
81+ }
7082}
7183
7284function buildNetwork() {
73- if (! scene ) {
85+ if (! enabled || ! scene ) {
7486 return
7587 }
7688
@@ -137,7 +149,7 @@ function buildNetwork() {
137149}
138150
139151function spawnSignal(startNode : NeuralNode ) {
140- if (! scene || startNode .connections .length === 0 ) {
152+ if (! enabled || ! scene || startNode .connections .length === 0 ) {
141153 return
142154 }
143155
@@ -171,6 +183,9 @@ function triggerThought() {
171183}
172184
173185function animate() {
186+ if (! enabled ) {
187+ return
188+ }
174189 animationFrameId = window .requestAnimationFrame (animate )
175190 const delta = clock .getDelta ()
176191
@@ -228,6 +243,9 @@ function handleResize() {
228243
229244onMounted (() => {
230245 initScene ()
246+ if (! enabled ) {
247+ return
248+ }
231249 buildNetwork ()
232250 animate ()
233251
0 commit comments