three-live 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +4 -1
  2. package/dist/index.d.ts +191 -0
  3. package/dist/three-author-engine.js +179 -144
  4. package/dist/three-author.cjs +153 -144
  5. package/dist/three-author.d.ts +191 -0
  6. package/dist/three-author.js +153 -144
  7. package/dist/three-convert.cjs +150 -141
  8. package/dist/three-convert.d.ts +191 -0
  9. package/dist/three-convert.js +150 -141
  10. package/dist/three-live-ai.cjs +41 -0
  11. package/dist/three-live-ai.d.ts +759 -0
  12. package/dist/three-live-ai.js +41 -0
  13. package/dist/three-live-ai.min.js +41 -0
  14. package/dist/three-live-animation.cjs +6 -6
  15. package/dist/three-live-animation.d.ts +191 -0
  16. package/dist/three-live-animation.js +5 -5
  17. package/dist/three-live-animation.min.js +5 -5
  18. package/dist/three-live-cad.cjs +2 -2
  19. package/dist/three-live-cad.d.ts +191 -0
  20. package/dist/three-live-cad.js +2 -2
  21. package/dist/three-live-cad.min.js +2 -2
  22. package/dist/three-live-element.cjs +50 -85
  23. package/dist/three-live-element.d.ts +191 -0
  24. package/dist/three-live-element.js +50 -85
  25. package/dist/three-live-full.cjs +915 -170
  26. package/dist/three-live-full.js +917 -172
  27. package/dist/three-live-full.min.js +915 -170
  28. package/dist/three-live-procedural.cjs +16 -0
  29. package/dist/three-live-procedural.d.ts +759 -0
  30. package/dist/three-live-procedural.js +16 -0
  31. package/dist/three-live-procedural.min.js +16 -0
  32. package/dist/three-live-sandbox.html +11 -1
  33. package/dist/three-live-studio.cjs +72 -17
  34. package/dist/three-live-studio.d.ts +191 -0
  35. package/dist/three-live-studio.js +72 -17
  36. package/dist/three-live-studio.min.js +73 -18
  37. package/dist/three-live-tsl.cjs +103 -0
  38. package/dist/three-live-tsl.d.ts +759 -0
  39. package/dist/three-live-tsl.js +103 -0
  40. package/dist/three-live-tsl.min.js +103 -0
  41. package/dist/three-live-viewer.cjs +50 -85
  42. package/dist/three-live-viewer.d.ts +191 -0
  43. package/dist/three-live-viewer.js +50 -85
  44. package/dist/three-live-viewer.min.js +50 -85
  45. package/dist/three-live-webgpu.cjs +585 -0
  46. package/dist/three-live-webgpu.d.ts +759 -0
  47. package/dist/three-live-webgpu.js +585 -0
  48. package/dist/three-live-webgpu.min.js +585 -0
  49. package/dist/three-live.cjs +155 -146
  50. package/dist/three-live.js +155 -146
  51. package/dist/three-live.min.js +155 -146
  52. package/dist/three-view.cjs +49 -84
  53. package/dist/three-view.d.ts +191 -0
  54. package/dist/three-view.js +50 -85
  55. package/dist/three-xr.cjs +150 -141
  56. package/dist/three-xr.d.ts +191 -0
  57. package/dist/three-xr.js +150 -141
  58. package/package.json +39 -1
@@ -13,23 +13,23 @@
13
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
- */var se=Object.defineProperty,De=Object.getOwnPropertyDescriptor,je=Object.getOwnPropertyNames,Qe=Object.prototype.hasOwnProperty,Xe=(t,e)=>{for(var r in e)se(t,r,{get:e[r],enumerable:!0})},Je=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of je(e))!Qe.call(t,i)&&i!==r&&se(t,i,{get:()=>e[i],enumerable:!(o=De(e,i))||o.enumerable});return t},$e=t=>Je(se({},"__esModule",{value:!0}),t),un={};Xe(un,{IKSolver:()=>Be,crossFadeTo:()=>Ae,ikPlugin:()=>ye,keyframeAnimationPlugin:()=>Te,morphPlugin:()=>xe,parseAnimations:()=>ge,quatFromUnitVectors:()=>te,sampleChannel:()=>U,setMorphTargetWeight:()=>ze,skinningPlugin:()=>we,solveFABRIK:()=>de,solveTwoBoneIK:()=>fe}),module.exports=$e(un);var Z="__THREE_LIVE_REGISTRY__";function Q(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Z]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Z,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Z]=e}}return t[Z]}var mn=Q().plugins;function _e(t){let e=Q();e.workerExtensionInstallers||(e.workerExtensionInstallers=[]),e.workerExtensionInstallers.includes(t)||e.workerExtensionInstallers.push(t)}function X(t){let e=Q().plugins;e.some(r=>r.name===t.name)||e.push(t),t.onRegister?.()}function N(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function ie(t,e,r){let o=e[0],i=e[1],a=e[2],g=e[3],p=e[4],n=e[5],s=e[6],l=e[7],u=e[8],h=e[9],f=e[10],M=e[11],c=e[12],d=e[13],b=e[14],v=e[15],m=r[0],A=r[1],x=r[2],k=r[3];return t[0]=m*o+A*p+x*u+k*c,t[1]=m*i+A*n+x*h+k*d,t[2]=m*a+A*s+x*f+k*b,t[3]=m*g+A*l+x*M+k*v,m=r[4],A=r[5],x=r[6],k=r[7],t[4]=m*o+A*p+x*u+k*c,t[5]=m*i+A*n+x*h+k*d,t[6]=m*a+A*s+x*f+k*b,t[7]=m*g+A*l+x*M+k*v,m=r[8],A=r[9],x=r[10],k=r[11],t[8]=m*o+A*p+x*u+k*c,t[9]=m*i+A*n+x*h+k*d,t[10]=m*a+A*s+x*f+k*b,t[11]=m*g+A*l+x*M+k*v,m=r[12],A=r[13],x=r[14],k=r[15],t[12]=m*o+A*p+x*u+k*c,t[13]=m*i+A*n+x*h+k*d,t[14]=m*a+A*s+x*f+k*b,t[15]=m*g+A*l+x*M+k*v,t}function J(t,e,r,o){let i=e[0],a=e[1],g=e[2],p=e[3],n=i+i,s=a+a,l=g+g,u=i*n,h=i*s,f=i*l,M=a*s,c=a*l,d=g*l,b=p*n,v=p*s,m=p*l,A=o[0],x=o[1],k=o[2];return t[0]=(1-(M+d))*A,t[1]=(h+m)*A,t[2]=(f-v)*A,t[3]=0,t[4]=(h-m)*x,t[5]=(1-(u+d))*x,t[6]=(c+b)*x,t[7]=0,t[8]=(f+v)*k,t[9]=(c-b)*k,t[10]=(1-(u+M))*k,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function ee(t,e,r=0){let o=e[0],i=e[1],a=e[2],g=e[4],p=e[5],n=e[6],s=e[8],l=e[9],u=e[10],h=u*p-n*l,f=-u*g+n*s,M=l*g-p*s,c=o*h+i*f+a*M;return!c||r>0&&(!Number.isFinite(c)||Math.abs(c)<=r)||(c=1/c,t[0]=h*c,t[1]=f*c,t[2]=M*c,t[3]=(-u*i+a*l)*c,t[4]=(u*o-a*s)*c,t[5]=(-l*o+i*s)*c,t[6]=(n*i-a*p)*c,t[7]=(-n*o+a*g)*c,t[8]=(p*o-i*g)*c),t}function ke(t,e){let r=e[0],o=e[1],i=e[2],a=e[3],g=e[4],p=e[5],n=e[6],s=e[7],l=e[8],u=e[9],h=e[10],f=e[11],M=e[12],c=e[13],d=e[14],b=e[15],v=r*p-o*g,m=r*n-i*g,A=r*s-a*g,x=o*n-i*p,k=o*s-a*p,F=i*s-a*n,V=l*c-u*M,T=l*d-h*M,y=l*b-f*M,w=u*d-h*c,_=u*b-f*c,I=h*b-f*d,P=v*I-m*_+A*w+x*y-k*T+F*V;return P?(P=1/P,t[0]=(p*I-n*_+s*w)*P,t[1]=(i*_-o*I-a*w)*P,t[2]=(c*F-d*k+b*x)*P,t[3]=(h*k-u*F-f*x)*P,t[4]=(n*y-g*I-s*T)*P,t[5]=(r*I-i*y+a*T)*P,t[6]=(d*A-M*F-b*m)*P,t[7]=(l*F-h*A+f*m)*P,t[8]=(g*_-p*y+s*V)*P,t[9]=(o*y-r*_-a*V)*P,t[10]=(M*k-c*A+b*v)*P,t[11]=(u*A-l*k-f*v)*P,t[12]=(p*T-g*w-n*V)*P,t[13]=(r*w-o*T+i*V)*P,t[14]=(c*m-M*x-d*v)*P,t[15]=(l*x-u*m+h*v)*P,t):null}function Le(t,e){let r=Array.isArray(t?.nodes)?t.nodes.length:0,o=[];for(let l=0;l<r;l++)o.push(N());if(r===0)return o;let i=new Set;for(let l of t.nodes)if(Array.isArray(l.children))for(let u of l.children)i.add(u);let a=new Set,g=128,p=(l,u,h=0)=>{if(h>g||l<0||l>=r||a.has(l))return;a.add(l);let f=t.nodes[l];if(!f)return;let M=N();if(e&&e[l])M.set(e[l]);else if(f.matrix&&f.matrix.length===16)M.set(f.matrix);else{let d=f.translation||[0,0,0],b=f.rotation||[0,0,0,1],v=f.scale||[1,1,1];J(M,b,d,v)}let c=o[l];if(u?ie(c,u,M):c.set(M),Array.isArray(f.children))for(let d of f.children)typeof d=="number"&&p(d,c,h+1)},n=[],s=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(s&&Array.isArray(s.nodes))n.push(...s.nodes);else for(let l=0;l<r;l++)i.has(l)||n.push(l);for(let l of n)p(l,null);for(let l=0;l<r;l++)!i.has(l)&&!n.includes(l)&&p(l,null);return o}function ue(t,e){function r(n,s,l,u){let h=typeof n=="number"?n:Number(n);return Number.isFinite(h)?Math.max(s,Math.min(l,h)):u}function o(n,s){let l=n[0]*s[0]+n[1]*s[1]+n[2]*s[2]+1;if(l<1e-6){if(Math.abs(n[0])>Math.abs(n[2])){let d=Math.hypot(n[1],n[0])||1;return[-n[1]/d,n[0]/d,0,0]}let c=Math.hypot(n[2],n[1])||1;return[0,-n[2]/c,n[1]/c,0]}let u=n[1]*s[2]-n[2]*s[1],h=n[2]*s[0]-n[0]*s[2],f=n[0]*s[1]-n[1]*s[0],M=Math.hypot(u,h,f,l)||1;return[u/M,h/M,f/M,l/M]}function i(n,s,l,u,h){let f=s[0]-n[0],M=s[1]-n[1],c=s[2]-n[2],d=Math.hypot(f,M,c),b=l[0]-s[0],v=l[1]-s[1],m=l[2]-s[2],A=Math.hypot(b,v,m);if(d<1e-6||A<1e-6)return{rootPos:[n[0],n[1],n[2]],midPos:[s[0],s[1],s[2]],effectorPos:[l[0],l[1],l[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let x=[f/d,M/d,c/d],k=[b/A,v/A,m/A],F=u[0]-n[0],V=u[1]-n[1],T=u[2]-n[2],y=Math.hypot(F,V,T),w=y>1e-6?[F/y,V/y,T/y]:x,_=Math.abs(d-A)+1e-5,I=Math.max(_,d+A-1e-5),P=Math.max(_,Math.min(I,y>1e-6?y:_)),S=r((d*d+P*P-A*A)/(2*d*P),-1,1,1),R=Math.sqrt(Math.max(0,1-S*S)),E=h?h[0]-n[0]:f,j=h?h[1]-n[1]:M,C=h?h[2]-n[2]:c,K=E*w[0]+j*w[1]+C*w[2],B=E-w[0]*K,W=j-w[1]*K,L=C-w[2]*K,q=Math.hypot(B,W,L);if(q<=1e-6){let nt=Math.abs(w[1])<.99?0:1,at=Math.abs(w[1])<.99?1:0,lt=0;B=w[1]*lt-w[2]*at,W=w[2]*nt-w[0]*lt,L=w[0]*at-w[1]*nt,q=Math.hypot(B,W,L)||1}let tt=[B/q,W/q,L/q],D=[n[0]+w[0]*(d*S)+tt[0]*(d*R),n[1]+w[1]*(d*S)+tt[1]*(d*R),n[2]+w[2]*(d*S)+tt[2]*(d*R)],et=[n[0]+w[0]*P,n[1]+w[1]*P,n[2]+w[2]*P],rt=et[0]-D[0],it=et[1]-D[1],ot=et[2]-D[2],z=Math.hypot(rt,it,ot),Y=z>1e-6?[rt/z,it/z,ot/z]:w,st=[D[0]+Y[0]*A,D[1]+Y[1]*A,D[2]+Y[2]*A],ft=[(D[0]-n[0])/d,(D[1]-n[1])/d,(D[2]-n[2])/d];return{rootPos:[n[0],n[1],n[2]],midPos:D,effectorPos:st,rootRotation:o(x,ft),midRotation:o(k,Y)}}function a(n,s,l=8,u=.001){let h=n.length;if(h<2)return{positions:n.map(y=>[y[0],y[1],y[2]]),rotations:[],iterations:0};let f=n.map(y=>[y[0],y[1],y[2]]),M=[],c=[],d=0;for(let y=0;y<h-1;y++){let w=f[y+1][0]-f[y][0],_=f[y+1][1]-f[y][1],I=f[y+1][2]-f[y][2],P=Math.hypot(w,_,I);M.push(P),d+=P,c.push(P>1e-6?[w/P,_/P,I/P]:[0,1,0])}let b=[f[0][0],f[0][1],f[0][2]],v=Math.round(r(l,1,32,8)),m=r(u,1e-5,.1,.001),A=s[0]-b[0],x=s[1]-b[1],k=s[2]-b[2],F=Math.hypot(A,x,k),V=0;if(F>=d&&d>1e-6){let y=F>1e-6?[A/F,x/F,k/F]:c[0];f[0]=[b[0],b[1],b[2]];for(let w=0;w<h-1;w++){let _=M[w];f[w+1]=[f[w][0]+y[0]*_,f[w][1]+y[1]*_,f[w][2]+y[2]*_]}V=1}else for(let y=1;y<=v;y++){let w=f[h-1];if(Math.hypot(w[0]-s[0],w[1]-s[1],w[2]-s[2])<=m)break;V=y;let _=(I,P,S,R,E)=>{let j=P[0]-I[0],C=P[1]-I[1],K=P[2]-I[2],B=Math.hypot(j,C,K);if(B>1e-6){let W=S/B;return[I[0]+j*W,I[1]+C*W,I[2]+K*W]}return[I[0]+R[0]*S*E,I[1]+R[1]*S*E,I[2]+R[2]*S*E]};f[h-1]=[s[0],s[1],s[2]];for(let I=h-2;I>=0;I--)f[I]=_(f[I+1],f[I],M[I],c[I],-1);f[0]=[b[0],b[1],b[2]];for(let I=0;I<h-1;I++)f[I+1]=_(f[I],f[I+1],M[I],c[I],1)}let T=[];for(let y=0;y<h-1;y++){let w=f[y+1][0]-f[y][0],_=f[y+1][1]-f[y][1],I=f[y+1][2]-f[y][2],P=Math.hypot(w,_,I),S=P>1e-6?[w/P,_/P,I/P]:c[y];T.push(o(c[y],S))}return{positions:f,rotations:T,iterations:V}}function g(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let s=n;if(s.enabled===!1)return null;let l=m=>{if(typeof m!="string")return;let A=m.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(A)?A:void 0},u=m=>Array.isArray(m)&&m.length===3&&m.every(A=>typeof A=="number"&&Number.isFinite(A))?[r(m[0],-1e3,1e3,0),r(m[1],-1e3,1e3,0),r(m[2],-1e3,1e3,0)]:void 0,h=l(s.root),f=l(s.effector);if(!h||!f)return null;let M=l(s.mid),c=u(s.target)??l(s.target);if(!c)return null;let d=s.pole??s.poleTarget,b=u(d)??l(d),v=s.solver==="fabrik"?"fabrik":s.solver==="two-bone"||M?"two-bone":"fabrik";return{root:h,...M?{mid:M}:{},effector:f,target:c,...b?{pole:b}:{},solver:v,iterations:Math.round(r(s.iterations,1,32,8)),tolerance:r(s.tolerance,1e-5,.1,.001),weight:r(s.weight,0,1,1)}}let p=Object.freeze({solveTwoBone:i,solveFABRIK:a,parseIKTrait:g});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=p),{clampNum:r,parseIKTrait:g,quatFromUnitVectors:o,solveTwoBoneIK:i,solveFABRIK:a,IKSolver:p}}var G=ue(),Ne=G.clampNum,He=G.parseIKTrait,te=G.quatFromUnitVectors,fe=G.solveTwoBoneIK,de=G.solveFABRIK,Be=G.IKSolver;function le(t){let e=t?.transform??t?.modelMatrix;return e&&e.length>=16?[e[12]||0,e[13]||0,e[14]||0]:[0,0,0]}function qe(t,e){let r=t?.transform??t?.modelMatrix;!r||r.length<16||(r[12]=e[0],r[13]=e[1],r[14]=e[2])}function Ye(t,e,r,o,i){let a=Ne(i,0,1,1),g=e[0]+(r[0]-e[0])*a,p=e[1]+(r[1]-e[1])*a,n=e[2]+(r[2]-e[2])*a,s=g-t[0],l=p-t[1],u=n-t[2],h=Math.hypot(s,l,u);if(h>1e-6&&o>1e-6){let b=o/h;return[t[0]+s*b,t[1]+l*b,t[2]+u*b]}let f=r[0]-t[0],M=r[1]-t[1],c=r[2]-t[2],d=Math.hypot(f,M,c);if(d>1e-6&&o>1e-6){let b=o/d;return[t[0]+f*b,t[1]+M*b,t[2]+c*b]}return[g,p,n]}function Ze(t,e){let r=t?.modelRootMatrix;if(!r||r.length!==16)return e;let o=new Float32Array(16);return ke(o,r instanceof Float32Array?r:Float32Array.from(r))?[o[0]*e[0]+o[4]*e[1]+o[8]*e[2]+o[12],o[1]*e[0]+o[5]*e[1]+o[9]*e[2]+o[13],o[2]*e[0]+o[6]*e[1]+o[10]*e[2]+o[14]]:e}function ae(t,e){t.__ikWarned||(t.__ikWarned=new Set);let r=t.__ikWarned;r.has(e)||(r.add(e),console.warn(`[three-live] ik: joint '${e}' on '${t?.name??""}' not found among scene nodes or meshes.`))}function me(t,e,r){if(Array.isArray(t))return[t[0],t[1],t[2]];let o=e.get(t);if(o)return le(o);let i;if(t==="head"?i=r?.headPose?.position??r?.headPose??r?.cameraPosition:t==="hand-left"?i=r?.handPoses?.left?.position??r?.handPoses?.left??r?.hands?.left?.position??r?.hands?.left:t==="hand-right"&&(i=r?.handPoses?.right?.position??r?.handPoses?.right??r?.hands?.right?.position??r?.hands?.right),(Array.isArray(i)||ArrayBuffer.isView(i))&&i.length>=3){let a=i;return Ze(r,[a[0],a[1],a[2]])}return null}function ce(t,e){return[t[3]*e[0]+t[0]*e[3]+t[1]*e[2]-t[2]*e[1],t[3]*e[1]-t[0]*e[2]+t[1]*e[3]+t[2]*e[0],t[3]*e[2]+t[0]*e[1]-t[1]*e[0]+t[2]*e[3],t[3]*e[3]-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]}function en(t){return[-t[0],-t[1],-t[2],t[3]]}function he(t){let e=Math.hypot(t[0],t[1],t[2],t[3]);return e>1e-12?[t[0]/e,t[1]/e,t[2]/e,t[3]/e]:[0,0,0,1]}function nn(t,e){if(e>=1)return t;if(e<=0)return[0,0,0,1];let[r,o,i,a]=t;a<0&&(r=-r,o=-o,i=-i,a=-a);let g=Math.acos(Math.min(1,a)),p=Math.sin(g);if(p<1e-9)return[0,0,0,1];let n=Math.sin(g*e)/p;return he([r*n,o*n,i*n,Math.cos(g*e)])}function tn(t){let e=Math.hypot(t[0],t[1],t[2])||1,r=Math.hypot(t[4],t[5],t[6])||1,o=Math.hypot(t[8],t[9],t[10])||1,i=t[0]/e,a=t[1]/e,g=t[2]/e,p=t[4]/r,n=t[5]/r,s=t[6]/r,l=t[8]/o,u=t[9]/o,h=t[10]/o,f=i+n+h,M;if(f>0){let c=Math.sqrt(f+1)*2;M=[(s-u)/c,(l-g)/c,(a-p)/c,.25*c]}else if(i>n&&i>h){let c=Math.sqrt(1+i-n-h)*2;M=[.25*c,(p+a)/c,(l+g)/c,(s-u)/c]}else if(n>h){let c=Math.sqrt(1+n-i-h)*2;M=[(p+a)/c,.25*c,(u+s)/c,(l-g)/c]}else{let c=Math.sqrt(1+h-i-n)*2;M=[(l+g)/c,(u+s)/c,.25*c,(a-p)/c]}return he(M)}function rn(t,e,r){let[o,i,a,g]=r,p=1-2*(i*i+a*a),n=2*(o*i-a*g),s=2*(o*a+i*g),l=2*(o*i+a*g),u=1-2*(o*o+a*a),h=2*(i*a-o*g),f=2*(o*a-i*g),M=2*(i*a+o*g),c=1-2*(o*o+i*i);for(let d=0;d<3;d++){let b=e[d*4],v=e[d*4+1],m=e[d*4+2];t[d*4]=p*b+n*v+s*m,t[d*4+1]=l*b+u*v+h*m,t[d*4+2]=f*b+M*v+c*m}}function ne(t,e){let r=e[0]-t[0],o=e[1]-t[1],i=e[2]-t[2],a=Math.hypot(r,o,i);return a>1e-9?[r/a,o/a,i/a]:null}function Ce(t){t?.normalMatrix&&t?.transform&&ee(t.normalMatrix,t.transform)}var Ee=new WeakMap;function on(t){let e=Ee.get(t);return e||(e=new Int32Array(t.nodes.length).fill(-1),t.nodes.forEach((r,o)=>{for(let i of Array.isArray(r?.children)?r.children:[])typeof i=="number"&&i>=0&&i<e.length&&(e[i]=o)}),Ee.set(t,e)),e}function sn(t,e,r){let o=t?.gltf,i=o?.nodes;if(!Array.isArray(i)||i.length===0)return!1;let a=new Map;i.forEach((T,y)=>{typeof T?.name=="string"&&T.name&&!a.has(T.name)&&a.set(T.name,y)});let g=(e.mid?[e.root,e.mid,e.effector]:[e.root,e.effector]).map(T=>a.get(T));if(g.some(T=>T===void 0))return!1;let p=g,n=on(o);for(let T=1;T<p.length;T++){let y=n[p[T]],w=0;for(;y>=0&&y!==p[T-1]&&w++<256;)y=n[y];if(y!==p[T-1])return!1}let s=p[0],l=t.initialNodeTransforms,u=new Map,h=[],f=[s];for(;f.length&&h.length<4096;){let T=f.pop();if(u.has(T))continue;let y=l?.[T],w=i[T];u.set(T,{t:y?[y.t[0],y.t[1],y.t[2]]:w?.translation?[...w.translation]:[0,0,0],r:y?[y.r[0],y.r[1],y.r[2],y.r[3]]:w?.rotation?[...w.rotation]:[0,0,0,1],s:y?[y.s[0],y.s[1],y.s[2]]:w?.scale?[...w.scale]:[1,1,1]}),h.push(T);for(let _ of Array.isArray(w?.children)?w.children:[])typeof _=="number"&&f.push(_)}let M=n[s],c=M>=0&&t.worldMatrices?.[M]?.length===16?Float32Array.from(t.worldMatrices[M]):N(),d=new Map,b=()=>{let T=(y,w)=>{let _=u.get(y);if(!_)return;let I=N();J(I,_.r,_.t,_.s);let P=N();ie(P,w,I),d.set(y,P);for(let S of Array.isArray(i[y]?.children)?i[y].children:[])typeof S=="number"&&T(S,P)};T(s,c)},v=T=>{let y=d.get(T);return[y[12],y[13],y[14]]};b();let m=p.map(v),A=T=>{if(typeof T=="string"&&!r.has(T)){let y=a.get(T),w=y!==void 0?d.get(y)??t.worldMatrices?.[y]:void 0;if(w&&w.length===16)return[w[12],w[13],w[14]]}return me(T,r,t)},x=A(e.target);if(!x)return!0;let k=e.pole?A(e.pole)??void 0:void 0,F=Pe(m,e,x,k),V=Ne(e.weight,0,1,1);for(let T=0;T<p.length-1;T++){let y=ne(v(p[T]),v(p[T+1])),w=ne(F[T],F[T+1]);if(!y||!w)continue;let _=nn(te(y,w),V),I=p[T],P=n[I],S=P===M||P<0?c:d.get(P)??c,R=tn(S),E=u.get(I);E.r=he(ce(en(R),ce(_,ce(R,E.r)))),b()}if(Array.isArray(t.worldMatrices))for(let[T,y]of d)t.worldMatrices[T]?.set&&t.worldMatrices[T].set(y);for(let T of t.meshes??[]){let y=d.get(T?.nodeIndex);y&&T.transform?.set&&(T.transform.set(y),Ce(T))}return!0}function Pe(t,e,r,o){if(e.solver==="two-bone"&&t.length===3){let i=fe(t[0],t[1],t[2],r,o);return[t[0],i.midPos,i.effectorPos]}return de(t,r,e.iterations,e.tolerance).positions}function an(t,e,r){let o=t.__ikRestOffsets,i=t.__ikRestMats;if(!(!o||!i))for(let a=0;a<e.length-1;a++){let g=e[a]?.transform??e[a]?.modelMatrix,p=i[a],n=ne([0,0,0],o[a]),s=ne(r[a],r[a+1]);!g||g.length<16||!p||p.length<16||!n||!s||(rn(g,p,te(n,s)),Ce(e[a]))}}var ye={name:"ik",onRegister(){let t=Q();_e(ue),ue(t.threeNamespace,t)},onUpdate(t){let e=t?.meshes;if(!Array.isArray(e)||e.length===0)return;let r=null;for(let o of e){let i=o?.userData?.xr?.ik??o?.extras?.xr?.ik??o?.extensions?.ANDROID_xr_scenecore?.ik;if(!i)continue;let a=He(i);if(!a||a.weight<=0)continue;if(!r){r=new Map;for(let m of e)m&&typeof m.name=="string"&&m.name&&r.set(m.name,m)}if(sn(t,a,r))continue;let g=r.get(a.root),p=r.get(a.effector),n=a.mid?r.get(a.mid):void 0;if(g||ae(o,a.root),p||ae(o,a.effector),a.mid&&!n&&ae(o,a.mid),!g||!p)continue;let s=me(a.target,r,t);if(!s)continue;let l=a.pole?me(a.pole,r,t)??void 0:void 0,u=n?[g,n,p]:[g,p],h=u.map(m=>m.name||"").join(">");if(!o.__ikRestOffsets||o.__ikRestKey!==h){let m=u.map(le),A=[];for(let x=0;x<m.length-1;x++)A.push([m[x+1][0]-m[x][0],m[x+1][1]-m[x][1],m[x+1][2]-m[x][2]]);o.__ikRestOffsets=A,o.__ikRestKey=h,o.__ikRestMats=u.map(x=>Array.from(x.transform??x.modelMatrix??[]))}let f=o.__ikRestOffsets,M=[le(g)],c=[];for(let m=0;m<f.length;m++){let A=M[m],x=f[m];M.push([A[0]+x[0],A[1]+x[1],A[2]+x[2]]),c.push(Math.hypot(x[0],x[1],x[2]))}let d=Pe(M,a,s,l),b=M[0],v=[M[0]];for(let m=1;m<u.length;m++){let A=f[m-1],x=[b[0]+A[0],b[1]+A[1],b[2]+A[2]],k=[b[0]+(d[m][0]-d[m-1][0]),b[1]+(d[m][1]-d[m-1][1]),b[2]+(d[m][2]-d[m-1][2])],F=Ye(b,x,k,c[m-1],a.weight);qe(u[m],F),b=F,v.push(F)}an(o,u,v)}}},cn={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function O(t,e,r,o){if(!r||r.bufferView===void 0)return null;let i=t.bufferViews?.[r.bufferView];if(!i)return null;let a=Number(r.count??0);if(!Number.isInteger(a)||a<=0)return null;let g=r.componentType??5126,p=cn[g];if(!p)throw new RangeError(`glTF accessor has unsupported componentType ${g}`);let n=p*o,s=i.byteStride&&i.byteStride>0?i.byteStride:n,l=(i.byteOffset||0)+(r.byteOffset||0);if(!Number.isInteger(l)||l<0||s<n||l+(a-1)*s+n>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(g===5126&&s===n&&l%4===0)return new Float32Array(e,l,a*o);let u=new DataView(e),h=r.normalized===!0,f=new Float32Array(a*o);for(let M=0;M<a;M++){let c=l+M*s;for(let d=0;d<o;d++){let b=c+d*p,v;switch(g){case 5126:v=u.getFloat32(b,!0);break;case 5120:v=u.getInt8(b),h&&(v=Math.max(v/127,-1));break;case 5121:v=u.getUint8(b),h&&(v/=255);break;case 5122:v=u.getInt16(b,!0),h&&(v=Math.max(v/32767,-1));break;case 5123:v=u.getUint16(b,!0),h&&(v/=65535);break;default:v=u.getUint32(b,!0),h&&(v/=4294967295)}f[M*o+d]=v}}return f}function We(t,e,r){return e%4===0?new Float32Array(t,e,r):new Float32Array(t.slice(e,e+r*4))}function Oe(t,e,r,o){let i=e[0],a=e[1],g=e[2],p=e[3],n=r[0],s=r[1],l=r[2],u=r[3],h=i*n+a*s+g*l+p*u;if(h<0&&(n=-n,s=-s,l=-l,u=-u,h=-h),Math.abs(h)>=1)return t[0]=i,t[1]=a,t[2]=g,t[3]=p,t;let f=Math.acos(h),M=Math.sqrt(1-h*h);if(Math.abs(M)<.001)return t[0]=.5*(i+n),t[1]=.5*(a+s),t[2]=.5*(g+l),t[3]=.5*(p+u),t;let c=Math.sin((1-o)*f)/M,d=Math.sin(o*f)/M;return t[0]=i*c+n*d,t[1]=a*c+s*d,t[2]=g*c+l*d,t[3]=p*c+u*d,t}function Ke(t,e,r,o){return t[0]=e[0]+o*(r[0]-e[0]),t[1]=e[1]+o*(r[1]-e[1]),t[2]=e[2]+o*(r[2]-e[2]),t}function ge(t,e){if(!Array.isArray(t?.animations))return[];let r=[];for(let o=0;o<t.animations.length;o++){let i=t.animations[o],a=i.name||`Animation_${o}`,g=[],p=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let n of i.channels){if(!n.target||n.target.node===void 0||!n.target.path)continue;let s=i.samplers[n.sampler];if(!s)continue;let l=t.accessors?.[s.input],u=t.accessors?.[s.output];if(!l||!u)continue;let h=t.bufferViews?.[l.bufferView],f=t.bufferViews?.[u.bufferView];if(!h||!f)continue;let M=(h.byteOffset||0)+(l.byteOffset||0),c=(f.byteOffset||0)+(u.byteOffset||0),d=O(t,e,l,1)??We(e,M,l.count);d.length>0&&d[d.length-1]>p&&(p=d[d.length-1]);let b=n.target.path==="rotation"?4:n.target.path==="weights"?Math.max(1,Math.round(u.count/Math.max(1,l.count))):3,v=n.target.path==="weights"?1:b,m=O(t,e,u,v)??We(e,c,u.count*v),A=s.interpolation==="STEP"?"STEP":"LINEAR";g.push({nodeIndex:n.target.node,path:n.target.path,times:d,values:m,interpolation:A})}g.length>0&&r.push({name:a,duration:p,channels:g})}return r}function U(t,e,r){let{times:o,values:i,path:a,interpolation:g}=t,p=o.length;if(p===0)return;let n=a==="rotation"?4:a==="weights"?Math.max(1,Math.round(i.length/p)):3;if(e<=o[0]){for(let v=0;v<n;v++)r[v]=i[v];return}if(e>=o[p-1]){let v=(p-1)*n;for(let m=0;m<n;m++)r[m]=i[v+m];return}let s=0,l=p-1;for(;s<=l;){let v=s+l>>1;o[v]<=e?s=v+1:l=v-1}let u=Math.max(0,l),h=Math.min(p-1,u+1);if(g==="STEP"||u===h){let v=u*n;for(let m=0;m<n;m++)r[m]=i[v+m];return}let f=o[u],M=o[h],c=(e-f)/Math.max(1e-5,M-f),d=u*n,b=h*n;if(a==="rotation"){let v=[i[d],i[d+1],i[d+2],i[d+3]],m=[i[b],i[b+1],i[b+2],i[b+3]];Oe(r,v,m,c)}else for(let v=0;v<n;v++)r[v]=i[d+v]+c*(i[b+v]-i[d+v])}var $=new WeakMap;function Ae(t,e,r=.3){if(!t?.animations)return;let o=t.animations.find(p=>p.name===e);if(!o)return;let i=$.get(t);i||(i=[],t.currentClip&&i.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),$.set(t,i));let a=r>0?1/r:1e3;for(let p of i)p.clip.name!==e&&(p.fadeSpeed=-a);let g=i.find(p=>p.clip.name===e);g?g.fadeSpeed=a:i.push({clip:o,time:0,weight:r>0?0:1,fadeSpeed:a}),t.currentClip=o,t.isPlayingAnimation=!0}function pe(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let r=$.get(t);if(!r||r.length===0){if(!t.currentClip)return;r=[{clip:t.currentClip,time:e,weight:1,fadeSpeed:0}]}let o=t.gltf.nodes.length,i=[];for(let u=0;u<o;u++){let h=t.initialNodeTransforms[u];h?i.push({t:[h.t[0],h.t[1],h.t[2]],r:[h.r[0],h.r[1],h.r[2],h.r[3]],s:[h.s[0],h.s[1],h.s[2]]}):i.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let a=[0,0,0],g=[0,0,0,1],p=[1,1,1],n=new Float32Array(64);for(let u of r){let h=Math.max(0,Math.min(1,u.weight));if(!(h<=1e-4))for(let f of u.clip.channels){if(f.nodeIndex<0||f.nodeIndex>=o)continue;let M=i[f.nodeIndex];if(f.path==="translation")U(f,u.time,a),Ke(M.t,M.t,a,h);else if(f.path==="rotation")U(f,u.time,g),Oe(M.r,M.r,g,h);else if(f.path==="scale")U(f,u.time,p),Ke(M.s,M.s,p,h);else if(f.path==="weights"&&(U(f,u.time,n),t.meshes)){for(let c of t.meshes)if(c.nodeIndex===f.nodeIndex){for(let d of c.primitives)if(d.pluginData?.morph?.weights){let b=d.pluginData.morph.weights,v=d.pluginData.morph.numTargets||b.length;for(let m=0;m<v;m++)b[m]=b[m]*(1-h)+n[m]*h}}}}}let s=[];for(let u=0;u<o;u++){let h=N(),{t:f,r:M,s:c}=i[u];J(h,M,f,c),s.push(h)}let l=Le(t.gltf,s);t.worldMatrices=l;for(let u of t.meshes)u.nodeIndex>=0&&u.nodeIndex<l.length&&(u.transform.set(l[u.nodeIndex]),ee(u.normalMatrix,u.transform))}var be=t=>{$.delete(t)},Te={name:"keyframes",evaluateAnimation:pe,crossFadeTo:Ae,onParseGLB(t){!t.animations&&t.gltf?.animations&&(t.animations=ge(t.gltf,t.bin))},onLoadModel:be,onClearScene:be,onDestroy:(t,e)=>be(e),onUpdate(t,e){if(!t.isPlayingAnimation)return;let r=$.get(t);if(r&&r.length>0){for(let o=r.length-1;o>=0;o--){let i=r[o];if(i.time+=e,i.clip.duration>0&&(i.time%=i.clip.duration),i.fadeSpeed!==0)if(i.weight+=i.fadeSpeed*e,i.weight<=0){r.splice(o,1);continue}else i.weight>=1&&(i.weight=1,i.fadeSpeed=0)}r.length>0&&(t.animationTime=r[r.length-1].time),pe(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),pe(t,t.animationTime))}},H=64;function ze(t,e,r){if(!(!t?.meshes||e<0||e>=H))for(let o of t.meshes)for(let i of o.primitives){let a=i.pluginData?.morph;a?.weights&&(a.weights[e]=r)}}var xe={name:"morph",onResolveShader(t,e,r,o){if(!Array.isArray(t?.targets)||t.targets.length===0)return null;let i=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
16
+ */var ae=Object.defineProperty,De=Object.getOwnPropertyDescriptor,je=Object.getOwnPropertyNames,Qe=Object.prototype.hasOwnProperty,Xe=(t,e)=>{for(var r in e)ae(t,r,{get:e[r],enumerable:!0})},Je=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of je(e))!Qe.call(t,i)&&i!==r&&ae(t,i,{get:()=>e[i],enumerable:!(o=De(e,i))||o.enumerable});return t},He=t=>Je(ae({},"__esModule",{value:!0}),t),ln={};Xe(ln,{IKSolver:()=>Ce,crossFadeTo:()=>Ae,ikPlugin:()=>pe,keyframeAnimationPlugin:()=>Te,morphPlugin:()=>xe,parseAnimations:()=>ge,quatFromUnitVectors:()=>te,sampleChannel:()=>K,setMorphTargetWeight:()=>Oe,skinningPlugin:()=>Me,solveFABRIK:()=>de,solveTwoBoneIK:()=>fe}),module.exports=He(ln);var Z="__THREE_LIVE_REGISTRY__";function Q(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Z]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Z,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Z]=e}}return t[Z]}var mn=Q().plugins;function ke(t){let e=Q();e.workerExtensionInstallers||(e.workerExtensionInstallers=[]),e.workerExtensionInstallers.includes(t)||e.workerExtensionInstallers.push(t)}function X(t){let e=Q().plugins;e.some(r=>r.name===t.name)||e.push(t),t.onRegister?.()}function P(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function ie(t,e,r){let o=e[0],i=e[1],a=e[2],g=e[3],d=e[4],n=e[5],s=e[6],l=e[7],u=e[8],h=e[9],f=e[10],M=e[11],c=e[12],p=e[13],w=e[14],b=e[15],m=r[0],A=r[1],x=r[2],_=r[3];return t[0]=m*o+A*d+x*u+_*c,t[1]=m*i+A*n+x*h+_*p,t[2]=m*a+A*s+x*f+_*w,t[3]=m*g+A*l+x*M+_*b,m=r[4],A=r[5],x=r[6],_=r[7],t[4]=m*o+A*d+x*u+_*c,t[5]=m*i+A*n+x*h+_*p,t[6]=m*a+A*s+x*f+_*w,t[7]=m*g+A*l+x*M+_*b,m=r[8],A=r[9],x=r[10],_=r[11],t[8]=m*o+A*d+x*u+_*c,t[9]=m*i+A*n+x*h+_*p,t[10]=m*a+A*s+x*f+_*w,t[11]=m*g+A*l+x*M+_*b,m=r[12],A=r[13],x=r[14],_=r[15],t[12]=m*o+A*d+x*u+_*c,t[13]=m*i+A*n+x*h+_*p,t[14]=m*a+A*s+x*f+_*w,t[15]=m*g+A*l+x*M+_*b,t}function J(t,e,r,o){let i=e[0],a=e[1],g=e[2],d=e[3],n=i+i,s=a+a,l=g+g,u=i*n,h=i*s,f=i*l,M=a*s,c=a*l,p=g*l,w=d*n,b=d*s,m=d*l,A=o[0],x=o[1],_=o[2];return t[0]=(1-(M+p))*A,t[1]=(h+m)*A,t[2]=(f-b)*A,t[3]=0,t[4]=(h-m)*x,t[5]=(1-(u+p))*x,t[6]=(c+w)*x,t[7]=0,t[8]=(f+b)*_,t[9]=(c-w)*_,t[10]=(1-(u+M))*_,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function ee(t,e,r=0){let o=e[0],i=e[1],a=e[2],g=e[4],d=e[5],n=e[6],s=e[8],l=e[9],u=e[10],h=u*d-n*l,f=-u*g+n*s,M=l*g-d*s,c=o*h+i*f+a*M;return!c||r>0&&(!Number.isFinite(c)||Math.abs(c)<=r)||(c=1/c,t[0]=h*c,t[1]=f*c,t[2]=M*c,t[3]=(-u*i+a*l)*c,t[4]=(u*o-a*s)*c,t[5]=(-l*o+i*s)*c,t[6]=(n*i-a*d)*c,t[7]=(-n*o+a*g)*c,t[8]=(d*o-i*g)*c),t}function Le(t,e){let r=e[0],o=e[1],i=e[2],a=e[3],g=e[4],d=e[5],n=e[6],s=e[7],l=e[8],u=e[9],h=e[10],f=e[11],M=e[12],c=e[13],p=e[14],w=e[15],b=r*d-o*g,m=r*n-i*g,A=r*s-a*g,x=o*n-i*d,_=o*s-a*d,F=i*s-a*n,O=l*c-u*M,T=l*p-h*M,y=l*w-f*M,v=u*p-h*c,S=u*w-f*c,k=h*w-f*p,I=b*k-m*S+A*v+x*y-_*T+F*O;return I?(I=1/I,t[0]=(d*k-n*S+s*v)*I,t[1]=(i*S-o*k-a*v)*I,t[2]=(c*F-p*_+w*x)*I,t[3]=(h*_-u*F-f*x)*I,t[4]=(n*y-g*k-s*T)*I,t[5]=(r*k-i*y+a*T)*I,t[6]=(p*A-M*F-w*m)*I,t[7]=(l*F-h*A+f*m)*I,t[8]=(g*S-d*y+s*O)*I,t[9]=(o*y-r*S-a*O)*I,t[10]=(M*_-c*A+w*b)*I,t[11]=(u*A-l*_-f*b)*I,t[12]=(d*T-g*v-n*O)*I,t[13]=(r*v-o*T+i*O)*I,t[14]=(c*m-M*x-p*b)*I,t[15]=(l*x-u*m+h*b)*I,t):null}function _e(t,e){let r=Array.isArray(t?.nodes)?t.nodes.length:0,o=[];for(let l=0;l<r;l++)o.push(P());if(r===0)return o;let i=new Set;for(let l of t.nodes)if(Array.isArray(l.children))for(let u of l.children)i.add(u);let a=new Set,g=128,d=(l,u,h=0)=>{if(h>g||l<0||l>=r||a.has(l))return;a.add(l);let f=t.nodes[l];if(!f)return;let M=P();if(e&&e[l])M.set(e[l]);else if(f.matrix&&f.matrix.length===16)M.set(f.matrix);else{let p=f.translation||[0,0,0],w=f.rotation||[0,0,0,1],b=f.scale||[1,1,1];J(M,w,p,b)}let c=o[l];if(u?ie(c,u,M):c.set(M),Array.isArray(f.children))for(let p of f.children)typeof p=="number"&&d(p,c,h+1)},n=[],s=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(s&&Array.isArray(s.nodes))n.push(...s.nodes);else for(let l=0;l<r;l++)i.has(l)||n.push(l);for(let l of n)d(l,null);for(let l=0;l<r;l++)!i.has(l)&&!n.includes(l)&&d(l,null);return o}function le(t,e){function r(n,s,l,u){let h=typeof n=="number"?n:Number(n);return Number.isFinite(h)?Math.max(s,Math.min(l,h)):u}function o(n,s){let l=n[0]*s[0]+n[1]*s[1]+n[2]*s[2]+1;if(l<1e-6){if(Math.abs(n[0])>Math.abs(n[2])){let p=Math.hypot(n[1],n[0])||1;return[-n[1]/p,n[0]/p,0,0]}let c=Math.hypot(n[2],n[1])||1;return[0,-n[2]/c,n[1]/c,0]}let u=n[1]*s[2]-n[2]*s[1],h=n[2]*s[0]-n[0]*s[2],f=n[0]*s[1]-n[1]*s[0],M=Math.hypot(u,h,f,l)||1;return[u/M,h/M,f/M,l/M]}function i(n,s,l,u,h){let f=s[0]-n[0],M=s[1]-n[1],c=s[2]-n[2],p=Math.hypot(f,M,c),w=l[0]-s[0],b=l[1]-s[1],m=l[2]-s[2],A=Math.hypot(w,b,m);if(p<1e-6||A<1e-6)return{rootPos:[n[0],n[1],n[2]],midPos:[s[0],s[1],s[2]],effectorPos:[l[0],l[1],l[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let x=[f/p,M/p,c/p],_=[w/A,b/A,m/A],F=u[0]-n[0],O=u[1]-n[1],T=u[2]-n[2],y=Math.hypot(F,O,T),v=y>1e-6?[F/y,O/y,T/y]:x,S=Math.abs(p-A)+1e-5,k=Math.max(S,p+A-1e-5),I=Math.max(S,Math.min(k,y>1e-6?y:S)),R=r((p*p+I*I-A*A)/(2*p*I),-1,1,1),V=Math.sqrt(Math.max(0,1-R*R)),D=h?h[0]-n[0]:f,L=h?h[1]-n[1]:M,j=h?h[2]-n[2]:c,U=D*v[0]+L*v[1]+j*v[2],W=D-v[0]*U,E=L-v[1]*U,q=j-v[2]*U,C=Math.hypot(W,E,q);if(C<=1e-6){let nt=Math.abs(v[1])<.99?0:1,at=Math.abs(v[1])<.99?1:0,lt=0;W=v[1]*lt-v[2]*at,E=v[2]*nt-v[0]*lt,q=v[0]*at-v[1]*nt,C=Math.hypot(W,E,q)||1}let tt=[W/C,E/C,q/C],N=[n[0]+v[0]*(p*R)+tt[0]*(p*V),n[1]+v[1]*(p*R)+tt[1]*(p*V),n[2]+v[2]*(p*R)+tt[2]*(p*V)],et=[n[0]+v[0]*I,n[1]+v[1]*I,n[2]+v[2]*I],rt=et[0]-N[0],it=et[1]-N[1],ot=et[2]-N[2],G=Math.hypot(rt,it,ot),Y=G>1e-6?[rt/G,it/G,ot/G]:v,st=[N[0]+Y[0]*A,N[1]+Y[1]*A,N[2]+Y[2]*A],ft=[(N[0]-n[0])/p,(N[1]-n[1])/p,(N[2]-n[2])/p];return{rootPos:[n[0],n[1],n[2]],midPos:N,effectorPos:st,rootRotation:o(x,ft),midRotation:o(_,Y)}}function a(n,s,l=8,u=.001){let h=n.length;if(h<2)return{positions:n.map(y=>[y[0],y[1],y[2]]),rotations:[],iterations:0};let f=n.map(y=>[y[0],y[1],y[2]]),M=[],c=[],p=0;for(let y=0;y<h-1;y++){let v=f[y+1][0]-f[y][0],S=f[y+1][1]-f[y][1],k=f[y+1][2]-f[y][2],I=Math.hypot(v,S,k);M.push(I),p+=I,c.push(I>1e-6?[v/I,S/I,k/I]:[0,1,0])}let w=[f[0][0],f[0][1],f[0][2]],b=Math.round(r(l,1,32,8)),m=r(u,1e-5,.1,.001),A=s[0]-w[0],x=s[1]-w[1],_=s[2]-w[2],F=Math.hypot(A,x,_),O=0;if(F>=p&&p>1e-6){let y=F>1e-6?[A/F,x/F,_/F]:c[0];f[0]=[w[0],w[1],w[2]];for(let v=0;v<h-1;v++){let S=M[v];f[v+1]=[f[v][0]+y[0]*S,f[v][1]+y[1]*S,f[v][2]+y[2]*S]}O=1}else for(let y=1;y<=b;y++){let v=f[h-1];if(Math.hypot(v[0]-s[0],v[1]-s[1],v[2]-s[2])<=m)break;O=y;let S=(k,I,R,V,D)=>{let L=I[0]-k[0],j=I[1]-k[1],U=I[2]-k[2],W=Math.hypot(L,j,U);if(W>1e-6){let E=R/W;return[k[0]+L*E,k[1]+j*E,k[2]+U*E]}return[k[0]+V[0]*R*D,k[1]+V[1]*R*D,k[2]+V[2]*R*D]};f[h-1]=[s[0],s[1],s[2]];for(let k=h-2;k>=0;k--)f[k]=S(f[k+1],f[k],M[k],c[k],-1);f[0]=[w[0],w[1],w[2]];for(let k=0;k<h-1;k++)f[k+1]=S(f[k],f[k+1],M[k],c[k],1)}let T=[];for(let y=0;y<h-1;y++){let v=f[y+1][0]-f[y][0],S=f[y+1][1]-f[y][1],k=f[y+1][2]-f[y][2],I=Math.hypot(v,S,k),R=I>1e-6?[v/I,S/I,k/I]:c[y];T.push(o(c[y],R))}return{positions:f,rotations:T,iterations:O}}function g(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let s=n;if(s.enabled===!1)return null;let l=m=>{if(typeof m!="string")return;let A=m.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(A)?A:void 0},u=m=>Array.isArray(m)&&m.length===3&&m.every(A=>typeof A=="number"&&Number.isFinite(A))?[r(m[0],-1e3,1e3,0),r(m[1],-1e3,1e3,0),r(m[2],-1e3,1e3,0)]:void 0,h=l(s.root),f=l(s.effector);if(!h||!f)return null;let M=l(s.mid),c=u(s.target)??l(s.target);if(!c)return null;let p=s.pole??s.poleTarget,w=u(p)??l(p),b=s.solver==="fabrik"?"fabrik":s.solver==="two-bone"||M?"two-bone":"fabrik";return{root:h,...M?{mid:M}:{},effector:f,target:c,...w?{pole:w}:{},solver:b,iterations:Math.round(r(s.iterations,1,32,8)),tolerance:r(s.tolerance,1e-5,.1,.001),weight:r(s.weight,0,1,1)}}let d=Object.freeze({solveTwoBone:i,solveFABRIK:a,parseIKTrait:g});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=d),{clampNum:r,parseIKTrait:g,quatFromUnitVectors:o,solveTwoBoneIK:i,solveFABRIK:a,IKSolver:d}}var z=le(),Pe=z.clampNum,$e=z.parseIKTrait,te=z.quatFromUnitVectors,fe=z.solveTwoBoneIK,de=z.solveFABRIK,Ce=z.IKSolver;function ue(t){let e=t?.transform??t?.modelMatrix;return e&&e.length>=16?[e[12]||0,e[13]||0,e[14]||0]:[0,0,0]}function qe(t,e){let r=t?.transform??t?.modelMatrix;!r||r.length<16||(r[12]=e[0],r[13]=e[1],r[14]=e[2])}function Ye(t,e,r,o,i){let a=Pe(i,0,1,1),g=e[0]+(r[0]-e[0])*a,d=e[1]+(r[1]-e[1])*a,n=e[2]+(r[2]-e[2])*a,s=g-t[0],l=d-t[1],u=n-t[2],h=Math.hypot(s,l,u);if(h>1e-6&&o>1e-6){let w=o/h;return[t[0]+s*w,t[1]+l*w,t[2]+u*w]}let f=r[0]-t[0],M=r[1]-t[1],c=r[2]-t[2],p=Math.hypot(f,M,c);if(p>1e-6&&o>1e-6){let w=o/p;return[t[0]+f*w,t[1]+M*w,t[2]+c*w]}return[g,d,n]}function Ze(t,e){let r=t?.modelRootMatrix;if(!r||r.length!==16)return e;let o=new Float32Array(16);return Le(o,r instanceof Float32Array?r:Float32Array.from(r))?[o[0]*e[0]+o[4]*e[1]+o[8]*e[2]+o[12],o[1]*e[0]+o[5]*e[1]+o[9]*e[2]+o[13],o[2]*e[0]+o[6]*e[1]+o[10]*e[2]+o[14]]:e}function se(t,e){t.__ikWarned||(t.__ikWarned=new Set);let r=t.__ikWarned;r.has(e)||(r.add(e),console.warn(`[three-live] ik: joint '${e}' on '${t?.name??""}' not found among scene nodes or meshes.`))}function me(t,e,r){if(Array.isArray(t))return[t[0],t[1],t[2]];let o=e.get(t);if(o)return ue(o);let i;if(t==="head"?i=r?.headPose?.position??r?.headPose??r?.cameraPosition:t==="hand-left"?i=r?.handPoses?.left?.position??r?.handPoses?.left??r?.hands?.left?.position??r?.hands?.left:t==="hand-right"&&(i=r?.handPoses?.right?.position??r?.handPoses?.right??r?.hands?.right?.position??r?.hands?.right),(Array.isArray(i)||ArrayBuffer.isView(i))&&i.length>=3){let a=i;return Ze(r,[a[0],a[1],a[2]])}return null}function ce(t,e){return[t[3]*e[0]+t[0]*e[3]+t[1]*e[2]-t[2]*e[1],t[3]*e[1]-t[0]*e[2]+t[1]*e[3]+t[2]*e[0],t[3]*e[2]+t[0]*e[1]-t[1]*e[0]+t[2]*e[3],t[3]*e[3]-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]}function en(t){return[-t[0],-t[1],-t[2],t[3]]}function ye(t){let e=Math.hypot(t[0],t[1],t[2],t[3]);return e>1e-12?[t[0]/e,t[1]/e,t[2]/e,t[3]/e]:[0,0,0,1]}function nn(t,e){if(e>=1)return t;if(e<=0)return[0,0,0,1];let[r,o,i,a]=t;a<0&&(r=-r,o=-o,i=-i,a=-a);let g=Math.acos(Math.min(1,a)),d=Math.sin(g);if(d<1e-9)return[0,0,0,1];let n=Math.sin(g*e)/d;return ye([r*n,o*n,i*n,Math.cos(g*e)])}function tn(t){let e=Math.hypot(t[0],t[1],t[2])||1,r=Math.hypot(t[4],t[5],t[6])||1,o=Math.hypot(t[8],t[9],t[10])||1,i=t[0]/e,a=t[1]/e,g=t[2]/e,d=t[4]/r,n=t[5]/r,s=t[6]/r,l=t[8]/o,u=t[9]/o,h=t[10]/o,f=i+n+h,M;if(f>0){let c=Math.sqrt(f+1)*2;M=[(s-u)/c,(l-g)/c,(a-d)/c,.25*c]}else if(i>n&&i>h){let c=Math.sqrt(1+i-n-h)*2;M=[.25*c,(d+a)/c,(l+g)/c,(s-u)/c]}else if(n>h){let c=Math.sqrt(1+n-i-h)*2;M=[(d+a)/c,.25*c,(u+s)/c,(l-g)/c]}else{let c=Math.sqrt(1+h-i-n)*2;M=[(l+g)/c,(u+s)/c,.25*c,(a-d)/c]}return ye(M)}function rn(t,e,r){let[o,i,a,g]=r,d=1-2*(i*i+a*a),n=2*(o*i-a*g),s=2*(o*a+i*g),l=2*(o*i+a*g),u=1-2*(o*o+a*a),h=2*(i*a-o*g),f=2*(o*a-i*g),M=2*(i*a+o*g),c=1-2*(o*o+i*i);for(let p=0;p<3;p++){let w=e[p*4],b=e[p*4+1],m=e[p*4+2];t[p*4]=d*w+n*b+s*m,t[p*4+1]=l*w+u*b+h*m,t[p*4+2]=f*w+M*b+c*m}}function ne(t,e){let r=e[0]-t[0],o=e[1]-t[1],i=e[2]-t[2],a=Math.hypot(r,o,i);return a>1e-9?[r/a,o/a,i/a]:null}function Ne(t){t?.normalMatrix&&t?.transform&&ee(t.normalMatrix,t.transform)}var Ee=new WeakMap;function on(t){let e=Ee.get(t);return e||(e=new Int32Array(t.nodes.length).fill(-1),t.nodes.forEach((r,o)=>{for(let i of Array.isArray(r?.children)?r.children:[])typeof i=="number"&&i>=0&&i<e.length&&(e[i]=o)}),Ee.set(t,e)),e}function an(t,e,r){let o=t?.gltf,i=o?.nodes;if(!Array.isArray(i)||i.length===0)return!1;let a=new Map;i.forEach((T,y)=>{typeof T?.name=="string"&&T.name&&!a.has(T.name)&&a.set(T.name,y)});let g=(e.mid?[e.root,e.mid,e.effector]:[e.root,e.effector]).map(T=>a.get(T));if(g.some(T=>T===void 0))return!1;let d=g,n=on(o);for(let T=1;T<d.length;T++){let y=n[d[T]],v=0;for(;y>=0&&y!==d[T-1]&&v++<256;)y=n[y];if(y!==d[T-1])return!1}let s=d[0],l=t.initialNodeTransforms,u=new Map,h=[],f=[s];for(;f.length&&h.length<4096;){let T=f.pop();if(u.has(T))continue;let y=l?.[T],v=i[T];u.set(T,{t:y?[y.t[0],y.t[1],y.t[2]]:v?.translation?[...v.translation]:[0,0,0],r:y?[y.r[0],y.r[1],y.r[2],y.r[3]]:v?.rotation?[...v.rotation]:[0,0,0,1],s:y?[y.s[0],y.s[1],y.s[2]]:v?.scale?[...v.scale]:[1,1,1]}),h.push(T);for(let S of Array.isArray(v?.children)?v.children:[])typeof S=="number"&&f.push(S)}let M=n[s],c=M>=0&&t.worldMatrices?.[M]?.length===16?Float32Array.from(t.worldMatrices[M]):P(),p=new Map,w=()=>{let T=(y,v)=>{let S=u.get(y);if(!S)return;let k=P();J(k,S.r,S.t,S.s);let I=P();ie(I,v,k),p.set(y,I);for(let R of Array.isArray(i[y]?.children)?i[y].children:[])typeof R=="number"&&T(R,I)};T(s,c)},b=T=>{let y=p.get(T);return[y[12],y[13],y[14]]};w();let m=d.map(b),A=T=>{if(typeof T=="string"&&!r.has(T)){let y=a.get(T),v=y!==void 0?p.get(y)??t.worldMatrices?.[y]:void 0;if(v&&v.length===16)return[v[12],v[13],v[14]]}return me(T,r,t)},x=A(e.target);if(!x)return!0;let _=e.pole?A(e.pole)??void 0:void 0,F=We(m,e,x,_),O=Pe(e.weight,0,1,1);for(let T=0;T<d.length-1;T++){let y=ne(b(d[T]),b(d[T+1])),v=ne(F[T],F[T+1]);if(!y||!v)continue;let S=nn(te(y,v),O),k=d[T],I=n[k],R=I===M||I<0?c:p.get(I)??c,V=tn(R),D=u.get(k);D.r=ye(ce(en(V),ce(S,ce(V,D.r)))),w()}if(Array.isArray(t.worldMatrices))for(let[T,y]of p)t.worldMatrices[T]?.set&&t.worldMatrices[T].set(y);for(let T of t.meshes??[]){let y=p.get(T?.nodeIndex);y&&T.transform?.set&&(T.transform.set(y),Ne(T))}return!0}function We(t,e,r,o){if(e.solver==="two-bone"&&t.length===3){let i=fe(t[0],t[1],t[2],r,o);return[t[0],i.midPos,i.effectorPos]}return de(t,r,e.iterations,e.tolerance).positions}function sn(t,e,r){let o=t.__ikRestOffsets,i=t.__ikRestMats;if(!(!o||!i))for(let a=0;a<e.length-1;a++){let g=e[a]?.transform??e[a]?.modelMatrix,d=i[a],n=ne([0,0,0],o[a]),s=ne(r[a],r[a+1]);!g||g.length<16||!d||d.length<16||!n||!s||(rn(g,d,te(n,s)),Ne(e[a]))}}var pe={name:"ik",onRegister(){let t=Q();ke(le),le(t.threeNamespace,t)},onUpdate(t){let e=t?.meshes;if(!Array.isArray(e)||e.length===0)return;let r=null;for(let o of e){let i=o?.userData?.xr?.ik??o?.extras?.xr?.ik??o?.extensions?.ANDROID_xr_scenecore?.ik;if(!i)continue;let a=$e(i);if(!a||a.weight<=0)continue;if(!r){r=new Map;for(let m of e)m&&typeof m.name=="string"&&m.name&&r.set(m.name,m)}if(an(t,a,r))continue;let g=r.get(a.root),d=r.get(a.effector),n=a.mid?r.get(a.mid):void 0;if(g||se(o,a.root),d||se(o,a.effector),a.mid&&!n&&se(o,a.mid),!g||!d)continue;let s=me(a.target,r,t);if(!s)continue;let l=a.pole?me(a.pole,r,t)??void 0:void 0,u=n?[g,n,d]:[g,d],h=u.map(m=>m.name||"").join(">");if(!o.__ikRestOffsets||o.__ikRestKey!==h){let m=u.map(ue),A=[];for(let x=0;x<m.length-1;x++)A.push([m[x+1][0]-m[x][0],m[x+1][1]-m[x][1],m[x+1][2]-m[x][2]]);o.__ikRestOffsets=A,o.__ikRestKey=h,o.__ikRestMats=u.map(x=>Array.from(x.transform??x.modelMatrix??[]))}let f=o.__ikRestOffsets,M=[ue(g)],c=[];for(let m=0;m<f.length;m++){let A=M[m],x=f[m];M.push([A[0]+x[0],A[1]+x[1],A[2]+x[2]]),c.push(Math.hypot(x[0],x[1],x[2]))}let p=We(M,a,s,l),w=M[0],b=[M[0]];for(let m=1;m<u.length;m++){let A=f[m-1],x=[w[0]+A[0],w[1]+A[1],w[2]+A[2]],_=[w[0]+(p[m][0]-p[m-1][0]),w[1]+(p[m][1]-p[m-1][1]),w[2]+(p[m][2]-p[m-1][2])],F=Ye(w,x,_,c[m-1],a.weight);qe(u[m],F),w=F,b.push(F)}sn(o,u,b)}}},cn={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function B(t,e,r,o){if(!r||r.bufferView===void 0)return null;let i=t.bufferViews?.[r.bufferView];if(!i)return null;let a=Number(r.count??0);if(!Number.isInteger(a)||a<=0)return null;let g=r.componentType??5126,d=cn[g];if(!d)throw new RangeError(`glTF accessor has unsupported componentType ${g}`);let n=d*o,s=i.byteStride&&i.byteStride>0?i.byteStride:n,l=(i.byteOffset||0)+(r.byteOffset||0);if(!Number.isInteger(l)||l<0||s<n||l+(a-1)*s+n>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(g===5126&&s===n&&l%4===0)return new Float32Array(e,l,a*o);let u=new DataView(e),h=r.normalized===!0,f=new Float32Array(a*o);for(let M=0;M<a;M++){let c=l+M*s;for(let p=0;p<o;p++){let w=c+p*d,b;switch(g){case 5126:b=u.getFloat32(w,!0);break;case 5120:b=u.getInt8(w),h&&(b=Math.max(b/127,-1));break;case 5121:b=u.getUint8(w),h&&(b/=255);break;case 5122:b=u.getInt16(w,!0),h&&(b=Math.max(b/32767,-1));break;case 5123:b=u.getUint16(w,!0),h&&(b/=65535);break;default:b=u.getUint32(w,!0),h&&(b/=4294967295)}f[M*o+p]=b}}return f}function Ge(t,e,r){return e%4===0?new Float32Array(t,e,r):new Float32Array(t.slice(e,e+r*4))}function Be(t,e,r,o){let i=e[0],a=e[1],g=e[2],d=e[3],n=r[0],s=r[1],l=r[2],u=r[3],h=i*n+a*s+g*l+d*u;if(h<0&&(n=-n,s=-s,l=-l,u=-u,h=-h),Math.abs(h)>=1)return t[0]=i,t[1]=a,t[2]=g,t[3]=d,t;let f=Math.acos(h),M=Math.sqrt(1-h*h);if(Math.abs(M)<.001)return t[0]=.5*(i+n),t[1]=.5*(a+s),t[2]=.5*(g+l),t[3]=.5*(d+u),t;let c=Math.sin((1-o)*f)/M,p=Math.sin(o*f)/M;return t[0]=i*c+n*p,t[1]=a*c+s*p,t[2]=g*c+l*p,t[3]=d*c+u*p,t}function Ue(t,e,r,o){return t[0]=e[0]+o*(r[0]-e[0]),t[1]=e[1]+o*(r[1]-e[1]),t[2]=e[2]+o*(r[2]-e[2]),t}function ge(t,e){if(!Array.isArray(t?.animations))return[];let r=[];for(let o=0;o<t.animations.length;o++){let i=t.animations[o],a=i.name||`Animation_${o}`,g=[],d=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let n of i.channels){if(!n.target||n.target.node===void 0||!n.target.path)continue;let s=i.samplers[n.sampler];if(!s)continue;let l=t.accessors?.[s.input],u=t.accessors?.[s.output];if(!l||!u)continue;let h=t.bufferViews?.[l.bufferView],f=t.bufferViews?.[u.bufferView];if(!h||!f)continue;let M=(h.byteOffset||0)+(l.byteOffset||0),c=(f.byteOffset||0)+(u.byteOffset||0),p=B(t,e,l,1)??Ge(e,M,l.count);p.length>0&&p[p.length-1]>d&&(d=p[p.length-1]);let w=n.target.path==="rotation"?4:n.target.path==="weights"?Math.max(1,Math.round(u.count/Math.max(1,l.count))):3,b=n.target.path==="weights"?1:w,m=B(t,e,u,b)??Ge(e,c,u.count*b),A=s.interpolation==="STEP"?"STEP":"LINEAR";g.push({nodeIndex:n.target.node,path:n.target.path,times:p,values:m,interpolation:A})}g.length>0&&r.push({name:a,duration:d,channels:g})}return r}function K(t,e,r){let{times:o,values:i,path:a,interpolation:g}=t,d=o.length;if(d===0)return;let n=a==="rotation"?4:a==="weights"?Math.max(1,Math.round(i.length/d)):3;if(e<=o[0]){for(let b=0;b<n;b++)r[b]=i[b];return}if(e>=o[d-1]){let b=(d-1)*n;for(let m=0;m<n;m++)r[m]=i[b+m];return}let s=0,l=d-1;for(;s<=l;){let b=s+l>>1;o[b]<=e?s=b+1:l=b-1}let u=Math.max(0,l),h=Math.min(d-1,u+1);if(g==="STEP"||u===h){let b=u*n;for(let m=0;m<n;m++)r[m]=i[b+m];return}let f=o[u],M=o[h],c=(e-f)/Math.max(1e-5,M-f),p=u*n,w=h*n;if(a==="rotation"){let b=[i[p],i[p+1],i[p+2],i[p+3]],m=[i[w],i[w+1],i[w+2],i[w+3]];Be(r,b,m,c)}else for(let b=0;b<n;b++)r[b]=i[p+b]+c*(i[w+b]-i[p+b])}var H=new WeakMap;function Ae(t,e,r=.3){if(!t?.animations)return;let o=t.animations.find(d=>d.name===e);if(!o)return;let i=H.get(t);i||(i=[],t.currentClip&&i.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),H.set(t,i));let a=r>0?1/r:1e3;for(let d of i)d.clip.name!==e&&(d.fadeSpeed=-a);let g=i.find(d=>d.clip.name===e);g?g.fadeSpeed=a:i.push({clip:o,time:0,weight:r>0?0:1,fadeSpeed:a}),t.currentClip=o,t.isPlayingAnimation=!0}function be(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let r=H.get(t);if(!r||r.length===0){if(!t.currentClip)return;r=[{clip:t.currentClip,time:e,weight:1,fadeSpeed:0}]}let o=t.gltf.nodes.length,i=[];for(let u=0;u<o;u++){let h=t.initialNodeTransforms[u];h?i.push({t:[h.t[0],h.t[1],h.t[2]],r:[h.r[0],h.r[1],h.r[2],h.r[3]],s:[h.s[0],h.s[1],h.s[2]]}):i.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let a=[0,0,0],g=[0,0,0,1],d=[1,1,1],n=new Float32Array(64);for(let u of r){let h=Math.max(0,Math.min(1,u.weight));if(!(h<=1e-4))for(let f of u.clip.channels){if(f.nodeIndex<0||f.nodeIndex>=o)continue;let M=i[f.nodeIndex];if(f.path==="translation")K(f,u.time,a),Ue(M.t,M.t,a,h);else if(f.path==="rotation")K(f,u.time,g),Be(M.r,M.r,g,h);else if(f.path==="scale")K(f,u.time,d),Ue(M.s,M.s,d,h);else if(f.path==="weights"&&(K(f,u.time,n),t.meshes)){for(let c of t.meshes)if(c.nodeIndex===f.nodeIndex){for(let p of c.primitives)if(p.pluginData?.morph?.weights){let w=p.pluginData.morph.weights,b=p.pluginData.morph.numTargets||w.length;for(let m=0;m<b;m++)w[m]=w[m]*(1-h)+n[m]*h}}}}}let s=[];for(let u=0;u<o;u++){let h=P(),{t:f,r:M,s:c}=i[u];J(h,M,f,c),s.push(h)}let l=_e(t.gltf,s);t.worldMatrices=l;for(let u of t.meshes)u.nodeIndex>=0&&u.nodeIndex<l.length&&(u.transform.set(l[u.nodeIndex]),ee(u.normalMatrix,u.transform))}var he=t=>{H.delete(t)},Te={name:"keyframes",evaluateAnimation:be,crossFadeTo:Ae,onParseGLB(t){(t.animationsParsed===!1||!t.animations)&&(t.animations=ge(t.gltf,t.bin),t.animationsParsed=!0)},onLoadModel:he,onClearScene:he,onDestroy:(t,e)=>he(e),onUpdate(t,e){if(!t.isPlayingAnimation)return;let r=H.get(t);if(r&&r.length>0){for(let o=r.length-1;o>=0;o--){let i=r[o];if(i.time+=e,i.clip.duration>0&&(i.time%=i.clip.duration),i.fadeSpeed!==0)if(i.weight+=i.fadeSpeed*e,i.weight<=0){r.splice(o,1);continue}else i.weight>=1&&(i.weight=1,i.fadeSpeed=0)}r.length>0&&(t.animationTime=r[r.length-1].time),be(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),be(t,t.animationTime))}},$=64;function Oe(t,e,r){if(!(!t?.meshes||e<0||e>=$))for(let o of t.meshes)for(let i of o.primitives){let a=i.pluginData?.morph;a?.weights&&(a.weights[e]=r)}}var xe={name:"morph",onResolveShader(t,e,r,o){if(!Array.isArray(t?.targets)||t.targets.length===0)return null;let i=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
17
17
  uniform sampler2D uMorphDeltasTex;
18
- uniform float uMorphWeights[${H}];
18
+ uniform float uMorphWeights[${$}];
19
19
  uniform int uNumMorphTargets;`);return i=i.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
20
- for (int m = 0; m < ${H}; m++) {
20
+ for (int m = 0; m < ${$}; m++) {
21
21
  if (m >= uNumMorphTargets) break;
22
22
  float w = uMorphWeights[m];
23
23
  if (abs(w) > 0.0001) {
24
24
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
25
25
  }
26
26
  }
27
- vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:i,fs:o}},onBuildPrimitiveVAO(t,e,r,o,i){let a=r?.targets;if(!Array.isArray(a)||a.length===0)return null;let g=r.attributes?.POSITION,p=o?.accessors?.[g];if(!p)return null;let n=p.count,s=Math.min(a.length,H),l=new Float32Array(n*s*4);for(let f=0;f<s;f++){let M=a[f].POSITION;if(M===void 0)continue;let c=o.accessors?.[M],d=o.bufferViews?.[c?.bufferView];if(!c||!d)continue;let b=O(o,i,c,3);if(!b||b.length<n*3)continue;let v=f*n*4;for(let m=0;m<n;m++)l[v+m*4]=b[m*3],l[v+m*4+1]=b[m*3+1],l[v+m*4+2]=b[m*3+2],l[v+m*4+3]=0}let u=t.createTexture();t.bindTexture(3553,u),t.texImage2D(3553,0,34836,n,s,0,6408,5126,l),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728);let h=new Float32Array(H);return{hasMorph:!0,morphTex:u,numTargets:s,vertexCount:n,weights:h}},onBeforeDrawPrimitive(t,e,r,o,i,a){let g=r.pluginData?.morph;if(!g?.hasMorph||!g.morphTex)return;t.activeTexture(33989),t.bindTexture(3553,g.morphTex);let p=t.getUniformLocation(e,"uMorphDeltasTex");p&&t.uniform1i(p,5);let n=t.getUniformLocation(e,"uNumMorphTargets");n&&t.uniform1i(n,g.numTargets);let s=t.getUniformLocation(e,"uMorphWeights[0]");s&&t.uniform1fv(s,g.weights)}},Me=64,we={name:"skinning",onResolveShader(t,e,r,o){if(t?.attributes?.JOINTS_0===void 0||t?.attributes?.WEIGHTS_0===void 0)return null;let i=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
27
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:i,fs:o}},onBuildPrimitiveVAO(t,e,r,o,i){let a=r?.targets;if(!Array.isArray(a)||a.length===0)return null;let g=r.attributes?.POSITION,d=o?.accessors?.[g];if(!d)return null;let n=d.count,s=Math.min(a.length,$),l=new Float32Array(n*s*4);for(let f=0;f<s;f++){let M=a[f].POSITION;if(M===void 0)continue;let c=o.accessors?.[M],p=o.bufferViews?.[c?.bufferView];if(!c||!p)continue;let w=B(o,i,c,3);if(!w||w.length<n*3)continue;let b=f*n*4;for(let m=0;m<n;m++)l[b+m*4]=w[m*3],l[b+m*4+1]=w[m*3+1],l[b+m*4+2]=w[m*3+2],l[b+m*4+3]=0}let u=t.createTexture();t.bindTexture(3553,u),t.texImage2D(3553,0,34836,n,s,0,6408,5126,l),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728);let h=new Float32Array($);return{hasMorph:!0,morphTex:u,numTargets:s,vertexCount:n,weights:h}},onBeforeDrawPrimitive(t,e,r,o,i,a){let g=r.pluginData?.morph;if(!g?.hasMorph||!g.morphTex)return;t.activeTexture(33989),t.bindTexture(3553,g.morphTex);let d=t.getUniformLocation(e,"uMorphDeltasTex");d&&t.uniform1i(d,5);let n=t.getUniformLocation(e,"uNumMorphTargets");n&&t.uniform1i(n,g.numTargets);let s=t.getUniformLocation(e,"uMorphWeights[0]");s&&t.uniform1fv(s,g.weights)}},we=64,Me={name:"skinning",onResolveShader(t,e,r,o){if(t?.attributes?.JOINTS_0===void 0||t?.attributes?.WEIGHTS_0===void 0)return null;let i=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
28
28
  layout(location=4) in uvec4 aJoints;
29
29
  layout(location=5) in vec4 aWeights;
30
- uniform mat4 uJointMatrix[${Me}];`),a=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${a},1.0);`,`mat4 skinMatrix =
30
+ uniform mat4 uJointMatrix[${we}];`),a=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${a},1.0);`,`mat4 skinMatrix =
31
31
  aWeights.x * uJointMatrix[int(aJoints.x)] +
32
32
  aWeights.y * uJointMatrix[int(aJoints.y)] +
33
33
  aWeights.z * uJointMatrix[int(aJoints.z)] +
34
34
  aWeights.w * uJointMatrix[int(aJoints.w)];
35
- vec4 world=uModel*(skinMatrix*vec4(${a},1.0));`).replace(`gl_Position=uMVP*vec4(${a},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${a},1.0));`),{vs:i,fs:o}},onBuildPrimitiveVAO(t,e,r,o,i){let a=r?.attributes;if(!a||a.JOINTS_0===void 0||a.WEIGHTS_0===void 0)return null;let g=o.accessors[a.JOINTS_0],p=o.accessors[a.WEIGHTS_0];if(!g||!p)return null;let n=o.bufferViews[g.bufferView],s=o.bufferViews[p.bufferView];if(!n||!s)return null;let l=(n.byteOffset||0)+(g.byteOffset||0),u=(s.byteOffset||0)+(p.byteOffset||0),h=t.createBuffer();t.bindBuffer(34962,h);let f=g.componentType===5121?5121:5123,M=f===5121?new Uint8Array(i,l,g.count*4):new Uint16Array(i,l,g.count*4);t.bufferData(34962,M,35044),t.enableVertexAttribArray(4),t.vertexAttribIPointer(4,4,f,0,0);let c=t.createBuffer();t.bindBuffer(34962,c);let d=O(o,i,p,4)??new Float32Array(i,u,p.count*4);return t.bufferData(34962,d,35044),t.enableVertexAttribArray(5),t.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[h,c]}},onBeforeDrawPrimitive(t,e,r,o,i,a){if(!r.pluginData?.skinning?.hasSkin)return;let g=a?.nodes?.[o.nodeIndex]?.skin;if(g===void 0||!a.skins||!a.skins[g])return;let p=a.skins[g].joints||[],n=new Float32Array(Me*16);for(let l=0;l<p.length&&l<Me;l++){let u=p[l],h=i[u]||N();n.subarray(l*16,(l+1)*16).set(h)}let s=t.getUniformLocation(e,"uJointMatrix[0]");s&&t.uniformMatrix4fv(s,!1,n)}};X(xe),X(Te),X(we),X(ye);
35
+ vec4 world=uModel*(skinMatrix*vec4(${a},1.0));`).replace(`gl_Position=uMVP*vec4(${a},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${a},1.0));`),{vs:i,fs:o}},onBuildPrimitiveVAO(t,e,r,o,i){let a=r?.attributes;if(!a||a.JOINTS_0===void 0||a.WEIGHTS_0===void 0)return null;let g=o.accessors[a.JOINTS_0],d=o.accessors[a.WEIGHTS_0];if(!g||!d)return null;let n=o.bufferViews[g.bufferView],s=o.bufferViews[d.bufferView];if(!n||!s)return null;let l=(n.byteOffset||0)+(g.byteOffset||0),u=(s.byteOffset||0)+(d.byteOffset||0),h=t.createBuffer();t.bindBuffer(34962,h);let f=g.componentType===5121?5121:5123,M=f===5121?new Uint8Array(i,l,g.count*4):new Uint16Array(i,l,g.count*4);t.bufferData(34962,M,35044),t.enableVertexAttribArray(4),t.vertexAttribIPointer(4,4,f,0,0);let c=t.createBuffer();t.bindBuffer(34962,c);let p=B(o,i,d,4)??new Float32Array(i,u,d.count*4);return t.bufferData(34962,p,35044),t.enableVertexAttribArray(5),t.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[h,c]}},onBeforeDrawPrimitive(t,e,r,o,i,a){if(!r.pluginData?.skinning?.hasSkin)return;let g=a?.nodes?.[o.nodeIndex]?.skin;if(g===void 0||!a.skins||!a.skins[g])return;let d=a.skins[g].joints||[],n=new Float32Array(we*16);for(let l=0;l<d.length&&l<we;l++){let u=d[l],h=i[u]||P();n.subarray(l*16,(l+1)*16).set(h)}let s=t.getUniformLocation(e,"uJointMatrix[0]");s&&t.uniformMatrix4fv(s,!1,n)}};X(xe),X(Te),X(Me),X(pe);
@@ -20,6 +20,7 @@
20
20
 
21
21
  import type {
22
22
  CameraState,
23
+ ShadowMapsMode,
23
24
  ThreeLiveElement,
24
25
  } from './three-live/src/three-live-element';
25
26
  import type {
@@ -118,6 +119,27 @@ export {
118
119
  postprocessingPlugin,
119
120
  resolveViewerBloom,
120
121
  } from './three-live/src/plugins/postprocessing';
122
+ export {
123
+ installProceduralExtension,
124
+ proceduralPlugin,
125
+ } from './three-live/src/plugins/procedural';
126
+ export {
127
+ computeWorldSceneBounds,
128
+ doesMeshCastShadow,
129
+ doesMeshReceiveShadow,
130
+ fitDirectionalShadowMatrix,
131
+ fitSpotShadowMatrix,
132
+ getShadowMapStats,
133
+ MAX_SHADOW_LIGHTS,
134
+ normalizeShadowMapsMode,
135
+ resolveActiveShadowLights,
136
+ SHADOW_MAP_TEXTURE_UNIT,
137
+ shadowMapsPlugin,
138
+ type ResolvedShadowPlan,
139
+ type ResolvedShadowSlice,
140
+ type ShadowMapStats,
141
+ type WorldSceneBounds,
142
+ } from './three-live/src/plugins/shadow-maps';
121
143
  export {
122
144
  extractMaterialVariants,
123
145
  extractPrimitiveVariantMappings,
@@ -126,6 +148,7 @@ export {
126
148
  type VariantMapping,
127
149
  } from './three-live/src/plugins/variants';
128
150
  export {
151
+ defineModelViewer,
129
152
  ThreeLiveElement,
130
153
  type ARLaunchOptions,
131
154
  type ARLaunchResult,
@@ -142,10 +165,144 @@ export {
142
165
  type XRProfile,
143
166
  type XRSimulatorRoom,
144
167
  } from './xr-live/src/xr-live-element';
168
+ /** Opt-in bring-your-own-LLM scene editing (`three-live/ai`, `three-live-ai.min.js`). */
169
+ export {
170
+ aiPlugin,
171
+ createAIChatProvider,
172
+ editScene,
173
+ extractScript,
174
+ undoEdit,
175
+ } from './three-live/src/plugins/ai';
176
+ export type {
177
+ AIChatContentPart,
178
+ AIChatMessage,
179
+ AIChatProviderOptions,
180
+ EditSceneOptions,
181
+ EditSceneResult,
182
+ ThreeLiveAIProvider,
183
+ } from './three-live/src/plugins/ai';
184
+ export {
185
+ buildImageMessages,
186
+ buildImageUserText,
187
+ compileFromImage,
188
+ detectImageMime,
189
+ formatSpatialPriors,
190
+ IMAGE_SYSTEM_PROMPT,
191
+ imageRepairMessage,
192
+ isAllowedImageUrl,
193
+ normalizeImageInput,
194
+ } from './three-live/src/plugins/ai-image';
195
+ export type {
196
+ AIImageInput,
197
+ AISpatialCamera,
198
+ AISpatialObject,
199
+ AISpatialPlane,
200
+ AISpatialPriors,
201
+ CompileFromImageOptions,
202
+ } from './three-live/src/plugins/ai-image';
203
+ /** AI PBR textures: texture packs and image providers (part of `three-live-ai.min.js`). */
204
+ export {
205
+ browserImageCodec,
206
+ createAIImageProvider,
207
+ indexedDbTextureCache,
208
+ parseTexturePack,
209
+ prepareAlbedo,
210
+ serializeTexturePack,
211
+ TEXTURE_PROMPT_SUFFIX,
212
+ textureRequests,
213
+ } from './three-live/src/plugins/ai-texture';
214
+ export type {
215
+ AIImageProviderOptions,
216
+ AITextureSpec,
217
+ GenerateTexturesOptions,
218
+ GenerateTexturesResult,
219
+ TextureCache,
220
+ TextureCacheRecord,
221
+ TextureImageCodec,
222
+ TextureMiss,
223
+ TexturePackEntry,
224
+ TexturePackJSON,
225
+ ThreeLiveImageProvider,
226
+ } from './three-live/src/plugins/ai-texture';
227
+ /** "Tap & Speak" voice editing (part of `three-live-ai.min.js`). */
228
+ export {
229
+ hideSelectionChips,
230
+ showSelectionChips,
231
+ } from './three-live/src/plugins/ai-select-chips';
232
+ export type {AISelectChipsState} from './three-live/src/plugins/ai-select-chips';
233
+ export {
234
+ AIVoiceSession,
235
+ connectVoice,
236
+ createWebSpeechRecognizer,
237
+ describeEditResult,
238
+ describeVoiceSelection,
239
+ geminiLiveAdapter,
240
+ realtimeAdapter,
241
+ selectByVoice,
242
+ selectNamesByVoice,
243
+ setSelectOnTap,
244
+ speakableName,
245
+ startVoiceEdit,
246
+ } from './three-live/src/plugins/ai-voice';
247
+ /** Multi-select for Tap & Speak / Talk-to-Select (part of `three-live-ai.min.js`). */
248
+ export {
249
+ describeSelection,
250
+ getSelection,
251
+ parseSelectReply,
252
+ resolveSelection,
253
+ resolveSelectionWithModel,
254
+ sceneSelectEntries,
255
+ selectCamera,
256
+ selectMessages,
257
+ setSelection,
258
+ } from './three-live/src/plugins/ai-select';
259
+ export type {
260
+ AIModelSelection,
261
+ AISelectProvider,
262
+ } from './three-live/src/plugins/ai-select';
263
+ /** Talk-to-Select tier-1 matcher and push-to-talk grammar (mirrors the Rust core). */
264
+ export type {
265
+ AISelectionEventDetail,
266
+ AISelectionMode,
267
+ AISelectionSource,
268
+ } from './three-live/src/plugins/ai-select';
269
+ export {
270
+ buildSelectIndex,
271
+ matchSelection,
272
+ parseVoiceCommand,
273
+ } from './three-live/src/plugins/ai-select-match';
274
+ export type {
275
+ SelectCamera,
276
+ SelectConfidence,
277
+ SelectIndexEntry,
278
+ SelectMatch,
279
+ SelectRawEntry,
280
+ VoiceCommand,
281
+ } from './three-live/src/plugins/ai-select-match';
282
+ export type {
283
+ AIAudioSink,
284
+ AIMicrophoneSource,
285
+ AISpeechRecognizer,
286
+ AIVoiceAdapter,
287
+ AIVoiceEditOptions,
288
+ AIVoiceEditResult,
289
+ AIVoiceEventDetail,
290
+ AIVoiceProviderName,
291
+ AIVoiceSelection,
292
+ AIVoiceSessionOptions,
293
+ AIVoiceState,
294
+ AIVoiceTransport,
295
+ } from './three-live/src/plugins/ai-voice';
145
296
  /** Optional spatial plugins (`xr-live/spatial`, `xr-live-spatial.min.js`). */
146
297
  export * from './xr-live/src/plugins/index';
147
298
  /** Optional simulation plugins (`xr-live/sim`, `xr-live-sim.min.js`). */
148
299
  export * from './xr-live/src/sim/index';
300
+ /** Optional WebGPU Gaussian Splatting compute & render accelerator (`xr-live/webgpu`, `xr-live-webgpu.min.js`). */
301
+ export * from './xr-live/src/webgpu';
302
+ /** Optional WebGPU `GPURenderBundle` scene accelerator (`three-live/webgpu`, `three-live-webgpu.min.js`). */
303
+ export * from './three-live/src/webgpu';
304
+ /** Optional Loop-Free `THREE.TSL` & `MeshStandardNodeMaterial` compiler (`three-live/tsl`, `three-live-tsl.min.js`). */
305
+ export * from './three-live/src/tsl';
149
306
 
150
307
  /**
151
308
  * Declarative JSX / HTML attributes supported by the <three-live> custom element.
@@ -234,6 +391,40 @@ export interface ThreeLiveAttributes {
234
391
  * Server-generated scripts (`script-src`) are enabled by default.
235
392
  */
236
393
  'allow-client-scripts'?: boolean | string;
394
+ /** `three-live-ai`: Chat Completions-compatible endpoint (your proxy or a local model) for `editScene()`. */
395
+ 'ai-endpoint'?: string;
396
+ /** `three-live-ai`: model name sent to `ai-endpoint`. */
397
+ 'ai-model'?: string;
398
+ /** `three-live-ai`: provider protocol for `ai-endpoint` (`'ai-chat'`, the default). */
399
+ 'ai-provider'?: 'ai-chat';
400
+ /** `three-live-ai`: OpenAI-compatible Images endpoint (`/v1/images/generations`) for AI textures (`userData.xr.material.prompt`). */
401
+ 'ai-image-endpoint'?: string;
402
+ /** `three-live-ai`: model name sent to `ai-image-endpoint`. */
403
+ 'ai-image-model'?: string;
404
+ /** `three-live-ai`: `'auto'` (default) generates missing AI textures when an image endpoint is configured; `'manual'` waits for `el.generateTextures()`. */
405
+ 'ai-textures'?: 'auto' | 'manual';
406
+ /** `three-live-ai`: URL of a texture pack (`scene.textures.json`) for AI textures. */
407
+ 'texture-pack'?: string;
408
+ /** `three-live-webgpu`: scene rendering backend (`'auto'`, `'webgpu'`, or `'webgl2'`). */
409
+ renderer?: 'auto' | 'webgpu' | 'webgl2' | string;
410
+ /** `three-live-studio` / `shadowMapsPlugin`: multi-light depth shadow maps (`'auto'`, `'pcf'`, or `'off'`). */
411
+ 'shadow-maps'?: ShadowMapsMode | string;
412
+ /** `xr-live-webgpu`: Gaussian splatting backend (`'auto'`, `'webgpu'`, `'hybrid'`, or `'webgl2'`). */
413
+ 'splat-renderer'?: 'auto' | 'webgpu' | 'hybrid' | 'webgl2' | string;
414
+ /** `xr-live-spatial` / `xr-live-webgpu`: Spherical Harmonics view-dependent color quality (`'normal'` or `'high'`). */
415
+ 'splat-quality'?: 'normal' | 'high' | string;
416
+ /** Allow cross-origin `.splat` / `.spz` URLs on `userData.xr.splatUrl`. */
417
+ 'allow-remote-splats'?: boolean | string;
418
+ /** `three-live-ai`: tapping a mesh selects it (tap again to clear; Shift/Ctrl/Cmd-tap or long-press adds to `el.selectedMeshes`). */
419
+ 'ai-select-on-tap'?: boolean | string;
420
+ /** `three-live-ai`: show a mic button (push-to-talk, or a realtime session when `ai-voice-url` is set). */
421
+ 'ai-voice-button'?: boolean | string;
422
+ /** `three-live-ai`: `wss://` realtime voice endpoint (your proxy or an ephemeral-token URL) for the mic button. */
423
+ 'ai-voice-url'?: string;
424
+ /** `three-live-ai`: realtime voice protocol for `ai-voice-url` (`'ai-realtime'`, the default, or `'gemini-live'`). */
425
+ 'ai-voice-provider'?: 'ai-realtime' | 'gemini-live';
426
+ /** `three-live-ai`: model name sent in the realtime session setup. */
427
+ 'ai-voice-model'?: string;
237
428
 
238
429
  // React 19 / JSX Event Listeners
239
430
  onload?: (e: CustomEvent<{model: GLBData}>) => void;
@@ -13,18 +13,18 @@
13
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
- */var H="__THREE_LIVE_REGISTRY__";function Y(){let t=typeof globalThis<"u"?globalThis:{};if(!t[H]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,H,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[H]=e}}return t[H]}var ee=Y().plugins;function Bt(t){let e=Y();e.workerExtensionInstallers||(e.workerExtensionInstallers=[]),e.workerExtensionInstallers.includes(t)||e.workerExtensionInstallers.push(t)}function Z(t){let e=Y().plugins;e.some(r=>r.name===t.name)||e.push(t),t.onRegister?.()}function W(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function bt(t,e,r){let n=e[0],i=e[1],a=e[2],g=e[3],p=e[4],o=e[5],s=e[6],l=e[7],u=e[8],h=e[9],f=e[10],M=e[11],c=e[12],d=e[13],b=e[14],w=e[15],m=r[0],v=r[1],x=r[2],k=r[3];return t[0]=m*n+v*p+x*u+k*c,t[1]=m*i+v*o+x*h+k*d,t[2]=m*a+v*s+x*f+k*b,t[3]=m*g+v*l+x*M+k*w,m=r[4],v=r[5],x=r[6],k=r[7],t[4]=m*n+v*p+x*u+k*c,t[5]=m*i+v*o+x*h+k*d,t[6]=m*a+v*s+x*f+k*b,t[7]=m*g+v*l+x*M+k*w,m=r[8],v=r[9],x=r[10],k=r[11],t[8]=m*n+v*p+x*u+k*c,t[9]=m*i+v*o+x*h+k*d,t[10]=m*a+v*s+x*f+k*b,t[11]=m*g+v*l+x*M+k*w,m=r[12],v=r[13],x=r[14],k=r[15],t[12]=m*n+v*p+x*u+k*c,t[13]=m*i+v*o+x*h+k*d,t[14]=m*a+v*s+x*f+k*b,t[15]=m*g+v*l+x*M+k*w,t}function rt(t,e,r,n){let i=e[0],a=e[1],g=e[2],p=e[3],o=i+i,s=a+a,l=g+g,u=i*o,h=i*s,f=i*l,M=a*s,c=a*l,d=g*l,b=p*o,w=p*s,m=p*l,v=n[0],x=n[1],k=n[2];return t[0]=(1-(M+d))*v,t[1]=(h+m)*v,t[2]=(f-w)*v,t[3]=0,t[4]=(h-m)*x,t[5]=(1-(u+d))*x,t[6]=(c+b)*x,t[7]=0,t[8]=(f+w)*k,t[9]=(c-b)*k,t[10]=(1-(u+M))*k,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function wt(t,e,r=0){let n=e[0],i=e[1],a=e[2],g=e[4],p=e[5],o=e[6],s=e[8],l=e[9],u=e[10],h=u*p-o*l,f=-u*g+o*s,M=l*g-p*s,c=n*h+i*f+a*M;return!c||r>0&&(!Number.isFinite(c)||Math.abs(c)<=r)||(c=1/c,t[0]=h*c,t[1]=f*c,t[2]=M*c,t[3]=(-u*i+a*l)*c,t[4]=(u*n-a*s)*c,t[5]=(-l*n+i*s)*c,t[6]=(o*i-a*p)*c,t[7]=(-o*n+a*g)*c,t[8]=(p*n-i*g)*c),t}function Kt(t,e){let r=e[0],n=e[1],i=e[2],a=e[3],g=e[4],p=e[5],o=e[6],s=e[7],l=e[8],u=e[9],h=e[10],f=e[11],M=e[12],c=e[13],d=e[14],b=e[15],w=r*p-n*g,m=r*o-i*g,v=r*s-a*g,x=n*o-i*p,k=n*s-a*p,F=i*s-a*o,V=l*c-u*M,T=l*d-h*M,y=l*b-f*M,A=u*d-h*c,_=u*b-f*c,P=h*b-f*d,I=w*P-m*_+v*A+x*y-k*T+F*V;return I?(I=1/I,t[0]=(p*P-o*_+s*A)*I,t[1]=(i*_-n*P-a*A)*I,t[2]=(c*F-d*k+b*x)*I,t[3]=(h*k-u*F-f*x)*I,t[4]=(o*y-g*P-s*T)*I,t[5]=(r*P-i*y+a*T)*I,t[6]=(d*v-M*F-b*m)*I,t[7]=(l*F-h*v+f*m)*I,t[8]=(g*_-p*y+s*V)*I,t[9]=(n*y-r*_-a*V)*I,t[10]=(M*k-c*v+b*w)*I,t[11]=(u*v-l*k-f*w)*I,t[12]=(p*T-g*A-o*V)*I,t[13]=(r*A-n*T+i*V)*I,t[14]=(c*m-M*x-d*w)*I,t[15]=(l*x-u*m+h*w)*I,t):null}function Ut(t,e){let r=Array.isArray(t?.nodes)?t.nodes.length:0,n=[];for(let l=0;l<r;l++)n.push(W());if(r===0)return n;let i=new Set;for(let l of t.nodes)if(Array.isArray(l.children))for(let u of l.children)i.add(u);let a=new Set,g=128,p=(l,u,h=0)=>{if(h>g||l<0||l>=r||a.has(l))return;a.add(l);let f=t.nodes[l];if(!f)return;let M=W();if(e&&e[l])M.set(e[l]);else if(f.matrix&&f.matrix.length===16)M.set(f.matrix);else{let d=f.translation||[0,0,0],b=f.rotation||[0,0,0,1],w=f.scale||[1,1,1];rt(M,b,d,w)}let c=n[l];if(u?bt(c,u,M):c.set(M),Array.isArray(f.children))for(let d of f.children)typeof d=="number"&&p(d,c,h+1)},o=[],s=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(s&&Array.isArray(s.nodes))o.push(...s.nodes);else for(let l=0;l<r;l++)i.has(l)||o.push(l);for(let l of o)p(l,null);for(let l=0;l<r;l++)!i.has(l)&&!o.includes(l)&&p(l,null);return n}function it(t,e){function r(o,s,l,u){let h=typeof o=="number"?o:Number(o);return Number.isFinite(h)?Math.max(s,Math.min(l,h)):u}function n(o,s){let l=o[0]*s[0]+o[1]*s[1]+o[2]*s[2]+1;if(l<1e-6){if(Math.abs(o[0])>Math.abs(o[2])){let d=Math.hypot(o[1],o[0])||1;return[-o[1]/d,o[0]/d,0,0]}let c=Math.hypot(o[2],o[1])||1;return[0,-o[2]/c,o[1]/c,0]}let u=o[1]*s[2]-o[2]*s[1],h=o[2]*s[0]-o[0]*s[2],f=o[0]*s[1]-o[1]*s[0],M=Math.hypot(u,h,f,l)||1;return[u/M,h/M,f/M,l/M]}function i(o,s,l,u,h){let f=s[0]-o[0],M=s[1]-o[1],c=s[2]-o[2],d=Math.hypot(f,M,c),b=l[0]-s[0],w=l[1]-s[1],m=l[2]-s[2],v=Math.hypot(b,w,m);if(d<1e-6||v<1e-6)return{rootPos:[o[0],o[1],o[2]],midPos:[s[0],s[1],s[2]],effectorPos:[l[0],l[1],l[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let x=[f/d,M/d,c/d],k=[b/v,w/v,m/v],F=u[0]-o[0],V=u[1]-o[1],T=u[2]-o[2],y=Math.hypot(F,V,T),A=y>1e-6?[F/y,V/y,T/y]:x,_=Math.abs(d-v)+1e-5,P=Math.max(_,d+v-1e-5),I=Math.max(_,Math.min(P,y>1e-6?y:_)),S=r((d*d+I*I-v*v)/(2*d*I),-1,1,1),R=Math.sqrt(Math.max(0,1-S*S)),N=h?h[0]-o[0]:f,U=h?h[1]-o[1]:M,J=h?h[2]-o[2]:c,B=N*A[0]+U*A[1]+J*A[2],E=N-A[0]*B,D=U-A[1]*B,j=J-A[2]*B,$=Math.hypot(E,D,j);if($<=1e-6){let gt=Math.abs(A[1])<.99?0:1,yt=Math.abs(A[1])<.99?1:0,Mt=0;E=A[1]*Mt-A[2]*yt,D=A[2]*gt-A[0]*Mt,j=A[0]*yt-A[1]*gt,$=Math.hypot(E,D,j)||1}let tt=[E/$,D/$,j/$],O=[o[0]+A[0]*(d*S)+tt[0]*(d*R),o[1]+A[1]*(d*S)+tt[1]*(d*R),o[2]+A[2]*(d*S)+tt[2]*(d*R)],et=[o[0]+A[0]*I,o[1]+A[1]*I,o[2]+A[2]*I],ct=et[0]-O[0],dt=et[1]-O[1],pt=et[2]-O[2],z=Math.hypot(ct,dt,pt),G=z>1e-6?[ct/z,dt/z,pt/z]:A,Et=[O[0]+G[0]*v,O[1]+G[1]*v,O[2]+G[2]*v],Wt=[(O[0]-o[0])/d,(O[1]-o[1])/d,(O[2]-o[2])/d];return{rootPos:[o[0],o[1],o[2]],midPos:O,effectorPos:Et,rootRotation:n(x,Wt),midRotation:n(k,G)}}function a(o,s,l=8,u=.001){let h=o.length;if(h<2)return{positions:o.map(y=>[y[0],y[1],y[2]]),rotations:[],iterations:0};let f=o.map(y=>[y[0],y[1],y[2]]),M=[],c=[],d=0;for(let y=0;y<h-1;y++){let A=f[y+1][0]-f[y][0],_=f[y+1][1]-f[y][1],P=f[y+1][2]-f[y][2],I=Math.hypot(A,_,P);M.push(I),d+=I,c.push(I>1e-6?[A/I,_/I,P/I]:[0,1,0])}let b=[f[0][0],f[0][1],f[0][2]],w=Math.round(r(l,1,32,8)),m=r(u,1e-5,.1,.001),v=s[0]-b[0],x=s[1]-b[1],k=s[2]-b[2],F=Math.hypot(v,x,k),V=0;if(F>=d&&d>1e-6){let y=F>1e-6?[v/F,x/F,k/F]:c[0];f[0]=[b[0],b[1],b[2]];for(let A=0;A<h-1;A++){let _=M[A];f[A+1]=[f[A][0]+y[0]*_,f[A][1]+y[1]*_,f[A][2]+y[2]*_]}V=1}else for(let y=1;y<=w;y++){let A=f[h-1];if(Math.hypot(A[0]-s[0],A[1]-s[1],A[2]-s[2])<=m)break;V=y;let _=(P,I,S,R,N)=>{let U=I[0]-P[0],J=I[1]-P[1],B=I[2]-P[2],E=Math.hypot(U,J,B);if(E>1e-6){let D=S/E;return[P[0]+U*D,P[1]+J*D,P[2]+B*D]}return[P[0]+R[0]*S*N,P[1]+R[1]*S*N,P[2]+R[2]*S*N]};f[h-1]=[s[0],s[1],s[2]];for(let P=h-2;P>=0;P--)f[P]=_(f[P+1],f[P],M[P],c[P],-1);f[0]=[b[0],b[1],b[2]];for(let P=0;P<h-1;P++)f[P+1]=_(f[P],f[P+1],M[P],c[P],1)}let T=[];for(let y=0;y<h-1;y++){let A=f[y+1][0]-f[y][0],_=f[y+1][1]-f[y][1],P=f[y+1][2]-f[y][2],I=Math.hypot(A,_,P),S=I>1e-6?[A/I,_/I,P/I]:c[y];T.push(n(c[y],S))}return{positions:f,rotations:T,iterations:V}}function g(o){if(!o||typeof o!="object"||Array.isArray(o))return null;let s=o;if(s.enabled===!1)return null;let l=m=>{if(typeof m!="string")return;let v=m.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(v)?v:void 0},u=m=>Array.isArray(m)&&m.length===3&&m.every(v=>typeof v=="number"&&Number.isFinite(v))?[r(m[0],-1e3,1e3,0),r(m[1],-1e3,1e3,0),r(m[2],-1e3,1e3,0)]:void 0,h=l(s.root),f=l(s.effector);if(!h||!f)return null;let M=l(s.mid),c=u(s.target)??l(s.target);if(!c)return null;let d=s.pole??s.poleTarget,b=u(d)??l(d),w=s.solver==="fabrik"?"fabrik":s.solver==="two-bone"||M?"two-bone":"fabrik";return{root:h,...M?{mid:M}:{},effector:f,target:c,...b?{pole:b}:{},solver:w,iterations:Math.round(r(s.iterations,1,32,8)),tolerance:r(s.tolerance,1e-5,.1,.001),weight:r(s.weight,0,1,1)}}let p=Object.freeze({solveTwoBone:i,solveFABRIK:a,parseIKTrait:g});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=p),{clampNum:r,parseIKTrait:g,quatFromUnitVectors:n,solveTwoBoneIK:i,solveFABRIK:a,IKSolver:p}}var K=it(),At=K.clampNum,Jt=K.parseIKTrait,ot=K.quatFromUnitVectors,vt=K.solveTwoBoneIK,xt=K.solveFABRIK,$t=K.IKSolver;function nt(t){let e=t?.transform??t?.modelMatrix;return e&&e.length>=16?[e[12]||0,e[13]||0,e[14]||0]:[0,0,0]}function Ct(t,e){let r=t?.transform??t?.modelMatrix;!r||r.length<16||(r[12]=e[0],r[13]=e[1],r[14]=e[2])}function qt(t,e,r,n,i){let a=At(i,0,1,1),g=e[0]+(r[0]-e[0])*a,p=e[1]+(r[1]-e[1])*a,o=e[2]+(r[2]-e[2])*a,s=g-t[0],l=p-t[1],u=o-t[2],h=Math.hypot(s,l,u);if(h>1e-6&&n>1e-6){let b=n/h;return[t[0]+s*b,t[1]+l*b,t[2]+u*b]}let f=r[0]-t[0],M=r[1]-t[1],c=r[2]-t[2],d=Math.hypot(f,M,c);if(d>1e-6&&n>1e-6){let b=n/d;return[t[0]+f*b,t[1]+M*b,t[2]+c*b]}return[g,p,o]}function Lt(t,e){let r=t?.modelRootMatrix;if(!r||r.length!==16)return e;let n=new Float32Array(16);return Kt(n,r instanceof Float32Array?r:Float32Array.from(r))?[n[0]*e[0]+n[4]*e[1]+n[8]*e[2]+n[12],n[1]*e[0]+n[5]*e[1]+n[9]*e[2]+n[13],n[2]*e[0]+n[6]*e[1]+n[10]*e[2]+n[14]]:e}function at(t,e){t.__ikWarned||(t.__ikWarned=new Set);let r=t.__ikWarned;r.has(e)||(r.add(e),console.warn(`[three-live] ik: joint '${e}' on '${t?.name??""}' not found among scene nodes or meshes.`))}function lt(t,e,r){if(Array.isArray(t))return[t[0],t[1],t[2]];let n=e.get(t);if(n)return nt(n);let i;if(t==="head"?i=r?.headPose?.position??r?.headPose??r?.cameraPosition:t==="hand-left"?i=r?.handPoses?.left?.position??r?.handPoses?.left??r?.hands?.left?.position??r?.hands?.left:t==="hand-right"&&(i=r?.handPoses?.right?.position??r?.handPoses?.right??r?.hands?.right?.position??r?.hands?.right),(Array.isArray(i)||ArrayBuffer.isView(i))&&i.length>=3){let a=i;return Lt(r,[a[0],a[1],a[2]])}return null}function st(t,e){return[t[3]*e[0]+t[0]*e[3]+t[1]*e[2]-t[2]*e[1],t[3]*e[1]-t[0]*e[2]+t[1]*e[3]+t[2]*e[0],t[3]*e[2]+t[0]*e[1]-t[1]*e[0]+t[2]*e[3],t[3]*e[3]-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]}function jt(t){return[-t[0],-t[1],-t[2],t[3]]}function ft(t){let e=Math.hypot(t[0],t[1],t[2],t[3]);return e>1e-12?[t[0]/e,t[1]/e,t[2]/e,t[3]/e]:[0,0,0,1]}function zt(t,e){if(e>=1)return t;if(e<=0)return[0,0,0,1];let[r,n,i,a]=t;a<0&&(r=-r,n=-n,i=-i,a=-a);let g=Math.acos(Math.min(1,a)),p=Math.sin(g);if(p<1e-9)return[0,0,0,1];let o=Math.sin(g*e)/p;return ft([r*o,n*o,i*o,Math.cos(g*e)])}function Gt(t){let e=Math.hypot(t[0],t[1],t[2])||1,r=Math.hypot(t[4],t[5],t[6])||1,n=Math.hypot(t[8],t[9],t[10])||1,i=t[0]/e,a=t[1]/e,g=t[2]/e,p=t[4]/r,o=t[5]/r,s=t[6]/r,l=t[8]/n,u=t[9]/n,h=t[10]/n,f=i+o+h,M;if(f>0){let c=Math.sqrt(f+1)*2;M=[(s-u)/c,(l-g)/c,(a-p)/c,.25*c]}else if(i>o&&i>h){let c=Math.sqrt(1+i-o-h)*2;M=[.25*c,(p+a)/c,(l+g)/c,(s-u)/c]}else if(o>h){let c=Math.sqrt(1+o-i-h)*2;M=[(p+a)/c,.25*c,(u+s)/c,(l-g)/c]}else{let c=Math.sqrt(1+h-i-o)*2;M=[(l+g)/c,(u+s)/c,.25*c,(a-p)/c]}return ft(M)}function Ht(t,e,r){let[n,i,a,g]=r,p=1-2*(i*i+a*a),o=2*(n*i-a*g),s=2*(n*a+i*g),l=2*(n*i+a*g),u=1-2*(n*n+a*a),h=2*(i*a-n*g),f=2*(n*a-i*g),M=2*(i*a+n*g),c=1-2*(n*n+i*i);for(let d=0;d<3;d++){let b=e[d*4],w=e[d*4+1],m=e[d*4+2];t[d*4]=p*b+o*w+s*m,t[d*4+1]=l*b+u*w+h*m,t[d*4+2]=f*b+M*w+c*m}}function Q(t,e){let r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=Math.hypot(r,n,i);return a>1e-9?[r/a,n/a,i/a]:null}function Tt(t){t?.normalMatrix&&t?.transform&&wt(t.normalMatrix,t.transform)}var It=new WeakMap;function Yt(t){let e=It.get(t);return e||(e=new Int32Array(t.nodes.length).fill(-1),t.nodes.forEach((r,n)=>{for(let i of Array.isArray(r?.children)?r.children:[])typeof i=="number"&&i>=0&&i<e.length&&(e[i]=n)}),It.set(t,e)),e}function Zt(t,e,r){let n=t?.gltf,i=n?.nodes;if(!Array.isArray(i)||i.length===0)return!1;let a=new Map;i.forEach((T,y)=>{typeof T?.name=="string"&&T.name&&!a.has(T.name)&&a.set(T.name,y)});let g=(e.mid?[e.root,e.mid,e.effector]:[e.root,e.effector]).map(T=>a.get(T));if(g.some(T=>T===void 0))return!1;let p=g,o=Yt(n);for(let T=1;T<p.length;T++){let y=o[p[T]],A=0;for(;y>=0&&y!==p[T-1]&&A++<256;)y=o[y];if(y!==p[T-1])return!1}let s=p[0],l=t.initialNodeTransforms,u=new Map,h=[],f=[s];for(;f.length&&h.length<4096;){let T=f.pop();if(u.has(T))continue;let y=l?.[T],A=i[T];u.set(T,{t:y?[y.t[0],y.t[1],y.t[2]]:A?.translation?[...A.translation]:[0,0,0],r:y?[y.r[0],y.r[1],y.r[2],y.r[3]]:A?.rotation?[...A.rotation]:[0,0,0,1],s:y?[y.s[0],y.s[1],y.s[2]]:A?.scale?[...A.scale]:[1,1,1]}),h.push(T);for(let _ of Array.isArray(A?.children)?A.children:[])typeof _=="number"&&f.push(_)}let M=o[s],c=M>=0&&t.worldMatrices?.[M]?.length===16?Float32Array.from(t.worldMatrices[M]):W(),d=new Map,b=()=>{let T=(y,A)=>{let _=u.get(y);if(!_)return;let P=W();rt(P,_.r,_.t,_.s);let I=W();bt(I,A,P),d.set(y,I);for(let S of Array.isArray(i[y]?.children)?i[y].children:[])typeof S=="number"&&T(S,I)};T(s,c)},w=T=>{let y=d.get(T);return[y[12],y[13],y[14]]};b();let m=p.map(w),v=T=>{if(typeof T=="string"&&!r.has(T)){let y=a.get(T),A=y!==void 0?d.get(y)??t.worldMatrices?.[y]:void 0;if(A&&A.length===16)return[A[12],A[13],A[14]]}return lt(T,r,t)},x=v(e.target);if(!x)return!0;let k=e.pole?v(e.pole)??void 0:void 0,F=Pt(m,e,x,k),V=At(e.weight,0,1,1);for(let T=0;T<p.length-1;T++){let y=Q(w(p[T]),w(p[T+1])),A=Q(F[T],F[T+1]);if(!y||!A)continue;let _=zt(ot(y,A),V),P=p[T],I=o[P],S=I===M||I<0?c:d.get(I)??c,R=Gt(S),N=u.get(P);N.r=ft(st(jt(R),st(_,st(R,N.r)))),b()}if(Array.isArray(t.worldMatrices))for(let[T,y]of d)t.worldMatrices[T]?.set&&t.worldMatrices[T].set(y);for(let T of t.meshes??[]){let y=d.get(T?.nodeIndex);y&&T.transform?.set&&(T.transform.set(y),Tt(T))}return!0}function Pt(t,e,r,n){if(e.solver==="two-bone"&&t.length===3){let i=vt(t[0],t[1],t[2],r,n);return[t[0],i.midPos,i.effectorPos]}return xt(t,r,e.iterations,e.tolerance).positions}function Qt(t,e,r){let n=t.__ikRestOffsets,i=t.__ikRestMats;if(!(!n||!i))for(let a=0;a<e.length-1;a++){let g=e[a]?.transform??e[a]?.modelMatrix,p=i[a],o=Q([0,0,0],n[a]),s=Q(r[a],r[a+1]);!g||g.length<16||!p||p.length<16||!o||!s||(Ht(g,p,ot(o,s)),Tt(e[a]))}}var kt={name:"ik",onRegister(){let t=Y();Bt(it),it(t.threeNamespace,t)},onUpdate(t){let e=t?.meshes;if(!Array.isArray(e)||e.length===0)return;let r=null;for(let n of e){let i=n?.userData?.xr?.ik??n?.extras?.xr?.ik??n?.extensions?.ANDROID_xr_scenecore?.ik;if(!i)continue;let a=Jt(i);if(!a||a.weight<=0)continue;if(!r){r=new Map;for(let m of e)m&&typeof m.name=="string"&&m.name&&r.set(m.name,m)}if(Zt(t,a,r))continue;let g=r.get(a.root),p=r.get(a.effector),o=a.mid?r.get(a.mid):void 0;if(g||at(n,a.root),p||at(n,a.effector),a.mid&&!o&&at(n,a.mid),!g||!p)continue;let s=lt(a.target,r,t);if(!s)continue;let l=a.pole?lt(a.pole,r,t)??void 0:void 0,u=o?[g,o,p]:[g,p],h=u.map(m=>m.name||"").join(">");if(!n.__ikRestOffsets||n.__ikRestKey!==h){let m=u.map(nt),v=[];for(let x=0;x<m.length-1;x++)v.push([m[x+1][0]-m[x][0],m[x+1][1]-m[x][1],m[x+1][2]-m[x][2]]);n.__ikRestOffsets=v,n.__ikRestKey=h,n.__ikRestMats=u.map(x=>Array.from(x.transform??x.modelMatrix??[]))}let f=n.__ikRestOffsets,M=[nt(g)],c=[];for(let m=0;m<f.length;m++){let v=M[m],x=f[m];M.push([v[0]+x[0],v[1]+x[1],v[2]+x[2]]),c.push(Math.hypot(x[0],x[1],x[2]))}let d=Pt(M,a,s,l),b=M[0],w=[M[0]];for(let m=1;m<u.length;m++){let v=f[m-1],x=[b[0]+v[0],b[1]+v[1],b[2]+v[2]],k=[b[0]+(d[m][0]-d[m-1][0]),b[1]+(d[m][1]-d[m-1][1]),b[2]+(d[m][2]-d[m-1][2])],F=qt(b,x,k,c[m-1],a.weight);Ct(u[m],F),b=F,w.push(F)}Qt(n,u,w)}}},Xt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function X(t,e,r,n){if(!r||r.bufferView===void 0)return null;let i=t.bufferViews?.[r.bufferView];if(!i)return null;let a=Number(r.count??0);if(!Number.isInteger(a)||a<=0)return null;let g=r.componentType??5126,p=Xt[g];if(!p)throw new RangeError(`glTF accessor has unsupported componentType ${g}`);let o=p*n,s=i.byteStride&&i.byteStride>0?i.byteStride:o,l=(i.byteOffset||0)+(r.byteOffset||0);if(!Number.isInteger(l)||l<0||s<o||l+(a-1)*s+o>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(g===5126&&s===o&&l%4===0)return new Float32Array(e,l,a*n);let u=new DataView(e),h=r.normalized===!0,f=new Float32Array(a*n);for(let M=0;M<a;M++){let c=l+M*s;for(let d=0;d<n;d++){let b=c+d*p,w;switch(g){case 5126:w=u.getFloat32(b,!0);break;case 5120:w=u.getInt8(b),h&&(w=Math.max(w/127,-1));break;case 5121:w=u.getUint8(b),h&&(w/=255);break;case 5122:w=u.getInt16(b,!0),h&&(w=Math.max(w/32767,-1));break;case 5123:w=u.getUint16(b,!0),h&&(w/=65535);break;default:w=u.getUint32(b,!0),h&&(w/=4294967295)}f[M*n+d]=w}}return f}function _t(t,e,r){return e%4===0?new Float32Array(t,e,r):new Float32Array(t.slice(e,e+r*4))}function Ft(t,e,r,n){let i=e[0],a=e[1],g=e[2],p=e[3],o=r[0],s=r[1],l=r[2],u=r[3],h=i*o+a*s+g*l+p*u;if(h<0&&(o=-o,s=-s,l=-l,u=-u,h=-h),Math.abs(h)>=1)return t[0]=i,t[1]=a,t[2]=g,t[3]=p,t;let f=Math.acos(h),M=Math.sqrt(1-h*h);if(Math.abs(M)<.001)return t[0]=.5*(i+o),t[1]=.5*(a+s),t[2]=.5*(g+l),t[3]=.5*(p+u),t;let c=Math.sin((1-n)*f)/M,d=Math.sin(n*f)/M;return t[0]=i*c+o*d,t[1]=a*c+s*d,t[2]=g*c+l*d,t[3]=p*c+u*d,t}function St(t,e,r,n){return t[0]=e[0]+n*(r[0]-e[0]),t[1]=e[1]+n*(r[1]-e[1]),t[2]=e[2]+n*(r[2]-e[2]),t}function Vt(t,e){if(!Array.isArray(t?.animations))return[];let r=[];for(let n=0;n<t.animations.length;n++){let i=t.animations[n],a=i.name||`Animation_${n}`,g=[],p=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let o of i.channels){if(!o.target||o.target.node===void 0||!o.target.path)continue;let s=i.samplers[o.sampler];if(!s)continue;let l=t.accessors?.[s.input],u=t.accessors?.[s.output];if(!l||!u)continue;let h=t.bufferViews?.[l.bufferView],f=t.bufferViews?.[u.bufferView];if(!h||!f)continue;let M=(h.byteOffset||0)+(l.byteOffset||0),c=(f.byteOffset||0)+(u.byteOffset||0),d=X(t,e,l,1)??_t(e,M,l.count);d.length>0&&d[d.length-1]>p&&(p=d[d.length-1]);let b=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(u.count/Math.max(1,l.count))):3,w=o.target.path==="weights"?1:b,m=X(t,e,u,w)??_t(e,c,u.count*w),v=s.interpolation==="STEP"?"STEP":"LINEAR";g.push({nodeIndex:o.target.node,path:o.target.path,times:d,values:m,interpolation:v})}g.length>0&&r.push({name:a,duration:p,channels:g})}return r}function C(t,e,r){let{times:n,values:i,path:a,interpolation:g}=t,p=n.length;if(p===0)return;let o=a==="rotation"?4:a==="weights"?Math.max(1,Math.round(i.length/p)):3;if(e<=n[0]){for(let w=0;w<o;w++)r[w]=i[w];return}if(e>=n[p-1]){let w=(p-1)*o;for(let m=0;m<o;m++)r[m]=i[w+m];return}let s=0,l=p-1;for(;s<=l;){let w=s+l>>1;n[w]<=e?s=w+1:l=w-1}let u=Math.max(0,l),h=Math.min(p-1,u+1);if(g==="STEP"||u===h){let w=u*o;for(let m=0;m<o;m++)r[m]=i[w+m];return}let f=n[u],M=n[h],c=(e-f)/Math.max(1e-5,M-f),d=u*o,b=h*o;if(a==="rotation"){let w=[i[d],i[d+1],i[d+2],i[d+3]],m=[i[b],i[b+1],i[b+2],i[b+3]];Ft(r,w,m,c)}else for(let w=0;w<o;w++)r[w]=i[d+w]+c*(i[b+w]-i[d+w])}var q=new WeakMap;function Rt(t,e,r=.3){if(!t?.animations)return;let n=t.animations.find(p=>p.name===e);if(!n)return;let i=q.get(t);i||(i=[],t.currentClip&&i.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),q.set(t,i));let a=r>0?1/r:1e3;for(let p of i)p.clip.name!==e&&(p.fadeSpeed=-a);let g=i.find(p=>p.clip.name===e);g?g.fadeSpeed=a:i.push({clip:n,time:0,weight:r>0?0:1,fadeSpeed:a}),t.currentClip=n,t.isPlayingAnimation=!0}function ut(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let r=q.get(t);if(!r||r.length===0){if(!t.currentClip)return;r=[{clip:t.currentClip,time:e,weight:1,fadeSpeed:0}]}let n=t.gltf.nodes.length,i=[];for(let u=0;u<n;u++){let h=t.initialNodeTransforms[u];h?i.push({t:[h.t[0],h.t[1],h.t[2]],r:[h.r[0],h.r[1],h.r[2],h.r[3]],s:[h.s[0],h.s[1],h.s[2]]}):i.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let a=[0,0,0],g=[0,0,0,1],p=[1,1,1],o=new Float32Array(64);for(let u of r){let h=Math.max(0,Math.min(1,u.weight));if(!(h<=1e-4))for(let f of u.clip.channels){if(f.nodeIndex<0||f.nodeIndex>=n)continue;let M=i[f.nodeIndex];if(f.path==="translation")C(f,u.time,a),St(M.t,M.t,a,h);else if(f.path==="rotation")C(f,u.time,g),Ft(M.r,M.r,g,h);else if(f.path==="scale")C(f,u.time,p),St(M.s,M.s,p,h);else if(f.path==="weights"&&(C(f,u.time,o),t.meshes)){for(let c of t.meshes)if(c.nodeIndex===f.nodeIndex){for(let d of c.primitives)if(d.pluginData?.morph?.weights){let b=d.pluginData.morph.weights,w=d.pluginData.morph.numTargets||b.length;for(let m=0;m<w;m++)b[m]=b[m]*(1-h)+o[m]*h}}}}}let s=[];for(let u=0;u<n;u++){let h=W(),{t:f,r:M,s:c}=i[u];rt(h,M,f,c),s.push(h)}let l=Ut(t.gltf,s);t.worldMatrices=l;for(let u of t.meshes)u.nodeIndex>=0&&u.nodeIndex<l.length&&(u.transform.set(l[u.nodeIndex]),wt(u.normalMatrix,u.transform))}var ht=t=>{q.delete(t)},Ot={name:"keyframes",evaluateAnimation:ut,crossFadeTo:Rt,onParseGLB(t){!t.animations&&t.gltf?.animations&&(t.animations=Vt(t.gltf,t.bin))},onLoadModel:ht,onClearScene:ht,onDestroy:(t,e)=>ht(e),onUpdate(t,e){if(!t.isPlayingAnimation)return;let r=q.get(t);if(r&&r.length>0){for(let n=r.length-1;n>=0;n--){let i=r[n];if(i.time+=e,i.clip.duration>0&&(i.time%=i.clip.duration),i.fadeSpeed!==0)if(i.weight+=i.fadeSpeed*e,i.weight<=0){r.splice(n,1);continue}else i.weight>=1&&(i.weight=1,i.fadeSpeed=0)}r.length>0&&(t.animationTime=r[r.length-1].time),ut(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),ut(t,t.animationTime))}},L=64;function te(t,e,r){if(!(!t?.meshes||e<0||e>=L))for(let n of t.meshes)for(let i of n.primitives){let a=i.pluginData?.morph;a?.weights&&(a.weights[e]=r)}}var Nt={name:"morph",onResolveShader(t,e,r,n){if(!Array.isArray(t?.targets)||t.targets.length===0)return null;let i=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
16
+ */var H="__THREE_LIVE_REGISTRY__";function Y(){let t=typeof globalThis<"u"?globalThis:{};if(!t[H]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,H,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[H]=e}}return t[H]}var ee=Y().plugins;function Wt(t){let e=Y();e.workerExtensionInstallers||(e.workerExtensionInstallers=[]),e.workerExtensionInstallers.includes(t)||e.workerExtensionInstallers.push(t)}function Z(t){let e=Y().plugins;e.some(r=>r.name===t.name)||e.push(t),t.onRegister?.()}function B(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function wt(t,e,r){let n=e[0],i=e[1],a=e[2],g=e[3],d=e[4],o=e[5],s=e[6],l=e[7],u=e[8],h=e[9],f=e[10],M=e[11],c=e[12],p=e[13],w=e[14],A=e[15],m=r[0],v=r[1],x=r[2],k=r[3];return t[0]=m*n+v*d+x*u+k*c,t[1]=m*i+v*o+x*h+k*p,t[2]=m*a+v*s+x*f+k*w,t[3]=m*g+v*l+x*M+k*A,m=r[4],v=r[5],x=r[6],k=r[7],t[4]=m*n+v*d+x*u+k*c,t[5]=m*i+v*o+x*h+k*p,t[6]=m*a+v*s+x*f+k*w,t[7]=m*g+v*l+x*M+k*A,m=r[8],v=r[9],x=r[10],k=r[11],t[8]=m*n+v*d+x*u+k*c,t[9]=m*i+v*o+x*h+k*p,t[10]=m*a+v*s+x*f+k*w,t[11]=m*g+v*l+x*M+k*A,m=r[12],v=r[13],x=r[14],k=r[15],t[12]=m*n+v*d+x*u+k*c,t[13]=m*i+v*o+x*h+k*p,t[14]=m*a+v*s+x*f+k*w,t[15]=m*g+v*l+x*M+k*A,t}function rt(t,e,r,n){let i=e[0],a=e[1],g=e[2],d=e[3],o=i+i,s=a+a,l=g+g,u=i*o,h=i*s,f=i*l,M=a*s,c=a*l,p=g*l,w=d*o,A=d*s,m=d*l,v=n[0],x=n[1],k=n[2];return t[0]=(1-(M+p))*v,t[1]=(h+m)*v,t[2]=(f-A)*v,t[3]=0,t[4]=(h-m)*x,t[5]=(1-(u+p))*x,t[6]=(c+w)*x,t[7]=0,t[8]=(f+A)*k,t[9]=(c-w)*k,t[10]=(1-(u+M))*k,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function At(t,e,r=0){let n=e[0],i=e[1],a=e[2],g=e[4],d=e[5],o=e[6],s=e[8],l=e[9],u=e[10],h=u*d-o*l,f=-u*g+o*s,M=l*g-d*s,c=n*h+i*f+a*M;return!c||r>0&&(!Number.isFinite(c)||Math.abs(c)<=r)||(c=1/c,t[0]=h*c,t[1]=f*c,t[2]=M*c,t[3]=(-u*i+a*l)*c,t[4]=(u*n-a*s)*c,t[5]=(-l*n+i*s)*c,t[6]=(o*i-a*d)*c,t[7]=(-o*n+a*g)*c,t[8]=(d*n-i*g)*c),t}function Kt(t,e){let r=e[0],n=e[1],i=e[2],a=e[3],g=e[4],d=e[5],o=e[6],s=e[7],l=e[8],u=e[9],h=e[10],f=e[11],M=e[12],c=e[13],p=e[14],w=e[15],A=r*d-n*g,m=r*o-i*g,v=r*s-a*g,x=n*o-i*d,k=n*s-a*d,_=i*s-a*o,R=l*c-u*M,T=l*p-h*M,y=l*w-f*M,b=u*p-h*c,S=u*w-f*c,I=h*w-f*p,P=A*I-m*S+v*b+x*y-k*T+_*R;return P?(P=1/P,t[0]=(d*I-o*S+s*b)*P,t[1]=(i*S-n*I-a*b)*P,t[2]=(c*_-p*k+w*x)*P,t[3]=(h*k-u*_-f*x)*P,t[4]=(o*y-g*I-s*T)*P,t[5]=(r*I-i*y+a*T)*P,t[6]=(p*v-M*_-w*m)*P,t[7]=(l*_-h*v+f*m)*P,t[8]=(g*S-d*y+s*R)*P,t[9]=(n*y-r*S-a*R)*P,t[10]=(M*k-c*v+w*A)*P,t[11]=(u*v-l*k-f*A)*P,t[12]=(d*T-g*b-o*R)*P,t[13]=(r*b-n*T+i*R)*P,t[14]=(c*m-M*x-p*A)*P,t[15]=(l*x-u*m+h*A)*P,t):null}function Ut(t,e){let r=Array.isArray(t?.nodes)?t.nodes.length:0,n=[];for(let l=0;l<r;l++)n.push(B());if(r===0)return n;let i=new Set;for(let l of t.nodes)if(Array.isArray(l.children))for(let u of l.children)i.add(u);let a=new Set,g=128,d=(l,u,h=0)=>{if(h>g||l<0||l>=r||a.has(l))return;a.add(l);let f=t.nodes[l];if(!f)return;let M=B();if(e&&e[l])M.set(e[l]);else if(f.matrix&&f.matrix.length===16)M.set(f.matrix);else{let p=f.translation||[0,0,0],w=f.rotation||[0,0,0,1],A=f.scale||[1,1,1];rt(M,w,p,A)}let c=n[l];if(u?wt(c,u,M):c.set(M),Array.isArray(f.children))for(let p of f.children)typeof p=="number"&&d(p,c,h+1)},o=[],s=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(s&&Array.isArray(s.nodes))o.push(...s.nodes);else for(let l=0;l<r;l++)i.has(l)||o.push(l);for(let l of o)d(l,null);for(let l=0;l<r;l++)!i.has(l)&&!o.includes(l)&&d(l,null);return n}function it(t,e){function r(o,s,l,u){let h=typeof o=="number"?o:Number(o);return Number.isFinite(h)?Math.max(s,Math.min(l,h)):u}function n(o,s){let l=o[0]*s[0]+o[1]*s[1]+o[2]*s[2]+1;if(l<1e-6){if(Math.abs(o[0])>Math.abs(o[2])){let p=Math.hypot(o[1],o[0])||1;return[-o[1]/p,o[0]/p,0,0]}let c=Math.hypot(o[2],o[1])||1;return[0,-o[2]/c,o[1]/c,0]}let u=o[1]*s[2]-o[2]*s[1],h=o[2]*s[0]-o[0]*s[2],f=o[0]*s[1]-o[1]*s[0],M=Math.hypot(u,h,f,l)||1;return[u/M,h/M,f/M,l/M]}function i(o,s,l,u,h){let f=s[0]-o[0],M=s[1]-o[1],c=s[2]-o[2],p=Math.hypot(f,M,c),w=l[0]-s[0],A=l[1]-s[1],m=l[2]-s[2],v=Math.hypot(w,A,m);if(p<1e-6||v<1e-6)return{rootPos:[o[0],o[1],o[2]],midPos:[s[0],s[1],s[2]],effectorPos:[l[0],l[1],l[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let x=[f/p,M/p,c/p],k=[w/v,A/v,m/v],_=u[0]-o[0],R=u[1]-o[1],T=u[2]-o[2],y=Math.hypot(_,R,T),b=y>1e-6?[_/y,R/y,T/y]:x,S=Math.abs(p-v)+1e-5,I=Math.max(S,p+v-1e-5),P=Math.max(S,Math.min(I,y>1e-6?y:S)),F=r((p*p+P*P-v*v)/(2*p*P),-1,1,1),V=Math.sqrt(Math.max(0,1-F*F)),N=h?h[0]-o[0]:f,U=h?h[1]-o[1]:M,J=h?h[2]-o[2]:c,W=N*b[0]+U*b[1]+J*b[2],E=N-b[0]*W,D=U-b[1]*W,j=J-b[2]*W,L=Math.hypot(E,D,j);if(L<=1e-6){let gt=Math.abs(b[1])<.99?0:1,yt=Math.abs(b[1])<.99?1:0,Mt=0;E=b[1]*Mt-b[2]*yt,D=b[2]*gt-b[0]*Mt,j=b[0]*yt-b[1]*gt,L=Math.hypot(E,D,j)||1}let tt=[E/L,D/L,j/L],O=[o[0]+b[0]*(p*F)+tt[0]*(p*V),o[1]+b[1]*(p*F)+tt[1]*(p*V),o[2]+b[2]*(p*F)+tt[2]*(p*V)],et=[o[0]+b[0]*P,o[1]+b[1]*P,o[2]+b[2]*P],ct=et[0]-O[0],pt=et[1]-O[1],dt=et[2]-O[2],z=Math.hypot(ct,pt,dt),G=z>1e-6?[ct/z,pt/z,dt/z]:b,Et=[O[0]+G[0]*v,O[1]+G[1]*v,O[2]+G[2]*v],Bt=[(O[0]-o[0])/p,(O[1]-o[1])/p,(O[2]-o[2])/p];return{rootPos:[o[0],o[1],o[2]],midPos:O,effectorPos:Et,rootRotation:n(x,Bt),midRotation:n(k,G)}}function a(o,s,l=8,u=.001){let h=o.length;if(h<2)return{positions:o.map(y=>[y[0],y[1],y[2]]),rotations:[],iterations:0};let f=o.map(y=>[y[0],y[1],y[2]]),M=[],c=[],p=0;for(let y=0;y<h-1;y++){let b=f[y+1][0]-f[y][0],S=f[y+1][1]-f[y][1],I=f[y+1][2]-f[y][2],P=Math.hypot(b,S,I);M.push(P),p+=P,c.push(P>1e-6?[b/P,S/P,I/P]:[0,1,0])}let w=[f[0][0],f[0][1],f[0][2]],A=Math.round(r(l,1,32,8)),m=r(u,1e-5,.1,.001),v=s[0]-w[0],x=s[1]-w[1],k=s[2]-w[2],_=Math.hypot(v,x,k),R=0;if(_>=p&&p>1e-6){let y=_>1e-6?[v/_,x/_,k/_]:c[0];f[0]=[w[0],w[1],w[2]];for(let b=0;b<h-1;b++){let S=M[b];f[b+1]=[f[b][0]+y[0]*S,f[b][1]+y[1]*S,f[b][2]+y[2]*S]}R=1}else for(let y=1;y<=A;y++){let b=f[h-1];if(Math.hypot(b[0]-s[0],b[1]-s[1],b[2]-s[2])<=m)break;R=y;let S=(I,P,F,V,N)=>{let U=P[0]-I[0],J=P[1]-I[1],W=P[2]-I[2],E=Math.hypot(U,J,W);if(E>1e-6){let D=F/E;return[I[0]+U*D,I[1]+J*D,I[2]+W*D]}return[I[0]+V[0]*F*N,I[1]+V[1]*F*N,I[2]+V[2]*F*N]};f[h-1]=[s[0],s[1],s[2]];for(let I=h-2;I>=0;I--)f[I]=S(f[I+1],f[I],M[I],c[I],-1);f[0]=[w[0],w[1],w[2]];for(let I=0;I<h-1;I++)f[I+1]=S(f[I],f[I+1],M[I],c[I],1)}let T=[];for(let y=0;y<h-1;y++){let b=f[y+1][0]-f[y][0],S=f[y+1][1]-f[y][1],I=f[y+1][2]-f[y][2],P=Math.hypot(b,S,I),F=P>1e-6?[b/P,S/P,I/P]:c[y];T.push(n(c[y],F))}return{positions:f,rotations:T,iterations:R}}function g(o){if(!o||typeof o!="object"||Array.isArray(o))return null;let s=o;if(s.enabled===!1)return null;let l=m=>{if(typeof m!="string")return;let v=m.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(v)?v:void 0},u=m=>Array.isArray(m)&&m.length===3&&m.every(v=>typeof v=="number"&&Number.isFinite(v))?[r(m[0],-1e3,1e3,0),r(m[1],-1e3,1e3,0),r(m[2],-1e3,1e3,0)]:void 0,h=l(s.root),f=l(s.effector);if(!h||!f)return null;let M=l(s.mid),c=u(s.target)??l(s.target);if(!c)return null;let p=s.pole??s.poleTarget,w=u(p)??l(p),A=s.solver==="fabrik"?"fabrik":s.solver==="two-bone"||M?"two-bone":"fabrik";return{root:h,...M?{mid:M}:{},effector:f,target:c,...w?{pole:w}:{},solver:A,iterations:Math.round(r(s.iterations,1,32,8)),tolerance:r(s.tolerance,1e-5,.1,.001),weight:r(s.weight,0,1,1)}}let d=Object.freeze({solveTwoBone:i,solveFABRIK:a,parseIKTrait:g});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=d),{clampNum:r,parseIKTrait:g,quatFromUnitVectors:n,solveTwoBoneIK:i,solveFABRIK:a,IKSolver:d}}var K=it(),bt=K.clampNum,Jt=K.parseIKTrait,ot=K.quatFromUnitVectors,vt=K.solveTwoBoneIK,xt=K.solveFABRIK,Lt=K.IKSolver;function nt(t){let e=t?.transform??t?.modelMatrix;return e&&e.length>=16?[e[12]||0,e[13]||0,e[14]||0]:[0,0,0]}function $t(t,e){let r=t?.transform??t?.modelMatrix;!r||r.length<16||(r[12]=e[0],r[13]=e[1],r[14]=e[2])}function Ct(t,e,r,n,i){let a=bt(i,0,1,1),g=e[0]+(r[0]-e[0])*a,d=e[1]+(r[1]-e[1])*a,o=e[2]+(r[2]-e[2])*a,s=g-t[0],l=d-t[1],u=o-t[2],h=Math.hypot(s,l,u);if(h>1e-6&&n>1e-6){let w=n/h;return[t[0]+s*w,t[1]+l*w,t[2]+u*w]}let f=r[0]-t[0],M=r[1]-t[1],c=r[2]-t[2],p=Math.hypot(f,M,c);if(p>1e-6&&n>1e-6){let w=n/p;return[t[0]+f*w,t[1]+M*w,t[2]+c*w]}return[g,d,o]}function qt(t,e){let r=t?.modelRootMatrix;if(!r||r.length!==16)return e;let n=new Float32Array(16);return Kt(n,r instanceof Float32Array?r:Float32Array.from(r))?[n[0]*e[0]+n[4]*e[1]+n[8]*e[2]+n[12],n[1]*e[0]+n[5]*e[1]+n[9]*e[2]+n[13],n[2]*e[0]+n[6]*e[1]+n[10]*e[2]+n[14]]:e}function at(t,e){t.__ikWarned||(t.__ikWarned=new Set);let r=t.__ikWarned;r.has(e)||(r.add(e),console.warn(`[three-live] ik: joint '${e}' on '${t?.name??""}' not found among scene nodes or meshes.`))}function lt(t,e,r){if(Array.isArray(t))return[t[0],t[1],t[2]];let n=e.get(t);if(n)return nt(n);let i;if(t==="head"?i=r?.headPose?.position??r?.headPose??r?.cameraPosition:t==="hand-left"?i=r?.handPoses?.left?.position??r?.handPoses?.left??r?.hands?.left?.position??r?.hands?.left:t==="hand-right"&&(i=r?.handPoses?.right?.position??r?.handPoses?.right??r?.hands?.right?.position??r?.hands?.right),(Array.isArray(i)||ArrayBuffer.isView(i))&&i.length>=3){let a=i;return qt(r,[a[0],a[1],a[2]])}return null}function st(t,e){return[t[3]*e[0]+t[0]*e[3]+t[1]*e[2]-t[2]*e[1],t[3]*e[1]-t[0]*e[2]+t[1]*e[3]+t[2]*e[0],t[3]*e[2]+t[0]*e[1]-t[1]*e[0]+t[2]*e[3],t[3]*e[3]-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]}function jt(t){return[-t[0],-t[1],-t[2],t[3]]}function ft(t){let e=Math.hypot(t[0],t[1],t[2],t[3]);return e>1e-12?[t[0]/e,t[1]/e,t[2]/e,t[3]/e]:[0,0,0,1]}function zt(t,e){if(e>=1)return t;if(e<=0)return[0,0,0,1];let[r,n,i,a]=t;a<0&&(r=-r,n=-n,i=-i,a=-a);let g=Math.acos(Math.min(1,a)),d=Math.sin(g);if(d<1e-9)return[0,0,0,1];let o=Math.sin(g*e)/d;return ft([r*o,n*o,i*o,Math.cos(g*e)])}function Gt(t){let e=Math.hypot(t[0],t[1],t[2])||1,r=Math.hypot(t[4],t[5],t[6])||1,n=Math.hypot(t[8],t[9],t[10])||1,i=t[0]/e,a=t[1]/e,g=t[2]/e,d=t[4]/r,o=t[5]/r,s=t[6]/r,l=t[8]/n,u=t[9]/n,h=t[10]/n,f=i+o+h,M;if(f>0){let c=Math.sqrt(f+1)*2;M=[(s-u)/c,(l-g)/c,(a-d)/c,.25*c]}else if(i>o&&i>h){let c=Math.sqrt(1+i-o-h)*2;M=[.25*c,(d+a)/c,(l+g)/c,(s-u)/c]}else if(o>h){let c=Math.sqrt(1+o-i-h)*2;M=[(d+a)/c,.25*c,(u+s)/c,(l-g)/c]}else{let c=Math.sqrt(1+h-i-o)*2;M=[(l+g)/c,(u+s)/c,.25*c,(a-d)/c]}return ft(M)}function Ht(t,e,r){let[n,i,a,g]=r,d=1-2*(i*i+a*a),o=2*(n*i-a*g),s=2*(n*a+i*g),l=2*(n*i+a*g),u=1-2*(n*n+a*a),h=2*(i*a-n*g),f=2*(n*a-i*g),M=2*(i*a+n*g),c=1-2*(n*n+i*i);for(let p=0;p<3;p++){let w=e[p*4],A=e[p*4+1],m=e[p*4+2];t[p*4]=d*w+o*A+s*m,t[p*4+1]=l*w+u*A+h*m,t[p*4+2]=f*w+M*A+c*m}}function Q(t,e){let r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],a=Math.hypot(r,n,i);return a>1e-9?[r/a,n/a,i/a]:null}function Tt(t){t?.normalMatrix&&t?.transform&&At(t.normalMatrix,t.transform)}var Pt=new WeakMap;function Yt(t){let e=Pt.get(t);return e||(e=new Int32Array(t.nodes.length).fill(-1),t.nodes.forEach((r,n)=>{for(let i of Array.isArray(r?.children)?r.children:[])typeof i=="number"&&i>=0&&i<e.length&&(e[i]=n)}),Pt.set(t,e)),e}function Zt(t,e,r){let n=t?.gltf,i=n?.nodes;if(!Array.isArray(i)||i.length===0)return!1;let a=new Map;i.forEach((T,y)=>{typeof T?.name=="string"&&T.name&&!a.has(T.name)&&a.set(T.name,y)});let g=(e.mid?[e.root,e.mid,e.effector]:[e.root,e.effector]).map(T=>a.get(T));if(g.some(T=>T===void 0))return!1;let d=g,o=Yt(n);for(let T=1;T<d.length;T++){let y=o[d[T]],b=0;for(;y>=0&&y!==d[T-1]&&b++<256;)y=o[y];if(y!==d[T-1])return!1}let s=d[0],l=t.initialNodeTransforms,u=new Map,h=[],f=[s];for(;f.length&&h.length<4096;){let T=f.pop();if(u.has(T))continue;let y=l?.[T],b=i[T];u.set(T,{t:y?[y.t[0],y.t[1],y.t[2]]:b?.translation?[...b.translation]:[0,0,0],r:y?[y.r[0],y.r[1],y.r[2],y.r[3]]:b?.rotation?[...b.rotation]:[0,0,0,1],s:y?[y.s[0],y.s[1],y.s[2]]:b?.scale?[...b.scale]:[1,1,1]}),h.push(T);for(let S of Array.isArray(b?.children)?b.children:[])typeof S=="number"&&f.push(S)}let M=o[s],c=M>=0&&t.worldMatrices?.[M]?.length===16?Float32Array.from(t.worldMatrices[M]):B(),p=new Map,w=()=>{let T=(y,b)=>{let S=u.get(y);if(!S)return;let I=B();rt(I,S.r,S.t,S.s);let P=B();wt(P,b,I),p.set(y,P);for(let F of Array.isArray(i[y]?.children)?i[y].children:[])typeof F=="number"&&T(F,P)};T(s,c)},A=T=>{let y=p.get(T);return[y[12],y[13],y[14]]};w();let m=d.map(A),v=T=>{if(typeof T=="string"&&!r.has(T)){let y=a.get(T),b=y!==void 0?p.get(y)??t.worldMatrices?.[y]:void 0;if(b&&b.length===16)return[b[12],b[13],b[14]]}return lt(T,r,t)},x=v(e.target);if(!x)return!0;let k=e.pole?v(e.pole)??void 0:void 0,_=It(m,e,x,k),R=bt(e.weight,0,1,1);for(let T=0;T<d.length-1;T++){let y=Q(A(d[T]),A(d[T+1])),b=Q(_[T],_[T+1]);if(!y||!b)continue;let S=zt(ot(y,b),R),I=d[T],P=o[I],F=P===M||P<0?c:p.get(P)??c,V=Gt(F),N=u.get(I);N.r=ft(st(jt(V),st(S,st(V,N.r)))),w()}if(Array.isArray(t.worldMatrices))for(let[T,y]of p)t.worldMatrices[T]?.set&&t.worldMatrices[T].set(y);for(let T of t.meshes??[]){let y=p.get(T?.nodeIndex);y&&T.transform?.set&&(T.transform.set(y),Tt(T))}return!0}function It(t,e,r,n){if(e.solver==="two-bone"&&t.length===3){let i=vt(t[0],t[1],t[2],r,n);return[t[0],i.midPos,i.effectorPos]}return xt(t,r,e.iterations,e.tolerance).positions}function Qt(t,e,r){let n=t.__ikRestOffsets,i=t.__ikRestMats;if(!(!n||!i))for(let a=0;a<e.length-1;a++){let g=e[a]?.transform??e[a]?.modelMatrix,d=i[a],o=Q([0,0,0],n[a]),s=Q(r[a],r[a+1]);!g||g.length<16||!d||d.length<16||!o||!s||(Ht(g,d,ot(o,s)),Tt(e[a]))}}var kt={name:"ik",onRegister(){let t=Y();Wt(it),it(t.threeNamespace,t)},onUpdate(t){let e=t?.meshes;if(!Array.isArray(e)||e.length===0)return;let r=null;for(let n of e){let i=n?.userData?.xr?.ik??n?.extras?.xr?.ik??n?.extensions?.ANDROID_xr_scenecore?.ik;if(!i)continue;let a=Jt(i);if(!a||a.weight<=0)continue;if(!r){r=new Map;for(let m of e)m&&typeof m.name=="string"&&m.name&&r.set(m.name,m)}if(Zt(t,a,r))continue;let g=r.get(a.root),d=r.get(a.effector),o=a.mid?r.get(a.mid):void 0;if(g||at(n,a.root),d||at(n,a.effector),a.mid&&!o&&at(n,a.mid),!g||!d)continue;let s=lt(a.target,r,t);if(!s)continue;let l=a.pole?lt(a.pole,r,t)??void 0:void 0,u=o?[g,o,d]:[g,d],h=u.map(m=>m.name||"").join(">");if(!n.__ikRestOffsets||n.__ikRestKey!==h){let m=u.map(nt),v=[];for(let x=0;x<m.length-1;x++)v.push([m[x+1][0]-m[x][0],m[x+1][1]-m[x][1],m[x+1][2]-m[x][2]]);n.__ikRestOffsets=v,n.__ikRestKey=h,n.__ikRestMats=u.map(x=>Array.from(x.transform??x.modelMatrix??[]))}let f=n.__ikRestOffsets,M=[nt(g)],c=[];for(let m=0;m<f.length;m++){let v=M[m],x=f[m];M.push([v[0]+x[0],v[1]+x[1],v[2]+x[2]]),c.push(Math.hypot(x[0],x[1],x[2]))}let p=It(M,a,s,l),w=M[0],A=[M[0]];for(let m=1;m<u.length;m++){let v=f[m-1],x=[w[0]+v[0],w[1]+v[1],w[2]+v[2]],k=[w[0]+(p[m][0]-p[m-1][0]),w[1]+(p[m][1]-p[m-1][1]),w[2]+(p[m][2]-p[m-1][2])],_=Ct(w,x,k,c[m-1],a.weight);$t(u[m],_),w=_,A.push(_)}Qt(n,u,A)}}},Xt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function X(t,e,r,n){if(!r||r.bufferView===void 0)return null;let i=t.bufferViews?.[r.bufferView];if(!i)return null;let a=Number(r.count??0);if(!Number.isInteger(a)||a<=0)return null;let g=r.componentType??5126,d=Xt[g];if(!d)throw new RangeError(`glTF accessor has unsupported componentType ${g}`);let o=d*n,s=i.byteStride&&i.byteStride>0?i.byteStride:o,l=(i.byteOffset||0)+(r.byteOffset||0);if(!Number.isInteger(l)||l<0||s<o||l+(a-1)*s+o>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(g===5126&&s===o&&l%4===0)return new Float32Array(e,l,a*n);let u=new DataView(e),h=r.normalized===!0,f=new Float32Array(a*n);for(let M=0;M<a;M++){let c=l+M*s;for(let p=0;p<n;p++){let w=c+p*d,A;switch(g){case 5126:A=u.getFloat32(w,!0);break;case 5120:A=u.getInt8(w),h&&(A=Math.max(A/127,-1));break;case 5121:A=u.getUint8(w),h&&(A/=255);break;case 5122:A=u.getInt16(w,!0),h&&(A=Math.max(A/32767,-1));break;case 5123:A=u.getUint16(w,!0),h&&(A/=65535);break;default:A=u.getUint32(w,!0),h&&(A/=4294967295)}f[M*n+p]=A}}return f}function St(t,e,r){return e%4===0?new Float32Array(t,e,r):new Float32Array(t.slice(e,e+r*4))}function _t(t,e,r,n){let i=e[0],a=e[1],g=e[2],d=e[3],o=r[0],s=r[1],l=r[2],u=r[3],h=i*o+a*s+g*l+d*u;if(h<0&&(o=-o,s=-s,l=-l,u=-u,h=-h),Math.abs(h)>=1)return t[0]=i,t[1]=a,t[2]=g,t[3]=d,t;let f=Math.acos(h),M=Math.sqrt(1-h*h);if(Math.abs(M)<.001)return t[0]=.5*(i+o),t[1]=.5*(a+s),t[2]=.5*(g+l),t[3]=.5*(d+u),t;let c=Math.sin((1-n)*f)/M,p=Math.sin(n*f)/M;return t[0]=i*c+o*p,t[1]=a*c+s*p,t[2]=g*c+l*p,t[3]=d*c+u*p,t}function Ft(t,e,r,n){return t[0]=e[0]+n*(r[0]-e[0]),t[1]=e[1]+n*(r[1]-e[1]),t[2]=e[2]+n*(r[2]-e[2]),t}function Rt(t,e){if(!Array.isArray(t?.animations))return[];let r=[];for(let n=0;n<t.animations.length;n++){let i=t.animations[n],a=i.name||`Animation_${n}`,g=[],d=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let o of i.channels){if(!o.target||o.target.node===void 0||!o.target.path)continue;let s=i.samplers[o.sampler];if(!s)continue;let l=t.accessors?.[s.input],u=t.accessors?.[s.output];if(!l||!u)continue;let h=t.bufferViews?.[l.bufferView],f=t.bufferViews?.[u.bufferView];if(!h||!f)continue;let M=(h.byteOffset||0)+(l.byteOffset||0),c=(f.byteOffset||0)+(u.byteOffset||0),p=X(t,e,l,1)??St(e,M,l.count);p.length>0&&p[p.length-1]>d&&(d=p[p.length-1]);let w=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(u.count/Math.max(1,l.count))):3,A=o.target.path==="weights"?1:w,m=X(t,e,u,A)??St(e,c,u.count*A),v=s.interpolation==="STEP"?"STEP":"LINEAR";g.push({nodeIndex:o.target.node,path:o.target.path,times:p,values:m,interpolation:v})}g.length>0&&r.push({name:a,duration:d,channels:g})}return r}function $(t,e,r){let{times:n,values:i,path:a,interpolation:g}=t,d=n.length;if(d===0)return;let o=a==="rotation"?4:a==="weights"?Math.max(1,Math.round(i.length/d)):3;if(e<=n[0]){for(let A=0;A<o;A++)r[A]=i[A];return}if(e>=n[d-1]){let A=(d-1)*o;for(let m=0;m<o;m++)r[m]=i[A+m];return}let s=0,l=d-1;for(;s<=l;){let A=s+l>>1;n[A]<=e?s=A+1:l=A-1}let u=Math.max(0,l),h=Math.min(d-1,u+1);if(g==="STEP"||u===h){let A=u*o;for(let m=0;m<o;m++)r[m]=i[A+m];return}let f=n[u],M=n[h],c=(e-f)/Math.max(1e-5,M-f),p=u*o,w=h*o;if(a==="rotation"){let A=[i[p],i[p+1],i[p+2],i[p+3]],m=[i[w],i[w+1],i[w+2],i[w+3]];_t(r,A,m,c)}else for(let A=0;A<o;A++)r[A]=i[p+A]+c*(i[w+A]-i[p+A])}var C=new WeakMap;function Vt(t,e,r=.3){if(!t?.animations)return;let n=t.animations.find(d=>d.name===e);if(!n)return;let i=C.get(t);i||(i=[],t.currentClip&&i.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),C.set(t,i));let a=r>0?1/r:1e3;for(let d of i)d.clip.name!==e&&(d.fadeSpeed=-a);let g=i.find(d=>d.clip.name===e);g?g.fadeSpeed=a:i.push({clip:n,time:0,weight:r>0?0:1,fadeSpeed:a}),t.currentClip=n,t.isPlayingAnimation=!0}function ut(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let r=C.get(t);if(!r||r.length===0){if(!t.currentClip)return;r=[{clip:t.currentClip,time:e,weight:1,fadeSpeed:0}]}let n=t.gltf.nodes.length,i=[];for(let u=0;u<n;u++){let h=t.initialNodeTransforms[u];h?i.push({t:[h.t[0],h.t[1],h.t[2]],r:[h.r[0],h.r[1],h.r[2],h.r[3]],s:[h.s[0],h.s[1],h.s[2]]}):i.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let a=[0,0,0],g=[0,0,0,1],d=[1,1,1],o=new Float32Array(64);for(let u of r){let h=Math.max(0,Math.min(1,u.weight));if(!(h<=1e-4))for(let f of u.clip.channels){if(f.nodeIndex<0||f.nodeIndex>=n)continue;let M=i[f.nodeIndex];if(f.path==="translation")$(f,u.time,a),Ft(M.t,M.t,a,h);else if(f.path==="rotation")$(f,u.time,g),_t(M.r,M.r,g,h);else if(f.path==="scale")$(f,u.time,d),Ft(M.s,M.s,d,h);else if(f.path==="weights"&&($(f,u.time,o),t.meshes)){for(let c of t.meshes)if(c.nodeIndex===f.nodeIndex){for(let p of c.primitives)if(p.pluginData?.morph?.weights){let w=p.pluginData.morph.weights,A=p.pluginData.morph.numTargets||w.length;for(let m=0;m<A;m++)w[m]=w[m]*(1-h)+o[m]*h}}}}}let s=[];for(let u=0;u<n;u++){let h=B(),{t:f,r:M,s:c}=i[u];rt(h,M,f,c),s.push(h)}let l=Ut(t.gltf,s);t.worldMatrices=l;for(let u of t.meshes)u.nodeIndex>=0&&u.nodeIndex<l.length&&(u.transform.set(l[u.nodeIndex]),At(u.normalMatrix,u.transform))}var ht=t=>{C.delete(t)},Ot={name:"keyframes",evaluateAnimation:ut,crossFadeTo:Vt,onParseGLB(t){(t.animationsParsed===!1||!t.animations)&&(t.animations=Rt(t.gltf,t.bin),t.animationsParsed=!0)},onLoadModel:ht,onClearScene:ht,onDestroy:(t,e)=>ht(e),onUpdate(t,e){if(!t.isPlayingAnimation)return;let r=C.get(t);if(r&&r.length>0){for(let n=r.length-1;n>=0;n--){let i=r[n];if(i.time+=e,i.clip.duration>0&&(i.time%=i.clip.duration),i.fadeSpeed!==0)if(i.weight+=i.fadeSpeed*e,i.weight<=0){r.splice(n,1);continue}else i.weight>=1&&(i.weight=1,i.fadeSpeed=0)}r.length>0&&(t.animationTime=r[r.length-1].time),ut(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),ut(t,t.animationTime))}},q=64;function te(t,e,r){if(!(!t?.meshes||e<0||e>=q))for(let n of t.meshes)for(let i of n.primitives){let a=i.pluginData?.morph;a?.weights&&(a.weights[e]=r)}}var Nt={name:"morph",onResolveShader(t,e,r,n){if(!Array.isArray(t?.targets)||t.targets.length===0)return null;let i=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
17
17
  uniform sampler2D uMorphDeltasTex;
18
- uniform float uMorphWeights[${L}];
18
+ uniform float uMorphWeights[${q}];
19
19
  uniform int uNumMorphTargets;`);return i=i.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
20
- for (int m = 0; m < ${L}; m++) {
20
+ for (int m = 0; m < ${q}; m++) {
21
21
  if (m >= uNumMorphTargets) break;
22
22
  float w = uMorphWeights[m];
23
23
  if (abs(w) > 0.0001) {
24
24
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
25
25
  }
26
26
  }
27
- vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:i,fs:n}},onBuildPrimitiveVAO(t,e,r,n,i){let a=r?.targets;if(!Array.isArray(a)||a.length===0)return null;let g=r.attributes?.POSITION,p=n?.accessors?.[g];if(!p)return null;let o=p.count,s=Math.min(a.length,L),l=new Float32Array(o*s*4);for(let f=0;f<s;f++){let M=a[f].POSITION;if(M===void 0)continue;let c=n.accessors?.[M],d=n.bufferViews?.[c?.bufferView];if(!c||!d)continue;let b=X(n,i,c,3);if(!b||b.length<o*3)continue;let w=f*o*4;for(let m=0;m<o;m++)l[w+m*4]=b[m*3],l[w+m*4+1]=b[m*3+1],l[w+m*4+2]=b[m*3+2],l[w+m*4+3]=0}let u=t.createTexture();t.bindTexture(3553,u),t.texImage2D(3553,0,34836,o,s,0,6408,5126,l),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728);let h=new Float32Array(L);return{hasMorph:!0,morphTex:u,numTargets:s,vertexCount:o,weights:h}},onBeforeDrawPrimitive(t,e,r,n,i,a){let g=r.pluginData?.morph;if(!g?.hasMorph||!g.morphTex)return;t.activeTexture(33989),t.bindTexture(3553,g.morphTex);let p=t.getUniformLocation(e,"uMorphDeltasTex");p&&t.uniform1i(p,5);let o=t.getUniformLocation(e,"uNumMorphTargets");o&&t.uniform1i(o,g.numTargets);let s=t.getUniformLocation(e,"uMorphWeights[0]");s&&t.uniform1fv(s,g.weights)}},mt=64,Dt={name:"skinning",onResolveShader(t,e,r,n){if(t?.attributes?.JOINTS_0===void 0||t?.attributes?.WEIGHTS_0===void 0)return null;let i=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
27
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:i,fs:n}},onBuildPrimitiveVAO(t,e,r,n,i){let a=r?.targets;if(!Array.isArray(a)||a.length===0)return null;let g=r.attributes?.POSITION,d=n?.accessors?.[g];if(!d)return null;let o=d.count,s=Math.min(a.length,q),l=new Float32Array(o*s*4);for(let f=0;f<s;f++){let M=a[f].POSITION;if(M===void 0)continue;let c=n.accessors?.[M],p=n.bufferViews?.[c?.bufferView];if(!c||!p)continue;let w=X(n,i,c,3);if(!w||w.length<o*3)continue;let A=f*o*4;for(let m=0;m<o;m++)l[A+m*4]=w[m*3],l[A+m*4+1]=w[m*3+1],l[A+m*4+2]=w[m*3+2],l[A+m*4+3]=0}let u=t.createTexture();t.bindTexture(3553,u),t.texImage2D(3553,0,34836,o,s,0,6408,5126,l),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728);let h=new Float32Array(q);return{hasMorph:!0,morphTex:u,numTargets:s,vertexCount:o,weights:h}},onBeforeDrawPrimitive(t,e,r,n,i,a){let g=r.pluginData?.morph;if(!g?.hasMorph||!g.morphTex)return;t.activeTexture(33989),t.bindTexture(3553,g.morphTex);let d=t.getUniformLocation(e,"uMorphDeltasTex");d&&t.uniform1i(d,5);let o=t.getUniformLocation(e,"uNumMorphTargets");o&&t.uniform1i(o,g.numTargets);let s=t.getUniformLocation(e,"uMorphWeights[0]");s&&t.uniform1fv(s,g.weights)}},mt=64,Dt={name:"skinning",onResolveShader(t,e,r,n){if(t?.attributes?.JOINTS_0===void 0||t?.attributes?.WEIGHTS_0===void 0)return null;let i=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
28
28
  layout(location=4) in uvec4 aJoints;
29
29
  layout(location=5) in vec4 aWeights;
30
30
  uniform mat4 uJointMatrix[${mt}];`),a=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${a},1.0);`,`mat4 skinMatrix =
@@ -32,4 +32,4 @@ uniform mat4 uJointMatrix[${mt}];`),a=i.includes("morphedPos")?"morphedPos":"aPo
32
32
  aWeights.y * uJointMatrix[int(aJoints.y)] +
33
33
  aWeights.z * uJointMatrix[int(aJoints.z)] +
34
34
  aWeights.w * uJointMatrix[int(aJoints.w)];
35
- vec4 world=uModel*(skinMatrix*vec4(${a},1.0));`).replace(`gl_Position=uMVP*vec4(${a},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${a},1.0));`),{vs:i,fs:n}},onBuildPrimitiveVAO(t,e,r,n,i){let a=r?.attributes;if(!a||a.JOINTS_0===void 0||a.WEIGHTS_0===void 0)return null;let g=n.accessors[a.JOINTS_0],p=n.accessors[a.WEIGHTS_0];if(!g||!p)return null;let o=n.bufferViews[g.bufferView],s=n.bufferViews[p.bufferView];if(!o||!s)return null;let l=(o.byteOffset||0)+(g.byteOffset||0),u=(s.byteOffset||0)+(p.byteOffset||0),h=t.createBuffer();t.bindBuffer(34962,h);let f=g.componentType===5121?5121:5123,M=f===5121?new Uint8Array(i,l,g.count*4):new Uint16Array(i,l,g.count*4);t.bufferData(34962,M,35044),t.enableVertexAttribArray(4),t.vertexAttribIPointer(4,4,f,0,0);let c=t.createBuffer();t.bindBuffer(34962,c);let d=X(n,i,p,4)??new Float32Array(i,u,p.count*4);return t.bufferData(34962,d,35044),t.enableVertexAttribArray(5),t.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[h,c]}},onBeforeDrawPrimitive(t,e,r,n,i,a){if(!r.pluginData?.skinning?.hasSkin)return;let g=a?.nodes?.[n.nodeIndex]?.skin;if(g===void 0||!a.skins||!a.skins[g])return;let p=a.skins[g].joints||[],o=new Float32Array(mt*16);for(let l=0;l<p.length&&l<mt;l++){let u=p[l],h=i[u]||W();o.subarray(l*16,(l+1)*16).set(h)}let s=t.getUniformLocation(e,"uJointMatrix[0]");s&&t.uniformMatrix4fv(s,!1,o)}};Z(Nt),Z(Ot),Z(Dt),Z(kt);export{$t as IKSolver,Rt as crossFadeTo,kt as ikPlugin,Ot as keyframeAnimationPlugin,Nt as morphPlugin,Vt as parseAnimations,ot as quatFromUnitVectors,C as sampleChannel,te as setMorphTargetWeight,Dt as skinningPlugin,xt as solveFABRIK,vt as solveTwoBoneIK};
35
+ vec4 world=uModel*(skinMatrix*vec4(${a},1.0));`).replace(`gl_Position=uMVP*vec4(${a},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${a},1.0));`),{vs:i,fs:n}},onBuildPrimitiveVAO(t,e,r,n,i){let a=r?.attributes;if(!a||a.JOINTS_0===void 0||a.WEIGHTS_0===void 0)return null;let g=n.accessors[a.JOINTS_0],d=n.accessors[a.WEIGHTS_0];if(!g||!d)return null;let o=n.bufferViews[g.bufferView],s=n.bufferViews[d.bufferView];if(!o||!s)return null;let l=(o.byteOffset||0)+(g.byteOffset||0),u=(s.byteOffset||0)+(d.byteOffset||0),h=t.createBuffer();t.bindBuffer(34962,h);let f=g.componentType===5121?5121:5123,M=f===5121?new Uint8Array(i,l,g.count*4):new Uint16Array(i,l,g.count*4);t.bufferData(34962,M,35044),t.enableVertexAttribArray(4),t.vertexAttribIPointer(4,4,f,0,0);let c=t.createBuffer();t.bindBuffer(34962,c);let p=X(n,i,d,4)??new Float32Array(i,u,d.count*4);return t.bufferData(34962,p,35044),t.enableVertexAttribArray(5),t.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[h,c]}},onBeforeDrawPrimitive(t,e,r,n,i,a){if(!r.pluginData?.skinning?.hasSkin)return;let g=a?.nodes?.[n.nodeIndex]?.skin;if(g===void 0||!a.skins||!a.skins[g])return;let d=a.skins[g].joints||[],o=new Float32Array(mt*16);for(let l=0;l<d.length&&l<mt;l++){let u=d[l],h=i[u]||B();o.subarray(l*16,(l+1)*16).set(h)}let s=t.getUniformLocation(e,"uJointMatrix[0]");s&&t.uniformMatrix4fv(s,!1,o)}};Z(Nt),Z(Ot),Z(Dt),Z(kt);export{Lt as IKSolver,Vt as crossFadeTo,kt as ikPlugin,Ot as keyframeAnimationPlugin,Nt as morphPlugin,Rt as parseAnimations,ot as quatFromUnitVectors,$ as sampleChannel,te as setMorphTargetWeight,Dt as skinningPlugin,xt as solveFABRIK,vt as solveTwoBoneIK};