code wiki / (root) / nx_game_rig_inspection_motion_candidate_t328.nx

nx_game_rig_inspection_motion_candidate_t328.nx source

↩ module page · 4 lines · 6650 B

1// Shared character inspection adapter; all pose and hierarchy mathematics comes from native preparation. 2func gpe_rig_inspection_emit(out:*u8,pos:i64)->i64{ 3 return gpe_ap(out,pos,"function nxRigAdmission(descriptor,packet){\n const r=descriptor.rig;if(r==null)return {state:'unavailable',reason:'Source rig evidence not prepared'};\n const bad=reason=>{throw Error('prepared-rig-'+reason)};\n if(!Array.isArray(packet.samples)||!packet.samples.length||!Number.isSafeInteger(packet.q)||packet.q<=0||!Number.isSafeInteger(packet.timeQ)||packet.timeQ<=0)bad('sample-basis');\n if(r.schema!=='nishi-source-rig/1'||r.sourceSha256!==descriptor.sourceSha256||r.skin!==descriptor.skin||r.q!==packet.q||r.basis!==descriptor.basis||r.matrixOrder!=='column-major'||!Array.isArray(r.nodes)||!r.nodes.length||!Array.isArray(r.jointNodes)||r.jointNodes.length!==descriptor.joints)bad('identity');\n const nodes=r.nodes,slots=new Map();\n for(let i=0;i<nodes.length;i++){const n=nodes[i];if(n.sourceNode!==i||!Number.isSafeInteger(n.parent)||n.parent< -1||n.parent>=nodes.length||n.parent===i||(n.name!==null&&typeof n.name!=='string')||![n.localRest,n.worldRest].every(a=>Array.isArray(a)&&a.length===16&&a.every(Number.isSafeInteger)))bad('node');\n }\n const done=new Uint8Array(nodes.length);for(let i=0;i<nodes.length;i++){let at=i;const path=[];while(at>=0&&done[at]!==2){if(done[at]===1)bad('cycle');done[at]=1;path.push(at);at=nodes[at].parent;}for(const p of path)done[p]=2;}\n r.jointNodes.forEach((node,slot)=>{if(!Number.isSafeInteger(node)||node<0||node>=nodes.length||slots.has(node))bad('joint-index');slots.set(node,slot);});\n let sampled=true;for(const sample of packet.samples){if(sample.jointWorld===undefined){sampled=false;continue;}if(!Array.isArray(sample.jointWorld)||sample.jointWorld.length!==r.jointNodes.length||!sample.jointWorld.every(a=>Array.isArray(a)&&a.length===3&&a.every(Number.isSafeInteger)))bad('joint-world');}\n return {state:'ready',rig:r,slots,sampled,scope:'Source hierarchy and native sampled joint origins; anatomy and contact unqualified'};\n}\nfunction nxRigObservation(D,nodeIndex){\n const a=D.prepared.rigEvidence;if(a?.state!=='ready')return {state:'unavailable',reason:a?.reason||'No rig evidence'};\n const node=Number.isSafeInteger(nodeIndex)?a.rig.nodes[nodeIndex]:null;if(!node)return {state:'unavailable',reason:'Source node unavailable'};\n const slot=a.slots.get(nodeIndex),sample=nxPreparedCurrentSample(D),world=slot===undefined?null:sample.jointWorld?.[slot]||null;\n return {state:'observed',sourceSha256:a.rig.sourceSha256,descriptorSha256:D.prepared.manifest.descriptor.sha256,discretePoseSha256:D.prepared.manifest.poses.sha256,clipSha256:D.prepared.motionActive!==false?D.prepared.motion?.manifest.clip.sha256||null:null,sourceNode:nodeIndex,name:node.name,parent:node.parent,skinSlot:slot??null,sampleIndex:D.prepared.motionActive!==false&&D.prepared.motion?null:D.prepared.selected,mode:D.prepared.motionActive!==false&&D.prepared.motion?D.prepared.motion.mode:'discrete',time:sample.time,timeQ:D.prepared.packet.timeQ,q:a.rig.q,restOrigin:node.worldRest.slice(12,15),sampleOrigin:world,units:'source-scene coordinates (not Beach placement); physical scale unknown',anatomicalRole:'unassigned',continuousPlayback:D.prepared.motionActive!==false&&!!D.prepared.motion?.status().continuousPlayback,terrainContact:'unqualified',navigation:'unbound'};\n}\nfunction nxRigInspection(D,box){\n const a=D.prepared.rigEvidence,details=document.createElement('details'),summary=document.createElement('summary');summary.textContent='Rig and motion evidence';details.append(summary);details.style.maxInlineSize='100%';box.append(details);\n if(a.state!=='ready'){const p=document.createElement('p');p.textContent=a.reason;details.append(p);return;}\n const label=document.createElement('label'),select=document.createElement('select');label.textContent='Source joint ';select.setAttribute('aria-label','Source joint '+D.l);select.style.maxInlineSize='100%';\n for(const n of a.rig.nodes){const o=document.createElement('option');o.value=String(n.sourceNode);o.textContent='#'+n.sourceNode+' '+(n.name||'Unnamed')+' · parent '+n.parent;select.append(o);}label.append(select);details.append(label);\n const status=document.createElement('p'),record=document.createElement('dl'),table=document.createElement('table'),caption=document.createElement('caption');caption.textContent='Native joint origin by sampled time · source-scene coordinates (not Beach placement)';table.append(caption);const head=document.createElement('thead'),hr=document.createElement('tr');for(const text of ['Time (s)','X','Y','Z']){const th=document.createElement('th');th.textContent=text;hr.append(th);}head.append(hr);table.append(head);const body=document.createElement('tbody');table.append(body);const scroll=document.createElement('div');scroll.style.cssText='max-inline-size:100%;max-block-size:40vh;overflow:auto';scroll.append(table);details.append(record,scroll,status);\n let tableSlot=undefined;const update=()=>{const o=nxRigObservation(D,Number(select.value));window.__nx_rig_observation=o;record.replaceChildren();for(const [key,value]of [['Node',o.name||'Unnamed'],['Source index',o.sourceNode],['Parent index',o.parent],['Skin slot',o.skinSlot??'Not skinned'],['Selected time',(o.time/o.timeQ).toFixed(3)+' s'],['Anatomical role','Unassigned']]){const dt=document.createElement('dt'),dd=document.createElement('dd');dt.textContent=key;dd.textContent=String(value);record.append(dt,dd);}\n if(tableSlot!==o.skinSlot){tableSlot=o.skinSlot;body.replaceChildren();for(const sample of D.prepared.packet.samples){const row=document.createElement('tr'),p=o.skinSlot===null?null:sample.jointWorld?.[o.skinSlot];for(const value of [(sample.time/D.prepared.packet.timeQ).toFixed(3),...(p?p.map(v=>(v/o.q).toFixed(4)):['—','—','—'])]){const td=document.createElement('td');td.textContent=value;row.append(td);}body.append(row);}}\n status.textContent=(o.sampleOrigin?'Native joint samples available. ':'Joint motion not sampled. ')+(D.prepared.motionActive!==false&&D.prepared.motion?'Current native clip time '+(o.time/o.timeQ).toFixed(3)+' s. ':'Discrete native pose. ')+'Anatomical fit, contact and navigation remain unqualified.';\n };\n select.addEventListener('change',update);details.addEventListener('toggle',()=>{if(details.open)update();});D.prepared.rigRefresh=()=>{if(details.open)update();};update();\n}\nwindow.nishiRigObservation=(asset,node)=>{const D=DN.find(d=>d.sourceId===asset);return D?.prepared?nxRigObservation(D,node):{state:'unavailable',reason:'Prepared actor not loaded'};};\n" as *u8) 4}