@protomaze/geometry 0.0.0-stage → 0.1.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/GeometryDemo.d.ts +1 -0
- package/GeometryDemo.js +1 -0
- package/README.md +301 -2
- package/common/Colors.d.ts +47 -0
- package/common/Colors.js +1 -0
- package/common/Disposables.d.ts +7 -0
- package/common/Disposables.js +1 -0
- package/data/Geometry.d.ts +62 -0
- package/data/Geometry.js +1 -0
- package/demo/DemoControls.d.ts +68 -0
- package/demo/DemoControls.js +1 -0
- package/demo/Town.d.ts +115 -0
- package/demo/Town.js +1 -0
- package/edit/CreateController.d.ts +101 -0
- package/edit/CreateController.js +1 -0
- package/edit/EditController.d.ts +121 -0
- package/edit/EditController.js +1 -0
- package/edit/EditHistory.d.ts +46 -0
- package/edit/EditHistory.js +1 -0
- package/edit/EditShape.d.ts +45 -0
- package/edit/EditShape.js +1 -0
- package/edit/GeometryController.d.ts +83 -0
- package/edit/GeometryController.js +1 -0
- package/edit/MeasureController.d.ts +102 -0
- package/edit/MeasureController.js +1 -0
- package/edit/Sketch.d.ts +73 -0
- package/edit/Sketch.js +1 -0
- package/edit/Snapper.d.ts +67 -0
- package/edit/Snapper.js +1 -0
- package/engine/GeometryEngine.d.ts +267 -0
- package/engine/GeometryEngine.js +1 -0
- package/engine/GeometryFrame.d.ts +91 -0
- package/engine/GeometryFrame.js +1 -0
- package/engine/GeometryOptions.d.ts +79 -0
- package/engine/GeometryOptions.js +1 -0
- package/engine/GeometryView.d.ts +192 -0
- package/engine/GeometryView.js +1 -0
- package/engine/Labels.d.ts +42 -0
- package/engine/Labels.js +1 -0
- package/engine/MapCamera.d.ts +78 -0
- package/engine/MapCamera.js +1 -0
- package/event/TypedEventEmitter.d.ts +13 -0
- package/event/TypedEventEmitter.js +1 -0
- package/index.d.ts +53 -0
- package/index.js +1 -0
- package/layers/AreaLayer.d.ts +36 -0
- package/layers/AreaLayer.js +1 -0
- package/layers/GeometryLayer.d.ts +312 -0
- package/layers/GeometryLayer.js +1 -0
- package/layers/LineLayer.d.ts +48 -0
- package/layers/LineLayer.js +1 -0
- package/layers/PointLayer.d.ts +42 -0
- package/layers/PointLayer.js +1 -0
- package/layers/SphereLayer.d.ts +25 -0
- package/layers/SphereLayer.js +1 -0
- package/layers/TubeLayer.d.ts +52 -0
- package/layers/TubeLayer.js +1 -0
- package/math/Boolean.d.ts +21 -0
- package/math/Boolean.js +1 -0
- package/math/FeatureIndex.d.ts +70 -0
- package/math/FeatureIndex.js +1 -0
- package/math/Geodesy.d.ts +29 -0
- package/math/Geodesy.js +1 -0
- package/math/Lines.d.ts +115 -0
- package/math/Lines.js +1 -0
- package/math/Measure.d.ts +71 -0
- package/math/Measure.js +1 -0
- package/math/Polygons.d.ts +59 -0
- package/math/Polygons.js +1 -0
- package/math/Projection.d.ts +25 -0
- package/math/Projection.js +1 -0
- package/math/Relations.d.ts +27 -0
- package/math/Relations.js +1 -0
- package/math/SpatialIndex.d.ts +36 -0
- package/math/SpatialIndex.js +1 -0
- package/math/Transform.d.ts +36 -0
- package/math/Transform.js +1 -0
- package/math/Triangulate.d.ts +19 -0
- package/math/Triangulate.js +1 -0
- package/math/Vector.d.ts +24 -0
- package/math/Vector.js +1 -0
- package/package.json +76 -4
- package/react/ReactGeometry.d.ts +35 -0
- package/react/ReactGeometry.js +1 -0
- package/three/CanvasGeometryEngine.d.ts +79 -0
- package/three/CanvasGeometryEngine.js +1 -0
- package/three/DensityMap.d.ts +31 -0
- package/three/DensityMap.js +1 -0
- package/three/FeatureLook.d.ts +191 -0
- package/three/FeatureLook.js +1 -0
- package/three/Ground.d.ts +54 -0
- package/three/Ground.js +1 -0
- package/three/Halo.d.ts +26 -0
- package/three/Halo.js +1 -0
- package/three/HostedGeometryEngine.d.ts +57 -0
- package/three/HostedGeometryEngine.js +1 -0
- package/three/RiaGeometryEngine.d.ts +48 -0
- package/three/RiaGeometryEngine.js +1 -0
- package/three/Shading.d.ts +42 -0
- package/three/Shading.js +1 -0
- package/three/Sky.d.ts +27 -0
- package/three/Sky.js +1 -0
- package/three/Tsl.d.ts +47 -0
- package/three/Tsl.js +1 -0
- package/three/primitives/Body.d.ts +82 -0
- package/three/primitives/Body.js +1 -0
- package/three/primitives/GpuAreas.d.ts +72 -0
- package/three/primitives/GpuAreas.js +1 -0
- package/three/primitives/GpuIcons.d.ts +112 -0
- package/three/primitives/GpuIcons.js +1 -0
- package/three/primitives/GpuLines.d.ts +198 -0
- package/three/primitives/GpuLines.js +1 -0
- package/three/primitives/GpuSpheres.d.ts +55 -0
- package/three/primitives/GpuSpheres.js +1 -0
- package/three/primitives/GpuTubes.d.ts +125 -0
- package/three/primitives/GpuTubes.js +1 -0
- package/three/primitives/IconAtlas.d.ts +12 -0
- package/three/primitives/IconAtlas.js +1 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Mesh, Vector2, Vector3 } from 'three/webgpu';
|
|
2
|
+
import { GeometryFrame, GeometryOccluder, GeometryPasses, GeometryPrimitive, PickOptions } from '../../engine/GeometryFrame';
|
|
3
|
+
import { FeatureLook, FeatureState } from '../FeatureLook';
|
|
4
|
+
/** The outline look's white (#EBE8E0), as the shader takes it. */
|
|
5
|
+
export declare const OUTLINE_RGB: [number, number, number];
|
|
6
|
+
/** How one feature's line is drawn: the Ing+ map's style, written into the shared look. */
|
|
7
|
+
export interface LineFeatureStyle {
|
|
8
|
+
/** Straight (not premultiplied) RGBA, 0..1. */
|
|
9
|
+
color: [number, number, number, number];
|
|
10
|
+
width: number;
|
|
11
|
+
/** `width` in metres (world units) rather than pixels. */
|
|
12
|
+
meters: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The line's real width in metres, 0 for none: drawn at that where it is wider than `width`
|
|
15
|
+
* on screen - a line is never thinner than its style and never thinner than itself.
|
|
16
|
+
*/
|
|
17
|
+
realWidth: number;
|
|
18
|
+
state: FeatureState;
|
|
19
|
+
/** Other `LookFlag` bits: dashed, flowing, no arrow. */
|
|
20
|
+
flags?: number;
|
|
21
|
+
}
|
|
22
|
+
/** The Ing+ map's name for a feature's state. */
|
|
23
|
+
export declare const LineState: typeof FeatureState;
|
|
24
|
+
export type LineState = FeatureState;
|
|
25
|
+
/** A polyline in the engine's origin-relative world coordinates. */
|
|
26
|
+
export type LinePath = {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
z: number;
|
|
30
|
+
}[];
|
|
31
|
+
export interface GpuLinesOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Lay the lines flat on a 3D map's ground, in perspective - a road view - rather than across
|
|
34
|
+
* the screen: `up` is the ground's up at the origin. `focal` must then be set each frame.
|
|
35
|
+
*/
|
|
36
|
+
ground?: {
|
|
37
|
+
up: readonly number[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Draw the lines in space: as wide on screen as their style, at their own depth - a
|
|
41
|
+
* trajectory, a flight path, a cable through a building - tested against the depth of
|
|
42
|
+
* everything else drawn.
|
|
43
|
+
*/
|
|
44
|
+
space?: boolean;
|
|
45
|
+
/** On the ground: not drawn where this says something stands in front. */
|
|
46
|
+
occluder?: GeometryOccluder | null;
|
|
47
|
+
/**
|
|
48
|
+
* Drawn into the engine's pick pass too (`pickMesh`), writing `source` and each feature's
|
|
49
|
+
* index - and, as the pick's distance, the clip w in 3D, the line's own layering on a 2D map.
|
|
50
|
+
*/
|
|
51
|
+
pick?: PickOptions;
|
|
52
|
+
/**
|
|
53
|
+
* How far each feature's line runs inside what stands at its two ends, in world units along
|
|
54
|
+
* it - a manhole's symbol - two numbers a feature, start then end: the line stops there.
|
|
55
|
+
*/
|
|
56
|
+
ends?: ArrayLike<number>;
|
|
57
|
+
/** The flow arrow at each line's middle, where it is long enough on screen. On by default. */
|
|
58
|
+
arrows?: boolean;
|
|
59
|
+
/** The look to read; one of the lines' own, with fail looks for range drags, when not given. */
|
|
60
|
+
look?: FeatureLook;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The flow arrow, in view pixels: this long, as high either side as the line's style is wide
|
|
64
|
+
* (this at least), outlined this wide in black. From the style's width, not the real one: the
|
|
65
|
+
* arrow stays one size as the map zooms in and the line takes its real width.
|
|
66
|
+
*/
|
|
67
|
+
export declare const ARROW_LENGTH = 16;
|
|
68
|
+
export declare const ARROW_MIN_HALF_HEIGHT = 3;
|
|
69
|
+
export declare const ARROW_OUTLINE = 1.5;
|
|
70
|
+
/**
|
|
71
|
+
* Every line of one layer as one instanced draw: one quad per segment, widened to its pixel width
|
|
72
|
+
* in the vertex shader and cut to a round-capped line plus the flow arrow in the fragment shader.
|
|
73
|
+
* Styles live in the feature look's float textures, so a restyle of any number of features is one
|
|
74
|
+
* texture upload and no tessellation at all.
|
|
75
|
+
*
|
|
76
|
+
* Three ways to lie: across the screen on a 2D map (the default), flat on the ground in
|
|
77
|
+
* perspective (`ground`), or in space at their own depth (`space`).
|
|
78
|
+
*
|
|
79
|
+
* On a 2D map depth does the layering. Each feature gets its own depth, nearer for a stronger
|
|
80
|
+
* state (selected over default over faded) and for a layer higher up (`rank`), so a translucent
|
|
81
|
+
* line never blends over itself where its segments overlap at a joint.
|
|
82
|
+
*/
|
|
83
|
+
export declare class GpuLines implements GeometryPrimitive {
|
|
84
|
+
private readonly options;
|
|
85
|
+
readonly mesh: Mesh;
|
|
86
|
+
/**
|
|
87
|
+
* The lines' anti-aliased edges, drawn after `mesh` without writing depth. In one pass, an
|
|
88
|
+
* edge pixel of one segment wrote depth and blocked the solid pixels of the next at the same
|
|
89
|
+
* depth, which left a notch at joints.
|
|
90
|
+
*/
|
|
91
|
+
readonly fringeMesh: Mesh;
|
|
92
|
+
/** The same lines again, for a pass that draws only the selected ones to be bloomed. */
|
|
93
|
+
readonly bloomMesh: Mesh;
|
|
94
|
+
/**
|
|
95
|
+
* The outline look's casing: the selected lines alone, widened by the outline and drawn in its
|
|
96
|
+
* white behind every one of them and in front of the rest - so where two lit lines meet, no
|
|
97
|
+
* white runs between them. Before the lines, at a depth of its own.
|
|
98
|
+
*/
|
|
99
|
+
readonly casingMesh: Mesh;
|
|
100
|
+
/** The same lines, at least `PICK_MIN_PIXELS` wide, for the pick pass; with `pick` only. */
|
|
101
|
+
readonly pickMesh: Mesh | null;
|
|
102
|
+
/** The same lines again, adding their weight into the engine's heatmap (`DensityMap`). */
|
|
103
|
+
readonly densityMesh: Mesh;
|
|
104
|
+
readonly look: FeatureLook;
|
|
105
|
+
/** How many segments, all lines together. */
|
|
106
|
+
segments: number;
|
|
107
|
+
/** How many features: each its own depth on a 2D map. */
|
|
108
|
+
private readonly featureCount;
|
|
109
|
+
/** Pixels per world unit at the view, per frame. */
|
|
110
|
+
readonly pxPerWorld: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
111
|
+
/** Frame pixels per view pixel. */
|
|
112
|
+
readonly pixelRatio: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
113
|
+
/** Where the layer stands among the line layers, 0 lowest; decides which is nearer. */
|
|
114
|
+
readonly rank: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
115
|
+
/**
|
|
116
|
+
* How a selected line is set off: 0 nothing (the bloom pass does it), 1 a glow drawn in the
|
|
117
|
+
* fragment shader, 2 an outline round it (`casingMesh`).
|
|
118
|
+
*/
|
|
119
|
+
readonly glowMode: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
120
|
+
/** The outline's colour: white on a dark map, ink on a light one. */
|
|
121
|
+
readonly outlineRgb: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
122
|
+
/** The outline's width, in view pixels, past the line on either side. */
|
|
123
|
+
readonly outlineWidth: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
124
|
+
/** The glow's reach, in view pixels, past a selected line. */
|
|
125
|
+
readonly glowWidth: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
126
|
+
/** On the ground and in space: frame pixels per world unit at one unit from the camera. */
|
|
127
|
+
readonly focal: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
128
|
+
/** The camera's near plane: in space, an end behind it is pulled in front. */
|
|
129
|
+
readonly near: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
130
|
+
/**
|
|
131
|
+
* World units per metre on the ground, for real widths and ends: 1 / cos(latitude) on a web
|
|
132
|
+
* mercator map, where a world unit shrinks away from the equator; 1 elsewhere.
|
|
133
|
+
*/
|
|
134
|
+
readonly worldPerMetre: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
135
|
+
/**
|
|
136
|
+
* 1 while the symbols at the lines' ends are drawn, 0 when they are not: the lines then run on
|
|
137
|
+
* to their ends rather than stopping short of nothing.
|
|
138
|
+
*/
|
|
139
|
+
readonly endsShown: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
140
|
+
/** A dashed line's dash and gap, in view pixels. */
|
|
141
|
+
readonly dash: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector2>>;
|
|
142
|
+
/** Flowing lines: pulses this far apart, in view pixels, moving at this many a second. */
|
|
143
|
+
readonly flowSpacing: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
144
|
+
readonly flowSpeed: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
145
|
+
readonly time: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
146
|
+
private readonly up;
|
|
147
|
+
/** One entry per feature: its parts, usually one polyline, several for a multi-line. */
|
|
148
|
+
constructor(features: LinePath[][], options?: GpuLinesOptions);
|
|
149
|
+
/** 1 while a range is being dragged: the GPU then decides pass or fail per feature. */
|
|
150
|
+
get dragActive(): import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
151
|
+
get dragLow(): import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
152
|
+
get dragHigh(): import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
153
|
+
/** How bright the lines that are not lit are while something is: see `FeatureLook.othersShade`. */
|
|
154
|
+
get othersShade(): import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
155
|
+
get othersToward(): import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
156
|
+
passes(): GeometryPasses;
|
|
157
|
+
setFrame(frame: GeometryFrame): void;
|
|
158
|
+
setStyle(index: number, style: LineFeatureStyle): void;
|
|
159
|
+
/** Uploads what setStyle wrote. */
|
|
160
|
+
commit(): void;
|
|
161
|
+
/**
|
|
162
|
+
* What a feature looks like should it fail the dragged range, and the value the range is held
|
|
163
|
+
* against: `fixed` 0 leaves that to the GPU, 1 has it pass whatever the range, 2 fail.
|
|
164
|
+
*/
|
|
165
|
+
setDragStyle(index: number, fail: LineFeatureStyle, value: number, fixed: 0 | 1 | 2): void;
|
|
166
|
+
/** Uploads what setDragStyle wrote. */
|
|
167
|
+
commitDrag(): void;
|
|
168
|
+
private meshes;
|
|
169
|
+
adopt(other: GeometryPrimitive): boolean;
|
|
170
|
+
dispose(): void;
|
|
171
|
+
/**
|
|
172
|
+
* `core`: the lines' solid part, writing depth. `fringe`: their soft edges, after it, not
|
|
173
|
+
* writing depth, passing at equal depth. `bloom`: only the selected lines, plain, to bloom.
|
|
174
|
+
* `pick`: each line's index into the pick window, where it shows, at least `PICK_MIN_PIXELS`
|
|
175
|
+
* either side of its middle. `density`: each line's weight added into the heatmap over its
|
|
176
|
+
* width, with no arrow or glow. `casing`: only the selected lines, as wide as the outline
|
|
177
|
+
* look's band round them, in its colour, between them and the rest.
|
|
178
|
+
*/
|
|
179
|
+
private createMaterial;
|
|
180
|
+
/**
|
|
181
|
+
* A segment's quad across the screen: widened to its width in pixels, or in metres at the
|
|
182
|
+
* view's scale, and long enough past its ends for the caps, the glow and the arrow. Local
|
|
183
|
+
* coordinates in pixels. `size` is the frame's, in pixels - the pick pass draws into a target
|
|
184
|
+
* of its own - `minPixels` the least half width, `noArrow` for the heatmap. In `space`, at
|
|
185
|
+
* each end's own depth, an end behind the camera pulled in front of it.
|
|
186
|
+
*/
|
|
187
|
+
private screenQuad;
|
|
188
|
+
/**
|
|
189
|
+
* A segment's quad lying flat on the ground of a 3D map, in perspective: as wide as the line
|
|
190
|
+
* is, in metres or in its pixels at the distance, but across the ground rather than the
|
|
191
|
+
* screen - looked at from low down it is foreshortened, as the street is. Local coordinates
|
|
192
|
+
* in metres. Everything in pixels is taken at each corner's own distance, so a line in pixels
|
|
193
|
+
* is that many pixels wide all along; the arrow at its own distance, so it is one size on
|
|
194
|
+
* every segment that draws a part of it. An end behind the camera is pulled forward to just
|
|
195
|
+
* in front of it; a segment wholly behind is not drawn.
|
|
196
|
+
*/
|
|
197
|
+
private groundQuad;
|
|
198
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DoubleSide as e,InstancedBufferAttribute as t,InstancedBufferGeometry as s,LessDepth as a,LessEqualDepth as r,Mesh as l,NoBlending as o,Vector2 as i,Vector3 as n}from"three/webgpu";import{abs as h,attribute as u,cameraProjectionMatrix as d,clamp as c,cross as m,dFdx as g,dFdy as w,Discard as p,float as T,Fn as b,fract as f,If as v,int as x,length as y,max as V,min as M,mix as S,normalize as k,positionGeometry as E,screenCoordinate as W,smoothstep as z,uniform as R,varyingProperty as A,vec2 as L,vec3 as q,vec4 as H,viewport as C}from"three/tsl";import{FeatureLook as F,FeatureState as N,hasFlag as _,LookFlag as G}from"../FeatureLook.js";import{additive as I,adoptGeometry as O,disposeMaterial as P,GONE as D,nodeMaterial as Q,segmentQuad as U,unculled as j}from"../Tsl.js";export const OUTLINE_RGB=[235/255,232/255,224/255];export const LineState=N;export const ARROW_LENGTH=16;export const ARROW_MIN_HALF_HEIGHT=3;export const ARROW_OUTLINE=1.5;export class GpuLines{constructor(e,a={}){this.options=a,this.pickMesh=null,this.featureCount=R(1),this.pxPerWorld=R(1),this.pixelRatio=R(1),this.rank=R(0),this.glowMode=R(1),this.outlineRgb=R(new n(...OUTLINE_RGB)),this.outlineWidth=R(2),this.glowWidth=R(6),this.focal=R(1e3),this.near=R(.3),this.worldPerMetre=R(1),this.endsShown=R(1),this.dash=R(new i(10,6)),this.flowSpacing=R(48),this.flowSpeed=R(60),this.time=R(0),this.up=R(new n(0,0,1)),a.ground&&this.up.value.set(a.ground.up[0],a.ground.up[1],a.ground.up[2]).normalize();const r=e.length;this.look=a.look??new F(r,{failLooks:!0}),this.featureCount.value=Math.max(1,r);let o=0;for(const t of e)for(const e of t)o+=Math.max(0,e.length-1);this.segments=o;const h=new Float32Array(3*o),u=new Float32Array(3*o),d=new Float32Array(4*o),c=new Float32Array(2*o),m=a.ends;let g=0;e.forEach((e,t)=>e.forEach(s=>{let a=0;for(let e=1;e<s.length;e++)a+=J(s[e-1],s[e]);let r=0;for(let l=1;l<s.length;l++){const o=s[l-1],i=s[l],n=J(o,i);h[3*g]=o.x,h[3*g+1]=o.y,h[3*g+2]=o.z,u[3*g]=i.x,u[3*g+1]=i.y,u[3*g+2]=i.z,d[4*g]=t,d[4*g+1]=r,d[4*g+2]=r+n,d[4*g+3]=a,m&&1===e.length&&(c[2*g]=m[2*t]||0,c[2*g+1]=m[2*t+1]||0),r+=n,g++}}));const w=U(new s);w.setAttribute("segStart",new t(h,3)),w.setAttribute("segEnd",new t(u,3)),w.setAttribute("segMeta",new t(d,4)),w.setAttribute("segTrim",new t(c,2)),w.instanceCount=o,this.mesh=j(new l(w,this.createMaterial(r,"core"))),this.fringeMesh=j(new l(w,this.createMaterial(r,"fringe")),1),this.bloomMesh=j(new l(w,this.createMaterial(r,"bloom"))),this.casingMesh=j(new l(w,this.createMaterial(r,"casing")),-1),this.casingMesh.visible=!1,a.pick&&(this.pickMesh=j(new l(w,this.createMaterial(r,"pick")))),this.densityMesh=j(new l(w,this.createMaterial(r,"density"))),this.densityMesh.visible=!1}get dragActive(){return this.look.rangeActive}get dragLow(){return this.look.rangeLow}get dragHigh(){return this.look.rangeHigh}get othersShade(){return this.look.othersShade}get othersToward(){return this.look.othersToward}passes(){return{scene:[this.casingMesh,this.mesh,this.fringeMesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){this.pxPerWorld.value=e.pxPerWorld,this.pixelRatio.value=e.pixelRatio,this.near.value=e.near,e.focal&&(this.focal.value=e.focal),void 0!==e.time&&(this.time.value=e.time)}setStyle(e,t){this.look.set(e,{color:t.color,width:t.width,flags:(t.flags??0)&~G.Meters,meters:t.meters,state:t.state,realWidth:t.realWidth,weight:t.color[3],fadedWeight:t.color[3]})}commit(){this.look.commit()}setDragStyle(e,t,s,a){this.look.setFail(e,{color:t.color,width:t.width,meters:t.meters,state:t.state,realWidth:t.realWidth,flags:t.flags}),this.look.setValue(e,s,a)}commitDrag(){this.look.commit()}meshes(){return[this.mesh,this.fringeMesh,this.bloomMesh,this.casingMesh,this.pickMesh,this.densityMesh]}adopt(e){return!!(e instanceof GpuLines&&O(this.meshes(),e.meshes()))&&(this.segments=e.segments,this.featureCount.value=e.featureCount.value,!0)}dispose(){this.mesh.geometry.dispose(),this.meshes().forEach(P),this.options.look||this.look.dispose()}createMaterial(t,s){const l="bloom"===s,i="casing"===s,n="pick"===s,d="density"===s,m=this.options.pick,k=!!this.options.ground,E=!k&&!!this.options.space,R=!1!==this.options.arrows,F=k||E?this.options.occluder:null,N=Q();N.transparent=!n,n&&(N.blending=o),N.side=e,N.depthTest=!0,N.depthWrite="fringe"!==s,N.depthFunc="fringe"===s||i||E?r:a,d&&I(N);const O=this.look,{rank:P,glowMode:U}=this,j=l||i,B=this.featureCount,J=A("vec2","vLocal"),K=A("float","vW"),X=A("vec4","vSegment"),Y=A("vec4","vColor"),Z=A("vec4","vExtra"),$=A("float","vDistance"),ee=A("float","vIndex"),te=A("vec3","vCut"),se=A("vec2","vJoin"),ae=A("vec3","vAlong");return N.vertexNode=b(()=>{const e=u("segStart","vec3"),t=u("segEnd","vec3"),s=u("segMeta","vec4"),a=x(s.x),r=O.read(a),o=r.state,h=r.selected,c=h.and(U.greaterThan(.5)).and(T(l||d?0:1).greaterThan(.5)),g=R?_(r.flags,G.NoArrow):T(1).greaterThan(0),w=u("segTrim","vec2").mul(this.endsShown),p=n?4:0,b=k?this.groundQuad(e,t,s,w,r.width,r.meters,r.realWidth,c,p,g):this.screenQuad(e,t,s,w,r.width,r.meters,r.realWidth,c,n&&m?m.pass.frameSize:C.zw,p,d,g,E);te.assign(q(w.x.greaterThan(0).select(b.cutStart,T(-1e9)),w.y.greaterThan(0).select(b.cutEnd,T(1e9)),b.arrowHalf)),J.assign(b.local.mul(b.w)),K.assign(b.w),X.assign(H(b.segLength,b.halfWidth,b.arrowCentre,b.arrowSize)),Y.assign(H(r.rgb,r.alpha));const f=s.y.lessThanEqual(0).select(this.endsShown,T(0)),v=s.z.greaterThanEqual(s.w).select(this.endsShown,T(0));Z.assign(H(b.glow,b.step,f,v)),se.assign(L(s.y.lessThanEqual(0).select(T(1),T(0)),s.z.greaterThanEqual(s.w).select(T(1),T(0)))),ee.assign(s.x),ae.assign(q(r.flags,b.alongStart,b.pixel));const y=T(.9).sub(o.mul(.25)).sub(P.mul(.04)).sub(s.x.div(B).mul(.03));$.assign(k||E?b.clip.w:y);const V=i?T(.24):y,M=o.lessThan(.5).or(T(j?1:0).greaterThan(.5).and(h.not())).or(d?r.weight.lessThan(.001):T(0).greaterThan(1)).or(b.gone).or(T(i&&(k||E)?1:0).greaterThan(.5)),S=b.clip,W=k||E?S:H(S.xy,V.mul(S.w),S.w);return M.select(D(),n&&m?m.pass.window.mul(W):W)})(),N.fragmentNode=b(()=>{const e=J.div(K).toVar(),t=e.x,a=e.y,r=X.x,l=X.y;if(n&&m){const e=y(L(t.sub(c(t,0,r)),a)).greaterThan(l).or(t.lessThan(te.x)).or(t.greaterThan(te.y)),s=F?e.or(F.hides($,W.xy.add(m.pass.origin))):e;return v(s.toVar(),()=>{p()}),H(T(m.source),ee,$,1)}const o=X.z,u=X.w,b=k?y(L(g(t),w(t))).mul(.5).toVar():T(.5),x=k?y(L(g(a),w(a))).mul(.5).toVar():T(.5);F&&v(F.hides($).toVar(),()=>{p()});const E=c(t,0,r),R=y(L(t.sub(E),a)).toVar(),A=Z.x,C=T(1).sub(Z.z.mul(z(b.negate(),b,t.negate()))),N=T(1).sub(Z.w.mul(z(b.negate(),b,t.sub(r)))),I=z(b.negate(),b,t.sub(te.x)).mul(z(b.negate(),b,te.y.sub(t))),O=C.mul(N).mul(I).toVar(),P=V(b,x).mul(2).toVar(),D=ae.y.add(t).div(V(ae.z,1e-6)).toVar(),Q=this.dash.x.add(this.dash.y).mul(this.pixelRatio),U=f(D.div(Q)).mul(Q),j=M(U,this.dash.x.mul(this.pixelRatio).sub(U)),B=_(ae.x,G.Dashed).select(c(j.add(.5),0,1),T(1)),re=T(1).sub(z(l.sub(x),l.add(x),R)).mul(O).mul(B).toVar();if(d){const e=t.greaterThanEqual(0).or(se.x.greaterThan(.5)).and(t.lessThan(r).or(se.y.greaterThan(.5))).select(Y.a.mul(re),T(0));return v(e.lessThan(.001),()=>{p()}),H(e,0,0,1)}const le=t.sub(o.sub(u.mul(.5))),oe=te.z.mul(T(1).sub(le.div(u))),ie=M(M(le,u.sub(le)),oe.sub(h(a))).toVar(),ne=t.greaterThanEqual(b.negate()).and(t.lessThanEqual(r.add(b))).select(T(1),T(0)),he=c(ie.div(P).add(.5),0,1).mul(ne).toVar(),ue=c(ie.div(P).add(this.pixelRatio.mul(1.5)).add(.5),0,1).mul(ne).toVar(),de=S(q(0,0,0),Y.rgb,he.div(V(ue,.001))),ce=V(re,ue).toVar(),me=A.greaterThan(0),ge=T(1).sub(z(l,l.add(A),R)),we=this.glowMode.greaterThan(1.5),pe=l.add(this.outlineWidth.mul(this.pixelRatio).mul(P)),Te=T(1).sub(z(pe.sub(P.mul(.5)),pe.add(P.mul(.5)),R)).mul(O);if(i)return v(Te.lessThan(.01),()=>{p()}),H(this.outlineRgb,Te);const be=me.select(we.select(T(0),ge.mul(ge).mul(.55)),T(0)),fe=V(ce,be),ve="fringe"===s?fe.lessThan(.01).or(fe.greaterThanEqual(.5)):"core"===s?fe.lessThan(.5):fe.lessThan(.01);v(ve,()=>{p()});const xe=ue.greaterThan(.01).select(de,Y.rgb).toVar(),ye=_(ae.x,G.Flow),Ve=this.flowSpacing.mul(this.pixelRatio),Me=f(D.sub(this.time.mul(this.flowSpeed).mul(this.pixelRatio)).div(Ve)),Se=ye.select(z(.55,.95,Me).mul(T(1).sub(z(.95,1,Me))),T(0)),ke=S(xe,q(1,1,1),Se.mul(.65)).toVar(),Ee=S(ke,q(1,1,1),S(T(.6),T(.4),ce)),We=me.select(we.select(ke,Ee),ke);return H(We,Y.a.mul(fe))})(),N}screenQuad(e,t,s,a,r,l,o,i,n,h=0,u=!1,m,g=!1){const{pxPerWorld:w,pixelRatio:p,worldPerMetre:b,focal:f}=this,x=d.mul(H(e,1)).toVar(),M=d.mul(H(t,1)).toVar(),k=this.near.mul(1.01);g&&(v(x.w.lessThan(k),()=>{x.assign(S(x,M,c(k.sub(x.w).div(M.w.sub(x.w)),0,1)))}),v(M.w.lessThan(k),()=>{M.assign(S(M,x,c(k.sub(M.w).div(x.w.sub(M.w)),0,1)))}));const W=x.xy.div(x.w).mul(.5).add(.5).mul(n).toVar(),z=M.xy.div(M.w).mul(.5).add(.5).mul(n).toVar().sub(W).toVar(),R=y(z).toVar(),A=R.greaterThan(1e-6).select(z.div(V(R,1e-6)),L(1,0)).toVar(),q=L(A.y.negate(),A.x).toVar(),C=E.y.greaterThan(.5),F=C.select(M.w,x.w).toVar(),N=g?f.div(V(F,1e-6)):w,_=l.select(r.mul(N),r.mul(p)).toVar(),G=V(V(_,o.mul(b).mul(N)),p.mul(2*h)).toVar(),I=G.mul(.5).toVar(),O=i.select(p.mul(this.glowWidth),T(0)).toVar(),{arrowHalf:P,arrowSize:D,step:Q,outline:U}=B(_,p),j=V(s.z.sub(s.y),1e-6),J=g?R.div(j):w.toVar(),K=s.w.mul(J),X=s.w.mul(.5),Y=D.mul(.5).add(Q).add(G).div(J),Z=X.greaterThanEqual(s.y.sub(Y)).and(X.lessThan(s.z.add(Y))).and(K.greaterThanEqual(D.mul(3).add(Q.mul(2)))).and(T(u?0:1).greaterThan(.5)).and(m.not()),$=Z.select(X.sub(s.y).mul(J),T(-1e6)).toVar(),ee=V(I,Z.select(P.add(U),T(0))).add(V(O,this.outlineWidth.mul(p))).add(1),te=V(ee,Z.select(D.mul(.5).add(U).add(1),T(0))).toVar(),se=a.x.mul(b).sub(s.y).mul(J),ae=s.w.sub(a.y.mul(b)).sub(s.y).mul(J),re=E.x,le=C.select(R.add(te),te.negate()).toVar(),oe=W.add(A.mul(le)).add(q.mul(re.mul(ee))).div(n).mul(2).sub(1),ie=g?H(oe.mul(F),C.select(M.z,x.z),F):H(oe,0,1),ne=g?x.w.lessThan(k).and(M.w.lessThan(k)):T(0).greaterThan(1);return{clip:ie,w:g?F:T(1),local:L(le,re.mul(ee)),segLength:R,halfWidth:I,arrowCentre:$,arrowSize:D,arrowHalf:P,glow:O,step:Q,cutStart:se,cutEnd:ae,alongStart:s.y.mul(J),pixel:T(1),gone:ne}}groundQuad(e,t,s,a,r,l,o,i,n=0,h){const{pixelRatio:u,focal:g,up:w}=this,p=T(.05),b=t.sub(e).toVar(),f=y(b),v=b.div(V(f,1e-6)).toVar(),x=m(w,v),M=y(x).greaterThan(1e-4).select(k(x),k(m(v,q(1,0,0)))).toVar(),W=d.mul(H(e,1)).w.toVar(),z=d.mul(H(t,1)).w.toVar(),R=W.lessThan(p).and(z.lessThan(p)),A=c(p.sub(W).div(z.sub(W)),0,1),C=W.lessThan(p).select(A,T(0)).mul(f).toVar(),F=z.lessThan(p).select(A,T(1)).mul(f).toVar(),N=e=>(e=>V(S(W,z,e.div(V(f,1e-6))),p))(e).div(g),_=e=>l.select(r,r.mul(u).mul(e)),G=e=>V(V(_(e),o),u.mul(2*n).mul(e)),I=s.w.mul(.5),O=N(I.sub(s.y)).toVar(),{arrowHalf:P,arrowSize:D,step:Q}=B(_(O),u.mul(O)),U=D.mul(.5).add(Q).add(G(O)),j=I.greaterThanEqual(s.y.sub(U)).and(I.lessThan(s.z.add(U))).and(s.w.greaterThanEqual(D.mul(3).add(Q.mul(2)))).and(h.not()),J=j.select(I.sub(s.y),T(-1e6)).toVar(),K=E.x,X=E.y.greaterThan(.5),Y=e=>{const t=G(e),s=u.mul(1.5).mul(e);return V(t.mul(.5),j.select(P.add(s),T(0))).add(i.select(u.mul(this.glowWidth).mul(e),T(0))).add(e)},Z=X.select(F,C).toVar(),$=N(Z),ee=X.select(F.lessThan(f),C.greaterThan(0)).select(T(0),V(Y($),j.select(D.mul(.5).add($),T(0)))),te=X.select(Z.add(ee),Z.sub(ee)).toVar(),se=N(te).toVar(),ae=G(se),re=K.mul(Y(se)),le=e.add(v.mul(te)).add(M.mul(re));return{clip:d.mul(H(le,1)),w:T(1),local:L(te,re),segLength:f,halfWidth:ae.mul(.5),arrowCentre:J,arrowSize:D,arrowHalf:P,glow:i.select(u.mul(this.glowWidth).mul(se),T(0)),step:Q,cutStart:a.x.sub(s.y),cutEnd:s.w.sub(a.y).sub(s.y),alongStart:s.y,pixel:N(f.mul(.5)),gone:R}}}function B(e,t){const s=V(e,t.mul(3)),a=t.mul(16);return{arrowHalf:s,arrowSize:a,step:a.mul(.25),outline:t.mul(1.5)}}function J(e,t){return Math.hypot(t.x-e.x,t.y-e.y,t.z-e.z)}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Mesh } from 'three/webgpu';
|
|
2
|
+
import { GeometryFrame, GeometryPasses, GeometryPrimitive } from '../../engine/GeometryFrame';
|
|
3
|
+
import { FeatureLook } from '../FeatureLook';
|
|
4
|
+
import { Lighting } from '../Shading';
|
|
5
|
+
import { BodyOptions } from './Body';
|
|
6
|
+
/** A sphere: its centre relative to the origin, its feature's index, its radius, its reach (0: always). */
|
|
7
|
+
export type GpuSphere = {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
z: number;
|
|
11
|
+
index: number;
|
|
12
|
+
radius: number;
|
|
13
|
+
reach?: number;
|
|
14
|
+
};
|
|
15
|
+
export interface GpuSpheresOptions extends BodyOptions {
|
|
16
|
+
/** Feature count, when no look is given. */
|
|
17
|
+
count?: number;
|
|
18
|
+
/** Rings and segments of the sphere's mesh: more is rounder close in. */
|
|
19
|
+
detail?: [number, number];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Points in 3D as spheres, one instanced draw: connection points, sensors, nodes, at their real
|
|
23
|
+
* size and never smaller than their look's width in pixels. Shaded, ghosted, haloed, lit, picked
|
|
24
|
+
* and counted into the heatmap as the tubes are (`Body`).
|
|
25
|
+
*/
|
|
26
|
+
export declare class GpuSpheres implements GeometryPrimitive {
|
|
27
|
+
private readonly options;
|
|
28
|
+
readonly mesh: Mesh;
|
|
29
|
+
/** Silhouettes for the halo, where the scene's surface hides them; with a `sceneDepth` only. */
|
|
30
|
+
readonly haloMesh: Mesh | null;
|
|
31
|
+
readonly bloomMesh: Mesh;
|
|
32
|
+
readonly pickMesh: Mesh | null;
|
|
33
|
+
readonly densityMesh: Mesh;
|
|
34
|
+
readonly look: FeatureLook;
|
|
35
|
+
readonly lighting: Lighting;
|
|
36
|
+
readonly uniforms: {
|
|
37
|
+
focal: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
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>>;
|
|
48
|
+
constructor(spheres: GpuSphere[], options?: GpuSpheresOptions);
|
|
49
|
+
passes(): GeometryPasses;
|
|
50
|
+
setFrame(frame: GeometryFrame): void;
|
|
51
|
+
private meshes;
|
|
52
|
+
adopt(other: GeometryPrimitive): boolean;
|
|
53
|
+
dispose(): void;
|
|
54
|
+
private material;
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Float32BufferAttribute as e,InstancedBufferAttribute as t,InstancedBufferGeometry as s,Mesh as i}from"three/webgpu";import{attribute as o,cameraProjectionMatrix as h,float as n,Fn as a,int as r,max as l,mix as m,positionGeometry as c,uniform as p,vec2 as u,vec3 as d,vec4 as g}from"three/tsl";import{FeatureLook as w}from"../FeatureLook.js";import{Lighting as M}from"../Shading.js";import{adoptGeometry as f,disposeMaterial as y,GONE as v,unculled as x}from"../Tsl.js";import{bodyFragment as b,bodyMaterial as k,bodyUniforms as T,bodyVaryings as I,HALO_GROW as A,pixelSize as P}from"./Body.js";export class GpuSpheres{constructor(o,h={}){this.options=h,this.uniforms=T(),this.near=p(.3),this.look=h.look??new w(h.count??o.reduce((e,t)=>Math.max(e,t.index+1),0)),this.lighting=h.lighting??new M;const n=function(i,[o,h]){const n=[],a=[];for(let e=0;e<=o;e++){const t=e/o*Math.PI;for(let e=0;e<=h;e++){const s=e/h*2*Math.PI;n.push(Math.sin(t)*Math.cos(s),Math.sin(t)*Math.sin(s),Math.cos(t))}}for(let e=0;e<o;e++)for(let t=0;t<h;t++){const s=e*(h+1)+t,i=s+h+1;a.push(s,i,s+1,s+1,i,i+1)}const r=i.length,l=new Float32Array(3*r),m=new Float32Array(3*r);i.forEach((e,t)=>{l[3*t]=e.x,l[3*t+1]=e.y,l[3*t+2]=e.z,m[3*t]=e.index,m[3*t+1]=e.radius,m[3*t+2]=e.reach??0});const c=new s;return c.setAttribute("position",new e(n,3)),c.setIndex(a),c.setAttribute("aCentre",new t(l,3)),c.setAttribute("aInfo",new t(m,3)),c.instanceCount=r,c}(o,h.detail??[10,16]);this.mesh=x(new i(n,this.material("solid"))),this.haloMesh=h.sceneDepth?x(new i(n,this.material("window"))):null,this.bloomMesh=x(new i(n,this.material("bloom"))),this.bloomMesh.visible=!1,this.pickMesh=h.pick?x(new i(n,this.material("pick"))):null,this.densityMesh=x(new i(n,this.material("density"))),this.densityMesh.visible=!1}passes(){return{scene:[this.mesh],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.pickMesh,this.densityMesh]}adopt(e){return e instanceof GpuSpheres&&f(this.meshes(),e.meshes())}dispose(){this.mesh.geometry.dispose(),this.meshes().forEach(y),this.options.look||this.look.dispose()}material(e){const t="pick"===e,s=k(e),i=this.uniforms,{vColor:p,vNormal:w,vDistance:M,vPosition:f,vMaterial:y,vIndex:x}=I(),T=this.options.pick;return s.vertexNode=a(()=>{const s=o("aCentre","vec3"),a=o("aInfo","vec3"),b=c,k=this.look.read(r(a.x)),I=k.selected,j=I.select(l(k.alpha,n(1)),k.alpha),C=I.select(m(k.rgb,d(1,1,1),i.litMix),k.rgb),F=l(h.mul(g(s,1)).w,this.near),N=P(i,F).mul(i.pixelRatio),R=l(N.mul(k.width).mul(.5),t?N.mul(4):n(0)),S=l(a.y,R),W="window"===e?n(A):"casing"===e?N.mul(i.outlineWidth):n(0),z=s.add(b.mul(S.add(W))),D=h.mul(g(z,1));p.assign(g(C,"density"===e?k.weight:j)),w.assign(b),M.assign(D.w),f.assign(z),x.assign(a.x),y.assign(u(k.material,I.select(n(1),n(0))));const E=a.z;return j.lessThan(.001).or(E.greaterThan(0).and(D.w.greaterThan(E))).or("bloom"===e?I.not():n(0).greaterThan(1)).or("density"===e?k.weight.lessThan(.001):n(0).greaterThan(1)).select(v(),t&&T?T.pass.window.mul(D):D)})(),s.fragmentNode=b(e,this.options,i,this.lighting),s}}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Mesh, Vector3 } from 'three/webgpu';
|
|
2
|
+
import { GeometryFrame, GeometryPasses, GeometryPrimitive } from '../../engine/GeometryFrame';
|
|
3
|
+
import { FeatureLook } from '../FeatureLook';
|
|
4
|
+
import { Lighting } from '../Shading';
|
|
5
|
+
import { BodyOptions } from './Body';
|
|
6
|
+
/**
|
|
7
|
+
* A tube's cross-section, in world units: half its width, half its height, and its corners'
|
|
8
|
+
* radius. A round one has all three the same; a box culvert a small corner radius.
|
|
9
|
+
*/
|
|
10
|
+
export type Profile = [number, number, number];
|
|
11
|
+
export declare function roundProfile(radius: number): Profile;
|
|
12
|
+
/**
|
|
13
|
+
* A rectangle of a width and height whose corners are rounded by `cornerShare` of half the
|
|
14
|
+
* smaller side: an egg or a mouth profile, until the real outlines come.
|
|
15
|
+
*/
|
|
16
|
+
export declare function boxProfile(width: number, height: number, cornerShare?: number): Profile;
|
|
17
|
+
export type TubeKind = 'line' | 'shaft' | 'column';
|
|
18
|
+
/** One tube: a path through space, drawn as segments that meet in mitred joints. */
|
|
19
|
+
export interface GpuTube {
|
|
20
|
+
/** Its points, relative to the engine's origin. */
|
|
21
|
+
points: readonly (readonly number[])[];
|
|
22
|
+
/** Its feature's index into the look. */
|
|
23
|
+
index: number;
|
|
24
|
+
profile: Profile;
|
|
25
|
+
/** Drawn only within this distance of the camera; 0 for always. */
|
|
26
|
+
reach?: number;
|
|
27
|
+
/**
|
|
28
|
+
* `line`, a pipe; `shaft`, standing, its top left open for a cover lying there; `column`,
|
|
29
|
+
* standing and closed.
|
|
30
|
+
*/
|
|
31
|
+
kind?: TubeKind;
|
|
32
|
+
/**
|
|
33
|
+
* How far each end was cut back from a junction's axis to its wall, in world units: the tube
|
|
34
|
+
* runs on to the axis, and as far again as it is wide, where the junction is not drawn
|
|
35
|
+
* (beyond `shaftReach`), so tubes meeting there join rather than leave a gap.
|
|
36
|
+
*/
|
|
37
|
+
cuts?: [number, number];
|
|
38
|
+
/** The point before the first and after the last: a neighbour to mitre onto at each end. */
|
|
39
|
+
before?: readonly number[];
|
|
40
|
+
after?: readonly number[];
|
|
41
|
+
}
|
|
42
|
+
export interface GpuTubesOptions extends BodyOptions {
|
|
43
|
+
/** The ground's up at the origin: tubes turn their height up and down it. */
|
|
44
|
+
up?: readonly number[];
|
|
45
|
+
/**
|
|
46
|
+
* The flow arrow on each line tube, as a 2D map draws it on its line: at its middle, laid out
|
|
47
|
+
* in pixels at the tube's course and depth, over the tubes.
|
|
48
|
+
*/
|
|
49
|
+
arrows?: boolean;
|
|
50
|
+
/** Feature count, when no look is given: one of the tubes' own is made that large. */
|
|
51
|
+
count?: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Pipes, cables, ducts, shafts and columns as tubes, one instanced draw: every segment a unit
|
|
55
|
+
* cylinder with caps, turned and stretched onto its course in the vertex shader, at its real size
|
|
56
|
+
* and cross-section - round, or a rectangle with rounded corners - and mitred to the next segment
|
|
57
|
+
* so a bend is closed all round. Never thinner on screen than its look's width in pixels: far off
|
|
58
|
+
* the same draw is a line that many pixels wide, still at its depth.
|
|
59
|
+
*
|
|
60
|
+
* Painted in the feature's colour with its material's finish (`Lighting`). Behind the scene's
|
|
61
|
+
* surface (`sceneDepth`) drawn ghosted, and outlined by the engine's halo from the `window` pass.
|
|
62
|
+
* Selected ones lit, bloomed or outlined (`casingMesh`); picked by their shape, mitres and all.
|
|
63
|
+
*
|
|
64
|
+
* The Ing+ map's 3D sewer network, made general.
|
|
65
|
+
*/
|
|
66
|
+
export declare class GpuTubes implements GeometryPrimitive {
|
|
67
|
+
private readonly options;
|
|
68
|
+
readonly mesh: Mesh;
|
|
69
|
+
/** Silhouettes for the halo, where the scene's surface hides them; with a `sceneDepth` only. */
|
|
70
|
+
readonly haloMesh: Mesh | null;
|
|
71
|
+
readonly bloomMesh: Mesh;
|
|
72
|
+
readonly casingMesh: Mesh;
|
|
73
|
+
readonly pickMesh: Mesh | null;
|
|
74
|
+
readonly densityMesh: Mesh;
|
|
75
|
+
/** The flow arrows, with `arrows`. */
|
|
76
|
+
readonly arrowMesh: Mesh | null;
|
|
77
|
+
readonly look: FeatureLook;
|
|
78
|
+
readonly lighting: Lighting;
|
|
79
|
+
readonly uniforms: {
|
|
80
|
+
focal: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
81
|
+
pixelRatio: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
82
|
+
orthographic: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
83
|
+
pxPerWorld: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
84
|
+
ghostAlpha: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
85
|
+
ghostLighten: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
86
|
+
outlineRgb: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
87
|
+
outlineWidth: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
88
|
+
litMix: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
89
|
+
};
|
|
90
|
+
segments: number;
|
|
91
|
+
readonly near: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
92
|
+
/**
|
|
93
|
+
* How far from the camera the junctions are drawn: a tube ending in one further off runs on to
|
|
94
|
+
* its axis rather than stopping at a wall that is not there.
|
|
95
|
+
*/
|
|
96
|
+
readonly shaftReach: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
97
|
+
private readonly up;
|
|
98
|
+
constructor(tubes: GpuTube[], options?: GpuTubesOptions);
|
|
99
|
+
passes(): GeometryPasses;
|
|
100
|
+
setFrame(frame: GeometryFrame): void;
|
|
101
|
+
private meshes;
|
|
102
|
+
adopt(other: GeometryPrimitive): boolean;
|
|
103
|
+
dispose(): void;
|
|
104
|
+
/**
|
|
105
|
+
* The cylinders: `solid` the tubes, `window` their silhouettes where the scene's surface hides
|
|
106
|
+
* them, a little widened, `bloom` the selected ones alone, `casing` the outline's band round
|
|
107
|
+
* them, `pick` each one's index into the pick window - at least `PICK_MIN_PIXELS` thick, a
|
|
108
|
+
* standing one as much longer too - and `density` their weights.
|
|
109
|
+
*/
|
|
110
|
+
private cylinderMaterial;
|
|
111
|
+
/**
|
|
112
|
+
* The flow arrow on each line tube: a triangle `ARROW_LENGTH` long, as high either side as the
|
|
113
|
+
* tube's look is wide in pixels (`ARROW_MIN_HALF_HEIGHT` at least), in the tube's colour
|
|
114
|
+
* outlined in black, at the tube's middle - only where the tube is three arrows and two gaps
|
|
115
|
+
* long on screen. Laid out in pixels at the tube's own course, at any distance; drawn over
|
|
116
|
+
* the tubes and through the surface, not through what stands in front.
|
|
117
|
+
*/
|
|
118
|
+
private arrowMaterial;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Where two tubes end at the same point - within `tolerance` - and no other does, each takes the
|
|
122
|
+
* other as its neighbour there, as a bend in one tube does: they meet in a mitre rather than two
|
|
123
|
+
* flat caps. Sets `before` and `after` of the tubes given; returns them.
|
|
124
|
+
*/
|
|
125
|
+
export declare function joinTubeEnds(tubes: GpuTube[], tolerance?: number): GpuTube[];
|
|
@@ -0,0 +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(B.alpha,m(1)),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("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))}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CanvasTexture } from 'three/webgpu';
|
|
2
|
+
/** Each icon's cell in an atlas, px square. */
|
|
3
|
+
export declare const ICON_CELL = 128;
|
|
4
|
+
/** An icon for the atlas: an image's url (a data url, an SVG's), or a drawing of its own on a cell. */
|
|
5
|
+
export type IconSource = string | ((context: CanvasRenderingContext2D, size: number) => void);
|
|
6
|
+
/**
|
|
7
|
+
* Icons in one texture, each drawn into a cell of one row - cell `i` the i-th source - stretched
|
|
8
|
+
* to the square. Rows run top-down (`flipY` off). Drawn as they load; `loaded` asks for a frame.
|
|
9
|
+
*/
|
|
10
|
+
export declare function iconAtlas(sources: IconSource[], loaded?: () => void): CanvasTexture;
|
|
11
|
+
/** An SVG as a data url, for `iconAtlas`. */
|
|
12
|
+
export declare function svgIcon(svg: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{CanvasTexture as e,LinearFilter as t}from"three/webgpu";export const ICON_CELL=128;export function iconAtlas(n,o=()=>{}){const r=document.createElement("canvas");r.width=128*Math.max(1,n.length),r.height=128;const a=new e(r);a.flipY=!1,a.generateMipmaps=!1,a.minFilter=t,a.magFilter=t;const c=r.getContext("2d");return n.forEach((e,t)=>{if("function"==typeof e)return c.save(),c.translate(128*t,0),c.beginPath(),c.rect(0,0,128,128),c.clip(),e(c,128),c.restore(),void(a.needsUpdate=!0);const n=new Image;n.crossOrigin="anonymous",n.onload=()=>{c.drawImage(n,128*t,0,128,128),a.needsUpdate=!0,o()},n.src=e}),n.some(e=>"function"==typeof e)&&queueMicrotask(o),a}export function svgIcon(e){return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`}
|