var OV=(()=>{var vi=Object.defineProperty;var On=Object.getOwnPropertyDescriptor;var Bn=Object.getOwnPropertyNames;var Ln=Object.prototype.hasOwnProperty;var Un=(s,e)=>{for(var t in e)vi(s,t,{get:e[t],enumerable:!0})},zn=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Bn(e))!Ln.call(s,i)&&i!==t&&vi(s,i,{get:()=>e[i],enumerable:!(r=On(e,i))||r.enumerable});return s};var _n=s=>zn(vi({},"__esModule",{value:!0}),s);var kn={};Un(kn,{AddCoord2D:()=>Yi,AddCoord3D:()=>Br,AddDiv:()=>bn,AddDomElement:()=>Bi,ArrayBufferToAsciiString:()=>Zi,ArrayBufferToUtf8String:()=>J,ArrayToColor:()=>Vr,ArrayToCoord3D:()=>Re,ArrayToQuaternion:()=>$e,AsciiStringToArrayBuffer:()=>Qi,Base64DataURIToArrayBuffer:()=>st,BezierTweenFunction:()=>rn,BigEps:()=>ji,BinaryReader:()=>pe,BinaryWriter:()=>Be,BoundingBoxCalculator3D:()=>Yt,Box3D:()=>bt,CalculateSurfaceArea:()=>In,CalculateTriangleNormal:()=>at,CalculateVolume:()=>yn,Camera:()=>De,CameraIsEqual3D:()=>ai,CheckModel:()=>hn,ClearDomElement:()=>wn,ClickDetector:()=>yi,Color:()=>R,ColorComponentFromFloat:()=>de,ColorFromFloatComponents:()=>ge,ColorIsEqual:()=>ke,ColorToHexString:()=>Ke,ColorToMaterialConverter:()=>Qt,ConvertColorToThreeColor:()=>ce,ConvertMeshToMeshBuffer:()=>Mt,ConvertModelToThreeObject:()=>mi,ConvertThreeColorToColor:()=>Rt,ConvertThreeGeometryToMesh:()=>qe,Coord2D:()=>N,Coord3D:()=>y,Coord4D:()=>Se,CoordDistance2D:()=>Bt,CoordDistance3D:()=>ye,CoordIsEqual2D:()=>Ae,CoordIsEqual3D:()=>Te,CopyObjectAttributes:()=>gt,CreateDiv:()=>Pn,CreateDomElement:()=>gi,CreateModelUrlParameters:()=>En,CreateObjectUrl:()=>lt,CreateObjectUrlWithMimeType:()=>zt,CreateUrlBuilder:()=>Oi,CreateUrlParser:()=>Mn,CrossVector3D:()=>Ge,DegRad:()=>Je,Direction:()=>S,DotVector3D:()=>Ut,EmbeddedViewer:()=>Si,Eps:()=>Wi,ExportedFile:()=>q,Exporter:()=>Ai,Exporter3dm:()=>_t,ExporterBase:()=>le,ExporterGltf:()=>Ht,ExporterModel:()=>kt,ExporterObj:()=>Wt,ExporterOff:()=>jt,ExporterPly:()=>qt,ExporterSettings:()=>jr,ExporterStl:()=>Xt,FaceMaterial:()=>Lt,File:()=>vt,FileFormat:()=>L,FileList:()=>At,FileSource:()=>Z,FinalizeModel:()=>ei,FlipMeshTrianglesOrientation:()=>Wr,GenerateCone:()=>or,GenerateCuboid:()=>ti,GenerateCylinder:()=>ri,GeneratePlatonicSolid:()=>ni,GenerateSphere:()=>ii,Generator:()=>ht,GeneratorHelper:()=>nr,GeneratorParams:()=>Nt,GetBoundingBox:()=>Gi,GetDefaultCamera:()=>Mi,GetDomElementClientCoordinates:()=>Ye,GetDomElementExternalHeight:()=>pi,GetDomElementExternalWidth:()=>ci,GetDomElementInnerDimensions:()=>xi,GetDomElementOuterHeight:()=>Fn,GetDomElementOuterWidth:()=>Rn,GetExternalLibPath:()=>Vt,GetFileExtension:()=>Ve,GetFileExtensionFromMimeType:()=>Qe,GetFileName:()=>X,GetIntegerFromStyle:()=>Q,GetMeshType:()=>et,GetShadingType:()=>$r,GetShadingTypeOfObject:()=>zi,GetTetrahedronSignedVolume:()=>Vi,GetTopology:()=>Ri,GetTriangleArea:()=>Pi,HasDefaultMaterial:()=>sn,HasHighpDriverIssue:()=>Qr,HexStringToColor:()=>Ji,ImportError:()=>ft,ImportErrorCode:()=>_e,ImportResult:()=>si,ImportSettings:()=>gr,Importer:()=>Cr,Importer3dm:()=>$t,Importer3ds:()=>er,ImporterBase:()=>z,ImporterBim:()=>dr,ImporterFileAccessor:()=>li,ImporterGltf:()=>rr,ImporterIfc:()=>ir,ImporterO3dv:()=>sr,ImporterObj:()=>lr,ImporterOff:()=>ar,ImporterPly:()=>ur,ImporterStl:()=>fr,ImporterStp:()=>hr,ImporterThree3mf:()=>xr,ImporterThreeBase:()=>Xe,ImporterThreeDae:()=>cr,ImporterThreeFbx:()=>mr,ImporterThreeSvg:()=>Di,ImporterThreeWrl:()=>pr,Init3DViewerElement:()=>_i,Init3DViewerElements:()=>Vn,InsertDomElementAfter:()=>vn,InsertDomElementBefore:()=>Sn,IntegerToHexString:()=>Y,IsDefined:()=>xt,IsDomElementVisible:()=>Gn,IsEqual:()=>V,IsEqualEps:()=>Xi,IsGreater:()=>Pr,IsGreaterOrEqual:()=>yt,IsLower:()=>Ct,IsLowerOrEqual:()=>Tt,IsModelEmpty:()=>Gt,IsNegative:()=>He,IsPositive:()=>we,IsPowerOfTwo:()=>Fi,IsSolid:()=>on,IsZero:()=>nt,LinearToSRGB:()=>ot,LinearTweenFunction:()=>nn,LoadExternalLibrary:()=>fe,MaterialBase:()=>Or,MaterialType:()=>ee,Matrix:()=>O,MatrixIsEqual:()=>kr,Mesh:()=>k,MeshBuffer:()=>zr,MeshInstance:()=>Ft,MeshInstanceId:()=>tt,MeshPrimitiveBuffer:()=>Ur,MeshType:()=>Le,Model:()=>Zt,ModelObject3D:()=>je,ModelToThreeConversionOutput:()=>yr,ModelToThreeConversionParams:()=>Tr,MouseInteraction:()=>Ci,NameFromLine:()=>ze,Navigation:()=>Mr,NavigationType:()=>he,NextPowerOfTwo:()=>fn,Node:()=>ue,NodeType:()=>Me,Object3D:()=>Zr,Octree:()=>Jt,OctreeNode:()=>wt,ParabolicTweenFunction:()=>qr,ParameterConverter:()=>K,ParameterListBuilder:()=>ui,ParameterListParser:()=>hi,ParametersFromLine:()=>Fe,PhongMaterial:()=>j,PhysicalMaterial:()=>We,Property:()=>re,PropertyGroup:()=>me,PropertyType:()=>se,Quaternion:()=>oe,QuaternionFromAxisAngle:()=>Hr,QuaternionFromXYZ:()=>en,QuaternionIsEqual:()=>$i,RadDeg:()=>qi,ReadFile:()=>Nr,ReadLines:()=>ve,ReplaceDefaultMaterialColor:()=>ln,RequestUrl:()=>Fr,RevokeObjectUrl:()=>_r,RunTaskAsync:()=>Pt,RunTasks:()=>vr,RunTasksBatch:()=>Ar,SRGBToLinear:()=>Oe,SetDomElementHeight:()=>Ui,SetDomElementOuterHeight:()=>Dn,SetDomElementOuterWidth:()=>Nn,SetDomElementWidth:()=>Li,SetExternalLibLocation:()=>ki,SetThreeMeshPolygonOffset:()=>Ii,ShadingModel:()=>wi,ShadingType:()=>ae,ShowDomElement:()=>An,SubCoord2D:()=>Ot,SubCoord3D:()=>te,TaskRunner:()=>Dt,TextWriter:()=>Ie,TextureIsEqual:()=>Ki,TextureMap:()=>Ce,TextureMapIsEqual:()=>Ze,ThreeConversionStateHandler:()=>fi,ThreeModelLoader:()=>Ir,ThreeNodeTree:()=>di,Topology:()=>Kt,TopologyEdge:()=>Yr,TopologyTriangle:()=>Kr,TopologyTriangleEdge:()=>Jr,TopologyVertex:()=>Xr,TouchInteraction:()=>Ti,TransformFileHostUrls:()=>Dr,TransformMesh:()=>Ue,Transformation:()=>H,TransformationIsEqual:()=>tn,TraverseThreeObject:()=>Ei,Triangle:()=>U,TweenCoord3D:()=>St,UpVector:()=>bi,UpdateMaterialTransparency:()=>ie,Utf8StringToArrayBuffer:()=>Et,ValueOrDefault:()=>be,VectorAngle3D:()=>Lr,VectorLength3D:()=>It,Viewer:()=>wr,ViewerExtraGeometry:()=>br,ViewerGeometry:()=>Er,WaitWhile:()=>Gr});function xt(s){return s!=null}function be(s,e){return s??e}function gt(s,e){if(!!xt(s))for(let t of Object.keys(s))xt(s[t])&&(e[t]=s[t])}var Dt=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,r){let i=0;e>0&&(i=parseInt((e-1)/t,10)+1),this.Run(i,{runTask:(n,o)=>{let l=n*t,a=Math.min((n+1)*t,e)-1;r.runTask(l,a,o)},onReady:r.onReady})}RunOnce(){setTimeout(()=>{this.callbacks.runTask(this.current,this.TaskReady.bind(this))},0)}TaskReady(){this.current+=1,this.current{s()},0)}function vr(s,e){new Dt().Run(s,e)}function Ar(s,e,t){new Dt().RunBatch(s,e,t)}function Gr(s){function e(t){t()&&setTimeout(()=>{e(t)},1)}e(s)}var Rr=null,Hi=new Set;function ki(s){Rr=s}function Vt(s){return Rr===null?null:Rr+"/"+s}function fe(s){return new Promise((e,t)=>{if(Rr===null){t();return}if(Hi.has(s)){e();return}let r=document.createElement("script");r.type="text/javascript",r.src=Vt(s),r.onload=()=>{Hi.add(s),e()},r.onerror=()=>{t()},document.head.appendChild(r)})}var Z={Url:1,File:2,Decompressed:3},L={Text:1,Binary:2};function X(s){let e=s.lastIndexOf("/");e===-1&&(e=s.lastIndexOf("\\"));let t=s;e!==-1&&(t=s.substring(e+1));let r=t.indexOf("?");return r!==-1&&(t=t.substring(0,r)),decodeURI(t)}function Ve(s){let e=X(s),t=e.lastIndexOf(".");return t===-1?"":e.substring(t+1).toLowerCase()}function Fr(s,e){return new Promise((t,r)=>{let i=new XMLHttpRequest;if(i.open("GET",s,!0),e===L.Text)i.responseType="text";else if(e===L.Binary)i.responseType="arraybuffer";else{r();return}i.onload=function(){i.status===200?t(i.response):r()},i.onerror=function(){r()},i.send(null)})}function Nr(s,e){return new Promise((t,r)=>{let i=new FileReader;i.onloadend=function(n){n.target.readyState===FileReader.DONE&&t(n.target.result)},i.onerror=function(){r()},e===L.Text?i.readAsText(s):e===L.Binary?i.readAsArrayBuffer(s):r()})}function Dr(s){for(let e=0;e1e-8}function Pr(s,e){return s-e>1e-8}function Tt(s,e){return e-s>-1e-8}function yt(s,e){return s-e>-1e-8}function V(s,e){return Math.abs(e-s)<1e-8}function Xi(s,e,t){return Math.abs(e-s)1e-8}function He(s){return s<-1e-8}var S={X:1,Y:2,Z:3};var N=class{constructor(e,t){this.x=e,this.y=t}Clone(){return new N(this.x,this.y)}};function Ae(s,e){return V(s.x,e.x)&&V(s.y,e.y)}function Yi(s,e){return new N(s.x+e.x,s.y+e.y)}function Ot(s,e){return new N(s.x-e.x,s.y-e.y)}function Bt(s,e){return Math.sqrt((s.x-e.x)*(s.x-e.x)+(s.y-e.y)*(s.y-e.y))}var R=class{constructor(e,t,r){this.r=e,this.g=t,this.b=r}Set(e,t,r){this.r=e,this.g=t,this.b=r}Clone(){return new R(this.r,this.g,this.b)}};function de(s){return parseInt(Math.round(s*255),10)}function ge(s,e,t){return new R(de(s),de(e),de(t))}function Oe(s){return s<.04045?s*.0773993808:Math.pow(s*.9478672986+.0521327014,2.4)}function ot(s){return s<.0031308?s*12.92:1.055*Math.pow(s,.41666)-.055}function Y(s){let e=parseInt(s,10).toString(16);for(;e.length<2;)e="0"+e;return e}function Ke(s){let e=Y(s.r),t=Y(s.g),r=Y(s.b);return e+t+r}function Ji(s){if(s.length!==6)return null;let e=parseInt(s.substring(0,2),16),t=parseInt(s.substring(2,4),16),r=parseInt(s.substring(4,6),16);return new R(e,t,r)}function Vr(s){return new R(s[0],s[1],s[2])}function ke(s,e){return s.r===e.r&&s.g===e.g&&s.b===e.b}var Ce=class{constructor(){this.name=null,this.url=null,this.buffer=null,this.offset=new N(0,0),this.scale=new N(1,1),this.rotation=0}IsValid(){return this.name!==null&&this.url!==null&&this.buffer!==null}HasTransformation(){return!Ae(this.offset,new N(0,0))||!Ae(this.scale,new N(1,1))||!V(this.rotation,0)}IsEqual(e){return!(this.name!==e.name||this.url!==e.url||!Ae(this.offset,e.offset)||!Ae(this.scale,e.scale)||!V(this.rotation,e.rotation))}};function Ze(s,e){return s===null&&e===null?!0:s===null||e===null?!1:s.IsEqual(e)}var ee={Phong:1,Physical:2},Or=class{constructor(e){this.type=e,this.isDefault=!1,this.name="",this.color=new R(0,0,0),this.vertexColors=!1}IsEqual(e){return!(this.type!==e.type||this.isDefault!==e.isDefault||this.name!==e.name||!ke(this.color,e.color)||this.vertexColors!==e.vertexColors)}},Lt=class extends Or{constructor(e){super(e);this.emissive=new R(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)||!ke(this.emissive,e.emissive)||!V(this.opacity,e.opacity)||this.transparent!==e.transparent||!Ze(this.diffuseMap,e.diffuseMap)||!Ze(this.bumpMap,e.bumpMap)||!Ze(this.normalMap,e.normalMap)||!Ze(this.emissiveMap,e.emissiveMap)||!V(this.alphaTest,e.alphaTest)||this.multiplyDiffuseMap!==e.multiplyDiffuseMap)}EnumerateTextureMaps(e){this.diffuseMap!==null&&e(this.diffuseMap),this.bumpMap!==null&&e(this.bumpMap),this.normalMap!==null&&e(this.normalMap),this.emissiveMap!==null&&e(this.emissiveMap)}},j=class extends Lt{constructor(){super(ee.Phong);this.ambient=new R(0,0,0),this.specular=new R(0,0,0),this.shininess=0,this.specularMap=null}IsEqual(e){return!(!super.IsEqual(e)||!ke(this.ambient,e.ambient)||!ke(this.specular,e.specular)||!V(this.shininess,e.shininess)||!Ze(this.specularMap,e.specularMap))}EnumerateTextureMaps(e){super.EnumerateTextureMaps(e),this.specularMap!==null&&e(this.specularMap)}},We=class extends Lt{constructor(){super(ee.Physical);this.metalness=0,this.roughness=1,this.metalnessMap=null}IsEqual(e){return!(!super.IsEqual(e)||!V(this.metalness,e.metalness)||!V(this.roughness,e.roughness)||!Ze(this.metalnessMap,e.metalnessMap))}EnumerateTextureMaps(e){super.EnumerateTextureMaps(e),this.metalnessMap!==null&&e(this.metalnessMap)}};function Ki(s,e){return!(s.name!==e.name||s.url!==e.url||!Ae(s.offset,e.offset)||!Ae(s.scale,e.scale)||!V(s.rotation,e.rotation))}var y=class{constructor(e,t,r){this.x=e,this.y=t,this.z=r}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 r=e.Clone().Normalize();return this.x+=r.x*t,this.y+=r.y*t,this.z+=r.z*t,this}Rotate(e,t,r){let i=e.Clone().Normalize(),n=i.x,o=i.y,l=i.z,a=this.x-r.x,u=this.y-r.y,h=this.z-r.z,f=Math.sin(t),d=Math.cos(t);return this.x=-n*(-n*a-o*u-l*h)*(1-d)+a*d+(-l*u+o*h)*f,this.y=-o*(-n*a-o*u-l*h)*(1-d)+u*d+(l*a-n*h)*f,this.z=-l*(-n*a-o*u-l*h)*(1-d)+h*d+(-o*a+n*u)*f,this.x+=r.x,this.y+=r.y,this.z+=r.z,this}Clone(){return new y(this.x,this.y,this.z)}};function Te(s,e){return V(s.x,e.x)&&V(s.y,e.y)&&V(s.z,e.z)}function Br(s,e){return new y(s.x+e.x,s.y+e.y,s.z+e.z)}function te(s,e){return new y(s.x-e.x,s.y-e.y,s.z-e.z)}function ye(s,e){return Math.sqrt((s.x-e.x)*(s.x-e.x)+(s.y-e.y)*(s.y-e.y)+(s.z-e.z)*(s.z-e.z))}function Ut(s,e){return s.x*e.x+s.y*e.y+s.z*e.z}function Lr(s,e){let t=s.Clone().Normalize(),r=e.Clone().Normalize();if(Te(t,r))return 0;let i=Ut(t,r);return Math.acos(i)}function Ge(s,e){let t=new y(0,0,0);return t.x=s.y*e.z-s.z*e.y,t.y=s.z*e.x-s.x*e.z,t.z=s.x*e.y-s.y*e.x,t}function It(s,e,t){return Math.sqrt(s*s+e*e+t*t)}function Re(s){return new y(s[0],s[1],s[2])}var Ur=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 r=0;r0,M=m.TextureUVCount()>0,T=m.GetVertex(x.vertex),E=m.GetNormal(x.normal),w=g.vertices.length/3;g.indices.push(w),g.vertices.push(T.x,T.y,T.z);let I=f(m,x.color,C);I!==null&&g.colors.push(I.r/255,I.g/255,I.b/255),g.normals.push(E.x,E.y,E.z);let v=d(m,x.uv,M);return v!==null&&g.uvs.push(v.x,v.y),{index:w,color:I,normal:E,uv:v}}function p(m,x,g){function C(E,w,I){if(I===null&&w===null)return!0;let v=f(E,w,!0);return ke(I,v)}function M(E,w,I){let v=E.GetNormal(w);return Te(I,v)}function T(E,w,I){if(I===null&&w===null)return!0;let v=d(E,w,!0);return Ae(I,v)}for(let E=0;E{let u=s.GetTriangle(l),h=s.GetTriangle(a);return u.mat-h.mat});let n=null,o=null;for(let l=0;l{r(i)})}ExportContent(e,t,r,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 _t=class extends le{constructor(){super();this.rhino=null}CanExport(e,t){return e===L.Binary&&t==="3dm"}ExportContent(e,t,r,i){this.rhino===null?fe("loaders/rhino3dm.min.js").then(()=>{rhino3dm().then(n=>{this.rhino=n,this.ExportRhinoContent(e,r,i)})}).catch(()=>{i()}):this.ExportRhinoContent(e,r,i)}ExportRhinoContent(e,t,r){function i(u){return{r:u.r,g:u.g,b:u.b,a:255}}let n=new q("model.3dm");t.push(n);let o=new this.rhino.File3dm;e.EnumerateTransformedMeshes(u=>{let h=Mt(u);for(let f=0;f=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 Ht=class extends le{constructor(){super();this.components={index:{type:5125,size:4},number:{type:5126,size:4}}}CanExport(e,t){return e===L.Text&&t==="gltf"||e===L.Binary&&t==="glb"}ExportContent(e,t,r,i){t===L.Text?this.ExportAsciiContent(e,r):t===L.Binary&&this.ExportBinaryContent(e,r),i()}ExportAsciiContent(e,t){let r=new q("model.gltf"),i=new q("model.bin");t.push(r),t.push(i);let n=this.GetMeshData(e),o=this.GetMainBuffer(n),l=this.GetMainJson(n);l.buffers.push({uri:i.GetName(),byteLength:o.byteLength});let a=new Map;this.ExportMaterials(e,l,u=>{let h=X(u.name);if(a.has(h))return a.get(h);{let f=new q(h);f.SetBufferContent(u.buffer),t.push(f);let d=l.textures.length;return a.set(h,d),l.images.push({uri:h}),l.textures.push({source:d}),d}}),r.SetTextContent(JSON.stringify(l,null,4)),i.SetBufferContent(o)}ExportBinaryContent(e,t){function r(T){let E=T%4;return E===0?T:T+(4-E)}function i(T,E,w){for(let I=0;I{let E=X(T.name),w=Ve(T.name);if(f.has(E))return f.get(E);{let I=a.bufferViews.length,v=a.textures.length;f.set(E,v);let b=T.buffer;return u.push(b),a.bufferViews.push({buffer:0,byteOffset:h,byteLength:b.byteLength}),h+=b.byteLength,a.images.push({bufferView:I,mimeType:"image/"+w}),a.textures.push({source:v}),v}});let d=l.byteLength;for(let T=0;T{let i=Mt(r);t.push({name:r.GetName(),buffer:i,offsets:[],sizes:[]})}),t}GetMainBuffer(e){let t=0;for(let i=0;i0&&(c=h.AddBufferView(u.colors.length*this.components.number.size));let p=h.AddBufferView(u.normals.length*this.components.number.size),m=null;u.uvs.length>0&&(m=h.AddBufferView(u.uvs.length*this.components.number.size));let x={attributes:{},mode:4,material:u.material},g=u.GetBounds();r.accessors.push({bufferView:f,byteOffset:0,componentType:this.components.index.type,count:u.indices.length,type:"SCALAR"}),x.indices=r.accessors.length-1,r.accessors.push({bufferView:d,byteOffset:0,componentType:this.components.number.type,count:u.vertices.length/3,min:g.min,max:g.max,type:"VEC3"}),x.attributes.POSITION=r.accessors.length-1,c!==null&&(r.accessors.push({bufferView:c,byteOffset:0,componentType:this.components.number.type,count:u.colors.length/3,type:"VEC3"}),x.attributes.COLOR_0=r.accessors.length-1),r.accessors.push({bufferView:p,byteOffset:0,componentType:this.components.number.type,count:u.normals.length/3,type:"VEC3"}),x.attributes.NORMAL=r.accessors.length-1,m!==null&&(r.accessors.push({bufferView:m,byteOffset:0,componentType:this.components.number.type,count:u.uvs.length/2,type:"VEC2"}),x.attributes.TEXCOORD_0=r.accessors.length-1),o.primitives.push(x)}r.meshes.push(o)}return r}ExportMaterials(e,t,r){function i(n,o,l,a){function u(x,g){return[Oe(x.r/255),Oe(x.g/255),Oe(x.b/255),g]}function h(x){return[Oe(x.r/255),Oe(x.g/255),Oe(x.b/255)]}function f(x,g,C){if(g===null||!g.IsValid())return null;x.images===void 0&&(x.images=[]),x.textures===void 0&&(x.textures=[]);let T={index:C(g)};if(g.HasTransformation()){let E="KHR_texture_transform";x.extensionsUsed===void 0&&(x.extensionsUsed=[]),x.extensionsUsed.indexOf(E)===-1&&x.extensionsUsed.push(E),T.extensions={KHR_texture_transform:{offset:[g.offset.x,-g.offset.y],scale:[g.scale.x,g.scale.y],rotation:-g.rotation}}}return T}let d={name:n.GetExportedMaterialName(l.name),pbrMetallicRoughness:{baseColorFactor:u(l.color,l.opacity)},emissiveFactor:h(l.emissive),doubleSided:!0,alphaMode:"OPAQUE"};l.transparent&&(d.alphaMode="BLEND");let c=f(o,l.diffuseMap,a);if(c!==null&&(l.multiplyDiffuseMap||(d.pbrMetallicRoughness.baseColorFactor=u(new R(255,255,255),l.opacity)),d.pbrMetallicRoughness.baseColorTexture=c),l.type===ee.Physical){let x=f(o,l.metalnessMap,a);x!==null?d.pbrMetallicRoughness.metallicRoughnessTexture=x:(d.pbrMetallicRoughness.metallicFactor=l.metalness,d.pbrMetallicRoughness.roughnessFactor=l.roughness)}let p=f(o,l.normalMap,a);p!==null&&(d.normalTexture=p);let m=f(o,l.emissiveMap,a);m!==null&&(d.emissiveTexture=m),o.materials.push(d)}for(let n=0;n0){let C=Math.sqrt(g+1)*2;x=new oe((p-d)/C,(u-c)/C,(h-a)/C,.25*C)}else if(l>f&&l>m){let C=Math.sqrt(1+l-f-m)*2;x=new oe(.25*C,(a+h)/C,(u+c)/C,(p-d)/C)}else if(f>m){let C=Math.sqrt(1+f-l-m)*2;x=new oe((a+h)/C,.25*C,(d+p)/C,(u-c)/C)}else{let C=Math.sqrt(1+m-l-f)*2;x=new oe((u+c)/C,(d+p)/C,.25*C,(h-a)/C)}return{translation:e,rotation:x,scale:o}}Determinant(){let e=this.matrix[0],t=this.matrix[1],r=this.matrix[2],i=this.matrix[3],n=this.matrix[4],o=this.matrix[5],l=this.matrix[6],a=this.matrix[7],u=this.matrix[8],h=this.matrix[9],f=this.matrix[10],d=this.matrix[11],c=this.matrix[12],p=this.matrix[13],m=this.matrix[14],x=this.matrix[15],g=e*o-t*n,C=e*l-r*n,M=e*a-i*n,T=t*l-r*o,E=t*a-i*o,w=r*a-i*l,I=u*p-h*c,v=u*m-f*c,b=u*x-d*c,G=h*m-f*p,B=h*x-d*p,F=f*x-d*m;return g*F-C*B+M*G+T*b-E*v+w*I}Invert(){let e=this.matrix[0],t=this.matrix[1],r=this.matrix[2],i=this.matrix[3],n=this.matrix[4],o=this.matrix[5],l=this.matrix[6],a=this.matrix[7],u=this.matrix[8],h=this.matrix[9],f=this.matrix[10],d=this.matrix[11],c=this.matrix[12],p=this.matrix[13],m=this.matrix[14],x=this.matrix[15],g=e*o-t*n,C=e*l-r*n,M=e*a-i*n,T=t*l-r*o,E=t*a-i*o,w=r*a-i*l,I=u*p-h*c,v=u*m-f*c,b=u*x-d*c,G=h*m-f*p,B=h*x-d*p,F=f*x-d*m,D=g*F-C*B+M*G+T*b-E*v+w*I;if(V(D,0))return null;let P=[(o*F-l*B+a*G)/D,(r*B-t*F-i*G)/D,(p*w-m*E+x*T)/D,(f*E-h*w-d*T)/D,(l*b-n*F-a*v)/D,(e*F-r*b+i*v)/D,(m*M-c*w-x*C)/D,(u*w-f*M+d*C)/D,(n*B-o*b+a*I)/D,(t*b-e*B-i*I)/D,(c*E-p*M+x*g)/D,(h*M-u*E-d*g)/D,(o*v-n*G-l*I)/D,(e*G-t*v+r*I)/D,(p*C-c*T-m*g)/D,(u*T-h*C+f*g)/D];return new O(P)}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 O(e)}InvertTranspose(){let e=this.Invert();return e===null?null:e.Transpose()}MultiplyVector(e){let t=e.x,r=e.y,i=e.z,n=e.w,o=this.matrix[0],l=this.matrix[1],a=this.matrix[2],u=this.matrix[3],h=this.matrix[4],f=this.matrix[5],d=this.matrix[6],c=this.matrix[7],p=this.matrix[8],m=this.matrix[9],x=this.matrix[10],g=this.matrix[11],C=this.matrix[12],M=this.matrix[13],T=this.matrix[14],E=this.matrix[15];return new Se(t*o+r*h+i*p+n*C,t*l+r*f+i*m+n*M,t*a+r*d+i*x+n*T,t*u+r*c+i*g+n*E)}MultiplyMatrix(e){let t=this.matrix[0],r=this.matrix[1],i=this.matrix[2],n=this.matrix[3],o=this.matrix[4],l=this.matrix[5],a=this.matrix[6],u=this.matrix[7],h=this.matrix[8],f=this.matrix[9],d=this.matrix[10],c=this.matrix[11],p=this.matrix[12],m=this.matrix[13],x=this.matrix[14],g=this.matrix[15],C=e.matrix[0],M=e.matrix[1],T=e.matrix[2],E=e.matrix[3],w=e.matrix[4],I=e.matrix[5],v=e.matrix[6],b=e.matrix[7],G=e.matrix[8],B=e.matrix[9],F=e.matrix[10],D=e.matrix[11],P=e.matrix[12],ne=e.matrix[13],_=e.matrix[14],xe=e.matrix[15],Pe=[t*C+r*w+i*G+n*P,t*M+r*I+i*B+n*ne,t*T+r*v+i*F+n*_,t*E+r*b+i*D+n*xe,o*C+l*w+a*G+u*P,o*M+l*I+a*B+u*ne,o*T+l*v+a*F+u*_,o*E+l*b+a*D+u*xe,h*C+f*w+d*G+c*P,h*M+f*I+d*B+c*ne,h*T+f*v+d*F+c*_,h*E+f*b+d*D+c*xe,p*C+m*w+x*G+g*P,p*M+m*I+x*B+g*ne,p*T+m*v+x*F+g*_,p*E+m*b+x*D+g*xe];return new O(Pe)}};function kr(s,e){let t=s.Get(),r=e.Get();for(let i=0;i<16;i++)if(!V(t[i],r[i]))return!1;return!0}var H=class{constructor(e){e!=null?this.matrix=e:(this.matrix=new O,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 Se(e.x,e.y,e.z,1),r=this.matrix.MultiplyVector(t);return new y(r.x,r.y,r.z)}Clone(){let e=this.matrix.Clone();return new H(e)}};function tn(s,e){return kr(s.GetMatrix(),e.GetMatrix())}var Le={Empty:0,TriangleMesh:1};function et(s){return s.TriangleCount()>0?Le.TriangleMesh:Le.Empty}function at(s,e,t){let r=te(e,s),i=te(t,s),n=Ge(r,i);return n.Normalize(),n}function Ue(s,e){if(!e.IsIdentity()){for(let t=0;t0){let t=e.GetMatrix().InvertTranspose();if(t!==null){let r=new H(t);for(let i=0;i!0,gt(e,this)}},kt=class{constructor(e,t){this.model=e,this.settings=t||new jr}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}MeshInstanceCount(){let e=0;return this.EnumerateMeshInstances(t=>{e+=1}),e}EnumerateMeshInstances(e){this.model.EnumerateMeshInstances(t=>{this.settings.isMeshVisible(t.GetId())&&e(t)})}EnumerateTransformedMeshes(e){this.EnumerateMeshInstances(t=>{let r=t.GetTransformation();this.settings.transformation.IsIdentity()||r.Append(this.settings.transformation);let n=t.GetMesh().Clone();r.IsIdentity()||Ue(n,r),e(n)})}EnumerateVerticesAndTriangles(e){let t=[];this.EnumerateTransformedMeshes(i=>{t.push(i)});for(let i of t)i.EnumerateVertices(n=>{e.onVertex(n.x,n.y,n.z)});let r=0;for(let i of t)i.EnumerateTriangleVertexIndices((n,o,l)=>{e.onTriangle(n+r,o+r,l+r)}),r+=i.VertexCount()}EnumerateTrianglesWithNormals(e){this.EnumerateTransformedMeshes(t=>{t.EnumerateTriangleVertices((r,i,n)=>{let o=at(r,i,n);e(r,i,n,o)})})}};var Ie=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;eT.GetName()===C)===-1){let T=new q(C);T.SetBufferContent(x.buffer),g.push(T)}}let o=new q("model.mtl"),l=new q("model.obj");r.push(o),r.push(l);let a=new Ie;a.WriteLine(this.GetHeaderText());for(let p=0;p{u.WriteArrayLine(["g",this.GetExportedMeshName(p.GetName())]);for(let m=0;m{i.WriteArrayLine(["facet","normal",a.x,a.y,a.z]),i.Indent(1),i.WriteLine("outer loop"),i.Indent(1),i.WriteArrayLine(["vertex",n.x,n.y,n.z]),i.WriteArrayLine(["vertex",o.x,o.y,o.z]),i.WriteArrayLine(["vertex",l.x,l.y,l.z]),i.Indent(-1),i.WriteLine("endloop"),i.Indent(-1),i.WriteLine("endfacet")}),i.WriteLine("endsolid Model"),r.SetTextContent(i.GetText())}ExportBinary(e,t){let r=new q("model.stl");t.push(r);let i=e.TriangleCount(),n=80,o=n+4+i*50,l=new Be(o,!0);for(let a=0;a{l.WriteFloat32(f.x),l.WriteFloat32(f.y),l.WriteFloat32(f.z),l.WriteFloat32(a.x),l.WriteFloat32(a.y),l.WriteFloat32(a.z),l.WriteFloat32(u.x),l.WriteFloat32(u.y),l.WriteFloat32(u.z),l.WriteFloat32(h.x),l.WriteFloat32(h.y),l.WriteFloat32(h.z),l.WriteUnsignedInteger16(0)}),r.SetBufferContent(l.GetBuffer())}};var Ai=class{constructor(){this.exporters=[new Wt,new Xt,new qt,new jt,new Ht,new _t]}AddExporter(e){this.exporters.push(e)}Export(e,t,r,i,n){let o=null;for(let a=0;a{a.length===0?n.onError():n.onSuccess(a)})}};var bt=class{constructor(e,t){this.min=e,this.max=t}GetMin(){return this.min}GetMax(){return this.max}GetCenter(){return new y((this.min.x+this.max.x)/2,(this.min.y+this.max.y)/2,(this.min.z+this.max.z)/2)}},Yt=class{constructor(){this.box=new bt(new y(1/0,1/0,1/0),new y(-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 wt=class{constructor(e,t){this.boundingBox=e,this.level=t,this.pointItems=[],this.childNodes=[]}AddPoint(e,t,r){let i=this.FindNodeForPoint(e);if(i===null||i.FindPointDirectly(e)!==null)return!1;if(i.pointItems.length=r.maxTreeDepth)return i.AddPointDirectly(e,t),!0;{i.CreateChildNodes();let n=i.pointItems;i.pointItems=[];for(let o=0;o{this.GetFileContent(this.files[t],r)},onReady:e})}ContainsFileByPath(e){return this.FindFileByPath(e)!==null}FindFileByPath(e){let t=X(e).toLowerCase();for(let r=0;r{e.SetContent(i)}).catch(()=>{}).finally(()=>{t()})}};var Xr=class{constructor(){this.edges=[],this.triangles=[]}},Yr=class{constructor(e,t){this.vertex1=e,this.vertex2=t,this.triangles=[]}},Jr=class{constructor(e,t){this.edge=e,this.reversed=t}},Kr=class{constructor(){this.triEdge1=null,this.triEdge2=null,this.triEdge3=null}},Kt=class{constructor(){this.vertices=[],this.edges=[],this.triangleEdges=[],this.triangles=[],this.edgeStartToEndVertexMap=new Map}AddVertex(){return this.vertices.push(new Xr),this.vertices.length-1}AddTriangle(e,t,r){function i(u,h,f){u[h].triangles.push(f)}function n(u,h,f,d){let c=u[f],p=h[d];c.edges.push(p.edge)}function o(u,h,f,d){let c=h[f];u[c.edge].triangles.push(d)}let l=this.triangles.length,a=new Kr;a.triEdge1=this.AddTriangleEdge(e,t),a.triEdge2=this.AddTriangleEdge(t,r),a.triEdge3=this.AddTriangleEdge(r,e),i(this.vertices,e,l),i(this.vertices,t,l),i(this.vertices,r,l),n(this.vertices,this.triangleEdges,e,a.triEdge1),n(this.vertices,this.triangleEdges,t,a.triEdge2),n(this.vertices,this.triangleEdges,r,a.triEdge3),o(this.edges,this.triangleEdges,a.triEdge1,l),o(this.edges,this.triangleEdges,a.triEdge2,l),o(this.edges,this.triangleEdges,a.triEdge3,l),this.triangles.push(a)}AddTriangleEdge(e,t){let r=e,i=t,n=!1;t{et(t)!==Le.Empty&&(e=!1)}),e}function Gi(s){let e=new Yt;return s.EnumerateVertices(t=>{e.AddPoint(t)}),e.GetBox()}function Ri(s){function e(n,o,l){let a=o.FindPoint(n);return a===null&&(a=l.AddVertex(),o.AddPoint(n,a)),a}let t=Gi(s),r=new Jt(t),i=new Kt;return s.EnumerateTriangleVertices((n,o,l)=>{let a=e(n,r,i),u=e(o,r,i),h=e(l,r,i);i.AddTriangle(a,u,h)}),i}function on(s){function e(r,i,n){let o=r.triangles[i],l=r.triangleEdges[o.triEdge1],a=r.triangleEdges[o.triEdge2],u=r.triangleEdges[o.triEdge3];return l.edge===n?l.reversed:a.edge===n?a.reversed:u.edge===n?u.reversed:null}let t=Ri(s);for(let r=0;r=t?ae.Phong:ae.Physical}function Rt(s){return ge(s.r,s.g,s.b)}function ce(s){return new THREE.Color(s.r/255,s.g/255,s.b/255)}function qe(s,e){let t=new k,r=s.attributes.position.array,i=s.attributes.position.itemSize||3;for(let u=0;u{let i=t.TransformCoord3D(r);e(i)})}EnumerateTriangleVertexIndices(e){this.mesh.EnumerateTriangleVertexIndices(e)}EnumerateTriangleVertices(e){let t=this.node.GetWorldTransformation();t.IsIdentity()?this.mesh.EnumerateTriangleVertices(e):this.mesh.EnumerateTriangleVertices((r,i,n)=>{let o=t.TransformCoord3D(r),l=t.TransformCoord3D(i),a=t.TransformCoord3D(n);e(o,l,a)})}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 Ue(t,e),t}};var an=class{constructor(){this.nextId=0}GenerateId(){let e=this.nextId;return this.nextId+=1,e}},Me={GroupNode:0,MeshNode:1},ue=class{constructor(){this.type=Me.GroupNode,this.name="",this.parent=null,this.transformation=new H,this.childNodes=[],this.meshIndices=[],this.idGenerator=new an,this.id=this.idGenerator.GenerateId()}IsEmpty(){return this.childNodes.length===0&&this.meshIndices.length===0}GetType(){return this.type}SetType(e){this.type=e}GetId(){return this.id}GetName(){return this.name}SetName(e){this.name=e}HasParent(){return this.parent!==null}GetParent(){return this.parent}GetTransformation(){return this.transformation}GetWorldTransformation(){let e=this.transformation.Clone(),t=this.parent;for(;t!==null;)e.Append(t.transformation),t=t.parent;return e}SetTransformation(e){this.transformation=e}AddChildNode(e){return e.parent=this,e.idGenerator=this.idGenerator,e.id=e.idGenerator.GenerateId(),this.childNodes.push(e),this.childNodes.length-1}RemoveChildNode(e){e.parent=null;let t=this.childNodes.indexOf(e);this.childNodes.splice(t,1)}GetChildNodes(){return this.childNodes}ChildNodeCount(){return this.childNodes.length}GetChildNode(e){return this.childNodes[e]}AddMeshIndex(e){return this.meshIndices.push(e),this.meshIndices.length-1}MeshIndexCount(){return this.meshIndices.length}GetMeshIndex(e){return this.meshIndices[e]}GetMeshIndices(){return this.meshIndices}Enumerate(e){e(this);for(let t of this.childNodes)t.Enumerate(e)}EnumerateChildren(e){for(let t of this.childNodes)e(t),t.EnumerateChildren(e)}EnumerateMeshIndices(e){for(let t of this.meshIndices)e(t);for(let t of this.childNodes)t.EnumerateMeshIndices(e)}};var Zt=class extends je{constructor(){super();this.root=new ue,this.materials=[],this.meshes=[]}GetRootNode(){return this.root}MaterialCount(){return this.materials.length}MeshCount(){return this.meshes.length}MeshInstanceCount(){let e=0;return this.root.Enumerate(t=>{e+=t.MeshIndexCount()}),e}VertexCount(){let e=0;return this.EnumerateMeshInstances(t=>{e+=t.VertexCount()}),e}VertexColorCount(){let e=0;return this.EnumerateMeshInstances(t=>{e+=t.VertexColorCount()}),e}NormalCount(){let e=0;return this.EnumerateMeshInstances(t=>{e+=t.NormalCount()}),e}TextureUVCount(){let e=0;return this.EnumerateMeshInstances(t=>{e+=t.TextureUVCount()}),e}TriangleCount(){let e=0;return this.EnumerateMeshInstances(t=>{e+=t.TriangleCount()}),e}AddMaterial(e){return this.materials.push(e),this.materials.length-1}GetMaterial(e){return this.materials[e]}AddMesh(e){return this.meshes.push(e),this.meshes.length-1}AddMeshToRootNode(e){let t=this.AddMesh(e);return this.root.AddMeshIndex(t),t}RemoveMesh(e){this.meshes.splice(e,1),this.root.Enumerate(t=>{for(let r=0;re&&(t.meshIndices[r]-=1)})}GetMesh(e){return this.meshes[e]}GetMeshInstance(e){let t=null;if(this.root.Enumerate(o=>{o.GetId()===e.nodeId&&(t=o)}),t===null||t.GetMeshIndices().indexOf(e.meshIndex)===-1)return null;let i=this.GetMesh(e.meshIndex),n=new tt(t.GetId(),e.meshIndex);return new Ft(n,t,i)}EnumerateMeshes(e){for(let t of this.meshes)e(t)}EnumerateMeshInstances(e){this.root.Enumerate(t=>{for(let r of t.GetMeshIndices()){let i=new tt(t.GetId(),r),n=this.GetMesh(r),o=new Ft(i,t,n);e(o)}})}EnumerateTransformedMeshes(e){this.EnumerateMeshInstances(t=>{let r=t.GetTransformedMesh();e(r)})}EnumerateVertices(e){this.EnumerateMeshInstances(t=>{t.EnumerateVertices(e)})}EnumerateTriangleVertexIndices(e){this.EnumerateMeshInstances(t=>{t.EnumerateTriangleVertexIndices(e)})}EnumerateTriangleVertices(e){this.EnumerateMeshInstances(t=>{t.EnumerateTriangleVertices(e)})}};var un=class{constructor(e){this.params={getDefaultMaterialColor:()=>new R(0,0,0)},gt(e,this.params),this.defaultMaterialIndex=null}Finalize(e){this.Reset(),this.FinalizeMeshes(e),this.FinalizeMaterials(e),this.FinalizeNodes(e)}FinalizeMaterials(e){if(!(e.VertexColorCount()>0))return;let r=new Map;for(let i=0;i{i.IsEmpty()&&r.push(i)});for(let i=0;i=o)}function i(n,o){function l(a,u,h){return!(!r(h.v0,u.VertexCount())||!r(h.v1,u.VertexCount())||!r(h.v2,u.VertexCount())||h.HasVertexColors()&&(!r(h.c0,u.VertexColorCount())||!r(h.c1,u.VertexColorCount())||!r(h.c2,u.VertexColorCount()))||!r(h.n0,u.NormalCount())||!r(h.n1,u.NormalCount())||!r(h.n2,u.NormalCount())||h.HasTextureUVs()&&(!r(h.u0,u.TextureUVCount())||!r(h.u1,u.TextureUVCount())||!r(h.u2,u.TextureUVCount()))||!r(h.mat,a.MaterialCount())||!t(h.curve))}for(let a=0;a{this.CreateResult(i)})}Clear(){this.name=null,this.extension=null,this.callbacks=null,this.model=null,this.error=null,this.message=null,this.ClearContent()}CreateResult(e){if(this.error){e.onError(),e.onComplete();return}if(Gt(this.model)){this.SetError("The model doesn't contain any meshes."),e.onError(),e.onComplete();return}ei(this.model,{getDefaultMaterialColor:this.callbacks.getDefaultMaterialColor}),e.onSuccess(),e.onComplete()}CanImportExtension(e){return!1}GetUpDirection(){return S.Z}ClearContent(){}ResetContent(){}ImportContent(e,t){}GetModel(){return this.model}SetError(e){this.error=!0,e!=null&&(this.message=e)}WasError(){return this.error}GetErrorMessage(){return this.message}};function ze(s,e,t){let r=s.substring(e),i=r.indexOf(t);return i!==-1&&(r=r.substring(0,i)),r.trim()}function Fe(s,e){if(e!==null){let t=s.indexOf(e);t!==-1&&(s=s.substring(0,t).trim())}return s.split(/\s+/u)}function ve(s,e){function t(n,o){let l=n.trim();l.length>0&&o(l)}let r=0,i=s.indexOf(` `,r);for(;i!==-1;)t(s.substring(r,i),e),r=i+1,i=s.indexOf(` `,r);t(s.substring(r),e)}function Fi(s){return(s&s-1)===0}function fn(s){if(Fi(s))return s;let e=Math.pow(2,Math.ceil(Math.log(s)/Math.log(2)));return parseInt(e,10)}function ie(s){s.transparent=!1,Ct(s.opacity,1)&&(s.transparent=!0)}var Qt=class{constructor(e){this.createMaterialFunc=e,this.colorToMaterialIndex=new Map}GetMaterialIndex(e){let t=Ke(e);if(this.colorToMaterialIndex.has(t))return this.colorToMaterialIndex.get(t);{let r=this.createMaterialFunc(e);return this.colorToMaterialIndex.set(t,r),r}}};var $t=class extends z{constructor(){super();this.rhino=null}CanImportExtension(e){return e==="3dm"}GetUpDirection(){return S.Z}ClearContent(){this.instanceIdToObject=null,this.instanceIdToDefinition=null}ResetContent(){this.instanceIdToObject=new Map,this.instanceIdToDefinition=new Map}ImportContent(e,t){this.rhino===null?fe("loaders/rhino3dm.min.js").then(()=>{rhino3dm().then(r=>{this.rhino=r,this.ImportRhinoContent(e),t()})}).catch(()=>{this.SetError("Failed to load rhino3dm."),t()}):(this.ImportRhinoContent(e),t())}ImportRhinoContent(e){let t=this.rhino.File3dm.fromByteArray(e);if(t===null){this.SetError("Failed to read Rhino file.");return}this.ImportRhinoDocument(t),Gt(this.model)&&this.SetError("The model doesn't contain any 3D meshes. Try to save the model while you are in shaded view in Rhino.")}ImportRhinoDocument(e){this.InitRhinoInstances(e),this.ImportRhinoUserStrings(e),this.ImportRhinoGeometry(e)}InitRhinoInstances(e){let t=e.objects();for(let i=0;i0){let r=new me("Document user texts");for(let i=0;i0){let h=new me("User texts");for(let f=0;f=0;d--){let m=i[d].geometry().xform.toFloatArray(!1),x=new O(m);h=h.MultiplyMatrix(x)}let f=new H(h);Ue(a,f)}this.model.AddMeshToRootNode(a)}GetMaterialIndex(e,t,r){function i(a,u,h){let f=u.attributes();if(f.materialSource===a.ObjectMaterialSource.MaterialFromObject){let d=f.materialIndex;if(d>-1)return e.materials().get(d)}else if(f.materialSource===a.ObjectMaterialSource.MaterialFromLayer){let d=f.layerIndex;if(d>-1){let p=e.layers().get(d).renderMaterialIndex;if(p>-1)return e.materials().get(p)}}else if(f.materialSource===a.ObjectMaterialSource.MaterialFromParent&&h.length!==0)return i(a,h[0],[]);return null}function n(a,u){function h(x,g){x.Set(g.r,g.g,g.b)}function f(x){return x.r===0&&x.g===0&&x.b===0}function d(x){return x.r===255&&x.g===255&&x.b===255}let c=null,p=a.physicallyBased();p.supported?(c=new We,c.metalness=p.metallic?1:0,c.roughness=p.roughness):(c=new j,h(c.ambient,a.ambientColor),h(c.specular,a.specularColor)),c.name=a.name,h(c.color,a.diffuseColor),c.opacity=1-a.transparency,ie(c),f(c.color)&&!d(a.reflectionColor)&&h(c.color,a.reflectionColor),f(c.color)&&!d(a.transparentColor)&&h(c.color,a.transparentColor);let m=a.getBitmapTexture();if(m){let x=new Ce,g=X(m.fileName),C=u.getTextureBuffer(g);x.name=g,C!==null&&(x.url=C.url,x.buffer=C.buffer),c.diffuseMap=x}return c}function o(a,u,h){let f=n(u,h);for(let d=0;d=this.arrayBuffer.byteLength}ReadArrayBuffer(e){let t=new Uint8Array(this.arrayBuffer),r=new ArrayBuffer(e),i=new Uint8Array(r),n=t.subarray(this.position,this.position+e);return i.set(n,0),this.position+=e,r}ReadBoolean8(){let e=this.dataView.getInt8(this.position);return this.position=this.position+1,!!e}ReadCharacter8(){let e=this.dataView.getInt8(this.position);return this.position=this.position+1,e}ReadUnsignedCharacter8(){let e=this.dataView.getUint8(this.position);return this.position=this.position+1,e}ReadInteger16(){let e=this.dataView.getInt16(this.position,this.isLittleEndian);return this.position=this.position+2,e}ReadUnsignedInteger16(){let e=this.dataView.getUint16(this.position,this.isLittleEndian);return this.position=this.position+2,e}ReadInteger32(){let e=this.dataView.getInt32(this.position,this.isLittleEndian);return this.position=this.position+4,e}ReadUnsignedInteger32(){let e=this.dataView.getUint32(this.position,this.isLittleEndian);return this.position=this.position+4,e}ReadFloat32(){let e=this.dataView.getFloat32(this.position,this.isLittleEndian);return this.position=this.position+4,e}ReadDouble64(){let e=this.dataView.getFloat64(this.position,this.isLittleEndian);return this.position=this.position+8,e}};var A={MAIN3DS:19789,EDIT3DS:15677,EDIT_MATERIAL:45055,MAT_NAME:40960,MAT_AMBIENT:40976,MAT_DIFFUSE:40992,MAT_SPECULAR:41008,MAT_SHININESS:41024,MAT_SHININESS_STRENGTH:41025,MAT_TRANSPARENCY:41040,MAT_COLOR_F:16,MAT_COLOR:17,MAT_LIN_COLOR:18,MAT_LIN_COLOR_F:19,MAT_TEXMAP:41472,MAT_TEXMAP_NAME:41728,MAT_TEXMAP_UOFFSET:41816,MAT_TEXMAP_VOFFSET:41818,MAT_TEXMAP_USCALE:41812,MAT_TEXMAP_VSCALE:41814,MAT_TEXMAP_ROTATION:41820,PERCENTAGE:48,PERCENTAGE_F:49,EDIT_OBJECT:16384,OBJ_TRIMESH:16640,OBJ_LIGHT:17920,OBJ_CAMERA:18176,TRI_VERTEX:16656,TRI_TEXVERTEX:16704,TRI_FACE:16672,TRI_TRANSFORMATION:16736,TRI_MATERIAL:16688,TRI_SMOOTH:16720,KF3DS:45056,OBJECT_NODE:45058,OBJECT_HIERARCHY:45072,OBJECT_INSTANCE_NAME:45073,OBJECT_PIVOT:45075,OBJECT_POSITION:45088,OBJECT_ROTATION:45089,OBJECT_SCALE:45090,OBJECT_ID:45104},dn=class{constructor(){this.id=-1,this.name="",this.flags=-1,this.parentId=-1,this.instanceName="",this.pivot=[0,0,0],this.positions=[],this.rotations=[],this.scales=[]}},mn=class{constructor(){this.nodes=[],this.nodeIdToNode=new Map}IsEmpty(){return this.nodes.length===0}AddNode(e){this.nodes.push(e),this.nodeIdToNode.set(e.nodeId,e)}GetNodes(){return this.nodes}},er=class extends z{constructor(){super()}CanImportExtension(e){return e==="3ds"}GetUpDirection(){return S.Z}ClearContent(){this.materialNameToIndex=null,this.meshNameToIndex=null,this.nodeList=null}ResetContent(){this.materialNameToIndex=new Map,this.meshNameToIndex=new Map,this.nodeList=new mn}ImportContent(e,t){this.ProcessBinary(e),t()}ProcessBinary(e){let t=new pe(e,!0),r=t.GetByteLength();this.ReadChunks(t,r,(i,n)=>{i===A.MAIN3DS?this.ReadMainChunk(t,n):this.SkipChunk(t,n)})}ReadMainChunk(e,t){let r=this.GetChunkEnd(e,t);this.ReadChunks(e,r,(i,n)=>{i===A.EDIT3DS?this.ReadEditorChunk(e,n):i===A.KF3DS?this.ReadKeyFrameChunk(e,n):this.SkipChunk(e,n)}),this.BuildNodeHierarchy()}ReadEditorChunk(e,t){let r=this.GetChunkEnd(e,t);this.ReadChunks(e,r,(i,n)=>{i===A.EDIT_MATERIAL?this.ReadMaterialChunk(e,n):i===A.EDIT_OBJECT?this.ReadObjectChunk(e,n):this.SkipChunk(e,n)})}ReadMaterialChunk(e,t){let r=new j,i=this.GetChunkEnd(e,t),n=null,o=null;this.ReadChunks(e,i,(a,u)=>{a===A.MAT_NAME?r.name=this.ReadName(e):a===A.MAT_AMBIENT?r.ambient=this.ReadColorChunk(e,u):a===A.MAT_DIFFUSE?r.color=this.ReadColorChunk(e,u):a===A.MAT_SPECULAR?r.specular=this.ReadColorChunk(e,u):a===A.MAT_SHININESS?n=this.ReadPercentageChunk(e,u):a===A.MAT_SHININESS_STRENGTH?o=this.ReadPercentageChunk(e,u):a===A.MAT_TRANSPARENCY?(r.opacity=1-this.ReadPercentageChunk(e,u),ie(r)):a===A.MAT_TEXMAP?(r.diffuseMap=this.ReadTextureMapChunk(e,u),ie(r)):this.SkipChunk(e,u)}),n!==null&&o!==null&&(r.shininess=n*o/10);let l=this.model.AddMaterial(r);this.materialNameToIndex.set(r.name,l)}ReadTextureMapChunk(e,t){let r=new Ce,i=this.GetChunkEnd(e,t);return this.ReadChunks(e,i,(n,o)=>{if(n===A.MAT_TEXMAP_NAME){let l=this.ReadName(e),a=this.callbacks.getTextureBuffer(l);r.name=l,a!==null&&(r.url=a.url,r.buffer=a.buffer)}else n===A.MAT_TEXMAP_UOFFSET?r.offset.x=e.ReadFloat32():n===A.MAT_TEXMAP_VOFFSET?r.offset.y=e.ReadFloat32():n===A.MAT_TEXMAP_USCALE?r.scale.x=e.ReadFloat32():n===A.MAT_TEXMAP_VSCALE?r.scale.y=e.ReadFloat32():n===A.MAT_TEXMAP_ROTATION?r.rotation=e.ReadFloat32()*Je:this.SkipChunk(e,o)}),r}ReadColorChunk(e,t){let r=new R(0,0,0),i=this.GetChunkEnd(e,t),n=!1;return this.ReadChunks(e,i,(o,l)=>{o===A.MAT_COLOR?n||(r.r=e.ReadUnsignedCharacter8(),r.g=e.ReadUnsignedCharacter8(),r.b=e.ReadUnsignedCharacter8()):o===A.MAT_LIN_COLOR?(r.r=e.ReadUnsignedCharacter8(),r.g=e.ReadUnsignedCharacter8(),r.b=e.ReadUnsignedCharacter8(),n=!0):o===A.MAT_COLOR_F?n||(r.r=de(e.ReadFloat32()),r.g=de(e.ReadFloat32()),r.b=de(e.ReadFloat32())):o===A.MAT_LIN_COLOR_F?(r.r=de(e.ReadFloat32()),r.g=de(e.ReadFloat32()),r.b=de(e.ReadFloat32()),n=!0):this.SkipChunk(e,l)}),r}ReadPercentageChunk(e,t){let r=0,i=this.GetChunkEnd(e,t);return this.ReadChunks(e,i,(n,o)=>{n===A.PERCENTAGE?r=e.ReadUnsignedInteger16()/100:n===A.PERCENTAGE_F?r=e.ReadFloat32():this.SkipChunk(e,o)}),r}ReadObjectChunk(e,t){let r=this.GetChunkEnd(e,t),i=this.ReadName(e);this.ReadChunks(e,r,(n,o)=>{n===A.OBJ_TRIMESH?this.ReadMeshChunk(e,o,i):this.SkipChunk(e,o)})}ReadMeshChunk(e,t,r){function i(h,f){if(!f.IsValid())return;let d=f.Determinant(),c=He(d);c&&(f=new O().CreateScale(-1,1,1).MultiplyMatrix(f));let p=f.Invert();if(p===null)return;let m=new H(p);Ue(h,m),c&&Wr(h)}let n=new k;n.SetName(r);let o=this.GetChunkEnd(e,t),l=null;if(this.ReadChunks(e,o,(h,f)=>{h===A.TRI_VERTEX?this.ReadVerticesChunk(n,e):h===A.TRI_TEXVERTEX?this.ReadTextureVerticesChunk(n,e):h===A.TRI_FACE?this.ReadFacesChunk(n,e,f):h===A.TRI_TRANSFORMATION?l=this.ReadTransformationChunk(e):this.SkipChunk(e,f)}),n.VertexCount()===n.TextureUVCount())for(let h=0;h{o===A.TRI_MATERIAL?this.ReadFaceMaterialsChunk(e,t):o===A.TRI_SMOOTH?this.ReadFaceSmoothingGroupsChunk(e,n,t):this.SkipChunk(t,l)})}ReadFaceMaterialsChunk(e,t){let r=this.ReadName(t),i=this.materialNameToIndex.get(r),n=t.ReadUnsignedInteger16();for(let o=0;o{i===A.OBJECT_NODE?this.ReadObjectNodeChunk(e,n):this.SkipChunk(e,n)})}BuildNodeHierarchy(){function e(r,i){function n(u){return u.positions.length===0?[0,0,0]:u.positions[0]}function o(u){function h(d){let c=[0,0,0,1],p=Math.sqrt(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]);if(p>0){let m=d[3]*-.5,x=Math.sin(m)/p;c=[x*d[0],x*d[1],x*d[2],Math.cos(m)]}return c}if(u.rotations.length===0)return[0,0,0,1];let f=u.rotations[0];return h(f)}function l(u){return u.scales.length===0?[1,1,1]:u.scales[0]}let a=new O;if(a.ComposeTRS(Re(n(r)),$e(o(r)),Re(l(r))),i){let u=r.pivot;a=new O().CreateTranslation(-u[0],-u[1],-u[2]).MultiplyMatrix(a)}return new H(a)}let t=this.model.GetRootNode();if(this.nodeList.IsEmpty())for(let r=0;r0&&i.name!=="$$$DUMMY"&&(n.SetName(i.name),i.instanceName.length>0&&n.SetName(n.GetName()+" "+i.instanceName)),i.parentId===65535||!r.has(i.parentId)?t.AddChildNode(n):r.get(i.parentId).AddChildNode(n),r.set(i.id,n);let o=this.meshNameToIndex.has(i.name);n.SetTransformation(e(i,o)),o&&(n.SetType(Me.MeshNode),n.AddMeshIndex(this.meshNameToIndex.get(i.name)))}}}ReadObjectNodeChunk(e,t){function r(o,l,a){let u=[];l.Skip(10);let h=l.ReadInteger32();for(let f=0;f{o===A.OBJECT_HIERARCHY?(i.name=this.ReadName(e),i.flags=e.ReadUnsignedInteger32(),i.parentId=e.ReadUnsignedInteger16()):o===A.OBJECT_INSTANCE_NAME?i.instanceName=this.ReadName(e):o===A.OBJECT_PIVOT?i.pivot=this.ReadVector(e):o===A.OBJECT_POSITION?i.positions=r(this,e,A.OBJECT_POSITION):o===A.OBJECT_ROTATION?i.rotations=r(this,e,A.OBJECT_ROTATION):o===A.OBJECT_SCALE?i.scales=r(this,e,A.OBJECT_SCALE):o===A.OBJECT_ID?i.id=e.ReadUnsignedInteger16():this.SkipChunk(e,l)}),this.nodeList.AddNode(i)}ReadName(e){let t="",r=0,i=0;for(;i<64&&(r=e.ReadCharacter8(),r!==0);)t=t+String.fromCharCode(r),i=i+1;return t}ReadVector(e){return[e.ReadFloat32(),e.ReadFloat32(),e.ReadFloat32()]}ReadChunks(e,t,r){for(;e.GetPosition()<=t-6;){let i=e.ReadUnsignedInteger16(),n=e.ReadUnsignedInteger32();r(i,n)}}GetChunkEnd(e,t){return e.GetPosition()+t-6}SkipChunk(e,t){e.Skip(t-6)}};var Ee={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,UNSIGNED_INT:5125,FLOAT:5126},Ne={SCALAR:0,VEC2:1,VEC3:2,VEC4:3,MAT2:4,MAT3:5,MAT4:6},ut={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},Ni={GLTF_STRING:1179937895,JSON_CHUNK_TYPE:1313821514,BINARY_CHUNK_TYPE:5130562};function tr(s){return ge(ot(s[0]),ot(s[1]),ot(s[2]))}function Hn(s,e){function t(r,i){let n=r;return i!==Ee.FLOAT&&(n/=255),de(ot(n))}return new R(t(s[0],e),t(s[1],e),t(s[2],e))}var cn=class{constructor(e){this.reader=new pe(e,!0),this.componentType=null,this.dataType=null,this.byteStride=null,this.dataCount=null,this.sparseReader=null}SetComponentType(e){this.componentType=e}SetDataType(e){e==="SCALAR"?this.dataType=Ne.SCALAR:e==="VEC2"?this.dataType=Ne.VEC2:e==="VEC3"?this.dataType=Ne.VEC3:e==="VEC4"?this.dataType=Ne.VEC4:e==="MAT2"?this.dataType=Ne.MAT2:e==="MAT3"?this.dataType=Ne.MAT3:e==="MAT4"&&(this.dataType=Ne.MAT4)}SetByteStride(e){this.byteStride=e}SetDataCount(e){this.dataCount=e}SetSparseReader(e,t){this.sparseReader={indexReader:e,valueReader:t}}ReadArrayBuffer(e){return this.reader.ReadArrayBuffer(e)}GetDataCount(){return this.dataCount}ReadData(){if(this.dataType===null)return null;if(this.dataType===Ne.SCALAR){let e=this.ReadComponent();return this.SkipBytesByStride(1),e}else if(this.dataType===Ne.VEC2){let e=this.ReadComponent(),t=this.ReadComponent();return this.SkipBytesByStride(2),new N(e,t)}else if(this.dataType===Ne.VEC3){let e=this.ReadComponent(),t=this.ReadComponent(),r=this.ReadComponent();return this.SkipBytesByStride(3),new y(e,t,r)}else if(this.dataType===Ne.VEC4){let e=this.ReadComponent(),t=this.ReadComponent(),r=this.ReadComponent(),i=this.ReadComponent();return this.SkipBytesByStride(4),new Se(e,t,r,i)}return null}EnumerateData(e){if(this.sparseReader===null)for(let t=0;t{DracoDecoderModule().then(r=>{this.draco=r,t.onSuccess()})}).catch(()=>{t.onError("Failed to load draco decoder.")}):t.onSuccess()}GetUnsupportedExtensions(e){let t=[];if(e===void 0)return t;for(let r=0;r{i.AddVertex(F)}),g&&n(this.draco,o,c,a.attributes.NORMAL,F=>{i.AddNormal(F)}),C&&n(this.draco,o,c,a.attributes.TEXCOORD_0,F=>{F.y=-F.y,i.AddTextureUV(F)});let v=c.num_faces()*3,b=v*4,G=this.draco._malloc(b);o.GetTrianglesUInt32Array(c,b,G);let B=new Uint32Array(this.draco.HEAPU32.buffer,G,v).slice();for(let F=0;F0){this.SetError("Unsupported extension: "+r.join(", ")+"."),t();return}this.gltfExtensions.LoadLibraries(e.extensionsRequired,{onSuccess:()=>{this.ImportModel(e),t()},onError:i=>{this.SetError(i),t()}})}ImportModel(e){let t=e.materials;if(t!==void 0)for(let i of t)this.ImportMaterial(e,i);let r=e.meshes;if(r!==void 0)for(let i of r)this.ImportMesh(e,i);this.ImportNodes(e),this.ImportModelProperties(e)}ImportModelProperties(e){function t(r,i,n){let o=new me(i);for(let l in n)if(Object.prototype.hasOwnProperty.call(n,l)&&typeof n[l]=="string"){let a=new re(se.Text,l,n[l]);o.AddProperty(a)}return o.PropertyCount()>0&&r.AddPropertyGroup(o),o}t(this.model,"Asset properties",e.asset),e.asset.extras&&t(this.model,"Extras",e.asset.extras)}GetDefaultScene(e){let t=e.scene||0;return t>=e.scenes.length?null:e.scenes[t]}ImportMaterial(e,t){let r=new We;if(t.name!==void 0&&(r.name=t.name),r.color=tr([1,1,1]),t.pbrMetallicRoughness!==void 0){let n=t.pbrMetallicRoughness.baseColorFactor;n!==void 0&&(r.color=tr(n),r.opacity=n[3]);let o=t.pbrMetallicRoughness.metallicFactor;o!==void 0&&(r.metalness=o);let l=t.pbrMetallicRoughness.roughnessFactor;l!==void 0&&(r.roughness=l);let a=t.emissiveFactor;a!==void 0&&(r.emissive=tr(a)),r.diffuseMap=this.ImportTexture(e,t.pbrMetallicRoughness.baseColorTexture),r.metalnessMap=this.ImportTexture(e,t.pbrMetallicRoughness.metallicRoughnessTexture),r.normalMap=this.ImportTexture(e,t.normalTexture),r.emissiveMap=this.ImportTexture(e,t.emissiveTexture),r.diffuseMap!==null&&(r.multiplyDiffuseMap=!0);let u=t.alphaMode;u!==void 0&&(u==="BLEND"?r.transparent=!0:u==="MASK"&&(r.transparent=!0,r.alphaTest=t.alphaCutoff||.5))}let i=this.gltfExtensions.ProcessMaterial(t,r,n=>this.ImportTexture(e,n));i!==null&&(r=i),this.model.AddMaterial(r)}ImportTexture(e,t){if(t==null)return null;let r=new Ce,n=e.textures[t.index].source,o=e.images[n],l=null;if(this.imageIndexToTextureParams.has(n))l=this.imageIndexToTextureParams.get(n);else{l={name:null,url:null,buffer:null};let a=n.toString();if(o.uri!==void 0){let u=st(o.uri);if(u!==null)l.name="Embedded_"+a+"."+Qe(u.mimeType),l.url=zt(u.buffer,u.mimeType),l.buffer=u.buffer;else{let h=this.callbacks.getTextureBuffer(o.uri);l.name=o.uri,h!==null&&(l.url=h.url,l.buffer=h.buffer)}}else if(o.bufferView!==void 0){let u=e.bufferViews[o.bufferView],h=this.GetReaderFromBufferView(u);if(h!==null){let f=h.ReadArrayBuffer(u.byteLength);l.name="Binary_"+a+"."+Qe(o.mimeType),l.url=zt(f,o.mimeType),l.buffer=f}}this.imageIndexToTextureParams.set(n,l)}return r.name=l.name,r.url=l.url,r.buffer=l.buffer,this.gltfExtensions.ProcessTexture(t,r),r}ImportMesh(e,t){let r=new k;this.model.AddMesh(r),t.name!==void 0&&r.SetName(t.name);for(let i=0;i{r.AddVertex(g)})}else return;if(n){let m=e.accessors[t.attributes.COLOR_0],x=this.GetReaderFromAccessor(e,m);if(x===null)return;x.EnumerateData(g=>{let C=Hn([g.x,g.y,g.z],x.componentType);r.AddVertexColor(C)})}if(o){let m=e.accessors[t.attributes.NORMAL],x=this.GetReaderFromAccessor(e,m);if(x===null)return;x.EnumerateData(g=>{r.AddNormal(g)})}if(l){let m=e.accessors[t.attributes.TEXCOORD_0],x=this.GetReaderFromAccessor(e,m);if(x===null)return;x.EnumerateData(g=>{g.y=-g.y,r.AddTextureUV(g)})}let p=[];if(a){let m=e.accessors[t.indices],x=this.GetReaderFromAccessor(e,m);if(x===null)return;x.EnumerateData(g=>{p.push(g)})}else{let m=r.VertexCount()-h;for(let x=0;x{this.ifc=new WebIFC.IfcAPI,this.ifc.Init().then(()=>{this.ImportIfcContent(e),t()})}).catch(()=>{this.SetError("Failed to load web-ifc."),t()}):(this.ImportIfcContent(e),t())}ImportIfcContent(e){let t=new Uint8Array(e),r=this.ifc.OpenModel(t,{COORDINATE_TO_ORIGIN:!0}),i=this.ifc.LoadAllGeometry(r);for(let n=0;n0&&this.ImportIfcMesh(r,o)}this.ImportProperties(r),this.ifc.CloseModel(r)}ImportIfcMesh(e,t){let r=new k;r.SetName("Mesh "+t.expressID.toString());let i=0,n=t.geometries;for(let o=0;o{let l=null;if(this.expressIDToMesh.has(o.value)?l=this.expressIDToMesh.get(o.value):this.ifc.GetLine(e,o.value,!0).type===WebIFC.IFCBUILDING&&(l=this.model),l===null)return;let a=n.RelatingPropertyDefinition,u=this.ifc.GetLine(e,a.value,!0);if(!u||!u.HasProperties)return;let h=new me(u.Name.value);u.HasProperties.forEach(f=>{if(!f||!f.Name||!f.NominalValue)return;let d=null,c=this.GetIFCString(f.Name.value),p=null;switch(f.NominalValue.label){case"IFCTEXT":case"IFCLABEL":case"IFCIDENTIFIER":d=new re(se.Text,c,this.GetIFCString(f.NominalValue.value));break;case"IFCBOOLEAN":case"IFCLOGICAL":p="Unknown",f.NominalValue.value==="T"?p="True":f.NominalValue.value==="F"&&(p="False"),d=new re(se.Text,c,p);break;case"IFCINTEGER":case"IFCCOUNTMEASURE":d=new re(se.Integer,c,f.NominalValue.value);break;case"IFCREAL":case"IFCLENGTHMEASURE":case"IFCPOSITIVELENGTHMEASURE":case"IFCAREAMEASURE":case"IFCVOLUMEMEASURE":case"IFCRATIOMEASURE":case"IFCPOSITIVERATIOMEASURE":case"IFCMASSMEASURE":case"IFCMASSPERLENGTHMEASURE":case"IFCPLANEANGLEMEASURE":case"IFCTHERMALTRANSMITTANCEMEASURE":d=new re(se.Number,c,f.NominalValue.value);break;default:console.log(f.NominalValue.label),console.log(f.NominalValue.value);break}d!==null&&h.AddProperty(d)}),h.PropertyCount()>0&&l.AddPropertyGroup(h)})}}GetMaterialIndexByColor(e){let t=ge(e.x,e.y,e.z),r="Color "+Y(t.r)+Y(t.g)+Y(t.b)+Y(parseInt(e.w*255,10));if(this.materialNameToIndex.has(r))return this.materialNameToIndex.get(r);{let i=new j;i.name=r,i.color=t,i.opacity=e.w,ie(i);let n=this.model.AddMaterial(i);return this.materialNameToIndex.set(r,n),n}}GetIFCString(e){let t=this.DecodeIFCString(e);return t.length===0&&(t="-"),t}DecodeIFCString(e){let t=/\\X2\\(.*?)\\X0\\/uig,r=e,i=t.exec(e);for(;i;){let n=String.fromCharCode(parseInt(i[1],16));r=r.replace(i[0],n),i=t.exec(e)}return r}};var Nt=class{constructor(){this.name=null,this.material=null}SetName(e){return this.name=e,this}SetMaterial(e){return this.material=e,this}},ht=class{constructor(e){this.params=e||new Nt,this.mesh=new k,this.params.name!==null&&this.mesh.SetName(this.params.name),this.curve=null}GetMesh(){return this.mesh}AddVertex(e,t,r){let i=new y(e,t,r);return this.mesh.AddVertex(i)}AddVertices(e){let t=[];for(let r=0;r1&&o.GenerateSurfaceBetweenPolygons(l[l.length-1],p),l.push(p)}let f=n.AddVertex(0,0,e),d=n.AddVertex(0,0,-e);return o.GenerateTriangleFan(l[0].slice().reverse(),f),o.GenerateTriangleFan(l[l.length-1],d),n.ResetCurve(),n.GetMesh()}function ni(s,e,t){function r(n,o,l,a,u){let h=new y(l,a,u);h.MultiplyScalar(o/h.Length()),n.AddVertex(h.x,h.y,h.z)}if(!we(t))return null;let i=new ht(s);if(e==="tetrahedron"){let n=1;r(i,t,+n,+n,+n),r(i,t,-n,-n,+n),r(i,t,-n,+n,-n),r(i,t,+n,-n,-n),i.AddTriangle(0,1,3),i.AddTriangle(0,2,1),i.AddTriangle(0,3,2),i.AddTriangle(1,2,3)}else if(e==="hexahedron"){let n=1;r(i,t,+n,+n,+n),r(i,t,+n,+n,-n),r(i,t,+n,-n,+n),r(i,t,+n,-n,-n),r(i,t,-n,+n,+n),r(i,t,-n,+n,-n),r(i,t,-n,-n,+n),r(i,t,-n,-n,-n),i.AddConvexPolygon([0,1,5,4]),i.AddConvexPolygon([0,2,3,1]),i.AddConvexPolygon([0,4,6,2]),i.AddConvexPolygon([1,3,7,5]),i.AddConvexPolygon([2,6,7,3]),i.AddConvexPolygon([4,5,7,6])}else if(e==="octahedron"){let n=1,o=0;r(i,t,+n,+o,+o),r(i,t,-n,+o,+o),r(i,t,+o,+n,+o),r(i,t,+o,-n,+o),r(i,t,+o,+o,+n),r(i,t,+o,+o,-n),i.AddTriangle(0,2,4),i.AddTriangle(0,3,5),i.AddTriangle(0,4,3),i.AddTriangle(0,5,2),i.AddTriangle(1,2,5),i.AddTriangle(1,3,4),i.AddTriangle(1,4,2),i.AddTriangle(1,5,3)}else if(e==="dodecahedron"){let n=1,o=0,l=(1+Math.sqrt(5))/2,a=1/l;r(i,t,+n,+n,+n),r(i,t,+n,+n,-n),r(i,t,+n,-n,+n),r(i,t,-n,+n,+n),r(i,t,+n,-n,-n),r(i,t,-n,+n,-n),r(i,t,-n,-n,+n),r(i,t,-n,-n,-n),r(i,t,+o,+a,+l),r(i,t,+o,+a,-l),r(i,t,+o,-a,+l),r(i,t,+o,-a,-l),r(i,t,+a,+l,+o),r(i,t,+a,-l,+o),r(i,t,-a,+l,+o),r(i,t,-a,-l,+o),r(i,t,+l,+o,+a),r(i,t,-l,+o,+a),r(i,t,+l,+o,-a),r(i,t,-l,+o,-a),i.AddConvexPolygon([0,8,10,2,16]),i.AddConvexPolygon([0,16,18,1,12]),i.AddConvexPolygon([0,12,14,3,8]),i.AddConvexPolygon([1,9,5,14,12]),i.AddConvexPolygon([1,18,4,11,9]),i.AddConvexPolygon([2,10,6,15,13]),i.AddConvexPolygon([2,13,4,18,16]),i.AddConvexPolygon([3,14,5,19,17]),i.AddConvexPolygon([3,17,6,10,8]),i.AddConvexPolygon([4,13,15,7,11]),i.AddConvexPolygon([5,9,11,7,19]),i.AddConvexPolygon([6,17,19,7,15])}else if(e==="icosahedron"){let n=1,o=0,l=(1+Math.sqrt(5))/2;r(i,t,+o,+n,+l),r(i,t,+o,+n,-l),r(i,t,+o,-n,+l),r(i,t,+o,-n,-l),r(i,t,+n,+l,+o),r(i,t,+n,-l,+o),r(i,t,-n,+l,+o),r(i,t,-n,-l,+o),r(i,t,+l,+o,+n),r(i,t,+l,+o,-n),r(i,t,-l,+o,+n),r(i,t,-l,+o,-n),i.AddTriangle(0,2,8),i.AddTriangle(0,4,6),i.AddTriangle(0,6,10),i.AddTriangle(0,8,4),i.AddTriangle(0,10,2),i.AddTriangle(1,3,11),i.AddTriangle(1,4,9),i.AddTriangle(1,6,4),i.AddTriangle(1,9,3),i.AddTriangle(1,11,6),i.AddTriangle(2,5,8),i.AddTriangle(2,7,5),i.AddTriangle(2,10,7),i.AddTriangle(3,5,7),i.AddTriangle(3,7,11),i.AddTriangle(3,9,5),i.AddTriangle(4,8,9),i.AddTriangle(5,9,8),i.AddTriangle(6,11,10),i.AddTriangle(7,10,11)}return i.GetMesh()}var sr=class extends z{constructor(){super()}CanImportExtension(e){return e==="o3dv"}GetUpDirection(){return S.Z}ClearContent(){}ResetContent(){}ImportContent(e,t){let r=J(e),i=JSON.parse(r);if(i.root===void 0){t();return}if(i.materials!==void 0)for(let o=0;othis.mesh.AddVertex(new y(r.x,r.y,r.z)))}AddVertexColor(e,t){return this.GetLocalIndex(e,t,this.globalToMeshVertexColors,r=>this.mesh.AddVertexColor(new R(r.r,r.g,r.b)))}AddNormal(e,t){return this.GetLocalIndex(e,t,this.globalToMeshNormals,r=>this.mesh.AddNormal(new y(r.x,r.y,r.z)))}AddUV(e,t){return this.GetLocalIndex(e,t,this.globalToMeshUvs,r=>this.mesh.AddTextureUV(new N(r.x,r.y)))}AddTriangle(e){this.mesh.AddTriangle(e)}GetLocalIndex(e,t,r,i){if(isNaN(e)||e<0||e>=t.length)return null;if(r.has(e))return r.get(e);{let n=t[e],o=i(n);return r.set(e,o),o}}};function oi(s,e,t){return ge(parseFloat(s),parseFloat(e),parseFloat(t))}var lr=class extends z{constructor(){super()}CanImportExtension(e){return e==="obj"}GetUpDirection(){return S.Y}ClearContent(){this.globalVertices=null,this.globalVertexColors=null,this.globalNormals=null,this.globalUvs=null,this.currentMeshConverter=null,this.currentMaterial=null,this.currentMaterialIndex=null,this.meshNameToConverter=null,this.materialNameToIndex=null}ResetContent(){this.globalVertices=[],this.globalVertexColors=[],this.globalNormals=[],this.globalUvs=[],this.currentMeshConverter=null,this.currentMaterial=null,this.currentMaterialIndex=null,this.meshNameToConverter=new Map,this.materialNameToIndex=new Map}ImportContent(e,t){let r=J(e);ve(r,i=>{this.WasError()||this.ProcessLine(i)}),t()}ProcessLine(e){if(e[0]==="#")return;let t=Fe(e,"#");if(t.length===0)return;let r=t[0].toLowerCase();t.shift(),!this.ProcessMeshParameter(r,t,e)&&this.ProcessMaterialParameter(r,t,e)}AddNewMesh(e){if(this.meshNameToConverter.has(e))this.currentMeshConverter=this.meshNameToConverter.get(e);else{let t=new k;t.SetName(e),this.model.AddMeshToRootNode(t),this.currentMeshConverter=new gn(t),this.meshNameToConverter.set(e,this.currentMeshConverter)}}ProcessMeshParameter(e,t,r){if(e==="g"||e==="o"){if(t.length===0)return!0;let i=ze(r,e.length,"#");return this.AddNewMesh(i),!0}else{if(e==="v")return t.length<3||(this.globalVertices.push(new y(parseFloat(t[0]),parseFloat(t[1]),parseFloat(t[2]))),t.length>=6&&this.globalVertexColors.push(oi(t[3],t[4],t[5]))),!0;if(e==="vn")return t.length<3||this.globalNormals.push(new y(parseFloat(t[0]),parseFloat(t[1]),parseFloat(t[2]))),!0;if(e==="vt")return t.length<2||this.globalUvs.push(new N(parseFloat(t[0]),parseFloat(t[1]))),!0;if(e==="f")return t.length<3||this.ProcessFace(t),!0}return!1}ProcessMaterialParameter(e,t,r){function i(n,o,l){let a=new Ce,u=ze(o,n.length,"#"),h=l.getTextureBuffer(u);return a.name=u,h!==null&&(a.url=h.url,a.buffer=h.buffer),a}if(e==="newmtl"){if(t.length===0)return!0;let n=new j,o=ze(r,e.length,"#"),l=this.model.AddMaterial(n);return n.name=o,this.currentMaterial=n,this.materialNameToIndex.set(o,l),!0}else if(e==="usemtl"){if(t.length===0)return!0;let n=ze(r,e.length,"#");return this.materialNameToIndex.has(n)&&(this.currentMaterialIndex=this.materialNameToIndex.get(n)),!0}else if(e==="mtllib"){if(t.length===0)return!0;let n=ze(r,e.length,"#"),o=this.callbacks.getFileBuffer(n);if(o!==null){let l=J(o);ve(l,a=>{this.WasError()||this.ProcessLine(a)})}return!0}else{if(e==="map_kd")return this.currentMaterial===null||t.length===0||(this.currentMaterial.diffuseMap=i(e,r,this.callbacks),ie(this.currentMaterial)),!0;if(e==="map_ks")return this.currentMaterial===null||t.length===0||(this.currentMaterial.specularMap=i(e,r,this.callbacks)),!0;if(e==="map_bump"||e==="bump")return this.currentMaterial===null||t.length===0||(this.currentMaterial.bumpMap=i(e,r,this.callbacks)),!0;if(e==="ka")return this.currentMaterial===null||t.length<3||(this.currentMaterial.ambient=oi(t[0],t[1],t[2])),!0;if(e==="kd")return this.currentMaterial===null||t.length<3||(this.currentMaterial.color=oi(t[0],t[1],t[2])),!0;if(e==="ks")return this.currentMaterial===null||t.length<3||(this.currentMaterial.specular=oi(t[0],t[1],t[2])),!0;if(e==="ns")return this.currentMaterial===null||t.length<1||(this.currentMaterial.shininess=parseFloat(t[0])/1e3),!0;if(e==="tr")return this.currentMaterial===null||t.length<1||(this.currentMaterial.opacity=1-parseFloat(t[0]),ie(this.currentMaterial)),!0;if(e==="d")return this.currentMaterial===null||t.length<1||(this.currentMaterial.opacity=parseFloat(t[0]),ie(this.currentMaterial)),!0}return!1}ProcessFace(e){function t(l,a){return l>0?l-1:a+l}let r=[],i=[],n=[],o=[];for(let l=0;l1&&a[1].length>0&&o.push(t(parseInt(a[1],10),this.globalUvs.length)),a.length>2&&a[2].length>0&&n.push(t(parseInt(a[2],10),this.globalNormals.length))}this.currentMeshConverter===null&&this.AddNewMesh("");for(let l=0;l{this.WasError()||this.ProcessLine(i)}),t()}ProcessLine(e){if(e[0]==="#")return;let t=Fe(e,"#");if(t.length!==0&&t[0]!=="OFF"){if(this.status.vertexCount===0&&this.status.faceCount===0){t.length>1&&(this.status.vertexCount=parseInt(t[0],10),this.status.faceCount=parseInt(t[1],10));return}if(this.status.foundVertex=3&&(this.mesh.AddVertex(new y(parseFloat(t[0]),parseFloat(t[1]),parseFloat(t[2]))),this.status.foundVertex+=1);return}if(this.status.foundFace=4){let r=parseInt(t[0],10);if(t.length0&&t.format.length>0,n=r!==null&&r.count>0&&r.format.length>0;if(!i&&!n)return rt.NoFaces}else return rt.UnknownError;return rt.Ok}},Tn=class{constructor(e){this.model=e,this.colorToMaterial=new Map}GetMaterialIndexByColor(e){let t="Color "+Y(e[0])+Y(e[1])+Y(e[2])+Y(e[3]);if(this.colorToMaterial.has(t))return this.colorToMaterial.get(t);{let r=new j;r.name=t,r.color=new R(e[0],e[1],e[2]),r.opacity=e[3]/255,ie(r);let i=this.model.AddMaterial(r);return this.colorToMaterial.set(t,i),i}}},ur=class extends z{constructor(){super()}CanImportExtension(e){return e==="ply"}GetUpDirection(){return S.Y}ClearContent(){this.mesh=null}ResetContent(){this.mesh=new k,this.model.AddMeshToRootNode(this.mesh)}ImportContent(e,t){let r=this.GetHeaderContent(e),i=this.ReadHeader(r),n=i.Check();if(n===rt.Ok)if(i.format==="ascii"){let o=J(e);o=o.substring(r.length),this.ReadAsciiContent(i,o)}else(i.format==="binary_little_endian"||i.format==="binary_big_endian")&&this.ReadBinaryContent(i,e,r.length);else n===rt.NoVertices?this.SetError("The model contains no vertices."):n===rt.NoFaces?this.SetError("The model contains no faces."):this.SetError("Invalid header information.");t()}GetHeaderContent(e){let t="",r=new Uint8Array(e),i=0;for(i=0;i{let i=Fe(r,null);i.length===0||i[0]==="comment"||i[0]!=="ply"&&(i[0]==="format"&&i.length>=2?t.SetFormat(i[1]):i[0]==="element"&&i.length>=3?t.AddElement(i[1],parseInt(i[2],10)):i[0]==="property"&&i.length>=3&&(i[1]==="list"&&i.length>=5?t.AddListFormat(i[2],i[3],i[4]):t.AddSingleFormat(i[1],i[2])))}),t}ReadAsciiContent(e,t){let r=e.GetElement("vertex"),i=e.GetElement("face"),n=0,o=0;ve(t,l=>{if(this.WasError())return;let a=Fe(l,null);if(!(a.length===0||a[0]==="comment")){if(n=3&&(this.mesh.AddVertex(new y(parseFloat(a[0]),parseFloat(a[1]),parseFloat(a[2]))),n+=1);return}if(i!==null&&o=4){let u=parseInt(a[0],10);if(a.length0&&M.SetVertexColors(x,g,C),this.mesh.AddTriangle(M)}}else if(f.name==="tristrips")for(let d=0;d{this.ImportStepContent(n.data,t),this.worker.removeEventListener("message",r)};this.worker.addEventListener("message",r),this.worker.addEventListener("error",n=>{this.worker=null,this.SetError("Failed to load occt-import-js."),t()});let i=new Uint8Array(e);this.worker.postMessage(i)}ImportStepContent(e,t){if(!e.success)return;let r=new Qt(i=>{let n=new j;return n.name=Ke(i).toUpperCase(),n.color=i,this.model.AddMaterial(n)});for(let i of e.meshes){let n=null;if(i.color){let l=ge(i.color[0],i.color[1],i.color[2]);n=r.GetMaterialIndex(l)}let o=qe(i,n);if(i.name&&o.SetName(i.name),i.face_colors)for(let l of i.face_colors){let a=ge(l.color[0],l.color[1],l.color[2]),u=r.GetMaterialIndex(a);for(let h=l.first;h<=l.last;h++)o.GetTriangle(h).SetMaterial(u)}this.model.AddMeshToRootNode(o)}t()}};var fr=class extends z{constructor(){super()}CanImportExtension(e){return e==="stl"}GetUpDirection(){return S.Z}ClearContent(){this.mesh=null,this.triangle=null}ResetContent(){this.mesh=new k,this.model.AddMeshToRootNode(this.mesh),this.triangle=null}ImportContent(e,t){if(this.IsBinaryStlFile(e))this.ProcessBinary(e);else{let r=J(e);ve(r,i=>{this.WasError()||this.ProcessLine(i)})}t()}IsBinaryStlFile(e){let t=e.byteLength;if(t<84)return!1;let r=new pe(e,!0);r.Skip(80);let i=r.ReadUnsignedInteger32();return t===i*50+84}ProcessLine(e){if(e[0]==="#")return;let t=Fe(e,"#");if(t.length===0)return;let r=t[0];if(r==="solid"){if(t.length>1){let i=ze(e,r.length,"#");this.mesh.SetName(i)}return}if(r==="facet"){if(this.triangle=new U(-1,-1,-1),t.length>=5&&t[1]==="normal"){let i=new y(parseFloat(t[2]),parseFloat(t[3]),parseFloat(t[4]));if(we(i.Length())){let n=this.mesh.AddNormal(i);this.triangle.SetNormals(n,n,n)}}return}if(r==="vertex"&&this.triangle!==null){if(t.length>=4){let i=this.mesh.AddVertex(new y(parseFloat(t[1]),parseFloat(t[2]),parseFloat(t[3])));this.triangle.v0===-1?this.triangle.v0=i:this.triangle.v1===-1?this.triangle.v1=i:this.triangle.v2===-1&&(this.triangle.v2=i)}return}if(r==="endfacet"&&this.triangle!==null){this.triangle.v0!==-1&&this.triangle.v1!==-1&&this.triangle.v2!==null&&this.mesh.AddTriangle(this.triangle),this.triangle=null;return}}ProcessBinary(e){function t(o){let l=new y;return l.x=o.ReadFloat32(),l.y=o.ReadFloat32(),l.z=o.ReadFloat32(),l}function r(o,l){let a=t(l);return o.AddVertex(a)}let i=new pe(e,!0);i.Skip(80);let n=i.ReadUnsignedInteger32();for(let o=0;o{this.LoadModel(e,t)},()=>{this.SetError("Failed to load three.js loader."),t()})}LoadModel(e,t){let r=!1,i=new THREE.LoadingManager(()=>{r=!0}),n=lt(e);i.setURLModifier(l=>{if(l===n)return l;let a=X(l);if(Ve(l).length>0){let h=this.callbacks.getFileBuffer(l);if(h!==null){let f=lt(h);return this.objectUrlToFileName.set(f,a),f}}return l});let o=this.CreateLoader(i);if(o===null){t();return}o.load(n,l=>{Gr(()=>r?(this.OnThreeObjectsLoaded(l,t),!1):!0)},()=>{},l=>{this.SetError(l),t()})}OnThreeObjectsLoaded(e,t){function r(l){let a=new O().CreateIdentity();return l.updateMatrix(),l.matrix!==void 0&&l.matrix!==null&&a.Set(l.matrix.elements),new H(a)}function i(l,a,u,h){let f=new ue;u.name!==void 0&&f.SetName(u.name),f.SetTransformation(r(u)),h.AddChildNode(f);for(let d of u.children)i(l,a,d,f);if(u.isMesh&&l.IsMeshVisible(u)){u.children.length===0&&f.SetType(Me.MeshNode);let d=l.ConvertThreeMesh(u),c=a.AddMesh(d);f.AddMeshIndex(c)}}let n=this.GetMainObject(e),o=this.model.GetRootNode();o.SetTransformation(r(n));for(let l of n.children)i(this,this.model,l,o);t()}ConvertThreeMesh(e){let t=null;if(Array.isArray(e.material)){if(t=qe(e.geometry,null),e.geometry.attributes.color===void 0||e.geometry.attributes.color===null){let r=[];for(let i=0;i{i.onFilesLoaded(),Pt(()=>{this.ImportLoadedFiles(r,i)})})}LoadFiles(e,t,r){let i=new At;t===Z.Url?i.FillFromFileUrls(e):t===Z.File&&i.FillFromFileObjects(e);let n=!1;if(this.HasImportableFile(i))n=!0;else{let o=!1;for(let l=0;l{this.DecompressArchives(this.fileList,()=>{r()})})}ImportLoadedFiles(e,t){let r=this.GetImportableFiles(this.fileList);if(r.length===0){t.onImportError(new ft(_e.NoImportableFile));return}if(r.length===1||!t.onSelectMainFile){let i=r[0];this.ImportLoadedMainFile(i,e,t)}else{let i=r.map(n=>n.file.name);t.onSelectMainFile(i,n=>{if(n===null){t.onImportError(new ft(_e.NoImportableFile));return}Pt(()=>{let o=r[n];this.ImportLoadedMainFile(o,e,t)})})}}ImportLoadedMainFile(e,t,r){if(e===null||e.file===null||e.file.content===null){let o=new ft(_e.FailedToLoadFile);e!==null&&e.file!==null&&(o.mainFile=e.file.name),r.onImportError(o);return}this.RevokeModelUrls(),this.model=null,this.usedFiles=[],this.missingFiles=[],this.usedFiles.push(e.file.name);let i=e.importer,n=new li(o=>{let l=null,a=this.fileList.FindFileByPath(o);return a===null||a.content===null?(this.missingFiles.push(o),l=null):(this.usedFiles.push(o),l=a.content),l});i.Import(e.file.name,e.file.extension,e.file.content,{getDefaultMaterialColor:()=>t.defaultColor,getFileBuffer:o=>n.GetFileBuffer(o),getTextureBuffer:o=>n.GetTextureBuffer(o),onSuccess:()=>{this.model=i.GetModel();let o=new si;o.mainFile=e.file.name,o.model=this.model,o.usedFiles=this.usedFiles,o.missingFiles=this.missingFiles,o.upVector=i.GetUpDirection(),r.onImportSuccess(o)},onError:()=>{let o=new ft(_e.ImportFailed);o.mainFile=e.file.name,o.message=i.GetErrorMessage(),r.onImportError(o)},onComplete:()=>{i.Clear()}})}DecompressArchives(e,t){let r=e.GetFiles(),i=[];for(let n of r)n.extension==="zip"&&i.push(n);if(i.length===0){t();return}fe("loaders/fflate.min.js").then(()=>{for(let n=0;n{t()})}GetFileList(){return this.fileList}HasImportableFile(e){return this.GetImportableFiles(e).length>0}GetImportableFiles(e){function t(n,o){for(let l=0;l{r.url!==null&&_r(r.url)})}};var Di=class extends Xe{constructor(){super()}CanImportExtension(e){return e==="svg"}GetUpDirection(){return S.Z}GetExternalLibraries(){return["three_loaders/SVGLoader.js"]}CreateLoader(e){return new THREE.SVGLoader(e)}GetMainObject(e){function t(o){let l=o.userData.style;return!(l.fill===void 0||l.fill==="none")}function r(o,l,a){let u=null;for(let h of o)if(h.style===l&&h.opacity===a){u=h.material;break}return u===null&&(u=new THREE.MeshPhongMaterial({color:new THREE.Color().setStyle(l),opacity:a,transparent:a<1}),o.push({style:l,opacity:a,material:u})),u}let i=[],n=new THREE.Object3D;n.rotation.x=Math.PI;for(let o of e.paths){let l=THREE.SVGLoader.createShapes(o);if(t(o)){let a=o.userData.style,u=r(i,a.fill,a.opacity);for(let h of l){let f=new THREE.ExtrudeGeometry(h,{depth:10,bevelEnabled:!1}),d=new THREE.Mesh(f,u);d.name=o.userData.node.id,n.add(d)}}}return n}};function Pi(s,e,t){let r=ye(s,e),i=ye(e,t),n=ye(s,t),o=(r+i+n)/2,l=o*(o-r)*(o-i)*(o-n);return l<0?0:Math.sqrt(l)}function Vi(s,e,t){return Ut(s,Ge(e,t))/6}function yn(s){let e=0;return s.EnumerateTriangleVertices((t,r,i)=>{e+=Vi(t,r,i)}),e}function In(s){let e=0;return s.EnumerateTriangleVertices((t,r,i)=>{e+=Pi(t,r,i)}),e}var De=class{constructor(e,t,r){this.eye=e,this.center=t,this.up=r}Clone(){return new De(this.eye.Clone(),this.center.Clone(),this.up.Clone())}};function ai(s,e){return Te(s.eye,e.eye)&&Te(s.center,e.center)&&Te(s.up,e.up)}var K={IntegerToString(s){return s.toString()},StringToInteger(s){return parseInt(s,10)},NumberToString(s){let e=5;return s.toFixed(e)},StringToNumber(s){return parseFloat(s)},ModelUrlsToString:function(s){return s===null?null:s.join(",")},StringToModelUrls:function(s){return s===null||s.length===0?null:s.split(",")},CameraToString:function(s){return s===null?null:[this.NumberToString(s.eye.x),this.NumberToString(s.eye.y),this.NumberToString(s.eye.z),this.NumberToString(s.center.x),this.NumberToString(s.center.y),this.NumberToString(s.center.z),this.NumberToString(s.up.x),this.NumberToString(s.up.y),this.NumberToString(s.up.z)].join(",")},StringToCamera:function(s){if(s===null||s.length===0)return null;let e=s.split(",");return e.length!==9?null:new De(new y(this.StringToNumber(e[0]),this.StringToNumber(e[1]),this.StringToNumber(e[2])),new y(this.StringToNumber(e[3]),this.StringToNumber(e[4]),this.StringToNumber(e[5])),new y(this.StringToNumber(e[6]),this.StringToNumber(e[7]),this.StringToNumber(e[8])))},ColorToString:function(s){return s===null?null:[this.IntegerToString(s.r),this.IntegerToString(s.g),this.IntegerToString(s.b)].join(",")},StringToColor:function(s){if(s===null||s.length===0)return null;let e=s.split(",");return e.length!==3?null:new R(this.StringToInteger(e[0]),this.StringToInteger(e[1]),this.StringToInteger(e[2]))},EnvironmentSettingsToString(s){return s===null?null:[s.environmentMapName,s.backgroundIsEnvMap?"on":"off"].join(",")},StringToEnvironmentSettings:function(s){if(s===null||s.length===0)return null;let e=s.split(",");return e.length!==2?null:{environmentMapName:e[0],backgroundIsEnvMap:e[1]==="on"}},EdgeSettingsToString:function(s){return s===null?null:[s.showEdges?"on":"off",this.ColorToString(s.edgeColor),this.IntegerToString(s.edgeThreshold)].join(",")},StringToEdgeSettings:function(s){if(s===null||s.length===0)return null;let e=s.split(",");return e.length!==5?null:{showEdges:e[0]==="on",edgeColor:new R(this.StringToInteger(e[1]),this.StringToInteger(e[2]),this.StringToInteger(e[3])),edgeThreshold:this.StringToInteger(e[4])}}},ui=class{constructor(e){this.separator=e,this.paramList=""}AddModelUrls(e){return this.AddUrlPart("model",K.ModelUrlsToString(e)),this}AddCamera(e){return this.AddUrlPart("camera",K.CameraToString(e)),this}AddEnvironmentSettings(e){return this.AddUrlPart("envsettings",K.EnvironmentSettingsToString(e)),this}AddBackgroundColor(e){return this.AddUrlPart("backgroundcolor",K.ColorToString(e)),this}AddDefaultColor(e){return this.AddUrlPart("defaultcolor",K.ColorToString(e)),this}AddEdgeSettings(e){return this.AddUrlPart("edgesettings",K.EdgeSettingsToString(e)),this}AddUrlPart(e,t){e===null||t===null||(this.paramList.length>0&&(this.paramList+=this.separator),this.paramList+=e+"="+t)}GetParameterList(){return this.paramList}},hi=class{constructor(e,t){this.separator=t,this.paramList=e}GetModelUrls(){if(this.paramList.indexOf("=")===-1)return this.paramList.split(",");let e=this.GetKeywordParams("model");return K.StringToModelUrls(e)}GetCamera(){let e=this.GetKeywordParams("camera");return K.StringToCamera(e)}GetEnvironmentSettings(){let e=this.GetKeywordParams("envsettings");return K.StringToEnvironmentSettings(e)}GetBackgroundColor(){let e=this.GetKeywordParams("backgroundcolor");return K.StringToColor(e)}GetDefaultColor(){let e=this.GetKeywordParams("defaultcolor");return K.StringToColor(e)}GetEdgeSettings(){let e=this.GetKeywordParams("edgesettings");return K.StringToEdgeSettings(e)}GetKeywordParams(e){if(this.paramList===null||this.paramList.length===0)return null;let t=e+"=",r=this.paramList.split(this.separator);for(let i=0;i{C(B,P),G.needsUpdate=!0,F(P),b.OnTextureLoaded()},null,P=>{b.OnTextureLoaded()})}let T=c.GetMaterial(p),E=ce(T.color);T.vertexColors&&E.setRGB(1,1,1);let w={color:E,vertexColors:T.vertexColors,opacity:T.opacity,transparent:T.transparent,alphaTest:T.alphaTest,side:THREE.DoubleSide};x.forceMediumpForMaterials&&(w.precision="mediump");let I=null;if(m===ae.Phong){if(I=new THREE.MeshPhongMaterial(w),T.type===ee.Phong){let b=ce(T.specular);V(T.shininess,0)&&b.setRGB(0,0,0),I.specular=b,I.shininess=T.shininess*100,M(d,I,T.specularMap,G=>{I.specularMap=G})}}else m===ae.Physical&&(I=new THREE.MeshStandardMaterial(w),T.type===ee.Physical&&(I.metalness=T.metalness,I.roughness=T.roughness,M(d,I,T.metalnessMap,b=>{I.metalness=1,I.roughness=1,I.metalnessMap=b,I.roughnessMap=b})));let v=ce(T.emissive);return I.emissive=v,M(d,I,T.diffuseMap,b=>{T.multiplyDiffuseMap||I.color.setRGB(1,1,1),I.map=b}),M(d,I,T.bumpMap,b=>{I.bumpMap=b}),M(d,I,T.normalMap,b=>{I.normalMap=b}),M(d,I,T.emissiveMap,b=>{I.emissiveMap=b}),T.isDefault&&(g.defaultMaterial=I),I}function n(d,c,p){let m=d.GetMesh(c.meshIndex),x=m.TriangleCount(),g=[];for(let P=0;P{let _=m.GetTriangle(P),xe=m.GetTriangle(ne);return _.mat-xe.mat});let C=new THREE.BufferGeometry,M=[],T=[],E=new Map,w=[],I=[],v=[],b=[],G=[];G.push({start:0,end:-1});let B=m.VertexColorCount()>0,F=m.TextureUVCount()>0;for(let P=0;P0&&(G[G.length-1].end=P-1,G.push({start:G[G.length-1].end+1,end:-1})))}G[G.length-1].end=x-1,C.setAttribute("position",new THREE.Float32BufferAttribute(w,3)),I.length!==0&&C.setAttribute("color",new THREE.Float32BufferAttribute(I,3)),C.setAttribute("normal",new THREE.Float32BufferAttribute(v,3)),b.length!==0&&C.setAttribute("uv",new THREE.Float32BufferAttribute(b,2));for(let P=0;P{for(let w=M;w<=T;w++){let I=C[w],v=I.node,b=I.threeNode,G=new tt(v.GetId(),I.meshIndex);o(b,c,G,p)}E()},onReady:()=>{m.OnModelLoaded(d)}})}let a=new fi(r),u=$r(s),h=[];for(let d=0;d{i.onImportStart()},onSelectMainFile:(n,o)=>{i.onSelectMainFile?i.onSelectMainFile(n,o):o(0)},onImportSuccess:n=>{i.onVisualizationStart();let o=new Tr;o.forceMediumpForMaterials=this.hasHighpDriverIssue;let l=new yr;mi(n.model,o,l,{onTextureLoaded:()=>{i.onTextureLoaded()},onModelLoaded:a=>{if(this.defaultMaterial=l.defaultMaterial,n.upVector===S.X){let u=new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1),Math.PI/2);a.quaternion.multiply(u)}else if(n.upVector===S.Z){let u=new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1,0,0),-Math.PI/2);a.quaternion.multiply(u)}i.onModelFinished(n,a),this.inProgress=!1}})},onImportError:n=>{i.onLoadError(n),this.inProgress=!1}}))}GetImporter(){return this.importer}GetDefaultMaterial(){return this.defaultMaterial}ReplaceDefaultMaterialColor(e){this.defaultMaterial!==null&&!this.defaultMaterial.vertexColors&&(this.defaultMaterial.color=ce(e))}};function Q(s){return Math.round(parseFloat(s))}function ci(s){let e=Q(s.paddingLeft)+Q(s.paddingRight),t=Q(s.borderLeftWidth)+Q(s.borderRightWidth),r=Q(s.marginLeft)+Q(s.marginRight);return e+t+r}function pi(s){let e=Q(s.paddingTop)+Q(s.paddingBottom),t=Q(s.borderTopWidth)+Q(s.borderBottomWidth),r=Q(s.marginTop)+Q(s.marginBottom);return e+t+r}function xi(s,e,t){let r=getComputedStyle(s),i=e-ci(r),n=t-pi(r);return{width:i,height:n}}function Ye(s,e,t){if(s.getBoundingClientRect){let r=s.getBoundingClientRect();e-=r.left,t-=r.top}return window.pageXOffset&&window.pageYOffset&&(e+=window.pageXOffset,t+=window.pageYOffset),new N(e,t)}function gi(s,e,t){let r=document.createElement(s);return e&&(r.className=e),t&&(r.innerHTML=t),r}function Bi(s,e,t,r){let i=gi(e,t,r);return s.appendChild(i),i}function bn(s,e,t){return Bi(s,"div",e,t)}function wn(s){for(;s.firstChild;)s.removeChild(s.firstChild)}function Sn(s,e){e.parentNode.insertBefore(s,e)}function vn(s,e){e.parentNode.insertBefore(s,e.nextSibling)}function An(s,e){e?s.style.display="block":s.style.display="none"}function Gn(s){return s.offsetParent!==null}function Li(s,e){s.style.width=e.toString()+"px"}function Ui(s,e){s.style.height=e.toString()+"px"}function Rn(s){let e=getComputedStyle(s);return s.offsetWidth+Q(e.marginLeft)+Q(e.marginRight)}function Fn(s){let e=getComputedStyle(s);return s.offsetHeight+Q(e.marginTop)+Q(e.marginBottom)}function Nn(s,e){let t=getComputedStyle(s);Li(s,e-ci(t))}function Dn(s,e){let t=getComputedStyle(s);Ui(s,e-pi(t))}function Pn(s,e){return gi("div",s,e)}var Ci=class{constructor(){this.prev=new N(0,0),this.curr=new N(0,0),this.diff=new N(0,0),this.buttons=[]}Down(e,t){this.buttons.push(t.which),this.curr=this.GetPositionFromEvent(e,t),this.prev=this.curr.Clone()}Move(e,t){this.curr=this.GetPositionFromEvent(e,t),this.diff=Ot(this.curr,this.prev),this.prev=this.curr.Clone()}Up(e,t){let r=this.buttons.indexOf(t.which);r!==-1&&this.buttons.splice(r,1),this.curr=this.GetPositionFromEvent(e,t)}Leave(e,t){this.buttons=[],this.curr=this.GetPositionFromEvent(e,t)}IsButtonDown(){return this.buttons.length>0}GetButton(){let e=this.buttons.length;return e===0?0:this.buttons[e-1]}GetPosition(){return this.curr}GetMoveDiff(){return this.diff}GetPositionFromEvent(e,t){return Ye(e,t.clientX,t.clientY)}},Ti=class{constructor(){this.prevPos=new N(0,0),this.currPos=new N(0,0),this.diffPos=new N(0,0),this.prevDist=0,this.currDist=0,this.diffDist=0,this.fingers=0}Start(e,t){t.touches.length!==0&&(this.fingers=t.touches.length,this.currPos=this.GetPositionFromEvent(e,t),this.prevPos=this.currPos.Clone(),this.currDist=this.GetTouchDistanceFromEvent(e,t),this.prevDist=this.currDist)}Move(e,t){t.touches.length!==0&&(this.currPos=this.GetPositionFromEvent(e,t),this.diffPos=Ot(this.currPos,this.prevPos),this.prevPos=this.currPos.Clone(),this.currDist=this.GetTouchDistanceFromEvent(e,t),this.diffDist=this.currDist-this.prevDist,this.prevDist=this.currDist)}End(e,t){t.touches.length!==0&&(this.fingers=0,this.currPos=this.GetPositionFromEvent(e,t),this.currDist=this.GetTouchDistanceFromEvent(e,t))}IsFingerDown(){return this.fingers!==0}GetFingerCount(){return this.fingers}GetPosition(){return this.currPos}GetMoveDiff(){return this.diffPos}GetDistanceDiff(){return this.diffDist}GetPositionFromEvent(e,t){let r=null;if(t.touches.length!==0){let i=t.touches[0];r=Ye(e,i.pageX,i.pageY)}return r}GetTouchDistanceFromEvent(e,t){if(t.touches.length!==2)return 0;let r=t.touches[0],i=t.touches[1];return Bt(Ye(e,r.pageX,r.pageY),Ye(e,i.pageX,i.pageY))}},yi=class{constructor(){this.isClick=!1,this.startPosition=null}Start(e){this.isClick=!0,this.startPosition=e}Move(e){!this.isClick||(this.startPosition!==null?Bt(this.startPosition,e)>3&&this.Cancel():this.Cancel())}End(){this.startPosition=null}Cancel(){this.isClick=!1,this.startPosition=null}IsClick(){return this.isClick}},he={None:0,Orbit:1,Pan:2,Zoom:3},Mr=class{constructor(e,t,r){this.canvas=e,this.camera=t,this.callbacks=r,this.fixUpVector=!0,this.mouse=new Ci,this.touch=new Ti,this.clickDetector=new yi,this.onMouseClick=null,this.onMouseMove=null,this.onContext=null,this.canvas.addEventListener&&(this.canvas.addEventListener("mousedown",this.OnMouseDown.bind(this)),this.canvas.addEventListener("wheel",this.OnMouseWheel.bind(this)),this.canvas.addEventListener("touchstart",this.OnTouchStart.bind(this)),this.canvas.addEventListener("touchmove",this.OnTouchMove.bind(this)),this.canvas.addEventListener("touchcancel",this.OnTouchEnd.bind(this)),this.canvas.addEventListener("touchend",this.OnTouchEnd.bind(this)),this.canvas.addEventListener("contextmenu",this.OnContextMenu.bind(this))),document.addEventListener&&(document.addEventListener("mousemove",this.OnMouseMove.bind(this)),document.addEventListener("mouseup",this.OnMouseUp.bind(this)),document.addEventListener("mouseleave",this.OnMouseLeave.bind(this)))}SetMouseClickHandler(e){this.onMouseClick=e}SetMouseMoveHandler(e){this.onMouseMove=e}SetContextMenuHandler(e){this.onContext=e}IsFixUpVector(){return this.fixUpVector}SetFixUpVector(e){this.fixUpVector=e}GetCamera(){return this.camera}SetCamera(e){this.camera=e}MoveCamera(e,t){function r(i,n,o,l){i.camera.eye=n.eye[l],i.camera.center=n.center[l],i.camera.up=n.up[l],i.Update(),l{r(i,n,o,l+1)})}if(e!==null){if(t===0||ai(this.camera,e))this.camera=e;else{let i=qr,n={eye:St(this.camera.eye,e.eye,t,i),center:St(this.camera.center,e.center,t,i),up:St(this.camera.up,e.up,t,i)};requestAnimationFrame(()=>{r(this,n,t,0)})}this.Update()}}GetFitToSphereCamera(e,t,r){if(nt(t))return null;let i=this.camera.Clone(),n=te(i.center,e);i.eye=te(i.eye,n),i.center=e.Clone();let o=te(i.eye,i.center).Normalize(),l=r/2;this.canvas.width{o.material.color=n})}else this.ClearMainEdgeObject()}GenerateMainEdgeObject(){let e=ce(this.edgeSettings.edgeColor);this.mainEdgeObject=new THREE.Object3D,this.UpdateWorldMatrix(),this.EnumerateMeshes(t=>{Ii(t,!0);let r=new THREE.EdgesGeometry(t.geometry,this.edgeSettings.edgeThreshold),i=new THREE.LineSegments(r,new THREE.LineBasicMaterial({color:e}));i.applyMatrix4(t.matrixWorld),i.userData=t.userData,i.visible=t.visible,this.mainEdgeObject.add(i)}),this.scene.add(this.mainEdgeObject)}GetBoundingBox(e){let t=!1,r=new THREE.Box3;return this.EnumerateMeshes(i=>{e(i.userData)&&(r.union(new THREE.Box3().setFromObject(i)),t=!0)}),t?r:null}GetBoundingSphere(e){let t=this.GetBoundingBox(e);if(t===null)return null;let r=new THREE.Sphere;return t.getBoundingSphere(r),r}Clear(){this.ClearMainObject(),this.ClearMainEdgeObject()}ClearMainObject(){this.mainObject!==null&&(this.EnumerateMeshes(e=>{e.geometry.dispose()}),this.scene.remove(this.mainObject),this.mainObject=null)}ClearMainEdgeObject(){this.mainEdgeObject!==null&&(this.EnumerateMeshes(e=>{Ii(e,!1)}),this.EnumerateEdges(e=>{e.geometry.dispose()}),this.scene.remove(this.mainEdgeObject),this.mainEdgeObject=null)}EnumerateMeshes(e){this.mainObject!==null&&this.mainObject.traverse(t=>{t.isMesh&&e(t)})}EnumerateEdges(e){this.mainEdgeObject!==null&&this.mainEdgeObject.traverse(t=>{t.isLineSegments&&e(t)})}GetMeshIntersectionUnderMouse(e,t,r,i){if(this.mainObject===null||e.x<0||e.x>r||e.y<0||e.y>i)return null;let n=new THREE.Raycaster,o=new THREE.Vector2;o.x=e.x/r*2-1,o.y=-(e.y/i)*2+1,n.setFromCamera(o,t);let l=n.intersectObject(this.mainObject,!0);for(let a=0;a{(e.isMesh||e.isLineSegments)&&e.geometry.dispose()}),this.scene.remove(this.mainObject),this.mainObject=null)}};function Mi(s){return s===S.X?new De(new y(2,-3,1.5),new y(0,0,0),new y(1,0,0)):s===S.Y?new De(new y(-1.5,2,3),new y(0,0,0),new y(0,1,0)):s===S.Z?new De(new y(-1.5,-3,2),new y(0,0,0),new y(0,0,1)):null}function Ei(s,e){if(!e(s))return!1;for(let t of s.children)if(!Ei(t,e))return!1;return!0}function zi(s){let e=null;return Ei(s,t=>{if(t.isMesh)for(let r of t.material)return r.type==="MeshPhongMaterial"?e=ae.Phong:r.type==="MeshStandardMaterial"&&(e=ae.Physical),!1;return!0}),e}var bi=class{constructor(){this.direction=S.Z,this.isFixed=!0,this.isFlipped=!1}SetDirection(e,t){this.direction=e,this.isFlipped=!1;let r=Mi(this.direction),i=te(r.eye,r.center),n=ye(t.center,t.eye),o=t.center.Clone().Offset(i,n),l=t.Clone();return this.direction===S.X?(l.up=new y(1,0,0),l.eye=o):this.direction===S.Y?(l.up=new y(0,1,0),l.eye=o):this.direction===S.Z&&(l.up=new y(0,0,1),l.eye=o),l}SetFixed(e,t){return this.isFixed=e,this.isFixed?this.SetDirection(this.direction,t):null}Flip(e){this.isFlipped=!this.isFlipped;let t=e.Clone();return t.up.MultiplyScalar(-1),t}},wi=class{constructor(e){this.scene=e,this.type=ae.Phong,this.ambientLight=new THREE.AmbientLight(8947848),this.directionalLight=new THREE.DirectionalLight(8947848),this.environment=null,this.backgroundIsEnvMap=!1,this.scene.add(this.ambientLight),this.scene.add(this.directionalLight)}SetType(e){this.type=e,this.UpdateShading()}UpdateShading(){this.type===ae.Phong?(this.ambientLight.color.set(8947848),this.directionalLight.color.set(8947848),this.scene.environment=null,this.scene.background=null):this.type===ae.Physical&&(this.ambientLight.color.set(0),this.directionalLight.color.set(5592405),this.scene.environment=this.environment,this.backgroundIsEnvMap?this.scene.background=this.environment:this.scene.background=null)}SetEnvironment(e,t,r){let i=new THREE.CubeTextureLoader;this.environment=i.load(e,()=>{r()}),this.backgroundIsEnvMap=t}UpdateByCamera(e){let t=te(e.eye,e.center);this.directionalLight.position.set(t.x,t.y,t.z)}CreateHighlightMaterial(e,t){let r=null;return this.type===ae.Phong?r=new THREE.MeshPhongMaterial({color:e,side:THREE.DoubleSide}):this.type===ae.Physical&&(r=new THREE.MeshStandardMaterial({color:e,side:THREE.DoubleSide})),r!==null&&t&&(r.polygonOffset=!0,r.polygonOffsetUnit=1,r.polygonOffsetFactor=1),r}},wr=class{constructor(){this.canvas=null,this.renderer=null,this.scene=null,this.geometry=null,this.extraGeometry=null,this.camera=null,this.shading=null,this.navigation=null,this.upVector=null,this.settings={animationSteps:40}}Init(e){this.canvas=e,this.canvas.id="viewer";let t={canvas:this.canvas,antialias:!0};this.renderer=new THREE.WebGLRenderer(t),window.devicePixelRatio&&this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setClearColor("#ffffff",1),this.renderer.setSize(this.canvas.width,this.canvas.height),this.scene=new THREE.Scene,this.geometry=new Er(this.scene),this.extraGeometry=new br(this.scene),this.InitNavigation(),this.InitShading(),this.Render()}SetMouseClickHandler(e){this.navigation.SetMouseClickHandler(e)}SetMouseMoveHandler(e){this.navigation.SetMouseMoveHandler(e)}SetContextMenuHandler(e){this.navigation.SetContextMenuHandler(e)}SetEnvironmentMapSettings(e,t){this.shading.SetEnvironment(e,t,()=>{this.Render()}),this.shading.UpdateShading(),this.Render()}SetBackgroundColor(e){let t="#"+Ke(e);this.renderer.setClearColor(t,1),this.Render()}SetEdgeSettings(e,t,r){this.geometry.SetEdgeSettings(e,t,r),this.Render()}GetCanvas(){return this.canvas}GetCamera(){return this.navigation.GetCamera()}SetCamera(e){this.navigation.SetCamera(e),this.Render()}Resize(e,t){let r=xi(this.canvas,e,t);this.ResizeRenderer(r.width,r.height)}ResizeRenderer(e,t){window.devicePixelRatio&&this.renderer.setPixelRatio(window.devicePixelRatio),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t),this.Render()}FitSphereToWindow(e,t){if(e===null)return;let r=new y(e.center.x,e.center.y,e.center.z),i=e.radius,n=this.camera.fov,o=this.navigation.GetFitToSphereCamera(r,i,n);this.navigation.MoveCamera(o,t?this.settings.animationSteps:0)}AdjustClippingPlanesToSphere(e){e!==null&&(e.radius<10?(this.camera.near=.01,this.camera.far=100):e.radius<100?(this.camera.near=.1,this.camera.far=1e3):e.radius<1e3?(this.camera.near=10,this.camera.far=1e4):(this.camera.near=100,this.camera.far=1e6),this.camera.updateProjectionMatrix(),this.Render())}IsFixUpVector(){return this.navigation.IsFixUpVector()}SetFixUpVector(e){let t=this.navigation.GetCamera(),r=this.upVector.SetFixed(e,t);this.navigation.SetFixUpVector(e),r!==null&&this.navigation.MoveCamera(r,this.settings.animationSteps),this.Render()}SetUpVector(e,t){let r=this.navigation.GetCamera(),i=this.upVector.SetDirection(e,r),n=t?this.settings.animationSteps:0;this.navigation.MoveCamera(i,n),this.Render()}FlipUpVector(){let e=this.navigation.GetCamera(),t=this.upVector.Flip(e);this.navigation.MoveCamera(t,0),this.Render()}Render(){let e=this.navigation.GetCamera();this.camera.position.set(e.eye.x,e.eye.y,e.eye.z),this.camera.up.set(e.up.x,e.up.y,e.up.z),this.camera.lookAt(new THREE.Vector3(e.center.x,e.center.y,e.center.z)),this.shading.UpdateByCamera(e),this.renderer.render(this.scene,this.camera)}SetMainObject(e){let t=zi(e);this.geometry.SetMainObject(e),this.shading.SetType(t),this.Render()}AddExtraObject(e){this.extraGeometry.AddObject(e),this.Render()}Clear(){this.geometry.Clear(),this.extraGeometry.Clear(),this.Render()}ClearExtra(){this.extraGeometry.Clear(),this.Render()}SetMeshesVisibility(e){this.geometry.EnumerateMeshes(t=>{let r=e(t.userData);t.visible!==r&&(t.visible=r)}),this.geometry.EnumerateEdges(t=>{let r=e(t.userData);t.visible!==r&&(t.visible=r)}),this.Render()}SetMeshesHighlight(e,t){function r(n,o){let l=[];for(let a=0;a{t(n.userData)?n.userData.threeMaterials===null&&(n.userData.threeMaterials=n.material,n.material=r(n.material,i)):n.userData.threeMaterials!==null&&(n.material=n.userData.threeMaterials,n.userData.threeMaterials=null)}),this.Render()}CreateHighlightMaterial(e){let t=this.geometry.edgeSettings.showEdges;return this.shading.CreateHighlightMaterial(e,t)}GetMeshUserDataUnderMouse(e){let t=this.GetMeshIntersectionUnderMouse(e);return t===null?null:t.object.userData}GetMeshIntersectionUnderMouse(e){let t=this.GetCanvasSize(),r=this.geometry.GetMeshIntersectionUnderMouse(e,this.camera,t.width,t.height);return r===null?null:r}GetBoundingBox(e){return this.geometry.GetBoundingBox(e)}GetBoundingSphere(e){return this.geometry.GetBoundingSphere(e)}EnumerateMeshesUserData(e){this.geometry.EnumerateMeshes(t=>{e(t.userData)})}InitNavigation(){this.camera=new THREE.PerspectiveCamera(45,this.canvas.width/this.canvas.height,.1,1e3),this.scene.add(this.camera);let e=this.renderer.domElement,t=Mi(S.Z);this.navigation=new Mr(e,t,{onUpdate:()=>{this.Render()}}),this.upVector=new bi}InitShading(){this.shading=new wi(this.scene)}GetShadingType(){return this.shading.type}GetImageSize(){let e=new THREE.Vector2;return this.renderer.getSize(e),{width:parseInt(e.x,10),height:parseInt(e.y,10)}}GetCanvasSize(){let e=this.canvas.width,t=this.canvas.height;return window.devicePixelRatio&&(e/=window.devicePixelRatio,t/=window.devicePixelRatio),{width:e,height:t}}GetImageAsDataUrl(e,t){let r=this.GetImageSize(),i=e,n=t;window.devicePixelRatio&&(i/=window.devicePixelRatio,n/=window.devicePixelRatio),this.ResizeRenderer(i,n),this.Render();let o=this.renderer.domElement.toDataURL();return this.ResizeRenderer(r.width,r.height),o}};var Si=class{constructor(e,t){this.parentElement=e,this.parameters={},xt(t)&&(this.parameters=t),this.canvas=document.createElement("canvas"),this.parentElement.appendChild(this.canvas),this.viewer=new wr,this.viewer.Init(this.canvas);let r=this.parentElement.clientWidth,i=this.parentElement.clientHeight;if(this.viewer.Resize(r,i),this.parameters.backgroundColor&&this.viewer.SetBackgroundColor(this.parameters.backgroundColor),this.parameters.edgeSettings&&this.viewer.SetEdgeSettings(this.parameters.edgeSettings.showEdges,this.parameters.edgeSettings.edgeColor,this.parameters.edgeSettings.edgeThreshold),this.parameters.environmentSettings){let n=this.parameters.environmentSettings.environmentMap,o=this.parameters.environmentSettings.backgroundIsEnvMap;this.viewer.SetEnvironmentMapSettings(n,o)}window.addEventListener("resize",()=>{this.Resize()})}LoadModelFromUrls(e){if(this.viewer.Clear(),e===null||e.length===0)return null;Dr(e);let t=new gr;this.parameters.defaultColor&&(t.defaultColor=this.parameters.defaultColor);let r=null;new Ir().LoadModel(e,Z.Url,t,{onLoadStart:()=>{this.canvas.style.display="none",r=document.createElement("div"),r.innerHTML="Loading model...",this.parentElement.appendChild(r)},onImportStart:()=>{r.innerHTML="Importing model..."},onVisualizationStart:()=>{r.innerHTML="Visualizing model..."},onModelFinished:(n,o)=>{this.parentElement.removeChild(r),this.canvas.style.display="inherit",this.viewer.SetMainObject(o);let l=this.viewer.GetBoundingSphere(a=>!0);this.viewer.AdjustClippingPlanesToSphere(l),this.parameters.camera?this.viewer.SetCamera(this.parameters.camera):this.viewer.SetUpVector(S.Y,!1),this.viewer.FitSphereToWindow(l,!1)},onTextureLoaded:()=>{this.viewer.Render()},onLoadError:n=>{let o="Unknown error";n.code===_e.NoImportableFile?o="No importable file found":n.code===_e.FailedToLoadFile?o="Failed to load file for import.":n.code===_e.ImportFailed&&(o="Failed to import model."),n.message!==null&&(o+=" ("+n.message+")"),r.innerHTML=o}})}GetViewer(){return this.viewer}Resize(){let e=this.parentElement.clientWidth,t=this.parentElement.clientHeight;this.viewer.Resize(e,t)}};function _i(s,e,t){let r=new Si(s,t);return r.LoadModelFromUrls(e),r}function Vn(s){function e(r){let i=null,n=r.getAttribute("camera");n&&(i=K.StringToCamera(n));let o=null,l=r.getAttribute("backgroundcolor");l&&(o=K.StringToColor(l));let a=null,u=r.getAttribute("defaultcolor");u&&(a=K.StringToColor(u));let h=null,f=r.getAttribute("edgesettings");f&&(h=K.StringToEdgeSettings(f));let d=null,c=r.getAttribute("environmentmap");if(c){let x=c.split(",");if(x.length===6){let g=!1,C=r.getAttribute("environmentmapbg");C&&C==="true"&&(g=!0),d={environmentMap:x,backgroundIsEnvMap:g}}}let p=null,m=r.getAttribute("model");return m&&(p=K.StringToModelUrls(m)),_i(r,p,{camera:i,backgroundColor:o,defaultColor:a,edgeSettings:h,environmentSettings:d})}let t=[];window.addEventListener("load",()=>{let r=document.getElementsByClassName("online_3d_viewer");for(let i=0;i