VegGeo: the flat-array mesh kit the tropicalProps vegetation generators build with.
local G = require("~.VegGeo")
local g = G.new()
local a = G.vertex(g, x,y,z, nx,ny,nz, u,v, r,gg,b,a) -- 0-based index
G.tri(g, a, b, c) -- counter-clockwise = front
G.tube(g, path, { sides = 10, radius = function(i, t) ... end })
G.flatten(g) -- faceted copy (lowpoly look)
G.bake("tropicalProps.package/meshes/veg/coconut", "coconut_real_v1_l0_husk", g, true)
Vertex colour follows the tropicalProps mesh contract: RGB is a tint the
material multiplies its albedo by; ALPHA is the wind-sway weight on foliage
(0 rigid at the base, 1 full sway at the tips). Solid parts are baked with
alpha 1 (`solid`). Metres, +Y up, origin at the ground contact.
vert(g: Geometry, p: Vec, n: Vec, u: number, v: number, col: Vec, a: number) → number
vertex from vector tables: position p, normal n, uv, colour {r,g,b}, alpha
| arg | type | description |
|---|
| g | Geometry | |
| p | Vec | |
| n | Vec | |
| u | number | |
| v | number | |
| col | Vec | |
| a | number | |
tri(g: Geometry, a: number, b: number, c: number) → void
| arg | type | description |
|---|
| g | Geometry | |
| a | number | |
| b | number | |
| c | number | |
quad(g: Geometry, a: number, b: number, c: number, d: number) → void
| arg | type | description |
|---|
| g | Geometry | |
| a | number | |
| b | number | |
| c | number | |
| d | number | |
triCount(g: Geometry) → number
| arg | type | description |
|---|
| g | Geometry | |
append(dst: Geometry, src: Geometry) → void
| arg | type | description |
|---|
| dst | Geometry | |
| src | Geometry | |
bounds(g: Geometry) → void
| arg | type | description |
|---|
| g | Geometry | |
orient(g: { positions: { number }, normals: { number }, indices: { number } }) → number
Make every triangle's winding agree with its vertex normals (front = counter-clockwise). Returns how many were flipped.
| arg | type | description |
|---|
| g | { positions: { number }, normals: { number }, indices: { number } } | |
solid(g: { colors: { number }? }) → void
Vertex alpha 1 everywhere (RGB kept): the contract for solid parts.
| arg | type | description |
|---|
| g | { colors: { number }? } | |
flatten(g: Geometry) → Geometry
A faceted copy of g: every triangle gets its own three vertices carrying the face normal (turned to the side the original vertex normals faced). The lowpoly look.
| arg | type | description |
|---|
| g | Geometry | |
shareBounds(parts: { any }) → void
Give every part of one prop the same bounds (two unreferenced corner vertices), so MeshLod measures every part as the whole prop and all parts swap LOD together.
| arg | type | description |
|---|
| parts | { any } | |
bake(folder: string, name: string, g: Geometry, solid: boolean?) → any
Write g as a durable .mesh asset at <folder>/<name>.mesh (folder relative to /zero/source), replacing an earlier bake. Winding is made to agree with the normals first; `solid` sets vertex alpha to 1.
| arg | type | description |
|---|
| folder | string | |
| name | string | |
| g | Geometry | |
| solid | boolean? | |
v(x: number, y: number, z: number) → Vec return
| arg | type | description |
|---|
| x | number | |
| y | number | |
| z | number | |
add(a: Vec, b: Vec) → Vec return
| arg | type | description |
|---|
| a | Vec | |
| b | Vec | |
sub(a: Vec, b: Vec) → Vec return
| arg | type | description |
|---|
| a | Vec | |
| b | Vec | |
scale(a: Vec, s: number) → Vec return
| arg | type | description |
|---|
| a | Vec | |
| s | number | |
madd(a: Vec, b: Vec, s: number) → Vec return
| arg | type | description |
|---|
| a | Vec | |
| b | Vec | |
| s | number | |
dot(a: Vec, b: Vec) → number return a
| arg | type | description |
|---|
| a | Vec | |
| b | Vec | |
cross(a: Vec, b: Vec) → Vec
| arg | type | description |
|---|
| a | Vec | |
| b | Vec | |
len(a: Vec) → number return sqrt
lerp(a: Vec, b: Vec, t: number) → Vec
| arg | type | description |
|---|
| a | Vec | |
| b | Vec | |
| t | number | |
rotate(v: Vec, k: Vec, angle: number) → Vec
Rotate v about unit axis k by angle (Rodrigues).
| arg | type | description |
|---|
| v | Vec | |
| k | Vec | |
| angle | number | |
dir(az: number, el: number) → Vec
Unit direction from azimuth (radians, 0 = +Z, pi/2 = +X) and elevation above horizontal (radians).
| arg | type | description |
|---|
| az | number | |
| el | number | |
rng(seed: number) → Rng
| arg | type | description |
|---|
| seed | number | |
range(r: Rng, a: number, b: number) → number
| arg | type | description |
|---|
| r | Rng | |
| a | number | |
| b | number | |
hash(s: string) → number
| arg | type | description |
|---|
| s | string | |
noise1(x: number, seed: number) → number
Smooth 1D value noise in [-1,1].
| arg | type | description |
|---|
| x | number | |
| seed | number | |
h(n: number) → number
| arg | type | description |
|---|
| n | number | |
frames(path: { Vec }, firstNormal: Vec?) → void
Parallel-transport frames along a polyline: tangents T, normals N, binormals B, and arc length s (metres) at each point.
| arg | type | description |
|---|
| path | { Vec } | |
| firstNormal | Vec? | |
along(path: { Vec }, S: { number }, t: number) → void
Point and tangent at fraction t (0..1, by arc length) along a polyline.
| arg | type | description |
|---|
| path | { Vec } | |
| S | { number } | |
| t | number | |
tube(g: Geometry, path: { Vec }, o: TubeOpts) → void
A tube along a polyline with parallel-transport frames. UVs: u wraps the ring (uTiles per revolution), v = metres along / vScale. Returns ring vertex indices.
| arg | type | description |
|---|
| g | Geometry | |
| path | { Vec } | |
| o | TubeOpts | |
cap(i: number, dirSign: number) → void
| arg | type | description |
|---|
| i | number | |
| dirSign | number | |
blade(g: Geometry, spine: { Vec }, side: { Vec }, up: { Vec }, width: (t: number) → void
A leaf blade along a spine: `width(t)` gives the half-width at t (0 base .. 1 tip), `side[i]` the across direction at node i, `fold` lifts the edges (negative droops them) relative to `up[i]`. UVs: u 0..1 across (midrib at 0.5), v 0 base -> 1 tip. Alpha from `alpha(t)`. Returns triangles added.
| arg | type | description |
|---|
| g | Geometry | |
| spine | { Vec } | |
| side | { Vec } | |
| up | { Vec } | |
| width | (t: number | |