gl-draw 0.15.24 → 0.15.25

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 +1 @@
1
- "use strict";var We=Object.defineProperty,qe=Object.defineProperties;var ke=Object.getOwnPropertyDescriptors;var ce=Object.getOwnPropertySymbols;var Be=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var je=(u,e,t)=>e in u?We(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t,E=(u,e)=>{for(var t in e||(e={}))Be.call(e,t)&&je(u,t,e[t]);if(ce)for(var t of ce(e))Ee.call(e,t)&&je(u,t,e[t]);return u},le=(u,e)=>qe(u,ke(e));var de=(u,e)=>{var t={};for(var n in u)Be.call(u,n)&&e.indexOf(n)<0&&(t[n]=u[n]);if(u!=null&&ce)for(var n of ce(u))e.indexOf(n)<0&&Ee.call(u,n)&&(t[n]=u[n]);return t};var se=(u,e,t)=>new Promise((n,s)=>{var i=r=>{try{m(t.next(r))}catch(f){s(f)}},a=r=>{try{m(t.throw(r))}catch(f){s(f)}},m=r=>r.done?n(r.value):Promise.resolve(r.value).then(i,a);m((t=t.apply(u,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Oe=require("three/examples/jsm/lines/LineMaterial"),Ie=require("three/examples/jsm/lines/LineSegmentsGeometry"),P=require("../WebGPULineSegments2.js"),c=require("three"),pe=require("three/examples/jsm/utils/BufferGeometryUtils"),Pe=require("../uvGenerator.js"),he=require("three-bvh-csg"),Fe=require("three/examples/jsm/lights/RectAreaLightUniformsLib"),Ye=require("@tweenjs/tween.js"),Ze=require("three/examples/jsm/lines/LineSegments2");function $e(u){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const t in u)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(u,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>u[t]})}}return e.default=u,Object.freeze(e)}const ee=$e(Ye);function D(u,e=0){const t=u[0].index!==null,n=new Set(Object.keys(u[0].attributes)),s=new Set(Object.keys(u[0].morphAttributes)),i={},a={},m=u[0].morphTargetsRelative,r=new c.BufferGeometry;let f=0;for(let o=0;o<u.length;++o){const l=u[o];let b=0;if(t!==(l.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const d in l.attributes){if(!n.has(d))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+'. All geometries must have compatible attributes; make sure "'+d+'" attribute exists among all geometries, or in none of them.'),null;i[d]===void 0&&(i[d]=[]),i[d].push(l.attributes[d]),b++}if(b!==n.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". Make sure all geometries have the same number of attributes."),null;if(m!==l.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const d in l.morphAttributes){if(!s.has(d))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". .morphAttributes must be consistent throughout all geometries."),null;a[d]===void 0&&(a[d]=[]),a[d].push(l.morphAttributes[d])}if(e){let d;if(t)d=l.index.count;else if(l.attributes.position!==void 0)d=l.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". The geometry must have either an index or a position attribute"),null;if(e===1)r.addGroup(f,d,o);else if(e===2&&l.groups.length>0)for(let y of l.groups){let C=y.materialIndex;r.addGroup(f+y.start,Math.min(y.count,d),C)}f+=d}}if(t){let o=0;const l=[];for(let b=0;b<u.length;++b){const d=u[b].index;for(let y=0;y<d.count;++y)l.push(d.getX(y)+o);o+=u[b].attributes.position.count}r.setIndex(l)}for(const o in i){const l=pe.mergeAttributes(i[o]);if(!l)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+o+" attribute."),null;r.setAttribute(o,l)}for(const o in a){const l=a[o][0].length;if(l===0)break;r.morphAttributes=r.morphAttributes||{},r.morphAttributes[o]=[];for(let b=0;b<l;++b){const d=[];for(let C=0;C<a[o].length;++C)d.push(a[o][C][b]);const y=pe.mergeAttributes(d);if(!y)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+o+" morphAttribute."),null;r.morphAttributes[o].push(y)}}return e===2?pe.mergeGroups(r):r}const Ve=u=>{const m=u,{coordinate:e,startHeight:t,height:n}=m,s=de(m,["coordinate","startHeight","height"]);let i=t||0;return typeof t!="undefined"&&typeof n!="undefined"&&(i=t+n),new P.PolygonGeometry([e],le(E({},s),{startHeight:t,endHeight:i}))};class Je extends P.BaseObject{constructor(e){super(),this.options=E({},e)}create(){const r=this.options,{geometry:e,coordinateArr:t,coordinate:n,material:s,useGroups:i}=r,a=de(r,["geometry","coordinateArr","coordinate","material","useGroups"]);let m=e;if(!m&&n)m=Ve(E({coordinate:n},a));else if(!m&&t){const f=t.map(o=>Ve(E({coordinate:o},a)));m=D(f,i!=null?i:0)}this.createMesh(m,s)}}const Qe={ArcCurve:c.ArcCurve,CatmullRomCurve3:c.CatmullRomCurve3,CubicBezierCurve:c.CubicBezierCurve,CubicBezierCurve3:c.CubicBezierCurve3,EllipseCurve:c.EllipseCurve,LineCurve:c.LineCurve,LineCurve3:c.LineCurve3,QuadraticBezierCurve:c.QuadraticBezierCurve,QuadraticBezierCurve3:c.QuadraticBezierCurve3,SplineCurve:c.SplineCurve};class J extends c.BufferGeometry{constructor(e=new c.Shape([new c.Vector2(.5,.5),new c.Vector2(-.5,.5),new c.Vector2(-.5,-.5),new c.Vector2(.5,-.5)]),t={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:e,options:t},e=Array.isArray(e)?e:[e];const n=this,s=[],i=[];for(let m=0,r=e.length;m<r;m++){const f=e[m];a(f)}this.setAttribute("position",new c.Float32BufferAttribute(s,3)),this.setAttribute("uv",new c.Float32BufferAttribute(i,2)),this.computeVertexNormals();function a(m){var ve,Se,Ae;const r=[],f=t.curveSegments!==void 0?t.curveSegments:12,o=t.steps!==void 0?t.steps:1,l=t.depth!==void 0?t.depth:1;let b=t.bevelEnabled!==void 0?t.bevelEnabled:!0,d=t.bevelThickness!==void 0?t.bevelThickness:.2,y=t.bevelSize!==void 0?t.bevelSize:d-.1,C=t.bevelOffset!==void 0?t.bevelOffset:0,A=t.bevelSegments!==void 0?t.bevelSegments:3;const M=t.extrudePath,B=t.UVGenerator!==void 0?t.UVGenerator:Ke,S=(ve=t.hasTop)!=null?ve:!0,V=(Se=t.hasBottom)!=null?Se:!0,Q=(Ae=t.hasSide)!=null?Ae:!0;let H,Y=!1,U,te,ne,N;M&&(H=M.getSpacedPoints(o),Y=!0,b=!1,U=M.computeFrenetFrames(o,!1),te=new c.Vector3,ne=new c.Vector3,N=new c.Vector3),b||(A=0,d=0,y=0,C=0);const ge=m.extractPoints(f);let I=ge.shape;const _=ge.holes;if(!c.ShapeUtils.isClockWise(I)){I=I.reverse();for(let h=0,p=_.length;h<p;h++){const g=_[h];c.ShapeUtils.isClockWise(g)&&(_[h]=g.reverse())}}function ye(h){const g=10000000000000001e-36;let w=h[0];for(let x=1;x<=h.length;x++){const L=x%h.length,v=h[L],T=v.x-w.x,G=v.y-w.y,j=T*T+G*G,z=Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(w.x),Math.abs(w.y)),$=g*z*z;if(j<=$){h.splice(L,1),x--;continue}w=v}}ye(I),_.forEach(ye);const ue=_.length,R=I;for(let h=0;h<ue;h++){const p=_[h];I=I.concat(p)}function K(h,p,g){return p||console.error("THREE.ExtrudeGeometry: vec does not exist"),h.clone().addScaledVector(p,g)}const X=I.length;function be(h,p,g){let w,x,L;const v=h.x-p.x,T=h.y-p.y,G=g.x-h.x,j=g.y-h.y,z=v*v+T*T,$=v*j-T*G;if(Math.abs($)>Number.EPSILON){const O=Math.sqrt(z),Me=Math.sqrt(G*G+j*j),Le=p.x-T/O,Ce=p.y+v/O,Ne=g.x-j/Me,Xe=g.y+G/Me,Te=((Ne-Le)*j-(Xe-Ce)*G)/(v*j-T*G);w=Le+v*Te-h.x,x=Ce+T*Te-h.y;const Ge=w*w+x*x;if(Ge<=2)return new c.Vector2(w,x);L=Math.sqrt(Ge/2)}else{let O=!1;v>Number.EPSILON?G>Number.EPSILON&&(O=!0):v<-Number.EPSILON?G<-Number.EPSILON&&(O=!0):Math.sign(T)===Math.sign(j)&&(O=!0),O?(w=-T,x=v,L=Math.sqrt(z)):(w=v,x=T,L=Math.sqrt(z/2))}return new c.Vector2(w/L,x/L)}const oe=[];for(let h=0,p=R.length,g=p-1,w=h+1;h<p;h++,g++,w++)g===p&&(g=0),w===p&&(w=0),oe[h]=be(R[h],R[g],R[w]);const fe=[];let F,ie=oe.concat();for(let h=0,p=ue;h<p;h++){const g=_[h];F=[];for(let w=0,x=g.length,L=x-1,v=w+1;w<x;w++,L++,v++)L===x&&(L=0),v===x&&(v=0),F[w]=be(g[w],g[L],g[v]);fe.push(F),ie=ie.concat(F)}let Z;if(A===0)Z=c.ShapeUtils.triangulateShape(R,_);else{const h=[],p=[];for(let g=0;g<A;g++){const w=g/A,x=d*Math.cos(w*Math.PI/2),L=y*Math.sin(w*Math.PI/2)+C;for(let v=0,T=R.length;v<T;v++){const G=K(R[v],oe[v],L);W(G.x,G.y,-x),w===0&&h.push(G)}for(let v=0,T=ue;v<T;v++){const G=_[v];F=fe[v];const j=[];for(let z=0,$=G.length;z<$;z++){const O=K(G[z],F[z],L);W(O.x,O.y,-x),w===0&&j.push(O)}w===0&&p.push(j)}}Z=c.ShapeUtils.triangulateShape(h,p)}const re=Z.length,xe=y+C;for(let h=0;h<X;h++){const p=b?K(I[h],ie[h],xe):I[h];Y?(ne.copy(U.normals[0]).multiplyScalar(p.x),te.copy(U.binormals[0]).multiplyScalar(p.y),N.copy(H[0]).add(ne).add(te),W(N.x,N.y,N.z)):W(p.x,p.y,0)}for(let h=1;h<=o;h++)for(let p=0;p<X;p++){const g=b?K(I[p],ie[p],xe):I[p];Y?(ne.copy(U.normals[h]).multiplyScalar(g.x),te.copy(U.binormals[h]).multiplyScalar(g.y),N.copy(H[h]).add(ne).add(te),W(N.x,N.y,N.z)):W(g.x,g.y,l/o*h)}for(let h=A-1;h>=0;h--){const p=h/A,g=d*Math.cos(p*Math.PI/2),w=y*Math.sin(p*Math.PI/2)+C;for(let x=0,L=R.length;x<L;x++){const v=K(R[x],oe[x],w);W(v.x,v.y,l+g)}for(let x=0,L=_.length;x<L;x++){const v=_[x];F=fe[x];for(let T=0,G=v.length;T<G;T++){const j=K(v[T],F[T],w);Y?W(j.x,j.y+H[o-1].y,H[o-1].x+g):W(j.x,j.y,l+g)}}}Re(),Q&&De();function Re(){const h=s.length/3;if(b){let p=0,g=X*p;if(V)for(let w=0;w<re;w++){const x=Z[w];ae(x[2]+g,x[1]+g,x[0]+g)}if(p=o+A*2,g=X*p,S)for(let w=0;w<re;w++){const x=Z[w];ae(x[0]+g,x[1]+g,x[2]+g)}}else{if(V)for(let p=0;p<re;p++){const g=Z[p];ae(g[2],g[1],g[0])}if(S)for(let p=0;p<re;p++){const g=Z[p];ae(g[0]+X*o,g[1]+X*o,g[2]+X*o)}}n.addGroup(h,s.length/3-h,0)}function De(){const h=s.length/3;let p=0;we(R,p),p+=R.length;for(let g=0,w=_.length;g<w;g++){const x=_[g];we(x,p),p+=x.length}n.addGroup(h,s.length/3-h,1)}function we(h,p){let g=h.length;for(;--g>=0;){const w=g;let x=g-1;x<0&&(x=h.length-1);for(let L=0,v=o+A*2;L<v;L++){const T=X*L,G=X*(L+1),j=p+w+T,z=p+x+T,$=p+x+G,O=p+w+G;He(j,z,$,O)}}}function W(h,p,g){r.push(h),r.push(p),r.push(g)}function ae(h,p,g){q(h),q(p),q(g);const w=s.length/3,x=B.generateTopUV(n,s,w-3,w-2,w-1);k(x[0]),k(x[1]),k(x[2])}function He(h,p,g,w){q(h),q(p),q(w),q(p),q(g),q(w);const x=s.length/3,L=B.generateSideWallUV(n,s,x-6,x-3,x-2,x-1);k(L[0]),k(L[1]),k(L[3]),k(L[1]),k(L[2]),k(L[3])}function q(h){s.push(r[h*3+0]),s.push(r[h*3+1]),s.push(r[h*3+2])}function k(h){i.push(h.x),i.push(h.y)}}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON(),t=this.parameters.shapes,n=this.parameters.options;return et(t,n,e)}static fromJSON(e,t){const n=[];for(let i=0,a=e.shapes.length;i<a;i++){const m=t[e.shapes[i]];n.push(m)}const s=e.options.extrudePath;return s!==void 0&&(e.options.extrudePath=new Qe[`${s.type}`]().fromJSON(s)),new J(n,e.options)}}const Ke={generateTopUV:function(u,e,t,n,s){const i=e[t*3],a=e[t*3+1],m=e[n*3],r=e[n*3+1],f=e[s*3],o=e[s*3+1];return[new c.Vector2(i,a),new c.Vector2(m,r),new c.Vector2(f,o)]},generateSideWallUV:function(u,e,t,n,s,i){const a=e[t*3],m=e[t*3+1],r=e[t*3+2],f=e[n*3],o=e[n*3+1],l=e[n*3+2],b=e[s*3],d=e[s*3+1],y=e[s*3+2],C=e[i*3],A=e[i*3+1],M=e[i*3+2];return Math.abs(m-o)<Math.abs(a-f)?[new c.Vector2(a,1-r),new c.Vector2(f,1-l),new c.Vector2(b,1-y),new c.Vector2(C,1-M)]:[new c.Vector2(m,1-r),new c.Vector2(o,1-l),new c.Vector2(d,1-y),new c.Vector2(A,1-M)]}};function et(u,e,t){if(t.shapes=[],Array.isArray(u))for(let n=0,s=u.length;n<s;n++){const i=u[n];t.shapes.push(i.uuid)}else t.shapes.push(u.uuid);return t.options=Object.assign({},e),e.extrudePath!==void 0&&(t.options.extrudePath=e.extrudePath.toJSON()),t}class tt extends J{constructor(e,t){super(e,t);const n=new he.Brush(new J(e,le(E({},t),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const s=new c.Box3().setFromObject(n),i=new c.Vector3;s.getSize(i);const a=new c.Vector3(s.min.x+i.x/2,s.min.y+i.y/2,0);let m=t.topSegments,r=t.box3;if(r){r=r.union(s);const M=new c.Vector3;r.getSize(M);const B=Math.max(i.x/M.x,i.y/M.y);m=Math.ceil(t.topSegments*B)}if(m<4)return this;const f=new c.PlaneGeometry(i.x,i.y,m,m),o=new he.Brush(f);o.position.set(a.x,a.y,a.z),o.updateMatrixWorld();const b=new he.Evaluator().evaluate(o,n,he.INTERSECTION),d=b.geometry.getAttribute("position"),y=new c.Float32BufferAttribute(d.count*2,2);for(let M=0;M<d.count;M++){const B=d.getZ(M);d.setZ(M,t.depth+B)}if(r){const M=r.min,B=r.max,S=new c.Vector3().subVectors(B,M);for(let V=0;V<d.count;V++){const Q=d.getX(V),H=d.getY(V),Y=(Q-M.x)/S.x,U=(H-M.y)/S.y;y.setXY(V,Y,U)}b.geometry.setAttribute("uv",y)}d.needsUpdate=!0;const C=new J(e,le(E({},t),{hasTop:!1})),A=D([b.geometry,C],2);this.copy(A.toNonIndexed())}}const _e=u=>{const{split:e,depth:t,points:n,box3:s,hasTop:i,hasBottom:a,hasSide:m,sideRepeat:r,topSegments:f}=u,o=f?tt:J,l=new o(new c.Shape(n),{depth:t,bevelEnabled:!1,box3:s,UVGenerator:Pe.getUVGenerator({split:e,box3:s,sideRepeat:r}),hasTop:i,hasBottom:a,hasSide:m,topSegments:f});return Pe.claerUVGenerator(),l};class nt extends P.BaseObject{constructor(e){super(),this.options=E({depth:1},e)}create(){return se(this,null,function*(){const{points:e,pointsArr:t,useGroups:n,depth:s,geometry:i,geometryArr:a,material:m,box3:r,split:f,hasTop:o,hasBottom:l,hasSide:b}=this.options,d=Array.isArray(s)?s:[s],y=Array.isArray(r)?r:[r],C=m;let A=i;C||console.log("material is null"),!A&&e?A=_e({points:e,depth:d[0],box3:y[0],split:f,hasTop:o,hasBottom:l,hasSide:b}):!A&&t?A=D(t.map((M,B)=>{var S,V;return _e({points:M,depth:(S=d[B])!=null?S:d[0],box3:(V=y[B])!=null?V:y[0],split:f,hasTop:o,hasBottom:l,hasSide:b})}),n!=null?n:0):!A&&a&&a.length>1?A=D(a,n!=null?n:0):!A&&a&&a.length===1&&([A]=a),this.createMesh(A,C)})}addGeometries(e){const t=this.object3d,n=D([t.geometry,...e]);t.geometry=n}setTextureAnisotropic(e,t){e.anisotropy=t||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const st=u=>{const{topColor:e,sideColor:t,sideMap:n,createCanvasObjectURL:s,split:i,maxAnisotropy:a}=u;return new Promise(m=>{const r=n?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};r.onload=()=>{const f=i,o=document.createElement("canvas"),l=o.getContext("2d");o.height=r.height/(1-f),o.width=r.width,f&&e&&(l.fillStyle=e,l.fillRect(0,0,r.width,o.height*f)),n&&r instanceof HTMLImageElement?l.drawImage(r,0,o.height*f,r.width,r.height):t&&(l.fillStyle=t,l.fillRect(0,o.height*f,r.width,r.height)),s&&o.toBlob(d=>{console.log(URL.createObjectURL(d))});const b=new c.CanvasTexture(o);m(b)},n?r.src=n:r instanceof HTMLImageElement||r.onload()})};class ot extends P.BaseObject{create(){this.createGroup()}}class it extends P.BaseObject{constructor(e){super(),this.rectAreaLightUniformsLibInit=!1,this.options=e}create(){var t,n,s,i,a,m,r,f,o,l,b,d,y,C,A,M,B;const e=this.options;if(e.type==="AmbientLight"){const S=new c.AmbientLight(e.color);S.name="环境光",this.object3d=S}else if(e.type==="DirectionalLight"){const S=new c.DirectionalLight(e.color,e.intensity);S.name="平行光",S.target.position.set(0,0,0),this.object3d=S,S.target.name="平行光目标",S.shadow.camera.name="平行光阴影相机",S.shadow.camera.userData.directionalLightShadow=!0,this.directionalLight=S}else if(e.type==="PointLight"){const S=new c.PointLight((t=e.color)!=null?t:16777215,(n=e.intensity)!=null?n:1,(s=e.distance)!=null?s:0,(i=e.decay)!=null?i:2);S.name="点光源",this.object3d=S,this.pointLight=S}else if(e.type==="SpotLight"){const S=new c.SpotLight((a=e.color)!=null?a:16777215,(m=e.intensity)!=null?m:1,(r=e.distance)!=null?r:0,(f=e.angle)!=null?f:Math.PI/3,(o=e.penumbra)!=null?o:1,(l=e.decay)!=null?l:2);S.name="聚光灯",this.object3d=S,this.spotLight=S,S.target.name="聚光灯目标"}else if(e.type==="HemisphereLight"){const S=new c.HemisphereLight((b=e.color)!=null?b:16777215,(d=e.groundColor)!=null?d:16777215,(y=e.intensity)!=null?y:1);S.name="半球光",this.object3d=S,this.hemisphereLight=S}else if(e.type==="RectAreaLight"){this.rectAreaLightUniformsLibInit||(Fe.RectAreaLightUniformsLib.init(),this.rectAreaLightUniformsLibInit=!0);const S=new c.RectAreaLight((C=e.color)!=null?C:16777215,(A=e.intensity)!=null?A:1,(M=e.width)!=null?M:10,(B=e.height)!=null?B:10);S.name="矩形区域光",this.object3d=S,this.rectAreaLight=S}}render(){const e=this.object3d;e.target&&this.pencil.scene.add(e.target);const t=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const n=this.spotLight||this.directionalLight;n.position.copy(t),n.target.position.copy(t)}else this.pointLight&&this.pointLight.position.copy(t)}dispose(){const e=this.object3d;e.target&&this.pencil.scene.remove(e.target),super.dispose()}}class Ue extends c.BufferGeometry{constructor(e=[],t="none",n){super(),this.type="MeshLineGeometry",this.pointCount=0,this._points=[],this.shape="none",this.shapeFunction=s=>1,this.matrixWorld=new c.Matrix4,this.shape=t,n&&(this.shapeFunction=n),e.length>0&&this.setPoints(e)}convertToVector3Array(e){if(typeof e[0]=="number"){const t=[],n=e;for(let s=0;s<n.length;s+=3)t.push(new c.Vector3(n[s],n[s+1],n[s+2]));return t}else return e.map(t=>{if(t instanceof c.Vector2)return new c.Vector3(t.x,t.y,0);if(t instanceof c.Vector3)return t;if(Array.isArray(t)&&t.length===2)return new c.Vector3(t[0],t[1],0);if(Array.isArray(t)&&t.length===3)return new c.Vector3(t[0],t[1],t[2])}).filter(Boolean)}setMatrixWorld(e){this.matrixWorld=e}setPoints(e,t){!e||e.length===0||(this._points=this.convertToVector3Array(e),this.pointCount=this._points.length,t&&(this.shapeFunction=t,this.shape="custom"),this.initializeGeometry(),this.updateGeometry())}initializeGeometry(){const e=new c.BufferAttribute(new Float32Array(this.pointCount*6),3),t=new c.BufferAttribute(new Float32Array(this.pointCount*6),3),n=new c.BufferAttribute(new Float32Array(this.pointCount*6),3),s=new c.BufferAttribute(new Float32Array(this.pointCount*2),1),i=new c.BufferAttribute(new Float32Array(this.pointCount*2),1),a=new c.BufferAttribute(new Float32Array(this.pointCount*2),1),m=new c.BufferAttribute(new Float32Array(this.pointCount*4),2),r=new c.BufferAttribute(new Uint16Array((this.pointCount-1)*6),1);this.shape==="taper"&&(this.shapeFunction=f=>1*Math.pow(4*f*(1-f),1));for(let f=0,o=0,l=0;f<this.pointCount;f+=1,o+=2,l+=6){s.setX(o,f/this.pointCount),s.setX(o+1,f/this.pointCount),i.setX(o,1),i.setX(o+1,-1);const b=this.shape==="none"?1:this.shapeFunction(f/(this.pointCount-1));a.setX(o,b),a.setX(o+1,b);const d=f/(this.pointCount-1);if(m.setXY(o,d,0),m.setXY(o+1,d,1),f<this.pointCount-1){const y=f*2;r.setX(l+0,y+0),r.setX(l+1,y+1),r.setX(l+2,y+2),r.setX(l+3,y+2),r.setX(l+4,y+1),r.setX(l+5,y+3)}}this.setAttribute("position",e),this.setAttribute("previous",t),this.setAttribute("next",n),this.setAttribute("counters",s),this.setAttribute("side",i),this.setAttribute("width",a),this.setAttribute("uv",m),this.setIndex(r)}updateGeometry(){if(!this._points[0])return;const e=this.getAttribute("position"),t=this.getAttribute("previous"),n=this.getAttribute("next");let s=0,i=0,a=0;const m=this._points[0];t.setXYZ(i,m.x,m.y,m.z),i+=1,t.setXYZ(i,m.x,m.y,m.z),i+=1;for(let f=0;f<this.pointCount;f++){const o=this._points[f];e.setXYZ(s,o.x,o.y,o.z),s+=1,e.setXYZ(s,o.x,o.y,o.z),s+=1,f<this.pointCount-1&&(t.setXYZ(i,o.x,o.y,o.z),i+=1,t.setXYZ(i,o.x,o.y,o.z),i+=1),f>0&&f+1<=this.pointCount&&(n.setXYZ(a,o.x,o.y,o.z),a+=1,n.setXYZ(a,o.x,o.y,o.z),a+=1)}const r=this._points[this.pointCount-1];n.setXYZ(a,r.x,r.y,r.z),a+=1,n.setXYZ(a,r.x,r.y,r.z),a+=1,e.needsUpdate=!0,t.needsUpdate=!0,n.needsUpdate=!0,this.computeBoundingSphere(),this.computeBoundingBox()}get points(){return this._points}set points(e){this.setPoints(e)}updatePoints(e,t){const n=this.convertToVector3Array(e);if(n.length!==this.pointCount){console.warn("MeshLineGeometry: Cannot update points with different length. Use setPoints() instead.");return}this._points=n,t&&(this.shapeFunction=t,this.shape="custom",this.initializeGeometry()),this.updateGeometry()}setShape(e,t){this.shape=e,t&&(this.shapeFunction=t),this._points.length>0&&(this.initializeGeometry(),this.updateGeometry())}}function rt(u,e){const t=new c.Matrix4,n=new c.Ray,s=new c.Sphere,i=new c.Vector3,a=this.geometry;if(s.copy(a.boundingSphere),s.applyMatrix4(this.matrixWorld),!u.ray.intersectSphere(s,i))return;t.copy(this.matrixWorld).invert(),n.copy(u.ray).applyMatrix4(t);const m=new c.Vector3,r=new c.Vector3,f=new c.Vector3,o=this instanceof c.LineSegments?2:1,l=a.index,b=a.attributes;if(l!==null){const d=l.array,y=b.position.array,C=b.width.array;for(let A=0,M=d.length-1;A<M;A+=o){const B=d[A],S=d[A+1];m.fromArray(y,B*3),r.fromArray(y,S*3);const V=C[Math.floor(A/3)]!==void 0?C[Math.floor(A/3)]:1,Q=u.params.Line.threshold+this.material.lineWidth*V/2,H=Q*Q;if(n.distanceSqToSegment(m,r,i,f)>H)continue;i.applyMatrix4(this.matrixWorld);const U=u.ray.origin.distanceTo(i);U<u.near||U>u.far||(e.push({distance:U,point:f.clone().applyMatrix4(this.matrixWorld),index:A,face:null,faceIndex:void 0,object:this}),A=M)}}}const me=u=>{const{setPointWidth:e,nodes:t}=u,n=new Ue;return n.setPoints(t,e),n};let at=class extends P.BaseObject{constructor(e={}){super(),this.options=E({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return se(this,null,function*(){const{nodes:e,nodesArr:t,geometry:n,geometryArr:s,material:i,useGroups:a,setPointWidth:m,lineWidthArr:r,materialParameters:f}=this.options;let o=i,l=n;!o&&f&&(o=this.getMaterial(f)),!l&&e?l=me({nodes:e,setPointWidth:m}):!l&&t?l=D(t.map((b,d)=>{let y=m;return!y&&r&&(y=()=>{var C;return(C=r[d])!=null?C:r[0]}),me({nodes:b,setPointWidth:y})}),a!=null?a:0):!l&&s&&s.length>1?l=D(s,a!=null?a:0):!l&&s&&s.length===1&&([l]=s),this.createMesh(l,o)})}setGeometry(e,t){const n=me({nodes:e,setPointWidth:t}),s=this.object3d,i=s.geometry;s.geometry=n,i.dispose()}getMaterial(e){const{width:t,height:n}=this.pencil.getSize(),s=new P.MeshLineMaterial(E({color:new c.Color("#ffffff")},e));return s.uniforms.resolution.value.set(t,n),s}addGeometries(e){const t=this.object3d,n=D([t.geometry,...e]);t.geometry=n}resize(e,t){var n,s;(s=(n=this.material)==null?void 0:n.uniforms)==null||s.resolution.value.set(e,t)}handleMaterialChange(e){if(e){const{width:t,height:n}=this.pencil.getSize();this.resize(t,n)}}animate({duration:e=1e3,delay:t=0,repeat:n=0,lineLoop:s,onRepeat:i,onUpdate:a,onComplete:m,startShow:r}={}){const{offset:f,offsetLoop:o}=this.material.uniforms;if(this.material.userData.tween)return;const l=s!=null?s:!0;f.value.x=1,o.value=l&&r?1:0;let b=0;const d=new ee.Tween(f.value).to({x:-1},e).delay(t).repeat(n).onUpdate(({x:y})=>{l&&y<=0&&o.value===0&&(o.value=1),a&&a(y)}).onRepeat(()=>{b+=1,i&&i(b)}).onComplete(()=>{m&&m()}).start();this.material.userData.tween=d}render(){const{width:e,height:t}=this.pencil.getSize();this.resize(e,t)}dispose(){this.material.userData.tween&&(this.material.userData.tween.stop(),ee.remove(this.material.userData.tween)),super.dispose()}};const ze=u=>{const{points:e}=u,t=e.reduce((s,i,a)=>(a<e.length-1&&s.push(i,e[a+1]),s),[]);return new c.BufferGeometry().setFromPoints(t)};class ct extends P.BaseObject{constructor(e={}){super(),this.options=E({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return se(this,null,function*(){const{points:e,pointsArr:t,geometry:n,geometryArr:s,material:i,useGroups:a,setPointWidth:m,lineWidthArr:r,materialParameters:f,instanceCount:o}=this.options;let l=i,b=n;!l&&f&&(l=this.getMaterial(f)),!b&&e?b=ze({points:e}):!b&&t?b=D(t.map(y=>ze({points:y})),a!=null?a:0):!b&&s&&s.length>1?b=D(s,a!=null?a:0):!b&&s&&s.length===1&&([b]=s);const d=new Ie.LineSegmentsGeometry().fromLineSegments(new c.LineSegments(b));if(this.pencil.options.WebGPUTHREE){o&&(d.instanceCount=o);const y=new P.LineSegments2(d,l);y.computeLineDistances(),this.object3d=y}else{const y=new Ze.LineSegments2(d,l);y.computeLineDistances(),this.object3d=y}})}getMaterial(e){return new Oe.LineMaterial(E({color:new c.Color("#ffffff")},e))}}class lt extends P.BaseObject{constructor(e){super(),this.objectType="BaseObject#Node",this.onNodePointerIndex=[],this.options=E({type:"2d"},e)}create(){const{position:e,children:t}=this.options,n=document.createElement("div");this.element=n,t&&n.appendChild(t),this.options.type==="3d"?this.createCSS3DObject(n):this.options.type==="3dSprite"?this.createCSS3DSprite(n):this.createCSS2DObject(n),e&&this.object3d.position.copy(e)}setChildren(e){this.options.children=e,this.element.innerHTML="",this.element.appendChild(e)}showAndEnsureVisible(){const e=this.options.children;e&&(e.style.visibility="hidden",this.show(),setTimeout(()=>{e.style.visibility="",this.ensureVisible()}))}moveElementToViewport(){const e=this.options.children;if(!e)return;const t=e.getBoundingClientRect(),n=window.innerWidth,s=window.innerHeight;let i=0,a=0;t.left<0?i=-t.left:t.right>n&&(i=n-t.right),t.top<0?a=-t.top:t.bottom>s&&(a=s-t.bottom),t.left+i<0&&(i=-t.left),t.top+a<0&&(a=-t.top),(i!==0||a!==0)&&(e.style.transform=`translate(${i}px, ${a}px)`)}ensureVisible(){const e=this.options.children;if(!e)return;e.style.transform&&(e.style.transform="");const t=new IntersectionObserver(n=>{n.forEach(s=>{s.isIntersecting&&(this.moveElementToViewport(),t.disconnect())})});t.observe(e)}onPointerEvent(e,t){const n=this.lead.handlePickNode([this],e,t);this.onNodePointerIndex.push(n)}dispose(){this.onNodePointerIndex.forEach(e=>{this.lead.removePickNode(e)}),super.dispose()}}class ht extends P.BaseObject{constructor(e){super(),this.options=E({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},e)}create(){return se(this,null,function*(){this.createGroup();const{data:e,maxDepth:t,colors:n,material:s,percentDepth:i,activeIndex:a}=this.options,m=Math.max(...e),r=e.reduce((o,l)=>o+l,0);let f=Math.PI/2;e.forEach((o,l)=>{if(o===0)return;const b=Math.PI*2*(o/r),d=n[l],y=i?t*(o/m):t,C=this.createGeometry(y,b),A=s?s.clone():new c.MeshBasicMaterial({color:d});s&&A.color.set(d);const M=new c.Mesh(C,A);M.userData.depth=y,M.userData.index=l,M.rotateZ(f),f+=b,this.add(M)}),a!==-1&&this.setActive(a)})}createGeometry(e,t){const{outRadius:n,innerRadius:s}=this.options,i=new c.Shape;return i.moveTo(n,0),i.lineTo(s,0),i.absarc(0,0,s,0,t,!1),i.absarc(0,0,n,t,0,!0),new J(i,{curveSegments:48,depth:e,bevelEnabled:!1})}handlePick(e,t=1.3){const{object:n}=this.pencil.pick(e,this.object3d.children)||{},s=n?this.object3d.children.findIndex(i=>i===n):this.options.activeIndex;return this.setActive(s,t)}setActive(e,t=1.3){const n=this.object3d.children[e];if(this.object3d.children.forEach(s=>{if(!(n&&n===s)&&s.scale.z!==1){if(s.userData.levTween)return;s.userData.enTween&&(s.userData.enTween.stop(),s.userData.enTween=null);const i=new ee.Tween(s.scale).to({z:1},100);s.userData.levTween=i,i.start()}}),n){if(n.userData.enTween)return;n.userData.levTween&&(n.userData.levTween.stop(),n.userData.levTween=null);const s=new ee.Tween(n.scale).to({z:t},100);return n.userData.enTween=s,s.start(),n.userData.index}return-1}render(){this.object3d.scale.z=0,new ee.Tween(this.object3d.scale).to({z:1},1e3).easing(ee.Easing.Sinusoidal.InOut).start()}}Object.defineProperty(exports,"Line2Material",{enumerable:!0,get:()=>Oe.LineMaterial});Object.defineProperty(exports,"LineSegmentsGeometry",{enumerable:!0,get:()=>Ie.LineSegmentsGeometry});exports.MeshLineMaterial=P.MeshLineMaterial;exports.getConicPolygonGeometry=P.PolygonGeometry;exports.getConicPolygonGeometryMetas=P.getMetas;exports.ConicPolygon=Je;exports.ExtrudePolygon=nt;exports.Group=ot;exports.Light=it;exports.Line=at;exports.Line2=ct;exports.MeshLineGeometry=Ue;exports.MeshLineRaycast=rt;exports.Node=lt;exports.Pie=ht;exports.getSplitTexture=st;
1
+ "use strict";var We=Object.defineProperty,qe=Object.defineProperties;var ke=Object.getOwnPropertyDescriptors;var ce=Object.getOwnPropertySymbols;var je=Object.prototype.hasOwnProperty,Be=Object.prototype.propertyIsEnumerable;var Ee=(u,e,t)=>e in u?We(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t,B=(u,e)=>{for(var t in e||(e={}))je.call(e,t)&&Ee(u,t,e[t]);if(ce)for(var t of ce(e))Be.call(e,t)&&Ee(u,t,e[t]);return u},le=(u,e)=>qe(u,ke(e));var de=(u,e)=>{var t={};for(var n in u)je.call(u,n)&&e.indexOf(n)<0&&(t[n]=u[n]);if(u!=null&&ce)for(var n of ce(u))e.indexOf(n)<0&&Be.call(u,n)&&(t[n]=u[n]);return t};var se=(u,e,t)=>new Promise((n,s)=>{var i=r=>{try{m(t.next(r))}catch(f){s(f)}},a=r=>{try{m(t.throw(r))}catch(f){s(f)}},m=r=>r.done?n(r.value):Promise.resolve(r.value).then(i,a);m((t=t.apply(u,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Oe=require("three/examples/jsm/lines/LineMaterial"),Ie=require("three/examples/jsm/lines/LineSegmentsGeometry"),P=require("../WebGPULineSegments2.js"),c=require("three"),pe=require("three/examples/jsm/utils/BufferGeometryUtils"),Pe=require("../uvGenerator.js"),he=require("three-bvh-csg"),Fe=require("three/examples/jsm/lights/RectAreaLightUniformsLib"),Ye=require("@tweenjs/tween.js"),Ze=require("three/examples/jsm/lines/LineSegments2");function $e(u){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const t in u)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(u,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>u[t]})}}return e.default=u,Object.freeze(e)}const ee=$e(Ye);function D(u,e=0){const t=u[0].index!==null,n=new Set(Object.keys(u[0].attributes)),s=new Set(Object.keys(u[0].morphAttributes)),i={},a={},m=u[0].morphTargetsRelative,r=new c.BufferGeometry;let f=0;for(let o=0;o<u.length;++o){const l=u[o];let b=0;if(t!==(l.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const d in l.attributes){if(!n.has(d))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+'. All geometries must have compatible attributes; make sure "'+d+'" attribute exists among all geometries, or in none of them.'),null;i[d]===void 0&&(i[d]=[]),i[d].push(l.attributes[d]),b++}if(b!==n.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". Make sure all geometries have the same number of attributes."),null;if(m!==l.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const d in l.morphAttributes){if(!s.has(d))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". .morphAttributes must be consistent throughout all geometries."),null;a[d]===void 0&&(a[d]=[]),a[d].push(l.morphAttributes[d])}if(e){let d;if(t)d=l.index.count;else if(l.attributes.position!==void 0)d=l.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". The geometry must have either an index or a position attribute"),null;if(e===1)r.addGroup(f,d,o);else if(e===2&&l.groups.length>0)for(let y of l.groups){let C=y.materialIndex;r.addGroup(f+y.start,Math.min(y.count,d),C)}f+=d}}if(t){let o=0;const l=[];for(let b=0;b<u.length;++b){const d=u[b].index;for(let y=0;y<d.count;++y)l.push(d.getX(y)+o);o+=u[b].attributes.position.count}r.setIndex(l)}for(const o in i){const l=pe.mergeAttributes(i[o]);if(!l)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+o+" attribute."),null;r.setAttribute(o,l)}for(const o in a){const l=a[o][0].length;if(l===0)break;r.morphAttributes=r.morphAttributes||{},r.morphAttributes[o]=[];for(let b=0;b<l;++b){const d=[];for(let C=0;C<a[o].length;++C)d.push(a[o][C][b]);const y=pe.mergeAttributes(d);if(!y)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+o+" morphAttribute."),null;r.morphAttributes[o].push(y)}}return e===2?pe.mergeGroups(r):r}const Ve=u=>{const m=u,{coordinate:e,startHeight:t,height:n}=m,s=de(m,["coordinate","startHeight","height"]);let i=t||0;return typeof t!="undefined"&&typeof n!="undefined"&&(i=t+n),new P.PolygonGeometry([e],le(B({},s),{startHeight:t,endHeight:i}))};class Je extends P.BaseObject{constructor(e){super(),this.options=B({},e)}create(){const r=this.options,{geometry:e,coordinateArr:t,coordinate:n,material:s,useGroups:i}=r,a=de(r,["geometry","coordinateArr","coordinate","material","useGroups"]);let m=e;if(!m&&n)m=Ve(B({coordinate:n},a));else if(!m&&t){const f=t.map(o=>Ve(B({coordinate:o},a)));m=D(f,i!=null?i:0)}this.createMesh(m,s)}}const Qe={ArcCurve:c.ArcCurve,CatmullRomCurve3:c.CatmullRomCurve3,CubicBezierCurve:c.CubicBezierCurve,CubicBezierCurve3:c.CubicBezierCurve3,EllipseCurve:c.EllipseCurve,LineCurve:c.LineCurve,LineCurve3:c.LineCurve3,QuadraticBezierCurve:c.QuadraticBezierCurve,QuadraticBezierCurve3:c.QuadraticBezierCurve3,SplineCurve:c.SplineCurve};class J extends c.BufferGeometry{constructor(e=new c.Shape([new c.Vector2(.5,.5),new c.Vector2(-.5,.5),new c.Vector2(-.5,-.5),new c.Vector2(.5,-.5)]),t={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:e,options:t},e=Array.isArray(e)?e:[e];const n=this,s=[],i=[];for(let m=0,r=e.length;m<r;m++){const f=e[m];a(f)}this.setAttribute("position",new c.Float32BufferAttribute(s,3)),this.setAttribute("uv",new c.Float32BufferAttribute(i,2)),this.computeVertexNormals();function a(m){var ve,Se,Ae;const r=[],f=t.curveSegments!==void 0?t.curveSegments:12,o=t.steps!==void 0?t.steps:1,l=t.depth!==void 0?t.depth:1;let b=t.bevelEnabled!==void 0?t.bevelEnabled:!0,d=t.bevelThickness!==void 0?t.bevelThickness:.2,y=t.bevelSize!==void 0?t.bevelSize:d-.1,C=t.bevelOffset!==void 0?t.bevelOffset:0,A=t.bevelSegments!==void 0?t.bevelSegments:3;const M=t.extrudePath,j=t.UVGenerator!==void 0?t.UVGenerator:Ke,S=(ve=t.hasTop)!=null?ve:!0,V=(Se=t.hasBottom)!=null?Se:!0,Q=(Ae=t.hasSide)!=null?Ae:!0;let H,Y=!1,U,te,ne,N;M&&(H=M.getSpacedPoints(o),Y=!0,b=!1,U=M.computeFrenetFrames(o,!1),te=new c.Vector3,ne=new c.Vector3,N=new c.Vector3),b||(A=0,d=0,y=0,C=0);const ge=m.extractPoints(f);let I=ge.shape;const _=ge.holes;if(!c.ShapeUtils.isClockWise(I)){I=I.reverse();for(let h=0,p=_.length;h<p;h++){const g=_[h];c.ShapeUtils.isClockWise(g)&&(_[h]=g.reverse())}}function ye(h){const g=10000000000000001e-36;let w=h[0];for(let x=1;x<=h.length;x++){const L=x%h.length,v=h[L],T=v.x-w.x,G=v.y-w.y,E=T*T+G*G,z=Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(w.x),Math.abs(w.y)),$=g*z*z;if(E<=$){h.splice(L,1),x--;continue}w=v}}ye(I),_.forEach(ye);const ue=_.length,R=I;for(let h=0;h<ue;h++){const p=_[h];I=I.concat(p)}function K(h,p,g){return p||console.error("THREE.ExtrudeGeometry: vec does not exist"),h.clone().addScaledVector(p,g)}const X=I.length;function be(h,p,g){let w,x,L;const v=h.x-p.x,T=h.y-p.y,G=g.x-h.x,E=g.y-h.y,z=v*v+T*T,$=v*E-T*G;if(Math.abs($)>Number.EPSILON){const O=Math.sqrt(z),Me=Math.sqrt(G*G+E*E),Le=p.x-T/O,Ce=p.y+v/O,Ne=g.x-E/Me,Xe=g.y+G/Me,Te=((Ne-Le)*E-(Xe-Ce)*G)/(v*E-T*G);w=Le+v*Te-h.x,x=Ce+T*Te-h.y;const Ge=w*w+x*x;if(Ge<=2)return new c.Vector2(w,x);L=Math.sqrt(Ge/2)}else{let O=!1;v>Number.EPSILON?G>Number.EPSILON&&(O=!0):v<-Number.EPSILON?G<-Number.EPSILON&&(O=!0):Math.sign(T)===Math.sign(E)&&(O=!0),O?(w=-T,x=v,L=Math.sqrt(z)):(w=v,x=T,L=Math.sqrt(z/2))}return new c.Vector2(w/L,x/L)}const oe=[];for(let h=0,p=R.length,g=p-1,w=h+1;h<p;h++,g++,w++)g===p&&(g=0),w===p&&(w=0),oe[h]=be(R[h],R[g],R[w]);const fe=[];let F,ie=oe.concat();for(let h=0,p=ue;h<p;h++){const g=_[h];F=[];for(let w=0,x=g.length,L=x-1,v=w+1;w<x;w++,L++,v++)L===x&&(L=0),v===x&&(v=0),F[w]=be(g[w],g[L],g[v]);fe.push(F),ie=ie.concat(F)}let Z;if(A===0)Z=c.ShapeUtils.triangulateShape(R,_);else{const h=[],p=[];for(let g=0;g<A;g++){const w=g/A,x=d*Math.cos(w*Math.PI/2),L=y*Math.sin(w*Math.PI/2)+C;for(let v=0,T=R.length;v<T;v++){const G=K(R[v],oe[v],L);W(G.x,G.y,-x),w===0&&h.push(G)}for(let v=0,T=ue;v<T;v++){const G=_[v];F=fe[v];const E=[];for(let z=0,$=G.length;z<$;z++){const O=K(G[z],F[z],L);W(O.x,O.y,-x),w===0&&E.push(O)}w===0&&p.push(E)}}Z=c.ShapeUtils.triangulateShape(h,p)}const re=Z.length,xe=y+C;for(let h=0;h<X;h++){const p=b?K(I[h],ie[h],xe):I[h];Y?(ne.copy(U.normals[0]).multiplyScalar(p.x),te.copy(U.binormals[0]).multiplyScalar(p.y),N.copy(H[0]).add(ne).add(te),W(N.x,N.y,N.z)):W(p.x,p.y,0)}for(let h=1;h<=o;h++)for(let p=0;p<X;p++){const g=b?K(I[p],ie[p],xe):I[p];Y?(ne.copy(U.normals[h]).multiplyScalar(g.x),te.copy(U.binormals[h]).multiplyScalar(g.y),N.copy(H[h]).add(ne).add(te),W(N.x,N.y,N.z)):W(g.x,g.y,l/o*h)}for(let h=A-1;h>=0;h--){const p=h/A,g=d*Math.cos(p*Math.PI/2),w=y*Math.sin(p*Math.PI/2)+C;for(let x=0,L=R.length;x<L;x++){const v=K(R[x],oe[x],w);W(v.x,v.y,l+g)}for(let x=0,L=_.length;x<L;x++){const v=_[x];F=fe[x];for(let T=0,G=v.length;T<G;T++){const E=K(v[T],F[T],w);Y?W(E.x,E.y+H[o-1].y,H[o-1].x+g):W(E.x,E.y,l+g)}}}Re(),Q&&De();function Re(){const h=s.length/3;if(b){let p=0,g=X*p;if(V)for(let w=0;w<re;w++){const x=Z[w];ae(x[2]+g,x[1]+g,x[0]+g)}if(p=o+A*2,g=X*p,S)for(let w=0;w<re;w++){const x=Z[w];ae(x[0]+g,x[1]+g,x[2]+g)}}else{if(V)for(let p=0;p<re;p++){const g=Z[p];ae(g[2],g[1],g[0])}if(S)for(let p=0;p<re;p++){const g=Z[p];ae(g[0]+X*o,g[1]+X*o,g[2]+X*o)}}n.addGroup(h,s.length/3-h,0)}function De(){const h=s.length/3;let p=0;we(R,p),p+=R.length;for(let g=0,w=_.length;g<w;g++){const x=_[g];we(x,p),p+=x.length}n.addGroup(h,s.length/3-h,1)}function we(h,p){let g=h.length;for(;--g>=0;){const w=g;let x=g-1;x<0&&(x=h.length-1);for(let L=0,v=o+A*2;L<v;L++){const T=X*L,G=X*(L+1),E=p+w+T,z=p+x+T,$=p+x+G,O=p+w+G;He(E,z,$,O)}}}function W(h,p,g){r.push(h),r.push(p),r.push(g)}function ae(h,p,g){q(h),q(p),q(g);const w=s.length/3,x=j.generateTopUV(n,s,w-3,w-2,w-1);k(x[0]),k(x[1]),k(x[2])}function He(h,p,g,w){q(h),q(p),q(w),q(p),q(g),q(w);const x=s.length/3,L=j.generateSideWallUV(n,s,x-6,x-3,x-2,x-1);k(L[0]),k(L[1]),k(L[3]),k(L[1]),k(L[2]),k(L[3])}function q(h){s.push(r[h*3+0]),s.push(r[h*3+1]),s.push(r[h*3+2])}function k(h){i.push(h.x),i.push(h.y)}}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON(),t=this.parameters.shapes,n=this.parameters.options;return et(t,n,e)}static fromJSON(e,t){const n=[];for(let i=0,a=e.shapes.length;i<a;i++){const m=t[e.shapes[i]];n.push(m)}const s=e.options.extrudePath;return s!==void 0&&(e.options.extrudePath=new Qe[`${s.type}`]().fromJSON(s)),new J(n,e.options)}}const Ke={generateTopUV:function(u,e,t,n,s){const i=e[t*3],a=e[t*3+1],m=e[n*3],r=e[n*3+1],f=e[s*3],o=e[s*3+1];return[new c.Vector2(i,a),new c.Vector2(m,r),new c.Vector2(f,o)]},generateSideWallUV:function(u,e,t,n,s,i){const a=e[t*3],m=e[t*3+1],r=e[t*3+2],f=e[n*3],o=e[n*3+1],l=e[n*3+2],b=e[s*3],d=e[s*3+1],y=e[s*3+2],C=e[i*3],A=e[i*3+1],M=e[i*3+2];return Math.abs(m-o)<Math.abs(a-f)?[new c.Vector2(a,1-r),new c.Vector2(f,1-l),new c.Vector2(b,1-y),new c.Vector2(C,1-M)]:[new c.Vector2(m,1-r),new c.Vector2(o,1-l),new c.Vector2(d,1-y),new c.Vector2(A,1-M)]}};function et(u,e,t){if(t.shapes=[],Array.isArray(u))for(let n=0,s=u.length;n<s;n++){const i=u[n];t.shapes.push(i.uuid)}else t.shapes.push(u.uuid);return t.options=Object.assign({},e),e.extrudePath!==void 0&&(t.options.extrudePath=e.extrudePath.toJSON()),t}class tt extends J{constructor(e,t){super(e,t);const n=new he.Brush(new J(e,le(B({},t),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const s=new c.Box3().setFromObject(n),i=new c.Vector3;s.getSize(i);const a=new c.Vector3(s.min.x+i.x/2,s.min.y+i.y/2,0);let m=t.topSegments,r=t.box3;if(r){r=r.union(s);const M=new c.Vector3;r.getSize(M);const j=Math.max(i.x/M.x,i.y/M.y);m=Math.ceil(t.topSegments*j)}if(m<4)return this;const f=new c.PlaneGeometry(i.x,i.y,m,m),o=new he.Brush(f);o.position.set(a.x,a.y,a.z),o.updateMatrixWorld();const b=new he.Evaluator().evaluate(o,n,he.INTERSECTION),d=b.geometry.getAttribute("position"),y=new c.Float32BufferAttribute(d.count*2,2);for(let M=0;M<d.count;M++){const j=d.getZ(M);d.setZ(M,t.depth+j)}if(r){const M=r.min,j=r.max,S=new c.Vector3().subVectors(j,M);for(let V=0;V<d.count;V++){const Q=d.getX(V),H=d.getY(V),Y=(Q-M.x)/S.x,U=(H-M.y)/S.y;y.setXY(V,Y,U)}b.geometry.setAttribute("uv",y)}d.needsUpdate=!0;const C=new J(e,le(B({},t),{hasTop:!1})),A=D([b.geometry,C],2);this.copy(A.toNonIndexed())}}const _e=u=>{const{split:e,depth:t,points:n,box3:s,hasTop:i,hasBottom:a,hasSide:m,sideRepeat:r,topSegments:f}=u,o=f?tt:J,l=new o(new c.Shape(n),{depth:t,bevelEnabled:!1,box3:s,UVGenerator:Pe.getUVGenerator({split:e,box3:s,sideRepeat:r}),hasTop:i,hasBottom:a,hasSide:m,topSegments:f});return Pe.claerUVGenerator(),l};class nt extends P.BaseObject{constructor(e){super(),this.options=B({depth:1},e)}create(){return se(this,null,function*(){const{points:e,pointsArr:t,useGroups:n,depth:s,geometry:i,geometryArr:a,material:m,box3:r,split:f,hasTop:o,hasBottom:l,hasSide:b}=this.options,d=Array.isArray(s)?s:[s],y=Array.isArray(r)?r:[r],C=m;let A=i;C||console.log("material is null"),!A&&e?A=_e({points:e,depth:d[0],box3:y[0],split:f,hasTop:o,hasBottom:l,hasSide:b}):!A&&t?A=D(t.map((M,j)=>{var S,V;return _e({points:M,depth:(S=d[j])!=null?S:d[0],box3:(V=y[j])!=null?V:y[0],split:f,hasTop:o,hasBottom:l,hasSide:b})}),n!=null?n:0):!A&&a&&a.length>1?A=D(a,n!=null?n:0):!A&&a&&a.length===1&&([A]=a),this.createMesh(A,C)})}addGeometries(e){const t=this.object3d,n=D([t.geometry,...e]);t.geometry=n}setTextureAnisotropic(e,t){e.anisotropy=t||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const st=u=>{const{topColor:e,sideColor:t,sideMap:n,createCanvasObjectURL:s,split:i,maxAnisotropy:a}=u;return new Promise(m=>{const r=n?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};r.onload=()=>{const f=i,o=document.createElement("canvas"),l=o.getContext("2d");o.height=r.height/(1-f),o.width=r.width,f&&e&&(l.fillStyle=e,l.fillRect(0,0,r.width,o.height*f)),n&&r instanceof HTMLImageElement?l.drawImage(r,0,o.height*f,r.width,r.height):t&&(l.fillStyle=t,l.fillRect(0,o.height*f,r.width,r.height)),s&&o.toBlob(d=>{console.log(URL.createObjectURL(d))});const b=new c.CanvasTexture(o);m(b)},n?r.src=n:r instanceof HTMLImageElement||r.onload()})};class ot extends P.BaseObject{create(){this.createGroup()}}class it extends P.BaseObject{constructor(e){super(),this.rectAreaLightUniformsLibInit=!1,this.options=e}create(){var t,n,s,i,a,m,r,f,o,l,b,d,y,C,A,M,j;const e=this.options;if(e.type==="AmbientLight"){const S=new c.AmbientLight(e.color);S.name="环境光",this.object3d=S}else if(e.type==="DirectionalLight"){const S=new c.DirectionalLight(e.color,e.intensity);S.name="平行光",S.target.position.set(0,0,0),this.object3d=S,S.target.name="平行光目标",S.shadow.camera.name="平行光阴影相机",S.shadow.camera.userData.directionalLightShadow=!0,this.directionalLight=S}else if(e.type==="PointLight"){const S=new c.PointLight((t=e.color)!=null?t:16777215,(n=e.intensity)!=null?n:1,(s=e.distance)!=null?s:0,(i=e.decay)!=null?i:2);S.name="点光源",this.object3d=S,this.pointLight=S}else if(e.type==="SpotLight"){const S=new c.SpotLight((a=e.color)!=null?a:16777215,(m=e.intensity)!=null?m:1,(r=e.distance)!=null?r:0,(f=e.angle)!=null?f:Math.PI/3,(o=e.penumbra)!=null?o:1,(l=e.decay)!=null?l:2);S.name="聚光灯",this.object3d=S,this.spotLight=S,S.target.name="聚光灯目标"}else if(e.type==="HemisphereLight"){const S=new c.HemisphereLight((b=e.color)!=null?b:16777215,(d=e.groundColor)!=null?d:16777215,(y=e.intensity)!=null?y:1);S.name="半球光",this.object3d=S,this.hemisphereLight=S}else if(e.type==="RectAreaLight"){this.rectAreaLightUniformsLibInit||(Fe.RectAreaLightUniformsLib.init(),this.rectAreaLightUniformsLibInit=!0);const S=new c.RectAreaLight((C=e.color)!=null?C:16777215,(A=e.intensity)!=null?A:1,(M=e.width)!=null?M:10,(j=e.height)!=null?j:10);S.name="矩形区域光",this.object3d=S,this.rectAreaLight=S}}render(){const e=this.object3d;e.target&&this.pencil.scene.add(e.target);const t=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const n=this.spotLight||this.directionalLight;n.position.copy(t),n.target.position.copy(t)}else this.pointLight&&this.pointLight.position.copy(t)}dispose(){const e=this.object3d;e.target&&this.pencil.scene.remove(e.target),super.dispose()}}class Ue extends c.BufferGeometry{constructor(e=[],t="none",n){super(),this.type="MeshLineGeometry",this.pointCount=0,this._points=[],this.shape="none",this.shapeFunction=s=>1,this.matrixWorld=new c.Matrix4,this.shape=t,n&&(this.shapeFunction=n),e.length>0&&this.setPoints(e)}convertToVector3Array(e){if(typeof e[0]=="number"){const t=[],n=e;for(let s=0;s<n.length;s+=3)t.push(new c.Vector3(n[s],n[s+1],n[s+2]));return t}else return e.map(t=>{if(t instanceof c.Vector2)return new c.Vector3(t.x,t.y,0);if(t instanceof c.Vector3)return t;if(Array.isArray(t)&&t.length===2)return new c.Vector3(t[0],t[1],0);if(Array.isArray(t)&&t.length===3)return new c.Vector3(t[0],t[1],t[2])}).filter(Boolean)}setMatrixWorld(e){this.matrixWorld=e}setPoints(e,t){!e||e.length===0||(this._points=this.convertToVector3Array(e),this.pointCount=this._points.length,t&&(this.shapeFunction=t,this.shape="custom"),this.initializeGeometry(),this.updateGeometry())}initializeGeometry(){const e=new c.BufferAttribute(new Float32Array(this.pointCount*6),3),t=new c.BufferAttribute(new Float32Array(this.pointCount*6),3),n=new c.BufferAttribute(new Float32Array(this.pointCount*6),3),s=new c.BufferAttribute(new Float32Array(this.pointCount*2),1),i=new c.BufferAttribute(new Float32Array(this.pointCount*2),1),a=new c.BufferAttribute(new Float32Array(this.pointCount*2),1),m=new c.BufferAttribute(new Float32Array(this.pointCount*4),2),r=new c.BufferAttribute(new Uint16Array((this.pointCount-1)*6),1);this.shape==="taper"&&(this.shapeFunction=f=>1*Math.pow(4*f*(1-f),1));for(let f=0,o=0,l=0;f<this.pointCount;f+=1,o+=2,l+=6){s.setX(o,f/this.pointCount),s.setX(o+1,f/this.pointCount),i.setX(o,1),i.setX(o+1,-1);const b=this.shape==="none"?1:this.shapeFunction(f/(this.pointCount-1));a.setX(o,b),a.setX(o+1,b);const d=f/(this.pointCount-1);if(m.setXY(o,d,0),m.setXY(o+1,d,1),f<this.pointCount-1){const y=f*2;r.setX(l+0,y+0),r.setX(l+1,y+1),r.setX(l+2,y+2),r.setX(l+3,y+2),r.setX(l+4,y+1),r.setX(l+5,y+3)}}this.setAttribute("position",e),this.setAttribute("previous",t),this.setAttribute("next",n),this.setAttribute("counters",s),this.setAttribute("side",i),this.setAttribute("width",a),this.setAttribute("uv",m),this.setIndex(r)}updateGeometry(){if(!this._points[0])return;const e=this.getAttribute("position"),t=this.getAttribute("previous"),n=this.getAttribute("next");let s=0,i=0,a=0;const m=this._points[0];t.setXYZ(i,m.x,m.y,m.z),i+=1,t.setXYZ(i,m.x,m.y,m.z),i+=1;for(let f=0;f<this.pointCount;f++){const o=this._points[f];e.setXYZ(s,o.x,o.y,o.z),s+=1,e.setXYZ(s,o.x,o.y,o.z),s+=1,f<this.pointCount-1&&(t.setXYZ(i,o.x,o.y,o.z),i+=1,t.setXYZ(i,o.x,o.y,o.z),i+=1),f>0&&f+1<=this.pointCount&&(n.setXYZ(a,o.x,o.y,o.z),a+=1,n.setXYZ(a,o.x,o.y,o.z),a+=1)}const r=this._points[this.pointCount-1];n.setXYZ(a,r.x,r.y,r.z),a+=1,n.setXYZ(a,r.x,r.y,r.z),a+=1,e.needsUpdate=!0,t.needsUpdate=!0,n.needsUpdate=!0,this.computeBoundingSphere(),this.computeBoundingBox()}get points(){return this._points}set points(e){this.setPoints(e)}updatePoints(e,t){const n=this.convertToVector3Array(e);if(n.length!==this.pointCount){console.warn("MeshLineGeometry: Cannot update points with different length. Use setPoints() instead.");return}this._points=n,t&&(this.shapeFunction=t,this.shape="custom",this.initializeGeometry()),this.updateGeometry()}setShape(e,t){this.shape=e,t&&(this.shapeFunction=t),this._points.length>0&&(this.initializeGeometry(),this.updateGeometry())}}function rt(u,e){const t=new c.Matrix4,n=new c.Ray,s=new c.Sphere,i=new c.Vector3,a=this.geometry;if(s.copy(a.boundingSphere),s.applyMatrix4(this.matrixWorld),!u.ray.intersectSphere(s,i))return;t.copy(this.matrixWorld).invert(),n.copy(u.ray).applyMatrix4(t);const m=new c.Vector3,r=new c.Vector3,f=new c.Vector3,o=this instanceof c.LineSegments?2:1,l=a.index,b=a.attributes;if(l!==null){const d=l.array,y=b.position.array,C=b.width.array;for(let A=0,M=d.length-1;A<M;A+=o){const j=d[A],S=d[A+1];m.fromArray(y,j*3),r.fromArray(y,S*3);const V=C[Math.floor(A/3)]!==void 0?C[Math.floor(A/3)]:1,Q=u.params.Line.threshold+this.material.lineWidth*V/2,H=Q*Q;if(n.distanceSqToSegment(m,r,i,f)>H)continue;i.applyMatrix4(this.matrixWorld);const U=u.ray.origin.distanceTo(i);U<u.near||U>u.far||(e.push({distance:U,point:f.clone().applyMatrix4(this.matrixWorld),index:A,face:null,faceIndex:void 0,object:this}),A=M)}}}const me=u=>{const{setPointWidth:e,nodes:t}=u,n=new Ue;return n.setPoints(t,e),n};let at=class extends P.BaseObject{constructor(e={}){super(),this.options=B({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return se(this,null,function*(){const{nodes:e,nodesArr:t,geometry:n,geometryArr:s,material:i,useGroups:a,setPointWidth:m,lineWidthArr:r,materialParameters:f}=this.options;let o=i,l=n;!o&&f&&(o=this.getMaterial(f)),!l&&e?l=me({nodes:e,setPointWidth:m}):!l&&t?l=D(t.map((b,d)=>{let y=m;return!y&&r&&(y=()=>{var C;return(C=r[d])!=null?C:r[0]}),me({nodes:b,setPointWidth:y})}),a!=null?a:0):!l&&s&&s.length>1?l=D(s,a!=null?a:0):!l&&s&&s.length===1&&([l]=s),this.createMesh(l,o)})}setGeometry(e,t){const n=me({nodes:e,setPointWidth:t}),s=this.object3d,i=s.geometry;s.geometry=n,i.dispose()}getMaterial(e){const{width:t,height:n}=this.pencil.getSize(),s=new P.MeshLineMaterial(B({color:new c.Color("#ffffff")},e));return s.uniforms.resolution.value.set(t,n),s}addGeometries(e){const t=this.object3d,n=D([t.geometry,...e]);t.geometry=n}resize(e,t){var n,s;(s=(n=this.material)==null?void 0:n.uniforms)==null||s.resolution.value.set(e,t)}handleMaterialChange(e){if(e){const{width:t,height:n}=this.pencil.getSize();this.resize(t,n)}}animate({duration:e=1e3,delay:t=0,repeat:n=0,lineLoop:s,onRepeat:i,onUpdate:a,onComplete:m,startShow:r}={}){const{offset:f,offsetLoop:o}=this.material.uniforms;if(this.material.userData.tween)return;const l=s!=null?s:!0;f.value.x=1,o.value=l&&r?1:0;let b=0;const d=new ee.Tween(f.value).to({x:-1},e).delay(t).repeat(n).onUpdate(({x:y})=>{l&&y<=0&&o.value===0&&(o.value=1),a&&a(y)}).onRepeat(()=>{b+=1,i&&i(b)}).onComplete(()=>{m&&m()}).start();this.material.userData.tween=!0,this.material.addEventListener("dispose",()=>{d.stop(),ee.remove(d),this.material.userData.tween=null})}render(){const{width:e,height:t}=this.pencil.getSize();this.resize(e,t)}};const ze=u=>{const{points:e}=u,t=e.reduce((s,i,a)=>(a<e.length-1&&s.push(i,e[a+1]),s),[]);return new c.BufferGeometry().setFromPoints(t)};class ct extends P.BaseObject{constructor(e={}){super(),this.options=B({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return se(this,null,function*(){const{points:e,pointsArr:t,geometry:n,geometryArr:s,material:i,useGroups:a,setPointWidth:m,lineWidthArr:r,materialParameters:f,instanceCount:o}=this.options;let l=i,b=n;!l&&f&&(l=this.getMaterial(f)),!b&&e?b=ze({points:e}):!b&&t?b=D(t.map(y=>ze({points:y})),a!=null?a:0):!b&&s&&s.length>1?b=D(s,a!=null?a:0):!b&&s&&s.length===1&&([b]=s);const d=new Ie.LineSegmentsGeometry().fromLineSegments(new c.LineSegments(b));if(this.pencil.options.WebGPUTHREE){o&&(d.instanceCount=o);const y=new P.LineSegments2(d,l);y.computeLineDistances(),this.object3d=y}else{const y=new Ze.LineSegments2(d,l);y.computeLineDistances(),this.object3d=y}})}getMaterial(e){return new Oe.LineMaterial(B({color:new c.Color("#ffffff")},e))}}class lt extends P.BaseObject{constructor(e){super(),this.objectType="BaseObject#Node",this.onNodePointerIndex=[],this.options=B({type:"2d"},e)}create(){const{position:e,children:t}=this.options,n=document.createElement("div");this.element=n,t&&n.appendChild(t),this.options.type==="3d"?this.createCSS3DObject(n):this.options.type==="3dSprite"?this.createCSS3DSprite(n):this.createCSS2DObject(n),e&&this.object3d.position.copy(e)}setChildren(e){this.options.children=e,this.element.innerHTML="",this.element.appendChild(e)}showAndEnsureVisible(){const e=this.options.children;e&&(e.style.visibility="hidden",this.show(),setTimeout(()=>{e.style.visibility="",this.ensureVisible()}))}moveElementToViewport(){const e=this.options.children;if(!e)return;const t=e.getBoundingClientRect(),n=window.innerWidth,s=window.innerHeight;let i=0,a=0;t.left<0?i=-t.left:t.right>n&&(i=n-t.right),t.top<0?a=-t.top:t.bottom>s&&(a=s-t.bottom),t.left+i<0&&(i=-t.left),t.top+a<0&&(a=-t.top),(i!==0||a!==0)&&(e.style.transform=`translate(${i}px, ${a}px)`)}ensureVisible(){const e=this.options.children;if(!e)return;e.style.transform&&(e.style.transform="");const t=new IntersectionObserver(n=>{n.forEach(s=>{s.isIntersecting&&(this.moveElementToViewport(),t.disconnect())})});t.observe(e)}onPointerEvent(e,t){const n=this.lead.handlePickNode([this],e,t);this.onNodePointerIndex.push(n)}dispose(){this.onNodePointerIndex.forEach(e=>{this.lead.removePickNode(e)}),super.dispose()}}class ht extends P.BaseObject{constructor(e){super(),this.options=B({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},e)}create(){return se(this,null,function*(){this.createGroup();const{data:e,maxDepth:t,colors:n,material:s,percentDepth:i,activeIndex:a}=this.options,m=Math.max(...e),r=e.reduce((o,l)=>o+l,0);let f=Math.PI/2;e.forEach((o,l)=>{if(o===0)return;const b=Math.PI*2*(o/r),d=n[l],y=i?t*(o/m):t,C=this.createGeometry(y,b),A=s?s.clone():new c.MeshBasicMaterial({color:d});s&&A.color.set(d);const M=new c.Mesh(C,A);M.userData.depth=y,M.userData.index=l,M.rotateZ(f),f+=b,this.add(M)}),a!==-1&&this.setActive(a)})}createGeometry(e,t){const{outRadius:n,innerRadius:s}=this.options,i=new c.Shape;return i.moveTo(n,0),i.lineTo(s,0),i.absarc(0,0,s,0,t,!1),i.absarc(0,0,n,t,0,!0),new J(i,{curveSegments:48,depth:e,bevelEnabled:!1})}handlePick(e,t=1.3){const{object:n}=this.pencil.pick(e,this.object3d.children)||{},s=n?this.object3d.children.findIndex(i=>i===n):this.options.activeIndex;return this.setActive(s,t)}setActive(e,t=1.3){const n=this.object3d.children[e];if(this.object3d.children.forEach(s=>{if(!(n&&n===s)&&s.scale.z!==1){if(s.userData.levTween)return;s.userData.enTween&&(s.userData.enTween.stop(),s.userData.enTween=null);const i=new ee.Tween(s.scale).to({z:1},100);s.userData.levTween=i,i.start()}}),n){if(n.userData.enTween)return;n.userData.levTween&&(n.userData.levTween.stop(),n.userData.levTween=null);const s=new ee.Tween(n.scale).to({z:t},100);return n.userData.enTween=s,s.start(),n.userData.index}return-1}render(){this.object3d.scale.z=0,new ee.Tween(this.object3d.scale).to({z:1},1e3).easing(ee.Easing.Sinusoidal.InOut).start()}}Object.defineProperty(exports,"Line2Material",{enumerable:!0,get:()=>Oe.LineMaterial});Object.defineProperty(exports,"LineSegmentsGeometry",{enumerable:!0,get:()=>Ie.LineSegmentsGeometry});exports.MeshLineMaterial=P.MeshLineMaterial;exports.getConicPolygonGeometry=P.PolygonGeometry;exports.getConicPolygonGeometryMetas=P.getMetas;exports.ConicPolygon=Je;exports.ExtrudePolygon=nt;exports.Group=ot;exports.Light=it;exports.Line=at;exports.Line2=ct;exports.MeshLineGeometry=Ue;exports.MeshLineRaycast=rt;exports.Node=lt;exports.Pie=ht;exports.getSplitTexture=st;
@@ -41,14 +41,14 @@ import { LineSegmentsGeometry as Ke } from "three/examples/jsm/lines/LineSegment
41
41
  import { LineSegmentsGeometry as un } from "three/examples/jsm/lines/LineSegmentsGeometry";
42
42
  import { P as et, a as Z, M as tt, L as nt } from "../WebGPULineSegments2.module.js";
43
43
  import { g as fn } from "../WebGPULineSegments2.module.js";
44
- import { BufferGeometry as fe, Float32BufferAttribute as be, Vector3 as _, ShapeUtils as de, Shape as xe, Vector2 as G, ArcCurve as st, CatmullRomCurve3 as ot, CubicBezierCurve as it, CubicBezierCurve3 as rt, EllipseCurve as at, LineCurve as ct, LineCurve3 as lt, QuadraticBezierCurve as ht, QuadraticBezierCurve3 as ut, SplineCurve as dt, Box3 as ft, PlaneGeometry as pt, CanvasTexture as mt, AmbientLight as gt, DirectionalLight as yt, PointLight as bt, SpotLight as xt, HemisphereLight as wt, RectAreaLight as vt, Matrix4 as Ve, BufferAttribute as Y, Ray as St, Sphere as At, LineSegments as Xe, Color as Ne, MeshBasicMaterial as Mt, Mesh as Lt } from "three";
44
+ import { BufferGeometry as fe, Float32BufferAttribute as be, Vector3 as _, ShapeUtils as de, Shape as xe, Vector2 as G, ArcCurve as st, CatmullRomCurve3 as ot, CubicBezierCurve as it, CubicBezierCurve3 as rt, EllipseCurve as at, LineCurve as ct, LineCurve3 as lt, QuadraticBezierCurve as ht, QuadraticBezierCurve3 as ut, SplineCurve as dt, Box3 as ft, PlaneGeometry as pt, CanvasTexture as mt, AmbientLight as gt, DirectionalLight as yt, PointLight as bt, SpotLight as xt, HemisphereLight as wt, RectAreaLight as vt, Matrix4 as De, BufferAttribute as Y, Ray as St, Sphere as At, LineSegments as Xe, Color as Ne, MeshBasicMaterial as Mt, Mesh as Lt } from "three";
45
45
  import { mergeAttributes as Re, mergeGroups as Tt } from "three/examples/jsm/utils/BufferGeometryUtils";
46
46
  import { g as Et, c as Ct } from "../uvGenerator.module.js";
47
47
  import { Brush as Oe, Evaluator as Gt, INTERSECTION as Pt } from "three-bvh-csg";
48
48
  import { RectAreaLightUniformsLib as _t } from "three/examples/jsm/lights/RectAreaLightUniformsLib";
49
49
  import * as ne from "@tweenjs/tween.js";
50
50
  import { LineSegments2 as jt } from "three/examples/jsm/lines/LineSegments2";
51
- function H(m, e = 0) {
51
+ function V(m, e = 0) {
52
52
  const t = m[0].index !== null, n = new Set(Object.keys(m[0].attributes)), s = new Set(
53
53
  Object.keys(m[0].morphAttributes)
54
54
  ), i = {}, a = {}, f = m[0].morphTargetsRelative, r = new fe();
@@ -180,7 +180,7 @@ class Zt extends Z {
180
180
  coordinate: o
181
181
  }, a))
182
182
  );
183
- f = H(h, i != null ? i : 0);
183
+ f = V(h, i != null ? i : 0);
184
184
  }
185
185
  this.createMesh(f, s);
186
186
  }
@@ -225,8 +225,8 @@ class K extends fe {
225
225
  const r = [], h = t.curveSegments !== void 0 ? t.curveSegments : 12, o = t.steps !== void 0 ? t.steps : 1, c = t.depth !== void 0 ? t.depth : 1;
226
226
  let y = t.bevelEnabled !== void 0 ? t.bevelEnabled : !0, u = t.bevelThickness !== void 0 ? t.bevelThickness : 0.2, g = t.bevelSize !== void 0 ? t.bevelSize : u - 0.1, L = t.bevelOffset !== void 0 ? t.bevelOffset : 0, S = t.bevelSegments !== void 0 ? t.bevelSegments : 3;
227
227
  const A = t.extrudePath, P = t.UVGenerator !== void 0 ? t.UVGenerator : It, v = (Le = t.hasTop) != null ? Le : !0, z = (Te = t.hasBottom) != null ? Te : !0, ee = (Ee = t.hasSide) != null ? Ee : !0;
228
- let V, $ = !1, U, se, oe, X;
229
- A && (V = A.getSpacedPoints(o), $ = !0, y = !1, U = A.computeFrenetFrames(o, !1), se = new _(), oe = new _(), X = new _()), y || (S = 0, u = 0, g = 0, L = 0);
228
+ let D, $ = !1, U, se, oe, X;
229
+ A && (D = A.getSpacedPoints(o), $ = !0, y = !1, U = A.computeFrenetFrames(o, !1), se = new _(), oe = new _(), X = new _()), y || (S = 0, u = 0, g = 0, L = 0);
230
230
  const we = f.extractPoints(h);
231
231
  let O = we.shape;
232
232
  const I = we.holes;
@@ -255,7 +255,7 @@ class K extends fe {
255
255
  }
256
256
  }
257
257
  ve(O), I.forEach(ve);
258
- const pe = I.length, D = O;
258
+ const pe = I.length, H = O;
259
259
  for (let l = 0; l < pe; l++) {
260
260
  const d = I[l];
261
261
  O = O.concat(d);
@@ -283,8 +283,8 @@ class K extends fe {
283
283
  return new G(x / M, b / M);
284
284
  }
285
285
  const re = [];
286
- for (let l = 0, d = D.length, p = d - 1, x = l + 1; l < d; l++, p++, x++)
287
- p === d && (p = 0), x === d && (x = 0), re[l] = Se(D[l], D[p], D[x]);
286
+ for (let l = 0, d = H.length, p = d - 1, x = l + 1; l < d; l++, p++, x++)
287
+ p === d && (p = 0), x === d && (x = 0), re[l] = Se(H[l], H[p], H[x]);
288
288
  const me = [];
289
289
  let q, ae = re.concat();
290
290
  for (let l = 0, d = pe; l < d; l++) {
@@ -296,13 +296,13 @@ class K extends fe {
296
296
  }
297
297
  let J;
298
298
  if (S === 0)
299
- J = de.triangulateShape(D, I);
299
+ J = de.triangulateShape(H, I);
300
300
  else {
301
301
  const l = [], d = [];
302
302
  for (let p = 0; p < S; p++) {
303
303
  const x = p / S, b = u * Math.cos(x * Math.PI / 2), M = g * Math.sin(x * Math.PI / 2) + L;
304
- for (let w = 0, T = D.length; w < T; w++) {
305
- const E = te(D[w], re[w], M);
304
+ for (let w = 0, T = H.length; w < T; w++) {
305
+ const E = te(H[w], re[w], M);
306
306
  W(E.x, E.y, -b), x === 0 && l.push(E);
307
307
  }
308
308
  for (let w = 0, T = pe; w < T; w++) {
@@ -324,17 +324,17 @@ class K extends fe {
324
324
  const ce = J.length, Ae = g + L;
325
325
  for (let l = 0; l < N; l++) {
326
326
  const d = y ? te(O[l], ae[l], Ae) : O[l];
327
- $ ? (oe.copy(U.normals[0]).multiplyScalar(d.x), se.copy(U.binormals[0]).multiplyScalar(d.y), X.copy(V[0]).add(oe).add(se), W(X.x, X.y, X.z)) : W(d.x, d.y, 0);
327
+ $ ? (oe.copy(U.normals[0]).multiplyScalar(d.x), se.copy(U.binormals[0]).multiplyScalar(d.y), X.copy(D[0]).add(oe).add(se), W(X.x, X.y, X.z)) : W(d.x, d.y, 0);
328
328
  }
329
329
  for (let l = 1; l <= o; l++)
330
330
  for (let d = 0; d < N; d++) {
331
331
  const p = y ? te(O[d], ae[d], Ae) : O[d];
332
- $ ? (oe.copy(U.normals[l]).multiplyScalar(p.x), se.copy(U.binormals[l]).multiplyScalar(p.y), X.copy(V[l]).add(oe).add(se), W(X.x, X.y, X.z)) : W(p.x, p.y, c / o * l);
332
+ $ ? (oe.copy(U.normals[l]).multiplyScalar(p.x), se.copy(U.binormals[l]).multiplyScalar(p.y), X.copy(D[l]).add(oe).add(se), W(X.x, X.y, X.z)) : W(p.x, p.y, c / o * l);
333
333
  }
334
334
  for (let l = S - 1; l >= 0; l--) {
335
335
  const d = l / S, p = u * Math.cos(d * Math.PI / 2), x = g * Math.sin(d * Math.PI / 2) + L;
336
- for (let b = 0, M = D.length; b < M; b++) {
337
- const w = te(D[b], re[b], x);
336
+ for (let b = 0, M = H.length; b < M; b++) {
337
+ const w = te(H[b], re[b], x);
338
338
  W(w.x, w.y, c + p);
339
339
  }
340
340
  for (let b = 0, M = I.length; b < M; b++) {
@@ -344,8 +344,8 @@ class K extends fe {
344
344
  const C = te(w[T], q[T], x);
345
345
  $ ? W(
346
346
  C.x,
347
- C.y + V[o - 1].y,
348
- V[o - 1].x + p
347
+ C.y + D[o - 1].y,
348
+ D[o - 1].x + p
349
349
  ) : W(C.x, C.y, c + p);
350
350
  }
351
351
  }
@@ -386,7 +386,7 @@ class K extends fe {
386
386
  function ke() {
387
387
  const l = s.length / 3;
388
388
  let d = 0;
389
- Me(D, d), d += D.length;
389
+ Me(H, d), d += H.length;
390
390
  for (let p = 0, x = I.length; p < x; p++) {
391
391
  const b = I[p];
392
392
  Me(b, d), d += b.length;
@@ -549,7 +549,7 @@ class Rt extends K {
549
549
  if (r) {
550
550
  const A = r.min, P = r.max, v = new _().subVectors(P, A);
551
551
  for (let z = 0; z < u.count; z++) {
552
- const ee = u.getX(z), V = u.getY(z), $ = (ee - A.x) / v.x, U = (V - A.y) / v.y;
552
+ const ee = u.getX(z), D = u.getY(z), $ = (ee - A.x) / v.x, U = (D - A.y) / v.y;
553
553
  g.setXY(z, $, U);
554
554
  }
555
555
  y.geometry.setAttribute("uv", g);
@@ -557,11 +557,11 @@ class Rt extends K {
557
557
  u.needsUpdate = !0;
558
558
  const L = new K(e, ue(j({}, t), {
559
559
  hasTop: !1
560
- })), S = H([y.geometry, L], 2);
560
+ })), S = V([y.geometry, L], 2);
561
561
  this.copy(S.toNonIndexed());
562
562
  }
563
563
  }
564
- const De = (m) => {
564
+ const He = (m) => {
565
565
  const {
566
566
  split: e,
567
567
  depth: t,
@@ -611,7 +611,7 @@ class $t extends Z {
611
611
  hasSide: y
612
612
  } = this.options, u = Array.isArray(s) ? s : [s], g = Array.isArray(r) ? r : [r], L = f;
613
613
  let S = i;
614
- L || console.log("material is null"), !S && e ? S = De({
614
+ L || console.log("material is null"), !S && e ? S = He({
615
615
  points: e,
616
616
  depth: u[0],
617
617
  box3: g[0],
@@ -619,11 +619,11 @@ class $t extends Z {
619
619
  hasTop: o,
620
620
  hasBottom: c,
621
621
  hasSide: y
622
- }) : !S && t ? S = H(
622
+ }) : !S && t ? S = V(
623
623
  t.map(
624
624
  (A, P) => {
625
625
  var v, z;
626
- return De({
626
+ return He({
627
627
  points: A,
628
628
  depth: (v = u[P]) != null ? v : u[0],
629
629
  box3: (z = g[P]) != null ? z : g[0],
@@ -635,11 +635,11 @@ class $t extends Z {
635
635
  }
636
636
  ),
637
637
  n != null ? n : 0
638
- ) : !S && a && a.length > 1 ? S = H(a, n != null ? n : 0) : !S && a && a.length === 1 && ([S] = a), this.createMesh(S, L);
638
+ ) : !S && a && a.length > 1 ? S = V(a, n != null ? n : 0) : !S && a && a.length === 1 && ([S] = a), this.createMesh(S, L);
639
639
  });
640
640
  }
641
641
  addGeometries(e) {
642
- const t = this.object3d, n = H([t.geometry, ...e]);
642
+ const t = this.object3d, n = V([t.geometry, ...e]);
643
643
  t.geometry = n;
644
644
  }
645
645
  setTextureAnisotropic(e, t) {
@@ -743,7 +743,7 @@ class Kt extends Z {
743
743
  }
744
744
  class Ot extends fe {
745
745
  constructor(e = [], t = "none", n) {
746
- super(), this.type = "MeshLineGeometry", this.pointCount = 0, this._points = [], this.shape = "none", this.shapeFunction = (s) => 1, this.matrixWorld = new Ve(), this.shape = t, n && (this.shapeFunction = n), e.length > 0 && this.setPoints(e);
746
+ super(), this.type = "MeshLineGeometry", this.pointCount = 0, this._points = [], this.shape = "none", this.shapeFunction = (s) => 1, this.matrixWorld = new De(), this.shape = t, n && (this.shapeFunction = n), e.length > 0 && this.setPoints(e);
747
747
  }
748
748
  convertToVector3Array(e) {
749
749
  if (typeof e[0] == "number") {
@@ -830,7 +830,7 @@ class Ot extends fe {
830
830
  }
831
831
  }
832
832
  function en(m, e) {
833
- const t = new Ve(), n = new St(), s = new At(), i = new _(), a = this.geometry;
833
+ const t = new De(), n = new St(), s = new At(), i = new _(), a = this.geometry;
834
834
  if (s.copy(a.boundingSphere), s.applyMatrix4(this.matrixWorld), !m.ray.intersectSphere(s, i)) return;
835
835
  t.copy(this.matrixWorld).invert(), n.copy(m.ray).applyMatrix4(t);
836
836
  const f = new _(), r = new _(), h = new _(), o = this instanceof Xe ? 2 : 1, c = a.index, y = a.attributes;
@@ -839,13 +839,13 @@ function en(m, e) {
839
839
  for (let S = 0, A = u.length - 1; S < A; S += o) {
840
840
  const P = u[S], v = u[S + 1];
841
841
  f.fromArray(g, P * 3), r.fromArray(g, v * 3);
842
- const z = L[Math.floor(S / 3)] !== void 0 ? L[Math.floor(S / 3)] : 1, ee = m.params.Line.threshold + this.material.lineWidth * z / 2, V = ee * ee;
842
+ const z = L[Math.floor(S / 3)] !== void 0 ? L[Math.floor(S / 3)] : 1, ee = m.params.Line.threshold + this.material.lineWidth * z / 2, D = ee * ee;
843
843
  if (n.distanceSqToSegment(
844
844
  f,
845
845
  r,
846
846
  i,
847
847
  h
848
- ) > V) continue;
848
+ ) > D) continue;
849
849
  i.applyMatrix4(this.matrixWorld);
850
850
  const U = m.ray.origin.distanceTo(i);
851
851
  U < m.near || U > m.far || (e.push({
@@ -890,7 +890,7 @@ let tn = class extends Z {
890
890
  !o && h && (o = this.getMaterial(h)), !c && e ? c = ye({
891
891
  nodes: e,
892
892
  setPointWidth: f
893
- }) : !c && t ? c = H(
893
+ }) : !c && t ? c = V(
894
894
  t.map((y, u) => {
895
895
  let g = f;
896
896
  return !g && r && (g = () => {
@@ -902,7 +902,7 @@ let tn = class extends Z {
902
902
  });
903
903
  }),
904
904
  a != null ? a : 0
905
- ) : !c && s && s.length > 1 ? c = H(s, a != null ? a : 0) : !c && s && s.length === 1 && ([c] = s), this.createMesh(c, o);
905
+ ) : !c && s && s.length > 1 ? c = V(s, a != null ? a : 0) : !c && s && s.length === 1 && ([c] = s), this.createMesh(c, o);
906
906
  });
907
907
  }
908
908
  setGeometry(e, t) {
@@ -919,7 +919,7 @@ let tn = class extends Z {
919
919
  return s.uniforms.resolution.value.set(t, n), s;
920
920
  }
921
921
  addGeometries(e) {
922
- const t = this.object3d, n = H([t.geometry, ...e]);
922
+ const t = this.object3d, n = V([t.geometry, ...e]);
923
923
  t.geometry = n;
924
924
  }
925
925
  resize(e, t) {
@@ -955,17 +955,16 @@ let tn = class extends Z {
955
955
  }).onComplete(() => {
956
956
  f && f();
957
957
  }).start();
958
- this.material.userData.tween = u;
958
+ this.material.userData.tween = !0, this.material.addEventListener("dispose", () => {
959
+ u.stop(), ne.remove(u), this.material.userData.tween = null;
960
+ });
959
961
  }
960
962
  render() {
961
963
  const { width: e, height: t } = this.pencil.getSize();
962
964
  this.resize(e, t);
963
965
  }
964
- dispose() {
965
- this.material.userData.tween && (this.material.userData.tween.stop(), ne.remove(this.material.userData.tween)), super.dispose();
966
- }
967
966
  };
968
- const He = (m) => {
967
+ const Ve = (m) => {
969
968
  const { points: e } = m, t = e.reduce((s, i, a) => (a < e.length - 1 && s.push(i, e[a + 1]), s), []);
970
969
  return new fe().setFromPoints(t);
971
970
  };
@@ -992,14 +991,14 @@ class sn extends Z {
992
991
  instanceCount: o
993
992
  } = this.options;
994
993
  let c = i, y = n;
995
- !c && h && (c = this.getMaterial(h)), !y && e ? y = He({
994
+ !c && h && (c = this.getMaterial(h)), !y && e ? y = Ve({
996
995
  points: e
997
- }) : !y && t ? y = H(
998
- t.map((g) => He({
996
+ }) : !y && t ? y = V(
997
+ t.map((g) => Ve({
999
998
  points: g
1000
999
  })),
1001
1000
  a != null ? a : 0
1002
- ) : !y && s && s.length > 1 ? y = H(s, a != null ? a : 0) : !y && s && s.length === 1 && ([y] = s);
1001
+ ) : !y && s && s.length > 1 ? y = V(s, a != null ? a : 0) : !y && s && s.length === 1 && ([y] = s);
1003
1002
  const u = new Ke().fromLineSegments(
1004
1003
  new Xe(y)
1005
1004
  );
@@ -36,6 +36,5 @@ export default class Line extends BaseObject {
36
36
  startShow?: boolean;
37
37
  }): void;
38
38
  render(): void;
39
- dispose(): void;
40
39
  }
41
40
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gl-draw",
3
- "version": "0.15.24",
3
+ "version": "0.15.25",
4
4
  "author": "gitplus <hstits@gmail.com>",
5
5
  "scripts": {
6
6
  "start": "bundler-dev",