editor_heroRoadEditor_mesh¶
File: lua/ge/extensions/editor/heroRoadEditor/mesh.lua · VM: Game Engine (GE) · 1113 lines · BeamNG.drive 0.40.5 (buildbot 302427 on GitLab)
Access: extension editor_heroRoadEditor_mesh: extensions.load("editor_heroRoadEditor_mesh"), then the global editor_heroRoadEditor_mesh
Generation of a group's procedural driving mesh in the Hero Road Editor. Sweeps the profile.lua cross-sections along the 3D centerline (divPoints): roadway, shoulders, peripheral chamfers, carved potholes, and surface groups (groundmodels) distributed by material. Produces ProceduralMeshes with collision for editing (named 'HeroRoad_
Notes¶
- The editable surface IS LOD0: the live mesh is built with the same tolerance as the near level of the bake; the coarser LODs are only produced at bake time (buildChunkLODs).
- Chunk splitting: length chunkLenM (default 120, min 20 m); no cut if the road is at most 1.5 chunks long. The cuts are shared by all LODs and the collision to avoid cracks.
- LOD scale (size px / quality cm / max triangle length m): LOD0 400 / 1.0 / 20, LOD1 150 / 3.0 / 30, LOD2 40 / 8.0 / 45 (fields group.lodSize0..2, lodQualityCm0..2, lodMaxSegM0..2). If group.lodFarNull ~= false (default), the last level becomes a 'nulldetail' level (nothing is drawn below its size) and nullSize is returned. The coarsest visible LOD removes the chamfer. A LOD is only kept if it saves more than 2 % of triangles compared to the previous one.
- Collision: detailed roadway surface without chamfer, tolerance group.collisionTolCm (default 1.0 cm), max length group.lodMaxSegM0 (20 m). Potholes are only carved in LOD0 and the collision.
- Constants: default material 'm_asphalt_new_01' (roadway and shoulder), 4 m x 4 m texture, chamfer 0.6 m wide for 0.1 m drop (max angle 70 degrees), coplanar extension of 1.0 m beyond each end (so that decals drape entirely).
- The live ProceduralMeshes have canSave=false: they are rebuilt from the spline at load.
- The default of group.latRes is 4 in profile.lua but 16 in the lodPreview cache signature and at group creation (groupMgr); only the default of the new group (16) matters in practice.
Functions¶
| Function | Description | Line |
|---|---|---|
editor_heroRoadEditor_mesh.buildChunkLODs(group, chunkLenM) |
Builds the entire bake payload: for each chunk of about chunkLenM, its set of visible LODs and a roadway-only collision mesh. The cuts are computed once from the full-resolution arc length and shared by all levels. LODs with a nearly equal triangle count are dropped. | 883 |
editor_heroRoadEditor_mesh.buildExportParts(group, opts, jLo, jHi, isFirst, isLast, cutArcs) |
Assembles the driving geometry into a list of material parts (meshPart); this is the internal assemble function exported under this name. Overwrites the group's derived fields (edges, grid, vArc, triCount...). With jLo/jHi, only builds the stations of that chunk. | 371 |
editor_heroRoadEditor_mesh.buildRibbonEdges(group) |
LIGHT rebuild of only the outer top edges (group.meshEdgeL/R) during a drag, when grid, collision and decals are torn down. Reuses profile.build and worldStation on the two extreme points of the cross-section, with the same end extension: the ribbon follows exactly the edge the full mesh will have. Also updates group.divBankR (banked right axis, for the heat map). Clears the edges if the geometry is insufficient. | 1033 |
editor_heroRoadEditor_mesh.buildTerrainEdges(group) |
Builds FLAT edge references (leveled horizontally) for a road in terrain mode: group.meshEdgeL/R offset by leftExtM/rightExtM (default 4.0 m) along the binormal, meshEdgeDirL/R, meshEdgeUp = (0,0,1), and sets meshGrid to nil (no roadway grid in terrain mode). | 1068 |
editor_heroRoadEditor_mesh.chunkCount(total, chunkLenM) |
Number of DAE chunks a bake will produce for a given total arc length and chunk length (mirrors the baker). The interface must pass the same arc length as the bake (group.meshVArc[end]). | 810 |
editor_heroRoadEditor_mesh.lodPreview(group) |
Computes, for the Export panel, the triangle count of the whole road for each visible LOD. The result is cached per group (signature of the LOD, resolution, geometry and pothole parameters) and the group's derived fields overwritten by the assembly are restored afterwards. Also writes group.lodMaxEdgeM. | 924 |
editor_heroRoadEditor_mesh.removeMesh(group) |
Deletes the group's ProceduralMeshes: the legacy one without suffix ('HeroRoad_ |
68 |
editor_heroRoadEditor_mesh.updateMesh(group) |
Rebuilds the group's live LOD0 (near level) mesh: deletes the old one, assembles the geometry, splits it into chunks, creates a ProceduralMesh with collision per chunk in the group's scene folder and fills group.meshIds / group.meshId. Called by the rebuild pipeline on every modification; does nothing without a scene folder (sceneTreeFolderId). | 1098 |
Parameter details¶
editor_heroRoadEditor_mesh.buildChunkLODs(group, chunkLenM)¶
Builds the entire bake payload: for each chunk of about chunkLenM, its set of visible LODs and a roadway-only collision mesh. The cuts are computed once from the full-resolution arc length and shared by all levels. LODs with a nearly equal triangle count are dropped.
group(table) : Hero Road group.chunkLenM(number|nil) : Chunk length in meters (min 20, default 120).- returns: table|nil List of chunks { lods = { {size, parts}, ... }, col = { part, ... } }, or nil if there is nothing to build.
- returns: number|nil nullSize: size in px of the far 'nulldetail' level, or nil if the last level is a visible LOD.
editor_heroRoadEditor_mesh.buildExportParts(group, opts, jLo, jHi, isFirst, isLast, cutArcs)¶
Assembles the driving geometry into a list of material parts (meshPart); this is the internal assemble function exported under this name. Overwrites the group's derived fields (edges, grid, vArc, triCount...). With jLo/jHi, only builds the stations of that chunk.
group(table) : Hero Road group (divPoints, tangents, materials, profile parameters).opts(table|nil) : Options: tol (decimation tolerance in m, nil = full resolution), maxSeg (max segment length in m), emitChamfer (false to omit the chamfers), potholes (true to carve the potholes).jLo(integer|nil) : First station of the chunk.jHi(integer|nil) : Last station of the chunk.isFirst(boolean|nil) : Start-of-road chunk (inferred from code).isLast(boolean|nil) : End-of-road chunk (inferred from code).cutArcs(number[]|nil) : Arc positions (m) of the chunk cuts.- returns: table|nil List of parts (material, vertices, faces), or nil if the geometry is insufficient.
editor_heroRoadEditor_mesh.buildRibbonEdges(group)¶
LIGHT rebuild of only the outer top edges (group.meshEdgeL/R) during a drag, when grid, collision and decals are torn down. Reuses profile.build and worldStation on the two extreme points of the cross-section, with the same end extension: the ribbon follows exactly the edge the full mesh will have. Also updates group.divBankR (banked right axis, for the heat map). Clears the edges if the geometry is insufficient.
group(table) : Hero Road group.
editor_heroRoadEditor_mesh.buildTerrainEdges(group)¶
Builds FLAT edge references (leveled horizontally) for a road in terrain mode: group.meshEdgeL/R offset by leftExtM/rightExtM (default 4.0 m) along the binormal, meshEdgeDirL/R, meshEdgeUp = (0,0,1), and sets meshGrid to nil (no roadway grid in terrain mode).
group(table) : Hero Road group (divPoints, binormals).
editor_heroRoadEditor_mesh.chunkCount(total, chunkLenM)¶
Number of DAE chunks a bake will produce for a given total arc length and chunk length (mirrors the baker). The interface must pass the same arc length as the bake (group.meshVArc[end]).
total(number) : Total arc length in meters.chunkLenM(number|nil) : Chunk length in meters (min 20, default 120).- returns: integer Number of chunks (at least 1).
editor_heroRoadEditor_mesh.lodPreview(group)¶
Computes, for the Export panel, the triangle count of the whole road for each visible LOD. The result is cached per group (signature of the LOD, resolution, geometry and pothole parameters) and the group's derived fields overwritten by the assembly are restored afterwards. Also writes group.lodMaxEdgeM.
group(table) : Hero Road group.- returns: table { lods = { {size, tris, kept}, ... }, nullSize = number|nil }; kept indicates whether the level is kept at bake.
editor_heroRoadEditor_mesh.removeMesh(group)¶
Deletes the group's ProceduralMeshes: the legacy one without suffix ('HeroRoad_
group(table) : Hero Road group.
editor_heroRoadEditor_mesh.updateMesh(group)¶
Rebuilds the group's live LOD0 (near level) mesh: deletes the old one, assembles the geometry, splits it into chunks, creates a ProceduralMesh with collision per chunk in the group's scene folder and fills group.meshIds / group.meshId. Called by the rebuild pipeline on every modification; does nothing without a scene folder (sceneTreeFolderId).
group(table) : Hero Road group.
Calls into the engine (C++)¶
obj:deletescenetree.findObject,findObjectById
tim19Atlas (Tim0219800) — derived from BeamNG GmbH Lua code (bCDDL 1.1, see LICENSE). Source: lua/ge/extensions/editor/heroRoadEditor/mesh.lua.