@protomaze/geometry 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/engine/GeometryFrame.d.ts +7 -6
- package/index.d.ts +1 -0
- package/index.js +1 -1
- package/layers/TubeLayer.d.ts +20 -5
- package/layers/TubeLayer.js +1 -1
- package/math/AxisIndex.d.ts +22 -0
- package/math/AxisIndex.js +1 -0
- package/package.json +1 -1
- package/three/DensityMap.d.ts +4 -3
- package/three/FeatureLook.d.ts +17 -17
- package/three/Ground.d.ts +7 -6
- package/three/Halo.d.ts +3 -2
- package/three/Shading.d.ts +7 -6
- package/three/Sky.d.ts +8 -6
- package/three/Tsl.d.ts +9 -1
- package/three/primitives/Body.d.ts +15 -22
- package/three/primitives/GpuAreas.d.ts +9 -8
- package/three/primitives/GpuIcons.d.ts +6 -5
- package/three/primitives/GpuLines.d.ts +21 -20
- package/three/primitives/GpuSpheres.d.ts +3 -12
- package/three/primitives/GpuTubes.d.ts +5 -14
- package/three/primitives/GpuTubes.js +1 -1
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
|
|
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
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Mesh } from 'three/webgpu';
|
|
2
2
|
import { Matrix4, Vector2, Vector3 } from 'three/webgpu';
|
|
3
|
+
import type { Uniform } from '../three/Tsl';
|
|
3
4
|
/**
|
|
4
5
|
* What drawing in pixels or metres needs to know about the frame being drawn. An engine fills it
|
|
5
6
|
* in before every frame and hands it to each primitive's `setFrame`.
|
|
@@ -33,12 +34,12 @@ export interface GeometryFrame {
|
|
|
33
34
|
* top-left, for whatever looks things up by frame pixel (`screenCoordinate` there is the
|
|
34
35
|
* target's). Pixel sizes come from `frameSize`, never from `viewport`, which is the target's.
|
|
35
36
|
*/
|
|
36
|
-
export declare function pickPassUniforms():
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
export declare function pickPassUniforms(): PickPass;
|
|
38
|
+
export interface PickPass {
|
|
39
|
+
window: Uniform<Matrix4>;
|
|
40
|
+
origin: Uniform<Vector2>;
|
|
41
|
+
frameSize: Uniform<Vector2>;
|
|
42
|
+
}
|
|
42
43
|
/** What a primitive needs to be drawn into a pick pass: the pass, and the id it writes. */
|
|
43
44
|
export interface PickOptions {
|
|
44
45
|
pass: PickPass;
|
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";
|
package/layers/TubeLayer.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
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. */
|
package/layers/TubeLayer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{linesOf as t,pointsOf as
|
|
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
package/three/DensityMap.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Mesh, RenderTarget, Scene } from 'three/webgpu';
|
|
2
2
|
import { ColorRamp } from '../common/Colors';
|
|
3
|
+
import { Uniform } from './Tsl';
|
|
3
4
|
/**
|
|
4
5
|
* The heatmap: whatever is in `scene` adds its weight into a half-float target the frame's size,
|
|
5
6
|
* and one full-screen pass (`quad`, in the engine's scene, over everything) colours each pixel's
|
|
@@ -13,15 +14,15 @@ export declare class DensityMap {
|
|
|
13
14
|
private readonly colors;
|
|
14
15
|
private colorMap;
|
|
15
16
|
/** The sum that takes the top colour. */
|
|
16
|
-
readonly top:
|
|
17
|
+
readonly top: Uniform<number>;
|
|
17
18
|
/** The whole map's opacity. */
|
|
18
|
-
readonly opacity:
|
|
19
|
+
readonly opacity: Uniform<number>;
|
|
19
20
|
constructor(ramp?: ColorRamp);
|
|
20
21
|
/**
|
|
21
22
|
* The colours to colour the sum with: a ramp from 0 to `top`, or a colour map with
|
|
22
23
|
* `retrieveColor`, read from 0 to `top` as it is. Read again only when given another.
|
|
23
24
|
*/
|
|
24
|
-
setColorMap(colorMap: ColorRamp, top?:
|
|
25
|
+
setColorMap(colorMap: ColorRamp, top?: any): void;
|
|
25
26
|
/** Whether anything adds to the map this frame; the colouring pass is shown only then. */
|
|
26
27
|
update(): boolean;
|
|
27
28
|
/** Sums this frame's weights into the target, through `draw`, the engine's draw into a target. */
|
package/three/FeatureLook.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataTexture } from 'three/webgpu';
|
|
2
2
|
import { ColorLike, ColorRamp } from '../common/Colors';
|
|
3
|
-
import { N } from './Tsl';
|
|
3
|
+
import { N, Uniform } from './Tsl';
|
|
4
4
|
/**
|
|
5
5
|
* How a feature is drawn, from strongest to weakest: depth and the selection's glow follow it.
|
|
6
6
|
*/
|
|
@@ -116,30 +116,30 @@ export declare class FeatureLook {
|
|
|
116
116
|
readonly categories: DataTexture;
|
|
117
117
|
readonly ramp: DataTexture;
|
|
118
118
|
/** 1 while a range is applied: the GPU then decides pass or fail per feature. */
|
|
119
|
-
readonly rangeActive:
|
|
120
|
-
readonly rangeLow:
|
|
121
|
-
readonly rangeHigh:
|
|
119
|
+
readonly rangeActive: Uniform<number>;
|
|
120
|
+
readonly rangeLow: Uniform<number>;
|
|
121
|
+
readonly rangeHigh: Uniform<number>;
|
|
122
122
|
/** What a feature out of the range becomes: 0 its fail look (`setFail`), 1 hidden, 2 faded. */
|
|
123
|
-
readonly rangeOutside:
|
|
123
|
+
readonly rangeOutside: Uniform<number>;
|
|
124
124
|
/** The feature pointed at, -1 for none: drawn lit while `hoverLights`. */
|
|
125
|
-
readonly hoverIndex:
|
|
126
|
-
readonly hoverLights:
|
|
125
|
+
readonly hoverIndex: Uniform<number>;
|
|
126
|
+
readonly hoverLights: Uniform<number>;
|
|
127
127
|
/** 1 while the category table applies. */
|
|
128
|
-
readonly categoryActive:
|
|
128
|
+
readonly categoryActive: Uniform<number>;
|
|
129
129
|
/** 0 each feature's own colour, 1 its category's, 2 its `colorValue` through the ramp. */
|
|
130
|
-
readonly colorMode:
|
|
131
|
-
readonly rampLow:
|
|
132
|
-
readonly rampHigh:
|
|
130
|
+
readonly colorMode: Uniform<number>;
|
|
131
|
+
readonly rampLow: Uniform<number>;
|
|
132
|
+
readonly rampHigh: Uniform<number>;
|
|
133
133
|
/** What the GPU's filters fade: this much of its alpha left, this much towards grey. */
|
|
134
|
-
readonly fadeOpacity:
|
|
135
|
-
readonly fadeDesaturate:
|
|
134
|
+
readonly fadeOpacity: Uniform<number>;
|
|
135
|
+
readonly fadeDesaturate: Uniform<number>;
|
|
136
136
|
/** How bright the plain ones are while something is lit, 0 to 1, and towards what (0 black, 1 white). */
|
|
137
|
-
readonly othersShade:
|
|
137
|
+
readonly othersShade: Uniform<number>;
|
|
138
138
|
/** How opaque a lit feature is whose own style or the GPU's filters fade or hide it, 0 to 1. */
|
|
139
|
-
readonly outsideOpacity:
|
|
140
|
-
readonly othersToward:
|
|
139
|
+
readonly outsideOpacity: Uniform<number>;
|
|
140
|
+
readonly othersToward: Uniform<number>;
|
|
141
141
|
/** The whole set's opacity. */
|
|
142
|
-
readonly opacity:
|
|
142
|
+
readonly opacity: Uniform<number>;
|
|
143
143
|
private dirty;
|
|
144
144
|
/** How many features the look has room for: its textures' whole rows. */
|
|
145
145
|
get capacity(): number;
|
package/three/Ground.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Color } from 'three/webgpu';
|
|
1
2
|
import { Mesh, Vector3 } from 'three/webgpu';
|
|
2
|
-
import { N } from './Tsl';
|
|
3
|
+
import { N, Uniform } from './Tsl';
|
|
3
4
|
export interface GroundOptions {
|
|
4
5
|
/** Where the picture lies, in world units: min x, min y, max x, max y. The ground reaches far past it. */
|
|
5
6
|
bounds: [number, number, number, number];
|
|
@@ -30,13 +31,13 @@ export declare class Ground {
|
|
|
30
31
|
readonly options: GroundOptions;
|
|
31
32
|
readonly mesh: Mesh;
|
|
32
33
|
private texture;
|
|
33
|
-
readonly color:
|
|
34
|
-
readonly gridColor:
|
|
35
|
-
readonly gridOpacity:
|
|
34
|
+
readonly color: Uniform<Color>;
|
|
35
|
+
readonly gridColor: Uniform<Vector3>;
|
|
36
|
+
readonly gridOpacity: Uniform<number>;
|
|
36
37
|
/** The haze the ground fades into with distance, and where it starts and is whole. */
|
|
37
38
|
readonly fogColor: N;
|
|
38
|
-
readonly fogNear:
|
|
39
|
-
readonly fogFar:
|
|
39
|
+
readonly fogNear: Uniform<number>;
|
|
40
|
+
readonly fogFar: Uniform<number>;
|
|
40
41
|
/** The camera relative to the origin. */
|
|
41
42
|
readonly eye: N;
|
|
42
43
|
/** The plane's middle relative to the origin. */
|
package/three/Halo.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Mesh, RenderTarget, Scene } from 'three/webgpu';
|
|
2
|
+
import { Uniform } from './Tsl';
|
|
2
3
|
/**
|
|
3
4
|
* The dark halo round what is seen through the scene's surface - pipes under the street: their
|
|
4
5
|
* silhouettes where the surface hides them (the bodies' `window` pass, in `scene`), drawn into a
|
|
@@ -14,8 +15,8 @@ export declare class Halo {
|
|
|
14
15
|
readonly quad: Mesh;
|
|
15
16
|
readonly target: RenderTarget<import("three/webgpu").Texture>;
|
|
16
17
|
/** How far the blur reaches, in frame pixels, and how dark the halo is at most. */
|
|
17
|
-
readonly blur:
|
|
18
|
-
readonly strength:
|
|
18
|
+
readonly blur: Uniform<number>;
|
|
19
|
+
readonly strength: Uniform<number>;
|
|
19
20
|
constructor();
|
|
20
21
|
/** Whether any silhouette is drawn this frame. */
|
|
21
22
|
get active(): boolean;
|
package/three/Shading.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Vector3 } from 'three/webgpu';
|
|
2
|
+
import { Uniform } from './Tsl';
|
|
2
3
|
import { N } from './Tsl';
|
|
3
4
|
/**
|
|
4
5
|
* The finishes bodies are painted in, by `materialCode`, the first for any other; the colour is
|
|
@@ -21,13 +22,13 @@ export declare function materialCode(value: unknown): number;
|
|
|
21
22
|
* to the origin, set each frame.
|
|
22
23
|
*/
|
|
23
24
|
export declare class Lighting {
|
|
24
|
-
readonly up:
|
|
25
|
-
readonly sun:
|
|
26
|
-
readonly eye:
|
|
25
|
+
readonly up: Uniform<Vector3>;
|
|
26
|
+
readonly sun: Uniform<Vector3>;
|
|
27
|
+
readonly eye: Uniform<Vector3>;
|
|
27
28
|
/** How bright the sky is from below and from above, and the sun on top of it. */
|
|
28
|
-
readonly ambient:
|
|
29
|
-
readonly skyGain:
|
|
30
|
-
readonly sunGain:
|
|
29
|
+
readonly ambient: Uniform<number>;
|
|
30
|
+
readonly skyGain: Uniform<number>;
|
|
31
|
+
readonly sunGain: Uniform<number>;
|
|
31
32
|
/** Every material's shininess and sheen, a texel each. */
|
|
32
33
|
readonly materials: import("three/webgpu").DataTexture;
|
|
33
34
|
constructor();
|
package/three/Sky.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Color } from 'three/webgpu';
|
|
1
2
|
import { Mesh, Vector3 } from 'three/webgpu';
|
|
3
|
+
import { Uniform } from './Tsl';
|
|
2
4
|
/**
|
|
3
5
|
* The sky behind a view in perspective: dark overhead, lighter towards the horizon, with a faint
|
|
4
6
|
* glow just above it - each pixel's colour from the direction it looks in, the view's own
|
|
@@ -7,14 +9,14 @@ import { Mesh, Vector3 } from 'three/webgpu';
|
|
|
7
9
|
*/
|
|
8
10
|
export declare class Sky {
|
|
9
11
|
readonly mesh: Mesh;
|
|
10
|
-
readonly zenith:
|
|
11
|
-
readonly horizon:
|
|
12
|
-
readonly glow:
|
|
12
|
+
readonly zenith: Uniform<Color>;
|
|
13
|
+
readonly horizon: Uniform<Color>;
|
|
14
|
+
readonly glow: Uniform<Color>;
|
|
13
15
|
/** What a view looking down past the ground sees. */
|
|
14
|
-
readonly below:
|
|
16
|
+
readonly below: Uniform<Color>;
|
|
15
17
|
/** The camera relative to the origin, and the ground's up. */
|
|
16
|
-
readonly eye:
|
|
17
|
-
readonly up:
|
|
18
|
+
readonly eye: Uniform<Vector3>;
|
|
19
|
+
readonly up: Uniform<Vector3>;
|
|
18
20
|
constructor();
|
|
19
21
|
setColors(colors: {
|
|
20
22
|
zenith: string;
|
package/three/Tsl.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ import { BufferGeometry, Color, DataTexture, InstancedBufferGeometry, Mesh, Mesh
|
|
|
4
4
|
* to release, and the package runs on three 0.178 and later.
|
|
5
5
|
*/
|
|
6
6
|
export type N = any;
|
|
7
|
+
/**
|
|
8
|
+
* A uniform as the package hands it out: its `value`, to set from outside; inside, a TSL node to
|
|
9
|
+
* build shaders with. Typed by its value alone - the node itself as loosely as `N` - so that the
|
|
10
|
+
* package's declarations hold under any @types/three: its node types change from release to release.
|
|
11
|
+
*/
|
|
12
|
+
export type Uniform<T> = {
|
|
13
|
+
value: T;
|
|
14
|
+
} & N;
|
|
7
15
|
/** The width of every per-feature texture: feature `i` is texel `(i % 1024, i / 1024)`. */
|
|
8
16
|
export declare const TEXTURE_WIDTH = 1024;
|
|
9
17
|
/** Texel of feature `index` (an int node) in a per-feature texture. */
|
|
@@ -14,7 +22,7 @@ export declare function featureTexture(data: Float32Array, rows: number): DataTe
|
|
|
14
22
|
export declare function rowTexture(data: Float32Array, linear?: boolean): DataTexture;
|
|
15
23
|
export declare function rowsFor(count: number): number;
|
|
16
24
|
/** A vertex that is not drawn: outside clip space, so its triangles are clipped away whole. */
|
|
17
|
-
export declare const GONE: () =>
|
|
25
|
+
export declare const GONE: () => N;
|
|
18
26
|
/** Makes a material add what it draws into the target: a weight into the density sum. */
|
|
19
27
|
export declare function additive(material: MeshBasicNodeMaterial): void;
|
|
20
28
|
/**
|
|
@@ -2,7 +2,7 @@ import { Texture, Vector3 } from 'three/webgpu';
|
|
|
2
2
|
import { GeometryOccluder, PickOptions } from '../../engine/GeometryFrame';
|
|
3
3
|
import { FeatureLook } from '../FeatureLook';
|
|
4
4
|
import { Lighting } from '../Shading';
|
|
5
|
-
import { N } from '../Tsl';
|
|
5
|
+
import { N, Uniform } from '../Tsl';
|
|
6
6
|
/**
|
|
7
7
|
* The passes a body - a tube, a sphere - is drawn in: `solid` itself, `window` its silhouette
|
|
8
8
|
* where the scene's surface hides it, into the halo's mask, `bloom` the selected ones alone,
|
|
@@ -39,37 +39,30 @@ export interface BodyOptions {
|
|
|
39
39
|
lighting?: Lighting;
|
|
40
40
|
}
|
|
41
41
|
/** The uniforms every body shares. */
|
|
42
|
-
export
|
|
42
|
+
export interface BodyUniforms {
|
|
43
43
|
/** Frame pixels per world unit at one unit from the camera. */
|
|
44
|
-
focal:
|
|
44
|
+
focal: Uniform<number>;
|
|
45
45
|
/** Frame pixels per view pixel. */
|
|
46
|
-
pixelRatio:
|
|
46
|
+
pixelRatio: Uniform<number>;
|
|
47
47
|
/** 1 on a flat (orthographic) map, where a pixel is `1 / pxPerWorld` everywhere. */
|
|
48
|
-
orthographic:
|
|
49
|
-
pxPerWorld:
|
|
48
|
+
orthographic: Uniform<number>;
|
|
49
|
+
pxPerWorld: Uniform<number>;
|
|
50
50
|
/** How much of a body shows where the scene's surface is in front of it. */
|
|
51
|
-
ghostAlpha:
|
|
51
|
+
ghostAlpha: Uniform<number>;
|
|
52
52
|
/** And how much lighter it is drawn there, so it reads as seen through something. */
|
|
53
|
-
ghostLighten:
|
|
53
|
+
ghostLighten: Uniform<number>;
|
|
54
54
|
/** The outline look's colour and width (view pixels). */
|
|
55
|
-
outlineRgb:
|
|
56
|
-
outlineWidth:
|
|
55
|
+
outlineRgb: Uniform<Vector3>;
|
|
56
|
+
outlineWidth: Uniform<number>;
|
|
57
57
|
/** How much a selected body is lit towards white. */
|
|
58
|
-
litMix:
|
|
59
|
-
}
|
|
60
|
-
export
|
|
58
|
+
litMix: Uniform<number>;
|
|
59
|
+
}
|
|
60
|
+
export declare function bodyUniforms(): BodyUniforms;
|
|
61
61
|
/**
|
|
62
62
|
* What a body's vertex shader hands its fragment: colour and alpha, normal, distance from the
|
|
63
63
|
* camera, position relative to the origin, material and selection, index.
|
|
64
64
|
*/
|
|
65
|
-
export declare function bodyVaryings():
|
|
66
|
-
vColor: import("three/tsl").ShaderNodeObject<import("three/webgpu").PropertyNode>;
|
|
67
|
-
vNormal: import("three/tsl").ShaderNodeObject<import("three/webgpu").PropertyNode>;
|
|
68
|
-
vDistance: import("three/tsl").ShaderNodeObject<import("three/webgpu").PropertyNode>;
|
|
69
|
-
vPosition: import("three/tsl").ShaderNodeObject<import("three/webgpu").PropertyNode>;
|
|
70
|
-
vMaterial: import("three/tsl").ShaderNodeObject<import("three/webgpu").PropertyNode>;
|
|
71
|
-
vIndex: import("three/tsl").ShaderNodeObject<import("three/webgpu").PropertyNode>;
|
|
72
|
-
};
|
|
65
|
+
export declare function bodyVaryings(): Record<'vColor' | 'vNormal' | 'vDistance' | 'vPosition' | 'vMaterial' | 'vIndex', N>;
|
|
73
66
|
/** A world unit's worth of pixels at clip w `w`: what a size in view pixels is in world units. */
|
|
74
67
|
export declare function pixelSize(u: BodyUniforms, w: N): N;
|
|
75
68
|
/** How a body is blended and depth-tested in each pass. */
|
|
@@ -79,4 +72,4 @@ export declare function bodyMaterial(pass: BodyPass): import("three/webgpu").Mes
|
|
|
79
72
|
* the scene's surface hides it, for the halo; its colour for the bloom; or painted in its
|
|
80
73
|
* material, ghosted where the surface is in front - and nothing where an occluder hides it.
|
|
81
74
|
*/
|
|
82
|
-
export declare function bodyFragment(pass: BodyPass, options: BodyOptions, u: BodyUniforms, lighting: Lighting):
|
|
75
|
+
export declare function bodyFragment(pass: BodyPass, options: BodyOptions, u: BodyUniforms, lighting: Lighting): N;
|
|
@@ -2,6 +2,7 @@ import { Mesh, Vector3 } from 'three/webgpu';
|
|
|
2
2
|
import { GeometryFrame, GeometryPasses, GeometryPrimitive, PickOptions } from '../../engine/GeometryFrame';
|
|
3
3
|
import { FeatureLook } from '../FeatureLook';
|
|
4
4
|
import { Lighting } from '../Shading';
|
|
5
|
+
import { Uniform } from '../Tsl';
|
|
5
6
|
/** One area: its rings, the outer first and holes after, relative to the engine's origin. */
|
|
6
7
|
export interface GpuArea {
|
|
7
8
|
rings: readonly (readonly (readonly number[])[])[];
|
|
@@ -45,22 +46,22 @@ export declare class GpuAreas implements GeometryPrimitive {
|
|
|
45
46
|
readonly look: FeatureLook;
|
|
46
47
|
readonly lighting: Lighting;
|
|
47
48
|
triangles: number;
|
|
48
|
-
readonly pixelRatio:
|
|
49
|
+
readonly pixelRatio: Uniform<number>;
|
|
49
50
|
/** Hatching: the stripes' spacing and width, in view pixels. */
|
|
50
|
-
readonly hatch:
|
|
51
|
+
readonly hatch: Uniform<Vector3>;
|
|
51
52
|
/** A volume's walls darker towards their foot over this height, as if the ground shaded them. */
|
|
52
|
-
readonly footShade:
|
|
53
|
+
readonly footShade: Uniform<number>;
|
|
53
54
|
/** How much a selected area is lit towards white. */
|
|
54
|
-
readonly litMix:
|
|
55
|
+
readonly litMix: Uniform<number>;
|
|
55
56
|
/**
|
|
56
57
|
* Windows on a volume's walls, a grid of them a storey high: lit, this much of them, in
|
|
57
58
|
* `windowRgb` - a city at night - or 0 for dark glass only.
|
|
58
59
|
*/
|
|
59
|
-
readonly windows:
|
|
60
|
-
readonly windowsLit:
|
|
61
|
-
readonly windowRgb:
|
|
60
|
+
readonly windows: Uniform<number>;
|
|
61
|
+
readonly windowsLit: Uniform<number>;
|
|
62
|
+
readonly windowRgb: Uniform<Vector3>;
|
|
62
63
|
/** The windows' grid: width and height of a bay, in world units. */
|
|
63
|
-
readonly windowGrid:
|
|
64
|
+
readonly windowGrid: Uniform<Vector3>;
|
|
64
65
|
private readonly up;
|
|
65
66
|
constructor(areas: GpuArea[], options?: GpuAreasOptions);
|
|
66
67
|
passes(): GeometryPasses;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CanvasTexture, Mesh, Texture, Vector3 } from 'three/webgpu';
|
|
2
2
|
import { GeometryFrame, GeometryPasses, GeometryPrimitive, PickOptions } from '../../engine/GeometryFrame';
|
|
3
3
|
import { FeatureLook } from '../FeatureLook';
|
|
4
|
+
import { Uniform } from '../Tsl';
|
|
4
5
|
/**
|
|
5
6
|
* An icon to draw: where, relative to the engine's origin, and its cell in the atlas - or a
|
|
6
7
|
* negative `IconShape`, drawn in the shader.
|
|
@@ -84,17 +85,17 @@ export declare class GpuIcons implements GeometryPrimitive {
|
|
|
84
85
|
private readonly perspective;
|
|
85
86
|
private readonly focal;
|
|
86
87
|
/** 1 for the outline look: a selected one's rim in `rimRgb`, not lit to white. */
|
|
87
|
-
readonly outlineMode:
|
|
88
|
+
readonly outlineMode: Uniform<number>;
|
|
88
89
|
/** The rim's colour: near white on a dark map, ink on a light one. */
|
|
89
|
-
readonly rimRgb:
|
|
90
|
+
readonly rimRgb: Uniform<Vector3>;
|
|
90
91
|
/** How much bigger a lit icon is drawn. */
|
|
91
|
-
readonly litScale:
|
|
92
|
+
readonly litScale: Uniform<number>;
|
|
92
93
|
private readonly up;
|
|
93
94
|
constructor(icons: GpuIcon[], atlas: CanvasTexture | Texture | null, size: number, pickOrOptions?: PickOptions | GpuIconsOptions);
|
|
94
95
|
private readonly options;
|
|
95
96
|
/** How bright the icons that are not lit are while something is: see `FeatureLook.othersShade`. */
|
|
96
|
-
get othersShade():
|
|
97
|
-
get othersToward():
|
|
97
|
+
get othersShade(): any;
|
|
98
|
+
get othersToward(): any;
|
|
98
99
|
passes(): GeometryPasses;
|
|
99
100
|
setFrame(frame: GeometryFrame): void;
|
|
100
101
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Mesh, Vector2, Vector3 } from 'three/webgpu';
|
|
2
2
|
import { GeometryFrame, GeometryOccluder, GeometryPasses, GeometryPrimitive, PickOptions } from '../../engine/GeometryFrame';
|
|
3
3
|
import { FeatureLook, FeatureState } from '../FeatureLook';
|
|
4
|
+
import { Uniform } from '../Tsl';
|
|
4
5
|
/** The outline look's white (#EBE8E0), as the shader takes it. */
|
|
5
6
|
export declare const OUTLINE_RGB: [number, number, number];
|
|
6
7
|
/** How one feature's line is drawn, written into the shared look. */
|
|
@@ -107,52 +108,52 @@ export declare class GpuLines implements GeometryPrimitive {
|
|
|
107
108
|
/** How many features: each its own depth on a 2D map. */
|
|
108
109
|
private readonly featureCount;
|
|
109
110
|
/** Pixels per world unit at the view, per frame. */
|
|
110
|
-
readonly pxPerWorld:
|
|
111
|
+
readonly pxPerWorld: Uniform<number>;
|
|
111
112
|
/** Frame pixels per view pixel. */
|
|
112
|
-
readonly pixelRatio:
|
|
113
|
+
readonly pixelRatio: Uniform<number>;
|
|
113
114
|
/** Where the layer stands among the line layers, 0 lowest; decides which is nearer. */
|
|
114
|
-
readonly rank:
|
|
115
|
+
readonly rank: Uniform<number>;
|
|
115
116
|
/**
|
|
116
117
|
* How a selected line is set off: 0 nothing (the bloom pass does it), 1 a glow drawn in the
|
|
117
118
|
* fragment shader, 2 an outline round it (`casingMesh`).
|
|
118
119
|
*/
|
|
119
|
-
readonly glowMode:
|
|
120
|
+
readonly glowMode: Uniform<number>;
|
|
120
121
|
/** The outline's colour: white on a dark map, ink on a light one. */
|
|
121
|
-
readonly outlineRgb:
|
|
122
|
+
readonly outlineRgb: Uniform<Vector3>;
|
|
122
123
|
/** The outline's width, in view pixels, past the line on either side. */
|
|
123
|
-
readonly outlineWidth:
|
|
124
|
+
readonly outlineWidth: Uniform<number>;
|
|
124
125
|
/** The glow's reach, in view pixels, past a selected line. */
|
|
125
|
-
readonly glowWidth:
|
|
126
|
+
readonly glowWidth: Uniform<number>;
|
|
126
127
|
/** On the ground and in space: frame pixels per world unit at one unit from the camera. */
|
|
127
|
-
readonly focal:
|
|
128
|
+
readonly focal: Uniform<number>;
|
|
128
129
|
/** The camera's near plane: in space, an end behind it is pulled in front. */
|
|
129
|
-
readonly near:
|
|
130
|
+
readonly near: Uniform<number>;
|
|
130
131
|
/**
|
|
131
132
|
* World units per metre on the ground, for real widths and ends: 1 / cos(latitude) on a web
|
|
132
133
|
* mercator map, where a world unit shrinks away from the equator; 1 elsewhere.
|
|
133
134
|
*/
|
|
134
|
-
readonly worldPerMetre:
|
|
135
|
+
readonly worldPerMetre: Uniform<number>;
|
|
135
136
|
/**
|
|
136
137
|
* 1 while the symbols at the lines' ends are drawn, 0 when they are not: the lines then run on
|
|
137
138
|
* to their ends rather than stopping short of nothing.
|
|
138
139
|
*/
|
|
139
|
-
readonly endsShown:
|
|
140
|
+
readonly endsShown: Uniform<number>;
|
|
140
141
|
/** A dashed line's dash and gap, in view pixels. */
|
|
141
|
-
readonly dash:
|
|
142
|
+
readonly dash: Uniform<Vector2>;
|
|
142
143
|
/** Flowing lines: pulses this far apart, in view pixels, moving at this many a second. */
|
|
143
|
-
readonly flowSpacing:
|
|
144
|
-
readonly flowSpeed:
|
|
145
|
-
readonly time:
|
|
144
|
+
readonly flowSpacing: Uniform<number>;
|
|
145
|
+
readonly flowSpeed: Uniform<number>;
|
|
146
|
+
readonly time: Uniform<number>;
|
|
146
147
|
private readonly up;
|
|
147
148
|
/** One entry per feature: its parts, usually one polyline, several for a multi-line. */
|
|
148
149
|
constructor(features: LinePath[][], options?: GpuLinesOptions);
|
|
149
150
|
/** 1 while a range is being dragged: the GPU then decides pass or fail per feature. */
|
|
150
|
-
get dragActive():
|
|
151
|
-
get dragLow():
|
|
152
|
-
get dragHigh():
|
|
151
|
+
get dragActive(): any;
|
|
152
|
+
get dragLow(): any;
|
|
153
|
+
get dragHigh(): any;
|
|
153
154
|
/** How bright the lines that are not lit are while something is: see `FeatureLook.othersShade`. */
|
|
154
|
-
get othersShade():
|
|
155
|
-
get othersToward():
|
|
155
|
+
get othersShade(): any;
|
|
156
|
+
get othersToward(): any;
|
|
156
157
|
passes(): GeometryPasses;
|
|
157
158
|
setFrame(frame: GeometryFrame): void;
|
|
158
159
|
setStyle(index: number, style: LineFeatureStyle): void;
|
|
@@ -2,6 +2,7 @@ import { Mesh } from 'three/webgpu';
|
|
|
2
2
|
import { GeometryFrame, GeometryPasses, GeometryPrimitive } from '../../engine/GeometryFrame';
|
|
3
3
|
import { FeatureLook } from '../FeatureLook';
|
|
4
4
|
import { Lighting } from '../Shading';
|
|
5
|
+
import { Uniform } from '../Tsl';
|
|
5
6
|
import { BodyOptions } from './Body';
|
|
6
7
|
/** A sphere: its centre relative to the origin, its feature's index, its radius, its reach (0: always). */
|
|
7
8
|
export type GpuSphere = {
|
|
@@ -33,18 +34,8 @@ export declare class GpuSpheres implements GeometryPrimitive {
|
|
|
33
34
|
readonly densityMesh: Mesh;
|
|
34
35
|
readonly look: FeatureLook;
|
|
35
36
|
readonly lighting: Lighting;
|
|
36
|
-
readonly uniforms:
|
|
37
|
-
|
|
38
|
-
pixelRatio: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
39
|
-
orthographic: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
40
|
-
pxPerWorld: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
41
|
-
ghostAlpha: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
42
|
-
ghostLighten: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
43
|
-
outlineRgb: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<import("three/webgpu").Vector3>>;
|
|
44
|
-
outlineWidth: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
45
|
-
litMix: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
46
|
-
};
|
|
47
|
-
readonly near: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
37
|
+
readonly uniforms: import("./Body").BodyUniforms;
|
|
38
|
+
readonly near: Uniform<number>;
|
|
48
39
|
constructor(spheres: GpuSphere[], options?: GpuSpheresOptions);
|
|
49
40
|
passes(): GeometryPasses;
|
|
50
41
|
setFrame(frame: GeometryFrame): void;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Mesh
|
|
1
|
+
import { Mesh } from 'three/webgpu';
|
|
2
2
|
import { GeometryFrame, GeometryPasses, GeometryPrimitive } from '../../engine/GeometryFrame';
|
|
3
3
|
import { FeatureLook } from '../FeatureLook';
|
|
4
4
|
import { Lighting } from '../Shading';
|
|
5
|
+
import { Uniform } from '../Tsl';
|
|
5
6
|
import { BodyOptions } from './Body';
|
|
6
7
|
/**
|
|
7
8
|
* A tube's cross-section, in world units: half its width, half its height, and its corners'
|
|
@@ -74,24 +75,14 @@ export declare class GpuTubes implements GeometryPrimitive {
|
|
|
74
75
|
readonly arrowMesh: Mesh | null;
|
|
75
76
|
readonly look: FeatureLook;
|
|
76
77
|
readonly lighting: Lighting;
|
|
77
|
-
readonly uniforms:
|
|
78
|
-
focal: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
79
|
-
pixelRatio: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
80
|
-
orthographic: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
81
|
-
pxPerWorld: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
82
|
-
ghostAlpha: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
83
|
-
ghostLighten: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
84
|
-
outlineRgb: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
85
|
-
outlineWidth: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
86
|
-
litMix: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
87
|
-
};
|
|
78
|
+
readonly uniforms: import("./Body").BodyUniforms;
|
|
88
79
|
segments: number;
|
|
89
|
-
readonly near:
|
|
80
|
+
readonly near: Uniform<number>;
|
|
90
81
|
/**
|
|
91
82
|
* How far from the camera the junctions are drawn: a tube ending in one further off runs on to
|
|
92
83
|
* its axis rather than stopping at a wall that is not there.
|
|
93
84
|
*/
|
|
94
|
-
readonly shaftReach:
|
|
85
|
+
readonly shaftReach: Uniform<number>;
|
|
95
86
|
private readonly up;
|
|
96
87
|
constructor(tubes: GpuTube[], options?: GpuTubesOptions);
|
|
97
88
|
passes(): GeometryPasses;
|
|
@@ -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))}
|