code wiki / (root) / nx_gltf_static_descriptor_candidate_t338.nx

nx_gltf_static_descriptor_candidate_t338.nx source

↩ module page · 62 lines · 5859 B

1import "nx_gltf_render_descriptor_candidate_t181.nx" 2func gpd_static_material_admit(cx:*i64,index:i64)->i64{ 3 if index<0{return 0};let mat:i64=gld_nth(cx,0,"materials",index);if mat<0{return -2} 4 if gli_member(cx,mat,"normalTexture")!=0||gli_member(cx,mat,"occlusionTexture")!=0||gli_member(cx,mat,"emissiveTexture")!=0{return -2} 5 let have:i64=gli_member(cx,mat,"pbrMetallicRoughness");if have<0{return -2} 6 if have==1{let sp:*i64=cx[4] as *i64;let pbr:i64=sp[0] 7 if gli_member(cx,pbr,"baseColorTexture")!=0||gli_member(cx,pbr,"metallicRoughnessTexture")!=0{return -2}} 8 return 0 9} 10// Additive static variant of the existing authored descriptor. No skin, poses or weights are invented. 11// This first boundary admits a single unskinned node with positive uniform axis scale only. 12// cx must already pass gltf_view_open. Refusal may leave partial writer bytes; callers must not publish them. 13// Scalar materials only: this variant emits no UV view and never admits material texture inputs. 14func gpd_static_into(cx:*i64,node:i64,w:*i64,arena:*i64)->i64{ 15 let nodes:i64=gli_array(cx,0,"nodes",0) 16 if nodes!=1||node!=0{return -2} 17 let at:i64=gld_nth(cx,0,"nodes",node) 18 if at<0||gli_member(cx,at,"skin")!=0||gli_member(cx,at,"children")!=0||gli_member(cx,at,"extensions")!=0{return -2} 19 let mesh:i64=gld_int(cx,at,"mesh",-1);let m:i64=gld_nth(cx,0,"meshes",mesh) 20 if m<0||gli_member(cx,m,"weights")!=0||gli_member(cx,m,"extensions")!=0{return -2} 21 if gli_array(cx,m,"primitives",0)!=1{return -2} 22 let p:i64=gld_nth(cx,m,"primitives",0) 23 if p<0||gld_int(cx,p,"mode",4)!=4||gli_member(cx,p,"targets")!=0||gli_member(cx,p,"extensions")!=0{return -2} 24 let sp:*i64=cx[4] as *i64;if gli_member(cx,p,"attributes")!=1{return -2};let a:i64=sp[0] 25 if gli_member(cx,a,"JOINTS_0")!=0||gli_member(cx,a,"WEIGHTS_0")!=0||gli_member(cx,a,"COLOR_0")!=0{return -2} 26 let position:i64=gld_int(cx,a,"POSITION",-1);let normal:i64=gld_int(cx,a,"NORMAL",-1);let index:i64=gld_int(cx,p,"indices",-1) 27 if position<0||normal<0||index<0{return -2} 28 let pv:*i64=arena;let nv:*i64=(arena as i64+GLD_VIEW_WORDS*8) as *i64;let iv:*i64=(arena as i64+GLD_VIEW_WORDS*16) as *i64;let st:*i64=cx[5] as *i64 29 if gltf_accessor_view(cx,position,st[2],pv)!=0||gltf_accessor_view(cx,normal,st[2],nv)!=0||gltf_accessor_view(cx,index,st[2],iv)!=0{return -2} 30 if pv[3]!=5126||nv[3]!=5126||pv[5]!=3||nv[5]!=3||pv[1]!=nv[1]||pv[1]<=0||pv[6]!=0||nv[6]!=0{return -2} 31 if iv[5]!=1||iv[6]!=0||iv[1]%3!=0||(iv[3]!=5121&&iv[3]!=5123&&iv[3]!=5125){return -2} 32 var ix:i64=0;while ix<iv[1]{let off:i64=iv[0]+ix*iv[2];var idx:i64=0 33 if iv[3]==5121{idx=gll_ru8(cx[8] as *u8,off)}else{if iv[3]==5123{idx=gls_ru16(cx[8] as *u8,off)}else{idx=gll_ru32(cx[8] as *u8,off)}} 34 if idx<0||idx>=pv[1]{return -2};ix=ix+1} 35 let trs:*i64=(arena as i64+GLD_VIEW_WORDS*24) as *i64;let matrix:*i64=(trs as i64+10*8) as *i64 36 if gld_node_trs(cx,node,trs,matrix)<0{return -2} 37 if matrix[0]<=0||matrix[0]!=matrix[5]||matrix[0]!=matrix[10]||matrix[15]!=FBB_Q{return -2} 38 var k:i64=0;while k<12{if k!=0&&k!=5&&k!=10{if matrix[k]!=0{return -2}};k=k+1} 39 let bounds:*i64=(matrix as i64+16*8) as *i64;let v:*i64=(bounds as i64+6*8) as *i64;let out:*i64=(v as i64+3*8) as *i64 40 var i:i64=0;while i<pv[1]{k=0;while k<3{if gld_view_float(cx,pv,i,k,FBB_VERTEX_Q,(v as i64+k*8) as *i64)!=0{return -2};k=k+1} 41 k=0;while k<3{if gld_view_float(cx,nv,i,k,FBB_Q,out)!=0{return -2};k=k+1} 42 if fbb_point(matrix,v,out)!=0{return -2} 43 k=0;while k<3{if i==0||out[k]<bounds[k]{bounds[k]=out[k]};if i==0||out[k]>bounds[k+3]{bounds[k+3]=out[k]};k=k+1};i=i+1} 44 gpd_s(w,"{");if gpd_source_identity(w,cx)!=0{return -7} 45 gpd_s(w,"\"schema\":\"nishi-authored-render/1\",\"geometryMode\":\"static\",\"scope\":\"native-static-source-geometry\",\"basis\":\"gltf-Y-up\",\"physicalScale\":null,\"skin\":null,\"joints\":0,\"node\":0,\"q\":1048576,\"transformContract\":\"positive-uniform-axis-scale\",\"sourceBytes\":");gpd_n(w,cx[7]);gpd_s(w,",\"binOffset\":");gpd_n(w,cx[8]-cx[6]);gpd_s(w,",\"mesh\":");gpd_n(w,mesh) 46 gpd_s(w,",\"nodeMatrixQ20\":[");i=0;while i<16{if i>0{gpd_s(w,",")};gpd_i(w,matrix[i]);i=i+1};gpd_s(w,"],\"normalMatrixQ20\":[") 47 i=0;while i<9{if i>0{gpd_s(w,",")};var n:i64=0;if i==0||i==4||i==8{n=FBB_Q*FBB_Q/matrix[0]};gpd_i(w,n);i=i+1};gpd_s(w,"],\"boundsQ20\":[") 48 i=0;while i<6{if bounds[i]>GLD_I64_MAX/(FBB_Q/FBB_VERTEX_Q)||bounds[i]<0-GLD_I64_MAX/(FBB_Q/FBB_VERTEX_Q){return -2};if i>0{gpd_s(w,",")};gpd_i(w,bounds[i]*(FBB_Q/FBB_VERTEX_Q));i=i+1} 49 gpd_s(w,"],\"boundsMethod\":\"native-all-vertices-FX1024-expanded-to-Q20\",\"parts\":[{\"attributes\":{\"POSITION\":");if gpd_view(w,cx,position,pv)!=0{return -2};gpd_s(w,",\"NORMAL\":");if gpd_view(w,cx,normal,nv)!=0{return -2} 50 gpd_s(w,"},\"vertexColorInput\":null,\"litGeometryEligible\":true,\"litGeometryReason\":\"static-source-normals-no-maps\",\"indices\":");if gpd_view(w,cx,index,iv)!=0{return -2};gpd_s(w,",\"material\":") 51 let ma:i64=gld_int(cx,p,"material",-1) 52 if gpd_static_material_admit(cx,ma)!=0{return -2} 53 if ma>=0{if gpd_material(w,cx,ma)!=0{return -2}}else{gpd_s(w,"{\"index\":null,\"source\":\"gltf-default-material\",\"alpha\":0,\"cutoff\":0.5,\"doubleSided\":false,\"factor\":[1,1,1,1],\"metallicFactor\":1,\"roughnessFactor\":1,\"emissiveFactor\":[0,0,0],\"baseColor\":null,\"mapInputs\":{\"normalTexture\":null,\"occlusionTexture\":null,\"emissiveTexture\":null,\"metallicRoughnessTexture\":null},\"litEligible\":true,\"litUnsupportedInputs\":0,\"litReason\":\"gltf-default-material\"}")} 54 gpd_s(w,"}]}");if w[3]!=0{return -3};return 0 55} 56 57func gltf_render_static_descriptor(cx:*i64,node:i64,w:*i64)->i64{ 58 if (cx as i64)<=0||(w as i64)<=0{return -1} 59 let bytes:i64=(GLD_VIEW_WORDS*3+10+16+6+3+3)*8 60 let arena:*i64=sys_mmap_try(bytes) as *i64;if (arena as i64)==0{return -7} 61 let rc:i64=gpd_static_into(cx,node,w,arena);sys_munmap_direct(arena as *u8,bytes);return rc 62}