three-live 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,18 +14,18 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- "use strict";var _=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var $=(e,n)=>{for(var r in n)_(e,r,{get:n[r],enumerable:!0})},Y=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of X(n))!H.call(e,t)&&t!==r&&_(e,t,{get:()=>n[t],enumerable:!(i=J(n,t))||i.enumerable});return e};var q=e=>Y(_({},"__esModule",{value:!0}),e);var Q={};$(Q,{crossFadeTo:()=>W,keyframeAnimationPlugin:()=>D,morphPlugin:()=>B,parseAnimations:()=>I,sampleChannel:()=>v,setMorphTargetWeight:()=>j,skinningPlugin:()=>O});module.exports=q(Q);var M="__THREE_LIVE_REGISTRY__";function G(){let e=typeof globalThis<"u"?globalThis:{};if(!e[M]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,M,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[M]=n}}return e[M]}var ee=G().plugins;function S(e){let n=G().plugins;n.some(r=>r.name===e.name)||n.push(e)}function R(){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],h=n[13],x=n[14],d=n[15],y=r[0],g=r[1],T=r[2],P=r[3];return e[0]=y*i+g*u+T*a+P*A,e[1]=y*t+g*s+T*m+P*h,e[2]=y*c+g*b+T*l+P*x,e[3]=y*f+g*o+T*p+P*d,y=r[4],g=r[5],T=r[6],P=r[7],e[4]=y*i+g*u+T*a+P*A,e[5]=y*t+g*s+T*m+P*h,e[6]=y*c+g*b+T*l+P*x,e[7]=y*f+g*o+T*p+P*d,y=r[8],g=r[9],T=r[10],P=r[11],e[8]=y*i+g*u+T*a+P*A,e[9]=y*t+g*s+T*m+P*h,e[10]=y*c+g*b+T*l+P*x,e[11]=y*f+g*o+T*p+P*d,y=r[12],g=r[13],T=r[14],P=r[15],e[12]=y*i+g*u+T*a+P*A,e[13]=y*t+g*s+T*m+P*h,e[14]=y*c+g*b+T*l+P*x,e[15]=y*f+g*o+T*p+P*d,e}function L(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,h=f*o,x=u*s,d=u*b,y=u*o,g=i[0],T=i[1],P=i[2];return e[0]=(1-(p+h))*g,e[1]=(m+y)*g,e[2]=(l-d)*g,e[3]=0,e[4]=(m-y)*T,e[5]=(1-(a+h))*T,e[6]=(A+x)*T,e[7]=0,e[8]=(l+d)*P,e[9]=(A-x)*P,e[10]=(1-(a+p))*P,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(R());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=R();if(n&&n[o])p.set(n[o]);else if(l.matrix&&l.matrix.length===16)p.set(l.matrix);else{let h=l.translation||[0,0,0],x=l.rotation||[0,0,0,1],d=l.scale||[1,1,1];L(p,x,h,d)}let A=i[o];if(a?K(A,a,p):A.set(p),Array.isArray(l.children))for(let h of l.children)typeof h=="number"&&u(h,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,h=Math.sin(i*l)/p;return e[0]=t*A+s*h,e[1]=c*A+b*h,e[2]=f*A+o*h,e[3]=u*A+a*h,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),h=w(n,p,o.count);h.length>0&&h[h.length-1]>u&&(u=h[h.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,d=w(n,A,a.count*(s.target.path==="weights"?1:x)),y=b.interpolation==="STEP"?"STEP":"LINEAR";f.push({nodeIndex:s.target.node,path:s.target.path,times:h,values:d,interpolation:y})}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 d=0;d<s;d++)r[d]=t[d];return}if(n>=i[u-1]){let d=(u-1)*s;for(let y=0;y<s;y++)r[y]=t[d+y];return}let b=0,o=u-1;for(;b<=o;){let d=b+o>>1;i[d]<=n?b=d+1:o=d-1}let a=Math.max(0,o),m=Math.min(u-1,a+1);if(f==="STEP"||a===m){let d=a*s;for(let y=0;y<s;y++)r[y]=t[d+y];return}let l=i[a],p=i[m],A=(n-l)/Math.max(1e-5,p-l),h=a*s,x=m*s;if(c==="rotation"){let d=[t[h],t[h+1],t[h+2],t[h+3]],y=[t[x],t[x+1],t[x+2],t[x+3]];z(r,d,y,A)}else for(let d=0;d<s;d++)r[d]=t[h+d]+A*(t[x+d]-t[h+d])}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 h of A.primitives)if(h.pluginData?.morph?.weights){let x=h.pluginData.morph.weights,d=h.pluginData.morph.numTargets||x.length;for(let y=0;y<d;y++)x[y]=x[y]*(1-m)+s[y]*m}}}}}let b=[];for(let a=0;a<i;a++){let m=R(),{t:l,r:p,s:A}=t[a];L(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 F=64;function j(e,n,r){if(!(!e?.meshes||n<0||n>=F))for(let i of e.meshes)for(let t of i.primitives){let c=t.pluginData?.morph;c?.weights&&(c.weights[n]=r)}}var B={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 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;
18
18
  uniform sampler2D uMorphDeltasTex;
19
- uniform float uMorphWeights[${F}];
19
+ uniform float uMorphWeights[${S}];
20
20
  uniform int uNumMorphTargets;`);return t=t.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
21
- for (int m = 0; m < ${F}; m++) {
21
+ for (int m = 0; m < ${S}; 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:t,fs:i}},onBuildPrimitiveVAO(e,n,r,i,t){let c=r?.targets;if(!Array.isArray(c)||c.length===0)return null;let f=r.attributes?.POSITION,u=i?.accessors?.[f];if(!u)return null;let s=u.count,b=Math.min(c.length,F),o=new Float32Array(s*b*4);for(let l=0;l<b;l++){let p=c[l].POSITION;if(p===void 0)continue;let A=i.accessors?.[p],h=i.bufferViews?.[A?.bufferView];if(!A||!h)continue;let x=(h.byteOffset||0)+(A.byteOffset||0),d=w(t,x,s*3),y=l*s*4;for(let g=0;g<s;g++)o[y+g*4]=d[g*3],o[y+g*4+1]=d[g*3+1],o[y+g*4+2]=d[g*3+2],o[y+g*4+3]=0}let a=e.createTexture();e.bindTexture(3553,a),e.texImage2D(3553,0,34836,s,b,0,6408,5126,o),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array(F);return{hasMorph:!0,morphTex:a,numTargets:b,vertexCount:s,weights:m}},onBeforeDrawPrimitive(e,n,r,i,t,c){let f=r.pluginData?.morph;if(!f?.hasMorph||!f.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,f.morphTex);let u=e.getUniformLocation(n,"uMorphDeltasTex");u&&e.uniform1i(u,5);let s=e.getUniformLocation(n,"uNumMorphTargets");s&&e.uniform1i(s,f.numTargets);let b=e.getUniformLocation(n,"uMorphWeights[0]");b&&e.uniform1fv(b,f.weights)}};var k=64,O={name:"skinning",onResolveShader(e,n,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let t=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
28
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:t,fs:i}},onBuildPrimitiveVAO(e,n,r,i,t){let c=r?.targets;if(!Array.isArray(c)||c.length===0)return null;let f=r.attributes?.POSITION,u=i?.accessors?.[f];if(!u)return null;let s=u.count,b=Math.min(c.length,S),o=new Float32Array(s*b*4);for(let l=0;l<b;l++){let p=c[l].POSITION;if(p===void 0)continue;let A=i.accessors?.[p],d=i.bufferViews?.[A?.bufferView];if(!A||!d)continue;let x=(d.byteOffset||0)+(A.byteOffset||0),y=w(t,x,s*3),h=l*s*4;for(let g=0;g<s;g++)o[h+g*4]=y[g*3],o[h+g*4+1]=y[g*3+1],o[h+g*4+2]=y[g*3+2],o[h+g*4+3]=0}let a=e.createTexture();e.bindTexture(3553,a),e.texImage2D(3553,0,34836,s,b,0,6408,5126,o),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array(S);return{hasMorph:!0,morphTex:a,numTargets:b,vertexCount:s,weights:m}},onBeforeDrawPrimitive(e,n,r,i,t,c){let f=r.pluginData?.morph;if(!f?.hasMorph||!f.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,f.morphTex);let u=e.getUniformLocation(n,"uMorphDeltasTex");u&&e.uniform1i(u,5);let s=e.getUniformLocation(n,"uNumMorphTargets");s&&e.uniform1i(s,f.numTargets);let b=e.getUniformLocation(n,"uMorphWeights[0]");b&&e.uniform1fv(b,f.weights)}};var k=64,B={name:"skinning",onResolveShader(e,n,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let t=r.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
31
  uniform mat4 uJointMatrix[${k}];`),c=t.includes("morphedPos")?"morphedPos":"aPosition";return t=t.replace(`vec4 world=uModel*vec4(${c},1.0);`,`mat4 skinMatrix =
@@ -33,4 +33,4 @@ uniform mat4 uJointMatrix[${k}];`),c=t.includes("morphedPos")?"morphedPos":"aPos
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(${c},1.0));`).replace(`gl_Position=uMVP*vec4(${c},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${c},1.0));`),{vs:t,fs:i}},onBuildPrimitiveVAO(e,n,r,i,t){let c=r?.attributes;if(!c||c.JOINTS_0===void 0||c.WEIGHTS_0===void 0)return null;let f=i.accessors[c.JOINTS_0],u=i.accessors[c.WEIGHTS_0];if(!f||!u)return null;let s=i.bufferViews[f.bufferView],b=i.bufferViews[u.bufferView];if(!s||!b)return null;let o=(s.byteOffset||0)+(f.byteOffset||0),a=(b.byteOffset||0)+(u.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let l=f.componentType===5121?5121:5123,p=l===5121?new Uint8Array(t,o,f.count*4):new Uint16Array(t,o,f.count*4);e.bufferData(34962,p,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,l,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let h=new Float32Array(t,a,u.count*4);return e.bufferData(34962,h,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,A]}},onBeforeDrawPrimitive(e,n,r,i,t,c){if(!r.pluginData?.skinning?.hasSkin)return;let f=c?.nodes?.[i.nodeIndex]?.skin;if(f===void 0||!c.skins||!c.skins[f])return;let s=c.skins[f].joints||[],b=new Float32Array(k*16);for(let a=0;a<s.length&&a<k;a++){let m=s[a],l=t[m]||R();b.subarray(a*16,(a+1)*16).set(l)}let o=e.getUniformLocation(n,"uJointMatrix[0]");o&&e.uniformMatrix4fv(o,!1,b)}};S(B);S(D);S(O);
36
+ vec4 world=uModel*(skinMatrix*vec4(${c},1.0));`).replace(`gl_Position=uMVP*vec4(${c},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${c},1.0));`),{vs:t,fs:i}},onBuildPrimitiveVAO(e,n,r,i,t){let c=r?.attributes;if(!c||c.JOINTS_0===void 0||c.WEIGHTS_0===void 0)return null;let f=i.accessors[c.JOINTS_0],u=i.accessors[c.WEIGHTS_0];if(!f||!u)return null;let s=i.bufferViews[f.bufferView],b=i.bufferViews[u.bufferView];if(!s||!b)return null;let o=(s.byteOffset||0)+(f.byteOffset||0),a=(b.byteOffset||0)+(u.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let l=f.componentType===5121?5121:5123,p=l===5121?new Uint8Array(t,o,f.count*4):new Uint16Array(t,o,f.count*4);e.bufferData(34962,p,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,l,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let d=new Float32Array(t,a,u.count*4);return e.bufferData(34962,d,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,A]}},onBeforeDrawPrimitive(e,n,r,i,t,c){if(!r.pluginData?.skinning?.hasSkin)return;let f=c?.nodes?.[i.nodeIndex]?.skin;if(f===void 0||!c.skins||!c.skins[f])return;let s=c.skins[f].joints||[],b=new Float32Array(k*16);for(let a=0;a<s.length&&a<k;a++){let m=s[a],l=t[m]||P();b.subarray(a*16,(a+1)*16).set(l)}let o=e.getUniformLocation(n,"uJointMatrix[0]");o&&e.uniformMatrix4fv(o,!1,b)}};M(G);M(D);M(B);
@@ -29,8 +29,14 @@ import type {
29
29
  ThreeView,
30
30
  } from './three-live/src/three-view';
31
31
  import type {ARLaunchResult, ARMode} from './three-live/src/three-xr';
32
- import type {TranscriptEvent} from './xr-live/src/plugins/gemini-live';
33
- import type {Detection3D} from './xr-live/src/plugins/world-understanding';
32
+ import type {
33
+ Detection3D,
34
+ DimensionUnit,
35
+ ExplodeMode,
36
+ RemotePeerState,
37
+ SnapSurfaceMode,
38
+ TranscriptEvent,
39
+ } from './xr-live/src/plugins/index';
34
40
  import type {
35
41
  XRAnchorElement,
36
42
  XRDepthMode,
@@ -187,25 +193,241 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
187
193
  'xr-depth'?: XRDepthMode;
188
194
  /** 25-joint hand tracking and gesture recognition mode ("gestures", "joints", "pinch", "none"). */
189
195
  'xr-hands'?: XRHandsMode;
190
- /** Desktop room simulator environment ("living-room", "office", "tabletop", "none"). */
196
+ /** Desktop 3D room preview environment, unrelated to `xr-live-sim` ("living-room", "office", "tabletop", "none"). */
191
197
  'xr-simulator'?: XRSimulatorRoom;
192
198
  /** Spatial UI profile ("quest3", "android-xr", "visionos", "auto"). */
193
199
  'xr-profile'?: XRProfile;
200
+ /** Play procedural Web Audio earcons and haptics on spatial interactions. */
201
+ 'sound-feedback'?: boolean | string;
194
202
  /** Spatial plugin: enables plane/mesh detection; include "reticle" for a gaze reticle. */
195
203
  'world-understanding'?: boolean | string;
196
204
  /** Spatial plugin: pinch in empty space to paint 3D tubes (optional `#rrggbb` color). */
197
205
  'spatial-paint'?: boolean | string;
206
+ /** Spatial plugin: 3D dimension callouts and AR tape measure ("bounds", "tape", "all", "none"). */
207
+ 'spatial-measure'?: boolean | 'bounds' | 'tape' | 'all' | 'none' | string;
208
+ /** Default display unit for `spatial-measure` ("auto", "m", "cm", "mm", "in", "ft-in"). */
209
+ 'measure-unit'?: DimensionUnit;
210
+ /** Spatial plugin: socket, grid, surface, and angle snapping ("grid", "surface", "sockets", "all", "none"). */
211
+ 'magnetic-snap'?:
212
+ | boolean
213
+ | 'grid'
214
+ | 'surface'
215
+ | 'sockets'
216
+ | 'all'
217
+ | 'none'
218
+ | string;
219
+ /** Cartesian snap grid step in meters ("0.05" or "0.05 0.05 0.05"). */
220
+ 'snap-grid'?: number | string;
221
+ /** Rotational yaw snap increment in degrees (0 to 180). */
222
+ 'snap-angle'?: number | string;
223
+ /** Spatial plugin: hands-free eye/head gaze reticle and dwell selection ("auto", "none", or boolean). */
224
+ 'gaze-dwell'?: boolean | 'auto' | 'none' | string;
225
+ /** Default dwell duration in milliseconds for `gaze-dwell` (250 to 10000, default: 1200). */
226
+ 'dwell-time'?: number | string;
227
+ /** Spatial plugin: normalized [0..1] multi-part exploded-view factor. */
228
+ 'explode'?: number | string;
229
+ /** Multi-part explosion vector strategy ("radial", "axial-x", "axial-y", "axial-z", "hierarchical"). */
230
+ 'explode-mode'?: ExplodeMode;
231
+ /** Multiplier applied to per-part explosion distances (default: 1.0). */
232
+ 'explode-scale'?: number | string;
233
+ /** Real-time cross-section clipping plane ("none", "x:0", "y:0.2", "-z:0", "interactive"). */
234
+ 'section-plane'?: string;
235
+ /** Spatial plugin: persist manipulated anchor transforms under an optional storage namespace. */
236
+ 'persistent-anchors'?: boolean | string;
237
+ /** Sync persisted anchor transforms into `#xr-state=<base64url>` for zero-backend link sharing. */
238
+ 'persist-url-hash'?: boolean | string;
239
+ /** Spatial plugin: XR locomotion mode ("teleport", "snap-turn", "smooth", "teleport snap-turn", "none"). */
240
+ 'locomotion'?: boolean | string;
241
+ /** Thumbstick snap-turn increment in degrees (default: 30). */
242
+ 'snap-turn-deg'?: number | string;
243
+ /** Show a 120ms peripheral FOV comfort vignette on teleport/turn (default: true). */
244
+ 'comfort-vignette'?: boolean | string;
245
+ /** Spatial plugin: join a multi-user room via BroadcastChannel ID or `wss://` relay URL. */
246
+ 'shared-room'?: string;
247
+ /** Local display name broadcast to peers in `shared-room` (max 32 chars). */
248
+ 'peer-name'?: string;
249
+ /** Local avatar visor & laser color (`#rrggbb`) in `shared-room`. */
250
+ 'peer-color'?: string;
251
+ /** xr-live-sim: character camera mode, or `none` to disable the character. */
252
+ 'character-controller'?:
253
+ | 'third-person'
254
+ | 'first-person'
255
+ | 'top-down'
256
+ | 'fixed-camera'
257
+ | 'none';
258
+ /** xr-live-sim: character speed override (m/s). */
259
+ 'character-speed'?: number | string;
260
+ /** xr-live-sim: character jump velocity override (m/s). */
261
+ 'character-jump'?: number | string;
262
+ /** xr-live-sim: on-screen joystick (`auto` shows it on touch screens). */
263
+ 'touch-joystick'?: 'auto' | 'always' | 'none';
264
+ /** xr-live-sim: `false` or `none` pauses steering agents. */
265
+ 'steering-agents'?: boolean | string;
266
+ /** xr-live-sim: firing mode (empty means `projectile`). */
267
+ 'hit-zones'?: '' | 'projectile' | 'hitscan' | 'contact' | 'off';
268
+ /** xr-live-sim: shots per second (default: 4). */
269
+ 'fire-rate'?: number | string;
270
+ /** xr-live-sim: projectile speed in m/s (default: 14). */
271
+ 'projectile-speed'?: number | string;
272
+ /** xr-live-sim: projectile gravity in m/s² (default: 0). */
273
+ 'projectile-gravity'?: number | string;
274
+ /** xr-live-sim: integrity removed per hit (default: 25). */
275
+ 'hit-amount'?: number | string;
276
+ /** xr-live-sim: enables objectives and scoring (`none` disables). */
277
+ 'objectives'?: boolean | string;
278
+ /** xr-live-sim: scenario countdown in seconds. */
279
+ 'scenario-timer'?: number | string;
280
+ /** xr-live-sim: score that passes the scenario. */
281
+ 'target-score'?: number | string;
282
+ /** xr-live-sim: attempts before the scenario fails. */
283
+ 'attempts'?: number | string;
284
+ /** xr-live-sim: score HUD style. */
285
+ 'sim-hud'?: 'auto' | 'minimal' | 'none';
286
+ /** xr-live-sim: plays procedural audio cues (`muted` disables). */
287
+ 'synth-audio'?: boolean | string;
288
+ /** xr-live-sim: cue volume from 0 to 1 (default: 0.7). */
289
+ 'synth-volume'?: number | string;
290
+ /** Register WebMCP browser AI tools on `navigator.modelContext`. */
291
+ 'webmcp'?: boolean | string;
292
+ /** Opt-in gate allowing WebMCP `capture_xr_view` to include the 8x8 depth grid. */
293
+ 'webmcp-allow-depth'?: boolean | string;
294
+ /** Omit `headPosition` from WebMCP `inspect_xr_scene` responses. */
295
+ 'webmcp-omit-pose'?: boolean | string;
296
+
198
297
  'onxr-object-detected'?: (e: CustomEvent<Detection3D>) => void;
199
298
  'onxr-transcription'?: (e: CustomEvent<TranscriptEvent>) => void;
200
299
  'onxr-hold-to-ask'?: (
201
300
  e: CustomEvent<{mesh: string; transcript: string; prompt: string}>,
202
301
  ) => void;
203
302
  'onxr-handles-change'?: (
204
- e: CustomEvent<{mesh: string; scale: number; yawDeg: number}>,
303
+ e: CustomEvent<{mesh: any; scale: number; yawDeg: number}>,
205
304
  ) => void;
206
305
  'onxr-paint-stroke'?: (
207
306
  e: CustomEvent<{index: number; points: number; lengthMeters: number}>,
208
307
  ) => void;
308
+ onmeasurecomplete?: (
309
+ e: CustomEvent<{
310
+ start: [number, number, number];
311
+ end: [number, number, number];
312
+ distanceMeters: number;
313
+ formatted: string;
314
+ }>,
315
+ ) => void;
316
+ onxrsnap?: (
317
+ e: CustomEvent<{
318
+ node: any;
319
+ socket: any;
320
+ position: [number, number, number];
321
+ quaternion: [number, number, number, number];
322
+ mode: 'socket' | 'grid' | 'surface' | 'angle';
323
+ }>,
324
+ ) => void;
325
+ onxrunsnap?: (e: CustomEvent<{node: any; socket: any}>) => void;
326
+ ongazeenter?: (
327
+ e: CustomEvent<{node: any; point: [number, number, number]}>,
328
+ ) => void;
329
+ ongazeleave?: (e: CustomEvent<{node: any}>) => void;
330
+ ongazedwell?: (
331
+ e: CustomEvent<{
332
+ node: any;
333
+ point: [number, number, number];
334
+ action: 'select' | 'ask';
335
+ }>,
336
+ ) => void;
337
+ onexplodechange?: (
338
+ e: CustomEvent<{
339
+ factor: number;
340
+ source: 'attribute' | 'gesture' | 'api' | 'peer';
341
+ }>,
342
+ ) => void;
343
+ onanchorsrestored?: (
344
+ e: CustomEvent<{
345
+ count: number;
346
+ source: 'xr-anchor' | 'storage' | 'url-hash';
347
+ }>,
348
+ ) => void;
349
+ onxrteleport?: (
350
+ e: CustomEvent<{
351
+ from: [number, number, number];
352
+ to: [number, number, number];
353
+ yawDeg: number;
354
+ }>,
355
+ ) => void;
356
+ onpeerjoin?: (
357
+ e: CustomEvent<Pick<RemotePeerState, 'peerId' | 'name' | 'color'>>,
358
+ ) => void;
359
+ onpeerleave?: (
360
+ e: CustomEvent<Pick<RemotePeerState, 'peerId' | 'name' | 'color'>>,
361
+ ) => void;
362
+ onpeersync?: (e: CustomEvent<{peerId: string; nodeId: string}>) => void;
363
+ onpeergrabconflict?: (
364
+ e: CustomEvent<{peerId: string; nodeId: string}>,
365
+ ) => void;
366
+ /** xr-live-sim events. */
367
+ oncharacterjump?: (
368
+ e: CustomEvent<{nodeId: string; position: [number, number, number]}>,
369
+ ) => void;
370
+ oncharacterland?: (
371
+ e: CustomEvent<{nodeId: string; fallSpeed: number}>,
372
+ ) => void;
373
+ onagentstatechange?: (
374
+ e: CustomEvent<{nodeId: string; state: string; targetId: string | null}>,
375
+ ) => void;
376
+ onagentreach?: (
377
+ e: CustomEvent<{
378
+ agentId: string;
379
+ targetId: string;
380
+ position: [number, number, number];
381
+ }>,
382
+ ) => void;
383
+ onxrhit?: (
384
+ e: CustomEvent<{
385
+ targetId: string;
386
+ /** Shooter node name, or `'user'`. */
387
+ sourceId: string;
388
+ amount: number;
389
+ remaining: number;
390
+ point: [number, number, number];
391
+ }>,
392
+ ) => void;
393
+ onxrdepleted?: (
394
+ e: CustomEvent<{targetId: string; group: string; scoreValue: number}>,
395
+ ) => void;
396
+ onxrzoneenter?: (
397
+ e: CustomEvent<{zoneId: string; nodeId: string; group: string}>,
398
+ ) => void;
399
+ onxrzoneexit?: (
400
+ e: CustomEvent<{zoneId: string; nodeId: string; group: string}>,
401
+ ) => void;
402
+ onxrspawn?: (
403
+ e: CustomEvent<{spawnerId: string; instanceId: string; index: number}>,
404
+ ) => void;
405
+ onxrobjective?: (
406
+ e: CustomEvent<{
407
+ nodeId: string;
408
+ tag: string;
409
+ type: string;
410
+ amount: number;
411
+ totalScore: number;
412
+ remainingRequired: number;
413
+ outOfOrder: boolean;
414
+ }>,
415
+ ) => void;
416
+ onxrscorechange?: (
417
+ e: CustomEvent<{
418
+ score: number;
419
+ delta: number;
420
+ attemptsLeft: number | null;
421
+ timeRemaining: number | null;
422
+ }>,
423
+ ) => void;
424
+ onxrscenarioend?: (
425
+ e: CustomEvent<{
426
+ outcome: 'pass' | 'fail' | 'timeout';
427
+ finalScore: number;
428
+ elapsedSec: number;
429
+ }>,
430
+ ) => void;
209
431
  }
210
432
 
211
433
  declare global {
@@ -14,18 +14,18 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- var M="__THREE_LIVE_REGISTRY__";function I(){let e=typeof globalThis<"u"?globalThis:{};if(!e[M]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,M,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[M]=t}}return e[M]}var J=I().plugins;function S(e){let t=I().plugins;t.some(r=>r.name===e.name)||t.push(e)}function R(){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],h=t[13],x=t[14],d=t[15],y=r[0],g=r[1],T=r[2],P=r[3];return e[0]=y*i+g*u+T*a+P*A,e[1]=y*n+g*s+T*m+P*h,e[2]=y*c+g*b+T*l+P*x,e[3]=y*f+g*o+T*p+P*d,y=r[4],g=r[5],T=r[6],P=r[7],e[4]=y*i+g*u+T*a+P*A,e[5]=y*n+g*s+T*m+P*h,e[6]=y*c+g*b+T*l+P*x,e[7]=y*f+g*o+T*p+P*d,y=r[8],g=r[9],T=r[10],P=r[11],e[8]=y*i+g*u+T*a+P*A,e[9]=y*n+g*s+T*m+P*h,e[10]=y*c+g*b+T*l+P*x,e[11]=y*f+g*o+T*p+P*d,y=r[12],g=r[13],T=r[14],P=r[15],e[12]=y*i+g*u+T*a+P*A,e[13]=y*n+g*s+T*m+P*h,e[14]=y*c+g*b+T*l+P*x,e[15]=y*f+g*o+T*p+P*d,e}function _(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,h=f*o,x=u*s,d=u*b,y=u*o,g=i[0],T=i[1],P=i[2];return e[0]=(1-(p+h))*g,e[1]=(m+y)*g,e[2]=(l-d)*g,e[3]=0,e[4]=(m-y)*T,e[5]=(1-(a+h))*T,e[6]=(A+x)*T,e[7]=0,e[8]=(l+d)*P,e[9]=(A-x)*P,e[10]=(1-(a+p))*P,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(R());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=R();if(t&&t[o])p.set(t[o]);else if(l.matrix&&l.matrix.length===16)p.set(l.matrix);else{let h=l.translation||[0,0,0],x=l.rotation||[0,0,0,1],d=l.scale||[1,1,1];_(p,x,h,d)}let A=i[o];if(a?z(A,a,p):A.set(p),Array.isArray(l.children))for(let h of l.children)typeof h=="number"&&u(h,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,h=Math.sin(i*l)/p;return e[0]=n*A+s*h,e[1]=c*A+b*h,e[2]=f*A+o*h,e[3]=u*A+a*h,e}function B(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 O(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),h=w(t,p,o.count);h.length>0&&h[h.length-1]>u&&(u=h[h.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,d=w(t,A,a.count*(s.target.path==="weights"?1:x)),y=b.interpolation==="STEP"?"STEP":"LINEAR";f.push({nodeIndex:s.target.node,path:s.target.path,times:h,values:d,interpolation:y})}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 d=0;d<s;d++)r[d]=n[d];return}if(t>=i[u-1]){let d=(u-1)*s;for(let y=0;y<s;y++)r[y]=n[d+y];return}let b=0,o=u-1;for(;b<=o;){let d=b+o>>1;i[d]<=t?b=d+1:o=d-1}let a=Math.max(0,o),m=Math.min(u-1,a+1);if(f==="STEP"||a===m){let d=a*s;for(let y=0;y<s;y++)r[y]=n[d+y];return}let l=i[a],p=i[m],A=(t-l)/Math.max(1e-5,p-l),h=a*s,x=m*s;if(c==="rotation"){let d=[n[h],n[h+1],n[h+2],n[h+3]],y=[n[x],n[x+1],n[x+2],n[x+3]];k(r,d,y,A)}else for(let d=0;d<s;d++)r[d]=n[h+d]+A*(n[x+d]-n[h+d])}var E=new WeakMap;function G(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 L(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),B(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),B(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 h of A.primitives)if(h.pluginData?.morph?.weights){let x=h.pluginData.morph.weights,d=h.pluginData.morph.numTargets||x.length;for(let y=0;y<d;y++)x[y]=x[y]*(1-m)+s[y]*m}}}}}let b=[];for(let a=0;a<i;a++){let m=R(),{t:l,r:p,s:A}=n[a];_(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:L,crossFadeTo:G,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=O(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),L(e,e.animationTime)}else e.currentClip&&(e.animationTime+=t,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),L(e,e.animationTime))}};var F=64;function j(e,t,r){if(!(!e?.meshes||t<0||t>=F))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 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;
18
18
  uniform sampler2D uMorphDeltasTex;
19
- uniform float uMorphWeights[${F}];
19
+ uniform float uMorphWeights[${S}];
20
20
  uniform int uNumMorphTargets;`);return n=n.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
21
- for (int m = 0; m < ${F}; m++) {
21
+ for (int m = 0; m < ${S}; 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:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let c=r?.targets;if(!Array.isArray(c)||c.length===0)return null;let f=r.attributes?.POSITION,u=i?.accessors?.[f];if(!u)return null;let s=u.count,b=Math.min(c.length,F),o=new Float32Array(s*b*4);for(let l=0;l<b;l++){let p=c[l].POSITION;if(p===void 0)continue;let A=i.accessors?.[p],h=i.bufferViews?.[A?.bufferView];if(!A||!h)continue;let x=(h.byteOffset||0)+(A.byteOffset||0),d=w(n,x,s*3),y=l*s*4;for(let g=0;g<s;g++)o[y+g*4]=d[g*3],o[y+g*4+1]=d[g*3+1],o[y+g*4+2]=d[g*3+2],o[y+g*4+3]=0}let a=e.createTexture();e.bindTexture(3553,a),e.texImage2D(3553,0,34836,s,b,0,6408,5126,o),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array(F);return{hasMorph:!0,morphTex:a,numTargets:b,vertexCount:s,weights:m}},onBeforeDrawPrimitive(e,t,r,i,n,c){let f=r.pluginData?.morph;if(!f?.hasMorph||!f.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,f.morphTex);let u=e.getUniformLocation(t,"uMorphDeltasTex");u&&e.uniform1i(u,5);let s=e.getUniformLocation(t,"uNumMorphTargets");s&&e.uniform1i(s,f.numTargets);let b=e.getUniformLocation(t,"uMorphWeights[0]");b&&e.uniform1fv(b,f.weights)}};var C=64,N={name:"skinning",onResolveShader(e,t,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let n=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
28
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let c=r?.targets;if(!Array.isArray(c)||c.length===0)return null;let f=r.attributes?.POSITION,u=i?.accessors?.[f];if(!u)return null;let s=u.count,b=Math.min(c.length,S),o=new Float32Array(s*b*4);for(let l=0;l<b;l++){let p=c[l].POSITION;if(p===void 0)continue;let A=i.accessors?.[p],d=i.bufferViews?.[A?.bufferView];if(!A||!d)continue;let x=(d.byteOffset||0)+(A.byteOffset||0),y=w(n,x,s*3),h=l*s*4;for(let g=0;g<s;g++)o[h+g*4]=y[g*3],o[h+g*4+1]=y[g*3+1],o[h+g*4+2]=y[g*3+2],o[h+g*4+3]=0}let a=e.createTexture();e.bindTexture(3553,a),e.texImage2D(3553,0,34836,s,b,0,6408,5126,o),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array(S);return{hasMorph:!0,morphTex:a,numTargets:b,vertexCount:s,weights:m}},onBeforeDrawPrimitive(e,t,r,i,n,c){let f=r.pluginData?.morph;if(!f?.hasMorph||!f.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,f.morphTex);let u=e.getUniformLocation(t,"uMorphDeltasTex");u&&e.uniform1i(u,5);let s=e.getUniformLocation(t,"uNumMorphTargets");s&&e.uniform1i(s,f.numTargets);let b=e.getUniformLocation(t,"uMorphWeights[0]");b&&e.uniform1fv(b,f.weights)}};var C=64,N={name:"skinning",onResolveShader(e,t,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let n=r.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
31
  uniform mat4 uJointMatrix[${C}];`),c=n.includes("morphedPos")?"morphedPos":"aPosition";return n=n.replace(`vec4 world=uModel*vec4(${c},1.0);`,`mat4 skinMatrix =
@@ -33,4 +33,4 @@ uniform mat4 uJointMatrix[${C}];`),c=n.includes("morphedPos")?"morphedPos":"aPos
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(${c},1.0));`).replace(`gl_Position=uMVP*vec4(${c},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${c},1.0));`),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let c=r?.attributes;if(!c||c.JOINTS_0===void 0||c.WEIGHTS_0===void 0)return null;let f=i.accessors[c.JOINTS_0],u=i.accessors[c.WEIGHTS_0];if(!f||!u)return null;let s=i.bufferViews[f.bufferView],b=i.bufferViews[u.bufferView];if(!s||!b)return null;let o=(s.byteOffset||0)+(f.byteOffset||0),a=(b.byteOffset||0)+(u.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let l=f.componentType===5121?5121:5123,p=l===5121?new Uint8Array(n,o,f.count*4):new Uint16Array(n,o,f.count*4);e.bufferData(34962,p,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,l,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let h=new Float32Array(n,a,u.count*4);return e.bufferData(34962,h,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,A]}},onBeforeDrawPrimitive(e,t,r,i,n,c){if(!r.pluginData?.skinning?.hasSkin)return;let f=c?.nodes?.[i.nodeIndex]?.skin;if(f===void 0||!c.skins||!c.skins[f])return;let s=c.skins[f].joints||[],b=new Float32Array(C*16);for(let a=0;a<s.length&&a<C;a++){let m=s[a],l=n[m]||R();b.subarray(a*16,(a+1)*16).set(l)}let o=e.getUniformLocation(t,"uJointMatrix[0]");o&&e.uniformMatrix4fv(o,!1,b)}};S(U);S(V);S(N);export{G as crossFadeTo,V as keyframeAnimationPlugin,U as morphPlugin,O as parseAnimations,v as sampleChannel,j as setMorphTargetWeight,N as skinningPlugin};
36
+ vec4 world=uModel*(skinMatrix*vec4(${c},1.0));`).replace(`gl_Position=uMVP*vec4(${c},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${c},1.0));`),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let c=r?.attributes;if(!c||c.JOINTS_0===void 0||c.WEIGHTS_0===void 0)return null;let f=i.accessors[c.JOINTS_0],u=i.accessors[c.WEIGHTS_0];if(!f||!u)return null;let s=i.bufferViews[f.bufferView],b=i.bufferViews[u.bufferView];if(!s||!b)return null;let o=(s.byteOffset||0)+(f.byteOffset||0),a=(b.byteOffset||0)+(u.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let l=f.componentType===5121?5121:5123,p=l===5121?new Uint8Array(n,o,f.count*4):new Uint16Array(n,o,f.count*4);e.bufferData(34962,p,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,l,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let d=new Float32Array(n,a,u.count*4);return e.bufferData(34962,d,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,A]}},onBeforeDrawPrimitive(e,t,r,i,n,c){if(!r.pluginData?.skinning?.hasSkin)return;let f=c?.nodes?.[i.nodeIndex]?.skin;if(f===void 0||!c.skins||!c.skins[f])return;let s=c.skins[f].joints||[],b=new Float32Array(C*16);for(let a=0;a<s.length&&a<C;a++){let m=s[a],l=n[m]||P();b.subarray(a*16,(a+1)*16).set(l)}let o=e.getUniformLocation(t,"uJointMatrix[0]");o&&e.uniformMatrix4fv(o,!1,b)}};M(U);M(V);M(N);export{O as crossFadeTo,V as keyframeAnimationPlugin,U as morphPlugin,B as parseAnimations,v as sampleChannel,X as setMorphTargetWeight,N as skinningPlugin};
@@ -14,18 +14,18 @@
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 _=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var $=(e,n)=>{for(var r in n)_(e,r,{get:n[r],enumerable:!0})},Y=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of X(n))!H.call(e,t)&&t!==r&&_(e,t,{get:()=>n[t],enumerable:!(i=J(n,t))||i.enumerable});return e};var q=e=>Y(_({},"__esModule",{value:!0}),e);var Q={};$(Q,{crossFadeTo:()=>W,keyframeAnimationPlugin:()=>D,morphPlugin:()=>B,parseAnimations:()=>I,sampleChannel:()=>v,setMorphTargetWeight:()=>j,skinningPlugin:()=>O});var M="__THREE_LIVE_REGISTRY__";function G(){let e=typeof globalThis<"u"?globalThis:{};if(!e[M]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,M,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[M]=n}}return e[M]}var ee=G().plugins;function S(e){let n=G().plugins;n.some(r=>r.name===e.name)||n.push(e)}function R(){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],h=n[13],x=n[14],d=n[15],y=r[0],g=r[1],T=r[2],P=r[3];return e[0]=y*i+g*u+T*a+P*A,e[1]=y*t+g*s+T*m+P*h,e[2]=y*c+g*b+T*l+P*x,e[3]=y*f+g*o+T*p+P*d,y=r[4],g=r[5],T=r[6],P=r[7],e[4]=y*i+g*u+T*a+P*A,e[5]=y*t+g*s+T*m+P*h,e[6]=y*c+g*b+T*l+P*x,e[7]=y*f+g*o+T*p+P*d,y=r[8],g=r[9],T=r[10],P=r[11],e[8]=y*i+g*u+T*a+P*A,e[9]=y*t+g*s+T*m+P*h,e[10]=y*c+g*b+T*l+P*x,e[11]=y*f+g*o+T*p+P*d,y=r[12],g=r[13],T=r[14],P=r[15],e[12]=y*i+g*u+T*a+P*A,e[13]=y*t+g*s+T*m+P*h,e[14]=y*c+g*b+T*l+P*x,e[15]=y*f+g*o+T*p+P*d,e}function L(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,h=f*o,x=u*s,d=u*b,y=u*o,g=i[0],T=i[1],P=i[2];return e[0]=(1-(p+h))*g,e[1]=(m+y)*g,e[2]=(l-d)*g,e[3]=0,e[4]=(m-y)*T,e[5]=(1-(a+h))*T,e[6]=(A+x)*T,e[7]=0,e[8]=(l+d)*P,e[9]=(A-x)*P,e[10]=(1-(a+p))*P,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(R());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=R();if(n&&n[o])p.set(n[o]);else if(l.matrix&&l.matrix.length===16)p.set(l.matrix);else{let h=l.translation||[0,0,0],x=l.rotation||[0,0,0,1],d=l.scale||[1,1,1];L(p,x,h,d)}let A=i[o];if(a?K(A,a,p):A.set(p),Array.isArray(l.children))for(let h of l.children)typeof h=="number"&&u(h,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,h=Math.sin(i*l)/p;return e[0]=t*A+s*h,e[1]=c*A+b*h,e[2]=f*A+o*h,e[3]=u*A+a*h,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),h=w(n,p,o.count);h.length>0&&h[h.length-1]>u&&(u=h[h.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,d=w(n,A,a.count*(s.target.path==="weights"?1:x)),y=b.interpolation==="STEP"?"STEP":"LINEAR";f.push({nodeIndex:s.target.node,path:s.target.path,times:h,values:d,interpolation:y})}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 d=0;d<s;d++)r[d]=t[d];return}if(n>=i[u-1]){let d=(u-1)*s;for(let y=0;y<s;y++)r[y]=t[d+y];return}let b=0,o=u-1;for(;b<=o;){let d=b+o>>1;i[d]<=n?b=d+1:o=d-1}let a=Math.max(0,o),m=Math.min(u-1,a+1);if(f==="STEP"||a===m){let d=a*s;for(let y=0;y<s;y++)r[y]=t[d+y];return}let l=i[a],p=i[m],A=(n-l)/Math.max(1e-5,p-l),h=a*s,x=m*s;if(c==="rotation"){let d=[t[h],t[h+1],t[h+2],t[h+3]],y=[t[x],t[x+1],t[x+2],t[x+3]];z(r,d,y,A)}else for(let d=0;d<s;d++)r[d]=t[h+d]+A*(t[x+d]-t[h+d])}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 h of A.primitives)if(h.pluginData?.morph?.weights){let x=h.pluginData.morph.weights,d=h.pluginData.morph.numTargets||x.length;for(let y=0;y<d;y++)x[y]=x[y]*(1-m)+s[y]*m}}}}}let b=[];for(let a=0;a<i;a++){let m=R(),{t:l,r:p,s:A}=t[a];L(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 F=64;function j(e,n,r){if(!(!e?.meshes||n<0||n>=F))for(let i of e.meshes)for(let t of i.primitives){let c=t.pluginData?.morph;c?.weights&&(c.weights[n]=r)}}var B={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 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;
18
18
  uniform sampler2D uMorphDeltasTex;
19
- uniform float uMorphWeights[${F}];
19
+ uniform float uMorphWeights[${S}];
20
20
  uniform int uNumMorphTargets;`);return t=t.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
21
- for (int m = 0; m < ${F}; m++) {
21
+ for (int m = 0; m < ${S}; 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:t,fs:i}},onBuildPrimitiveVAO(e,n,r,i,t){let c=r?.targets;if(!Array.isArray(c)||c.length===0)return null;let f=r.attributes?.POSITION,u=i?.accessors?.[f];if(!u)return null;let s=u.count,b=Math.min(c.length,F),o=new Float32Array(s*b*4);for(let l=0;l<b;l++){let p=c[l].POSITION;if(p===void 0)continue;let A=i.accessors?.[p],h=i.bufferViews?.[A?.bufferView];if(!A||!h)continue;let x=(h.byteOffset||0)+(A.byteOffset||0),d=w(t,x,s*3),y=l*s*4;for(let g=0;g<s;g++)o[y+g*4]=d[g*3],o[y+g*4+1]=d[g*3+1],o[y+g*4+2]=d[g*3+2],o[y+g*4+3]=0}let a=e.createTexture();e.bindTexture(3553,a),e.texImage2D(3553,0,34836,s,b,0,6408,5126,o),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array(F);return{hasMorph:!0,morphTex:a,numTargets:b,vertexCount:s,weights:m}},onBeforeDrawPrimitive(e,n,r,i,t,c){let f=r.pluginData?.morph;if(!f?.hasMorph||!f.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,f.morphTex);let u=e.getUniformLocation(n,"uMorphDeltasTex");u&&e.uniform1i(u,5);let s=e.getUniformLocation(n,"uNumMorphTargets");s&&e.uniform1i(s,f.numTargets);let b=e.getUniformLocation(n,"uMorphWeights[0]");b&&e.uniform1fv(b,f.weights)}};var k=64,O={name:"skinning",onResolveShader(e,n,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let t=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
28
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:t,fs:i}},onBuildPrimitiveVAO(e,n,r,i,t){let c=r?.targets;if(!Array.isArray(c)||c.length===0)return null;let f=r.attributes?.POSITION,u=i?.accessors?.[f];if(!u)return null;let s=u.count,b=Math.min(c.length,S),o=new Float32Array(s*b*4);for(let l=0;l<b;l++){let p=c[l].POSITION;if(p===void 0)continue;let A=i.accessors?.[p],d=i.bufferViews?.[A?.bufferView];if(!A||!d)continue;let x=(d.byteOffset||0)+(A.byteOffset||0),y=w(t,x,s*3),h=l*s*4;for(let g=0;g<s;g++)o[h+g*4]=y[g*3],o[h+g*4+1]=y[g*3+1],o[h+g*4+2]=y[g*3+2],o[h+g*4+3]=0}let a=e.createTexture();e.bindTexture(3553,a),e.texImage2D(3553,0,34836,s,b,0,6408,5126,o),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array(S);return{hasMorph:!0,morphTex:a,numTargets:b,vertexCount:s,weights:m}},onBeforeDrawPrimitive(e,n,r,i,t,c){let f=r.pluginData?.morph;if(!f?.hasMorph||!f.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,f.morphTex);let u=e.getUniformLocation(n,"uMorphDeltasTex");u&&e.uniform1i(u,5);let s=e.getUniformLocation(n,"uNumMorphTargets");s&&e.uniform1i(s,f.numTargets);let b=e.getUniformLocation(n,"uMorphWeights[0]");b&&e.uniform1fv(b,f.weights)}};var k=64,B={name:"skinning",onResolveShader(e,n,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let t=r.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
31
  uniform mat4 uJointMatrix[${k}];`),c=t.includes("morphedPos")?"morphedPos":"aPosition";return t=t.replace(`vec4 world=uModel*vec4(${c},1.0);`,`mat4 skinMatrix =
@@ -33,4 +33,4 @@ uniform mat4 uJointMatrix[${k}];`),c=t.includes("morphedPos")?"morphedPos":"aPos
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(${c},1.0));`).replace(`gl_Position=uMVP*vec4(${c},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${c},1.0));`),{vs:t,fs:i}},onBuildPrimitiveVAO(e,n,r,i,t){let c=r?.attributes;if(!c||c.JOINTS_0===void 0||c.WEIGHTS_0===void 0)return null;let f=i.accessors[c.JOINTS_0],u=i.accessors[c.WEIGHTS_0];if(!f||!u)return null;let s=i.bufferViews[f.bufferView],b=i.bufferViews[u.bufferView];if(!s||!b)return null;let o=(s.byteOffset||0)+(f.byteOffset||0),a=(b.byteOffset||0)+(u.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let l=f.componentType===5121?5121:5123,p=l===5121?new Uint8Array(t,o,f.count*4):new Uint16Array(t,o,f.count*4);e.bufferData(34962,p,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,l,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let h=new Float32Array(t,a,u.count*4);return e.bufferData(34962,h,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,A]}},onBeforeDrawPrimitive(e,n,r,i,t,c){if(!r.pluginData?.skinning?.hasSkin)return;let f=c?.nodes?.[i.nodeIndex]?.skin;if(f===void 0||!c.skins||!c.skins[f])return;let s=c.skins[f].joints||[],b=new Float32Array(k*16);for(let a=0;a<s.length&&a<k;a++){let m=s[a],l=t[m]||R();b.subarray(a*16,(a+1)*16).set(l)}let o=e.getUniformLocation(n,"uJointMatrix[0]");o&&e.uniformMatrix4fv(o,!1,b)}};S(B);S(D);S(O);return q(Q);})();
36
+ vec4 world=uModel*(skinMatrix*vec4(${c},1.0));`).replace(`gl_Position=uMVP*vec4(${c},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${c},1.0));`),{vs:t,fs:i}},onBuildPrimitiveVAO(e,n,r,i,t){let c=r?.attributes;if(!c||c.JOINTS_0===void 0||c.WEIGHTS_0===void 0)return null;let f=i.accessors[c.JOINTS_0],u=i.accessors[c.WEIGHTS_0];if(!f||!u)return null;let s=i.bufferViews[f.bufferView],b=i.bufferViews[u.bufferView];if(!s||!b)return null;let o=(s.byteOffset||0)+(f.byteOffset||0),a=(b.byteOffset||0)+(u.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let l=f.componentType===5121?5121:5123,p=l===5121?new Uint8Array(t,o,f.count*4):new Uint16Array(t,o,f.count*4);e.bufferData(34962,p,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,l,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let d=new Float32Array(t,a,u.count*4);return e.bufferData(34962,d,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,A]}},onBeforeDrawPrimitive(e,n,r,i,t,c){if(!r.pluginData?.skinning?.hasSkin)return;let f=c?.nodes?.[i.nodeIndex]?.skin;if(f===void 0||!c.skins||!c.skins[f])return;let s=c.skins[f].joints||[],b=new Float32Array(k*16);for(let a=0;a<s.length&&a<k;a++){let m=s[a],l=t[m]||P();b.subarray(a*16,(a+1)*16).set(l)}let o=e.getUniformLocation(n,"uJointMatrix[0]");o&&e.uniformMatrix4fv(o,!1,b)}};M(G);M(D);M(B);return q(Q);})();