@protomaze/geometry 0.3.0 → 0.3.1

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/README.md CHANGED
@@ -68,7 +68,7 @@ The view emits `hover`, `click`, `select`, `camera`, `mode` and `frame` (fps, dr
68
68
  |---|---|---|
69
69
  | `LineLayer` | lines | across the screen (2D), flat on the ground in perspective, or in space at their own depth (trajectories); round joints, flat ends, flow arrows, dashes, light flowing along them |
70
70
  | `PointLayer` | points | icons from an atlas or shapes drawn in the shader - circle, ring, square, diamond, triangle, hexagon, pin, cross, star, the manhole cover - in pixels or metres, facing the screen or lying on the ground |
71
- | `TubeLayer` | lines, points | pipes, cables and ducts at their real size and cross-section, mitred bends, joints cut to the shafts' walls, materials; points as shafts or columns with covers. A 2D map draws the same features as lines and covers |
71
+ | `TubeLayer` | lines, points | pipes, cables and ducts at their real size and cross-section, mitred bends, joints cut to the shafts' walls, materials; points as shafts or columns with covers - `stand` from heights where z is up, or from a `foot` and a `top` position anywhere, a globe's included, where a pipe's end is in the shaft whose axis it lies on (in 3D, `joinTolerance`). A 2D map draws the same features as lines and covers |
72
72
  | `SphereLayer` | points | lit spheres - connections, sensors, nodes, tree crowns |
73
73
  | `AreaLayer` | polygons | flat fills, solid or hatched, with outlines; or extruded volumes, heights on the GPU, lit windows at night |
74
74
 
@@ -290,7 +290,8 @@ The view on a host's engine has layers, their looks, the highlight, selection, e
290
290
  and picking; the host keeps the camera, the ground and the input, so there is no `init`, no
291
291
  controllers and no camera calls. `view.toScreen(p)` is where the host's camera put a position on
292
292
  the last frame. On a globe (`geocentric`) the ground's up is the ellipsoid's normal at the origin,
293
- which tubes stand along and volumes rise along. `view.setMode('2d' | '3d')` when the host switches:
293
+ which volumes rise along and covers lie across; give a shaft its own `foot` and `top`
294
+ (`TubeLayer`'s `stand`), and it stands along whatever its axis is. `view.setMode('2d' | '3d')` when the host switches:
294
295
  the layers draw the other way, the host turns its camera. The `--pm-*` tokens are read round
295
296
  `element`.
296
297
 
package/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from './math/Relations';
11
11
  export * from './math/Geodesy';
12
12
  export * from './math/SpatialIndex';
13
13
  export * from './math/FeatureIndex';
14
+ export * from './math/AxisIndex';
14
15
  export * from './engine/GeometryFrame';
15
16
  export * from './engine/GeometryEngine';
16
17
  export * from './engine/GeometryOptions';
package/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./data/Geometry.js";export*from"./math/Triangulate.js";export*from"./math/Projection.js";export*from"./math/Vector.js";export*from"./math/Measure.js";export*from"./math/Lines.js";export*from"./math/Polygons.js";export*from"./math/Boolean.js";export*from"./math/Transform.js";export*from"./math/Relations.js";export*from"./math/Geodesy.js";export*from"./math/SpatialIndex.js";export*from"./math/FeatureIndex.js";export*from"./engine/GeometryFrame.js";export*from"./engine/GeometryEngine.js";export*from"./engine/GeometryOptions.js";export*from"./engine/GeometryView.js";export*from"./engine/MapCamera.js";export*from"./engine/Labels.js";export*from"./edit/GeometryController.js";export*from"./edit/Snapper.js";export*from"./edit/Sketch.js";export*from"./edit/EditShape.js";export*from"./edit/EditHistory.js";export*from"./edit/CreateController.js";export*from"./edit/EditController.js";export*from"./edit/MeasureController.js";export*from"./three/CanvasGeometryEngine.js";export*from"./three/HostedGeometryEngine.js";export*from"./three/FeatureLook.js";export*from"./three/Shading.js";export*from"./three/DensityMap.js";export*from"./three/Halo.js";export*from"./three/Ground.js";export*from"./three/Tsl.js";export*from"./three/primitives/GpuLines.js";export*from"./three/primitives/GpuIcons.js";export*from"./three/primitives/GpuTubes.js";export*from"./three/primitives/GpuSpheres.js";export*from"./three/primitives/GpuAreas.js";export*from"./three/primitives/IconAtlas.js";export*from"./three/primitives/Body.js";export*from"./layers/GeometryLayer.js";export*from"./layers/LineLayer.js";export*from"./layers/PointLayer.js";export*from"./layers/TubeLayer.js";export*from"./layers/SphereLayer.js";export*from"./layers/AreaLayer.js";export*from"./react/ReactGeometry.js";export*from"./theme/Theme.js";export*from"./common/Colors.js";export*from"./common/Disposables.js";export*from"./event/TypedEventEmitter.js";
1
+ export*from"./data/Geometry.js";export*from"./math/Triangulate.js";export*from"./math/Projection.js";export*from"./math/Vector.js";export*from"./math/Measure.js";export*from"./math/Lines.js";export*from"./math/Polygons.js";export*from"./math/Boolean.js";export*from"./math/Transform.js";export*from"./math/Relations.js";export*from"./math/Geodesy.js";export*from"./math/SpatialIndex.js";export*from"./math/FeatureIndex.js";export*from"./math/AxisIndex.js";export*from"./engine/GeometryFrame.js";export*from"./engine/GeometryEngine.js";export*from"./engine/GeometryOptions.js";export*from"./engine/GeometryView.js";export*from"./engine/MapCamera.js";export*from"./engine/Labels.js";export*from"./edit/GeometryController.js";export*from"./edit/Snapper.js";export*from"./edit/Sketch.js";export*from"./edit/EditShape.js";export*from"./edit/EditHistory.js";export*from"./edit/CreateController.js";export*from"./edit/EditController.js";export*from"./edit/MeasureController.js";export*from"./three/CanvasGeometryEngine.js";export*from"./three/HostedGeometryEngine.js";export*from"./three/FeatureLook.js";export*from"./three/Shading.js";export*from"./three/DensityMap.js";export*from"./three/Halo.js";export*from"./three/Ground.js";export*from"./three/Tsl.js";export*from"./three/primitives/GpuLines.js";export*from"./three/primitives/GpuIcons.js";export*from"./three/primitives/GpuTubes.js";export*from"./three/primitives/GpuSpheres.js";export*from"./three/primitives/GpuAreas.js";export*from"./three/primitives/IconAtlas.js";export*from"./three/primitives/Body.js";export*from"./layers/GeometryLayer.js";export*from"./layers/LineLayer.js";export*from"./layers/PointLayer.js";export*from"./layers/TubeLayer.js";export*from"./layers/SphereLayer.js";export*from"./layers/AreaLayer.js";export*from"./react/ReactGeometry.js";export*from"./theme/Theme.js";export*from"./common/Colors.js";export*from"./common/Disposables.js";export*from"./event/TypedEventEmitter.js";
@@ -10,15 +10,26 @@ export interface TubeStyle extends BaseStyle {
10
10
  /** On a 2D map, light running along its line, in the direction of its points. */
11
11
  flow?: boolean;
12
12
  }
13
- /** A standing tube for a point feature: a shaft, a pole, a well. */
14
- export interface TubeStand {
15
- /** Heights of its foot and its top, in world units. */
13
+ /**
14
+ * A standing tube for a point feature - a shaft, a pole, a well - from its foot to its top: two
15
+ * world positions, which on a globe stand along the ellipsoid's up there; or, where z is up, the
16
+ * heights of its foot and top at the point's x and y.
17
+ */
18
+ export type TubeStand = ({
19
+ /** Its foot and its top, as world positions. */
20
+ foot: readonly number[];
21
+ top: readonly number[];
22
+ } | {
23
+ /** The heights of its foot and its top at the point, where z is up. */
16
24
  bottom: number;
17
25
  top: number;
26
+ }) & {
18
27
  radius: number;
19
28
  /** A shaft, its top open for the cover lying there (the default), or closed. */
20
29
  open?: boolean;
21
- }
30
+ };
31
+ /** A stand's foot and top as world positions: given, or at its point's x and y. */
32
+ export declare function standAxis(point: readonly number[], stand: TubeStand): [number[], number[]];
22
33
  export interface TubeLayerOptions<F> extends GeometryLayerOptions<F, TubeStyle> {
23
34
  /** A line feature's cross-section: a radius, or a profile. Round, 0.15 by default. */
24
35
  profile?: (feature: F) => number | Profile;
@@ -30,9 +41,13 @@ export interface TubeLayerOptions<F> extends GeometryLayerOptions<F, TubeStyle>
30
41
  arrows?: boolean;
31
42
  /**
32
43
  * Tubes ending in a shaft are cut back to its wall, and two ending on its axis, or at the same
33
- * point, meet in a mitre. On by default.
44
+ * point, meet in a mitre. On by default. A tube's end is in a shaft where it lies on the
45
+ * shaft's axis - within `joinTolerance` of it, in 3D, so on a globe as on a level world -
46
+ * with the pipes and their shafts in one layer.
34
47
  */
35
48
  join?: boolean;
49
+ /** How far off a shaft's axis a tube's end still ends in it, in world units. 0.05 by default. */
50
+ joinTolerance?: number;
36
51
  /** Ghosted where the scene's surface is in front of them, with a halo. On by default. */
37
52
  ghost?: boolean;
38
53
  /** Covers lying on the open shafts' tops, as a 2D map draws manholes. On by default. */
@@ -1 +1 @@
1
- import{linesOf as t,pointsOf as e}from"../data/Geometry.js";import{LookFlag as o}from"../three/FeatureLook.js";import{GpuIcons as r,IconShape as i}from"../three/primitives/GpuIcons.js";import{GpuLines as n}from"../three/primitives/GpuLines.js";import{GpuTubes as s,joinTubeEnds as p,roundProfile as h}from"../three/primitives/GpuTubes.js";import{materialCode as a}from"../three/Shading.js";import{GeometryLayer as c}from"./GeometryLayer.js";export class TubeLayer extends c{constructor(t={}){super(t),this.options=t}createPrimitives(c,d){const m=this.options,f=new Map,g=(t,e)=>`${Math.round(100*t)},${Math.round(100*e)}`,w=this.features.map(t=>{const o=e(t.geometry)[0],r=o&&m.stand?.(t);return o&&r&&!1!==r.open&&f.set(g(o[0],o[1]),r.radius),o&&r?{point:o,stand:r}:null}),v=this.addRole((t,e,r,i,n)=>{const s=w[e];n.color=this.colorOf(r.color,r.opacity,i,"#4cc9f0"),n.material=a(r.material),n.weight=r.weight??1,n.fadedWeight=.3*(r.weight??1),n.flags=r.flow?o.Flow:0,s?(n.width=2*s.stand.radius,n.meters=!0):(n.width=r.width??2.5,n.meters=!1,n.realWidth=2*l(m.profile?.(t))[0])}),k=[],y=[];if(w.forEach((t,e)=>{t&&!1!==t.stand.open&&!1!==m.covers&&y.push({x:t.point[0]-d[0],y:t.point[1]-d[1],z:t.stand.top-d[2]+.01,cell:i.Cover,index:e})}),"2d"===c.mode){const e=[],o=new Float32Array(2*this.features.length);return this.features.forEach((r,i)=>{e.push(t(r.geometry).filter(t=>t.length>1).map(t=>{const e=t[0],r=t[t.length-1];return o[2*i]=f.get(g(e[0],e[1]))??0,o[2*i+1]=f.get(g(r[0],r[1]))??0,t.map(t=>({x:t[0]-d[0],y:t[1]-d[1],z:0}))}))}),k.push(new n(e,{look:v,pick:this.pick??void 0,arrows:!!m.arrows,ends:o})),y.length>0&&k.push(new r(y.map(t=>({...t,z:0})),null,1,{look:v,pick:this.pick??void 0,minPixels:7})),k}const x=[],j=!1!==m.join;this.features.forEach((e,o)=>{const r=m.reach?.(e)??0,i=w[o];if(i){const{point:t,stand:e}=i;return void x.push({points:[[t[0]-d[0],t[1]-d[1],e.bottom-d[2]],[t[0]-d[0],t[1]-d[1],e.top-d[2]]],index:o,profile:h(e.radius),reach:r,kind:!1===e.open?"column":"shaft"})}const n=l(m.profile?.(e));for(const i of t(e.geometry)){if(i.length<2)continue;let t=i.map(t=>[t[0]-d[0],t[1]-d[1],(t[2]??0)-d[2]]);const e=[0,0];if(j){const o=f.get(g(i[0][0],i[0][1])),r=f.get(g(i[i.length-1][0],i[i.length-1][1]));o&&o>n[0]&&(e[0]=Math.sqrt(o*o-n[0]*n[0]),t=u(t,e[0])),r&&r>n[0]&&(e[1]=Math.sqrt(r*r-n[0]*n[0]),t=u(t.reverse(),e[1]).reverse())}t.length<2||x.push({points:t,index:o,profile:n,reach:r,cuts:e})}}),j&&p(x,.01);const M=!1!==m.ghost;M&&c.engine.depthTexture();const G=new s(x,{look:v,lighting:c.lighting,up:c.up,pick:this.pick??void 0,arrows:!!m.arrows,sceneDepth:M?c.engine.sceneDepth:null,occluder:this.occluder});return k.push(G),y.length>0&&k.push(new r(y,null,1,{look:v,pick:this.pick??void 0,orientation:"ground",up:c.up,depth:!0})),k}get primitive(){return this.primitives.find(t=>t instanceof s)??null}}function l(t){return void 0===t?h(.15):"number"==typeof t?h(t):t}function u(t,e){let o=e;for(let e=0;e<t.length-1;e++){const[r,i]=[t[e],t[e+1]],n=Math.hypot(i[0]-r[0],i[1]-r[1],i[2]-r[2]);if(n>o+.001){const s=o/n;return[[r[0]+(i[0]-r[0])*s,r[1]+(i[1]-r[1])*s,r[2]+(i[2]-r[2])*s],...t.slice(e+1)]}o-=n}return t}
1
+ import{linesOf as t,pointsOf as o}from"../data/Geometry.js";import{AxisIndex as e}from"../math/AxisIndex.js";import{LookFlag as r}from"../three/FeatureLook.js";import{GpuIcons as i,IconShape as s}from"../three/primitives/GpuIcons.js";import{GpuLines as n}from"../three/primitives/GpuLines.js";import{GpuTubes as p,joinTubeEnds as h,roundProfile as a}from"../three/primitives/GpuTubes.js";import{materialCode as c}from"../three/Shading.js";import{GeometryLayer as u}from"./GeometryLayer.js";export function standAxis(t,o){return"foot"in o?[[...o.foot],[...o.top]]:[[t[0],t[1],o.bottom],[t[0],t[1],o.top]]}export class TubeLayer extends u{constructor(t={}){super(t),this.options=t}createPrimitives(u,d){const m=this.options,g=[],w=this.features.map(t=>{const e=o(t.geometry)[0],r=e&&m.stand?.(t);if(!e||!r)return null;const[i,s]=standAxis(e,r);return!1!==r.open&&g.push({foot:i,top:s,radius:r.radius}),{stand:r,foot:i,top:s}}),v=new e(g,m.joinTolerance??.05),k=(t,o)=>v.at(t,o)?.radius,x=this.addRole((t,o,e,i,s)=>{const n=w[o];s.color=this.colorOf(e.color,e.opacity,i,"#4cc9f0"),s.material=c(e.material),s.weight=e.weight??1,s.fadedWeight=.3*(e.weight??1),s.flags=e.flow?r.Flow:0,n?(s.width=2*n.stand.radius,s.meters=!0):(s.width=e.width??2.5,s.meters=!1,s.realWidth=2*l(m.profile?.(t))[0])}),y=[],j=[];if(w.forEach((t,o)=>{if(t&&!1!==t.stand.open&&!1!==m.covers){const[e,r,i]=[t.top[0]-t.foot[0],t.top[1]-t.foot[1],(t.top[2]??0)-(t.foot[2]??0)],n=.01/(Math.hypot(e,r,i)||1);j.push({x:t.top[0]+e*n-d[0],y:t.top[1]+r*n-d[1],z:(t.top[2]??0)+i*n-d[2],cell:s.Cover,index:o})}}),"2d"===u.mode){const o=[],e=new Float32Array(2*this.features.length);return this.features.forEach((r,i)=>{o.push(t(r.geometry).filter(t=>t.length>1).map(t=>{const o=t[0],r=t[t.length-1];return e[2*i]=k(o,!0)??0,e[2*i+1]=k(r,!0)??0,t.map(t=>({x:t[0]-d[0],y:t[1]-d[1],z:0}))}))}),y.push(new n(o,{look:x,pick:this.pick??void 0,arrows:!!m.arrows,ends:e})),j.length>0&&y.push(new i(j.map(t=>({...t,z:0})),null,1,{look:x,pick:this.pick??void 0,minPixels:7})),y}const G=[],b=!1!==m.join;this.features.forEach((o,e)=>{const r=m.reach?.(o)??0,i=w[e];if(i){const{stand:t,foot:o,top:s}=i;return void G.push({points:[[o[0]-d[0],o[1]-d[1],(o[2]??0)-d[2]],[s[0]-d[0],s[1]-d[1],(s[2]??0)-d[2]]],index:e,profile:a(t.radius),reach:r,kind:!1===t.open?"column":"shaft"})}const s=l(m.profile?.(o));for(const i of t(o.geometry)){if(i.length<2)continue;let t=i.map(t=>[t[0]-d[0],t[1]-d[1],(t[2]??0)-d[2]]);const o=[0,0];if(b){const e=k(i[0],!1),r=k(i[i.length-1],!1);e&&e>s[0]&&(o[0]=Math.sqrt(e*e-s[0]*s[0]),t=f(t,o[0])),r&&r>s[0]&&(o[1]=Math.sqrt(r*r-s[0]*s[0]),t=f(t.reverse(),o[1]).reverse())}t.length<2||G.push({points:t,index:e,profile:s,reach:r,cuts:o})}}),b&&h(G,.01);const A=!1!==m.ghost;A&&u.engine.depthTexture();const L=new p(G,{look:x,lighting:u.lighting,up:u.up,pick:this.pick??void 0,arrows:!!m.arrows,sceneDepth:A?u.engine.sceneDepth:null,occluder:this.occluder});return y.push(L),j.length>0&&y.push(new i(j,null,1,{look:x,pick:this.pick??void 0,orientation:"ground",up:u.up,depth:!0})),y}get primitive(){return this.primitives.find(t=>t instanceof p)??null}}function l(t){return void 0===t?a(.15):"number"==typeof t?a(t):t}function f(t,o){let e=o;for(let o=0;o<t.length-1;o++){const[r,i]=[t[o],t[o+1]],s=Math.hypot(i[0]-r[0],i[1]-r[1],i[2]-r[2]);if(s>e+.001){const n=e/s;return[[r[0]+(i[0]-r[0])*n,r[1]+(i[1]-r[1])*n,r[2]+(i[2]-r[2])*n],...t.slice(o+1)]}e-=s}return t}
@@ -0,0 +1,22 @@
1
+ /** An axis from its foot to its top - a shaft's, a pole's - and how wide what stands on it is. */
2
+ export interface Axis {
3
+ foot: readonly number[];
4
+ top: readonly number[];
5
+ radius: number;
6
+ }
7
+ /**
8
+ * Axes - shafts standing anywhere, along any direction - found from a point on or near them: what
9
+ * shaft a pipe's end lies in. In 3D a point is on an axis within `tolerance` of the line through
10
+ * it, and no further along it than a radius past either end; on a flat map (`flat`) by its x and y
11
+ * alone, so a line at any height finds the shaft it ends at. Works in any world: level x, y and z
12
+ * up, or geocentric, where a shaft stands along the ellipsoid's up and x, y say nothing by
13
+ * themselves.
14
+ */
15
+ export declare class AxisIndex<A extends Axis = Axis> {
16
+ readonly axes: readonly A[];
17
+ readonly tolerance: number;
18
+ private readonly index;
19
+ constructor(axes: readonly A[], tolerance?: number);
20
+ /** The axis a point lies on - the nearest, where several are in reach - or null. */
21
+ at(p: readonly number[], flat?: boolean): A | null;
22
+ }
@@ -0,0 +1 @@
1
+ import{SpatialIndex as t}from"./SpatialIndex.js";export class AxisIndex{constructor(o,n=.05){this.axes=o,this.tolerance=n,this.index=new t;for(const t of o){const o=n+t.radius;this.index.add(Math.min(t.foot[0],t.top[0])-o,Math.min(t.foot[1],t.top[1])-o,Math.max(t.foot[0],t.top[0])+o,Math.max(t.foot[1],t.top[1])+o)}this.index.finish()}at(t,s=!1){const i=this.tolerance;let a=null,h=1/0;for(const e of this.index.search(t[0]-i,t[1]-i,t[0]+i,t[1]+i)){const r=this.axes[e],c=s?n(t,r):o(t,r);c<=i&&c<h&&(a=r,h=c)}return a}}function o(t,o){const n=o.foot,s=o.top,i=s[0]-n[0],a=s[1]-n[1],h=(s[2]??0)-(n[2]??0),e=Math.hypot(i,a,h),r=t[0]-n[0],c=t[1]-n[1],f=(t[2]??0)-(n[2]??0);if(e<1e-9)return Math.hypot(r,c,f);const p=(r*i+c*a+f*h)/e;if(p<-o.radius||p>e+o.radius)return 1/0;const x=p/e;return Math.hypot(r-i*x,c-a*x,f-h*x)}function n(t,o){const n=o.foot,s=o.top,i=s[0]-n[0],a=s[1]-n[1],h=i*i+a*a,e=t[0]-n[0],r=t[1]-n[1],c=h<1e-18?0:Math.max(0,Math.min(1,(e*i+r*a)/h));return Math.hypot(e-i*c,r-a*c)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protomaze/geometry",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Protomaze Geometry: GPU points, lines, tubes and areas in 2D and 3D, styled, filtered, highlighted and picked on the GPU",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +1 @@
1
- import{DoubleSide as e,Float32BufferAttribute as t,InstancedBufferAttribute as s,InstancedBufferGeometry as n,Mesh as a,Vector3 as r}from"three/webgpu";import{abs as o,attribute as i,cameraProjectionMatrix as l,clamp as h,cross as u,Discard as c,dot as d,float as m,Fn as p,If as f,int as g,length as w,max as b,min as y,mix as v,normalize as M,positionGeometry as x,sign as T,uniform as A,varyingProperty as k,vec2 as z,vec3 as E,vec4 as S,viewport as F}from"three/tsl";import{FeatureLook as I}from"../FeatureLook.js";import{Lighting as R}from"../Shading.js";import{adoptGeometry as j,disposeMaterial as C,GONE as P,nodeMaterial as N,unculled as q}from"../Tsl.js";import{bodyFragment as W,bodyMaterial as X,bodyUniforms as Y,bodyVaryings as B,HALO_GROW as D,pixelSize as G}from"./Body.js";import{ARROW_LENGTH as V,ARROW_MIN_HALF_HEIGHT as $,ARROW_OUTLINE as L}from"./GpuLines.js";export function roundProfile(e){return[e,e,e]}export function boxProfile(e,t,s=.5){return[e/2,t/2,Math.min(e,t)/2*s]}const U={line:0,shaft:1,column:2};export class GpuTubes{constructor(e,o={}){this.options=o,this.arrowMesh=null,this.uniforms=Y(),this.near=A(.3),this.shaftReach=A(1e9),this.up=A(new r(0,0,1)),this.look=o.look??new I(o.count??e.reduce((e,t)=>Math.max(e,t.index+1),0)),this.lighting=o.lighting??new R,o.up&&(this.up.value.set(o.up[0],o.up[1],o.up[2]).normalize(),o.lighting||this.lighting.setUp(o.up));const i=function(e){let t=0;for(const s of e)t+=Math.max(0,s.points.length-1);const s={count:t,starts:new Float32Array(3*t),ends:new Float32Array(3*t),infos:new Float32Array(4*t),shapes:new Float32Array(4*t),befores:new Float32Array(3*t),afters:new Float32Array(3*t)};let n=0;for(const t of e){const e=t.points,a=e.length-1,r=U[t.kind??"line"],o=t.cuts??[0,0];for(let i=1;i<=a;i++){const l=e[i-1],h=e[i];s.starts[3*n]=l[0],s.starts[3*n+1]=l[1],s.starts[3*n+2]=l[2]??0,s.ends[3*n]=h[0],s.ends[3*n+1]=h[1],s.ends[3*n+2]=h[2]??0,s.infos[4*n]=t.index,s.infos[4*n+1]=1===i?o[0]:0,s.infos[4*n+2]=t.reach??0,s.infos[4*n+3]=r,s.shapes[4*n]=t.profile[0],s.shapes[4*n+1]=t.profile[1],s.shapes[4*n+2]=t.profile[2],s.shapes[4*n+3]=i===a?o[1]:0;const u=1===i?t.before:e[i-2],c=i===a?t.after:e[i+1];H(s.befores,n,u,l),H(s.afters,n,h,c),n++}}return s}(e);this.segments=i.count;const l=function(e){const a=function(){const e=[];return[[1,1],[-1,1],[-1,-1],[1,-1]].forEach(([t,s],n)=>{for(let a=0;a<=4;a++){const r=(n+a/4)*Math.PI/2;e.push({x:Math.cos(r),y:Math.sin(r),cornerX:t,cornerY:s})}}),e.push(e[0]),e}(),r=a.length-1,o=[],i=[],l=[];for(const e of a)o.push(e.x,e.y,0,e.x,e.y,1),i.push(e.cornerX,e.cornerY,0,e.cornerX,e.cornerY,0);for(let e=0;e<r;e++){const t=2*e;l.push(t,t+2,t+1,t+1,t+2,t+3)}for(const[e,t]of[[0,-1],[1,1]]){const s=o.length/3;o.push(0,0,e),i.push(0,0,t);for(const s of a)o.push(s.x,s.y,e),i.push(s.cornerX,s.cornerY,1e-4*t);for(let e=0;e<r;e++){const n=s+1+e;t>0?l.push(s,n,n+1):l.push(s,n+1,n)}}const h=new n;return h.setAttribute("position",new t(o,3)),h.setAttribute("cornerCap",new t(i,3)),h.setIndex(l),h.setAttribute("aStart",new s(e.starts,3)),h.setAttribute("aEnd",new s(e.ends,3)),h.setAttribute("aInfo",new s(e.infos,4)),h.setAttribute("aShape",new s(e.shapes,4)),h.setAttribute("aBefore",new s(e.befores,3)),h.setAttribute("aAfter",new s(e.afters,3)),h.instanceCount=e.count,h}(i);if(this.mesh=q(new a(l,this.cylinderMaterial("solid"))),this.haloMesh=o.sceneDepth?q(new a(l,this.cylinderMaterial("window"))):null,this.bloomMesh=q(new a(l,this.cylinderMaterial("bloom"))),this.bloomMesh.visible=!1,this.casingMesh=q(new a(l,this.cylinderMaterial("casing")),-1),this.casingMesh.visible=!1,this.pickMesh=o.pick?q(new a(l,this.cylinderMaterial("pick"))):null,this.densityMesh=q(new a(l,this.cylinderMaterial("density"))),this.densityMesh.visible=!1,o.arrows){const r=function(e){const t=e.filter(e=>"line"===(e.kind??"line")&&e.points.length>1);let s=0;for(const e of t)s+=e.points.length-1;const n={count:s,starts:new Float32Array(3*s),ends:new Float32Array(3*s),infos:new Float32Array(4*s),metas:new Float32Array(3*s)};let a=0;for(const e of t){const t=e.points;let s=0;for(let e=1;e<t.length;e++)s+=J(t[e-1],t[e]);let r=0;for(let o=1;o<t.length;o++){const[i,l]=[t[o-1],t[o]],h=J(i,l);n.starts.set([i[0],i[1],i[2]??0],3*a),n.ends.set([l[0],l[1],l[2]??0],3*a),n.infos.set([e.index,2*e.profile[0],e.reach??0,0],4*a),n.metas.set([r,r+h,s],3*a),r+=h,a++}}return n}(e);r.count>0&&(this.arrowMesh=q(new a(function(e){const a=new n;return a.setAttribute("position",new t([-1,0,0,1,0,0,1,1,0,-1,0,0,1,1,0,-1,1,0],3)),a.setAttribute("aStart",new s(e.starts,3)),a.setAttribute("aEnd",new s(e.ends,3)),a.setAttribute("aInfo",new s(e.infos,4)),a.setAttribute("aMeta",new s(e.metas,3)),a.instanceCount=e.count,a}(r),this.arrowMaterial()),1))}}passes(){return{scene:[this.casingMesh,this.mesh,this.arrowMesh],halo:[this.haloMesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){const t=this.uniforms;t.pixelRatio.value=e.pixelRatio,t.pxPerWorld.value=e.pxPerWorld,t.orthographic.value=e.orthographic?1:0,e.focal&&(t.focal.value=e.focal),this.near.value=e.near,e.eye&&this.lighting.eye.value.copy(e.eye)}meshes(){return[this.mesh,this.haloMesh,this.bloomMesh,this.casingMesh,this.pickMesh,this.densityMesh,this.arrowMesh]}adopt(e){return!!(e instanceof GpuTubes&&j(this.meshes(),e.meshes()))&&(this.segments=e.segments,!0)}dispose(){this.mesh.geometry.dispose(),this.arrowMesh?.geometry.dispose(),this.meshes().forEach(C),this.options.look||this.look.dispose()}cylinderMaterial(e){const t="pick"===e,s=X(e),{up:n,near:a,look:r}=this,h=this.uniforms,{vColor:c,vNormal:f,vDistance:x,vPosition:A,vMaterial:k,vIndex:F}=B(),I=this.options.pick;return s.vertexNode=p(()=>{const s=i("aStart","vec3"),p=i("aEnd","vec3"),R=i("aInfo","vec4"),j=i("aShape","vec4"),C=i("position","vec3"),N=i("cornerCap","vec3"),q=N.xy,W=N.z,X=i("aBefore","vec3"),Y=i("aAfter","vec3"),B=r.read(g(R.x)),V=B.selected,$=V.select(B.strength,B.alpha),L=V.select(v(B.rgb,E(1,1,1),h.litMix),B.rgb),U=R.w.lessThan(.5),H=b(l.mul(S(s.add(p.sub(s).mul(C.z)),1)).w,a),J=G(h,H).mul(h.pixelRatio),K=B.width.mul(V.select(m(1.5),B.faded.select(m(.5),m(1)))),O="window"===e?m(0):U.select(J.mul(K).mul(.5),m(0)),Q=b(j.x,O),Z=b(j.y,O),_=b(j.z,O),ee=t?b(J.mul(4).sub(y(Q,Z)),0):"casing"===e?J.mul(h.outlineWidth):m("window"===e?D:0),te=Q.add(ee),se=Z.add(ee),ne=_.add(ee),ae=p.sub(s),re=M(ae),oe=C.z.greaterThan(.5),ie=oe.select(j.w,R.y),le="density"===e?m(0):b(te,se),he=ie.greaterThan(0).and(H.greaterThan(this.shaftReach)).select(ie.add(le),m(0)),ue=oe.select(he,he.negate()),ce=R.w.greaterThan(.5).or(o(d(re,n)).greaterThan(.95)),de=M(ce.select(u(re,E(1,0,0)),u(re,n))),me=u(re,de),pe=de.mul(C.x).add(me.mul(C.y)),fe=q.x.mul(te.sub(ne)).add(C.x.mul(ne)),ge=q.y.mul(se.sub(ne)).add(C.y.mul(ne)),we=de.mul(fe).add(me.mul(ge)).mul(m(1).sub(o(W))),be=oe.select(Y,X),ye=M(oe.select(re.add(Y),X.add(re))),ve=w(be).greaterThan(.5).select(d(we,ye).negate().div(b(d(re,ye),.26)),m(0)),Me=t?ce.select(ee,m(0)):m(0),xe=s.add(ae.mul(C.z)).add(re.mul(ve.add(ue).add(C.z.mul(2).sub(1).mul(Me)))).add(we),Te=l.mul(S(xe,1)),Ae=l.mul(S(xe.add(M(xe.sub(this.lighting.eye)).mul(b(te,se).mul(2))),1)),ke="casing"===e?S(Te.x,Te.y,Ae.z.div(Ae.w).mul(Te.w),Te.w):Te;c.assign(S(L,"density"===e?B.weight:$)),f.assign(o(W).greaterThan(1e-5).select(re.mul(T(W)),pe)),x.assign(ke.w),A.assign(xe),F.assign(R.x),k.assign(z(B.material,V.select(m(1),m(0))));const ze=R.z;return $.lessThan(.001).or(ze.greaterThan(0).and(ke.w.greaterThan(ze))).or(w(ae).lessThan(1e-4)).or("bloom"===e||"casing"===e?V.not():m(0).greaterThan(1)).or("density"===e?B.weight.lessThan(.001):m(0).greaterThan(1)).or(t?B.pickable.not():m(0).greaterThan(1)).or("window"===e?m(0).greaterThan(1):R.w.greaterThan(.5).and(R.w.lessThan(1.5)).and(W.greaterThan(0))).select(P(),t&&I?I.pass.window.mul(ke):ke)})(),s.fragmentNode=W(e,this.options,h,this.lighting),s}arrowMaterial(){const t=N();t.transparent=!0,t.side=e,t.depthTest=!0,t.depthWrite=!1;const s=this.options.occluder,n=this.uniforms,{near:a,look:r}=this,u=k("vec4","vColor"),d=k("float","vDistance"),T=k("float","vAcross"),A=k("vec3","vArrow"),I=k("float","vSegment");return t.vertexNode=p(()=>{const e=i("aInfo","vec4"),t=g(e.x),s=r.read(t),o=l.mul(S(i("aStart","vec3"),1)).toVar(),c=l.mul(S(i("aEnd","vec3"),1)).toVar(),p=a.mul(1.5);f(o.w.lessThan(p),()=>{o.assign(v(o,c,h(p.sub(o.w).div(c.w.sub(o.w)),0,1)))}),f(c.w.lessThan(p),()=>{c.assign(v(c,o,h(p.sub(c.w).div(o.w.sub(c.w)),0,1)))});const y=F.zw,k=o.xy.div(o.w).mul(.5).add(.5).mul(y),R=c.xy.div(c.w).mul(.5).add(.5).mul(y),j=R.sub(k),C=M(w(j).greaterThan(1e-6).select(j,z(1,0))),N=z(C.y.negate(),C.x),q=x.y.greaterThan(.5),W=q.select(c.w,o.w),X=i("aMeta","vec3"),Y=w(j),B=Y.div(b(X.y.sub(X.x),.001)),D=n.pixelRatio,G=b(s.width,m($)).mul(D),U=D.mul(V),H=U.mul(.25),J=X.z.mul(.5),K=U.mul(.5).add(H).div(b(B,1e-6)),O=J.greaterThanEqual(X.x.sub(K)).and(J.lessThan(X.y.add(K))).and(X.z.mul(B).greaterThanEqual(U.mul(3).add(H.mul(2)))),Q=J.sub(X.x).mul(B),Z=G.add(D.mul(L+1)),_=q.select(R,k).add(N.mul(x.x.mul(Z)));u.assign(S(s.rgb,s.alpha)),d.assign(W),T.assign(x.x.mul(Z)),A.assign(E(q.select(Y,m(0)),G,Q)),I.assign(Y);const ee=o.w.lessThan(p).and(c.w.lessThan(p)),te=e.z,se=ee.or(s.alpha.lessThan(.001)).or(s.faded).or(te.greaterThan(0).and(W.greaterThan(te))).or(O.not()),ne=v(i("aStart","vec3"),i("aEnd","vec3"),h(Q.div(b(Y,1e-6)),0,1)),ae=l.mul(S(ne.add(M(this.lighting.eye.sub(ne)).mul(e.y.add(.05))),1)),re=ae.z.div(b(ae.w,1e-6));return se.select(P(),S(_.div(y).mul(2).sub(1),re,1))})(),t.fragmentNode=p(()=>{s&&f(s.hides(d).toVar(),()=>{c()});const e=n.pixelRatio,t=A.x,a=o(T),r=A.y,i=e.mul(V),l=t.sub(A.z.sub(i.mul(.5))),p=r.mul(m(1).sub(l.div(i))),g=y(y(l,i.sub(l)),p.sub(a)),w=t.greaterThanEqual(-.5).and(t.lessThanEqual(I.add(.5))).select(m(1),m(0)),M=h(g.add(.5),0,1).mul(w),x=h(g.add(e.mul(L)).add(.5),0,1).mul(w);return f(x.lessThan(.002),()=>{c()}),S(v(E(0,0,0),u.xyz,M.div(b(x,.001))),x.mul(u.w))})(),t}}export function joinTubeEnds(e,t=.001){const s=e=>`${Math.round(e[0]/t)},${Math.round(e[1]/t)},${Math.round((e[2]??0)/t)}`,n=new Map;return e.forEach(e=>{if("line"!==(e.kind??"line")||e.points.length<2)return;const t=s(e.points[0]),a=s(e.points[e.points.length-1]);n.set(t,[...n.get(t)??[],{tube:e,atStart:!0}]),n.set(a,[...n.get(a)??[],{tube:e,atStart:!1}])}),n.forEach(e=>{if(2!==e.length)return;const[t,s]=e,n=e=>e.atStart?e.tube.points[1]:e.tube.points[e.tube.points.length-2],a=(e,t)=>{var s,n;e.atStart?(s=e.tube).before??(s.before=t):(n=e.tube).after??(n.after=t)};a(t,n(s)),a(s,n(t))}),e}function H(e,t,s,n){if(!s||!n)return;const a=n[0]-s[0],r=n[1]-s[1],o=(n[2]??0)-(s[2]??0),i=Math.hypot(a,r,o);i<=1e-6||(e[3*t]=a/i,e[3*t+1]=r/i,e[3*t+2]=o/i)}function J(e,t){return Math.hypot(t[0]-e[0],t[1]-e[1],(t[2]??0)-(e[2]??0))}
1
+ import{DoubleSide as e,Float32BufferAttribute as t,InstancedBufferAttribute as s,InstancedBufferGeometry as n,Mesh as a,Vector3 as r}from"three/webgpu";import{abs as o,attribute as i,cameraProjectionMatrix as l,clamp as h,cross as u,Discard as c,dot as d,float as m,Fn as p,If as f,int as g,length as w,max as b,min as y,mix as v,normalize as M,positionGeometry as x,sign as T,uniform as A,varyingProperty as k,vec2 as z,vec3 as E,vec4 as S,viewport as F}from"three/tsl";import{FeatureLook as I}from"../FeatureLook.js";import{Lighting as R}from"../Shading.js";import{adoptGeometry as j,disposeMaterial as C,GONE as P,nodeMaterial as N,unculled as q}from"../Tsl.js";import{bodyFragment as V,bodyMaterial as W,bodyUniforms as X,bodyVaryings as Y,HALO_GROW as B,pixelSize as D}from"./Body.js";import{ARROW_LENGTH as G,ARROW_MIN_HALF_HEIGHT as $,ARROW_OUTLINE as L}from"./GpuLines.js";export function roundProfile(e){return[e,e,e]}export function boxProfile(e,t,s=.5){return[e/2,t/2,Math.min(e,t)/2*s]}const U={line:0,shaft:1,column:2};export class GpuTubes{constructor(e,o={}){this.options=o,this.arrowMesh=null,this.uniforms=X(),this.near=A(.3),this.shaftReach=A(1e9),this.up=A(new r(0,0,1)),this.look=o.look??new I(o.count??e.reduce((e,t)=>Math.max(e,t.index+1),0)),this.lighting=o.lighting??new R,o.up&&(this.up.value.set(o.up[0],o.up[1],o.up[2]).normalize(),o.lighting||this.lighting.setUp(o.up));const i=function(e){let t=0;for(const s of e)t+=Math.max(0,s.points.length-1);const s={count:t,starts:new Float32Array(3*t),ends:new Float32Array(3*t),infos:new Float32Array(4*t),shapes:new Float32Array(4*t),befores:new Float32Array(3*t),afters:new Float32Array(3*t)};let n=0;for(const t of e){const e=t.points,a=e.length-1,r=U[t.kind??"line"],o=t.cuts??[0,0];for(let i=1;i<=a;i++){const l=e[i-1],h=e[i];s.starts[3*n]=l[0],s.starts[3*n+1]=l[1],s.starts[3*n+2]=l[2]??0,s.ends[3*n]=h[0],s.ends[3*n+1]=h[1],s.ends[3*n+2]=h[2]??0,s.infos[4*n]=t.index,s.infos[4*n+1]=1===i?o[0]:0,s.infos[4*n+2]=t.reach??0,s.infos[4*n+3]=r,s.shapes[4*n]=t.profile[0],s.shapes[4*n+1]=t.profile[1],s.shapes[4*n+2]=t.profile[2],s.shapes[4*n+3]=i===a?o[1]:0;const u=1===i?t.before:e[i-2],c=i===a?t.after:e[i+1];H(s.befores,n,u,l),H(s.afters,n,h,c),n++}}return s}(e);this.segments=i.count;const l=function(e){const a=function(){const e=[];return[[1,1],[-1,1],[-1,-1],[1,-1]].forEach(([t,s],n)=>{for(let a=0;a<=4;a++){const r=(n+a/4)*Math.PI/2;e.push({x:Math.cos(r),y:Math.sin(r),cornerX:t,cornerY:s})}}),e.push(e[0]),e}(),r=a.length-1,o=[],i=[],l=[];for(const e of a)o.push(e.x,e.y,0,e.x,e.y,1),i.push(e.cornerX,e.cornerY,0,e.cornerX,e.cornerY,0);for(let e=0;e<r;e++){const t=2*e;l.push(t,t+2,t+1,t+1,t+2,t+3)}for(const[e,t]of[[0,-1],[1,1]]){const s=o.length/3;o.push(0,0,e),i.push(0,0,t);for(const s of a)o.push(s.x,s.y,e),i.push(s.cornerX,s.cornerY,1e-4*t);for(let e=0;e<r;e++){const n=s+1+e;t>0?l.push(s,n,n+1):l.push(s,n+1,n)}}const h=new n;return h.setAttribute("position",new t(o,3)),h.setAttribute("cornerCap",new t(i,3)),h.setIndex(l),h.setAttribute("aStart",new s(e.starts,3)),h.setAttribute("aEnd",new s(e.ends,3)),h.setAttribute("aInfo",new s(e.infos,4)),h.setAttribute("aShape",new s(e.shapes,4)),h.setAttribute("aBefore",new s(e.befores,3)),h.setAttribute("aAfter",new s(e.afters,3)),h.instanceCount=e.count,h}(i);if(this.mesh=q(new a(l,this.cylinderMaterial("solid"))),this.haloMesh=o.sceneDepth?q(new a(l,this.cylinderMaterial("window"))):null,this.bloomMesh=q(new a(l,this.cylinderMaterial("bloom"))),this.bloomMesh.visible=!1,this.casingMesh=q(new a(l,this.cylinderMaterial("casing")),-1),this.casingMesh.visible=!1,this.pickMesh=o.pick?q(new a(l,this.cylinderMaterial("pick"))):null,this.densityMesh=q(new a(l,this.cylinderMaterial("density"))),this.densityMesh.visible=!1,o.arrows){const r=function(e){const t=e.filter(e=>"line"===(e.kind??"line")&&e.points.length>1);let s=0;for(const e of t)s+=e.points.length-1;const n={count:s,starts:new Float32Array(3*s),ends:new Float32Array(3*s),infos:new Float32Array(4*s),metas:new Float32Array(3*s)};let a=0;for(const e of t){const t=e.points;let s=0;for(let e=1;e<t.length;e++)s+=J(t[e-1],t[e]);let r=0;for(let o=1;o<t.length;o++){const[i,l]=[t[o-1],t[o]],h=J(i,l);n.starts.set([i[0],i[1],i[2]??0],3*a),n.ends.set([l[0],l[1],l[2]??0],3*a),n.infos.set([e.index,2*e.profile[0],e.reach??0,0],4*a),n.metas.set([r,r+h,s],3*a),r+=h,a++}}return n}(e);r.count>0&&(this.arrowMesh=q(new a(function(e){const a=new n;return a.setAttribute("position",new t([-1,0,0,1,0,0,1,1,0,-1,0,0,1,1,0,-1,1,0],3)),a.setAttribute("aStart",new s(e.starts,3)),a.setAttribute("aEnd",new s(e.ends,3)),a.setAttribute("aInfo",new s(e.infos,4)),a.setAttribute("aMeta",new s(e.metas,3)),a.instanceCount=e.count,a}(r),this.arrowMaterial()),1))}}passes(){return{scene:[this.casingMesh,this.mesh,this.arrowMesh],halo:[this.haloMesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){const t=this.uniforms;t.pixelRatio.value=e.pixelRatio,t.pxPerWorld.value=e.pxPerWorld,t.orthographic.value=e.orthographic?1:0,e.focal&&(t.focal.value=e.focal),this.near.value=e.near,e.eye&&this.lighting.eye.value.copy(e.eye)}meshes(){return[this.mesh,this.haloMesh,this.bloomMesh,this.casingMesh,this.pickMesh,this.densityMesh,this.arrowMesh]}adopt(e){return!!(e instanceof GpuTubes&&j(this.meshes(),e.meshes()))&&(this.segments=e.segments,!0)}dispose(){this.mesh.geometry.dispose(),this.arrowMesh?.geometry.dispose(),this.meshes().forEach(C),this.options.look||this.look.dispose()}cylinderMaterial(e){const t="pick"===e,s=W(e),{up:n,near:a,look:r}=this,h=this.uniforms,{vColor:c,vNormal:f,vDistance:x,vPosition:A,vMaterial:k,vIndex:F}=Y(),I=this.options.pick;return s.vertexNode=p(()=>{const s=i("aStart","vec3"),p=i("aEnd","vec3"),R=i("aInfo","vec4"),j=i("aShape","vec4"),C=i("position","vec3"),N=i("cornerCap","vec3"),q=N.xy,V=N.z,W=i("aBefore","vec3"),X=i("aAfter","vec3"),Y=r.read(g(R.x)),G=Y.selected,$=G.select(Y.strength,Y.alpha),L=G.select(v(Y.rgb,E(1,1,1),h.litMix),Y.rgb),U=R.w.lessThan(.5),H=b(l.mul(S(s.add(p.sub(s).mul(C.z)),1)).w,a),J=D(h,H).mul(h.pixelRatio),K=Y.width.mul(G.select(m(1.5),Y.faded.select(m(.5),m(1)))),O="window"===e?m(0):U.select(J.mul(K).mul(.5),m(0)),Q=b(j.x,O),Z=b(j.y,O),_=b(j.z,O),ee=t?b(J.mul(4).sub(y(Q,Z)),0):"casing"===e?J.mul(h.outlineWidth):m("window"===e?B:0),te=Q.add(ee),se=Z.add(ee),ne=_.add(ee),ae=p.sub(s),re=M(ae),oe=C.z.greaterThan(.5),ie=oe.select(j.w,R.y),le="density"===e?m(0):b(te,se),he=ie.greaterThan(0).and(H.greaterThan(this.shaftReach)).select(ie.add(le),m(0)),ue=oe.select(he,he.negate()),ce=R.w.greaterThan(.5).or(o(d(re,n)).greaterThan(.95)),de=o(re.x).greaterThan(.9).select(E(0,1,0),E(1,0,0)).toVar(),me=M(ce.select(u(re,de),u(re,n))),pe=u(re,me),fe=me.mul(C.x).add(pe.mul(C.y)),ge=q.x.mul(te.sub(ne)).add(C.x.mul(ne)),we=q.y.mul(se.sub(ne)).add(C.y.mul(ne)),be=me.mul(ge).add(pe.mul(we)).mul(m(1).sub(o(V))),ye=oe.select(X,W),ve=M(oe.select(re.add(X),W.add(re))),Me=w(ye).greaterThan(.5).select(d(be,ve).negate().div(b(d(re,ve),.26)),m(0)),xe=t?ce.select(ee,m(0)):m(0),Te=s.add(ae.mul(C.z)).add(re.mul(Me.add(ue).add(C.z.mul(2).sub(1).mul(xe)))).add(be),Ae=l.mul(S(Te,1)),ke=l.mul(S(Te.add(M(Te.sub(this.lighting.eye)).mul(b(te,se).mul(2))),1)),ze="casing"===e?S(Ae.x,Ae.y,ke.z.div(ke.w).mul(Ae.w),Ae.w):Ae;c.assign(S(L,"density"===e?Y.weight:$)),f.assign(o(V).greaterThan(1e-5).select(re.mul(T(V)),fe)),x.assign(ze.w),A.assign(Te),F.assign(R.x),k.assign(z(Y.material,G.select(m(1),m(0))));const Ee=R.z;return $.lessThan(.001).or(Ee.greaterThan(0).and(ze.w.greaterThan(Ee))).or(w(ae).lessThan(1e-4)).or("bloom"===e||"casing"===e?G.not():m(0).greaterThan(1)).or("density"===e?Y.weight.lessThan(.001):m(0).greaterThan(1)).or(t?Y.pickable.not():m(0).greaterThan(1)).or("window"===e?m(0).greaterThan(1):R.w.greaterThan(.5).and(R.w.lessThan(1.5)).and(V.greaterThan(0))).select(P(),t&&I?I.pass.window.mul(ze):ze)})(),s.fragmentNode=V(e,this.options,h,this.lighting),s}arrowMaterial(){const t=N();t.transparent=!0,t.side=e,t.depthTest=!0,t.depthWrite=!1;const s=this.options.occluder,n=this.uniforms,{near:a,look:r}=this,u=k("vec4","vColor"),d=k("float","vDistance"),T=k("float","vAcross"),A=k("vec3","vArrow"),I=k("float","vSegment");return t.vertexNode=p(()=>{const e=i("aInfo","vec4"),t=g(e.x),s=r.read(t),o=l.mul(S(i("aStart","vec3"),1)).toVar(),c=l.mul(S(i("aEnd","vec3"),1)).toVar(),p=a.mul(1.5);f(o.w.lessThan(p),()=>{o.assign(v(o,c,h(p.sub(o.w).div(c.w.sub(o.w)),0,1)))}),f(c.w.lessThan(p),()=>{c.assign(v(c,o,h(p.sub(c.w).div(o.w.sub(c.w)),0,1)))});const y=F.zw,k=o.xy.div(o.w).mul(.5).add(.5).mul(y),R=c.xy.div(c.w).mul(.5).add(.5).mul(y),j=R.sub(k),C=M(w(j).greaterThan(1e-6).select(j,z(1,0))),N=z(C.y.negate(),C.x),q=x.y.greaterThan(.5),V=q.select(c.w,o.w),W=i("aMeta","vec3"),X=w(j),Y=X.div(b(W.y.sub(W.x),.001)),B=n.pixelRatio,D=b(s.width,m($)).mul(B),U=B.mul(G),H=U.mul(.25),J=W.z.mul(.5),K=U.mul(.5).add(H).div(b(Y,1e-6)),O=J.greaterThanEqual(W.x.sub(K)).and(J.lessThan(W.y.add(K))).and(W.z.mul(Y).greaterThanEqual(U.mul(3).add(H.mul(2)))),Q=J.sub(W.x).mul(Y),Z=D.add(B.mul(L+1)),_=q.select(R,k).add(N.mul(x.x.mul(Z)));u.assign(S(s.rgb,s.alpha)),d.assign(V),T.assign(x.x.mul(Z)),A.assign(E(q.select(X,m(0)),D,Q)),I.assign(X);const ee=o.w.lessThan(p).and(c.w.lessThan(p)),te=e.z,se=ee.or(s.alpha.lessThan(.001)).or(s.faded).or(te.greaterThan(0).and(V.greaterThan(te))).or(O.not()),ne=v(i("aStart","vec3"),i("aEnd","vec3"),h(Q.div(b(X,1e-6)),0,1)),ae=l.mul(S(ne.add(M(this.lighting.eye.sub(ne)).mul(e.y.add(.05))),1)),re=ae.z.div(b(ae.w,1e-6));return se.select(P(),S(_.div(y).mul(2).sub(1),re,1))})(),t.fragmentNode=p(()=>{s&&f(s.hides(d).toVar(),()=>{c()});const e=n.pixelRatio,t=A.x,a=o(T),r=A.y,i=e.mul(G),l=t.sub(A.z.sub(i.mul(.5))),p=r.mul(m(1).sub(l.div(i))),g=y(y(l,i.sub(l)),p.sub(a)),w=t.greaterThanEqual(-.5).and(t.lessThanEqual(I.add(.5))).select(m(1),m(0)),M=h(g.add(.5),0,1).mul(w),x=h(g.add(e.mul(L)).add(.5),0,1).mul(w);return f(x.lessThan(.002),()=>{c()}),S(v(E(0,0,0),u.xyz,M.div(b(x,.001))),x.mul(u.w))})(),t}}export function joinTubeEnds(e,t=.001){const s=e=>`${Math.round(e[0]/t)},${Math.round(e[1]/t)},${Math.round((e[2]??0)/t)}`,n=new Map;return e.forEach(e=>{if("line"!==(e.kind??"line")||e.points.length<2)return;const t=s(e.points[0]),a=s(e.points[e.points.length-1]);n.set(t,[...n.get(t)??[],{tube:e,atStart:!0}]),n.set(a,[...n.get(a)??[],{tube:e,atStart:!1}])}),n.forEach(e=>{if(2!==e.length)return;const[t,s]=e,n=e=>e.atStart?e.tube.points[1]:e.tube.points[e.tube.points.length-2],a=(e,t)=>{var s,n;e.atStart?(s=e.tube).before??(s.before=t):(n=e.tube).after??(n.after=t)};a(t,n(s)),a(s,n(t))}),e}function H(e,t,s,n){if(!s||!n)return;const a=n[0]-s[0],r=n[1]-s[1],o=(n[2]??0)-(s[2]??0),i=Math.hypot(a,r,o);i<=1e-6||(e[3*t]=a/i,e[3*t+1]=r/i,e[3*t+2]=o/i)}function J(e,t){return Math.hypot(t[0]-e[0],t[1]-e[1],(t[2]??0)-(e[2]??0))}