nx_wasmvox3d.nx
buildroot/runtime/nx_wasmvox3d.nx
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
imports: nx_f32_hw.nx
imported by: nx_wasmvox3d_gate.nx
structs
| none |
consts
| 7 | const O_MAGIC_65536: i64 = 65536 |
| 9 | const W: i64 = 192 |
| 10 | const H: i64 = 144 |
| 11 | const HW: i64 = 96 |
| 12 | const HH: i64 = 72 |
| 13 | const ZFAR: i64 = 1073741824 |
| 14 | const FOCAL: i64 = 150 |
| 15 | const WN: i64 = 48 |
| 16 | const YMAX: i64 = 18 |
| 17 | const WSEED: i64 = 7 |
| 18 | const WWATER: i64 = 3 |
| 19 | const WMAXH: i64 = 12 |
| 20 | const WLAT: i64 = 6 |
| 21 | const VDIST: i64 = 14 |
| 23 | const O_FB: i64 = 0 |
| 24 | const O_ZB: i64 = 221184 // W*H*8 |
| 25 | const O_R: i64 = 442368 |
| 26 | const O_RY: i64 = 442496 |
| 27 | const O_RX: i64 = 442624 |
| 28 | const O_V: i64 = 442752 |
| 29 | const O_RV: i64 = 442784 |
| 30 | const O_SX: i64 = 442816 |
| 31 | const O_SY: i64 = 442880 |
| 32 | const O_SD: i64 = 442944 |
| 33 | const O_SOK: i64 = 443008 |
| 34 | const O_PJ: i64 = 443072 |
| 35 | const O_HC: i64 = 443136 // per-column height cache, WN*WN i64 |
| 36 | const O_GRID: i64 = 461568 // 2-bit 3D edit grid: WN*WN*YMAX cells / 32 per i64 |
functions
| 38 | func imin(a: i64, b: i64) -> i64 { if a < b { return a } return b } |
| 39 | func imax(a: i64, b: i64) -> i64 { if a > b { return a } return b } |
| 40 | func min3(a: i64, b: i64, c: i64) -> i64 { return imin(a, imin(b, c)) } |
| 41 | func max3(a: i64, b: i64, c: i64) -> i64 { return imax(a, imax(b, c)) } |
| 42 | func clamp255(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v } called by 1: shade |
| 43 | func fratio(num: i64, den: i64) -> i64 { return f32_div(f32_of(num), f32_of(den)) } |
| 45 | func wlat(ix: i64, iz: i64) -> i64 called by 1: terrain_h0 |
| 51 | func terrain_h0(gx: i64, gz: i64) -> i64 |
| 70 | func grid_idx(gx: i64, gy: i64, gz: i64) -> i64 { return (gy * WN + gz) * WN + gx } |
| 71 | func getcell(base: i64, gx: i64, gy: i64, gz: i64) -> i64 |
| 76 | func setcell(base: i64, gx: i64, gy: i64, gz: i64, v: i64) -> i64 |
| 85 | func solid_h(base: i64, gx: i64, gy: i64, gz: i64, hcol: i64) -> i64 |
| 100 | func solid(base: i64, gx: i64, gy: i64, gz: i64) -> i64 |
| 108 | func voxel_color(gy: i64, top: i64) -> i64 called by 1: draw_voxel |
| 118 | func shade(lnx: i64, lny: i64, lnz: i64) -> i64 |
| 123 | func packc(col: i64, bright: i64) -> i64 called by 1: face |
| 129 | func 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 |
| 159 | func project(base: i64, camx: i64, camy: i64, camz: i64, iwx: i64, iwy: i64, iwz: i64) -> i64 |
| 179 | func corners(base: i64, camx: i64, camy: i64, camz: i64, x0: i64, y0: i64, z0: i64) -> i64 |
| 193 | func face(base: i64, a: i64, b: i64, c: i64, dd: i64, lnx: i64, lny: i64, lnz: i64, col: i64) -> i64 |
| 208 | func draw_voxel(base: i64, camx: i64, camy: i64, camz: i64, gx: i64, gy: i64, gz: i64) -> i64 |
| 220 | func corners_sz(base: i64, camx: i64, camy: i64, camz: i64, x0: i64, y0: i64, z0: i64, sw: i64, sh: i64, sl: i64) -> i64 |
| 234 | func 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 |
| 243 | func has_tree(gx: i64, gz: i64) -> i64 |
| 252 | func draw_tree(base: i64, camx: i64, camy: i64, camz: i64, gx: i64, gz: i64) -> i64 |
| 258 | func render_at(base: i64, camx: i64, camy: i64, camz: i64, cgx: i64, cgz: i64) -> i64 |
| 301 | func build_R(base: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64 |
| 310 | func mem_bytes() -> i64 { return O_GRID + (WN * WN * YMAX / 32 + 4) * 8 } called by 1: main |
| 312 | func surface_y(base: i64, gx: i64, gz: i64) -> i64 |
| 319 | func raycast(base: i64, camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64, out: *i64) -> i64 |
| 345 | func render(camx256: i64, camy256: i64, camz256: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64 |
| 353 | func terrain_at(gx: i64, gz: i64) -> i64 |
| 359 | func break_at(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64 |
| 366 | func place_at(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64 |
| 372 | func fb_off() -> i64 { return O_FB } called by 1: main |
| 373 | func ww() -> i64 { return W } called by 1: main |
| 374 | func hh() -> i64 { return H } called by 1: main |
| 375 | func main() -> i64 { return 0 } |