Mesh Primitives
App: apps/mesh_primitives/
Demonstrates the MeshGen procedural mesh factories (engine PLM-244 /
ADR 0082), part of Block SPL (splines / geometry / scatter). One of each primitive —
box, cylinder, cone, plane, grid — is laid out in a row, with a sine-wave heightmap terrain
behind them. Everything is built by the device-free modules/geometry core and drawn
immediate-mode with a lit N·L shader, so the shapes’ generated normals shade correctly.
Run from root
Section titled “Run from root”% ./plume3d mesh_primitivesA front, raised camera looks at the row of primitives with the heightmap terrain behind. The demo captures a screenshot at frame 60 and exits at frame 80.
What it does
Section titled “What it does”-
Builds one of each
MeshGenfactory, tints the returnedMeshwithsetColor, and lays them out along X — each factory returns a plainMeshyou draw like any other:var box = MeshGen.box(1.4, 1.4, 1.4) // AABB = ±(1.4)/2, per-face normalsbox.setColor(0.85, 0.30, 0.28, 1.0)var cyl = MeshGen.cylinder(0.75, 1.7, 28, true) // capped, about Yvar cone = MeshGen.cone(0.95, 1.9, 28, true) // apex up, capped basevar plane = MeshGen.plane(1.9, 1.9, 4, 4) // 4×4 quads, faces +Yvar grid = MeshGen.grid(8, 8, 0.28, 0.28) // exactly 8×8 vertices -
Builds a sine-wave heightmap terrain — a flat list of
n·nsamples (row-major, X fastest) fed toMeshGen.heightmap, which displaces a grid in Y and recomputes normals:var n = 32var heights = []for (iz in 0...n) {for (ix in 0...n) {heights.add(((ix * 0.45).sin * (iz * 0.4).cos) * 0.6)}}_terrain = MeshGen.heightmap(heights, n, n, 0.6, 0.6, 1.0)_terrain.setColor(0.45, 0.40, 0.34, 1.0) -
Draws the terrain first, then the primitive row, each with a column-major translation matrix passed to
Graphics.drawMesh:Graphics.drawMesh(_terrain, _shader, trans(0, -2.0, -3))for (it in _items) {Graphics.drawMesh(it[0], _shader, trans(it[1], it[2], it[3]))}
- Each primitive is centered at the origin, Y up — the demo positions them purely with the model matrix, never by baking an offset into the geometry.
- The lit shader proves the generated normals are correct: the box reads with hard edges
(per-face normals), the cylinder/cone/heightmap shade smoothly (per-vertex normals), and the
heightmap’s gentle gradients show
computeNormalsworking on the displaced surface. - The plane and grid are lifted and face the camera so their
+Y-facing surface is visible from the front-above view.
See MeshGen for the full factory surface — plane / grid / box / cylinder / cone / heightmap, the centered/Y-up conventions, and the tangents-deferred note.