@splinetool/loader 1.10.2 → 1.10.3
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/build/SplineLoader.cjs +4 -4
- package/build/SplineLoader.js +4 -4
- package/package.json +1 -1
package/build/SplineLoader.cjs
CHANGED
|
@@ -15,7 +15,7 @@ best distance: ${d.d}`);let b=[d.x,d.y];return b.distance=d.d,b.distance}functio
|
|
|
15
15
|
}`}if(n){o=`${!1&&window.location.search.includes("api-dev")?"https://api-dev.spline.design/":"https://apis.spline.design/"}file/${i.proxy.fileId}/external-api/request?uuidexternalapi=${i.proxy.proxyId}`;let u;a!==void 0?u=a:i.method==="POST"&&i.body&&(u=Dl(JSON.parse(i.body),r)),u!==void 0&&(o+=`&data=${encodeURIComponent(u.replace(/(\r\n|\n|\r|\t)/gm,""))}`)}else i.integration?.type==="OpenAI"?t=a:i.method==="POST"&&i.body&&(t=Dl(JSON.parse(i.body),r));let s=await fetch(o,{method:n?"GET":i.method,headers:n?void 0:cI(i),signal:e.signal,body:t});if(!s.ok)throw new Error("status:"+s.status+"_:_"+s.statusText);if(i.integration?.type==="OpenAI"){let l=await s.json();return n&&(l=l.response),{content:l.choices[0].message.content}}else{let l=await s.json();return n&&(l=l.response),l}}var ob=(i,r)=>{if(typeof i=="string"){let e=r.getVariable(i);if(e)return ob(e,r)}return Vi.isBoolean(i)?Vi.getDisplayedValue(i).toLowerCase():Vi.getDisplayedValue(i)},Dl=(i,r)=>i.map((e,t)=>{if("text"in e)return e.text;if("type"in e){if(e.type==="paragraph")return(t>0?`
|
|
16
16
|
`:"")+Dl(e.children,r);if(e.type==="variable"){let o=r.getVariable(e.variableId);if(o!==void 0)return ob(o,r)}}return""}).join("");var hI=new Ie.Matrix4,mI=new Ie.Matrix4;function yI(i,r,e){let t=[new Ie.Vector3,new Ie.Vector3,new Ie.Vector3],o=[new Ie.Vector3,new Ie.Vector3,new Ie.Vector3];return i.extractBasis(t[0],t[1],t[2]),r.extractBasis(o[0],o[1],o[2]),t.forEach((n,a)=>{let s=o[a],l=Ie.MathUtils.lerp(n.length(),s.length(),e);n.lerp(s,e).setLength(l)}),new Ie.Matrix4().makeBasis(t[0],t[1],t[2])}var ib=class{static create(i){return this.build(this.normalizeInputs(i))}static normalizeInputs(i,r){let e=Object.assign({},r?.parameters??{width:100,height:100,depth:1,subdivisions:12,roundness:0,extrudeBevelSize:0,extrudeBevelSegments:3},i.parameters),t=Math.abs(e.width),o=Math.abs(e.height??e.width),n=Math.abs(e.depth??0),a=r?.shapeData??Ya.create({parameters:$p}).userData.shape;return{path:i.path??Ia.defaultData(),parameters:Object.assign(e,{width:t,height:o,depth:n,extrusion:{...gu,...e.extrusion}}),shapeData:a}}static build(i){if(i.path.points.length>=2){let e=new Gf(i);return Object.assign(e,{userData:{...i,type:"PathGeometry"}})}else return Object.assign(new Ie.BufferGeometry,{userData:{...i,type:"PathGeometry"}})}},Gf=class extends Ie.BufferGeometry{constructor(e){super();this.type="PathExtrusionGeometry",this.inputs=e,this.build()}_isGeometryClosed(){return this.inputs.path.isClosed&&this.inputs.parameters.extrusion.depth===1}_isOpenEnded(){let e=this.inputs.parameters.extrusion;return!(this.inputs.path.isClosed&&e.depth===1)||!tb(e.twist,0)||e.startScale!==e.endScale}build(){let e=this._extractPathPoints();if(e.length<2)return;let t=this._computeBasisMatrices(e),{depth:o,offset:n}=this.inputs.parameters.extrusion;o=Math.max(0,Math.min(o,1)),n=Math.max(0,Math.min(n,1));let a=this.inputs.path.isClosed?e.length:e.length-1,s=Math.floor(n*a),l=this.inputs.path.isClosed?Math.ceil((o+n)*a):Math.ceil(Math.min(1,o+n)*a),c=Math.min(Math.max(2,l-s+1),a+2),u=[],p=[];for(let F=0;F<c;F++){let j=this.inputs.path.isClosed?(F+s)%e.length:Math.min(F+s,e.length-1);u.push(e[j].clone()),p.push(t[j].clone())}let d=(F,j,H)=>{u[F]=u[F].clone().lerp(u[j],H),p[F]=yI(p[F],p[j],H)},f=0,h=n*a%1;(!this.inputs.path.isClosed||o<=1)&&(h||n===0)&&(f=h,d(0,1,f));let m=0,y=(n+o)*a%1;if((this.inputs.path.isClosed&&o<=1||!this.inputs.path.isClosed&&n+o<1)&&y&&(m=y,d(u.length-1,u.length-2,1-m)),o===0){let F=u.length-1;u[F].copy(u[0]),p[F].copy(p[0])}this._applyPathModifiers(p,f,m);let{bevel:b,bevelSides:v}=this.inputs.parameters.extrusion,w=b>0?this.inputs.parameters.extrusion.capType:"flat",O=5;this.inputs.parameters.extrusion.shape.type==="Custom"&&(O=this.inputs.parameters.extrusion.shape.shapeQuality==="low"?5:12);let{regions:S,infos:T,vertices:A}=this._computeShapePoints(O),g=0,D;w==="round"&&(D=new Ui(this.inputs.shapeData,2*b,b,O,v,void 0,!0),g=D.getAttribute("position").count);let E=0,I=0;T.sort((F,j)=>F.start-j.start),T.forEach(F=>{F.verticesStart=E,F.verticesCount=F.continuous.reduce((j,H,q)=>j+(q===0||!H?2:1),0),I+=F.verticesCount,E=I});let N=I*c,_,R=0;if(this._isOpenEnded()&&w==="flat"){try{_=co({windingRule:$e.ODD,elementType:St.POLYGONS,polySize:3,vertexSize:2,strict:!0,contours:S})}catch{_=Ef}R=_.vertexCount}let V=N+2*R+g*2,U=N+2*R,B={positions:new Float32Array(V*3),normals:new Float32Array(V*3),uvs:new Float32Array(V*2)},W=[];if(T.forEach(F=>{this._extrudeRegion(F,A,p,u,B,W,this._isGeometryClosed()&&!this._isOpenEnded())}),_&&(this._closeEnd(_,N,W,B,p[0],u[0],!1),this._closeEnd(_,N+R,W,B,p[p.length-1],u[u.length-1],!0)),D){B.positions.set(D.getAttribute("position").array,U*3),B.normals.set(D.getAttribute("normal").array,U*3),B.uvs.set(D.getAttribute("uv").array,U*2);for(let q=U;q<U+g;q++)B.uvs[q*2+1]=1e-4;let F=W.length;W.push(...D.getIndex().array.map(q=>q+U)),U+=g,B.positions.set(D.getAttribute("position").array,U*3),B.normals.set(D.getAttribute("normal").array,U*3),B.uvs.set(D.getAttribute("uv").array,U*2);let j=W.length;W.push(...D.getIndex().array.map(q=>q+U)),this.setAttribute("position",new Ie.BufferAttribute(B.positions,3)),this.setAttribute("normal",new Ie.BufferAttribute(B.normals,3)),this.setAttribute("uv",new Ie.BufferAttribute(B.uvs,2)),this.setIndex(W);let H=hI;H.copy(p[p.length-1]).setPosition(u[u.length-1]),this.applyMatrix4OnRange(H,U,V),H.copy(p[0]).setPosition(u[0]).multiply(mI.makeScale(1,1,-1)),this.applyMatrix4OnRange(H,U-g,U),this.reverseIndicesOnRange(F,j)}else this.setAttribute("position",new Ie.BufferAttribute(B.positions,3)),this.setAttribute("normal",new Ie.BufferAttribute(B.normals,3)),this.setAttribute("uv",new Ie.BufferAttribute(B.uvs,2)),this.setIndex(W)}_extractPathPoints(){let t=Vu(this.inputs.path).getPoints(this.inputs.path.subdivisions);if(t.length<2)return[];let o=[t[0]];return t.forEach(a=>{o[o.length-1].distanceToSquared(a)>.001&&o.push(a)}),this.inputs.path.isClosed&&o[o.length-1].distanceTo(o[0])<.001&&o.pop(),o}_computeBasisMatrices(e){let t=[],o=e.length,n=this.inputs.path.isClosed,a=new Ie.Vector3,s=new Ie.Vector3,l=new Ie.Vector3,c=new Ie.Vector3,u=new Ie.Vector3(0,1,0);for(let y=0;y<o;y++){let b=e[y],v;y===0?v=n?e[e.length-2]:b.clone().multiplyScalar(2).sub(e[1]):v=e[y-1];let w;y===o-1?w=n?e[1]:b.clone().multiplyScalar(2).sub(e[y-1]):w=e[y+1];let O=b.clone().sub(v).normalize(),S=w.clone().sub(b).normalize(),T=O.clone().add(S).normalize();l.copy(T),y===0&&(T.equals(u)||T.clone().negate().equals(u))&&u.set(0,0,1);let A=u.clone().cross(T).normalize(),g=T.clone().cross(A).normalize();u.copy(g),c.copy(A),y===0&&(a.copy(g),s.copy(T));let D=new Ie.Matrix4().makeBasis(A,g,T);t.push(D)}let p=n?s:l,d=n?a:new Ie.Vector3(0,1,0),f=p.clone().cross(c).normalize(),h=Math.acos(d.dot(f));if(isNaN(h))return t;let m=d.clone().cross(f);p.dot(m)>0&&(h*=-1);for(let y=1;y<t.length;y++){let b=new Ie.Matrix4().makeRotationZ(h*y/t.length);t[y].multiply(b)}return t}_applyPathModifiers(e,t,o){let n=e.length,{angle:a,twist:s,startScale:l,endScale:c}=this.inputs.parameters.extrusion,u=new Ie.Matrix4,p=new Ie.Matrix4;return e.forEach((d,f)=>{let h=f===0?0:f===n-1?1:(f-t)/(n-(o===0?0:1)-(t+(1-o)));u.makeRotationZ(Ie.MathUtils.lerp(a,a+s,h)*Ie.MathUtils.DEG2RAD);let m=Ie.MathUtils.lerp(l,c,h);p.makeScale(m,m,m),d.multiply(u).multiply(p)}),e}_computeShapePoints(e=12,t=$e.ODD){let o=this.inputs.shapeData,n=o.extractShapePointsToFlatArray([],e),a=o.shapeHoles.map(m=>{let y=m.extractShapePointsToFlatArray([],e),b=[];for(let v=y.length-1;v>=1;v-=2){let w=y[v-1],O=y[v-0];b.push(w,O)}return b}),s;try{s=co({windingRule:t,elementType:St.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[n]})}catch{s=Ml}let l;try{l=co({windingRule:$e.ODD,elementType:St.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[...a]})}catch{l=If}if(!s)throw new Error("error generating geometry");let c=s.elementCount;if(l){s.elementCount+=l.elementCount;for(let m=0;m<l.elements.length;m++){let y=l.elements[m],b=m%2===0?s.vertexCount:0;s.elements.push(y+b)}for(let m=0;m<l.vertexIndices.length;m++){let y=l.vertexIndices[m],b=s.vertexCount;s.vertexIndices.push(y+b)}for(let m=0;m<l.vertices.length;m++){let y=l.vertices[m];s.vertices.push(y)}}let u=1/0,p=-1/0,d=1/0,f=-1/0;for(let m=0,y=s.vertexCount;m<y;m++){let b=m*2,v=s.vertices[b+0],w=s.vertices[b+1];v<u&&(u=v),v>p&&(p=v),w<d&&(d=w),w>f&&(f=w)}let h=[];for(let m=s.elementCount-1;m>=0;m--){let y=m>=c,b=m*2,v=s.elements[b+0],w=s.elements[b+1],O=v+w,S={start:v,count:w,normals:[],isHole:y,continuous:[],verticesStart:0,verticesCount:0};h.push(S);let T=v,A=O-1,g=v+1,D=o.roundedCurves.length;do{let E=T-v,I=s.vertices[A*2+0],N=s.vertices[A*2+1],_=s.vertices[T*2+0],R=s.vertices[T*2+1],V=s.vertices[g*2+0],U=s.vertices[g*2+1],B=_-I,W=R-N,F=Math.sqrt(B*B+W*W);B/=F,W/=F;let j=_-V,H=R-U,q=Math.sqrt(j*j+H*H);j/=q,H/=q,S.normals[E*2+0]=-H,S.normals[E*2+1]=j;let re=s.vertexIndices[T];if(Array.isArray(re))S.continuous[E]=!1;else{let[ee,Y]=o.getCurveIndexFromVertexId(re-1,!0);if(Y>0&&Y<1)S.continuous[E]=!0;else{let te=Y===1?ee+1:ee-1;te=(te+D)%D;let K=Y===1?0:1,Z=o.roundedCurves[ee].getTangent(Y),Q=o.roundedCurves[te].getTangent(K);S.continuous[E]=Z.dot(Q)>.95}}y&&(S.normals[E*2+0]*=-1,S.normals[E*2+1]*=-1),[A,T,g]=[T,g,g+1],g>=O&&(g-=w)}while(g!==v+1)}return{regions:[n,...a],infos:h,vertices:s.vertices}}_insertVertex(e,t,o,n,a){let s=t*2,l=t*3;e.positions[l+0]=o.x,e.positions[l+1]=o.y,e.positions[l+2]=o.z,e.normals[l+0]=n.x,e.normals[l+1]=n.y,e.normals[l+2]=n.z,e.uvs[s+0]=a.x,e.uvs[s+1]=a.y}_extrudeRegion(e,t,o,n,a,s,l){let c=new Ie.Vector3,u=new Ie.Vector3,p=new Ie.Vector3,d=new Ie.Vector3,f=new Ie.Vector2;o.forEach((m,y)=>{let b=n[y],v=e.verticesStart*o.length+e.verticesCount*y;for(let w=0;w<e.count;w++){let O=(e.start+w)*2;if(c.set(t[O+0],t[O+1],0),p.copy(c).applyMatrix4(m).add(b),e.continuous[w])d.set(e.normals[w*2+0],e.normals[w*2+1],0);else{let S=w===0?(e.start+e.count-1)*2:O-2;u.set(t[S+0],t[S+1],0),d.copy(c).sub(u),d.set(-d.y,d.x,0),e.isHole||d.negate()}if(d.applyMatrix4(m).normalize(),f.set(w===0?1:w/e.count,y/(o.length-1)),this._insertVertex(a,v,p,d,f),v++,!e.continuous[w]||w===0){if(w===0)d.set(e.normals[w*2+0],e.normals[w*2+1],0),f.set(0,y/(o.length-1));else{let S=w===e.count-1?e.start*2:O+2;u.set(t[S+0],t[S+1],0),d.copy(u).sub(c),d.set(-d.y,d.x,0),e.isHole||d.negate()}d.applyMatrix4(m).normalize(),this._insertVertex(a,v,p,d,f),v++}}});let h=o.length-1;for(let m=0;m<h;m++){let y=e.verticesStart*o.length+e.verticesCount*m,b=e.verticesStart*o.length+e.verticesCount*(m+1),v=0;for(let w=0;w<e.count;w++){(!e.continuous[w]||w===0)&&v++;let O=w===e.count-1?0:v+1,S=y+v,T=y+O,A=b+O,g=b+v;e.isHole?s.push(S,A,T,S,g,A):s.push(S,T,A,S,A,g),v++}}}_closeEnd(e,t,o,n,a,s,l){let c=e.vertexCount,u=new Ie.Vector3(0,0,l?-1:1).applyMatrix4(a),p=new Ie.Vector3,d=new Ie.Vector2;for(let h=0;h<c;h++){let m=2*h;p.set(e.vertices[m+0],e.vertices[m+1],0).applyMatrix4(a).add(s),this._insertVertex(n,t+h,p,u,d)}let f=e.elements;for(let h=0;h<e.elementCount;h++){let m=3*h,y=f[m+0]+t,b=f[m+(l?1:2)]+t,v=f[m+(l?2:1)]+t;o.push(y,b,v)}}applyMatrix4OnRange(e,t,o){let n=e.elements,a=new Ie.Matrix3().getNormalMatrix(e).elements,s,l,c,u,p=this.attributes.position,d=this.attributes.normal;if(!p||!d)return;let f=p.array,h=d.array,m=p.itemSize;for(let y=t*m,b=o*m;y<b;y+=m){if(y===t)debugger;s=f[y+0],l=f[y+1],c=f[y+2],u=1/(n[3]*s+n[7]*l+n[11]*c+n[15]),f[y+0]=(n[0]*s+n[4]*l+n[8]*c+n[12])*u,f[y+1]=(n[1]*s+n[5]*l+n[9]*c+n[13])*u,f[y+2]=(n[2]*s+n[6]*l+n[10]*c+n[14])*u,s=h[y+0],l=h[y+1],c=h[y+2],h[y+0]=a[0]*s+a[3]*l+a[6]*c,h[y+1]=a[1]*s+a[4]*l+a[7]*c,h[y+2]=a[2]*s+a[5]*l+a[8]*c}p.needsUpdate=!0,d.needsUpdate=!0}reverseIndicesOnRange(e,t){let o=this.index;if(o){for(let n=e;n<t;n+=3){let a=o.getX(n),s=o.getX(n+1),l=o.getX(n+2);o.setXYZ(n,l,s,a)}o.needsUpdate=!0}}};var In=require("three"),nb=require("three/examples/jsm/utils/BufferGeometryUtils.js");function ab(){let i=new In.BufferGeometry;return i.setAttribute("position",new In.BufferAttribute(new Float32Array([]),3)),i.setIndex(new In.BufferAttribute(new Uint16Array([]),1)),i}var xI=ab().attributes,bI=12,vI=1,En=class extends In.BufferGeometry{constructor(e,t){super();this.charWidths=[];this.charCoords=[];this.wrappedText=[];this.isLowResolution=!1;this.vectorShapes=[];Object.assign(this.attributes,xI),this.userData={parameters:e,type:"TextGeometry"};let o=t.getFont(e.font);o?.isLoaded?(this.font=o,this.update(e)):this.updateFont(e.font,t).then(()=>{this.update(e),t?.requestRender()})}async updateFont(e,t){let o=t.getFont(e);o&&(this.font=o,await o.loadingPromise)}update(e){let t=this.font;if(this.userData={parameters:e,type:"TextGeometry"},!t?.isLoaded){console.warn("Cannot update text because its font is not loaded");return}let{width:o,height:n,depth:a,extrudeBevelSize:s,extrudeBevelSegments:l,text:c,textTransform:u}=e,p=Vi.getDisplayedValue(c),d=u===2?p.toUpperCase():u===3?p.toLowerCase():p,f=SI(e,t,d),{shapes:h,charWidths:m,charCoords:y}=t.generateShapes(f,e),b=(typeof o=="number"?o:1)*.5,v=(typeof n=="number"?n:1)*.5,w=h.map(T=>new Xe().fromShape(T,!0));this.vectorShapes=w;let O=w.map(T=>wr.create({shape:T,parameters:{depth:a,extrudeBevelSegments:l,extrudeBevelSize:s,windingRule:a<=0?$e.NONZERO:$e.ODD,subdivisions:this.isLowResolution&&a>0?vI:bI}})),S=O.length?(0,nb.mergeBufferGeometries)(O):ab();S.translate(-b,v,0),this.dispose(),this.wrappedText=f,this.charCoords=y,this.charWidths=m,this.deleteAttribute("extrudeNormal"),Object.entries(S.attributes).forEach(([T,A])=>{this.setAttribute(T,A)}),this.setIndex(S.index),this.computeBoundingSphere()}clone(){let e=tr(new In.BufferGeometry,En.prototype);return e.copy(this),console.log("CloneGeometry",this,e),e}copy(e){return Object.entries(e.attributes).forEach(([t,o])=>{this.setAttribute(t,o)}),this.setIndex(e.index),this.userData={parameters:{...e.userData.parameters},type:"TextGeometry"},this}async setText(e){this.font&&await this.font.loadingPromise,await this.update({...this.userData.parameters,text:{textValue:e}})}get text(){return this.userData.parameters.text??""}};function SI(i,r,e){let t=[""],o="";for(let n of e)o+=n,n===" "||n===`
|
|
17
17
|
`?(t[t.length-1]+=o,o="",n===`
|
|
18
|
-
`&&t.push("")):r.getTextWidth(t[t.length-1]+o,i)>i.width&&(t[t.length-1].length&&t.push(""),r.getTextWidth(t[t.length-1]+o,i)>i.width&&(o.length===1?(t[t.length-1]+=o,o=""):(t[t.length-1]+=o.slice(0,-1),o=o[o.length-1],t.push(""))));return t[t.length-1]+=o,t}var st=require("three");var lb,Ju=new Promise(i=>{lb=i}),sb=!1;var Zu;function cb(){if(sb)return;if(Zu)return Zu;async function i(){let e=!1?".":"https://unpkg.com/@splinetool/modelling-wasm@1.10.2/build",o=import("./process.js"),[n,a]=await Promise.all([o,fetch(`${e}/process.wasm`).then(c=>c.arrayBuffer())]),s=n.default,l=await s({wasmBinary:a});lb(l),sb=!0}return Zu=i(),Zu}var ub=require("three");var wI=["font"];function ui(i,r,e,t){let o,n,a;i.type==="PathGeometry"?(n=JSON.parse(JSON.stringify(i)),a=[[],["extrusion"]]):(n={...i},a=[[]]);for(let c of a){let u=n;for(let p of c)u=u[p];for(o in u){let p=u[o];Hp(p)&&!wI.includes(o)&&(u[o]=r.getVariable(p,[t.uuid,"geometry",...c,o]),Hp(u[o])&&(u[o]=1))}}let s={parameters:n,type:n.type};if(n.type==="PathGeometry")s.path=n.path;else if(n.type==="VectorGeometry"){let c=Xe.createFromState(n.shape,n.width,n.height);s.shape=c}else if(n.type==="NonParametricGeometry"){if(n.data.groups&&n.data.groups?.forEach(c=>c.materialIndex=Math.max(c.materialIndex??0,0)),s.geometry=new ub.BufferGeometryLoader().parse(n),s.geometry.groups.length===0){let c=s.geometry;c.addGroup(0,Math.max(c.getIndex()?.count??0,c.getAttribute("position").count),0)}}else if(n.type==="SubdivGeometry"){let c=new _t(n,e);return c.data=i,c}else{if(n.type==="TextGeometry")return new En(n,r);if(n.type==="InputGeometry")return new En(n,r);if(n.type==="UIGeometry")return Za.create({parameters:{width:n.width,height:n.height,cornerRadius:n.cornerRadius,cornerType:n.cornerType}})}let l;try{l=Ff(s)}catch(c){console.error(c)}if(!l){let c=Xe.createFromState(Ma.defaultData(),100,100);s.shape=c,l=Ff(s)}return l}var db=require("three"),PI=new db.Matrix4;function _l(i,r,e,t){let o=i.position.array,n=i.normal.array,a=PI.makeScale(r,e,t).invert().elements,s,l,c;for(var u=0,p=o.length;u<p;u+=3)o[u]*=r,o[u+1]*=e,o[u+2]*=t,s=n[u],l=n[u+1],c=n[u+2],n[u]=a[0]*s+a[4]*l+a[8]*c,n[u+1]=a[1]*s+a[5]*l+a[9]*c,n[u+2]=a[2]*s+a[6]*l+a[10]*c;i.position.needsUpdate=!0,i.normal.needsUpdate=!0}var ed=new st.Box3,es=new st.Vector3,Pe;Ju.then(i=>{Pe=i});var pb=new Float32Array([10,10,0,-10,10,0,-10,-10,0,10,-10,0]),fb=new Uint32Array([0,1,2,3]),hb=new Uint8Array([4]),_t=class extends st.BufferGeometry{constructor(e,t){super();this.data=e;this.flatShading=t;this.subdivPointer=0;this.rebuild(),this.freeSubdivPointer()}mutateDirectlyScaleBaked(e,t){this.freeSubdivPointer();let o=this.data.scaleBaked,n=Ni.div(t,o);this.subdividedGeometry&&_l(this.subdividedGeometry.attributes,...n),this.originalGeometry&&_l(this.originalGeometry.attributes,...n),this.data=e;let a=this.userData.parameters;this.userData.parameters={width:a.width*n[0],height:a.height*n[1],depth:a.depth*n[2]},this.originalGeometry.boundingSphere.center.multiply(es.fromArray(n));let s=es.set(a.width,a.height,a.depth).length();this.originalGeometry.boundingSphere.radius=s/2}ensureSubdivPointer(){return this.subdivPointer===0&&this.rebuild(),this.subdivPointer}rebuild(){let e,t,o;try{({originalGeometry:e,subdividedGeometry:t,subdivPointer:o}=_t.build(this.data,void 0,!this.flatShading,void 0))}catch{e=new st.BoxGeometry(100,100,100),o=0}this.subdivPointer=o,this.originalGeometry=e,this.subdividedGeometry=t??void 0;let n=this.subdividedGeometry??this.originalGeometry;Object.assign(this,n),this.calcBoundingBox()}freeSubdivPointer(){this.subdivPointer&&(_t.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0)}dispose(){super.dispose(),this.freeSubdivPointer()}calcBoundingBox(){let e=this.originalGeometry;e.boundingSphere===null&&(e.boundingSphere=new st.Sphere,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let t=e.attributes.position,o=e.boundingSphere.center;ed.setFromBufferAttribute(t),ed.getCenter(o),e.boundingSphere.radius=o.distanceTo(ed.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),ed.getSize(es);let n={width:es.x,height:es.y,depth:es.z};return this.userData.parameters=n,n}static build(e,t,o,n){let a,s,l,c=e?.phongAngle??35;o===!1&&(c=-1),t&&(Pe.free_bvh(t),Pe.free_subdivision_surface(t));try{a=_t.allocate(e,n)}catch(u){console.error(u,e),a=_t.allocate({positionWASM:pb,indexWASM:fb,verticesPerFaceWASM:hb},n)}if(Pe.set_destination_refinement_level(a,0),s=_t.buildLevel(a,!0,c),e.subdivisions>0)try{Pe.set_destination_refinement_level(a,e.subdivisions),l=_t.buildLevel(a,!1,c)}catch{try{Pe.set_destination_refinement_level(a,e.subdivisions-1),l=_t.buildLevel(a,!1,c)}catch{l=null}}else l=null;return{subdivPointer:a,originalGeometry:s,subdividedGeometry:l}}static primitiveToQuads(e,t,o){e.widthSegments>16&&(e.widthSegments=16),e.heightSegments>16&&(e.heightSegments=16),e.depthSegments>16&&(e.depthSegments=16),e.radialSegments>16&&(e.radialSegments=16),e.type==="DodecahedronGeometry"&&(e.detail=0);let n=e.shape!==void 0||e.path!==void 0?t.geometry:ui(e,o,!1),a;e.type==="TorusGeometry"&&e.arc===Math.PI*2?a=n.getClosedTorusIndicesForBooleanOrSubdiv():a=n.getIndex();let s,l,c,u;({positions:s,triIndices:u}=Hf(n.getAttribute("position"),a));let p;if(e.type==="CylinderGeometry"&&e.cornerRadius===0&&e.hollow===0&&e.openEnded===!1){let d=e.radialSegments*e.heightSegments*3*2,f=d+e.radialSegments*3;p=[d,f]}return{indices:l,verticesPerFace:c}=Wf(s,u,n,p),{positions:s,indices:l,verticesPerFace:c}}static allocate(e,t){let o,n,a,s=[],l=[];e.positionWASM&&e.positionWASM.length>0?(o=e.positionWASM,n=e.indexWASM,a=e.verticesPerFaceWASM):(o=pb,n=fb,a=hb);let c=o.length,u=n.length,p=a.length,d=o.length+s.length+l.length,f=n.length+a.length,h=d*Float32Array.BYTES_PER_ELEMENT+f*Uint32Array.BYTES_PER_ELEMENT,m=d*Float32Array.BYTES_PER_ELEMENT,y=f*Uint32Array.BYTES_PER_ELEMENT,b=Pe._malloc(h),v=new Float32Array(Pe.HEAPF32.buffer,b,d),w=new Uint32Array(Pe.HEAPU32.buffer,b+m,f);v.set(o,0),v.set(s,o.length),v.set(l,o.length+s.length),w.set(n,0),w.set(a,n.length);let O;e?.scaleBaked?.some(T=>T!==1)&&(O=new st.Matrix4().makeScale(...e.scaleBaked)),t&&(O?O.premultiply(t):O=t);let S=O?Pe.alloc_subdivision_surface2(b,c,b+m,u,b+m+n.length*Uint32Array.BYTES_PER_ELEMENT,p,O.elements):Pe.alloc_subdivision_surface(b,c,b+m,u,b+m+n.length*Uint32Array.BYTES_PER_ELEMENT,p);return Pe._free(b),S}static buildLevel(e,t,o,n,a){let s=a?Pe.get_mesh_data2(e,t?Pe.Level.CONTROL:Pe.Level.REFINED,o,a.elements):Pe.get_mesh_data(e,t?Pe.Level.CONTROL:Pe.Level.REFINED,o),l=8,c=Pe.HEAPU32.subarray(s>>2,(s>>2)+l),u=c.subarray(4,4+4),p=0,d=Pe.HEAPU32[c[p]>>2],f=Pe.HEAPF32.subarray(d>>2,(d>>2)+u[p]);p++;let h=Pe.HEAPU32[c[p]>>2],m=Pe.HEAPF32.subarray(h>>2,(h>>2)+u[p]);p++;let y=Pe.HEAPU32[c[p]>>2],b=Pe.HEAPU32.subarray(y>>2,(y>>2)+u[p]);p++;let v=Pe.HEAPU32[c[p]>>2],w=Pe.HEAPU32.subarray(v>>2,(v>>2)+u[p]);if(p++,n===void 0){let O=new st.BufferGeometry;if(O.setIndex(new st.Uint32BufferAttribute(w,1)),O.setAttribute("position",new st.Float32BufferAttribute(f,3)),O.setAttribute("normal",new st.Float32BufferAttribute(m,3)),t){O.setAttribute("faceMap",new st.Uint32BufferAttribute(b,1));let S=new Float32Array(m.length/3*4).fill(0);O.setAttribute("color",new st.BufferAttribute(S,4))}return Pe.free_mesh_data(s),O.userData.type="SubdivGeometry",O}n.getAttribute("position").copyArray(f),n.getAttribute("normal").copyArray(m),n.attributes.position.needsUpdate=!0,n.attributes.normal.needsUpdate=!0,Pe.free_mesh_data(s)}static freeSubdivPointer(e){Pe.free_bvh(e),Pe.free_subdivision_surface(e)}static buildControlCageWireframe(e,t,o){let n=Pe.get_wireframe_data_for_base_level(e),a=4,s=Pe.HEAPU32.subarray(n>>2,(n>>2)+a),l=s.subarray(2,2+2),c=0,u=Pe.HEAPU32[s[c]>>2],p=Pe.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let d=Pe.HEAPU32[s[c]>>2],f=Pe.HEAPU32.subarray(d>>2,(d>>2)+l[c]);if(t===void 0){let h=new st.BufferGeometry;h.setAttribute("position",new st.Float32BufferAttribute(p,3));let m=new Float32Array(p.length);for(let y=0,b=p.length;y<b;)m[y++]=o.r,m[y++]=o.g,m[y++]=o.b;return h.setAttribute("color",new st.BufferAttribute(m,3)),h.setIndex(new st.Uint32BufferAttribute(f,1)),Pe.free_wireframe_data_for_base_level(n),h}t.getAttribute("position").copyArray(p),t.attributes.position.needsUpdate=!0,Pe.free_wireframe_data_for_base_level(n)}static updateCollabMesh(e,t,o){let n=t===0;n||Pe.set_destination_refinement_level(e,t);let a=o?Pe.get_topological_data2(e,n?Pe.Level.CONTROL:Pe.Level.REFINED,o.elements):Pe.get_topological_data(e,n?Pe.Level.CONTROL:Pe.Level.REFINED),s=6,l=Pe.HEAPU32.subarray(a>>2,(a>>2)+s),c=l.subarray(3,3+3),u=0,p=Pe.HEAPU32[l[u]>>2],d=new Float32Array(Pe.HEAPF32.subarray(p>>2,(p>>2)+c[u]));u++;let f=Pe.HEAPU32[l[u]>>2],h=new Uint32Array(Pe.HEAPU32.subarray(f>>2,(f>>2)+c[u]));u++;let m=Pe.HEAPU32[l[u]>>2],y=new Uint8Array(Pe.HEAPU32.subarray(m>>2,(m>>2)+c[u]));return Pe.free_topological_data(a),{positions:d,indices:h,verticesPerFace:y}}};var mb=["getX","getY","getZ"];function Hf(i,r){let e={},t=r?r.count:i.count,o=0,n=[],a=[],s=1e4;for(let c=0;c<t;c++){let u=r?r.getX(c):c,p="";for(let d=0;d<3;d++)p+=`${~~(i[mb[d]](u)*s)},`;if(p in e)n.push(e[p]);else{for(let d=0;d<3;d++)a.push(i[mb[d]](u));e[p]=o,n.push(o),o++}}let l=[];for(let c=0;c<n.length;c+=3)n[c]===n[c+1]||n[c]===n[c+2]||n[c+1]===n[c+2]||l.push(n[c],n[c+1],n[c+2]);return{positions:a,triIndices:l}}var td=new st.Vector3,jf=new st.Vector3,Uf=new st.Vector3,kf=new st.Vector3;function Wf(i,r,e,t){let o=[],n=[];if(e.userData.shape!==void 0&&e.userData.parameters.depth===0&&e.userData.shape.shapeHoles.length===0){let l=e.userData.shape.extractShapePointsToFlatArray([]),c=e.userData.parameters.spikes;if(e.userData.type==="EllipseGeometry"&&c<=24&&c%4===0&&e.userData.parameters.angle>=360){let d=l.length/2/c;l=l.filter((f,h)=>Math.floor(h/2)%d===0)}let u=0;for(let d=0;d<l.length;d+=2)u+=(l[d]-l[(d===0?l.length:d)-2])*(l[d+1]+l[(d===0?l.length:d)-1]);i.length=0;let p=0;if(u<0)for(let d=0;d<l.length;d+=2)i.push(l[d],l[d+1],0),o.push(p++);else for(let d=l.length-2;d>=0;d-=2)i.push(l[d],l[d+1],0),o.push(p++);return n.push(p),{indices:o,verticesPerFace:n}}let a=new Float32Array([e.userData.parameters.depth])[0],s=0;for(;s<r.length;){if(e.useNgonForTopBottomFaceDuringBake){let l=0;if((i[r[s]*3+2]===a||i[r[s]*3+2]===0)&&l++,(i[r[s+1]*3+2]===a||i[r[s+1]*3+2]===0)&&l++,(i[r[s+2]*3+2]===a||i[r[s+2]*3+2]===0)&&l++,l===3)break}if(r[s+1]===r[s+3]&&r[s+2]===r[s+5]||r[s+0]===r[s+3]&&r[s+2]===r[s+4]){td.set(i[r[s]*3],i[r[s]*3+1],i[r[s]*3+2]),jf.set(i[r[s+1]*3],i[r[s+1]*3+1],i[r[s+1]*3+2]),Uf.set(i[r[s+4]*3],i[r[s+4]*3+1],i[r[s+4]*3+2]),kf.set(i[r[s+5]*3],i[r[s+5]*3+1],i[r[s+5]*3+2]),jf.sub(td).normalize(),Uf.sub(td).normalize(),kf.sub(td).normalize();let l=jf.cross(Uf).dot(kf);Math.abs(l)>.005||t&&t.some((c,u)=>u%2===1?!1:s>=t[u]&&s<t[u+1])?(o.push(r[s],r[s+1],r[s+2]),n.push(3),s+=3):(o.push(r[s],r[s+1],r[s+4],r[s+5]),n.push(4),s+=6)}else o.push(r[s],r[s+1],r[s+2]),n.push(3),s+=3}if(e.useNgonForTopBottomFaceDuringBake){let l=[],c=[],u=0;for(let p=0,d=0;p<i.length;p+=3,d++)i[p+2]===0&&(l.push(d),u++),i[p+2]===a&&c.push(d);if(e.userData.parameters.extrudeBevelSize===0){let p=c[0];c[0]=c[1],c[1]=p}l.reverse(),o.push(...l,...c),n.push(u,u)}return{indices:o,verticesPerFace:n}}var Hr={};am(Hr,{calcBoolean:()=>AI,calcBooleanTopological:()=>CI,freeMeshSet:()=>NI,getMeshSet:()=>MI,hasOpenEdges:()=>II,transformMeshSet:()=>EI});var OI,yb=new Promise(i=>{OI=i});var Rl=require("three");var Ue,ts;yb.then(i=>Ue=i);function TI(i,r,e){let t,o;i.userData.parameters.type==="TorusGeometry"&&i.userData.parameters.arc===Math.PI*2?o=i.getClosedTorusIndicesForBooleanOrSubdiv():o=i.getIndex();let{positions:n,triIndices:a}=Hf(i.getAttribute("position"),o),s;if(r&&e){let{indices:l,verticesPerFace:c}=Wf(n,a,i);s=c.length,t=[];for(let u=0,p=0;u<s;u++){t.push(c[u]);for(let d=0;d<c[u];d++)t.push(l[p++])}}else{let l=a.length;t=Array(l+l/3),s=0;for(let c=0,u=0;u<t.length;)t[u++]=3,s++,t[u++]=a[c++],t[u++]=a[c++],t[u++]=a[c++]}return{positions:n,faceIndices:t,nFaces:s}}function gb(i){let r=i.length,e=r*Uint32Array.BYTES_PER_ELEMENT,t=r*Float32Array.BYTES_PER_ELEMENT,o=Number.isInteger(i[0])?e:t,n=Ue._malloc(o);return(Number.isInteger(i[0])?new Uint32Array(Ue.HEAPU32.buffer,n,r):new Float32Array(Ue.HEAPF32.buffer,n,r)).set(i,0),n}function xb(i){switch(i){case 0:return Ue.OP.UNION;case 1:return Ue.OP.INTERSECTION;case 2:return Ue.OP.A_MINUS_B;default:throw new Error("Unknown boolean operation "+i)}}function CI(i,r){ts===void 0&&(ts=Ue.init_csg());let e=gb(i),t=Ue.csg_calc_topological(ts,e,i.length,xb(r));Ue._free(e);let o=6,n=Ue.HEAPU32.subarray(t>>2,(t>>2)+o),a=n.subarray(3,3+3),s=0,l=Ue.HEAPU32[n[s]>>2],c=new Float32Array(Ue.HEAPF32.subarray(l>>2,(l>>2)+a[s]));s++;let u=Ue.HEAPU32[n[s]>>2],p=new Uint32Array(Ue.HEAPU32.subarray(u>>2,(u>>2)+a[s]));s++;let d=Ue.HEAPU32[n[s]>>2],f=new Uint8Array(Ue.HEAPU32.subarray(d>>2,(d>>2)+a[s]));return Ue.free_mesh_data(t),{positions:c,indices:p,verticesPerFace:f}}function AI(i,r,e,t){ts===void 0&&(ts=Ue.init_csg());let o=gb(i),n=Ue.csg_calc(ts,o,i.length,t,xb(r));Ue._free(o);let a=5,s=Ue.HEAPU32.subarray(n>>2,(n>>2)+a),l=s.subarray(2,2+3),c=0,u=Ue.HEAPU32[s[c]>>2],p=Ue.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let d=Ue.HEAPU32[s[c]>>2],f=Ue.HEAPF32.subarray(d>>2,(d>>2)+l[c]);c++;let h=l[c];e.setAttribute("position",new Rl.Float32BufferAttribute(p,3)),e.setAttribute("normal",new Rl.Float32BufferAttribute(f,3));let m=Ue.HEAPF32.subarray((n>>2)+5,(n>>2)+5+6);return e.boundingSphere===null&&(e.boundingSphere=new Rl.Sphere),e.boundingSphere.center.set(m[0],m[1],m[2]),e.boundingSphere.radius=(m[3]**2+m[4]**2+m[5]**2)**.5,e.userData.parameters={width:m[3]*2,height:m[4]*2,depth:m[5]*2},Ue.free_mesh_data(n),h}function MI(i,r,e){if(Ue===void 0)return-1;let t,o,n;if(r&&i.userData.positions!==void 0){let b=i.userData;n=b.verticesPerFace.length,t=b.positions,o=Array(b.verticesPerFace.reduce((v,w)=>v+w,0)+n);for(let v=0,w=0,O=0;v<b.verticesPerFace.length;v++){o[O++]=b.verticesPerFace[v];for(let S=0;S<b.verticesPerFace[v];S++)o[O++]=b.indices[w++]}}else({positions:t,faceIndices:o,nFaces:n}=TI(i,r,e));let a=t.length,s=o.length,l=t.length,c=o.length,u=l*Float32Array.BYTES_PER_ELEMENT+c*Uint32Array.BYTES_PER_ELEMENT,p=l*Float32Array.BYTES_PER_ELEMENT,d=c*Uint32Array.BYTES_PER_ELEMENT,f=Ue._malloc(u),h=new Float32Array(Ue.HEAPF32.buffer,f,l),m=new Uint32Array(Ue.HEAPU32.buffer,f+p,c);h.set(t,0),m.set(o,0);let y=Ue.get_csg_mesh(f,a,f+p,s,n);return Ue._free(f),y}function II(i){return Ue.has_open_edges(i)}function EI(i,r){Ue.transform_csg_mesh(i,r.elements)}function NI(i){Ue.free_csg_mesh(i)}var DI={ConeGeometry:lx,CubeGeometry:cx,CylinderGeometry:sx,DodecahedronGeometry:dx,EllipseGeometry:Ya,HelixGeometry:Bx,IcosahedronGeometry:zx,LatheGeometry:Gx,NonParametricGeometry:kx,PolygonGeometry:Yu,PyramidGeometry:Hx,RectangleGeometry:Za,SphereGeometry:Wx,PlaneGeometry:$x,BackdropGeometry:Xx,StarGeometry:Ku,TextFrameGeometry:Kx,TorusGeometry:Qx,TorusKnotGeometry:Jx,TriangleGeometry:eb,PathGeometry:ib,VectorGeometry:wr},Ff=i=>DI[i.type].create(i);function rs(i){return i!==null&&"booleanOp"in i}var os=class extends ja(rd.Mesh){constructor(){super(...arguments);this.booleanMeshSetAddress=-1;this.booleanWasTransformed=!1;this.booleanMatrixInvOld=new rd.Matrix4}updateVisible(e){super.updateVisible(e),this.visible=!rs(this.parent)&&this.visible,rs(this.parent)&&this.parent.invalidateDownstreamBooleanData()}freeBooleanPointer(){this.booleanMeshSetAddress!==-1&&(Hr.freeMeshSet(this.booleanMeshSetAddress),this.booleanMeshSetAddress=-1)}invalidateDownstreamBooleanData(e=!1){return e?this.booleanWasTransformed=!0:this.freeBooleanPointer(),rs(this.parent)?this.parent.invalidateDownstreamBooleanData():this}invalidateUpstreamBooleanData(){this.freeBooleanPointer();for(let e of this.children)e instanceof os&&(e.freeBooleanPointer(),rs(e)&&e.invalidateUpstreamBooleanData())}updateTransformState(e,t){let o=super.updateTransformState(e,t);return o&&rs(this.parent)&&this.invalidateDownstreamBooleanData(!0),o}onVariableUpdate(e=!1){super.onVariableUpdate(e),rs(this.parent)&&this.invalidateDownstreamBooleanData(!0)}};var od=new is.Box3;function Ll(i,r=0,e=i.count,t,o){let n=1/0,a=1/0,s=1/0,l=-1/0,c=-1/0,u=-1/0;for(let p=r;p<e;p++){let d=i.getX(p),f=i.getY(p),h=i.getZ(p);d<n&&(n=d),f<a&&(a=f),h<s&&(s=h),d>l&&(l=d),f>c&&(c=f),h>u&&(u=h)}od.min.set(n,a,s),od.max.set(l,c,u),od.getCenter(t),od.getSize(o).multiplyScalar(.5)}var _I=new is.BufferGeometry,RI=new is.MeshBasicMaterial,Ut=class extends os{constructor(r,e){super(_I,RI),this.super_Entity(r,e)}updateState(r,e){this.updateState_Entity(r,e)}updateEntityBoxSize(r,e){let t=this.geometry.getAttribute("position");t!==void 0?Ll(t,this.geometry.drawRange.start,this.geometry.drawRange.count<1/0?this.geometry.drawRange.count:t.count,r,e):super.updateEntityBoxSize(r,e)}};var mi=require("three");var Br=require("three");var jb=require("three");var di=class{constructor(r){this.hashProperties=void 0;this.isNode=!0;this.shortcuts={};if(di.uuidContext===null)throw new Error("plz startContext");di.uuidContext===di.globalContext?this.uuid="_gid"+di.uuidContext.nodeContextUuid++:this.uuid="_uid"+di.uuidContext.nodeContextUuid++,this.type=r,this.name=""}static startContext(r){this.uuidContext===null||this.uuidContext===di.globalContext?this.uuidContext=r:console.error("Can't start context twice")}static endContext(r){this.uuidContext!==r&&console.error("Can't end context twice"),this.uuidContext=null}analyze(r,e){e=e??{},r.analyzing=!0,this.build(r.addFlow(e.slot,e.cache,e.context),"v4"),r.clearVertexNodeCode(),r.clearFragmentNodeCode(),r.removeFlow(),r.analyzing=!1}analyzeAndFlow(r,e,t){return t=t??{},this.analyze(r,t),this.flow(r,e,t)}flow(r,e,t){t=t??{},r.addFlow(t.slot,t.cache,t.context);let o={result:this.build(r,e),code:r.clearNodeCode(),extra:r.context.extra};return r.removeFlow(),o}build(r,e,t){e=e??this.getType(r,e);let o=r.getNodeData(t??this);return r.analyzing&&this.appendDepsNode(r,o,e),r.nodes.indexOf(this)===-1&&r.nodes.push(this),this.updateFrame!==void 0&&r.updaters.indexOf(this)===-1&&r.updaters.push(this),this.generate(r,e,t)}updateFrame(r){}generateReadonly(r,e,t,o,n,a){return""}generate(r,e,t,o,n){return""}parse(r,e,t,o){}appendDepsNode(r,e,t){e.deps=(e.deps||0)+1;let o=r.getTypeLength(t);(o>(e.outputMax||0)||this.getType(r,t))&&(e.outputMax=o,e.output=t)}setName(r){this.name=r}getName(){return this.name}getType(r,e){return e==="sampler2D"||e==="samplerCube"?e:this.type}},rt=di;rt.globalContext={nodeContextUuid:0},rt.uuidContext=di.globalContext;var mo=require("three");var Bl=class{constructor(r){r=r??{},this.name=r.name,this.type=r.type,this.node=r.node,this.size=r.size,this.needsUpdate=r.needsUpdate}get value(){return this.node.value}set value(r){this.node.value=r}};var qf=class{constructor(){this.nodes={};this.keywords={}}add(r){this.nodes[r.name]=r}addKeyword(r,e,t){t=t!==void 0?t:!0,this.keywords[r]={callback:e,cache:t}}remove(r){delete this.nodes[r.name]}removeKeyword(r){delete this.keywords[r]}get(r){return this.nodes[r]}getKeyword(r,e){return this.keywords[r].callback(e)}getKeywordData(r){return this.keywords[r]}contains(r){return this.nodes[r]!==void 0}containsKeyword(r){return this.keywords[r]!==void 0}},kt=new qf;var $f=require("three");var bb=require("three"),be=class extends rt{constructor(e,t){super(e);this.scope="";t=t??{},this.shared=t.shared!==void 0?t.shared:!0,this.unique=t.unique!==void 0?t.unique:!1}build(e,t,o,n){if(t=t??this.getType(e),this.getShared(e,t)){let a=this.getUnique(e,t);a&&this.uuid===void 0&&(this.uuid=bb.MathUtils.generateUUID()),o=e.getUUID(o??this.getUUID(),!a);let s=e.getNodeData(o),l=s.output||this.getType(e);if(e.analyzing)return(s.deps||0)>0||this.getLabel()?(this.appendDepsNode(e,s,t),this.generate(e,t,o)):super.build(e,t,o);if(a)return s.name=s.name||super.build(e,t,o),s.name;if(!this.getLabel()&&(!this.getShared(e,l)||e.context.ignoreCache||s.deps===1))return super.build(e,t,o);o=this.getUUID(!1);let c=this.getTemp(e,o);if(c)return e.format(c,l,t);{c=super.generate(e,t,o,s.output,n);let u=this.generate(e,l,o);return e.addNodeCode(c+" = "+u+";"),e.format(c,l,t)}}return super.build(e,t,o)}getShared(e,t){return t!=="sampler2D"&&t!=="samplerCube"&&this.shared}getUnique(e,t){return this.unique}setLabel(e){return this.label=e,this}getLabel(){return this.label}getUUID(e){let t=this.uuid;return typeof this.scope=="string"&&(t=this.scope+"-"+t),t}getTemp(e,t){t=t||this.uuid;let o=e.getVars()[t];return o?o.name:void 0}generate(e,t,o,n,a){return this.getShared(e,t)||console.error("TempNode is not shared"),o=o??this.uuid,e.getTempVar(o,n??this.getType(e),a,this.getLabel()).name}};var ot=class extends be{constructor(e,t){t=t??{},t.shared=t.shared!==void 0?t.shared:!1;super(e,t);this.readonly=!1}setReadonly(e){return this.readonly=e,this.hashProperties=this.readonly?["value"]:void 0,this}getReadonly(){return this.readonly}generate(e,t,o,n,a,s){o=e.getUUID(o??this.getUUID()),n=n??this.getType(e);let l=e.getNodeData(o);return this.getReadonly()&&this.generateReadonly!==void 0?this.generateReadonly(e,t,o,n,a,s):e.isShader("vertex")?(l.vertex||(l.vertex=e.createVertexUniform(n,this,a,s,this.getLabel())),e.format(l.vertex.name,n,t)):(l.fragment||(l.fragment=e.createFragmentUniform(n,this,a,s,this.getLabel())),e.format(l.fragment.name,n,t))}};var wt=class extends ot{constructor(e=0,t){super("v2");this.nodeType="Vector2";this.value=e instanceof $f.Vector2?e:new $f.Vector2(e,t)}get x(){return this.value.x}set x(e){this.value.x=e}get y(){return this.value.y}set y(e){this.value.y=e}generateReadonly(e,t,o,n,a,s){return e.format("vec2("+this.value.x+", "+this.value.y+")",n,t)}};var Xf=require("three");var or=class extends ot{constructor(e=0,t,o){super("v3");this.nodeType="Vector3";this.value=e instanceof Xf.Vector3?e:new Xf.Vector3(e,t,o)}get x(){return this.value.x}set x(e){this.value.x=e}get y(){return this.value.y}set y(e){this.value.y=e}get z(){return this.value.z}set z(e){this.value.z=e}generateReadonly(e,t,o,n,a,s){return e.format("vec3("+this.value.x+", "+this.value.y+", "+this.value.z+")",n,t)}};var vb=require("three"),Ht=class extends vb.Color{constructor(e,t,o,n){super(e,t,o);this.isColorA=!0;this.a=n}setRGBA(e,t,o,n){super.setRGB(e,t,o),this.a=n}copy(e){return super.copy(e),this.a="a"in e?e.a:1,this}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}equals(e){return super.equals(e)&&this.a===e.a}setStyle(e,t="srgb"){let o;if(e==="transparent")return this.setRGBA(0,0,0,0),this;if(o=/^((?:rgb|hsl)a?)\(([^)]*)\)/.exec(e)){let n,a=o[1],s=o[2];switch(a){case"rgb":case"rgba":if(n=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return this.a=a==="rgba"?parseFloat(n[4]):1,super.setStyle(e,t);break;case"hsl":case"hsla":if(n=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return this.a=a==="hsla"?parseFloat(n[4]):1,super.setStyle(e,t);break}}return super.setStyle(e,t)}get x(){return this.r}get y(){return this.g}get z(){return this.b}get w(){return this.a}set x(e){this.r=e}set y(e){this.g=e}set z(e){this.b=e}set w(e){this.a=e}};var Pr=class extends ot{constructor(e){super("v4");this.nodeType="Vector4";this.value=e instanceof Ht?e:new Ht(e.r,e.g,e.b,e.a)}generateReadonly(e,t,o,n,a,s){return e.format("vec4("+this.value.r+", "+this.value.g+", "+this.value.b+", "+this.value.a+")",n,t)}};var LI=/^\s*([a-z_0-9]+)\s([a-z_0-9]+)\s*\((.*?)\)/i,Sb=/[a-z_0-9]+/gi,J=class extends be{constructor(e,t,o,n,a){super(a);this.src="";this.nodeType="Function";this.useKeywords=!0;this.includes=[];this.extensions={};this.keywords={};this.isMethod=a===void 0,this.isInterface=!1,this.parse(e,t,o,n)}getShared(e,t){return!this.isMethod}getType(e){return e.getTypeByFormat(this.type)}getInputByName(e){if(this.inputs){let t=this.inputs.length;for(;t--;)if(this.inputs[t].name===e)return this.inputs[t]}}getIncludeByName(e){if(this.includes){let t=this.includes.length;for(;t--;)if(this.includes[t].name===e)return this.includes[t]}}generate(e,t,o,n,a){let s,l=0,c=this.src;if(this.includes)for(let p=0;p<this.includes.length;p++)e.include(this.includes[p],this);for(let p in this.extensions)e.extensions[p]=!0;let u=[];for(;s=Sb.exec(this.src);)u.push(s);for(let p=0;p<u.length;p++){let d=u[p],f=d[0],h=this.isMethod?!this.getInputByName(f):!0,m=f;if(this.keywords[f]||this.useKeywords&&h&&kt.containsKeyword(f)){let y=this.keywords[f];if(!y){let b=kt.getKeywordData(f);b.cache&&(y=e.keywords[f]),y=y||kt.getKeyword(f,e),b.cache&&(e.keywords[f]=y)}m=y.build(e)}f!==m&&c[d.index+l-1]!=="."&&(c=c.substring(0,d.index+l)+m+c.substring(d.index+f.length+l),l+=m.length-f.length),this.getIncludeByName(m)===void 0&&kt.contains(m)&&e.include(kt.get(m))}return t==="source"?c:this.isMethod?(this.isInterface||e.include(this,void 0,c),this.name):e.format("( "+c+" )",this.getType(e),t)}parse(e,t,o,n){if(this.src=e||"",this.includes=t??[],this.extensions=o??{},this.keywords=n??{},this.isMethod){let a=LI.exec(this.src);if(this.inputs=[],a&&a.length==4){this.type=a[1],this.name=a[2];let s=a[3].match(Sb);if(s){let l=0;for(;l<s.length;){let c=s[l++],u;c==="in"||c==="out"||c==="inout"?u=s[l++]:(u=c,c="");let p=s[l++];this.inputs.push({name:p,type:u,qualifier:c})}}this.isInterface=this.src.indexOf("{")===-1}else this.type="",this.name=""}}};var BI=/^([a-z_0-9]+)\s([a-z_0-9]+)\s?\=?\s?(.*?)(\;|$)/i,Yf=class extends be{constructor(e="",t){super();this.src="";this.useDefine=!1;this.nodeType="Const";this.parse(e||Yf.PI,void 0,void 0,void 0,t)}getType(e){return e.getTypeByFormat(this.type)}parse(e,t,o,n,a){this.src=e||"";let s,l,c="",u=BI.exec(e);this.useDefine=a??this.src.charAt(0)==="#",u&&u.length>1?(l=u[1],s=u[2],c=u[3]):(s=this.src,l="f"),this.name=s,this.type=l,this.value=c}build(e,t){if(t==="source"){if(this.value)return this.useDefine?"#define "+this.name+" "+this.value:"const "+this.type+" "+this.name+" = "+this.value+";";if(this.useDefine)return this.src}return e.include(this),e.format(this.name,this.getType(e),t)}generate(e,t,o,n,a){return e.format(this.name,this.getType(e),t)}},qe=Yf;qe.PI="PI",qe.PI2="PI2",qe.RECIPROCAL_PI="RECIPROCAL_PI",qe.RECIPROCAL_PI2="RECIPROCAL_PI2",qe.LOG2="LOG2",qe.EPSILON="EPSILON";var VI=new RegExp(`^structs*([a-z_0-9]+)s*{s*((.|
|
|
18
|
+
`&&t.push("")):r.getTextWidth(t[t.length-1]+o,i)>i.width&&(t[t.length-1].length&&t.push(""),r.getTextWidth(t[t.length-1]+o,i)>i.width&&(o.length===1?(t[t.length-1]+=o,o=""):(t[t.length-1]+=o.slice(0,-1),o=o[o.length-1],t.push(""))));return t[t.length-1]+=o,t}var st=require("three");var lb,Ju=new Promise(i=>{lb=i}),sb=!1;var Zu;function cb(){if(sb)return;if(Zu)return Zu;async function i(){let e=!1?".":"https://unpkg.com/@splinetool/modelling-wasm@1.10.3/build",o=import("./process.js"),[n,a]=await Promise.all([o,fetch(`${e}/process.wasm`).then(c=>c.arrayBuffer())]),s=n.default,l=await s({wasmBinary:a});lb(l),sb=!0}return Zu=i(),Zu}var ub=require("three");var wI=["font"];function ui(i,r,e,t){let o,n,a;i.type==="PathGeometry"?(n=JSON.parse(JSON.stringify(i)),a=[[],["extrusion"]]):(n={...i},a=[[]]);for(let c of a){let u=n;for(let p of c)u=u[p];for(o in u){let p=u[o];Hp(p)&&!wI.includes(o)&&(u[o]=r.getVariable(p,[t.uuid,"geometry",...c,o]),Hp(u[o])&&(u[o]=1))}}let s={parameters:n,type:n.type};if(n.type==="PathGeometry")s.path=n.path;else if(n.type==="VectorGeometry"){let c=Xe.createFromState(n.shape,n.width,n.height);s.shape=c}else if(n.type==="NonParametricGeometry"){if(n.data.groups&&n.data.groups?.forEach(c=>c.materialIndex=Math.max(c.materialIndex??0,0)),s.geometry=new ub.BufferGeometryLoader().parse(n),s.geometry.groups.length===0){let c=s.geometry;c.addGroup(0,Math.max(c.getIndex()?.count??0,c.getAttribute("position").count),0)}}else if(n.type==="SubdivGeometry"){let c=new _t(n,e);return c.data=i,c}else{if(n.type==="TextGeometry")return new En(n,r);if(n.type==="InputGeometry")return new En(n,r);if(n.type==="UIGeometry")return Za.create({parameters:{width:n.width,height:n.height,cornerRadius:n.cornerRadius,cornerType:n.cornerType}})}let l;try{l=Ff(s)}catch(c){console.error(c)}if(!l){let c=Xe.createFromState(Ma.defaultData(),100,100);s.shape=c,l=Ff(s)}return l}var db=require("three"),PI=new db.Matrix4;function _l(i,r,e,t){let o=i.position.array,n=i.normal.array,a=PI.makeScale(r,e,t).invert().elements,s,l,c;for(var u=0,p=o.length;u<p;u+=3)o[u]*=r,o[u+1]*=e,o[u+2]*=t,s=n[u],l=n[u+1],c=n[u+2],n[u]=a[0]*s+a[4]*l+a[8]*c,n[u+1]=a[1]*s+a[5]*l+a[9]*c,n[u+2]=a[2]*s+a[6]*l+a[10]*c;i.position.needsUpdate=!0,i.normal.needsUpdate=!0}var ed=new st.Box3,es=new st.Vector3,Pe;Ju.then(i=>{Pe=i});var pb=new Float32Array([10,10,0,-10,10,0,-10,-10,0,10,-10,0]),fb=new Uint32Array([0,1,2,3]),hb=new Uint8Array([4]),_t=class extends st.BufferGeometry{constructor(e,t){super();this.data=e;this.flatShading=t;this.subdivPointer=0;this.rebuild(),this.freeSubdivPointer()}mutateDirectlyScaleBaked(e,t){this.freeSubdivPointer();let o=this.data.scaleBaked,n=Ni.div(t,o);this.subdividedGeometry&&_l(this.subdividedGeometry.attributes,...n),this.originalGeometry&&_l(this.originalGeometry.attributes,...n),this.data=e;let a=this.userData.parameters;this.userData.parameters={width:a.width*n[0],height:a.height*n[1],depth:a.depth*n[2]},this.originalGeometry.boundingSphere.center.multiply(es.fromArray(n));let s=es.set(a.width,a.height,a.depth).length();this.originalGeometry.boundingSphere.radius=s/2}ensureSubdivPointer(){return this.subdivPointer===0&&this.rebuild(),this.subdivPointer}rebuild(){let e,t,o;try{({originalGeometry:e,subdividedGeometry:t,subdivPointer:o}=_t.build(this.data,void 0,!this.flatShading,void 0))}catch{e=new st.BoxGeometry(100,100,100),o=0}this.subdivPointer=o,this.originalGeometry=e,this.subdividedGeometry=t??void 0;let n=this.subdividedGeometry??this.originalGeometry;Object.assign(this,n),this.calcBoundingBox()}freeSubdivPointer(){this.subdivPointer&&(_t.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0)}dispose(){super.dispose(),this.freeSubdivPointer()}calcBoundingBox(){let e=this.originalGeometry;e.boundingSphere===null&&(e.boundingSphere=new st.Sphere,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let t=e.attributes.position,o=e.boundingSphere.center;ed.setFromBufferAttribute(t),ed.getCenter(o),e.boundingSphere.radius=o.distanceTo(ed.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),ed.getSize(es);let n={width:es.x,height:es.y,depth:es.z};return this.userData.parameters=n,n}static build(e,t,o,n){let a,s,l,c=e?.phongAngle??35;o===!1&&(c=-1),t&&(Pe.free_bvh(t),Pe.free_subdivision_surface(t));try{a=_t.allocate(e,n)}catch(u){console.error(u,e),a=_t.allocate({positionWASM:pb,indexWASM:fb,verticesPerFaceWASM:hb},n)}if(Pe.set_destination_refinement_level(a,0),s=_t.buildLevel(a,!0,c),e.subdivisions>0)try{Pe.set_destination_refinement_level(a,e.subdivisions),l=_t.buildLevel(a,!1,c)}catch{try{Pe.set_destination_refinement_level(a,e.subdivisions-1),l=_t.buildLevel(a,!1,c)}catch{l=null}}else l=null;return{subdivPointer:a,originalGeometry:s,subdividedGeometry:l}}static primitiveToQuads(e,t,o){e.widthSegments>16&&(e.widthSegments=16),e.heightSegments>16&&(e.heightSegments=16),e.depthSegments>16&&(e.depthSegments=16),e.radialSegments>16&&(e.radialSegments=16),e.type==="DodecahedronGeometry"&&(e.detail=0);let n=e.shape!==void 0||e.path!==void 0?t.geometry:ui(e,o,!1),a;e.type==="TorusGeometry"&&e.arc===Math.PI*2?a=n.getClosedTorusIndicesForBooleanOrSubdiv():a=n.getIndex();let s,l,c,u;({positions:s,triIndices:u}=Hf(n.getAttribute("position"),a));let p;if(e.type==="CylinderGeometry"&&e.cornerRadius===0&&e.hollow===0&&e.openEnded===!1){let d=e.radialSegments*e.heightSegments*3*2,f=d+e.radialSegments*3;p=[d,f]}return{indices:l,verticesPerFace:c}=Wf(s,u,n,p),{positions:s,indices:l,verticesPerFace:c}}static allocate(e,t){let o,n,a,s=[],l=[];e.positionWASM&&e.positionWASM.length>0?(o=e.positionWASM,n=e.indexWASM,a=e.verticesPerFaceWASM):(o=pb,n=fb,a=hb);let c=o.length,u=n.length,p=a.length,d=o.length+s.length+l.length,f=n.length+a.length,h=d*Float32Array.BYTES_PER_ELEMENT+f*Uint32Array.BYTES_PER_ELEMENT,m=d*Float32Array.BYTES_PER_ELEMENT,y=f*Uint32Array.BYTES_PER_ELEMENT,b=Pe._malloc(h),v=new Float32Array(Pe.HEAPF32.buffer,b,d),w=new Uint32Array(Pe.HEAPU32.buffer,b+m,f);v.set(o,0),v.set(s,o.length),v.set(l,o.length+s.length),w.set(n,0),w.set(a,n.length);let O;e?.scaleBaked?.some(T=>T!==1)&&(O=new st.Matrix4().makeScale(...e.scaleBaked)),t&&(O?O.premultiply(t):O=t);let S=O?Pe.alloc_subdivision_surface2(b,c,b+m,u,b+m+n.length*Uint32Array.BYTES_PER_ELEMENT,p,O.elements):Pe.alloc_subdivision_surface(b,c,b+m,u,b+m+n.length*Uint32Array.BYTES_PER_ELEMENT,p);return Pe._free(b),S}static buildLevel(e,t,o,n,a){let s=a?Pe.get_mesh_data2(e,t?Pe.Level.CONTROL:Pe.Level.REFINED,o,a.elements):Pe.get_mesh_data(e,t?Pe.Level.CONTROL:Pe.Level.REFINED,o),l=8,c=Pe.HEAPU32.subarray(s>>2,(s>>2)+l),u=c.subarray(4,4+4),p=0,d=Pe.HEAPU32[c[p]>>2],f=Pe.HEAPF32.subarray(d>>2,(d>>2)+u[p]);p++;let h=Pe.HEAPU32[c[p]>>2],m=Pe.HEAPF32.subarray(h>>2,(h>>2)+u[p]);p++;let y=Pe.HEAPU32[c[p]>>2],b=Pe.HEAPU32.subarray(y>>2,(y>>2)+u[p]);p++;let v=Pe.HEAPU32[c[p]>>2],w=Pe.HEAPU32.subarray(v>>2,(v>>2)+u[p]);if(p++,n===void 0){let O=new st.BufferGeometry;if(O.setIndex(new st.Uint32BufferAttribute(w,1)),O.setAttribute("position",new st.Float32BufferAttribute(f,3)),O.setAttribute("normal",new st.Float32BufferAttribute(m,3)),t){O.setAttribute("faceMap",new st.Uint32BufferAttribute(b,1));let S=new Float32Array(m.length/3*4).fill(0);O.setAttribute("color",new st.BufferAttribute(S,4))}return Pe.free_mesh_data(s),O.userData.type="SubdivGeometry",O}n.getAttribute("position").copyArray(f),n.getAttribute("normal").copyArray(m),n.attributes.position.needsUpdate=!0,n.attributes.normal.needsUpdate=!0,Pe.free_mesh_data(s)}static freeSubdivPointer(e){Pe.free_bvh(e),Pe.free_subdivision_surface(e)}static buildControlCageWireframe(e,t,o){let n=Pe.get_wireframe_data_for_base_level(e),a=4,s=Pe.HEAPU32.subarray(n>>2,(n>>2)+a),l=s.subarray(2,2+2),c=0,u=Pe.HEAPU32[s[c]>>2],p=Pe.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let d=Pe.HEAPU32[s[c]>>2],f=Pe.HEAPU32.subarray(d>>2,(d>>2)+l[c]);if(t===void 0){let h=new st.BufferGeometry;h.setAttribute("position",new st.Float32BufferAttribute(p,3));let m=new Float32Array(p.length);for(let y=0,b=p.length;y<b;)m[y++]=o.r,m[y++]=o.g,m[y++]=o.b;return h.setAttribute("color",new st.BufferAttribute(m,3)),h.setIndex(new st.Uint32BufferAttribute(f,1)),Pe.free_wireframe_data_for_base_level(n),h}t.getAttribute("position").copyArray(p),t.attributes.position.needsUpdate=!0,Pe.free_wireframe_data_for_base_level(n)}static updateCollabMesh(e,t,o){let n=t===0;n||Pe.set_destination_refinement_level(e,t);let a=o?Pe.get_topological_data2(e,n?Pe.Level.CONTROL:Pe.Level.REFINED,o.elements):Pe.get_topological_data(e,n?Pe.Level.CONTROL:Pe.Level.REFINED),s=6,l=Pe.HEAPU32.subarray(a>>2,(a>>2)+s),c=l.subarray(3,3+3),u=0,p=Pe.HEAPU32[l[u]>>2],d=new Float32Array(Pe.HEAPF32.subarray(p>>2,(p>>2)+c[u]));u++;let f=Pe.HEAPU32[l[u]>>2],h=new Uint32Array(Pe.HEAPU32.subarray(f>>2,(f>>2)+c[u]));u++;let m=Pe.HEAPU32[l[u]>>2],y=new Uint8Array(Pe.HEAPU32.subarray(m>>2,(m>>2)+c[u]));return Pe.free_topological_data(a),{positions:d,indices:h,verticesPerFace:y}}};var mb=["getX","getY","getZ"];function Hf(i,r){let e={},t=r?r.count:i.count,o=0,n=[],a=[],s=1e4;for(let c=0;c<t;c++){let u=r?r.getX(c):c,p="";for(let d=0;d<3;d++)p+=`${~~(i[mb[d]](u)*s)},`;if(p in e)n.push(e[p]);else{for(let d=0;d<3;d++)a.push(i[mb[d]](u));e[p]=o,n.push(o),o++}}let l=[];for(let c=0;c<n.length;c+=3)n[c]===n[c+1]||n[c]===n[c+2]||n[c+1]===n[c+2]||l.push(n[c],n[c+1],n[c+2]);return{positions:a,triIndices:l}}var td=new st.Vector3,jf=new st.Vector3,Uf=new st.Vector3,kf=new st.Vector3;function Wf(i,r,e,t){let o=[],n=[];if(e.userData.shape!==void 0&&e.userData.parameters.depth===0&&e.userData.shape.shapeHoles.length===0){let l=e.userData.shape.extractShapePointsToFlatArray([]),c=e.userData.parameters.spikes;if(e.userData.type==="EllipseGeometry"&&c<=24&&c%4===0&&e.userData.parameters.angle>=360){let d=l.length/2/c;l=l.filter((f,h)=>Math.floor(h/2)%d===0)}let u=0;for(let d=0;d<l.length;d+=2)u+=(l[d]-l[(d===0?l.length:d)-2])*(l[d+1]+l[(d===0?l.length:d)-1]);i.length=0;let p=0;if(u<0)for(let d=0;d<l.length;d+=2)i.push(l[d],l[d+1],0),o.push(p++);else for(let d=l.length-2;d>=0;d-=2)i.push(l[d],l[d+1],0),o.push(p++);return n.push(p),{indices:o,verticesPerFace:n}}let a=new Float32Array([e.userData.parameters.depth])[0],s=0;for(;s<r.length;){if(e.useNgonForTopBottomFaceDuringBake){let l=0;if((i[r[s]*3+2]===a||i[r[s]*3+2]===0)&&l++,(i[r[s+1]*3+2]===a||i[r[s+1]*3+2]===0)&&l++,(i[r[s+2]*3+2]===a||i[r[s+2]*3+2]===0)&&l++,l===3)break}if(r[s+1]===r[s+3]&&r[s+2]===r[s+5]||r[s+0]===r[s+3]&&r[s+2]===r[s+4]){td.set(i[r[s]*3],i[r[s]*3+1],i[r[s]*3+2]),jf.set(i[r[s+1]*3],i[r[s+1]*3+1],i[r[s+1]*3+2]),Uf.set(i[r[s+4]*3],i[r[s+4]*3+1],i[r[s+4]*3+2]),kf.set(i[r[s+5]*3],i[r[s+5]*3+1],i[r[s+5]*3+2]),jf.sub(td).normalize(),Uf.sub(td).normalize(),kf.sub(td).normalize();let l=jf.cross(Uf).dot(kf);Math.abs(l)>.005||t&&t.some((c,u)=>u%2===1?!1:s>=t[u]&&s<t[u+1])?(o.push(r[s],r[s+1],r[s+2]),n.push(3),s+=3):(o.push(r[s],r[s+1],r[s+4],r[s+5]),n.push(4),s+=6)}else o.push(r[s],r[s+1],r[s+2]),n.push(3),s+=3}if(e.useNgonForTopBottomFaceDuringBake){let l=[],c=[],u=0;for(let p=0,d=0;p<i.length;p+=3,d++)i[p+2]===0&&(l.push(d),u++),i[p+2]===a&&c.push(d);if(e.userData.parameters.extrudeBevelSize===0){let p=c[0];c[0]=c[1],c[1]=p}l.reverse(),o.push(...l,...c),n.push(u,u)}return{indices:o,verticesPerFace:n}}var Hr={};am(Hr,{calcBoolean:()=>AI,calcBooleanTopological:()=>CI,freeMeshSet:()=>NI,getMeshSet:()=>MI,hasOpenEdges:()=>II,transformMeshSet:()=>EI});var OI,yb=new Promise(i=>{OI=i});var Rl=require("three");var Ue,ts;yb.then(i=>Ue=i);function TI(i,r,e){let t,o;i.userData.parameters.type==="TorusGeometry"&&i.userData.parameters.arc===Math.PI*2?o=i.getClosedTorusIndicesForBooleanOrSubdiv():o=i.getIndex();let{positions:n,triIndices:a}=Hf(i.getAttribute("position"),o),s;if(r&&e){let{indices:l,verticesPerFace:c}=Wf(n,a,i);s=c.length,t=[];for(let u=0,p=0;u<s;u++){t.push(c[u]);for(let d=0;d<c[u];d++)t.push(l[p++])}}else{let l=a.length;t=Array(l+l/3),s=0;for(let c=0,u=0;u<t.length;)t[u++]=3,s++,t[u++]=a[c++],t[u++]=a[c++],t[u++]=a[c++]}return{positions:n,faceIndices:t,nFaces:s}}function gb(i){let r=i.length,e=r*Uint32Array.BYTES_PER_ELEMENT,t=r*Float32Array.BYTES_PER_ELEMENT,o=Number.isInteger(i[0])?e:t,n=Ue._malloc(o);return(Number.isInteger(i[0])?new Uint32Array(Ue.HEAPU32.buffer,n,r):new Float32Array(Ue.HEAPF32.buffer,n,r)).set(i,0),n}function xb(i){switch(i){case 0:return Ue.OP.UNION;case 1:return Ue.OP.INTERSECTION;case 2:return Ue.OP.A_MINUS_B;default:throw new Error("Unknown boolean operation "+i)}}function CI(i,r){ts===void 0&&(ts=Ue.init_csg());let e=gb(i),t=Ue.csg_calc_topological(ts,e,i.length,xb(r));Ue._free(e);let o=6,n=Ue.HEAPU32.subarray(t>>2,(t>>2)+o),a=n.subarray(3,3+3),s=0,l=Ue.HEAPU32[n[s]>>2],c=new Float32Array(Ue.HEAPF32.subarray(l>>2,(l>>2)+a[s]));s++;let u=Ue.HEAPU32[n[s]>>2],p=new Uint32Array(Ue.HEAPU32.subarray(u>>2,(u>>2)+a[s]));s++;let d=Ue.HEAPU32[n[s]>>2],f=new Uint8Array(Ue.HEAPU32.subarray(d>>2,(d>>2)+a[s]));return Ue.free_mesh_data(t),{positions:c,indices:p,verticesPerFace:f}}function AI(i,r,e,t){ts===void 0&&(ts=Ue.init_csg());let o=gb(i),n=Ue.csg_calc(ts,o,i.length,t,xb(r));Ue._free(o);let a=5,s=Ue.HEAPU32.subarray(n>>2,(n>>2)+a),l=s.subarray(2,2+3),c=0,u=Ue.HEAPU32[s[c]>>2],p=Ue.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let d=Ue.HEAPU32[s[c]>>2],f=Ue.HEAPF32.subarray(d>>2,(d>>2)+l[c]);c++;let h=l[c];e.setAttribute("position",new Rl.Float32BufferAttribute(p,3)),e.setAttribute("normal",new Rl.Float32BufferAttribute(f,3));let m=Ue.HEAPF32.subarray((n>>2)+5,(n>>2)+5+6);return e.boundingSphere===null&&(e.boundingSphere=new Rl.Sphere),e.boundingSphere.center.set(m[0],m[1],m[2]),e.boundingSphere.radius=(m[3]**2+m[4]**2+m[5]**2)**.5,e.userData.parameters={width:m[3]*2,height:m[4]*2,depth:m[5]*2},Ue.free_mesh_data(n),h}function MI(i,r,e){if(Ue===void 0)return-1;let t,o,n;if(r&&i.userData.positions!==void 0){let b=i.userData;n=b.verticesPerFace.length,t=b.positions,o=Array(b.verticesPerFace.reduce((v,w)=>v+w,0)+n);for(let v=0,w=0,O=0;v<b.verticesPerFace.length;v++){o[O++]=b.verticesPerFace[v];for(let S=0;S<b.verticesPerFace[v];S++)o[O++]=b.indices[w++]}}else({positions:t,faceIndices:o,nFaces:n}=TI(i,r,e));let a=t.length,s=o.length,l=t.length,c=o.length,u=l*Float32Array.BYTES_PER_ELEMENT+c*Uint32Array.BYTES_PER_ELEMENT,p=l*Float32Array.BYTES_PER_ELEMENT,d=c*Uint32Array.BYTES_PER_ELEMENT,f=Ue._malloc(u),h=new Float32Array(Ue.HEAPF32.buffer,f,l),m=new Uint32Array(Ue.HEAPU32.buffer,f+p,c);h.set(t,0),m.set(o,0);let y=Ue.get_csg_mesh(f,a,f+p,s,n);return Ue._free(f),y}function II(i){return Ue.has_open_edges(i)}function EI(i,r){Ue.transform_csg_mesh(i,r.elements)}function NI(i){Ue.free_csg_mesh(i)}var DI={ConeGeometry:lx,CubeGeometry:cx,CylinderGeometry:sx,DodecahedronGeometry:dx,EllipseGeometry:Ya,HelixGeometry:Bx,IcosahedronGeometry:zx,LatheGeometry:Gx,NonParametricGeometry:kx,PolygonGeometry:Yu,PyramidGeometry:Hx,RectangleGeometry:Za,SphereGeometry:Wx,PlaneGeometry:$x,BackdropGeometry:Xx,StarGeometry:Ku,TextFrameGeometry:Kx,TorusGeometry:Qx,TorusKnotGeometry:Jx,TriangleGeometry:eb,PathGeometry:ib,VectorGeometry:wr},Ff=i=>DI[i.type].create(i);function rs(i){return i!==null&&"booleanOp"in i}var os=class extends ja(rd.Mesh){constructor(){super(...arguments);this.booleanMeshSetAddress=-1;this.booleanWasTransformed=!1;this.booleanMatrixInvOld=new rd.Matrix4}updateVisible(e){super.updateVisible(e),this.visible=!rs(this.parent)&&this.visible,rs(this.parent)&&this.parent.invalidateDownstreamBooleanData()}freeBooleanPointer(){this.booleanMeshSetAddress!==-1&&(Hr.freeMeshSet(this.booleanMeshSetAddress),this.booleanMeshSetAddress=-1)}invalidateDownstreamBooleanData(e=!1){return e?this.booleanWasTransformed=!0:this.freeBooleanPointer(),rs(this.parent)?this.parent.invalidateDownstreamBooleanData():this}invalidateUpstreamBooleanData(){this.freeBooleanPointer();for(let e of this.children)e instanceof os&&(e.freeBooleanPointer(),rs(e)&&e.invalidateUpstreamBooleanData())}updateTransformState(e,t){let o=super.updateTransformState(e,t);return o&&rs(this.parent)&&this.invalidateDownstreamBooleanData(!0),o}onVariableUpdate(e=!1){super.onVariableUpdate(e),rs(this.parent)&&this.invalidateDownstreamBooleanData(!0)}};var od=new is.Box3;function Ll(i,r=0,e=i.count,t,o){let n=1/0,a=1/0,s=1/0,l=-1/0,c=-1/0,u=-1/0;for(let p=r;p<e;p++){let d=i.getX(p),f=i.getY(p),h=i.getZ(p);d<n&&(n=d),f<a&&(a=f),h<s&&(s=h),d>l&&(l=d),f>c&&(c=f),h>u&&(u=h)}od.min.set(n,a,s),od.max.set(l,c,u),od.getCenter(t),od.getSize(o).multiplyScalar(.5)}var _I=new is.BufferGeometry,RI=new is.MeshBasicMaterial,Ut=class extends os{constructor(r,e){super(_I,RI),this.super_Entity(r,e)}updateState(r,e){this.updateState_Entity(r,e)}updateEntityBoxSize(r,e){let t=this.geometry.getAttribute("position");t!==void 0?Ll(t,this.geometry.drawRange.start,this.geometry.drawRange.count<1/0?this.geometry.drawRange.count:t.count,r,e):super.updateEntityBoxSize(r,e)}};var mi=require("three");var Br=require("three");var jb=require("three");var di=class{constructor(r){this.hashProperties=void 0;this.isNode=!0;this.shortcuts={};if(di.uuidContext===null)throw new Error("plz startContext");di.uuidContext===di.globalContext?this.uuid="_gid"+di.uuidContext.nodeContextUuid++:this.uuid="_uid"+di.uuidContext.nodeContextUuid++,this.type=r,this.name=""}static startContext(r){this.uuidContext===null||this.uuidContext===di.globalContext?this.uuidContext=r:console.error("Can't start context twice")}static endContext(r){this.uuidContext!==r&&console.error("Can't end context twice"),this.uuidContext=null}analyze(r,e){e=e??{},r.analyzing=!0,this.build(r.addFlow(e.slot,e.cache,e.context),"v4"),r.clearVertexNodeCode(),r.clearFragmentNodeCode(),r.removeFlow(),r.analyzing=!1}analyzeAndFlow(r,e,t){return t=t??{},this.analyze(r,t),this.flow(r,e,t)}flow(r,e,t){t=t??{},r.addFlow(t.slot,t.cache,t.context);let o={result:this.build(r,e),code:r.clearNodeCode(),extra:r.context.extra};return r.removeFlow(),o}build(r,e,t){e=e??this.getType(r,e);let o=r.getNodeData(t??this);return r.analyzing&&this.appendDepsNode(r,o,e),r.nodes.indexOf(this)===-1&&r.nodes.push(this),this.updateFrame!==void 0&&r.updaters.indexOf(this)===-1&&r.updaters.push(this),this.generate(r,e,t)}updateFrame(r){}generateReadonly(r,e,t,o,n,a){return""}generate(r,e,t,o,n){return""}parse(r,e,t,o){}appendDepsNode(r,e,t){e.deps=(e.deps||0)+1;let o=r.getTypeLength(t);(o>(e.outputMax||0)||this.getType(r,t))&&(e.outputMax=o,e.output=t)}setName(r){this.name=r}getName(){return this.name}getType(r,e){return e==="sampler2D"||e==="samplerCube"?e:this.type}},rt=di;rt.globalContext={nodeContextUuid:0},rt.uuidContext=di.globalContext;var mo=require("three");var Bl=class{constructor(r){r=r??{},this.name=r.name,this.type=r.type,this.node=r.node,this.size=r.size,this.needsUpdate=r.needsUpdate}get value(){return this.node.value}set value(r){this.node.value=r}};var qf=class{constructor(){this.nodes={};this.keywords={}}add(r){this.nodes[r.name]=r}addKeyword(r,e,t){t=t!==void 0?t:!0,this.keywords[r]={callback:e,cache:t}}remove(r){delete this.nodes[r.name]}removeKeyword(r){delete this.keywords[r]}get(r){return this.nodes[r]}getKeyword(r,e){return this.keywords[r].callback(e)}getKeywordData(r){return this.keywords[r]}contains(r){return this.nodes[r]!==void 0}containsKeyword(r){return this.keywords[r]!==void 0}},kt=new qf;var $f=require("three");var bb=require("three"),be=class extends rt{constructor(e,t){super(e);this.scope="";t=t??{},this.shared=t.shared!==void 0?t.shared:!0,this.unique=t.unique!==void 0?t.unique:!1}build(e,t,o,n){if(t=t??this.getType(e),this.getShared(e,t)){let a=this.getUnique(e,t);a&&this.uuid===void 0&&(this.uuid=bb.MathUtils.generateUUID()),o=e.getUUID(o??this.getUUID(),!a);let s=e.getNodeData(o),l=s.output||this.getType(e);if(e.analyzing)return(s.deps||0)>0||this.getLabel()?(this.appendDepsNode(e,s,t),this.generate(e,t,o)):super.build(e,t,o);if(a)return s.name=s.name||super.build(e,t,o),s.name;if(!this.getLabel()&&(!this.getShared(e,l)||e.context.ignoreCache||s.deps===1))return super.build(e,t,o);o=this.getUUID(!1);let c=this.getTemp(e,o);if(c)return e.format(c,l,t);{c=super.generate(e,t,o,s.output,n);let u=this.generate(e,l,o);return e.addNodeCode(c+" = "+u+";"),e.format(c,l,t)}}return super.build(e,t,o)}getShared(e,t){return t!=="sampler2D"&&t!=="samplerCube"&&this.shared}getUnique(e,t){return this.unique}setLabel(e){return this.label=e,this}getLabel(){return this.label}getUUID(e){let t=this.uuid;return typeof this.scope=="string"&&(t=this.scope+"-"+t),t}getTemp(e,t){t=t||this.uuid;let o=e.getVars()[t];return o?o.name:void 0}generate(e,t,o,n,a){return this.getShared(e,t)||console.error("TempNode is not shared"),o=o??this.uuid,e.getTempVar(o,n??this.getType(e),a,this.getLabel()).name}};var ot=class extends be{constructor(e,t){t=t??{},t.shared=t.shared!==void 0?t.shared:!1;super(e,t);this.readonly=!1}setReadonly(e){return this.readonly=e,this.hashProperties=this.readonly?["value"]:void 0,this}getReadonly(){return this.readonly}generate(e,t,o,n,a,s){o=e.getUUID(o??this.getUUID()),n=n??this.getType(e);let l=e.getNodeData(o);return this.getReadonly()&&this.generateReadonly!==void 0?this.generateReadonly(e,t,o,n,a,s):e.isShader("vertex")?(l.vertex||(l.vertex=e.createVertexUniform(n,this,a,s,this.getLabel())),e.format(l.vertex.name,n,t)):(l.fragment||(l.fragment=e.createFragmentUniform(n,this,a,s,this.getLabel())),e.format(l.fragment.name,n,t))}};var wt=class extends ot{constructor(e=0,t){super("v2");this.nodeType="Vector2";this.value=e instanceof $f.Vector2?e:new $f.Vector2(e,t)}get x(){return this.value.x}set x(e){this.value.x=e}get y(){return this.value.y}set y(e){this.value.y=e}generateReadonly(e,t,o,n,a,s){return e.format("vec2("+this.value.x+", "+this.value.y+")",n,t)}};var Xf=require("three");var or=class extends ot{constructor(e=0,t,o){super("v3");this.nodeType="Vector3";this.value=e instanceof Xf.Vector3?e:new Xf.Vector3(e,t,o)}get x(){return this.value.x}set x(e){this.value.x=e}get y(){return this.value.y}set y(e){this.value.y=e}get z(){return this.value.z}set z(e){this.value.z=e}generateReadonly(e,t,o,n,a,s){return e.format("vec3("+this.value.x+", "+this.value.y+", "+this.value.z+")",n,t)}};var vb=require("three"),Ht=class extends vb.Color{constructor(e,t,o,n){super(e,t,o);this.isColorA=!0;this.a=n}setRGBA(e,t,o,n){super.setRGB(e,t,o),this.a=n}copy(e){return super.copy(e),this.a="a"in e?e.a:1,this}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}equals(e){return super.equals(e)&&this.a===e.a}setStyle(e,t="srgb"){let o;if(e==="transparent")return this.setRGBA(0,0,0,0),this;if(o=/^((?:rgb|hsl)a?)\(([^)]*)\)/.exec(e)){let n,a=o[1],s=o[2];switch(a){case"rgb":case"rgba":if(n=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return this.a=a==="rgba"?parseFloat(n[4]):1,super.setStyle(e,t);break;case"hsl":case"hsla":if(n=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return this.a=a==="hsla"?parseFloat(n[4]):1,super.setStyle(e,t);break}}return super.setStyle(e,t)}get x(){return this.r}get y(){return this.g}get z(){return this.b}get w(){return this.a}set x(e){this.r=e}set y(e){this.g=e}set z(e){this.b=e}set w(e){this.a=e}};var Pr=class extends ot{constructor(e){super("v4");this.nodeType="Vector4";this.value=e instanceof Ht?e:new Ht(e.r,e.g,e.b,e.a)}generateReadonly(e,t,o,n,a,s){return e.format("vec4("+this.value.r+", "+this.value.g+", "+this.value.b+", "+this.value.a+")",n,t)}};var LI=/^\s*([a-z_0-9]+)\s([a-z_0-9]+)\s*\((.*?)\)/i,Sb=/[a-z_0-9]+/gi,J=class extends be{constructor(e,t,o,n,a){super(a);this.src="";this.nodeType="Function";this.useKeywords=!0;this.includes=[];this.extensions={};this.keywords={};this.isMethod=a===void 0,this.isInterface=!1,this.parse(e,t,o,n)}getShared(e,t){return!this.isMethod}getType(e){return e.getTypeByFormat(this.type)}getInputByName(e){if(this.inputs){let t=this.inputs.length;for(;t--;)if(this.inputs[t].name===e)return this.inputs[t]}}getIncludeByName(e){if(this.includes){let t=this.includes.length;for(;t--;)if(this.includes[t].name===e)return this.includes[t]}}generate(e,t,o,n,a){let s,l=0,c=this.src;if(this.includes)for(let p=0;p<this.includes.length;p++)e.include(this.includes[p],this);for(let p in this.extensions)e.extensions[p]=!0;let u=[];for(;s=Sb.exec(this.src);)u.push(s);for(let p=0;p<u.length;p++){let d=u[p],f=d[0],h=this.isMethod?!this.getInputByName(f):!0,m=f;if(this.keywords[f]||this.useKeywords&&h&&kt.containsKeyword(f)){let y=this.keywords[f];if(!y){let b=kt.getKeywordData(f);b.cache&&(y=e.keywords[f]),y=y||kt.getKeyword(f,e),b.cache&&(e.keywords[f]=y)}m=y.build(e)}f!==m&&c[d.index+l-1]!=="."&&(c=c.substring(0,d.index+l)+m+c.substring(d.index+f.length+l),l+=m.length-f.length),this.getIncludeByName(m)===void 0&&kt.contains(m)&&e.include(kt.get(m))}return t==="source"?c:this.isMethod?(this.isInterface||e.include(this,void 0,c),this.name):e.format("( "+c+" )",this.getType(e),t)}parse(e,t,o,n){if(this.src=e||"",this.includes=t??[],this.extensions=o??{},this.keywords=n??{},this.isMethod){let a=LI.exec(this.src);if(this.inputs=[],a&&a.length==4){this.type=a[1],this.name=a[2];let s=a[3].match(Sb);if(s){let l=0;for(;l<s.length;){let c=s[l++],u;c==="in"||c==="out"||c==="inout"?u=s[l++]:(u=c,c="");let p=s[l++];this.inputs.push({name:p,type:u,qualifier:c})}}this.isInterface=this.src.indexOf("{")===-1}else this.type="",this.name=""}}};var BI=/^([a-z_0-9]+)\s([a-z_0-9]+)\s?\=?\s?(.*?)(\;|$)/i,Yf=class extends be{constructor(e="",t){super();this.src="";this.useDefine=!1;this.nodeType="Const";this.parse(e||Yf.PI,void 0,void 0,void 0,t)}getType(e){return e.getTypeByFormat(this.type)}parse(e,t,o,n,a){this.src=e||"";let s,l,c="",u=BI.exec(e);this.useDefine=a??this.src.charAt(0)==="#",u&&u.length>1?(l=u[1],s=u[2],c=u[3]):(s=this.src,l="f"),this.name=s,this.type=l,this.value=c}build(e,t){if(t==="source"){if(this.value)return this.useDefine?"#define "+this.name+" "+this.value:"const "+this.type+" "+this.name+" = "+this.value+";";if(this.useDefine)return this.src}return e.include(this),e.format(this.name,this.getType(e),t)}generate(e,t,o,n,a){return e.format(this.name,this.getType(e),t)}},qe=Yf;qe.PI="PI",qe.PI2="PI2",qe.RECIPROCAL_PI="RECIPROCAL_PI",qe.RECIPROCAL_PI2="RECIPROCAL_PI2",qe.LOG2="LOG2",qe.EPSILON="EPSILON";var VI=new RegExp(`^structs*([a-z_0-9]+)s*{s*((.|
|
|
19
19
|
)*?)}`,"gim"),zI=new RegExp("s*(w*?)s*(w*?)(=|;)","gim"),ns=class extends be{constructor(e=""){super();this.inputs=[];this.src="";this.nodeType="Struct";this.parse(e)}getType(e){return e.getTypeByFormat(this.name)}getInputByName(e){let t=this.inputs.length;for(;t--;)if(this.inputs[t].name===e)return this.inputs[t]}generate(e,t,o,n,a){return t==="source"?this.src+";":e.format("( "+this.src+" )",this.getType(e),t)}parse(e=""){this.src=e,this.inputs=[];let t=VI.exec(e);if(t){let o=t[2],n;for(;n=zI.exec(o);)this.inputs.push({type:n[1],name:n[2]});this.name=t[1]}else this.name="";this.type=this.name}};var as=class extends be{constructor(e){super("v2",{shared:!1});this.nodeType="UV";this.index=e??0}generate(e,t){e.requires.uv[this.index]=!0;let o=this.index>0?this.index+1:"",n=e.isShader("vertex")?"uv"+o:"vUv"+o;return e.format(n,this.getType(e),t)}};kt.addKeyword("uv",function(){return new as});kt.addKeyword("uv2",function(){return new as(1)});var id=require("three");var Nn=class extends be{constructor(e,t){super("v4");this.nodeType="ColorSpace";this.input=e,this.method=t??Nn.LINEAR_TO_LINEAR,this.hashProperties=["method"]}static getEncodingComponents(e){switch(e){case id.LinearEncoding:return["Linear"];case id.sRGBEncoding:return["sRGB"];default:return[]}}generate(e,t){let o=this.input.build(e,"v4"),n=this.getType(e),a=Nn.Nodes[this.method],s=e.include(a);if(s===Nn.LINEAR_TO_LINEAR)return e.format(o,n,t);if(a.inputs?.length===2){let l=this.factor.build(e,"f");return e.format(s+"( "+o+", "+l+" )",n,t)}else return e.format(s+"( "+o+" )",n,t)}fromEncoding(e){let t=Nn.getEncodingComponents(e);this.method="LinearTo"+t[0],this.factor=t[1]}fromDecoding(e){let t=Nn.getEncodingComponents(e);this.method=t[0]+"ToLinear",this.factor=t[1]}},hr=Nn;hr.Nodes={LinearToLinear:new J(["vec4 LinearToLinear( in vec4 value ) {"," return value;","}"].join(`
|
|
20
20
|
`)),sRGBToLinear:new J(["vec4 sRGBToLinear( in vec4 value ) {"," return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );","}"].join(`
|
|
21
21
|
`)),LinearTosRGB:new J(["vec4 LinearTosRGB( in vec4 value ) {"," return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.w );","}"].join(`
|
|
@@ -1873,7 +1873,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
|
|
|
1873
1873
|
vec3 distorted2 = nearby2 + normal * displacementMapTexture(tex, crop, uv, mat, vec2(neighbor_offset)) * intensity;
|
|
1874
1874
|
displaced_normal = normalize(cross(distorted1 - displaced_position, distorted2 - displaced_position));
|
|
1875
1875
|
return displaced_position;
|
|
1876
|
-
}`,[e,t])}}();var De={normalRenderTarget:new mr,normalRenderTargetDepth:new mr,transmissionRenderTarget:new mr,aspectRatio:new wt,transmissionSize:new wt(2048,2048),transmissionRenderTargetDepth:new mr,aoRenderTarget:new mr,aoEnabled:new It,pixelRatioNode:new se(1),resolution:new wt,penumbraSize:new yo(5,.5),frameIndex:new Fe(0),transmissionLod:new Fe(2)};for(let i of Object.values(De))i.isRenderGlobal=!0;var Vb={skiaWasmUrl:"https://unpkg.com/@splinetool/ui-wasm@1.10.
|
|
1876
|
+
}`,[e,t])}}();var De={normalRenderTarget:new mr,normalRenderTargetDepth:new mr,transmissionRenderTarget:new mr,aspectRatio:new wt,transmissionSize:new wt(2048,2048),transmissionRenderTargetDepth:new mr,aoRenderTarget:new mr,aoEnabled:new It,pixelRatioNode:new se(1),resolution:new wt,penumbraSize:new yo(5,.5),frameIndex:new Fe(0),transmissionLod:new Fe(2)};for(let i of Object.values(De))i.isRenderGlobal=!0;var Vb={skiaWasmUrl:"https://unpkg.com/@splinetool/ui-wasm@1.10.3/build/ui.wasm"};var pi=class extends rt{constructor(){super("basic");this.nodeType="Basic";this.color=new Je(Nt),this.shadingAlpha=new se(1),this.shadingBlend=new Fe(0),this.previousModelViewMatrix=new ir,this.previouseProjectionMatrix=new ir}get category(){return"phong"}generate(e){let t;if(e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:De.frameIndex}),e.mergeUniform({resolution:De.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(cd.UniformsUtils.merge([cd.UniformsLib.fog])),e.addParsCode(["varying vec3 vViewPosition;","varying vec3 vWPosition;","#include <fog_pars_vertex>","#include <skinning_pars_vertex>","#include <normal_pars_vertex>","#include <morphtarget_pars_vertex>"].join(`
|
|
1877
1877
|
`));let n=["#include <beginnormal_vertex>","#include <morphnormal_vertex>",`
|
|
1878
1878
|
#include <skinbase_vertex>
|
|
1879
1879
|
#include <skinnormal_vertex>
|
|
@@ -2286,7 +2286,7 @@ float sobelSample(sampler2D t, sampler2D d, vec2 uv, vec2 resolution, float outl
|
|
|
2286
2286
|
`,e),c=e.horizontalAlign===1?l:0,u=this.computeSpaceWidthForLine(r,0,e),p=this.getLineInitialOffsetX(a[0],s,e.horizontalAlign,r[0],l),d=this.getLineInitialOffsetY(n,r.length,e.height,o,e.verticalAlign),f=[],h=r.map(v=>[]),m=r.map(v=>[]),y;for(let v=0;v<r.length;v++){let w=r[v],O={features:{liga:!0}},S=[];try{S=t.stringToGlyphs(w,O)}catch(A){console.warn(A)}p=this.getLineInitialOffsetX(a[v],s,e.horizontalAlign,w,l);let T=[];try{T=this.reverseLigaturesTable(t,w,S)}catch(A){console.warn(A)}u=this.computeSpaceWidthForLine(r,v,e);for(let A=0;A<S.length;A++){let g=S[A],D=g.index===0?`
|
|
2287
2287
|
`:g.unicode?String.fromCharCode(g.unicode):void 0,E=T[A],I=0,N=0;A===0&&e.horizontalAlign===2&&g.leftSideBearing!==void 0&&(N=-g.leftSideBearing*o),y&&(I=t.getKerningValue(g,y)*o),p+=N+I;let _=0;if(D===`
|
|
2288
2288
|
`)_=c;else if(D===" ")_=u;else{let R=this.createPath(g,o,p,d,e);R&&(_=R.offsetX-(I+N),f.push(R.path))}if(E.replacements.length===1)m[v].push([p,d]),h[v].push(_);else{let R=E.replacements.map(W=>(t.glyphs.get(W).advanceWidth??0)*o),V=R.reduce((W,F)=>W+=F,0),U=R.map(W=>W/V),B=p;for(let W=0;W<U.length;W++){let F=_*U[W];m[v].push([B,d]),h[v].push(F),B+=F}}p+=_,y=g}d-=n}let b=[];for(let v=0,w=f.length;v<w;v++)b.push(...f[v].toShapes());return{shapes:b,charWidths:h,lineWidths:a,charCoords:m}}get isUserFont(){return this._isUserFont}get arrayBuffer(){return this._arrayBuffer}get ascender(){return this.font?.ascender??0}get descender(){return this.font?.descender??0}get familyName(){return this.font?.names.fontFamily??""}get subfamilyName(){return this.font?.names.fontSubfamily??""}get unitsPerEm(){return this.font?.unitsPerEm??1}getLineInitialOffsetX(r,e,t,o,n){return(t===3||t===2)&&o.indexOf(`
|
|
2289
|
-
`)>=0&&(r-=n),t===3?e*.5-r*.5:t===2?e-r:0}getLineInitialOffsetY(r,e,t,o,n){let a=e*r,s=Math.abs(this.ascender-this.descender)*o,l=r-s,c=-this.ascender*o-l/2;return n===3?-(t-a-c):n===2?-(t*.5-a*.5-c):c}createPath(r,e,t,o,n){let a=r.getPath(t,-o,n.fontSize,{kerning:!1,letterSpacing:n.letterSpacing});if(!a){console.error('THREE.Font: character "'+r+'" does not exists in font family '+this.familyName+".");return}let s=new gd,l=(r.advanceWidth??1)*e;if(r)for(let c of a.commands){let u=s.currentPath?.currentPoint;if(!(u&&c.type!=="Z"&&u.x===c.x&&-u.y===c.y))switch(c.type){case"M":s.moveTo(c.x,-c.y);break;case"L":s.lineTo(c.x,-c.y);break;case"Q":s.quadraticCurveTo(c.x1,-c.y1,c.x,-c.y);break;case"C":s.bezierCurveTo(c.x1,-c.y1,c.x2,-c.y2,c.x,-c.y);break}}return s.subPaths.forEach(c=>{let u=d3(c.curves);u!==void 0&&c.currentPoint.distanceTo(u)>0&&c.lineTo(u.x,u.y)}),{offsetX:l+n.fontSize*n.letterSpacing,path:s}}getCharWidth(r,e){return this.font?.getAdvanceWidth(r,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}getTextWidth(r,e){return this.font?.getAdvanceWidth(r,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}computeSpaceWidthForLine(r,e,t){let o=this.getCharWidth(" ",t),n=r[e];if(n){let a=this.countSpaces(n.trimEnd());if(t.horizontalAlign===4&&e<r.length-1&&a){let s=t.width,l=this.getTextWidth(n,t);return(s-(l-a*o))/a}}return o}countSpaces(r){return(r.match(/ /g)||[]).length}};function d3(i){if(i.length){let r=i[0];if(r instanceof As.LineCurve)return r.v1;if(r instanceof As.CubicBezierCurve||r instanceof As.QuadraticBezierCurve)return r.v0}}var yh=class{constructor(){this.objects=new Map;this.unreachable=new Set}getCached(r){return this.objects.get(r)}get size(){return this.objects.size}get(r,e,t){let o=this.objects.get(r);return o===void 0?(o=this.createObject(r,e,t),this.objects.set(r,o)):o.isShared=!0,o}forceDelete(r){let e=this.objects.get(r);e&&(this.disposeObject(e),this.objects.delete(r))}mutateIfUnique(r,e){let t=this.objects.get(r);if(t&&t.isShared!==!0)return this.objects.delete(r),this.objects.set(e,t),t}startGc(){this.unreachable=new Set(this.objects.keys())}markAsReachable(r,e){let t=this.objects.get(r);e===t?this.unreachable.delete(r):!1&&console.warn("Reachable but deleted",r)}endGc(){this.unreachable.forEach(r=>{this.disposeObject(this.objects.get(r)),this.objects.delete(r)}),this.unreachable.clear()}dispose(){this.objects.forEach(r=>{this.disposeObject(r)}),this.objects.clear()}},Yl=class extends yh{constructor(e){super();this.flatShading=e}disposeObject(e){e.dispose()}createObject(e,t,o){let n=ui(e,t,this.flatShading,o);return n.computeBoundingSphere(),n}};var Yb={markNeedsUpdateRendererDirty:()=>{}};var bh=require("three");var vd=1e3,Kb=512*vd;function p3(i,r){let e=typeof i;return!!((r==="string"||r==="number")&&e===r||r==="boolean"&&(i==="true"||i==="false"||i===!0||i===!1)||r==="image"&&e==="string"&&i.startsWith("http"))}var Qb="https://hooks.spline.design",f3=`${Qb}/events?hashFile=`,zK=`${Qb}/`,Sd=class{constructor(r,e){this.id=r;this.userWebhook=e;this.result=void 0;this._connected=!1;this.emitter=ci();this.reconnectWaitFor=vd;this._onError=r=>{this.eventSource?.removeEventListener("message",this._onMessage),this.eventSource?.removeEventListener("error",this._onError),this.eventSource?.removeEventListener("open",this._onConnected),this._scheduleReconnect()};this._onConnected=r=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=vd,this._connected=!0};this._onDisconnected=()=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=vd,this._connected=!1};this._onMessage=r=>{let e=r.data,t;try{t=JSON.parse(e)}catch(o){console.error("Error parsing webhook message",o)}if(t){let o=!1;this.userWebhook.parametersSchemas.forEach(({data:n})=>{t[n.name]!==void 0&&p3(t[n.name],n.type)&&(this.result===void 0&&(this.result={}),this.result[n.name]=t[n.name],o=!0)}),o&&this.emitter.emit("message",{userWebhookId:this.id})}}}connect(){clearTimeout(this.scheduledReconnectHandle),this.userWebhook.url&&(this.eventSource=new EventSource(f3+this.userWebhook.url),this.eventSource.addEventListener("message",this._onMessage),this.eventSource.addEventListener("error",this._onError),this.eventSource.addEventListener("open",this._onConnected))}disconnect(){this.eventSource?.removeEventListener("message",this._onMessage),this.eventSource?.removeEventListener("error",this._onError),this.eventSource?.removeEventListener("open",this._onConnected),this.eventSource?.close(),this._onDisconnected(),clearTimeout(this.scheduledReconnectHandle)}_scheduleReconnect(){this.reconnectWaitFor*=2,this.reconnectWaitFor>Kb&&(this.reconnectWaitFor=Kb),clearTimeout(this.scheduledReconnectHandle),this.scheduledReconnectHandle=setTimeout(()=>{this.scheduledReconnectHandle=void 0,this.connect()},this.reconnectWaitFor)}update(r){this.userWebhook=r}dispose(){this._connected&&this.disconnect()}get connected(){return this._connected}on(r,e){this.emitter.on(r,e)}off(r,e){this.emitter.off(r,e)}getParametersKeys(){return this.userWebhook.parametersSchemas.map(r=>r.data.name)}getParameterValue(r){if(this.getParametersKeys().includes(r)){if(this.result)return this.result?.[r];for(let t of this.userWebhook.parametersSchemas)if(t.data.name===r)return Cu.defaultParameterValueByType(t.data.type)}}};var Zb=[4186.01,4434.92,4698.63,4978.03,5274.04,5587.65,5919.91,6271.93,6644.88,7040,7458.62,7902.13],h3=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],hi=[],Pd=[];for(let i=1;i<=8;i++)for(let r=0;r<Zb.length;r++){let e=Zb[r];hi.push(e/Math.pow(2,8-i)),Pd.push(h3[r]+i)}var wd=[32,2e3],gh=hi.filter((i,r)=>hi[r]>wd[0]&&hi[r]<wd[1]),Jb=Pd.filter((i,r)=>hi[r]>wd[0]&&hi[r]<wd[1]);var Od=class{static getFrequencies(r,e,t,o="frequency",n=-100,a=-30){t||(t=new Float32Array(r.frequencyBinCount),r.getFloatFrequencyData(t));let s=e/2,l=1/t.length*s,c,u,p;if(o==="music"||o==="voice"){let h=o==="voice"?gh:hi,m=Array(h.length).fill(n);for(let y=0;y<t.length;y++){let b=y*l,v=t[y];for(let w=h.length-1;w>=0;w--)if(b>h[w]){m[w]=Math.max(m[w],v);break}}c=m,u=o==="voice"?gh:hi,p=o==="voice"?Jb:Pd}else c=Array.from(t),u=c.map((h,m)=>l*m),p=u.map(h=>`${h.toFixed(2)} Hz`);let d=c.map(h=>Math.max(0,Math.min((h-n)/(a-n),1)));return{values:new Float32Array(d),frequencies:u,labels:p}}};var m3="gpt-4o-realtime-preview-2024-12-17",y3=()=>!1&&window.location.search.includes("api-dev")?"https://relayserver-dev.spline.design/":"https://relayserver.spline.design/";async function g3(i){try{return(await(await fetch(y3()+"session?uuidfile="+i)).json()).token}catch(r){console.error("Token generation error:",r)}}var xh=class{constructor(r){this.value=0;this.frequencies=new Float32Array(0);let e=new AudioContext;this.source=e.createMediaStreamSource(r),this.analyser=e.createAnalyser(),this.source.connect(this.analyser),this.analyser.fftSize=8192,this.analyser.smoothingTimeConstant=.1}getFrequencies(r=-100,e=-30){if(!this.analyser)throw new Error("Not connected, please call .connect() first");return Od.getFrequencies(this.analyser,44100,void 0,"voice",r,e)}update(){let r=this.getFrequencies(),e=r.values.reduce((t,o)=>t+o,0)/r.values.length;this.value=e,this.frequencies=r.values}disconnect(){this.source.disconnect(),this.analyser.disconnect()}},Kl=class{constructor(r,e,t){this.data=r;this.id=e;this.shared=t;this.emitter=ci();this.rafId=0;this.voice=0;this.frequencies=new Float32Array([0]);this.events=[];this.isConnected=!1;this.isToolsAdded=!1;this.tools=[];this.onMessage=r=>{let e=JSON.parse(r.data);if(this.appendEvent(e),e.type==="session.created"&&this.onSessionCreated(),e.type==="response.done"&&e.response?.output){for(let t of e.response.output)if(t.type==="function_call")for(let[o,n]of this.tools)t.name===o.name&&(n(JSON.parse(t.arguments)),setTimeout(()=>{this.sendClientEvent({type:"response.create",response:{instructions:"notice the user about what you just did"}})}))}};this.onSessionCreated=()=>{this.isToolsAdded||this.registerTools()};this.onOpen=()=>{this.events=[],this.isConnected=!0,this.sendClientEvent({type:"response.create",response:{instructions:"Say hi"}})};this.animate=()=>{if(this.rafId=requestAnimationFrame(this.animate),this.isConnected&&this.analyser){this.analyser.update();let r=this.analyser.value,e=this.analyser.frequencies;this.voice=r,this.frequencies=e,this.emitter.emit("voice",{value:r,frequencies:e})}}}update(r){this.data=r}setColorByName(r,e){let t=this.shared.getColorByName(r);if(t){let{id:o}=t,{r:n,g:a,b:s}=rb.hexStringToRgb(e)??{r:0,g:0,b:0};this.shared.updateColor(o,{r:n/255,g:a/255,b:s/255})}}async connect(){if(this.isConnected)return;let r=await g3(this.data.integration.hash);this.pc=new RTCPeerConnection,this.audioElement=document.createElement("audio"),this.audioElement.autoplay=!0,this.pc.ontrack=l=>{let c=l.streams[0];this.audioElement.srcObject=c,this.analyser=new xh(c)};let e=await navigator.mediaDevices.getUserMedia({audio:!0});this.pc.addTrack(e.getTracks()[0]),this.dc=this.pc.createDataChannel("oai-events"),this.dc.addEventListener("message",this.onMessage),this.dc.addEventListener("open",this.onOpen);let t=await this.pc.createOffer();await this.pc.setLocalDescription(t);let s={type:"answer",sdp:await(await fetch(`https://api.openai.com/v1/realtime?model=${m3}`,{method:"POST",body:t.sdp,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/sdp"}})).text()};await this.pc.setRemoteDescription(s),this.animate()}appendEvent(r){this.events=[r,...this.events]}sendClientEvent(r){this.dc?(r.event_id=r.event_id||crypto.randomUUID(),this.dc.send(JSON.stringify(r)),this.appendEvent(r)):console.error("Failed to send message - no data channel available",r)}registerTools(){this.isToolsAdded=!0,this.registerTool({type:"function",name:"set_personality_color",description:"returns a color based on the voice personality of the ai assistant. This should be called by the voice assistant each time it is asks to speak differently. If a color cannot be associated to the personality, the color should be a neutral color.",parameters:{type:"object",properties:{color:{type:"string",description:"css hex color string, reflecting the personality"},personality:{type:"string",description:"the personality of the voice assistant"}},required:["color","personality"]}},({color:n})=>{this.setColorByName("Voice Assistant Color",n)});let r=this.shared.getVariablesNames().join(", ");this.registerTool({type:"function",name:"set_variable",description:"Sets a Spline variable value when asked by the user.",parameters:{type:"object",properties:{name:{type:"string",description:`The name of the variable that needs to be set. Here's a list of available variables: ${r}. It the variable does not exist, don't call the function and warn the user about it.`},value:{type:"string",description:"The new value for this variable, should always be a string even for number and boolean variables, assume that the value will be cast to the proper type afterwards."}},required:["name","value","type"]}},({name:n,value:a})=>{let s=this.shared.getVariableByName(n);if(s){let l=this.shared.getVariable(s.id),c;typeof l=="number"?c=parseFloat(a):typeof l=="boolean"?c=a.toLowerCase()==="true":c={textValue:a},this.shared.updateVariable(s.id,c)}});let e=this.shared.getColorNames().join(", ");this.registerTool({type:"function",name:"set_color",description:"Sets a Spline color asset value when asked by the user.",parameters:{type:"object",properties:{name:{type:"string",description:`The name of the color asset that needs to be set. Here's a list of available color assets: ${e}. It the color asset does not exist, don't call the function and warn the user about it.`},value:{type:"string",description:"css hex color string"}},required:["name","value"]}},({name:n,value:a})=>{this.setColorByName(n,a)});let t=this.shared.scene,o=[];t.traverseEntity(n=>{n.data.events.forEach(a=>{if(a.data.type==="AIAssistantTrigger"){let{description:s}=a.data;o.push(s)}})}),this.registerTool({type:"function",name:"trigger_event",description:"Trigger an event by name, here are the available events, please match what the user is asking for to one of these if it applies, otherwise don't call the function and warn the user.",parameters:{type:"object",properties:{description:{type:"string",description:`The name of the event that needs to be triggered. Here's a list of available events: ${JSON.stringify(o)}.`},direction:{type:"string",description:"default is forward, but can be forward or backward. Always set to forward unless the user ask to reverse or cancel the event, then set to backward."}},required:["description","direction"]}},({description:n,direction:a})=>{this.emitter.emit("trigger_event",{description:n,direction:a})}),this.sendClientEvent({type:"session.update",session:{tools:this.tools.map(([n])=>n)}})}registerTool(r,e){this.tools.push([r,e])}disconnect(){cancelAnimationFrame(this.rafId),this.analyser?.disconnect(),this.voice=0,this.isConnected=!1,this.isToolsAdded=!1,this.dc?.removeEventListener("message",this.onMessage),this.dc?.removeEventListener("open",this.onOpen),this.dc?.close(),this.pc?.getSenders().forEach(r=>{r.track&&r.track.stop()}),this.pc?.close(),this.pc=void 0}computeAnalysisForListenerEvent(r){if(r.analysis==="range"){let e=this.frequencies.slice(...r.analysisRange);return e.reduce((t,o)=>t+o,0)/e.length}return r.analysis==="single"?this.frequencies[r.analysisSingle]:this.voice}on(r,e){this.emitter.on(r,e)}off(r,e){this.emitter.off(r,e)}};function ev(i){return"variable_"+i}var vh=class extends pd{constructor(e){super();this.shared=e}create(e){return new Cs(e,this.shared)}},Gn=class{constructor(r,e={},t=!0,o=!1){this.data=r;this.needsJitter=t;this.enableLocalStorageForPersistentVariables=o;this.geometryCache=new Yl(!0);this.geometryCache2=new Yl(!1);this.imageHolderCache=new vh(this);this.thisContext={scene:Yb,shared:this};this.deletedMaterial=new Vn(Ft.defaultTwoLayerData("phong"),this.thisContext,"");this.deletedImage=new Rr(Eu.emptyImage,this);this.deletedVideo=new Rr(Aa.defaultVideo,this);this.materials={};this.images={};this.uiBuffers={};this.videos={};this.colors={};this.audios={};this.particles={};this.fonts={};this.variables={};this.userAPIs={};this.userWebhooks={};this.mouseProperty=null;this.raycastProperty=null;this.requestRender=()=>{this._requestRender&&this._requestRender()};if(e.images)for(let[n,a]of Object.entries(e.images))this.addImage(n,a);if(e.videos)for(let[n,a]of Object.entries(e.videos))this.addVideo(n,a);if(e.audios)for(let[n,a]of Object.entries(e.audios))this.addAudio(n,a);if(e.particles)for(let[n,a]of Object.entries(e.particles))this.addParticle(n,a);this.reset(r)}setRequestRender(r){this._requestRender=r}getImageLoadPromises(){return Object.values(this.images).map(r=>r.loadPromise)}setEntityOpContext(r){this.entityOpContext=r}reset(r,e=!1){this.data=r,this.resetLib(r.lib);for(let{id:t,data:o}of r.variables)this.addVariableHolder(t,o),e&&this.updateVariableHolder(t,o);for(let[t,o]of Object.entries(r.userAPIs))this.addUserAPI(t,o);for(let[t,o]of Object.entries(r.userWebhooks))this.addUserWebhook(t,o);for(let[t,o]of Object.entries(r.images))this.addImage(t,o);for(let[t,o]of Object.entries(r.videos))this.addVideo(t,o);for(let[t,o]of Object.entries(r.colors))this.addColor(t,o);for(let[t,o]of Object.entries(r.materials))this.addMaterial(t,o);for(let[t,o]of Object.entries(r.audios))this.addAudio(t,o);for(let[t,o]of Object.entries(r.particles))this.addParticle(t,o);for(let[t,o]of Object.entries(r.fonts))this.addFont(t,o)}addMaterial(r,e){if(this.materials[r]){let t=this.materials[r];t.reset(e,this.thisContext),t.dispose()}else{let t=new Vn(e,this.thisContext,r);this.materials[r]=t}}deleteMaterial(r){this.materials[r]&&(this.materials[r].nodeMaterialDispose(),delete this.materials[r])}getMaterial(r){let e=this.materials[r];return e}getMaterialOrDeletedPlaceholder(r){return this.materials[r]??this.deletedMaterial}material(r){return typeof r=="string"?this.getMaterialOrDeletedPlaceholder(r):r==null?(console.error("material is undefined or null"),this.deletedMaterial):new Bn(r,this.thisContext)}getMaterials(){return this.materials}addImage(r,e){return this.images[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.images[r].updateSrc(e.data),!0):(this.images[r]=new Rr(e,this),!1)}deleteImage(r){let e=this.images[r];e&&(e.dispose(),delete this.images[r])}getDefaultImage(){return this.images.image_0}getImage(r){return this.images[r]??this.deletedImage}image(r){return typeof r=="string"?this.getImage(r):this.imageHolderCache.load(r)}addUIBuffer(r,e){return this.uiBuffers[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.uiBuffers[r].updateSrc(e),!0):(this.uiBuffers[r]=new Rr(e,this),!1)}uiBuffer(r){return this.uiBuffers[r]}addVideo(r,e){return this.videos[r]?(this.videos[r].updateSrc(e.data),!0):(this.videos[r]=new Rr(e,this),!1)}deleteVideo(r){let e=this.videos[r];e&&(e.dispose(),delete this.videos[r])}getVideo(r){return this.videos[r]??this.deletedVideo}video(r){return typeof r=="string"?this.getVideo(r):this.imageHolderCache.load(r)}addColor(r,e){return this.colors[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),"a"in e?this.colors[r].setRGBA(e.r,e.g,e.b,e.a):this.colors[r].setRGBA(e.r,e.g,e.b,1),!0):("a"in e?this.colors[r]=new $i(e.r,e.g,e.b,e.a):this.colors[r]=new $i(e.r,e.g,e.b,1),!1)}updateColor(r,e){if(this.colors[r]){this.onColorOrImageUpdate&&this.onColorOrImageUpdate();let t=this.colors[r];return this.colors[r].r=e.r??t.r,this.colors[r].g=e.g??t.g,this.colors[r].b=e.b??t.b,this.colors[r].a=e.a??t.a,!0}return!1}deleteColor(r){this.colors[r]&&delete this.colors[r]}getColor(r){return this.colors[r]}getColorNames(){return Object.values(this.data.colors).map(r=>r.name)}getColorByName(r){for(let e in this.data.colors)if(this.data.colors[e].name===r)return{color:this.colors[e],id:e}}color(r){let e;if(typeof r=="string"){let t=this.getColor(r);t?e=t:(console.warn("Tried to create color layer params with a color key that does not exist in the assets manager"),e=new Ht(0,0,0,0))}else return"a"in r?new Ht(r.r,r.g,r.b,r.a):new Ht(r.r,r.g,r.b,1);return e}addAudio(r,e){this.audios[r]=e}getAudio(r){let e=this.audios[r];if(e instanceof zn)return e;{let t=new zn({src:e.data});return this.audios[r]=t,t}}addParticle(r,e){this.particles[r]=e}getParticle(r){return this.particles[r]}deleteParticle(r){this.particles[r]&&delete this.particles[r]}deleteAudio(r){let e=this.audios[r];e&&(e instanceof zn&&e.dispose(),delete this.audios[r])}addFont(r,e){this.fonts[r]=new bd(e),this.fonts[r].loadingPromise.then(()=>this.requestRender())}getFont(r){return this.fonts[r]}deleteFont(r){this.fonts[r]&&delete this.fonts[r]}dispose(){Object.keys(this.materials).forEach(e=>this.deleteMaterial(e)),this._requestRender=void 0,Object.values(this.audios).forEach(e=>{e instanceof zn&&e.dispose()}),this.audios={},this.particles={},this.geometryCache.dispose(),this.geometryCache2.dispose()}addVariableHolder(r,e){if(this.variables[r]===void 0){let t=e.value;if(this.enableLocalStorageForPersistentVariables&&e.persistent){let o=localStorage.getItem(ev(r));t=o!==null?JSON.parse(o):e.value}return this.variables[r]={value:t,locations:[],persistent:e.persistent},"dynamicVariableType"in e&&(this.variables[r].dynamicVariablePlayState="Playing",this.variables[r].dynamicVariableToggleIsForward=void 0),!0}return this.variables[r].value=e.value,!1}resetDynamicVariablePlayState(){for(let r in this.variables)this.variables[r].dynamicVariablePlayState!==void 0&&(this.variables[r].dynamicVariablePlayState="Playing",this.variables[r].dynamicVariableToggleIsForward=void 0)}updateVariableHolder(r,e){this.updateVariable(r,e.value)}updateVariable(r,e){if(this.variables[r]===void 0)return!1;this.variables[r].value=e,this.enableLocalStorageForPersistentVariables&&this.variables[r].persistent&&localStorage.setItem(ev(r),JSON.stringify(e));let t=e;for(;typeof t=="string";)t=this.variables[t].value;let o=this.entityOpContext.scene;for(let n=this.variables[r].locations.length-1;n>=0;n--){let a=this.variables[r].locations[n];if(a[0]==="material"){let s=a[1],l=t,c={scene:o,shared:this},u=a.slice(2);o.traverseMaterial(d=>{let f=d.root??d;f.uuid===s&&f.onVariableUpdate(u,l,c)});let p=this.materials[s];p&&p.onVariableUpdate(u,l,c)}else{let s=o.find(a[0]);if(s===void 0){this.variables[r].locations.splice(n,1);continue}if(a[1]!=="geometry"&&a[1]!=="particles"){for(let l=1;l<a.length-1;l++)s=s[a[l]];a[1]==="rotation"?s[a[a.length-1]]=t*bh.MathUtils.DEG2RAD:s[a[a.length-1]]=t}if(s=o.find(a[0]),s.type==="ParticleEmitter"&&s.updateVariableState(t,a),ze.is(s))if(a[1]==="position"||a[1]==="rotation"||a[1]==="scale")s.onVariableUpdate();else if(a[1]==="geometry"){let l=s;s.component&&(l=s.component);let c=l.dataPatched;l.chooseGeoemtryCache(this).forceDelete(c.geometry),l.createGeometryDelayed(this.entityOpContext),l.onVariableUpdate(!0),l.invalidateDownstreamBooleanData(),l.instances.forEach(u=>{let p=u.dataPatched;u.chooseGeoemtryCache(this).forceDelete(p.geometry),u.createGeometryDelayed(this.entityOpContext),u.onVariableUpdate(!0),u.invalidateDownstreamBooleanData()})}else a[1]==="morphTargetInfluences"&&s.updateMorphInfluences(a[2],t)}}return this.requestRender(),!0}deleteVariable(r){this.variables[r]&&delete this.variables[r]}getVariable(r,e){if(Array.isArray(r)){if(r[0]==="mouse")return this.mouseProperty?.[r[1]]??0;if(r[0]==="raycast")return this.raycastProperty?.[r[1]]??0;let t=this.entityOpContext.scene.find(r[0]);if(r[1]==="width"||r[1]==="height"||r[1]==="depth")return t.geometry.userData.parameters[r[1]];for(let o=1;o<r.length;o++)t=t[r[o]];return r[1]==="rotation"&&(t*=bh.MathUtils.RAD2DEG),t}for(let t in this.variables){if(e===void 0)break;let o=this.variables[t],n=o.locations?.findIndex(a=>ut.equal(a,e));n!==void 0&&n!==-1&&o.locations.splice(n,1)}if(typeof r=="string"){let t=r,o=r;do{if(o=t,this.variables[t]===void 0)break;let n=this.variables[t].value;e&&this.variables[o]!==void 0&&this.variables[o].locations.push(e),t=n}while(typeof t=="string");return t}else return r}getVariables(){return this.variables}getVariablesNames(){return this.data.variables.map(r=>r.data.name)}getVariableByName(r){for(let e of this.data.variables)if(e.data.name===r)return{variable:e.data,id:e.id}}getDynamicVariablePlayState(r){return this.variables[r]?.dynamicVariablePlayState}setDynamicVariablePlayState(r,e){this.variables[r]!==void 0&&(this.variables[r].dynamicVariablePlayState=e)}getDynamicVariableToggleIsForward(r){return this.variables[r]?.dynamicVariableToggleIsForward}setDynamicVariableToggleIsForward(r,e){this.variables[r]!==void 0&&(this.variables[r].dynamicVariableToggleIsForward=e)}resetLib(r){for(let[e,t]of Object.entries(r.images))this.addImage(e,t.asset);for(let[e,t]of Object.entries(r.audios))this.addAudio(e,t.asset);for(let[e,t]of Object.entries(r.particles))this.addParticle(e,t.asset);for(let[e,t]of Object.entries(r.colors))this.addColor(e,t.asset);for(let[e,t]of Object.entries(r.fonts))this.addFont(e,t.asset);for(let[e,t]of Object.entries(r.materials))this.addMaterial(e,t.asset);for(let[e,t]of Object.entries(r.videos))this.addVideo(e,t.asset);for(let[e,t]of Object.entries(r.variables))this.addVariableHolder(e,t.asset)}updateLibByOp(r,e){r.path[0]==="images"?r.path.length===1&&r.type===1?this.addImage(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteImage(r.id):r.path[0]==="videos"?r.path.length===1&&r.type===1?this.addVideo(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteVideo(r.id):r.path[0]==="audios"?r.path.length===1&&r.type===1?this.addAudio(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteAudio(r.id):r.path[0]==="particles"?r.path.length===1&&r.type===1?this.addParticle(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteParticle(r.id):r.path[0]==="colors"?r.path.length===1&&r.type===1?this.addColor(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteColor(r.id):r.path[0]==="materials"?r.path.length===1&&r.type===1?this.addMaterial(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteMaterial(r.id):r.path[0]==="fonts"?r.path.length===1&&r.type===1?this.addFont(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteFont(r.id):r.path[0]==="variables"?r.path.length===1&&r.type===1?this.addVariableHolder(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteVariable(r.id):r.path[0]==="components"&&e.updateByLibOp(r,this)}updateByOp(r,e,t){if(this.data=e,r.path[0]==="images")r.path.length===2&&r.type===0?r.props.data&&this.getImage(r.path[1]).updateSrc(r.props.data):r.path.length===1&&r.type===1?this.addImage(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteImage(r.id);else if(r.path[0]==="videos")r.path.length===2&&r.type===0?r.props.data&&this.getVideo(r.path[1]).updateSrc(r.props.data):r.path.length===1&&r.type===1?this.addVideo(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteVideo(r.id);else if(r.path[0]==="audios")r.path.length===2&&r.type===0?r.props.data&&this.addAudio(r.path[1],e.audios[r.path[1]]):r.path.length===1&&r.type===1?this.addAudio(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteAudio(r.id);else if(r.path[0]==="particles")r.path.length===2&&r.type===0?r.props.data&&this.addParticle(r.path[1],e.particles[r.path[1]]):r.path.length===1&&r.type===1?this.addParticle(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteParticle(r.id);else if(r.path[0]==="colors")r.path.length===2&&r.type===0?this.updateColor(r.path[1],r.props):r.path.length===1&&r.type===1?this.addColor(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteColor(r.id);else if(r.path[0]==="materials")r.path.length===1&&r.type===1?this.addMaterial(r.id,r.data):r.path.length===1&&r.type===2?this.deleteMaterial(r.id):r.path.length>1&&this.getMaterial(r.path[1]).updateByOp(bt.drop(r,2),e.materials[r.path[1]],{shared:this,scene:t});else if(r.path[0]==="fonts")r.path.length===2&&r.type===0?this.updateFont(r.path[1],r,t):r.path.length===1&&r.type===1?this.addFont(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteFont(r.id);else if(r.path[0]==="variables")r.path.length===2&&r.type===0?"value"in r.props?this.updateVariable(r.path[1],r.props.value):"persistent"in r.props&&(this.variables[r.path[1]].persistent=r.props.persistent):r.path.length===1&&r.type===4?this.addVariableHolder(r.id,r.data):r.path.length===1&&r.type===5&&this.deleteVariable(r.id);else if(r.path[0]==="userAPIs"){if(r.path.length===1&&r.type===1)this.addUserAPI(r.id,r.data);else if(r.path.length===1&&r.type===2)this.deleteUserAPI(r.id);else if(typeof r.path[1]=="string"){let o=e.userAPIs[r.path[1]];if(o){let n=r.type===0&&r.props.debounce===void 0,a=this.getUserAPI(r.path[1]);a instanceof Kl?a.update(o):a?.update(o,this,n)}}}else if(r.path[0]==="userWebhooks"){if(r.path.length===1&&r.type===1)this.addUserWebhook(r.id,r.data);else if(r.path.length===1&&r.type===2)this.deleteUserWebhook(r.id);else if(typeof r.path[1]=="string"){let o=e.userWebhooks[r.path[1]];o&&this.getUserWebhook(r.path[1])?.update(o)}}else r.path[0]==="lib"&&this.updateLibByOp(bt.drop(r,1),t)}updateFont(r,e,t){if(e.props.url){let o=this.getFont(r),n={...this.data.fonts[r],url:e.props.url};o.update(n),o.loadingPromise.then(()=>this.requestRender()),t.updateFont(r,this)}}addUserAPI(r,e){return this.userAPIs[r]?(this.userAPIs[r].update(e,this),!0):this.openAIRealtime?.id===r?(this.openAIRealtime.update(e),!0):e.integration?.type==="VoiceAssistant"?(this.openAIRealtime=new Kl(e,r,this),!1):(this.userAPIs[r]=new Qu(r,e,this),!1)}getUserAPI(r){return this.openAIRealtime?.id===r?this.openAIRealtime:this.userAPIs[r]}getUserAPIs(){return this.userAPIs}deleteUserAPI(r){let e=this.userAPIs[r];e&&(e.dispose(),delete this.userAPIs[r])}addUserWebhook(r,e){return this.userWebhooks[r]?(this.userWebhooks[r].update(e),!0):(this.userWebhooks[r]=new Sd(r,e),!1)}getUserWebhook(r){return this.userWebhooks[r]}getUserWebhooks(){return this.userWebhooks}deleteUserWebhook(r){let e=this.userWebhooks[r];e&&(e.dispose(),delete this.userWebhooks[r])}get scene(){return this.entityOpContext.scene}},tv=new Gn(Ur.emptyData());var Cr=class extends Ut{updateByPatchedOp(e,t,o){if(super.updateByPatchedOp(e,t,o),Ug(e.path,["materials"])!==null&&e.type===0&&Array.isArray(this.material))for(let[n,a]of Object.entries(e.props)){let s=o.shared.material(a);this.material[Number(n)]=s}else if(je(e.path,["material"])&&this.material instanceof Tr)"material"in t&&typeof t.material!="string"&&this.material.updateByOp(bt.drop(e,1),t.material,o);else if(je(e.path,["materials","*"])&&Array.isArray(this.material)){let n=e.path[1];if("materials"in t&&n<this.material.length){let a=t.materials[n];typeof a!="string"&&this.material[n].updateByOp(bt.drop(e,2),a,o)}}}get needsAO(){return this.material!==void 0?(Array.isArray(this.material)?this.material[0]:this.material).hasAO:!1}updateState(e,t){super.updateState(e,t),e.castShadow!==void 0&&(this.castShadow=e.castShadow),e.receiveShadow!==void 0&&(this.receiveShadow=e.receiveShadow);let o=this.dataPatched;this.dataPatched.type==="Mesh"&&!!this.dataPatched.geometry.shapeBlendNode&&this.layers.set(9);let a;if(this.dataPatched.type==="Mesh"&&this.dataPatched.geometry.type==="ShapeBlendGeometry"&&(a={resolutionLevel:this.dataPatched.geometry.resolutionLevel,useChildrenColors:this.dataPatched.geometry.useChildrenColors}),e.geometry?.type!=="NonParametricGeometry"&&"material"in e&&e.material!==void 0&&(this.disposeMaterial(),this.material=t.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe,a),t.scene.markNeedsUpdateRendererDirty()),(e.geometry?.type==="NonParametricGeometry"||"materials"in e)&&("materials"in e&&e.materials!==void 0?(this.disposeMaterial(),this.material=e.materials.map(s=>t.shared.material(s).getFlavor(o.flatShading,o.side,o.wireframe)),t.scene.markNeedsUpdateRendererDirty()):"material"in e&&e.material!==void 0&&(this.disposeMaterial(),this.material=[t.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe)],t.scene.markNeedsUpdateRendererDirty())),e.flatShading!==void 0||e.wireframe!==void 0||e.side!==void 0)if(Array.isArray(this.material))for(let s=0;s<this.material.length;s++)this.material[s]=this.material[s].getFlavor(o.flatShading,o.side,o.wireframe);else this.material=this.material.getFlavor(o.flatShading,o.side,o.wireframe,a)}disposeMaterial(){this.material&&vc(this.material).forEach(e=>{e instanceof Tr&&(e instanceof Vn||e.nodeMaterialDispose())})}dispose(){this.disposeMaterial(),super.dispose()}};var Lr=require("three");var rv=new Lr.Vector3,ov=new Lr.Vector4,iv=new Lr.Vector4,b3=new Lr.Vector3,nv=new Lr.Matrix4,ft=class extends Cr{constructor(e,t,o){super(e,t);this.data=t;this.isSkinnedMesh=!1;this.localGeometry=void 0,t.bindMode&&t.bindMatrix&&(this.bindMode=t.bindMode,this.bindMatrix=new Lr.Matrix4().fromArray(t.bindMatrix),this.bindMatrixInverse=new Lr.Matrix4)}chooseGeoemtryCache(e){return e.geometryCache}markGeometryAsReachable(e){this.geometryCreateDeleyed instanceof Lr.BufferGeometry&&this.chooseGeoemtryCache(e).markAsReachable(this.dataPatched.geometry,this.geometryCreateDeleyed)}get geometry(){if(this.localGeometry!==void 0)return this.localGeometry;if(this.geometryCreateDeleyed instanceof Gn){let e=this.geometryCreateDeleyed,t=this.chooseGeoemtryCache(e);this.geometryCreateDeleyed=t.get(this.dataPatched.geometry,e,this)}return this.geometryCreateDeleyed}set geometry(e){this.localGeometry=e}get is2DAndNoDepth(){let e=this.dataPatched.geometry;return fl.is2DParametricMesh(e.type)&&e.depth===0}get is2DType(){return fl.is2DParametricMesh(this.geometry.userData.type)}get isNonParametric(){return this.geometry.userData.type==="NonParametricGeometry"}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),je(e.path,["geometry"])&&this.updateByPatchedOpGeometry(bt.drop(e,1),t.geometry,o)}removeInteractionGeometry(e){this.localGeometry?.dispose(),this.localGeometry=void 0}updateGeometryInteractions(e,t){this.invalidateDownstreamBooleanData();let o=this.data.geometry.type;if(o==="NonParametricGeometry"||o==="SubdivGeometry"){let n=e;if(this.localGeometry===void 0){let u={...this.data.geometry,...n};this.localGeometry=ui(u,t,this.data.flatShading,this)}let a,s,l;n.scaleBaked?[a,s,l]=n.scaleBaked:{width:a,height:s,depth:l}=n;let c=this.localGeometry.userData;c.sxPrev!==void 0&&_l(this.localGeometry.attributes,a/c.sxPrev,s/c.syPrev,l/c.szPrev),c.sxPrev=a,c.syPrev=s,c.szPrev=l}else{let n={...this.data.geometry,...e};this.localGeometry?.dispose(),this.localGeometry=ui(n,t,this.data.flatShading,this)}}refreshAttachedClonersInteractions(){for(let e of this.attachedSurfaceCloners)e.update()}refreshAttachedCloners(e){for(let t of this.attachedSurfaceCloners)e.scene.addPendingUpdateCloner(t.object)}refreshAttachedPaths(e){for(let t of this.attachedPaths)e.scene.addPendingCommand(()=>t.updateShape())}createGeometryDelayed(e){this.geometryCreateDeleyed=e.shared,this.refreshAttachedCloners(e),this.refreshAttachedPaths(e)}updateByPatchedOpGeometry(e,t,o){let n=!1;e.type===0&&e.path.length===0&&Object.keys(e.props).includes("scaleBaked")&&this.geometryCreateDeleyed instanceof _t&&this.chooseGeoemtryCache(o.shared).mutateIfUnique(this.geometryCreateDeleyed.data,t)===this.geometryCreateDeleyed&&(n=!0,this.geometryCreateDeleyed.mutateDirectlyScaleBaked(t,e.props.scaleBaked),this.refreshAttachedCloners(o),this.refreshAttachedPaths(o)),n||(o.scene?.markGeometryCacheDirty(),this.createGeometryDelayed(o)),this.resetBBoxNeedsUpdate(),this.invalidateDownstreamBooleanData()}updateGeometryOnStateUpdate(e,t){this.createGeometryDelayed(t)}updateState(e,t){e.geometry!==void 0&&this.updateGeometryOnStateUpdate(e.geometry,t);let o=e.morphTargetInfluences;if(o){this.updateMorphTargets(),this.geometry.morphTargetsRelative=!0;for(let{data:{name:n,value:a}}of o)this.updateMorphInfluences(n,t.shared.getVariable(a,[this.uuid,"morphTargetInfluences",n]))}super.updateState(e,t)}updateMorphInfluences(e,t){if(this.morphTargetDictionary===void 0)return;let o=this.morphTargetDictionary[e];o!==void 0&&(this.morphTargetInfluences[o]=t)}updateGeometryGroupsIfNeeded(){Array.isArray(this.material)&&this.geometry.groups.length===0&&this.geometry.addGroup(0,Math.max(this.geometry.getIndex()?.count??0,this.geometry.getAttribute("position").count),0)}updateEntityBoxSize(e,t){let o=this.geometry.userData.parameters;this.is2DType?e.set(0,0,o.depth*.5):this.isNonParametric?(e.setScalar(0),this.geometry.boundingSphere&&e.copy(this.geometry.boundingSphere.center),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)):o.centerOffset?e.fromArray(o.centerOffset):e.setScalar(0),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)}updateMatrixWorld(e){super.updateMatrixWorld(e),this.bindMode==="attached"?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode==="detached"&&this.bindMatrixInverse.copy(this.bindMatrix).invert()}bind(e,t){this.skeleton=e,this.isSkinnedMesh=!0,t===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),t=this.matrixWorld),this.bindMatrix.copy(t),this.bindMatrixInverse.copy(t).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(e){let t=new Lr.Vector4,o=this.geometry.attributes.skinWeight;for(let n=0,a=o.count;n<a;n++){t.fromBufferAttribute(o,n);let s=1/t.manhattanLength();s!==1/0?t.multiplyScalar(s):t.set(1,0,0,0),o.setXYZW(n,t.x,t.y,t.z,t.w)}}boneTransform(e,t){let o=this.skeleton;if(o===void 0)return;let n=this.geometry;ov.fromBufferAttribute(n.attributes.skinIndex,e),iv.fromBufferAttribute(n.attributes.skinWeight,e),rv.copy(t).applyMatrix4(this.bindMatrix),t.set(0,0,0);for(let a=0;a<4;a++){let s=iv.getComponent(a);if(s!==0){let l=ov.getComponent(a);nv.multiplyMatrices(o.bones[l].matrixWorld,o.boneInverses[l]),t.addScaledVector(b3.copy(rv).applyMatrix4(nv),s)}}return t.applyMatrix4(this.bindMatrixInverse)}};function v3(i){if(i.geometry.attributes.extrudeNormal||!i.geometry.attributes.position||!i.geometry.attributes.normal)return;let r=new Map,e=i.geometry.attributes,t=e.position.array,o=e.normal.array,n=new Float32Array(t.length);for(let a=0;a<t.length;a+=3){let s=`${t[a]}_${t[a+1]}_${t[a+2]}`,l=new Br.Vector3(o[a],o[a+1],o[a+2]);r.has(s)?r.get(s)?.normals.push(l):r.set(s,{normals:[l],result:new Br.Vector3})}r.forEach((a,s)=>{for(let l of a.normals)a.result.add(l);a.result.divideScalar(a.normals.length)});for(let a=0;a<t.length;a+=3){let s=`${t[a]}_${t[a+1]}_${t[a+2]}`,l=r.get(s)?.result;l&&(n[a]=l.x,n[a+1]=l.y,n[a+2]=l.z)}i.geometry.setAttribute("extrudeNormal",new Br.Float32BufferAttribute(n,3))}function S3(i){if(i.geometry.attributes.extrudeNormals||!i.geometry.attributes.position)return;let e=i.geometry.attributes.position.array,t=new Float32Array(e.length),o=new Br.Vector3;for(let n=0;n<e.length;n+=3)o.set(e[n],e[n+1],e[n+2]).normalize(),t[n]=o.x,t[n+1]=o.y,t[n+2]=o.z;i.geometry.setAttribute("extrudeNormal",new Br.Float32BufferAttribute(t,3))}function Ms(i){if(Array.isArray(i.material)){for(let r of i.material)if(r.getLayersOfType("outline").length===0)return}else if(!(i.material instanceof Tr)||i.material.getLayersOfType("outline").length===0)return;i instanceof ft&&i.is2DAndNoDepth?S3(i):v3(i)}function Is(i){if(!i.geometry.attributes.position)return;let e=i.geometry.attributes.position.array,t=new Float32Array(e.length),o=parseInt(i.uuid.replace(/\D/g,"")),n=[Br.MathUtils.seededRandom(o),Br.MathUtils.seededRandom(o+1e4),Br.MathUtils.seededRandom(o+2e4)];for(let a=0;a<e.length;a++)t[a]=n[a%3];i.geometry.setAttribute("randomColor",new Br.BufferAttribute(t,3))}var zo=new mi.Box3,Ql=new mi.Vector3;function av(i){let r=!1;return i.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&t.geometry.type==="SubdivGeometry"&&(r=!0)}),r}var Fn=class extends ft{constructor(e,t,o){super(e,t,o);this.data=t;this.hiddenMatrixOld=new mi.Matrix4;this.smoothShading=!0;this.skipReactionUpdate=!1}chooseGeoemtryCache(e){return this.dataPatched.flatShading?e.geometryCache:e.geometryCache2}get subdivPointerNew(){return this.localGeometry!==void 0?this.subdivPointer:this.geometry.ensureSubdivPointer()}get originalGeometryNew(){return this.localGeometry!==void 0?this.originalGeometry:this.geometry.originalGeometry}get phongAngle(){return this.data.geometry.phongAngle??45}updateEntityBoxSize(e,t){let o=this.geometry.userData.parameters;e.copy(this.originalGeometryNew.boundingSphere.center),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)}createGeometryByControls(e){if(this.skipReactionUpdate===!0)return;let t=this.localGeometry?.uuid,{originalGeometry:o,subdividedGeometry:n,subdivPointer:a}=_t.build(e,this.subdivPointer,this.smoothShading,this.hasNonUniformScale?this.shearScale:void 0);this.subdivPointer=a,o!==void 0&&(this.originalGeometry?.dispose(),this.originalGeometry=o),n!==void 0&&(this.subdividedGeometry?.dispose(),this.subdividedGeometry=n??void 0),this.localGeometry=this.subdividedGeometry??this.originalGeometry,Ms(this),Is(this),this.calcBoundingBox(),t&&(this.localGeometry.uuid=t)}updateState(e,t){if(super.updateState(e,t),e.flatShading!==void 0){let o=this.material;this.material=Array.isArray(o)?o.map(n=>n.getFlavor(!1,n.side,n.wireframe)):o.getFlavor(!1,o.side,o.wireframe),this.smoothShading=!e.flatShading,this.createGeometryDelayed(t)}}updateMesh(e=!1){_t.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1,this.originalGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0),this.subdividedGeometry&&_t.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1,this.subdividedGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0)}updateTopology(){this.originalGeometry.dispose(),this.originalGeometry=_t.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1),this.subdividedGeometry&&(this.subdividedGeometry.dispose(),this.subdividedGeometry=_t.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1)),this.localGeometry=this.subdividedGeometry??this.originalGeometry}raycast(e,t){let o=this.localGeometry;this.localGeometry=this.originalGeometryNew,Ut.prototype.raycast.call(this,e,t),this.localGeometry=o}activateSVDCompensation(){!this.hasNonUniformScale||(this.matrix.copy(this.matrixWorldRigid),this.hiddenMatrixOld.copy(this.hiddenMatrix),this.hiddenMatrix.copy(this.parent.matrixWorld).invert())}deactivateSVDCompensation(){!this.hasNonUniformScale||(this.updateMatrix(),this.hasNonUniformScale=void 0,this.hiddenMatrix.copy(this.hiddenMatrixOld))}calcBoundingBox(){let e=this.originalGeometry;e.boundingSphere===null&&(e.boundingSphere=new mi.Sphere,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let t=e.attributes.position,o=e.boundingSphere.center;zo.setFromBufferAttribute(t),zo.getCenter(o),e.boundingSphere.radius=o.distanceTo(zo.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),zo.getSize(Ql),this.hasNonUniformScale&&Ql.divide(this.scale);let n={width:Ql.x,height:Ql.y,depth:Ql.z};return this.geometry.userData.parameters=n,n}updateBoundingSphere(e){let t=this.originalGeometry;zo.min.set(e[0],e[2],e[4]),zo.max.set(e[1],e[3],e[5]),this.hasNonUniformScale&&(zo.min.applyMatrix4(this.shearScaleInv),zo.max.applyMatrix4(this.shearScaleInv)),t.boundingSphere===null&&(t.boundingSphere=new mi.Sphere);let o=t.boundingSphere.center;zo.getCenter(o),t.boundingSphere.radius=o.distanceTo(zo.max)}freeSubdivPointer(){this.subdivPointer&&(_t.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0),this.localGeometry=void 0,this.originalGeometry?.dispose(),this.subdividedGeometry?.dispose()}dispose(){super.dispose(),this.freeSubdivPointer()}updateByPatchedOpGeometry(e,t,o){super.updateByPatchedOpGeometry(e,t,o),this.localGeometry&&this.createGeometryByControls(t)}};var Go=require("three"),sv=-1,w3=1,lv={x:[1,0,0],"-x":[-1,0,0],y:[0,1,0],"-y":[0,-1,0],z:[0,0,1],"-z":[0,0,-1]},cv={polygon_center:0,edge:1,vertex:2},Zl=(i,r)=>(e,t)=>!r||e===0||i===0?0:i*t/100,Ee=(i,r)=>{let e=Math.abs(r),t=e*-1;return(i-sv)*(e-t)/(w3-sv)+t},P3=new Go.Vector3,Td=new Go.Vector3,O3=new Go.Vector3,T3=new Go.Vector3;function Es(i,r){let e=O3.fromArray(i),t=T3.fromArray(r);Td.copy(t).sub(e);let o=Td.length();return Td.normalize().multiplyScalar(o*.5),P3.copy(e).add(Td).toArray()}var qr=new Go.Triangle,Cd=new Go.Vector3,Ad=new Go.Vector3,jn=new Go.Vector3;function uv(i){let r=[];for(let e=0;e<=i.index.count;e++)if(Cd.fromArray(i.index.array,e*3),qr.setFromAttributeAndIndices(i.attributes.position,Cd.x,Cd.y,Cd.z),qr.getNormal(Ad),qr.getMidpoint(jn),!(isNaN(jn.x)||isNaN(jn.y)||isNaN(jn.z))){let{a:t,b:o,c:n}=qr,a=t.toArray(),s=o.toArray(),l=n.toArray(),c=t.distanceTo(o),u=o.distanceTo(n),p=n.distanceTo(t),d=Es(a,s),f=Es(s,l),h=Es(l,a),m=[c,u,p],y=Math.max(...m),b=m.filter(O=>Math.round(O)===Math.round(y)).length>1,v=[],w=qr.getMidpoint(jn).toArray();y===c&&!b&&(v=[f,h,h],w=d),y===u&&!b&&(v=[d,h,h],w=f),y===p&&!b&&(v=[d,f,f],w=h),b&&(v=[d,f,h]),r.push({vertices:[a,s,l],faceCenters:v,midpoint:w,norm:qr.getNormal(Ad).toArray()})}return r}function dv(i){let r=[],{position:e}=i.attributes;for(let t=0;t<e.count;t++){qr.setFromAttributeAndIndices(e,t*3,t*3+1,t*3+2),qr.getNormal(Ad),qr.getMidpoint(jn);let o=qr.a.toArray(),n=qr.b.toArray(),a=qr.c.toArray();r.push({vertices:[o,n,a],faceCenters:[Es(o,n),Es(n,a),Es(a,o)],midpoint:jn.toArray(),norm:Ad.toArray()})}return r}var C3=4,A3=.5,wh=i=>.5*(1-Math.cos(i*Math.PI)),Ph=class{constructor(){this.perlin=new Array(4095+1)}noise(r,e=0,t=0){if(this.perlin==null){this.perlin=new Array(4095+1);for(let b=0;b<4095+1;b++)this.perlin[b]=Math.random()}r<0&&(r=-r),e<0&&(e=-e),t<0&&(t=-t);let o=Math.floor(r),n=Math.floor(e),a=Math.floor(t),s=r-o,l=e-n,c=t-a,u,p,d=0,f=.5,h,m,y;for(let b=0;b<C3;b++){let v=o+(n<<4)+(a<<8);u=wh(s),p=wh(l),h=this.perlin[v&4095],h+=u*(this.perlin[v+1&4095]-h),m=this.perlin[v+16&4095],m+=u*(this.perlin[v+16+1&4095]-m),h+=p*(m-h),v+=256,m=this.perlin[v&4095],m+=u*(this.perlin[v+1&4095]-m),y=this.perlin[v+16&4095],y+=u*(this.perlin[v+16+1&4095]-y),m+=p*(y-m),h+=wh(c)*(m-h),d+=h*f,f*=A3,o<<=1,s*=2,n<<=1,l*=2,a<<=1,c*=2,s>=1&&(o++,s--),l>=1&&(n++,l--),c>=1&&(a++,c--)}return d}noiseSeed(r){let e=(()=>{let a,s;return{setSeed(l){s=a=(l??Math.random()*4294967296)>>>0},getSeed(){return a},rand(){return s=(1664525*s+1013904223)%4294967296,s/4294967296}}})();e.setSeed(r),this.perlin=new Array(4095+1);for(let t=0;t<4095+1;t++)this.perlin[t]=e.rand()}},pv=Ph;var Ns=require("three");var fv=new Ns.Vector3,hv=new Ns.Matrix4,mv=new Ns.Ray;function yv(i){let r=!1;return i.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&(t.geometry.type==="TextGeometry"||t.geometry.type==="InputGeometry")&&(r=!0)}),r}var Ki=class extends ft{constructor(e,t,o){super(e,t,o);this.data=t}get textGeometry(){return this.geometry}get charWidths(){return this.textGeometry.charWidths}get charCoords(){return this.textGeometry.charCoords}get wrappedText(){return this.textGeometry.wrappedText}get font(){return this.textGeometry.font}get initialOffsetY(){let e=this.dataPatched;return this.font?.getLineInitialOffsetY(this.lineHeight,this.wrappedText.length,e.geometry.height,this.fontScale,e.geometry.verticalAlign)??0}get fontScale(){let e=this.dataPatched;return this.font?e.geometry.fontSize/this.font.unitsPerEm:1}get AD(){return Math.abs(this.ascender-this.descender)}get ascender(){return(this.font?.ascender??1)*this.fontScale}get descender(){return(this.font?.descender??1)*this.fontScale}get lineHeight(){let e=this.dataPatched;return e.geometry.fontSize*e.geometry.lineHeight}raycast(e,t){let{matrixWorld:o}=this;if(!(isNaN(e.ray.origin.x)||this.scale.x===0||this.scale.y===0||this.scale.z===0)&&(hv.copy(o).invert(),mv.copy(e.ray).applyMatrix4(hv),mv.intersectBox(this.singleBBox,fv))){let n=fv.applyMatrix4(o),a=e.ray.origin.distanceTo(n);t.push({distance:a,point:n.clone(),object:this})}}};var gr=1e-4,Fo,bv,vv,Sv,gv=new et.Vector3,xv=new et.Vector3;Ju.then(i=>{Fo=i,bv=[Fo.get_face_center,Fo.get_edge_midpoint,Fo.get_vertex_position],vv=[Fo.get_face_normal,Fo.get_edge_normal,Fo.get_vertex_normal],Sv=[Fo.face_count,Fo.edge_count,Fo.vertex_count]});var M3=new et.Matrix4,I3=new et.Matrix4,Qi=new et.Vector3,Md=new et.Vector3,Jl=new et.Vector3,Oh=new et.Vector3,E3=new et.Vector3,N3=new et.Vector3;var Th=class{constructor(r,e){this.data=r;this.is3D=e;this.perlin=new pv;r.noiseType==="perlin"?(this.perlin.noiseSeed(r.seed),e?this.noise=(o,n,a)=>this.perlin.noise(o,n,a):this.noise=o=>this.perlin.noise(o)):e?this.noise=Q0((0,Id.default)(r.seed)):this.noise=K0((0,Id.default)(r.seed))}},Zi=class extends za(et.Object3D){constructor(e,t){super();this.parameters=t;this.objectForSample=void 0;this._pendingMediaLoad=!1;this.random=null;this.object=e}resetOnMove(){this.removeFromParent(),this.parent=null}expandClones(e){if(this.parent===null)this.updateState(this.parameters,e);else for(let t of this.children)t instanceof ao&&t.expand()}invalidateTransform(e){this.matrixWorldNeedsUpdate=!0,this.traverse(t=>{t instanceof ao&&t.object===e&&(t.matrixWorldNeedsUpdate=!0)})}onObjUpdateMatrix(){this.parameters.type!=="toObject"&&(this.matrixWorldNeedsUpdate=!0)}update(){switch(this._updateCount(),this.parameters.type){case"radial":this._updateRadial(this.parameters);break;case"linear":this._updateLinear(this.parameters);break;case"grid":this._updateGrid(this.parameters);break;case"toObject":this._updateToObject(this.parameters)}for(let e of this.children)e.updateMatrix(),e.hasNonUniformScale&&(e.updateMatrixWorld(),e.updateMatrixWorldSVD())}_updateCount(e){let t;if(e!==void 0?t=e:t=this.parameters.type==="grid"?Math.round(this.parameters.grid.count[0])*Math.round(this.parameters.grid.count[1])*Math.round(this.parameters.grid.count[2]):this.parameters.count,this.parameters.type==="toObject"){if(!this.parameters.toObject.object)t=0;else if(e===void 0&&this.parameters.toObject.spreadType!=="random")return}if(this.parameters.type==="toObject"&&this.objectForSample){let o=this.children;if(o.length===t)return;if(o.length<t)for(let n=0,a=t-o.length;n<a;++n){let s=new ao(this.object);s.expand(),this.add(s)}else for(let n=0,a=o.length-t;n<a;++n)this.remove(o[n])}else{if(this.children.length===t)return;if(this.children.length<t)for(let o=0,n=t-this.children.length;o<n;++o){let a=new ao(this.object);a.expand(),this.add(a)}else for(let o=0,n=this.children.length-t;o<n;++o)this.remove(this.children[o])}}getRandom(e,t=!1){return(this.random===null||this.random.data.seed!==e.seed||this.random.is3D!==t)&&(this.random=new Th(e,t)),this.random}_updateRadial(e){let t=e.radial,o=t.start*et.MathUtils.DEG2RAD,n=t.end*et.MathUtils.DEG2RAD,a=o-n,s=new et.Euler(t.rotation[0],t.rotation[1],t.rotation[2]),l;switch(t.axis){case"z":l=new et.Vector3(0,0,1);break;case"y":l=new et.Vector3(0,1,0);break;default:case"x":l=new et.Vector3(1,0,0);break}let c=e.randomnessObject??Mo.defaultData([1,1,1]).randomnessObject,u=this.getRandom(c),p=Zl(c.strength,this.parameters.randomness);for(let[d,f]of this.children.entries()){let h=d*(c.freqScale/10)+c.movement,m=u.noise(h,h,h),y=d+1;f.scale.x=t.scale[0]+p(y,Ee(m,c.scale[0]))||gr,f.scale.y=t.scale[1]+p(y,Ee(m,c.scale[1]))||gr,f.scale.z=t.scale[2]+p(y,Ee(m,c.scale[2]))||gr,f.position.setScalar(0);let b=a/e.count*d-o;switch(t.axis){case"x":f.rotation.set(0,b,0);break;case"y":f.rotation.set(0,0,b);break;case"z":f.rotation.set(b,0,0);break}f.translateOnAxis(l,t.radius),f.position.x+=t.position[0]+p(y,Ee(m,c.position[0])),f.position.y+=t.position[1]+p(y,Ee(m,c.position[1])),f.position.z+=t.position[2]+p(y,Ee(m,c.position[2]));let v=p(y,Ee(m,c.rotation[0])),w=p(y,Ee(m,c.rotation[1])),O=p(y,Ee(m,c.rotation[2]));t.alignment===!0?(f.rotation.x+=s.x+v,f.rotation.y+=s.y+w,f.rotation.z+=s.z+O):f.rotation.set(s.x+v,s.y+w,s.z+O)}}_updateLinear(e){if(e.type!=="linear")throw new Error;let t=e.linear,o=new et.Euler(t.rotation[0],t.rotation[1],t.rotation[2]),n=e.randomnessObject??Mo.defaultData([1,1,1]).randomnessObject,a=this.getRandom(n),s=Zl(n.strength,this.parameters.randomness);for(let[l,c]of this.children.entries()){let u=l*(n.freqScale/10)+n.movement,p=a.noise(u,u,u),d=l+1,f=s(d,Ee(p,n.rotation[0])),h=s(d,Ee(p,n.rotation[1])),m=s(d,Ee(p,n.rotation[2]));c.scale.x=1+(t.scale[0]-1)*l+s(d,Ee(p,n.scale[0]))||gr,c.scale.y=1+(t.scale[1]-1)*l+s(d,Ee(p,n.scale[1]))||gr,c.scale.z=1+(t.scale[2]-1)*l+s(d,Ee(p,n.scale[2]))||gr,c.rotation.x=o.x*l+f,c.rotation.y=o.y*l+h,c.rotation.z=o.z*l+m,c.position.x=t.position[0]*l+s(d,Ee(p,n.position[0])),c.position.y=t.position[1]*l+s(d,Ee(p,n.position[1])),c.position.z=t.position[2]*l+s(d,Ee(p,n.position[2]))}}_updateGrid(e){let t=0,o=e.grid,n=e.randomnessObject??Mo.defaultData([1,1,1]).randomnessObject,a=this.getRandom(n,!0),s=Zl(n.strength,this.parameters.randomness);if(o.useCenter===!0){let l={x:o.count[0]%2===0?2:1,y:o.count[1]%2===0?2:1,z:o.count[2]%2===0?2:1},c=new et.Vector3(o.size[0]*(o.count[0]-l.x)*.5,o.size[1]*(o.count[1]-l.y)*.5,o.size[2]*(o.count[2]-l.z)*.5);for(let u=0;u<o.count[0];u++)for(let p=0;p<o.count[1];p++)for(let d=0;d<o.count[2];d++){let f=a.noise((u+1)*(n.freqScale/10)+n.movement,(p+1)*(n.freqScale/10)+n.movement,(d+1)*(n.freqScale/10)+n.movement),h=this.children[t++];h.scale.x=1+s(t,Ee(f,n.scale[0]))||gr,h.scale.y=1+s(t,Ee(f,n.scale[1]))||gr,h.scale.z=1+s(t,Ee(f,n.scale[2]))||gr;let m=s(t,Ee(f,n.rotation[0])),y=s(t,Ee(f,n.rotation[1])),b=s(t,Ee(f,n.rotation[2]));h.rotation.set(m,y,b),h.position.x=o.size[0]*u-c.x+s(t,Ee(f,n.position[0])),h.position.y=o.size[1]*p-c.y+s(t,Ee(f,n.position[1])),h.position.z=o.size[2]*d-c.z+s(t,Ee(f,n.position[2]))}}else for(let l=0;l<o.count[0];l++)for(let c=0;c<o.count[1];c++)for(let u=0;u<o.count[2];u++){let p=a.noise((l+1)*(n.freqScale/10)+n.movement,(c+1)*(n.freqScale/10)+n.movement,(u+1)*(n.freqScale/10)+n.movement),d=this.children[t++];d.scale.x=1+s(t,Ee(p,n.scale[0]))||gr,d.scale.y=1+s(t,Ee(p,n.scale[1]))||gr,d.scale.z=1+s(t,Ee(p,n.scale[2]))||gr;let f=s(t,Ee(p,n.rotation[0])),h=s(t,Ee(p,n.rotation[1])),m=s(t,Ee(p,n.rotation[2]));d.rotation.set(f,h,m),d.position.x=o.size[0]*l+s(t,Ee(p,n.position[0])),d.position.y=-o.size[1]*c+s(t,Ee(p,n.position[1])),d.position.z=-o.size[2]*u+s(t,Ee(p,n.position[2]))}}_updateToObject(e){if(e.type!=="toObject")throw new Error;let{toObject:t}=e,o=new et.Euler(t.rotation[0],t.rotation[1],t.rotation[2]),n=e.randomnessObject??Mo.defaultData([1,1,1]).randomnessObject,a=this.getRandom(n),s=Zl(n.strength,this.parameters.randomness);if(!t.object){for(let[,d]of this.children.entries())d.position.set(0,0,0),d.scale.setScalar(1),d.rotation.set(0,0,0);this.objectForSample=void 0;return}if(!this.objectForSample)return;if(this.objectForSample instanceof Ki)if(!this.objectForSample.font?.isLoaded||this.objectForSample.geometry.attributes.position===void 0){this._pendingMediaLoad=!0;return}else this._pendingMediaLoad=!1;if(this.objectForSample.geometry===void 0&&this.objectForSample.isAncestorOf(this.object.uuid)){console.warn(`Oh no! The object "${this.object.name}" (${this.object.uuid}) seem to be a child/descendant of the object it's being cloned to. Please re-parent it so that they are siblings instead.`);return}let l=this.getSubdivData();if(l.length>0){let d=Math.round(l.length*t.count/100);this._updateCount(d)}else{let d=this.objectForSample.geometry.getAttribute("position");if(!d||isNaN(d.count)||d.count===0){console.warn(`Oh no! The object "${this.object.name}" (${this.object.uuid}) cannot be cloned on the surface of "${this.objectForSample.name}" (${this.objectForSample.uuid}) because the latter does not have a valid geometry.`);return}}this.objectForSample.updateMatrixWorld();let c=new Lu(this.objectForSample).build(),u=lv[t.axis],p=this.children;c.setRandomGenerator((0,Id.default)(this.object.uuid+t.seed));for(let[d,f]of p.entries()){let h=d*(n.freqScale/10)+n.movement,m=a.noise(h,h,h),y=d+1,b=s(y,Ee(m,n.rotation[0])),v=s(y,Ee(m,n.rotation[1])),w=s(y,Ee(m,n.rotation[2]));t.spreadType==="random"?c.sample(Jl,Oh):(l.length&&(Jl.fromArray(l[d].pos),Oh.fromArray(l[d].norm)),this.objectForSample instanceof Fn&&Jl.applyMatrix4(M3.copy(this.objectForSample.matrixWorld).invert())),Jl.applyMatrix4(this.object.hiddenMatrix.clone().invert()),f.position.copy(Jl),Qi.fromArray(u);let O=t.align==="normal"?Oh:this.object.getWorldDirection(N3),S=Md.fromArray(t.position);Md.x+=s(y,Ee(m,n.position[0])),Md.y+=s(y,Ee(m,n.position[1])),Md.z+=s(y,Ee(m,n.position[2]));let T=Math.acos(O.dot(Qi)),A=E3.crossVectors(Qi,O).normalize(),g=I3.makeRotationAxis(A,T),D=O.clone().cross(this.object.up).normalize(),E=D.clone().cross(O).normalize(),I=new et.Matrix4().makeBasis(D,O,E),N=new et.Vector3(Qi.y,Qi.z,Qi.x).normalize(),_=N.clone().cross(Qi).normalize(),R=new et.Matrix4().makeBasis(N,Qi,_).invert(),V=new et.Matrix4().multiplyMatrices(I,R);f.rotation.setFromRotationMatrix(V),S.applyMatrix4(g),f.position.add(S),f.rotation.x=f.rotation.x+o.x+b,f.rotation.y=f.rotation.y+o.y+v,f.rotation.z=f.rotation.z+o.z+w,f.scale.setScalar(1),f.scale.x=f.scale.x+t.scale[0]+s(y,Ee(m,n.scale[0]))||gr,f.scale.y=f.scale.y+t.scale[1]+s(y,Ee(m,n.scale[1]))||gr,f.scale.z=f.scale.z+t.scale[2]+s(y,Ee(m,n.scale[2]))||gr,f.scale.multiply(this.object.scale),f.hiddenMatrix=this.object.hiddenMatrix}}getSubdivData(){if(!this.objectForSample)return[];let e=this.parameters.toObject.spreadType,t=new Map,o=(a,s)=>{let l=Math.round(a[0]*1e4)+"_"+Math.round(a[1]*1e4)+"_"+Math.round(a[2]*1e4),c=t.get(l);c?(c.pos[0]+=a[0],c.pos[1]+=a[1],c.pos[2]+=a[2],c.norm[0]+=s[0],c.norm[1]+=s[1],c.norm[2]+=s[2],c.count+=1):t.set(l,{pos:[...a],norm:[...s],count:1})};if(e==="random")return[];if(this.objectForSample instanceof Fn){let a=this.objectForSample,s=cv[e],l=Sv[s],c=bv[s],u=vv[s],p=l(a.subdivPointerNew);for(let d=0;d<=p-1;d++){let f=c(a.subdivPointerNew,d),h=u(a.subdivPointerNew,d);gv.fromArray(f).applyMatrix4(a.matrixWorld),xv.fromArray(h),o(gv.toArray(),xv.toArray())}}else(this.objectForSample.geometry.index?uv(this.objectForSample.geometry):dv(this.objectForSample.geometry)).forEach((s,l)=>{e==="polygon_center"&&o(s.midpoint,s.norm),e==="vertex"&&(o(s.vertices[0],s.norm),o(s.vertices[1],s.norm),o(s.vertices[2],s.norm)),e==="edge"&&(o(s.faceCenters[0],s.norm),o(s.faceCenters[1],s.norm),o(s.faceCenters[2],s.norm))});let n=Array.from(t.values());for(let a of n)a.pos[0]/=a.count,a.pos[1]/=a.count,a.pos[2]/=a.count,a.norm[0]/=a.count,a.norm[1]/=a.count,a.norm[2]/=a.count;return n}updateState(e,t){if(this.parameters=Qo(e),this.parameters.type!=="toObject")(this.parent===null||this.parent!==this.object)&&(this.removeFromParent(),this.object.parent?.add(this),this.matrix=this.object.matrix,this.hiddenMatrix=this.object.hiddenMatrix,this.matrixWorldNeedsUpdate=!0,this.matrixAutoUpdate=!1);else if(this.parent===null||this.parent.uuid!==this.parameters.toObject.object){this.removeFromParent();let o=t.find(this.parameters.toObject.object);o instanceof Ut?this.objectForSample=o:this.objectForSample=void 0,this.matrix=new et.Matrix4,this.hiddenMatrix=new et.Matrix4,this.matrixWorldNeedsUpdate=!0,this.matrixAutoUpdate=!1,o&&o.add(this)}this.update()}get pendingMediaLoad(){return this._pendingMediaLoad}};var Jr=require("three");var gt=require("three");var ar=require("three");var wv=require("three"),jo=i=>{var r;return r=class extends i{},r.geometryHelper=new wv.BoxGeometry(30,30,30),r};var dr=require("three"),Ed=new dr.Ray,Ch=new dr.Sphere,Pv=new dr.Matrix4,Uo=(i,r,e,t,o=!1,n=i)=>{let a=r,s=n.matrixWorld;if(a.boundingSphere===null&&a.computeBoundingSphere(),Ch.copy(a.boundingSphere),Ch.applyMatrix4(s),e.ray.intersectsSphere(Ch)===!1||(Pv.copy(s).invert(),Ed.copy(e.ray).applyMatrix4(Pv),a.boundingBox!==null&&Ed.intersectsBox(a.boundingBox)===!1))return;let l,c,u,p,d=a.index,f=a.attributes.position,h=a.drawRange,m,y;if(o===!1){let v=Math.max(0,h.start),w=Math.min(d.count,h.start+h.count);for(m=v,y=w;m<y;m+=3)if(c=d.getX(m),u=d.getX(m+1),p=d.getX(m+2),l=b(i,e,Ed,f,c,u,p),l){l.faceIndex=Math.floor(m/3),t.push(l);return}}else{let w=a.attributes.position,O=new dr.Vector3,S=new dr.Vector3,T=new dr.Vector3,A=new dr.Vector3,g=2,E=1/((n.scale.x+n.scale.y+n.scale.z)/3),I=E*E,N=Math.max(0,h.start),_=Math.min(w.count,h.start+h.count);for(let R=N,V=_-1;R<V;R+=g){if(O.fromBufferAttribute(w,R),S.fromBufferAttribute(w,R+1),Ed.distanceSqToSegment(O,S,A,T)>I)continue;A.applyMatrix4(n.matrixWorld);let B=e.ray.origin.distanceTo(A);B<e.near||B>e.far||t.push({distance:B,point:T.clone().applyMatrix4(n.matrixWorld),object:i})}}function b(v,w,O,S,T,A,g){let D=new dr.Vector3,E=new dr.Vector3,I=new dr.Vector3,N=new dr.Vector3,_=new dr.Vector3;if(D.fromBufferAttribute(S,T),E.fromBufferAttribute(S,A),I.fromBufferAttribute(S,g),O.intersectTriangle(D,E,I,!1,N)===null)return null;_.copy(N),_.applyMatrix4(v.matrixWorld);let V=w.ray.origin.distanceTo(_);return V<w.near||V>w.far?null:{faceIndex:1,distance:V,point:_.clone(),object:v}}};var Nd=new ar.Vector3,$r=new ar.Camera,Ah=class extends ar.LineSegments{constructor(e){let t=new ar.BufferGeometry,o=new ar.LineBasicMaterial({color:16777215,vertexColors:!0,toneMapped:!1}),n=[],a=[],s={},l=new ar.Color(15711266),c=new ar.Color(15711266),u=new ar.Color(2857471);p("n1","n2",l),p("n2","n4",l),p("n4","n3",l),p("n3","n1",l),p("f1","f2",l),p("f2","f4",l),p("f4","f3",l),p("f3","f1",l),p("n1","f1",l),p("n2","f2",l),p("n3","f3",l),p("n4","f4",l),p("p","n1",c),p("p","n2",c),p("p","n3",c),p("p","n4",c),p("u1","u2",u),p("u2","u3",u),p("u3","u1",u);function p(f,h,m){d(f,m),d(h,m)}function d(f,h){n.push(0,0,0),a.push(h.r,h.g,h.b),s[f]===void 0&&(s[f]=[]),s[f].push(n.length/3-1)}t.setAttribute("position",new ar.Float32BufferAttribute(n,3)),t.setAttribute("color",new ar.Float32BufferAttribute(a,3));super(t,o);this.type="CameraHelper",this.camera=e,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=e.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=s,this.update()}update(){let e=this.geometry,t=this.pointMap,o=!0;$r.projectionMatrixInverse.elements=[.5112609807824982,-0,-0,-0,-0,.41421356237309503,-0,-0,-0,-0,-0,-.099999,-0,-0,-1.0000000000000002,.100001];let n=1,a=1,s=o?.8:1e-4;bo("n1",t,e,$r,-n,-a,s),bo("n2",t,e,$r,n,-a,s),bo("n3",t,e,$r,-n,a,s),bo("n4",t,e,$r,n,a,s);let l=s;bo("f1",t,e,$r,-n,-a,l),bo("f2",t,e,$r,n,-a,l),bo("f3",t,e,$r,-n,a,l),bo("f4",t,e,$r,n,a,l);let c=l,u=.5;bo("u1",t,e,$r,n*.7*u,a*1.1,c),bo("u2",t,e,$r,-n*.7*u,a*1.1,c),bo("u3",t,e,$r,0,a*(1.1+.9*u),c),e.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}};function bo(i,r,e,t,o,n,a){Nd.set(o,n,a).unproject(t);let s=r[i];if(s!==void 0){let l=e.getAttribute("position");for(let c=0,u=s.length;c<u;c++)l.setXYZ(s[c],Nd.x,Nd.y,Nd.z)}}var Dd=class extends jo(Ah){constructor(e){super(e);this.object=e;this.object=e,this.name=`CombinedCameraHelper: ${e.uuid}`}updateMatrixWorld(e){super.updateMatrixWorld(e),this.updateTarget()}updateTarget(){let e=this.object.getTarget();this.updateWorldMatrix(!0,!1),this.worldToLocal(e)}raycast(e,t){Uo(this.object,this.geometry,e,t,!0)}};var ec=require("three");var _d;(r=>r.is=e=>"objectHelper"in e)(_d||(_d={}));var Xr=(i,r)=>class extends ja(i){constructor(){super(...arguments);this.objectHelper=new r(this);this.gizmos={}}get geometryHelper(){return r.geometryHelper}raycast(o,n){this.objectHelper.raycast(o,n)}showGizmos(){for(let o in this.gizmos){let n=this.gizmos[o];n instanceof ec.Box3Helper&&(n.visible=!0)}}updateEntityBoxSize(o,n){this.objectHelper.visible&&this.geometryHelper instanceof ec.BoxGeometry?(o.setScalar(0),n.set(this.geometryHelper.parameters.width,this.geometryHelper.parameters.height,this.geometryHelper.parameters.height).multiplyScalar(.5)):super.updateEntityBoxSize(o,n)}hideGizmos(){for(let o in this.gizmos){let n=this.gizmos[o];n instanceof ec.Box3Helper&&(n.visible=!1)}}};var Rd=790,Ds=new gt.Vector3,Mh=new gt.Vector3,Ih=new gt.Quaternion,Eh=new gt.Vector3,tc=new gt.Vector3,Nh=new gt.Vector3,yi=class extends Xr(gt.Camera,Dd){constructor(e="",t={...Pn.defaultData,name:""}){super();this._cameraType="OrthographicCamera";this.targetOffset=Li.DefaultTargetOffset;this.isUpVectorFlipped=!1;this.angleOffsetFromUp=0;this.wasMovedByUser=!1;this.wasMovedBySwitchCameraAction=!1;this.super_Entity(e,t),this.previousProjectionMatrix=new gt.Matrix4,this.matrixAutoUpdate=!0,this.width=window.innerWidth,this.height=window.innerHeight;let o=this.width,n=this.height;this.orthoCamera=new gt.OrthographicCamera(o*-.5,o*.5,n*.5,n*-.5,-5e4,1e4),this.perspCamera=new gt.PerspectiveCamera(45,o/n,50,1e4),this.left=this.orthoCamera.left,this.right=this.orthoCamera.right,this.top=this.orthoCamera.top,this.bottom=this.orthoCamera.bottom,this.far=this.orthoCamera.far,this.view=this.orthoCamera.view,this.aspect=this.perspCamera.aspect,this.focus=this.perspCamera.focus,this.filmGauge=this.perspCamera.filmGauge,this.filmOffset=this.perspCamera.filmOffset,this.objectHelper.update()}get isPerspectiveCamera(){return this.cameraType==="PerspectiveCamera"}get isOrthographicCamera(){return!this.isPerspectiveCamera}get cameraType(){return this._cameraType}set fov(e){this.perspCamera.fov=e}get fov(){return this.perspCamera.fov}setNear(e,t){e==="PerspectiveCamera"?this.perspCamera.near=t:this.orthoCamera.near=t}setZoom(e,t){t>=0&&(e==="PerspectiveCamera"?this.perspCamera.zoom=t:this.orthoCamera.zoom=t)}set cameraType(e){e==="PerspectiveCamera"?this.toPerspective():e==="OrthographicCamera"&&this.toOrthographic()}get near(){return this._cameraType==="PerspectiveCamera"?this.perspCamera.near:this.orthoCamera.near}set near(e){this._cameraType==="PerspectiveCamera"?this.perspCamera.near=e:this.orthoCamera.near=e}get zoom(){return this._cameraType==="PerspectiveCamera"?this.perspCamera.zoom:this.orthoCamera.zoom}set zoom(e){e>=0&&(this._cameraType==="PerspectiveCamera"?this.perspCamera.zoom=e:this.orthoCamera.zoom=e)}lookAt(e,t,o){typeof e=="number"&&(e=new gt.Vector3(e,t,o)),super.lookAt(e),this.getWorldPosition(Ds),this.targetOffset=Ds.distanceTo(e)}getTarget(e=new gt.Vector3){return this.getWorldDirection(Mh),this.getWorldPosition(Ds),Mh.multiplyScalar(this.targetOffset),e.copy(Ds).add(Mh),e}getDistanceToTarget(){let e=this.getTarget();return this.getWorldPosition(Ds),Ds.distanceTo(e)}updateUp(){this.getWorldQuaternion(Ih),Eh.set(0,0,1).applyQuaternion(Ih),tc.copy(gt.Object3D.DEFAULT_UP),this.isUpVectorFlipped&&tc.negate(),tc.applyQuaternion(Ih),Nh.copy(gt.Object3D.DEFAULT_UP).projectOnPlane(Eh),this.angleOffsetFromUp=Nh.angleTo(tc),this.angleOffsetFromUp*=Nh.cross(tc).dot(Eh)>=0?1:-1}updateTransformState(e,t){let o=super.updateTransformState(e,t);return e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateUp(),o}getViewFrontToObject(e){let t=e.getWorldPosition(new gt.Vector3),n=e.getWorldDirection(new gt.Vector3).multiplyScalar(this.targetOffset);return{position:t.clone().add(n),target:t}}getViewToTarget(e){let o=this.getWorldDirection(new gt.Vector3).multiplyScalar(this.targetOffset);return{position:e.clone().sub(o),target:e}}getViewToObject(e){let t=new gt.Vector3,o=e.getWorldPosition(t);return this.getViewToTarget(t)}setViewplaneSize(e,t,o=!1){if(this.aspect=e/t,o){let n=e>t?this.aspect:1,a=e>t?1:this.aspect;this.left=-Rd*.5*n,this.right=Rd*.5*n,this.top=Rd*.5*(1/a),this.bottom=-Rd*.5*(1/a)}else this.left=-e*.5,this.right=e*.5,this.top=t*.5,this.bottom=-t*.5;this.updateProjectionMatrix()}copyViewPlaneSize(e){this.aspect=e.aspect,this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.updateProjectionMatrix()}toOrthographic(){this.orthoCamera.left=this.left,this.orthoCamera.right=this.right,this.orthoCamera.top=this.top,this.orthoCamera.bottom=this.bottom,this.orthoCamera.view=this.view,this.orthoCamera.far=this.far,this.orthoCamera.updateProjectionMatrix(),this.projectionMatrix=this.orthoCamera.projectionMatrix,this.projectionMatrixInverse=this.orthoCamera.projectionMatrixInverse,this._cameraType="OrthographicCamera",this.objectHelper&&this.objectHelper.update()}toPerspective(){this.perspCamera.aspect=this.aspect,this.perspCamera.fov=this.fov,this.perspCamera.view=this.view,this.perspCamera.far=this.far,this.perspCamera.updateProjectionMatrix(),this.projectionMatrix=this.perspCamera.projectionMatrix,this.projectionMatrixInverse=this.perspCamera.projectionMatrixInverse,this._cameraType="PerspectiveCamera",this.objectHelper&&this.objectHelper.update()}setFocalLength(e){this.perspCamera.setFocalLength(e),this.toPerspective()}getFocalLength(){return this.perspCamera.getFocalLength()}getEffectiveFOV(){return this.perspCamera.getEffectiveFOV()}getFilmWidth(){return this.perspCamera.getFilmWidth()}getFilmHeight(){return this.perspCamera.getFilmHeight()}setViewOffset(e,t,o,n,a,s){this._cameraType==="PerspectiveCamera"?this.perspCamera.setViewOffset(e,t,o,n,a,s):this.orthoCamera.setViewOffset(e,t,o,n,a,s)}clearViewOffset(){this._cameraType==="PerspectiveCamera"?(this.perspCamera.clearViewOffset(),this.toPerspective()):(this.orthoCamera.clearViewOffset(),this.toOrthographic())}copyHistory(){this.previousProjectionMatrix&&this.previousProjectionMatrix.copy(this.projectionMatrix)}updateProjectionMatrix(){this._cameraType==="PerspectiveCamera"?this.toPerspective():this._cameraType==="OrthographicCamera"&&this.toOrthographic()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}copy(e,t){return super.copy(e,t),this.parent=e.parent,this.orthoCamera.copy(e.orthoCamera),this.perspCamera.copy(e.perspCamera),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.far=e.far,this.view=e.view===null?null:Object.assign({},e.view),this._cameraType=e._cameraType,this.aspect=e.aspect,this.fov=e.fov,this.focus=e.focus,this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this.targetOffset=e.targetOffset,this.updateProjectionMatrix(),this}toCameraState(e=[]){let t={type:this.cameraType,far:this.far,orthographic:{near:this.orthoCamera.near,zoom:this.orthoCamera.zoom},perspective:{near:this.perspCamera.near,fov:this.perspCamera.fov,zoom:this.perspCamera.zoom},up:this.up.toArray(),targetOffset:this.targetOffset,isUpVectorFlipped:this.isUpVectorFlipped};return ya(t,e)}updateCameraSubtype(e,t){let o=e==="perspective"?"PerspectiveCamera":"OrthographicCamera";t.zoom!==void 0&&this.setZoom(o,t.zoom),t.near!==void 0&&this.setNear(o,t.near),t.fov!==void 0&&o==="PerspectiveCamera"&&(this.fov=t.fov)}updateState(e,t){this.updateCameraState(e,t)}updateCameraState(e,t){this.updateState_Entity(e,t),e.far!==void 0&&(this.far=e.far),e.orthographic!==void 0&&this.updateCameraSubtype("orthographic",e.orthographic),e.perspective!==void 0&&this.updateCameraSubtype("perspective",e.perspective),e.type!==void 0&&(this.cameraType=e.type),e.up!==void 0&&this.up.fromArray(e.up),e.targetOffset!==void 0&&(this.targetOffset=e.targetOffset),e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateProjectionMatrix()}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.path.length===1&&e.type===0&&this.updateCameraSubtype(e.path[0],e.props)}toState(e){return{...super.toState(e),...this.toCameraState(e),type:this.cameraType}}};var R3=require("three");var Ji=require("three");var _s=new Ji.Matrix4,_3=new Ji.Matrix4;var Ar=class extends Cr{constructor(e,t,o){super(e,t);this.data=t;this.meshSetAddresses=[];this.needsTransformForDownstream=!1;this.geometry=new Ji.BufferGeometry;this.onAfterRender=(e,t,o,n,a,s)=>{super.onAfterRender(e,t,o,n,a,s),this.recomputeBoolean()};this.geometry.userData.parameters={width:0,height:0,depth:0}}get booleanOp(){return this.data.geometry.operation}get phongAngle(){return this.data.geometry.phongAngle??45}get isLOD(){return this.recomputeBoolean(),!1}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.path.length===1&&e.path[0]==="geometry"&&e.type===0&&e.props.operation!==void 0&&(this.freeBooleanPointer(),this.resetBBoxNeedsUpdate())}freeBooleanPointer(){super.freeBooleanPointer(),this.geometry.dispose()}recomputeBoolean(e,t=!0){if(this.booleanMeshSetAddress!==-1&&!e)return;for(let n=0;n<this.children.length;n++){let a=this.children[n];a instanceof Ar&&a.dataPatched.visible===!0&&a.recomputeBoolean(e===!0,t)}this.meshSetAddresses=[];for(let n=0;n<this.children.length;n++){let a=this.children[n];if(a instanceof Ut&&a.dataPatched.visible===!0&&a.geometry.attributes.position?.count>0&&a.geometry.drawRange.count>0&&a.booleanMeshSetAddress!==0){_s.multiplyMatrices(a.hiddenMatrix,a.matrix);try{if(a.booleanMeshSetAddress===-1){if((a.geometry.index??a.geometry.getAttribute("position")).count/3<15e5&&(a.booleanMeshSetAddress=Hr.getMeshSet(a.geometry,e===!0,t)),a.booleanMeshSetAddress===-1)return;Hr.transformMeshSet(a.booleanMeshSetAddress,_s),a.booleanMatrixInvOld.copy(_s).invert(),a.booleanWasTransformed=!1}else a instanceof Ar&&a.needsTransformForDownstream===!0?(Hr.transformMeshSet(a.booleanMeshSetAddress,_s),a.needsTransformForDownstream=!1):a.booleanWasTransformed===!0&&(Hr.transformMeshSet(a.booleanMeshSetAddress,_3.multiplyMatrices(_s,a.booleanMatrixInvOld)),a.booleanMatrixInvOld.copy(_s).invert(),a.booleanWasTransformed=!1)}catch(s){console.error(s),a.booleanMeshSetAddress=0,a.geometry.userData.booleanOperationDidFail=!0;continue}Hr.hasOpenEdges(a.booleanMeshSetAddress)===!1||n===this.children.length-1&&this.booleanOp===2?(this.meshSetAddresses.push(a.booleanMeshSetAddress),a.geometry.userData.booleanOperationDidFail=!1):a.geometry.userData.booleanOperationDidFail="openEdges"}}if(this.meshSetAddresses.length===0){this.geometry.setAttribute("position",new Ji.Float32BufferAttribute([],0)),this.geometry.setDrawRange(0,0);return}if(e===!0)return Hr.calcBooleanTopological(this.meshSetAddresses,this.booleanOp);let o=this.geometry;o.dispose(),this.geometry=new Ji.BufferGeometry,this.geometry.userData=o.userData,this.geometry.boundingSphere=o.boundingSphere;try{this.booleanMeshSetAddress=Hr.calcBoolean(this.meshSetAddresses,this.booleanOp,this.geometry,this.phongAngle)}catch(n){this.booleanMeshSetAddress=0,this.geometry.userData.booleanOperationDidFail=!0,console.error(n)}this.booleanMatrixInvOld.copy(this.matrix).invert(),this.needsTransformForDownstream=!0,Ms(this),Is(this)}dispose(){super.dispose(),this.geometry.dispose()}};var Tv=require("three");var Ov;(r=>{function i(e){return ze.is(e)&&e instanceof Tv.Light}r.is=i})(Ov||(Ov={}));var Rs=(i,r)=>class extends Xr(i,r){updateState_Light(t,o){this.updateState_Entity(t,o),t.color!==void 0&&(this.color=o.shared.color(t.color)),t.intensity!==void 0&&(this.intensity=t.intensity),t.depth!==void 0&&(this.shadow.camera.far=t.depth,this.shadow.needsUpdate=!0),t.shadows!==void 0&&(this.castShadow=t.shadows)}};var en=i=>i instanceof Ut,rc=i=>i!==null&&i instanceof Ar;var oc=i=>_d.is(i);var Mv=require("three");var ko=require("three");var L3=new ko.Vector3(1,1,1),Cv=new ko.Vector3,B3=new ko.Vector3,Av=new ko.Quaternion,Yr=class extends jo(ko.AxesHelper){constructor(e,t=15){super(t);this.object=e;this.dummy=new ko.Group;this.object.updateMatrixWorld(),this.name=`EmptyObjectHelper: ${e.uuid}`,this.matrix=this.dummy.matrixWorld,this.matrixAutoUpdate=!1,this.object.isBone&&(this.visible=!1)}raycast(e,t){Uo(this.object,Yr.geometryHelper,e,t,!1,this.dummy)}update(){}updateMatrix(){}updateMatrixWorld(e){this.object.matrixWorld.decompose(Cv,Av,B3),this.matrix.compose(Cv,Av,L3),super.updateMatrixWorld(e)}updateWorldMatrix(e,t){}};var tn=class extends Xr(Mv.Group,Yr){constructor(r,e){super(),this.super_Entity(r,e),this.objectHelper.update()}updateState(r,e){this.updateState_Entity(r,e),"buffer"in r&&Object.keys(r).length===1&&e.scene.reloadSplats()}};var Iv=require("three");var Ls=class extends Xr(Iv.Group,Yr){constructor(e,t,o){super();this.super_Entity(e,t),this.context=o,this.objectHelper.update()}updateState(e,t){this.updateState_Entity(e,t)}};var ks=require("three");var Bs=require("three"),V3=i=>`
|
|
2289
|
+
`)>=0&&(r-=n),t===3?e*.5-r*.5:t===2?e-r:0}getLineInitialOffsetY(r,e,t,o,n){let a=e*r,s=Math.abs(this.ascender-this.descender)*o,l=r-s,c=-this.ascender*o-l/2;return n===3?-(t-a-c):n===2?-(t*.5-a*.5-c):c}createPath(r,e,t,o,n){let a=r.getPath(t,-o,n.fontSize,{kerning:!1,letterSpacing:n.letterSpacing});if(!a){console.error('THREE.Font: character "'+r+'" does not exists in font family '+this.familyName+".");return}let s=new gd,l=(r.advanceWidth??1)*e;if(r)for(let c of a.commands){let u=s.currentPath?.currentPoint;if(!(u&&c.type!=="Z"&&u.x===c.x&&-u.y===c.y))switch(c.type){case"M":s.moveTo(c.x,-c.y);break;case"L":s.lineTo(c.x,-c.y);break;case"Q":s.quadraticCurveTo(c.x1,-c.y1,c.x,-c.y);break;case"C":s.bezierCurveTo(c.x1,-c.y1,c.x2,-c.y2,c.x,-c.y);break}}return s.subPaths.forEach(c=>{let u=d3(c.curves);u!==void 0&&c.currentPoint.distanceTo(u)>0&&c.lineTo(u.x,u.y)}),{offsetX:l+n.fontSize*n.letterSpacing,path:s}}getCharWidth(r,e){return this.font?.getAdvanceWidth(r,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}getTextWidth(r,e){return this.font?.getAdvanceWidth(r,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}computeSpaceWidthForLine(r,e,t){let o=this.getCharWidth(" ",t),n=r[e];if(n){let a=this.countSpaces(n.trimEnd());if(t.horizontalAlign===4&&e<r.length-1&&a){let s=t.width,l=this.getTextWidth(n,t);return(s-(l-a*o))/a}}return o}countSpaces(r){return(r.match(/ /g)||[]).length}};function d3(i){if(i.length){let r=i[0];if(r instanceof As.LineCurve)return r.v1;if(r instanceof As.CubicBezierCurve||r instanceof As.QuadraticBezierCurve)return r.v0}}var yh=class{constructor(){this.objects=new Map;this.unreachable=new Set}getCached(r){return this.objects.get(r)}get size(){return this.objects.size}get(r,e,t){let o=this.objects.get(r);return o===void 0?(o=this.createObject(r,e,t),this.objects.set(r,o)):o.isShared=!0,o}forceDelete(r){let e=this.objects.get(r);e&&(this.disposeObject(e),this.objects.delete(r))}mutateIfUnique(r,e){let t=this.objects.get(r);if(t&&t.isShared!==!0)return this.objects.delete(r),this.objects.set(e,t),t}startGc(){this.unreachable=new Set(this.objects.keys())}markAsReachable(r,e){let t=this.objects.get(r);e===t?this.unreachable.delete(r):!1&&console.warn("Reachable but deleted",r)}endGc(){this.unreachable.forEach(r=>{this.disposeObject(this.objects.get(r)),this.objects.delete(r)}),this.unreachable.clear()}dispose(){this.objects.forEach(r=>{this.disposeObject(r)}),this.objects.clear()}},Yl=class extends yh{constructor(e){super();this.flatShading=e}disposeObject(e){e.dispose()}createObject(e,t,o){let n=ui(e,t,this.flatShading,o);return n.computeBoundingSphere(),n}};var Yb={markNeedsUpdateRendererDirty:()=>{}};var bh=require("three");var vd=1e3,Kb=512*vd;function p3(i,r){let e=typeof i;return!!((r==="string"||r==="number")&&e===r||r==="boolean"&&(i==="true"||i==="false"||i===!0||i===!1)||r==="image"&&e==="string"&&i.startsWith("http"))}var Qb="https://hooks.spline.design",f3=`${Qb}/events?hashFile=`,zK=`${Qb}/`,Sd=class{constructor(r,e){this.id=r;this.userWebhook=e;this.result=void 0;this._connected=!1;this.emitter=ci();this.reconnectWaitFor=vd;this._onError=r=>{this.eventSource?.removeEventListener("message",this._onMessage),this.eventSource?.removeEventListener("error",this._onError),this.eventSource?.removeEventListener("open",this._onConnected),this._scheduleReconnect()};this._onConnected=r=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=vd,this._connected=!0};this._onDisconnected=()=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=vd,this._connected=!1};this._onMessage=r=>{let e=r.data,t;try{t=JSON.parse(e)}catch(o){console.error("Error parsing webhook message",o)}if(t){let o=!1;this.userWebhook.parametersSchemas.forEach(({data:n})=>{t[n.name]!==void 0&&p3(t[n.name],n.type)&&(this.result===void 0&&(this.result={}),this.result[n.name]=t[n.name],o=!0)}),o&&this.emitter.emit("message",{userWebhookId:this.id})}}}connect(){clearTimeout(this.scheduledReconnectHandle),this.userWebhook.url&&(this.eventSource=new EventSource(f3+this.userWebhook.url),this.eventSource.addEventListener("message",this._onMessage),this.eventSource.addEventListener("error",this._onError),this.eventSource.addEventListener("open",this._onConnected))}disconnect(){this.eventSource?.removeEventListener("message",this._onMessage),this.eventSource?.removeEventListener("error",this._onError),this.eventSource?.removeEventListener("open",this._onConnected),this.eventSource?.close(),this._onDisconnected(),clearTimeout(this.scheduledReconnectHandle)}_scheduleReconnect(){this.reconnectWaitFor*=2,this.reconnectWaitFor>Kb&&(this.reconnectWaitFor=Kb),clearTimeout(this.scheduledReconnectHandle),this.scheduledReconnectHandle=setTimeout(()=>{this.scheduledReconnectHandle=void 0,this.connect()},this.reconnectWaitFor)}update(r){this.userWebhook=r}dispose(){this._connected&&this.disconnect()}get connected(){return this._connected}on(r,e){this.emitter.on(r,e)}off(r,e){this.emitter.off(r,e)}getParametersKeys(){return this.userWebhook.parametersSchemas.map(r=>r.data.name)}getParameterValue(r){if(this.getParametersKeys().includes(r)){if(this.result)return this.result?.[r];for(let t of this.userWebhook.parametersSchemas)if(t.data.name===r)return Cu.defaultParameterValueByType(t.data.type)}}};var Zb=[4186.01,4434.92,4698.63,4978.03,5274.04,5587.65,5919.91,6271.93,6644.88,7040,7458.62,7902.13],h3=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],hi=[],Pd=[];for(let i=1;i<=8;i++)for(let r=0;r<Zb.length;r++){let e=Zb[r];hi.push(e/Math.pow(2,8-i)),Pd.push(h3[r]+i)}var wd=[32,2e3],gh=hi.filter((i,r)=>hi[r]>wd[0]&&hi[r]<wd[1]),Jb=Pd.filter((i,r)=>hi[r]>wd[0]&&hi[r]<wd[1]);var Od=class{static getFrequencies(r,e,t,o="frequency",n=-100,a=-30){t||(t=new Float32Array(r.frequencyBinCount),r.getFloatFrequencyData(t));let s=e/2,l=1/t.length*s,c,u,p;if(o==="music"||o==="voice"){let h=o==="voice"?gh:hi,m=Array(h.length).fill(n);for(let y=0;y<t.length;y++){let b=y*l,v=t[y];for(let w=h.length-1;w>=0;w--)if(b>h[w]){m[w]=Math.max(m[w],v);break}}c=m,u=o==="voice"?gh:hi,p=o==="voice"?Jb:Pd}else c=Array.from(t),u=c.map((h,m)=>l*m),p=u.map(h=>`${h.toFixed(2)} Hz`);let d=c.map(h=>Math.max(0,Math.min((h-n)/(a-n),1)));return{values:new Float32Array(d),frequencies:u,labels:p}}};var m3="gpt-4o-realtime-preview-2024-12-17",y3=()=>!1&&window.location.search.includes("api-dev")?"https://relayserver-dev.spline.design/":"https://relayserver.spline.design/";async function g3(i){try{return(await(await fetch(y3()+"session?uuidfile="+i)).json()).token}catch(r){console.error("Token generation error:",r)}}var xh=class{constructor(r){this.value=0;this.frequencies=new Float32Array(0);let e=new AudioContext;this.source=e.createMediaStreamSource(r),this.analyser=e.createAnalyser(),this.source.connect(this.analyser),this.analyser.fftSize=8192,this.analyser.smoothingTimeConstant=.1}getFrequencies(r=-100,e=-30){if(!this.analyser)throw new Error("Not connected, please call .connect() first");return Od.getFrequencies(this.analyser,44100,void 0,"voice",r,e)}update(){let r=this.getFrequencies(),e=r.values.reduce((t,o)=>t+o,0)/r.values.length;this.value=e,this.frequencies=r.values}disconnect(){this.source.disconnect(),this.analyser.disconnect()}},Kl=class{constructor(r,e,t){this.data=r;this.id=e;this.shared=t;this.emitter=ci();this.rafId=0;this.voice=0;this.frequencies=new Float32Array([0]);this.events=[];this.isConnected=!1;this.isToolsAdded=!1;this.tools=[];this.onMessage=r=>{let e=JSON.parse(r.data);if(this.appendEvent(e),e.type==="session.created"&&this.onSessionCreated(),e.type==="response.done"&&e.response?.output){for(let t of e.response.output)if(t.type==="function_call")for(let[o,n]of this.tools)t.name===o.name&&(n(JSON.parse(t.arguments)),setTimeout(()=>{this.sendClientEvent({type:"response.create",response:{instructions:"notice the user about what you just did"}})}))}};this.onSessionCreated=()=>{this.isToolsAdded||this.registerTools()};this.onOpen=()=>{this.events=[],this.isConnected=!0,this.sendClientEvent({type:"response.create",response:{instructions:"Say hi"}})};this.animate=()=>{if(this.rafId=requestAnimationFrame(this.animate),this.isConnected&&this.analyser){this.analyser.update();let r=this.analyser.value,e=this.analyser.frequencies;this.voice=r,this.frequencies=e,this.emitter.emit("voice",{value:r,frequencies:e})}}}update(r){this.data=r}setColorByName(r,e){let t=this.shared.getColorByName(r);if(t){let{id:o}=t,{r:n,g:a,b:s}=rb.hexStringToRgb(e)??{r:0,g:0,b:0};this.shared.updateColor(o,{r:n/255,g:a/255,b:s/255})}}async connect(){if(this.isConnected)return;let r=await g3(this.data.integration.hash);this.pc=new RTCPeerConnection,this.audioElement=document.createElement("audio"),this.audioElement.autoplay=!0,this.pc.ontrack=l=>{let c=l.streams[0];this.audioElement.srcObject=c,this.analyser=new xh(c)};let e=await navigator.mediaDevices.getUserMedia({audio:!0});this.pc.addTrack(e.getTracks()[0]),this.dc=this.pc.createDataChannel("oai-events"),this.dc.addEventListener("message",this.onMessage),this.dc.addEventListener("open",this.onOpen);let t=await this.pc.createOffer();await this.pc.setLocalDescription(t);let s={type:"answer",sdp:await(await fetch(`https://api.openai.com/v1/realtime?model=${m3}`,{method:"POST",body:t.sdp,headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/sdp"}})).text()};await this.pc.setRemoteDescription(s),this.animate()}appendEvent(r){this.events=[r,...this.events]}sendClientEvent(r){this.dc?(r.event_id=r.event_id||crypto.randomUUID(),this.dc.send(JSON.stringify(r)),this.appendEvent(r)):console.error("Failed to send message - no data channel available",r)}registerTools(){this.isToolsAdded=!0,this.registerTool({type:"function",name:"set_personality_color",description:"returns a color based on the voice personality of the ai assistant. This should be called by the voice assistant each time it is asks to speak differently. If a color cannot be associated to the personality, the color should be a neutral color.",parameters:{type:"object",properties:{color:{type:"string",description:"css hex color string, reflecting the personality"},personality:{type:"string",description:"the personality of the voice assistant"}},required:["color","personality"]}},({color:n})=>{this.setColorByName("Voice Assistant Color",n)});let r=this.shared.getVariablesNames().join(", ");this.registerTool({type:"function",name:"set_variable",description:"Sets a Spline variable value when asked by the user.",parameters:{type:"object",properties:{name:{type:"string",description:`The name of the variable that needs to be set. Here's a list of available variables: ${r}. It the variable does not exist, don't call the function and warn the user about it.`},value:{type:"string",description:"The new value for this variable, should always be a string even for number and boolean variables, assume that the value will be cast to the proper type afterwards."}},required:["name","value","type"]}},({name:n,value:a})=>{let s=this.shared.getVariableByName(n);if(s){let l=this.shared.getVariable(s.id),c;typeof l=="number"?c=parseFloat(a):typeof l=="boolean"?c=a.toLowerCase()==="true":c={textValue:a},this.shared.updateVariable(s.id,c)}});let e=this.shared.getColorNames().join(", ");this.registerTool({type:"function",name:"set_color",description:"Sets a Spline color asset value when asked by the user.",parameters:{type:"object",properties:{name:{type:"string",description:`The name of the color asset that needs to be set. Here's a list of available color assets: ${e}. It the color asset does not exist, don't call the function and warn the user about it.`},value:{type:"string",description:"css hex color string"}},required:["name","value"]}},({name:n,value:a})=>{this.setColorByName(n,a)});let t=this.shared.scene,o=[];t.traverseEntity(n=>{n.data.events.forEach(a=>{if(a.data.type==="AIAssistantTrigger"){let{description:s}=a.data;o.push(s)}})}),this.registerTool({type:"function",name:"trigger_event",description:"Trigger an event by name, here are the available events, please match what the user is asking for to one of these if it applies, otherwise don't call the function and warn the user.",parameters:{type:"object",properties:{description:{type:"string",description:`The name of the event that needs to be triggered. Here's a list of available events: ${JSON.stringify(o)}.`},direction:{type:"string",description:"default is forward, but can be forward or backward. Always set to forward unless the user ask to reverse or cancel the event, then set to backward."}},required:["description","direction"]}},({description:n,direction:a})=>{this.emitter.emit("trigger_event",{description:n,direction:a})}),this.sendClientEvent({type:"session.update",session:{tools:this.tools.map(([n])=>n)}})}registerTool(r,e){this.tools.push([r,e])}disconnect(){cancelAnimationFrame(this.rafId),this.analyser?.disconnect(),this.voice=0,this.isConnected=!1,this.isToolsAdded=!1,this.dc?.removeEventListener("message",this.onMessage),this.dc?.removeEventListener("open",this.onOpen),this.dc?.close(),this.pc?.getSenders().forEach(r=>{r.track&&r.track.stop()}),this.pc?.close(),this.pc=void 0}computeAnalysisForListenerEvent(r){if(r.analysis==="range"){let e=this.frequencies.slice(...r.analysisRange);return e.reduce((t,o)=>t+o,0)/e.length}return r.analysis==="single"?this.frequencies[r.analysisSingle]:this.voice}on(r,e){this.emitter.on(r,e)}off(r,e){this.emitter.off(r,e)}};function ev(i){return"variable_"+i}var vh=class extends pd{constructor(e){super();this.shared=e}create(e){return new Cs(e,this.shared)}},Gn=class{constructor(r,e={},t=!0,o=!1){this.data=r;this.needsJitter=t;this.enableLocalStorageForPersistentVariables=o;this.geometryCache=new Yl(!0);this.geometryCache2=new Yl(!1);this.imageHolderCache=new vh(this);this.thisContext={scene:Yb,shared:this};this.deletedMaterial=new Vn(Ft.defaultTwoLayerData("phong"),this.thisContext,"");this.deletedImage=new Rr(Eu.emptyImage,this);this.deletedVideo=new Rr(Aa.defaultVideo,this);this.materials={};this.images={};this.uiBuffers={};this.videos={};this.colors={};this.audios={};this.particles={};this.fonts={};this.variables={};this.userAPIs={};this.userWebhooks={};this.mouseProperty=null;this.raycastProperty=null;this.requestRender=()=>{this._requestRender&&this._requestRender()};if(e.images)for(let[n,a]of Object.entries(e.images))this.addImage(n,a);if(e.videos)for(let[n,a]of Object.entries(e.videos))this.addVideo(n,a);if(e.audios)for(let[n,a]of Object.entries(e.audios))this.addAudio(n,a);if(e.particles)for(let[n,a]of Object.entries(e.particles))this.addParticle(n,a);this.reset(r)}setRequestRender(r){this._requestRender=r}getImageLoadPromises(){return Object.values(this.images).map(r=>r.loadPromise)}setEntityOpContext(r){this.entityOpContext=r}reset(r,e=!1,t=!1){this.data=r,this.resetLib(r.lib);for(let{id:o,data:n}of r.variables)this.addVariableHolder(o,n),e&&this.updateVariableHolder(o,n);for(let[o,n]of Object.entries(r.userAPIs))this.addUserAPI(o,n);for(let[o,n]of Object.entries(r.userWebhooks))this.addUserWebhook(o,n);if(!t){for(let[o,n]of Object.entries(r.images))this.addImage(o,n);for(let[o,n]of Object.entries(r.videos))this.addVideo(o,n)}for(let[o,n]of Object.entries(r.colors))this.addColor(o,n);for(let[o,n]of Object.entries(r.materials))this.addMaterial(o,n);for(let[o,n]of Object.entries(r.audios))this.addAudio(o,n);for(let[o,n]of Object.entries(r.particles))this.addParticle(o,n);for(let[o,n]of Object.entries(r.fonts))this.addFont(o,n)}addMaterial(r,e){if(this.materials[r]){let t=this.materials[r];t.reset(e,this.thisContext),t.dispose()}else{let t=new Vn(e,this.thisContext,r);this.materials[r]=t}}deleteMaterial(r){this.materials[r]&&(this.materials[r].nodeMaterialDispose(),delete this.materials[r])}getMaterial(r){let e=this.materials[r];return e}getMaterialOrDeletedPlaceholder(r){return this.materials[r]??this.deletedMaterial}material(r){return typeof r=="string"?this.getMaterialOrDeletedPlaceholder(r):r==null?(console.error("material is undefined or null"),this.deletedMaterial):new Bn(r,this.thisContext)}getMaterials(){return this.materials}addImage(r,e){return this.images[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.images[r].updateSrc(e.data),!0):(this.images[r]=new Rr(e,this),!1)}deleteImage(r){let e=this.images[r];e&&(e.dispose(),delete this.images[r])}getDefaultImage(){return this.images.image_0}getImage(r){return this.images[r]??this.deletedImage}image(r){return typeof r=="string"?this.getImage(r):this.imageHolderCache.load(r)}addUIBuffer(r,e){return this.uiBuffers[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.uiBuffers[r].updateSrc(e),!0):(this.uiBuffers[r]=new Rr(e,this),!1)}uiBuffer(r){return this.uiBuffers[r]}addVideo(r,e){return this.videos[r]?(this.videos[r].updateSrc(e.data),!0):(this.videos[r]=new Rr(e,this),!1)}deleteVideo(r){let e=this.videos[r];e&&(e.dispose(),delete this.videos[r])}getVideo(r){return this.videos[r]??this.deletedVideo}video(r){return typeof r=="string"?this.getVideo(r):this.imageHolderCache.load(r)}addColor(r,e){return this.colors[r]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),"a"in e?this.colors[r].setRGBA(e.r,e.g,e.b,e.a):this.colors[r].setRGBA(e.r,e.g,e.b,1),!0):("a"in e?this.colors[r]=new $i(e.r,e.g,e.b,e.a):this.colors[r]=new $i(e.r,e.g,e.b,1),!1)}updateColor(r,e){if(this.colors[r]){this.onColorOrImageUpdate&&this.onColorOrImageUpdate();let t=this.colors[r];return this.colors[r].r=e.r??t.r,this.colors[r].g=e.g??t.g,this.colors[r].b=e.b??t.b,this.colors[r].a=e.a??t.a,!0}return!1}deleteColor(r){this.colors[r]&&delete this.colors[r]}getColor(r){return this.colors[r]}getColorNames(){return Object.values(this.data.colors).map(r=>r.name)}getColorByName(r){for(let e in this.data.colors)if(this.data.colors[e].name===r)return{color:this.colors[e],id:e}}color(r){let e;if(typeof r=="string"){let t=this.getColor(r);t?e=t:(console.warn("Tried to create color layer params with a color key that does not exist in the assets manager"),e=new Ht(0,0,0,0))}else return"a"in r?new Ht(r.r,r.g,r.b,r.a):new Ht(r.r,r.g,r.b,1);return e}addAudio(r,e){this.audios[r]=e}getAudio(r){let e=this.audios[r];if(e instanceof zn)return e;{let t=new zn({src:e.data});return this.audios[r]=t,t}}addParticle(r,e){this.particles[r]=e}getParticle(r){return this.particles[r]}deleteParticle(r){this.particles[r]&&delete this.particles[r]}deleteAudio(r){let e=this.audios[r];e&&(e instanceof zn&&e.dispose(),delete this.audios[r])}addFont(r,e){this.fonts[r]=new bd(e),this.fonts[r].loadingPromise.then(()=>this.requestRender())}getFont(r){return this.fonts[r]}deleteFont(r){this.fonts[r]&&delete this.fonts[r]}dispose(){Object.keys(this.materials).forEach(e=>this.deleteMaterial(e)),this._requestRender=void 0,Object.values(this.audios).forEach(e=>{e instanceof zn&&e.dispose()}),this.audios={},this.particles={},this.geometryCache.dispose(),this.geometryCache2.dispose()}addVariableHolder(r,e){if(this.variables[r]===void 0){let t=e.value;if(this.enableLocalStorageForPersistentVariables&&e.persistent){let o=localStorage.getItem(ev(r));t=o!==null?JSON.parse(o):e.value}return this.variables[r]={value:t,locations:[],persistent:e.persistent},"dynamicVariableType"in e&&(this.variables[r].dynamicVariablePlayState="Playing",this.variables[r].dynamicVariableToggleIsForward=void 0),!0}return this.variables[r].value=e.value,!1}resetDynamicVariablePlayState(){for(let r in this.variables)this.variables[r].dynamicVariablePlayState!==void 0&&(this.variables[r].dynamicVariablePlayState="Playing",this.variables[r].dynamicVariableToggleIsForward=void 0)}updateVariableHolder(r,e){this.updateVariable(r,e.value)}updateVariable(r,e){if(this.variables[r]===void 0)return!1;this.variables[r].value=e,this.enableLocalStorageForPersistentVariables&&this.variables[r].persistent&&localStorage.setItem(ev(r),JSON.stringify(e));let t=e;for(;typeof t=="string";)t=this.variables[t].value;let o=this.entityOpContext.scene;for(let n=this.variables[r].locations.length-1;n>=0;n--){let a=this.variables[r].locations[n];if(a[0]==="material"){let s=a[1],l=t,c={scene:o,shared:this},u=a.slice(2);o.traverseMaterial(d=>{let f=d.root??d;f.uuid===s&&f.onVariableUpdate(u,l,c)});let p=this.materials[s];p&&p.onVariableUpdate(u,l,c)}else{let s=o.find(a[0]);if(s===void 0){this.variables[r].locations.splice(n,1);continue}if(a[1]!=="geometry"&&a[1]!=="particles"){for(let l=1;l<a.length-1;l++)s=s[a[l]];a[1]==="rotation"?s[a[a.length-1]]=t*bh.MathUtils.DEG2RAD:s[a[a.length-1]]=t}if(s=o.find(a[0]),s.type==="ParticleEmitter"&&s.updateVariableState(t,a),ze.is(s))if(a[1]==="position"||a[1]==="rotation"||a[1]==="scale")s.onVariableUpdate();else if(a[1]==="geometry"){let l=s;s.component&&(l=s.component);let c=l.dataPatched;l.chooseGeoemtryCache(this).forceDelete(c.geometry),l.createGeometryDelayed(this.entityOpContext),l.onVariableUpdate(!0),l.invalidateDownstreamBooleanData(),l.instances.forEach(u=>{let p=u.dataPatched;u.chooseGeoemtryCache(this).forceDelete(p.geometry),u.createGeometryDelayed(this.entityOpContext),u.onVariableUpdate(!0),u.invalidateDownstreamBooleanData()})}else a[1]==="morphTargetInfluences"&&s.updateMorphInfluences(a[2],t)}}return this.requestRender(),!0}deleteVariable(r){this.variables[r]&&delete this.variables[r]}getVariable(r,e){if(Array.isArray(r)){if(r[0]==="mouse")return this.mouseProperty?.[r[1]]??0;if(r[0]==="raycast")return this.raycastProperty?.[r[1]]??0;let t=this.entityOpContext.scene.find(r[0]);if(r[1]==="width"||r[1]==="height"||r[1]==="depth")return t.geometry.userData.parameters[r[1]];for(let o=1;o<r.length;o++)t=t[r[o]];return r[1]==="rotation"&&(t*=bh.MathUtils.RAD2DEG),t}for(let t in this.variables){if(e===void 0)break;let o=this.variables[t],n=o.locations?.findIndex(a=>ut.equal(a,e));n!==void 0&&n!==-1&&o.locations.splice(n,1)}if(typeof r=="string"){let t=r,o=r;do{if(o=t,this.variables[t]===void 0)break;let n=this.variables[t].value;e&&this.variables[o]!==void 0&&this.variables[o].locations.push(e),t=n}while(typeof t=="string");return t}else return r}getVariables(){return this.variables}getVariablesNames(){return this.data.variables.map(r=>r.data.name)}getVariableByName(r){for(let e of this.data.variables)if(e.data.name===r)return{variable:e.data,id:e.id}}getDynamicVariablePlayState(r){return this.variables[r]?.dynamicVariablePlayState}setDynamicVariablePlayState(r,e){this.variables[r]!==void 0&&(this.variables[r].dynamicVariablePlayState=e)}getDynamicVariableToggleIsForward(r){return this.variables[r]?.dynamicVariableToggleIsForward}setDynamicVariableToggleIsForward(r,e){this.variables[r]!==void 0&&(this.variables[r].dynamicVariableToggleIsForward=e)}resetLib(r){for(let[e,t]of Object.entries(r.images))this.addImage(e,t.asset);for(let[e,t]of Object.entries(r.audios))this.addAudio(e,t.asset);for(let[e,t]of Object.entries(r.particles))this.addParticle(e,t.asset);for(let[e,t]of Object.entries(r.colors))this.addColor(e,t.asset);for(let[e,t]of Object.entries(r.fonts))this.addFont(e,t.asset);for(let[e,t]of Object.entries(r.materials))this.addMaterial(e,t.asset);for(let[e,t]of Object.entries(r.videos))this.addVideo(e,t.asset);for(let[e,t]of Object.entries(r.variables))this.addVariableHolder(e,t.asset)}updateLibByOp(r,e){r.path[0]==="images"?r.path.length===1&&r.type===1?this.addImage(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteImage(r.id):r.path[0]==="videos"?r.path.length===1&&r.type===1?this.addVideo(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteVideo(r.id):r.path[0]==="audios"?r.path.length===1&&r.type===1?this.addAudio(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteAudio(r.id):r.path[0]==="particles"?r.path.length===1&&r.type===1?this.addParticle(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteParticle(r.id):r.path[0]==="colors"?r.path.length===1&&r.type===1?this.addColor(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteColor(r.id):r.path[0]==="materials"?r.path.length===1&&r.type===1?this.addMaterial(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteMaterial(r.id):r.path[0]==="fonts"?r.path.length===1&&r.type===1?this.addFont(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteFont(r.id):r.path[0]==="variables"?r.path.length===1&&r.type===1?this.addVariableHolder(r.id,r.data.asset):r.path.length===1&&r.type===2&&this.deleteVariable(r.id):r.path[0]==="components"&&e.updateByLibOp(r,this)}updateByOp(r,e,t){if(this.data=e,r.path[0]==="images")r.path.length===2&&r.type===0?r.props.data&&this.getImage(r.path[1]).updateSrc(r.props.data):r.path.length===1&&r.type===1?this.addImage(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteImage(r.id);else if(r.path[0]==="videos")r.path.length===2&&r.type===0?r.props.data&&this.getVideo(r.path[1]).updateSrc(r.props.data):r.path.length===1&&r.type===1?this.addVideo(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteVideo(r.id);else if(r.path[0]==="audios")r.path.length===2&&r.type===0?r.props.data&&this.addAudio(r.path[1],e.audios[r.path[1]]):r.path.length===1&&r.type===1?this.addAudio(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteAudio(r.id);else if(r.path[0]==="particles")r.path.length===2&&r.type===0?r.props.data&&this.addParticle(r.path[1],e.particles[r.path[1]]):r.path.length===1&&r.type===1?this.addParticle(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteParticle(r.id);else if(r.path[0]==="colors")r.path.length===2&&r.type===0?this.updateColor(r.path[1],r.props):r.path.length===1&&r.type===1?this.addColor(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteColor(r.id);else if(r.path[0]==="materials")r.path.length===1&&r.type===1?this.addMaterial(r.id,r.data):r.path.length===1&&r.type===2?this.deleteMaterial(r.id):r.path.length>1&&this.getMaterial(r.path[1]).updateByOp(bt.drop(r,2),e.materials[r.path[1]],{shared:this,scene:t});else if(r.path[0]==="fonts")r.path.length===2&&r.type===0?this.updateFont(r.path[1],r,t):r.path.length===1&&r.type===1?this.addFont(r.id,r.data):r.path.length===1&&r.type===2&&this.deleteFont(r.id);else if(r.path[0]==="variables")r.path.length===2&&r.type===0?"value"in r.props?this.updateVariable(r.path[1],r.props.value):"persistent"in r.props&&(this.variables[r.path[1]].persistent=r.props.persistent):r.path.length===1&&r.type===4?this.addVariableHolder(r.id,r.data):r.path.length===1&&r.type===5&&this.deleteVariable(r.id);else if(r.path[0]==="userAPIs"){if(r.path.length===1&&r.type===1)this.addUserAPI(r.id,r.data);else if(r.path.length===1&&r.type===2)this.deleteUserAPI(r.id);else if(typeof r.path[1]=="string"){let o=e.userAPIs[r.path[1]];if(o){let n=r.type===0&&r.props.debounce===void 0,a=this.getUserAPI(r.path[1]);a instanceof Kl?a.update(o):a?.update(o,this,n)}}}else if(r.path[0]==="userWebhooks"){if(r.path.length===1&&r.type===1)this.addUserWebhook(r.id,r.data);else if(r.path.length===1&&r.type===2)this.deleteUserWebhook(r.id);else if(typeof r.path[1]=="string"){let o=e.userWebhooks[r.path[1]];o&&this.getUserWebhook(r.path[1])?.update(o)}}else r.path[0]==="lib"&&this.updateLibByOp(bt.drop(r,1),t)}updateFont(r,e,t){if(e.props.url){let o=this.getFont(r),n={...this.data.fonts[r],url:e.props.url};o.update(n),o.loadingPromise.then(()=>this.requestRender()),t.updateFont(r,this)}}addUserAPI(r,e){return this.userAPIs[r]?(this.userAPIs[r].update(e,this),!0):this.openAIRealtime?.id===r?(this.openAIRealtime.update(e),!0):e.integration?.type==="VoiceAssistant"?(this.openAIRealtime=new Kl(e,r,this),!1):(this.userAPIs[r]=new Qu(r,e,this),!1)}getUserAPI(r){return this.openAIRealtime?.id===r?this.openAIRealtime:this.userAPIs[r]}getUserAPIs(){return this.userAPIs}deleteUserAPI(r){let e=this.userAPIs[r];e&&(e.dispose(),delete this.userAPIs[r])}addUserWebhook(r,e){return this.userWebhooks[r]?(this.userWebhooks[r].update(e),!0):(this.userWebhooks[r]=new Sd(r,e),!1)}getUserWebhook(r){return this.userWebhooks[r]}getUserWebhooks(){return this.userWebhooks}deleteUserWebhook(r){let e=this.userWebhooks[r];e&&(e.dispose(),delete this.userWebhooks[r])}get scene(){return this.entityOpContext.scene}},tv=new Gn(Ur.emptyData());var Cr=class extends Ut{updateByPatchedOp(e,t,o){if(super.updateByPatchedOp(e,t,o),Ug(e.path,["materials"])!==null&&e.type===0&&Array.isArray(this.material))for(let[n,a]of Object.entries(e.props)){let s=o.shared.material(a);this.material[Number(n)]=s}else if(je(e.path,["material"])&&this.material instanceof Tr)"material"in t&&typeof t.material!="string"&&this.material.updateByOp(bt.drop(e,1),t.material,o);else if(je(e.path,["materials","*"])&&Array.isArray(this.material)){let n=e.path[1];if("materials"in t&&n<this.material.length){let a=t.materials[n];typeof a!="string"&&this.material[n].updateByOp(bt.drop(e,2),a,o)}}}get needsAO(){return this.material!==void 0?(Array.isArray(this.material)?this.material[0]:this.material).hasAO:!1}updateState(e,t){super.updateState(e,t),e.castShadow!==void 0&&(this.castShadow=e.castShadow),e.receiveShadow!==void 0&&(this.receiveShadow=e.receiveShadow);let o=this.dataPatched;this.dataPatched.type==="Mesh"&&!!this.dataPatched.geometry.shapeBlendNode&&this.layers.set(9);let a;if(this.dataPatched.type==="Mesh"&&this.dataPatched.geometry.type==="ShapeBlendGeometry"&&(a={resolutionLevel:this.dataPatched.geometry.resolutionLevel,useChildrenColors:this.dataPatched.geometry.useChildrenColors}),e.geometry?.type!=="NonParametricGeometry"&&"material"in e&&e.material!==void 0&&(this.disposeMaterial(),this.material=t.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe,a),t.scene.markNeedsUpdateRendererDirty()),(e.geometry?.type==="NonParametricGeometry"||"materials"in e)&&("materials"in e&&e.materials!==void 0?(this.disposeMaterial(),this.material=e.materials.map(s=>t.shared.material(s).getFlavor(o.flatShading,o.side,o.wireframe)),t.scene.markNeedsUpdateRendererDirty()):"material"in e&&e.material!==void 0&&(this.disposeMaterial(),this.material=[t.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe)],t.scene.markNeedsUpdateRendererDirty())),e.flatShading!==void 0||e.wireframe!==void 0||e.side!==void 0)if(Array.isArray(this.material))for(let s=0;s<this.material.length;s++)this.material[s]=this.material[s].getFlavor(o.flatShading,o.side,o.wireframe);else this.material=this.material.getFlavor(o.flatShading,o.side,o.wireframe,a)}disposeMaterial(){this.material&&vc(this.material).forEach(e=>{e instanceof Tr&&(e instanceof Vn||e.nodeMaterialDispose())})}dispose(){this.disposeMaterial(),super.dispose()}};var Lr=require("three");var rv=new Lr.Vector3,ov=new Lr.Vector4,iv=new Lr.Vector4,b3=new Lr.Vector3,nv=new Lr.Matrix4,ft=class extends Cr{constructor(e,t,o){super(e,t);this.data=t;this.isSkinnedMesh=!1;this.localGeometry=void 0,t.bindMode&&t.bindMatrix&&(this.bindMode=t.bindMode,this.bindMatrix=new Lr.Matrix4().fromArray(t.bindMatrix),this.bindMatrixInverse=new Lr.Matrix4)}chooseGeoemtryCache(e){return e.geometryCache}markGeometryAsReachable(e){this.geometryCreateDeleyed instanceof Lr.BufferGeometry&&this.chooseGeoemtryCache(e).markAsReachable(this.dataPatched.geometry,this.geometryCreateDeleyed)}get geometry(){if(this.localGeometry!==void 0)return this.localGeometry;if(this.geometryCreateDeleyed instanceof Gn){let e=this.geometryCreateDeleyed,t=this.chooseGeoemtryCache(e);this.geometryCreateDeleyed=t.get(this.dataPatched.geometry,e,this)}return this.geometryCreateDeleyed}set geometry(e){this.localGeometry=e}get is2DAndNoDepth(){let e=this.dataPatched.geometry;return fl.is2DParametricMesh(e.type)&&e.depth===0}get is2DType(){return fl.is2DParametricMesh(this.geometry.userData.type)}get isNonParametric(){return this.geometry.userData.type==="NonParametricGeometry"}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),je(e.path,["geometry"])&&this.updateByPatchedOpGeometry(bt.drop(e,1),t.geometry,o)}removeInteractionGeometry(e){this.localGeometry?.dispose(),this.localGeometry=void 0}updateGeometryInteractions(e,t){this.invalidateDownstreamBooleanData();let o=this.data.geometry.type;if(o==="NonParametricGeometry"||o==="SubdivGeometry"){let n=e;if(this.localGeometry===void 0){let u={...this.data.geometry,...n};this.localGeometry=ui(u,t,this.data.flatShading,this)}let a,s,l;n.scaleBaked?[a,s,l]=n.scaleBaked:{width:a,height:s,depth:l}=n;let c=this.localGeometry.userData;c.sxPrev!==void 0&&_l(this.localGeometry.attributes,a/c.sxPrev,s/c.syPrev,l/c.szPrev),c.sxPrev=a,c.syPrev=s,c.szPrev=l}else{let n={...this.data.geometry,...e};this.localGeometry?.dispose(),this.localGeometry=ui(n,t,this.data.flatShading,this)}}refreshAttachedClonersInteractions(){for(let e of this.attachedSurfaceCloners)e.update()}refreshAttachedCloners(e){for(let t of this.attachedSurfaceCloners)e.scene.addPendingUpdateCloner(t.object)}refreshAttachedPaths(e){for(let t of this.attachedPaths)e.scene.addPendingCommand(()=>t.updateShape())}createGeometryDelayed(e){this.geometryCreateDeleyed=e.shared,this.refreshAttachedCloners(e),this.refreshAttachedPaths(e)}updateByPatchedOpGeometry(e,t,o){let n=!1;e.type===0&&e.path.length===0&&Object.keys(e.props).includes("scaleBaked")&&this.geometryCreateDeleyed instanceof _t&&this.chooseGeoemtryCache(o.shared).mutateIfUnique(this.geometryCreateDeleyed.data,t)===this.geometryCreateDeleyed&&(n=!0,this.geometryCreateDeleyed.mutateDirectlyScaleBaked(t,e.props.scaleBaked),this.refreshAttachedCloners(o),this.refreshAttachedPaths(o)),n||(o.scene?.markGeometryCacheDirty(),this.createGeometryDelayed(o)),this.resetBBoxNeedsUpdate(),this.invalidateDownstreamBooleanData()}updateGeometryOnStateUpdate(e,t){this.createGeometryDelayed(t)}updateState(e,t){e.geometry!==void 0&&this.updateGeometryOnStateUpdate(e.geometry,t);let o=e.morphTargetInfluences;if(o){this.updateMorphTargets(),this.geometry.morphTargetsRelative=!0;for(let{data:{name:n,value:a}}of o)this.updateMorphInfluences(n,t.shared.getVariable(a,[this.uuid,"morphTargetInfluences",n]))}super.updateState(e,t)}updateMorphInfluences(e,t){if(this.morphTargetDictionary===void 0)return;let o=this.morphTargetDictionary[e];o!==void 0&&(this.morphTargetInfluences[o]=t)}updateGeometryGroupsIfNeeded(){Array.isArray(this.material)&&this.geometry.groups.length===0&&this.geometry.addGroup(0,Math.max(this.geometry.getIndex()?.count??0,this.geometry.getAttribute("position").count),0)}updateEntityBoxSize(e,t){let o=this.geometry.userData.parameters;this.is2DType?e.set(0,0,o.depth*.5):this.isNonParametric?(e.setScalar(0),this.geometry.boundingSphere&&e.copy(this.geometry.boundingSphere.center),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)):o.centerOffset?e.fromArray(o.centerOffset):e.setScalar(0),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)}updateMatrixWorld(e){super.updateMatrixWorld(e),this.bindMode==="attached"?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode==="detached"&&this.bindMatrixInverse.copy(this.bindMatrix).invert()}bind(e,t){this.skeleton=e,this.isSkinnedMesh=!0,t===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),t=this.matrixWorld),this.bindMatrix.copy(t),this.bindMatrixInverse.copy(t).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(e){let t=new Lr.Vector4,o=this.geometry.attributes.skinWeight;for(let n=0,a=o.count;n<a;n++){t.fromBufferAttribute(o,n);let s=1/t.manhattanLength();s!==1/0?t.multiplyScalar(s):t.set(1,0,0,0),o.setXYZW(n,t.x,t.y,t.z,t.w)}}boneTransform(e,t){let o=this.skeleton;if(o===void 0)return;let n=this.geometry;ov.fromBufferAttribute(n.attributes.skinIndex,e),iv.fromBufferAttribute(n.attributes.skinWeight,e),rv.copy(t).applyMatrix4(this.bindMatrix),t.set(0,0,0);for(let a=0;a<4;a++){let s=iv.getComponent(a);if(s!==0){let l=ov.getComponent(a);nv.multiplyMatrices(o.bones[l].matrixWorld,o.boneInverses[l]),t.addScaledVector(b3.copy(rv).applyMatrix4(nv),s)}}return t.applyMatrix4(this.bindMatrixInverse)}};function v3(i){if(i.geometry.attributes.extrudeNormal||!i.geometry.attributes.position||!i.geometry.attributes.normal)return;let r=new Map,e=i.geometry.attributes,t=e.position.array,o=e.normal.array,n=new Float32Array(t.length);for(let a=0;a<t.length;a+=3){let s=`${t[a]}_${t[a+1]}_${t[a+2]}`,l=new Br.Vector3(o[a],o[a+1],o[a+2]);r.has(s)?r.get(s)?.normals.push(l):r.set(s,{normals:[l],result:new Br.Vector3})}r.forEach((a,s)=>{for(let l of a.normals)a.result.add(l);a.result.divideScalar(a.normals.length)});for(let a=0;a<t.length;a+=3){let s=`${t[a]}_${t[a+1]}_${t[a+2]}`,l=r.get(s)?.result;l&&(n[a]=l.x,n[a+1]=l.y,n[a+2]=l.z)}i.geometry.setAttribute("extrudeNormal",new Br.Float32BufferAttribute(n,3))}function S3(i){if(i.geometry.attributes.extrudeNormals||!i.geometry.attributes.position)return;let e=i.geometry.attributes.position.array,t=new Float32Array(e.length),o=new Br.Vector3;for(let n=0;n<e.length;n+=3)o.set(e[n],e[n+1],e[n+2]).normalize(),t[n]=o.x,t[n+1]=o.y,t[n+2]=o.z;i.geometry.setAttribute("extrudeNormal",new Br.Float32BufferAttribute(t,3))}function Ms(i){if(Array.isArray(i.material)){for(let r of i.material)if(r.getLayersOfType("outline").length===0)return}else if(!(i.material instanceof Tr)||i.material.getLayersOfType("outline").length===0)return;i instanceof ft&&i.is2DAndNoDepth?S3(i):v3(i)}function Is(i){if(!i.geometry.attributes.position)return;let e=i.geometry.attributes.position.array,t=new Float32Array(e.length),o=parseInt(i.uuid.replace(/\D/g,"")),n=[Br.MathUtils.seededRandom(o),Br.MathUtils.seededRandom(o+1e4),Br.MathUtils.seededRandom(o+2e4)];for(let a=0;a<e.length;a++)t[a]=n[a%3];i.geometry.setAttribute("randomColor",new Br.BufferAttribute(t,3))}var zo=new mi.Box3,Ql=new mi.Vector3;function av(i){let r=!1;return i.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&t.geometry.type==="SubdivGeometry"&&(r=!0)}),r}var Fn=class extends ft{constructor(e,t,o){super(e,t,o);this.data=t;this.hiddenMatrixOld=new mi.Matrix4;this.smoothShading=!0;this.skipReactionUpdate=!1}chooseGeoemtryCache(e){return this.dataPatched.flatShading?e.geometryCache:e.geometryCache2}get subdivPointerNew(){return this.localGeometry!==void 0?this.subdivPointer:this.geometry.ensureSubdivPointer()}get originalGeometryNew(){return this.localGeometry!==void 0?this.originalGeometry:this.geometry.originalGeometry}get phongAngle(){return this.data.geometry.phongAngle??45}updateEntityBoxSize(e,t){let o=this.geometry.userData.parameters;e.copy(this.originalGeometryNew.boundingSphere.center),t.set(o.width,o.height,o.depth??0).multiplyScalar(.5)}createGeometryByControls(e){if(this.skipReactionUpdate===!0)return;let t=this.localGeometry?.uuid,{originalGeometry:o,subdividedGeometry:n,subdivPointer:a}=_t.build(e,this.subdivPointer,this.smoothShading,this.hasNonUniformScale?this.shearScale:void 0);this.subdivPointer=a,o!==void 0&&(this.originalGeometry?.dispose(),this.originalGeometry=o),n!==void 0&&(this.subdividedGeometry?.dispose(),this.subdividedGeometry=n??void 0),this.localGeometry=this.subdividedGeometry??this.originalGeometry,Ms(this),Is(this),this.calcBoundingBox(),t&&(this.localGeometry.uuid=t)}updateState(e,t){if(super.updateState(e,t),e.flatShading!==void 0){let o=this.material;this.material=Array.isArray(o)?o.map(n=>n.getFlavor(!1,n.side,n.wireframe)):o.getFlavor(!1,o.side,o.wireframe),this.smoothShading=!e.flatShading,this.createGeometryDelayed(t)}}updateMesh(e=!1){_t.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1,this.originalGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0),this.subdividedGeometry&&_t.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1,this.subdividedGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0)}updateTopology(){this.originalGeometry.dispose(),this.originalGeometry=_t.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1),this.subdividedGeometry&&(this.subdividedGeometry.dispose(),this.subdividedGeometry=_t.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1)),this.localGeometry=this.subdividedGeometry??this.originalGeometry}raycast(e,t){let o=this.localGeometry;this.localGeometry=this.originalGeometryNew,Ut.prototype.raycast.call(this,e,t),this.localGeometry=o}activateSVDCompensation(){!this.hasNonUniformScale||(this.matrix.copy(this.matrixWorldRigid),this.hiddenMatrixOld.copy(this.hiddenMatrix),this.hiddenMatrix.copy(this.parent.matrixWorld).invert())}deactivateSVDCompensation(){!this.hasNonUniformScale||(this.updateMatrix(),this.hasNonUniformScale=void 0,this.hiddenMatrix.copy(this.hiddenMatrixOld))}calcBoundingBox(){let e=this.originalGeometry;e.boundingSphere===null&&(e.boundingSphere=new mi.Sphere,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let t=e.attributes.position,o=e.boundingSphere.center;zo.setFromBufferAttribute(t),zo.getCenter(o),e.boundingSphere.radius=o.distanceTo(zo.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),zo.getSize(Ql),this.hasNonUniformScale&&Ql.divide(this.scale);let n={width:Ql.x,height:Ql.y,depth:Ql.z};return this.geometry.userData.parameters=n,n}updateBoundingSphere(e){let t=this.originalGeometry;zo.min.set(e[0],e[2],e[4]),zo.max.set(e[1],e[3],e[5]),this.hasNonUniformScale&&(zo.min.applyMatrix4(this.shearScaleInv),zo.max.applyMatrix4(this.shearScaleInv)),t.boundingSphere===null&&(t.boundingSphere=new mi.Sphere);let o=t.boundingSphere.center;zo.getCenter(o),t.boundingSphere.radius=o.distanceTo(zo.max)}freeSubdivPointer(){this.subdivPointer&&(_t.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0),this.localGeometry=void 0,this.originalGeometry?.dispose(),this.subdividedGeometry?.dispose()}dispose(){super.dispose(),this.freeSubdivPointer()}updateByPatchedOpGeometry(e,t,o){super.updateByPatchedOpGeometry(e,t,o),this.localGeometry&&this.createGeometryByControls(t)}};var Go=require("three"),sv=-1,w3=1,lv={x:[1,0,0],"-x":[-1,0,0],y:[0,1,0],"-y":[0,-1,0],z:[0,0,1],"-z":[0,0,-1]},cv={polygon_center:0,edge:1,vertex:2},Zl=(i,r)=>(e,t)=>!r||e===0||i===0?0:i*t/100,Ee=(i,r)=>{let e=Math.abs(r),t=e*-1;return(i-sv)*(e-t)/(w3-sv)+t},P3=new Go.Vector3,Td=new Go.Vector3,O3=new Go.Vector3,T3=new Go.Vector3;function Es(i,r){let e=O3.fromArray(i),t=T3.fromArray(r);Td.copy(t).sub(e);let o=Td.length();return Td.normalize().multiplyScalar(o*.5),P3.copy(e).add(Td).toArray()}var qr=new Go.Triangle,Cd=new Go.Vector3,Ad=new Go.Vector3,jn=new Go.Vector3;function uv(i){let r=[];for(let e=0;e<=i.index.count;e++)if(Cd.fromArray(i.index.array,e*3),qr.setFromAttributeAndIndices(i.attributes.position,Cd.x,Cd.y,Cd.z),qr.getNormal(Ad),qr.getMidpoint(jn),!(isNaN(jn.x)||isNaN(jn.y)||isNaN(jn.z))){let{a:t,b:o,c:n}=qr,a=t.toArray(),s=o.toArray(),l=n.toArray(),c=t.distanceTo(o),u=o.distanceTo(n),p=n.distanceTo(t),d=Es(a,s),f=Es(s,l),h=Es(l,a),m=[c,u,p],y=Math.max(...m),b=m.filter(O=>Math.round(O)===Math.round(y)).length>1,v=[],w=qr.getMidpoint(jn).toArray();y===c&&!b&&(v=[f,h,h],w=d),y===u&&!b&&(v=[d,h,h],w=f),y===p&&!b&&(v=[d,f,f],w=h),b&&(v=[d,f,h]),r.push({vertices:[a,s,l],faceCenters:v,midpoint:w,norm:qr.getNormal(Ad).toArray()})}return r}function dv(i){let r=[],{position:e}=i.attributes;for(let t=0;t<e.count;t++){qr.setFromAttributeAndIndices(e,t*3,t*3+1,t*3+2),qr.getNormal(Ad),qr.getMidpoint(jn);let o=qr.a.toArray(),n=qr.b.toArray(),a=qr.c.toArray();r.push({vertices:[o,n,a],faceCenters:[Es(o,n),Es(n,a),Es(a,o)],midpoint:jn.toArray(),norm:Ad.toArray()})}return r}var C3=4,A3=.5,wh=i=>.5*(1-Math.cos(i*Math.PI)),Ph=class{constructor(){this.perlin=new Array(4095+1)}noise(r,e=0,t=0){if(this.perlin==null){this.perlin=new Array(4095+1);for(let b=0;b<4095+1;b++)this.perlin[b]=Math.random()}r<0&&(r=-r),e<0&&(e=-e),t<0&&(t=-t);let o=Math.floor(r),n=Math.floor(e),a=Math.floor(t),s=r-o,l=e-n,c=t-a,u,p,d=0,f=.5,h,m,y;for(let b=0;b<C3;b++){let v=o+(n<<4)+(a<<8);u=wh(s),p=wh(l),h=this.perlin[v&4095],h+=u*(this.perlin[v+1&4095]-h),m=this.perlin[v+16&4095],m+=u*(this.perlin[v+16+1&4095]-m),h+=p*(m-h),v+=256,m=this.perlin[v&4095],m+=u*(this.perlin[v+1&4095]-m),y=this.perlin[v+16&4095],y+=u*(this.perlin[v+16+1&4095]-y),m+=p*(y-m),h+=wh(c)*(m-h),d+=h*f,f*=A3,o<<=1,s*=2,n<<=1,l*=2,a<<=1,c*=2,s>=1&&(o++,s--),l>=1&&(n++,l--),c>=1&&(a++,c--)}return d}noiseSeed(r){let e=(()=>{let a,s;return{setSeed(l){s=a=(l??Math.random()*4294967296)>>>0},getSeed(){return a},rand(){return s=(1664525*s+1013904223)%4294967296,s/4294967296}}})();e.setSeed(r),this.perlin=new Array(4095+1);for(let t=0;t<4095+1;t++)this.perlin[t]=e.rand()}},pv=Ph;var Ns=require("three");var fv=new Ns.Vector3,hv=new Ns.Matrix4,mv=new Ns.Ray;function yv(i){let r=!1;return i.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&(t.geometry.type==="TextGeometry"||t.geometry.type==="InputGeometry")&&(r=!0)}),r}var Ki=class extends ft{constructor(e,t,o){super(e,t,o);this.data=t}get textGeometry(){return this.geometry}get charWidths(){return this.textGeometry.charWidths}get charCoords(){return this.textGeometry.charCoords}get wrappedText(){return this.textGeometry.wrappedText}get font(){return this.textGeometry.font}get initialOffsetY(){let e=this.dataPatched;return this.font?.getLineInitialOffsetY(this.lineHeight,this.wrappedText.length,e.geometry.height,this.fontScale,e.geometry.verticalAlign)??0}get fontScale(){let e=this.dataPatched;return this.font?e.geometry.fontSize/this.font.unitsPerEm:1}get AD(){return Math.abs(this.ascender-this.descender)}get ascender(){return(this.font?.ascender??1)*this.fontScale}get descender(){return(this.font?.descender??1)*this.fontScale}get lineHeight(){let e=this.dataPatched;return e.geometry.fontSize*e.geometry.lineHeight}raycast(e,t){let{matrixWorld:o}=this;if(!(isNaN(e.ray.origin.x)||this.scale.x===0||this.scale.y===0||this.scale.z===0)&&(hv.copy(o).invert(),mv.copy(e.ray).applyMatrix4(hv),mv.intersectBox(this.singleBBox,fv))){let n=fv.applyMatrix4(o),a=e.ray.origin.distanceTo(n);t.push({distance:a,point:n.clone(),object:this})}}};var gr=1e-4,Fo,bv,vv,Sv,gv=new et.Vector3,xv=new et.Vector3;Ju.then(i=>{Fo=i,bv=[Fo.get_face_center,Fo.get_edge_midpoint,Fo.get_vertex_position],vv=[Fo.get_face_normal,Fo.get_edge_normal,Fo.get_vertex_normal],Sv=[Fo.face_count,Fo.edge_count,Fo.vertex_count]});var M3=new et.Matrix4,I3=new et.Matrix4,Qi=new et.Vector3,Md=new et.Vector3,Jl=new et.Vector3,Oh=new et.Vector3,E3=new et.Vector3,N3=new et.Vector3;var Th=class{constructor(r,e){this.data=r;this.is3D=e;this.perlin=new pv;r.noiseType==="perlin"?(this.perlin.noiseSeed(r.seed),e?this.noise=(o,n,a)=>this.perlin.noise(o,n,a):this.noise=o=>this.perlin.noise(o)):e?this.noise=Q0((0,Id.default)(r.seed)):this.noise=K0((0,Id.default)(r.seed))}},Zi=class extends za(et.Object3D){constructor(e,t){super();this.parameters=t;this.objectForSample=void 0;this._pendingMediaLoad=!1;this.random=null;this.object=e}resetOnMove(){this.removeFromParent(),this.parent=null}expandClones(e){if(this.parent===null)this.updateState(this.parameters,e);else for(let t of this.children)t instanceof ao&&t.expand()}invalidateTransform(e){this.matrixWorldNeedsUpdate=!0,this.traverse(t=>{t instanceof ao&&t.object===e&&(t.matrixWorldNeedsUpdate=!0)})}onObjUpdateMatrix(){this.parameters.type!=="toObject"&&(this.matrixWorldNeedsUpdate=!0)}update(){switch(this._updateCount(),this.parameters.type){case"radial":this._updateRadial(this.parameters);break;case"linear":this._updateLinear(this.parameters);break;case"grid":this._updateGrid(this.parameters);break;case"toObject":this._updateToObject(this.parameters)}for(let e of this.children)e.updateMatrix(),e.hasNonUniformScale&&(e.updateMatrixWorld(),e.updateMatrixWorldSVD())}_updateCount(e){let t;if(e!==void 0?t=e:t=this.parameters.type==="grid"?Math.round(this.parameters.grid.count[0])*Math.round(this.parameters.grid.count[1])*Math.round(this.parameters.grid.count[2]):this.parameters.count,this.parameters.type==="toObject"){if(!this.parameters.toObject.object)t=0;else if(e===void 0&&this.parameters.toObject.spreadType!=="random")return}if(this.parameters.type==="toObject"&&this.objectForSample){let o=this.children;if(o.length===t)return;if(o.length<t)for(let n=0,a=t-o.length;n<a;++n){let s=new ao(this.object);s.expand(),this.add(s)}else for(let n=0,a=o.length-t;n<a;++n)this.remove(o[n])}else{if(this.children.length===t)return;if(this.children.length<t)for(let o=0,n=t-this.children.length;o<n;++o){let a=new ao(this.object);a.expand(),this.add(a)}else for(let o=0,n=this.children.length-t;o<n;++o)this.remove(this.children[o])}}getRandom(e,t=!1){return(this.random===null||this.random.data.seed!==e.seed||this.random.is3D!==t)&&(this.random=new Th(e,t)),this.random}_updateRadial(e){let t=e.radial,o=t.start*et.MathUtils.DEG2RAD,n=t.end*et.MathUtils.DEG2RAD,a=o-n,s=new et.Euler(t.rotation[0],t.rotation[1],t.rotation[2]),l;switch(t.axis){case"z":l=new et.Vector3(0,0,1);break;case"y":l=new et.Vector3(0,1,0);break;default:case"x":l=new et.Vector3(1,0,0);break}let c=e.randomnessObject??Mo.defaultData([1,1,1]).randomnessObject,u=this.getRandom(c),p=Zl(c.strength,this.parameters.randomness);for(let[d,f]of this.children.entries()){let h=d*(c.freqScale/10)+c.movement,m=u.noise(h,h,h),y=d+1;f.scale.x=t.scale[0]+p(y,Ee(m,c.scale[0]))||gr,f.scale.y=t.scale[1]+p(y,Ee(m,c.scale[1]))||gr,f.scale.z=t.scale[2]+p(y,Ee(m,c.scale[2]))||gr,f.position.setScalar(0);let b=a/e.count*d-o;switch(t.axis){case"x":f.rotation.set(0,b,0);break;case"y":f.rotation.set(0,0,b);break;case"z":f.rotation.set(b,0,0);break}f.translateOnAxis(l,t.radius),f.position.x+=t.position[0]+p(y,Ee(m,c.position[0])),f.position.y+=t.position[1]+p(y,Ee(m,c.position[1])),f.position.z+=t.position[2]+p(y,Ee(m,c.position[2]));let v=p(y,Ee(m,c.rotation[0])),w=p(y,Ee(m,c.rotation[1])),O=p(y,Ee(m,c.rotation[2]));t.alignment===!0?(f.rotation.x+=s.x+v,f.rotation.y+=s.y+w,f.rotation.z+=s.z+O):f.rotation.set(s.x+v,s.y+w,s.z+O)}}_updateLinear(e){if(e.type!=="linear")throw new Error;let t=e.linear,o=new et.Euler(t.rotation[0],t.rotation[1],t.rotation[2]),n=e.randomnessObject??Mo.defaultData([1,1,1]).randomnessObject,a=this.getRandom(n),s=Zl(n.strength,this.parameters.randomness);for(let[l,c]of this.children.entries()){let u=l*(n.freqScale/10)+n.movement,p=a.noise(u,u,u),d=l+1,f=s(d,Ee(p,n.rotation[0])),h=s(d,Ee(p,n.rotation[1])),m=s(d,Ee(p,n.rotation[2]));c.scale.x=1+(t.scale[0]-1)*l+s(d,Ee(p,n.scale[0]))||gr,c.scale.y=1+(t.scale[1]-1)*l+s(d,Ee(p,n.scale[1]))||gr,c.scale.z=1+(t.scale[2]-1)*l+s(d,Ee(p,n.scale[2]))||gr,c.rotation.x=o.x*l+f,c.rotation.y=o.y*l+h,c.rotation.z=o.z*l+m,c.position.x=t.position[0]*l+s(d,Ee(p,n.position[0])),c.position.y=t.position[1]*l+s(d,Ee(p,n.position[1])),c.position.z=t.position[2]*l+s(d,Ee(p,n.position[2]))}}_updateGrid(e){let t=0,o=e.grid,n=e.randomnessObject??Mo.defaultData([1,1,1]).randomnessObject,a=this.getRandom(n,!0),s=Zl(n.strength,this.parameters.randomness);if(o.useCenter===!0){let l={x:o.count[0]%2===0?2:1,y:o.count[1]%2===0?2:1,z:o.count[2]%2===0?2:1},c=new et.Vector3(o.size[0]*(o.count[0]-l.x)*.5,o.size[1]*(o.count[1]-l.y)*.5,o.size[2]*(o.count[2]-l.z)*.5);for(let u=0;u<o.count[0];u++)for(let p=0;p<o.count[1];p++)for(let d=0;d<o.count[2];d++){let f=a.noise((u+1)*(n.freqScale/10)+n.movement,(p+1)*(n.freqScale/10)+n.movement,(d+1)*(n.freqScale/10)+n.movement),h=this.children[t++];h.scale.x=1+s(t,Ee(f,n.scale[0]))||gr,h.scale.y=1+s(t,Ee(f,n.scale[1]))||gr,h.scale.z=1+s(t,Ee(f,n.scale[2]))||gr;let m=s(t,Ee(f,n.rotation[0])),y=s(t,Ee(f,n.rotation[1])),b=s(t,Ee(f,n.rotation[2]));h.rotation.set(m,y,b),h.position.x=o.size[0]*u-c.x+s(t,Ee(f,n.position[0])),h.position.y=o.size[1]*p-c.y+s(t,Ee(f,n.position[1])),h.position.z=o.size[2]*d-c.z+s(t,Ee(f,n.position[2]))}}else for(let l=0;l<o.count[0];l++)for(let c=0;c<o.count[1];c++)for(let u=0;u<o.count[2];u++){let p=a.noise((l+1)*(n.freqScale/10)+n.movement,(c+1)*(n.freqScale/10)+n.movement,(u+1)*(n.freqScale/10)+n.movement),d=this.children[t++];d.scale.x=1+s(t,Ee(p,n.scale[0]))||gr,d.scale.y=1+s(t,Ee(p,n.scale[1]))||gr,d.scale.z=1+s(t,Ee(p,n.scale[2]))||gr;let f=s(t,Ee(p,n.rotation[0])),h=s(t,Ee(p,n.rotation[1])),m=s(t,Ee(p,n.rotation[2]));d.rotation.set(f,h,m),d.position.x=o.size[0]*l+s(t,Ee(p,n.position[0])),d.position.y=-o.size[1]*c+s(t,Ee(p,n.position[1])),d.position.z=-o.size[2]*u+s(t,Ee(p,n.position[2]))}}_updateToObject(e){if(e.type!=="toObject")throw new Error;let{toObject:t}=e,o=new et.Euler(t.rotation[0],t.rotation[1],t.rotation[2]),n=e.randomnessObject??Mo.defaultData([1,1,1]).randomnessObject,a=this.getRandom(n),s=Zl(n.strength,this.parameters.randomness);if(!t.object){for(let[,d]of this.children.entries())d.position.set(0,0,0),d.scale.setScalar(1),d.rotation.set(0,0,0);this.objectForSample=void 0;return}if(!this.objectForSample)return;if(this.objectForSample instanceof Ki)if(!this.objectForSample.font?.isLoaded||this.objectForSample.geometry.attributes.position===void 0){this._pendingMediaLoad=!0;return}else this._pendingMediaLoad=!1;if(this.objectForSample.geometry===void 0&&this.objectForSample.isAncestorOf(this.object.uuid)){console.warn(`Oh no! The object "${this.object.name}" (${this.object.uuid}) seem to be a child/descendant of the object it's being cloned to. Please re-parent it so that they are siblings instead.`);return}let l=this.getSubdivData();if(l.length>0){let d=Math.round(l.length*t.count/100);this._updateCount(d)}else{let d=this.objectForSample.geometry.getAttribute("position");if(!d||isNaN(d.count)||d.count===0){console.warn(`Oh no! The object "${this.object.name}" (${this.object.uuid}) cannot be cloned on the surface of "${this.objectForSample.name}" (${this.objectForSample.uuid}) because the latter does not have a valid geometry.`);return}}this.objectForSample.updateMatrixWorld();let c=new Lu(this.objectForSample).build(),u=lv[t.axis],p=this.children;c.setRandomGenerator((0,Id.default)(this.object.uuid+t.seed));for(let[d,f]of p.entries()){let h=d*(n.freqScale/10)+n.movement,m=a.noise(h,h,h),y=d+1,b=s(y,Ee(m,n.rotation[0])),v=s(y,Ee(m,n.rotation[1])),w=s(y,Ee(m,n.rotation[2]));t.spreadType==="random"?c.sample(Jl,Oh):(l.length&&(Jl.fromArray(l[d].pos),Oh.fromArray(l[d].norm)),this.objectForSample instanceof Fn&&Jl.applyMatrix4(M3.copy(this.objectForSample.matrixWorld).invert())),Jl.applyMatrix4(this.object.hiddenMatrix.clone().invert()),f.position.copy(Jl),Qi.fromArray(u);let O=t.align==="normal"?Oh:this.object.getWorldDirection(N3),S=Md.fromArray(t.position);Md.x+=s(y,Ee(m,n.position[0])),Md.y+=s(y,Ee(m,n.position[1])),Md.z+=s(y,Ee(m,n.position[2]));let T=Math.acos(O.dot(Qi)),A=E3.crossVectors(Qi,O).normalize(),g=I3.makeRotationAxis(A,T),D=O.clone().cross(this.object.up).normalize(),E=D.clone().cross(O).normalize(),I=new et.Matrix4().makeBasis(D,O,E),N=new et.Vector3(Qi.y,Qi.z,Qi.x).normalize(),_=N.clone().cross(Qi).normalize(),R=new et.Matrix4().makeBasis(N,Qi,_).invert(),V=new et.Matrix4().multiplyMatrices(I,R);f.rotation.setFromRotationMatrix(V),S.applyMatrix4(g),f.position.add(S),f.rotation.x=f.rotation.x+o.x+b,f.rotation.y=f.rotation.y+o.y+v,f.rotation.z=f.rotation.z+o.z+w,f.scale.setScalar(1),f.scale.x=f.scale.x+t.scale[0]+s(y,Ee(m,n.scale[0]))||gr,f.scale.y=f.scale.y+t.scale[1]+s(y,Ee(m,n.scale[1]))||gr,f.scale.z=f.scale.z+t.scale[2]+s(y,Ee(m,n.scale[2]))||gr,f.scale.multiply(this.object.scale),f.hiddenMatrix=this.object.hiddenMatrix}}getSubdivData(){if(!this.objectForSample)return[];let e=this.parameters.toObject.spreadType,t=new Map,o=(a,s)=>{let l=Math.round(a[0]*1e4)+"_"+Math.round(a[1]*1e4)+"_"+Math.round(a[2]*1e4),c=t.get(l);c?(c.pos[0]+=a[0],c.pos[1]+=a[1],c.pos[2]+=a[2],c.norm[0]+=s[0],c.norm[1]+=s[1],c.norm[2]+=s[2],c.count+=1):t.set(l,{pos:[...a],norm:[...s],count:1})};if(e==="random")return[];if(this.objectForSample instanceof Fn){let a=this.objectForSample,s=cv[e],l=Sv[s],c=bv[s],u=vv[s],p=l(a.subdivPointerNew);for(let d=0;d<=p-1;d++){let f=c(a.subdivPointerNew,d),h=u(a.subdivPointerNew,d);gv.fromArray(f).applyMatrix4(a.matrixWorld),xv.fromArray(h),o(gv.toArray(),xv.toArray())}}else(this.objectForSample.geometry.index?uv(this.objectForSample.geometry):dv(this.objectForSample.geometry)).forEach((s,l)=>{e==="polygon_center"&&o(s.midpoint,s.norm),e==="vertex"&&(o(s.vertices[0],s.norm),o(s.vertices[1],s.norm),o(s.vertices[2],s.norm)),e==="edge"&&(o(s.faceCenters[0],s.norm),o(s.faceCenters[1],s.norm),o(s.faceCenters[2],s.norm))});let n=Array.from(t.values());for(let a of n)a.pos[0]/=a.count,a.pos[1]/=a.count,a.pos[2]/=a.count,a.norm[0]/=a.count,a.norm[1]/=a.count,a.norm[2]/=a.count;return n}updateState(e,t){if(this.parameters=Qo(e),this.parameters.type!=="toObject")(this.parent===null||this.parent!==this.object)&&(this.removeFromParent(),this.object.parent?.add(this),this.matrix=this.object.matrix,this.hiddenMatrix=this.object.hiddenMatrix,this.matrixWorldNeedsUpdate=!0,this.matrixAutoUpdate=!1);else if(this.parent===null||this.parent.uuid!==this.parameters.toObject.object){this.removeFromParent();let o=t.find(this.parameters.toObject.object);o instanceof Ut?this.objectForSample=o:this.objectForSample=void 0,this.matrix=new et.Matrix4,this.hiddenMatrix=new et.Matrix4,this.matrixWorldNeedsUpdate=!0,this.matrixAutoUpdate=!1,o&&o.add(this)}this.update()}get pendingMediaLoad(){return this._pendingMediaLoad}};var Jr=require("three");var gt=require("three");var ar=require("three");var wv=require("three"),jo=i=>{var r;return r=class extends i{},r.geometryHelper=new wv.BoxGeometry(30,30,30),r};var dr=require("three"),Ed=new dr.Ray,Ch=new dr.Sphere,Pv=new dr.Matrix4,Uo=(i,r,e,t,o=!1,n=i)=>{let a=r,s=n.matrixWorld;if(a.boundingSphere===null&&a.computeBoundingSphere(),Ch.copy(a.boundingSphere),Ch.applyMatrix4(s),e.ray.intersectsSphere(Ch)===!1||(Pv.copy(s).invert(),Ed.copy(e.ray).applyMatrix4(Pv),a.boundingBox!==null&&Ed.intersectsBox(a.boundingBox)===!1))return;let l,c,u,p,d=a.index,f=a.attributes.position,h=a.drawRange,m,y;if(o===!1){let v=Math.max(0,h.start),w=Math.min(d.count,h.start+h.count);for(m=v,y=w;m<y;m+=3)if(c=d.getX(m),u=d.getX(m+1),p=d.getX(m+2),l=b(i,e,Ed,f,c,u,p),l){l.faceIndex=Math.floor(m/3),t.push(l);return}}else{let w=a.attributes.position,O=new dr.Vector3,S=new dr.Vector3,T=new dr.Vector3,A=new dr.Vector3,g=2,E=1/((n.scale.x+n.scale.y+n.scale.z)/3),I=E*E,N=Math.max(0,h.start),_=Math.min(w.count,h.start+h.count);for(let R=N,V=_-1;R<V;R+=g){if(O.fromBufferAttribute(w,R),S.fromBufferAttribute(w,R+1),Ed.distanceSqToSegment(O,S,A,T)>I)continue;A.applyMatrix4(n.matrixWorld);let B=e.ray.origin.distanceTo(A);B<e.near||B>e.far||t.push({distance:B,point:T.clone().applyMatrix4(n.matrixWorld),object:i})}}function b(v,w,O,S,T,A,g){let D=new dr.Vector3,E=new dr.Vector3,I=new dr.Vector3,N=new dr.Vector3,_=new dr.Vector3;if(D.fromBufferAttribute(S,T),E.fromBufferAttribute(S,A),I.fromBufferAttribute(S,g),O.intersectTriangle(D,E,I,!1,N)===null)return null;_.copy(N),_.applyMatrix4(v.matrixWorld);let V=w.ray.origin.distanceTo(_);return V<w.near||V>w.far?null:{faceIndex:1,distance:V,point:_.clone(),object:v}}};var Nd=new ar.Vector3,$r=new ar.Camera,Ah=class extends ar.LineSegments{constructor(e){let t=new ar.BufferGeometry,o=new ar.LineBasicMaterial({color:16777215,vertexColors:!0,toneMapped:!1}),n=[],a=[],s={},l=new ar.Color(15711266),c=new ar.Color(15711266),u=new ar.Color(2857471);p("n1","n2",l),p("n2","n4",l),p("n4","n3",l),p("n3","n1",l),p("f1","f2",l),p("f2","f4",l),p("f4","f3",l),p("f3","f1",l),p("n1","f1",l),p("n2","f2",l),p("n3","f3",l),p("n4","f4",l),p("p","n1",c),p("p","n2",c),p("p","n3",c),p("p","n4",c),p("u1","u2",u),p("u2","u3",u),p("u3","u1",u);function p(f,h,m){d(f,m),d(h,m)}function d(f,h){n.push(0,0,0),a.push(h.r,h.g,h.b),s[f]===void 0&&(s[f]=[]),s[f].push(n.length/3-1)}t.setAttribute("position",new ar.Float32BufferAttribute(n,3)),t.setAttribute("color",new ar.Float32BufferAttribute(a,3));super(t,o);this.type="CameraHelper",this.camera=e,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=e.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=s,this.update()}update(){let e=this.geometry,t=this.pointMap,o=!0;$r.projectionMatrixInverse.elements=[.5112609807824982,-0,-0,-0,-0,.41421356237309503,-0,-0,-0,-0,-0,-.099999,-0,-0,-1.0000000000000002,.100001];let n=1,a=1,s=o?.8:1e-4;bo("n1",t,e,$r,-n,-a,s),bo("n2",t,e,$r,n,-a,s),bo("n3",t,e,$r,-n,a,s),bo("n4",t,e,$r,n,a,s);let l=s;bo("f1",t,e,$r,-n,-a,l),bo("f2",t,e,$r,n,-a,l),bo("f3",t,e,$r,-n,a,l),bo("f4",t,e,$r,n,a,l);let c=l,u=.5;bo("u1",t,e,$r,n*.7*u,a*1.1,c),bo("u2",t,e,$r,-n*.7*u,a*1.1,c),bo("u3",t,e,$r,0,a*(1.1+.9*u),c),e.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}};function bo(i,r,e,t,o,n,a){Nd.set(o,n,a).unproject(t);let s=r[i];if(s!==void 0){let l=e.getAttribute("position");for(let c=0,u=s.length;c<u;c++)l.setXYZ(s[c],Nd.x,Nd.y,Nd.z)}}var Dd=class extends jo(Ah){constructor(e){super(e);this.object=e;this.object=e,this.name=`CombinedCameraHelper: ${e.uuid}`}updateMatrixWorld(e){super.updateMatrixWorld(e),this.updateTarget()}updateTarget(){let e=this.object.getTarget();this.updateWorldMatrix(!0,!1),this.worldToLocal(e)}raycast(e,t){Uo(this.object,this.geometry,e,t,!0)}};var ec=require("three");var _d;(r=>r.is=e=>"objectHelper"in e)(_d||(_d={}));var Xr=(i,r)=>class extends ja(i){constructor(){super(...arguments);this.objectHelper=new r(this);this.gizmos={}}get geometryHelper(){return r.geometryHelper}raycast(o,n){this.objectHelper.raycast(o,n)}showGizmos(){for(let o in this.gizmos){let n=this.gizmos[o];n instanceof ec.Box3Helper&&(n.visible=!0)}}updateEntityBoxSize(o,n){this.objectHelper.visible&&this.geometryHelper instanceof ec.BoxGeometry?(o.setScalar(0),n.set(this.geometryHelper.parameters.width,this.geometryHelper.parameters.height,this.geometryHelper.parameters.height).multiplyScalar(.5)):super.updateEntityBoxSize(o,n)}hideGizmos(){for(let o in this.gizmos){let n=this.gizmos[o];n instanceof ec.Box3Helper&&(n.visible=!1)}}};var Rd=790,Ds=new gt.Vector3,Mh=new gt.Vector3,Ih=new gt.Quaternion,Eh=new gt.Vector3,tc=new gt.Vector3,Nh=new gt.Vector3,yi=class extends Xr(gt.Camera,Dd){constructor(e="",t={...Pn.defaultData,name:""}){super();this._cameraType="OrthographicCamera";this.targetOffset=Li.DefaultTargetOffset;this.isUpVectorFlipped=!1;this.angleOffsetFromUp=0;this.wasMovedByUser=!1;this.wasMovedBySwitchCameraAction=!1;this.super_Entity(e,t),this.previousProjectionMatrix=new gt.Matrix4,this.matrixAutoUpdate=!0,this.width=window.innerWidth,this.height=window.innerHeight;let o=this.width,n=this.height;this.orthoCamera=new gt.OrthographicCamera(o*-.5,o*.5,n*.5,n*-.5,-5e4,1e4),this.perspCamera=new gt.PerspectiveCamera(45,o/n,50,1e4),this.left=this.orthoCamera.left,this.right=this.orthoCamera.right,this.top=this.orthoCamera.top,this.bottom=this.orthoCamera.bottom,this.far=this.orthoCamera.far,this.view=this.orthoCamera.view,this.aspect=this.perspCamera.aspect,this.focus=this.perspCamera.focus,this.filmGauge=this.perspCamera.filmGauge,this.filmOffset=this.perspCamera.filmOffset,this.objectHelper.update()}get isPerspectiveCamera(){return this.cameraType==="PerspectiveCamera"}get isOrthographicCamera(){return!this.isPerspectiveCamera}get cameraType(){return this._cameraType}set fov(e){this.perspCamera.fov=e}get fov(){return this.perspCamera.fov}setNear(e,t){e==="PerspectiveCamera"?this.perspCamera.near=t:this.orthoCamera.near=t}setZoom(e,t){t>=0&&(e==="PerspectiveCamera"?this.perspCamera.zoom=t:this.orthoCamera.zoom=t)}set cameraType(e){e==="PerspectiveCamera"?this.toPerspective():e==="OrthographicCamera"&&this.toOrthographic()}get near(){return this._cameraType==="PerspectiveCamera"?this.perspCamera.near:this.orthoCamera.near}set near(e){this._cameraType==="PerspectiveCamera"?this.perspCamera.near=e:this.orthoCamera.near=e}get zoom(){return this._cameraType==="PerspectiveCamera"?this.perspCamera.zoom:this.orthoCamera.zoom}set zoom(e){e>=0&&(this._cameraType==="PerspectiveCamera"?this.perspCamera.zoom=e:this.orthoCamera.zoom=e)}lookAt(e,t,o){typeof e=="number"&&(e=new gt.Vector3(e,t,o)),super.lookAt(e),this.getWorldPosition(Ds),this.targetOffset=Ds.distanceTo(e)}getTarget(e=new gt.Vector3){return this.getWorldDirection(Mh),this.getWorldPosition(Ds),Mh.multiplyScalar(this.targetOffset),e.copy(Ds).add(Mh),e}getDistanceToTarget(){let e=this.getTarget();return this.getWorldPosition(Ds),Ds.distanceTo(e)}updateUp(){this.getWorldQuaternion(Ih),Eh.set(0,0,1).applyQuaternion(Ih),tc.copy(gt.Object3D.DEFAULT_UP),this.isUpVectorFlipped&&tc.negate(),tc.applyQuaternion(Ih),Nh.copy(gt.Object3D.DEFAULT_UP).projectOnPlane(Eh),this.angleOffsetFromUp=Nh.angleTo(tc),this.angleOffsetFromUp*=Nh.cross(tc).dot(Eh)>=0?1:-1}updateTransformState(e,t){let o=super.updateTransformState(e,t);return e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateUp(),o}getViewFrontToObject(e){let t=e.getWorldPosition(new gt.Vector3),n=e.getWorldDirection(new gt.Vector3).multiplyScalar(this.targetOffset);return{position:t.clone().add(n),target:t}}getViewToTarget(e){let o=this.getWorldDirection(new gt.Vector3).multiplyScalar(this.targetOffset);return{position:e.clone().sub(o),target:e}}getViewToObject(e){let t=new gt.Vector3,o=e.getWorldPosition(t);return this.getViewToTarget(t)}setViewplaneSize(e,t,o=!1){if(this.aspect=e/t,o){let n=e>t?this.aspect:1,a=e>t?1:this.aspect;this.left=-Rd*.5*n,this.right=Rd*.5*n,this.top=Rd*.5*(1/a),this.bottom=-Rd*.5*(1/a)}else this.left=-e*.5,this.right=e*.5,this.top=t*.5,this.bottom=-t*.5;this.updateProjectionMatrix()}copyViewPlaneSize(e){this.aspect=e.aspect,this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.updateProjectionMatrix()}toOrthographic(){this.orthoCamera.left=this.left,this.orthoCamera.right=this.right,this.orthoCamera.top=this.top,this.orthoCamera.bottom=this.bottom,this.orthoCamera.view=this.view,this.orthoCamera.far=this.far,this.orthoCamera.updateProjectionMatrix(),this.projectionMatrix=this.orthoCamera.projectionMatrix,this.projectionMatrixInverse=this.orthoCamera.projectionMatrixInverse,this._cameraType="OrthographicCamera",this.objectHelper&&this.objectHelper.update()}toPerspective(){this.perspCamera.aspect=this.aspect,this.perspCamera.fov=this.fov,this.perspCamera.view=this.view,this.perspCamera.far=this.far,this.perspCamera.updateProjectionMatrix(),this.projectionMatrix=this.perspCamera.projectionMatrix,this.projectionMatrixInverse=this.perspCamera.projectionMatrixInverse,this._cameraType="PerspectiveCamera",this.objectHelper&&this.objectHelper.update()}setFocalLength(e){this.perspCamera.setFocalLength(e),this.toPerspective()}getFocalLength(){return this.perspCamera.getFocalLength()}getEffectiveFOV(){return this.perspCamera.getEffectiveFOV()}getFilmWidth(){return this.perspCamera.getFilmWidth()}getFilmHeight(){return this.perspCamera.getFilmHeight()}setViewOffset(e,t,o,n,a,s){this._cameraType==="PerspectiveCamera"?this.perspCamera.setViewOffset(e,t,o,n,a,s):this.orthoCamera.setViewOffset(e,t,o,n,a,s)}clearViewOffset(){this._cameraType==="PerspectiveCamera"?(this.perspCamera.clearViewOffset(),this.toPerspective()):(this.orthoCamera.clearViewOffset(),this.toOrthographic())}copyHistory(){this.previousProjectionMatrix&&this.previousProjectionMatrix.copy(this.projectionMatrix)}updateProjectionMatrix(){this._cameraType==="PerspectiveCamera"?this.toPerspective():this._cameraType==="OrthographicCamera"&&this.toOrthographic()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}copy(e,t){return super.copy(e,t),this.parent=e.parent,this.orthoCamera.copy(e.orthoCamera),this.perspCamera.copy(e.perspCamera),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.far=e.far,this.view=e.view===null?null:Object.assign({},e.view),this._cameraType=e._cameraType,this.aspect=e.aspect,this.fov=e.fov,this.focus=e.focus,this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this.targetOffset=e.targetOffset,this.updateProjectionMatrix(),this}toCameraState(e=[]){let t={type:this.cameraType,far:this.far,orthographic:{near:this.orthoCamera.near,zoom:this.orthoCamera.zoom},perspective:{near:this.perspCamera.near,fov:this.perspCamera.fov,zoom:this.perspCamera.zoom},up:this.up.toArray(),targetOffset:this.targetOffset,isUpVectorFlipped:this.isUpVectorFlipped};return ya(t,e)}updateCameraSubtype(e,t){let o=e==="perspective"?"PerspectiveCamera":"OrthographicCamera";t.zoom!==void 0&&this.setZoom(o,t.zoom),t.near!==void 0&&this.setNear(o,t.near),t.fov!==void 0&&o==="PerspectiveCamera"&&(this.fov=t.fov)}updateState(e,t){this.updateCameraState(e,t)}updateCameraState(e,t){this.updateState_Entity(e,t),e.far!==void 0&&(this.far=e.far),e.orthographic!==void 0&&this.updateCameraSubtype("orthographic",e.orthographic),e.perspective!==void 0&&this.updateCameraSubtype("perspective",e.perspective),e.type!==void 0&&(this.cameraType=e.type),e.up!==void 0&&this.up.fromArray(e.up),e.targetOffset!==void 0&&(this.targetOffset=e.targetOffset),e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateProjectionMatrix()}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.path.length===1&&e.type===0&&this.updateCameraSubtype(e.path[0],e.props)}toState(e){return{...super.toState(e),...this.toCameraState(e),type:this.cameraType}}};var R3=require("three");var Ji=require("three");var _s=new Ji.Matrix4,_3=new Ji.Matrix4;var Ar=class extends Cr{constructor(e,t,o){super(e,t);this.data=t;this.meshSetAddresses=[];this.needsTransformForDownstream=!1;this.geometry=new Ji.BufferGeometry;this.onAfterRender=(e,t,o,n,a,s)=>{super.onAfterRender(e,t,o,n,a,s),this.recomputeBoolean()};this.geometry.userData.parameters={width:0,height:0,depth:0}}get booleanOp(){return this.data.geometry.operation}get phongAngle(){return this.data.geometry.phongAngle??45}get isLOD(){return this.recomputeBoolean(),!1}updateByPatchedOp(e,t,o){super.updateByPatchedOp(e,t,o),e.path.length===1&&e.path[0]==="geometry"&&e.type===0&&e.props.operation!==void 0&&(this.freeBooleanPointer(),this.resetBBoxNeedsUpdate())}freeBooleanPointer(){super.freeBooleanPointer(),this.geometry.dispose()}recomputeBoolean(e,t=!0){if(this.booleanMeshSetAddress!==-1&&!e)return;for(let n=0;n<this.children.length;n++){let a=this.children[n];a instanceof Ar&&a.dataPatched.visible===!0&&a.recomputeBoolean(e===!0,t)}this.meshSetAddresses=[];for(let n=0;n<this.children.length;n++){let a=this.children[n];if(a instanceof Ut&&a.dataPatched.visible===!0&&a.geometry.attributes.position?.count>0&&a.geometry.drawRange.count>0&&a.booleanMeshSetAddress!==0){_s.multiplyMatrices(a.hiddenMatrix,a.matrix);try{if(a.booleanMeshSetAddress===-1){if((a.geometry.index??a.geometry.getAttribute("position")).count/3<15e5&&(a.booleanMeshSetAddress=Hr.getMeshSet(a.geometry,e===!0,t)),a.booleanMeshSetAddress===-1)return;Hr.transformMeshSet(a.booleanMeshSetAddress,_s),a.booleanMatrixInvOld.copy(_s).invert(),a.booleanWasTransformed=!1}else a instanceof Ar&&a.needsTransformForDownstream===!0?(Hr.transformMeshSet(a.booleanMeshSetAddress,_s),a.needsTransformForDownstream=!1):a.booleanWasTransformed===!0&&(Hr.transformMeshSet(a.booleanMeshSetAddress,_3.multiplyMatrices(_s,a.booleanMatrixInvOld)),a.booleanMatrixInvOld.copy(_s).invert(),a.booleanWasTransformed=!1)}catch(s){console.error(s),a.booleanMeshSetAddress=0,a.geometry.userData.booleanOperationDidFail=!0;continue}Hr.hasOpenEdges(a.booleanMeshSetAddress)===!1||n===this.children.length-1&&this.booleanOp===2?(this.meshSetAddresses.push(a.booleanMeshSetAddress),a.geometry.userData.booleanOperationDidFail=!1):a.geometry.userData.booleanOperationDidFail="openEdges"}}if(this.meshSetAddresses.length===0){this.geometry.setAttribute("position",new Ji.Float32BufferAttribute([],0)),this.geometry.setDrawRange(0,0);return}if(e===!0)return Hr.calcBooleanTopological(this.meshSetAddresses,this.booleanOp);let o=this.geometry;o.dispose(),this.geometry=new Ji.BufferGeometry,this.geometry.userData=o.userData,this.geometry.boundingSphere=o.boundingSphere;try{this.booleanMeshSetAddress=Hr.calcBoolean(this.meshSetAddresses,this.booleanOp,this.geometry,this.phongAngle)}catch(n){this.booleanMeshSetAddress=0,this.geometry.userData.booleanOperationDidFail=!0,console.error(n)}this.booleanMatrixInvOld.copy(this.matrix).invert(),this.needsTransformForDownstream=!0,Ms(this),Is(this)}dispose(){super.dispose(),this.geometry.dispose()}};var Tv=require("three");var Ov;(r=>{function i(e){return ze.is(e)&&e instanceof Tv.Light}r.is=i})(Ov||(Ov={}));var Rs=(i,r)=>class extends Xr(i,r){updateState_Light(t,o){this.updateState_Entity(t,o),t.color!==void 0&&(this.color=o.shared.color(t.color)),t.intensity!==void 0&&(this.intensity=t.intensity),t.depth!==void 0&&(this.shadow.camera.far=t.depth,this.shadow.needsUpdate=!0),t.shadows!==void 0&&(this.castShadow=t.shadows)}};var en=i=>i instanceof Ut,rc=i=>i!==null&&i instanceof Ar;var oc=i=>_d.is(i);var Mv=require("three");var ko=require("three");var L3=new ko.Vector3(1,1,1),Cv=new ko.Vector3,B3=new ko.Vector3,Av=new ko.Quaternion,Yr=class extends jo(ko.AxesHelper){constructor(e,t=15){super(t);this.object=e;this.dummy=new ko.Group;this.object.updateMatrixWorld(),this.name=`EmptyObjectHelper: ${e.uuid}`,this.matrix=this.dummy.matrixWorld,this.matrixAutoUpdate=!1,this.object.isBone&&(this.visible=!1)}raycast(e,t){Uo(this.object,Yr.geometryHelper,e,t,!1,this.dummy)}update(){}updateMatrix(){}updateMatrixWorld(e){this.object.matrixWorld.decompose(Cv,Av,B3),this.matrix.compose(Cv,Av,L3),super.updateMatrixWorld(e)}updateWorldMatrix(e,t){}};var tn=class extends Xr(Mv.Group,Yr){constructor(r,e){super(),this.super_Entity(r,e),this.objectHelper.update()}updateState(r,e){this.updateState_Entity(r,e),"buffer"in r&&Object.keys(r).length===1&&e.scene.reloadSplats()}};var Iv=require("three");var Ls=class extends Xr(Iv.Group,Yr){constructor(e,t,o){super();this.super_Entity(e,t),this.context=o,this.objectHelper.update()}updateState(e,t){this.updateState_Entity(e,t)}};var ks=require("three");var Bs=require("three"),V3=i=>`
|
|
2290
2290
|
|
|
2291
2291
|
// PCSS implementation based on:
|
|
2292
2292
|
// https://www.gamedev.net/articles/programming/graphics/contact-hardening-soft-shadows-made-fast-r4906/
|
|
@@ -4376,4 +4376,4 @@ void main() {
|
|
|
4376
4376
|
A = exp(A) * vColor.a;
|
|
4377
4377
|
gl_FragColor = vec4(color.rgb, A);
|
|
4378
4378
|
gVelocity = vec4(0.0); // so it is ignored by TAA
|
|
4379
|
-
}`,n={covariancesTexture:{type:"t",value:null},centersColorsTexture:{type:"t",value:null},meshIndexIntervals:{value:e},meshMatrixWorldsTexture:{type:"t",value:null},focal:{type:"v2",value:new Te.Vector2},viewport:{type:"v2",value:new Te.Vector2},basisViewport:{type:"v2",value:new Te.Vector2},debugColor:{type:"v3",value:new Te.Color},covariancesTextureSize:{type:"v2",value:new Te.Vector2(1024,1024)},centersColorsTextureSize:{type:"v2",value:new Te.Vector2(1024,1024)},orthoZoom:{type:"f",value:-1}};return new Te.ShaderMaterial({uniforms:n,vertexShader:t,fragmentShader:o,transparent:!0,alphaTest:1,blending:Te.NormalBlending,depthTest:!0,depthWrite:!1,side:Te.DoubleSide})}static buildGeomtery(e){let t=new Te.BufferGeometry;t.setIndex([0,1,2,0,2,3]);let o=new Float32Array(4*3),n=new Te.BufferAttribute(o,3);t.setAttribute("position",n),n.setXYZ(0,-1,-1,0),n.setXYZ(1,-1,1,0),n.setXYZ(2,1,1,0),n.setXYZ(3,1,-1,0),n.needsUpdate=!0;let a=new Te.InstancedBufferGeometry().copy(t),s=new Uint32Array(e),l=new Te.InstancedBufferAttribute(s,1,!1);return l.setUsage(Te.DynamicDrawUsage),a.setAttribute("splatIndex",l),a.instanceCount=e,a}resetLocalSplatDataAndTexturesFromSplatBuffer(){this.updateLocalSplatDataFromSplatBuffer(),this.allocateAndStoreLocalSplatDataInTextures()}updateLocalSplatDataFromSplatBuffer(){this.splatBuffers.forEach(n=>n.buildPreComputedBuffers()),this.covariances=new Float32Array(this.splatCount*6),this.colors=new Uint8Array(this.splatCount*4),this.centers=new Float32Array(this.splatCount*3);let e=0,t=0,o=0;for(let n of this.splatBuffers){let a=n.nsplats;this.colors.subarray(e,e+a*4).set(n.colorsA),e+=a*4,this.centers.subarray(t,t+a*3).set(n.decoded.xyz.denormDequant().data),t+=a*3,this.covariances.subarray(o,o+a*6).set(new Float32Array(n.precomputedCovarianceBufferData)),o+=a*6}}allocateAndStoreLocalSplatDataInTextures(){let o=this.splatCount,n=new Te.Vector2(4096,1024);for(;n.x*n.y*2<o*6;)n.y*=2;let a=new Te.Vector2(4096,1024);for(;a.x*a.y*4<o*4;)a.y*=2;let s,l;if(this.halfPrecisionCovariancesOnGPU){l=new Uint16Array(n.x*n.y*2);for(let h=0;h<this.covariances.length;h++)l[h]=Te.DataUtils.toHalfFloat(this.covariances[h]);s=new Te.DataTexture(l,n.x,n.y,Te.RGFormat,Te.HalfFloatType)}else l=new Float32Array(n.x*n.y*2),l.set(this.covariances),s=new Te.DataTexture(l,n.x,n.y,Te.RGFormat,Te.FloatType);s.needsUpdate=!0,this.material.uniforms.covariancesTexture.value=s,this.material.uniforms.covariancesTextureSize.value.copy(n);let c=new Uint32Array(a.x*a.y*4);for(let h=0;h<o;h++){let m=h*4,y=h*3,b=h*4;c[b]=W1(this.colors[m],this.colors[m+1],this.colors[m+2],this.colors[m+3]),c[b+1]=tp(this.centers[y]),c[b+2]=tp(this.centers[y+1]),c[b+3]=tp(this.centers[y+2])}let u=new Te.DataTexture(c,a.x,a.y,Te.RGBAIntegerFormat,Te.UnsignedIntType);u.internalFormat="RGBA32UI",u.needsUpdate=!0,this.material.uniforms.centersColorsTexture.value=u,this.material.uniforms.centersColorsTextureSize.value.copy(a);let p=256*4,d=new Float32Array(256*16);for(let h=0;h<this.meshMatrixWorlds.length;h++)d.set(this.meshMatrixWorlds[h].elements,h*16);let f=new Te.DataTexture(d,p,1,Te.RGBAFormat,Te.FloatType);f.needsUpdate=!0,this.material.uniforms.meshMatrixWorldsTexture.value=f,this.material.uniformsNeedUpdate=!0,this.splatDataTextures={covariances:{data:l,texture:s,size:n},centerColors:{data:c,texture:u,size:a},meshMatrixWorlds:{data:d,texture:f}}}updateIndexes(e){let t=this.geometry;t.attributes.splatIndex.set(e),t.attributes.splatIndex.needsUpdate=!0,t.instanceCount=e.length}updateUniforms(e,t,o,n){this.splatCount>0&&(rp.set(e.x*this.devicePixelRatio,e.y*this.devicePixelRatio),this.material.uniforms.viewport.value.copy(rp),this.material.uniforms.basisViewport.value.set(2/rp.x,2/rp.y),this.material.uniforms.focal.value.set(t,o),this.material.uniforms.orthoZoom.value=n,this.material.uniformsNeedUpdate=!0)}getSplatDataTextures(){return this.splatDataTextures}getSplatCount(){return this.splatCount}getCenters(){return this.centers}getColors(){return this.colors}getCovariances(){return this.covariances}dispose(){this.geometry.dispose(),this.material.dispose(),this.splatDataTextures&&(this.splatDataTextures.covariances.texture.dispose(),this.splatDataTextures.centerColors.texture.dispose(),this.splatDataTextures.meshMatrixWorlds.texture.dispose()),this.removeFromParent()}};var $1,Yh=new Promise(i=>{$1=i}),q1=!1;var ip;function Kh(){if(q1)return;if(ip)return ip;async function i(){let e=await import("./gaussian-splat-compression.js");$1(e),q1=!0}return ip=i(),ip}var X1;Yh.then(i=>X1=i);var pc=class{constructor(r={}){yn(this,"updateView",function(){let r=new xr.Matrix4,e=[],t=new xr.Vector3(0,0,-1),o=new xr.Vector3(0,0,-1),n=new xr.Vector3,a=new xr.Vector3;return function(s=!1,l){let c=this.updateMatrixWorldsInWorkerIfNeeded(),u=this.cropsChanged();if(!s){o.set(0,0,-1).applyQuaternion(l.quaternion);let d=!1,f=!1;if(o.dot(t)<=.95&&(d=!0),a.copy(l.position).sub(n).length()>=1&&(f=!0),!d&&!f&&!c&&!u&&!this.needsInitialRender)return}this.needsInitialRender=!1,n.copy(l.position),t.copy(o),r.copy(l.matrixWorld).invert(),r.premultiply(this.dummyPerspectiveMatrix),e[0]=l.position.x,e[1]=l.position.y,e[2]=l.position.z;let p={sort:{view:r.elements,cameraPosition:e,splatRenderCount:this.splatRenderCount,splatSortCount:this.splatRenderCount},...c?{newMatrixWorlds:this.meshMatrixWorlds}:{},...u?{newCropsArray:this.cropsArray}:{}};this.sortRunning?this.queuedMessage=p:(this.queuedMessage=null,this.sortRunning=!0,this.sortWorker.postMessage(p))}}());this.scene=r.scene,this.currentPage=null,this.devicePixelRatio=window.devicePixelRatio,this.sortWorker=null,this.splatRenderCount=0,this.splatSortCount=0,this.splatMesh=null,this.sortRunning=!1,this.meshMatrixWorlds=null,this.meshMatrixWorldsOld=null,this.cropsArray=null,this.splatEntries=null,this.queuedMessage=null,this.needsInitialRender=!0,this.dummyPerspectiveMatrix=new xr.Matrix4().makePerspective(-1,1,-1,1,.1,1e3)}updateSplatMeshUniforms(r,e){let t=new xr.Vector2;if(this.splatMesh===null)return;this.splatMesh.getSplatCount()>0&&(r.getSize(t),this.cameraFocalLengthX=e.projectionMatrix.elements[0]*this.devicePixelRatio*t.x*.45,this.cameraFocalLengthY=e.projectionMatrix.elements[5]*this.devicePixelRatio*t.y*.45,this.splatMesh.updateUniforms(t,this.cameraFocalLengthX,this.cameraFocalLengthY,e.isPerspectiveCamera?-1:e.zoom*this.devicePixelRatio))}loadSplat(r={}){this.activePage=this.scene.activePage,r.position&&(r.position=new xr.Vector3().fromArray(r.position)),r.orientation&&(r.orientation=new xr.Quaternion().fromArray(r.orientation)),r.halfPrecisionCovariances=!!r.halfPrecisionCovariances;let e=[];if(this.splatEntries=e,this.activePage.traverseVisibleEntity(a=>{a.data.type==="Splat"&&e.push(a)}),this.splatMesh&&this.splatMesh.dispose(),e.length===0)return this.splatMesh=null,!1;this.meshMatrixWorlds=e.map(a=>a.matrixWorld),this.meshMatrixWorldsOld=e.map(a=>a.matrixWorld.clone()),this.cropsArray=e.map(a=>a.data.crops.map(s=>s.data));let t=e.map(a=>new X1.GSplineBuffer(new Uint8Array(a.data.buffer).buffer)),o=0,n=[0];for(let a of t)o+=a.getSplatCount(),n.push(o);return this.setupSplatMesh(t,o,r.position,r.orientation,r.halfPrecisionCovariances,this.devicePixelRatio,n,this.meshMatrixWorlds),this.setupSortWorker(o),!0}updateMatrixWorldsInWorkerIfNeeded(){let r=this.splatDataTextures.meshMatrixWorlds.data;for(let e=0;e<this.meshMatrixWorlds.length;e++)r.set(this.meshMatrixWorlds[e].elements,e*16);return this.splatDataTextures.meshMatrixWorlds.texture.needsUpdate=!0,this.meshMatrixWorlds.every((e,t)=>e.equals(this.meshMatrixWorldsOld[t]))?!1:(this.meshMatrixWorldsOld=this.meshMatrixWorlds.map(e=>e.clone()),!0)}cropsChanged(){let r=!1;return this.splatEntries.forEach((e,t)=>{e.data.crops.forEach((o,n)=>{this.cropsArray[t][n]===void 0?(r=!0,this.cropsArray[t][n]=o.data):Object.entries(o.data).forEach(([a,s])=>{Array.isArray(s)&&s.some((l,c)=>l!==this.cropsArray[t][n][a][c])?(r=!0,this.cropsArray[t][n][a]=s):s!==this.cropsArray[t][n]?.[a]&&(r=!0,this.cropsArray[t][n][a]=s)})}),e.data.crops.length!==this.cropsArray[t]?.length&&(this.cropsArray[t].length=e.data.crops.length,r=!0)}),r}setupSplatMesh(r,e,t=new xr.Vector3,o=new xr.Quaternion,n=!1,a=1,s,l){this.splatMesh=un.buildMesh(r,e,n,a,s,l),this.splatMesh.position.copy(t),this.splatMesh.quaternion.copy(o),this.splatMesh.frustumCulled=!1,this.splatMesh.renderOrder=99999,this.splatRenderCount=e,this.splatMesh.onBeforeRender=(c,u,p)=>this.update(c,p)}setupSortWorker(r){this.sortWorker=H1(r),this.sortWorker.onmessage=e=>{e.data.sortDone?(this.sortRunning=!1,this.splatMesh?.updateIndexes(new Uint32Array(e.data.indexesBuffer)),this.lastSortTime=e.data.sortTime,this.queuedMessage&&(this.sortWorker.postMessage(this.queuedMessage),this.queuedMessage=null)):e.data.sortCanceled?this.sortRunning=!1:e.data.sortSetupPhase1Complete?this.sortWorker.postMessage({positions:this.splatMesh.getCenters().buffer,meshMatrixWorlds:this.splatMesh.meshMatrixWorlds,meshIndexIntervals:this.splatMesh.meshIndexIntervals,cropsArray:this.cropsArray}):e.data.sortSetupComplete&&(this.splatDataTextures=this.splatMesh.getSplatDataTextures(),this.scene.activePage.add(this.splatMesh),this.needsInitialRender=!0)}}update(r,e){this.splatMesh!==null&&(this.updateSplatMeshUniforms(r,e),this.updateView(!1,e))}getSplatMesh(){return this.splatMesh}};var SE=new Jr.MeshBasicMaterial;SE.wireframe=!0;var Y1=new Jr.Vector3,np=class extends Jr.Scene{constructor(e,t){super();this.data=e;this.sharedAssets=t;this.enableHelpers=!1;this.wireframeState=!1;this.needsTransmissionDirty=!0;this.needsNormalDirty=!0;this._needsTransmission=!1;this._needsNormal=!1;this.geometryCacheChanged=!1;this.splatViewer=null;this.shapeBlendIntances=[];this.entityByUuid={};this.entityIdentityToEntity={};this.toExpandCloner=new Set;this.toUpdateCloner=new Set;this.pendingCommands=[];this.pathConstraints=new ep;this.invisibleObjects=new tn("jflkdsafjasdifjaslk",{...Pu.defaultData,visible:!1,name:"buildin invisible"});this.needsRecomputeInstances=!1;this.init(e,t),this.matrixAutoUpdate=!1,this.errorPage=new Qr("fdasfa",{...ei.defaultData,name:""},{shared:t,scene:this})}markGeometryCacheDirty(){this.geometryCacheChanged=!0}markNeedsUpdateRendererDirty(){this.needsTransmissionDirty=!0,this.needsNormalDirty=!0}needsTransmission(){return this.needsTransmissionDirty&&(this._needsTransmission=U1(this),this.needsTransmissionDirty=!1),this._needsTransmission}needsNormal(){return this.needsNormalDirty&&(this._needsNormal=j1(this),this.needsNormalDirty=!1),this._needsNormal}registerInstanceAndSetUuid(e){let t=e.identity.join("-"),o=this.entityIdentityToEntity[t];o&&(e.uuid=o.uuid),this.entityIdentityToEntity[t]=e,this.entityByUuid[e.uuid]=e}markPenumbraSizeDirty(){for(let e of this.children)e instanceof Qr&&(e.penumbraSizeArrayCache=null)}findInstance(e){return this.entityIdentityToEntity[e.join("-")]}get bgColor(){return this.activePage.bgColor}get postprocessing(){return this.activePage.data.postprocessing}getWithSortKey(e){let t=this.find(e);if(t===void 0)return;let o=[],n=t;for(;n!==this;){let a=n;n=n.parent;let s=n.children.indexOf(a);o.splice(0,0,s)}return{entity:t,sortKey:o}}getAllSorted(e){let t=[];for(let o of e){let n=this.getWithSortKey(o.id);n!==void 0&&t.push(n)}return t.sort((o,n)=>Sc(o.sortKey,n.sortKey)),t.map(o=>o.entity)}nonExistOrDescendantOf(e,t){let o=this.find(e);if(o===void 0)return!0;for(;o;){if(o.uuid===t)return!0;o=o.parent}return!1}find(e){if(this.activePage&&this.activePage.personalCamera.parent){if(e==="f23858d0-4a3b-4bd8-8173-66ed0af7f6fb-personalCamera")return this.activePage.personalCamera;if(e===_i)return this.activePage.personalCamera}if(e===""||e===void 0)return;let t=this.entityByUuid[e];return t===void 0?this.getObjectByProperty("uuid",e):t}find2D(e){for(let t of this.children)if(t instanceof Qr&&t.uiScene){let o=t.uiScene.find(e);if(o)return o}}findScene2DfromObject2D(e){for(let t of this.children)if(t instanceof Qr&&t.uiScene&&t.uiScene.find(e))return t.uiScene}find2DInUIObjects(e){let t;return this.traverseEntity(o=>{t===void 0&&o instanceof Hn&&(t=o.uiCanvas.find(e))}),t}traverse2D(e){for(let t of this.children)t instanceof Qr&&t.uiScene&&t.uiScene.traverse(e)}debugEnsureEntity(e){let t=this.find(e);if(t){if(Array.isArray(t.identity)&&this.findInstance(t.identity)===void 0){console.error("not found instance");debugger}}else{console.error("not found");debugger}}addPendingExpandCloner(e){this.toExpandCloner.add(e)}addPendingUpdateCloner(e){this.toUpdateCloner.add(e)}markToExpandCloner(e){this.toExpandCloner.add(e),e.traverseEntityAncestors(t=>{this.toExpandCloner.add(t)})}doPendingExpandCloner(){this.toExpandCloner.forEach(e=>{e.expandCloner(this)}),this.toExpandCloner.clear()}doPendingUpdateCloner(){this.toUpdateCloner.forEach(e=>{e.cloner?.update()}),this.toUpdateCloner.clear()}doPendingUpdates(){this.doPendingExpandCloner(),this.doPendingUpdateCloner(),this.applyPendingCommands()}addPendingCommand(e){this.pendingCommands.push(e)}applyPendingCommands(){this.pendingCommands.forEach(e=>e()),this.pendingCommands.length=0}updateByLibOp(e,t){e.path.length===1&&e.path[0]==="components"&&e.type===1&&this.createChildrenObjects([{...e.data.asset,id:e.id}],this.invisibleObjects,t)}updateTreeByOp(e,t){if(e.path.length===0&&e.type===7){let o=e.parent===null?this:this.find(e.parent);if(o===void 0)throw new Error("unexpected");let n=this.createObject(e.id,e.data,e.children,o,e.localIndex,t);n.updateVisible(this),n.resetBBoxNeedsUpdate(),en(n)&&rc(n.parent)&&(n.invalidateUpstreamBooleanData(),n.parent.invalidateDownstreamBooleanData().recomputeBoolean()),this.markNeedsRecomputeInstancesForAncessors(o),this.markNeedsRecomputeInstancesForChildren(n),this.markToExpandCloner(n),this.markPenumbraSizeDirty(),n.updatePathSnapping()}else if(e.path.length===0&&e.type===8){let o=this.find(e.id);if(o===void 0)throw new Error("unexpected");o.traverseEntity(a=>{a instanceof sn&&(this.shapeBlendIntances=this.shapeBlendIntances.filter(s=>s!==a))}),this.markToExpandCloner(o),o.resetBBoxNeedsUpdate(),this.unregisterObject(o);let n=o.parent;this.markNeedsRecomputeInstancesForAncessors(n),this.markNeedsRecomputeInstancesForChildren(o),this.markPenumbraSizeDirty(),o.parent.remove(o),rc(o.parent)&&(o.parent.invalidateUpstreamBooleanData(),o.parent.invalidateDownstreamBooleanData().recomputeBoolean()),en(o)&&(o.freeBooleanPointer(),n instanceof Ar&&n.invalidateDownstreamBooleanData().recomputeBoolean()),o instanceof Hs&&o.detachShape(),this.disposeAndUnregisterEntityRecursivelyIfNotReregistered(o),this.pathConstraints.removeDependencies(o.uuid),o.updatePathSnapping()}else if(e.path.length===0&&e.type===9){let o=this.find(e.id);if(o===void 0)throw new Error("unexpected");this.markNeedsRecomputeInstancesForChildren(o);let n=o.parent;this.markNeedsRecomputeInstancesForAncessors(n),o.cloner?.resetOnMove(),this.markToExpandCloner(o);let a=e.parent===null?this:this.find(e.parent);if(a===void 0)throw new Error("unexpected");a.add(o),this.markNeedsRecomputeInstancesForAncessors(a),this.markToExpandCloner(o),o.invalidateClonerTransform(o),o.updateVisible(this),o.resetBBoxNeedsUpdate(),this.markPenumbraSizeDirty();let s=e.localIndex;a.children.splice(s,0,a.children.pop()),en(o)&&(o.invalidateUpstreamBooleanData(),rc(o.parent)?o.parent.invalidateDownstreamBooleanData().recomputeBoolean():n instanceof Ar&&n.invalidateDownstreamBooleanData().recomputeBoolean()),o.updatePathSnapping()}this.markNeedsUpdateRendererDirty(),this.markGeometryCacheDirty()}get playPage(){return this.find(this.data.publish.playPage)??this.errorPage}updatePage(e){this.activePage&&this.activePage.onDeactive(),this.activePage=this.errorPage;for(let t of this.children)t instanceof Qr&&(t.visible=t.uuid===e,t.visible&&(this.activePage=t,this.activePage.onActive(this)));this.activePage!==this.splatViewer?.activePage&&this.reloadSplats()}updateEntityByOp(e,t,o,n){if(t.type===0){if(("overrides"in t.props||"component"in t.props)&&this.markNeedsRecomputeInstances(),"visible"in t.props&&this.markPenumbraSizeDirty(),t.path.includes("overrides")&&"states"in t.props){let{rest:s}=t.props;t={...t,props:s},this.markNeedsRecomputeInstances()}t.path[0]==="pathSnapping"&&t.props.pathId!==void 0&&this.pathConstraints.setConstraint(e,t.props.pathId)}let a=this.find(e);if(a)try{L1(a,t,o,{scene:this,shared:n}),a instanceof ft&&a.updateGeometryGroupsIfNeeded()}catch(s){console.error(s)}}updateEntity2DByOp(e,t,o,n,a,s=[]){e.updateEntityByOp(t,o,n,a),this.traverseEntity(l=>{(l instanceof Hn||l instanceof Qr)&&(s.includes(l.frameId??"")||l.frameId===t)&&l.updateEntity2DByOp(t,o,n,a)})}get activeCamera(){return this.activePage.activeCamera}switchActiveCamera(e){this.activePage.switchActiveCamera(e)}isInvisibleObjects(e){return e===this.invisibleObjects||e.hasAnccestor(this.invisibleObjects)}init(e,t){let o=Object.entries(t.data.lib.components).map((n,a)=>({data:n[1].asset.data,children:n[1].asset.children,id:n[0],fi:a}));this.invisibleObjects.updateState(this.invisibleObjects.data,{scene:this,shared:t}),this.add(this.invisibleObjects),this.createChildrenObjects(o,this.invisibleObjects,t),this.createChildrenObjects(e.objects,this,t),this.updatePage(e.publish.playPage),this.activePage.switchToPlayCamera(),this.expandInstances(t,!0),this.traverseEntity(n=>{n instanceof yi&&n.updateUp()}),this.doPendingExpandCloner(),this.applyPendingCommands()}markNeedsRecomputeInstances(){this.needsRecomputeInstances=!0}markNeedsRecomputeInstancesForChildren(e){e.traverseEntity(t=>{(t.data.type==="Component"||t.data.type==="Instance")&&this.markNeedsRecomputeInstances()})}markNeedsRecomputeInstancesForAncessors(e){ze.is(e)&&(e.data.type==="Component"&&this.markNeedsRecomputeInstances(),e.traverseAncestors(t=>{ze.is(t)&&t.data.type==="Component"&&this.markNeedsRecomputeInstances()}))}relativeizeInner(e,t,o,n,a,s,l){if(e){let c=n.find(e);c&&c!==n&&a.forInstancesRec(u=>{u.data=Ai(u.data,p=>{let d=p.events.data(l.id),f=u.goUp(s);if(f){let h=[...vc(f.identity),e].join("-"),m=this.entityIdentityToEntity[h];if(m){let y=m.uuid,b=ut.zoom(d,t);b[o]=y}else{if(!1)debugger;console.warn("cannot find instance")}}}).data})}}rewriteActions(e,t,o,n,a,s){e.forEach(l=>{l.data.type==="Transition"?this.relativeizeInner(l.data.object,[...t,l.id],"object",o,n,a,s):l.data.type==="Animation"?this.relativeizeInner(l.data.object,[...t,l.id],"object",o,n,a,s):l.data.type==="Conditional"&&(this.rewriteActions(l.data.ifActions,[...t,l.id,"ifActions"],o,n,a,s),this.rewriteActions(l.data.elseActions,[...t,l.id,"elseActions"],o,n,a,s))})}rewriteEventsBeforeGoToPlayMode(){this.traverseEntity(e=>{if(e instanceof bi&&typeof e.identity=="string"&&e.data.type==="Component")return e.traverseEntity((t,o)=>{t.data.events.forEach(n=>{if(n.data.type==="GameControl"){let a=!1;if(t.forInstancesRec(s=>{s.data=Ai(s.data,l=>{s.isInstanceRoot||(l.events.delete(n.id),a=!0)}).data}),a===!1)for(let s of Au.list)this.rewriteActions(n.data.gameActions[s],["gameActions",s],e,t,o,n)}else n.data.type==="Conditional"?(n.data.condition.type==="Distance"?(this.relativeizeInner(n.data.condition.fromObject,["condition"],"fromObject",e,t,o,n),this.relativeizeInner(n.data.condition.toObject,["condition"],"toObject",e,t,o,n)):n.data.condition.type==="State"?this.relativeizeInner(n.data.condition.object,["condition"],"object",e,t,o,n):n.data.condition.type==="Comparison"&&(n.data.condition.lOperand.type==="Property"&&this.relativeizeInner(n.data.condition.lOperand.value[0],["condition","lOperand","value"],0,e,t,o,n),n.data.condition.rOperand.type==="Property"&&this.relativeizeInner(n.data.condition.rOperand.value[0],["condition","rOperand","value"],0,e,t,o,n)),this.rewriteActions(n.data.inActions,["inActions"],e,t,o,n),this.rewriteActions(n.data.outActions,["outActions"],e,t,o,n)):"actions"in n.data&&this.rewriteActions(n.data.actions,["actions"],e,t,o,n)})}),!0})}expandInstances(e,t,o){let n=new Set;this.traverseEntity(a=>{if(a instanceof bi&&a.isInstanceRoot)return a.expandInstanceChildren({scene:this,shared:e,pendingDeletes:n}),t||a.resetBBoxNeedsUpdate(),o&&a.traverseEntity(s=>{o.addClip(s)}),!0});for(let a of n)this.disposeAndUnregisterEntityRecursivelyIfNotReregistered(a),$d(a)}recomputeInstances(e,t){this.needsRecomputeInstances&&(this.needsRecomputeInstances=!1,this.traverseEntity(o=>{o instanceof bi&&o.isInstanceRoot&&(o.component=void 0)}),this.expandInstances(e,!1,t))}disposeAndUnregisterEntityRecursivelyIfNotReregistered(e){e.traverseEntity(t=>{let o=typeof t.identity=="string"?t.identity:t.identity.join("-");this.entityIdentityToEntity[o]===t&&(delete this.entityByUuid[t.uuid],delete this.entityIdentityToEntity[o]),t.dispose()})}clearScene(){for(let e of this.children)ze.is(e)&&e.disposeRecursively();this.children.length=0}resetAfterClear(e,t){this.init(e,t)}raycast(e){return this.raycast1(e,!1)}raycast1(e,t){let o=[],n=a=>{for(let s of a.children){let l=s.cloner;if(ze.is(s)&&!s.raycastLock&&(s.visible||l?.object.data.visible))if(t===!0&&s.isInstanceRoot){let c=[];if(e.intersectObject(s,!0,c),c.length){let u=c[0];u.object=s,u.point.applyMatrix4(u.object.matrixWorld);let p=s.matrixWorld.clone().invert();u.point.applyMatrix4(p),o.push(u)}}else(en(s)||oc(s)&&this.enableHelpers&&s.objectHelper.visible)&&(e.intersectObject(s,!1,o),uc(s,e,o)),n(s)}};return n(this.activePage),o}raycastWithClones(e){let t=[],o=n=>{for(let a of n.children){let s=a.cloner;ze.is(a)&&(a.visible||s?.object.data.visible)&&((en(a)||oc(a)&&this.enableHelpers&&a.objectHelper.visible)&&(e.intersectObject(a,!1,t),uc(a,e,t,!0)),o(a))}};return o(this),t}forEachEntity(e){for(let t of this.children)ze.is(t)&&e(t)}traverseConcreteEntity(e){for(let t of this.children)ze.is(t)&&t.isConcreteEntity&&t.traverseEntity(e)}traverseEntity(e){for(let t of this.children)ze.is(t)&&t.traverseEntity(e)}updateFont(e,t){this.traverseEntity(o=>{if(o instanceof ft&&o.data.type==="Mesh"&&(o.data.geometry.type==="TextGeometry"||o.data.geometry.type==="InputGeometry")&&o.data.geometry.font===e){let n=o.geometry,a=o.data.geometry;n.updateFont(e,t).then(()=>{n.update(a);let s=o.invalidateDownstreamBooleanData();rc(s)&&s.recomputeBoolean()})}})}traverseObject(e){for(let t of this.children)ai.is(t)&&t.traverseObject(e)}traverseVisibleEntity(e){for(let t of this.children)ze.is(t)&&t.visible&&t.traverseVisibleEntity(e)}dispose(){this.clearScene()}createChildrenObjects(e,t,o){let n=0;for(let a of e)this.createObject(a.id,a.data,a.children,t,n,o),n+=1}registerObjectCreatedInLegacy(e){this.entityByUuid[e.uuid]=e}unregisterObject(e){delete this.entityByUuid[e.uuid];for(let t of e.children)this.unregisterObject(t)}createObject(e,t,o,n,a,s){let l={scene:this,shared:s},c=Qd(e,t,l);return c instanceof sn&&this.shapeBlendIntances.push(c),c&&(this.entityByUuid[e]=c,n.add(c),n.children.splice(a,0,n.children.pop()),o.length>0&&(c.isInstanceRoot?console.error("instance should not have children!"):this.createChildrenObjects(o,c,s)),c.updateState(t,l),c instanceof ft&&c.updateGeometryGroupsIfNeeded(),c.updateVisible(this),c.cloner&&this.toExpandCloner.add(c),t.pathSnapping?.pathId&&this.pathConstraints.setConstraint(e,t.pathSnapping.pathId)),t.type==="Empty"&&t.animations&&c.traverseEntity(u=>{let p=u.dataPatched;if(u instanceof ft&&p.bones&&p.boneInverses){let d=p.bones.map(m=>this.find(m)),f=p.boneInverses.map(m=>new Jr.Matrix4().fromArray(m)),h=new Jr.Skeleton(d,f);u.bind(h,u.bindMatrix)}else u.matrixAutoUpdate=!0}),c}getCenter(e){let t=[];for(let n=0,a=e.length;n<a;++n){let{id:s,recursive:l}=e[n],c=this.find(s),u=l?c.recursiveBBox:c.singleBBox;t.push(...u.vertices)}let o=new Jr.Box3;return o.setFromPoints(t),o.getCenter(Y1),Y1}copyMatrixWorld(e,t){if(e===null){t.identity();return}let o=this.find(e);o?t.copy(o.matrixWorld):t.identity()}copyParentMatrixWorld(e,t){if(e===null){t.identity();return}let o=this.find(e)?.parent;o?t.copy(o.matrixWorld):t.identity()}traverseMaterial(e){this.traverseEntity(t=>{if(t instanceof Ut)if(Array.isArray(t.material))for(let o=0;o<t.material.length;o++)t.material[o]instanceof Tr&&e(t.material[o]);else t.material instanceof Tr&&e(t.material)})}updateViewPlaneSize(e,t,o=!1){this.traverseConcreteEntity(n=>{n instanceof yi&&n.setViewplaneSize(e,t,o)})}initializeSplatViewer(){this.splatViewer=new pc({scene:this}),this.reloadSplats()}reloadSplats(){this.splatViewer?.loadSplat()}};var K1=require("three/examples/jsm/loaders/DRACOLoader.js");var dn;function Q1(){return dn||(dn=new K1.DRACOLoader,dn.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.5.2/").preload()),dn.decoderPending}async function wE(i){if(dn){let r={attributeIDs:dn.defaultAttributeIDs,attributeTypes:dn.defaultAttributeTypes,useUniqueIDs:!1},e;try{e=await dn.decodeGeometry(new Int8Array(i).buffer,r)}catch(t){console.error(t)}if(e)return{index:e.index?{array:e.index.array}:void 0,attributes:Object.entries(e.attributes).map(([t,o])=>({name:t,itemSize:o.itemSize,array:o.array}))}}return null}async function Z1(i,r){let[e,t]=Np(uu.deserialize(new Uint8Array(i)));return Iu(e),r&&r(e),t.result().data}function J1(i){let r=[];return i.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&t.geometry.type==="NonParametricGeometry"&&t.geometry.data.draco!==void 0&&r.push(t)}),r}async function eS(i){for(let r of i){let e=await wE(r.geometry.data.draco);if(e){let t=r.geometry.data;e.index&&(t.index={array:e.index.array,itemSize:1,normalized:!1,type:"Uint32Array"});let o={};e.attributes.forEach(({name:n,array:a,itemSize:s})=>{o[n]={array:a,itemSize:s,type:"Float32Array",normalized:!1}}),t.attributes=o,t.draco=void 0}}}var PE=require("three"),OE=require("three/examples/jsm/utils/BufferGeometryUtils.js");function tS(i){let r;if(!!i.index)for(let e=0;e<i.index.array.length;e+=3)r=i.index.array[e],i.index.array[e]=i.index.array[e+2],i.index.array[e+2]=r}var fc=require("three");function rS(i){let r=new Set;return i.traverse(e=>{if(e instanceof Cr)if(Tt(e.material))e.material.forEach(t=>{let o=t;r.has(o)||r.add(o)});else{let t=e.material;r.has(t)||r.add(t)}}),r.forEach(e=>{if(e instanceof Array)return;let t=e.onBeforeCompile.bind(e);if(TE(e)){Object.assign(e,{isMeshStandardMaterial:!0,isMeshPhysicalMaterial:!0,transmission:1,attenuationColor:new fc.Color,specularColor:new fc.Color});let o=0;e.onBeforeCompile=(n,a)=>{t&&t(n,a),n.uniforms=Object.assign({},fc.ShaderLib.physical.uniforms,n.uniforms),e.getLayersOfType("transmission").forEach(s=>{if(n.uniforms.transmissionSamplerMap.value){let l=s.color;l&&(l.transmissionSamplerMap.value=n.uniforms.transmissionSamplerMap.value,l.transmissionSamplerSize.value=n.uniforms.transmissionSamplerSize.value,l.aspectRatio.value=Bb(window.innerWidth,window.innerHeight),e.defines.IS_THREEJS_EXPORT=!0)}else o++,o<2&&(e.needsUpdate=!0)})}}else CE(e)||(e.onBeforeCompile=(o,n)=>{t&&t(o,n),e.transparent=!1})}),i}function TE(i){return i.getLayersOfType("transmission").length>0}function CE(i){let r=0;for(let e of i.layers){if(e.data.type!=="displace"&&e.data.isMask)return!0;if(e.type!=="light"&&e.type!=="fresnel"){let o=e.uniforms["f"+e.id+"_alpha"];o&&(r+=(1-r)*o.value)}}return r<1}function oS(i){return i.traverse(r=>{if(r.type==="Camera"){let e=r;e.type=e.cameraType}}),i}function iS(i){let r=[],e=(t,o=0)=>{let n=o>0?t+o:t;return r.includes(n)?e(t,o+1):n};return i.traverse(t=>{if(r.includes(t.name)){let o=t.name,n=e(t.name);if(t.name=n,t.isMesh){let a=t;a.material instanceof Array?a.material.forEach(s=>{s.name=s.name.replace(o,n)}):a.material.isAsset||(a.material.name=a.material.name.replace(o,n))}}r.push(t.name)}),i}var nS=require("three/examples/jsm/utils/BufferGeometryUtils.js");function aS(i){let r=[];return i.traverse(e=>{e instanceof Zi&&r.push(e)}),r.forEach(e=>{let t=e.object,a=[...e.children.map(s=>{s.updateMatrix();let l;if(s.geometry!==void 0)try{l=s.geometry.clone().applyMatrix4(s.matrix)}catch(c){console.error(c)}return l!==void 0&&s.matrix.determinant()<0&&tS(l),l}).filter(s=>s!==void 0)];if(!e.parameters.hideBase&&t instanceof Ut&&a.unshift(t.geometry),a.length){let s=(0,nS.mergeBufferGeometries)(a);t instanceof Ut&&(t.geometry=s)}e.removeFromParent(),t.setFromClonerState(null,{scene:i,shared:tv})}),i}function sS(i){return i.traverse(r=>{r.matrixAutoUpdate=!0}),i}function lS(i){Object.values(i.shared.materials).forEach(r=>{Qh(r)}),i.scene.objects.traverse((r,e)=>{"material"in e?Qh(e.material):"materials"in e&&e.materials.forEach(t=>{Qh(t)})})}function Qh(i){if(typeof i=="string")return;let r=[];i.layers.forEach((e,t)=>{e.type==="outline"&&r.push(t)}),r.reverse().forEach(e=>{i.layers.delete(e)}),r.length&&console.warn("The Spline Loader currently does not support the outline layer.")}var pS=tl(uS(),1);var dS="The SplineLoader only accepts .splinecode files that are generated from Spline export panel.",ap=class extends sp.Loader{load(r,e,t,o=console.error){let n=new sp.FileLoader(this.manager);n.setPath(this.path),n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),r.endsWith(".spline")?console.warn(dS+" The .spline files are only meant to be used by the Editor."):r.endsWith(".splinecode")||console.warn(dS),n.load(r,async a=>{try{if(typeof a=="string")throw new Error("The .spline file is not binary!");let s=await this.parse(a);e(s)}catch(s){o(s)}},t,o)}async parse(r){let e=await Z1(r,lS),t=J1(e);e.version&&(0,pS.default)(e.version,"1.10.2")>0&&console.warn("Your .splinecode file is more recent than the library. Please upgrade @splinetool/loader to the latest version."),await Promise.allSettled([t.length&&Q1(),av(e)&&cb(),yv(e)&&Xb(),Kv(e)&&$v(),op(e)&&Kh()].filter(Boolean)),t.length&&await eS(t);let o=!1,n=new Gn(e.shared,{},o);Object.values(n.getMaterials()).forEach(l=>Object.assign(l,{isAsset:!0}));let a=new np(e.scene,n);op(e)&&a.initializeSplatViewer();let s=a.activeCamera;return s&&Object.assign(s,{makeDefault:!0}),a=aS(a),a=rS(a),a=oS(a),a=iS(a),a=sS(a),a}};
|
|
4379
|
+
}`,n={covariancesTexture:{type:"t",value:null},centersColorsTexture:{type:"t",value:null},meshIndexIntervals:{value:e},meshMatrixWorldsTexture:{type:"t",value:null},focal:{type:"v2",value:new Te.Vector2},viewport:{type:"v2",value:new Te.Vector2},basisViewport:{type:"v2",value:new Te.Vector2},debugColor:{type:"v3",value:new Te.Color},covariancesTextureSize:{type:"v2",value:new Te.Vector2(1024,1024)},centersColorsTextureSize:{type:"v2",value:new Te.Vector2(1024,1024)},orthoZoom:{type:"f",value:-1}};return new Te.ShaderMaterial({uniforms:n,vertexShader:t,fragmentShader:o,transparent:!0,alphaTest:1,blending:Te.NormalBlending,depthTest:!0,depthWrite:!1,side:Te.DoubleSide})}static buildGeomtery(e){let t=new Te.BufferGeometry;t.setIndex([0,1,2,0,2,3]);let o=new Float32Array(4*3),n=new Te.BufferAttribute(o,3);t.setAttribute("position",n),n.setXYZ(0,-1,-1,0),n.setXYZ(1,-1,1,0),n.setXYZ(2,1,1,0),n.setXYZ(3,1,-1,0),n.needsUpdate=!0;let a=new Te.InstancedBufferGeometry().copy(t),s=new Uint32Array(e),l=new Te.InstancedBufferAttribute(s,1,!1);return l.setUsage(Te.DynamicDrawUsage),a.setAttribute("splatIndex",l),a.instanceCount=e,a}resetLocalSplatDataAndTexturesFromSplatBuffer(){this.updateLocalSplatDataFromSplatBuffer(),this.allocateAndStoreLocalSplatDataInTextures()}updateLocalSplatDataFromSplatBuffer(){this.splatBuffers.forEach(n=>n.buildPreComputedBuffers()),this.covariances=new Float32Array(this.splatCount*6),this.colors=new Uint8Array(this.splatCount*4),this.centers=new Float32Array(this.splatCount*3);let e=0,t=0,o=0;for(let n of this.splatBuffers){let a=n.nsplats;this.colors.subarray(e,e+a*4).set(n.colorsA),e+=a*4,this.centers.subarray(t,t+a*3).set(n.decoded.xyz.denormDequant().data),t+=a*3,this.covariances.subarray(o,o+a*6).set(new Float32Array(n.precomputedCovarianceBufferData)),o+=a*6}}allocateAndStoreLocalSplatDataInTextures(){let o=this.splatCount,n=new Te.Vector2(4096,1024);for(;n.x*n.y*2<o*6;)n.y*=2;let a=new Te.Vector2(4096,1024);for(;a.x*a.y*4<o*4;)a.y*=2;let s,l;if(this.halfPrecisionCovariancesOnGPU){l=new Uint16Array(n.x*n.y*2);for(let h=0;h<this.covariances.length;h++)l[h]=Te.DataUtils.toHalfFloat(this.covariances[h]);s=new Te.DataTexture(l,n.x,n.y,Te.RGFormat,Te.HalfFloatType)}else l=new Float32Array(n.x*n.y*2),l.set(this.covariances),s=new Te.DataTexture(l,n.x,n.y,Te.RGFormat,Te.FloatType);s.needsUpdate=!0,this.material.uniforms.covariancesTexture.value=s,this.material.uniforms.covariancesTextureSize.value.copy(n);let c=new Uint32Array(a.x*a.y*4);for(let h=0;h<o;h++){let m=h*4,y=h*3,b=h*4;c[b]=W1(this.colors[m],this.colors[m+1],this.colors[m+2],this.colors[m+3]),c[b+1]=tp(this.centers[y]),c[b+2]=tp(this.centers[y+1]),c[b+3]=tp(this.centers[y+2])}let u=new Te.DataTexture(c,a.x,a.y,Te.RGBAIntegerFormat,Te.UnsignedIntType);u.internalFormat="RGBA32UI",u.needsUpdate=!0,this.material.uniforms.centersColorsTexture.value=u,this.material.uniforms.centersColorsTextureSize.value.copy(a);let p=256*4,d=new Float32Array(256*16);for(let h=0;h<this.meshMatrixWorlds.length;h++)d.set(this.meshMatrixWorlds[h].elements,h*16);let f=new Te.DataTexture(d,p,1,Te.RGBAFormat,Te.FloatType);f.needsUpdate=!0,this.material.uniforms.meshMatrixWorldsTexture.value=f,this.material.uniformsNeedUpdate=!0,this.splatDataTextures={covariances:{data:l,texture:s,size:n},centerColors:{data:c,texture:u,size:a},meshMatrixWorlds:{data:d,texture:f}}}updateIndexes(e){let t=this.geometry;t.attributes.splatIndex.set(e),t.attributes.splatIndex.needsUpdate=!0,t.instanceCount=e.length}updateUniforms(e,t,o,n){this.splatCount>0&&(rp.set(e.x*this.devicePixelRatio,e.y*this.devicePixelRatio),this.material.uniforms.viewport.value.copy(rp),this.material.uniforms.basisViewport.value.set(2/rp.x,2/rp.y),this.material.uniforms.focal.value.set(t,o),this.material.uniforms.orthoZoom.value=n,this.material.uniformsNeedUpdate=!0)}getSplatDataTextures(){return this.splatDataTextures}getSplatCount(){return this.splatCount}getCenters(){return this.centers}getColors(){return this.colors}getCovariances(){return this.covariances}dispose(){this.geometry.dispose(),this.material.dispose(),this.splatDataTextures&&(this.splatDataTextures.covariances.texture.dispose(),this.splatDataTextures.centerColors.texture.dispose(),this.splatDataTextures.meshMatrixWorlds.texture.dispose()),this.removeFromParent()}};var $1,Yh=new Promise(i=>{$1=i}),q1=!1;var ip;function Kh(){if(q1)return;if(ip)return ip;async function i(){let e=await import("./gaussian-splat-compression.js");$1(e),q1=!0}return ip=i(),ip}var X1;Yh.then(i=>X1=i);var pc=class{constructor(r={}){yn(this,"updateView",function(){let r=new xr.Matrix4,e=[],t=new xr.Vector3(0,0,-1),o=new xr.Vector3(0,0,-1),n=new xr.Vector3,a=new xr.Vector3;return function(s=!1,l){let c=this.updateMatrixWorldsInWorkerIfNeeded(),u=this.cropsChanged();if(!s){o.set(0,0,-1).applyQuaternion(l.quaternion);let d=!1,f=!1;if(o.dot(t)<=.95&&(d=!0),a.copy(l.position).sub(n).length()>=1&&(f=!0),!d&&!f&&!c&&!u&&!this.needsInitialRender)return}this.needsInitialRender=!1,n.copy(l.position),t.copy(o),r.copy(l.matrixWorld).invert(),r.premultiply(this.dummyPerspectiveMatrix),e[0]=l.position.x,e[1]=l.position.y,e[2]=l.position.z;let p={sort:{view:r.elements,cameraPosition:e,splatRenderCount:this.splatRenderCount,splatSortCount:this.splatRenderCount},...c?{newMatrixWorlds:this.meshMatrixWorlds}:{},...u?{newCropsArray:this.cropsArray}:{}};this.sortRunning?this.queuedMessage=p:(this.queuedMessage=null,this.sortRunning=!0,this.sortWorker.postMessage(p))}}());this.scene=r.scene,this.currentPage=null,this.devicePixelRatio=window.devicePixelRatio,this.sortWorker=null,this.splatRenderCount=0,this.splatSortCount=0,this.splatMesh=null,this.sortRunning=!1,this.meshMatrixWorlds=null,this.meshMatrixWorldsOld=null,this.cropsArray=null,this.splatEntries=null,this.queuedMessage=null,this.needsInitialRender=!0,this.dummyPerspectiveMatrix=new xr.Matrix4().makePerspective(-1,1,-1,1,.1,1e3)}updateSplatMeshUniforms(r,e){let t=new xr.Vector2;if(this.splatMesh===null)return;this.splatMesh.getSplatCount()>0&&(r.getSize(t),this.cameraFocalLengthX=e.projectionMatrix.elements[0]*this.devicePixelRatio*t.x*.45,this.cameraFocalLengthY=e.projectionMatrix.elements[5]*this.devicePixelRatio*t.y*.45,this.splatMesh.updateUniforms(t,this.cameraFocalLengthX,this.cameraFocalLengthY,e.isPerspectiveCamera?-1:e.zoom*this.devicePixelRatio))}loadSplat(r={}){this.activePage=this.scene.activePage,r.position&&(r.position=new xr.Vector3().fromArray(r.position)),r.orientation&&(r.orientation=new xr.Quaternion().fromArray(r.orientation)),r.halfPrecisionCovariances=!!r.halfPrecisionCovariances;let e=[];if(this.splatEntries=e,this.activePage.traverseVisibleEntity(a=>{a.data.type==="Splat"&&e.push(a)}),this.splatMesh&&this.splatMesh.dispose(),e.length===0)return this.splatMesh=null,!1;this.meshMatrixWorlds=e.map(a=>a.matrixWorld),this.meshMatrixWorldsOld=e.map(a=>a.matrixWorld.clone()),this.cropsArray=e.map(a=>a.data.crops.map(s=>s.data));let t=e.map(a=>new X1.GSplineBuffer(new Uint8Array(a.data.buffer).buffer)),o=0,n=[0];for(let a of t)o+=a.getSplatCount(),n.push(o);return this.setupSplatMesh(t,o,r.position,r.orientation,r.halfPrecisionCovariances,this.devicePixelRatio,n,this.meshMatrixWorlds),this.setupSortWorker(o),!0}updateMatrixWorldsInWorkerIfNeeded(){let r=this.splatDataTextures.meshMatrixWorlds.data;for(let e=0;e<this.meshMatrixWorlds.length;e++)r.set(this.meshMatrixWorlds[e].elements,e*16);return this.splatDataTextures.meshMatrixWorlds.texture.needsUpdate=!0,this.meshMatrixWorlds.every((e,t)=>e.equals(this.meshMatrixWorldsOld[t]))?!1:(this.meshMatrixWorldsOld=this.meshMatrixWorlds.map(e=>e.clone()),!0)}cropsChanged(){let r=!1;return this.splatEntries.forEach((e,t)=>{e.data.crops.forEach((o,n)=>{this.cropsArray[t][n]===void 0?(r=!0,this.cropsArray[t][n]=o.data):Object.entries(o.data).forEach(([a,s])=>{Array.isArray(s)&&s.some((l,c)=>l!==this.cropsArray[t][n][a][c])?(r=!0,this.cropsArray[t][n][a]=s):s!==this.cropsArray[t][n]?.[a]&&(r=!0,this.cropsArray[t][n][a]=s)})}),e.data.crops.length!==this.cropsArray[t]?.length&&(this.cropsArray[t].length=e.data.crops.length,r=!0)}),r}setupSplatMesh(r,e,t=new xr.Vector3,o=new xr.Quaternion,n=!1,a=1,s,l){this.splatMesh=un.buildMesh(r,e,n,a,s,l),this.splatMesh.position.copy(t),this.splatMesh.quaternion.copy(o),this.splatMesh.frustumCulled=!1,this.splatMesh.renderOrder=99999,this.splatRenderCount=e,this.splatMesh.onBeforeRender=(c,u,p)=>this.update(c,p)}setupSortWorker(r){this.sortWorker=H1(r),this.sortWorker.onmessage=e=>{e.data.sortDone?(this.sortRunning=!1,this.splatMesh?.updateIndexes(new Uint32Array(e.data.indexesBuffer)),this.lastSortTime=e.data.sortTime,this.queuedMessage&&(this.sortWorker.postMessage(this.queuedMessage),this.queuedMessage=null)):e.data.sortCanceled?this.sortRunning=!1:e.data.sortSetupPhase1Complete?this.sortWorker.postMessage({positions:this.splatMesh.getCenters().buffer,meshMatrixWorlds:this.splatMesh.meshMatrixWorlds,meshIndexIntervals:this.splatMesh.meshIndexIntervals,cropsArray:this.cropsArray}):e.data.sortSetupComplete&&(this.splatDataTextures=this.splatMesh.getSplatDataTextures(),this.scene.activePage.add(this.splatMesh),this.needsInitialRender=!0)}}update(r,e){this.splatMesh!==null&&(this.updateSplatMeshUniforms(r,e),this.updateView(!1,e))}getSplatMesh(){return this.splatMesh}};var SE=new Jr.MeshBasicMaterial;SE.wireframe=!0;var Y1=new Jr.Vector3,np=class extends Jr.Scene{constructor(e,t){super();this.data=e;this.sharedAssets=t;this.enableHelpers=!1;this.wireframeState=!1;this.needsTransmissionDirty=!0;this.needsNormalDirty=!0;this._needsTransmission=!1;this._needsNormal=!1;this.geometryCacheChanged=!1;this.splatViewer=null;this.shapeBlendIntances=[];this.entityByUuid={};this.entityIdentityToEntity={};this.toExpandCloner=new Set;this.toUpdateCloner=new Set;this.pendingCommands=[];this.pathConstraints=new ep;this.invisibleObjects=new tn("jflkdsafjasdifjaslk",{...Pu.defaultData,visible:!1,name:"buildin invisible"});this.needsRecomputeInstances=!1;this.init(e,t),this.matrixAutoUpdate=!1,this.errorPage=new Qr("fdasfa",{...ei.defaultData,name:""},{shared:t,scene:this})}markGeometryCacheDirty(){this.geometryCacheChanged=!0}markNeedsUpdateRendererDirty(){this.needsTransmissionDirty=!0,this.needsNormalDirty=!0}needsTransmission(){return this.needsTransmissionDirty&&(this._needsTransmission=U1(this),this.needsTransmissionDirty=!1),this._needsTransmission}needsNormal(){return this.needsNormalDirty&&(this._needsNormal=j1(this),this.needsNormalDirty=!1),this._needsNormal}registerInstanceAndSetUuid(e){let t=e.identity.join("-"),o=this.entityIdentityToEntity[t];o&&(e.uuid=o.uuid),this.entityIdentityToEntity[t]=e,this.entityByUuid[e.uuid]=e}markPenumbraSizeDirty(){for(let e of this.children)e instanceof Qr&&(e.penumbraSizeArrayCache=null)}findInstance(e){return this.entityIdentityToEntity[e.join("-")]}get bgColor(){return this.activePage.bgColor}get postprocessing(){return this.activePage.data.postprocessing}getWithSortKey(e){let t=this.find(e);if(t===void 0)return;let o=[],n=t;for(;n!==this;){let a=n;n=n.parent;let s=n.children.indexOf(a);o.splice(0,0,s)}return{entity:t,sortKey:o}}getAllSorted(e){let t=[];for(let o of e){let n=this.getWithSortKey(o.id);n!==void 0&&t.push(n)}return t.sort((o,n)=>Sc(o.sortKey,n.sortKey)),t.map(o=>o.entity)}nonExistOrDescendantOf(e,t){let o=this.find(e);if(o===void 0)return!0;for(;o;){if(o.uuid===t)return!0;o=o.parent}return!1}find(e){if(this.activePage&&this.activePage.personalCamera.parent){if(e==="f23858d0-4a3b-4bd8-8173-66ed0af7f6fb-personalCamera")return this.activePage.personalCamera;if(e===_i)return this.activePage.personalCamera}if(e===""||e===void 0)return;let t=this.entityByUuid[e];return t===void 0?this.getObjectByProperty("uuid",e):t}find2D(e){for(let t of this.children)if(t instanceof Qr&&t.uiScene){let o=t.uiScene.find(e);if(o)return o}}findScene2DfromObject2D(e){for(let t of this.children)if(t instanceof Qr&&t.uiScene&&t.uiScene.find(e))return t.uiScene}find2DInUIObjects(e){let t;return this.traverseEntity(o=>{t===void 0&&o instanceof Hn&&(t=o.uiCanvas.find(e))}),t}traverse2D(e){for(let t of this.children)t instanceof Qr&&t.uiScene&&t.uiScene.traverse(e)}debugEnsureEntity(e){let t=this.find(e);if(t){if(Array.isArray(t.identity)&&this.findInstance(t.identity)===void 0){console.error("not found instance");debugger}}else{console.error("not found");debugger}}addPendingExpandCloner(e){this.toExpandCloner.add(e)}addPendingUpdateCloner(e){this.toUpdateCloner.add(e)}markToExpandCloner(e){this.toExpandCloner.add(e),e.traverseEntityAncestors(t=>{this.toExpandCloner.add(t)})}doPendingExpandCloner(){this.toExpandCloner.forEach(e=>{e.expandCloner(this)}),this.toExpandCloner.clear()}doPendingUpdateCloner(){this.toUpdateCloner.forEach(e=>{e.cloner?.update()}),this.toUpdateCloner.clear()}doPendingUpdates(){this.doPendingExpandCloner(),this.doPendingUpdateCloner(),this.applyPendingCommands()}addPendingCommand(e){this.pendingCommands.push(e)}applyPendingCommands(){this.pendingCommands.forEach(e=>e()),this.pendingCommands.length=0}updateByLibOp(e,t){e.path.length===1&&e.path[0]==="components"&&e.type===1&&this.createChildrenObjects([{...e.data.asset,id:e.id}],this.invisibleObjects,t)}updateTreeByOp(e,t){if(e.path.length===0&&e.type===7){let o=e.parent===null?this:this.find(e.parent);if(o===void 0)throw new Error("unexpected");let n=this.createObject(e.id,e.data,e.children,o,e.localIndex,t);n.updateVisible(this),n.resetBBoxNeedsUpdate(),en(n)&&rc(n.parent)&&(n.invalidateUpstreamBooleanData(),n.parent.invalidateDownstreamBooleanData().recomputeBoolean()),this.markNeedsRecomputeInstancesForAncessors(o),this.markNeedsRecomputeInstancesForChildren(n),this.markToExpandCloner(n),this.markPenumbraSizeDirty(),n.updatePathSnapping()}else if(e.path.length===0&&e.type===8){let o=this.find(e.id);if(o===void 0)throw new Error("unexpected");o.traverseEntity(a=>{a instanceof sn&&(this.shapeBlendIntances=this.shapeBlendIntances.filter(s=>s!==a))}),this.markToExpandCloner(o),o.resetBBoxNeedsUpdate(),this.unregisterObject(o);let n=o.parent;this.markNeedsRecomputeInstancesForAncessors(n),this.markNeedsRecomputeInstancesForChildren(o),this.markPenumbraSizeDirty(),o.parent.remove(o),rc(o.parent)&&(o.parent.invalidateUpstreamBooleanData(),o.parent.invalidateDownstreamBooleanData().recomputeBoolean()),en(o)&&(o.freeBooleanPointer(),n instanceof Ar&&n.invalidateDownstreamBooleanData().recomputeBoolean()),o instanceof Hs&&o.detachShape(),this.disposeAndUnregisterEntityRecursivelyIfNotReregistered(o),this.pathConstraints.removeDependencies(o.uuid),o.updatePathSnapping()}else if(e.path.length===0&&e.type===9){let o=this.find(e.id);if(o===void 0)throw new Error("unexpected");this.markNeedsRecomputeInstancesForChildren(o);let n=o.parent;this.markNeedsRecomputeInstancesForAncessors(n),o.cloner?.resetOnMove(),this.markToExpandCloner(o);let a=e.parent===null?this:this.find(e.parent);if(a===void 0)throw new Error("unexpected");a.add(o),this.markNeedsRecomputeInstancesForAncessors(a),this.markToExpandCloner(o),o.invalidateClonerTransform(o),o.updateVisible(this),o.resetBBoxNeedsUpdate(),this.markPenumbraSizeDirty();let s=e.localIndex;a.children.splice(s,0,a.children.pop()),en(o)&&(o.invalidateUpstreamBooleanData(),rc(o.parent)?o.parent.invalidateDownstreamBooleanData().recomputeBoolean():n instanceof Ar&&n.invalidateDownstreamBooleanData().recomputeBoolean()),o.updatePathSnapping()}this.markNeedsUpdateRendererDirty(),this.markGeometryCacheDirty()}get playPage(){return this.find(this.data.publish.playPage)??this.errorPage}updatePage(e){this.activePage&&this.activePage.onDeactive(),this.activePage=this.errorPage;for(let t of this.children)t instanceof Qr&&(t.visible=t.uuid===e,t.visible&&(this.activePage=t,this.activePage.onActive(this)));this.activePage!==this.splatViewer?.activePage&&this.reloadSplats()}updateEntityByOp(e,t,o,n){if(t.type===0){if(("overrides"in t.props||"component"in t.props)&&this.markNeedsRecomputeInstances(),"visible"in t.props&&this.markPenumbraSizeDirty(),t.path.includes("overrides")&&"states"in t.props){let{rest:s}=t.props;t={...t,props:s},this.markNeedsRecomputeInstances()}t.path[0]==="pathSnapping"&&t.props.pathId!==void 0&&this.pathConstraints.setConstraint(e,t.props.pathId)}let a=this.find(e);if(a)try{L1(a,t,o,{scene:this,shared:n}),a instanceof ft&&a.updateGeometryGroupsIfNeeded()}catch(s){console.error(s)}}updateEntity2DByOp(e,t,o,n,a,s=[]){e.updateEntityByOp(t,o,n,a),this.traverseEntity(l=>{(l instanceof Hn||l instanceof Qr)&&(s.includes(l.frameId??"")||l.frameId===t)&&l.updateEntity2DByOp(t,o,n,a)})}get activeCamera(){return this.activePage.activeCamera}switchActiveCamera(e){this.activePage.switchActiveCamera(e)}isInvisibleObjects(e){return e===this.invisibleObjects||e.hasAnccestor(this.invisibleObjects)}init(e,t){let o=Object.entries(t.data.lib.components).map((n,a)=>({data:n[1].asset.data,children:n[1].asset.children,id:n[0],fi:a}));this.invisibleObjects.updateState(this.invisibleObjects.data,{scene:this,shared:t}),this.add(this.invisibleObjects),this.createChildrenObjects(o,this.invisibleObjects,t),this.createChildrenObjects(e.objects,this,t),this.updatePage(e.publish.playPage),this.activePage.switchToPlayCamera(),this.expandInstances(t,!0),this.traverseEntity(n=>{n instanceof yi&&n.updateUp()}),this.doPendingExpandCloner(),this.applyPendingCommands()}markNeedsRecomputeInstances(){this.needsRecomputeInstances=!0}markNeedsRecomputeInstancesForChildren(e){e.traverseEntity(t=>{(t.data.type==="Component"||t.data.type==="Instance")&&this.markNeedsRecomputeInstances()})}markNeedsRecomputeInstancesForAncessors(e){ze.is(e)&&(e.data.type==="Component"&&this.markNeedsRecomputeInstances(),e.traverseAncestors(t=>{ze.is(t)&&t.data.type==="Component"&&this.markNeedsRecomputeInstances()}))}relativeizeInner(e,t,o,n,a,s,l){if(e){let c=n.find(e);c&&c!==n&&a.forInstancesRec(u=>{u.data=Ai(u.data,p=>{let d=p.events.data(l.id),f=u.goUp(s);if(f){let h=[...vc(f.identity),e].join("-"),m=this.entityIdentityToEntity[h];if(m){let y=m.uuid,b=ut.zoom(d,t);b[o]=y}else{if(!1)debugger;console.warn("cannot find instance")}}}).data})}}rewriteActions(e,t,o,n,a,s){e.forEach(l=>{l.data.type==="Transition"?this.relativeizeInner(l.data.object,[...t,l.id],"object",o,n,a,s):l.data.type==="Animation"?this.relativeizeInner(l.data.object,[...t,l.id],"object",o,n,a,s):l.data.type==="Conditional"&&(this.rewriteActions(l.data.ifActions,[...t,l.id,"ifActions"],o,n,a,s),this.rewriteActions(l.data.elseActions,[...t,l.id,"elseActions"],o,n,a,s))})}rewriteEventsBeforeGoToPlayMode(){this.traverseEntity(e=>{if(e instanceof bi&&typeof e.identity=="string"&&e.data.type==="Component")return e.traverseEntity((t,o)=>{t.data.events.forEach(n=>{if(n.data.type==="GameControl"){let a=!1;if(t.forInstancesRec(s=>{s.data=Ai(s.data,l=>{s.isInstanceRoot||(l.events.delete(n.id),a=!0)}).data}),a===!1)for(let s of Au.list)this.rewriteActions(n.data.gameActions[s],["gameActions",s],e,t,o,n)}else n.data.type==="Conditional"?(n.data.condition.type==="Distance"?(this.relativeizeInner(n.data.condition.fromObject,["condition"],"fromObject",e,t,o,n),this.relativeizeInner(n.data.condition.toObject,["condition"],"toObject",e,t,o,n)):n.data.condition.type==="State"?this.relativeizeInner(n.data.condition.object,["condition"],"object",e,t,o,n):n.data.condition.type==="Comparison"&&(n.data.condition.lOperand.type==="Property"&&this.relativeizeInner(n.data.condition.lOperand.value[0],["condition","lOperand","value"],0,e,t,o,n),n.data.condition.rOperand.type==="Property"&&this.relativeizeInner(n.data.condition.rOperand.value[0],["condition","rOperand","value"],0,e,t,o,n)),this.rewriteActions(n.data.inActions,["inActions"],e,t,o,n),this.rewriteActions(n.data.outActions,["outActions"],e,t,o,n)):"actions"in n.data&&this.rewriteActions(n.data.actions,["actions"],e,t,o,n)})}),!0})}expandInstances(e,t,o){let n=new Set;this.traverseEntity(a=>{if(a instanceof bi&&a.isInstanceRoot)return a.expandInstanceChildren({scene:this,shared:e,pendingDeletes:n}),t||a.resetBBoxNeedsUpdate(),o&&a.traverseEntity(s=>{o.addClip(s)}),!0});for(let a of n)this.disposeAndUnregisterEntityRecursivelyIfNotReregistered(a),$d(a)}recomputeInstances(e,t){this.needsRecomputeInstances&&(this.needsRecomputeInstances=!1,this.traverseEntity(o=>{o instanceof bi&&o.isInstanceRoot&&(o.component=void 0)}),this.expandInstances(e,!1,t))}disposeAndUnregisterEntityRecursivelyIfNotReregistered(e){e.traverseEntity(t=>{let o=typeof t.identity=="string"?t.identity:t.identity.join("-");this.entityIdentityToEntity[o]===t&&(delete this.entityByUuid[t.uuid],delete this.entityIdentityToEntity[o]),t.dispose()})}clearScene(){for(let e of this.children)ze.is(e)&&e.disposeRecursively();this.children.length=0}resetAfterClear(e,t){this.init(e,t)}raycast(e){return this.raycast1(e,!1)}raycast1(e,t){let o=[],n=a=>{for(let s of a.children){let l=s.cloner;if(ze.is(s)&&!s.raycastLock&&(s.visible||l?.object.data.visible))if(t===!0&&s.isInstanceRoot){let c=[];if(e.intersectObject(s,!0,c),c.length){let u=c[0];u.object=s,u.point.applyMatrix4(u.object.matrixWorld);let p=s.matrixWorld.clone().invert();u.point.applyMatrix4(p),o.push(u)}}else(en(s)||oc(s)&&this.enableHelpers&&s.objectHelper.visible)&&(e.intersectObject(s,!1,o),uc(s,e,o)),n(s)}};return n(this.activePage),o}raycastWithClones(e){let t=[],o=n=>{for(let a of n.children){let s=a.cloner;ze.is(a)&&(a.visible||s?.object.data.visible)&&((en(a)||oc(a)&&this.enableHelpers&&a.objectHelper.visible)&&(e.intersectObject(a,!1,t),uc(a,e,t,!0)),o(a))}};return o(this),t}forEachEntity(e){for(let t of this.children)ze.is(t)&&e(t)}traverseConcreteEntity(e){for(let t of this.children)ze.is(t)&&t.isConcreteEntity&&t.traverseEntity(e)}traverseEntity(e){for(let t of this.children)ze.is(t)&&t.traverseEntity(e)}updateFont(e,t){this.traverseEntity(o=>{if(o instanceof ft&&o.data.type==="Mesh"&&(o.data.geometry.type==="TextGeometry"||o.data.geometry.type==="InputGeometry")&&o.data.geometry.font===e){let n=o.geometry,a=o.data.geometry;n.updateFont(e,t).then(()=>{n.update(a);let s=o.invalidateDownstreamBooleanData();rc(s)&&s.recomputeBoolean()})}})}traverseObject(e){for(let t of this.children)ai.is(t)&&t.traverseObject(e)}traverseVisibleEntity(e){for(let t of this.children)ze.is(t)&&t.visible&&t.traverseVisibleEntity(e)}dispose(){this.clearScene()}createChildrenObjects(e,t,o){let n=0;for(let a of e)this.createObject(a.id,a.data,a.children,t,n,o),n+=1}registerObjectCreatedInLegacy(e){this.entityByUuid[e.uuid]=e}unregisterObject(e){delete this.entityByUuid[e.uuid];for(let t of e.children)this.unregisterObject(t)}createObject(e,t,o,n,a,s){let l={scene:this,shared:s},c=Qd(e,t,l);return c instanceof sn&&this.shapeBlendIntances.push(c),c&&(this.entityByUuid[e]=c,n.add(c),n.children.splice(a,0,n.children.pop()),o.length>0&&(c.isInstanceRoot?console.error("instance should not have children!"):this.createChildrenObjects(o,c,s)),c.updateState(t,l),c instanceof ft&&c.updateGeometryGroupsIfNeeded(),c.updateVisible(this),c.cloner&&this.toExpandCloner.add(c),t.pathSnapping?.pathId&&this.pathConstraints.setConstraint(e,t.pathSnapping.pathId)),t.type==="Empty"&&t.animations&&c.traverseEntity(u=>{let p=u.dataPatched;if(u instanceof ft&&p.bones&&p.boneInverses){let d=p.bones.map(m=>this.find(m)),f=p.boneInverses.map(m=>new Jr.Matrix4().fromArray(m)),h=new Jr.Skeleton(d,f);u.bind(h,u.bindMatrix)}else u.matrixAutoUpdate=!0}),c}getCenter(e){let t=[];for(let n=0,a=e.length;n<a;++n){let{id:s,recursive:l}=e[n],c=this.find(s),u=l?c.recursiveBBox:c.singleBBox;t.push(...u.vertices)}let o=new Jr.Box3;return o.setFromPoints(t),o.getCenter(Y1),Y1}copyMatrixWorld(e,t){if(e===null){t.identity();return}let o=this.find(e);o?t.copy(o.matrixWorld):t.identity()}copyParentMatrixWorld(e,t){if(e===null){t.identity();return}let o=this.find(e)?.parent;o?t.copy(o.matrixWorld):t.identity()}traverseMaterial(e){this.traverseEntity(t=>{if(t instanceof Ut)if(Array.isArray(t.material))for(let o=0;o<t.material.length;o++)t.material[o]instanceof Tr&&e(t.material[o]);else t.material instanceof Tr&&e(t.material)})}updateViewPlaneSize(e,t,o=!1){this.traverseConcreteEntity(n=>{n instanceof yi&&n.setViewplaneSize(e,t,o)})}initializeSplatViewer(){this.splatViewer=new pc({scene:this}),this.reloadSplats()}reloadSplats(){this.splatViewer?.loadSplat()}};var K1=require("three/examples/jsm/loaders/DRACOLoader.js");var dn;function Q1(){return dn||(dn=new K1.DRACOLoader,dn.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.5.2/").preload()),dn.decoderPending}async function wE(i){if(dn){let r={attributeIDs:dn.defaultAttributeIDs,attributeTypes:dn.defaultAttributeTypes,useUniqueIDs:!1},e;try{e=await dn.decodeGeometry(new Int8Array(i).buffer,r)}catch(t){console.error(t)}if(e)return{index:e.index?{array:e.index.array}:void 0,attributes:Object.entries(e.attributes).map(([t,o])=>({name:t,itemSize:o.itemSize,array:o.array}))}}return null}async function Z1(i,r){let[e,t]=Np(uu.deserialize(new Uint8Array(i)));return Iu(e),r&&r(e),t.result().data}function J1(i){let r=[];return i.scene.objects.traverse((e,t)=>{t.type==="Mesh"&&t.geometry.type==="NonParametricGeometry"&&t.geometry.data.draco!==void 0&&r.push(t)}),r}async function eS(i){for(let r of i){let e=await wE(r.geometry.data.draco);if(e){let t=r.geometry.data;e.index&&(t.index={array:e.index.array,itemSize:1,normalized:!1,type:"Uint32Array"});let o={};e.attributes.forEach(({name:n,array:a,itemSize:s})=>{o[n]={array:a,itemSize:s,type:"Float32Array",normalized:!1}}),t.attributes=o,t.draco=void 0}}}var PE=require("three"),OE=require("three/examples/jsm/utils/BufferGeometryUtils.js");function tS(i){let r;if(!!i.index)for(let e=0;e<i.index.array.length;e+=3)r=i.index.array[e],i.index.array[e]=i.index.array[e+2],i.index.array[e+2]=r}var fc=require("three");function rS(i){let r=new Set;return i.traverse(e=>{if(e instanceof Cr)if(Tt(e.material))e.material.forEach(t=>{let o=t;r.has(o)||r.add(o)});else{let t=e.material;r.has(t)||r.add(t)}}),r.forEach(e=>{if(e instanceof Array)return;let t=e.onBeforeCompile.bind(e);if(TE(e)){Object.assign(e,{isMeshStandardMaterial:!0,isMeshPhysicalMaterial:!0,transmission:1,attenuationColor:new fc.Color,specularColor:new fc.Color});let o=0;e.onBeforeCompile=(n,a)=>{t&&t(n,a),n.uniforms=Object.assign({},fc.ShaderLib.physical.uniforms,n.uniforms),e.getLayersOfType("transmission").forEach(s=>{if(n.uniforms.transmissionSamplerMap.value){let l=s.color;l&&(l.transmissionSamplerMap.value=n.uniforms.transmissionSamplerMap.value,l.transmissionSamplerSize.value=n.uniforms.transmissionSamplerSize.value,l.aspectRatio.value=Bb(window.innerWidth,window.innerHeight),e.defines.IS_THREEJS_EXPORT=!0)}else o++,o<2&&(e.needsUpdate=!0)})}}else CE(e)||(e.onBeforeCompile=(o,n)=>{t&&t(o,n),e.transparent=!1})}),i}function TE(i){return i.getLayersOfType("transmission").length>0}function CE(i){let r=0;for(let e of i.layers){if(e.data.type!=="displace"&&e.data.isMask)return!0;if(e.type!=="light"&&e.type!=="fresnel"){let o=e.uniforms["f"+e.id+"_alpha"];o&&(r+=(1-r)*o.value)}}return r<1}function oS(i){return i.traverse(r=>{if(r.type==="Camera"){let e=r;e.type=e.cameraType}}),i}function iS(i){let r=[],e=(t,o=0)=>{let n=o>0?t+o:t;return r.includes(n)?e(t,o+1):n};return i.traverse(t=>{if(r.includes(t.name)){let o=t.name,n=e(t.name);if(t.name=n,t.isMesh){let a=t;a.material instanceof Array?a.material.forEach(s=>{s.name=s.name.replace(o,n)}):a.material.isAsset||(a.material.name=a.material.name.replace(o,n))}}r.push(t.name)}),i}var nS=require("three/examples/jsm/utils/BufferGeometryUtils.js");function aS(i){let r=[];return i.traverse(e=>{e instanceof Zi&&r.push(e)}),r.forEach(e=>{let t=e.object,a=[...e.children.map(s=>{s.updateMatrix();let l;if(s.geometry!==void 0)try{l=s.geometry.clone().applyMatrix4(s.matrix)}catch(c){console.error(c)}return l!==void 0&&s.matrix.determinant()<0&&tS(l),l}).filter(s=>s!==void 0)];if(!e.parameters.hideBase&&t instanceof Ut&&a.unshift(t.geometry),a.length){let s=(0,nS.mergeBufferGeometries)(a);t instanceof Ut&&(t.geometry=s)}e.removeFromParent(),t.setFromClonerState(null,{scene:i,shared:tv})}),i}function sS(i){return i.traverse(r=>{r.matrixAutoUpdate=!0}),i}function lS(i){Object.values(i.shared.materials).forEach(r=>{Qh(r)}),i.scene.objects.traverse((r,e)=>{"material"in e?Qh(e.material):"materials"in e&&e.materials.forEach(t=>{Qh(t)})})}function Qh(i){if(typeof i=="string")return;let r=[];i.layers.forEach((e,t)=>{e.type==="outline"&&r.push(t)}),r.reverse().forEach(e=>{i.layers.delete(e)}),r.length&&console.warn("The Spline Loader currently does not support the outline layer.")}var pS=tl(uS(),1);var dS="The SplineLoader only accepts .splinecode files that are generated from Spline export panel.",ap=class extends sp.Loader{load(r,e,t,o=console.error){let n=new sp.FileLoader(this.manager);n.setPath(this.path),n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),r.endsWith(".spline")?console.warn(dS+" The .spline files are only meant to be used by the Editor."):r.endsWith(".splinecode")||console.warn(dS),n.load(r,async a=>{try{if(typeof a=="string")throw new Error("The .spline file is not binary!");let s=await this.parse(a);e(s)}catch(s){o(s)}},t,o)}async parse(r){let e=await Z1(r,lS),t=J1(e);e.version&&(0,pS.default)(e.version,"1.10.3")>0&&console.warn("Your .splinecode file is more recent than the library. Please upgrade @splinetool/loader to the latest version."),await Promise.allSettled([t.length&&Q1(),av(e)&&cb(),yv(e)&&Xb(),Kv(e)&&$v(),op(e)&&Kh()].filter(Boolean)),t.length&&await eS(t);let o=!1,n=new Gn(e.shared,{},o);Object.values(n.getMaterials()).forEach(l=>Object.assign(l,{isAsset:!0}));let a=new np(e.scene,n);op(e)&&a.initializeSplatViewer();let s=a.activeCamera;return s&&Object.assign(s,{makeDefault:!0}),a=aS(a),a=rS(a),a=oS(a),a=iS(a),a=sS(a),a}};
|