three-live 1.2.4 → 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 +2 -2
  2. package/dist/index.d.ts +58 -0
  3. package/dist/three-author-engine.js +89 -63
  4. package/dist/three-author.cjs +88 -62
  5. package/dist/three-author.d.ts +58 -0
  6. package/dist/three-author.js +87 -61
  7. package/dist/three-convert.cjs +81 -59
  8. package/dist/three-convert.d.ts +58 -0
  9. package/dist/three-convert.js +80 -58
  10. package/dist/three-live-animation.cjs +8 -9
  11. package/dist/three-live-animation.d.ts +58 -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 +58 -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 +20 -21
  20. package/dist/three-live-element.d.ts +58 -0
  21. package/dist/three-live-element.js +19 -20
  22. package/dist/three-live-full.cjs +113 -87
  23. package/dist/three-live-full.js +110 -84
  24. package/dist/three-live-full.min.js +113 -87
  25. package/dist/three-live-studio.cjs +19 -20
  26. package/dist/three-live-studio.d.ts +58 -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 +20 -21
  30. package/dist/three-live-viewer.d.ts +58 -0
  31. package/dist/three-live-viewer.js +19 -20
  32. package/dist/three-live-viewer.min.js +20 -21
  33. package/dist/three-live.cjs +90 -64
  34. package/dist/three-live.js +89 -63
  35. package/dist/three-live.min.js +89 -63
  36. package/dist/three-view.cjs +18 -19
  37. package/dist/three-view.d.ts +58 -0
  38. package/dist/three-view.js +19 -20
  39. package/dist/three-xr.cjs +81 -59
  40. package/dist/three-xr.d.ts +58 -0
  41. package/dist/three-xr.js +80 -58
  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 sn=Object.defineProperty;var Dn=Object.getOwnPropertyDescriptor;var jn=Object.getOwnPropertyNames;var Qn=Object.prototype.hasOwnProperty;var Xn=(n,e)=>{for(var t in e)sn(n,t,{get:e[t],enumerable:!0})},Jn=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of jn(e))!Qn.call(n,r)&&r!==t&&sn(n,r,{get:()=>e[r],enumerable:!(s=Dn(e,r))||s.enumerable});return n};var $n=n=>Jn(sn({},"__esModule",{value:!0}),n);var ce={};Xn(ce,{IKSolver:()=>Bn,crossFadeTo:()=>An,ikPlugin:()=>pn,keyframeAnimationPlugin:()=>Tn,morphPlugin:()=>xn,parseAnimations:()=>gn,quatFromUnitVectors:()=>en,sampleChannel:()=>U,setMorphTargetWeight:()=>zn,skinningPlugin:()=>wn,solveFABRIK:()=>hn,solveTwoBoneIK:()=>dn});module.exports=$n(ce);var Y="__THREE_LIVE_REGISTRY__";function Q(){let n=typeof globalThis<"u"?globalThis:{};if(!n[Y]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,Y,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[Y]=e}}return n[Y]}var le=Q().plugins;function _n(n){let e=Q();e.workerExtensionInstallers||(e.workerExtensionInstallers=[]),e.workerExtensionInstallers.includes(n)||e.workerExtensionInstallers.push(n)}function X(n){let e=Q().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function N(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function an(n,e,t){let s=e[0],r=e[1],i=e[2],h=e[3],y=e[4],o=e[5],a=e[6],c=e[7],l=e[8],m=e[9],u=e[10],b=e[11],d=e[12],f=e[13],T=e[14],x=e[15],M=t[0],A=t[1],F=t[2],R=t[3];return n[0]=M*s+A*y+F*l+R*d,n[1]=M*r+A*o+F*m+R*f,n[2]=M*i+A*a+F*u+R*T,n[3]=M*h+A*c+F*b+R*x,M=t[4],A=t[5],F=t[6],R=t[7],n[4]=M*s+A*y+F*l+R*d,n[5]=M*r+A*o+F*m+R*f,n[6]=M*i+A*a+F*u+R*T,n[7]=M*h+A*c+F*b+R*x,M=t[8],A=t[9],F=t[10],R=t[11],n[8]=M*s+A*y+F*l+R*d,n[9]=M*r+A*o+F*m+R*f,n[10]=M*i+A*a+F*u+R*T,n[11]=M*h+A*c+F*b+R*x,M=t[12],A=t[13],F=t[14],R=t[15],n[12]=M*s+A*y+F*l+R*d,n[13]=M*r+A*o+F*m+R*f,n[14]=M*i+A*a+F*u+R*T,n[15]=M*h+A*c+F*b+R*x,n}function J(n,e,t,s){let r=e[0],i=e[1],h=e[2],y=e[3],o=r+r,a=i+i,c=h+h,l=r*o,m=r*a,u=r*c,b=i*a,d=i*c,f=h*c,T=y*o,x=y*a,M=y*c,A=s[0],F=s[1],R=s[2];return n[0]=(1-(b+f))*A,n[1]=(m+M)*A,n[2]=(u-x)*A,n[3]=0,n[4]=(m-M)*F,n[5]=(1-(l+f))*F,n[6]=(d+T)*F,n[7]=0,n[8]=(u+x)*R,n[9]=(d-T)*R,n[10]=(1-(l+b))*R,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function Z(n,e){let t=e[0],s=e[1],r=e[2],i=e[4],h=e[5],y=e[6],o=e[8],a=e[9],c=e[10],l=c*h-y*a,m=-c*i+y*o,u=a*i-h*o,b=t*l+s*m+r*u;return b&&(b=1/b,n[0]=l*b,n[1]=m*b,n[2]=u*b,n[3]=(-c*s+r*a)*b,n[4]=(c*t-r*o)*b,n[5]=(-a*t+s*o)*b,n[6]=(y*s-r*h)*b,n[7]=(-y*t+r*i)*b,n[8]=(h*t-s*i)*b),n}function kn(n,e){let t=e[0],s=e[1],r=e[2],i=e[3],h=e[4],y=e[5],o=e[6],a=e[7],c=e[8],l=e[9],m=e[10],u=e[11],b=e[12],d=e[13],f=e[14],T=e[15],x=t*y-s*h,M=t*o-r*h,A=t*a-i*h,F=s*o-r*y,R=s*a-i*y,_=r*a-i*o,v=c*d-l*b,k=c*f-m*b,p=c*T-u*b,g=l*f-m*d,I=l*T-u*d,V=m*T-u*f,w=x*V-M*I+A*g+F*p-R*k+_*v;return w?(w=1/w,n[0]=(y*V-o*I+a*g)*w,n[1]=(r*I-s*V-i*g)*w,n[2]=(d*_-f*R+T*F)*w,n[3]=(m*R-l*_-u*F)*w,n[4]=(o*p-h*V-a*k)*w,n[5]=(t*V-r*p+i*k)*w,n[6]=(f*A-b*_-T*M)*w,n[7]=(c*_-m*A+u*M)*w,n[8]=(h*I-y*p+a*v)*w,n[9]=(s*p-t*I-i*v)*w,n[10]=(b*R-d*A+T*x)*w,n[11]=(l*A-c*R-u*x)*w,n[12]=(y*k-h*g-o*v)*w,n[13]=(t*g-s*k+r*v)*w,n[14]=(d*M-b*F-f*x)*w,n[15]=(c*F-l*M+m*x)*w,n):null}function En(n,e){let t=Array.isArray(n?.nodes)?n.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 n.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=n.nodes[c];if(!u)return;let b=N();if(e&&e[c])b.set(e[c]);else if(u.matrix&&u.matrix.length===16)b.set(u.matrix);else{let f=u.translation||[0,0,0],T=u.rotation||[0,0,0,1],x=u.scale||[1,1,1];J(b,T,f,x)}let d=s[c];if(l?an(d,l,b):d.set(b),Array.isArray(u.children))for(let f of u.children)typeof f=="number"&&y(f,d,m+1)},o=[],a=n.scenes&&n.scenes[n.scene!==void 0?n.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 ln(n,e){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 T=Math.hypot(o[1],o[0])||1;return[-o[1]/T,o[0]/T,0,0]}let f=Math.hypot(o[2],o[1])||1;return[0,-o[2]/f,o[1]/f,0]}let m=o[1]*a[2]-o[2]*a[1],u=o[2]*a[0]-o[0]*a[2],b=o[0]*a[1]-o[1]*a[0],d=Math.hypot(m,u,b,l)||1;return[m/d,u/d,b/d,l/d]}function r(o,a,c,l,m){let u=a[0]-o[0],b=a[1]-o[1],d=a[2]-o[2],f=Math.hypot(u,b,d),T=c[0]-a[0],x=c[1]-a[1],M=c[2]-a[2],A=Math.hypot(T,x,M);if(f<1e-6||A<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/f,b/f,d/f],R=[T/A,x/A,M/A],_=l[0]-o[0],v=l[1]-o[1],k=l[2]-o[2],p=Math.hypot(_,v,k),g=p>1e-6?[_/p,v/p,k/p]:F,I=Math.abs(f-A)+1e-5,V=Math.max(I,f+A-1e-5),w=Math.max(I,Math.min(V,p>1e-6?p:I)),S=t((f*f+w*w-A*A)/(2*f*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]:b,D=m?m[2]-o[2]:d,z=B*g[0]+C*g[1]+D*g[2],K=B-g[0]*z,O=C-g[1]*z,P=D-g[2]*z,j=Math.hypot(K,O,P);if(j<=1e-6){let Vn=Math.abs(g[1])<.99?0:1,vn=Math.abs(g[1])<.99?1:0,Sn=0;K=g[1]*Sn-g[2]*vn,O=g[2]*Vn-g[0]*Sn,P=g[0]*vn-g[1]*Vn,j=Math.hypot(K,O,P)||1}let rn=[K/j,O/j,P/j],L=[o[0]+g[0]*(f*S)+rn[0]*(f*E),o[1]+g[1]*(f*S)+rn[1]*(f*E),o[2]+g[2]*(f*S)+rn[2]*(f*E)],on=[o[0]+g[0]*w,o[1]+g[1]*w,o[2]+g[2]*w],Rn=on[0]-L[0],Fn=on[1]-L[1],In=on[2]-L[2],H=Math.hypot(Rn,Fn,In),q=H>1e-6?[Rn/H,Fn/H,In/H]:g,Gn=[L[0]+q[0]*A,L[1]+q[1]*A,L[2]+q[2]*A],Un=[(L[0]-o[0])/f,(L[1]-o[1])/f,(L[2]-o[2])/f];return{rootPos:[o[0],o[1],o[2]],midPos:L,effectorPos:Gn,rootRotation:s(F,Un),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]]),b=[],d=[],f=0;for(let p=0;p<m-1;p++){let g=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(g,I,V);b.push(w),f+=w,d.push(w>1e-6?[g/w,I/w,V/w]:[0,1,0])}let T=[u[0][0],u[0][1],u[0][2]],x=Math.round(t(c,1,32,8)),M=t(l,1e-5,.1,.001),A=a[0]-T[0],F=a[1]-T[1],R=a[2]-T[2],_=Math.hypot(A,F,R),v=0;if(_>=f&&f>1e-6){let p=_>1e-6?[A/_,F/_,R/_]:d[0];u[0]=[T[0],T[1],T[2]];for(let g=0;g<m-1;g++){let I=b[g];u[g+1]=[u[g][0]+p[0]*I,u[g][1]+p[1]*I,u[g][2]+p[2]*I]}v=1}else for(let p=1;p<=x;p++){let g=u[m-1];if(Math.hypot(g[0]-a[0],g[1]-a[1],g[2]-a[2])<=M)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],b[w],d[w],-1);u[0]=[T[0],T[1],T[2]];for(let w=0;w<m-1;w++)u[w+1]=V(u[w],u[w+1],b[w],d[w],1)}let k=[];for(let p=0;p<m-1;p++){let g=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(g,I,V),S=w>1e-6?[g/w,I/w,V/w]:d[p];k.push(s(d[p],S))}return{positions:u,rotations:k,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=M=>{if(typeof M!="string")return;let A=M.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(A)?A:void 0},l=M=>Array.isArray(M)&&M.length===3&&M.every(A=>typeof A=="number"&&Number.isFinite(A))?[t(M[0],-1e3,1e3,0),t(M[1],-1e3,1e3,0),t(M[2],-1e3,1e3,0)]:void 0,m=c(a.root),u=c(a.effector);if(!m||!u)return null;let b=c(a.mid),d=l(a.target)??c(a.target);if(!d)return null;let f=a.pole??a.poleTarget,T=l(f)??c(f),x=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||b?"two-bone":"fabrik";return{root:m,...b?{mid:b}:{},effector:u,target:d,...T?{pole:T}:{},solver:x,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 e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=y),{clampNum:t,parseIKTrait:h,quatFromUnitVectors:s,solveTwoBoneIK:r,solveFABRIK:i,IKSolver:y}}var G=ln(),Nn=G.clampNum,Hn=G.parseIKTrait,en=G.quatFromUnitVectors,dn=G.solveTwoBoneIK,hn=G.solveFABRIK,Bn=G.IKSolver;function mn(n){let e=n?.transform??n?.modelMatrix;return e&&e.length>=16?[e[12]||0,e[13]||0,e[14]||0]:[0,0,0]}function qn(n,e){let t=n?.transform??n?.modelMatrix;!t||t.length<16||(t[12]=e[0],t[13]=e[1],t[14]=e[2])}function Yn(n,e,t,s,r){let i=Nn(r,0,1,1),h=e[0]+(t[0]-e[0])*i,y=e[1]+(t[1]-e[1])*i,o=e[2]+(t[2]-e[2])*i,a=h-n[0],c=y-n[1],l=o-n[2],m=Math.hypot(a,c,l);if(m>1e-6&&s>1e-6){let T=s/m;return[n[0]+a*T,n[1]+c*T,n[2]+l*T]}let u=t[0]-n[0],b=t[1]-n[1],d=t[2]-n[2],f=Math.hypot(u,b,d);if(f>1e-6&&s>1e-6){let T=s/f;return[n[0]+u*T,n[1]+b*T,n[2]+d*T]}return[h,y,o]}function Zn(n,e){let t=n?.modelRootMatrix;if(!t||t.length!==16)return e;let s=new Float32Array(16);return kn(s,t instanceof Float32Array?t:Float32Array.from(t))?[s[0]*e[0]+s[4]*e[1]+s[8]*e[2]+s[12],s[1]*e[0]+s[5]*e[1]+s[9]*e[2]+s[13],s[2]*e[0]+s[6]*e[1]+s[10]*e[2]+s[14]]:e}function cn(n,e){n.__ikWarned||(n.__ikWarned=new Set);let t=n.__ikWarned;t.has(e)||(t.add(e),console.warn(`[three-live] ik: joint '${e}' on '${n?.name??""}' not found among scene nodes or meshes.`))}function fn(n,e,t){if(Array.isArray(n))return[n[0],n[1],n[2]];let s=e.get(n);if(s)return mn(s);let r;if(n==="head"?r=t?.headPose?.position??t?.headPose??t?.cameraPosition:n==="hand-left"?r=t?.handPoses?.left?.position??t?.handPoses?.left??t?.hands?.left?.position??t?.hands?.left:n==="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 Zn(t,[i[0],i[1],i[2]])}return null}function un(n,e){return[n[3]*e[0]+n[0]*e[3]+n[1]*e[2]-n[2]*e[1],n[3]*e[1]-n[0]*e[2]+n[1]*e[3]+n[2]*e[0],n[3]*e[2]+n[0]*e[1]-n[1]*e[0]+n[2]*e[3],n[3]*e[3]-n[0]*e[0]-n[1]*e[1]-n[2]*e[2]]}function ne(n){return[-n[0],-n[1],-n[2],n[3]]}function yn(n){let e=Math.hypot(n[0],n[1],n[2],n[3]);return e>1e-12?[n[0]/e,n[1]/e,n[2]/e,n[3]/e]:[0,0,0,1]}function ee(n,e){if(e>=1)return n;if(e<=0)return[0,0,0,1];let[t,s,r,i]=n;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*e)/y;return yn([t*o,s*o,r*o,Math.cos(h*e)])}function te(n){let e=Math.hypot(n[0],n[1],n[2])||1,t=Math.hypot(n[4],n[5],n[6])||1,s=Math.hypot(n[8],n[9],n[10])||1,r=n[0]/e,i=n[1]/e,h=n[2]/e,y=n[4]/t,o=n[5]/t,a=n[6]/t,c=n[8]/s,l=n[9]/s,m=n[10]/s,u=r+o+m,b;if(u>0){let d=Math.sqrt(u+1)*2;b=[(a-l)/d,(c-h)/d,(i-y)/d,.25*d]}else if(r>o&&r>m){let d=Math.sqrt(1+r-o-m)*2;b=[.25*d,(y+i)/d,(c+h)/d,(a-l)/d]}else if(o>m){let d=Math.sqrt(1+o-r-m)*2;b=[(y+i)/d,.25*d,(l+a)/d,(c-h)/d]}else{let d=Math.sqrt(1+m-r-o)*2;b=[(c+h)/d,(l+a)/d,.25*d,(i-y)/d]}return yn(b)}function re(n,e,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),b=2*(r*i+s*h),d=1-2*(s*s+r*r);for(let f=0;f<3;f++){let T=e[f*4],x=e[f*4+1],M=e[f*4+2];n[f*4]=y*T+o*x+a*M,n[f*4+1]=c*T+l*x+m*M,n[f*4+2]=u*T+b*x+d*M}}function nn(n,e){let t=e[0]-n[0],s=e[1]-n[1],r=e[2]-n[2],i=Math.hypot(t,s,r);return i>1e-9?[t/i,s/i,r/i]:null}function Cn(n){n?.normalMatrix&&n?.transform&&Z(n.normalMatrix,n.transform)}var Ln=new WeakMap;function oe(n){let e=Ln.get(n);return e||(e=new Int32Array(n.nodes.length).fill(-1),n.nodes.forEach((t,s)=>{for(let r of Array.isArray(t?.children)?t.children:[])typeof r=="number"&&r>=0&&r<e.length&&(e[r]=s)}),Ln.set(n,e)),e}function se(n,e,t){let s=n?.gltf,r=s?.nodes;if(!Array.isArray(r)||r.length===0)return!1;let i=new Map;r.forEach((p,g)=>{typeof p?.name=="string"&&p.name&&!i.has(p.name)&&i.set(p.name,g)});let y=(e.mid?[e.root,e.mid,e.effector]:[e.root,e.effector]).map(p=>i.get(p));if(y.some(p=>p===void 0))return!1;let o=y,a=oe(s);for(let p=1;p<o.length;p++){let g=a[o[p]],I=0;for(;g>=0&&g!==o[p-1]&&I++<256;)g=a[g];if(g!==o[p-1])return!1}let c=o[0],l=n.initialNodeTransforms,m=new Map,u=[],b=[c];for(;b.length&&u.length<4096;){let p=b.pop();if(m.has(p))continue;let g=l?.[p],I=r[p];m.set(p,{t:g?[g.t[0],g.t[1],g.t[2]]:I?.translation?[...I.translation]:[0,0,0],r:g?[g.r[0],g.r[1],g.r[2],g.r[3]]:I?.rotation?[...I.rotation]:[0,0,0,1],s:g?[g.s[0],g.s[1],g.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"&&b.push(V)}let d=a[c],f=d>=0&&n.worldMatrices?.[d]?.length===16?Float32Array.from(n.worldMatrices[d]):N(),T=new Map,x=()=>{let p=(g,I)=>{let V=m.get(g);if(!V)return;let w=N();J(w,V.r,V.t,V.s);let S=N();an(S,I,w),T.set(g,S);for(let E of Array.isArray(r[g]?.children)?r[g].children:[])typeof E=="number"&&p(E,S)};p(c,f)},M=p=>{let g=T.get(p);return[g[12],g[13],g[14]]};x();let A=o.map(M),F=p=>{if(typeof p=="string"&&!t.has(p)){let g=i.get(p),I=g!==void 0?T.get(g)??n.worldMatrices?.[g]:void 0;if(I&&I.length===16)return[I[12],I[13],I[14]]}return fn(p,t,n)},R=F(e.target);if(!R)return!0;let _=e.pole?F(e.pole)??void 0:void 0,v=Pn(A,e,R,_),k=Nn(e.weight,0,1,1);for(let p=0;p<o.length-1;p++){let g=nn(M(o[p]),M(o[p+1])),I=nn(v[p],v[p+1]);if(!g||!I)continue;let V=ee(en(g,I),k),w=o[p],S=a[w],E=S===d||S<0?f:T.get(S)??f,B=te(E),C=m.get(w);C.r=yn(un(ne(B),un(V,un(B,C.r)))),x()}if(Array.isArray(n.worldMatrices))for(let[p,g]of T)n.worldMatrices[p]?.set&&n.worldMatrices[p].set(g);for(let p of n.meshes??[]){let g=T.get(p?.nodeIndex);g&&p.transform?.set&&(p.transform.set(g),Cn(p))}return!0}function Pn(n,e,t,s){if(e.solver==="two-bone"&&n.length===3){let r=dn(n[0],n[1],n[2],t,s);return[n[0],r.midPos,r.effectorPos]}return hn(n,t,e.iterations,e.tolerance).positions}function ie(n,e,t){let s=n.__ikRestOffsets,r=n.__ikRestMats;if(!(!s||!r))for(let i=0;i<e.length-1;i++){let h=e[i]?.transform??e[i]?.modelMatrix,y=r[i],o=nn([0,0,0],s[i]),a=nn(t[i],t[i+1]);!h||h.length<16||!y||y.length<16||!o||!a||(re(h,y,en(o,a)),Cn(e[i]))}}var pn={name:"ik",onRegister(){let n=Q();_n(ln),ln(n.threeNamespace,n)},onUpdate(n){let e=n?.meshes;if(!Array.isArray(e)||e.length===0)return;let t=null;for(let s of e){let r=s?.userData?.xr?.ik??s?.extras?.xr?.ik??s?.extensions?.ANDROID_xr_scenecore?.ik;if(!r)continue;let i=Hn(r);if(!i||i.weight<=0)continue;if(!t){t=new Map;for(let A of e)A&&typeof A.name=="string"&&A.name&&t.set(A.name,A)}if(se(n,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||cn(s,i.root),y||cn(s,i.effector),i.mid&&!o&&cn(s,i.mid),!h||!y)continue;let a=fn(i.target,t,n);if(!a)continue;let c=i.pole?fn(i.pole,t,n)??void 0:void 0,l=o?[h,o,y]:[h,y],m=l.map(A=>A.name||"").join(">");if(!s.__ikRestOffsets||s.__ikRestKey!==m){let A=l.map(mn),F=[];for(let R=0;R<A.length-1;R++)F.push([A[R+1][0]-A[R][0],A[R+1][1]-A[R][1],A[R+1][2]-A[R][2]]);s.__ikRestOffsets=F,s.__ikRestKey=m,s.__ikRestMats=l.map(R=>Array.from(R.transform??R.modelMatrix??[]))}let u=s.__ikRestOffsets,d=[mn(h)],f=[];for(let A=0;A<u.length;A++){let F=d[A],R=u[A];d.push([F[0]+R[0],F[1]+R[1],F[2]+R[2]]),f.push(Math.hypot(R[0],R[1],R[2]))}let T=Pn(d,i,a,c),x=d[0],M=[d[0]];for(let A=1;A<l.length;A++){let F=u[A-1],R=[x[0]+F[0],x[1]+F[1],x[2]+F[2]],_=[x[0]+(T[A][0]-T[A-1][0]),x[1]+(T[A][1]-T[A-1][1]),x[2]+(T[A][2]-T[A-1][2])],v=Yn(x,R,_,f[A-1],i.weight);qn(l[A],v),x=v,M.push(v)}ie(s,l,M)}}};var ae={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function W(n,e,t,s){if(!t||t.bufferView===void 0)return null;let r=n.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=ae[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>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(h===5126&&a===o&&c%4===0)return new Float32Array(e,c,i*s);let l=new DataView(e),m=t.normalized===!0,u=new Float32Array(i*s);for(let b=0;b<i;b++){let d=c+b*a;for(let f=0;f<s;f++){let T=d+f*y,x;switch(h){case 5126:x=l.getFloat32(T,!0);break;case 5120:x=l.getInt8(T),m&&(x=Math.max(x/127,-1));break;case 5121:x=l.getUint8(T),m&&(x/=255);break;case 5122:x=l.getInt16(T,!0),m&&(x=Math.max(x/32767,-1));break;case 5123:x=l.getUint16(T,!0),m&&(x/=65535);break;default:x=l.getUint32(T,!0),m&&(x/=4294967295)}u[b*s+f]=x}}return u}function Kn(n,e,t){return e%4===0?new Float32Array(n,e,t):new Float32Array(n.slice(e,e+t*4))}function Wn(n,e,t,s){let r=e[0],i=e[1],h=e[2],y=e[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 n[0]=r,n[1]=i,n[2]=h,n[3]=y,n;let u=Math.acos(m),b=Math.sqrt(1-m*m);if(Math.abs(b)<.001)return n[0]=.5*(r+o),n[1]=.5*(i+a),n[2]=.5*(h+c),n[3]=.5*(y+l),n;let d=Math.sin((1-s)*u)/b,f=Math.sin(s*u)/b;return n[0]=r*d+o*f,n[1]=i*d+a*f,n[2]=h*d+c*f,n[3]=y*d+l*f,n}function On(n,e,t,s){return n[0]=e[0]+s*(t[0]-e[0]),n[1]=e[1]+s*(t[1]-e[1]),n[2]=e[2]+s*(t[2]-e[2]),n}function gn(n,e){if(!Array.isArray(n?.animations))return[];let t=[];for(let s=0;s<n.animations.length;s++){let r=n.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=n.accessors?.[a.input],l=n.accessors?.[a.output];if(!c||!l)continue;let m=n.bufferViews?.[c.bufferView],u=n.bufferViews?.[l.bufferView];if(!m||!u)continue;let b=(m.byteOffset||0)+(c.byteOffset||0),d=(u.byteOffset||0)+(l.byteOffset||0),f=W(n,e,c,1)??Kn(e,b,c.count);f.length>0&&f[f.length-1]>y&&(y=f[f.length-1]);let T=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(l.count/Math.max(1,c.count))):3,x=o.target.path==="weights"?1:T,M=W(n,e,l,x)??Kn(e,d,l.count*x),A=a.interpolation==="STEP"?"STEP":"LINEAR";h.push({nodeIndex:o.target.node,path:o.target.path,times:f,values:M,interpolation:A})}h.length>0&&t.push({name:i,duration:y,channels:h})}return t}function U(n,e,t){let{times:s,values:r,path:i,interpolation:h}=n,y=s.length;if(y===0)return;let o=i==="rotation"?4:i==="weights"?Math.max(1,Math.round(r.length/y)):3;if(e<=s[0]){for(let x=0;x<o;x++)t[x]=r[x];return}if(e>=s[y-1]){let x=(y-1)*o;for(let M=0;M<o;M++)t[M]=r[x+M];return}let a=0,c=y-1;for(;a<=c;){let x=a+c>>1;s[x]<=e?a=x+1:c=x-1}let l=Math.max(0,c),m=Math.min(y-1,l+1);if(h==="STEP"||l===m){let x=l*o;for(let M=0;M<o;M++)t[M]=r[x+M];return}let u=s[l],b=s[m],d=(e-u)/Math.max(1e-5,b-u),f=l*o,T=m*o;if(i==="rotation"){let x=[r[f],r[f+1],r[f+2],r[f+3]],M=[r[T],r[T+1],r[T+2],r[T+3]];Wn(t,x,M,d)}else for(let x=0;x<o;x++)t[x]=r[f+x]+d*(r[T+x]-r[f+x])}var tn=new WeakMap;function An(n,e,t=.3){if(!n?.animations)return;let s=n.animations.find(y=>y.name===e);if(!s)return;let r=tn.get(n);r||(r=[],n.currentClip&&r.push({clip:n.currentClip,time:n.animationTime||0,weight:1,fadeSpeed:0}),tn.set(n,r));let i=t>0?1/t:1e3;for(let y of r)y.clip.name!==e&&(y.fadeSpeed=-i);let h=r.find(y=>y.clip.name===e);h?h.fadeSpeed=i:r.push({clip:s,time:0,weight:t>0?0:1,fadeSpeed:i}),n.currentClip=s,n.isPlayingAnimation=!0}function bn(n,e){if(!n.gltf||!Array.isArray(n.gltf.nodes))return;let t=tn.get(n);if(!t||t.length===0){if(!n.currentClip)return;t=[{clip:n.currentClip,time:e,weight:1,fadeSpeed:0}]}let s=n.gltf.nodes.length,r=[];for(let l=0;l<s;l++){let m=n.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 b=r[u.nodeIndex];if(u.path==="translation")U(u,l.time,i),On(b.t,b.t,i,m);else if(u.path==="rotation")U(u,l.time,h),Wn(b.r,b.r,h,m);else if(u.path==="scale")U(u,l.time,y),On(b.s,b.s,y,m);else if(u.path==="weights"&&(U(u,l.time,o),n.meshes)){for(let d of n.meshes)if(d.nodeIndex===u.nodeIndex){for(let f of d.primitives)if(f.pluginData?.morph?.weights){let T=f.pluginData.morph.weights,x=f.pluginData.morph.numTargets||T.length;for(let M=0;M<x;M++)T[M]=T[M]*(1-m)+o[M]*m}}}}}let a=[];for(let l=0;l<s;l++){let m=N(),{t:u,r:b,s:d}=r[l];J(m,b,u,d),a.push(m)}let c=En(n.gltf,a);n.worldMatrices=c;for(let l of n.meshes)l.nodeIndex>=0&&l.nodeIndex<c.length&&(l.transform.set(c[l.nodeIndex]),Z(l.normalMatrix,l.transform))}var Tn={name:"keyframes",evaluateAnimation:bn,crossFadeTo:An,onParseGLB(n){!n.animations&&n.gltf?.animations&&(n.animations=gn(n.gltf,n.bin))},onUpdate(n,e){if(!n.isPlayingAnimation)return;let t=tn.get(n);if(t&&t.length>0){for(let s=t.length-1;s>=0;s--){let r=t[s];if(r.time+=e,r.clip.duration>0&&(r.time%=r.clip.duration),r.fadeSpeed!==0)if(r.weight+=r.fadeSpeed*e,r.weight<=0){t.splice(s,1);continue}else r.weight>=1&&(r.weight=1,r.fadeSpeed=0)}t.length>0&&(n.animationTime=t[t.length-1].time),bn(n,n.animationTime)}else n.currentClip&&(n.animationTime+=e,n.currentClip.duration>0&&(n.animationTime%=n.currentClip.duration),bn(n,n.animationTime))}};var $=64;function zn(n,e,t){if(!(!n?.meshes||e<0||e>=$))for(let s of n.meshes)for(let r of s.primitives){let i=r.pluginData?.morph;i?.weights&&(i.weights[e]=t)}}var xn={name:"morph",onResolveShader(n,e,t,s){if(!Array.isArray(n?.targets)||n.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(n,e,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 b=i[u].POSITION;if(b===void 0)continue;let d=s.accessors?.[b],f=s.bufferViews?.[d?.bufferView];if(!d||!f)continue;let T=W(s,r,d,3);if(!T||T.length<o*3)continue;let x=u*o*4;for(let M=0;M<o;M++)c[x+M*4]=T[M*3],c[x+M*4+1]=T[M*3+1],c[x+M*4+2]=T[M*3+2],c[x+M*4+3]=0}let l=n.createTexture();n.bindTexture(3553,l),n.texImage2D(3553,0,34836,o,a,0,6408,5126,c),n.texParameteri(3553,10242,33071),n.texParameteri(3553,10243,33071),n.texParameteri(3553,10241,9728),n.texParameteri(3553,10240,9728);let m=new Float32Array($);return{hasMorph:!0,morphTex:l,numTargets:a,vertexCount:o,weights:m}},onBeforeDrawPrimitive(n,e,t,s,r,i){let h=t.pluginData?.morph;if(!h?.hasMorph||!h.morphTex)return;n.activeTexture(33989),n.bindTexture(3553,h.morphTex);let y=n.getUniformLocation(e,"uMorphDeltasTex");y&&n.uniform1i(y,5);let o=n.getUniformLocation(e,"uNumMorphTargets");o&&n.uniform1i(o,h.numTargets);let a=n.getUniformLocation(e,"uMorphWeights[0]");a&&n.uniform1fv(a,h.weights)}};var Mn=64,wn={name:"skinning",onResolveShader(n,e,t,s){if(n?.attributes?.JOINTS_0===void 0||n?.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[${Mn}];`),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(n,e,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=n.createBuffer();n.bindBuffer(34962,m);let u=h.componentType===5121?5121:5123,b=u===5121?new Uint8Array(r,c,h.count*4):new Uint16Array(r,c,h.count*4);n.bufferData(34962,b,35044),n.enableVertexAttribArray(4),n.vertexAttribIPointer(4,4,u,0,0);let d=n.createBuffer();n.bindBuffer(34962,d);let f=W(s,r,y,4)??new Float32Array(r,l,y.count*4);return n.bufferData(34962,f,35044),n.enableVertexAttribArray(5),n.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,d]}},onBeforeDrawPrimitive(n,e,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(Mn*16);for(let l=0;l<o.length&&l<Mn;l++){let m=o[l],u=r[m]||N();a.subarray(l*16,(l+1)*16).set(u)}let c=n.getUniformLocation(e,"uJointMatrix[0]");c&&n.uniformMatrix4fv(c,!1,a)}};X(xn);X(Tn);X(wn);X(pn);
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.
@@ -169,6 +185,18 @@ export interface ThreeLiveAttributes {
169
185
  'shadow-softness'?: number | string;
170
186
  /** Tone mapping mode ("neutral", "aces", "agx", "reinhard", "none"). */
171
187
  'tone-mapping'?: string;
188
+ /** Dual-Kawase bloom intensity (0.0 to 5.0). */
189
+ 'bloom'?: number | string;
190
+ /** Luminance threshold for bloom extraction (default: 0.8). */
191
+ 'bloom-threshold'?: number | string;
192
+ /** Blur radius multiplier for bloom passes (default: 0.5). */
193
+ 'bloom-radius'?: number | string;
194
+ /** Declarative silhouette outline toggle or config. */
195
+ 'outline'?: boolean | string;
196
+ /** Highlight the currently `selected-mesh` with a silhouette outline. */
197
+ 'outline-selected'?: boolean | string;
198
+ /** Silhouette outline CSS hex color (default: "#38bdf8"). */
199
+ 'outline-color'?: string;
172
200
  /** Enable or disable interactive camera orbit/pan/zoom controls (default: true). */
173
201
  'camera-controls'?: boolean | string;
174
202
  /** Automatically start keyframe animation playback. */
@@ -210,6 +238,16 @@ export interface ThreeLiveAttributes {
210
238
  // React 19 / JSX Event Listeners
211
239
  onload?: (e: CustomEvent<{model: GLBData}>) => void;
212
240
  onerror?: (e: CustomEvent<{error: any}>) => void;
241
+ 'onthree-load'?: (
242
+ e: CustomEvent<{model: GLBData; source?: 'src' | 'model'}>,
243
+ ) => void;
244
+ 'onthree-error'?: (
245
+ e: CustomEvent<{error: any; message: string; stage: string}>,
246
+ ) => void;
247
+ 'onthree-context-lost'?: (e: CustomEvent<{originalEvent?: Event}>) => void;
248
+ 'onthree-context-restored'?: (
249
+ e: CustomEvent<{originalEvent?: Event}>,
250
+ ) => void;
213
251
  onmeshclick?: (e: CustomEvent<HitDetail>) => void;
214
252
  'oncamera-change'?: (e: CustomEvent<CameraDetail>) => void;
215
253
  'onvariant-applied'?: (e: CustomEvent<{variantName: string | null}>) => void;
@@ -427,7 +465,27 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
427
465
  sdpMLineIndex: number | null;
428
466
  }>,
429
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;
430
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;
431
489
  oncharacterjump?: (
432
490
  e: CustomEvent<{nodeId: string; position: [number, number, number]}>,
433
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 n=typeof globalThis<"u"?globalThis:{};if(!n[Y]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,Y,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[Y]=e}}return n[Y]}var ee=j().plugins;function xn(n){let e=j();e.workerExtensionInstallers||(e.workerExtensionInstallers=[]),e.workerExtensionInstallers.includes(n)||e.workerExtensionInstallers.push(n)}function Q(n){let e=j().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function N(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function on(n,e,t){let s=e[0],r=e[1],i=e[2],h=e[3],y=e[4],o=e[5],a=e[6],c=e[7],l=e[8],m=e[9],u=e[10],b=e[11],d=e[12],f=e[13],T=e[14],x=e[15],M=t[0],A=t[1],F=t[2],R=t[3];return n[0]=M*s+A*y+F*l+R*d,n[1]=M*r+A*o+F*m+R*f,n[2]=M*i+A*a+F*u+R*T,n[3]=M*h+A*c+F*b+R*x,M=t[4],A=t[5],F=t[6],R=t[7],n[4]=M*s+A*y+F*l+R*d,n[5]=M*r+A*o+F*m+R*f,n[6]=M*i+A*a+F*u+R*T,n[7]=M*h+A*c+F*b+R*x,M=t[8],A=t[9],F=t[10],R=t[11],n[8]=M*s+A*y+F*l+R*d,n[9]=M*r+A*o+F*m+R*f,n[10]=M*i+A*a+F*u+R*T,n[11]=M*h+A*c+F*b+R*x,M=t[12],A=t[13],F=t[14],R=t[15],n[12]=M*s+A*y+F*l+R*d,n[13]=M*r+A*o+F*m+R*f,n[14]=M*i+A*a+F*u+R*T,n[15]=M*h+A*c+F*b+R*x,n}function X(n,e,t,s){let r=e[0],i=e[1],h=e[2],y=e[3],o=r+r,a=i+i,c=h+h,l=r*o,m=r*a,u=r*c,b=i*a,d=i*c,f=h*c,T=y*o,x=y*a,M=y*c,A=s[0],F=s[1],R=s[2];return n[0]=(1-(b+f))*A,n[1]=(m+M)*A,n[2]=(u-x)*A,n[3]=0,n[4]=(m-M)*F,n[5]=(1-(l+f))*F,n[6]=(d+T)*F,n[7]=0,n[8]=(u+x)*R,n[9]=(d-T)*R,n[10]=(1-(l+b))*R,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function Z(n,e){let t=e[0],s=e[1],r=e[2],i=e[4],h=e[5],y=e[6],o=e[8],a=e[9],c=e[10],l=c*h-y*a,m=-c*i+y*o,u=a*i-h*o,b=t*l+s*m+r*u;return b&&(b=1/b,n[0]=l*b,n[1]=m*b,n[2]=u*b,n[3]=(-c*s+r*a)*b,n[4]=(c*t-r*o)*b,n[5]=(-a*t+s*o)*b,n[6]=(y*s-r*h)*b,n[7]=(-y*t+r*i)*b,n[8]=(h*t-s*i)*b),n}function Mn(n,e){let t=e[0],s=e[1],r=e[2],i=e[3],h=e[4],y=e[5],o=e[6],a=e[7],c=e[8],l=e[9],m=e[10],u=e[11],b=e[12],d=e[13],f=e[14],T=e[15],x=t*y-s*h,M=t*o-r*h,A=t*a-i*h,F=s*o-r*y,R=s*a-i*y,_=r*a-i*o,v=c*d-l*b,k=c*f-m*b,p=c*T-u*b,g=l*f-m*d,I=l*T-u*d,V=m*T-u*f,w=x*V-M*I+A*g+F*p-R*k+_*v;return w?(w=1/w,n[0]=(y*V-o*I+a*g)*w,n[1]=(r*I-s*V-i*g)*w,n[2]=(d*_-f*R+T*F)*w,n[3]=(m*R-l*_-u*F)*w,n[4]=(o*p-h*V-a*k)*w,n[5]=(t*V-r*p+i*k)*w,n[6]=(f*A-b*_-T*M)*w,n[7]=(c*_-m*A+u*M)*w,n[8]=(h*I-y*p+a*v)*w,n[9]=(s*p-t*I-i*v)*w,n[10]=(b*R-d*A+T*x)*w,n[11]=(l*A-c*R-u*x)*w,n[12]=(y*k-h*g-o*v)*w,n[13]=(t*g-s*k+r*v)*w,n[14]=(d*M-b*F-f*x)*w,n[15]=(c*F-l*M+m*x)*w,n):null}function wn(n,e){let t=Array.isArray(n?.nodes)?n.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 n.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=n.nodes[c];if(!u)return;let b=N();if(e&&e[c])b.set(e[c]);else if(u.matrix&&u.matrix.length===16)b.set(u.matrix);else{let f=u.translation||[0,0,0],T=u.rotation||[0,0,0,1],x=u.scale||[1,1,1];X(b,T,f,x)}let d=s[c];if(l?on(d,l,b):d.set(b),Array.isArray(u.children))for(let f of u.children)typeof f=="number"&&y(f,d,m+1)},o=[],a=n.scenes&&n.scenes[n.scene!==void 0?n.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 cn(n,e){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 T=Math.hypot(o[1],o[0])||1;return[-o[1]/T,o[0]/T,0,0]}let f=Math.hypot(o[2],o[1])||1;return[0,-o[2]/f,o[1]/f,0]}let m=o[1]*a[2]-o[2]*a[1],u=o[2]*a[0]-o[0]*a[2],b=o[0]*a[1]-o[1]*a[0],d=Math.hypot(m,u,b,l)||1;return[m/d,u/d,b/d,l/d]}function r(o,a,c,l,m){let u=a[0]-o[0],b=a[1]-o[1],d=a[2]-o[2],f=Math.hypot(u,b,d),T=c[0]-a[0],x=c[1]-a[1],M=c[2]-a[2],A=Math.hypot(T,x,M);if(f<1e-6||A<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/f,b/f,d/f],R=[T/A,x/A,M/A],_=l[0]-o[0],v=l[1]-o[1],k=l[2]-o[2],p=Math.hypot(_,v,k),g=p>1e-6?[_/p,v/p,k/p]:F,I=Math.abs(f-A)+1e-5,V=Math.max(I,f+A-1e-5),w=Math.max(I,Math.min(V,p>1e-6?p:I)),S=t((f*f+w*w-A*A)/(2*f*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]:b,U=m?m[2]-o[2]:d,z=B*g[0]+C*g[1]+U*g[2],K=B-g[0]*z,O=C-g[1]*z,P=U-g[2]*z,D=Math.hypot(K,O,P);if(D<=1e-6){let gn=Math.abs(g[1])<.99?0:1,An=Math.abs(g[1])<.99?1:0,Tn=0;K=g[1]*Tn-g[2]*An,O=g[2]*gn-g[0]*Tn,P=g[0]*An-g[1]*gn,D=Math.hypot(K,O,P)||1}let tn=[K/D,O/D,P/D],L=[o[0]+g[0]*(f*S)+tn[0]*(f*E),o[1]+g[1]*(f*S)+tn[1]*(f*E),o[2]+g[2]*(f*S)+tn[2]*(f*E)],rn=[o[0]+g[0]*w,o[1]+g[1]*w,o[2]+g[2]*w],yn=rn[0]-L[0],pn=rn[1]-L[1],bn=rn[2]-L[2],H=Math.hypot(yn,pn,bn),q=H>1e-6?[yn/H,pn/H,bn/H]:g,On=[L[0]+q[0]*A,L[1]+q[1]*A,L[2]+q[2]*A],Wn=[(L[0]-o[0])/f,(L[1]-o[1])/f,(L[2]-o[2])/f];return{rootPos:[o[0],o[1],o[2]],midPos:L,effectorPos:On,rootRotation:s(F,Wn),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]]),b=[],d=[],f=0;for(let p=0;p<m-1;p++){let g=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(g,I,V);b.push(w),f+=w,d.push(w>1e-6?[g/w,I/w,V/w]:[0,1,0])}let T=[u[0][0],u[0][1],u[0][2]],x=Math.round(t(c,1,32,8)),M=t(l,1e-5,.1,.001),A=a[0]-T[0],F=a[1]-T[1],R=a[2]-T[2],_=Math.hypot(A,F,R),v=0;if(_>=f&&f>1e-6){let p=_>1e-6?[A/_,F/_,R/_]:d[0];u[0]=[T[0],T[1],T[2]];for(let g=0;g<m-1;g++){let I=b[g];u[g+1]=[u[g][0]+p[0]*I,u[g][1]+p[1]*I,u[g][2]+p[2]*I]}v=1}else for(let p=1;p<=x;p++){let g=u[m-1];if(Math.hypot(g[0]-a[0],g[1]-a[1],g[2]-a[2])<=M)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],b[w],d[w],-1);u[0]=[T[0],T[1],T[2]];for(let w=0;w<m-1;w++)u[w+1]=V(u[w],u[w+1],b[w],d[w],1)}let k=[];for(let p=0;p<m-1;p++){let g=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(g,I,V),S=w>1e-6?[g/w,I/w,V/w]:d[p];k.push(s(d[p],S))}return{positions:u,rotations:k,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=M=>{if(typeof M!="string")return;let A=M.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(A)?A:void 0},l=M=>Array.isArray(M)&&M.length===3&&M.every(A=>typeof A=="number"&&Number.isFinite(A))?[t(M[0],-1e3,1e3,0),t(M[1],-1e3,1e3,0),t(M[2],-1e3,1e3,0)]:void 0,m=c(a.root),u=c(a.effector);if(!m||!u)return null;let b=c(a.mid),d=l(a.target)??c(a.target);if(!d)return null;let f=a.pole??a.poleTarget,T=l(f)??c(f),x=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||b?"two-bone":"fabrik";return{root:m,...b?{mid:b}:{},effector:u,target:d,...T?{pole:T}:{},solver:x,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 e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=y),{clampNum:t,parseIKTrait:h,quatFromUnitVectors:s,solveTwoBoneIK:r,solveFABRIK:i,IKSolver:y}}var G=cn(),Fn=G.clampNum,zn=G.parseIKTrait,mn=G.quatFromUnitVectors,In=G.solveTwoBoneIK,Vn=G.solveFABRIK,Gn=G.IKSolver;function un(n){let e=n?.transform??n?.modelMatrix;return e&&e.length>=16?[e[12]||0,e[13]||0,e[14]||0]:[0,0,0]}function Un(n,e){let t=n?.transform??n?.modelMatrix;!t||t.length<16||(t[12]=e[0],t[13]=e[1],t[14]=e[2])}function Dn(n,e,t,s,r){let i=Fn(r,0,1,1),h=e[0]+(t[0]-e[0])*i,y=e[1]+(t[1]-e[1])*i,o=e[2]+(t[2]-e[2])*i,a=h-n[0],c=y-n[1],l=o-n[2],m=Math.hypot(a,c,l);if(m>1e-6&&s>1e-6){let T=s/m;return[n[0]+a*T,n[1]+c*T,n[2]+l*T]}let u=t[0]-n[0],b=t[1]-n[1],d=t[2]-n[2],f=Math.hypot(u,b,d);if(f>1e-6&&s>1e-6){let T=s/f;return[n[0]+u*T,n[1]+b*T,n[2]+d*T]}return[h,y,o]}function jn(n,e){let t=n?.modelRootMatrix;if(!t||t.length!==16)return e;let s=new Float32Array(16);return Mn(s,t instanceof Float32Array?t:Float32Array.from(t))?[s[0]*e[0]+s[4]*e[1]+s[8]*e[2]+s[12],s[1]*e[0]+s[5]*e[1]+s[9]*e[2]+s[13],s[2]*e[0]+s[6]*e[1]+s[10]*e[2]+s[14]]:e}function sn(n,e){n.__ikWarned||(n.__ikWarned=new Set);let t=n.__ikWarned;t.has(e)||(t.add(e),console.warn(`[three-live] ik: joint '${e}' on '${n?.name??""}' not found among scene nodes or meshes.`))}function ln(n,e,t){if(Array.isArray(n))return[n[0],n[1],n[2]];let s=e.get(n);if(s)return un(s);let r;if(n==="head"?r=t?.headPose?.position??t?.headPose??t?.cameraPosition:n==="hand-left"?r=t?.handPoses?.left?.position??t?.handPoses?.left??t?.hands?.left?.position??t?.hands?.left:n==="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 jn(t,[i[0],i[1],i[2]])}return null}function an(n,e){return[n[3]*e[0]+n[0]*e[3]+n[1]*e[2]-n[2]*e[1],n[3]*e[1]-n[0]*e[2]+n[1]*e[3]+n[2]*e[0],n[3]*e[2]+n[0]*e[1]-n[1]*e[0]+n[2]*e[3],n[3]*e[3]-n[0]*e[0]-n[1]*e[1]-n[2]*e[2]]}function Qn(n){return[-n[0],-n[1],-n[2],n[3]]}function fn(n){let e=Math.hypot(n[0],n[1],n[2],n[3]);return e>1e-12?[n[0]/e,n[1]/e,n[2]/e,n[3]/e]:[0,0,0,1]}function Xn(n,e){if(e>=1)return n;if(e<=0)return[0,0,0,1];let[t,s,r,i]=n;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*e)/y;return fn([t*o,s*o,r*o,Math.cos(h*e)])}function Jn(n){let e=Math.hypot(n[0],n[1],n[2])||1,t=Math.hypot(n[4],n[5],n[6])||1,s=Math.hypot(n[8],n[9],n[10])||1,r=n[0]/e,i=n[1]/e,h=n[2]/e,y=n[4]/t,o=n[5]/t,a=n[6]/t,c=n[8]/s,l=n[9]/s,m=n[10]/s,u=r+o+m,b;if(u>0){let d=Math.sqrt(u+1)*2;b=[(a-l)/d,(c-h)/d,(i-y)/d,.25*d]}else if(r>o&&r>m){let d=Math.sqrt(1+r-o-m)*2;b=[.25*d,(y+i)/d,(c+h)/d,(a-l)/d]}else if(o>m){let d=Math.sqrt(1+o-r-m)*2;b=[(y+i)/d,.25*d,(l+a)/d,(c-h)/d]}else{let d=Math.sqrt(1+m-r-o)*2;b=[(c+h)/d,(l+a)/d,.25*d,(i-y)/d]}return fn(b)}function $n(n,e,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),b=2*(r*i+s*h),d=1-2*(s*s+r*r);for(let f=0;f<3;f++){let T=e[f*4],x=e[f*4+1],M=e[f*4+2];n[f*4]=y*T+o*x+a*M,n[f*4+1]=c*T+l*x+m*M,n[f*4+2]=u*T+b*x+d*M}}function nn(n,e){let t=e[0]-n[0],s=e[1]-n[1],r=e[2]-n[2],i=Math.hypot(t,s,r);return i>1e-9?[t/i,s/i,r/i]:null}function vn(n){n?.normalMatrix&&n?.transform&&Z(n.normalMatrix,n.transform)}var Rn=new WeakMap;function Hn(n){let e=Rn.get(n);return e||(e=new Int32Array(n.nodes.length).fill(-1),n.nodes.forEach((t,s)=>{for(let r of Array.isArray(t?.children)?t.children:[])typeof r=="number"&&r>=0&&r<e.length&&(e[r]=s)}),Rn.set(n,e)),e}function qn(n,e,t){let s=n?.gltf,r=s?.nodes;if(!Array.isArray(r)||r.length===0)return!1;let i=new Map;r.forEach((p,g)=>{typeof p?.name=="string"&&p.name&&!i.has(p.name)&&i.set(p.name,g)});let y=(e.mid?[e.root,e.mid,e.effector]:[e.root,e.effector]).map(p=>i.get(p));if(y.some(p=>p===void 0))return!1;let o=y,a=Hn(s);for(let p=1;p<o.length;p++){let g=a[o[p]],I=0;for(;g>=0&&g!==o[p-1]&&I++<256;)g=a[g];if(g!==o[p-1])return!1}let c=o[0],l=n.initialNodeTransforms,m=new Map,u=[],b=[c];for(;b.length&&u.length<4096;){let p=b.pop();if(m.has(p))continue;let g=l?.[p],I=r[p];m.set(p,{t:g?[g.t[0],g.t[1],g.t[2]]:I?.translation?[...I.translation]:[0,0,0],r:g?[g.r[0],g.r[1],g.r[2],g.r[3]]:I?.rotation?[...I.rotation]:[0,0,0,1],s:g?[g.s[0],g.s[1],g.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"&&b.push(V)}let d=a[c],f=d>=0&&n.worldMatrices?.[d]?.length===16?Float32Array.from(n.worldMatrices[d]):N(),T=new Map,x=()=>{let p=(g,I)=>{let V=m.get(g);if(!V)return;let w=N();X(w,V.r,V.t,V.s);let S=N();on(S,I,w),T.set(g,S);for(let E of Array.isArray(r[g]?.children)?r[g].children:[])typeof E=="number"&&p(E,S)};p(c,f)},M=p=>{let g=T.get(p);return[g[12],g[13],g[14]]};x();let A=o.map(M),F=p=>{if(typeof p=="string"&&!t.has(p)){let g=i.get(p),I=g!==void 0?T.get(g)??n.worldMatrices?.[g]:void 0;if(I&&I.length===16)return[I[12],I[13],I[14]]}return ln(p,t,n)},R=F(e.target);if(!R)return!0;let _=e.pole?F(e.pole)??void 0:void 0,v=Sn(A,e,R,_),k=Fn(e.weight,0,1,1);for(let p=0;p<o.length-1;p++){let g=nn(M(o[p]),M(o[p+1])),I=nn(v[p],v[p+1]);if(!g||!I)continue;let V=Xn(mn(g,I),k),w=o[p],S=a[w],E=S===d||S<0?f:T.get(S)??f,B=Jn(E),C=m.get(w);C.r=fn(an(Qn(B),an(V,an(B,C.r)))),x()}if(Array.isArray(n.worldMatrices))for(let[p,g]of T)n.worldMatrices[p]?.set&&n.worldMatrices[p].set(g);for(let p of n.meshes??[]){let g=T.get(p?.nodeIndex);g&&p.transform?.set&&(p.transform.set(g),vn(p))}return!0}function Sn(n,e,t,s){if(e.solver==="two-bone"&&n.length===3){let r=In(n[0],n[1],n[2],t,s);return[n[0],r.midPos,r.effectorPos]}return Vn(n,t,e.iterations,e.tolerance).positions}function Yn(n,e,t){let s=n.__ikRestOffsets,r=n.__ikRestMats;if(!(!s||!r))for(let i=0;i<e.length-1;i++){let h=e[i]?.transform??e[i]?.modelMatrix,y=r[i],o=nn([0,0,0],s[i]),a=nn(t[i],t[i+1]);!h||h.length<16||!y||y.length<16||!o||!a||($n(h,y,mn(o,a)),vn(e[i]))}}var _n={name:"ik",onRegister(){let n=j();xn(cn),cn(n.threeNamespace,n)},onUpdate(n){let e=n?.meshes;if(!Array.isArray(e)||e.length===0)return;let t=null;for(let s of e){let r=s?.userData?.xr?.ik??s?.extras?.xr?.ik??s?.extensions?.ANDROID_xr_scenecore?.ik;if(!r)continue;let i=zn(r);if(!i||i.weight<=0)continue;if(!t){t=new Map;for(let A of e)A&&typeof A.name=="string"&&A.name&&t.set(A.name,A)}if(qn(n,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||sn(s,i.root),y||sn(s,i.effector),i.mid&&!o&&sn(s,i.mid),!h||!y)continue;let a=ln(i.target,t,n);if(!a)continue;let c=i.pole?ln(i.pole,t,n)??void 0:void 0,l=o?[h,o,y]:[h,y],m=l.map(A=>A.name||"").join(">");if(!s.__ikRestOffsets||s.__ikRestKey!==m){let A=l.map(un),F=[];for(let R=0;R<A.length-1;R++)F.push([A[R+1][0]-A[R][0],A[R+1][1]-A[R][1],A[R+1][2]-A[R][2]]);s.__ikRestOffsets=F,s.__ikRestKey=m,s.__ikRestMats=l.map(R=>Array.from(R.transform??R.modelMatrix??[]))}let u=s.__ikRestOffsets,d=[un(h)],f=[];for(let A=0;A<u.length;A++){let F=d[A],R=u[A];d.push([F[0]+R[0],F[1]+R[1],F[2]+R[2]]),f.push(Math.hypot(R[0],R[1],R[2]))}let T=Sn(d,i,a,c),x=d[0],M=[d[0]];for(let A=1;A<l.length;A++){let F=u[A-1],R=[x[0]+F[0],x[1]+F[1],x[2]+F[2]],_=[x[0]+(T[A][0]-T[A-1][0]),x[1]+(T[A][1]-T[A-1][1]),x[2]+(T[A][2]-T[A-1][2])],v=Dn(x,R,_,f[A-1],i.weight);Un(l[A],v),x=v,M.push(v)}Yn(s,l,M)}}};var Zn={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function W(n,e,t,s){if(!t||t.bufferView===void 0)return null;let r=n.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=Zn[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>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(h===5126&&a===o&&c%4===0)return new Float32Array(e,c,i*s);let l=new DataView(e),m=t.normalized===!0,u=new Float32Array(i*s);for(let b=0;b<i;b++){let d=c+b*a;for(let f=0;f<s;f++){let T=d+f*y,x;switch(h){case 5126:x=l.getFloat32(T,!0);break;case 5120:x=l.getInt8(T),m&&(x=Math.max(x/127,-1));break;case 5121:x=l.getUint8(T),m&&(x/=255);break;case 5122:x=l.getInt16(T,!0),m&&(x=Math.max(x/32767,-1));break;case 5123:x=l.getUint16(T,!0),m&&(x/=65535);break;default:x=l.getUint32(T,!0),m&&(x/=4294967295)}u[b*s+f]=x}}return u}function kn(n,e,t){return e%4===0?new Float32Array(n,e,t):new Float32Array(n.slice(e,e+t*4))}function Ln(n,e,t,s){let r=e[0],i=e[1],h=e[2],y=e[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 n[0]=r,n[1]=i,n[2]=h,n[3]=y,n;let u=Math.acos(m),b=Math.sqrt(1-m*m);if(Math.abs(b)<.001)return n[0]=.5*(r+o),n[1]=.5*(i+a),n[2]=.5*(h+c),n[3]=.5*(y+l),n;let d=Math.sin((1-s)*u)/b,f=Math.sin(s*u)/b;return n[0]=r*d+o*f,n[1]=i*d+a*f,n[2]=h*d+c*f,n[3]=y*d+l*f,n}function En(n,e,t,s){return n[0]=e[0]+s*(t[0]-e[0]),n[1]=e[1]+s*(t[1]-e[1]),n[2]=e[2]+s*(t[2]-e[2]),n}function Nn(n,e){if(!Array.isArray(n?.animations))return[];let t=[];for(let s=0;s<n.animations.length;s++){let r=n.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=n.accessors?.[a.input],l=n.accessors?.[a.output];if(!c||!l)continue;let m=n.bufferViews?.[c.bufferView],u=n.bufferViews?.[l.bufferView];if(!m||!u)continue;let b=(m.byteOffset||0)+(c.byteOffset||0),d=(u.byteOffset||0)+(l.byteOffset||0),f=W(n,e,c,1)??kn(e,b,c.count);f.length>0&&f[f.length-1]>y&&(y=f[f.length-1]);let T=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(l.count/Math.max(1,c.count))):3,x=o.target.path==="weights"?1:T,M=W(n,e,l,x)??kn(e,d,l.count*x),A=a.interpolation==="STEP"?"STEP":"LINEAR";h.push({nodeIndex:o.target.node,path:o.target.path,times:f,values:M,interpolation:A})}h.length>0&&t.push({name:i,duration:y,channels:h})}return t}function J(n,e,t){let{times:s,values:r,path:i,interpolation:h}=n,y=s.length;if(y===0)return;let o=i==="rotation"?4:i==="weights"?Math.max(1,Math.round(r.length/y)):3;if(e<=s[0]){for(let x=0;x<o;x++)t[x]=r[x];return}if(e>=s[y-1]){let x=(y-1)*o;for(let M=0;M<o;M++)t[M]=r[x+M];return}let a=0,c=y-1;for(;a<=c;){let x=a+c>>1;s[x]<=e?a=x+1:c=x-1}let l=Math.max(0,c),m=Math.min(y-1,l+1);if(h==="STEP"||l===m){let x=l*o;for(let M=0;M<o;M++)t[M]=r[x+M];return}let u=s[l],b=s[m],d=(e-u)/Math.max(1e-5,b-u),f=l*o,T=m*o;if(i==="rotation"){let x=[r[f],r[f+1],r[f+2],r[f+3]],M=[r[T],r[T+1],r[T+2],r[T+3]];Ln(t,x,M,d)}else for(let x=0;x<o;x++)t[x]=r[f+x]+d*(r[T+x]-r[f+x])}var en=new WeakMap;function Bn(n,e,t=.3){if(!n?.animations)return;let s=n.animations.find(y=>y.name===e);if(!s)return;let r=en.get(n);r||(r=[],n.currentClip&&r.push({clip:n.currentClip,time:n.animationTime||0,weight:1,fadeSpeed:0}),en.set(n,r));let i=t>0?1/t:1e3;for(let y of r)y.clip.name!==e&&(y.fadeSpeed=-i);let h=r.find(y=>y.clip.name===e);h?h.fadeSpeed=i:r.push({clip:s,time:0,weight:t>0?0:1,fadeSpeed:i}),n.currentClip=s,n.isPlayingAnimation=!0}function dn(n,e){if(!n.gltf||!Array.isArray(n.gltf.nodes))return;let t=en.get(n);if(!t||t.length===0){if(!n.currentClip)return;t=[{clip:n.currentClip,time:e,weight:1,fadeSpeed:0}]}let s=n.gltf.nodes.length,r=[];for(let l=0;l<s;l++){let m=n.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 b=r[u.nodeIndex];if(u.path==="translation")J(u,l.time,i),En(b.t,b.t,i,m);else if(u.path==="rotation")J(u,l.time,h),Ln(b.r,b.r,h,m);else if(u.path==="scale")J(u,l.time,y),En(b.s,b.s,y,m);else if(u.path==="weights"&&(J(u,l.time,o),n.meshes)){for(let d of n.meshes)if(d.nodeIndex===u.nodeIndex){for(let f of d.primitives)if(f.pluginData?.morph?.weights){let T=f.pluginData.morph.weights,x=f.pluginData.morph.numTargets||T.length;for(let M=0;M<x;M++)T[M]=T[M]*(1-m)+o[M]*m}}}}}let a=[];for(let l=0;l<s;l++){let m=N(),{t:u,r:b,s:d}=r[l];X(m,b,u,d),a.push(m)}let c=wn(n.gltf,a);n.worldMatrices=c;for(let l of n.meshes)l.nodeIndex>=0&&l.nodeIndex<c.length&&(l.transform.set(c[l.nodeIndex]),Z(l.normalMatrix,l.transform))}var Cn={name:"keyframes",evaluateAnimation:dn,crossFadeTo:Bn,onParseGLB(n){!n.animations&&n.gltf?.animations&&(n.animations=Nn(n.gltf,n.bin))},onUpdate(n,e){if(!n.isPlayingAnimation)return;let t=en.get(n);if(t&&t.length>0){for(let s=t.length-1;s>=0;s--){let r=t[s];if(r.time+=e,r.clip.duration>0&&(r.time%=r.clip.duration),r.fadeSpeed!==0)if(r.weight+=r.fadeSpeed*e,r.weight<=0){t.splice(s,1);continue}else r.weight>=1&&(r.weight=1,r.fadeSpeed=0)}t.length>0&&(n.animationTime=t[t.length-1].time),dn(n,n.animationTime)}else n.currentClip&&(n.animationTime+=e,n.currentClip.duration>0&&(n.animationTime%=n.currentClip.duration),dn(n,n.animationTime))}};var $=64;function ne(n,e,t){if(!(!n?.meshes||e<0||e>=$))for(let s of n.meshes)for(let r of s.primitives){let i=r.pluginData?.morph;i?.weights&&(i.weights[e]=t)}}var Pn={name:"morph",onResolveShader(n,e,t,s){if(!Array.isArray(n?.targets)||n.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(n,e,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 b=i[u].POSITION;if(b===void 0)continue;let d=s.accessors?.[b],f=s.bufferViews?.[d?.bufferView];if(!d||!f)continue;let T=W(s,r,d,3);if(!T||T.length<o*3)continue;let x=u*o*4;for(let M=0;M<o;M++)c[x+M*4]=T[M*3],c[x+M*4+1]=T[M*3+1],c[x+M*4+2]=T[M*3+2],c[x+M*4+3]=0}let l=n.createTexture();n.bindTexture(3553,l),n.texImage2D(3553,0,34836,o,a,0,6408,5126,c),n.texParameteri(3553,10242,33071),n.texParameteri(3553,10243,33071),n.texParameteri(3553,10241,9728),n.texParameteri(3553,10240,9728);let m=new Float32Array($);return{hasMorph:!0,morphTex:l,numTargets:a,vertexCount:o,weights:m}},onBeforeDrawPrimitive(n,e,t,s,r,i){let h=t.pluginData?.morph;if(!h?.hasMorph||!h.morphTex)return;n.activeTexture(33989),n.bindTexture(3553,h.morphTex);let y=n.getUniformLocation(e,"uMorphDeltasTex");y&&n.uniform1i(y,5);let o=n.getUniformLocation(e,"uNumMorphTargets");o&&n.uniform1i(o,h.numTargets);let a=n.getUniformLocation(e,"uMorphWeights[0]");a&&n.uniform1fv(a,h.weights)}};var hn=64,Kn={name:"skinning",onResolveShader(n,e,t,s){if(n?.attributes?.JOINTS_0===void 0||n?.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[${hn}];`),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(n,e,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=n.createBuffer();n.bindBuffer(34962,m);let u=h.componentType===5121?5121:5123,b=u===5121?new Uint8Array(r,c,h.count*4):new Uint16Array(r,c,h.count*4);n.bufferData(34962,b,35044),n.enableVertexAttribArray(4),n.vertexAttribIPointer(4,4,u,0,0);let d=n.createBuffer();n.bindBuffer(34962,d);let f=W(s,r,y,4)??new Float32Array(r,l,y.count*4);return n.bufferData(34962,f,35044),n.enableVertexAttribArray(5),n.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,d]}},onBeforeDrawPrimitive(n,e,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(hn*16);for(let l=0;l<o.length&&l<hn;l++){let m=o[l],u=r[m]||N();a.subarray(l*16,(l+1)*16).set(u)}let c=n.getUniformLocation(e,"uJointMatrix[0]");c&&n.uniformMatrix4fv(c,!1,a)}};Q(Pn);Q(Cn);Q(Kn);Q(_n);export{Gn as IKSolver,Bn as crossFadeTo,_n as ikPlugin,Cn as keyframeAnimationPlugin,Pn as morphPlugin,Nn as parseAnimations,mn as quatFromUnitVectors,J as sampleChannel,ne as setMorphTargetWeight,Kn as skinningPlugin,Vn as solveFABRIK,In 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 sn=Object.defineProperty;var Dn=Object.getOwnPropertyDescriptor;var jn=Object.getOwnPropertyNames;var Qn=Object.prototype.hasOwnProperty;var Xn=(n,e)=>{for(var t in e)sn(n,t,{get:e[t],enumerable:!0})},Jn=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of jn(e))!Qn.call(n,r)&&r!==t&&sn(n,r,{get:()=>e[r],enumerable:!(s=Dn(e,r))||s.enumerable});return n};var $n=n=>Jn(sn({},"__esModule",{value:!0}),n);var ce={};Xn(ce,{IKSolver:()=>Bn,crossFadeTo:()=>An,ikPlugin:()=>pn,keyframeAnimationPlugin:()=>Tn,morphPlugin:()=>xn,parseAnimations:()=>gn,quatFromUnitVectors:()=>en,sampleChannel:()=>U,setMorphTargetWeight:()=>zn,skinningPlugin:()=>wn,solveFABRIK:()=>hn,solveTwoBoneIK:()=>dn});var Y="__THREE_LIVE_REGISTRY__";function Q(){let n=typeof globalThis<"u"?globalThis:{};if(!n[Y]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,Y,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[Y]=e}}return n[Y]}var le=Q().plugins;function _n(n){let e=Q();e.workerExtensionInstallers||(e.workerExtensionInstallers=[]),e.workerExtensionInstallers.includes(n)||e.workerExtensionInstallers.push(n)}function X(n){let e=Q().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function N(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function an(n,e,t){let s=e[0],r=e[1],i=e[2],h=e[3],y=e[4],o=e[5],a=e[6],c=e[7],l=e[8],m=e[9],u=e[10],b=e[11],d=e[12],f=e[13],T=e[14],x=e[15],M=t[0],A=t[1],F=t[2],R=t[3];return n[0]=M*s+A*y+F*l+R*d,n[1]=M*r+A*o+F*m+R*f,n[2]=M*i+A*a+F*u+R*T,n[3]=M*h+A*c+F*b+R*x,M=t[4],A=t[5],F=t[6],R=t[7],n[4]=M*s+A*y+F*l+R*d,n[5]=M*r+A*o+F*m+R*f,n[6]=M*i+A*a+F*u+R*T,n[7]=M*h+A*c+F*b+R*x,M=t[8],A=t[9],F=t[10],R=t[11],n[8]=M*s+A*y+F*l+R*d,n[9]=M*r+A*o+F*m+R*f,n[10]=M*i+A*a+F*u+R*T,n[11]=M*h+A*c+F*b+R*x,M=t[12],A=t[13],F=t[14],R=t[15],n[12]=M*s+A*y+F*l+R*d,n[13]=M*r+A*o+F*m+R*f,n[14]=M*i+A*a+F*u+R*T,n[15]=M*h+A*c+F*b+R*x,n}function J(n,e,t,s){let r=e[0],i=e[1],h=e[2],y=e[3],o=r+r,a=i+i,c=h+h,l=r*o,m=r*a,u=r*c,b=i*a,d=i*c,f=h*c,T=y*o,x=y*a,M=y*c,A=s[0],F=s[1],R=s[2];return n[0]=(1-(b+f))*A,n[1]=(m+M)*A,n[2]=(u-x)*A,n[3]=0,n[4]=(m-M)*F,n[5]=(1-(l+f))*F,n[6]=(d+T)*F,n[7]=0,n[8]=(u+x)*R,n[9]=(d-T)*R,n[10]=(1-(l+b))*R,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function Z(n,e){let t=e[0],s=e[1],r=e[2],i=e[4],h=e[5],y=e[6],o=e[8],a=e[9],c=e[10],l=c*h-y*a,m=-c*i+y*o,u=a*i-h*o,b=t*l+s*m+r*u;return b&&(b=1/b,n[0]=l*b,n[1]=m*b,n[2]=u*b,n[3]=(-c*s+r*a)*b,n[4]=(c*t-r*o)*b,n[5]=(-a*t+s*o)*b,n[6]=(y*s-r*h)*b,n[7]=(-y*t+r*i)*b,n[8]=(h*t-s*i)*b),n}function kn(n,e){let t=e[0],s=e[1],r=e[2],i=e[3],h=e[4],y=e[5],o=e[6],a=e[7],c=e[8],l=e[9],m=e[10],u=e[11],b=e[12],d=e[13],f=e[14],T=e[15],x=t*y-s*h,M=t*o-r*h,A=t*a-i*h,F=s*o-r*y,R=s*a-i*y,_=r*a-i*o,v=c*d-l*b,k=c*f-m*b,p=c*T-u*b,g=l*f-m*d,I=l*T-u*d,V=m*T-u*f,w=x*V-M*I+A*g+F*p-R*k+_*v;return w?(w=1/w,n[0]=(y*V-o*I+a*g)*w,n[1]=(r*I-s*V-i*g)*w,n[2]=(d*_-f*R+T*F)*w,n[3]=(m*R-l*_-u*F)*w,n[4]=(o*p-h*V-a*k)*w,n[5]=(t*V-r*p+i*k)*w,n[6]=(f*A-b*_-T*M)*w,n[7]=(c*_-m*A+u*M)*w,n[8]=(h*I-y*p+a*v)*w,n[9]=(s*p-t*I-i*v)*w,n[10]=(b*R-d*A+T*x)*w,n[11]=(l*A-c*R-u*x)*w,n[12]=(y*k-h*g-o*v)*w,n[13]=(t*g-s*k+r*v)*w,n[14]=(d*M-b*F-f*x)*w,n[15]=(c*F-l*M+m*x)*w,n):null}function En(n,e){let t=Array.isArray(n?.nodes)?n.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 n.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=n.nodes[c];if(!u)return;let b=N();if(e&&e[c])b.set(e[c]);else if(u.matrix&&u.matrix.length===16)b.set(u.matrix);else{let f=u.translation||[0,0,0],T=u.rotation||[0,0,0,1],x=u.scale||[1,1,1];J(b,T,f,x)}let d=s[c];if(l?an(d,l,b):d.set(b),Array.isArray(u.children))for(let f of u.children)typeof f=="number"&&y(f,d,m+1)},o=[],a=n.scenes&&n.scenes[n.scene!==void 0?n.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 ln(n,e){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 T=Math.hypot(o[1],o[0])||1;return[-o[1]/T,o[0]/T,0,0]}let f=Math.hypot(o[2],o[1])||1;return[0,-o[2]/f,o[1]/f,0]}let m=o[1]*a[2]-o[2]*a[1],u=o[2]*a[0]-o[0]*a[2],b=o[0]*a[1]-o[1]*a[0],d=Math.hypot(m,u,b,l)||1;return[m/d,u/d,b/d,l/d]}function r(o,a,c,l,m){let u=a[0]-o[0],b=a[1]-o[1],d=a[2]-o[2],f=Math.hypot(u,b,d),T=c[0]-a[0],x=c[1]-a[1],M=c[2]-a[2],A=Math.hypot(T,x,M);if(f<1e-6||A<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/f,b/f,d/f],R=[T/A,x/A,M/A],_=l[0]-o[0],v=l[1]-o[1],k=l[2]-o[2],p=Math.hypot(_,v,k),g=p>1e-6?[_/p,v/p,k/p]:F,I=Math.abs(f-A)+1e-5,V=Math.max(I,f+A-1e-5),w=Math.max(I,Math.min(V,p>1e-6?p:I)),S=t((f*f+w*w-A*A)/(2*f*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]:b,D=m?m[2]-o[2]:d,z=B*g[0]+C*g[1]+D*g[2],K=B-g[0]*z,O=C-g[1]*z,P=D-g[2]*z,j=Math.hypot(K,O,P);if(j<=1e-6){let Vn=Math.abs(g[1])<.99?0:1,vn=Math.abs(g[1])<.99?1:0,Sn=0;K=g[1]*Sn-g[2]*vn,O=g[2]*Vn-g[0]*Sn,P=g[0]*vn-g[1]*Vn,j=Math.hypot(K,O,P)||1}let rn=[K/j,O/j,P/j],L=[o[0]+g[0]*(f*S)+rn[0]*(f*E),o[1]+g[1]*(f*S)+rn[1]*(f*E),o[2]+g[2]*(f*S)+rn[2]*(f*E)],on=[o[0]+g[0]*w,o[1]+g[1]*w,o[2]+g[2]*w],Rn=on[0]-L[0],Fn=on[1]-L[1],In=on[2]-L[2],H=Math.hypot(Rn,Fn,In),q=H>1e-6?[Rn/H,Fn/H,In/H]:g,Gn=[L[0]+q[0]*A,L[1]+q[1]*A,L[2]+q[2]*A],Un=[(L[0]-o[0])/f,(L[1]-o[1])/f,(L[2]-o[2])/f];return{rootPos:[o[0],o[1],o[2]],midPos:L,effectorPos:Gn,rootRotation:s(F,Un),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]]),b=[],d=[],f=0;for(let p=0;p<m-1;p++){let g=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(g,I,V);b.push(w),f+=w,d.push(w>1e-6?[g/w,I/w,V/w]:[0,1,0])}let T=[u[0][0],u[0][1],u[0][2]],x=Math.round(t(c,1,32,8)),M=t(l,1e-5,.1,.001),A=a[0]-T[0],F=a[1]-T[1],R=a[2]-T[2],_=Math.hypot(A,F,R),v=0;if(_>=f&&f>1e-6){let p=_>1e-6?[A/_,F/_,R/_]:d[0];u[0]=[T[0],T[1],T[2]];for(let g=0;g<m-1;g++){let I=b[g];u[g+1]=[u[g][0]+p[0]*I,u[g][1]+p[1]*I,u[g][2]+p[2]*I]}v=1}else for(let p=1;p<=x;p++){let g=u[m-1];if(Math.hypot(g[0]-a[0],g[1]-a[1],g[2]-a[2])<=M)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],b[w],d[w],-1);u[0]=[T[0],T[1],T[2]];for(let w=0;w<m-1;w++)u[w+1]=V(u[w],u[w+1],b[w],d[w],1)}let k=[];for(let p=0;p<m-1;p++){let g=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(g,I,V),S=w>1e-6?[g/w,I/w,V/w]:d[p];k.push(s(d[p],S))}return{positions:u,rotations:k,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=M=>{if(typeof M!="string")return;let A=M.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(A)?A:void 0},l=M=>Array.isArray(M)&&M.length===3&&M.every(A=>typeof A=="number"&&Number.isFinite(A))?[t(M[0],-1e3,1e3,0),t(M[1],-1e3,1e3,0),t(M[2],-1e3,1e3,0)]:void 0,m=c(a.root),u=c(a.effector);if(!m||!u)return null;let b=c(a.mid),d=l(a.target)??c(a.target);if(!d)return null;let f=a.pole??a.poleTarget,T=l(f)??c(f),x=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||b?"two-bone":"fabrik";return{root:m,...b?{mid:b}:{},effector:u,target:d,...T?{pole:T}:{},solver:x,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 e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=y),{clampNum:t,parseIKTrait:h,quatFromUnitVectors:s,solveTwoBoneIK:r,solveFABRIK:i,IKSolver:y}}var G=ln(),Nn=G.clampNum,Hn=G.parseIKTrait,en=G.quatFromUnitVectors,dn=G.solveTwoBoneIK,hn=G.solveFABRIK,Bn=G.IKSolver;function mn(n){let e=n?.transform??n?.modelMatrix;return e&&e.length>=16?[e[12]||0,e[13]||0,e[14]||0]:[0,0,0]}function qn(n,e){let t=n?.transform??n?.modelMatrix;!t||t.length<16||(t[12]=e[0],t[13]=e[1],t[14]=e[2])}function Yn(n,e,t,s,r){let i=Nn(r,0,1,1),h=e[0]+(t[0]-e[0])*i,y=e[1]+(t[1]-e[1])*i,o=e[2]+(t[2]-e[2])*i,a=h-n[0],c=y-n[1],l=o-n[2],m=Math.hypot(a,c,l);if(m>1e-6&&s>1e-6){let T=s/m;return[n[0]+a*T,n[1]+c*T,n[2]+l*T]}let u=t[0]-n[0],b=t[1]-n[1],d=t[2]-n[2],f=Math.hypot(u,b,d);if(f>1e-6&&s>1e-6){let T=s/f;return[n[0]+u*T,n[1]+b*T,n[2]+d*T]}return[h,y,o]}function Zn(n,e){let t=n?.modelRootMatrix;if(!t||t.length!==16)return e;let s=new Float32Array(16);return kn(s,t instanceof Float32Array?t:Float32Array.from(t))?[s[0]*e[0]+s[4]*e[1]+s[8]*e[2]+s[12],s[1]*e[0]+s[5]*e[1]+s[9]*e[2]+s[13],s[2]*e[0]+s[6]*e[1]+s[10]*e[2]+s[14]]:e}function cn(n,e){n.__ikWarned||(n.__ikWarned=new Set);let t=n.__ikWarned;t.has(e)||(t.add(e),console.warn(`[three-live] ik: joint '${e}' on '${n?.name??""}' not found among scene nodes or meshes.`))}function fn(n,e,t){if(Array.isArray(n))return[n[0],n[1],n[2]];let s=e.get(n);if(s)return mn(s);let r;if(n==="head"?r=t?.headPose?.position??t?.headPose??t?.cameraPosition:n==="hand-left"?r=t?.handPoses?.left?.position??t?.handPoses?.left??t?.hands?.left?.position??t?.hands?.left:n==="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 Zn(t,[i[0],i[1],i[2]])}return null}function un(n,e){return[n[3]*e[0]+n[0]*e[3]+n[1]*e[2]-n[2]*e[1],n[3]*e[1]-n[0]*e[2]+n[1]*e[3]+n[2]*e[0],n[3]*e[2]+n[0]*e[1]-n[1]*e[0]+n[2]*e[3],n[3]*e[3]-n[0]*e[0]-n[1]*e[1]-n[2]*e[2]]}function ne(n){return[-n[0],-n[1],-n[2],n[3]]}function yn(n){let e=Math.hypot(n[0],n[1],n[2],n[3]);return e>1e-12?[n[0]/e,n[1]/e,n[2]/e,n[3]/e]:[0,0,0,1]}function ee(n,e){if(e>=1)return n;if(e<=0)return[0,0,0,1];let[t,s,r,i]=n;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*e)/y;return yn([t*o,s*o,r*o,Math.cos(h*e)])}function te(n){let e=Math.hypot(n[0],n[1],n[2])||1,t=Math.hypot(n[4],n[5],n[6])||1,s=Math.hypot(n[8],n[9],n[10])||1,r=n[0]/e,i=n[1]/e,h=n[2]/e,y=n[4]/t,o=n[5]/t,a=n[6]/t,c=n[8]/s,l=n[9]/s,m=n[10]/s,u=r+o+m,b;if(u>0){let d=Math.sqrt(u+1)*2;b=[(a-l)/d,(c-h)/d,(i-y)/d,.25*d]}else if(r>o&&r>m){let d=Math.sqrt(1+r-o-m)*2;b=[.25*d,(y+i)/d,(c+h)/d,(a-l)/d]}else if(o>m){let d=Math.sqrt(1+o-r-m)*2;b=[(y+i)/d,.25*d,(l+a)/d,(c-h)/d]}else{let d=Math.sqrt(1+m-r-o)*2;b=[(c+h)/d,(l+a)/d,.25*d,(i-y)/d]}return yn(b)}function re(n,e,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),b=2*(r*i+s*h),d=1-2*(s*s+r*r);for(let f=0;f<3;f++){let T=e[f*4],x=e[f*4+1],M=e[f*4+2];n[f*4]=y*T+o*x+a*M,n[f*4+1]=c*T+l*x+m*M,n[f*4+2]=u*T+b*x+d*M}}function nn(n,e){let t=e[0]-n[0],s=e[1]-n[1],r=e[2]-n[2],i=Math.hypot(t,s,r);return i>1e-9?[t/i,s/i,r/i]:null}function Cn(n){n?.normalMatrix&&n?.transform&&Z(n.normalMatrix,n.transform)}var Ln=new WeakMap;function oe(n){let e=Ln.get(n);return e||(e=new Int32Array(n.nodes.length).fill(-1),n.nodes.forEach((t,s)=>{for(let r of Array.isArray(t?.children)?t.children:[])typeof r=="number"&&r>=0&&r<e.length&&(e[r]=s)}),Ln.set(n,e)),e}function se(n,e,t){let s=n?.gltf,r=s?.nodes;if(!Array.isArray(r)||r.length===0)return!1;let i=new Map;r.forEach((p,g)=>{typeof p?.name=="string"&&p.name&&!i.has(p.name)&&i.set(p.name,g)});let y=(e.mid?[e.root,e.mid,e.effector]:[e.root,e.effector]).map(p=>i.get(p));if(y.some(p=>p===void 0))return!1;let o=y,a=oe(s);for(let p=1;p<o.length;p++){let g=a[o[p]],I=0;for(;g>=0&&g!==o[p-1]&&I++<256;)g=a[g];if(g!==o[p-1])return!1}let c=o[0],l=n.initialNodeTransforms,m=new Map,u=[],b=[c];for(;b.length&&u.length<4096;){let p=b.pop();if(m.has(p))continue;let g=l?.[p],I=r[p];m.set(p,{t:g?[g.t[0],g.t[1],g.t[2]]:I?.translation?[...I.translation]:[0,0,0],r:g?[g.r[0],g.r[1],g.r[2],g.r[3]]:I?.rotation?[...I.rotation]:[0,0,0,1],s:g?[g.s[0],g.s[1],g.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"&&b.push(V)}let d=a[c],f=d>=0&&n.worldMatrices?.[d]?.length===16?Float32Array.from(n.worldMatrices[d]):N(),T=new Map,x=()=>{let p=(g,I)=>{let V=m.get(g);if(!V)return;let w=N();J(w,V.r,V.t,V.s);let S=N();an(S,I,w),T.set(g,S);for(let E of Array.isArray(r[g]?.children)?r[g].children:[])typeof E=="number"&&p(E,S)};p(c,f)},M=p=>{let g=T.get(p);return[g[12],g[13],g[14]]};x();let A=o.map(M),F=p=>{if(typeof p=="string"&&!t.has(p)){let g=i.get(p),I=g!==void 0?T.get(g)??n.worldMatrices?.[g]:void 0;if(I&&I.length===16)return[I[12],I[13],I[14]]}return fn(p,t,n)},R=F(e.target);if(!R)return!0;let _=e.pole?F(e.pole)??void 0:void 0,v=Pn(A,e,R,_),k=Nn(e.weight,0,1,1);for(let p=0;p<o.length-1;p++){let g=nn(M(o[p]),M(o[p+1])),I=nn(v[p],v[p+1]);if(!g||!I)continue;let V=ee(en(g,I),k),w=o[p],S=a[w],E=S===d||S<0?f:T.get(S)??f,B=te(E),C=m.get(w);C.r=yn(un(ne(B),un(V,un(B,C.r)))),x()}if(Array.isArray(n.worldMatrices))for(let[p,g]of T)n.worldMatrices[p]?.set&&n.worldMatrices[p].set(g);for(let p of n.meshes??[]){let g=T.get(p?.nodeIndex);g&&p.transform?.set&&(p.transform.set(g),Cn(p))}return!0}function Pn(n,e,t,s){if(e.solver==="two-bone"&&n.length===3){let r=dn(n[0],n[1],n[2],t,s);return[n[0],r.midPos,r.effectorPos]}return hn(n,t,e.iterations,e.tolerance).positions}function ie(n,e,t){let s=n.__ikRestOffsets,r=n.__ikRestMats;if(!(!s||!r))for(let i=0;i<e.length-1;i++){let h=e[i]?.transform??e[i]?.modelMatrix,y=r[i],o=nn([0,0,0],s[i]),a=nn(t[i],t[i+1]);!h||h.length<16||!y||y.length<16||!o||!a||(re(h,y,en(o,a)),Cn(e[i]))}}var pn={name:"ik",onRegister(){let n=Q();_n(ln),ln(n.threeNamespace,n)},onUpdate(n){let e=n?.meshes;if(!Array.isArray(e)||e.length===0)return;let t=null;for(let s of e){let r=s?.userData?.xr?.ik??s?.extras?.xr?.ik??s?.extensions?.ANDROID_xr_scenecore?.ik;if(!r)continue;let i=Hn(r);if(!i||i.weight<=0)continue;if(!t){t=new Map;for(let A of e)A&&typeof A.name=="string"&&A.name&&t.set(A.name,A)}if(se(n,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||cn(s,i.root),y||cn(s,i.effector),i.mid&&!o&&cn(s,i.mid),!h||!y)continue;let a=fn(i.target,t,n);if(!a)continue;let c=i.pole?fn(i.pole,t,n)??void 0:void 0,l=o?[h,o,y]:[h,y],m=l.map(A=>A.name||"").join(">");if(!s.__ikRestOffsets||s.__ikRestKey!==m){let A=l.map(mn),F=[];for(let R=0;R<A.length-1;R++)F.push([A[R+1][0]-A[R][0],A[R+1][1]-A[R][1],A[R+1][2]-A[R][2]]);s.__ikRestOffsets=F,s.__ikRestKey=m,s.__ikRestMats=l.map(R=>Array.from(R.transform??R.modelMatrix??[]))}let u=s.__ikRestOffsets,d=[mn(h)],f=[];for(let A=0;A<u.length;A++){let F=d[A],R=u[A];d.push([F[0]+R[0],F[1]+R[1],F[2]+R[2]]),f.push(Math.hypot(R[0],R[1],R[2]))}let T=Pn(d,i,a,c),x=d[0],M=[d[0]];for(let A=1;A<l.length;A++){let F=u[A-1],R=[x[0]+F[0],x[1]+F[1],x[2]+F[2]],_=[x[0]+(T[A][0]-T[A-1][0]),x[1]+(T[A][1]-T[A-1][1]),x[2]+(T[A][2]-T[A-1][2])],v=Yn(x,R,_,f[A-1],i.weight);qn(l[A],v),x=v,M.push(v)}ie(s,l,M)}}};var ae={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function W(n,e,t,s){if(!t||t.bufferView===void 0)return null;let r=n.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=ae[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>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(h===5126&&a===o&&c%4===0)return new Float32Array(e,c,i*s);let l=new DataView(e),m=t.normalized===!0,u=new Float32Array(i*s);for(let b=0;b<i;b++){let d=c+b*a;for(let f=0;f<s;f++){let T=d+f*y,x;switch(h){case 5126:x=l.getFloat32(T,!0);break;case 5120:x=l.getInt8(T),m&&(x=Math.max(x/127,-1));break;case 5121:x=l.getUint8(T),m&&(x/=255);break;case 5122:x=l.getInt16(T,!0),m&&(x=Math.max(x/32767,-1));break;case 5123:x=l.getUint16(T,!0),m&&(x/=65535);break;default:x=l.getUint32(T,!0),m&&(x/=4294967295)}u[b*s+f]=x}}return u}function Kn(n,e,t){return e%4===0?new Float32Array(n,e,t):new Float32Array(n.slice(e,e+t*4))}function Wn(n,e,t,s){let r=e[0],i=e[1],h=e[2],y=e[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 n[0]=r,n[1]=i,n[2]=h,n[3]=y,n;let u=Math.acos(m),b=Math.sqrt(1-m*m);if(Math.abs(b)<.001)return n[0]=.5*(r+o),n[1]=.5*(i+a),n[2]=.5*(h+c),n[3]=.5*(y+l),n;let d=Math.sin((1-s)*u)/b,f=Math.sin(s*u)/b;return n[0]=r*d+o*f,n[1]=i*d+a*f,n[2]=h*d+c*f,n[3]=y*d+l*f,n}function On(n,e,t,s){return n[0]=e[0]+s*(t[0]-e[0]),n[1]=e[1]+s*(t[1]-e[1]),n[2]=e[2]+s*(t[2]-e[2]),n}function gn(n,e){if(!Array.isArray(n?.animations))return[];let t=[];for(let s=0;s<n.animations.length;s++){let r=n.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=n.accessors?.[a.input],l=n.accessors?.[a.output];if(!c||!l)continue;let m=n.bufferViews?.[c.bufferView],u=n.bufferViews?.[l.bufferView];if(!m||!u)continue;let b=(m.byteOffset||0)+(c.byteOffset||0),d=(u.byteOffset||0)+(l.byteOffset||0),f=W(n,e,c,1)??Kn(e,b,c.count);f.length>0&&f[f.length-1]>y&&(y=f[f.length-1]);let T=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(l.count/Math.max(1,c.count))):3,x=o.target.path==="weights"?1:T,M=W(n,e,l,x)??Kn(e,d,l.count*x),A=a.interpolation==="STEP"?"STEP":"LINEAR";h.push({nodeIndex:o.target.node,path:o.target.path,times:f,values:M,interpolation:A})}h.length>0&&t.push({name:i,duration:y,channels:h})}return t}function U(n,e,t){let{times:s,values:r,path:i,interpolation:h}=n,y=s.length;if(y===0)return;let o=i==="rotation"?4:i==="weights"?Math.max(1,Math.round(r.length/y)):3;if(e<=s[0]){for(let x=0;x<o;x++)t[x]=r[x];return}if(e>=s[y-1]){let x=(y-1)*o;for(let M=0;M<o;M++)t[M]=r[x+M];return}let a=0,c=y-1;for(;a<=c;){let x=a+c>>1;s[x]<=e?a=x+1:c=x-1}let l=Math.max(0,c),m=Math.min(y-1,l+1);if(h==="STEP"||l===m){let x=l*o;for(let M=0;M<o;M++)t[M]=r[x+M];return}let u=s[l],b=s[m],d=(e-u)/Math.max(1e-5,b-u),f=l*o,T=m*o;if(i==="rotation"){let x=[r[f],r[f+1],r[f+2],r[f+3]],M=[r[T],r[T+1],r[T+2],r[T+3]];Wn(t,x,M,d)}else for(let x=0;x<o;x++)t[x]=r[f+x]+d*(r[T+x]-r[f+x])}var tn=new WeakMap;function An(n,e,t=.3){if(!n?.animations)return;let s=n.animations.find(y=>y.name===e);if(!s)return;let r=tn.get(n);r||(r=[],n.currentClip&&r.push({clip:n.currentClip,time:n.animationTime||0,weight:1,fadeSpeed:0}),tn.set(n,r));let i=t>0?1/t:1e3;for(let y of r)y.clip.name!==e&&(y.fadeSpeed=-i);let h=r.find(y=>y.clip.name===e);h?h.fadeSpeed=i:r.push({clip:s,time:0,weight:t>0?0:1,fadeSpeed:i}),n.currentClip=s,n.isPlayingAnimation=!0}function bn(n,e){if(!n.gltf||!Array.isArray(n.gltf.nodes))return;let t=tn.get(n);if(!t||t.length===0){if(!n.currentClip)return;t=[{clip:n.currentClip,time:e,weight:1,fadeSpeed:0}]}let s=n.gltf.nodes.length,r=[];for(let l=0;l<s;l++){let m=n.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 b=r[u.nodeIndex];if(u.path==="translation")U(u,l.time,i),On(b.t,b.t,i,m);else if(u.path==="rotation")U(u,l.time,h),Wn(b.r,b.r,h,m);else if(u.path==="scale")U(u,l.time,y),On(b.s,b.s,y,m);else if(u.path==="weights"&&(U(u,l.time,o),n.meshes)){for(let d of n.meshes)if(d.nodeIndex===u.nodeIndex){for(let f of d.primitives)if(f.pluginData?.morph?.weights){let T=f.pluginData.morph.weights,x=f.pluginData.morph.numTargets||T.length;for(let M=0;M<x;M++)T[M]=T[M]*(1-m)+o[M]*m}}}}}let a=[];for(let l=0;l<s;l++){let m=N(),{t:u,r:b,s:d}=r[l];J(m,b,u,d),a.push(m)}let c=En(n.gltf,a);n.worldMatrices=c;for(let l of n.meshes)l.nodeIndex>=0&&l.nodeIndex<c.length&&(l.transform.set(c[l.nodeIndex]),Z(l.normalMatrix,l.transform))}var Tn={name:"keyframes",evaluateAnimation:bn,crossFadeTo:An,onParseGLB(n){!n.animations&&n.gltf?.animations&&(n.animations=gn(n.gltf,n.bin))},onUpdate(n,e){if(!n.isPlayingAnimation)return;let t=tn.get(n);if(t&&t.length>0){for(let s=t.length-1;s>=0;s--){let r=t[s];if(r.time+=e,r.clip.duration>0&&(r.time%=r.clip.duration),r.fadeSpeed!==0)if(r.weight+=r.fadeSpeed*e,r.weight<=0){t.splice(s,1);continue}else r.weight>=1&&(r.weight=1,r.fadeSpeed=0)}t.length>0&&(n.animationTime=t[t.length-1].time),bn(n,n.animationTime)}else n.currentClip&&(n.animationTime+=e,n.currentClip.duration>0&&(n.animationTime%=n.currentClip.duration),bn(n,n.animationTime))}};var $=64;function zn(n,e,t){if(!(!n?.meshes||e<0||e>=$))for(let s of n.meshes)for(let r of s.primitives){let i=r.pluginData?.morph;i?.weights&&(i.weights[e]=t)}}var xn={name:"morph",onResolveShader(n,e,t,s){if(!Array.isArray(n?.targets)||n.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(n,e,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 b=i[u].POSITION;if(b===void 0)continue;let d=s.accessors?.[b],f=s.bufferViews?.[d?.bufferView];if(!d||!f)continue;let T=W(s,r,d,3);if(!T||T.length<o*3)continue;let x=u*o*4;for(let M=0;M<o;M++)c[x+M*4]=T[M*3],c[x+M*4+1]=T[M*3+1],c[x+M*4+2]=T[M*3+2],c[x+M*4+3]=0}let l=n.createTexture();n.bindTexture(3553,l),n.texImage2D(3553,0,34836,o,a,0,6408,5126,c),n.texParameteri(3553,10242,33071),n.texParameteri(3553,10243,33071),n.texParameteri(3553,10241,9728),n.texParameteri(3553,10240,9728);let m=new Float32Array($);return{hasMorph:!0,morphTex:l,numTargets:a,vertexCount:o,weights:m}},onBeforeDrawPrimitive(n,e,t,s,r,i){let h=t.pluginData?.morph;if(!h?.hasMorph||!h.morphTex)return;n.activeTexture(33989),n.bindTexture(3553,h.morphTex);let y=n.getUniformLocation(e,"uMorphDeltasTex");y&&n.uniform1i(y,5);let o=n.getUniformLocation(e,"uNumMorphTargets");o&&n.uniform1i(o,h.numTargets);let a=n.getUniformLocation(e,"uMorphWeights[0]");a&&n.uniform1fv(a,h.weights)}};var Mn=64,wn={name:"skinning",onResolveShader(n,e,t,s){if(n?.attributes?.JOINTS_0===void 0||n?.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[${Mn}];`),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(n,e,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=n.createBuffer();n.bindBuffer(34962,m);let u=h.componentType===5121?5121:5123,b=u===5121?new Uint8Array(r,c,h.count*4):new Uint16Array(r,c,h.count*4);n.bufferData(34962,b,35044),n.enableVertexAttribArray(4),n.vertexAttribIPointer(4,4,u,0,0);let d=n.createBuffer();n.bindBuffer(34962,d);let f=W(s,r,y,4)??new Float32Array(r,l,y.count*4);return n.bufferData(34962,f,35044),n.enableVertexAttribArray(5),n.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,d]}},onBeforeDrawPrimitive(n,e,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(Mn*16);for(let l=0;l<o.length&&l<Mn;l++){let m=o[l],u=r[m]||N();a.subarray(l*16,(l+1)*16).set(u)}let c=n.getUniformLocation(e,"uJointMatrix[0]");c&&n.uniformMatrix4fv(c,!1,a)}};X(xn);X(Tn);X(wn);X(pn);return $n(ce);})();
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)})();