three-live 1.1.0 → 1.1.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.
- package/dist/index.d.ts +3 -3
- package/dist/three-author-engine.js +45 -40
- package/dist/three-author.cjs +32 -27
- package/dist/three-author.d.ts +3 -3
- package/dist/three-author.js +32 -27
- package/dist/three-convert.cjs +43 -38
- package/dist/three-convert.d.ts +3 -3
- package/dist/three-convert.js +42 -37
- package/dist/three-live-animation.cjs +6 -6
- package/dist/three-live-animation.d.ts +3 -3
- package/dist/three-live-animation.js +5 -5
- package/dist/three-live-animation.min.js +6 -6
- package/dist/three-live-element.cjs +12 -7
- package/dist/three-live-element.d.ts +3 -3
- package/dist/three-live-element.js +12 -7
- package/dist/three-live-extras.cjs +13 -13
- package/dist/three-live-extras.d.ts +3 -3
- package/dist/three-live-extras.js +12 -12
- package/dist/three-live-extras.min.js +13 -13
- package/dist/three-live-full.cjs +69 -64
- package/dist/three-live-full.js +69 -64
- package/dist/three-live-full.min.js +69 -64
- package/dist/three-live-viewer.cjs +12 -7
- package/dist/three-live-viewer.d.ts +3 -3
- package/dist/three-live-viewer.js +12 -7
- package/dist/three-live-viewer.min.js +12 -7
- package/dist/three-live.cjs +49 -44
- package/dist/three-live.js +49 -44
- package/dist/three-live.min.js +49 -44
- package/dist/three-view.cjs +12 -7
- package/dist/three-view.d.ts +3 -3
- package/dist/three-view.js +12 -7
- package/dist/three-xr.cjs +44 -39
- package/dist/three-xr.d.ts +3 -3
- package/dist/three-xr.js +44 -39
- package/package.json +1 -1
|
@@ -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 _=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:()=>
|
|
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;
|
|
18
18
|
uniform sampler2D uMorphDeltasTex;
|
|
19
|
-
uniform float uMorphWeights[${
|
|
19
|
+
uniform float uMorphWeights[${F}];
|
|
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 < ${
|
|
21
|
+
for (int m = 0; m < ${F}; 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,
|
|
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;
|
|
29
29
|
layout(location=4) in uvec4 aJoints;
|
|
30
30
|
layout(location=5) in vec4 aWeights;
|
|
31
|
-
uniform mat4 uJointMatrix[${
|
|
31
|
+
uniform mat4 uJointMatrix[${k}];`),c=t.includes("morphedPos")?"morphedPos":"aPosition";return t=t.replace(`vec4 world=uModel*vec4(${c},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(${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(
|
|
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);
|
|
@@ -74,7 +74,7 @@ export {
|
|
|
74
74
|
type XRProfile,
|
|
75
75
|
type XRSimulatorRoom,
|
|
76
76
|
} from './xr-live/src/xr-live-element';
|
|
77
|
-
/** Optional
|
|
77
|
+
/** Optional spatial plugins (`xr-live/plugins`, `xr-live-plugins.min.js`). */
|
|
78
78
|
export * from './xr-live/src/plugins/index';
|
|
79
79
|
|
|
80
80
|
/**
|
|
@@ -191,9 +191,9 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
|
191
191
|
'xr-simulator'?: XRSimulatorRoom;
|
|
192
192
|
/** Spatial UI profile ("quest3", "android-xr", "visionos", "auto"). */
|
|
193
193
|
'xr-profile'?: XRProfile;
|
|
194
|
-
/**
|
|
194
|
+
/** Spatial plugin: enables plane/mesh detection; include "reticle" for a gaze reticle. */
|
|
195
195
|
'world-understanding'?: boolean | string;
|
|
196
|
-
/**
|
|
196
|
+
/** Spatial plugin: pinch in empty space to paint 3D tubes (optional `#rrggbb` color). */
|
|
197
197
|
'spatial-paint'?: boolean | string;
|
|
198
198
|
'onxr-object-detected'?: (e: CustomEvent<Detection3D>) => void;
|
|
199
199
|
'onxr-transcription'?: (e: CustomEvent<TranscriptEvent>) => void;
|
|
@@ -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
|
|
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;
|
|
18
18
|
uniform sampler2D uMorphDeltasTex;
|
|
19
|
-
uniform float uMorphWeights[${
|
|
19
|
+
uniform float uMorphWeights[${F}];
|
|
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 < ${
|
|
21
|
+
for (int m = 0; m < ${F}; 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,
|
|
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;
|
|
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,
|
|
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};
|
|
@@ -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 _=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:()=>
|
|
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;
|
|
18
18
|
uniform sampler2D uMorphDeltasTex;
|
|
19
|
-
uniform float uMorphWeights[${
|
|
19
|
+
uniform float uMorphWeights[${F}];
|
|
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 < ${
|
|
21
|
+
for (int m = 0; m < ${F}; 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,
|
|
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;
|
|
29
29
|
layout(location=4) in uvec4 aJoints;
|
|
30
30
|
layout(location=5) in vec4 aWeights;
|
|
31
|
-
uniform mat4 uJointMatrix[${
|
|
31
|
+
uniform mat4 uJointMatrix[${k}];`),c=t.includes("morphedPos")?"morphedPos":"aPosition";return t=t.replace(`vec4 world=uModel*vec4(${c},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(${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(
|
|
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);})();
|