Architecture Overview
Vector Display 2D is built on Godot’s node system and uses a smart, performance-optimized rendering pipeline. The addon captures vector data from a target node and visualizes it in real-time using Godot’s drawing API.Core Components
The system consists of three main components:- VectorDisplay2D - The main visualization node that extends
Node2D - VectorDisplaySettings - A
Resourcethat stores all configuration options - VectorDisplayFunctions - Static utility functions for calculations and validation
The separation of logic into static functions allows for future 3D support without code duplication.
Vector Capture Process
The addon uses Godot’s reflection system to dynamically read vector properties from any node.Target Validation
During initialization in_ready(), the system validates the target configuration:
vector_display_2d.gd:18-22
- Target node exists (auto-assigns to parent if not set)
- Target property exists and is a
Vector2 - Settings resource is configured
If no target node is specified, the addon automatically uses the parent node. This makes setup faster for common use cases.
Dynamic Property Reading
Every frame, the_process() function reads the current vector value:
vector_display_2d.gd:26-40
- Read - Uses
get()to retrieve the property value - Scale - Applies
vector_scalefor visual sizing - Transform - Applies length mode (Normal, Clamp, or Normalize)
- Compare - Checks if the vector actually changed
- Queue - Only triggers redraw if necessary
Smart Redraw System
One of the key performance optimizations is the smart redraw mechanism.Performance Optimization
Instead of redrawing every frame, the system only triggersqueue_redraw() when:
- The vector value changes (
current_vector == new_vector) - The raw length changes (using
is_equal_approx()for floating-point comparison) - Settings are modified (via
settings.changedsignal)
Why track both vector and raw length?
Why track both vector and raw length?
The system tracks both the processed vector and the raw length separately because:
- Processed vector - Used for actual rendering, includes scale and length mode transformations
- Raw length - Used for color dimming calculations to show the true magnitude
Automatic Settings Updates
The settings resource emits achanged signal whenever any property is modified:
vector_display_2d.gd:22
Drawing and Rendering
The_draw() function handles all visual output using Godot’s 2D drawing API.
Main Vector Rendering
vector_display_2d.gd:43-51
Axes Component Rendering
Whenshow_axes is enabled, the system draws X and Y components:
vector_display_2d.gd:53-62
Arrowhead Drawing
Arrowheads are drawn as triangular polygons with automatic sizing:vector_display_2d.gd:66-87
Arrowheads automatically hide when vectors become too small, preventing visual clutter.
Rendering Pipeline Summary
The complete rendering flow:Color Calculations
Colors are calculated dynamically based on settings usingvector_display_functions.gd:34-69:
- Base colors - Start with configured colors
- Rainbow mode - Calculate hue from vector angle
- Dimming - Lerp towards fallback color based on magnitude
Rainbow color calculation
Rainbow color calculation
vector_display_functions.gd:46-51
Keyboard Shortcut Handling
The system includes built-in keyboard shortcut support for toggling visibility:vector_display_2d.gd:91-93
