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 2 imports · 0 importers
imports: nx_render_core.nxnx_vecmath.nx
imported by: nobody (leaf or entry point)
structs
| none |
consts
| 12 | const MV_W: i64 = 64 |
| 13 | const MV_H: i64 = 64 |
| 14 | const MV_N: i64 = 4096 // 64*64 |
| 15 | const VQ: i64 = 16384 // Q14 one (== RC_Q) |
| 16 | const DIST: i64 = 65536 // 4.0 Q14: push the model down -Z |
| 17 | const FOVH: i64 = 30 // half field-of-view degrees |
| 18 | const FARQ: i64 = 16384000 // far plane Q14 |
| 19 | const BG: i64 = 4280295456 // r32 g32 b32 a255 |
| 20 | const RED: i64 = 4278190335 // r255 g0 b0 a255 |
| 21 | const BLU: i64 = 4294901760 // r0 g0 b255 a255 |
| 24 | const O_FB: i64 = 0 // MV_N i64 framebuffer (-> 32768) |
| 25 | const O_ZB: i64 = 32768 // MV_N i64 z-buffer (-> 65536) |
| 26 | const O_PROJ: i64 = 65536 // 16 i64 |
| 27 | const O_ROTY: i64 = 65664 |
| 28 | const O_MV: i64 = 65792 |
| 29 | const O_TRANS: i64 = 65920 |
| 30 | const O_MVP: i64 = 66048 |
| 31 | const O_VB: i64 = 66176 // 4 i64 vertex scratch |
| 32 | const O_CLIP: i64 = 66208 // 4 i64 clip scratch |
| 33 | const O_SCR: i64 = 66240 // 6 verts * 4 i64 (-> 66432) |
| 34 | const O_TRI: i64 = 66432 // 12 i64 tri scratch (-> 66528) |
| 35 | const O_VERTS: i64 = 66528 // 6 verts * 4 i64 (-> 66720) |
| 36 | const O_IDX: i64 = 66720 // 2 tris * 3 i64 (-> 66768) |
| 38 | const O_CVERTS: i64 = 66768 // 8 cube verts * 3 i64 (-> 66960) |
| 39 | const O_CTRIS: i64 = 66960 // 12 tris * 7 i64 [i0,i1,i2,nx,ny,nz,color] (-> 67632) |
| 40 | const O_CSCR: i64 = 67632 // 8 verts * 4 i64 projected scratch (-> 67888) |
| 41 | const C_HALF: i64 = 9830 // 0.6 * Q14 cube half-extent |
| 42 | const C_BASE: i64 = 4292004040 // base material (200,200,210,255) -- shading reveals the form |
| 44 | const O_SKIN: i64 = 67888 // 8 skinned verts * 4 i64 (-> 68144) |
| 45 | const O_M0: i64 = 68144 // bone0 mat4 (-> 68272) |
| 46 | const O_M1: i64 = 68272 // bone1 mat4 (-> 68400) |
| 47 | const O_REST: i64 = 68400 // rest vec4 scratch (-> 68432) |
| 48 | const O_STMP: i64 = 68432 // skin tmp vec4 scratch (-> 68464) |
| 50 | const SP_RINGS: i64 = 8 |
| 51 | const SP_SECT: i64 = 12 |
| 52 | const SP_NV: i64 = 117 // (RINGS+1)*(SECT+1) |
| 53 | const SP_NT: i64 = 192 // RINGS*SECT*2 |
| 54 | const SP_R: i64 = 9830 // radius 0.6*Q |
| 55 | const SPHERE_BASE: i64 = 4293299280 // base material (80,140,230,255) |
| 56 | const O_SPV: i64 = 68480 // sphere verts SP_NV*3 (-> 71288) |
| 57 | const O_SPN: i64 = 71288 // sphere normals SP_NV*3 (-> 74096) |
| 58 | const O_SPC: i64 = 74096 // sphere per-vertex colours SP_NV (-> 75032) |
| 59 | const O_SPS: i64 = 75032 // sphere projected scr SP_NV*4 (-> 78776) |
| 60 | const O_SPI: i64 = 78776 // sphere indices SP_NT*3 (-> 83384) |
| 61 | const O_PBUF: i64 = 83392 // phong tri buffer 28 i64 (-> 83616) |
| 63 | const O_MVV: i64 = 83616 // mesh verts 256*3 (-> 89760) |
| 64 | const O_MVN: i64 = 89760 // mesh normals 256*3 (-> 95904) |
| 65 | const O_MVC: i64 = 95904 // mesh colours 256 (-> 97952) |
| 66 | const O_MVS: i64 = 97952 // mesh projected 256*4 (-> 106144) |
| 67 | const O_MVI: i64 = 106144 // mesh indices 512*3 (-> 118432) |
| 68 | const MESH_BASE: i64 = 4282158310 // mesh material (230,140,60,255) -- orange |
| 69 | const TR_SECT: i64 = 12 |
| 70 | const TR_RING: i64 = 8 |
| 71 | const TR_NV: i64 = 96 // SECT*RING |
| 72 | const TR_NT: i64 = 192 // SECT*RING*2 |
| 73 | const TR_MAJ: i64 = 7000 // major (centre) radius, Q14 |
| 74 | const TR_MIN: i64 = 3600 // tube radius, Q14 (chunky donut, still a clear hole) |
| 829 | const DV_W: i64 = 640 |
| 830 | const DV_H: i64 = 480 |
| 831 | const DV_MAXV: i64 = 7000 |
| 832 | const DV_MAXT: i64 = 14000 |
| 833 | const DV_NJ: i64 = 11 |
| 834 | const DV_MAXK: i64 = 128 |
| 835 | const DV_MAGIC: i64 = 0x3256584E |
| 836 | const DV_DIST_MIN: i64 = 16384 |
| 837 | const DV_DIST_MAX: i64 = 524288 |
| 839 | const O_DFB: i64 = 131072 |
| 840 | const O_DZB: i64 = 2588672 |
| 841 | const O_DHDR: i64 = 5046272 |
| 842 | const O_DV: i64 = 5046336 |
| 843 | const O_DN: i64 = 5214336 |
| 844 | const O_DC: i64 = 5382336 |
| 845 | const O_DJ: i64 = 5438336 |
| 846 | const O_DJ2: i64 = 5494336 |
| 847 | const O_DWT: i64 = 5550336 |
| 848 | const O_DI: i64 = 5606336 |
| 849 | const O_DPAR: i64 = 5942336 |
| 850 | const O_DJT: i64 = 5942424 |
| 851 | const O_DIBM: i64 = 5942688 |
| 852 | const O_DTRK: i64 = 5944096 |
| 853 | const O_DSK: i64 = 5976864 |
| 854 | const O_DS: i64 = 6200864 |
| 855 | const O_DCL: i64 = 6424864 |
| 856 | const O_DPAL: i64 = 6480864 |
| 857 | const O_DWLD: i64 = 6482272 |
| 858 | const O_DLOC: i64 = 6483680 |
| 859 | const O_DQ: i64 = 6483808 |
| 860 | const O_DRX: i64 = 6483840 |
| 861 | const O_DRY: i64 = 6483968 |
| 862 | const O_DROT: i64 = 6484096 |
| 863 | const O_DPRJ: i64 = 6484224 |
| 864 | const O_DMV: i64 = 6484352 |
| 865 | const O_DMVP: i64 = 6484480 |
| 866 | const O_DVB: i64 = 6484608 |
| 867 | const O_DVC: i64 = 6484640 |
| 868 | const O_DVD: i64 = 6484672 |
| 869 | const O_DVE: i64 = 6484704 |
functions
| 76 | func mv_w() -> i64 { return MV_W } |
| 77 | func mv_h() -> i64 { return MV_H } |
| 78 | func mv_fb_off() -> i64 { return O_FB } // byte offset of the framebuffer (JS reads it stride-8) |
| 81 | func mv_scene() -> i64 called by 1: mv_render |
| 95 | func mv_proj1(mvp: *i64, vx: i64, vy: i64, vz: i64, scr: *i64, base: i64) -> i64 |
| 110 | func mv_render(angle: i64) -> i64 |
| 155 | func mv_pixel(i: i64) -> i64 { let fb: *i64 = (O_FB as i64) as *i64; return fb[i] } |
| 156 | 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 } |
| 159 | func mv_dot3(ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64) -> i64 { return (ax*bx + ay*by + az*bz) / VQ } |
| 160 | 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 } |
| 161 | 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 |
| 162 | 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 } |
| 163 | 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 |
| 164 | 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 |
| 165 | func mv_cube_scene() -> i64 |
| 181 | func mv_render_cube(angle: i64) -> i64 |
| 238 | func mv_rotz(deg: i64, out: *i64) -> i64 |
| 247 | func mv_skin2(rest: *i64, m0: *i64, w0: i64, m1: *i64, w1: i64, tmp: *i64, ob: *i64, obase: i64) -> i64 |
| 255 | func mv_facecol(f: i64) -> i64 |
| 268 | func mv_isqrt(n: i64) -> i64 { return vm_isqrt(n) } |
| 269 | 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 |
| 285 | func mv_pow_q14(base: i64, n: i64) -> i64 |
| 294 | 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 |
| 318 | func mv_add_spec(rgba: i64, sp: i64) -> i64 |
| 333 | func mv_skincube_xform(frame: i64) -> i64 |
| 377 | func mv_render_skincube(frame: i64) -> i64 |
| 411 | func mv_render_skincube_lit(frame: i64) -> i64 |
| 449 | func mv_render_skincube_spec(frame: i64) -> i64 |
| 491 | 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 |
| 506 | func mv_sphere_scene() -> i64 |
| 551 | func mv_sphere_xform() -> i64 |
| 571 | 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 |
| 635 | func mv_meshv_off() -> i64 { return O_MVV } |
| 636 | func mv_meshn_off() -> i64 { return O_MVN } |
| 637 | func mv_meshi_off() -> i64 { return O_MVI } |
| 639 | func mv_torus_scene() -> i64 |
| 685 | func mv_render_torus(angle: i64) -> i64 |
| 690 | func mv_render_loaded(angle: i64, nverts: i64, ntris: i64) -> i64 calls 1: mv_render_mesh |
| 698 | func mv_render_loaded_cam(yaw: i64, dist: i64, nverts: i64, ntris: i64) -> i64 |
| 759 | func mv_render_sphere(angle: i64) -> i64 |
| 764 | func mv_render_sphere_flat(angle: i64) -> i64 |
| 774 | func mv_sphere_phong_draw(angle: i64, bump: i64) -> i64 |
| 814 | func mv_render_sphere_phong(angle: i64) -> i64 { return mv_sphere_phong_draw(angle, 0) } calls 1: mv_sphere_phong_draw |
| 817 | func mv_render_sphere_nmap(angle: i64) -> i64 { return mv_sphere_phong_draw(angle, 1200) } calls 1: mv_sphere_phong_draw |
| 871 | func dv_w() -> i64 { return DV_W } |
| 872 | func dv_h() -> i64 { return DV_H } |
| 873 | func dv_fb_off() -> i64 { return O_DFB } |
| 874 | func dv_blob_off() -> i64 { return O_DHDR } |
| 875 | func dv_blob_len() -> i64 { return O_DSK - O_DHDR } |
| 876 | func dv_duration_ms() -> i64 |
| 883 | func dv_quatmat(q: *i64, tx: i64, ty: i64, tz: i64, out: *i64) -> i64 called by 1: dv_palette |
| 914 | func dv_sample(bone: i64, tms: i64, qo: *i64) -> i64 |
| 943 | func dv_palette(tms: i64) -> i64 |
| 970 | func dv_proj1(vx: i64, vy: i64, vz: i64, scr: *i64, base: i64) -> i64 |
| 987 | func mv_dance_render(tms: i64, yaw: i64, pitch: i64, dist: i64) -> i64 |