gl-draw 0.16.0-beta.1 → 0.16.0-beta.2

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,7 +1,7 @@
1
1
  "use strict";var pe=Object.defineProperty,me=Object.defineProperties;var ve=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var te=Math.pow,J=(n,e,t)=>e in n?pe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,E=(n,e)=>{for(var t in e||(e={}))H.call(e,t)&&J(n,t,e[t]);if(W)for(var t of W(e))ee.call(e,t)&&J(n,t,e[t]);return n},R=(n,e)=>me(n,ve(e));var re=(n,e)=>{var t={};for(var r in n)H.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&W)for(var r of W(n))e.indexOf(r)<0&&ee.call(n,r)&&(t[r]=n[r]);return t};var ie=(n,e,t)=>new Promise((r,i)=>{var o=c=>{try{s(t.next(c))}catch(l){i(l)}},d=c=>{try{s(t.throw(c))}catch(l){i(l)}},s=c=>c.done?r(c.value):Promise.resolve(c.value).then(o,d);s((t=t.apply(n,e)).next())});const a=require("three"),ye=require("three/examples/jsm/renderers/CSS2DRenderer"),ne=require("three/examples/jsm/renderers/CSS3DRenderer"),O=require("d3-geo");require("d3-geo-projection");const Q=require("./polar2Cartesian.js"),_=require("d3-array"),X=require("earcut"),be=require("@turf/boolean-clockwise"),ge=require("delaunator"),Me=require("@turf/boolean-point-in-polygon"),xe=require("d3-geo-voronoi"),se=require("d3-scale"),Se=require("three/examples/jsm/lines/LineSegmentsGeometry"),we=0,je=1,Ae=2,Ce=!1;class fe{constructor(){this.resources=new Set,this.disposeMaterial=!0,this.disposeVideo=!0}track(e){if(!e)return e;if(Array.isArray(e))return e.forEach(t=>this.track(t)),e;if(!this.disposeMaterial&&e instanceof a.Material)return e;if(e instanceof Y?(e.disposeTrack&&e.object3d?this.track(e.object3d):this.resources.add(e),Object.values(e.materialList).map(t=>this.track(t))):(e instanceof a.Object3D||Reflect.has(e,"dispose"))&&this.resources.add(e),e instanceof Y)e.children.forEach(t=>{t.disposeTrack=!1}),this.track(e.children);else if(e instanceof a.Object3D){const t=e;this.track(t.geometry),this.track(t.material),this.track(t.children)}else if(e instanceof a.Material){for(const r of Object.values(e))r instanceof a.Texture&&this.track(r);const t=e;if(t.uniforms){for(const r of Object.values(t.uniforms))if(r){const i=r.value;(i instanceof a.Texture||Array.isArray(i))&&this.track(i)}}}else this.disposeVideo&&e.isVideoTexture&&e.source.data&&this.resources.add(e.source.data);return e}dispose(){const e=[];for(const t of this.resources)t instanceof a.Object3D?e.push(t):t instanceof HTMLVideoElement&&t.pause(),Reflect.has(t,"dispose")&&t.dispose();e.forEach(t=>{t.removeFromParent()}),e.length=0,this.resources.clear()}}const Pe=(n,e=1)=>{const t=new a.BufferGeometry;t.setAttribute("position",new a.Float32BufferAttribute(new Array(e*3).fill(0),3)),t.setAttribute("scaleAtt",new a.Float32BufferAttribute(new Array(e).fill(1),1));const r=n.material,i=new a.PointsMaterial({size:10,map:r.map,alphaMap:r.alphaMap,color:r.color,blending:r.blending,depthTest:r.depthTest,depthWrite:!1,opacity:r.opacity,transparent:!0,alphaTest:r.alphaTest,sizeAttenuation:!1});return i.onBeforeCompile=o=>{o.vertexShader=`
2
2
  attribute float scaleAtt;
3
3
  ${o.vertexShader.replace("gl_PointSize = size;","gl_PointSize = size * scaleAtt;")}
4
- `},new a.Points(t,i)},Be=(n,e)=>{const t=new a.Object3D;e.forEach((r,i)=>{const o=Q.parseVector3(r.position),d=Q.parseVector3(r.scale||[1,1,1]);t.position.copy(o),t.scale.copy(d),t.updateMatrix();const s=t.matrix.clone();if(n instanceof a.InstancedMesh||n.isInstantiate)n.setMatrixAt(i,s);else if(n instanceof a.Points||n.type==="Points"){const l=n.geometry,v=l.attributes.position.array,f=l.attributes.scaleAtt.array,p=new a.Vector3,u=new a.Vector3,m=new a.Quaternion,h=i*3,y=i*1;s.decompose(p,m,u),v[h]=p.x,v[h+1]=p.y,v[h+2]=p.z,f[y]=Math.max(u.x,u.y,u.z),l.attributes.position.needsUpdate=!0,l.attributes.scaleAtt.needsUpdate=!0}})};class De{constructor(){this.onPointerIndex=[]}onPointerEvent(e,t){const r=this.lead.handlePick([this],e,t);this.onPointerIndex.push(r)}onClick(e){this.onPointerEvent("click",e)}onPointerEnter(e){this.onPointerEvent("enter",e)}onPointerLeave(e){this.onPointerEvent("leave",e)}onPointerMove(e){this.onPointerEvent("move",e)}onPointerDown(e){this.onPointerEvent("down",e)}dispose(){this.onPointerIndex.forEach(e=>{this.lead.removePick(e)})}}class Ie extends De{constructor(){super(...arguments),this.userData={},this.materialList={},this.useMaterialType="origin",this.disposeMaterialIfNotUsed=!0}cloneMaterial(){const e=this.object3d;if(!e||!e.material)return;const t=e.material;if(Array.isArray(t))return t.map(r=>{const i=r.userData;r.userData={};const o=r.clone();return r.userData=i,o});{const r=t.userData;t.userData={};const i=t.clone();return t.userData=r,i}}setMaterialList(e,t){const r=this.object3d;if(!r||!r.material)return;this.materialList.origin||(this.materialList.origin=r.material);const i=t==="clone"?this.cloneMaterial():Array.isArray(t)?t.slice():t;return this.materialList[e]=i,i}useMaterial(e){const t=this.object3d;!t||!t.material||this.useMaterialType===e||!this.materialList[e]||(this.useMaterialType=e,t.material=this.materialList[e])}useMListById(e,t){if(!this.mList)return;const r=this.mList.get(e);if(!r)return;const i=this.object3d;Array.isArray(i.material)&&t!==void 0?i.material[t]=r:i.material=r}useMListByName(e,t){if(!this.mList)return;const r=this.mList.getKeyByName(e);r&&this.useMListById(r,t)}dispose(){super.dispose(),this.mList.rmBaseObjectMap(this,void 0,this.disposeMaterialIfNotUsed)}}class Y extends Ie{constructor(){super(...arguments),this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!1,this.isBloom=!1,this.disposeTrack=!0}get parent(){const e=this.object3d.parent;return e&&this.lead.objMap.get(e)||null}get children(){return this.object3d.children.map(e=>this.lead.objMap.get(e)).filter(e=>!!e)}get position(){return this.object3d.position}get rotation(){return this.object3d.rotation}get scale(){return this.object3d.scale}get lookAt(){return this.object3d.lookAt}add(...e){[...e].forEach(t=>{this.lead.objMap.get(t)?this.object3d.add(t):this.lead.createBaseObject(t,{target:this})})}remove(...e){[...e].forEach(t=>{var r;this.lead.objMap.get(t)?(r=this.lead.objMap.get(t))==null||r.erase():this.object3d.remove(t)})}get visible(){return this.object3d.visible}get visibleWithAncestors(){if(this.visible){let e=this.parent;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}else return!1}create(){this.createGroup()}render(){}update(e,t){}resize(e,t){}show(){return this.object3d.visible=!0,this.object3d.layers.set(we),this}hide(){return this.object3d.visible=!1,this.object3d.layers.set(Ae),this}createGroup(){return this.object3d=new a.Group,this}createMesh(...e){return this.object3d=new a.Mesh(...e),this}createPoints(...e){return this.object3d=new a.Points(...e),this}createCSS2DObject(e){return this.object3d=new ye.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new ne.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new ne.CSS3DSprite(e),this}createSprite(e){return this.object3d=new a.Sprite(e),this}attach(...e){return[...e].forEach(t=>{this.object3d.attach(t.object3d)}),this}getSize(){const e=new a.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new a.Vector3),center:e.getCenter(new a.Vector3)}}setTop(e){this.object3d&&(this.object3d.renderOrder=e)}traverse(e){e(this),this.children.forEach(t=>{t.traverse(e)})}instantiate(e){return ie(this,null,function*(){var l,v;const t=(l=e==null?void 0:e.recursive)!=null?l:!0,r=(v=e==null?void 0:e.cloneMaterial)!=null?v:!1,{objectType:i,objectOptions:o}=this,[,d]=i.split("#");let s=e==null?void 0:e.create;s===void 0&&(s=f=>{var p;if(this.object3d){if((p=e==null?void 0:e.instancedAttr)!=null&&p.length){const u=e.instancedAttr.length;if(this.object3d instanceof a.Sprite)f.object3d=Pe(this.object3d,u);else{const m=this.object3d,h=r?this.cloneMaterial():m.material;f.object3d=new a.InstancedMesh(m.geometry,h,u)}Be(f.object3d,e==null?void 0:e.instancedAttr)}else f.object3d=this.object3d.clone(!1),r&&f.object3d.material&&(f.object3d.material=this.cloneMaterial());f.object3d.userData.prefab&&delete f.object3d.userData.prefab}});const c=yield this.lead.draw(d,R(E({},o||{}),{create:s,prefab:!1,key:(e==null?void 0:e.key)||(o==null?void 0:o.key),target:(e==null?void 0:e.target)||(o==null?void 0:o.target)}));return this.isBloom&&c.enableBloom(),t&&(yield Promise.all(this.children.map(f=>f.instantiate({target:c})))),c.isInstantiate=!0,c})}erase(){this.lead.erase(this)}handleMaterialChange(e){}enableBloom(){var e;(e=this.pencil.composerController)==null||e.setBloomSelection(this,!0),this.isBloom=!0}disableBloom(){var e;(e=this.pencil.composerController)==null||e.setBloomSelection(this,!1),this.isBloom=!1}dispose(){var e;if(super.dispose(),(e=this.pencil.composerController)==null||e.bloomSelection.delete(this),this.lead&&(this.lead.objects.delete(this.key),this.lead.objectWrapChindIdMap.delete(this),this.object3d&&this.lead.objMap.delete(this.object3d)),this.disposeTrack){const t=new fe;t.disposeMaterial=!1,t.track(this),t.dispose()}}}function Ve(n,e){return n.map(t=>{const r=[];let i;return t.forEach(o=>{if(i){const d=O.geoDistance(o,i)*180/Math.PI;if(d>e){const s=O.geoInterpolate(i,o),c=1/Math.ceil(d/e);let l=c;for(;l<1;)r.push(s(l)),l+=c}}r.push(i=o)}),r})}function Te(n,{minLng:e,maxLng:t,minLat:r,maxLat:i}={}){const o=Math.round(te(360/n,2)/Math.PI),d=(1+Math.sqrt(5))/2,s=u=>u/d*360%360-180,c=u=>Math.acos(2*u/o-1)/Math.PI*180-90,l=u=>o*(Math.cos((u+90)*Math.PI/180)+1)/2,v=[i!==void 0?Math.ceil(l(i)):0,r!==void 0?Math.floor(l(r)):o-1],f=e===void 0&&t===void 0?()=>!0:e===void 0?u=>u<=t:t===void 0?u=>u>=e:t>=e?u=>u>=e&&u<=t:u=>u>=e||u<=t,p=[];for(let u=v[0];u<=v[1];u++){const m=s(u);f(m)&&p.push([m,c(u)])}return p}function Z(n,e,t=!1){return t?O.geoContains(e,n):Me(n,e)}function ze(n,e){const t={type:"Polygon",coordinates:n},[[r,i],[o,d]]=O.geoBounds(t);if(Math.min(Math.abs(o-r),Math.abs(d-i))<e)return[];const s=r>o||d>=89||i<=-89;return Te(e,{minLng:r,maxLng:o,minLat:i,maxLat:d}).filter(c=>Z(c,t,s))}function Le(n,{resolution:e=1/0,bbox:t,projection:r}={}){const i=Ve(n,e),o=_.merge(i),d=ze(n,e),s=[...o,...d],c={type:"Polygon",coordinates:n},[[l,v],[f,p]]=O.geoBounds(c),u=l>f||p>=89||v<=-89;let m=[];if(u){const b=xe.geoVoronoi(s).triangles(),S=new Map(s.map(([C,P],z)=>[`${C}-${P}`,z]));b.features.forEach(C=>{const P=C.geometry.coordinates[0].slice(0,3).reverse(),z=[];if(P.forEach(([B,q])=>{const k=`${B}-${q}`;S.has(k)&&z.push(S.get(k))}),z.length===3){if(z.some(B=>B<o.length)){const B=C.properties.circumcenter;if(!Z(B,c,u))return}m.push(...z)}})}else if(d.length){const b=ge.from(s);for(let S=0,C=b.triangles.length;S<C;S+=3){const P=[2,1,0].map(B=>b.triangles[S+B]),z=P.map(B=>s[B]);if(P.some(B=>B<o.length)){const B=[0,1].map(q=>_.mean(z,k=>k[q]));if(!Z(B,c,u))continue}m.push(...P)}}else{const{vertices:b,holes:S=[]}=X.flatten(i);m=X(b,S,2)}let h=t?[t[0],t[2]]:_.extent(s,b=>b[0]),y=t?[t[1],t[3]]:_.extent(s,b=>b[1]);if(r){const[b,S]=r([h[0],y[0]]),[C,P]=r([h[1],y[1]]);h=[b,C],y=[-S,-P]}const w=se.scaleLinear(h,[0,1]),j=se.scaleLinear(y,[0,1]),D=s.map(([b,S])=>{if(r){const[C,P]=r([b,S]);return[w(C),j(-P)]}else return[w(b),j(S)]});return{contour:i,triangles:{points:s,indices:m,uvs:D}}}const oe=new a.BufferGeometry().setAttribute?"setAttribute":"addAttribute";function G(n,e,t,r){const i=n.map(o=>o.map(([d,s])=>{if(r){const[c,l]=r([d,s]);return[c,-l,e]}return t?Q.polar2Cartesian(d,s,e):[d,s,e]}));return X.flatten(i)}function _e(n,e,t,r,i){const{vertices:o,holes:d}=G(n,e,r,i),{vertices:s}=G(n,t,r,i),c=_.merge([s,o]),l=Math.round(s.length/3),v=new Set(d);let f=0;const p=[];for(let m=0;m<l;m++){let h=m+1;if(h===l)h=f;else if(v.has(h)){const y=h;h=f,f=y}p.push(m,m+l,h+l),p.push(h+l,h,m)}const u=[];for(let m=1;m>=0;m--)for(let h=0;h<l;h+=1)u.push(h/(l-1),m);return{indices:p,vertices:c,uvs:u,topVerts:s}}function ae(n,e,t,r,i,o){return{indices:r?n.indices:n.indices.slice().reverse(),vertices:G([n.points],e,i,o).vertices,uvs:t}}const he=({polygonGeoJson:n,startHeight:e,endHeight:t,curvatureResolution:r=1,cartesian:i=!0,hasSide:o=!0,hasBottom:d=!1,hasTop:s=!1,projection:c,bbox:l})=>{n.forEach(w=>{be(w)||w.reverse()});const{contour:v,triangles:f}=Le(n,{resolution:r,bbox:l,projection:c});let p={},u;o&&(p=_e(v,e!=null?e:t,t!=null?t:e,i,c),u=p.topVerts);let m=[];(d||s)&&(m=_.merge(f.uvs));let h={};d&&(h=ae(f,e,m,!1,i,c));let y={};return s&&(y=ae(f,t,m,!0,i,c)),{contour:v,triangles:f,sideTorso:p,bottomCap:h,topCap:y,topVerts:u}};class Ee extends a.BufferGeometry{constructor(e,t={}){super(),this.type="PolygonBufferGeometry",this.parameters=E({polygonGeoJson:e,startHeight:0,endHeight:1,hasTop:!0,topFirst:!1,hasBottom:!0,hasSide:!0,curvatureResolution:1,cartesian:!0,userDataRsoOffset:0},t);const{endHeight:r,hasTop:i,topFirst:o,hasBottom:d,hasSide:s,cartesian:c,userDataRsoOffset:l,projection:v}=this.parameters,{contour:f,sideTorso:p,topVerts:u,bottomCap:m,topCap:h}=he(E({},this.parameters));let y=[],w=[],j=[],D=0;const A=b=>{const S=Math.round(y.length/3),C=j.length;y=y.concat(b.vertices),w=w.concat(b.uvs),j=j.concat(S?b.indices.map(P=>P+S):b.indices),this.addGroup(C,j.length-C,D++)};i&&o&&A(h),s&&(A(p),this.userData.topVerts=l?G(f,r+l,c,v).vertices:u),d&&A(m),i&&!o&&A(h),this.setIndex(j),this[oe]("position",new a.Float32BufferAttribute(y,3)),this[oe]("uv",new a.Float32BufferAttribute(w,2)),this.computeVertexNormals()}}const Oe=`
4
+ `},new a.Points(t,i)},Be=(n,e)=>{const t=new a.Object3D;e.forEach((r,i)=>{const o=Q.parseVector3(r.position),d=Q.parseVector3(r.scale||[1,1,1]);t.position.copy(o),t.scale.copy(d),t.updateMatrix();const s=t.matrix.clone();if(n instanceof a.InstancedMesh||n.isInstantiate)n.setMatrixAt(i,s);else if(n instanceof a.Points||n.type==="Points"){const l=n.geometry,v=l.attributes.position.array,f=l.attributes.scaleAtt.array,p=new a.Vector3,u=new a.Vector3,m=new a.Quaternion,h=i*3,y=i*1;s.decompose(p,m,u),v[h]=p.x,v[h+1]=p.y,v[h+2]=p.z,f[y]=Math.max(u.x,u.y,u.z),l.attributes.position.needsUpdate=!0,l.attributes.scaleAtt.needsUpdate=!0}})};class De{constructor(){this.onPointerIndex=[]}onPointerEvent(e,t){const r=this.lead.handlePick([this],e,t);this.onPointerIndex.push(r)}onClick(e){this.onPointerEvent("click",e)}onPointerEnter(e){this.onPointerEvent("enter",e)}onPointerLeave(e){this.onPointerEvent("leave",e)}onPointerMove(e){this.onPointerEvent("move",e)}onPointerDown(e){this.onPointerEvent("down",e)}dispose(){this.onPointerIndex.forEach(e=>{this.lead.removePick(e)})}}class Ie extends De{constructor(){super(...arguments),this.userData={},this.materialList={},this.useMaterialType="origin",this.disposeMaterialIfNotUsed=!0}cloneMaterial(){const e=this.object3d;if(!e||!e.material)return;const t=e.material;if(Array.isArray(t))return t.map(r=>{const i=r.userData;r.userData={};const o=r.clone();return r.userData=i,o});{const r=t.userData;t.userData={};const i=t.clone();return t.userData=r,i}}setMaterialList(e,t){const r=this.object3d;if(!r||!r.material)return;this.materialList.origin||(this.materialList.origin=r.material);const i=t==="clone"?this.cloneMaterial():Array.isArray(t)?t.slice():t;return this.materialList[e]=i,i}useMaterial(e){const t=this.object3d;!t||!t.material||this.useMaterialType===e||!this.materialList[e]||(this.useMaterialType=e,t.material=this.materialList[e])}useMListById(e,t){if(!this.mList)return;const r=this.mList.get(e);if(!r)return;const i=this.object3d;Array.isArray(i.material)&&t!==void 0?i.material[t]=r:i.material=r}useMListByName(e,t){if(!this.mList)return;const r=this.mList.getKeyByName(e);r&&this.useMListById(r,t)}dispose(){super.dispose(),this.mList.rmBaseObjectMap(this,void 0,this.disposeMaterialIfNotUsed)}}class Y extends Ie{constructor(){super(...arguments),this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!1,this.isBloom=!1,this.disposeTrack=!0}get parent(){const e=this.object3d.parent;return e&&this.lead.objMap.get(e)||null}get children(){return this.object3d.children.map(e=>this.lead.objMap.get(e)).filter(e=>!!e)}get position(){return this.object3d.position}get rotation(){return this.object3d.rotation}get scale(){return this.object3d.scale}get lookAt(){return this.object3d.lookAt}add(...e){[...e].forEach(t=>{this.lead.objMap.get(t)?this.object3d.add(t):this.lead.createBaseObject(t,{target:this})})}remove(...e){[...e].forEach(t=>{var r;this.lead.objMap.get(t)?(r=this.lead.objMap.get(t))==null||r.erase():this.object3d.remove(t)})}get visible(){return this.object3d.visible}get visibleWithAncestors(){if(this.visible){let e=this.parent;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}else return!1}create(){this.createGroup()}render(){}update(e,t){}resize(e,t){}show(){return this.object3d.visible=!0,this.object3d.layers.set(we),this}hide(){return this.object3d.visible=!1,this.object3d.layers.set(Ae),this}createGroup(){return this.object3d=new a.Group,this}createMesh(...e){return this.object3d=new a.Mesh(...e),this}createPoints(...e){return this.object3d=new a.Points(...e),this}createCSS2DObject(e){return this.object3d=new ye.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new ne.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new ne.CSS3DSprite(e),this}createSprite(e){return this.object3d=new a.Sprite(e),this}attach(...e){return[...e].forEach(t=>{this.object3d.attach(t.object3d)}),this}getSize(){const e=new a.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new a.Vector3),center:e.getCenter(new a.Vector3)}}setTop(e){this.object3d&&(this.object3d.renderOrder=e)}traverse(e){e(this),this.children.forEach(t=>{t.traverse(e)})}instantiate(e){return ie(this,null,function*(){var l,v;const t=(l=e==null?void 0:e.recursive)!=null?l:!0,r=(v=e==null?void 0:e.cloneMaterial)!=null?v:!1,{objectType:i,objectOptions:o}=this,[,d]=i.split("#");let s=e==null?void 0:e.create;s===void 0&&(s=f=>{var p;if(this.object3d){if((p=e==null?void 0:e.instancedAttr)!=null&&p.length){const u=e.instancedAttr.length;if(this.object3d instanceof a.Sprite)f.object3d=Pe(this.object3d,u);else{const m=this.object3d,h=r?this.cloneMaterial():m.material;f.object3d=new a.InstancedMesh(m.geometry,h,u)}Be(f.object3d,e==null?void 0:e.instancedAttr)}else f.object3d=this.object3d.clone(!1),r&&f.object3d.material&&(f.object3d.material=this.cloneMaterial());f.object3d.userData.prefab&&delete f.object3d.userData.prefab}});const c=yield this.lead.draw(d,R(E({},o||{}),{create:s,prefab:!1,key:(e==null?void 0:e.key)||(o==null?void 0:o.key),target:(e==null?void 0:e.target)||(o==null?void 0:o.target)}));return this.isBloom&&c.enableBloom(),t&&(yield Promise.all(this.children.map(f=>f.instantiate({cloneMaterial:r,target:c})))),c.isInstantiate=!0,c})}erase(){this.lead.erase(this)}handleMaterialChange(e){}enableBloom(){var e;(e=this.pencil.composerController)==null||e.setBloomSelection(this,!0),this.isBloom=!0}disableBloom(){var e;(e=this.pencil.composerController)==null||e.setBloomSelection(this,!1),this.isBloom=!1}dispose(){var e;if(super.dispose(),(e=this.pencil.composerController)==null||e.bloomSelection.delete(this),this.lead&&(this.lead.objects.delete(this.key),this.lead.objectWrapChindIdMap.delete(this),this.object3d&&this.lead.objMap.delete(this.object3d)),this.disposeTrack){const t=new fe;t.disposeMaterial=!1,t.track(this),t.dispose()}}}function Ve(n,e){return n.map(t=>{const r=[];let i;return t.forEach(o=>{if(i){const d=O.geoDistance(o,i)*180/Math.PI;if(d>e){const s=O.geoInterpolate(i,o),c=1/Math.ceil(d/e);let l=c;for(;l<1;)r.push(s(l)),l+=c}}r.push(i=o)}),r})}function Te(n,{minLng:e,maxLng:t,minLat:r,maxLat:i}={}){const o=Math.round(te(360/n,2)/Math.PI),d=(1+Math.sqrt(5))/2,s=u=>u/d*360%360-180,c=u=>Math.acos(2*u/o-1)/Math.PI*180-90,l=u=>o*(Math.cos((u+90)*Math.PI/180)+1)/2,v=[i!==void 0?Math.ceil(l(i)):0,r!==void 0?Math.floor(l(r)):o-1],f=e===void 0&&t===void 0?()=>!0:e===void 0?u=>u<=t:t===void 0?u=>u>=e:t>=e?u=>u>=e&&u<=t:u=>u>=e||u<=t,p=[];for(let u=v[0];u<=v[1];u++){const m=s(u);f(m)&&p.push([m,c(u)])}return p}function Z(n,e,t=!1){return t?O.geoContains(e,n):Me(n,e)}function ze(n,e){const t={type:"Polygon",coordinates:n},[[r,i],[o,d]]=O.geoBounds(t);if(Math.min(Math.abs(o-r),Math.abs(d-i))<e)return[];const s=r>o||d>=89||i<=-89;return Te(e,{minLng:r,maxLng:o,minLat:i,maxLat:d}).filter(c=>Z(c,t,s))}function Le(n,{resolution:e=1/0,bbox:t,projection:r}={}){const i=Ve(n,e),o=_.merge(i),d=ze(n,e),s=[...o,...d],c={type:"Polygon",coordinates:n},[[l,v],[f,p]]=O.geoBounds(c),u=l>f||p>=89||v<=-89;let m=[];if(u){const b=xe.geoVoronoi(s).triangles(),S=new Map(s.map(([C,P],z)=>[`${C}-${P}`,z]));b.features.forEach(C=>{const P=C.geometry.coordinates[0].slice(0,3).reverse(),z=[];if(P.forEach(([B,q])=>{const k=`${B}-${q}`;S.has(k)&&z.push(S.get(k))}),z.length===3){if(z.some(B=>B<o.length)){const B=C.properties.circumcenter;if(!Z(B,c,u))return}m.push(...z)}})}else if(d.length){const b=ge.from(s);for(let S=0,C=b.triangles.length;S<C;S+=3){const P=[2,1,0].map(B=>b.triangles[S+B]),z=P.map(B=>s[B]);if(P.some(B=>B<o.length)){const B=[0,1].map(q=>_.mean(z,k=>k[q]));if(!Z(B,c,u))continue}m.push(...P)}}else{const{vertices:b,holes:S=[]}=X.flatten(i);m=X(b,S,2)}let h=t?[t[0],t[2]]:_.extent(s,b=>b[0]),y=t?[t[1],t[3]]:_.extent(s,b=>b[1]);if(r){const[b,S]=r([h[0],y[0]]),[C,P]=r([h[1],y[1]]);h=[b,C],y=[-S,-P]}const w=se.scaleLinear(h,[0,1]),j=se.scaleLinear(y,[0,1]),D=s.map(([b,S])=>{if(r){const[C,P]=r([b,S]);return[w(C),j(-P)]}else return[w(b),j(S)]});return{contour:i,triangles:{points:s,indices:m,uvs:D}}}const oe=new a.BufferGeometry().setAttribute?"setAttribute":"addAttribute";function G(n,e,t,r){const i=n.map(o=>o.map(([d,s])=>{if(r){const[c,l]=r([d,s]);return[c,-l,e]}return t?Q.polar2Cartesian(d,s,e):[d,s,e]}));return X.flatten(i)}function _e(n,e,t,r,i){const{vertices:o,holes:d}=G(n,e,r,i),{vertices:s}=G(n,t,r,i),c=_.merge([s,o]),l=Math.round(s.length/3),v=new Set(d);let f=0;const p=[];for(let m=0;m<l;m++){let h=m+1;if(h===l)h=f;else if(v.has(h)){const y=h;h=f,f=y}p.push(m,m+l,h+l),p.push(h+l,h,m)}const u=[];for(let m=1;m>=0;m--)for(let h=0;h<l;h+=1)u.push(h/(l-1),m);return{indices:p,vertices:c,uvs:u,topVerts:s}}function ae(n,e,t,r,i,o){return{indices:r?n.indices:n.indices.slice().reverse(),vertices:G([n.points],e,i,o).vertices,uvs:t}}const he=({polygonGeoJson:n,startHeight:e,endHeight:t,curvatureResolution:r=1,cartesian:i=!0,hasSide:o=!0,hasBottom:d=!1,hasTop:s=!1,projection:c,bbox:l})=>{n.forEach(w=>{be(w)||w.reverse()});const{contour:v,triangles:f}=Le(n,{resolution:r,bbox:l,projection:c});let p={},u;o&&(p=_e(v,e!=null?e:t,t!=null?t:e,i,c),u=p.topVerts);let m=[];(d||s)&&(m=_.merge(f.uvs));let h={};d&&(h=ae(f,e,m,!1,i,c));let y={};return s&&(y=ae(f,t,m,!0,i,c)),{contour:v,triangles:f,sideTorso:p,bottomCap:h,topCap:y,topVerts:u}};class Ee extends a.BufferGeometry{constructor(e,t={}){super(),this.type="PolygonBufferGeometry",this.parameters=E({polygonGeoJson:e,startHeight:0,endHeight:1,hasTop:!0,topFirst:!1,hasBottom:!0,hasSide:!0,curvatureResolution:1,cartesian:!0,userDataRsoOffset:0},t);const{endHeight:r,hasTop:i,topFirst:o,hasBottom:d,hasSide:s,cartesian:c,userDataRsoOffset:l,projection:v}=this.parameters,{contour:f,sideTorso:p,topVerts:u,bottomCap:m,topCap:h}=he(E({},this.parameters));let y=[],w=[],j=[],D=0;const A=b=>{const S=Math.round(y.length/3),C=j.length;y=y.concat(b.vertices),w=w.concat(b.uvs),j=j.concat(S?b.indices.map(P=>P+S):b.indices),this.addGroup(C,j.length-C,D++)};i&&o&&A(h),s&&(A(p),this.userData.topVerts=l?G(f,r+l,c,v).vertices:u),d&&A(m),i&&!o&&A(h),this.setIndex(j),this[oe]("position",new a.Float32BufferAttribute(y,3)),this[oe]("uv",new a.Float32BufferAttribute(w,2)),this.computeVertexNormals()}}const Oe=`
5
5
  #include <fog_pars_fragment>
6
6
  #include <logdepthbuf_pars_fragment>
7
7
 
@@ -363,6 +363,7 @@ class pt extends se {
363
363
  return this.isBloom && o.enableBloom(), e && (yield Promise.all(
364
364
  this.children.map(
365
365
  (f) => f.instantiate({
366
+ cloneMaterial: i,
366
367
  target: o
367
368
  })
368
369
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gl-draw",
3
- "version": "0.16.0-beta.1",
3
+ "version": "0.16.0-beta.2",
4
4
  "author": "gitplus <hstits@gmail.com>",
5
5
  "scripts": {
6
6
  "start": "bundler-dev",