Spaces:
Build error
Build error
File size: 3,115 Bytes
8a01471 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | import { Suspense } from 'react';
import { Canvas } from '@react-three/fiber';
import { Stars, GizmoHelper, GizmoViewport } from '@react-three/drei';
import { LayerNodes } from './layers';
import { EdgeConnections } from './edges';
import { CameraControls, useKeyboardShortcuts } from './controls';
import { useVisualizerStore } from '@/core/store';
/**
* Loading fallback component
*/
function LoadingFallback() {
return (
<mesh>
<sphereGeometry args={[0.5, 32, 32]} />
<meshStandardMaterial color="#4fc3f7" wireframe />
</mesh>
);
}
/**
* Scene lighting setup
*/
function SceneLighting() {
const config = useVisualizerStore(state => state.config);
const isDark = config.theme !== 'light';
return (
<>
<ambientLight intensity={isDark ? 0.4 : 0.6} />
<directionalLight
position={[10, 20, 10]}
intensity={isDark ? 0.8 : 1}
castShadow
shadow-mapSize={[2048, 2048]}
/>
<directionalLight position={[-10, 10, -10]} intensity={0.3} />
<pointLight position={[0, 10, 0]} intensity={0.5} color="#4fc3f7" />
</>
);
}
/**
* Scene background
*/
function SceneBackground() {
const config = useVisualizerStore(state => state.config);
if (config.theme === 'light') {
return <color attach="background" args={['#f0f0f0']} />;
}
if (config.theme === 'blueprint') {
return (
<>
<color attach="background" args={['#0a1929']} />
<gridHelper args={[100, 100, '#1e3a5f', '#0d2137']} position={[0, -10, 0]} />
</>
);
}
// Dark theme (default)
return (
<>
<color attach="background" args={['#0f0f1a']} />
<Stars radius={100} depth={50} count={2000} factor={4} fade speed={0.5} />
</>
);
}
/**
* Keyboard shortcuts handler component
*/
function KeyboardHandler() {
useKeyboardShortcuts();
return null;
}
/**
* Grid and helper elements
*/
function SceneHelpers() {
const model = useVisualizerStore(state => state.model);
if (!model) return null;
return (
<>
<gridHelper
args={[50, 50, '#333', '#222']}
position={[0, -15, 0]}
rotation={[0, 0, 0]}
/>
<GizmoHelper alignment="bottom-left" margin={[80, 80]}>
<GizmoViewport axisColors={['#f44336', '#4caf50', '#2196f3']} labelColor="white" />
</GizmoHelper>
</>
);
}
/**
* Main 3D network scene
*/
function NetworkScene() {
return (
<>
<SceneLighting />
<SceneBackground />
<SceneHelpers />
<Suspense fallback={<LoadingFallback />}>
<EdgeConnections />
<LayerNodes />
</Suspense>
</>
);
}
/**
* Main 3D Canvas component
*/
export function Scene() {
return (
<Canvas
camera={{
position: [0, 5, 20],
fov: 60,
near: 0.1,
far: 1000,
}}
dpr={[1, 2]}
gl={{
antialias: true,
alpha: false,
powerPreference: 'high-performance',
}}
>
<CameraControls />
<KeyboardHandler />
<NetworkScene />
</Canvas>
);
}
export default Scene;
|