code wiki / (root) / nx_game_rig_observation_candidate_t331.nx

nx_game_rig_observation_candidate_t331.nx source

↩ module page · 4 lines · 11012 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}\nconst nxResidentRigCapture={serial:0,pending:null,record:null};\nconst nxResidentRigPhases=['native','ankle','collapse','plant'];\nfunction nxResidentRigRequest(actor,request){\n const c=nxResidentRigCapture,action=request?.action||'status',N=GPU?.cast||GL?.npc,actors=Number(ex.mobs());\n if(!Number.isSafeInteger(actor)||!Number.isSafeInteger(actors)||actor<0||actor>=actors||!N?.st?.[actor])return {schema:'nishi-resident-rig-observation/1',state:'refused',reason:'Resident actor is not loaded',actor,actors};\n if(action==='capture'){\n if(c.pending)return {state:'busy',accepted:false,requestedActor:actor,pendingActor:c.pending.actor,requestId:c.pending.id};\n c.record=null;c.pending={id:++c.serial,actor,requestedAt:new Date().toISOString()};return {schema:'nishi-resident-rig-observation/1',state:'waiting',accepted:true,request:c.pending,next:'The next normal evaluation of this actor captures native and draw stages; playback is unchanged.'};\n }\n if(action==='cancel'){\n if(!c.pending)return {state:'unavailable',reason:'No pending capture'};\n if(c.pending.actor!==actor||request?.requestId!==c.pending.id)return {state:'refused',reason:'Cancellation requires matching actor and requestId',requestedActor:actor,pendingActor:c.pending.actor,requestId:c.pending.id};\n const pending=c.pending;if(c.record)c.record.state='cancelled';c.pending=null;return {state:'cancelled',request:pending};\n }\n if(action!=='status'&&action!=='read')return {state:'refused',reason:'Unknown observation action'};\n if(c.pending)return {schema:'nishi-resident-rig-observation/1',state:c.pending.actor===actor?'waiting':'busy',requestedActor:actor,pendingActor:c.pending.actor,request:c.pending};\n if(!c.record||c.record.actor!==actor)return {schema:'nishi-resident-rig-observation/1',state:'unavailable',reason:'No completed capture for this actor'};\n if(action==='read')return c.record;\n return {schema:c.record.schema,state:c.record.state,actor:c.record.actor,tick:c.record.tick,requestId:c.record.requestId,phases:c.record.phases.map(p=>p.name),reason:c.record.reason||null};\n}\nfunction nxResidentRigStage(N,m,v,name,rc=0){\n const c=nxResidentRigCapture,p=c.pending;if(!p||p.actor!==m)return;\n try{\n const refuse=reason=>{c.record={...(c.record||{}),schema:'nishi-resident-rig-observation/1',state:'refused',requestId:p.id,actor:m,phases:c.record?.phases||[],reason};c.pending=null;};\n const expected=c.record?.phases.length||0;\n if(name!==nxResidentRigPhases[expected]){refuse('Unexpected palette phase: expected '+nxResidentRigPhases[expected]+', received '+name);return;}\n if(!Number.isSafeInteger(N.nj)||N.nj<1||!Number.isSafeInteger(v)||v<0||(v+1)*N.nj*8>N.jf.length){refuse('Palette extent invalid');return;}\n if(name==='native'){\n const a=window.__nx_cast_asset;c.record={schema:'nishi-resident-rig-observation/1',state:'capturing',requestId:p.id,actor:m,slot:v,tick:String(ex.tnow()),joints:N.nj,source:a?{sha256:a.sha256||null,url:a.actual_url||a.requested_url||null,bytes:a.bytes||null}:null,units:'model units; quaternion and dual rows divided by4096',positionQ8:[String(ex.mobx(BigInt(m))),String(ex.moby(BigInt(m))),String(ex.mobz(BigInt(m)))],idleQ12:String(ex.cast_iw(BigInt(m))),footJoints:Array.from(N.fj||[]),collapsedJoints:Array.from(N.hc||[],x=>Array.from(x)),phases:[],qualification:'Actual evaluator and page overrides; visual deformation remains unqualified'};\n if(rc<0){refuse('Native palette evaluation failed: '+rc);return;}\n }\n const r=c.record;if(r.actor!==m||r.slot!==v||r.joints!==N.nj||r.tick!==String(ex.tnow())){refuse('Actor, palette, or scene tick changed during capture');return;}\n const rows=Array.from(N.jf.slice(v*N.nj*8,(v+1)*N.nj*8));if(rows.length!==N.nj*8||!rows.every(Number.isFinite)){refuse('Palette rows unavailable or nonfinite');return;}\n r.phases.push({name,rows});if(r.phases.length===nxResidentRigPhases.length){r.plantModelUnits=Number(N.zf[v]);if(!Number.isFinite(r.plantModelUnits)){refuse('Plant translation nonfinite');return;}r.state='observed';r.observedAt=new Date().toISOString();c.pending=null;}\n }catch(error){c.record={schema:'nishi-resident-rig-observation/1',state:'refused',requestId:p.id,actor:m,phases:[],reason:'Observation failed: '+String(error)};c.pending=null;}\n}\nwindow.nishiRigObservation=(asset,node,request)=>{if(asset?.kind==='resident')return nxResidentRigRequest(asset.actor,request);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}