three-live 1.3.0 → 1.3.1

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 (42) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +36 -0
  3. package/dist/three-author-engine.js +86 -62
  4. package/dist/three-author.cjs +84 -60
  5. package/dist/three-author.d.ts +36 -0
  6. package/dist/three-author.js +83 -59
  7. package/dist/three-convert.cjs +78 -58
  8. package/dist/three-convert.d.ts +36 -0
  9. package/dist/three-convert.js +77 -57
  10. package/dist/three-live-animation.cjs +8 -9
  11. package/dist/three-live-animation.d.ts +36 -0
  12. package/dist/three-live-animation.js +7 -8
  13. package/dist/three-live-animation.min.js +6 -7
  14. package/dist/three-live-cad.cjs +3 -4
  15. package/dist/three-live-cad.d.ts +36 -0
  16. package/dist/three-live-cad.js +2 -3
  17. package/dist/three-live-cad.min.js +3 -4
  18. package/dist/three-live-cli.js +231 -0
  19. package/dist/three-live-element.cjs +17 -20
  20. package/dist/three-live-element.d.ts +36 -0
  21. package/dist/three-live-element.js +16 -19
  22. package/dist/three-live-full.cjs +110 -86
  23. package/dist/three-live-full.js +107 -83
  24. package/dist/three-live-full.min.js +110 -86
  25. package/dist/three-live-studio.cjs +19 -20
  26. package/dist/three-live-studio.d.ts +36 -0
  27. package/dist/three-live-studio.js +18 -19
  28. package/dist/three-live-studio.min.js +18 -19
  29. package/dist/three-live-viewer.cjs +17 -20
  30. package/dist/three-live-viewer.d.ts +36 -0
  31. package/dist/three-live-viewer.js +16 -19
  32. package/dist/three-live-viewer.min.js +17 -20
  33. package/dist/three-live.cjs +87 -63
  34. package/dist/three-live.js +86 -62
  35. package/dist/three-live.min.js +86 -62
  36. package/dist/three-view.cjs +17 -20
  37. package/dist/three-view.d.ts +36 -0
  38. package/dist/three-view.js +16 -19
  39. package/dist/three-xr.cjs +78 -58
  40. package/dist/three-xr.d.ts +36 -0
  41. package/dist/three-xr.js +77 -57
  42. package/package.json +7 -1
@@ -1,4 +1,4 @@
1
- /**
1
+ "use strict";/**
2
2
  * @license
3
3
  * Copyright 2026 Google LLC
4
4
  *
@@ -13,24 +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
- */
17
- "use strict";var se=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var je=Object.prototype.hasOwnProperty;var Qe=(e,n)=>{for(var t in n)se(e,t,{get:n[t],enumerable:!0})},Xe=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of De(n))!je.call(e,r)&&r!==t&&se(e,r,{get:()=>n[r],enumerable:!(s=Ue(n,r))||s.enumerable});return e};var Je=e=>Xe(se({},"__esModule",{value:!0}),e);var cn={};Qe(cn,{IKSolver:()=>Ne,crossFadeTo:()=>ge,ikPlugin:()=>ye,keyframeAnimationPlugin:()=>Ae,morphPlugin:()=>Te,parseAnimations:()=>be,quatFromUnitVectors:()=>ne,sampleChannel:()=>U,setMorphTargetWeight:()=>We,skinningPlugin:()=>Me,solveFABRIK:()=>de,solveTwoBoneIK:()=>fe});module.exports=Je(cn);var Y="__THREE_LIVE_REGISTRY__";function Q(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Y]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,Y,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[Y]=n}}return e[Y]}var ln=Q().plugins;function Se(e){let n=Q();n.workerExtensionInstallers||(n.workerExtensionInstallers=[]),n.workerExtensionInstallers.includes(e)||n.workerExtensionInstallers.push(e)}function X(e){let n=Q().plugins;n.some(t=>t.name===e.name)||n.push(e),e.onRegister?.()}function N(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function ie(e,n,t){let s=n[0],r=n[1],i=n[2],h=n[3],y=n[4],o=n[5],a=n[6],c=n[7],l=n[8],m=n[9],u=n[10],M=n[11],f=n[12],d=n[13],A=n[14],T=n[15],x=t[0],g=t[1],F=t[2],R=t[3];return e[0]=x*s+g*y+F*l+R*f,e[1]=x*r+g*o+F*m+R*d,e[2]=x*i+g*a+F*u+R*A,e[3]=x*h+g*c+F*M+R*T,x=t[4],g=t[5],F=t[6],R=t[7],e[4]=x*s+g*y+F*l+R*f,e[5]=x*r+g*o+F*m+R*d,e[6]=x*i+g*a+F*u+R*A,e[7]=x*h+g*c+F*M+R*T,x=t[8],g=t[9],F=t[10],R=t[11],e[8]=x*s+g*y+F*l+R*f,e[9]=x*r+g*o+F*m+R*d,e[10]=x*i+g*a+F*u+R*A,e[11]=x*h+g*c+F*M+R*T,x=t[12],g=t[13],F=t[14],R=t[15],e[12]=x*s+g*y+F*l+R*f,e[13]=x*r+g*o+F*m+R*d,e[14]=x*i+g*a+F*u+R*A,e[15]=x*h+g*c+F*M+R*T,e}function J(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=r+r,a=i+i,c=h+h,l=r*o,m=r*a,u=r*c,M=i*a,f=i*c,d=h*c,A=y*o,T=y*a,x=y*c,g=s[0],F=s[1],R=s[2];return e[0]=(1-(M+d))*g,e[1]=(m+x)*g,e[2]=(u-T)*g,e[3]=0,e[4]=(m-x)*F,e[5]=(1-(l+d))*F,e[6]=(f+A)*F,e[7]=0,e[8]=(u+T)*R,e[9]=(f-A)*R,e[10]=(1-(l+M))*R,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function Z(e,n,t=0){let s=n[0],r=n[1],i=n[2],h=n[4],y=n[5],o=n[6],a=n[8],c=n[9],l=n[10],m=l*y-o*c,u=-l*h+o*a,M=c*h-y*a,f=s*m+r*u+i*M;return!f||t>0&&(!Number.isFinite(f)||Math.abs(f)<=t)||(f=1/f,e[0]=m*f,e[1]=u*f,e[2]=M*f,e[3]=(-l*r+i*c)*f,e[4]=(l*s-i*a)*f,e[5]=(-c*s+r*a)*f,e[6]=(o*r-i*y)*f,e[7]=(-o*s+i*h)*f,e[8]=(y*s-r*h)*f),e}function ke(e,n){let t=n[0],s=n[1],r=n[2],i=n[3],h=n[4],y=n[5],o=n[6],a=n[7],c=n[8],l=n[9],m=n[10],u=n[11],M=n[12],f=n[13],d=n[14],A=n[15],T=t*y-s*h,x=t*o-r*h,g=t*a-i*h,F=s*o-r*y,R=s*a-i*y,k=r*a-i*o,v=c*f-l*M,_=c*d-m*M,p=c*A-u*M,b=l*d-m*f,I=l*A-u*f,V=m*A-u*d,w=T*V-x*I+g*b+F*p-R*_+k*v;return w?(w=1/w,e[0]=(y*V-o*I+a*b)*w,e[1]=(r*I-s*V-i*b)*w,e[2]=(f*k-d*R+A*F)*w,e[3]=(m*R-l*k-u*F)*w,e[4]=(o*p-h*V-a*_)*w,e[5]=(t*V-r*p+i*_)*w,e[6]=(d*g-M*k-A*x)*w,e[7]=(c*k-m*g+u*x)*w,e[8]=(h*I-y*p+a*v)*w,e[9]=(s*p-t*I-i*v)*w,e[10]=(M*R-f*g+A*T)*w,e[11]=(l*g-c*R-u*T)*w,e[12]=(y*_-h*b-o*v)*w,e[13]=(t*b-s*_+r*v)*w,e[14]=(f*x-M*F-d*T)*w,e[15]=(c*F-l*x+m*T)*w,e):null}function _e(e,n){let t=Array.isArray(e?.nodes)?e.nodes.length:0,s=[];for(let c=0;c<t;c++)s.push(N());if(t===0)return s;let r=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let l of c.children)r.add(l);let i=new Set,h=128,y=(c,l,m=0)=>{if(m>h||c<0||c>=t||i.has(c))return;i.add(c);let u=e.nodes[c];if(!u)return;let M=N();if(n&&n[c])M.set(n[c]);else if(u.matrix&&u.matrix.length===16)M.set(u.matrix);else{let d=u.translation||[0,0,0],A=u.rotation||[0,0,0,1],T=u.scale||[1,1,1];J(M,A,d,T)}let f=s[c];if(l?ie(f,l,M):f.set(M),Array.isArray(u.children))for(let d of u.children)typeof d=="number"&&y(d,f,m+1)},o=[],a=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(a&&Array.isArray(a.nodes))o.push(...a.nodes);else for(let c=0;c<t;c++)r.has(c)||o.push(c);for(let c of o)y(c,null);for(let c=0;c<t;c++)!r.has(c)&&!o.includes(c)&&y(c,null);return s}function ue(e,n){function t(o,a,c,l){let m=typeof o=="number"?o:Number(o);return Number.isFinite(m)?Math.max(a,Math.min(c,m)):l}function s(o,a){let l=o[0]*a[0]+o[1]*a[1]+o[2]*a[2]+1;if(l<1e-6){if(Math.abs(o[0])>Math.abs(o[2])){let A=Math.hypot(o[1],o[0])||1;return[-o[1]/A,o[0]/A,0,0]}let d=Math.hypot(o[2],o[1])||1;return[0,-o[2]/d,o[1]/d,0]}let m=o[1]*a[2]-o[2]*a[1],u=o[2]*a[0]-o[0]*a[2],M=o[0]*a[1]-o[1]*a[0],f=Math.hypot(m,u,M,l)||1;return[m/f,u/f,M/f,l/f]}function r(o,a,c,l,m){let u=a[0]-o[0],M=a[1]-o[1],f=a[2]-o[2],d=Math.hypot(u,M,f),A=c[0]-a[0],T=c[1]-a[1],x=c[2]-a[2],g=Math.hypot(A,T,x);if(d<1e-6||g<1e-6)return{rootPos:[o[0],o[1],o[2]],midPos:[a[0],a[1],a[2]],effectorPos:[c[0],c[1],c[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let F=[u/d,M/d,f/d],R=[A/g,T/g,x/g],k=l[0]-o[0],v=l[1]-o[1],_=l[2]-o[2],p=Math.hypot(k,v,_),b=p>1e-6?[k/p,v/p,_/p]:F,I=Math.abs(d-g)+1e-5,V=Math.max(I,d+g-1e-5),w=Math.max(I,Math.min(V,p>1e-6?p:I)),S=t((d*d+w*w-g*g)/(2*d*w),-1,1,1),E=Math.sqrt(Math.max(0,1-S*S)),B=m?m[0]-o[0]:u,C=m?m[1]-o[1]:M,D=m?m[2]-o[2]:f,z=B*b[0]+C*b[1]+D*b[2],K=B-b[0]*z,O=C-b[1]*z,P=D-b[2]*z,j=Math.hypot(K,O,P);if(j<=1e-6){let Ie=Math.abs(b[1])<.99?0:1,Ve=Math.abs(b[1])<.99?1:0,ve=0;K=b[1]*ve-b[2]*Ve,O=b[2]*Ie-b[0]*ve,P=b[0]*Ve-b[1]*Ie,j=Math.hypot(K,O,P)||1}let re=[K/j,O/j,P/j],L=[o[0]+b[0]*(d*S)+re[0]*(d*E),o[1]+b[1]*(d*S)+re[1]*(d*E),o[2]+b[2]*(d*S)+re[2]*(d*E)],oe=[o[0]+b[0]*w,o[1]+b[1]*w,o[2]+b[2]*w],we=oe[0]-L[0],Re=oe[1]-L[1],Fe=oe[2]-L[2],H=Math.hypot(we,Re,Fe),q=H>1e-6?[we/H,Re/H,Fe/H]:b,ze=[L[0]+q[0]*g,L[1]+q[1]*g,L[2]+q[2]*g],Ge=[(L[0]-o[0])/d,(L[1]-o[1])/d,(L[2]-o[2])/d];return{rootPos:[o[0],o[1],o[2]],midPos:L,effectorPos:ze,rootRotation:s(F,Ge),midRotation:s(R,q)}}function i(o,a,c=8,l=.001){let m=o.length;if(m<2)return{positions:o.map(p=>[p[0],p[1],p[2]]),rotations:[],iterations:0};let u=o.map(p=>[p[0],p[1],p[2]]),M=[],f=[],d=0;for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V);M.push(w),d+=w,f.push(w>1e-6?[b/w,I/w,V/w]:[0,1,0])}let A=[u[0][0],u[0][1],u[0][2]],T=Math.round(t(c,1,32,8)),x=t(l,1e-5,.1,.001),g=a[0]-A[0],F=a[1]-A[1],R=a[2]-A[2],k=Math.hypot(g,F,R),v=0;if(k>=d&&d>1e-6){let p=k>1e-6?[g/k,F/k,R/k]:f[0];u[0]=[A[0],A[1],A[2]];for(let b=0;b<m-1;b++){let I=M[b];u[b+1]=[u[b][0]+p[0]*I,u[b][1]+p[1]*I,u[b][2]+p[2]*I]}v=1}else for(let p=1;p<=T;p++){let b=u[m-1];if(Math.hypot(b[0]-a[0],b[1]-a[1],b[2]-a[2])<=x)break;v=p;let V=(w,S,E,B,C)=>{let D=S[0]-w[0],z=S[1]-w[1],K=S[2]-w[2],O=Math.hypot(D,z,K);if(O>1e-6){let P=E/O;return[w[0]+D*P,w[1]+z*P,w[2]+K*P]}return[w[0]+B[0]*E*C,w[1]+B[1]*E*C,w[2]+B[2]*E*C]};u[m-1]=[a[0],a[1],a[2]];for(let w=m-2;w>=0;w--)u[w]=V(u[w+1],u[w],M[w],f[w],-1);u[0]=[A[0],A[1],A[2]];for(let w=0;w<m-1;w++)u[w+1]=V(u[w],u[w+1],M[w],f[w],1)}let _=[];for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V),S=w>1e-6?[b/w,I/w,V/w]:f[p];_.push(s(f[p],S))}return{positions:u,rotations:_,iterations:v}}function h(o){if(!o||typeof o!="object"||Array.isArray(o))return null;let a=o;if(a.enabled===!1)return null;let c=x=>{if(typeof x!="string")return;let g=x.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(g)?g:void 0},l=x=>Array.isArray(x)&&x.length===3&&x.every(g=>typeof g=="number"&&Number.isFinite(g))?[t(x[0],-1e3,1e3,0),t(x[1],-1e3,1e3,0),t(x[2],-1e3,1e3,0)]:void 0,m=c(a.root),u=c(a.effector);if(!m||!u)return null;let M=c(a.mid),f=l(a.target)??c(a.target);if(!f)return null;let d=a.pole??a.poleTarget,A=l(d)??c(d),T=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||M?"two-bone":"fabrik";return{root:m,...M?{mid:M}:{},effector:u,target:f,...A?{pole:A}:{},solver:T,iterations:Math.round(t(a.iterations,1,32,8)),tolerance:t(a.tolerance,1e-5,.1,.001),weight:t(a.weight,0,1,1)}}let y=Object.freeze({solveTwoBone:r,solveFABRIK:i,parseIKTrait:h});return n&&typeof n=="object"&&(n.authorNamespace=n.authorNamespace||{},n.authorNamespace.IKSolver=y),{clampNum:t,parseIKTrait:h,quatFromUnitVectors:s,solveTwoBoneIK:r,solveFABRIK:i,IKSolver:y}}var G=ue(),Le=G.clampNum,$e=G.parseIKTrait,ne=G.quatFromUnitVectors,fe=G.solveTwoBoneIK,de=G.solveFABRIK,Ne=G.IKSolver;function le(e){let n=e?.transform??e?.modelMatrix;return n&&n.length>=16?[n[12]||0,n[13]||0,n[14]||0]:[0,0,0]}function He(e,n){let t=e?.transform??e?.modelMatrix;!t||t.length<16||(t[12]=n[0],t[13]=n[1],t[14]=n[2])}function qe(e,n,t,s,r){let i=Le(r,0,1,1),h=n[0]+(t[0]-n[0])*i,y=n[1]+(t[1]-n[1])*i,o=n[2]+(t[2]-n[2])*i,a=h-e[0],c=y-e[1],l=o-e[2],m=Math.hypot(a,c,l);if(m>1e-6&&s>1e-6){let A=s/m;return[e[0]+a*A,e[1]+c*A,e[2]+l*A]}let u=t[0]-e[0],M=t[1]-e[1],f=t[2]-e[2],d=Math.hypot(u,M,f);if(d>1e-6&&s>1e-6){let A=s/d;return[e[0]+u*A,e[1]+M*A,e[2]+f*A]}return[h,y,o]}function Ye(e,n){let t=e?.modelRootMatrix;if(!t||t.length!==16)return n;let s=new Float32Array(16);return ke(s,t instanceof Float32Array?t:Float32Array.from(t))?[s[0]*n[0]+s[4]*n[1]+s[8]*n[2]+s[12],s[1]*n[0]+s[5]*n[1]+s[9]*n[2]+s[13],s[2]*n[0]+s[6]*n[1]+s[10]*n[2]+s[14]]:n}function ae(e,n){e.__ikWarned||(e.__ikWarned=new Set);let t=e.__ikWarned;t.has(n)||(t.add(n),console.warn(`[three-live] ik: joint '${n}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function me(e,n,t){if(Array.isArray(e))return[e[0],e[1],e[2]];let s=n.get(e);if(s)return le(s);let r;if(e==="head"?r=t?.headPose?.position??t?.headPose??t?.cameraPosition:e==="hand-left"?r=t?.handPoses?.left?.position??t?.handPoses?.left??t?.hands?.left?.position??t?.hands?.left:e==="hand-right"&&(r=t?.handPoses?.right?.position??t?.handPoses?.right??t?.hands?.right?.position??t?.hands?.right),(Array.isArray(r)||ArrayBuffer.isView(r))&&r.length>=3){let i=r;return Ye(t,[i[0],i[1],i[2]])}return null}function ce(e,n){return[e[3]*n[0]+e[0]*n[3]+e[1]*n[2]-e[2]*n[1],e[3]*n[1]-e[0]*n[2]+e[1]*n[3]+e[2]*n[0],e[3]*n[2]+e[0]*n[1]-e[1]*n[0]+e[2]*n[3],e[3]*n[3]-e[0]*n[0]-e[1]*n[1]-e[2]*n[2]]}function Ze(e){return[-e[0],-e[1],-e[2],e[3]]}function he(e){let n=Math.hypot(e[0],e[1],e[2],e[3]);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n,e[3]/n]:[0,0,0,1]}function en(e,n){if(n>=1)return e;if(n<=0)return[0,0,0,1];let[t,s,r,i]=e;i<0&&(t=-t,s=-s,r=-r,i=-i);let h=Math.acos(Math.min(1,i)),y=Math.sin(h);if(y<1e-9)return[0,0,0,1];let o=Math.sin(h*n)/y;return he([t*o,s*o,r*o,Math.cos(h*n)])}function nn(e){let n=Math.hypot(e[0],e[1],e[2])||1,t=Math.hypot(e[4],e[5],e[6])||1,s=Math.hypot(e[8],e[9],e[10])||1,r=e[0]/n,i=e[1]/n,h=e[2]/n,y=e[4]/t,o=e[5]/t,a=e[6]/t,c=e[8]/s,l=e[9]/s,m=e[10]/s,u=r+o+m,M;if(u>0){let f=Math.sqrt(u+1)*2;M=[(a-l)/f,(c-h)/f,(i-y)/f,.25*f]}else if(r>o&&r>m){let f=Math.sqrt(1+r-o-m)*2;M=[.25*f,(y+i)/f,(c+h)/f,(a-l)/f]}else if(o>m){let f=Math.sqrt(1+o-r-m)*2;M=[(y+i)/f,.25*f,(l+a)/f,(c-h)/f]}else{let f=Math.sqrt(1+m-r-o)*2;M=[(c+h)/f,(l+a)/f,.25*f,(i-y)/f]}return he(M)}function tn(e,n,t){let[s,r,i,h]=t,y=1-2*(r*r+i*i),o=2*(s*r-i*h),a=2*(s*i+r*h),c=2*(s*r+i*h),l=1-2*(s*s+i*i),m=2*(r*i-s*h),u=2*(s*i-r*h),M=2*(r*i+s*h),f=1-2*(s*s+r*r);for(let d=0;d<3;d++){let A=n[d*4],T=n[d*4+1],x=n[d*4+2];e[d*4]=y*A+o*T+a*x,e[d*4+1]=c*A+l*T+m*x,e[d*4+2]=u*A+M*T+f*x}}function ee(e,n){let t=n[0]-e[0],s=n[1]-e[1],r=n[2]-e[2],i=Math.hypot(t,s,r);return i>1e-9?[t/i,s/i,r/i]:null}function Be(e){e?.normalMatrix&&e?.transform&&Z(e.normalMatrix,e.transform)}var Ee=new WeakMap;function rn(e){let n=Ee.get(e);return n||(n=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((t,s)=>{for(let r of Array.isArray(t?.children)?t.children:[])typeof r=="number"&&r>=0&&r<n.length&&(n[r]=s)}),Ee.set(e,n)),n}function on(e,n,t){let s=e?.gltf,r=s?.nodes;if(!Array.isArray(r)||r.length===0)return!1;let i=new Map;r.forEach((p,b)=>{typeof p?.name=="string"&&p.name&&!i.has(p.name)&&i.set(p.name,b)});let y=(n.mid?[n.root,n.mid,n.effector]:[n.root,n.effector]).map(p=>i.get(p));if(y.some(p=>p===void 0))return!1;let o=y,a=rn(s);for(let p=1;p<o.length;p++){let b=a[o[p]],I=0;for(;b>=0&&b!==o[p-1]&&I++<256;)b=a[b];if(b!==o[p-1])return!1}let c=o[0],l=e.initialNodeTransforms,m=new Map,u=[],M=[c];for(;M.length&&u.length<4096;){let p=M.pop();if(m.has(p))continue;let b=l?.[p],I=r[p];m.set(p,{t:b?[b.t[0],b.t[1],b.t[2]]:I?.translation?[...I.translation]:[0,0,0],r:b?[b.r[0],b.r[1],b.r[2],b.r[3]]:I?.rotation?[...I.rotation]:[0,0,0,1],s:b?[b.s[0],b.s[1],b.s[2]]:I?.scale?[...I.scale]:[1,1,1]}),u.push(p);for(let V of Array.isArray(I?.children)?I.children:[])typeof V=="number"&&M.push(V)}let f=a[c],d=f>=0&&e.worldMatrices?.[f]?.length===16?Float32Array.from(e.worldMatrices[f]):N(),A=new Map,T=()=>{let p=(b,I)=>{let V=m.get(b);if(!V)return;let w=N();J(w,V.r,V.t,V.s);let S=N();ie(S,I,w),A.set(b,S);for(let E of Array.isArray(r[b]?.children)?r[b].children:[])typeof E=="number"&&p(E,S)};p(c,d)},x=p=>{let b=A.get(p);return[b[12],b[13],b[14]]};T();let g=o.map(x),F=p=>{if(typeof p=="string"&&!t.has(p)){let b=i.get(p),I=b!==void 0?A.get(b)??e.worldMatrices?.[b]:void 0;if(I&&I.length===16)return[I[12],I[13],I[14]]}return me(p,t,e)},R=F(n.target);if(!R)return!0;let k=n.pole?F(n.pole)??void 0:void 0,v=Ce(g,n,R,k),_=Le(n.weight,0,1,1);for(let p=0;p<o.length-1;p++){let b=ee(x(o[p]),x(o[p+1])),I=ee(v[p],v[p+1]);if(!b||!I)continue;let V=en(ne(b,I),_),w=o[p],S=a[w],E=S===f||S<0?d:A.get(S)??d,B=nn(E),C=m.get(w);C.r=he(ce(Ze(B),ce(V,ce(B,C.r)))),T()}if(Array.isArray(e.worldMatrices))for(let[p,b]of A)e.worldMatrices[p]?.set&&e.worldMatrices[p].set(b);for(let p of e.meshes??[]){let b=A.get(p?.nodeIndex);b&&p.transform?.set&&(p.transform.set(b),Be(p))}return!0}function Ce(e,n,t,s){if(n.solver==="two-bone"&&e.length===3){let r=fe(e[0],e[1],e[2],t,s);return[e[0],r.midPos,r.effectorPos]}return de(e,t,n.iterations,n.tolerance).positions}function sn(e,n,t){let s=e.__ikRestOffsets,r=e.__ikRestMats;if(!(!s||!r))for(let i=0;i<n.length-1;i++){let h=n[i]?.transform??n[i]?.modelMatrix,y=r[i],o=ee([0,0,0],s[i]),a=ee(t[i],t[i+1]);!h||h.length<16||!y||y.length<16||!o||!a||(tn(h,y,ne(o,a)),Be(n[i]))}}var ye={name:"ik",onRegister(){let e=Q();Se(ue),ue(e.threeNamespace,e)},onUpdate(e){let n=e?.meshes;if(!Array.isArray(n)||n.length===0)return;let t=null;for(let s of n){let r=s?.userData?.xr?.ik??s?.extras?.xr?.ik??s?.extensions?.ANDROID_xr_scenecore?.ik;if(!r)continue;let i=$e(r);if(!i||i.weight<=0)continue;if(!t){t=new Map;for(let g of n)g&&typeof g.name=="string"&&g.name&&t.set(g.name,g)}if(on(e,i,t))continue;let h=t.get(i.root),y=t.get(i.effector),o=i.mid?t.get(i.mid):void 0;if(h||ae(s,i.root),y||ae(s,i.effector),i.mid&&!o&&ae(s,i.mid),!h||!y)continue;let a=me(i.target,t,e);if(!a)continue;let c=i.pole?me(i.pole,t,e)??void 0:void 0,l=o?[h,o,y]:[h,y],m=l.map(g=>g.name||"").join(">");if(!s.__ikRestOffsets||s.__ikRestKey!==m){let g=l.map(le),F=[];for(let R=0;R<g.length-1;R++)F.push([g[R+1][0]-g[R][0],g[R+1][1]-g[R][1],g[R+1][2]-g[R][2]]);s.__ikRestOffsets=F,s.__ikRestKey=m,s.__ikRestMats=l.map(R=>Array.from(R.transform??R.modelMatrix??[]))}let u=s.__ikRestOffsets,f=[le(h)],d=[];for(let g=0;g<u.length;g++){let F=f[g],R=u[g];f.push([F[0]+R[0],F[1]+R[1],F[2]+R[2]]),d.push(Math.hypot(R[0],R[1],R[2]))}let A=Ce(f,i,a,c),T=f[0],x=[f[0]];for(let g=1;g<l.length;g++){let F=u[g-1],R=[T[0]+F[0],T[1]+F[1],T[2]+F[2]],k=[T[0]+(A[g][0]-A[g-1][0]),T[1]+(A[g][1]-A[g-1][1]),T[2]+(A[g][2]-A[g-1][2])],v=qe(T,R,k,d[g-1],i.weight);He(l[g],v),T=v,x.push(v)}sn(s,l,x)}}};var an={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function W(e,n,t,s){if(!t||t.bufferView===void 0)return null;let r=e.bufferViews?.[t.bufferView];if(!r)return null;let i=Number(t.count??0);if(!Number.isInteger(i)||i<=0)return null;let h=t.componentType??5126,y=an[h];if(!y)throw new RangeError(`glTF accessor has unsupported componentType ${h}`);let o=y*s,a=r.byteStride&&r.byteStride>0?r.byteStride:o,c=(r.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(c)||c<0||a<o||c+(i-1)*a+o>n.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${n.byteLength} bytes)`);if(h===5126&&a===o&&c%4===0)return new Float32Array(n,c,i*s);let l=new DataView(n),m=t.normalized===!0,u=new Float32Array(i*s);for(let M=0;M<i;M++){let f=c+M*a;for(let d=0;d<s;d++){let A=f+d*y,T;switch(h){case 5126:T=l.getFloat32(A,!0);break;case 5120:T=l.getInt8(A),m&&(T=Math.max(T/127,-1));break;case 5121:T=l.getUint8(A),m&&(T/=255);break;case 5122:T=l.getInt16(A,!0),m&&(T=Math.max(T/32767,-1));break;case 5123:T=l.getUint16(A,!0),m&&(T/=65535);break;default:T=l.getUint32(A,!0),m&&(T/=4294967295)}u[M*s+d]=T}}return u}function Pe(e,n,t){return n%4===0?new Float32Array(e,n,t):new Float32Array(e.slice(n,n+t*4))}function Oe(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=t[0],a=t[1],c=t[2],l=t[3],m=r*o+i*a+h*c+y*l;if(m<0&&(o=-o,a=-a,c=-c,l=-l,m=-m),Math.abs(m)>=1)return e[0]=r,e[1]=i,e[2]=h,e[3]=y,e;let u=Math.acos(m),M=Math.sqrt(1-m*m);if(Math.abs(M)<.001)return e[0]=.5*(r+o),e[1]=.5*(i+a),e[2]=.5*(h+c),e[3]=.5*(y+l),e;let f=Math.sin((1-s)*u)/M,d=Math.sin(s*u)/M;return e[0]=r*f+o*d,e[1]=i*f+a*d,e[2]=h*f+c*d,e[3]=y*f+l*d,e}function Ke(e,n,t,s){return e[0]=n[0]+s*(t[0]-n[0]),e[1]=n[1]+s*(t[1]-n[1]),e[2]=n[2]+s*(t[2]-n[2]),e}function be(e,n){if(!Array.isArray(e?.animations))return[];let t=[];for(let s=0;s<e.animations.length;s++){let r=e.animations[s],i=r.name||`Animation_${s}`,h=[],y=0;if(Array.isArray(r.channels)&&Array.isArray(r.samplers))for(let o of r.channels){if(!o.target||o.target.node===void 0||!o.target.path)continue;let a=r.samplers[o.sampler];if(!a)continue;let c=e.accessors?.[a.input],l=e.accessors?.[a.output];if(!c||!l)continue;let m=e.bufferViews?.[c.bufferView],u=e.bufferViews?.[l.bufferView];if(!m||!u)continue;let M=(m.byteOffset||0)+(c.byteOffset||0),f=(u.byteOffset||0)+(l.byteOffset||0),d=W(e,n,c,1)??Pe(n,M,c.count);d.length>0&&d[d.length-1]>y&&(y=d[d.length-1]);let A=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(l.count/Math.max(1,c.count))):3,T=o.target.path==="weights"?1:A,x=W(e,n,l,T)??Pe(n,f,l.count*T),g=a.interpolation==="STEP"?"STEP":"LINEAR";h.push({nodeIndex:o.target.node,path:o.target.path,times:d,values:x,interpolation:g})}h.length>0&&t.push({name:i,duration:y,channels:h})}return t}function U(e,n,t){let{times:s,values:r,path:i,interpolation:h}=e,y=s.length;if(y===0)return;let o=i==="rotation"?4:i==="weights"?Math.max(1,Math.round(r.length/y)):3;if(n<=s[0]){for(let T=0;T<o;T++)t[T]=r[T];return}if(n>=s[y-1]){let T=(y-1)*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let a=0,c=y-1;for(;a<=c;){let T=a+c>>1;s[T]<=n?a=T+1:c=T-1}let l=Math.max(0,c),m=Math.min(y-1,l+1);if(h==="STEP"||l===m){let T=l*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let u=s[l],M=s[m],f=(n-u)/Math.max(1e-5,M-u),d=l*o,A=m*o;if(i==="rotation"){let T=[r[d],r[d+1],r[d+2],r[d+3]],x=[r[A],r[A+1],r[A+2],r[A+3]];Oe(t,T,x,f)}else for(let T=0;T<o;T++)t[T]=r[d+T]+f*(r[A+T]-r[d+T])}var te=new WeakMap;function ge(e,n,t=.3){if(!e?.animations)return;let s=e.animations.find(y=>y.name===n);if(!s)return;let r=te.get(e);r||(r=[],e.currentClip&&r.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),te.set(e,r));let i=t>0?1/t:1e3;for(let y of r)y.clip.name!==n&&(y.fadeSpeed=-i);let h=r.find(y=>y.clip.name===n);h?h.fadeSpeed=i:r.push({clip:s,time:0,weight:t>0?0:1,fadeSpeed:i}),e.currentClip=s,e.isPlayingAnimation=!0}function pe(e,n){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let t=te.get(e);if(!t||t.length===0){if(!e.currentClip)return;t=[{clip:e.currentClip,time:n,weight:1,fadeSpeed:0}]}let s=e.gltf.nodes.length,r=[];for(let l=0;l<s;l++){let m=e.initialNodeTransforms[l];m?r.push({t:[m.t[0],m.t[1],m.t[2]],r:[m.r[0],m.r[1],m.r[2],m.r[3]],s:[m.s[0],m.s[1],m.s[2]]}):r.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let i=[0,0,0],h=[0,0,0,1],y=[1,1,1],o=new Float32Array(64);for(let l of t){let m=Math.max(0,Math.min(1,l.weight));if(!(m<=1e-4))for(let u of l.clip.channels){if(u.nodeIndex<0||u.nodeIndex>=s)continue;let M=r[u.nodeIndex];if(u.path==="translation")U(u,l.time,i),Ke(M.t,M.t,i,m);else if(u.path==="rotation")U(u,l.time,h),Oe(M.r,M.r,h,m);else if(u.path==="scale")U(u,l.time,y),Ke(M.s,M.s,y,m);else if(u.path==="weights"&&(U(u,l.time,o),e.meshes)){for(let f of e.meshes)if(f.nodeIndex===u.nodeIndex){for(let d of f.primitives)if(d.pluginData?.morph?.weights){let A=d.pluginData.morph.weights,T=d.pluginData.morph.numTargets||A.length;for(let x=0;x<T;x++)A[x]=A[x]*(1-m)+o[x]*m}}}}}let a=[];for(let l=0;l<s;l++){let m=N(),{t:u,r:M,s:f}=r[l];J(m,M,u,f),a.push(m)}let c=_e(e.gltf,a);e.worldMatrices=c;for(let l of e.meshes)l.nodeIndex>=0&&l.nodeIndex<c.length&&(l.transform.set(c[l.nodeIndex]),Z(l.normalMatrix,l.transform))}var Ae={name:"keyframes",evaluateAnimation:pe,crossFadeTo:ge,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=be(e.gltf,e.bin))},onUpdate(e,n){if(!e.isPlayingAnimation)return;let t=te.get(e);if(t&&t.length>0){for(let s=t.length-1;s>=0;s--){let r=t[s];if(r.time+=n,r.clip.duration>0&&(r.time%=r.clip.duration),r.fadeSpeed!==0)if(r.weight+=r.fadeSpeed*n,r.weight<=0){t.splice(s,1);continue}else r.weight>=1&&(r.weight=1,r.fadeSpeed=0)}t.length>0&&(e.animationTime=t[t.length-1].time),pe(e,e.animationTime)}else e.currentClip&&(e.animationTime+=n,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),pe(e,e.animationTime))}};var $=64;function We(e,n,t){if(!(!e?.meshes||n<0||n>=$))for(let s of e.meshes)for(let r of s.primitives){let i=r.pluginData?.morph;i?.weights&&(i.weights[n]=t)}}var Te={name:"morph",onResolveShader(e,n,t,s){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let r=t.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
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;
18
17
  uniform sampler2D uMorphDeltasTex;
19
- uniform float uMorphWeights[${$}];
20
- uniform int uNumMorphTargets;`);return r=r.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
21
- for (int m = 0; m < ${$}; m++) {
18
+ uniform float uMorphWeights[${H}];
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++) {
22
21
  if (m >= uNumMorphTargets) break;
23
22
  float w = uMorphWeights[m];
24
23
  if (abs(w) > 0.0001) {
25
24
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
26
25
  }
27
26
  }
28
- vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.targets;if(!Array.isArray(i)||i.length===0)return null;let h=t.attributes?.POSITION,y=s?.accessors?.[h];if(!y)return null;let o=y.count,a=Math.min(i.length,$),c=new Float32Array(o*a*4);for(let u=0;u<a;u++){let M=i[u].POSITION;if(M===void 0)continue;let f=s.accessors?.[M],d=s.bufferViews?.[f?.bufferView];if(!f||!d)continue;let A=W(s,r,f,3);if(!A||A.length<o*3)continue;let T=u*o*4;for(let x=0;x<o;x++)c[T+x*4]=A[x*3],c[T+x*4+1]=A[x*3+1],c[T+x*4+2]=A[x*3+2],c[T+x*4+3]=0}let l=e.createTexture();e.bindTexture(3553,l),e.texImage2D(3553,0,34836,o,a,0,6408,5126,c),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array($);return{hasMorph:!0,morphTex:l,numTargets:a,vertexCount:o,weights:m}},onBeforeDrawPrimitive(e,n,t,s,r,i){let h=t.pluginData?.morph;if(!h?.hasMorph||!h.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,h.morphTex);let y=e.getUniformLocation(n,"uMorphDeltasTex");y&&e.uniform1i(y,5);let o=e.getUniformLocation(n,"uNumMorphTargets");o&&e.uniform1i(o,h.numTargets);let a=e.getUniformLocation(n,"uMorphWeights[0]");a&&e.uniform1fv(a,h.weights)}};var xe=64,Me={name:"skinning",onResolveShader(e,n,t,s){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let r=t.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,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;
29
28
  layout(location=4) in uvec4 aJoints;
30
29
  layout(location=5) in vec4 aWeights;
31
- uniform mat4 uJointMatrix[${xe}];`),i=r.includes("morphedPos")?"morphedPos":"aPosition";return r=r.replace(`vec4 world=uModel*vec4(${i},1.0);`,`mat4 skinMatrix =
30
+ uniform mat4 uJointMatrix[${Me}];`),a=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${a},1.0);`,`mat4 skinMatrix =
32
31
  aWeights.x * uJointMatrix[int(aJoints.x)] +
33
32
  aWeights.y * uJointMatrix[int(aJoints.y)] +
34
33
  aWeights.z * uJointMatrix[int(aJoints.z)] +
35
34
  aWeights.w * uJointMatrix[int(aJoints.w)];
36
- vec4 world=uModel*(skinMatrix*vec4(${i},1.0));`).replace(`gl_Position=uMVP*vec4(${i},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${i},1.0));`),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.attributes;if(!i||i.JOINTS_0===void 0||i.WEIGHTS_0===void 0)return null;let h=s.accessors[i.JOINTS_0],y=s.accessors[i.WEIGHTS_0];if(!h||!y)return null;let o=s.bufferViews[h.bufferView],a=s.bufferViews[y.bufferView];if(!o||!a)return null;let c=(o.byteOffset||0)+(h.byteOffset||0),l=(a.byteOffset||0)+(y.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let u=h.componentType===5121?5121:5123,M=u===5121?new Uint8Array(r,c,h.count*4):new Uint16Array(r,c,h.count*4);e.bufferData(34962,M,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,u,0,0);let f=e.createBuffer();e.bindBuffer(34962,f);let d=W(s,r,y,4)??new Float32Array(r,l,y.count*4);return e.bufferData(34962,d,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,f]}},onBeforeDrawPrimitive(e,n,t,s,r,i){if(!t.pluginData?.skinning?.hasSkin)return;let h=i?.nodes?.[s.nodeIndex]?.skin;if(h===void 0||!i.skins||!i.skins[h])return;let o=i.skins[h].joints||[],a=new Float32Array(xe*16);for(let l=0;l<o.length&&l<xe;l++){let m=o[l],u=r[m]||N();a.subarray(l*16,(l+1)*16).set(u)}let c=e.getUniformLocation(n,"uJointMatrix[0]");c&&e.uniformMatrix4fv(c,!1,a)}};X(Te);X(Ae);X(Me);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],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);
@@ -87,6 +87,20 @@ export {
87
87
  type InteractivityValueSocket,
88
88
  type InteractivityVariableDef,
89
89
  } from './three-live/src/plugins/interactivity';
90
+ export {
91
+ decimateGeometry,
92
+ getLodController,
93
+ installLodExtension,
94
+ LOD,
95
+ LodController,
96
+ lodPlugin,
97
+ materializeLodGeometry,
98
+ parseLod,
99
+ selectLodLevelIndex,
100
+ type LodGroupState,
101
+ type LodLevel,
102
+ type LodOptions,
103
+ } from './three-live/src/plugins/lod';
90
104
  export {
91
105
  applyMeshoptFilter,
92
106
  decodeMeshoptBuffer,
@@ -130,6 +144,8 @@ export {
130
144
  } from './xr-live/src/xr-live-element';
131
145
  /** Optional spatial plugins (`xr-live/spatial`, `xr-live-spatial.min.js`). */
132
146
  export * from './xr-live/src/plugins/index';
147
+ /** Optional simulation plugins (`xr-live/sim`, `xr-live-sim.min.js`). */
148
+ export * from './xr-live/src/sim/index';
133
149
 
134
150
  /**
135
151
  * Declarative JSX / HTML attributes supported by the <three-live> custom element.
@@ -449,7 +465,27 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
449
465
  sdpMLineIndex: number | null;
450
466
  }>,
451
467
  ) => void;
468
+ onxraudioplay?: (
469
+ e: CustomEvent<{
470
+ node: string;
471
+ meshIndex: number;
472
+ preset: string | null;
473
+ src: string | null;
474
+ gain: number;
475
+ pan: number;
476
+ triggerCount: number;
477
+ }>,
478
+ ) => void;
452
479
  /** xr-live-sim events. */
480
+ onxrcollision?: (
481
+ e: CustomEvent<{
482
+ nodeId: string;
483
+ otherId: string;
484
+ normal: [number, number, number];
485
+ impactSpeed: number;
486
+ }>,
487
+ ) => void;
488
+ onxrsleep?: (e: CustomEvent<{nodeId: string}>) => void;
453
489
  oncharacterjump?: (
454
490
  e: CustomEvent<{nodeId: string; position: [number, number, number]}>,
455
491
  ) => void;
@@ -13,24 +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
- */
17
- var Y="__THREE_LIVE_REGISTRY__";function j(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Y]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,Y,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[Y]=n}}return e[Y]}var en=j().plugins;function Te(e){let n=j();n.workerExtensionInstallers||(n.workerExtensionInstallers=[]),n.workerExtensionInstallers.includes(e)||n.workerExtensionInstallers.push(e)}function Q(e){let n=j().plugins;n.some(t=>t.name===e.name)||n.push(e),e.onRegister?.()}function N(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function oe(e,n,t){let s=n[0],r=n[1],i=n[2],h=n[3],y=n[4],o=n[5],a=n[6],c=n[7],l=n[8],m=n[9],u=n[10],M=n[11],f=n[12],d=n[13],A=n[14],T=n[15],x=t[0],g=t[1],F=t[2],R=t[3];return e[0]=x*s+g*y+F*l+R*f,e[1]=x*r+g*o+F*m+R*d,e[2]=x*i+g*a+F*u+R*A,e[3]=x*h+g*c+F*M+R*T,x=t[4],g=t[5],F=t[6],R=t[7],e[4]=x*s+g*y+F*l+R*f,e[5]=x*r+g*o+F*m+R*d,e[6]=x*i+g*a+F*u+R*A,e[7]=x*h+g*c+F*M+R*T,x=t[8],g=t[9],F=t[10],R=t[11],e[8]=x*s+g*y+F*l+R*f,e[9]=x*r+g*o+F*m+R*d,e[10]=x*i+g*a+F*u+R*A,e[11]=x*h+g*c+F*M+R*T,x=t[12],g=t[13],F=t[14],R=t[15],e[12]=x*s+g*y+F*l+R*f,e[13]=x*r+g*o+F*m+R*d,e[14]=x*i+g*a+F*u+R*A,e[15]=x*h+g*c+F*M+R*T,e}function X(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=r+r,a=i+i,c=h+h,l=r*o,m=r*a,u=r*c,M=i*a,f=i*c,d=h*c,A=y*o,T=y*a,x=y*c,g=s[0],F=s[1],R=s[2];return e[0]=(1-(M+d))*g,e[1]=(m+x)*g,e[2]=(u-T)*g,e[3]=0,e[4]=(m-x)*F,e[5]=(1-(l+d))*F,e[6]=(f+A)*F,e[7]=0,e[8]=(u+T)*R,e[9]=(f-A)*R,e[10]=(1-(l+M))*R,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function Z(e,n,t=0){let s=n[0],r=n[1],i=n[2],h=n[4],y=n[5],o=n[6],a=n[8],c=n[9],l=n[10],m=l*y-o*c,u=-l*h+o*a,M=c*h-y*a,f=s*m+r*u+i*M;return!f||t>0&&(!Number.isFinite(f)||Math.abs(f)<=t)||(f=1/f,e[0]=m*f,e[1]=u*f,e[2]=M*f,e[3]=(-l*r+i*c)*f,e[4]=(l*s-i*a)*f,e[5]=(-c*s+r*a)*f,e[6]=(o*r-i*y)*f,e[7]=(-o*s+i*h)*f,e[8]=(y*s-r*h)*f),e}function xe(e,n){let t=n[0],s=n[1],r=n[2],i=n[3],h=n[4],y=n[5],o=n[6],a=n[7],c=n[8],l=n[9],m=n[10],u=n[11],M=n[12],f=n[13],d=n[14],A=n[15],T=t*y-s*h,x=t*o-r*h,g=t*a-i*h,F=s*o-r*y,R=s*a-i*y,k=r*a-i*o,v=c*f-l*M,_=c*d-m*M,p=c*A-u*M,b=l*d-m*f,I=l*A-u*f,V=m*A-u*d,w=T*V-x*I+g*b+F*p-R*_+k*v;return w?(w=1/w,e[0]=(y*V-o*I+a*b)*w,e[1]=(r*I-s*V-i*b)*w,e[2]=(f*k-d*R+A*F)*w,e[3]=(m*R-l*k-u*F)*w,e[4]=(o*p-h*V-a*_)*w,e[5]=(t*V-r*p+i*_)*w,e[6]=(d*g-M*k-A*x)*w,e[7]=(c*k-m*g+u*x)*w,e[8]=(h*I-y*p+a*v)*w,e[9]=(s*p-t*I-i*v)*w,e[10]=(M*R-f*g+A*T)*w,e[11]=(l*g-c*R-u*T)*w,e[12]=(y*_-h*b-o*v)*w,e[13]=(t*b-s*_+r*v)*w,e[14]=(f*x-M*F-d*T)*w,e[15]=(c*F-l*x+m*T)*w,e):null}function Me(e,n){let t=Array.isArray(e?.nodes)?e.nodes.length:0,s=[];for(let c=0;c<t;c++)s.push(N());if(t===0)return s;let r=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let l of c.children)r.add(l);let i=new Set,h=128,y=(c,l,m=0)=>{if(m>h||c<0||c>=t||i.has(c))return;i.add(c);let u=e.nodes[c];if(!u)return;let M=N();if(n&&n[c])M.set(n[c]);else if(u.matrix&&u.matrix.length===16)M.set(u.matrix);else{let d=u.translation||[0,0,0],A=u.rotation||[0,0,0,1],T=u.scale||[1,1,1];X(M,A,d,T)}let f=s[c];if(l?oe(f,l,M):f.set(M),Array.isArray(u.children))for(let d of u.children)typeof d=="number"&&y(d,f,m+1)},o=[],a=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(a&&Array.isArray(a.nodes))o.push(...a.nodes);else for(let c=0;c<t;c++)r.has(c)||o.push(c);for(let c of o)y(c,null);for(let c=0;c<t;c++)!r.has(c)&&!o.includes(c)&&y(c,null);return s}function ae(e,n){function t(o,a,c,l){let m=typeof o=="number"?o:Number(o);return Number.isFinite(m)?Math.max(a,Math.min(c,m)):l}function s(o,a){let l=o[0]*a[0]+o[1]*a[1]+o[2]*a[2]+1;if(l<1e-6){if(Math.abs(o[0])>Math.abs(o[2])){let A=Math.hypot(o[1],o[0])||1;return[-o[1]/A,o[0]/A,0,0]}let d=Math.hypot(o[2],o[1])||1;return[0,-o[2]/d,o[1]/d,0]}let m=o[1]*a[2]-o[2]*a[1],u=o[2]*a[0]-o[0]*a[2],M=o[0]*a[1]-o[1]*a[0],f=Math.hypot(m,u,M,l)||1;return[m/f,u/f,M/f,l/f]}function r(o,a,c,l,m){let u=a[0]-o[0],M=a[1]-o[1],f=a[2]-o[2],d=Math.hypot(u,M,f),A=c[0]-a[0],T=c[1]-a[1],x=c[2]-a[2],g=Math.hypot(A,T,x);if(d<1e-6||g<1e-6)return{rootPos:[o[0],o[1],o[2]],midPos:[a[0],a[1],a[2]],effectorPos:[c[0],c[1],c[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let F=[u/d,M/d,f/d],R=[A/g,T/g,x/g],k=l[0]-o[0],v=l[1]-o[1],_=l[2]-o[2],p=Math.hypot(k,v,_),b=p>1e-6?[k/p,v/p,_/p]:F,I=Math.abs(d-g)+1e-5,V=Math.max(I,d+g-1e-5),w=Math.max(I,Math.min(V,p>1e-6?p:I)),S=t((d*d+w*w-g*g)/(2*d*w),-1,1,1),E=Math.sqrt(Math.max(0,1-S*S)),B=m?m[0]-o[0]:u,C=m?m[1]-o[1]:M,U=m?m[2]-o[2]:f,z=B*b[0]+C*b[1]+U*b[2],K=B-b[0]*z,O=C-b[1]*z,P=U-b[2]*z,D=Math.hypot(K,O,P);if(D<=1e-6){let be=Math.abs(b[1])<.99?0:1,ge=Math.abs(b[1])<.99?1:0,Ae=0;K=b[1]*Ae-b[2]*ge,O=b[2]*be-b[0]*Ae,P=b[0]*ge-b[1]*be,D=Math.hypot(K,O,P)||1}let te=[K/D,O/D,P/D],L=[o[0]+b[0]*(d*S)+te[0]*(d*E),o[1]+b[1]*(d*S)+te[1]*(d*E),o[2]+b[2]*(d*S)+te[2]*(d*E)],re=[o[0]+b[0]*w,o[1]+b[1]*w,o[2]+b[2]*w],he=re[0]-L[0],ye=re[1]-L[1],pe=re[2]-L[2],H=Math.hypot(he,ye,pe),q=H>1e-6?[he/H,ye/H,pe/H]:b,Ke=[L[0]+q[0]*g,L[1]+q[1]*g,L[2]+q[2]*g],Oe=[(L[0]-o[0])/d,(L[1]-o[1])/d,(L[2]-o[2])/d];return{rootPos:[o[0],o[1],o[2]],midPos:L,effectorPos:Ke,rootRotation:s(F,Oe),midRotation:s(R,q)}}function i(o,a,c=8,l=.001){let m=o.length;if(m<2)return{positions:o.map(p=>[p[0],p[1],p[2]]),rotations:[],iterations:0};let u=o.map(p=>[p[0],p[1],p[2]]),M=[],f=[],d=0;for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V);M.push(w),d+=w,f.push(w>1e-6?[b/w,I/w,V/w]:[0,1,0])}let A=[u[0][0],u[0][1],u[0][2]],T=Math.round(t(c,1,32,8)),x=t(l,1e-5,.1,.001),g=a[0]-A[0],F=a[1]-A[1],R=a[2]-A[2],k=Math.hypot(g,F,R),v=0;if(k>=d&&d>1e-6){let p=k>1e-6?[g/k,F/k,R/k]:f[0];u[0]=[A[0],A[1],A[2]];for(let b=0;b<m-1;b++){let I=M[b];u[b+1]=[u[b][0]+p[0]*I,u[b][1]+p[1]*I,u[b][2]+p[2]*I]}v=1}else for(let p=1;p<=T;p++){let b=u[m-1];if(Math.hypot(b[0]-a[0],b[1]-a[1],b[2]-a[2])<=x)break;v=p;let V=(w,S,E,B,C)=>{let U=S[0]-w[0],z=S[1]-w[1],K=S[2]-w[2],O=Math.hypot(U,z,K);if(O>1e-6){let P=E/O;return[w[0]+U*P,w[1]+z*P,w[2]+K*P]}return[w[0]+B[0]*E*C,w[1]+B[1]*E*C,w[2]+B[2]*E*C]};u[m-1]=[a[0],a[1],a[2]];for(let w=m-2;w>=0;w--)u[w]=V(u[w+1],u[w],M[w],f[w],-1);u[0]=[A[0],A[1],A[2]];for(let w=0;w<m-1;w++)u[w+1]=V(u[w],u[w+1],M[w],f[w],1)}let _=[];for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V),S=w>1e-6?[b/w,I/w,V/w]:f[p];_.push(s(f[p],S))}return{positions:u,rotations:_,iterations:v}}function h(o){if(!o||typeof o!="object"||Array.isArray(o))return null;let a=o;if(a.enabled===!1)return null;let c=x=>{if(typeof x!="string")return;let g=x.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(g)?g:void 0},l=x=>Array.isArray(x)&&x.length===3&&x.every(g=>typeof g=="number"&&Number.isFinite(g))?[t(x[0],-1e3,1e3,0),t(x[1],-1e3,1e3,0),t(x[2],-1e3,1e3,0)]:void 0,m=c(a.root),u=c(a.effector);if(!m||!u)return null;let M=c(a.mid),f=l(a.target)??c(a.target);if(!f)return null;let d=a.pole??a.poleTarget,A=l(d)??c(d),T=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||M?"two-bone":"fabrik";return{root:m,...M?{mid:M}:{},effector:u,target:f,...A?{pole:A}:{},solver:T,iterations:Math.round(t(a.iterations,1,32,8)),tolerance:t(a.tolerance,1e-5,.1,.001),weight:t(a.weight,0,1,1)}}let y=Object.freeze({solveTwoBone:r,solveFABRIK:i,parseIKTrait:h});return n&&typeof n=="object"&&(n.authorNamespace=n.authorNamespace||{},n.authorNamespace.IKSolver=y),{clampNum:t,parseIKTrait:h,quatFromUnitVectors:s,solveTwoBoneIK:r,solveFABRIK:i,IKSolver:y}}var G=ae(),Re=G.clampNum,We=G.parseIKTrait,le=G.quatFromUnitVectors,Fe=G.solveTwoBoneIK,Ie=G.solveFABRIK,ze=G.IKSolver;function ce(e){let n=e?.transform??e?.modelMatrix;return n&&n.length>=16?[n[12]||0,n[13]||0,n[14]||0]:[0,0,0]}function Ge(e,n){let t=e?.transform??e?.modelMatrix;!t||t.length<16||(t[12]=n[0],t[13]=n[1],t[14]=n[2])}function Ue(e,n,t,s,r){let i=Re(r,0,1,1),h=n[0]+(t[0]-n[0])*i,y=n[1]+(t[1]-n[1])*i,o=n[2]+(t[2]-n[2])*i,a=h-e[0],c=y-e[1],l=o-e[2],m=Math.hypot(a,c,l);if(m>1e-6&&s>1e-6){let A=s/m;return[e[0]+a*A,e[1]+c*A,e[2]+l*A]}let u=t[0]-e[0],M=t[1]-e[1],f=t[2]-e[2],d=Math.hypot(u,M,f);if(d>1e-6&&s>1e-6){let A=s/d;return[e[0]+u*A,e[1]+M*A,e[2]+f*A]}return[h,y,o]}function De(e,n){let t=e?.modelRootMatrix;if(!t||t.length!==16)return n;let s=new Float32Array(16);return xe(s,t instanceof Float32Array?t:Float32Array.from(t))?[s[0]*n[0]+s[4]*n[1]+s[8]*n[2]+s[12],s[1]*n[0]+s[5]*n[1]+s[9]*n[2]+s[13],s[2]*n[0]+s[6]*n[1]+s[10]*n[2]+s[14]]:n}function se(e,n){e.__ikWarned||(e.__ikWarned=new Set);let t=e.__ikWarned;t.has(n)||(t.add(n),console.warn(`[three-live] ik: joint '${n}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function ue(e,n,t){if(Array.isArray(e))return[e[0],e[1],e[2]];let s=n.get(e);if(s)return ce(s);let r;if(e==="head"?r=t?.headPose?.position??t?.headPose??t?.cameraPosition:e==="hand-left"?r=t?.handPoses?.left?.position??t?.handPoses?.left??t?.hands?.left?.position??t?.hands?.left:e==="hand-right"&&(r=t?.handPoses?.right?.position??t?.handPoses?.right??t?.hands?.right?.position??t?.hands?.right),(Array.isArray(r)||ArrayBuffer.isView(r))&&r.length>=3){let i=r;return De(t,[i[0],i[1],i[2]])}return null}function ie(e,n){return[e[3]*n[0]+e[0]*n[3]+e[1]*n[2]-e[2]*n[1],e[3]*n[1]-e[0]*n[2]+e[1]*n[3]+e[2]*n[0],e[3]*n[2]+e[0]*n[1]-e[1]*n[0]+e[2]*n[3],e[3]*n[3]-e[0]*n[0]-e[1]*n[1]-e[2]*n[2]]}function je(e){return[-e[0],-e[1],-e[2],e[3]]}function me(e){let n=Math.hypot(e[0],e[1],e[2],e[3]);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n,e[3]/n]:[0,0,0,1]}function Qe(e,n){if(n>=1)return e;if(n<=0)return[0,0,0,1];let[t,s,r,i]=e;i<0&&(t=-t,s=-s,r=-r,i=-i);let h=Math.acos(Math.min(1,i)),y=Math.sin(h);if(y<1e-9)return[0,0,0,1];let o=Math.sin(h*n)/y;return me([t*o,s*o,r*o,Math.cos(h*n)])}function Xe(e){let n=Math.hypot(e[0],e[1],e[2])||1,t=Math.hypot(e[4],e[5],e[6])||1,s=Math.hypot(e[8],e[9],e[10])||1,r=e[0]/n,i=e[1]/n,h=e[2]/n,y=e[4]/t,o=e[5]/t,a=e[6]/t,c=e[8]/s,l=e[9]/s,m=e[10]/s,u=r+o+m,M;if(u>0){let f=Math.sqrt(u+1)*2;M=[(a-l)/f,(c-h)/f,(i-y)/f,.25*f]}else if(r>o&&r>m){let f=Math.sqrt(1+r-o-m)*2;M=[.25*f,(y+i)/f,(c+h)/f,(a-l)/f]}else if(o>m){let f=Math.sqrt(1+o-r-m)*2;M=[(y+i)/f,.25*f,(l+a)/f,(c-h)/f]}else{let f=Math.sqrt(1+m-r-o)*2;M=[(c+h)/f,(l+a)/f,.25*f,(i-y)/f]}return me(M)}function Je(e,n,t){let[s,r,i,h]=t,y=1-2*(r*r+i*i),o=2*(s*r-i*h),a=2*(s*i+r*h),c=2*(s*r+i*h),l=1-2*(s*s+i*i),m=2*(r*i-s*h),u=2*(s*i-r*h),M=2*(r*i+s*h),f=1-2*(s*s+r*r);for(let d=0;d<3;d++){let A=n[d*4],T=n[d*4+1],x=n[d*4+2];e[d*4]=y*A+o*T+a*x,e[d*4+1]=c*A+l*T+m*x,e[d*4+2]=u*A+M*T+f*x}}function ee(e,n){let t=n[0]-e[0],s=n[1]-e[1],r=n[2]-e[2],i=Math.hypot(t,s,r);return i>1e-9?[t/i,s/i,r/i]:null}function Ve(e){e?.normalMatrix&&e?.transform&&Z(e.normalMatrix,e.transform)}var we=new WeakMap;function $e(e){let n=we.get(e);return n||(n=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((t,s)=>{for(let r of Array.isArray(t?.children)?t.children:[])typeof r=="number"&&r>=0&&r<n.length&&(n[r]=s)}),we.set(e,n)),n}function He(e,n,t){let s=e?.gltf,r=s?.nodes;if(!Array.isArray(r)||r.length===0)return!1;let i=new Map;r.forEach((p,b)=>{typeof p?.name=="string"&&p.name&&!i.has(p.name)&&i.set(p.name,b)});let y=(n.mid?[n.root,n.mid,n.effector]:[n.root,n.effector]).map(p=>i.get(p));if(y.some(p=>p===void 0))return!1;let o=y,a=$e(s);for(let p=1;p<o.length;p++){let b=a[o[p]],I=0;for(;b>=0&&b!==o[p-1]&&I++<256;)b=a[b];if(b!==o[p-1])return!1}let c=o[0],l=e.initialNodeTransforms,m=new Map,u=[],M=[c];for(;M.length&&u.length<4096;){let p=M.pop();if(m.has(p))continue;let b=l?.[p],I=r[p];m.set(p,{t:b?[b.t[0],b.t[1],b.t[2]]:I?.translation?[...I.translation]:[0,0,0],r:b?[b.r[0],b.r[1],b.r[2],b.r[3]]:I?.rotation?[...I.rotation]:[0,0,0,1],s:b?[b.s[0],b.s[1],b.s[2]]:I?.scale?[...I.scale]:[1,1,1]}),u.push(p);for(let V of Array.isArray(I?.children)?I.children:[])typeof V=="number"&&M.push(V)}let f=a[c],d=f>=0&&e.worldMatrices?.[f]?.length===16?Float32Array.from(e.worldMatrices[f]):N(),A=new Map,T=()=>{let p=(b,I)=>{let V=m.get(b);if(!V)return;let w=N();X(w,V.r,V.t,V.s);let S=N();oe(S,I,w),A.set(b,S);for(let E of Array.isArray(r[b]?.children)?r[b].children:[])typeof E=="number"&&p(E,S)};p(c,d)},x=p=>{let b=A.get(p);return[b[12],b[13],b[14]]};T();let g=o.map(x),F=p=>{if(typeof p=="string"&&!t.has(p)){let b=i.get(p),I=b!==void 0?A.get(b)??e.worldMatrices?.[b]:void 0;if(I&&I.length===16)return[I[12],I[13],I[14]]}return ue(p,t,e)},R=F(n.target);if(!R)return!0;let k=n.pole?F(n.pole)??void 0:void 0,v=ve(g,n,R,k),_=Re(n.weight,0,1,1);for(let p=0;p<o.length-1;p++){let b=ee(x(o[p]),x(o[p+1])),I=ee(v[p],v[p+1]);if(!b||!I)continue;let V=Qe(le(b,I),_),w=o[p],S=a[w],E=S===f||S<0?d:A.get(S)??d,B=Xe(E),C=m.get(w);C.r=me(ie(je(B),ie(V,ie(B,C.r)))),T()}if(Array.isArray(e.worldMatrices))for(let[p,b]of A)e.worldMatrices[p]?.set&&e.worldMatrices[p].set(b);for(let p of e.meshes??[]){let b=A.get(p?.nodeIndex);b&&p.transform?.set&&(p.transform.set(b),Ve(p))}return!0}function ve(e,n,t,s){if(n.solver==="two-bone"&&e.length===3){let r=Fe(e[0],e[1],e[2],t,s);return[e[0],r.midPos,r.effectorPos]}return Ie(e,t,n.iterations,n.tolerance).positions}function qe(e,n,t){let s=e.__ikRestOffsets,r=e.__ikRestMats;if(!(!s||!r))for(let i=0;i<n.length-1;i++){let h=n[i]?.transform??n[i]?.modelMatrix,y=r[i],o=ee([0,0,0],s[i]),a=ee(t[i],t[i+1]);!h||h.length<16||!y||y.length<16||!o||!a||(Je(h,y,le(o,a)),Ve(n[i]))}}var Se={name:"ik",onRegister(){let e=j();Te(ae),ae(e.threeNamespace,e)},onUpdate(e){let n=e?.meshes;if(!Array.isArray(n)||n.length===0)return;let t=null;for(let s of n){let r=s?.userData?.xr?.ik??s?.extras?.xr?.ik??s?.extensions?.ANDROID_xr_scenecore?.ik;if(!r)continue;let i=We(r);if(!i||i.weight<=0)continue;if(!t){t=new Map;for(let g of n)g&&typeof g.name=="string"&&g.name&&t.set(g.name,g)}if(He(e,i,t))continue;let h=t.get(i.root),y=t.get(i.effector),o=i.mid?t.get(i.mid):void 0;if(h||se(s,i.root),y||se(s,i.effector),i.mid&&!o&&se(s,i.mid),!h||!y)continue;let a=ue(i.target,t,e);if(!a)continue;let c=i.pole?ue(i.pole,t,e)??void 0:void 0,l=o?[h,o,y]:[h,y],m=l.map(g=>g.name||"").join(">");if(!s.__ikRestOffsets||s.__ikRestKey!==m){let g=l.map(ce),F=[];for(let R=0;R<g.length-1;R++)F.push([g[R+1][0]-g[R][0],g[R+1][1]-g[R][1],g[R+1][2]-g[R][2]]);s.__ikRestOffsets=F,s.__ikRestKey=m,s.__ikRestMats=l.map(R=>Array.from(R.transform??R.modelMatrix??[]))}let u=s.__ikRestOffsets,f=[ce(h)],d=[];for(let g=0;g<u.length;g++){let F=f[g],R=u[g];f.push([F[0]+R[0],F[1]+R[1],F[2]+R[2]]),d.push(Math.hypot(R[0],R[1],R[2]))}let A=ve(f,i,a,c),T=f[0],x=[f[0]];for(let g=1;g<l.length;g++){let F=u[g-1],R=[T[0]+F[0],T[1]+F[1],T[2]+F[2]],k=[T[0]+(A[g][0]-A[g-1][0]),T[1]+(A[g][1]-A[g-1][1]),T[2]+(A[g][2]-A[g-1][2])],v=Ue(T,R,k,d[g-1],i.weight);Ge(l[g],v),T=v,x.push(v)}qe(s,l,x)}}};var Ye={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function W(e,n,t,s){if(!t||t.bufferView===void 0)return null;let r=e.bufferViews?.[t.bufferView];if(!r)return null;let i=Number(t.count??0);if(!Number.isInteger(i)||i<=0)return null;let h=t.componentType??5126,y=Ye[h];if(!y)throw new RangeError(`glTF accessor has unsupported componentType ${h}`);let o=y*s,a=r.byteStride&&r.byteStride>0?r.byteStride:o,c=(r.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(c)||c<0||a<o||c+(i-1)*a+o>n.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${n.byteLength} bytes)`);if(h===5126&&a===o&&c%4===0)return new Float32Array(n,c,i*s);let l=new DataView(n),m=t.normalized===!0,u=new Float32Array(i*s);for(let M=0;M<i;M++){let f=c+M*a;for(let d=0;d<s;d++){let A=f+d*y,T;switch(h){case 5126:T=l.getFloat32(A,!0);break;case 5120:T=l.getInt8(A),m&&(T=Math.max(T/127,-1));break;case 5121:T=l.getUint8(A),m&&(T/=255);break;case 5122:T=l.getInt16(A,!0),m&&(T=Math.max(T/32767,-1));break;case 5123:T=l.getUint16(A,!0),m&&(T/=65535);break;default:T=l.getUint32(A,!0),m&&(T/=4294967295)}u[M*s+d]=T}}return u}function ke(e,n,t){return n%4===0?new Float32Array(e,n,t):new Float32Array(e.slice(n,n+t*4))}function Ee(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=t[0],a=t[1],c=t[2],l=t[3],m=r*o+i*a+h*c+y*l;if(m<0&&(o=-o,a=-a,c=-c,l=-l,m=-m),Math.abs(m)>=1)return e[0]=r,e[1]=i,e[2]=h,e[3]=y,e;let u=Math.acos(m),M=Math.sqrt(1-m*m);if(Math.abs(M)<.001)return e[0]=.5*(r+o),e[1]=.5*(i+a),e[2]=.5*(h+c),e[3]=.5*(y+l),e;let f=Math.sin((1-s)*u)/M,d=Math.sin(s*u)/M;return e[0]=r*f+o*d,e[1]=i*f+a*d,e[2]=h*f+c*d,e[3]=y*f+l*d,e}function _e(e,n,t,s){return e[0]=n[0]+s*(t[0]-n[0]),e[1]=n[1]+s*(t[1]-n[1]),e[2]=n[2]+s*(t[2]-n[2]),e}function Le(e,n){if(!Array.isArray(e?.animations))return[];let t=[];for(let s=0;s<e.animations.length;s++){let r=e.animations[s],i=r.name||`Animation_${s}`,h=[],y=0;if(Array.isArray(r.channels)&&Array.isArray(r.samplers))for(let o of r.channels){if(!o.target||o.target.node===void 0||!o.target.path)continue;let a=r.samplers[o.sampler];if(!a)continue;let c=e.accessors?.[a.input],l=e.accessors?.[a.output];if(!c||!l)continue;let m=e.bufferViews?.[c.bufferView],u=e.bufferViews?.[l.bufferView];if(!m||!u)continue;let M=(m.byteOffset||0)+(c.byteOffset||0),f=(u.byteOffset||0)+(l.byteOffset||0),d=W(e,n,c,1)??ke(n,M,c.count);d.length>0&&d[d.length-1]>y&&(y=d[d.length-1]);let A=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(l.count/Math.max(1,c.count))):3,T=o.target.path==="weights"?1:A,x=W(e,n,l,T)??ke(n,f,l.count*T),g=a.interpolation==="STEP"?"STEP":"LINEAR";h.push({nodeIndex:o.target.node,path:o.target.path,times:d,values:x,interpolation:g})}h.length>0&&t.push({name:i,duration:y,channels:h})}return t}function J(e,n,t){let{times:s,values:r,path:i,interpolation:h}=e,y=s.length;if(y===0)return;let o=i==="rotation"?4:i==="weights"?Math.max(1,Math.round(r.length/y)):3;if(n<=s[0]){for(let T=0;T<o;T++)t[T]=r[T];return}if(n>=s[y-1]){let T=(y-1)*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let a=0,c=y-1;for(;a<=c;){let T=a+c>>1;s[T]<=n?a=T+1:c=T-1}let l=Math.max(0,c),m=Math.min(y-1,l+1);if(h==="STEP"||l===m){let T=l*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let u=s[l],M=s[m],f=(n-u)/Math.max(1e-5,M-u),d=l*o,A=m*o;if(i==="rotation"){let T=[r[d],r[d+1],r[d+2],r[d+3]],x=[r[A],r[A+1],r[A+2],r[A+3]];Ee(t,T,x,f)}else for(let T=0;T<o;T++)t[T]=r[d+T]+f*(r[A+T]-r[d+T])}var ne=new WeakMap;function Ne(e,n,t=.3){if(!e?.animations)return;let s=e.animations.find(y=>y.name===n);if(!s)return;let r=ne.get(e);r||(r=[],e.currentClip&&r.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),ne.set(e,r));let i=t>0?1/t:1e3;for(let y of r)y.clip.name!==n&&(y.fadeSpeed=-i);let h=r.find(y=>y.clip.name===n);h?h.fadeSpeed=i:r.push({clip:s,time:0,weight:t>0?0:1,fadeSpeed:i}),e.currentClip=s,e.isPlayingAnimation=!0}function fe(e,n){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let t=ne.get(e);if(!t||t.length===0){if(!e.currentClip)return;t=[{clip:e.currentClip,time:n,weight:1,fadeSpeed:0}]}let s=e.gltf.nodes.length,r=[];for(let l=0;l<s;l++){let m=e.initialNodeTransforms[l];m?r.push({t:[m.t[0],m.t[1],m.t[2]],r:[m.r[0],m.r[1],m.r[2],m.r[3]],s:[m.s[0],m.s[1],m.s[2]]}):r.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let i=[0,0,0],h=[0,0,0,1],y=[1,1,1],o=new Float32Array(64);for(let l of t){let m=Math.max(0,Math.min(1,l.weight));if(!(m<=1e-4))for(let u of l.clip.channels){if(u.nodeIndex<0||u.nodeIndex>=s)continue;let M=r[u.nodeIndex];if(u.path==="translation")J(u,l.time,i),_e(M.t,M.t,i,m);else if(u.path==="rotation")J(u,l.time,h),Ee(M.r,M.r,h,m);else if(u.path==="scale")J(u,l.time,y),_e(M.s,M.s,y,m);else if(u.path==="weights"&&(J(u,l.time,o),e.meshes)){for(let f of e.meshes)if(f.nodeIndex===u.nodeIndex){for(let d of f.primitives)if(d.pluginData?.morph?.weights){let A=d.pluginData.morph.weights,T=d.pluginData.morph.numTargets||A.length;for(let x=0;x<T;x++)A[x]=A[x]*(1-m)+o[x]*m}}}}}let a=[];for(let l=0;l<s;l++){let m=N(),{t:u,r:M,s:f}=r[l];X(m,M,u,f),a.push(m)}let c=Me(e.gltf,a);e.worldMatrices=c;for(let l of e.meshes)l.nodeIndex>=0&&l.nodeIndex<c.length&&(l.transform.set(c[l.nodeIndex]),Z(l.normalMatrix,l.transform))}var Be={name:"keyframes",evaluateAnimation:fe,crossFadeTo:Ne,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=Le(e.gltf,e.bin))},onUpdate(e,n){if(!e.isPlayingAnimation)return;let t=ne.get(e);if(t&&t.length>0){for(let s=t.length-1;s>=0;s--){let r=t[s];if(r.time+=n,r.clip.duration>0&&(r.time%=r.clip.duration),r.fadeSpeed!==0)if(r.weight+=r.fadeSpeed*n,r.weight<=0){t.splice(s,1);continue}else r.weight>=1&&(r.weight=1,r.fadeSpeed=0)}t.length>0&&(e.animationTime=t[t.length-1].time),fe(e,e.animationTime)}else e.currentClip&&(e.animationTime+=n,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),fe(e,e.animationTime))}};var $=64;function Ze(e,n,t){if(!(!e?.meshes||n<0||n>=$))for(let s of e.meshes)for(let r of s.primitives){let i=r.pluginData?.morph;i?.weights&&(i.weights[n]=t)}}var Ce={name:"morph",onResolveShader(e,n,t,s){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let r=t.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 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;
18
17
  uniform sampler2D uMorphDeltasTex;
19
- uniform float uMorphWeights[${$}];
20
- uniform int uNumMorphTargets;`);return r=r.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
21
- for (int m = 0; m < ${$}; m++) {
18
+ uniform float uMorphWeights[${L}];
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++) {
22
21
  if (m >= uNumMorphTargets) break;
23
22
  float w = uMorphWeights[m];
24
23
  if (abs(w) > 0.0001) {
25
24
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
26
25
  }
27
26
  }
28
- vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.targets;if(!Array.isArray(i)||i.length===0)return null;let h=t.attributes?.POSITION,y=s?.accessors?.[h];if(!y)return null;let o=y.count,a=Math.min(i.length,$),c=new Float32Array(o*a*4);for(let u=0;u<a;u++){let M=i[u].POSITION;if(M===void 0)continue;let f=s.accessors?.[M],d=s.bufferViews?.[f?.bufferView];if(!f||!d)continue;let A=W(s,r,f,3);if(!A||A.length<o*3)continue;let T=u*o*4;for(let x=0;x<o;x++)c[T+x*4]=A[x*3],c[T+x*4+1]=A[x*3+1],c[T+x*4+2]=A[x*3+2],c[T+x*4+3]=0}let l=e.createTexture();e.bindTexture(3553,l),e.texImage2D(3553,0,34836,o,a,0,6408,5126,c),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array($);return{hasMorph:!0,morphTex:l,numTargets:a,vertexCount:o,weights:m}},onBeforeDrawPrimitive(e,n,t,s,r,i){let h=t.pluginData?.morph;if(!h?.hasMorph||!h.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,h.morphTex);let y=e.getUniformLocation(n,"uMorphDeltasTex");y&&e.uniform1i(y,5);let o=e.getUniformLocation(n,"uNumMorphTargets");o&&e.uniform1i(o,h.numTargets);let a=e.getUniformLocation(n,"uMorphWeights[0]");a&&e.uniform1fv(a,h.weights)}};var de=64,Pe={name:"skinning",onResolveShader(e,n,t,s){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let r=t.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,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;
29
28
  layout(location=4) in uvec4 aJoints;
30
29
  layout(location=5) in vec4 aWeights;
31
- uniform mat4 uJointMatrix[${de}];`),i=r.includes("morphedPos")?"morphedPos":"aPosition";return r=r.replace(`vec4 world=uModel*vec4(${i},1.0);`,`mat4 skinMatrix =
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
31
  aWeights.x * uJointMatrix[int(aJoints.x)] +
33
32
  aWeights.y * uJointMatrix[int(aJoints.y)] +
34
33
  aWeights.z * uJointMatrix[int(aJoints.z)] +
35
34
  aWeights.w * uJointMatrix[int(aJoints.w)];
36
- vec4 world=uModel*(skinMatrix*vec4(${i},1.0));`).replace(`gl_Position=uMVP*vec4(${i},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${i},1.0));`),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.attributes;if(!i||i.JOINTS_0===void 0||i.WEIGHTS_0===void 0)return null;let h=s.accessors[i.JOINTS_0],y=s.accessors[i.WEIGHTS_0];if(!h||!y)return null;let o=s.bufferViews[h.bufferView],a=s.bufferViews[y.bufferView];if(!o||!a)return null;let c=(o.byteOffset||0)+(h.byteOffset||0),l=(a.byteOffset||0)+(y.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let u=h.componentType===5121?5121:5123,M=u===5121?new Uint8Array(r,c,h.count*4):new Uint16Array(r,c,h.count*4);e.bufferData(34962,M,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,u,0,0);let f=e.createBuffer();e.bindBuffer(34962,f);let d=W(s,r,y,4)??new Float32Array(r,l,y.count*4);return e.bufferData(34962,d,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,f]}},onBeforeDrawPrimitive(e,n,t,s,r,i){if(!t.pluginData?.skinning?.hasSkin)return;let h=i?.nodes?.[s.nodeIndex]?.skin;if(h===void 0||!i.skins||!i.skins[h])return;let o=i.skins[h].joints||[],a=new Float32Array(de*16);for(let l=0;l<o.length&&l<de;l++){let m=o[l],u=r[m]||N();a.subarray(l*16,(l+1)*16).set(u)}let c=e.getUniformLocation(n,"uJointMatrix[0]");c&&e.uniformMatrix4fv(c,!1,a)}};Q(Ce);Q(Be);Q(Pe);Q(Se);export{ze as IKSolver,Ne as crossFadeTo,Se as ikPlugin,Be as keyframeAnimationPlugin,Ce as morphPlugin,Le as parseAnimations,le as quatFromUnitVectors,J as sampleChannel,Ze as setMorphTargetWeight,Pe as skinningPlugin,Ie as solveFABRIK,Fe 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],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};
@@ -1,4 +1,4 @@
1
- /**
1
+ "use strict";/**
2
2
  * @license
3
3
  * Copyright 2026 Google LLC
4
4
  *
@@ -13,11 +13,10 @@
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
- */
17
- "use strict";var ThreeLiveAnimation=(()=>{var se=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var je=Object.prototype.hasOwnProperty;var Qe=(e,n)=>{for(var t in n)se(e,t,{get:n[t],enumerable:!0})},Xe=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of De(n))!je.call(e,r)&&r!==t&&se(e,r,{get:()=>n[r],enumerable:!(s=Ue(n,r))||s.enumerable});return e};var Je=e=>Xe(se({},"__esModule",{value:!0}),e);var cn={};Qe(cn,{IKSolver:()=>Ne,crossFadeTo:()=>ge,ikPlugin:()=>ye,keyframeAnimationPlugin:()=>Ae,morphPlugin:()=>Te,parseAnimations:()=>be,quatFromUnitVectors:()=>ne,sampleChannel:()=>U,setMorphTargetWeight:()=>We,skinningPlugin:()=>Me,solveFABRIK:()=>de,solveTwoBoneIK:()=>fe});var Y="__THREE_LIVE_REGISTRY__";function Q(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Y]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,Y,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[Y]=n}}return e[Y]}var ln=Q().plugins;function Se(e){let n=Q();n.workerExtensionInstallers||(n.workerExtensionInstallers=[]),n.workerExtensionInstallers.includes(e)||n.workerExtensionInstallers.push(e)}function X(e){let n=Q().plugins;n.some(t=>t.name===e.name)||n.push(e),e.onRegister?.()}function N(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function ie(e,n,t){let s=n[0],r=n[1],i=n[2],h=n[3],y=n[4],o=n[5],a=n[6],c=n[7],l=n[8],m=n[9],u=n[10],M=n[11],f=n[12],d=n[13],A=n[14],T=n[15],x=t[0],g=t[1],F=t[2],R=t[3];return e[0]=x*s+g*y+F*l+R*f,e[1]=x*r+g*o+F*m+R*d,e[2]=x*i+g*a+F*u+R*A,e[3]=x*h+g*c+F*M+R*T,x=t[4],g=t[5],F=t[6],R=t[7],e[4]=x*s+g*y+F*l+R*f,e[5]=x*r+g*o+F*m+R*d,e[6]=x*i+g*a+F*u+R*A,e[7]=x*h+g*c+F*M+R*T,x=t[8],g=t[9],F=t[10],R=t[11],e[8]=x*s+g*y+F*l+R*f,e[9]=x*r+g*o+F*m+R*d,e[10]=x*i+g*a+F*u+R*A,e[11]=x*h+g*c+F*M+R*T,x=t[12],g=t[13],F=t[14],R=t[15],e[12]=x*s+g*y+F*l+R*f,e[13]=x*r+g*o+F*m+R*d,e[14]=x*i+g*a+F*u+R*A,e[15]=x*h+g*c+F*M+R*T,e}function J(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=r+r,a=i+i,c=h+h,l=r*o,m=r*a,u=r*c,M=i*a,f=i*c,d=h*c,A=y*o,T=y*a,x=y*c,g=s[0],F=s[1],R=s[2];return e[0]=(1-(M+d))*g,e[1]=(m+x)*g,e[2]=(u-T)*g,e[3]=0,e[4]=(m-x)*F,e[5]=(1-(l+d))*F,e[6]=(f+A)*F,e[7]=0,e[8]=(u+T)*R,e[9]=(f-A)*R,e[10]=(1-(l+M))*R,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function Z(e,n,t=0){let s=n[0],r=n[1],i=n[2],h=n[4],y=n[5],o=n[6],a=n[8],c=n[9],l=n[10],m=l*y-o*c,u=-l*h+o*a,M=c*h-y*a,f=s*m+r*u+i*M;return!f||t>0&&(!Number.isFinite(f)||Math.abs(f)<=t)||(f=1/f,e[0]=m*f,e[1]=u*f,e[2]=M*f,e[3]=(-l*r+i*c)*f,e[4]=(l*s-i*a)*f,e[5]=(-c*s+r*a)*f,e[6]=(o*r-i*y)*f,e[7]=(-o*s+i*h)*f,e[8]=(y*s-r*h)*f),e}function ke(e,n){let t=n[0],s=n[1],r=n[2],i=n[3],h=n[4],y=n[5],o=n[6],a=n[7],c=n[8],l=n[9],m=n[10],u=n[11],M=n[12],f=n[13],d=n[14],A=n[15],T=t*y-s*h,x=t*o-r*h,g=t*a-i*h,F=s*o-r*y,R=s*a-i*y,k=r*a-i*o,v=c*f-l*M,_=c*d-m*M,p=c*A-u*M,b=l*d-m*f,I=l*A-u*f,V=m*A-u*d,w=T*V-x*I+g*b+F*p-R*_+k*v;return w?(w=1/w,e[0]=(y*V-o*I+a*b)*w,e[1]=(r*I-s*V-i*b)*w,e[2]=(f*k-d*R+A*F)*w,e[3]=(m*R-l*k-u*F)*w,e[4]=(o*p-h*V-a*_)*w,e[5]=(t*V-r*p+i*_)*w,e[6]=(d*g-M*k-A*x)*w,e[7]=(c*k-m*g+u*x)*w,e[8]=(h*I-y*p+a*v)*w,e[9]=(s*p-t*I-i*v)*w,e[10]=(M*R-f*g+A*T)*w,e[11]=(l*g-c*R-u*T)*w,e[12]=(y*_-h*b-o*v)*w,e[13]=(t*b-s*_+r*v)*w,e[14]=(f*x-M*F-d*T)*w,e[15]=(c*F-l*x+m*T)*w,e):null}function _e(e,n){let t=Array.isArray(e?.nodes)?e.nodes.length:0,s=[];for(let c=0;c<t;c++)s.push(N());if(t===0)return s;let r=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let l of c.children)r.add(l);let i=new Set,h=128,y=(c,l,m=0)=>{if(m>h||c<0||c>=t||i.has(c))return;i.add(c);let u=e.nodes[c];if(!u)return;let M=N();if(n&&n[c])M.set(n[c]);else if(u.matrix&&u.matrix.length===16)M.set(u.matrix);else{let d=u.translation||[0,0,0],A=u.rotation||[0,0,0,1],T=u.scale||[1,1,1];J(M,A,d,T)}let f=s[c];if(l?ie(f,l,M):f.set(M),Array.isArray(u.children))for(let d of u.children)typeof d=="number"&&y(d,f,m+1)},o=[],a=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(a&&Array.isArray(a.nodes))o.push(...a.nodes);else for(let c=0;c<t;c++)r.has(c)||o.push(c);for(let c of o)y(c,null);for(let c=0;c<t;c++)!r.has(c)&&!o.includes(c)&&y(c,null);return s}function ue(e,n){function t(o,a,c,l){let m=typeof o=="number"?o:Number(o);return Number.isFinite(m)?Math.max(a,Math.min(c,m)):l}function s(o,a){let l=o[0]*a[0]+o[1]*a[1]+o[2]*a[2]+1;if(l<1e-6){if(Math.abs(o[0])>Math.abs(o[2])){let A=Math.hypot(o[1],o[0])||1;return[-o[1]/A,o[0]/A,0,0]}let d=Math.hypot(o[2],o[1])||1;return[0,-o[2]/d,o[1]/d,0]}let m=o[1]*a[2]-o[2]*a[1],u=o[2]*a[0]-o[0]*a[2],M=o[0]*a[1]-o[1]*a[0],f=Math.hypot(m,u,M,l)||1;return[m/f,u/f,M/f,l/f]}function r(o,a,c,l,m){let u=a[0]-o[0],M=a[1]-o[1],f=a[2]-o[2],d=Math.hypot(u,M,f),A=c[0]-a[0],T=c[1]-a[1],x=c[2]-a[2],g=Math.hypot(A,T,x);if(d<1e-6||g<1e-6)return{rootPos:[o[0],o[1],o[2]],midPos:[a[0],a[1],a[2]],effectorPos:[c[0],c[1],c[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let F=[u/d,M/d,f/d],R=[A/g,T/g,x/g],k=l[0]-o[0],v=l[1]-o[1],_=l[2]-o[2],p=Math.hypot(k,v,_),b=p>1e-6?[k/p,v/p,_/p]:F,I=Math.abs(d-g)+1e-5,V=Math.max(I,d+g-1e-5),w=Math.max(I,Math.min(V,p>1e-6?p:I)),S=t((d*d+w*w-g*g)/(2*d*w),-1,1,1),E=Math.sqrt(Math.max(0,1-S*S)),B=m?m[0]-o[0]:u,C=m?m[1]-o[1]:M,D=m?m[2]-o[2]:f,z=B*b[0]+C*b[1]+D*b[2],K=B-b[0]*z,O=C-b[1]*z,P=D-b[2]*z,j=Math.hypot(K,O,P);if(j<=1e-6){let Ie=Math.abs(b[1])<.99?0:1,Ve=Math.abs(b[1])<.99?1:0,ve=0;K=b[1]*ve-b[2]*Ve,O=b[2]*Ie-b[0]*ve,P=b[0]*Ve-b[1]*Ie,j=Math.hypot(K,O,P)||1}let re=[K/j,O/j,P/j],L=[o[0]+b[0]*(d*S)+re[0]*(d*E),o[1]+b[1]*(d*S)+re[1]*(d*E),o[2]+b[2]*(d*S)+re[2]*(d*E)],oe=[o[0]+b[0]*w,o[1]+b[1]*w,o[2]+b[2]*w],we=oe[0]-L[0],Re=oe[1]-L[1],Fe=oe[2]-L[2],H=Math.hypot(we,Re,Fe),q=H>1e-6?[we/H,Re/H,Fe/H]:b,ze=[L[0]+q[0]*g,L[1]+q[1]*g,L[2]+q[2]*g],Ge=[(L[0]-o[0])/d,(L[1]-o[1])/d,(L[2]-o[2])/d];return{rootPos:[o[0],o[1],o[2]],midPos:L,effectorPos:ze,rootRotation:s(F,Ge),midRotation:s(R,q)}}function i(o,a,c=8,l=.001){let m=o.length;if(m<2)return{positions:o.map(p=>[p[0],p[1],p[2]]),rotations:[],iterations:0};let u=o.map(p=>[p[0],p[1],p[2]]),M=[],f=[],d=0;for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V);M.push(w),d+=w,f.push(w>1e-6?[b/w,I/w,V/w]:[0,1,0])}let A=[u[0][0],u[0][1],u[0][2]],T=Math.round(t(c,1,32,8)),x=t(l,1e-5,.1,.001),g=a[0]-A[0],F=a[1]-A[1],R=a[2]-A[2],k=Math.hypot(g,F,R),v=0;if(k>=d&&d>1e-6){let p=k>1e-6?[g/k,F/k,R/k]:f[0];u[0]=[A[0],A[1],A[2]];for(let b=0;b<m-1;b++){let I=M[b];u[b+1]=[u[b][0]+p[0]*I,u[b][1]+p[1]*I,u[b][2]+p[2]*I]}v=1}else for(let p=1;p<=T;p++){let b=u[m-1];if(Math.hypot(b[0]-a[0],b[1]-a[1],b[2]-a[2])<=x)break;v=p;let V=(w,S,E,B,C)=>{let D=S[0]-w[0],z=S[1]-w[1],K=S[2]-w[2],O=Math.hypot(D,z,K);if(O>1e-6){let P=E/O;return[w[0]+D*P,w[1]+z*P,w[2]+K*P]}return[w[0]+B[0]*E*C,w[1]+B[1]*E*C,w[2]+B[2]*E*C]};u[m-1]=[a[0],a[1],a[2]];for(let w=m-2;w>=0;w--)u[w]=V(u[w+1],u[w],M[w],f[w],-1);u[0]=[A[0],A[1],A[2]];for(let w=0;w<m-1;w++)u[w+1]=V(u[w],u[w+1],M[w],f[w],1)}let _=[];for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V),S=w>1e-6?[b/w,I/w,V/w]:f[p];_.push(s(f[p],S))}return{positions:u,rotations:_,iterations:v}}function h(o){if(!o||typeof o!="object"||Array.isArray(o))return null;let a=o;if(a.enabled===!1)return null;let c=x=>{if(typeof x!="string")return;let g=x.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(g)?g:void 0},l=x=>Array.isArray(x)&&x.length===3&&x.every(g=>typeof g=="number"&&Number.isFinite(g))?[t(x[0],-1e3,1e3,0),t(x[1],-1e3,1e3,0),t(x[2],-1e3,1e3,0)]:void 0,m=c(a.root),u=c(a.effector);if(!m||!u)return null;let M=c(a.mid),f=l(a.target)??c(a.target);if(!f)return null;let d=a.pole??a.poleTarget,A=l(d)??c(d),T=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||M?"two-bone":"fabrik";return{root:m,...M?{mid:M}:{},effector:u,target:f,...A?{pole:A}:{},solver:T,iterations:Math.round(t(a.iterations,1,32,8)),tolerance:t(a.tolerance,1e-5,.1,.001),weight:t(a.weight,0,1,1)}}let y=Object.freeze({solveTwoBone:r,solveFABRIK:i,parseIKTrait:h});return n&&typeof n=="object"&&(n.authorNamespace=n.authorNamespace||{},n.authorNamespace.IKSolver=y),{clampNum:t,parseIKTrait:h,quatFromUnitVectors:s,solveTwoBoneIK:r,solveFABRIK:i,IKSolver:y}}var G=ue(),Le=G.clampNum,$e=G.parseIKTrait,ne=G.quatFromUnitVectors,fe=G.solveTwoBoneIK,de=G.solveFABRIK,Ne=G.IKSolver;function le(e){let n=e?.transform??e?.modelMatrix;return n&&n.length>=16?[n[12]||0,n[13]||0,n[14]||0]:[0,0,0]}function He(e,n){let t=e?.transform??e?.modelMatrix;!t||t.length<16||(t[12]=n[0],t[13]=n[1],t[14]=n[2])}function qe(e,n,t,s,r){let i=Le(r,0,1,1),h=n[0]+(t[0]-n[0])*i,y=n[1]+(t[1]-n[1])*i,o=n[2]+(t[2]-n[2])*i,a=h-e[0],c=y-e[1],l=o-e[2],m=Math.hypot(a,c,l);if(m>1e-6&&s>1e-6){let A=s/m;return[e[0]+a*A,e[1]+c*A,e[2]+l*A]}let u=t[0]-e[0],M=t[1]-e[1],f=t[2]-e[2],d=Math.hypot(u,M,f);if(d>1e-6&&s>1e-6){let A=s/d;return[e[0]+u*A,e[1]+M*A,e[2]+f*A]}return[h,y,o]}function Ye(e,n){let t=e?.modelRootMatrix;if(!t||t.length!==16)return n;let s=new Float32Array(16);return ke(s,t instanceof Float32Array?t:Float32Array.from(t))?[s[0]*n[0]+s[4]*n[1]+s[8]*n[2]+s[12],s[1]*n[0]+s[5]*n[1]+s[9]*n[2]+s[13],s[2]*n[0]+s[6]*n[1]+s[10]*n[2]+s[14]]:n}function ae(e,n){e.__ikWarned||(e.__ikWarned=new Set);let t=e.__ikWarned;t.has(n)||(t.add(n),console.warn(`[three-live] ik: joint '${n}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function me(e,n,t){if(Array.isArray(e))return[e[0],e[1],e[2]];let s=n.get(e);if(s)return le(s);let r;if(e==="head"?r=t?.headPose?.position??t?.headPose??t?.cameraPosition:e==="hand-left"?r=t?.handPoses?.left?.position??t?.handPoses?.left??t?.hands?.left?.position??t?.hands?.left:e==="hand-right"&&(r=t?.handPoses?.right?.position??t?.handPoses?.right??t?.hands?.right?.position??t?.hands?.right),(Array.isArray(r)||ArrayBuffer.isView(r))&&r.length>=3){let i=r;return Ye(t,[i[0],i[1],i[2]])}return null}function ce(e,n){return[e[3]*n[0]+e[0]*n[3]+e[1]*n[2]-e[2]*n[1],e[3]*n[1]-e[0]*n[2]+e[1]*n[3]+e[2]*n[0],e[3]*n[2]+e[0]*n[1]-e[1]*n[0]+e[2]*n[3],e[3]*n[3]-e[0]*n[0]-e[1]*n[1]-e[2]*n[2]]}function Ze(e){return[-e[0],-e[1],-e[2],e[3]]}function he(e){let n=Math.hypot(e[0],e[1],e[2],e[3]);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n,e[3]/n]:[0,0,0,1]}function en(e,n){if(n>=1)return e;if(n<=0)return[0,0,0,1];let[t,s,r,i]=e;i<0&&(t=-t,s=-s,r=-r,i=-i);let h=Math.acos(Math.min(1,i)),y=Math.sin(h);if(y<1e-9)return[0,0,0,1];let o=Math.sin(h*n)/y;return he([t*o,s*o,r*o,Math.cos(h*n)])}function nn(e){let n=Math.hypot(e[0],e[1],e[2])||1,t=Math.hypot(e[4],e[5],e[6])||1,s=Math.hypot(e[8],e[9],e[10])||1,r=e[0]/n,i=e[1]/n,h=e[2]/n,y=e[4]/t,o=e[5]/t,a=e[6]/t,c=e[8]/s,l=e[9]/s,m=e[10]/s,u=r+o+m,M;if(u>0){let f=Math.sqrt(u+1)*2;M=[(a-l)/f,(c-h)/f,(i-y)/f,.25*f]}else if(r>o&&r>m){let f=Math.sqrt(1+r-o-m)*2;M=[.25*f,(y+i)/f,(c+h)/f,(a-l)/f]}else if(o>m){let f=Math.sqrt(1+o-r-m)*2;M=[(y+i)/f,.25*f,(l+a)/f,(c-h)/f]}else{let f=Math.sqrt(1+m-r-o)*2;M=[(c+h)/f,(l+a)/f,.25*f,(i-y)/f]}return he(M)}function tn(e,n,t){let[s,r,i,h]=t,y=1-2*(r*r+i*i),o=2*(s*r-i*h),a=2*(s*i+r*h),c=2*(s*r+i*h),l=1-2*(s*s+i*i),m=2*(r*i-s*h),u=2*(s*i-r*h),M=2*(r*i+s*h),f=1-2*(s*s+r*r);for(let d=0;d<3;d++){let A=n[d*4],T=n[d*4+1],x=n[d*4+2];e[d*4]=y*A+o*T+a*x,e[d*4+1]=c*A+l*T+m*x,e[d*4+2]=u*A+M*T+f*x}}function ee(e,n){let t=n[0]-e[0],s=n[1]-e[1],r=n[2]-e[2],i=Math.hypot(t,s,r);return i>1e-9?[t/i,s/i,r/i]:null}function Be(e){e?.normalMatrix&&e?.transform&&Z(e.normalMatrix,e.transform)}var Ee=new WeakMap;function rn(e){let n=Ee.get(e);return n||(n=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((t,s)=>{for(let r of Array.isArray(t?.children)?t.children:[])typeof r=="number"&&r>=0&&r<n.length&&(n[r]=s)}),Ee.set(e,n)),n}function on(e,n,t){let s=e?.gltf,r=s?.nodes;if(!Array.isArray(r)||r.length===0)return!1;let i=new Map;r.forEach((p,b)=>{typeof p?.name=="string"&&p.name&&!i.has(p.name)&&i.set(p.name,b)});let y=(n.mid?[n.root,n.mid,n.effector]:[n.root,n.effector]).map(p=>i.get(p));if(y.some(p=>p===void 0))return!1;let o=y,a=rn(s);for(let p=1;p<o.length;p++){let b=a[o[p]],I=0;for(;b>=0&&b!==o[p-1]&&I++<256;)b=a[b];if(b!==o[p-1])return!1}let c=o[0],l=e.initialNodeTransforms,m=new Map,u=[],M=[c];for(;M.length&&u.length<4096;){let p=M.pop();if(m.has(p))continue;let b=l?.[p],I=r[p];m.set(p,{t:b?[b.t[0],b.t[1],b.t[2]]:I?.translation?[...I.translation]:[0,0,0],r:b?[b.r[0],b.r[1],b.r[2],b.r[3]]:I?.rotation?[...I.rotation]:[0,0,0,1],s:b?[b.s[0],b.s[1],b.s[2]]:I?.scale?[...I.scale]:[1,1,1]}),u.push(p);for(let V of Array.isArray(I?.children)?I.children:[])typeof V=="number"&&M.push(V)}let f=a[c],d=f>=0&&e.worldMatrices?.[f]?.length===16?Float32Array.from(e.worldMatrices[f]):N(),A=new Map,T=()=>{let p=(b,I)=>{let V=m.get(b);if(!V)return;let w=N();J(w,V.r,V.t,V.s);let S=N();ie(S,I,w),A.set(b,S);for(let E of Array.isArray(r[b]?.children)?r[b].children:[])typeof E=="number"&&p(E,S)};p(c,d)},x=p=>{let b=A.get(p);return[b[12],b[13],b[14]]};T();let g=o.map(x),F=p=>{if(typeof p=="string"&&!t.has(p)){let b=i.get(p),I=b!==void 0?A.get(b)??e.worldMatrices?.[b]:void 0;if(I&&I.length===16)return[I[12],I[13],I[14]]}return me(p,t,e)},R=F(n.target);if(!R)return!0;let k=n.pole?F(n.pole)??void 0:void 0,v=Ce(g,n,R,k),_=Le(n.weight,0,1,1);for(let p=0;p<o.length-1;p++){let b=ee(x(o[p]),x(o[p+1])),I=ee(v[p],v[p+1]);if(!b||!I)continue;let V=en(ne(b,I),_),w=o[p],S=a[w],E=S===f||S<0?d:A.get(S)??d,B=nn(E),C=m.get(w);C.r=he(ce(Ze(B),ce(V,ce(B,C.r)))),T()}if(Array.isArray(e.worldMatrices))for(let[p,b]of A)e.worldMatrices[p]?.set&&e.worldMatrices[p].set(b);for(let p of e.meshes??[]){let b=A.get(p?.nodeIndex);b&&p.transform?.set&&(p.transform.set(b),Be(p))}return!0}function Ce(e,n,t,s){if(n.solver==="two-bone"&&e.length===3){let r=fe(e[0],e[1],e[2],t,s);return[e[0],r.midPos,r.effectorPos]}return de(e,t,n.iterations,n.tolerance).positions}function sn(e,n,t){let s=e.__ikRestOffsets,r=e.__ikRestMats;if(!(!s||!r))for(let i=0;i<n.length-1;i++){let h=n[i]?.transform??n[i]?.modelMatrix,y=r[i],o=ee([0,0,0],s[i]),a=ee(t[i],t[i+1]);!h||h.length<16||!y||y.length<16||!o||!a||(tn(h,y,ne(o,a)),Be(n[i]))}}var ye={name:"ik",onRegister(){let e=Q();Se(ue),ue(e.threeNamespace,e)},onUpdate(e){let n=e?.meshes;if(!Array.isArray(n)||n.length===0)return;let t=null;for(let s of n){let r=s?.userData?.xr?.ik??s?.extras?.xr?.ik??s?.extensions?.ANDROID_xr_scenecore?.ik;if(!r)continue;let i=$e(r);if(!i||i.weight<=0)continue;if(!t){t=new Map;for(let g of n)g&&typeof g.name=="string"&&g.name&&t.set(g.name,g)}if(on(e,i,t))continue;let h=t.get(i.root),y=t.get(i.effector),o=i.mid?t.get(i.mid):void 0;if(h||ae(s,i.root),y||ae(s,i.effector),i.mid&&!o&&ae(s,i.mid),!h||!y)continue;let a=me(i.target,t,e);if(!a)continue;let c=i.pole?me(i.pole,t,e)??void 0:void 0,l=o?[h,o,y]:[h,y],m=l.map(g=>g.name||"").join(">");if(!s.__ikRestOffsets||s.__ikRestKey!==m){let g=l.map(le),F=[];for(let R=0;R<g.length-1;R++)F.push([g[R+1][0]-g[R][0],g[R+1][1]-g[R][1],g[R+1][2]-g[R][2]]);s.__ikRestOffsets=F,s.__ikRestKey=m,s.__ikRestMats=l.map(R=>Array.from(R.transform??R.modelMatrix??[]))}let u=s.__ikRestOffsets,f=[le(h)],d=[];for(let g=0;g<u.length;g++){let F=f[g],R=u[g];f.push([F[0]+R[0],F[1]+R[1],F[2]+R[2]]),d.push(Math.hypot(R[0],R[1],R[2]))}let A=Ce(f,i,a,c),T=f[0],x=[f[0]];for(let g=1;g<l.length;g++){let F=u[g-1],R=[T[0]+F[0],T[1]+F[1],T[2]+F[2]],k=[T[0]+(A[g][0]-A[g-1][0]),T[1]+(A[g][1]-A[g-1][1]),T[2]+(A[g][2]-A[g-1][2])],v=qe(T,R,k,d[g-1],i.weight);He(l[g],v),T=v,x.push(v)}sn(s,l,x)}}};var an={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function W(e,n,t,s){if(!t||t.bufferView===void 0)return null;let r=e.bufferViews?.[t.bufferView];if(!r)return null;let i=Number(t.count??0);if(!Number.isInteger(i)||i<=0)return null;let h=t.componentType??5126,y=an[h];if(!y)throw new RangeError(`glTF accessor has unsupported componentType ${h}`);let o=y*s,a=r.byteStride&&r.byteStride>0?r.byteStride:o,c=(r.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(c)||c<0||a<o||c+(i-1)*a+o>n.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${n.byteLength} bytes)`);if(h===5126&&a===o&&c%4===0)return new Float32Array(n,c,i*s);let l=new DataView(n),m=t.normalized===!0,u=new Float32Array(i*s);for(let M=0;M<i;M++){let f=c+M*a;for(let d=0;d<s;d++){let A=f+d*y,T;switch(h){case 5126:T=l.getFloat32(A,!0);break;case 5120:T=l.getInt8(A),m&&(T=Math.max(T/127,-1));break;case 5121:T=l.getUint8(A),m&&(T/=255);break;case 5122:T=l.getInt16(A,!0),m&&(T=Math.max(T/32767,-1));break;case 5123:T=l.getUint16(A,!0),m&&(T/=65535);break;default:T=l.getUint32(A,!0),m&&(T/=4294967295)}u[M*s+d]=T}}return u}function Pe(e,n,t){return n%4===0?new Float32Array(e,n,t):new Float32Array(e.slice(n,n+t*4))}function Oe(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=t[0],a=t[1],c=t[2],l=t[3],m=r*o+i*a+h*c+y*l;if(m<0&&(o=-o,a=-a,c=-c,l=-l,m=-m),Math.abs(m)>=1)return e[0]=r,e[1]=i,e[2]=h,e[3]=y,e;let u=Math.acos(m),M=Math.sqrt(1-m*m);if(Math.abs(M)<.001)return e[0]=.5*(r+o),e[1]=.5*(i+a),e[2]=.5*(h+c),e[3]=.5*(y+l),e;let f=Math.sin((1-s)*u)/M,d=Math.sin(s*u)/M;return e[0]=r*f+o*d,e[1]=i*f+a*d,e[2]=h*f+c*d,e[3]=y*f+l*d,e}function Ke(e,n,t,s){return e[0]=n[0]+s*(t[0]-n[0]),e[1]=n[1]+s*(t[1]-n[1]),e[2]=n[2]+s*(t[2]-n[2]),e}function be(e,n){if(!Array.isArray(e?.animations))return[];let t=[];for(let s=0;s<e.animations.length;s++){let r=e.animations[s],i=r.name||`Animation_${s}`,h=[],y=0;if(Array.isArray(r.channels)&&Array.isArray(r.samplers))for(let o of r.channels){if(!o.target||o.target.node===void 0||!o.target.path)continue;let a=r.samplers[o.sampler];if(!a)continue;let c=e.accessors?.[a.input],l=e.accessors?.[a.output];if(!c||!l)continue;let m=e.bufferViews?.[c.bufferView],u=e.bufferViews?.[l.bufferView];if(!m||!u)continue;let M=(m.byteOffset||0)+(c.byteOffset||0),f=(u.byteOffset||0)+(l.byteOffset||0),d=W(e,n,c,1)??Pe(n,M,c.count);d.length>0&&d[d.length-1]>y&&(y=d[d.length-1]);let A=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(l.count/Math.max(1,c.count))):3,T=o.target.path==="weights"?1:A,x=W(e,n,l,T)??Pe(n,f,l.count*T),g=a.interpolation==="STEP"?"STEP":"LINEAR";h.push({nodeIndex:o.target.node,path:o.target.path,times:d,values:x,interpolation:g})}h.length>0&&t.push({name:i,duration:y,channels:h})}return t}function U(e,n,t){let{times:s,values:r,path:i,interpolation:h}=e,y=s.length;if(y===0)return;let o=i==="rotation"?4:i==="weights"?Math.max(1,Math.round(r.length/y)):3;if(n<=s[0]){for(let T=0;T<o;T++)t[T]=r[T];return}if(n>=s[y-1]){let T=(y-1)*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let a=0,c=y-1;for(;a<=c;){let T=a+c>>1;s[T]<=n?a=T+1:c=T-1}let l=Math.max(0,c),m=Math.min(y-1,l+1);if(h==="STEP"||l===m){let T=l*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let u=s[l],M=s[m],f=(n-u)/Math.max(1e-5,M-u),d=l*o,A=m*o;if(i==="rotation"){let T=[r[d],r[d+1],r[d+2],r[d+3]],x=[r[A],r[A+1],r[A+2],r[A+3]];Oe(t,T,x,f)}else for(let T=0;T<o;T++)t[T]=r[d+T]+f*(r[A+T]-r[d+T])}var te=new WeakMap;function ge(e,n,t=.3){if(!e?.animations)return;let s=e.animations.find(y=>y.name===n);if(!s)return;let r=te.get(e);r||(r=[],e.currentClip&&r.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),te.set(e,r));let i=t>0?1/t:1e3;for(let y of r)y.clip.name!==n&&(y.fadeSpeed=-i);let h=r.find(y=>y.clip.name===n);h?h.fadeSpeed=i:r.push({clip:s,time:0,weight:t>0?0:1,fadeSpeed:i}),e.currentClip=s,e.isPlayingAnimation=!0}function pe(e,n){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let t=te.get(e);if(!t||t.length===0){if(!e.currentClip)return;t=[{clip:e.currentClip,time:n,weight:1,fadeSpeed:0}]}let s=e.gltf.nodes.length,r=[];for(let l=0;l<s;l++){let m=e.initialNodeTransforms[l];m?r.push({t:[m.t[0],m.t[1],m.t[2]],r:[m.r[0],m.r[1],m.r[2],m.r[3]],s:[m.s[0],m.s[1],m.s[2]]}):r.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let i=[0,0,0],h=[0,0,0,1],y=[1,1,1],o=new Float32Array(64);for(let l of t){let m=Math.max(0,Math.min(1,l.weight));if(!(m<=1e-4))for(let u of l.clip.channels){if(u.nodeIndex<0||u.nodeIndex>=s)continue;let M=r[u.nodeIndex];if(u.path==="translation")U(u,l.time,i),Ke(M.t,M.t,i,m);else if(u.path==="rotation")U(u,l.time,h),Oe(M.r,M.r,h,m);else if(u.path==="scale")U(u,l.time,y),Ke(M.s,M.s,y,m);else if(u.path==="weights"&&(U(u,l.time,o),e.meshes)){for(let f of e.meshes)if(f.nodeIndex===u.nodeIndex){for(let d of f.primitives)if(d.pluginData?.morph?.weights){let A=d.pluginData.morph.weights,T=d.pluginData.morph.numTargets||A.length;for(let x=0;x<T;x++)A[x]=A[x]*(1-m)+o[x]*m}}}}}let a=[];for(let l=0;l<s;l++){let m=N(),{t:u,r:M,s:f}=r[l];J(m,M,u,f),a.push(m)}let c=_e(e.gltf,a);e.worldMatrices=c;for(let l of e.meshes)l.nodeIndex>=0&&l.nodeIndex<c.length&&(l.transform.set(c[l.nodeIndex]),Z(l.normalMatrix,l.transform))}var Ae={name:"keyframes",evaluateAnimation:pe,crossFadeTo:ge,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=be(e.gltf,e.bin))},onUpdate(e,n){if(!e.isPlayingAnimation)return;let t=te.get(e);if(t&&t.length>0){for(let s=t.length-1;s>=0;s--){let r=t[s];if(r.time+=n,r.clip.duration>0&&(r.time%=r.clip.duration),r.fadeSpeed!==0)if(r.weight+=r.fadeSpeed*n,r.weight<=0){t.splice(s,1);continue}else r.weight>=1&&(r.weight=1,r.fadeSpeed=0)}t.length>0&&(e.animationTime=t[t.length-1].time),pe(e,e.animationTime)}else e.currentClip&&(e.animationTime+=n,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),pe(e,e.animationTime))}};var $=64;function We(e,n,t){if(!(!e?.meshes||n<0||n>=$))for(let s of e.meshes)for(let r of s.primitives){let i=r.pluginData?.morph;i?.weights&&(i.weights[n]=t)}}var Te={name:"morph",onResolveShader(e,n,t,s){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let r=t.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
16
+ */var ThreeLiveAnimation=(()=>{var tt=Object.defineProperty,Bt=Object.getOwnPropertyDescriptor,Kt=Object.getOwnPropertyNames,Ut=Object.prototype.hasOwnProperty,Jt=(t,e)=>{for(var r in e)tt(t,r,{get:e[r],enumerable:!0})},$t=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Kt(e))!Ut.call(t,i)&&i!==r&&tt(t,i,{get:()=>e[i],enumerable:!(o=Bt(e,i))||o.enumerable});return t},jt=t=>$t(tt({},"__esModule",{value:!0}),t),dt={};Jt(dt,{IKSolver:()=>Gt,crossFadeTo:()=>_t,ikPlugin:()=>xt,keyframeAnimationPlugin:()=>Ft,morphPlugin:()=>St,parseAnimations:()=>kt,quatFromUnitVectors:()=>it,sampleChannel:()=>U,setMorphTargetWeight:()=>ae,skinningPlugin:()=>Vt,solveFABRIK:()=>bt,solveTwoBoneIK:()=>Mt});var q="__THREE_LIVE_REGISTRY__";function z(){let t=typeof globalThis<"u"?globalThis:{};if(!t[q]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,q,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[q]=e}}return t[q]}var fe=z().plugins;function Ct(t){let e=z();e.workerExtensionInstallers||(e.workerExtensionInstallers=[]),e.workerExtensionInstallers.includes(t)||e.workerExtensionInstallers.push(t)}function G(t){let e=z().plugins;e.some(r=>r.name===t.name)||e.push(t),t.onRegister?.()}function E(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function pt(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 et(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 gt(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 Lt(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 qt(t,e){let r=Array.isArray(t?.nodes)?t.nodes.length:0,o=[];for(let l=0;l<r;l++)o.push(E());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=E();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];et(M,b,d,v)}let c=o[l];if(u?pt(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 rt(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)),N=h?h[0]-n[0]:f,j=h?h[1]-n[1]:M,C=h?h[2]-n[2]:c,K=N*w[0]+j*w[1]+C*w[2],W=N-w[0]*K,D=j-w[1]*K,Z=C-w[2]*K,L=Math.hypot(W,D,Z);if(L<=1e-6){let Dt=Math.abs(w[1])<.99?0:1,Et=Math.abs(w[1])<.99?1:0,Wt=0;W=w[1]*Wt-w[2]*Et,D=w[2]*Dt-w[0]*Wt,Z=w[0]*Et-w[1]*Dt,L=Math.hypot(W,D,Z)||1}let mt=[W/L,D/L,Z/L],O=[n[0]+w[0]*(d*S)+mt[0]*(d*R),n[1]+w[1]*(d*S)+mt[1]*(d*R),n[2]+w[2]*(d*S)+mt[2]*(d*R)],ct=[n[0]+w[0]*P,n[1]+w[1]*P,n[2]+w[2]*P],Rt=ct[0]-O[0],Ot=ct[1]-O[1],Nt=ct[2]-O[2],Q=Math.hypot(Rt,Ot,Nt),X=Q>1e-6?[Rt/Q,Ot/Q,Nt/Q]:w,le=[O[0]+X[0]*A,O[1]+X[1]*A,O[2]+X[2]*A],se=[(O[0]-n[0])/d,(O[1]-n[1])/d,(O[2]-n[2])/d];return{rootPos:[n[0],n[1],n[2]],midPos:O,effectorPos:le,rootRotation:o(x,se),midRotation:o(k,X)}}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,N)=>{let j=P[0]-I[0],C=P[1]-I[1],K=P[2]-I[2],W=Math.hypot(j,C,K);if(W>1e-6){let D=S/W;return[I[0]+j*D,I[1]+C*D,I[2]+K*D]}return[I[0]+R[0]*S*N,I[1]+R[1]*S*N,I[2]+R[2]*S*N]};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 B=rt(),yt=B.clampNum,zt=B.parseIKTrait,it=B.quatFromUnitVectors,Mt=B.solveTwoBoneIK,bt=B.solveFABRIK,Gt=B.IKSolver;function ot(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 Ht(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 Yt(t,e,r,o,i){let a=yt(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 Zt(t,e){let r=t?.modelRootMatrix;if(!r||r.length!==16)return e;let o=new Float32Array(16);return Lt(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 nt(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 at(t,e,r){if(Array.isArray(t))return[t[0],t[1],t[2]];let o=e.get(t);if(o)return ot(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 Zt(r,[a[0],a[1],a[2]])}return null}function lt(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 Qt(t){return[-t[0],-t[1],-t[2],t[3]]}function st(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 Xt(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 st([r*n,o*n,i*n,Math.cos(g*e)])}function te(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 st(M)}function ee(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 H(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 vt(t){t?.normalMatrix&&t?.transform&&gt(t.normalMatrix,t.transform)}var wt=new WeakMap;function re(t){let e=wt.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)}),wt.set(t,e)),e}function ie(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=re(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]):E(),d=new Map,b=()=>{let T=(y,w)=>{let _=u.get(y);if(!_)return;let I=E();et(I,_.r,_.t,_.s);let P=E();pt(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 at(T,r,t)},x=A(e.target);if(!x)return!0;let k=e.pole?A(e.pole)??void 0:void 0,F=At(m,e,x,k),V=yt(e.weight,0,1,1);for(let T=0;T<p.length-1;T++){let y=H(v(p[T]),v(p[T+1])),w=H(F[T],F[T+1]);if(!y||!w)continue;let _=Xt(it(y,w),V),I=p[T],P=n[I],S=P===M||P<0?c:d.get(P)??c,R=te(S),N=u.get(I);N.r=st(lt(Qt(R),lt(_,lt(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),vt(T))}return!0}function At(t,e,r,o){if(e.solver==="two-bone"&&t.length===3){let i=Mt(t[0],t[1],t[2],r,o);return[t[0],i.midPos,i.effectorPos]}return bt(t,r,e.iterations,e.tolerance).positions}function oe(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=H([0,0,0],o[a]),s=H(r[a],r[a+1]);!g||g.length<16||!p||p.length<16||!n||!s||(ee(g,p,it(n,s)),vt(e[a]))}}var xt={name:"ik",onRegister(){let t=z();Ct(rt),rt(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=zt(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(ie(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||nt(o,a.root),p||nt(o,a.effector),a.mid&&!n&&nt(o,a.mid),!g||!p)continue;let s=at(a.target,r,t);if(!s)continue;let l=a.pole?at(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(ot),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=[ot(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=At(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=Yt(b,x,k,c[m-1],a.weight);Ht(u[m],F),b=F,v.push(F)}oe(o,u,v)}}},ne={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Y(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=ne[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 Tt(t,e,r){return e%4===0?new Float32Array(t,e,r):new Float32Array(t.slice(e,e+r*4))}function Pt(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 It(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 kt(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=Y(t,e,l,1)??Tt(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=Y(t,e,u,v)??Tt(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]];Pt(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 J=new WeakMap;function _t(t,e,r=.3){if(!t?.animations)return;let o=t.animations.find(p=>p.name===e);if(!o)return;let i=J.get(t);i||(i=[],t.currentClip&&i.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),J.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 ft(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let r=J.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),It(M.t,M.t,a,h);else if(f.path==="rotation")U(f,u.time,g),Pt(M.r,M.r,g,h);else if(f.path==="scale")U(f,u.time,p),It(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=E(),{t:f,r:M,s:c}=i[u];et(h,M,f,c),s.push(h)}let l=qt(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]),gt(u.normalMatrix,u.transform))}var ut=t=>{J.delete(t)},Ft={name:"keyframes",evaluateAnimation:ft,crossFadeTo:_t,onParseGLB(t){!t.animations&&t.gltf?.animations&&(t.animations=kt(t.gltf,t.bin))},onLoadModel:ut,onClearScene:ut,onDestroy:(t,e)=>ut(e),onUpdate(t,e){if(!t.isPlayingAnimation)return;let r=J.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),ft(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),ft(t,t.animationTime))}},$=64;function ae(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 St={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;
18
17
  uniform sampler2D uMorphDeltasTex;
19
18
  uniform float uMorphWeights[${$}];
20
- uniform int uNumMorphTargets;`);return r=r.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
19
+ uniform int uNumMorphTargets;`);return i=i.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
21
20
  for (int m = 0; m < ${$}; m++) {
22
21
  if (m >= uNumMorphTargets) break;
23
22
  float w = uMorphWeights[m];
@@ -25,12 +24,12 @@ for (int m = 0; m < ${$}; m++) {
25
24
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
26
25
  }
27
26
  }
28
- vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.targets;if(!Array.isArray(i)||i.length===0)return null;let h=t.attributes?.POSITION,y=s?.accessors?.[h];if(!y)return null;let o=y.count,a=Math.min(i.length,$),c=new Float32Array(o*a*4);for(let u=0;u<a;u++){let M=i[u].POSITION;if(M===void 0)continue;let f=s.accessors?.[M],d=s.bufferViews?.[f?.bufferView];if(!f||!d)continue;let A=W(s,r,f,3);if(!A||A.length<o*3)continue;let T=u*o*4;for(let x=0;x<o;x++)c[T+x*4]=A[x*3],c[T+x*4+1]=A[x*3+1],c[T+x*4+2]=A[x*3+2],c[T+x*4+3]=0}let l=e.createTexture();e.bindTexture(3553,l),e.texImage2D(3553,0,34836,o,a,0,6408,5126,c),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array($);return{hasMorph:!0,morphTex:l,numTargets:a,vertexCount:o,weights:m}},onBeforeDrawPrimitive(e,n,t,s,r,i){let h=t.pluginData?.morph;if(!h?.hasMorph||!h.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,h.morphTex);let y=e.getUniformLocation(n,"uMorphDeltasTex");y&&e.uniform1i(y,5);let o=e.getUniformLocation(n,"uNumMorphTargets");o&&e.uniform1i(o,h.numTargets);let a=e.getUniformLocation(n,"uMorphWeights[0]");a&&e.uniform1fv(a,h.weights)}};var xe=64,Me={name:"skinning",onResolveShader(e,n,t,s){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let r=t.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,p=o?.accessors?.[g];if(!p)return null;let n=p.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],d=o.bufferViews?.[c?.bufferView];if(!c||!d)continue;let b=Y(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($);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)}},ht=64,Vt={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;
29
28
  layout(location=4) in uvec4 aJoints;
30
29
  layout(location=5) in vec4 aWeights;
31
- uniform mat4 uJointMatrix[${xe}];`),i=r.includes("morphedPos")?"morphedPos":"aPosition";return r=r.replace(`vec4 world=uModel*vec4(${i},1.0);`,`mat4 skinMatrix =
30
+ uniform mat4 uJointMatrix[${ht}];`),a=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${a},1.0);`,`mat4 skinMatrix =
32
31
  aWeights.x * uJointMatrix[int(aJoints.x)] +
33
32
  aWeights.y * uJointMatrix[int(aJoints.y)] +
34
33
  aWeights.z * uJointMatrix[int(aJoints.z)] +
35
34
  aWeights.w * uJointMatrix[int(aJoints.w)];
36
- vec4 world=uModel*(skinMatrix*vec4(${i},1.0));`).replace(`gl_Position=uMVP*vec4(${i},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${i},1.0));`),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.attributes;if(!i||i.JOINTS_0===void 0||i.WEIGHTS_0===void 0)return null;let h=s.accessors[i.JOINTS_0],y=s.accessors[i.WEIGHTS_0];if(!h||!y)return null;let o=s.bufferViews[h.bufferView],a=s.bufferViews[y.bufferView];if(!o||!a)return null;let c=(o.byteOffset||0)+(h.byteOffset||0),l=(a.byteOffset||0)+(y.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let u=h.componentType===5121?5121:5123,M=u===5121?new Uint8Array(r,c,h.count*4):new Uint16Array(r,c,h.count*4);e.bufferData(34962,M,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,u,0,0);let f=e.createBuffer();e.bindBuffer(34962,f);let d=W(s,r,y,4)??new Float32Array(r,l,y.count*4);return e.bufferData(34962,d,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,f]}},onBeforeDrawPrimitive(e,n,t,s,r,i){if(!t.pluginData?.skinning?.hasSkin)return;let h=i?.nodes?.[s.nodeIndex]?.skin;if(h===void 0||!i.skins||!i.skins[h])return;let o=i.skins[h].joints||[],a=new Float32Array(xe*16);for(let l=0;l<o.length&&l<xe;l++){let m=o[l],u=r[m]||N();a.subarray(l*16,(l+1)*16).set(u)}let c=e.getUniformLocation(n,"uJointMatrix[0]");c&&e.uniformMatrix4fv(c,!1,a)}};X(Te);X(Ae);X(Me);X(ye);return Je(cn);})();
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=Y(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(ht*16);for(let l=0;l<p.length&&l<ht;l++){let u=p[l],h=i[u]||E();n.subarray(l*16,(l+1)*16).set(h)}let s=t.getUniformLocation(e,"uJointMatrix[0]");s&&t.uniformMatrix4fv(s,!1,n)}};return G(St),G(Ft),G(Vt),G(xt),jt(dt)})();