gl-draw 0.17.0-beta.34 → 0.17.0-beta.36
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/index.js +1 -1
- package/dist/index.module.js +4 -3
- package/dist/index.module2.js +353 -295
- package/dist/index2.js +5 -5
- package/dist/utils/Sprite2Points.d.ts +1 -1
- package/dist/utils/proposedRaycast.d.ts +1 -0
- package/package.json +1 -1
package/dist/index2.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Se=Object.defineProperty,je=Object.defineProperties;var Ce=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var oe=Math.pow,se=(n,e,t)=>e in n?Se(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,k=(n,e)=>{for(var t in e||(e={}))re.call(e,t)&&se(n,t,e[t]);if(R)for(var t of R(e))ne.call(e,t)&&se(n,t,e[t]);return n},X=(n,e)=>je(n,Ce(e));var ae=(n,e)=>{var t={};for(var i in n)re.call(n,i)&&e.indexOf(i)<0&&(t[i]=n[i]);if(n!=null&&R)for(var i of R(n))e.indexOf(i)<0&&ne.call(n,i)&&(t[i]=n[i]);return t};var ce=(n,e,t)=>new Promise((i,s)=>{var o=c=>{try{r(t.next(c))}catch(u){s(u)}},l=c=>{try{r(t.throw(c))}catch(u){s(u)}},r=c=>c.done?i(c.value):Promise.resolve(c.value).then(o,l);r((t=t.apply(n,e)).next())});const z=require("d3-array"),J=require("earcut"),a=require("three"),Ae=require("@turf/boolean-clockwise"),H=require("./polar2Cartesian.js"),Pe=require("delaunator"),Be=require("@turf/boolean-point-in-polygon"),_=require("d3-geo"),Ie=require("d3-geo-voronoi"),le=require("d3-scale"),Oe=require("three/examples/jsm/lines/LineSegmentsGeometry"),De=require("three/examples/jsm/renderers/CSS2DRenderer"),ue=require("three/examples/jsm/renderers/CSS3DRenderer");require("d3-geo-projection");const de=0,ee=1,Te=!1;class Me{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 q?(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 q)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 i of Object.values(e))i instanceof a.Texture&&this.track(i);const t=e;if(t.uniforms){for(const i of Object.values(t.uniforms))if(i){const s=i.value;(s instanceof a.Texture||Array.isArray(s))&&this.track(s)}}}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 he=new a.Matrix4,xe=new a.Ray,K=new a.Sphere,W=new a.Vector3;function Ve(n,e){const t=this.geometry,i=this.matrixWorld,s=n.params.Points.threshold,o=t.drawRange;t.boundingSphere===null&&t.computeBoundingSphere(),K.copy(t.boundingSphere),K.applyMatrix4(i),K.radius+=s,he.copy(i).invert(),xe.copy(n.ray).applyMatrix4(he);const l=s/((this.scale.x+this.scale.y+this.scale.z)/3),r=t.index,u=t.attributes.position;if(r!==null){const p=Math.max(0,o.start),d=Math.min(r.count,o.start+o.count);for(let f=p,h=d;f<h;f++){const m=r.getX(f);W.fromBufferAttribute(u,m),fe(W,m,l,i,n,e,this)}}else{const p=Math.max(0,o.start),d=Math.min(u.count,o.start+o.count);for(let f=p,h=d;f<h;f++)W.fromBufferAttribute(u,f),fe(W,f,l,i,n,e,this)}}function fe(n,e,t,i,s,o,l){const r=new a.Vector3;xe.closestPointToPoint(n,r),r.applyMatrix4(i);const c=s.ray.origin.distanceTo(n),u=r.distanceTo(n),p=Math.asin(u/c);if(p<t){if(c<s.near||c>s.far)return;o.push({distance:c,distanceToRay:u,angleToRay:p,point:r,index:e,face:null,object:l})}}const Ee=(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 i=n.material,s=new a.PointsMaterial({size:10,map:i.map,alphaMap:i.alphaMap,color:i.color,blending:i.blending,depthTest:i.depthTest,depthWrite:!1,opacity:i.opacity,transparent:!0,alphaTest:i.alphaTest,sizeAttenuation:!1});s.onBeforeCompile=l=>{l.vertexShader=`
|
|
2
2
|
attribute float scaleAtt;
|
|
3
|
-
${
|
|
4
|
-
`},new a.Points(t,s)},Ie=(n,e)=>{const t=new a.Object3D;e.forEach((i,s)=>{const o=Z.parseVector3(i.position),l=Z.parseVector3(i.scale||[1,1,1]);t.position.copy(o),t.scale.copy(l),t.updateMatrix();const r=t.matrix.clone();if(n instanceof a.InstancedMesh||n.isInstantiate)n.setMatrixAt(s,r);else if(n instanceof a.Points||n.type==="Points"){const u=n.geometry,v=u.attributes.position.array,d=u.attributes.scaleAtt.array,p=new a.Vector3,h=new a.Vector3,m=new a.Quaternion,f=s*3,b=s*1;r.decompose(p,m,h),v[f]=p.x,v[f+1]=p.y,v[f+2]=p.z,d[b]=Math.max(h.x,h.y,h.z),u.attributes.position.needsUpdate=!0,u.attributes.scaleAtt.needsUpdate=!0}})};class Oe{constructor(){this.onPointerIndex=[]}onPointerEvent(e,t){const i=this.lead.handlePick([this],e,t);this.onPointerIndex.push(i)}onClick(e){this.onPointerEvent("click",e)}onPointerEnter(e){this.onPointerEvent("enter",e)}onPointerEnterOnStop(e){this.onPointerEvent("enterOnStop",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 De extends Oe{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(i=>{const s=i.userData;i.userData={};const o=i.clone();return i.userData=s,o});{const i=t.userData;t.userData={};const s=t.clone();return t.userData=i,s}}setMaterialList(e,t){const i=this.object3d;if(!i||!i.material)return;this.materialList.origin||(this.materialList.origin=i.material);const s=t==="clone"?this.cloneMaterial():Array.isArray(t)?t.slice():t;return this.materialList[e]=s,s}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 i=this.mList.get(e);if(!i)return;const s=this.object3d;Array.isArray(s.material)&&t!==void 0?s.material[t]=i:s.material=i}useMListByName(e,t){if(!this.mList)return;const i=this.mList.getKeyByName(e);i&&this.useMListById(i,t)}dispose(){super.dispose(),this.mList.rmBaseObjectMap(this,void 0,this.disposeMaterialIfNotUsed)}}class G extends De{constructor(){super(...arguments),this.key="",this.objectType="BaseObject",this.userData={},this.isPrefab=!1,this.isInstantiate=!1,this.isBloom=!1,this.isBaseObject=!0,this.disposeTrack=!0,this.isDispose=!1}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}lookAt(e){const t=e instanceof a.Vector3?e:new a.Vector3(...e);this.object3d.lookAt(t)}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 i;this.lead.objMap.get(t)?(i=this.lead.objMap.get(t))==null||i.erase():this.object3d.remove(t)})}get visible(){return this.object3d.visible}isActuallyVisible(){if(!this.object3d.visible)return!1;const e=this.parent;return e?e.isActuallyVisible():!0}create(){this.createGroup()}render(){}update(e,t){}resize(e,t){}show(){return this.object3d.visible=!0,this.isActuallyVisible()&&this._enableLayersRecursive(),this}hide(){return this.object3d.visible=!1,this._disableLayersRecursive(),this}_disableLayersRecursive(){var e;(e=this.object3d)==null||e.layers.disable(le),this.children.forEach(t=>{t._disableLayersRecursive()})}_enableLayersRecursive(){var e;this.object3d.visible&&((e=this.object3d)==null||e.layers.enable(le),this.children.forEach(t=>{t._enableLayersRecursive()}))}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 Ae.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new ce.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new ce.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 oe(this,null,function*(){var u,v;const t=(u=e==null?void 0:e.recursive)!=null?u:!0,i=(v=e==null?void 0:e.cloneMaterial)!=null?v:!1,{objectType:s,objectOptions:o}=this;let l=e==null?void 0:e.create,r,c=(e==null?void 0:e.target)||this.parent;return c===this.lead.prefabGroup&&(c=this.lead.group),this.objectType==="BaseObject"?r=this.lead.createBaseObject(this.object3d.clone(!1),{target:c}):(l===void 0&&(l=d=>{var p;if(this.object3d){if((p=e==null?void 0:e.instancedAttr)!=null&&p.length){const h=e.instancedAttr.length;if(this.object3d instanceof a.Sprite)d.object3d=Be(this.object3d,h);else{const m=this.object3d,f=i?this.cloneMaterial():m.material;d.object3d=new a.InstancedMesh(m.geometry,f,h)}Ie(d.object3d,e==null?void 0:e.instancedAttr)}else d.object3d=this.object3d.clone(!1),i&&d.object3d.material&&(d.object3d.material=this.cloneMaterial());d.object3d.userData.prefab&&delete d.object3d.userData.prefab}}),r=yield this.lead.draw(s,$(k({},o||{}),{create:l,prefab:!1,keyType:this.keyType,key:(e==null?void 0:e.key)||this.keyName,uId:(e==null?void 0:e.uId)||this.keyUId,target:c}))),this.isBloom&&r.enableBloom(),t&&(yield Promise.all(this.children.map(d=>d.instantiate({key:d.keyUId&&d.keyName?`${d.keyName}-${d.keyUId}`:d.keyName,uId:e==null?void 0:e.uId,cloneMaterial:i,target:r})))),r.isInstantiate=!0,r})}erase(){this.lead.erase(this)}handleMaterialChange(e){}enableBloom(e=!0){var t,i,s;if(!((t=this.pencil.composerController)!=null&&t.bloomComposer)){console.warn("err:pencil.options.bloom");return}if(e){this.traverse(o=>{o.enableBloom(!1)});return}this.object3d&&((i=this.pencil.composerController)==null||i.bloomSelection.add(this),this.object3d.layers.enable(J)),(s=this.pencil.composerController)==null||s.checkBloomComposerActive(),this.isBloom=!0}disableBloom(e=!0){var t,i,s;if(!((t=this.pencil.composerController)!=null&&t.bloomComposer)){console.warn("err:pencil.options.bloom");return}if(e){this.traverse(o=>{o.disableBloom(!1)});return}this.object3d&&((i=this.pencil.composerController)==null||i.bloomSelection.delete(this),this.object3d.layers.disable(J)),(s=this.pencil.composerController)==null||s.checkBloomComposerActive(),this.isBloom=!1}dispose(){var e,t;if(!this.isDispose&&(this.isDispose=!0,super.dispose(),this.isBloom&&(this.disableBloom(!1),(e=this.pencil.composerController)==null||e.checkBloomComposerActive()),(t=this.lead)==null||t.disableCursor(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 i=new ve;i.disposeMaterial=!1,i.track(this),i.dispose()}}}function Ve(n,e){return n.map(t=>{const i=[];let s;return t.forEach(o=>{if(s){const l=N.geoDistance(o,s)*180/Math.PI;if(l>e){const r=N.geoInterpolate(s,o),c=1/Math.ceil(l/e);let u=c;for(;u<1;)i.push(r(u)),u+=c}}i.push(s=o)}),i})}function Te(n,{minLng:e,maxLng:t,minLat:i,maxLat:s}={}){const o=Math.round(re(360/n,2)/Math.PI),l=(1+Math.sqrt(5))/2,r=h=>h/l*360%360-180,c=h=>Math.acos(2*h/o-1)/Math.PI*180-90,u=h=>o*(Math.cos((h+90)*Math.PI/180)+1)/2,v=[s!==void 0?Math.ceil(u(s)):0,i!==void 0?Math.floor(u(i)):o-1],d=e===void 0&&t===void 0?()=>!0:e===void 0?h=>h<=t:t===void 0?h=>h>=e:t>=e?h=>h>=e&&h<=t:h=>h>=e||h<=t,p=[];for(let h=v[0];h<=v[1];h++){const m=r(h);d(m)&&p.push([m,c(h)])}return p}function H(n,e,t=!1){return t?N.geoContains(e,n):Se(n,e)}function Ee(n,e){const t={type:"Polygon",coordinates:n},[[i,s],[o,l]]=N.geoBounds(t);if(Math.min(Math.abs(o-i),Math.abs(l-s))<e)return[];const r=i>o||l>=89||s<=-89;return Te(e,{minLng:i,maxLng:o,minLat:s,maxLat:l}).filter(c=>H(c,t,r))}function Le(n,{resolution:e=1/0,bbox:t,projection:i}={}){const s=Ve(n,e),o=z.merge(s),l=Ee(n,e),r=[...o,...l],c={type:"Polygon",coordinates:n},[[u,v],[d,p]]=N.geoBounds(c),h=u>d||p>=89||v<=-89;let m=[];if(h){const g=je.geoVoronoi(r).triangles(),S=new Map(r.map(([P,B],E)=>[`${P}-${B}`,E]));g.features.forEach(P=>{const B=P.geometry.coordinates[0].slice(0,3).reverse(),E=[];if(B.forEach(([I,F])=>{const _=`${I}-${F}`;S.has(_)&&E.push(S.get(_))}),E.length===3){if(E.some(I=>I<o.length)){const I=P.properties.circumcenter;if(!H(I,c,h))return}m.push(...E)}})}else if(l.length){const g=xe.from(r);for(let S=0,P=g.triangles.length;S<P;S+=3){const B=[2,1,0].map(I=>g.triangles[S+I]),E=B.map(I=>r[I]);if(B.some(I=>I<o.length)){const I=[0,1].map(F=>z.mean(E,_=>_[F]));if(!H(I,c,h))continue}m.push(...B)}}else{const{vertices:g,holes:S=[]}=Y.flatten(s);m=Y(g,S,2)}let f=t?[t[0],t[2]]:z.extent(r,g=>g[0]),b=t?[t[1],t[3]]:z.extent(r,g=>g[1]);if(i){const[g,S]=i([f[0],b[0]]),[P,B]=i([f[1],b[1]]);f=[g,P],b=[-S,-B]}const j=ae.scaleLinear(f,[0,1]),C=ae.scaleLinear(b,[0,1]),O=r.map(([g,S])=>{if(i){const[P,B]=i([g,S]);return[j(P),C(-B)]}else return[j(g),C(S)]});return{contour:s,triangles:{points:r,indices:m,uvs:O}}}const ue=new a.BufferGeometry().setAttribute?"setAttribute":"addAttribute";function q(n,e,t,i){const s=n.map(o=>o.map(([l,r])=>{if(i){const[c,u]=i([l,r]);return[c,-u,e]}return t?Z.polar2Cartesian(l,r,e):[l,r,e]}));return Y.flatten(s)}function ke(n,e,t,i,s){const{vertices:o,holes:l}=q(n,e,i,s),{vertices:r}=q(n,t,i,s),c=z.merge([r,o]),u=Math.round(r.length/3),v=new Set(l);let d=0;const p=[];for(let m=0;m<u;m++){let f=m+1;if(f===u)f=d;else if(v.has(f)){const b=f;f=d,d=b}p.push(m,m+u,f+u),p.push(f+u,f,m)}const h=[];for(let m=1;m>=0;m--)for(let f=0;f<u;f+=1)h.push(f/(u-1),m);return{indices:p,vertices:c,uvs:h,topVerts:r}}function de(n,e,t,i,s,o){return{indices:i?n.indices:n.indices.slice().reverse(),vertices:q([n.points],e,s,o).vertices,uvs:t}}const be=({polygonGeoJson:n,startHeight:e,endHeight:t,curvatureResolution:i=1,cartesian:s=!0,hasSide:o=!0,hasBottom:l=!1,hasTop:r=!1,projection:c,bbox:u})=>{n.forEach(j=>{we(j)||j.reverse()});const{contour:v,triangles:d}=Le(n,{resolution:i,bbox:u,projection:c});let p={},h;o&&(p=ke(v,e!=null?e:t,t!=null?t:e,s,c),h=p.topVerts);let m=[];(l||r)&&(m=z.merge(d.uvs));let f={};l&&(f=de(d,e,m,!1,s,c));let b={};return r&&(b=de(d,t,m,!0,s,c)),{contour:v,triangles:d,sideTorso:p,bottomCap:f,topCap:b,topVerts:h}};class ze extends a.BufferGeometry{constructor(e,t={}){super(),this.type="PolygonBufferGeometry",this.parameters=k({polygonGeoJson:e,startHeight:0,endHeight:1,hasTop:!0,topFirst:!1,hasBottom:!0,hasSide:!0,curvatureResolution:1,cartesian:!0,userDataRsoOffset:0},t);const{endHeight:i,hasTop:s,topFirst:o,hasBottom:l,hasSide:r,cartesian:c,userDataRsoOffset:u,projection:v}=this.parameters,{contour:d,sideTorso:p,topVerts:h,bottomCap:m,topCap:f}=be(k({},this.parameters));let b=[],j=[],C=[],O=0;const A=g=>{const S=Math.round(b.length/3),P=C.length;b=b.concat(g.vertices),j=j.concat(g.uvs),C=C.concat(S?g.indices.map(B=>B+S):g.indices),this.addGroup(P,C.length-P,O++)};s&&o&&A(f),r&&(A(p),this.userData.topVerts=u?q(d,i+u,c,v).vertices:h),l&&A(m),s&&!o&&A(f),this.setIndex(C),this[ue]("position",new a.Float32BufferAttribute(b,3)),this[ue]("uv",new a.Float32BufferAttribute(j,2)),this.computeVertexNormals()}}const Ne=`
|
|
3
|
+
${l.vertexShader.replace("gl_PointSize = size;","gl_PointSize = size * scaleAtt;")}
|
|
4
|
+
`};const o=new a.Points(t,s);return o.raycast=Ve,o},Le=(n,e)=>{const t=new a.Object3D;e.forEach((i,s)=>{const o=H.parseVector3(i.position),l=H.parseVector3(i.scale||[1,1,1]);t.position.copy(o),t.scale.copy(l),t.updateMatrix();const r=t.matrix.clone();if(n instanceof a.InstancedMesh||n.isInstantiate)n.setMatrixAt(s,r);else if(n instanceof a.Points||n.type==="Points"){const u=n.geometry,p=u.attributes.position.array,d=u.attributes.scaleAtt.array,f=new a.Vector3,h=new a.Vector3,m=new a.Quaternion,v=s*3,b=s*1;r.decompose(f,m,h),p[v]=f.x,p[v+1]=f.y,p[v+2]=f.z,d[b]=Math.max(h.x,h.y,h.z),u.attributes.position.needsUpdate=!0,u.attributes.scaleAtt.needsUpdate=!0}})};class ke{constructor(){this.onPointerIndex=[]}onPointerEvent(e,t){const i=this.lead.handlePick([this],e,t);this.onPointerIndex.push(i)}onClick(e){this.onPointerEvent("click",e)}onPointerEnter(e){this.onPointerEvent("enter",e)}onPointerEnterOnStop(e){this.onPointerEvent("enterOnStop",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 ze extends ke{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(i=>{const s=i.userData;i.userData={};const o=i.clone();return i.userData=s,o});{const i=t.userData;t.userData={};const s=t.clone();return t.userData=i,s}}setMaterialList(e,t){const i=this.object3d;if(!i||!i.material)return;this.materialList.origin||(this.materialList.origin=i.material);const s=t==="clone"?this.cloneMaterial():Array.isArray(t)?t.slice():t;return this.materialList[e]=s,s}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 i=this.mList.get(e);if(!i)return;const s=this.object3d;Array.isArray(s.material)&&t!==void 0?s.material[t]=i:s.material=i}useMListByName(e,t){if(!this.mList)return;const i=this.mList.getKeyByName(e);i&&this.useMListById(i,t)}dispose(){super.dispose(),this.mList.rmBaseObjectMap(this,void 0,this.disposeMaterialIfNotUsed)}}class q extends ze{constructor(){super(...arguments),this.key="",this.objectType="BaseObject",this.userData={},this.isPrefab=!1,this.isInstantiate=!1,this.isBloom=!1,this.isBaseObject=!0,this.disposeTrack=!0,this.isDispose=!1}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}lookAt(e){const t=e instanceof a.Vector3?e:new a.Vector3(...e);this.object3d.lookAt(t)}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 i;this.lead.objMap.get(t)?(i=this.lead.objMap.get(t))==null||i.erase():this.object3d.remove(t)})}get visible(){return this.object3d.visible}isActuallyVisible(){if(!this.object3d.visible)return!1;const e=this.parent;return e?e.isActuallyVisible():!0}create(){this.createGroup()}render(){}update(e,t){}resize(e,t){}show(){return this.object3d.visible=!0,this.isActuallyVisible()&&this._enableLayersRecursive(),this}hide(){return this.object3d.visible=!1,this._disableLayersRecursive(),this}_disableLayersRecursive(){var e;(e=this.object3d)==null||e.layers.disable(de),this.children.forEach(t=>{t._disableLayersRecursive()})}_enableLayersRecursive(){var e;this.object3d.visible&&((e=this.object3d)==null||e.layers.enable(de),this.children.forEach(t=>{t._enableLayersRecursive()}))}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 De.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new ue.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new ue.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 ce(this,null,function*(){var u,p;const t=(u=e==null?void 0:e.recursive)!=null?u:!0,i=(p=e==null?void 0:e.cloneMaterial)!=null?p:!1,{objectType:s,objectOptions:o}=this;let l=e==null?void 0:e.create,r,c=(e==null?void 0:e.target)||this.parent;return c===this.lead.prefabGroup&&(c=this.lead.group),this.objectType==="BaseObject"?r=this.lead.createBaseObject(this.object3d.clone(!1),{target:c}):(l===void 0&&(l=d=>{var f;if(this.object3d){if((f=e==null?void 0:e.instancedAttr)!=null&&f.length){const h=e.instancedAttr.length;if(this.object3d instanceof a.Sprite)d.object3d=Ee(this.object3d,h);else{const m=this.object3d,v=i?this.cloneMaterial():m.material;d.object3d=new a.InstancedMesh(m.geometry,v,h)}Le(d.object3d,e==null?void 0:e.instancedAttr)}else d.object3d=this.object3d.clone(!1),i&&d.object3d.material&&(d.object3d.material=this.cloneMaterial());d.object3d.userData.prefab&&delete d.object3d.userData.prefab}}),r=yield this.lead.draw(s,X(k({},o||{}),{create:l,prefab:!1,keyType:this.keyType,key:(e==null?void 0:e.key)||this.keyName,uId:(e==null?void 0:e.uId)||this.keyUId,target:c}))),this.isBloom&&r.enableBloom(),t&&(yield Promise.all(this.children.map(d=>d.instantiate({key:d.keyUId&&d.keyName?`${d.keyName}-${d.keyUId}`:d.keyName,uId:e==null?void 0:e.uId,cloneMaterial:i,target:r})))),r.isInstantiate=!0,r})}erase(){this.lead.erase(this)}handleMaterialChange(e){}enableBloom(e=!0){var t,i,s;if(!((t=this.pencil.composerController)!=null&&t.bloomComposer)){console.warn("err:pencil.options.bloom");return}if(e){this.traverse(o=>{o.enableBloom(!1)});return}this.object3d&&((i=this.pencil.composerController)==null||i.bloomSelection.add(this),this.object3d.layers.enable(ee)),(s=this.pencil.composerController)==null||s.checkBloomComposerActive(),this.isBloom=!0}disableBloom(e=!0){var t,i,s;if(!((t=this.pencil.composerController)!=null&&t.bloomComposer)){console.warn("err:pencil.options.bloom");return}if(e){this.traverse(o=>{o.disableBloom(!1)});return}this.object3d&&((i=this.pencil.composerController)==null||i.bloomSelection.delete(this),this.object3d.layers.disable(ee)),(s=this.pencil.composerController)==null||s.checkBloomComposerActive(),this.isBloom=!1}dispose(){var e,t;if(!this.isDispose&&(this.isDispose=!0,super.dispose(),this.isBloom&&(this.disableBloom(!1),(e=this.pencil.composerController)==null||e.checkBloomComposerActive()),(t=this.lead)==null||t.disableCursor(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 i=new Me;i.disposeMaterial=!1,i.track(this),i.dispose()}}}function _e(n,e){return n.map(t=>{const i=[];let s;return t.forEach(o=>{if(s){const l=_.geoDistance(o,s)*180/Math.PI;if(l>e){const r=_.geoInterpolate(s,o),c=1/Math.ceil(l/e);let u=c;for(;u<1;)i.push(r(u)),u+=c}}i.push(s=o)}),i})}function Ne(n,{minLng:e,maxLng:t,minLat:i,maxLat:s}={}){const o=Math.round(oe(360/n,2)/Math.PI),l=(1+Math.sqrt(5))/2,r=h=>h/l*360%360-180,c=h=>Math.acos(2*h/o-1)/Math.PI*180-90,u=h=>o*(Math.cos((h+90)*Math.PI/180)+1)/2,p=[s!==void 0?Math.ceil(u(s)):0,i!==void 0?Math.floor(u(i)):o-1],d=e===void 0&&t===void 0?()=>!0:e===void 0?h=>h<=t:t===void 0?h=>h>=e:t>=e?h=>h>=e&&h<=t:h=>h>=e||h<=t,f=[];for(let h=p[0];h<=p[1];h++){const m=r(h);d(m)&&f.push([m,c(h)])}return f}function te(n,e,t=!1){return t?_.geoContains(e,n):Be(n,e)}function Re(n,e){const t={type:"Polygon",coordinates:n},[[i,s],[o,l]]=_.geoBounds(t);if(Math.min(Math.abs(o-i),Math.abs(l-s))<e)return[];const r=i>o||l>=89||s<=-89;return Ne(e,{minLng:i,maxLng:o,minLat:s,maxLat:l}).filter(c=>te(c,t,r))}function We(n,{resolution:e=1/0,bbox:t,projection:i}={}){const s=_e(n,e),o=z.merge(s),l=Re(n,e),r=[...o,...l],c={type:"Polygon",coordinates:n},[[u,p],[d,f]]=_.geoBounds(c),h=u>d||f>=89||p<=-89;let m=[];if(h){const g=Ie.geoVoronoi(r).triangles(),S=new Map(r.map(([P,B],E)=>[`${P}-${B}`,E]));g.features.forEach(P=>{const B=P.geometry.coordinates[0].slice(0,3).reverse(),E=[];if(B.forEach(([I,F])=>{const N=`${I}-${F}`;S.has(N)&&E.push(S.get(N))}),E.length===3){if(E.some(I=>I<o.length)){const I=P.properties.circumcenter;if(!te(I,c,h))return}m.push(...E)}})}else if(l.length){const g=Pe.from(r);for(let S=0,P=g.triangles.length;S<P;S+=3){const B=[2,1,0].map(I=>g.triangles[S+I]),E=B.map(I=>r[I]);if(B.some(I=>I<o.length)){const I=[0,1].map(F=>z.mean(E,N=>N[F]));if(!te(I,c,h))continue}m.push(...B)}}else{const{vertices:g,holes:S=[]}=J.flatten(s);m=J(g,S,2)}let v=t?[t[0],t[2]]:z.extent(r,g=>g[0]),b=t?[t[1],t[3]]:z.extent(r,g=>g[1]);if(i){const[g,S]=i([v[0],b[0]]),[P,B]=i([v[1],b[1]]);v=[g,P],b=[-S,-B]}const j=le.scaleLinear(v,[0,1]),C=le.scaleLinear(b,[0,1]),O=r.map(([g,S])=>{if(i){const[P,B]=i([g,S]);return[j(P),C(-B)]}else return[j(g),C(S)]});return{contour:s,triangles:{points:r,indices:m,uvs:O}}}const pe=new a.BufferGeometry().setAttribute?"setAttribute":"addAttribute";function $(n,e,t,i){const s=n.map(o=>o.map(([l,r])=>{if(i){const[c,u]=i([l,r]);return[c,-u,e]}return t?H.polar2Cartesian(l,r,e):[l,r,e]}));return J.flatten(s)}function Ue(n,e,t,i,s){const{vertices:o,holes:l}=$(n,e,i,s),{vertices:r}=$(n,t,i,s),c=z.merge([r,o]),u=Math.round(r.length/3),p=new Set(l);let d=0;const f=[];for(let m=0;m<u;m++){let v=m+1;if(v===u)v=d;else if(p.has(v)){const b=v;v=d,d=b}f.push(m,m+u,v+u),f.push(v+u,v,m)}const h=[];for(let m=1;m>=0;m--)for(let v=0;v<u;v+=1)h.push(v/(u-1),m);return{indices:f,vertices:c,uvs:h,topVerts:r}}function me(n,e,t,i,s,o){return{indices:i?n.indices:n.indices.slice().reverse(),vertices:$([n.points],e,s,o).vertices,uvs:t}}const we=({polygonGeoJson:n,startHeight:e,endHeight:t,curvatureResolution:i=1,cartesian:s=!0,hasSide:o=!0,hasBottom:l=!1,hasTop:r=!1,projection:c,bbox:u})=>{n.forEach(j=>{Ae(j)||j.reverse()});const{contour:p,triangles:d}=We(n,{resolution:i,bbox:u,projection:c});let f={},h;o&&(f=Ue(p,e!=null?e:t,t!=null?t:e,s,c),h=f.topVerts);let m=[];(l||r)&&(m=z.merge(d.uvs));let v={};l&&(v=me(d,e,m,!1,s,c));let b={};return r&&(b=me(d,t,m,!0,s,c)),{contour:p,triangles:d,sideTorso:f,bottomCap:v,topCap:b,topVerts:h}};class Ge extends a.BufferGeometry{constructor(e,t={}){super(),this.type="PolygonBufferGeometry",this.parameters=k({polygonGeoJson:e,startHeight:0,endHeight:1,hasTop:!0,topFirst:!1,hasBottom:!0,hasSide:!0,curvatureResolution:1,cartesian:!0,userDataRsoOffset:0},t);const{endHeight:i,hasTop:s,topFirst:o,hasBottom:l,hasSide:r,cartesian:c,userDataRsoOffset:u,projection:p}=this.parameters,{contour:d,sideTorso:f,topVerts:h,bottomCap:m,topCap:v}=we(k({},this.parameters));let b=[],j=[],C=[],O=0;const A=g=>{const S=Math.round(b.length/3),P=C.length;b=b.concat(g.vertices),j=j.concat(g.uvs),C=C.concat(S?g.indices.map(B=>B+S):g.indices),this.addGroup(P,C.length-P,O++)};s&&o&&A(v),r&&(A(f),this.userData.topVerts=u?$(d,i+u,c,p).vertices:h),l&&A(m),s&&!o&&A(v),this.setIndex(C),this[pe]("position",new a.Float32BufferAttribute(b,3)),this[pe]("uv",new a.Float32BufferAttribute(j,2)),this.computeVertexNormals()}}const qe=`
|
|
5
5
|
#include <fog_pars_fragment>
|
|
6
6
|
#include <logdepthbuf_pars_fragment>
|
|
7
7
|
|
|
@@ -45,7 +45,7 @@ void main() {
|
|
|
45
45
|
#include <tonemapping_fragment>
|
|
46
46
|
#include <colorspace_fragment>
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
`,$e=`
|
|
49
49
|
#include <common>
|
|
50
50
|
#include <logdepthbuf_pars_vertex>
|
|
51
51
|
#include <fog_pars_vertex>
|
|
@@ -137,4 +137,4 @@ void main() {
|
|
|
137
137
|
#include <logdepthbuf_vertex>
|
|
138
138
|
#include <fog_vertex>
|
|
139
139
|
}
|
|
140
|
-
`;class
|
|
140
|
+
`;class Fe extends a.ShaderMaterial{constructor(e={}){const C=e,{lineWidth:t=1,color:i="#ffffff",opacity:s=1,map:o=null,dashOffset:l=0,dashArray:r=0,dashRatio:c=0,sizeAttenuation:u=!0,offsetLoop:p=!0,offset:d=new a.Vector2(0,0),scaleDown:f=0,alphaMap:h=void 0,alphaTest:m=0,repeat:v=new a.Vector2(1,1),resolution:b=new a.Vector2(1,1)}=C,j=ae(C,["lineWidth","color","opacity","map","dashOffset","dashArray","dashRatio","sizeAttenuation","offsetLoop","offset","scaleDown","alphaMap","alphaTest","repeat","resolution"]);super(X(k({},j),{uniforms:{lineWidth:{value:t},color:{value:new a.Color(i)},opacity:{value:s},map:{value:o},useMap:{value:o?1:0},resolution:{value:b},sizeAttenuation:{value:u?1:0},offset:{value:d},offsetLoop:{value:p?1:0},dashArray:{value:r},dashOffset:{value:l},dashRatio:{value:c},useDash:{value:r>0?1:0},scaleDown:{value:f/10},alphaTest:{value:m},alphaMap:{value:h},useAlphaMap:{value:h?1:0},repeat:{value:v}},vertexShader:$e,fragmentShader:qe})),this.type="MeshLineMaterial"}get color(){return this.uniforms.color.value}set color(e){this.uniforms.color.value=new a.Color(e)}get opacity(){var e;return((e=this.uniforms)==null?void 0:e.opacity.value)||1}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}get alphaTest(){return this.uniforms.alphaTest.value}set alphaTest(e){this.uniforms&&(this.uniforms.alphaTest.value=e)}get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e,this.uniforms.useMap.value=e?1:0}get repeat(){return this.uniforms.repeat.value}set repeat(e){this.uniforms.repeat.value.copy(e)}get lineWidth(){return this.uniforms.lineWidth.value}set lineWidth(e){this.uniforms.lineWidth.value=e}get sizeAttenuation(){return this.uniforms.sizeAttenuation.value===1}set sizeAttenuation(e){this.uniforms.sizeAttenuation.value=e?1:0}}const Q=new a.Vector4,ve=new a.Vector3,be=new a.Vector3,M=new a.Vector4,x=new a.Vector4,D=new a.Vector4,Y=new a.Vector3,Z=new a.Matrix4,w=new a.Line3,ye=new a.Vector3,U=new a.Box3,G=new a.Sphere,T=new a.Vector4;let V,L;function ge(n,e,t){return T.set(0,0,-e,1).applyMatrix4(n.projectionMatrix),T.multiplyScalar(1/T.w),T.x=L/t.width,T.y=L/t.height,T.applyMatrix4(n.projectionMatrixInverse),T.multiplyScalar(1/T.w),Math.abs(Math.max(T.x,T.y))}function Xe(n,e){const t=n.matrixWorld,i=n.geometry,s=i.attributes.instanceStart,o=i.attributes.instanceEnd,l=Math.min(i.instanceCount,s.count);for(let r=0,c=l;r<c;r++){w.start.fromBufferAttribute(s,r),w.end.fromBufferAttribute(o,r),w.applyMatrix4(t);const u=new a.Vector3,p=new a.Vector3;V.distanceSqToSegment(w.start,w.end,p,u),p.distanceTo(u)<L*.5&&e.push({point:p,pointOnLine:u,distance:V.origin.distanceTo(p),object:n,face:null,faceIndex:r,uv:null,uv1:null})}}function Ke(n,e,t){const i=e.projectionMatrix,o=n.material.resolution,l=n.matrixWorld,r=n.geometry,c=r.attributes.instanceStart,u=r.attributes.instanceEnd,p=Math.min(r.instanceCount,c.count),d=-e.near;V.at(1,D),D.w=1,D.applyMatrix4(e.matrixWorldInverse),D.applyMatrix4(i),D.multiplyScalar(1/D.w),D.x*=o.x/2,D.y*=o.y/2,D.z=0,Y.copy(D),Z.multiplyMatrices(e.matrixWorldInverse,l);for(let f=0,h=p;f<h;f++){if(M.fromBufferAttribute(c,f),x.fromBufferAttribute(u,f),M.w=1,x.w=1,M.applyMatrix4(Z),x.applyMatrix4(Z),M.z>d&&x.z>d)continue;if(M.z>d){const O=M.z-x.z,A=(M.z-d)/O;M.lerp(x,A)}else if(x.z>d){const O=x.z-M.z,A=(x.z-d)/O;x.lerp(M,A)}M.applyMatrix4(i),x.applyMatrix4(i),M.multiplyScalar(1/M.w),x.multiplyScalar(1/x.w),M.x*=o.x/2,M.y*=o.y/2,x.x*=o.x/2,x.y*=o.y/2,w.start.copy(M),w.start.z=0,w.end.copy(x),w.end.z=0;const v=w.closestPointToPointParameter(Y,!0);w.at(v,ye);const b=a.MathUtils.lerp(M.z,x.z,v),j=b>=-1&&b<=1,C=Y.distanceTo(ye)<L*.5;if(j&&C){w.start.fromBufferAttribute(c,f),w.end.fromBufferAttribute(u,f),w.start.applyMatrix4(l),w.end.applyMatrix4(l);const O=new a.Vector3,A=new a.Vector3;V.distanceSqToSegment(w.start,w.end,A,O),t.push({point:A,pointOnLine:O,distance:V.origin.distanceTo(A),object:n,face:null,faceIndex:f,uv:null,uv1:null})}}}class Qe extends a.Mesh{constructor(e=new Oe.LineSegmentsGeometry,t){super(e,t),this.isLineSegments2=!0,this.type="LineSegments2"}computeLineDistances(){const e=this.geometry,t=e.attributes.instanceStart,i=e.attributes.instanceEnd,s=new Float32Array(2*t.count);for(let l=0,r=0,c=t.count;l<c;l++,r+=2)ve.fromBufferAttribute(t,l),be.fromBufferAttribute(i,l),s[r]=r===0?0:s[r-1],s[r+1]=s[r]+ve.distanceTo(be);const o=new a.InstancedInterleavedBuffer(s,2,1);return e.setAttribute("instanceDistanceStart",new a.InterleavedBufferAttribute(o,1,0)),e.setAttribute("instanceDistanceEnd",new a.InterleavedBufferAttribute(o,1,1)),this}raycast(e,t){const i=this.material.worldUnits,s=e.camera;s===null&&!i&&console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');const o=e.params.Line2!==void 0&&e.params.Line2.threshold||0;V=e.ray;const l=this.matrixWorld,r=this.geometry,c=this.material;L=c.linewidth+o,r.boundingSphere===null&&r.computeBoundingSphere(),G.copy(r.boundingSphere).applyMatrix4(l);let u;if(i)u=L*.5;else{const d=Math.max(s.near,G.distanceToPoint(V.origin));u=ge(s,d,c.resolution)}if(G.radius+=u,V.intersectsSphere(G)===!1)return;r.boundingBox===null&&r.computeBoundingBox(),U.copy(r.boundingBox).applyMatrix4(l);let p;if(i)p=L*.5;else{const d=Math.max(s.near,U.distanceToPoint(V.origin));p=ge(s,d,c.resolution)}U.expandByScalar(p),V.intersectsBox(U)!==!1&&(i?Xe(this,t):Ke(this,s,t))}onBeforeRender(e){const t=this.material.uniforms;t&&t.resolution&&(e.getViewport(Q),this.material.uniforms.resolution.value.set(Q.z,Q.w))}}const y=class y extends q{constructor(e){super(),this.objectType="Node",this.onNodePointerIndex=[],this.options=k({type:"2d"},e)}create(){const{position:e,children:t}=this.options,i=document.createElement("div");this.element=i,t&&i.appendChild(t),this.options.type==="3d"?this.createCSS3DObject(i):this.options.type==="3dSprite"?this.createCSS3DSprite(i):this.createCSS2DObject(i),e&&this.object3d.position.copy(e)}setChildren(e){this.options.children=e,this.element.innerHTML="",this.element.appendChild(e)}showAndEnsureVisible(){const e=this.options.children;e&&(e.style.visibility="hidden",this.show(),setTimeout(()=>{e.style.visibility="",this.ensureVisible()}))}moveElementToViewport(){const e=this.options.children;if(!e)return;const t=e.getBoundingClientRect(),i=window.innerWidth,s=window.innerHeight,o=t.width,l=t.height;let r=0,c=0;o>i?t.left>0&&(r=-t.left):t.left<0?r=-t.left:t.right>i&&(r=i-t.right,t.left+r<0&&(r=-t.left)),l>s?t.top>0&&(c=-t.top):t.top<0?c=-t.top:t.bottom>s&&(c=s-t.bottom,t.top+c<0&&(c=-t.top)),(r!==0||c!==0)&&(e.style.transform=`translate(${r}px, ${c}px)`)}ensureVisible(){const e=this.options.children;e&&(e.style.transform&&(e.style.transform=""),!y.observerMap.has(e)&&(y.sharedObserver||(y.sharedObserver=new IntersectionObserver(t=>{t.forEach(i=>{const s=i.target,o=y.observerMap.get(s);o&&i.isIntersecting&&(o.moveElementToViewport(),y.observerMap.delete(s),y.sharedObserver&&(y.sharedObserver.unobserve(s),y.observerMap.size===0&&(y.sharedObserver.disconnect(),y.sharedObserver=void 0)))})})),y.observerMap.set(e,this),y.sharedObserver.observe(e)))}onPointerEvent(e,t){const i=this.lead.handlePickNode([this],e,t);this.onNodePointerIndex.push(i)}dispose(){const e=this.options.children;e&&y.sharedObserver&&(y.observerMap.delete(e),y.sharedObserver.unobserve(e),y.observerMap.size===0&&(y.sharedObserver.disconnect(),y.sharedObserver=void 0)),this.onNodePointerIndex.forEach(t=>{this.lead.removePickNode(t)}),super.dispose()}};y.observerMap=new Map;let ie=y;exports.BLOOM_SCENE=ee;exports.BaseObject=q;exports.IS_DEV=Te;exports.LineSegments2=Qe;exports.MeshLineMaterial=Fe;exports.Node=ie;exports.PolygonGeometry=Ge;exports.ResourceTracker=Me;exports.getMetas=we;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BufferGeometry, Points, PointsMaterial, type Sprite } from 'three';
|
|
2
2
|
declare const _default: (object3d: Sprite, count?: number) => Points<BufferGeometry<import("three").NormalBufferAttributes, import("three").BufferGeometryEventMap>, PointsMaterial, import("three").Object3DEventMap>;
|
|
3
3
|
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function proposedRaycast(raycaster: any, intersects: any): void;
|