Gen Network Module
Road network generation and geometric utility module with socket-based communication.
Road network generation and geometric utility module with socket-based communication.
Overview
The network module handles procedural road network generation for the gen editor. It provides geometric utilities (segment intersection, fan ordering, curve height lookup, vector normals) and a socket-based networking layer for external communication. Used for generating and analyzing road networks in levels.
Module Table: Net
| Field | Type | Description |
|---|---|---|
Net.out | table | Output data |
Geometric Utility Functions
Added to the shared U (utils) module:
| Function | Signature | Description |
|---|---|---|
U.segmentCross(a1, a2, b1, b2, inner) | (vec3, vec3, vec3, vec3, bool?) → x, y? | Tests two 2D line segments for intersection; returns nil if no crossing |
U.fanOrder(apos) | (table) → table | Sorts positions by angle around origin (fan ordering for polygons) |
U.vnorm(v) | (vec3) → vec3 | Returns the 2D perpendicular normal of a vector |
U.hightOnCurve(p, rdinfo, start, dbg) | (vec3, table, number, bool?) → ... | Finds height on a road curve at a given position by projecting onto road edges |
Road Info Structure (rdinfo)
| Field | Type | Description |
|---|---|---|
id | number | Decal road scene object ID |
av | table | Road vertex array |
avstep | number | Vertex step interval |
Dependencies
| Module | Path |
|---|---|
| socket | socket (LuaSocket) |
| Utils | /lua/ge/extensions/editor/gen/utils |
| Render | /lua/ge/extensions/editor/gen/render |
| Mesh | /lua/ge/extensions/editor/gen/mesh |
Usage Example
local Net = require('/lua/ge/extensions/editor/gen/network')
-- Test if two road segments cross
local x, y = U.segmentCross(
vec3(0,0,0), vec3(10,0,0),
vec3(5,-5,0), vec3(5,5,0)
)
-- x=5, y=0
-- Sort intersection points by angle
local ordered = U.fanOrder({vec3(1,0,0), vec3(0,1,0), vec3(-1,0,0)})
-- Get perpendicular normal
local normal = U.vnorm(vec3(1,0,0)) -- returns vec3(0,1,0)Module Fields
| Field | Type | Description |
|---|---|---|
Net.cid | number? | Road ID set during path-to-decal conversion |
Net.sregion | table? | Selected region indices for highlighting (set externally, not initialized on Net) |
Net.exitBranch | function? | Exit branch handler (set externally, called in onUpdate) |
Exported Functions
Net.circleSeed(nnode, pos, r, mode)
Seeds the circle-packing road network with nnode circles centered at pos.
nnode(number) - Number of circle nodes to generatepos(vec3?) - Center position (defaults to vec3(0,0,0))r(number?) - Max circle radius overridemode(table?) - Optional mode with.resizefield for resizing existing nodes
Returns: table? - Array of node data {pos, r, stamp}, or nil on failure
Net.pathsUp()
Computes Eulerian-style paths through the circle-packing network graph.
Net.toDecals()
Converts computed paths into road decal objects in the scene.
Net.onUpdate()
Per-frame update callback. Renders circle outlines, paths, and debug text.
Note: This module also extends
Mesh.strip(L, apos, av, af)on the imported Mesh module for strip mesh generation.
See Also
- Gen Decal - Road/decal generation
- Gen Region - Region-based procedural generation
- Gen Render - Debug rendering