@splinetool/loader 1.12.41 → 1.12.42

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.
@@ -15,7 +15,7 @@ best distance: ${p.d}`);let g=[p.x,p.y];return g.distance=p.d,g.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=Fl(JSON.parse(i.body),t)),u!==void 0&&(o+=`&data=${encodeURIComponent(u.replace(/(\r\n|\n|\r|\t)/gm,""))}`)}else i.integration?.type==="OpenAI"?r=a:i.method==="POST"&&i.body&&(r=Fl(JSON.parse(i.body),t));let s=await fetch(o,{method:n?"GET":i.method,headers:n?void 0:PI(i),signal:e.signal,body:r});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 gb=(i,t)=>{if(typeof i=="string"){let e=t.getVariable(i);if(e)return gb(e,t)}return Ui.isBoolean(i)?Ui.getDisplayedValue(i).toLowerCase():Ui.getDisplayedValue(i)},Fl=(i,t)=>i.map((e,r)=>{if("text"in e)return e.text;if("type"in e){if(e.type==="paragraph")return(r>0?`
16
16
  `:"")+Fl(e.children,t);if(e.type==="variable"){let o=t.getVariable(e.variableId);if(o!==void 0)return gb(o,t)}}return""}).join("");var MI=new Ee.Matrix4,II=new Ee.Matrix4;function EI(i,t,e){let r=[new Ee.Vector3,new Ee.Vector3,new Ee.Vector3],o=[new Ee.Vector3,new Ee.Vector3,new Ee.Vector3];return i.extractBasis(r[0],r[1],r[2]),t.extractBasis(o[0],o[1],o[2]),r.forEach((n,a)=>{let s=o[a],l=Ee.MathUtils.lerp(n.length(),s.length(),e);n.lerp(s,e).setLength(l)}),new Ee.Matrix4().makeBasis(r[0],r[1],r[2])}var xb=class{static create(i){return this.build(this.normalizeInputs(i))}static normalizeInputs(i,t){let e=Object.assign({},t?.parameters??{width:100,height:100,depth:1,subdivisions:12,roundness:0,extrudeBevelSize:0,extrudeBevelSegments:3},i.parameters),r=Math.abs(e.width),o=Math.abs(e.height??e.width),n=Math.abs(e.depth??0),a=t?.shapeData??ts.create({parameters:{...In,width:typeof In.width=="number"?In.width:100,height:typeof In.height=="number"?In.height:100}}).userData.shape;return{path:i.path??Ba.defaultData(),parameters:Object.assign(e,{width:r,height:o,depth:n,extrusion:{...Cu,...e.extrusion}}),shapeData:a}}static build(i){if(i.path.points.length>=2){let e=new Kf(i);return Object.assign(e,{userData:{...i,type:"PathGeometry"}})}else return Object.assign(new Ee.BufferGeometry,{userData:{...i,type:"PathGeometry"}})}},Kf=class extends Ee.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)||!mb(e.twist,0)||e.startScale!==e.endScale}build(){let e=this._extractPathPoints();if(e.length<2)return;let r=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=[],d=[];for(let j=0;j<c;j++){let F=this.inputs.path.isClosed?(j+s)%e.length:Math.min(j+s,e.length-1);u.push(e[F].clone()),d.push(r[F].clone())}let p=(j,F,H)=>{u[j]=u[j].clone().lerp(u[F],H),d[j]=EI(d[j],d[F],H)},f=0,h=n*a%1;(!this.inputs.path.isClosed||o<=1)&&(h||n===0)&&(f=h,p(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,p(u.length-1,u.length-2,1-m)),o===0){let j=u.length-1;u[j].copy(u[0]),d[j].copy(d[0])}this._applyPathModifiers(d,f,m);let{bevel:g,bevelSides:b}=this.inputs.parameters.extrusion,w=g>0?this.inputs.parameters.extrusion.capType:"flat",P=5;this.inputs.parameters.extrusion.shape.type==="Custom"&&(P=this.inputs.parameters.extrusion.shape.shapeQuality==="low"?5:12);let{regions:S,infos:T,vertices:A}=this._computeShapePoints(P),x=0,N;w==="round"&&(N=new $i(this.inputs.shapeData,2*g,g,P,b,void 0,!0),x=N.getAttribute("position").count);let E=0,M=0;T.sort((j,F)=>j.start-F.start),T.forEach(j=>{j.verticesStart=E,j.verticesCount=j.continuous.reduce((F,H,W)=>F+(W===0||!H?2:1),0),M+=j.verticesCount,E=M});let D=M*c,_,R=0;if(this._isOpenEnded()&&w==="flat"){try{_=fo({windingRule:Xe.ODD,elementType:Pt.POLYGONS,polySize:3,vertexSize:2,strict:!0,contours:S})}catch{_=jf}R=_.vertexCount}let V=D+2*R+x*2,U=D+2*R,B={positions:new Float32Array(V*3),normals:new Float32Array(V*3),uvs:new Float32Array(V*2)},q=[];if(T.forEach(j=>{this._extrudeRegion(j,A,d,u,B,q,this._isGeometryClosed()&&!this._isOpenEnded())}),_&&(this._closeEnd(_,D,q,B,d[0],u[0],!1),this._closeEnd(_,D+R,q,B,d[d.length-1],u[u.length-1],!0)),N){B.positions.set(N.getAttribute("position").array,U*3),B.normals.set(N.getAttribute("normal").array,U*3),B.uvs.set(N.getAttribute("uv").array,U*2);for(let W=U;W<U+x;W++)B.uvs[W*2+1]=1e-4;let j=q.length;q.push(...N.getIndex().array.map(W=>W+U)),U+=x,B.positions.set(N.getAttribute("position").array,U*3),B.normals.set(N.getAttribute("normal").array,U*3),B.uvs.set(N.getAttribute("uv").array,U*2);let F=q.length;q.push(...N.getIndex().array.map(W=>W+U)),this.setAttribute("position",new Ee.BufferAttribute(B.positions,3)),this.setAttribute("normal",new Ee.BufferAttribute(B.normals,3)),this.setAttribute("uv",new Ee.BufferAttribute(B.uvs,2)),this.setIndex(q);let H=MI;H.copy(d[d.length-1]).setPosition(u[u.length-1]),this.applyMatrix4OnRange(H,U,V),H.copy(d[0]).setPosition(u[0]).multiply(II.makeScale(1,1,-1)),this.applyMatrix4OnRange(H,U-x,U),this.reverseIndicesOnRange(j,F)}else this.setAttribute("position",new Ee.BufferAttribute(B.positions,3)),this.setAttribute("normal",new Ee.BufferAttribute(B.normals,3)),this.setAttribute("uv",new Ee.BufferAttribute(B.uvs,2)),this.setIndex(q)}_extractPathPoints(){let e=qu(this.inputs.path),r=this.inputs.path.subdivisions,o=this.inputs.path.subdivisionMode==="uniform"?e.getSpacedPoints(r*4):e.getPoints(r);if(o.length<2)return[];let n=[o[0]];return o.forEach(s=>{n[n.length-1].distanceToSquared(s)>.001&&n.push(s)}),this.inputs.path.isClosed&&n[n.length-1].distanceTo(n[0])<.001&&n.pop(),n}_computeBasisMatrices(e){let r=[],o=e.length,n=this.inputs.path.isClosed,a=new Ee.Vector3,s=new Ee.Vector3,l=new Ee.Vector3,c=new Ee.Vector3,u=new Ee.Vector3(0,1,0);for(let y=0;y<o;y++){let g=e[y],b;y===0?b=n?e[e.length-2]:g.clone().multiplyScalar(2).sub(e[1]):b=e[y-1];let w;y===o-1?w=n?e[1]:g.clone().multiplyScalar(2).sub(e[y-1]):w=e[y+1];let P=g.clone().sub(b).normalize(),S=w.clone().sub(g).normalize(),T=P.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(),x=T.clone().cross(A).normalize();u.copy(x),c.copy(A),y===0&&(a.copy(x),s.copy(T));let N=new Ee.Matrix4().makeBasis(A,x,T);r.push(N)}let d=n?s:l,p=n?a:new Ee.Vector3(0,1,0),f=d.clone().cross(c).normalize(),h=Math.acos(p.dot(f));if(isNaN(h))return r;let m=p.clone().cross(f);d.dot(m)>0&&(h*=-1);for(let y=1;y<r.length;y++){let g=new Ee.Matrix4().makeRotationZ(h*y/r.length);r[y].multiply(g)}return r}_applyPathModifiers(e,r,o){let n=e.length,{angle:a,twist:s,startScale:l,endScale:c}=this.inputs.parameters.extrusion,u=new Ee.Matrix4,d=new Ee.Matrix4;return e.forEach((p,f)=>{let h=f===0?0:f===n-1?1:(f-r)/(n-(o===0?0:1)-(r+(1-o)));u.makeRotationZ(Ee.MathUtils.lerp(a,a+s,h)*Ee.MathUtils.DEG2RAD);let m=Ee.MathUtils.lerp(l,c,h);d.makeScale(m,m,m),p.multiply(u).multiply(d)}),e}_computeShapePoints(e=12,r=Xe.ODD){let o=this.inputs.shapeData,n=o.extractShapePointsToFlatArray([],e),a=o.shapeHoles.map(m=>{let y=m.extractShapePointsToFlatArray([],e),g=[];for(let b=y.length-1;b>=1;b-=2){let w=y[b-1],P=y[b-0];g.push(w,P)}return g}),s;try{s=fo({windingRule:r,elementType:Pt.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[n]})}catch{s=Bl}let l;try{l=fo({windingRule:Xe.ODD,elementType:Pt.BOUNDARY_CONTOURS,vertexSize:2,strict:!0,contours:[...a]})}catch{l=Ff}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],g=m%2===0?s.vertexCount:0;s.elements.push(y+g)}for(let m=0;m<l.vertexIndices.length;m++){let y=l.vertexIndices[m],g=s.vertexCount;s.vertexIndices.push(y+g)}for(let m=0;m<l.vertices.length;m++){let y=l.vertices[m];s.vertices.push(y)}}let u=1/0,d=-1/0,p=1/0,f=-1/0;for(let m=0,y=s.vertexCount;m<y;m++){let g=m*2,b=s.vertices[g+0],w=s.vertices[g+1];b<u&&(u=b),b>d&&(d=b),w<p&&(p=w),w>f&&(f=w)}let h=[];for(let m=s.elementCount-1;m>=0;m--){let y=m>=c,g=m*2,b=s.elements[g+0],w=s.elements[g+1],P=b+w,S={start:b,count:w,normals:[],isHole:y,continuous:[],verticesStart:0,verticesCount:0};h.push(S);let T=b,A=P-1,x=b+1,N=o.roundedCurves.length;do{let E=T-b,M=s.vertices[A*2+0],D=s.vertices[A*2+1],_=s.vertices[T*2+0],R=s.vertices[T*2+1],V=s.vertices[x*2+0],U=s.vertices[x*2+1],B=_-M,q=R-D,j=Math.sqrt(B*B+q*q);B/=j,q/=j;let F=_-V,H=R-U,W=Math.sqrt(F*F+H*H);F/=W,H/=W,S.normals[E*2+0]=-H,S.normals[E*2+1]=F;let ee=s.vertexIndices[T];if(Array.isArray(ee))S.continuous[E]=!1;else{let[te,Y]=o.getCurveIndexFromVertexId(ee-1,!0);if(Y>0&&Y<1)S.continuous[E]=!0;else{let re=Y===1?te+1:te-1;re=(re+N)%N;let K=Y===1?0:1,Z=o.roundedCurves[te].getTangent(Y),Q=o.roundedCurves[re].getTangent(K);S.continuous[E]=Z.dot(Q)>.95}}y&&(S.normals[E*2+0]*=-1,S.normals[E*2+1]*=-1),[A,T,x]=[T,x,x+1],x>=P&&(x-=w)}while(x!==b+1)}return{regions:[n,...a],infos:h,vertices:s.vertices}}_insertVertex(e,r,o,n,a){let s=r*2,l=r*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,r,o,n,a,s,l){let c=new Ee.Vector3,u=new Ee.Vector3,d=new Ee.Vector3,p=new Ee.Vector3,f=new Ee.Vector2;o.forEach((m,y)=>{let g=n[y],b=e.verticesStart*o.length+e.verticesCount*y;for(let w=0;w<e.count;w++){let P=(e.start+w)*2;if(c.set(r[P+0],r[P+1],0),d.copy(c).applyMatrix4(m).add(g),e.continuous[w])p.set(e.normals[w*2+0],e.normals[w*2+1],0);else{let S=w===0?(e.start+e.count-1)*2:P-2;u.set(r[S+0],r[S+1],0),p.copy(c).sub(u),p.set(-p.y,p.x,0),e.isHole||p.negate()}if(p.applyMatrix4(m).normalize(),f.set(w===0?1:w/e.count,y/(o.length-1)),this._insertVertex(a,b,d,p,f),b++,!e.continuous[w]||w===0){if(w===0)p.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:P+2;u.set(r[S+0],r[S+1],0),p.copy(u).sub(c),p.set(-p.y,p.x,0),e.isHole||p.negate()}p.applyMatrix4(m).normalize(),this._insertVertex(a,b,d,p,f),b++}}});let h=o.length-1;for(let m=0;m<h;m++){let y=e.verticesStart*o.length+e.verticesCount*m,g=e.verticesStart*o.length+e.verticesCount*(m+1),b=0;for(let w=0;w<e.count;w++){(!e.continuous[w]||w===0)&&b++;let P=w===e.count-1?0:b+1,S=y+b,T=y+P,A=g+P,x=g+b;e.isHole?s.push(S,A,T,S,x,A):s.push(S,T,A,S,A,x),b++}}}_closeEnd(e,r,o,n,a,s,l){let c=e.vertexCount,u=new Ee.Vector3(0,0,l?-1:1).applyMatrix4(a),d=new Ee.Vector3,p=new Ee.Vector2;for(let h=0;h<c;h++){let m=2*h;d.set(e.vertices[m+0],e.vertices[m+1],0).applyMatrix4(a).add(s),this._insertVertex(n,r+h,d,u,p)}let f=e.elements;for(let h=0;h<e.elementCount;h++){let m=3*h,y=f[m+0]+r,g=f[m+(l?1:2)]+r,b=f[m+(l?2:1)]+r;o.push(y,g,b)}}applyMatrix4OnRange(e,r,o){let n=e.elements,a=new Ee.Matrix3().getNormalMatrix(e).elements,s,l,c,u,d=this.attributes.position,p=this.attributes.normal;if(!d||!p)return;let f=d.array,h=p.array,m=d.itemSize;for(let y=r*m,g=o*m;y<g;y+=m){if(y===r)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}d.needsUpdate=!0,p.needsUpdate=!0}reverseIndicesOnRange(e,r){let o=this.index;if(o){for(let n=e;n<r;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 Bn=require("three"),bb=require("three/examples/jsm/utils/BufferGeometryUtils.js");function vb(){let i=new Bn.BufferGeometry;return i.setAttribute("position",new Bn.BufferAttribute(new Float32Array([]),3)),i.setIndex(new Bn.BufferAttribute(new Uint16Array([]),1)),i}var DI=vb().attributes,_I=12,RI=1,Vn=class extends Bn.BufferGeometry{constructor(e,r){super();this.charWidths=[];this.charCoords=[];this.wrappedText=[];this.isLowResolution=!1;this.vectorShapes=[];Object.assign(this.attributes,DI),this.userData={parameters:e,type:"TextGeometry"};let o=r.getFont(e.font);o?.isLoaded?(this.font=o,this.update(e,r)):this.updateFont(e.font,r).then(()=>{this.update(e,r),r?.requestRender()})}async updateFont(e,r){let o=r.getFont(e);o&&(this.font=o,await o.loadingPromise)}update(e,r){let o=this.font;if(this.userData={parameters:e,type:"TextGeometry"},!o?.isLoaded){console.warn("Cannot update text because its font is not loaded");return}let{width:n,height:a,depth:s,extrudeBevelSize:l,extrudeBevelSegments:c,text:u,textTransform:d}=e,p=Ui.getDisplayedValue(u),f=d===2?p.toUpperCase():d===3?p.toLowerCase():p,h=LI(e,o,f,r),{shapes:m,charWidths:y,charCoords:g}=o.generateShapes(h,e,r),b=(typeof n=="number"?n:Number(r.getVariable(n)))*.5,w=(typeof a=="number"?a:Number(r.getVariable(a)))*.5,P=m.map(A=>new Ye().fromShape(A,!0));this.vectorShapes=P;let S=P.map(A=>Tr.create({shape:A,parameters:{depth:s,extrudeBevelSegments:c,extrudeBevelSize:l,windingRule:s<=0?Xe.NONZERO:Xe.ODD,subdivisions:this.isLowResolution&&s>0?RI:_I}})),T=S.length?(0,bb.mergeBufferGeometries)(S):vb();T.translate(-b,w,0),this.dispose(),this.wrappedText=h,this.charCoords=g,this.charWidths=y,this.deleteAttribute("extrudeNormal"),Object.entries(T.attributes).forEach(([A,x])=>{this.setAttribute(A,x)}),this.setIndex(T.index),this.computeBoundingSphere()}clone(){let e=Ht(new Bn.BufferGeometry,Vn.prototype);return e.copy(this),console.log("CloneGeometry",this,e),e}copy(e){return Object.entries(e.attributes).forEach(([r,o])=>{this.setAttribute(r,o)}),this.setIndex(e.index),this.userData={parameters:{...e.userData.parameters},type:"TextGeometry"},this}async setText(e,r){this.font&&await this.font.loadingPromise,await this.update({...this.userData.parameters,text:{textValue:e}},r)}get text(){return this.userData.parameters.text??""}};function LI(i,t,e,r){let o=typeof i.width=="string"?Number(r.getVariable(i.width)):i.width,n=[""],a="";for(let s of e)a+=s,s===" "||s===`
17
17
  `?(n[n.length-1]+=a,a="",s===`
18
- `&&n.push("")):t.getTextWidth(n[n.length-1]+a,i)>o&&(n[n.length-1].length&&n.push(""),t.getTextWidth(n[n.length-1]+a,i)>o&&(a.length===1?(n[n.length-1]+=a,a=""):(n[n.length-1]+=a.slice(0,-1),a=a[a.length-1],n.push(""))));return n[n.length-1]+=a,n}var lt=require("three");var wb,ld=new Promise(i=>{wb=i}),Sb=!1;var sd;function Pb(i){if(Sb)return;if(sd)return sd;async function t(){let r=i??(!1?".":"https://unpkg.com/@splinetool/modelling-wasm@1.12.41/build"),n=import("./process.js"),[a,s]=await Promise.all([n,fetch(`${r}/process.wasm`).then(u=>u.arrayBuffer())]),l=a.default,c=await l({wasmBinary:s});wb(c),Sb=!0}return sd=t(),sd}var Ob=require("three");var BI=["font"];function zo(i,t,e,r){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 d of c)u=u[d];for(o in u){let d=u[o];tf(d)&&!BI.includes(o)&&(u[o]=t.getVariable(d,[r.uuid,"geometry",...c,o]),tf(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=Ye.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 Ob.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 zt(n,e);return c.data=i,c}else{if(n.type==="TextGeometry")return new Vn(n,t);if(n.type==="InputGeometry")return new Vn(n,t);if(n.type==="UIGeometry")return is.create({parameters:{width:n.width,height:n.height,cornerRadius:n.cornerRadius,cornerType:n.cornerType}})}let l;try{l=Qf(s)}catch(c){console.error(c),console.error(`Error generating geometry with inputs: ${s}`);let u=Ye.createFromState(La.defaultData(),100,100);s.shape=u,s.type="VectorGeometry",l=Qf(s)}return l}var Tb=require("three"),VI=new Tb.Matrix4;function jl(i,t,e,r){let o=i.position.array,n=i.normal.array,a=VI.makeScale(t,e,r).invert().elements,s,l,c;for(var u=0,d=o.length;u<d;u+=3)o[u]*=t,o[u+1]*=e,o[u+2]*=r,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 cd=new lt.Box3,as=new lt.Vector3,Oe;ld.then(i=>{Oe=i});var Cb=new Float32Array([10,10,0,-10,10,0,-10,-10,0,10,-10,0]),Ab=new Uint32Array([0,1,2,3]),Mb=new Uint8Array([4]),zt=class extends lt.BufferGeometry{constructor(e,r){super();this.data=e;this.flatShading=r;this.subdivPointer=0;this.rebuild(),this.freeSubdivPointer()}mutateDirectlyScaleBaked(e,r){this.freeSubdivPointer();let o=this.data.scaleBaked.map(l=>typeof l=="number"?l:1),n=Bi.div(r.map(l=>typeof l=="number"?l:0),o);if(n.every(l=>l===1))return;this.subdividedGeometry&&jl(this.subdividedGeometry.attributes,...n),this.originalGeometry&&jl(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(as.fromArray(n));let s=as.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,r,o;try{({originalGeometry:e,subdividedGeometry:r,subdivPointer:o}=zt.build(this.data,void 0,!this.flatShading,void 0))}catch{e=new lt.BoxGeometry(100,100,100),o=0}this.subdivPointer=o,this.originalGeometry=e,this.subdividedGeometry=r??void 0;let n=this.subdividedGeometry??this.originalGeometry;Object.assign(this,n),this.calcBoundingBox()}freeSubdivPointer(){this.subdivPointer&&(zt.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0)}dispose(){super.dispose(),this.freeSubdivPointer()}calcBoundingBox(){let e=this.originalGeometry;e.boundingSphere===null&&(e.boundingSphere=new lt.Sphere,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let r=e.attributes.position,o=e.boundingSphere.center;cd.setFromBufferAttribute(r),cd.getCenter(o),e.boundingSphere.radius=o.distanceTo(cd.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),cd.getSize(as);let n={width:as.x,height:as.y,depth:as.z};return this.userData.parameters=n,n}static build(e,r,o,n){let a,s,l,c=e?.phongAngle??35;o===!1&&(c=-1),r&&(Oe.free_bvh(r),Oe.free_subdivision_surface(r));try{a=zt.allocate(e,n)}catch(u){console.error(u,e),a=zt.allocate({positionWASM:Cb,indexWASM:Ab,verticesPerFaceWASM:Mb},n)}if(Oe.set_destination_refinement_level(a,0),s=zt.buildLevel(a,!0,c),e.subdivisions>0)try{Oe.set_destination_refinement_level(a,e.subdivisions),l=zt.buildLevel(a,!1,c)}catch{try{Oe.set_destination_refinement_level(a,e.subdivisions-1),l=zt.buildLevel(a,!1,c)}catch{l=null}}else l=null;return{subdivPointer:a,originalGeometry:s,subdividedGeometry:l}}static primitiveToQuads(e,r,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?r.geometry:zo(e,o,!1,r),a;e.type==="TorusGeometry"&&e.arc===Math.PI*2?a=n.getClosedTorusIndicesForBooleanOrSubdiv():a=n.getIndex();let s,l,c,u;({positions:s,triIndices:u}=th(n.getAttribute("position"),a));let d;if(e.type==="CylinderGeometry"&&e.cornerRadius===0&&e.hollow===0&&e.openEnded===!1){let p=e.radialSegments*e.heightSegments*3*2,f=p+e.radialSegments*3;d=[p,f]}return{indices:l,verticesPerFace:c}=rh(s,u,n,d),{positions:s,indices:l,verticesPerFace:c}}static allocate(e,r){let o,n,a,s=[],l=[];e.positionWASM&&e.positionWASM.length>0?(o=e.positionWASM,n=e.indexWASM,a=e.verticesPerFaceWASM):(o=Cb,n=Ab,a=Mb);let c=o.length,u=n.length,d=a.length,p=o.length+s.length+l.length,f=n.length+a.length,h=p*Float32Array.BYTES_PER_ELEMENT+f*Uint32Array.BYTES_PER_ELEMENT,m=p*Float32Array.BYTES_PER_ELEMENT,y=Oe._malloc(h),g=new Float32Array(Oe.HEAPF32.buffer,y,p),b=new Uint32Array(Oe.HEAPU32.buffer,y+m,f);g.set(o,0),g.set(s,o.length),g.set(l,o.length+s.length),b.set(n,0),b.set(a,n.length);let w;e?.scaleBaked?.some(S=>S!==1)&&(w=new lt.Matrix4().makeScale(...e.scaleBaked.map(S=>typeof S=="number"?S:1))),r&&(w?w.premultiply(r):w=r);let P=w?Oe.alloc_subdivision_surface2(y,c,y+m,u,y+m+n.length*Uint32Array.BYTES_PER_ELEMENT,d,w.elements):Oe.alloc_subdivision_surface(y,c,y+m,u,y+m+n.length*Uint32Array.BYTES_PER_ELEMENT,d);return Oe._free(y),P}static buildLevel(e,r,o,n,a){let s=a?Oe.get_mesh_data2(e,r?Oe.Level.CONTROL:Oe.Level.REFINED,o,a.elements):Oe.get_mesh_data(e,r?Oe.Level.CONTROL:Oe.Level.REFINED,o),l=8,c=Oe.HEAPU32.subarray(s>>2,(s>>2)+l),u=c.subarray(4,4+4),d=0,p=Oe.HEAPU32[c[d]>>2],f=Oe.HEAPF32.subarray(p>>2,(p>>2)+u[d]);d++;let h=Oe.HEAPU32[c[d]>>2],m=Oe.HEAPF32.subarray(h>>2,(h>>2)+u[d]);d++;let y=Oe.HEAPU32[c[d]>>2],g=Oe.HEAPU32.subarray(y>>2,(y>>2)+u[d]);d++;let b=Oe.HEAPU32[c[d]>>2],w=Oe.HEAPU32.subarray(b>>2,(b>>2)+u[d]);if(d++,n===void 0){let P=new lt.BufferGeometry;if(P.setIndex(new lt.Uint32BufferAttribute(w,1)),P.setAttribute("position",new lt.Float32BufferAttribute(f,3)),P.setAttribute("normal",new lt.Float32BufferAttribute(m,3)),r){P.setAttribute("faceMap",new lt.Uint32BufferAttribute(g,1));let S=new Float32Array(m.length/3*4).fill(0);P.setAttribute("color",new lt.BufferAttribute(S,4))}return Oe.free_mesh_data(s),P.userData.type="SubdivGeometry",P}n.getAttribute("position").copyArray(f),n.getAttribute("normal").copyArray(m),n.attributes.position.needsUpdate=!0,n.attributes.normal.needsUpdate=!0,Oe.free_mesh_data(s)}static freeSubdivPointer(e){Oe.free_bvh(e),Oe.free_subdivision_surface(e)}static buildControlCageWireframe(e,r,o){let n=Oe.get_wireframe_data_for_base_level(e),a=4,s=Oe.HEAPU32.subarray(n>>2,(n>>2)+a),l=s.subarray(2,2+2),c=0,u=Oe.HEAPU32[s[c]>>2],d=Oe.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let p=Oe.HEAPU32[s[c]>>2],f=Oe.HEAPU32.subarray(p>>2,(p>>2)+l[c]);if(r===void 0){let h=new lt.BufferGeometry;h.setAttribute("position",new lt.Float32BufferAttribute(d,3));let m=new Float32Array(d.length);for(let y=0,g=d.length;y<g;)m[y++]=o.r,m[y++]=o.g,m[y++]=o.b;return h.setAttribute("color",new lt.BufferAttribute(m,3)),h.setIndex(new lt.Uint32BufferAttribute(f,1)),Oe.free_wireframe_data_for_base_level(n),h}r.getAttribute("position").copyArray(d),r.attributes.position.needsUpdate=!0,Oe.free_wireframe_data_for_base_level(n)}static updateCollabMesh(e,r,o){let n=r===0;n||Oe.set_destination_refinement_level(e,r);let a=o?Oe.get_topological_data2(e,n?Oe.Level.CONTROL:Oe.Level.REFINED,o.elements):Oe.get_topological_data(e,n?Oe.Level.CONTROL:Oe.Level.REFINED),s=6,l=Oe.HEAPU32.subarray(a>>2,(a>>2)+s),c=l.subarray(3,3+3),u=0,d=Oe.HEAPU32[l[u]>>2],p=new Float32Array(Oe.HEAPF32.subarray(d>>2,(d>>2)+c[u]));u++;let f=Oe.HEAPU32[l[u]>>2],h=new Uint32Array(Oe.HEAPU32.subarray(f>>2,(f>>2)+c[u]));u++;let m=Oe.HEAPU32[l[u]>>2],y=new Uint8Array(Oe.HEAPU32.subarray(m>>2,(m>>2)+c[u]));return Oe.free_topological_data(a),{positions:p,indices:h,verticesPerFace:y}}};var Ib=["getX","getY","getZ"];function th(i,t){let e={},r=t?t.count:i.count,o=0,n=[],a=[],s=1e4;for(let c=0;c<r;c++){let u=t?t.getX(c):c,d="";for(let p=0;p<3;p++)d+=`${~~(i[Ib[p]](u)*s)},`;if(d in e)n.push(e[d]);else{for(let p=0;p<3;p++)a.push(i[Ib[p]](u));e[d]=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 ud=new lt.Vector3,Zf=new lt.Vector3,Jf=new lt.Vector3,eh=new lt.Vector3;function rh(i,t,e,r){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 p=l.length/2/c;l=l.filter((f,h)=>Math.floor(h/2)%p===0)}let u=0;for(let p=0;p<l.length;p+=2)u+=(l[p]-l[(p===0?l.length:p)-2])*(l[p+1]+l[(p===0?l.length:p)-1]);i.length=0;let d=0;if(u<0)for(let p=0;p<l.length;p+=2)i.push(l[p],l[p+1],0),o.push(d++);else for(let p=l.length-2;p>=0;p-=2)i.push(l[p],l[p+1],0),o.push(d++);return n.push(d),{indices:o,verticesPerFace:n}}let a=new Float32Array([e.userData.parameters.depth])[0],s=0;for(;s<t.length;){if(e.useNgonForTopBottomFaceDuringBake){let l=0;if((i[t[s]*3+2]===a||i[t[s]*3+2]===0)&&l++,(i[t[s+1]*3+2]===a||i[t[s+1]*3+2]===0)&&l++,(i[t[s+2]*3+2]===a||i[t[s+2]*3+2]===0)&&l++,l===3)break}if(t[s+1]===t[s+3]&&t[s+2]===t[s+5]||t[s+0]===t[s+3]&&t[s+2]===t[s+4]){ud.set(i[t[s]*3],i[t[s]*3+1],i[t[s]*3+2]),Zf.set(i[t[s+1]*3],i[t[s+1]*3+1],i[t[s+1]*3+2]),Jf.set(i[t[s+4]*3],i[t[s+4]*3+1],i[t[s+4]*3+2]),eh.set(i[t[s+5]*3],i[t[s+5]*3+1],i[t[s+5]*3+2]),Zf.sub(ud).normalize(),Jf.sub(ud).normalize(),eh.sub(ud).normalize();let l=Zf.cross(Jf).dot(eh),c=s;Math.abs(l)>.005||r&&r.some((u,d)=>d%2===1?!1:c>=r[d]&&c<r[d+1])?(o.push(t[s],t[s+1],t[s+2]),n.push(3),s+=3):(o.push(t[s],t[s+1],t[s+4],t[s+5]),n.push(4),s+=6)}else o.push(t[s],t[s+1],t[s+2]),n.push(3),s+=3}if(e.useNgonForTopBottomFaceDuringBake){let l=[],c=[],u=0;for(let d=0,p=0;d<i.length;d+=3,p++)i[d+2]===0&&(l.push(p),u++),i[d+2]===a&&c.push(p);if(e.userData.parameters.extrudeBevelSize===0){let d=c[0];c[0]=c[1],c[1]=d}l.reverse(),o.push(...l,...c),n.push(u,u)}return{indices:o,verticesPerFace:n}}var Xr={};gm(Xr,{calcBoolean:()=>jI,calcBooleanTopological:()=>FI,freeMeshSet:()=>WI,getMeshSet:()=>UI,hasOpenEdges:()=>kI,transformMeshSet:()=>HI});var zI,Eb=new Promise(i=>{zI=i});var Ul=require("three");var ke,ss;Eb.then(i=>ke=i);function GI(i,t,e){let r,o;i.userData.parameters.type==="TorusGeometry"&&i.userData.parameters.arc===Math.PI*2?o=i.getClosedTorusIndicesForBooleanOrSubdiv():o=i.getIndex();let{positions:n,triIndices:a}=th(i.getAttribute("position"),o),s;if(t&&e){let{indices:l,verticesPerFace:c}=rh(n,a,i);s=c.length,r=[];for(let u=0,d=0;u<s;u++){r.push(c[u]);for(let p=0;p<c[u];p++)r.push(l[d++])}}else{let l=a.length;r=Array(l+l/3),s=0;for(let c=0,u=0;u<r.length;)r[u++]=3,s++,r[u++]=a[c++],r[u++]=a[c++],r[u++]=a[c++]}return{positions:n,faceIndices:r,nFaces:s}}function Nb(i){let t=i.length,e=t*Uint32Array.BYTES_PER_ELEMENT,r=t*Float32Array.BYTES_PER_ELEMENT,o=Number.isInteger(i[0])?e:r,n=ke._malloc(o);return(Number.isInteger(i[0])?new Uint32Array(ke.HEAPU32.buffer,n,t):new Float32Array(ke.HEAPF32.buffer,n,t)).set(i,0),n}function Db(i){switch(i){case 0:return ke.OP.UNION;case 1:return ke.OP.INTERSECTION;case 2:return ke.OP.A_MINUS_B;default:throw new Error("Unknown boolean operation "+i)}}function FI(i,t){ss===void 0&&(ss=ke.init_csg());let e=Nb(i),r=ke.csg_calc_topological(ss,e,i.length,Db(t));ke._free(e);let o=6,n=ke.HEAPU32.subarray(r>>2,(r>>2)+o),a=n.subarray(3,3+3),s=0,l=ke.HEAPU32[n[s]>>2],c=new Float32Array(ke.HEAPF32.subarray(l>>2,(l>>2)+a[s]));s++;let u=ke.HEAPU32[n[s]>>2],d=new Uint32Array(ke.HEAPU32.subarray(u>>2,(u>>2)+a[s]));s++;let p=ke.HEAPU32[n[s]>>2],f=new Uint8Array(ke.HEAPU32.subarray(p>>2,(p>>2)+a[s]));return ke.free_mesh_data(r),{positions:c,indices:d,verticesPerFace:f}}function jI(i,t,e,r){ss===void 0&&(ss=ke.init_csg());let o=Nb(i),n=ke.csg_calc(ss,o,i.length,r,Db(t));ke._free(o);let a=5,s=ke.HEAPU32.subarray(n>>2,(n>>2)+a),l=s.subarray(2,2+3),c=0,u=ke.HEAPU32[s[c]>>2],d=ke.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let p=ke.HEAPU32[s[c]>>2],f=ke.HEAPF32.subarray(p>>2,(p>>2)+l[c]);c++;let h=l[c];e.setAttribute("position",new Ul.Float32BufferAttribute(d,3)),e.setAttribute("normal",new Ul.Float32BufferAttribute(f,3));let m=ke.HEAPF32.subarray((n>>2)+5,(n>>2)+5+6);return e.boundingSphere===null&&(e.boundingSphere=new Ul.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},ke.free_mesh_data(n),h}function UI(i,t,e){if(ke===void 0)return-1;let r,o,n;if(t&&i.userData.positions!==void 0){let g=i.userData;n=g.verticesPerFace.length,r=g.positions,o=Array(g.verticesPerFace.reduce((b,w)=>b+w,0)+n);for(let b=0,w=0,P=0;b<g.verticesPerFace.length;b++){o[P++]=g.verticesPerFace[b];for(let S=0;S<g.verticesPerFace[b];S++)o[P++]=g.indices[w++]}}else({positions:r,faceIndices:o,nFaces:n}=GI(i,t,e));let a=r.length,s=o.length,l=r.length,c=o.length,u=l*Float32Array.BYTES_PER_ELEMENT+c*Uint32Array.BYTES_PER_ELEMENT,d=l*Float32Array.BYTES_PER_ELEMENT,p=c*Uint32Array.BYTES_PER_ELEMENT,f=ke._malloc(u),h=new Float32Array(ke.HEAPF32.buffer,f,l),m=new Uint32Array(ke.HEAPU32.buffer,f+d,c);h.set(r,0),m.set(o,0);let y=ke.get_csg_mesh(f,a,f+d,s,n);return ke._free(f),y}function kI(i){return ke.has_open_edges(i)}function HI(i,t){ke.transform_csg_mesh(i,t.elements)}function WI(i){ke.free_csg_mesh(i)}var qI={ConeGeometry:wx,CubeGeometry:Px,CylinderGeometry:Sx,DodecahedronGeometry:Tx,EllipseGeometry:ts,HelixGeometry:Kx,IcosahedronGeometry:Zx,LatheGeometry:Jx,NonParametricGeometry:ob,PolygonGeometry:id,PyramidGeometry:ib,RectangleGeometry:is,SphereGeometry:nb,PlaneGeometry:sb,BackdropGeometry:lb,StarGeometry:nd,TextFrameGeometry:ub,TorusGeometry:db,TorusKnotGeometry:fb,TriangleGeometry:hb,PathGeometry:xb,VectorGeometry:Tr},Qf=i=>qI[i.type].create(i);function ls(i){return i!==null&&"booleanOp"in i}var cs=class extends $a(dd.Mesh){constructor(){super(...arguments);this.booleanMeshSetAddress=-1;this.booleanWasTransformed=!1;this.booleanMatrixInvOld=new dd.Matrix4}updateVisible(e){super.updateVisible(e),this.visible=!ls(this.parent)&&this.visible,ls(this.parent)&&this.parent.invalidateDownstreamBooleanData()}freeBooleanPointer(){this.booleanMeshSetAddress!==-1&&(Xr.freeMeshSet(this.booleanMeshSetAddress),this.booleanMeshSetAddress=-1)}invalidateDownstreamBooleanData(e=!1){return e?this.booleanWasTransformed=!0:this.freeBooleanPointer(),ls(this.parent)?this.parent.invalidateDownstreamBooleanData():this}invalidateUpstreamBooleanData(){this.freeBooleanPointer();for(let e of this.children)e instanceof cs&&(e.freeBooleanPointer(),ls(e)&&e.invalidateUpstreamBooleanData())}updateTransformState(e,r){let o=super.updateTransformState(e,r);return o&&ls(this.parent)&&this.invalidateDownstreamBooleanData(!0),o}onVariableUpdate(e=!1){super.onVariableUpdate(e),ls(this.parent)&&this.invalidateDownstreamBooleanData(!0)}};var pd=new us.Box3;function kl(i,t=0,e=i.count,r,o){let n=1/0,a=1/0,s=1/0,l=-1/0,c=-1/0,u=-1/0;for(let d=t;d<e;d++){let p=i.getX(d),f=i.getY(d),h=i.getZ(d);p<n&&(n=p),f<a&&(a=f),h<s&&(s=h),p>l&&(l=p),f>c&&(c=f),h>u&&(u=h)}pd.min.set(n,a,s),pd.max.set(l,c,u),pd.getCenter(r),pd.getSize(o).multiplyScalar(.5)}var $I=new us.BufferGeometry,XI=new us.MeshBasicMaterial,Xt=class extends cs{constructor(t,e){super($I,XI),this.super_Entity(t,e)}updateState(t,e){this.updateState_Entity(t,e)}updateEntityBoxSize(t,e){let r=this.geometry.getAttribute("position");r!==void 0?kl(r,this.geometry.drawRange.start,this.geometry.drawRange.count<1/0?this.geometry.drawRange.count:r.count,t,e):super.updateEntityBoxSize(t,e)}};var vi=require("three");var Gr=require("three");var Cd=require("three");var mi=class{constructor(t){this.hashProperties=void 0;this.isNode=!0;this.shortcuts={};if(mi.uuidContext===null)throw new Error("plz startContext");mi.uuidContext===mi.globalContext?this.uuid="_gid"+mi.uuidContext.nodeContextUuid++:this.uuid="_uid"+mi.uuidContext.nodeContextUuid++,this.type=t,this.name=""}static startContext(t){this.uuidContext===null||this.uuidContext===mi.globalContext?this.uuidContext=t:console.error("Can't start context twice")}static endContext(t){this.uuidContext!==t&&console.error("Can't end context twice"),this.uuidContext=null}analyze(t,e){e=e??{},t.analyzing=!0,this.build(t.addFlow(e.slot,e.cache,e.context),"v4"),t.clearVertexNodeCode(),t.clearFragmentNodeCode(),t.removeFlow(),t.analyzing=!1}analyzeAndFlow(t,e,r){return r=r??{},this.analyze(t,r),this.flow(t,e,r)}flow(t,e,r){r=r??{},t.addFlow(r.slot,r.cache,r.context);let o={result:this.build(t,e),code:t.clearNodeCode(),extra:t.context.extra};return t.removeFlow(),o}build(t,e,r){e=e??this.getType(t,e);let o=t.getNodeData(r??this);return t.analyzing&&this.appendDepsNode(t,o,e),t.nodes.indexOf(this)===-1&&t.nodes.push(this),this.updateFrame!==void 0&&t.updaters.indexOf(this)===-1&&t.updaters.push(this),this.generate(t,e,r)}updateFrame(t){}generateReadonly(t,e,r,o,n,a){return""}generate(t,e,r,o,n){return""}parse(t,e,r,o){}appendDepsNode(t,e,r){e.deps=(e.deps||0)+1;let o=t.getTypeLength(r);(o>(e.outputMax||0)||this.getType(t,r))&&(e.outputMax=o,e.output=r)}setName(t){this.name=t}getName(){return this.name}getType(t,e){return e==="sampler2D"||e==="samplerCube"?e:this.type}},ot=mi;ot.globalContext={nodeContextUuid:0},ot.uuidContext=mi.globalContext;var xo=require("three");var Hl=class{constructor(t){t=t??{},this.name=t.name,this.type=t.type,this.node=t.node,this.size=t.size,this.needsUpdate=t.needsUpdate}get value(){return this.node.value}set value(t){this.node.value=t}};var oh=class{constructor(){this.nodes={};this.keywords={}}add(t){this.nodes[t.name]=t}addKeyword(t,e,r){r=r!==void 0?r:!0,this.keywords[t]={callback:e,cache:r}}remove(t){delete this.nodes[t.name]}removeKeyword(t){delete this.keywords[t]}get(t){return this.nodes[t]}getKeyword(t,e){return this.keywords[t].callback(e)}getKeywordData(t){return this.keywords[t]}contains(t){return this.nodes[t]!==void 0}containsKeyword(t){return this.keywords[t]!==void 0}},Yt=new oh;var ih=require("three");var _b=require("three"),be=class extends ot{constructor(e,r){super(e);this.scope="";r=r??{},this.shared=r.shared!==void 0?r.shared:!0,this.unique=r.unique!==void 0?r.unique:!1}build(e,r,o,n){if(r=r??this.getType(e),this.getShared(e,r)){let a=this.getUnique(e,r);a&&this.uuid===void 0&&(this.uuid=_b.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,r),this.generate(e,r,o)):super.build(e,r,o);if(a)return s.name=s.name||super.build(e,r,o),s.name;if(!this.getLabel()&&(!this.getShared(e,l)||e.context.ignoreCache||s.deps===1))return super.build(e,r,o);o=this.getUUID(!1);let c=this.getTemp(e,o);if(c)return e.format(c,l,r);{c=super.generate(e,r,o,s.output,n);let u=this.generate(e,l,o);return e.addNodeCode(c+" = "+u+";"),e.format(c,l,r)}}return super.build(e,r,o)}getShared(e,r){return r!=="sampler2D"&&r!=="samplerCube"&&this.shared}getUnique(e,r){return this.unique}setLabel(e){return this.label=e,this}getLabel(){return this.label}getUUID(e){let r=this.uuid;return typeof this.scope=="string"&&(r=this.scope+"-"+r),r}getTemp(e,r){r=r||this.uuid;let o=e.getVars()[r];return o?o.name:void 0}generate(e,r,o,n,a){return this.getShared(e,r)||console.error("TempNode is not shared"),o=o??this.uuid,e.getTempVar(o,n??this.getType(e),a,this.getLabel()).name}};var it=class extends be{constructor(e,r){r=r??{},r.shared=r.shared!==void 0?r.shared:!1;super(e,r);this.readonly=!1}setReadonly(e){return this.readonly=e,this.hashProperties=this.readonly?["value"]:void 0,this}getReadonly(){return this.readonly}generate(e,r,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,r,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,r)):(l.fragment||(l.fragment=e.createFragmentUniform(n,this,a,s,this.getLabel())),e.format(l.fragment.name,n,r))}};var Ot=class extends it{constructor(e=0,r){super("v2");this.nodeType="Vector2";this.value=e instanceof ih.Vector2?e:new ih.Vector2(e,r)}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,r,o,n,a,s){return e.format("vec2("+this.value.x+", "+this.value.y+")",n,r)}};var nh=require("three");var ar=class extends it{constructor(e=0,r,o){super("v3");this.nodeType="Vector3";this.value=e instanceof nh.Vector3?e:new nh.Vector3(e,r,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,r,o,n,a,s){return e.format("vec3("+this.value.x+", "+this.value.y+", "+this.value.z+")",n,r)}};var Cr=class extends it{constructor(e){super("v4");this.nodeType="Vector4";this.value=e instanceof qt?e:new qt(e.r,e.g,e.b,e.a)}generateReadonly(e,r,o,n,a,s){return e.format("vec4("+this.value.r+", "+this.value.g+", "+this.value.b+", "+this.value.a+")",n,r)}};var YI=/^\s*([a-z_0-9]+)\s([a-z_0-9]+)\s*\((.*?)\)/i,Rb=/[a-z_0-9]+/gi,J=class extends be{constructor(e,r,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,r,o,n)}getShared(e,r){return!this.isMethod}getType(e){return e.getTypeByFormat(this.type)}getInputByName(e){if(this.inputs){let r=this.inputs.length;for(;r--;)if(this.inputs[r].name===e)return this.inputs[r]}}getIncludeByName(e){if(this.includes){let r=this.includes.length;for(;r--;)if(this.includes[r].name===e)return this.includes[r]}}generate(e,r,o,n,a){let s,l=0,c=this.src;if(this.includes)for(let d=0;d<this.includes.length;d++)e.include(this.includes[d],this);for(let d in this.extensions)e.extensions[d]=!0;let u=[];for(;s=Rb.exec(this.src);)u.push(s);for(let d=0;d<u.length;d++){let p=u[d],f=p[0],h=this.isMethod?!this.getInputByName(f):!0,m=f;if(this.keywords[f]||this.useKeywords&&h&&Yt.containsKeyword(f)){let y=this.keywords[f];if(!y){let g=Yt.getKeywordData(f);g.cache&&(y=e.keywords[f]),y=y||Yt.getKeyword(f,e),g.cache&&(e.keywords[f]=y)}m=y.build(e)}f!==m&&c[p.index+l-1]!=="."&&(c=c.substring(0,p.index+l)+m+c.substring(p.index+f.length+l),l+=m.length-f.length),this.getIncludeByName(m)===void 0&&Yt.contains(m)&&e.include(Yt.get(m))}return r==="source"?c:this.isMethod?(this.isInterface||e.include(this,void 0,c),this.name):e.format("( "+c+" )",this.getType(e),r)}parse(e,r,o,n){if(this.src=e||"",this.includes=r??[],this.extensions=o??{},this.keywords=n??{},this.isMethod){let a=YI.exec(this.src);if(this.inputs=[],a&&a.length==4){this.type=a[1],this.name=a[2];let s=a[3].match(Rb);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 d=s[l++];this.inputs.push({name:d,type:u,qualifier:c})}}this.isInterface=this.src.indexOf("{")===-1}else this.type="",this.name=""}}};var KI=/^([a-z_0-9]+)\s([a-z_0-9]+)\s?\=?\s?(.*?)(\;|$)/i,ah=class extends be{constructor(e="",r){super();this.src="";this.useDefine=!1;this.nodeType="Const";this.parse(e||ah.PI,void 0,void 0,void 0,r)}getType(e){return e.getTypeByFormat(this.type)}parse(e,r,o,n,a){this.src=e||"";let s,l,c="",u=KI.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,r){if(r==="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),r)}generate(e,r,o,n,a){return e.format(this.name,this.getType(e),r)}},$e=ah;$e.PI="PI",$e.PI2="PI2",$e.RECIPROCAL_PI="RECIPROCAL_PI",$e.RECIPROCAL_PI2="RECIPROCAL_PI2",$e.LOG2="LOG2",$e.EPSILON="EPSILON";var QI=new RegExp(`^structs*([a-z_0-9]+)s*{s*((.|
18
+ `&&n.push("")):t.getTextWidth(n[n.length-1]+a,i)>o&&(n[n.length-1].length&&n.push(""),t.getTextWidth(n[n.length-1]+a,i)>o&&(a.length===1?(n[n.length-1]+=a,a=""):(n[n.length-1]+=a.slice(0,-1),a=a[a.length-1],n.push(""))));return n[n.length-1]+=a,n}var lt=require("three");var wb,ld=new Promise(i=>{wb=i}),Sb=!1;var sd;function Pb(i){if(Sb)return;if(sd)return sd;async function t(){let r=i??(!1?".":"https://unpkg.com/@splinetool/modelling-wasm@1.12.42/build"),n=import("./process.js"),[a,s]=await Promise.all([n,fetch(`${r}/process.wasm`).then(u=>u.arrayBuffer())]),l=a.default,c=await l({wasmBinary:s});wb(c),Sb=!0}return sd=t(),sd}var Ob=require("three");var BI=["font"];function zo(i,t,e,r){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 d of c)u=u[d];for(o in u){let d=u[o];tf(d)&&!BI.includes(o)&&(u[o]=t.getVariable(d,[r.uuid,"geometry",...c,o]),tf(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=Ye.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 Ob.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 zt(n,e);return c.data=i,c}else{if(n.type==="TextGeometry")return new Vn(n,t);if(n.type==="InputGeometry")return new Vn(n,t);if(n.type==="UIGeometry")return is.create({parameters:{width:n.width,height:n.height,cornerRadius:n.cornerRadius,cornerType:n.cornerType}})}let l;try{l=Qf(s)}catch(c){console.error(c),console.error(`Error generating geometry with inputs: ${s}`);let u=Ye.createFromState(La.defaultData(),100,100);s.shape=u,s.type="VectorGeometry",l=Qf(s)}return l}var Tb=require("three"),VI=new Tb.Matrix4;function jl(i,t,e,r){let o=i.position.array,n=i.normal.array,a=VI.makeScale(t,e,r).invert().elements,s,l,c;for(var u=0,d=o.length;u<d;u+=3)o[u]*=t,o[u+1]*=e,o[u+2]*=r,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 cd=new lt.Box3,as=new lt.Vector3,Oe;ld.then(i=>{Oe=i});var Cb=new Float32Array([10,10,0,-10,10,0,-10,-10,0,10,-10,0]),Ab=new Uint32Array([0,1,2,3]),Mb=new Uint8Array([4]),zt=class extends lt.BufferGeometry{constructor(e,r){super();this.data=e;this.flatShading=r;this.subdivPointer=0;this.rebuild(),this.freeSubdivPointer()}mutateDirectlyScaleBaked(e,r){this.freeSubdivPointer();let o=this.data.scaleBaked.map(l=>typeof l=="number"?l:1),n=Bi.div(r.map(l=>typeof l=="number"?l:0),o);if(n.every(l=>l===1))return;this.subdividedGeometry&&jl(this.subdividedGeometry.attributes,...n),this.originalGeometry&&jl(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(as.fromArray(n));let s=as.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,r,o;try{({originalGeometry:e,subdividedGeometry:r,subdivPointer:o}=zt.build(this.data,void 0,!this.flatShading,void 0))}catch{e=new lt.BoxGeometry(100,100,100),o=0}this.subdivPointer=o,this.originalGeometry=e,this.subdividedGeometry=r??void 0;let n=this.subdividedGeometry??this.originalGeometry;Object.assign(this,n),this.calcBoundingBox()}freeSubdivPointer(){this.subdivPointer&&(zt.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0)}dispose(){super.dispose(),this.freeSubdivPointer()}calcBoundingBox(){let e=this.originalGeometry;e.boundingSphere===null&&(e.boundingSphere=new lt.Sphere,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let r=e.attributes.position,o=e.boundingSphere.center;cd.setFromBufferAttribute(r),cd.getCenter(o),e.boundingSphere.radius=o.distanceTo(cd.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),cd.getSize(as);let n={width:as.x,height:as.y,depth:as.z};return this.userData.parameters=n,n}static build(e,r,o,n){let a,s,l,c=e?.phongAngle??35;o===!1&&(c=-1),r&&(Oe.free_bvh(r),Oe.free_subdivision_surface(r));try{a=zt.allocate(e,n)}catch(u){console.error(u,e),a=zt.allocate({positionWASM:Cb,indexWASM:Ab,verticesPerFaceWASM:Mb},n)}if(Oe.set_destination_refinement_level(a,0),s=zt.buildLevel(a,!0,c),e.subdivisions>0)try{Oe.set_destination_refinement_level(a,e.subdivisions),l=zt.buildLevel(a,!1,c)}catch{try{Oe.set_destination_refinement_level(a,e.subdivisions-1),l=zt.buildLevel(a,!1,c)}catch{l=null}}else l=null;return{subdivPointer:a,originalGeometry:s,subdividedGeometry:l}}static primitiveToQuads(e,r,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?r.geometry:zo(e,o,!1,r),a;e.type==="TorusGeometry"&&e.arc===Math.PI*2?a=n.getClosedTorusIndicesForBooleanOrSubdiv():a=n.getIndex();let s,l,c,u;({positions:s,triIndices:u}=th(n.getAttribute("position"),a));let d;if(e.type==="CylinderGeometry"&&e.cornerRadius===0&&e.hollow===0&&e.openEnded===!1){let p=e.radialSegments*e.heightSegments*3*2,f=p+e.radialSegments*3;d=[p,f]}return{indices:l,verticesPerFace:c}=rh(s,u,n,d),{positions:s,indices:l,verticesPerFace:c}}static allocate(e,r){let o,n,a,s=[],l=[];e.positionWASM&&e.positionWASM.length>0?(o=e.positionWASM,n=e.indexWASM,a=e.verticesPerFaceWASM):(o=Cb,n=Ab,a=Mb);let c=o.length,u=n.length,d=a.length,p=o.length+s.length+l.length,f=n.length+a.length,h=p*Float32Array.BYTES_PER_ELEMENT+f*Uint32Array.BYTES_PER_ELEMENT,m=p*Float32Array.BYTES_PER_ELEMENT,y=Oe._malloc(h),g=new Float32Array(Oe.HEAPF32.buffer,y,p),b=new Uint32Array(Oe.HEAPU32.buffer,y+m,f);g.set(o,0),g.set(s,o.length),g.set(l,o.length+s.length),b.set(n,0),b.set(a,n.length);let w;e?.scaleBaked?.some(S=>S!==1)&&(w=new lt.Matrix4().makeScale(...e.scaleBaked.map(S=>typeof S=="number"?S:1))),r&&(w?w.premultiply(r):w=r);let P=w?Oe.alloc_subdivision_surface2(y,c,y+m,u,y+m+n.length*Uint32Array.BYTES_PER_ELEMENT,d,w.elements):Oe.alloc_subdivision_surface(y,c,y+m,u,y+m+n.length*Uint32Array.BYTES_PER_ELEMENT,d);return Oe._free(y),P}static buildLevel(e,r,o,n,a){let s=a?Oe.get_mesh_data2(e,r?Oe.Level.CONTROL:Oe.Level.REFINED,o,a.elements):Oe.get_mesh_data(e,r?Oe.Level.CONTROL:Oe.Level.REFINED,o),l=8,c=Oe.HEAPU32.subarray(s>>2,(s>>2)+l),u=c.subarray(4,4+4),d=0,p=Oe.HEAPU32[c[d]>>2],f=Oe.HEAPF32.subarray(p>>2,(p>>2)+u[d]);d++;let h=Oe.HEAPU32[c[d]>>2],m=Oe.HEAPF32.subarray(h>>2,(h>>2)+u[d]);d++;let y=Oe.HEAPU32[c[d]>>2],g=Oe.HEAPU32.subarray(y>>2,(y>>2)+u[d]);d++;let b=Oe.HEAPU32[c[d]>>2],w=Oe.HEAPU32.subarray(b>>2,(b>>2)+u[d]);if(d++,n===void 0){let P=new lt.BufferGeometry;if(P.setIndex(new lt.Uint32BufferAttribute(w,1)),P.setAttribute("position",new lt.Float32BufferAttribute(f,3)),P.setAttribute("normal",new lt.Float32BufferAttribute(m,3)),r){P.setAttribute("faceMap",new lt.Uint32BufferAttribute(g,1));let S=new Float32Array(m.length/3*4).fill(0);P.setAttribute("color",new lt.BufferAttribute(S,4))}return Oe.free_mesh_data(s),P.userData.type="SubdivGeometry",P}n.getAttribute("position").copyArray(f),n.getAttribute("normal").copyArray(m),n.attributes.position.needsUpdate=!0,n.attributes.normal.needsUpdate=!0,Oe.free_mesh_data(s)}static freeSubdivPointer(e){Oe.free_bvh(e),Oe.free_subdivision_surface(e)}static buildControlCageWireframe(e,r,o){let n=Oe.get_wireframe_data_for_base_level(e),a=4,s=Oe.HEAPU32.subarray(n>>2,(n>>2)+a),l=s.subarray(2,2+2),c=0,u=Oe.HEAPU32[s[c]>>2],d=Oe.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let p=Oe.HEAPU32[s[c]>>2],f=Oe.HEAPU32.subarray(p>>2,(p>>2)+l[c]);if(r===void 0){let h=new lt.BufferGeometry;h.setAttribute("position",new lt.Float32BufferAttribute(d,3));let m=new Float32Array(d.length);for(let y=0,g=d.length;y<g;)m[y++]=o.r,m[y++]=o.g,m[y++]=o.b;return h.setAttribute("color",new lt.BufferAttribute(m,3)),h.setIndex(new lt.Uint32BufferAttribute(f,1)),Oe.free_wireframe_data_for_base_level(n),h}r.getAttribute("position").copyArray(d),r.attributes.position.needsUpdate=!0,Oe.free_wireframe_data_for_base_level(n)}static updateCollabMesh(e,r,o){let n=r===0;n||Oe.set_destination_refinement_level(e,r);let a=o?Oe.get_topological_data2(e,n?Oe.Level.CONTROL:Oe.Level.REFINED,o.elements):Oe.get_topological_data(e,n?Oe.Level.CONTROL:Oe.Level.REFINED),s=6,l=Oe.HEAPU32.subarray(a>>2,(a>>2)+s),c=l.subarray(3,3+3),u=0,d=Oe.HEAPU32[l[u]>>2],p=new Float32Array(Oe.HEAPF32.subarray(d>>2,(d>>2)+c[u]));u++;let f=Oe.HEAPU32[l[u]>>2],h=new Uint32Array(Oe.HEAPU32.subarray(f>>2,(f>>2)+c[u]));u++;let m=Oe.HEAPU32[l[u]>>2],y=new Uint8Array(Oe.HEAPU32.subarray(m>>2,(m>>2)+c[u]));return Oe.free_topological_data(a),{positions:p,indices:h,verticesPerFace:y}}};var Ib=["getX","getY","getZ"];function th(i,t){let e={},r=t?t.count:i.count,o=0,n=[],a=[],s=1e4;for(let c=0;c<r;c++){let u=t?t.getX(c):c,d="";for(let p=0;p<3;p++)d+=`${~~(i[Ib[p]](u)*s)},`;if(d in e)n.push(e[d]);else{for(let p=0;p<3;p++)a.push(i[Ib[p]](u));e[d]=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 ud=new lt.Vector3,Zf=new lt.Vector3,Jf=new lt.Vector3,eh=new lt.Vector3;function rh(i,t,e,r){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 p=l.length/2/c;l=l.filter((f,h)=>Math.floor(h/2)%p===0)}let u=0;for(let p=0;p<l.length;p+=2)u+=(l[p]-l[(p===0?l.length:p)-2])*(l[p+1]+l[(p===0?l.length:p)-1]);i.length=0;let d=0;if(u<0)for(let p=0;p<l.length;p+=2)i.push(l[p],l[p+1],0),o.push(d++);else for(let p=l.length-2;p>=0;p-=2)i.push(l[p],l[p+1],0),o.push(d++);return n.push(d),{indices:o,verticesPerFace:n}}let a=new Float32Array([e.userData.parameters.depth])[0],s=0;for(;s<t.length;){if(e.useNgonForTopBottomFaceDuringBake){let l=0;if((i[t[s]*3+2]===a||i[t[s]*3+2]===0)&&l++,(i[t[s+1]*3+2]===a||i[t[s+1]*3+2]===0)&&l++,(i[t[s+2]*3+2]===a||i[t[s+2]*3+2]===0)&&l++,l===3)break}if(t[s+1]===t[s+3]&&t[s+2]===t[s+5]||t[s+0]===t[s+3]&&t[s+2]===t[s+4]){ud.set(i[t[s]*3],i[t[s]*3+1],i[t[s]*3+2]),Zf.set(i[t[s+1]*3],i[t[s+1]*3+1],i[t[s+1]*3+2]),Jf.set(i[t[s+4]*3],i[t[s+4]*3+1],i[t[s+4]*3+2]),eh.set(i[t[s+5]*3],i[t[s+5]*3+1],i[t[s+5]*3+2]),Zf.sub(ud).normalize(),Jf.sub(ud).normalize(),eh.sub(ud).normalize();let l=Zf.cross(Jf).dot(eh),c=s;Math.abs(l)>.005||r&&r.some((u,d)=>d%2===1?!1:c>=r[d]&&c<r[d+1])?(o.push(t[s],t[s+1],t[s+2]),n.push(3),s+=3):(o.push(t[s],t[s+1],t[s+4],t[s+5]),n.push(4),s+=6)}else o.push(t[s],t[s+1],t[s+2]),n.push(3),s+=3}if(e.useNgonForTopBottomFaceDuringBake){let l=[],c=[],u=0;for(let d=0,p=0;d<i.length;d+=3,p++)i[d+2]===0&&(l.push(p),u++),i[d+2]===a&&c.push(p);if(e.userData.parameters.extrudeBevelSize===0){let d=c[0];c[0]=c[1],c[1]=d}l.reverse(),o.push(...l,...c),n.push(u,u)}return{indices:o,verticesPerFace:n}}var Xr={};gm(Xr,{calcBoolean:()=>jI,calcBooleanTopological:()=>FI,freeMeshSet:()=>WI,getMeshSet:()=>UI,hasOpenEdges:()=>kI,transformMeshSet:()=>HI});var zI,Eb=new Promise(i=>{zI=i});var Ul=require("three");var ke,ss;Eb.then(i=>ke=i);function GI(i,t,e){let r,o;i.userData.parameters.type==="TorusGeometry"&&i.userData.parameters.arc===Math.PI*2?o=i.getClosedTorusIndicesForBooleanOrSubdiv():o=i.getIndex();let{positions:n,triIndices:a}=th(i.getAttribute("position"),o),s;if(t&&e){let{indices:l,verticesPerFace:c}=rh(n,a,i);s=c.length,r=[];for(let u=0,d=0;u<s;u++){r.push(c[u]);for(let p=0;p<c[u];p++)r.push(l[d++])}}else{let l=a.length;r=Array(l+l/3),s=0;for(let c=0,u=0;u<r.length;)r[u++]=3,s++,r[u++]=a[c++],r[u++]=a[c++],r[u++]=a[c++]}return{positions:n,faceIndices:r,nFaces:s}}function Nb(i){let t=i.length,e=t*Uint32Array.BYTES_PER_ELEMENT,r=t*Float32Array.BYTES_PER_ELEMENT,o=Number.isInteger(i[0])?e:r,n=ke._malloc(o);return(Number.isInteger(i[0])?new Uint32Array(ke.HEAPU32.buffer,n,t):new Float32Array(ke.HEAPF32.buffer,n,t)).set(i,0),n}function Db(i){switch(i){case 0:return ke.OP.UNION;case 1:return ke.OP.INTERSECTION;case 2:return ke.OP.A_MINUS_B;default:throw new Error("Unknown boolean operation "+i)}}function FI(i,t){ss===void 0&&(ss=ke.init_csg());let e=Nb(i),r=ke.csg_calc_topological(ss,e,i.length,Db(t));ke._free(e);let o=6,n=ke.HEAPU32.subarray(r>>2,(r>>2)+o),a=n.subarray(3,3+3),s=0,l=ke.HEAPU32[n[s]>>2],c=new Float32Array(ke.HEAPF32.subarray(l>>2,(l>>2)+a[s]));s++;let u=ke.HEAPU32[n[s]>>2],d=new Uint32Array(ke.HEAPU32.subarray(u>>2,(u>>2)+a[s]));s++;let p=ke.HEAPU32[n[s]>>2],f=new Uint8Array(ke.HEAPU32.subarray(p>>2,(p>>2)+a[s]));return ke.free_mesh_data(r),{positions:c,indices:d,verticesPerFace:f}}function jI(i,t,e,r){ss===void 0&&(ss=ke.init_csg());let o=Nb(i),n=ke.csg_calc(ss,o,i.length,r,Db(t));ke._free(o);let a=5,s=ke.HEAPU32.subarray(n>>2,(n>>2)+a),l=s.subarray(2,2+3),c=0,u=ke.HEAPU32[s[c]>>2],d=ke.HEAPF32.subarray(u>>2,(u>>2)+l[c]);c++;let p=ke.HEAPU32[s[c]>>2],f=ke.HEAPF32.subarray(p>>2,(p>>2)+l[c]);c++;let h=l[c];e.setAttribute("position",new Ul.Float32BufferAttribute(d,3)),e.setAttribute("normal",new Ul.Float32BufferAttribute(f,3));let m=ke.HEAPF32.subarray((n>>2)+5,(n>>2)+5+6);return e.boundingSphere===null&&(e.boundingSphere=new Ul.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},ke.free_mesh_data(n),h}function UI(i,t,e){if(ke===void 0)return-1;let r,o,n;if(t&&i.userData.positions!==void 0){let g=i.userData;n=g.verticesPerFace.length,r=g.positions,o=Array(g.verticesPerFace.reduce((b,w)=>b+w,0)+n);for(let b=0,w=0,P=0;b<g.verticesPerFace.length;b++){o[P++]=g.verticesPerFace[b];for(let S=0;S<g.verticesPerFace[b];S++)o[P++]=g.indices[w++]}}else({positions:r,faceIndices:o,nFaces:n}=GI(i,t,e));let a=r.length,s=o.length,l=r.length,c=o.length,u=l*Float32Array.BYTES_PER_ELEMENT+c*Uint32Array.BYTES_PER_ELEMENT,d=l*Float32Array.BYTES_PER_ELEMENT,p=c*Uint32Array.BYTES_PER_ELEMENT,f=ke._malloc(u),h=new Float32Array(ke.HEAPF32.buffer,f,l),m=new Uint32Array(ke.HEAPU32.buffer,f+d,c);h.set(r,0),m.set(o,0);let y=ke.get_csg_mesh(f,a,f+d,s,n);return ke._free(f),y}function kI(i){return ke.has_open_edges(i)}function HI(i,t){ke.transform_csg_mesh(i,t.elements)}function WI(i){ke.free_csg_mesh(i)}var qI={ConeGeometry:wx,CubeGeometry:Px,CylinderGeometry:Sx,DodecahedronGeometry:Tx,EllipseGeometry:ts,HelixGeometry:Kx,IcosahedronGeometry:Zx,LatheGeometry:Jx,NonParametricGeometry:ob,PolygonGeometry:id,PyramidGeometry:ib,RectangleGeometry:is,SphereGeometry:nb,PlaneGeometry:sb,BackdropGeometry:lb,StarGeometry:nd,TextFrameGeometry:ub,TorusGeometry:db,TorusKnotGeometry:fb,TriangleGeometry:hb,PathGeometry:xb,VectorGeometry:Tr},Qf=i=>qI[i.type].create(i);function ls(i){return i!==null&&"booleanOp"in i}var cs=class extends $a(dd.Mesh){constructor(){super(...arguments);this.booleanMeshSetAddress=-1;this.booleanWasTransformed=!1;this.booleanMatrixInvOld=new dd.Matrix4}updateVisible(e){super.updateVisible(e),this.visible=!ls(this.parent)&&this.visible,ls(this.parent)&&this.parent.invalidateDownstreamBooleanData()}freeBooleanPointer(){this.booleanMeshSetAddress!==-1&&(Xr.freeMeshSet(this.booleanMeshSetAddress),this.booleanMeshSetAddress=-1)}invalidateDownstreamBooleanData(e=!1){return e?this.booleanWasTransformed=!0:this.freeBooleanPointer(),ls(this.parent)?this.parent.invalidateDownstreamBooleanData():this}invalidateUpstreamBooleanData(){this.freeBooleanPointer();for(let e of this.children)e instanceof cs&&(e.freeBooleanPointer(),ls(e)&&e.invalidateUpstreamBooleanData())}updateTransformState(e,r){let o=super.updateTransformState(e,r);return o&&ls(this.parent)&&this.invalidateDownstreamBooleanData(!0),o}onVariableUpdate(e=!1){super.onVariableUpdate(e),ls(this.parent)&&this.invalidateDownstreamBooleanData(!0)}};var pd=new us.Box3;function kl(i,t=0,e=i.count,r,o){let n=1/0,a=1/0,s=1/0,l=-1/0,c=-1/0,u=-1/0;for(let d=t;d<e;d++){let p=i.getX(d),f=i.getY(d),h=i.getZ(d);p<n&&(n=p),f<a&&(a=f),h<s&&(s=h),p>l&&(l=p),f>c&&(c=f),h>u&&(u=h)}pd.min.set(n,a,s),pd.max.set(l,c,u),pd.getCenter(r),pd.getSize(o).multiplyScalar(.5)}var $I=new us.BufferGeometry,XI=new us.MeshBasicMaterial,Xt=class extends cs{constructor(t,e){super($I,XI),this.super_Entity(t,e)}updateState(t,e){this.updateState_Entity(t,e)}updateEntityBoxSize(t,e){let r=this.geometry.getAttribute("position");r!==void 0?kl(r,this.geometry.drawRange.start,this.geometry.drawRange.count<1/0?this.geometry.drawRange.count:r.count,t,e):super.updateEntityBoxSize(t,e)}};var vi=require("three");var Gr=require("three");var Cd=require("three");var mi=class{constructor(t){this.hashProperties=void 0;this.isNode=!0;this.shortcuts={};if(mi.uuidContext===null)throw new Error("plz startContext");mi.uuidContext===mi.globalContext?this.uuid="_gid"+mi.uuidContext.nodeContextUuid++:this.uuid="_uid"+mi.uuidContext.nodeContextUuid++,this.type=t,this.name=""}static startContext(t){this.uuidContext===null||this.uuidContext===mi.globalContext?this.uuidContext=t:console.error("Can't start context twice")}static endContext(t){this.uuidContext!==t&&console.error("Can't end context twice"),this.uuidContext=null}analyze(t,e){e=e??{},t.analyzing=!0,this.build(t.addFlow(e.slot,e.cache,e.context),"v4"),t.clearVertexNodeCode(),t.clearFragmentNodeCode(),t.removeFlow(),t.analyzing=!1}analyzeAndFlow(t,e,r){return r=r??{},this.analyze(t,r),this.flow(t,e,r)}flow(t,e,r){r=r??{},t.addFlow(r.slot,r.cache,r.context);let o={result:this.build(t,e),code:t.clearNodeCode(),extra:t.context.extra};return t.removeFlow(),o}build(t,e,r){e=e??this.getType(t,e);let o=t.getNodeData(r??this);return t.analyzing&&this.appendDepsNode(t,o,e),t.nodes.indexOf(this)===-1&&t.nodes.push(this),this.updateFrame!==void 0&&t.updaters.indexOf(this)===-1&&t.updaters.push(this),this.generate(t,e,r)}updateFrame(t){}generateReadonly(t,e,r,o,n,a){return""}generate(t,e,r,o,n){return""}parse(t,e,r,o){}appendDepsNode(t,e,r){e.deps=(e.deps||0)+1;let o=t.getTypeLength(r);(o>(e.outputMax||0)||this.getType(t,r))&&(e.outputMax=o,e.output=r)}setName(t){this.name=t}getName(){return this.name}getType(t,e){return e==="sampler2D"||e==="samplerCube"?e:this.type}},ot=mi;ot.globalContext={nodeContextUuid:0},ot.uuidContext=mi.globalContext;var xo=require("three");var Hl=class{constructor(t){t=t??{},this.name=t.name,this.type=t.type,this.node=t.node,this.size=t.size,this.needsUpdate=t.needsUpdate}get value(){return this.node.value}set value(t){this.node.value=t}};var oh=class{constructor(){this.nodes={};this.keywords={}}add(t){this.nodes[t.name]=t}addKeyword(t,e,r){r=r!==void 0?r:!0,this.keywords[t]={callback:e,cache:r}}remove(t){delete this.nodes[t.name]}removeKeyword(t){delete this.keywords[t]}get(t){return this.nodes[t]}getKeyword(t,e){return this.keywords[t].callback(e)}getKeywordData(t){return this.keywords[t]}contains(t){return this.nodes[t]!==void 0}containsKeyword(t){return this.keywords[t]!==void 0}},Yt=new oh;var ih=require("three");var _b=require("three"),be=class extends ot{constructor(e,r){super(e);this.scope="";r=r??{},this.shared=r.shared!==void 0?r.shared:!0,this.unique=r.unique!==void 0?r.unique:!1}build(e,r,o,n){if(r=r??this.getType(e),this.getShared(e,r)){let a=this.getUnique(e,r);a&&this.uuid===void 0&&(this.uuid=_b.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,r),this.generate(e,r,o)):super.build(e,r,o);if(a)return s.name=s.name||super.build(e,r,o),s.name;if(!this.getLabel()&&(!this.getShared(e,l)||e.context.ignoreCache||s.deps===1))return super.build(e,r,o);o=this.getUUID(!1);let c=this.getTemp(e,o);if(c)return e.format(c,l,r);{c=super.generate(e,r,o,s.output,n);let u=this.generate(e,l,o);return e.addNodeCode(c+" = "+u+";"),e.format(c,l,r)}}return super.build(e,r,o)}getShared(e,r){return r!=="sampler2D"&&r!=="samplerCube"&&this.shared}getUnique(e,r){return this.unique}setLabel(e){return this.label=e,this}getLabel(){return this.label}getUUID(e){let r=this.uuid;return typeof this.scope=="string"&&(r=this.scope+"-"+r),r}getTemp(e,r){r=r||this.uuid;let o=e.getVars()[r];return o?o.name:void 0}generate(e,r,o,n,a){return this.getShared(e,r)||console.error("TempNode is not shared"),o=o??this.uuid,e.getTempVar(o,n??this.getType(e),a,this.getLabel()).name}};var it=class extends be{constructor(e,r){r=r??{},r.shared=r.shared!==void 0?r.shared:!1;super(e,r);this.readonly=!1}setReadonly(e){return this.readonly=e,this.hashProperties=this.readonly?["value"]:void 0,this}getReadonly(){return this.readonly}generate(e,r,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,r,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,r)):(l.fragment||(l.fragment=e.createFragmentUniform(n,this,a,s,this.getLabel())),e.format(l.fragment.name,n,r))}};var Ot=class extends it{constructor(e=0,r){super("v2");this.nodeType="Vector2";this.value=e instanceof ih.Vector2?e:new ih.Vector2(e,r)}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,r,o,n,a,s){return e.format("vec2("+this.value.x+", "+this.value.y+")",n,r)}};var nh=require("three");var ar=class extends it{constructor(e=0,r,o){super("v3");this.nodeType="Vector3";this.value=e instanceof nh.Vector3?e:new nh.Vector3(e,r,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,r,o,n,a,s){return e.format("vec3("+this.value.x+", "+this.value.y+", "+this.value.z+")",n,r)}};var Cr=class extends it{constructor(e){super("v4");this.nodeType="Vector4";this.value=e instanceof qt?e:new qt(e.r,e.g,e.b,e.a)}generateReadonly(e,r,o,n,a,s){return e.format("vec4("+this.value.r+", "+this.value.g+", "+this.value.b+", "+this.value.a+")",n,r)}};var YI=/^\s*([a-z_0-9]+)\s([a-z_0-9]+)\s*\((.*?)\)/i,Rb=/[a-z_0-9]+/gi,J=class extends be{constructor(e,r,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,r,o,n)}getShared(e,r){return!this.isMethod}getType(e){return e.getTypeByFormat(this.type)}getInputByName(e){if(this.inputs){let r=this.inputs.length;for(;r--;)if(this.inputs[r].name===e)return this.inputs[r]}}getIncludeByName(e){if(this.includes){let r=this.includes.length;for(;r--;)if(this.includes[r].name===e)return this.includes[r]}}generate(e,r,o,n,a){let s,l=0,c=this.src;if(this.includes)for(let d=0;d<this.includes.length;d++)e.include(this.includes[d],this);for(let d in this.extensions)e.extensions[d]=!0;let u=[];for(;s=Rb.exec(this.src);)u.push(s);for(let d=0;d<u.length;d++){let p=u[d],f=p[0],h=this.isMethod?!this.getInputByName(f):!0,m=f;if(this.keywords[f]||this.useKeywords&&h&&Yt.containsKeyword(f)){let y=this.keywords[f];if(!y){let g=Yt.getKeywordData(f);g.cache&&(y=e.keywords[f]),y=y||Yt.getKeyword(f,e),g.cache&&(e.keywords[f]=y)}m=y.build(e)}f!==m&&c[p.index+l-1]!=="."&&(c=c.substring(0,p.index+l)+m+c.substring(p.index+f.length+l),l+=m.length-f.length),this.getIncludeByName(m)===void 0&&Yt.contains(m)&&e.include(Yt.get(m))}return r==="source"?c:this.isMethod?(this.isInterface||e.include(this,void 0,c),this.name):e.format("( "+c+" )",this.getType(e),r)}parse(e,r,o,n){if(this.src=e||"",this.includes=r??[],this.extensions=o??{},this.keywords=n??{},this.isMethod){let a=YI.exec(this.src);if(this.inputs=[],a&&a.length==4){this.type=a[1],this.name=a[2];let s=a[3].match(Rb);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 d=s[l++];this.inputs.push({name:d,type:u,qualifier:c})}}this.isInterface=this.src.indexOf("{")===-1}else this.type="",this.name=""}}};var KI=/^([a-z_0-9]+)\s([a-z_0-9]+)\s?\=?\s?(.*?)(\;|$)/i,ah=class extends be{constructor(e="",r){super();this.src="";this.useDefine=!1;this.nodeType="Const";this.parse(e||ah.PI,void 0,void 0,void 0,r)}getType(e){return e.getTypeByFormat(this.type)}parse(e,r,o,n,a){this.src=e||"";let s,l,c="",u=KI.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,r){if(r==="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),r)}generate(e,r,o,n,a){return e.format(this.name,this.getType(e),r)}},$e=ah;$e.PI="PI",$e.PI2="PI2",$e.RECIPROCAL_PI="RECIPROCAL_PI",$e.RECIPROCAL_PI2="RECIPROCAL_PI2",$e.LOG2="LOG2",$e.EPSILON="EPSILON";var QI=new RegExp(`^structs*([a-z_0-9]+)s*{s*((.|
19
19
  )*?)}`,"gim"),ZI=new RegExp("s*(w*?)s*(w*?)(=|;)","gim"),ds=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 r=this.inputs.length;for(;r--;)if(this.inputs[r].name===e)return this.inputs[r]}generate(e,r,o,n,a){return r==="source"?this.src+";":e.format("( "+this.src+" )",this.getType(e),r)}parse(e=""){this.src=e,this.inputs=[];let r=QI.exec(e);if(r){let o=r[2],n;for(;n=ZI.exec(o);)this.inputs.push({type:n[1],name:n[2]});this.name=r[1]}else this.name="";this.type=this.name}};var ps=class extends be{constructor(e){super("v2",{shared:!1});this.nodeType="UV";this.index=e??0}generate(e,r){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),r)}};Yt.addKeyword("uv",function(){return new ps});Yt.addKeyword("uv2",function(){return new ps(1)});var fd=require("three");var zn=class extends be{constructor(e,r){super("v4");this.nodeType="ColorSpace";this.input=e,this.method=r??zn.LINEAR_TO_LINEAR,this.hashProperties=["method"]}static getEncodingComponents(e){switch(e){case fd.LinearEncoding:return["Linear"];case fd.sRGBEncoding:return["sRGB"];default:return[]}}generate(e,r){let o=this.input.build(e,"v4"),n=this.getType(e),a=zn.Nodes[this.method],s=e.include(a);if(s===zn.LINEAR_TO_LINEAR)return e.format(o,n,r);if(a.inputs?.length===2){let l=this.factor.build(e,"f");return e.format(s+"( "+o+", "+l+" )",n,r)}else return e.format(s+"( "+o+" )",n,r)}fromEncoding(e){let r=zn.getEncodingComponents(e);this.method="LinearTo"+r[0],this.factor=r[1]}fromDecoding(e){let r=zn.getEncodingComponents(e);this.method=r[0]+"ToLinear",this.factor=r[1]}},yr=zn;yr.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,r])}}();var _e={normalRenderTarget:new gr,normalRenderTargetDepth:new gr,transmissionRenderTarget:new gr,aspectRatio:new Ot,transmissionSize:new Ot(2048,2048),transmissionRenderTargetDepth:new gr,aoRenderTarget:new gr,aoEnabled:new Tt,pixelRatioNode:new se(1),resolution:new Ot,penumbraSize:new bo(5,.5),frameIndex:new je(0),transmissionLod:new je(2),taaEnabled:new Tt(!0)};for(let i of Object.values(_e))i.isRenderGlobal=!0;var Kb={skiaWasmUrl:"https://unpkg.com/@splinetool/ui-wasm@1.12.41/build/ui.wasm"};var yi=class extends ot{constructor(){super("basic");this.nodeType="Basic";this.color=new et(Bt),this.shadingAlpha=new se(1),this.shadingBlend=new je(0),this.previousModelViewMatrix=new sr,this.previouseProjectionMatrix=new sr}get category(){return"phong"}generate(e){let r;if(e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:_e.frameIndex}),e.mergeUniform({resolution:_e.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(xd.UniformsUtils.merge([xd.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(`
1876
+ }`,[e,r])}}();var _e={normalRenderTarget:new gr,normalRenderTargetDepth:new gr,transmissionRenderTarget:new gr,aspectRatio:new Ot,transmissionSize:new Ot(2048,2048),transmissionRenderTargetDepth:new gr,aoRenderTarget:new gr,aoEnabled:new Tt,pixelRatioNode:new se(1),resolution:new Ot,penumbraSize:new bo(5,.5),frameIndex:new je(0),transmissionLod:new je(2),taaEnabled:new Tt(!0)};for(let i of Object.values(_e))i.isRenderGlobal=!0;var Kb={skiaWasmUrl:"https://unpkg.com/@splinetool/ui-wasm@1.12.42/build/ui.wasm"};var yi=class extends ot{constructor(){super("basic");this.nodeType="Basic";this.color=new et(Bt),this.shadingAlpha=new se(1),this.shadingBlend=new je(0),this.previousModelViewMatrix=new sr,this.previouseProjectionMatrix=new sr}get category(){return"phong"}generate(e){let r;if(e.isShader("vertex")){let o=this.position?this.position.analyzeAndFlow(e,"v3",{cache:"position"}):void 0;e.mergeUniform({frameIndex:_e.frameIndex}),e.mergeUniform({resolution:_e.resolution}),e.mergeUniform({previousModelViewMatrix:this.previousModelViewMatrix}),e.mergeUniform({previousProjectionMatrix:this.previouseProjectionMatrix}),e.mergeUniform(xd.UniformsUtils.merge([xd.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),d=e.horizontalAlign===1?u:0,p=this.getLineInitialOffsetX(s[0],l,e.horizontalAlign,t[0],u),f=this.getLineInitialOffsetY(a,t.length,c,n,e.verticalAlign),h=[],m=t.map(b=>[]),y=t.map(b=>[]);for(let b=0;b<t.length;b++){let w=t[b],P={features:{liga:!0},letterSpacing:e.letterSpacing},S=[];try{S=o.stringToGlyphs(w,P)}catch(E){console.warn(E)}p=this.getLineInitialOffsetX(s[b],l,e.horizontalAlign,w,u);let T=[];try{T=this.reverseLigaturesTable(o,w,S)}catch(E){console.warn(E)}let A=this.computeSpaceWidthForLine(t,b,e,r),x=0,N=S[0];N&&e.horizontalAlign===2&&N.leftSideBearing!==void 0&&(p-=N.leftSideBearing*n),this.font?.forEachGlyph(w,p,f,e.fontSize,P,(E,M,D,_,R)=>{let V=E.index===0?`
2287
2287
  `:E.unicode?String.fromCharCode(E.unicode):void 0,U=T[x],B=0;if(V===`
2288
2288
  `)B=d;else if(V===" ")B=A;else{let q=this.createPath(E,n,M,D,e);q&&(B=q.offsetX,h.push(q.path))}if(U.replacements.length===1)y[b].push([M,D]),m[b].push(B);else{let q=U.replacements.map(W=>(o.glyphs.get(W).advanceWidth??0)*n),j=q.reduce((W,ee)=>W+=ee,0),F=q.map(W=>W/j),H=M;for(let W=0;W<F.length;W++){let ee=B*F[W];y[b].push([H,D]),m[b].push(ee),H+=ee}}x++}),f-=a}let g=[];for(let b=0,w=h.length;b<w;b++)g.push(...h[b].toShapes());return{shapes:g,charWidths:m,lineWidths:s,charCoords:y}}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(t,e,r,o,n){return(r===3||r===2)&&o.indexOf(`
2289
- `)>=0&&(t-=n),r===3?e*.5-t*.5:r===2?e-t:0}getLineInitialOffsetY(t,e,r,o,n){let a=e*t,s=Math.abs(this.ascender-this.descender)*o,l=t-s,c=-this.ascender*o-l/2;return n===3?-(r-a-c):n===2?-(r*.5-a*.5-c):c}createPath(t,e,r,o,n){let a=t.getPath(r,-o,n.fontSize,{kerning:!1,letterSpacing:n.letterSpacing});if(!a){console.error('THREE.Font: character "'+t+'" does not exists in font family '+this.familyName+".");return}let s=new Ad,l=(t.advanceWidth??1)*e;if(t)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=T3(c.curves);u!==void 0&&c.currentPoint.distanceTo(u)>0&&c.lineTo(u.x,u.y)}),{offsetX:l,path:s}}getCharWidth(t,e){return this.font?.getAdvanceWidth(t,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}getTextWidth(t,e){return this.font?.getAdvanceWidth(t,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}computeSpaceWidthForLine(t,e,r,o){let n=this.getCharWidth(" ",r),a=t[e];if(a){let s=this.countSpaces(a.trimEnd());if(r.horizontalAlign===4&&e<t.length-1&&s){let l=typeof r.width=="string"?Number(o.getVariable(r.width)):r.width,c=this.getTextWidth(a,r);return(l-(c-s*n))/s}}return n}countSpaces(t){return(t.match(/ /g)||[]).length}};function T3(i){if(i.length){let t=i[0];if(t instanceof Rs.LineCurve)return t.v1;if(t instanceof Rs.CubicBezierCurve||t instanceof Rs.QuadraticBezierCurve)return t.v0}}var Ah=class{constructor(){this.objects=new Map;this.unreachable=new Set}getCached(t){return this.objects.get(t)}get size(){return this.objects.size}get(t,e,r){let o=this.objects.get(t);return o===void 0?(o=this.createObject(t,e,r),this.objects.set(t,o)):o.isShared=!0,o}forceDelete(t){let e=this.objects.get(t);e&&(this.disposeObject(e),this.objects.delete(t))}mutateIfUnique(t,e){let r=this.objects.get(t);if(r&&r.isShared!==!0)return this.objects.delete(t),this.objects.set(e,r),r}startGc(){this.unreachable=new Set(this.objects.keys())}markAsReachable(t,e){let r=this.objects.get(t);e===r?this.unreachable.delete(t):!1&&console.warn("Reachable but deleted",t)}endGc(){this.unreachable.forEach(t=>{this.disposeObject(this.objects.get(t)),this.objects.delete(t)}),this.unreachable.clear()}dispose(){this.objects.forEach(t=>{this.disposeObject(t)}),this.objects.clear()}},ic=class extends Ah{constructor(e){super();this.flatShading=e}disposeObject(e){e.dispose()}createObject(e,r,o){let n=zo(e,r,this.flatShading,o);return n.computeBoundingSphere(),n}};var sv={markNeedsUpdateRendererDirty:()=>{}};var Eh=require("three");var Ed=1e3,lv=512*Ed;function C3(i,t){let e=typeof i;return!!((t==="string"||t==="number")&&e===t||t==="boolean"&&(i==="true"||i==="false"||i===!0||i===!1)||t==="image"&&e==="string"&&i.startsWith("http"))}var cv="https://hooks.spline.design",A3=`${cv}/events?hashFile=`,AQ=`${cv}/`,Nd=class{constructor(t,e){this.id=t;this.userWebhook=e;this.result=void 0;this._connected=!1;this.emitter=hi();this.reconnectWaitFor=Ed;this._onError=t=>{this.eventSource?.removeEventListener("message",this._onMessage),this.eventSource?.removeEventListener("error",this._onError),this.eventSource?.removeEventListener("open",this._onConnected),this._scheduleReconnect()};this._onConnected=t=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=Ed,this._connected=!0};this._onDisconnected=()=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=Ed,this._connected=!1};this._onMessage=t=>{let e=t.data,r;try{r=JSON.parse(e)}catch(o){console.error("Error parsing webhook message",o)}if(r){let o=!1;this.userWebhook.parametersSchemas.forEach(({data:n})=>{r[n.name]!==void 0&&C3(r[n.name],n.type)&&(this.result===void 0&&(this.result={}),this.result[n.name]=r[n.name],o=!0)}),o&&this.emitter.emit("message",{userWebhookId:this.id})}}}connect(){clearTimeout(this.scheduledReconnectHandle),this.userWebhook.url&&(this.eventSource=new EventSource(A3+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>lv&&(this.reconnectWaitFor=lv),clearTimeout(this.scheduledReconnectHandle),this.scheduledReconnectHandle=setTimeout(()=>{this.scheduledReconnectHandle=void 0,this.connect()},this.reconnectWaitFor)}update(t){this.userWebhook=t}dispose(){this._connected&&this.disconnect()}get connected(){return this._connected}on(t,e){this.emitter.on(t,e)}off(t,e){this.emitter.off(t,e)}getParametersKeys(){return this.userWebhook.parametersSchemas.map(t=>t.data.name)}getParameterValue(t){if(this.getParametersKeys().includes(t)){if(this.result)return this.result?.[t];for(let r of this.userWebhook.parametersSchemas)if(r.data.name===t)return Lu.defaultParameterValueByType(r.data.type)}}};var uv=[4186.01,4434.92,4698.63,4978.03,5274.04,5587.65,5919.91,6271.93,6644.88,7040,7458.62,7902.13],M3=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],bi=[],_d=[];for(let i=1;i<=8;i++)for(let t=0;t<uv.length;t++){let e=uv[t];bi.push(e/Math.pow(2,8-i)),_d.push(M3[t]+i)}var Dd=[32,2e3],Mh=bi.filter((i,t)=>bi[t]>Dd[0]&&bi[t]<Dd[1]),dv=_d.filter((i,t)=>bi[t]>Dd[0]&&bi[t]<Dd[1]);var Rd=class{static getFrequencies(t,e,r,o="frequency",n=-100,a=-30){r||(r=new Float32Array(t.frequencyBinCount),t.getFloatFrequencyData(r));let s=e/2,l=1/r.length*s,c,u,d;if(o==="music"||o==="voice"){let h=o==="voice"?Mh:bi,m=Array(h.length).fill(n);for(let y=0;y<r.length;y++){let g=y*l,b=r[y];for(let w=h.length-1;w>=0;w--)if(g>h[w]){m[w]=Math.max(m[w],b);break}}c=m,u=o==="voice"?Mh:bi,d=o==="voice"?dv:_d}else c=Array.from(r),u=c.map((h,m)=>l*m),d=u.map(h=>`${h.toFixed(2)} Hz`);let p=c.map(h=>Math.max(0,Math.min((h-n)/(a-n),1)));return{values:new Float32Array(p),frequencies:u,labels:d}}};var I3="gpt-4o-realtime-preview-2024-12-17",E3=()=>!1&&window.location.search.includes("api-dev")?"https://relayserver-dev.spline.design/":"https://relayserver.spline.design/";async function N3(i){try{return(await(await fetch(E3()+"session?uuidfile="+i)).json()).token}catch(t){console.error("Token generation error:",t)}}var Ih=class{constructor(t){this.value=0;this.frequencies=new Float32Array(0);let e=new AudioContext;this.source=e.createMediaStreamSource(t),this.analyser=e.createAnalyser(),this.source.connect(this.analyser),this.analyser.fftSize=8192,this.analyser.smoothingTimeConstant=.1}getFrequencies(t=-100,e=-30){if(!this.analyser)throw new Error("Not connected, please call .connect() first");return Rd.getFrequencies(this.analyser,44100,void 0,"voice",t,e)}update(){let t=this.getFrequencies(),e=t.values.reduce((r,o)=>r+o,0)/t.values.length;this.value=e,this.frequencies=t.values}disconnect(){this.source.disconnect(),this.analyser.disconnect()}},nc=class{constructor(t,e,r){this.data=t;this.id=e;this.shared=r;this.emitter=hi();this.rafId=0;this.voice=0;this.frequencies=new Float32Array([0]);this.events=[];this.isConnected=!1;this.isToolsAdded=!1;this.tools=[];this.onMessage=t=>{let e=JSON.parse(t.data);if(this.appendEvent(e),e.type==="session.created"&&this.onSessionCreated(),e.type==="response.done"&&e.response?.output){for(let r of e.response.output)if(r.type==="function_call")for(let[o,n]of this.tools)r.name===o.name&&(n(JSON.parse(r.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 t=this.analyser.value,e=this.analyser.frequencies;this.voice=t,this.frequencies=e,this.emitter.emit("voice",{value:t,frequencies:e})}}}update(t){this.data=t}setColorByName(t,e){let r=this.shared.getColorByName(t);if(r){let{id:o}=r,{r:n,g:a,b:s}=yb.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 t=await N3(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 Ih(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 r=await this.pc.createOffer();await this.pc.setLocalDescription(r);let s={type:"answer",sdp:await(await fetch(`https://api.openai.com/v1/realtime?model=${I3}`,{method:"POST",body:r.sdp,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/sdp"}})).text()};await this.pc.setRemoteDescription(s),this.animate()}appendEvent(t){this.events=[t,...this.events]}sendClientEvent(t){this.dc?(t.event_id=t.event_id||crypto.randomUUID(),this.dc.send(JSON.stringify(t)),this.appendEvent(t)):console.error("Failed to send message - no data channel available",t)}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 t=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: ${t}. 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 r=this.shared.scene,o=[];r.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(t,e){this.tools.push([t,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(t=>{t.track&&t.track.stop()}),this.pc?.close(),this.pc=void 0}computeAnalysisForListenerEvent(t){if(t.analysis==="range"){let e=this.frequencies.slice(...t.analysisRange);return e.reduce((r,o)=>r+o,0)/e.length}return t.analysis==="single"?this.frequencies[t.analysisSingle]:this.voice}on(t,e){this.emitter.on(t,e)}off(t,e){this.emitter.off(t,e)}};function pv(i){return"variable_"+i}var Nh=class extends Sd{constructor(e){super();this.shared=e}create(e){return new Ds(e,this.shared)}},qn=class{constructor(t,e={},r=!0,o=!1){this.data=t;this.needsJitter=r;this.enableLocalStorageForPersistentVariables=o;this.geometryCache=new ic(!0);this.geometryCache2=new ic(!1);this.imageHolderCache=new Nh(this);this.thisContext={scene:sv,shared:this};this.deletedMaterial=new Hn(Wt.defaultTwoLayerData("phong"),this.thisContext,"");this.deletedImage=new Vr(Gu.emptyImage,this);this.deletedVideo=new Vr(Ra.defaultVideo,this);this.materials={};this.images={};this.uiBuffers={};this.videos={};this.colors={};this.audios={};this.particles={};this.fonts={};this.timelineAnimations={};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(t)}setRequestRender(t){this._requestRender=t}getImageLoadPromises(){return Object.values(this.images).map(t=>t.loadPromise)}setEntityOpContext(t){this.entityOpContext=t}reset(t,e=!1,r=!1){this.data=t,this.resetLib(t.lib);for(let{id:o,data:n}of t.variables)this.addVariableHolder(o,n),e&&this.updateVariableHolder(o,n);for(let[o,n]of Object.entries(t.userAPIs??{}))this.addUserAPI(o,n);for(let[o,n]of Object.entries(t.userWebhooks??{}))this.addUserWebhook(o,n);if(!r){for(let[o,n]of Object.entries(t.images))this.addImage(o,n);for(let[o,n]of Object.entries(t.videos))this.addVideo(o,n)}for(let[o,n]of Object.entries(t.colors))this.addColor(o,n);for(let[o,n]of Object.entries(t.materials))this.addMaterial(o,n);for(let[o,n]of Object.entries(t.audios))this.addAudio(o,n);for(let[o,n]of Object.entries(t.particles))this.addParticle(o,n);for(let[o,n]of Object.entries(t.fonts))this.addFont(o,n);for(let[o,n]of Object.entries(t.timelineAnimations??{}))this.addAnimation(o,n)}addMaterial(t,e){if(this.materials[t]){let r=this.materials[t];r.reset(e,this.thisContext),r.dispose()}else{let r=new Hn(e,this.thisContext,t);this.materials[t]=r}}deleteMaterial(t){this.materials[t]&&(this.materials[t].nodeMaterialDispose(),delete this.materials[t])}getMaterial(t){let e=this.materials[t];return e}getMaterialOrDeletedPlaceholder(t){return this.materials[t]??this.deletedMaterial}material(t){return typeof t=="string"?this.getMaterialOrDeletedPlaceholder(t):t==null?(console.error("material is undefined or null"),this.deletedMaterial):new kn(t,this.thisContext)}getMaterials(){return this.materials}addImage(t,e){return this.images[t]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.images[t].updateSrc(e.data),!0):(this.images[t]=new Vr(e,this),!1)}deleteImage(t){let e=this.images[t];e&&(e.dispose(),delete this.images[t])}getDefaultImage(){return this.images.image_0}getImage(t){return this.images[t]??this.deletedImage}image(t){return typeof t=="string"?this.getImage(t):this.imageHolderCache.load(t)}addUIBuffer(t,e){return this.uiBuffers[t]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.uiBuffers[t].updateSrc(e),!0):(this.uiBuffers[t]=new Vr(e,this),!1)}uiBuffer(t){return this.uiBuffers[t]}addVideo(t,e){return this.videos[t]?(this.videos[t].updateSrc(e.data),!0):(this.videos[t]=new Vr(e,this),!1)}deleteVideo(t){let e=this.videos[t];e&&(e.dispose(),delete this.videos[t])}getVideo(t){return this.videos[t]??this.deletedVideo}video(t){return typeof t=="string"?this.getVideo(t):this.imageHolderCache.load(t)}addColor(t,e){return this.colors[t]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),"a"in e?this.colors[t].setRGBA(e.r,e.g,e.b,e.a):this.colors[t].setRGBA(e.r,e.g,e.b,1),!0):("a"in e?this.colors[t]=new Zi(e.r,e.g,e.b,e.a):this.colors[t]=new Zi(e.r,e.g,e.b,1),!1)}updateColor(t,e){if(this.colors[t]){this.onColorOrImageUpdate&&this.onColorOrImageUpdate();let r=this.colors[t];return this.colors[t].r=e.r??r.r,this.colors[t].g=e.g??r.g,this.colors[t].b=e.b??r.b,this.colors[t].a=e.a??r.a,!0}return!1}deleteColor(t){this.colors[t]&&delete this.colors[t]}getColor(t){return this.colors[t]}getColorNames(){return Object.values(this.data.colors).map(t=>t.name)}getColorByName(t){for(let e in this.data.colors)if(this.data.colors[e].name===t)return{color:this.colors[e],id:e}}color(t){let e;if(typeof t=="string"){let r=this.getColor(t);r?e=r:(console.warn("Tried to create color layer params with a color key that does not exist in the assets manager"),e=new qt(0,0,0,0))}else return"a"in t?new qt(t.r,t.g,t.b,t.a):new qt(t.r,t.g,t.b,1);return e}addAudio(t,e){this.audios[t]=e}getAudio(t){let e=this.audios[t];if(e instanceof Wn)return e;{let r=new Wn({src:e.data});return this.audios[t]=r,r}}addParticle(t,e){this.particles[t]=e}getParticle(t){return this.particles[t]}deleteParticle(t){this.particles[t]&&delete this.particles[t]}deleteAudio(t){let e=this.audios[t];e&&(e instanceof Wn&&e.dispose(),delete this.audios[t])}addFont(t,e){this.fonts[t]=new Id(e),this.fonts[t].loadingPromise.then(()=>this.requestRender())}getFont(t){return this.fonts[t]}deleteFont(t){this.fonts[t]&&delete this.fonts[t]}addAnimation(t,e){this.timelineAnimations[t]=e}getAnimation(t){return this.timelineAnimations[t]}deleteAniamtion(t){this.timelineAnimations[t]&&delete this.timelineAnimations[t]}dispose(){Object.keys(this.materials).forEach(e=>this.deleteMaterial(e)),this._requestRender=void 0,Object.values(this.audios).forEach(e=>{e instanceof Wn&&e.dispose()}),this.audios={},this.particles={},this.geometryCache.dispose(),this.geometryCache2.dispose()}addVariableHolder(t,e){if(this.variables[t]===void 0){let r=e.value;if(this.enableLocalStorageForPersistentVariables&&e.persistent){let o=localStorage.getItem(pv(t));r=o!==null?JSON.parse(o):e.value}return this.variables[t]={value:r,locations:[],persistent:e.persistent},"dynamicVariableType"in e&&(this.variables[t].dynamicVariablePlayState="Playing",this.variables[t].dynamicVariableToggleIsForward=void 0),!0}return this.variables[t].value=e.value,!1}resetDynamicVariablePlayState(){for(let t in this.variables)this.variables[t].dynamicVariablePlayState!==void 0&&(this.variables[t].dynamicVariablePlayState="Playing",this.variables[t].dynamicVariableToggleIsForward=void 0)}updateVariableHolder(t,e){this.updateVariable(t,e.value)}updateVariable(t,e){if(this.variables[t]===void 0)return!1;this.variables[t].value=e,this.enableLocalStorageForPersistentVariables&&this.variables[t].persistent&&localStorage.setItem(pv(t),JSON.stringify(e));let r=e;for(;typeof r=="string";)r=this.variables[r].value;let o=this.entityOpContext.scene;for(let n=this.variables[t].locations.length-1;n>=0;n--){let a=this.variables[t].locations[n];if(a[0]==="material"){let s=a[1],l=r,c={scene:o,shared:this},u=a.slice(2);o.traverseMaterial(p=>{let f=p.root??p;f.uuid===s&&f.onVariableUpdate(u,l,c)});let d=this.materials[s];d&&d.onVariableUpdate(u,l,c)}else{let s=o.find(a[0]);if(s===void 0){this.variables[t].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]]=r*Eh.MathUtils.DEG2RAD:s[a[a.length-1]]=r}if(s=o.find(a[0]),s.type==="ParticleEmitter"&&s.updateVariableState(r,a),Ge.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 d=u.dataPatched;u.chooseGeoemtryCache(this).forceDelete(d.geometry),u.createGeometryDelayed(this.entityOpContext),u.onVariableUpdate(!0),u.invalidateDownstreamBooleanData()})}else a[1]==="morphTargetInfluences"&&s.updateMorphInfluences(a[2],r)}}return this.requestRender(),!0}deleteVariable(t){this.variables[t]&&delete this.variables[t]}getVariable(t,e){if(Array.isArray(t)){if(t[0]==="mouse")return this.mouseProperty?.[t[1]]??0;if(t[0]==="raycast")return this.raycastProperty?.[t[1]]??0;let r=this.entityOpContext.scene.find(t[0]);if(t[1]==="width"||t[1]==="height"||t[1]==="depth")return r.geometry.userData.parameters[t[1]];for(let o=1;o<t.length;o++)r=r[t[o]];return t[1]==="rotation"&&(r*=Eh.MathUtils.RAD2DEG),r}for(let r in this.variables){if(e===void 0)break;let o=this.variables[r],n=o.locations?.findIndex(a=>dt.equal(a,e));n!==void 0&&n!==-1&&o.locations.splice(n,1)}if(typeof t=="string"){let r=t,o=t;do{if(o=r,this.variables[r]===void 0)break;let n=this.variables[r].value;e&&this.variables[o]!==void 0&&this.variables[o].locations.push(e),r=n}while(typeof r=="string");return r}else return t}getVariables(){return this.variables}getVariablesNames(){return this.data.variables.map(t=>t.data.name)}getVariableByName(t){for(let e of this.data.variables)if(e.data.name===t)return{variable:e.data,id:e.id}}getDynamicVariablePlayState(t){return this.variables[t]?.dynamicVariablePlayState}setDynamicVariablePlayState(t,e){this.variables[t]!==void 0&&(this.variables[t].dynamicVariablePlayState=e)}getDynamicVariableToggleIsForward(t){return this.variables[t]?.dynamicVariableToggleIsForward}setDynamicVariableToggleIsForward(t,e){this.variables[t]!==void 0&&(this.variables[t].dynamicVariableToggleIsForward=e)}resetLib(t){for(let[e,r]of Object.entries(t.images))this.addImage(e,r.asset);for(let[e,r]of Object.entries(t.audios))this.addAudio(e,r.asset);for(let[e,r]of Object.entries(t.particles))this.addParticle(e,r.asset);for(let[e,r]of Object.entries(t.colors))this.addColor(e,r.asset);for(let[e,r]of Object.entries(t.fonts))this.addFont(e,r.asset);for(let[e,r]of Object.entries(t.materials))this.addMaterial(e,r.asset);for(let[e,r]of Object.entries(t.videos))this.addVideo(e,r.asset);for(let[e,r]of Object.entries(t.variables))this.addVariableHolder(e,r.asset)}updateLibByOp(t,e){t.path[0]==="images"?t.path.length===1&&t.type===1?this.addImage(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteImage(t.id):t.path[0]==="videos"?t.path.length===1&&t.type===1?this.addVideo(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteVideo(t.id):t.path[0]==="audios"?t.path.length===1&&t.type===1?this.addAudio(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteAudio(t.id):t.path[0]==="particles"?t.path.length===1&&t.type===1?this.addParticle(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteParticle(t.id):t.path[0]==="colors"?t.path.length===1&&t.type===1?this.addColor(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteColor(t.id):t.path[0]==="materials"?t.path.length===1&&t.type===1?this.addMaterial(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteMaterial(t.id):t.path[0]==="fonts"?t.path.length===1&&t.type===1?this.addFont(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteFont(t.id):t.path[0]==="variables"?t.path.length===1&&t.type===1?this.addVariableHolder(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteVariable(t.id):t.path[0]==="components"&&e.updateByLibOp(t,this)}updateByOp(t,e,r){if(this.data=e,t.path[0]==="images")t.path.length===2&&t.type===0?t.props.data&&this.getImage(t.path[1]).updateSrc(t.props.data):t.path.length===1&&t.type===1?this.addImage(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteImage(t.id);else if(t.path[0]==="videos")t.path.length===2&&t.type===0?t.props.data&&this.getVideo(t.path[1]).updateSrc(t.props.data):t.path.length===1&&t.type===1?this.addVideo(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteVideo(t.id);else if(t.path[0]==="audios")t.path.length===2&&t.type===0?t.props.data&&this.addAudio(t.path[1],e.audios[t.path[1]]):t.path.length===1&&t.type===1?this.addAudio(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteAudio(t.id);else if(t.path[0]==="particles")t.path.length===2&&t.type===0?t.props.data&&this.addParticle(t.path[1],e.particles[t.path[1]]):t.path.length===1&&t.type===1?this.addParticle(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteParticle(t.id);else if(t.path[0]==="colors")t.path.length===2&&t.type===0?this.updateColor(t.path[1],t.props):t.path.length===1&&t.type===1?this.addColor(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteColor(t.id);else if(t.path[0]==="materials")t.path.length===1&&t.type===1?this.addMaterial(t.id,t.data):t.path.length===1&&t.type===2?this.deleteMaterial(t.id):t.path.length>1&&this.getMaterial(t.path[1]).updateByOp(vt.drop(t,2),e.materials[t.path[1]],{shared:this,scene:r});else if(t.path[0]==="fonts")t.path.length===2&&t.type===0?this.updateFont(t.path[1],t,r):t.path.length===1&&t.type===1?this.addFont(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteFont(t.id);else if(t.path[0]==="variables")t.path.length===2&&t.type===0?"value"in t.props?this.updateVariable(t.path[1],t.props.value):"persistent"in t.props&&(this.variables[t.path[1]].persistent=t.props.persistent):t.path.length===1&&t.type===4?this.addVariableHolder(t.id,t.data):t.path.length===1&&t.type===5&&this.deleteVariable(t.id);else if(t.path[0]==="userAPIs"){if(t.path.length===1&&t.type===1)this.addUserAPI(t.id,t.data);else if(t.path.length===1&&t.type===2)this.deleteUserAPI(t.id);else if(typeof t.path[1]=="string"){let o=e.userAPIs[t.path[1]];if(o){let n=t.type===0&&t.props.debounce===void 0,a=this.getUserAPI(t.path[1]);a instanceof nc?a.update(o):a?.update(o,this,n)}}}else if(t.path[0]==="userWebhooks"){if(t.path.length===1&&t.type===1)this.addUserWebhook(t.id,t.data);else if(t.path.length===1&&t.type===2)this.deleteUserWebhook(t.id);else if(typeof t.path[1]=="string"){let o=e.userWebhooks[t.path[1]];o&&this.getUserWebhook(t.path[1])?.update(o)}}else t.path[0]==="lib"&&this.updateLibByOp(vt.drop(t,1),r)}updateFont(t,e,r){if(e.props.url){let o=this.getFont(t),n={...this.data.fonts[t],url:e.props.url};o.update(n),o.loadingPromise.then(()=>this.requestRender()),r.updateFont(t,this)}}addUserAPI(t,e){return this.userAPIs[t]?(this.userAPIs[t].update(e,this),!0):this.openAIRealtime?.id===t?(this.openAIRealtime.update(e),!0):e.integration?.type==="VoiceAssistant"?(this.openAIRealtime=new nc(e,t,this),!1):(this.userAPIs[t]=new ad(t,e,this),!1)}getUserAPI(t){return this.openAIRealtime?.id===t?this.openAIRealtime:this.userAPIs[t]}getUserAPIs(){return this.userAPIs}deleteUserAPI(t){let e=this.userAPIs[t];e&&(e.dispose(),delete this.userAPIs[t])}addUserWebhook(t,e){return this.userWebhooks[t]?(this.userWebhooks[t].update(e),!0):(this.userWebhooks[t]=new Nd(t,e),!1)}getUserWebhook(t){return this.userWebhooks[t]}getUserWebhooks(){return this.userWebhooks}deleteUserWebhook(t){let e=this.userWebhooks[t];e&&(e.dispose(),delete this.userWebhooks[t])}get scene(){return this.entityOpContext.scene}},fv=new qn(qr.emptyData());var Er=class extends Xt{updateByPatchedOp(e,r,o){if(super.updateByPatchedOp(e,r,o),Jg(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(Ue(e.path,["material"])&&this.material instanceof Ir)"material"in r&&typeof r.material!="string"&&this.material.updateByOp(vt.drop(e,1),r.material,o);else if(Ue(e.path,["materials","*"])&&Array.isArray(this.material)){let n=e.path[1];if("materials"in r&&n<this.material.length){let a=r.materials[n];typeof a!="string"&&this.material[n].updateByOp(vt.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,r){super.updateState(e,r),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;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=r.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe,a),r.scene.markNeedsUpdateRendererDirty()),(e.geometry?.type==="NonParametricGeometry"||"materials"in e)&&("materials"in e&&e.materials!==void 0?(this.disposeMaterial(),this.material=e.materials.map(l=>r.shared.material(l).getFlavor(o.flatShading,o.side,o.wireframe)),r.scene.markNeedsUpdateRendererDirty()):"material"in e&&e.material!==void 0&&(this.disposeMaterial(),this.material=[r.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe)],r.scene.markNeedsUpdateRendererDirty()));let s=this.data;if(s.geometry?.type!=="NonParametricGeometry"&&"materials"in s&&s.materials!==void 0&&(this.disposeMaterial(),this.material=r.shared.material(s.materials[0]).getFlavor(o.flatShading,o.side,o.wireframe)),e.flatShading!==void 0||e.wireframe!==void 0||e.side!==void 0)if(Array.isArray(this.material))for(let l=0;l<this.material.length;l++)this.material[l]=this.material[l].getFlavor(o.flatShading,o.side,o.wireframe);else this.material=this.material.getFlavor(o.flatShading,o.side,o.wireframe,a)}disposeMaterial(){this.material&&Ic(this.material).forEach(e=>{e instanceof Ir&&(e instanceof Hn||e.nodeMaterialDispose())})}dispose(){this.disposeMaterial(),super.dispose()}};var zr=require("three");var hv=new zr.Vector3,mv=new zr.Vector4,yv=new zr.Vector4,_3=new zr.Vector3,gv=new zr.Matrix4,ht=class extends Er{constructor(e,r,o){super(e,r);this.data=r;this.isSkinnedMesh=!1;this.localGeometry=void 0,r.bindMode&&r.bindMatrix&&(this.bindMode=r.bindMode,this.bindMatrix=new zr.Matrix4().fromArray(r.bindMatrix),this.bindMatrixInverse=new zr.Matrix4)}chooseGeoemtryCache(e){return e.geometryCache}markGeometryAsReachable(e){this.geometryCreateDeleyed instanceof zr.BufferGeometry&&this.chooseGeoemtryCache(e).markAsReachable(this.dataPatched.geometry,this.geometryCreateDeleyed)}get geometry(){if(this.localGeometry!==void 0)return this.localGeometry;if(this.geometryCreateDeleyed instanceof qn){let e=this.geometryCreateDeleyed,r=this.chooseGeoemtryCache(e);this.geometryCreateDeleyed=r.get(this.dataPatched.geometry,e,this)}return this.geometryCreateDeleyed}set geometry(e){this.localGeometry=e}get is2DAndNoDepth(){let e=this.dataPatched.geometry;return vl.is2DParametricMesh(e.type)&&e.depth===0}get is2DType(){return vl.is2DParametricMesh(this.geometry.userData.type)}get isNonParametric(){return this.geometry.userData.type==="NonParametricGeometry"}updateByPatchedOp(e,r,o){super.updateByPatchedOp(e,r,o),Ue(e.path,["geometry"])&&this.updateByPatchedOpGeometry(vt.drop(e,1),r.geometry,o)}removeInteractionGeometry(e){this.localGeometry?.dispose(),this.localGeometry=void 0}updateGeometryInteractions(e,r){this.invalidateDownstreamBooleanData();let o=this.data.geometry.type;if(o==="NonParametricGeometry"||o==="SubdivGeometry"){let n=e;if(this.localGeometry===void 0){let f={...this.data.geometry,...n};this.localGeometry=zo(f,r,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,u=typeof a=="number"?a:1,d=typeof s=="number"?s:1,p=typeof l=="number"?l:1;c.sxPrev!==void 0&&jl(this.localGeometry.attributes,u/c.sxPrev,d/c.syPrev,p/c.szPrev),c.sxPrev=u,c.syPrev=d,c.szPrev=p}else{let n={...this.data.geometry,...e};this.localGeometry?.dispose(),this.localGeometry=zo(n,r,this.data.flatShading,this)}}refreshAttachedClonersInteractions(e){for(let r of this.attachedSurfaceCloners)r.update(e)}refreshAttachedCloners(e){for(let r of this.attachedSurfaceCloners)e.scene.addPendingUpdateCloner(r.object)}refreshAttachedPaths(e){for(let r of this.attachedPaths)e.scene.addPendingCommand(()=>r.updateShape())}createGeometryDelayed(e){this.geometryCreateDeleyed=e.shared,this.refreshAttachedCloners(e),this.refreshAttachedPaths(e)}updateByPatchedOpGeometry(e,r,o){let n=!1;e.type===0&&e.path.length===0&&Object.keys(e.props).includes("scaleBaked")&&this.geometryCreateDeleyed instanceof zt&&this.chooseGeoemtryCache(o.shared).mutateIfUnique(this.geometryCreateDeleyed.data,r)===this.geometryCreateDeleyed&&(n=!0,this.geometryCreateDeleyed.mutateDirectlyScaleBaked(r,e.props.scaleBaked),this.refreshAttachedCloners(o),this.refreshAttachedPaths(o)),n||(o.scene?.markGeometryCacheDirty(),this.createGeometryDelayed(o)),this.resetBBoxNeedsUpdate(),this.invalidateDownstreamBooleanData()}updateGeometryOnStateUpdate(e,r){this.createGeometryDelayed(r)}updateState(e,r){e.geometry!==void 0&&this.updateGeometryOnStateUpdate(e.geometry,r);let o=e.morphTargetInfluences;if(o){this.updateMorphTargets(),this.geometry.morphTargetsRelative=!0;for(let{data:{name:n,value:a}}of o)this.updateMorphInfluences(n,r.shared.getVariable(a,[this.uuid,"morphTargetInfluences",n]))}super.updateState(e,r)}updateMorphInfluences(e,r){if(this.morphTargetDictionary===void 0)return;let o=this.morphTargetDictionary[e];o!==void 0&&(this.morphTargetInfluences[o]=r)}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,r){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),r.set(o.width,o.height,o.depth??0).multiplyScalar(.5)):o.centerOffset?e.fromArray(o.centerOffset):e.setScalar(0),r.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,r){this.skeleton=e,this.isSkinnedMesh=!0,r===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),r=this.matrixWorld),this.bindMatrix.copy(r),this.bindMatrixInverse.copy(r).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(e){let r=new zr.Vector4,o=this.geometry.attributes.skinWeight;for(let n=0,a=o.count;n<a;n++){r.fromBufferAttribute(o,n);let s=1/r.manhattanLength();s!==1/0?r.multiplyScalar(s):r.set(1,0,0,0),o.setXYZW(n,r.x,r.y,r.z,r.w)}}boneTransform(e,r){let o=this.skeleton;if(o===void 0)return;let n=this.geometry;mv.fromBufferAttribute(n.attributes.skinIndex,e),yv.fromBufferAttribute(n.attributes.skinWeight,e),hv.copy(r).applyMatrix4(this.bindMatrix),r.set(0,0,0);for(let a=0;a<4;a++){let s=yv.getComponent(a);if(s!==0){let l=mv.getComponent(a);gv.multiplyMatrices(o.bones[l].matrixWorld,o.boneInverses[l]),r.addScaledVector(_3.copy(hv).applyMatrix4(gv),s)}}return r.applyMatrix4(this.bindMatrixInverse)}};function R3(i){if(i.geometry.attributes.extrudeNormal||!i.geometry.attributes.position||!i.geometry.attributes.normal)return;let t=new Map,e=i.geometry.attributes,r=e.position.array,o=e.normal.array,n=new Float32Array(r.length);for(let a=0;a<r.length;a+=3){let s=`${r[a]}_${r[a+1]}_${r[a+2]}`,l=new Gr.Vector3(o[a],o[a+1],o[a+2]);t.has(s)?t.get(s)?.normals.push(l):t.set(s,{normals:[l],result:new Gr.Vector3})}t.forEach((a,s)=>{for(let l of a.normals)a.result.add(l);a.result.divideScalar(a.normals.length)});for(let a=0;a<r.length;a+=3){let s=`${r[a]}_${r[a+1]}_${r[a+2]}`,l=t.get(s)?.result;l&&(n[a]=l.x,n[a+1]=l.y,n[a+2]=l.z)}i.geometry.setAttribute("extrudeNormal",new Gr.Float32BufferAttribute(n,3))}function L3(i){if(i.geometry.attributes.extrudeNormals||!i.geometry.attributes.position)return;let e=i.geometry.attributes.position.array,r=new Float32Array(e.length),o=new Gr.Vector3;for(let n=0;n<e.length;n+=3)o.set(e[n],e[n+1],e[n+2]).normalize(),r[n]=o.x,r[n+1]=o.y,r[n+2]=o.z;i.geometry.setAttribute("extrudeNormal",new Gr.Float32BufferAttribute(r,3))}function Ls(i){if(Array.isArray(i.material)){for(let t of i.material)if(t.getLayersOfType("outline").length===0)return}else if(!(i.material instanceof Ir)||i.material.getLayersOfType("outline").length===0)return;i instanceof ht&&i.is2DAndNoDepth?L3(i):R3(i)}function Bs(i){if(!i.geometry.attributes.position)return;let e=i.geometry.attributes.position.array,r=new Float32Array(e.length),o=parseInt(i.uuid.replace(/\D/g,"")),n=[Gr.MathUtils.seededRandom(o),Gr.MathUtils.seededRandom(o+1e4),Gr.MathUtils.seededRandom(o+2e4)];for(let a=0;a<e.length;a++)r[a]=n[a%3];i.geometry.setAttribute("randomColor",new Gr.BufferAttribute(r,3))}var Uo=new vi.Box3,ac=new vi.Vector3;function xv(i){let t=!1;return i.scene.objects.traverse((e,r)=>{r.type==="Mesh"&&r.geometry.type==="SubdivGeometry"&&(t=!0)}),t}var $n=class extends ht{constructor(e,r,o){super(e,r,o);this.data=r;this.hiddenMatrixOld=new vi.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,r){let o=this.geometry.userData.parameters;e.copy(this.originalGeometryNew.boundingSphere.center),r.set(o.width,o.height,o.depth??0).multiplyScalar(.5)}createGeometryByControls(e){if(this.skipReactionUpdate===!0)return;let r=this.localGeometry?.uuid,{originalGeometry:o,subdividedGeometry:n,subdivPointer:a}=zt.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,Ls(this),Bs(this),this.calcBoundingBox(),r&&(this.localGeometry.uuid=r)}updateState(e,r){if(super.updateState(e,r),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(r)}}updateMesh(e=!1){zt.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1,this.originalGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0),this.subdividedGeometry&&zt.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1,this.subdividedGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0)}updateTopology(){this.originalGeometry.dispose(),this.originalGeometry=zt.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1),this.subdividedGeometry&&(this.subdividedGeometry.dispose(),this.subdividedGeometry=zt.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1)),this.localGeometry=this.subdividedGeometry??this.originalGeometry}raycast(e,r){let o=this.localGeometry;this.localGeometry=this.originalGeometryNew,Xt.prototype.raycast.call(this,e,r),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 vi.Sphere,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let r=e.attributes.position,o=e.boundingSphere.center;Uo.setFromBufferAttribute(r),Uo.getCenter(o),e.boundingSphere.radius=o.distanceTo(Uo.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),Uo.getSize(ac),this.hasNonUniformScale&&ac.divide(this.scale);let n={width:ac.x,height:ac.y,depth:ac.z};return this.geometry.userData.parameters=n,n}updateBoundingSphere(e){let r=this.originalGeometry;Uo.min.set(e[0],e[2],e[4]),Uo.max.set(e[1],e[3],e[5]),this.hasNonUniformScale&&(Uo.min.applyMatrix4(this.shearScaleInv),Uo.max.applyMatrix4(this.shearScaleInv)),r.boundingSphere===null&&(r.boundingSphere=new vi.Sphere);let o=r.boundingSphere.center;Uo.getCenter(o),r.boundingSphere.radius=o.distanceTo(Uo.max)}freeSubdivPointer(){this.subdivPointer&&(zt.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0),this.localGeometry=void 0,this.originalGeometry?.dispose(),this.subdividedGeometry?.dispose()}dispose(){super.dispose(),this.freeSubdivPointer()}updateByPatchedOpGeometry(e,r,o){super.updateByPatchedOpGeometry(e,r,o),this.localGeometry&&this.createGeometryByControls(r)}};var ko=require("three"),bv=-1,B3=1,vv={x:[1,0,0],"-x":[-1,0,0],y:[0,1,0],"-y":[0,-1,0],z:[0,0,1],"-z":[0,0,-1]},Sv={polygon_center:0,edge:1,vertex:2},sc=(i,t)=>(e,r)=>!t||e===0||i===0?0:i*r/100,Ne=(i,t)=>{let e=Math.abs(t),r=e*-1;return(i-bv)*(e-r)/(B3-bv)+r},V3=new ko.Vector3,Ld=new ko.Vector3,z3=new ko.Vector3,G3=new ko.Vector3;function Vs(i,t){let e=z3.fromArray(i),r=G3.fromArray(t);Ld.copy(r).sub(e);let o=Ld.length();return Ld.normalize().multiplyScalar(o*.5),V3.copy(e).add(Ld).toArray()}var Kr=new ko.Triangle,Bd=new ko.Vector3,Vd=new ko.Vector3,Xn=new ko.Vector3;function wv(i){let t=[];for(let e=0;e<=i.index.count;e++)if(Bd.fromArray(i.index.array,e*3),Kr.setFromAttributeAndIndices(i.attributes.position,Bd.x,Bd.y,Bd.z),Kr.getNormal(Vd),Kr.getMidpoint(Xn),!(isNaN(Xn.x)||isNaN(Xn.y)||isNaN(Xn.z))){let{a:r,b:o,c:n}=Kr,a=r.toArray(),s=o.toArray(),l=n.toArray(),c=r.distanceTo(o),u=o.distanceTo(n),d=n.distanceTo(r),p=Vs(a,s),f=Vs(s,l),h=Vs(l,a),m=[c,u,d],y=Math.max(...m),g=m.filter(P=>Math.round(P)===Math.round(y)).length>1,b=[],w=Kr.getMidpoint(Xn).toArray();y===c&&!g&&(b=[f,h,h],w=p),y===u&&!g&&(b=[p,h,h],w=f),y===d&&!g&&(b=[p,f,f],w=h),g&&(b=[p,f,h]),t.push({vertices:[a,s,l],faceCenters:b,midpoint:w,norm:Kr.getNormal(Vd).toArray()})}return t}function Pv(i){let t=[],{position:e}=i.attributes;for(let r=0;r<e.count;r++){Kr.setFromAttributeAndIndices(e,r*3,r*3+1,r*3+2),Kr.getNormal(Vd),Kr.getMidpoint(Xn);let o=Kr.a.toArray(),n=Kr.b.toArray(),a=Kr.c.toArray();t.push({vertices:[o,n,a],faceCenters:[Vs(o,n),Vs(n,a),Vs(a,o)],midpoint:Xn.toArray(),norm:Vd.toArray()})}return t}var F3=4,j3=.5,_h=i=>.5*(1-Math.cos(i*Math.PI)),Rh=class{constructor(){this.perlin=new Array(4095+1)}noise(t,e=0,r=0){if(this.perlin==null){this.perlin=new Array(4095+1);for(let g=0;g<4095+1;g++)this.perlin[g]=Math.random()}t<0&&(t=-t),e<0&&(e=-e),r<0&&(r=-r);let o=Math.floor(t),n=Math.floor(e),a=Math.floor(r),s=t-o,l=e-n,c=r-a,u,d,p=0,f=.5,h,m,y;for(let g=0;g<F3;g++){let b=o+(n<<4)+(a<<8);u=_h(s),d=_h(l),h=this.perlin[b&4095],h+=u*(this.perlin[b+1&4095]-h),m=this.perlin[b+16&4095],m+=u*(this.perlin[b+16+1&4095]-m),h+=d*(m-h),b+=256,m=this.perlin[b&4095],m+=u*(this.perlin[b+1&4095]-m),y=this.perlin[b+16&4095],y+=u*(this.perlin[b+16+1&4095]-y),m+=d*(y-m),h+=_h(c)*(m-h),p+=h*f,f*=j3,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 p}noiseSeed(t){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(t),this.perlin=new Array(4095+1);for(let r=0;r<4095+1;r++)this.perlin[r]=e.rand()}},Ov=Rh;var zs=require("three");var Tv=new zs.Vector3,Cv=new zs.Matrix4,Av=new zs.Ray;function Mv(i){let t=!1;return i.scene.objects.traverse((e,r)=>{r.type==="Mesh"&&(r.geometry.type==="TextGeometry"||r.geometry.type==="InputGeometry")&&(t=!0)}),t}var rn=class extends ht{constructor(e,r,o){super(e,r,o);this.data=r}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,typeof e.geometry.height=="number"?e.geometry.height:1,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,r){let{matrixWorld:o}=this;if(!(isNaN(e.ray.origin.x)||this.scale.x===0||this.scale.y===0||this.scale.z===0)&&(Cv.copy(o).invert(),Av.copy(e.ray).applyMatrix4(Cv),Av.intersectBox(this.singleBBox,Tv))){let n=Tv.applyMatrix4(o),a=e.ray.origin.distanceTo(n);r.push({distance:a,point:n.clone(),object:this})}}};var br=1e-4,Ho,Nv,Dv,_v,Iv=new tt.Vector3,Ev=new tt.Vector3;ld.then(i=>{Ho=i,Nv=[Ho.get_face_center,Ho.get_edge_midpoint,Ho.get_vertex_position],Dv=[Ho.get_face_normal,Ho.get_edge_normal,Ho.get_vertex_normal],_v=[Ho.face_count,Ho.edge_count,Ho.vertex_count]});var U3=new tt.Matrix4,k3=new tt.Matrix4,on=new tt.Vector3,zd=new tt.Vector3,lc=new tt.Vector3,Lh=new tt.Vector3,H3=new tt.Vector3,W3=new tt.Vector3;function St(i,t){return[typeof i?.[0]=="number"?i[0]:typeof i?.[0]=="string"&&t?parseFloat(String(t.shared.getVariable(i[0])??"0")):0,typeof i?.[1]=="number"?i[1]:typeof i?.[1]=="string"&&t?parseFloat(String(t.shared.getVariable(i[1])??"0")):0,typeof i?.[2]=="number"?i[2]:typeof i?.[2]=="string"&&t?parseFloat(String(t.shared.getVariable(i[2])??"0")):0]}var Bh=class{constructor(t,e){this.data=t;this.is3D=e;this.perlin=new Ov;t.noiseType==="perlin"?(this.perlin.noiseSeed(t.seed),e?this.noise=(o,n,a)=>this.perlin.noise(o,n,a):this.noise=o=>this.perlin.noise(o)):e?this.noise=cx((0,Gd.default)(t.seed)):this.noise=lx((0,Gd.default)(t.seed??""))}},nn=class extends Ha(tt.Object3D){constructor(e,r){super();this.parameters=r;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 r of this.children)r instanceof co&&r.expand()}invalidateTransform(e){this.matrixWorldNeedsUpdate=!0,this.traverse(r=>{r instanceof co&&r.object===e&&(r.matrixWorldNeedsUpdate=!0)})}onObjUpdateMatrix(){this.parameters.type!=="toObject"&&(this.matrixWorldNeedsUpdate=!0)}update(e){switch(this._updateCount(e),this.parameters.type){case"radial":this._updateRadial(this.parameters,e);break;case"linear":this._updateLinear(this.parameters,e);break;case"grid":this._updateGrid(this.parameters,e);break;case"toObject":this._updateToObject(this.parameters,e)}for(let r of this.children)r.updateMatrix(),r.hasNonUniformScale&&(r.updateMatrixWorld(),r.updateMatrixWorldSVD())}_updateCount(e,r){let o;if(r!==void 0)o=r;else{let n=St(this.parameters.grid.count,e);o=this.parameters.type==="grid"?Math.round(n[0])*Math.round(n[1])*Math.round(n[2]):this.parameters.count}if(this.parameters.type==="toObject"){if(!this.parameters.toObject.object)o=0;else if(r===void 0&&this.parameters.toObject.spreadType!=="random")return}if(this.parameters.type==="toObject"&&this.objectForSample){let n=this.children;if(n.length===o)return;if(n.length<o)for(let a=0,s=o-n.length;a<s;++a){let l=new co(this.object);l.expand(),this.add(l)}else for(let a=0,s=n.length-o;a<s;++a)this.remove(n[a])}else{if(this.children.length===o)return;if(this.children.length<o)for(let n=0,a=o-this.children.length;n<a;++n){let s=new co(this.object);s.expand(),this.add(s)}else for(let n=0,a=this.children.length-o;n<a;++n)this.remove(this.children[n])}}getRandom(e,r=!1){return(this.random===null||this.random.data.seed!==e.seed||this.random.is3D!==r)&&(this.random=new Bh(e,r)),this.random}_updateRadial(e,r){let o=e.radial,n=o.start*tt.MathUtils.DEG2RAD,a=o.end*tt.MathUtils.DEG2RAD,s=n-a,l=St(o.rotation,r),c=new tt.Euler(l[0],l[1],l[2]),u;switch(o.axis){case"z":u=new tt.Vector3(0,0,1);break;case"y":u=new tt.Vector3(0,1,0);break;default:case"x":u=new tt.Vector3(1,0,0);break}let d=e.randomnessObject??No.defaultData([1,1,1]).randomnessObject,p=this.getRandom(d),f=sc(d.strength,this.parameters.randomness);for(let[h,m]of this.children.entries()){let y=h*(d.freqScale/10)+d.movement,g=p.noise(y,y,y),b=h+1,w=St(o.scale,r),P=St(d.scale,r);m.scale.x=w[0]+f(b,Ne(g,P[0]))||br,m.scale.y=w[1]+f(b,Ne(g,P[1]))||br,m.scale.z=w[2]+f(b,Ne(g,P[2]))||br,m.position.setScalar(0);let S=s/e.count*h-n;switch(o.axis){case"x":m.rotation.set(0,S,0);break;case"y":m.rotation.set(0,0,S);break;case"z":m.rotation.set(S,0,0);break}m.translateOnAxis(u,o.radius);let T=St(o.position,r),A=St(d.position,r);m.position.x+=T[0]+f(b,Ne(g,A[0])),m.position.y+=T[1]+f(b,Ne(g,A[1])),m.position.z+=T[2]+f(b,Ne(g,A[2]));let x=St(d.rotation,r),N=f(b,Ne(g,x[0])),E=f(b,Ne(g,x[1])),M=f(b,Ne(g,x[2]));o.alignment===!0?(m.rotation.x+=c.x+N,m.rotation.y+=c.y+E,m.rotation.z+=c.z+M):m.rotation.set(c.x+N,c.y+E,c.z+M)}}_updateLinear(e,r){if(e.type!=="linear")throw new Error;let o=e.linear,n=St(o.rotation,r),a=St(o.scale,r),s=St(o.position,r),l=new tt.Euler(n[0]??0,n[1]??0,n[2]??0),c=e.randomnessObject??No.defaultData([1,1,1]).randomnessObject,u=St(c.rotation,r),d=St(c.scale,r),p=St(c.position,r),f=this.getRandom(c),h=sc(c.strength,this.parameters.randomness);for(let[m,y]of this.children.entries()){let g=m*(c.freqScale/10)+c.movement,b=f.noise(g,g,g),w=m+1,P=h(w,Ne(b,u[0])),S=h(w,Ne(b,u[1])),T=h(w,Ne(b,u[2]));y.scale.x=1+(a[0]-1)*m+h(w,Ne(b,d[0]))||br,y.scale.y=1+(a[1]-1)*m+h(w,Ne(b,d[1]))||br,y.scale.z=1+(a[2]-1)*m+h(w,Ne(b,d[2]))||br,y.rotation.x=l.x*m+P,y.rotation.y=l.y*m+S,y.rotation.z=l.z*m+T,y.position.x=s[0]*m+h(w,Ne(b,p[0])),y.position.y=s[1]*m+h(w,Ne(b,p[1])),y.position.z=s[2]*m+h(w,Ne(b,p[2]))}}_updateGrid(e,r){let o=0,n=e.grid,a=e.randomnessObject??No.defaultData([1,1,1]).randomnessObject,s=St(a.scale,r),l=St(a.rotation,r),c=St(a.position,r),u=this.getRandom(a,!0),d=sc(a.strength,this.parameters.randomness),p=St(n.count,r),f=St(n.size,r);if(n.useCenter===!0){let h={x:p[0]%2===0?2:1,y:p[1]%2===0?2:1,z:p[2]%2===0?2:1},m=new tt.Vector3(f[0]*(p[0]-h.x)*.5,f[1]*(p[1]-h.y)*.5,f[2]*(p[2]-h.z)*.5);for(let y=0;y<p[0];y++)for(let g=0;g<p[1];g++)for(let b=0;b<p[2];b++){let w=u.noise((y+1)*(a.freqScale/10)+a.movement,(g+1)*(a.freqScale/10)+a.movement,(b+1)*(a.freqScale/10)+a.movement),P=this.children[o++];P.scale.x=1+d(o,Ne(w,s[0]))||br,P.scale.y=1+d(o,Ne(w,s[1]))||br,P.scale.z=1+d(o,Ne(w,s[2]))||br;let S=d(o,Ne(w,l[0])),T=d(o,Ne(w,l[1])),A=d(o,Ne(w,l[2]));P.rotation.set(S,T,A),P.position.x=f[0]*y-m.x+d(o,Ne(w,c[0])),P.position.y=f[1]*g-m.y+d(o,Ne(w,c[1])),P.position.z=f[2]*b-m.z+d(o,Ne(w,c[2]))}}else for(let h=0;h<p[0];h++)for(let m=0;m<p[1];m++)for(let y=0;y<p[2];y++){let g=u.noise((h+1)*(a.freqScale/10)+a.movement,(m+1)*(a.freqScale/10)+a.movement,(y+1)*(a.freqScale/10)+a.movement),b=this.children[o++];b.scale.x=1+d(o,Ne(g,s[0]))||br,b.scale.y=1+d(o,Ne(g,s[1]))||br,b.scale.z=1+d(o,Ne(g,s[2]))||br;let w=d(o,Ne(g,l[0])),P=d(o,Ne(g,l[1])),S=d(o,Ne(g,l[2]));b.rotation.set(w,P,S),b.position.x=f[0]*h+d(o,Ne(g,c[0])),b.position.y=-f[1]*m+d(o,Ne(g,c[1])),b.position.z=-f[2]*y+d(o,Ne(g,c[2]))}}_updateToObject(e,r){if(e.type!=="toObject")throw new Error;let{toObject:o}=e,n=St(o.rotation,r),a=St(o.position,r),s=St(o.scale,r),l=new tt.Euler(n[0],n[1],n[2]),c=e.randomnessObject??No.defaultData([1,1,1]).randomnessObject,u=St(c.rotation,r),d=St(c.position,r),p=St(c.scale,r),f=this.getRandom(c),h=sc(c.strength,this.parameters.randomness);if(!o.object){for(let[,w]of this.children.entries())w.position.set(0,0,0),w.scale.setScalar(1),w.rotation.set(0,0,0);this.objectForSample=void 0;return}if(!this.objectForSample)return;if(this.objectForSample instanceof rn)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 m=this.getSubdivData();if(m.length>0){let w=Math.round(m.length*o.count/100);this._updateCount(r,w)}else{let w=this.objectForSample.geometry.getAttribute("position");if(!w||isNaN(w.count)||w.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 y=new Hu(this.objectForSample).build(),g=vv[o.axis],b=this.children;y.setRandomGenerator((0,Gd.default)(this.object.uuid+o.seed));for(let[w,P]of b.entries()){let S=w*(c.freqScale/10)+c.movement,T=f.noise(S,S,S),A=w+1,x=h(A,Ne(T,u[0])),N=h(A,Ne(T,u[1])),E=h(A,Ne(T,u[2]));o.spreadType==="random"?y.sample(lc,Lh):(m.length&&(lc.fromArray(m[w].pos),Lh.fromArray(m[w].norm)),this.objectForSample instanceof $n&&lc.applyMatrix4(U3.copy(this.objectForSample.matrixWorld).invert())),lc.applyMatrix4(this.object.hiddenMatrix.clone().invert()),P.position.copy(lc),on.fromArray(g);let M=o.align==="normal"?Lh:this.object.getWorldDirection(W3),D=zd.fromArray(a);zd.x+=h(A,Ne(T,d[0])),zd.y+=h(A,Ne(T,d[1])),zd.z+=h(A,Ne(T,d[2]));let _=Math.acos(M.dot(on)),R=H3.crossVectors(on,M).normalize(),V=k3.makeRotationAxis(R,_),U=M.clone().cross(this.object.up).normalize(),B=U.clone().cross(M).normalize(),q=new tt.Matrix4().makeBasis(U,M,B),j=new tt.Vector3(on.y,on.z,on.x).normalize(),F=j.clone().cross(on).normalize(),H=new tt.Matrix4().makeBasis(j,on,F).invert(),W=new tt.Matrix4().multiplyMatrices(q,H);P.rotation.setFromRotationMatrix(W),D.applyMatrix4(V),P.position.add(D),P.rotation.x=P.rotation.x+l.x+x,P.rotation.y=P.rotation.y+l.y+N,P.rotation.z=P.rotation.z+l.z+E,P.scale.setScalar(1),P.scale.x=P.scale.x+s[0]+h(A,Ne(T,p[0]))||br,P.scale.y=P.scale.y+s[1]+h(A,Ne(T,p[1]))||br,P.scale.z=P.scale.z+s[2]+h(A,Ne(T,p[2]))||br,P.scale.multiply(this.object.scale),P.hiddenMatrix=this.object.hiddenMatrix}}getSubdivData(){if(!this.objectForSample)return[];let e=this.parameters.toObject.spreadType,r=new Map,o=(a,s)=>{let l=Math.round(a[0]*1e4)+"_"+Math.round(a[1]*1e4)+"_"+Math.round(a[2]*1e4),c=r.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):r.set(l,{pos:[...a],norm:[...s],count:1})};if(e==="random")return[];if(this.objectForSample instanceof $n){let a=this.objectForSample,s=Sv[e],l=_v[s],c=Nv[s],u=Dv[s],d=l(a.subdivPointerNew);for(let p=0;p<=d-1;p++){let f=c(a.subdivPointerNew,p),h=u(a.subdivPointerNew,p);Iv.fromArray(f).applyMatrix4(a.matrixWorld),Ev.fromArray(h),o(Iv.toArray(),Ev.toArray())}}else(this.objectForSample.geometry.index?wv(this.objectForSample.geometry):Pv(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(r.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,r){if(this.parameters=ti(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=r.scene.find(this.parameters.toObject.object);o instanceof Xt?this.objectForSample=o:this.objectForSample=void 0,this.matrix=new tt.Matrix4,this.hiddenMatrix=new tt.Matrix4,this.matrixWorldNeedsUpdate=!0,this.matrixAutoUpdate=!1,o&&o.add(this)}this.update(r)}get pendingMediaLoad(){return this._pendingMediaLoad}};var oo=require("three");var xt=require("three");var cr=require("three");var Rv=require("three"),Wo=i=>{var t;return t=class extends i{},t.geometryHelper=new Rv.BoxGeometry(30,30,30),t};var fr=require("three"),Fd=new fr.Ray,Vh=new fr.Sphere,Lv=new fr.Matrix4,qo=(i,t,e,r,o=!1,n=i)=>{let a=t,s=n.matrixWorld;if(a.boundingSphere===null&&a.computeBoundingSphere(),Vh.copy(a.boundingSphere),Vh.applyMatrix4(s),e.ray.intersectsSphere(Vh)===!1||(Lv.copy(s).invert(),Fd.copy(e.ray).applyMatrix4(Lv),a.boundingBox!==null&&Fd.intersectsBox(a.boundingBox)===!1))return;let l,c,u,d,p=a.index,f=a.attributes.position,h=a.drawRange,m,y;if(o===!1){let b=Math.max(0,h.start),w=Math.min(p.count,h.start+h.count);for(m=b,y=w;m<y;m+=3)if(c=p.getX(m),u=p.getX(m+1),d=p.getX(m+2),l=g(i,e,Fd,f,c,u,d),l){l.faceIndex=Math.floor(m/3),r.push(l);return}}else{let w=a.attributes.position,P=new fr.Vector3,S=new fr.Vector3,T=new fr.Vector3,A=new fr.Vector3,x=2,E=1/((n.scale.x+n.scale.y+n.scale.z)/3),M=E*E,D=Math.max(0,h.start),_=Math.min(w.count,h.start+h.count);for(let R=D,V=_-1;R<V;R+=x){if(P.fromBufferAttribute(w,R),S.fromBufferAttribute(w,R+1),Fd.distanceSqToSegment(P,S,A,T)>M)continue;A.applyMatrix4(n.matrixWorld);let B=e.ray.origin.distanceTo(A);B<e.near||B>e.far||r.push({distance:B,point:T.clone().applyMatrix4(n.matrixWorld),object:i})}}function g(b,w,P,S,T,A,x){let N=new fr.Vector3,E=new fr.Vector3,M=new fr.Vector3,D=new fr.Vector3,_=new fr.Vector3;if(N.fromBufferAttribute(S,T),E.fromBufferAttribute(S,A),M.fromBufferAttribute(S,x),P.intersectTriangle(N,E,M,!1,D)===null)return null;_.copy(D),_.applyMatrix4(b.matrixWorld);let V=w.ray.origin.distanceTo(_);return V<w.near||V>w.far?null:{faceIndex:1,distance:V,point:_.clone(),object:b}}};var jd=new cr.Vector3,Qr=new cr.Camera,zh=class extends cr.LineSegments{constructor(e){let r=new cr.BufferGeometry,o=new cr.LineBasicMaterial({color:16777215,vertexColors:!0,toneMapped:!1}),n=[],a=[],s={},l=new cr.Color(15711266),c=new cr.Color(15711266),u=new cr.Color(2857471);d("n1","n2",l),d("n2","n4",l),d("n4","n3",l),d("n3","n1",l),d("f1","f2",l),d("f2","f4",l),d("f4","f3",l),d("f3","f1",l),d("n1","f1",l),d("n2","f2",l),d("n3","f3",l),d("n4","f4",l),d("p","n1",c),d("p","n2",c),d("p","n3",c),d("p","n4",c),d("u1","u2",u),d("u2","u3",u),d("u3","u1",u);function d(f,h,m){p(f,m),p(h,m)}function p(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)}r.setAttribute("position",new cr.Float32BufferAttribute(n,3)),r.setAttribute("color",new cr.Float32BufferAttribute(a,3));super(r,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,r=this.pointMap,o=!0;Qr.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;wo("n1",r,e,Qr,-n,-a,s),wo("n2",r,e,Qr,n,-a,s),wo("n3",r,e,Qr,-n,a,s),wo("n4",r,e,Qr,n,a,s);let l=s;wo("f1",r,e,Qr,-n,-a,l),wo("f2",r,e,Qr,n,-a,l),wo("f3",r,e,Qr,-n,a,l),wo("f4",r,e,Qr,n,a,l);let c=l,u=.5;wo("u1",r,e,Qr,n*.7*u,a*1.1,c),wo("u2",r,e,Qr,-n*.7*u,a*1.1,c),wo("u3",r,e,Qr,0,a*(1.1+.9*u),c),e.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}};function wo(i,t,e,r,o,n,a){jd.set(o,n,a).unproject(r);let s=t[i];if(s!==void 0){let l=e.getAttribute("position");for(let c=0,u=s.length;c<u;c++)l.setXYZ(s[c],jd.x,jd.y,jd.z)}}var Ud=class extends Wo(zh){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,r){qo(this.object,this.geometry,e,r,!0)}};var cc=require("three");var kd;(t=>t.is=e=>"objectHelper"in e)(kd||(kd={}));var Zr=(i,t)=>class extends $a(i){constructor(){super(...arguments);this.objectHelper=new t(this);this.gizmos={}}get geometryHelper(){return t.geometryHelper}raycast(o,n){this.objectHelper.raycast(o,n)}showGizmos(){for(let o in this.gizmos){let n=this.gizmos[o];n instanceof cc.Box3Helper&&(n.visible=!0)}}updateEntityBoxSize(o,n){this.objectHelper.visible&&this.geometryHelper instanceof cc.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 cc.Box3Helper&&(n.visible=!1)}}};var Hd=790,Gs=new xt.Vector3,Gh=new xt.Vector3,Fh=new xt.Quaternion,jh=new xt.Vector3,uc=new xt.Vector3,Uh=new xt.Vector3,Si=class extends Zr(xt.Camera,Ud){constructor(e="",r={...En.defaultData,name:""}){super();this._cameraType="OrthographicCamera";this.targetOffset=Fi.DefaultTargetOffset;this.isUpVectorFlipped=!1;this.angleOffsetFromUp=0;this.wasMovedByUser=!1;this.wasMovedBySwitchCameraAction=!1;this.super_Entity(e,r),this.previousProjectionMatrix=new xt.Matrix4,this.matrixAutoUpdate=!0,this.width=window.innerWidth,this.height=window.innerHeight;let o=this.width,n=this.height;this.orthoCamera=new xt.OrthographicCamera(o*-.5,o*.5,n*.5,n*-.5,-5e4,1e4),this.perspCamera=new xt.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,r){e==="PerspectiveCamera"?this.perspCamera.near=r:this.orthoCamera.near=r}setZoom(e,r){r>=0&&(e==="PerspectiveCamera"?this.perspCamera.zoom=r:this.orthoCamera.zoom=r)}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,r,o){typeof e=="number"&&(e=new xt.Vector3(e,r,o)),super.lookAt(e),this.getWorldPosition(Gs),this.targetOffset=Gs.distanceTo(e)}getTarget(e=new xt.Vector3){return this.getWorldDirection(Gh),this.getWorldPosition(Gs),Gh.multiplyScalar(this.targetOffset),e.copy(Gs).add(Gh),e}getDistanceToTarget(){let e=this.getTarget();return this.getWorldPosition(Gs),Gs.distanceTo(e)}updateUp(){this.getWorldQuaternion(Fh),jh.set(0,0,1).applyQuaternion(Fh),uc.copy(xt.Object3D.DEFAULT_UP),this.isUpVectorFlipped&&uc.negate(),uc.applyQuaternion(Fh),Uh.copy(xt.Object3D.DEFAULT_UP).projectOnPlane(jh),this.angleOffsetFromUp=Uh.angleTo(uc),this.angleOffsetFromUp*=Uh.cross(uc).dot(jh)>=0?1:-1}updateTransformState(e,r){let o=super.updateTransformState(e,r);return e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateUp(),o}getViewFrontToObject(e){let r=e.getWorldPosition(new xt.Vector3),n=e.getWorldDirection(new xt.Vector3).multiplyScalar(this.targetOffset);return{position:r.clone().add(n),target:r}}getViewToTarget(e){let o=this.getWorldDirection(new xt.Vector3).multiplyScalar(this.targetOffset);return{position:e.clone().sub(o),target:e}}getViewToObject(e){let r=new xt.Vector3;return e.getWorldPosition(r),this.getViewToTarget(r)}setViewplaneSize(e,r,o=!1){if(this.aspect=e/r,o){let n=e>r?this.aspect:1,a=e>r?1:this.aspect;this.left=-Hd*.5*n,this.right=Hd*.5*n,this.top=Hd*.5*(1/a),this.bottom=-Hd*.5*(1/a)}else this.left=-e*.5,this.right=e*.5,this.top=r*.5,this.bottom=-r*.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,r,o,n,a,s){this._cameraType==="PerspectiveCamera"?this.perspCamera.setViewOffset(e,r,o,n,a,s):this.orthoCamera.setViewOffset(e,r,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,r){super.updateWorldMatrix(e,r),this.matrixWorldInverse.copy(this.matrixWorld).invert()}copy(e,r){return super.copy(e,r),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 r={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 Pa(r,e)}updateCameraSubtype(e,r){let o=e==="perspective"?"PerspectiveCamera":"OrthographicCamera";r.zoom!==void 0&&this.setZoom(o,r.zoom),r.near!==void 0&&this.setNear(o,r.near),r.fov!==void 0&&o==="PerspectiveCamera"&&(this.fov=r.fov)}updateState(e,r){this.updateCameraState(e,r)}updateCameraState(e,r){this.updateState_Entity(e,r),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.map(o=>typeof o=="number"?o:0)),e.targetOffset!==void 0&&(this.targetOffset=e.targetOffset),e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateProjectionMatrix()}updateByPatchedOp(e,r,o){super.updateByPatchedOp(e,r,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 X3=require("three");var an=require("three");var Fs=new an.Matrix4,$3=new an.Matrix4;var Nr=class extends Er{constructor(e,r,o){super(e,r);this.data=r;this.meshSetAddresses=[];this.needsTransformForDownstream=!1;this.geometry=new an.BufferGeometry;this.onAfterRender=(e,r,o,n,a,s)=>{super.onAfterRender(e,r,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,r,o){super.updateByPatchedOp(e,r,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,r=!0){if(this.booleanMeshSetAddress!==-1&&!e)return;for(let n=0;n<this.children.length;n++){let a=this.children[n];a instanceof Nr&&a.dataPatched.visible===!0&&a.recomputeBoolean(e===!0,r)}this.meshSetAddresses=[];for(let n=0;n<this.children.length;n++){let a=this.children[n];if(a instanceof Xt&&a.dataPatched.visible===!0&&a.geometry.attributes.position?.count>0&&a.geometry.drawRange.count>0&&a.booleanMeshSetAddress!==0){Fs.multiplyMatrices(a.hiddenMatrix,a.matrix).multiply(a.pivotMatrix);try{if(a.booleanMeshSetAddress===-1){if((a.geometry.index??a.geometry.getAttribute("position")).count/3<15e5&&(a.booleanMeshSetAddress=Xr.getMeshSet(a.geometry,e===!0,r)),a.booleanMeshSetAddress===-1)return;Xr.transformMeshSet(a.booleanMeshSetAddress,Fs),a.booleanMatrixInvOld.copy(Fs).invert(),a.booleanWasTransformed=!1}else a instanceof Nr&&a.needsTransformForDownstream===!0?(Xr.transformMeshSet(a.booleanMeshSetAddress,Fs),a.needsTransformForDownstream=!1):a.booleanWasTransformed===!0&&(Xr.transformMeshSet(a.booleanMeshSetAddress,$3.multiplyMatrices(Fs,a.booleanMatrixInvOld)),a.booleanMatrixInvOld.copy(Fs).invert(),a.booleanWasTransformed=!1)}catch(s){console.error(s),a.booleanMeshSetAddress=0,a.geometry.userData.booleanOperationDidFail=!0;continue}Xr.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 an.Float32BufferAttribute([],0)),this.geometry.setDrawRange(0,0);return}if(e===!0)return Xr.calcBooleanTopological(this.meshSetAddresses,this.booleanOp);let o=this.geometry;o.dispose(),this.geometry=new an.BufferGeometry,this.geometry.userData=o.userData,this.geometry.boundingSphere=o.boundingSphere;try{this.booleanMeshSetAddress=Xr.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,Ls(this),Bs(this)}dispose(){super.dispose(),this.geometry.dispose()}};var Vv=require("three");var Bv;(t=>{function i(e){return Ge.is(e)&&e instanceof Vv.Light}t.is=i})(Bv||(Bv={}));var js=(i,t)=>class extends Zr(i,t){updateState_Light(r,o){this.updateState_Entity(r,o),r.color!==void 0&&(this.color=o.shared.color(r.color)),r.intensity!==void 0&&(this.intensity=r.intensity),r.depth!==void 0&&(this.shadow.camera.far=r.depth,this.shadow.needsUpdate=!0),r.shadows!==void 0&&(this.castShadow=r.shadows)}};var sn=i=>i instanceof Xt,dc=i=>i!==null&&i instanceof Nr;var pc=i=>kd.is(i);var Fv=require("three");var $o=require("three");var Y3=new $o.Vector3(1,1,1),zv=new $o.Vector3,K3=new $o.Vector3,Gv=new $o.Quaternion,Jr=class extends Wo($o.AxesHelper){constructor(e,r=15){super(r);this.object=e;this.dummy=new $o.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,r){qo(this.object,Jr.geometryHelper,e,r,!1,this.dummy)}update(){}updateMatrix(){}updateMatrixWorld(e){this.object.matrixWorld.decompose(zv,Gv,K3),this.matrix.compose(zv,Gv,Y3),super.updateMatrixWorld(e)}updateWorldMatrix(e,r){}};var ln=class extends Zr(Fv.Group,Jr){constructor(t,e){super(),this.super_Entity(t,e),this.objectHelper.update()}updateState(t,e){this.updateState_Entity(t,e),"buffer"in t&&Object.keys(t).length===1&&e.scene.reloadSplats()}};var jv=require("three");var Us=class extends Zr(jv.Group,Jr){constructor(e,r,o){super();this.super_Entity(e,r),this.context=o,this.objectHelper.update()}updateState(e,r){this.updateState_Entity(e,r)}};var Ks=require("three");var ks=require("three"),Q3=i=>`
2289
+ `)>=0&&(t-=n),r===3?e*.5-t*.5:r===2?e-t:0}getLineInitialOffsetY(t,e,r,o,n){let a=e*t,s=Math.abs(this.ascender-this.descender)*o,l=t-s,c=-this.ascender*o-l/2;return n===3?-(r-a-c):n===2?-(r*.5-a*.5-c):c}createPath(t,e,r,o,n){let a=t.getPath(r,-o,n.fontSize,{kerning:!1,letterSpacing:n.letterSpacing});if(!a){console.error('THREE.Font: character "'+t+'" does not exists in font family '+this.familyName+".");return}let s=new Ad,l=(t.advanceWidth??1)*e;if(t)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=T3(c.curves);u!==void 0&&c.currentPoint.distanceTo(u)>0&&c.lineTo(u.x,u.y)}),{offsetX:l,path:s}}getCharWidth(t,e){return this.font?.getAdvanceWidth(t,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}getTextWidth(t,e){return this.font?.getAdvanceWidth(t,e.fontSize,{kerning:!0,letterSpacing:e.letterSpacing})??0}computeSpaceWidthForLine(t,e,r,o){let n=this.getCharWidth(" ",r),a=t[e];if(a){let s=this.countSpaces(a.trimEnd());if(r.horizontalAlign===4&&e<t.length-1&&s){let l=typeof r.width=="string"?Number(o.getVariable(r.width)):r.width,c=this.getTextWidth(a,r);return(l-(c-s*n))/s}}return n}countSpaces(t){return(t.match(/ /g)||[]).length}};function T3(i){if(i.length){let t=i[0];if(t instanceof Rs.LineCurve)return t.v1;if(t instanceof Rs.CubicBezierCurve||t instanceof Rs.QuadraticBezierCurve)return t.v0}}var Ah=class{constructor(){this.objects=new Map;this.unreachable=new Set}getCached(t){return this.objects.get(t)}get size(){return this.objects.size}get(t,e,r){let o=this.objects.get(t);return o===void 0?(o=this.createObject(t,e,r),this.objects.set(t,o)):o.isShared=!0,o}forceDelete(t){let e=this.objects.get(t);e&&(this.disposeObject(e),this.objects.delete(t))}mutateIfUnique(t,e){let r=this.objects.get(t);if(r&&r.isShared!==!0)return this.objects.delete(t),this.objects.set(e,r),r}startGc(){this.unreachable=new Set(this.objects.keys())}markAsReachable(t,e){let r=this.objects.get(t);e===r?this.unreachable.delete(t):!1&&console.warn("Reachable but deleted",t)}endGc(){this.unreachable.forEach(t=>{this.disposeObject(this.objects.get(t)),this.objects.delete(t)}),this.unreachable.clear()}dispose(){this.objects.forEach(t=>{this.disposeObject(t)}),this.objects.clear()}},ic=class extends Ah{constructor(e){super();this.flatShading=e}disposeObject(e){e.dispose()}createObject(e,r,o){let n=zo(e,r,this.flatShading,o);return n.computeBoundingSphere(),n}};var sv={markNeedsUpdateRendererDirty:()=>{}};var Eh=require("three");var Ed=1e3,lv=512*Ed;function C3(i,t){let e=typeof i;return!!((t==="string"||t==="number")&&e===t||t==="boolean"&&(i==="true"||i==="false"||i===!0||i===!1)||t==="image"&&e==="string"&&i.startsWith("http"))}var cv="https://hooks.spline.design",A3=`${cv}/events?hashFile=`,AQ=`${cv}/`,Nd=class{constructor(t,e){this.id=t;this.userWebhook=e;this.result=void 0;this._connected=!1;this.emitter=hi();this.reconnectWaitFor=Ed;this._onError=t=>{this.eventSource?.removeEventListener("message",this._onMessage),this.eventSource?.removeEventListener("error",this._onError),this.eventSource?.removeEventListener("open",this._onConnected),this._scheduleReconnect()};this._onConnected=t=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=Ed,this._connected=!0};this._onDisconnected=()=>{clearTimeout(this.scheduledReconnectHandle),this.reconnectWaitFor=Ed,this._connected=!1};this._onMessage=t=>{let e=t.data,r;try{r=JSON.parse(e)}catch(o){console.error("Error parsing webhook message",o)}if(r){let o=!1;this.userWebhook.parametersSchemas.forEach(({data:n})=>{r[n.name]!==void 0&&C3(r[n.name],n.type)&&(this.result===void 0&&(this.result={}),this.result[n.name]=r[n.name],o=!0)}),o&&this.emitter.emit("message",{userWebhookId:this.id})}}}connect(){clearTimeout(this.scheduledReconnectHandle),this.userWebhook.url&&(this.eventSource=new EventSource(A3+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>lv&&(this.reconnectWaitFor=lv),clearTimeout(this.scheduledReconnectHandle),this.scheduledReconnectHandle=setTimeout(()=>{this.scheduledReconnectHandle=void 0,this.connect()},this.reconnectWaitFor)}update(t){this.userWebhook=t}dispose(){this._connected&&this.disconnect()}get connected(){return this._connected}on(t,e){this.emitter.on(t,e)}off(t,e){this.emitter.off(t,e)}getParametersKeys(){return this.userWebhook.parametersSchemas.map(t=>t.data.name)}getParameterValue(t){if(this.getParametersKeys().includes(t)){if(this.result)return this.result?.[t];for(let r of this.userWebhook.parametersSchemas)if(r.data.name===t)return Lu.defaultParameterValueByType(r.data.type)}}};var uv=[4186.01,4434.92,4698.63,4978.03,5274.04,5587.65,5919.91,6271.93,6644.88,7040,7458.62,7902.13],M3=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"],bi=[],_d=[];for(let i=1;i<=8;i++)for(let t=0;t<uv.length;t++){let e=uv[t];bi.push(e/Math.pow(2,8-i)),_d.push(M3[t]+i)}var Dd=[32,2e3],Mh=bi.filter((i,t)=>bi[t]>Dd[0]&&bi[t]<Dd[1]),dv=_d.filter((i,t)=>bi[t]>Dd[0]&&bi[t]<Dd[1]);var Rd=class{static getFrequencies(t,e,r,o="frequency",n=-100,a=-30){r||(r=new Float32Array(t.frequencyBinCount),t.getFloatFrequencyData(r));let s=e/2,l=1/r.length*s,c,u,d;if(o==="music"||o==="voice"){let h=o==="voice"?Mh:bi,m=Array(h.length).fill(n);for(let y=0;y<r.length;y++){let g=y*l,b=r[y];for(let w=h.length-1;w>=0;w--)if(g>h[w]){m[w]=Math.max(m[w],b);break}}c=m,u=o==="voice"?Mh:bi,d=o==="voice"?dv:_d}else c=Array.from(r),u=c.map((h,m)=>l*m),d=u.map(h=>`${h.toFixed(2)} Hz`);let p=c.map(h=>Math.max(0,Math.min((h-n)/(a-n),1)));return{values:new Float32Array(p),frequencies:u,labels:d}}};var I3="gpt-4o-realtime-preview-2024-12-17",E3=()=>!1&&window.location.search.includes("api-dev")?"https://relayserver-dev.spline.design/":"https://relayserver.spline.design/";async function N3(i){try{return(await(await fetch(E3()+"session?uuidfile="+i)).json()).token}catch(t){console.error("Token generation error:",t)}}var Ih=class{constructor(t){this.value=0;this.frequencies=new Float32Array(0);let e=new AudioContext;this.source=e.createMediaStreamSource(t),this.analyser=e.createAnalyser(),this.source.connect(this.analyser),this.analyser.fftSize=8192,this.analyser.smoothingTimeConstant=.1}getFrequencies(t=-100,e=-30){if(!this.analyser)throw new Error("Not connected, please call .connect() first");return Rd.getFrequencies(this.analyser,44100,void 0,"voice",t,e)}update(){let t=this.getFrequencies(),e=t.values.reduce((r,o)=>r+o,0)/t.values.length;this.value=e,this.frequencies=t.values}disconnect(){this.source.disconnect(),this.analyser.disconnect()}},nc=class{constructor(t,e,r){this.data=t;this.id=e;this.shared=r;this.emitter=hi();this.rafId=0;this.voice=0;this.frequencies=new Float32Array([0]);this.events=[];this.isConnected=!1;this.isToolsAdded=!1;this.tools=[];this.onMessage=t=>{let e=JSON.parse(t.data);if(this.appendEvent(e),e.type==="session.created"&&this.onSessionCreated(),e.type==="response.done"&&e.response?.output){for(let r of e.response.output)if(r.type==="function_call")for(let[o,n]of this.tools)r.name===o.name&&(n(JSON.parse(r.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 t=this.analyser.value,e=this.analyser.frequencies;this.voice=t,this.frequencies=e,this.emitter.emit("voice",{value:t,frequencies:e})}}}update(t){this.data=t}setColorByName(t,e){let r=this.shared.getColorByName(t);if(r){let{id:o}=r,{r:n,g:a,b:s}=yb.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 t=await N3(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 Ih(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 r=await this.pc.createOffer();await this.pc.setLocalDescription(r);let s={type:"answer",sdp:await(await fetch(`https://api.openai.com/v1/realtime?model=${I3}`,{method:"POST",body:r.sdp,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/sdp"}})).text()};await this.pc.setRemoteDescription(s),this.animate()}appendEvent(t){this.events=[t,...this.events]}sendClientEvent(t){this.dc?(t.event_id=t.event_id||crypto.randomUUID(),this.dc.send(JSON.stringify(t)),this.appendEvent(t)):console.error("Failed to send message - no data channel available",t)}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 t=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: ${t}. 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 r=this.shared.scene,o=[];r.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(t,e){this.tools.push([t,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(t=>{t.track&&t.track.stop()}),this.pc?.close(),this.pc=void 0}computeAnalysisForListenerEvent(t){if(t.analysis==="range"){let e=this.frequencies.slice(...t.analysisRange);return e.reduce((r,o)=>r+o,0)/e.length}return t.analysis==="single"?this.frequencies[t.analysisSingle]:this.voice}on(t,e){this.emitter.on(t,e)}off(t,e){this.emitter.off(t,e)}};function pv(i){return"variable_"+i}var Nh=class extends Sd{constructor(e){super();this.shared=e}create(e){return new Ds(e,this.shared)}},qn=class{constructor(t,e={},r=!0,o=!1){this.data=t;this.needsJitter=r;this.enableLocalStorageForPersistentVariables=o;this.geometryCache=new ic(!0);this.geometryCache2=new ic(!1);this.imageHolderCache=new Nh(this);this.thisContext={scene:sv,shared:this};this.deletedMaterial=new Hn(Wt.defaultTwoLayerData("phong"),this.thisContext,"");this.deletedImage=new Vr(Gu.emptyImage,this);this.deletedVideo=new Vr(Ra.defaultVideo,this);this.materials={};this.images={};this.uiBuffers={};this.videos={};this.colors={};this.audios={};this.particles={};this.fonts={};this.timelineAnimations={};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(t)}setRequestRender(t){this._requestRender=t}getImageLoadPromises(){return Object.values(this.images).map(t=>t.loadPromise)}setEntityOpContext(t){this.entityOpContext=t}reset(t,e=!1,r=!1){this.data=t,this.resetLib(t.lib);for(let{id:o,data:n}of t.variables)this.addVariableHolder(o,n),e&&this.updateVariableHolder(o,n);for(let[o,n]of Object.entries(t.userAPIs??{}))this.addUserAPI(o,n);for(let[o,n]of Object.entries(t.userWebhooks??{}))this.addUserWebhook(o,n);if(!r){for(let[o,n]of Object.entries(t.images))this.addImage(o,n);for(let[o,n]of Object.entries(t.videos))this.addVideo(o,n)}for(let[o,n]of Object.entries(t.colors))this.addColor(o,n);for(let[o,n]of Object.entries(t.materials))this.addMaterial(o,n);for(let[o,n]of Object.entries(t.audios))this.addAudio(o,n);for(let[o,n]of Object.entries(t.particles))this.addParticle(o,n);for(let[o,n]of Object.entries(t.fonts))this.addFont(o,n);for(let[o,n]of Object.entries(t.timelineAnimations??{}))this.addAnimation(o,n)}addMaterial(t,e){if(this.materials[t]){let r=this.materials[t];r.reset(e,this.thisContext),r.dispose()}else{let r=new Hn(e,this.thisContext,t);this.materials[t]=r}}deleteMaterial(t){this.materials[t]&&(this.materials[t].nodeMaterialDispose(),delete this.materials[t])}getMaterial(t){let e=this.materials[t];return e}getMaterialOrDeletedPlaceholder(t){return this.materials[t]??this.deletedMaterial}material(t){return typeof t=="string"?this.getMaterialOrDeletedPlaceholder(t):t==null?(console.error("material is undefined or null"),this.deletedMaterial):new kn(t,this.thisContext)}getMaterials(){return this.materials}addImage(t,e){return this.images[t]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.images[t].updateSrc(e.data),!0):(this.images[t]=new Vr(e,this),!1)}deleteImage(t){let e=this.images[t];e&&(e.dispose(),delete this.images[t])}getDefaultImage(){return this.images.image_0}getImage(t){return this.images[t]??this.deletedImage}image(t){return typeof t=="string"?this.getImage(t):this.imageHolderCache.load(t)}addUIBuffer(t,e){return this.uiBuffers[t]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),this.uiBuffers[t].updateSrc(e),!0):(this.uiBuffers[t]=new Vr(e,this),!1)}uiBuffer(t){return this.uiBuffers[t]}addVideo(t,e){return this.videos[t]?(this.videos[t].updateSrc(e.data),!0):(this.videos[t]=new Vr(e,this),!1)}deleteVideo(t){let e=this.videos[t];e&&(e.dispose(),delete this.videos[t])}getVideo(t){return this.videos[t]??this.deletedVideo}video(t){return typeof t=="string"?this.getVideo(t):this.imageHolderCache.load(t)}addColor(t,e){return this.colors[t]?(this.onColorOrImageUpdate&&this.onColorOrImageUpdate(),"a"in e?this.colors[t].setRGBA(e.r,e.g,e.b,e.a):this.colors[t].setRGBA(e.r,e.g,e.b,1),!0):("a"in e?this.colors[t]=new Zi(e.r,e.g,e.b,e.a):this.colors[t]=new Zi(e.r,e.g,e.b,1),!1)}updateColor(t,e){if(this.colors[t]){this.onColorOrImageUpdate&&this.onColorOrImageUpdate();let r=this.colors[t];return this.colors[t].r=e.r??r.r,this.colors[t].g=e.g??r.g,this.colors[t].b=e.b??r.b,this.colors[t].a=e.a??r.a,!0}return!1}deleteColor(t){this.colors[t]&&delete this.colors[t]}getColor(t){return this.colors[t]}getColorNames(){return Object.values(this.data.colors).map(t=>t.name)}getColorByName(t){for(let e in this.data.colors)if(this.data.colors[e].name===t)return{color:this.colors[e],id:e}}color(t){let e;if(typeof t=="string"){let r=this.getColor(t);r?e=r:(console.warn("Tried to create color layer params with a color key that does not exist in the assets manager"),e=new qt(0,0,0,0))}else return"a"in t?new qt(t.r,t.g,t.b,t.a):new qt(t.r,t.g,t.b,1);return e}addAudio(t,e){this.audios[t]=e}getAudio(t){let e=this.audios[t];if(e instanceof Wn)return e;{let r=new Wn({src:e.data});return this.audios[t]=r,r}}addParticle(t,e){this.particles[t]=e}getParticle(t){return this.particles[t]}deleteParticle(t){this.particles[t]&&delete this.particles[t]}deleteAudio(t){let e=this.audios[t];e&&(e instanceof Wn&&e.dispose(),delete this.audios[t])}addFont(t,e){this.fonts[t]=new Id(e),this.fonts[t].loadingPromise.then(()=>this.requestRender())}getFont(t){return this.fonts[t]}deleteFont(t){this.fonts[t]&&delete this.fonts[t]}addAnimation(t,e){this.timelineAnimations[t]=e}getAnimation(t){return this.timelineAnimations[t]}deleteAniamtion(t){this.timelineAnimations[t]&&delete this.timelineAnimations[t]}dispose(){Object.keys(this.materials).forEach(e=>this.deleteMaterial(e)),this._requestRender=void 0,Object.values(this.audios).forEach(e=>{e instanceof Wn&&e.dispose()}),this.audios={},this.particles={},this.geometryCache.dispose(),this.geometryCache2.dispose()}addVariableHolder(t,e){if(this.variables[t]===void 0){let r=e.value;if(this.enableLocalStorageForPersistentVariables&&e.persistent){let o=localStorage.getItem(pv(t));r=o!==null?JSON.parse(o):e.value}return this.variables[t]={value:r,locations:[],persistent:e.persistent},"dynamicVariableType"in e&&(this.variables[t].dynamicVariablePlayState="Playing",this.variables[t].dynamicVariableToggleIsForward=void 0),!0}return this.variables[t].value=e.value,!1}resetDynamicVariablePlayState(){for(let t in this.variables)this.variables[t].dynamicVariablePlayState!==void 0&&(this.variables[t].dynamicVariablePlayState="Playing",this.variables[t].dynamicVariableToggleIsForward=void 0)}updateVariableHolder(t,e){this.updateVariable(t,e.value)}updateVariable(t,e){if(this.variables[t]===void 0)return!1;this.variables[t].value=e,this.enableLocalStorageForPersistentVariables&&this.variables[t].persistent&&localStorage.setItem(pv(t),JSON.stringify(e));let r=e;for(;typeof r=="string";)r=this.variables[r].value;let o=this.entityOpContext.scene;for(let n=this.variables[t].locations.length-1;n>=0;n--){let a=this.variables[t].locations[n];if(a[0]==="material"){let s=a[1],l=r,c={scene:o,shared:this},u=a.slice(2);o.traverseMaterial(p=>{let f=p.root??p;f.uuid===s&&f.onVariableUpdate(u,l,c)});let d=this.materials[s];d&&d.onVariableUpdate(u,l,c)}else{let s=o.find(a[0]);if(s===void 0){this.variables[t].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]]=r*Eh.MathUtils.DEG2RAD:s[a[a.length-1]]=r}if(s=o.find(a[0]),s.type==="ParticleEmitter"&&s.updateVariableState(r,a),Ge.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 d=u.dataPatched;u.chooseGeoemtryCache(this).forceDelete(d.geometry),u.createGeometryDelayed(this.entityOpContext),u.onVariableUpdate(!0),u.invalidateDownstreamBooleanData()})}else a[1]==="morphTargetInfluences"&&s.updateMorphInfluences(a[2],r)}}return this.requestRender(),!0}deleteVariable(t){this.variables[t]&&delete this.variables[t]}getVariable(t,e){if(Array.isArray(t)){if(t[0]==="mouse")return this.mouseProperty?.[t[1]]??0;if(t[0]==="raycast")return this.raycastProperty?.[t[1]]??0;let r=this.entityOpContext.scene.find(t[0]);if(t[1]==="width"||t[1]==="height"||t[1]==="depth")return r.geometry.userData.parameters[t[1]];for(let o=1;o<t.length;o++)r=r[t[o]];return t[1]==="rotation"&&(r*=Eh.MathUtils.RAD2DEG),r}for(let r in this.variables){if(e===void 0)break;let o=this.variables[r],n=o.locations?.findIndex(a=>dt.equal(a,e));n!==void 0&&n!==-1&&o.locations.splice(n,1)}if(typeof t=="string"){let r=t,o=t;do{if(o=r,this.variables[r]===void 0)break;let n=this.variables[r].value;e&&this.variables[o]!==void 0&&this.variables[o].locations.push(e),r=n}while(typeof r=="string");return r}else return t}getVariables(){return this.variables}getVariablesNames(){return this.data.variables.map(t=>t.data.name)}getVariableByName(t){for(let e of this.data.variables)if(e.data.name===t)return{variable:e.data,id:e.id}}getDynamicVariablePlayState(t){return this.variables[t]?.dynamicVariablePlayState}setDynamicVariablePlayState(t,e){this.variables[t]!==void 0&&(this.variables[t].dynamicVariablePlayState=e)}getDynamicVariableToggleIsForward(t){return this.variables[t]?.dynamicVariableToggleIsForward}setDynamicVariableToggleIsForward(t,e){this.variables[t]!==void 0&&(this.variables[t].dynamicVariableToggleIsForward=e)}resetLib(t){for(let[e,r]of Object.entries(t.images))this.addImage(e,r.asset);for(let[e,r]of Object.entries(t.audios))this.addAudio(e,r.asset);for(let[e,r]of Object.entries(t.particles))this.addParticle(e,r.asset);for(let[e,r]of Object.entries(t.colors))this.addColor(e,r.asset);for(let[e,r]of Object.entries(t.fonts))this.addFont(e,r.asset);for(let[e,r]of Object.entries(t.materials))this.addMaterial(e,r.asset);for(let[e,r]of Object.entries(t.videos))this.addVideo(e,r.asset);for(let[e,r]of Object.entries(t.variables))this.addVariableHolder(e,r.asset)}updateLibByOp(t,e){t.path[0]==="images"?t.path.length===1&&t.type===1?this.addImage(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteImage(t.id):t.path[0]==="videos"?t.path.length===1&&t.type===1?this.addVideo(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteVideo(t.id):t.path[0]==="audios"?t.path.length===1&&t.type===1?this.addAudio(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteAudio(t.id):t.path[0]==="particles"?t.path.length===1&&t.type===1?this.addParticle(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteParticle(t.id):t.path[0]==="colors"?t.path.length===1&&t.type===1?this.addColor(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteColor(t.id):t.path[0]==="materials"?t.path.length===1&&t.type===1?this.addMaterial(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteMaterial(t.id):t.path[0]==="fonts"?t.path.length===1&&t.type===1?this.addFont(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteFont(t.id):t.path[0]==="variables"?t.path.length===1&&t.type===1?this.addVariableHolder(t.id,t.data.asset):t.path.length===1&&t.type===2&&this.deleteVariable(t.id):t.path[0]==="components"&&e.updateByLibOp(t,this)}updateByOp(t,e,r){if(this.data=e,t.path[0]==="images")t.path.length===2&&t.type===0?t.props.data&&this.getImage(t.path[1]).updateSrc(t.props.data):t.path.length===1&&t.type===1?this.addImage(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteImage(t.id);else if(t.path[0]==="videos")t.path.length===2&&t.type===0?t.props.data&&this.getVideo(t.path[1]).updateSrc(t.props.data):t.path.length===1&&t.type===1?this.addVideo(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteVideo(t.id);else if(t.path[0]==="audios")t.path.length===2&&t.type===0?t.props.data&&this.addAudio(t.path[1],e.audios[t.path[1]]):t.path.length===1&&t.type===1?this.addAudio(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteAudio(t.id);else if(t.path[0]==="particles")t.path.length===2&&t.type===0?t.props.data&&this.addParticle(t.path[1],e.particles[t.path[1]]):t.path.length===1&&t.type===1?this.addParticle(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteParticle(t.id);else if(t.path[0]==="colors")t.path.length===2&&t.type===0?this.updateColor(t.path[1],t.props):t.path.length===1&&t.type===1?this.addColor(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteColor(t.id);else if(t.path[0]==="materials")t.path.length===1&&t.type===1?this.addMaterial(t.id,t.data):t.path.length===1&&t.type===2?this.deleteMaterial(t.id):t.path.length>1&&this.getMaterial(t.path[1]).updateByOp(vt.drop(t,2),e.materials[t.path[1]],{shared:this,scene:r});else if(t.path[0]==="fonts")t.path.length===2&&t.type===0?this.updateFont(t.path[1],t,r):t.path.length===1&&t.type===1?this.addFont(t.id,t.data):t.path.length===1&&t.type===2&&this.deleteFont(t.id);else if(t.path[0]==="variables")t.path.length===2&&t.type===0?"value"in t.props?this.updateVariable(t.path[1],t.props.value):"persistent"in t.props&&(this.variables[t.path[1]].persistent=t.props.persistent):t.path.length===1&&t.type===4?this.addVariableHolder(t.id,t.data):t.path.length===1&&t.type===5&&this.deleteVariable(t.id);else if(t.path[0]==="userAPIs"){if(t.path.length===1&&t.type===1)this.addUserAPI(t.id,t.data);else if(t.path.length===1&&t.type===2)this.deleteUserAPI(t.id);else if(typeof t.path[1]=="string"){let o=e.userAPIs[t.path[1]];if(o){let n=t.type===0&&t.props.debounce===void 0,a=this.getUserAPI(t.path[1]);a instanceof nc?a.update(o):a?.update(o,this,n)}}}else if(t.path[0]==="userWebhooks"){if(t.path.length===1&&t.type===1)this.addUserWebhook(t.id,t.data);else if(t.path.length===1&&t.type===2)this.deleteUserWebhook(t.id);else if(typeof t.path[1]=="string"){let o=e.userWebhooks[t.path[1]];o&&this.getUserWebhook(t.path[1])?.update(o)}}else t.path[0]==="lib"&&this.updateLibByOp(vt.drop(t,1),r)}updateFont(t,e,r){if(e.props.url){let o=this.getFont(t),n={...this.data.fonts[t],url:e.props.url};o.update(n),o.loadingPromise.then(()=>this.requestRender()),r.updateFont(t,this)}}addUserAPI(t,e){return this.userAPIs[t]?(this.userAPIs[t].update(e,this),!0):this.openAIRealtime?.id===t?(this.openAIRealtime.update(e),!0):e.integration?.type==="VoiceAssistant"?(this.openAIRealtime=new nc(e,t,this),!1):(this.userAPIs[t]=new ad(t,e,this),!1)}getUserAPI(t){return this.openAIRealtime?.id===t?this.openAIRealtime:this.userAPIs[t]}getUserAPIs(){return this.userAPIs}deleteUserAPI(t){let e=this.userAPIs[t];e&&(e.dispose(),delete this.userAPIs[t])}addUserWebhook(t,e){return this.userWebhooks[t]?(this.userWebhooks[t].update(e),!0):(this.userWebhooks[t]=new Nd(t,e),!1)}getUserWebhook(t){return this.userWebhooks[t]}getUserWebhooks(){return this.userWebhooks}deleteUserWebhook(t){let e=this.userWebhooks[t];e&&(e.dispose(),delete this.userWebhooks[t])}get scene(){return this.entityOpContext.scene}},fv=new qn(qr.emptyData());var Er=class extends Xt{updateByPatchedOp(e,r,o){if(super.updateByPatchedOp(e,r,o),Jg(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(Ue(e.path,["material"])&&this.material instanceof Ir)"material"in r&&typeof r.material!="string"&&this.material.updateByOp(vt.drop(e,1),r.material,o);else if(Ue(e.path,["materials","*"])&&Array.isArray(this.material)){let n=e.path[1];if("materials"in r&&n<this.material.length){let a=r.materials[n];typeof a!="string"&&this.material[n].updateByOp(vt.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,r){super.updateState(e,r),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;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=r.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe,a),r.scene.markNeedsUpdateRendererDirty()),(e.geometry?.type==="NonParametricGeometry"||"materials"in e)&&("materials"in e&&e.materials!==void 0?(this.disposeMaterial(),this.material=e.materials.map(l=>r.shared.material(l).getFlavor(o.flatShading,o.side,o.wireframe)),r.scene.markNeedsUpdateRendererDirty()):"material"in e&&e.material!==void 0&&(this.disposeMaterial(),this.material=[r.shared.material(e.material).getFlavor(o.flatShading,o.side,o.wireframe)],r.scene.markNeedsUpdateRendererDirty()));let s=this.data;if(s.geometry?.type!=="NonParametricGeometry"&&"materials"in s&&s.materials!==void 0&&(this.disposeMaterial(),this.material=r.shared.material(s.materials[0]).getFlavor(o.flatShading,o.side,o.wireframe)),e.flatShading!==void 0||e.wireframe!==void 0||e.side!==void 0)if(Array.isArray(this.material))for(let l=0;l<this.material.length;l++)this.material[l]=this.material[l].getFlavor(o.flatShading,o.side,o.wireframe);else this.material=this.material.getFlavor(o.flatShading,o.side,o.wireframe,a)}disposeMaterial(){this.material&&Ic(this.material).forEach(e=>{e instanceof Ir&&(e instanceof Hn||e.nodeMaterialDispose())})}dispose(){this.disposeMaterial(),super.dispose()}};var zr=require("three");var hv=new zr.Vector3,mv=new zr.Vector4,yv=new zr.Vector4,_3=new zr.Vector3,gv=new zr.Matrix4,ht=class extends Er{constructor(e,r,o){super(e,r);this.data=r;this.isSkinnedMesh=!1;this.localGeometry=void 0,r.bindMode&&r.bindMatrix&&(this.bindMode=r.bindMode,this.bindMatrix=new zr.Matrix4().fromArray(r.bindMatrix),this.bindMatrixInverse=new zr.Matrix4)}chooseGeoemtryCache(e){return e.geometryCache}markGeometryAsReachable(e){this.geometryCreateDeleyed instanceof zr.BufferGeometry&&this.chooseGeoemtryCache(e).markAsReachable(this.dataPatched.geometry,this.geometryCreateDeleyed)}get geometry(){if(this.localGeometry!==void 0)return this.localGeometry;if(this.geometryCreateDeleyed instanceof qn){let e=this.geometryCreateDeleyed,r=this.chooseGeoemtryCache(e);this.geometryCreateDeleyed=r.get(this.dataPatched.geometry,e,this)}return this.geometryCreateDeleyed}set geometry(e){this.localGeometry=e}get is2DAndNoDepth(){let e=this.dataPatched.geometry;return vl.is2DParametricMesh(e.type)&&e.depth===0}get is2DType(){return vl.is2DParametricMesh(this.geometry.userData.type)}get isNonParametric(){return this.geometry.userData.type==="NonParametricGeometry"}updateByPatchedOp(e,r,o){super.updateByPatchedOp(e,r,o),Ue(e.path,["geometry"])&&this.updateByPatchedOpGeometry(vt.drop(e,1),r.geometry,o)}removeInteractionGeometry(e){this.localGeometry?.dispose(),this.localGeometry=void 0}updateGeometryInteractions(e,r){this.invalidateDownstreamBooleanData();let o=this.data.geometry.type;if(o==="NonParametricGeometry"||o==="SubdivGeometry"){let n=e;if(this.localGeometry===void 0){let f={...this.data.geometry,...n};this.localGeometry=zo(f,r,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,u=typeof a=="number"?a:1,d=typeof s=="number"?s:1,p=typeof l=="number"?l:1;c.sxPrev!==void 0&&jl(this.localGeometry.attributes,u/c.sxPrev,d/c.syPrev,p/c.szPrev),c.sxPrev=u,c.syPrev=d,c.szPrev=p}else{let n={...this.data.geometry,...e};this.localGeometry?.dispose(),this.localGeometry=zo(n,r,this.data.flatShading,this)}}refreshAttachedClonersInteractions(e){for(let r of this.attachedSurfaceCloners)r.update(e)}refreshAttachedCloners(e){for(let r of this.attachedSurfaceCloners)e.scene.addPendingUpdateCloner(r.object)}refreshAttachedPaths(e){for(let r of this.attachedPaths)e.scene.addPendingCommand(()=>r.updateShape())}createGeometryDelayed(e){this.geometryCreateDeleyed=e.shared,this.refreshAttachedCloners(e),this.refreshAttachedPaths(e)}updateByPatchedOpGeometry(e,r,o){let n=!1;e.type===0&&e.path.length===0&&Object.keys(e.props).includes("scaleBaked")&&this.geometryCreateDeleyed instanceof zt&&this.chooseGeoemtryCache(o.shared).mutateIfUnique(this.geometryCreateDeleyed.data,r)===this.geometryCreateDeleyed&&(n=!0,this.geometryCreateDeleyed.mutateDirectlyScaleBaked(r,e.props.scaleBaked),this.refreshAttachedCloners(o),this.refreshAttachedPaths(o)),n||(o.scene?.markGeometryCacheDirty(),this.createGeometryDelayed(o)),this.resetBBoxNeedsUpdate(),this.invalidateDownstreamBooleanData()}updateGeometryOnStateUpdate(e,r){this.createGeometryDelayed(r)}updateState(e,r){e.geometry!==void 0&&this.updateGeometryOnStateUpdate(e.geometry,r);let o=e.morphTargetInfluences;if(o){this.updateMorphTargets(),this.geometry.morphTargetsRelative=!0;for(let{data:{name:n,value:a}}of o)this.updateMorphInfluences(n,r.shared.getVariable(a,[this.uuid,"morphTargetInfluences",n]))}super.updateState(e,r)}updateMorphInfluences(e,r){if(this.morphTargetDictionary===void 0)return;let o=this.morphTargetDictionary[e];o!==void 0&&(this.morphTargetInfluences[o]=r)}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,r){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),r.set(o.width,o.height,o.depth??0).multiplyScalar(.5)):o.centerOffset?e.fromArray(o.centerOffset):e.setScalar(0),r.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,r){this.skeleton=e,this.isSkinnedMesh=!0,r===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),r=this.matrixWorld),this.bindMatrix.copy(r),this.bindMatrixInverse.copy(r).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(e){let r=new zr.Vector4,o=this.geometry.attributes.skinWeight;for(let n=0,a=o.count;n<a;n++){r.fromBufferAttribute(o,n);let s=1/r.manhattanLength();s!==1/0?r.multiplyScalar(s):r.set(1,0,0,0),o.setXYZW(n,r.x,r.y,r.z,r.w)}}boneTransform(e,r){let o=this.skeleton;if(o===void 0)return;let n=this.geometry;mv.fromBufferAttribute(n.attributes.skinIndex,e),yv.fromBufferAttribute(n.attributes.skinWeight,e),hv.copy(r).applyMatrix4(this.bindMatrix),r.set(0,0,0);for(let a=0;a<4;a++){let s=yv.getComponent(a);if(s!==0){let l=mv.getComponent(a);gv.multiplyMatrices(o.bones[l].matrixWorld,o.boneInverses[l]),r.addScaledVector(_3.copy(hv).applyMatrix4(gv),s)}}return r.applyMatrix4(this.bindMatrixInverse)}};function R3(i){if(i.geometry.attributes.extrudeNormal||!i.geometry.attributes.position||!i.geometry.attributes.normal)return;let t=new Map,e=i.geometry.attributes,r=e.position.array,o=e.normal.array,n=new Float32Array(r.length);for(let a=0;a<r.length;a+=3){let s=`${r[a]}_${r[a+1]}_${r[a+2]}`,l=new Gr.Vector3(o[a],o[a+1],o[a+2]);t.has(s)?t.get(s)?.normals.push(l):t.set(s,{normals:[l],result:new Gr.Vector3})}t.forEach((a,s)=>{for(let l of a.normals)a.result.add(l);a.result.divideScalar(a.normals.length)});for(let a=0;a<r.length;a+=3){let s=`${r[a]}_${r[a+1]}_${r[a+2]}`,l=t.get(s)?.result;l&&(n[a]=l.x,n[a+1]=l.y,n[a+2]=l.z)}i.geometry.setAttribute("extrudeNormal",new Gr.Float32BufferAttribute(n,3))}function L3(i){if(i.geometry.attributes.extrudeNormals||!i.geometry.attributes.position)return;let e=i.geometry.attributes.position.array,r=new Float32Array(e.length),o=new Gr.Vector3;for(let n=0;n<e.length;n+=3)o.set(e[n],e[n+1],e[n+2]).normalize(),r[n]=o.x,r[n+1]=o.y,r[n+2]=o.z;i.geometry.setAttribute("extrudeNormal",new Gr.Float32BufferAttribute(r,3))}function Ls(i){if(Array.isArray(i.material)){for(let t of i.material)if(t.getLayersOfType("outline").length===0)return}else if(!(i.material instanceof Ir)||i.material.getLayersOfType("outline").length===0)return;i instanceof ht&&i.is2DAndNoDepth?L3(i):R3(i)}function Bs(i){if(!i.geometry.attributes.position)return;let e=i.geometry.attributes.position.array,r=new Float32Array(e.length),o=parseInt(i.uuid.replace(/\D/g,"")),n=[Gr.MathUtils.seededRandom(o),Gr.MathUtils.seededRandom(o+1e4),Gr.MathUtils.seededRandom(o+2e4)];for(let a=0;a<e.length;a++)r[a]=n[a%3];i.geometry.setAttribute("randomColor",new Gr.BufferAttribute(r,3))}var Uo=new vi.Box3,ac=new vi.Vector3;function xv(i){let t=!1;return i.scene.objects.traverse((e,r)=>{r.type==="Mesh"&&r.geometry.type==="SubdivGeometry"&&(t=!0)}),t}var $n=class extends ht{constructor(e,r,o){super(e,r,o);this.data=r;this.hiddenMatrixOld=new vi.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,r){let o=this.geometry.userData.parameters;e.copy(this.originalGeometryNew.boundingSphere.center),r.set(o.width,o.height,o.depth??0).multiplyScalar(.5)}createGeometryByControls(e){if(this.skipReactionUpdate===!0)return;let r=this.localGeometry?.uuid,{originalGeometry:o,subdividedGeometry:n,subdivPointer:a}=zt.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,Ls(this),Bs(this),this.calcBoundingBox(),r&&(this.localGeometry.uuid=r)}updateState(e,r){if(super.updateState(e,r),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(r)}}updateMesh(e=!1){zt.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1,this.originalGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0),this.subdividedGeometry&&zt.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1,this.subdividedGeometry,e&&this.hasNonUniformScale?this.shearScaleInv:void 0)}updateTopology(){this.originalGeometry.dispose(),this.originalGeometry=zt.buildLevel(this.subdivPointer,!0,this.smoothShading?this.phongAngle:-1),this.subdividedGeometry&&(this.subdividedGeometry.dispose(),this.subdividedGeometry=zt.buildLevel(this.subdivPointer,!1,this.smoothShading?this.phongAngle:-1)),this.localGeometry=this.subdividedGeometry??this.originalGeometry}raycast(e,r){let o=this.localGeometry;this.localGeometry=this.originalGeometryNew,Xt.prototype.raycast.call(this,e,r),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 vi.Sphere,this.subdividedGeometry&&(this.subdividedGeometry.boundingSphere=e.boundingSphere));let r=e.attributes.position,o=e.boundingSphere.center;Uo.setFromBufferAttribute(r),Uo.getCenter(o),e.boundingSphere.radius=o.distanceTo(Uo.max),isNaN(e.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this),Uo.getSize(ac),this.hasNonUniformScale&&ac.divide(this.scale);let n={width:ac.x,height:ac.y,depth:ac.z};return this.geometry.userData.parameters=n,n}updateBoundingSphere(e){let r=this.originalGeometry;Uo.min.set(e[0],e[2],e[4]),Uo.max.set(e[1],e[3],e[5]),this.hasNonUniformScale&&(Uo.min.applyMatrix4(this.shearScaleInv),Uo.max.applyMatrix4(this.shearScaleInv)),r.boundingSphere===null&&(r.boundingSphere=new vi.Sphere);let o=r.boundingSphere.center;Uo.getCenter(o),r.boundingSphere.radius=o.distanceTo(Uo.max)}freeSubdivPointer(){this.subdivPointer&&(zt.freeSubdivPointer(this.subdivPointer),this.subdivPointer=0),this.localGeometry=void 0,this.originalGeometry?.dispose(),this.subdividedGeometry?.dispose()}dispose(){super.dispose(),this.freeSubdivPointer()}updateByPatchedOpGeometry(e,r,o){super.updateByPatchedOpGeometry(e,r,o),this.localGeometry&&this.createGeometryByControls(r)}};var ko=require("three"),bv=-1,B3=1,vv={x:[1,0,0],"-x":[-1,0,0],y:[0,1,0],"-y":[0,-1,0],z:[0,0,1],"-z":[0,0,-1]},Sv={polygon_center:0,edge:1,vertex:2},sc=(i,t)=>(e,r)=>!t||e===0||i===0?0:i*r/100,Ne=(i,t)=>{let e=Math.abs(t),r=e*-1;return(i-bv)*(e-r)/(B3-bv)+r},V3=new ko.Vector3,Ld=new ko.Vector3,z3=new ko.Vector3,G3=new ko.Vector3;function Vs(i,t){let e=z3.fromArray(i),r=G3.fromArray(t);Ld.copy(r).sub(e);let o=Ld.length();return Ld.normalize().multiplyScalar(o*.5),V3.copy(e).add(Ld).toArray()}var Kr=new ko.Triangle,Bd=new ko.Vector3,Vd=new ko.Vector3,Xn=new ko.Vector3;function wv(i){let t=[];for(let e=0;e<=i.index.count;e++)if(Bd.fromArray(i.index.array,e*3),Kr.setFromAttributeAndIndices(i.attributes.position,Bd.x,Bd.y,Bd.z),Kr.getNormal(Vd),Kr.getMidpoint(Xn),!(isNaN(Xn.x)||isNaN(Xn.y)||isNaN(Xn.z))){let{a:r,b:o,c:n}=Kr,a=r.toArray(),s=o.toArray(),l=n.toArray(),c=r.distanceTo(o),u=o.distanceTo(n),d=n.distanceTo(r),p=Vs(a,s),f=Vs(s,l),h=Vs(l,a),m=[c,u,d],y=Math.max(...m),g=m.filter(P=>Math.round(P)===Math.round(y)).length>1,b=[],w=Kr.getMidpoint(Xn).toArray();y===c&&!g&&(b=[f,h,h],w=p),y===u&&!g&&(b=[p,h,h],w=f),y===d&&!g&&(b=[p,f,f],w=h),g&&(b=[p,f,h]),t.push({vertices:[a,s,l],faceCenters:b,midpoint:w,norm:Kr.getNormal(Vd).toArray()})}return t}function Pv(i){let t=[],{position:e}=i.attributes;for(let r=0;r<e.count;r++){Kr.setFromAttributeAndIndices(e,r*3,r*3+1,r*3+2),Kr.getNormal(Vd),Kr.getMidpoint(Xn);let o=Kr.a.toArray(),n=Kr.b.toArray(),a=Kr.c.toArray();t.push({vertices:[o,n,a],faceCenters:[Vs(o,n),Vs(n,a),Vs(a,o)],midpoint:Xn.toArray(),norm:Vd.toArray()})}return t}var F3=4,j3=.5,_h=i=>.5*(1-Math.cos(i*Math.PI)),Rh=class{constructor(){this.perlin=new Array(4095+1)}noise(t,e=0,r=0){if(this.perlin==null){this.perlin=new Array(4095+1);for(let g=0;g<4095+1;g++)this.perlin[g]=Math.random()}t<0&&(t=-t),e<0&&(e=-e),r<0&&(r=-r);let o=Math.floor(t),n=Math.floor(e),a=Math.floor(r),s=t-o,l=e-n,c=r-a,u,d,p=0,f=.5,h,m,y;for(let g=0;g<F3;g++){let b=o+(n<<4)+(a<<8);u=_h(s),d=_h(l),h=this.perlin[b&4095],h+=u*(this.perlin[b+1&4095]-h),m=this.perlin[b+16&4095],m+=u*(this.perlin[b+16+1&4095]-m),h+=d*(m-h),b+=256,m=this.perlin[b&4095],m+=u*(this.perlin[b+1&4095]-m),y=this.perlin[b+16&4095],y+=u*(this.perlin[b+16+1&4095]-y),m+=d*(y-m),h+=_h(c)*(m-h),p+=h*f,f*=j3,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 p}noiseSeed(t){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(t),this.perlin=new Array(4095+1);for(let r=0;r<4095+1;r++)this.perlin[r]=e.rand()}},Ov=Rh;var zs=require("three");var Tv=new zs.Vector3,Cv=new zs.Matrix4,Av=new zs.Ray;function Mv(i){let t=!1;return i.scene.objects.traverse((e,r)=>{r.type==="Mesh"&&(r.geometry.type==="TextGeometry"||r.geometry.type==="InputGeometry")&&(t=!0)}),t}var rn=class extends ht{constructor(e,r,o){super(e,r,o);this.data=r}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,typeof e.geometry.height=="number"?e.geometry.height:1,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,r){let{matrixWorld:o}=this;if(!(isNaN(e.ray.origin.x)||this.scale.x===0||this.scale.y===0||this.scale.z===0)&&(Cv.copy(o).invert(),Av.copy(e.ray).applyMatrix4(Cv),Av.intersectBox(this.singleBBox,Tv))){let n=Tv.applyMatrix4(o),a=e.ray.origin.distanceTo(n);r.push({distance:a,point:n.clone(),object:this})}}};var br=1e-4,Ho,Nv,Dv,_v,Iv=new tt.Vector3,Ev=new tt.Vector3;ld.then(i=>{Ho=i,Nv=[Ho.get_face_center,Ho.get_edge_midpoint,Ho.get_vertex_position],Dv=[Ho.get_face_normal,Ho.get_edge_normal,Ho.get_vertex_normal],_v=[Ho.face_count,Ho.edge_count,Ho.vertex_count]});var U3=new tt.Matrix4,k3=new tt.Matrix4,on=new tt.Vector3,zd=new tt.Vector3,lc=new tt.Vector3,Lh=new tt.Vector3,H3=new tt.Vector3,W3=new tt.Vector3;function St(i,t){return[typeof i?.[0]=="number"?i[0]:typeof i?.[0]=="string"&&t?parseFloat(String(t.shared.getVariable(i[0])??"0")):0,typeof i?.[1]=="number"?i[1]:typeof i?.[1]=="string"&&t?parseFloat(String(t.shared.getVariable(i[1])??"0")):0,typeof i?.[2]=="number"?i[2]:typeof i?.[2]=="string"&&t?parseFloat(String(t.shared.getVariable(i[2])??"0")):0]}var Bh=class{constructor(t,e){this.data=t;this.is3D=e;this.perlin=new Ov;t.noiseType==="perlin"?(this.perlin.noiseSeed(t.seed),e?this.noise=(o,n,a)=>this.perlin.noise(o,n,a):this.noise=o=>this.perlin.noise(o)):e?this.noise=cx((0,Gd.default)(t.seed)):this.noise=lx((0,Gd.default)(t.seed??""))}},nn=class extends Ha(tt.Object3D){constructor(e,r){super();this.parameters=r;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 r of this.children)r instanceof co&&r.expand()}invalidateTransform(e){this.matrixWorldNeedsUpdate=!0,this.traverse(r=>{r instanceof co&&r.object===e&&(r.matrixWorldNeedsUpdate=!0)})}onObjUpdateMatrix(){this.parameters.type!=="toObject"&&(this.matrixWorldNeedsUpdate=!0)}update(e){switch(this._updateCount(e),this.parameters.type){case"radial":this._updateRadial(this.parameters,e);break;case"linear":this._updateLinear(this.parameters,e);break;case"grid":this._updateGrid(this.parameters,e);break;case"toObject":this._updateToObject(this.parameters,e)}for(let r of this.children)r.updateMatrix(),r.hasNonUniformScale&&(r.updateMatrixWorld(),r.updateMatrixWorldSVD())}_updateCount(e,r){let o;if(r!==void 0)o=r;else{let n=St(this.parameters.grid.count,e);o=this.parameters.type==="grid"?Math.round(n[0])*Math.round(n[1])*Math.round(n[2]):this.parameters.count}if(this.parameters.type==="toObject"){if(!this.parameters.toObject.object)o=0;else if(r===void 0&&this.parameters.toObject.spreadType!=="random")return}if(this.parameters.type==="toObject"&&this.objectForSample){let n=this.children;if(n.length===o)return;if(n.length<o)for(let a=0,s=o-n.length;a<s;++a){let l=new co(this.object);l.expand(),this.add(l)}else for(let a=0,s=n.length-o;a<s;++a)this.remove(n[a])}else{if(this.children.length===o)return;if(this.children.length<o)for(let n=0,a=o-this.children.length;n<a;++n){let s=new co(this.object);s.expand(),this.add(s)}else for(let n=0,a=this.children.length-o;n<a;++n)this.remove(this.children[n])}}getRandom(e,r=!1){return(this.random===null||this.random.data.seed!==e.seed||this.random.is3D!==r)&&(this.random=new Bh(e,r)),this.random}_updateRadial(e,r){let o=e.radial,n=o.start*tt.MathUtils.DEG2RAD,a=o.end*tt.MathUtils.DEG2RAD,s=n-a,l=St(o.rotation,r),c=new tt.Euler(l[0],l[1],l[2]),u;switch(o.axis){case"z":u=new tt.Vector3(0,0,1);break;case"y":u=new tt.Vector3(0,1,0);break;default:case"x":u=new tt.Vector3(1,0,0);break}let d=e.randomnessObject??No.defaultData([1,1,1]).randomnessObject,p=this.getRandom(d),f=sc(d.strength,this.parameters.randomness);for(let[h,m]of this.children.entries()){let y=h*(d.freqScale/10)+d.movement,g=p.noise(y,y,y),b=h+1,w=St(o.scale,r),P=St(d.scale,r);m.scale.x=w[0]+f(b,Ne(g,P[0]))||br,m.scale.y=w[1]+f(b,Ne(g,P[1]))||br,m.scale.z=w[2]+f(b,Ne(g,P[2]))||br,m.position.setScalar(0);let S=s/e.count*h-n;switch(o.axis){case"x":m.rotation.set(0,S,0);break;case"y":m.rotation.set(0,0,S);break;case"z":m.rotation.set(S,0,0);break}m.translateOnAxis(u,o.radius);let T=St(o.position,r),A=St(d.position,r);m.position.x+=T[0]+f(b,Ne(g,A[0])),m.position.y+=T[1]+f(b,Ne(g,A[1])),m.position.z+=T[2]+f(b,Ne(g,A[2]));let x=St(d.rotation,r),N=f(b,Ne(g,x[0])),E=f(b,Ne(g,x[1])),M=f(b,Ne(g,x[2]));o.alignment===!0?(m.rotation.x+=c.x+N,m.rotation.y+=c.y+E,m.rotation.z+=c.z+M):m.rotation.set(c.x+N,c.y+E,c.z+M)}}_updateLinear(e,r){if(e.type!=="linear")throw new Error;let o=e.linear,n=St(o.rotation,r),a=St(o.scale,r),s=St(o.position,r),l=new tt.Euler(n[0]??0,n[1]??0,n[2]??0),c=e.randomnessObject??No.defaultData([1,1,1]).randomnessObject,u=St(c.rotation,r),d=St(c.scale,r),p=St(c.position,r),f=this.getRandom(c),h=sc(c.strength,this.parameters.randomness);for(let[m,y]of this.children.entries()){let g=m*(c.freqScale/10)+c.movement,b=f.noise(g,g,g),w=m+1,P=h(w,Ne(b,u[0])),S=h(w,Ne(b,u[1])),T=h(w,Ne(b,u[2]));y.scale.x=1+(a[0]-1)*m+h(w,Ne(b,d[0]))||br,y.scale.y=1+(a[1]-1)*m+h(w,Ne(b,d[1]))||br,y.scale.z=1+(a[2]-1)*m+h(w,Ne(b,d[2]))||br,y.rotation.x=l.x*m+P,y.rotation.y=l.y*m+S,y.rotation.z=l.z*m+T,y.position.x=s[0]*m+h(w,Ne(b,p[0])),y.position.y=s[1]*m+h(w,Ne(b,p[1])),y.position.z=s[2]*m+h(w,Ne(b,p[2]))}}_updateGrid(e,r){let o=0,n=e.grid,a=e.randomnessObject??No.defaultData([1,1,1]).randomnessObject,s=St(a.scale,r),l=St(a.rotation,r),c=St(a.position,r),u=this.getRandom(a,!0),d=sc(a.strength,this.parameters.randomness),p=St(n.count,r),f=St(n.size,r);if(n.useCenter===!0){let h={x:p[0]%2===0?2:1,y:p[1]%2===0?2:1,z:p[2]%2===0?2:1},m=new tt.Vector3(f[0]*(p[0]-h.x)*.5,f[1]*(p[1]-h.y)*.5,f[2]*(p[2]-h.z)*.5);for(let y=0;y<p[0];y++)for(let g=0;g<p[1];g++)for(let b=0;b<p[2];b++){let w=u.noise((y+1)*(a.freqScale/10)+a.movement,(g+1)*(a.freqScale/10)+a.movement,(b+1)*(a.freqScale/10)+a.movement),P=this.children[o++];if(!P)continue;P.scale.x=1+d(o,Ne(w,s[0]))||br,P.scale.y=1+d(o,Ne(w,s[1]))||br,P.scale.z=1+d(o,Ne(w,s[2]))||br;let S=d(o,Ne(w,l[0])),T=d(o,Ne(w,l[1])),A=d(o,Ne(w,l[2]));P.rotation.set(S,T,A),P.position.x=f[0]*y-m.x+d(o,Ne(w,c[0])),P.position.y=f[1]*g-m.y+d(o,Ne(w,c[1])),P.position.z=f[2]*b-m.z+d(o,Ne(w,c[2]))}}else for(let h=0;h<p[0];h++)for(let m=0;m<p[1];m++)for(let y=0;y<p[2];y++){let g=u.noise((h+1)*(a.freqScale/10)+a.movement,(m+1)*(a.freqScale/10)+a.movement,(y+1)*(a.freqScale/10)+a.movement),b=this.children[o++];if(!b)continue;b.scale.x=1+d(o,Ne(g,s[0]))||br,b.scale.y=1+d(o,Ne(g,s[1]))||br,b.scale.z=1+d(o,Ne(g,s[2]))||br;let w=d(o,Ne(g,l[0])),P=d(o,Ne(g,l[1])),S=d(o,Ne(g,l[2]));b.rotation.set(w,P,S),b.position.x=f[0]*h+d(o,Ne(g,c[0])),b.position.y=-f[1]*m+d(o,Ne(g,c[1])),b.position.z=-f[2]*y+d(o,Ne(g,c[2]))}}_updateToObject(e,r){if(e.type!=="toObject")throw new Error;let{toObject:o}=e,n=St(o.rotation,r),a=St(o.position,r),s=St(o.scale,r),l=new tt.Euler(n[0],n[1],n[2]),c=e.randomnessObject??No.defaultData([1,1,1]).randomnessObject,u=St(c.rotation,r),d=St(c.position,r),p=St(c.scale,r),f=this.getRandom(c),h=sc(c.strength,this.parameters.randomness);if(!o.object){for(let[,w]of this.children.entries())w.position.set(0,0,0),w.scale.setScalar(1),w.rotation.set(0,0,0);this.objectForSample=void 0;return}if(!this.objectForSample)return;if(this.objectForSample instanceof rn)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 m=this.getSubdivData();if(m.length>0){let w=Math.round(m.length*o.count/100);this._updateCount(r,w)}else{let w=this.objectForSample.geometry.getAttribute("position");if(!w||isNaN(w.count)||w.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 y=new Hu(this.objectForSample).build(),g=vv[o.axis],b=this.children;y.setRandomGenerator((0,Gd.default)(this.object.uuid+o.seed));for(let[w,P]of b.entries()){let S=w*(c.freqScale/10)+c.movement,T=f.noise(S,S,S),A=w+1,x=h(A,Ne(T,u[0])),N=h(A,Ne(T,u[1])),E=h(A,Ne(T,u[2]));o.spreadType==="random"?y.sample(lc,Lh):(m.length&&(lc.fromArray(m[w].pos),Lh.fromArray(m[w].norm)),this.objectForSample instanceof $n&&lc.applyMatrix4(U3.copy(this.objectForSample.matrixWorld).invert())),lc.applyMatrix4(this.object.hiddenMatrix.clone().invert()),P.position.copy(lc),on.fromArray(g);let M=o.align==="normal"?Lh:this.object.getWorldDirection(W3),D=zd.fromArray(a);zd.x+=h(A,Ne(T,d[0])),zd.y+=h(A,Ne(T,d[1])),zd.z+=h(A,Ne(T,d[2]));let _=Math.acos(M.dot(on)),R=H3.crossVectors(on,M).normalize(),V=k3.makeRotationAxis(R,_),U=M.clone().cross(this.object.up).normalize(),B=U.clone().cross(M).normalize(),q=new tt.Matrix4().makeBasis(U,M,B),j=new tt.Vector3(on.y,on.z,on.x).normalize(),F=j.clone().cross(on).normalize(),H=new tt.Matrix4().makeBasis(j,on,F).invert(),W=new tt.Matrix4().multiplyMatrices(q,H);P.rotation.setFromRotationMatrix(W),D.applyMatrix4(V),P.position.add(D),P.rotation.x=P.rotation.x+l.x+x,P.rotation.y=P.rotation.y+l.y+N,P.rotation.z=P.rotation.z+l.z+E,P.scale.setScalar(1),P.scale.x=P.scale.x+s[0]+h(A,Ne(T,p[0]))||br,P.scale.y=P.scale.y+s[1]+h(A,Ne(T,p[1]))||br,P.scale.z=P.scale.z+s[2]+h(A,Ne(T,p[2]))||br,P.scale.multiply(this.object.scale),P.hiddenMatrix=this.object.hiddenMatrix}}getSubdivData(){if(!this.objectForSample)return[];let e=this.parameters.toObject.spreadType,r=new Map,o=(a,s)=>{let l=Math.round(a[0]*1e4)+"_"+Math.round(a[1]*1e4)+"_"+Math.round(a[2]*1e4),c=r.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):r.set(l,{pos:[...a],norm:[...s],count:1})};if(e==="random")return[];if(this.objectForSample instanceof $n){let a=this.objectForSample,s=Sv[e],l=_v[s],c=Nv[s],u=Dv[s],d=l(a.subdivPointerNew);for(let p=0;p<=d-1;p++){let f=c(a.subdivPointerNew,p),h=u(a.subdivPointerNew,p);Iv.fromArray(f).applyMatrix4(a.matrixWorld),Ev.fromArray(h),o(Iv.toArray(),Ev.toArray())}}else(this.objectForSample.geometry.index?wv(this.objectForSample.geometry):Pv(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(r.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,r){if(this.parameters=ti(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=r.scene.find(this.parameters.toObject.object);o instanceof Xt?this.objectForSample=o:this.objectForSample=void 0,this.matrix=new tt.Matrix4,this.hiddenMatrix=new tt.Matrix4,this.matrixWorldNeedsUpdate=!0,this.matrixAutoUpdate=!1,o&&o.add(this)}this.update(r)}get pendingMediaLoad(){return this._pendingMediaLoad}};var oo=require("three");var xt=require("three");var cr=require("three");var Rv=require("three"),Wo=i=>{var t;return t=class extends i{},t.geometryHelper=new Rv.BoxGeometry(30,30,30),t};var fr=require("three"),Fd=new fr.Ray,Vh=new fr.Sphere,Lv=new fr.Matrix4,qo=(i,t,e,r,o=!1,n=i)=>{let a=t,s=n.matrixWorld;if(a.boundingSphere===null&&a.computeBoundingSphere(),Vh.copy(a.boundingSphere),Vh.applyMatrix4(s),e.ray.intersectsSphere(Vh)===!1||(Lv.copy(s).invert(),Fd.copy(e.ray).applyMatrix4(Lv),a.boundingBox!==null&&Fd.intersectsBox(a.boundingBox)===!1))return;let l,c,u,d,p=a.index,f=a.attributes.position,h=a.drawRange,m,y;if(o===!1){let b=Math.max(0,h.start),w=Math.min(p.count,h.start+h.count);for(m=b,y=w;m<y;m+=3)if(c=p.getX(m),u=p.getX(m+1),d=p.getX(m+2),l=g(i,e,Fd,f,c,u,d),l){l.faceIndex=Math.floor(m/3),r.push(l);return}}else{let w=a.attributes.position,P=new fr.Vector3,S=new fr.Vector3,T=new fr.Vector3,A=new fr.Vector3,x=2,E=1/((n.scale.x+n.scale.y+n.scale.z)/3),M=E*E,D=Math.max(0,h.start),_=Math.min(w.count,h.start+h.count);for(let R=D,V=_-1;R<V;R+=x){if(P.fromBufferAttribute(w,R),S.fromBufferAttribute(w,R+1),Fd.distanceSqToSegment(P,S,A,T)>M)continue;A.applyMatrix4(n.matrixWorld);let B=e.ray.origin.distanceTo(A);B<e.near||B>e.far||r.push({distance:B,point:T.clone().applyMatrix4(n.matrixWorld),object:i})}}function g(b,w,P,S,T,A,x){let N=new fr.Vector3,E=new fr.Vector3,M=new fr.Vector3,D=new fr.Vector3,_=new fr.Vector3;if(N.fromBufferAttribute(S,T),E.fromBufferAttribute(S,A),M.fromBufferAttribute(S,x),P.intersectTriangle(N,E,M,!1,D)===null)return null;_.copy(D),_.applyMatrix4(b.matrixWorld);let V=w.ray.origin.distanceTo(_);return V<w.near||V>w.far?null:{faceIndex:1,distance:V,point:_.clone(),object:b}}};var jd=new cr.Vector3,Qr=new cr.Camera,zh=class extends cr.LineSegments{constructor(e){let r=new cr.BufferGeometry,o=new cr.LineBasicMaterial({color:16777215,vertexColors:!0,toneMapped:!1}),n=[],a=[],s={},l=new cr.Color(15711266),c=new cr.Color(15711266),u=new cr.Color(2857471);d("n1","n2",l),d("n2","n4",l),d("n4","n3",l),d("n3","n1",l),d("f1","f2",l),d("f2","f4",l),d("f4","f3",l),d("f3","f1",l),d("n1","f1",l),d("n2","f2",l),d("n3","f3",l),d("n4","f4",l),d("p","n1",c),d("p","n2",c),d("p","n3",c),d("p","n4",c),d("u1","u2",u),d("u2","u3",u),d("u3","u1",u);function d(f,h,m){p(f,m),p(h,m)}function p(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)}r.setAttribute("position",new cr.Float32BufferAttribute(n,3)),r.setAttribute("color",new cr.Float32BufferAttribute(a,3));super(r,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,r=this.pointMap,o=!0;Qr.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;wo("n1",r,e,Qr,-n,-a,s),wo("n2",r,e,Qr,n,-a,s),wo("n3",r,e,Qr,-n,a,s),wo("n4",r,e,Qr,n,a,s);let l=s;wo("f1",r,e,Qr,-n,-a,l),wo("f2",r,e,Qr,n,-a,l),wo("f3",r,e,Qr,-n,a,l),wo("f4",r,e,Qr,n,a,l);let c=l,u=.5;wo("u1",r,e,Qr,n*.7*u,a*1.1,c),wo("u2",r,e,Qr,-n*.7*u,a*1.1,c),wo("u3",r,e,Qr,0,a*(1.1+.9*u),c),e.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}};function wo(i,t,e,r,o,n,a){jd.set(o,n,a).unproject(r);let s=t[i];if(s!==void 0){let l=e.getAttribute("position");for(let c=0,u=s.length;c<u;c++)l.setXYZ(s[c],jd.x,jd.y,jd.z)}}var Ud=class extends Wo(zh){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,r){qo(this.object,this.geometry,e,r,!0)}};var cc=require("three");var kd;(t=>t.is=e=>"objectHelper"in e)(kd||(kd={}));var Zr=(i,t)=>class extends $a(i){constructor(){super(...arguments);this.objectHelper=new t(this);this.gizmos={}}get geometryHelper(){return t.geometryHelper}raycast(o,n){this.objectHelper.raycast(o,n)}showGizmos(){for(let o in this.gizmos){let n=this.gizmos[o];n instanceof cc.Box3Helper&&(n.visible=!0)}}updateEntityBoxSize(o,n){this.objectHelper.visible&&this.geometryHelper instanceof cc.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 cc.Box3Helper&&(n.visible=!1)}}};var Hd=790,Gs=new xt.Vector3,Gh=new xt.Vector3,Fh=new xt.Quaternion,jh=new xt.Vector3,uc=new xt.Vector3,Uh=new xt.Vector3,Si=class extends Zr(xt.Camera,Ud){constructor(e="",r={...En.defaultData,name:""}){super();this._cameraType="OrthographicCamera";this.targetOffset=Fi.DefaultTargetOffset;this.isUpVectorFlipped=!1;this.angleOffsetFromUp=0;this.wasMovedByUser=!1;this.wasMovedBySwitchCameraAction=!1;this.super_Entity(e,r),this.previousProjectionMatrix=new xt.Matrix4,this.matrixAutoUpdate=!0,this.width=window.innerWidth,this.height=window.innerHeight;let o=this.width,n=this.height;this.orthoCamera=new xt.OrthographicCamera(o*-.5,o*.5,n*.5,n*-.5,-5e4,1e4),this.perspCamera=new xt.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,r){e==="PerspectiveCamera"?this.perspCamera.near=r:this.orthoCamera.near=r}setZoom(e,r){r>=0&&(e==="PerspectiveCamera"?this.perspCamera.zoom=r:this.orthoCamera.zoom=r)}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,r,o){typeof e=="number"&&(e=new xt.Vector3(e,r,o)),super.lookAt(e),this.getWorldPosition(Gs),this.targetOffset=Gs.distanceTo(e)}getTarget(e=new xt.Vector3){return this.getWorldDirection(Gh),this.getWorldPosition(Gs),Gh.multiplyScalar(this.targetOffset),e.copy(Gs).add(Gh),e}getDistanceToTarget(){let e=this.getTarget();return this.getWorldPosition(Gs),Gs.distanceTo(e)}updateUp(){this.getWorldQuaternion(Fh),jh.set(0,0,1).applyQuaternion(Fh),uc.copy(xt.Object3D.DEFAULT_UP),this.isUpVectorFlipped&&uc.negate(),uc.applyQuaternion(Fh),Uh.copy(xt.Object3D.DEFAULT_UP).projectOnPlane(jh),this.angleOffsetFromUp=Uh.angleTo(uc),this.angleOffsetFromUp*=Uh.cross(uc).dot(jh)>=0?1:-1}updateTransformState(e,r){let o=super.updateTransformState(e,r);return e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateUp(),o}getViewFrontToObject(e){let r=e.getWorldPosition(new xt.Vector3),n=e.getWorldDirection(new xt.Vector3).multiplyScalar(this.targetOffset);return{position:r.clone().add(n),target:r}}getViewToTarget(e){let o=this.getWorldDirection(new xt.Vector3).multiplyScalar(this.targetOffset);return{position:e.clone().sub(o),target:e}}getViewToObject(e){let r=new xt.Vector3;return e.getWorldPosition(r),this.getViewToTarget(r)}setViewplaneSize(e,r,o=!1){if(this.aspect=e/r,o){let n=e>r?this.aspect:1,a=e>r?1:this.aspect;this.left=-Hd*.5*n,this.right=Hd*.5*n,this.top=Hd*.5*(1/a),this.bottom=-Hd*.5*(1/a)}else this.left=-e*.5,this.right=e*.5,this.top=r*.5,this.bottom=-r*.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,r,o,n,a,s){this._cameraType==="PerspectiveCamera"?this.perspCamera.setViewOffset(e,r,o,n,a,s):this.orthoCamera.setViewOffset(e,r,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,r){super.updateWorldMatrix(e,r),this.matrixWorldInverse.copy(this.matrixWorld).invert()}copy(e,r){return super.copy(e,r),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 r={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 Pa(r,e)}updateCameraSubtype(e,r){let o=e==="perspective"?"PerspectiveCamera":"OrthographicCamera";r.zoom!==void 0&&this.setZoom(o,r.zoom),r.near!==void 0&&this.setNear(o,r.near),r.fov!==void 0&&o==="PerspectiveCamera"&&(this.fov=r.fov)}updateState(e,r){this.updateCameraState(e,r)}updateCameraState(e,r){this.updateState_Entity(e,r),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.map(o=>typeof o=="number"?o:0)),e.targetOffset!==void 0&&(this.targetOffset=e.targetOffset),e.isUpVectorFlipped!==void 0&&(this.isUpVectorFlipped=e.isUpVectorFlipped),this.updateProjectionMatrix()}updateByPatchedOp(e,r,o){super.updateByPatchedOp(e,r,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 X3=require("three");var an=require("three");var Fs=new an.Matrix4,$3=new an.Matrix4;var Nr=class extends Er{constructor(e,r,o){super(e,r);this.data=r;this.meshSetAddresses=[];this.needsTransformForDownstream=!1;this.geometry=new an.BufferGeometry;this.onAfterRender=(e,r,o,n,a,s)=>{super.onAfterRender(e,r,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,r,o){super.updateByPatchedOp(e,r,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,r=!0){if(this.booleanMeshSetAddress!==-1&&!e)return;for(let n=0;n<this.children.length;n++){let a=this.children[n];a instanceof Nr&&a.dataPatched.visible===!0&&a.recomputeBoolean(e===!0,r)}this.meshSetAddresses=[];for(let n=0;n<this.children.length;n++){let a=this.children[n];if(a instanceof Xt&&a.dataPatched.visible===!0&&a.geometry.attributes.position?.count>0&&a.geometry.drawRange.count>0&&a.booleanMeshSetAddress!==0){Fs.multiplyMatrices(a.hiddenMatrix,a.matrix).multiply(a.pivotMatrix);try{if(a.booleanMeshSetAddress===-1){if((a.geometry.index??a.geometry.getAttribute("position")).count/3<15e5&&(a.booleanMeshSetAddress=Xr.getMeshSet(a.geometry,e===!0,r)),a.booleanMeshSetAddress===-1)return;Xr.transformMeshSet(a.booleanMeshSetAddress,Fs),a.booleanMatrixInvOld.copy(Fs).invert(),a.booleanWasTransformed=!1}else a instanceof Nr&&a.needsTransformForDownstream===!0?(Xr.transformMeshSet(a.booleanMeshSetAddress,Fs),a.needsTransformForDownstream=!1):a.booleanWasTransformed===!0&&(Xr.transformMeshSet(a.booleanMeshSetAddress,$3.multiplyMatrices(Fs,a.booleanMatrixInvOld)),a.booleanMatrixInvOld.copy(Fs).invert(),a.booleanWasTransformed=!1)}catch(s){console.error(s),a.booleanMeshSetAddress=0,a.geometry.userData.booleanOperationDidFail=!0;continue}Xr.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 an.Float32BufferAttribute([],0)),this.geometry.setDrawRange(0,0);return}if(e===!0)return Xr.calcBooleanTopological(this.meshSetAddresses,this.booleanOp);let o=this.geometry;o.dispose(),this.geometry=new an.BufferGeometry,this.geometry.userData=o.userData,this.geometry.boundingSphere=o.boundingSphere;try{this.booleanMeshSetAddress=Xr.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,Ls(this),Bs(this)}dispose(){super.dispose(),this.geometry.dispose()}};var Vv=require("three");var Bv;(t=>{function i(e){return Ge.is(e)&&e instanceof Vv.Light}t.is=i})(Bv||(Bv={}));var js=(i,t)=>class extends Zr(i,t){updateState_Light(r,o){this.updateState_Entity(r,o),r.color!==void 0&&(this.color=o.shared.color(r.color)),r.intensity!==void 0&&(this.intensity=r.intensity),r.depth!==void 0&&(this.shadow.camera.far=r.depth,this.shadow.needsUpdate=!0),r.shadows!==void 0&&(this.castShadow=r.shadows)}};var sn=i=>i instanceof Xt,dc=i=>i!==null&&i instanceof Nr;var pc=i=>kd.is(i);var Fv=require("three");var $o=require("three");var Y3=new $o.Vector3(1,1,1),zv=new $o.Vector3,K3=new $o.Vector3,Gv=new $o.Quaternion,Jr=class extends Wo($o.AxesHelper){constructor(e,r=15){super(r);this.object=e;this.dummy=new $o.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,r){qo(this.object,Jr.geometryHelper,e,r,!1,this.dummy)}update(){}updateMatrix(){}updateMatrixWorld(e){this.object.matrixWorld.decompose(zv,Gv,K3),this.matrix.compose(zv,Gv,Y3),super.updateMatrixWorld(e)}updateWorldMatrix(e,r){}};var ln=class extends Zr(Fv.Group,Jr){constructor(t,e){super(),this.super_Entity(t,e),this.objectHelper.update()}updateState(t,e){this.updateState_Entity(t,e),"buffer"in t&&Object.keys(t).length===1&&e.scene.reloadSplats()}};var jv=require("three");var Us=class extends Zr(jv.Group,Jr){constructor(e,r,o){super();this.super_Entity(e,r),this.context=o,this.objectHelper.update()}updateState(e,r){this.updateState_Entity(e,r)}};var Ks=require("three");var ks=require("three"),Q3=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 Ce.Vector2},viewport:{type:"v2",value:new Ce.Vector2},basisViewport:{type:"v2",value:new Ce.Vector2},debugColor:{type:"v3",value:new Ce.Color},covariancesTextureSize:{type:"v2",value:new Ce.Vector2(1024,1024)},centersColorsTextureSize:{type:"v2",value:new Ce.Vector2(1024,1024)},orthoZoom:{type:"f",value:-1}};return new Ce.ShaderMaterial({uniforms:n,vertexShader:r,fragmentShader:o,transparent:!0,alphaTest:1,blending:Ce.NormalBlending,depthTest:!0,depthWrite:!1,side:Ce.DoubleSide})}static buildGeomtery(e){let r=new Ce.BufferGeometry;r.setIndex([0,1,2,0,2,3]);let o=new Float32Array(4*3),n=new Ce.BufferAttribute(o,3);r.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 Ce.InstancedBufferGeometry().copy(r),s=new Uint32Array(e),l=new Ce.InstancedBufferAttribute(s,1,!1);return l.setUsage(Ce.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,r=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(r,r+a*3).set(n.decoded.xyz.denormDequant().data),r+=a*3,this.covariances.subarray(o,o+a*6).set(new Float32Array(n.precomputedCovarianceBufferData)),o+=a*6}}allocateAndStoreLocalSplatDataInTextures(){let o=this.splatCount,n=new Ce.Vector2(4096,1024);for(;n.x*n.y*2<o*6;)n.y*=2;let a=new Ce.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]=Ce.DataUtils.toHalfFloat(this.covariances[h]);s=new Ce.DataTexture(l,n.x,n.y,Ce.RGFormat,Ce.HalfFloatType)}else l=new Float32Array(n.x*n.y*2),l.set(this.covariances),s=new Ce.DataTexture(l,n.x,n.y,Ce.RGFormat,Ce.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,g=h*4;c[g]=oS(this.colors[m],this.colors[m+1],this.colors[m+2],this.colors[m+3]),c[g+1]=pp(this.centers[y]),c[g+2]=pp(this.centers[y+1]),c[g+3]=pp(this.centers[y+2])}let u=new Ce.DataTexture(c,a.x,a.y,Ce.RGBAIntegerFormat,Ce.UnsignedIntType);u.internalFormat="RGBA32UI",u.needsUpdate=!0,this.material.uniforms.centersColorsTexture.value=u,this.material.uniforms.centersColorsTextureSize.value.copy(a);let d=256*4,p=new Float32Array(256*16);for(let h=0;h<this.meshMatrixWorlds.length;h++)p.set(this.meshMatrixWorlds[h].elements,h*16);let f=new Ce.DataTexture(p,d,1,Ce.RGBAFormat,Ce.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:p,texture:f}}}updateIndexes(e){let r=this.geometry;r.attributes.splatIndex.set(e),r.attributes.splatIndex.needsUpdate=!0,r.instanceCount=e.length}updateUniforms(e,r,o,n){this.splatCount>0&&(fp.set(e.x*this.devicePixelRatio,e.y*this.devicePixelRatio),this.material.uniforms.viewport.value.copy(fp),this.material.uniforms.basisViewport.value.set(2/fp.x,2/fp.y),this.material.uniforms.focal.value.set(r,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 nS,am=new Promise(i=>{nS=i}),iS=!1;var mp;function sm(){if(iS)return;if(mp)return mp;async function i(){let e=await import("./gaussian-splat-compression.js");nS(e),iS=!0}return mp=i(),mp}var aS;am.then(i=>aS=i);var Sc=class{constructor(t={}){wn(this,"updateView",function(){let t=new vr.Matrix4,e=[],r=new vr.Vector3(0,0,-1),o=new vr.Vector3(0,0,-1),n=new vr.Vector3,a=new vr.Vector3;return function(s=!1,l){let c=this.updateMatrixWorldsInWorkerIfNeeded(),u=this.cropsChanged();if(!s){o.set(0,0,-1).applyQuaternion(l.quaternion);let p=!1,f=!1;if(o.dot(r)<=.95&&(p=!0),a.copy(l.position).sub(n).length()>=1&&(f=!0),!p&&!f&&!c&&!u&&!this.needsInitialRender)return}this.needsInitialRender=!1,n.copy(l.position),r.copy(o),t.copy(l.matrixWorld).invert(),t.premultiply(this.dummyPerspectiveMatrix),e[0]=l.position.x,e[1]=l.position.y,e[2]=l.position.z;let d={sort:{view:t.elements,cameraPosition:e,splatRenderCount:this.splatRenderCount,splatSortCount:this.splatRenderCount},...c?{newMatrixWorlds:this.meshMatrixWorlds}:{},...u?{newCropsArray:this.cropsArray}:{}};this.sortRunning?this.queuedMessage=d:(this.queuedMessage=null,this.sortRunning=!0,this.sortWorker.postMessage(d))}}());this.scene=t.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 vr.Matrix4().makePerspective(-1,1,-1,1,.1,1e3)}updateSplatMeshUniforms(t,e){let r=new vr.Vector2;if(this.splatMesh===null)return;this.splatMesh.getSplatCount()>0&&(t.getSize(r),this.cameraFocalLengthX=e.projectionMatrix.elements[0]*this.devicePixelRatio*r.x*.45,this.cameraFocalLengthY=e.projectionMatrix.elements[5]*this.devicePixelRatio*r.y*.45,this.splatMesh.updateUniforms(r,this.cameraFocalLengthX,this.cameraFocalLengthY,e.isPerspectiveCamera?-1:e.zoom*this.devicePixelRatio))}loadSplat(t={}){this.activePage=this.scene.activePage,t.position&&(t.position=new vr.Vector3().fromArray(t.position)),t.orientation&&(t.orientation=new vr.Quaternion().fromArray(t.orientation)),t.halfPrecisionCovariances=!!t.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 r=e.map(a=>new aS.GSplineBuffer(new Uint8Array(a.data.buffer).buffer)),o=0,n=[0];for(let a of r)o+=a.getSplatCount(),n.push(o);return this.setupSplatMesh(r,o,t.position,t.orientation,t.halfPrecisionCovariances,this.devicePixelRatio,n,this.meshMatrixWorlds),this.setupSortWorker(o),!0}updateMatrixWorldsInWorkerIfNeeded(){let t=this.splatDataTextures.meshMatrixWorlds.data;for(let e=0;e<this.meshMatrixWorlds.length;e++)t.set(this.meshMatrixWorlds[e].elements,e*16);return this.splatDataTextures.meshMatrixWorlds.texture.needsUpdate=!0,this.meshMatrixWorlds.every((e,r)=>e.equals(this.meshMatrixWorldsOld[r]))?!1:(this.meshMatrixWorldsOld=this.meshMatrixWorlds.map(e=>e.clone()),!0)}cropsChanged(){let t=!1;return this.splatEntries.forEach((e,r)=>{e.data.crops.forEach((o,n)=>{this.cropsArray[r][n]===void 0?(t=!0,this.cropsArray[r][n]=o.data):Object.entries(o.data).forEach(([a,s])=>{Array.isArray(s)&&s.some((l,c)=>l!==this.cropsArray[r][n][a][c])?(t=!0,this.cropsArray[r][n][a]=s):s!==this.cropsArray[r][n]?.[a]&&(t=!0,this.cropsArray[r][n][a]=s)})}),e.data.crops.length!==this.cropsArray[r]?.length&&(this.cropsArray[r].length=e.data.crops.length,t=!0)}),t}setupSplatMesh(t,e,r=new vr.Vector3,o=new vr.Quaternion,n=!1,a=1,s,l){this.splatMesh=yn.buildMesh(t,e,n,a,s,l),this.splatMesh.position.copy(r),this.splatMesh.quaternion.copy(o),this.splatMesh.frustumCulled=!1,this.splatMesh.renderOrder=99999,this.splatRenderCount=e,this.splatMesh.onBeforeRender=(c,u,d)=>this.update(c,d)}setupSortWorker(t){this.sortWorker=rS(t),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(t,e){this.splatMesh!==null&&(this.updateSplatMeshUniforms(t,e),this.updateView(!1,e))}getSplatMesh(){return this.splatMesh}};var LE=new oo.MeshBasicMaterial;LE.wireframe=!0;var sS=new oo.Vector3,yp=class extends oo.Scene{constructor(e,r){super();this.data=e;this.sharedAssets=r;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 dp;this.invisibleObjects=new ln("jflkdsafjasdifjaslk",{...Du.defaultData,visible:!1,name:"buildin invisible"});this.needsRecomputeInstances=!1;this.init(e,r),this.matrixAutoUpdate=!1,this.errorPage=new to("fdasfa",{...ii.defaultData,name:""},{shared:r,scene:this})}markGeometryCacheDirty(){this.geometryCacheChanged=!0}markNeedsUpdateRendererDirty(){this.needsTransmissionDirty=!0,this.needsNormalDirty=!0}needsTransmission(){return this.needsTransmissionDirty&&(this._needsTransmission=eS(this),this.needsTransmissionDirty=!1),this._needsTransmission}needsNormal(){return this.needsNormalDirty&&(this._needsNormal=J1(this),this.needsNormalDirty=!1),this._needsNormal}registerInstanceAndSetUuid(e){let r=e.identity.join("-"),o=this.entityIdentityToEntity[r];o&&(e.uuid=o.uuid),this.entityIdentityToEntity[r]=e,this.entityByUuid[e.uuid]=e}markPenumbraSizeDirty(){for(let e of this.children)e instanceof to&&(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 r=this.find(e);if(r===void 0)return;let o=[],n=r;for(;n!==this;){let a=n;n=n.parent;let s=n.children.indexOf(a);o.splice(0,0,s)}return{entity:r,sortKey:o}}getAllSorted(e){let r=[];for(let o of e){let n=this.getWithSortKey(o.id);n!==void 0&&r.push(n)}return r.sort((o,n)=>Ec(o.sortKey,n.sortKey)),r.map(o=>o.entity)}nonExistOrDescendantOf(e,r){let o=this.find(e);if(o===void 0)return!0;for(;o;){if(o.uuid===r)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===zi)return this.activePage.personalCamera}if(e===""||e===void 0)return;let r=this.entityByUuid[e];return r===void 0?this.getObjectByProperty("uuid",e):r}find2D(e){for(let r of this.children)if(r instanceof to&&r.uiScene){let o=r.uiScene.find(e);if(o)return o}}findScene2DfromObject2D(e){for(let r of this.children)if(r instanceof to&&r.uiScene&&r.uiScene.find(e))return r.uiScene}find2DInUIObjects(e){let r;return this.traverseEntity(o=>{r===void 0&&o instanceof Qn&&(r=o.uiCanvas.find(e))}),r}traverse2D(e){for(let r of this.children)r instanceof to&&r.uiScene&&r.uiScene.traverse(e)}debugEnsureEntity(e){let r=this.find(e);if(r){if(Array.isArray(r.identity)&&this.findInstance(r.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(r=>{this.toExpandCloner.add(r)})}doPendingExpandCloner(e){this.toExpandCloner.forEach(r=>{r.expandCloner(e)}),this.toExpandCloner.clear()}doPendingUpdateCloner(e){this.toUpdateCloner.forEach(r=>{r.cloner?.update(e)}),this.toUpdateCloner.clear()}doPendingUpdates(e){this.doPendingExpandCloner(e),this.doPendingUpdateCloner(e),this.applyPendingCommands()}addPendingCommand(e){this.pendingCommands.push(e)}applyPendingCommands(){this.pendingCommands.forEach(e=>e()),this.pendingCommands.length=0}updateByLibOp(e,r){e.path.length===1&&e.path[0]==="components"&&e.type===1&&this.createChildrenObjects([{...e.data.asset,id:e.id}],this.invisibleObjects,r)}updateTreeByOp(e,r){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,r);n.updateVisible(this),n.resetBBoxNeedsUpdate(),sn(n)&&dc(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 fn&&(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),dc(o.parent)&&(o.parent.invalidateUpstreamBooleanData(),o.parent.invalidateDownstreamBooleanData().recomputeBoolean()),sn(o)&&(o.freeBooleanPointer(),n instanceof Nr&&n.invalidateDownstreamBooleanData().recomputeBoolean()),o instanceof Qs&&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()),sn(o)&&(o.invalidateUpstreamBooleanData(),dc(o.parent)?o.parent.invalidateDownstreamBooleanData().recomputeBoolean():n instanceof Nr&&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 r of this.children)r instanceof to&&(r.visible=r.uuid===e,r.visible&&(this.activePage=r,this.activePage.onActive(this)));this.activePage!==this.splatViewer?.activePage&&this.reloadSplats()}updateEntityByOp(e,r,o,n){if(r.type===0){if(("overrides"in r.props||"component"in r.props)&&this.markNeedsRecomputeInstances(),"visible"in r.props&&this.markPenumbraSizeDirty(),r.path.includes("overrides")&&"states"in r.props){let{rest:s}=r.props;r={...r,props:s},this.markNeedsRecomputeInstances()}r.path[0]==="pathSnapping"&&r.props.pathId!==void 0&&this.pathConstraints.setConstraint(e,r.props.pathId)}let a=this.find(e);if(a)try{$1(a,r,o,{scene:this,shared:n}),a instanceof ht&&a.updateGeometryGroupsIfNeeded()}catch(s){console.error(s)}}updateEntity2DByOp(e,r,o,n,a,s=[]){e.updateEntityByOp(r,o,n,a),this.traverseEntity(l=>{(l instanceof Qn||l instanceof to)&&(s.includes(l.frameId??"")||l.frameId===r)&&l.updateEntity2DByOp(r,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,r){let o=Object.entries(r.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:r}),this.add(this.invisibleObjects),this.createChildrenObjects(o,this.invisibleObjects,r),this.createChildrenObjects(e.objects,this,r),this.updatePage(e.publish.playPage),this.activePage.switchToPlayCamera(),this.expandInstances(r,!0),this.traverseEntity(n=>{n instanceof Si&&n.updateUp()}),this.doPendingExpandCloner({scene:this,shared:r}),this.applyPendingCommands()}markNeedsRecomputeInstances(){this.needsRecomputeInstances=!0}markNeedsRecomputeInstancesForChildren(e){e.traverseEntity(r=>{(r.data.type==="Component"||r.data.type==="Instance")&&this.markNeedsRecomputeInstances()})}markNeedsRecomputeInstancesForAncessors(e){Ge.is(e)&&(e.data.type==="Component"&&this.markNeedsRecomputeInstances(),e.traverseAncestors(r=>{Ge.is(r)&&r.data.type==="Component"&&this.markNeedsRecomputeInstances()}))}relativeizeInner(e,r,o,n,a,s,l){if(e){let c=n.find(e);c&&c!==n&&a.forInstancesRec(u=>{u.data=Di(u.data,d=>{let p=d.events.data(l.id),f=u.goUp(s);if(f){let h=[...Ic(f.identity),e].join("-"),m=this.entityIdentityToEntity[h];if(m){let y=m.uuid,g=dt.zoom(p,r);g[o]=y}else{if(!1)debugger;console.warn("cannot find instance")}}}).data})}}rewriteActions(e,r,o,n,a,s){e.forEach(l=>{l.data.type==="Transition"?this.relativeizeInner(l.data.object,[...r,l.id],"object",o,n,a,s):l.data.type==="Animation"?this.relativeizeInner(l.data.object,[...r,l.id],"object",o,n,a,s):l.data.type==="Conditional"&&(this.rewriteActions(l.data.ifActions,[...r,l.id,"ifActions"],o,n,a,s),this.rewriteActions(l.data.elseActions,[...r,l.id,"elseActions"],o,n,a,s))})}rewriteEventsBeforeGoToPlayMode(){this.traverseEntity(e=>{if(e instanceof Oi&&typeof e.identity=="string"&&e.data.type==="Component")return e.traverseEntity((r,o)=>{r.data.events.forEach(n=>{if(n.data.type==="GameControl"){let a=!1;if(r.forInstancesRec(s=>{s.data=Di(s.data,l=>{s.isInstanceRoot||(l.events.delete(n.id),a=!0)}).data}),a===!1)for(let s of Bu.list)this.rewriteActions(n.data.gameActions[s],["gameActions",s],e,r,o,n)}else n.data.type==="Conditional"?(n.data.condition.type==="Distance"?(this.relativeizeInner(n.data.condition.fromObject,["condition"],"fromObject",e,r,o,n),this.relativeizeInner(n.data.condition.toObject,["condition"],"toObject",e,r,o,n)):n.data.condition.type==="State"?this.relativeizeInner(n.data.condition.object,["condition"],"object",e,r,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,r,o,n),n.data.condition.rOperand.type==="Property"&&this.relativeizeInner(n.data.condition.rOperand.value[0],["condition","rOperand","value"],0,e,r,o,n)),this.rewriteActions(n.data.inActions,["inActions"],e,r,o,n),this.rewriteActions(n.data.outActions,["outActions"],e,r,o,n)):"actions"in n.data&&this.rewriteActions(n.data.actions,["actions"],e,r,o,n)})}),!0})}expandInstances(e,r,o){let n=new Set;this.traverseEntity(a=>{if(a instanceof Oi&&a.isInstanceRoot)return a.expandInstanceChildren({scene:this,shared:e,pendingDeletes:n}),r||a.resetBBoxNeedsUpdate(),o&&a.traverseEntity(s=>{o.addClip(s)}),!0});for(let a of n)this.disposeAndUnregisterEntityRecursivelyIfNotReregistered(a),ip(a)}recomputeInstances(e,r){this.needsRecomputeInstances&&(this.needsRecomputeInstances=!1,this.traverseEntity(o=>{o instanceof Oi&&o.isInstanceRoot&&(o.component=void 0)}),this.expandInstances(e,!1,r))}disposeAndUnregisterEntityRecursivelyIfNotReregistered(e){e.traverseEntity(r=>{let o=typeof r.identity=="string"?r.identity:r.identity.join("-");this.entityIdentityToEntity[o]===r&&(delete this.entityByUuid[r.uuid],delete this.entityIdentityToEntity[o]),r.dispose()})}clearScene(){for(let e of this.children)Ge.is(e)&&e.disposeRecursively();this.children.length=0}resetAfterClear(e,r){this.init(e,r)}raycast(e){return this.raycast1(e,!1)}raycast1(e,r){let o=[],n=a=>{for(let s of a.children){let l=s.cloner;if(Ge.is(s)&&!s.raycastLock&&(s.visible||l?.object.data.visible))if(r===!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 d=s.matrixWorld.clone().invert();u.point.applyMatrix4(d),o.push(u)}}else(sn(s)||pc(s)&&this.enableHelpers&&s.objectHelper.visible)&&(e.intersectObject(s,!1,o),bc(s,e,o)),n(s)}};return n(this.activePage),o}raycastWithClones(e){let r=[],o=n=>{for(let a of n.children){let s=a.cloner;Ge.is(a)&&(a.visible||s?.object.data.visible)&&((sn(a)||pc(a)&&this.enableHelpers&&a.objectHelper.visible)&&(e.intersectObject(a,!1,r),bc(a,e,r,!0)),o(a))}};return o(this),r}forEachEntity(e){for(let r of this.children)Ge.is(r)&&e(r)}traverseConcreteEntity(e){for(let r of this.children)Ge.is(r)&&r.isConcreteEntity&&r.traverseEntity(e)}traverseEntity(e){for(let r of this.children)Ge.is(r)&&r.traverseEntity(e)}updateFont(e,r){this.traverseEntity(o=>{if(o instanceof ht&&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,r).then(()=>{n.update(a,r);let s=o.invalidateDownstreamBooleanData();dc(s)&&s.recomputeBoolean()})}})}traverseObject(e){for(let r of this.children)di.is(r)&&r.traverseObject(e)}traverseVisibleEntity(e){for(let r of this.children)Ge.is(r)&&r.visible&&r.traverseVisibleEntity(e)}dispose(){this.clearScene()}createChildrenObjects(e,r,o){let n=0;for(let a of e)this.createObject(a.id,a.data,a.children,r,n,o),n+=1}registerObjectCreatedInLegacy(e){this.entityByUuid[e.uuid]=e}unregisterObject(e){delete this.entityByUuid[e.uuid];for(let r of e.children)this.unregisterObject(r)}createObject(e,r,o,n,a,s){let l={scene:this,shared:s},c=lp(e,r,l);return c instanceof fn&&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(r,l),c instanceof ht&&c.updateGeometryGroupsIfNeeded(),c.updateVisible(this),c.cloner&&this.toExpandCloner.add(c),r.pathSnapping?.pathId&&this.pathConstraints.setConstraint(e,r.pathSnapping.pathId)),r.type==="Empty"&&r.animations&&c.traverseEntity(u=>{let d=u.dataPatched;if(u instanceof ht&&d.bones&&d.boneInverses){let p=d.bones.map(m=>this.find(m)),f=d.boneInverses.map(m=>new oo.Matrix4().fromArray(m)),h=new oo.Skeleton(p,f);u.bind(h,u.bindMatrix)}else u.matrixAutoUpdate=!0}),c}getCenter(e){let r=[];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;r.push(...u.vertices)}let o=new oo.Box3;return o.setFromPoints(r),o.getCenter(sS),sS}copyMatrixWorld(e,r){if(e===null){r.identity();return}let o=this.find(e);o?r.copy(o.matrixWorld):r.identity()}copyParentMatrixWorld(e,r){if(e===null){r.identity();return}let o=this.find(e)?.parent;o?r.copy(o.matrixWorld):r.identity()}traverseMaterial(e){this.traverseEntity(r=>{if(r instanceof Xt)if(Array.isArray(r.material))for(let o=0;o<r.material.length;o++)r.material[o]instanceof Ir&&e(r.material[o]);else r.material instanceof Ir&&e(r.material)})}updateViewPlaneSize(e,r,o=!1){this.traverseConcreteEntity(n=>{n instanceof Si&&n.setViewplaneSize(e,r,o)})}initializeSplatViewer(){this.splatViewer=new Sc({scene:this}),this.reloadSplats()}reloadSplats(){this.splatViewer?.loadSplat()}};var lS=require("three/examples/jsm/loaders/DRACOLoader.js");var gn;function cS(i){return gn||(gn=new lS.DRACOLoader,gn.setDecoderPath(i?`${i}/`:"https://www.gstatic.com/draco/versioned/decoders/1.5.2/").preload()),gn.decoderPending}async function BE(i){if(gn){let t={attributeIDs:gn.defaultAttributeIDs,attributeTypes:gn.defaultAttributeTypes,useUniqueIDs:!1},e;try{e=await gn.decodeGeometry(new Int8Array(i).buffer,t)}catch(r){console.error(r)}if(e)return{index:e.index?{array:e.index.array}:void 0,attributes:Object.entries(e.attributes).map(([r,o])=>({name:r,itemSize:o.itemSize,array:o.array}))}}return null}async function uS(i,t){let[e,r]=Up(bu.deserialize(new Uint8Array(i)));return zu(e),t&&t(e),r.result().data}function dS(i){let t=[];return i.scene.objects.traverse((e,r)=>{r.type==="Mesh"&&r.geometry.type==="NonParametricGeometry"&&r.geometry.data.draco!==void 0&&t.push(r)}),t}async function pS(i){for(let t of i){let e=await BE(t.geometry.data.draco);if(e){let r=t.geometry.data;e.index&&(r.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}}),r.attributes=o,r.draco=void 0}}}var VE=require("three"),zE=require("three/examples/jsm/utils/BufferGeometryUtils.js");function fS(i){let t;if(!!i.index)for(let e=0;e<i.index.array.length;e+=3)t=i.index.array[e],i.index.array[e]=i.index.array[e+2],i.index.array[e+2]=t}var wc=require("three");function hS(i){let t=new Set;return i.traverse(e=>{if(e instanceof Er)if(Mt(e.material))e.material.forEach(r=>{let o=r;t.has(o)||t.add(o)});else{let r=e.material;t.has(r)||t.add(r)}}),t.forEach(e=>{if(e instanceof Array)return;let r=e.onBeforeCompile.bind(e);if(GE(e)){Object.assign(e,{isMeshStandardMaterial:!0,isMeshPhysicalMaterial:!0,transmission:1,attenuationColor:new wc.Color,specularColor:new wc.Color});let o=0;e.onBeforeCompile=(n,a)=>{r&&r(n,a),n.uniforms=Object.assign({},wc.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=Yb(window.innerWidth,window.innerHeight),e.defines.IS_THREEJS_EXPORT=!0)}else o++,o<2&&(e.needsUpdate=!0)})}}else FE(e)||(e.onBeforeCompile=(o,n)=>{r&&r(o,n),e.transparent=!1})}),i}function GE(i){return i.getLayersOfType("transmission").length>0}function FE(i){let t=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&&(t+=(1-t)*o.value)}}return t<1}function mS(i){return i.traverse(t=>{if(t.type==="Camera"){let e=t;e.type=e.cameraType}}),i}function yS(i){let t=[],e=(r,o=0)=>{let n=o>0?r+o:r;return t.includes(n)?e(r,o+1):n};return i.traverse(r=>{if(t.includes(r.name)){let o=r.name,n=e(r.name);if(r.name=n,r.isMesh){let a=r;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))}}t.push(r.name)}),i}var gS=require("three/examples/jsm/utils/BufferGeometryUtils.js");function xS(i){let t=[];return i.traverse(e=>{e instanceof nn&&t.push(e)}),t.forEach(e=>{let r=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&&fS(l),l}).filter(s=>s!==void 0)];if(!e.parameters.hideBase&&r instanceof Xt&&a.unshift(r.geometry),a.length){let s=(0,gS.mergeBufferGeometries)(a);r instanceof Xt&&(r.geometry=s)}e.removeFromParent(),r.setFromClonerState(null,{scene:i,shared:fv})}),i}function bS(i){return i.traverse(t=>{t.matrixAutoUpdate=!0}),i}function vS(i){Object.values(i.shared.materials).forEach(t=>{lm(t)}),i.scene.objects.traverse((t,e)=>{"material"in e?lm(e.material):"materials"in e&&e.materials.forEach(r=>{lm(r)})})}function lm(i){if(typeof i=="string")return;let t=[];i.layers.forEach((e,r)=>{e.type==="outline"&&t.push(r)}),t.reverse().forEach(e=>{i.layers.delete(e)}),t.length&&console.warn("The Spline Loader currently does not support the outline layer.")}var OS=ll(wS(),1);var PS="The SplineLoader only accepts .splinecode files that are generated from Spline export panel.",gp=class extends xp.Loader{load(t,e,r,o=console.error){let n=new xp.FileLoader(this.manager);n.setPath(this.path),n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),t.endsWith(".spline")?console.warn(PS+" The .spline files are only meant to be used by the Editor."):t.endsWith(".splinecode")||console.warn(PS),n.load(t,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)}},r,o)}async parse(t){let e=await uS(t,vS),r=dS(e);e.version&&(0,OS.default)(e.version,"1.12.41")>0&&console.warn("Your .splinecode file is more recent than the library. Please upgrade @splinetool/loader to the latest version."),await Promise.allSettled([r.length&&cS(),xv(e)&&Pb(),Mv(e)&&av(),l1(e)&&n1(),hp(e)&&sm()].filter(Boolean)),r.length&&await pS(r);let o=!1,n=new qn(e.shared,{},o);Object.values(n.getMaterials()).forEach(l=>Object.assign(l,{isAsset:!0}));let a=new yp(e.scene,n);hp(e)&&a.initializeSplatViewer();let s=a.activeCamera;return s&&Object.assign(s,{makeDefault:!0}),a=xS(a),a=hS(a),a=mS(a),a=yS(a),a=bS(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 Ce.Vector2},viewport:{type:"v2",value:new Ce.Vector2},basisViewport:{type:"v2",value:new Ce.Vector2},debugColor:{type:"v3",value:new Ce.Color},covariancesTextureSize:{type:"v2",value:new Ce.Vector2(1024,1024)},centersColorsTextureSize:{type:"v2",value:new Ce.Vector2(1024,1024)},orthoZoom:{type:"f",value:-1}};return new Ce.ShaderMaterial({uniforms:n,vertexShader:r,fragmentShader:o,transparent:!0,alphaTest:1,blending:Ce.NormalBlending,depthTest:!0,depthWrite:!1,side:Ce.DoubleSide})}static buildGeomtery(e){let r=new Ce.BufferGeometry;r.setIndex([0,1,2,0,2,3]);let o=new Float32Array(4*3),n=new Ce.BufferAttribute(o,3);r.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 Ce.InstancedBufferGeometry().copy(r),s=new Uint32Array(e),l=new Ce.InstancedBufferAttribute(s,1,!1);return l.setUsage(Ce.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,r=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(r,r+a*3).set(n.decoded.xyz.denormDequant().data),r+=a*3,this.covariances.subarray(o,o+a*6).set(new Float32Array(n.precomputedCovarianceBufferData)),o+=a*6}}allocateAndStoreLocalSplatDataInTextures(){let o=this.splatCount,n=new Ce.Vector2(4096,1024);for(;n.x*n.y*2<o*6;)n.y*=2;let a=new Ce.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]=Ce.DataUtils.toHalfFloat(this.covariances[h]);s=new Ce.DataTexture(l,n.x,n.y,Ce.RGFormat,Ce.HalfFloatType)}else l=new Float32Array(n.x*n.y*2),l.set(this.covariances),s=new Ce.DataTexture(l,n.x,n.y,Ce.RGFormat,Ce.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,g=h*4;c[g]=oS(this.colors[m],this.colors[m+1],this.colors[m+2],this.colors[m+3]),c[g+1]=pp(this.centers[y]),c[g+2]=pp(this.centers[y+1]),c[g+3]=pp(this.centers[y+2])}let u=new Ce.DataTexture(c,a.x,a.y,Ce.RGBAIntegerFormat,Ce.UnsignedIntType);u.internalFormat="RGBA32UI",u.needsUpdate=!0,this.material.uniforms.centersColorsTexture.value=u,this.material.uniforms.centersColorsTextureSize.value.copy(a);let d=256*4,p=new Float32Array(256*16);for(let h=0;h<this.meshMatrixWorlds.length;h++)p.set(this.meshMatrixWorlds[h].elements,h*16);let f=new Ce.DataTexture(p,d,1,Ce.RGBAFormat,Ce.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:p,texture:f}}}updateIndexes(e){let r=this.geometry;r.attributes.splatIndex.set(e),r.attributes.splatIndex.needsUpdate=!0,r.instanceCount=e.length}updateUniforms(e,r,o,n){this.splatCount>0&&(fp.set(e.x*this.devicePixelRatio,e.y*this.devicePixelRatio),this.material.uniforms.viewport.value.copy(fp),this.material.uniforms.basisViewport.value.set(2/fp.x,2/fp.y),this.material.uniforms.focal.value.set(r,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 nS,am=new Promise(i=>{nS=i}),iS=!1;var mp;function sm(){if(iS)return;if(mp)return mp;async function i(){let e=await import("./gaussian-splat-compression.js");nS(e),iS=!0}return mp=i(),mp}var aS;am.then(i=>aS=i);var Sc=class{constructor(t={}){wn(this,"updateView",function(){let t=new vr.Matrix4,e=[],r=new vr.Vector3(0,0,-1),o=new vr.Vector3(0,0,-1),n=new vr.Vector3,a=new vr.Vector3;return function(s=!1,l){let c=this.updateMatrixWorldsInWorkerIfNeeded(),u=this.cropsChanged();if(!s){o.set(0,0,-1).applyQuaternion(l.quaternion);let p=!1,f=!1;if(o.dot(r)<=.95&&(p=!0),a.copy(l.position).sub(n).length()>=1&&(f=!0),!p&&!f&&!c&&!u&&!this.needsInitialRender)return}this.needsInitialRender=!1,n.copy(l.position),r.copy(o),t.copy(l.matrixWorld).invert(),t.premultiply(this.dummyPerspectiveMatrix),e[0]=l.position.x,e[1]=l.position.y,e[2]=l.position.z;let d={sort:{view:t.elements,cameraPosition:e,splatRenderCount:this.splatRenderCount,splatSortCount:this.splatRenderCount},...c?{newMatrixWorlds:this.meshMatrixWorlds}:{},...u?{newCropsArray:this.cropsArray}:{}};this.sortRunning?this.queuedMessage=d:(this.queuedMessage=null,this.sortRunning=!0,this.sortWorker.postMessage(d))}}());this.scene=t.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 vr.Matrix4().makePerspective(-1,1,-1,1,.1,1e3)}updateSplatMeshUniforms(t,e){let r=new vr.Vector2;if(this.splatMesh===null)return;this.splatMesh.getSplatCount()>0&&(t.getSize(r),this.cameraFocalLengthX=e.projectionMatrix.elements[0]*this.devicePixelRatio*r.x*.45,this.cameraFocalLengthY=e.projectionMatrix.elements[5]*this.devicePixelRatio*r.y*.45,this.splatMesh.updateUniforms(r,this.cameraFocalLengthX,this.cameraFocalLengthY,e.isPerspectiveCamera?-1:e.zoom*this.devicePixelRatio))}loadSplat(t={}){this.activePage=this.scene.activePage,t.position&&(t.position=new vr.Vector3().fromArray(t.position)),t.orientation&&(t.orientation=new vr.Quaternion().fromArray(t.orientation)),t.halfPrecisionCovariances=!!t.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 r=e.map(a=>new aS.GSplineBuffer(new Uint8Array(a.data.buffer).buffer)),o=0,n=[0];for(let a of r)o+=a.getSplatCount(),n.push(o);return this.setupSplatMesh(r,o,t.position,t.orientation,t.halfPrecisionCovariances,this.devicePixelRatio,n,this.meshMatrixWorlds),this.setupSortWorker(o),!0}updateMatrixWorldsInWorkerIfNeeded(){let t=this.splatDataTextures.meshMatrixWorlds.data;for(let e=0;e<this.meshMatrixWorlds.length;e++)t.set(this.meshMatrixWorlds[e].elements,e*16);return this.splatDataTextures.meshMatrixWorlds.texture.needsUpdate=!0,this.meshMatrixWorlds.every((e,r)=>e.equals(this.meshMatrixWorldsOld[r]))?!1:(this.meshMatrixWorldsOld=this.meshMatrixWorlds.map(e=>e.clone()),!0)}cropsChanged(){let t=!1;return this.splatEntries.forEach((e,r)=>{e.data.crops.forEach((o,n)=>{this.cropsArray[r][n]===void 0?(t=!0,this.cropsArray[r][n]=o.data):Object.entries(o.data).forEach(([a,s])=>{Array.isArray(s)&&s.some((l,c)=>l!==this.cropsArray[r][n][a][c])?(t=!0,this.cropsArray[r][n][a]=s):s!==this.cropsArray[r][n]?.[a]&&(t=!0,this.cropsArray[r][n][a]=s)})}),e.data.crops.length!==this.cropsArray[r]?.length&&(this.cropsArray[r].length=e.data.crops.length,t=!0)}),t}setupSplatMesh(t,e,r=new vr.Vector3,o=new vr.Quaternion,n=!1,a=1,s,l){this.splatMesh=yn.buildMesh(t,e,n,a,s,l),this.splatMesh.position.copy(r),this.splatMesh.quaternion.copy(o),this.splatMesh.frustumCulled=!1,this.splatMesh.renderOrder=99999,this.splatRenderCount=e,this.splatMesh.onBeforeRender=(c,u,d)=>this.update(c,d)}setupSortWorker(t){this.sortWorker=rS(t),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(t,e){this.splatMesh!==null&&(this.updateSplatMeshUniforms(t,e),this.updateView(!1,e))}getSplatMesh(){return this.splatMesh}};var LE=new oo.MeshBasicMaterial;LE.wireframe=!0;var sS=new oo.Vector3,yp=class extends oo.Scene{constructor(e,r){super();this.data=e;this.sharedAssets=r;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 dp;this.invisibleObjects=new ln("jflkdsafjasdifjaslk",{...Du.defaultData,visible:!1,name:"buildin invisible"});this.needsRecomputeInstances=!1;this.init(e,r),this.matrixAutoUpdate=!1,this.errorPage=new to("fdasfa",{...ii.defaultData,name:""},{shared:r,scene:this})}markGeometryCacheDirty(){this.geometryCacheChanged=!0}markNeedsUpdateRendererDirty(){this.needsTransmissionDirty=!0,this.needsNormalDirty=!0}needsTransmission(){return this.needsTransmissionDirty&&(this._needsTransmission=eS(this),this.needsTransmissionDirty=!1),this._needsTransmission}needsNormal(){return this.needsNormalDirty&&(this._needsNormal=J1(this),this.needsNormalDirty=!1),this._needsNormal}registerInstanceAndSetUuid(e){let r=e.identity.join("-"),o=this.entityIdentityToEntity[r];o&&(e.uuid=o.uuid),this.entityIdentityToEntity[r]=e,this.entityByUuid[e.uuid]=e}markPenumbraSizeDirty(){for(let e of this.children)e instanceof to&&(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 r=this.find(e);if(r===void 0)return;let o=[],n=r;for(;n!==this;){let a=n;n=n.parent;let s=n.children.indexOf(a);o.splice(0,0,s)}return{entity:r,sortKey:o}}getAllSorted(e){let r=[];for(let o of e){let n=this.getWithSortKey(o.id);n!==void 0&&r.push(n)}return r.sort((o,n)=>Ec(o.sortKey,n.sortKey)),r.map(o=>o.entity)}nonExistOrDescendantOf(e,r){let o=this.find(e);if(o===void 0)return!0;for(;o;){if(o.uuid===r)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===zi)return this.activePage.personalCamera}if(e===""||e===void 0)return;let r=this.entityByUuid[e];return r===void 0?this.getObjectByProperty("uuid",e):r}find2D(e){for(let r of this.children)if(r instanceof to&&r.uiScene){let o=r.uiScene.find(e);if(o)return o}}findScene2DfromObject2D(e){for(let r of this.children)if(r instanceof to&&r.uiScene&&r.uiScene.find(e))return r.uiScene}find2DInUIObjects(e){let r;return this.traverseEntity(o=>{r===void 0&&o instanceof Qn&&(r=o.uiCanvas.find(e))}),r}traverse2D(e){for(let r of this.children)r instanceof to&&r.uiScene&&r.uiScene.traverse(e)}debugEnsureEntity(e){let r=this.find(e);if(r){if(Array.isArray(r.identity)&&this.findInstance(r.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(r=>{this.toExpandCloner.add(r)})}doPendingExpandCloner(e){this.toExpandCloner.forEach(r=>{r.expandCloner(e)}),this.toExpandCloner.clear()}doPendingUpdateCloner(e){this.toUpdateCloner.forEach(r=>{r.cloner?.update(e)}),this.toUpdateCloner.clear()}doPendingUpdates(e){this.doPendingExpandCloner(e),this.doPendingUpdateCloner(e),this.applyPendingCommands()}addPendingCommand(e){this.pendingCommands.push(e)}applyPendingCommands(){this.pendingCommands.forEach(e=>e()),this.pendingCommands.length=0}updateByLibOp(e,r){e.path.length===1&&e.path[0]==="components"&&e.type===1&&this.createChildrenObjects([{...e.data.asset,id:e.id}],this.invisibleObjects,r)}updateTreeByOp(e,r){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,r);n.updateVisible(this),n.resetBBoxNeedsUpdate(),sn(n)&&dc(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 fn&&(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),dc(o.parent)&&(o.parent.invalidateUpstreamBooleanData(),o.parent.invalidateDownstreamBooleanData().recomputeBoolean()),sn(o)&&(o.freeBooleanPointer(),n instanceof Nr&&n.invalidateDownstreamBooleanData().recomputeBoolean()),o instanceof Qs&&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()),sn(o)&&(o.invalidateUpstreamBooleanData(),dc(o.parent)?o.parent.invalidateDownstreamBooleanData().recomputeBoolean():n instanceof Nr&&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 r of this.children)r instanceof to&&(r.visible=r.uuid===e,r.visible&&(this.activePage=r,this.activePage.onActive(this)));this.activePage!==this.splatViewer?.activePage&&this.reloadSplats()}updateEntityByOp(e,r,o,n){if(r.type===0){if(("overrides"in r.props||"component"in r.props)&&this.markNeedsRecomputeInstances(),"visible"in r.props&&this.markPenumbraSizeDirty(),r.path.includes("overrides")&&"states"in r.props){let{rest:s}=r.props;r={...r,props:s},this.markNeedsRecomputeInstances()}r.path[0]==="pathSnapping"&&r.props.pathId!==void 0&&this.pathConstraints.setConstraint(e,r.props.pathId)}let a=this.find(e);if(a)try{$1(a,r,o,{scene:this,shared:n}),a instanceof ht&&a.updateGeometryGroupsIfNeeded()}catch(s){console.error(s)}}updateEntity2DByOp(e,r,o,n,a,s=[]){e.updateEntityByOp(r,o,n,a),this.traverseEntity(l=>{(l instanceof Qn||l instanceof to)&&(s.includes(l.frameId??"")||l.frameId===r)&&l.updateEntity2DByOp(r,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,r){let o=Object.entries(r.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:r}),this.add(this.invisibleObjects),this.createChildrenObjects(o,this.invisibleObjects,r),this.createChildrenObjects(e.objects,this,r),this.updatePage(e.publish.playPage),this.activePage.switchToPlayCamera(),this.expandInstances(r,!0),this.traverseEntity(n=>{n instanceof Si&&n.updateUp()}),this.doPendingExpandCloner({scene:this,shared:r}),this.applyPendingCommands()}markNeedsRecomputeInstances(){this.needsRecomputeInstances=!0}markNeedsRecomputeInstancesForChildren(e){e.traverseEntity(r=>{(r.data.type==="Component"||r.data.type==="Instance")&&this.markNeedsRecomputeInstances()})}markNeedsRecomputeInstancesForAncessors(e){Ge.is(e)&&(e.data.type==="Component"&&this.markNeedsRecomputeInstances(),e.traverseAncestors(r=>{Ge.is(r)&&r.data.type==="Component"&&this.markNeedsRecomputeInstances()}))}relativeizeInner(e,r,o,n,a,s,l){if(e){let c=n.find(e);c&&c!==n&&a.forInstancesRec(u=>{u.data=Di(u.data,d=>{let p=d.events.data(l.id),f=u.goUp(s);if(f){let h=[...Ic(f.identity),e].join("-"),m=this.entityIdentityToEntity[h];if(m){let y=m.uuid,g=dt.zoom(p,r);g[o]=y}else{if(!1)debugger;console.warn("cannot find instance")}}}).data})}}rewriteActions(e,r,o,n,a,s){e.forEach(l=>{l.data.type==="Transition"?this.relativeizeInner(l.data.object,[...r,l.id],"object",o,n,a,s):l.data.type==="Animation"?this.relativeizeInner(l.data.object,[...r,l.id],"object",o,n,a,s):l.data.type==="Conditional"&&(this.rewriteActions(l.data.ifActions,[...r,l.id,"ifActions"],o,n,a,s),this.rewriteActions(l.data.elseActions,[...r,l.id,"elseActions"],o,n,a,s))})}rewriteEventsBeforeGoToPlayMode(){this.traverseEntity(e=>{if(e instanceof Oi&&typeof e.identity=="string"&&e.data.type==="Component")return e.traverseEntity((r,o)=>{r.data.events.forEach(n=>{if(n.data.type==="GameControl"){let a=!1;if(r.forInstancesRec(s=>{s.data=Di(s.data,l=>{s.isInstanceRoot||(l.events.delete(n.id),a=!0)}).data}),a===!1)for(let s of Bu.list)this.rewriteActions(n.data.gameActions[s],["gameActions",s],e,r,o,n)}else n.data.type==="Conditional"?(n.data.condition.type==="Distance"?(this.relativeizeInner(n.data.condition.fromObject,["condition"],"fromObject",e,r,o,n),this.relativeizeInner(n.data.condition.toObject,["condition"],"toObject",e,r,o,n)):n.data.condition.type==="State"?this.relativeizeInner(n.data.condition.object,["condition"],"object",e,r,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,r,o,n),n.data.condition.rOperand.type==="Property"&&this.relativeizeInner(n.data.condition.rOperand.value[0],["condition","rOperand","value"],0,e,r,o,n)),this.rewriteActions(n.data.inActions,["inActions"],e,r,o,n),this.rewriteActions(n.data.outActions,["outActions"],e,r,o,n)):"actions"in n.data&&this.rewriteActions(n.data.actions,["actions"],e,r,o,n)})}),!0})}expandInstances(e,r,o){let n=new Set;this.traverseEntity(a=>{if(a instanceof Oi&&a.isInstanceRoot)return a.expandInstanceChildren({scene:this,shared:e,pendingDeletes:n}),r||a.resetBBoxNeedsUpdate(),o&&a.traverseEntity(s=>{o.addClip(s)}),!0});for(let a of n)this.disposeAndUnregisterEntityRecursivelyIfNotReregistered(a),ip(a)}recomputeInstances(e,r){this.needsRecomputeInstances&&(this.needsRecomputeInstances=!1,this.traverseEntity(o=>{o instanceof Oi&&o.isInstanceRoot&&(o.component=void 0)}),this.expandInstances(e,!1,r))}disposeAndUnregisterEntityRecursivelyIfNotReregistered(e){e.traverseEntity(r=>{let o=typeof r.identity=="string"?r.identity:r.identity.join("-");this.entityIdentityToEntity[o]===r&&(delete this.entityByUuid[r.uuid],delete this.entityIdentityToEntity[o]),r.dispose()})}clearScene(){for(let e of this.children)Ge.is(e)&&e.disposeRecursively();this.children.length=0}resetAfterClear(e,r){this.init(e,r)}raycast(e){return this.raycast1(e,!1)}raycast1(e,r){let o=[],n=a=>{for(let s of a.children){let l=s.cloner;if(Ge.is(s)&&!s.raycastLock&&(s.visible||l?.object.data.visible))if(r===!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 d=s.matrixWorld.clone().invert();u.point.applyMatrix4(d),o.push(u)}}else(sn(s)||pc(s)&&this.enableHelpers&&s.objectHelper.visible)&&(e.intersectObject(s,!1,o),bc(s,e,o)),n(s)}};return n(this.activePage),o}raycastWithClones(e){let r=[],o=n=>{for(let a of n.children){let s=a.cloner;Ge.is(a)&&(a.visible||s?.object.data.visible)&&((sn(a)||pc(a)&&this.enableHelpers&&a.objectHelper.visible)&&(e.intersectObject(a,!1,r),bc(a,e,r,!0)),o(a))}};return o(this),r}forEachEntity(e){for(let r of this.children)Ge.is(r)&&e(r)}traverseConcreteEntity(e){for(let r of this.children)Ge.is(r)&&r.isConcreteEntity&&r.traverseEntity(e)}traverseEntity(e){for(let r of this.children)Ge.is(r)&&r.traverseEntity(e)}updateFont(e,r){this.traverseEntity(o=>{if(o instanceof ht&&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,r).then(()=>{n.update(a,r);let s=o.invalidateDownstreamBooleanData();dc(s)&&s.recomputeBoolean()})}})}traverseObject(e){for(let r of this.children)di.is(r)&&r.traverseObject(e)}traverseVisibleEntity(e){for(let r of this.children)Ge.is(r)&&r.visible&&r.traverseVisibleEntity(e)}dispose(){this.clearScene()}createChildrenObjects(e,r,o){let n=0;for(let a of e)this.createObject(a.id,a.data,a.children,r,n,o),n+=1}registerObjectCreatedInLegacy(e){this.entityByUuid[e.uuid]=e}unregisterObject(e){delete this.entityByUuid[e.uuid];for(let r of e.children)this.unregisterObject(r)}createObject(e,r,o,n,a,s){let l={scene:this,shared:s},c=lp(e,r,l);return c instanceof fn&&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(r,l),c instanceof ht&&c.updateGeometryGroupsIfNeeded(),c.updateVisible(this),c.cloner&&this.toExpandCloner.add(c),r.pathSnapping?.pathId&&this.pathConstraints.setConstraint(e,r.pathSnapping.pathId)),r.type==="Empty"&&r.animations&&c.traverseEntity(u=>{let d=u.dataPatched;if(u instanceof ht&&d.bones&&d.boneInverses){let p=d.bones.map(m=>this.find(m)),f=d.boneInverses.map(m=>new oo.Matrix4().fromArray(m)),h=new oo.Skeleton(p,f);u.bind(h,u.bindMatrix)}else u.matrixAutoUpdate=!0}),c}getCenter(e){let r=[];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;r.push(...u.vertices)}let o=new oo.Box3;return o.setFromPoints(r),o.getCenter(sS),sS}copyMatrixWorld(e,r){if(e===null){r.identity();return}let o=this.find(e);o?r.copy(o.matrixWorld):r.identity()}copyParentMatrixWorld(e,r){if(e===null){r.identity();return}let o=this.find(e)?.parent;o?r.copy(o.matrixWorld):r.identity()}traverseMaterial(e){this.traverseEntity(r=>{if(r instanceof Xt)if(Array.isArray(r.material))for(let o=0;o<r.material.length;o++)r.material[o]instanceof Ir&&e(r.material[o]);else r.material instanceof Ir&&e(r.material)})}updateViewPlaneSize(e,r,o=!1){this.traverseConcreteEntity(n=>{n instanceof Si&&n.setViewplaneSize(e,r,o)})}initializeSplatViewer(){this.splatViewer=new Sc({scene:this}),this.reloadSplats()}reloadSplats(){this.splatViewer?.loadSplat()}};var lS=require("three/examples/jsm/loaders/DRACOLoader.js");var gn;function cS(i){return gn||(gn=new lS.DRACOLoader,gn.setDecoderPath(i?`${i}/`:"https://www.gstatic.com/draco/versioned/decoders/1.5.2/").preload()),gn.decoderPending}async function BE(i){if(gn){let t={attributeIDs:gn.defaultAttributeIDs,attributeTypes:gn.defaultAttributeTypes,useUniqueIDs:!1},e;try{e=await gn.decodeGeometry(new Int8Array(i).buffer,t)}catch(r){console.error(r)}if(e)return{index:e.index?{array:e.index.array}:void 0,attributes:Object.entries(e.attributes).map(([r,o])=>({name:r,itemSize:o.itemSize,array:o.array}))}}return null}async function uS(i,t){let[e,r]=Up(bu.deserialize(new Uint8Array(i)));return zu(e),t&&t(e),r.result().data}function dS(i){let t=[];return i.scene.objects.traverse((e,r)=>{r.type==="Mesh"&&r.geometry.type==="NonParametricGeometry"&&r.geometry.data.draco!==void 0&&t.push(r)}),t}async function pS(i){for(let t of i){let e=await BE(t.geometry.data.draco);if(e){let r=t.geometry.data;e.index&&(r.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}}),r.attributes=o,r.draco=void 0}}}var VE=require("three"),zE=require("three/examples/jsm/utils/BufferGeometryUtils.js");function fS(i){let t;if(!!i.index)for(let e=0;e<i.index.array.length;e+=3)t=i.index.array[e],i.index.array[e]=i.index.array[e+2],i.index.array[e+2]=t}var wc=require("three");function hS(i){let t=new Set;return i.traverse(e=>{if(e instanceof Er)if(Mt(e.material))e.material.forEach(r=>{let o=r;t.has(o)||t.add(o)});else{let r=e.material;t.has(r)||t.add(r)}}),t.forEach(e=>{if(e instanceof Array)return;let r=e.onBeforeCompile.bind(e);if(GE(e)){Object.assign(e,{isMeshStandardMaterial:!0,isMeshPhysicalMaterial:!0,transmission:1,attenuationColor:new wc.Color,specularColor:new wc.Color});let o=0;e.onBeforeCompile=(n,a)=>{r&&r(n,a),n.uniforms=Object.assign({},wc.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=Yb(window.innerWidth,window.innerHeight),e.defines.IS_THREEJS_EXPORT=!0)}else o++,o<2&&(e.needsUpdate=!0)})}}else FE(e)||(e.onBeforeCompile=(o,n)=>{r&&r(o,n),e.transparent=!1})}),i}function GE(i){return i.getLayersOfType("transmission").length>0}function FE(i){let t=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&&(t+=(1-t)*o.value)}}return t<1}function mS(i){return i.traverse(t=>{if(t.type==="Camera"){let e=t;e.type=e.cameraType}}),i}function yS(i){let t=[],e=(r,o=0)=>{let n=o>0?r+o:r;return t.includes(n)?e(r,o+1):n};return i.traverse(r=>{if(t.includes(r.name)){let o=r.name,n=e(r.name);if(r.name=n,r.isMesh){let a=r;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))}}t.push(r.name)}),i}var gS=require("three/examples/jsm/utils/BufferGeometryUtils.js");function xS(i){let t=[];return i.traverse(e=>{e instanceof nn&&t.push(e)}),t.forEach(e=>{let r=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&&fS(l),l}).filter(s=>s!==void 0)];if(!e.parameters.hideBase&&r instanceof Xt&&a.unshift(r.geometry),a.length){let s=(0,gS.mergeBufferGeometries)(a);r instanceof Xt&&(r.geometry=s)}e.removeFromParent(),r.setFromClonerState(null,{scene:i,shared:fv})}),i}function bS(i){return i.traverse(t=>{t.matrixAutoUpdate=!0}),i}function vS(i){Object.values(i.shared.materials).forEach(t=>{lm(t)}),i.scene.objects.traverse((t,e)=>{"material"in e?lm(e.material):"materials"in e&&e.materials.forEach(r=>{lm(r)})})}function lm(i){if(typeof i=="string")return;let t=[];i.layers.forEach((e,r)=>{e.type==="outline"&&t.push(r)}),t.reverse().forEach(e=>{i.layers.delete(e)}),t.length&&console.warn("The Spline Loader currently does not support the outline layer.")}var OS=ll(wS(),1);var PS="The SplineLoader only accepts .splinecode files that are generated from Spline export panel.",gp=class extends xp.Loader{load(t,e,r,o=console.error){let n=new xp.FileLoader(this.manager);n.setPath(this.path),n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),t.endsWith(".spline")?console.warn(PS+" The .spline files are only meant to be used by the Editor."):t.endsWith(".splinecode")||console.warn(PS),n.load(t,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)}},r,o)}async parse(t){let e=await uS(t,vS),r=dS(e);e.version&&(0,OS.default)(e.version,"1.12.42")>0&&console.warn("Your .splinecode file is more recent than the library. Please upgrade @splinetool/loader to the latest version."),await Promise.allSettled([r.length&&cS(),xv(e)&&Pb(),Mv(e)&&av(),l1(e)&&n1(),hp(e)&&sm()].filter(Boolean)),r.length&&await pS(r);let o=!1,n=new qn(e.shared,{},o);Object.values(n.getMaterials()).forEach(l=>Object.assign(l,{isAsset:!0}));let a=new yp(e.scene,n);hp(e)&&a.initializeSplatViewer();let s=a.activeCamera;return s&&Object.assign(s,{makeDefault:!0}),a=xS(a),a=hS(a),a=mS(a),a=yS(a),a=bS(a),a}};