code wiki / (root) / nx_meshview_wasm.nx

nx_meshview_wasm.nx

buildroot/runtime/nx_meshview_wasm.nx

39091 B828 linesdepth 1pulls 1 transitivereach 0 importersview sourcekind orphan librarytopic meshview
docsdependenciesstructsconstsfunctions

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

nx_render_core.nx nx_meshview_wasm.nx

imports: nx_render_core.nx

imported by: nobody (leaf or entry point)

structs

none

consts

11const MV_W: i64 = 64
12const MV_H: i64 = 64
13const MV_N: i64 = 4096 // 64*64
14const VQ: i64 = 16384 // Q14 one (== RC_Q)
15const DIST: i64 = 65536 // 4.0 Q14: push the model down -Z
16const FOVH: i64 = 30 // half field-of-view degrees
17const FARQ: i64 = 16384000 // far plane Q14
18const BG: i64 = 4280295456 // r32 g32 b32 a255
19const RED: i64 = 4278190335 // r255 g0 b0 a255
20const BLU: i64 = 4294901760 // r0 g0 b255 a255
23const O_FB: i64 = 0 // MV_N i64 framebuffer (-> 32768)
24const O_ZB: i64 = 32768 // MV_N i64 z-buffer (-> 65536)
25const O_PROJ: i64 = 65536 // 16 i64
26const O_ROTY: i64 = 65664
27const O_MV: i64 = 65792
28const O_TRANS: i64 = 65920
29const O_MVP: i64 = 66048
30const O_VB: i64 = 66176 // 4 i64 vertex scratch
31const O_CLIP: i64 = 66208 // 4 i64 clip scratch
32const O_SCR: i64 = 66240 // 6 verts * 4 i64 (-> 66432)
33const O_TRI: i64 = 66432 // 12 i64 tri scratch (-> 66528)
34const O_VERTS: i64 = 66528 // 6 verts * 4 i64 (-> 66720)
35const O_IDX: i64 = 66720 // 2 tris * 3 i64 (-> 66768)
37const O_CVERTS: i64 = 66768 // 8 cube verts * 3 i64 (-> 66960)
38const O_CTRIS: i64 = 66960 // 12 tris * 7 i64 [i0,i1,i2,nx,ny,nz,color] (-> 67632)
39const O_CSCR: i64 = 67632 // 8 verts * 4 i64 projected scratch (-> 67888)
40const C_HALF: i64 = 9830 // 0.6 * Q14 cube half-extent
41const C_BASE: i64 = 4292004040 // base material (200,200,210,255) -- shading reveals the form
43const O_SKIN: i64 = 67888 // 8 skinned verts * 4 i64 (-> 68144)
44const O_M0: i64 = 68144 // bone0 mat4 (-> 68272)
45const O_M1: i64 = 68272 // bone1 mat4 (-> 68400)
46const O_REST: i64 = 68400 // rest vec4 scratch (-> 68432)
47const O_STMP: i64 = 68432 // skin tmp vec4 scratch (-> 68464)
49const SP_RINGS: i64 = 8
50const SP_SECT: i64 = 12
51const SP_NV: i64 = 117 // (RINGS+1)*(SECT+1)
52const SP_NT: i64 = 192 // RINGS*SECT*2
53const SP_R: i64 = 9830 // radius 0.6*Q
54const SPHERE_BASE: i64 = 4293299280 // base material (80,140,230,255)
55const O_SPV: i64 = 68480 // sphere verts SP_NV*3 (-> 71288)
56const O_SPN: i64 = 71288 // sphere normals SP_NV*3 (-> 74096)
57const O_SPC: i64 = 74096 // sphere per-vertex colours SP_NV (-> 75032)
58const O_SPS: i64 = 75032 // sphere projected scr SP_NV*4 (-> 78776)
59const O_SPI: i64 = 78776 // sphere indices SP_NT*3 (-> 83384)
60const O_PBUF: i64 = 83392 // phong tri buffer 28 i64 (-> 83616)
62const O_MVV: i64 = 83616 // mesh verts 256*3 (-> 89760)
63const O_MVN: i64 = 89760 // mesh normals 256*3 (-> 95904)
64const O_MVC: i64 = 95904 // mesh colours 256 (-> 97952)
65const O_MVS: i64 = 97952 // mesh projected 256*4 (-> 106144)
66const O_MVI: i64 = 106144 // mesh indices 512*3 (-> 118432)
67const MESH_BASE: i64 = 4282158310 // mesh material (230,140,60,255) -- orange
68const TR_SECT: i64 = 12
69const TR_RING: i64 = 8
70const TR_NV: i64 = 96 // SECT*RING
71const TR_NT: i64 = 192 // SECT*RING*2
72const TR_MAJ: i64 = 7000 // major (centre) radius, Q14
73const TR_MIN: i64 = 3600 // tube radius, Q14 (chunky donut, still a clear hole)

functions

75func mv_w() -> i64 { return MV_W }
76func mv_h() -> i64 { return MV_H }
77func mv_fb_off() -> i64 { return O_FB } // byte offset of the framebuffer (JS reads it stride-8)
80func mv_scene() -> i64
called by 1: mv_render
94func mv_proj1(mvp: *i64, vx: i64, vy: i64, vz: i64, scr: *i64, base: i64) -> i64
109func mv_render(angle: i64) -> i64
154func mv_pixel(i: i64) -> i64 { let fb: *i64 = (O_FB as i64) as *i64; return fb[i] }
155func 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 }
158func 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
159func 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 }
160func 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
161func 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 }
162func 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
163func 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
164func mv_cube_scene() -> i64
180func mv_render_cube(angle: i64) -> i64
237func mv_rotz(deg: i64, out: *i64) -> i64
246func mv_skin2(rest: *i64, m0: *i64, w0: i64, m1: *i64, w1: i64, tmp: *i64, ob: *i64, obase: i64) -> i64
called by 1: mv_skincube_xform calls 1: rc_mat4_vec4
254func mv_facecol(f: i64) -> i64
267func mv_isqrt(n: i64) -> i64
280func 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
296func mv_pow_q14(base: i64, n: i64) -> i64
305func 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
329func mv_add_spec(rgba: i64, sp: i64) -> i64
344func mv_skincube_xform(frame: i64) -> i64
388func mv_render_skincube(frame: i64) -> i64
422func mv_render_skincube_lit(frame: i64) -> i64
460func mv_render_skincube_spec(frame: i64) -> i64
502func mv_normal_specular(nx: i64, ny: i64, nz: i64, lx: i64, ly: i64, lz: i64, vx: i64, vy: i64, vz: i64, shin: i64) -> i64
517func mv_sphere_scene() -> i64
562func mv_sphere_xform() -> i64
582func mv_render_mesh(angle: i64, vbuf: i64, nbuf: i64, cbuf: i64, sbuf: i64, ibuf: i64, nverts: i64, ntris: i64, base: i64, mode: i64) -> i64
646func mv_meshv_off() -> i64 { return O_MVV }
647func mv_meshn_off() -> i64 { return O_MVN }
648func mv_meshi_off() -> i64 { return O_MVI }
650func mv_torus_scene() -> i64
696func mv_render_torus(angle: i64) -> i64
701func mv_render_loaded(angle: i64, nverts: i64, ntris: i64) -> i64
calls 1: mv_render_mesh
709func mv_render_loaded_cam(yaw: i64, dist: i64, nverts: i64, ntris: i64) -> i64
770func mv_render_sphere(angle: i64) -> i64
775func mv_render_sphere_flat(angle: i64) -> i64
785func mv_sphere_phong_draw(angle: i64, bump: i64) -> i64
825func mv_render_sphere_phong(angle: i64) -> i64 { return mv_sphere_phong_draw(angle, 0) }
828func mv_render_sphere_nmap(angle: i64) -> i64 { return mv_sphere_phong_draw(angle, 1200) }