# # SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # WebGL-Enhanced Remote GPU Rendering Service # Using Three.js for GPU-accelerated visualization import json from typing import Dict, Any, List class WebGLGPUVisualizationService: """Enhanced remote GPU service with Three.js WebGL rendering""" def _generate_threejs_webgl_html(self, session_data: dict, config: dict) -> str: """Generate Three.js WebGL visualization with GPU-accelerated rendering""" # Extract data nodes = session_data['processed_nodes'] edges = session_data['processed_edges'] layout_positions = session_data.get('layout_positions', {}) clusters = session_data.get('clusters', {}) centrality = session_data.get('centrality', {}) # Configuration animation_duration = config.get('animation_duration', 3000) show_splash = config.get('show_splash', True) auto_zoom = config.get('auto_zoom', True) show_labels = config.get('show_labels', True) background_color = config.get('background_color', '#0a0a0a') render_quality = config.get('render_quality', 'high') # GPU rendering settings gpu_settings = self._get_gpu_rendering_settings(len(nodes), render_quality) html_template = f""" GPU-Accelerated WebGL Graph Visualization
πŸš€ WebGL GPU Rendering
FPS: --
Nodes: {len(nodes):,}
Triangles: --
Memory: --MB
{"" if not show_splash else '''
Loading {len(nodes):,} nodes with GPU acceleration
Quality: {render_quality.title()} β€’ WebGL 2.0
Initializing WebGL...
'''}
""" return html_template def _get_gpu_rendering_settings(self, node_count: int, quality: str) -> Dict[str, Any]: """Get GPU rendering settings based on graph size and quality""" base_settings = { 'max_instanced_nodes': 100000, 'use_instanced_mesh': node_count > 1000, 'enable_lod': node_count > 25000, 'frustum_culling': node_count > 10000, 'texture_atlas_size': 1024 } quality_multipliers = { 'low': {'texture_atlas_size': 512, 'max_instanced_nodes': 50000}, 'medium': {'texture_atlas_size': 1024, 'max_instanced_nodes': 75000}, 'high': {'texture_atlas_size': 2048, 'max_instanced_nodes': 100000}, 'ultra': {'texture_atlas_size': 4096, 'max_instanced_nodes': 500000} } settings = base_settings.copy() settings.update(quality_multipliers.get(quality, quality_multipliers['high'])) return settings