three-live 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +22 -0
  3. package/dist/three-author-engine.js +31 -29
  4. package/dist/three-author.cjs +29 -27
  5. package/dist/three-author.d.ts +22 -0
  6. package/dist/three-author.js +30 -28
  7. package/dist/three-convert.cjs +21 -19
  8. package/dist/three-convert.d.ts +22 -0
  9. package/dist/three-convert.js +21 -19
  10. package/dist/three-live-animation.cjs +4 -4
  11. package/dist/three-live-animation.d.ts +22 -0
  12. package/dist/three-live-animation.js +4 -4
  13. package/dist/three-live-animation.min.js +4 -4
  14. package/dist/three-live-cad.cjs +2 -2
  15. package/dist/three-live-cad.d.ts +22 -0
  16. package/dist/three-live-cad.js +2 -2
  17. package/dist/three-live-cad.min.js +2 -2
  18. package/dist/three-live-element.cjs +5 -3
  19. package/dist/three-live-element.d.ts +22 -0
  20. package/dist/three-live-element.js +5 -3
  21. package/dist/three-live-full.cjs +44 -42
  22. package/dist/three-live-full.js +40 -38
  23. package/dist/three-live-full.min.js +44 -42
  24. package/dist/three-live-studio.cjs +15 -15
  25. package/dist/three-live-studio.d.ts +22 -0
  26. package/dist/three-live-studio.js +13 -13
  27. package/dist/three-live-studio.min.js +15 -15
  28. package/dist/three-live-viewer.cjs +5 -3
  29. package/dist/three-live-viewer.d.ts +22 -0
  30. package/dist/three-live-viewer.js +5 -3
  31. package/dist/three-live-viewer.min.js +5 -3
  32. package/dist/three-live.cjs +22 -20
  33. package/dist/three-live.js +22 -20
  34. package/dist/three-live.min.js +22 -20
  35. package/dist/three-view.cjs +8 -6
  36. package/dist/three-view.d.ts +22 -0
  37. package/dist/three-view.js +8 -6
  38. package/dist/three-xr.cjs +24 -22
  39. package/dist/three-xr.d.ts +22 -0
  40. package/dist/three-xr.js +24 -22
  41. package/package.json +1 -1
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
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;
17
+ "use strict";var se=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var je=Object.prototype.hasOwnProperty;var Qe=(e,n)=>{for(var t in n)se(e,t,{get:n[t],enumerable:!0})},Xe=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of De(n))!je.call(e,r)&&r!==t&&se(e,r,{get:()=>n[r],enumerable:!(s=Ue(n,r))||s.enumerable});return e};var Je=e=>Xe(se({},"__esModule",{value:!0}),e);var cn={};Qe(cn,{IKSolver:()=>Ne,crossFadeTo:()=>ge,ikPlugin:()=>ye,keyframeAnimationPlugin:()=>Ae,morphPlugin:()=>Te,parseAnimations:()=>be,quatFromUnitVectors:()=>ne,sampleChannel:()=>U,setMorphTargetWeight:()=>We,skinningPlugin:()=>Me,solveFABRIK:()=>de,solveTwoBoneIK:()=>fe});module.exports=Je(cn);var Y="__THREE_LIVE_REGISTRY__";function Q(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Y]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,Y,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[Y]=n}}return e[Y]}var ln=Q().plugins;function Se(e){let n=Q();n.workerExtensionInstallers||(n.workerExtensionInstallers=[]),n.workerExtensionInstallers.includes(e)||n.workerExtensionInstallers.push(e)}function X(e){let n=Q().plugins;n.some(t=>t.name===e.name)||n.push(e),e.onRegister?.()}function N(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function ie(e,n,t){let s=n[0],r=n[1],i=n[2],h=n[3],y=n[4],o=n[5],a=n[6],c=n[7],l=n[8],m=n[9],u=n[10],M=n[11],f=n[12],d=n[13],A=n[14],T=n[15],x=t[0],g=t[1],F=t[2],R=t[3];return e[0]=x*s+g*y+F*l+R*f,e[1]=x*r+g*o+F*m+R*d,e[2]=x*i+g*a+F*u+R*A,e[3]=x*h+g*c+F*M+R*T,x=t[4],g=t[5],F=t[6],R=t[7],e[4]=x*s+g*y+F*l+R*f,e[5]=x*r+g*o+F*m+R*d,e[6]=x*i+g*a+F*u+R*A,e[7]=x*h+g*c+F*M+R*T,x=t[8],g=t[9],F=t[10],R=t[11],e[8]=x*s+g*y+F*l+R*f,e[9]=x*r+g*o+F*m+R*d,e[10]=x*i+g*a+F*u+R*A,e[11]=x*h+g*c+F*M+R*T,x=t[12],g=t[13],F=t[14],R=t[15],e[12]=x*s+g*y+F*l+R*f,e[13]=x*r+g*o+F*m+R*d,e[14]=x*i+g*a+F*u+R*A,e[15]=x*h+g*c+F*M+R*T,e}function J(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=r+r,a=i+i,c=h+h,l=r*o,m=r*a,u=r*c,M=i*a,f=i*c,d=h*c,A=y*o,T=y*a,x=y*c,g=s[0],F=s[1],R=s[2];return e[0]=(1-(M+d))*g,e[1]=(m+x)*g,e[2]=(u-T)*g,e[3]=0,e[4]=(m-x)*F,e[5]=(1-(l+d))*F,e[6]=(f+A)*F,e[7]=0,e[8]=(u+T)*R,e[9]=(f-A)*R,e[10]=(1-(l+M))*R,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function Z(e,n,t=0){let s=n[0],r=n[1],i=n[2],h=n[4],y=n[5],o=n[6],a=n[8],c=n[9],l=n[10],m=l*y-o*c,u=-l*h+o*a,M=c*h-y*a,f=s*m+r*u+i*M;return!f||t>0&&(!Number.isFinite(f)||Math.abs(f)<=t)||(f=1/f,e[0]=m*f,e[1]=u*f,e[2]=M*f,e[3]=(-l*r+i*c)*f,e[4]=(l*s-i*a)*f,e[5]=(-c*s+r*a)*f,e[6]=(o*r-i*y)*f,e[7]=(-o*s+i*h)*f,e[8]=(y*s-r*h)*f),e}function ke(e,n){let t=n[0],s=n[1],r=n[2],i=n[3],h=n[4],y=n[5],o=n[6],a=n[7],c=n[8],l=n[9],m=n[10],u=n[11],M=n[12],f=n[13],d=n[14],A=n[15],T=t*y-s*h,x=t*o-r*h,g=t*a-i*h,F=s*o-r*y,R=s*a-i*y,k=r*a-i*o,v=c*f-l*M,_=c*d-m*M,p=c*A-u*M,b=l*d-m*f,I=l*A-u*f,V=m*A-u*d,w=T*V-x*I+g*b+F*p-R*_+k*v;return w?(w=1/w,e[0]=(y*V-o*I+a*b)*w,e[1]=(r*I-s*V-i*b)*w,e[2]=(f*k-d*R+A*F)*w,e[3]=(m*R-l*k-u*F)*w,e[4]=(o*p-h*V-a*_)*w,e[5]=(t*V-r*p+i*_)*w,e[6]=(d*g-M*k-A*x)*w,e[7]=(c*k-m*g+u*x)*w,e[8]=(h*I-y*p+a*v)*w,e[9]=(s*p-t*I-i*v)*w,e[10]=(M*R-f*g+A*T)*w,e[11]=(l*g-c*R-u*T)*w,e[12]=(y*_-h*b-o*v)*w,e[13]=(t*b-s*_+r*v)*w,e[14]=(f*x-M*F-d*T)*w,e[15]=(c*F-l*x+m*T)*w,e):null}function _e(e,n){let t=Array.isArray(e?.nodes)?e.nodes.length:0,s=[];for(let c=0;c<t;c++)s.push(N());if(t===0)return s;let r=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let l of c.children)r.add(l);let i=new Set,h=128,y=(c,l,m=0)=>{if(m>h||c<0||c>=t||i.has(c))return;i.add(c);let u=e.nodes[c];if(!u)return;let M=N();if(n&&n[c])M.set(n[c]);else if(u.matrix&&u.matrix.length===16)M.set(u.matrix);else{let d=u.translation||[0,0,0],A=u.rotation||[0,0,0,1],T=u.scale||[1,1,1];J(M,A,d,T)}let f=s[c];if(l?ie(f,l,M):f.set(M),Array.isArray(u.children))for(let d of u.children)typeof d=="number"&&y(d,f,m+1)},o=[],a=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(a&&Array.isArray(a.nodes))o.push(...a.nodes);else for(let c=0;c<t;c++)r.has(c)||o.push(c);for(let c of o)y(c,null);for(let c=0;c<t;c++)!r.has(c)&&!o.includes(c)&&y(c,null);return s}function ue(e,n){function t(o,a,c,l){let m=typeof o=="number"?o:Number(o);return Number.isFinite(m)?Math.max(a,Math.min(c,m)):l}function s(o,a){let l=o[0]*a[0]+o[1]*a[1]+o[2]*a[2]+1;if(l<1e-6){if(Math.abs(o[0])>Math.abs(o[2])){let A=Math.hypot(o[1],o[0])||1;return[-o[1]/A,o[0]/A,0,0]}let d=Math.hypot(o[2],o[1])||1;return[0,-o[2]/d,o[1]/d,0]}let m=o[1]*a[2]-o[2]*a[1],u=o[2]*a[0]-o[0]*a[2],M=o[0]*a[1]-o[1]*a[0],f=Math.hypot(m,u,M,l)||1;return[m/f,u/f,M/f,l/f]}function r(o,a,c,l,m){let u=a[0]-o[0],M=a[1]-o[1],f=a[2]-o[2],d=Math.hypot(u,M,f),A=c[0]-a[0],T=c[1]-a[1],x=c[2]-a[2],g=Math.hypot(A,T,x);if(d<1e-6||g<1e-6)return{rootPos:[o[0],o[1],o[2]],midPos:[a[0],a[1],a[2]],effectorPos:[c[0],c[1],c[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let F=[u/d,M/d,f/d],R=[A/g,T/g,x/g],k=l[0]-o[0],v=l[1]-o[1],_=l[2]-o[2],p=Math.hypot(k,v,_),b=p>1e-6?[k/p,v/p,_/p]:F,I=Math.abs(d-g)+1e-5,V=Math.max(I,d+g-1e-5),w=Math.max(I,Math.min(V,p>1e-6?p:I)),S=t((d*d+w*w-g*g)/(2*d*w),-1,1,1),E=Math.sqrt(Math.max(0,1-S*S)),B=m?m[0]-o[0]:u,C=m?m[1]-o[1]:M,D=m?m[2]-o[2]:f,z=B*b[0]+C*b[1]+D*b[2],K=B-b[0]*z,O=C-b[1]*z,P=D-b[2]*z,j=Math.hypot(K,O,P);if(j<=1e-6){let Ie=Math.abs(b[1])<.99?0:1,Ve=Math.abs(b[1])<.99?1:0,ve=0;K=b[1]*ve-b[2]*Ve,O=b[2]*Ie-b[0]*ve,P=b[0]*Ve-b[1]*Ie,j=Math.hypot(K,O,P)||1}let re=[K/j,O/j,P/j],L=[o[0]+b[0]*(d*S)+re[0]*(d*E),o[1]+b[1]*(d*S)+re[1]*(d*E),o[2]+b[2]*(d*S)+re[2]*(d*E)],oe=[o[0]+b[0]*w,o[1]+b[1]*w,o[2]+b[2]*w],we=oe[0]-L[0],Re=oe[1]-L[1],Fe=oe[2]-L[2],H=Math.hypot(we,Re,Fe),q=H>1e-6?[we/H,Re/H,Fe/H]:b,ze=[L[0]+q[0]*g,L[1]+q[1]*g,L[2]+q[2]*g],Ge=[(L[0]-o[0])/d,(L[1]-o[1])/d,(L[2]-o[2])/d];return{rootPos:[o[0],o[1],o[2]],midPos:L,effectorPos:ze,rootRotation:s(F,Ge),midRotation:s(R,q)}}function i(o,a,c=8,l=.001){let m=o.length;if(m<2)return{positions:o.map(p=>[p[0],p[1],p[2]]),rotations:[],iterations:0};let u=o.map(p=>[p[0],p[1],p[2]]),M=[],f=[],d=0;for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V);M.push(w),d+=w,f.push(w>1e-6?[b/w,I/w,V/w]:[0,1,0])}let A=[u[0][0],u[0][1],u[0][2]],T=Math.round(t(c,1,32,8)),x=t(l,1e-5,.1,.001),g=a[0]-A[0],F=a[1]-A[1],R=a[2]-A[2],k=Math.hypot(g,F,R),v=0;if(k>=d&&d>1e-6){let p=k>1e-6?[g/k,F/k,R/k]:f[0];u[0]=[A[0],A[1],A[2]];for(let b=0;b<m-1;b++){let I=M[b];u[b+1]=[u[b][0]+p[0]*I,u[b][1]+p[1]*I,u[b][2]+p[2]*I]}v=1}else for(let p=1;p<=T;p++){let b=u[m-1];if(Math.hypot(b[0]-a[0],b[1]-a[1],b[2]-a[2])<=x)break;v=p;let V=(w,S,E,B,C)=>{let D=S[0]-w[0],z=S[1]-w[1],K=S[2]-w[2],O=Math.hypot(D,z,K);if(O>1e-6){let P=E/O;return[w[0]+D*P,w[1]+z*P,w[2]+K*P]}return[w[0]+B[0]*E*C,w[1]+B[1]*E*C,w[2]+B[2]*E*C]};u[m-1]=[a[0],a[1],a[2]];for(let w=m-2;w>=0;w--)u[w]=V(u[w+1],u[w],M[w],f[w],-1);u[0]=[A[0],A[1],A[2]];for(let w=0;w<m-1;w++)u[w+1]=V(u[w],u[w+1],M[w],f[w],1)}let _=[];for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V),S=w>1e-6?[b/w,I/w,V/w]:f[p];_.push(s(f[p],S))}return{positions:u,rotations:_,iterations:v}}function h(o){if(!o||typeof o!="object"||Array.isArray(o))return null;let a=o;if(a.enabled===!1)return null;let c=x=>{if(typeof x!="string")return;let g=x.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(g)?g:void 0},l=x=>Array.isArray(x)&&x.length===3&&x.every(g=>typeof g=="number"&&Number.isFinite(g))?[t(x[0],-1e3,1e3,0),t(x[1],-1e3,1e3,0),t(x[2],-1e3,1e3,0)]:void 0,m=c(a.root),u=c(a.effector);if(!m||!u)return null;let M=c(a.mid),f=l(a.target)??c(a.target);if(!f)return null;let d=a.pole??a.poleTarget,A=l(d)??c(d),T=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||M?"two-bone":"fabrik";return{root:m,...M?{mid:M}:{},effector:u,target:f,...A?{pole:A}:{},solver:T,iterations:Math.round(t(a.iterations,1,32,8)),tolerance:t(a.tolerance,1e-5,.1,.001),weight:t(a.weight,0,1,1)}}let y=Object.freeze({solveTwoBone:r,solveFABRIK:i,parseIKTrait:h});return n&&typeof n=="object"&&(n.authorNamespace=n.authorNamespace||{},n.authorNamespace.IKSolver=y),{clampNum:t,parseIKTrait:h,quatFromUnitVectors:s,solveTwoBoneIK:r,solveFABRIK:i,IKSolver:y}}var G=ue(),Le=G.clampNum,$e=G.parseIKTrait,ne=G.quatFromUnitVectors,fe=G.solveTwoBoneIK,de=G.solveFABRIK,Ne=G.IKSolver;function le(e){let n=e?.transform??e?.modelMatrix;return n&&n.length>=16?[n[12]||0,n[13]||0,n[14]||0]:[0,0,0]}function He(e,n){let t=e?.transform??e?.modelMatrix;!t||t.length<16||(t[12]=n[0],t[13]=n[1],t[14]=n[2])}function qe(e,n,t,s,r){let i=Le(r,0,1,1),h=n[0]+(t[0]-n[0])*i,y=n[1]+(t[1]-n[1])*i,o=n[2]+(t[2]-n[2])*i,a=h-e[0],c=y-e[1],l=o-e[2],m=Math.hypot(a,c,l);if(m>1e-6&&s>1e-6){let A=s/m;return[e[0]+a*A,e[1]+c*A,e[2]+l*A]}let u=t[0]-e[0],M=t[1]-e[1],f=t[2]-e[2],d=Math.hypot(u,M,f);if(d>1e-6&&s>1e-6){let A=s/d;return[e[0]+u*A,e[1]+M*A,e[2]+f*A]}return[h,y,o]}function Ye(e,n){let t=e?.modelRootMatrix;if(!t||t.length!==16)return n;let s=new Float32Array(16);return ke(s,t instanceof Float32Array?t:Float32Array.from(t))?[s[0]*n[0]+s[4]*n[1]+s[8]*n[2]+s[12],s[1]*n[0]+s[5]*n[1]+s[9]*n[2]+s[13],s[2]*n[0]+s[6]*n[1]+s[10]*n[2]+s[14]]:n}function ae(e,n){e.__ikWarned||(e.__ikWarned=new Set);let t=e.__ikWarned;t.has(n)||(t.add(n),console.warn(`[three-live] ik: joint '${n}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function me(e,n,t){if(Array.isArray(e))return[e[0],e[1],e[2]];let s=n.get(e);if(s)return le(s);let r;if(e==="head"?r=t?.headPose?.position??t?.headPose??t?.cameraPosition:e==="hand-left"?r=t?.handPoses?.left?.position??t?.handPoses?.left??t?.hands?.left?.position??t?.hands?.left:e==="hand-right"&&(r=t?.handPoses?.right?.position??t?.handPoses?.right??t?.hands?.right?.position??t?.hands?.right),(Array.isArray(r)||ArrayBuffer.isView(r))&&r.length>=3){let i=r;return Ye(t,[i[0],i[1],i[2]])}return null}function ce(e,n){return[e[3]*n[0]+e[0]*n[3]+e[1]*n[2]-e[2]*n[1],e[3]*n[1]-e[0]*n[2]+e[1]*n[3]+e[2]*n[0],e[3]*n[2]+e[0]*n[1]-e[1]*n[0]+e[2]*n[3],e[3]*n[3]-e[0]*n[0]-e[1]*n[1]-e[2]*n[2]]}function Ze(e){return[-e[0],-e[1],-e[2],e[3]]}function he(e){let n=Math.hypot(e[0],e[1],e[2],e[3]);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n,e[3]/n]:[0,0,0,1]}function en(e,n){if(n>=1)return e;if(n<=0)return[0,0,0,1];let[t,s,r,i]=e;i<0&&(t=-t,s=-s,r=-r,i=-i);let h=Math.acos(Math.min(1,i)),y=Math.sin(h);if(y<1e-9)return[0,0,0,1];let o=Math.sin(h*n)/y;return he([t*o,s*o,r*o,Math.cos(h*n)])}function nn(e){let n=Math.hypot(e[0],e[1],e[2])||1,t=Math.hypot(e[4],e[5],e[6])||1,s=Math.hypot(e[8],e[9],e[10])||1,r=e[0]/n,i=e[1]/n,h=e[2]/n,y=e[4]/t,o=e[5]/t,a=e[6]/t,c=e[8]/s,l=e[9]/s,m=e[10]/s,u=r+o+m,M;if(u>0){let f=Math.sqrt(u+1)*2;M=[(a-l)/f,(c-h)/f,(i-y)/f,.25*f]}else if(r>o&&r>m){let f=Math.sqrt(1+r-o-m)*2;M=[.25*f,(y+i)/f,(c+h)/f,(a-l)/f]}else if(o>m){let f=Math.sqrt(1+o-r-m)*2;M=[(y+i)/f,.25*f,(l+a)/f,(c-h)/f]}else{let f=Math.sqrt(1+m-r-o)*2;M=[(c+h)/f,(l+a)/f,.25*f,(i-y)/f]}return he(M)}function tn(e,n,t){let[s,r,i,h]=t,y=1-2*(r*r+i*i),o=2*(s*r-i*h),a=2*(s*i+r*h),c=2*(s*r+i*h),l=1-2*(s*s+i*i),m=2*(r*i-s*h),u=2*(s*i-r*h),M=2*(r*i+s*h),f=1-2*(s*s+r*r);for(let d=0;d<3;d++){let A=n[d*4],T=n[d*4+1],x=n[d*4+2];e[d*4]=y*A+o*T+a*x,e[d*4+1]=c*A+l*T+m*x,e[d*4+2]=u*A+M*T+f*x}}function ee(e,n){let t=n[0]-e[0],s=n[1]-e[1],r=n[2]-e[2],i=Math.hypot(t,s,r);return i>1e-9?[t/i,s/i,r/i]:null}function Be(e){e?.normalMatrix&&e?.transform&&Z(e.normalMatrix,e.transform)}var Ee=new WeakMap;function rn(e){let n=Ee.get(e);return n||(n=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((t,s)=>{for(let r of Array.isArray(t?.children)?t.children:[])typeof r=="number"&&r>=0&&r<n.length&&(n[r]=s)}),Ee.set(e,n)),n}function on(e,n,t){let s=e?.gltf,r=s?.nodes;if(!Array.isArray(r)||r.length===0)return!1;let i=new Map;r.forEach((p,b)=>{typeof p?.name=="string"&&p.name&&!i.has(p.name)&&i.set(p.name,b)});let y=(n.mid?[n.root,n.mid,n.effector]:[n.root,n.effector]).map(p=>i.get(p));if(y.some(p=>p===void 0))return!1;let o=y,a=rn(s);for(let p=1;p<o.length;p++){let b=a[o[p]],I=0;for(;b>=0&&b!==o[p-1]&&I++<256;)b=a[b];if(b!==o[p-1])return!1}let c=o[0],l=e.initialNodeTransforms,m=new Map,u=[],M=[c];for(;M.length&&u.length<4096;){let p=M.pop();if(m.has(p))continue;let b=l?.[p],I=r[p];m.set(p,{t:b?[b.t[0],b.t[1],b.t[2]]:I?.translation?[...I.translation]:[0,0,0],r:b?[b.r[0],b.r[1],b.r[2],b.r[3]]:I?.rotation?[...I.rotation]:[0,0,0,1],s:b?[b.s[0],b.s[1],b.s[2]]:I?.scale?[...I.scale]:[1,1,1]}),u.push(p);for(let V of Array.isArray(I?.children)?I.children:[])typeof V=="number"&&M.push(V)}let f=a[c],d=f>=0&&e.worldMatrices?.[f]?.length===16?Float32Array.from(e.worldMatrices[f]):N(),A=new Map,T=()=>{let p=(b,I)=>{let V=m.get(b);if(!V)return;let w=N();J(w,V.r,V.t,V.s);let S=N();ie(S,I,w),A.set(b,S);for(let E of Array.isArray(r[b]?.children)?r[b].children:[])typeof E=="number"&&p(E,S)};p(c,d)},x=p=>{let b=A.get(p);return[b[12],b[13],b[14]]};T();let g=o.map(x),F=p=>{if(typeof p=="string"&&!t.has(p)){let b=i.get(p),I=b!==void 0?A.get(b)??e.worldMatrices?.[b]:void 0;if(I&&I.length===16)return[I[12],I[13],I[14]]}return me(p,t,e)},R=F(n.target);if(!R)return!0;let k=n.pole?F(n.pole)??void 0:void 0,v=Ce(g,n,R,k),_=Le(n.weight,0,1,1);for(let p=0;p<o.length-1;p++){let b=ee(x(o[p]),x(o[p+1])),I=ee(v[p],v[p+1]);if(!b||!I)continue;let V=en(ne(b,I),_),w=o[p],S=a[w],E=S===f||S<0?d:A.get(S)??d,B=nn(E),C=m.get(w);C.r=he(ce(Ze(B),ce(V,ce(B,C.r)))),T()}if(Array.isArray(e.worldMatrices))for(let[p,b]of A)e.worldMatrices[p]?.set&&e.worldMatrices[p].set(b);for(let p of e.meshes??[]){let b=A.get(p?.nodeIndex);b&&p.transform?.set&&(p.transform.set(b),Be(p))}return!0}function Ce(e,n,t,s){if(n.solver==="two-bone"&&e.length===3){let r=fe(e[0],e[1],e[2],t,s);return[e[0],r.midPos,r.effectorPos]}return de(e,t,n.iterations,n.tolerance).positions}function sn(e,n,t){let s=e.__ikRestOffsets,r=e.__ikRestMats;if(!(!s||!r))for(let i=0;i<n.length-1;i++){let h=n[i]?.transform??n[i]?.modelMatrix,y=r[i],o=ee([0,0,0],s[i]),a=ee(t[i],t[i+1]);!h||h.length<16||!y||y.length<16||!o||!a||(tn(h,y,ne(o,a)),Be(n[i]))}}var ye={name:"ik",onRegister(){let e=Q();Se(ue),ue(e.threeNamespace,e)},onUpdate(e){let n=e?.meshes;if(!Array.isArray(n)||n.length===0)return;let t=null;for(let s of n){let r=s?.userData?.xr?.ik??s?.extras?.xr?.ik??s?.extensions?.ANDROID_xr_scenecore?.ik;if(!r)continue;let i=$e(r);if(!i||i.weight<=0)continue;if(!t){t=new Map;for(let g of n)g&&typeof g.name=="string"&&g.name&&t.set(g.name,g)}if(on(e,i,t))continue;let h=t.get(i.root),y=t.get(i.effector),o=i.mid?t.get(i.mid):void 0;if(h||ae(s,i.root),y||ae(s,i.effector),i.mid&&!o&&ae(s,i.mid),!h||!y)continue;let a=me(i.target,t,e);if(!a)continue;let c=i.pole?me(i.pole,t,e)??void 0:void 0,l=o?[h,o,y]:[h,y],m=l.map(g=>g.name||"").join(">");if(!s.__ikRestOffsets||s.__ikRestKey!==m){let g=l.map(le),F=[];for(let R=0;R<g.length-1;R++)F.push([g[R+1][0]-g[R][0],g[R+1][1]-g[R][1],g[R+1][2]-g[R][2]]);s.__ikRestOffsets=F,s.__ikRestKey=m,s.__ikRestMats=l.map(R=>Array.from(R.transform??R.modelMatrix??[]))}let u=s.__ikRestOffsets,f=[le(h)],d=[];for(let g=0;g<u.length;g++){let F=f[g],R=u[g];f.push([F[0]+R[0],F[1]+R[1],F[2]+R[2]]),d.push(Math.hypot(R[0],R[1],R[2]))}let A=Ce(f,i,a,c),T=f[0],x=[f[0]];for(let g=1;g<l.length;g++){let F=u[g-1],R=[T[0]+F[0],T[1]+F[1],T[2]+F[2]],k=[T[0]+(A[g][0]-A[g-1][0]),T[1]+(A[g][1]-A[g-1][1]),T[2]+(A[g][2]-A[g-1][2])],v=qe(T,R,k,d[g-1],i.weight);He(l[g],v),T=v,x.push(v)}sn(s,l,x)}}};var an={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function W(e,n,t,s){if(!t||t.bufferView===void 0)return null;let r=e.bufferViews?.[t.bufferView];if(!r)return null;let i=Number(t.count??0);if(!Number.isInteger(i)||i<=0)return null;let h=t.componentType??5126,y=an[h];if(!y)throw new RangeError(`glTF accessor has unsupported componentType ${h}`);let o=y*s,a=r.byteStride&&r.byteStride>0?r.byteStride:o,c=(r.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(c)||c<0||a<o||c+(i-1)*a+o>n.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${n.byteLength} bytes)`);if(h===5126&&a===o&&c%4===0)return new Float32Array(n,c,i*s);let l=new DataView(n),m=t.normalized===!0,u=new Float32Array(i*s);for(let M=0;M<i;M++){let f=c+M*a;for(let d=0;d<s;d++){let A=f+d*y,T;switch(h){case 5126:T=l.getFloat32(A,!0);break;case 5120:T=l.getInt8(A),m&&(T=Math.max(T/127,-1));break;case 5121:T=l.getUint8(A),m&&(T/=255);break;case 5122:T=l.getInt16(A,!0),m&&(T=Math.max(T/32767,-1));break;case 5123:T=l.getUint16(A,!0),m&&(T/=65535);break;default:T=l.getUint32(A,!0),m&&(T/=4294967295)}u[M*s+d]=T}}return u}function Pe(e,n,t){return n%4===0?new Float32Array(e,n,t):new Float32Array(e.slice(n,n+t*4))}function Oe(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=t[0],a=t[1],c=t[2],l=t[3],m=r*o+i*a+h*c+y*l;if(m<0&&(o=-o,a=-a,c=-c,l=-l,m=-m),Math.abs(m)>=1)return e[0]=r,e[1]=i,e[2]=h,e[3]=y,e;let u=Math.acos(m),M=Math.sqrt(1-m*m);if(Math.abs(M)<.001)return e[0]=.5*(r+o),e[1]=.5*(i+a),e[2]=.5*(h+c),e[3]=.5*(y+l),e;let f=Math.sin((1-s)*u)/M,d=Math.sin(s*u)/M;return e[0]=r*f+o*d,e[1]=i*f+a*d,e[2]=h*f+c*d,e[3]=y*f+l*d,e}function Ke(e,n,t,s){return e[0]=n[0]+s*(t[0]-n[0]),e[1]=n[1]+s*(t[1]-n[1]),e[2]=n[2]+s*(t[2]-n[2]),e}function be(e,n){if(!Array.isArray(e?.animations))return[];let t=[];for(let s=0;s<e.animations.length;s++){let r=e.animations[s],i=r.name||`Animation_${s}`,h=[],y=0;if(Array.isArray(r.channels)&&Array.isArray(r.samplers))for(let o of r.channels){if(!o.target||o.target.node===void 0||!o.target.path)continue;let a=r.samplers[o.sampler];if(!a)continue;let c=e.accessors?.[a.input],l=e.accessors?.[a.output];if(!c||!l)continue;let m=e.bufferViews?.[c.bufferView],u=e.bufferViews?.[l.bufferView];if(!m||!u)continue;let M=(m.byteOffset||0)+(c.byteOffset||0),f=(u.byteOffset||0)+(l.byteOffset||0),d=W(e,n,c,1)??Pe(n,M,c.count);d.length>0&&d[d.length-1]>y&&(y=d[d.length-1]);let A=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(l.count/Math.max(1,c.count))):3,T=o.target.path==="weights"?1:A,x=W(e,n,l,T)??Pe(n,f,l.count*T),g=a.interpolation==="STEP"?"STEP":"LINEAR";h.push({nodeIndex:o.target.node,path:o.target.path,times:d,values:x,interpolation:g})}h.length>0&&t.push({name:i,duration:y,channels:h})}return t}function U(e,n,t){let{times:s,values:r,path:i,interpolation:h}=e,y=s.length;if(y===0)return;let o=i==="rotation"?4:i==="weights"?Math.max(1,Math.round(r.length/y)):3;if(n<=s[0]){for(let T=0;T<o;T++)t[T]=r[T];return}if(n>=s[y-1]){let T=(y-1)*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let a=0,c=y-1;for(;a<=c;){let T=a+c>>1;s[T]<=n?a=T+1:c=T-1}let l=Math.max(0,c),m=Math.min(y-1,l+1);if(h==="STEP"||l===m){let T=l*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let u=s[l],M=s[m],f=(n-u)/Math.max(1e-5,M-u),d=l*o,A=m*o;if(i==="rotation"){let T=[r[d],r[d+1],r[d+2],r[d+3]],x=[r[A],r[A+1],r[A+2],r[A+3]];Oe(t,T,x,f)}else for(let T=0;T<o;T++)t[T]=r[d+T]+f*(r[A+T]-r[d+T])}var te=new WeakMap;function ge(e,n,t=.3){if(!e?.animations)return;let s=e.animations.find(y=>y.name===n);if(!s)return;let r=te.get(e);r||(r=[],e.currentClip&&r.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),te.set(e,r));let i=t>0?1/t:1e3;for(let y of r)y.clip.name!==n&&(y.fadeSpeed=-i);let h=r.find(y=>y.clip.name===n);h?h.fadeSpeed=i:r.push({clip:s,time:0,weight:t>0?0:1,fadeSpeed:i}),e.currentClip=s,e.isPlayingAnimation=!0}function pe(e,n){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let t=te.get(e);if(!t||t.length===0){if(!e.currentClip)return;t=[{clip:e.currentClip,time:n,weight:1,fadeSpeed:0}]}let s=e.gltf.nodes.length,r=[];for(let l=0;l<s;l++){let m=e.initialNodeTransforms[l];m?r.push({t:[m.t[0],m.t[1],m.t[2]],r:[m.r[0],m.r[1],m.r[2],m.r[3]],s:[m.s[0],m.s[1],m.s[2]]}):r.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let i=[0,0,0],h=[0,0,0,1],y=[1,1,1],o=new Float32Array(64);for(let l of t){let m=Math.max(0,Math.min(1,l.weight));if(!(m<=1e-4))for(let u of l.clip.channels){if(u.nodeIndex<0||u.nodeIndex>=s)continue;let M=r[u.nodeIndex];if(u.path==="translation")U(u,l.time,i),Ke(M.t,M.t,i,m);else if(u.path==="rotation")U(u,l.time,h),Oe(M.r,M.r,h,m);else if(u.path==="scale")U(u,l.time,y),Ke(M.s,M.s,y,m);else if(u.path==="weights"&&(U(u,l.time,o),e.meshes)){for(let f of e.meshes)if(f.nodeIndex===u.nodeIndex){for(let d of f.primitives)if(d.pluginData?.morph?.weights){let A=d.pluginData.morph.weights,T=d.pluginData.morph.numTargets||A.length;for(let x=0;x<T;x++)A[x]=A[x]*(1-m)+o[x]*m}}}}}let a=[];for(let l=0;l<s;l++){let m=N(),{t:u,r:M,s:f}=r[l];J(m,M,u,f),a.push(m)}let c=_e(e.gltf,a);e.worldMatrices=c;for(let l of e.meshes)l.nodeIndex>=0&&l.nodeIndex<c.length&&(l.transform.set(c[l.nodeIndex]),Z(l.normalMatrix,l.transform))}var Ae={name:"keyframes",evaluateAnimation:pe,crossFadeTo:ge,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=be(e.gltf,e.bin))},onUpdate(e,n){if(!e.isPlayingAnimation)return;let t=te.get(e);if(t&&t.length>0){for(let s=t.length-1;s>=0;s--){let r=t[s];if(r.time+=n,r.clip.duration>0&&(r.time%=r.clip.duration),r.fadeSpeed!==0)if(r.weight+=r.fadeSpeed*n,r.weight<=0){t.splice(s,1);continue}else r.weight>=1&&(r.weight=1,r.fadeSpeed=0)}t.length>0&&(e.animationTime=t[t.length-1].time),pe(e,e.animationTime)}else e.currentClip&&(e.animationTime+=n,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),pe(e,e.animationTime))}};var $=64;function We(e,n,t){if(!(!e?.meshes||n<0||n>=$))for(let s of e.meshes)for(let r of s.primitives){let i=r.pluginData?.morph;i?.weights&&(i.weights[n]=t)}}var Te={name:"morph",onResolveShader(e,n,t,s){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let r=t.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
18
18
  uniform sampler2D uMorphDeltasTex;
19
19
  uniform float uMorphWeights[${$}];
20
20
  uniform int uNumMorphTargets;`);return r=r.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
@@ -25,12 +25,12 @@ for (int m = 0; m < ${$}; m++) {
25
25
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
26
26
  }
27
27
  }
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;
28
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.targets;if(!Array.isArray(i)||i.length===0)return null;let h=t.attributes?.POSITION,y=s?.accessors?.[h];if(!y)return null;let o=y.count,a=Math.min(i.length,$),c=new Float32Array(o*a*4);for(let u=0;u<a;u++){let M=i[u].POSITION;if(M===void 0)continue;let f=s.accessors?.[M],d=s.bufferViews?.[f?.bufferView];if(!f||!d)continue;let A=W(s,r,f,3);if(!A||A.length<o*3)continue;let T=u*o*4;for(let x=0;x<o;x++)c[T+x*4]=A[x*3],c[T+x*4+1]=A[x*3+1],c[T+x*4+2]=A[x*3+2],c[T+x*4+3]=0}let l=e.createTexture();e.bindTexture(3553,l),e.texImage2D(3553,0,34836,o,a,0,6408,5126,c),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array($);return{hasMorph:!0,morphTex:l,numTargets:a,vertexCount:o,weights:m}},onBeforeDrawPrimitive(e,n,t,s,r,i){let h=t.pluginData?.morph;if(!h?.hasMorph||!h.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,h.morphTex);let y=e.getUniformLocation(n,"uMorphDeltasTex");y&&e.uniform1i(y,5);let o=e.getUniformLocation(n,"uNumMorphTargets");o&&e.uniform1i(o,h.numTargets);let a=e.getUniformLocation(n,"uMorphWeights[0]");a&&e.uniform1fv(a,h.weights)}};var xe=64,Me={name:"skinning",onResolveShader(e,n,t,s){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let r=t.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
29
29
  layout(location=4) in uvec4 aJoints;
30
30
  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 =
31
+ uniform mat4 uJointMatrix[${xe}];`),i=r.includes("morphedPos")?"morphedPos":"aPosition";return r=r.replace(`vec4 world=uModel*vec4(${i},1.0);`,`mat4 skinMatrix =
32
32
  aWeights.x * uJointMatrix[int(aJoints.x)] +
33
33
  aWeights.y * uJointMatrix[int(aJoints.y)] +
34
34
  aWeights.z * uJointMatrix[int(aJoints.z)] +
35
35
  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);
36
+ vec4 world=uModel*(skinMatrix*vec4(${i},1.0));`).replace(`gl_Position=uMVP*vec4(${i},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${i},1.0));`),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.attributes;if(!i||i.JOINTS_0===void 0||i.WEIGHTS_0===void 0)return null;let h=s.accessors[i.JOINTS_0],y=s.accessors[i.WEIGHTS_0];if(!h||!y)return null;let o=s.bufferViews[h.bufferView],a=s.bufferViews[y.bufferView];if(!o||!a)return null;let c=(o.byteOffset||0)+(h.byteOffset||0),l=(a.byteOffset||0)+(y.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let u=h.componentType===5121?5121:5123,M=u===5121?new Uint8Array(r,c,h.count*4):new Uint16Array(r,c,h.count*4);e.bufferData(34962,M,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,u,0,0);let f=e.createBuffer();e.bindBuffer(34962,f);let d=W(s,r,y,4)??new Float32Array(r,l,y.count*4);return e.bufferData(34962,d,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,f]}},onBeforeDrawPrimitive(e,n,t,s,r,i){if(!t.pluginData?.skinning?.hasSkin)return;let h=i?.nodes?.[s.nodeIndex]?.skin;if(h===void 0||!i.skins||!i.skins[h])return;let o=i.skins[h].joints||[],a=new Float32Array(xe*16);for(let l=0;l<o.length&&l<xe;l++){let m=o[l],u=r[m]||N();a.subarray(l*16,(l+1)*16).set(u)}let c=e.getUniformLocation(n,"uJointMatrix[0]");c&&e.uniformMatrix4fv(c,!1,a)}};X(Te);X(Ae);X(Me);X(ye);
@@ -169,6 +169,18 @@ export interface ThreeLiveAttributes {
169
169
  'shadow-softness'?: number | string;
170
170
  /** Tone mapping mode ("neutral", "aces", "agx", "reinhard", "none"). */
171
171
  'tone-mapping'?: string;
172
+ /** Dual-Kawase bloom intensity (0.0 to 5.0). */
173
+ 'bloom'?: number | string;
174
+ /** Luminance threshold for bloom extraction (default: 0.8). */
175
+ 'bloom-threshold'?: number | string;
176
+ /** Blur radius multiplier for bloom passes (default: 0.5). */
177
+ 'bloom-radius'?: number | string;
178
+ /** Declarative silhouette outline toggle or config. */
179
+ 'outline'?: boolean | string;
180
+ /** Highlight the currently `selected-mesh` with a silhouette outline. */
181
+ 'outline-selected'?: boolean | string;
182
+ /** Silhouette outline CSS hex color (default: "#38bdf8"). */
183
+ 'outline-color'?: string;
172
184
  /** Enable or disable interactive camera orbit/pan/zoom controls (default: true). */
173
185
  'camera-controls'?: boolean | string;
174
186
  /** Automatically start keyframe animation playback. */
@@ -210,6 +222,16 @@ export interface ThreeLiveAttributes {
210
222
  // React 19 / JSX Event Listeners
211
223
  onload?: (e: CustomEvent<{model: GLBData}>) => void;
212
224
  onerror?: (e: CustomEvent<{error: any}>) => void;
225
+ 'onthree-load'?: (
226
+ e: CustomEvent<{model: GLBData; source?: 'src' | 'model'}>,
227
+ ) => void;
228
+ 'onthree-error'?: (
229
+ e: CustomEvent<{error: any; message: string; stage: string}>,
230
+ ) => void;
231
+ 'onthree-context-lost'?: (e: CustomEvent<{originalEvent?: Event}>) => void;
232
+ 'onthree-context-restored'?: (
233
+ e: CustomEvent<{originalEvent?: Event}>,
234
+ ) => void;
213
235
  onmeshclick?: (e: CustomEvent<HitDetail>) => void;
214
236
  'oncamera-change'?: (e: CustomEvent<CameraDetail>) => void;
215
237
  'onvariant-applied'?: (e: CustomEvent<{variantName: string | null}>) => void;
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
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;
17
+ var Y="__THREE_LIVE_REGISTRY__";function j(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Y]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,Y,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[Y]=n}}return e[Y]}var en=j().plugins;function Te(e){let n=j();n.workerExtensionInstallers||(n.workerExtensionInstallers=[]),n.workerExtensionInstallers.includes(e)||n.workerExtensionInstallers.push(e)}function Q(e){let n=j().plugins;n.some(t=>t.name===e.name)||n.push(e),e.onRegister?.()}function N(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function oe(e,n,t){let s=n[0],r=n[1],i=n[2],h=n[3],y=n[4],o=n[5],a=n[6],c=n[7],l=n[8],m=n[9],u=n[10],M=n[11],f=n[12],d=n[13],A=n[14],T=n[15],x=t[0],g=t[1],F=t[2],R=t[3];return e[0]=x*s+g*y+F*l+R*f,e[1]=x*r+g*o+F*m+R*d,e[2]=x*i+g*a+F*u+R*A,e[3]=x*h+g*c+F*M+R*T,x=t[4],g=t[5],F=t[6],R=t[7],e[4]=x*s+g*y+F*l+R*f,e[5]=x*r+g*o+F*m+R*d,e[6]=x*i+g*a+F*u+R*A,e[7]=x*h+g*c+F*M+R*T,x=t[8],g=t[9],F=t[10],R=t[11],e[8]=x*s+g*y+F*l+R*f,e[9]=x*r+g*o+F*m+R*d,e[10]=x*i+g*a+F*u+R*A,e[11]=x*h+g*c+F*M+R*T,x=t[12],g=t[13],F=t[14],R=t[15],e[12]=x*s+g*y+F*l+R*f,e[13]=x*r+g*o+F*m+R*d,e[14]=x*i+g*a+F*u+R*A,e[15]=x*h+g*c+F*M+R*T,e}function X(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=r+r,a=i+i,c=h+h,l=r*o,m=r*a,u=r*c,M=i*a,f=i*c,d=h*c,A=y*o,T=y*a,x=y*c,g=s[0],F=s[1],R=s[2];return e[0]=(1-(M+d))*g,e[1]=(m+x)*g,e[2]=(u-T)*g,e[3]=0,e[4]=(m-x)*F,e[5]=(1-(l+d))*F,e[6]=(f+A)*F,e[7]=0,e[8]=(u+T)*R,e[9]=(f-A)*R,e[10]=(1-(l+M))*R,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function Z(e,n,t=0){let s=n[0],r=n[1],i=n[2],h=n[4],y=n[5],o=n[6],a=n[8],c=n[9],l=n[10],m=l*y-o*c,u=-l*h+o*a,M=c*h-y*a,f=s*m+r*u+i*M;return!f||t>0&&(!Number.isFinite(f)||Math.abs(f)<=t)||(f=1/f,e[0]=m*f,e[1]=u*f,e[2]=M*f,e[3]=(-l*r+i*c)*f,e[4]=(l*s-i*a)*f,e[5]=(-c*s+r*a)*f,e[6]=(o*r-i*y)*f,e[7]=(-o*s+i*h)*f,e[8]=(y*s-r*h)*f),e}function xe(e,n){let t=n[0],s=n[1],r=n[2],i=n[3],h=n[4],y=n[5],o=n[6],a=n[7],c=n[8],l=n[9],m=n[10],u=n[11],M=n[12],f=n[13],d=n[14],A=n[15],T=t*y-s*h,x=t*o-r*h,g=t*a-i*h,F=s*o-r*y,R=s*a-i*y,k=r*a-i*o,v=c*f-l*M,_=c*d-m*M,p=c*A-u*M,b=l*d-m*f,I=l*A-u*f,V=m*A-u*d,w=T*V-x*I+g*b+F*p-R*_+k*v;return w?(w=1/w,e[0]=(y*V-o*I+a*b)*w,e[1]=(r*I-s*V-i*b)*w,e[2]=(f*k-d*R+A*F)*w,e[3]=(m*R-l*k-u*F)*w,e[4]=(o*p-h*V-a*_)*w,e[5]=(t*V-r*p+i*_)*w,e[6]=(d*g-M*k-A*x)*w,e[7]=(c*k-m*g+u*x)*w,e[8]=(h*I-y*p+a*v)*w,e[9]=(s*p-t*I-i*v)*w,e[10]=(M*R-f*g+A*T)*w,e[11]=(l*g-c*R-u*T)*w,e[12]=(y*_-h*b-o*v)*w,e[13]=(t*b-s*_+r*v)*w,e[14]=(f*x-M*F-d*T)*w,e[15]=(c*F-l*x+m*T)*w,e):null}function Me(e,n){let t=Array.isArray(e?.nodes)?e.nodes.length:0,s=[];for(let c=0;c<t;c++)s.push(N());if(t===0)return s;let r=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let l of c.children)r.add(l);let i=new Set,h=128,y=(c,l,m=0)=>{if(m>h||c<0||c>=t||i.has(c))return;i.add(c);let u=e.nodes[c];if(!u)return;let M=N();if(n&&n[c])M.set(n[c]);else if(u.matrix&&u.matrix.length===16)M.set(u.matrix);else{let d=u.translation||[0,0,0],A=u.rotation||[0,0,0,1],T=u.scale||[1,1,1];X(M,A,d,T)}let f=s[c];if(l?oe(f,l,M):f.set(M),Array.isArray(u.children))for(let d of u.children)typeof d=="number"&&y(d,f,m+1)},o=[],a=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(a&&Array.isArray(a.nodes))o.push(...a.nodes);else for(let c=0;c<t;c++)r.has(c)||o.push(c);for(let c of o)y(c,null);for(let c=0;c<t;c++)!r.has(c)&&!o.includes(c)&&y(c,null);return s}function ae(e,n){function t(o,a,c,l){let m=typeof o=="number"?o:Number(o);return Number.isFinite(m)?Math.max(a,Math.min(c,m)):l}function s(o,a){let l=o[0]*a[0]+o[1]*a[1]+o[2]*a[2]+1;if(l<1e-6){if(Math.abs(o[0])>Math.abs(o[2])){let A=Math.hypot(o[1],o[0])||1;return[-o[1]/A,o[0]/A,0,0]}let d=Math.hypot(o[2],o[1])||1;return[0,-o[2]/d,o[1]/d,0]}let m=o[1]*a[2]-o[2]*a[1],u=o[2]*a[0]-o[0]*a[2],M=o[0]*a[1]-o[1]*a[0],f=Math.hypot(m,u,M,l)||1;return[m/f,u/f,M/f,l/f]}function r(o,a,c,l,m){let u=a[0]-o[0],M=a[1]-o[1],f=a[2]-o[2],d=Math.hypot(u,M,f),A=c[0]-a[0],T=c[1]-a[1],x=c[2]-a[2],g=Math.hypot(A,T,x);if(d<1e-6||g<1e-6)return{rootPos:[o[0],o[1],o[2]],midPos:[a[0],a[1],a[2]],effectorPos:[c[0],c[1],c[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let F=[u/d,M/d,f/d],R=[A/g,T/g,x/g],k=l[0]-o[0],v=l[1]-o[1],_=l[2]-o[2],p=Math.hypot(k,v,_),b=p>1e-6?[k/p,v/p,_/p]:F,I=Math.abs(d-g)+1e-5,V=Math.max(I,d+g-1e-5),w=Math.max(I,Math.min(V,p>1e-6?p:I)),S=t((d*d+w*w-g*g)/(2*d*w),-1,1,1),E=Math.sqrt(Math.max(0,1-S*S)),B=m?m[0]-o[0]:u,C=m?m[1]-o[1]:M,U=m?m[2]-o[2]:f,z=B*b[0]+C*b[1]+U*b[2],K=B-b[0]*z,O=C-b[1]*z,P=U-b[2]*z,D=Math.hypot(K,O,P);if(D<=1e-6){let be=Math.abs(b[1])<.99?0:1,ge=Math.abs(b[1])<.99?1:0,Ae=0;K=b[1]*Ae-b[2]*ge,O=b[2]*be-b[0]*Ae,P=b[0]*ge-b[1]*be,D=Math.hypot(K,O,P)||1}let te=[K/D,O/D,P/D],L=[o[0]+b[0]*(d*S)+te[0]*(d*E),o[1]+b[1]*(d*S)+te[1]*(d*E),o[2]+b[2]*(d*S)+te[2]*(d*E)],re=[o[0]+b[0]*w,o[1]+b[1]*w,o[2]+b[2]*w],he=re[0]-L[0],ye=re[1]-L[1],pe=re[2]-L[2],H=Math.hypot(he,ye,pe),q=H>1e-6?[he/H,ye/H,pe/H]:b,Ke=[L[0]+q[0]*g,L[1]+q[1]*g,L[2]+q[2]*g],Oe=[(L[0]-o[0])/d,(L[1]-o[1])/d,(L[2]-o[2])/d];return{rootPos:[o[0],o[1],o[2]],midPos:L,effectorPos:Ke,rootRotation:s(F,Oe),midRotation:s(R,q)}}function i(o,a,c=8,l=.001){let m=o.length;if(m<2)return{positions:o.map(p=>[p[0],p[1],p[2]]),rotations:[],iterations:0};let u=o.map(p=>[p[0],p[1],p[2]]),M=[],f=[],d=0;for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V);M.push(w),d+=w,f.push(w>1e-6?[b/w,I/w,V/w]:[0,1,0])}let A=[u[0][0],u[0][1],u[0][2]],T=Math.round(t(c,1,32,8)),x=t(l,1e-5,.1,.001),g=a[0]-A[0],F=a[1]-A[1],R=a[2]-A[2],k=Math.hypot(g,F,R),v=0;if(k>=d&&d>1e-6){let p=k>1e-6?[g/k,F/k,R/k]:f[0];u[0]=[A[0],A[1],A[2]];for(let b=0;b<m-1;b++){let I=M[b];u[b+1]=[u[b][0]+p[0]*I,u[b][1]+p[1]*I,u[b][2]+p[2]*I]}v=1}else for(let p=1;p<=T;p++){let b=u[m-1];if(Math.hypot(b[0]-a[0],b[1]-a[1],b[2]-a[2])<=x)break;v=p;let V=(w,S,E,B,C)=>{let U=S[0]-w[0],z=S[1]-w[1],K=S[2]-w[2],O=Math.hypot(U,z,K);if(O>1e-6){let P=E/O;return[w[0]+U*P,w[1]+z*P,w[2]+K*P]}return[w[0]+B[0]*E*C,w[1]+B[1]*E*C,w[2]+B[2]*E*C]};u[m-1]=[a[0],a[1],a[2]];for(let w=m-2;w>=0;w--)u[w]=V(u[w+1],u[w],M[w],f[w],-1);u[0]=[A[0],A[1],A[2]];for(let w=0;w<m-1;w++)u[w+1]=V(u[w],u[w+1],M[w],f[w],1)}let _=[];for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V),S=w>1e-6?[b/w,I/w,V/w]:f[p];_.push(s(f[p],S))}return{positions:u,rotations:_,iterations:v}}function h(o){if(!o||typeof o!="object"||Array.isArray(o))return null;let a=o;if(a.enabled===!1)return null;let c=x=>{if(typeof x!="string")return;let g=x.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(g)?g:void 0},l=x=>Array.isArray(x)&&x.length===3&&x.every(g=>typeof g=="number"&&Number.isFinite(g))?[t(x[0],-1e3,1e3,0),t(x[1],-1e3,1e3,0),t(x[2],-1e3,1e3,0)]:void 0,m=c(a.root),u=c(a.effector);if(!m||!u)return null;let M=c(a.mid),f=l(a.target)??c(a.target);if(!f)return null;let d=a.pole??a.poleTarget,A=l(d)??c(d),T=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||M?"two-bone":"fabrik";return{root:m,...M?{mid:M}:{},effector:u,target:f,...A?{pole:A}:{},solver:T,iterations:Math.round(t(a.iterations,1,32,8)),tolerance:t(a.tolerance,1e-5,.1,.001),weight:t(a.weight,0,1,1)}}let y=Object.freeze({solveTwoBone:r,solveFABRIK:i,parseIKTrait:h});return n&&typeof n=="object"&&(n.authorNamespace=n.authorNamespace||{},n.authorNamespace.IKSolver=y),{clampNum:t,parseIKTrait:h,quatFromUnitVectors:s,solveTwoBoneIK:r,solveFABRIK:i,IKSolver:y}}var G=ae(),Re=G.clampNum,We=G.parseIKTrait,le=G.quatFromUnitVectors,Fe=G.solveTwoBoneIK,Ie=G.solveFABRIK,ze=G.IKSolver;function ce(e){let n=e?.transform??e?.modelMatrix;return n&&n.length>=16?[n[12]||0,n[13]||0,n[14]||0]:[0,0,0]}function Ge(e,n){let t=e?.transform??e?.modelMatrix;!t||t.length<16||(t[12]=n[0],t[13]=n[1],t[14]=n[2])}function Ue(e,n,t,s,r){let i=Re(r,0,1,1),h=n[0]+(t[0]-n[0])*i,y=n[1]+(t[1]-n[1])*i,o=n[2]+(t[2]-n[2])*i,a=h-e[0],c=y-e[1],l=o-e[2],m=Math.hypot(a,c,l);if(m>1e-6&&s>1e-6){let A=s/m;return[e[0]+a*A,e[1]+c*A,e[2]+l*A]}let u=t[0]-e[0],M=t[1]-e[1],f=t[2]-e[2],d=Math.hypot(u,M,f);if(d>1e-6&&s>1e-6){let A=s/d;return[e[0]+u*A,e[1]+M*A,e[2]+f*A]}return[h,y,o]}function De(e,n){let t=e?.modelRootMatrix;if(!t||t.length!==16)return n;let s=new Float32Array(16);return xe(s,t instanceof Float32Array?t:Float32Array.from(t))?[s[0]*n[0]+s[4]*n[1]+s[8]*n[2]+s[12],s[1]*n[0]+s[5]*n[1]+s[9]*n[2]+s[13],s[2]*n[0]+s[6]*n[1]+s[10]*n[2]+s[14]]:n}function se(e,n){e.__ikWarned||(e.__ikWarned=new Set);let t=e.__ikWarned;t.has(n)||(t.add(n),console.warn(`[three-live] ik: joint '${n}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function ue(e,n,t){if(Array.isArray(e))return[e[0],e[1],e[2]];let s=n.get(e);if(s)return ce(s);let r;if(e==="head"?r=t?.headPose?.position??t?.headPose??t?.cameraPosition:e==="hand-left"?r=t?.handPoses?.left?.position??t?.handPoses?.left??t?.hands?.left?.position??t?.hands?.left:e==="hand-right"&&(r=t?.handPoses?.right?.position??t?.handPoses?.right??t?.hands?.right?.position??t?.hands?.right),(Array.isArray(r)||ArrayBuffer.isView(r))&&r.length>=3){let i=r;return De(t,[i[0],i[1],i[2]])}return null}function ie(e,n){return[e[3]*n[0]+e[0]*n[3]+e[1]*n[2]-e[2]*n[1],e[3]*n[1]-e[0]*n[2]+e[1]*n[3]+e[2]*n[0],e[3]*n[2]+e[0]*n[1]-e[1]*n[0]+e[2]*n[3],e[3]*n[3]-e[0]*n[0]-e[1]*n[1]-e[2]*n[2]]}function je(e){return[-e[0],-e[1],-e[2],e[3]]}function me(e){let n=Math.hypot(e[0],e[1],e[2],e[3]);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n,e[3]/n]:[0,0,0,1]}function Qe(e,n){if(n>=1)return e;if(n<=0)return[0,0,0,1];let[t,s,r,i]=e;i<0&&(t=-t,s=-s,r=-r,i=-i);let h=Math.acos(Math.min(1,i)),y=Math.sin(h);if(y<1e-9)return[0,0,0,1];let o=Math.sin(h*n)/y;return me([t*o,s*o,r*o,Math.cos(h*n)])}function Xe(e){let n=Math.hypot(e[0],e[1],e[2])||1,t=Math.hypot(e[4],e[5],e[6])||1,s=Math.hypot(e[8],e[9],e[10])||1,r=e[0]/n,i=e[1]/n,h=e[2]/n,y=e[4]/t,o=e[5]/t,a=e[6]/t,c=e[8]/s,l=e[9]/s,m=e[10]/s,u=r+o+m,M;if(u>0){let f=Math.sqrt(u+1)*2;M=[(a-l)/f,(c-h)/f,(i-y)/f,.25*f]}else if(r>o&&r>m){let f=Math.sqrt(1+r-o-m)*2;M=[.25*f,(y+i)/f,(c+h)/f,(a-l)/f]}else if(o>m){let f=Math.sqrt(1+o-r-m)*2;M=[(y+i)/f,.25*f,(l+a)/f,(c-h)/f]}else{let f=Math.sqrt(1+m-r-o)*2;M=[(c+h)/f,(l+a)/f,.25*f,(i-y)/f]}return me(M)}function Je(e,n,t){let[s,r,i,h]=t,y=1-2*(r*r+i*i),o=2*(s*r-i*h),a=2*(s*i+r*h),c=2*(s*r+i*h),l=1-2*(s*s+i*i),m=2*(r*i-s*h),u=2*(s*i-r*h),M=2*(r*i+s*h),f=1-2*(s*s+r*r);for(let d=0;d<3;d++){let A=n[d*4],T=n[d*4+1],x=n[d*4+2];e[d*4]=y*A+o*T+a*x,e[d*4+1]=c*A+l*T+m*x,e[d*4+2]=u*A+M*T+f*x}}function ee(e,n){let t=n[0]-e[0],s=n[1]-e[1],r=n[2]-e[2],i=Math.hypot(t,s,r);return i>1e-9?[t/i,s/i,r/i]:null}function Ve(e){e?.normalMatrix&&e?.transform&&Z(e.normalMatrix,e.transform)}var we=new WeakMap;function $e(e){let n=we.get(e);return n||(n=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((t,s)=>{for(let r of Array.isArray(t?.children)?t.children:[])typeof r=="number"&&r>=0&&r<n.length&&(n[r]=s)}),we.set(e,n)),n}function He(e,n,t){let s=e?.gltf,r=s?.nodes;if(!Array.isArray(r)||r.length===0)return!1;let i=new Map;r.forEach((p,b)=>{typeof p?.name=="string"&&p.name&&!i.has(p.name)&&i.set(p.name,b)});let y=(n.mid?[n.root,n.mid,n.effector]:[n.root,n.effector]).map(p=>i.get(p));if(y.some(p=>p===void 0))return!1;let o=y,a=$e(s);for(let p=1;p<o.length;p++){let b=a[o[p]],I=0;for(;b>=0&&b!==o[p-1]&&I++<256;)b=a[b];if(b!==o[p-1])return!1}let c=o[0],l=e.initialNodeTransforms,m=new Map,u=[],M=[c];for(;M.length&&u.length<4096;){let p=M.pop();if(m.has(p))continue;let b=l?.[p],I=r[p];m.set(p,{t:b?[b.t[0],b.t[1],b.t[2]]:I?.translation?[...I.translation]:[0,0,0],r:b?[b.r[0],b.r[1],b.r[2],b.r[3]]:I?.rotation?[...I.rotation]:[0,0,0,1],s:b?[b.s[0],b.s[1],b.s[2]]:I?.scale?[...I.scale]:[1,1,1]}),u.push(p);for(let V of Array.isArray(I?.children)?I.children:[])typeof V=="number"&&M.push(V)}let f=a[c],d=f>=0&&e.worldMatrices?.[f]?.length===16?Float32Array.from(e.worldMatrices[f]):N(),A=new Map,T=()=>{let p=(b,I)=>{let V=m.get(b);if(!V)return;let w=N();X(w,V.r,V.t,V.s);let S=N();oe(S,I,w),A.set(b,S);for(let E of Array.isArray(r[b]?.children)?r[b].children:[])typeof E=="number"&&p(E,S)};p(c,d)},x=p=>{let b=A.get(p);return[b[12],b[13],b[14]]};T();let g=o.map(x),F=p=>{if(typeof p=="string"&&!t.has(p)){let b=i.get(p),I=b!==void 0?A.get(b)??e.worldMatrices?.[b]:void 0;if(I&&I.length===16)return[I[12],I[13],I[14]]}return ue(p,t,e)},R=F(n.target);if(!R)return!0;let k=n.pole?F(n.pole)??void 0:void 0,v=ve(g,n,R,k),_=Re(n.weight,0,1,1);for(let p=0;p<o.length-1;p++){let b=ee(x(o[p]),x(o[p+1])),I=ee(v[p],v[p+1]);if(!b||!I)continue;let V=Qe(le(b,I),_),w=o[p],S=a[w],E=S===f||S<0?d:A.get(S)??d,B=Xe(E),C=m.get(w);C.r=me(ie(je(B),ie(V,ie(B,C.r)))),T()}if(Array.isArray(e.worldMatrices))for(let[p,b]of A)e.worldMatrices[p]?.set&&e.worldMatrices[p].set(b);for(let p of e.meshes??[]){let b=A.get(p?.nodeIndex);b&&p.transform?.set&&(p.transform.set(b),Ve(p))}return!0}function ve(e,n,t,s){if(n.solver==="two-bone"&&e.length===3){let r=Fe(e[0],e[1],e[2],t,s);return[e[0],r.midPos,r.effectorPos]}return Ie(e,t,n.iterations,n.tolerance).positions}function qe(e,n,t){let s=e.__ikRestOffsets,r=e.__ikRestMats;if(!(!s||!r))for(let i=0;i<n.length-1;i++){let h=n[i]?.transform??n[i]?.modelMatrix,y=r[i],o=ee([0,0,0],s[i]),a=ee(t[i],t[i+1]);!h||h.length<16||!y||y.length<16||!o||!a||(Je(h,y,le(o,a)),Ve(n[i]))}}var Se={name:"ik",onRegister(){let e=j();Te(ae),ae(e.threeNamespace,e)},onUpdate(e){let n=e?.meshes;if(!Array.isArray(n)||n.length===0)return;let t=null;for(let s of n){let r=s?.userData?.xr?.ik??s?.extras?.xr?.ik??s?.extensions?.ANDROID_xr_scenecore?.ik;if(!r)continue;let i=We(r);if(!i||i.weight<=0)continue;if(!t){t=new Map;for(let g of n)g&&typeof g.name=="string"&&g.name&&t.set(g.name,g)}if(He(e,i,t))continue;let h=t.get(i.root),y=t.get(i.effector),o=i.mid?t.get(i.mid):void 0;if(h||se(s,i.root),y||se(s,i.effector),i.mid&&!o&&se(s,i.mid),!h||!y)continue;let a=ue(i.target,t,e);if(!a)continue;let c=i.pole?ue(i.pole,t,e)??void 0:void 0,l=o?[h,o,y]:[h,y],m=l.map(g=>g.name||"").join(">");if(!s.__ikRestOffsets||s.__ikRestKey!==m){let g=l.map(ce),F=[];for(let R=0;R<g.length-1;R++)F.push([g[R+1][0]-g[R][0],g[R+1][1]-g[R][1],g[R+1][2]-g[R][2]]);s.__ikRestOffsets=F,s.__ikRestKey=m,s.__ikRestMats=l.map(R=>Array.from(R.transform??R.modelMatrix??[]))}let u=s.__ikRestOffsets,f=[ce(h)],d=[];for(let g=0;g<u.length;g++){let F=f[g],R=u[g];f.push([F[0]+R[0],F[1]+R[1],F[2]+R[2]]),d.push(Math.hypot(R[0],R[1],R[2]))}let A=ve(f,i,a,c),T=f[0],x=[f[0]];for(let g=1;g<l.length;g++){let F=u[g-1],R=[T[0]+F[0],T[1]+F[1],T[2]+F[2]],k=[T[0]+(A[g][0]-A[g-1][0]),T[1]+(A[g][1]-A[g-1][1]),T[2]+(A[g][2]-A[g-1][2])],v=Ue(T,R,k,d[g-1],i.weight);Ge(l[g],v),T=v,x.push(v)}qe(s,l,x)}}};var Ye={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function W(e,n,t,s){if(!t||t.bufferView===void 0)return null;let r=e.bufferViews?.[t.bufferView];if(!r)return null;let i=Number(t.count??0);if(!Number.isInteger(i)||i<=0)return null;let h=t.componentType??5126,y=Ye[h];if(!y)throw new RangeError(`glTF accessor has unsupported componentType ${h}`);let o=y*s,a=r.byteStride&&r.byteStride>0?r.byteStride:o,c=(r.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(c)||c<0||a<o||c+(i-1)*a+o>n.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${n.byteLength} bytes)`);if(h===5126&&a===o&&c%4===0)return new Float32Array(n,c,i*s);let l=new DataView(n),m=t.normalized===!0,u=new Float32Array(i*s);for(let M=0;M<i;M++){let f=c+M*a;for(let d=0;d<s;d++){let A=f+d*y,T;switch(h){case 5126:T=l.getFloat32(A,!0);break;case 5120:T=l.getInt8(A),m&&(T=Math.max(T/127,-1));break;case 5121:T=l.getUint8(A),m&&(T/=255);break;case 5122:T=l.getInt16(A,!0),m&&(T=Math.max(T/32767,-1));break;case 5123:T=l.getUint16(A,!0),m&&(T/=65535);break;default:T=l.getUint32(A,!0),m&&(T/=4294967295)}u[M*s+d]=T}}return u}function ke(e,n,t){return n%4===0?new Float32Array(e,n,t):new Float32Array(e.slice(n,n+t*4))}function Ee(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=t[0],a=t[1],c=t[2],l=t[3],m=r*o+i*a+h*c+y*l;if(m<0&&(o=-o,a=-a,c=-c,l=-l,m=-m),Math.abs(m)>=1)return e[0]=r,e[1]=i,e[2]=h,e[3]=y,e;let u=Math.acos(m),M=Math.sqrt(1-m*m);if(Math.abs(M)<.001)return e[0]=.5*(r+o),e[1]=.5*(i+a),e[2]=.5*(h+c),e[3]=.5*(y+l),e;let f=Math.sin((1-s)*u)/M,d=Math.sin(s*u)/M;return e[0]=r*f+o*d,e[1]=i*f+a*d,e[2]=h*f+c*d,e[3]=y*f+l*d,e}function _e(e,n,t,s){return e[0]=n[0]+s*(t[0]-n[0]),e[1]=n[1]+s*(t[1]-n[1]),e[2]=n[2]+s*(t[2]-n[2]),e}function Le(e,n){if(!Array.isArray(e?.animations))return[];let t=[];for(let s=0;s<e.animations.length;s++){let r=e.animations[s],i=r.name||`Animation_${s}`,h=[],y=0;if(Array.isArray(r.channels)&&Array.isArray(r.samplers))for(let o of r.channels){if(!o.target||o.target.node===void 0||!o.target.path)continue;let a=r.samplers[o.sampler];if(!a)continue;let c=e.accessors?.[a.input],l=e.accessors?.[a.output];if(!c||!l)continue;let m=e.bufferViews?.[c.bufferView],u=e.bufferViews?.[l.bufferView];if(!m||!u)continue;let M=(m.byteOffset||0)+(c.byteOffset||0),f=(u.byteOffset||0)+(l.byteOffset||0),d=W(e,n,c,1)??ke(n,M,c.count);d.length>0&&d[d.length-1]>y&&(y=d[d.length-1]);let A=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(l.count/Math.max(1,c.count))):3,T=o.target.path==="weights"?1:A,x=W(e,n,l,T)??ke(n,f,l.count*T),g=a.interpolation==="STEP"?"STEP":"LINEAR";h.push({nodeIndex:o.target.node,path:o.target.path,times:d,values:x,interpolation:g})}h.length>0&&t.push({name:i,duration:y,channels:h})}return t}function J(e,n,t){let{times:s,values:r,path:i,interpolation:h}=e,y=s.length;if(y===0)return;let o=i==="rotation"?4:i==="weights"?Math.max(1,Math.round(r.length/y)):3;if(n<=s[0]){for(let T=0;T<o;T++)t[T]=r[T];return}if(n>=s[y-1]){let T=(y-1)*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let a=0,c=y-1;for(;a<=c;){let T=a+c>>1;s[T]<=n?a=T+1:c=T-1}let l=Math.max(0,c),m=Math.min(y-1,l+1);if(h==="STEP"||l===m){let T=l*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let u=s[l],M=s[m],f=(n-u)/Math.max(1e-5,M-u),d=l*o,A=m*o;if(i==="rotation"){let T=[r[d],r[d+1],r[d+2],r[d+3]],x=[r[A],r[A+1],r[A+2],r[A+3]];Ee(t,T,x,f)}else for(let T=0;T<o;T++)t[T]=r[d+T]+f*(r[A+T]-r[d+T])}var ne=new WeakMap;function Ne(e,n,t=.3){if(!e?.animations)return;let s=e.animations.find(y=>y.name===n);if(!s)return;let r=ne.get(e);r||(r=[],e.currentClip&&r.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),ne.set(e,r));let i=t>0?1/t:1e3;for(let y of r)y.clip.name!==n&&(y.fadeSpeed=-i);let h=r.find(y=>y.clip.name===n);h?h.fadeSpeed=i:r.push({clip:s,time:0,weight:t>0?0:1,fadeSpeed:i}),e.currentClip=s,e.isPlayingAnimation=!0}function fe(e,n){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let t=ne.get(e);if(!t||t.length===0){if(!e.currentClip)return;t=[{clip:e.currentClip,time:n,weight:1,fadeSpeed:0}]}let s=e.gltf.nodes.length,r=[];for(let l=0;l<s;l++){let m=e.initialNodeTransforms[l];m?r.push({t:[m.t[0],m.t[1],m.t[2]],r:[m.r[0],m.r[1],m.r[2],m.r[3]],s:[m.s[0],m.s[1],m.s[2]]}):r.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let i=[0,0,0],h=[0,0,0,1],y=[1,1,1],o=new Float32Array(64);for(let l of t){let m=Math.max(0,Math.min(1,l.weight));if(!(m<=1e-4))for(let u of l.clip.channels){if(u.nodeIndex<0||u.nodeIndex>=s)continue;let M=r[u.nodeIndex];if(u.path==="translation")J(u,l.time,i),_e(M.t,M.t,i,m);else if(u.path==="rotation")J(u,l.time,h),Ee(M.r,M.r,h,m);else if(u.path==="scale")J(u,l.time,y),_e(M.s,M.s,y,m);else if(u.path==="weights"&&(J(u,l.time,o),e.meshes)){for(let f of e.meshes)if(f.nodeIndex===u.nodeIndex){for(let d of f.primitives)if(d.pluginData?.morph?.weights){let A=d.pluginData.morph.weights,T=d.pluginData.morph.numTargets||A.length;for(let x=0;x<T;x++)A[x]=A[x]*(1-m)+o[x]*m}}}}}let a=[];for(let l=0;l<s;l++){let m=N(),{t:u,r:M,s:f}=r[l];X(m,M,u,f),a.push(m)}let c=Me(e.gltf,a);e.worldMatrices=c;for(let l of e.meshes)l.nodeIndex>=0&&l.nodeIndex<c.length&&(l.transform.set(c[l.nodeIndex]),Z(l.normalMatrix,l.transform))}var Be={name:"keyframes",evaluateAnimation:fe,crossFadeTo:Ne,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=Le(e.gltf,e.bin))},onUpdate(e,n){if(!e.isPlayingAnimation)return;let t=ne.get(e);if(t&&t.length>0){for(let s=t.length-1;s>=0;s--){let r=t[s];if(r.time+=n,r.clip.duration>0&&(r.time%=r.clip.duration),r.fadeSpeed!==0)if(r.weight+=r.fadeSpeed*n,r.weight<=0){t.splice(s,1);continue}else r.weight>=1&&(r.weight=1,r.fadeSpeed=0)}t.length>0&&(e.animationTime=t[t.length-1].time),fe(e,e.animationTime)}else e.currentClip&&(e.animationTime+=n,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),fe(e,e.animationTime))}};var $=64;function Ze(e,n,t){if(!(!e?.meshes||n<0||n>=$))for(let s of e.meshes)for(let r of s.primitives){let i=r.pluginData?.morph;i?.weights&&(i.weights[n]=t)}}var Ce={name:"morph",onResolveShader(e,n,t,s){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let r=t.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
18
18
  uniform sampler2D uMorphDeltasTex;
19
19
  uniform float uMorphWeights[${$}];
20
20
  uniform int uNumMorphTargets;`);return r=r.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
@@ -25,12 +25,12 @@ for (int m = 0; m < ${$}; m++) {
25
25
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
26
26
  }
27
27
  }
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;
28
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.targets;if(!Array.isArray(i)||i.length===0)return null;let h=t.attributes?.POSITION,y=s?.accessors?.[h];if(!y)return null;let o=y.count,a=Math.min(i.length,$),c=new Float32Array(o*a*4);for(let u=0;u<a;u++){let M=i[u].POSITION;if(M===void 0)continue;let f=s.accessors?.[M],d=s.bufferViews?.[f?.bufferView];if(!f||!d)continue;let A=W(s,r,f,3);if(!A||A.length<o*3)continue;let T=u*o*4;for(let x=0;x<o;x++)c[T+x*4]=A[x*3],c[T+x*4+1]=A[x*3+1],c[T+x*4+2]=A[x*3+2],c[T+x*4+3]=0}let l=e.createTexture();e.bindTexture(3553,l),e.texImage2D(3553,0,34836,o,a,0,6408,5126,c),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array($);return{hasMorph:!0,morphTex:l,numTargets:a,vertexCount:o,weights:m}},onBeforeDrawPrimitive(e,n,t,s,r,i){let h=t.pluginData?.morph;if(!h?.hasMorph||!h.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,h.morphTex);let y=e.getUniformLocation(n,"uMorphDeltasTex");y&&e.uniform1i(y,5);let o=e.getUniformLocation(n,"uNumMorphTargets");o&&e.uniform1i(o,h.numTargets);let a=e.getUniformLocation(n,"uMorphWeights[0]");a&&e.uniform1fv(a,h.weights)}};var de=64,Pe={name:"skinning",onResolveShader(e,n,t,s){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let r=t.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
29
29
  layout(location=4) in uvec4 aJoints;
30
30
  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 =
31
+ uniform mat4 uJointMatrix[${de}];`),i=r.includes("morphedPos")?"morphedPos":"aPosition";return r=r.replace(`vec4 world=uModel*vec4(${i},1.0);`,`mat4 skinMatrix =
32
32
  aWeights.x * uJointMatrix[int(aJoints.x)] +
33
33
  aWeights.y * uJointMatrix[int(aJoints.y)] +
34
34
  aWeights.z * uJointMatrix[int(aJoints.z)] +
35
35
  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};
36
+ vec4 world=uModel*(skinMatrix*vec4(${i},1.0));`).replace(`gl_Position=uMVP*vec4(${i},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${i},1.0));`),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.attributes;if(!i||i.JOINTS_0===void 0||i.WEIGHTS_0===void 0)return null;let h=s.accessors[i.JOINTS_0],y=s.accessors[i.WEIGHTS_0];if(!h||!y)return null;let o=s.bufferViews[h.bufferView],a=s.bufferViews[y.bufferView];if(!o||!a)return null;let c=(o.byteOffset||0)+(h.byteOffset||0),l=(a.byteOffset||0)+(y.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let u=h.componentType===5121?5121:5123,M=u===5121?new Uint8Array(r,c,h.count*4):new Uint16Array(r,c,h.count*4);e.bufferData(34962,M,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,u,0,0);let f=e.createBuffer();e.bindBuffer(34962,f);let d=W(s,r,y,4)??new Float32Array(r,l,y.count*4);return e.bufferData(34962,d,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,f]}},onBeforeDrawPrimitive(e,n,t,s,r,i){if(!t.pluginData?.skinning?.hasSkin)return;let h=i?.nodes?.[s.nodeIndex]?.skin;if(h===void 0||!i.skins||!i.skins[h])return;let o=i.skins[h].joints||[],a=new Float32Array(de*16);for(let l=0;l<o.length&&l<de;l++){let m=o[l],u=r[m]||N();a.subarray(l*16,(l+1)*16).set(u)}let c=e.getUniformLocation(n,"uJointMatrix[0]");c&&e.uniformMatrix4fv(c,!1,a)}};Q(Ce);Q(Be);Q(Pe);Q(Se);export{ze as IKSolver,Ne as crossFadeTo,Se as ikPlugin,Be as keyframeAnimationPlugin,Ce as morphPlugin,Le as parseAnimations,le as quatFromUnitVectors,J as sampleChannel,Ze as setMorphTargetWeight,Pe as skinningPlugin,Ie as solveFABRIK,Fe as solveTwoBoneIK};
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
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;
17
+ "use strict";var ThreeLiveAnimation=(()=>{var se=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var je=Object.prototype.hasOwnProperty;var Qe=(e,n)=>{for(var t in n)se(e,t,{get:n[t],enumerable:!0})},Xe=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of De(n))!je.call(e,r)&&r!==t&&se(e,r,{get:()=>n[r],enumerable:!(s=Ue(n,r))||s.enumerable});return e};var Je=e=>Xe(se({},"__esModule",{value:!0}),e);var cn={};Qe(cn,{IKSolver:()=>Ne,crossFadeTo:()=>ge,ikPlugin:()=>ye,keyframeAnimationPlugin:()=>Ae,morphPlugin:()=>Te,parseAnimations:()=>be,quatFromUnitVectors:()=>ne,sampleChannel:()=>U,setMorphTargetWeight:()=>We,skinningPlugin:()=>Me,solveFABRIK:()=>de,solveTwoBoneIK:()=>fe});var Y="__THREE_LIVE_REGISTRY__";function Q(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Y]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,Y,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[Y]=n}}return e[Y]}var ln=Q().plugins;function Se(e){let n=Q();n.workerExtensionInstallers||(n.workerExtensionInstallers=[]),n.workerExtensionInstallers.includes(e)||n.workerExtensionInstallers.push(e)}function X(e){let n=Q().plugins;n.some(t=>t.name===e.name)||n.push(e),e.onRegister?.()}function N(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function ie(e,n,t){let s=n[0],r=n[1],i=n[2],h=n[3],y=n[4],o=n[5],a=n[6],c=n[7],l=n[8],m=n[9],u=n[10],M=n[11],f=n[12],d=n[13],A=n[14],T=n[15],x=t[0],g=t[1],F=t[2],R=t[3];return e[0]=x*s+g*y+F*l+R*f,e[1]=x*r+g*o+F*m+R*d,e[2]=x*i+g*a+F*u+R*A,e[3]=x*h+g*c+F*M+R*T,x=t[4],g=t[5],F=t[6],R=t[7],e[4]=x*s+g*y+F*l+R*f,e[5]=x*r+g*o+F*m+R*d,e[6]=x*i+g*a+F*u+R*A,e[7]=x*h+g*c+F*M+R*T,x=t[8],g=t[9],F=t[10],R=t[11],e[8]=x*s+g*y+F*l+R*f,e[9]=x*r+g*o+F*m+R*d,e[10]=x*i+g*a+F*u+R*A,e[11]=x*h+g*c+F*M+R*T,x=t[12],g=t[13],F=t[14],R=t[15],e[12]=x*s+g*y+F*l+R*f,e[13]=x*r+g*o+F*m+R*d,e[14]=x*i+g*a+F*u+R*A,e[15]=x*h+g*c+F*M+R*T,e}function J(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=r+r,a=i+i,c=h+h,l=r*o,m=r*a,u=r*c,M=i*a,f=i*c,d=h*c,A=y*o,T=y*a,x=y*c,g=s[0],F=s[1],R=s[2];return e[0]=(1-(M+d))*g,e[1]=(m+x)*g,e[2]=(u-T)*g,e[3]=0,e[4]=(m-x)*F,e[5]=(1-(l+d))*F,e[6]=(f+A)*F,e[7]=0,e[8]=(u+T)*R,e[9]=(f-A)*R,e[10]=(1-(l+M))*R,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function Z(e,n,t=0){let s=n[0],r=n[1],i=n[2],h=n[4],y=n[5],o=n[6],a=n[8],c=n[9],l=n[10],m=l*y-o*c,u=-l*h+o*a,M=c*h-y*a,f=s*m+r*u+i*M;return!f||t>0&&(!Number.isFinite(f)||Math.abs(f)<=t)||(f=1/f,e[0]=m*f,e[1]=u*f,e[2]=M*f,e[3]=(-l*r+i*c)*f,e[4]=(l*s-i*a)*f,e[5]=(-c*s+r*a)*f,e[6]=(o*r-i*y)*f,e[7]=(-o*s+i*h)*f,e[8]=(y*s-r*h)*f),e}function ke(e,n){let t=n[0],s=n[1],r=n[2],i=n[3],h=n[4],y=n[5],o=n[6],a=n[7],c=n[8],l=n[9],m=n[10],u=n[11],M=n[12],f=n[13],d=n[14],A=n[15],T=t*y-s*h,x=t*o-r*h,g=t*a-i*h,F=s*o-r*y,R=s*a-i*y,k=r*a-i*o,v=c*f-l*M,_=c*d-m*M,p=c*A-u*M,b=l*d-m*f,I=l*A-u*f,V=m*A-u*d,w=T*V-x*I+g*b+F*p-R*_+k*v;return w?(w=1/w,e[0]=(y*V-o*I+a*b)*w,e[1]=(r*I-s*V-i*b)*w,e[2]=(f*k-d*R+A*F)*w,e[3]=(m*R-l*k-u*F)*w,e[4]=(o*p-h*V-a*_)*w,e[5]=(t*V-r*p+i*_)*w,e[6]=(d*g-M*k-A*x)*w,e[7]=(c*k-m*g+u*x)*w,e[8]=(h*I-y*p+a*v)*w,e[9]=(s*p-t*I-i*v)*w,e[10]=(M*R-f*g+A*T)*w,e[11]=(l*g-c*R-u*T)*w,e[12]=(y*_-h*b-o*v)*w,e[13]=(t*b-s*_+r*v)*w,e[14]=(f*x-M*F-d*T)*w,e[15]=(c*F-l*x+m*T)*w,e):null}function _e(e,n){let t=Array.isArray(e?.nodes)?e.nodes.length:0,s=[];for(let c=0;c<t;c++)s.push(N());if(t===0)return s;let r=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let l of c.children)r.add(l);let i=new Set,h=128,y=(c,l,m=0)=>{if(m>h||c<0||c>=t||i.has(c))return;i.add(c);let u=e.nodes[c];if(!u)return;let M=N();if(n&&n[c])M.set(n[c]);else if(u.matrix&&u.matrix.length===16)M.set(u.matrix);else{let d=u.translation||[0,0,0],A=u.rotation||[0,0,0,1],T=u.scale||[1,1,1];J(M,A,d,T)}let f=s[c];if(l?ie(f,l,M):f.set(M),Array.isArray(u.children))for(let d of u.children)typeof d=="number"&&y(d,f,m+1)},o=[],a=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(a&&Array.isArray(a.nodes))o.push(...a.nodes);else for(let c=0;c<t;c++)r.has(c)||o.push(c);for(let c of o)y(c,null);for(let c=0;c<t;c++)!r.has(c)&&!o.includes(c)&&y(c,null);return s}function ue(e,n){function t(o,a,c,l){let m=typeof o=="number"?o:Number(o);return Number.isFinite(m)?Math.max(a,Math.min(c,m)):l}function s(o,a){let l=o[0]*a[0]+o[1]*a[1]+o[2]*a[2]+1;if(l<1e-6){if(Math.abs(o[0])>Math.abs(o[2])){let A=Math.hypot(o[1],o[0])||1;return[-o[1]/A,o[0]/A,0,0]}let d=Math.hypot(o[2],o[1])||1;return[0,-o[2]/d,o[1]/d,0]}let m=o[1]*a[2]-o[2]*a[1],u=o[2]*a[0]-o[0]*a[2],M=o[0]*a[1]-o[1]*a[0],f=Math.hypot(m,u,M,l)||1;return[m/f,u/f,M/f,l/f]}function r(o,a,c,l,m){let u=a[0]-o[0],M=a[1]-o[1],f=a[2]-o[2],d=Math.hypot(u,M,f),A=c[0]-a[0],T=c[1]-a[1],x=c[2]-a[2],g=Math.hypot(A,T,x);if(d<1e-6||g<1e-6)return{rootPos:[o[0],o[1],o[2]],midPos:[a[0],a[1],a[2]],effectorPos:[c[0],c[1],c[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let F=[u/d,M/d,f/d],R=[A/g,T/g,x/g],k=l[0]-o[0],v=l[1]-o[1],_=l[2]-o[2],p=Math.hypot(k,v,_),b=p>1e-6?[k/p,v/p,_/p]:F,I=Math.abs(d-g)+1e-5,V=Math.max(I,d+g-1e-5),w=Math.max(I,Math.min(V,p>1e-6?p:I)),S=t((d*d+w*w-g*g)/(2*d*w),-1,1,1),E=Math.sqrt(Math.max(0,1-S*S)),B=m?m[0]-o[0]:u,C=m?m[1]-o[1]:M,D=m?m[2]-o[2]:f,z=B*b[0]+C*b[1]+D*b[2],K=B-b[0]*z,O=C-b[1]*z,P=D-b[2]*z,j=Math.hypot(K,O,P);if(j<=1e-6){let Ie=Math.abs(b[1])<.99?0:1,Ve=Math.abs(b[1])<.99?1:0,ve=0;K=b[1]*ve-b[2]*Ve,O=b[2]*Ie-b[0]*ve,P=b[0]*Ve-b[1]*Ie,j=Math.hypot(K,O,P)||1}let re=[K/j,O/j,P/j],L=[o[0]+b[0]*(d*S)+re[0]*(d*E),o[1]+b[1]*(d*S)+re[1]*(d*E),o[2]+b[2]*(d*S)+re[2]*(d*E)],oe=[o[0]+b[0]*w,o[1]+b[1]*w,o[2]+b[2]*w],we=oe[0]-L[0],Re=oe[1]-L[1],Fe=oe[2]-L[2],H=Math.hypot(we,Re,Fe),q=H>1e-6?[we/H,Re/H,Fe/H]:b,ze=[L[0]+q[0]*g,L[1]+q[1]*g,L[2]+q[2]*g],Ge=[(L[0]-o[0])/d,(L[1]-o[1])/d,(L[2]-o[2])/d];return{rootPos:[o[0],o[1],o[2]],midPos:L,effectorPos:ze,rootRotation:s(F,Ge),midRotation:s(R,q)}}function i(o,a,c=8,l=.001){let m=o.length;if(m<2)return{positions:o.map(p=>[p[0],p[1],p[2]]),rotations:[],iterations:0};let u=o.map(p=>[p[0],p[1],p[2]]),M=[],f=[],d=0;for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V);M.push(w),d+=w,f.push(w>1e-6?[b/w,I/w,V/w]:[0,1,0])}let A=[u[0][0],u[0][1],u[0][2]],T=Math.round(t(c,1,32,8)),x=t(l,1e-5,.1,.001),g=a[0]-A[0],F=a[1]-A[1],R=a[2]-A[2],k=Math.hypot(g,F,R),v=0;if(k>=d&&d>1e-6){let p=k>1e-6?[g/k,F/k,R/k]:f[0];u[0]=[A[0],A[1],A[2]];for(let b=0;b<m-1;b++){let I=M[b];u[b+1]=[u[b][0]+p[0]*I,u[b][1]+p[1]*I,u[b][2]+p[2]*I]}v=1}else for(let p=1;p<=T;p++){let b=u[m-1];if(Math.hypot(b[0]-a[0],b[1]-a[1],b[2]-a[2])<=x)break;v=p;let V=(w,S,E,B,C)=>{let D=S[0]-w[0],z=S[1]-w[1],K=S[2]-w[2],O=Math.hypot(D,z,K);if(O>1e-6){let P=E/O;return[w[0]+D*P,w[1]+z*P,w[2]+K*P]}return[w[0]+B[0]*E*C,w[1]+B[1]*E*C,w[2]+B[2]*E*C]};u[m-1]=[a[0],a[1],a[2]];for(let w=m-2;w>=0;w--)u[w]=V(u[w+1],u[w],M[w],f[w],-1);u[0]=[A[0],A[1],A[2]];for(let w=0;w<m-1;w++)u[w+1]=V(u[w],u[w+1],M[w],f[w],1)}let _=[];for(let p=0;p<m-1;p++){let b=u[p+1][0]-u[p][0],I=u[p+1][1]-u[p][1],V=u[p+1][2]-u[p][2],w=Math.hypot(b,I,V),S=w>1e-6?[b/w,I/w,V/w]:f[p];_.push(s(f[p],S))}return{positions:u,rotations:_,iterations:v}}function h(o){if(!o||typeof o!="object"||Array.isArray(o))return null;let a=o;if(a.enabled===!1)return null;let c=x=>{if(typeof x!="string")return;let g=x.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(g)?g:void 0},l=x=>Array.isArray(x)&&x.length===3&&x.every(g=>typeof g=="number"&&Number.isFinite(g))?[t(x[0],-1e3,1e3,0),t(x[1],-1e3,1e3,0),t(x[2],-1e3,1e3,0)]:void 0,m=c(a.root),u=c(a.effector);if(!m||!u)return null;let M=c(a.mid),f=l(a.target)??c(a.target);if(!f)return null;let d=a.pole??a.poleTarget,A=l(d)??c(d),T=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||M?"two-bone":"fabrik";return{root:m,...M?{mid:M}:{},effector:u,target:f,...A?{pole:A}:{},solver:T,iterations:Math.round(t(a.iterations,1,32,8)),tolerance:t(a.tolerance,1e-5,.1,.001),weight:t(a.weight,0,1,1)}}let y=Object.freeze({solveTwoBone:r,solveFABRIK:i,parseIKTrait:h});return n&&typeof n=="object"&&(n.authorNamespace=n.authorNamespace||{},n.authorNamespace.IKSolver=y),{clampNum:t,parseIKTrait:h,quatFromUnitVectors:s,solveTwoBoneIK:r,solveFABRIK:i,IKSolver:y}}var G=ue(),Le=G.clampNum,$e=G.parseIKTrait,ne=G.quatFromUnitVectors,fe=G.solveTwoBoneIK,de=G.solveFABRIK,Ne=G.IKSolver;function le(e){let n=e?.transform??e?.modelMatrix;return n&&n.length>=16?[n[12]||0,n[13]||0,n[14]||0]:[0,0,0]}function He(e,n){let t=e?.transform??e?.modelMatrix;!t||t.length<16||(t[12]=n[0],t[13]=n[1],t[14]=n[2])}function qe(e,n,t,s,r){let i=Le(r,0,1,1),h=n[0]+(t[0]-n[0])*i,y=n[1]+(t[1]-n[1])*i,o=n[2]+(t[2]-n[2])*i,a=h-e[0],c=y-e[1],l=o-e[2],m=Math.hypot(a,c,l);if(m>1e-6&&s>1e-6){let A=s/m;return[e[0]+a*A,e[1]+c*A,e[2]+l*A]}let u=t[0]-e[0],M=t[1]-e[1],f=t[2]-e[2],d=Math.hypot(u,M,f);if(d>1e-6&&s>1e-6){let A=s/d;return[e[0]+u*A,e[1]+M*A,e[2]+f*A]}return[h,y,o]}function Ye(e,n){let t=e?.modelRootMatrix;if(!t||t.length!==16)return n;let s=new Float32Array(16);return ke(s,t instanceof Float32Array?t:Float32Array.from(t))?[s[0]*n[0]+s[4]*n[1]+s[8]*n[2]+s[12],s[1]*n[0]+s[5]*n[1]+s[9]*n[2]+s[13],s[2]*n[0]+s[6]*n[1]+s[10]*n[2]+s[14]]:n}function ae(e,n){e.__ikWarned||(e.__ikWarned=new Set);let t=e.__ikWarned;t.has(n)||(t.add(n),console.warn(`[three-live] ik: joint '${n}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function me(e,n,t){if(Array.isArray(e))return[e[0],e[1],e[2]];let s=n.get(e);if(s)return le(s);let r;if(e==="head"?r=t?.headPose?.position??t?.headPose??t?.cameraPosition:e==="hand-left"?r=t?.handPoses?.left?.position??t?.handPoses?.left??t?.hands?.left?.position??t?.hands?.left:e==="hand-right"&&(r=t?.handPoses?.right?.position??t?.handPoses?.right??t?.hands?.right?.position??t?.hands?.right),(Array.isArray(r)||ArrayBuffer.isView(r))&&r.length>=3){let i=r;return Ye(t,[i[0],i[1],i[2]])}return null}function ce(e,n){return[e[3]*n[0]+e[0]*n[3]+e[1]*n[2]-e[2]*n[1],e[3]*n[1]-e[0]*n[2]+e[1]*n[3]+e[2]*n[0],e[3]*n[2]+e[0]*n[1]-e[1]*n[0]+e[2]*n[3],e[3]*n[3]-e[0]*n[0]-e[1]*n[1]-e[2]*n[2]]}function Ze(e){return[-e[0],-e[1],-e[2],e[3]]}function he(e){let n=Math.hypot(e[0],e[1],e[2],e[3]);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n,e[3]/n]:[0,0,0,1]}function en(e,n){if(n>=1)return e;if(n<=0)return[0,0,0,1];let[t,s,r,i]=e;i<0&&(t=-t,s=-s,r=-r,i=-i);let h=Math.acos(Math.min(1,i)),y=Math.sin(h);if(y<1e-9)return[0,0,0,1];let o=Math.sin(h*n)/y;return he([t*o,s*o,r*o,Math.cos(h*n)])}function nn(e){let n=Math.hypot(e[0],e[1],e[2])||1,t=Math.hypot(e[4],e[5],e[6])||1,s=Math.hypot(e[8],e[9],e[10])||1,r=e[0]/n,i=e[1]/n,h=e[2]/n,y=e[4]/t,o=e[5]/t,a=e[6]/t,c=e[8]/s,l=e[9]/s,m=e[10]/s,u=r+o+m,M;if(u>0){let f=Math.sqrt(u+1)*2;M=[(a-l)/f,(c-h)/f,(i-y)/f,.25*f]}else if(r>o&&r>m){let f=Math.sqrt(1+r-o-m)*2;M=[.25*f,(y+i)/f,(c+h)/f,(a-l)/f]}else if(o>m){let f=Math.sqrt(1+o-r-m)*2;M=[(y+i)/f,.25*f,(l+a)/f,(c-h)/f]}else{let f=Math.sqrt(1+m-r-o)*2;M=[(c+h)/f,(l+a)/f,.25*f,(i-y)/f]}return he(M)}function tn(e,n,t){let[s,r,i,h]=t,y=1-2*(r*r+i*i),o=2*(s*r-i*h),a=2*(s*i+r*h),c=2*(s*r+i*h),l=1-2*(s*s+i*i),m=2*(r*i-s*h),u=2*(s*i-r*h),M=2*(r*i+s*h),f=1-2*(s*s+r*r);for(let d=0;d<3;d++){let A=n[d*4],T=n[d*4+1],x=n[d*4+2];e[d*4]=y*A+o*T+a*x,e[d*4+1]=c*A+l*T+m*x,e[d*4+2]=u*A+M*T+f*x}}function ee(e,n){let t=n[0]-e[0],s=n[1]-e[1],r=n[2]-e[2],i=Math.hypot(t,s,r);return i>1e-9?[t/i,s/i,r/i]:null}function Be(e){e?.normalMatrix&&e?.transform&&Z(e.normalMatrix,e.transform)}var Ee=new WeakMap;function rn(e){let n=Ee.get(e);return n||(n=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((t,s)=>{for(let r of Array.isArray(t?.children)?t.children:[])typeof r=="number"&&r>=0&&r<n.length&&(n[r]=s)}),Ee.set(e,n)),n}function on(e,n,t){let s=e?.gltf,r=s?.nodes;if(!Array.isArray(r)||r.length===0)return!1;let i=new Map;r.forEach((p,b)=>{typeof p?.name=="string"&&p.name&&!i.has(p.name)&&i.set(p.name,b)});let y=(n.mid?[n.root,n.mid,n.effector]:[n.root,n.effector]).map(p=>i.get(p));if(y.some(p=>p===void 0))return!1;let o=y,a=rn(s);for(let p=1;p<o.length;p++){let b=a[o[p]],I=0;for(;b>=0&&b!==o[p-1]&&I++<256;)b=a[b];if(b!==o[p-1])return!1}let c=o[0],l=e.initialNodeTransforms,m=new Map,u=[],M=[c];for(;M.length&&u.length<4096;){let p=M.pop();if(m.has(p))continue;let b=l?.[p],I=r[p];m.set(p,{t:b?[b.t[0],b.t[1],b.t[2]]:I?.translation?[...I.translation]:[0,0,0],r:b?[b.r[0],b.r[1],b.r[2],b.r[3]]:I?.rotation?[...I.rotation]:[0,0,0,1],s:b?[b.s[0],b.s[1],b.s[2]]:I?.scale?[...I.scale]:[1,1,1]}),u.push(p);for(let V of Array.isArray(I?.children)?I.children:[])typeof V=="number"&&M.push(V)}let f=a[c],d=f>=0&&e.worldMatrices?.[f]?.length===16?Float32Array.from(e.worldMatrices[f]):N(),A=new Map,T=()=>{let p=(b,I)=>{let V=m.get(b);if(!V)return;let w=N();J(w,V.r,V.t,V.s);let S=N();ie(S,I,w),A.set(b,S);for(let E of Array.isArray(r[b]?.children)?r[b].children:[])typeof E=="number"&&p(E,S)};p(c,d)},x=p=>{let b=A.get(p);return[b[12],b[13],b[14]]};T();let g=o.map(x),F=p=>{if(typeof p=="string"&&!t.has(p)){let b=i.get(p),I=b!==void 0?A.get(b)??e.worldMatrices?.[b]:void 0;if(I&&I.length===16)return[I[12],I[13],I[14]]}return me(p,t,e)},R=F(n.target);if(!R)return!0;let k=n.pole?F(n.pole)??void 0:void 0,v=Ce(g,n,R,k),_=Le(n.weight,0,1,1);for(let p=0;p<o.length-1;p++){let b=ee(x(o[p]),x(o[p+1])),I=ee(v[p],v[p+1]);if(!b||!I)continue;let V=en(ne(b,I),_),w=o[p],S=a[w],E=S===f||S<0?d:A.get(S)??d,B=nn(E),C=m.get(w);C.r=he(ce(Ze(B),ce(V,ce(B,C.r)))),T()}if(Array.isArray(e.worldMatrices))for(let[p,b]of A)e.worldMatrices[p]?.set&&e.worldMatrices[p].set(b);for(let p of e.meshes??[]){let b=A.get(p?.nodeIndex);b&&p.transform?.set&&(p.transform.set(b),Be(p))}return!0}function Ce(e,n,t,s){if(n.solver==="two-bone"&&e.length===3){let r=fe(e[0],e[1],e[2],t,s);return[e[0],r.midPos,r.effectorPos]}return de(e,t,n.iterations,n.tolerance).positions}function sn(e,n,t){let s=e.__ikRestOffsets,r=e.__ikRestMats;if(!(!s||!r))for(let i=0;i<n.length-1;i++){let h=n[i]?.transform??n[i]?.modelMatrix,y=r[i],o=ee([0,0,0],s[i]),a=ee(t[i],t[i+1]);!h||h.length<16||!y||y.length<16||!o||!a||(tn(h,y,ne(o,a)),Be(n[i]))}}var ye={name:"ik",onRegister(){let e=Q();Se(ue),ue(e.threeNamespace,e)},onUpdate(e){let n=e?.meshes;if(!Array.isArray(n)||n.length===0)return;let t=null;for(let s of n){let r=s?.userData?.xr?.ik??s?.extras?.xr?.ik??s?.extensions?.ANDROID_xr_scenecore?.ik;if(!r)continue;let i=$e(r);if(!i||i.weight<=0)continue;if(!t){t=new Map;for(let g of n)g&&typeof g.name=="string"&&g.name&&t.set(g.name,g)}if(on(e,i,t))continue;let h=t.get(i.root),y=t.get(i.effector),o=i.mid?t.get(i.mid):void 0;if(h||ae(s,i.root),y||ae(s,i.effector),i.mid&&!o&&ae(s,i.mid),!h||!y)continue;let a=me(i.target,t,e);if(!a)continue;let c=i.pole?me(i.pole,t,e)??void 0:void 0,l=o?[h,o,y]:[h,y],m=l.map(g=>g.name||"").join(">");if(!s.__ikRestOffsets||s.__ikRestKey!==m){let g=l.map(le),F=[];for(let R=0;R<g.length-1;R++)F.push([g[R+1][0]-g[R][0],g[R+1][1]-g[R][1],g[R+1][2]-g[R][2]]);s.__ikRestOffsets=F,s.__ikRestKey=m,s.__ikRestMats=l.map(R=>Array.from(R.transform??R.modelMatrix??[]))}let u=s.__ikRestOffsets,f=[le(h)],d=[];for(let g=0;g<u.length;g++){let F=f[g],R=u[g];f.push([F[0]+R[0],F[1]+R[1],F[2]+R[2]]),d.push(Math.hypot(R[0],R[1],R[2]))}let A=Ce(f,i,a,c),T=f[0],x=[f[0]];for(let g=1;g<l.length;g++){let F=u[g-1],R=[T[0]+F[0],T[1]+F[1],T[2]+F[2]],k=[T[0]+(A[g][0]-A[g-1][0]),T[1]+(A[g][1]-A[g-1][1]),T[2]+(A[g][2]-A[g-1][2])],v=qe(T,R,k,d[g-1],i.weight);He(l[g],v),T=v,x.push(v)}sn(s,l,x)}}};var an={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function W(e,n,t,s){if(!t||t.bufferView===void 0)return null;let r=e.bufferViews?.[t.bufferView];if(!r)return null;let i=Number(t.count??0);if(!Number.isInteger(i)||i<=0)return null;let h=t.componentType??5126,y=an[h];if(!y)throw new RangeError(`glTF accessor has unsupported componentType ${h}`);let o=y*s,a=r.byteStride&&r.byteStride>0?r.byteStride:o,c=(r.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(c)||c<0||a<o||c+(i-1)*a+o>n.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${n.byteLength} bytes)`);if(h===5126&&a===o&&c%4===0)return new Float32Array(n,c,i*s);let l=new DataView(n),m=t.normalized===!0,u=new Float32Array(i*s);for(let M=0;M<i;M++){let f=c+M*a;for(let d=0;d<s;d++){let A=f+d*y,T;switch(h){case 5126:T=l.getFloat32(A,!0);break;case 5120:T=l.getInt8(A),m&&(T=Math.max(T/127,-1));break;case 5121:T=l.getUint8(A),m&&(T/=255);break;case 5122:T=l.getInt16(A,!0),m&&(T=Math.max(T/32767,-1));break;case 5123:T=l.getUint16(A,!0),m&&(T/=65535);break;default:T=l.getUint32(A,!0),m&&(T/=4294967295)}u[M*s+d]=T}}return u}function Pe(e,n,t){return n%4===0?new Float32Array(e,n,t):new Float32Array(e.slice(n,n+t*4))}function Oe(e,n,t,s){let r=n[0],i=n[1],h=n[2],y=n[3],o=t[0],a=t[1],c=t[2],l=t[3],m=r*o+i*a+h*c+y*l;if(m<0&&(o=-o,a=-a,c=-c,l=-l,m=-m),Math.abs(m)>=1)return e[0]=r,e[1]=i,e[2]=h,e[3]=y,e;let u=Math.acos(m),M=Math.sqrt(1-m*m);if(Math.abs(M)<.001)return e[0]=.5*(r+o),e[1]=.5*(i+a),e[2]=.5*(h+c),e[3]=.5*(y+l),e;let f=Math.sin((1-s)*u)/M,d=Math.sin(s*u)/M;return e[0]=r*f+o*d,e[1]=i*f+a*d,e[2]=h*f+c*d,e[3]=y*f+l*d,e}function Ke(e,n,t,s){return e[0]=n[0]+s*(t[0]-n[0]),e[1]=n[1]+s*(t[1]-n[1]),e[2]=n[2]+s*(t[2]-n[2]),e}function be(e,n){if(!Array.isArray(e?.animations))return[];let t=[];for(let s=0;s<e.animations.length;s++){let r=e.animations[s],i=r.name||`Animation_${s}`,h=[],y=0;if(Array.isArray(r.channels)&&Array.isArray(r.samplers))for(let o of r.channels){if(!o.target||o.target.node===void 0||!o.target.path)continue;let a=r.samplers[o.sampler];if(!a)continue;let c=e.accessors?.[a.input],l=e.accessors?.[a.output];if(!c||!l)continue;let m=e.bufferViews?.[c.bufferView],u=e.bufferViews?.[l.bufferView];if(!m||!u)continue;let M=(m.byteOffset||0)+(c.byteOffset||0),f=(u.byteOffset||0)+(l.byteOffset||0),d=W(e,n,c,1)??Pe(n,M,c.count);d.length>0&&d[d.length-1]>y&&(y=d[d.length-1]);let A=o.target.path==="rotation"?4:o.target.path==="weights"?Math.max(1,Math.round(l.count/Math.max(1,c.count))):3,T=o.target.path==="weights"?1:A,x=W(e,n,l,T)??Pe(n,f,l.count*T),g=a.interpolation==="STEP"?"STEP":"LINEAR";h.push({nodeIndex:o.target.node,path:o.target.path,times:d,values:x,interpolation:g})}h.length>0&&t.push({name:i,duration:y,channels:h})}return t}function U(e,n,t){let{times:s,values:r,path:i,interpolation:h}=e,y=s.length;if(y===0)return;let o=i==="rotation"?4:i==="weights"?Math.max(1,Math.round(r.length/y)):3;if(n<=s[0]){for(let T=0;T<o;T++)t[T]=r[T];return}if(n>=s[y-1]){let T=(y-1)*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let a=0,c=y-1;for(;a<=c;){let T=a+c>>1;s[T]<=n?a=T+1:c=T-1}let l=Math.max(0,c),m=Math.min(y-1,l+1);if(h==="STEP"||l===m){let T=l*o;for(let x=0;x<o;x++)t[x]=r[T+x];return}let u=s[l],M=s[m],f=(n-u)/Math.max(1e-5,M-u),d=l*o,A=m*o;if(i==="rotation"){let T=[r[d],r[d+1],r[d+2],r[d+3]],x=[r[A],r[A+1],r[A+2],r[A+3]];Oe(t,T,x,f)}else for(let T=0;T<o;T++)t[T]=r[d+T]+f*(r[A+T]-r[d+T])}var te=new WeakMap;function ge(e,n,t=.3){if(!e?.animations)return;let s=e.animations.find(y=>y.name===n);if(!s)return;let r=te.get(e);r||(r=[],e.currentClip&&r.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),te.set(e,r));let i=t>0?1/t:1e3;for(let y of r)y.clip.name!==n&&(y.fadeSpeed=-i);let h=r.find(y=>y.clip.name===n);h?h.fadeSpeed=i:r.push({clip:s,time:0,weight:t>0?0:1,fadeSpeed:i}),e.currentClip=s,e.isPlayingAnimation=!0}function pe(e,n){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let t=te.get(e);if(!t||t.length===0){if(!e.currentClip)return;t=[{clip:e.currentClip,time:n,weight:1,fadeSpeed:0}]}let s=e.gltf.nodes.length,r=[];for(let l=0;l<s;l++){let m=e.initialNodeTransforms[l];m?r.push({t:[m.t[0],m.t[1],m.t[2]],r:[m.r[0],m.r[1],m.r[2],m.r[3]],s:[m.s[0],m.s[1],m.s[2]]}):r.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let i=[0,0,0],h=[0,0,0,1],y=[1,1,1],o=new Float32Array(64);for(let l of t){let m=Math.max(0,Math.min(1,l.weight));if(!(m<=1e-4))for(let u of l.clip.channels){if(u.nodeIndex<0||u.nodeIndex>=s)continue;let M=r[u.nodeIndex];if(u.path==="translation")U(u,l.time,i),Ke(M.t,M.t,i,m);else if(u.path==="rotation")U(u,l.time,h),Oe(M.r,M.r,h,m);else if(u.path==="scale")U(u,l.time,y),Ke(M.s,M.s,y,m);else if(u.path==="weights"&&(U(u,l.time,o),e.meshes)){for(let f of e.meshes)if(f.nodeIndex===u.nodeIndex){for(let d of f.primitives)if(d.pluginData?.morph?.weights){let A=d.pluginData.morph.weights,T=d.pluginData.morph.numTargets||A.length;for(let x=0;x<T;x++)A[x]=A[x]*(1-m)+o[x]*m}}}}}let a=[];for(let l=0;l<s;l++){let m=N(),{t:u,r:M,s:f}=r[l];J(m,M,u,f),a.push(m)}let c=_e(e.gltf,a);e.worldMatrices=c;for(let l of e.meshes)l.nodeIndex>=0&&l.nodeIndex<c.length&&(l.transform.set(c[l.nodeIndex]),Z(l.normalMatrix,l.transform))}var Ae={name:"keyframes",evaluateAnimation:pe,crossFadeTo:ge,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=be(e.gltf,e.bin))},onUpdate(e,n){if(!e.isPlayingAnimation)return;let t=te.get(e);if(t&&t.length>0){for(let s=t.length-1;s>=0;s--){let r=t[s];if(r.time+=n,r.clip.duration>0&&(r.time%=r.clip.duration),r.fadeSpeed!==0)if(r.weight+=r.fadeSpeed*n,r.weight<=0){t.splice(s,1);continue}else r.weight>=1&&(r.weight=1,r.fadeSpeed=0)}t.length>0&&(e.animationTime=t[t.length-1].time),pe(e,e.animationTime)}else e.currentClip&&(e.animationTime+=n,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),pe(e,e.animationTime))}};var $=64;function We(e,n,t){if(!(!e?.meshes||n<0||n>=$))for(let s of e.meshes)for(let r of s.primitives){let i=r.pluginData?.morph;i?.weights&&(i.weights[n]=t)}}var Te={name:"morph",onResolveShader(e,n,t,s){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let r=t.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
18
18
  uniform sampler2D uMorphDeltasTex;
19
19
  uniform float uMorphWeights[${$}];
20
20
  uniform int uNumMorphTargets;`);return r=r.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
@@ -25,12 +25,12 @@ for (int m = 0; m < ${$}; m++) {
25
25
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
26
26
  }
27
27
  }
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;
28
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.targets;if(!Array.isArray(i)||i.length===0)return null;let h=t.attributes?.POSITION,y=s?.accessors?.[h];if(!y)return null;let o=y.count,a=Math.min(i.length,$),c=new Float32Array(o*a*4);for(let u=0;u<a;u++){let M=i[u].POSITION;if(M===void 0)continue;let f=s.accessors?.[M],d=s.bufferViews?.[f?.bufferView];if(!f||!d)continue;let A=W(s,r,f,3);if(!A||A.length<o*3)continue;let T=u*o*4;for(let x=0;x<o;x++)c[T+x*4]=A[x*3],c[T+x*4+1]=A[x*3+1],c[T+x*4+2]=A[x*3+2],c[T+x*4+3]=0}let l=e.createTexture();e.bindTexture(3553,l),e.texImage2D(3553,0,34836,o,a,0,6408,5126,c),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array($);return{hasMorph:!0,morphTex:l,numTargets:a,vertexCount:o,weights:m}},onBeforeDrawPrimitive(e,n,t,s,r,i){let h=t.pluginData?.morph;if(!h?.hasMorph||!h.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,h.morphTex);let y=e.getUniformLocation(n,"uMorphDeltasTex");y&&e.uniform1i(y,5);let o=e.getUniformLocation(n,"uNumMorphTargets");o&&e.uniform1i(o,h.numTargets);let a=e.getUniformLocation(n,"uMorphWeights[0]");a&&e.uniform1fv(a,h.weights)}};var xe=64,Me={name:"skinning",onResolveShader(e,n,t,s){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let r=t.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
29
29
  layout(location=4) in uvec4 aJoints;
30
30
  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 =
31
+ uniform mat4 uJointMatrix[${xe}];`),i=r.includes("morphedPos")?"morphedPos":"aPosition";return r=r.replace(`vec4 world=uModel*vec4(${i},1.0);`,`mat4 skinMatrix =
32
32
  aWeights.x * uJointMatrix[int(aJoints.x)] +
33
33
  aWeights.y * uJointMatrix[int(aJoints.y)] +
34
34
  aWeights.z * uJointMatrix[int(aJoints.z)] +
35
35
  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);})();
36
+ vec4 world=uModel*(skinMatrix*vec4(${i},1.0));`).replace(`gl_Position=uMVP*vec4(${i},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${i},1.0));`),{vs:r,fs:s}},onBuildPrimitiveVAO(e,n,t,s,r){let i=t?.attributes;if(!i||i.JOINTS_0===void 0||i.WEIGHTS_0===void 0)return null;let h=s.accessors[i.JOINTS_0],y=s.accessors[i.WEIGHTS_0];if(!h||!y)return null;let o=s.bufferViews[h.bufferView],a=s.bufferViews[y.bufferView];if(!o||!a)return null;let c=(o.byteOffset||0)+(h.byteOffset||0),l=(a.byteOffset||0)+(y.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let u=h.componentType===5121?5121:5123,M=u===5121?new Uint8Array(r,c,h.count*4):new Uint16Array(r,c,h.count*4);e.bufferData(34962,M,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,u,0,0);let f=e.createBuffer();e.bindBuffer(34962,f);let d=W(s,r,y,4)??new Float32Array(r,l,y.count*4);return e.bufferData(34962,d,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,f]}},onBeforeDrawPrimitive(e,n,t,s,r,i){if(!t.pluginData?.skinning?.hasSkin)return;let h=i?.nodes?.[s.nodeIndex]?.skin;if(h===void 0||!i.skins||!i.skins[h])return;let o=i.skins[h].joints||[],a=new Float32Array(xe*16);for(let l=0;l<o.length&&l<xe;l++){let m=o[l],u=r[m]||N();a.subarray(l*16,(l+1)*16).set(u)}let c=e.getUniformLocation(n,"uJointMatrix[0]");c&&e.uniformMatrix4fv(c,!1,a)}};X(Te);X(Ae);X(Me);X(ye);return Je(cn);})();