code wiki / _hdl_build / nx_gltf_load_gate.nx
nx_gltf_load_gate.nx source
↩ module page · 64 lines · 3702 B
1// nx_gltf_load_gate.nx -- ★NATIVE sovereign glTF viewer: load our exported nishi_being.glb back into the Nishi renderer and
2// render it -- proving the round-trip on OUR OWN stack (closes the honest-scope gap) and giving Nishi OS / the Nishi browser
3// a native .glb view. T1 loads. T2 counts round-trip (verts/tris == export). T3 renders (filled). T4 turntable PNG.
4// license_tier: ORIGINAL expect_exit: 0
5import "nx_syscalls.nx"
6import "nx_png.nx"
7import "nx_trimesh.nx"
8import "nx_gltf_load.nx"
9
10func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 }
12func clearfb(fb: *i64, n: i64, c: i64) -> i64 { var i: i64=0; while i<n { fb[i]=c; i=i+1 } return 0 }
13func filled(fb: *i64, n: i64, bg: i64) -> i64 { var c: i64=0; var i: i64=0; while i<n { if fb[i]!=bg { c=c+1 } i=i+1 } return c }
14
15const BG: i64 = 24 + 26*256 + 34*65536
16const W: i64 = 300
17const H: i64 = 460
18
19func main() -> i64 {
20 hw("=== nx_gltf_load_gate -- load nishi_being.glb into the Nishi renderer (native sovereign view) ===\n" as *u8)
21 var fails: i64 = 0
22 let ok: i64 = gltf_load("knowledge/nishi_being.glb" as *u8)
23 let nv: i64 = tm_nv(); let nt: i64 = tm_nt()
24 hw(" loaded: ok="); pn(ok); hw(" verts="); pn(nv); hw(" tris="); pn(nt); hw(" overflow="); pn(tm_ovf()); hw("\n" as *u8)
25 var t1: i64 = 0
26 if ok == 1 { if nv > 1000 { if tm_ovf() == 0 { t1 = 1 } } }
27 if t1 == 1 { hw("T1 PASS parsed the .glb into the native renderer\n" as *u8) } else { fails=fails+1; hw("T1 FAIL\n" as *u8) }
28 // round-trip: the export was 7954 verts / 15912 tris
29 var t2: i64 = 0
30 if nv == 7954 { if nt == 15912 { t2 = 1 } }
31 if t2 == 1 { hw("T2 PASS counts round-trip exactly (7954 verts / 15912 tris)\n" as *u8) } else { fails=fails+1; hw("T2 FAIL nv="); pn(nv); hw(" nt="); pn(nt); hw("\n" as *u8) }
32
33 let npx: i64 = W*H
34 let fb: *i64 = sys_mmap(npx*8) as *i64
35 let zb: *i64 = sys_mmap(npx*8) as *i64
36 clearfb(fb, npx, BG); trimesh_zclear(zb, npx); trimesh_render(fb, zb, W, H, 2400, 0-200, 2600, 520, 2)
37 let fil: i64 = filled(fb, npx, BG)
38 hw(" render: filled="); pn(fil); hw("\n" as *u8)
39 var t3: i64 = 0
40 if fil > npx/12 { t3 = 1 }
41 if t3 == 1 { hw("T3 PASS the loaded .glb RENDERS on our stack (sovereign round-trip verified)\n" as *u8) } else { fails=fails+1; hw("T3 FAIL\n" as *u8) }
42
43 // T4 turntable: 3 views of the loaded model
44 let yaws: *i64 = sys_mmap(3*8) as *i64
45 yaws[0]=1400; yaws[1]=3200; yaws[2]=5600
46 let GW: i64 = W*3
47 let gal: *i64 = sys_mmap(GW*H*8) as *i64
48 clearfb(gal, GW*H, BG)
49 let cell: *i64 = sys_mmap(npx*8) as *i64
50 var v: i64 = 0
51 while v < 3 {
52 clearfb(cell, npx, BG); trimesh_zclear(zb, npx); trimesh_render(cell, zb, W, H, yaws[v], 0-200, 2600, 520, 2)
53 var y: i64 = 0
54 while y < H { var x: i64=0; while x<W { gal[y*GW+v*W+x]=cell[y*W+x]; x=x+1 } y=y+1 }
55 v = v + 1
56 }
57 write_png(gal, GW, H, "knowledge/nx_gltf_view.png" as *u8)
58 hw("T4 native turntable -> knowledge/nx_gltf_view.png (loaded .glb, 3 views)\n" as *u8)
59
60 if fails == 0 { hw("GLTF-LOAD-GATE GREEN -- the Nishi renderer NATIVELY loads + views a .glb (round-trip from our own export, verified on our own stack). Nishi OS / Nishi browser can view 3D models sovereignly.\n" as *u8); sys_exit(0); return 0 }
61 hw("GLTF-LOAD-GATE RED fails="); pn(fails); hw("\n" as *u8)
62 sys_exit(1)
63 return 1
64}