gl-draw 0.9.17 → 0.9.18
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.
- package/dist/objects/index.js +1 -1
- package/dist/objects/index.module.js +385 -390
- package/dist/objects/line/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/objects/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ee=Object.defineProperty,se=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var lt=Object.getOwnPropertySymbols;var Lt=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable;var Ct=Math.pow,It=(o,t,e)=>t in o?ee(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,C=(o,t)=>{for(var e in t||(t={}))Lt.call(t,e)&&It(o,e,t[e]);if(lt)for(var e of lt(t))Ut.call(t,e)&&It(o,e,t[e]);return o},Ot=(o,t)=>se(o,ie(t));var ft=(o,t)=>{var e={};for(var s in o)Lt.call(o,s)&&t.indexOf(s)<0&&(e[s]=o[s]);if(o!=null&<)for(var s of lt(o))t.indexOf(s)<0&&Ut.call(o,s)&&(e[s]=o[s]);return e};var Z=(o,t,e)=>new Promise((s,i)=>{var r=c=>{try{a(e.next(c))}catch(h){i(h)}},n=c=>{try{a(e.throw(c))}catch(h){i(h)}},a=c=>c.done?s(c.value):Promise.resolve(c.value).then(r,n);a((e=e.apply(o,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("three"),X=require("../BaseObject.js"),re=require("esus-lite"),ne=require("../index2.js"),oe=require("@tweenjs/tween.js"),xt=require("../MeshLineMaterial.js"),Y=require("d3-array"),gt=require("earcut"),ae=require("@turf/boolean-clockwise"),yt=require("../uvGenerator.js"),ce=require("delaunator"),le=require("@turf/boolean-point-in-polygon"),rt=require("d3-geo"),he=require("d3-geo-voronoi"),Rt=require("d3-scale");function Ft(o){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>o[e]})}}return t.default=o,Object.freeze(t)}const w=Ft(_),tt=Ft(oe),ue=+w.REVISION<144,Ht=ue?"PlaneBufferGeometry":"PlaneGeometry";class Wt extends X.BaseObject{constructor(t){super(),this.scaleValue=1,this.options=C({scale:1},t)}get material(){var t;return(t=this.object3d)==null?void 0:t.material}getMaterial(){return Z(this,null,function*(){const{src:t,texture:e,transparent:s,opacity:i,blending:r,depthWrite:n,depthTest:a,alphaTest:c,sprite:h,sizeAttenuation:l,color:d}=this.options,f=e||(yield new w.TextureLoader().loadAsync(t));return h?new w.SpriteMaterial({map:f,transparent:s!=null?s:!1,blending:r!=null?r:w.NormalBlending,depthWrite:n!=null?n:!0,depthTest:a!=null?a:!0,alphaTest:c!=null?c:0,opacity:i!=null?i:1,sizeAttenuation:l!=null?l:!0}):new w.MeshBasicMaterial({color:d!=null?d:16777215,map:f,transparent:s!=null?s:!1,blending:r!=null?r:w.NormalBlending,depthWrite:n!=null?n:!0,depthTest:a!=null?a:!0,alphaTest:c!=null?c:0,opacity:i!=null?i:1})})}create(){return Z(this,null,function*(){const{position:t,material:e,sprite:s}=this.options,i=e||(yield this.getMaterial());s?this.createSprite(i):this.createMesh(new w[Ht](1,1),i),t&&this.object3d.position.copy(t)})}render(){const{scale:t}=this.options;this.setScale(t)}setScale(t){this.scaleValue=t;const e=this.material.map;e!=null&&e.image?this.object3d.scale.set(e.image.width*t,e.image.height*t,1):this.object3d.scale.set(t,t,1)}setTexture(t){const e=this.object3d;e.material.map&&e.material.map.dispose(),e.material.map=t,e.material.needsUpdate=!0,this.setScale(this.scaleValue)}}class de extends Wt{constructor(t){super(t),this.canvas=document.createElement("canvas")}getTexture(){const{text:t,textOptions:e}=this.options,{fontSize:s,fontFamily:i,fontWeight:r,flipX:n,color:a,setCtx:c}=C({fontSize:28,fontFamily:"system-ui,-apple-system,BlinkMacSystemFont,sans-serif",fontWeight:"normal",flipX:!1,color:"#ffffff",setCtx:u=>{}},e||{}),{canvas:h}=this;h.width=s*t.length*2,h.height=s;let l=h.getContext("2d");l.font=`${r} ${s}px/1 ${i}`;const{width:d}=l.measureText(t);h.width=d,l=h.getContext("2d"),l.clearRect(0,0,h.width,h.height),n&&l.scale(-1,1),l.font=`${r} ${s}px/1 ${i}`,l.textBaseline="middle",l.fillStyle=a,c&&c(l),l.fillText(t,n?d*-1:0,h.height/2),l.restore();const f=new w.Texture(h);return f.anisotropy=this.pencil.renderer.capabilities.getMaxAnisotropy(),f.needsUpdate=!0,Promise.resolve(f)}}class fe extends X.BaseObject{constructor(t){super(),this.scaleValue=1,this.options=C({scale:1,autoPlay:!0,loop:!0},t)}getMaterial(){const{src:t,transparent:e,blending:s,depthWrite:i,depthTest:r,format:n,autoPlay:a,loop:c,alphaTest:h,sprite:l}=this.options,d=re.makePromiseCreator();if(!t)return Promise.reject("src is required");const f=document.createElement("video");return f.addEventListener("loadedmetadata",()=>{const u=new w.VideoTexture(f);u.format=n!=null?n:w.RGBAFormat,u.needsUpdate=!0;const b=l?new w.SpriteMaterial({map:u,transparent:e!=null?e:!1,blending:s!=null?s:w.NormalBlending,depthWrite:i!=null?i:!0,depthTest:r!=null?r:!0,alphaTest:h!=null?h:0}):new w.MeshBasicMaterial({map:u,transparent:e!=null?e:!1,blending:s!=null?s:w.NormalBlending,depthWrite:i!=null?i:!0,depthTest:r!=null?r:!0,alphaTest:h!=null?h:0});d.resolve(b)},!1),f.src=t,f.muted=!0,f.autoplay=a,f.loop=c,f.preload="auto",d.promise}create(){return Z(this,null,function*(){const{scale:t,position:e,src:s,cache:i,sprite:r}=this.options,n=s&&(i?yield i.get(s,()=>this.getMaterial()):yield this.getMaterial());this.video=n.map.image,r?this.createSprite(n):this.createMesh(new w[Ht](1,1),n),this.setScale(t),e&&this.object3d.position.copy(e)})}setScale(t){this.scaleValue=t,this.object3d.scale.set(this.video.videoWidth*t,this.video.videoHeight*t,1)}render(){const{autoPlay:t}=this.options;t&&this.video.play()}dispose(){this.video.pause(),this.video.src="",super.dispose()}}class pe extends X.BaseObject{constructor(t){super(),this.objectType="BaseObject#Node",this.drawGroupShow=!0,this.visibleCache=!0,this.options=C({event:"click",type:"2d"},t)}get clickTarge(){const{eventTarge:t}=this.options;return t?t.map(s=>[...this.element.querySelectorAll(s)]).flat():[this.element]}create(){const{position:t,children:e,handler:s,event:i}=this.options,r=document.createElement("div");this.element=r,e&&r.appendChild(e),this.options.type==="3d"?this.createCSS3DObject(r):this.options.type==="3dSprite"?this.createCSS3DSprite(r):this.createCSS2DObject(r),t&&this.object3d.position.copy(t),s&&i&&this.clickTarge.forEach(n=>{const a=Array.isArray(i)?i:[i],c=Array.isArray(s)?s:[s];a.forEach((h,l)=>{const d=c[l];d&&n.addEventListener(h,d)})})}setChildren(t){this.element.innerHTML="",this.element.appendChild(t)}render(){this.checkVisible()}show(){return this.visibleCache=!0,this.checkVisible(),this}hide(){return this.visibleCache=!1,this.checkVisible(),this}checkVisible(){this.drawGroupShow&&this.visibleCache?super.show():(!this.drawGroupShow||!this.visibleCache)&&super.hide()}dispose(){const{handler:t,event:e}=this.options;t&&e&&this.clickTarge.forEach(s=>{const i=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t];i.forEach((n,a)=>{const c=r[a];c&&s.removeEventListener(n,c)})}),super.dispose()}}class me extends X.BaseObject{constructor(t){super(),this.options=C({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},t)}create(){return Z(this,null,function*(){this.createGroup();const{data:t,maxDepth:e,colors:s,material:i,percentDepth:r,activeIndex:n}=this.options,a=Math.max(...t),c=t.reduce((l,d)=>l+d,0);let h=Math.PI/2;t.forEach((l,d)=>{if(l===0)return;const f=Math.PI*2*(l/c),u=s[d],b=r?e*(l/a):e,p=this.createGeometry(b,f),A=i?i.clone():new w.MeshBasicMaterial({color:u});i&&A.color.set(u);const S=new w.Mesh(p,A);S.userData.depth=b,S.userData.index=d,S.rotateZ(h),h+=f,this.add(S)}),n!==-1&&this.setActive(n)})}createGeometry(t,e){const{outRadius:s,innerRadius:i}=this.options,r=new w.Shape;return r.moveTo(s,0),r.lineTo(i,0),r.absarc(0,0,i,0,e,!1),r.absarc(0,0,s,e,0,!0),new w.ExtrudeGeometry(r,{curveSegments:48,depth:t,bevelEnabled:!1})}handlePick(t,e=1.3){const{object:s}=this.pencil.pick(t,this.object3d.children)||{},i=s?this.object3d.children.findIndex(r=>r===s):this.options.activeIndex;return this.setActive(i,e)}setActive(t,e=1.3){const s=this.object3d.children[t];if(this.object3d.children.forEach(i=>{if(!(s&&s===i)&&i.scale.z!==1){if(i.userData.levTween)return;i.userData.enTween&&(i.userData.enTween.stop(),i.userData.enTween=null);const r=new tt.Tween(i.scale).to({z:1},100);i.userData.levTween=r,r.start()}}),s){if(s.userData.enTween)return;s.userData.levTween&&(s.userData.levTween.stop(),s.userData.levTween=null);const i=new tt.Tween(s.scale).to({z:e},100);return s.userData.enTween=i,i.start(),s.userData.index}return-1}render(){this.object3d.scale.z=0,new tt.Tween(this.object3d.scale).to({z:1},1e3).easing(tt.Easing.Sinusoidal.InOut).start()}}class ge extends X.BaseObject{constructor(t){super(),this.options=t}create(){var e,s,i,r,n,a,c,h,l,d,f,u,b;const t=this.options;if(t.type==="AmbientLight"){const p=new w.AmbientLight(t.color);p.name="AmbientLight",this.object3d=p}else if(t.type==="DirectionalLight"){const p=new w.DirectionalLight(t.color,t.intensity);p.name="DirectionalLight",p.target.position.set(0,0,0),this.object3d=p,this.pencil.scene.add(p.target),this.directionalLight=p}else if(t.type==="PointLight"){const p=new w.PointLight((e=t.color)!=null?e:16777215,(s=t.intensity)!=null?s:1,(i=t.distance)!=null?i:0,(r=t.decay)!=null?r:2);p.name="PointLight",this.object3d=p,this.pointLight=p}else if(t.type==="SpotLight"){const p=new w.SpotLight((n=t.color)!=null?n:16777215,(a=t.intensity)!=null?a:1,(c=t.distance)!=null?c:0,(h=t.angle)!=null?h:Math.PI/3,(l=t.penumbra)!=null?l:1,(d=t.decay)!=null?d:2);p.name="SpotLight",this.object3d=p,this.spotLight=p,this.pencil.scene.add(p.target)}else if(t.type==="HemisphereLight"){const p=new w.HemisphereLight((f=t.color)!=null?f:16777215,(u=t.groundColor)!=null?u:16777215,(b=t.intensity)!=null?b:1);p.name="HemisphereLight",this.object3d=p,this.hemisphereLight=p}}render(){const t=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const e=this.spotLight||this.directionalLight;e.position.copy(t),e.target.position.copy(t)}else this.pointLight&&this.pointLight.position.copy(t)}dispose(){const t=this.object3d;t.target&&this.pencil.scene.remove(t.target),super.dispose()}}function pt(o,t,e,s,i){let r;if(o=o.subarray||o.slice?o:o.buffer,e=e.subarray||e.slice?e:e.buffer,o=t?o.subarray?o.subarray(t,i&&t+i):o.slice(t,i&&t+i):o,e.set)e.set(o,s);else for(r=0;r<o.length;r++)e[r+s]=o[r];return e}function ye(o){return o instanceof Float32Array?o:o instanceof w.BufferGeometry?o.getAttribute("position").array:o.map(t=>{const e=Array.isArray(t);return t instanceof w.Vector3?[t.x,t.y,t.z]:t instanceof w.Vector2?[t.x,t.y,0]:e&&t.length===3?[t[0],t[1],t[2]]:e&&t.length===2?[t[0],t[1],0]:t}).flat()}class $t extends w.BufferGeometry{constructor(){super(),this.type="MeshLine",this.isMeshLine=!0,this.positions=[],this.previous=[],this.next=[],this.side=[],this.width=[],this.indices_array=[],this.uvs=[],this.counters=[],this.widthCallback=null,this._points=[],this.matrixWorld=new w.Matrix4,Object.defineProperties(this,{points:{enumerable:!0,get(){return this._points},set(t){this.setPoints(t,this.widthCallback)}}})}setMatrixWorld(t){this.matrixWorld=t}setPoints(t,e){if(t=ye(t),this._points=t,this.widthCallback=e!=null?e:null,this.positions=[],this.counters=[],t.length&&t[0]instanceof w.Vector3)for(let s=0;s<t.length;s++){const i=t[s],r=s/(t.length-1);this.positions.push(i.x,i.y,i.z),this.positions.push(i.x,i.y,i.z),this.counters.push(r),this.counters.push(r)}else for(let s=0;s<t.length;s+=3){const i=s/(t.length-1);this.positions.push(t[s],t[s+1],t[s+2]),this.positions.push(t[s],t[s+1],t[s+2]),this.counters.push(i),this.counters.push(i)}this.process()}compareV3(t,e){const s=t*6,i=e*6;return this.positions[s]===this.positions[i]&&this.positions[s+1]===this.positions[i+1]&&this.positions[s+2]===this.positions[i+2]}copyV3(t){const e=t*6;return[this.positions[e],this.positions[e+1],this.positions[e+2]]}process(){const t=this.positions.length/6;this.previous=[],this.next=[],this.side=[],this.width=[],this.indices_array=[],this.uvs=[];let e,s;this.compareV3(0,t-1)?s=this.copyV3(t-2):s=this.copyV3(0),this.previous.push(s[0],s[1],s[2]),this.previous.push(s[0],s[1],s[2]);for(let i=0;i<t;i++){if(this.side.push(1),this.side.push(-1),this.widthCallback?e=this.widthCallback(i/(t-1)):e=1,this.width.push(e),this.width.push(e),this.uvs.push(i/(t-1),0),this.uvs.push(i/(t-1),1),i<t-1){s=this.copyV3(i),this.previous.push(s[0],s[1],s[2]),this.previous.push(s[0],s[1],s[2]);const r=i*2;this.indices_array.push(r,r+1,r+2),this.indices_array.push(r+2,r+1,r+3)}i>0&&(s=this.copyV3(i),this.next.push(s[0],s[1],s[2]),this.next.push(s[0],s[1],s[2]))}this.compareV3(t-1,0)?s=this.copyV3(1):s=this.copyV3(t-1),this.next.push(s[0],s[1],s[2]),this.next.push(s[0],s[1],s[2]),!this._attributes||this._attributes.position.count!==this.counters.length?this._attributes={position:new w.BufferAttribute(new Float32Array(this.positions),3),previous:new w.BufferAttribute(new Float32Array(this.previous),3),next:new w.BufferAttribute(new Float32Array(this.next),3),side:new w.BufferAttribute(new Float32Array(this.side),1),width:new w.BufferAttribute(new Float32Array(this.width),1),uv:new w.BufferAttribute(new Float32Array(this.uvs),2),index:new w.BufferAttribute(new Uint16Array(this.indices_array),1),counters:new w.BufferAttribute(new Float32Array(this.counters),1)}:(this._attributes.position.copyArray(new Float32Array(this.positions)),this._attributes.position.needsUpdate=!0,this._attributes.previous.copyArray(new Float32Array(this.previous)),this._attributes.previous.needsUpdate=!0,this._attributes.next.copyArray(new Float32Array(this.next)),this._attributes.next.needsUpdate=!0,this._attributes.side.copyArray(new Float32Array(this.side)),this._attributes.side.needsUpdate=!0,this._attributes.width.copyArray(new Float32Array(this.width)),this._attributes.width.needsUpdate=!0,this._attributes.uv.copyArray(new Float32Array(this.uvs)),this._attributes.uv.needsUpdate=!0,this._attributes.index.copyArray(new Uint16Array(this.indices_array)),this._attributes.index.needsUpdate=!0),this.setAttribute("position",this._attributes.position),this.setAttribute("previous",this._attributes.previous),this.setAttribute("next",this._attributes.next),this.setAttribute("side",this._attributes.side),this.setAttribute("width",this._attributes.width),this.setAttribute("uv",this._attributes.uv),this.setAttribute("counters",this._attributes.counters),this.setAttribute("position",this._attributes.position),this.setAttribute("previous",this._attributes.previous),this.setAttribute("next",this._attributes.next),this.setAttribute("side",this._attributes.side),this.setAttribute("width",this._attributes.width),this.setAttribute("uv",this._attributes.uv),this.setAttribute("counters",this._attributes.counters),this.setIndex(this._attributes.index),this.computeBoundingSphere(),this.computeBoundingBox()}advance({x:t,y:e,z:s}){const i=this._attributes.position.array,r=this._attributes.previous.array,n=this._attributes.next.array,a=i.length;pt(i,0,r,0,a),pt(i,6,i,0,a-6),i[a-6]=t,i[a-5]=e,i[a-4]=s,i[a-3]=t,i[a-2]=e,i[a-1]=s,pt(i,6,n,0,a-6),n[a-6]=t,n[a-5]=e,n[a-4]=s,n[a-3]=t,n[a-2]=e,n[a-1]=s,this._attributes.position.needsUpdate=!0,this._attributes.previous.needsUpdate=!0,this._attributes.next.needsUpdate=!0}}function be(o,t){const e=new w.Matrix4,s=new w.Ray,i=new w.Sphere,r=new w.Vector3,n=this.geometry;if(i.copy(n.boundingSphere),i.applyMatrix4(this.matrixWorld),!o.ray.intersectSphere(i,r))return;e.copy(this.matrixWorld).invert(),s.copy(o.ray).applyMatrix4(e);const a=new w.Vector3,c=new w.Vector3,h=new w.Vector3,l=this instanceof w.LineSegments?2:1,d=n.index,f=n.attributes;if(d!==null){const u=d.array,b=f.position.array,p=f.width.array;for(let A=0,S=u.length-1;A<S;A+=l){const P=u[A],V=u[A+1];a.fromArray(b,P*3),c.fromArray(b,V*3);const B=p[Math.floor(A/3)]!=null?p[Math.floor(A/3)]:1,I=o.params.Line.threshold+this.material.lineWidth*B/2,j=I*I;if(s.distanceSqToSegment(a,c,r,h)>j)continue;r.applyMatrix4(this.matrixWorld);const R=o.ray.origin.distanceTo(r);R<o.near||R>o.far||(t.push({distance:R,point:h.clone().applyMatrix4(this.matrixWorld),index:A,face:null,faceIndex:void 0,object:this}),A=S)}}}function K(o,t=0){const e=o[0].index!==null,s=new Set(Object.keys(o[0].attributes)),i=new Set(Object.keys(o[0].morphAttributes)),r={},n={},a=o[0].morphTargetsRelative,c=new _.BufferGeometry;let h=0;for(let l=0;l<o.length;++l){const d=o[l];let f=0;if(e!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const u in d.attributes){if(!s.has(u))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+'. All geometries must have compatible attributes; make sure "'+u+'" attribute exists among all geometries, or in none of them.'),null;r[u]===void 0&&(r[u]=[]),r[u].push(d.attributes[u]),f++}if(f!==s.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const u in d.morphAttributes){if(!i.has(u))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". .morphAttributes must be consistent throughout all geometries."),null;n[u]===void 0&&(n[u]=[]),n[u].push(d.morphAttributes[u])}if(t){let u;if(e)u=d.index.count;else if(d.attributes.position!==void 0)u=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". The geometry must have either an index or a position attribute"),null;if(t===1)c.addGroup(h,u,l);else if(t===2&&d.groups.length>0)for(let b of d.groups){let p=b.materialIndex;c.addGroup(h+b.start,Math.min(b.count,u),p)}h+=u}}if(e){let l=0;const d=[];for(let f=0;f<o.length;++f){const u=o[f].index;for(let b=0;b<u.count;++b)d.push(u.getX(b)+l);l+=o[f].attributes.position.count}c.setIndex(d)}for(const l in r){const d=zt(r[l]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+l+" attribute."),null;c.setAttribute(l,d)}for(const l in n){const d=n[l][0].length;if(d===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[l]=[];for(let f=0;f<d;++f){const u=[];for(let p=0;p<n[l].length;++p)u.push(n[l][p][f]);const b=zt(u);if(!b)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+l+" morphAttribute."),null;c.morphAttributes[l].push(b)}}return t===2?xe(c):c}function zt(o){let t,e,s,i=-1,r=0;for(let h=0;h<o.length;++h){const l=o[h];if(l.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(t===void 0&&(t=l.array.constructor),t!==l.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=l.itemSize),e!==l.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(s===void 0&&(s=l.normalized),s!==l.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(i===-1&&(i=l.gpuType),i!==l.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;r+=l.array.length}const n=new t(r);let a=0;for(let h=0;h<o.length;++h)n.set(o[h].array,a),a+=o[h].array.length;const c=new _.BufferAttribute(n,e,s);return i!==void 0&&(c.gpuType=i),c}function xe(o){if(o.groups.length===0)return console.warn("THREE.BufferGeometryUtils.mergeGroups(): No groups are defined. Nothing to merge."),o;let t=o.groups;if(t=t.sort((n,a)=>n.materialIndex!==a.materialIndex?n.materialIndex-a.materialIndex:n.start-a.start),o.getIndex()===null){const n=o.getAttribute("position"),a=[];for(let c=0;c<n.count;c+=3)a.push(c,c+1,c+2);o.setIndex(a),a.length=0}const e=o.getIndex(),s=[];for(let n=0;n<t.length;n++){const a=t[n],c=a.start,h=c+a.count;for(let l=c;l<h;l++)s.push(e.getX(l))}o.dispose(),o.setIndex(s),s.length=0;let i=0;for(let n=0;n<t.length;n++){const a=t[n];a.start=i,i+=a.count}let r=t[0];o.groups=[r];for(let n=1;n<t.length;n++){const a=t[n];r.materialIndex===a.materialIndex?r.count+=a.count:(r=a,o.groups.push(r))}return o}const mt=o=>{const{setPointWidth:t,nodes:e}=o,s=new $t;return s.setPoints(e,t),s};class we extends X.BaseObject{constructor(t={}){super(),this.options=C({},t)}get material(){var t;return(t=this.object3d)==null?void 0:t.material}create(){return Z(this,null,function*(){const{nodes:t,nodesArr:e,geometry:s,geometryArr:i,material:r,useGroups:n,setPointWidth:a,lineWidthArr:c,useUserDataPos:h,materialParameters:l}=this.options;let d=r,f=s;if(!d&&l&&(d=this.getMaterial(l)),!f&&t?f=mt({nodes:t,setPointWidth:a}):!f&&e?f=K(e.map((u,b)=>{let p=a;return!p&&c&&(p=()=>{var A;return(A=c[b])!=null?A:c[0]}),mt({nodes:u,setPointWidth:p})}),n!=null?n:0):!f&&i&&i.length>1?f=K(i,n!=null?n:0):!f&&i&&i.length===1&&([f]=i),this.createMesh(f,d),h&&(f!=null&&f.userData.position)){const{x:u,y:b,z:p}=f.userData.position;this.object3d.position.set(u,b,p)}})}setGeometry(t,e){const s=mt({nodes:t,setPointWidth:e}),i=this.object3d,r=i.geometry;i.geometry=s,r.dispose()}getMaterial(t){const{width:e,height:s}=this.pencil.getSize();return new xt.MeshLineMaterial(C({color:new w.Color("#ffffff"),resolution:new w.Vector2(e,s)},t))}addGeometries(t){const e=this.object3d,s=K([e.geometry,...t]);e.geometry=s}resize(t,e){var s,i;(i=(s=this.material)==null?void 0:s.uniforms)==null||i.resolution.value.set(t,e)}useMaterial(t){super.useMaterial(t);const{width:e,height:s}=this.pencil.getSize();this.resize(e,s)}animate(t,e){var a,c;const{onComplete:s}=this.options,{offset:i,offsetLoop:r}=this.material.uniforms;if(this.material.userData.tween)return;i.value.x=1,r.value=1;const n=new tt.Tween(i.value).to({x:0},(a=t!=null?t:this.options.duration)!=null?a:1e3).delay((c=e!=null?e:this.options.delay)!=null?c:0).repeat(1/0).onComplete(()=>{s&&s()}).start();this.material.userData.tween=n}animate2({duration:t,delay:e,repeat:s}={}){var c,h;const{onComplete:i}=this.options,{offset:r,offsetLoop:n}=this.material.uniforms;if(this.material.userData.tween)return;r.value.x=1,n.value=0;const a=new tt.Tween(r.value).to({x:-1},(c=t!=null?t:this.options.duration)!=null?c:2e3).delay((h=e!=null?e:this.options.delay)!=null?h:0).repeat(s!=null?s:0).onComplete(()=>{i&&i()}).start();this.material.userData.tween=a}render(){const{width:t,height:e}=this.pencil.getSize();this.resize(t,e)}dispose(t=!0){var e;t&&((e=this.material.userData.tween)==null||e.stop()),super.dispose(t)}}function ve(o,t){return o.map(e=>{const s=[];let i;return e.forEach(r=>{if(i){const n=rt.geoDistance(r,i)*180/Math.PI;if(n>t){const a=rt.geoInterpolate(i,r),c=1/Math.ceil(n/t);let h=c;for(;h<1;)s.push(a(h)),h+=c}}s.push(i=r)}),s})}function Ae(o,{minLng:t,maxLng:e,minLat:s,maxLat:i}={}){const r=Math.round(Ct(360/o,2)/Math.PI),n=(1+Math.sqrt(5))/2,a=u=>u/n*360%360-180,c=u=>Math.acos(2*u/r-1)/Math.PI*180-90,h=u=>r*(Math.cos((u+90)*Math.PI/180)+1)/2,l=[i!==void 0?Math.ceil(h(i)):0,s!==void 0?Math.floor(h(s)):r-1],d=t===void 0&&e===void 0?()=>!0:t===void 0?u=>u<=e:e===void 0?u=>u>=t:e>=t?u=>u>=t&&u<=e:u=>u>=t||u<=e,f=[];for(let u=l[0];u<=l[1];u++){const b=a(u);d(b)&&f.push([b,c(u)])}return f}function bt(o,t,e=!1){return e?rt.geoContains(t,o):le(o,t)}function Se(o,t){const e={type:"Polygon",coordinates:o},[[s,i],[r,n]]=rt.geoBounds(e);if(Math.min(Math.abs(r-s),Math.abs(n-i))<t)return[];const a=s>r||n>=89||i<=-89;return Ae(t,{minLng:s,maxLng:r,minLat:i,maxLat:n}).filter(c=>bt(c,e,a))}function Me(o,{resolution:t=1/0,bbox:e}={}){const s=ve(o,t),i=Y.merge(s),r=Se(o,t),n=[...i,...r],a={type:"Polygon",coordinates:o},[[c,h],[l,d]]=rt.geoBounds(a),f=c>l||d>=89||h<=-89;let u=[];if(f){const P=he.geoVoronoi(n).triangles(),V=new Map(n.map(([B,I],j)=>[`${B}-${I}`,j]));P.features.forEach(B=>{const I=B.geometry.coordinates[0].slice(0,3).reverse(),j=[];if(I.forEach(([G,R])=>{const k=`${G}-${R}`;V.has(k)&&j.push(V.get(k))}),j.length===3){if(j.some(G=>G<i.length)){const G=B.properties.circumcenter;if(!bt(G,a,f))return}u.push(...j)}})}else if(r.length){const P=ce.from(n);for(let V=0,B=P.triangles.length;V<B;V+=3){const I=[2,1,0].map(G=>P.triangles[V+G]),j=I.map(G=>n[G]);if(I.some(G=>G<i.length)){const G=[0,1].map(R=>Y.mean(j,k=>k[R]));if(!bt(G,a,f))continue}u.push(...I)}}else{const{vertices:P,holes:V=[]}=gt.flatten(s);u=gt(P,V,2)}const b=Rt.scaleLinear(e?[e[0],e[2]]:Y.extent(n,P=>P[0]),[0,1]),p=Rt.scaleLinear(e?[e[1],e[3]]:Y.extent(n,P=>P[1]),[0,1]),A=n.map(([P,V])=>[b(P),p(V)]);return{contour:s,triangles:{points:n,indices:u,uvs:A}}}const kt=new w.BufferGeometry().setAttribute?"setAttribute":"addAttribute";function ht(o,t,e,s){const i=o.map(r=>r.map(([n,a])=>{if(s){const[c,h]=s([n,a]);return[c,-h,t]}return e?yt.polar2Cartesian(n,a,t):[n,a,t]}));return gt.flatten(i)}function _e(o,t,e,s,i){const{vertices:r,holes:n}=ht(o,t,s,i),{vertices:a}=ht(o,e,s,i),c=Y.merge([a,r]),h=Math.round(a.length/3),l=new Set(n);let d=0;const f=[];for(let b=0;b<h;b++){let p=b+1;if(p===h)p=d;else if(l.has(p)){const A=p;p=d,d=A}f.push(b,b+h,p+h),f.push(p+h,p,b)}const u=[];for(let b=1;b>=0;b--)for(let p=0;p<h;p+=1)u.push(p/(h-1),b);return{indices:f,vertices:c,uvs:u,topVerts:a}}function Dt(o,t,e,s,i,r){return{indices:s?o.indices:o.indices.slice().reverse(),vertices:ht([o.points],t,i,r).vertices,uvs:e}}const Jt=({polygonGeoJson:o,startHeight:t,endHeight:e,curvatureResolution:s=1,cartesian:i=!0,hasSide:r=!0,hasBottom:n=!1,hasTop:a=!1,projection:c,bbox:h})=>{o.forEach(S=>{ae(S)||S.reverse()});const{contour:l,triangles:d}=Me(o,{resolution:s,bbox:h});let f={},u;r&&(f=_e(l,t!=null?t:e,e!=null?e:t,i,c),u=f.topVerts);let b=[];(n||a)&&(b=Y.merge(d.uvs));let p={};n&&(p=Dt(d,t,b,!1,i,c));let A={};return a&&(A=Dt(d,e,b,!0,i,c)),{contour:l,triangles:d,sideTorso:f,bottomCap:p,topCap:A,topVerts:u}};class Xt extends w.BufferGeometry{constructor(t,e={}){super(),this.type="PolygonBufferGeometry",this.parameters=C({polygonGeoJson:t,startHeight:0,endHeight:1,hasTop:!0,hasBottom:!0,hasSide:!0,curvatureResolution:1,cartesian:!0,userDataRsoOffset:0},e);const{endHeight:s,hasTop:i,hasBottom:r,hasSide:n,cartesian:a,userDataRsoOffset:c,projection:h}=this.parameters,{contour:l,sideTorso:d,topVerts:f,bottomCap:u,topCap:b}=Jt(C({},this.parameters));let p=[],A=[],S=[],P=0;const V=B=>{const I=Math.round(p.length/3),j=S.length;p=p.concat(B.vertices),A=A.concat(B.uvs),S=S.concat(I?B.indices.map(G=>G+I):B.indices),this.addGroup(j,S.length-j,P++)};n&&(V(d),this.userData.topVerts=c?ht(l,s+c,a,h).vertices:f),r&&V(u),i&&V(b),this.setIndex(S),this[kt]("position",new w.Float32BufferAttribute(p,3)),this[kt]("uv",new w.Float32BufferAttribute(A,2)),this.computeVertexNormals()}}const qt=o=>{const a=o,{coordinate:t,startHeight:e,height:s}=a,i=ft(a,["coordinate","startHeight","height"]);let r=e||0;return typeof e!="undefined"&&typeof s!="undefined"&&(r=e+s),new Xt([t],Ot(C({},i),{startHeight:e,endHeight:r}))};class Te extends X.BaseObject{constructor(t){super(),this.options=C({},t)}create(){const c=this.options,{geometry:t,coordinateArr:e,coordinate:s,material:i,useGroups:r}=c,n=ft(c,["geometry","coordinateArr","coordinate","material","useGroups"]);let a=t;if(!a&&s)a=qt(C({coordinate:s},n));else if(!a&&e){const h=e.map(l=>qt(C({coordinate:l},n)));a=K(h,r!=null?r:0)}this.createMesh(a,i)}}class wt extends _.BufferGeometry{constructor(t=new _.Shape([new _.Vector2(.5,.5),new _.Vector2(-.5,.5),new _.Vector2(-.5,-.5),new _.Vector2(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const s=this,i=[],r=[];for(let a=0,c=t.length;a<c;a++){const h=t[a];n(h)}this.setAttribute("position",new _.Float32BufferAttribute(i,3)),this.setAttribute("uv",new _.Float32BufferAttribute(r,2)),this.computeVertexNormals();function n(a){var _t,Tt,Vt;const c=[],h=e.curveSegments!==void 0?e.curveSegments:12,l=e.steps!==void 0?e.steps:1,d=e.depth!==void 0?e.depth:1;let f=e.bevelEnabled!==void 0?e.bevelEnabled:!0,u=e.bevelThickness!==void 0?e.bevelThickness:.2,b=e.bevelSize!==void 0?e.bevelSize:u-.1,p=e.bevelOffset!==void 0?e.bevelOffset:0,A=e.bevelSegments!==void 0?e.bevelSegments:3;const S=e.extrudePath,P=e.UVGenerator!==void 0?e.UVGenerator:Ve,V=(_t=e.hasTop)!=null?_t:!0,B=(Tt=e.hasBottom)!=null?Tt:!0,I=(Vt=e.hasSide)!=null?Vt:!0;let j,G=!1,R,k,et,q;S&&(j=S.getSpacedPoints(l),G=!0,f=!1,R=S.computeFrenetFrames(l,!1),k=new _.Vector3,et=new _.Vector3,q=new _.Vector3),f||(A=0,u=0,b=0,p=0);const vt=a.extractPoints(h);let z=vt.shape;const O=vt.holes;if(!_.ShapeUtils.isClockWise(z)){z=z.reverse();for(let m=0,g=O.length;m<g;m++){const y=O[m];_.ShapeUtils.isClockWise(y)&&(O[m]=y.reverse())}}const st=_.ShapeUtils.triangulateShape(z,O),D=z;for(let m=0,g=O.length;m<g;m++){const y=O[m];z=z.concat(y)}function Q(m,g,y){return g||console.error("THREE.ExtrudeGeometry: vec does not exist"),m.clone().addScaledVector(g,y)}const N=z.length,nt=st.length;function At(m,g,y){let v,x,M;const T=m.x-g.x,E=m.y-g.y,U=y.x-m.x,L=y.y-m.y,it=T*T+E*E,dt=T*L-E*U;if(Math.abs(dt)>Number.EPSILON){const $=Math.sqrt(it),Pt=Math.sqrt(U*U+L*L),Et=g.x-E/$,Bt=g.y+T/$,Yt=y.x-L/Pt,te=y.y+U/Pt,Gt=((Yt-Et)*L-(te-Bt)*U)/(T*L-E*U);v=Et+T*Gt-m.x,x=Bt+E*Gt-m.y;const jt=v*v+x*x;if(jt<=2)return new _.Vector2(v,x);M=Math.sqrt(jt/2)}else{let $=!1;T>Number.EPSILON?U>Number.EPSILON&&($=!0):T<-Number.EPSILON?U<-Number.EPSILON&&($=!0):Math.sign(E)===Math.sign(L)&&($=!0),$?(v=-E,x=T,M=Math.sqrt(it)):(v=T,x=E,M=Math.sqrt(it/2))}return new _.Vector2(v/M,x/M)}const ot=[];for(let m=0,g=D.length,y=g-1,v=m+1;m<g;m++,y++,v++)y===g&&(y=0),v===g&&(v=0),ot[m]=At(D[m],D[y],D[v]);const ut=[];let J,at=ot.concat();for(let m=0,g=O.length;m<g;m++){const y=O[m];J=[];for(let v=0,x=y.length,M=x-1,T=v+1;v<x;v++,M++,T++)M===x&&(M=0),T===x&&(T=0),J[v]=At(y[v],y[M],y[T]);ut.push(J),at=at.concat(J)}for(let m=0;m<A;m++){const g=m/A,y=u*Math.cos(g*Math.PI/2),v=b*Math.sin(g*Math.PI/2)+p;for(let x=0,M=D.length;x<M;x++){const T=Q(D[x],ot[x],v);F(T.x,T.y,-y)}for(let x=0,M=O.length;x<M;x++){const T=O[x];J=ut[x];for(let E=0,U=T.length;E<U;E++){const L=Q(T[E],J[E],v);F(L.x,L.y,-y)}}}const St=b+p;for(let m=0;m<N;m++){const g=f?Q(z[m],at[m],St):z[m];G?(et.copy(R.normals[0]).multiplyScalar(g.x),k.copy(R.binormals[0]).multiplyScalar(g.y),q.copy(j[0]).add(et).add(k),F(q.x,q.y,q.z)):F(g.x,g.y,0)}for(let m=1;m<=l;m++)for(let g=0;g<N;g++){const y=f?Q(z[g],at[g],St):z[g];G?(et.copy(R.normals[m]).multiplyScalar(y.x),k.copy(R.binormals[m]).multiplyScalar(y.y),q.copy(j[m]).add(et).add(k),F(q.x,q.y,q.z)):F(y.x,y.y,d/l*m)}for(let m=A-1;m>=0;m--){const g=m/A,y=u*Math.cos(g*Math.PI/2),v=b*Math.sin(g*Math.PI/2)+p;for(let x=0,M=D.length;x<M;x++){const T=Q(D[x],ot[x],v);F(T.x,T.y,d+y)}for(let x=0,M=O.length;x<M;x++){const T=O[x];J=ut[x];for(let E=0,U=T.length;E<U;E++){const L=Q(T[E],J[E],v);G?F(L.x,L.y+j[l-1].y,j[l-1].x+y):F(L.x,L.y,d+y)}}}Zt(),I&&Kt();function Zt(){const m=i.length/3;if(f){let g=0,y=N*g;if(B)for(let v=0;v<nt;v++){const x=st[v];ct(x[2]+y,x[1]+y,x[0]+y)}if(g=l+A*2,y=N*g,V)for(let v=0;v<nt;v++){const x=st[v];ct(x[0]+y,x[1]+y,x[2]+y)}}else{if(B)for(let g=0;g<nt;g++){const y=st[g];ct(y[2],y[1],y[0])}if(V)for(let g=0;g<nt;g++){const y=st[g];ct(y[0]+N*l,y[1]+N*l,y[2]+N*l)}}s.addGroup(m,i.length/3-m,0)}function Kt(){const m=i.length/3;let g=0;Mt(D,g),g+=D.length;for(let y=0,v=O.length;y<v;y++){const x=O[y];Mt(x,g),g+=x.length}s.addGroup(m,i.length/3-m,1)}function Mt(m,g){let y=m.length;for(;--y>=0;){const v=y;let x=y-1;x<0&&(x=m.length-1);for(let M=0,T=l+A*2;M<T;M++){const E=N*M,U=N*(M+1),L=g+v+E,it=g+x+E,dt=g+x+U,$=g+v+U;Qt(L,it,dt,$)}}}function F(m,g,y){c.push(m),c.push(g),c.push(y)}function ct(m,g,y){H(m),H(g),H(y);const v=i.length/3,x=P.generateTopUV(s,i,v-3,v-2,v-1);W(x[0]),W(x[1]),W(x[2])}function Qt(m,g,y,v){H(m),H(g),H(v),H(g),H(y),H(v);const x=i.length/3,M=P.generateSideWallUV(s,i,x-6,x-3,x-2,x-1);W(M[0]),W(M[1]),W(M[3]),W(M[1]),W(M[2]),W(M[3])}function H(m){i.push(c[m*3+0]),i.push(c[m*3+1]),i.push(c[m*3+2])}function W(m){r.push(m.x),r.push(m.y)}}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON(),e=this.parameters.shapes,s=this.parameters.options;return Pe(e,s,t)}static fromJSON(t,e){const s=[];for(let r=0,n=t.shapes.length;r<n;r++){const a=e[t.shapes[r]];s.push(a)}const i=t.options.extrudePath;return console.log(i.type),i!==void 0&&(t.options.extrudePath=new w[`${i.type}Curve`]().fromJSON(i)),new wt(s,t.options)}}const Ve={generateTopUV:function(o,t,e,s,i){const r=t[e*3],n=t[e*3+1],a=t[s*3],c=t[s*3+1],h=t[i*3],l=t[i*3+1];return[new _.Vector2(r,n),new _.Vector2(a,c),new _.Vector2(h,l)]},generateSideWallUV:function(o,t,e,s,i,r){const n=t[e*3],a=t[e*3+1],c=t[e*3+2],h=t[s*3],l=t[s*3+1],d=t[s*3+2],f=t[i*3],u=t[i*3+1],b=t[i*3+2],p=t[r*3],A=t[r*3+1],S=t[r*3+2];return Math.abs(a-l)<Math.abs(n-h)?[new _.Vector2(n,1-c),new _.Vector2(h,1-d),new _.Vector2(f,1-b),new _.Vector2(p,1-S)]:[new _.Vector2(a,1-c),new _.Vector2(l,1-d),new _.Vector2(u,1-b),new _.Vector2(A,1-S)]}};function Pe(o,t,e){if(e.shapes=[],Array.isArray(o))for(let s=0,i=o.length;s<i;s++){const r=o[s];e.shapes.push(r.uuid)}else e.shapes.push(o.uuid);return e.options=Object.assign({},t),t.extrudePath!==void 0&&(e.options.extrudePath=t.extrudePath.toJSON()),e}const Nt=o=>{const{split:t,depth:e,points:s,box3:i,hasTop:r,hasBottom:n,hasSide:a,sideRepeat:c}=o,h=new wt(new w.Shape(s),{depth:e,bevelEnabled:!1,UVGenerator:yt.getUVGenerator({split:t,box3:i,sideRepeat:c}),hasTop:r,hasBottom:n,hasSide:a});return yt.claerUVGenerator(),h};class Ee extends X.BaseObject{constructor(t){super(),this.options=C({depth:1},t)}create(){return Z(this,null,function*(){const{points:t,pointsArr:e,useGroups:s,depth:i,geometry:r,geometryArr:n,material:a,box3:c,split:h,hasTop:l,hasBottom:d,hasSide:f,useUserDataPos:u}=this.options,b=Array.isArray(i)?i:[i],p=Array.isArray(c)?c:[c],A=a;let S=r;if(A||console.log("material is null"),!S&&t?S=Nt({points:t,depth:b[0],box3:p[0],split:h,hasTop:l,hasBottom:d,hasSide:f}):!S&&e?S=K(e.map((P,V)=>{var B,I;return Nt({points:P,depth:(B=b[V])!=null?B:b[0],box3:(I=p[V])!=null?I:p[0],split:h,hasTop:l,hasBottom:d,hasSide:f})}),s!=null?s:0):!S&&n&&n.length>1?S=K(n,s!=null?s:0):!S&&n&&n.length===1&&([S]=n),this.createMesh(S,A),u&&(S!=null&&S.userData.position)){const{x:P,y:V,z:B}=S.userData.position;this.object3d.position.set(P,V,B)}})}addGeometries(t){const e=this.object3d,s=K([e.geometry,...t]);e.geometry=s}setTextureAnisotropic(t,e){t.anisotropy=e||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const Be=o=>{const{topColor:t,sideColor:e,sideMap:s,createCanvasObjectURL:i,split:r,maxAnisotropy:n}=o;return new Promise(a=>{const c=s?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};c.onload=()=>{const h=r,l=document.createElement("canvas"),d=l.getContext("2d");l.height=c.height/(1-h),l.width=c.width,h&&t&&(d.fillStyle=t,d.fillRect(0,0,c.width,l.height*h)),s&&c instanceof HTMLImageElement?d.drawImage(c,0,l.height*h,c.width,c.height):e&&(d.fillStyle=e,d.fillRect(0,l.height*h,c.width,c.height)),i&&l.toBlob(u=>{console.log(URL.createObjectURL(u))});const f=new w.CanvasTexture(l);a(f)},s?c.src=s:c instanceof HTMLImageElement||c.onload()})};exports.Group=ne.Group;exports.MeshLineMaterial=xt.MeshLineMaterial;exports.meshLineMaterialArr=xt.meshLineMaterialArr;exports.ConicPolygon=Te;exports.ExtrudePolygon=Ee;exports.Image=Wt;exports.Light=ge;exports.Line=we;exports.MeshLineGeometry=$t;exports.MeshLineRaycast=be;exports.Node=pe;exports.Pie=me;exports.Text=de;exports.Video=fe;exports.getConicPolygonGeometry=Xt;exports.getConicPolygonGeometryMetas=Jt;exports.getSplitTexture=Be;
|
|
1
|
+
"use strict";var ee=Object.defineProperty,se=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var lt=Object.getOwnPropertySymbols;var Lt=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable;var Ct=Math.pow,It=(o,t,e)=>t in o?ee(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,C=(o,t)=>{for(var e in t||(t={}))Lt.call(t,e)&&It(o,e,t[e]);if(lt)for(var e of lt(t))Ut.call(t,e)&&It(o,e,t[e]);return o},Ot=(o,t)=>se(o,ie(t));var ft=(o,t)=>{var e={};for(var s in o)Lt.call(o,s)&&t.indexOf(s)<0&&(e[s]=o[s]);if(o!=null&<)for(var s of lt(o))t.indexOf(s)<0&&Ut.call(o,s)&&(e[s]=o[s]);return e};var Z=(o,t,e)=>new Promise((s,i)=>{var r=c=>{try{a(e.next(c))}catch(h){i(h)}},n=c=>{try{a(e.throw(c))}catch(h){i(h)}},a=c=>c.done?s(c.value):Promise.resolve(c.value).then(r,n);a((e=e.apply(o,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("three"),X=require("../BaseObject.js"),re=require("esus-lite"),ne=require("../index2.js"),oe=require("@tweenjs/tween.js"),xt=require("../MeshLineMaterial.js"),Y=require("d3-array"),gt=require("earcut"),ae=require("@turf/boolean-clockwise"),yt=require("../uvGenerator.js"),ce=require("delaunator"),le=require("@turf/boolean-point-in-polygon"),rt=require("d3-geo"),he=require("d3-geo-voronoi"),Rt=require("d3-scale");function Ft(o){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>o[e]})}}return t.default=o,Object.freeze(t)}const v=Ft(_),it=Ft(oe),ue=+v.REVISION<144,Ht=ue?"PlaneBufferGeometry":"PlaneGeometry";class Wt extends X.BaseObject{constructor(t){super(),this.scaleValue=1,this.options=C({scale:1},t)}get material(){var t;return(t=this.object3d)==null?void 0:t.material}getMaterial(){return Z(this,null,function*(){const{src:t,texture:e,transparent:s,opacity:i,blending:r,depthWrite:n,depthTest:a,alphaTest:c,sprite:h,sizeAttenuation:l,color:d}=this.options,f=e||(yield new v.TextureLoader().loadAsync(t));return h?new v.SpriteMaterial({map:f,transparent:s!=null?s:!1,blending:r!=null?r:v.NormalBlending,depthWrite:n!=null?n:!0,depthTest:a!=null?a:!0,alphaTest:c!=null?c:0,opacity:i!=null?i:1,sizeAttenuation:l!=null?l:!0}):new v.MeshBasicMaterial({color:d!=null?d:16777215,map:f,transparent:s!=null?s:!1,blending:r!=null?r:v.NormalBlending,depthWrite:n!=null?n:!0,depthTest:a!=null?a:!0,alphaTest:c!=null?c:0,opacity:i!=null?i:1})})}create(){return Z(this,null,function*(){const{position:t,material:e,sprite:s}=this.options,i=e||(yield this.getMaterial());s?this.createSprite(i):this.createMesh(new v[Ht](1,1),i),t&&this.object3d.position.copy(t)})}render(){const{scale:t}=this.options;this.setScale(t)}setScale(t){this.scaleValue=t;const e=this.material.map;e!=null&&e.image?this.object3d.scale.set(e.image.width*t,e.image.height*t,1):this.object3d.scale.set(t,t,1)}setTexture(t){const e=this.object3d;e.material.map&&e.material.map.dispose(),e.material.map=t,e.material.needsUpdate=!0,this.setScale(this.scaleValue)}}class de extends Wt{constructor(t){super(t),this.canvas=document.createElement("canvas")}getTexture(){const{text:t,textOptions:e}=this.options,{fontSize:s,fontFamily:i,fontWeight:r,flipX:n,color:a,setCtx:c}=C({fontSize:28,fontFamily:"system-ui,-apple-system,BlinkMacSystemFont,sans-serif",fontWeight:"normal",flipX:!1,color:"#ffffff",setCtx:u=>{}},e||{}),{canvas:h}=this;h.width=s*t.length*2,h.height=s;let l=h.getContext("2d");l.font=`${r} ${s}px/1 ${i}`;const{width:d}=l.measureText(t);h.width=d,l=h.getContext("2d"),l.clearRect(0,0,h.width,h.height),n&&l.scale(-1,1),l.font=`${r} ${s}px/1 ${i}`,l.textBaseline="middle",l.fillStyle=a,c&&c(l),l.fillText(t,n?d*-1:0,h.height/2),l.restore();const f=new v.Texture(h);return f.anisotropy=this.pencil.renderer.capabilities.getMaxAnisotropy(),f.needsUpdate=!0,Promise.resolve(f)}}class fe extends X.BaseObject{constructor(t){super(),this.scaleValue=1,this.options=C({scale:1,autoPlay:!0,loop:!0},t)}getMaterial(){const{src:t,transparent:e,blending:s,depthWrite:i,depthTest:r,format:n,autoPlay:a,loop:c,alphaTest:h,sprite:l}=this.options,d=re.makePromiseCreator();if(!t)return Promise.reject("src is required");const f=document.createElement("video");return f.addEventListener("loadedmetadata",()=>{const u=new v.VideoTexture(f);u.format=n!=null?n:v.RGBAFormat,u.needsUpdate=!0;const b=l?new v.SpriteMaterial({map:u,transparent:e!=null?e:!1,blending:s!=null?s:v.NormalBlending,depthWrite:i!=null?i:!0,depthTest:r!=null?r:!0,alphaTest:h!=null?h:0}):new v.MeshBasicMaterial({map:u,transparent:e!=null?e:!1,blending:s!=null?s:v.NormalBlending,depthWrite:i!=null?i:!0,depthTest:r!=null?r:!0,alphaTest:h!=null?h:0});d.resolve(b)},!1),f.src=t,f.muted=!0,f.autoplay=a,f.loop=c,f.preload="auto",d.promise}create(){return Z(this,null,function*(){const{scale:t,position:e,src:s,cache:i,sprite:r}=this.options,n=s&&(i?yield i.get(s,()=>this.getMaterial()):yield this.getMaterial());this.video=n.map.image,r?this.createSprite(n):this.createMesh(new v[Ht](1,1),n),this.setScale(t),e&&this.object3d.position.copy(e)})}setScale(t){this.scaleValue=t,this.object3d.scale.set(this.video.videoWidth*t,this.video.videoHeight*t,1)}render(){const{autoPlay:t}=this.options;t&&this.video.play()}dispose(){this.video.pause(),this.video.src="",super.dispose()}}class pe extends X.BaseObject{constructor(t){super(),this.objectType="BaseObject#Node",this.drawGroupShow=!0,this.visibleCache=!0,this.options=C({event:"click",type:"2d"},t)}get clickTarge(){const{eventTarge:t}=this.options;return t?t.map(s=>[...this.element.querySelectorAll(s)]).flat():[this.element]}create(){const{position:t,children:e,handler:s,event:i}=this.options,r=document.createElement("div");this.element=r,e&&r.appendChild(e),this.options.type==="3d"?this.createCSS3DObject(r):this.options.type==="3dSprite"?this.createCSS3DSprite(r):this.createCSS2DObject(r),t&&this.object3d.position.copy(t),s&&i&&this.clickTarge.forEach(n=>{const a=Array.isArray(i)?i:[i],c=Array.isArray(s)?s:[s];a.forEach((h,l)=>{const d=c[l];d&&n.addEventListener(h,d)})})}setChildren(t){this.element.innerHTML="",this.element.appendChild(t)}render(){this.checkVisible()}show(){return this.visibleCache=!0,this.checkVisible(),this}hide(){return this.visibleCache=!1,this.checkVisible(),this}checkVisible(){this.drawGroupShow&&this.visibleCache?super.show():(!this.drawGroupShow||!this.visibleCache)&&super.hide()}dispose(){const{handler:t,event:e}=this.options;t&&e&&this.clickTarge.forEach(s=>{const i=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t];i.forEach((n,a)=>{const c=r[a];c&&s.removeEventListener(n,c)})}),super.dispose()}}class me extends X.BaseObject{constructor(t){super(),this.options=C({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},t)}create(){return Z(this,null,function*(){this.createGroup();const{data:t,maxDepth:e,colors:s,material:i,percentDepth:r,activeIndex:n}=this.options,a=Math.max(...t),c=t.reduce((l,d)=>l+d,0);let h=Math.PI/2;t.forEach((l,d)=>{if(l===0)return;const f=Math.PI*2*(l/c),u=s[d],b=r?e*(l/a):e,p=this.createGeometry(b,f),A=i?i.clone():new v.MeshBasicMaterial({color:u});i&&A.color.set(u);const S=new v.Mesh(p,A);S.userData.depth=b,S.userData.index=d,S.rotateZ(h),h+=f,this.add(S)}),n!==-1&&this.setActive(n)})}createGeometry(t,e){const{outRadius:s,innerRadius:i}=this.options,r=new v.Shape;return r.moveTo(s,0),r.lineTo(i,0),r.absarc(0,0,i,0,e,!1),r.absarc(0,0,s,e,0,!0),new v.ExtrudeGeometry(r,{curveSegments:48,depth:t,bevelEnabled:!1})}handlePick(t,e=1.3){const{object:s}=this.pencil.pick(t,this.object3d.children)||{},i=s?this.object3d.children.findIndex(r=>r===s):this.options.activeIndex;return this.setActive(i,e)}setActive(t,e=1.3){const s=this.object3d.children[t];if(this.object3d.children.forEach(i=>{if(!(s&&s===i)&&i.scale.z!==1){if(i.userData.levTween)return;i.userData.enTween&&(i.userData.enTween.stop(),i.userData.enTween=null);const r=new it.Tween(i.scale).to({z:1},100);i.userData.levTween=r,r.start()}}),s){if(s.userData.enTween)return;s.userData.levTween&&(s.userData.levTween.stop(),s.userData.levTween=null);const i=new it.Tween(s.scale).to({z:e},100);return s.userData.enTween=i,i.start(),s.userData.index}return-1}render(){this.object3d.scale.z=0,new it.Tween(this.object3d.scale).to({z:1},1e3).easing(it.Easing.Sinusoidal.InOut).start()}}class ge extends X.BaseObject{constructor(t){super(),this.options=t}create(){var e,s,i,r,n,a,c,h,l,d,f,u,b;const t=this.options;if(t.type==="AmbientLight"){const p=new v.AmbientLight(t.color);p.name="AmbientLight",this.object3d=p}else if(t.type==="DirectionalLight"){const p=new v.DirectionalLight(t.color,t.intensity);p.name="DirectionalLight",p.target.position.set(0,0,0),this.object3d=p,this.pencil.scene.add(p.target),this.directionalLight=p}else if(t.type==="PointLight"){const p=new v.PointLight((e=t.color)!=null?e:16777215,(s=t.intensity)!=null?s:1,(i=t.distance)!=null?i:0,(r=t.decay)!=null?r:2);p.name="PointLight",this.object3d=p,this.pointLight=p}else if(t.type==="SpotLight"){const p=new v.SpotLight((n=t.color)!=null?n:16777215,(a=t.intensity)!=null?a:1,(c=t.distance)!=null?c:0,(h=t.angle)!=null?h:Math.PI/3,(l=t.penumbra)!=null?l:1,(d=t.decay)!=null?d:2);p.name="SpotLight",this.object3d=p,this.spotLight=p,this.pencil.scene.add(p.target)}else if(t.type==="HemisphereLight"){const p=new v.HemisphereLight((f=t.color)!=null?f:16777215,(u=t.groundColor)!=null?u:16777215,(b=t.intensity)!=null?b:1);p.name="HemisphereLight",this.object3d=p,this.hemisphereLight=p}}render(){const t=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const e=this.spotLight||this.directionalLight;e.position.copy(t),e.target.position.copy(t)}else this.pointLight&&this.pointLight.position.copy(t)}dispose(){const t=this.object3d;t.target&&this.pencil.scene.remove(t.target),super.dispose()}}function pt(o,t,e,s,i){let r;if(o=o.subarray||o.slice?o:o.buffer,e=e.subarray||e.slice?e:e.buffer,o=t?o.subarray?o.subarray(t,i&&t+i):o.slice(t,i&&t+i):o,e.set)e.set(o,s);else for(r=0;r<o.length;r++)e[r+s]=o[r];return e}function ye(o){return o instanceof Float32Array?o:o instanceof v.BufferGeometry?o.getAttribute("position").array:o.map(t=>{const e=Array.isArray(t);return t instanceof v.Vector3?[t.x,t.y,t.z]:t instanceof v.Vector2?[t.x,t.y,0]:e&&t.length===3?[t[0],t[1],t[2]]:e&&t.length===2?[t[0],t[1],0]:t}).flat()}class $t extends v.BufferGeometry{constructor(){super(),this.type="MeshLine",this.isMeshLine=!0,this.positions=[],this.previous=[],this.next=[],this.side=[],this.width=[],this.indices_array=[],this.uvs=[],this.counters=[],this.widthCallback=null,this._points=[],this.matrixWorld=new v.Matrix4,Object.defineProperties(this,{points:{enumerable:!0,get(){return this._points},set(t){this.setPoints(t,this.widthCallback)}}})}setMatrixWorld(t){this.matrixWorld=t}setPoints(t,e){if(t=ye(t),this._points=t,this.widthCallback=e!=null?e:null,this.positions=[],this.counters=[],t.length&&t[0]instanceof v.Vector3)for(let s=0;s<t.length;s++){const i=t[s],r=s/(t.length-1);this.positions.push(i.x,i.y,i.z),this.positions.push(i.x,i.y,i.z),this.counters.push(r),this.counters.push(r)}else for(let s=0;s<t.length;s+=3){const i=s/(t.length-1);this.positions.push(t[s],t[s+1],t[s+2]),this.positions.push(t[s],t[s+1],t[s+2]),this.counters.push(i),this.counters.push(i)}this.process()}compareV3(t,e){const s=t*6,i=e*6;return this.positions[s]===this.positions[i]&&this.positions[s+1]===this.positions[i+1]&&this.positions[s+2]===this.positions[i+2]}copyV3(t){const e=t*6;return[this.positions[e],this.positions[e+1],this.positions[e+2]]}process(){const t=this.positions.length/6;this.previous=[],this.next=[],this.side=[],this.width=[],this.indices_array=[],this.uvs=[];let e,s;this.compareV3(0,t-1)?s=this.copyV3(t-2):s=this.copyV3(0),this.previous.push(s[0],s[1],s[2]),this.previous.push(s[0],s[1],s[2]);for(let i=0;i<t;i++){if(this.side.push(1),this.side.push(-1),this.widthCallback?e=this.widthCallback(i/(t-1)):e=1,this.width.push(e),this.width.push(e),this.uvs.push(i/(t-1),0),this.uvs.push(i/(t-1),1),i<t-1){s=this.copyV3(i),this.previous.push(s[0],s[1],s[2]),this.previous.push(s[0],s[1],s[2]);const r=i*2;this.indices_array.push(r,r+1,r+2),this.indices_array.push(r+2,r+1,r+3)}i>0&&(s=this.copyV3(i),this.next.push(s[0],s[1],s[2]),this.next.push(s[0],s[1],s[2]))}this.compareV3(t-1,0)?s=this.copyV3(1):s=this.copyV3(t-1),this.next.push(s[0],s[1],s[2]),this.next.push(s[0],s[1],s[2]),!this._attributes||this._attributes.position.count!==this.counters.length?this._attributes={position:new v.BufferAttribute(new Float32Array(this.positions),3),previous:new v.BufferAttribute(new Float32Array(this.previous),3),next:new v.BufferAttribute(new Float32Array(this.next),3),side:new v.BufferAttribute(new Float32Array(this.side),1),width:new v.BufferAttribute(new Float32Array(this.width),1),uv:new v.BufferAttribute(new Float32Array(this.uvs),2),index:new v.BufferAttribute(new Uint16Array(this.indices_array),1),counters:new v.BufferAttribute(new Float32Array(this.counters),1)}:(this._attributes.position.copyArray(new Float32Array(this.positions)),this._attributes.position.needsUpdate=!0,this._attributes.previous.copyArray(new Float32Array(this.previous)),this._attributes.previous.needsUpdate=!0,this._attributes.next.copyArray(new Float32Array(this.next)),this._attributes.next.needsUpdate=!0,this._attributes.side.copyArray(new Float32Array(this.side)),this._attributes.side.needsUpdate=!0,this._attributes.width.copyArray(new Float32Array(this.width)),this._attributes.width.needsUpdate=!0,this._attributes.uv.copyArray(new Float32Array(this.uvs)),this._attributes.uv.needsUpdate=!0,this._attributes.index.copyArray(new Uint16Array(this.indices_array)),this._attributes.index.needsUpdate=!0),this.setAttribute("position",this._attributes.position),this.setAttribute("previous",this._attributes.previous),this.setAttribute("next",this._attributes.next),this.setAttribute("side",this._attributes.side),this.setAttribute("width",this._attributes.width),this.setAttribute("uv",this._attributes.uv),this.setAttribute("counters",this._attributes.counters),this.setAttribute("position",this._attributes.position),this.setAttribute("previous",this._attributes.previous),this.setAttribute("next",this._attributes.next),this.setAttribute("side",this._attributes.side),this.setAttribute("width",this._attributes.width),this.setAttribute("uv",this._attributes.uv),this.setAttribute("counters",this._attributes.counters),this.setIndex(this._attributes.index),this.computeBoundingSphere(),this.computeBoundingBox()}advance({x:t,y:e,z:s}){const i=this._attributes.position.array,r=this._attributes.previous.array,n=this._attributes.next.array,a=i.length;pt(i,0,r,0,a),pt(i,6,i,0,a-6),i[a-6]=t,i[a-5]=e,i[a-4]=s,i[a-3]=t,i[a-2]=e,i[a-1]=s,pt(i,6,n,0,a-6),n[a-6]=t,n[a-5]=e,n[a-4]=s,n[a-3]=t,n[a-2]=e,n[a-1]=s,this._attributes.position.needsUpdate=!0,this._attributes.previous.needsUpdate=!0,this._attributes.next.needsUpdate=!0}}function be(o,t){const e=new v.Matrix4,s=new v.Ray,i=new v.Sphere,r=new v.Vector3,n=this.geometry;if(i.copy(n.boundingSphere),i.applyMatrix4(this.matrixWorld),!o.ray.intersectSphere(i,r))return;e.copy(this.matrixWorld).invert(),s.copy(o.ray).applyMatrix4(e);const a=new v.Vector3,c=new v.Vector3,h=new v.Vector3,l=this instanceof v.LineSegments?2:1,d=n.index,f=n.attributes;if(d!==null){const u=d.array,b=f.position.array,p=f.width.array;for(let A=0,S=u.length-1;A<S;A+=l){const P=u[A],V=u[A+1];a.fromArray(b,P*3),c.fromArray(b,V*3);const B=p[Math.floor(A/3)]!=null?p[Math.floor(A/3)]:1,I=o.params.Line.threshold+this.material.lineWidth*B/2,j=I*I;if(s.distanceSqToSegment(a,c,r,h)>j)continue;r.applyMatrix4(this.matrixWorld);const R=o.ray.origin.distanceTo(r);R<o.near||R>o.far||(t.push({distance:R,point:h.clone().applyMatrix4(this.matrixWorld),index:A,face:null,faceIndex:void 0,object:this}),A=S)}}}function K(o,t=0){const e=o[0].index!==null,s=new Set(Object.keys(o[0].attributes)),i=new Set(Object.keys(o[0].morphAttributes)),r={},n={},a=o[0].morphTargetsRelative,c=new _.BufferGeometry;let h=0;for(let l=0;l<o.length;++l){const d=o[l];let f=0;if(e!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const u in d.attributes){if(!s.has(u))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+'. All geometries must have compatible attributes; make sure "'+u+'" attribute exists among all geometries, or in none of them.'),null;r[u]===void 0&&(r[u]=[]),r[u].push(d.attributes[u]),f++}if(f!==s.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const u in d.morphAttributes){if(!i.has(u))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". .morphAttributes must be consistent throughout all geometries."),null;n[u]===void 0&&(n[u]=[]),n[u].push(d.morphAttributes[u])}if(t){let u;if(e)u=d.index.count;else if(d.attributes.position!==void 0)u=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+l+". The geometry must have either an index or a position attribute"),null;if(t===1)c.addGroup(h,u,l);else if(t===2&&d.groups.length>0)for(let b of d.groups){let p=b.materialIndex;c.addGroup(h+b.start,Math.min(b.count,u),p)}h+=u}}if(e){let l=0;const d=[];for(let f=0;f<o.length;++f){const u=o[f].index;for(let b=0;b<u.count;++b)d.push(u.getX(b)+l);l+=o[f].attributes.position.count}c.setIndex(d)}for(const l in r){const d=zt(r[l]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+l+" attribute."),null;c.setAttribute(l,d)}for(const l in n){const d=n[l][0].length;if(d===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[l]=[];for(let f=0;f<d;++f){const u=[];for(let p=0;p<n[l].length;++p)u.push(n[l][p][f]);const b=zt(u);if(!b)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+l+" morphAttribute."),null;c.morphAttributes[l].push(b)}}return t===2?xe(c):c}function zt(o){let t,e,s,i=-1,r=0;for(let h=0;h<o.length;++h){const l=o[h];if(l.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(t===void 0&&(t=l.array.constructor),t!==l.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=l.itemSize),e!==l.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(s===void 0&&(s=l.normalized),s!==l.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(i===-1&&(i=l.gpuType),i!==l.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;r+=l.array.length}const n=new t(r);let a=0;for(let h=0;h<o.length;++h)n.set(o[h].array,a),a+=o[h].array.length;const c=new _.BufferAttribute(n,e,s);return i!==void 0&&(c.gpuType=i),c}function xe(o){if(o.groups.length===0)return console.warn("THREE.BufferGeometryUtils.mergeGroups(): No groups are defined. Nothing to merge."),o;let t=o.groups;if(t=t.sort((n,a)=>n.materialIndex!==a.materialIndex?n.materialIndex-a.materialIndex:n.start-a.start),o.getIndex()===null){const n=o.getAttribute("position"),a=[];for(let c=0;c<n.count;c+=3)a.push(c,c+1,c+2);o.setIndex(a),a.length=0}const e=o.getIndex(),s=[];for(let n=0;n<t.length;n++){const a=t[n],c=a.start,h=c+a.count;for(let l=c;l<h;l++)s.push(e.getX(l))}o.dispose(),o.setIndex(s),s.length=0;let i=0;for(let n=0;n<t.length;n++){const a=t[n];a.start=i,i+=a.count}let r=t[0];o.groups=[r];for(let n=1;n<t.length;n++){const a=t[n];r.materialIndex===a.materialIndex?r.count+=a.count:(r=a,o.groups.push(r))}return o}const mt=o=>{const{setPointWidth:t,nodes:e}=o,s=new $t;return s.setPoints(e,t),s};class ve extends X.BaseObject{constructor(t={}){super(),this.options=C({delay:0,duration:1e3},t)}get material(){var t;return(t=this.object3d)==null?void 0:t.material}create(){return Z(this,null,function*(){const{nodes:t,nodesArr:e,geometry:s,geometryArr:i,material:r,useGroups:n,setPointWidth:a,lineWidthArr:c,useUserDataPos:h,materialParameters:l}=this.options;let d=r,f=s;if(!d&&l&&(d=this.getMaterial(l)),!f&&t?f=mt({nodes:t,setPointWidth:a}):!f&&e?f=K(e.map((u,b)=>{let p=a;return!p&&c&&(p=()=>{var A;return(A=c[b])!=null?A:c[0]}),mt({nodes:u,setPointWidth:p})}),n!=null?n:0):!f&&i&&i.length>1?f=K(i,n!=null?n:0):!f&&i&&i.length===1&&([f]=i),this.createMesh(f,d),h&&(f!=null&&f.userData.position)){const{x:u,y:b,z:p}=f.userData.position;this.object3d.position.set(u,b,p)}})}setGeometry(t,e){const s=mt({nodes:t,setPointWidth:e}),i=this.object3d,r=i.geometry;i.geometry=s,r.dispose()}getMaterial(t){const{width:e,height:s}=this.pencil.getSize();return new xt.MeshLineMaterial(C({color:new v.Color("#ffffff"),resolution:new v.Vector2(e,s)},t))}addGeometries(t){const e=this.object3d,s=K([e.geometry,...t]);e.geometry=s}resize(t,e){var s,i;(i=(s=this.material)==null?void 0:s.uniforms)==null||i.resolution.value.set(t,e)}useMaterial(t){super.useMaterial(t);const{width:e,height:s}=this.pencil.getSize();this.resize(e,s)}animate({duration:t,delay:e,repeat:s,lineLoop:i}={}){const{onComplete:r}=this.options,{offset:n,offsetLoop:a}=this.material.uniforms;if(this.material.userData.tween)return;const c=i!=null?i:!0;n.value.x=1,a.value=0;const h=new it.Tween(n.value).to({x:-1},t!=null?t:this.options.duration).delay(e!=null?e:this.options.delay).repeat(s!=null?s:0).onUpdate(({x:l})=>{c&&l<=0&&a.value===0&&(a.value=1)}).onComplete(()=>{r&&r()}).start();this.material.userData.tween=h}render(){const{width:t,height:e}=this.pencil.getSize();this.resize(t,e)}dispose(t=!0){var e;t&&((e=this.material.userData.tween)==null||e.stop()),super.dispose(t)}}function we(o,t){return o.map(e=>{const s=[];let i;return e.forEach(r=>{if(i){const n=rt.geoDistance(r,i)*180/Math.PI;if(n>t){const a=rt.geoInterpolate(i,r),c=1/Math.ceil(n/t);let h=c;for(;h<1;)s.push(a(h)),h+=c}}s.push(i=r)}),s})}function Ae(o,{minLng:t,maxLng:e,minLat:s,maxLat:i}={}){const r=Math.round(Ct(360/o,2)/Math.PI),n=(1+Math.sqrt(5))/2,a=u=>u/n*360%360-180,c=u=>Math.acos(2*u/r-1)/Math.PI*180-90,h=u=>r*(Math.cos((u+90)*Math.PI/180)+1)/2,l=[i!==void 0?Math.ceil(h(i)):0,s!==void 0?Math.floor(h(s)):r-1],d=t===void 0&&e===void 0?()=>!0:t===void 0?u=>u<=e:e===void 0?u=>u>=t:e>=t?u=>u>=t&&u<=e:u=>u>=t||u<=e,f=[];for(let u=l[0];u<=l[1];u++){const b=a(u);d(b)&&f.push([b,c(u)])}return f}function bt(o,t,e=!1){return e?rt.geoContains(t,o):le(o,t)}function Se(o,t){const e={type:"Polygon",coordinates:o},[[s,i],[r,n]]=rt.geoBounds(e);if(Math.min(Math.abs(r-s),Math.abs(n-i))<t)return[];const a=s>r||n>=89||i<=-89;return Ae(t,{minLng:s,maxLng:r,minLat:i,maxLat:n}).filter(c=>bt(c,e,a))}function Me(o,{resolution:t=1/0,bbox:e}={}){const s=we(o,t),i=Y.merge(s),r=Se(o,t),n=[...i,...r],a={type:"Polygon",coordinates:o},[[c,h],[l,d]]=rt.geoBounds(a),f=c>l||d>=89||h<=-89;let u=[];if(f){const P=he.geoVoronoi(n).triangles(),V=new Map(n.map(([B,I],j)=>[`${B}-${I}`,j]));P.features.forEach(B=>{const I=B.geometry.coordinates[0].slice(0,3).reverse(),j=[];if(I.forEach(([G,R])=>{const k=`${G}-${R}`;V.has(k)&&j.push(V.get(k))}),j.length===3){if(j.some(G=>G<i.length)){const G=B.properties.circumcenter;if(!bt(G,a,f))return}u.push(...j)}})}else if(r.length){const P=ce.from(n);for(let V=0,B=P.triangles.length;V<B;V+=3){const I=[2,1,0].map(G=>P.triangles[V+G]),j=I.map(G=>n[G]);if(I.some(G=>G<i.length)){const G=[0,1].map(R=>Y.mean(j,k=>k[R]));if(!bt(G,a,f))continue}u.push(...I)}}else{const{vertices:P,holes:V=[]}=gt.flatten(s);u=gt(P,V,2)}const b=Rt.scaleLinear(e?[e[0],e[2]]:Y.extent(n,P=>P[0]),[0,1]),p=Rt.scaleLinear(e?[e[1],e[3]]:Y.extent(n,P=>P[1]),[0,1]),A=n.map(([P,V])=>[b(P),p(V)]);return{contour:s,triangles:{points:n,indices:u,uvs:A}}}const kt=new v.BufferGeometry().setAttribute?"setAttribute":"addAttribute";function ht(o,t,e,s){const i=o.map(r=>r.map(([n,a])=>{if(s){const[c,h]=s([n,a]);return[c,-h,t]}return e?yt.polar2Cartesian(n,a,t):[n,a,t]}));return gt.flatten(i)}function _e(o,t,e,s,i){const{vertices:r,holes:n}=ht(o,t,s,i),{vertices:a}=ht(o,e,s,i),c=Y.merge([a,r]),h=Math.round(a.length/3),l=new Set(n);let d=0;const f=[];for(let b=0;b<h;b++){let p=b+1;if(p===h)p=d;else if(l.has(p)){const A=p;p=d,d=A}f.push(b,b+h,p+h),f.push(p+h,p,b)}const u=[];for(let b=1;b>=0;b--)for(let p=0;p<h;p+=1)u.push(p/(h-1),b);return{indices:f,vertices:c,uvs:u,topVerts:a}}function Dt(o,t,e,s,i,r){return{indices:s?o.indices:o.indices.slice().reverse(),vertices:ht([o.points],t,i,r).vertices,uvs:e}}const Jt=({polygonGeoJson:o,startHeight:t,endHeight:e,curvatureResolution:s=1,cartesian:i=!0,hasSide:r=!0,hasBottom:n=!1,hasTop:a=!1,projection:c,bbox:h})=>{o.forEach(S=>{ae(S)||S.reverse()});const{contour:l,triangles:d}=Me(o,{resolution:s,bbox:h});let f={},u;r&&(f=_e(l,t!=null?t:e,e!=null?e:t,i,c),u=f.topVerts);let b=[];(n||a)&&(b=Y.merge(d.uvs));let p={};n&&(p=Dt(d,t,b,!1,i,c));let A={};return a&&(A=Dt(d,e,b,!0,i,c)),{contour:l,triangles:d,sideTorso:f,bottomCap:p,topCap:A,topVerts:u}};class Xt extends v.BufferGeometry{constructor(t,e={}){super(),this.type="PolygonBufferGeometry",this.parameters=C({polygonGeoJson:t,startHeight:0,endHeight:1,hasTop:!0,hasBottom:!0,hasSide:!0,curvatureResolution:1,cartesian:!0,userDataRsoOffset:0},e);const{endHeight:s,hasTop:i,hasBottom:r,hasSide:n,cartesian:a,userDataRsoOffset:c,projection:h}=this.parameters,{contour:l,sideTorso:d,topVerts:f,bottomCap:u,topCap:b}=Jt(C({},this.parameters));let p=[],A=[],S=[],P=0;const V=B=>{const I=Math.round(p.length/3),j=S.length;p=p.concat(B.vertices),A=A.concat(B.uvs),S=S.concat(I?B.indices.map(G=>G+I):B.indices),this.addGroup(j,S.length-j,P++)};n&&(V(d),this.userData.topVerts=c?ht(l,s+c,a,h).vertices:f),r&&V(u),i&&V(b),this.setIndex(S),this[kt]("position",new v.Float32BufferAttribute(p,3)),this[kt]("uv",new v.Float32BufferAttribute(A,2)),this.computeVertexNormals()}}const qt=o=>{const a=o,{coordinate:t,startHeight:e,height:s}=a,i=ft(a,["coordinate","startHeight","height"]);let r=e||0;return typeof e!="undefined"&&typeof s!="undefined"&&(r=e+s),new Xt([t],Ot(C({},i),{startHeight:e,endHeight:r}))};class Te extends X.BaseObject{constructor(t){super(),this.options=C({},t)}create(){const c=this.options,{geometry:t,coordinateArr:e,coordinate:s,material:i,useGroups:r}=c,n=ft(c,["geometry","coordinateArr","coordinate","material","useGroups"]);let a=t;if(!a&&s)a=qt(C({coordinate:s},n));else if(!a&&e){const h=e.map(l=>qt(C({coordinate:l},n)));a=K(h,r!=null?r:0)}this.createMesh(a,i)}}class vt extends _.BufferGeometry{constructor(t=new _.Shape([new _.Vector2(.5,.5),new _.Vector2(-.5,.5),new _.Vector2(-.5,-.5),new _.Vector2(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const s=this,i=[],r=[];for(let a=0,c=t.length;a<c;a++){const h=t[a];n(h)}this.setAttribute("position",new _.Float32BufferAttribute(i,3)),this.setAttribute("uv",new _.Float32BufferAttribute(r,2)),this.computeVertexNormals();function n(a){var _t,Tt,Vt;const c=[],h=e.curveSegments!==void 0?e.curveSegments:12,l=e.steps!==void 0?e.steps:1,d=e.depth!==void 0?e.depth:1;let f=e.bevelEnabled!==void 0?e.bevelEnabled:!0,u=e.bevelThickness!==void 0?e.bevelThickness:.2,b=e.bevelSize!==void 0?e.bevelSize:u-.1,p=e.bevelOffset!==void 0?e.bevelOffset:0,A=e.bevelSegments!==void 0?e.bevelSegments:3;const S=e.extrudePath,P=e.UVGenerator!==void 0?e.UVGenerator:Ve,V=(_t=e.hasTop)!=null?_t:!0,B=(Tt=e.hasBottom)!=null?Tt:!0,I=(Vt=e.hasSide)!=null?Vt:!0;let j,G=!1,R,k,tt,q;S&&(j=S.getSpacedPoints(l),G=!0,f=!1,R=S.computeFrenetFrames(l,!1),k=new _.Vector3,tt=new _.Vector3,q=new _.Vector3),f||(A=0,u=0,b=0,p=0);const wt=a.extractPoints(h);let z=wt.shape;const O=wt.holes;if(!_.ShapeUtils.isClockWise(z)){z=z.reverse();for(let m=0,g=O.length;m<g;m++){const y=O[m];_.ShapeUtils.isClockWise(y)&&(O[m]=y.reverse())}}const et=_.ShapeUtils.triangulateShape(z,O),D=z;for(let m=0,g=O.length;m<g;m++){const y=O[m];z=z.concat(y)}function Q(m,g,y){return g||console.error("THREE.ExtrudeGeometry: vec does not exist"),m.clone().addScaledVector(g,y)}const N=z.length,nt=et.length;function At(m,g,y){let w,x,M;const T=m.x-g.x,E=m.y-g.y,U=y.x-m.x,L=y.y-m.y,st=T*T+E*E,dt=T*L-E*U;if(Math.abs(dt)>Number.EPSILON){const $=Math.sqrt(st),Pt=Math.sqrt(U*U+L*L),Et=g.x-E/$,Bt=g.y+T/$,Yt=y.x-L/Pt,te=y.y+U/Pt,Gt=((Yt-Et)*L-(te-Bt)*U)/(T*L-E*U);w=Et+T*Gt-m.x,x=Bt+E*Gt-m.y;const jt=w*w+x*x;if(jt<=2)return new _.Vector2(w,x);M=Math.sqrt(jt/2)}else{let $=!1;T>Number.EPSILON?U>Number.EPSILON&&($=!0):T<-Number.EPSILON?U<-Number.EPSILON&&($=!0):Math.sign(E)===Math.sign(L)&&($=!0),$?(w=-E,x=T,M=Math.sqrt(st)):(w=T,x=E,M=Math.sqrt(st/2))}return new _.Vector2(w/M,x/M)}const ot=[];for(let m=0,g=D.length,y=g-1,w=m+1;m<g;m++,y++,w++)y===g&&(y=0),w===g&&(w=0),ot[m]=At(D[m],D[y],D[w]);const ut=[];let J,at=ot.concat();for(let m=0,g=O.length;m<g;m++){const y=O[m];J=[];for(let w=0,x=y.length,M=x-1,T=w+1;w<x;w++,M++,T++)M===x&&(M=0),T===x&&(T=0),J[w]=At(y[w],y[M],y[T]);ut.push(J),at=at.concat(J)}for(let m=0;m<A;m++){const g=m/A,y=u*Math.cos(g*Math.PI/2),w=b*Math.sin(g*Math.PI/2)+p;for(let x=0,M=D.length;x<M;x++){const T=Q(D[x],ot[x],w);F(T.x,T.y,-y)}for(let x=0,M=O.length;x<M;x++){const T=O[x];J=ut[x];for(let E=0,U=T.length;E<U;E++){const L=Q(T[E],J[E],w);F(L.x,L.y,-y)}}}const St=b+p;for(let m=0;m<N;m++){const g=f?Q(z[m],at[m],St):z[m];G?(tt.copy(R.normals[0]).multiplyScalar(g.x),k.copy(R.binormals[0]).multiplyScalar(g.y),q.copy(j[0]).add(tt).add(k),F(q.x,q.y,q.z)):F(g.x,g.y,0)}for(let m=1;m<=l;m++)for(let g=0;g<N;g++){const y=f?Q(z[g],at[g],St):z[g];G?(tt.copy(R.normals[m]).multiplyScalar(y.x),k.copy(R.binormals[m]).multiplyScalar(y.y),q.copy(j[m]).add(tt).add(k),F(q.x,q.y,q.z)):F(y.x,y.y,d/l*m)}for(let m=A-1;m>=0;m--){const g=m/A,y=u*Math.cos(g*Math.PI/2),w=b*Math.sin(g*Math.PI/2)+p;for(let x=0,M=D.length;x<M;x++){const T=Q(D[x],ot[x],w);F(T.x,T.y,d+y)}for(let x=0,M=O.length;x<M;x++){const T=O[x];J=ut[x];for(let E=0,U=T.length;E<U;E++){const L=Q(T[E],J[E],w);G?F(L.x,L.y+j[l-1].y,j[l-1].x+y):F(L.x,L.y,d+y)}}}Zt(),I&&Kt();function Zt(){const m=i.length/3;if(f){let g=0,y=N*g;if(B)for(let w=0;w<nt;w++){const x=et[w];ct(x[2]+y,x[1]+y,x[0]+y)}if(g=l+A*2,y=N*g,V)for(let w=0;w<nt;w++){const x=et[w];ct(x[0]+y,x[1]+y,x[2]+y)}}else{if(B)for(let g=0;g<nt;g++){const y=et[g];ct(y[2],y[1],y[0])}if(V)for(let g=0;g<nt;g++){const y=et[g];ct(y[0]+N*l,y[1]+N*l,y[2]+N*l)}}s.addGroup(m,i.length/3-m,0)}function Kt(){const m=i.length/3;let g=0;Mt(D,g),g+=D.length;for(let y=0,w=O.length;y<w;y++){const x=O[y];Mt(x,g),g+=x.length}s.addGroup(m,i.length/3-m,1)}function Mt(m,g){let y=m.length;for(;--y>=0;){const w=y;let x=y-1;x<0&&(x=m.length-1);for(let M=0,T=l+A*2;M<T;M++){const E=N*M,U=N*(M+1),L=g+w+E,st=g+x+E,dt=g+x+U,$=g+w+U;Qt(L,st,dt,$)}}}function F(m,g,y){c.push(m),c.push(g),c.push(y)}function ct(m,g,y){H(m),H(g),H(y);const w=i.length/3,x=P.generateTopUV(s,i,w-3,w-2,w-1);W(x[0]),W(x[1]),W(x[2])}function Qt(m,g,y,w){H(m),H(g),H(w),H(g),H(y),H(w);const x=i.length/3,M=P.generateSideWallUV(s,i,x-6,x-3,x-2,x-1);W(M[0]),W(M[1]),W(M[3]),W(M[1]),W(M[2]),W(M[3])}function H(m){i.push(c[m*3+0]),i.push(c[m*3+1]),i.push(c[m*3+2])}function W(m){r.push(m.x),r.push(m.y)}}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON(),e=this.parameters.shapes,s=this.parameters.options;return Pe(e,s,t)}static fromJSON(t,e){const s=[];for(let r=0,n=t.shapes.length;r<n;r++){const a=e[t.shapes[r]];s.push(a)}const i=t.options.extrudePath;return console.log(i.type),i!==void 0&&(t.options.extrudePath=new v[`${i.type}Curve`]().fromJSON(i)),new vt(s,t.options)}}const Ve={generateTopUV:function(o,t,e,s,i){const r=t[e*3],n=t[e*3+1],a=t[s*3],c=t[s*3+1],h=t[i*3],l=t[i*3+1];return[new _.Vector2(r,n),new _.Vector2(a,c),new _.Vector2(h,l)]},generateSideWallUV:function(o,t,e,s,i,r){const n=t[e*3],a=t[e*3+1],c=t[e*3+2],h=t[s*3],l=t[s*3+1],d=t[s*3+2],f=t[i*3],u=t[i*3+1],b=t[i*3+2],p=t[r*3],A=t[r*3+1],S=t[r*3+2];return Math.abs(a-l)<Math.abs(n-h)?[new _.Vector2(n,1-c),new _.Vector2(h,1-d),new _.Vector2(f,1-b),new _.Vector2(p,1-S)]:[new _.Vector2(a,1-c),new _.Vector2(l,1-d),new _.Vector2(u,1-b),new _.Vector2(A,1-S)]}};function Pe(o,t,e){if(e.shapes=[],Array.isArray(o))for(let s=0,i=o.length;s<i;s++){const r=o[s];e.shapes.push(r.uuid)}else e.shapes.push(o.uuid);return e.options=Object.assign({},t),t.extrudePath!==void 0&&(e.options.extrudePath=t.extrudePath.toJSON()),e}const Nt=o=>{const{split:t,depth:e,points:s,box3:i,hasTop:r,hasBottom:n,hasSide:a,sideRepeat:c}=o,h=new vt(new v.Shape(s),{depth:e,bevelEnabled:!1,UVGenerator:yt.getUVGenerator({split:t,box3:i,sideRepeat:c}),hasTop:r,hasBottom:n,hasSide:a});return yt.claerUVGenerator(),h};class Ee extends X.BaseObject{constructor(t){super(),this.options=C({depth:1},t)}create(){return Z(this,null,function*(){const{points:t,pointsArr:e,useGroups:s,depth:i,geometry:r,geometryArr:n,material:a,box3:c,split:h,hasTop:l,hasBottom:d,hasSide:f,useUserDataPos:u}=this.options,b=Array.isArray(i)?i:[i],p=Array.isArray(c)?c:[c],A=a;let S=r;if(A||console.log("material is null"),!S&&t?S=Nt({points:t,depth:b[0],box3:p[0],split:h,hasTop:l,hasBottom:d,hasSide:f}):!S&&e?S=K(e.map((P,V)=>{var B,I;return Nt({points:P,depth:(B=b[V])!=null?B:b[0],box3:(I=p[V])!=null?I:p[0],split:h,hasTop:l,hasBottom:d,hasSide:f})}),s!=null?s:0):!S&&n&&n.length>1?S=K(n,s!=null?s:0):!S&&n&&n.length===1&&([S]=n),this.createMesh(S,A),u&&(S!=null&&S.userData.position)){const{x:P,y:V,z:B}=S.userData.position;this.object3d.position.set(P,V,B)}})}addGeometries(t){const e=this.object3d,s=K([e.geometry,...t]);e.geometry=s}setTextureAnisotropic(t,e){t.anisotropy=e||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const Be=o=>{const{topColor:t,sideColor:e,sideMap:s,createCanvasObjectURL:i,split:r,maxAnisotropy:n}=o;return new Promise(a=>{const c=s?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};c.onload=()=>{const h=r,l=document.createElement("canvas"),d=l.getContext("2d");l.height=c.height/(1-h),l.width=c.width,h&&t&&(d.fillStyle=t,d.fillRect(0,0,c.width,l.height*h)),s&&c instanceof HTMLImageElement?d.drawImage(c,0,l.height*h,c.width,c.height):e&&(d.fillStyle=e,d.fillRect(0,l.height*h,c.width,c.height)),i&&l.toBlob(u=>{console.log(URL.createObjectURL(u))});const f=new v.CanvasTexture(l);a(f)},s?c.src=s:c instanceof HTMLImageElement||c.onload()})};exports.Group=ne.Group;exports.MeshLineMaterial=xt.MeshLineMaterial;exports.meshLineMaterialArr=xt.meshLineMaterialArr;exports.ConicPolygon=Te;exports.ExtrudePolygon=Ee;exports.Image=Wt;exports.Light=ge;exports.Line=ve;exports.MeshLineGeometry=$t;exports.MeshLineRaycast=be;exports.Node=pe;exports.Pie=me;exports.Text=de;exports.Video=fe;exports.getConicPolygonGeometry=Xt;exports.getConicPolygonGeometryMetas=Jt;exports.getSplitTexture=Be;
|