gl-draw 0.15.0-beta.42 → 0.15.0-beta.44

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 $e=Object.defineProperty,Xe=Object.defineProperties;var Ye=Object.getOwnPropertyDescriptors;var ae=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var Be=(c,e,t)=>e in c?$e(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t,E=(c,e)=>{for(var t in e||(e={}))Ee.call(e,t)&&Be(c,t,e[t]);if(ae)for(var t of ae(e))_e.call(e,t)&&Be(c,t,e[t]);return c},le=(c,e)=>Xe(c,Ye(e));var me=(c,e)=>{var t={};for(var n in c)Ee.call(c,n)&&e.indexOf(n)<0&&(t[n]=c[n]);if(c!=null&&ae)for(var n of ae(c))e.indexOf(n)<0&&_e.call(c,n)&&(t[n]=c[n]);return t};var ne=(c,e,t)=>new Promise((n,s)=>{var o=r=>{try{p(t.next(r))}catch(y){s(y)}},l=r=>{try{p(t.throw(r))}catch(y){s(y)}},p=r=>r.done?n(r.value):Promise.resolve(r.value).then(o,l);p((t=t.apply(c,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("../index2.js"),h=require("three"),Ze=require("@tweenjs/tween.js"),Je=require("three/examples/jsm/lights/RectAreaLightUniformsLib"),pe=require("three/examples/jsm/utils/BufferGeometryUtils"),Qe=require("three/examples/jsm/lines/LineSegments2"),Re=require("three/examples/jsm/lines/LineSegmentsGeometry"),De=require("three/examples/jsm/lines/LineMaterial"),Pe=require("../uvGenerator.js"),he=require("three-bvh-csg");function Ke(c){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const t in c)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(c,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>c[t]})}}return e.default=c,Object.freeze(e)}const K=Ke(Ze);class et extends _.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 o=0,l=0;t.left<0?o=-t.left:t.right>n&&(o=n-t.right),t.top<0?l=-t.top:t.bottom>s&&(l=s-t.bottom),t.left+o<0&&(o=-t.left),t.top+l<0&&(l=-t.top),(o!==0||l!==0)&&(e.style.transform=`translate(${o}px, ${l}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 tt extends _.BaseObject{create(){this.createGroup()}}const nt={ArcCurve:h.ArcCurve,CatmullRomCurve3:h.CatmullRomCurve3,CubicBezierCurve:h.CubicBezierCurve,CubicBezierCurve3:h.CubicBezierCurve3,EllipseCurve:h.EllipseCurve,LineCurve:h.LineCurve,LineCurve3:h.LineCurve3,QuadraticBezierCurve:h.QuadraticBezierCurve,QuadraticBezierCurve3:h.QuadraticBezierCurve3,SplineCurve:h.SplineCurve};class Z extends h.BufferGeometry{constructor(e=new h.Shape([new h.Vector2(.5,.5),new h.Vector2(-.5,.5),new h.Vector2(-.5,-.5),new h.Vector2(.5,-.5)]),t={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:e,options:t},e=Array.isArray(e)?e:[e];const n=this,s=[],o=[];for(let p=0,r=e.length;p<r;p++){const y=e[p];l(y)}this.setAttribute("position",new h.Float32BufferAttribute(s,3)),this.setAttribute("uv",new h.Float32BufferAttribute(o,2)),this.computeVertexNormals();function l(p){var Se,Ae,Me;const r=[],y=t.curveSegments!==void 0?t.curveSegments:12,i=t.steps!==void 0?t.steps:1,a=t.depth!==void 0?t.depth:1;let w=t.bevelEnabled!==void 0?t.bevelEnabled:!0,f=t.bevelThickness!==void 0?t.bevelThickness:.2,x=t.bevelSize!==void 0?t.bevelSize:f-.1,C=t.bevelOffset!==void 0?t.bevelOffset:0,L=t.bevelSegments!==void 0?t.bevelSegments:3;const M=t.extrudePath,B=t.UVGenerator!==void 0?t.UVGenerator:st,S=(Se=t.hasTop)!=null?Se:!0,I=(Ae=t.hasBottom)!=null?Ae:!0,ue=(Me=t.hasSide)!=null?Me:!0;let F,J=!1,$,ee,te,D;M&&(F=M.getSpacedPoints(i),J=!0,w=!1,$=M.computeFrenetFrames(i,!1),ee=new h.Vector3,te=new h.Vector3,D=new h.Vector3),w||(L=0,f=0,x=0,C=0);const ye=p.extractPoints(y);let z=ye.shape;const P=ye.holes;if(!h.ShapeUtils.isClockWise(z)){z=z.reverse();for(let u=0,d=P.length;u<d;u++){const m=P[u];h.ShapeUtils.isClockWise(m)&&(P[u]=m.reverse())}}function be(u){const m=10000000000000001e-36;let b=u[0];for(let g=1;g<=u.length;g++){const A=g%u.length,v=u[A],T=v.x-b.x,G=v.y-b.y,j=T*T+G*G,V=Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(b.x),Math.abs(b.y)),Y=m*V*V;if(j<=Y){u.splice(A,1),g--;continue}b=v}}be(z),P.forEach(be);const fe=P.length,U=z;for(let u=0;u<fe;u++){const d=P[u];z=z.concat(d)}function Q(u,d,m){return d||console.error("THREE.ExtrudeGeometry: vec does not exist"),u.clone().addScaledVector(d,m)}const H=z.length;function we(u,d,m){let b,g,A;const v=u.x-d.x,T=u.y-d.y,G=m.x-u.x,j=m.y-u.y,V=v*v+T*T,Y=v*j-T*G;if(Math.abs(Y)>Number.EPSILON){const O=Math.sqrt(V),Le=Math.sqrt(G*G+j*j),Ce=d.x-T/O,Te=d.y+v/O,ke=m.x-j/Le,Fe=m.y+G/Le,Ge=((ke-Ce)*j-(Fe-Te)*G)/(v*j-T*G);b=Ce+v*Ge-u.x,g=Te+T*Ge-u.y;const je=b*b+g*g;if(je<=2)return new h.Vector2(b,g);A=Math.sqrt(je/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?(b=-T,g=v,A=Math.sqrt(V)):(b=v,g=T,A=Math.sqrt(V/2))}return new h.Vector2(b/A,g/A)}const ie=[];for(let u=0,d=U.length,m=d-1,b=u+1;u<d;u++,m++,b++)m===d&&(m=0),b===d&&(b=0),ie[u]=we(U[u],U[m],U[b]);const de=[];let k,oe=ie.concat();for(let u=0,d=fe;u<d;u++){const m=P[u];k=[];for(let b=0,g=m.length,A=g-1,v=b+1;b<g;b++,A++,v++)A===g&&(A=0),v===g&&(v=0),k[b]=we(m[b],m[A],m[v]);de.push(k),oe=oe.concat(k)}let X;if(L===0)X=h.ShapeUtils.triangulateShape(U,P);else{const u=[],d=[];for(let m=0;m<L;m++){const b=m/L,g=f*Math.cos(b*Math.PI/2),A=x*Math.sin(b*Math.PI/2)+C;for(let v=0,T=U.length;v<T;v++){const G=Q(U[v],ie[v],A);N(G.x,G.y,-g),b===0&&u.push(G)}for(let v=0,T=fe;v<T;v++){const G=P[v];k=de[v];const j=[];for(let V=0,Y=G.length;V<Y;V++){const O=Q(G[V],k[V],A);N(O.x,O.y,-g),b===0&&j.push(O)}b===0&&d.push(j)}}X=h.ShapeUtils.triangulateShape(u,d)}const re=X.length,xe=x+C;for(let u=0;u<H;u++){const d=w?Q(z[u],oe[u],xe):z[u];J?(te.copy($.normals[0]).multiplyScalar(d.x),ee.copy($.binormals[0]).multiplyScalar(d.y),D.copy(F[0]).add(te).add(ee),N(D.x,D.y,D.z)):N(d.x,d.y,0)}for(let u=1;u<=i;u++)for(let d=0;d<H;d++){const m=w?Q(z[d],oe[d],xe):z[d];J?(te.copy($.normals[u]).multiplyScalar(m.x),ee.copy($.binormals[u]).multiplyScalar(m.y),D.copy(F[u]).add(te).add(ee),N(D.x,D.y,D.z)):N(m.x,m.y,a/i*u)}for(let u=L-1;u>=0;u--){const d=u/L,m=f*Math.cos(d*Math.PI/2),b=x*Math.sin(d*Math.PI/2)+C;for(let g=0,A=U.length;g<A;g++){const v=Q(U[g],ie[g],b);N(v.x,v.y,a+m)}for(let g=0,A=P.length;g<A;g++){const v=P[g];k=de[g];for(let T=0,G=v.length;T<G;T++){const j=Q(v[T],k[T],b);J?N(j.x,j.y+F[i-1].y,F[i-1].x+m):N(j.x,j.y,a+m)}}}Ne(),ue&&We();function Ne(){const u=s.length/3;if(w){let d=0,m=H*d;if(I)for(let b=0;b<re;b++){const g=X[b];ce(g[2]+m,g[1]+m,g[0]+m)}if(d=i+L*2,m=H*d,S)for(let b=0;b<re;b++){const g=X[b];ce(g[0]+m,g[1]+m,g[2]+m)}}else{if(I)for(let d=0;d<re;d++){const m=X[d];ce(m[2],m[1],m[0])}if(S)for(let d=0;d<re;d++){const m=X[d];ce(m[0]+H*i,m[1]+H*i,m[2]+H*i)}}n.addGroup(u,s.length/3-u,0)}function We(){const u=s.length/3;let d=0;ve(U,d),d+=U.length;for(let m=0,b=P.length;m<b;m++){const g=P[m];ve(g,d),d+=g.length}n.addGroup(u,s.length/3-u,1)}function ve(u,d){let m=u.length;for(;--m>=0;){const b=m;let g=m-1;g<0&&(g=u.length-1);for(let A=0,v=i+L*2;A<v;A++){const T=H*A,G=H*(A+1),j=d+b+T,V=d+g+T,Y=d+g+G,O=d+b+G;qe(j,V,Y,O)}}}function N(u,d,m){r.push(u),r.push(d),r.push(m)}function ce(u,d,m){W(u),W(d),W(m);const b=s.length/3,g=B.generateTopUV(n,s,b-3,b-2,b-1);q(g[0]),q(g[1]),q(g[2])}function qe(u,d,m,b){W(u),W(d),W(b),W(d),W(m),W(b);const g=s.length/3,A=B.generateSideWallUV(n,s,g-6,g-3,g-2,g-1);q(A[0]),q(A[1]),q(A[3]),q(A[1]),q(A[2]),q(A[3])}function W(u){s.push(r[u*3+0]),s.push(r[u*3+1]),s.push(r[u*3+2])}function q(u){o.push(u.x),o.push(u.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 it(t,n,e)}static fromJSON(e,t){const n=[];for(let o=0,l=e.shapes.length;o<l;o++){const p=t[e.shapes[o]];n.push(p)}const s=e.options.extrudePath;return s!==void 0&&(e.options.extrudePath=new nt[`${s.type}`]().fromJSON(s)),new Z(n,e.options)}}const st={generateTopUV:function(c,e,t,n,s){const o=e[t*3],l=e[t*3+1],p=e[n*3],r=e[n*3+1],y=e[s*3],i=e[s*3+1];return[new h.Vector2(o,l),new h.Vector2(p,r),new h.Vector2(y,i)]},generateSideWallUV:function(c,e,t,n,s,o){const l=e[t*3],p=e[t*3+1],r=e[t*3+2],y=e[n*3],i=e[n*3+1],a=e[n*3+2],w=e[s*3],f=e[s*3+1],x=e[s*3+2],C=e[o*3],L=e[o*3+1],M=e[o*3+2];return Math.abs(p-i)<Math.abs(l-y)?[new h.Vector2(l,1-r),new h.Vector2(y,1-a),new h.Vector2(w,1-x),new h.Vector2(C,1-M)]:[new h.Vector2(p,1-r),new h.Vector2(i,1-a),new h.Vector2(f,1-x),new h.Vector2(L,1-M)]}};function it(c,e,t){if(t.shapes=[],Array.isArray(c))for(let n=0,s=c.length;n<s;n++){const o=c[n];t.shapes.push(o.uuid)}else t.shapes.push(c.uuid);return t.options=Object.assign({},e),e.extrudePath!==void 0&&(t.options.extrudePath=e.extrudePath.toJSON()),t}class ot extends _.BaseObject{constructor(e){super(),this.options=E({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},e)}create(){return ne(this,null,function*(){this.createGroup();const{data:e,maxDepth:t,colors:n,material:s,percentDepth:o,activeIndex:l}=this.options,p=Math.max(...e),r=e.reduce((i,a)=>i+a,0);let y=Math.PI/2;e.forEach((i,a)=>{if(i===0)return;const w=Math.PI*2*(i/r),f=n[a],x=o?t*(i/p):t,C=this.createGeometry(x,w),L=s?s.clone():new h.MeshBasicMaterial({color:f});s&&L.color.set(f);const M=new h.Mesh(C,L);M.userData.depth=x,M.userData.index=a,M.rotateZ(y),y+=w,this.add(M)}),l!==-1&&this.setActive(l)})}createGeometry(e,t){const{outRadius:n,innerRadius:s}=this.options,o=new h.Shape;return o.moveTo(n,0),o.lineTo(s,0),o.absarc(0,0,s,0,t,!1),o.absarc(0,0,n,t,0,!0),new Z(o,{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(o=>o===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 o=new K.Tween(s.scale).to({z:1},100);s.userData.levTween=o,o.start()}}),n){if(n.userData.enTween)return;n.userData.levTween&&(n.userData.levTween.stop(),n.userData.levTween=null);const s=new K.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 K.Tween(this.object3d.scale).to({z:1},1e3).easing(K.Easing.Sinusoidal.InOut).start()}}class rt extends _.BaseObject{constructor(e){super(),this.rectAreaLightUniformsLibInit=!1,this.options=e}create(){var t,n,s,o,l,p,r,y,i,a,w,f,x,C,L,M,B;const e=this.options;if(e.type==="AmbientLight"){const S=new h.AmbientLight(e.color);S.name="环境光",this.object3d=S}else if(e.type==="DirectionalLight"){const S=new h.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 h.PointLight((t=e.color)!=null?t:16777215,(n=e.intensity)!=null?n:1,(s=e.distance)!=null?s:0,(o=e.decay)!=null?o:2);S.name="点光源",this.object3d=S,this.pointLight=S}else if(e.type==="SpotLight"){const S=new h.SpotLight((l=e.color)!=null?l:16777215,(p=e.intensity)!=null?p:1,(r=e.distance)!=null?r:0,(y=e.angle)!=null?y:Math.PI/3,(i=e.penumbra)!=null?i:1,(a=e.decay)!=null?a:2);S.name="聚光灯",this.object3d=S,this.spotLight=S,S.target.name="聚光灯目标"}else if(e.type==="HemisphereLight"){const S=new h.HemisphereLight((w=e.color)!=null?w:16777215,(f=e.groundColor)!=null?f:16777215,(x=e.intensity)!=null?x:1);S.name="半球光",this.object3d=S,this.hemisphereLight=S}else if(e.type==="RectAreaLight"){this.rectAreaLightUniformsLibInit||(Je.RectAreaLightUniformsLib.init(),this.rectAreaLightUniformsLibInit=!0);const S=new h.RectAreaLight((C=e.color)!=null?C:16777215,(L=e.intensity)!=null?L: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()}}function R(c,e=0){const t=c[0].index!==null,n=new Set(Object.keys(c[0].attributes)),s=new Set(Object.keys(c[0].morphAttributes)),o={},l={},p=c[0].morphTargetsRelative,r=new h.BufferGeometry;let y=0;for(let i=0;i<c.length;++i){const a=c[i];let w=0;if(t!==(a.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in a.attributes){if(!n.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;o[f]===void 0&&(o[f]=[]),o[f].push(a.attributes[f]),w++}if(w!==n.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". Make sure all geometries have the same number of attributes."),null;if(p!==a.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in a.morphAttributes){if(!s.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". .morphAttributes must be consistent throughout all geometries."),null;l[f]===void 0&&(l[f]=[]),l[f].push(a.morphAttributes[f])}if(e){let f;if(t)f=a.index.count;else if(a.attributes.position!==void 0)f=a.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". The geometry must have either an index or a position attribute"),null;if(e===1)r.addGroup(y,f,i);else if(e===2&&a.groups.length>0)for(let x of a.groups){let C=x.materialIndex;r.addGroup(y+x.start,Math.min(x.count,f),C)}y+=f}}if(t){let i=0;const a=[];for(let w=0;w<c.length;++w){const f=c[w].index;for(let x=0;x<f.count;++x)a.push(f.getX(x)+i);i+=c[w].attributes.position.count}r.setIndex(a)}for(const i in o){const a=pe.mergeAttributes(o[i]);if(!a)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+i+" attribute."),null;r.setAttribute(i,a)}for(const i in l){const a=l[i][0].length;if(a===0)break;r.morphAttributes=r.morphAttributes||{},r.morphAttributes[i]=[];for(let w=0;w<a;++w){const f=[];for(let C=0;C<l[i].length;++C)f.push(l[i][C][w]);const x=pe.mergeAttributes(f);if(!x)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+i+" morphAttribute."),null;r.morphAttributes[i].push(x)}}return e===2?pe.mergeGroups(r):r}const Ve=c=>{const{points:e}=c,t=e.reduce((s,o,l)=>(l<e.length-1&&s.push(o,e[l+1]),s),[]);return new h.BufferGeometry().setFromPoints(t)};let ct=class extends _.BaseObject{constructor(e={}){super(),this.options=E({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return ne(this,null,function*(){const{points:e,pointsArr:t,geometry:n,geometryArr:s,material:o,useGroups:l,setPointWidth:p,lineWidthArr:r,materialParameters:y,instanceCount:i}=this.options;let a=o,w=n;!a&&y&&(a=this.getMaterial(y)),!w&&e?w=Ve({points:e}):!w&&t?w=R(t.map(x=>Ve({points:x})),l!=null?l:0):!w&&s&&s.length>1?w=R(s,l!=null?l:0):!w&&s&&s.length===1&&([w]=s);const f=new Re.LineSegmentsGeometry().fromLineSegments(new h.LineSegments(w));if(this.pencil.options.WebGPUTHREE){i&&(f.instanceCount=i);const x=new _.LineSegments2(f,a);x.computeLineDistances(),this.object3d=x}else{const x=new Qe.LineSegments2(f,a);x.computeLineDistances(),this.object3d=x}})}getMaterial(e){return new De.LineMaterial(E({color:new h.Color("#ffffff")},e))}};const se=(c,e,t,n,s)=>{c[e+0]=t,c[e+1]=n,c[e+2]=s,c[e+3]=t,c[e+4]=n,c[e+5]=s},Oe=(c,e,t,n)=>{c[e+0]=t,c[e+1]=n},ze=(c,e,t,n,s)=>{c[e+0]=t,c[e+1]=n,c[e+2]=s},at=(c,e,t,n,s,o)=>{c[e+0]=t,c[e+1]=n,c[e+2]=s,c[e+3]=o};class He extends h.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 h.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 h.Vector3(n[s],n[s+1],n[s+2]));return t}else return e.map(t=>{if(t instanceof h.Vector2)return new h.Vector3(t.x,t.y,0);if(t instanceof h.Vector3)return t;if(Array.isArray(t)&&t.length===2)return new h.Vector3(t[0],t[1],0);if(Array.isArray(t)&&t.length===3)return new h.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=[];let t=0;const n=[],s=[];let o=0;const l=[];let p=0;const r=[];let y=0;this.shape==="taper"&&(this.shapeFunction=i=>1*Math.pow(4*i*(1-i),1));for(let i=0;i<this.pointCount;i++){const a=i/this._points.length;e[t+0]=a,e[t+1]=a,t+=2,Oe(n,o,1,-1);const w=this.shape==="none"?1:this.shapeFunction(i/(this.pointCount-1));if(Oe(s,o,w,w),o+=2,at(l,p,i/(this.pointCount-1),0,i/(this.pointCount-1),1),p+=4,i<this.pointCount-1){const f=i*2;ze(r,y,f+0,f+1,f+2),ze(r,y+3,f+2,f+1,f+3),y+=6}}this.setAttribute("position",new h.BufferAttribute(new Float32Array(this.pointCount*6),3)),this.setAttribute("previous",new h.BufferAttribute(new Float32Array(this.pointCount*6),3)),this.setAttribute("next",new h.BufferAttribute(new Float32Array(this.pointCount*6),3)),this.setAttribute("counters",new h.BufferAttribute(new Float32Array(e),1)),this.setAttribute("side",new h.BufferAttribute(new Float32Array(n),1)),this.setAttribute("width",new h.BufferAttribute(new Float32Array(s),1)),this.setAttribute("uv",new h.BufferAttribute(new Float32Array(l),2)),this.setIndex(new h.BufferAttribute(new Uint16Array(r),1))}updateGeometry(){if(!this._points[0])return;const e=[],t=[],n=[];let s=0,o=0,l=0;se(t,o,this._points[0].x,this._points[0].y,this._points[0].z),o+=6;for(let i=0;i<this.pointCount;i++){const a=this._points[i];se(e,s,a.x,a.y,a.z),s+=6,i<this.pointCount-1&&(se(t,o,a.x,a.y,a.z),o+=6),i>0&&i+1<=this.pointCount&&(se(n,l,a.x,a.y,a.z),l+=6)}se(n,l,this._points[this.pointCount-1].x,this._points[this.pointCount-1].y,this._points[this.pointCount-1].z);const p=this.getAttribute("position"),r=this.getAttribute("previous"),y=this.getAttribute("next");p.set(e),r.set(t),y.set(n),p.needsUpdate=!0,r.needsUpdate=!0,y.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())}}const ge=c=>{const{setPointWidth:e,nodes:t}=c,n=new He;return n.setPoints(t,e),n};class lt extends _.BaseObject{constructor(e={}){super(),this.options=E({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return ne(this,null,function*(){const{nodes:e,nodesArr:t,geometry:n,geometryArr:s,material:o,useGroups:l,setPointWidth:p,lineWidthArr:r,materialParameters:y}=this.options;let i=o,a=n;!i&&y&&(i=this.getMaterial(y)),!a&&e?a=ge({nodes:e,setPointWidth:p}):!a&&t?a=R(t.map((w,f)=>{let x=p;return!x&&r&&(x=()=>{var C;return(C=r[f])!=null?C:r[0]}),ge({nodes:w,setPointWidth:x})}),l!=null?l:0):!a&&s&&s.length>1?a=R(s,l!=null?l:0):!a&&s&&s.length===1&&([a]=s),this.createMesh(a,i)})}setGeometry(e,t){const n=ge({nodes:e,setPointWidth:t}),s=this.object3d,o=s.geometry;s.geometry=n,o.dispose()}getMaterial(e){const{width:t,height:n}=this.pencil.getSize(),s=new _.MeshLineMaterial(E({color:new h.Color("#ffffff")},e));return s.uniforms.resolution.value.set(t,n),s}addGeometries(e){const t=this.object3d,n=R([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:o,onUpdate:l,onComplete:p,startShow:r}={}){const{offset:y,offsetLoop:i}=this.material.uniforms;if(this.material.userData.tween)return;const a=s!=null?s:!0;y.value.x=1,i.value=a&&r?1:0;let w=0;const f=new K.Tween(y.value).to({x:-1},e).delay(t).repeat(n).onUpdate(({x})=>{a&&x<=0&&i.value===0&&(i.value=1),l&&l(x)}).onRepeat(()=>{w+=1,o&&o(w)}).onComplete(()=>{p&&p()}).start();this.material.userData.tween=f}render(){const{width:e,height:t}=this.pencil.getSize();this.resize(e,t)}dispose(){this.material.userData.tween&&(this.material.userData.tween.stop(),K.remove(this.material.userData.tween)),super.dispose()}}const Ie=c=>{const p=c,{coordinate:e,startHeight:t,height:n}=p,s=me(p,["coordinate","startHeight","height"]);let o=t||0;return typeof t!="undefined"&&typeof n!="undefined"&&(o=t+n),new _.PolygonGeometry([e],le(E({},s),{startHeight:t,endHeight:o}))};class ht extends _.BaseObject{constructor(e){super(),this.options=E({},e)}create(){const r=this.options,{geometry:e,coordinateArr:t,coordinate:n,material:s,useGroups:o}=r,l=me(r,["geometry","coordinateArr","coordinate","material","useGroups"]);let p=e;if(!p&&n)p=Ie(E({coordinate:n},l));else if(!p&&t){const y=t.map(i=>Ie(E({coordinate:i},l)));p=R(y,o!=null?o:0)}this.createMesh(p,s)}}class ut extends Z{constructor(e,t){super(e,t);const n=new he.Brush(new Z(e,le(E({},t),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const s=new h.Box3().setFromObject(n),o=new h.Vector3;s.getSize(o);const l=new h.Vector3(s.min.x+o.x/2,s.min.y+o.y/2,0);let p=t.topSegments,r=t.box3;if(r){r=r.union(s);const M=new h.Vector3;r.getSize(M);const B=Math.max(o.x/M.x,o.y/M.y);p=Math.ceil(t.topSegments*B)}if(p<4)return this;const y=new h.PlaneGeometry(o.x,o.y,p,p),i=new he.Brush(y);i.position.set(l.x,l.y,l.z),i.updateMatrixWorld();const w=new he.Evaluator().evaluate(i,n,he.INTERSECTION),f=w.geometry.getAttribute("position"),x=new h.Float32BufferAttribute(f.count*2,2);for(let M=0;M<f.count;M++){const B=f.getZ(M);f.setZ(M,t.depth+B)}if(r){const M=r.min,B=r.max,S=new h.Vector3().subVectors(B,M);for(let I=0;I<f.count;I++){const ue=f.getX(I),F=f.getY(I),J=(ue-M.x)/S.x,$=(F-M.y)/S.y;x.setXY(I,J,$)}w.geometry.setAttribute("uv",x)}f.needsUpdate=!0;const C=new Z(e,le(E({},t),{hasTop:!1})),L=R([w.geometry,C],2);this.copy(L.toNonIndexed())}}const Ue=c=>{const{split:e,depth:t,points:n,box3:s,hasTop:o,hasBottom:l,hasSide:p,sideRepeat:r,topSegments:y}=c,i=y?ut:Z,a=new i(new h.Shape(n),{depth:t,bevelEnabled:!1,box3:s,UVGenerator:Pe.getUVGenerator({split:e,box3:s,sideRepeat:r}),hasTop:o,hasBottom:l,hasSide:p,topSegments:y});return Pe.claerUVGenerator(),a};class ft extends _.BaseObject{constructor(e){super(),this.options=E({depth:1},e)}create(){return ne(this,null,function*(){const{points:e,pointsArr:t,useGroups:n,depth:s,geometry:o,geometryArr:l,material:p,box3:r,split:y,hasTop:i,hasBottom:a,hasSide:w}=this.options,f=Array.isArray(s)?s:[s],x=Array.isArray(r)?r:[r],C=p;let L=o;C||console.log("material is null"),!L&&e?L=Ue({points:e,depth:f[0],box3:x[0],split:y,hasTop:i,hasBottom:a,hasSide:w}):!L&&t?L=R(t.map((M,B)=>{var S,I;return Ue({points:M,depth:(S=f[B])!=null?S:f[0],box3:(I=x[B])!=null?I:x[0],split:y,hasTop:i,hasBottom:a,hasSide:w})}),n!=null?n:0):!L&&l&&l.length>1?L=R(l,n!=null?n:0):!L&&l&&l.length===1&&([L]=l),this.createMesh(L,C)})}addGeometries(e){const t=this.object3d,n=R([t.geometry,...e]);t.geometry=n}setTextureAnisotropic(e,t){e.anisotropy=t||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const dt=c=>{const{topColor:e,sideColor:t,sideMap:n,createCanvasObjectURL:s,split:o,maxAnisotropy:l}=c;return new Promise(p=>{const r=n?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};r.onload=()=>{const y=o,i=document.createElement("canvas"),a=i.getContext("2d");i.height=r.height/(1-y),i.width=r.width,y&&e&&(a.fillStyle=e,a.fillRect(0,0,r.width,i.height*y)),n&&r instanceof HTMLImageElement?a.drawImage(r,0,i.height*y,r.width,r.height):t&&(a.fillStyle=t,a.fillRect(0,i.height*y,r.width,r.height)),s&&i.toBlob(f=>{console.log(URL.createObjectURL(f))});const w=new h.CanvasTexture(i);p(w)},n?r.src=n:r instanceof HTMLImageElement||r.onload()})};exports.MeshLineMaterial=_.MeshLineMaterial;exports.getConicPolygonGeometry=_.PolygonGeometry;exports.getConicPolygonGeometryMetas=_.getMetas;Object.defineProperty(exports,"LineSegmentsGeometry",{enumerable:!0,get:()=>Re.LineSegmentsGeometry});Object.defineProperty(exports,"Line2Material",{enumerable:!0,get:()=>De.LineMaterial});exports.ConicPolygon=ht;exports.ExtrudePolygon=ft;exports.Group=tt;exports.Light=rt;exports.Line=lt;exports.Line2=ct;exports.MeshLineGeometry=He;exports.Node=et;exports.Pie=ot;exports.getSplitTexture=dt;
1
+ "use strict";var qe=Object.defineProperty,We=Object.defineProperties;var ke=Object.getOwnPropertyDescriptors;var ae=Object.getOwnPropertySymbols;var je=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var Be=(p,e,t)=>e in p?qe(p,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):p[e]=t,E=(p,e)=>{for(var t in e||(e={}))je.call(e,t)&&Be(p,t,e[t]);if(ae)for(var t of ae(e))Ee.call(e,t)&&Be(p,t,e[t]);return p},ce=(p,e)=>We(p,ke(e));var de=(p,e)=>{var t={};for(var n in p)je.call(p,n)&&e.indexOf(n)<0&&(t[n]=p[n]);if(p!=null&&ae)for(var n of ae(p))e.indexOf(n)<0&&Ee.call(p,n)&&(t[n]=p[n]);return t};var ne=(p,e,t)=>new Promise((n,s)=>{var i=r=>{try{g(t.next(r))}catch(u){s(u)}},a=r=>{try{g(t.throw(r))}catch(u){s(u)}},g=r=>r.done?n(r.value):Promise.resolve(r.value).then(i,a);g((t=t.apply(p,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("../index2.js"),c=require("three"),Fe=require("@tweenjs/tween.js"),Ye=require("three/examples/jsm/lights/RectAreaLightUniformsLib"),me=require("three/examples/jsm/utils/BufferGeometryUtils"),Ze=require("three/examples/jsm/lines/LineSegments2"),Oe=require("three/examples/jsm/lines/LineSegmentsGeometry"),Ie=require("three/examples/jsm/lines/LineMaterial"),Pe=require("../uvGenerator.js"),le=require("three-bvh-csg");function $e(p){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(p){for(const t in p)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(p,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>p[t]})}}return e.default=p,Object.freeze(e)}const K=$e(Fe);class Je 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 Qe extends P.BaseObject{create(){this.createGroup()}}const Ke={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 $ 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 g=0,r=e.length;g<r;g++){const u=e[g];a(u)}this.setAttribute("position",new c.Float32BufferAttribute(s,3)),this.setAttribute("uv",new c.Float32BufferAttribute(i,2)),this.computeVertexNormals();function a(g){var ve,Se,Ae;const r=[],u=t.curveSegments!==void 0?t.curveSegments:12,o=t.steps!==void 0?t.steps:1,h=t.depth!==void 0?t.depth:1;let w=t.bevelEnabled!==void 0?t.bevelEnabled:!0,m=t.bevelThickness!==void 0?t.bevelThickness:.2,b=t.bevelSize!==void 0?t.bevelSize:m-.1,C=t.bevelOffset!==void 0?t.bevelOffset:0,L=t.bevelSegments!==void 0?t.bevelSegments:3;const M=t.extrudePath,j=t.UVGenerator!==void 0?t.UVGenerator:et,S=(ve=t.hasTop)!=null?ve:!0,I=(Se=t.hasBottom)!=null?Se:!0,he=(Ae=t.hasSide)!=null?Ae:!0;let k,J=!1,F,ee,te,D;M&&(k=M.getSpacedPoints(o),J=!0,w=!1,F=M.computeFrenetFrames(o,!1),ee=new c.Vector3,te=new c.Vector3,D=new c.Vector3),w||(L=0,m=0,b=0,C=0);const ge=g.extractPoints(u);let O=ge.shape;const V=ge.holes;if(!c.ShapeUtils.isClockWise(O)){O=O.reverse();for(let l=0,f=V.length;l<f;l++){const d=V[l];c.ShapeUtils.isClockWise(d)&&(V[l]=d.reverse())}}function ye(l){const d=10000000000000001e-36;let x=l[0];for(let y=1;y<=l.length;y++){const A=y%l.length,v=l[A],T=v.x-x.x,G=v.y-x.y,B=T*T+G*G,_=Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(x.x),Math.abs(x.y)),Z=d*_*_;if(B<=Z){l.splice(A,1),y--;continue}x=v}}ye(O),V.forEach(ye);const ue=V.length,U=O;for(let l=0;l<ue;l++){const f=V[l];O=O.concat(f)}function Q(l,f,d){return f||console.error("THREE.ExtrudeGeometry: vec does not exist"),l.clone().addScaledVector(f,d)}const H=O.length;function be(l,f,d){let x,y,A;const v=l.x-f.x,T=l.y-f.y,G=d.x-l.x,B=d.y-l.y,_=v*v+T*T,Z=v*B-T*G;if(Math.abs(Z)>Number.EPSILON){const z=Math.sqrt(_),Me=Math.sqrt(G*G+B*B),Le=f.x-T/z,Ce=f.y+v/z,Ne=d.x-B/Me,Xe=d.y+G/Me,Te=((Ne-Le)*B-(Xe-Ce)*G)/(v*B-T*G);x=Le+v*Te-l.x,y=Ce+T*Te-l.y;const Ge=x*x+y*y;if(Ge<=2)return new c.Vector2(x,y);A=Math.sqrt(Ge/2)}else{let z=!1;v>Number.EPSILON?G>Number.EPSILON&&(z=!0):v<-Number.EPSILON?G<-Number.EPSILON&&(z=!0):Math.sign(T)===Math.sign(B)&&(z=!0),z?(x=-T,y=v,A=Math.sqrt(_)):(x=v,y=T,A=Math.sqrt(_/2))}return new c.Vector2(x/A,y/A)}const se=[];for(let l=0,f=U.length,d=f-1,x=l+1;l<f;l++,d++,x++)d===f&&(d=0),x===f&&(x=0),se[l]=be(U[l],U[d],U[x]);const fe=[];let W,oe=se.concat();for(let l=0,f=ue;l<f;l++){const d=V[l];W=[];for(let x=0,y=d.length,A=y-1,v=x+1;x<y;x++,A++,v++)A===y&&(A=0),v===y&&(v=0),W[x]=be(d[x],d[A],d[v]);fe.push(W),oe=oe.concat(W)}let Y;if(L===0)Y=c.ShapeUtils.triangulateShape(U,V);else{const l=[],f=[];for(let d=0;d<L;d++){const x=d/L,y=m*Math.cos(x*Math.PI/2),A=b*Math.sin(x*Math.PI/2)+C;for(let v=0,T=U.length;v<T;v++){const G=Q(U[v],se[v],A);N(G.x,G.y,-y),x===0&&l.push(G)}for(let v=0,T=ue;v<T;v++){const G=V[v];W=fe[v];const B=[];for(let _=0,Z=G.length;_<Z;_++){const z=Q(G[_],W[_],A);N(z.x,z.y,-y),x===0&&B.push(z)}x===0&&f.push(B)}}Y=c.ShapeUtils.triangulateShape(l,f)}const ie=Y.length,xe=b+C;for(let l=0;l<H;l++){const f=w?Q(O[l],oe[l],xe):O[l];J?(te.copy(F.normals[0]).multiplyScalar(f.x),ee.copy(F.binormals[0]).multiplyScalar(f.y),D.copy(k[0]).add(te).add(ee),N(D.x,D.y,D.z)):N(f.x,f.y,0)}for(let l=1;l<=o;l++)for(let f=0;f<H;f++){const d=w?Q(O[f],oe[f],xe):O[f];J?(te.copy(F.normals[l]).multiplyScalar(d.x),ee.copy(F.binormals[l]).multiplyScalar(d.y),D.copy(k[l]).add(te).add(ee),N(D.x,D.y,D.z)):N(d.x,d.y,h/o*l)}for(let l=L-1;l>=0;l--){const f=l/L,d=m*Math.cos(f*Math.PI/2),x=b*Math.sin(f*Math.PI/2)+C;for(let y=0,A=U.length;y<A;y++){const v=Q(U[y],se[y],x);N(v.x,v.y,h+d)}for(let y=0,A=V.length;y<A;y++){const v=V[y];W=fe[y];for(let T=0,G=v.length;T<G;T++){const B=Q(v[T],W[T],x);J?N(B.x,B.y+k[o-1].y,k[o-1].x+d):N(B.x,B.y,h+d)}}}Re(),he&&De();function Re(){const l=s.length/3;if(w){let f=0,d=H*f;if(I)for(let x=0;x<ie;x++){const y=Y[x];re(y[2]+d,y[1]+d,y[0]+d)}if(f=o+L*2,d=H*f,S)for(let x=0;x<ie;x++){const y=Y[x];re(y[0]+d,y[1]+d,y[2]+d)}}else{if(I)for(let f=0;f<ie;f++){const d=Y[f];re(d[2],d[1],d[0])}if(S)for(let f=0;f<ie;f++){const d=Y[f];re(d[0]+H*o,d[1]+H*o,d[2]+H*o)}}n.addGroup(l,s.length/3-l,0)}function De(){const l=s.length/3;let f=0;we(U,f),f+=U.length;for(let d=0,x=V.length;d<x;d++){const y=V[d];we(y,f),f+=y.length}n.addGroup(l,s.length/3-l,1)}function we(l,f){let d=l.length;for(;--d>=0;){const x=d;let y=d-1;y<0&&(y=l.length-1);for(let A=0,v=o+L*2;A<v;A++){const T=H*A,G=H*(A+1),B=f+x+T,_=f+y+T,Z=f+y+G,z=f+x+G;He(B,_,Z,z)}}}function N(l,f,d){r.push(l),r.push(f),r.push(d)}function re(l,f,d){X(l),X(f),X(d);const x=s.length/3,y=j.generateTopUV(n,s,x-3,x-2,x-1);q(y[0]),q(y[1]),q(y[2])}function He(l,f,d,x){X(l),X(f),X(x),X(f),X(d),X(x);const y=s.length/3,A=j.generateSideWallUV(n,s,y-6,y-3,y-2,y-1);q(A[0]),q(A[1]),q(A[3]),q(A[1]),q(A[2]),q(A[3])}function X(l){s.push(r[l*3+0]),s.push(r[l*3+1]),s.push(r[l*3+2])}function q(l){i.push(l.x),i.push(l.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 tt(t,n,e)}static fromJSON(e,t){const n=[];for(let i=0,a=e.shapes.length;i<a;i++){const g=t[e.shapes[i]];n.push(g)}const s=e.options.extrudePath;return s!==void 0&&(e.options.extrudePath=new Ke[`${s.type}`]().fromJSON(s)),new $(n,e.options)}}const et={generateTopUV:function(p,e,t,n,s){const i=e[t*3],a=e[t*3+1],g=e[n*3],r=e[n*3+1],u=e[s*3],o=e[s*3+1];return[new c.Vector2(i,a),new c.Vector2(g,r),new c.Vector2(u,o)]},generateSideWallUV:function(p,e,t,n,s,i){const a=e[t*3],g=e[t*3+1],r=e[t*3+2],u=e[n*3],o=e[n*3+1],h=e[n*3+2],w=e[s*3],m=e[s*3+1],b=e[s*3+2],C=e[i*3],L=e[i*3+1],M=e[i*3+2];return Math.abs(g-o)<Math.abs(a-u)?[new c.Vector2(a,1-r),new c.Vector2(u,1-h),new c.Vector2(w,1-b),new c.Vector2(C,1-M)]:[new c.Vector2(g,1-r),new c.Vector2(o,1-h),new c.Vector2(m,1-b),new c.Vector2(L,1-M)]}};function tt(p,e,t){if(t.shapes=[],Array.isArray(p))for(let n=0,s=p.length;n<s;n++){const i=p[n];t.shapes.push(i.uuid)}else t.shapes.push(p.uuid);return t.options=Object.assign({},e),e.extrudePath!==void 0&&(t.options.extrudePath=e.extrudePath.toJSON()),t}class nt extends P.BaseObject{constructor(e){super(),this.options=E({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},e)}create(){return ne(this,null,function*(){this.createGroup();const{data:e,maxDepth:t,colors:n,material:s,percentDepth:i,activeIndex:a}=this.options,g=Math.max(...e),r=e.reduce((o,h)=>o+h,0);let u=Math.PI/2;e.forEach((o,h)=>{if(o===0)return;const w=Math.PI*2*(o/r),m=n[h],b=i?t*(o/g):t,C=this.createGeometry(b,w),L=s?s.clone():new c.MeshBasicMaterial({color:m});s&&L.color.set(m);const M=new c.Mesh(C,L);M.userData.depth=b,M.userData.index=h,M.rotateZ(u),u+=w,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 $(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 K.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 K.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 K.Tween(this.object3d.scale).to({z:1},1e3).easing(K.Easing.Sinusoidal.InOut).start()}}class st extends P.BaseObject{constructor(e){super(),this.rectAreaLightUniformsLibInit=!1,this.options=e}create(){var t,n,s,i,a,g,r,u,o,h,w,m,b,C,L,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,(g=e.intensity)!=null?g:1,(r=e.distance)!=null?r:0,(u=e.angle)!=null?u:Math.PI/3,(o=e.penumbra)!=null?o:1,(h=e.decay)!=null?h:2);S.name="聚光灯",this.object3d=S,this.spotLight=S,S.target.name="聚光灯目标"}else if(e.type==="HemisphereLight"){const S=new c.HemisphereLight((w=e.color)!=null?w:16777215,(m=e.groundColor)!=null?m:16777215,(b=e.intensity)!=null?b:1);S.name="半球光",this.object3d=S,this.hemisphereLight=S}else if(e.type==="RectAreaLight"){this.rectAreaLightUniformsLibInit||(Ye.RectAreaLightUniformsLib.init(),this.rectAreaLightUniformsLibInit=!0);const S=new c.RectAreaLight((C=e.color)!=null?C:16777215,(L=e.intensity)!=null?L: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()}}function R(p,e=0){const t=p[0].index!==null,n=new Set(Object.keys(p[0].attributes)),s=new Set(Object.keys(p[0].morphAttributes)),i={},a={},g=p[0].morphTargetsRelative,r=new c.BufferGeometry;let u=0;for(let o=0;o<p.length;++o){const h=p[o];let w=0;if(t!==(h.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 m in h.attributes){if(!n.has(m))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+'. All geometries must have compatible attributes; make sure "'+m+'" attribute exists among all geometries, or in none of them.'),null;i[m]===void 0&&(i[m]=[]),i[m].push(h.attributes[m]),w++}if(w!==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(g!==h.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const m in h.morphAttributes){if(!s.has(m))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". .morphAttributes must be consistent throughout all geometries."),null;a[m]===void 0&&(a[m]=[]),a[m].push(h.morphAttributes[m])}if(e){let m;if(t)m=h.index.count;else if(h.attributes.position!==void 0)m=h.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(u,m,o);else if(e===2&&h.groups.length>0)for(let b of h.groups){let C=b.materialIndex;r.addGroup(u+b.start,Math.min(b.count,m),C)}u+=m}}if(t){let o=0;const h=[];for(let w=0;w<p.length;++w){const m=p[w].index;for(let b=0;b<m.count;++b)h.push(m.getX(b)+o);o+=p[w].attributes.position.count}r.setIndex(h)}for(const o in i){const h=me.mergeAttributes(i[o]);if(!h)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+o+" attribute."),null;r.setAttribute(o,h)}for(const o in a){const h=a[o][0].length;if(h===0)break;r.morphAttributes=r.morphAttributes||{},r.morphAttributes[o]=[];for(let w=0;w<h;++w){const m=[];for(let C=0;C<a[o].length;++C)m.push(a[o][C][w]);const b=me.mergeAttributes(m);if(!b)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+o+" morphAttribute."),null;r.morphAttributes[o].push(b)}}return e===2?me.mergeGroups(r):r}const Ve=p=>{const{points:e}=p,t=e.reduce((s,i,a)=>(a<e.length-1&&s.push(i,e[a+1]),s),[]);return new c.BufferGeometry().setFromPoints(t)};let ot=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 ne(this,null,function*(){const{points:e,pointsArr:t,geometry:n,geometryArr:s,material:i,useGroups:a,setPointWidth:g,lineWidthArr:r,materialParameters:u,instanceCount:o}=this.options;let h=i,w=n;!h&&u&&(h=this.getMaterial(u)),!w&&e?w=Ve({points:e}):!w&&t?w=R(t.map(b=>Ve({points:b})),a!=null?a:0):!w&&s&&s.length>1?w=R(s,a!=null?a:0):!w&&s&&s.length===1&&([w]=s);const m=new Oe.LineSegmentsGeometry().fromLineSegments(new c.LineSegments(w));if(this.pencil.options.WebGPUTHREE){o&&(m.instanceCount=o);const b=new P.LineSegments2(m,h);b.computeLineDistances(),this.object3d=b}else{const b=new Ze.LineSegments2(m,h);b.computeLineDistances(),this.object3d=b}})}getMaterial(e){return new Ie.LineMaterial(E({color:new c.Color("#ffffff")},e))}};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),g=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=u=>1*Math.pow(4*u*(1-u),1));for(let u=0,o=0,h=0;u<this.pointCount;u+=1,o+=2,h+=6){s.setX(o,u/this.pointCount),s.setX(o+1,u/this.pointCount),i.setX(o,1),i.setX(o+1,-1);const w=this.shape==="none"?1:this.shapeFunction(u/(this.pointCount-1));a.setX(o,w),a.setX(o+1,w);const m=u/(this.pointCount-1);if(g.setXY(o,m,0),g.setXY(o+1,m,1),u<this.pointCount-1){const b=u*2;r.setX(h+0,b+0),r.setX(h+1,b+1),r.setX(h+2,b+2),r.setX(h+3,b+2),r.setX(h+4,b+1),r.setX(h+5,b+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",g),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 g=this._points[0];t.setXYZ(i,g.x,g.y,g.z),i+=1,t.setXYZ(i,g.x,g.y,g.z),i+=1;for(let u=0;u<this.pointCount;u++){const o=this._points[u];e.setXYZ(s,o.x,o.y,o.z),s+=1,e.setXYZ(s,o.x,o.y,o.z),s+=1,u<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),u>0&&u+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())}}const pe=p=>{const{setPointWidth:e,nodes:t}=p,n=new Ue;return n.setPoints(t,e),n};class it 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 ne(this,null,function*(){const{nodes:e,nodesArr:t,geometry:n,geometryArr:s,material:i,useGroups:a,setPointWidth:g,lineWidthArr:r,materialParameters:u}=this.options;let o=i,h=n;!o&&u&&(o=this.getMaterial(u)),!h&&e?h=pe({nodes:e,setPointWidth:g}):!h&&t?h=R(t.map((w,m)=>{let b=g;return!b&&r&&(b=()=>{var C;return(C=r[m])!=null?C:r[0]}),pe({nodes:w,setPointWidth:b})}),a!=null?a:0):!h&&s&&s.length>1?h=R(s,a!=null?a:0):!h&&s&&s.length===1&&([h]=s),this.createMesh(h,o)})}setGeometry(e,t){const n=pe({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=R([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:g,startShow:r}={}){const{offset:u,offsetLoop:o}=this.material.uniforms;if(this.material.userData.tween)return;const h=s!=null?s:!0;u.value.x=1,o.value=h&&r?1:0;let w=0;const m=new K.Tween(u.value).to({x:-1},e).delay(t).repeat(n).onUpdate(({x:b})=>{h&&b<=0&&o.value===0&&(o.value=1),a&&a(b)}).onRepeat(()=>{w+=1,i&&i(w)}).onComplete(()=>{g&&g()}).start();this.material.userData.tween=m}render(){const{width:e,height:t}=this.pencil.getSize();this.resize(e,t)}dispose(){this.material.userData.tween&&(this.material.userData.tween.stop(),K.remove(this.material.userData.tween)),super.dispose()}}const _e=p=>{const g=p,{coordinate:e,startHeight:t,height:n}=g,s=de(g,["coordinate","startHeight","height"]);let i=t||0;return typeof t!="undefined"&&typeof n!="undefined"&&(i=t+n),new P.PolygonGeometry([e],ce(E({},s),{startHeight:t,endHeight:i}))};class rt 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 g=e;if(!g&&n)g=_e(E({coordinate:n},a));else if(!g&&t){const u=t.map(o=>_e(E({coordinate:o},a)));g=R(u,i!=null?i:0)}this.createMesh(g,s)}}class at extends ${constructor(e,t){super(e,t);const n=new le.Brush(new $(e,ce(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 g=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);g=Math.ceil(t.topSegments*j)}if(g<4)return this;const u=new c.PlaneGeometry(i.x,i.y,g,g),o=new le.Brush(u);o.position.set(a.x,a.y,a.z),o.updateMatrixWorld();const w=new le.Evaluator().evaluate(o,n,le.INTERSECTION),m=w.geometry.getAttribute("position"),b=new c.Float32BufferAttribute(m.count*2,2);for(let M=0;M<m.count;M++){const j=m.getZ(M);m.setZ(M,t.depth+j)}if(r){const M=r.min,j=r.max,S=new c.Vector3().subVectors(j,M);for(let I=0;I<m.count;I++){const he=m.getX(I),k=m.getY(I),J=(he-M.x)/S.x,F=(k-M.y)/S.y;b.setXY(I,J,F)}w.geometry.setAttribute("uv",b)}m.needsUpdate=!0;const C=new $(e,ce(E({},t),{hasTop:!1})),L=R([w.geometry,C],2);this.copy(L.toNonIndexed())}}const ze=p=>{const{split:e,depth:t,points:n,box3:s,hasTop:i,hasBottom:a,hasSide:g,sideRepeat:r,topSegments:u}=p,o=u?at:$,h=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:g,topSegments:u});return Pe.claerUVGenerator(),h};class ct extends P.BaseObject{constructor(e){super(),this.options=E({depth:1},e)}create(){return ne(this,null,function*(){const{points:e,pointsArr:t,useGroups:n,depth:s,geometry:i,geometryArr:a,material:g,box3:r,split:u,hasTop:o,hasBottom:h,hasSide:w}=this.options,m=Array.isArray(s)?s:[s],b=Array.isArray(r)?r:[r],C=g;let L=i;C||console.log("material is null"),!L&&e?L=ze({points:e,depth:m[0],box3:b[0],split:u,hasTop:o,hasBottom:h,hasSide:w}):!L&&t?L=R(t.map((M,j)=>{var S,I;return ze({points:M,depth:(S=m[j])!=null?S:m[0],box3:(I=b[j])!=null?I:b[0],split:u,hasTop:o,hasBottom:h,hasSide:w})}),n!=null?n:0):!L&&a&&a.length>1?L=R(a,n!=null?n:0):!L&&a&&a.length===1&&([L]=a),this.createMesh(L,C)})}addGeometries(e){const t=this.object3d,n=R([t.geometry,...e]);t.geometry=n}setTextureAnisotropic(e,t){e.anisotropy=t||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const lt=p=>{const{topColor:e,sideColor:t,sideMap:n,createCanvasObjectURL:s,split:i,maxAnisotropy:a}=p;return new Promise(g=>{const r=n?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};r.onload=()=>{const u=i,o=document.createElement("canvas"),h=o.getContext("2d");o.height=r.height/(1-u),o.width=r.width,u&&e&&(h.fillStyle=e,h.fillRect(0,0,r.width,o.height*u)),n&&r instanceof HTMLImageElement?h.drawImage(r,0,o.height*u,r.width,r.height):t&&(h.fillStyle=t,h.fillRect(0,o.height*u,r.width,r.height)),s&&o.toBlob(m=>{console.log(URL.createObjectURL(m))});const w=new c.CanvasTexture(o);g(w)},n?r.src=n:r instanceof HTMLImageElement||r.onload()})};exports.MeshLineMaterial=P.MeshLineMaterial;exports.getConicPolygonGeometry=P.PolygonGeometry;exports.getConicPolygonGeometryMetas=P.getMetas;Object.defineProperty(exports,"LineSegmentsGeometry",{enumerable:!0,get:()=>Oe.LineSegmentsGeometry});Object.defineProperty(exports,"Line2Material",{enumerable:!0,get:()=>Ie.LineMaterial});exports.ConicPolygon=rt;exports.ExtrudePolygon=ct;exports.Group=Qe;exports.Light=st;exports.Line=it;exports.Line2=ot;exports.MeshLineGeometry=Ue;exports.Node=Je;exports.Pie=nt;exports.getSplitTexture=lt;