greenlight-motion 0.3.4 → 0.5.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.
@@ -0,0 +1 @@
1
+ (function(){"use strict";function kt(t){const s=t.position;if(!s.length)return{min:[0,0,0],max:[0,0,0]};const e=[1/0,1/0,1/0],$=[-1/0,-1/0,-1/0];for(let c=0;c<s.length;c+=3)for(let l=0;l<3;l+=1){const p=s[c+l];p<e[l]&&(e[l]=p),p>$[l]&&($[l]=p)}return{min:e,max:$}}function wt(t,s){const e=t.length/3,$=new Int32Array(e);if(!e)return $;let c=s;if(c==null){const{min:i,max:d}=kt({position:t});c=Math.max(1e-7,Math.hypot(d[0]-i[0],d[1]-i[1],d[2]-i[2])*1e-6)}const l=1/(c*4),p=c*c;let f=16;for(;f<e*2;)f*=2;const r=f-1,x=new Int32Array(f).fill(-1),y=new Int32Array(e),a=(i,d,m)=>(Math.imul(i,73856093)^Math.imul(d,19349663)^Math.imul(m,83492791))&r;for(let i=0;i<e;i+=1){const d=t[i*3],m=t[i*3+1],o=t[i*3+2],k=d*l,w=m*l,h=o*l,g=Math.floor(k),L=Math.floor(w),u=Math.floor(h),z=k-g<.25?g-1:g,O=k-g>.75?g+1:g,j=w-L<.25?L-1:L,E=w-L>.75?L+1:L,R=h-u<.25?u-1:u,N=h-u>.75?u+1:u;let n=-1;for(let F=z;F<=O&&n<0;F+=1)for(let b=j;b<=E&&n<0;b+=1)for(let A=R;A<=N&&n<0;A+=1)for(let I=x[a(F,b,A)];I>=0;I=y[I]){const v=t[I*3]-d,T=t[I*3+1]-m,_=t[I*3+2]-o;if(v*v+T*T+_*_<=p){n=I;break}}if(n>=0){$[i]=n;continue}$[i]=i;const M=a(g,L,u);y[i]=x[M],x[M]=i}return $}function at(t,s,e){const $=e[0]-s[0],c=e[1]-s[1],l=e[2]-s[2],p=$*$+c*c+l*l;if(!(p>0))return 0;const f=((t[0]-s[0])*$+(t[1]-s[1])*c+(t[2]-s[2])*l)/p;return f<0?0:f>1?1:f}function bt(t,s){const e=t.length/3,$=wt(t),c=new Int32Array(e);let l=0;for(let h=0;h<e;h+=1)c[h]=$[h]===h?l++:-1;for(let h=0;h<e;h+=1)$[h]!==h&&(c[h]=c[$[h]]);const p=new Float64Array(l*3);for(let h=0;h<e;h+=1)if($[h]===h){const g=c[h]*3;p[g]=t[h*3],p[g+1]=t[h*3+1],p[g+2]=t[h*3+2]}const f=s||Uint32Array.from({length:e},(h,g)=>g),r=[];for(let h=0;h<f.length;h+=3){const g=c[f[h]],L=c[f[h+1]],u=c[f[h+2]];g===L||L===u||g===u||r.push(g,L,u)}const x=Int32Array.from(r),y=Int32Array.from({length:l},(h,g)=>g),a=h=>{for(;y[h]!==h;)y[h]=y[y[h]],h=y[h];return h};for(let h=0;h<x.length;h+=3){const g=a(x[h]),L=a(x[h+1]),u=a(x[h+2]);y[L]=g,y[a(u)]=g}const i=new Map,d=new Int32Array(l);for(let h=0;h<l;h+=1){const g=a(h);i.has(g)||i.set(g,i.size),d[h]=i.get(g)}const m=new Float64Array(l*3);for(let h=0;h<x.length;h+=3){const g=x[h]*3,L=x[h+1]*3,u=x[h+2]*3,z=p[L]-p[g],O=p[L+1]-p[g+1],j=p[L+2]-p[g+2],E=p[u]-p[g],R=p[u+1]-p[g+1],N=p[u+2]-p[g+2],n=O*N-j*R,M=j*E-z*N,F=z*R-O*E;for(const b of[g,L,u])m[b]+=n,m[b+1]+=M,m[b+2]+=F}for(let h=0;h<l;h+=1){const g=Math.hypot(m[h*3],m[h*3+1],m[h*3+2])||1;m[h*3]/=g,m[h*3+1]/=g,m[h*3+2]/=g}let o=[1/0,1/0,1/0],k=[-1/0,-1/0,-1/0];for(let h=0;h<l;h+=1)for(let g=0;g<3;g+=1)o[g]=Math.min(o[g],p[h*3+g]),k[g]=Math.max(k[g],p[h*3+g]);l||(o=[0,0,0],k=[0,0,0]);const w=Math.hypot(k[0]-o[0],k[1]-o[1],k[2]-o[2])||1;return{n:e,m:l,pid:c,P:p,T:x,island:d,islands:i.size,N:m,diag:w,min:o,max:k}}function Mt(t,s){const e=s.length/3,$=Int32Array.from({length:e},(a,i)=>i),c=new Float64Array(e*3);for(let a=0;a<e;a+=1)for(let i=0;i<3;i+=1)c[a*3+i]=(t[s[a*3]*3+i]+t[s[a*3+1]*3+i]+t[s[a*3+2]*3+i])/3;const l=[],p=[],f=[],r=[],x=[],y=(a,i)=>{const d=r.length;let m=1/0,o=1/0,k=1/0,w=-1/0,h=-1/0,g=-1/0;for(let A=a;A<i;A+=1){const I=$[A];for(let v=0;v<3;v+=1){const T=s[I*3+v]*3;t[T]<m&&(m=t[T]),t[T]>w&&(w=t[T]),t[T+1]<o&&(o=t[T+1]),t[T+1]>h&&(h=t[T+1]),t[T+2]<k&&(k=t[T+2]),t[T+2]>g&&(g=t[T+2])}}if(l.push(m,o,k,w,h,g),r.push(a),x.push(i-a),p.push(-1),f.push(-1),i-a<=4)return d;let L=1/0,u=1/0,z=1/0,O=-1/0,j=-1/0,E=-1/0;for(let A=a;A<i;A+=1){const I=$[A]*3;c[I]<L&&(L=c[I]),c[I]>O&&(O=c[I]),c[I+1]<u&&(u=c[I+1]),c[I+1]>j&&(j=c[I+1]),c[I+2]<z&&(z=c[I+2]),c[I+2]>E&&(E=c[I+2])}const R=[O-L,j-u,E-z],N=R[0]>=R[1]&&R[0]>=R[2]?0:R[1]>=R[2]?1:2,n=Array.from($.subarray(a,i)).sort((A,I)=>c[A*3+N]-c[I*3+N]);$.set(n,a);const M=a+i>>1,F=y(a,M),b=y(M,i);return p[d]=F,f[d]=b,d};return e&&y(0,e),{box:Float64Array.from(l),left:Int32Array.from(p),right:Int32Array.from(f),start:Int32Array.from(r),size:Int32Array.from(x),order:$}}function $t(t,s,e,$,c,l,p,f,r,x,y,a){if(!t.start.length)return!1;const i=1/x,d=1/y,m=1/a,o=[0],k=1e-6;for(;o.length;){const w=o.pop(),h=w*6;let g=0,L=1,u=(t.box[h]-p)*i,z=(t.box[h+3]-p)*i;if(u>z){const O=u;u=z,z=O}if(u>g&&(g=u),z<L&&(L=z),u=(t.box[h+1]-f)*d,z=(t.box[h+4]-f)*d,u>z){const O=u;u=z,z=O}if(u>g&&(g=u),z<L&&(L=z),u=(t.box[h+2]-r)*m,z=(t.box[h+5]-r)*m,u>z){const O=u;u=z,z=O}if(u>g&&(g=u),z<L&&(L=z),g<=L){if(t.left[w]>=0){o.push(t.left[w],t.right[w]);continue}for(let O=t.start[w],j=O+t.size[w];O<j;O+=1){const E=t.order[O];if($[E]!==c)continue;const R=e[E*3],N=e[E*3+1],n=e[E*3+2];if(R===l||N===l||n===l)continue;const M=s[N*3]-s[R*3],F=s[N*3+1]-s[R*3+1],b=s[N*3+2]-s[R*3+2],A=s[n*3]-s[R*3],I=s[n*3+1]-s[R*3+1],v=s[n*3+2]-s[R*3+2],T=y*v-a*I,_=a*A-x*v,q=x*I-y*A,P=M*T+F*_+b*q;if(Math.abs(P)<1e-18)continue;const Y=1/P,H=p-s[R*3],V=f-s[R*3+1],B=r-s[R*3+2],D=(H*T+V*_+B*q)*Y;if(D<-k||D>1+k)continue;const C=V*b-B*F,G=B*M-H*b,tt=H*F-V*M,gt=(x*C+y*G+a*tt)*Y;if(gt<-k||D+gt>1+k)continue;const yt=(A*C+I*G+v*tt)*Y;if(yt>1e-4&&yt<1-1e-4)return!0}}}return!1}function xt(t){const{m:s,P:e,T:$}=t,c=new Map,l=new Float64Array(s),p=(o,k,w)=>{const h=o<k?o*s+k:k*s+o;c.set(h,(c.get(h)||0)+w)},f=(o,k,w)=>{const h=e[k*3]-e[o*3],g=e[k*3+1]-e[o*3+1],L=e[k*3+2]-e[o*3+2],u=e[w*3]-e[o*3],z=e[w*3+1]-e[o*3+1],O=e[w*3+2]-e[o*3+2],j=h*u+g*z+L*O,E=g*O-L*z,R=L*u-h*O,N=h*z-g*u,n=Math.hypot(E,R,N);return{c:n>1e-30?j/n:0,area:n/2}};for(let o=0;o<$.length;o+=3){const k=$[o],w=$[o+1],h=$[o+2],g=f(k,w,h),L=f(w,h,k),u=f(h,k,w);p(w,h,g.c/2),p(h,k,L.c/2),p(k,w,u.c/2);const z=g.area/3;l[k]+=z,l[w]+=z,l[h]+=z}let r=0;for(const o of c.values())r+=Math.abs(o);r=c.size?r/c.size:1;const x=r*1e-4,y=Array.from({length:s},()=>[]),a=new Float64Array(s);for(const[o,k]of c){const w=Math.floor(o/s),h=o-w*s,g=Math.max(k,x);y[w].push(h,g),y[h].push(w,g),a[w]+=g,a[h]+=g}const i=new Int32Array(s+1);for(let o=0;o<s;o+=1)i[o+1]=i[o]+y[o].length/2;const d=new Int32Array(i[s]),m=new Float64Array(i[s]);for(let o=0;o<s;o+=1){const k=y[o];for(let w=0,h=i[o];w<k.length;w+=2,h+=1)d[h]=k[w],m[h]=-k[w+1]}return{ptr:i,col:d,val:m,diag:a,mass:l}}function At(t,s,e,$,c,l,{tol:p=1e-4,maxIter:f=2e3}={}){const r=e.length,{ptr:x,col:y,val:a,diag:i}=t,d=$,m=new Float64Array(r),o=new Float64Array(r),k=new Float64Array(r),w=new Float64Array(r),h=new Float64Array(r);for(let j=0;j<r;j+=1){const E=e[j],R=i[E]+s[E];h[j]=R>0?1/R:0}const g=(j,E)=>{for(let R=0;R<r;R+=1){const N=e[R];let n=(i[N]+s[N])*j[R];for(let M=x[N],F=x[N+1];M<F;M+=1){const b=d[y[M]];b&&(n+=a[M]*j[b-1])}E[R]=n}};g(l,w);let L=0,u=0;for(let j=0;j<r;j+=1)m[j]=c[j]-w[j],o[j]=m[j]*h[j],k[j]=o[j],L+=m[j]*o[j],u+=m[j]*m[j];const z=Math.sqrt(u)||1;let O=0;for(;O<f&&Math.sqrt(u)/z>=p;O+=1){g(k,w);let j=0;for(let n=0;n<r;n+=1)j+=k[n]*w[n];if(!(j>0))break;const E=L/j;let R=0;u=0;for(let n=0;n<r;n+=1)l[n]+=E*k[n],m[n]-=E*w[n],o[n]=m[n]*h[n],R+=m[n]*o[n],u+=m[n]*m[n];const N=R/L;L=R;for(let n=0;n<r;n+=1)k[n]=o[n]+N*k[n]}return O}function It(t,s,e,{tol:$=1e-4,maxIter:c=3e3,visibility:l=!0,parents:p=null}={}){const{m:f,P:r,T:x,island:y}=t,a=e,i=new Float32Array(f*a),d={points:f,triangles:x.length/3,islands:t.islands,unseen:0,iterations:0,solves:0,fallback:0};if(!f||!s.length)return{W:i,stats:d};const m=xt(t),o=new Int32Array(x.length/3);for(let b=0;b<o.length;b+=1)o[b]=y[x[b*3]];const k=l?Mt(r,x):null,w=new Float64Array(f),h=new Int32Array(f*4).fill(-1),g=new Float64Array(f),L=new Int32Array(f),u=s.map(b=>({joint:b.joint,a:b.a,b:b.b})),z=new Float64Array(u.length),O=Array.from({length:u.length},(b,A)=>A),j=[0,0,0],E=t.diag*1e-5;for(let b=0;b<f;b+=1){const A=[r[b*3],r[b*3+1],r[b*3+2]];for(let _=0;_<u.length;_+=1){const q=at(A,u[_].a,u[_].b),P=u[_].a[0]+(u[_].b[0]-u[_].a[0])*q-A[0],Y=u[_].a[1]+(u[_].b[1]-u[_].a[1])*q-A[1],H=u[_].a[2]+(u[_].b[2]-u[_].a[2])*q-A[2];z[_]=Math.hypot(P,Y,H)}O.sort((_,q)=>z[_]-z[q]),L[b]=u[O[0]].joint;let I=-1,v=0;for(let _=0;_<O.length&&_<8;_+=1){const q=O[_];if(I>=0&&z[q]>I*(1+1e-6)+1e-12)break;const P=at(A,u[q].a,u[q].b);j[0]=u[q].a[0]+(u[q].b[0]-u[q].a[0])*P,j[1]=u[q].a[1]+(u[q].b[1]-u[q].a[1])*P,j[2]=u[q].a[2]+(u[q].b[2]-u[q].a[2])*P;let Y=!0;if(k){const H=A[0]-t.N[b*3]*E,V=A[1]-t.N[b*3+1]*E,B=A[2]-t.N[b*3+2]*E;Y=!$t(k,r,x,o,y[b],b,H,V,B,j[0]-H,j[1]-V,j[2]-B)}Y&&(I<0&&(I=z[q]),v<4&&!Array.from(h.subarray(b*4,b*4+v)).includes(u[q].joint)&&(h[b*4+v++]=u[q].joint))}if(I<0){d.unseen+=1;continue}const T=Math.max(I,t.diag*1e-4);w[b]=1/(T*T),g[b]=1/v}const R=new Float64Array(f);for(let b=0;b<f;b+=1)R[b]=m.mass[b]*w[b];const N=[];for(let b=0;b<a;b+=1){let A=!1;for(let I=0;I<f*4&&!A;I+=1)h[I]===b&&(A=!0);A&&N.push(b)}const n=p?Array.from({length:a},(b,A)=>new Set([A,...p[A]>=0?[p[A]]:[],...p.flatMap((I,v)=>I===A?[v]:[])])):null,M=Array.from({length:f},(b,A)=>{const I=[];for(let v=0;v<4;v+=1)h[A*4+v]>=0&&I.push(h[A*4+v]);return I.length||I.push(L[A]),I}),F=new Int32Array(f);for(const b of N){const A=[];for(let T=0;T<f;T+=1)(!n||M[T].some(_=>n[_].has(b)))&&A.push(T);F.fill(0),A.forEach((T,_)=>{F[T]=_+1});const I=new Float64Array(A.length),v=new Float64Array(A.length);A.forEach((T,_)=>{for(let q=0;q<4;q+=1)h[T*4+q]===b&&(v[_]=g[T],I[_]=R[T]*g[T])}),d.iterations+=At(m,R,A,F,I,v,{tol:$,maxIter:c}),d.solves+=1,A.forEach((T,_)=>{const q=v[_];i[T*a+b]=q<0?0:q>1?1:q})}for(let b=0;b<f;b+=1){let A=0;for(let I=0;I<a;I+=1)A+=i[b*a+I];A<1e-6&&(i[b*a+L[b]]=1,d.fallback+=1)}return{W:i,stats:d}}function Lt(t,s,e){const{m:$,island:c,islands:l}=t,p=new Float64Array($),{T:f,P:r}=t;for(let a=0;a<f.length;a+=3){const i=f[a]*3,d=f[a+1]*3,m=f[a+2]*3,o=r[d]-r[i],k=r[d+1]-r[i+1],w=r[d+2]-r[i+2],h=r[m]-r[i],g=r[m+1]-r[i+1],L=r[m+2]-r[i+2],u=Math.hypot(k*L-w*g,w*h-o*L,o*g-k*h)/6;p[f[a]]+=u,p[f[a+1]]+=u,p[f[a+2]]+=u}const x=new Float64Array(l*e);for(let a=0;a<$;a+=1)for(let i=0;i<e;i+=1)x[c[a]*e+i]+=s[a*e+i]*(p[a]||1e-12);const y=new Int32Array(l);for(let a=0;a<l;a+=1){let i=0;for(let d=1;d<e;d+=1)x[a*e+d]>x[a*e+i]&&(i=d);y[a]=i}for(let a=0;a<$;a+=1){for(let i=0;i<e;i+=1)s[a*e+i]=0;s[a*e+y[c[a]]]=1}return y}function ot(t,s,e){for(let $=0;$<s;$+=1){let c=0;for(let l=0;l<e;l+=1)c+=t[$*e+l];if(c>0)for(let l=0;l<e;l+=1)t[$*e+l]/=c}}function lt(t,s,e,{iterations:$=2,strength:c=.5,mask:l=null}={}){const{m:p,T:f}=t,r=Array.from({length:p},()=>new Set);for(let y=0;y<f.length;y+=3){const a=f[y],i=f[y+1],d=f[y+2];r[a].add(i).add(d),r[i].add(a).add(d),r[d].add(a).add(i)}const x=new Float32Array(s.length);for(let y=0;y<$;y+=1){for(let a=0;a<p;a+=1){const i=(l?l[a]:1)*c,d=r[a];for(let m=0;m<e;m+=1){const o=s[a*e+m];if(!(i>0)||!d.size){x[a*e+m]=o;continue}let k=0;for(const w of d)k+=s[w*e+m];x[a*e+m]=o+(k/d.size-o)*i}}s.set(x)}}function Ft(t,s,e,{threshold:$=.01,max:c=4}={}){const{n:l,m:p,pid:f}=t,r=new Uint16Array(p*4),x=new Float32Array(p*4),y=[];let a=0,i=0;for(let o=0;o<p;o+=1){y.length=0;for(let g=0;g<e;g+=1)s[o*e+g]>0&&y.push(g);y.sort((g,L)=>s[o*e+L]-s[o*e+g]);let k=y.slice(0,c).filter((g,L)=>L===0||s[o*e+g]>=$);k.length||(k=[0]),y.length>k.length&&(a+=1),i=Math.max(i,Math.min(y.length,c));let w=0;for(const g of k)w+=s[o*e+g];for(let g=0;g<4;g+=1){const L=k[g];r[o*4+g]=L??0,x[o*4+g]=L===void 0?0:w>0?s[o*e+L]/w:g===0?1:0}let h=0;for(let g=1;g<4;g+=1){const L=Math.round(x[o*4+g]*16777216)/16777216;x[o*4+g]=L,h+=L}x[o*4]=1-h}const d=new Uint16Array(l*4),m=new Float32Array(l*4);for(let o=0;o<l;o+=1){const k=f[o];d.set(r.subarray(k*4,k*4+4),o*4),m.set(x.subarray(k*4,k*4+4),o*4)}return{skinIndex:d,skinWeight:m,dropped:a,most:i}}const S=(t,s)=>[t[0]+s[0],t[1]+s[1],t[2]+s[2]],X=(t,s)=>[t[0]-s[0],t[1]-s[1],t[2]-s[2]],J=(t,s)=>[t[0]*s,t[1]*s,t[2]*s],nt=(t,s,e)=>S(t,J(X(s,t),e)),U=t=>Array.isArray(t)&&t.length===3&&t.every(Number.isFinite),ct={biped:{landmarks:["hips","spine","chest","neck","head","headTop","shoulder.L","elbow.L","wrist.L","handTip.L","hip.L","knee.L","ankle.L","ball.L","toe.L","shoulder.R","elbow.R","wrist.R","handTip.R","hip.R","knee.R","ankle.R","ball.R","toe.R"],joints:[{name:"hips",parent:null,at:"hips"},{name:"spine",parent:"hips",at:"spine"},{name:"chest",parent:"spine",at:"chest"},{name:"neck",parent:"chest",at:"neck"},{name:"head",parent:"neck",at:"head",tail:"headTop"},...["L","R"].flatMap(t=>[{name:`upperArm.${t}`,parent:"chest",at:`shoulder.${t}`},{name:`forearm.${t}`,parent:`upperArm.${t}`,at:`elbow.${t}`},{name:`hand.${t}`,parent:`forearm.${t}`,at:`wrist.${t}`,tail:`handTip.${t}`},{name:`thigh.${t}`,parent:"hips",at:`hip.${t}`},{name:`shin.${t}`,parent:`thigh.${t}`,at:`knee.${t}`},{name:`foot.${t}`,parent:`shin.${t}`,at:`ankle.${t}`},{name:`toe.${t}`,parent:`foot.${t}`,at:`ball.${t}`,tail:`toe.${t}`}])]},quadruped:{landmarks:["hips","spine","chest","neck","head","nose","tail","tailTip","shoulder.L","elbow.L","wrist.L","frontFoot.L","hip.L","knee.L","hock.L","hindFoot.L","shoulder.R","elbow.R","wrist.R","frontFoot.R","hip.R","knee.R","hock.R","hindFoot.R"],joints:[{name:"hips",parent:null,at:"hips"},{name:"spine",parent:"hips",at:"spine"},{name:"chest",parent:"spine",at:"chest"},{name:"neck",parent:"chest",at:"neck"},{name:"head",parent:"neck",at:"head",tail:"nose"},{name:"tail",parent:"hips",at:"tail",tail:"tailTip"},...["L","R"].flatMap(t=>[{name:`upperArm.${t}`,parent:"chest",at:`shoulder.${t}`},{name:`forearm.${t}`,parent:`upperArm.${t}`,at:`elbow.${t}`},{name:`frontFoot.${t}`,parent:`forearm.${t}`,at:`wrist.${t}`,tail:`frontFoot.${t}`},{name:`thigh.${t}`,parent:"hips",at:`hip.${t}`},{name:`shin.${t}`,parent:`thigh.${t}`,at:`knee.${t}`},{name:`hindFoot.${t}`,parent:`shin.${t}`,at:`hock.${t}`,tail:`hindFoot.${t}`}])]}},vt=Object.keys(ct);function ft(t){const s=/^(.*?)([._-])(L|R|Left|Right)$/.exec(t);if(!s)return null;const e={L:"R",R:"L",Left:"Right",Right:"Left"}[s[3]];return`${s[1]}${s[2]}${e}`}function st(t,s,e,$){const c=[],{P:l,m:p}=t;for(let f=0;f<p;f+=1)Math.abs(l[f*3+s]-e)<=$&&c.push([l[f*3],l[f*3+1],l[f*3+2]]);return c}function K(t,s,e,$=0){const{P:c,T:l,m:p}=t,f=new Map,r=[],x=[],y=d=>{for(;x[d]!==d;)x[d]=x[x[d]],d=x[d];return d},a=(d,m)=>{const o=d<m?d*p+m:m*p+d;let k=f.get(o);if(k===void 0){const w=c[d*3+s],h=c[m*3+s],g=(e-w)/(h-w);r.push([c[d*3]+(c[m*3]-c[d*3])*g,c[d*3+1]+(c[m*3+1]-c[d*3+1])*g,c[d*3+2]+(c[m*3+2]-c[d*3+2])*g]),k=r.length-1,x.push(k),f.set(o,k)}return k};for(let d=0;d<l.length;d+=3){const m=[l[d],l[d+1],l[d+2]],o=m.map(w=>c[w*3+s]>=e);if(o[0]===o[1]&&o[1]===o[2])continue;const k=[];for(let w=0;w<3;w+=1){const h=m[w],g=m[(w+1)%3];o[w]!==o[(w+1)%3]&&k.push(a(h,g))}if(k.length===2){const w=y(k[0]),h=y(k[1]);w!==h&&(x[h]=w)}}const i=new Map;return r.forEach((d,m)=>{const o=y(m);i.has(o)||i.set(o,[]),i.get(o).push(d)}),[...i.values()].map(d=>d.sort((m,o)=>m[$]-o[$]))}const zt=.5,Rt=.42,jt=.76,Q=t=>{if(!t.length)return null;let s=1/0,e=-1/0,$=1/0,c=-1/0,l=0;for(const p of t)s=Math.min(s,p[0]),e=Math.max(e,p[0]),$=Math.min($,p[2]),c=Math.max(c,p[2]),l+=p[1];return[(s+e)/2,l/t.length,($+c)/2]},Z=(t,s)=>t[0]*s[0]+t[1]*s[1]+t[2]*s[2],ht=t=>Math.hypot(t[0],t[1],t[2]),et=t=>{const s=ht(t)||1;return[t[0]/s,t[1]/s,t[2]/s]},ut=new WeakMap;function Nt(t){let s=ut.get(t);if(s)return s;const{P:e,T:$}=t;s=new Float64Array($.length/3*4);for(let c=0,l=0;c<$.length;c+=3,l+=4){const p=$[c]*3,f=$[c+1]*3,r=$[c+2]*3,x=(e[p]+e[f]+e[r])/3,y=(e[p+1]+e[f+1]+e[r+1])/3,a=(e[p+2]+e[f+2]+e[r+2])/3;let i=0;for(const d of[p,f,r])i=Math.max(i,Math.hypot(e[d]-x,e[d+1]-y,e[d+2]-a));s[l]=x,s[l+1]=y,s[l+2]=a,s[l+3]=i}return ut.set(t,s),s}function Tt(t,s,e,$){const{P:c,T:l,m:p}=t,f=Nt(t),r=new Map,x=[],y=[],a=[],i=u=>{for(;x[u]!==u;)x[u]=x[x[u]],u=x[u];return u},d=(u,z,O,j)=>{const E=u<z?u*p+z:z*p+u;let R=r.get(E);if(R===void 0){const N=O/(O-j);a.push([c[u*3]+(c[z*3]-c[u*3])*N,c[u*3+1]+(c[z*3+1]-c[u*3+1])*N,c[u*3+2]+(c[z*3+2]-c[u*3+2])*N]),R=a.length-1,x.push(R),y.push(0),r.set(E,R)}return R},m=[],o=[0,0,0],k=[0,0,0];for(let u=0,z=0;u<l.length;u+=3,z+=4){const O=f[z]-s[0],j=f[z+1]-s[1],E=f[z+2]-s[2],R=f[z+3];if(O*O+j*j+E*E>($+R)*($+R)||Math.abs(O*e[0]+j*e[1]+E*e[2])>R)continue;for(let D=0;D<3;D+=1){o[D]=l[u+D];const C=o[D]*3;k[D]=(c[C]-s[0])*e[0]+(c[C+1]-s[1])*e[1]+(c[C+2]-s[2])*e[2]}const N=[];for(let D=0;D<3;D+=1){const C=D,G=(D+1)%3;k[C]>=0!=k[G]>=0&&N.push(d(o[C],o[G],k[C],k[G]))}if(N.length!==2)continue;const n=o[0]*3,M=o[1]*3,F=o[2]*3,b=c[M]-c[n],A=c[M+1]-c[n+1],I=c[M+2]-c[n+2],v=c[F]-c[n],T=c[F+1]-c[n+1],_=c[F+2]-c[n+2],q=[A*_-I*T,I*v-b*_,b*T-A*v],P=[e[1]*q[2]-e[2]*q[1],e[2]*q[0]-e[0]*q[2],e[0]*q[1]-e[1]*q[0]];let[Y,H]=N;Z(X(a[H],a[Y]),P)<0&&([Y,H]=[H,Y]),y[Y]+=1,y[H]+=1,m.push(Y,H);const V=i(Y),B=i(H);V!==B&&(x[B]=V)}const w=et(Math.abs(e[0])<.9?[0,e[2],-e[1]]:[-e[2],0,e[0]]),h=[e[1]*w[2]-e[2]*w[1],e[2]*w[0]-e[0]*w[2],e[0]*w[1]-e[1]*w[0]],g=new Map;for(let u=0;u<m.length;u+=2){const z=a[m[u]],O=a[m[u+1]],j=Math.hypot(z[0]-O[0],z[1]-O[1],z[2]-O[2]),E=i(m[u]);let R=g.get(E);R||(R={sx:0,sy:0,sz:0,len:0,open:!1,far:0,area:0,ax:0,ay:0},g.set(E,R)),R.sx+=(z[0]+O[0])*.5*j,R.sy+=(z[1]+O[1])*.5*j,R.sz+=(z[2]+O[2])*.5*j,R.len+=j;const N=X(z,s),n=X(O,s),M=Z(N,w),F=Z(N,h),b=Z(n,w),A=Z(n,h),I=M*A-b*F;R.area+=I/2,R.ax+=(M+b)*I,R.ay+=(F+A)*I}for(let u=0;u<a.length;u+=1){const z=g.get(i(u));if(!z)continue;y[u]===1&&(z.open=!0);const O=a[u];z.far=Math.max(z.far,Math.hypot(O[0]-s[0],O[1]-s[1],O[2]-s[2]))}const L=[];for(const u of g.values()){if(!(u.len>0))continue;const z=[u.sx/u.len,u.sy/u.len,u.sz/u.len],O=!u.open&&u.area>u.len*u.len/(4*Math.PI)*.02,j=O?S(s,S(J(w,u.ax/(6*u.area)),J(h,u.ay/(6*u.area)))):z;L.push({c:j,len:u.len,r:O?Math.sqrt(u.area/Math.PI):u.len/(2*Math.PI),open:u.open||u.far>$})}return L}function it(t,s,e,{step:$,maxLen:c,reach:l,settle:p=0}){let f=et(e);const r=[];let x=s,y=!1,a=0;for(let i=$;i<=c;i+=$){const d=S(x,J(f,$)),m=Tt(t,d,f,l);let o=null,k=1/0;for(const h of m){const g=ht(X(h.c,d));g<k&&(k=g,o=h)}if(!o||k>Math.max(l*.5,3*(r.length?r[r.length-1].r:0))){if((a+=1)>3)break;x=d;continue}if(a=0,r.length>=3&&i>p){const h=r.slice(-6).map(L=>L.r).sort((L,u)=>L-u),g=h[h.length>>1];if(o.open||o.r>g*2){y=!0;break}}else if(o.open&&i>p){y=!0;break}r.push({c:o.c,r:o.r,s:i});const w=r[Math.max(0,r.length-5)].c;if(r.length>=3){const h=et(X(o.c,w)),g=Z(h,f);g>.94?f=h:g>0&&(f=et(S(J(f,.7),J(h,.3))))}x=o.c}return{line:r,dir:f,merged:y}}function Ot(t,s){const{P:e,T:$}=t;let c=null;for(let l=0;l<$.length;l+=3){const p=$[l]*3,f=$[l+1]*3,r=$[l+2]*3,x=(e[f+2]-e[r+2])*(e[p]-e[r])+(e[r]-e[f])*(e[p+2]-e[r+2]);if(Math.abs(x)<1e-18)continue;const y=((e[f+2]-e[r+2])*(s[0]-e[r])+(e[r]-e[f])*(s[2]-e[r+2]))/x,a=((e[r+2]-e[p+2])*(s[0]-e[r])+(e[p]-e[r])*(s[2]-e[r+2]))/x;if(y<0||a<0||y+a>1)continue;const i=y*e[p+1]+a*e[f+1]+(1-y-a)*e[r+1];i>s[1]&&(c===null||i<c)&&(c=i)}return c}function pt(t,s){if(!t.length)return null;const e=t[0],$=X(t[t.length-1],e),c=Z($,$);if(!(c>0))return e.slice();const l=Math.min(1,Math.max(0,s));let p=0;for(let f=1;f<t.length;f+=1){const r=Z(X(t[f],e),$)/c;if(r>=l)return nt(t[f-1],t[f],r>p?(l-p)/(r-p):0);p=r}return t[t.length-1].slice()}function _t(t,s={},{symmetric:e=!0}={}){const $=[],c=[],l={...s},p=(n,M)=>{!U(l[n])&&M&&(l[n]=M.map(F=>+F.toFixed(5)),c.push(n))},f=t.min[1],r=t.max[1]-t.min[1];if(!(r>0))return{points:l,found:c,warnings:["skeleton: the mesh has no height to find a biped in"]};const x=st(t,1,f+r/2,r),y=U(l.hips)?l.hips[0]:(t.min[0]+t.max[0])/2;let a=null;const i={L:[],R:[]};for(let n=2;n<70;n+=1){const M=f+r*n/120,F=K(t,1,M,0),b=F.filter(v=>Q(v)[0]>y),A=F.filter(v=>Q(v)[0]<y);if(F.some(v=>v[0][0]<y&&v[v.length-1][0]>y)){a=M;break}if(b.length&&A.length){const v=(T,_)=>T.sort((q,P)=>_*(Q(q)[0]-Q(P)[0]))[0];i.L.push(Q(v(b,1))),i.R.push(Q(v(A,-1)))}}(a===null||i.L.length<4)&&$.push("skeleton: no two legs found (give hip.L, knee.L, ankle.L and their .R)");const d=a??f+r*.47,m=(n,M)=>{const F=i[n];if(!F.length)return null;let b=F[0];for(const A of F)Math.abs(A[1]-M)<Math.abs(b[1]-M)&&(b=A);return[b[0],M,b[2]]},o=n=>{const M=K(t,1,n,0),F=M.find(A=>A[0][0]<=y&&A[A.length-1][0]>=y)||M[0];if(!F)return[y,n,(t.min[2]+t.max[2])/2];const b=F.map(A=>A[2]);return[y,n,(Math.min(...b)+Math.max(...b))/2]},k=e?["L"]:["L","R"];for(const n of k){const M=m(n,d-r*.02);p(`hip.${n}`,M&&[M[0],d+r*.05,M[2]]);const F=m(n,f+r*.1);if(p(`ankle.${n}`,F&&[F[0],f+r*.045,F[2]]),U(l[`hip.${n}`])&&U(l[`ankle.${n}`])){const A=l[`ankle.${n}`][1],I=l[`hip.${n}`][1],v=i[n].filter(q=>q[1]>=A+(I-A)*.2&&q[1]<=I-(I-A)*.2);let T=null,_=0;if(v.length>=3){const q=v[0],P=v[v.length-1];for(const Y of v){const H=Y[2]-(q[2]+(P[2]-q[2])*(Y[1]-q[1])/(P[1]-q[1]||1));Math.abs(H)>_&&(_=Math.abs(H),T=Y)}}p(`knee.${n}`,T&&_>r*.004?T:m(n,(I+A)/2)||nt(l[`hip.${n}`],l[`ankle.${n}`],.5))}const b=l[`ankle.${n}`];if(U(b)){const I=st(t,1,f+r*.02,r*.02).filter(v=>n==="L"?v[0]>y:v[0]<y).reduce((v,T)=>!v||T[2]>v[2]?T:v,null);I&&(p(`toe.${n}`,[b[0],f+r*.02,I[2]]),p(`ball.${n}`,[b[0],f+r*.025,b[2]+(I[2]-b[2])*.65]))}}const w=d+r*.07;p("hips",o(w)),p("headTop",(()=>{let n=null;for(const M of x)(!n||M[1]>n[1])&&(n=M);return n&&[y,n[1],o(n[1]-r*.06)[2]]})());const h=U(l.headTop)?l.headTop[1]:f+r,g=n=>d+(h-d)*n;p("chest",o(g(.52)));let L=g(.76),u=1/0;for(let n=g(.6);n<h-r*.06;n+=r/200){const M=K(t,1,n,0).find(F=>F[0][0]<=y&&F[F.length-1][0]>=y);M&&M[M.length-1][0]-M[0][0]<u&&(u=M[M.length-1][0]-M[0][0],L=n)}p("neck",o(L-r*.025)),p("head",o(L+r*.02));const z=(()=>{const n=K(t,1,g(.4),0).find(M=>M[0][0]<=y&&M[M.length-1][0]>=y);return n?Math.max(y-n[0][0],n[n.length-1][0]-y):r*.1})(),O=r/160,j=r*.16,E=g(.3),R=K(t,1,E,0),N=R.find(n=>n[0][0]<=y&&n[n.length-1][0]>=y)||null;for(const n of k){const M=n==="L"?1:-1,F=n==="L"?"left":"right",b=N?M>0?N[N.length-1][0]:N[0][0]:y,A=Math.abs(b-y)||z,I=R.filter(B=>B!==N).map(B=>Q(B)).filter(B=>M*(B[0]-b)>0&&M*(B[0]-b)<A*1.5).sort((B,D)=>M*(B[0]-D[0]))[0];let v=null,T=null;if(I){const B=it(t,I,[0,-1,0],{step:O,maxLen:r*.5,reach:j}),D=B.line.length?B.line[B.line.length-1]:{c:I,r:A*.3},C=D.r*3+O*4;for(let G=0;G<t.m;G+=1){const tt=t.P[G*3+1];tt>D.c[1]+O||Math.hypot(t.P[G*3]-D.c[0],t.P[G*3+2]-D.c[2])>C||(!v||tt<v[1])&&(v=[t.P[G*3],tt,t.P[G*3+2]])}T=[0,1,0]}else{for(const B of x)B[1]>d&&(!v||M*B[0]>M*v[0])&&(v=B);if(!v||M*(v[0]-y)<z*1.6){$.push(`skeleton: the ${F} arm is not found (out from the body, or hanging clear of it): give shoulder.${n}, elbow.${n}, wrist.${n}, handTip.${n}`);continue}T=[y-v[0],g(.62)-v[1],0]}if(!v){$.push(`skeleton: the ${F} arm's hand was not found: give handTip.${n}`);continue}const _=it(t,v,T,{step:O,maxLen:r*.6,reach:j,settle:r*.12});if(!_.merged||_.line.length<6){$.push(`skeleton: the ${F} shoulder was not found: give shoulder.${n}`);continue}const q=_.line[_.line.length-1],P=S(q.c,J(_.dir,q.r*zt)),Y=Ot(t,P);Y!==null&&Y-P[1]<q.r*4&&(P[1]=Math.max(P[1],Y-q.r)),p(`shoulder.${n}`,P),p(`handTip.${n}`,v);const H=l[`shoulder.${n}`],V=l[`handTip.${n}`];if(U(H)&&U(V)){const B=[H,..._.line.map(D=>D.c).reverse(),V];p(`elbow.${n}`,pt(B,Rt)),p(`wrist.${n}`,pt(B,jt))}}return e&&mt(l,c,y,p),{points:l,found:c,warnings:$}}function mt(t,s,e,$){for(const c of[...s]){const l=ft(c);l&&U(t[c])&&$(l,[2*e-t[c][0],t[c][1],t[c][2]])}}function qt(t,s={},{symmetric:e=!0}={}){const $=[],c=[],l={...s},p=(n,M)=>{!U(l[n])&&M&&(l[n]=M.map(F=>+F.toFixed(5)),c.push(n))},f=t.min[1],r=t.max[1]-t.min[1],x=(t.min[0]+t.max[0])/2;if(!(r>0))return{points:l,found:c,warnings:["skeleton: the mesh has no height to find a quadruped in"]};const y=Math.max(t.max[0]-t.min[0],t.max[2]-t.min[2],r),a=y*.015;let i=null,d=null;for(let n=1;n<60;n+=1){const M=f+r*n/100,F=K(t,1,M,0).filter(b=>b.length>=3);if(F.length===4)i=M,d||(d=F.map(Q));else if(i!==null&&F.length<4)break}if(i===null)return $.push("skeleton: no four legs found near the ground (give shoulder.L, elbow.L, wrist.L, frontFoot.L, hip.L, knee.L, hock.L, hindFoot.L and their .R)"),{points:l,found:c,warnings:$};const m=n=>K(t,1,n,0).filter(M=>M.length>=3).map(Q),o=d.reduce((n,M)=>n+M[2],0)/4,k=(n,M)=>F=>(n?F[2]>o:F[2]<o)&&(M==="L"?F[0]>x:F[0]<x),w=(n,M,F)=>m(F).find(k(n,M)),h=st(t,1,i+(t.max[1]-i)*.35,r*.08),g=Math.max(...h.map(n=>n[2])),L=Math.min(...h.map(n=>n[2])),u=i+(t.max[1]-i)*.3,z=d.filter(n=>n[2]>o),O=d.filter(n=>n[2]<o),j=z.reduce((n,M)=>n+M[2],0)/Math.max(1,z.length),E=O.reduce((n,M)=>n+M[2],0)/Math.max(1,O.length);p("hips",[x,u,E]),p("chest",[x,u,j]),p("spine",[x,u,(E+j)/2]);let R=null;for(let n=0;n<t.m;n+=1){const M=[t.P[n*3],t.P[n*3+1],t.P[n*3+2]];M[1]>u&&(!R||M[2]>R[2])&&(R=M)}if(R&&p("nose",[x,R[1],R[2]]),U(l.nose)){const M=it(t,l.nose,[0,0,-1],{step:y/200,maxLen:y*.6,reach:y*.2,settle:y*.12}).line;if(M.length>8){let F=0;for(let T=0;T<M.length/2;T+=1)M[T].r>M[F].r&&(F=T);let b=F;for(let T=F;T<M.length;T+=1)M[T].r<M[b].r&&(b=T);const A=K(t,1,i,0).filter(T=>T.length>=3&&Q(T)[2]>o);let I=-1/0;for(const T of A)for(const _ of T)I=Math.max(I,_[2]);let v=b;for(;v<M.length-1&&M[v].r<M[b].r*1.3&&M[v].c[2]>I;)v+=1;b<M.length-1&&(p("head",[x,M[b].c[1],M[b].c[2]]),p("neck",[x,M[v].c[1],M[v].c[2]]))}}U(l.nose)&&U(l.chest)&&(p("neck",[x,l.chest[1]+(t.max[1]-l.chest[1])*.25,l.chest[2]+(g-l.chest[2])*.6]),p("head",nt(l.neck,l.nose,.35)));let N=null;for(let n=0;n<t.m;n+=1){const M=t.P[n*3+2];(!N||M<N[2])&&(N=[t.P[n*3],t.P[n*3+1],M])}N&&N[2]<L+a&&p("tailTip",[x,N[1],N[2]]),U(l.hips)&&U(l.tailTip)&&p("tail",[x,l.hips[1],E-(j-E)*.25]);for(const n of e?["L"]:["L","R"]){const M=w(!0,n,f+r*.02),F=w(!1,n,f+r*.02);if(!M||!F){$.push(`skeleton: the ${n==="L"?"left":"right"} legs were not found`);continue}const b=i-f,A=H=>w(!0,n,H)||[M[0],H,M[2]],I=H=>w(!1,n,H)||[F[0],H,F[2]];p(`frontFoot.${n}`,[M[0],f+r*.01,M[2]+a]),p(`wrist.${n}`,A(f+b*.25)),p(`elbow.${n}`,A(f+b*.8)),p(`shoulder.${n}`,[A(i)[0],u,A(i)[2]]),p(`hindFoot.${n}`,[F[0],f+r*.01,F[2]+a]);const v=[];for(let H=1;H<=40;H+=1){const V=m(f+b*H/40).filter(k(!1,n)).sort((B,D)=>Math.abs(B[0]-F[0])-Math.abs(D[0]-F[0]))[0];V&&v.push(V)}const T=(H,V,B)=>v.filter(D=>D[1]>=f+b*H&&D[1]<=f+b*V).reduce((D,C)=>!D||B*C[2]>B*D[2]?C:D,null),_=T(.15,.7,-1),q=T(.5,1,1),P=v.length?(v[0][2]+v[v.length-1][2])/2:0,Y=a*2;p(`hock.${n}`,_&&P-_[2]>Y*.5?_:I(f+b*.4)),p(`knee.${n}`,q&&q[2]-(_?_[2]:P)>Y?q:I(f+b*.88)),p(`hip.${n}`,[I(i)[0],u,I(i)[2]])}return e&&mt(l,c,x,p),{points:l,found:c,warnings:$}}function Et(t,s=null){const e=[],$=[];let c=null,l=[];const p=t?.landmarks&&typeof t.landmarks=="object"?{...t.landmarks}:{};if(t?.template){const a=ct[t.template];if(!a)return{joints:[],landmarks:null,found:l,warnings:[`skeleton: no template "${t.template}" (${vt.join(", ")})`]};const i=U(p.hips)?p.hips[0]:s?(s.min[0]+s.max[0])/2:0;if(t.symmetric!==!1)for(const[m,o]of Object.entries({...p})){const k=ft(m);k&&U(o)&&!U(p[k])&&(p[k]=[2*i-o[0],o[1],o[2]])}let d=p;if(s){const m={symmetric:t.symmetric!==!1},o=t.template==="biped"?_t(s,p,m):qt(s,p,m);d=o.points,l=o.found,e.push(...o.warnings)}if(t.template==="biped"){!U(d.spine)&&U(d.hips)&&U(d.chest)&&(d.spine=nt(d.hips,d.chest,.5),l.push("spine"));for(const m of["L","R"])!U(d[`ball.${m}`])&&U(d[`ankle.${m}`])&&U(d[`toe.${m}`])&&(d[`ball.${m}`]=nt(d[`ankle.${m}`],d[`toe.${m}`],.65),l.push(`ball.${m}`))}c=d;for(const m of a.joints){const o=d[m.at];if(!U(o)){e.push(`skeleton: template ${t.template} needs landmark "${m.at}" (for joint ${m.name})`);continue}$.push({name:m.name,parentName:m.parent,at:o.slice(),tail:m.tail&&U(d[m.tail])?d[m.tail].slice():null,rot:null})}}for(const a of Array.isArray(t?.joints)?t.joints:[]){if(!a||typeof a.name!="string"||!a.name){e.push("skeleton: a joint needs a name");continue}if(!U(a.at)){e.push(`skeleton: joint "${a.name}" needs at: [x, y, z]`);continue}const i={name:a.name,parentName:a.parent??null,at:a.at.slice(),tail:U(a.tail)?a.tail.slice():null,rot:Array.isArray(a.rot)&&a.rot.length===3?a.rot.map(Number):null},d=$.findIndex(m=>m.name===a.name);d>=0?$[d]={...$[d],...i,parentName:a.parent===void 0?$[d].parentName:i.parentName,tail:i.tail||$[d].tail}:$.push(i)}const f=new Map;for(const a of $)f.has(a.name)?e.push(`skeleton: joint "${a.name}" is named twice`):f.set(a.name,a);const r=[],x=new Map,y=(a,i=0)=>{if(x.has(a.name))return x.get(a.name);if(i>256)return e.push(`skeleton: joint "${a.name}" is in a loop`),-1;let d=-1;if(a.parentName!=null){const o=f.get(a.parentName);o?d=y(o,i+1):e.push(`skeleton: joint "${a.name}" has no parent "${a.parentName}"`)}const m=r.length;return r.push({name:a.name,parent:d,at:a.at,tail:a.tail,rot:a.rot}),x.set(a.name,m),m};for(const a of f.values())y(a);return{joints:r,landmarks:c,found:l,warnings:e}}function Bt(t){const s=[];return t.forEach((e,$)=>{const c=t.filter(l=>l.parent===$);for(const l of c)s.push({joint:$,a:e.at,b:l.at});e.tail&&s.push({joint:$,a:e.at,b:e.tail}),!c.length&&!e.tail&&s.push({joint:$,a:e.at,b:e.at})}),s}const Ht=["set","add","multiply","max","min"],Dt=["skin","rigid"],rt=t=>Array.isArray(t)&&t.length===3&&t.every(Number.isFinite),W=(t,s)=>Number.isFinite(Number(t))&&t!==null&&t!==""?Number(t):s,dt=t=>{const s=Math.min(1,Math.max(0,t));return s*s*(3-2*s)};function Ut(t){let s=0,e=0;for(const x of t)s+=x.position.length/3,e+=x.index?x.index.length:x.position.length/3;const $=new Float32Array(s*3),c=new Uint32Array(e),l=new Int32Array(s),p={};let f=0,r=0;return t.forEach((x,y)=>{const a=x.position.length/3;if($.set(x.position,f*3),l.fill(y,f,f+a),x.index){for(let i=0;i<x.index.length;i+=1)c[r+i]=x.index[i]+f;r+=x.index.length}else{for(let i=0;i<a;i+=1)c[r+i]=f+i;r+=a}for(const[i,d]of Object.entries(x.groups||{}))!d||d.length!==a||(p[i]||=new Float32Array(s),p[i].set(d,f));f+=a}),{position:$,index:c,meshOf:l,groups:p}}function Yt(t,s,e,$,c,l,p,f){const{m:r,P:x}=s,y=new Float32Array(r).fill(1),a=new Int32Array(r).fill(-1);for(let m=0;m<s.n;m+=1)a[s.pid[m]]<0&&(a[s.pid[m]]=m);if(t.group!=null){const m=String(t.group).replace(/^group:/,""),o=e.groups[m]||e.groups[`group:${m}`];if(!o)return f(`skeleton: fix group "${t.group}" is not a vertex group of this mesh (${Object.keys(e.groups).join(", ")||"none"})`),y.fill(0),y;const k=new Float32Array(r);for(let w=0;w<s.n;w+=1)k[s.pid[w]]=Math.max(k[s.pid[w]],o[w]);for(let w=0;w<r;w+=1)y[w]*=k[w]}if(t.mesh!=null){const m=$.findIndex(o=>o.name===t.mesh);if(m<0)return f(`skeleton: fix mesh "${t.mesh}" is not one of this model's meshes`),y.fill(0),y;for(let o=0;o<r;o+=1)y[o]*=e.meshOf[a[o]]===m?1:0}if(t.box&&rt(t.box.min)&&rt(t.box.max)){const m=Math.max(0,W(t.soft,0));for(let o=0;o<r;o+=1){let k=1;for(let w=0;w<3;w+=1){const h=x[o*3+w],g=t.box.min[w],L=t.box.max[w],u=h<g?g-h:h>L?h-L:0;k*=m>0?1-dt(u/m):u>0?0:1}y[o]*=k}}const i=t.sphere||t.near;if(i&&rt(i.at)){const m=Math.max(1e-9,W(i.radius,.1)),o=t.sphere?Math.max(0,m-Math.max(0,W(t.soft,0))):Math.min(m,Math.max(0,W(i.inner,0))),k=t.sphere?"smooth":["linear","sharp","smooth"].includes(i.falloff)?i.falloff:"smooth";for(let w=0;w<r;w+=1){const h=Math.hypot(x[w*3]-i.at[0],x[w*3+1]-i.at[1],x[w*3+2]-i.at[2]);let g;if(h>m)g=0;else if(h<=o||k==="sharp")g=1;else{const L=(h-o)/(m-o);g=k==="linear"?1-L:1-dt(L)}y[w]*=g}}if(t.of!=null){const m=p.get(t.of);if(m===void 0)return f(`skeleton: fix "of" joint "${t.of}" is not a joint`),y.fill(0),y;for(let o=0;o<r;o+=1){let k=0;for(let w=1;w<l;w+=1)c[o*l+w]>c[o*l+k]&&(k=w);y[o]*=k===m?1:0}}const d=Math.min(1,Math.max(0,W(t.strength,1)));if(d!==1)for(let m=0;m<r;m+=1)y[m]*=d;return y}function Pt(t,s,e,$,c,l,p){const f=Ht.includes(t.mode)?t.mode:"set",r=W(t.value,f==="multiply"?1:f==="add"?0:1);let x=0;for(let y=0;y<$;y+=1){const a=s[y];if(!(a>0))continue;const i=e[y*c+l],d=f==="set"?r:f==="add"?i+r:f==="multiply"?i*r:f==="max"?Math.max(i,r):Math.min(i,r),m=Math.min(1,Math.max(0,i+(d-i)*a));if(m===i)continue;x+=1;let o=0;for(let k=0;k<c;k+=1)k!==l&&(o+=e[y*c+k]);if(e[y*c+l]=m,o>0){const k=(1-m)/o;for(let w=0;w<c;w+=1)w!==l&&(e[y*c+w]*=k)}else if(m<1){const k=p[l].parent;k>=0?e[y*c+k]=1-m:e[y*c+l]=1}}return x}function Vt(t,s){const e=typeof performance<"u"?performance.now():Date.now(),$=[],c=new Set,l=N=>{c.has(N)||(c.add(N),$.push(N))},p=Ut(s),f=bt(p.position,p.index),{joints:r,landmarks:x,found:y,warnings:a}=Et(t,f);a.forEach(l);const i=r.length;if(!i)return l("skeleton: no joints (give `joints`, or a `template` with `landmarks`)"),{joints:r,landmarks:x,found:y,influences:null,warnings:$,report:{joints:0}};const d=new Map(r.map((N,n)=>[N.name,n])),m=t.weights&&typeof t.weights=="object"?t.weights:{},{W:o,stats:k}=It(f,Bt(r),i,{visibility:m.visibility!==!1,parents:r.map(N=>N.parent)}),w=Dt.includes(t.bind)?t.bind:"skin";let h=null;if(w==="rigid"&&(h=Lt(f,o,i)),t.parts&&typeof t.parts=="object")for(const[N,n]of Object.entries(t.parts)){const M=s.findIndex(b=>b.name===N),F=d.get(n);if(M<0){l(`skeleton: parts names mesh "${N}", which this model does not have`);continue}if(F===void 0){l(`skeleton: parts gives mesh "${N}" to joint "${n}", which is not a joint`);continue}for(let b=0;b<f.n;b+=1){if(p.meshOf[b]!==M)continue;const A=f.pid[b];for(let I=0;I<i;I+=1)o[A*i+I]=0;o[A*i+F]=1}}ot(o,f.m,i);const g=Math.max(0,Math.min(50,Math.round(W(m.smooth,0))));g&&w==="skin"&&(lt(f,o,i,{iterations:g,strength:.5}),ot(o,f.m,i));const L=[];for(const[N,n]of(Array.isArray(t.fixes)?t.fixes:[]).entries()){if(!n||typeof n!="object")continue;const M=Yt(n,f,p,s,o,i,d,l);let F=0;if(Number.isFinite(Number(n.smooth))&&n.joint==null){lt(f,o,i,{iterations:Math.max(1,Math.min(50,Math.round(Number(n.smooth)))),strength:.5,mask:M}),ot(o,f.m,i);for(let b=0;b<f.m;b+=1)M[b]>0&&(F+=1)}else{const b=d.get(n.joint);if(b===void 0){l(`skeleton: fix ${N} names joint "${n.joint}", which is not a joint`);continue}F=Pt(n,M,o,f.m,i,b,r)}F||l(`skeleton: fix ${N} touched no point (its region is empty)`),L.push({fix:N,points:F})}const u=Math.min(.5,Math.max(0,W(m.threshold,.01))),z=Ft(f,o,i,{threshold:u}),O=[];let j=0;for(const N of s){const n=N.position.length/3;O.push({skinIndex:z.skinIndex.slice(j*4,(j+n)*4),skinWeight:z.skinWeight.slice(j*4,(j+n)*4)}),j+=n}const E=(typeof performance<"u"?performance.now():Date.now())-e,R={joints:i,bind:w,vertices:f.n,points:f.m,triangles:k.triangles,parts:f.islands,unseen:k.unseen,fallback:k.fallback,solves:k.solves,iterations:k.iterations,influencesMost:z.most,...h?{partJoints:Array.from(h,N=>r[N].name)}:{},...L.length?{fixes:L}:{},ms:+E.toFixed(1)};return{joints:r,landmarks:x,found:y,influences:O,warnings:$,report:R,W:o,S:f}}self.onmessage=({data:t})=>{const{id:s,spec:e,meshes:$}=t||{};try{const{W:c,S:l,...p}=Vt(e,$),f=[];for(const r of p.influences||[])f.push(r.skinIndex.buffer,r.skinWeight.buffer);self.postMessage({id:s,result:p},f)}catch(c){self.postMessage({id:s,error:String(c?.message||c)})}}})();
@@ -88,6 +88,7 @@
88
88
  "frontend/src/components/videoEditor/effectTransitionOrder.js",
89
89
  "frontend/src/components/videoEditor/engine/adjustmentComposite.js",
90
90
  "frontend/src/components/videoEditor/engine/background.js",
91
+ "frontend/src/components/videoEditor/engine/cachePlate.js",
91
92
  "frontend/src/components/videoEditor/engine/camera.js",
92
93
  "frontend/src/components/videoEditor/engine/canvasHelpers.js",
93
94
  "frontend/src/components/videoEditor/engine/channelRender.js",
@@ -125,26 +126,35 @@
125
126
  "frontend/src/components/videoEditor/engine/motionPasses.js",
126
127
  "frontend/src/components/videoEditor/engine/passPool.js",
127
128
  "frontend/src/components/videoEditor/engine/pathFx.js",
129
+ "frontend/src/components/videoEditor/engine/phoneMedia.js",
130
+ "frontend/src/components/videoEditor/engine/phoneMode.js",
128
131
  "frontend/src/components/videoEditor/engine/previewMedia.js",
129
132
  "frontend/src/components/videoEditor/engine/projectDerive.js",
130
133
  "frontend/src/components/videoEditor/engine/recordingCursorPass.js",
131
134
  "frontend/src/components/videoEditor/engine/renderTargets.js",
135
+ "frontend/src/components/videoEditor/engine/seekFrame.js",
132
136
  "frontend/src/components/videoEditor/engine/sequenceComposite.js",
133
137
  "frontend/src/components/videoEditor/engine/textDeepGlow.js",
134
138
  "frontend/src/components/videoEditor/engine/textPaint.js",
135
139
  "frontend/src/components/videoEditor/engine/transitions.js",
140
+ "frontend/src/components/videoEditor/engine/videoCanvasTexture.js",
136
141
  "frontend/src/components/videoEditor/engine/warmUp.js",
137
142
  "frontend/src/components/videoEditor/engine/worldLayerFx.js",
138
143
  "frontend/src/components/videoEditor/fastBlurEffect.js",
139
144
  "frontend/src/components/videoEditor/fastBlurNodes.js",
140
145
  "frontend/src/components/videoEditor/filmStockEffect.js",
141
146
  "frontend/src/components/videoEditor/filmStockNodes.js",
147
+ "frontend/src/components/videoEditor/frameGrid.js",
142
148
  "frontend/src/components/videoEditor/frameResampler.js",
143
149
  "frontend/src/components/videoEditor/fresnelRimLayer.js",
144
150
  "frontend/src/components/videoEditor/fxProbeBroker.js",
145
151
  "frontend/src/components/videoEditor/glassEffect.js",
146
152
  "frontend/src/components/videoEditor/glassNodes.js",
153
+ "frontend/src/components/videoEditor/gooeyEffect.js",
154
+ "frontend/src/components/videoEditor/gooeyNodes.js",
147
155
  "frontend/src/components/videoEditor/gpuReset.js",
156
+ "frontend/src/components/videoEditor/gradientGlowEffect.js",
157
+ "frontend/src/components/videoEditor/gradientGlowNodes.js",
148
158
  "frontend/src/components/videoEditor/gridLayout.js",
149
159
  "frontend/src/components/videoEditor/gridLinesEffect.js",
150
160
  "frontend/src/components/videoEditor/gridLinesNodes.js",
@@ -166,7 +176,10 @@
166
176
  "frontend/src/components/videoEditor/layerVelocity.js",
167
177
  "frontend/src/components/videoEditor/legacyTextAnimation.js",
168
178
  "frontend/src/components/videoEditor/legacyTextAnimationMigrate.js",
179
+ "frontend/src/components/videoEditor/lightSweepEffect.js",
180
+ "frontend/src/components/videoEditor/lightSweepNodes.js",
169
181
  "frontend/src/components/videoEditor/linesDrawProfiles.js",
182
+ "frontend/src/components/videoEditor/liveLayers.js",
170
183
  "frontend/src/components/videoEditor/localAdvancedTransitions.js",
171
184
  "frontend/src/components/videoEditor/localEffects.js",
172
185
  "frontend/src/components/videoEditor/materialFactory.js",
@@ -191,6 +204,7 @@
191
204
  "frontend/src/components/videoEditor/model3dShadowPlate.js",
192
205
  "frontend/src/components/videoEditor/model3dTonePass.js",
193
206
  "frontend/src/components/videoEditor/modelDof.js",
207
+ "frontend/src/components/videoEditor/modelPose.js",
194
208
  "frontend/src/components/videoEditor/motionBlur.js",
195
209
  "frontend/src/components/videoEditor/motionBlurLayer.js",
196
210
  "frontend/src/components/videoEditor/motionBlurLevels.js",
@@ -226,12 +240,14 @@
226
240
  "frontend/src/components/videoEditor/pathPointer.js",
227
241
  "frontend/src/components/videoEditor/pathStroke.js",
228
242
  "frontend/src/components/videoEditor/pathStrokeRenderer.js",
243
+ "frontend/src/components/videoEditor/pcssRadius.js",
229
244
  "frontend/src/components/videoEditor/perfRegistry.js",
230
245
  "frontend/src/components/videoEditor/photoSlots.js",
231
246
  "frontend/src/components/videoEditor/pixelateEffect.js",
232
247
  "frontend/src/components/videoEditor/pixelateNodes.js",
233
248
  "frontend/src/components/videoEditor/pointLoupe.js",
234
249
  "frontend/src/components/videoEditor/pointPickBroker.js",
250
+ "frontend/src/components/videoEditor/popoverSelect.css",
235
251
  "frontend/src/components/videoEditor/posterizeEffect.js",
236
252
  "frontend/src/components/videoEditor/posterizeNodes.js",
237
253
  "frontend/src/components/videoEditor/posterizeTime.js",
@@ -253,6 +269,9 @@
253
269
  "frontend/src/components/videoEditor/renderCache.js",
254
270
  "frontend/src/components/videoEditor/renderCacheController.js",
255
271
  "frontend/src/components/videoEditor/renderOutputSize.js",
272
+ "frontend/src/components/videoEditor/renderPrime.js",
273
+ "frontend/src/components/videoEditor/renderProfile.js",
274
+ "frontend/src/components/videoEditor/renderSettle.js",
256
275
  "frontend/src/components/videoEditor/renderWarmup.js",
257
276
  "frontend/src/components/videoEditor/repetileLayer.js",
258
277
  "frontend/src/components/videoEditor/repetileNodes.js",
@@ -263,9 +282,11 @@
263
282
  "frontend/src/components/videoEditor/rigDeformNodes.js",
264
283
  "frontend/src/components/videoEditor/rigShadowFit.js",
265
284
  "frontend/src/components/videoEditor/rigSoftShadows.js",
285
+ "frontend/src/components/videoEditor/rigSolveEditor.js",
266
286
  "frontend/src/components/videoEditor/rotoRegion.js",
267
287
  "frontend/src/components/videoEditor/runningGlow.js",
268
288
  "frontend/src/components/videoEditor/runningGlowNodes.js",
289
+ "frontend/src/components/videoEditor/scenePose.js",
269
290
  "frontend/src/components/videoEditor/sequencePrerender.js",
270
291
  "frontend/src/components/videoEditor/sequenceUtils.js",
271
292
  "frontend/src/components/videoEditor/shapePath.js",
@@ -273,6 +294,7 @@
273
294
  "frontend/src/components/videoEditor/shapeRulersNodes.js",
274
295
  "frontend/src/components/videoEditor/silhouetteFraming.js",
275
296
  "frontend/src/components/videoEditor/silhouetteFramingNodes.js",
297
+ "frontend/src/components/videoEditor/skinDQWebGL.js",
276
298
  "frontend/src/components/videoEditor/smartZoom.js",
277
299
  "frontend/src/components/videoEditor/smartZoomCamera.js",
278
300
  "frontend/src/components/videoEditor/smartZoomCursors.js",
@@ -293,6 +315,7 @@
293
315
  "frontend/src/components/videoEditor/textAnimators.js",
294
316
  "frontend/src/components/videoEditor/textCounter.js",
295
317
  "frontend/src/components/videoEditor/textFootprint.js",
318
+ "frontend/src/components/videoEditor/textMorph.js",
296
319
  "frontend/src/components/videoEditor/textPathCorners.js",
297
320
  "frontend/src/components/videoEditor/textPlaceholders.js",
298
321
  "frontend/src/components/videoEditor/threeDisplayTransform.js",
@@ -311,6 +334,7 @@
311
334
  "frontend/src/components/videoEditor/tslStableHash.js",
312
335
  "frontend/src/components/videoEditor/tslUserShader.js",
313
336
  "frontend/src/components/videoEditor/types.js",
337
+ "frontend/src/components/videoEditor/useAudioRecording.js",
314
338
  "frontend/src/components/videoEditor/usePreviewViewport.js",
315
339
  "frontend/src/components/videoEditor/vectorMedia.js",
316
340
  "frontend/src/components/videoEditor/videoEditorStore.js",
@@ -325,6 +349,13 @@
325
349
  "frontend/src/components/videoEditor/webmClipDecoder.js",
326
350
  "frontend/src/components/videoEditor/webmDemux.js",
327
351
  "frontend/src/components/videoEditor/webmFrameCache.js",
352
+ "frontend/src/components/videoEditor/world3dFx.js",
353
+ "frontend/src/components/videoEditor/world3dLayer.js",
354
+ "frontend/src/components/videoEditor/world3dScene.js",
355
+ "frontend/src/components/videoEditor/world3dText.js",
356
+ "frontend/src/components/videoEditor/worldHandoff.js",
357
+ "frontend/src/components/videoEditor/worldLayerCritique.js",
358
+ "frontend/src/components/videoEditor/worldMotion.js",
328
359
  "frontend/src/hooks/appPrefs.js",
329
360
  "frontend/src/hooks/useHoverTip.jsx",
330
361
  "frontend/src/motionEngine/EngineCanvas.jsx",
@@ -332,12 +363,16 @@
332
363
  "frontend/src/motionEngine/ReviewLayer.jsx",
333
364
  "frontend/src/motionEngine/ReviewUI.jsx",
334
365
  "frontend/src/motionEngine/assets.js",
366
+ "frontend/src/motionEngine/critique.js",
335
367
  "frontend/src/motionEngine/engineEntry.jsx",
368
+ "frontend/src/motionEngine/finalCap.js",
369
+ "frontend/src/motionEngine/localRenderCache.js",
336
370
  "frontend/src/motionEngine/mix.js",
337
371
  "frontend/src/motionEngine/normalize.js",
338
372
  "frontend/src/motionEngine/pageEdits.js",
339
373
  "frontend/src/motionEngine/playerPage.css",
340
374
  "frontend/src/motionEngine/reviewNotes.js",
375
+ "frontend/src/motionEngine/rulerSteps.js",
341
376
  "frontend/src/motionEngine/sfx.js",
342
377
  "frontend/src/motionEngine/soundCues.js",
343
378
  "frontend/src/motionEngine/soundLibrary.js",
@@ -350,6 +385,7 @@
350
385
  "frontend/src/motionEngine/studio/gizmo.js",
351
386
  "frontend/src/motionEngine/studio/highlight.css",
352
387
  "frontend/src/motionEngine/studio/highlight.js",
388
+ "frontend/src/motionEngine/studio/history.js",
353
389
  "frontend/src/motionEngine/studio/index.js",
354
390
  "frontend/src/motionEngine/studio/inspector.js",
355
391
  "frontend/src/motionEngine/studio/lab.css",
@@ -359,11 +395,15 @@
359
395
  "frontend/src/motionEngine/studio/notes.js",
360
396
  "frontend/src/motionEngine/studio/review.css",
361
397
  "frontend/src/motionEngine/studio/review.js",
398
+ "frontend/src/motionEngine/studio/timelineZoom.js",
362
399
  "frontend/src/motionEngine/studio/voice.js",
363
400
  "frontend/src/motionEngine/template.js",
364
401
  "frontend/src/motionEngine/textWraps.js",
365
402
  "frontend/src/motionEngine/trace.js",
366
403
  "frontend/src/motionEngine/useReview.js",
404
+ "frontend/src/motionEngine/world3dContract.js",
405
+ "frontend/src/motionEngine/world3dPlugin.js",
406
+ "frontend/src/pipelines/pipelineUtils.js",
367
407
  "frontend/src/platform/compact.js",
368
408
  "frontend/src/platform/runtime.js",
369
409
  "frontend/src/render-shims/FontFamilySelect.jsx",
@@ -398,7 +438,25 @@
398
438
  "frontend/src/utils/cssGradient.js",
399
439
  "frontend/src/utils/shaderBackground.js",
400
440
  "frontend/src/utils/shaderPresetsLab.js",
401
- "frontend/src/utils/zoomRate.js"
441
+ "frontend/src/utils/wgslSwizzleFix.js",
442
+ "frontend/src/utils/zoomRate.js",
443
+ "frontend/src/world3d/cameraPath.js",
444
+ "frontend/src/world3d/gpuLimits.js",
445
+ "frontend/src/world3d/keys.js",
446
+ "frontend/src/world3d/lens.js",
447
+ "frontend/src/world3d/mat.js",
448
+ "frontend/src/world3d/mesh.js",
449
+ "frontend/src/world3d/render/animatedMaterials.js",
450
+ "frontend/src/world3d/render/tone.js",
451
+ "frontend/src/world3d/rig/bind.js",
452
+ "frontend/src/world3d/rig/core.js",
453
+ "frontend/src/world3d/rig/dualQuat.js",
454
+ "frontend/src/world3d/rig/joints.js",
455
+ "frontend/src/world3d/rig/rigSolver.js",
456
+ "frontend/src/world3d/rig/rigWorker.js",
457
+ "frontend/src/world3d/rig/weights.js",
458
+ "frontend/src/world3d/schema/critiqueHints.js",
459
+ "frontend/src/world3d/splat/readSplat.js"
402
460
  ],
403
461
  "packages": [
404
462
  {