poly-extrude 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  /*!
2
- * poly-extrude v0.4.0
2
+ * poly-extrude v0.6.0
3
3
  */
4
- !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).polyextrude=t.polyextrude||{})}(this,(function(t){"use strict";var n={exports:{}};function r(t,n,r){r=r||2;var e,o,h,a,u,x,v,f=n&&n.length,y=f?n[0]*r:t.length,d=i(t,0,y,r,!0),g=[];if(!d||d.next===d.prev)return g;if(f&&(d=function(t,n,r,e){var s,o,h,a=[];for(s=0,o=n.length;s<o;s++)(h=i(t,n[s]*e,s<o-1?n[s+1]*e:t.length,e,!1))===h.next&&(h.steiner=!0),a.push(p(h));for(a.sort(c),s=0;s<a.length;s++)r=l(a[s],r);return r}(t,n,d,r)),t.length>80*r){e=h=t[0],o=a=t[1];for(var z=r;z<y;z+=r)(u=t[z])<e&&(e=u),(x=t[z+1])<o&&(o=x),u>h&&(h=u),x>a&&(a=x);v=0!==(v=Math.max(h-e,a-o))?32767/v:0}return s(d,g,r,e,o,v,0),g}function i(t,n,r,i,e){var s,o;if(e===V(t,n,r,i)>0)for(s=n;s<r;s+=i)o=P(s,t[s],t[s+1],o);else for(s=r-i;s>=n;s-=i)o=P(s,t[s],t[s+1],o);return o&&g(o,o.next)&&(S(o),o=o.next),o}function e(t,n){if(!t)return t;n||(n=t);var r,i=t;do{if(r=!1,i.steiner||!g(i,i.next)&&0!==d(i.prev,i,i.next))i=i.next;else{if(S(i),(i=n=i.prev)===i.next)break;r=!0}}while(r||i!==n);return n}function s(t,n,r,i,c,l,x){if(t){!x&&l&&function(t,n,r,i){var e=t;do{0===e.z&&(e.z=v(e.x,e.y,n,r,i)),e.prevZ=e.prev,e.nextZ=e.next,e=e.next}while(e!==t);e.prevZ.nextZ=null,e.prevZ=null,function(t){var n,r,i,e,s,o,h,a,u=1;do{for(r=t,t=null,s=null,o=0;r;){for(o++,i=r,h=0,n=0;n<u&&(h++,i=i.nextZ);n++);for(a=u;h>0||a>0&&i;)0!==h&&(0===a||!i||r.z<=i.z)?(e=r,r=r.nextZ,h--):(e=i,i=i.nextZ,a--),s?s.nextZ=e:t=e,e.prevZ=s,s=e;r=i}s.nextZ=null,u*=2}while(o>1)}(e)}(t,i,c,l);for(var p,f,y=t;t.prev!==t.next;)if(p=t.prev,f=t.next,l?h(t,i,c,l):o(t))n.push(p.i/r|0),n.push(t.i/r|0),n.push(f.i/r|0),S(t),t=f.next,y=f.next;else if((t=f)===y){x?1===x?s(t=a(e(t),n,r),n,r,i,c,l,2):2===x&&u(t,n,r,i,c,l):s(e(t),n,r,i,c,l,1);break}}}function o(t){var n=t.prev,r=t,i=t.next;if(d(n,r,i)>=0)return!1;for(var e=n.x,s=r.x,o=i.x,h=n.y,a=r.y,u=i.y,c=e<s?e<o?e:o:s<o?s:o,l=h<a?h<u?h:u:a<u?a:u,x=e>s?e>o?e:o:s>o?s:o,v=h>a?h>u?h:u:a>u?a:u,p=i.next;p!==n;){if(p.x>=c&&p.x<=x&&p.y>=l&&p.y<=v&&f(e,h,s,a,o,u,p.x,p.y)&&d(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function h(t,n,r,i){var e=t.prev,s=t,o=t.next;if(d(e,s,o)>=0)return!1;for(var h=e.x,a=s.x,u=o.x,c=e.y,l=s.y,x=o.y,p=h<a?h<u?h:u:a<u?a:u,y=c<l?c<x?c:x:l<x?l:x,g=h>a?h>u?h:u:a>u?a:u,z=c>l?c>x?c:x:l>x?l:x,m=v(p,y,n,r,i),M=v(g,z,n,r,i),w=t.prevZ,b=t.nextZ;w&&w.z>=m&&b&&b.z<=M;){if(w.x>=p&&w.x<=g&&w.y>=y&&w.y<=z&&w!==e&&w!==o&&f(h,c,a,l,u,x,w.x,w.y)&&d(w.prev,w,w.next)>=0)return!1;if(w=w.prevZ,b.x>=p&&b.x<=g&&b.y>=y&&b.y<=z&&b!==e&&b!==o&&f(h,c,a,l,u,x,b.x,b.y)&&d(b.prev,b,b.next)>=0)return!1;b=b.nextZ}for(;w&&w.z>=m;){if(w.x>=p&&w.x<=g&&w.y>=y&&w.y<=z&&w!==e&&w!==o&&f(h,c,a,l,u,x,w.x,w.y)&&d(w.prev,w,w.next)>=0)return!1;w=w.prevZ}for(;b&&b.z<=M;){if(b.x>=p&&b.x<=g&&b.y>=y&&b.y<=z&&b!==e&&b!==o&&f(h,c,a,l,u,x,b.x,b.y)&&d(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function a(t,n,r){var i=t;do{var s=i.prev,o=i.next.next;!g(s,o)&&z(s,i,i.next,o)&&w(s,o)&&w(o,s)&&(n.push(s.i/r|0),n.push(i.i/r|0),n.push(o.i/r|0),S(i),S(i.next),i=t=o),i=i.next}while(i!==t);return e(i)}function u(t,n,r,i,o,h){var a=t;do{for(var u=a.next.next;u!==a.prev;){if(a.i!==u.i&&y(a,u)){var c=b(a,u);return a=e(a,a.next),c=e(c,c.next),s(a,n,r,i,o,h,0),void s(c,n,r,i,o,h,0)}u=u.next}a=a.next}while(a!==t)}function c(t,n){return t.x-n.x}function l(t,n){var r=function(t,n){var r,i=n,e=t.x,s=t.y,o=-1/0;do{if(s<=i.y&&s>=i.next.y&&i.next.y!==i.y){var h=i.x+(s-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(h<=e&&h>o&&(o=h,r=i.x<i.next.x?i:i.next,h===e))return r}i=i.next}while(i!==n);if(!r)return null;var a,u=r,c=r.x,l=r.y,v=1/0;i=r;do{e>=i.x&&i.x>=c&&e!==i.x&&f(s<l?e:o,s,c,l,s<l?o:e,s,i.x,i.y)&&(a=Math.abs(s-i.y)/(e-i.x),w(i,t)&&(a<v||a===v&&(i.x>r.x||i.x===r.x&&x(r,i)))&&(r=i,v=a)),i=i.next}while(i!==u);return r}(t,n);if(!r)return n;var i=b(r,t);return e(i,i.next),e(r,r.next)}function x(t,n){return d(t.prev,t,n.prev)<0&&d(n.next,t,t.next)<0}function v(t,n,r,i,e){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*e|0)|t<<8))|t<<4))|t<<2))|t<<1))|(n=1431655765&((n=858993459&((n=252645135&((n=16711935&((n=(n-i)*e|0)|n<<8))|n<<4))|n<<2))|n<<1))<<1}function p(t){var n=t,r=t;do{(n.x<r.x||n.x===r.x&&n.y<r.y)&&(r=n),n=n.next}while(n!==t);return r}function f(t,n,r,i,e,s,o,h){return(e-o)*(n-h)>=(t-o)*(s-h)&&(t-o)*(i-h)>=(r-o)*(n-h)&&(r-o)*(s-h)>=(e-o)*(i-h)}function y(t,n){return t.next.i!==n.i&&t.prev.i!==n.i&&!function(t,n){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==n.i&&r.next.i!==n.i&&z(r,r.next,t,n))return!0;r=r.next}while(r!==t);return!1}(t,n)&&(w(t,n)&&w(n,t)&&function(t,n){var r=t,i=!1,e=(t.x+n.x)/2,s=(t.y+n.y)/2;do{r.y>s!=r.next.y>s&&r.next.y!==r.y&&e<(r.next.x-r.x)*(s-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==t);return i}(t,n)&&(d(t.prev,t,n.prev)||d(t,n.prev,n))||g(t,n)&&d(t.prev,t,t.next)>0&&d(n.prev,n,n.next)>0)}function d(t,n,r){return(n.y-t.y)*(r.x-n.x)-(n.x-t.x)*(r.y-n.y)}function g(t,n){return t.x===n.x&&t.y===n.y}function z(t,n,r,i){var e=M(d(t,n,r)),s=M(d(t,n,i)),o=M(d(r,i,t)),h=M(d(r,i,n));return e!==s&&o!==h||(!(0!==e||!m(t,r,n))||(!(0!==s||!m(t,i,n))||(!(0!==o||!m(r,t,i))||!(0!==h||!m(r,n,i)))))}function m(t,n,r){return n.x<=Math.max(t.x,r.x)&&n.x>=Math.min(t.x,r.x)&&n.y<=Math.max(t.y,r.y)&&n.y>=Math.min(t.y,r.y)}function M(t){return t>0?1:t<0?-1:0}function w(t,n){return d(t.prev,t,t.next)<0?d(t,n,t.next)>=0&&d(t,t.prev,n)>=0:d(t,n,t.prev)<0||d(t,t.next,n)<0}function b(t,n){var r=new A(t.i,t.x,t.y),i=new A(n.i,n.x,n.y),e=t.next,s=n.prev;return t.next=n,n.prev=t,r.next=e,e.prev=r,i.next=r,r.prev=i,s.next=i,i.prev=s,i}function P(t,n,r,i){var e=new A(t,n,r);return i?(e.next=i.next,e.prev=i,i.next.prev=e,i.next=e):(e.prev=e,e.next=e),e}function S(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function A(t,n,r){this.i=t,this.x=n,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function V(t,n,r,i){for(var e=0,s=n,o=r-i;s<r;s+=i)e+=(t[o]-t[s])*(t[s+1]+t[o+1]),o=s;return e}n.exports=r,n.exports.default=r,r.deviation=function(t,n,r,i){var e=n&&n.length,s=e?n[0]*r:t.length,o=Math.abs(V(t,0,s,r));if(e)for(var h=0,a=n.length;h<a;h++){var u=n[h]*r,c=h<a-1?n[h+1]*r:t.length;o-=Math.abs(V(t,u,c,r))}var l=0;for(h=0;h<i.length;h+=3){var x=i[h]*r,v=i[h+1]*r,p=i[h+2]*r;l+=Math.abs((t[x]-t[p])*(t[v+1]-t[x+1])-(t[x]-t[v])*(t[p+1]-t[x+1]))}return 0===o&&0===l?0:Math.abs((l-o)/o)},r.flatten=function(t){for(var n=t[0][0].length,r={vertices:[],holes:[],dimensions:n},i=0,e=0;e<t.length;e++){for(var s=0;s<t[e].length;s++)for(var o=0;o<n;o++)r.vertices.push(t[e][s][o]);e>0&&(i+=t[e-1].length,r.holes.push(i))}return r};var Z=n.exports;function _(t){for(var n,r,i=0,e=1,s=t.length;e<s;)n=r||t[0],i+=((r=t[e])[0]-n[0])*(r[1]+n[1]),e++;return i>0}function L(t,n,r){return t[0]=n[0]-r[0],t[1]=n[1]-r[1],t[2]=n[2]-r[2],t}function F(t,n){var r=n[0],i=n[1],e=n[2],s=Math.sqrt(r*r+i*i+e*e)||1;return t[0]=r/s,t[1]=i/s,t[2]=e/s,t}function I(t,n){function r(t,n,r,i){t[0]=n,t[1]=r,t[2]=i}for(var i,e,s,o,h,a,u,c,l,x=[],v=[],p=[],f=[],y=[],d=[],g=t.length,z=new Float32Array(n.length),m=0;m<g;){var M=3*t[m],w=3*t[m+1],b=3*t[m+2];r(x,n[M],n[M+1],n[M+2]),r(v,n[w],n[w+1],n[w+2]),r(p,n[b],n[b+1],n[b+2]),L(y,p,v),L(f,x,v),i=d,s=f,o=void 0,h=void 0,a=void 0,u=void 0,c=void 0,l=void 0,o=(e=y)[0],h=e[1],a=e[2],u=s[0],c=s[1],l=s[2],i[0]=h*l-a*c,i[1]=a*u-o*l,i[2]=o*c-h*u;for(var P=0;P<3;P++)z[M+P]+=d[P],z[w+P]+=d[P],z[b+P]+=d[P];m+=3}for(var S=0,A=z.length;S<A;)r(d,z[S],z[S+1],z[S+2]),F(d,d),z[S]=d[0]||0,z[S+1]=d[1]||0,z[S+2]=d[2]||0,S+=3;return z}function O(t){if(1===t.length)return{position:t[0].position,normal:t[0].normal,uv:t[0].uv,indices:t[0].indices,results:t};for(var n=0,r=0,i=0,e=t.length;i<e;i++){var s=t[i],o=s.position,h=s.indices;n+=o.length,r+=h.length}for(var a={position:new Float32Array(n),normal:new Float32Array(n),uv:new Float32Array(n/3*2),indices:new Uint32Array(r),results:t},u=0,c=0,l=0,x=0,v=0,p=t.length;v<p;v++){var f=t[v],y=f.position,d=f.indices,g=f.normal,z=f.uv;a.position.set(y,u),a.normal.set(g,u),a.uv.set(z,x);for(var m=0,M=d.length;m<M;){var w=d[m]+c;a.indices[l]=w,l++,m++}x+=z.length,u+=y.length,c+=y.length/3}return a}function q(t){return 180*t/Math.PI}function U(t){return t/180*Math.PI}function j(t,n,r,i,e,s){var o=3*r,h=3*i,a=3*e,u=3*s,c=n[o],l=n[o+1],x=n[o+2],v=n[h],p=n[h+1],f=n[h+2],y=n[a],d=n[a+1],g=n[a+2],z=n[u],m=n[u+1],M=n[u+2];Math.abs(l-p)<Math.abs(c-v)?(t.push(c,1-x),t.push(v,1-f),t.push(y,1-g),t.push(z,1-M)):(t.push(l,1-x),t.push(p,1-f),t.push(d,1-g),t.push(m,1-M))}function C(t){T(t)||t.push(t[0])}function T(t){var n=t.length,r=t[0],i=r[0],e=r[1],s=t[n-1],o=s[0],h=s[1];return i===o&&e===h}var k={x:0,y:0},B={x:0,y:0};function R(t,n){for(var r=n.lineWidth/2,i=[],e=[],s=[],o=t.length,h=0;h<o;){var a=t[h],u=t[h+1],c=t[h];h===o-1&&(a=t[o-2],u=t[o-1]);var l=u[1]-a[1],x=u[0]-a[0],v=0,p=q(Math.atan(l/x));if(0===h||h===o-1)v=p,v-=90;else{var f=t[h-1];k.x=f[0]-a[0],k.y=f[1]-a[1],B.x=u[0]-a[0],B.y=u[1]-a[1],v=p-E(k,B)/2}var y=U(v),d=c,g=[Math.cos(y)+d[0],Math.sin(y)+d[1]],z=W(a,u,r),m=z[0],M=z[1],w=D(m[0],m[1],d,g),b=D(M[0],M[1],d,g);if(!w||!b){var P=i.length,S=i[P-2],A=i[P-1];if(!S||!A)continue;w=[S[0],S[1]],b=[A[0],A[1]]}w[2]=c[2]||0,b[2]=c[2]||0,i.push(w,b),N(w,a,u)?(e.push(w),s.push(b)):(e.push(b),s.push(w)),h++}return{offsetPoints:i,leftPoints:e,rightPoints:s}}var E=function(t,n){var r=t.x,i=t.y,e=n.x,s=n.y,o=r*e+i*s,h=r*s-i*e;return(Math.atan2(h,o)/Math.PI*180+360)%360};function N(t,n,r){var i=n[0],e=n[1],s=r[0],o=r[1];return(e-o)*t[0]+(s-i)*t[1]+i*o-s*e>0}function W(t,n,r){var i=n[1]-t[1],e=n[0]-t[0],s=Math.atan2(i,e),o=s+Math.PI/2,h=Math.cos(o)*r,a=Math.sin(o)*r,u=[t[0]+h,t[1]+a],c=[n[0]+h,n[1]+a],l=s-Math.PI/2;return h=Math.cos(l)*r,a=Math.sin(l)*r,[[u,c],[[t[0]+h,t[1]+a],[n[0]+h,n[1]+a]]]}function D(t,n,r,i){var e=n[0]-t[0],s=n[1]-t[1],o=i[0]-r[0],h=i[1]-r[1];if(0===e&&0===o)return null;if(0===s&&0===h)return null;var a,u,c=s/e,l=h/o,x=t[1]-c*t[0],v=r[1]-l*r[0];return 0===e?u=l*(a=t[0])+v:0===o?u=c*(a=r[0])+x:0===s?a=((u=t[1])-v)/l:0===h?a=((u=r[1])-x)/c:u=c*(a=(v-x)/(c-l))+x,[a,u]}var Q=function(){function t(t,n,r){void 0===t&&(t=0),void 0===n&&(n=0),void 0===r&&(r=0),this.x=t,this.y=n,this.z=r}var n=t.prototype;return n.set=function(t,n,r){return void 0===r&&(r=this.z),this.x=t,this.y=n,this.z=r,this},n.clone=function(){return new this.constructor(this.x,this.y,this.z)},n.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},n.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},n.addScalar=function(t){return this.x+=t,this.y+=t,this.z+=t,this},n.addVectors=function(t,n){return this.x=t.x+n.x,this.y=t.y+n.y,this.z=t.z+n.z,this},n.addScaledVector=function(t,n){return this.x+=t.x*n,this.y+=t.y*n,this.z+=t.z*n,this},n.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},n.subScalar=function(t){return this.x-=t,this.y-=t,this.z-=t,this},n.subVectors=function(t,n){return this.x=t.x-n.x,this.y=t.y-n.y,this.z=t.z-n.z,this},n.multiply=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this},n.multiplyScalar=function(t){return this.x*=t,this.y*=t,this.z*=t,this},n.multiplyVectors=function(t,n){return this.x=t.x*n.x,this.y=t.y*n.y,this.z=t.z*n.z,this},n.applyMatrix4=function(t){var n=this.x,r=this.y,i=this.z,e=t.elements,s=1/(e[3]*n+e[7]*r+e[11]*i+e[15]);return this.x=(e[0]*n+e[4]*r+e[8]*i+e[12])*s,this.y=(e[1]*n+e[5]*r+e[9]*i+e[13])*s,this.z=(e[2]*n+e[6]*r+e[10]*i+e[14])*s,this},n.divide=function(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this},n.divideScalar=function(t){return this.multiplyScalar(1/t)},n.min=function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this},n.max=function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this},n.clamp=function(t,n){return this.x=Math.max(t.x,Math.min(n.x,this.x)),this.y=Math.max(t.y,Math.min(n.y,this.y)),this.z=Math.max(t.z,Math.min(n.z,this.z)),this},n.clampScalar=function(t,n){return this.x=Math.max(t,Math.min(n,this.x)),this.y=Math.max(t,Math.min(n,this.y)),this.z=Math.max(t,Math.min(n,this.z)),this},n.clampLength=function(t,n){var r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(t,Math.min(n,r)))},n.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},n.lengthSq=function(){return this.x*this.x+this.y*this.y+this.z*this.z},n.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},n.normalize=function(){return this.divideScalar(this.length()||1)},n.setLength=function(t){return this.normalize().multiplyScalar(t)},n.lerp=function(t,n){return this.x+=(t.x-this.x)*n,this.y+=(t.y-this.y)*n,this.z+=(t.z-this.z)*n,this},n.lerpVectors=function(t,n,r){return this.x=t.x+(n.x-t.x)*r,this.y=t.y+(n.y-t.y)*r,this.z=t.z+(n.z-t.z)*r,this},n.cross=function(t){return this.crossVectors(this,t)},n.crossVectors=function(t,n){var r=t.x,i=t.y,e=t.z,s=n.x,o=n.y,h=n.z;return this.x=i*h-e*o,this.y=e*s-r*h,this.z=r*o-i*s,this},n.distanceTo=function(t){return Math.sqrt(this.distanceToSquared(t))},n.equals=function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z},n.fromArray=function(t,n){return void 0===n&&(n=0),this.x=t[n],this.y=t[n+1],this.z=t[n+2],this},n.random=function(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this},t}(),H=function(){function t(){this.pos=new Q,this.dir=new Q,this.right=new Q,this.up=new Q,this.dist=0,this.widthScale=1,this.sharp=!1}var n=t.prototype;return n.lerpPathPoints=function(t,n,r){this.pos.lerpVectors(t.pos,n.pos,r),this.dir.lerpVectors(t.dir,n.dir,r),this.up.lerpVectors(t.up,n.up,r),this.right.lerpVectors(t.right,n.right,r),this.dist=(n.dist-t.dist)*r+t.dist,this.widthScale=(n.widthScale-t.widthScale)*r+t.widthScale},n.copy=function(t){this.pos.copy(t.pos),this.dir.copy(t.dir),this.up.copy(t.up),this.right.copy(t.right),this.dist=t.dist,this.widthScale=t.widthScale},t}(),X=function(){function t(t,n,r,i,e,s,o,h,a,u,c,l,x,v,p,f){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,n,r,i,e,s,o,h,a,u,c,l,x,v,p,f)}var n=t.prototype;return n.set=function(t,n,r,i,e,s,o,h,a,u,c,l,x,v,p,f){var y=this.elements;return y[0]=t,y[4]=n,y[8]=r,y[12]=i,y[1]=e,y[5]=s,y[9]=o,y[13]=h,y[2]=a,y[6]=u,y[10]=c,y[14]=l,y[3]=x,y[7]=v,y[11]=p,y[15]=f,this},n.multiply=function(t){return this.multiplyMatrices(this,t)},n.makeRotationAxis=function(t,n){var r=Math.cos(n),i=Math.sin(n),e=1-r,s=t.x,o=t.y,h=t.z,a=e*s,u=e*o;return this.set(a*s+r,a*o-i*h,a*h+i*o,0,a*o+i*h,u*o+r,u*h-i*s,0,a*h-i*o,u*h+i*s,e*h*h+r,0,0,0,0,1),this},n.equals=function(t){for(var n=this.elements,r=t.elements,i=0;i<16;i++)if(n[i]!==r[i])return!1;return!0},t}();function G(t,n){return G=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},G(t,n)}function J(t,n,r,i){return function(t,n){var r=1-t;return r*r*n}(t,n)+function(t,n){return 2*(1-t)*t*n}(t,r)+function(t,n){return t*t*n}(t,i)}var K=function(t){var n,r;function i(n,r,i){var e;return void 0===n&&(n=new Q),void 0===r&&(r=new Q),void 0===i&&(i=new Q),(e=t.call(this)||this).isQuadraticBezierCurve3=!0,e.type="QuadraticBezierCurve3",e.v0=n,e.v1=r,e.v2=i,e}return r=t,(n=i).prototype=Object.create(r.prototype),n.prototype.constructor=n,G(n,r),i.prototype.getPoint=function(t,n){void 0===n&&(n=new Q);var r=n,i=this.v0,e=this.v1,s=this.v2;return r.set(J(t,i.x,e.x,s.x),J(t,i.y,e.y,s.y),J(t,i.z,e.z,s.z)),r},i}(function(){function t(){this.type="Curve",this.arcLengthDivisions=200}var n=t.prototype;return n.getPoint=function(){return console.warn("THREE.Curve: .getPoint() not implemented."),null},n.getPointAt=function(t,n){var r=this.getUtoTmapping(t);return this.getPoint(r,n)},n.getPoints=function(t){void 0===t&&(t=5);for(var n=[],r=0;r<=t;r++)n.push(this.getPoint(r/t));return n},n.getLength=function(){var t=this.getLengths();return t[t.length-1]},n.getLengths=function(t){if(void 0===t&&(t=this.arcLengthDivisions),this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var n,r=[],i=this.getPoint(0),e=0;r.push(0);for(var s=1;s<=t;s++)e+=(n=this.getPoint(s/t)).distanceTo(i),r.push(e),i=n;return this.cacheArcLengths=r,r},n.getUtoTmapping=function(t,n){var r,i=this.getLengths(),e=0,s=i.length;r=n||t*i[s-1];for(var o,h=0,a=s-1;h<=a;)if((o=i[e=Math.floor(h+(a-h)/2)]-r)<0)h=e+1;else{if(!(o>0)){a=e;break}a=e-1}if(i[e=a]===r)return e/(s-1);var u=i[e];return(e+(r-u)/(i[e+1]-u))/(s-1)},t}()),Y=new Q,$=new Q,tt=new Q,nt=new X,rt=new K;var it=function(){function t(){this.array=[],this.count=0}var n=t.prototype;return n.set=function(t,n,r,i,e){if(void 0===n&&(n=.1),void 0===r&&(r=10),void 0===i&&(i=null),void 0===e&&(e=!1),(t=t.slice(0)).length<2)return console.warn("PathPointList: points length less than 2."),void(this.count=0);e&&!t[0].equals(t[t.length-1])&&t.push((new Q).copy(t[0]));for(var s=0,o=t.length;s<o;s++)if(0===s)this._start(t[s],t[s+1],i);else if(s===o-1)if(e){this._corner(t[s],t[1],n,r,i);var h=this.array[0].dist;this.array[0].copy(this.array[this.count-1]),this.array[0].dist=h}else this._end(t[s]);else this._corner(t[s],t[s+1],n,r,i)},n.distance=function(){return this.count>0?this.array[this.count-1].dist:0},n._getByIndex=function(t){return this.array[t]||(this.array[t]=new H),this.array[t]},n._start=function(t,n,r){this.count=0;var i=this._getByIndex(this.count);if(i.pos.copy(t),i.dir.subVectors(n,t),r)i.up.copy(r);else{var e=Number.MAX_VALUE,s=Math.abs(i.dir.x),o=Math.abs(i.dir.y),h=Math.abs(i.dir.z);s<e&&(e=s,i.up.set(1,0,0)),o<e&&(e=o,i.up.set(0,1,0)),h<e&&i.up.set(0,0,1)}i.right.crossVectors(i.dir,i.up).normalize(),i.up.crossVectors(i.right,i.dir).normalize(),i.dist=0,i.widthScale=1,i.sharp=!1,i.dir.normalize(),this.count++},n._end=function(t){var n=this.array[this.count-1],r=this._getByIndex(this.count);r.pos.copy(t),r.dir.subVectors(t,n.pos);var i=r.dir.length();r.dir.normalize(),r.up.copy(n.up);var e=Y.crossVectors(n.dir,r.dir);if(e.length()>Number.EPSILON){e.normalize();var s=Math.acos(Math.min(Math.max(n.dir.dot(r.dir),-1),1));r.up.applyMatrix4(nt.makeRotationAxis(e,s))}r.right.crossVectors(r.dir,r.up).normalize(),r.dist=n.dist+i,r.widthScale=1,r.sharp=!1,this.count++},n._corner=function(t,n,r,i,e){if(r>0&&i>0){for(var s=function(t,n,r,i,e,s){var o=Y.subVectors(n,t),h=$.subVectors(r,n),a=o.length(),u=h.length();o.normalize(),h.normalize();var c=Math.min(.999999*(e?a/2:a),i);s.v0.copy(n).sub(o.multiplyScalar(c)),s.v1.copy(n);var l=Math.min(u/2*.999999,i);return s.v2.copy(n).add(h.multiplyScalar(l)),s}(this.array[this.count-1].pos,t,n,r,this.count-1==0,rt),o=s.getPoints(i),h=0;h<i;h++)this._sharpCorner(o[h],o[h+1],e,0===h?1:0);o[i].equals(n)||this._sharpCorner(o[i],n,e,2)}else this._sharpCorner(t,n,e,0,!0)},n._sharpCorner=function(t,n,r,i,e){void 0===i&&(i=0),void 0===e&&(e=!1);var s=this.array[this.count-1],o=this._getByIndex(this.count),h=Y.subVectors(t,s.pos),a=$.subVectors(n,t),u=h.length();if(h.normalize(),a.normalize(),o.pos.copy(t),1===i?o.dir.copy(h):2===i?o.dir.copy(a):(o.dir.addVectors(h,a),o.dir.normalize()),r)1===o.dir.dot(r)?o.right.crossVectors(a,r).normalize():o.right.crossVectors(o.dir,r).normalize(),o.up.crossVectors(o.right,o.dir).normalize();else{o.up.copy(s.up);var c=tt.crossVectors(s.dir,o.dir);if(c.length()>Number.EPSILON){c.normalize();var l=Math.acos(Math.min(Math.max(s.dir.dot(o.dir),-1),1));o.up.applyMatrix4(nt.makeRotationAxis(c,l))}o.right.crossVectors(o.dir,o.up).normalize()}o.dist=s.dist+u;var x=h.dot(a);o.widthScale=Math.min(1/Math.sqrt((1+x)/2),1.415)||1,o.sharp=Math.abs(x-1)>.05&&e,this.count++},t}(),et=new Q(0,0,1);t.cylinder=function(t,n){void 0===n&&(n={}),n=Object.assign({},{radius:1,height:2,radialSegments:6},n);for(var r=Math.round(Math.max(4,n.radialSegments)),i=n,e=i.radius,s=i.height,o=360/r/360*Math.PI*2,h=r+1,a=new Float32Array(3*h*2),u=t[0],c=t[1],l=0,x=0,v=3*h,p=2*h,f=[],y=[],d=-1;d<r;d++){var g=o*d,z=Math.cos(g)*e+u,m=Math.sin(g)*e+c;a[l]=z,a[l+1]=m,a[l+2]=0,a[l+v]=z,a[l+1+v]=m,a[l+2+v]=s;var M,w;M=.5+z/e/2,w=.5+m/e/2,y[x]=M,y[x+1]=w,y[x+p]=M,y[x+1+p]=w,l+=3,x+=2,d>1&&f.push(0,d-1,d)}a[l-=3]=a[0],a[l+1]=a[1],a[l+2]=a[2];var b=a.length;a[b-3]=a[0],a[b-2]=a[1],a[b-1]=s;for(var P=f.length,S=0;S<P;S++){var A=f[S];f.push(A+h)}var V=new Float32Array(2*(3*h*2-6)),Z=-1;l=2*h,x=0;for(var _=0,L=a.length/2;_<L-3;_+=3){var F=a[_],O=a[_+1],q=a[_+3],U=a[_+4];V[++Z]=F,V[++Z]=O,V[++Z]=s,V[++Z]=q,V[++Z]=U,V[++Z]=s,V[++Z]=F,V[++Z]=O,V[++Z]=0,V[++Z]=q,V[++Z]=U,V[++Z]=0;var j=l+2,C=l+3,T=l,k=l+1;f.push(T,j,k,j,C,k),l+=4;var B=x/h,R=(x+1)/h;y.push(B,s/e/2,R,s/e/2,B,0,R,0),x++}var E=new Float32Array(a.length+V.length);E.set(a,0),E.set(V,a.length);var N=I(f,E);return{points:a,indices:new Uint32Array(f),position:E,normal:N,uv:new Float32Array(y)}},t.expandLine=R,t.expandPaths=function(t,n){n=Object.assign({},{lineWidth:1,cornerRadius:0,cornerSplit:10},n);var r=t.map((function(t){var r=t.map((function(t){var n=t[0],r=t[1],i=t[2];return new Q(n,r,i||0)})),i=new it;i.set(r,n.cornerRadius,n.cornerSplit,et);var e=function(t,n){var r=n.lineWidth||.1,i=1,e=r/2,s=r,o=t.distance(),h=i*o;if(0===o)return null;var a,u=e/s,c=0,l=[],x=[],v=[],p=[],f=0,y=new Q,d=new Q,g=new Q,z=new Q,m=new Q,M=new Q;function w(t){var n=0===l.length,r=t.sharp&&!n,i=t.dist/s,o=t.dir,h=t.up,a=t.right;if(y.copy(a).multiplyScalar(e*t.widthScale),d.copy(a).multiplyScalar(-e*t.widthScale),y.add(t.pos),d.add(t.pos),r){g.fromArray(l,l.length-6).sub(d),z.fromArray(l,l.length-3).sub(y);var w,b,P=g.length()-z.length();P>0?(w=g,b=d):(w=z,b=y),m.copy(w).setLength(Math.abs(P)).add(b);var S=M.copy(b).sub(m).normalize().dot(o)*M.copy(b).sub(m).length()*2;M.copy(o).setLength(S).add(m),P>0?(l.push(m.x,m.y,m.z,y.x,y.y,y.z,d.x,d.y,d.z,y.x,y.y,y.z,M.x,M.y,M.z,y.x,y.y,y.z),f+=6,p.push(f-6,f-8,f-7,f-6,f-7,f-5,f-4,f-6,f-5,f-2,f-4,f-1),c+=12):(l.push(d.x,d.y,d.z,m.x,m.y,m.z,d.x,d.y,d.z,y.x,y.y,y.z,d.x,d.y,d.z,M.x,M.y,M.z),f+=6,p.push(f-6,f-8,f-7,f-6,f-7,f-5,f-6,f-5,f-3,f-2,f-3,f-1),c+=12),x.push(h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z),v.push(i-u,0,i-u,1,i,0,i,1,i+u,0,i+u,1)}else l.push(d.x,d.y,d.z,y.x,y.y,y.z),x.push(h.x,h.y,h.z,h.x,h.y,h.z),v.push(i,0,i,1),f+=2,n||(p.push(f-2,f-4,f-3,f-2,f-3,f-1),c+=6)}if(h>0)for(var b=0;b<t.count;b++){var P=t.array[b];if(P.dist>h){var S=t.array[b-1];a=new H;var A=(h-S.dist)/(P.dist-S.dist);a.lerpPathPoints(S,P,A),w(a);break}w(P)}else a=t.array[0];return{points:l,normal:x,uvs:v,index:p,count:c}}(i,n);return e.line=t,e.position=new Float32Array(e.points),e.indices=new Uint32Array(e.index),e.uv=new Float32Array(e.uvs),e.normal=new Float32Array(e.normal),e})),i=O(r);return i.lines=t,i},t.extrudePolygons=function(t,n){n=Object.assign({},{depth:2},n);var r=t.map((function(t){for(var r=0,i=t.length;r<i;r++){var e=t[r];C(e),0===r?_(e)||(t[r]=e.reverse()):_(e)&&(t[r]=e.reverse()),T(e)&&e.splice(e.length-1,1)}var s=function(t,n){for(var r=function(t){var n=0,r=0,i=t.length;for(;r<i;)n+=t[r].length,r++;return n}(t),i=t.length,e=[],s=new Float32Array(2*r),o=[],h=[],a=3*r,u=2*r,c=n.depth,l=0,x=0,v=0,p=0;p<i;p++){var f=t[p];p>0&&e.push(l/2);for(var y=0,d=f.length;y<d;){var g=f[y],z=g[0],m=g[1];s[l++]=z,s[l++]=m,o[x]=z,o[x+1]=m,o[x+2]=c,o[a+x]=z,o[a+x+1]=m,o[a+x+2]=0,h[v]=z,h[v+1]=m,h[u+v]=z,h[u+v+1]=m,x+=3,v+=2,y++}}return{flatVertices:s,holes:e,points:o,count:r,uvs:h}}(t,n);return s.polygon=t,function(t,n){for(var r=[],i=t.count,e=0,s=n.length;e<s;e+=3){var o=n[e],h=n[e+1],a=n[e+2];r[e]=o,r[e+1]=h,r[e+2]=a;var u=s+e,c=i+o,l=i+h,x=i+a;r[u]=c,r[u+1]=l,r[u+2]=x}t.index=r}(s,Z(s.flatVertices,s.holes,2)),function(t,n){for(var r=t.points,i=t.index,e=t.polygon,s=t.uvs,o=n.depth,h=0,a=e.length;h<a;h++)for(var u=e[h],c=0,l=u.length;c<l;){var x=u[c],v=u[c+1];c===l-1&&(v=u[0]);var p=r.length/3,f=x[0],y=x[1],d=v[0],g=v[1];r.push(f,y,o,d,g,o,f,y,0,d,g,0);var z=p+2,m=p+3,M=p,w=p+1;i.push(z,M,m,M,w,m),j(s,r,z,m,M,w),c++}}(s,n),s.position=new Float32Array(s.points),s.indices=new Uint32Array(s.index),s.uv=new Float32Array(s.uvs),s.normal=I(s.indices,s.position),s})),i=O(r);return i.polygons=t,i},t.extrudePolylines=function(t,n){n=Object.assign({},{depth:2,lineWidth:1},n);var r=t.map((function(t){var r=R(t,n);return r.line=t,function(t,n){var r=n.depth,i=[],e=[],s=[],o=t.leftPoints,h=t.rightPoints,a=0,u=o.length;for(;a<u;){var c=3*a,l=o[a],x=l[0],v=l[1],p=l[2];i[c]=x,i[c+1]=v,i[c+2]=r+p;var f=h[a],y=f[0],d=f[1],g=f[2],z=3*u+c;i[z]=y,i[z+1]=d,i[z+2]=r+g;var m=2*u*3+c;i[m]=x,i[m+1]=v,i[m+2]=p;var M=2*u*3+3*u+c;i[M]=y,i[M+1]=d,i[M+2]=g,a++}a=0,u=i.length;for(;a<u;){var w=i[a],b=i[a+1];s.push(w,b),a+=3}a=0,u=o.length;for(;a<u-1;){var P=a,S=a+1,A=P+u,V=S+u;e.push(P,A,S),e.push(A,V,S);var Z=a+2*u,_=Z+1,L=Z+u,F=_+u;e.push(Z,L,_),e.push(L,F,_),a++}t.index=e,t.points=i,t.uvs=s}(r,n),function(t,n){var r=t.points,i=t.index,e=t.leftPoints,s=t.rightPoints,o=t.uvs,h=n.depth,a=[e,s];function u(t,n){var e=r.length/3;r.push(t[0],t[1],h+t[2],n[0],n[1],h+n[2],t[0],t[1],t[2],n[0],n[1],n[2]);var s=e+2,a=e+3,u=e,c=e+1;i.push(s,u,a,u,c,a),j(o,r,s,a,u,c)}for(var c=0,l=a.length;c<l;c++){var x=a[c];c>0&&(x=(x=x.map((function(t){return t}))).reverse());for(var v=0,p=x.length-1;v<p;){u(x[v],x[v+1]),v++}}for(var f=e.length,y=[s[0],e[0],e[f-1],s[f-1]],d=0;d<y.length;d+=2){u(y[d],y[d+1])}}(r,n),r.position=new Float32Array(r.points),r.indices=new Uint32Array(r.index),r.uv=new Float32Array(r.uvs),r.normal=I(r.indices,r.position),r})),i=O(r);return i.lines=t,i},Object.defineProperty(t,"__esModule",{value:!0})}));
4
+ !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).polyextrude=t.polyextrude||{})}(this,(function(t){"use strict";var n={exports:{}};function r(t,n,r){r=r||2;var e,o,h,a,u,p,x,f=n&&n.length,y=f?n[0]*r:t.length,d=i(t,0,y,r,!0),g=[];if(!d||d.next===d.prev)return g;if(f&&(d=function(t,n,r,e){var s,o,h,a=[];for(s=0,o=n.length;s<o;s++)(h=i(t,n[s]*e,s<o-1?n[s+1]*e:t.length,e,!1))===h.next&&(h.steiner=!0),a.push(v(h));for(a.sort(c),s=0;s<a.length;s++)r=l(a[s],r);return r}(t,n,d,r)),t.length>80*r){e=h=t[0],o=a=t[1];for(var m=r;m<y;m+=r)(u=t[m])<e&&(e=u),(p=t[m+1])<o&&(o=p),u>h&&(h=u),p>a&&(a=p);x=0!==(x=Math.max(h-e,a-o))?32767/x:0}return s(d,g,r,e,o,x,0),g}function i(t,n,r,i,e){var s,o;if(e===V(t,n,r,i)>0)for(s=n;s<r;s+=i)o=P(s,t[s],t[s+1],o);else for(s=r-i;s>=n;s-=i)o=P(s,t[s],t[s+1],o);return o&&g(o,o.next)&&(S(o),o=o.next),o}function e(t,n){if(!t)return t;n||(n=t);var r,i=t;do{if(r=!1,i.steiner||!g(i,i.next)&&0!==d(i.prev,i,i.next))i=i.next;else{if(S(i),(i=n=i.prev)===i.next)break;r=!0}}while(r||i!==n);return n}function s(t,n,r,i,c,l,p){if(t){!p&&l&&function(t,n,r,i){var e=t;do{0===e.z&&(e.z=x(e.x,e.y,n,r,i)),e.prevZ=e.prev,e.nextZ=e.next,e=e.next}while(e!==t);e.prevZ.nextZ=null,e.prevZ=null,function(t){var n,r,i,e,s,o,h,a,u=1;do{for(r=t,t=null,s=null,o=0;r;){for(o++,i=r,h=0,n=0;n<u&&(h++,i=i.nextZ);n++);for(a=u;h>0||a>0&&i;)0!==h&&(0===a||!i||r.z<=i.z)?(e=r,r=r.nextZ,h--):(e=i,i=i.nextZ,a--),s?s.nextZ=e:t=e,e.prevZ=s,s=e;r=i}s.nextZ=null,u*=2}while(o>1)}(e)}(t,i,c,l);for(var v,f,y=t;t.prev!==t.next;)if(v=t.prev,f=t.next,l?h(t,i,c,l):o(t))n.push(v.i/r|0),n.push(t.i/r|0),n.push(f.i/r|0),S(t),t=f.next,y=f.next;else if((t=f)===y){p?1===p?s(t=a(e(t),n,r),n,r,i,c,l,2):2===p&&u(t,n,r,i,c,l):s(e(t),n,r,i,c,l,1);break}}}function o(t){var n=t.prev,r=t,i=t.next;if(d(n,r,i)>=0)return!1;for(var e=n.x,s=r.x,o=i.x,h=n.y,a=r.y,u=i.y,c=e<s?e<o?e:o:s<o?s:o,l=h<a?h<u?h:u:a<u?a:u,p=e>s?e>o?e:o:s>o?s:o,x=h>a?h>u?h:u:a>u?a:u,v=i.next;v!==n;){if(v.x>=c&&v.x<=p&&v.y>=l&&v.y<=x&&f(e,h,s,a,o,u,v.x,v.y)&&d(v.prev,v,v.next)>=0)return!1;v=v.next}return!0}function h(t,n,r,i){var e=t.prev,s=t,o=t.next;if(d(e,s,o)>=0)return!1;for(var h=e.x,a=s.x,u=o.x,c=e.y,l=s.y,p=o.y,v=h<a?h<u?h:u:a<u?a:u,y=c<l?c<p?c:p:l<p?l:p,g=h>a?h>u?h:u:a>u?a:u,m=c>l?c>p?c:p:l>p?l:p,z=x(v,y,n,r,i),M=x(g,m,n,r,i),w=t.prevZ,b=t.nextZ;w&&w.z>=z&&b&&b.z<=M;){if(w.x>=v&&w.x<=g&&w.y>=y&&w.y<=m&&w!==e&&w!==o&&f(h,c,a,l,u,p,w.x,w.y)&&d(w.prev,w,w.next)>=0)return!1;if(w=w.prevZ,b.x>=v&&b.x<=g&&b.y>=y&&b.y<=m&&b!==e&&b!==o&&f(h,c,a,l,u,p,b.x,b.y)&&d(b.prev,b,b.next)>=0)return!1;b=b.nextZ}for(;w&&w.z>=z;){if(w.x>=v&&w.x<=g&&w.y>=y&&w.y<=m&&w!==e&&w!==o&&f(h,c,a,l,u,p,w.x,w.y)&&d(w.prev,w,w.next)>=0)return!1;w=w.prevZ}for(;b&&b.z<=M;){if(b.x>=v&&b.x<=g&&b.y>=y&&b.y<=m&&b!==e&&b!==o&&f(h,c,a,l,u,p,b.x,b.y)&&d(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function a(t,n,r){var i=t;do{var s=i.prev,o=i.next.next;!g(s,o)&&m(s,i,i.next,o)&&w(s,o)&&w(o,s)&&(n.push(s.i/r|0),n.push(i.i/r|0),n.push(o.i/r|0),S(i),S(i.next),i=t=o),i=i.next}while(i!==t);return e(i)}function u(t,n,r,i,o,h){var a=t;do{for(var u=a.next.next;u!==a.prev;){if(a.i!==u.i&&y(a,u)){var c=b(a,u);return a=e(a,a.next),c=e(c,c.next),s(a,n,r,i,o,h,0),void s(c,n,r,i,o,h,0)}u=u.next}a=a.next}while(a!==t)}function c(t,n){return t.x-n.x}function l(t,n){var r=function(t,n){var r,i=n,e=t.x,s=t.y,o=-1/0;do{if(s<=i.y&&s>=i.next.y&&i.next.y!==i.y){var h=i.x+(s-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(h<=e&&h>o&&(o=h,r=i.x<i.next.x?i:i.next,h===e))return r}i=i.next}while(i!==n);if(!r)return null;var a,u=r,c=r.x,l=r.y,x=1/0;i=r;do{e>=i.x&&i.x>=c&&e!==i.x&&f(s<l?e:o,s,c,l,s<l?o:e,s,i.x,i.y)&&(a=Math.abs(s-i.y)/(e-i.x),w(i,t)&&(a<x||a===x&&(i.x>r.x||i.x===r.x&&p(r,i)))&&(r=i,x=a)),i=i.next}while(i!==u);return r}(t,n);if(!r)return n;var i=b(r,t);return e(i,i.next),e(r,r.next)}function p(t,n){return d(t.prev,t,n.prev)<0&&d(n.next,t,t.next)<0}function x(t,n,r,i,e){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*e|0)|t<<8))|t<<4))|t<<2))|t<<1))|(n=1431655765&((n=858993459&((n=252645135&((n=16711935&((n=(n-i)*e|0)|n<<8))|n<<4))|n<<2))|n<<1))<<1}function v(t){var n=t,r=t;do{(n.x<r.x||n.x===r.x&&n.y<r.y)&&(r=n),n=n.next}while(n!==t);return r}function f(t,n,r,i,e,s,o,h){return(e-o)*(n-h)>=(t-o)*(s-h)&&(t-o)*(i-h)>=(r-o)*(n-h)&&(r-o)*(s-h)>=(e-o)*(i-h)}function y(t,n){return t.next.i!==n.i&&t.prev.i!==n.i&&!function(t,n){var r=t;do{if(r.i!==t.i&&r.next.i!==t.i&&r.i!==n.i&&r.next.i!==n.i&&m(r,r.next,t,n))return!0;r=r.next}while(r!==t);return!1}(t,n)&&(w(t,n)&&w(n,t)&&function(t,n){var r=t,i=!1,e=(t.x+n.x)/2,s=(t.y+n.y)/2;do{r.y>s!=r.next.y>s&&r.next.y!==r.y&&e<(r.next.x-r.x)*(s-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==t);return i}(t,n)&&(d(t.prev,t,n.prev)||d(t,n.prev,n))||g(t,n)&&d(t.prev,t,t.next)>0&&d(n.prev,n,n.next)>0)}function d(t,n,r){return(n.y-t.y)*(r.x-n.x)-(n.x-t.x)*(r.y-n.y)}function g(t,n){return t.x===n.x&&t.y===n.y}function m(t,n,r,i){var e=M(d(t,n,r)),s=M(d(t,n,i)),o=M(d(r,i,t)),h=M(d(r,i,n));return e!==s&&o!==h||(!(0!==e||!z(t,r,n))||(!(0!==s||!z(t,i,n))||(!(0!==o||!z(r,t,i))||!(0!==h||!z(r,n,i)))))}function z(t,n,r){return n.x<=Math.max(t.x,r.x)&&n.x>=Math.min(t.x,r.x)&&n.y<=Math.max(t.y,r.y)&&n.y>=Math.min(t.y,r.y)}function M(t){return t>0?1:t<0?-1:0}function w(t,n){return d(t.prev,t,t.next)<0?d(t,n,t.next)>=0&&d(t,t.prev,n)>=0:d(t,n,t.prev)<0||d(t,t.next,n)<0}function b(t,n){var r=new A(t.i,t.x,t.y),i=new A(n.i,n.x,n.y),e=t.next,s=n.prev;return t.next=n,n.prev=t,r.next=e,e.prev=r,i.next=r,r.prev=i,s.next=i,i.prev=s,i}function P(t,n,r,i){var e=new A(t,n,r);return i?(e.next=i.next,e.prev=i,i.next.prev=e,i.next=e):(e.prev=e,e.next=e),e}function S(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function A(t,n,r){this.i=t,this.x=n,this.y=r,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function V(t,n,r,i){for(var e=0,s=n,o=r-i;s<r;s+=i)e+=(t[o]-t[s])*(t[s+1]+t[o+1]),o=s;return e}n.exports=r,n.exports.default=r,r.deviation=function(t,n,r,i){var e=n&&n.length,s=e?n[0]*r:t.length,o=Math.abs(V(t,0,s,r));if(e)for(var h=0,a=n.length;h<a;h++){var u=n[h]*r,c=h<a-1?n[h+1]*r:t.length;o-=Math.abs(V(t,u,c,r))}var l=0;for(h=0;h<i.length;h+=3){var p=i[h]*r,x=i[h+1]*r,v=i[h+2]*r;l+=Math.abs((t[p]-t[v])*(t[x+1]-t[p+1])-(t[p]-t[x])*(t[v+1]-t[p+1]))}return 0===o&&0===l?0:Math.abs((l-o)/o)},r.flatten=function(t){for(var n=t[0][0].length,r={vertices:[],holes:[],dimensions:n},i=0,e=0;e<t.length;e++){for(var s=0;s<t[e].length;s++)for(var o=0;o<n;o++)r.vertices.push(t[e][s][o]);e>0&&(i+=t[e-1].length,r.holes.push(i))}return r};var Z=n.exports;function _(t){for(var n,r,i=0,e=1,s=t.length;e<s;)n=r||t[0],i+=((r=t[e])[0]-n[0])*(r[1]+n[1]),e++;return i>0}function L(t,n,r){return t[0]=n[0]-r[0],t[1]=n[1]-r[1],t[2]=n[2]-r[2],t}function F(t,n){var r=n[0],i=n[1],e=n[2],s=Math.sqrt(r*r+i*i+e*e)||1;return t[0]=r/s,t[1]=i/s,t[2]=e/s,t}function O(t,n){function r(t,n,r,i){t[0]=n,t[1]=r,t[2]=i}for(var i,e,s,o,h,a,u,c,l,p=[],x=[],v=[],f=[],y=[],d=[],g=t.length,m=new Float32Array(n.length),z=0;z<g;){var M=3*t[z],w=3*t[z+1],b=3*t[z+2];r(p,n[M],n[M+1],n[M+2]),r(x,n[w],n[w+1],n[w+2]),r(v,n[b],n[b+1],n[b+2]),L(y,v,x),L(f,p,x),i=d,s=f,o=void 0,h=void 0,a=void 0,u=void 0,c=void 0,l=void 0,o=(e=y)[0],h=e[1],a=e[2],u=s[0],c=s[1],l=s[2],i[0]=h*l-a*c,i[1]=a*u-o*l,i[2]=o*c-h*u;for(var P=0;P<3;P++)m[M+P]+=d[P],m[w+P]+=d[P],m[b+P]+=d[P];z+=3}for(var S=0,A=m.length;S<A;)r(d,m[S],m[S+1],m[S+2]),F(d,d),m[S]=d[0]||0,m[S+1]=d[1]||0,m[S+2]=d[2]||0,S+=3;return m}function I(t){if(1===t.length)return{position:t[0].position,normal:t[0].normal,uv:t[0].uv,indices:t[0].indices,results:t};for(var n=0,r=0,i=0,e=t.length;i<e;i++){var s=t[i],o=s.position,h=s.indices;n+=o.length,r+=h.length}for(var a={position:new Float32Array(n),normal:new Float32Array(n),uv:new Float32Array(n/3*2),indices:new Uint32Array(r),results:t},u=0,c=0,l=0,p=0,x=0,v=t.length;x<v;x++){var f=t[x],y=f.position,d=f.indices,g=f.normal,m=f.uv;a.position.set(y,u),a.normal.set(g,u),a.uv.set(m,p);for(var z=0,M=d.length;z<M;){var w=d[z]+c;a.indices[l]=w,l++,z++}p+=m.length,u+=y.length,c+=y.length/3}return a}function k(t){return 180*t/Math.PI}function U(t){return t/180*Math.PI}function j(t,n,r,i,e,s){var o=3*r,h=3*i,a=3*e,u=3*s,c=n[o],l=n[o+1],p=n[o+2],x=n[h],v=n[h+1],f=n[h+2],y=n[a],d=n[a+1],g=n[a+2],m=n[u],z=n[u+1],M=n[u+2];Math.abs(l-v)<Math.abs(c-x)?(t.push(c,1-p),t.push(x,1-f),t.push(y,1-g),t.push(m,1-M)):(t.push(l,1-p),t.push(v,1-f),t.push(d,1-g),t.push(z,1-M))}function q(t){C(t)||t.push(t[0])}function C(t){var n=t.length,r=t[0],i=r[0],e=r[1],s=t[n-1],o=s[0],h=s[1];return i===o&&e===h}function T(t){t.lineWidth=Math.max(0,t.lineWidth),t.depth=Math.max(0,t.depth),t.sideDepth=Math.max(0,t.sideDepth)}function W(t,n){var r=n.bottomStickGround,i=n.depth,e=t.depths,s=i,o=i;e&&(s=e[0],o=e[1]);for(var h=[],a=[],u=[],c=t.leftPoints,l=t.rightPoints,p=0,x=c.length;p<x;){var v=3*p,f=c[p],y=f[0],d=f[1],g=f[2];h[v]=y,h[v+1]=d,h[v+2]=s+g;var m=l[p],z=m[0],M=m[1],w=m[2],b=3*x+v;h[b]=z,h[b+1]=M,h[b+2]=o+w;var P=2*x*3+v;h[P]=y,h[P+1]=d,h[P+2]=g,r&&(h[P+2]=0);var S=2*x*3+3*x+v;h[S]=z,h[S+1]=M,h[S+2]=w,r&&(h[S+2]=0),p++}for(p=0,x=h.length;p<x;){var A=h[p],V=h[p+1];u.push(A,V),p+=3}for(p=0,x=c.length;p<x-1;){var Z=p,_=p+1,L=Z+x,F=_+x;a.push(Z,L,_),a.push(L,F,_);var O=p+2*x,I=O+1,k=O+x,U=I+x;a.push(O,k,I),a.push(k,U,I),p++}if(t.index=a,t.points=h,t.uvs=u,e)for(x=c.length,p=0;p<x;)c[p].depth=s,l[p].depth=o,p++}function B(t,n){var r=t.points,i=t.index,e=t.leftPoints,s=t.rightPoints,o=t.uvs,h=n.depth,a=n.bottomStickGround,u=[e,s],c=t.depths;function l(t,n){var e=r.length/3,s=r.length-1;r[++s]=t[0],r[++s]=t[1],r[++s]=(c?t.depth:h)+t[2],r[++s]=n[0],r[++s]=n[1],r[++s]=(c?n.depth:h)+n[2],r[++s]=t[0],r[++s]=t[1],r[++s]=a?0:t[2],r[++s]=n[0],r[++s]=n[1],r[++s]=a?0:n[2];var u=e+2,l=e+3,p=e,x=e+1;i.push(u,p,l,p,x,l),j(o,r,u,l,p,x)}for(var p=0,x=u.length;p<x;p++){var v=u[p];p>0&&(v=(v=v.map((function(t){return t}))).reverse());for(var f=0,y=v.length-1;f<y;){l(v[f],v[f+1]),f++}}for(var d=e.length,g=[s[0],e[0],e[d-1],s[d-1]],m=0;m<g.length;m+=2){l(g[m],g[m+1])}}var D={x:0,y:0},R={x:0,y:0};function E(t,n){for(var r=n.lineWidth/2,i=[],e=[],s=[],o=t.length,h=0;h<o;){var a=t[h],u=t[h+1],c=t[h];h===o-1&&(a=t[o-2],u=t[o-1]);var l=u[1]-a[1],p=u[0]-a[0],x=0,v=k(Math.atan(l/p));if(0===h||h===o-1)x=v,x-=90;else{var f=t[h-1];D.x=f[0]-a[0],D.y=f[1]-a[1],R.x=u[0]-a[0],R.y=u[1]-a[1],x=v-N(D,R)/2}var y=U(x),d=c,g=[Math.cos(y)+d[0],Math.sin(y)+d[1]],m=Q(a,u,r),z=m[0],M=m[1],w=H(z[0],z[1],d,g),b=H(M[0],M[1],d,g);if(!w||!b){var P=i.length,S=i[P-2],A=i[P-1];if(!S||!A)continue;w=[S[0],S[1]],b=[A[0],A[1]]}w[2]=c[2]||0,b[2]=c[2]||0,i.push(w,b),G(w,a,u)?(e.push(w),s.push(b)):(e.push(b),s.push(w)),h++}return{offsetPoints:i,leftPoints:e,rightPoints:s}}var N=function(t,n){var r=t.x,i=t.y,e=n.x,s=n.y,o=r*e+i*s,h=r*s-i*e;return(Math.atan2(h,o)/Math.PI*180+360)%360};function G(t,n,r){var i=n[0],e=n[1],s=r[0],o=r[1];return(e-o)*t[0]+(s-i)*t[1]+i*o-s*e>0}function Q(t,n,r){var i=n[1]-t[1],e=n[0]-t[0],s=Math.atan2(i,e),o=s+Math.PI/2,h=Math.cos(o)*r,a=Math.sin(o)*r,u=[t[0]+h,t[1]+a],c=[n[0]+h,n[1]+a],l=s-Math.PI/2;return h=Math.cos(l)*r,a=Math.sin(l)*r,[[u,c],[[t[0]+h,t[1]+a],[n[0]+h,n[1]+a]]]}function H(t,n,r,i){var e=n[0]-t[0],s=n[1]-t[1],o=i[0]-r[0],h=i[1]-r[1];if(0===e&&0===o)return null;if(0===s&&0===h)return null;var a,u,c=s/e,l=h/o,p=t[1]-c*t[0],x=r[1]-l*r[0];return 0===e?u=l*(a=t[0])+x:0===o?u=c*(a=r[0])+p:0===s?a=((u=t[1])-x)/l:0===h?a=((u=r[1])-p)/c:u=c*(a=(x-p)/(c-l))+p,[a,u]}var X=function(){function t(t,n,r){void 0===t&&(t=0),void 0===n&&(n=0),void 0===r&&(r=0),this.x=t,this.y=n,this.z=r}var n=t.prototype;return n.set=function(t,n,r){return void 0===r&&(r=this.z),this.x=t,this.y=n,this.z=r,this},n.clone=function(){return new this.constructor(this.x,this.y,this.z)},n.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},n.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},n.addScalar=function(t){return this.x+=t,this.y+=t,this.z+=t,this},n.addVectors=function(t,n){return this.x=t.x+n.x,this.y=t.y+n.y,this.z=t.z+n.z,this},n.addScaledVector=function(t,n){return this.x+=t.x*n,this.y+=t.y*n,this.z+=t.z*n,this},n.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},n.subScalar=function(t){return this.x-=t,this.y-=t,this.z-=t,this},n.subVectors=function(t,n){return this.x=t.x-n.x,this.y=t.y-n.y,this.z=t.z-n.z,this},n.multiply=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this},n.multiplyScalar=function(t){return this.x*=t,this.y*=t,this.z*=t,this},n.multiplyVectors=function(t,n){return this.x=t.x*n.x,this.y=t.y*n.y,this.z=t.z*n.z,this},n.applyMatrix4=function(t){var n=this.x,r=this.y,i=this.z,e=t.elements,s=1/(e[3]*n+e[7]*r+e[11]*i+e[15]);return this.x=(e[0]*n+e[4]*r+e[8]*i+e[12])*s,this.y=(e[1]*n+e[5]*r+e[9]*i+e[13])*s,this.z=(e[2]*n+e[6]*r+e[10]*i+e[14])*s,this},n.divide=function(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this},n.divideScalar=function(t){return this.multiplyScalar(1/t)},n.min=function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this},n.max=function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this},n.clamp=function(t,n){return this.x=Math.max(t.x,Math.min(n.x,this.x)),this.y=Math.max(t.y,Math.min(n.y,this.y)),this.z=Math.max(t.z,Math.min(n.z,this.z)),this},n.clampScalar=function(t,n){return this.x=Math.max(t,Math.min(n,this.x)),this.y=Math.max(t,Math.min(n,this.y)),this.z=Math.max(t,Math.min(n,this.z)),this},n.clampLength=function(t,n){var r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(t,Math.min(n,r)))},n.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},n.lengthSq=function(){return this.x*this.x+this.y*this.y+this.z*this.z},n.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},n.normalize=function(){return this.divideScalar(this.length()||1)},n.setLength=function(t){return this.normalize().multiplyScalar(t)},n.lerp=function(t,n){return this.x+=(t.x-this.x)*n,this.y+=(t.y-this.y)*n,this.z+=(t.z-this.z)*n,this},n.lerpVectors=function(t,n,r){return this.x=t.x+(n.x-t.x)*r,this.y=t.y+(n.y-t.y)*r,this.z=t.z+(n.z-t.z)*r,this},n.cross=function(t){return this.crossVectors(this,t)},n.crossVectors=function(t,n){var r=t.x,i=t.y,e=t.z,s=n.x,o=n.y,h=n.z;return this.x=i*h-e*o,this.y=e*s-r*h,this.z=r*o-i*s,this},n.distanceTo=function(t){return Math.sqrt(this.distanceToSquared(t))},n.equals=function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z},n.fromArray=function(t,n){return void 0===n&&(n=0),this.x=t[n],this.y=t[n+1],this.z=t[n+2],this},n.random=function(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this},t}(),J=function(){function t(){this.pos=new X,this.dir=new X,this.right=new X,this.up=new X,this.dist=0,this.widthScale=1,this.sharp=!1}var n=t.prototype;return n.lerpPathPoints=function(t,n,r){this.pos.lerpVectors(t.pos,n.pos,r),this.dir.lerpVectors(t.dir,n.dir,r),this.up.lerpVectors(t.up,n.up,r),this.right.lerpVectors(t.right,n.right,r),this.dist=(n.dist-t.dist)*r+t.dist,this.widthScale=(n.widthScale-t.widthScale)*r+t.widthScale},n.copy=function(t){this.pos.copy(t.pos),this.dir.copy(t.dir),this.up.copy(t.up),this.right.copy(t.right),this.dist=t.dist,this.widthScale=t.widthScale},t}(),K=function(){function t(t,n,r,i,e,s,o,h,a,u,c,l,p,x,v,f){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,n,r,i,e,s,o,h,a,u,c,l,p,x,v,f)}var n=t.prototype;return n.set=function(t,n,r,i,e,s,o,h,a,u,c,l,p,x,v,f){var y=this.elements;return y[0]=t,y[4]=n,y[8]=r,y[12]=i,y[1]=e,y[5]=s,y[9]=o,y[13]=h,y[2]=a,y[6]=u,y[10]=c,y[14]=l,y[3]=p,y[7]=x,y[11]=v,y[15]=f,this},n.multiply=function(t){return this.multiplyMatrices(this,t)},n.makeRotationAxis=function(t,n){var r=Math.cos(n),i=Math.sin(n),e=1-r,s=t.x,o=t.y,h=t.z,a=e*s,u=e*o;return this.set(a*s+r,a*o-i*h,a*h+i*o,0,a*o+i*h,u*o+r,u*h-i*s,0,a*h-i*o,u*h+i*s,e*h*h+r,0,0,0,0,1),this},n.equals=function(t){for(var n=this.elements,r=t.elements,i=0;i<16;i++)if(n[i]!==r[i])return!1;return!0},t}();function Y(t,n){return Y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},Y(t,n)}function $(t,n,r,i){return function(t,n){var r=1-t;return r*r*n}(t,n)+function(t,n){return 2*(1-t)*t*n}(t,r)+function(t,n){return t*t*n}(t,i)}var tt=function(t){var n,r;function i(n,r,i){var e;return void 0===n&&(n=new X),void 0===r&&(r=new X),void 0===i&&(i=new X),(e=t.call(this)||this).isQuadraticBezierCurve3=!0,e.type="QuadraticBezierCurve3",e.v0=n,e.v1=r,e.v2=i,e}return r=t,(n=i).prototype=Object.create(r.prototype),n.prototype.constructor=n,Y(n,r),i.prototype.getPoint=function(t,n){void 0===n&&(n=new X);var r=n,i=this.v0,e=this.v1,s=this.v2;return r.set($(t,i.x,e.x,s.x),$(t,i.y,e.y,s.y),$(t,i.z,e.z,s.z)),r},i}(function(){function t(){this.type="Curve",this.arcLengthDivisions=200}var n=t.prototype;return n.getPoint=function(){return console.warn("THREE.Curve: .getPoint() not implemented."),null},n.getPointAt=function(t,n){var r=this.getUtoTmapping(t);return this.getPoint(r,n)},n.getPoints=function(t){void 0===t&&(t=5);for(var n=[],r=0;r<=t;r++)n.push(this.getPoint(r/t));return n},n.getLength=function(){var t=this.getLengths();return t[t.length-1]},n.getLengths=function(t){if(void 0===t&&(t=this.arcLengthDivisions),this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var n,r=[],i=this.getPoint(0),e=0;r.push(0);for(var s=1;s<=t;s++)e+=(n=this.getPoint(s/t)).distanceTo(i),r.push(e),i=n;return this.cacheArcLengths=r,r},n.getUtoTmapping=function(t,n){var r,i=this.getLengths(),e=0,s=i.length;r=n||t*i[s-1];for(var o,h=0,a=s-1;h<=a;)if((o=i[e=Math.floor(h+(a-h)/2)]-r)<0)h=e+1;else{if(!(o>0)){a=e;break}a=e-1}if(i[e=a]===r)return e/(s-1);var u=i[e];return(e+(r-u)/(i[e+1]-u))/(s-1)},t}()),nt=new X,rt=new X,it=new X,et=new K,st=new tt;var ot=function(){function t(){this.array=[],this.count=0}var n=t.prototype;return n.set=function(t,n,r,i,e){if(void 0===n&&(n=.1),void 0===r&&(r=10),void 0===i&&(i=null),void 0===e&&(e=!1),(t=t.slice(0)).length<2)return console.warn("PathPointList: points length less than 2."),void(this.count=0);e&&!t[0].equals(t[t.length-1])&&t.push((new X).copy(t[0]));for(var s=0,o=t.length;s<o;s++)if(0===s)this._start(t[s],t[s+1],i);else if(s===o-1)if(e){this._corner(t[s],t[1],n,r,i);var h=this.array[0].dist;this.array[0].copy(this.array[this.count-1]),this.array[0].dist=h}else this._end(t[s]);else this._corner(t[s],t[s+1],n,r,i)},n.distance=function(){return this.count>0?this.array[this.count-1].dist:0},n._getByIndex=function(t){return this.array[t]||(this.array[t]=new J),this.array[t]},n._start=function(t,n,r){this.count=0;var i=this._getByIndex(this.count);if(i.pos.copy(t),i.dir.subVectors(n,t),r)i.up.copy(r);else{var e=Number.MAX_VALUE,s=Math.abs(i.dir.x),o=Math.abs(i.dir.y),h=Math.abs(i.dir.z);s<e&&(e=s,i.up.set(1,0,0)),o<e&&(e=o,i.up.set(0,1,0)),h<e&&i.up.set(0,0,1)}i.right.crossVectors(i.dir,i.up).normalize(),i.up.crossVectors(i.right,i.dir).normalize(),i.dist=0,i.widthScale=1,i.sharp=!1,i.dir.normalize(),this.count++},n._end=function(t){var n=this.array[this.count-1],r=this._getByIndex(this.count);r.pos.copy(t),r.dir.subVectors(t,n.pos);var i=r.dir.length();r.dir.normalize(),r.up.copy(n.up);var e=nt.crossVectors(n.dir,r.dir);if(e.length()>Number.EPSILON){e.normalize();var s=Math.acos(Math.min(Math.max(n.dir.dot(r.dir),-1),1));r.up.applyMatrix4(et.makeRotationAxis(e,s))}r.right.crossVectors(r.dir,r.up).normalize(),r.dist=n.dist+i,r.widthScale=1,r.sharp=!1,this.count++},n._corner=function(t,n,r,i,e){if(r>0&&i>0){for(var s=function(t,n,r,i,e,s){var o=nt.subVectors(n,t),h=rt.subVectors(r,n),a=o.length(),u=h.length();o.normalize(),h.normalize();var c=Math.min(.999999*(e?a/2:a),i);s.v0.copy(n).sub(o.multiplyScalar(c)),s.v1.copy(n);var l=Math.min(u/2*.999999,i);return s.v2.copy(n).add(h.multiplyScalar(l)),s}(this.array[this.count-1].pos,t,n,r,this.count-1==0,st),o=s.getPoints(i),h=0;h<i;h++)this._sharpCorner(o[h],o[h+1],e,0===h?1:0);o[i].equals(n)||this._sharpCorner(o[i],n,e,2)}else this._sharpCorner(t,n,e,0,!0)},n._sharpCorner=function(t,n,r,i,e){void 0===i&&(i=0),void 0===e&&(e=!1);var s=this.array[this.count-1],o=this._getByIndex(this.count),h=nt.subVectors(t,s.pos),a=rt.subVectors(n,t),u=h.length();if(h.normalize(),a.normalize(),o.pos.copy(t),1===i?o.dir.copy(h):2===i?o.dir.copy(a):(o.dir.addVectors(h,a),o.dir.normalize()),r)1===o.dir.dot(r)?o.right.crossVectors(a,r).normalize():o.right.crossVectors(o.dir,r).normalize(),o.up.crossVectors(o.right,o.dir).normalize();else{o.up.copy(s.up);var c=it.crossVectors(s.dir,o.dir);if(c.length()>Number.EPSILON){c.normalize();var l=Math.acos(Math.min(Math.max(s.dir.dot(o.dir),-1),1));o.up.applyMatrix4(et.makeRotationAxis(c,l))}o.right.crossVectors(o.dir,o.up).normalize()}o.dist=s.dist+u;var p=h.dot(a);o.widthScale=Math.min(1/Math.sqrt((1+p)/2),1.415)||1,o.sharp=Math.abs(p-1)>.05&&e,this.count++},t}(),ht=new X(0,0,1);t.cylinder=function(t,n){void 0===n&&(n={}),n=Object.assign({},{radius:1,height:2,radialSegments:6},n);for(var r=Math.round(Math.max(4,n.radialSegments)),i=n,e=i.radius,s=i.height,o=360/r/360*Math.PI*2,h=r+1,a=new Float32Array(3*h*2),u=t[0],c=t[1],l=0,p=0,x=3*h,v=2*h,f=[],y=[],d=-1;d<r;d++){var g=o*d,m=Math.cos(g)*e+u,z=Math.sin(g)*e+c;a[l]=m,a[l+1]=z,a[l+2]=0,a[l+x]=m,a[l+1+x]=z,a[l+2+x]=s;var M,w;M=.5+m/e/2,w=.5+z/e/2,y[p]=M,y[p+1]=w,y[p+v]=M,y[p+1+v]=w,l+=3,p+=2,d>1&&f.push(0,d-1,d)}a[l-=3]=a[0],a[l+1]=a[1],a[l+2]=a[2];var b=a.length;a[b-3]=a[0],a[b-2]=a[1],a[b-1]=s;for(var P=f.length,S=0;S<P;S++){var A=f[S];f.push(A+h)}var V=new Float32Array(2*(3*h*2-6)),Z=-1;l=2*h,p=0;for(var _=0,L=a.length/2;_<L-3;_+=3){var F=a[_],I=a[_+1],k=a[_+3],U=a[_+4];V[++Z]=F,V[++Z]=I,V[++Z]=s,V[++Z]=k,V[++Z]=U,V[++Z]=s,V[++Z]=F,V[++Z]=I,V[++Z]=0,V[++Z]=k,V[++Z]=U,V[++Z]=0;var j=l+2,q=l+3,C=l,T=l+1;f.push(C,j,T,j,q,T),l+=4;var W=p/h,B=(p+1)/h;y.push(W,s/e/2,B,s/e/2,W,0,B,0),p++}var D=new Float32Array(a.length+V.length);D.set(a,0),D.set(V,a.length);var R=O(f,D);return{points:a,indices:new Uint32Array(f),position:D,normal:R,uv:new Float32Array(y)}},t.expandLine=E,t.expandPaths=function(t,n){n=Object.assign({},{lineWidth:1,cornerRadius:0,cornerSplit:10},n);var r=t.map((function(t){var r=t.map((function(t){var n=t[0],r=t[1],i=t[2];return new X(n,r,i||0)})),i=new ot;i.set(r,n.cornerRadius,n.cornerSplit,ht);var e=function(t,n){var r=n.lineWidth||.1,i=1,e=r/2,s=r,o=t.distance(),h=i*o;if(0===o)return null;var a,u=e/s,c=0,l=[],p=[],x=[],v=[],f=0,y=new X,d=new X,g=new X,m=new X,z=new X,M=new X;function w(t){var n=0===l.length,r=t.sharp&&!n,i=t.dist/s,o=t.dir,h=t.up,a=t.right;if(y.copy(a).multiplyScalar(e*t.widthScale),d.copy(a).multiplyScalar(-e*t.widthScale),y.add(t.pos),d.add(t.pos),r){g.fromArray(l,l.length-6).sub(d),m.fromArray(l,l.length-3).sub(y);var w,b,P=g.length()-m.length();P>0?(w=g,b=d):(w=m,b=y),z.copy(w).setLength(Math.abs(P)).add(b);var S=M.copy(b).sub(z).normalize().dot(o)*M.copy(b).sub(z).length()*2;M.copy(o).setLength(S).add(z),P>0?(l.push(z.x,z.y,z.z,y.x,y.y,y.z,d.x,d.y,d.z,y.x,y.y,y.z,M.x,M.y,M.z,y.x,y.y,y.z),f+=6,v.push(f-6,f-8,f-7,f-6,f-7,f-5,f-4,f-6,f-5,f-2,f-4,f-1),c+=12):(l.push(d.x,d.y,d.z,z.x,z.y,z.z,d.x,d.y,d.z,y.x,y.y,y.z,d.x,d.y,d.z,M.x,M.y,M.z),f+=6,v.push(f-6,f-8,f-7,f-6,f-7,f-5,f-6,f-5,f-3,f-2,f-3,f-1),c+=12),p.push(h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z,h.x,h.y,h.z),x.push(i-u,0,i-u,1,i,0,i,1,i+u,0,i+u,1)}else l.push(d.x,d.y,d.z,y.x,y.y,y.z),p.push(h.x,h.y,h.z,h.x,h.y,h.z),x.push(i,0,i,1),f+=2,n||(v.push(f-2,f-4,f-3,f-2,f-3,f-1),c+=6)}if(h>0)for(var b=0;b<t.count;b++){var P=t.array[b];if(P.dist>h){var S=t.array[b-1];a=new J;var A=(h-S.dist)/(P.dist-S.dist);a.lerpPathPoints(S,P,A),w(a);break}w(P)}else a=t.array[0];return{points:l,normal:p,uvs:x,index:v,count:c}}(i,n);return e.line=t,e.position=new Float32Array(e.points),e.indices=new Uint32Array(e.index),e.uv=new Float32Array(e.uvs),e.normal=new Float32Array(e.normal),e})),i=I(r);return i.lines=t,i},t.extrudePolygons=function(t,n){n=Object.assign({},{depth:2},n);var r=t.map((function(t){for(var r=0,i=t.length;r<i;r++){var e=t[r];q(e),0===r?_(e)||(t[r]=e.reverse()):_(e)&&(t[r]=e.reverse()),C(e)&&e.splice(e.length-1,1)}var s=function(t,n){for(var r=function(t){var n=0,r=0,i=t.length;for(;r<i;)n+=t[r].length,r++;return n}(t),i=t.length,e=[],s=new Float32Array(2*r),o=[],h=[],a=3*r,u=2*r,c=n.depth,l=0,p=0,x=0,v=0;v<i;v++){var f=t[v];v>0&&e.push(l/2);for(var y=0,d=f.length;y<d;){var g=f[y],m=g[0],z=g[1];s[l++]=m,s[l++]=z,o[p]=m,o[p+1]=z,o[p+2]=c,o[a+p]=m,o[a+p+1]=z,o[a+p+2]=0,h[x]=m,h[x+1]=z,h[u+x]=m,h[u+x+1]=z,p+=3,x+=2,y++}}return{flatVertices:s,holes:e,points:o,count:r,uvs:h}}(t,n);return s.polygon=t,function(t,n){for(var r=[],i=t.count,e=0,s=n.length;e<s;e+=3){var o=n[e],h=n[e+1],a=n[e+2];r[e]=o,r[e+1]=h,r[e+2]=a;var u=s+e,c=i+o,l=i+h,p=i+a;r[u]=c,r[u+1]=l,r[u+2]=p}t.index=r}(s,Z(s.flatVertices,s.holes,2)),function(t,n){for(var r=t.points,i=t.index,e=t.polygon,s=t.uvs,o=n.depth,h=0,a=e.length;h<a;h++)for(var u=e[h],c=0,l=u.length;c<l;){var p=u[c],x=u[c+1];c===l-1&&(x=u[0]);var v=r.length/3,f=p[0],y=p[1],d=x[0],g=x[1];r.push(f,y,o,d,g,o,f,y,0,d,g,0);var m=v+2,z=v+3,M=v,w=v+1;i.push(m,M,z,M,w,z),j(s,r,m,z,M,w),c++}}(s,n),s.position=new Float32Array(s.points),s.indices=new Uint32Array(s.index),s.uv=new Float32Array(s.uvs),s.normal=O(s.indices,s.position),s})),i=I(r);return i.polygons=t,i},t.extrudePolylines=function(t,n){T(n=Object.assign({},{depth:2,lineWidth:1,bottomStickGround:!1},n));var r=t.map((function(t){var r=E(t,n);return r.line=t,W(r,n),B(r,n),r.position=new Float32Array(r.points),r.indices=new Uint32Array(r.index),r.uv=new Float32Array(r.uvs),r.normal=O(r.indices,r.position),r})),i=I(r);return i.lines=t,i},t.extrudeSlopes=function(t,n){T(n=Object.assign({},{depth:2,lineWidth:1,side:"left",sideDepth:0,bottomStickGround:!1},n));var r=n,i=r.depth,e=r.side,s=r.sideDepth,o=t.map((function(t){var r=E(t,n);r.line=t;for(var o,h=r.leftPoints,a=r.rightPoints,u={line:t},c=0,l=t.length;c<l;c++)t[c][2]=t[c][2]||0;return"left"===e?(u.leftPoints=h,u.rightPoints=t,o=[s,i]):(u.leftPoints=t,u.rightPoints=a,o=[i,s]),u.depths=o,W(u,n),B(u,n),u.position=new Float32Array(u.points),u.indices=new Uint32Array(u.index),u.uv=new Float32Array(u.uvs),u.normal=O(u.indices,u.position),u})),h=I(o);return h.lines=t,h},t.leftOnLine=G,Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * poly-extrude v0.4.0
2
+ * poly-extrude v0.6.0
3
3
  */
4
4
  var earcut$2 = {exports: {}};
5
5
 
@@ -1065,11 +1065,19 @@ function isClosedRing(ring) {
1065
1065
  return x1 === x2 && y1 === y2;
1066
1066
  }
1067
1067
 
1068
+ function checkOptions(options) {
1069
+ options.lineWidth = Math.max(0, options.lineWidth);
1070
+ options.depth = Math.max(0, options.depth);
1071
+ options.sideDepth = Math.max(0, options.sideDepth);
1072
+ }
1073
+
1068
1074
  function extrudePolylines(lines, options) {
1069
1075
  options = Object.assign({}, {
1070
1076
  depth: 2,
1071
- lineWidth: 1
1077
+ lineWidth: 1,
1078
+ bottomStickGround: false
1072
1079
  }, options);
1080
+ checkOptions(options);
1073
1081
  var results = lines.map(function (line) {
1074
1082
  var result = expandLine(line, options);
1075
1083
  result.line = line;
@@ -1085,9 +1093,69 @@ function extrudePolylines(lines, options) {
1085
1093
  result.lines = lines;
1086
1094
  return result;
1087
1095
  }
1096
+ function extrudeSlopes(lines, options) {
1097
+ options = Object.assign({}, {
1098
+ depth: 2,
1099
+ lineWidth: 1,
1100
+ side: 'left',
1101
+ sideDepth: 0,
1102
+ bottomStickGround: false
1103
+ }, options);
1104
+ checkOptions(options);
1105
+ var _options = options,
1106
+ depth = _options.depth,
1107
+ side = _options.side,
1108
+ sideDepth = _options.sideDepth;
1109
+ var results = lines.map(function (line) {
1110
+ var tempResult = expandLine(line, options);
1111
+ tempResult.line = line;
1112
+ var leftPoints = tempResult.leftPoints,
1113
+ rightPoints = tempResult.rightPoints;
1114
+ var result = {
1115
+ line: line
1116
+ };
1117
+ var depths;
1118
+
1119
+ for (var i = 0, len = line.length; i < len; i++) {
1120
+ line[i][2] = line[i][2] || 0;
1121
+ }
1122
+
1123
+ if (side === 'left') {
1124
+ result.leftPoints = leftPoints;
1125
+ result.rightPoints = line;
1126
+ depths = [sideDepth, depth];
1127
+ } else {
1128
+ result.leftPoints = line;
1129
+ result.rightPoints = rightPoints;
1130
+ depths = [depth, sideDepth];
1131
+ }
1132
+
1133
+ result.depths = depths;
1134
+ generateTopAndBottom(result, options);
1135
+ generateSides(result, options);
1136
+ result.position = new Float32Array(result.points);
1137
+ result.indices = new Uint32Array(result.index);
1138
+ result.uv = new Float32Array(result.uvs);
1139
+ result.normal = generateNormal(result.indices, result.position);
1140
+ return result;
1141
+ });
1142
+ var result = merge(results);
1143
+ result.lines = lines;
1144
+ return result;
1145
+ }
1088
1146
 
1089
1147
  function generateTopAndBottom(result, options) {
1148
+ var bottomStickGround = options.bottomStickGround;
1090
1149
  var z = options.depth;
1150
+ var depths = result.depths;
1151
+ var lz = z,
1152
+ rz = z;
1153
+
1154
+ if (depths) {
1155
+ lz = depths[0];
1156
+ rz = depths[1];
1157
+ }
1158
+
1091
1159
  var points = [],
1092
1160
  index = [],
1093
1161
  uvs = [];
@@ -1105,7 +1173,7 @@ function generateTopAndBottom(result, options) {
1105
1173
  z1 = _leftPoints$i[2];
1106
1174
  points[idx0] = x1;
1107
1175
  points[idx0 + 1] = y1;
1108
- points[idx0 + 2] = z + z1; // top right
1176
+ points[idx0 + 2] = lz + z1; // top right
1109
1177
 
1110
1178
  var _rightPoints$i = rightPoints[i],
1111
1179
  x2 = _rightPoints$i[0],
@@ -1114,17 +1182,27 @@ function generateTopAndBottom(result, options) {
1114
1182
  var idx1 = len * 3 + idx0;
1115
1183
  points[idx1] = x2;
1116
1184
  points[idx1 + 1] = y2;
1117
- points[idx1 + 2] = z + z2; // bottom left
1185
+ points[idx1 + 2] = rz + z2; // bottom left
1118
1186
 
1119
1187
  var idx2 = len * 2 * 3 + idx0;
1120
1188
  points[idx2] = x1;
1121
1189
  points[idx2 + 1] = y1;
1122
- points[idx2 + 2] = z1; // bottom right
1190
+ points[idx2 + 2] = z1;
1191
+
1192
+ if (bottomStickGround) {
1193
+ points[idx2 + 2] = 0;
1194
+ } // bottom right
1195
+
1123
1196
 
1124
1197
  var idx3 = len * 2 * 3 + len * 3 + idx0;
1125
1198
  points[idx3] = x2;
1126
1199
  points[idx3 + 1] = y2;
1127
1200
  points[idx3 + 2] = z2;
1201
+
1202
+ if (bottomStickGround) {
1203
+ points[idx3 + 2] = 0;
1204
+ }
1205
+
1128
1206
  i++;
1129
1207
  }
1130
1208
 
@@ -1165,6 +1243,17 @@ function generateTopAndBottom(result, options) {
1165
1243
  result.index = index;
1166
1244
  result.points = points;
1167
1245
  result.uvs = uvs;
1246
+
1247
+ if (depths) {
1248
+ len = leftPoints.length;
1249
+ i = 0;
1250
+
1251
+ while (i < len) {
1252
+ leftPoints[i].depth = lz;
1253
+ rightPoints[i].depth = rz;
1254
+ i++;
1255
+ }
1256
+ }
1168
1257
  }
1169
1258
 
1170
1259
  function generateSides(result, options) {
@@ -1174,11 +1263,29 @@ function generateSides(result, options) {
1174
1263
  rightPoints = result.rightPoints,
1175
1264
  uvs = result.uvs;
1176
1265
  var z = options.depth;
1266
+ var bottomStickGround = options.bottomStickGround;
1177
1267
  var rings = [leftPoints, rightPoints];
1268
+ var depthsEnable = result.depths;
1178
1269
 
1179
1270
  function addOneSideIndex(v1, v2) {
1180
1271
  var idx = points.length / 3;
1181
- points.push(v1[0], v1[1], z + v1[2], v2[0], v2[1], z + v2[2], v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
1272
+ var pIndex = points.length - 1; // top
1273
+
1274
+ points[++pIndex] = v1[0];
1275
+ points[++pIndex] = v1[1];
1276
+ points[++pIndex] = (depthsEnable ? v1.depth : z) + v1[2];
1277
+ points[++pIndex] = v2[0];
1278
+ points[++pIndex] = v2[1];
1279
+ points[++pIndex] = (depthsEnable ? v2.depth : z) + v2[2]; // points.push(v1[0], v1[1], (depthsEnable ? v1.depth : z) + v1[2], v2[0], v2[1], (depthsEnable ? v2.depth : z) + v2[2]);
1280
+ // bottom
1281
+
1282
+ points[++pIndex] = v1[0];
1283
+ points[++pIndex] = v1[1];
1284
+ points[++pIndex] = bottomStickGround ? 0 : v1[2];
1285
+ points[++pIndex] = v2[0];
1286
+ points[++pIndex] = v2[1];
1287
+ points[++pIndex] = bottomStickGround ? 0 : v2[2]; // points.push(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
1288
+
1182
1289
  var a = idx + 2,
1183
1290
  b = idx + 3,
1184
1291
  c = idx,
@@ -1342,7 +1449,6 @@ function leftOnLine(p, p1, p2) {
1342
1449
  * @returns
1343
1450
  */
1344
1451
 
1345
-
1346
1452
  function translateLine(p1, p2, distance) {
1347
1453
  var dy = p2[1] - p1[1],
1348
1454
  dx = p2[0] - p1[0];
@@ -3496,4 +3602,4 @@ function generatePathVertexData(pathPointList, options) {
3496
3602
  };
3497
3603
  }
3498
3604
 
3499
- export { cylinder, expandLine, expandPaths, extrudePolygons, extrudePolylines };
3605
+ export { cylinder, expandLine, expandPaths, extrudePolygons, extrudePolylines, extrudeSlopes, leftOnLine };
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { extrudePolygons } from './src/polygon';
2
- import { extrudePolylines, expandLine } from './src/polyline';
2
+ import { extrudePolylines, expandLine, leftOnLine, extrudeSlopes } from './src/polyline';
3
3
  import { cylinder } from './src/cylinder';
4
4
  import { expandPaths } from './src/path';
5
- export { extrudePolygons, extrudePolylines, expandLine, cylinder, expandPaths };
5
+ export { extrudePolygons, extrudePolylines, extrudeSlopes, expandLine, leftOnLine, cylinder, expandPaths };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poly-extrude",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "",
5
5
  "main": "dist/poly-extrude.js",
6
6
  "module": "dist/poly-extrude.mjs",
package/readme.md CHANGED
@@ -1,29 +1,30 @@
1
1
  # poly-extrude
2
2
 
3
-
4
3
  Extrude polygons/polylines. Born in [maptalks.three](https://github.com/maptalks/maptalks.three) project<br>
5
4
 
6
5
  ## Examples
7
- [building](https://deyihu.github.io/poly-extrude/test/building.html)<br>
8
- ![](./gallery/building.png)<br>
9
- [buildings](https://deyihu.github.io/poly-extrude/test/buildings.html)<br>
10
- ![](./gallery/buildings.png)<br>
6
+
7
+ [building](https://deyihu.github.io/poly-extrude/test/building.html)
8
+ <!-- ![](./gallery/building.png)<br> -->
9
+ [buildings](https://deyihu.github.io/poly-extrude/test/buildings.html)
10
+ <!-- ![](./gallery/buildings.png)<br> -->
11
11
  [multi-polygon](https://deyihu.github.io/poly-extrude/test/multi-polygon.html)<br>
12
- ![](./gallery/multi-polygon.png)<br>
12
+ <!-- ![](./gallery/multi-polygon.png)<br> -->
13
13
  [street](https://deyihu.github.io/poly-extrude/test/street.html)<br>
14
- ![](./gallery/street.png)<br>
14
+ <!-- ![](./gallery/street.png)<br> -->
15
15
  [line-uv](https://deyihu.github.io/poly-extrude/test/line-uv.html)<br>
16
- ![](./gallery/line-uv.png)
16
+ <!-- ![](./gallery/line-uv.png) -->
17
17
  [ny-building](https://deyihu.github.io/poly-extrude/test/ny-building.html)<br>
18
- ![](./gallery/ny-building.png)
18
+ <!-- ![](./gallery/ny-building.png) -->
19
19
  [cylinder](https://deyihu.github.io/poly-extrude/test/cylinder.html)<br>
20
- ![](./gallery/cylinder.png)
20
+ <!-- ![](./gallery/cylinder.png) -->
21
21
  [brige](https://deyihu.github.io/poly-extrude/test/brige.html)<br>
22
- ![](./gallery/brige.png)
22
+ <!-- ![](./gallery/brige.png) -->
23
23
  [spring](https://deyihu.github.io/poly-extrude/test/spring.html)<br>
24
- ![](./gallery/spring.png)
24
+ <!-- ![](./gallery/spring.png) -->
25
25
  [expand paths](https://deyihu.github.io/poly-extrude/test/expand-paths-brige.html)<br>
26
- ![](./gallery/expand-paths-brige.png)
26
+ <!-- ![](./gallery/expand-paths-brige.png) -->
27
+ [slope](https://deyihu.github.io/poly-extrude/test/slope.html)<br>
27
28
 
28
29
  ## Install
29
30
 
@@ -48,7 +49,8 @@ pnpm i poly-extrude
48
49
  extrudePolygons,
49
50
  extrudePolylines,
50
51
  cylinder,
51
- expandPaths
52
+ expandPaths,
53
+ extrudeSlopes
52
54
  } from 'poly-extrude';
53
55
  const polygons = [
54
56
  //polygon
@@ -120,8 +122,6 @@ pnpm i poly-extrude
120
122
  } = result;
121
123
  //do something
122
124
 
123
-
124
-
125
125
  const polylines = [
126
126
  // polyline
127
127
  [
@@ -147,6 +147,32 @@ pnpm i poly-extrude
147
147
  } = result;
148
148
  //do something
149
149
 
150
+ const polylines = [
151
+ // polyline
152
+ [
153
+ [x, y],
154
+ [x, y], ...........
155
+ ],
156
+ //polyline
157
+ [
158
+ [x, y],
159
+ [x, y], ...........
160
+ ],
161
+ ];
162
+
163
+ const result = extrudeSlopes(polylines, {
164
+ depth: 1,
165
+ side: 'left',
166
+ sideDepth: 0,
167
+ lineWidth: 2
168
+ });
169
+ const {
170
+ positon,
171
+ normal,
172
+ uv,
173
+ indices
174
+ } = result;
175
+ //do something
150
176
  ```
151
177
 
152
178
  ### CDN
@@ -225,9 +251,32 @@ pnpm i poly-extrude
225
251
  } = result;
226
252
  //do something
227
253
 
254
+ const polylines = [
255
+ // polyline
256
+ [
257
+ [x, y],
258
+ [x, y], ...........
259
+ ],
260
+ //polyline
261
+ [
262
+ [x, y],
263
+ [x, y], ...........
264
+ ],
265
+ ];
228
266
 
229
-
230
- const polylines = [
267
+ const result = polyextrude.expandPaths(polylines, {
268
+ cornerRadius: 0.5,
269
+ lineWidth: 2
270
+ });
271
+ const {
272
+ positon,
273
+ normal,
274
+ uv,
275
+ indices
276
+ } = result;
277
+ //do something
278
+
279
+ const polylines = [
231
280
  // polyline
232
281
  [
233
282
  [x, y],
@@ -240,8 +289,10 @@ pnpm i poly-extrude
240
289
  ],
241
290
  ];
242
291
 
243
- const result = polyextrude.expandPaths(polylines, {
244
- cornerRadius: 0.5,
292
+ const result = polyextrude.extrudeSlopes(polylines, {
293
+ depth: 1,
294
+ side: 'left',
295
+ sideDepth: 0,
245
296
  lineWidth: 2
246
297
  });
247
298
  const {
package/src/polyline.js CHANGED
@@ -1,7 +1,14 @@
1
1
  import { degToRad, generateNormal, generateSideWallUV, merge, radToDeg } from './util';
2
2
 
3
+ function checkOptions(options) {
4
+ options.lineWidth = Math.max(0, options.lineWidth);
5
+ options.depth = Math.max(0, options.depth);
6
+ options.sideDepth = Math.max(0, options.sideDepth);
7
+ }
8
+
3
9
  export function extrudePolylines(lines, options) {
4
- options = Object.assign({}, { depth: 2, lineWidth: 1 }, options);
10
+ options = Object.assign({}, { depth: 2, lineWidth: 1, bottomStickGround: false }, options);
11
+ checkOptions(options);
5
12
  const results = lines.map(line => {
6
13
  const result = expandLine(line, options);
7
14
  result.line = line;
@@ -18,8 +25,51 @@ export function extrudePolylines(lines, options) {
18
25
  return result;
19
26
  }
20
27
 
28
+ export function extrudeSlopes(lines, options) {
29
+ options = Object.assign({}, { depth: 2, lineWidth: 1, side: 'left', sideDepth: 0, bottomStickGround: false }, options);
30
+ checkOptions(options);
31
+ const { depth, side, sideDepth } = options;
32
+ const results = lines.map(line => {
33
+ const tempResult = expandLine(line, options);
34
+ tempResult.line = line;
35
+ const { leftPoints, rightPoints } = tempResult;
36
+ const result = { line };
37
+ let depths;
38
+ for (let i = 0, len = line.length; i < len; i++) {
39
+ line[i][2] = line[i][2] || 0;
40
+ }
41
+ if (side === 'left') {
42
+ result.leftPoints = leftPoints;
43
+ result.rightPoints = line;
44
+ depths = [sideDepth, depth];
45
+ } else {
46
+ result.leftPoints = line;
47
+ result.rightPoints = rightPoints;
48
+ depths = [depth, sideDepth];
49
+ }
50
+ result.depths = depths;
51
+ generateTopAndBottom(result, options);
52
+ generateSides(result, options);
53
+ result.position = new Float32Array(result.points);
54
+ result.indices = new Uint32Array(result.index);
55
+ result.uv = new Float32Array(result.uvs);
56
+ result.normal = generateNormal(result.indices, result.position);
57
+ return result;
58
+ });
59
+ const result = merge(results);
60
+ result.lines = lines;
61
+ return result;
62
+ }
63
+
21
64
  function generateTopAndBottom(result, options) {
65
+ const bottomStickGround = options.bottomStickGround;
22
66
  const z = options.depth;
67
+ const depths = result.depths;
68
+ let lz = z, rz = z;
69
+ if (depths) {
70
+ lz = depths[0];
71
+ rz = depths[1];
72
+ }
23
73
  const points = [], index = [], uvs = [];
24
74
  const { leftPoints, rightPoints } = result;
25
75
  let i = 0, len = leftPoints.length;
@@ -29,26 +79,32 @@ function generateTopAndBottom(result, options) {
29
79
  const [x1, y1, z1] = leftPoints[i];
30
80
  points[idx0] = x1;
31
81
  points[idx0 + 1] = y1;
32
- points[idx0 + 2] = z + z1;
82
+ points[idx0 + 2] = lz + z1;
33
83
 
34
84
  // top right
35
85
  const [x2, y2, z2] = rightPoints[i];
36
86
  const idx1 = len * 3 + idx0;
37
87
  points[idx1] = x2;
38
88
  points[idx1 + 1] = y2;
39
- points[idx1 + 2] = z + z2;
89
+ points[idx1 + 2] = rz + z2;
40
90
 
41
91
  // bottom left
42
92
  const idx2 = (len * 2) * 3 + idx0;
43
93
  points[idx2] = x1;
44
94
  points[idx2 + 1] = y1;
45
95
  points[idx2 + 2] = z1;
96
+ if (bottomStickGround) {
97
+ points[idx2 + 2] = 0;
98
+ }
46
99
 
47
100
  // bottom right
48
101
  const idx3 = (len * 2) * 3 + len * 3 + idx0;
49
102
  points[idx3] = x2;
50
103
  points[idx3 + 1] = y2;
51
104
  points[idx3 + 2] = z2;
105
+ if (bottomStickGround) {
106
+ points[idx3 + 2] = 0;
107
+ }
52
108
 
53
109
  i++;
54
110
  }
@@ -79,16 +135,51 @@ function generateTopAndBottom(result, options) {
79
135
  result.index = index;
80
136
  result.points = points;
81
137
  result.uvs = uvs;
138
+ if (depths) {
139
+ len = leftPoints.length;
140
+ i = 0;
141
+ while (i < len) {
142
+ leftPoints[i].depth = lz;
143
+ rightPoints[i].depth = rz;
144
+ i++;
145
+ }
146
+ }
82
147
  }
83
148
 
84
149
  function generateSides(result, options) {
85
150
  const { points, index, leftPoints, rightPoints, uvs } = result;
86
151
  const z = options.depth;
152
+ const bottomStickGround = options.bottomStickGround;
87
153
  const rings = [leftPoints, rightPoints];
154
+ const depthsEnable = result.depths;
88
155
 
89
156
  function addOneSideIndex(v1, v2) {
90
157
  const idx = points.length / 3;
91
- points.push(v1[0], v1[1], z + v1[2], v2[0], v2[1], z + v2[2], v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
158
+ let pIndex = points.length - 1;
159
+
160
+ // top
161
+ points[++pIndex] = v1[0];
162
+ points[++pIndex] = v1[1];
163
+ points[++pIndex] = (depthsEnable ? v1.depth : z) + v1[2];
164
+
165
+ points[++pIndex] = v2[0];
166
+ points[++pIndex] = v2[1];
167
+ points[++pIndex] = (depthsEnable ? v2.depth : z) + v2[2];
168
+
169
+ // points.push(v1[0], v1[1], (depthsEnable ? v1.depth : z) + v1[2], v2[0], v2[1], (depthsEnable ? v2.depth : z) + v2[2]);
170
+
171
+ // bottom
172
+
173
+ points[++pIndex] = v1[0];
174
+ points[++pIndex] = v1[1];
175
+ points[++pIndex] = bottomStickGround ? 0 : v1[2];
176
+
177
+ points[++pIndex] = v2[0];
178
+ points[++pIndex] = v2[1];
179
+ points[++pIndex] = bottomStickGround ? 0 : v2[2];
180
+
181
+ // points.push(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
182
+
92
183
  const a = idx + 2, b = idx + 3, c = idx, d = idx + 1;
93
184
  index.push(a, c, b, c, d, b);
94
185
  generateSideWallUV(uvs, points, a, b, c, d);
@@ -209,7 +300,7 @@ const getAngle = ({ x: x1, y: y1 }, { x: x2, y: y2 }) => {
209
300
  return (angle + 360) % 360;
210
301
  };
211
302
 
212
- function leftOnLine(p, p1, p2) {
303
+ export function leftOnLine(p, p1, p2) {
213
304
  const [x1, y1] = p1;
214
305
  const [x2, y2] = p2;
215
306
  const [x, y] = p;