three-live 1.2.1 → 1.2.3
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.
- package/README.md +6 -1
- package/dist/index.d.ts +66 -2
- package/dist/three-author-engine.js +85 -42
- package/dist/three-author.cjs +84 -42
- package/dist/three-author.d.ts +66 -2
- package/dist/three-author.js +84 -42
- package/dist/three-convert.cjs +84 -42
- package/dist/three-convert.d.ts +66 -2
- package/dist/three-convert.js +84 -42
- package/dist/three-live-animation.cjs +7 -7
- package/dist/three-live-animation.d.ts +66 -2
- package/dist/three-live-animation.js +7 -7
- package/dist/three-live-animation.min.js +7 -7
- package/dist/three-live-cad.cjs +18 -0
- package/dist/{three-live-extras.d.ts → three-live-cad.d.ts} +66 -2
- package/dist/three-live-cad.js +18 -0
- package/dist/three-live-cad.min.js +18 -0
- package/dist/three-live-element.cjs +48 -6
- package/dist/three-live-element.d.ts +66 -2
- package/dist/three-live-element.js +48 -6
- package/dist/three-live-full.cjs +176 -55
- package/dist/three-live-full.js +176 -55
- package/dist/three-live-full.min.js +176 -55
- package/dist/three-live-studio.cjs +120 -0
- package/dist/three-live-studio.d.ts +510 -0
- package/dist/three-live-studio.js +120 -0
- package/dist/three-live-studio.min.js +120 -0
- package/dist/three-live-viewer.cjs +48 -6
- package/dist/three-live-viewer.d.ts +66 -2
- package/dist/three-live-viewer.js +48 -6
- package/dist/three-live-viewer.min.js +48 -6
- package/dist/three-live.cjs +86 -44
- package/dist/three-live.js +86 -44
- package/dist/three-live.min.js +86 -44
- package/dist/three-view.cjs +48 -6
- package/dist/three-view.d.ts +66 -2
- package/dist/three-view.js +48 -6
- package/dist/three-xr.cjs +83 -41
- package/dist/three-xr.d.ts +66 -2
- package/dist/three-xr.js +83 -41
- package/package.json +10 -5
- package/dist/three-live-extras.cjs +0 -42
- package/dist/three-live-extras.js +0 -42
- package/dist/three-live-extras.min.js +0 -42
|
@@ -14,23 +14,23 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
"use strict";var L=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var $=(e,n)=>{for(var r in n)L(e,r,{get:n[r],enumerable:!0})},Y=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of J(n))!H.call(e,t)&&t!==r&&L(e,t,{get:()=>n[t],enumerable:!(i=j(n,t))||i.enumerable});return e};var q=e=>Y(L({},"__esModule",{value:!0}),e);var Q={};$(Q,{crossFadeTo:()=>W,keyframeAnimationPlugin:()=>D,morphPlugin:()=>G,parseAnimations:()=>I,sampleChannel:()=>v,setMorphTargetWeight:()=>X,skinningPlugin:()=>B});module.exports=q(Q);var F="__THREE_LIVE_REGISTRY__";function O(){let e=typeof globalThis<"u"?globalThis:{};if(!e[F]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,F,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[F]=n}}return e[F]}var ee=O().plugins;function M(e){let n=O().plugins;n.some(r=>r.name===e.name)||n.push(e)}function P(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function K(e,n,r){let i=n[0],t=n[1],c=n[2],f=n[3],u=n[4],s=n[5],b=n[6],o=n[7],a=n[8],m=n[9],l=n[10],p=n[11],A=n[12],d=n[13],x=n[14],y=n[15],h=r[0],g=r[1],T=r[2],R=r[3];return e[0]=h*i+g*u+T*a+R*A,e[1]=h*t+g*s+T*m+R*d,e[2]=h*c+g*b+T*l+R*x,e[3]=h*f+g*o+T*p+R*y,h=r[4],g=r[5],T=r[6],R=r[7],e[4]=h*i+g*u+T*a+R*A,e[5]=h*t+g*s+T*m+R*d,e[6]=h*c+g*b+T*l+R*x,e[7]=h*f+g*o+T*p+R*y,h=r[8],g=r[9],T=r[10],R=r[11],e[8]=h*i+g*u+T*a+R*A,e[9]=h*t+g*s+T*m+R*d,e[10]=h*c+g*b+T*l+R*x,e[11]=h*f+g*o+T*p+R*y,h=r[12],g=r[13],T=r[14],R=r[15],e[12]=h*i+g*u+T*a+R*A,e[13]=h*t+g*s+T*m+R*d,e[14]=h*c+g*b+T*l+R*x,e[15]=h*f+g*o+T*p+R*y,e}function _(e,n,r,i){let t=n[0],c=n[1],f=n[2],u=n[3],s=t+t,b=c+c,o=f+f,a=t*s,m=t*b,l=t*o,p=c*b,A=c*o,d=f*o,x=u*s,y=u*b,h=u*o,g=i[0],T=i[1],R=i[2];return e[0]=(1-(p+d))*g,e[1]=(m+h)*g,e[2]=(l-y)*g,e[3]=0,e[4]=(m-h)*T,e[5]=(1-(a+d))*T,e[6]=(A+x)*T,e[7]=0,e[8]=(l+y)*R,e[9]=(A-x)*R,e[10]=(1-(a+p))*R,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function V(e,n){let r=n[0],i=n[1],t=n[2],c=n[4],f=n[5],u=n[6],s=n[8],b=n[9],o=n[10],a=o*f-u*b,m=-o*c+u*s,l=b*c-f*s,p=r*a+i*m+t*l;return p&&(p=1/p,e[0]=a*p,e[1]=(-o*i+t*b)*p,e[2]=(u*i-t*f)*p,e[3]=m*p,e[4]=(o*r-t*s)*p,e[5]=(-u*r+t*c)*p,e[6]=l*p,e[7]=(-b*r+i*s)*p,e[8]=(f*r-i*c)*p),e}function U(e,n){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let o=0;o<r;o++)i.push(P());if(r===0)return i;let t=new Set;for(let o of e.nodes)if(Array.isArray(o.children))for(let a of o.children)t.add(a);let c=new Set,f=128,u=(o,a,m=0)=>{if(m>f||o<0||o>=r||c.has(o))return;c.add(o);let l=e.nodes[o];if(!l)return;let p=P();if(n&&n[o])p.set(n[o]);else if(l.matrix&&l.matrix.length===16)p.set(l.matrix);else{let d=l.translation||[0,0,0],x=l.rotation||[0,0,0,1],y=l.scale||[1,1,1];_(p,x,d,y)}let A=i[o];if(a?K(A,a,p):A.set(p),Array.isArray(l.children))for(let d of l.children)typeof d=="number"&&u(d,A,m+1)},s=[],b=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(b&&Array.isArray(b.nodes))s.push(...b.nodes);else for(let o=0;o<r;o++)t.has(o)||s.push(o);for(let o of s)u(o,null);for(let o=0;o<r;o++)!t.has(o)&&!s.includes(o)&&u(o,null);return i}function w(e,n,r){return n%4===0?new Float32Array(e,n,r):new Float32Array(e.slice(n,n+r*4))}function z(e,n,r,i){let t=n[0],c=n[1],f=n[2],u=n[3],s=r[0],b=r[1],o=r[2],a=r[3],m=t*s+c*b+f*o+u*a;if(m<0&&(s=-s,b=-b,o=-o,a=-a,m=-m),Math.abs(m)>=1)return e[0]=t,e[1]=c,e[2]=f,e[3]=u,e;let l=Math.acos(m),p=Math.sqrt(1-m*m);if(Math.abs(p)<.001)return e[0]=.5*(t+s),e[1]=.5*(c+b),e[2]=.5*(f+o),e[3]=.5*(u+a),e;let A=Math.sin((1-i)*l)/p,d=Math.sin(i*l)/p;return e[0]=t*A+s*d,e[1]=c*A+b*d,e[2]=f*A+o*d,e[3]=u*A+a*d,e}function N(e,n,r,i){return e[0]=n[0]+i*(r[0]-n[0]),e[1]=n[1]+i*(r[1]-n[1]),e[2]=n[2]+i*(r[2]-n[2]),e}function I(e,n){if(!Array.isArray(e?.animations))return[];let r=[];for(let i=0;i<e.animations.length;i++){let t=e.animations[i],c=t.name||`Animation_${i}`,f=[],u=0;if(Array.isArray(t.channels)&&Array.isArray(t.samplers))for(let s of t.channels){if(!s.target||s.target.node===void 0||!s.target.path)continue;let b=t.samplers[s.sampler];if(!b)continue;let o=e.accessors?.[b.input],a=e.accessors?.[b.output];if(!o||!a)continue;let m=e.bufferViews?.[o.bufferView],l=e.bufferViews?.[a.bufferView];if(!m||!l)continue;let p=(m.byteOffset||0)+(o.byteOffset||0),A=(l.byteOffset||0)+(a.byteOffset||0),d=w(n,p,o.count);d.length>0&&d[d.length-1]>u&&(u=d[d.length-1]);let x=s.target.path==="rotation"?4:s.target.path==="weights"?Math.max(1,Math.round(a.count/Math.max(1,o.count))):3,y=w(n,A,a.count*(s.target.path==="weights"?1:x)),h=b.interpolation==="STEP"?"STEP":"LINEAR";f.push({nodeIndex:s.target.node,path:s.target.path,times:d,values:y,interpolation:h})}f.length>0&&r.push({name:c,duration:u,channels:f})}return r}function v(e,n,r){let{times:i,values:t,path:c,interpolation:f}=e,u=i.length;if(u===0)return;let s=c==="rotation"?4:c==="weights"?Math.max(1,Math.round(t.length/u)):3;if(n<=i[0]){for(let y=0;y<s;y++)r[y]=t[y];return}if(n>=i[u-1]){let y=(u-1)*s;for(let h=0;h<s;h++)r[h]=t[y+h];return}let b=0,o=u-1;for(;b<=o;){let y=b+o>>1;i[y]<=n?b=y+1:o=y-1}let a=Math.max(0,o),m=Math.min(u-1,a+1);if(f==="STEP"||a===m){let y=a*s;for(let h=0;h<s;h++)r[h]=t[y+h];return}let l=i[a],p=i[m],A=(n-l)/Math.max(1e-5,p-l),d=a*s,x=m*s;if(c==="rotation"){let y=[t[d],t[d+1],t[d+2],t[d+3]],h=[t[x],t[x+1],t[x+2],t[x+3]];z(r,y,h,A)}else for(let y=0;y<s;y++)r[y]=t[d+y]+A*(t[x+y]-t[d+y])}var E=new WeakMap;function W(e,n,r=.3){if(!e?.animations)return;let i=e.animations.find(u=>u.name===n);if(!i)return;let t=E.get(e);t||(t=[],e.currentClip&&t.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),E.set(e,t));let c=r>0?1/r:1e3;for(let u of t)u.clip.name!==n&&(u.fadeSpeed=-c);let f=t.find(u=>u.clip.name===n);f?f.fadeSpeed=c:t.push({clip:i,time:0,weight:r>0?0:1,fadeSpeed:c}),e.currentClip=i,e.isPlayingAnimation=!0}function C(e,n){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let r=E.get(e);if(!r||r.length===0){if(!e.currentClip)return;r=[{clip:e.currentClip,time:n,weight:1,fadeSpeed:0}]}let i=e.gltf.nodes.length,t=[];for(let a=0;a<i;a++){let m=e.initialNodeTransforms[a];m?t.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]]}):t.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let c=[0,0,0],f=[0,0,0,1],u=[1,1,1],s=new Float32Array(64);for(let a of r){let m=Math.max(0,Math.min(1,a.weight));if(!(m<=1e-4))for(let l of a.clip.channels){if(l.nodeIndex<0||l.nodeIndex>=i)continue;let p=t[l.nodeIndex];if(l.path==="translation")v(l,a.time,c),N(p.t,p.t,c,m);else if(l.path==="rotation")v(l,a.time,f),z(p.r,p.r,f,m);else if(l.path==="scale")v(l,a.time,u),N(p.s,p.s,u,m);else if(l.path==="weights"&&(v(l,a.time,s),e.meshes)){for(let A of e.meshes)if(A.nodeIndex===l.nodeIndex){for(let d of A.primitives)if(d.pluginData?.morph?.weights){let x=d.pluginData.morph.weights,y=d.pluginData.morph.numTargets||x.length;for(let h=0;h<y;h++)x[h]=x[h]*(1-m)+s[h]*m}}}}}let b=[];for(let a=0;a<i;a++){let m=P(),{t:l,r:p,s:A}=t[a];_(m,p,l,A),b.push(m)}let o=U(e.gltf,b);e.worldMatrices=o;for(let a of e.meshes)a.nodeIndex>=0&&a.nodeIndex<o.length&&(a.transform.set(o[a.nodeIndex]),V(a.normalMatrix,a.transform))}var D={name:"keyframes",evaluateAnimation:C,crossFadeTo:W,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=I(e.gltf,e.bin))},onUpdate(e,n){if(!e.isPlayingAnimation)return;let r=E.get(e);if(r&&r.length>0){for(let i=r.length-1;i>=0;i--){let t=r[i];if(t.time+=n,t.clip.duration>0&&(t.time%=t.clip.duration),t.fadeSpeed!==0)if(t.weight+=t.fadeSpeed*n,t.weight<=0){r.splice(i,1);continue}else t.weight>=1&&(t.weight=1,t.fadeSpeed=0)}r.length>0&&(e.animationTime=r[r.length-1].time),C(e,e.animationTime)}else e.currentClip&&(e.animationTime+=n,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),C(e,e.animationTime))}};var S=64;function X(e,n,r){if(!(!e?.meshes||n<0||n>=S))for(let i of e.meshes)for(let t of i.primitives){let c=t.pluginData?.morph;c?.weights&&(c.weights[n]=r)}}var G={name:"morph",onResolveShader(e,n,r,i){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let t=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
|
|
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;
|
|
18
18
|
uniform sampler2D uMorphDeltasTex;
|
|
19
|
-
uniform float uMorphWeights[${
|
|
20
|
-
uniform int uNumMorphTargets;`);return
|
|
21
|
-
for (int m = 0; m < ${
|
|
19
|
+
uniform float uMorphWeights[${$}];
|
|
20
|
+
uniform int uNumMorphTargets;`);return r=r.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
|
|
21
|
+
for (int m = 0; m < ${$}; m++) {
|
|
22
22
|
if (m >= uNumMorphTargets) break;
|
|
23
23
|
float w = uMorphWeights[m];
|
|
24
24
|
if (abs(w) > 0.0001) {
|
|
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:
|
|
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;
|
|
29
29
|
layout(location=4) in uvec4 aJoints;
|
|
30
30
|
layout(location=5) in vec4 aWeights;
|
|
31
|
-
uniform mat4 uJointMatrix[${
|
|
31
|
+
uniform mat4 uJointMatrix[${Mn}];`),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(${
|
|
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);
|
|
@@ -48,6 +48,30 @@ import type {
|
|
|
48
48
|
} from './xr-live/src/xr-live-element';
|
|
49
49
|
|
|
50
50
|
export * from './three-live/src/core';
|
|
51
|
+
export {
|
|
52
|
+
cadPlugin,
|
|
53
|
+
installCadExtension,
|
|
54
|
+
MAX_BSP_DEPTH,
|
|
55
|
+
MAX_CSG_TRIANGLES,
|
|
56
|
+
MAX_SHAPE_POINTS,
|
|
57
|
+
MAX_TEXT_GEOMETRY_CHARS,
|
|
58
|
+
type ExtrudeGeometryOptions,
|
|
59
|
+
type TextGeometryOptions,
|
|
60
|
+
} from './three-live/src/plugins/cad';
|
|
61
|
+
export {
|
|
62
|
+
ikPlugin,
|
|
63
|
+
IKSolver,
|
|
64
|
+
quatFromUnitVectors,
|
|
65
|
+
solveFABRIK,
|
|
66
|
+
solveTwoBoneIK,
|
|
67
|
+
type FABRIKSolution,
|
|
68
|
+
type IKQuat,
|
|
69
|
+
type TwoBoneIKSolution,
|
|
70
|
+
} from './three-live/src/plugins/ik';
|
|
71
|
+
export {
|
|
72
|
+
extractNodeInstancing,
|
|
73
|
+
instancingPlugin,
|
|
74
|
+
} from './three-live/src/plugins/instancing';
|
|
51
75
|
export {
|
|
52
76
|
getInteractivityVM,
|
|
53
77
|
interactivityPlugin,
|
|
@@ -63,6 +87,30 @@ export {
|
|
|
63
87
|
type InteractivityValueSocket,
|
|
64
88
|
type InteractivityVariableDef,
|
|
65
89
|
} from './three-live/src/plugins/interactivity';
|
|
90
|
+
export {
|
|
91
|
+
applyMeshoptFilter,
|
|
92
|
+
decodeMeshoptBuffer,
|
|
93
|
+
decodeMeshoptGLB,
|
|
94
|
+
encodeMeshoptBuffer,
|
|
95
|
+
meshoptDecoder,
|
|
96
|
+
meshoptPlugin,
|
|
97
|
+
type MeshoptFilter,
|
|
98
|
+
type MeshoptMode,
|
|
99
|
+
} from './three-live/src/plugins/meshopt';
|
|
100
|
+
export {
|
|
101
|
+
computeOutlineClipOffset,
|
|
102
|
+
evaluateKawaseBloom,
|
|
103
|
+
parseHexRgb,
|
|
104
|
+
postprocessingPlugin,
|
|
105
|
+
resolveViewerBloom,
|
|
106
|
+
} from './three-live/src/plugins/postprocessing';
|
|
107
|
+
export {
|
|
108
|
+
extractMaterialVariants,
|
|
109
|
+
extractPrimitiveVariantMappings,
|
|
110
|
+
selectMaterialVariant,
|
|
111
|
+
variantsPlugin,
|
|
112
|
+
type VariantMapping,
|
|
113
|
+
} from './three-live/src/plugins/variants';
|
|
66
114
|
export {
|
|
67
115
|
ThreeLiveElement,
|
|
68
116
|
type ARLaunchOptions,
|
|
@@ -80,7 +128,7 @@ export {
|
|
|
80
128
|
type XRProfile,
|
|
81
129
|
type XRSimulatorRoom,
|
|
82
130
|
} from './xr-live/src/xr-live-element';
|
|
83
|
-
/** Optional spatial plugins (`xr-live/
|
|
131
|
+
/** Optional spatial plugins (`xr-live/spatial`, `xr-live-spatial.min.js`). */
|
|
84
132
|
export * from './xr-live/src/plugins/index';
|
|
85
133
|
|
|
86
134
|
/**
|
|
@@ -119,7 +167,7 @@ export interface ThreeLiveAttributes {
|
|
|
119
167
|
'shadow-intensity'?: number | string;
|
|
120
168
|
/** Radial Gaussian blur falloff of contact shadow (0.0 to 1.0). */
|
|
121
169
|
'shadow-softness'?: number | string;
|
|
122
|
-
/** Tone mapping mode ("neutral", "reinhard", "none"). */
|
|
170
|
+
/** Tone mapping mode ("neutral", "aces", "agx", "reinhard", "none"). */
|
|
123
171
|
'tone-mapping'?: string;
|
|
124
172
|
/** Enable or disable interactive camera orbit/pan/zoom controls (default: true). */
|
|
125
173
|
'camera-controls'?: boolean | string;
|
|
@@ -127,6 +175,8 @@ export interface ThreeLiveAttributes {
|
|
|
127
175
|
'autoplay'?: boolean | string;
|
|
128
176
|
/** Name of specific glTF animation clip to play. */
|
|
129
177
|
'animation-name'?: string;
|
|
178
|
+
/** Name of the active KHR_materials_variants material variant. */
|
|
179
|
+
'variant-name'?: string;
|
|
130
180
|
/** Automatically rotate scene around the Y-axis when user is idle. */
|
|
131
181
|
'auto-rotate'?: boolean | string;
|
|
132
182
|
/** Delay in milliseconds before auto-rotation resumes after user interaction (default: 3000). */
|
|
@@ -162,6 +212,7 @@ export interface ThreeLiveAttributes {
|
|
|
162
212
|
onerror?: (e: CustomEvent<{error: any}>) => void;
|
|
163
213
|
onmeshclick?: (e: CustomEvent<HitDetail>) => void;
|
|
164
214
|
'oncamera-change'?: (e: CustomEvent<CameraDetail>) => void;
|
|
215
|
+
'onvariant-applied'?: (e: CustomEvent<{variantName: string | null}>) => void;
|
|
165
216
|
'onar-status'?: (
|
|
166
217
|
e: CustomEvent<{
|
|
167
218
|
status: 'session-started' | 'not-presenting' | 'failed';
|
|
@@ -248,6 +299,8 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
|
248
299
|
'peer-name'?: string;
|
|
249
300
|
/** Local avatar visor & laser color (`#rrggbb`) in `shared-room`. */
|
|
250
301
|
'peer-color'?: string;
|
|
302
|
+
/** Opt-in WebRTC voice signaling relay (offer/answer/ICE) and `voiceGain` helpers in `shared-room`. Apps own `RTCPeerConnection` and audio. */
|
|
303
|
+
'shared-room-voice'?: boolean | string;
|
|
251
304
|
/** xr-live-sim: character camera mode, or `none` to disable the character. */
|
|
252
305
|
'character-controller'?:
|
|
253
306
|
| 'third-person'
|
|
@@ -363,6 +416,17 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
|
363
416
|
onpeergrabconflict?: (
|
|
364
417
|
e: CustomEvent<{peerId: string; nodeId: string}>,
|
|
365
418
|
) => void;
|
|
419
|
+
onpeerrtcsignal?: (
|
|
420
|
+
e: CustomEvent<{
|
|
421
|
+
peerId: string;
|
|
422
|
+
targetPeerId: string;
|
|
423
|
+
signalType: 'offer' | 'answer' | 'ice';
|
|
424
|
+
sdp: string | null;
|
|
425
|
+
candidate: string | null;
|
|
426
|
+
sdpMid: string | null;
|
|
427
|
+
sdpMLineIndex: number | null;
|
|
428
|
+
}>,
|
|
429
|
+
) => void;
|
|
366
430
|
/** xr-live-sim events. */
|
|
367
431
|
oncharacterjump?: (
|
|
368
432
|
e: CustomEvent<{nodeId: string; position: [number, number, number]}>,
|
|
@@ -14,23 +14,23 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
var F="__THREE_LIVE_REGISTRY__";function I(){let e=typeof globalThis<"u"?globalThis:{};if(!e[F]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,F,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[F]=t}}return e[F]}var j=I().plugins;function M(e){let t=I().plugins;t.some(r=>r.name===e.name)||t.push(e)}function P(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function z(e,t,r){let i=t[0],n=t[1],c=t[2],f=t[3],u=t[4],s=t[5],b=t[6],o=t[7],a=t[8],m=t[9],l=t[10],p=t[11],A=t[12],d=t[13],x=t[14],y=t[15],h=r[0],g=r[1],T=r[2],R=r[3];return e[0]=h*i+g*u+T*a+R*A,e[1]=h*n+g*s+T*m+R*d,e[2]=h*c+g*b+T*l+R*x,e[3]=h*f+g*o+T*p+R*y,h=r[4],g=r[5],T=r[6],R=r[7],e[4]=h*i+g*u+T*a+R*A,e[5]=h*n+g*s+T*m+R*d,e[6]=h*c+g*b+T*l+R*x,e[7]=h*f+g*o+T*p+R*y,h=r[8],g=r[9],T=r[10],R=r[11],e[8]=h*i+g*u+T*a+R*A,e[9]=h*n+g*s+T*m+R*d,e[10]=h*c+g*b+T*l+R*x,e[11]=h*f+g*o+T*p+R*y,h=r[12],g=r[13],T=r[14],R=r[15],e[12]=h*i+g*u+T*a+R*A,e[13]=h*n+g*s+T*m+R*d,e[14]=h*c+g*b+T*l+R*x,e[15]=h*f+g*o+T*p+R*y,e}function L(e,t,r,i){let n=t[0],c=t[1],f=t[2],u=t[3],s=n+n,b=c+c,o=f+f,a=n*s,m=n*b,l=n*o,p=c*b,A=c*o,d=f*o,x=u*s,y=u*b,h=u*o,g=i[0],T=i[1],R=i[2];return e[0]=(1-(p+d))*g,e[1]=(m+h)*g,e[2]=(l-y)*g,e[3]=0,e[4]=(m-h)*T,e[5]=(1-(a+d))*T,e[6]=(A+x)*T,e[7]=0,e[8]=(l+y)*R,e[9]=(A-x)*R,e[10]=(1-(a+p))*R,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function W(e,t){let r=t[0],i=t[1],n=t[2],c=t[4],f=t[5],u=t[6],s=t[8],b=t[9],o=t[10],a=o*f-u*b,m=-o*c+u*s,l=b*c-f*s,p=r*a+i*m+n*l;return p&&(p=1/p,e[0]=a*p,e[1]=(-o*i+n*b)*p,e[2]=(u*i-n*f)*p,e[3]=m*p,e[4]=(o*r-n*s)*p,e[5]=(-u*r+n*c)*p,e[6]=l*p,e[7]=(-b*r+i*s)*p,e[8]=(f*r-i*c)*p),e}function D(e,t){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let o=0;o<r;o++)i.push(P());if(r===0)return i;let n=new Set;for(let o of e.nodes)if(Array.isArray(o.children))for(let a of o.children)n.add(a);let c=new Set,f=128,u=(o,a,m=0)=>{if(m>f||o<0||o>=r||c.has(o))return;c.add(o);let l=e.nodes[o];if(!l)return;let p=P();if(t&&t[o])p.set(t[o]);else if(l.matrix&&l.matrix.length===16)p.set(l.matrix);else{let d=l.translation||[0,0,0],x=l.rotation||[0,0,0,1],y=l.scale||[1,1,1];L(p,x,d,y)}let A=i[o];if(a?z(A,a,p):A.set(p),Array.isArray(l.children))for(let d of l.children)typeof d=="number"&&u(d,A,m+1)},s=[],b=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(b&&Array.isArray(b.nodes))s.push(...b.nodes);else for(let o=0;o<r;o++)n.has(o)||s.push(o);for(let o of s)u(o,null);for(let o=0;o<r;o++)!n.has(o)&&!s.includes(o)&&u(o,null);return i}function w(e,t,r){return t%4===0?new Float32Array(e,t,r):new Float32Array(e.slice(t,t+r*4))}function k(e,t,r,i){let n=t[0],c=t[1],f=t[2],u=t[3],s=r[0],b=r[1],o=r[2],a=r[3],m=n*s+c*b+f*o+u*a;if(m<0&&(s=-s,b=-b,o=-o,a=-a,m=-m),Math.abs(m)>=1)return e[0]=n,e[1]=c,e[2]=f,e[3]=u,e;let l=Math.acos(m),p=Math.sqrt(1-m*m);if(Math.abs(p)<.001)return e[0]=.5*(n+s),e[1]=.5*(c+b),e[2]=.5*(f+o),e[3]=.5*(u+a),e;let A=Math.sin((1-i)*l)/p,d=Math.sin(i*l)/p;return e[0]=n*A+s*d,e[1]=c*A+b*d,e[2]=f*A+o*d,e[3]=u*A+a*d,e}function G(e,t,r,i){return e[0]=t[0]+i*(r[0]-t[0]),e[1]=t[1]+i*(r[1]-t[1]),e[2]=t[2]+i*(r[2]-t[2]),e}function B(e,t){if(!Array.isArray(e?.animations))return[];let r=[];for(let i=0;i<e.animations.length;i++){let n=e.animations[i],c=n.name||`Animation_${i}`,f=[],u=0;if(Array.isArray(n.channels)&&Array.isArray(n.samplers))for(let s of n.channels){if(!s.target||s.target.node===void 0||!s.target.path)continue;let b=n.samplers[s.sampler];if(!b)continue;let o=e.accessors?.[b.input],a=e.accessors?.[b.output];if(!o||!a)continue;let m=e.bufferViews?.[o.bufferView],l=e.bufferViews?.[a.bufferView];if(!m||!l)continue;let p=(m.byteOffset||0)+(o.byteOffset||0),A=(l.byteOffset||0)+(a.byteOffset||0),d=w(t,p,o.count);d.length>0&&d[d.length-1]>u&&(u=d[d.length-1]);let x=s.target.path==="rotation"?4:s.target.path==="weights"?Math.max(1,Math.round(a.count/Math.max(1,o.count))):3,y=w(t,A,a.count*(s.target.path==="weights"?1:x)),h=b.interpolation==="STEP"?"STEP":"LINEAR";f.push({nodeIndex:s.target.node,path:s.target.path,times:d,values:y,interpolation:h})}f.length>0&&r.push({name:c,duration:u,channels:f})}return r}function v(e,t,r){let{times:i,values:n,path:c,interpolation:f}=e,u=i.length;if(u===0)return;let s=c==="rotation"?4:c==="weights"?Math.max(1,Math.round(n.length/u)):3;if(t<=i[0]){for(let y=0;y<s;y++)r[y]=n[y];return}if(t>=i[u-1]){let y=(u-1)*s;for(let h=0;h<s;h++)r[h]=n[y+h];return}let b=0,o=u-1;for(;b<=o;){let y=b+o>>1;i[y]<=t?b=y+1:o=y-1}let a=Math.max(0,o),m=Math.min(u-1,a+1);if(f==="STEP"||a===m){let y=a*s;for(let h=0;h<s;h++)r[h]=n[y+h];return}let l=i[a],p=i[m],A=(t-l)/Math.max(1e-5,p-l),d=a*s,x=m*s;if(c==="rotation"){let y=[n[d],n[d+1],n[d+2],n[d+3]],h=[n[x],n[x+1],n[x+2],n[x+3]];k(r,y,h,A)}else for(let y=0;y<s;y++)r[y]=n[d+y]+A*(n[x+y]-n[d+y])}var E=new WeakMap;function O(e,t,r=.3){if(!e?.animations)return;let i=e.animations.find(u=>u.name===t);if(!i)return;let n=E.get(e);n||(n=[],e.currentClip&&n.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),E.set(e,n));let c=r>0?1/r:1e3;for(let u of n)u.clip.name!==t&&(u.fadeSpeed=-c);let f=n.find(u=>u.clip.name===t);f?f.fadeSpeed=c:n.push({clip:i,time:0,weight:r>0?0:1,fadeSpeed:c}),e.currentClip=i,e.isPlayingAnimation=!0}function _(e,t){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let r=E.get(e);if(!r||r.length===0){if(!e.currentClip)return;r=[{clip:e.currentClip,time:t,weight:1,fadeSpeed:0}]}let i=e.gltf.nodes.length,n=[];for(let a=0;a<i;a++){let m=e.initialNodeTransforms[a];m?n.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]]}):n.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let c=[0,0,0],f=[0,0,0,1],u=[1,1,1],s=new Float32Array(64);for(let a of r){let m=Math.max(0,Math.min(1,a.weight));if(!(m<=1e-4))for(let l of a.clip.channels){if(l.nodeIndex<0||l.nodeIndex>=i)continue;let p=n[l.nodeIndex];if(l.path==="translation")v(l,a.time,c),G(p.t,p.t,c,m);else if(l.path==="rotation")v(l,a.time,f),k(p.r,p.r,f,m);else if(l.path==="scale")v(l,a.time,u),G(p.s,p.s,u,m);else if(l.path==="weights"&&(v(l,a.time,s),e.meshes)){for(let A of e.meshes)if(A.nodeIndex===l.nodeIndex){for(let d of A.primitives)if(d.pluginData?.morph?.weights){let x=d.pluginData.morph.weights,y=d.pluginData.morph.numTargets||x.length;for(let h=0;h<y;h++)x[h]=x[h]*(1-m)+s[h]*m}}}}}let b=[];for(let a=0;a<i;a++){let m=P(),{t:l,r:p,s:A}=n[a];L(m,p,l,A),b.push(m)}let o=D(e.gltf,b);e.worldMatrices=o;for(let a of e.meshes)a.nodeIndex>=0&&a.nodeIndex<o.length&&(a.transform.set(o[a.nodeIndex]),W(a.normalMatrix,a.transform))}var V={name:"keyframes",evaluateAnimation:_,crossFadeTo:O,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=B(e.gltf,e.bin))},onUpdate(e,t){if(!e.isPlayingAnimation)return;let r=E.get(e);if(r&&r.length>0){for(let i=r.length-1;i>=0;i--){let n=r[i];if(n.time+=t,n.clip.duration>0&&(n.time%=n.clip.duration),n.fadeSpeed!==0)if(n.weight+=n.fadeSpeed*t,n.weight<=0){r.splice(i,1);continue}else n.weight>=1&&(n.weight=1,n.fadeSpeed=0)}r.length>0&&(e.animationTime=r[r.length-1].time),_(e,e.animationTime)}else e.currentClip&&(e.animationTime+=t,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),_(e,e.animationTime))}};var S=64;function X(e,t,r){if(!(!e?.meshes||t<0||t>=S))for(let i of e.meshes)for(let n of i.primitives){let c=n.pluginData?.morph;c?.weights&&(c.weights[t]=r)}}var U={name:"morph",onResolveShader(e,t,r,i){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let n=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
|
|
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;
|
|
18
18
|
uniform sampler2D uMorphDeltasTex;
|
|
19
|
-
uniform float uMorphWeights[${
|
|
20
|
-
uniform int uNumMorphTargets;`);return
|
|
21
|
-
for (int m = 0; m < ${
|
|
19
|
+
uniform float uMorphWeights[${$}];
|
|
20
|
+
uniform int uNumMorphTargets;`);return r=r.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
|
|
21
|
+
for (int m = 0; m < ${$}; m++) {
|
|
22
22
|
if (m >= uNumMorphTargets) break;
|
|
23
23
|
float w = uMorphWeights[m];
|
|
24
24
|
if (abs(w) > 0.0001) {
|
|
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:
|
|
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;
|
|
29
29
|
layout(location=4) in uvec4 aJoints;
|
|
30
30
|
layout(location=5) in vec4 aWeights;
|
|
31
|
-
uniform mat4 uJointMatrix[${
|
|
31
|
+
uniform mat4 uJointMatrix[${hn}];`),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(${
|
|
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};
|
|
@@ -14,23 +14,23 @@
|
|
|
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 L=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var $=(e,n)=>{for(var r in n)L(e,r,{get:n[r],enumerable:!0})},Y=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of J(n))!H.call(e,t)&&t!==r&&L(e,t,{get:()=>n[t],enumerable:!(i=j(n,t))||i.enumerable});return e};var q=e=>Y(L({},"__esModule",{value:!0}),e);var Q={};$(Q,{crossFadeTo:()=>W,keyframeAnimationPlugin:()=>D,morphPlugin:()=>G,parseAnimations:()=>I,sampleChannel:()=>v,setMorphTargetWeight:()=>X,skinningPlugin:()=>B});var F="__THREE_LIVE_REGISTRY__";function O(){let e=typeof globalThis<"u"?globalThis:{};if(!e[F]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,F,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[F]=n}}return e[F]}var ee=O().plugins;function M(e){let n=O().plugins;n.some(r=>r.name===e.name)||n.push(e)}function P(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function K(e,n,r){let i=n[0],t=n[1],c=n[2],f=n[3],u=n[4],s=n[5],b=n[6],o=n[7],a=n[8],m=n[9],l=n[10],p=n[11],A=n[12],d=n[13],x=n[14],y=n[15],h=r[0],g=r[1],T=r[2],R=r[3];return e[0]=h*i+g*u+T*a+R*A,e[1]=h*t+g*s+T*m+R*d,e[2]=h*c+g*b+T*l+R*x,e[3]=h*f+g*o+T*p+R*y,h=r[4],g=r[5],T=r[6],R=r[7],e[4]=h*i+g*u+T*a+R*A,e[5]=h*t+g*s+T*m+R*d,e[6]=h*c+g*b+T*l+R*x,e[7]=h*f+g*o+T*p+R*y,h=r[8],g=r[9],T=r[10],R=r[11],e[8]=h*i+g*u+T*a+R*A,e[9]=h*t+g*s+T*m+R*d,e[10]=h*c+g*b+T*l+R*x,e[11]=h*f+g*o+T*p+R*y,h=r[12],g=r[13],T=r[14],R=r[15],e[12]=h*i+g*u+T*a+R*A,e[13]=h*t+g*s+T*m+R*d,e[14]=h*c+g*b+T*l+R*x,e[15]=h*f+g*o+T*p+R*y,e}function _(e,n,r,i){let t=n[0],c=n[1],f=n[2],u=n[3],s=t+t,b=c+c,o=f+f,a=t*s,m=t*b,l=t*o,p=c*b,A=c*o,d=f*o,x=u*s,y=u*b,h=u*o,g=i[0],T=i[1],R=i[2];return e[0]=(1-(p+d))*g,e[1]=(m+h)*g,e[2]=(l-y)*g,e[3]=0,e[4]=(m-h)*T,e[5]=(1-(a+d))*T,e[6]=(A+x)*T,e[7]=0,e[8]=(l+y)*R,e[9]=(A-x)*R,e[10]=(1-(a+p))*R,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function V(e,n){let r=n[0],i=n[1],t=n[2],c=n[4],f=n[5],u=n[6],s=n[8],b=n[9],o=n[10],a=o*f-u*b,m=-o*c+u*s,l=b*c-f*s,p=r*a+i*m+t*l;return p&&(p=1/p,e[0]=a*p,e[1]=(-o*i+t*b)*p,e[2]=(u*i-t*f)*p,e[3]=m*p,e[4]=(o*r-t*s)*p,e[5]=(-u*r+t*c)*p,e[6]=l*p,e[7]=(-b*r+i*s)*p,e[8]=(f*r-i*c)*p),e}function U(e,n){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let o=0;o<r;o++)i.push(P());if(r===0)return i;let t=new Set;for(let o of e.nodes)if(Array.isArray(o.children))for(let a of o.children)t.add(a);let c=new Set,f=128,u=(o,a,m=0)=>{if(m>f||o<0||o>=r||c.has(o))return;c.add(o);let l=e.nodes[o];if(!l)return;let p=P();if(n&&n[o])p.set(n[o]);else if(l.matrix&&l.matrix.length===16)p.set(l.matrix);else{let d=l.translation||[0,0,0],x=l.rotation||[0,0,0,1],y=l.scale||[1,1,1];_(p,x,d,y)}let A=i[o];if(a?K(A,a,p):A.set(p),Array.isArray(l.children))for(let d of l.children)typeof d=="number"&&u(d,A,m+1)},s=[],b=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(b&&Array.isArray(b.nodes))s.push(...b.nodes);else for(let o=0;o<r;o++)t.has(o)||s.push(o);for(let o of s)u(o,null);for(let o=0;o<r;o++)!t.has(o)&&!s.includes(o)&&u(o,null);return i}function w(e,n,r){return n%4===0?new Float32Array(e,n,r):new Float32Array(e.slice(n,n+r*4))}function z(e,n,r,i){let t=n[0],c=n[1],f=n[2],u=n[3],s=r[0],b=r[1],o=r[2],a=r[3],m=t*s+c*b+f*o+u*a;if(m<0&&(s=-s,b=-b,o=-o,a=-a,m=-m),Math.abs(m)>=1)return e[0]=t,e[1]=c,e[2]=f,e[3]=u,e;let l=Math.acos(m),p=Math.sqrt(1-m*m);if(Math.abs(p)<.001)return e[0]=.5*(t+s),e[1]=.5*(c+b),e[2]=.5*(f+o),e[3]=.5*(u+a),e;let A=Math.sin((1-i)*l)/p,d=Math.sin(i*l)/p;return e[0]=t*A+s*d,e[1]=c*A+b*d,e[2]=f*A+o*d,e[3]=u*A+a*d,e}function N(e,n,r,i){return e[0]=n[0]+i*(r[0]-n[0]),e[1]=n[1]+i*(r[1]-n[1]),e[2]=n[2]+i*(r[2]-n[2]),e}function I(e,n){if(!Array.isArray(e?.animations))return[];let r=[];for(let i=0;i<e.animations.length;i++){let t=e.animations[i],c=t.name||`Animation_${i}`,f=[],u=0;if(Array.isArray(t.channels)&&Array.isArray(t.samplers))for(let s of t.channels){if(!s.target||s.target.node===void 0||!s.target.path)continue;let b=t.samplers[s.sampler];if(!b)continue;let o=e.accessors?.[b.input],a=e.accessors?.[b.output];if(!o||!a)continue;let m=e.bufferViews?.[o.bufferView],l=e.bufferViews?.[a.bufferView];if(!m||!l)continue;let p=(m.byteOffset||0)+(o.byteOffset||0),A=(l.byteOffset||0)+(a.byteOffset||0),d=w(n,p,o.count);d.length>0&&d[d.length-1]>u&&(u=d[d.length-1]);let x=s.target.path==="rotation"?4:s.target.path==="weights"?Math.max(1,Math.round(a.count/Math.max(1,o.count))):3,y=w(n,A,a.count*(s.target.path==="weights"?1:x)),h=b.interpolation==="STEP"?"STEP":"LINEAR";f.push({nodeIndex:s.target.node,path:s.target.path,times:d,values:y,interpolation:h})}f.length>0&&r.push({name:c,duration:u,channels:f})}return r}function v(e,n,r){let{times:i,values:t,path:c,interpolation:f}=e,u=i.length;if(u===0)return;let s=c==="rotation"?4:c==="weights"?Math.max(1,Math.round(t.length/u)):3;if(n<=i[0]){for(let y=0;y<s;y++)r[y]=t[y];return}if(n>=i[u-1]){let y=(u-1)*s;for(let h=0;h<s;h++)r[h]=t[y+h];return}let b=0,o=u-1;for(;b<=o;){let y=b+o>>1;i[y]<=n?b=y+1:o=y-1}let a=Math.max(0,o),m=Math.min(u-1,a+1);if(f==="STEP"||a===m){let y=a*s;for(let h=0;h<s;h++)r[h]=t[y+h];return}let l=i[a],p=i[m],A=(n-l)/Math.max(1e-5,p-l),d=a*s,x=m*s;if(c==="rotation"){let y=[t[d],t[d+1],t[d+2],t[d+3]],h=[t[x],t[x+1],t[x+2],t[x+3]];z(r,y,h,A)}else for(let y=0;y<s;y++)r[y]=t[d+y]+A*(t[x+y]-t[d+y])}var E=new WeakMap;function W(e,n,r=.3){if(!e?.animations)return;let i=e.animations.find(u=>u.name===n);if(!i)return;let t=E.get(e);t||(t=[],e.currentClip&&t.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),E.set(e,t));let c=r>0?1/r:1e3;for(let u of t)u.clip.name!==n&&(u.fadeSpeed=-c);let f=t.find(u=>u.clip.name===n);f?f.fadeSpeed=c:t.push({clip:i,time:0,weight:r>0?0:1,fadeSpeed:c}),e.currentClip=i,e.isPlayingAnimation=!0}function C(e,n){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let r=E.get(e);if(!r||r.length===0){if(!e.currentClip)return;r=[{clip:e.currentClip,time:n,weight:1,fadeSpeed:0}]}let i=e.gltf.nodes.length,t=[];for(let a=0;a<i;a++){let m=e.initialNodeTransforms[a];m?t.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]]}):t.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let c=[0,0,0],f=[0,0,0,1],u=[1,1,1],s=new Float32Array(64);for(let a of r){let m=Math.max(0,Math.min(1,a.weight));if(!(m<=1e-4))for(let l of a.clip.channels){if(l.nodeIndex<0||l.nodeIndex>=i)continue;let p=t[l.nodeIndex];if(l.path==="translation")v(l,a.time,c),N(p.t,p.t,c,m);else if(l.path==="rotation")v(l,a.time,f),z(p.r,p.r,f,m);else if(l.path==="scale")v(l,a.time,u),N(p.s,p.s,u,m);else if(l.path==="weights"&&(v(l,a.time,s),e.meshes)){for(let A of e.meshes)if(A.nodeIndex===l.nodeIndex){for(let d of A.primitives)if(d.pluginData?.morph?.weights){let x=d.pluginData.morph.weights,y=d.pluginData.morph.numTargets||x.length;for(let h=0;h<y;h++)x[h]=x[h]*(1-m)+s[h]*m}}}}}let b=[];for(let a=0;a<i;a++){let m=P(),{t:l,r:p,s:A}=t[a];_(m,p,l,A),b.push(m)}let o=U(e.gltf,b);e.worldMatrices=o;for(let a of e.meshes)a.nodeIndex>=0&&a.nodeIndex<o.length&&(a.transform.set(o[a.nodeIndex]),V(a.normalMatrix,a.transform))}var D={name:"keyframes",evaluateAnimation:C,crossFadeTo:W,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=I(e.gltf,e.bin))},onUpdate(e,n){if(!e.isPlayingAnimation)return;let r=E.get(e);if(r&&r.length>0){for(let i=r.length-1;i>=0;i--){let t=r[i];if(t.time+=n,t.clip.duration>0&&(t.time%=t.clip.duration),t.fadeSpeed!==0)if(t.weight+=t.fadeSpeed*n,t.weight<=0){r.splice(i,1);continue}else t.weight>=1&&(t.weight=1,t.fadeSpeed=0)}r.length>0&&(e.animationTime=r[r.length-1].time),C(e,e.animationTime)}else e.currentClip&&(e.animationTime+=n,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),C(e,e.animationTime))}};var S=64;function X(e,n,r){if(!(!e?.meshes||n<0||n>=S))for(let i of e.meshes)for(let t of i.primitives){let c=t.pluginData?.morph;c?.weights&&(c.weights[n]=r)}}var G={name:"morph",onResolveShader(e,n,r,i){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let t=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
|
|
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;
|
|
18
18
|
uniform sampler2D uMorphDeltasTex;
|
|
19
|
-
uniform float uMorphWeights[${
|
|
20
|
-
uniform int uNumMorphTargets;`);return
|
|
21
|
-
for (int m = 0; m < ${
|
|
19
|
+
uniform float uMorphWeights[${$}];
|
|
20
|
+
uniform int uNumMorphTargets;`);return r=r.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
|
|
21
|
+
for (int m = 0; m < ${$}; m++) {
|
|
22
22
|
if (m >= uNumMorphTargets) break;
|
|
23
23
|
float w = uMorphWeights[m];
|
|
24
24
|
if (abs(w) > 0.0001) {
|
|
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:
|
|
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;
|
|
29
29
|
layout(location=4) in uvec4 aJoints;
|
|
30
30
|
layout(location=5) in vec4 aWeights;
|
|
31
|
-
uniform mat4 uJointMatrix[${
|
|
31
|
+
uniform mat4 uJointMatrix[${Mn}];`),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(${
|
|
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);})();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
"use strict";var Ce=Object.defineProperty;var kn=Object.getOwnPropertyDescriptor;var Gn=Object.getOwnPropertyNames;var Cn=Object.prototype.hasOwnProperty;var Tn=(P,C)=>{for(var _ in C)Ce(P,_,{get:C[_],enumerable:!0})},Ln=(P,C,_,le)=>{if(C&&typeof C=="object"||typeof C=="function")for(let ee of Gn(C))!Cn.call(P,ee)&&ee!==_&&Ce(P,ee,{get:()=>C[ee],enumerable:!(le=kn(C,ee))||le.enumerable});return P};var En=P=>Ln(Ce({},"__esModule",{value:!0}),P);var Rn={};Tn(Rn,{MAX_BSP_DEPTH:()=>cn,MAX_CSG_TRIANGLES:()=>rn,MAX_SHAPE_POINTS:()=>un,MAX_TEXT_GEOMETRY_CHARS:()=>an,cadPlugin:()=>Te,installCadExtension:()=>Se});module.exports=En(Rn);var ve="__THREE_LIVE_REGISTRY__";function ye(){let P=typeof globalThis<"u"?globalThis:{};if(!P[ve]){let C={plugins:[],decoders:new Map};try{Object.defineProperty(P,ve,{value:C,writable:!1,configurable:!1,enumerable:!1})}catch{P[ve]=C}}return P[ve]}var Vn=ye().plugins;function sn(P){let C=ye();C.workerExtensionInstallers||(C.workerExtensionInstallers=[]),C.workerExtensionInstallers.includes(P)||C.workerExtensionInstallers.push(P)}function on(P){let C=ye().plugins;C.some(_=>_.name===P.name)||C.push(P),P.onRegister?.()}var rn=8192,cn=2048,an=128,un=4096;function Se(P,C){if(!P||!P.BufferGeometry)return null;let _=P.Vector2,le=P.Vector3,ee=P.Quaternion,Pe=P.Matrix4,ln=P.Matrix3,hn=P.Color,D=P.BufferAttribute,te=P.BufferGeometry,mn=P.Material,Le=P.MeshStandardMaterial,fe=P.Mesh,he=8192,se=2048,Ee=128,we=4096,O=(t,e)=>{let n=t==null?NaN:Number(t);return Number.isFinite(n)?n:e};class xe{constructor(e){this.currentPoint=new _(0,0),this.segments=[],Array.isArray(e)&&e.length>0&&this.fromPoints(e)}fromPoints(e){if(!e.length)return this;this.moveTo(e[0].x,e[0].y);for(let n=1;n<e.length;n++)this.lineTo(e[n].x,e[n].y);return this}moveTo(e,n){let s=Number(e)||0,o=Number(n)||0;return this.currentPoint.set(s,o),this.segments.push({type:"move",pts:[s,o]}),this}lineTo(e,n){let s=Number(e)||0,o=Number(n)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(s,o),this.segments.push({type:"line",pts:[s,o]}),this}quadraticCurveTo(e,n,s,o){let i=this.currentPoint.x,c=this.currentPoint.y,a=Number(e)||0,u=Number(n)||0,r=Number(s)||0,h=Number(o)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[i,c]}),this.currentPoint.set(r,h),this.segments.push({type:"quad",pts:[i,c,a,u,r,h]}),this}bezierCurveTo(e,n,s,o,i,c){let a=this.currentPoint.x,u=this.currentPoint.y,r=Number(e)||0,h=Number(n)||0,m=Number(s)||0,l=Number(o)||0,f=Number(i)||0,x=Number(c)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[a,u]}),this.currentPoint.set(f,x),this.segments.push({type:"cubic",pts:[a,u,r,h,m,l,f,x]}),this}absarc(e,n,s,o,i,c=!1){return this.absellipse(e,n,s,s,o,i,c,0)}arc(e,n,s,o,i,c=!1){return this.absarc(this.currentPoint.x+(Number(e)||0),this.currentPoint.y+(Number(n)||0),s,o,i,c)}absellipse(e,n,s,o,i,c,a=!1,u=0){let r=Number(e)||0,h=Number(n)||0,m=Math.max(0,Number(s)||0),l=Math.max(0,Number(o)||0),f=Number(i)||0,x=Number(c)||0,b=a?1:0,p=Number(u)||0;this.segments.push({type:"arc",pts:[r,h,m,l,f,x,b,p]});let y=Math.cos(p),g=Math.sin(p),S=m*Math.cos(x),d=l*Math.sin(x);return this.currentPoint.set(r+S*y-d*g,h+S*g+d*y),this}ellipse(e,n,s,o,i,c,a=!1,u=0){return this.absellipse(this.currentPoint.x+(Number(e)||0),this.currentPoint.y+(Number(n)||0),s,o,i,c,a,u)}closePath(){if(this.segments.length>0){let e=this.segments[0],n=0,s=0;if(e.type==="arc"){let o=e.pts[0],i=e.pts[1],c=e.pts[2],a=e.pts[3],u=e.pts[4],r=e.pts[7],h=Math.cos(r),m=Math.sin(r),l=c*Math.cos(u),f=a*Math.sin(u);n=o+l*h-f*m,s=i+l*m+f*h}else n=e.pts[0],s=e.pts[1];Math.hypot(this.currentPoint.x-n,this.currentPoint.y-s)>1e-6&&this.lineTo(n,s)}return this}getPoints(e=12){let n=Math.max(1,Math.min(128,Math.floor(Number(e)||12))),s=[],o=(i,c)=>{if(s.length>0){let a=s[s.length-1];if(Math.hypot(a.x-i,a.y-c)<1e-6)return}s.push(new _(i,c))};for(let i of this.segments){let c=i.pts;if(i.type==="move"||i.type==="line")o(c[0],c[1]);else if(i.type==="quad"){let a=c[0],u=c[1],r=c[2],h=c[3],m=c[4],l=c[5];o(a,u);for(let f=1;f<=n;f++){let x=f/n,b=1-x;o(b*b*a+2*b*x*r+x*x*m,b*b*u+2*b*x*h+x*x*l)}}else if(i.type==="cubic"){let a=c[0],u=c[1],r=c[2],h=c[3],m=c[4],l=c[5],f=c[6],x=c[7];o(a,u);for(let b=1;b<=n;b++){let p=b/n,y=1-p,g=y*y,S=p*p;o(g*y*a+3*g*p*r+3*y*S*m+S*p*f,g*y*u+3*g*p*h+3*y*S*l+S*p*x)}}else if(i.type==="arc"){let a=c[0],u=c[1],r=c[2],h=c[3],m=c[4],l=c[5],f=c[6]!==0,x=c[7],b=Math.PI*2,p=l-m,y=Math.abs(p)<1e-9;for(;p<0;)p+=b;for(;p>b;)p-=b;p<1e-9&&(p=y?0:b),f&&!y&&(p=p===b?-b:p-b);let g=Math.cos(x),S=Math.sin(x),d=Math.max(2,n);for(let T=0;T<=d;T++){let w=T/d,E=m+w*p,k=r*Math.cos(E),L=h*Math.sin(E);o(a+k*g-L*S,u+k*S+L*g)}}}if(s.length>2){let i=s[0],c=s[s.length-1];Math.hypot(i.x-c.x,i.y-c.y)<1e-6&&s.pop()}return s}getSpacedPoints(e=12){return this.getPoints(e)}}class be extends xe{constructor(e){super(e),this.holes=[]}extractPoints(e=12){return{shape:this.getPoints(e),holes:this.holes.map(n=>n.getPoints(e))}}}function pe(t){let e=0,n=t.length;for(let s=0,o=n-1;s<n;o=s++)e+=t[o].x*t[s].y-t[s].x*t[o].y;return e*.5}function yn(t,e,n,s,o,i,c,a){let u=c-n,r=a-s,h=o-n,m=i-s,l=t-n,f=e-s,x=u*u+r*r,b=u*h+r*m,p=u*l+r*f,y=h*h+m*m,g=h*l+m*f,S=x*y-b*b;if(Math.abs(S)<1e-12)return!1;let d=1/S,T=(y*p-b*g)*d,w=(x*g-b*p)*d;return T>=-1e-7&&w>=-1e-7&&T+w<=1+1e-7}function Re(t,e){let n=t.slice();pe(n)<0&&n.reverse();let s=n.map(u=>new _(u.x,u.y)),o=n.map((u,r)=>r),i=[];for(let u of e){if(!u||u.length<3)continue;let r=u.slice();pe(r)>0&&r.reverse();let h=[],m=-1/0,l=0;for(let f=0;f<r.length;f++){let x=r[f],b=s.length;s.push(new _(x.x,x.y)),h.push(b),x.x>m&&(m=x.x,l=f)}i.push({pts:r,indices:h,maxX:m,maxIdx:l})}i.sort((u,r)=>r.maxX-u.maxX);let c=(u,r,h)=>(r.x-u.x)*(h.y-u.y)-(r.y-u.y)*(h.x-u.x),a=(u,r,h)=>{for(let m=0;m<h.length;m++){let l=h[m],f=h[(m+1)%h.length];if(c(u,r,l)*c(u,r,f)<0&&c(l,f,u)*c(l,f,r)<0)return!0}return!1};for(let u of i){let r=u.pts[u.maxIdx],h=r.x,m=o.length,l=o.map(y=>s[y]),f=y=>Math.hypot(l[y].x-h,l[y].y-r.y),x=l.map((y,g)=>g).sort((y,g)=>+(l[y].x<h)-+(l[g].x<h)||f(y)-f(g)),b=x[0];for(let y of x){let g=l[y],S=l[(y+m-1)%m],d=l[(y+1)%m],T=c(g,d,r)>=0,w=c(S,g,r)>=0;if((c(S,g,d)>=0?T&&w:T||w)&&!a(r,g,l)&&!i.some(k=>a(r,g,k.pts))){b=y;break}}let p=[];for(let y=0;y<=b;y++)p.push(o[y]);for(let y=0;y<=u.indices.length;y++){let g=u.indices[(u.maxIdx+y)%u.indices.length];p.push(g)}for(let y=b;y<o.length;y++)p.push(o[y]);o=p}return{merged:o.map(u=>s[u]),mergedIndices:o,allVertices:s}}function Ae(t,e){let n=[],s=t.slice();if(s.length<3)return n;let o=s.length*s.length+64,i=0;for(;s.length>2&&o-- >0;){let c=s.length,a=s[(i+c-1)%c],u=s[i%c],r=s[(i+1)%c],h=e[a],m=e[u],l=e[r];if((m.x-h.x)*(l.y-h.y)-(m.y-h.y)*(l.x-h.x)>1e-9){let x=!0;for(let b=0;b<c;b++){let p=s[b];if(p===a||p===u||p===r)continue;let y=e[p];if(yn(y.x,y.y,h.x,h.y,m.x,m.y,l.x,l.y)&&Math.hypot(y.x-h.x,y.y-h.y)>=1e-6&&Math.hypot(y.x-m.x,y.y-m.y)>=1e-6&&Math.hypot(y.x-l.x,y.y-l.y)>=1e-6){x=!1;break}}if(x){n.push([a,u,r]),s.splice(i%c,1),i=Math.max(0,i%c-1);continue}}i++,i>=c*2&&(n.push([a,u,r]),s.splice((i-1)%c,1),i=0)}return n}function Ve(t,e){let n=t instanceof be?t.extractPoints(e):{shape:t.getPoints(e),holes:[]},s=n.shape.length;for(let o of n.holes)s+=o.length;if(s>we)throw new RangeError(`SecurityError: shape point count (${s}) exceeds MAX_SHAPE_POINTS (${we})`);return n}class fn extends te{constructor(e=new be,n=12){super();let s=Array.isArray(e)?e:[e],o=[],i=[],c=[],a=[];for(let u of s){if(!(u instanceof xe))continue;let r=Ve(u,n);if(r.shape.length<3)continue;let{mergedIndices:h,allVertices:m}=Re(r.shape,r.holes),l=Ae(h,m),f=o.length/3,x=1/0,b=1/0,p=-1/0,y=-1/0;for(let d of m)d.x<x&&(x=d.x),d.y<b&&(b=d.y),d.x>p&&(p=d.x),d.y>y&&(y=d.y);let g=Math.max(1e-6,p-x),S=Math.max(1e-6,y-b);for(let d of m)o.push(d.x,d.y,0),i.push(0,0,1),c.push((d.x-x)/g,(d.y-b)/S);for(let[d,T,w]of l)a.push(f+d,f+T,f+w)}this.setAttribute("position",new D(new Float32Array(o),3)),this.setAttribute("normal",new D(new Float32Array(i),3)),this.setAttribute("uv",new D(new Float32Array(c),2)),this.setIndex(a)}}function xn(t){let e=t.length,n=[];for(let s=0;s<e;s++){let o=t[(s+e-1)%e],i=t[s],c=t[(s+1)%e],a=i.x-o.x,u=i.y-o.y,r=Math.hypot(a,u)||1;a/=r,u/=r;let h=c.x-i.x,m=c.y-i.y,l=Math.hypot(h,m)||1;h/=l,m/=l;let f=u,x=-a,b=m,p=-h,y=f+b,g=x+p,S=Math.hypot(y,g);if(S>1e-6){y/=S,g/=S;let d=Math.max(.35,y*f+g*x);n.push(new _(y/d,g/d))}else n.push(new _(f,x))}return n}class bn extends te{constructor(e=new be,n={}){super();let s=Array.isArray(e)?e:[e],o=Math.max(1,Math.min(64,Math.floor(O(n.curveSegments,12)))),i=O(n.depth??n.amount,1),c=Math.max(1,Math.min(32,Math.floor(O(n.steps,1)))),a=!!(n.bevelEnabled??!1),u=a?Math.max(0,O(n.bevelThickness,.06)):0,r=a?Math.max(0,O(n.bevelSize,u*.8)):0,h=a?O(n.bevelOffset,0):0,m=a?Math.max(1,Math.min(8,Math.floor(O(n.bevelSegments,2)))):0,l=[],f=[],x=[],b=[];for(let p of s){if(!(p instanceof xe))continue;let y=Ve(p,o);if(y.shape.length<3)continue;let g=y.shape.slice();pe(g)<0&&g.reverse();let S=[];for(let v of y.holes){if(v.length<3)continue;let M=v.slice();pe(M)>0&&M.reverse(),S.push(M)}let{mergedIndices:d,allVertices:T}=Re(g,S),w=Ae(d,T),E=[g,...S],k=[];for(let v of E){let M=xn(v);for(let G of M)k.push(G)}let L=1/0,z=1/0,V=-1/0,B=-1/0;for(let v of T)v.x<L&&(L=v.x),v.y<z&&(z=v.y),v.x>V&&(V=v.x),v.y>B&&(B=v.y);let I=Math.max(1e-6,V-L),F=Math.max(1e-6,B-z),oe=-u,re=i+u,W=l.length/3;for(let v=0;v<T.length;v++){let M=T[v],G=k[v]??new _(0,0),R=M.x+G.x*h,A=M.y+G.y*h;l.push(R,A,oe),f.push(0,0,-1),x.push((R-L)/I,(A-z)/F)}for(let[v,M,G]of w)b.push(W+v,W+G,W+M);let j=l.length/3;for(let v=0;v<T.length;v++){let M=T[v],G=k[v]??new _(0,0),R=M.x+G.x*h,A=M.y+G.y*h;l.push(R,A,re),f.push(0,0,1),x.push((R-L)/I,(A-z)/F)}for(let[v,M,G]of w)b.push(j+v,j+M,j+G);let N=[];if(a&&m>0)for(let v=0;v<m;v++){let G=v/m*Math.PI/2;N.push({z:-u*Math.cos(G),expand:h+r*Math.sin(G)})}for(let v=0;v<=c;v++){let M=v/c;N.push({z:M*i,expand:h+r})}if(a&&m>0)for(let v=1;v<=m;v++){let G=v/m*Math.PI/2;N.push({z:i+u*Math.sin(G),expand:h+r*Math.cos(G)})}let Y=0;for(let v of E){let M=v.length;for(let G=0;G<N.length-1;G++){let R=N[G],A=N[G+1];for(let X=0;X<M;X++){let H=(X+1)%M,$=v[X],U=v[H],Q=k[Y+X],Z=k[Y+H],K=$.x+Q.x*R.expand,J=$.y+Q.y*R.expand,ne=U.x+Z.x*R.expand,q=U.y+Z.y*R.expand,wn=U.x+Z.x*A.expand,Mn=U.y+Z.y*A.expand,qe=$.x+Q.x*A.expand,We=$.y+Q.y*A.expand,je=ne-K,$e=q-J,Ue=0,Qe=qe-K,Ze=We-J,Ke=A.z-R.z,ie=$e*Ke-Ue*Ze,ce=Ue*Qe-je*Ke,ae=je*Ze-$e*Qe,Ge=Math.hypot(ie,ce,ae)||1;ie/=Ge,ce/=Ge,ae/=Ge;let ue=l.length/3;l.push(K,J,R.z,ne,q,R.z,wn,Mn,A.z,qe,We,A.z),f.push(ie,ce,ae,ie,ce,ae,ie,ce,ae,ie,ce,ae);let Je=X/M,en=(X+1)/M,nn=G/(N.length-1),tn=(G+1)/(N.length-1);x.push(Je,nn,en,nn,en,tn,Je,tn),b.push(ue,ue+1,ue+2,ue,ue+2,ue+3)}}Y+=M}}this.setAttribute("position",new D(new Float32Array(l),3)),this.setAttribute("normal",new D(new Float32Array(f),3)),this.setAttribute("uv",new D(new Float32Array(x),2)),this.setIndex(b)}}function ze(t){return{x:t.x,y:t.y,z:t.z,nx:t.nx,ny:t.ny,nz:t.nz,u:t.u,v:t.v}}function pn(t){return{x:t.x,y:t.y,z:t.z,nx:-t.nx,ny:-t.ny,nz:-t.nz,u:t.u,v:t.v}}function gn(t,e,n){let s=t.nx+(e.nx-t.nx)*n,o=t.ny+(e.ny-t.ny)*n,i=t.nz+(e.nz-t.nz)*n,c=Math.hypot(s,o,i)||1;return{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n,z:t.z+(e.z-t.z)*n,nx:s/c,ny:o/c,nz:i/c,u:t.u+(e.u-t.u)*n,v:t.v+(e.v-t.v)*n}}function dn(t){if(t.length<3)return null;let e=t[0],n=t[1],s=t[2],o=n.x-e.x,i=n.y-e.y,c=n.z-e.z,a=s.x-e.x,u=s.y-e.y,r=s.z-e.z,h=i*r-c*u,m=c*a-o*r,l=o*u-i*a,f=Math.hypot(h,m,l);if(f<1e-9)return null;h/=f,m/=f,l/=f;let x=h*e.x+m*e.y+l*e.z;return{vertices:t,nx:h,ny:m,nz:l,w:x}}function vn(t){t.vertices.reverse();for(let e=0;e<t.vertices.length;e++)t.vertices[e]=pn(t.vertices[e]);t.nx=-t.nx,t.ny=-t.ny,t.nz=-t.nz,t.w=-t.w}let Ie=1e-5,_e=0,Me=1,ge=2,Ne=3;function Xe(t,e,n,s,o,i,c,a,u){let r=0,h=[];for(let m=0;m<o.vertices.length;m++){let l=o.vertices[m],f=t*l.x+e*l.y+n*l.z-s,x=f<-Ie?ge:f>Ie?Me:_e;r|=x,h.push(x)}switch(r){case _e:{t*o.nx+e*o.ny+n*o.nz>0?i.push(o):c.push(o);break}case Me:a.push(o);break;case ge:u.push(o);break;case Ne:{let m=[],l=[],f=o.vertices.length;for(let g=0;g<f;g++){let S=(g+1)%f,d=h[g],T=h[S],w=o.vertices[g],E=o.vertices[S];if(d!==ge&&m.push(w),d!==Me&&l.push(d!==ge?ze(w):w),(d|T)===Ne){let k=E.x-w.x,L=E.y-w.y,z=E.z-w.z,V=t*k+e*L+n*z,B=Math.abs(V)>1e-12?(s-(t*w.x+e*w.y+n*w.z))/V:.5,I=gn(w,E,Math.max(0,Math.min(1,B)));m.push(I),l.push(ze(I))}}let{nx:x,ny:b,nz:p,w:y}=o;m.length>=3&&a.push({vertices:m,nx:x,ny:b,nz:p,w:y}),l.length>=3&&u.push({vertices:l,nx:x,ny:b,nz:p,w:y});break}default:break}}class me{constructor(e,n=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,e&&e.length>0&&this.build(e,n)}invert(){for(let n=0;n<this.polygons.length;n++)vn(this.polygons[n]);this.nx=-this.nx,this.ny=-this.ny,this.nz=-this.nz,this.w=-this.w,this.front&&this.front.invert(),this.back&&this.back.invert();let e=this.front;this.front=this.back,this.back=e}clipPolygons(e,n=0){if(!this.hasPlane||e.length===0)return e.slice();if(n>=se)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${se})`);let s=[],o=[];for(let i=0;i<e.length;i++)Xe(this.nx,this.ny,this.nz,this.w,e[i],s,o,s,o);return this.front&&s.length>0&&(s=this.front.clipPolygons(s,n+1)),this.back?o=o.length>0?this.back.clipPolygons(o,n+1):[]:o=[],s.concat(o)}clipTo(e,n=0){this.polygons.length>0&&(this.polygons=e.clipPolygons(this.polygons,0)),n<se&&(this.front&&this.front.clipTo(e,n+1),this.back&&this.back.clipTo(e,n+1))}allPolygons(e=[]){for(let n=0;n<this.polygons.length;n++)e.push(this.polygons[n]);return this.front&&this.front.allPolygons(e),this.back&&this.back.allPolygons(e),e}build(e,n=0){if(!e.length)return;if(!this.hasPlane){let i=e[0];this.nx=i.nx,this.ny=i.ny,this.nz=i.nz,this.w=i.w,this.hasPlane=!0}if(n>=se)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${se})`);let s=[],o=[];for(let i=0;i<e.length;i++)Xe(this.nx,this.ny,this.nz,this.w,e[i],this.polygons,this.polygons,s,o);s.length>0&&(this.front||(this.front=new me),this.front.build(s,n+1)),o.length>0&&(this.back||(this.back=new me),this.back.build(o,n+1))}}function De(t,e){let n=t.attributes.position;if(!n||n.count===0)return[];let s=t.attributes.normal,o=t.attributes.uv,i=t.index?t.index.array:null,c=Math.floor(i?i.length/3:n.count/3);if(c>he)throw new RangeError(`SecurityError: CSG input triangle count (${c}) exceeds MAX_CSG_TRIANGLES (${he})`);let a=e?e.elements:null,u=a?a[0]*(a[5]*a[10]-a[9]*a[6])-a[4]*(a[1]*a[10]-a[9]*a[2])+a[8]*(a[1]*a[6]-a[5]*a[2])<0:!1,r=a?new ln().getNormalMatrix(e).elements:null,h=l=>{let f=n.getX(l),x=n.getY(l),b=n.getZ(l),p=s?s.getX(l):NaN,y=s?s.getY(l):NaN,g=s?s.getZ(l):NaN;if(a&&r){let T=a[0]*f+a[4]*x+a[8]*b+a[12],w=a[1]*f+a[5]*x+a[9]*b+a[13],E=a[2]*f+a[6]*x+a[10]*b+a[14];f=T,x=w,b=E;let k=r[0]*p+r[3]*y+r[6]*g,L=r[1]*p+r[4]*y+r[7]*g,z=r[2]*p+r[5]*y+r[8]*g,V=Math.hypot(k,L,z)||1;p=k/V,y=L/V,g=z/V}let S=o?o.getX(l):0,d=o?o.getY(l):0;return{x:f,y:x,z:b,nx:p,ny:y,nz:g,u:S,v:d}},m=[];for(let l=0;l<c;l++){let f=i?i[l*3]:l*3,x=i?i[l*3+1]:l*3+1,b=i?i[l*3+2]:l*3+2,p=dn(u?[h(f),h(b),h(x)]:[h(f),h(x),h(b)]);p&&m.push(p)}return m}function Sn(t){let e=[],n=[],s=[],o=[];for(let c of t){let a=c.vertices;if(a.length<3)continue;let u=e.length/3;for(let r of a)e.push(r.x,r.y,r.z),Number.isFinite(r.nx)&&r.nx*r.nx+r.ny*r.ny+r.nz*r.nz>.5?n.push(r.nx,r.ny,r.nz):n.push(c.nx,c.ny,c.nz),s.push(r.u,r.v);for(let r=1;r<a.length-1;r++)o.push(u,u+r,u+r+1)}let i=new te;return i.setAttribute("position",new D(new Float32Array(e),3)),i.setAttribute("normal",new D(new Float32Array(n),3)),i.setAttribute("uv",new D(new Float32Array(s),2)),i.setIndex(o),i}function Pn(t,e,n){if(t.length+e.length>he)throw new RangeError(`SecurityError: Combined CSG triangle count (${t.length+e.length}) exceeds MAX_CSG_TRIANGLES (${he})`);if(t.length===0)return n==="union"?e:[];if(e.length===0)return n==="intersect"?[]:t;let s=new me(t),o=new me(e);return n==="union"?(s.clipTo(o),o.clipTo(s),o.invert(),o.clipTo(s),o.invert(),s.build(o.allPolygons()),s.allPolygons()):n==="subtract"?(s.invert(),s.clipTo(o),o.clipTo(s),o.invert(),o.clipTo(s),o.invert(),s.build(o.allPolygons()),s.invert(),s.allPolygons()):(s.invert(),o.clipTo(s),o.invert(),s.clipTo(o),o.clipTo(s),s.build(o.allPolygons()),s.invert(),s.allPolygons())}function Be(t,e,n,s=null,o=null){let i=De(t,s),c=De(e,o);return Sn(Pn(i,c,n))}function ke(t,e,n){let s=t instanceof fe||!!t?.isMesh,o=e instanceof fe||!!e?.isMesh,i=s?t.geometry:t,c=o?e.geometry:e,a=null;if(o)if(e.updateMatrix(),s){t.updateMatrix();let m=new Pe().makeScale(1/(t.scale.x||1),1/(t.scale.y||1),1/(t.scale.z||1)),l=Math.hypot(t.quaternion.x,t.quaternion.y,t.quaternion.z,t.quaternion.w)||1,f=new Pe().compose(new le(0,0,0),new ee(-t.quaternion.x/l,-t.quaternion.y/l,-t.quaternion.z/l,t.quaternion.w/l),new le(1,1,1)),x=new Pe().makeTranslation(-t.position.x,-t.position.y,-t.position.z);a=m.multiply(f).multiply(x).multiply(e.matrix)}else a=e.matrix;let u=Be(i,c,n,null,a),r=s?t.material:new Le,h=new fe(u,r);return s&&(h.position.copy(t.position),h.quaternion.copy(t.quaternion),h.scale.copy(t.scale),h.name=t.name),h}let de={toGeometry:Be,subtract(t,e){return ke(t,e,"subtract")},union(t,e){return ke(t,e,"union")},intersect(t,e){return ke(t,e,"intersect")}},Oe={0:[[[.15,0],[.85,0],[.85,1],[.15,1],[.15,0]]],1:[[[.3,.8],[.5,1],[.5,0]],[[.2,0],[.8,0]]],2:[[[.15,.8],[.3,1],[.7,1],[.85,.8],[.85,.55],[.15,0],[.85,0]]],3:[[[.15,.85],[.3,1],[.75,1],[.85,.75],[.5,.5],[.85,.25],[.75,0],[.3,0],[.15,.15]]],4:[[[.7,0],[.7,1],[.15,.35],[.9,.35]]],5:[[[.85,1],[.2,1],[.15,.55],[.75,.55],[.85,.3],[.75,0],[.2,0]]],6:[[[.8,.9],[.5,1],[.15,.7],[.15,.15],[.5,0],[.85,.2],[.85,.45],[.5,.55],[.15,.45]]],7:[[[.15,1],[.85,1],[.35,0]]],8:[[[.2,.5],[.15,.75],[.3,1],[.7,1],[.85,.75],[.8,.5],[.2,.5],[.15,.2],[.3,0],[.7,0],[.85,.2],[.8,.5]]],9:[[[.85,.55],[.5,.45],[.15,.55],[.15,.85],[.5,1],[.85,.85],[.85,.2],[.5,0],[.2,.1]]],A:[[[.1,0],[.5,1],[.9,0]],[[.25,.35],[.75,.35]]],B:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.7,.5],[.85,.25],[.7,0],[.15,0]]],C:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.65,0],[.85,.2]]],D:[[[.15,0],[.15,1],[.65,1],[.85,.75],[.85,.25],[.65,0],[.15,0]]],E:[[[.85,1],[.15,1],[.15,0],[.85,0]],[[.15,.5],[.7,.5]]],F:[[[.85,1],[.15,1],[.15,0]],[[.15,.5],[.7,.5]]],G:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.85,0],[.85,.45],[.55,.45]]],H:[[[.15,0],[.15,1]],[[.85,0],[.85,1]],[[.15,.5],[.85,.5]]],I:[[[.25,1],[.75,1]],[[.5,1],[.5,0]],[[.25,0],[.75,0]]],J:[[[.8,1],[.8,.25],[.6,0],[.3,0],[.15,.25]]],K:[[[.15,0],[.15,1]],[[.85,1],[.15,.45],[.85,0]]],L:[[[.15,1],[.15,0],[.85,0]]],M:[[[.1,0],[.1,1],[.5,.35],[.9,1],[.9,0]]],N:[[[.15,0],[.15,1],[.85,0],[.85,1]]],O:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]]],P:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]]],Q:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]],[[.55,.3],[.9,-.05]]],R:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.55,.5],[.85,0]]],S:[[[.85,.85],[.65,1],[.3,1],[.15,.75],[.85,.25],[.7,0],[.3,0],[.15,.15]]],T:[[[.1,1],[.9,1]],[[.5,1],[.5,0]]],U:[[[.15,1],[.15,.25],[.35,0],[.65,0],[.85,.25],[.85,1]]],V:[[[.1,1],[.5,0],[.9,1]]],W:[[[.05,1],[.25,0],[.5,.65],[.75,0],[.95,1]]],X:[[[.15,1],[.85,0]],[[.85,1],[.15,0]]],Y:[[[.15,1],[.5,.5],[.85,1]],[[.5,.5],[.5,0]]],Z:[[[.15,1],[.85,1],[.15,0],[.85,0]]],".":[[[.45,0],[.55,0],[.55,.12],[.45,.12],[.45,0]]],",":[[[.5,.15],[.4,-.1]]],":":[[[.45,.1],[.55,.1]],[[.45,.7],[.55,.7]]],"-":[[[.2,.5],[.8,.5]]],"+":[[[.2,.5],[.8,.5]],[[.5,.2],[.5,.8]]],"=":[[[.2,.35],[.8,.35]],[[.2,.65],[.8,.65]]],"/":[[[.2,0],[.8,1]]],"!":[[[.5,1],[.5,.28]],[[.5,.1],[.5,0]]],"?":[[[.2,.8],[.35,1],[.7,1],[.85,.75],[.5,.45],[.5,.28]],[[.5,.1],[.5,0]]],"(":[[[.65,1],[.35,.65],[.35,.35],[.65,0]]],")":[[[.35,1],[.65,.65],[.65,.35],[.35,0]]],"%":[[[.2,0],[.8,1]],[[.2,.8],[.35,.8],[.35,.95],[.2,.95],[.2,.8]],[[.65,.05],[.8,.05],[.8,.2],[.65,.2],[.65,.05]]],"#":[[[.32,0],[.32,1]],[[.68,0],[.68,1]],[[.12,.35],[.88,.35]],[[.12,.65],[.88,.65]]],$:[[[.8,.8],[.6,.92],[.3,.92],[.18,.72],[.82,.28],[.7,.08],[.4,.08],[.2,.2]],[[.5,1],[.5,0]]],_:[[[.1,0],[.9,0]]],"[":[[[.65,1],[.3,1],[.3,0],[.65,0]]],"]":[[[.35,1],[.7,1],[.7,0],[.35,0]]],"<":[[[.75,.85],[.25,.5],[.75,.15]]],">":[[[.25,.85],[.75,.5],[.25,.15]]],"*":[[[.5,.2],[.5,.8]],[[.2,.35],[.8,.65]],[[.2,.65],[.8,.35]]],"\\":[[[.2,1],[.8,0]]]};class Fe extends te{constructor(e="",n={}){super();let s=String(e??"").slice(0,Ee),o=Math.max(.005,Math.min(100,O(n.size,.2))),i=!!(n.bevelEnabled??!1),c=i?Math.max(0,Math.min(2,O(n.bevelThickness,o*.04))):0,a=i?Math.max(0,Math.min(2,O(n.bevelSize,o*.03))):0,u=Math.max(.001,Math.min(20,O(n.depth??n.height,o*.2)))+c*2,r=o*.085+a,h=o*.68,m=o*.82,l=[],f=[],x=[],b=[],p=(S,d,T,w,E,k,L)=>{let z=T-S,V=w-d,B=Math.hypot(z,V),I=1,F=0;B>1e-6&&(I=z/B,F=V/B);let oe=-F*E,re=I*E,W=I*E*.6,j=F*E*.6,N=S-W+oe,Y=d-j+re,v=S-W-oe,M=d-j-re,G=T+W-oe,R=w+j-re,A=T+W+oe,X=w+j+re,H=($,U,Q,Z,K,J,ne)=>{let q=l.length/3;l.push($[0],$[1],$[2],U[0],U[1],U[2],Q[0],Q[1],Q[2],Z[0],Z[1],Z[2]),f.push(K,J,ne,K,J,ne,K,J,ne,K,J,ne),x.push(0,0,1,0,1,1,0,1),b.push(q,q+1,q+2,q,q+2,q+3)};H([N,Y,L],[v,M,L],[G,R,L],[A,X,L],0,0,1),H([v,M,k],[N,Y,k],[A,X,k],[G,R,k],0,0,-1),H([N,Y,k],[v,M,k],[v,M,L],[N,Y,L],-I,-F,0),H([G,R,k],[A,X,k],[A,X,L],[G,R,L],I,F,0),H([v,M,k],[G,R,k],[G,R,L],[v,M,L],F,-I,0),H([A,X,k],[N,Y,k],[N,Y,L],[A,X,L],-F,I,0)},y=0,g=0;for(let S=0;S<s.length;S++){let d=s[S];if(d===`
|
|
18
|
+
`){y=0,g-=o*1.35;continue}if(d===" "||d===" "){y+=m*(d===" "?.75:3);continue}if(d==="\r")continue;let T=d.toUpperCase(),w=d!==T&&d>="a"&&d<="z",E=Oe[T]??Oe["?"],k=w?o*.76:o,L=w?h*.88:h;for(let z of E)for(let V=0;V<z.length-1;V++){let B=z[V],I=z[V+1];p(y+B[0]*L,g+B[1]*k,y+I[0]*L,g+I[1]*k,r,-u*.5,u*.5)}y+=w?m*.88:m}this.setAttribute("position",new D(new Float32Array(l),3)),this.setAttribute("normal",new D(new Float32Array(f),3)),this.setAttribute("uv",new D(new Float32Array(x),2)),this.setIndex(b),n.center!==!1?this.center():this.computeBoundingBox()}}function Ye(t){if(!t)return;let e=t,n=t.userData?.xr?.text;if(n!=null&&n!==!1){let o=e.geometry?.attributes?.position;if((!o||o.count===0)&&t.userData._textApplied!==!0){let i="",c=.08,a=.015,u;if(typeof n=="string"||typeof n=="number")i=String(n);else if(typeof n=="object"){let r=n;i=String(r.text??r.value??""),r.size!==void 0&&(c=Number(r.size)||.08),(r.depth!==void 0||r.height!==void 0)&&(a=Number(r.depth??r.height)||c*.2),(typeof r.color=="string"||typeof r.color=="number")&&(u=r.color)}i.trim().length>0&&(e.geometry=new Fe(i,{size:c,depth:a}),t.userData._textApplied=!0,e.material instanceof mn?u!==void 0&&t.userData._autoTextColorApplied!==!0&&(e.material.color=new hn(u),t.userData._autoTextColorApplied=!0):e.material=new Le({color:u??16317180}))}}let s=t.userData?.csg;if(s&&typeof s=="object"&&t.userData._csgApplied!==!0&&e.geometry instanceof te&&e.geometry.attributes.position?.count>0){t.userData._csgApplied=!0;let o=Array.isArray(s)?s:[s],i=e.geometry;for(let c of o){if(!c||typeof c!="object")continue;let a=c,u=String(a.op??a.operation??"subtract"),r=u==="union"||u==="intersect"?u:"subtract",h=a.target??a.mesh??a.geometry;if(h instanceof fe||h instanceof te)try{let m=r==="union"?de.union(e,h):r==="intersect"?de.intersect(e,h):de.subtract(e,h);e.geometry!==i&&e.geometry.dispose?.(),e.geometry=m.geometry}catch(m){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",m)}}}}let He={Path:xe,Shape:be,ShapeGeometry:fn,ExtrudeGeometry:bn,TextGeometry:Fe,CSG:de,MAX_CSG_TRIANGLES:he,MAX_BSP_DEPTH:se,MAX_TEXT_GEOMETRY_CHARS:Ee,MAX_SHAPE_POINTS:we,materializeDeclarativeGeometry:Ye};return C&&typeof C=="object"&&(C.authorNamespace||(C.authorNamespace={}),Object.assign(C.authorNamespace,He),C.materializeDeclarativeGeometry=Ye),He}var Te={name:"cad",onRegister(){sn(Se);let P=ye(),C=P.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);C&&Se(C,P)}};on(Te);
|