three-live 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +112 -3
- package/dist/three-author-engine.js +40 -54
- package/dist/three-author.cjs +30 -44
- package/dist/three-author.d.ts +112 -3
- package/dist/three-author.js +30 -44
- package/dist/three-convert.cjs +39 -53
- package/dist/three-convert.d.ts +112 -3
- package/dist/three-convert.js +39 -53
- package/dist/three-live-animation.cjs +5 -5
- package/dist/three-live-animation.d.ts +112 -3
- package/dist/three-live-animation.js +5 -5
- package/dist/three-live-animation.min.js +5 -5
- package/dist/three-live-element.cjs +13 -27
- package/dist/three-live-element.d.ts +112 -3
- package/dist/three-live-element.js +13 -27
- package/dist/three-live-extras.cjs +12 -12
- package/dist/three-live-extras.d.ts +112 -3
- package/dist/three-live-extras.js +12 -12
- package/dist/three-live-extras.min.js +12 -12
- package/dist/three-live-full.cjs +59 -73
- package/dist/three-live-full.js +59 -73
- package/dist/three-live-full.min.js +59 -73
- package/dist/three-live-viewer.cjs +13 -27
- package/dist/three-live-viewer.d.ts +112 -3
- package/dist/three-live-viewer.js +13 -27
- package/dist/three-live-viewer.min.js +13 -27
- package/dist/three-live.cjs +34 -48
- package/dist/three-live.js +34 -48
- package/dist/three-live.min.js +34 -48
- package/dist/three-view.cjs +13 -27
- package/dist/three-view.d.ts +112 -3
- package/dist/three-view.js +13 -27
- package/dist/three-xr.cjs +41 -55
- package/dist/three-xr.d.ts +112 -3
- package/dist/three-xr.js +41 -55
- package/package.json +1 -1
|
@@ -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
|
|
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[${
|
|
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 < ${
|
|
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,
|
|
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
|
|
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 {
|
|
33
|
-
|
|
32
|
+
import type {
|
|
33
|
+
DimensionUnit,
|
|
34
|
+
ExplodeMode,
|
|
35
|
+
RemotePeerState,
|
|
36
|
+
SnapSurfaceMode,
|
|
37
|
+
TranscriptEvent,
|
|
38
|
+
Detection3D,
|
|
39
|
+
} from './xr-live/src/plugins/index';
|
|
34
40
|
import type {
|
|
35
41
|
XRAnchorElement,
|
|
36
42
|
XRDepthMode,
|
|
@@ -191,21 +197,124 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
|
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'?: boolean | 'grid' | 'surface' | 'sockets' | 'all' | 'none' | string;
|
|
212
|
+
/** Cartesian snap grid step in meters ("0.05" or "0.05 0.05 0.05"). */
|
|
213
|
+
'snap-grid'?: number | string;
|
|
214
|
+
/** Rotational yaw snap increment in degrees (0 to 180). */
|
|
215
|
+
'snap-angle'?: number | string;
|
|
216
|
+
/** Spatial plugin: hands-free eye/head gaze reticle and dwell selection ("auto", "none", or boolean). */
|
|
217
|
+
'gaze-dwell'?: boolean | 'auto' | 'none' | string;
|
|
218
|
+
/** Default dwell duration in milliseconds for `gaze-dwell` (250 to 10000, default: 1200). */
|
|
219
|
+
'dwell-time'?: number | string;
|
|
220
|
+
/** Spatial plugin: normalized [0..1] multi-part exploded-view factor. */
|
|
221
|
+
'explode'?: number | string;
|
|
222
|
+
/** Multi-part explosion vector strategy ("radial", "axial-x", "axial-y", "axial-z", "hierarchical"). */
|
|
223
|
+
'explode-mode'?: ExplodeMode;
|
|
224
|
+
/** Multiplier applied to per-part explosion distances (default: 1.0). */
|
|
225
|
+
'explode-scale'?: number | string;
|
|
226
|
+
/** Real-time cross-section clipping plane ("none", "x:0", "y:0.2", "-z:0", "interactive"). */
|
|
227
|
+
'section-plane'?: string;
|
|
228
|
+
/** Spatial plugin: persist manipulated anchor transforms under an optional storage namespace. */
|
|
229
|
+
'persistent-anchors'?: boolean | string;
|
|
230
|
+
/** Sync persisted anchor transforms into `#xr-state=<base64url>` for zero-backend link sharing. */
|
|
231
|
+
'persist-url-hash'?: boolean | string;
|
|
232
|
+
/** Spatial plugin: XR locomotion mode ("teleport", "snap-turn", "smooth", "teleport snap-turn", "none"). */
|
|
233
|
+
'locomotion'?: boolean | string;
|
|
234
|
+
/** Thumbstick snap-turn increment in degrees (default: 30). */
|
|
235
|
+
'snap-turn-deg'?: number | string;
|
|
236
|
+
/** Show a 120ms peripheral FOV comfort vignette on teleport/turn (default: true). */
|
|
237
|
+
'comfort-vignette'?: boolean | string;
|
|
238
|
+
/** Spatial plugin: join a multi-user room via BroadcastChannel ID or `wss://` relay URL. */
|
|
239
|
+
'shared-room'?: string;
|
|
240
|
+
/** Local display name broadcast to peers in `shared-room` (max 32 chars). */
|
|
241
|
+
'peer-name'?: string;
|
|
242
|
+
/** Local avatar visor & laser color (`#rrggbb`) in `shared-room`. */
|
|
243
|
+
'peer-color'?: string;
|
|
244
|
+
/** Register WebMCP browser AI tools on `navigator.modelContext`. */
|
|
245
|
+
'webmcp'?: boolean | string;
|
|
246
|
+
/** Opt-in gate allowing WebMCP `capture_xr_view` to include the 8x8 depth grid. */
|
|
247
|
+
'webmcp-allow-depth'?: boolean | string;
|
|
248
|
+
/** Omit `headPosition` from WebMCP `inspect_xr_scene` responses. */
|
|
249
|
+
'webmcp-omit-pose'?: boolean | string;
|
|
250
|
+
|
|
198
251
|
'onxr-object-detected'?: (e: CustomEvent<Detection3D>) => void;
|
|
199
252
|
'onxr-transcription'?: (e: CustomEvent<TranscriptEvent>) => void;
|
|
200
253
|
'onxr-hold-to-ask'?: (
|
|
201
254
|
e: CustomEvent<{mesh: string; transcript: string; prompt: string}>,
|
|
202
255
|
) => void;
|
|
203
256
|
'onxr-handles-change'?: (
|
|
204
|
-
e: CustomEvent<{mesh:
|
|
257
|
+
e: CustomEvent<{mesh: any; scale: number; yawDeg: number}>,
|
|
205
258
|
) => void;
|
|
206
259
|
'onxr-paint-stroke'?: (
|
|
207
260
|
e: CustomEvent<{index: number; points: number; lengthMeters: number}>,
|
|
208
261
|
) => void;
|
|
262
|
+
onmeasurecomplete?: (
|
|
263
|
+
e: CustomEvent<{
|
|
264
|
+
start: [number, number, number];
|
|
265
|
+
end: [number, number, number];
|
|
266
|
+
distanceMeters: number;
|
|
267
|
+
formatted: string;
|
|
268
|
+
}>,
|
|
269
|
+
) => void;
|
|
270
|
+
onxrsnap?: (
|
|
271
|
+
e: CustomEvent<{
|
|
272
|
+
node: any;
|
|
273
|
+
socket: any;
|
|
274
|
+
position: [number, number, number];
|
|
275
|
+
quaternion: [number, number, number, number];
|
|
276
|
+
mode: 'socket' | 'grid' | 'surface' | 'angle';
|
|
277
|
+
}>,
|
|
278
|
+
) => void;
|
|
279
|
+
onxrunsnap?: (e: CustomEvent<{node: any; socket: any}>) => void;
|
|
280
|
+
ongazeenter?: (
|
|
281
|
+
e: CustomEvent<{node: any; point: [number, number, number]}>,
|
|
282
|
+
) => void;
|
|
283
|
+
ongazeleave?: (e: CustomEvent<{node: any}>) => void;
|
|
284
|
+
ongazedwell?: (
|
|
285
|
+
e: CustomEvent<{
|
|
286
|
+
node: any;
|
|
287
|
+
point: [number, number, number];
|
|
288
|
+
action: 'select' | 'ask';
|
|
289
|
+
}>,
|
|
290
|
+
) => void;
|
|
291
|
+
onexplodechange?: (
|
|
292
|
+
e: CustomEvent<{
|
|
293
|
+
factor: number;
|
|
294
|
+
source: 'attribute' | 'gesture' | 'api' | 'peer';
|
|
295
|
+
}>,
|
|
296
|
+
) => void;
|
|
297
|
+
onanchorsrestored?: (
|
|
298
|
+
e: CustomEvent<{
|
|
299
|
+
count: number;
|
|
300
|
+
source: 'xr-anchor' | 'storage' | 'url-hash';
|
|
301
|
+
}>,
|
|
302
|
+
) => void;
|
|
303
|
+
onxrteleport?: (
|
|
304
|
+
e: CustomEvent<{
|
|
305
|
+
from: [number, number, number];
|
|
306
|
+
to: [number, number, number];
|
|
307
|
+
yawDeg: number;
|
|
308
|
+
}>,
|
|
309
|
+
) => void;
|
|
310
|
+
onpeerjoin?: (
|
|
311
|
+
e: CustomEvent<Pick<RemotePeerState, 'peerId' | 'name' | 'color'>>,
|
|
312
|
+
) => void;
|
|
313
|
+
onpeerleave?: (
|
|
314
|
+
e: CustomEvent<Pick<RemotePeerState, 'peerId' | 'name' | 'color'>>,
|
|
315
|
+
) => void;
|
|
316
|
+
onpeersync?: (e: CustomEvent<{peerId: string; nodeId: string}>) => void;
|
|
317
|
+
onpeergrabconflict?: (e: CustomEvent<{peerId: string; nodeId: string}>) => void;
|
|
209
318
|
}
|
|
210
319
|
|
|
211
320
|
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
|
|
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[${
|
|
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 < ${
|
|
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,
|
|
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
|
|
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
|
|
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[${
|
|
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 < ${
|
|
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,
|
|
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
|
|
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);})();
|