code wiki / (root) / nx_wasmvox3d.nx

nx_wasmvox3d.nx

buildroot/runtime/nx_wasmvox3d.nx

15497 B375 linesdepth 1pulls 1 transitivereach 1 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_wasmvox3d.nx -- TRUE 3D VOXEL world (per-voxel faces, not column boxes) so you can dig holes/tunnels and stack blocks. Base-relative (same code runs native->PNG and wasm->browser). The world = a natural heightmap PLUS a 2-bit-packed 3D edit grid (0=default, 1=placed-solid, 2=dug-air). Render draws only EXPOSED faces of solid voxels (face to an air neighbor) -> tunnels/overhangs/floating blocks all work. Scoped small (48x48x18, 192x144) for software-raster speed. Reuses the proven f32 + raster math. license_tier: ORIGINAL

dependencies 1 imports · 1 importers

nx_f32_hw.nx nx_wasmvox3d.nx nx_wasmvox3d_gate.nx

imports: nx_f32_hw.nx

imported by: nx_wasmvox3d_gate.nx

structs

none

consts

7const O_MAGIC_65536: i64 = 65536
9const W: i64 = 192
10const H: i64 = 144
11const HW: i64 = 96
12const HH: i64 = 72
13const ZFAR: i64 = 1073741824
14const FOCAL: i64 = 150
15const WN: i64 = 48
16const YMAX: i64 = 18
17const WSEED: i64 = 7
18const WWATER: i64 = 3
19const WMAXH: i64 = 12
20const WLAT: i64 = 6
21const VDIST: i64 = 14
23const O_FB: i64 = 0
24const O_ZB: i64 = 221184 // W*H*8
25const O_R: i64 = 442368
26const O_RY: i64 = 442496
27const O_RX: i64 = 442624
28const O_V: i64 = 442752
29const O_RV: i64 = 442784
30const O_SX: i64 = 442816
31const O_SY: i64 = 442880
32const O_SD: i64 = 442944
33const O_SOK: i64 = 443008
34const O_PJ: i64 = 443072
35const O_HC: i64 = 443136 // per-column height cache, WN*WN i64
36const O_GRID: i64 = 461568 // 2-bit 3D edit grid: WN*WN*YMAX cells / 32 per i64

functions

38func imin(a: i64, b: i64) -> i64 { if a < b { return a } return b }
called by 2: min3fill_z
39func imax(a: i64, b: i64) -> i64 { if a > b { return a } return b }
called by 2: max3fill_z
40func min3(a: i64, b: i64, c: i64) -> i64 { return imin(a, imin(b, c)) }
called by 1: fill_z calls 1: imin
41func max3(a: i64, b: i64, c: i64) -> i64 { return imax(a, imax(b, c)) }
called by 1: fill_z calls 1: imax
42func clamp255(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v }
called by 1: shade
43func fratio(num: i64, den: i64) -> i64 { return f32_div(f32_of(num), f32_of(den)) }
called by 1: build_R calls 2: f32_divf32_of
45func wlat(ix: i64, iz: i64) -> i64
called by 1: terrain_h0
51func terrain_h0(gx: i64, gz: i64) -> i64
70func grid_idx(gx: i64, gy: i64, gz: i64) -> i64 { return (gy * WN + gz) * WN + gx }
called by 2: getcellsetcell
71func getcell(base: i64, gx: i64, gy: i64, gz: i64) -> i64
called by 1: solid_h calls 1: grid_idx
76func setcell(base: i64, gx: i64, gy: i64, gz: i64, v: i64) -> i64
called by 3: break_atplace_atmain calls 1: grid_idx
85func solid_h(base: i64, gx: i64, gy: i64, gz: i64, hcol: i64) -> i64
called by 1: solid calls 2: getcellterrain_h0
100func solid(base: i64, gx: i64, gy: i64, gz: i64) -> i64
108func voxel_color(gy: i64, top: i64) -> i64
called by 1: draw_voxel
118func shade(lnx: i64, lny: i64, lnz: i64) -> i64
called by 1: face calls 1: clamp255
123func packc(col: i64, bright: i64) -> i64
called by 1: face
129func fill_z(base: i64, x0: i64, y0: i64, d0: i64, x1: i64, y1: i64, d1: i64, x2: i64, y2: i64, d2: i64, col: i64) -> i64
called by 1: face calls 4: imaxmin3iminmax3
159func project(base: i64, camx: i64, camy: i64, camz: i64, iwx: i64, iwy: i64, iwz: i64) -> i64
179func corners(base: i64, camx: i64, camy: i64, camz: i64, x0: i64, y0: i64, z0: i64) -> i64
called by 1: draw_voxel calls 1: project
193func face(base: i64, a: i64, b: i64, c: i64, dd: i64, lnx: i64, lny: i64, lnz: i64, col: i64) -> i64
208func draw_voxel(base: i64, camx: i64, camy: i64, camz: i64, gx: i64, gy: i64, gz: i64) -> i64
220func corners_sz(base: i64, camx: i64, camy: i64, camz: i64, x0: i64, y0: i64, z0: i64, sw: i64, sh: i64, sl: i64) -> i64
called by 1: draw_solidbox calls 1: project
234func draw_solidbox(base: i64, camx: i64, camy: i64, camz: i64, x0: i64, y0: i64, z0: i64, sw: i64, sh: i64, sl: i64, col: i64) -> i64
called by 1: draw_tree calls 2: corners_szface
243func has_tree(gx: i64, gz: i64) -> i64
called by 1: render_at calls 1: terrain_h0
252func draw_tree(base: i64, camx: i64, camy: i64, camz: i64, gx: i64, gz: i64) -> i64
called by 1: render_at calls 2: terrain_h0draw_solidbox
258func render_at(base: i64, camx: i64, camy: i64, camz: i64, cgx: i64, cgz: i64) -> i64
301func build_R(base: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64
310func mem_bytes() -> i64 { return O_GRID + (WN * WN * YMAX / 32 + 4) * 8 }
called by 1: main
312func surface_y(base: i64, gx: i64, gz: i64) -> i64
called by 1: terrain_at calls 1: solid
319func raycast(base: i64, camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64, out: *i64) -> i64
called by 2: break_atplace_at calls 1: solid
345func render(camx256: i64, camy256: i64, camz256: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64
353func terrain_at(gx: i64, gz: i64) -> i64
359func break_at(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64
calls 2: raycastsetcell
366func place_at(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64
calls 2: raycastsetcell
372func fb_off() -> i64 { return O_FB }
called by 1: main
373func ww() -> i64 { return W }
called by 1: main
374func hh() -> i64 { return H }
called by 1: main
375func main() -> i64 { return 0 }