gl-draw 0.17.0-beta.3 → 0.17.0-beta.30
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/constants.d.ts +0 -1
- package/dist/core/BaseObject/PointerEvent.d.ts +1 -0
- package/dist/core/BaseObject/index.d.ts +4 -4
- package/dist/core/Composer.d.ts +5 -5
- package/dist/core/Lead/Pick.d.ts +35 -3
- package/dist/core/Lead/index.d.ts +5 -6
- package/dist/core/Pages/Pages.d.ts +1 -0
- package/dist/core/Pencil.d.ts +3 -3
- package/dist/core/pass/OutputPass.d.ts +1 -2
- package/dist/index.js +2 -2
- package/dist/index.module.js +498 -407
- package/dist/index.module2.js +1097 -0
- package/dist/index2.js +140 -0
- package/dist/objects/extrudePolygon/createGeometry.d.ts +2 -1
- package/dist/objects/group/index.d.ts +1 -0
- package/dist/objects/index.js +1 -1
- package/dist/objects/index.module.js +339 -379
- package/dist/objects/node/index.d.ts +4 -2
- package/dist/objects/pie/index.d.ts +2 -1
- package/dist/plugins/Worker/getAttributes/conicLine.d.ts +2 -3
- package/dist/plugins/Worker/getAttributes/conicPolygon.d.ts +2 -3
- package/dist/plugins/Worker/getAttributes/extrudePolygon.d.ts +2 -4
- package/dist/plugins/Worker/getAttributes/getCoordinatesArr.d.ts +5 -1
- package/dist/plugins/Worker/getAttributes/getMessage.d.ts +1 -1
- package/dist/plugins/Worker/getAttributes/line.d.ts +2 -2
- package/dist/plugins/Worker/getAttributes/line2.d.ts +2 -2
- package/dist/plugins/Worker/getAttributes/splitPolygonsByLongitudeDifference.d.ts +5 -2
- package/dist/plugins/Worker/index.d.ts +3 -3
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/index.module.js +77 -57
- package/package.json +1 -1
- package/dist/WebGPULineSegments2.js +0 -140
- package/dist/WebGPULineSegments2.module.js +0 -1031
package/dist/index2.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";var ye=Object.defineProperty,ge=Object.defineProperties;var Me=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable;var re=Math.pow,te=(n,e,t)=>e in n?ye(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,z=(n,e)=>{for(var t in e||(e={}))ie.call(e,t)&&te(n,t,e[t]);if(U)for(var t of U(e))se.call(e,t)&&te(n,t,e[t]);return n},$=(n,e)=>ge(n,Me(e));var ne=(n,e)=>{var t={};for(var i in n)ie.call(n,i)&&e.indexOf(i)<0&&(t[i]=n[i]);if(n!=null&&U)for(var i of U(n))e.indexOf(i)<0&&se.call(n,i)&&(t[i]=n[i]);return t};var oe=(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 L=require("d3-array"),Y=require("earcut"),a=require("three"),we=require("@turf/boolean-clockwise"),Z=require("./polar2Cartesian.js"),xe=require("delaunator"),Se=require("@turf/boolean-point-in-polygon"),N=require("d3-geo"),je=require("d3-geo-voronoi"),ae=require("d3-scale"),Ce=require("three/examples/jsm/lines/LineSegmentsGeometry"),Ae=require("three/examples/jsm/renderers/CSS2DRenderer"),ce=require("three/examples/jsm/renderers/CSS3DRenderer");require("d3-geo-projection");const le=0,J=1,Pe=!1;class ve{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 R?(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 R)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 Be=(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});return s.onBeforeCompile=o=>{o.vertexShader=`
|
|
2
|
+
attribute float scaleAtt;
|
|
3
|
+
${o.vertexShader.replace("gl_PointSize = size;","gl_PointSize = size * scaleAtt;")}
|
|
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 R 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}create(){this.createGroup()}render(){}update(e,t){}resize(e,t){}show(){return this.object3d.visible=!0,this.traverse(e=>{var t;(t=e.object3d)==null||t.layers.enable(le)}),this}hide(){return this.object3d.visible=!1,this.traverse(e=>{var t;(t=e.object3d)==null||t.layers.disable(le)}),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 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,$(z({},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 ke(n,{resolution:e=1/0,bbox:t,projection:i}={}){const s=Ve(n,e),o=L.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 W=`${I}-${F}`;S.has(W)&&E.push(S.get(W))}),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=>L.mean(E,W=>W[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]]:L.extent(r,g=>g[0]),b=t?[t[1],t[3]]:L.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 ze(n,e,t,i,s){const{vertices:o,holes:l}=q(n,e,i,s),{vertices:r}=q(n,t,i,s),c=L.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}=ke(n,{resolution:i,bbox:u,projection:c});let p={},h;o&&(p=ze(v,e!=null?e:t,t!=null?t:e,s,c),h=p.topVerts);let m=[];(l||r)&&(m=L.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 Le extends a.BufferGeometry{constructor(e,t={}){super(),this.type="PolygonBufferGeometry",this.parameters=z({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(z({},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=`
|
|
5
|
+
#include <fog_pars_fragment>
|
|
6
|
+
#include <logdepthbuf_pars_fragment>
|
|
7
|
+
|
|
8
|
+
uniform float useDash;
|
|
9
|
+
uniform float dashArray;
|
|
10
|
+
uniform float dashOffset;
|
|
11
|
+
uniform float dashRatio;
|
|
12
|
+
uniform sampler2D alphaMap;
|
|
13
|
+
uniform float useAlphaMap;
|
|
14
|
+
|
|
15
|
+
varying vec2 vUV;
|
|
16
|
+
varying vec4 vColor;
|
|
17
|
+
varying float vCounters;
|
|
18
|
+
|
|
19
|
+
uniform sampler2D map;
|
|
20
|
+
uniform float useMap;
|
|
21
|
+
uniform vec2 repeat;
|
|
22
|
+
uniform float offsetLoop;
|
|
23
|
+
uniform float alphaTest;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
void main() {
|
|
28
|
+
#include <logdepthbuf_fragment>
|
|
29
|
+
|
|
30
|
+
vec4 c = vColor;
|
|
31
|
+
|
|
32
|
+
if( useMap == 1. ) c *= texture2D( map, vUV * repeat );
|
|
33
|
+
if( useAlphaMap == 1. ) c.a *= texture2D( alphaMap, vUV * repeat ).r;
|
|
34
|
+
if(offsetLoop!=1.0){
|
|
35
|
+
if(vUV.x>1.0 || vUV.x<0.0){
|
|
36
|
+
c.a = 0.0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (c.a < alphaTest) discard;
|
|
40
|
+
if( useDash == 1. ){
|
|
41
|
+
c.a *= ceil(mod(vCounters + dashOffset, dashArray) - (dashArray * dashRatio));
|
|
42
|
+
}
|
|
43
|
+
gl_FragColor = c;
|
|
44
|
+
#include <fog_fragment>
|
|
45
|
+
#include <tonemapping_fragment>
|
|
46
|
+
#include <colorspace_fragment>
|
|
47
|
+
}
|
|
48
|
+
`,We=`
|
|
49
|
+
#include <common>
|
|
50
|
+
#include <logdepthbuf_pars_vertex>
|
|
51
|
+
#include <fog_pars_vertex>
|
|
52
|
+
|
|
53
|
+
attribute vec3 previous;
|
|
54
|
+
attribute vec3 next;
|
|
55
|
+
attribute float side;
|
|
56
|
+
attribute float width;
|
|
57
|
+
attribute float counters;
|
|
58
|
+
|
|
59
|
+
uniform vec2 resolution;
|
|
60
|
+
uniform float lineWidth;
|
|
61
|
+
uniform vec3 color;
|
|
62
|
+
uniform float opacity;
|
|
63
|
+
uniform float sizeAttenuation;
|
|
64
|
+
uniform float scaleDown;
|
|
65
|
+
uniform vec2 offset;
|
|
66
|
+
|
|
67
|
+
varying vec2 vUV;
|
|
68
|
+
varying vec4 vColor;
|
|
69
|
+
varying float vCounters;
|
|
70
|
+
|
|
71
|
+
vec2 intoScreen(vec4 i) {
|
|
72
|
+
return resolution * (0.5 * i.xy / i.w + 0.5);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void main() {
|
|
76
|
+
float aspect = resolution.y / resolution.x;
|
|
77
|
+
|
|
78
|
+
mat4 m = projectionMatrix * modelViewMatrix;
|
|
79
|
+
|
|
80
|
+
vec4 currentClip = m * vec4( position, 1.0 );
|
|
81
|
+
vec4 prevClip = m * vec4( previous, 1.0 );
|
|
82
|
+
vec4 nextClip = m * vec4( next, 1.0 );
|
|
83
|
+
|
|
84
|
+
vec4 currentNormed = currentClip / currentClip.w;
|
|
85
|
+
vec4 prevNormed = prevClip / prevClip.w;
|
|
86
|
+
vec4 nextNormed = nextClip / nextClip.w;
|
|
87
|
+
|
|
88
|
+
vec2 currentScreen = intoScreen(currentNormed);
|
|
89
|
+
vec2 prevScreen = intoScreen(prevNormed);
|
|
90
|
+
vec2 nextScreen = intoScreen(nextNormed);
|
|
91
|
+
|
|
92
|
+
float actualWidth = lineWidth * width;
|
|
93
|
+
|
|
94
|
+
vec2 dir;
|
|
95
|
+
if(nextScreen == currentScreen) {
|
|
96
|
+
dir = normalize( currentScreen - prevScreen );
|
|
97
|
+
} else if(prevScreen == currentScreen) {
|
|
98
|
+
dir = normalize( nextScreen - currentScreen );
|
|
99
|
+
} else {
|
|
100
|
+
vec2 inDir = currentScreen - prevScreen;
|
|
101
|
+
vec2 outDir = nextScreen - currentScreen;
|
|
102
|
+
vec2 fullDir = nextScreen - prevScreen;
|
|
103
|
+
|
|
104
|
+
if(length(fullDir) > 0.0) {
|
|
105
|
+
dir = normalize(fullDir);
|
|
106
|
+
} else if(length(inDir) > 0.0){
|
|
107
|
+
dir = normalize(inDir);
|
|
108
|
+
} else {
|
|
109
|
+
dir = normalize(outDir);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
vec2 normal = vec2(-dir.y, dir.x);
|
|
114
|
+
|
|
115
|
+
if(sizeAttenuation != 0.0) {
|
|
116
|
+
normal /= currentClip.w;
|
|
117
|
+
normal *= min(resolution.x, resolution.y);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (scaleDown > 0.0) {
|
|
121
|
+
float dist = length(nextNormed - prevNormed);
|
|
122
|
+
normal *= smoothstep(0.0, scaleDown, dist);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
vec2 offsetInScreen = actualWidth * normal * side * 0.5;
|
|
126
|
+
|
|
127
|
+
vec2 withOffsetScreen = currentScreen + offsetInScreen;
|
|
128
|
+
vec3 withOffsetNormed = vec3((2.0 * withOffsetScreen/resolution - 1.0), currentNormed.z);
|
|
129
|
+
|
|
130
|
+
vCounters = counters;
|
|
131
|
+
vColor = vec4( color, opacity );
|
|
132
|
+
vUV = uv;
|
|
133
|
+
vUV=uv+offset;
|
|
134
|
+
|
|
135
|
+
gl_Position = currentClip.w * vec4(withOffsetNormed, 1.0);
|
|
136
|
+
|
|
137
|
+
#include <logdepthbuf_vertex>
|
|
138
|
+
#include <fog_vertex>
|
|
139
|
+
}
|
|
140
|
+
`;class Ue 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:v=!0,offset:d=new a.Vector2(0,0),scaleDown:p=0,alphaMap:h=void 0,alphaTest:m=0,repeat:f=new a.Vector2(1,1),resolution:b=new a.Vector2(1,1)}=C,j=ne(C,["lineWidth","color","opacity","map","dashOffset","dashArray","dashRatio","sizeAttenuation","offsetLoop","offset","scaleDown","alphaMap","alphaTest","repeat","resolution"]);super($(z({},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:v?1:0},dashArray:{value:r},dashOffset:{value:l},dashRatio:{value:c},useDash:{value:r>0?1:0},scaleDown:{value:p/10},alphaTest:{value:m},alphaMap:{value:h},useAlphaMap:{value:h?1:0},repeat:{value:f}},vertexShader:We,fragmentShader:Ne})),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 K=new a.Vector4,he=new a.Vector3,fe=new a.Vector3,M=new a.Vector4,w=new a.Vector4,D=new a.Vector4,Q=new a.Vector3,X=new a.Matrix4,x=new a.Line3,pe=new a.Vector3,_=new a.Box3,G=new a.Sphere,V=new a.Vector4;let T,k;function me(n,e,t){return V.set(0,0,-e,1).applyMatrix4(n.projectionMatrix),V.multiplyScalar(1/V.w),V.x=k/t.width,V.y=k/t.height,V.applyMatrix4(n.projectionMatrixInverse),V.multiplyScalar(1/V.w),Math.abs(Math.max(V.x,V.y))}function _e(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++){x.start.fromBufferAttribute(s,r),x.end.fromBufferAttribute(o,r),x.applyMatrix4(t);const u=new a.Vector3,v=new a.Vector3;T.distanceSqToSegment(x.start,x.end,v,u),v.distanceTo(u)<k*.5&&e.push({point:v,pointOnLine:u,distance:T.origin.distanceTo(v),object:n,face:null,faceIndex:r,uv:null,uv1:null})}}function Ge(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,v=Math.min(r.instanceCount,c.count),d=-e.near;T.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,Q.copy(D),X.multiplyMatrices(e.matrixWorldInverse,l);for(let p=0,h=v;p<h;p++){if(M.fromBufferAttribute(c,p),w.fromBufferAttribute(u,p),M.w=1,w.w=1,M.applyMatrix4(X),w.applyMatrix4(X),M.z>d&&w.z>d)continue;if(M.z>d){const O=M.z-w.z,A=(M.z-d)/O;M.lerp(w,A)}else if(w.z>d){const O=w.z-M.z,A=(w.z-d)/O;w.lerp(M,A)}M.applyMatrix4(i),w.applyMatrix4(i),M.multiplyScalar(1/M.w),w.multiplyScalar(1/w.w),M.x*=o.x/2,M.y*=o.y/2,w.x*=o.x/2,w.y*=o.y/2,x.start.copy(M),x.start.z=0,x.end.copy(w),x.end.z=0;const f=x.closestPointToPointParameter(Q,!0);x.at(f,pe);const b=a.MathUtils.lerp(M.z,w.z,f),j=b>=-1&&b<=1,C=Q.distanceTo(pe)<k*.5;if(j&&C){x.start.fromBufferAttribute(c,p),x.end.fromBufferAttribute(u,p),x.start.applyMatrix4(l),x.end.applyMatrix4(l);const O=new a.Vector3,A=new a.Vector3;T.distanceSqToSegment(x.start,x.end,A,O),t.push({point:A,pointOnLine:O,distance:T.origin.distanceTo(A),object:n,face:null,faceIndex:p,uv:null,uv1:null})}}}class Re extends a.Mesh{constructor(e=new Ce.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)he.fromBufferAttribute(t,l),fe.fromBufferAttribute(i,l),s[r]=r===0?0:s[r-1],s[r+1]=s[r]+he.distanceTo(fe);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;T=e.ray;const l=this.matrixWorld,r=this.geometry,c=this.material;k=c.linewidth+o,r.boundingSphere===null&&r.computeBoundingSphere(),G.copy(r.boundingSphere).applyMatrix4(l);let u;if(i)u=k*.5;else{const d=Math.max(s.near,G.distanceToPoint(T.origin));u=me(s,d,c.resolution)}if(G.radius+=u,T.intersectsSphere(G)===!1)return;r.boundingBox===null&&r.computeBoundingBox(),_.copy(r.boundingBox).applyMatrix4(l);let v;if(i)v=k*.5;else{const d=Math.max(s.near,_.distanceToPoint(T.origin));v=me(s,d,c.resolution)}_.expandByScalar(v),T.intersectsBox(_)!==!1&&(i?_e(this,t):Ge(this,s,t))}onBeforeRender(e){const t=this.material.uniforms;t&&t.resolution&&(e.getViewport(K),this.material.uniforms.resolution.value.set(K.z,K.w))}}const y=class y extends R{constructor(e){super(),this.objectType="Node",this.onNodePointerIndex=[],this.options=z({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 ee=y;exports.BLOOM_SCENE=J;exports.BaseObject=R;exports.IS_DEV=Pe;exports.LineSegments2=Re;exports.MeshLineMaterial=Ue;exports.Node=ee;exports.PolygonGeometry=Le;exports.ResourceTracker=ve;exports.getMetas=be;
|
|
@@ -20,6 +20,7 @@ declare const _default: (options: Options) => {
|
|
|
20
20
|
name: string;
|
|
21
21
|
index: import("three").BufferAttribute | null;
|
|
22
22
|
indirect: import("three/src/renderers/common/IndirectStorageBufferAttribute").default | null;
|
|
23
|
+
indirectOffset: number | number[];
|
|
23
24
|
attributes: import("three").NormalBufferAttributes;
|
|
24
25
|
morphAttributes: {
|
|
25
26
|
position?: Array<import("three").BufferAttribute | import("three").InterleavedBufferAttribute> | undefined;
|
|
@@ -38,7 +39,7 @@ declare const _default: (options: Options) => {
|
|
|
38
39
|
readonly isBufferGeometry: true;
|
|
39
40
|
getIndex(): import("three").BufferAttribute | null;
|
|
40
41
|
setIndex(index: import("three").BufferAttribute | number[] | null): any;
|
|
41
|
-
setIndirect(indirect: import("three/src/renderers/common/IndirectStorageBufferAttribute").default | null): any;
|
|
42
|
+
setIndirect(indirect: import("three/src/renderers/common/IndirectStorageBufferAttribute").default | null, indirectOffset?: number | number[]): any;
|
|
42
43
|
getIndirect(): import("three/src/renderers/common/IndirectStorageBufferAttribute").default | null;
|
|
43
44
|
setAttribute<K extends string>(name: K, attribute: import("three").BufferAttribute | import("three").InterleavedBufferAttribute): any;
|
|
44
45
|
getAttribute<K extends string>(name: K): import("three").BufferAttribute | import("three").InterleavedBufferAttribute;
|
package/dist/objects/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ke=Object.defineProperty,Fe=Object.defineProperties;var Ye=Object.getOwnPropertyDescriptors;var ce=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var Be=(u,e,t)=>e in u?ke(u,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):u[e]=t,E=(u,e)=>{for(var t in e||(e={}))Ee.call(e,t)&&Be(u,t,e[t]);if(ce)for(var t of ce(e))Pe.call(e,t)&&Be(u,t,e[t]);return u},le=(u,e)=>Fe(u,Ye(e));var pe=(u,e)=>{var t={};for(var n in u)Ee.call(u,n)&&e.indexOf(n)<0&&(t[n]=u[n]);if(u!=null&&ce)for(var n of ce(u))e.indexOf(n)<0&&Pe.call(u,n)&&(t[n]=u[n]);return t};var se=(u,e,t)=>new Promise((n,s)=>{var o=r=>{try{p(t.next(r))}catch(f){s(f)}},a=r=>{try{p(t.throw(r))}catch(f){s(f)}},p=r=>r.done?n(r.value):Promise.resolve(r.value).then(o,a);p((t=t.apply(u,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ue=require("three/examples/jsm/lines/LineMaterial"),Re=require("three/examples/jsm/lines/LineSegmentsGeometry"),P=require("../WebGPULineSegments2.js"),c=require("three"),me=require("three/examples/jsm/utils/BufferGeometryUtils"),Ve=require("../uvGenerator.js"),he=require("three-bvh-csg"),Ze=require("three/examples/jsm/lights/RectAreaLightUniformsLib"),$e=require("@tweenjs/tween.js"),Je=require("three/examples/jsm/lines/LineSegments2");function Qe(u){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const t in u)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(u,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>u[t]})}}return e.default=u,Object.freeze(e)}const ee=Qe($e);function D(u,e=0){const t=u[0].index!==null,n=new Set(Object.keys(u[0].attributes)),s=new Set(Object.keys(u[0].morphAttributes)),o={},a={},p=u[0].morphTargetsRelative,r=new c.BufferGeometry;let f=0;for(let i=0;i<u.length;++i){const l=u[i];let y=0;if(t!==(l.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const d in l.attributes){if(!n.has(d))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+'. All geometries must have compatible attributes; make sure "'+d+'" attribute exists among all geometries, or in none of them.'),null;o[d]===void 0&&(o[d]=[]),o[d].push(l.attributes[d]),y++}if(y!==n.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". Make sure all geometries have the same number of attributes."),null;if(p!==l.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const d in l.morphAttributes){if(!s.has(d))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". .morphAttributes must be consistent throughout all geometries."),null;a[d]===void 0&&(a[d]=[]),a[d].push(l.morphAttributes[d])}if(e){let d;if(t)d=l.index.count;else if(l.attributes.position!==void 0)d=l.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". The geometry must have either an index or a position attribute"),null;if(e===1)r.addGroup(f,d,i);else if(e===2&&l.groups.length>0)for(let b of l.groups){let T=b.materialIndex;r.addGroup(f+b.start,Math.min(b.count,d),T)}f+=d}}if(t){let i=0;const l=[];for(let y=0;y<u.length;++y){const d=u[y].index;for(let b=0;b<d.count;++b)l.push(d.getX(b)+i);i+=u[y].attributes.position.count}r.setIndex(l)}for(const i in o){const l=me.mergeAttributes(o[i]);if(!l)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+i+" attribute."),null;r.setAttribute(i,l)}for(const i in a){const l=a[i][0].length;if(l===0)break;r.morphAttributes=r.morphAttributes||{},r.morphAttributes[i]=[];for(let y=0;y<l;++y){const d=[];for(let T=0;T<a[i].length;++T)d.push(a[i][T][y]);const b=me.mergeAttributes(d);if(!b)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+i+" morphAttribute."),null;r.morphAttributes[i].push(b)}}return e===2?me.mergeGroups(r):r}const _e=u=>{const p=u,{coordinate:e,startHeight:t,height:n}=p,s=pe(p,["coordinate","startHeight","height"]);let o=t||0;return typeof t!="undefined"&&typeof n!="undefined"&&(o=t+n),new P.PolygonGeometry([e],le(E({},s),{startHeight:t,endHeight:o}))};class Ke extends P.BaseObject{constructor(e){super(),this.options=E({},e)}create(){const r=this.options,{geometry:e,coordinateArr:t,coordinate:n,material:s,useGroups:o}=r,a=pe(r,["geometry","coordinateArr","coordinate","material","useGroups"]);let p=e;if(!p&&n)p=_e(E({coordinate:n},a));else if(!p&&t){const f=t.map(i=>_e(E({coordinate:i},a)));p=D(f,o!=null?o:0)}this.createMesh(p,s)}}const et={ArcCurve:c.ArcCurve,CatmullRomCurve3:c.CatmullRomCurve3,CubicBezierCurve:c.CubicBezierCurve,CubicBezierCurve3:c.CubicBezierCurve3,EllipseCurve:c.EllipseCurve,LineCurve:c.LineCurve,LineCurve3:c.LineCurve3,QuadraticBezierCurve:c.QuadraticBezierCurve,QuadraticBezierCurve3:c.QuadraticBezierCurve3,SplineCurve:c.SplineCurve};class J extends c.BufferGeometry{constructor(e=new c.Shape([new c.Vector2(.5,.5),new c.Vector2(-.5,.5),new c.Vector2(-.5,-.5),new c.Vector2(.5,-.5)]),t={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:e,options:t},e=Array.isArray(e)?e:[e];const n=this,s=[],o=[];for(let p=0,r=e.length;p<r;p++){const f=e[p];a(f)}this.setAttribute("position",new c.Float32BufferAttribute(s,3)),this.setAttribute("uv",new c.Float32BufferAttribute(o,2)),this.computeVertexNormals();function a(p){var Se,Ae,Me;const r=[],f=t.curveSegments!==void 0?t.curveSegments:12,i=t.steps!==void 0?t.steps:1,l=t.depth!==void 0?t.depth:1;let y=t.bevelEnabled!==void 0?t.bevelEnabled:!0,d=t.bevelThickness!==void 0?t.bevelThickness:.2,b=t.bevelSize!==void 0?t.bevelSize:d-.1,T=t.bevelOffset!==void 0?t.bevelOffset:0,A=t.bevelSegments!==void 0?t.bevelSegments:3;const M=t.extrudePath,B=t.UVGenerator!==void 0?t.UVGenerator:tt,S=(Se=t.hasTop)!=null?Se:!0,V=(Ae=t.hasBottom)!=null?Ae:!0,Q=(Me=t.hasSide)!=null?Me:!0;let H,Y=!1,U,te,ne,N;M&&(H=M.getSpacedPoints(i),Y=!0,y=!1,U=M.computeFrenetFrames(i,!1),te=new c.Vector3,ne=new c.Vector3,N=new c.Vector3),y||(A=0,d=0,b=0,T=0);const ye=p.extractPoints(f);let I=ye.shape;const _=ye.holes;if(!c.ShapeUtils.isClockWise(I)){I=I.reverse();for(let h=0,m=_.length;h<m;h++){const g=_[h];c.ShapeUtils.isClockWise(g)&&(_[h]=g.reverse())}}function be(h){const g=10000000000000001e-36;let w=h[0];for(let x=1;x<=h.length;x++){const L=x%h.length,v=h[L],C=v.x-w.x,G=v.y-w.y,j=C*C+G*G,z=Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(w.x),Math.abs(w.y)),$=g*z*z;if(j<=$){h.splice(L,1),x--;continue}w=v}}be(I),_.forEach(be);const fe=_.length,R=I;for(let h=0;h<fe;h++){const m=_[h];I=I.concat(m)}function K(h,m,g){return m||error("ExtrudeGeometry: vec does not exist"),h.clone().addScaledVector(m,g)}const W=I.length;function xe(h,m,g){let w,x,L;const v=h.x-m.x,C=h.y-m.y,G=g.x-h.x,j=g.y-h.y,z=v*v+C*C,$=v*j-C*G;if(Math.abs($)>Number.EPSILON){const O=Math.sqrt(z),Le=Math.sqrt(G*G+j*j),Te=m.x-C/O,Ce=m.y+v/O,Xe=g.x-j/Le,qe=g.y+G/Le,Ge=((Xe-Te)*j-(qe-Ce)*G)/(v*j-C*G);w=Te+v*Ge-h.x,x=Ce+C*Ge-h.y;const je=w*w+x*x;if(je<=2)return new c.Vector2(w,x);L=Math.sqrt(je/2)}else{let O=!1;v>Number.EPSILON?G>Number.EPSILON&&(O=!0):v<-Number.EPSILON?G<-Number.EPSILON&&(O=!0):Math.sign(C)===Math.sign(j)&&(O=!0),O?(w=-C,x=v,L=Math.sqrt(z)):(w=v,x=C,L=Math.sqrt(z/2))}return new c.Vector2(w/L,x/L)}const ie=[];for(let h=0,m=R.length,g=m-1,w=h+1;h<m;h++,g++,w++)g===m&&(g=0),w===m&&(w=0),ie[h]=xe(R[h],R[g],R[w]);const de=[];let F,oe=ie.concat();for(let h=0,m=fe;h<m;h++){const g=_[h];F=[];for(let w=0,x=g.length,L=x-1,v=w+1;w<x;w++,L++,v++)L===x&&(L=0),v===x&&(v=0),F[w]=xe(g[w],g[L],g[v]);de.push(F),oe=oe.concat(F)}let Z;if(A===0)Z=c.ShapeUtils.triangulateShape(R,_);else{const h=[],m=[];for(let g=0;g<A;g++){const w=g/A,x=d*Math.cos(w*Math.PI/2),L=b*Math.sin(w*Math.PI/2)+T;for(let v=0,C=R.length;v<C;v++){const G=K(R[v],ie[v],L);X(G.x,G.y,-x),w===0&&h.push(G)}for(let v=0,C=fe;v<C;v++){const G=_[v];F=de[v];const j=[];for(let z=0,$=G.length;z<$;z++){const O=K(G[z],F[z],L);X(O.x,O.y,-x),w===0&&j.push(O)}w===0&&m.push(j)}}Z=c.ShapeUtils.triangulateShape(h,m)}const re=Z.length,we=b+T;for(let h=0;h<W;h++){const m=y?K(I[h],oe[h],we):I[h];Y?(ne.copy(U.normals[0]).multiplyScalar(m.x),te.copy(U.binormals[0]).multiplyScalar(m.y),N.copy(H[0]).add(ne).add(te),X(N.x,N.y,N.z)):X(m.x,m.y,0)}for(let h=1;h<=i;h++)for(let m=0;m<W;m++){const g=y?K(I[m],oe[m],we):I[m];Y?(ne.copy(U.normals[h]).multiplyScalar(g.x),te.copy(U.binormals[h]).multiplyScalar(g.y),N.copy(H[h]).add(ne).add(te),X(N.x,N.y,N.z)):X(g.x,g.y,l/i*h)}for(let h=A-1;h>=0;h--){const m=h/A,g=d*Math.cos(m*Math.PI/2),w=b*Math.sin(m*Math.PI/2)+T;for(let x=0,L=R.length;x<L;x++){const v=K(R[x],ie[x],w);X(v.x,v.y,l+g)}for(let x=0,L=_.length;x<L;x++){const v=_[x];F=de[x];for(let C=0,G=v.length;C<G;C++){const j=K(v[C],F[C],w);Y?X(j.x,j.y+H[i-1].y,H[i-1].x+g):X(j.x,j.y,l+g)}}}He(),Q&&Ne();function He(){const h=s.length/3;if(y){let m=0,g=W*m;if(V)for(let w=0;w<re;w++){const x=Z[w];ae(x[2]+g,x[1]+g,x[0]+g)}if(m=i+A*2,g=W*m,S)for(let w=0;w<re;w++){const x=Z[w];ae(x[0]+g,x[1]+g,x[2]+g)}}else{if(V)for(let m=0;m<re;m++){const g=Z[m];ae(g[2],g[1],g[0])}if(S)for(let m=0;m<re;m++){const g=Z[m];ae(g[0]+W*i,g[1]+W*i,g[2]+W*i)}}n.addGroup(h,s.length/3-h,0)}function Ne(){const h=s.length/3;let m=0;ve(R,m),m+=R.length;for(let g=0,w=_.length;g<w;g++){const x=_[g];ve(x,m),m+=x.length}n.addGroup(h,s.length/3-h,1)}function ve(h,m){let g=h.length;for(;--g>=0;){const w=g;let x=g-1;x<0&&(x=h.length-1);for(let L=0,v=i+A*2;L<v;L++){const C=W*L,G=W*(L+1),j=m+w+C,z=m+x+C,$=m+x+G,O=m+w+G;We(j,z,$,O)}}}function X(h,m,g){r.push(h),r.push(m),r.push(g)}function ae(h,m,g){q(h),q(m),q(g);const w=s.length/3,x=B.generateTopUV(n,s,w-3,w-2,w-1);k(x[0]),k(x[1]),k(x[2])}function We(h,m,g,w){q(h),q(m),q(w),q(m),q(g),q(w);const x=s.length/3,L=B.generateSideWallUV(n,s,x-6,x-3,x-2,x-1);k(L[0]),k(L[1]),k(L[3]),k(L[1]),k(L[2]),k(L[3])}function q(h){s.push(r[h*3+0]),s.push(r[h*3+1]),s.push(r[h*3+2])}function k(h){o.push(h.x),o.push(h.y)}}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON(),t=this.parameters.shapes,n=this.parameters.options;return nt(t,n,e)}static fromJSON(e,t){const n=[];for(let o=0,a=e.shapes.length;o<a;o++){const p=t[e.shapes[o]];n.push(p)}const s=e.options.extrudePath;return s!==void 0&&(e.options.extrudePath=new et[s.type]().fromJSON(s)),new J(n,e.options)}}const tt={generateTopUV:function(u,e,t,n,s){const o=e[t*3],a=e[t*3+1],p=e[n*3],r=e[n*3+1],f=e[s*3],i=e[s*3+1];return[new c.Vector2(o,a),new c.Vector2(p,r),new c.Vector2(f,i)]},generateSideWallUV:function(u,e,t,n,s,o){const a=e[t*3],p=e[t*3+1],r=e[t*3+2],f=e[n*3],i=e[n*3+1],l=e[n*3+2],y=e[s*3],d=e[s*3+1],b=e[s*3+2],T=e[o*3],A=e[o*3+1],M=e[o*3+2];return Math.abs(p-i)<Math.abs(a-f)?[new c.Vector2(a,1-r),new c.Vector2(f,1-l),new c.Vector2(y,1-b),new c.Vector2(T,1-M)]:[new c.Vector2(p,1-r),new c.Vector2(i,1-l),new c.Vector2(d,1-b),new c.Vector2(A,1-M)]}};function nt(u,e,t){if(t.shapes=[],Array.isArray(u))for(let n=0,s=u.length;n<s;n++){const o=u[n];t.shapes.push(o.uuid)}else t.shapes.push(u.uuid);return t.options=Object.assign({},e),e.extrudePath!==void 0&&(t.options.extrudePath=e.extrudePath.toJSON()),t}class st extends J{constructor(e,t){super(e,t);const n=new he.Brush(new J(e,le(E({},t),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const s=new c.Box3().setFromObject(n),o=new c.Vector3;s.getSize(o);const a=new c.Vector3(s.min.x+o.x/2,s.min.y+o.y/2,0);let p=t.topSegments,r=t.box3;if(r){r=r.union(s);const M=new c.Vector3;r.getSize(M);const B=Math.max(o.x/M.x,o.y/M.y);p=Math.ceil(t.topSegments*B)}if(p<4)return this;const f=new c.PlaneGeometry(o.x,o.y,p,p),i=new he.Brush(f);i.position.set(a.x,a.y,a.z),i.updateMatrixWorld();const y=new he.Evaluator().evaluate(i,n,he.INTERSECTION),d=y.geometry.getAttribute("position"),b=new c.Float32BufferAttribute(d.count*2,2);for(let M=0;M<d.count;M++){const B=d.getZ(M);d.setZ(M,t.depth+B)}if(r){const M=r.min,B=r.max,S=new c.Vector3().subVectors(B,M);for(let V=0;V<d.count;V++){const Q=d.getX(V),H=d.getY(V),Y=(Q-M.x)/S.x,U=(H-M.y)/S.y;b.setXY(V,Y,U)}y.geometry.setAttribute("uv",b)}d.needsUpdate=!0;const T=new J(e,le(E({},t),{hasTop:!1})),A=D([y.geometry,T],2);this.copy(A.toNonIndexed())}}const ze=u=>{const{split:e,depth:t,points:n,box3:s,hasTop:o,hasBottom:a,hasSide:p,sideRepeat:r,topSegments:f}=u,i=f?st:J,l=new i(new c.Shape(n),{depth:t,bevelEnabled:!1,box3:s,UVGenerator:Ve.getUVGenerator({split:e,box3:s,sideRepeat:r}),hasTop:o,hasBottom:a,hasSide:p,topSegments:f});return Ve.claerUVGenerator(),l};class it extends P.BaseObject{constructor(e){super(),this.options=E({depth:1},e)}create(){return se(this,null,function*(){const{points:e,pointsArr:t,useGroups:n,depth:s,geometry:o,geometryArr:a,material:p,box3:r,split:f,hasTop:i,hasBottom:l,hasSide:y}=this.options,d=Array.isArray(s)?s:[s],b=Array.isArray(r)?r:[r],T=p;let A=o;T||console.log("material is null"),!A&&e?A=ze({points:e,depth:d[0],box3:b[0],split:f,hasTop:i,hasBottom:l,hasSide:y}):!A&&t?A=D(t.map((M,B)=>{var S,V;return ze({points:M,depth:(S=d[B])!=null?S:d[0],box3:(V=b[B])!=null?V:b[0],split:f,hasTop:i,hasBottom:l,hasSide:y})}),n!=null?n:0):!A&&a&&a.length>1?A=D(a,n!=null?n:0):!A&&a&&a.length===1&&([A]=a),this.createMesh(A,T)})}addGeometries(e){const t=this.object3d,n=D([t.geometry,...e]);t.geometry=n}setTextureAnisotropic(e,t){e.anisotropy=t||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const ot=u=>{const{topColor:e,sideColor:t,sideMap:n,createCanvasObjectURL:s,split:o,maxAnisotropy:a}=u;return new Promise(p=>{const r=n?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};r.onload=()=>{const f=o,i=document.createElement("canvas"),l=i.getContext("2d");i.height=r.height/(1-f),i.width=r.width,f&&e&&(l.fillStyle=e,l.fillRect(0,0,r.width,i.height*f)),n&&r instanceof HTMLImageElement?l.drawImage(r,0,i.height*f,r.width,r.height):t&&(l.fillStyle=t,l.fillRect(0,i.height*f,r.width,r.height)),s&&i.toBlob(d=>{console.log(URL.createObjectURL(d))});const y=new c.CanvasTexture(i);p(y)},n?r.src=n:r instanceof HTMLImageElement||r.onload()})};class rt extends P.BaseObject{create(){this.createGroup()}}class at extends P.BaseObject{constructor(e){super(),this.rectAreaLightUniformsLibInit=!1,this.options=e}create(){var t,n,s,o,a,p,r,f,i,l,y,d,b,T,A,M,B;const e=this.options;if(e.type==="AmbientLight"){const S=new c.AmbientLight(e.color);S.name="环境光",this.object3d=S}else if(e.type==="DirectionalLight"){const S=new c.DirectionalLight(e.color,e.intensity);S.name="平行光",S.target.position.set(0,0,0),this.object3d=S,S.target.name="平行光目标",S.shadow.camera.name="平行光阴影相机",S.shadow.camera.userData.directionalLightShadow=!0,this.directionalLight=S}else if(e.type==="PointLight"){const S=new c.PointLight((t=e.color)!=null?t:16777215,(n=e.intensity)!=null?n:1,(s=e.distance)!=null?s:0,(o=e.decay)!=null?o:2);S.name="点光源",this.object3d=S,this.pointLight=S}else if(e.type==="SpotLight"){const S=new c.SpotLight((a=e.color)!=null?a:16777215,(p=e.intensity)!=null?p:1,(r=e.distance)!=null?r:0,(f=e.angle)!=null?f:Math.PI/3,(i=e.penumbra)!=null?i:1,(l=e.decay)!=null?l:2);S.name="聚光灯",this.object3d=S,this.spotLight=S,S.target.name="聚光灯目标"}else if(e.type==="HemisphereLight"){const S=new c.HemisphereLight((y=e.color)!=null?y:16777215,(d=e.groundColor)!=null?d:16777215,(b=e.intensity)!=null?b:1);S.name="半球光",this.object3d=S,this.hemisphereLight=S}else if(e.type==="RectAreaLight"){this.rectAreaLightUniformsLibInit||(Ze.RectAreaLightUniformsLib.init(),this.rectAreaLightUniformsLibInit=!0);const S=new c.RectAreaLight((T=e.color)!=null?T:16777215,(A=e.intensity)!=null?A:1,(M=e.width)!=null?M:10,(B=e.height)!=null?B:10);S.name="矩形区域光",this.object3d=S,this.rectAreaLight=S}}render(){const e=this.object3d;e.target&&this.pencil.scene.add(e.target);const t=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const n=this.spotLight||this.directionalLight;n.position.copy(t),n.target.position.copy(t)}else this.pointLight&&this.pointLight.position.copy(t)}dispose(){const e=this.object3d;e.target&&this.pencil.scene.remove(e.target),super.dispose()}}class De extends c.BufferGeometry{constructor(e=[],t="none",n){super(),this.type="MeshLineGeometry",this.pointCount=0,this._points=[],this.shape="none",this.shapeFunction=s=>1,this.matrixWorld=new c.Matrix4,this.shape=t,n&&(this.shapeFunction=n),e.length>0&&this.setPoints(e)}convertToVector3Array(e){if(typeof e[0]=="number"){const t=[],n=e;for(let s=0;s<n.length;s+=3)t.push(new c.Vector3(n[s],n[s+1],n[s+2]));return t}else return e.map(t=>{if(t instanceof c.Vector2)return new c.Vector3(t.x,t.y,0);if(t instanceof c.Vector3)return t;if(Array.isArray(t)&&t.length===2)return new c.Vector3(t[0],t[1],0);if(Array.isArray(t)&&t.length===3)return new c.Vector3(t[0],t[1],t[2])}).filter(Boolean)}setMatrixWorld(e){this.matrixWorld=e}setPoints(e,t){!e||e.length===0||(this._points=this.convertToVector3Array(e),this.pointCount=this._points.length,t&&(this.shapeFunction=t,this.shape="custom"),this.initializeGeometry(),this.updateGeometry())}initializeGeometry(){const e=new c.BufferAttribute(new Float32Array(this.pointCount*6),3),t=new c.BufferAttribute(new Float32Array(this.pointCount*6),3),n=new c.BufferAttribute(new Float32Array(this.pointCount*6),3),s=new c.BufferAttribute(new Float32Array(this.pointCount*2),1),o=new c.BufferAttribute(new Float32Array(this.pointCount*2),1),a=new c.BufferAttribute(new Float32Array(this.pointCount*2),1),p=new c.BufferAttribute(new Float32Array(this.pointCount*4),2),r=new c.BufferAttribute(new Uint16Array((this.pointCount-1)*6),1);this.shape==="taper"&&(this.shapeFunction=f=>1*Math.pow(4*f*(1-f),1));for(let f=0,i=0,l=0;f<this.pointCount;f+=1,i+=2,l+=6){s.setX(i,f/this.pointCount),s.setX(i+1,f/this.pointCount),o.setX(i,1),o.setX(i+1,-1);const y=this.shape==="none"?1:this.shapeFunction(f/(this.pointCount-1));a.setX(i,y),a.setX(i+1,y);const d=f/(this.pointCount-1);if(p.setXY(i,d,0),p.setXY(i+1,d,1),f<this.pointCount-1){const b=f*2;r.setX(l+0,b+0),r.setX(l+1,b+1),r.setX(l+2,b+2),r.setX(l+3,b+2),r.setX(l+4,b+1),r.setX(l+5,b+3)}}this.setAttribute("position",e),this.setAttribute("previous",t),this.setAttribute("next",n),this.setAttribute("counters",s),this.setAttribute("side",o),this.setAttribute("width",a),this.setAttribute("uv",p),this.setIndex(r)}updateGeometry(){if(!this._points[0])return;const e=this.getAttribute("position"),t=this.getAttribute("previous"),n=this.getAttribute("next");let s=0,o=0,a=0;const p=this._points[0];t.setXYZ(o,p.x,p.y,p.z),o+=1,t.setXYZ(o,p.x,p.y,p.z),o+=1;for(let f=0;f<this.pointCount;f++){const i=this._points[f];e.setXYZ(s,i.x,i.y,i.z),s+=1,e.setXYZ(s,i.x,i.y,i.z),s+=1,f<this.pointCount-1&&(t.setXYZ(o,i.x,i.y,i.z),o+=1,t.setXYZ(o,i.x,i.y,i.z),o+=1),f>0&&f+1<=this.pointCount&&(n.setXYZ(a,i.x,i.y,i.z),a+=1,n.setXYZ(a,i.x,i.y,i.z),a+=1)}const r=this._points[this.pointCount-1];n.setXYZ(a,r.x,r.y,r.z),a+=1,n.setXYZ(a,r.x,r.y,r.z),a+=1,e.needsUpdate=!0,t.needsUpdate=!0,n.needsUpdate=!0,this.computeBoundingSphere(),this.computeBoundingBox()}get points(){return this._points}set points(e){this.setPoints(e)}updatePoints(e,t){const n=this.convertToVector3Array(e);if(n.length!==this.pointCount){console.warn("MeshLineGeometry: Cannot update points with different length. Use setPoints() instead.");return}this._points=n,t&&(this.shapeFunction=t,this.shape="custom",this.initializeGeometry()),this.updateGeometry()}setShape(e,t){this.shape=e,t&&(this.shapeFunction=t),this._points.length>0&&(this.initializeGeometry(),this.updateGeometry())}}function ct(u,e){const t=new c.Matrix4,n=new c.Ray,s=new c.Sphere,o=new c.Vector3,a=this.geometry;if(s.copy(a.boundingSphere),s.applyMatrix4(this.matrixWorld),!u.ray.intersectSphere(s,o))return;t.copy(this.matrixWorld).invert(),n.copy(u.ray).applyMatrix4(t);const p=new c.Vector3,r=new c.Vector3,f=new c.Vector3,i=this instanceof c.LineSegments?2:1,l=a.index,y=a.attributes;if(l!==null){const d=l.array,b=y.position.array,T=y.width.array;for(let A=0,M=d.length-1;A<M;A+=i){const B=d[A],S=d[A+1];p.fromArray(b,B*3),r.fromArray(b,S*3);const V=T[Math.floor(A/3)]!==void 0?T[Math.floor(A/3)]:1,Q=u.params.Line.threshold+this.material.lineWidth*V/2,H=Q*Q;if(n.distanceSqToSegment(p,r,o,f)>H)continue;o.applyMatrix4(this.matrixWorld);const U=u.ray.origin.distanceTo(o);U<u.near||U>u.far||(e.push({distance:U,point:f.clone().applyMatrix4(this.matrixWorld),index:A,face:null,faceIndex:void 0,object:this}),A=M)}}}const ge=u=>{const{setPointWidth:e,nodes:t}=u,n=new De;return n.setPoints(t,e),n},Oe=new WeakMap,ue=new Map;let lt=class extends P.BaseObject{constructor(e={}){super(),this.options=E({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return se(this,null,function*(){const{nodes:e,nodesArr:t,geometry:n,geometryArr:s,material:o,useGroups:a,setPointWidth:p,lineWidthArr:r,materialParameters:f}=this.options;let i=o,l=n;!i&&f&&(i=this.getMaterial(f)),!l&&e?l=ge({nodes:e,setPointWidth:p}):!l&&t?l=D(t.map((y,d)=>{let b=p;return!b&&r&&(b=()=>{var T;return(T=r[d])!=null?T:r[0]}),ge({nodes:y,setPointWidth:b})}),a!=null?a:0):!l&&s&&s.length>1?l=D(s,a!=null?a:0):!l&&s&&s.length===1&&([l]=s),this.createMesh(l,i)})}setGeometry(e,t){const n=ge({nodes:e,setPointWidth:t}),s=this.object3d,o=s.geometry;s.geometry=n,o.dispose()}getMaterial(e){const{width:t,height:n}=this.pencil.getSize(),s=new P.MeshLineMaterial(E({color:new c.Color("#ffffff")},e));return s.uniforms.resolution.value.set(t,n),s}addGeometries(e){const t=this.object3d,n=D([t.geometry,...e]);t.geometry=n}resize(e,t){var n,s;(s=(n=this.material)==null?void 0:n.uniforms)==null||s.resolution.value.set(e,t)}handleMaterialChange(e){if(e){const{width:t,height:n}=this.pencil.getSize();this.resize(t,n)}}animate({duration:e=1e3,delay:t=0,repeat:n=0,lineLoop:s,onRepeat:o,onUpdate:a,onComplete:p,startShow:r}={}){const{offset:f,offsetLoop:i}=this.material.uniforms,l=this.pencil.userData.debugLine?ue:Oe;if(l.get(this.material)&&this.stopAnimation(),e===0)return;const y=s!=null?s:!0;f.value.x=1,i.value=y&&r?1:0;let d=0;const b=new ee.Tween(f.value).to({x:-1},e).delay(t).repeat(n).onUpdate(({x:T})=>{y&&T<=0&&i.value===0&&(i.value=1),a==null||a(T)}).onRepeat(()=>{d+=1,o==null||o(d)}).onComplete(()=>{p==null||p()}).start();l.set(this.material,b),this.material.addEventListener("dispose",()=>{this.stopAnimation()}),this.pencil.userData.debugLine&&console.log("animate",ue.size)}stopAnimation(){const e=this.pencil.userData.debugLine?ue:Oe,t=e.get(this.material);t&&(t.stop(),ee.remove(t),e.delete(this.material),this.material.uniforms.offset.value.x=0,this.material.uniforms.offsetLoop.value=1),this.pencil.userData.debugLine&&console.log("stopAnimation",ue.size)}render(){const{width:e,height:t}=this.pencil.getSize();this.resize(e,t)}};const Ie=u=>{const{points:e}=u,t=e.reduce((s,o,a)=>(a<e.length-1&&s.push(o,e[a+1]),s),[]);return new c.BufferGeometry().setFromPoints(t)};class ht extends P.BaseObject{constructor(e={}){super(),this.options=E({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return se(this,null,function*(){const{points:e,pointsArr:t,geometry:n,geometryArr:s,material:o,useGroups:a,setPointWidth:p,lineWidthArr:r,materialParameters:f,instanceCount:i}=this.options;let l=o,y=n;!l&&f&&(l=this.getMaterial(f)),!y&&e?y=Ie({points:e}):!y&&t?y=D(t.map(b=>Ie({points:b})),a!=null?a:0):!y&&s&&s.length>1?y=D(s,a!=null?a:0):!y&&s&&s.length===1&&([y]=s);const d=new Re.LineSegmentsGeometry().fromLineSegments(new c.LineSegments(y));if(this.pencil.options.WebGPUTHREE){i&&(d.instanceCount=i);const b=new P.LineSegments2(d,l);b.computeLineDistances(),this.object3d=b}else{const b=new Je.LineSegments2(d,l);b.computeLineDistances(),this.object3d=b}})}getMaterial(e){return new Ue.LineMaterial(E({color:new c.Color("#ffffff")},e))}}class ut extends P.BaseObject{constructor(e){super(),this.objectType="Node",this.onNodePointerIndex=[],this.options=E({type:"2d"},e)}create(){const{position:e,children:t}=this.options,n=document.createElement("div");this.element=n,t&&n.appendChild(t),this.options.type==="3d"?this.createCSS3DObject(n):this.options.type==="3dSprite"?this.createCSS3DSprite(n):this.createCSS2DObject(n),e&&this.object3d.position.copy(e)}setChildren(e){this.options.children=e,this.element.innerHTML="",this.element.appendChild(e)}showAndEnsureVisible(){const e=this.options.children;e&&(e.style.visibility="hidden",this.show(),setTimeout(()=>{e.style.visibility="",this.ensureVisible()}))}moveElementToViewport(){const e=this.options.children;if(!e)return;const t=e.getBoundingClientRect(),n=window.innerWidth,s=window.innerHeight;let o=0,a=0;t.left<0?o=-t.left:t.right>n&&(o=n-t.right),t.top<0?a=-t.top:t.bottom>s&&(a=s-t.bottom),t.left+o<0&&(o=-t.left),t.top+a<0&&(a=-t.top),(o!==0||a!==0)&&(e.style.transform=`translate(${o}px, ${a}px)`)}ensureVisible(){const e=this.options.children;if(!e)return;e.style.transform&&(e.style.transform="");const t=new IntersectionObserver(n=>{n.forEach(s=>{s.isIntersecting&&(this.moveElementToViewport(),t.disconnect())})});t.observe(e)}onPointerEvent(e,t){const n=this.lead.handlePickNode([this],e,t);this.onNodePointerIndex.push(n)}dispose(){this.onNodePointerIndex.forEach(e=>{this.lead.removePickNode(e)}),super.dispose()}}class ft extends P.BaseObject{constructor(e){super(),this.options=E({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},e)}create(){return se(this,null,function*(){this.createGroup();const{data:e,maxDepth:t,colors:n,material:s,percentDepth:o,activeIndex:a}=this.options,p=Math.max(...e),r=e.reduce((i,l)=>i+l,0);let f=Math.PI/2;e.forEach((i,l)=>{if(i===0)return;const y=Math.PI*2*(i/r),d=n[l],b=o?t*(i/p):t,T=this.createGeometry(b,y),A=s?s.clone():new c.MeshBasicMaterial({color:d});s&&A.color.set(d);const M=new c.Mesh(T,A);M.userData.depth=b,M.userData.index=l,M.rotateZ(f),f+=y,this.add(M)}),a!==-1&&this.setActive(a)})}createGeometry(e,t){const{outRadius:n,innerRadius:s}=this.options,o=new c.Shape;return o.moveTo(n,0),o.lineTo(s,0),o.absarc(0,0,s,0,t,!1),o.absarc(0,0,n,t,0,!0),new J(o,{curveSegments:48,depth:e,bevelEnabled:!1})}handlePick(e,t=1.3){const{object:n}=this.pencil.pick(e,this.object3d.children)||{},s=n?this.object3d.children.findIndex(o=>o===n):this.options.activeIndex;return this.setActive(s,t)}setActive(e,t=1.3){const n=this.object3d.children[e];if(this.object3d.children.forEach(s=>{if(!(n&&n===s)&&s.scale.z!==1){if(s.userData.levTween)return;s.userData.enTween&&(s.userData.enTween.stop(),s.userData.enTween=null);const o=new ee.Tween(s.scale).to({z:1},100);s.userData.levTween=o,o.start()}}),n){if(n.userData.enTween)return;n.userData.levTween&&(n.userData.levTween.stop(),n.userData.levTween=null);const s=new ee.Tween(n.scale).to({z:t},100);return n.userData.enTween=s,s.start(),n.userData.index}return-1}render(){this.object3d.scale.z=0,new ee.Tween(this.object3d.scale).to({z:1},1e3).easing(ee.Easing.Sinusoidal.InOut).start()}}Object.defineProperty(exports,"Line2Material",{enumerable:!0,get:()=>Ue.LineMaterial});Object.defineProperty(exports,"LineSegmentsGeometry",{enumerable:!0,get:()=>Re.LineSegmentsGeometry});exports.MeshLineMaterial=P.MeshLineMaterial;exports.getConicPolygonGeometry=P.PolygonGeometry;exports.getConicPolygonGeometryMetas=P.getMetas;exports.ConicPolygon=Ke;exports.ExtrudePolygon=it;exports.Group=rt;exports.Light=at;exports.Line=lt;exports.Line2=ht;exports.MeshLineGeometry=De;exports.MeshLineRaycast=ct;exports.Node=ut;exports.Pie=ft;exports.getSplitTexture=ot;
|
|
1
|
+
"use strict";var ke=Object.defineProperty,Fe=Object.defineProperties;var Ye=Object.getOwnPropertyDescriptors;var ce=Object.getOwnPropertySymbols;var Ve=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var Be=(f,e,t)=>e in f?ke(f,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):f[e]=t,O=(f,e)=>{for(var t in e||(e={}))Ve.call(e,t)&&Be(f,t,e[t]);if(ce)for(var t of ce(e))_e.call(e,t)&&Be(f,t,e[t]);return f},le=(f,e)=>Fe(f,Ye(e));var me=(f,e)=>{var t={};for(var n in f)Ve.call(f,n)&&e.indexOf(n)<0&&(t[n]=f[n]);if(f!=null&&ce)for(var n of ce(f))e.indexOf(n)<0&&_e.call(f,n)&&(t[n]=f[n]);return t};var se=(f,e,t)=>new Promise((n,s)=>{var r=o=>{try{m(t.next(o))}catch(u){s(u)}},c=o=>{try{m(t.throw(o))}catch(u){s(u)}},m=o=>o.done?n(o.value):Promise.resolve(o.value).then(r,c);m((t=t.apply(f,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ue=require("three/examples/jsm/lines/LineMaterial"),Re=require("three/examples/jsm/lines/LineSegmentsGeometry"),V=require("../index2.js"),a=require("three"),pe=require("three/examples/jsm/utils/BufferGeometryUtils"),Ee=require("../uvGenerator.js"),he=require("three-bvh-csg"),Ze=require("three/examples/jsm/lights/RectAreaLightUniformsLib"),$e=require("@tweenjs/tween.js"),Je=require("three/examples/jsm/lines/LineSegments2");function Qe(f){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(f){for(const t in f)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(f,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>f[t]})}}return e.default=f,Object.freeze(e)}const ee=Qe($e);function D(f,e=0){const t=f[0].index!==null,n=new Set(Object.keys(f[0].attributes)),s=new Set(Object.keys(f[0].morphAttributes)),r={},c={},m=f[0].morphTargetsRelative,o=new a.BufferGeometry;let u=0;for(let i=0;i<f.length;++i){const l=f[i];let y=0;if(t!==(l.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const d in l.attributes){if(!n.has(d))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+'. All geometries must have compatible attributes; make sure "'+d+'" attribute exists among all geometries, or in none of them.'),null;r[d]===void 0&&(r[d]=[]),r[d].push(l.attributes[d]),y++}if(y!==n.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". Make sure all geometries have the same number of attributes."),null;if(m!==l.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const d in l.morphAttributes){if(!s.has(d))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". .morphAttributes must be consistent throughout all geometries."),null;c[d]===void 0&&(c[d]=[]),c[d].push(l.morphAttributes[d])}if(e){let d;if(t)d=l.index.count;else if(l.attributes.position!==void 0)d=l.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". The geometry must have either an index or a position attribute"),null;if(e===1)o.addGroup(u,d,i);else if(e===2&&l.groups.length>0)for(let b of l.groups){let G=b.materialIndex;o.addGroup(u+b.start,Math.min(b.count,d),G)}u+=d}}if(t){let i=0;const l=[];for(let y=0;y<f.length;++y){const d=f[y].index;for(let b=0;b<d.count;++b)l.push(d.getX(b)+i);i+=f[y].attributes.position.count}o.setIndex(l)}for(const i in r){const l=pe.mergeAttributes(r[i]);if(!l)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+i+" attribute."),null;o.setAttribute(i,l)}for(const i in c){const l=c[i][0].length;if(l===0)break;o.morphAttributes=o.morphAttributes||{},o.morphAttributes[i]=[];for(let y=0;y<l;++y){const d=[];for(let G=0;G<c[i].length;++G)d.push(c[i][G][y]);const b=pe.mergeAttributes(d);if(!b)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+i+" morphAttribute."),null;o.morphAttributes[i].push(b)}}return e===2?pe.mergeGroups(o):o}const Pe=f=>{const m=f,{coordinate:e,startHeight:t,height:n}=m,s=me(m,["coordinate","startHeight","height"]);let r=t||0;return typeof t!="undefined"&&typeof n!="undefined"&&(r=t+n),new V.PolygonGeometry([e],le(O({},s),{startHeight:t,endHeight:r}))};class Ke extends V.BaseObject{constructor(e){super(),this.options=O({},e)}create(){const o=this.options,{geometry:e,coordinateArr:t,coordinate:n,material:s,useGroups:r}=o,c=me(o,["geometry","coordinateArr","coordinate","material","useGroups"]);let m=e;if(!m&&n)m=Pe(O({coordinate:n},c));else if(!m&&t){const u=t.map(i=>Pe(O({coordinate:i},c)));m=D(u,r!=null?r:0)}this.createMesh(m,s)}}const et={ArcCurve:a.ArcCurve,CatmullRomCurve3:a.CatmullRomCurve3,CubicBezierCurve:a.CubicBezierCurve,CubicBezierCurve3:a.CubicBezierCurve3,EllipseCurve:a.EllipseCurve,LineCurve:a.LineCurve,LineCurve3:a.LineCurve3,QuadraticBezierCurve:a.QuadraticBezierCurve,QuadraticBezierCurve3:a.QuadraticBezierCurve3,SplineCurve:a.SplineCurve};class J extends a.BufferGeometry{constructor(e=new a.Shape([new a.Vector2(.5,.5),new a.Vector2(-.5,.5),new a.Vector2(-.5,-.5),new a.Vector2(.5,-.5)]),t={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:e,options:t},e=Array.isArray(e)?e:[e];const n=this,s=[],r=[];for(let m=0,o=e.length;m<o;m++){const u=e[m];c(u)}this.setAttribute("position",new a.Float32BufferAttribute(s,3)),this.setAttribute("uv",new a.Float32BufferAttribute(r,2)),this.computeVertexNormals();function c(m){var Se,Ae,Me;const o=[],u=t.curveSegments!==void 0?t.curveSegments:12,i=t.steps!==void 0?t.steps:1,l=t.depth!==void 0?t.depth:1;let y=t.bevelEnabled!==void 0?t.bevelEnabled:!0,d=t.bevelThickness!==void 0?t.bevelThickness:.2,b=t.bevelSize!==void 0?t.bevelSize:d-.1,G=t.bevelOffset!==void 0?t.bevelOffset:0,A=t.bevelSegments!==void 0?t.bevelSegments:3;const M=t.extrudePath,B=t.UVGenerator!==void 0?t.UVGenerator:tt,S=(Se=t.hasTop)!=null?Se:!0,_=(Ae=t.hasBottom)!=null?Ae:!0,Q=(Me=t.hasSide)!=null?Me:!0;let H,Y=!1,U,te,ne,X;M&&(H=M.getSpacedPoints(i),Y=!0,y=!1,U=M.computeFrenetFrames(i,!1),te=new a.Vector3,ne=new a.Vector3,X=new a.Vector3),y||(A=0,d=0,b=0,G=0);const ye=m.extractPoints(u);let I=ye.shape;const E=ye.holes;if(!a.ShapeUtils.isClockWise(I)){I=I.reverse();for(let h=0,p=E.length;h<p;h++){const g=E[h];a.ShapeUtils.isClockWise(g)&&(E[h]=g.reverse())}}function be(h){const g=10000000000000001e-36;let w=h[0];for(let x=1;x<=h.length;x++){const L=x%h.length,v=h[L],T=v.x-w.x,C=v.y-w.y,j=T*T+C*C,P=Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(w.x),Math.abs(w.y)),$=g*P*P;if(j<=$){h.splice(L,1),x--;continue}w=v}}be(I),E.forEach(be);const fe=E.length,R=I;for(let h=0;h<fe;h++){const p=E[h];I=I.concat(p)}function K(h,p,g){return p||error("ExtrudeGeometry: vec does not exist"),h.clone().addScaledVector(p,g)}const W=I.length;function xe(h,p,g){let w,x,L;const v=h.x-p.x,T=h.y-p.y,C=g.x-h.x,j=g.y-h.y,P=v*v+T*T,$=v*j-T*C;if(Math.abs($)>Number.EPSILON){const z=Math.sqrt(P),Le=Math.sqrt(C*C+j*j),Ge=p.x-T/z,Te=p.y+v/z,qe=g.x-j/Le,Ne=g.y+C/Le,Ce=((qe-Ge)*j-(Ne-Te)*C)/(v*j-T*C);w=Ge+v*Ce-h.x,x=Te+T*Ce-h.y;const je=w*w+x*x;if(je<=2)return new a.Vector2(w,x);L=Math.sqrt(je/2)}else{let z=!1;v>Number.EPSILON?C>Number.EPSILON&&(z=!0):v<-Number.EPSILON?C<-Number.EPSILON&&(z=!0):Math.sign(T)===Math.sign(j)&&(z=!0),z?(w=-T,x=v,L=Math.sqrt(P)):(w=v,x=T,L=Math.sqrt(P/2))}return new a.Vector2(w/L,x/L)}const ie=[];for(let h=0,p=R.length,g=p-1,w=h+1;h<p;h++,g++,w++)g===p&&(g=0),w===p&&(w=0),ie[h]=xe(R[h],R[g],R[w]);const de=[];let F,oe=ie.concat();for(let h=0,p=fe;h<p;h++){const g=E[h];F=[];for(let w=0,x=g.length,L=x-1,v=w+1;w<x;w++,L++,v++)L===x&&(L=0),v===x&&(v=0),F[w]=xe(g[w],g[L],g[v]);de.push(F),oe=oe.concat(F)}let Z;if(A===0)Z=a.ShapeUtils.triangulateShape(R,E);else{const h=[],p=[];for(let g=0;g<A;g++){const w=g/A,x=d*Math.cos(w*Math.PI/2),L=b*Math.sin(w*Math.PI/2)+G;for(let v=0,T=R.length;v<T;v++){const C=K(R[v],ie[v],L);q(C.x,C.y,-x),w===0&&h.push(C)}for(let v=0,T=fe;v<T;v++){const C=E[v];F=de[v];const j=[];for(let P=0,$=C.length;P<$;P++){const z=K(C[P],F[P],L);q(z.x,z.y,-x),w===0&&j.push(z)}w===0&&p.push(j)}}Z=a.ShapeUtils.triangulateShape(h,p)}const re=Z.length,we=b+G;for(let h=0;h<W;h++){const p=y?K(I[h],oe[h],we):I[h];Y?(ne.copy(U.normals[0]).multiplyScalar(p.x),te.copy(U.binormals[0]).multiplyScalar(p.y),X.copy(H[0]).add(ne).add(te),q(X.x,X.y,X.z)):q(p.x,p.y,0)}for(let h=1;h<=i;h++)for(let p=0;p<W;p++){const g=y?K(I[p],oe[p],we):I[p];Y?(ne.copy(U.normals[h]).multiplyScalar(g.x),te.copy(U.binormals[h]).multiplyScalar(g.y),X.copy(H[h]).add(ne).add(te),q(X.x,X.y,X.z)):q(g.x,g.y,l/i*h)}for(let h=A-1;h>=0;h--){const p=h/A,g=d*Math.cos(p*Math.PI/2),w=b*Math.sin(p*Math.PI/2)+G;for(let x=0,L=R.length;x<L;x++){const v=K(R[x],ie[x],w);q(v.x,v.y,l+g)}for(let x=0,L=E.length;x<L;x++){const v=E[x];F=de[x];for(let T=0,C=v.length;T<C;T++){const j=K(v[T],F[T],w);Y?q(j.x,j.y+H[i-1].y,H[i-1].x+g):q(j.x,j.y,l+g)}}}He(),Q&&Xe();function He(){const h=s.length/3;if(y){let p=0,g=W*p;if(_)for(let w=0;w<re;w++){const x=Z[w];ae(x[2]+g,x[1]+g,x[0]+g)}if(p=i+A*2,g=W*p,S)for(let w=0;w<re;w++){const x=Z[w];ae(x[0]+g,x[1]+g,x[2]+g)}}else{if(_)for(let p=0;p<re;p++){const g=Z[p];ae(g[2],g[1],g[0])}if(S)for(let p=0;p<re;p++){const g=Z[p];ae(g[0]+W*i,g[1]+W*i,g[2]+W*i)}}n.addGroup(h,s.length/3-h,0)}function Xe(){const h=s.length/3;let p=0;ve(R,p),p+=R.length;for(let g=0,w=E.length;g<w;g++){const x=E[g];ve(x,p),p+=x.length}n.addGroup(h,s.length/3-h,1)}function ve(h,p){let g=h.length;for(;--g>=0;){const w=g;let x=g-1;x<0&&(x=h.length-1);for(let L=0,v=i+A*2;L<v;L++){const T=W*L,C=W*(L+1),j=p+w+T,P=p+x+T,$=p+x+C,z=p+w+C;We(j,P,$,z)}}}function q(h,p,g){o.push(h),o.push(p),o.push(g)}function ae(h,p,g){N(h),N(p),N(g);const w=s.length/3,x=B.generateTopUV(n,s,w-3,w-2,w-1);k(x[0]),k(x[1]),k(x[2])}function We(h,p,g,w){N(h),N(p),N(w),N(p),N(g),N(w);const x=s.length/3,L=B.generateSideWallUV(n,s,x-6,x-3,x-2,x-1);k(L[0]),k(L[1]),k(L[3]),k(L[1]),k(L[2]),k(L[3])}function N(h){s.push(o[h*3+0]),s.push(o[h*3+1]),s.push(o[h*3+2])}function k(h){r.push(h.x),r.push(h.y)}}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON(),t=this.parameters.shapes,n=this.parameters.options;return nt(t,n,e)}static fromJSON(e,t){const n=[];for(let r=0,c=e.shapes.length;r<c;r++){const m=t[e.shapes[r]];n.push(m)}const s=e.options.extrudePath;return s!==void 0&&(e.options.extrudePath=new et[s.type]().fromJSON(s)),new J(n,e.options)}}const tt={generateTopUV:function(f,e,t,n,s){const r=e[t*3],c=e[t*3+1],m=e[n*3],o=e[n*3+1],u=e[s*3],i=e[s*3+1];return[new a.Vector2(r,c),new a.Vector2(m,o),new a.Vector2(u,i)]},generateSideWallUV:function(f,e,t,n,s,r){const c=e[t*3],m=e[t*3+1],o=e[t*3+2],u=e[n*3],i=e[n*3+1],l=e[n*3+2],y=e[s*3],d=e[s*3+1],b=e[s*3+2],G=e[r*3],A=e[r*3+1],M=e[r*3+2];return Math.abs(m-i)<Math.abs(c-u)?[new a.Vector2(c,1-o),new a.Vector2(u,1-l),new a.Vector2(y,1-b),new a.Vector2(G,1-M)]:[new a.Vector2(m,1-o),new a.Vector2(i,1-l),new a.Vector2(d,1-b),new a.Vector2(A,1-M)]}};function nt(f,e,t){if(t.shapes=[],Array.isArray(f))for(let n=0,s=f.length;n<s;n++){const r=f[n];t.shapes.push(r.uuid)}else t.shapes.push(f.uuid);return t.options=Object.assign({},e),e.extrudePath!==void 0&&(t.options.extrudePath=e.extrudePath.toJSON()),t}class st extends J{constructor(e,t){super(e,t);const n=new he.Brush(new J(e,le(O({},t),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const s=new a.Box3().setFromObject(n),r=new a.Vector3;s.getSize(r);const c=new a.Vector3(s.min.x+r.x/2,s.min.y+r.y/2,0);let m=t.topSegments,o=t.box3;if(o){o=o.union(s);const M=new a.Vector3;o.getSize(M);const B=Math.max(r.x/M.x,r.y/M.y);m=Math.ceil(t.topSegments*B)}if(m<4)return this;const u=new a.PlaneGeometry(r.x,r.y,m,m),i=new he.Brush(u);i.position.set(c.x,c.y,c.z),i.updateMatrixWorld();const y=new he.Evaluator().evaluate(i,n,he.INTERSECTION),d=y.geometry.getAttribute("position"),b=new a.Float32BufferAttribute(d.count*2,2);for(let M=0;M<d.count;M++){const B=d.getZ(M);d.setZ(M,t.depth+B)}if(o){const M=o.min,B=o.max,S=new a.Vector3().subVectors(B,M);for(let _=0;_<d.count;_++){const Q=d.getX(_),H=d.getY(_),Y=(Q-M.x)/S.x,U=(H-M.y)/S.y;b.setXY(_,Y,U)}y.geometry.setAttribute("uv",b)}d.needsUpdate=!0;const G=new J(e,le(O({},t),{hasTop:!1})),A=D([y.geometry,G],2);this.copy(A.toNonIndexed())}}const ze=f=>{const{split:e,depth:t,points:n,box3:s,hasTop:r,hasBottom:c,hasSide:m,sideRepeat:o,topSegments:u}=f,i=u?st:J,l=new i(new a.Shape(n),{depth:t,bevelEnabled:!1,box3:s,UVGenerator:Ee.getUVGenerator({split:e,box3:s,sideRepeat:o}),hasTop:r,hasBottom:c,hasSide:m,topSegments:u});return Ee.claerUVGenerator(),l};class it extends V.BaseObject{constructor(e){super(),this.options=O({depth:1},e)}create(){return se(this,null,function*(){const{points:e,pointsArr:t,useGroups:n,depth:s,geometry:r,geometryArr:c,material:m,box3:o,split:u,hasTop:i,hasBottom:l,hasSide:y}=this.options,d=Array.isArray(s)?s:[s],b=Array.isArray(o)?o:[o],G=m;let A=r;G||console.log("material is null"),!A&&e?A=ze({points:e,depth:d[0],box3:b[0],split:u,hasTop:i,hasBottom:l,hasSide:y}):!A&&t?A=D(t.map((M,B)=>{var S,_;return ze({points:M,depth:(S=d[B])!=null?S:d[0],box3:(_=b[B])!=null?_:b[0],split:u,hasTop:i,hasBottom:l,hasSide:y})}),n!=null?n:0):!A&&c&&c.length>1?A=D(c,n!=null?n:0):!A&&c&&c.length===1&&([A]=c),this.createMesh(A,G)})}addGeometries(e){const t=this.object3d,n=D([t.geometry,...e]);t.geometry=n}setTextureAnisotropic(e,t){e.anisotropy=t||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const ot=f=>{const{topColor:e,sideColor:t,sideMap:n,createCanvasObjectURL:s,split:r,maxAnisotropy:c}=f;return new Promise(m=>{const o=n?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};o.onload=()=>{const u=r,i=document.createElement("canvas"),l=i.getContext("2d");i.height=o.height/(1-u),i.width=o.width,u&&e&&(l.fillStyle=e,l.fillRect(0,0,o.width,i.height*u)),n&&o instanceof HTMLImageElement?l.drawImage(o,0,i.height*u,o.width,o.height):t&&(l.fillStyle=t,l.fillRect(0,i.height*u,o.width,o.height)),s&&i.toBlob(d=>{console.log(URL.createObjectURL(d))});const y=new a.CanvasTexture(i);m(y)},n?o.src=n:o instanceof HTMLImageElement||o.onload()})};class rt extends V.BaseObject{create(){this.createGroup()}render(){this.object3d.raycast=(e,t)=>e.intersectObjects(this.object3d.children,!0,t)}}class at extends V.BaseObject{constructor(e){super(),this.rectAreaLightUniformsLibInit=!1,this.options=e}create(){var t,n,s,r,c,m,o,u,i,l,y,d,b,G,A,M,B;const e=this.options;if(e.type==="AmbientLight"){const S=new a.AmbientLight(e.color);S.name="环境光",this.object3d=S}else if(e.type==="DirectionalLight"){const S=new a.DirectionalLight(e.color,e.intensity);S.name="平行光",S.target.position.set(0,0,0),this.object3d=S,S.target.name="平行光目标",S.shadow.camera.name="平行光阴影相机",S.shadow.camera.userData.directionalLightShadow=!0,this.directionalLight=S}else if(e.type==="PointLight"){const S=new a.PointLight((t=e.color)!=null?t:16777215,(n=e.intensity)!=null?n:1,(s=e.distance)!=null?s:0,(r=e.decay)!=null?r:2);S.name="点光源",this.object3d=S,this.pointLight=S}else if(e.type==="SpotLight"){const S=new a.SpotLight((c=e.color)!=null?c:16777215,(m=e.intensity)!=null?m:1,(o=e.distance)!=null?o:0,(u=e.angle)!=null?u:Math.PI/3,(i=e.penumbra)!=null?i:1,(l=e.decay)!=null?l:2);S.name="聚光灯",this.object3d=S,this.spotLight=S,S.target.name="聚光灯目标"}else if(e.type==="HemisphereLight"){const S=new a.HemisphereLight((y=e.color)!=null?y:16777215,(d=e.groundColor)!=null?d:16777215,(b=e.intensity)!=null?b:1);S.name="半球光",this.object3d=S,this.hemisphereLight=S}else if(e.type==="RectAreaLight"){this.rectAreaLightUniformsLibInit||(Ze.RectAreaLightUniformsLib.init(),this.rectAreaLightUniformsLibInit=!0);const S=new a.RectAreaLight((G=e.color)!=null?G:16777215,(A=e.intensity)!=null?A:1,(M=e.width)!=null?M:10,(B=e.height)!=null?B:10);S.name="矩形区域光",this.object3d=S,this.rectAreaLight=S}}render(){const e=this.object3d;e.target&&this.pencil.scene.add(e.target);const t=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const n=this.spotLight||this.directionalLight;n.position.copy(t),n.target.position.copy(t)}else this.pointLight&&this.pointLight.position.copy(t)}dispose(){const e=this.object3d;e.target&&this.pencil.scene.remove(e.target),super.dispose()}}class De extends a.BufferGeometry{constructor(e=[],t="none",n){super(),this.type="MeshLineGeometry",this.pointCount=0,this._points=[],this.shape="none",this.shapeFunction=s=>1,this.matrixWorld=new a.Matrix4,this.shape=t,n&&(this.shapeFunction=n),e.length>0&&this.setPoints(e)}convertToVector3Array(e){if(typeof e[0]=="number"){const t=[],n=e;for(let s=0;s<n.length;s+=3)t.push(new a.Vector3(n[s],n[s+1],n[s+2]));return t}else return e.map(t=>{if(t instanceof a.Vector2)return new a.Vector3(t.x,t.y,0);if(t instanceof a.Vector3)return t;if(Array.isArray(t)&&t.length===2)return new a.Vector3(t[0],t[1],0);if(Array.isArray(t)&&t.length===3)return new a.Vector3(t[0],t[1],t[2])}).filter(Boolean)}setMatrixWorld(e){this.matrixWorld=e}setPoints(e,t){!e||e.length===0||(this._points=this.convertToVector3Array(e),this.pointCount=this._points.length,t&&(this.shapeFunction=t,this.shape="custom"),this.initializeGeometry(),this.updateGeometry())}initializeGeometry(){const e=new a.BufferAttribute(new Float32Array(this.pointCount*6),3),t=new a.BufferAttribute(new Float32Array(this.pointCount*6),3),n=new a.BufferAttribute(new Float32Array(this.pointCount*6),3),s=new a.BufferAttribute(new Float32Array(this.pointCount*2),1),r=new a.BufferAttribute(new Float32Array(this.pointCount*2),1),c=new a.BufferAttribute(new Float32Array(this.pointCount*2),1),m=new a.BufferAttribute(new Float32Array(this.pointCount*4),2),o=new a.BufferAttribute(new Uint16Array((this.pointCount-1)*6),1);this.shape==="taper"&&(this.shapeFunction=u=>1*Math.pow(4*u*(1-u),1));for(let u=0,i=0,l=0;u<this.pointCount;u+=1,i+=2,l+=6){s.setX(i,u/this.pointCount),s.setX(i+1,u/this.pointCount),r.setX(i,1),r.setX(i+1,-1);const y=this.shape==="none"?1:this.shapeFunction(u/(this.pointCount-1));c.setX(i,y),c.setX(i+1,y);const d=u/(this.pointCount-1);if(m.setXY(i,d,0),m.setXY(i+1,d,1),u<this.pointCount-1){const b=u*2;o.setX(l+0,b+0),o.setX(l+1,b+1),o.setX(l+2,b+2),o.setX(l+3,b+2),o.setX(l+4,b+1),o.setX(l+5,b+3)}}this.setAttribute("position",e),this.setAttribute("previous",t),this.setAttribute("next",n),this.setAttribute("counters",s),this.setAttribute("side",r),this.setAttribute("width",c),this.setAttribute("uv",m),this.setIndex(o)}updateGeometry(){if(!this._points[0])return;const e=this.getAttribute("position"),t=this.getAttribute("previous"),n=this.getAttribute("next");let s=0,r=0,c=0;const m=this._points[0];t.setXYZ(r,m.x,m.y,m.z),r+=1,t.setXYZ(r,m.x,m.y,m.z),r+=1;for(let u=0;u<this.pointCount;u++){const i=this._points[u];e.setXYZ(s,i.x,i.y,i.z),s+=1,e.setXYZ(s,i.x,i.y,i.z),s+=1,u<this.pointCount-1&&(t.setXYZ(r,i.x,i.y,i.z),r+=1,t.setXYZ(r,i.x,i.y,i.z),r+=1),u>0&&u+1<=this.pointCount&&(n.setXYZ(c,i.x,i.y,i.z),c+=1,n.setXYZ(c,i.x,i.y,i.z),c+=1)}const o=this._points[this.pointCount-1];n.setXYZ(c,o.x,o.y,o.z),c+=1,n.setXYZ(c,o.x,o.y,o.z),c+=1,e.needsUpdate=!0,t.needsUpdate=!0,n.needsUpdate=!0,this.computeBoundingSphere(),this.computeBoundingBox()}get points(){return this._points}set points(e){this.setPoints(e)}updatePoints(e,t){const n=this.convertToVector3Array(e);if(n.length!==this.pointCount){console.warn("MeshLineGeometry: Cannot update points with different length. Use setPoints() instead.");return}this._points=n,t&&(this.shapeFunction=t,this.shape="custom",this.initializeGeometry()),this.updateGeometry()}setShape(e,t){this.shape=e,t&&(this.shapeFunction=t),this._points.length>0&&(this.initializeGeometry(),this.updateGeometry())}}function ct(f,e){const t=new a.Matrix4,n=new a.Ray,s=new a.Sphere,r=new a.Vector3,c=this.geometry;if(s.copy(c.boundingSphere),s.applyMatrix4(this.matrixWorld),!f.ray.intersectSphere(s,r))return;t.copy(this.matrixWorld).invert(),n.copy(f.ray).applyMatrix4(t);const m=new a.Vector3,o=new a.Vector3,u=new a.Vector3,i=this instanceof a.LineSegments?2:1,l=c.index,y=c.attributes;if(l!==null){const d=l.array,b=y.position.array,G=y.width.array;for(let A=0,M=d.length-1;A<M;A+=i){const B=d[A],S=d[A+1];m.fromArray(b,B*3),o.fromArray(b,S*3);const _=G[Math.floor(A/3)]!==void 0?G[Math.floor(A/3)]:1,Q=f.params.Line.threshold+this.material.lineWidth*_/2,H=Q*Q;if(n.distanceSqToSegment(m,o,r,u)>H)continue;r.applyMatrix4(this.matrixWorld);const U=f.ray.origin.distanceTo(r);U<f.near||U>f.far||(e.push({distance:U,point:u.clone().applyMatrix4(this.matrixWorld),index:A,face:null,faceIndex:void 0,object:this}),A=M)}}}const ge=f=>{const{setPointWidth:e,nodes:t}=f,n=new De;return n.setPoints(t,e),n},Oe=new WeakMap,ue=new Map;let lt=class extends V.BaseObject{constructor(e={}){super(),this.options=O({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return se(this,null,function*(){const{nodes:e,nodesArr:t,geometry:n,geometryArr:s,material:r,useGroups:c,setPointWidth:m,lineWidthArr:o,materialParameters:u}=this.options;let i=r,l=n;!i&&u&&(i=this.getMaterial(u)),!l&&e?l=ge({nodes:e,setPointWidth:m}):!l&&t?l=D(t.map((y,d)=>{let b=m;return!b&&o&&(b=()=>{var G;return(G=o[d])!=null?G:o[0]}),ge({nodes:y,setPointWidth:b})}),c!=null?c:0):!l&&s&&s.length>1?l=D(s,c!=null?c:0):!l&&s&&s.length===1&&([l]=s),this.createMesh(l,i)})}setGeometry(e,t){const n=ge({nodes:e,setPointWidth:t}),s=this.object3d,r=s.geometry;s.geometry=n,r.dispose()}getMaterial(e){const{width:t,height:n}=this.pencil.getSize(),s=new V.MeshLineMaterial(O({color:new a.Color("#ffffff")},e));return s.uniforms.resolution.value.set(t,n),s}addGeometries(e){const t=this.object3d,n=D([t.geometry,...e]);t.geometry=n}resize(e,t){var n,s;(s=(n=this.material)==null?void 0:n.uniforms)==null||s.resolution.value.set(e,t)}handleMaterialChange(e){if(e){const{width:t,height:n}=this.pencil.getSize();this.resize(t,n)}}animate({duration:e=1e3,delay:t=0,repeat:n=0,lineLoop:s,onRepeat:r,onUpdate:c,onComplete:m,startShow:o}={}){const{offset:u,offsetLoop:i}=this.material.uniforms,l=this.pencil.userData.debugLine?ue:Oe;if(l.get(this.material)&&this.stopAnimation(),e===0)return;const y=s!=null?s:!0;u.value.x=1,i.value=y&&o?1:0;let d=0;const b=new ee.Tween(u.value).to({x:-1},e).delay(t).repeat(n).onUpdate(({x:G})=>{y&&G<=0&&i.value===0&&(i.value=1),c==null||c(G)}).onRepeat(()=>{d+=1,r==null||r(d)}).onComplete(()=>{m==null||m()}).start();l.set(this.material,b),this.material.addEventListener("dispose",()=>{this.stopAnimation()}),this.pencil.userData.debugLine&&console.log("animate",ue.size)}stopAnimation(){const e=this.pencil.userData.debugLine?ue:Oe,t=e.get(this.material);t&&(t.stop(),ee.remove(t),e.delete(this.material),this.material.uniforms.offset.value.x=0,this.material.uniforms.offsetLoop.value=1),this.pencil.userData.debugLine&&console.log("stopAnimation",ue.size)}render(){const{width:e,height:t}=this.pencil.getSize();this.resize(e,t)}};const Ie=f=>{const{points:e}=f,t=e.reduce((s,r,c)=>(c<e.length-1&&s.push(r,e[c+1]),s),[]);return new a.BufferGeometry().setFromPoints(t)};class ht extends V.BaseObject{constructor(e={}){super(),this.options=O({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return se(this,null,function*(){const{points:e,pointsArr:t,geometry:n,geometryArr:s,material:r,useGroups:c,setPointWidth:m,lineWidthArr:o,materialParameters:u,instanceCount:i}=this.options;let l=r,y=n;!l&&u&&(l=this.getMaterial(u)),!y&&e?y=Ie({points:e}):!y&&t?y=D(t.map(b=>Ie({points:b})),c!=null?c:0):!y&&s&&s.length>1?y=D(s,c!=null?c:0):!y&&s&&s.length===1&&([y]=s);const d=new Re.LineSegmentsGeometry().fromLineSegments(new a.LineSegments(y));if(this.pencil.options.WebGPUTHREE){i&&(d.instanceCount=i);const b=new V.LineSegments2(d,l);b.computeLineDistances(),this.object3d=b}else{const b=new Je.LineSegments2(d,l);b.computeLineDistances(),this.object3d=b}})}getMaterial(e){return new Ue.LineMaterial(O({color:new a.Color("#ffffff")},e))}}class ut extends V.BaseObject{constructor(e){super(),this.options=O({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},e)}create(){return se(this,null,function*(){this.createGroup();const{data:e,maxDepth:t,colors:n,material:s,percentDepth:r,activeIndex:c}=this.options,m=Math.max(...e),o=e.reduce((i,l)=>i+l,0);let u=Math.PI/2;e.forEach((i,l)=>{if(i===0)return;const y=Math.PI*2*(i/o),d=n[l],b=r?t*(i/m):t,G=this.createGeometry(b,y),A=s?s.clone():new a.MeshBasicMaterial({color:d});s&&A.color.set(d);const M=new a.Mesh(G,A);M.userData.depth=b,M.userData.index=l,M.rotateZ(u),u+=y,this.add(M)}),c!==-1&&this.setActive(c)})}createGeometry(e,t){const{outRadius:n,innerRadius:s}=this.options,r=new a.Shape;return r.moveTo(n,0),r.lineTo(s,0),r.absarc(0,0,s,0,t,!1),r.absarc(0,0,n,t,0,!0),new J(r,{curveSegments:48,depth:e,bevelEnabled:!1})}handlePick(e,t=1.3){const{object:n}=this.pencil.pick(e,this.object3d.children)||{},s=n?this.object3d.children.findIndex(r=>r===n):this.options.activeIndex;return this.setActive(s,t)}setActive(e,t=1.3){const n=this.object3d.children[e];if(this.object3d.children.forEach(s=>{if(!(n&&n===s)&&s.scale.z!==1){if(s.userData.levTween)return;s.userData.enTween&&(s.userData.enTween.stop(),s.userData.enTween=null);const r=new ee.Tween(s.scale).to({z:1},100);s.userData.levTween=r,r.start()}}),n){if(n.userData.enTween)return;n.userData.levTween&&(n.userData.levTween.stop(),n.userData.levTween=null);const s=new ee.Tween(n.scale).to({z:t},100);return n.userData.enTween=s,s.start(),n.userData.index}return-1}render(){this.object3d.scale.z=0,new ee.Tween(this.object3d.scale).to({z:1},1e3).easing(ee.Easing.Sinusoidal.InOut).start()}}Object.defineProperty(exports,"Line2Material",{enumerable:!0,get:()=>Ue.LineMaterial});Object.defineProperty(exports,"LineSegmentsGeometry",{enumerable:!0,get:()=>Re.LineSegmentsGeometry});exports.MeshLineMaterial=V.MeshLineMaterial;exports.Node=V.Node;exports.getConicPolygonGeometry=V.PolygonGeometry;exports.getConicPolygonGeometryMetas=V.getMetas;exports.ConicPolygon=Ke;exports.ExtrudePolygon=it;exports.Group=rt;exports.Light=at;exports.Line=lt;exports.Line2=ht;exports.MeshLineGeometry=De;exports.MeshLineRaycast=ct;exports.Pie=ut;exports.getSplitTexture=ot;
|