code wiki / (root) / nx_gltf_animated_gate_t181.nx

nx_gltf_animated_gate_t181.nx source

↩ module page · 23 lines · 2797 B

1import "nx_gltf_pose_candidate_t181.nx" 2func gp(s:*u8)->i64{sys_write(1,s,gll_slen(s));return 0} 3func gn(v:i64)->i64{let b:*u8=sys_mmap(32);var x:i64=v;var i:i64=31;if x<0{gp("-");x=0-x};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};sys_write(1,(b as i64+i+1) as *u8,31-i);sys_munmap(b,32);return 0} 4 5func main()->i64{ 6 let ln:*i64=sys_mmap(16) as *i64;let src:*u8=sys_read_file("../knowledge/fetched/rigmodels-tifa-catwalk-143925f3.glb",ln);let cx:*i64=sys_mmap(GLD_CONTEXT_WORDS*8) as *i64 7 if gltf_view_open(src,ln[0],cx)!=0{return 1};let st:*i64=cx[5] as *i64;let count:i64=st[5];if count<=0||count>GLD_I64_MAX/128{return 2} 8 let parents:*i64=sys_mmap(count*8) as *i64;let local:*i64=sys_mmap(count*128) as *i64;let world:*i64=sys_mmap(count*128) as *i64;let done:*i64=sys_mmap(count*8) as *i64;let trs:*i64=sys_mmap(count*80) as *i64;let flags:*i64=sys_mmap(count*8) as *i64;let masks:*i64=sys_mmap(count*8) as *i64 9 let palette:*i64=sys_mmap(st[20]*128) as *i64;let pv:*i64=sys_mmap(GLD_VIEW_WORDS*8) as *i64;let jv:*i64=sys_mmap(GLD_VIEW_WORDS*8) as *i64;let wv:*i64=sys_mmap(GLD_VIEW_WORDS*8) as *i64;let vertex:*i64=sys_mmap(24) as *i64 10 if gltf_accessor_view(cx,0,st[2],pv)!=0||gltf_accessor_view(cx,1,st[2],jv)!=0||gltf_accessor_view(cx,2,st[2],wv)!=0{return 3} 11 if gld_parents(cx,count,parents)!=0{return 4};var sample:i64=0 12 while sample<5{var time:i64=0;if sample==1{time=17895698};if sample==2{time=35791396};if sample==3{time=536870912};if sample==4{time=1252698752} 13 var i:i64=0;while i<count{flags[i]=gld_node_trs(cx,i,(trs as i64+i*80) as *i64,(local as i64+i*128) as *i64);if flags[i]<0{return 5};i=i+1} 14 let channels:i64=gld_animate(cx,0,time,trs,count,masks);if channels<0{gp("ANIMATION_ERROR=");gn(channels);return 6} 15 i=0;while i<count{if flags[i]==0{if gld_trs_matrix((trs as i64+i*80) as *i64,(local as i64+i*128) as *i64)!=0{return 7}};i=i+1} 16 if gld_world_matrices(count,parents,local,world,done)!=0{return 8} 17 let joints:i64=gld_skin_palette(cx,0,world,count,palette,st[20]);if joints<0{gp("PALETTE_ERROR=");gn(joints);return 9} 18 gp("SAMPLE time_q30=");gn(time);gp(" channels=");gn(channels);gp(" joints=");gn(joints);gp(" root71_q20=");var k:i64=0;while k<16{gn(world[71*16+k]);gp(",");k=k+1};gp("\n") 19 i=0;while i<joints{gp("PALETTE joint=");gn(i);gp(" matrix_q20=");k=0;while k<16{gn(palette[i*16+k]);gp(",");k=k+1};gp("\n");i=i+1} 20 i=0;while i<7{var v:i64=0;if i==1{v=1};if i==2{v=100};if i==3{v=1000};if i==4{v=10000};if i==5{v=20000};if i==6{v=pv[1]-1} 21 let rc:i64=gld_skin_vertex(cx,pv,jv,wv,v,palette,joints,vertex);if rc!=0{gp("VERTEX_ERROR=");gn(rc);return 10};gp("VERTEX index=");gn(v);gp(" xyz_q20=");k=0;while k<3{gn(vertex[k]);gp(",");k=k+1};gp("\n");i=i+1} 22 sample=sample+1 23 };gp("ANIMATED_SAMPLES=5\n");return 0}