/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/three-svg-renderer@1.0.4/build/index.umd.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("three"),require("arrangement-2d-js"),require("isect"),require("fast-triangle-triangle-intersection"),require("@svgdotjs/svg.js"),require("opencv-ts"),require("three-mesh-halfedge"),require("three-mesh-bvh")):"function"==typeof define&&define.amd?define(["exports","three","arrangement-2d-js","isect","fast-triangle-triangle-intersection","@svgdotjs/svg.js","opencv-ts","three-mesh-halfedge","three-mesh-bvh"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).NPRRendering={},e.THREE,e.Arrangement2d,e.isect,e.FastTriangleTriangleIntersection,e.Svgdotjs,e.opencv,e.ThreeMeshHalfEdge,e.ThreeMeshBVH)}(this,(function(e,t,n,s,i,r,o,a,c){"use strict";function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d,u=l(n),h=l(o);e.ViewEdgeNature=void 0,(d=e.ViewEdgeNature||(e.ViewEdgeNature={})).Silhouette="Silhouette",d.Boundary="Boundary",d.MeshIntersection="MeshIntersection",d.Crease="Crease",d.Material="Material";const f=new Set([e.ViewEdgeNature.Silhouette,e.ViewEdgeNature.Boundary,e.ViewEdgeNature.MeshIntersection]);class p{halfedge;meshes=new Array;nature;faceAngle=1/0;isBack=!1;isConcave=!1;faces=new Array;a;b;constructor(e,t,n,s){this.a=e,this.b=t,this.nature=n,this.halfedge=s}get vertices(){return[this.a,this.b]}get from(){return this.a.pos2d}get to(){return this.b.pos2d}toJSON(){return{id:[...this.a.vertices].map((e=>e.id)).join(",")+"-"+[...this.b.vertices].map((e=>e.id)).join(",")}}clone(){const e=new p(this.a,this.b,this.nature,this.halfedge);return e.faceAngle=this.faceAngle,e.isBack=this.isBack,e.isConcave=this.isConcave,e.meshes.push(...this.meshes),e.faces.push(...this.faces),e}otherVertex(e){return e===this.a?this.b:this.a}hasVertex(e){return this.a===e||this.b===e}isConnectedTo(e){return this.hasVertex(e.a)||this.hasVertex(e.b)}}function w(e,n){e.geometry.hasAttribute("normal")||e.geometry.computeVertexNormals();const{morphedPositionAttribute:s,morphedNormalAttribute:i}=function(e){if(!0!==e.geometry.isBufferGeometry)return console.error("THREE.BufferGeometryUtils: Geometry is not of type BufferGeometry."),null;const n=new t.Vector3,s=new t.Vector3,i=new t.Vector3,r=new t.Vector3,o=new t.Vector3,a=new t.Vector3,c=new t.Vector3,l=new t.Vector3,d=new t.Vector3;function u(e,t,u,h,f,p,w,g){n.fromBufferAttribute(t,f),s.fromBufferAttribute(t,p),i.fromBufferAttribute(t,w);const y=e.morphTargetInfluences;if(u&&y){c.set(0,0,0),l.set(0,0,0),d.set(0,0,0);for(let e=0,t=u.length;e<t;e++){const t=y[e],g=u[e];0!==t&&(r.fromBufferAttribute(g,f),o.fromBufferAttribute(g,p),a.fromBufferAttribute(g,w),h?(c.addScaledVector(r,t),l.addScaledVector(o,t),d.addScaledVector(a,t)):(c.addScaledVector(r.sub(n),t),l.addScaledVector(o.sub(s),t),d.addScaledVector(a.sub(i),t)))}n.add(c),s.add(l),i.add(d)}e.isSkinnedMesh&&(e.boneTransform(f,n),e.boneTransform(p,s),e.boneTransform(w,i)),g[3*f+0]=n.x,g[3*f+1]=n.y,g[3*f+2]=n.z,g[3*p+0]=s.x,g[3*p+1]=s.y,g[3*p+2]=s.z,g[3*w+0]=i.x,g[3*w+1]=i.y,g[3*w+2]=i.z}const h=e.geometry,f=e.material;let p,w,g;const y=h.index,m=h.attributes.position,b=h.morphAttributes.position,x=h.morphTargetsRelative,v=h.attributes.normal,V=h.morphAttributes.position,S=h.groups,A=h.drawRange;let E,M,C,P,T,I,D;const N=new Float32Array(m.count*m.itemSize),B=new Float32Array(v.count*v.itemSize);if(null!==y)if(Array.isArray(f))for(E=0,C=S.length;E<C;E++)for(T=S[E],I=Math.max(T.start,A.start),D=Math.min(T.start+T.count,A.start+A.count),M=I,P=D;M<P;M+=3)p=y.getX(M),w=y.getX(M+1),g=y.getX(M+2),u(e,m,b,x,p,w,g,N),u(e,v,V,x,p,w,g,B);else for(I=Math.max(0,A.start),D=Math.min(y.count,A.start+A.count),E=I,C=D;E<C;E+=3)p=y.getX(E),w=y.getX(E+1),g=y.getX(E+2),u(e,m,b,x,p,w,g,N),u(e,v,V,x,p,w,g,B);else if(Array.isArray(f))for(E=0,C=S.length;E<C;E++)for(T=S[E],I=Math.max(T.start,A.start),D=Math.min(T.start+T.count,A.start+A.count),M=I,P=D;M<P;M+=3)p=M,w=M+1,g=M+2,u(e,m,b,x,p,w,g,N),u(e,v,V,x,p,w,g,B);else for(I=Math.max(0,A.start),D=Math.min(m.count,A.start+A.count),E=I,C=D;E<C;E+=3)p=E,w=E+1,g=E+2,u(e,m,b,x,p,w,g,N),u(e,v,V,x,p,w,g,B);return{positionAttribute:m,normalAttribute:v,morphedPositionAttribute:new t.Float32BufferAttribute(N,3),morphedNormalAttribute:new t.Float32BufferAttribute(B,3)}}(e);n.groups=[...e.geometry.groups],e.geometry.index&&(n.index=e.geometry.index.clone()),n.deleteAttribute("position"),n.deleteAttribute("normal"),n.setAttribute("position",s),n.setAttribute("normal",i)}const g=new t.Vector3;function y(e,t,n,s){return function(e,t,n){g.copy(e).project(n),t.set(g.x,g.y)}(e,t,n),function(e,t,n){t.set((e.x+1)/2*n.w,(1-e.y)/2*n.h)}(t,t,s),t}function m(e,t=1e10){const n=.001/t;return`${x(e.x+n,t)},${x(e.y+n,t)},${x(e.z+n,t)}`}function b(e,t=1e10){const n=.001/t;return`${x(e.x+n,t)},${x(e.y+n,t)}`}function x(e,t=1e10){return Math.trunc(e*t)}function v(e,t,n,s=!1,i=1e-10){const{x:r,y:o,z:a}=e.start,{x:c,y:l,z:d}=e.end,{x:u,y:h,z:f}=t.start,{x:p,y:w,z:g}=t.end,y=(r-u)*(p-u)+(o-h)*(w-h)+(a-f)*(g-f),m=(p-u)*(c-r)+(w-h)*(l-o)+(g-f)*(d-a),b=(p-u)*(p-u)+(w-h)*(w-h)+(g-f)*(g-f),x=((c-r)*(c-r)+(l-o)*(l-o)+(d-a)*(d-a))*b-m*m;if(x<i)return!1;const v=(y*m-((r-u)*(c-r)+(o-h)*(l-o)+(a-f)*(d-a))*b)/x,V=(y+v*m)/b;if(!s&&(v<0||v>1||V<0||V>1))return!1;const S=r+v*(c-r),A=o+v*(l-o),E=a+v*(d-a),M=u+V*(p-u),C=h+V*(w-h),P=f+V*(g-f);return Math.abs(S-M)<i&&Math.abs(A-C)<i&&Math.abs(E-P)<i&&(n.set(S,A,E),!0)}const V=new t.Matrix4;function S(e,t,n,s,i=1e-10){V.set(e.x,e.y,e.z,1,t.x,t.y,t.z,1,n.x,n.y,n.z,1,s.x,s.y,s.z,1);const r=V.determinant();return r>i?1:r<-i?-1:0}function A(e,t,n,s,i,r=1e-10){return S(e,t,n,s,r)>0==S(e,t,n,i,r)>0}function E(e,t=100){return Math.round(e*t)/t}var M,C;e.ViewVertexSingularity=void 0,(M=e.ViewVertexSingularity||(e.ViewVertexSingularity={})).None="None",M.ImageIntersection="ImageIntersection",M.MeshIntersection="MeshIntersection",M.CurtainFold="CurtainFold",M.Bifurcation="Bifurcation";class P{hash3d="";hash2d="";singularity=e.ViewVertexSingularity.None;vertices=new Set;pos3d=new t.Vector3;pos2d=new t.Vector2;viewEdges=new Array;visible=!1;commonViewEdgeWith(e){for(const t of this.viewEdges)if(e.viewEdges.includes(t))return t;return null}isConnectedTo(e){return null!=this.commonViewEdgeWith(e)}matches3dPosition(e,t=1e-10){return function(e,t,n=1e-10){return Math.abs(e.x-t.x)<n&&Math.abs(e.y-t.y)<n&&Math.abs(e.z-t.z)<n}(this.pos3d,e,t)}matches2dPosition(e,t=1e-10){return function(e,t,n=1e-10){return Math.abs(e.x-t.x)<n&&Math.abs(e.y-t.y)<n}(this.pos2d,e,t)}get x(){return this.pos2d.x}get y(){return this.pos2d.y}}e.ChainVisibility=void 0,(C=e.ChainVisibility||(e.ChainVisibility={})).Unknown="Unknown",C.Hidden="Hidden",C.Visible="Visible";class T{id;object;raycastPoint=new t.Vector2;edges=new Array;vertices=new Array;visibility=e.ChainVisibility.Unknown;constructor(e,t){this.id=e,this.object=t}get head(){return this.vertices[0]}get tail(){return this.vertices[this.vertices.length-1]}get size(){return this.vertices.length}get nature(){return this.edges[0].nature}middlePoint(){return this.vertices[Math.floor(this.vertices.length/2)]}middleEdge(){return 0===this.edges.length?null:this.edges[Math.floor(this.edges.length/2)]}addEdge(e){0==this.edges.length?(this.edges.push(e),this.vertices.push(e.a),this.vertices.push(e.b)):e.hasVertex(this.head)?(this.vertices.unshift(e.otherVertex(this.head)),this.edges.unshift(e)):e.hasVertex(this.tail)&&(this.vertices.push(e.otherVertex(this.tail)),this.edges.push(e))}}class I{id;mesh;color=new t.Color;insidePoint=new t.Vector2;contour;holes;constructor(e,t,n){this.id=e,this.contour=t,this.holes=n}}const D=u.default();class N{smallAreaIgnored=1/0;insidePointErrors=1/0}function B(e){const t=new Array;for(let n=0;n<e.size();n++)t.push(F(e.at(n)));return t}function F(e){const n=new Array;for(let s=0;s<e.size();s++){const i=e.at(s);n.push(new t.Vector2(i.x,i.y))}return n}function z(t,n,s,i){if(n.singularity!==e.ViewVertexSingularity.None)return null;for(const e of n.viewEdges){if(s.has(e)&&e.nature===t.nature&&e.meshes.includes(i))return e}return null}function G(t,n){const s=new Set;let i=!1,r=!1;for(const n of t.viewEdges)s.add(n.nature),n.faces.length>1&&n.nature===e.ViewEdgeNature.Silhouette&&(i||=n.isConcave,r||=!n.isConcave);return 0===s.size?(console.error("No natures found around vertex",t),e.ViewVertexSingularity.None):1===s.size&&t.viewEdges.length>2&&(s.has(e.ViewEdgeNature.Silhouette)||s.has(e.ViewEdgeNature.Boundary))?e.ViewVertexSingularity.Bifurcation:s.size>1&&(s.has(e.ViewEdgeNature.Silhouette)||s.has(e.ViewEdgeNature.Boundary)||s.has(e.ViewEdgeNature.MeshIntersection))?e.ViewVertexSingularity.MeshIntersection:i&&r||s.has(e.ViewEdgeNature.Boundary)&&function(e,t){for(const n of e.vertices){let e=null,s=null,i=-1/0;for(const r of H(n)){let o;o=r.vertex===n?r.next.vertex:r.vertex;const a=o.position.distanceTo(t.position);a>i&&(i=a,e=r,s=o)}if(e&&s){const i=t.position,r=n.position,o=s.position,a=e.twin.face;if(a){for(const e of n.loopCW())if(e.face!==a){const t=e.next.vertex.position,n=e.next.vertex.position;if(!A(r,t,n,i,o)&&A(i,r,t,o,n)&&A(i,r,n,o,t))return!0}}else console.error("Boundary halfedge twin has no connected face")}}return!1}(t,n)?e.ViewVertexSingularity.CurtainFold:e.ViewVertexSingularity.None}function*H(e){yield*e.boundaryHalfedgesInLoop(),yield*e.boundaryHalfedgesOutLoop()}function R(e,t){const{camera:n,viewVertexMap:s,renderSize:i}=e,r=m(t);let o=s.get(r);return o||(o=new P,o.pos3d.copy(t),y(t,o.pos2d,n,i),o.hash2d=b(o.pos2d),o.hash3d=r,s.set(r,o)),o}const k=new t.Vector3,O=new t.Vector3;function j(t,n,s){const i={nature:e.ViewEdgeNature.Silhouette,faceAngle:0,isConcave:!1,isBack:!1},r={creaseAngle:{min:80,max:100},...s};if(!t.face||!t.twin.face)return i.nature=e.ViewEdgeNature.Boundary,i;{const s=t.face.isFront(n.position),o=t.twin.face.isFront(n.position);if(i.isBack=!s&&!o,t.face.getNormal(k),t.twin.face.getNormal(O),i.faceAngle=180*Math.acos(k.dot(O))/Math.PI,i.isConcave=function(e,t,n,s,i=1e-10){return S(s,t,n,e,i)>0}(t.prev.vertex.position,t.vertex.position,t.next.vertex.position,t.twin.prev.vertex.position),s!==o)return i.nature=e.ViewEdgeNature.Silhouette,i;if(r.creaseAngle.min<=i.faceAngle&&i.faceAngle<=r.creaseAngle.max)return i.nature=e.ViewEdgeNature.Crease,i}return null}const L=new t.Vector3,W=new t.Vector3,U=new t.Vector3,$=new t.Vector2,_=new t.Vector2;function q(e,t,n){const s=m(n);if(t.a.matches3dPosition(n))return t.a.hash3d!==s&&console.log("Different hash",t.a,n,s),{viewVertex:t.a,viewEdge:null};if(t.b.matches3dPosition(n))return t.b.hash3d!==s&&console.log("Different hash",t.b,n,s),{viewVertex:t.b,viewEdge:null};L.subVectors(n,t.a.pos3d),W.subVectors(t.b.pos3d,t.a.pos3d);const i=L.cross(W),r=i.x+i.y+i.z;if(r>1e-10||r<-1e-10)return null;if(L.dot(W)<-1e-10)return null;if(L.length()>W.length())return null;const o=R(e,n);return{viewVertex:o,viewEdge:Z(e,t,o)}}function X(e,t,n){const s=b(n);if(t.a.matches2dPosition(n))return t.a.hash2d!==s&&console.log("Different hash",t.a,n,s),{viewVertex:t.a,viewEdge:null};if(t.b.matches2dPosition(n))return t.b.hash2d!==s&&console.log("Different hash",t.b,n,s),{viewVertex:t.b,viewEdge:null};$.subVectors(n,t.a.pos2d),_.subVectors(t.b.pos2d,t.a.pos2d);const i=$.cross(_);if(i>1e-10||i<-1e-10)return null;const r=$.length(),o=_.length();if(r>o)return null;if(L.dot(W)<-1e10)return null;U.lerpVectors(t.a.pos3d,t.b.pos3d,r/o);const a=R(e,U);return{viewVertex:a,viewEdge:Z(e,t,a)}}function Z(e,t,n){const s=t.b,i=t.clone();t.b=n,i.a=n,i.b=s,n.viewEdges.push(t),n.viewEdges.push(i),s.viewEdges.remove(t),s.viewEdges.push(i);for(const e of i.faces)e.viewEdges.push(i);return e.viewEdges.push(i),i}const J=new t.Vector2;class Y{assigned=1/0;nonAssigned=1/0}const K=new t.Color,Q=new t.Raycaster,ee=new t.Vector2;const te=new t.Raycaster,ne=new t.Vector3,se=new t.Vector3;class ie{nbTests=1/0;nbRaycasts=1/0}function re(t,n,s,i=1e-5){const r=t.middleEdge();if(!r)return console.error("Contour has no edges"),void(t.visibility=e.ChainVisibility.Visible);se.lerpVectors(r.a.pos3d,r.b.pos3d,.5),ne.subVectors(n.position,se).normalize(),te.firstHitOnly=!1,te.set(se,ne),t.raycastPoint.lerpVectors(r.a.pos2d,r.b.pos2d,.5);const o=te.intersectObjects(s,!1);let a=0;for(const e of o)a+=e.distance;t.visibility=a<i?e.ChainVisibility.Visible:e.ChainVisibility.Hidden}const oe=new t.Matrix4,ae=new t.Line3,ce=new Array;class le{name="";nbTests=1/0;nbIntersections=1/0;time=1/0}function de(e,t,n,s=new le){const r=Date.now();s.name=e.name+" ∩ "+t.name,s.nbTests=0,s.nbIntersections=0,oe.copy(e.matrixWorld).invert().multiply(t.matrixWorld),e.bvh.bvhcast(t.bvh,oe,{intersectsTriangles:(r,o,a,c)=>{if(s.nbTests+=1,null!==i.trianglesIntersect(r,o,ce)){if(s.nbIntersections+=1,1===ce.length)return!1;ce.length>2&&ce.push(ce[0]);for(let s=0;s<ce.length-1;s++)ae.start.copy(ce[s]),ae.end.copy(ce[s+1]),ae.distance()>1e-10&&(ae.applyMatrix4(e.matrixWorld),n(e,t,ae,e.hes.faces[a],t.hes.faces[c]))}return!1}}),s.time=Date.now()-r}const ue=new t.Line3,he=new t.Vector3,fe=new t.Vector3,pe=new t.Vector3;class we{details=new Array;nbTests=1/0;nbIntersections=1/0;nbMeshesTested=1/0;nbEdgesAdded=1/0}class ge{totalTime=1/0;times={updateGeometries:1/0,updateBVH:1/0,updateHES:1/0,setupEdges:1/0,find3dSingularities:1/0,find2dSingularities:1/0,computeChains:1/0,visibility:1/0,computePolygons:1/0,assignPolygons:1/0,worldTransform:1/0,meshIntersections:1/0,setupPoints:1/0,setupFaceMap:1/0};intersections=new we;visibility={nbTests:1/0,nbRaycasts:1/0};polygons={smallAreaIgnored:1/0,insidePointErrors:1/0,assigned:1/0,nonAssigned:1/0}}class ye{meshes=new Array;viewEdges=new Array;viewVertexMap=new Map;chains=new Array;polygons=new Array;camera=new t.PerspectiveCamera;renderSize={w:500,h:500};options={updateMeshes:!0,ignoreVisibility:!1,defaultMeshColor:5592405,creaseAngle:{min:80,max:100}};constructor(e){Object.assign(this.options,e)}clear(){this.meshes.clear(),this.viewEdges.clear(),this.viewVertexMap.clear(),this.chains.clear(),this.polygons.clear()}build(e,t,n,s=new ge,i){this.clear(),this.meshes.push(...e),this.camera.copy(t),this.camera.getWorldPosition(t.position),this.renderSize.w=n.w,this.renderSize.h=n.h;const r=this.setupActions(s);return s.totalTime=Date.now(),this.buildAsync(0,r,s,i)}buildAsync(e,t,n,s){return n.totalTime=Date.now(),new Promise((i=>{e<t.length?(s&&s({totalSteps:t.length,currentStep:e+1,currentStepName:t[e].name}),console.info(`Viewmap step ${e+1}/${t.length} : ${t[e].name}`),t[e].process().then((()=>{i(this.buildAsync(e+1,t,n,s))}))):(n.totalTime=Date.now()-n.totalTime,i())}))}setupActions(n=new ge){const i=new Array;return this.options.updateMeshes&&(i.push({name:"Update Morphed Geometries",process:async()=>{const e=Date.now();for(const e of this.meshes)e.updateMorphGeometry();n.times.updateGeometries=Date.now()-e}}),i.push({name:"Update BVH Structures",process:async()=>{const e=Date.now();for(const e of this.meshes)e.updateBVH(!1);n.times.updateBVH=Date.now()-e}}),i.push({name:"Update Halfedge Structures",process:async()=>{const e=Date.now();for(const e of this.meshes)e.updateHES(!1);n.times.updateHES=Date.now()-e}}),i.push({name:"Transform local 3d points into world",process:async()=>{const e=Date.now();for(const e of this.meshes)for(const t of e.hes.vertices)t.position.applyMatrix4(e.matrixWorld);n.times.worldTransform=Date.now()-e}})),i.push({name:"Setup viewmap edges",process:async()=>{const e=Date.now();!function(e,t){const{viewEdges:n,camera:s,meshes:i}=e,r=new Set;for(const o of i){for(const e of o.hes.faces)e.viewEdges=new Array;for(const i of o.hes.halfedges)if(!r.has(i.twin)){r.add(i);const a=j(i,s,t);if(a){const t=i.vertex,s=i.twin.vertex,r=R(e,t.position),c=R(e,s.position);t.viewVertex=r,s.viewVertex=c,r.vertices.add(t),c.vertices.add(s);const l=new p(r,c,a.nature,i);l.faceAngle=a.faceAngle,l.isConcave=a.isConcave,l.isBack=a.isBack,l.meshes.push(o),r.viewEdges.push(l),c.viewEdges.push(l),i.face&&(i.face.viewEdges.push(l),l.faces.push(i.face)),i.twin.face&&(i.twin.face.viewEdges.push(l),l.faces.push(i.twin.face)),n.push(l)}}}}(this,this.options),n.times.setupEdges=Date.now()-e}}),i.push({name:"Compute meshes intersections",process:async()=>{const t=Date.now();!function(t,n=new we){const{meshes:s}=t;n.nbMeshesTested=0,n.nbIntersections=0,n.nbTests=0,n.nbEdgesAdded=0;const i=(n,s,i,r,o)=>{const a=[R(t,i.start),R(t,i.end)],c=new Set([...r.viewEdges,...o.viewEdges]);for(const e of c)if(ue.set(e.a.pos3d,e.b.pos3d),v(ue,i,he)){const n=q(t,e,he);n?a.includes(n.viewVertex)||a.push(n.viewVertex):console.error("Intersection but split failed")}pe.subVectors(i.end,i.start),a.sort(((e,t)=>(pe.subVectors(t.pos3d,e.pos3d),pe.dot(fe))));for(let i=0;i<a.length-1;i++){const c=a[i],l=a[i+1],d=new p(c,l,e.ViewEdgeNature.MeshIntersection);d.meshes.push(n,s),d.faces.push(r,o),c.viewEdges.push(d),l.viewEdges.push(d),r.viewEdges.push(d),o.viewEdges.push(d),t.viewEdges.push(d)}};for(let e=0;e<s.length-1;e++)for(let t=e+1;t<s.length;t++){const r=s[e],o=s[t],a=new le;de(r,o,i,a),n.nbIntersections+=a.nbIntersections,n.nbTests+=a.nbTests,n.nbMeshesTested+=1,n.details.push(a)}}(this,n.intersections),n.times.meshIntersections=Date.now()-t}}),i.push({name:"Find singularities in the 3d space",process:async()=>{const e=Date.now();!function(e){const{viewVertexMap:t,camera:n}=e;for(const[,e]of t)e.singularity=G(e,n)}(this),n.times.find3dSingularities=Date.now()-e}}),i.push({name:"Find singularities in the 2d space",process:async()=>{const t=Date.now();!function(t){const{viewEdges:n}=t;let i=s.bush([...n]).run();i=i.filter((({segments:[e,t]})=>!e.isConnectedTo(t)&&(f.has(e.nature)||f.has(t.nature))));const r=new Map;for(const n of i){const s=[];J.set(n.point.x,n.point.y);const i=b(J);for(const e of n.segments){let n=r.get(e);n||(n=[e],r.set(e,n));let o=0,a=null;for(;o<n.length&&null===a;)a=X(t,n[o],J),o+=1;a?(s.push(a.viewVertex),a.viewVertex.pos2d.copy(J),a.viewVertex.hash2d=i,a.viewEdge&&n.push(a.viewEdge)):console.error("Image intersection -- Edge could not be splitted",n,J)}if(0===s.length)console.error("Image intersection -- Should have 2 split vertices");else if(1===s.length)s[0].singularity=e.ViewVertexSingularity.ImageIntersection;else{const n=s[0],i=s[1],r=n.pos3d.distanceTo(t.camera.position),o=i.pos3d.distanceTo(t.camera.position);r>o+1e-10?n.singularity=e.ViewVertexSingularity.ImageIntersection:(o>r+1e-10||(n.singularity=e.ViewVertexSingularity.ImageIntersection),i.singularity=e.ViewVertexSingularity.ImageIntersection)}}}(this),n.times.find2dSingularities=Date.now()-t}}),i.push({name:"Create chains",process:async()=>{const e=Date.now();!function(e){const{viewEdges:t,chains:n}=e,s=new Set(t);let i=0;for(;s.size>0;){const[e]=s,t=e.meshes[0],r=new T(i,t);s.delete(e),r.addEdge(e);for(const n of e.vertices){let i=n,o=z(e,i,s,t);for(;o;)s.delete(o),r.addEdge(o),i=o.otherVertex(i),o=z(o,i,s,t)}n.push(r),i+=1}}(this),n.times.computeChains=Date.now()-e}}),i.push({name:"Compute chains visibility",process:async()=>{if(this.options.ignoreVisibility)this.chains.map((t=>t.visibility=e.ChainVisibility.Visible));else{const e=Date.now(),s=new ie;!function(e,n=new ie){const{chains:s,meshes:i,camera:r}=e,o=i.map((e=>e.threeMesh));n.nbRaycasts=0,n.nbTests=0;const a=new Map;for(const e of i)if(Array.isArray(e.material))for(const n of e.material)a.set(n,n.side),n.side=t.DoubleSide;else a.set(e.material,e.material.side),e.material.side=t.DoubleSide;for(const e of s)n.nbTests+=1,re(e,r,o),n.nbRaycasts+=1;for(const e of i)if(Array.isArray(e.material))for(const t of e.material)t.side=a.get(t)??t.side;else e.material.side=a.get(e.material)??e.material.side}(this,s),n.visibility.nbRaycasts=s.nbRaycasts,n.visibility.nbTests=s.nbTests,n.times.visibility=Date.now()-e}}}),i.push({name:"Compute polygons",process:async()=>{const t=Date.now(),s=new N;await async function(t,n=new N){const{chains:s,polygons:i}=t,r=await D,o=s.filter((t=>t.visibility===e.ChainVisibility.Visible)),a=new r.PointList;let c,l;for(const e of o){c=new r.Point(e.vertices[0].pos2d.x,e.vertices[0].pos2d.y);for(let t=1;t<e.vertices.length;t++)l=new r.Point(e.vertices[t].pos2d.x,e.vertices[t].pos2d.y),a.push_back(c),a.push_back(l),c=l}const d=(new r.ArrangementBuilder).getPolygons(a),u=new r.Point;n.smallAreaIgnored=0,n.insidePointErrors=0;for(let e=0;e<d.size();e++){const t=d.at(e);if(t.getPolyTristripArea()>1e-10){const s=F(t.contour),r=B(t.holes),o=new I(e,s,r);t.getInsidePoint(u)?(o.insidePoint.set(u.x,u.y),i.push(o)):n.insidePointErrors+=1}else n.smallAreaIgnored+=1;r.destroy(t)}r.destroy(d),r.destroy(u)}(this,s),n.polygons.smallAreaIgnored=s.smallAreaIgnored,n.polygons.insidePointErrors=s.insidePointErrors,n.times.computePolygons=Date.now()-t}}),i.push({name:"Assign Polygons",process:async()=>{const e=Date.now(),t=new Y;!function(e,t,n=new Y){t={defaultMeshColor:3355443,...t},K.set(t.defaultMeshColor),n.assigned=0,n.nonAssigned=0;const{meshes:s,renderSize:i,camera:r,polygons:o}=e,a=new Map,c=new Array;for(const e of s)a.set(e.threeMesh,e),c.push(e.threeMesh);for(const e of o){l=e.insidePoint,d=i,ee.set(2/d.w*l.x-1,1-2/d.h*l.y),Q.setFromCamera(ee,r),Q.firstHitOnly=!0;const t=Q.intersectObjects(c,!1);if(t.length>0){const s=t[0],i=s.faceIndex;if(void 0!==i){const t=s.object;e.mesh=a.get(t),e.mesh?(e.color.copy(e.mesh.colorForFaceIndex(i)||K),n.assigned+=1):console.error(`Could not associate SVG mesh to polygon ${e.id}`)}else console.error(`Polygon ${e.id} intersection has no face index`,s)}}var l,d;n.nonAssigned=o.length-n.assigned}(this,this.options,t),n.polygons.assigned=t.assigned,n.polygons.nonAssigned=t.nonAssigned,n.times.assignPolygons=Date.now()-e}}),i}visibleChains(){return this.chains.filter((t=>t.visibility===e.ChainVisibility.Visible))}hiddenChains(){return this.chains.filter((t=>t.visibility===e.ChainVisibility.Hidden))}}r.extend(r.Shape,{toPath(e=!0){var t;switch(this.type){case"rect":{let{width:e,height:n,rx:s,ry:i,x:r,y:o}=this.attr(["width","height","rx","ry","x","y"]);s<0&&(s=0),i<0&&(i=0),s=s||i,i=i||s,s>e/2&&(s=e/2),i>n/2&&(i=n/2),t=s&&i?[["M",s+r,o],["h",e-2*s],["a",s,i,0,0,1,s,i],["v",n-2*i],["a",s,i,0,0,1,-s,i],["h",2*s-e],["a",s,i,0,0,1,-s,-i],["v",2*i-n],["a",s,i,0,0,1,s,-i],["z"]]:[["M",r,o],["h",e],["v",n],["h",-e],["v",-n],["z"]];break}case"circle":case"ellipse":{let e=this.rx(),n=this.ry(),{cx:s,cy:i}=this.attr(["cx","cy"]);t=[["M",s-e,i],["A",e,n,0,0,0,s+e,i],["A",e,n,0,0,0,s-e,i],["z"]];break}case"polygon":case"polyline":case"line":(t=this.array().map((function(e){return["L"].concat(e)})))[0][0]="M","polygon"===this.type&&t.push("Z");break;case"path":t=this.array();break;default:throw new Error("SVG toPath got unsupported type "+this.type,this)}const n=(new r.Path).plot(t).attr((e=>{for(const t in e)/fill|stroke|opacity|transform/.test(t)||delete e[t];return e})(this.attr()));return e&&this.replace(n),n}});class me{totalTime=1/0;passesInfo=new Array}class be{options={prettifySVG:!1};passes=new Array;constructor(e){Object.assign(this.options,e)}async drawSVG(e,t,n=new me){const s=Date.now(),i=new r.Svg;i.width(t.w),i.height(t.h);for(let t=0;t<this.passes.length;t++){const s=this.passes[t];if(s.enabled){const r=Date.now();await s.draw(i,e),n.passesInfo.push({name:s.name,order:t,time:Date.now()-r})}}return n.totalTime=Date.now()-s,i}}class xe{name;enabled=!0;constructor(){this.name=this.constructor.name}}function ve(e,t,n,s={},i={},o={}){const a=new r.Text;return a.text(e),a.x(t),a.y(n),a.font(s),a.stroke(i),a.fill(o),a}function Ve(e,t,n,s,i){const o=new r.Path;let a=Se(e,n);for(const e of t)a=a.concat(Se(e,n));return o.plot(new r.PathArray(a)),s?o.stroke(s):o.stroke("none"),i?o.fill({...i,rule:"evenodd"}):o.fill("none"),o}function Se(e,t=!0){const n=new Array;let s;if(e.length>0){s=e[0],n.push(["M",E(s.x),E(s.y)]);for(let t=1;t<e.length;t++)s=e[t],n.push(["L",E(s.x),E(s.y)]);t&&n.push(["Z"])}return n}function Ae(e,t,n,s={},i={}){const o=new r.Circle;return o.center(e,t),o.radius(n),o.stroke(s),o.fill(i),o}const Ee=["x","y","width","height","viewbox","cx","cy","rw","rx","points"];function Me(e){const t=e.toPath(!0),n=e.attr();for(const e in n)Ee.includes(e)||t.attr(e,n[e]);return t}function Ce(e){switch(typeof e){case"number":return e;case"string":return Number(e);case typeof r.Number:return e.value}return 0}function Pe(e,t){for(const n of Object.keys(t))t[n]instanceof Object&&Object.assign(t[n],Pe(e[n],t[n]));return Object.assign(e||{},t),e}function Te(e,t,n){const s={...n.fillStyle};n.useFixedStyle||(s.color="#"+t.color.getHexString()),n.useRandomColors&&(s.color=r.Color.random().toString());const i=Ve(t.contour,t.holes,!0,{},s);i.id("fill-"+t.id),e.add(i),n.drawRaycastPoint&&function(e,t){const n={color:"black"},s={color:"white"},i=t.insidePoint.x,r=t.insidePoint.y,o=Ae(i,r,2,n,s);o.id("raycast-point"),e.add(o)}(e,t)}const Ie=Object.values(e.ViewVertexSingularity).filter((t=>t!==e.ViewVertexSingularity.None)),De={[e.ViewVertexSingularity.None]:"",[e.ViewVertexSingularity.ImageIntersection]:"green",[e.ViewVertexSingularity.MeshIntersection]:"red",[e.ViewVertexSingularity.CurtainFold]:"blue",[e.ViewVertexSingularity.Bifurcation]:"orange"};let Ne,Be;const Fe=new Promise((e=>{h.default.onRuntimeInitialized=()=>{Ne=h.default.matFromArray(1,1,h.default.CV_32FC2,[0,0]),Be=h.default.matFromArray(1,1,h.default.CV_32FC2,[0,0]),e()}}));async function ze(e){const t=document.createElement("img");t.src=e.texture.url;const n=h.default.imread(t),s={x:0,y:0,w:n.cols,h:n.rows},{matrix:i,outRect:o}=He(s,e),a=new h.default.Mat,c=new h.default.Size(o.w,o.h);h.default.warpPerspective(n,a,i,c,h.default.INTER_LINEAR);const l=document.createElement("canvas");return h.default.imshow(l,a),n.delete(),a.delete(),new Promise(((e,t)=>{l.toBlob((n=>{if(n){const t=new FileReader;t.onloadend=()=>{const n=function(e,t){const n=new r.Image;return n.load(e),n.x(t.x),n.y(t.y),n.width(t.w),n.height(t.h),n}(t.result,o);e(n)},t.readAsDataURL(n)}else t("Error blob conversion from opencv canvas")}))}))}async function Ge(e){return new Promise(((t,n)=>{var s;(s=e.texture.url,new Promise(((e,t)=>{s.startsWith("data:image/svg+xml;base64,")?fetch(s).then((n=>{n.blob().then((n=>{const s=new FileReader;s.onloadend=()=>{e(s.result)},s.onerror=()=>{t("Couldn't read content")},s.readAsText(n)})).catch((()=>{t("Couldn't create blob")}))})).catch((()=>{t("Couldn't fetch data ")})):t("Data not svg xml based")}))).then((n=>{const s=r.SVG().svg(n),i=new r.G({id:"svg-interface-"+e.name});for(const t of s.children()){try{const n=new Array;Re(t,e,void 0,n),console.info(`SVG Transform: ${n.length} elements ignored.`,n)}catch(e){console.error("Error while transforming SVG",e)}i.add(t)}t(i)})).catch((e=>{n("Couldn't retrieved svg content from base64 dataURL: "+e)}))}))}function He(e,t){let n=1/0,s=1/0,i=-1/0,r=-1/0;const o=[e.x,e.y,e.x,e.y+e.h,e.x+e.w,e.y,e.x+e.w,e.y+e.h],a=new Array,c=Array.from(t.hes.vertices).map((e=>e.viewVertex));for(const e of c)n=Math.min(n,e.x),s=Math.min(s,e.y),i=Math.max(i,e.x),r=Math.max(r,e.y),a.push(e.x),a.push(e.y);for(let e=0;e<8;e+=2)a[e]-=n,a[e+1]-=s;const l=h.default.matFromArray(4,1,h.default.CV_32FC2,o),d=h.default.matFromArray(4,1,h.default.CV_32FC2,a),u=h.default.getPerspectiveTransform(l,d,h.default.DECOMP_LU);return l.delete(),d.delete(),{matrix:u,outRect:{x:n,y:s,w:i-n,h:r-s}}}function Re(e,t,n,s){if("svg"===e.type){const s=e;let i={x:Ce(s.x()),y:Ce(s.y()),w:Ce(s.width()),h:Ce(s.height())};const r=s.viewbox();if(0!==r.height&&0!==r.width&&(i={x:r.x,y:r.y,w:r.width,h:r.height}),0===i.w||0===i.h)throw"Embedded SVG has no visible dimension: i.e no width/height or viewbox properties.";const{matrix:o,outRect:a}=He(i,t);s.x(a.x),s.y(a.y),s.width(a.w),s.height(a.h),s.attr("viewBox",null),n=o}else"polygon"===e.type||"rect"===e.type||"ellipse"===e.type||"circle"===e.type?e=Me(e):"path"!==e.type&&"g"!==e.type&&s?.push(e);if("svg"!==e.type&&!n)throw"There is no perspective transform matrix or it hasn't been initialized.";if(n&&"path"===e.type){!function(e,t){const n=e.array(),s=new Array,i={x:0,y:0};let o,a,c;for(let e=0;e<n.length;e++){const r=n[e],l=r[0];switch(l){case"H":o=ke(r[1],i.y,t),s.push(["L",E(o.x),E(o.y)]),i.x=r[1];break;case"V":o=ke(i.x,r[1],t),s.push(["L",E(o.x),E(o.y)]),i.y=r[1];break;case"M":case"L":o=ke(r[1],r[2],t),s.push([l,E(o.x),E(o.y)]),i.x=r[1],i.y=r[2];break;case"C":o=ke(r[1],r[2],t),a=ke(r[3],r[4],t),c=ke(r[5],r[6],t),s.push([l,E(o.x),E(o.y),E(a.x),E(a.y),E(c.x),E(c.y)]),i.x=r[5],i.y=r[6];break;case"Z":s.push(["Z"]);break;default:console.info("Unsupported SVG path command",l)}}e.plot(new r.PathArray(s))}(e,n)}for(const i of e.children())Re(i,t,n,s);"svg"===e.type&&n&&n.delete()}function ke(e,t,n){return Ne.data32F[0]=e,Ne.data32F[1]=t,h.default.perspectiveTransform(Ne,Be,n),{x:Be.data32F[0],y:Be.data32F[1]}}const Oe=Object.values(e.ViewEdgeNature);class je extends xe{options={drawRaycastPoint:!1,useRandomColors:!1,drawLegend:!1,defaultStyle:{color:"#000000",width:1,dasharray:"",linecap:"butt",linejoin:"miter",opacity:1,dashoffset:0},styles:{[e.ViewEdgeNature.Silhouette]:{enabled:!0,drawOrder:5},[e.ViewEdgeNature.Boundary]:{enabled:!0,drawOrder:4},[e.ViewEdgeNature.MeshIntersection]:{enabled:!0,drawOrder:3},[e.ViewEdgeNature.Crease]:{enabled:!0,drawOrder:2},[e.ViewEdgeNature.Material]:{enabled:!0,drawOrder:1}}};constructor(e={}){super(),Pe(this.options,e)}}function Le(e,t,n,s){const{defaultStyle:i,styles:o}=s;Oe.sort(((e,t)=>(o[e].drawOrder??0)-(o[t].drawOrder??0)));for(const a of t){const t=n.filter((e=>e.object===a)),c=new r.G({id:a.name});e.add(c);for(const e of Oe)if(o[e]?.enabled){const n={...i,...o[e]},a=t.filter((t=>t.nature===e)),l=new r.G({id:e});c.add(l);for(const e of a)We(l,e,s,n)}}s.drawLegend&&e.add(function(e){const t=new r.G({id:"edges-nature-legend"});t.add(ve("Natures",10,140,{size:15,anchor:"start"}));let n=170;for(const s of Oe){const i=e.styles[s].color??"black";t.add(Ae(15,n,8,{color:"black"},{color:i})),t.add(ve(s,30,n-10,{size:15,anchor:"start"})),n+=20}return t}(s))}function We(e,t,n,s={}){s={...s},n.useRandomColors&&(s.color=r.Color.random().toString());const i=Ve(t.vertices,[],!1,s);e.add(i),n.drawRaycastPoint&&function(e,t){const n={color:"black"},s={color:"white"},i=t.raycastPoint.x,r=t.raycastPoint.y,o=Ae(i,r,2,n,s);o.id("raycast-point"),e.add(o)}(e,t)}function Ue(e){return e.color}var $e,_e;function qe(){if(_e)return $e;return _e=1,$e=function(e,t={}){function n(){return r()||function(){const e=c(/^([^<]+)/);if(e){const n={type:"Text",content:e[1]};return{excluded:!1===t.filter(n),node:n}}}()||o()||function(){if(e.startsWith("<![CDATA[")){const n=e.indexOf("]]>");if(n>-1){const s=n+3,i={type:"CDATA",content:e.substring(0,s)};return e=e.slice(s),{excluded:!1===t.filter(i),node:i}}}}()}function s(){return c(/\s*/),r(!0)||o()||function(){const e=c(/^<!DOCTYPE\s+[^>]*>/);if(e){const n={type:"DocumentType",content:e[0]};return{excluded:!1===t.filter(n),node:n}}}()||i(!1)}function i(e){const n=c(e?/^<\?(xml)\s*/:/^<\?([\w-:.]+)\s*/);if(!n)return;const s={name:n[1],type:"ProcessingInstruction",attributes:{}};for(;!l()&&!d("?>");){const e=a();if(!e)return s;s.attributes[e.name]=e.value}return c(/\?>/),{excluded:!e&&!1===t.filter(s),node:s}}function r(e){const s=c(/^<([\w-:.]+)\s*/);if(!s)return;const i={type:"Element",name:s[1],attributes:{},children:[]};for(;!(l()||d(">")||d("?>")||d("/>"));){const e=a();if(!e)return i;i.attributes[e.name]=e.value}const r=!e&&!1===t.filter(i);if(c(/^\s*\/>/))return i.children=null,{excluded:r,node:i};if(c(/\??>/),!r){let e=n();for(;e;)e.excluded||i.children.push(e.node),e=n()}return c(/^<\/[\w-:.]+>/),{excluded:r,node:i}}function o(){const e=c(/^<!--[\s\S]*?-->/);if(e){const n={type:"Comment",content:e[0]};return{excluded:!1===t.filter(n),node:n}}}function a(){const e=c(/([\w-:.]+)\s*=\s*("[^"]*"|'[^']*'|\w+)\s*/);var t;if(e)return{name:e[1],value:(t=e[2],t.replace(/^['"]|['"]$/g,""))}}function c(t){const n=e.match(t);if(n)return e=e.slice(n[0].length),n}function l(){return 0===e.length}function d(t){return 0===e.indexOf(t)}return t.filter=t.filter||(()=>!0),e=e.trim(),function(){const e=i(!0),t=[];let n,r=s();for(;r;){if("Element"===r.node.type){if(n)throw new Error("Found multiple root nodes");n=r.node}r.excluded||t.push(r.node),r=s()}if(!n)throw new Error("Failed to parse XML");return{declaration:e?e.node:null,root:n,children:t}}()}}function Xe(e){if(!e.options.indentation&&!e.options.lineSeparator)return;let t;for(e.content+=e.options.lineSeparator,t=0;t<e.level;t++)e.content+=e.options.indentation}function Ze(e,t){e.content+=t}function Je(e,t,n){if("string"==typeof e.content)!function(e,t,n){n||(e.content=e.content.trim());e.content.length>0&&(!n&&t.content.length>0&&Xe(t),Ze(t,e.content))}(e,t,n);else if("Element"===e.type)!function(e,t,n){!n&&t.content.length>0&&Xe(t);if(Ze(t,"<"+e.name),Ye(t,e.attributes),null===e.children){const e=t.options.whiteSpaceAtEndOfSelfclosingTag?" />":"/>";Ze(t,e)}else if(0===e.children.length)Ze(t,"></"+e.name+">");else{Ze(t,">"),t.level++;let s="preserve"===e.attributes["xml:space"];if(!s&&t.options.collapseContent){let t=!1,n=!1,i=!1;e.children.forEach((function(s,r){"Text"===s.type?(s.content.includes("\n")?(n=!0,s.content=s.content.trim()):0!==r&&r!==e.children.length-1||0===s.content.trim().length&&(s.content=""),s.content.length>0&&(t=!0)):"CDATA"===s.type?t=!0:i=!0})),!t||i&&n||(s=!0)}e.children.forEach((function(e){Je(e,t,n||s,t.options)})),t.level--,n||s||Xe(t),Ze(t,"</"+e.name+">")}}(e,t,n);else{if("ProcessingInstruction"!==e.type)throw new Error("Unknown node type: "+e.type);Ke(e,t)}}function Ye(e,t){Object.keys(t).forEach((function(n){const s=t[n].replace(/"/g,"&quot;");Ze(e," "+n+'="'+s+'"')}))}function Ke(e,t){t.content.length>0&&Xe(t),Ze(t,"<?"+e.name),Ye(t,e.attributes),Ze(t,"?>")}var Qe=function(e,t={}){t.indentation="indentation"in t?t.indentation:"    ",t.collapseContent=!0===t.collapseContent,t.lineSeparator="lineSeparator"in t?t.lineSeparator:"\r\n",t.whiteSpaceAtEndOfSelfclosingTag=!!t.whiteSpaceAtEndOfSelfclosingTag;const n=qe()(e,{filter:t.filter}),s={content:"",level:0,options:t};return n.declaration&&Ke(n.declaration,s),n.children.forEach((function(e){Je(e,s,!1)})),s.content.replace(/\r\n/g,"\n").replace(/\n/g,t.lineSeparator)};class et{resolution={w:1/0,h:1/0};renderingTime=1/0;svgDrawInfo=new me;viewmapInfo=new ge}e.Chain=T,e.ChainPass=je,e.DrawPass=xe,e.FillPass=class extends xe{options={drawRaycastPoint:!1,useRandomColors:!1,useFixedStyle:!1,fillStyle:{color:"#333333",opacity:1}};constructor(e={}){super(),Pe(this.options,e)}async draw(e,t){const n=new r.G({id:"fills"});e.add(n);for(const e of t.meshes)if(e.drawFills){const s=t.polygons.filter((t=>t.mesh===e)),i=new r.G({id:e.name});n.add(i);for(const e of s)Te(n,e,this.options)}}},e.HiddenChainPass=class extends je{constructor(e={}){const{defaultStyle:t,...n}=e;super(e={defaultStyle:{color:"#FF0000",dasharray:"2,2",...t},...n})}async draw(t,n){const s=n.chains.filter((t=>t.visibility===e.ChainVisibility.Hidden)),i=Array.from(n.meshes).filter((e=>e.drawHiddenContours)),o=new r.G({id:"hidden-contours"});t.add(o),Le(o,i,s,this.options)}},e.Polygon=I,e.SVGDrawHandler=be,e.SVGDrawInfo=me,e.SVGMesh=class{sourceMesh;threeMesh=new t.Mesh;hes;bvh;drawFills=!0;drawVisibleContours=!0;drawHiddenContours=!0;isUsingBVHForRaycasting=!1;texture;constructor(e,t={}){this.sourceMesh=e,this.threeMesh.copy(e),this.threeMesh.geometry=this.sourceMesh.geometry.clone(),this.hes=new a.HalfedgeDS;const n={maxLeafTris:1,strategy:c.CENTER,...t?.bvhOptions};this.bvh=new c.MeshBVH(this.threeMesh.geometry,n),this.threeMesh.raycast=c.acceleratedRaycast,this.threeMesh.geometry.boundsTree=this.bvh}addTexture(e){this.texture=e}updateMorphGeometry(){w(this.sourceMesh,this.threeMesh.geometry)}updateBVH(e=!0){e&&this.updateMorphGeometry(),this.bvh.refit()}updateHES(e=!0){e&&this.updateMorphGeometry(),this.hes.setFromGeometry(this.threeMesh.geometry)}localToWorld(e){return this.threeMesh.localToWorld(e)}colorForFaceIndex(e){if(Array.isArray(this.material)){for(const t of this.threeMesh.geometry.groups)if(t.start<=e&&e<t.start+t.count&&null!=t.materialIndex&&t.materialIndex<this.material.length)return Ue(this.material[t.materialIndex]);return null}return Ue(this.material)}dispose(){!function(e){if(e.geometry.dispose(),e.material instanceof Array){const t=e.material;for(const e of t)e.dispose()}else e.material.dispose()}(this.threeMesh)}get material(){return this.threeMesh.material}get matrixWorld(){return this.threeMesh.matrixWorld}get name(){return this.threeMesh.name}set name(e){this.threeMesh.name=e}},e.SVGRenderInfo=et,e.SVGRenderer=class{viewmap;drawHandler;constructor(e,t){this.viewmap=new ye(e),this.drawHandler=new be(t)}async generateSVG(e,t,n,s=new et){const i=Date.now(),r={w:n.w,h:n.w/t.aspect};s.resolution=r,await this.viewmap.build(e,t,r,s.viewmapInfo);const o=await this.drawHandler.drawSVG(this.viewmap,r,s.svgDrawInfo);return s.renderingTime=Date.now()-i,o}addPass(e){this.drawHandler.passes.includes(e)||this.drawHandler.passes.push(e)}removePass(e){this.drawHandler.passes.remove(e)}clearPasses(){this.drawHandler.passes.clear()}static exportSVG(e,t,n){const s={prettify:!1,...n};let i=e.svg();s.prettify&&(i=Qe(i,{}));const r=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),o=URL.createObjectURL(r),a=document.createElement("a");a.href=o,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a)}},e.SingularityPointPass=class extends xe{options={drawVisiblePoints:!0,drawHiddenPoints:!1,drawLegend:!0,pointSize:2};constructor(e={}){super(),Object.assign(this.options,e)}async draw(t,n){for(const t of n.chains)for(const n of t.vertices)n.visible=n.visible||t.visibility===e.ChainVisibility.Visible;const s=[];this.options.drawVisiblePoints&&s.push(!0),this.options.drawHiddenPoints&&s.push(!1);const i=new r.G({id:"singularity-points"});t.add(i);const o={color:"black"},a={color:""},c=Array.from(n.viewVertexMap.values()).filter((t=>t.singularity!=e.ViewVertexSingularity.None));for(const e of s){const t=new r.G({id:e?"visible":"hidden"});i.add(t);for(const n of Ie){const s=c.filter((t=>t.singularity===n&&t.visible===e)),i=new r.G({id:n});t.add(i),a.color=De[n];for(const e of s){const t=Ae(e.pos2d.x,e.pos2d.y,this.options.pointSize,o,a);i.add(t)}}}this.options.drawLegend&&i.add(function(){const e=new r.G({id:"singularity-legend"});e.add(ve("Singularities",10,10,{size:15,anchor:"start"}));let t=40;for(const n of Ie){const s=De[n];e.add(Ae(15,t,8,{color:"black"},{color:s})),e.add(ve(n,30,t-10,{size:15,anchor:"start"})),t+=20}return e}())}},e.TexturePass=class extends xe{async draw(e,t){const{meshes:n,polygons:s}=t,i=new Array;for(const e of n)e.texture&&(e.hes&&4===e.hes.vertices.length&&2===e.hes.faces.length?i.push(e):console.warn(`Mesh "${e.name}": Texture ignored, not a plane geometry.`));if(0===i.length)return;await Fe;const o=new r.G({id:"textures"});e.add(o);const a=new Map;for(const e of i)a.set(e,[]);for(const e of s)e.mesh&&a.has(e.mesh)&&a.get(e.mesh)?.push(e);for(const e of i){let t;t=e.texture.url.startsWith("data:image/svg+xml;base64,")?await Ge(e):await ze(e);const n=new r.ClipPath,s=a.get(e)??[];for(const e of s){const t=Ve(e.contour,e.holes,!0);n.add(t)}o.add(n),t.clipWith(n),o.add(t)}}},e.ViewEdge=p,e.ViewVertex=P,e.Viewmap=ye,e.ViewmapBuildInfo=ge,e.VisibleChainPass=class extends je{constructor(e={}){super(e)}async draw(t,n){const s=n.chains.filter((t=>t.visibility===e.ChainVisibility.Visible)),i=Array.from(n.meshes).filter((e=>e.drawVisibleContours)),o=new r.G({id:"visible-contours"});Le(o,i,s,this.options),t.add(o)}},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=/sm/ae21e419611c04db59bd32adca52a30158c66c0d2d88b46ee15cfd47cb821f5d.map