Instanced Line Render Demo
Demo extension showcasing the instanced line and dot rendering API. Features an N-body gravity simulation, grid drawing, sine waves, edge tests, and traffic signal visualization.
Demo extension showcasing the instanced line and dot rendering API. Features an N-body gravity simulation, grid drawing, sine waves, edge tests, and traffic signal visualization.
Overview
util_instancedLineRenderDemo demonstrates the debugDrawer:drawLineInstance() and debugDrawer:drawDot() APIs with several visual demos. Includes an N-body simulation with history trails, grid comparisons (standard vs instanced lines), sine wave rendering, edge/width tests, and a traffic signal mock-up.
Extension path: lua/ge/extensions/util/instancedLineRenderDemo.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
onExtensionLoaded | () | Initializes the N-body simulation. |
onPreRender | (dtReal, dtSim, dtRaw) | Runs simulation and renders all demos. |
Internals
N-Body Simulation
- Masses: 5 particles with random initial positions, velocities, and colors.
- Forces: Each particle is attracted toward origin (
-32x) and repelled/attracted by other masses. - History: Up to 10,000 line segments stored per mass for trail rendering.
- Rendering: Two copies - one with depth testing off, one with depth on (offset by 5 units).
Instanced Line API
-- Full signature:
debugDrawer:drawLineInstance(posA, posB, widthA, colorA, widthB, colorB, colOutlineA, colOutlineB, outLineMultiplier, endRoundCaps)
-- Simplified (uniform width/color):
debugDrawer:drawLineInstance(posA, posB, width, color, useDepth)
-- Dot:
debugDrawer:drawDot(pos, size, color, colOutline, outLineMultiplier)Demo Components
| Demo | Description |
|---|---|
| N-body trails | Colorful particle trails from gravity sim. |
| Grid comparison | Side-by-side standard vs instanced line grids. |
| Sine waves | Varying width sine waves with animated color. |
| Edge test | Variable-width connected segments with outlines. |
| Traffic signal | Dot-based traffic light mock-up with state cycling. |
Signal States
The traffic signal cycles through 4 states:
- Red
- Red + Yellow
- Green
- Yellow
How It Works
- Load:
extensions.load('util_instancedLineRenderDemo'). - The simulation starts automatically.
- Every frame,
onPreRenderupdates physics and draws all demos near origin(0, 0, 3). - Commented-out demos (grid, sine, edge, signal) can be re-enabled in the source.
Lua Examples
-- Load the demo
extensions.load('util_instancedLineRenderDemo')
-- Key rendering calls used in the demo:
debugDrawer:drawLineInstance(p1, p2, 3, ColorF(1,0,0,1), true)
debugDrawer:drawDot(pos, 50, ColorF(0,1,0,1), ColorF(0,0,0,1), 1.2)
debugDrawer:drawLineInstance(p1, p2, 10, col1, 30, col2, bgColor, bgColor, 30)Additional Exports
M.onExtensionLoaded- (undocumented)M.onPreRender- (undocumented)
Input System Utils
Utilities for analyzing and re-formatting input map JSON files. Prints binding statistics and resaves all inputmap files with consistent formatting and sorting.
JBeam Stats
Generates statistics about all JBeam files in the game - part counts, section usage, line counts, and modifier counts.