code wiki / (root) / nx_meshview_wasm.nx

nx_meshview_wasm.nx

buildroot/runtime/nx_meshview_wasm.nx

51080 B1126 linesdepth 3pulls 3 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 2 imports · 0 importers

nx_render_core.nx nx_vecmath.nx nx_meshview_wasm.nx

imports: nx_render_core.nxnx_vecmath.nx

imported by: nobody (leaf or entry point)

structs

none

consts

12const MV_W: i64 = 64
13const MV_H: i64 = 64
14const MV_N: i64 = 4096 // 64*64
15const VQ: i64 = 16384 // Q14 one (== RC_Q)
16const DIST: i64 = 65536 // 4.0 Q14: push the model down -Z
17const FOVH: i64 = 30 // half field-of-view degrees
18const FARQ: i64 = 16384000 // far plane Q14
19const BG: i64 = 4280295456 // r32 g32 b32 a255
20const RED: i64 = 4278190335 // r255 g0 b0 a255
21const BLU: i64 = 4294901760 // r0 g0 b255 a255
24const O_FB: i64 = 0 // MV_N i64 framebuffer (-> 32768)
25const O_ZB: i64 = 32768 // MV_N i64 z-buffer (-> 65536)
26const O_PROJ: i64 = 65536 // 16 i64
27const O_ROTY: i64 = 65664
28const O_MV: i64 = 65792
29const O_TRANS: i64 = 65920
30const O_MVP: i64 = 66048
31const O_VB: i64 = 66176 // 4 i64 vertex scratch
32const O_CLIP: i64 = 66208 // 4 i64 clip scratch
33const O_SCR: i64 = 66240 // 6 verts * 4 i64 (-> 66432)
34const O_TRI: i64 = 66432 // 12 i64 tri scratch (-> 66528)
35const O_VERTS: i64 = 66528 // 6 verts * 4 i64 (-> 66720)
36const O_IDX: i64 = 66720 // 2 tris * 3 i64 (-> 66768)
38const O_CVERTS: i64 = 66768 // 8 cube verts * 3 i64 (-> 66960)
39const O_CTRIS: i64 = 66960 // 12 tris * 7 i64 [i0,i1,i2,nx,ny,nz,color] (-> 67632)
40const O_CSCR: i64 = 67632 // 8 verts * 4 i64 projected scratch (-> 67888)
41const C_HALF: i64 = 9830 // 0.6 * Q14 cube half-extent
42const C_BASE: i64 = 4292004040 // base material (200,200,210,255) -- shading reveals the form
44const O_SKIN: i64 = 67888 // 8 skinned verts * 4 i64 (-> 68144)
45const O_M0: i64 = 68144 // bone0 mat4 (-> 68272)
46const O_M1: i64 = 68272 // bone1 mat4 (-> 68400)
47const O_REST: i64 = 68400 // rest vec4 scratch (-> 68432)
48const O_STMP: i64 = 68432 // skin tmp vec4 scratch (-> 68464)
50const SP_RINGS: i64 = 8
51const SP_SECT: i64 = 12
52const SP_NV: i64 = 117 // (RINGS+1)*(SECT+1)
53const SP_NT: i64 = 192 // RINGS*SECT*2
54const SP_R: i64 = 9830 // radius 0.6*Q
55const SPHERE_BASE: i64 = 4293299280 // base material (80,140,230,255)
56const O_SPV: i64 = 68480 // sphere verts SP_NV*3 (-> 71288)
57const O_SPN: i64 = 71288 // sphere normals SP_NV*3 (-> 74096)
58const O_SPC: i64 = 74096 // sphere per-vertex colours SP_NV (-> 75032)
59const O_SPS: i64 = 75032 // sphere projected scr SP_NV*4 (-> 78776)
60const O_SPI: i64 = 78776 // sphere indices SP_NT*3 (-> 83384)
61const O_PBUF: i64 = 83392 // phong tri buffer 28 i64 (-> 83616)
63const O_MVV: i64 = 83616 // mesh verts 256*3 (-> 89760)
64const O_MVN: i64 = 89760 // mesh normals 256*3 (-> 95904)
65const O_MVC: i64 = 95904 // mesh colours 256 (-> 97952)
66const O_MVS: i64 = 97952 // mesh projected 256*4 (-> 106144)
67const O_MVI: i64 = 106144 // mesh indices 512*3 (-> 118432)
68const MESH_BASE: i64 = 4282158310 // mesh material (230,140,60,255) -- orange
69const TR_SECT: i64 = 12
70const TR_RING: i64 = 8
71const TR_NV: i64 = 96 // SECT*RING
72const TR_NT: i64 = 192 // SECT*RING*2
73const TR_MAJ: i64 = 7000 // major (centre) radius, Q14
74const TR_MIN: i64 = 3600 // tube radius, Q14 (chunky donut, still a clear hole)
829const DV_W: i64 = 640
830const DV_H: i64 = 480
831const DV_MAXV: i64 = 7000
832const DV_MAXT: i64 = 14000
833const DV_NJ: i64 = 11
834const DV_MAXK: i64 = 128
835const DV_MAGIC: i64 = 0x3256584E
836const DV_DIST_MIN: i64 = 16384
837const DV_DIST_MAX: i64 = 524288
839const O_DFB: i64 = 131072
840const O_DZB: i64 = 2588672
841const O_DHDR: i64 = 5046272
842const O_DV: i64 = 5046336
843const O_DN: i64 = 5214336
844const O_DC: i64 = 5382336
845const O_DJ: i64 = 5438336
846const O_DJ2: i64 = 5494336
847const O_DWT: i64 = 5550336
848const O_DI: i64 = 5606336
849const O_DPAR: i64 = 5942336
850const O_DJT: i64 = 5942424
851const O_DIBM: i64 = 5942688
852const O_DTRK: i64 = 5944096
853const O_DSK: i64 = 5976864
854const O_DS: i64 = 6200864
855const O_DCL: i64 = 6424864
856const O_DPAL: i64 = 6480864
857const O_DWLD: i64 = 6482272
858const O_DLOC: i64 = 6483680
859const O_DQ: i64 = 6483808
860const O_DRX: i64 = 6483840
861const O_DRY: i64 = 6483968
862const O_DROT: i64 = 6484096
863const O_DPRJ: i64 = 6484224
864const O_DMV: i64 = 6484352
865const O_DMVP: i64 = 6484480
866const O_DVB: i64 = 6484608
867const O_DVC: i64 = 6484640
868const O_DVD: i64 = 6484672
869const O_DVE: i64 = 6484704

functions

76func mv_w() -> i64 { return MV_W }
77func mv_h() -> i64 { return MV_H }
78func mv_fb_off() -> i64 { return O_FB } // byte offset of the framebuffer (JS reads it stride-8)
81func mv_scene() -> i64
called by 1: mv_render
95func mv_proj1(mvp: *i64, vx: i64, vy: i64, vz: i64, scr: *i64, base: i64) -> i64
110func mv_render(angle: i64) -> i64
155func mv_pixel(i: i64) -> i64 { let fb: *i64 = (O_FB as i64) as *i64; return fb[i] }
156func 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 }
159func mv_dot3(ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64) -> i64 { return (ax*bx + ay*by + az*bz) / VQ }
160func 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 }
161func 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
162func 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 }
163func 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
164func 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
165func mv_cube_scene() -> i64
181func mv_render_cube(angle: i64) -> i64
238func mv_rotz(deg: i64, out: *i64) -> i64
247func 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
255func mv_facecol(f: i64) -> i64
268func mv_isqrt(n: i64) -> i64 { return vm_isqrt(n) }
269func 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
285func mv_pow_q14(base: i64, n: i64) -> i64
294func 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
318func mv_add_spec(rgba: i64, sp: i64) -> i64
333func mv_skincube_xform(frame: i64) -> i64
377func mv_render_skincube(frame: i64) -> i64
411func mv_render_skincube_lit(frame: i64) -> i64
449func mv_render_skincube_spec(frame: i64) -> i64
491func mv_normal_specular(nx: i64, ny: i64, nz: i64, lx: i64, ly: i64, lz: i64, vx: i64, vy: i64, vz: i64, shin: i64) -> i64
506func mv_sphere_scene() -> i64
551func mv_sphere_xform() -> i64
571func mv_render_mesh(angle: i64, vbuf: i64, nbuf: i64, cbuf: i64, sbuf: i64, ibuf: i64, nverts: i64, ntris: i64, base: i64, mode: i64) -> i64
635func mv_meshv_off() -> i64 { return O_MVV }
636func mv_meshn_off() -> i64 { return O_MVN }
637func mv_meshi_off() -> i64 { return O_MVI }
639func mv_torus_scene() -> i64
685func mv_render_torus(angle: i64) -> i64
690func mv_render_loaded(angle: i64, nverts: i64, ntris: i64) -> i64
calls 1: mv_render_mesh
698func mv_render_loaded_cam(yaw: i64, dist: i64, nverts: i64, ntris: i64) -> i64
759func mv_render_sphere(angle: i64) -> i64
764func mv_render_sphere_flat(angle: i64) -> i64
774func mv_sphere_phong_draw(angle: i64, bump: i64) -> i64
814func mv_render_sphere_phong(angle: i64) -> i64 { return mv_sphere_phong_draw(angle, 0) }
817func mv_render_sphere_nmap(angle: i64) -> i64 { return mv_sphere_phong_draw(angle, 1200) }
871func dv_w() -> i64 { return DV_W }
872func dv_h() -> i64 { return DV_H }
873func dv_fb_off() -> i64 { return O_DFB }
874func dv_blob_off() -> i64 { return O_DHDR }
875func dv_blob_len() -> i64 { return O_DSK - O_DHDR }
876func dv_duration_ms() -> i64
883func dv_quatmat(q: *i64, tx: i64, ty: i64, tz: i64, out: *i64) -> i64
called by 1: dv_palette
914func dv_sample(bone: i64, tms: i64, qo: *i64) -> i64
called by 1: dv_palette calls 1: mv_isqrt
943func dv_palette(tms: i64) -> i64
970func dv_proj1(vx: i64, vy: i64, vz: i64, scr: *i64, base: i64) -> i64
called by 1: mv_dance_render calls 1: rc_mat4_vec4
987func mv_dance_render(tms: i64, yaw: i64, pitch: i64, dist: i64) -> i64