three-live 1.2.0 → 1.2.2
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 +182 -6
- package/dist/three-author-engine.js +66 -41
- package/dist/three-author.cjs +63 -39
- package/dist/three-author.d.ts +182 -6
- package/dist/three-author.js +63 -39
- package/dist/three-convert.cjs +61 -37
- package/dist/three-convert.d.ts +182 -6
- package/dist/three-convert.js +61 -37
- package/dist/three-live-animation.cjs +7 -7
- package/dist/three-live-animation.d.ts +182 -6
- 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} +182 -6
- package/dist/three-live-cad.js +18 -0
- package/dist/three-live-cad.min.js +18 -0
- package/dist/three-live-element.cjs +29 -5
- package/dist/three-live-element.d.ts +182 -6
- package/dist/three-live-element.js +29 -5
- package/dist/three-live-full.cjs +159 -56
- package/dist/three-live-full.js +159 -56
- package/dist/three-live-full.min.js +159 -56
- package/dist/three-live-studio.cjs +120 -0
- package/dist/three-live-studio.d.ts +509 -0
- package/dist/three-live-studio.js +120 -0
- package/dist/three-live-studio.min.js +120 -0
- package/dist/three-live-viewer.cjs +29 -5
- package/dist/three-live-viewer.d.ts +182 -6
- package/dist/three-live-viewer.js +29 -5
- package/dist/three-live-viewer.min.js +29 -5
- package/dist/three-live.cjs +66 -42
- package/dist/three-live.js +66 -42
- package/dist/three-live.min.js +66 -42
- package/dist/three-view.cjs +29 -5
- package/dist/three-view.d.ts +182 -6
- package/dist/three-view.js +29 -5
- package/dist/three-xr.cjs +65 -41
- package/dist/three-xr.d.ts +182 -6
- package/dist/three-xr.js +65 -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 ne=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Pe=Object.prototype.hasOwnProperty;var Ce=(e,t)=>{for(var n in t)ne(e,n,{get:t[n],enumerable:!0})},Ke=(e,t,n,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Be(t))!Pe.call(e,o)&&o!==n&&ne(e,o,{get:()=>t[o],enumerable:!(u=Le(t,o))||u.enumerable});return e};var Ne=e=>Ke(ne({},"__esModule",{value:!0}),e);var Ue={};Ce(Ue,{IKSolver:()=>we,crossFadeTo:()=>fe,ikPlugin:()=>ce,keyframeAnimationPlugin:()=>he,morphPlugin:()=>de,parseAnimations:()=>me,quatFromUnitVectors:()=>ve,sampleChannel:()=>N,setMorphTargetWeight:()=>Ee,skinningPlugin:()=>be,solveFABRIK:()=>ae,solveTwoBoneIK:()=>se});module.exports=Ne(Ue);var H="__THREE_LIVE_REGISTRY__";function G(){let e=typeof globalThis<"u"?globalThis:{};if(!e[H]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,H,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[H]=t}}return e[H]}var je=G().plugins;function Re(e){let t=G();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function z(e){let t=G().plugins;t.some(n=>n.name===e.name)||t.push(e),e.onRegister?.()}function oe(e,t){function n(r,a,c,m){let l=typeof r=="number"?r:Number(r);return Number.isFinite(l)?Math.max(a,Math.min(c,l)):m}function u(r,a){let m=r[0]*a[0]+r[1]*a[1]+r[2]*a[2]+1;if(m<1e-6){if(Math.abs(r[0])>Math.abs(r[2])){let p=Math.hypot(r[1],r[0])||1;return[-r[1]/p,r[0]/p,0,0]}let s=Math.hypot(r[2],r[1])||1;return[0,-r[2]/s,r[1]/s,0]}let l=r[1]*a[2]-r[2]*a[1],i=r[2]*a[0]-r[0]*a[2],d=r[0]*a[1]-r[1]*a[0],A=Math.hypot(l,i,d,m)||1;return[l/A,i/A,d/A,m/A]}function o(r,a,c,m,l){let i=a[0]-r[0],d=a[1]-r[1],A=a[2]-r[2],s=Math.hypot(i,d,A),p=c[0]-a[0],h=c[1]-a[1],x=c[2]-a[2],b=Math.hypot(p,h,x);if(s<1e-6||b<1e-6)return{rootPos:[r[0],r[1],r[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 v=[i/s,d/s,A/s],w=[p/b,h/b,x/b],L=m[0]-r[0],P=m[1]-r[1],O=m[2]-r[2],M=Math.hypot(L,P,O),R=M>1e-6?[L/M,P/M,O/M]:v,S=Math.abs(s-b)+1e-5,T=Math.max(S,s+b-1e-5),I=Math.max(S,Math.min(T,M>1e-6?M:S)),V=n((s*s+I*I-b*b)/(2*s*I),-1,1,1),_=Math.sqrt(Math.max(0,1-V*V)),B=l?l[0]-r[0]:i,E=l?l[1]-r[1]:d,F=l?l[2]-r[2]:A,Y=B*R[0]+E*R[1]+F*R[2],D=B-R[0]*Y,j=E-R[1]*Y,X=F-R[2]*Y,W=Math.hypot(D,j,X);if(W<=1e-6){let xe=Math.abs(R[1])<.99?0:1,Te=Math.abs(R[1])<.99?1:0,Me=0;D=R[1]*Me-R[2]*Te,j=R[2]*xe-R[0]*Me,X=R[0]*Te-R[1]*xe,W=Math.hypot(D,j,X)||1}let Z=[D/W,j/W,X/W],k=[r[0]+R[0]*(s*V)+Z[0]*(s*_),r[1]+R[1]*(s*V)+Z[1]*(s*_),r[2]+R[2]*(s*V)+Z[2]*(s*_)],ee=[r[0]+R[0]*I,r[1]+R[1]*I,r[2]+R[2]*I],ye=ee[0]-k[0],ge=ee[1]-k[1],Ae=ee[2]-k[2],J=Math.hypot(ye,ge,Ae),q=J>1e-6?[ye/J,ge/J,Ae/J]:R,ke=[k[0]+q[0]*b,k[1]+q[1]*b,k[2]+q[2]*b],_e=[(k[0]-r[0])/s,(k[1]-r[1])/s,(k[2]-r[2])/s];return{rootPos:[r[0],r[1],r[2]],midPos:k,effectorPos:ke,rootRotation:u(v,_e),midRotation:u(w,q)}}function f(r,a,c=8,m=.001){let l=r.length;if(l<2)return{positions:r.map(M=>[M[0],M[1],M[2]]),rotations:[],iterations:0};let i=r.map(M=>[M[0],M[1],M[2]]),d=[],A=[],s=0;for(let M=0;M<l-1;M++){let R=i[M+1][0]-i[M][0],S=i[M+1][1]-i[M][1],T=i[M+1][2]-i[M][2],I=Math.hypot(R,S,T);d.push(I),s+=I,A.push(I>1e-6?[R/I,S/I,T/I]:[0,1,0])}let p=[i[0][0],i[0][1],i[0][2]],h=Math.round(n(c,1,32,8)),x=n(m,1e-5,.1,.001),b=a[0]-p[0],v=a[1]-p[1],w=a[2]-p[2],L=Math.hypot(b,v,w),P=0;if(L>=s&&s>1e-6){let M=L>1e-6?[b/L,v/L,w/L]:A[0];i[0]=[p[0],p[1],p[2]];for(let R=0;R<l-1;R++){let S=d[R];i[R+1]=[i[R][0]+M[0]*S,i[R][1]+M[1]*S,i[R][2]+M[2]*S]}P=1}else for(let M=1;M<=h;M++){let R=i[l-1];if(Math.hypot(R[0]-a[0],R[1]-a[1],R[2]-a[2])<=x)break;P=M,i[l-1]=[a[0],a[1],a[2]];for(let T=l-2;T>=0;T--){let I=i[T][0]-i[T+1][0],V=i[T][1]-i[T+1][1],_=i[T][2]-i[T+1][2],B=Math.hypot(I,V,_),E=d[T];if(B>1e-6){let F=E/B;i[T]=[i[T+1][0]+I*F,i[T+1][1]+V*F,i[T+1][2]+_*F]}else{let F=A[T];i[T]=[i[T+1][0]-F[0]*E,i[T+1][1]-F[1]*E,i[T+1][2]-F[2]*E]}}i[0]=[p[0],p[1],p[2]];for(let T=0;T<l-1;T++){let I=i[T+1][0]-i[T][0],V=i[T+1][1]-i[T][1],_=i[T+1][2]-i[T][2],B=Math.hypot(I,V,_),E=d[T];if(B>1e-6){let F=E/B;i[T+1]=[i[T][0]+I*F,i[T][1]+V*F,i[T][2]+_*F]}else{let F=A[T];i[T+1]=[i[T][0]+F[0]*E,i[T][1]+F[1]*E,i[T][2]+F[2]*E]}}}let O=[];for(let M=0;M<l-1;M++){let R=i[M+1][0]-i[M][0],S=i[M+1][1]-i[M][1],T=i[M+1][2]-i[M][2],I=Math.hypot(R,S,T),V=I>1e-6?[R/I,S/I,T/I]:A[M];O.push(u(A[M],V))}return{positions:i,rotations:O,iterations:P}}function g(r){if(!r||typeof r!="object"||Array.isArray(r))return null;let a=r;if(a.enabled===!1)return null;let c=b=>{if(typeof b!="string")return;let v=b.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(v)?v:void 0},m=b=>Array.isArray(b)&&b.length===3&&typeof b[0]=="number"&&Number.isFinite(b[0])&&typeof b[1]=="number"&&Number.isFinite(b[1])&&typeof b[2]=="number"&&Number.isFinite(b[2]),l=c(a.root),i=c(a.effector);if(!l||!i)return null;let d=c(a.mid),A=a.target,s;if(m(A))s=[n(A[0],-1e3,1e3,0),n(A[1],-1e3,1e3,0),n(A[2],-1e3,1e3,0)];else{let b=c(A);if(!b)return null;s=b}let p=a.pole,h=m(p)?[n(p[0],-1e3,1e3,0),n(p[1],-1e3,1e3,0),n(p[2],-1e3,1e3,0)]:void 0,x=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||d?"two-bone":"fabrik";return{root:l,...d?{mid:d}:{},effector:i,target:s,...h?{pole:h}:{},solver:x,iterations:Math.round(n(a.iterations,1,32,8)),tolerance:n(a.tolerance,1e-5,.1,.001),weight:n(a.weight,0,1,1)}}let y=Object.freeze({solveTwoBone:o,solveFABRIK:f,parseIKTrait:g});return t&&typeof t=="object"&&(t.authorNamespace=t.authorNamespace||{},t.authorNamespace.IKSolver=y),{clampNum:n,parseIKTrait:g,quatFromUnitVectors:u,solveTwoBoneIK:o,solveFABRIK:f,IKSolver:y}}var C=oe(),Oe=C.clampNum,We=C.parseIKTrait,ve=C.quatFromUnitVectors,se=C.solveTwoBoneIK,ae=C.solveFABRIK,we=C.IKSolver;function ie(e){let t=e?.transform??e?.modelMatrix;return t&&t.length>=16?[t[12]||0,t[13]||0,t[14]||0]:[0,0,0]}function te(e,t){let n=e?.transform??e?.modelMatrix;!n||n.length<16||(n[12]=t[0],n[13]=t[1],n[14]=t[2])}function re(e,t,n,u,o){let f=Oe(o,0,1,1),g=t[0]+(n[0]-t[0])*f,y=t[1]+(n[1]-t[1])*f,r=t[2]+(n[2]-t[2])*f,a=g-e[0],c=y-e[1],m=r-e[2],l=Math.hypot(a,c,m);if(l>1e-6&&u>1e-6){let i=u/l;return[e[0]+a*i,e[1]+c*i,e[2]+m*i]}return[g,y,r]}function Ge(e,t,n){if(Array.isArray(e))return[e[0],e[1],e[2]];let u=t.get(e);if(u)return ie(u);if(e==="head"){let o=n?.headPose?.position??n?.headPose??n?.cameraPosition;if(Array.isArray(o)&&o.length>=3)return[o[0],o[1],o[2]]}else if(e==="hand-left"){let o=n?.handPoses?.left?.position??n?.handPoses?.left??n?.hands?.left?.position??n?.hands?.left;if(Array.isArray(o)&&o.length>=3)return[o[0],o[1],o[2]]}else if(e==="hand-right"){let o=n?.handPoses?.right?.position??n?.handPoses?.right??n?.hands?.right?.position??n?.hands?.right;if(Array.isArray(o)&&o.length>=3)return[o[0],o[1],o[2]]}return null}var ce={name:"ik",onRegister(){let e=G();Re(oe),oe(e.threeNamespace,e)},onUpdate(e){let t=e?.meshes;if(!Array.isArray(t)||t.length===0)return;let n=null;for(let u of t){let o=u?.userData?.xr?.ik??u?.extras?.xr?.ik??u?.extensions?.ANDROID_xr_scenecore?.ik;if(!o)continue;let f=We(o);if(!f||f.weight<=0)continue;if(!n){n=new Map;for(let s of t)s&&typeof s.name=="string"&&s.name&&n.set(s.name,s)}let g=n.get(f.root),y=n.get(f.effector);if(!g||!y)continue;let r=Ge(f.target,n,e);if(!r)continue;let a=f.mid?n.get(f.mid):void 0,c=a?[g,a,y]:[g,y],m=c.map(s=>s.name||"").join(">");if(!u.__ikRestOffsets||u.__ikRestKey!==m){let s=c.map(ie),p=[];for(let h=0;h<s.length-1;h++)p.push([s[h+1][0]-s[h][0],s[h+1][1]-s[h][1],s[h+1][2]-s[h][2]]);u.__ikRestOffsets=p,u.__ikRestKey=m}let l=u.__ikRestOffsets,d=[ie(g)],A=[];for(let s=0;s<l.length;s++){let p=d[s],h=l[s];d.push([p[0]+h[0],p[1]+h[1],p[2]+h[2]]),A.push(Math.hypot(h[0],h[1],h[2]))}if(f.solver==="two-bone"&&a&&d.length===3){let s=se(d[0],d[1],d[2],r,f.pole),p=re(d[0],d[1],s.midPos,A[0],f.weight),h=[p[0]+l[1][0],p[1]+l[1][1],p[2]+l[1][2]],x=[p[0]+(s.effectorPos[0]-s.midPos[0]),p[1]+(s.effectorPos[1]-s.midPos[1]),p[2]+(s.effectorPos[2]-s.midPos[2])],b=re(p,h,x,A[1],f.weight);te(a,p),te(y,b)}else{let s=ae(d,r,f.iterations,f.tolerance),p=d[0];for(let h=1;h<c.length;h++){let x=l[h-1],b=[p[0]+x[0],p[1]+x[1],p[2]+x[2]],v=[p[0]+(s.positions[h][0]-s.positions[h-1][0]),p[1]+(s.positions[h][1]-s.positions[h-1][1]),p[2]+(s.positions[h][2]-s.positions[h-1][2])],w=re(p,b,v,A[h-1],f.weight);te(c[h],w),p=w}}}}};function K(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function ze(e,t,n){let u=t[0],o=t[1],f=t[2],g=t[3],y=t[4],r=t[5],a=t[6],c=t[7],m=t[8],l=t[9],i=t[10],d=t[11],A=t[12],s=t[13],p=t[14],h=t[15],x=n[0],b=n[1],v=n[2],w=n[3];return e[0]=x*u+b*y+v*m+w*A,e[1]=x*o+b*r+v*l+w*s,e[2]=x*f+b*a+v*i+w*p,e[3]=x*g+b*c+v*d+w*h,x=n[4],b=n[5],v=n[6],w=n[7],e[4]=x*u+b*y+v*m+w*A,e[5]=x*o+b*r+v*l+w*s,e[6]=x*f+b*a+v*i+w*p,e[7]=x*g+b*c+v*d+w*h,x=n[8],b=n[9],v=n[10],w=n[11],e[8]=x*u+b*y+v*m+w*A,e[9]=x*o+b*r+v*l+w*s,e[10]=x*f+b*a+v*i+w*p,e[11]=x*g+b*c+v*d+w*h,x=n[12],b=n[13],v=n[14],w=n[15],e[12]=x*u+b*y+v*m+w*A,e[13]=x*o+b*r+v*l+w*s,e[14]=x*f+b*a+v*i+w*p,e[15]=x*g+b*c+v*d+w*h,e}function ue(e,t,n,u){let o=t[0],f=t[1],g=t[2],y=t[3],r=o+o,a=f+f,c=g+g,m=o*r,l=o*a,i=o*c,d=f*a,A=f*c,s=g*c,p=y*r,h=y*a,x=y*c,b=u[0],v=u[1],w=u[2];return e[0]=(1-(d+s))*b,e[1]=(l+x)*b,e[2]=(i-h)*b,e[3]=0,e[4]=(l-x)*v,e[5]=(1-(m+s))*v,e[6]=(A+p)*v,e[7]=0,e[8]=(i+h)*w,e[9]=(A-p)*w,e[10]=(1-(m+d))*w,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function Ie(e,t){let n=t[0],u=t[1],o=t[2],f=t[4],g=t[5],y=t[6],r=t[8],a=t[9],c=t[10],m=c*g-y*a,l=-c*f+y*r,i=a*f-g*r,d=n*m+u*l+o*i;return d&&(d=1/d,e[0]=m*d,e[1]=l*d,e[2]=i*d,e[3]=(-c*u+o*a)*d,e[4]=(c*n-o*r)*d,e[5]=(-a*n+u*r)*d,e[6]=(y*u-o*g)*d,e[7]=(-y*n+o*f)*d,e[8]=(g*n-u*f)*d),e}function Fe(e,t){let n=Array.isArray(e?.nodes)?e.nodes.length:0,u=[];for(let c=0;c<n;c++)u.push(K());if(n===0)return u;let o=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let m of c.children)o.add(m);let f=new Set,g=128,y=(c,m,l=0)=>{if(l>g||c<0||c>=n||f.has(c))return;f.add(c);let i=e.nodes[c];if(!i)return;let d=K();if(t&&t[c])d.set(t[c]);else if(i.matrix&&i.matrix.length===16)d.set(i.matrix);else{let s=i.translation||[0,0,0],p=i.rotation||[0,0,0,1],h=i.scale||[1,1,1];ue(d,p,s,h)}let A=u[c];if(m?ze(A,m,d):A.set(d),Array.isArray(i.children))for(let s of i.children)typeof s=="number"&&y(s,A,l+1)},r=[],a=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(a&&Array.isArray(a.nodes))r.push(...a.nodes);else for(let c=0;c<n;c++)o.has(c)||r.push(c);for(let c of r)y(c,null);for(let c=0;c<n;c++)!o.has(c)&&!r.includes(c)&&y(c,null);return u}function $(e,t,n){return t%4===0?new Float32Array(e,t,n):new Float32Array(e.slice(t,t+n*4))}function Ve(e,t,n,u){let o=t[0],f=t[1],g=t[2],y=t[3],r=n[0],a=n[1],c=n[2],m=n[3],l=o*r+f*a+g*c+y*m;if(l<0&&(r=-r,a=-a,c=-c,m=-m,l=-l),Math.abs(l)>=1)return e[0]=o,e[1]=f,e[2]=g,e[3]=y,e;let i=Math.acos(l),d=Math.sqrt(1-l*l);if(Math.abs(d)<.001)return e[0]=.5*(o+r),e[1]=.5*(f+a),e[2]=.5*(g+c),e[3]=.5*(y+m),e;let A=Math.sin((1-u)*i)/d,s=Math.sin(u*i)/d;return e[0]=o*A+r*s,e[1]=f*A+a*s,e[2]=g*A+c*s,e[3]=y*A+m*s,e}function Se(e,t,n,u){return e[0]=t[0]+u*(n[0]-t[0]),e[1]=t[1]+u*(n[1]-t[1]),e[2]=t[2]+u*(n[2]-t[2]),e}function me(e,t){if(!Array.isArray(e?.animations))return[];let n=[];for(let u=0;u<e.animations.length;u++){let o=e.animations[u],f=o.name||`Animation_${u}`,g=[],y=0;if(Array.isArray(o.channels)&&Array.isArray(o.samplers))for(let r of o.channels){if(!r.target||r.target.node===void 0||!r.target.path)continue;let a=o.samplers[r.sampler];if(!a)continue;let c=e.accessors?.[a.input],m=e.accessors?.[a.output];if(!c||!m)continue;let l=e.bufferViews?.[c.bufferView],i=e.bufferViews?.[m.bufferView];if(!l||!i)continue;let d=(l.byteOffset||0)+(c.byteOffset||0),A=(i.byteOffset||0)+(m.byteOffset||0),s=$(t,d,c.count);s.length>0&&s[s.length-1]>y&&(y=s[s.length-1]);let p=r.target.path==="rotation"?4:r.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,c.count))):3,h=$(t,A,m.count*(r.target.path==="weights"?1:p)),x=a.interpolation==="STEP"?"STEP":"LINEAR";g.push({nodeIndex:r.target.node,path:r.target.path,times:s,values:h,interpolation:x})}g.length>0&&n.push({name:f,duration:y,channels:g})}return n}function N(e,t,n){let{times:u,values:o,path:f,interpolation:g}=e,y=u.length;if(y===0)return;let r=f==="rotation"?4:f==="weights"?Math.max(1,Math.round(o.length/y)):3;if(t<=u[0]){for(let h=0;h<r;h++)n[h]=o[h];return}if(t>=u[y-1]){let h=(y-1)*r;for(let x=0;x<r;x++)n[x]=o[h+x];return}let a=0,c=y-1;for(;a<=c;){let h=a+c>>1;u[h]<=t?a=h+1:c=h-1}let m=Math.max(0,c),l=Math.min(y-1,m+1);if(g==="STEP"||m===l){let h=m*r;for(let x=0;x<r;x++)n[x]=o[h+x];return}let i=u[m],d=u[l],A=(t-i)/Math.max(1e-5,d-i),s=m*r,p=l*r;if(f==="rotation"){let h=[o[s],o[s+1],o[s+2],o[s+3]],x=[o[p],o[p+1],o[p+2],o[p+3]];Ve(n,h,x,A)}else for(let h=0;h<r;h++)n[h]=o[s+h]+A*(o[p+h]-o[s+h])}var Q=new WeakMap;function fe(e,t,n=.3){if(!e?.animations)return;let u=e.animations.find(y=>y.name===t);if(!u)return;let o=Q.get(e);o||(o=[],e.currentClip&&o.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),Q.set(e,o));let f=n>0?1/n:1e3;for(let y of o)y.clip.name!==t&&(y.fadeSpeed=-f);let g=o.find(y=>y.clip.name===t);g?g.fadeSpeed=f:o.push({clip:u,time:0,weight:n>0?0:1,fadeSpeed:f}),e.currentClip=u,e.isPlayingAnimation=!0}function le(e,t){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let n=Q.get(e);if(!n||n.length===0){if(!e.currentClip)return;n=[{clip:e.currentClip,time:t,weight:1,fadeSpeed:0}]}let u=e.gltf.nodes.length,o=[];for(let m=0;m<u;m++){let l=e.initialNodeTransforms[m];l?o.push({t:[l.t[0],l.t[1],l.t[2]],r:[l.r[0],l.r[1],l.r[2],l.r[3]],s:[l.s[0],l.s[1],l.s[2]]}):o.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let f=[0,0,0],g=[0,0,0,1],y=[1,1,1],r=new Float32Array(64);for(let m of n){let l=Math.max(0,Math.min(1,m.weight));if(!(l<=1e-4))for(let i of m.clip.channels){if(i.nodeIndex<0||i.nodeIndex>=u)continue;let d=o[i.nodeIndex];if(i.path==="translation")N(i,m.time,f),Se(d.t,d.t,f,l);else if(i.path==="rotation")N(i,m.time,g),Ve(d.r,d.r,g,l);else if(i.path==="scale")N(i,m.time,y),Se(d.s,d.s,y,l);else if(i.path==="weights"&&(N(i,m.time,r),e.meshes)){for(let A of e.meshes)if(A.nodeIndex===i.nodeIndex){for(let s of A.primitives)if(s.pluginData?.morph?.weights){let p=s.pluginData.morph.weights,h=s.pluginData.morph.numTargets||p.length;for(let x=0;x<h;x++)p[x]=p[x]*(1-l)+r[x]*l}}}}}let a=[];for(let m=0;m<u;m++){let l=K(),{t:i,r:d,s:A}=o[m];ue(l,d,i,A),a.push(l)}let c=Fe(e.gltf,a);e.worldMatrices=c;for(let m of e.meshes)m.nodeIndex>=0&&m.nodeIndex<c.length&&(m.transform.set(c[m.nodeIndex]),Ie(m.normalMatrix,m.transform))}var he={name:"keyframes",evaluateAnimation:le,crossFadeTo:fe,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=me(e.gltf,e.bin))},onUpdate(e,t){if(!e.isPlayingAnimation)return;let n=Q.get(e);if(n&&n.length>0){for(let u=n.length-1;u>=0;u--){let o=n[u];if(o.time+=t,o.clip.duration>0&&(o.time%=o.clip.duration),o.fadeSpeed!==0)if(o.weight+=o.fadeSpeed*t,o.weight<=0){n.splice(u,1);continue}else o.weight>=1&&(o.weight=1,o.fadeSpeed=0)}n.length>0&&(e.animationTime=n[n.length-1].time),le(e,e.animationTime)}else e.currentClip&&(e.animationTime+=t,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),le(e,e.animationTime))}};var U=64;function Ee(e,t,n){if(!(!e?.meshes||t<0||t>=U))for(let u of e.meshes)for(let o of u.primitives){let f=o.pluginData?.morph;f?.weights&&(f.weights[t]=n)}}var de={name:"morph",onResolveShader(e,t,n,u){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let o=n.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[${U}];
|
|
20
|
+
uniform int uNumMorphTargets;`);return o=o.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
|
|
21
|
+
for (int m = 0; m < ${U}; 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:o,fs:u}},onBuildPrimitiveVAO(e,t,n,u,o){let f=n?.targets;if(!Array.isArray(f)||f.length===0)return null;let g=n.attributes?.POSITION,y=u?.accessors?.[g];if(!y)return null;let r=y.count,a=Math.min(f.length,U),c=new Float32Array(r*a*4);for(let i=0;i<a;i++){let d=f[i].POSITION;if(d===void 0)continue;let A=u.accessors?.[d],s=u.bufferViews?.[A?.bufferView];if(!A||!s)continue;let p=(s.byteOffset||0)+(A.byteOffset||0),h=$(o,p,r*3),x=i*r*4;for(let b=0;b<r;b++)c[x+b*4]=h[b*3],c[x+b*4+1]=h[b*3+1],c[x+b*4+2]=h[b*3+2],c[x+b*4+3]=0}let m=e.createTexture();e.bindTexture(3553,m),e.texImage2D(3553,0,34836,r,a,0,6408,5126,c),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let l=new Float32Array(U);return{hasMorph:!0,morphTex:m,numTargets:a,vertexCount:r,weights:l}},onBeforeDrawPrimitive(e,t,n,u,o,f){let g=n.pluginData?.morph;if(!g?.hasMorph||!g.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,g.morphTex);let y=e.getUniformLocation(t,"uMorphDeltasTex");y&&e.uniform1i(y,5);let r=e.getUniformLocation(t,"uNumMorphTargets");r&&e.uniform1i(r,g.numTargets);let a=e.getUniformLocation(t,"uMorphWeights[0]");a&&e.uniform1fv(a,g.weights)}};var pe=64,be={name:"skinning",onResolveShader(e,t,n,u){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let o=n.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[${pe}];`),f=o.includes("morphedPos")?"morphedPos":"aPosition";return o=o.replace(`vec4 world=uModel*vec4(${f},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(${f},1.0));`).replace(`gl_Position=uMVP*vec4(${f},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${f},1.0));`),{vs:o,fs:u}},onBuildPrimitiveVAO(e,t,n,u,o){let f=n?.attributes;if(!f||f.JOINTS_0===void 0||f.WEIGHTS_0===void 0)return null;let g=u.accessors[f.JOINTS_0],y=u.accessors[f.WEIGHTS_0];if(!g||!y)return null;let r=u.bufferViews[g.bufferView],a=u.bufferViews[y.bufferView];if(!r||!a)return null;let c=(r.byteOffset||0)+(g.byteOffset||0),m=(a.byteOffset||0)+(y.byteOffset||0),l=e.createBuffer();e.bindBuffer(34962,l);let i=g.componentType===5121?5121:5123,d=i===5121?new Uint8Array(o,c,g.count*4):new Uint16Array(o,c,g.count*4);e.bufferData(34962,d,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,i,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let s=new Float32Array(o,m,y.count*4);return e.bufferData(34962,s,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[l,A]}},onBeforeDrawPrimitive(e,t,n,u,o,f){if(!n.pluginData?.skinning?.hasSkin)return;let g=f?.nodes?.[u.nodeIndex]?.skin;if(g===void 0||!f.skins||!f.skins[g])return;let r=f.skins[g].joints||[],a=new Float32Array(pe*16);for(let m=0;m<r.length&&m<pe;m++){let l=r[m],i=o[l]||K();a.subarray(m*16,(m+1)*16).set(i)}let c=e.getUniformLocation(t,"uJointMatrix[0]");c&&e.uniformMatrix4fv(c,!1,a)}};z(de);z(he);z(be);z(ce);
|
|
@@ -30,12 +30,12 @@ import type {
|
|
|
30
30
|
} from './three-live/src/three-view';
|
|
31
31
|
import type {ARLaunchResult, ARMode} from './three-live/src/three-xr';
|
|
32
32
|
import type {
|
|
33
|
+
Detection3D,
|
|
33
34
|
DimensionUnit,
|
|
34
35
|
ExplodeMode,
|
|
35
36
|
RemotePeerState,
|
|
36
37
|
SnapSurfaceMode,
|
|
37
38
|
TranscriptEvent,
|
|
38
|
-
Detection3D,
|
|
39
39
|
} from './xr-live/src/plugins/index';
|
|
40
40
|
import type {
|
|
41
41
|
XRAnchorElement,
|
|
@@ -48,6 +48,29 @@ 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_TEXT_GEOMETRY_CHARS,
|
|
57
|
+
type ExtrudeGeometryOptions,
|
|
58
|
+
type TextGeometryOptions,
|
|
59
|
+
} from './three-live/src/plugins/cad';
|
|
60
|
+
export {
|
|
61
|
+
ikPlugin,
|
|
62
|
+
IKSolver,
|
|
63
|
+
quatFromUnitVectors,
|
|
64
|
+
solveFABRIK,
|
|
65
|
+
solveTwoBoneIK,
|
|
66
|
+
type FABRIKSolution,
|
|
67
|
+
type IKQuat,
|
|
68
|
+
type TwoBoneIKSolution,
|
|
69
|
+
} from './three-live/src/plugins/ik';
|
|
70
|
+
export {
|
|
71
|
+
extractNodeInstancing,
|
|
72
|
+
instancingPlugin,
|
|
73
|
+
} from './three-live/src/plugins/instancing';
|
|
51
74
|
export {
|
|
52
75
|
getInteractivityVM,
|
|
53
76
|
interactivityPlugin,
|
|
@@ -63,6 +86,30 @@ export {
|
|
|
63
86
|
type InteractivityValueSocket,
|
|
64
87
|
type InteractivityVariableDef,
|
|
65
88
|
} from './three-live/src/plugins/interactivity';
|
|
89
|
+
export {
|
|
90
|
+
applyMeshoptFilter,
|
|
91
|
+
decodeMeshoptBuffer,
|
|
92
|
+
decodeMeshoptGLB,
|
|
93
|
+
encodeMeshoptBuffer,
|
|
94
|
+
meshoptDecoder,
|
|
95
|
+
meshoptPlugin,
|
|
96
|
+
type MeshoptFilter,
|
|
97
|
+
type MeshoptMode,
|
|
98
|
+
} from './three-live/src/plugins/meshopt';
|
|
99
|
+
export {
|
|
100
|
+
computeOutlineClipOffset,
|
|
101
|
+
evaluateKawaseBloom,
|
|
102
|
+
parseHexRgb,
|
|
103
|
+
postprocessingPlugin,
|
|
104
|
+
resolveViewerBloom,
|
|
105
|
+
} from './three-live/src/plugins/postprocessing';
|
|
106
|
+
export {
|
|
107
|
+
extractMaterialVariants,
|
|
108
|
+
extractPrimitiveVariantMappings,
|
|
109
|
+
selectMaterialVariant,
|
|
110
|
+
variantsPlugin,
|
|
111
|
+
type VariantMapping,
|
|
112
|
+
} from './three-live/src/plugins/variants';
|
|
66
113
|
export {
|
|
67
114
|
ThreeLiveElement,
|
|
68
115
|
type ARLaunchOptions,
|
|
@@ -80,7 +127,7 @@ export {
|
|
|
80
127
|
type XRProfile,
|
|
81
128
|
type XRSimulatorRoom,
|
|
82
129
|
} from './xr-live/src/xr-live-element';
|
|
83
|
-
/** Optional spatial plugins (`xr-live/
|
|
130
|
+
/** Optional spatial plugins (`xr-live/spatial`, `xr-live-spatial.min.js`). */
|
|
84
131
|
export * from './xr-live/src/plugins/index';
|
|
85
132
|
|
|
86
133
|
/**
|
|
@@ -119,7 +166,7 @@ export interface ThreeLiveAttributes {
|
|
|
119
166
|
'shadow-intensity'?: number | string;
|
|
120
167
|
/** Radial Gaussian blur falloff of contact shadow (0.0 to 1.0). */
|
|
121
168
|
'shadow-softness'?: number | string;
|
|
122
|
-
/** Tone mapping mode ("neutral", "reinhard", "none"). */
|
|
169
|
+
/** Tone mapping mode ("neutral", "aces", "agx", "reinhard", "none"). */
|
|
123
170
|
'tone-mapping'?: string;
|
|
124
171
|
/** Enable or disable interactive camera orbit/pan/zoom controls (default: true). */
|
|
125
172
|
'camera-controls'?: boolean | string;
|
|
@@ -127,6 +174,8 @@ export interface ThreeLiveAttributes {
|
|
|
127
174
|
'autoplay'?: boolean | string;
|
|
128
175
|
/** Name of specific glTF animation clip to play. */
|
|
129
176
|
'animation-name'?: string;
|
|
177
|
+
/** Name of the active KHR_materials_variants material variant. */
|
|
178
|
+
'variant-name'?: string;
|
|
130
179
|
/** Automatically rotate scene around the Y-axis when user is idle. */
|
|
131
180
|
'auto-rotate'?: boolean | string;
|
|
132
181
|
/** Delay in milliseconds before auto-rotation resumes after user interaction (default: 3000). */
|
|
@@ -162,6 +211,7 @@ export interface ThreeLiveAttributes {
|
|
|
162
211
|
onerror?: (e: CustomEvent<{error: any}>) => void;
|
|
163
212
|
onmeshclick?: (e: CustomEvent<HitDetail>) => void;
|
|
164
213
|
'oncamera-change'?: (e: CustomEvent<CameraDetail>) => void;
|
|
214
|
+
'onvariant-applied'?: (e: CustomEvent<{variantName: string | null}>) => void;
|
|
165
215
|
'onar-status'?: (
|
|
166
216
|
e: CustomEvent<{
|
|
167
217
|
status: 'session-started' | 'not-presenting' | 'failed';
|
|
@@ -193,7 +243,7 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
|
193
243
|
'xr-depth'?: XRDepthMode;
|
|
194
244
|
/** 25-joint hand tracking and gesture recognition mode ("gestures", "joints", "pinch", "none"). */
|
|
195
245
|
'xr-hands'?: XRHandsMode;
|
|
196
|
-
/** Desktop room
|
|
246
|
+
/** Desktop 3D room preview environment, unrelated to `xr-live-sim` ("living-room", "office", "tabletop", "none"). */
|
|
197
247
|
'xr-simulator'?: XRSimulatorRoom;
|
|
198
248
|
/** Spatial UI profile ("quest3", "android-xr", "visionos", "auto"). */
|
|
199
249
|
'xr-profile'?: XRProfile;
|
|
@@ -208,7 +258,14 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
|
208
258
|
/** Default display unit for `spatial-measure` ("auto", "m", "cm", "mm", "in", "ft-in"). */
|
|
209
259
|
'measure-unit'?: DimensionUnit;
|
|
210
260
|
/** Spatial plugin: socket, grid, surface, and angle snapping ("grid", "surface", "sockets", "all", "none"). */
|
|
211
|
-
'magnetic-snap'?:
|
|
261
|
+
'magnetic-snap'?:
|
|
262
|
+
| boolean
|
|
263
|
+
| 'grid'
|
|
264
|
+
| 'surface'
|
|
265
|
+
| 'sockets'
|
|
266
|
+
| 'all'
|
|
267
|
+
| 'none'
|
|
268
|
+
| string;
|
|
212
269
|
/** Cartesian snap grid step in meters ("0.05" or "0.05 0.05 0.05"). */
|
|
213
270
|
'snap-grid'?: number | string;
|
|
214
271
|
/** Rotational yaw snap increment in degrees (0 to 180). */
|
|
@@ -241,6 +298,47 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
|
241
298
|
'peer-name'?: string;
|
|
242
299
|
/** Local avatar visor & laser color (`#rrggbb`) in `shared-room`. */
|
|
243
300
|
'peer-color'?: string;
|
|
301
|
+
/** Opt-in WebRTC spatial voice chat signaling and HRTF distance attenuation in `shared-room`. */
|
|
302
|
+
'shared-room-voice'?: boolean | string;
|
|
303
|
+
/** xr-live-sim: character camera mode, or `none` to disable the character. */
|
|
304
|
+
'character-controller'?:
|
|
305
|
+
| 'third-person'
|
|
306
|
+
| 'first-person'
|
|
307
|
+
| 'top-down'
|
|
308
|
+
| 'fixed-camera'
|
|
309
|
+
| 'none';
|
|
310
|
+
/** xr-live-sim: character speed override (m/s). */
|
|
311
|
+
'character-speed'?: number | string;
|
|
312
|
+
/** xr-live-sim: character jump velocity override (m/s). */
|
|
313
|
+
'character-jump'?: number | string;
|
|
314
|
+
/** xr-live-sim: on-screen joystick (`auto` shows it on touch screens). */
|
|
315
|
+
'touch-joystick'?: 'auto' | 'always' | 'none';
|
|
316
|
+
/** xr-live-sim: `false` or `none` pauses steering agents. */
|
|
317
|
+
'steering-agents'?: boolean | string;
|
|
318
|
+
/** xr-live-sim: firing mode (empty means `projectile`). */
|
|
319
|
+
'hit-zones'?: '' | 'projectile' | 'hitscan' | 'contact' | 'off';
|
|
320
|
+
/** xr-live-sim: shots per second (default: 4). */
|
|
321
|
+
'fire-rate'?: number | string;
|
|
322
|
+
/** xr-live-sim: projectile speed in m/s (default: 14). */
|
|
323
|
+
'projectile-speed'?: number | string;
|
|
324
|
+
/** xr-live-sim: projectile gravity in m/s² (default: 0). */
|
|
325
|
+
'projectile-gravity'?: number | string;
|
|
326
|
+
/** xr-live-sim: integrity removed per hit (default: 25). */
|
|
327
|
+
'hit-amount'?: number | string;
|
|
328
|
+
/** xr-live-sim: enables objectives and scoring (`none` disables). */
|
|
329
|
+
'objectives'?: boolean | string;
|
|
330
|
+
/** xr-live-sim: scenario countdown in seconds. */
|
|
331
|
+
'scenario-timer'?: number | string;
|
|
332
|
+
/** xr-live-sim: score that passes the scenario. */
|
|
333
|
+
'target-score'?: number | string;
|
|
334
|
+
/** xr-live-sim: attempts before the scenario fails. */
|
|
335
|
+
'attempts'?: number | string;
|
|
336
|
+
/** xr-live-sim: score HUD style. */
|
|
337
|
+
'sim-hud'?: 'auto' | 'minimal' | 'none';
|
|
338
|
+
/** xr-live-sim: plays procedural audio cues (`muted` disables). */
|
|
339
|
+
'synth-audio'?: boolean | string;
|
|
340
|
+
/** xr-live-sim: cue volume from 0 to 1 (default: 0.7). */
|
|
341
|
+
'synth-volume'?: number | string;
|
|
244
342
|
/** Register WebMCP browser AI tools on `navigator.modelContext`. */
|
|
245
343
|
'webmcp'?: boolean | string;
|
|
246
344
|
/** Opt-in gate allowing WebMCP `capture_xr_view` to include the 8x8 depth grid. */
|
|
@@ -314,7 +412,85 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
|
314
412
|
e: CustomEvent<Pick<RemotePeerState, 'peerId' | 'name' | 'color'>>,
|
|
315
413
|
) => void;
|
|
316
414
|
onpeersync?: (e: CustomEvent<{peerId: string; nodeId: string}>) => void;
|
|
317
|
-
onpeergrabconflict?: (
|
|
415
|
+
onpeergrabconflict?: (
|
|
416
|
+
e: CustomEvent<{peerId: string; nodeId: string}>,
|
|
417
|
+
) => void;
|
|
418
|
+
onpeerrtcsignal?: (
|
|
419
|
+
e: CustomEvent<{
|
|
420
|
+
peerId: string;
|
|
421
|
+
targetPeerId: string;
|
|
422
|
+
signalType: 'offer' | 'answer' | 'ice';
|
|
423
|
+
sdp: string | null;
|
|
424
|
+
candidate: string | null;
|
|
425
|
+
sdpMid: string | null;
|
|
426
|
+
sdpMLineIndex: number | null;
|
|
427
|
+
}>,
|
|
428
|
+
) => void;
|
|
429
|
+
/** xr-live-sim events. */
|
|
430
|
+
oncharacterjump?: (
|
|
431
|
+
e: CustomEvent<{nodeId: string; position: [number, number, number]}>,
|
|
432
|
+
) => void;
|
|
433
|
+
oncharacterland?: (
|
|
434
|
+
e: CustomEvent<{nodeId: string; fallSpeed: number}>,
|
|
435
|
+
) => void;
|
|
436
|
+
onagentstatechange?: (
|
|
437
|
+
e: CustomEvent<{nodeId: string; state: string; targetId: string | null}>,
|
|
438
|
+
) => void;
|
|
439
|
+
onagentreach?: (
|
|
440
|
+
e: CustomEvent<{
|
|
441
|
+
agentId: string;
|
|
442
|
+
targetId: string;
|
|
443
|
+
position: [number, number, number];
|
|
444
|
+
}>,
|
|
445
|
+
) => void;
|
|
446
|
+
onxrhit?: (
|
|
447
|
+
e: CustomEvent<{
|
|
448
|
+
targetId: string;
|
|
449
|
+
/** Shooter node name, or `'user'`. */
|
|
450
|
+
sourceId: string;
|
|
451
|
+
amount: number;
|
|
452
|
+
remaining: number;
|
|
453
|
+
point: [number, number, number];
|
|
454
|
+
}>,
|
|
455
|
+
) => void;
|
|
456
|
+
onxrdepleted?: (
|
|
457
|
+
e: CustomEvent<{targetId: string; group: string; scoreValue: number}>,
|
|
458
|
+
) => void;
|
|
459
|
+
onxrzoneenter?: (
|
|
460
|
+
e: CustomEvent<{zoneId: string; nodeId: string; group: string}>,
|
|
461
|
+
) => void;
|
|
462
|
+
onxrzoneexit?: (
|
|
463
|
+
e: CustomEvent<{zoneId: string; nodeId: string; group: string}>,
|
|
464
|
+
) => void;
|
|
465
|
+
onxrspawn?: (
|
|
466
|
+
e: CustomEvent<{spawnerId: string; instanceId: string; index: number}>,
|
|
467
|
+
) => void;
|
|
468
|
+
onxrobjective?: (
|
|
469
|
+
e: CustomEvent<{
|
|
470
|
+
nodeId: string;
|
|
471
|
+
tag: string;
|
|
472
|
+
type: string;
|
|
473
|
+
amount: number;
|
|
474
|
+
totalScore: number;
|
|
475
|
+
remainingRequired: number;
|
|
476
|
+
outOfOrder: boolean;
|
|
477
|
+
}>,
|
|
478
|
+
) => void;
|
|
479
|
+
onxrscorechange?: (
|
|
480
|
+
e: CustomEvent<{
|
|
481
|
+
score: number;
|
|
482
|
+
delta: number;
|
|
483
|
+
attemptsLeft: number | null;
|
|
484
|
+
timeRemaining: number | null;
|
|
485
|
+
}>,
|
|
486
|
+
) => void;
|
|
487
|
+
onxrscenarioend?: (
|
|
488
|
+
e: CustomEvent<{
|
|
489
|
+
outcome: 'pass' | 'fail' | 'timeout';
|
|
490
|
+
finalScore: number;
|
|
491
|
+
elapsedSec: number;
|
|
492
|
+
}>,
|
|
493
|
+
) => void;
|
|
318
494
|
}
|
|
319
495
|
|
|
320
496
|
declare global {
|
|
@@ -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 H="__THREE_LIVE_REGISTRY__";function W(){let e=typeof globalThis<"u"?globalThis:{};if(!e[H]){let r={plugins:[],decoders:new Map};try{Object.defineProperty(e,H,{value:r,writable:!1,configurable:!1,enumerable:!1})}catch{e[H]=r}}return e[H]}var Ce=W().plugins;function de(e){let r=W();r.workerExtensionInstallers||(r.workerExtensionInstallers=[]),r.workerExtensionInstallers.includes(e)||r.workerExtensionInstallers.push(e)}function G(e){let r=W().plugins;r.some(n=>n.name===e.name)||r.push(e),e.onRegister?.()}function re(e,r){function n(t,a,c,m){let u=typeof t=="number"?t:Number(t);return Number.isFinite(u)?Math.max(a,Math.min(c,u)):m}function l(t,a){let m=t[0]*a[0]+t[1]*a[1]+t[2]*a[2]+1;if(m<1e-6){if(Math.abs(t[0])>Math.abs(t[2])){let p=Math.hypot(t[1],t[0])||1;return[-t[1]/p,t[0]/p,0,0]}let s=Math.hypot(t[2],t[1])||1;return[0,-t[2]/s,t[1]/s,0]}let u=t[1]*a[2]-t[2]*a[1],o=t[2]*a[0]-t[0]*a[2],d=t[0]*a[1]-t[1]*a[0],A=Math.hypot(u,o,d,m)||1;return[u/A,o/A,d/A,m/A]}function i(t,a,c,m,u){let o=a[0]-t[0],d=a[1]-t[1],A=a[2]-t[2],s=Math.hypot(o,d,A),p=c[0]-a[0],h=c[1]-a[1],x=c[2]-a[2],b=Math.hypot(p,h,x);if(s<1e-6||b<1e-6)return{rootPos:[t[0],t[1],t[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 v=[o/s,d/s,A/s],w=[p/b,h/b,x/b],L=m[0]-t[0],P=m[1]-t[1],N=m[2]-t[2],M=Math.hypot(L,P,N),R=M>1e-6?[L/M,P/M,N/M]:v,S=Math.abs(s-b)+1e-5,T=Math.max(S,s+b-1e-5),I=Math.max(S,Math.min(T,M>1e-6?M:S)),V=n((s*s+I*I-b*b)/(2*s*I),-1,1,1),_=Math.sqrt(Math.max(0,1-V*V)),B=u?u[0]-t[0]:o,E=u?u[1]-t[1]:d,F=u?u[2]-t[2]:A,Y=B*R[0]+E*R[1]+F*R[2],D=B-R[0]*Y,j=E-R[1]*Y,X=F-R[2]*Y,O=Math.hypot(D,j,X);if(O<=1e-6){let me=Math.abs(R[1])<.99?0:1,fe=Math.abs(R[1])<.99?1:0,he=0;D=R[1]*he-R[2]*fe,j=R[2]*me-R[0]*he,X=R[0]*fe-R[1]*me,O=Math.hypot(D,j,X)||1}let Z=[D/O,j/O,X/O],k=[t[0]+R[0]*(s*V)+Z[0]*(s*_),t[1]+R[1]*(s*V)+Z[1]*(s*_),t[2]+R[2]*(s*V)+Z[2]*(s*_)],ee=[t[0]+R[0]*I,t[1]+R[1]*I,t[2]+R[2]*I],ce=ee[0]-k[0],ue=ee[1]-k[1],le=ee[2]-k[2],J=Math.hypot(ce,ue,le),q=J>1e-6?[ce/J,ue/J,le/J]:R,Fe=[k[0]+q[0]*b,k[1]+q[1]*b,k[2]+q[2]*b],Se=[(k[0]-t[0])/s,(k[1]-t[1])/s,(k[2]-t[2])/s];return{rootPos:[t[0],t[1],t[2]],midPos:k,effectorPos:Fe,rootRotation:l(v,Se),midRotation:l(w,q)}}function f(t,a,c=8,m=.001){let u=t.length;if(u<2)return{positions:t.map(M=>[M[0],M[1],M[2]]),rotations:[],iterations:0};let o=t.map(M=>[M[0],M[1],M[2]]),d=[],A=[],s=0;for(let M=0;M<u-1;M++){let R=o[M+1][0]-o[M][0],S=o[M+1][1]-o[M][1],T=o[M+1][2]-o[M][2],I=Math.hypot(R,S,T);d.push(I),s+=I,A.push(I>1e-6?[R/I,S/I,T/I]:[0,1,0])}let p=[o[0][0],o[0][1],o[0][2]],h=Math.round(n(c,1,32,8)),x=n(m,1e-5,.1,.001),b=a[0]-p[0],v=a[1]-p[1],w=a[2]-p[2],L=Math.hypot(b,v,w),P=0;if(L>=s&&s>1e-6){let M=L>1e-6?[b/L,v/L,w/L]:A[0];o[0]=[p[0],p[1],p[2]];for(let R=0;R<u-1;R++){let S=d[R];o[R+1]=[o[R][0]+M[0]*S,o[R][1]+M[1]*S,o[R][2]+M[2]*S]}P=1}else for(let M=1;M<=h;M++){let R=o[u-1];if(Math.hypot(R[0]-a[0],R[1]-a[1],R[2]-a[2])<=x)break;P=M,o[u-1]=[a[0],a[1],a[2]];for(let T=u-2;T>=0;T--){let I=o[T][0]-o[T+1][0],V=o[T][1]-o[T+1][1],_=o[T][2]-o[T+1][2],B=Math.hypot(I,V,_),E=d[T];if(B>1e-6){let F=E/B;o[T]=[o[T+1][0]+I*F,o[T+1][1]+V*F,o[T+1][2]+_*F]}else{let F=A[T];o[T]=[o[T+1][0]-F[0]*E,o[T+1][1]-F[1]*E,o[T+1][2]-F[2]*E]}}o[0]=[p[0],p[1],p[2]];for(let T=0;T<u-1;T++){let I=o[T+1][0]-o[T][0],V=o[T+1][1]-o[T][1],_=o[T+1][2]-o[T][2],B=Math.hypot(I,V,_),E=d[T];if(B>1e-6){let F=E/B;o[T+1]=[o[T][0]+I*F,o[T][1]+V*F,o[T][2]+_*F]}else{let F=A[T];o[T+1]=[o[T][0]+F[0]*E,o[T][1]+F[1]*E,o[T][2]+F[2]*E]}}}let N=[];for(let M=0;M<u-1;M++){let R=o[M+1][0]-o[M][0],S=o[M+1][1]-o[M][1],T=o[M+1][2]-o[M][2],I=Math.hypot(R,S,T),V=I>1e-6?[R/I,S/I,T/I]:A[M];N.push(l(A[M],V))}return{positions:o,rotations:N,iterations:P}}function g(t){if(!t||typeof t!="object"||Array.isArray(t))return null;let a=t;if(a.enabled===!1)return null;let c=b=>{if(typeof b!="string")return;let v=b.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(v)?v:void 0},m=b=>Array.isArray(b)&&b.length===3&&typeof b[0]=="number"&&Number.isFinite(b[0])&&typeof b[1]=="number"&&Number.isFinite(b[1])&&typeof b[2]=="number"&&Number.isFinite(b[2]),u=c(a.root),o=c(a.effector);if(!u||!o)return null;let d=c(a.mid),A=a.target,s;if(m(A))s=[n(A[0],-1e3,1e3,0),n(A[1],-1e3,1e3,0),n(A[2],-1e3,1e3,0)];else{let b=c(A);if(!b)return null;s=b}let p=a.pole,h=m(p)?[n(p[0],-1e3,1e3,0),n(p[1],-1e3,1e3,0),n(p[2],-1e3,1e3,0)]:void 0,x=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||d?"two-bone":"fabrik";return{root:u,...d?{mid:d}:{},effector:o,target:s,...h?{pole:h}:{},solver:x,iterations:Math.round(n(a.iterations,1,32,8)),tolerance:n(a.tolerance,1e-5,.1,.001),weight:n(a.weight,0,1,1)}}let y=Object.freeze({solveTwoBone:i,solveFABRIK:f,parseIKTrait:g});return r&&typeof r=="object"&&(r.authorNamespace=r.authorNamespace||{},r.authorNamespace.IKSolver=y),{clampNum:n,parseIKTrait:g,quatFromUnitVectors:l,solveTwoBoneIK:i,solveFABRIK:f,IKSolver:y}}var C=re(),Ve=C.clampNum,Ee=C.parseIKTrait,ke=C.quatFromUnitVectors,pe=C.solveTwoBoneIK,be=C.solveFABRIK,_e=C.IKSolver;function oe(e){let r=e?.transform??e?.modelMatrix;return r&&r.length>=16?[r[12]||0,r[13]||0,r[14]||0]:[0,0,0]}function ne(e,r){let n=e?.transform??e?.modelMatrix;!n||n.length<16||(n[12]=r[0],n[13]=r[1],n[14]=r[2])}function te(e,r,n,l,i){let f=Ve(i,0,1,1),g=r[0]+(n[0]-r[0])*f,y=r[1]+(n[1]-r[1])*f,t=r[2]+(n[2]-r[2])*f,a=g-e[0],c=y-e[1],m=t-e[2],u=Math.hypot(a,c,m);if(u>1e-6&&l>1e-6){let o=l/u;return[e[0]+a*o,e[1]+c*o,e[2]+m*o]}return[g,y,t]}function Le(e,r,n){if(Array.isArray(e))return[e[0],e[1],e[2]];let l=r.get(e);if(l)return oe(l);if(e==="head"){let i=n?.headPose?.position??n?.headPose??n?.cameraPosition;if(Array.isArray(i)&&i.length>=3)return[i[0],i[1],i[2]]}else if(e==="hand-left"){let i=n?.handPoses?.left?.position??n?.handPoses?.left??n?.hands?.left?.position??n?.hands?.left;if(Array.isArray(i)&&i.length>=3)return[i[0],i[1],i[2]]}else if(e==="hand-right"){let i=n?.handPoses?.right?.position??n?.handPoses?.right??n?.hands?.right?.position??n?.hands?.right;if(Array.isArray(i)&&i.length>=3)return[i[0],i[1],i[2]]}return null}var ye={name:"ik",onRegister(){let e=W();de(re),re(e.threeNamespace,e)},onUpdate(e){let r=e?.meshes;if(!Array.isArray(r)||r.length===0)return;let n=null;for(let l of r){let i=l?.userData?.xr?.ik??l?.extras?.xr?.ik??l?.extensions?.ANDROID_xr_scenecore?.ik;if(!i)continue;let f=Ee(i);if(!f||f.weight<=0)continue;if(!n){n=new Map;for(let s of r)s&&typeof s.name=="string"&&s.name&&n.set(s.name,s)}let g=n.get(f.root),y=n.get(f.effector);if(!g||!y)continue;let t=Le(f.target,n,e);if(!t)continue;let a=f.mid?n.get(f.mid):void 0,c=a?[g,a,y]:[g,y],m=c.map(s=>s.name||"").join(">");if(!l.__ikRestOffsets||l.__ikRestKey!==m){let s=c.map(oe),p=[];for(let h=0;h<s.length-1;h++)p.push([s[h+1][0]-s[h][0],s[h+1][1]-s[h][1],s[h+1][2]-s[h][2]]);l.__ikRestOffsets=p,l.__ikRestKey=m}let u=l.__ikRestOffsets,d=[oe(g)],A=[];for(let s=0;s<u.length;s++){let p=d[s],h=u[s];d.push([p[0]+h[0],p[1]+h[1],p[2]+h[2]]),A.push(Math.hypot(h[0],h[1],h[2]))}if(f.solver==="two-bone"&&a&&d.length===3){let s=pe(d[0],d[1],d[2],t,f.pole),p=te(d[0],d[1],s.midPos,A[0],f.weight),h=[p[0]+u[1][0],p[1]+u[1][1],p[2]+u[1][2]],x=[p[0]+(s.effectorPos[0]-s.midPos[0]),p[1]+(s.effectorPos[1]-s.midPos[1]),p[2]+(s.effectorPos[2]-s.midPos[2])],b=te(p,h,x,A[1],f.weight);ne(a,p),ne(y,b)}else{let s=be(d,t,f.iterations,f.tolerance),p=d[0];for(let h=1;h<c.length;h++){let x=u[h-1],b=[p[0]+x[0],p[1]+x[1],p[2]+x[2]],v=[p[0]+(s.positions[h][0]-s.positions[h-1][0]),p[1]+(s.positions[h][1]-s.positions[h-1][1]),p[2]+(s.positions[h][2]-s.positions[h-1][2])],w=te(p,b,v,A[h-1],f.weight);ne(c[h],w),p=w}}}}};function K(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Be(e,r,n){let l=r[0],i=r[1],f=r[2],g=r[3],y=r[4],t=r[5],a=r[6],c=r[7],m=r[8],u=r[9],o=r[10],d=r[11],A=r[12],s=r[13],p=r[14],h=r[15],x=n[0],b=n[1],v=n[2],w=n[3];return e[0]=x*l+b*y+v*m+w*A,e[1]=x*i+b*t+v*u+w*s,e[2]=x*f+b*a+v*o+w*p,e[3]=x*g+b*c+v*d+w*h,x=n[4],b=n[5],v=n[6],w=n[7],e[4]=x*l+b*y+v*m+w*A,e[5]=x*i+b*t+v*u+w*s,e[6]=x*f+b*a+v*o+w*p,e[7]=x*g+b*c+v*d+w*h,x=n[8],b=n[9],v=n[10],w=n[11],e[8]=x*l+b*y+v*m+w*A,e[9]=x*i+b*t+v*u+w*s,e[10]=x*f+b*a+v*o+w*p,e[11]=x*g+b*c+v*d+w*h,x=n[12],b=n[13],v=n[14],w=n[15],e[12]=x*l+b*y+v*m+w*A,e[13]=x*i+b*t+v*u+w*s,e[14]=x*f+b*a+v*o+w*p,e[15]=x*g+b*c+v*d+w*h,e}function ie(e,r,n,l){let i=r[0],f=r[1],g=r[2],y=r[3],t=i+i,a=f+f,c=g+g,m=i*t,u=i*a,o=i*c,d=f*a,A=f*c,s=g*c,p=y*t,h=y*a,x=y*c,b=l[0],v=l[1],w=l[2];return e[0]=(1-(d+s))*b,e[1]=(u+x)*b,e[2]=(o-h)*b,e[3]=0,e[4]=(u-x)*v,e[5]=(1-(m+s))*v,e[6]=(A+p)*v,e[7]=0,e[8]=(o+h)*w,e[9]=(A-p)*w,e[10]=(1-(m+d))*w,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function ge(e,r){let n=r[0],l=r[1],i=r[2],f=r[4],g=r[5],y=r[6],t=r[8],a=r[9],c=r[10],m=c*g-y*a,u=-c*f+y*t,o=a*f-g*t,d=n*m+l*u+i*o;return d&&(d=1/d,e[0]=m*d,e[1]=u*d,e[2]=o*d,e[3]=(-c*l+i*a)*d,e[4]=(c*n-i*t)*d,e[5]=(-a*n+l*t)*d,e[6]=(y*l-i*g)*d,e[7]=(-y*n+i*f)*d,e[8]=(g*n-l*f)*d),e}function Ae(e,r){let n=Array.isArray(e?.nodes)?e.nodes.length:0,l=[];for(let c=0;c<n;c++)l.push(K());if(n===0)return l;let i=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let m of c.children)i.add(m);let f=new Set,g=128,y=(c,m,u=0)=>{if(u>g||c<0||c>=n||f.has(c))return;f.add(c);let o=e.nodes[c];if(!o)return;let d=K();if(r&&r[c])d.set(r[c]);else if(o.matrix&&o.matrix.length===16)d.set(o.matrix);else{let s=o.translation||[0,0,0],p=o.rotation||[0,0,0,1],h=o.scale||[1,1,1];ie(d,p,s,h)}let A=l[c];if(m?Be(A,m,d):A.set(d),Array.isArray(o.children))for(let s of o.children)typeof s=="number"&&y(s,A,u+1)},t=[],a=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(a&&Array.isArray(a.nodes))t.push(...a.nodes);else for(let c=0;c<n;c++)i.has(c)||t.push(c);for(let c of t)y(c,null);for(let c=0;c<n;c++)!i.has(c)&&!t.includes(c)&&y(c,null);return l}function $(e,r,n){return r%4===0?new Float32Array(e,r,n):new Float32Array(e.slice(r,r+n*4))}function Te(e,r,n,l){let i=r[0],f=r[1],g=r[2],y=r[3],t=n[0],a=n[1],c=n[2],m=n[3],u=i*t+f*a+g*c+y*m;if(u<0&&(t=-t,a=-a,c=-c,m=-m,u=-u),Math.abs(u)>=1)return e[0]=i,e[1]=f,e[2]=g,e[3]=y,e;let o=Math.acos(u),d=Math.sqrt(1-u*u);if(Math.abs(d)<.001)return e[0]=.5*(i+t),e[1]=.5*(f+a),e[2]=.5*(g+c),e[3]=.5*(y+m),e;let A=Math.sin((1-l)*o)/d,s=Math.sin(l*o)/d;return e[0]=i*A+t*s,e[1]=f*A+a*s,e[2]=g*A+c*s,e[3]=y*A+m*s,e}function xe(e,r,n,l){return e[0]=r[0]+l*(n[0]-r[0]),e[1]=r[1]+l*(n[1]-r[1]),e[2]=r[2]+l*(n[2]-r[2]),e}function Me(e,r){if(!Array.isArray(e?.animations))return[];let n=[];for(let l=0;l<e.animations.length;l++){let i=e.animations[l],f=i.name||`Animation_${l}`,g=[],y=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let t of i.channels){if(!t.target||t.target.node===void 0||!t.target.path)continue;let a=i.samplers[t.sampler];if(!a)continue;let c=e.accessors?.[a.input],m=e.accessors?.[a.output];if(!c||!m)continue;let u=e.bufferViews?.[c.bufferView],o=e.bufferViews?.[m.bufferView];if(!u||!o)continue;let d=(u.byteOffset||0)+(c.byteOffset||0),A=(o.byteOffset||0)+(m.byteOffset||0),s=$(r,d,c.count);s.length>0&&s[s.length-1]>y&&(y=s[s.length-1]);let p=t.target.path==="rotation"?4:t.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,c.count))):3,h=$(r,A,m.count*(t.target.path==="weights"?1:p)),x=a.interpolation==="STEP"?"STEP":"LINEAR";g.push({nodeIndex:t.target.node,path:t.target.path,times:s,values:h,interpolation:x})}g.length>0&&n.push({name:f,duration:y,channels:g})}return n}function z(e,r,n){let{times:l,values:i,path:f,interpolation:g}=e,y=l.length;if(y===0)return;let t=f==="rotation"?4:f==="weights"?Math.max(1,Math.round(i.length/y)):3;if(r<=l[0]){for(let h=0;h<t;h++)n[h]=i[h];return}if(r>=l[y-1]){let h=(y-1)*t;for(let x=0;x<t;x++)n[x]=i[h+x];return}let a=0,c=y-1;for(;a<=c;){let h=a+c>>1;l[h]<=r?a=h+1:c=h-1}let m=Math.max(0,c),u=Math.min(y-1,m+1);if(g==="STEP"||m===u){let h=m*t;for(let x=0;x<t;x++)n[x]=i[h+x];return}let o=l[m],d=l[u],A=(r-o)/Math.max(1e-5,d-o),s=m*t,p=u*t;if(f==="rotation"){let h=[i[s],i[s+1],i[s+2],i[s+3]],x=[i[p],i[p+1],i[p+2],i[p+3]];Te(n,h,x,A)}else for(let h=0;h<t;h++)n[h]=i[s+h]+A*(i[p+h]-i[s+h])}var Q=new WeakMap;function Re(e,r,n=.3){if(!e?.animations)return;let l=e.animations.find(y=>y.name===r);if(!l)return;let i=Q.get(e);i||(i=[],e.currentClip&&i.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),Q.set(e,i));let f=n>0?1/n:1e3;for(let y of i)y.clip.name!==r&&(y.fadeSpeed=-f);let g=i.find(y=>y.clip.name===r);g?g.fadeSpeed=f:i.push({clip:l,time:0,weight:n>0?0:1,fadeSpeed:f}),e.currentClip=l,e.isPlayingAnimation=!0}function se(e,r){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let n=Q.get(e);if(!n||n.length===0){if(!e.currentClip)return;n=[{clip:e.currentClip,time:r,weight:1,fadeSpeed:0}]}let l=e.gltf.nodes.length,i=[];for(let m=0;m<l;m++){let u=e.initialNodeTransforms[m];u?i.push({t:[u.t[0],u.t[1],u.t[2]],r:[u.r[0],u.r[1],u.r[2],u.r[3]],s:[u.s[0],u.s[1],u.s[2]]}):i.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let f=[0,0,0],g=[0,0,0,1],y=[1,1,1],t=new Float32Array(64);for(let m of n){let u=Math.max(0,Math.min(1,m.weight));if(!(u<=1e-4))for(let o of m.clip.channels){if(o.nodeIndex<0||o.nodeIndex>=l)continue;let d=i[o.nodeIndex];if(o.path==="translation")z(o,m.time,f),xe(d.t,d.t,f,u);else if(o.path==="rotation")z(o,m.time,g),Te(d.r,d.r,g,u);else if(o.path==="scale")z(o,m.time,y),xe(d.s,d.s,y,u);else if(o.path==="weights"&&(z(o,m.time,t),e.meshes)){for(let A of e.meshes)if(A.nodeIndex===o.nodeIndex){for(let s of A.primitives)if(s.pluginData?.morph?.weights){let p=s.pluginData.morph.weights,h=s.pluginData.morph.numTargets||p.length;for(let x=0;x<h;x++)p[x]=p[x]*(1-u)+t[x]*u}}}}}let a=[];for(let m=0;m<l;m++){let u=K(),{t:o,r:d,s:A}=i[m];ie(u,d,o,A),a.push(u)}let c=Ae(e.gltf,a);e.worldMatrices=c;for(let m of e.meshes)m.nodeIndex>=0&&m.nodeIndex<c.length&&(m.transform.set(c[m.nodeIndex]),ge(m.normalMatrix,m.transform))}var ve={name:"keyframes",evaluateAnimation:se,crossFadeTo:Re,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=Me(e.gltf,e.bin))},onUpdate(e,r){if(!e.isPlayingAnimation)return;let n=Q.get(e);if(n&&n.length>0){for(let l=n.length-1;l>=0;l--){let i=n[l];if(i.time+=r,i.clip.duration>0&&(i.time%=i.clip.duration),i.fadeSpeed!==0)if(i.weight+=i.fadeSpeed*r,i.weight<=0){n.splice(l,1);continue}else i.weight>=1&&(i.weight=1,i.fadeSpeed=0)}n.length>0&&(e.animationTime=n[n.length-1].time),se(e,e.animationTime)}else e.currentClip&&(e.animationTime+=r,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),se(e,e.animationTime))}};var U=64;function Pe(e,r,n){if(!(!e?.meshes||r<0||r>=U))for(let l of e.meshes)for(let i of l.primitives){let f=i.pluginData?.morph;f?.weights&&(f.weights[r]=n)}}var we={name:"morph",onResolveShader(e,r,n,l){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let i=n.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[${U}];
|
|
20
|
+
uniform int uNumMorphTargets;`);return i=i.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
|
|
21
|
+
for (int m = 0; m < ${U}; 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:i,fs:l}},onBuildPrimitiveVAO(e,r,n,l,i){let f=n?.targets;if(!Array.isArray(f)||f.length===0)return null;let g=n.attributes?.POSITION,y=l?.accessors?.[g];if(!y)return null;let t=y.count,a=Math.min(f.length,U),c=new Float32Array(t*a*4);for(let o=0;o<a;o++){let d=f[o].POSITION;if(d===void 0)continue;let A=l.accessors?.[d],s=l.bufferViews?.[A?.bufferView];if(!A||!s)continue;let p=(s.byteOffset||0)+(A.byteOffset||0),h=$(i,p,t*3),x=o*t*4;for(let b=0;b<t;b++)c[x+b*4]=h[b*3],c[x+b*4+1]=h[b*3+1],c[x+b*4+2]=h[b*3+2],c[x+b*4+3]=0}let m=e.createTexture();e.bindTexture(3553,m),e.texImage2D(3553,0,34836,t,a,0,6408,5126,c),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let u=new Float32Array(U);return{hasMorph:!0,morphTex:m,numTargets:a,vertexCount:t,weights:u}},onBeforeDrawPrimitive(e,r,n,l,i,f){let g=n.pluginData?.morph;if(!g?.hasMorph||!g.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,g.morphTex);let y=e.getUniformLocation(r,"uMorphDeltasTex");y&&e.uniform1i(y,5);let t=e.getUniformLocation(r,"uNumMorphTargets");t&&e.uniform1i(t,g.numTargets);let a=e.getUniformLocation(r,"uMorphWeights[0]");a&&e.uniform1fv(a,g.weights)}};var ae=64,Ie={name:"skinning",onResolveShader(e,r,n,l){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let i=n.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[${ae}];`),f=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${f},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(${f},1.0));`).replace(`gl_Position=uMVP*vec4(${f},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${f},1.0));`),{vs:i,fs:l}},onBuildPrimitiveVAO(e,r,n,l,i){let f=n?.attributes;if(!f||f.JOINTS_0===void 0||f.WEIGHTS_0===void 0)return null;let g=l.accessors[f.JOINTS_0],y=l.accessors[f.WEIGHTS_0];if(!g||!y)return null;let t=l.bufferViews[g.bufferView],a=l.bufferViews[y.bufferView];if(!t||!a)return null;let c=(t.byteOffset||0)+(g.byteOffset||0),m=(a.byteOffset||0)+(y.byteOffset||0),u=e.createBuffer();e.bindBuffer(34962,u);let o=g.componentType===5121?5121:5123,d=o===5121?new Uint8Array(i,c,g.count*4):new Uint16Array(i,c,g.count*4);e.bufferData(34962,d,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,o,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let s=new Float32Array(i,m,y.count*4);return e.bufferData(34962,s,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[u,A]}},onBeforeDrawPrimitive(e,r,n,l,i,f){if(!n.pluginData?.skinning?.hasSkin)return;let g=f?.nodes?.[l.nodeIndex]?.skin;if(g===void 0||!f.skins||!f.skins[g])return;let t=f.skins[g].joints||[],a=new Float32Array(ae*16);for(let m=0;m<t.length&&m<ae;m++){let u=t[m],o=i[u]||K();a.subarray(m*16,(m+1)*16).set(o)}let c=e.getUniformLocation(r,"uJointMatrix[0]");c&&e.uniformMatrix4fv(c,!1,a)}};G(we);G(ve);G(Ie);G(ye);export{_e as IKSolver,Re as crossFadeTo,ye as ikPlugin,ve as keyframeAnimationPlugin,we as morphPlugin,Me as parseAnimations,ke as quatFromUnitVectors,z as sampleChannel,Pe as setMorphTargetWeight,Ie as skinningPlugin,be as solveFABRIK,pe 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 ne=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Pe=Object.prototype.hasOwnProperty;var Ce=(e,t)=>{for(var n in t)ne(e,n,{get:t[n],enumerable:!0})},Ke=(e,t,n,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Be(t))!Pe.call(e,o)&&o!==n&&ne(e,o,{get:()=>t[o],enumerable:!(u=Le(t,o))||u.enumerable});return e};var Ne=e=>Ke(ne({},"__esModule",{value:!0}),e);var Ue={};Ce(Ue,{IKSolver:()=>we,crossFadeTo:()=>fe,ikPlugin:()=>ce,keyframeAnimationPlugin:()=>he,morphPlugin:()=>de,parseAnimations:()=>me,quatFromUnitVectors:()=>ve,sampleChannel:()=>N,setMorphTargetWeight:()=>Ee,skinningPlugin:()=>be,solveFABRIK:()=>ae,solveTwoBoneIK:()=>se});var H="__THREE_LIVE_REGISTRY__";function G(){let e=typeof globalThis<"u"?globalThis:{};if(!e[H]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,H,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[H]=t}}return e[H]}var je=G().plugins;function Re(e){let t=G();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function z(e){let t=G().plugins;t.some(n=>n.name===e.name)||t.push(e),e.onRegister?.()}function oe(e,t){function n(r,a,c,m){let l=typeof r=="number"?r:Number(r);return Number.isFinite(l)?Math.max(a,Math.min(c,l)):m}function u(r,a){let m=r[0]*a[0]+r[1]*a[1]+r[2]*a[2]+1;if(m<1e-6){if(Math.abs(r[0])>Math.abs(r[2])){let p=Math.hypot(r[1],r[0])||1;return[-r[1]/p,r[0]/p,0,0]}let s=Math.hypot(r[2],r[1])||1;return[0,-r[2]/s,r[1]/s,0]}let l=r[1]*a[2]-r[2]*a[1],i=r[2]*a[0]-r[0]*a[2],d=r[0]*a[1]-r[1]*a[0],A=Math.hypot(l,i,d,m)||1;return[l/A,i/A,d/A,m/A]}function o(r,a,c,m,l){let i=a[0]-r[0],d=a[1]-r[1],A=a[2]-r[2],s=Math.hypot(i,d,A),p=c[0]-a[0],h=c[1]-a[1],x=c[2]-a[2],b=Math.hypot(p,h,x);if(s<1e-6||b<1e-6)return{rootPos:[r[0],r[1],r[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 v=[i/s,d/s,A/s],w=[p/b,h/b,x/b],L=m[0]-r[0],P=m[1]-r[1],O=m[2]-r[2],M=Math.hypot(L,P,O),R=M>1e-6?[L/M,P/M,O/M]:v,S=Math.abs(s-b)+1e-5,T=Math.max(S,s+b-1e-5),I=Math.max(S,Math.min(T,M>1e-6?M:S)),V=n((s*s+I*I-b*b)/(2*s*I),-1,1,1),_=Math.sqrt(Math.max(0,1-V*V)),B=l?l[0]-r[0]:i,E=l?l[1]-r[1]:d,F=l?l[2]-r[2]:A,Y=B*R[0]+E*R[1]+F*R[2],D=B-R[0]*Y,j=E-R[1]*Y,X=F-R[2]*Y,W=Math.hypot(D,j,X);if(W<=1e-6){let xe=Math.abs(R[1])<.99?0:1,Te=Math.abs(R[1])<.99?1:0,Me=0;D=R[1]*Me-R[2]*Te,j=R[2]*xe-R[0]*Me,X=R[0]*Te-R[1]*xe,W=Math.hypot(D,j,X)||1}let Z=[D/W,j/W,X/W],k=[r[0]+R[0]*(s*V)+Z[0]*(s*_),r[1]+R[1]*(s*V)+Z[1]*(s*_),r[2]+R[2]*(s*V)+Z[2]*(s*_)],ee=[r[0]+R[0]*I,r[1]+R[1]*I,r[2]+R[2]*I],ye=ee[0]-k[0],ge=ee[1]-k[1],Ae=ee[2]-k[2],J=Math.hypot(ye,ge,Ae),q=J>1e-6?[ye/J,ge/J,Ae/J]:R,ke=[k[0]+q[0]*b,k[1]+q[1]*b,k[2]+q[2]*b],_e=[(k[0]-r[0])/s,(k[1]-r[1])/s,(k[2]-r[2])/s];return{rootPos:[r[0],r[1],r[2]],midPos:k,effectorPos:ke,rootRotation:u(v,_e),midRotation:u(w,q)}}function f(r,a,c=8,m=.001){let l=r.length;if(l<2)return{positions:r.map(M=>[M[0],M[1],M[2]]),rotations:[],iterations:0};let i=r.map(M=>[M[0],M[1],M[2]]),d=[],A=[],s=0;for(let M=0;M<l-1;M++){let R=i[M+1][0]-i[M][0],S=i[M+1][1]-i[M][1],T=i[M+1][2]-i[M][2],I=Math.hypot(R,S,T);d.push(I),s+=I,A.push(I>1e-6?[R/I,S/I,T/I]:[0,1,0])}let p=[i[0][0],i[0][1],i[0][2]],h=Math.round(n(c,1,32,8)),x=n(m,1e-5,.1,.001),b=a[0]-p[0],v=a[1]-p[1],w=a[2]-p[2],L=Math.hypot(b,v,w),P=0;if(L>=s&&s>1e-6){let M=L>1e-6?[b/L,v/L,w/L]:A[0];i[0]=[p[0],p[1],p[2]];for(let R=0;R<l-1;R++){let S=d[R];i[R+1]=[i[R][0]+M[0]*S,i[R][1]+M[1]*S,i[R][2]+M[2]*S]}P=1}else for(let M=1;M<=h;M++){let R=i[l-1];if(Math.hypot(R[0]-a[0],R[1]-a[1],R[2]-a[2])<=x)break;P=M,i[l-1]=[a[0],a[1],a[2]];for(let T=l-2;T>=0;T--){let I=i[T][0]-i[T+1][0],V=i[T][1]-i[T+1][1],_=i[T][2]-i[T+1][2],B=Math.hypot(I,V,_),E=d[T];if(B>1e-6){let F=E/B;i[T]=[i[T+1][0]+I*F,i[T+1][1]+V*F,i[T+1][2]+_*F]}else{let F=A[T];i[T]=[i[T+1][0]-F[0]*E,i[T+1][1]-F[1]*E,i[T+1][2]-F[2]*E]}}i[0]=[p[0],p[1],p[2]];for(let T=0;T<l-1;T++){let I=i[T+1][0]-i[T][0],V=i[T+1][1]-i[T][1],_=i[T+1][2]-i[T][2],B=Math.hypot(I,V,_),E=d[T];if(B>1e-6){let F=E/B;i[T+1]=[i[T][0]+I*F,i[T][1]+V*F,i[T][2]+_*F]}else{let F=A[T];i[T+1]=[i[T][0]+F[0]*E,i[T][1]+F[1]*E,i[T][2]+F[2]*E]}}}let O=[];for(let M=0;M<l-1;M++){let R=i[M+1][0]-i[M][0],S=i[M+1][1]-i[M][1],T=i[M+1][2]-i[M][2],I=Math.hypot(R,S,T),V=I>1e-6?[R/I,S/I,T/I]:A[M];O.push(u(A[M],V))}return{positions:i,rotations:O,iterations:P}}function g(r){if(!r||typeof r!="object"||Array.isArray(r))return null;let a=r;if(a.enabled===!1)return null;let c=b=>{if(typeof b!="string")return;let v=b.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(v)?v:void 0},m=b=>Array.isArray(b)&&b.length===3&&typeof b[0]=="number"&&Number.isFinite(b[0])&&typeof b[1]=="number"&&Number.isFinite(b[1])&&typeof b[2]=="number"&&Number.isFinite(b[2]),l=c(a.root),i=c(a.effector);if(!l||!i)return null;let d=c(a.mid),A=a.target,s;if(m(A))s=[n(A[0],-1e3,1e3,0),n(A[1],-1e3,1e3,0),n(A[2],-1e3,1e3,0)];else{let b=c(A);if(!b)return null;s=b}let p=a.pole,h=m(p)?[n(p[0],-1e3,1e3,0),n(p[1],-1e3,1e3,0),n(p[2],-1e3,1e3,0)]:void 0,x=a.solver==="fabrik"?"fabrik":a.solver==="two-bone"||d?"two-bone":"fabrik";return{root:l,...d?{mid:d}:{},effector:i,target:s,...h?{pole:h}:{},solver:x,iterations:Math.round(n(a.iterations,1,32,8)),tolerance:n(a.tolerance,1e-5,.1,.001),weight:n(a.weight,0,1,1)}}let y=Object.freeze({solveTwoBone:o,solveFABRIK:f,parseIKTrait:g});return t&&typeof t=="object"&&(t.authorNamespace=t.authorNamespace||{},t.authorNamespace.IKSolver=y),{clampNum:n,parseIKTrait:g,quatFromUnitVectors:u,solveTwoBoneIK:o,solveFABRIK:f,IKSolver:y}}var C=oe(),Oe=C.clampNum,We=C.parseIKTrait,ve=C.quatFromUnitVectors,se=C.solveTwoBoneIK,ae=C.solveFABRIK,we=C.IKSolver;function ie(e){let t=e?.transform??e?.modelMatrix;return t&&t.length>=16?[t[12]||0,t[13]||0,t[14]||0]:[0,0,0]}function te(e,t){let n=e?.transform??e?.modelMatrix;!n||n.length<16||(n[12]=t[0],n[13]=t[1],n[14]=t[2])}function re(e,t,n,u,o){let f=Oe(o,0,1,1),g=t[0]+(n[0]-t[0])*f,y=t[1]+(n[1]-t[1])*f,r=t[2]+(n[2]-t[2])*f,a=g-e[0],c=y-e[1],m=r-e[2],l=Math.hypot(a,c,m);if(l>1e-6&&u>1e-6){let i=u/l;return[e[0]+a*i,e[1]+c*i,e[2]+m*i]}return[g,y,r]}function Ge(e,t,n){if(Array.isArray(e))return[e[0],e[1],e[2]];let u=t.get(e);if(u)return ie(u);if(e==="head"){let o=n?.headPose?.position??n?.headPose??n?.cameraPosition;if(Array.isArray(o)&&o.length>=3)return[o[0],o[1],o[2]]}else if(e==="hand-left"){let o=n?.handPoses?.left?.position??n?.handPoses?.left??n?.hands?.left?.position??n?.hands?.left;if(Array.isArray(o)&&o.length>=3)return[o[0],o[1],o[2]]}else if(e==="hand-right"){let o=n?.handPoses?.right?.position??n?.handPoses?.right??n?.hands?.right?.position??n?.hands?.right;if(Array.isArray(o)&&o.length>=3)return[o[0],o[1],o[2]]}return null}var ce={name:"ik",onRegister(){let e=G();Re(oe),oe(e.threeNamespace,e)},onUpdate(e){let t=e?.meshes;if(!Array.isArray(t)||t.length===0)return;let n=null;for(let u of t){let o=u?.userData?.xr?.ik??u?.extras?.xr?.ik??u?.extensions?.ANDROID_xr_scenecore?.ik;if(!o)continue;let f=We(o);if(!f||f.weight<=0)continue;if(!n){n=new Map;for(let s of t)s&&typeof s.name=="string"&&s.name&&n.set(s.name,s)}let g=n.get(f.root),y=n.get(f.effector);if(!g||!y)continue;let r=Ge(f.target,n,e);if(!r)continue;let a=f.mid?n.get(f.mid):void 0,c=a?[g,a,y]:[g,y],m=c.map(s=>s.name||"").join(">");if(!u.__ikRestOffsets||u.__ikRestKey!==m){let s=c.map(ie),p=[];for(let h=0;h<s.length-1;h++)p.push([s[h+1][0]-s[h][0],s[h+1][1]-s[h][1],s[h+1][2]-s[h][2]]);u.__ikRestOffsets=p,u.__ikRestKey=m}let l=u.__ikRestOffsets,d=[ie(g)],A=[];for(let s=0;s<l.length;s++){let p=d[s],h=l[s];d.push([p[0]+h[0],p[1]+h[1],p[2]+h[2]]),A.push(Math.hypot(h[0],h[1],h[2]))}if(f.solver==="two-bone"&&a&&d.length===3){let s=se(d[0],d[1],d[2],r,f.pole),p=re(d[0],d[1],s.midPos,A[0],f.weight),h=[p[0]+l[1][0],p[1]+l[1][1],p[2]+l[1][2]],x=[p[0]+(s.effectorPos[0]-s.midPos[0]),p[1]+(s.effectorPos[1]-s.midPos[1]),p[2]+(s.effectorPos[2]-s.midPos[2])],b=re(p,h,x,A[1],f.weight);te(a,p),te(y,b)}else{let s=ae(d,r,f.iterations,f.tolerance),p=d[0];for(let h=1;h<c.length;h++){let x=l[h-1],b=[p[0]+x[0],p[1]+x[1],p[2]+x[2]],v=[p[0]+(s.positions[h][0]-s.positions[h-1][0]),p[1]+(s.positions[h][1]-s.positions[h-1][1]),p[2]+(s.positions[h][2]-s.positions[h-1][2])],w=re(p,b,v,A[h-1],f.weight);te(c[h],w),p=w}}}}};function K(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function ze(e,t,n){let u=t[0],o=t[1],f=t[2],g=t[3],y=t[4],r=t[5],a=t[6],c=t[7],m=t[8],l=t[9],i=t[10],d=t[11],A=t[12],s=t[13],p=t[14],h=t[15],x=n[0],b=n[1],v=n[2],w=n[3];return e[0]=x*u+b*y+v*m+w*A,e[1]=x*o+b*r+v*l+w*s,e[2]=x*f+b*a+v*i+w*p,e[3]=x*g+b*c+v*d+w*h,x=n[4],b=n[5],v=n[6],w=n[7],e[4]=x*u+b*y+v*m+w*A,e[5]=x*o+b*r+v*l+w*s,e[6]=x*f+b*a+v*i+w*p,e[7]=x*g+b*c+v*d+w*h,x=n[8],b=n[9],v=n[10],w=n[11],e[8]=x*u+b*y+v*m+w*A,e[9]=x*o+b*r+v*l+w*s,e[10]=x*f+b*a+v*i+w*p,e[11]=x*g+b*c+v*d+w*h,x=n[12],b=n[13],v=n[14],w=n[15],e[12]=x*u+b*y+v*m+w*A,e[13]=x*o+b*r+v*l+w*s,e[14]=x*f+b*a+v*i+w*p,e[15]=x*g+b*c+v*d+w*h,e}function ue(e,t,n,u){let o=t[0],f=t[1],g=t[2],y=t[3],r=o+o,a=f+f,c=g+g,m=o*r,l=o*a,i=o*c,d=f*a,A=f*c,s=g*c,p=y*r,h=y*a,x=y*c,b=u[0],v=u[1],w=u[2];return e[0]=(1-(d+s))*b,e[1]=(l+x)*b,e[2]=(i-h)*b,e[3]=0,e[4]=(l-x)*v,e[5]=(1-(m+s))*v,e[6]=(A+p)*v,e[7]=0,e[8]=(i+h)*w,e[9]=(A-p)*w,e[10]=(1-(m+d))*w,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function Ie(e,t){let n=t[0],u=t[1],o=t[2],f=t[4],g=t[5],y=t[6],r=t[8],a=t[9],c=t[10],m=c*g-y*a,l=-c*f+y*r,i=a*f-g*r,d=n*m+u*l+o*i;return d&&(d=1/d,e[0]=m*d,e[1]=l*d,e[2]=i*d,e[3]=(-c*u+o*a)*d,e[4]=(c*n-o*r)*d,e[5]=(-a*n+u*r)*d,e[6]=(y*u-o*g)*d,e[7]=(-y*n+o*f)*d,e[8]=(g*n-u*f)*d),e}function Fe(e,t){let n=Array.isArray(e?.nodes)?e.nodes.length:0,u=[];for(let c=0;c<n;c++)u.push(K());if(n===0)return u;let o=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let m of c.children)o.add(m);let f=new Set,g=128,y=(c,m,l=0)=>{if(l>g||c<0||c>=n||f.has(c))return;f.add(c);let i=e.nodes[c];if(!i)return;let d=K();if(t&&t[c])d.set(t[c]);else if(i.matrix&&i.matrix.length===16)d.set(i.matrix);else{let s=i.translation||[0,0,0],p=i.rotation||[0,0,0,1],h=i.scale||[1,1,1];ue(d,p,s,h)}let A=u[c];if(m?ze(A,m,d):A.set(d),Array.isArray(i.children))for(let s of i.children)typeof s=="number"&&y(s,A,l+1)},r=[],a=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(a&&Array.isArray(a.nodes))r.push(...a.nodes);else for(let c=0;c<n;c++)o.has(c)||r.push(c);for(let c of r)y(c,null);for(let c=0;c<n;c++)!o.has(c)&&!r.includes(c)&&y(c,null);return u}function $(e,t,n){return t%4===0?new Float32Array(e,t,n):new Float32Array(e.slice(t,t+n*4))}function Ve(e,t,n,u){let o=t[0],f=t[1],g=t[2],y=t[3],r=n[0],a=n[1],c=n[2],m=n[3],l=o*r+f*a+g*c+y*m;if(l<0&&(r=-r,a=-a,c=-c,m=-m,l=-l),Math.abs(l)>=1)return e[0]=o,e[1]=f,e[2]=g,e[3]=y,e;let i=Math.acos(l),d=Math.sqrt(1-l*l);if(Math.abs(d)<.001)return e[0]=.5*(o+r),e[1]=.5*(f+a),e[2]=.5*(g+c),e[3]=.5*(y+m),e;let A=Math.sin((1-u)*i)/d,s=Math.sin(u*i)/d;return e[0]=o*A+r*s,e[1]=f*A+a*s,e[2]=g*A+c*s,e[3]=y*A+m*s,e}function Se(e,t,n,u){return e[0]=t[0]+u*(n[0]-t[0]),e[1]=t[1]+u*(n[1]-t[1]),e[2]=t[2]+u*(n[2]-t[2]),e}function me(e,t){if(!Array.isArray(e?.animations))return[];let n=[];for(let u=0;u<e.animations.length;u++){let o=e.animations[u],f=o.name||`Animation_${u}`,g=[],y=0;if(Array.isArray(o.channels)&&Array.isArray(o.samplers))for(let r of o.channels){if(!r.target||r.target.node===void 0||!r.target.path)continue;let a=o.samplers[r.sampler];if(!a)continue;let c=e.accessors?.[a.input],m=e.accessors?.[a.output];if(!c||!m)continue;let l=e.bufferViews?.[c.bufferView],i=e.bufferViews?.[m.bufferView];if(!l||!i)continue;let d=(l.byteOffset||0)+(c.byteOffset||0),A=(i.byteOffset||0)+(m.byteOffset||0),s=$(t,d,c.count);s.length>0&&s[s.length-1]>y&&(y=s[s.length-1]);let p=r.target.path==="rotation"?4:r.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,c.count))):3,h=$(t,A,m.count*(r.target.path==="weights"?1:p)),x=a.interpolation==="STEP"?"STEP":"LINEAR";g.push({nodeIndex:r.target.node,path:r.target.path,times:s,values:h,interpolation:x})}g.length>0&&n.push({name:f,duration:y,channels:g})}return n}function N(e,t,n){let{times:u,values:o,path:f,interpolation:g}=e,y=u.length;if(y===0)return;let r=f==="rotation"?4:f==="weights"?Math.max(1,Math.round(o.length/y)):3;if(t<=u[0]){for(let h=0;h<r;h++)n[h]=o[h];return}if(t>=u[y-1]){let h=(y-1)*r;for(let x=0;x<r;x++)n[x]=o[h+x];return}let a=0,c=y-1;for(;a<=c;){let h=a+c>>1;u[h]<=t?a=h+1:c=h-1}let m=Math.max(0,c),l=Math.min(y-1,m+1);if(g==="STEP"||m===l){let h=m*r;for(let x=0;x<r;x++)n[x]=o[h+x];return}let i=u[m],d=u[l],A=(t-i)/Math.max(1e-5,d-i),s=m*r,p=l*r;if(f==="rotation"){let h=[o[s],o[s+1],o[s+2],o[s+3]],x=[o[p],o[p+1],o[p+2],o[p+3]];Ve(n,h,x,A)}else for(let h=0;h<r;h++)n[h]=o[s+h]+A*(o[p+h]-o[s+h])}var Q=new WeakMap;function fe(e,t,n=.3){if(!e?.animations)return;let u=e.animations.find(y=>y.name===t);if(!u)return;let o=Q.get(e);o||(o=[],e.currentClip&&o.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),Q.set(e,o));let f=n>0?1/n:1e3;for(let y of o)y.clip.name!==t&&(y.fadeSpeed=-f);let g=o.find(y=>y.clip.name===t);g?g.fadeSpeed=f:o.push({clip:u,time:0,weight:n>0?0:1,fadeSpeed:f}),e.currentClip=u,e.isPlayingAnimation=!0}function le(e,t){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let n=Q.get(e);if(!n||n.length===0){if(!e.currentClip)return;n=[{clip:e.currentClip,time:t,weight:1,fadeSpeed:0}]}let u=e.gltf.nodes.length,o=[];for(let m=0;m<u;m++){let l=e.initialNodeTransforms[m];l?o.push({t:[l.t[0],l.t[1],l.t[2]],r:[l.r[0],l.r[1],l.r[2],l.r[3]],s:[l.s[0],l.s[1],l.s[2]]}):o.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let f=[0,0,0],g=[0,0,0,1],y=[1,1,1],r=new Float32Array(64);for(let m of n){let l=Math.max(0,Math.min(1,m.weight));if(!(l<=1e-4))for(let i of m.clip.channels){if(i.nodeIndex<0||i.nodeIndex>=u)continue;let d=o[i.nodeIndex];if(i.path==="translation")N(i,m.time,f),Se(d.t,d.t,f,l);else if(i.path==="rotation")N(i,m.time,g),Ve(d.r,d.r,g,l);else if(i.path==="scale")N(i,m.time,y),Se(d.s,d.s,y,l);else if(i.path==="weights"&&(N(i,m.time,r),e.meshes)){for(let A of e.meshes)if(A.nodeIndex===i.nodeIndex){for(let s of A.primitives)if(s.pluginData?.morph?.weights){let p=s.pluginData.morph.weights,h=s.pluginData.morph.numTargets||p.length;for(let x=0;x<h;x++)p[x]=p[x]*(1-l)+r[x]*l}}}}}let a=[];for(let m=0;m<u;m++){let l=K(),{t:i,r:d,s:A}=o[m];ue(l,d,i,A),a.push(l)}let c=Fe(e.gltf,a);e.worldMatrices=c;for(let m of e.meshes)m.nodeIndex>=0&&m.nodeIndex<c.length&&(m.transform.set(c[m.nodeIndex]),Ie(m.normalMatrix,m.transform))}var he={name:"keyframes",evaluateAnimation:le,crossFadeTo:fe,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=me(e.gltf,e.bin))},onUpdate(e,t){if(!e.isPlayingAnimation)return;let n=Q.get(e);if(n&&n.length>0){for(let u=n.length-1;u>=0;u--){let o=n[u];if(o.time+=t,o.clip.duration>0&&(o.time%=o.clip.duration),o.fadeSpeed!==0)if(o.weight+=o.fadeSpeed*t,o.weight<=0){n.splice(u,1);continue}else o.weight>=1&&(o.weight=1,o.fadeSpeed=0)}n.length>0&&(e.animationTime=n[n.length-1].time),le(e,e.animationTime)}else e.currentClip&&(e.animationTime+=t,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),le(e,e.animationTime))}};var U=64;function Ee(e,t,n){if(!(!e?.meshes||t<0||t>=U))for(let u of e.meshes)for(let o of u.primitives){let f=o.pluginData?.morph;f?.weights&&(f.weights[t]=n)}}var de={name:"morph",onResolveShader(e,t,n,u){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let o=n.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[${U}];
|
|
20
|
+
uniform int uNumMorphTargets;`);return o=o.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
|
|
21
|
+
for (int m = 0; m < ${U}; 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:o,fs:u}},onBuildPrimitiveVAO(e,t,n,u,o){let f=n?.targets;if(!Array.isArray(f)||f.length===0)return null;let g=n.attributes?.POSITION,y=u?.accessors?.[g];if(!y)return null;let r=y.count,a=Math.min(f.length,U),c=new Float32Array(r*a*4);for(let i=0;i<a;i++){let d=f[i].POSITION;if(d===void 0)continue;let A=u.accessors?.[d],s=u.bufferViews?.[A?.bufferView];if(!A||!s)continue;let p=(s.byteOffset||0)+(A.byteOffset||0),h=$(o,p,r*3),x=i*r*4;for(let b=0;b<r;b++)c[x+b*4]=h[b*3],c[x+b*4+1]=h[b*3+1],c[x+b*4+2]=h[b*3+2],c[x+b*4+3]=0}let m=e.createTexture();e.bindTexture(3553,m),e.texImage2D(3553,0,34836,r,a,0,6408,5126,c),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let l=new Float32Array(U);return{hasMorph:!0,morphTex:m,numTargets:a,vertexCount:r,weights:l}},onBeforeDrawPrimitive(e,t,n,u,o,f){let g=n.pluginData?.morph;if(!g?.hasMorph||!g.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,g.morphTex);let y=e.getUniformLocation(t,"uMorphDeltasTex");y&&e.uniform1i(y,5);let r=e.getUniformLocation(t,"uNumMorphTargets");r&&e.uniform1i(r,g.numTargets);let a=e.getUniformLocation(t,"uMorphWeights[0]");a&&e.uniform1fv(a,g.weights)}};var pe=64,be={name:"skinning",onResolveShader(e,t,n,u){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let o=n.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[${pe}];`),f=o.includes("morphedPos")?"morphedPos":"aPosition";return o=o.replace(`vec4 world=uModel*vec4(${f},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(${f},1.0));`).replace(`gl_Position=uMVP*vec4(${f},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${f},1.0));`),{vs:o,fs:u}},onBuildPrimitiveVAO(e,t,n,u,o){let f=n?.attributes;if(!f||f.JOINTS_0===void 0||f.WEIGHTS_0===void 0)return null;let g=u.accessors[f.JOINTS_0],y=u.accessors[f.WEIGHTS_0];if(!g||!y)return null;let r=u.bufferViews[g.bufferView],a=u.bufferViews[y.bufferView];if(!r||!a)return null;let c=(r.byteOffset||0)+(g.byteOffset||0),m=(a.byteOffset||0)+(y.byteOffset||0),l=e.createBuffer();e.bindBuffer(34962,l);let i=g.componentType===5121?5121:5123,d=i===5121?new Uint8Array(o,c,g.count*4):new Uint16Array(o,c,g.count*4);e.bufferData(34962,d,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,i,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let s=new Float32Array(o,m,y.count*4);return e.bufferData(34962,s,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[l,A]}},onBeforeDrawPrimitive(e,t,n,u,o,f){if(!n.pluginData?.skinning?.hasSkin)return;let g=f?.nodes?.[u.nodeIndex]?.skin;if(g===void 0||!f.skins||!f.skins[g])return;let r=f.skins[g].joints||[],a=new Float32Array(pe*16);for(let m=0;m<r.length&&m<pe;m++){let l=r[m],i=o[l]||K();a.subarray(m*16,(m+1)*16).set(i)}let c=e.getUniformLocation(t,"uJointMatrix[0]");c&&e.uniformMatrix4fv(c,!1,a)}};z(de);z(he);z(be);z(ce);return Ne(Ue);})();
|