gl-draw 0.15.20 → 0.15.21
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/WebGPULineSegments2.js +139 -0
- package/dist/WebGPULineSegments2.module.js +1014 -0
- package/dist/core/BaseObject/index.d.ts +2 -1
- package/dist/core/Composer.d.ts +5 -5
- package/dist/core/ResourceTracker.d.ts +1 -1
- package/dist/index.js +23 -23
- package/dist/index.module.js +64 -60
- package/dist/objects/conicPolygon/geometry/index.d.ts +4 -4
- package/dist/objects/index.d.ts +8 -8
- package/dist/objects/index.js +1 -1
- package/dist/objects/index.module.js +954 -927
- package/dist/objects/line/createGeometry.d.ts +2 -2
- package/dist/objects/line/index.d.ts +5 -5
- package/dist/objects/line/meshLine/MeshLineGeometry.d.ts +16 -35
- package/dist/objects/line/meshLine/MeshLineMaterial.d.ts +67 -41
- package/dist/objects/line/meshLine/fragment.d.ts +1 -0
- package/dist/objects/line/meshLine/index.d.ts +1 -0
- package/dist/objects/line/meshLine/raycast.d.ts +3 -0
- package/dist/objects/line/meshLine/vertex.d.ts +1 -0
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/index.module.js +24 -24
- package/package.json +1 -1
- package/dist/index.module2.js +0 -1173
- package/dist/index2.js +0 -149
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";var pe=Object.defineProperty,me=Object.defineProperties;var ve=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var te=Math.pow,J=(n,e,t)=>e in n?pe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,_=(n,e)=>{for(var t in e||(e={}))H.call(e,t)&&J(n,t,e[t]);if(W)for(var t of W(e))ee.call(e,t)&&J(n,t,e[t]);return n},q=(n,e)=>me(n,ve(e));var re=(n,e)=>{var t={};for(var r in n)H.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&W)for(var r of W(n))e.indexOf(r)<0&&ee.call(n,r)&&(t[r]=n[r]);return t};var ie=(n,e,t)=>new Promise((r,i)=>{var c=l=>{try{s(t.next(l))}catch(a){i(a)}},u=l=>{try{s(t.throw(l))}catch(a){i(a)}},s=l=>l.done?r(l.value):Promise.resolve(l.value).then(c,u);s((t=t.apply(n,e)).next())});const o=require("three"),ye=require("three/examples/jsm/renderers/CSS2DRenderer"),ne=require("three/examples/jsm/renderers/CSS3DRenderer"),O=require("d3-geo");require("d3-geo-projection");const Q=require("./parseVector.js"),L=require("d3-array"),X=require("earcut"),be=require("@turf/boolean-clockwise"),ge=require("delaunator"),Me=require("@turf/boolean-point-in-polygon"),Se=require("d3-geo-voronoi"),se=require("d3-scale"),xe=require("three/examples/jsm/lines/LineSegmentsGeometry"),we=0,je=1,Ae=2,Ce=!1;class fe{constructor(){this.resources=new Set,this.disposeMaterial=!0,this.disposeVideo=!0}track(e){if(!e)return e;if(Array.isArray(e))return e.forEach(t=>this.track(t)),e;if(!this.disposeMaterial&&e instanceof o.Material)return e;if(e instanceof Y?(e.disposeTrack&&e.object3d?this.track(e.object3d):this.resources.add(e),Object.values(e.materialList).map(t=>this.track(t))):(e instanceof o.Object3D||Reflect.has(e,"dispose"))&&this.resources.add(e),e instanceof Y)e.children.forEach(t=>{t.disposeTrack=!1}),this.track(e.children);else if(e instanceof o.Object3D){const t=e;this.track(t.geometry),this.track(t.material),this.track(t.children)}else if(e instanceof o.Material){for(const r of Object.values(e))r instanceof o.Texture&&this.track(r);const t=e;if(t.uniforms){for(const r of Object.values(t.uniforms))if(r){const i=r.value;(i instanceof o.Texture||Array.isArray(i))&&this.track(i)}}}else this.disposeVideo&&e instanceof o.VideoTexture&&e.source.data&&this.resources.add(e.source.data);return e}dispose(){const e=[];for(const t of this.resources)t instanceof o.Object3D?e.push(t):t instanceof HTMLVideoElement&&t.pause(),Reflect.has(t,"dispose")&&t.dispose();e.forEach(t=>{t.removeFromParent()}),e.length=0,this.resources.clear()}}const Pe=(n,e=1)=>{const t=new o.BufferGeometry;t.setAttribute("position",new o.Float32BufferAttribute(new Array(e*3).fill(0),3)),t.setAttribute("scaleAtt",new o.Float32BufferAttribute(new Array(e).fill(1),1));const r=n.material,i=new o.PointsMaterial({size:10,map:r.map,alphaMap:r.alphaMap,color:r.color,blending:r.blending,depthTest:r.depthTest,depthWrite:!1,opacity:r.opacity,transparent:!0,alphaTest:r.alphaTest,sizeAttenuation:!1});return i.onBeforeCompile=c=>{c.vertexShader=`
|
|
2
|
+
attribute float scaleAtt;
|
|
3
|
+
${c.vertexShader.replace("gl_PointSize = size;","gl_PointSize = size * scaleAtt;")}
|
|
4
|
+
`},new o.Points(t,i)},Be=(n,e)=>{const t=new o.Object3D;e.forEach((r,i)=>{const c=Q.parseVector3(r.position),u=Q.parseVector3(r.scale||[1,1,1]);t.position.copy(c),t.scale.copy(u),t.updateMatrix();const s=t.matrix.clone();if(n instanceof o.InstancedMesh||n.isInstantiate)n.setMatrixAt(i,s);else if(n instanceof o.Points||n.type==="Points"){const a=n.geometry,p=a.attributes.position.array,f=a.attributes.scaleAtt.array,m=new o.Vector3,d=new o.Vector3,v=new o.Quaternion,h=i*3,y=i*1;s.decompose(m,v,d),p[h]=m.x,p[h+1]=m.y,p[h+2]=m.z,f[y]=Math.max(d.x,d.y,d.z),a.attributes.position.needsUpdate=!0,a.attributes.scaleAtt.needsUpdate=!0}})};class Ie{constructor(){this.onPointerIndex=[]}onPointerEvent(e,t){const r=this.lead.handlePick([this],e,t);this.onPointerIndex.push(r)}onClick(e){this.onPointerEvent("click",e)}onPointerEnter(e){this.onPointerEvent("enter",e)}onPointerLeave(e){this.onPointerEvent("leave",e)}onPointerMove(e){this.onPointerEvent("move",e)}onPointerDown(e){this.onPointerEvent("down",e)}dispose(){this.onPointerIndex.forEach(e=>{this.lead.removePick(e)})}}class De extends Ie{constructor(){super(...arguments),this.userData={},this.materialList={},this.useMaterialType="origin",this.disposeMaterialIfNotUsed=!0}cloneMaterial(){const e=this.object3d;if(!e||!e.material)return;const t=e.material;if(Array.isArray(t))return t.map(r=>{const i=r.userData;r.userData={};const c=r.clone();return r.userData=i,c});{const r=t.userData;t.userData={};const i=t.clone();return t.userData=r,i}}setMaterialList(e,t){const r=this.object3d;if(!r||!r.material)return;this.materialList.origin||(this.materialList.origin=r.material);const i=t==="clone"?this.cloneMaterial():Array.isArray(t)?t.slice():t;return this.materialList[e]=i,i}useMaterial(e){const t=this.object3d;!t||!t.material||this.useMaterialType===e||!this.materialList[e]||(this.useMaterialType=e,t.material=this.materialList[e])}useMListById(e,t){if(!this.mList)return;const r=this.mList.get(e);if(!r)return;const i=this.object3d;Array.isArray(i.material)&&t!==void 0?i.material[t]=r:i.material=r}useMListByName(e,t){if(!this.mList)return;const r=this.mList.getKeyByName(e);r&&this.useMListById(r,t)}dispose(){super.dispose(),this.mList.rmBaseObjectMap(this,void 0,this.disposeMaterialIfNotUsed)}}class Y extends De{constructor(){super(...arguments),this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!1,this.isBloom=!1,this.disposeTrack=!0}get parent(){const e=this.object3d.parent;return e&&this.lead.objMap.get(e)||null}get children(){return this.object3d.children.map(e=>this.lead.objMap.get(e)).filter(e=>!!e)}get position(){return this.object3d.position}get rotation(){return this.object3d.rotation}get scale(){return this.object3d.scale}get lookAt(){return this.object3d.lookAt}add(...e){[...e].forEach(t=>{this.lead.objMap.get(t)?this.object3d.add(t):this.lead.createBaseObject(t,{target:this})})}remove(...e){[...e].forEach(t=>{var r;this.lead.objMap.get(t)?(r=this.lead.objMap.get(t))==null||r.erase():this.object3d.remove(t)})}get visible(){return this.object3d.visible}get visibleWithAncestors(){if(this.visible){let e=this.parent;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}else return!1}create(){this.createGroup()}render(){}update(e,t){}resize(e,t){}show(){return this.object3d.visible=!0,this.object3d.layers.set(we),this}hide(){return this.object3d.visible=!1,this.object3d.layers.set(Ae),this}createGroup(){return this.object3d=new o.Group,this}createMesh(...e){return this.object3d=new o.Mesh(...e),this}createPoints(...e){return this.object3d=new o.Points(...e),this}createCSS2DObject(e){return this.object3d=new ye.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new ne.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new ne.CSS3DSprite(e),this}createSprite(e){return this.object3d=new o.Sprite(e),this}attach(...e){return[...e].forEach(t=>{this.object3d.attach(t.object3d)}),this}getSize(){const e=new o.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new o.Vector3),center:e.getCenter(new o.Vector3)}}setTop(e){this.object3d&&(this.object3d.renderOrder=e)}traverse(e){e(this),this.children.forEach(t=>{t.traverse(e)})}instantiate(e){return ie(this,null,function*(){var l;const t=(l=e==null?void 0:e.recursive)!=null?l:!0,{objectType:r,objectOptions:i}=this,[,c]=r.split("#");let u=e==null?void 0:e.create;u===void 0&&(u=a=>{var p;if(this.object3d){if((p=e==null?void 0:e.instancedAttr)!=null&&p.length){const f=e.instancedAttr.length;if(this.object3d instanceof o.Sprite)a.object3d=Pe(this.object3d,f);else{const m=this.object3d,d=this.cloneMaterial();a.object3d=new o.InstancedMesh(m.geometry,d,f)}Be(a.object3d,e==null?void 0:e.instancedAttr)}else a.object3d=this.object3d.clone(!1),a.object3d.material&&(a.object3d.material=this.cloneMaterial());a.object3d.userData.prefab&&delete a.object3d.userData.prefab}});const s=yield this.lead.draw(c,q(_({},i||{}),{create:u,prefab:!1,key:(e==null?void 0:e.key)||(i==null?void 0:i.key),target:(e==null?void 0:e.target)||(i==null?void 0:i.target)}));return this.isBloom&&s.enableBloom(),t&&(yield Promise.all(this.children.map(a=>a.instantiate({target:s})))),s.isInstantiate=!0,s})}erase(){this.lead.erase(this)}handleMaterialChange(e){}enableBloom(){var e;(e=this.pencil.composerController)==null||e.setBloomSelection(this,!0),this.isBloom=!0}disableBloom(){var e;(e=this.pencil.composerController)==null||e.setBloomSelection(this,!1),this.isBloom=!1}dispose(){var e;if(super.dispose(),(e=this.pencil.composerController)==null||e.bloomSelection.delete(this),this.lead&&(this.lead.objects.delete(this.key),this.lead.objectWrapChindIdMap.delete(this),this.object3d&&this.lead.objMap.delete(this.object3d)),this.disposeTrack){const t=new fe;t.disposeMaterial=!1,t.track(this),t.dispose()}}}function Ve(n,e){return n.map(t=>{const r=[];let i;return t.forEach(c=>{if(i){const u=O.geoDistance(c,i)*180/Math.PI;if(u>e){const s=O.geoInterpolate(i,c),l=1/Math.ceil(u/e);let a=l;for(;a<1;)r.push(s(a)),a+=l}}r.push(i=c)}),r})}function Te(n,{minLng:e,maxLng:t,minLat:r,maxLat:i}={}){const c=Math.round(te(360/n,2)/Math.PI),u=(1+Math.sqrt(5))/2,s=d=>d/u*360%360-180,l=d=>Math.acos(2*d/c-1)/Math.PI*180-90,a=d=>c*(Math.cos((d+90)*Math.PI/180)+1)/2,p=[i!==void 0?Math.ceil(a(i)):0,r!==void 0?Math.floor(a(r)):c-1],f=e===void 0&&t===void 0?()=>!0:e===void 0?d=>d<=t:t===void 0?d=>d>=e:t>=e?d=>d>=e&&d<=t:d=>d>=e||d<=t,m=[];for(let d=p[0];d<=p[1];d++){const v=s(d);f(v)&&m.push([v,l(d)])}return m}function Z(n,e,t=!1){return t?O.geoContains(e,n):Me(n,e)}function ze(n,e){const t={type:"Polygon",coordinates:n},[[r,i],[c,u]]=O.geoBounds(t);if(Math.min(Math.abs(c-r),Math.abs(u-i))<e)return[];const s=r>c||u>=89||i<=-89;return Te(e,{minLng:r,maxLng:c,minLat:i,maxLat:u}).filter(l=>Z(l,t,s))}function Ee(n,{resolution:e=1/0,bbox:t,projection:r}={}){const i=Ve(n,e),c=L.merge(i),u=ze(n,e),s=[...c,...u],l={type:"Polygon",coordinates:n},[[a,p],[f,m]]=O.geoBounds(l),d=a>f||m>=89||p<=-89;let v=[];if(d){const b=Se.geoVoronoi(s).triangles(),x=new Map(s.map(([C,P],z)=>[`${C}-${P}`,z]));b.features.forEach(C=>{const P=C.geometry.coordinates[0].slice(0,3).reverse(),z=[];if(P.forEach(([B,R])=>{const k=`${B}-${R}`;x.has(k)&&z.push(x.get(k))}),z.length===3){if(z.some(B=>B<c.length)){const B=C.properties.circumcenter;if(!Z(B,l,d))return}v.push(...z)}})}else if(u.length){const b=ge.from(s);for(let x=0,C=b.triangles.length;x<C;x+=3){const P=[2,1,0].map(B=>b.triangles[x+B]),z=P.map(B=>s[B]);if(P.some(B=>B<c.length)){const B=[0,1].map(R=>L.mean(z,k=>k[R]));if(!Z(B,l,d))continue}v.push(...P)}}else{const{vertices:b,holes:x=[]}=X.flatten(i);v=X(b,x,2)}let h=t?[t[0],t[2]]:L.extent(s,b=>b[0]),y=t?[t[1],t[3]]:L.extent(s,b=>b[1]);if(r){const[b,x]=r([h[0],y[0]]),[C,P]=r([h[1],y[1]]);h=[b,C],y=[-x,-P]}const w=se.scaleLinear(h,[0,1]),j=se.scaleLinear(y,[0,1]),I=s.map(([b,x])=>{if(r){const[C,P]=r([b,x]);return[w(C),j(-P)]}else return[w(b),j(x)]});return{contour:i,triangles:{points:s,indices:v,uvs:I}}}const oe=new o.BufferGeometry().setAttribute?"setAttribute":"addAttribute";function G(n,e,t,r){const i=n.map(c=>c.map(([u,s])=>{if(r){const[l,a]=r([u,s]);return[l,-a,e]}return t?Q.polar2Cartesian(u,s,e):[u,s,e]}));return X.flatten(i)}function Le(n,e,t,r,i){const{vertices:c,holes:u}=G(n,e,r,i),{vertices:s}=G(n,t,r,i),l=L.merge([s,c]),a=Math.round(s.length/3),p=new Set(u);let f=0;const m=[];for(let v=0;v<a;v++){let h=v+1;if(h===a)h=f;else if(p.has(h)){const y=h;h=f,f=y}m.push(v,v+a,h+a),m.push(h+a,h,v)}const d=[];for(let v=1;v>=0;v--)for(let h=0;h<a;h+=1)d.push(h/(a-1),v);return{indices:m,vertices:l,uvs:d,topVerts:s}}function ae(n,e,t,r,i,c){return{indices:r?n.indices:n.indices.slice().reverse(),vertices:G([n.points],e,i,c).vertices,uvs:t}}const he=({polygonGeoJson:n,startHeight:e,endHeight:t,curvatureResolution:r=1,cartesian:i=!0,hasSide:c=!0,hasBottom:u=!1,hasTop:s=!1,projection:l,bbox:a})=>{n.forEach(w=>{be(w)||w.reverse()});const{contour:p,triangles:f}=Ee(n,{resolution:r,bbox:a,projection:l});let m={},d;c&&(m=Le(p,e!=null?e:t,t!=null?t:e,i,l),d=m.topVerts);let v=[];(u||s)&&(v=L.merge(f.uvs));let h={};u&&(h=ae(f,e,v,!1,i,l));let y={};return s&&(y=ae(f,t,v,!0,i,l)),{contour:p,triangles:f,sideTorso:m,bottomCap:h,topCap:y,topVerts:d}};class _e extends o.BufferGeometry{constructor(e,t={}){super(),this.type="PolygonBufferGeometry",this.parameters=_({polygonGeoJson:e,startHeight:0,endHeight:1,hasTop:!0,topFirst:!1,hasBottom:!0,hasSide:!0,curvatureResolution:1,cartesian:!0,userDataRsoOffset:0},t);const{endHeight:r,hasTop:i,topFirst:c,hasBottom:u,hasSide:s,cartesian:l,userDataRsoOffset:a,projection:p}=this.parameters,{contour:f,sideTorso:m,topVerts:d,bottomCap:v,topCap:h}=he(_({},this.parameters));let y=[],w=[],j=[],I=0;const A=b=>{const x=Math.round(y.length/3),C=j.length;y=y.concat(b.vertices),w=w.concat(b.uvs),j=j.concat(x?b.indices.map(P=>P+x):b.indices),this.addGroup(C,j.length-C,I++)};i&&c&&A(h),s&&(A(m),this.userData.topVerts=a?G(f,r+a,l,p).vertices:d),u&&A(v),i&&!c&&A(h),this.setIndex(j),this[oe]("position",new o.Float32BufferAttribute(y,3)),this[oe]("uv",new o.Float32BufferAttribute(w,2)),this.computeVertexNormals()}}const Oe=`
|
|
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 <${parseInt(o.REVISION)<154?"encodings_fragment":"colorspace_fragment"}>
|
|
46
|
+
}
|
|
47
|
+
`,ke=`
|
|
48
|
+
#include <common>
|
|
49
|
+
${o.ShaderChunk.logdepthbuf_pars_vertex}
|
|
50
|
+
${o.ShaderChunk.fog_pars_vertex}
|
|
51
|
+
|
|
52
|
+
attribute vec3 previous;
|
|
53
|
+
attribute vec3 next;
|
|
54
|
+
attribute float side;
|
|
55
|
+
attribute float width;
|
|
56
|
+
attribute float counters;
|
|
57
|
+
|
|
58
|
+
uniform vec2 resolution;
|
|
59
|
+
uniform float lineWidth;
|
|
60
|
+
uniform vec3 color;
|
|
61
|
+
uniform float opacity;
|
|
62
|
+
uniform float sizeAttenuation;
|
|
63
|
+
uniform float scaleDown;
|
|
64
|
+
uniform vec2 offset;
|
|
65
|
+
|
|
66
|
+
varying vec2 vUV;
|
|
67
|
+
varying vec4 vColor;
|
|
68
|
+
varying float vCounters;
|
|
69
|
+
|
|
70
|
+
vec2 intoScreen(vec4 i) {
|
|
71
|
+
return resolution * (0.5 * i.xy / i.w + 0.5);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
void main() {
|
|
75
|
+
float aspect = resolution.y / resolution.x;
|
|
76
|
+
|
|
77
|
+
mat4 m = projectionMatrix * modelViewMatrix;
|
|
78
|
+
|
|
79
|
+
vec4 currentClip = m * vec4( position, 1.0 );
|
|
80
|
+
vec4 prevClip = m * vec4( previous, 1.0 );
|
|
81
|
+
vec4 nextClip = m * vec4( next, 1.0 );
|
|
82
|
+
|
|
83
|
+
vec4 currentNormed = currentClip / currentClip.w;
|
|
84
|
+
vec4 prevNormed = prevClip / prevClip.w;
|
|
85
|
+
vec4 nextNormed = nextClip / nextClip.w;
|
|
86
|
+
|
|
87
|
+
vec2 currentScreen = intoScreen(currentNormed);
|
|
88
|
+
vec2 prevScreen = intoScreen(prevNormed);
|
|
89
|
+
vec2 nextScreen = intoScreen(nextNormed);
|
|
90
|
+
|
|
91
|
+
float actualWidth = lineWidth * width;
|
|
92
|
+
|
|
93
|
+
vec2 dir;
|
|
94
|
+
if(nextScreen == currentScreen) {
|
|
95
|
+
dir = normalize( currentScreen - prevScreen );
|
|
96
|
+
} else if(prevScreen == currentScreen) {
|
|
97
|
+
dir = normalize( nextScreen - currentScreen );
|
|
98
|
+
} else {
|
|
99
|
+
vec2 inDir = currentScreen - prevScreen;
|
|
100
|
+
vec2 outDir = nextScreen - currentScreen;
|
|
101
|
+
vec2 fullDir = nextScreen - prevScreen;
|
|
102
|
+
|
|
103
|
+
if(length(fullDir) > 0.0) {
|
|
104
|
+
dir = normalize(fullDir);
|
|
105
|
+
} else if(length(inDir) > 0.0){
|
|
106
|
+
dir = normalize(inDir);
|
|
107
|
+
} else {
|
|
108
|
+
dir = normalize(outDir);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
vec2 normal = vec2(-dir.y, dir.x);
|
|
113
|
+
|
|
114
|
+
if(sizeAttenuation != 0.0) {
|
|
115
|
+
normal /= currentClip.w;
|
|
116
|
+
normal *= min(resolution.x, resolution.y);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (scaleDown > 0.0) {
|
|
120
|
+
float dist = length(nextNormed - prevNormed);
|
|
121
|
+
normal *= smoothstep(0.0, scaleDown, dist);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
vec2 offsetInScreen = actualWidth * normal * side * 0.5;
|
|
125
|
+
|
|
126
|
+
vec2 withOffsetScreen = currentScreen + offsetInScreen;
|
|
127
|
+
vec3 withOffsetNormed = vec3((2.0 * withOffsetScreen/resolution - 1.0), currentNormed.z);
|
|
128
|
+
|
|
129
|
+
vCounters = counters;
|
|
130
|
+
vColor = vec4( color, opacity );
|
|
131
|
+
vUV = uv;
|
|
132
|
+
vUV=uv+offset;
|
|
133
|
+
|
|
134
|
+
gl_Position = currentClip.w * vec4(withOffsetNormed, 1.0);
|
|
135
|
+
|
|
136
|
+
${o.ShaderChunk.logdepthbuf_vertex}
|
|
137
|
+
${o.ShaderChunk.fog_vertex}
|
|
138
|
+
}
|
|
139
|
+
`;class We extends o.ShaderMaterial{constructor(e={}){const j=e,{lineWidth:t=1,color:r="#ffffff",opacity:i=1,map:c=null,dashOffset:u=0,dashArray:s=0,dashRatio:l=0,sizeAttenuation:a=!0,offsetLoop:p=!0,offset:f=new o.Vector2(0,0),scaleDown:m=0,alphaMap:d=void 0,alphaTest:v=0,repeat:h=new o.Vector2(1,1),resolution:y=new o.Vector2(1,1)}=j,w=re(j,["lineWidth","color","opacity","map","dashOffset","dashArray","dashRatio","sizeAttenuation","offsetLoop","offset","scaleDown","alphaMap","alphaTest","repeat","resolution"]);super(q(_({},w),{uniforms:{lineWidth:{value:t},color:{value:new o.Color(r)},opacity:{value:i},map:{value:c},useMap:{value:c?1:0},resolution:{value:y},sizeAttenuation:{value:a?1:0},offset:{value:f},offsetLoop:{value:p?1:0},dashArray:{value:s},dashOffset:{value:u},dashRatio:{value:l},useDash:{value:s>0?1:0},scaleDown:{value:m/10},alphaTest:{value:v},alphaMap:{value:d},useAlphaMap:{value:d?1:0},repeat:{value:h}},vertexShader:ke,fragmentShader:Oe})),this.type="MeshLineMaterial"}get color(){return this.uniforms.color.value}set color(e){this.uniforms.color.value=new o.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 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 F=new o.Vector4,ce=new o.Vector3,le=new o.Vector3,g=new o.Vector4,M=new o.Vector4,D=new o.Vector4,$=new o.Vector3,K=new o.Matrix4,S=new o.Line3,ue=new o.Vector3,N=new o.Box3,U=new o.Sphere,V=new o.Vector4;let T,E;function de(n,e,t){return V.set(0,0,-e,1).applyMatrix4(n.projectionMatrix),V.multiplyScalar(1/V.w),V.x=E/t.width,V.y=E/t.height,V.applyMatrix4(n.projectionMatrixInverse),V.multiplyScalar(1/V.w),Math.abs(Math.max(V.x,V.y))}function Ne(n,e){const t=n.matrixWorld,r=n.geometry,i=r.attributes.instanceStart,c=r.attributes.instanceEnd,u=Math.min(r.instanceCount,i.count);for(let s=0,l=u;s<l;s++){S.start.fromBufferAttribute(i,s),S.end.fromBufferAttribute(c,s),S.applyMatrix4(t);const a=new o.Vector3,p=new o.Vector3;T.distanceSqToSegment(S.start,S.end,p,a),p.distanceTo(a)<E*.5&&e.push({point:p,pointOnLine:a,distance:T.origin.distanceTo(p),object:n,face:null,faceIndex:s,uv:null,uv1:null})}}function Ue(n,e,t){const r=e.projectionMatrix,c=n.material.resolution,u=n.matrixWorld,s=n.geometry,l=s.attributes.instanceStart,a=s.attributes.instanceEnd,p=Math.min(s.instanceCount,l.count),f=-e.near;T.at(1,D),D.w=1,D.applyMatrix4(e.matrixWorldInverse),D.applyMatrix4(r),D.multiplyScalar(1/D.w),D.x*=c.x/2,D.y*=c.y/2,D.z=0,$.copy(D),K.multiplyMatrices(e.matrixWorldInverse,u);for(let m=0,d=p;m<d;m++){if(g.fromBufferAttribute(l,m),M.fromBufferAttribute(a,m),g.w=1,M.w=1,g.applyMatrix4(K),M.applyMatrix4(K),g.z>f&&M.z>f)continue;if(g.z>f){const I=g.z-M.z,A=(g.z-f)/I;g.lerp(M,A)}else if(M.z>f){const I=M.z-g.z,A=(M.z-f)/I;M.lerp(g,A)}g.applyMatrix4(r),M.applyMatrix4(r),g.multiplyScalar(1/g.w),M.multiplyScalar(1/M.w),g.x*=c.x/2,g.y*=c.y/2,M.x*=c.x/2,M.y*=c.y/2,S.start.copy(g),S.start.z=0,S.end.copy(M),S.end.z=0;const h=S.closestPointToPointParameter($,!0);S.at(h,ue);const y=o.MathUtils.lerp(g.z,M.z,h),w=y>=-1&&y<=1,j=$.distanceTo(ue)<E*.5;if(w&&j){S.start.fromBufferAttribute(l,m),S.end.fromBufferAttribute(a,m),S.start.applyMatrix4(u),S.end.applyMatrix4(u);const I=new o.Vector3,A=new o.Vector3;T.distanceSqToSegment(S.start,S.end,A,I),t.push({point:A,pointOnLine:I,distance:T.origin.distanceTo(A),object:n,face:null,faceIndex:m,uv:null,uv1:null})}}}class Ge extends o.Mesh{constructor(e=new xe.LineSegmentsGeometry,t){super(e,t),this.isLineSegments2=!0,this.type="LineSegments2"}computeLineDistances(){const e=this.geometry,t=e.attributes.instanceStart,r=e.attributes.instanceEnd,i=new Float32Array(2*t.count);for(let u=0,s=0,l=t.count;u<l;u++,s+=2)ce.fromBufferAttribute(t,u),le.fromBufferAttribute(r,u),i[s]=s===0?0:i[s-1],i[s+1]=i[s]+ce.distanceTo(le);const c=new o.InstancedInterleavedBuffer(i,2,1);return e.setAttribute("instanceDistanceStart",new o.InterleavedBufferAttribute(c,1,0)),e.setAttribute("instanceDistanceEnd",new o.InterleavedBufferAttribute(c,1,1)),this}raycast(e,t){const r=this.material.worldUnits,i=e.camera;i===null&&!r&&console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');const c=e.params.Line2!==void 0&&e.params.Line2.threshold||0;T=e.ray;const u=this.matrixWorld,s=this.geometry,l=this.material;E=l.linewidth+c,s.boundingSphere===null&&s.computeBoundingSphere(),U.copy(s.boundingSphere).applyMatrix4(u);let a;if(r)a=E*.5;else{const f=Math.max(i.near,U.distanceToPoint(T.origin));a=de(i,f,l.resolution)}if(U.radius+=a,T.intersectsSphere(U)===!1)return;s.boundingBox===null&&s.computeBoundingBox(),N.copy(s.boundingBox).applyMatrix4(u);let p;if(r)p=E*.5;else{const f=Math.max(i.near,N.distanceToPoint(T.origin));p=de(i,f,l.resolution)}N.expandByScalar(p),T.intersectsBox(N)!==!1&&(r?Ne(this,t):Ue(this,i,t))}onBeforeRender(e){const t=this.material.uniforms;t&&t.resolution&&(e.getViewport(F),this.material.uniforms.resolution.value.set(F.z,F.w))}}exports.BLOOM_SCENE=je;exports.BaseObject=Y;exports.IS_DEV=Ce;exports.LineSegments2=Ge;exports.MeshLineMaterial=We;exports.PolygonGeometry=_e;exports.ResourceTracker=fe;exports.getMetas=he;
|