UNPKG

angular-3d-viewer

Version:
2 lines 1.01 MB
var OV=(()=>{var Eh=Object.defineProperty;var j0=Object.getOwnPropertyDescriptor;var Y0=Object.getOwnPropertyNames;var K0=Object.prototype.hasOwnProperty;var Z0=(r,e)=>{for(var t in e)Eh(r,t,{get:e[t],enumerable:!0})},J0=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Y0(e))!K0.call(r,i)&&i!==t&&Eh(r,i,{get:()=>e[i],enumerable:!(n=j0(e,i))||n.enumerable});return r};var $0=r=>J0(Eh({},"__esModule",{value:!0}),r);var tS={};Z0(tS,{AddCoord2D:()=>fp,AddCoord3D:()=>Ac,AddDiv:()=>L0,AddDomElement:()=>Kd,ArrayBufferToAsciiString:()=>vp,ArrayBufferToUtf8String:()=>fn,ArrayToCoord3D:()=>jr,ArrayToQuaternion:()=>yo,ArrayToRGBColor:()=>gp,AsciiStringToArrayBuffer:()=>xp,Base64DataURIToArrayBuffer:()=>Ss,BezierTweenFunction:()=>bp,BigEps:()=>cp,BinaryReader:()=>Yn,BinaryWriter:()=>Ni,BoundingBoxCalculator3D:()=>bo,Box3D:()=>Cs,CalculateSurfaceArea:()=>R0,CalculateTriangleNormal:()=>ws,CalculateVolume:()=>jd,Camera:()=>yr,CameraIsEqual3D:()=>uh,CameraMode:()=>zn,CameraValidator:()=>oc,CheckModel:()=>zg,ClearDomElement:()=>N0,ClickDetector:()=>sc,ColorComponentFromFloat:()=>En,ColorComponentToFloat:()=>Ms,ColorToMaterialConverter:()=>ti,ConvertColorToThreeColor:()=>On,ConvertMeshToMeshBuffer:()=>fo,ConvertModelToThreeObject:()=>fh,ConvertThreeColorToColor:()=>Gl,ConvertThreeGeometryToMesh:()=>Wi,Coord2D:()=>wt,Coord3D:()=>He,Coord4D:()=>Oi,CoordDistance2D:()=>Qa,CoordDistance3D:()=>Wn,CoordIsEqual2D:()=>Pi,CoordIsEqual3D:()=>li,CopyObjectAttributes:()=>so,CreateDiv:()=>z0,CreateDomElement:()=>gh,CreateModelUrlParameters:()=>P0,CreateObjectUrl:()=>As,CreateObjectUrlWithMimeType:()=>Cc,CreateUrlBuilder:()=>Yd,CreateUrlParser:()=>I0,CrossVector3D:()=>Li,DegRad:()=>tr,Direction:()=>ht,DisposeThreeObjects:()=>Wu,DotVector3D:()=>tl,EdgeSettings:()=>Qs,EmbeddedViewer:()=>ja,EnvironmentSettings:()=>eo,Eps:()=>lp,EscapeHtmlChars:()=>mc,EventNotifier:()=>gc,ExportedFile:()=>jt,Exporter:()=>Oc,Exporter3dm:()=>mo,ExporterBase:()=>bn,ExporterBim:()=>go,ExporterGltf:()=>vo,ExporterModel:()=>xo,ExporterObj:()=>_o,ExporterOff:()=>To,ExporterPly:()=>Eo,ExporterSettings:()=>ol,ExporterStl:()=>Mo,FaceMaterial:()=>uo,FileFormat:()=>nn,FileSource:()=>Ii,FinalizeModel:()=>Xu,FlipMeshTrianglesOrientation:()=>Nc,GenerateCone:()=>Wd,GenerateCuboid:()=>S0,GenerateCylinder:()=>A0,GeneratePlatonicSolid:()=>C0,GenerateSphere:()=>w0,Generator:()=>vs,GeneratorHelper:()=>Ba,GeneratorParams:()=>$l,GetBoundingBox:()=>bh,GetDefaultCamera:()=>yh,GetDomElementClientCoordinates:()=>Wr,GetDomElementExternalHeight:()=>ph,GetDomElementExternalWidth:()=>dh,GetDomElementInnerDimensions:()=>mh,GetDomElementOuterHeight:()=>B0,GetDomElementOuterWidth:()=>k0,GetExternalLibPath:()=>Ts,GetFileExtension:()=>er,GetFileExtensionFromMimeType:()=>Yr,GetFileName:()=>vn,GetIntegerFromStyle:()=>Cn,GetMeshType:()=>Kr,GetShadingType:()=>Hu,GetShadingTypeOfObject:()=>$d,GetTetrahedronSignedVolume:()=>qd,GetTopology:()=>Sh,GetTriangleArea:()=>Xd,HasDefaultMaterial:()=>Ap,HasHighpDriverIssue:()=>zu,HexStringToRGBAColor:()=>mp,HexStringToRGBColor:()=>pp,ImportError:()=>ys,ImportErrorCode:()=>gr,ImportResult:()=>Kl,ImportSettings:()=>Ua,Importer:()=>ka,Importer3dm:()=>va,Importer3ds:()=>xa,ImporterBase:()=>Vt,ImporterBim:()=>wa,ImporterFcstd:()=>Fa,ImporterFile:()=>Rs,ImporterFileAccessor:()=>Zl,ImporterFileList:()=>Is,ImporterGltf:()=>_a,ImporterIfc:()=>Ta,ImporterObj:()=>Ea,ImporterOcct:()=>Sa,ImporterOff:()=>Ma,ImporterPly:()=>ba,ImporterStl:()=>Aa,ImporterThree3mf:()=>Na,ImporterThreeAmf:()=>Oa,ImporterThreeBase:()=>Zi,ImporterThreeDae:()=>Pa,ImporterThreeFbx:()=>Ia,ImporterThreeSvg:()=>ch,ImporterThreeWrl:()=>La,Init3DViewerElements:()=>W0,Init3DViewerFromFileList:()=>H0,Init3DViewerFromUrlList:()=>Qd,InputFile:()=>wo,InputFilesFromFileObjects:()=>Uc,InputFilesFromUrls:()=>Fc,InsertDomElementAfter:()=>D0,InsertDomElementBefore:()=>O0,IntegerToHexString:()=>xn,IsDefined:()=>ro,IsDomElementVisible:()=>U0,IsEqual:()=>It,IsEqualEps:()=>hp,IsGreater:()=>bc,IsGreaterOrEqual:()=>co,IsLower:()=>ao,IsLowerOrEqual:()=>lo,IsModelEmpty:()=>Ro,IsNegative:()=>Tr,IsObjectEmpty:()=>pc,IsPositive:()=>gi,IsPowerOfTwo:()=>id,IsTwoManifold:()=>Ah,IsUrl:()=>ap,IsZero:()=>Es,LinearToSRGB:()=>bs,LinearTweenFunction:()=>Sp,LoadExternalLibrary:()=>Qi,MaterialBase:()=>el,MaterialType:()=>In,Matrix:()=>ln,MatrixIsEqual:()=>Lc,Mesh:()=>$t,MeshBuffer:()=>il,MeshInstance:()=>br,MeshInstanceId:()=>yi,MeshPrimitiveBuffer:()=>nl,MeshType:()=>ir,Model:()=>or,ModelObject3D:()=>sr,ModelToThreeConversionOutput:()=>za,ModelToThreeConversionParams:()=>Va,MouseInteraction:()=>ic,NameFromLine:()=>Vr,Navigation:()=>Wa,NavigationType:()=>Kn,NextPowerOfTwo:()=>Hg,Node:()=>Sn,Object3D:()=>rl,Octree:()=>So,OctreeNode:()=>al,ParabolicTweenFunction:()=>Dc,ParameterConverter:()=>on,ParameterListBuilder:()=>Ql,ParameterListParser:()=>ec,ParametersFromLine:()=>Xi,PhongMaterial:()=>hn,PhysicalMaterial:()=>qr,Property:()=>Jt,PropertyGroup:()=>Fn,PropertyToString:()=>Ic,PropertyType:()=>Bt,Quaternion:()=>Xn,QuaternionFromAxisAngle:()=>Pc,QuaternionFromXYZ:()=>Tp,QuaternionIsEqual:()=>_p,RGBAColor:()=>Er,RGBAColorToHexString:()=>dp,RGBColor:()=>Et,RGBColorFromFloatComponents:()=>ai,RGBColorIsEqual:()=>Mr,RGBColorToHexString:()=>Sc,RadDeg:()=>up,ReadFile:()=>Ec,ReadLines:()=>Si,ReplaceDefaultMaterialColor:()=>wp,RequestUrl:()=>Tc,RevokeObjectUrl:()=>Rc,RunTaskAsync:()=>Ja,RunTasks:()=>yc,RunTasksBatch:()=>vc,SRGBToLinear:()=>nr,SetDomElementHeight:()=>Jd,SetDomElementOuterHeight:()=>V0,SetDomElementOuterWidth:()=>G0,SetDomElementWidth:()=>Zd,SetExternalLibLocation:()=>op,SetThreeMeshPolygonOffset:()=>hh,ShadingModel:()=>Xa,ShadingType:()=>Vn,ShowDomElement:()=>F0,SubCoord2D:()=>$a,SubCoord3D:()=>Mn,TaskRunner:()=>oo,TextWriter:()=>$n,TextureIsEqual:()=>yp,TextureMap:()=>Jn,TextureMapIsEqual:()=>Xr,ThreeColorConverter:()=>ga,ThreeConversionStateHandler:()=>tc,ThreeLinearToSRGBColorConverter:()=>Zs,ThreeModelLoader:()=>Ha,ThreeNodeTree:()=>nc,ThreeSRGBToLinearColorConverter:()=>ya,Topology:()=>Co,TopologyEdge:()=>cl,TopologyTriangle:()=>hl,TopologyTriangleEdge:()=>ul,TopologyVertex:()=>ll,TouchInteraction:()=>rc,TransformFileHostUrls:()=>Mc,TransformMesh:()=>rr,Transformation:()=>rn,TransformationIsEqual:()=>Ep,TraverseThreeObject:()=>vh,Triangle:()=>Ht,TweenCoord3D:()=>Ao,UpVector:()=>ac,UpdateMaterialTransparency:()=>ni,Utf8StringToArrayBuffer:()=>po,ValueOrDefault:()=>rp,VectorAngle3D:()=>wc,VectorLength3D:()=>ho,Viewer:()=>qa,ViewerMainModel:()=>Ga,ViewerModel:()=>xs,WaitWhile:()=>xc});function ro(r){return r!=null}function rp(r,e){return r??e}function so(r,e){if(ro(r))for(let t of Object.keys(r))ro(r[t])&&(e[t]=r[t])}function pc(r){return Object.keys(r).length===0}function mc(r){return r.replace(/</g,"&lt;").replace(/>/g,"&gt;")}var gc=class{constructor(){this.eventListeners=new Map}AddEventListener(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,[]),this.eventListeners.get(e).push(t)}HasEventListener(e){return this.eventListeners.has(e)}GetEventNotifier(e){return()=>{this.NotifyEventListeners(e)}}NotifyEventListeners(e,...t){if(!this.eventListeners.has(e))return;let n=this.eventListeners.get(e);for(let i of n)i(...t)}};var oo=class{constructor(){this.count=null,this.current=null,this.callbacks=null}Run(e,t){this.count=e,this.current=0,this.callbacks=t,e===0?this.TaskReady():this.RunOnce()}RunBatch(e,t,n){let i=0;e>0&&(i=parseInt((e-1)/t,10)+1),this.Run(i,{runTask:(s,o)=>{let a=s*t,l=Math.min((s+1)*t,e)-1;n.runTask(a,l,o)},onReady:n.onReady})}RunOnce(){setTimeout(()=>{this.callbacks.runTask(this.current,this.TaskReady.bind(this))},0)}TaskReady(){this.current+=1,this.current<this.count?this.RunOnce():this.callbacks.onReady&&this.callbacks.onReady()}};function Ja(r){setTimeout(()=>{r()},10)}function yc(r,e){new oo().Run(r,e)}function vc(r,e,t){new oo().RunBatch(r,e,t)}function xc(r){function e(t){t()&&setTimeout(()=>{e(t)},10)}e(r)}var _c=null,sp=new Set;function op(r){_c=r}function Ts(r){return _c===null?null:_c+"/"+r}function Qi(r){return new Promise((e,t)=>{if(_c===null){t();return}if(sp.has(r)){e();return}let n=document.createElement("script");n.type="text/javascript",n.src=Ts(r),n.onload=()=>{sp.add(r),e()},n.onerror=()=>{t()},document.head.appendChild(n)})}var Ii={Url:1,File:2,Decompressed:3},nn={Text:1,Binary:2};function vn(r){let e=r,t=e.indexOf("?");t!==-1&&(e=e.substring(0,t));let n=e.lastIndexOf("/");return n===-1&&(n=e.lastIndexOf("\\")),n!==-1&&(e=e.substring(n+1)),decodeURI(e)}function er(r){let e=vn(r),t=e.lastIndexOf(".");return t===-1?"":e.substring(t+1).toLowerCase()}function Tc(r,e){return new Promise((t,n)=>{let i=new XMLHttpRequest;i.open("GET",r,!0),i.onprogress=s=>{e(s.loaded,s.total)},i.onload=()=>{i.status===200?t(i.response):n()},i.onerror=()=>{n()},i.responseType="arraybuffer",i.send(null)})}function Ec(r,e){return new Promise((t,n)=>{let i=new FileReader;i.onprogress=s=>{e(s.loaded,s.total)},i.onloadend=s=>{s.target.readyState===FileReader.DONE&&t(s.target.result)},i.onerror=()=>{n()},i.readAsArrayBuffer(r)})}function Mc(r){for(let e=0;e<r.length;e++){let t=r[e];if(t.search(/www\.dropbox\.com/u)!==-1){t=t.replace("www.dropbox.com","dl.dropbox.com");let n=t.indexOf("?");n!==-1&&(t=t.substring(0,n)),r[e]=t}else if(t.search(/github\.com/u)!==-1){t=t.replace("github.com","raw.githubusercontent.com"),t=t.replace("/blob","");let n=t.indexOf("?");n!==-1&&(t=t.substring(0,n)),r[e]=t}}}function ap(r){let e=/^https?:\/\/\S+$/g;return r.match(e)!==null}var lp=1e-8,cp=1e-4,up=57.29577951308232,tr=.017453292519943;function Es(r){return Math.abs(r)<1e-8}function ao(r,e){return e-r>1e-8}function bc(r,e){return r-e>1e-8}function lo(r,e){return e-r>-1e-8}function co(r,e){return r-e>-1e-8}function It(r,e){return Math.abs(e-r)<1e-8}function hp(r,e,t){return Math.abs(e-r)<t}function gi(r){return r>1e-8}function Tr(r){return r<-1e-8}var ht={X:1,Y:2,Z:3};var wt=class r{constructor(e,t){this.x=e,this.y=t}Clone(){return new r(this.x,this.y)}};function Pi(r,e){return It(r.x,e.x)&&It(r.y,e.y)}function fp(r,e){return new wt(r.x+e.x,r.y+e.y)}function $a(r,e){return new wt(r.x-e.x,r.y-e.y)}function Qa(r,e){return Math.sqrt((r.x-e.x)*(r.x-e.x)+(r.y-e.y)*(r.y-e.y))}var Et=class r{constructor(e,t,n){this.r=e,this.g=t,this.b=n}Set(e,t,n){this.r=e,this.g=t,this.b=n}Clone(){return new r(this.r,this.g,this.b)}},Er=class r{constructor(e,t,n,i){this.r=e,this.g=t,this.b=n,this.a=i}Set(e,t,n,i){this.r=e,this.g=t,this.b=n,this.a=i}Clone(){return new r(this.r,this.g,this.b,this.a)}};function En(r){return parseInt(Math.round(r*255),10)}function Ms(r){return r/255}function ai(r,e,t){return new Et(En(r),En(e),En(t))}function nr(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function bs(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}function xn(r){let e=parseInt(r,10).toString(16);for(;e.length<2;)e="0"+e;return e}function Sc(r){let e=xn(r.r),t=xn(r.g),n=xn(r.b);return e+t+n}function dp(r){let e=xn(r.r),t=xn(r.g),n=xn(r.b),i=xn(r.a);return e+t+n+i}function pp(r){if(r.length!==6)return null;let e=parseInt(r.substring(0,2),16),t=parseInt(r.substring(2,4),16),n=parseInt(r.substring(4,6),16);return new Et(e,t,n)}function mp(r){if(r.length!==6&&r.length!==8)return null;let e=parseInt(r.substring(0,2),16),t=parseInt(r.substring(2,4),16),n=parseInt(r.substring(4,6),16),i=255;return r.length===8&&(i=parseInt(r.substring(6,8),16)),new Er(e,t,n,i)}function gp(r){return new Et(r[0],r[1],r[2])}function Mr(r,e){return r.r===e.r&&r.g===e.g&&r.b===e.b}var Jn=class{constructor(){this.name=null,this.mimeType=null,this.buffer=null,this.offset=new wt(0,0),this.scale=new wt(1,1),this.rotation=0}IsValid(){return this.name!==null&&this.buffer!==null}HasTransformation(){return!Pi(this.offset,new wt(0,0))||!Pi(this.scale,new wt(1,1))||!It(this.rotation,0)}IsEqual(e){return!(this.name!==e.name||this.mimeType!==e.mimeType||!Pi(this.offset,e.offset)||!Pi(this.scale,e.scale)||!It(this.rotation,e.rotation))}};function Xr(r,e){return r===null&&e===null?!0:r===null||e===null?!1:r.IsEqual(e)}var In={Phong:1,Physical:2},el=class{constructor(e){this.type=e,this.isDefault=!1,this.name="",this.color=new Et(0,0,0),this.vertexColors=!1}IsEqual(e){return!(this.type!==e.type||this.isDefault!==e.isDefault||this.name!==e.name||!Mr(this.color,e.color)||this.vertexColors!==e.vertexColors)}},uo=class extends el{constructor(e){super(e),this.emissive=new Et(0,0,0),this.opacity=1,this.transparent=!1,this.diffuseMap=null,this.bumpMap=null,this.normalMap=null,this.emissiveMap=null,this.alphaTest=0,this.multiplyDiffuseMap=!1}IsEqual(e){return!(!super.IsEqual(e)||!Mr(this.emissive,e.emissive)||!It(this.opacity,e.opacity)||this.transparent!==e.transparent||!Xr(this.diffuseMap,e.diffuseMap)||!Xr(this.bumpMap,e.bumpMap)||!Xr(this.normalMap,e.normalMap)||!Xr(this.emissiveMap,e.emissiveMap)||!It(this.alphaTest,e.alphaTest)||this.multiplyDiffuseMap!==e.multiplyDiffuseMap)}},hn=class extends uo{constructor(){super(In.Phong),this.ambient=new Et(0,0,0),this.specular=new Et(0,0,0),this.shininess=0,this.specularMap=null}IsEqual(e){return!(!super.IsEqual(e)||!Mr(this.ambient,e.ambient)||!Mr(this.specular,e.specular)||!It(this.shininess,e.shininess)||!Xr(this.specularMap,e.specularMap))}},qr=class extends uo{constructor(){super(In.Physical),this.metalness=0,this.roughness=1,this.metalnessMap=null}IsEqual(e){return!(!super.IsEqual(e)||!It(this.metalness,e.metalness)||!It(this.roughness,e.roughness)||!Xr(this.metalnessMap,e.metalnessMap))}};function yp(r,e){return!(r.name!==e.name||r.mimeType!==e.mimeType||!Pi(r.offset,e.offset)||!Pi(r.scale,e.scale)||!It(r.rotation,e.rotation))}var He=class r{constructor(e,t,n){this.x=e,this.y=t,this.z=n}Length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}MultiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}Normalize(){let e=this.Length();return e>0&&this.MultiplyScalar(1/e),this}Offset(e,t){let n=e.Clone().Normalize();return this.x+=n.x*t,this.y+=n.y*t,this.z+=n.z*t,this}Rotate(e,t,n){let i=e.Clone().Normalize(),s=i.x,o=i.y,a=i.z,l=this.x-n.x,c=this.y-n.y,u=this.z-n.z,h=Math.sin(t),f=Math.cos(t);return this.x=-s*(-s*l-o*c-a*u)*(1-f)+l*f+(-a*c+o*u)*h,this.y=-o*(-s*l-o*c-a*u)*(1-f)+c*f+(a*l-s*u)*h,this.z=-a*(-s*l-o*c-a*u)*(1-f)+u*f+(-o*l+s*c)*h,this.x+=n.x,this.y+=n.y,this.z+=n.z,this}Clone(){return new r(this.x,this.y,this.z)}};function li(r,e){return It(r.x,e.x)&&It(r.y,e.y)&&It(r.z,e.z)}function Ac(r,e){return new He(r.x+e.x,r.y+e.y,r.z+e.z)}function Mn(r,e){return new He(r.x-e.x,r.y-e.y,r.z-e.z)}function Wn(r,e){return Math.sqrt((r.x-e.x)*(r.x-e.x)+(r.y-e.y)*(r.y-e.y)+(r.z-e.z)*(r.z-e.z))}function tl(r,e){return r.x*e.x+r.y*e.y+r.z*e.z}function wc(r,e){let t=r.Clone().Normalize(),n=e.Clone().Normalize();if(li(t,n))return 0;let i=tl(t,n);return Math.acos(i)}function Li(r,e){let t=new He(0,0,0);return t.x=r.y*e.z-r.z*e.y,t.y=r.z*e.x-r.x*e.z,t.z=r.x*e.y-r.y*e.x,t}function ho(r,e,t){return Math.sqrt(r*r+e*e+t*t)}function jr(r){return new He(r[0],r[1],r[2])}var nl=class{constructor(){this.indices=[],this.vertices=[],this.colors=[],this.normals=[],this.uvs=[],this.material=null}GetBounds(){let e=[1/0,1/0,1/0],t=[-1/0,-1/0,-1/0];for(let n=0;n<this.vertices.length/3;n++)for(let i=0;i<3;i++)e[i]=Math.min(e[i],this.vertices[n*3+i]),t[i]=Math.max(t[i],this.vertices[n*3+i]);return{min:e,max:t}}GetByteLength(e,t){let n=this.indices.length,i=this.vertices.length+this.colors.length+this.normals.length+this.uvs.length;return n*e+i*t}},il=class{constructor(){this.primitives=[]}PrimitiveCount(){return this.primitives.length}GetPrimitive(e){return this.primitives[e]}GetByteLength(e,t){let n=0;for(let i=0;i<this.primitives.length;i++){let s=this.primitives[i];n+=s.GetByteLength(e,t)}return n}};function fo(r){function e(a,l,c,u){function h(y,d,p){return d!==null?y.GetVertexColor(d):p?new Et(0,0,0):null}function f(y,d,p){return d!==null?y.GetTextureUV(d):p?new wt(0,0):null}function m(y,d,p){let _=y.VertexColorCount()>0,v=y.TextureUVCount()>0,x=y.GetVertex(d.vertex),M=y.GetNormal(d.normal),I=p.vertices.length/3;p.indices.push(I),p.vertices.push(x.x,x.y,x.z);let w=h(y,d.color,_);w!==null&&p.colors.push(w.r/255,w.g/255,w.b/255),p.normals.push(M.x,M.y,M.z);let L=f(y,d.uv,v);return L!==null&&p.uvs.push(L.x,L.y),{index:I,color:w,normal:M,uv:L}}function g(y,d,p){function _(M,I,w){if(w===null&&I===null)return!0;let L=h(M,I,!0);return Mr(w,L)}function v(M,I,w){let L=M.GetNormal(I);return li(w,L)}function x(M,I,w){if(w===null&&I===null)return!0;let L=f(M,I,!0);return Pi(w,L)}for(let M=0;M<d.length;M++){let I=d[M],w=_(y,p.color,I.color),L=v(y,p.normal,I.normal),T=x(y,p.uv,I.uv);if(w&&L&&T)return I}return null}if(u.has(l.vertex)){let y=u.get(l.vertex),d=g(a,y,l);if(d!==null)c.indices.push(d.index);else{let p=m(a,l,c);y.push(p)}}else{let y=m(a,l,c);u.set(l.vertex,[y])}}let t=new il,n=r.TriangleCount();if(n===0)return null;let i=[];for(let a=0;a<n;a++)i.push(a);i.sort((a,l)=>{let c=r.GetTriangle(a),u=r.GetTriangle(l);return c.mat-u.mat});let s=null,o=null;for(let a=0;a<i.length;a++){let l=i[a],c=r.GetTriangle(l);(s===null||s.material!==c.mat)&&(s=new nl,s.material=c.mat,o=new Map,t.primitives.push(s));let u={vertex:c.v0,color:c.c0,normal:c.n0,uv:c.u0},h={vertex:c.v1,color:c.c1,normal:c.n1,uv:c.u1},f={vertex:c.v2,color:c.c2,normal:c.n2,uv:c.u2};e(r,u,s,o),e(r,h,s,o),e(r,f,s,o)}return t}function fn(r){return new TextDecoder("utf-8").decode(r)}function vp(r){let e="",t=new Uint8Array(r);for(let n=0;n<t.byteLength;n++)e+=String.fromCharCode(t[n]);return e}function xp(r){let e=new ArrayBuffer(r.length),t=new Uint8Array(e);for(let n=0;n<r.length;n++)t[n]=r.charCodeAt(n);return e}function po(r){return new TextEncoder().encode(r).buffer}function Ss(r){let e="data:";if(!r.startsWith(e))return null;let t=r.indexOf(";");if(t===-1)return null;let n=r.indexOf(",");if(n===-1)return null;let i=r.substring(e.length,e.length+t-5),s=atob(r.substring(n+1)),o=new ArrayBuffer(s.length),a=new Uint8Array(o);for(let l=0;l<s.length;l++)a[l]=s.charCodeAt(l);return{mimeType:i,buffer:o}}function Yr(r){if(r==null)return"";let e=r.split("/");return e.length===0?"":e[e.length-1]}function As(r){let e=new Blob([r]);return URL.createObjectURL(e)}function Cc(r,e){let t=new Blob([r],{type:e});return URL.createObjectURL(t)}function Rc(r){URL.revokeObjectURL(r)}var jt=class{constructor(e){this.name=e,this.content=null}GetName(){return this.name}SetName(e){this.name=e}GetTextContent(){return fn(this.content)}GetBufferContent(){return this.content}SetTextContent(e){let t=po(e);this.content=t}SetBufferContent(e){this.content=e}},bn=class{constructor(){}CanExport(e,t){return!1}Export(e,t,n){let i=[];this.ExportContent(e,t,i,()=>{n(i)})}ExportContent(e,t,n,i){}GetExportedMaterialName(e){return this.GetExportedName(e,"Material")}GetExportedMeshName(e){return this.GetExportedName(e,"Mesh")}GetExportedName(e,t){return e.length===0?t:e}};var mo=class extends bn{constructor(){super(),this.rhino=null}CanExport(e,t){return e===nn.Binary&&t==="3dm"}ExportContent(e,t,n,i){this.rhino===null?Qi("loaders/rhino3dm.min.js").then(()=>{rhino3dm().then(s=>{this.rhino=s,this.ExportRhinoContent(e,n,i)})}).catch(()=>{i()}):this.ExportRhinoContent(e,n,i)}ExportRhinoContent(e,t,n){function i(c){return{r:c.r,g:c.g,b:c.b,a:255}}let s=new jt("model.3dm");t.push(s);let o=new this.rhino.File3dm;e.EnumerateTransformedMeshInstances(c=>{let u=fo(c);for(let h=0;h<u.PrimitiveCount();h++){let f=u.GetPrimitive(h),m={data:{attributes:{position:{itemSize:3,type:"Float32Array",array:f.vertices},normal:{itemSize:3,type:"Float32Array",array:f.normals}},index:{type:"Uint16Array",array:f.indices}}},g=e.GetMaterial(f.material),y=new this.rhino.Material;y.name=this.GetExportedMaterialName(g.name),g.type===In.Phong&&(y.ambientColor=i(g.ambient),y.specularColor=i(g.specular)),y.diffuseColor=i(g.color),y.transparency=1-g.opacity;let d=o.materials().count();o.materials().add(y);let p=new this.rhino.Mesh.createFromThreejsJSON(m),_=new this.rhino.ObjectAttributes;_.name=this.GetExportedMeshName(c.GetName()),_.materialSource=this.rhino.ObjectMaterialSource.MaterialFromObject,_.materialIndex=d,o.objects().add(p,_)}});let a=new this.rhino.File3dmWriteOptions;a.version=6;let l=o.toByteArray(a);s.SetBufferContent(l),n()}};var Bt={Text:1,Integer:2,Number:3,Boolean:4,Percent:5,Color:6},Jt=class r{constructor(e,t,n){this.type=e,this.name=t,this.value=n}Clone(){return this.type===Bt.Color?new r(this.type,this.name,this.value.Clone()):new r(this.type,this.name,this.value)}},Fn=class r{constructor(e){this.name=e,this.properties=[]}PropertyCount(){return this.properties.length}AddProperty(e){this.properties.push(e)}GetProperty(e){return this.properties[e]}Clone(){let e=new r(this.name);for(let t of this.properties)e.AddProperty(t.Clone());return e}};function Ic(r){return r.type===Bt.Text?mc(r.value):r.type===Bt.Integer?r.value.toLocaleString():r.type===Bt.Number?r.value.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}):r.type===Bt.Boolean?r.value?"True":"False":r.type===Bt.Percent?parseInt(r.value*100,10).toString()+"%":r.type===Bt.Color?"#"+Sc(r.value):null}function Q0(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}var go=class extends bn{constructor(){super()}CanExport(e,t){return e===nn.Text&&t==="bim"}ExportContent(e,t,n,i){let s={schema_version:"1.1.0",meshes:[],elements:[],info:{}};this.ExportProperties(e.GetModel(),s.info);let o=0;e.EnumerateTransformedMeshInstances(l=>{let c={mesh_id:o,coordinates:[],indices:[]};l.EnumerateVertices(g=>{c.coordinates.push(g.x,g.y,g.z)}),l.EnumerateTriangleVertexIndices((g,y,d)=>{c.indices.push(g,y,d)});let u={mesh_id:o,type:"Other",color:{r:200,g:200,b:200,a:255},vector:{x:0,y:0,z:0},rotation:{qx:0,qy:0,qz:0,qw:1},guid:Q0(),info:{}},h=null,f=!0,m=[];for(let g=0;g<l.TriangleCount();g++){let y=l.GetTriangle(g),d=e.GetMaterial(y.mat),p={r:d.color.r,g:d.color.g,b:d.color.b,a:En(d.opacity)};m.push(p.r,p.g,p.b,p.a),f&&(h===null?h=p:(h.r!==p.r||h.g!==p.g||h.b!==p.b||h.a!==p.a)&&(f=!1,h=null))}f?u.color=h:u.face_colors=m,u.info.Name=l.GetName(),this.ExportProperties(l,u.info),s.meshes.push(c),s.elements.push(u),o+=1});let a=new jt("model.bim");a.SetTextContent(JSON.stringify(s,null,4)),n.push(a),i()}ExportProperties(e,t){for(let n=0;n<e.PropertyGroupCount();n++){let i=e.GetPropertyGroup(n);for(let s=0;s<i.PropertyCount();s++){let o=i.GetProperty(s);t[o.name]=Ic(o)}}}};var Ni=class{constructor(e,t){this.arrayBuffer=new ArrayBuffer(e),this.dataView=new DataView(this.arrayBuffer),this.isLittleEndian=t,this.position=0}GetPosition(){return this.position}SetPosition(e){this.position=e}End(){return this.position>=this.arrayBuffer.byteLength}GetBuffer(){return this.arrayBuffer}WriteArrayBuffer(e){let t=new Uint8Array(e);new Uint8Array(this.arrayBuffer).set(t,this.position),this.position+=e.byteLength}WriteBoolean8(e){this.dataView.setInt8(this.position,e?1:0),this.position=this.position+1}WriteCharacter8(e){this.dataView.setInt8(this.position,e),this.position=this.position+1}WriteUnsignedCharacter8(e){this.dataView.setUint8(this.position,e),this.position=this.position+1}WriteInteger16(e){this.dataView.setInt16(this.position,e,this.isLittleEndian),this.position=this.position+2}WriteUnsignedInteger16(e){this.dataView.setUint16(this.position,e,this.isLittleEndian),this.position=this.position+2}WriteInteger32(e){this.dataView.setInt32(this.position,e,this.isLittleEndian),this.position=this.position+4}WriteUnsignedInteger32(e){this.dataView.setUint32(this.position,e,this.isLittleEndian),this.position=this.position+4}WriteFloat32(e){this.dataView.setFloat32(this.position,e,this.isLittleEndian),this.position=this.position+4}WriteDouble64(e){this.dataView.setFloat64(this.position,e,this.isLittleEndian),this.position=this.position+8}};var Oi=class r{constructor(e,t,n,i){this.x=e,this.y=t,this.z=n,this.w=i}Clone(){return new r(this.x,this.y,this.z,this.w)}};var Xn=class{constructor(e,t,n,i){this.x=e,this.y=t,this.z=n,this.w=i}};function _p(r,e){return It(r.x,e.x)&&It(r.y,e.y)&&It(r.z,e.z)&&It(r.w,e.w)}function yo(r){return new Xn(r[0],r[1],r[2],r[3])}function Pc(r,e){let t=e/2,n=Math.sin(t);return new Xn(r.x*n,r.y*n,r.z*n,Math.cos(t))}function Tp(r,e,t,n){let i=Math.cos(r/2),s=Math.cos(e/2),o=Math.cos(t/2),a=Math.sin(r/2),l=Math.sin(e/2),c=Math.sin(t/2),u=new Xn(0,0,0,1);if(n==="XYZ")u.x=a*s*o+i*l*c,u.y=i*l*o-a*s*c,u.z=i*s*c+a*l*o,u.w=i*s*o-a*l*c;else if(n==="YXZ")u.x=a*s*o+i*l*c,u.y=i*l*o-a*s*c,u.z=i*s*c-a*l*o,u.w=i*s*o+a*l*c;else if(n==="ZXY")u.x=a*s*o-i*l*c,u.y=i*l*o+a*s*c,u.z=i*s*c+a*l*o,u.w=i*s*o-a*l*c;else if(n==="ZYX")u.x=a*s*o-i*l*c,u.y=i*l*o+a*s*c,u.z=i*s*c-a*l*o,u.w=i*s*o+a*l*c;else if(n==="YZX")u.x=a*s*o+i*l*c,u.y=i*l*o+a*s*c,u.z=i*s*c-a*l*o,u.w=i*s*o-a*l*c;else if(n==="XZY")u.x=a*s*o-i*l*c,u.y=i*l*o-a*s*c,u.z=i*s*c+a*l*o,u.w=i*s*o+a*l*c;else return null;return u}var ln=class r{constructor(e){this.matrix=null,e!=null&&(this.matrix=e)}IsValid(){return this.matrix!==null}Set(e){return this.matrix=e,this}Get(){return this.matrix}Clone(){let e=[this.matrix[0],this.matrix[1],this.matrix[2],this.matrix[3],this.matrix[4],this.matrix[5],this.matrix[6],this.matrix[7],this.matrix[8],this.matrix[9],this.matrix[10],this.matrix[11],this.matrix[12],this.matrix[13],this.matrix[14],this.matrix[15]];return new r(e)}CreateIdentity(){return this.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],this}IsIdentity(){let e=new r().CreateIdentity().Get();for(let t=0;t<16;t++)if(!It(this.matrix[t],e[t]))return!1;return!0}CreateTranslation(e,t,n){return this.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,e,t,n,1],this}CreateRotation(e,t,n,i){let s=e+e,o=t+t,a=n+n,l=e*s,c=e*o,u=e*a,h=t*o,f=t*a,m=n*a,g=i*s,y=i*o,d=i*a;return this.matrix=[1-(h+m),c+d,u-y,0,c-d,1-(l+m),f+g,0,u+y,f-g,1-(l+h),0,0,0,0,1],this}CreateRotationAxisAngle(e,t){let n=Pc(e,t);return this.CreateRotation(n.x,n.y,n.z,n.w)}CreateScale(e,t,n){return this.matrix=[e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1],this}ComposeTRS(e,t,n){let i=e.x,s=e.y,o=e.z,a=t.x,l=t.y,c=t.z,u=t.w,h=n.x,f=n.y,m=n.z,g=a+a,y=l+l,d=c+c,p=a*g,_=a*y,v=a*d,x=l*y,M=l*d,I=c*d,w=u*g,L=u*y,T=u*d;return this.matrix=[(1-(x+I))*h,(_+T)*h,(v-L)*h,0,(_-T)*f,(1-(p+I))*f,(M+w)*f,0,(v+L)*m,(M-w)*m,(1-(p+x))*m,0,i,s,o,1],this}DecomposeTRS(){let e=new He(this.matrix[12],this.matrix[13],this.matrix[14]),t=ho(this.matrix[0],this.matrix[1],this.matrix[2]),n=ho(this.matrix[4],this.matrix[5],this.matrix[6]),i=ho(this.matrix[8],this.matrix[9],this.matrix[10]),s=this.Determinant();Tr(s)&&(t*=-1);let o=new He(t,n,i),a=this.matrix[0]/t,l=this.matrix[4]/n,c=this.matrix[8]/i,u=this.matrix[1]/t,h=this.matrix[5]/n,f=this.matrix[9]/i,m=this.matrix[2]/t,g=this.matrix[6]/n,y=this.matrix[10]/i,d=null,p=a+h+y;if(p>0){let _=Math.sqrt(p+1)*2;d=new Xn((g-f)/_,(c-m)/_,(u-l)/_,.25*_)}else if(a>h&&a>y){let _=Math.sqrt(1+a-h-y)*2;d=new Xn(.25*_,(l+u)/_,(c+m)/_,(g-f)/_)}else if(h>y){let _=Math.sqrt(1+h-a-y)*2;d=new Xn((l+u)/_,.25*_,(f+g)/_,(c-m)/_)}else{let _=Math.sqrt(1+y-a-h)*2;d=new Xn((c+m)/_,(f+g)/_,.25*_,(u-l)/_)}return{translation:e,rotation:d,scale:o}}Determinant(){let e=this.matrix[0],t=this.matrix[1],n=this.matrix[2],i=this.matrix[3],s=this.matrix[4],o=this.matrix[5],a=this.matrix[6],l=this.matrix[7],c=this.matrix[8],u=this.matrix[9],h=this.matrix[10],f=this.matrix[11],m=this.matrix[12],g=this.matrix[13],y=this.matrix[14],d=this.matrix[15],p=e*o-t*s,_=e*a-n*s,v=e*l-i*s,x=t*a-n*o,M=t*l-i*o,I=n*l-i*a,w=c*g-u*m,L=c*y-h*m,T=c*d-f*m,C=u*y-h*g,V=u*d-f*g,k=h*d-f*y;return p*k-_*V+v*C+x*T-M*L+I*w}Invert(){let e=this.matrix[0],t=this.matrix[1],n=this.matrix[2],i=this.matrix[3],s=this.matrix[4],o=this.matrix[5],a=this.matrix[6],l=this.matrix[7],c=this.matrix[8],u=this.matrix[9],h=this.matrix[10],f=this.matrix[11],m=this.matrix[12],g=this.matrix[13],y=this.matrix[14],d=this.matrix[15],p=e*o-t*s,_=e*a-n*s,v=e*l-i*s,x=t*a-n*o,M=t*l-i*o,I=n*l-i*a,w=c*g-u*m,L=c*y-h*m,T=c*d-f*m,C=u*y-h*g,V=u*d-f*g,k=h*d-f*y,F=p*k-_*V+v*C+x*T-M*L+I*w;if(It(F,0))return null;let U=[(o*k-a*V+l*C)/F,(n*V-t*k-i*C)/F,(g*I-y*M+d*x)/F,(h*M-u*I-f*x)/F,(a*T-s*k-l*L)/F,(e*k-n*T+i*L)/F,(y*v-m*I-d*_)/F,(c*I-h*v+f*_)/F,(s*V-o*T+l*w)/F,(t*T-e*V-i*w)/F,(m*M-g*v+d*p)/F,(u*v-c*M-f*p)/F,(o*L-s*C-a*w)/F,(e*C-t*L+n*w)/F,(g*_-m*x-y*p)/F,(c*x-u*_+h*p)/F];return new r(U)}Transpose(){let e=[this.matrix[0],this.matrix[4],this.matrix[8],this.matrix[12],this.matrix[1],this.matrix[5],this.matrix[9],this.matrix[13],this.matrix[2],this.matrix[6],this.matrix[10],this.matrix[14],this.matrix[3],this.matrix[7],this.matrix[11],this.matrix[15]];return new r(e)}InvertTranspose(){let e=this.Invert();return e===null?null:e.Transpose()}MultiplyVector(e){let t=e.x,n=e.y,i=e.z,s=e.w,o=this.matrix[0],a=this.matrix[1],l=this.matrix[2],c=this.matrix[3],u=this.matrix[4],h=this.matrix[5],f=this.matrix[6],m=this.matrix[7],g=this.matrix[8],y=this.matrix[9],d=this.matrix[10],p=this.matrix[11],_=this.matrix[12],v=this.matrix[13],x=this.matrix[14],M=this.matrix[15];return new Oi(t*o+n*u+i*g+s*_,t*a+n*h+i*y+s*v,t*l+n*f+i*d+s*x,t*c+n*m+i*p+s*M)}MultiplyMatrix(e){let t=this.matrix[0],n=this.matrix[1],i=this.matrix[2],s=this.matrix[3],o=this.matrix[4],a=this.matrix[5],l=this.matrix[6],c=this.matrix[7],u=this.matrix[8],h=this.matrix[9],f=this.matrix[10],m=this.matrix[11],g=this.matrix[12],y=this.matrix[13],d=this.matrix[14],p=this.matrix[15],_=e.matrix[0],v=e.matrix[1],x=e.matrix[2],M=e.matrix[3],I=e.matrix[4],w=e.matrix[5],L=e.matrix[6],T=e.matrix[7],C=e.matrix[8],V=e.matrix[9],k=e.matrix[10],F=e.matrix[11],U=e.matrix[12],K=e.matrix[13],Z=e.matrix[14],Y=e.matrix[15],H=[t*_+n*I+i*C+s*U,t*v+n*w+i*V+s*K,t*x+n*L+i*k+s*Z,t*M+n*T+i*F+s*Y,o*_+a*I+l*C+c*U,o*v+a*w+l*V+c*K,o*x+a*L+l*k+c*Z,o*M+a*T+l*F+c*Y,u*_+h*I+f*C+m*U,u*v+h*w+f*V+m*K,u*x+h*L+f*k+m*Z,u*M+h*T+f*F+m*Y,g*_+y*I+d*C+p*U,g*v+y*w+d*V+p*K,g*x+y*L+d*k+p*Z,g*M+y*T+d*F+p*Y];return new r(H)}};function Lc(r,e){let t=r.Get(),n=e.Get();for(let i=0;i<16;i++)if(!It(t[i],n[i]))return!1;return!0}var rn=class r{constructor(e){e!=null?this.matrix=e:(this.matrix=new ln,this.matrix.CreateIdentity())}SetMatrix(e){return this.matrix=e,this}GetMatrix(){return this.matrix}IsIdentity(){return this.matrix.IsIdentity()}AppendMatrix(e){return this.matrix=this.matrix.MultiplyMatrix(e),this}Append(e){return this.AppendMatrix(e.GetMatrix()),this}TransformCoord3D(e){let t=new Oi(e.x,e.y,e.z,1),n=this.matrix.MultiplyVector(t);return new He(n.x,n.y,n.z)}Clone(){let e=this.matrix.Clone();return new r(e)}};function Ep(r,e){return Lc(r.GetMatrix(),e.GetMatrix())}var ir={Empty:0,TriangleMesh:1};function Kr(r){return r.TriangleCount()>0?ir.TriangleMesh:ir.Empty}function ws(r,e,t){let n=Mn(e,r),i=Mn(t,r),s=Li(n,i);return s.Normalize(),s}function rr(r,e){if(!e.IsIdentity()){for(let t=0;t<r.VertexCount();t++){let n=r.GetVertex(t),i=e.TransformCoord3D(n);n.x=i.x,n.y=i.y,n.z=i.z}if(r.NormalCount()>0){let t=e.GetMatrix().InvertTranspose();if(t!==null){let n=new rn(t);for(let i=0;i<r.NormalCount();i++){let s=r.GetNormal(i),o=n.TransformCoord3D(s);s.x=o.x,s.y=o.y,s.z=o.z}}}}}function Nc(r){for(let e=0;e<r.TriangleCount();e++){let t=r.GetTriangle(e),n=t.v1;t.v1=t.v2,t.v2=n}}var rl=class{constructor(){}VertexCount(){return 0}VertexColorCount(){return 0}NormalCount(){return 0}TextureUVCount(){return 0}TriangleCount(){return 0}EnumerateVertices(e){}EnumerateTriangleVertexIndices(e){}EnumerateTriangleVertices(e){}},sr=class extends rl{constructor(){super(),this.name="",this.propertyGroups=[]}GetName(){return this.name}SetName(e){this.name=e}PropertyGroupCount(){return this.propertyGroups.length}AddPropertyGroup(e){return this.propertyGroups.push(e),this.propertyGroups.length-1}GetPropertyGroup(e){return this.propertyGroups[e]}CloneProperties(e){for(let t of this.propertyGroups)e.AddPropertyGroup(t.Clone())}};var yi=class{constructor(e,t){this.nodeId=e,this.meshIndex=t}IsEqual(e){return this.nodeId===e.nodeId&&this.meshIndex===e.meshIndex}GetKey(){return this.nodeId.toString()+":"+this.meshIndex.toString()}},br=class extends sr{constructor(e,t,n){super(),this.id=e,this.node=t,this.mesh=n}GetId(){return this.id}GetTransformation(){return this.node.GetWorldTransformation()}GetMesh(){return this.mesh}VertexCount(){return this.mesh.VertexCount()}VertexColorCount(){return this.mesh.VertexColorCount()}NormalCount(){return this.mesh.NormalCount()}TextureUVCount(){return this.mesh.TextureUVCount()}TriangleCount(){return this.mesh.TriangleCount()}EnumerateVertices(e){let t=this.node.GetWorldTransformation();t.IsIdentity()?this.mesh.EnumerateVertices(e):this.mesh.EnumerateVertices(n=>{let i=t.TransformCoord3D(n);e(i)})}EnumerateTriangleVertexIndices(e){this.mesh.EnumerateTriangleVertexIndices(e)}EnumerateTriangleVertices(e){let t=this.node.GetWorldTransformation();t.IsIdentity()?this.mesh.EnumerateTriangleVertices(e):this.mesh.EnumerateTriangleVertices((n,i,s)=>{let o=t.TransformCoord3D(n),a=t.TransformCoord3D(i),l=t.TransformCoord3D(s);e(o,a,l)})}PropertyGroupCount(){return this.mesh.PropertyGroupCount()}AddPropertyGroup(e){return this.mesh.AddPropertyGroup(e)}GetPropertyGroup(e){return this.mesh.GetPropertyGroup(e)}GetTransformedMesh(){let e=this.node.GetWorldTransformation(),t=this.mesh.Clone();return rr(t,e),t}};var Mp={UNSIGNED_INT:5125,FLOAT:5126},sl={ARRAY_BUFFER:34962,ELEMENT_ARRAY_BUFFER:34963},vo=class extends bn{constructor(){super(),this.components={index:{type:Mp.UNSIGNED_INT,size:4},number:{type:Mp.FLOAT,size:4}}}CanExport(e,t){return e===nn.Text&&t==="gltf"||e===nn.Binary&&t==="glb"}ExportContent(e,t,n,i){t===nn.Text?this.ExportAsciiContent(e,n):t===nn.Binary&&this.ExportBinaryContent(e,n),i()}ExportAsciiContent(e,t){let n=new jt("model.gltf"),i=new jt("model.bin");t.push(n),t.push(i);let s=this.GetMeshData(e),o=this.GetMainBuffer(s),a=this.GetMainJson(e,s);a.buffers.push({uri:i.GetName(),byteLength:o.byteLength});let l=new Map;this.ExportMaterials(e,a,c=>{let u=vn(c.name);if(l.has(u))return l.get(u);{let h=new jt(u);h.SetBufferContent(c.buffer),t.push(h);let f=a.textures.length;return l.set(u,f),a.images.push({uri:u}),a.textures.push({source:f}),f}}),n.SetTextContent(JSON.stringify(a,null,4)),i.SetBufferContent(o)}ExportBinaryContent(e,t){function n(x){let M=x%4;return M===0?x:x+(4-M)}function i(x,M,I){for(let w=0;w<I;w++)x.WriteUnsignedCharacter8(M)}let s=new jt("model.glb");t.push(s);let o=this.GetMeshData(e),a=this.GetMainBuffer(o),l=this.GetMainJson(e,o),c=[],u=a.byteLength,h=new Map;this.ExportMaterials(e,l,x=>{let M=vn(x.name),I=er(x.name);if(h.has(M))return h.get(M);{let w=l.bufferViews.length,L=l.textures.length;h.set(M,L);let T=x.buffer;return c.push(T),l.bufferViews.push({buffer:0,byteOffset:u,byteLength:T.byteLength}),u+=T.byteLength,l.images.push({bufferView:w,mimeType:"image/"+I}),l.textures.push({source:L}),L}});let f=a.byteLength;for(let x=0;x<c.length;x++){let M=c[x];f+=M.byteLength}let m=n(f);l.buffers.push({byteLength:m});let g=JSON.stringify(l),y=po(g),d=y.byteLength,p=n(d),_=12+8+p+8+m,v=new Ni(_,!0);v.WriteUnsignedInteger32(1179937895),v.WriteUnsignedInteger32(2),v.WriteUnsignedInteger32(_),v.WriteUnsignedInteger32(p),v.WriteUnsignedInteger32(1313821514),v.WriteArrayBuffer(y),i(v,32,p-d),v.WriteUnsignedInteger32(m),v.WriteUnsignedInteger32(5130562),v.WriteArrayBuffer(a);for(let x=0;x<c.length;x++){let M=c[x];v.WriteArrayBuffer(M)}i(v,0,m-f),s.SetBufferContent(v.GetBuffer())}GetMeshData(e){let t=[];return e.EnumerateMeshes(n=>{let i=fo(n);t.push({name:n.GetName(),buffer:i,offsets:[],sizes:[]})}),t}GetMainBuffer(e){let t=0;for(let i of e)t+=i.buffer.GetByteLength(this.components.index.size,this.components.number.size);let n=new Ni(t,!0);for(let i of e)for(let s=0;s<i.buffer.PrimitiveCount();s++){let o=i.buffer.GetPrimitive(s),a=n.GetPosition();for(let l=0;l<o.indices.length;l++)n.WriteUnsignedInteger32(o.indices[l]);for(let l=0;l<o.vertices.length;l++)n.WriteFloat32(o.vertices[l]);for(let l=0;l<o.colors.length;l++)n.WriteFloat32(nr(o.colors[l]));for(let l=0;l<o.normals.length;l++)n.WriteFloat32(o.normals[l]);for(let l=0;l<o.uvs.length;l++){let c=o.uvs[l];l%2===1&&(c*=-1),n.WriteFloat32(c)}i.offsets.push(a),i.sizes.push(n.GetPosition()-a)}return n.GetBuffer()}GetMainJson(e,t){class n{constructor(h,f){this.mainJson=h,this.byteOffset=f}AddBufferView(h,f){let m={buffer:0,byteOffset:this.byteOffset,byteLength:h,target:f};return this.mainJson.bufferViews.push(m),this.byteOffset+=h,this.mainJson.bufferViews.length-1}}function i(u,h){for(let f of h.GetMeshIndices()){let m=new yi(h.GetId(),f);if(u.IsMeshInstanceVisible(m))return!0}for(let f of h.GetChildNodes())if(i(u,f))return!0;return!1}function s(u,h,f,m){if(m.IsMeshNode())for(let g of m.GetMeshIndices())o(u,h,f,m,g,!0);else if(i(u,m)){let g={},y=m.GetName();y.length>0&&(g.name=y),m.GetTransformation().IsIdentity()||(g.matrix=m.GetTransformation().GetMatrix().Get()),f.push(g),h.push(f.length-1),g.children=[],a(u,g.children,f,m)}}function o(u,h,f,m,g,y){let d=new yi(m.GetId(),g);if(!u.IsMeshInstanceVisible(d))return;let p={mesh:u.MapMeshIndex(g)};y&&(m.GetTransformation().IsIdentity()||(p.matrix=m.GetTransformation().GetMatrix().Get())),f.push(p),h.push(f.length-1)}function a(u,h,f,m){for(let g of m.GetChildNodes())s(u,h,f,g);for(let g of m.GetMeshIndices())o(u,h,f,m,g,!1)}let l={asset:{generator:"https://3dviewer.net",version:"2.0"},scene:0,scenes:[{nodes:[]}],nodes:[],materials:[],meshes:[],buffers:[],bufferViews:[],accessors:[]},c=e.GetModel().GetRootNode();a(e,l.scenes[0].nodes,l.nodes,c);for(let u of t){let h={name:this.GetExportedMeshName(u.name),primitives:[]},f=u.buffer.primitives;for(let m=0;m<f.length;m++){let g=f[m],y=new n(l,u.offsets[m]),d=y.AddBufferView(g.indices.length*this.components.index.size,sl.ELEMENT_ARRAY_BUFFER),p=y.AddBufferView(g.vertices.length*this.components.number.size,sl.ARRAY_BUFFER),_=null;g.colors.length>0&&(_=y.AddBufferView(g.colors.length*this.components.number.size,sl.ARRAY_BUFFER));let v=y.AddBufferView(g.normals.length*this.components.number.size,sl.ARRAY_BUFFER),x=null;g.uvs.length>0&&(x=y.AddBufferView(g.uvs.length*this.components.number.size,sl.ARRAY_BUFFER));let M={attributes:{},mode:4,material:g.material},I=g.GetBounds();l.accessors.push({bufferView:d,byteOffset:0,componentType:this.components.index.type,count:g.indices.length,type:"SCALAR"}),M.indices=l.accessors.length-1,l.accessors.push({bufferView:p,byteOffset:0,componentType:this.components.number.type,count:g.vertices.length/3,min:I.min,max:I.max,type:"VEC3"}),M.attributes.POSITION=l.accessors.length-1,_!==null&&(l.accessors.push({bufferView:_,byteOffset:0,componentType:this.components.number.type,count:g.colors.length/3,type:"VEC3"}),M.attributes.COLOR_0=l.accessors.length-1),l.accessors.push({bufferView:v,byteOffset:0,componentType:this.components.number.type,count:g.normals.length/3,type:"VEC3"}),M.attributes.NORMAL=l.accessors.length-1,x!==null&&(l.accessors.push({bufferView:x,byteOffset:0,componentType:this.components.number.type,count:g.uvs.length/2,type:"VEC2"}),M.attributes.TEXCOORD_0=l.accessors.length-1),h.primitives.push(M)}l.meshes.push(h)}return l}ExportMaterials(e,t,n){function i(s,o,a,l){function c(d,p){return[nr(d.r/255),nr(d.g/255),nr(d.b/255),p]}function u(d){return[nr(d.r/255),nr(d.g/255),nr(d.b/255)]}function h(d,p,_){if(p===null||!p.IsValid())return null;d.images===void 0&&(d.images=[]),d.textures===void 0&&(d.textures=[]);let x={index:_(p)};if(p.HasTransformation()){let M="KHR_texture_transform";d.extensionsUsed===void 0&&(d.extensionsUsed=[]),d.extensionsUsed.indexOf(M)===-1&&d.extensionsUsed.push(M),x.extensions={KHR_texture_transform:{offset:[p.offset.x,-p.offset.y],scale:[p.scale.x,p.scale.y],rotation:-p.rotation}}}return x}let f={name:s.GetExportedMaterialName(a.name),pbrMetallicRoughness:{baseColorFactor:c(a.color,a.opacity)},emissiveFactor:u(a.emissive),doubleSided:!0,alphaMode:"OPAQUE"};a.transparent&&(f.alphaMode="BLEND");let m=h(o,a.diffuseMap,l);if(m!==null&&(a.multiplyDiffuseMap||(f.pbrMetallicRoughness.baseColorFactor=c(new Et(255,255,255),a.opacity)),f.pbrMetallicRoughness.baseColorTexture=m),a.type===In.Physical){let d=h(o,a.metalnessMap,l);d!==null?f.pbrMetallicRoughness.metallicRoughnessTexture=d:(f.pbrMetallicRoughness.metallicFactor=a.metalness,f.pbrMetallicRoughness.roughnessFactor=a.roughness)}let g=h(o,a.normalMap,l);g!==null&&(f.normalTexture=g);let y=h(o,a.emissiveMap,l);y!==null&&(f.emissiveTexture=y),o.materials.push(f)}for(let s=0;s<e.MaterialCount();s++){let o=e.GetMaterial(s);i(this,t,o,n)}}};var ol=class{constructor(e){this.transformation=new rn,this.isMeshVisible=t=>!0,so(e,this)}},xo=class{constructor(e,t){this.model=e,this.settings=t||new ol,this.visibleMeshes=null,this.meshToVisibleMeshIndex=null}GetModel(){return this.model}MaterialCount(){return this.model.MaterialCount()}GetMaterial(e){return this.model.GetMaterial(e)}VertexCount(){let e=0;return this.EnumerateMeshInstances(t=>{e+=t.VertexCount()}),e}TriangleCount(){let e=0;return this.EnumerateMeshInstances(t=>{e+=t.TriangleCount()}),e}MeshCount(){let e=0;return this.EnumerateMeshes(t=>{e+=1}),e}EnumerateMeshes(e){this.FillVisibleMeshCache();for(let t=0;t<this.model.MeshCount();t++)if(this.visibleMeshes.has(t)){let n=this.model.GetMesh(t);e(n)}}MapMeshIndex(e){return this.FillVisibleMeshCache(),this.meshToVisibleMeshIndex.get(e)}IsMeshInstanceVisible(e){return this.settings.isMeshVisible(e)}MeshInstanceCount(){let e=0;return this.EnumerateMeshInstances(t=>{e+=1}),e}EnumerateMeshInstances(e){this.model.EnumerateMeshInstances(t=>{this.settings.isMeshVisible(t.GetId())&&e(t)})}EnumerateTransformedMeshInstances(e){this.EnumerateMeshInstances(t=>{let n=t.GetTransformation();this.settings.transformation.IsIdentity()||n.Append(this.settings.transformation);let s=t.GetMesh().Clone();n.IsIdentity()||rr(s,n),e(s)})}EnumerateVerticesAndTriangles(e){let t=[];this.EnumerateTransformedMeshInstances(i=>{t.push(i)});for(let i of t)i.EnumerateVertices(s=>{e.onVertex(s.x,s.y,s.z)});let n=0;for(let i of t)i.EnumerateTriangleVertexIndices((s,o,a)=>{e.onTriangle(s+n,o+n,a+n)}),n+=i.VertexCount()}EnumerateTrianglesWithNormals(e){this.EnumerateTransformedMeshInstances(t=>{t.EnumerateTriangleVertices((n,i,s)=>{let o=ws(n,i,s);e(n,i,s,o)})})}FillVisibleMeshCache(){if(this.visibleMeshes!==null&&this.meshToVisibleMeshIndex!==null)return;this.visibleMeshes=new Set,this.model.EnumerateMeshInstances(t=>{let n=t.GetId();this.settings.isMeshVisible(n)&&this.visibleMeshes.add(n.meshIndex)}),this.meshToVisibleMeshIndex=new Map;let e=0;for(let t=0;t<this.model.MeshCount();t++)this.visibleMeshes.has(t)&&(this.meshToVisibleMeshIndex.set(t,e),e+=1)}};var $n=class{constructor(){this.text="",this.indentation=0}GetText(){return this.text}Indent(e){this.indentation+=e}WriteArrayLine(e){this.WriteLine(e.join(" "))}WriteLine(e){this.WriteIndentation(),this.Write(e+` `)}WriteIndentation(){for(let e=0;e<this.indentation;e++)this.Write(" ")}Write(e){this.text+=e}};var _o=class extends bn{constructor(){super()}CanExport(e,t){return e===nn.Text&&t==="obj"}ExportContent(e,t,n,i){function s(g,y,d,p){if(d===null||!d.IsValid())return;let _=vn(d.name);if(g.WriteArrayLine([y,_]),p.findIndex(x=>x.GetName()===_)===-1){let x=new jt(_);x.SetBufferContent(d.buffer),p.push(x)}}let o=new jt("model.mtl"),a=new jt("model.obj");n.push(o),n.push(a);let l=new $n;l.WriteLine(this.GetHeaderText());for(let g=0;g<e.MaterialCount();g++){let y=e.GetMaterial(g);l.WriteArrayLine(["newmtl",this.GetExportedMaterialName(y.name)]),l.WriteArrayLine(["Kd",y.color.r/255,y.color.g/255,y.color.b/255]),l.WriteArrayLine(["d",y.opacity]),y.type===In.Phong&&(l.WriteArrayLine(["Ka",y.ambient.r/255,y.ambient.g/255,y.ambient.b/255]),l.WriteArrayLine(["Ks",y.specular.r/255,y.specular.g/255,y.specular.b/255]),l.WriteArrayLine(["Ns",y.shininess*1e3])),s(l,"map_Kd",y.diffuseMap,n),y.type===In.Phong&&s(l,"map_Ks",y.specularMap,n),s(l,"bump",y.bumpMap,n)}o.SetTextContent(l.GetText());let c=new $n;c.WriteLine(this.GetHeaderText()),c.WriteArrayLine(["mtllib",o.GetName()]);let u=0,h=0,f=0,m=null;e.EnumerateTransformedMeshInstances(g=>{c.WriteArrayLine(["g",this.GetExportedMeshName(g.GetName())]);for(let y=0;y<g.VertexCount();y++){let d=g.GetVertex(y);c.WriteArrayLine(["v",d.x,d.y,d.z])}for(let y=0;y<g.NormalCount();y++){let d=g.GetNormal(y);c.WriteArrayLine(["vn",d.x,d.y,d.z])}for(let y=0;y<g.TextureUVCount();y++){let d=g.GetTextureUV(y);c.WriteArrayLine(["vt",d.x,d.y])}for(let y=0;y<g.TriangleCount();y++){let d=g.GetTriangle(y),p=d.v0+u+1,_=d.v1+u+1,v=d.v2+u+1,x=d.n0+h+1,M=d.n1+h+1,I=d.n2+h+1;if(d.mat!==null){let C=e.GetMaterial(d.mat),V=this.GetExportedMaterialName(C.name);V!==m&&(c.WriteArrayLine(["usemtl",V]),m=V)}let w="",L="",T="";d.HasTextureUVs()&&(w=d.u0+f+1,L=d.u1+f+1,T=d.u2+f+1),c.WriteArrayLine(["f",[p,w,x].join("/"),[_,L,M].join("/"),[v,T,I].join("/")])}u+=g.VertexCount(),h+=g.NormalCount(),f+=g.TextureUVCount()}),a.SetTextContent(c.GetText()),i()}GetHeaderText(){return"# exported by https://3dviewer.net"}};var To=class extends bn{constructor(){super()}CanExport(e,t){return e===nn.Text&&t==="off"}ExportContent(e,t,n,i){let s=new jt("model.off");n.push(s);let o=new $n;o.WriteLine("OFF"),o.WriteArrayLine([e.VertexCount(),e.TriangleCount(),0]),e.EnumerateVerticesAndTriangles({onVertex:function(a,l,c){o.WriteArrayLine([a,l,c])},onTriangle:function(a,l,c){o.WriteArrayLine([3,a,l,c])}}),s.SetTextContent(o.GetText()),i()}};var Eo=class extends bn{constructor(){super()}CanExport(e,t){return(e===nn.Text||e===nn.Binary)&&t==="ply"}ExportContent(e,t,n,i){t===nn.Text?this.ExportText(e,n):this.ExportBinary(e,n),i()}ExportText(e,t){let n=new jt("model.ply");t.push(n);let i=new $n,s=e.VertexCount(),o=e.TriangleCount(),a=this.GetHeaderText("ascii",s,o);i.Write(a),e.EnumerateVerticesAndTriangles({onVertex:function(l,c,u){i.WriteArrayLine([l,c,u])},onTriangle:function(l,c,u){i.WriteArrayLine([3,l,c,u])}}),n.SetTextContent(i.GetText())}ExportBinary(e,t){let n=new jt("model.ply");t.push(n);let i=e.VertexCount(),s=e.TriangleCount(),o=this.GetHeaderText("binary_little_endian",i,s),a=o.length+i*3*4+s*(1+3*4),l=new Ni(a,!0);for(let c=0;c<o.length;c++)l.WriteUnsignedCharacter8(o.charCodeAt(c));e.EnumerateVerticesAndTriangles({onVertex:function(c,u,h){l.WriteFloat32(c),l.WriteFloat32(u),l.WriteFloat32(h)},onTriangle:function(c,u,h){l.WriteUnsignedCharacter8(3),l.WriteInteger32(c),l.WriteInteger32(u),l.WriteInteger32(h)}}),n.SetBufferContent(l.GetBuffer())}GetHeaderText(e,t,n){let i=new $n;return i.WriteLine("ply"),i.WriteLine("format "+e+" 1.0"),i.WriteLine("element vertex "+t),i.WriteLine("property float x"),i.WriteLine("property float y"),i.WriteLine("property float z"),i.WriteLine("element face "+n),i.WriteLine("property list uchar int vertex_index"),i.WriteLine("end_header"),i.GetText()}};var Mo=class extends bn{constructor(){super()}CanExport(e,t){return(e===nn.Text||e===nn.Binary)&&t==="stl"}ExportContent(e,t,n,i){t===nn.Text?this.ExportText(e,n):this.ExportBinary(e,n),i()}ExportText(e,t){let n=new jt("model.stl");t.push(n);let i=new $n;i.WriteLine("solid Model"),e.EnumerateTrianglesWithNormals((s,o,a,l)=>{i.WriteArrayLine(["facet","normal",l.x,l.y,l.z]),i.Indent(1),i.WriteLine("outer loop"),i.Indent(1),i.WriteArrayLine(["vertex",s.x,s.y,s.z]),i.WriteArrayLine(["vertex",o.x,o.y,o.z]),i.WriteArrayLine(["vertex",a.x,a.y,a.z]),i.Indent(-1),i.WriteLine("endloop"),i.Indent(-1),i.WriteLine("endfacet")}),i.WriteLine("endsolid Model"),n.SetTextContent(i.GetText())}ExportBinary(e,t){let n=new jt("model.stl");t.push(n);let i=e.TriangleCount(),s=80,o=s+4+i*50,a=new Ni(o,!0);for(let l=0;l<s;l++)a.WriteUnsignedCharacter8(0);a.WriteUnsignedInteger32(i),e.EnumerateTrianglesWithNormals((l,c,u,h)=>{a.WriteFloat32(h.x),a.WriteFloat32(h.y),a.WriteFloat32(h.z),a.WriteFloat32(l.x),a.WriteFloat32(l.y),a.WriteFloat32(l.z),a.WriteFloat32(c.x),a.WriteFloat32(c.y),a.WriteFloat32(c.z),a.WriteFloat32(u.x),a.WriteFloat32(u.y),a.WriteFloat32(u.z),a.WriteUnsignedInteger16(0)}),n.SetBufferContent(a.GetBuffer())}};var Oc=class{constructor(){this.exporters=[new _o,new Mo,new Eo,new To,new vo,new mo,new go]}AddExporter(e){this.exporters.push(e)}Export(e,t,n,i,s){let o=null;for(let l=0;l<this.exporters.length;l++){let c=this.exporters[l];if(c.CanExport(n,i)){o=c;break}}if(o===null){s.onError();return}let a=new xo(e,t);o.Export(a,n,l=>{l.length===0?s.onError():s.onSuccess(l)})}};var Cs=class{constructor(e,t){this.min=e,this.max=t}GetMin(){return this.min}GetMax(){return this.max}GetCenter(){return new He((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,(this.min.z+this.max.z)/2)}},bo=class{constructor(){this.box=new Cs(new He(1/0,1/0,1/0),new He(-1/0,-1/0,-1/0)),this.isValid=!1}GetBox(){return this.isValid?this.box:null}AddPoint(e){this.box.min.x=Math.min(this.box.min.x,e.x),this.box.min.y=Math.min(this.box.min.y,e.y),this.box.min.z=Math.min(this.box.min.z,e.z),this.box.max.x=Math.max(this.box.max.x,e.x),this.box.max.y=Math.max(this.box.max.y,e.y),this.box.max.z=Math.max(this.box.max.z,e.z),this.isValid=!0}};var al=class r{constructor(e,t){this.boundingBox=e,this.level=t,this.pointItems=[],this.childNodes=[]}AddPoint(e,t,n){let i=this.FindNodeForPoint(e);if(i===null||i.FindPointDirectly(e)!==null)return!1;if(i.pointItems.length<n.maxPointsPerNode||i.level>=n.maxTreeDepth)return i.AddPointDirectly(e,t),!0;{i.CreateChildNodes();let s=i.pointItems;i.pointItems=[];for(let o=0;o<s.length;o++){let a=s[o];if(!i.AddPoint(a.point,a.data,n))return!1}return i.AddPoint(e,t,n)}}FindPoint(e){let t=this.FindNodeForPoint(e);return t===null?null:t.FindPointDirectly(e)}AddPointDirectly(e,t){this.pointItems.push({point:e,data:t})}FindPointDirectly(e){for(let t=0;t<this.pointItems.length;t++){let n=this.pointItems[t];if(li(e,n.point))return n.data}return null}FindNodeForPoint(e){if(!this.IsPointInBounds(e))return null;if(this.childNodes.length===0)return this;for(let t=0;t<this.childNodes.length;t++){let i=this.childNodes[t].FindNodeForPoint(e);if(i!==null)return i}return null}CreateChildNodes(){function e(a,l,c,u,h,f,m){let g=new Cs(new He(l,c,u),new He(l+h,c+f,u+m));a.childNodes.push(new r(g,a.level+1))}let t=this.boundingBox.min,