ComplexFieldGeometry is a real‑time, browser‑based visualization framework that builds and animates a grid of points connected by edges, enriched with scalar, vector, and tensor fields. It leverages:
- Three.js for 3D rendering
- dat.GUI for interactive parameter tuning
- Webpack/Babel for ES6+ module bundling and compatibility
- Modularity — Separate geometry computation, state management, visualization controls, and app bootstrap
- Extensibility — Support arbitrary fields, tensor visualizations, custom differential operators
- Performance — Spatial bucketing, incremental updates, debounced rendering, minimal GC pressure
- Interactivity — Real-time user control, animation toggles, scalar/vector/tensor visualizations
src/
├── index.html ← HTML entrypoint
├── index.js ← App bootstrap & render loop
├── complex-field-geometry.js ← Geometry engine (vertices, edges, fields)
├── field-manager.js ← Field abstraction layer (scalar, vector, tensor fields)
├── visualization.js ← dat.GUI setup + visualization helpers
├── state-store.js ← Centralized parameter store + flags
├── logger.js ← Timestamped logger (init, update hooks)
build/
├── .babelrc ← ES6+ transpilation
├── webpack.config.js ← Module bundling, dev server
├── package.json ← Scripts, dependencies
└── package-lock.json ← Resolved deps tree
- Purpose: N‑dimensional numerical array with fast access via strides
- Members:
dimensions: number[]data: Float32Arraystrides: number[]
- Methods:
.getValue(...indices).setValue(value, ...indices)
Encapsulates geometry, visual mesh, field data, and user-defined functions.
-
Properties:
id: numberposition: THREE.Vector3vector: THREE.Vector3tensor: Tensor | nullfunctions: Map<string, Function>properties: Map<string, any>mesh: THREE.Mesh
-
Methods:
.setVector(x, y, z).setTensor(dimensions, data).addFunction(name, fn)/.evaluateFunction(name, args).setProperty(name, value)/.getProperty(name).updateVisual(material)
Undirected connection with geometric and field data.
-
Properties:
from,to:EnhancedVertexdistance: numberproperties: Map<string, any>line: THREE.Line
-
Methods:
.updateDistance().setProperty(name, value)/.getProperty(name).updateVisual(material)
Main class managing all geometry, stateful fields, and rendering groups.
- Properties:
vertices: EnhancedVertex[]edges: Edge[]mesh: THREE.Groupfields: Map<string, Map<vertexId, value>>geometryCache:SphereGeometry,LineMaterial, etc.vertexMap,adjacencyMapnextVertexId
createBaseGeometry(stateStore)disposeGeometry()createFields()update(stateStore)updateFields()
computeDifferentialField(name, derivationFn)computeGradient(fieldName, newFieldName)- (planned)
computeCurl,computeLaplacian,computeDivergence
visualizeScalarField(name)→ color mapping (HSL)visualizeVectorField(name)→ arrow glyphsvisualizeTensorComponent()→ tensor entry/determinant visualizedanimateVertices()→ centralized animation hook (debounced) ✅ COMPLETED
Abstraction layer for managing scalar/vector/tensor fields:
- Stores per-field metadata: domain, color mapping, normalization
- Delegates to
ComplexFieldGeometryto apply visuals - Plans for legend rendering & field selector UI components
Powered by dat.GUI with folders:
- Grid:
gridSize,spacing - Visual:
pointSize,pointColor,lineColor - Metrics:
maxDistance,dimensionality - Fields: selector, compute buttons
- Animation:
enableAnimation,timeSlice, etc. - Tensor: entry selector (
0,0…det)
- Changes set
stateStore.needsUpdate = true - Compute buttons trigger field updates
- Debounced GUI sync to minimize excessive update calls
- Sets up
Logger,StateStore,Scene,Camera,Renderer,Controls,Clock - Creates
ComplexFieldGeometry→ adds mesh → callscreateBaseGeometry() - Runs
setupGUI()and adds event listeners
requestAnimationFrame(animate)- Handles camera damping, time updates
- If
stateStore.needsUpdate, callgeometry.update() - If
enableAnimation, callanimateVertices() renderer.render()
- Webpack + Babel targeting modern browsers
babel-loader,css-loader,asset modules- DevServer with hot module reload
- Scripts:
npm run dev/npm startnpm run build
- Spatial Bucketing → O(N) neighbor search for efficient adjacency calculation
- Incremental Updates → separate flags for mesh rebuilds vs. field updates
- Debouncing → GUI updates & render triggers to prevent redundant operations
- Field Abstraction → scalar/vector/tensor fields as maps + metadata
- Animation → time-driven function modulation per vertex
- Tensor Visualization → component-specific & determinant coloring
- Logger → timestamped events for init, updates, and profiling
Status: ✅ IMPLEMENTED
Implemented update debouncing to prevent redundant update() and createBaseGeometry() calls:
let updateQueued = false;
function scheduleUpdate() {
if (!updateQueued) {
updateQueued = true;
requestAnimationFrame(() => {
update();
updateQueued = false;
});
}
}Benefits:
- Eliminates multiple redundant updates per second
- Batches related parameter changes into single update calls
- Significantly reduces computational waste from repeated identical parameter changes
Status: ✅ IMPLEMENTED
Added intelligent update detection to skip geometry rebuild for material-only changes:
function update(params) {
if (params.onlyAffectMaterial) {
applyMaterialChanges(params);
return;
}
createBaseGeometry();
}Benefits:
- Color changes (
pointColor,lineColor) no longer trigger full geometry rebuilds - Vastly improved performance for visual-only parameter adjustments
- Cleaner separation between structural and aesthetic updates
Status: ✅ IMPLEMENTED
Added performance monitoring for gradient field computations and other heavy operations:
console.time("Gradient Field Computation");
computeGradientField();
console.timeEnd("Gradient Field Computation");Benefits:
- Visibility into computation bottlenecks
- Performance tracking as grid size scales (100 → 169+ vertices)
- Foundation for future Web Worker optimization
- DevTools integration for main thread blocking detection
| Area | Description | Priority |
|---|---|---|
| Update Invalidation Granularity | Add per-feature flags: needsMeshRebuild, needsRecolorOnly, needsMaterialRefresh, etc. |
Medium |
| Vector Field Rendering | Implement arrow glyphs via GPU instancing or line meshes | High |
| Shader-Based Color Mapping | Move scalar color mapping into fragment shader for performance | Medium |
| User Field Import | Support CSV/JSON loading to override sin/cos analytic defaults | Low |
| Unit Tests | Tensor ops, field computations, differential correctness tests | Medium |
| TensorVisualizer | Encapsulate component selection, normalization, legend | Medium |
| Web Worker Integration | Move heavy gradient computations off main thread | High |
| Volumetric 3D Support | Expand to full 3D lattices (x,y,z), 3D adjacency, slicing controls | Low |
- Grid scaling: 100 → 169+ vertices successfully tested
- Gradient field computation time: monitored via console profiling
- Update frequency: reduced from multiple/second to batched updates
performance.now()timing logs- Console.time/timeEnd for heavy computations
- DevTools markers for main thread analysis
- Update frequency tracking
- GPU Offloading: Shader-based computations,
InstancedMesh - Web Workers: Gradient and differential operator computations
- Memory Pooling: Reduce GC pressure in animation loops
- LOD System: Level-of-detail for large grids
| Task | Status | Description |
|---|---|---|
Duplicate animateVertices Refactor |
✅ COMPLETED | Consolidated animation logic into geometry.animateVertices() |
| Debouncing/Batching Implementation | ✅ COMPLETED | Implemented scheduleUpdate() with requestAnimationFrame batching |
| Material-Only Update Detection | ✅ COMPLETED | Added onlyAffectMaterial check to skip geometry rebuilds |
| Profiling Hooks | ✅ COMPLETED | Added performance monitoring for heavy computations |
ComplexFieldGeometry is a modular, extensible, and high-performance framework for real-time field visualization. Recent improvements have significantly enhanced performance through intelligent update batching, material-only change detection, and comprehensive profiling hooks.
The framework elegantly integrates mathematical structure (fields, tensors, differential operators), rendering architecture (Three.js, optimized geometry), and UI control (dat.GUI), making it suitable for:
- Scientific Visualization: Real-time field analysis and differential operator visualization
- Educational Tools: Interactive mathematical concept demonstration
- Simulation Frontends: High-performance data visualization for computational results
Continued development should focus on GPU acceleration, Web Worker integration for heavy computations, and expanding vector field visualization capabilities while maintaining the modular architecture that enables easy extension and customization.