nx_meshrender.nx
buildroot/runtime/nx_meshrender.nx
about
nx_meshrender.nx -- LIB: SOVEREIGN GENERAL TRIANGLE-MESH RENDERER (the keystone rung above nx_render_core).
Transforms + projects + z-buffer-rasterizes an ARBITRARY loaded triangle mesh (CAD STL / game asset) through
OUR OWN pipeline -- no OpenGL, no WebGL, no 3rd-party graphics. render_core gives the z-buffered triangle
primitive + Q14 perspective/mat4/sovereign-trig; this composes them over a vertex+index buffer so any mesh
renders, z-correct, in software (rule 15/22: compose, re-implement nothing). HAL-FREE (no syscalls, all
buffers caller-supplied) so the IDENTICAL code compiles to --target wat/wasm -> the mesh renders in ANY
browser via OUR sovereign WASM (the "emit, don't use 3rd party" path that nx_wasmcube/nx_pets3d_wasm proved).
license_tier: ORIGINAL
Vertex layout (stride 4 i64): [x_q14, y_q14, z_q14, packed_rgba]. Index layout (stride 3 i64): [i0,i1,i2].
Caller supplies scratch: proj/roty/mv/trans/mvp (16 i64 each), vbuf/clipbuf (4 i64), scr (nverts*4 i64:
[screen_x, screen_y, depth_q14, visible]), tribuf (12 i64). fb/zb = w*h i64. Returns triangles drawn.
dependencies 1 imports · 8 importers
imports: nx_render_core.nx
imported by: nx_explode3d_gate.nxnx_mechparts_gate.nxnx_meshlit_gate.nxnx_meshrender_gate.nxnx_render3d.nxnx_skin_gate.nxnx_skinnorm_gate.nxnx_spec_gate.nx
structs
| none |
consts
| 14 | const MR_MAGIC_65536: i64 = 65536 |
| 15 | const MR_MAGIC_16777216: i64 = 16777216 |
| 17 | const MR_NEAR: i64 = 16384 // 1.0 in Q14 (near plane) |
| 18 | const MR_FAR: i64 = 16384000 // 1000.0 in Q14 (far plane) |
functions
| 21 | func mr_roty(deg: i64, out: *i64) -> i64 |
| 37 | func mr_project(mvp: *i64, vx: i64, vy: i64, vz: i64, w: i64, h: i64, vbuf: *i64, clipbuf: *i64, scr: *i64, base: i64) -> i64 |
| 57 | func mr_dot3(ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64) -> i64 { return (ax * bx + ay * by + az * bz) / RC_Q } called by 1: mr_lambert |
| 59 | func mr_lambert(nx: i64, ny: i64, nz: i64, lx: i64, ly: i64, lz: i64) -> i64 { let d: i64 = mr_dot3(nx, ny, nz, lx, ly, lz); if d < 0 { return 0 } return d } |
| 61 | func mr_rotn(c: i64, s: i64, nx: i64, ny: i64, nz: i64, out: *i64) -> i64 { out[0] = (c * nx + s * nz) / RC_Q; out[1] = ny; out[2] = ((0 - s) * nx + c * nz) / RC_Q; return 0 } |
| 63 | func mr_shade(rgba: i64, b: i64, amb: i64) -> i64 |
| 77 | func mr_skin2(rest: *i64, m0: *i64, w0: i64, m1: *i64, w1: i64, tmp: *i64, out: *i64) -> i64 |
| 93 | func mr_isqrt(n: i64) -> i64 |
| 109 | func mr_face_lambert(p0x: i64, p0y: i64, p0z: i64, p1x: i64, p1y: i64, p1z: i64, p2x: i64, p2y: i64, p2z: i64, lx: i64, ly: i64, lz: i64) -> i64 |
| 126 | func mr_pow_q14(base: i64, n: i64) -> i64 |
| 139 | func mr_face_specular(p0x: i64, p0y: i64, p0z: i64, p1x: i64, p1y: i64, p1z: i64, p2x: i64, p2y: i64, p2z: i64, lx: i64, ly: i64, lz: i64, vx: i64, vy: i64, vz: i64, shin: i64) -> i64 |
| 166 | func mr_render(verts: *i64, nverts: i64, idx: *i64, ntris: i64, proj: *i64, roty: *i64, mv: *i64, trans: *i64, mvp: *i64, vbuf: *i64, clipbuf: *i64, scr: *i64, tribuf: *i64, fb: *i64, zb: *i64, w: i64, h: i64, angle_deg: i64, dist: i64, fov_half_deg: i64, bg: i64) -> i64 |