nx_game_page_emit.nx source
↩ module page · 264 lines · 119476 B
1// nx_game_page_emit.nx -- the SOVEREIGN game-page emitter. Until now the browser page for a wasm
2// game was assembled by printf blocks in _ops/nx_emit_game.sh -- real emission logic living in
3// SHELL, against the doctrine (shell only LAUNCHES sovereign ELFs). This organ owns it: reads the
4// .wasm, base64-encodes it (composes nx_base64 -- one encoder, not a coreutils dependency), and
5// emits the complete self-contained page (marker, shim, input forwarding, persistence bytes-mover).
6// usage: nx_game_page_emit <wasm> <out.html> <title> <native-client-name> <controls-html>
7//
8// RECOVERED 2026-08-02 from buildroot/_build/nx_craft_emit.s (the 14:07 build's data section)
9// after a failed in-place rewrite TRUNCATED this file to 0 bytes and the damage was copied to
10// both trees. Every emitted chunk below is the exact byte sequence that build shipped, so the
11// recovered emitter is byte-equivalent to the last one that passed both gates.
12// license_tier: ORIGINAL
13import "nx_syscalls.nx"
14import "nx_base64.nx"
15
16const GPE_WASM_CAP: i64 = 4194304
17const GPE_OUT_CAP: i64 = 16777216
18
19func gpe_slen(s: *u8) -> i64 { var k: i64 = 0; while s[k] != (0 as u8) { k = k + 1 } return k }
20func gpe_ap(out: *u8, pos: i64, s: *u8) -> i64 {
21 var k: i64 = 0
22 var p: i64 = pos
23 while s[k] != (0 as u8) { out[p] = s[k]; p = p + 1; k = k + 1 }
24 return p
25}
26func gpe_ap_n(out: *u8, pos: i64, s: *u8, n: i64) -> i64 {
27 var k: i64 = 0
28 var p: i64 = pos
29 while k < n { out[p] = s[k]; p = p + 1; k = k + 1 }
30 return p
31}
32
33// GPE-VERIFY v2 (negctl PROVEN 2026-08-02: uBAD9 refused the ship, name printed) -- the
34// page-side compile lint (debt 1785728065, which bit TWICE on 2026-08-02:
35// a backtick inside a shader comment killed the whole page script, and a uniform used in a
36// stage that never declared it killed the NPC program -- both shipped behind GREEN gates,
37// caught only by screenshots). The emit lane cannot run a browser, but BOTH classes are
38// mechanically visible in the emitted bytes: (a) an UNCLOSED backtick segment = the JS-string
39// kill; (b) inside each backtick segment (the shader sources are the page's only template
40// literals), any uXxx token USED but not DECLARED as a uniform in THAT segment = the stage
41// kill. Fails CLOSED: any hit refuses the ship with the name printed.
42func gpe_verify(out: *u8, n: i64) -> i64 {
43 let names: *u8 = sys_mmap(64*32)
44 var nn: i64 = 0
45 var bad: i64 = 0
46 var seg: i64 = 0 - 1
47 var i: i64 = 0
48 while i < n {
49 if out[i] == (96 as u8) {
50 if seg < 0 { seg = i + 1 } else {
51 // ---- declarations in [seg, i) ----
52 nn = 0
53 var p: i64 = seg
54 while p < i - 8 {
55 var hit: i64 = 1
56 let kw: *u8 = "uniform " as *u8
57 var kk: i64 = 0
58 while kk < 8 { if out[p+kk] != kw[kk] { hit = 0; kk = 8 } else { kk = kk + 1 } }
59 if hit == 1 {
60 var q: i64 = p + 8
61 var ts: i64 = 0 - 1
62 var ls: i64 = 0 - 1
63 var le: i64 = 0 - 1
64 var run: i64 = 1
65 while run == 1 {
66 if q >= i { run = 0 } else {
67 let c: i64 = out[q] as i64
68 var idc: i64 = 0
69 if c >= 97 { if c <= 122 { idc = 1 } }
70 if c >= 65 { if c <= 90 { idc = 1 } }
71 if c >= 48 { if c <= 57 { idc = 1 } }
72 if c == 95 { idc = 1 }
73 if idc == 1 { if ts < 0 { ts = q } }
74 if idc == 0 {
75 if ts >= 0 { ls = ts; le = q; ts = 0 - 1 }
76 if c == 59 { run = 0 }
77 if c == 91 { run = 0 }
78 }
79 q = q + 1
80 }
81 }
82 if ls >= 0 { if nn < 64 {
83 var k: i64 = 0
84 while k < 31 {
85 if ls + k < le { names[nn*32+k] = out[ls+k] } else { names[nn*32+k] = 0 as u8 }
86 k = k + 1
87 }
88 names[nn*32+31] = 0 as u8
89 nn = nn + 1
90 } }
91 }
92 p = p + 1
93 }
94 // ---- usages uXxx in [seg, i) ----
95 var p2: i64 = seg
96 while p2 < i - 1 {
97 var go: i64 = 0
98 if out[p2] == (117 as u8) {
99 let c2: i64 = out[p2+1] as i64
100 if c2 >= 65 { if c2 <= 90 { go = 1 } }
101 }
102 if go == 1 { if p2 > seg {
103 let pb: i64 = out[p2-1] as i64
104 if pb >= 97 { if pb <= 122 { go = 0 } }
105 if pb >= 65 { if pb <= 90 { go = 0 } }
106 if pb >= 48 { if pb <= 57 { go = 0 } }
107 if pb == 95 { go = 0 }
108 } }
109 if go == 1 {
110 var e2: i64 = p2 + 1
111 var r2: i64 = 1
112 while r2 == 1 {
113 if e2 >= i { r2 = 0 } else {
114 let c3: i64 = out[e2] as i64
115 var id3: i64 = 0
116 if c3 >= 97 { if c3 <= 122 { id3 = 1 } }
117 if c3 >= 65 { if c3 <= 90 { id3 = 1 } }
118 if c3 >= 48 { if c3 <= 57 { id3 = 1 } }
119 if c3 == 95 { id3 = 1 }
120 if id3 == 1 { e2 = e2 + 1 } else { r2 = 0 }
121 }
122 }
123 let ln: i64 = e2 - p2
124 var found: i64 = 0
125 var t2: i64 = 0
126 while t2 < nn {
127 var m2: i64 = 1
128 if ln > 31 { m2 = 0 }
129 if m2 == 1 {
130 var k2: i64 = 0
131 while k2 < ln {
132 if names[t2*32+k2] != out[p2+k2] { m2 = 0; k2 = ln } else { k2 = k2 + 1 }
133 }
134 }
135 if m2 == 1 { if names[t2*32+ln] != (0 as u8) { m2 = 0 } }
136 if m2 == 1 { found = 1; t2 = nn } else { t2 = t2 + 1 }
137 }
138 if found == 0 {
139 bad = bad + 1
140 let msg: *u8 = "GPE-VERIFY v2 RED: uniform used but not declared in its shader stage: " as *u8
141 sys_write(2, msg, gpe_slen(msg))
142 sys_write(2, ((out as i64) + p2) as *u8, ln)
143 sys_write(2, "\n" as *u8, 1)
144 }
145 p2 = e2 - 1
146 }
147 p2 = p2 + 1
148 }
149 seg = 0 - 1
150 }
151 }
152 i = i + 1
153 }
154 if seg >= 0 {
155 bad = bad + 1
156 let m2s: *u8 = "GPE-VERIFY RED: UNCLOSED backtick segment -- the page script is dead\n" as *u8
157 sys_write(2, m2s, gpe_slen(m2s))
158 }
159 return bad
160}
161
162// build the page into `out`; returns its byte length. Pure of the filesystem so the gate can
163// drive it with synthetic wasm bytes and byte-assert the result. vnum = game-spec VARIANT the
164// page selects at init (one engine wasm, many games -- the emission lever).
165func gpe_build(wasm: *u8, wn: i64, title: *u8, native: *u8, ctrl: *u8, vnum: i64, out: *u8) -> i64 {
166 let b64: *u8 = sys_mmap((wn/3 + 2)*4 + 64)
167 let bn: i64 = b64_encode(wasm, wn, b64)
168 var p: i64 = 0
169 p = gpe_ap(out, p, "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>" as *u8)
170 p = gpe_ap(out, p, title)
171 p = gpe_ap(out, p, "</title><meta name=\"nishi-game\" content=\"" as *u8)
172 p = gpe_ap(out, p, native)
173 p = gpe_ap(out, p, "\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>\nhtml{height:100%}\nbody{margin:0;min-height:100%;background:#08070f;color:#e9e5f5;font:14px/1.5 system-ui,sans-serif;\ndisplay:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;padding:12px 0;box-sizing:border-box}\ncanvas{image-rendering:pixelated;width:min(98vw,1920px);border:1px solid #2f2a4a;border-radius:4px;touch-action:none}\ncanvas:fullscreen{width:100vw;height:100vh;border:0}\nh1{margin:0;font:600 15px/1 ui-monospace,monospace;letter-spacing:.14em;text-transform:uppercase;color:#b9b1dc}\np{margin:0;color:#7d76a0;font:12px/1.6 ui-monospace,monospace;text-align:center;max-width:70ch}\nb{color:#a8e6c0}</style></head><body><h1>" as *u8)
174 p = gpe_ap(out, p, title)
175 p = gpe_ap(out, p, "</h1><canvas id=\"c\"></canvas>\n<p>" as *u8)
176 p = gpe_ap(out, p, ctrl)
177 p = gpe_ap(out, p, "<br>\nEvery pixel above is emitted by NishiLang compiled to WebAssembly.<br>\nThis page holds no game logic and no drawing code — it copies a framebuffer and forwards keys.</p>\n<script>\nconst B=\"" as *u8)
178 p = gpe_ap_n(out, p, b64, bn)
179 p = gpe_ap(out, p, "\";\nconst bytes=Uint8Array.from(atob(B),c=>c.charCodeAt(0));\nWebAssembly.instantiate(bytes).then(r=>{const ex=r.instance.exports;\nconst W=Number(ex.ww()),H=Number(ex.hh()),off=Number(ex.fb_off());\nconst cv=document.getElementById(\"c\");\n// a canvas holds ONE context type forever -- GL must claim it BEFORE any 2d setup\nlet ctx=null,img=null;\nfunction blit(){if(!ctx)return;const m=new Uint32Array(ex.memory.buffer,off,W*H*2);const d=new Uint32Array(img.data.buffer);\nfor(let i=0;i<W*H;i++){d[i]=m[i*2]|0xff000000;}\nctx.putImageData(img,0,0);}\nconst NXV=" as *u8)
180 // the ACTUAL identity digit (a 1-else-0 emit silently booted every v>=2 world as v0)
181 out[p] = (48 + vnum) as u8
182 p = p + 1
183 p = gpe_ap(out, p, ";\nif(NXV&&ex.init_v)ex.init_v(BigInt(NXV),BigInt(20260728));else ex.init();\n" as *u8)
184 p = gpe_ap(out, p, "// GPU DISPLAY PATH: the same DDA raycast as a fragment shader, EMITTED by the sovereign page\n// emitter. The organ keeps ALL game logic + quality authority; the GPU only draws its state at\n// TRUE DEVICE RESOLUTION (4K on a 4K panel). CPU wasm render remains the gate-proven truth and\n// the automatic fallback (?gl=0 forces it).\nlet GL=null;\nconst VSH=`#version 300 es\\nvoid main(){vec2 v=vec2((gl_VertexID<<1)&2,gl_VertexID&2);gl_Position=vec4(v*2.-1.,0.,1.);}`;\n" as *u8)
185 p = gpe_ap(out, p, "const FSH=`#version 300 es\nprecision highp float;precision highp int;\nuniform highp usampler3D uV;uniform vec3 uCam;uniform vec4 uYP;uniform vec3 uPal[12];\nuniform vec3 uPalF[5];uniform vec3 uSunD;uniform int uRain;\nuniform vec3 uSkT;uniform vec3 uSkH;uniform int uSun;uniform int uCld;uniform float uT;\nuniform vec2 uRes;uniform int uWmax;uniform int uSelB;uniform int uHok;\nuniform int uNpcT;\nout vec4 fc;\nuint vx(ivec3 c){if(c.x<0||c.y<0||c.z<0||c.x>127||c.y>47||c.z>127)return 0u;return texelFetch(uV,ivec3(c.x,c.z,c.y),0).r;}\nfloat h21(vec2 p){return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453);}\nfloat h31(vec3 p){return fract(sin(dot(p,vec3(127.1,311.7,74.7)))*43758.5453);}\nvec3 pal(uint b){int i=int(b);if(i<0)i=0;if(i>16)i=16;return i<12?uPal[i]:uPalF[i-12];}\n" as *u8)
186 p = gpe_ap(out, p, "vec3 sky(vec3 rd){vec3 s=mix(uSkH,uSkT,clamp(rd.y*1.6+.35,0.,1.));\nif(uSun==1){float d=dot(rd,uSunD);\nif(d>.9993)s=vec3(1.,.98,.88);else if(d>.985)s=mix(s,vec3(1.,.98,.88),(d-.985)/.015*.6);}\nif(uCld==1&&rd.y>.04){vec2 cp=uCam.xz+rd.xz*((56.-uCam.y)/rd.y);\nvec2 p1=cp/14.+vec2(uT/240.,uT/540.);vec2 i1=floor(p1),f1=smoothstep(0.,1.,fract(p1));\nfloat n=mix(mix(h21(i1),h21(i1+vec2(1.,0.)),f1.x),mix(h21(i1+vec2(0.,1.)),h21(i1+vec2(1.,1.)),f1.x),f1.y);\nvec2 p2=cp/37.+vec2(uT/300.,0.);vec2 i2=floor(p2),f2=smoothstep(0.,1.,fract(p2));\nfloat n2=mix(mix(h21(i2),h21(i2+vec2(1.,0.)),f2.x),mix(h21(i2+vec2(0.,1.)),h21(i2+vec2(1.,1.)),f2.x),f2.y);\nfloat cv=n*.55+n2*.6;if(cv>.6)s=mix(s,vec3(.98,.99,1.),min((cv-.6)*2.6,.9));}\nreturn s;}\n" as *u8)
187 p = gpe_ap(out, p, "float march(vec3 ro,vec3 rd,out ivec3 hc,out int fce,out uint hb,int skipw,int mx){\nivec3 c=ivec3(floor(ro));ivec3 st=ivec3(sign(rd));vec3 dd=abs(1./max(abs(rd),1e-6));\nvec3 tm=(vec3(st)*(vec3(c)-ro)+vec3(st)*.5+.5)*dd;float t=0.;\nfor(int i=0;i<200;i++){if(i>=mx)break;\nif(tm.x<tm.y&&tm.x<tm.z){c.x+=st.x;t=tm.x;tm.x+=dd.x;fce=st.x>0?2:1;}\nelse if(tm.y<tm.z){c.y+=st.y;t=tm.y;tm.y+=dd.y;fce=st.y>0?4:3;}\nelse{c.z+=st.z;t=tm.z;tm.z+=dd.z;fce=st.z>0?6:5;}\nif(c.y>uWmax&&rd.y>=0.)return -1.;if(c.y<0)return -1.;\nif(c.x<-8||c.x>135||c.z<-8||c.z>135)return -1.;\nuint b=vx(c);if(skipw==1&&b==4u)b=0u;\nif(b!=0u){hc=c;hb=b;return t;}}\nreturn -1.;}\n" as *u8)
188 p = gpe_ap(out, p, "vec3 shade(vec3 ro,vec3 rd,float t,ivec3 c,int fce,uint b){\nvec3 hp=ro+rd*t;\nvec2 uv;ivec3 oc=c;vec3 n=vec3(0.);\nif(fce==1){uv=hp.zy;oc.x+=1;n=vec3(1.,0.,0.);}else if(fce==2){uv=hp.zy;oc.x-=1;n=vec3(-1.,0.,0.);}\nelse if(fce==3){uv=hp.xz;oc.y+=1;n=vec3(0.,1.,0.);}else if(fce==4){uv=hp.xz;oc.y-=1;n=vec3(0.,-1.,0.);}\nelse if(fce==5){uv=hp.xy;oc.z+=1;n=vec3(0.,0.,1.);}else{uv=hp.xy;oc.z-=1;n=vec3(0.,0.,-1.);}\nvec2 f=fract(uv);\nuint bb=b;if(b==1u&&fce!=3&&fce!=4){bb=2u;if(f.y>.8)bb=1u;}\nfloat li=fce==3?1.:fce==4?.42:fce==1?.76:fce==2?.7:fce==5?.62:.56;\nif(uSun==1){if(fce==1)li*=1.12;if(fce==2)li*=.92;if(fce==5)li*=1.04;}\n// BUMP MAPPING: texel-hash height field -> gradient -> sun-lit micro-relief (the det lever:\n// real 1px luminance structure on every face, the difference between flat tint and rough matter)\nvec3 sd3=floor(hp)*.13;float bs=float(b)*7.;\nfloat t00=h31(vec3(floor(f*24.),bs)+sd3);\nfloat t10=h31(vec3(floor(f*24.+vec2(1.,0.)),bs)+sd3);\nfloat t01=h31(vec3(floor(f*24.+vec2(0.,1.)),bs)+sd3);\nfloat bmp=(t10-t00)*.6+(t01-t00)*.45;\nfloat bamp=b==3u||b==2u||b==9u||b==10u||b==11u?1.:b==7u?1.3:b==4u?.25:.7;\nfloat dfade=clamp(1.-t/24.,0.,1.);/*hash detail below pixel frequency reads as TV static (beach sand vistas, 08-03 frame); a hash cannot be mip-averaged, so micro-relief fades out by 24 blocks and flat tint + fog carry the far field*/li*=clamp(1.+bmp*bamp*dfade,.55,1.45);\nfloat tx=t00;\nli*=.9+tx*.2*dfade;\n// grass tufts: sparse taller blades on grass tops read as vegetation, not paint\nif(bb==1u&&fce==3&&t<24.){float tf=h21(floor(f*38.)+floor(hp.xz)*3.7);\nif(tf>.82)li*=1.28;else if(tf<.14)li*=.78;}\nif(f.x<.055||f.x>.945||f.y<.055||f.y>.945)li*=.82;\nfloat ao=0.;\nvec2 ua=fce==3||fce==4?vec2(1.,0.):fce<3?vec2(0.,0.):vec2(1.,0.);\nif(f.x<.17){ivec3 nb=oc;if(fce==3||fce==4)nb.x-=1;else if(fce<3)nb.z-=1;else nb.x-=1;if(vx(nb)!=0u&&vx(nb)!=4u)ao+=(.17-f.x)*2.;}\nif(f.x>.83){ivec3 nb=oc;if(fce==3||fce==4)nb.x+=1;else if(fce<3)nb.z+=1;else nb.x+=1;if(vx(nb)!=0u&&vx(nb)!=4u)ao+=(f.x-.83)*2.;}\nif(f.y<.17){ivec3 nb=oc;if(fce==3||fce==4)nb.z-=1;else nb.y-=1;if(vx(nb)!=0u&&vx(nb)!=4u)ao+=(.17-f.y)*2.;}\nif(f.y>.83){ivec3 nb=oc;if(fce==3||fce==4)nb.z+=1;else nb.y+=1;if(vx(nb)!=0u&&vx(nb)!=4u)ao+=(f.y-.83)*2.;}\nli*=1.-min(ao,.45);\n// SUN SHADOWS: one march from the hit point toward the sun; blocked = shadow (ambient kept)\nif(uSun==1){ivec3 sc2;int sf2;uint sb2;\nif(march(hp+n*.02,uSunD,sc2,sf2,sb2,1,60)>0.)li*=.55;}\nvec3 col=pal(bb)*li;\nfloat fog=clamp(t/46.,0.,.92);\nreturn mix(col,sky(rd),fog);}\n" as *u8)
189 p = gpe_ap(out, p, "void main(){\nvec2 sc=(gl_FragCoord.xy-uRes*.5)/(uRes.x*.5);\nvec3 fw=vec3(uYP.x*uYP.w,uYP.z,uYP.y*uYP.w);\nvec3 rt=vec3(uYP.y,0.,-uYP.x);\nvec3 up=vec3(-uYP.x*uYP.z,uYP.w,-uYP.y*uYP.z);\nvec3 rd=normalize(fw+rt*sc.x+up*sc.y);\nvec3 ro=uCam;\nivec3 hc;int fce=0;uint hb=0u;\nfloat t=march(ro,rd,hc,fce,hb,0,200);\nvec3 col;\nif(t<0.)col=sky(rd);\nelse{col=shade(ro,rd,t,hc,fce,hb);\nif(hb==4u){ivec3 h2;int f2;uint b2;float t2=march(ro,rd,h2,f2,b2,1,200);\nif(t2>0.)col=col*.58+shade(ro,rd,t2,h2,f2,b2)*.42;}}\n" as *u8)
190 p = gpe_ap(out, p, "vec2 px=gl_FragCoord.xy;vec2 ctr=uRes*.5;\n// RAIN (A1 weather made visible): cheap screen-space streaks + a wet dim, organ-driven\nif(uRain==1){float rr=h21(vec2(floor((px.x+px.y*.35)/2.),floor((px.y+uT*13.)/26.)));\nif(rr>.945)col=mix(col,vec3(.75,.8,.92),.45);col*=.93;/*re-raised 08-03: .965/.28 had thinned rain to invisible -- HUD said RAIN | MOOD -8 (soaked) over a clean blue sky; weather the mood ledger charges for must be visible in the frame*/}\nif((abs(px.x-ctr.x)<8.&&abs(px.y-ctr.y)<1.5)||(abs(px.y-ctr.y)<8.&&abs(px.x-ctr.x)<1.5))col=uNpcT>=0?vec3(1.,.45,.65):(uHok==1?vec3(1.,.82,.35):vec3(1.));\nfloat hbY=uRes.y*.045;float hbS=uRes.x*.018;\nfor(int s=0;s<7;s++){vec2 o=vec2(uRes.x*.02+float(s)*hbS*1.5,hbY);\nif(px.x>=o.x&&px.x<o.x+hbS&&px.y>=o.y&&px.y<o.y+hbS){int bt=s==0?3:s==1?2:s==2?6:s==3?7:s==4?5:s==5?12:13;col=s<5?uPal[bt-1]:uPalF[bt-12];\nif(bt==uSelB&&(px.x<o.x+2.||px.x>o.x+hbS-2.||px.y<o.y+2.||px.y>o.y+hbS-2.))col=vec3(1.);}}\nfc=vec4(col,1.);}`;\n" as *u8)
191 p = gpe_ap(out, p, "// SKINNED NXA NPC PASS (craft integration, the NXA lane's hybrid design): the benchmark body\n// (VERT/TRIS/SKEL/SKIN/ANIM from /world/ref8.nxa) walks the world as mob 0, LBS in the vertex\n// shader per the format's world-delta law M x = D(x-b)+b+dt -- no hierarchy at runtime. The DDA\n// pass publishes gl_FragDepth; this pass z-tests against it, so terrain occludes her correctly.\nconst MVS=`#version 300 es\nlayout(location=0) in vec3 aP;layout(location=1) in vec4 aJ;layout(location=2) in vec4 aW;layout(location=3) in vec3 aN;\nuniform sampler2D uJT;uniform float uSc;\nuniform vec3 uIP[12];uniform vec4 uIH[12];\nuniform vec3 uSB[36];\nuniform float uOF[12];\nuniform float uGN[12];\nuniform float uTm;uniform float uWnd;\nuniform float uZMN;uniform float uH;uniform float uNIP;\nuniform vec4 uDNL;uniform vec4 uDNR;\nuniform vec3 uCamM;uniform vec4 uYPM;uniform vec2 uResM;\nuniform int uHM;uniform int uGar;\nout vec3 vB;out vec3 vW;out vec3 vN;flat out int vII;flat out float vSh;\nfloat hsh(float s){return fract(sin(s*127.1)*43758.5453);}\nvoid main(){\n// hair DENSIFICATION (viewer-lane guide-interpolation, girl-instanced): when uHM>1 the\n// instance id decodes to (girl, lock); each lock is the guide jittered in model space with\n// its own shade -- hundreds of guides render as thousands of locks, CPU cost unchanged\nint ii=gl_InstanceID;\nvec3 jit=vec3(0.);vSh=1.;\nif(uHM>1){int lk=ii-(ii/uHM)*uHM;ii=ii/uHM;\nfloat f1=hsh(float(lk)+1.),f2=hsh(float(lk)+7.),f3=hsh(float(lk)+13.);\n// PER-GIRL HAIR STYLE, not one helmet (operator: weird helmet, not hair styles): her genome\n// row (uGN 0..3) sets lock DENSITY (sleek girls drop locks entirely), jitter SPREAD (tight vs\n// voluminous) and an asymmetric side-sweep bias -- one guide set, visibly different grooms.\nfloat gs9=uGN[ii];\nif(hsh(float(lk)+41.)>.55+.15*gs9){gl_Position=vec4(0.,-999.,0.,1.);vB=vec3(0.);vW=vec3(0.,-999.,0.);vN=vec3(0.,1.,0.);vII=ii;vSh=0.;return;}\nfloat sp9=(.48+.22*hsh(gs9*17.+float(ii)*3.1))*260.;\nfloat sw9=(hsh(float(ii)*7.7+2.)-.5)*.9;\njit=vec3((f1-.5+sw9*.4)*sp9,(f2-.5)*sp9,(f3-.5)*90.);\nvSh=.72+.5*hsh(float(lk)+29.);}\nvII=ii;\n// +.5 before int(): drivers may store 3.0 as 2.9999997 -- truncation would read the WRONG row\nint rb=int(uIH[ii].w+.5);int rd2=rb+1;\n// DUAL-QUATERNION skinning, ported from the PROVEN rigmesh viewer: linear blend collapses\n// under the T-pose->arms-down delta (splayed arms + shredded extremities on hardware).\nvec4 r0=texelFetch(uJT,ivec2(int(aJ.x+.5),rb),0),d0=texelFetch(uJT,ivec2(int(aJ.x+.5),rd2),0);\nvec4 r1=texelFetch(uJT,ivec2(int(aJ.y+.5),rb),0),d1=texelFetch(uJT,ivec2(int(aJ.y+.5),rd2),0);\nvec4 r2=texelFetch(uJT,ivec2(int(aJ.z+.5),rb),0),d2=texelFetch(uJT,ivec2(int(aJ.z+.5),rd2),0);\nvec4 r3=texelFetch(uJT,ivec2(int(aJ.w+.5),rb),0),d3=texelFetch(uJT,ivec2(int(aJ.w+.5),rd2),0);\nfloat s1=dot(r0,r1)<0.?-1.:1.;float s2=dot(r0,r2)<0.?-1.:1.;float s3=dot(r0,r3)<0.?-1.:1.;\nvec4 br=aW.x*r0+aW.y*s1*r1+aW.z*s2*r2+aW.w*s3*r3;\nvec4 bd=aW.x*d0+aW.y*s1*d1+aW.z*s2*d2+aW.w*s3*d3;\nfloat nr=max(length(br),1e-6);br/=nr;bd/=nr;\nvec3 aP2=aP+jit;\n// PASS-1 MASS, cut 1 (pointing machine v0.1, symmetrized n=6 ref frames): the NOSE BLOCK sits\n// +7.3mm LOW (3.5x ref spread) and the bridge +4.7mm, while the CHIN is already right (-3.6,\n// inside spread) -- the midface is stretched between the eyes and the nose, NOT uniformly long.\n// The cut: a LOCALIZED upward z-shift peaked at the nose line (.918H), zero at the eye line and\n// at the jaw, so nose+upper-lip rise ~7mm and the chin stays. Pure bind-space translation --\n// no normal displacement (the goblin trap), composes with skinning; paint bands select on vB\n// so painted features ride the same vertices coherently.\nif(uHM==1){\nfloat hb1=(aP.z-uZMN)/uH;\nfloat w1=smoothstep(.885,.918,hb1)*(1.-smoothstep(.918,.9448,hb1));\naP2.z+=704.*w1;\n// PASS-1 cut 2 (re-measure: verticals ZEROED, cheek_width -5.1mm the last significant error):\n// widen the sub-eye face band 8% peaked at the cheeks. MUST be zero at the EYE LINE -- IPD is\n// the normalizer, a whole-head scale cancels out of the measurement; width is relative to eyes.\nfloat w2=smoothstep(.9448,.920,hb1)*(1.-smoothstep(.895,.868,hb1));\naP2.x*=1.+.08*w2;}\n// FACE RELIEF, first rung (mhbench queue head: face@head measured 79 -- head-SHAPED, surface\n// FEATURELESS, no nose AS GEOMETRY). The same anatomy-canon landmarks the fragment shader\n// paints now DISPLACE the bind mesh along its own normals BEFORE skinning: nose ridge out\n// (nasal projection ~.095 of head height ~ 19mm, published adult ratio), orbital sockets in\n// (~1cm), lip and chin relief out. Bind-space displacement composes with skinning, springs\n// and every pass downstream; the skull-lane FACE section is the mm rung that replaces this.\n// (FACE RELIEF v1 REVERTED 2026-08-03, operator-caught: goblin noses. Root cause: this mesh's\n// normals are MAJORITY-INWARD (banked from the drape lane -- and not applied here), so\n// displacing along aN pushed much of the nose band IN and SIDEWAYS: a hooked dent, not a\n// ridge. v2 requires (a) an outwardness guard: flip aN by sign(dot(aN, aP - head_center)),\n// (b) half the magnitude, (c) portrait-framed screenshot calibration BEFORE ship -- the\n// face camera now exists for exactly this. The mm rung remains the skull-lane FACE bake.)\nvec3 sp=aP2+2.*cross(br.xyz,cross(br.xyz,aP2)+br.w*aP2)+2.*(br.w*bd.xyz-bd.w*br.xyz+cross(br.xyz,bd.xyz));\nvec3 sn=aN+2.*cross(br.xyz,cross(br.xyz,aN)+br.w*aN);\nvec3 nyup=vec3(sn.x,sn.z,-sn.y);\nvN=vec3(nyup.x*uIH[ii].y-nyup.z*uIH[ii].x,nyup.y,nyup.x*uIH[ii].x+nyup.z*uIH[ii].y);\nvB=aP;\nvec3 yup=vec3(sp.x,sp.z,-sp.y);\nvec3 rot=vec3(yup.x*uIH[ii].y-yup.z*uIH[ii].x,yup.y,yup.x*uIH[ii].x+yup.z*uIH[ii].y);\nvec3 wp=uIP[ii]+rot*(uSc*uIH[ii].z);\n// A4 SOFT-BODY, joint-honest: chest springs ride the CHEST JOINTS (dual-quat dt rows set\n// CPU-side -- the spring-decomposed-skinning contract's \"designated joints\"). Vertex-level\n// offsets here touch ONLY media that is soft EVERYWHERE: hair strands (tip-weighted, crown\n// pinned) and the dress hem. The skull is bone: it gets NOTHING (head-bobble class,\n// operator-caught -- height bands guessed anatomy; joints ARE anatomy).\n// NORMALIZE IN THE MESH'S OWN SPACE: (z - zmin)/H, both measured from the asset. Dividing by a\n// nominal height while ignoring a 1474-unit origin put every landmark ~1% low and, worse, made\n// the numbers unauditable. The anatomy probe supplies uZMN/uH; uNIP is the bust height DERIVED\n// from this mesh's own pelvis/head anchors through published anthropometric ratios.\nfloat hb2=(aP.z-uZMN)/uH;\nvec3 sbo=vec3(0.);\nif(uHM>1){float tw9=clamp((1.02-hb2)*1.7,0.,1.);sbo=uSB[ii*3]*tw9;\n// WEATHER IN THE HAIR (operator: hair should react to weather, not just bounce idly): a wind\n// sway rides the same tip weight the spring uses -- amplitude uWnd comes from the ORGAN's own\n// weather door (rain = storm wind, clear = breeze), time from the ORGAN tick, phase per lock\n// from its shade hash so the locks never move in unison.\nfloat wp9=uTm*3.1+vSh*7.9;\nsbo+=vec3(.7,.15*sin(wp9*1.7),.7)*(sin(wp9)*uWnd*tw9);}\nelse if(uGar==1){sbo=uSB[ii*3+2]*(1.-smoothstep(.30,.55,hb2));\n// E4 LAYERING-BY-CONSTRUCTION leg 1: the dress INHERITS the body's soft-tissue field over the\n// same DYNA anchors -- the chest moved and the dress top did not, so the body poked through\n// the cloth on every bounce. A layer that rides its underlayer's field cannot be pierced by\n// it: same displacement, same phase, zero cloth-vs-body collision needed.\nif(uDNL.w>0.5){float wLg=1.-smoothstep(0.,uDNL.w*1.4,length(aP-uDNL.xyz));float wRg=1.-smoothstep(0.,uDNR.w*1.4,length(aP-uDNR.xyz));sbo+=uSB[ii*3+1]*max(wLg,wRg);}}\nelse{\n// PER-SIDE FIELDS FROM THE ASSET'S OWN DYNA ANCHORS (I6 leg 1). The old comment here said\n// \"this rig ships no breast bones\" -- it DOES now: nx_nxa_dyna measured each side's anchor\n// as the centroid of that side's bust-band vertices and shipped them in the file. Each\n// side's weight falls off from ITS anchor over ITS declared influence radius (they meet at\n// the midline by construction), so the field is anatomically anchored per side instead of\n// one symmetric |x| band. The TIME response still shares one spring -- leg 2 splits L/R\n// springs so the sides can diverge under asymmetric impulse. Fallback: an asset with no\n// DYNA keeps the height band (uninitialized uniforms are zero by spec, so uDNL.w==0).\nfloat wB;\nif(uDNL.w>0.5){\nfloat wL=1.-smoothstep(0.,uDNL.w*1.4,length(aP-uDNL.xyz));\nfloat wR=1.-smoothstep(0.,uDNR.w*1.4,length(aP-uDNR.xyz));\nwB=max(wL,wR)*(1.-smoothstep(-1000.,-14000.,aP.y));\n}else{\nwB=(1.-smoothstep(0.,.085,abs(hb2-uNIP)))*(1.-smoothstep(6000.,26000.,abs(aP.x)))*(1.-smoothstep(-1000.,-14000.,aP.y));\n}\nsbo=uSB[ii*3+1]*wB;}\nwp+=sbo;\n// outfit dimension: a girl whose outfit excludes the dress gets its instance DEGENERATED\n// (moved far below the world) -- per-instance suppression inside one instanced draw\nif(uGar==1&&uOF[ii]>.5)wp=vec3(0.,-999.,0.);\nvW=wp;\nvec3 rel=wp-uCamM;\nvec3 fw=vec3(uYPM.x*uYPM.w,uYPM.z,uYPM.y*uYPM.w);\nvec3 rt=vec3(uYPM.y,0.,-uYPM.x);\nvec3 up=vec3(-uYPM.x*uYPM.z,uYPM.w,-uYPM.y*uYPM.z);\nfloat zv=max(dot(rel,fw),.081);\ngl_Position=vec4(dot(rel,rt),dot(rel,up)*(uResM.x/uResM.y),zv*(300.08/299.92)-(48./299.92),zv);}`;\n" as *u8)
192 p = gpe_ap(out, p, "const MFS=`#version 300 es\nprecision highp float;precision highp int;\nin vec3 vB;in vec3 vW;in vec3 vN;flat in int vII;flat in float vSh;\nuniform vec3 uCamM;uniform vec3 uSkTM;uniform highp usampler3D uVm;uniform int uOcc;\nuniform vec3 uCS[12];uniform vec3 uCO[12];uniform vec3 uCH[12];uniform int uGar;\nuniform float uGN[12];uniform float uOF[12];\nuniform float uMoodF[12];\nuniform float uTm;\nuniform vec4 uIH[12];\nuniform int uEyeG;\nuniform int uAnatM;\nuniform float uZMN;uniform float uH;uniform float uNIP;uniform float uEYE;\nout vec4 fc;\nuint vxm(ivec3 c){if(c.x<0||c.y<0||c.z<0||c.x>127||c.y>47||c.z>127)return 0u;return texelFetch(uVm,ivec3(c.x,c.z,c.y),0).r;}\nvoid main(){\n// WORLD OCCLUSION without gl_FragDepth (SwiftShader ignores it -- measured): march the SAME\n// voxel texture from the camera toward this fragment; solid before arrival = discard. The .35\n// standoff keeps the block she STANDS ON from eating her feet at grazing angles.\n// uOcc=0 (?npcocc=0) disables the march -- the standing diagnostic lever for this class.\nvec3 dW=vW-uCamM;float dst=length(dW);\nint hdbg=0;float tdbg=0.;\n// a fragment INSIDE a solid block is never visible -- mobs wander into wall faces and the\n// march standoff would otherwise let the last .35 blocks poke through voxel seams (the\n// scattered-limbs / zigzag class the operator reported)\nif(uOcc>=1){uint bf=vxm(ivec3(floor(vW)));if(bf!=0u&&bf!=4u)discard;}\nif(uOcc>=1&&dst>1.){vec3 rdm=dW/dst;float lim=dst-.35;\nivec3 c=ivec3(floor(uCamM));ivec3 st=ivec3(sign(rdm));vec3 dd=abs(1./max(abs(rdm),vec3(1e-6)));\nvec3 tmm=(vec3(st)*(vec3(c)-uCamM)+vec3(st)*.5+.5)*dd;float t2=0.;\nfor(int i=0;i<120;i++){\nif(tmm.x<tmm.y&&tmm.x<tmm.z){c.x+=st.x;t2=tmm.x;tmm.x+=dd.x;}\nelse if(tmm.y<tmm.z){c.y+=st.y;t2=tmm.y;tmm.y+=dd.y;}\nelse{c.z+=st.z;t2=tmm.z;tmm.z+=dd.z;}\nif(t2>=lim)break;\nuint b=vxm(c);if(b!=0u&&b!=4u){if(uOcc==1){discard;}hdbg=1;tdbg=t2/dst;break;}}}\n// uOcc=2 (?npcocc=2): visualize the march verdict instead of applying it -- red = would-discard\n// (green channel = hit fraction along the ray), green = clear. The debug lever that found v1.\nif(uOcc==2){fc=vec4(hdbg==1?1.:0.,hdbg==1?tdbg:1.,0.,1.);return;}\nvec3 vd=normalize(vW-uCamM);\n// smooth skinned normals (the mesh's normals are majority-INWARD -- measured in the drape\n// lane -- so keep the view-side flip; it is per-pixel correct either way)\nvec3 n=normalize(vN);\nif(dot(n,vd)>0.)n=-n;\nfloat h=(vB.z-uZMN)/uH;\n// bind-space banding carries the GENOME identity forward from the retired SDF girls:\n// per-instance skin tone, kind+brightness outfit, warden look, hair color as a scalp cap\n// (no hair geometry in the export yet -- seq1236; the groom rung replaces the cap).\nvec3 mc=uCS[vII];\n// clothing bands are TORSO-GATED (|bind x| under the torso half-width): in the bind pose the\n// hands/forearms hang at the same HEIGHT as the skirt/top, and height-only bands painted them\n// dress-red like opera gloves (operator-caught at close range)\nfloat axb=abs(vB.x);\n// the outfit dimension gates the painted garment bands: 0 full, 1 keeps only the bottom,\n// 2 none -- skin continues through (all figures are the one adult mesh)\n// the garment TOP EDGE derives from the measured bust line, never a literal: the band was\n// authored as .615-.735 when the nipple was assumed at .636 -- then the anatomy correction\n// moved NIP to .744 (origin-corrected, mesh-derived) and the neckline was left behind, so the\n// dress topped out BELOW the breasts (screenshot-caught). Cover to uNIP+.055, the same\n// half-width the nipple detail itself uses; one anatomy source, every band follows it.\n// CORRECTED 2026-08-03 (the see-it loop caught my own regression): the GVRT mesh is a SKIRT,\n// not a full dress -- the painted band was the ONLY top a clothed girl had, and the previous\n// one-representation edit UNDRESSED the clothed cast. The painted top returns (neckline still\n// derived from uNIP); the real fix for the seam read is a mesh TOP garment (E4 ladder), not\n// deleting the only top in the wardrobe. Build intelligence, never strip features.\nif(uOF[vII]<.5&&h>.615&&h<uNIP+.055&&axb<15000.)mc=uCO[vII];\nif(uOF[vII]<1.5&&h>.395&&h<.545&&axb<15000.)mc=uCO[vII]*.8;\n// bare chest detail at anatomy-ratio positions (front, ~5.6%H off midline, genome-scaled)\n// landmark from the MESH's own anchors (uNIP), never a guessed fraction: the old .636 sat at\n// the upper abdomen -- the operator saw the marks land near the legs. Half-separation stays a\n// RATIO of stature (published anthropometry), so it scales with whatever body wears it.\nif(uOF[vII]>.5&&vB.y<-1200.&&abs(h-uNIP)<.055){\nfloat nx9=abs(vB.x)-uH*.056;\nfloat nz9=(h-uNIP)*uH;\nfloat nd9=sqrt(nx9*nx9+nz9*nz9*1.3);\nfloat nr9=uH*.0125*(.85+.12*uGN[vII]);\nif(nd9<nr9)mc=mc*.72+vec3(.17,.06,.06);\nif(nd9<nr9*.38)mc=mc*.60+vec3(.22,.08,.08);\n}\n" as *u8)
193 p = gpe_ap(out, p, "if(h<.028)mc=vec3(.2,.12,.1);\n// hair = crown + BACK of skull only; front measured NEGATIVE y (the bust told us), so +y = back\nif(h>.955)mc=uCH[vII];\nif(h>.865&&vB.y>3000.)mc=uCH[vII];\n// FACE -- GENERATED, never hand-built: landmarks are anatomy-canon RATIOS (eyes at mid-head,\n// half-IPD ~.16 of head height, mouth 1/5 above chin, brows +8%) over the head segment the\n// mesh itself declares (chin .885H, crown 1.0H), scaled per girl by her genome feature bits;\n// iris tint = her hair gene. The skull/facemark NXA geometry bake is the named next rung --\n// this block is that lane's DATA CONTRACT, not a hand-drawn face.\nif(uGar==0&&h>.885&&h<.985&&vB.y<-1200.){\nfloat HH9=.115*171530.;\nfloat fs9=.82+.12*uGN[vII];\n// PASS-1 cut 3 (frozen instrument, n=6 ref): forehead/bridge/nose/brow/lip ALL sit ~5mm 'low'\n// by a near-constant while the chin is right -- ONE ROOT CAUSE WEARING FIVE MASKS: the EYE\n// LINE itself was painted ~5mm too high (all measures are eye-relative). Lower the eye line\n// .9448 -> .9420 H; every eye-relative error collapses together.\nfloat ex9=abs(vB.x)-.16*HH9;\nfloat ez9=(h-.9420)*171530.;\n// eye ellipse DE-RACCOONED (operator: wild eyeshadow): the old sclera was oversized with a\n// 2.1x vertical stretch -- a tall white/dark patch that read as makeup around the eye, not an\n// eye. Smaller sclera, flatter almond (1.4x), lids blend to skin instead of a hard rim, and\n// the iris/pupil ratios follow real ocular proportion (iris ~55% of visible aperture).\nfloat ed9=sqrt(ex9*ex9+ez9*ez9*1.4);\nfloat er9=.060*HH9*fs9;\nif(ed9<er9*1.25)mc=mix(mc,mc*.88,smoothstep(er9*1.25,er9,ed9)*.5);\n// LIVING EYES (operator: realistic eyes matching the reference). Perceptual hierarchy from\n// the realism research: the CATCHLIGHT carries aliveness, then the limbal ring, radial iris\n// depth, lid shadow, and blink. All paint-level here; corneal-bulge geometry is the skull-\n// lane rung. Skin tone captured BEFORE the eye overrides so the lid can close with skin.\nvec3 skin9=mc;\n// when real eyeballs exist, the face OPENS A HOLE for them (a genuine socket aperture) --\n// otherwise the painted eye runs exactly as before. One flag, both worlds correct.\nif(uEyeG==1&&ed9<er9*.98)discard;\nif(ed9<er9&&uEyeG==0){\nmc=vec3(.93,.92,.91);\nmc*=1.-.20*smoothstep(er9*.45,er9,abs(ez9));\n// GAZE-FOLLOW: the irises track the viewer (eye contact = the second-strongest aliveness cue\n// after the catchlight). Project the view direction onto the instance's right/up axes and\n// shift the iris center within the sclera aperture, clamped so the iris never leaves the eye.\n// MEASUREMENT MODE (uAnatM=1, the ?anat=1 lever): the geometry ruler must freeze every degree\n// of freedom it is not measuring -- gaze centered, blink off, mood zeroed CPU-side, same girl\n// framed. A ruler read through live mood/gaze/blink is measuring the weather.\nvec3 gvd9=normalize(uCamM-vW);\nfloat ggx9=(uAnatM==1)?0.:clamp(dot(gvd9,vec3(uIH[vII].y,0.,-uIH[vII].x))*.55,-.30,.30)*er9;\nfloat ggz9=(uAnatM==1)?0.:clamp(gvd9.y*.4,-.22,.22)*er9;\nfloat u9g=vB.x-((vB.x>0.)?1.:-1.)*.16*HH9;\nfloat ir9=er9*.55;\nfloat edg9=sqrt((u9g-ggx9)*(u9g-ggx9)+(ez9-ggz9)*(ez9-ggz9)*1.4);\nif(edg9<ir9){\nfloat t9=edg9/ir9;\nvec3 ib9=uCH[vII]*.5;\nmc=ib9*(1.15-.55*t9);\nmc+=vec3(.10,.07,.03)*max(0.,.5-abs(t9-.6))*1.6;\nif(t9>.82)mc*=.42;\nif(edg9<ir9*.42)mc=vec3(.03,.03,.05);\n}\n// wet catchlight, same world-side on both eyes: signed horizontal within THIS eye\nfloat u9=vB.x-((vB.x>0.)?1.:-1.)*.16*HH9;\nfloat cd9=length(vec2(u9-.25*er9,(ez9-.30*er9)*1.25));\nif(cd9<.17*er9)mc=vec3(1.25,1.24,1.22);\nif(cd9>=.17*er9&&cd9<.24*er9)mc=mix(mc,vec3(1.1),.5);\n// blink: ~130ms every ~4s, phase per girl -- the upper lid sweeps skin over the eye\nfloat bl9=fract(uTm*.24+float(vII)*.37);\nfloat lf9=(uAnatM==1)?0.:smoothstep(.950,.962,bl9)*(1.-smoothstep(.982,.994,bl9));\nif(lf9>0.&&ez9>(1.-2.2*lf9)*er9)mc=skin9*.92;\n}\n// UPPER LASH LINE: a dark arc hugging the top rim of the aperture -- lashes frame the eye and\n// are a major part of why real feminine eyes read as real (reference-confirmed). Thin band\n// just OUTSIDE the sclera on the upper edge, darkest at center, fading to the outer canthus.\nfloat lash9=smoothstep(er9*1.28,er9*1.02,ed9)*smoothstep(er9*.55,er9*1.0,ez9);\nif(lash9>.15)mc=mix(mc,vec3(.05,.03,.04),clamp(lash9,0.,.9));\n// WET CORNEAL SHEEN: the cornea is glossy -- beyond the sharp catchlight it lifts a broad soft\n// highlight from skylight, the 'wet look'. A second dimmer bloom offset from the catchlight.\nif(ed9<er9*.9){float sh9=1.-smoothstep(0.,er9*.9,length(vec2((vB.x-((vB.x>0.)?1.:-1.)*.16*HH9)+.10*er9,(ez9+.18*er9)*1.1)));\nmc=mix(mc,mc+vec3(.30,.32,.34),sh9*.35);}\n// brows ride mood too: up a touch when bright, pressed lower when dark -- the second channel\n// that makes an expression read as a FACE rather than a mouth sticker\nfloat bz9=(h-.954)*171530.;\nif(abs(bz9-uMoodF[vII]*.012*HH9)<.018*HH9&&abs(ex9)<.10*HH9)mc=uCH[vII]*.42;\n// I3 LEG 1 -- THE EXPRESSION CONSUMER (the largest unwired capability: mobmood computed an\n// inner life the face never showed). The mouth line CURVES with her mood: a parabola in x\n// lifts the corners when uMoodF is positive (smile) and drops them when negative -- one\n// signed door, real expression, zero new geometry. The MORF section replaces this with true\n// blend shapes later; this is the consumer that makes that section worth baking.\nfloat mz9=(h-.908)*171530.;\nfloat mx9=vB.x/(.085*HH9*fs9);\nfloat mcv9=uMoodF[vII]*.022*HH9*(mx9*mx9-.35);\nif(abs(mz9-mcv9)<.017*HH9*fs9&&abs(vB.x)<.065*HH9*fs9)mc=vec3(.82,.48,.48);\n}\nif(uGar==1)mc=uCO[vII];\n// HAIR: root-to-tip gradient + base-light compensation. Strand lines carry degenerate normals\n// (aN=0), so the diffuse term contributes ~nothing and locks rendered at .36x base -- flat and\n// dark, the operator's \"hair is awful\" in one number. Compensate the lighting floor and darken\n// toward the crown (roots) so locks read as volume instead of wire: tips ~1.65x, roots ~1.05x.\nif(uGar==2){float hg9=clamp((h-.72)/.26,0.,1.);mc=uCH[vII]*vSh*(1.65-.6*hg9);}\n// SKIN, NOT PLASTIC (the reference's biggest full-frame separator). Three cheap-SSS moves the\n// realism literature blesses on a no-compute budget: (1) WRAP DIFFUSE -- light reaches past\n// the geometric terminator the way scattering flesh does; (2) the RED-SHIFTED TERMINATOR --\n// at the light/dark boundary the shadow goes warm blood-red, not gray: the single strongest\n// this-is-skin cue; (3) CAPILLARY ZONATION on the anatomy bands -- cheeks, nose tip, ears,\n// knees, elbows flush warmer; a faint sun-tone gradient down the body (the beach class).\nvec3 L=normalize(vec3(2400.,2500.,1400.));\nfloat ndl=dot(n,L);\nfloat wr=.42;\nfloat dif=clamp((ndl+wr)/(1.+wr),0.,1.);\nfloat term=1.-smoothstep(.0,.45,abs(ndl+.05));\nif(uGar==0){\nmc=mix(mc,mc*vec3(1.12,.94,.90),term*.55);\nfloat fl9=0.;\nfloat chz9=(h-.925)*uH/(.115*uH);\nfl9+=max(0.,1.-length(vec2((abs(vB.x)-.11*.115*uH)/(.06*.115*uH),chz9/(.5))))*.5;\nfl9+=(1.-smoothstep(0.,.02,abs(h-.918)))*(1.-smoothstep(0.,.03*.115*uH,abs(vB.x)))*.6;\nfl9+=(1.-smoothstep(0.,.025,abs(h-.520)))*.30;\nfl9+=(1.-smoothstep(0.,.025,abs(h-.335)))*.25;\nmc=mix(mc,mc*vec3(1.10,.90,.88),clamp(fl9,0.,.5));\nmc*=mix(vec3(1.),vec3(1.03,.995,.96),clamp((h-.35)/.55,0.,1.)*.7);\n// CHEEK CONVEXITY LIGHT (sbs v1: our cheeks read CONCAVE/gaunt where the reference is full):\n// a soft radial lift on the cheek mass fakes the convex form until the skull rung lands.\nfloat ck9=(h-.912)*uH/(.115*uH);\nfloat ckm9=max(0.,1.-length(vec2((abs(vB.x)-.13*.115*uH)/(.10*.115*uH),ck9/.65)));\nmc*=1.+.12*ckm9;\n}\nvec3 H=normalize(L-vd);float spe=pow(max(dot(n,H),0.),26.);\nfloat rim=pow(1.-max(dot(n,-vd),0.),2.5);\nvec3 col=mc*(.34+.72*dif)+vec3(1.,.97,.9)*spe*.22+uSkTM*rim*.3;\nif(uGar==0)col+=mc*vec3(.30,.10,.06)*term*.5;\n// (grazing-angle darkening REMOVED 2026-08-02: the dot(n,-vd)<.24 col*=.4 term painted a dark ring\n// around every silhouette -- with the view-side normal flip the grazing band ALWAYS hugs the\n// outline, so a term meant to fake depth read as a black outline around the women. The rim\n// light above already models the edge; subtraction there was fighting addition here.)\nfloat fog=clamp(length(vW-uCamM)/46.,0.,.9);\nfc=vec4(mix(col,uSkTM,fog),1.);}`;\n" as *u8)
194 p = gpe_ap(out, p, "let VOX=0,SPC=0;\nif(ex.vox_off&&ex.yaw&&location.search.indexOf(\"gl=0\")<0){try{\nconst g=cv.getContext(\"webgl2\",{antialias:false,preserveDrawingBuffer:true});\nif(g){const cs=(t,s)=>{const o=g.createShader(t);g.shaderSource(o,s);g.compileShader(o);if(!g.getShaderParameter(o,g.COMPILE_STATUS))throw g.getShaderInfoLog(o);return o;};\nconst pr=g.createProgram();g.attachShader(pr,cs(g.VERTEX_SHADER,VSH));g.attachShader(pr,cs(g.FRAGMENT_SHADER,FSH));g.linkProgram(pr);\nif(!g.getProgramParameter(pr,g.LINK_STATUS))throw g.getProgramInfoLog(pr);\ng.useProgram(pr);\nconst L=n=>g.getUniformLocation(pr,n);\nconst tex=g.createTexture();g.activeTexture(g.TEXTURE0);g.bindTexture(g.TEXTURE_3D,tex);\ng.texStorage3D(g.TEXTURE_3D,1,g.R8UI,128,128,48);\ng.texParameteri(g.TEXTURE_3D,g.TEXTURE_MIN_FILTER,g.NEAREST);g.texParameteri(g.TEXTURE_3D,g.TEXTURE_MAG_FILTER,g.NEAREST);\ng.uniform1i(L(\"uV\"),0);\nVOX=Number(ex.vox_off());SPC=Number(ex.spec_off());\nGL={g,pr,L,lastEd:-1};\n}}catch(e){window.__sov_glfail=String(e);console.log(\"nishi: GL unavailable, CPU render\",e);GL=null;}}\n" as *u8)
195 p = gpe_ap(out, p, "function glDraw(){const g=GL.g,L=GL.L;\n// the mesh pass leaves program/VAO/texture-unit state behind -- reset OURS every frame\ng.useProgram(GL.pr);g.bindVertexArray(null);g.activeTexture(g.TEXTURE0);\nconst dpr=devicePixelRatio||1;const q=Number(ex.quality?ex.quality():2);\nlet scl=[1,1,.72,.5,.36,.25][q];\n// record mode shrinks the canvas (measurement outranks pixels) -- though the REAL headless\n// cost is the NPC mesh pass, so 600-tick measurement runs should use ?gl=0&review=1&record=1:\n// the recorder reads DOORS, not pixels, and the CPU path ticks fast\nif(REC)scl=.25;\n// MAXIMUM RESOURCES THAT ARE LOGICAL PER DEVICE CLASS (operator 2026-08-02): render at full\n// devicePixelRatio sharpness UP TO a per-class pixel budget, and let the adaptive quality\n// controller own the dynamic response below it. Without the budget a dpr-3 phone allocates a\n// 4M+px backing store (thermal + memory pressure the frame-time controller cannot see in its\n// first seconds), and desktop had no defined ceiling at all. Budgets: mobile 2.3Mpx (1080p\n// class), desktop 8.3Mpx (4K). The clamp preserves aspect: scale both axes by sqrt(over).\nconst _mob9=(\"ontouchstart\" in window)||navigator.maxTouchPoints>0;\nconst _PXB=_mob9?2300000:8300000;\nlet wpx=Math.max(64,Math.floor(cv.clientWidth*dpr*scl)),hpx=Math.max(64,Math.floor(cv.clientHeight*dpr*scl));\nif(wpx*hpx>_PXB){const _f9=Math.sqrt(_PXB/(wpx*hpx));wpx=Math.max(64,Math.floor(wpx*_f9));hpx=Math.max(64,Math.floor(hpx*_f9));}\nwindow.__px=wpx+\"x\"+hpx+(_mob9?\"m\":\"d\");\nif(cv.width!==wpx||cv.height!==hpx){cv.width=wpx;cv.height=hpx;g.viewport(0,0,wpx,hpx);}\n// crops grow and soil wets WITHOUT player edits -- refresh the voxel texture on the edit\n// counter OR every 64 organ ticks, whichever fires first (growth stays visible)\nconst ed=Number(ex.broken())+Number(ex.placed());const tn9=Number(ex.tnow());\nif(ed!==GL.lastEd||(tn9&63)===0){GL.lastEd=ed;\ng.texSubImage3D(g.TEXTURE_3D,0,0,0,0,128,128,48,g.RED_INTEGER,g.UNSIGNED_BYTE,new Uint8Array(ex.memory.buffer,VOX,128*48*128));}\nconst dv=new DataView(ex.memory.buffer);\n// A1 made visible: the organ's sun elevation drives palette light, sky colour, sun disc + rain\nconst sel=ex.sunel?Number(ex.sunel())/4096:1;const df=Math.max(0,sel);\nconst dl2=.22+.78*Math.pow(df,.6);\nconst pal=new Float32Array(36);\nfor(let i=0;i<12;i++){const v=Number(dv.getBigInt64(SPC+(16+i)*8,true));pal[i*3]=(v&255)/255*dl2;pal[i*3+1]=((v>>8)&255)/255*dl2;pal[i*3+2]=((v>>16)&255)/255*dl2;}\ng.uniform3fv(L(\"uPal\"),pal);\nconst palf=new Float32Array(15);\nfor(let i=0;i<5;i++){const v=Number(dv.getBigInt64(SPC+(34+i)*8,true));palf[i*3]=(v&255)/255*dl2;palf[i*3+1]=((v>>8)&255)/255*dl2;palf[i*3+2]=((v>>16)&255)/255*dl2;}\ng.uniform3fv(L(\"uPalF\"),palf);\nconst skt=Number(dv.getBigInt64(SPC+7*8,true)),skh=Number(dv.getBigInt64(SPC+8*8,true));\nconst nn=1-dl2;\ng.uniform3f(L(\"uSkT\"),(skt&255)/255*dl2+.02*nn,((skt>>8)&255)/255*dl2+.03*nn,((skt>>16)&255)/255*dl2+.10*nn);\ng.uniform3f(L(\"uSkH\"),(skh&255)/255*dl2+.04*nn,((skh>>8)&255)/255*dl2+.05*nn,((skh>>16)&255)/255*dl2+.12*nn);\nconst dfr=(ex.dayt&&ex.dlen)?Number(ex.dayt())/Math.max(1,Number(ex.dlen())):.3;\nconst az=Math.PI*(1.-dfr*1.6);const el=Math.asin(Math.max(-.99,Math.min(.99,sel)));\nlet sdx=Math.cos(el)*Math.cos(az),sdy=Math.sin(el),sdz=Math.cos(el)*.45;\nconst sdl=Math.hypot(sdx,sdy,sdz)||1;\ng.uniform3f(L(\"uSunD\"),sdx/sdl,sdy/sdl,sdz/sdl);\ng.uniform1i(L(\"uSun\"),(Number(dv.getBigInt64(SPC+9*8,true))===1&&df>.04)?1:0);\ng.uniform1i(L(\"uRain\"),ex.rainf?Number(ex.rainf()):0);\ng.uniform1i(L(\"uCld\"),Number(dv.getBigInt64(SPC+10*8,true)));\n" as *u8)
196 p = gpe_ap(out, p, "g.uniform3f(L(\"uCam\"),Number(ex.camx())/256,Number(ex.camy())/256,Number(ex.camz())/256);\nconst ya=Number(ex.yaw())/4096,pi2=Number(ex.pitch())/4096;\ng.uniform4f(L(\"uYP\"),Math.sin(ya),Math.cos(ya),Math.sin(pi2),Math.cos(pi2));\ng.uniform1f(L(\"uT\"),Number(ex.tnow()));\ng.uniform1i(L(\"uWmax\"),Number(ex.wmax()));\ng.uniform1i(L(\"uSelB\"),Number(ex.tsel()));\ng.uniform1i(L(\"uHok\"),Number(ex.hok()));\ng.uniform2f(L(\"uRes\"),cv.width,cv.height);\nconst nm=Number(ex.mobs());\ng.uniform1i(L(\"uNpcT\"),ex.npc_t?Number(ex.npc_t()):-1);\ng.disable(g.DEPTH_TEST);\ng.drawArrays(g.TRIANGLES,0,3);\nif(GL.npc&&GL.npc.ok&&nm>0){drawNPCs(g,nm);drawEyes(g);}\nwindow.__sov_glerr=g.getError();}\n" as *u8)
197 p = gpe_ap(out, p, "// evaluate one track at tm into the SHARED scratch N.ev (q x4, dt x3) -- no per-call\n// allocations (12 NPCs x 104 joints x 60fps would be real GC churn on mobile).\nfunction evalTrack(N,tr,cur,j,tm){\nlet c=cur[j];const t=tr.t,n=tr.n;\nif(c>=n||tm<t[c])c=0;\nwhile(c+1<n&&t[c+1]<=tm)c++;\ncur[j]=c;\nconst k1=c+1<n?c+1:c;\nconst t0=t[c],t1=t[k1];\nlet u=t1>t0?(tm-t0)/(t1-t0):0;if(u<0)u=0;if(u>1)u=1;\nconst q=tr.q,d=tr.d;\nlet ax=q[c*4],ay=q[c*4+1],az=q[c*4+2],aw2=q[c*4+3];\nlet bx=q[k1*4],by=q[k1*4+1],bz=q[k1*4+2],bw=q[k1*4+3];\nif(ax*bx+ay*by+az*bz+aw2*bw<0){bx=-bx;by=-by;bz=-bz;bw=-bw;}\nlet qx=ax+(bx-ax)*u,qy=ay+(by-ay)*u,qz=az+(bz-az)*u,qw=aw2+(bw-aw2)*u;\nconst il=1/Math.hypot(qx,qy,qz,qw);\nconst ev=N.ev;\nev[0]=qx*il;ev[1]=qy*il;ev[2]=qz*il;ev[3]=qw*il;\nev[4]=d[c*3]+(d[k1*3]-d[c*3])*u;\nev[5]=d[c*3+1]+(d[k1*3+1]-d[c*3+1])*u;\nev[6]=d[c*3+2]+(d[k1*3+2]-d[c*3+2])*u;}\n// evaluate the whole clip for visible-slot v at time tm: per-joint nlerp into jf rows\n// (2v)=dq (2v+1)=dt, ROOT horizontal drift subtracted so the figure stays on her mob anchor\n// (root motion removed; the ORGAN owns where she is, the clip only shapes her).\nfunction animEval(N,st,tm,v){const jf=N.jf,nj=N.nj;\nconst o0=(2*v)*nj*4,o1=(2*v+1)*nj*4;\nlet rdx=0,rdy=0;\n// subtract only the fitted LINEAR drift (see rv at load): the residual sway stays\nif(N.rv){rdx=N.rv.x0+N.rv.vx*(tm-N.rv.t0);rdy=N.rv.y0+N.rv.vy*(tm-N.rv.t0);}\nfor(let j=0;j<nj;j++){const tr=N.tr[j];\nif(!tr){jf[o0+j*4]=0;jf[o0+j*4+1]=0;jf[o0+j*4+2]=0;jf[o0+j*4+3]=1;jf[o1+j*4]=0;jf[o1+j*4+1]=0;jf[o1+j*4+2]=0;continue;}\nevalTrack(N,tr,st.cur,j,tm);\nconst ev=N.ev;\nlet rx=ev[0],ry=ev[1],rz=ev[2],rw=ev[3];\nlet ex4=ev[4]-rdx,ey4=ev[5]-rdy,ez4=ev[6];\n// IDLE POSE HOLD (seq1258): nlerp toward the file's frozen stand pose as the mob rests --\n// summoned girls settle into a stand instead of a mid-swing statue; POSE rows arrive\n// root-removed from nx_nxa_pose so they compose with the clip's own root removal\nconst w9=st.iw;\nif(w9>0&&N.pq){const px9=N.pq[j*4],py9=N.pq[j*4+1],pz9=N.pq[j*4+2],pw9=N.pq[j*4+3];\nconst s0=rx*px9+ry*py9+rz*pz9+rw*pw9<0?-1:1;\nrx+=(s0*px9-rx)*w9;ry+=(s0*py9-ry)*w9;rz+=(s0*pz9-rz)*w9;rw+=(s0*pw9-rw)*w9;\nconst il9=1/(Math.hypot(rx,ry,rz,rw)||1);rx*=il9;ry*=il9;rz*=il9;rw*=il9;\nex4+=(N.pd[j*3]-ex4)*w9;ey4+=(N.pd[j*3+1]-ey4)*w9;ez4+=(N.pd[j*3+2]-ez4)*w9;}\n// full affine translation T = b + dt - D*b, then DUAL QUAT rows [real|dual=.5*T x real]\n// (the rigmesh viewer's proven transform: LBS collapses under the T-pose->arms-down delta)\nconst bx=N.bind[j*4],by=N.bind[j*4+1],bz=N.bind[j*4+2];\nconst cxq=ry*bz-rz*by+rw*bx,cyq=rz*bx-rx*bz+rw*by,czq=rx*by-ry*bx+rw*bz;\nconst dbx=bx+2*(ry*czq-rz*cyq),dby=by+2*(rz*cxq-rx*czq),dbz=bz+2*(rx*cyq-ry*cxq);\nconst Tx=bx+ex4-dbx,Ty=by+ey4-dby,Tz=bz+ez4-dbz;\njf[o0+j*4]=rx;jf[o0+j*4+1]=ry;jf[o0+j*4+2]=rz;jf[o0+j*4+3]=rw;\njf[o1+j*4] =.5*( Tx*rw+Ty*rz-Tz*ry);\njf[o1+j*4+1]=.5*(-Tx*rz+Ty*rw+Tz*rx);\njf[o1+j*4+2]=.5*( Tx*ry-Ty*rx+Tz*rw);\njf[o1+j*4+3]=.5*(-Tx*rx-Ty*ry-Tz*rz);}\n// ANKLE DORSIFLEXION (operator: she walks on tippy-toes -- a constant plantarflexion rides the\n// retargeted clip). Feet are CHAIN ENDS here (no runtime hierarchy, and the toes copy the foot\n// row below), so composing a fixed counter-rotation onto the foot rows is safe: rotate about\n// the model lateral axis at the ankle bind pivot -- world = D(x-b)+b+dt keeps b fixed under\n// left-composition, so the ankle stays put and the sole drops. Foot joints = the toe-collapse\n// ANCHORS collected at load (N.fj); angle via ?ankle=<centirad> for screenshot calibration.\nif(N.fj){const a9=(window.__ankle!==undefined?window.__ankle:0.30);\nconst s9=Math.sin(a9/2),c9=Math.cos(a9/2);\nfor(const j of N.fj){\nconst rx0=jf[o0+j*4],ry0=jf[o0+j*4+1],rz0=jf[o0+j*4+2],rw0=jf[o0+j*4+3];\n// q_dx (x-axis) times r, then rebuild the dual from the SAME world translation T\nconst rx=s9*rw0+c9*rx0,ry=c9*ry0-s9*rz0,rz=s9*ry0+c9*rz0,rw=c9*rw0-s9*rx0;\nconst dx0=jf[o1+j*4],dy0=jf[o1+j*4+1],dz0=jf[o1+j*4+2],dw0=jf[o1+j*4+3];\n// T = 2 * dual times conj(real) (vector part)\nconst Tx=2*( dx0*rw0-dw0*rx0-dy0*rz0+dz0*ry0);\nconst Ty=2*( dy0*rw0-dw0*ry0-dz0*rx0+dx0*rz0);\nconst Tz=2*( dz0*rw0-dw0*rz0-dx0*ry0+dy0*rx0);\n// re-anchor: T2 = b + (T - b_rotated_delta) -- keep ankle pivot: T2 = b + Told - D2 b, where\n// Told already equals b+dt-D b; rotating D about b needs Db under the NEW rotation:\nconst bx=N.bind[j*4],by=N.bind[j*4+1],bz=N.bind[j*4+2];\nconst cX=ry*bz-rz*by+rw*bx,cY=rz*bx-rx*bz+rw*by,cZ=rx*by-ry*bx+rw*bz;\nconst Dbx=bx+2*(ry*cZ-rz*cY),Dby=by+2*(rz*cX-rx*cZ),Dbz=bz+2*(rx*cY-ry*cX);\nconst c0X=ry0*bz-rz0*by+rw0*bx,c0Y=rz0*bx-rx0*bz+rw0*by,c0Z=rx0*by-ry0*bx+rw0*bz;\nconst D0x=bx+2*(ry0*c0Z-rz0*c0Y),D0y=by+2*(rz0*c0X-rx0*c0Z),D0z=bz+2*(rx0*c0Y-ry0*c0X);\nconst T2x=Tx+D0x-Dbx,T2y=Ty+D0y-Dby,T2z=Tz+D0z-Dbz;\njf[o0+j*4]=rx;jf[o0+j*4+1]=ry;jf[o0+j*4+2]=rz;jf[o0+j*4+3]=rw;\njf[o1+j*4] =.5*( T2x*rw+T2y*rz-T2z*ry);\njf[o1+j*4+1]=.5*(-T2x*rz+T2y*rw+T2z*rx);\njf[o1+j*4+2]=.5*( T2x*ry-T2y*rx+T2z*rw);\njf[o1+j*4+3]=.5*(-T2x*rx-T2y*ry-T2z*rz);}}\n// rigid hands: finger rows copy their wrist-line anchor (see hcol at load; ?npchc=0 disables)\nif(location.search.indexOf(\"npchc=0\")<0)for(let hI=0;hI<N.hc.length;hI++){const j=N.hc[hI][0],a=N.hc[hI][1];\nfor(let c=0;c<4;c++)jf[o0+j*4+c]=jf[o0+a*4+c];\nfor(let c=0;c<4;c++)jf[o1+j*4+c]=jf[o1+a*4+c];}}\n" as *u8)
198 p = gpe_ap(out, p, "// ALL mobs render as skinned NXA instances (the SDF figures are RETIRED -- genome identity\n// rides the mesh: per-instance skin/outfit/hair/warden/height). Culling: >44 blocks or well\n// behind the camera. Clip time is DISTANCE-DRIVEN (ct += moved * ms-per-block) so nobody\n// walks in place or moonwalks; heading = smoothed motion direction (display derivative;\n// the ORGAN owns every position).\nconst H8=[[.94,.80,.52],[.65,.33,.18],[.42,.26,.16],[.16,.14,.18],[.86,.86,.90],[.90,.62,.54],[.82,.62,.36],[.78,.42,.22]];\n// E-2 EYEBALL GEOMETRY. Painted eyes top out at 'alive'; a real eye is a SPHERE, which is why\n// it catches light and why the iris shifts with parallax as the head turns -- a flat disc never\n// will at any resolution. This transforms the bind-space eye centre through the HEAD joint's own\n// dual quaternion (the same composition the vertex shader uses), so the eyeball rides her skull\n// exactly. Falls back to paint if anything failed at load (uEyeG stays 0).\nfunction eyeWorld(N,v,bp,ihx,ihy,scl,px,py,pz){\nconst nj=N.nj,jf=N.jf,hj=N.hj;\nconst o0=(2*v)*nj*4,o1=(2*v+1)*nj*4;\nconst rx=jf[o0+hj*4],ry=jf[o0+hj*4+1],rz=jf[o0+hj*4+2],rw=jf[o0+hj*4+3];\nconst dx=jf[o1+hj*4],dy=jf[o1+hj*4+1],dz=jf[o1+hj*4+2],dw=jf[o1+hj*4+3];\nconst bx=bp[0],by=bp[1],bz=bp[2];\nconst cx=ry*bz-rz*by+rw*bx,cy=rz*bx-rx*bz+rw*by,cz=rx*by-ry*bx+rw*bz;\nconst sx=bx+2*(ry*cz-rz*cy),sy=by+2*(rz*cx-rx*cz),sz=bz+2*(rx*cy-ry*cx);\nconst tx=2*(rw*dx-dw*rx+(ry*dz-rz*dy));\nconst ty=2*(rw*dy-dw*ry+(rz*dx-rx*dz));\nconst tz=2*(rw*dz-dw*rz+(rx*dy-ry*dx));\nconst mx=sx+tx,my=sy+ty,mz=sz+tz;\nconst yx=mx,yy=mz,yz=-my;\nconst S=1.78/171530*scl;\nreturn [px+(yx*ihy-yz*ihx)*S,py+yy*S,pz+(yx*ihx+yz*ihy)*S];\n}\nfunction drawEyes(g){const N=GL.npc;if(!N||!N.eye)return;const E=N.eye;\nconst k=window.__npcvis|0;if(!k)return;\nconst ya=Number(ex.yaw())/4096,pi4=Number(ex.pitch())/4096;\ng.useProgram(E.pr);g.bindVertexArray(E.vao);\ng.uniform3fv(E.l.uEC,E.ec);g.uniform4fv(E.l.uEG,E.eg);g.uniform3fv(E.l.uECol,E.ecol);\ng.uniform3f(E.l.uEcam,Number(ex.camx())/256,Number(ex.camy())/256,Number(ex.camz())/256);\ng.uniform4f(E.l.uEyp,Math.sin(ya),Math.cos(ya),Math.sin(pi4),Math.cos(pi4));\ng.uniform2f(E.l.uEres,cv.width,cv.height);\ng.enable(g.DEPTH_TEST);\ng.drawElementsInstanced(g.TRIANGLES,E.ni,g.UNSIGNED_SHORT,0,Math.min(24,k*2));\ng.bindVertexArray(null);}\nfunction drawNPCs(g,nm){const N=GL.npc;\nconst cam0=Number(ex.camx())/256,cam1=Number(ex.camy())/256,cam2=Number(ex.camz())/256;\nconst ya=Number(ex.yaw())/4096,pi3=Number(ex.pitch())/4096;\nconst fw0=Math.sin(ya)*Math.cos(pi3),fw1=Math.sin(pi3),fw2=Math.cos(ya)*Math.cos(pi3);\nconst nw2=performance.now();let dtf=(nw2-(N.pt||nw2))/1000;N.pt=nw2;\nif(dtf<0.001)dtf=0.001;if(dtf>0.1)dtf=0.1;\nlet nv=0;window.__npcidle=0;\nfor(let m=0;m<nm&&m<12;m++){\nconst px=Number(ex.mobx(BigInt(m)))/256,py=Number(ex.moby(BigInt(m)))/256,pz=Number(ex.mobz(BigInt(m)))/256;\nconst st=N.st[m];\n// ORGAN MOTION DOORS (seq1287 EATEN): heading, speed AND climb all read the organ's own\n// applied step (mobdx/mobdz/mobdy) -- the JS position-derivative and its absent-door\n// fallback are RETIRED (page+wasm are ONE emitted artifact, the doors are always present;\n// a fallback here is a workaround, and workarounds are bugs). Teleports never enter the\n// doors, so the dm<3 guard is gone too. Heading target still NEGATED (left-handed basis\n// vs atan2). Vertical step counts toward cadence: she strides while climbing.\nconst vx9=Number(ex.mobdx(BigInt(m)))/256,vz9=Number(ex.mobdz(BigInt(m)))/256,vy9=Number(ex.mobdy(BigInt(m)))/256;\nconst stp=Math.hypot(vx9,vz9)+Math.abs(vy9)*.7;\nconst raw=stp/dtf;st.spd+=(raw-st.spd)*.2;\n// heading gated on REAL speed: a single wander nudge used to swing st.A .18*angle -- a\n// visible twitch on a girl who is otherwise standing (part of the \"interrupted walk\" read)\nif((vx9!==0||vz9!==0)&&st.spd>0.1){let ta=-Math.atan2(vx9,vz9);let dd=ta-st.A;\nwhile(dd>Math.PI)dd-=2*Math.PI;while(dd<-Math.PI)dd+=2*Math.PI;st.A+=dd*.18;}\nif(st.spd>0.03)st.ct=(st.ct+st.spd*dtf*N.mpb)%N.dur;\n// IDLE HYSTERESIS (operator: \"the body still bounces as if the idle is an interrupted walk\").\n// The pose-hold blend was CORRECT and the single 0.03 threshold was the defect: girls micro-\n// step every few hundred ms (wander, curiosity), each nudge kicked spd over one shared\n// threshold and she churned walk<->pose forever, never settling. Easy in, hard out: enter\n// idle at <=0.03, LEAVE only above 0.15 (a real stride), and release over ~400ms not 200 --\n// a standing girl now absorbs nudges inside the held pose instead of flinching out of it.\n// S1 facing leg: a girl standing inside conversation distance turns to face the player --
199// the ring positions come from the ORGAN; orientation is display truth, so it lives here.
200const pdx9=cam0-px,pdz9=cam2-pz;const pdd9=Math.hypot(pdx9,pdz9);
201// M1: in PROFILE mode she turns 90 degrees off the camera axis so her SIDE is presented --\n// Monge's second projection, achieved by rotating the subject rather than the observer.\nconst _pf9=(typeof PROF9!==\"undefined\"&&PROF9);\n// PROFILE IS A MEASUREMENT, NOT A BEHAVIOUR: the facing branch is eased over ~300ms and gated\n// to conversation distance. Inheriting either wrecks the Monge pair -- the gate can leave her\n// frontal, and the ease fights the motion heading set above, so the yaw at shutter time is\n// whatever the race settled on. A geometry ruler FREEZES the DoF it measures: hard-set, ungated.\nif(_pf9){st.A=-Math.atan2(pdx9,pdz9)+Math.PI/2;}\nelse if(st.iw>.5&&pdd9<3.2){let fa9=-Math.atan2(pdx9,pdz9);let fd9=fa9-st.A;
202while(fd9>Math.PI)fd9-=2*Math.PI;while(fd9<-Math.PI)fd9+=2*Math.PI;st.A+=fd9*Math.min(1,dtf*3);}
203const thr9=st.iw>.5?0.15:0.03;const iwt=st.spd<=thr9?1:0;\n// STOP AT A FOOT-PLANT, NOT MID-SWING (operator: \"she stops as if she is still walking when\n// she is interrupted\"): while the idle pose blends IN, the clip keeps easing toward the\n// nearest double-support phase (0 and dur/2 in a single gait cycle) -- so the source of the\n// blend is a planted stance, not a frozen swing. A real person finishes the step; so does she.\nif(iwt&&st.iw<.95){const hd9=N.dur/2;let tg9=Math.round(st.ct/hd9)*hd9;\nlet dc9=tg9-st.ct;st.ct=(st.ct+dc9*Math.min(1,dtf*6)+N.dur)%N.dur;}\nst.iw+=(iwt-st.iw)*Math.min(1,dtf*(iwt?5:2.5));if(st.iw<0.004)st.iw=0;\nconst r0=px-cam0,r1=py+0.9-cam1,r2=pz-cam2;\nconst d=Math.hypot(r0,r1,r2);\nif(d>44)continue;\nif(r0*fw0+r1*fw1+r2*fw2<-2.)continue;\nanimEval(N,st,st.ct,nv);\nif(st.iw>.5)window.__npcidle=(window.__npcidle|0)+1;\nconst gv=Number(ex.mobg(BigInt(m))),ki=Number(ex.mobk(BigInt(m))),dgw=ex.mobd?Number(ex.mobd(BigInt(m))):0;\nconst wrd=(ki===2)&&((dgw&1)===0);\nconst sk=.92+((gv>>9)&3)*.04;\nconst ob=.76+.16*((gv>>7)&3);\n// side-by-side calibration (sbs_face v1): our base skin rendered GRAY-BROWN against the\n// reference's warm light tan -- the whole-face tone was the largest alien cue after shape.\n// Warmer, lighter base; the shader's flush/terminator warmth now acts on the right canvas.\nconst skin=wrd?[.66,.60,.66]:[.99*sk,.84*sk,.74*sk];\nconst outf=wrd?[.15,.10,.18]:(ki===0?[.58*ob,.16*ob,.22*ob]:ki===1?[.14*ob,.42*ob,.46*ob]:[.34*ob,.14*ob,.38*ob]);\nconst hair=wrd?[.13,.10,.18]:H8[gv&7];\n// NO instance-level bob: the mocap clip already animates the torso -- adding one made her\n// whole body pogo (operator-caught). The gait bob lives ONLY in the engine's spring anchor,\n// so the chest lags a stable torso: breast physics, not body bounce.\nN.ip[nv*3]=px;N.ip[nv*3+1]=py;N.ip[nv*3+2]=pz;\nN.ih[nv*4]=Math.sin(st.A);N.ih[nv*4+1]=Math.cos(st.A);N.ih[nv*4+2]=.94+((gv>>5)&3)*.03;N.ih[nv*4+3]=1+2*nv;\nfor(let c=0;c<3;c++){N.cs[nv*3+c]=skin[c];N.co[nv*3+c]=outf[c];N.ch[nv*3+c]=hair[c];}\n// A4: organ spring offsets (Q8 model units, model unit = worldQ8/4 => /16384 = blocks) at\n// PHYSICAL scale -- the solver's gate-proven K/C set the amplitude, not display fudge\nif(ex.sbx){const A9=[1.0,1.0,.8];for(let kd=0;kd<3;kd++){const a9=A9[kd];\nN.sb[nv*9+kd*3]=Number(ex.sbx(BigInt(m),BigInt(kd)))/16384*a9;\nN.sb[nv*9+kd*3+1]=Number((ex.sbyb?ex.sbyb:ex.sby)(BigInt(m),BigInt(kd)))/16384*a9;\nN.sb[nv*9+kd*3+2]=Number(ex.sbz(BigInt(m),BigInt(kd)))/16384*a9;}\n// chest spring onto its DESIGNATED JOINTS: world offset -> model frame (inverse heading,\n// inverse scale, yup remap), then dual += .5*(t (x) real) -- the exact composition\n// animEval itself uses, applied to this instance's jf rows before upload\n// (the chest spring is NOT injected into joints any more: the probe proved this rig carries no\n// breast bones -- its nearest candidates sit at 620-641 permil, the upper abdomen -- so driving\n// them swung the whole TORSO. Soft tissue with no bone of its own moves at the VERTEX band in\n// the vertex shader, centred on the derived bust height.)\n}\nN.gn[nv]=(gv>>11)&3;\nN.of[nv]=ex.mobout?Number(ex.mobout(BigInt(m))):0;\n// her mood, straight off the ledger door, scaled to [-1,1] for the expression bands\nN.mdf[nv]=(typeof ANAT9!==\"undefined\"&&ANAT9)?0:(ex.mobmood?Math.max(-1,Math.min(1,Number(ex.mobmood(BigInt(m)))/20)):0);\n// eyeball instances for this girl: two spheres seated on her skull, gazing at the viewer\nif(N.eye&&nv<12){const E=N.eye;const S9=1.78/171530*N.ih[nv*4+2];\nfor(let s=0;s<2;s++){const q=nv*2+s;\nconst c=eyeWorld(N,nv,E.bp[s],N.ih[nv*4],N.ih[nv*4+1],N.ih[nv*4+2],px,py,pz);\nE.ec[q*3]=c[0];E.ec[q*3+1]=c[1];E.ec[q*3+2]=c[2];\nlet gx=cam0-c[0],gy=cam1-c[1],gz2=cam2-c[2];\nconst gl9=Math.hypot(gx,gy,gz2)||1;gx/=gl9;gy/=gl9;gz2/=gl9;\nE.eg[q*4]=gx;E.eg[q*4+1]=gy;E.eg[q*4+2]=gz2;E.eg[q*4+3]=E.R*S9;\nE.ecol[q*3]=hair[0]*.55;E.ecol[q*3+1]=hair[1]*.55;E.ecol[q*3+2]=hair[2]*.55;}}\nnv++;}\nwindow.__npcvis=nv;\nif(nv===0)return;\ng.activeTexture(g.TEXTURE1);g.bindTexture(g.TEXTURE_2D,N.jt);\ng.texSubImage2D(g.TEXTURE_2D,0,0,1,N.nj,2*nv,g.RGBA,g.FLOAT,N.jf.subarray(0,N.nj*8*nv));\ng.useProgram(N.pr);g.bindVertexArray(N.vao);\nconst l=N.l;\ng.uniform1i(l.uJT,1);\ng.uniform1f(l.uSc,1.78/171530);\ng.uniform3fv(l.uIP,N.ip);g.uniform4fv(l.uIH,N.ih);\ng.uniform3fv(l.uCS,N.cs);g.uniform3fv(l.uCO,N.co);g.uniform3fv(l.uCH,N.ch);\nif(ex.sbx)g.uniform3fv(l.uSB,N.sb);\ng.uniform1fv(l.uGN,N.gn);\ng.uniform1fv(l.uOF,N.of);\ng.uniform1fv(l.uMoodF,N.mdf);\ng.uniform1i(l.uEyeG,N.eye?1:0);\ng.uniform1i(l.uAnatM,(typeof ANAT9!==\"undefined\"&&ANAT9)?1:0);\n// ANATOMY, DERIVED FROM THE ASSET: normalize in the mesh's own extents and map published\n// anthropometric ratios (hip .52, nipple .72, eye .93 of stature) through THIS mesh's pelvis\n// and head anchors. Guessed constants put the bust at .636 -- the upper abdomen.\ng.uniform1f(l.uZMN,N.an.zmn);g.uniform1f(l.uH,N.an.H);\ng.uniform1f(l.uNIP,N.an.nip);g.uniform1f(l.uEYE,N.an.eye);\n// weather-in-the-hair inputs: ORGAN tick + ORGAN weather (never wall-clock, never guessed)\ng.uniform1f(l.uTm,Number(ex.tnow())/60);\ng.uniform1f(l.uWnd,(ex.rainf&&Number(ex.rainf()))?0.10:0.03);\ng.uniform3f(l.uCamM,cam0,cam1,cam2);\n" as *u8)
204 p = gpe_ap(out, p, "g.uniform4f(l.uYPM,Math.sin(ya),Math.cos(ya),Math.sin(pi3),Math.cos(pi3));\ng.uniform2f(l.uResM,cv.width,cv.height);\nconst dv2=new DataView(ex.memory.buffer);\nconst skt=Number(dv2.getBigInt64(SPC+7*8,true));\ng.uniform3f(l.uSkTM,(skt&255)/255,((skt>>8)&255)/255,((skt>>16)&255)/255);\ng.uniform1i(l.uVm,0);\ng.uniform1i(l.uOcc,location.search.indexOf(\"npcocc=0\")>=0?0:(location.search.indexOf(\"npcocc=2\")>=0?2:1));\n// self-occlusion: fresh depth for the figures only (world occlusion = the FS voxel march)\ng.clear(g.DEPTH_BUFFER_BIT);g.enable(g.DEPTH_TEST);g.depthFunc(g.LESS);\ng.uniform1i(l.uGar,0);g.uniform1i(l.uHM,1);\ng.drawElementsInstanced(g.TRIANGLES,N.ni,g.UNSIGNED_SHORT,0,nv);\nif(N.gvao){g.uniform1i(l.uGar,1);g.bindVertexArray(N.gvao);\ng.drawElementsInstanced(g.TRIANGLES,N.gni,g.UNSIGNED_SHORT,0,nv);}\nif(N.hvao){g.uniform1i(l.uGar,2);g.bindVertexArray(N.hvao);\n// 8 jittered locks per guide per girl -- 4400 locks/head from 550 simulated-free guides\ng.uniform1i(l.uHM,8);\ng.drawArraysInstanced(g.LINES,0,N.hn,nv*8);}\ng.disable(g.DEPTH_TEST);\ng.bindVertexArray(null);g.useProgram(GL.pr);g.activeTexture(g.TEXTURE0);}\n" as *u8)
205 p = gpe_ap(out, p, "// fetch + verify + parse the NXA (refuse-corrupt law: every USED section's rolling checksum is\n// re-verified in two 32-bit lanes before a byte is trusted). Failure = silent SDF fallback.\nasync function loadNPC(){try{\n// the DYNA-bearing asset first, the pre-DYNA one as a fallback: a new asset that fails to serve\n// would otherwise drop every girl to the SDF blob path SILENTLY, which is a worse regression than\n// the missing physics it was meant to fix. Degrade to the old rig, never to no rig.\nlet rs=await fetch(\"/world/ref9d.nxa\");if(!rs.ok)rs=await fetch(\"/world/ref9.nxa\");if(!rs.ok)return;\nconst ab=await rs.arrayBuffer();const dv=new DataView(ab);const U8=new Uint8Array(ab);\nlet mg=\"\";for(let i=0;i<8;i++)mg+=String.fromCharCode(U8[i]);\nif(mg!==\"NXANIM01\")return;\nconst rdU=o=>dv.getUint32(o,true)+dv.getInt32(o+4,true)*4294967296;\nif(rdU(8)>1)return;\nconst ns=rdU(16);\nconst ckf=(off,nw)=>{let lo=1,hi=0;for(let i=0;i<nw;i++){\nconst l2=lo*1000003+dv.getUint32(off+i*8,true);\nconst h2=hi*1000003+dv.getUint32(off+i*8+4,true)+Math.floor(l2/4294967296);\nlo=l2>>>0;hi=h2>>>0;}return[lo,hi];};\nconst S={};\nfor(let s=0;s<ns;s++){const e=32+s*32;let tg=\"\";for(let i=0;i<4;i++)tg+=String.fromCharCode(U8[e+i]);\nconst off=rdU(e+8),wl=rdU(e+16);\nS[tg]={o:off,n:wl,e:e};}\nfor(const tg of[\"VERT\",\"TRIS\",\"SKEL\",\"SKIN\",\"ANIM\"]){if(!S[tg]){window.__npcfail=\"missing \"+tg;return;}\nconst c=ckf(S[tg].o,S[tg].n);\nif(c[0]!==dv.getUint32(S[tg].e+24,true)||c[1]!==dv.getUint32(S[tg].e+28,true)){window.__npcfail=\"ck \"+tg;return;}}\nconst nv=rdU(S.VERT.o);if(nv>65535)return;\nconst pos=new Float32Array(nv*3);\nfor(let i=0;i<nv*3;i++)pos[i]=rdU(S.VERT.o+8+i*8);\nconst nt2=rdU(S.TRIS.o);\nconst idx=new Uint16Array(nt2*3);\nfor(let i=0;i<nt2*3;i++)idx[i]=rdU(S.TRIS.o+8+i*8);\nconst nj=rdU(S.SKEL.o);\nconst bindR=new Float32Array(nj*4);\nconst par=new Int32Array(nj);\nfor(let j=0;j<nj;j++){const b=S.SKEL.o+8+j*64;\npar[j]=rdU(b);\nbindR[j*4]=rdU(b+8);bindR[j*4+1]=rdU(b+16);bindR[j*4+2]=rdU(b+24);}\n// HAND COLLAPSE (game-scale honesty): finger joints (bind |x| beyond the wrist line) ride\n// their nearest in-line ancestor RIGIDLY -- ~30 finger joints x mocap-adopted deltas LBS-blend\n// into zigzag chains at low screen size (the operator's report); rigid hands read correctly.\nconst hcol=[];\nfor(let j=0;j<nj;j++){\nif(Math.abs(bindR[j*4])>42000){\nlet a=par[j],guard=0;\nwhile(a>=0&&a<nj&&Math.abs(bindR[a*4])>42000&&guard<64){a=par[a];guard++;}\nif(a>=0&&a<nj)hcol.push([j,a]);continue;}\n// toes: below the ankle line they ride the foot rigidly (same tear class as fingers)\nif(bindR[j*4+2]<6000){\nlet a=par[j],guard=0;\nwhile(a>=0&&a<nj&&bindR[a*4+2]<6000&&guard<64){a=par[a];guard++;}\nif(a>=0&&a<nj)hcol.push([j,a]);}}\n// FOOT JOINTS = the toe-collapse anchors below the shin line: the set the ankle fix rotates\nconst fj=[...new Set(hcol.filter(p=>bindR[p[1]*4+2]<12000).map(p=>p[1]))];\n// ?ankle=NN (centirad) -- the screenshot-calibration lever for the dorsiflexion angle\nconst mA=location.search.match(/ankle=(-?\\d+)/);if(mA)window.__ankle=Number(mA[1])/100;\n// SOFT-TISSUE ANCHORS FROM THE ASSET'S OWN DYNA SECTION -- declared data, not a guessed band.\n// The previous derivation searched bind z/171530 within .58-.70 AND REQUIRED |x|<9000, i.e. the\n// NEAR-MIDLINE cluster -- which is the SPINE chain, so driving it swung the whole torso. Worse,\n// z/171530 omits zmin (~2872 here), so the band it actually searched was 563-683 permil of TRUE\n// stature while the bust line sits at 744: it was hunting 6-18 permil BELOW the target and could\n// never have found a breast bone even if the rig carried one. (This file's own anatomy probe\n// below already normalised correctly with (z-zmn)/H -- two instruments in one file disagreeing.)\n// nx_nxa_dyna derives a LATERAL pair from this mesh's vertex centroids and ships it in the file.\nlet zmn9=1e18,zmx9=-1e18;\nfor(let v=0;v<nv;v++){const z9=pos[v*3+2];if(z9<zmn9)zmn9=z9;if(z9>zmx9)zmx9=z9;}\nconst H9=(zmx9-zmn9)||1;\nconst dyn=[];\nif(S.DYNA){const cD=ckf(S.DYNA.o,S.DYNA.n);\nif(cD[0]===dv.getUint32(S.DYNA.e+24,true)&&cD[1]===dv.getUint32(S.DYNA.e+28,true)){\nconst ndb=rdU(S.DYNA.o),dst=rdU(S.DYNA.o+8);\nfor(let d=0;d<ndb;d++){const bD=S.DYNA.o+16+d*dst*8;\ndyn.push({side:rdU(bD),x:rdU(bD+8),y:rdU(bD+16),z:rdU(bD+24),\nk:rdU(bD+32),c:rdU(bD+40),max:rdU(bD+48),infl:rdU(bD+56),\nzp:Math.round(((rdU(bD+24)-zmn9)/H9)*1000)});}}}\n// FALLBACK for an asset with no DYNA: the same search, but with the origin RESTORED and aimed\n// at the true bust line, and requiring the joint to be OFF the midline (>3000) rather than on\n// it. On a rig with no lateral bones this legitimately finds NOTHING -- and finding nothing is\n// CORRECT, where finding the spine was actively harmful.\nconst chj=[];\nif(!dyn.length){for(let j=0;j<nj;j++){const bzT=(bindR[j*4+2]-zmn9)/H9;\nif(bzT>.704&&bzT<.784&&bindR[j*4+1]<-1200&&Math.abs(bindR[j*4])>3000)chj.push(j);}}\n// (2026-07-29 REVERTED: a twist-band collapse rule lived here briefly -- rigidifying the\n// forearm twist helpers to the main chain applied the WRONG orientation to twist-weighted\n// forearm flesh: forward-jutting flattened ribbon forearms on EVERY girl. A workaround that\n// trades one defect for a worse one is a bug; the real fix is weight-level in the NXA bake.)\n" as *u8)
206 p = gpe_ap(out, p, "const nsv=rdU(S.SKIN.o);if(nsv!==nv)return;\nconst aj=new Float32Array(nv*4),aw3=new Float32Array(nv*4);\nfor(let v=0;v<nv;v++){const b=S.SKIN.o+8+v*64;\nfor(let k=0;k<4;k++){aj[v*4+k]=rdU(b+k*8);aw3[v*4+k]=rdU(b+32+k*8)/4096;}}\n// SMOOTH VERTEX NORMALS (area-weighted accumulation): screen-space dFdx normals read as\n// faceted triangles at body scale (operator: \"very triangly\") -- real normals, skinned by\n" as *u8)
207 p = gpe_ap(out, p, "// the DQ rotation, give the smooth-shaded figure the last mile deserves.\nconst nrm=new Float32Array(nv*3);\nfor(let e=0;e<nt2*3;e+=3){const a=idx[e],b2=idx[e+1],c2=idx[e+2];\nconst ax=pos[a*3],ay=pos[a*3+1],az=pos[a*3+2];\nconst e1x=pos[b2*3]-ax,e1y=pos[b2*3+1]-ay,e1z=pos[b2*3+2]-az;\nconst e2x=pos[c2*3]-ax,e2y=pos[c2*3+1]-ay,e2z=pos[c2*3+2]-az;\nconst fx=e1y*e2z-e1z*e2y,fy=e1z*e2x-e1x*e2z,fz=e1x*e2y-e1y*e2x;\nnrm[a*3]+=fx;nrm[a*3+1]+=fy;nrm[a*3+2]+=fz;\nnrm[b2*3]+=fx;nrm[b2*3+1]+=fy;nrm[b2*3+2]+=fz;\nnrm[c2*3]+=fx;nrm[c2*3+1]+=fy;nrm[c2*3+2]+=fz;}\nfor(let v=0;v<nv;v++){const L3=Math.hypot(nrm[v*3],nrm[v*3+1],nrm[v*3+2])||1;\nnrm[v*3]/=L3;nrm[v*3+1]/=L3;nrm[v*3+2]/=L3;}\n// OPTIONAL sections already in the file (viewer-lane assets): DRESS mesh + HAIR guide strands\nfor(const tg of[\"GVRT\",\"GTRI\",\"HSTR\",\"POSE\"]){if(!S[tg])continue;\nconst c=ckf(S[tg].o,S[tg].n);\nif(c[0]!==dv.getUint32(S[tg].e+24,true)||c[1]!==dv.getUint32(S[tg].e+28,true))delete S[tg];}\nlet gpos=null,gidx=null,gaj=null,gaw=null,gnrm=null,gnt=0;\nif(S.GVRT&&S.GTRI){\nconst gnv=rdU(S.GVRT.o);gnt=rdU(S.GTRI.o);\ngpos=new Float32Array(gnv*3);\nfor(let i=0;i<gnv*3;i++)gpos[i]=rdU(S.GVRT.o+8+i*8);\ngidx=new Uint16Array(gnt*3);\nfor(let i=0;i<gnt*3;i++)gidx[i]=rdU(S.GTRI.o+8+i*8);\n// skin the dress by NEAREST BODY VERT weight copy (moves with the skin, zero physics)\ngaj=new Float32Array(gnv*4);gaw=new Float32Array(gnv*4);\n// skirt verts (below the hip line) may only bind to TORSO-band body verts -- hem verts that\n// grab the nearer LEG tear the dress apart mid-stride (the drape lane's measured class)\nfor(let v=0;v<gnv;v++){const gx=gpos[v*3],gy=gpos[v*3+1],gz=gpos[v*3+2];\nconst zlim=(gz<88000)?88000:0;\nlet bi=0,bd2=1e18;\nfor(let u=0;u<nv;u+=2){if(pos[u*3+2]<zlim)continue;\nconst dx2=pos[u*3]-gx,dy2=pos[u*3+1]-gy,dz2=pos[u*3+2]-gz;\nconst dd2=dx2*dx2+dy2*dy2+dz2*dz2;if(dd2<bd2){bd2=dd2;bi=u;}}\nfor(let k=0;k<4;k++){gaj[v*4+k]=aj[bi*4+k];gaw[v*4+k]=aw3[bi*4+k];}}\ngnrm=new Float32Array(gnv*3);\nfor(let e=0;e<gnt*3;e+=3){const a=gidx[e],b2=gidx[e+1],c2=gidx[e+2];\nconst e1x=gpos[b2*3]-gpos[a*3],e1y=gpos[b2*3+1]-gpos[a*3+1],e1z=gpos[b2*3+2]-gpos[a*3+2];\nconst e2x=gpos[c2*3]-gpos[a*3],e2y=gpos[c2*3+1]-gpos[a*3+1],e2z=gpos[c2*3+2]-gpos[a*3+2];\nconst fx=e1y*e2z-e1z*e2y,fy=e1z*e2x-e1x*e2z,fz=e1x*e2y-e1y*e2x;\ngnrm[a*3]+=fx;gnrm[a*3+1]+=fy;gnrm[a*3+2]+=fz;\ngnrm[b2*3]+=fx;gnrm[b2*3+1]+=fy;gnrm[b2*3+2]+=fz;\ngnrm[c2*3]+=fx;gnrm[c2*3+1]+=fy;gnrm[c2*3+2]+=fz;}\nfor(let v=0;v<gnv;v++){const L4=Math.hypot(gnrm[v*3],gnrm[v*3+1],gnrm[v*3+2])||1;\ngnrm[v*3]/=L4;gnrm[v*3+1]/=L4;gnrm[v*3+2]/=L4;}}\n// THE ANATOMY PROBE: the mesh's OWN bind-space, measured -- never assumed. Painted landmarks\n// (face, chest) were placed against a nominal 171530 height; if that is not the real extent,\n// every band lands on the wrong body part. The asset carries the truth (vertex extents + the\n// joint ladder): read it, publish it to the HUD, and DERIVE the bands from it.\nwindow.__anat=(()=>{let zmn=1e18,zmx=-1e18,xmx=-1e18;\nfor(let v=0;v<nv;v++){const z=pos[v*3+2];if(z<zmn)zmn=z;if(z>zmx)zmx=z;\nconst x=Math.abs(pos[v*3]);if(x>xmx)xmx=x;}\nconst H=(zmx-zmn)||1;const fr=z=>Math.round(((z-zmn)/H)*1000);\nlet jlo=1e18,jhi=-1e18;\nfor(let j=0;j<nj;j++){const z=bindR[j*4+2];if(z<jlo)jlo=z;if(z>jhi)jhi=z;}\nconst near=(f)=>{const t=zmn+f*H;let b=0,bd=1e18;\nfor(let j=0;j<nj;j++){const d=Math.abs(bindR[j*4+2]-t)+2*Math.abs(bindR[j*4]);if(d<bd){bd=d;b=j;}}return b;};\n// map published anthropometric ratios through THIS mesh's own anchors: hip .52 and eye .93 of\n// stature are the two landmarks a rig always has, so they calibrate the line that places every\n// other landmark (nipple .72). Falls back to the raw ratio if the anchors look degenerate.\nconst pv=(fr(bindR[near(.52)*4+2]))/1000,hd=(fr(bindR[near(.95)*4+2]))/1000;\nconst sl=(hd-pv)/(.93-.52);\nconst map=f=>(sl>.4&&sl<1.6)?(pv+sl*(f-.52)):f;\nreturn{zmn:Math.round(zmn),zmx:Math.round(zmx),H:Math.round(H),xmx:Math.round(xmx),\nfoot:fr(jlo),crown:fr(jhi),pelvisJ:Math.round(pv*1000),headJ:Math.round(hd*1000),\nnip:map(.72),eye:map(.93),nipP:Math.round(map(.72)*1000),\nchestJ:chj.map(j=>fr(bindR[j*4+2]))};})();\n// HEAD joint (hair anchor) = nearest bind to (0,0,.955H)\nlet hj=-1,hsc2=1e18;\nfor(let j=0;j<nj;j++){const s3=Math.abs(bindR[j*4+2]-163800)+2*Math.abs(bindR[j*4]);\nif(s3<hsc2){hsc2=s3;hj=j;}}\n// HAIR: sampled guide strands (HSTR 2200x8 pts, mm) as LINES rigid to the head joint\nlet hverts=null,hn=0;\nif(S.HSTR&&hj>=0){const nstr=rdU(S.HSTR.o);\nconst step=Math.max(1,Math.floor(nstr/550));\nconst segs=[];\nfor(let s5=0;s5<nstr;s5+=step){const so=S.HSTR.o+8+s5*24*8;\nfor(let p5=0;p5<7;p5++){\nsegs.push(rdU(so+(p5*3)*8),rdU(so+(p5*3+1)*8),rdU(so+(p5*3+2)*8));\nsegs.push(rdU(so+((p5+1)*3)*8),rdU(so+((p5+1)*3+1)*8),rdU(so+((p5+1)*3+2)*8));}}\nhn=segs.length/3;\nhverts=new Float32Array(segs);}\n" as *u8)
208 p = gpe_ap(out, p, "const ntr=rdU(S.ANIM.o);let ao=S.ANIM.o+8;\nconst tr=new Array(nj);let dur=0;\nfor(let k2=0;k2<ntr;k2++){const j=rdU(ao),chn=rdU(ao+8),nk=rdU(ao+16);ao+=24;\nif(chn===2){const t=new Uint16Array(nk),q=new Int16Array(nk*4),d=new Float32Array(nk*3);\n// dt lanes are MILLIMETERS (bake packs /100 to fit i16); binds are 0.01mm units -- x100\n// here or every baked translation renders at 1% (the zombie-arms class: forearms pinned\n// at T-pose pivots because their world displacement was dropped at apply time)\nfor(let i=0;i<nk;i++){const w0=ao+i*16;\nt[i]=dv.getUint16(w0,true);\nq[i*4]=dv.getInt16(w0+2,true);q[i*4+1]=dv.getInt16(w0+4,true);q[i*4+2]=dv.getInt16(w0+6,true);q[i*4+3]=dv.getInt16(w0+8,true);\nd[i*3]=dv.getInt16(w0+10,true)*100;d[i*3+1]=dv.getInt16(w0+12,true)*100;d[i*3+2]=dv.getInt16(w0+14,true)*100;}\nif(j<nj&&nk>0)tr[j]={n:nk,t:t,q:q,d:d};\nif(nk>0&&t[nk-1]>dur)dur=t[nk-1];\nao+=nk*16;}else{ao+=nk*(chn===0?32:40);}}\n// POSE: the held idle pose (id 0) -- frozen channel-2 keyframe rows [joint][q x4][dt x3],\n// root motion already removed at freeze time (nx_nxa_pose). Absent section = old freeze\n// behavior (rule 14); rdU handles negative i64 lanes (getInt32 high word).\nlet pq=null,pdl=null;\nif(S.POSE){const npz=rdU(S.POSE.o);let po=S.POSE.o+8;\nfor(let pz=0;pz<npz;pz++){const pid=rdU(po),ne=rdU(po+8);po+=16;\nif(pid===0&&!pq&&ne<=nj){pq=new Float32Array(nj*4);pdl=new Float32Array(nj*3);\nfor(let j=0;j<nj;j++)pq[j*4+3]=1;\nfor(let e=0;e<ne;e++){const j=rdU(po+e*64);\nif(j>=0&&j<nj){pq[j*4]=rdU(po+e*64+8)/4096;pq[j*4+1]=rdU(po+e*64+16)/4096;pq[j*4+2]=rdU(po+e*64+24)/4096;pq[j*4+3]=rdU(po+e*64+32)/4096;\npdl[j*3]=rdU(po+e*64+40);pdl[j*3+1]=rdU(po+e*64+48);pdl[j*3+2]=rdU(po+e*64+56);}}}\npo+=ne*64;}}\n" as *u8)
209 p = gpe_ap(out, p, "const g=GL.g;\nconst cs2=(ty,src)=>{const sh=g.createShader(ty);g.shaderSource(sh,src);g.compileShader(sh);\nif(!g.getShaderParameter(sh,g.COMPILE_STATUS))throw g.getShaderInfoLog(sh);return sh;};\nconst pr2=g.createProgram();\ng.attachShader(pr2,cs2(g.VERTEX_SHADER,MVS));g.attachShader(pr2,cs2(g.FRAGMENT_SHADER,MFS));\ng.linkProgram(pr2);if(!g.getProgramParameter(pr2,g.LINK_STATUS))throw g.getProgramInfoLog(pr2);\nconst vao=g.createVertexArray();g.bindVertexArray(vao);\nconst mkb=(arr,loc,nc)=>{const b=g.createBuffer();g.bindBuffer(g.ARRAY_BUFFER,b);\ng.bufferData(g.ARRAY_BUFFER,arr,g.STATIC_DRAW);\ng.enableVertexAttribArray(loc);g.vertexAttribPointer(loc,nc,g.FLOAT,false,0,0);};\nmkb(pos,0,3);mkb(aj,1,4);mkb(aw3,2,4);mkb(nrm,3,3);\nconst ib=g.createBuffer();g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,ib);\ng.bufferData(g.ELEMENT_ARRAY_BUFFER,idx,g.STATIC_DRAW);\ng.bindVertexArray(null);\n// dress VAO (same attribute layout)\nlet gvao=null;\nif(gpos){gvao=g.createVertexArray();g.bindVertexArray(gvao);\nmkb(gpos,0,3);mkb(gaj,1,4);mkb(gaw,2,4);mkb(gnrm,3,3);\nconst gib=g.createBuffer();g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,gib);\ng.bufferData(g.ELEMENT_ARRAY_BUFFER,gidx,g.STATIC_DRAW);\ng.bindVertexArray(null);}\n// hair VAO: line verts, every vert rides the head joint rigidly, radial normals\nlet hvao=null;\nif(hverts){const haj=new Float32Array(hn*4),haw=new Float32Array(hn*4),hnr=new Float32Array(hn*3);\nconst hcx=bindR[hj*4],hcy=bindR[hj*4+1],hcz=bindR[hj*4+2];\nfor(let v=0;v<hn;v++){haj[v*4]=hj;haw[v*4]=1;\nconst rx2=hverts[v*3]-hcx,ry2=hverts[v*3+1]-hcy,rz2=hverts[v*3+2]-hcz;\nconst rl=Math.hypot(rx2,ry2,rz2)||1;\nhnr[v*3]=rx2/rl;hnr[v*3+1]=ry2/rl;hnr[v*3+2]=rz2/rl;}\nhvao=g.createVertexArray();g.bindVertexArray(hvao);\nmkb(hverts,0,3);mkb(haj,1,4);mkb(haw,2,4);mkb(hnr,3,3);\ng.bindVertexArray(null);}\n// joint texture: row 0 = static binds; rows 1+2v,2+2v = visible-instance v's dq/dt (12 max)\nconst jt=g.createTexture();g.activeTexture(g.TEXTURE1);g.bindTexture(g.TEXTURE_2D,jt);\ng.texStorage2D(g.TEXTURE_2D,1,g.RGBA32F,nj,25);\ng.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,g.NEAREST);\ng.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,g.NEAREST);\ng.texSubImage2D(g.TEXTURE_2D,0,0,0,nj,1,g.RGBA,g.FLOAT,bindR);\ng.activeTexture(g.TEXTURE0);\n// ROOT joint = the pelvis-region bind (nearest to (0,0,.52H)): its horizontal clip drift is\n// subtracted at eval (root-motion removal) and its travel span DERIVES the walk cadence\nlet rj=-1,rsc=1e18;\nfor(let j=0;j<nj;j++){const s2=Math.abs(bindR[j*4+2]-89000)+2*Math.abs(bindR[j*4]);\nif(s2<rsc){rsc=s2;rj=j;}}\n" as *u8)
210 p = gpe_ap(out, p, "let mpb=700;\n// ROOT-MOTION EXTRACTION, done right (operator: \"her hips don't move naturally\"): the old\n// subtraction removed the root track's FULL horizontal translation -- forward locomotion\n// (correct) AND the captured lateral pelvis sway (the defect: mocap hips existed and the\n// pipeline deleted them). Fit the LINEAR drift once here; runtime subtracts only that line,\n// so the oscillatory residual -- sway, weight shift, the life in the walk -- survives on\n// every joint coherently, feet included (they were planted in capture, they stay planted).\nlet rv={x0:0,y0:0,vx:0,vy:0,t0:0};\nif(rj>=0&&tr[rj]&&tr[rj].n>1){const R=tr[rj];const nk9=R.n;\nconst spn=R.t[nk9-1]-R.t[0]||1;\nrv={x0:R.d[0],y0:R.d[1],vx:(R.d[(nk9-1)*3]-R.d[0])/spn,vy:(R.d[(nk9-1)*3+1]-R.d[1])/spn,t0:R.t[0]};}\nif(rj>=0&&tr[rj]){const dtr=tr[rj].d,nk2=tr[rj].n;\nlet x0=1e18,x1=-1e18,y0=1e18,y1=-1e18;\nfor(let i=0;i<nk2;i++){const X=dtr[i*3],Y=dtr[i*3+1];\nif(X<x0)x0=X;if(X>x1)x1=X;if(Y<y0)y0=Y;if(Y>y1)y1=Y;}\nconst blocks=Math.hypot(x1-x0,y1-y0)*1.78/171530;\nif(blocks>1.5)mpb=(dur||1)/blocks;}\nconst st2=[];\nfor(let m=0;m<12;m++){let ph0=0;try{ph0=Number(ex.mobph(BigInt(m)))%4096;}catch(e2){}\nst2.push({A:0,spd:0,iw:0,ct:ph0/4096*(dur||1),cur:new Int32Array(nj)});}\nconst l2={};for(const nm3 of[\"uJT\",\"uSc\",\"uIP\",\"uIH\",\"uSB\",\"uGN\",\"uOF\",\"uZMN\",\"uH\",\"uNIP\",\"uEYE\",\"uCS\",\"uCO\",\"uCH\",\"uCamM\",\"uYPM\",\"uResM\",\"uSkTM\",\"uVm\",\"uOcc\",\"uGar\",\"uHM\",\"uDNL\",\"uDNR\",\"uTm\",\"uWnd\",\"uMoodF\",\"uEyeG\",\"uAnatM\"])l2[nm3]=g.getUniformLocation(pr2,nm3);\n// the DYNA anchors are CONSTANT per asset -- set ONCE here, not per frame. Both sides must\n// exist or neither is set (a single-sided upload would weight one breast and zero the other,\n// which is worse than the symmetric fallback).\nif(dyn.length>=2){const dl9=dyn.find(d=>d.side<0),dr9=dyn.find(d=>d.side>0);\nif(dl9&&dr9){g.useProgram(pr2);g.uniform4f(l2.uDNL,dl9.x,dl9.y,dl9.z,dl9.infl);g.uniform4f(l2.uDNR,dr9.x,dr9.y,dr9.z,dr9.infl);}}\n// ---- E-2: the eyeball pass (own program + unit sphere). Wrapped so ANY failure leaves eyeO\n// null and the painted eyes keep working -- degrade to the old rig, never to no rig.\nlet eyeO=null;\ntry{\nconst ecs=(t,s)=>{const o=g.createShader(t);g.shaderSource(o,s);g.compileShader(o);if(!g.getShaderParameter(o,g.COMPILE_STATUS))throw g.getShaderInfoLog(o);return o;};\nconst EVS=`#version 300 es\nlayout(location=0) in vec3 aS;\nuniform vec3 uEC[24];uniform vec4 uEG[24];\nuniform vec3 uEcam;uniform vec4 uEyp;uniform vec2 uEres;\nout vec3 vSN;out vec3 vSW;flat out int vEI;\nvoid main(){int i=gl_InstanceID;vEI=i;vSN=aS;\nvec3 wp=uEC[i]+aS*uEG[i].w;vSW=wp;\nvec3 rel=wp-uEcam;\nvec3 fw=vec3(uEyp.x*uEyp.w,uEyp.z,uEyp.y*uEyp.w);\nvec3 rt=vec3(uEyp.y,0.,-uEyp.x);\nvec3 up=vec3(-uEyp.x*uEyp.z,uEyp.w,-uEyp.y*uEyp.z);\nfloat zv=max(dot(rel,fw),.081);\ngl_Position=vec4(dot(rel,rt),dot(rel,up)*(uEres.x/uEres.y),zv*(300.08/299.92)-(48./299.92),zv);}`;\nconst EFS=`#version 300 es\nprecision highp float;\nin vec3 vSN;in vec3 vSW;flat in int vEI;\nuniform vec4 uEG[24];uniform vec3 uECol[24];uniform vec3 uEcam;\nout vec4 fc;\nvoid main(){\nvec3 n=normalize(vSN);vec3 gz=normalize(uEG[vEI].xyz);\nvec3 vd=normalize(vSW-uEcam);\nvec3 col=vec3(.94,.93,.91);\ncol*=1.-.22*(1.-max(dot(n,-vd),0.));\nvec3 gp=normalize(gz-vd*.30);\nfloat ap=dot(n,gp);\nfloat ia=.87;\nif(ap>ia){float t=clamp((1.-ap)/(1.-ia),0.,1.);\ncol=uECol[vEI]*(1.35-.7*t);\ncol+=vec3(.11,.08,.03)*max(0.,.55-abs(t-.55))*1.6;\nif(t>.86)col*=.30;\nif(t<.40)col=vec3(.02,.02,.04);}\nvec3 L=normalize(vec3(2400.,2500.,1400.));\nvec3 H=normalize(L-vd);\nfloat spq=max(dot(n,H),0.);\ncol+=vec3(1.,1.,.98)*pow(spq,150.)*1.7;\ncol+=vec3(.16,.17,.18)*pow(spq,10.)*.45;\nfc=vec4(col,1.);}`;\nconst epr=g.createProgram();g.attachShader(epr,ecs(g.VERTEX_SHADER,EVS));g.attachShader(epr,ecs(g.FRAGMENT_SHADER,EFS));g.linkProgram(epr);\nif(!g.getProgramParameter(epr,g.LINK_STATUS))throw g.getProgramInfoLog(epr);\nconst SEG=18,RNG=12;const SPv=[],SIv=[];\nfor(let r=0;r<=RNG;r++){const th=r*Math.PI/RNG;\nfor(let s=0;s<=SEG;s++){const ph=s*2*Math.PI/SEG;\nSPv.push(Math.sin(th)*Math.cos(ph),Math.cos(th),Math.sin(th)*Math.sin(ph));}}\nfor(let r=0;r<RNG;r++)for(let s=0;s<SEG;s++){const a=r*(SEG+1)+s,b2=a+SEG+1;\nSIv.push(a,b2,a+1,a+1,b2,b2+1);}\nconst evao=g.createVertexArray();g.bindVertexArray(evao);\nconst evb=g.createBuffer();g.bindBuffer(g.ARRAY_BUFFER,evb);g.bufferData(g.ARRAY_BUFFER,new Float32Array(SPv),g.STATIC_DRAW);\ng.enableVertexAttribArray(0);g.vertexAttribPointer(0,3,g.FLOAT,false,0,0);\nconst eib=g.createBuffer();g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,eib);g.bufferData(g.ELEMENT_ARRAY_BUFFER,new Uint16Array(SIv),g.STATIC_DRAW);\ng.bindVertexArray(null);\nconst el={};for(const nmE of[\"uEC\",\"uEG\",\"uECol\",\"uEcam\",\"uEyp\",\"uEres\"])el[nmE]=g.getUniformLocation(epr,nmE);\n// bind-space eye centres MEASURED from the mesh: frontmost vertex near each eye landmark,\n// pushed back by ~one radius so the cornea sits just proud of the socket (the face shader\n// opens a matching hole, so the sphere is what you actually see).\nconst AN9=window.__anat;const HHb=.115*AN9.H,exl=.16*HHb,ezb=AN9.zmn+.9420*AN9.H,Rb=.046*HHb;\nlet my0=1e18,my1=1e18;\nfor(let v=0;v<nv;v++){const vx=pos[v*3],vy=pos[v*3+1],vz=pos[v*3+2];\nif(Math.abs(vz-ezb)>.07*HHb)continue;\nif(Math.abs(Math.abs(vx)-exl)>.11*HHb)continue;\nif(vx<0){if(vy<my0)my0=vy;}else{if(vy<my1)my1=vy;}}\nif(my0>1e17)my0=-.10*HHb;\nif(my1>1e17)my1=-.10*HHb;\neyeO={pr:epr,vao:evao,ni:SIv.length,l:el,R:Rb,\nbp:[[-exl,my0+.70*Rb,ezb],[exl,my1+.70*Rb,ezb]],\nec:new Float32Array(72),eg:new Float32Array(96),ecol:new Float32Array(72)};\n}catch(e9){eyeO=null;window.__eyefail=String(e9);}\nGL.npc={ok:1,pr:pr2,vao:vao,jt:jt,l:l2,nj:nj,ni:nt2*3,tr:tr,rj:rj,rv:rv,mpb:mpb,dur:dur||1,st:st2,hc:hcol,fj:fj,bind:bindR,chj:chj,dyn:dyn,eye:eyeO,hj:hj,\npq:pq,pd:pdl,\ngvao:gvao,gni:gnt*3,hvao:hvao,hn:hn,\nip:new Float32Array(36),ih:new Float32Array(48),cs:new Float32Array(36),co:new Float32Array(36),ch:new Float32Array(36),sb:new Float32Array(108),gn:new Float32Array(12),of:new Float32Array(12),mdf:new Float32Array(12),\njf:new Float32Array(nj*8*12),ev:new Float32Array(8),\nan:window.__anat,dbg:{pos:pos,aj:aj,aw:aw3,idx:idx}};\nwindow.__npc={nv:nv,nt:nt2,nj:nj,dur:dur,rj:rj,mpb:Math.round(mpb),pose:pq?1:0};\n}catch(e){window.__npcfail=String(e);}}\nif(GL&&ex.mobx)loadNPC();\n// N = summon the girls into a review ring around the player (organ door; perf test surface)\naddEventListener(\"keydown\",e=>{if(e.keyCode===78&&ex.summon)ex.summon();});\n// G = invite/dismiss the girl under the crosshair (party door; she must actually be bonded)\naddEventListener(\"keydown\",e=>{if(e.keyCode===71&&ex.party){const r=Number(ex.party());\nwindow.__party=r===1?\"joined your party\":r===0?\"left your party\":r===-2?\"needs a stronger bond\":r===-3?\"party is full (3)\":\"nobody in your sights\";\nsetTimeout(()=>{window.__party=null;},3000);}});\n// ★THE ISEKAI PASSPORT: the CHARACTER (lifetime ledger + party) is stored under ONE key for\n// EVERY world -- deliberately NOT pathname-scoped like the world save, because crossing to a\n// new world is the whole point. Loaded before the first tick, delta-synced on the world-save\n// beat, and written on pagehide. A corrupt passport is REFUSED by the organ, never half-read.\nif(ex.pass_off&&ex.pass_build&&ex.pass_apply){\nconst PK=\"nxsov_passport\";\nconst pb2s=b=>{let s=\"\";for(let i=0;i<b.length;i+=8192)s+=String.fromCharCode.apply(null,b.subarray(i,i+8192));return s;};\nwindow.__pass_save=()=>{const n=Number(ex.pass_build());const m=new Uint8Array(ex.memory.buffer,Number(ex.pass_off()),n);try{localStorage.setItem(PK,btoa(pb2s(m)));return n;}catch(e){return -1;}};\nwindow.__pass_load=()=>{const d=localStorage.getItem(PK);if(!d)return -1;const r=atob(d);const m=new Uint8Array(ex.memory.buffer,Number(ex.pass_off()),r.length);for(let i=0;i<r.length;i++)m[i]=r.charCodeAt(i);return Number(ex.pass_apply());};\nconst prc=window.__pass_load();\nif(prc===0)console.log(\"nishi: traveler arrived, level \"+Number(ex.pass_level()));\nelse ex.pass_build();\naddEventListener(\"pagehide\",()=>window.__pass_save());\n// PERSISTENCE MUST NOT LAND MID-FRAME. Building the save image, base64-ing it and handing it to\n// localStorage is synchronous multi-millisecond work, and on a fixed 5s timer it lands wherever\n// it lands -- including the middle of a frame, every five seconds, forever. That is the exact\n// signature of PERIODIC jank: mean fps barely moves while the operator sees a hitch on a beat.\n// requestIdleCallback exists for precisely this; the timer only ARMS the save, idle time RUNS it.\n// Fallback keeps old browsers correct rather than silently unpersisted.\nconst _idle=(f)=>window.requestIdleCallback?requestIdleCallback(f,{timeout:2000}):setTimeout(f,0);\nsetInterval(()=>_idle(()=>window.__pass_save()),5000);\n}\n// ?review=1 -- THE SEE-IT LOOP's lever: summon the girls, then auto-face the nearest each\n// frame (yaw/pitch fed through the REAL look door). Headless screenshots judge the figures\n// against realism instead of shipping blind; same class of lever as ?npcocc / ?gl.\nconst REV=location.search.indexOf(\"review=1\")>=0;let _revd=0,_revt=-1;\n// ?anat=1 -- THE MEASUREMENT MODE + operator calibration view: mood zeroed, gaze centered,\n// blink off, GIRL 0 framed every time (constant confounds cancel in before/after diffs).\nconst ANAT9=location.search.indexOf(\"anat=1\")>=0||location.search.indexOf(\"anat=2\")>=0;\n// M1 ORTHOGONAL PAIR (Monge, the mason's method): ?anat=2 frames the SAME frozen girl in PROFILE.\n// One projection cannot determine a solid -- depth (nose/chin/brow projection, the rhinoplasty\n// angles) is UNOBSERVABLE frontally. Two orthogonal views determine every point. The review\n// steering below adds a 90-degree yaw offset so the camera circles to her side; the frozen state\n// (mood/gaze/blink off, girl 0) is identical, so the pair is measurable as one solid.\nconst PROF9=location.search.indexOf(\"anat=2\")>=0;\n// ?record=1 (with review): THE RECORD FUNCTION -- sample the framed girl's chest-spring\n// offset + torso height per SIM TICK for 600 ticks (10s), then MEASURE: dominant frequency\n// (zero-crossings), peak-to-peak amplitude, torso stability -- and judge each against the\n// banked oracle bands. The verdict rides the HUD into every screenshot: physics reviewed by\n// MEASUREMENT of the live render, never by eyeball.\n// 180 samples = 3s at the fixed 60Hz tick: >=6 full cycles of a 2-3Hz signal, Nyquist 30Hz --\n// ample for zero-crossing frequency + peak-to-peak amplitude, and it FINISHES under a headless\n// SwiftShader budget (a 600-sample window measured 130/600 and starved)\nconst REC=location.search.indexOf(\"record=1\")>=0;const RECN=180;const _rc=[],_rt=[],_rs=[];\n// THE TRACE STRIP: a still frame cannot show dynamics, so the recorded series are DRAWN into\n// the page -- chest offset (green), torso height (blue), step signal (amber). This is the\n// gif-equivalent that survives a screenshot, and it is what makes \"wobbly vs tight\" legible\n// instead of arguable.\nfunction _drawtrace(){try{const W2=940,H2=150;const cn=document.createElement(\"canvas\");\ncn.width=W2;cn.height=H2;cn.style.cssText=\"width:min(96vw,940px);border:1px solid #2f2a4a;border-radius:4px;image-rendering:pixelated\";\nconst g2=cn.getContext(\"2d\");g2.fillStyle=\"#0b0a14\";g2.fillRect(0,0,W2,H2);\nconst band=(arr,col,y0,h)=>{if(!arr.length)return;const mn=Math.min.apply(null,arr),mx=Math.max.apply(null,arr),sp=(mx-mn)||1;\ng2.strokeStyle=col;g2.lineWidth=1.5;g2.beginPath();\nfor(let i=0;i<arr.length;i++){const x=i*(W2-8)/(arr.length-1)+4;const y=y0+h-((arr[i]-mn)/sp)*h;\nif(i===0)g2.moveTo(x,y);else g2.lineTo(x,y);}g2.stroke();};\nband(_rc,\"#7fe3a0\",6,42);band(_rt,\"#6fa8ff\",54,42);band(_rs,\"#e8c06a\",102,42);\ng2.fillStyle=\"#b9b1dc\";g2.font=\"11px ui-monospace,monospace\";\ng2.fillText(\"chest offset (tissue vs bone)\",6,16);g2.fillText(\"torso height\",6,64);g2.fillText(\"gait drive (cadence) -- chest should track this at a small lag\",6,112);\nconst hp=document.querySelector(\"p\");if(hp)document.body.insertBefore(cn,hp);}catch(e){}}\n// THE SAMPLER RUNS PER SIM TICK (called from the loop, not a timer): a 16ms interval could\n// only ever bank ~60 samples/s no matter how fast the sim ran -- the measurement was rate-\n// limited by its own instrument, which is the classic way a probe lies about the subject.\nfunction _recsample(){if(!ex.sby||_rc.length>=RECN)return;\nconst bi=window.__revbi|0;if(!Number(ex.mobs()))return;\n_rc.push(Number((ex.sbyb?ex.sbyb:ex.sby)(BigInt(bi),1n)));_rt.push(Number(ex.moby(BigInt(bi))));\n// the reference signal must be the DRIVE, not the speed: |dx|+|dz| is a step MAGNITUDE with no\n// cycle in it (the trace showed a monotone ramp, and correlating an oscillation against a ramp\n// scored coh 0.05 -- the instrument was wrong, not the physics). Her cadence lives in the gait\n// PHASE, so reconstruct the same bob the organ feeds the spring anchor. Correlating response\n// against drive is a transfer-function measurement: small lag + high coherence IS \"tight and\n// aligned with the body\".\n_rs.push(Math.sin(((Number(ex.mobph(BigInt(bi)))*214)%25736)/4096));window.__recn=_rc.length;\nif(_rc.length===RECN){\nconst mean=_rc.reduce((a,b)=>a+b,0)/RECN;let zc=0;\nfor(let i=1;i<RECN;i++)if((_rc[i]-mean)*(_rc[i-1]-mean)<0)zc++;\nconst fq=zc/2/(RECN/60);\nconst amp=(Math.max(..._rc)-Math.min(..._rc))/256*1.56;\nconst tam=(Math.max(..._rt)-Math.min(..._rt))/256*100;\nconst fok=fq>=1.5&&fq<=3.4,aok=amp>=.8&&<=6,tok=tam<=2;\n// PHASE ALIGNMENT, measured: cross-correlate the chest response against the STEP signal and\n// report lag in ticks + peak coherence. \"Wobbly, not tight and aligned with movement\" IS a\n// lag/coherence claim, so it becomes a number instead of an argument. NOTE the banked law\n// from the biomechanics sweep: gate on the ERROR, never on correlation alone -- a high\n// correlation with a large error is exactly how a gate banks an unearned green, so the lag\n// (an error in ticks) is the binding leg and coherence only qualifies it.\nconst nrm=a=>{const m=a.reduce((x,y)=>x+y,0)/a.length;const d=a.map(v=>v-m);\nconst sd=Math.sqrt(d.reduce((x,y)=>x+y*y,0)/a.length)||1;return d.map(v=>v/sd);};\nconst A=nrm(_rc),B=nrm(_rs);let bl=0,bc=-2;\nfor(let L=0;L<=20;L++){let c=0;for(let i=L;i<RECN;i++)c+=A[i]*B[i-L];c/=(RECN-L);if(c>bc){bc=c;bl=L;}}\nconst lok=bl<=8,cok=bc>=.25;\nwindow.__rec=\"REC chest \"+fq.toFixed(1)+\"Hz(\"+(fok?\"ok\":\"OUT\")+\") \"+amp.toFixed(1)+\"cm(\"+(aok?\"ok\":\"OUT\")+\") torso \"+tam.toFixed(1)+\"cm(\"+(tok?\"ok\":\"OUT\")+\") lag \"+bl+\"t(\"+(lok?\"ok\":\"OUT\")+\") coh \"+bc.toFixed(2)+\"(\"+(cok?\"ok\":\"OUT\")+\")\";\n_drawtrace();}}\n// ?breath=1 -- THE IDLE WINDOW. The gait recorder banks 180 ticks = 3.0s, but a 0.233Hz breath\n// has a 4.3s period: LESS THAN ONE CYCLE, so its zero-crossing frequency is arithmetic noise.\n// ★ AN EXIT CRITERION IS ONLY REAL IF THE INSTRUMENT'S WINDOW CAN CONTAIN THE SIGNAL -- Nyquist\n// is the ceiling, the WINDOW is the floor, and the published I1 criterion failed the floor.\n// 780 ticks = 13s = 3.03 breath cycles.\nconst BR=location.search.indexOf(\"breath=1\")>=0;const BRN=780;\nconst _ba=[],_bo=[],_bv=[];\nfunction _brsample(){if(!ex.mob_anchor_q8||_ba.length>=BRN)return;\nconst bi=window.__revbi|0;if(!Number(ex.mobs()))return;\n// ★ MEASURE THE ANCHOR, NOT THE RELATIVE OFFSET. Breathing is a 0.233Hz drive on a spring whose\n// natural frequency is ~2.75Hz, so the tissue tracks it QUASI-STATICALLY and the tissue-vs-bone\n// offset sits near ZERO BY CONSTRUCTION. Reading breath through a relative-displacement probe\n// would score ~0 and read as a dead driver -- a false negative produced by the instrument, not\n// the subject. Visible breathing IS the absolute chest excursion, which is the anchor itself.\n// The offset is banked too, because a near-zero offset here is the CORRECT physics and worth\n// showing rather than hiding.\n_ba.push(Number(ex.mob_anchor_q8(BigInt(bi))));\n_bo.push(Number(ex.sbyb(BigInt(bi),1n)));\n_bv.push(ex.mob_spd_q8?Number(ex.mob_spd_q8(BigInt(bi))):-1);\nwindow.__brn=_ba.length;\nif(_ba.length<BRN)return;\n// STILLNESS IS A PRECONDITION, NOT A DETAIL. An idle measurement taken while she walks measures\n// GAIT and would report it as breathing. If she moved, say INVALID -- never emit a number the\n// window did not earn.\nlet still=0;for(let i=0;i<BRN;i++)if(_bv[i]===0)still++;\nconst sr=still*100/BRN;\nconst mean=_ba.reduce((a,b)=>a+b,0)/BRN;let zc=0;\nfor(let i=1;i<BRN;i++)if((_ba[i]-mean)*(_ba[i-1]-mean)<0)zc++;\nconst fq=zc/2/(BRN/60);\n// q8 world units -> cm, derived from the cited gait constant (7 q8 == 2.7cm => /256*100)\nconst p2p=(Math.max(..._ba)-Math.min(..._ba))/256*100;\nconst op2p=(Math.max(..._bo)-Math.min(..._bo))/256*100;\n// gait-band proxy: a 2.5Hz signal has a far larger tick-to-tick delta than a 0.23Hz one at equal\n// amplitude, so the first-difference RMS against the signal RMS separates them. Labelled a PROXY\n// because it is not a filter bank.\nconst rms=a=>Math.sqrt(a.reduce((s,v)=>s+v*v,0)/a.length);\nconst d1=[];for(let i=1;i<BRN;i++)d1.push(_ba[i]-_ba[i-1]);\nconst hf=rms(d1)/(rms(_ba.map(v=>v-mean))||1);\n// speed stats: this is how WC_BREATH_CUT_Q8 stops being a guess. Report the observed scale of\n// the per-tick delta so the blend threshold can be SET from data next pass.\nconst nz=_bv.filter(v=>v>0).sort((a,b)=>a-b);\nconst vmed=nz.length?nz[nz.length>>1]:0,vmax=nz.length?nz[nz.length-1]:0;\nconst fok=fq>=0.20&&fq<=0.30,aok=p2p>=0.4&&p2p<=0.8,sok=sr>=90;\nwindow.__br=(sok?\"BREATH \":\"BREATH INVALID(moved) \")+fq.toFixed(3)+\"Hz(\"+(fok?\"ok\":\"OUT\")+\") p2p \"+p2p.toFixed(2)+\"cm(\"+(aok?\"ok\":\"OUT\")+\") still \"+sr.toFixed(0)+\"%(\"+(sok?\"ok\":\"OUT\")+\") hf \"+hf.toFixed(2)+\" | tissue-rel \"+op2p.toFixed(2)+\"cm (near-0 = correct, quasi-static) | spd med \"+vmed+\" max \"+vmax+\" cut \"+24;\nwindow.__rec=window.__br;}\n// feed AT MOST ONE gentle look delta per SIM TICK: the look channel ACCUMULATES between\n// steps, so a free-running interval slammed pitch to the clamp (sky-only / floor-only\n// screenshots -- instrumentation-caught both polarities)\n// ?perf=1 -- THE SMOOTHNESS PROBE. \"Laggy and janky\" is a TAIL claim, not an average-fps claim:\n// a build can hold 60fps mean and still feel broken if one frame in twenty takes 40ms. Mean fps\n// is the metric that hides exactly the defect the operator is reporting, so this measures the\n// DISTRIBUTION -- p50/p95/p99 -- plus a jank count using the shipped-industry definition (a frame\n// exceeding 2x the rolling median) and the worst single stall.\n// Sampling from an independent rAF chain is legitimate and deliberate: every rAF callback rides\n// the same vsync, so inter-callback deltas measure the compositor's real frame cadence without\n// having to instrument the render loop and perturb the thing being measured.\n// Bands: p50 <= 16.7ms (60Hz budget), p95 <= 20ms, p99 <= 33.3ms (never worse than ONE dropped\n// frame at the 99th), jank <= 5%. 90Hz VR would tighten the budget to 11.1ms -- reported too, so\n// the VR verdict is visible before anyone ships to a headset.\nconst PERF=location.search.indexOf(\"perf=1\")>=0;const PERFN=600;\nif(PERF){const _pf=[];let _plast=-1;\nconst _ptick=(t)=>{if(_plast>=0)_pf.push(t-_plast);_plast=t;\nwindow.__perfn=_pf.length;\nif(_pf.length<PERFN){requestAnimationFrame(_ptick);return;}\nconst s=_pf.slice().sort((a,b)=>a-b);\nconst q=f=>s[Math.min(s.length-1,Math.floor(s.length*f))];\nconst p50=q(.5),p95=q(.95),p99=q(.99),worst=s[s.length-1];\n// jank vs a ROLLING median, not the global one: a build that degrades halfway through would\n// otherwise hide its own stutter inside a global median it dragged upward itself.\nlet jank=0;const W=31;\nfor(let i=W;i<_pf.length;i++){const w=_pf.slice(i-W,i).sort((a,b)=>a-b);\nif(_pf[i]>2*w[W>>1])jank++;}\nconst jr=jank*100/Math.max(1,_pf.length-W);\nconst ok50=p50<=16.7,ok95=p95<=20,ok99=p99<=33.3,okj=jr<=5;\nwindow.__perf=\"PERF p50 \"+p50.toFixed(1)+\"ms(\"+(ok50?\"ok\":\"OUT\")+\") p95 \"+p95.toFixed(1)+\"ms(\"+(ok95?\"ok\":\"OUT\")+\") p99 \"+p99.toFixed(1)+\"ms(\"+(ok99?\"ok\":\"OUT\")+\") jank \"+jr.toFixed(1)+\"%(\"+(okj?\"ok\":\"OUT\")+\") worst \"+worst.toFixed(0)+\"ms\"\n+\" | vr90 \"+(p99<=11.1?\"ok\":\"OUT\")+\" | work \"+(ex.work_ms?Number(ex.work_ms()):-1)+\"ms q\"+(ex.quality?Number(ex.quality()):-1);\n};requestAnimationFrame(_ptick);}\nif(REV)setInterval(()=>{try{if(!ex.summon||!ex.mobs||!ex.look)return;\nconst t=Number(ex.tnow());if(t===_revt)return;_revt=t;\nif(!_revd||t-_revd>900){/*re-form the ring on a cadence: a long headless budget fast-forwards 10k+ ticks and the once-summoned girls wander beyond draw distance -- both 08-03 review frames measured nv:0, an empty stage under a green REC line*/ex.summon();_revd=t||1;return;}\nconst n=Number(ex.mobs());if(!n)return;\nconst cx=Number(ex.camx()),cy0=Number(ex.camy()),cz=Number(ex.camz());\nlet bi=0,bd=1e18;\nif(ANAT9){bd=1;}else{for(let i=0;i<n;i++){const dx=Number(ex.mobx(BigInt(i)))-cx,dz=Number(ex.mobz(BigInt(i)))-cz;const d=dx*dx+dz*dz;if(d<bd){bd=d;bi=i;}}}\nif(ANAT9){const dx0=Number(ex.mobx(0n))-cx,dz0=Number(ex.mobz(0n))-cz;bd=dx0*dx0+dz0*dz0;}\n// aim at EYE height (+430 ~ 1.7 blocks), not +300 (chest): the face is the measured worst\n// region and the review instrument was framing the torso -- every close-up parked on the\n// chest and the face never got its portrait. The ruler frames what it must judge.\nconst dx=Number(ex.mobx(BigInt(bi)))-cx,dz=Number(ex.mobz(BigInt(bi)))-cz,dy=Number(ex.moby(BigInt(bi)))+430-cy0;\n// (an ORBIT approach was started here and REMOVED: no camera-teleport door exists, so it\n// would have been dead code. The profile is achieved by TURNING HER instead of moving the\n// camera -- display-side heading is ours to set, per the organ-owns-position law.)\nconst dyaw=Math.atan2(dx,dz)*4096;const cur=Number(ex.yaw());let dd=dyaw-cur;\nwhile(dd>12868)dd-=25736;while(dd<-12868)dd+=25736;\nconst dpit=Math.atan2(dy,Math.sqrt(bd)||1)*4096;const cp=Number(ex.pitch());\nex.look(BigInt(Math.max(-300,Math.min(300,Math.round(dd/6)))),BigInt(Math.max(-150,Math.min(150,Math.round((cp-dpit)/6)))));\nwindow.__revbi=bi;\nwindow.__revready=(bd<26214400&&Math.abs(dd)<600&&Math.abs(cp-dpit)<600)?1:0;/*stage-ready = nearest girl within 20 blocks (bd is Q8-squared) and the aim within ~0.15rad on both axes -- the record paint gate holds for this*/\n}catch(e){}},16);\ncv.addEventListener(\"dblclick\",()=>{if(cv.requestFullscreen)cv.requestFullscreen();});\nif(!GL){cv.width=W;cv.height=H;ctx=cv.getContext(\"2d\");img=ctx.createImageData(W,H);ex.render();blit();}\n" as *u8)
211 p = gpe_ap(out, p, "// ?plant=1 -- THE RINGDOWN (PLUCK) PROBE. Every other probe here measures the FORCED response,\n// which confounds the plant with its drive. The two numbers biomechanics actually publishes --\n// natural frequency and damping ratio -- belong to the PLANT ALONE and are visible only once the\n// drive stops. She rings down every time she stops walking, so the pluck test is ALREADY HAPPENING\n// in the game and nobody was recording it: measuring our own tissue needs no reference footage and\n// no operator input at all.\n// CHANNEL = sbyb (tissue-vs-bone), correct by the same argument the breath probe rests on: under\n// the 0.233Hz respiration drive the tissue tracks QUASI-STATICALLY, so the relative offset decays\n// toward zero and what remains IS the free response.\n// BANDS (knowledge/gamefeel_oracle.conf, cited 2026-08-03): tissue_fn_mhz 4000-5200 (braless free\n// vibration modes, n=1) and tissue_zeta_permil 350-600 (Haake & Scurr 2010, zeta 0.475, n=1).\n// Those rows describe a HUMAN; this reports OURS in the SAME units, which is the only thing that\n// makes the comparison legitimate rather than the unit conflation this lane keeps hitting.\nconst PL=location.search.indexOf('plant=1')>=0;const PLN=150,PLCAP=1800;\nconst _pl=[];let _plst=-1,_pln=0,_plab=0;\nfunction _plsample(){if(!ex.sbyb||!ex.mob_spd_q8||window.__plant)return;\nconst bi=window.__revbi|0;if(!Number(ex.mobs()))return;\n_pln++;const sp=Number(ex.mob_spd_q8(BigInt(bi)));\nif(_plst<0){if(sp===0){_plst=_pln;}else if(_pln>=PLCAP){window.__plant='PLANT INVALID(she never stopped in '+PLCAP+'t)';window.__rec=window.__plant;}return;}\n// STILLNESS IS A PRECONDITION, NOT A DETAIL (banked): a window that catches her moving measured\n// GAIT and would report it as a ringdown. Discard and wait for the next stop -- never emit a\n// number the window did not earn.\nif(sp!==0){_pl.length=0;_plst=-1;_plab++;\nif(_pln>=PLCAP){window.__plant='PLANT INVALID(no clean still window, '+_plab+' aborted)';window.__rec=window.__plant;}return;}\n_pl.push(Number(ex.sbyb(BigInt(bi),1n)));window.__pln=_pl.length;\nif(_pl.length<PLN)return;\n// EXTREMA, not zero-crossings: crossings give the period but say nothing about amplitude, and\n// amplitude DECAY is the entire damping measurement. Successive extrema sit a HALF period apart,\n// so the full-period log decrement is twice the per-extremum one.\nconst xt=[];\nfor(let i=1;i<PLN-1;i++){const a=_pl[i-1],b=_pl[i],c=_pl[i+1];\nif((b>=a&&b>c)||(b<=a&&b<c))xt.push({i:i,v:b});}\n// A QUANTISED INSTRUMENT'S GRANULARITY MUST BE SMALL AGAINST ITS OWN SIGNAL (banked twice in this\n// file's own history). The offset is q8 = a 0.39cm floor; peaks under 2 quanta are quantisation\n// noise wearing the shape of physics. Refuse them and NAME the floor -- a refusal that names the\n// instrument's own limit is itself the argument for the finer channel.\nconst pk=xt.filter(e=>Math.abs(e.v)>=2);\nif(pk.length<3){window.__plant='PLANT INVALID(only '+pk.length+' peaks >=2q8; the q8 quantum 0.39cm is the floor, not the tissue)';window.__rec=window.__plant;return;}\nlet ss=0;for(let i=1;i<pk.length;i++)ss+=pk[i].i-pk[i-1].i;\nconst half=ss/(pk.length-1);const fn=60/(2*half);\nlet ds=0,dn=0;\nfor(let i=1;i<pk.length;i++){const a=Math.abs(pk[i-1].v),b=Math.abs(pk[i].v);\nif(a>0&&b>0&&a>b){ds+=Math.log(a/b);dn++;}}\nconst dl=dn?2*(ds/dn):0;\nconst zt=dl>0?dl/Math.sqrt(4*Math.PI*Math.PI+dl*dl):0;\nconst fm=Math.round(fn*1000),zp=Math.round(zt*1000);\nconst fok=fm>=4000&&fm<=5200,zok=zp>=350&&zp<=600;\nwindow.__plant='PLANT fn '+fm+'mHz('+(fok?'ok':'OUT 4000-5200')+') zeta '+zp+'permil('+(zok?'ok':'OUT 350-600')+') peaks '+pk.length+' half '+half.toFixed(1)+'t A0 '+Math.abs(pk[0].v)+'q8 decay '+(dn?dl.toFixed(3):'none');\nwindow.__rec=window.__plant;}\n" as *u8)
212 p = gpe_ap(out, p, "if(ex.step&&ex.key){\n// sovereign input layer (nx_input_abstract): forward RAW device events; meaning lives in the wasm.\naddEventListener(\"keydown\",e=>{ex.key(BigInt(e.keyCode),1n);if(e.keyCode===32||(e.keyCode>=37&&e.keyCode<=40))e.preventDefault();});\naddEventListener(\"keyup\",e=>ex.key(BigInt(e.keyCode),0n));\n// mouselook (organs exporting a look door): click locks the pointer, movement feeds the wasm,\n// mouse buttons enter through the standard-gamepad door (0=A/break, 1=B/place). Esc unlocks.\nconst locked=()=>document.pointerLockElement===cv;\nif(ex.look){\ncv.addEventListener(\"click\",()=>{if(!locked()&&cv.requestPointerLock)cv.requestPointerLock();});\naddEventListener(\"mousemove\",e=>{if(locked())ex.look(BigInt(e.movementX|0),BigInt(e.movementY|0));});\naddEventListener(\"mousedown\",e=>{if(locked()&&ex.padb)ex.padb(BigInt(e.button===2?1:0),1n);});\naddEventListener(\"mouseup\",e=>{if(locked()&&ex.padb)ex.padb(BigInt(e.button===2?1:0),0n);});\naddEventListener(\"contextmenu\",e=>{if(locked())e.preventDefault();});\n}\n" as *u8)
213 p = gpe_ap(out, p, "if((\"ontouchstart\" in window)||navigator.maxTouchPoints>0){\n// MOBILE: dual-thumb FPS controls, same sovereign doors as every device. LEFT half drag = move\n// (standard-gamepad dpad), RIGHT half drag = look (analog channel), right TAP = break (pad A),\n// right LONG-PRESS = place (pad B), left TAP = jump (space). Multi-touch: both thumbs at once.\nconst TS={};\ncv.addEventListener(\"touchstart\",e=>{e.preventDefault();const r=cv.getBoundingClientRect();\nfor(const t of e.changedTouches){const id=t.identifier;\nTS[id]={x0:t.clientX,y0:t.clientY,x:t.clientX,y:t.clientY,side:(t.clientX-r.left)<r.width/2?0:1,t0:performance.now(),moved:0,dp:0,lp:null};\nif(TS[id].side===1){TS[id].lp=setTimeout(()=>{const s=TS[id];if(s&&!s.moved&&ex.padb){ex.padb(1n,1n);setTimeout(()=>ex.padb(1n,0n),90);s.dp=1;}},450);}}},{passive:false});\ncv.addEventListener(\"touchmove\",e=>{e.preventDefault();\nfor(const t of e.changedTouches){const s=TS[t.identifier];if(!s)continue;\nconst dx=t.clientX-s.x,dy=t.clientY-s.y;s.x=t.clientX;s.y=t.clientY;\nconst tdx=t.clientX-s.x0,tdy=t.clientY-s.y0;\nif(Math.abs(tdx)+Math.abs(tdy)>14)s.moved=1;\nif(s.side===1){if(ex.look)ex.look(BigInt(Math.round(dx*3)),BigInt(Math.round(dy*3)));}\nelse if(ex.padb){const th=22;\nex.padb(12n,tdy<-th?1n:0n);ex.padb(13n,tdy>th?1n:0n);\nex.padb(14n,tdx<-th?1n:0n);ex.padb(15n,tdx>th?1n:0n);}}},{passive:false});\nconst endT=e=>{e.preventDefault();\nfor(const t of e.changedTouches){const s=TS[t.identifier];if(!s)continue;\nif(s.side===0){if(ex.padb){ex.padb(12n,0n);ex.padb(13n,0n);ex.padb(14n,0n);ex.padb(15n,0n);}\nif(!s.moved&&performance.now()-s.t0<260){ex.key(32n,1n);setTimeout(()=>ex.key(32n,0n),90);}}\nelse{if(s.lp)clearTimeout(s.lp);\nif(!s.moved&&!s.dp&&performance.now()-s.t0<300&&ex.padb){ex.padb(0n,1n);setTimeout(()=>ex.padb(0n,0n),90);}}\ndelete TS[t.identifier];}};\ncv.addEventListener(\"touchend\",endT,{passive:false});cv.addEventListener(\"touchcancel\",endT,{passive:false});\n}else{\ncv.addEventListener(\"pointerdown\",e=>{if(locked())return;const r=cv.getBoundingClientRect();\nex.touch(BigInt(Math.floor((e.clientX-r.left)*W/r.width)),BigInt(Math.floor((e.clientY-r.top)*H/r.height)),1n);e.preventDefault();});\naddEventListener(\"pointerup\",()=>ex.touch(0n,0n,0n));\n}\nconst pads=()=>{const gs=navigator.getGamepads?navigator.getGamepads():[];\nfor(const g of gs){if(!g)continue;\nfor(let i=0;i<Math.min(g.buttons.length,16);i++)ex.padb(BigInt(i),g.buttons[i].pressed?1n:0n);\nex.paxis(0n,BigInt(Math.round((g.axes[0]||0)*1000)));ex.paxis(1n,BigInt(Math.round((g.axes[1]||0)*1000)));break;}};\n// FIXED 60Hz SIM TICK (accumulator): the organ's tick rate belongs to the GAME, never the\n// PANEL -- stepping once per rAF ran life at the display's refresh (a 120Hz monitor doubled\n// day speed, physics and growth; operator: \"the day goes super fast\"). Catch-up capped at 4\n// steps/frame (spiral guard); GL path still feeds vsync headroom to the quality controller.\nlet _pt=performance.now(),_acc=0;\n(function loop(){const _t0=performance.now();let _dt=_t0-_pt;_pt=_t0;if(_dt>250)_dt=250;_acc+=_dt;\nlet _n=0;\n// RECORD MODE BYPASSES THE ACCUMULATOR: priming it fought the spiral guard one line below\n// (which zeroes any leftover) -- net ZERO ticks, and the HUD's t: counter proved it. A\n// measurement run steps a fixed batch; PLAY keeps the fixed-timestep accumulator untouched.\nif((REC||BR||PL)&&!window.__rec){for(let i=0;i<120&&!window.__rec;i++){pads();ex.step();if(PL)_plsample();else if(BR)_brsample();else _recsample();}}\nelse{while(_acc>=16.6667&&_n<4){pads();ex.step();_acc-=16.6667;_n++;}\nif(_acc>=16.6667)_acc=0;}\n// RECORD MODE DRAWS NOTHING until the window is full: the recorder reads DOORS, so rendering\n// is pure cost -- and it was the cost that starved the measurement (8/180 in a 90s headless\n// budget). Skipping it makes ticks nearly free; the final frame still paints the verdict.\n// ...and once the verdict EXISTS, paint exactly ONE frame and then stop drawing forever: the\n// remaining virtual budget was rendering thousands of CPU raycast frames nobody would ever\n// see (a 20s budget cost >10min wall). The HUD keeps updating in the DOM either way.\nconst _skipdraw=(REC||BR||PL)&&(!window.__rec||window.__recpainted||(REV&&!window.__revready&&(window.__recwaited=(window.__recwaited|0)+1)<240));/*the one post-verdict frame must show a READY stage: the old form painted at t~200, BEFORE the summon landed -- every record screenshot was an early empty canvas under a live HUD (08-03: nv:0 beside d0:3.5). Hold the paint until the review aim locks on a near girl, or 240 waited frames as the never-blank failsafe, THEN paint once and freeze.*/\nif((REC||BR||PL)&&window.__rec&&!window.__recpainted&&!_skipdraw)window.__recpainted=1;\nif(_skipdraw){}\nelse if(GL){glDraw();if(ex.frame_ms)ex.frame_ms(BigInt(Math.max(0,Math.round(_dt-16))));}\n" as *u8)
214 p = gpe_ap(out, p, "else if(!_skipdraw){ex.render();blit();if(ex.frame_ms)ex.frame_ms(BigInt(Math.round(performance.now()-_t0)));}\nrequestAnimationFrame(loop);})();\n}else{\n// legacy organs without the input layer: the old page-side map + single-held tick\nconst MAP={ArrowUp:0,w:0,ArrowDown:1,s:1,ArrowLeft:2,a:2,ArrowRight:3,d:3,e:4,E:4,b:5,B:5};\nlet held=-1;\naddEventListener(\"keydown\",e=>{const d=MAP[e.key];if(d===undefined)return;e.preventDefault();held=d;});\naddEventListener(\"keyup\",e=>{if(MAP[e.key]!==undefined)held=-1;});\n(function loop(){ex.tick(BigInt(held<0?9:held));ex.render();blit();requestAnimationFrame(loop);})();\n}\n" as *u8)
215 p = gpe_ap(out, p, "// THE LIFE HUD (organ doors only -- the page never computes game truth): day, season,\n// weather, harvest, the found-humans ledger, and the targeted girl's BOND.\nconst hud=document.createElement(\"div\");hud.style.cssText=\"font:12px ui-monospace,monospace;color:#b9b1dc;letter-spacing:.08em;min-height:16px\";\nconst hp0=document.querySelector(\"p\");if(hp0)document.body.insertBefore(hud,hp0);\nconst SE9=[\"SPRING\",\"SUMMER\",\"AUTUMN\",\"WINTER\"];\nsetInterval(()=>{try{if(!ex.dayt)return;\nlet s9=\"\";\n// the TRAVELER first: level, party, worlds walked -- the investment that crosses worlds\nif(ex.pass_level){s9+=\"LV \"+Number(ex.pass_level());\nif(ex.partyn){const pn9=Number(ex.partyn());if(pn9)s9+=\" | PARTY \"+pn9;}\nif(ex.pass_get){let w9=Number(ex.pass_get(10n)),c9=0;while(w9){c9+=w9&1;w9>>=1;}if(c9>1)s9+=\" | WORLDS \"+c9;}\ns9+=\" | \";}\ns9+=\"DAY \"+(Number(ex.dayn())+1)+\" | \"+SE9[Number(ex.season())%4]+(Number(ex.nightf())?\" | NIGHT\":\" | DAY\")+(Number(ex.rainf())?\" | RAIN\":\"\");\ns9+=\" | HARVEST \"+Number(ex.harv())+\" | PLANTED \"+Number(ex.planted())+\" | FOUND \"+Number(ex.found());\nconst t9=Number(ex.npc_t());\nif(t9>=0&&ex.mobfr){s9+=\" | BOND \"+Number(ex.mobfr(BigInt(t9)));\n// C3 made VISIBLE: her mood and its strongest live reason, straight off the ledger doors\nif(ex.mobmood){const md9=Number(ex.mobmood(BigInt(t9)));s9+=\" | MOOD \"+(md9>0?\"+\":\"\")+md9;\nconst TH9=[\"\",\"soaked by rain\",\"afraid of the dark\",\"met you\",\"slept well\",\"hungry\",\"saw a taking\",\"heard someone was taken\",\"heard of your kindness\",\"good company\"];\nlet bi9=0,bm9=0;for(let i9=0;i9<8;i9++){const w9=Number(ex.mobth(BigInt(t9),BigInt(i9)));if(!w9)continue;const mg9=Math.abs((w9&255)-128);if(mg9>bm9){bm9=mg9;bi9=w9>>8;}}\nif(bi9)s9+=\" (\"+(TH9[bi9]||\"?\")+\")\";}}\n// review mode: the WIRING TRUTH rides the HUD into every screenshot -- classified chest\n// joints, visible girls, sim tick (a chj of 0 = the additive physics layer drives nothing)\nif(REV)s9+=\" [\"+(GL&&GL.npc?\"dyn:\"+GL.npc.dyn.length+\" chj:\"+GL.npc.chj.length+\" nv:\"+(window.__npcvis|0)+\" px:\"+(window.__px||\"?\")+\" \":\"cpu \")+\"t:\"+Number(ex.tnow())+(ex.mobx?(()=>{/*the empty-stage instrument: nearest-girl distance + ticks-since-summon settle where the girls ARE instead of arguing about why they are not drawn*/const n8=Number(ex.mobs());let b8=1e9;for(let i8=0;i8<n8;i8++){const dx8=(Number(ex.mobx(BigInt(i8)))-Number(ex.camx()))/256,dz8=(Number(ex.mobz(BigInt(i8)))-Number(ex.camz()))/256;const d8=Math.hypot(dx8,dz8);if(d8<b8)b8=d8;}return \" d0:\"+b8.toFixed(1)+\" rs:\"+(Number(ex.tnow())-_revd);})():\"\")+\"]\";\n// the DECLARED anchors ride the HUD too: side, lateral offset and height in permil of THIS\n// mesh's measured stature -- so a screenshot proves the pair is lateral and at the bust line,\n// rather than leaving \"it reads the asset now\" as an assertion.\nif(REV&&GL&&GL.npc&&GL.npc.dyn.length)s9+=\" DYNA[\"+GL.npc.dyn.map(d=>(d.side<0?\"L\":\"R\")+\"x\"+d.x+\"@\"+d.zp).join(\" \")+\"]\";\n// ANATOMY PROBE into the frame: the mesh's OWN bind extents + joint ladder, per-mille of its\n// measured height. Painted landmarks were placed against an ASSUMED 171530 height; if the real\n// zmax differs, every band lands on the wrong body part (operator: nipples below the legs).\nif(REV&&window.__anat){const A=window.__anat;\ns9+=\" ANAT H\"+A.H+\" pelvis\"+A.pelvisJ+\" chestJ[\"+A.chestJ.join(\",\")+\"] head\"+A.headJ+\" NIP\"+A.nipP;}\nif(window.__party)s9+=\" | \"+window.__party;\nif(window.__perf)s9+=\" | \"+window.__perf;\nelse if(PERF&&window.__perfn)s9+=\" | PERF \"+window.__perfn+\"/\"+PERFN+\"...\";\nif(window.__rec)s9+=\" | \"+window.__rec;\nelse if(REC&&window.__recn)s9+=\" | REC \"+window.__recn+\"/\"+RECN+\"...\";\nhud.textContent=s9;}catch(e9){}},400);\nwindow.__sov={ex,blit};__sov.gl=!!GL;__sov.GL=GL;\n__sov.glpx=(x,y)=>{if(!GL)return null;const g=GL.g,b=new Uint8Array(4);g.readPixels(x,y,1,1,g.RGBA,g.UNSIGNED_BYTE,b);return[b[0],b[1],b[2]];};\nif(ex.save_build&&ex.save_apply&&ex.save_off){\n// persistence: this page moves save-image BYTES only; magic/version/checksum live in the wasm,\n// so a corrupt or stale localStorage entry is REFUSED by the organ, never half-applied.\nconst SK=\"nxsov_\"+location.pathname;\nconst b2s=b=>{let s=\"\";for(let i=0;i<b.length;i+=8192)s+=String.fromCharCode.apply(null,b.subarray(i,i+8192));return s;};\n__sov.save=()=>{const n=Number(ex.save_build());const m=new Uint8Array(ex.memory.buffer,Number(ex.save_off()),n);try{localStorage.setItem(SK,btoa(b2s(m)));return n;}catch(e){return -1;}};\n__sov.load=()=>{const d=localStorage.getItem(SK);if(!d)return -1;const r=atob(d);const m=new Uint8Array(ex.memory.buffer,Number(ex.save_off()),r.length);for(let i=0;i<r.length;i++)m[i]=r.charCodeAt(i);return Number(ex.save_apply());};\n__sov.wipe=()=>localStorage.removeItem(SK);\nif(__sov.load()===0)console.log(\"nishi: world restored\");\n// same rule as the passport above: the world save is armed on a beat but RUN in idle time, so a\n// multi-ms serialize can never be scheduled into the middle of a frame.\nconst _idle2=(f)=>window.requestIdleCallback?requestIdleCallback(f,{timeout:2000}):setTimeout(f,0);\nlet lastEd=-1;setInterval(()=>{if(!ex.broken)return;const ed=Number(ex.broken())+Number(ex.placed());if(ed!==lastEd){lastEd=ed;_idle2(()=>__sov.save());}},5000);\naddEventListener(\"pagehide\",()=>__sov.save());\n}\n" as *u8)
216 p = gpe_ap(out, p, "}).catch(e=>{document.body.innerHTML+=\"<pre style=\\\"color:#ff8f8f\\\">\"+e.message+\"</pre>\";});\n</script></body></html>" as *u8)
217 // the page-side compile lint runs on EVERY build -- a bad page returns NEGATIVE, which
218 // trips the caller's size floor and refuses the ship with the reason already on stderr
219 let vbad: i64 = gpe_verify(out, p)
220 if vbad > 0 { return 0 - vbad }
221 return p
222}
223func main(argc: i64, argv: *i64) -> i64 {
224 if argc < 6 {
225 let u: *u8 = "usage: nx_game_page_emit <wasm> <out.html> <title> <native> <controls-html>\n" as *u8
226 sys_write(2, u, gpe_slen(u))
227 return 2
228 }
229 let lp: *i64 = sys_mmap(16) as *i64
230 let wasm: *u8 = sys_read_file(argv[1] as *u8, lp)
231 let wn: i64 = lp[0]
232 if wn <= 8 { let m: *u8 = "nx_game_page_emit: wasm unreadable/empty\n" as *u8; sys_write(2, m, gpe_slen(m)); return 3 }
233 if wn > GPE_WASM_CAP { let m2: *u8 = "nx_game_page_emit: wasm exceeds cap\n" as *u8; sys_write(2, m2, gpe_slen(m2)); return 4 }
234 let out: *u8 = sys_mmap(GPE_OUT_CAP)
235 var vnum: i64 = 0
236 if argc > 6 {
237 let va: *u8 = argv[6] as *u8
238 vnum = (va[0] & 0xff) as i64 - 48
239 if vnum < 0 { vnum = 0 }
240 if vnum > 9 { vnum = 0 }
241 }
242 let n: i64 = gpe_build(wasm, wn, argv[3] as *u8, argv[4] as *u8, argv[5] as *u8, vnum, out)
243 let fd: i64 = sys_openat_wr(argv[2] as *u8, 0x1a4)
244 if fd < 0 { let m3: *u8 = "nx_game_page_emit: open out failed\n" as *u8; sys_write(2, m3, gpe_slen(m3)); return 5 }
245 var off: i64 = 0
246 while off < n {
247 let w: i64 = sys_write(fd, ((out as i64) + off) as *u8, n - off)
248 if w <= 0 { sys_close(fd); return 6 }
249 off = off + w
250 }
251 sys_close(fd)
252 let ok: *u8 = "PAGE-EMITTED bytes=" as *u8
253 sys_write(1, ok, gpe_slen(ok))
254 let d: *u8 = sys_mmap(32)
255 var v: i64 = n
256 var k: i64 = 0
257 while v > 0 { d[k] = (48 + (v % 10)) as u8; v = v / 10; k = k + 1 }
258 var j: i64 = 0
259 let t: *u8 = sys_mmap(32)
260 while j < k { t[j] = d[k - 1 - j]; j = j + 1 }
261 sys_write(1, t, k)
262 sys_write(1, "\n" as *u8, 1)
263 return 0
264}