code wiki / _hdl_build / nx_bunny_gate.nx
nx_bunny_gate.nx source
↩ module page · 77 lines · 4304 B
1// nx_bunny_gate.nx -- ★STANFORD BUNNY on the Nishi renderer (field-evidence rung 2): the standard mesh corpus. The
2// conformance claim is EXACTNESS: the banked Stanford ground truth says bun_zipper = 35947 vertices / 69451 triangles,
3// and the loaded mesh must match those numbers exactly (provenance proven by the counts). Then it must render.
4// T1 exact canonical counts. T2 renders (our largest mesh ever). T3 determinism. T4 evidence -> knowledge/nx_bunny.png.
5// license_tier: ORIGINAL expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_png.nx"
8import "nx_trimesh.nx"
9import "nx_objload.nx"
10
11func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func 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 }
13func clearfb(fb: *i64, n: i64, c: i64) -> i64 { var i: i64=0; while i<n { fb[i]=c; i=i+1 } return 0 }
14func 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 }
15
16const BG: i64 = 24 + 26*256 + 34*65536
17const W: i64 = 300
18const H: i64 = 300
19
20func main() -> i64 {
21 hw("=== nx_bunny_gate -- the Stanford bunny (standard mesh corpus) on the sovereign renderer ===\n" as *u8)
22 var fails: i64 = 0
23 let npx: i64 = W*H
24 let fb: *i64 = sys_mmap(npx*8) as *i64
25 let zb: *i64 = sys_mmap(npx*8) as *i64
26 tm_set_spec(0)
27 tm_set_tex(0)
28
29 let ok: i64 = obj_load("knowledge/stdassets/bunny.obj" as *u8, 1300, 205+200*256+195*65536)
30 let nv: i64 = tm_nv(); let nt: i64 = tm_nt()
31 hw(" bunny: ok="); pn(ok); hw(" verts="); pn(nv); hw(" tris="); pn(nt); hw(" ovf="); pn(tm_ovf()); hw("\n" as *u8)
32 // T1 EXACT canonical counts (banked Stanford ground truth: 35947 / 69451)
33 var t1: i64 = 0
34 if ok == 1 { if nv == 35947 { if nt == 69451 { if tm_ovf() == 0 { t1 = 1 } } } }
35 if t1 == 1 { hw("T1 PASS EXACT canonical Stanford counts: 35947 vertices / 69451 triangles (provenance proven by the numbers)\n" as *u8) }
36 else { fails=fails+1; hw("T1 FAIL\n" as *u8) }
37
38 // T2 renders -- our largest mesh ever
39 clearfb(fb, npx, BG); trimesh_zclear(zb, npx); trimesh_render(fb, zb, W, H, 1300, 0-250, 2300, 520, 2)
40 let fil: i64 = filled(fb, npx, BG)
41 hw(" render: filled="); pn(fil); hw("\n" as *u8)
42 var t2: i64 = 0
43 if fil > npx/12 { t2 = 1 }
44 if t2 == 1 { hw("T2 PASS the 69451-triangle bunny RENDERS on our rasterizer (largest mesh to date)\n" as *u8) }
45 else { fails=fails+1; hw("T2 FAIL filled="); pn(fil); hw("\n" as *u8) }
46
47 // T3 determinism
48 let f2: *i64 = sys_mmap(npx*8) as *i64
49 clearfb(f2, npx, BG); trimesh_zclear(zb, npx); trimesh_render(f2, zb, W, H, 1300, 0-250, 2300, 520, 2)
50 var diff: i64 = 0; var i: i64 = 0
51 while i < npx { if f2[i]!=fb[i] { diff=diff+1 } i=i+1 }
52 var t3: i64 = 0
53 if diff == 0 { t3 = 1 }
54 if t3 == 1 { hw("T3 PASS deterministic\n" as *u8) } else { fails=fails+1; hw("T3 FAIL diff="); pn(diff); hw("\n" as *u8) }
55
56 // T4 evidence gallery: 3/4 | profile | front
57 let GW: i64 = W*3
58 let gal: *i64 = sys_mmap(GW*H*8) as *i64
59 clearfb(gal, GW*H, BG)
60 let cell: *i64 = sys_mmap(npx*8) as *i64
61 let yaws: *i64 = sys_mmap(3*8) as *i64
62 yaws[0]=1300; yaws[1]=6434; yaws[2]=200
63 var v: i64 = 0
64 while v < 3 {
65 clearfb(cell, npx, BG); trimesh_zclear(zb, npx); trimesh_render(cell, zb, W, H, yaws[v], 0-250, 2300, 520, 2)
66 var y: i64 = 0
67 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 }
68 v = v + 1
69 }
70 write_png(gal, GW, H, "knowledge/nx_bunny.png" as *u8)
71 hw("T4 evidence -> knowledge/nx_bunny.png (Stanford bunny, 3 views)\n" as *u8)
72
73 if fails == 0 { hw("BUNNY-GATE GREEN -- the Stanford bunny (the field's standard mesh corpus, EXACT canonical 35947v/69451t) parses via the sovereign OBJ loader and renders smooth on our rasterizer. Census std-mesh-corpus GAP->HAVE. Residual: dragon/buddha (need >96k tri caps) + binary PLY.\n" as *u8); sys_exit(0); return 0 }
74 hw("BUNNY-GATE RED fails="); pn(fails); hw("\n" as *u8)
75 sys_exit(1)
76 return 1
77}