nx_meshview_wasm.nx
buildroot/runtime/nx_meshview_wasm.nx
about
nx_meshview_wasm.nx -- R3: the sovereign general-mesh renderer EMITTED to WASM (runs in ANY browser via OUR
software rasterizer -- zero WebGL, zero NVIDIA, zero Emscripten). Composes the HAL-free nx_render_core
(z-buffered Pineda raster + Q14 perspective/mat4/Bhaskara-trig) over a loaded vertex+index mesh held at fixed
linear-memory offsets (the proven nx_pets3d_wasm/nx_wasmcube wasm memory model: NO sys_mmap -- wasm has no
syscalls). The browser's ONLY job is to call mv_render(angle) and blit the framebuffer to a <canvas>; ALL
transform/projection/rasterization is sovereign Nishi. Mirrors the native nx_meshrender logic so the wasm
build is bit-faithful to native (proven by nx_meshview_wasm_gate via nx_wasm_vm). Compiles through the
SOVEREIGN chain: nx_compile_wat -> nx_wat_compiler -> .wasm. license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_render_core.nx
imported by: nobody (leaf or entry point)
structs
| none |
consts
| 11 | const MV_W: i64 = 64 |
| 12 | const MV_H: i64 = 64 |
| 13 | const MV_N: i64 = 4096 // 64*64 |
| 14 | const VQ: i64 = 16384 // Q14 one (== RC_Q) |
| 15 | const DIST: i64 = 65536 // 4.0 Q14: push the model down -Z |
| 16 | const FOVH: i64 = 30 // half field-of-view degrees |
| 17 | const FARQ: i64 = 16384000 // far plane Q14 |
| 18 | const BG: i64 = 4280295456 // r32 g32 b32 a255 |
| 19 | const RED: i64 = 4278190335 // r255 g0 b0 a255 |
| 20 | const BLU: i64 = 4294901760 // r0 g0 b255 a255 |
| 23 | const O_FB: i64 = 0 // MV_N i64 framebuffer (-> 32768) |
| 24 | const O_ZB: i64 = 32768 // MV_N i64 z-buffer (-> 65536) |
| 25 | const O_PROJ: i64 = 65536 // 16 i64 |
| 26 | const O_ROTY: i64 = 65664 |
| 27 | const O_MV: i64 = 65792 |
| 28 | const O_TRANS: i64 = 65920 |
| 29 | const O_MVP: i64 = 66048 |
| 30 | const O_VB: i64 = 66176 // 4 i64 vertex scratch |
| 31 | const O_CLIP: i64 = 66208 // 4 i64 clip scratch |
| 32 | const O_SCR: i64 = 66240 // 6 verts * 4 i64 (-> 66432) |
| 33 | const O_TRI: i64 = 66432 // 12 i64 tri scratch (-> 66528) |
| 34 | const O_VERTS: i64 = 66528 // 6 verts * 4 i64 (-> 66720) |
| 35 | const O_IDX: i64 = 66720 // 2 tris * 3 i64 (-> 66768) |
| 37 | const O_CVERTS: i64 = 66768 // 8 cube verts * 3 i64 (-> 66960) |
| 38 | const O_CTRIS: i64 = 66960 // 12 tris * 7 i64 [i0,i1,i2,nx,ny,nz,color] (-> 67632) |
| 39 | const O_CSCR: i64 = 67632 // 8 verts * 4 i64 projected scratch (-> 67888) |
| 40 | const C_HALF: i64 = 9830 // 0.6 * Q14 cube half-extent |
| 41 | const C_BASE: i64 = 4292004040 // base material (200,200,210,255) -- shading reveals the form |
| 43 | const O_SKIN: i64 = 67888 // 8 skinned verts * 4 i64 (-> 68144) |
| 44 | const O_M0: i64 = 68144 // bone0 mat4 (-> 68272) |
| 45 | const O_M1: i64 = 68272 // bone1 mat4 (-> 68400) |
| 46 | const O_REST: i64 = 68400 // rest vec4 scratch (-> 68432) |
| 47 | const O_STMP: i64 = 68432 // skin tmp vec4 scratch (-> 68464) |
| 49 | const SP_RINGS: i64 = 8 |
| 50 | const SP_SECT: i64 = 12 |
| 51 | const SP_NV: i64 = 117 // (RINGS+1)*(SECT+1) |
| 52 | const SP_NT: i64 = 192 // RINGS*SECT*2 |
| 53 | const SP_R: i64 = 9830 // radius 0.6*Q |
| 54 | const SPHERE_BASE: i64 = 4293299280 // base material (80,140,230,255) |
| 55 | const O_SPV: i64 = 68480 // sphere verts SP_NV*3 (-> 71288) |
| 56 | const O_SPN: i64 = 71288 // sphere normals SP_NV*3 (-> 74096) |
| 57 | const O_SPC: i64 = 74096 // sphere per-vertex colours SP_NV (-> 75032) |
| 58 | const O_SPS: i64 = 75032 // sphere projected scr SP_NV*4 (-> 78776) |
| 59 | const O_SPI: i64 = 78776 // sphere indices SP_NT*3 (-> 83384) |
| 60 | const O_PBUF: i64 = 83392 // phong tri buffer 28 i64 (-> 83616) |
| 62 | const O_MVV: i64 = 83616 // mesh verts 256*3 (-> 89760) |
| 63 | const O_MVN: i64 = 89760 // mesh normals 256*3 (-> 95904) |
| 64 | const O_MVC: i64 = 95904 // mesh colours 256 (-> 97952) |
| 65 | const O_MVS: i64 = 97952 // mesh projected 256*4 (-> 106144) |
| 66 | const O_MVI: i64 = 106144 // mesh indices 512*3 (-> 118432) |
| 67 | const MESH_BASE: i64 = 4282158310 // mesh material (230,140,60,255) -- orange |
| 68 | const TR_SECT: i64 = 12 |
| 69 | const TR_RING: i64 = 8 |
| 70 | const TR_NV: i64 = 96 // SECT*RING |
| 71 | const TR_NT: i64 = 192 // SECT*RING*2 |
| 72 | const TR_MAJ: i64 = 7000 // major (centre) radius, Q14 |
| 73 | const TR_MIN: i64 = 3600 // tube radius, Q14 (chunky donut, still a clear hole) |
functions
| 75 | func mv_w() -> i64 { return MV_W } |
| 76 | func mv_h() -> i64 { return MV_H } |
| 77 | func mv_fb_off() -> i64 { return O_FB } // byte offset of the framebuffer (JS reads it stride-8) |
| 80 | func mv_scene() -> i64 called by 1: mv_render |
| 94 | func mv_proj1(mvp: *i64, vx: i64, vy: i64, vz: i64, scr: *i64, base: i64) -> i64 |
| 109 | func mv_render(angle: i64) -> i64 |
| 154 | func mv_pixel(i: i64) -> i64 { let fb: *i64 = (O_FB as i64) as *i64; return fb[i] } |
| 155 | func mv_coverage() -> i64 { let fb: *i64 = (O_FB as i64) as *i64; var k: i64=0; var i: i64=0; while i<MV_N { if fb[i]!=BG {k=k+1} i=i+1 } return k } |
| 158 | func mv_dot3(ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64) -> i64 { return (ax*bx + ay*by + az*bz) / VQ } called by 1: mv_lambert |
| 159 | func mv_lambert(nx: i64, ny: i64, nz: i64, lx: i64, ly: i64, lz: i64) -> i64 { let d: i64 = mv_dot3(nx,ny,nz,lx,ly,lz); if d < 0 { return 0 } return d } |
| 160 | func mv_rotn(c: i64, s: i64, nx: i64, ny: i64, nz: i64, out: *i64) -> i64 { out[0] = (c*nx + s*nz)/VQ; out[1] = ny; out[2] = ((0-s)*nx + c*nz)/VQ; return 0 } called by 1: mv_render_cube |
| 161 | func mv_shade(rgba: i64, b: i64, amb: i64) -> i64 { var bb: i64 = b; if bb < amb { bb = amb } let r: i64 = (rgba%256)*bb/VQ; let g: i64 = ((rgba/256)%256)*bb/VQ; let bl: i64 = ((rgba/65536)%256)*bb/VQ; return r + g*256 + bl*65536 + 255*16777216 } |
| 162 | func mv_setv(p: *i64, k: i64, x: i64, y: i64, z: i64) -> i64 { p[k*3]=x; p[k*3+1]=y; p[k*3+2]=z; return 0 } called by 1: mv_cube_scene |
| 163 | func mv_sett(p: *i64, k: i64, a: i64, b: i64, c: i64, nx: i64, ny: i64, nz: i64, col: i64) -> i64 { p[k*7]=a; p[k*7+1]=b; p[k*7+2]=c; p[k*7+3]=nx; p[k*7+4]=ny; p[k*7+5]=nz; p[k*7+6]=col; return 0 } called by 1: mv_cube_scene |
| 164 | func mv_cube_scene() -> i64 |
| 180 | func mv_render_cube(angle: i64) -> i64 |
| 237 | func mv_rotz(deg: i64, out: *i64) -> i64 |
| 246 | func mv_skin2(rest: *i64, m0: *i64, w0: i64, m1: *i64, w1: i64, tmp: *i64, ob: *i64, obase: i64) -> i64 |
| 254 | func mv_facecol(f: i64) -> i64 |
| 267 | func mv_isqrt(n: i64) -> i64 |
| 280 | func mv_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 |
| 296 | func mv_pow_q14(base: i64, n: i64) -> i64 |
| 305 | func mv_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 |
| 329 | func mv_add_spec(rgba: i64, sp: i64) -> i64 |
| 344 | func mv_skincube_xform(frame: i64) -> i64 |
| 388 | func mv_render_skincube(frame: i64) -> i64 |
| 422 | func mv_render_skincube_lit(frame: i64) -> i64 |
| 460 | func mv_render_skincube_spec(frame: i64) -> i64 |
| 502 | func mv_normal_specular(nx: i64, ny: i64, nz: i64, lx: i64, ly: i64, lz: i64, vx: i64, vy: i64, vz: i64, shin: i64) -> i64 |
| 517 | func mv_sphere_scene() -> i64 |
| 562 | func mv_sphere_xform() -> i64 |
| 582 | func mv_render_mesh(angle: i64, vbuf: i64, nbuf: i64, cbuf: i64, sbuf: i64, ibuf: i64, nverts: i64, ntris: i64, base: i64, mode: i64) -> i64 |
| 646 | func mv_meshv_off() -> i64 { return O_MVV } |
| 647 | func mv_meshn_off() -> i64 { return O_MVN } |
| 648 | func mv_meshi_off() -> i64 { return O_MVI } |
| 650 | func mv_torus_scene() -> i64 |
| 696 | func mv_render_torus(angle: i64) -> i64 |
| 701 | func mv_render_loaded(angle: i64, nverts: i64, ntris: i64) -> i64 calls 1: mv_render_mesh |
| 709 | func mv_render_loaded_cam(yaw: i64, dist: i64, nverts: i64, ntris: i64) -> i64 |
| 770 | func mv_render_sphere(angle: i64) -> i64 |
| 775 | func mv_render_sphere_flat(angle: i64) -> i64 |
| 785 | func mv_sphere_phong_draw(angle: i64, bump: i64) -> i64 |
| 825 | func mv_render_sphere_phong(angle: i64) -> i64 { return mv_sphere_phong_draw(angle, 0) } calls 1: mv_sphere_phong_draw |
| 828 | func mv_render_sphere_nmap(angle: i64) -> i64 { return mv_sphere_phong_draw(angle, 1200) } calls 1: mv_sphere_phong_draw |