@shopware-ag/dive 1.18.5-beta.2 → 1.18.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/build/dive.cjs +3856 -1
- package/build/dive.cjs.map +1 -1
- package/build/dive.js +24728 -6
- package/build/dive.js.map +1 -1
- package/build/src/ar/arquicklook/ARQuickLook.d.ts +2 -3
- package/build/src/com/Communication.d.ts +1 -4
- package/build/src/module/Module.d.ts +8 -0
- package/package.json +2 -2
- package/src/ar/arquicklook/ARQuickLook.ts +75 -48
- package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +45 -80
- package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -12
- package/src/com/Communication.ts +17 -84
- package/src/com/__test__/Communication.test.ts +43 -16
- package/src/module/Module.ts +45 -0
- package/src/module/__test__/Module.test.ts +54 -0
- package/build/AR-B-g0updz.js +0 -1450
- package/build/AR-B-g0updz.js.map +0 -1
- package/build/AR-BWQebw6-.cjs +0 -153
- package/build/AR-BWQebw6-.cjs.map +0 -1
- package/build/IO-BgiJzKrU.js +0 -1257
- package/build/IO-BgiJzKrU.js.map +0 -1
- package/build/IO-CuYml7Y5.cjs +0 -2
- package/build/IO-CuYml7Y5.cjs.map +0 -1
- package/build/MediaCreator-4zmvmUWH.js +0 -22
- package/build/MediaCreator-4zmvmUWH.js.map +0 -1
- package/build/MediaCreator-BNxZVYyZ.cjs +0 -2
- package/build/MediaCreator-BNxZVYyZ.cjs.map +0 -1
- package/build/TextureUtils-CxpuVgwF.js +0 -38
- package/build/TextureUtils-CxpuVgwF.js.map +0 -1
- package/build/TextureUtils-DNG-yR77.cjs +0 -19
- package/build/TextureUtils-DNG-yR77.cjs.map +0 -1
- package/build/dive-Mi8g8Khn.js +0 -24852
- package/build/dive-Mi8g8Khn.js.map +0 -1
- package/build/dive-_-yiZbhn.cjs +0 -3857
- package/build/dive-_-yiZbhn.cjs.map +0 -1
package/build/AR-BWQebw6-.cjs
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./dive-_-yiZbhn.cjs"),Ft=require("./TextureUtils-DNG-yR77.cjs");function qt(e,t){return e?t in e:!1}function It(e,t){if(e)return qt(e,t)?e:It(e.parent,t)}/*!
|
|
2
|
-
fflate - fast JavaScript compression/decompression
|
|
3
|
-
<https://101arrowz.github.io/fflate>
|
|
4
|
-
Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
|
|
5
|
-
version 0.8.2
|
|
6
|
-
*/var T=Uint8Array,D=Uint16Array,gt=Int32Array,mt=new T([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Rt=new T([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),bt=new T([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Dt=function(e,t){for(var i=new D(31),r=0;r<31;++r)i[r]=t+=1<<e[r-1];for(var s=new gt(i[30]),r=1;r<30;++r)for(var n=i[r];n<i[r+1];++n)s[n]=n-i[r]<<5|r;return{b:i,r:s}},Ot=Dt(mt,2),Gt=Ot.b,lt=Ot.r;Gt[28]=258,lt[258]=28;var Qt=Dt(Rt,0),Et=Qt.r,ut=new D(32768);for(var R=0;R<32768;++R){var W=(R&43690)>>1|(R&21845)<<1;W=(W&52428)>>2|(W&13107)<<2,W=(W&61680)>>4|(W&3855)<<4,ut[R]=((W&65280)>>8|(W&255)<<8)>>1}var tt=function(e,t,i){for(var r=e.length,s=0,n=new D(t);s<r;++s)e[s]&&++n[e[s]-1];var o=new D(t);for(s=1;s<t;++s)o[s]=o[s-1]+n[s-1]<<1;var h;if(i){h=new D(1<<t);var c=15-t;for(s=0;s<r;++s)if(e[s])for(var u=s<<4|e[s],a=t-e[s],l=o[e[s]-1]++<<a,_=l|(1<<a)-1;l<=_;++l)h[ut[l]>>c]=u}else for(h=new D(r),s=0;s<r;++s)e[s]&&(h[s]=ut[o[e[s]-1]++]>>15-e[s]);return h},F=new T(288);for(var R=0;R<144;++R)F[R]=8;for(var R=144;R<256;++R)F[R]=9;for(var R=256;R<280;++R)F[R]=7;for(var R=280;R<288;++R)F[R]=8;var it=new T(32);for(var R=0;R<32;++R)it[R]=5;var Yt=tt(F,9,0),Zt=tt(it,5,0),Xt=function(e){return(e+7)/8|0},Vt=function(e,t,i){return(i==null||i>e.length)&&(i=e.length),new T(e.subarray(t,i))},Jt=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],st=function(e,t,i){var r=new Error(t||Jt[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,st),!i)throw r;return r},j=function(e,t,i){i<<=t&7;var r=t/8|0;e[r]|=i,e[r+1]|=i>>8},J=function(e,t,i){i<<=t&7;var r=t/8|0;e[r]|=i,e[r+1]|=i>>8,e[r+2]|=i>>16},ht=function(e,t){for(var i=[],r=0;r<e.length;++r)e[r]&&i.push({s:r,f:e[r]});var s=i.length,n=i.slice();if(!s)return{t:kt,l:0};if(s==1){var o=new T(i[0].s+1);return o[i[0].s]=1,{t:o,l:1}}i.sort(function(C,H){return C.f-H.f}),i.push({s:-1,f:25001});var h=i[0],c=i[1],u=0,a=1,l=2;for(i[0]={s:-1,f:h.f+c.f,l:h,r:c};a!=s-1;)h=i[i[u].f<i[l].f?u++:l++],c=i[u!=a&&i[u].f<i[l].f?u++:l++],i[a++]={s:-1,f:h.f+c.f,l:h,r:c};for(var _=n[0].s,r=1;r<s;++r)n[r].s>_&&(_=n[r].s);var d=new D(_+1),v=ft(i[a-1],d,0);if(v>t){var r=0,m=0,y=v-t,P=1<<y;for(n.sort(function(H,S){return d[S.s]-d[H.s]||H.f-S.f});r<s;++r){var O=n[r].s;if(d[O]>t)m+=P-(1<<v-d[O]),d[O]=t;else break}for(m>>=y;m>0;){var k=n[r].s;d[k]<t?m-=1<<t-d[k]++-1:++r}for(;r>=0&&m;--r){var w=n[r].s;d[w]==t&&(--d[w],++m)}v=t}return{t:new T(d),l:v}},ft=function(e,t,i){return e.s==-1?Math.max(ft(e.l,t,i+1),ft(e.r,t,i+1)):t[e.s]=i},Tt=function(e){for(var t=e.length;t&&!e[--t];);for(var i=new D(++t),r=0,s=e[0],n=1,o=function(c){i[r++]=c},h=1;h<=t;++h)if(e[h]==s&&h!=t)++n;else{if(!s&&n>2){for(;n>138;n-=138)o(32754);n>2&&(o(n>10?n-11<<5|28690:n-3<<5|12305),n=0)}else if(n>3){for(o(s),--n;n>6;n-=6)o(8304);n>2&&(o(n-3<<5|8208),n=0)}for(;n--;)o(s);n=1,s=e[h]}return{c:i.subarray(0,r),n:t}},K=function(e,t){for(var i=0,r=0;r<t.length;++r)i+=e[r]*t[r];return i},Ut=function(e,t,i){var r=i.length,s=Xt(t+2);e[s]=r&255,e[s+1]=r>>8,e[s+2]=e[s]^255,e[s+3]=e[s+1]^255;for(var n=0;n<r;++n)e[s+n+4]=i[n];return(s+4+r)*8},$t=function(e,t,i,r,s,n,o,h,c,u,a){j(t,a++,i),++s[256];for(var l=ht(s,15),_=l.t,d=l.l,v=ht(n,15),m=v.t,y=v.l,P=Tt(_),O=P.c,k=P.n,w=Tt(m),C=w.c,H=w.n,S=new D(19),g=0;g<O.length;++g)++S[O[g]&31];for(var g=0;g<C.length;++g)++S[C[g]&31];for(var p=ht(S,7),A=p.t,q=p.l,I=19;I>4&&!A[bt[I-1]];--I);var G=u+5<<3,X=K(s,F)+K(n,it)+o,V=K(s,_)+K(n,m)+o+14+3*I+K(S,A)+2*S[16]+3*S[17]+7*S[18];if(c>=0&&G<=X&&G<=V)return Ut(t,a,e.subarray(c,c+u));var L,x,U,N;if(j(t,a,1+(V<X)),a+=2,V<X){L=tt(_,d,0),x=_,U=tt(m,y,0),N=m;var nt=tt(A,q,0);j(t,a,k-257),j(t,a+5,H-1),j(t,a+10,I-4),a+=14;for(var g=0;g<I;++g)j(t,a+3*g,A[bt[g]]);a+=3*I;for(var z=[O,C],Z=0;Z<2;++Z)for(var Q=z[Z],g=0;g<Q.length;++g){var B=Q[g]&31;j(t,a,nt[B]),a+=A[B],B>15&&(j(t,a,Q[g]>>5&127),a+=Q[g]>>12)}}else L=Yt,x=F,U=Zt,N=it;for(var g=0;g<h;++g){var b=r[g];if(b>255){var B=b>>18&31;J(t,a,L[B+257]),a+=x[B+257],B>7&&(j(t,a,b>>23&31),a+=mt[B]);var Y=b&31;J(t,a,U[Y]),a+=N[Y],Y>3&&(J(t,a,b>>5&8191),a+=Rt[Y])}else J(t,a,L[b]),a+=x[b]}return J(t,a,L[256]),a+x[256]},Kt=new gt([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),kt=new T(0),te=function(e,t,i,r,s,n){var o=n.z||e.length,h=new T(r+o+5*(1+Math.ceil(o/7e3))+s),c=h.subarray(r,h.length-s),u=n.l,a=(n.r||0)&7;if(t){a&&(c[0]=n.r>>3);for(var l=Kt[t-1],_=l>>13,d=l&8191,v=(1<<i)-1,m=n.p||new D(32768),y=n.h||new D(v+1),P=Math.ceil(i/3),O=2*P,k=function(ct){return(e[ct]^e[ct+1]<<P^e[ct+2]<<O)&v},w=new gt(25e3),C=new D(288),H=new D(32),S=0,g=0,p=n.i||0,A=0,q=n.w||0,I=0;p+2<o;++p){var G=k(p),X=p&32767,V=y[G];if(m[X]=V,y[G]=X,q<=p){var L=o-p;if((S>7e3||A>24576)&&(L>423||!u)){a=$t(e,c,0,w,C,H,g,A,I,p-I,a),A=S=g=0,I=p;for(var x=0;x<286;++x)C[x]=0;for(var x=0;x<30;++x)H[x]=0}var U=2,N=0,nt=d,z=X-V&32767;if(L>2&&G==k(p-z))for(var Z=Math.min(_,L)-1,Q=Math.min(32767,p),B=Math.min(258,L);z<=Q&&--nt&&X!=V;){if(e[p+U]==e[p+U-z]){for(var b=0;b<B&&e[p+b]==e[p+b-z];++b);if(b>U){if(U=b,N=z,b>Z)break;for(var Y=Math.min(z,b-2),yt=0,x=0;x<Y;++x){var ot=p-z+x&32767,Wt=m[ot],wt=ot-Wt&32767;wt>yt&&(yt=wt,V=ot)}}}X=V,V=m[X],z+=X-V&32767}if(N){w[A++]=268435456|lt[U]<<18|Et[N];var xt=lt[U]&31,Mt=Et[N]&31;g+=mt[xt]+Rt[Mt],++C[257+xt],++H[Mt],q=p+U,++S}else w[A++]=e[p],++C[e[p]]}}for(p=Math.max(p,q);p<o;++p)w[A++]=e[p],++C[e[p]];a=$t(e,c,u,w,C,H,g,A,I,p-I,a),u||(n.r=a&7|c[a/8|0]<<3,a-=7,n.h=y,n.p=m,n.i=p,n.w=q)}else{for(var p=n.w||0;p<o+u;p+=65535){var at=p+65535;at>=o&&(c[a/8|0]=u,at=o),a=Ut(c,a+1,e.subarray(p,at))}n.i=o}return Vt(h,0,r+Xt(a)+s)},ee=function(){for(var e=new Int32Array(256),t=0;t<256;++t){for(var i=t,r=9;--r;)i=(i&1&&-306674912)^i>>>1;e[t]=i}return e}(),ie=function(){var e=-1;return{p:function(t){for(var i=e,r=0;r<t.length;++r)i=ee[i&255^t[r]]^i>>>8;e=i},d:function(){return~e}}},re=function(e,t,i,r,s){if(!s&&(s={l:1},t.dictionary)){var n=t.dictionary.subarray(-32768),o=new T(n.length+e.length);o.set(n),o.set(e,n.length),e=o,s.w=n.length}return te(e,t.level==null?6:t.level,t.mem==null?s.l?Math.ceil(Math.max(8,Math.min(13,Math.log(e.length)))*1.5):20:12+t.mem,i,r,s)},Lt=function(e,t){var i={};for(var r in e)i[r]=e[r];for(var r in t)i[r]=t[r];return i},M=function(e,t,i){for(;i;++t)e[t]=i,i>>>=8};function se(e,t){return re(e,t||{},0,0)}var zt=function(e,t,i,r){for(var s in e){var n=e[s],o=t+s,h=r;Array.isArray(n)&&(h=Lt(r,n[1]),n=n[0]),n instanceof T?i[o]=[n,h]:(i[o+="/"]=[new T(0),h],zt(n,o,i,r))}},Ct=typeof TextEncoder<"u"&&new TextEncoder,ne=typeof TextDecoder<"u"&&new TextDecoder,oe=0;try{ne.decode(kt,{stream:!0}),oe=1}catch{}function rt(e,t){var i;if(Ct)return Ct.encode(e);for(var r=e.length,s=new T(e.length+(e.length>>1)),n=0,o=function(u){s[n++]=u},i=0;i<r;++i){if(n+5>s.length){var h=new T(n+8+(r-i<<1));h.set(s),s=h}var c=e.charCodeAt(i);c<128||t?o(c):c<2048?(o(192|c>>6),o(128|c&63)):c>55295&&c<57344?(c=65536+(c&1047552)|e.charCodeAt(++i)&1023,o(240|c>>18),o(128|c>>12&63),o(128|c>>6&63),o(128|c&63)):(o(224|c>>12),o(128|c>>6&63),o(128|c&63))}return Vt(s,0,n)}var dt=function(e){var t=0;if(e)for(var i in e){var r=e[i].length;r>65535&&st(9),t+=r+4}return t},Pt=function(e,t,i,r,s,n,o,h){var c=r.length,u=i.extra,a=h&&h.length,l=dt(u);M(e,t,o!=null?33639248:67324752),t+=4,o!=null&&(e[t++]=20,e[t++]=i.os),e[t]=20,t+=2,e[t++]=i.flag<<1|(n<0&&8),e[t++]=s&&8,e[t++]=i.compression&255,e[t++]=i.compression>>8;var _=new Date(i.mtime==null?Date.now():i.mtime),d=_.getFullYear()-1980;if((d<0||d>119)&&st(10),M(e,t,d<<25|_.getMonth()+1<<21|_.getDate()<<16|_.getHours()<<11|_.getMinutes()<<5|_.getSeconds()>>1),t+=4,n!=-1&&(M(e,t,i.crc),M(e,t+4,n<0?-n-2:n),M(e,t+8,i.size)),M(e,t+12,c),M(e,t+14,l),t+=16,o!=null&&(M(e,t,a),M(e,t+6,i.attrs),M(e,t+10,o),t+=14),e.set(r,t),t+=c,l)for(var v in u){var m=u[v],y=m.length;M(e,t,+v),M(e,t+2,y),e.set(m,t+4),t+=4+y}return a&&(e.set(h,t),t+=a),t},ae=function(e,t,i,r,s){M(e,t,101010256),M(e,t+8,i),M(e,t+10,i),M(e,t+12,r),M(e,t+16,s)};function ce(e,t){t||(t={});var i={},r=[];zt(e,"",i,t);var s=0,n=0;for(var o in i){var h=i[o],c=h[0],u=h[1],a=u.level==0?0:8,l=rt(o),_=l.length,d=u.comment,v=d&&rt(d),m=v&&v.length,y=dt(u.extra);_>65535&&st(11);var P=a?se(c,u):c,O=P.length,k=ie();k.p(c),r.push(Lt(u,{size:c.length,crc:k.d(),c:P,f:l,m:v,u:_!=o.length||v&&d.length!=m,o:s,compression:a})),s+=30+_+y+O,n+=76+2*(_+y)+(m||0)+O}for(var w=new T(n+22),C=s,H=n-s,S=0;S<r.length;++S){var l=r[S];Pt(w,l.o,l,l.f,l.u,l.c.length);var g=30+l.f.length+dt(l.extra);w.set(l.c,l.o+g),Pt(w,s,l,l.f,l.u,l.c.length,l.o,l.m),s+=16+g+(l.m?l.m.length:0)}return ae(w,s,r.length,H,C),w}class he{async parse(t,i={}){i=Object.assign({ar:{anchoring:{type:"plane"},planeAnchoring:{alignment:"horizontal"}},quickLookCompatible:!1,maxTextureSize:1024},i);const r={},s="model.usda";r[s]=null;let n=Bt();n+=ue(i);const o={},h={};t.traverseVisible(u=>{if(u.isMesh){const a=u.geometry,l=u.material;if(l.isMeshStandardMaterial){const _="geometries/Geometry_"+a.id+".usda";if(!(_ in r)){const d=pe(a);r[_]=de(d)}l.uuid in o||(o[l.uuid]=l),n+=_e(u,a,l)}else console.warn("THREE.USDZExporter: Unsupported material type (USDZ only supports MeshStandardMaterial)",u)}else u.isCamera&&(n+=Me(u))}),n+=fe(),n+=ye(o,h,i.quickLookCompatible),r[s]=rt(n),n=null;for(const u in h){let a=h[u];a.isCompressedTexture===!0&&(a=Ft.decompress(a));const l=le(a.image,a.flipY,i.maxTextureSize),_=await new Promise(d=>l.toBlob(d,"image/png",1));r[`textures/Texture_${u}.png`]=new Uint8Array(await _.arrayBuffer())}let c=0;for(const u in r){const a=r[u],l=34+u.length;c+=l;const _=c&63;if(_!==4){const d=64-_,v=new Uint8Array(d);r[u]=[a,{extra:{12345:v}}]}c=a.length}return ce(r,{level:0})}}function le(e,t,i){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const r=i/Math.max(e.width,e.height),s=document.createElement("canvas");s.width=e.width*Math.min(1,r),s.height=e.height*Math.min(1,r);const n=s.getContext("2d");return t===!0&&(n.translate(0,s.height),n.scale(1,-1)),n.drawImage(e,0,0,s.width,s.height),s}else throw new Error("THREE.USDZExporter: No valid image data found. Unable to process texture.")}const E=7;function Bt(){return`#usda 1.0
|
|
7
|
-
(
|
|
8
|
-
customLayerData = {
|
|
9
|
-
string creator = "Three.js USDZExporter"
|
|
10
|
-
}
|
|
11
|
-
defaultPrim = "Root"
|
|
12
|
-
metersPerUnit = 1
|
|
13
|
-
upAxis = "Y"
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
`}function ue(e){return`def Xform "Root"
|
|
17
|
-
{
|
|
18
|
-
def Scope "Scenes" (
|
|
19
|
-
kind = "sceneLibrary"
|
|
20
|
-
)
|
|
21
|
-
{
|
|
22
|
-
def Xform "Scene" (
|
|
23
|
-
customData = {
|
|
24
|
-
bool preliminary_collidesWithEnvironment = 0
|
|
25
|
-
string sceneName = "Scene"
|
|
26
|
-
}
|
|
27
|
-
sceneName = "Scene"
|
|
28
|
-
)
|
|
29
|
-
{
|
|
30
|
-
token preliminary:anchoring:type = "${e.ar.anchoring.type}"
|
|
31
|
-
token preliminary:planeAnchoring:alignment = "${e.ar.planeAnchoring.alignment}"
|
|
32
|
-
|
|
33
|
-
`}function fe(){return`
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
`}function de(e){let t=Bt();return t+=e,rt(t)}function _e(e,t,i){const r="Object_"+e.id,s=jt(e.matrixWorld);return e.matrixWorld.determinant()<0&&console.warn("THREE.USDZExporter: USDZ does not support negative scales",e),`def Xform "${r}" (
|
|
39
|
-
prepend references = @./geometries/Geometry_${t.id}.usda@</Geometry>
|
|
40
|
-
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
41
|
-
)
|
|
42
|
-
{
|
|
43
|
-
matrix4d xformOp:transform = ${s}
|
|
44
|
-
uniform token[] xformOpOrder = ["xformOp:transform"]
|
|
45
|
-
|
|
46
|
-
rel material:binding = </Materials/Material_${i.id}>
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
`}function jt(e){const t=e.elements;return`( ${et(t,0)}, ${et(t,4)}, ${et(t,8)}, ${et(t,12)} )`}function et(e,t){return`(${e[t+0]}, ${e[t+1]}, ${e[t+2]}, ${e[t+3]})`}function pe(e){return`
|
|
50
|
-
def "Geometry"
|
|
51
|
-
{
|
|
52
|
-
${ve(e)}
|
|
53
|
-
}
|
|
54
|
-
`}function ve(e){const t="Geometry",i=e.attributes,r=i.position.count;return`
|
|
55
|
-
def Mesh "${t}"
|
|
56
|
-
{
|
|
57
|
-
int[] faceVertexCounts = [${ge(e)}]
|
|
58
|
-
int[] faceVertexIndices = [${me(e)}]
|
|
59
|
-
normal3f[] normals = [${_t(i.normal,r)}] (
|
|
60
|
-
interpolation = "vertex"
|
|
61
|
-
)
|
|
62
|
-
point3f[] points = [${_t(i.position,r)}]
|
|
63
|
-
${Se(i)}
|
|
64
|
-
uniform token subdivisionScheme = "none"
|
|
65
|
-
}
|
|
66
|
-
`}function ge(e){const t=e.index!==null?e.index.count:e.attributes.position.count;return Array(t/3).fill(3).join(", ")}function me(e){const t=e.index,i=[];if(t!==null)for(let r=0;r<t.count;r++)i.push(t.getX(r));else{const r=e.attributes.position.count;for(let s=0;s<r;s++)i.push(s)}return i.join(", ")}function _t(e,t){if(e===void 0)return console.warn("USDZExporter: Normals missing."),Array(t).fill("(0, 0, 0)").join(", ");const i=[];for(let r=0;r<e.count;r++){const s=e.getX(r),n=e.getY(r),o=e.getZ(r);i.push(`(${s.toPrecision(E)}, ${n.toPrecision(E)}, ${o.toPrecision(E)})`)}return i.join(", ")}function Re(e){const t=[];for(let i=0;i<e.count;i++){const r=e.getX(i),s=e.getY(i);t.push(`(${r.toPrecision(E)}, ${1-s.toPrecision(E)})`)}return t.join(", ")}function Se(e){let t="";for(let r=0;r<4;r++){const s=r>0?r:"",n=e["uv"+s];n!==void 0&&(t+=`
|
|
67
|
-
texCoord2f[] primvars:st${s} = [${Re(n)}] (
|
|
68
|
-
interpolation = "vertex"
|
|
69
|
-
)`)}const i=e.color;if(i!==void 0){const r=i.count;t+=`
|
|
70
|
-
color3f[] primvars:displayColor = [${_t(i,r)}] (
|
|
71
|
-
interpolation = "vertex"
|
|
72
|
-
)`}return t}function ye(e,t,i=!1){const r=[];for(const s in e){const n=e[s];r.push(we(n,t,i))}return`def "Materials"
|
|
73
|
-
{
|
|
74
|
-
${r.join("")}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
`}function we(e,t,i=!1){const r=" ",s=[],n=[];function o(h,c,u){const a=h.source.id+"_"+h.flipY;t[a]=h;const l=h.channel>0?"st"+h.channel:"st",_={1e3:"repeat",1001:"clamp",1002:"mirror"},d=h.repeat.clone(),v=h.offset.clone(),m=h.rotation,y=Math.sin(m),P=Math.cos(m);return v.y=1-v.y-d.y,i?(v.x=v.x/d.x,v.y=v.y/d.y,v.x+=y/d.x,v.y+=P-1):(v.x+=y*d.x,v.y+=(1-P)*d.y),`
|
|
78
|
-
def Shader "PrimvarReader_${c}"
|
|
79
|
-
{
|
|
80
|
-
uniform token info:id = "UsdPrimvarReader_float2"
|
|
81
|
-
float2 inputs:fallback = (0.0, 0.0)
|
|
82
|
-
token inputs:varname = "${l}"
|
|
83
|
-
float2 outputs:result
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
def Shader "Transform2d_${c}"
|
|
87
|
-
{
|
|
88
|
-
uniform token info:id = "UsdTransform2d"
|
|
89
|
-
token inputs:in.connect = </Materials/Material_${e.id}/PrimvarReader_${c}.outputs:result>
|
|
90
|
-
float inputs:rotation = ${(m*(180/Math.PI)).toFixed(E)}
|
|
91
|
-
float2 inputs:scale = ${At(d)}
|
|
92
|
-
float2 inputs:translation = ${At(v)}
|
|
93
|
-
float2 outputs:result
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
def Shader "Texture_${h.id}_${c}"
|
|
97
|
-
{
|
|
98
|
-
uniform token info:id = "UsdUVTexture"
|
|
99
|
-
asset inputs:file = @textures/Texture_${a}.png@
|
|
100
|
-
float2 inputs:st.connect = </Materials/Material_${e.id}/Transform2d_${c}.outputs:result>
|
|
101
|
-
${u!==void 0?"float4 inputs:scale = "+xe(u):""}
|
|
102
|
-
token inputs:sourceColorSpace = "${h.colorSpace===f.NoColorSpace?"raw":"sRGB"}"
|
|
103
|
-
token inputs:wrapS = "${_[h.wrapS]}"
|
|
104
|
-
token inputs:wrapT = "${_[h.wrapT]}"
|
|
105
|
-
float outputs:r
|
|
106
|
-
float outputs:g
|
|
107
|
-
float outputs:b
|
|
108
|
-
float3 outputs:rgb
|
|
109
|
-
${e.transparent||e.alphaTest>0?"float outputs:a":""}
|
|
110
|
-
}`}return e.side===f.DoubleSide&&console.warn("THREE.USDZExporter: USDZ does not support double sided materials",e),e.map!==null?(s.push(`${r}color3f inputs:diffuseColor.connect = </Materials/Material_${e.id}/Texture_${e.map.id}_diffuse.outputs:rgb>`),e.transparent?s.push(`${r}float inputs:opacity.connect = </Materials/Material_${e.id}/Texture_${e.map.id}_diffuse.outputs:a>`):e.alphaTest>0&&(s.push(`${r}float inputs:opacity.connect = </Materials/Material_${e.id}/Texture_${e.map.id}_diffuse.outputs:a>`),s.push(`${r}float inputs:opacityThreshold = ${e.alphaTest}`)),n.push(o(e.map,"diffuse",e.color))):s.push(`${r}color3f inputs:diffuseColor = ${Ht(e.color)}`),e.emissiveMap!==null?(s.push(`${r}color3f inputs:emissiveColor.connect = </Materials/Material_${e.id}/Texture_${e.emissiveMap.id}_emissive.outputs:rgb>`),n.push(o(e.emissiveMap,"emissive"))):e.emissive.getHex()>0&&s.push(`${r}color3f inputs:emissiveColor = ${Ht(e.emissive)}`),e.normalMap!==null&&(s.push(`${r}normal3f inputs:normal.connect = </Materials/Material_${e.id}/Texture_${e.normalMap.id}_normal.outputs:rgb>`),n.push(o(e.normalMap,"normal"))),e.aoMap!==null&&(s.push(`${r}float inputs:occlusion.connect = </Materials/Material_${e.id}/Texture_${e.aoMap.id}_occlusion.outputs:r>`),n.push(o(e.aoMap,"occlusion"))),e.roughnessMap!==null&&e.roughness===1?(s.push(`${r}float inputs:roughness.connect = </Materials/Material_${e.id}/Texture_${e.roughnessMap.id}_roughness.outputs:g>`),n.push(o(e.roughnessMap,"roughness"))):s.push(`${r}float inputs:roughness = ${e.roughness}`),e.metalnessMap!==null&&e.metalness===1?(s.push(`${r}float inputs:metallic.connect = </Materials/Material_${e.id}/Texture_${e.metalnessMap.id}_metallic.outputs:b>`),n.push(o(e.metalnessMap,"metallic"))):s.push(`${r}float inputs:metallic = ${e.metalness}`),e.alphaMap!==null?(s.push(`${r}float inputs:opacity.connect = </Materials/Material_${e.id}/Texture_${e.alphaMap.id}_opacity.outputs:r>`),s.push(`${r}float inputs:opacityThreshold = 0.0001`),n.push(o(e.alphaMap,"opacity"))):s.push(`${r}float inputs:opacity = ${e.opacity}`),e.isMeshPhysicalMaterial&&(s.push(`${r}float inputs:clearcoat = ${e.clearcoat}`),s.push(`${r}float inputs:clearcoatRoughness = ${e.clearcoatRoughness}`),s.push(`${r}float inputs:ior = ${e.ior}`)),`
|
|
111
|
-
def Material "Material_${e.id}"
|
|
112
|
-
{
|
|
113
|
-
def Shader "PreviewSurface"
|
|
114
|
-
{
|
|
115
|
-
uniform token info:id = "UsdPreviewSurface"
|
|
116
|
-
${s.join(`
|
|
117
|
-
`)}
|
|
118
|
-
int inputs:useSpecularWorkflow = 0
|
|
119
|
-
token outputs:surface
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
token outputs:surface.connect = </Materials/Material_${e.id}/PreviewSurface.outputs:surface>
|
|
123
|
-
|
|
124
|
-
${n.join(`
|
|
125
|
-
`)}
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
`}function Ht(e){return`(${e.r}, ${e.g}, ${e.b})`}function xe(e){return`(${e.r}, ${e.g}, ${e.b}, 1.0)`}function At(e){return`(${e.x}, ${e.y})`}function Me(e){const t=e.name?e.name:"Camera_"+e.id,i=jt(e.matrixWorld);return e.matrixWorld.determinant()<0&&console.warn("THREE.USDZExporter: USDZ does not support negative scales",e),e.isOrthographicCamera?`def Camera "${t}"
|
|
129
|
-
{
|
|
130
|
-
matrix4d xformOp:transform = ${i}
|
|
131
|
-
uniform token[] xformOpOrder = ["xformOp:transform"]
|
|
132
|
-
|
|
133
|
-
float2 clippingRange = (${e.near.toPrecision(E)}, ${e.far.toPrecision(E)})
|
|
134
|
-
float horizontalAperture = ${((Math.abs(e.left)+Math.abs(e.right))*10).toPrecision(E)}
|
|
135
|
-
float verticalAperture = ${((Math.abs(e.top)+Math.abs(e.bottom))*10).toPrecision(E)}
|
|
136
|
-
token projection = "orthographic"
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
`:`def Camera "${t}"
|
|
140
|
-
{
|
|
141
|
-
matrix4d xformOp:transform = ${i}
|
|
142
|
-
uniform token[] xformOpOrder = ["xformOp:transform"]
|
|
143
|
-
|
|
144
|
-
float2 clippingRange = (${e.near.toPrecision(E)}, ${e.far.toPrecision(E)})
|
|
145
|
-
float focalLength = ${e.getFocalLength().toPrecision(E)}
|
|
146
|
-
float focusDistance = ${e.focus.toPrecision(E)}
|
|
147
|
-
float horizontalAperture = ${e.getFilmWidth().toPrecision(E)}
|
|
148
|
-
token projection = "perspective"
|
|
149
|
-
float verticalAperture = ${e.getFilmHeight().toPrecision(E)}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
`}class be extends he{parse(t,i){return super.parse(t,i)}}const St=class St{static Launch(t,i){const r=new f.Object3D,s=t.Root.clone(!0);return r.add(...s.children),this.launchARFromNode(r,i)}static extractModels(t){return t.Root.children}static launchARFromNode(t,i){return this._usdzExporter.parse(t,{quickLookCompatible:!0,ar:{anchoring:{type:"plane"},planeAnchoring:{alignment:(i==null?void 0:i.arPlacement)==="vertical"?"vertical":"horizontal"}}}).then(r=>{const s=new Blob([r],{type:"model/vnd.usdz+zip"});let n=URL.createObjectURL(s);(i==null?void 0:i.arScale)==="fixed"&&(n=n.concat("#allowsContentScaling=0"));const o=document.createElement("a");o.innerHTML="<picture></picture>",o.rel="ar",o.href=n,o.download="scene.usdz",o.click()})}};St._usdzExporter=new be;let pt=St;class Ee{get Element(){return this._element}get CloseButton(){return this._closeButton}constructor(){this._element=document.createElement("div"),this._closeButton=this.createCloseButton(),this._element.appendChild(this._closeButton),document.body.appendChild(this._element)}createCloseButton(){const t=document.createElementNS("http://www.w3.org/2000/svg","path");t.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),t.setAttribute("stroke","#fff"),t.setAttribute("stroke-width","2");const i=document.createElementNS("http://www.w3.org/2000/svg","svg");return i.setAttribute("width","38"),i.setAttribute("height","38"),i.style.position="absolute",i.style.right="20px",i.style.top="20px",i.appendChild(t),i}}class Te extends f.Object3D{set mesh(t){this.clear(),t&&this.add(t)}constructor(t){return super(),t?this.mesh=t:this.UseDefaultMesh(),this.matrixAutoUpdate=!1,this}UseDefaultMesh(){const t=new f.RingGeometry(.08,.1,32).rotateX(-Math.PI/2),i=new f.MeshBasicMaterial;this.mesh=new f.Mesh(t,i)}UpdateFromPose(t){this.matrix.fromArray(t.transform.matrix)}}class $e{constructor(t,i){this._referenceSpaceBuffer=null,this._requesting=!1,this._initialized=!1,this._session=t,this._renderer=i,this._hitMatrixBuffer=new f.Matrix4}Dispose(){var t;(t=this._transientHitTestSource)==null||t.cancel(),this._transientHitTestSource=void 0,this._initialized=!1}async Init(){return this._session?this._requesting?(console.error("DIVEWebXRRaycaster: Currently initializing! Aborting initialization..."),Promise.reject()):this._initialized?(console.error("DIVEWebXRRaycaster: Already initialized! Aborting initialization..."),Promise.reject()):(this._requesting=!0,this._transientHitTestSource=await this._session.requestHitTestSourceForTransientInput({profile:"generic-touchscreen"}),this._referenceSpaceBuffer=this._renderer.xr.getReferenceSpace(),this._requesting=!1,this._transientHitTestSource?(this._initialized=!0,console.log("DIVEWebXRRaycasterAR: Initialized"),Promise.resolve(this)):Promise.reject()):(console.error("DIVEWebXRRaycaster: No session set in Init()! Aborting initialization..."),Promise.reject())}GetIntersections(t){if(!this._transientHitTestSource)return[];const i=t.getHitTestResultsForTransientInput(this._transientHitTestSource);return i.length===0?[]:i.map(s=>{if(!this._referenceSpaceBuffer||!s.results[0]||!s.results[0].getPose)return;const n=s.results[0].getPose(this._referenceSpaceBuffer);return n?(this._hitMatrixBuffer.fromArray(n.transform.matrix),{point:new f.Vector3().setFromMatrixPosition(this._hitMatrixBuffer),matrix:this._hitMatrixBuffer,object:void 0}):void 0}).filter(s=>s!==void 0)}}class Ce{constructor(t,i){this._raycaster=new f.Raycaster,this._renderer=t,this._scene=i,this._controller=this._renderer.xr.getController(0)}async Init(){return console.log("DIVEWebXRRaycasterTHREE: Initialized"),Promise.resolve(this)}GetIntersections(){this._controller.updateMatrixWorld(),this._raycaster.setFromXRController(this._controller);const t=this._raycaster.intersectObjects(this._scene.XRRoot.XRModelRoot.children);return t.length===0?[]:t.map(i=>({point:i.point,matrix:i.object.matrixWorld,object:i.object}))}}class Nt{constructor(){this._listeners=new Map}Subscribe(t,i){return this._listeners.get(t)||this._listeners.set(t,[]),this._listeners.get(t).push(i),()=>{const r=this._listeners.get(t);if(!r)return!1;const s=r.findIndex(n=>n===i);return s===-1?!1:(r.splice(s,1),!0)}}dispatch(t,i){const r=this._listeners.get(t);r&&r.forEach(s=>s(i))}}class Pe extends Nt{constructor(t,i,r){super(),this._initialized=!1,this._arHitResultBuffer=[],this._sceneHitResultBuffer=[],this._hasHit=!1,this._session=t,this._threeRaycaster=new Ce(i,r),this._arRaycaster=new $e(t,i)}Dispose(){this._initialized=!1}async Init(){return this._session?this._initialized?(console.error("DIVEWebXRRaycaster: Already initialized! Aborting initialization..."),Promise.reject()):(await this._threeRaycaster.Init(),await this._arRaycaster.Init(),console.log("DIVEWebXRRaycaster: Initialized"),this._initialized=!0,Promise.resolve(this)):(console.error("DIVEWebXRRaycaster: No session set in Init()! Aborting initialization..."),Promise.reject())}GetARIntersections(t){return this._arHitResultBuffer=this._arRaycaster.GetIntersections(t),this._arHitResultBuffer.length>0?this.onARHitFound(this._arHitResultBuffer[0]):this.onARHitLost(),this._arHitResultBuffer}GetSceneIntersections(){return this._sceneHitResultBuffer=this._threeRaycaster.GetIntersections(),this._sceneHitResultBuffer.length>0?this.onSceneHitFound(this._sceneHitResultBuffer[0]):this.onSceneHitLost(),this._sceneHitResultBuffer}onARHitFound(t){this._hasHit=!0,this.dispatch("AR_HIT_FOUND",{hit:t})}onARHitLost(){this._hasHit&&(this._hasHit=!1,this.dispatch("AR_HIT_LOST"))}onSceneHitFound(t){this._hasHit=!0,this.dispatch("SCENE_HIT_FOUND",{hit:t})}onSceneHitLost(){this._hasHit&&(this._hasHit=!1,this.dispatch("SCENE_HIT_LOST"))}}class He{constructor(t,i,r){this._raycastHitCounter=0,this._originSetResolve=()=>{},this._renderer=i,this._session=t,this._originSet=new Promise(s=>{this._originSetResolve=s}),this._requesting=!1,this._initialized=!1,this._referenceSpaceBuffer=null,this._hitTestSource=null,this._entityTypes=r||["plane"],this._hitTestResultBuffer=[],this._matrix=new f.Matrix4,this._position=new f.Vector3,this._quaternion=new f.Quaternion,this._scale=new f.Vector3,this._originSet.then(()=>{this._matrix.decompose(this._position,this._quaternion,this._scale)})}get originSet(){return this._originSet}get matrix(){return this._matrix}set matrix(t){this._matrix=t,this._matrix.decompose(this._position,this._quaternion,this._scale)}get position(){return this._position}get quaternion(){return this._quaternion}get scale(){return this._scale}async Init(){if(this._initialized)return Promise.resolve(this);if(!this._session)return console.error("DIVEWebXROrigin: No session set in Init()! Aborting initialization..."),Promise.reject();if(this._requesting)return console.error("DIVEWebXROrigin: Currently initializing! Aborting initialization..."),Promise.reject();this._requesting=!0;const t=await this._session.requestReferenceSpace("viewer");return this._hitTestSource=await this._session.requestHitTestSource({space:t,entityTypes:this._entityTypes})||null,this._requesting=!1,this._hitTestSource?(this._initialized=!0,Promise.resolve(this)):Promise.reject()}Dispose(){var t;this._initialized=!1,this._requesting=!1,(t=this._hitTestSource)==null||t.cancel(),this._hitTestSource=null,this._hitTestResultBuffer=[],this._matrix=new f.Matrix4,this._position=new f.Vector3,this._quaternion=new f.Quaternion,this._scale=new f.Vector3}Update(t){if(this._initialized){if(!this._hitTestSource)throw new Error("DIVEWebXRRaycaster: Critical Error: HitTestSource not available but WebXROrigin is initialized!");if(this._hitTestResultBuffer=t.getHitTestResults(this._hitTestSource),this._hitTestResultBuffer.length>0){if(this._referenceSpaceBuffer=this._renderer.xr.getReferenceSpace(),!this._referenceSpaceBuffer){this.onHitLost();return}const i=this._hitTestResultBuffer[0].getPose(this._referenceSpaceBuffer);if(!i){this.onHitLost();return}this.onHitFound(i)}else this.onHitLost()}}onHitFound(t){this._raycastHitCounter++,this.matrix.fromArray(t.transform.matrix),this._raycastHitCounter>50&&this._originSetResolve()}onHitLost(){this._raycastHitCounter=0}}class Ae extends Nt{constructor(t){super(),this._touchCount=0,this._touches=[],this._handleRotateStarted=!1,this._handleRotateMoved=!1,this._handleRotateEnded=!1,this._startAngle=0,this._lastAngle=0,this._angleDelta=0,this._handlePinchStarted=!1,this._handlePinchMoved=!1,this._handlePinchEnded=!1,this._scaleDistanceStart=0,this._currentDistance=1,this._deltaDistance=0,this._session=t,this._touches=[{start:new f.Vector2,current:new f.Vector2,delta:new f.Vector2},{start:new f.Vector2,current:new f.Vector2,delta:new f.Vector2}],this._handleRotateStarted=!1,window.addEventListener("touchstart",i=>this.onTouchStart(i)),window.addEventListener("touchmove",i=>this.onTouchMove(i)),window.addEventListener("touchend",i=>this.onTouchEnd(i)),this._session.addEventListener("selectstart",()=>this.onSessionSelectStart()),this._session.addEventListener("selectend",()=>this.onSessionSelectEnd())}Dispose(){window.removeEventListener("touchstart",t=>this.onTouchStart(t)),window.removeEventListener("touchmove",t=>this.onTouchMove(t)),window.removeEventListener("touchend",t=>this.onTouchEnd(t)),this._session.removeEventListener("selectstart",()=>this.onSessionSelectStart()),this._session.removeEventListener("selectend",()=>this.onSessionSelectEnd())}onTouchStart(t){this._touchCount=t.touches.length,this._touches[0].start.set(t.touches[0].clientX,t.touches[0].clientY),this._touches[0].current.set(t.touches[0].clientX,t.touches[0].clientY),this._touches[0].delta.set(0,0),this._touchCount>1&&(this._touches[1].start.set(t.touches[1].clientX,t.touches[1].clientY),this._touches[1].current.set(t.touches[1].clientX,t.touches[1].clientY),this._touches[1].delta.set(0,0)),this._touchCount===2&&(this.handleRotateStart(),this.handlePinchStart()),this._handleRotateStarted&&(this.dispatch("ROTATE_START",{current:0}),this._handleRotateStarted=!1),this._handlePinchStarted&&(this.dispatch("PINCH_START",{current:0}),this._handlePinchStarted=!1)}onTouchMove(t){this._touchCount=t.touches.length,this._touches[0].start.set(t.touches[0].clientX,t.touches[0].clientY),this._touches[0].current.set(t.touches[0].clientX,t.touches[0].clientY),this._touches[0].delta.copy(this._touches[0].current.clone().sub(this._touches[0].start)),this._touchCount>1&&(this._touches[1].start.set(t.touches[1].clientX,t.touches[1].clientY),this._touches[1].current.set(t.touches[1].clientX,t.touches[1].clientY),this._touches[1].delta.copy(this._touches[1].current.clone().sub(this._touches[1].start))),this._touchCount===2&&(this.handleRotateMoved(),this.handlePinchMoved()),this._touchCount===1&&this.dispatch("TOUCH_MOVE",{touches:[{current:this._touches[0].current.clone(),delta:this._touches[0].delta.clone()},{current:this._touches[1].current.clone(),delta:this._touches[1].delta.clone()}],touchCount:this._touchCount}),this._touchCount===2&&(this._handleRotateMoved&&(this.dispatch("ROTATE_MOVE",{current:this._lastAngle,delta:this._angleDelta}),this._handleRotateMoved=!1),this._handlePinchMoved&&(this.dispatch("PINCH_MOVE",{current:this._currentDistance,delta:this._deltaDistance}),this._handlePinchMoved=!1))}onTouchEnd(t){this._touchCount=t.touches.length,this._touchCount===0&&(this._touches[0].start.set(0,0),this._touches[0].current.set(0,0),this._touches[0].delta.set(0,0)),this._touchCount===1&&(this.handleRotateEnded(),this.handlePinchEnded(),this._touches[1].start.set(0,0),this._touches[1].current.set(0,0),this._touches[1].delta.set(0,0)),this._handleRotateEnded&&(this.dispatch("ROTATE_END",{current:this._lastAngle}),this._handleRotateEnded=!1),this._handlePinchEnded&&(this.dispatch("PINCH_END",{current:this._currentDistance}),this._handlePinchEnded=!1)}onSessionSelectStart(){this.dispatch("TOUCH_START",{touches:[{current:this._touches[0].current.clone()},{current:this._touches[1].current.clone()}],touchCount:this._touchCount})}onSessionSelectEnd(){this.dispatch("TOUCH_END",{touches:[{current:this._touches[0].current.clone()},{current:this._touches[1].current.clone()}],touchCount:this._touchCount})}handleRotateStart(){this._handleRotateStarted=!0,this._startAngle=this._touches[1].start.clone().sub(this._touches[0].current).angle()}handleRotateMoved(){this._handleRotateMoved=!0;const t=this._touches[1].current.clone().sub(this._touches[0].current).angle();this._angleDelta=t-this._startAngle,this._lastAngle=this._angleDelta*-1}handleRotateEnded(){this._handleRotateEnded=!0}handlePinchStart(){this._handlePinchStarted=!0,this._scaleDistanceStart=this._touches[1].start.distanceTo(this._touches[0].current)}handlePinchMoved(){this._handlePinchMoved=!0;const t=this._currentDistance,i=this._touches[1].current.distanceTo(this._touches[0].current);this._currentDistance=i/this._scaleDistanceStart,this._deltaDistance=this._currentDistance-t}handlePinchEnded(){this._handlePinchEnded=!0}}class Ie extends f.Object3D{constructor(t,i,r){super(),this._frameBuffer=null,this._handNodeInitialPosition=new f.Vector3,this._placed=!1,this._grabbedObject=null,this._arHitPosition=new f.Vector3,this._arHitQuaternion=new f.Quaternion,this._arHitScale=new f.Vector3(1,1,1),this._initialObjectPosition=null,this._initialRaycastHit=null,this._deltaRaycastHit=new f.Vector3,this._touchQuaterion=new f.Quaternion,this._touchScale=1,this._scaleThreshold=.1,this._startTouchQuaternion=new f.Quaternion,this._startTouchScale=1,this._renderer=i,this._scene=r,this._session=t,this._xrRaycaster=new Pe(t,i,r),this._origin=new He(this._session,this._renderer,["plane"]),this._crosshair=new Te,this._crosshair.visible=!1,this._xrCamera=this._renderer.xr.getCamera(),this._scene.XRRoot.XRHandNode.position.set(0,-.05,-.25),this._handNodeInitialPosition=this._scene.XRRoot.XRHandNode.position.clone(),this._touchscreenControls=new Ae(this._session),this._touchscreenControls.Subscribe("TOUCH_START",()=>this.onTouchStart()),this._touchscreenControls.Subscribe("TOUCH_MOVE",()=>this.onTouchMove()),this._touchscreenControls.Subscribe("TOUCH_END",s=>this.onTouchEnd(s)),this._touchscreenControls.Subscribe("ROTATE_START",()=>this.onRotateStart()),this._touchscreenControls.Subscribe("ROTATE_MOVE",s=>this.onRotateMove(s)),this._touchscreenControls.Subscribe("PINCH_START",()=>this.onPinchStart()),this._touchscreenControls.Subscribe("PINCH_MOVE",s=>this.onPinchMove(s))}async Init(){return this.prepareScene(),await this.initOrigin(),await this.initRaycaster(),Promise.resolve(this)}Dispose(){this.restoreScene(),this._origin.Dispose(),this._xrRaycaster.Dispose(),this._placed=!1}Update(t){this._frameBuffer=t,this._placed||(this.updateHandNode(),this._origin&&this._origin.Update(t))}updateHandNode(){this._xrCamera.updateMatrixWorld(),this._scene.XRRoot.XRHandNode.position.copy(this._handNodeInitialPosition.clone().applyMatrix4(this._xrCamera.matrixWorld)),this._scene.XRRoot.XRHandNode.quaternion.setFromRotationMatrix(this._xrCamera.matrixWorld)}async initOrigin(){this._origin=await this._origin.Init(),this._origin.originSet.then(()=>{this.placeObjects(this._origin.matrix)})}placeObjects(t){this._scene.XRRoot.XRModelRoot.matrix.copy(t),[...this._scene.XRRoot.XRHandNode.children].forEach(i=>{this._scene.XRRoot.XRModelRoot.add(i)}),this._placed=!0}updateObject(){this._grabbedObject&&(this._grabbedObject.position.copy(this._arHitPosition),this._grabbedObject.quaternion.copy(this._arHitQuaternion.clone().multiply(this._touchQuaterion)),this._grabbedObject.scale.copy(new f.Vector3(this._touchScale,this._touchScale,this._touchScale).multiply(this._arHitScale)))}onTouchStart(){const t=this._xrRaycaster.GetSceneIntersections();if(console.log("sceneHits",t),t.length===0||!t[0].object)return;const i=It(t[0].object,"isMovable");i&&(this._grabbedObject=i)}onTouchMove(){if(!this._frameBuffer||!this._grabbedObject)return;const t=this._xrRaycaster.GetARIntersections(this._frameBuffer);if(t.length===0){this._crosshair.visible=!1;return}const i=t[0];this._crosshair.visible=!0,this._crosshair.matrix.copy(i.matrix),this._grabbedObject&&((!this._initialObjectPosition||!this._initialRaycastHit)&&(this._initialObjectPosition=this._grabbedObject.position.clone(),this._initialRaycastHit=i.point.clone()),i.matrix.decompose(this._arHitPosition,this._arHitQuaternion,this._arHitScale),this._deltaRaycastHit.copy(i.point.clone().sub(this._initialRaycastHit)),this._arHitPosition.copy(this._initialObjectPosition.clone().add(this._deltaRaycastHit)),console.log("arHitPosition",this._arHitPosition),this.updateObject())}onTouchEnd(t){t.touchCount===0&&(this._crosshair.visible=!1,this._initialObjectPosition=null,this._initialRaycastHit=null,this._grabbedObject=null)}onRotateStart(){this._startTouchQuaternion=this._touchQuaterion.clone()}onRotateMove(t){this._touchQuaterion.setFromAxisAngle(new f.Vector3(0,-1,0),t.delta*3),this._touchQuaterion.multiply(this._startTouchQuaternion),this.updateObject()}onPinchStart(){this._startTouchScale=this._touchScale}onPinchMove(t){this._touchScale=this._startTouchScale*t.current,this.updateObject()}prepareScene(){this._scene.XRRoot.XRModelRoot.matrixAutoUpdate=!1,this._scene.add(this._crosshair);const t=[];this._scene.Root.children.forEach(i=>{const r=i.clone();r.layers.enableAll(),r.traverse(s=>{s.layers.enableAll(),s instanceof f.Mesh&&s.scale.set(.1,.1,.1)}),r.position.set(0,0,0),t.push(r)}),this._scene.XRRoot.XRHandNode.add(...t)}restoreScene(){this._scene.remove(this._crosshair),this._scene.XRRoot.XRHandNode.clear(),this._scene.XRRoot.XRModelRoot.clear(),this._scene.XRRoot.XRModelRoot.matrixAutoUpdate=!0}async initRaycaster(){if(await this._xrRaycaster.Init(),!this._xrRaycaster)return console.error("Raycaster not initialized successfully. Aborting WebXR..."),this.Dispose(),Promise.reject()}}const $=class ${static async Launch(t,i,r){if(this._renderer=t,this._scene=i,this._controller=r,this._cameraPosition=this._controller.object.position.clone(),this._cameraTarget=this._controller.target.clone(),!navigator.xr)return console.error("WebXR not supported"),Promise.reject();if(this._renderer.xr.enabled=!0,this._scene.InitXR(t),!$._overlay){const n=new Ee;$._overlay=n}$._options.domOverlay={root:$._overlay.Element};const s=await navigator.xr.requestSession("immersive-ar",this._options);return s.addEventListener("end",()=>{this._onSessionEnded()}),t.xr.setReferenceSpaceType(this._referenceSpaceType),await t.xr.setSession(s),$._overlay.Element.style.display="",this._session=s,$._overlay.CloseButton.addEventListener("click",()=>this.End()),await this._onSessionStarted(),Promise.resolve()}static Update(t,i){this._session&&this._xrController&&this._xrController.Update(i)}static End(){this._session&&this._session.end()}static async _onSessionStarted(){if(this._session)return this._renderCallbackId=this._renderer.AddPreRenderCallback((t,i)=>{this.Update(t,i)}),this._xrController=new Ie(this._session,this._renderer,this._scene),await this._xrController.Init().catch(()=>{this.End()}),Promise.resolve()}static _onSessionEnded(){if(!this._session)return;this._xrController&&this._xrController.Dispose(),this._renderCallbackId&&(this._renderer.RemovePreRenderCallback(this._renderCallbackId),this._renderCallbackId=null),this._renderer.xr.enabled=!1;const t=this._renderer.domElement.parentElement;if(t){const{clientWidth:i,clientHeight:r}=t;this._renderer.OnResize(i,r),this._controller.object.OnResize(i,r)}this._controller.object.position.copy(this._cameraPosition),this._controller.target.copy(this._cameraTarget),this._cameraPosition.set(0,0,0),this._cameraTarget.set(0,0,0),this._scene.DisposeXR(),this._session.removeEventListener("end",this._onSessionEnded),$._overlay.Element.style.display="none",this._session=null}};$._renderCallbackId=null,$._session=null,$._referenceSpaceType="local",$._overlay=null,$._options={requiredFeatures:["local","hit-test"],optionalFeatures:["light-estimation","local-floor","dom-overlay","depth-sensing"],depthSensing:{usagePreference:["gpu-optimized"],dataFormatPreference:[]},domOverlay:{root:{}}},$._xrController=null;let vt=$;class De{static Launch(t,i){const r=this.findSceneViewerSrc(t);this.launchSceneViewer(r,i)}static launchSceneViewer(t,i){const r=document.createElement("a"),s="#model-viewer-no-ar-fallback",n=self.location.toString(),o=new URL(n),h=new URL(t,n),c=new URLSearchParams(h.search);o.hash=s,c.set("mode","ar_only"),(i==null?void 0:i.arScale)==="fixed"&&c.set("resizable","false"),(i==null?void 0:i.arPlacement)==="vertical"&&c.set("enable_vertical_placement","true");const u=`intent://arvr.google.com/scene-viewer/1.2?${c.toString()+"&file="+h.toString()}#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;S.browser_fallback_url=${encodeURIComponent(o.toString())};end;`;r.setAttribute("href",u),r.click()}static findSceneViewerSrc(t){let i=null;if(t.traverse(r=>{i||r.userData.uri&&(i=r.userData.uri)}),!i)throw new Error("No model found in scene");return i}}class Oe{constructor(t,i,r){this._renderer=t,this._scene=i,this._controller=r}async Launch(t){const i=f.DIVEInfo.GetSystem();if(i==="iOS")return this.tryARQuickLook();if(i==="Android")return t!=null&&t.useWebXR?(console.warn("DIVE: WebXR is experimental on Android."),this.tryWebXR()):this.trySceneViewer();console.log("DIVE: AR not supported. Not a mobile system. (System is "+i+")")}async tryARQuickLook(t){return f.DIVEInfo.GetSupportsARQuickLook()?(console.log("DIVE: Launching AR with ARQuickLook ..."),await pt.Launch(this._scene,t),Promise.resolve()):(console.log("ARQuickLook not supported"),Promise.reject())}async tryWebXR(){return await f.DIVEInfo.GetSupportsWebXR()?(console.log("DIVE: Launching AR with WebXR ..."),await vt.Launch(this._renderer,this._scene,this._controller),Promise.resolve()):(console.log("WebXR not supported. Reason: "+f.WebXRUnsupportedReason[f.DIVEInfo.GetWebXRUnsupportedReason()]),Promise.reject())}async trySceneViewer(t){return console.log("DIVE: Launching AR with SceneViewer ..."),De.Launch(this._scene,t),Promise.resolve()}}exports.DIVEAR=Oe;
|
|
153
|
-
//# sourceMappingURL=AR-BWQebw6-.cjs.map
|