Editor Gen World
Central world/scene management module for the Building Architect Tool (BAT). Manages the full lifecycle of procedural buildings: creation, editing, material assignment, forest item placement, DAE expo
Central world/scene management module for the Building Architect Tool (BAT). Manages the full lifecycle of procedural buildings: creation, editing, material assignment, forest item placement, DAE export, terrain conforming, undo/redo, and session save/load.
Module Overview
| Aspect | Detail |
|---|---|
| File | extensions/editor/gen/world.lua |
| Returns | W table (global world state) |
| Requires | editor/gen/mesh, editor/gen/utils, editor/gen/decal, editor/gen/render, editor/gen/top, editor/gen/network, editor/gen/terrain, editor/gen/test |
| Size | ~17,800 lines - largest BAT module |
Key State
| Field | Type | Description |
|---|---|---|
W.ui | table | All UI-bound parameters (floor height, window spacing, material lists, seed, etc.) |
W.out | table | Runtime output state (selections, debug draws, mode flags) |
adesc | table | mesh_id → building_descriptor - all active buildings |
cedit | table | Current edit state: {mesh, part, forest, aforest, cval} |
dforest | table | forest_key → {item, mesh, type, ind, prn} - forest item registry |
ddae | table | dae_path → {type, fr, to, fo, list, w, h} - loaded DAE metadata |
Public Functions - Building Lifecycle
| Function | Description |
|---|---|
W.houseUp(desc, id) | Creates or updates a procedural building mesh from descriptor |
W.houseDown(desc, fkeep) | Converts procedural mesh to static TSStatic (fkeep = keep forest items) |
W.houseSave(desc, name) | Saves building to JSON + exports DAE + forest items to level |
W.daeExport() | COLLADA export dialog for current building with forest items |
W.toLevel(desc, pth) | Writes building DAE and forest placement JSON to level directory |
Public Functions - Editing
| Function | Description |
|---|---|
W.scopeOn(scope) | Sets edit scope: 'building', 'floor', 'wall', 'side', 'top' |
W.forScope() | Returns current scope and cij (floor/wall indices) |
W.markUp() | Updates visual selection markers |
W.matApply(name, index) | Applies material to current scope selection |
W.meshApply(type, index) | Applies mesh variant (window, door, etc.) |
W.selectionHide() | Toggles visibility of selected elements |
Public Functions - Forest Items
| Function | Description |
|---|---|
W.ifForest(types) | Checks if current selection has forest items of given types |
W.forDAE(type) | Returns DAE path list for given element type |
W.pref2dae(pref) | Resolves a DAE prefix group to its first DAE path |
W.splineUp(desc, ifloor, key, sdata) | Generates spline-based wall with window/door holes and forest items |
Public Functions - Session & Undo
| Function | Description |
|---|---|
W.onQuit(forestoff) | Cleanup on editor exit - removes edit group, forest items |
W.recover(jdesc, cb, keep) | Restores buildings from JSON descriptor table |
W.ifSaved() | Checks if session save file exists |
W.reload(mode) | Hot-reloads all sub-modules, optionally switches mode |
Public Functions - Terrain
| Function | Description |
|---|---|
W.conform(desc) | Conforms terrain to building footprint |
W.confSave() | Commits terrain modifications |
W.restore(tosave) | Reverts terrain height changes |
W.matUp() | Loads wall and roof material libraries from JSON files |
Building Descriptor Structure
desc = {
id = meshId, -- ProceduralMesh object ID
pos = vec3, -- World position
afloor = { -- Array of floors
{
h = 3.2, -- Floor height
pos = vec3, -- Floor offset
base = {vec3...}, -- Footprint polygon
awall = { -- Array of walls
{
u = vec3, -- Wall direction vector
v = vec3, -- Wall up vector
mat = "name", -- Material name
win = "path", -- Window DAE path
door = "path", -- Door DAE path
df = {}, -- Forest item registry {dae_path → {key_list}}
}
},
top = { -- Roof descriptor
shape = "ridge", -- flat/pyramid/shed/gable/ridge
margin = 0.4,
tip = 2,
mat = "material",
achild = {}, -- Child roof sections
}
}
},
data = {mdata...}, -- Compiled mesh data for rendering
}DAE Asset Loading
-- Assets loaded from standard path
local assetPath = '/art/shapes/common/building_architect_modules'
-- Element types loaded: windows, doors, corner, balcony, pillar,
-- store_front, stairs, basement_plinth, gutter, fire_stairs,
-- string_course, wall_pilaster, roof_borderModule Variables
adae(table) - Module variable.mpoint(any) - Module variable.dmat(any) - Module variable.pretest(any) - Module variable.
Functions
daeReg(pth, tp)
Handles dae reg.
pth(any)tp(any)
Returns: string.sub(s, 2)
forSpline()
Handles for spline.
Returns: boolean - true
forJSON(obj)
Handles for json.
obj(object)
Returns: end
floorClear(f)
Handles floor clear.
f(any)
Returns: end
atParent(desc)
Handles at parent.
desc(any)
Returns: end
selectionTurn(ang, center)
Handles selection turn.
ang(any)center(any)
Returns: desctop,base
building4test(num, R, center, istemplate)
Handles building4test.
num(number)R(any)center(any)istemplate(any)
Returns: end
buildingScan(desc, ondone)
Handles building scan.
desc(any)ondone(any)
buildingLOD(desc, arc)
Handles building lod.
desc(any)arc(any)
forRoof(desctop, cb)
Handles for roof.
desctop(any)cb(any)
Returns: end
matScale(scale)
Handles mat scale.
scale(vec3|number)
Returns: end
topClear(desctop)
Handles top clear.
desctop(any)
Returns: im.IsKeyDown(editor.keyModifiers.shift)
floorSplit(f, j, p, shapekeep)
Handles floor split.
f(any)j(any)p(any)shapekeep(any)
Returns: end
ray2rc(ray, floor)
Handles ray2rc.
ray(any)floor(any)
Returns: nil
floorChildrenOff(floor)
Handles floor children off.
floor(any)
Returns: newfloor
floorDel(desc, ind)
Handles floor del.
desc(any)ind(any)
Returns: end
voice2build(cmd)
Handles voice2build.
cmd(any)
Returns: end
overWall()
Handles over wall.
Returns: end
inView()
Handles in view.
Returns: end
cornerUp(desc, dae, toreplace)
Handles corner up.
desc(any)dae(any)toreplace(any)
Returns: a[1] < b[1]
hasExtra(tp, dobj)
Checks if has extra.
tp(any)dobj(any)
Returns: end
wallMatch(cw, f)
Handles wall match.
cw(any)f(any)
Returns: end
ifPairHit(ij)
Handles if pair hit.
ij(any)
Returns: nil,apair[i]
ifPairEnd(ij, dbg)
Handles if pair end.
ij(any)dbg(any)
Returns: nil,apair
childRebase(achild, val, sbase, j, cbase, toemu)
Handles child rebase.
achild(any)val(any)sbase(any)j(any)cbase(any)toemu(any)
Returns: end
mat2xml(fname)
Handles mat2xml.
fname(any)
persist(ahouse)
Handles persist.
ahouse(any)
forHit(ray, desc)
Handles for hit.
ray(any)desc(any)
toggle(tp, dae)
Handles toggle.
tp(any)dae(any)
clear(mode)
Handles clear.
mode(any)
forestEdit(key)
Handles forest edit.
key(string)
forestClean(desctop, dbg)
Handles forest clean.
desctop(any)dbg(any)
Returns: jsonEncode(adesc)
goAround(dir)
Handles go around.
dir(string)
matMove(ds, isrel)
Handles mat move.
ds(any)isrel(any)
partOn(id)
Handles part on.
id(number)
Returns: cij
isHidden()
Checks if hidden.
Returns: yes
wallSplit()
Handles wall split.
onKey(key)
Callback for key event.
key(string)
keyUD(dir)
Handles key ud.
dir(string)
keyRL(dir)
Handles key rl.
dir(string)
keyAlt(yes)
Handles key alt.
yes(any)
keyShift(yes)
Handles key shift.
yes(any)
mdown(rayCast, inject)
Handles mdown.
rayCast(any)inject(any)
Returns: forHit(ray, adesc[cedit.mesh])
mdrag(rayCast)
Handles mdrag.
rayCast(any)
mup(rayCast, inject)
Handles mup.
rayCast(any)inject(any)
mwheel(dir, rayCast)
Handles mwheel.
dir(string)rayCast(any)
Returns: boolean - true
windowsToggle()
Handles windows toggle.
Returns: v - start
doorToggle()
Handles door toggle.
pillarToggle()
Handles pillar toggle.
atticToggle()
Handles attic toggle.
corniceToggle()
Handles cornice toggle.
Returns: a[1] < b[1]
baseSet(nm)
Handles base set.
nm(any)
roofSet(nm)
Handles roof set.
nm(any)
forDesc()
Handles for desc.
Returns: adesc[cedit.mesh]
ifValid(tp)
Handles if valid.
tp(any)
Returns: boolean - true
ifRoof(nm)
Handles if roof.
nm(any)
Returns: boolean - false
ifTopRect()
Handles if top rect.
Returns: #base == 4 and isRect(base)
buildingGen(p, base, intest)
Handles building gen.
p(any)base(any)intest(any)
forHeight(flist, i)
Handles for height.
flist(any)i(number)
Returns: h
forSel()
Handles for sel.
Returns: adsc
forTop()
Handles for top.
Returns: desctop,base
forSide(ij, fromselect)
Handles for side.
ij(any)fromselect(any)
Returns: aij
base2world(desc, ij, p)
Handles base2world.
desc(any)ij(any)p(any)
Returns: table|any
onVal(key, val)
Callback for val event.
key(string)val(any)
onUpdate()
Callback for update event.
Missing Exports (Added by Audit)
up(d, inreload, inact, mode)
Main initialization/setup entry point.
d(any) - Init datainreload(boolean) - Whether called during reloadinact(any) - Active statemode(string) - Operating mode
undo()
Undoes the last building edit operation.
conform(desc)
Conforms terrain to building footprint.
desc(table) - Building descriptor
confSave()
Commits terrain height modifications to the terrain block.
restore(tosave)
Reverts terrain height changes.
tosave(boolean) - Whether to save before restoring
M.wallCut()
Empty stub on the extension module table (M). No-op.
Exported Fields
| Field | Type | Description |
|---|---|---|
W.ui | table | All UI-bound parameters |
W.out | table | Runtime output state |
W.adesc | table | mesh_id → building_descriptor registry |
W.dmat | table | Material dictionaries (wall, roof, ext, road) |
W.test | any | Test module reference |
W.pretest | any | Pre-test state |
W.mpoint | any | Mouse point state |
See Also
- Gen Decal Editor - Related reference
- Gen Experimental Frame Editor - Related reference
- Gen Mesh Explorer - Related reference
- World Editor Guide - Guide
Editor Gen Utils
Core utility library for the Building Architect Tool. Provides geometric math (line intersection, polygon operations, splines), array/string helpers, debug drawing, camera control, file I/O, and the s
Gen AI Library
Gradient descent optimization library for the gen editor's experimental tools.