@protomaze/geometry 0.0.0-stage → 0.1.0
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 +294 -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 +257 -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,48 @@
|
|
|
1
|
+
import { HostedGeometryEngine } from './HostedGeometryEngine';
|
|
2
|
+
/**
|
|
3
|
+
* What the engine uses of a LuciadRIA `WebGLMap`, typed by shape so this package needs no RIA:
|
|
4
|
+
* RIA 2026's map, which renders with WebGPU only, fits it as it is.
|
|
5
|
+
*/
|
|
6
|
+
export interface RiaMapLike {
|
|
7
|
+
webGPUDevice?: unknown;
|
|
8
|
+
reference: {
|
|
9
|
+
identifier: string;
|
|
10
|
+
};
|
|
11
|
+
camera: {
|
|
12
|
+
viewProjectionMatrix: ArrayLike<number>;
|
|
13
|
+
near: number;
|
|
14
|
+
eye: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
z: number;
|
|
18
|
+
};
|
|
19
|
+
fovY?: number;
|
|
20
|
+
height?: number;
|
|
21
|
+
};
|
|
22
|
+
viewSize: [number, number] | number[];
|
|
23
|
+
on(event: 'WebGPUDeviceChanged' | 'PostRender', callback: (...args: any[]) => void): {
|
|
24
|
+
remove(): void;
|
|
25
|
+
};
|
|
26
|
+
invalidate(): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The engine on a LuciadRIA map: draws into the map's own frame on "PostRender", with its device,
|
|
30
|
+
* camera and depth, over every GPU layer and under the map's HTML labels. One per map (`of`).
|
|
31
|
+
*
|
|
32
|
+
* The Ing+ map's `RiaThreeRenderer` is this: `scene`, `underlayScene`, `bloomScene`,
|
|
33
|
+
* `pickScene`, `pickPass`, `density`, `frame`, `setOrigin`, `getOrigin`, `depthTexture`,
|
|
34
|
+
* `onBeforeRender`, `onBeforeDraw`, `requestRepaint`, `renderToTarget`, `addPickSource` and
|
|
35
|
+
* `pick` are all here with the same meaning; `pick` gives the point hit as numbers in the map's
|
|
36
|
+
* reference, for the map to make a `Point` of.
|
|
37
|
+
*/
|
|
38
|
+
export declare class RiaGeometryEngine extends HostedGeometryEngine {
|
|
39
|
+
private readonly map;
|
|
40
|
+
/** The one engine of this map, made on first use. */
|
|
41
|
+
static of(map: RiaMapLike): RiaGeometryEngine;
|
|
42
|
+
/** The map's engine if something has made one, without making it. */
|
|
43
|
+
static existing(map: RiaMapLike): RiaGeometryEngine | null;
|
|
44
|
+
private handles;
|
|
45
|
+
constructor(map: RiaMapLike);
|
|
46
|
+
private renderMap;
|
|
47
|
+
dispose(): void;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{HostedGeometryEngine as e}from"./HostedGeometryEngine.js";const t=new WeakMap;export class RiaGeometryEngine extends e{static of(e){let i=t.get(e);return i||(i=new RiaGeometryEngine(e),t.set(e,i)),i}static existing(e){return t.get(e)??null}constructor(e){super({device:e.webGPUDevice,requestFrame:()=>{const t=e._viewPaintingStrategy;t?.repaint?t.repaint():e.invalidate()},originKey:()=>e.reference.identifier.toLowerCase()}),this.map=e,this.handles=[],this.handles.push(e.on("WebGPUDeviceChanged",()=>this.setDevice(e.webGPUDevice)),e.on("PostRender",(e,t)=>this.renderMap(e,t)))}renderMap(e,t){const i=this.map,n=e.width/Math.max(1,i.viewSize[0]),r=i.camera,s=(r.fovY??60)*Math.PI/180,a="epsg:4978"===i.reference.identifier.toLowerCase();this.render(e,t,{viewProjection:r.viewProjectionMatrix,glDepth:!0,near:r.near,pixelRatio:n,geocentric:a,focal:a&&r.height?r.height*n/2/Math.tan(s/2):void 0,eye:[r.eye.x,r.eye.y,r.eye.z]})}dispose(){this.handles.forEach(e=>e.remove()),this.handles=[],t.delete(this.map),super.dispose()}}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Vector3 } from 'three/webgpu';
|
|
2
|
+
import { N } from './Tsl';
|
|
3
|
+
/**
|
|
4
|
+
* The finishes bodies are painted in, by `materialCode`, the first for any other; the colour is
|
|
5
|
+
* the feature's, as paint. `shininess` is how tight the highlight is, `sheen` how bright.
|
|
6
|
+
* Concrete matt, vitrified clay glazed and glossy, PVC, PP, GRP and other plastics satin, PE-HD a
|
|
7
|
+
* soft sheen, steel bright, cast iron dull - the Ing+ map's pipes.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MATERIALS: {
|
|
10
|
+
name: string;
|
|
11
|
+
shininess: number;
|
|
12
|
+
sheen: number;
|
|
13
|
+
}[];
|
|
14
|
+
/** Material names and the German abbreviations of sewer data, as an index into `MATERIALS`. */
|
|
15
|
+
export declare const MATERIAL_CODES: Record<string, number>;
|
|
16
|
+
/** A material's index into `MATERIALS`: by its index, its name or its abbreviation; 0 for none. */
|
|
17
|
+
export declare function materialCode(value: unknown): number;
|
|
18
|
+
/**
|
|
19
|
+
* The light bodies are shaded with: a fixed sun, high up from the south-east as the 2D icons are
|
|
20
|
+
* shaded, and the sky above. `up` is the ground's up at the origin; `eye` the camera, relative
|
|
21
|
+
* to the origin, set each frame.
|
|
22
|
+
*/
|
|
23
|
+
export declare class Lighting {
|
|
24
|
+
readonly up: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
25
|
+
readonly sun: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
26
|
+
readonly eye: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
27
|
+
/** How bright the sky is from below and from above, and the sun on top of it. */
|
|
28
|
+
readonly ambient: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
29
|
+
readonly skyGain: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
30
|
+
readonly sunGain: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
31
|
+
/** Every material's shininess and sheen, a texel each. */
|
|
32
|
+
readonly materials: import("three/webgpu").DataTexture;
|
|
33
|
+
constructor();
|
|
34
|
+
/** Sets up and the sun with it: from the south-east, high up, in the local frame of `up`. */
|
|
35
|
+
setUp(up: readonly number[]): void;
|
|
36
|
+
/**
|
|
37
|
+
* Paint lit with a material's finish (`materialCode`): diffuse from the sun, the sky by how
|
|
38
|
+
* much the surface faces up, a highlight as tight and bright as the material is glossy. A
|
|
39
|
+
* dozen operations a pixel.
|
|
40
|
+
*/
|
|
41
|
+
shade(code: N, normal: N, position: N, paint: N): N;
|
|
42
|
+
}
|
package/three/Shading.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Vector3 as e}from"three/webgpu";import{rowTexture as s}from"./Tsl.js";import{dot as n,float as i,int as t,ivec2 as a,max as h,min as r,normalize as o,pow as m,textureLoad as c,uniform as l,vec3 as E}from"three/tsl";export const MATERIALS=[{name:"default",shininess:10,sheen:.06},{name:"concrete",shininess:4,sheen:.02},{name:"reinforced concrete",shininess:4,sheen:.03},{name:"vitrified clay",shininess:90,sheen:.55},{name:"pvc",shininess:40,sheen:.3},{name:"pe",shininess:30,sheen:.25},{name:"pp",shininess:40,sheen:.3},{name:"grp",shininess:35,sheen:.25},{name:"steel",shininess:120,sheen:.8},{name:"cast iron",shininess:20,sheen:.2},{name:"plastic",shininess:40,sheen:.3},{name:"glass",shininess:160,sheen:.9},{name:"brick",shininess:3,sheen:.015}];export const MATERIAL_CODES={DEFAULT:0,B:1,BE:1,BKF:1,BETON:1,CONCRETE:1,SB:2,STB:2,STAHLBETON:2,REINFORCEDCONCRETE:2,STZ:3,STEINZEUG:3,VITRIFIEDCLAY:3,CLAY:3,PVC:4,PVCU:4,PV:4,PE:5,PEHD:5,HDPE:5,PP:6,GFK:7,GFUP:7,GRP:7,ST:8,STL:8,STAHL:8,STEEL:8,GG:9,GGG:9,GUSS:9,CASTIRON:9,DUCTILEIRON:9,KS:10,KST:10,KUNSTSTOFF:10,PLASTIC:10,GLASS:11,GLAS:11,BRICK:12,MAUERWERK:12,MW:12};export function materialCode(e){return"number"==typeof e?e>=0&&e<MATERIALS.length?Math.floor(e):0:"string"!=typeof e?0:MATERIAL_CODES[e.toUpperCase().replace(/[^A-Z]/g,"")]??0}export class Lighting{constructor(){this.up=l(new e(0,0,1)),this.sun=l(new e(.4,-.3,.87).normalize()),this.eye=l(new e),this.ambient=l(.36),this.skyGain=l(.14),this.sunGain=l(.7),this.materials=s(new Float32Array(64));const n=this.materials.image.data;MATERIALS.forEach((e,s)=>n.set([e.shininess,e.sheen,0,0],4*s)),this.materials.needsUpdate=!0}setUp(s){const n=new e(s[0],s[1],s[2]).normalize();this.up.value.copy(n);const i=Math.abs(n.z)>.99?new e(0,1,0):new e(0,0,1),t=(new e).crossVectors(i,n).normalize();Math.abs(n.z)>.99&&t.set(1,0,0);const a=(new e).crossVectors(n,t).normalize();this.sun.value.copy(t.multiplyScalar(.4).addScaledVector(a,-.3).addScaledVector(n,.87)).normalize()}shade(e,s,l,S){const p=c(this.materials,a(t(h(r(e,i(MATERIALS.length-1)),i(0)).add(.5)),t(0))).toVar(),T=p.x,d=p.y,u=o(s),A=o(this.eye.sub(l)),L=h(n(u,this.sun),0),C=this.ambient.add(n(u,this.up).mul(this.skyGain)),R=o(this.sun.add(A)),G=m(h(n(u,R),0),T).mul(d);return S.mul(C.add(L.mul(this.sunGain))).add(E(G,G,G))}}
|
package/three/Sky.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Mesh, Vector3 } from 'three/webgpu';
|
|
2
|
+
/**
|
|
3
|
+
* The sky behind a view in perspective: dark overhead, lighter towards the horizon, with a faint
|
|
4
|
+
* glow just above it - each pixel's colour from the direction it looks in, the view's own
|
|
5
|
+
* view-projection inverted. Drawn first in the engine's base, writing no depth: where only the sky
|
|
6
|
+
* is, the scene is infinitely far.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Sky {
|
|
9
|
+
readonly mesh: Mesh;
|
|
10
|
+
readonly zenith: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<import("three/webgpu").Color>>;
|
|
11
|
+
readonly horizon: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<import("three/webgpu").Color>>;
|
|
12
|
+
readonly glow: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<import("three/webgpu").Color>>;
|
|
13
|
+
/** What a view looking down past the ground sees. */
|
|
14
|
+
readonly below: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<import("three/webgpu").Color>>;
|
|
15
|
+
/** The camera relative to the origin, and the ground's up. */
|
|
16
|
+
readonly eye: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
17
|
+
readonly up: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
18
|
+
constructor();
|
|
19
|
+
setColors(colors: {
|
|
20
|
+
zenith: string;
|
|
21
|
+
horizon: string;
|
|
22
|
+
glow: string;
|
|
23
|
+
below: string;
|
|
24
|
+
}): void;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
private material;
|
|
27
|
+
}
|
package/three/Sky.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Mesh as e,PlaneGeometry as t,Vector3 as s}from"three/webgpu";import{cameraProjectionMatrixInverse as i,float as h,Fn as o,max as r,mix as l,normalize as n,pow as u,positionGeometry as m,screenCoordinate as w,smoothstep as a,uniform as d,vec4 as p,viewport as z}from"three/tsl";import{disposeMaterial as b,nodeMaterial as g,rawColor as v,unculled as y}from"./Tsl.js";export class Sky{constructor(){this.zenith=d(v("#05070a")),this.horizon=d(v("#1a2533")),this.glow=d(v("#27425c")),this.below=d(v("#0b0d10")),this.eye=d(new s),this.up=d(new s(0,0,1)),this.mesh=y(new e(new t(2,2),this.material()),-2e3)}setColors(e){v(e.zenith,this.zenith.value),v(e.horizon,this.horizon.value),v(e.glow,this.glow.value),v(e.below,this.below.value)}dispose(){this.mesh.geometry.dispose(),b(this.mesh)}material(){const e=g();return e.depthTest=!1,e.depthWrite=!1,e.vertexNode=o(()=>p(m.xy,0,1))(),e.fragmentNode=o(()=>{const e=z.zw,t=p(w.x.div(e.x).mul(2).sub(1),h(1).sub(w.y.div(e.y).mul(2)),.5,1),s=i.mul(t),o=n(s.xyz.div(s.w).sub(this.eye)).dot(this.up),m=u(r(o,0),.45),d=l(this.horizon,this.zenith,m),b=h(1).sub(a(0,.12,o)).mul(a(-.02,0,o)),g=l(d,this.glow,b.mul(.6)),v=o.lessThan(0).select(l(this.horizon,this.below,a(0,.08,o.negate())),g);return p(v,1)})(),e}}
|
package/three/Tsl.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BufferGeometry, Color, DataTexture, InstancedBufferGeometry, Mesh, MeshBasicNodeMaterial } from 'three/webgpu';
|
|
2
|
+
/**
|
|
3
|
+
* TSL nodes are typed loosely here on purpose: the node types of @types/three change from release
|
|
4
|
+
* to release, and the package runs on three 0.178 and later.
|
|
5
|
+
*/
|
|
6
|
+
export type N = any;
|
|
7
|
+
/** The width of every per-feature texture: feature `i` is texel `(i % 1024, i / 1024)`. */
|
|
8
|
+
export declare const TEXTURE_WIDTH = 1024;
|
|
9
|
+
/** Texel of feature `index` (an int node) in a per-feature texture. */
|
|
10
|
+
export declare function texelOf(index: N): N;
|
|
11
|
+
/** A float RGBA texture of `rows` rows of `TEXTURE_WIDTH` texels, read with `textureLoad`. */
|
|
12
|
+
export declare function featureTexture(data: Float32Array, rows: number): DataTexture;
|
|
13
|
+
/** A one-row float RGBA texture, sampled with filtering when `linear`. */
|
|
14
|
+
export declare function rowTexture(data: Float32Array, linear?: boolean): DataTexture;
|
|
15
|
+
export declare function rowsFor(count: number): number;
|
|
16
|
+
/** A vertex that is not drawn: outside clip space, so its triangles are clipped away whole. */
|
|
17
|
+
export declare const GONE: () => import("three/tsl").ShaderNodeObject<import("three/webgpu").ConstNode<import("three/webgpu").Vector4>>;
|
|
18
|
+
/** Makes a material add what it draws into the target: a weight into the density sum. */
|
|
19
|
+
export declare function additive(material: MeshBasicNodeMaterial): void;
|
|
20
|
+
/**
|
|
21
|
+
* Disposes a mesh's material. three 0.178 throws disposing a node material that never drew (the
|
|
22
|
+
* bloom with nothing selected, the pick pass with nothing clicked): what is dropped is dropped
|
|
23
|
+
* either way.
|
|
24
|
+
*/
|
|
25
|
+
export declare function disposeMaterial(mesh: Mesh | null | undefined): void;
|
|
26
|
+
/**
|
|
27
|
+
* Hands the geometries of `theirs` - the same meshes of a primitive built again from new data -
|
|
28
|
+
* to `mine`, whose materials are compiled: three keeps a mesh's pipeline when only its geometry
|
|
29
|
+
* changes, so an edit costs the buffers alone. Geometries `mine` no longer uses are disposed;
|
|
30
|
+
* `theirs` are left with an empty one. False, changing nothing, when the two do not match mesh
|
|
31
|
+
* for mesh.
|
|
32
|
+
*/
|
|
33
|
+
export declare function adoptGeometry(mine: readonly (Mesh | null | undefined)[], theirs: readonly (Mesh | null | undefined)[]): boolean;
|
|
34
|
+
/** A mesh drawn wherever its vertex shader puts it: three's culling knows nothing of that. */
|
|
35
|
+
export declare function unculled(mesh: Mesh, order?: number): Mesh<BufferGeometry<import("three/webgpu").NormalBufferAttributes, import("three/webgpu").BufferGeometryEventMap>, import("three/webgpu").Material | import("three/webgpu").Material[], import("three/webgpu").Object3DEventMap>;
|
|
36
|
+
/** Instanced quads: x the side (-1, 1), y the end (0 start, 1 end) - a segment's quad. */
|
|
37
|
+
export declare function segmentQuad(geometry: InstancedBufferGeometry): InstancedBufferGeometry;
|
|
38
|
+
/** Instanced squares, -1 to 1 either way: an icon's or a disc's quad. */
|
|
39
|
+
export declare function centredQuad(geometry: InstancedBufferGeometry): InstancedBufferGeometry;
|
|
40
|
+
/**
|
|
41
|
+
* A CSS colour as three's `Color`, its values as written: the package draws colours as the
|
|
42
|
+
* application gives them, with no conversion on the way out, so none on the way in either.
|
|
43
|
+
* (`new Color('#e8eef3')` would hold the linear values, darker once drawn.)
|
|
44
|
+
*/
|
|
45
|
+
export declare function rawColor(css: string, into?: Color): Color;
|
|
46
|
+
/** A plain node material, both sides, the way most passes start. */
|
|
47
|
+
export declare function nodeMaterial(): MeshBasicNodeMaterial;
|
package/three/Tsl.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{AddEquation as e,BufferGeometry as t,Color as r,CustomBlending as n,DataTexture as o,Float32BufferAttribute as i,FloatType as u,LinearFilter as a,LinearSRGBColorSpace as p,MeshBasicNodeMaterial as s,NearestFilter as c,OneFactor as d,RGBAFormat as l}from"three/webgpu";import{int as f,ivec2 as m,vec4 as x}from"three/tsl";export const TEXTURE_WIDTH=1024;export function texelOf(e){return m(e.mod(f(1024)),e.div(f(1024)))}export function featureTexture(e,t){const r=new o(e,1024,t,l,u);return r.minFilter=c,r.magFilter=c,r.generateMipmaps=!1,r.needsUpdate=!0,r}export function rowTexture(e,t=!1){const r=new o(e,e.length/4,1,l,u);return r.minFilter=t?a:c,r.magFilter=t?a:c,r.generateMipmaps=!1,r.needsUpdate=!0,r}export function rowsFor(e){return Math.max(1,Math.ceil(e/1024))}export const GONE=()=>x(2,2,2,1);export function additive(t){t.transparent=!0,t.depthTest=!1,t.depthWrite=!1,t.blending=n,t.blendEquation=e,t.blendSrc=d,t.blendDst=d,t.blendSrcAlpha=d,t.blendDstAlpha=d}export function disposeMaterial(e){if(e)try{e.material.dispose()}catch{}}export function adoptGeometry(e,r){if(e.length!==r.length||e.some((e,t)=>!e!=!r[t]))return!1;const n=new Set;e.forEach(e=>{e&&n.add(e.geometry)});const o=new t;e.forEach((e,t)=>{e&&(e.geometry=r[t].geometry)}),r.forEach(e=>{e&&(e.geometry=o)});const i=new Set(e.map(e=>e?.geometry));return n.forEach(e=>{i.has(e)||e.dispose()}),!0}export function unculled(e,t=0){return e.frustumCulled=!1,e.renderOrder=t,e}export function segmentQuad(e){return e.setAttribute("position",new i([-1,0,0,1,0,0,1,1,0,-1,0,0,1,1,0,-1,1,0],3)),e}export function centredQuad(e){return e.setAttribute("position",new i([-1,-1,0,1,-1,0,1,1,0,-1,-1,0,1,1,0,-1,1,0],3)),e}export function rawColor(e,t=new r){return t.setStyle(e,p)}export function nodeMaterial(){return new s}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Texture, Vector3 } from 'three/webgpu';
|
|
2
|
+
import { GeometryOccluder, PickOptions } from '../../engine/GeometryFrame';
|
|
3
|
+
import { FeatureLook } from '../FeatureLook';
|
|
4
|
+
import { Lighting } from '../Shading';
|
|
5
|
+
import { N } from '../Tsl';
|
|
6
|
+
/**
|
|
7
|
+
* The passes a body - a tube, a sphere - is drawn in: `solid` itself, `window` its silhouette
|
|
8
|
+
* where the scene's surface hides it, into the halo's mask, `bloom` the selected ones alone,
|
|
9
|
+
* `casing` the outline round the selected ones, `pick` each one's index into the pick window,
|
|
10
|
+
* `density` its weight into the heatmap.
|
|
11
|
+
*/
|
|
12
|
+
export type BodyPass = 'solid' | 'window' | 'bloom' | 'casing' | 'pick' | 'density';
|
|
13
|
+
/**
|
|
14
|
+
* The scene's depth, as an engine has it: a texture holding `1 - near / w` per frame pixel, and
|
|
15
|
+
* whether it holds this frame's. Bodies behind it are drawn ghosted, and outlined by the halo.
|
|
16
|
+
*/
|
|
17
|
+
export interface SceneDepth {
|
|
18
|
+
readonly texture: Texture;
|
|
19
|
+
/** 1 while `texture` holds this frame's depth. */
|
|
20
|
+
readonly enabled: {
|
|
21
|
+
value: number;
|
|
22
|
+
};
|
|
23
|
+
readonly near: {
|
|
24
|
+
value: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** A fragment this much further than the scene's surface, in world units, is behind it. */
|
|
28
|
+
export declare const DEPTH_SLACK = 0.05;
|
|
29
|
+
/** How much the halo's silhouettes are widened, in world units. */
|
|
30
|
+
export declare const HALO_GROW = 0.25;
|
|
31
|
+
export interface BodyOptions {
|
|
32
|
+
/** The scene's depth: what lies behind it is drawn ghosted (`ghostAlpha`) and haloed. */
|
|
33
|
+
sceneDepth?: SceneDepth | null;
|
|
34
|
+
/** What stands in front and hides a body outright (the Ing+ map's buildings mask). */
|
|
35
|
+
occluder?: GeometryOccluder | null;
|
|
36
|
+
pick?: PickOptions;
|
|
37
|
+
look?: FeatureLook;
|
|
38
|
+
/** Shared lighting; one of the body's own when not given. */
|
|
39
|
+
lighting?: Lighting;
|
|
40
|
+
}
|
|
41
|
+
/** The uniforms every body shares. */
|
|
42
|
+
export declare function bodyUniforms(): {
|
|
43
|
+
/** Frame pixels per world unit at one unit from the camera. */
|
|
44
|
+
focal: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
45
|
+
/** Frame pixels per view pixel. */
|
|
46
|
+
pixelRatio: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
47
|
+
/** 1 on a flat (orthographic) map, where a pixel is `1 / pxPerWorld` everywhere. */
|
|
48
|
+
orthographic: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
49
|
+
pxPerWorld: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
50
|
+
/** How much of a body shows where the scene's surface is in front of it. */
|
|
51
|
+
ghostAlpha: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
52
|
+
/** And how much lighter it is drawn there, so it reads as seen through something. */
|
|
53
|
+
ghostLighten: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
54
|
+
/** The outline look's colour and width (view pixels). */
|
|
55
|
+
outlineRgb: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
56
|
+
outlineWidth: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
57
|
+
/** How much a selected body is lit towards white. */
|
|
58
|
+
litMix: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
59
|
+
};
|
|
60
|
+
export type BodyUniforms = ReturnType<typeof bodyUniforms>;
|
|
61
|
+
/**
|
|
62
|
+
* What a body's vertex shader hands its fragment: colour and alpha, normal, distance from the
|
|
63
|
+
* camera, position relative to the origin, material and selection, index.
|
|
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
|
+
};
|
|
73
|
+
/** A world unit's worth of pixels at clip w `w`: what a size in view pixels is in world units. */
|
|
74
|
+
export declare function pixelSize(u: BodyUniforms, w: N): N;
|
|
75
|
+
/** How a body is blended and depth-tested in each pass. */
|
|
76
|
+
export declare function bodyMaterial(pass: BodyPass): import("three/webgpu").MeshBasicNodeMaterial;
|
|
77
|
+
/**
|
|
78
|
+
* A body's fragment, from `bodyVaryings`: its index into the pick window; its silhouette where
|
|
79
|
+
* the scene's surface hides it, for the halo; its colour for the bloom; or painted in its
|
|
80
|
+
* material, ghosted where the surface is in front - and nothing where an occluder hides it.
|
|
81
|
+
*/
|
|
82
|
+
export declare function bodyFragment(pass: BodyPass, options: BodyOptions, u: BodyUniforms, lighting: Lighting): import("three/tsl").ShaderNodeObject<import("three/src/nodes/TSL.js").ShaderCallNodeInternal>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{CustomBlending as e,DoubleSide as t,FrontSide as o,LessDepth as r,MaxEquation as n,NoBlending as i,OneFactor as a,Vector3 as s}from"three/webgpu";import{Discard as l,float as d,Fn as c,If as h,ivec2 as p,max as u,mix as v,screenCoordinate as g,textureLoad as x,uniform as f,varyingProperty as b,vec3 as m,vec4 as w}from"three/tsl";import{additive as y,nodeMaterial as T}from"../Tsl.js";import{OUTLINE_RGB as D}from"./GpuLines.js";export const DEPTH_SLACK=.05;export const HALO_GROW=.25;export function bodyUniforms(){return{focal:f(1e3),pixelRatio:f(1),orthographic:f(0),pxPerWorld:f(1),ghostAlpha:f(.85),ghostLighten:f(.15),outlineRgb:f(new s(...D)),outlineWidth:f(2),litMix:f(.3)}}export function bodyVaryings(){return{vColor:b("vec4","vColor"),vNormal:b("vec3","vNormal"),vDistance:b("float","vDistance"),vPosition:b("vec3","vPosition"),vMaterial:b("vec2","vMaterial"),vIndex:b("float","vIndex")}}export function pixelSize(e,t){return e.orthographic.greaterThan(.5).select(d(1).div(e.pxPerWorld),t.div(e.focal))}export function bodyMaterial(s){const l="pick"===s,d=T();return d.transparent="bloom"!==s&&!l,l&&(d.blending=i),d.side=o,d.depthTest="window"!==s,d.depthWrite="window"!==s,d.depthFunc=r,"window"===s&&(d.side=t,d.blending=e,d.blendEquation=n,d.blendSrc=a,d.blendDst=a),"density"===s&&y(d),d}export function bodyFragment(e,t,o,r){const n="pick"===e,i=t.sceneDepth,a=t.occluder,s=t.pick,{vColor:f,vNormal:b,vDistance:y,vPosition:T,vMaterial:D,vIndex:P}=bodyVaryings();return c(()=>{if("density"===e)return w(f.w,0,0,1);if(n&&s)return a&&h(a.hides(y,g.xy.add(s.pass.origin)).toVar(),()=>{l()}),w(d(s.source),P,y,1);const t=a?a.hides(y).toVar():d(0).greaterThan(1);let c=d(0).greaterThan(1);if(i){const e=x(i.texture,p(g.xy)).x,t=i.near;c=i.enabled.greaterThan(.5).and(y.greaterThan(t.div(u(d(1).sub(e),1e-7)).add(.05)))}if("window"===e)return h(c.not().or(f.w.lessThan(.001)).or(t),()=>{l()}),w(f.w.lessThan(.5).select(d(.5),d(1)),0,0,1);if(h(t,()=>{l()}),"bloom"===e)return w(f.xyz,1);if("casing"===e)return w(o.outlineRgb,c.select(o.ghostAlpha,d(1)));const A=r.shade(D.x,b,T,f.xyz),L=c.select(f.w.mul(o.ghostAlpha),f.w);return w(c.select(v(A,m(1,1,1),o.ghostLighten),A),L)})()}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Mesh, Vector3 } from 'three/webgpu';
|
|
2
|
+
import { GeometryFrame, GeometryPasses, GeometryPrimitive, PickOptions } from '../../engine/GeometryFrame';
|
|
3
|
+
import { FeatureLook } from '../FeatureLook';
|
|
4
|
+
import { Lighting } from '../Shading';
|
|
5
|
+
/** One area: its rings, the outer first and holes after, relative to the engine's origin. */
|
|
6
|
+
export interface GpuArea {
|
|
7
|
+
rings: readonly (readonly (readonly number[])[])[];
|
|
8
|
+
index: number;
|
|
9
|
+
}
|
|
10
|
+
export interface GpuAreasOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Stand the areas up: walls and a roof, as high as each feature's look `width` and lifted by
|
|
13
|
+
* its `realWidth` - buildings, volumes, floors. Heights live in the look, so they change, and
|
|
14
|
+
* grow in, without a rebuild.
|
|
15
|
+
*/
|
|
16
|
+
extrude?: boolean;
|
|
17
|
+
/** The ground's up at the origin: what the areas stand up along. */
|
|
18
|
+
up?: readonly number[];
|
|
19
|
+
look?: FeatureLook;
|
|
20
|
+
lighting?: Lighting;
|
|
21
|
+
pick?: PickOptions;
|
|
22
|
+
/** Feature count, when no look is given. */
|
|
23
|
+
count?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Where these flat areas stand among others, higher over lower: where two overlap at the same
|
|
26
|
+
* height, a pick finds the higher one's, not whichever won the depth there.
|
|
27
|
+
*/
|
|
28
|
+
rank?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Areas, one draw: flat fills lying where their points are - on a 2D map, on the ground, on a
|
|
32
|
+
* slope or a wall (each polygon cut into triangles in its own plane) - or extruded into lit
|
|
33
|
+
* volumes. Per feature from the look: colour and alpha, hatching (`LookFlag.Hatch`), height and
|
|
34
|
+
* base for an extrusion, state: selected ones lit and bloomed, faded ones see-through - volumes
|
|
35
|
+
* in a pass of their own, blended over everything else. Outlines are a `GpuLines` sharing
|
|
36
|
+
* the same look.
|
|
37
|
+
*/
|
|
38
|
+
export declare class GpuAreas implements GeometryPrimitive {
|
|
39
|
+
private readonly options;
|
|
40
|
+
readonly mesh: Mesh;
|
|
41
|
+
/** The see-through volumes (alpha under 1), blended after the rest; with `extrude` only. */
|
|
42
|
+
readonly ghostMesh: Mesh | null;
|
|
43
|
+
readonly bloomMesh: Mesh;
|
|
44
|
+
readonly pickMesh: Mesh | null;
|
|
45
|
+
readonly look: FeatureLook;
|
|
46
|
+
readonly lighting: Lighting;
|
|
47
|
+
triangles: number;
|
|
48
|
+
readonly pixelRatio: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
49
|
+
/** Hatching: the stripes' spacing and width, in view pixels. */
|
|
50
|
+
readonly hatch: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
51
|
+
/** A volume's walls darker towards their foot over this height, as if the ground shaded them. */
|
|
52
|
+
readonly footShade: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
53
|
+
/** How much a selected area is lit towards white. */
|
|
54
|
+
readonly litMix: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
55
|
+
/**
|
|
56
|
+
* Windows on a volume's walls, a grid of them a storey high: lit, this much of them, in
|
|
57
|
+
* `windowRgb` - a city at night - or 0 for dark glass only.
|
|
58
|
+
*/
|
|
59
|
+
readonly windows: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
60
|
+
readonly windowsLit: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
61
|
+
readonly windowRgb: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
62
|
+
/** The windows' grid: width and height of a bay, in world units. */
|
|
63
|
+
readonly windowGrid: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
64
|
+
private readonly up;
|
|
65
|
+
constructor(areas: GpuArea[], options?: GpuAreasOptions);
|
|
66
|
+
passes(): GeometryPasses;
|
|
67
|
+
setFrame(frame: GeometryFrame): void;
|
|
68
|
+
private meshes;
|
|
69
|
+
adopt(other: GeometryPrimitive): boolean;
|
|
70
|
+
dispose(): void;
|
|
71
|
+
private material;
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{BufferGeometry as s,DoubleSide as t,Float32BufferAttribute as e,LessEqualDepth as i,Mesh as o,NoBlending as h,Uint32BufferAttribute as n,Vector3 as a}from"three/webgpu";import{attribute as l,cameraProjectionMatrix as r,cross as u,Discard as d,dot as c,float as m,floor as p,Fn as g,fract as w,fwidth as x,If as f,int as b,max as v,min as y,mix as T,normalize as M,screenCoordinate as k,sin as z,smoothstep as A,uniform as R,varyingProperty as G,vec2 as N,vec3 as S,vec4 as j}from"three/tsl";import{openLength as F,signedArea as L,triangulate as E}from"../../math/Triangulate.js";import{FeatureLook as O,hasFlag as W,LookFlag as H}from"../FeatureLook.js";import{Lighting as I}from"../Shading.js";import{adoptGeometry as U,disposeMaterial as q,GONE as C,nodeMaterial as D,unculled as P}from"../Tsl.js";export class GpuAreas{constructor(t,i={}){this.options=i,this.ghostMesh=null,this.pixelRatio=R(1),this.hatch=R(new a(8,2.5,0)),this.footShade=R(10),this.litMix=R(.35),this.windows=R(1),this.windowsLit=R(.35),this.windowRgb=R(new a(1,.82,.55)),this.windowGrid=R(new a(3.4,3.2,0)),this.up=R(new a(0,0,1)),this.look=i.look??new O(i.count??t.reduce((s,t)=>Math.max(s,t.index+1),0)),this.lighting=i.lighting??new I,i.up&&(this.up.value.set(i.up[0],i.up[1],i.up[2]).normalize(),i.lighting||this.lighting.setUp(i.up));const h=function(t,i,o){const h=[],a=[],l=[],r=[];for(const s of t){const{positions:t,triangles:e,ringStarts:n}=E(s.rings);if(0===e.length)continue;const u=h.length/3;for(let e=0;e<t.length;e+=3)h.push(t[e],t[e+1],t[e+2]),a.push(s.index,i?1:0,0),l.push(o.x,o.y,o.z);for(const s of e)r.push(u+s);i&&s.rings.forEach((t,e)=>{if(F(t)<3||e>=n.length)return;const i=F(t),o=L(t)>0,u=0===e?!o:o;for(let e=0;e<i;e++){const o=t[e],n=t[(e+1)%i],d=n[0]-o[0],c=n[1]-o[1],m=Math.hypot(d,c)||1,p=(u?-c:c)/m,g=(u?d:-d)/m,w=h.length/3;for(const[t,e]of[[o,0],[n,0],[o,1],[n,1]])h.push(t[0],t[1],t[2]??0),a.push(s.index,e,1),l.push(p,g,0);r.push(w,w+1,w+3,w,w+3,w+2)}})}const u=new s;return u.setAttribute("position",new e(h,3)),u.setAttribute("aArea",new e(a,3)),u.setAttribute("aNormal",new e(l,3)),u.setIndex(new n(r,1)),u}(t,!!i.extrude,this.up.value);this.triangles=(h.index?.count??0)/3;const l=i.extrude?0:-10;this.mesh=P(new o(h,this.material("solid")),l),i.extrude&&(this.ghostMesh=P(new o(h,this.material("ghost")),20)),this.bloomMesh=P(new o(h,this.material("bloom")),l),this.bloomMesh.visible=!1,this.pickMesh=i.pick?P(new o(h,this.material("pick")),l):null}passes(){return{scene:[this.mesh,this.ghostMesh],bloom:[this.bloomMesh],pick:[this.pickMesh]}}setFrame(s){this.pixelRatio.value=s.pixelRatio,s.eye&&this.lighting.eye.value.copy(s.eye)}meshes(){return[this.mesh,this.ghostMesh,this.bloomMesh,this.pickMesh]}adopt(s){return!!(s instanceof GpuAreas&&U(this.meshes(),s.meshes()))&&(this.triangles=s.triangles,!0)}dispose(){this.mesh.geometry.dispose(),this.meshes().forEach(q),this.options.look||this.look.dispose()}material(s){const e="pick"===s,o=!!this.options.extrude,n=this.options.pick,a=D();a.side=t,a.transparent=!(e||o&&"ghost"!==s),a.depthTest=!0,a.depthWrite=o&&"ghost"!==s||e,a.depthFunc=i,e&&(a.blending=h),a.polygonOffset=!o,a.polygonOffsetFactor=-1,a.polygonOffsetUnits=-4-(e?2*Math.max(0,this.options.rank??0):0);const R=this.look,F=G("vec4","vColor"),L=G("vec3","vNormal"),E=G("vec3","vPosition"),O=G("vec4","vHeight"),I=G("float","vIndex"),U=G("float","vDistance"),q=G("float","vSelected"),P=G("vec2","vWall");return a.vertexNode=g(()=>{const t=l("position","vec3"),i=l("aArea","vec3"),h=l("aNormal","vec3"),a=R.read(b(i.x)),u=o?v(a.width,0):m(0),d=o?a.realWidth.add(i.y.mul(u)):m(0),c=t.add(this.up.mul(d)),p=r.mul(j(c,1)),g=a.selected.select(T(a.rgb,S(1,1,1),this.litMix),a.rgb);F.assign(j(g,a.alpha)),L.assign(h),E.assign(c),O.assign(j(i.y.mul(u),u,a.material,a.flags)),I.assign(i.x),U.assign(p.w),q.assign(a.selected.select(m(1),m(0))),P.assign(N(i.z,i.x));return a.alpha.lessThan(.001).or("bloom"===s?a.selected.not():m(0).greaterThan(1)).or(o?u.lessThan(1e-4).and(i.z.greaterThan(.5)):m(0).greaterThan(1)).select(C(),e&&n?n.pass.window.mul(p):p)})(),a.fragmentNode=g(()=>{if(e&&n)return j(m(n.source),I,U,1);const t=W(O.w,H.Hatch),i=this.hatch.x.mul(this.pixelRatio),h=w(k.x.add(k.y).div(i)).mul(i),a=this.hatch.y.mul(this.pixelRatio).mul(.5),l=m(1).sub(A(a.sub(.7),a.add(.7),y(h,i.sub(h)))),r=t.select(l,m(1));let g=F.xyz,b=F.w.mul(r);if(o){const t=M(L),e=this.lighting.shade(O.z,t,E,F.xyz),i=T(m(.55),m(1),A(0,y(this.footShade,v(O.y,.001)),O.x)),o=P.x.greaterThan(.5),h=o.select(A(O.y.sub(.45),O.y,O.x).mul(.22),m(0));g=e.mul(i).add(S(h,h,h));const n=o.select(M(u(this.up,t)),S(1,0,0)),a=c(E,n).div(this.windowGrid.x),l=O.x.sub(1.1).div(this.windowGrid.y),r=w(a),k=w(l),R=v(x(a),x(l)).mul(.7).add(1e-4),G=A(m(.2).sub(R),m(.2).add(R),r).mul(m(1).sub(A(m(.8).sub(R),m(.8).add(R),r))).mul(A(m(.28).sub(R),m(.28).add(R),k)).mul(m(1).sub(A(m(.8).sub(R),m(.8).add(R),k))),N=O.x.greaterThan(1.3).and(O.x.lessThan(O.y.sub(.8))).and(O.y.greaterThan(4)),W=o.and(N).and(this.windows.greaterThan(.5)).select(G,m(0)),H=S(p(a),p(l),p(P.y.add(.5))),I=w(z(c(H,S(12.9898,78.233,37.719))).mul(43758.5453)),U=A(m(1).sub(this.windowsLit),m(1).sub(this.windowsLit).add(.02),I),q=T(m(.55),m(1),w(I.mul(7.31))),C=g.mul(.55),D=this.windowRgb.mul(q);if(g=W.greaterThan(.001).select(T(g,T(C,D,U),W),g),"ghost"===s){const s=M(this.lighting.eye.sub(E)),o=c(t,s);f(b.greaterThanEqual(.99).or(b.lessThan(.004)).or(o.lessThan(0)),()=>{d()});const h=m(1).sub(o).mul(.5);return j(e.mul(i).add(S(h,h,h).mul(.25)),b.mul(m(.6).add(h)))}"solid"===s&&(f(b.lessThan(.99),()=>{d()}),b=m(1))}else f(b.lessThan(.004),()=>{d()});return"bloom"===s?j(F.xyz,1):j(g,b)})(),a}}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { CanvasTexture, Mesh, Texture, Vector3 } from 'three/webgpu';
|
|
2
|
+
import { GeometryFrame, GeometryPasses, GeometryPrimitive, PickOptions } from '../../engine/GeometryFrame';
|
|
3
|
+
import { FeatureLook } from '../FeatureLook';
|
|
4
|
+
/**
|
|
5
|
+
* An icon to draw: where, relative to the engine's origin, and its cell in the atlas - or a
|
|
6
|
+
* negative `IconShape`, drawn in the shader.
|
|
7
|
+
*/
|
|
8
|
+
export type GpuIcon = {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
z: number;
|
|
12
|
+
cell: number;
|
|
13
|
+
/** Its feature's index into the look, when not its own place in the list: a multi-point's points share one. */
|
|
14
|
+
index?: number;
|
|
15
|
+
};
|
|
16
|
+
/** Shapes drawn in the shader rather than sampled from the atlas: an icon's negative cell. */
|
|
17
|
+
export declare const IconShape: {
|
|
18
|
+
/** The manhole cover: a rim of the colour round a darker disc with a thin ring on it. */
|
|
19
|
+
readonly Cover: -1;
|
|
20
|
+
readonly Circle: -2;
|
|
21
|
+
readonly Ring: -3;
|
|
22
|
+
readonly Square: -4;
|
|
23
|
+
readonly Diamond: -5;
|
|
24
|
+
readonly Triangle: -6;
|
|
25
|
+
readonly Hexagon: -7;
|
|
26
|
+
/** A map pin, its tip on the point (`anchor` [0, -1]). */
|
|
27
|
+
readonly Pin: -8;
|
|
28
|
+
readonly Cross: -9;
|
|
29
|
+
readonly Star: -10;
|
|
30
|
+
};
|
|
31
|
+
export type IconShapeName = Lowercase<keyof typeof IconShape>;
|
|
32
|
+
export declare function iconShapeOf(name: IconShapeName | string): number;
|
|
33
|
+
/** The cell that stands for the manhole cover, drawn rather than sampled. */
|
|
34
|
+
export declare const COVER_CELL: -1;
|
|
35
|
+
/** The manhole cover as the Ing+ map draws it: rim, fill, ring and its width and strength. */
|
|
36
|
+
export declare const MANHOLE_COVER: {
|
|
37
|
+
rim: number;
|
|
38
|
+
fill: number;
|
|
39
|
+
ring: number;
|
|
40
|
+
ringWidth: number;
|
|
41
|
+
ringAlpha: number;
|
|
42
|
+
};
|
|
43
|
+
export interface GpuIconsOptions {
|
|
44
|
+
/** `size` in world units (the default, a metre on a map) or in view pixels. */
|
|
45
|
+
sizeUnit?: 'world' | 'pixels';
|
|
46
|
+
/** Facing the screen (the default), or lying flat on the ground under `up`, at their real size. */
|
|
47
|
+
orientation?: 'screen' | 'ground';
|
|
48
|
+
/** The ground's up at the origin, for `ground`. */
|
|
49
|
+
up?: readonly number[];
|
|
50
|
+
/** Tested against the depth of what else is drawn, at their own: icons in 3D. Off on a 2D map, where icons lie over everything. */
|
|
51
|
+
depth?: boolean;
|
|
52
|
+
/** Where the point is on the icon, in half sizes from its middle: [0, -1] its foot, for pins. */
|
|
53
|
+
anchor?: [number, number];
|
|
54
|
+
/** Never drawn smaller than this, in view pixels across. */
|
|
55
|
+
minPixels?: number;
|
|
56
|
+
/** A shape's dark border, in view pixels; 0 for none. */
|
|
57
|
+
border?: number;
|
|
58
|
+
/** The look to read; one of the icons' own when not given. */
|
|
59
|
+
look?: FeatureLook;
|
|
60
|
+
pick?: PickOptions;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Icons and markers, every one an instanced quad, drawn after the lines so a line never covers
|
|
64
|
+
* one: facing the screen at a size in world units (a metre on the map, the Ing+ map's manholes)
|
|
65
|
+
* or in pixels, or lying on the ground at their real size. Their picture from an atlas
|
|
66
|
+
* (`iconAtlas`), or a shape drawn in the shader - the manhole cover, circles, rings, squares,
|
|
67
|
+
* diamonds, triangles, hexagons, pins, crosses, stars - crisp however close. Their look is the
|
|
68
|
+
* shared `FeatureLook`: colour (tinting an atlas icon), size, state; selected ones lit, glowing or
|
|
69
|
+
* outlined. Picked in the pick pass; added into the heatmap as the density mark while it draws
|
|
70
|
+
* density.
|
|
71
|
+
*/
|
|
72
|
+
export declare class GpuIcons implements GeometryPrimitive {
|
|
73
|
+
private readonly size;
|
|
74
|
+
readonly mesh: Mesh;
|
|
75
|
+
readonly pickMesh: Mesh | null;
|
|
76
|
+
readonly bloomMesh: Mesh;
|
|
77
|
+
readonly densityMesh: Mesh;
|
|
78
|
+
readonly look: FeatureLook;
|
|
79
|
+
count: number;
|
|
80
|
+
/** Frame pixels per world unit, and per view pixel, this frame (`setFrame`). */
|
|
81
|
+
private readonly pxPerWorld;
|
|
82
|
+
private readonly pixelRatio;
|
|
83
|
+
/** 1 in perspective, where a size in world units is as many pixels as its distance makes it. */
|
|
84
|
+
private readonly perspective;
|
|
85
|
+
private readonly focal;
|
|
86
|
+
/** 1 for the outline look: a selected one's rim in `rimRgb`, not lit to white. */
|
|
87
|
+
readonly outlineMode: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
88
|
+
/** The rim's colour: near white on a dark map, ink on a light one. */
|
|
89
|
+
readonly rimRgb: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
|
|
90
|
+
/** How much bigger a lit icon is drawn. */
|
|
91
|
+
readonly litScale: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
92
|
+
private readonly up;
|
|
93
|
+
constructor(icons: GpuIcon[], atlas: CanvasTexture | Texture | null, size: number, pickOrOptions?: PickOptions | GpuIconsOptions);
|
|
94
|
+
private readonly options;
|
|
95
|
+
/** How bright the icons that are not lit are while something is: see `FeatureLook.othersShade`. */
|
|
96
|
+
get othersShade(): import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
97
|
+
get othersToward(): import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
|
|
98
|
+
passes(): GeometryPasses;
|
|
99
|
+
setFrame(frame: GeometryFrame): void;
|
|
100
|
+
/**
|
|
101
|
+
* How strongly icon `index` shows, 0 for not at all, whether it is selected, the colour it is
|
|
102
|
+
* tinted with (straight RGB, 0 to 1), and whether it is in the set - shaded while something
|
|
103
|
+
* else is lit (`othersShade`). The Ing+ map's way to style an icon.
|
|
104
|
+
*/
|
|
105
|
+
setState(index: number, alpha: number, selected: boolean, tint?: number[], inSet?: boolean): void;
|
|
106
|
+
/** Uploads what setState wrote. */
|
|
107
|
+
commit(): void;
|
|
108
|
+
private meshes;
|
|
109
|
+
adopt(other: GeometryPrimitive): boolean;
|
|
110
|
+
dispose(): void;
|
|
111
|
+
private material;
|
|
112
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DoubleSide as e,InstancedBufferAttribute as t,InstancedBufferGeometry as s,LessDepth as i,LessEqualDepth as o,Mesh as n,NoBlending as l,Vector3 as a}from"three/webgpu";import{abs as r,attribute as h,cameraProjectionMatrix as u,clamp as c,cross as m,dot as d,dFdx as p,dFdy as g,Discard as b,float as x,Fn as v,If as y,int as f,length as w,max as S,min as T,mix as k,normalize as I,positionGeometry as R,sign as C,smoothstep as M,texture as z,uniform as A,varyingProperty as E,vec2 as W,vec3 as L,vec4 as O,viewport as P}from"three/tsl";import{FeatureLook as F,FeatureState as D}from"../FeatureLook.js";import{additive as H,adoptGeometry as V,centredQuad as j,disposeMaterial as N,GONE as q,nodeMaterial as _,unculled as G}from"../Tsl.js";import{ICON_CELL as U}from"./IconAtlas.js";export const IconShape={Cover:-1,Circle:-2,Ring:-3,Square:-4,Diamond:-5,Triangle:-6,Hexagon:-7,Pin:-8,Cross:-9,Star:-10};export function iconShapeOf(e){const t=Object.keys(IconShape).find(t=>t.toLowerCase()===e.toLowerCase());return t?IconShape[t]:IconShape.Circle}export const COVER_CELL=IconShape.Cover;export const MANHOLE_COVER={rim:.8,fill:.5,ring:.55,ringWidth:.06,ringAlpha:.7};export class GpuIcons{constructor(e,i,o,l){this.size=o,this.pxPerWorld=A(1),this.pixelRatio=A(1),this.perspective=A(0),this.focal=A(1e3),this.outlineMode=A(0),this.rimRgb=A(new a(.92,.91,.88)),this.litScale=A(1.15),this.up=A(new a(0,0,1));const r=l&&"pass"in l?{pick:l}:l??{};if(this.options=r,r.up&&this.up.value.set(r.up[0],r.up[1],r.up[2]).normalize(),this.count=e.length,this.look=r.look??new F(e.length),!r.look){for(let t=0;t<e.length;t++)this.look.set(t,{color:J,state:D.Default});this.look.commit()}const h=new Float32Array(3*e.length),u=new Float32Array(2*e.length);e.forEach((e,t)=>{h[3*t]=e.x,h[3*t+1]=e.y,h[3*t+2]=e.z,u[2*t]=e.index??t,u[2*t+1]=e.cell});const c=j(new s);c.setAttribute("aCentre",new t(h,3)),c.setAttribute("aIcon",new t(u,2)),c.instanceCount=e.length,this.mesh=G(new n(c,this.material("solid",i)),3),this.pickMesh=r.pick?G(new n(c,this.material("pick",i)),3):null,this.bloomMesh=G(new n(c,this.material("bloom",i))),this.densityMesh=G(new n(c,this.material("density",i))),this.densityMesh.visible=!1}get othersShade(){return this.look.othersShade}get othersToward(){return this.look.othersToward}passes(){return{scene:[this.mesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){this.pxPerWorld.value=e.pxPerWorld,this.pixelRatio.value=e.pixelRatio,this.perspective.value=!1===e.orthographic?1:0,e.focal&&(this.focal.value=e.focal)}setState(e,t,s,i=B,o=!1){this.look.set(e,{color:[i[0],i[1],i[2],t],state:t<=0?D.Hidden:s?D.Selected:o?D.Default:D.Faded,weight:t,fadedWeight:t})}commit(){this.look.commit()}meshes(){return[this.mesh,this.bloomMesh,this.pickMesh,this.densityMesh]}adopt(e){return!!(e instanceof GpuIcons&&V(this.meshes(),e.meshes()))&&(this.count=e.count,!0)}dispose(){this.mesh.geometry.dispose(),this.meshes().forEach(N),this.options.look||this.look.dispose()}material(t,s){const n=this.options,a=n.pick,A="pick"===t,F="density"===t,D="bloom"===t,V="ground"===n.orientation,j=!!n.depth||V,N="pixels"===n.sizeUnit,G=n.anchor??[0,0],B=n.minPixels??0,J=n.border??1,K=_();K.transparent=!A,K.side=e,K.depthTest=A||j&&!F,K.depthWrite=A,K.depthFunc=A&&!j?i:o,A&&(K.blending=l),F&&H(K);const Q=this.look,X=E("vec2","vCorner"),Y=E("vec2","vScale"),Z=E("vec3","vIcon"),$=E("vec3","vTint"),ee=E("float","vIndex"),te=E("float","vDistance");return K.vertexNode=v(()=>{const e=h("aCentre","vec3"),t=h("aIcon","vec2"),s=f(t.x),i=Q.read(s),o=R.xy,n=u.mul(O(e,1)),l=A&&a?a.pass.frameSize:P.zw,r=i.width.greaterThan(0),c=r.and(i.meters).select(i.width,x(N?0:this.size)),d=r.and(i.meters.not()).select(i.width,x(N?this.size:0)),p=i.selected.and(x(D||F||A?0:1).greaterThan(.5)).select(this.litScale,x(1)),g=S(n.w,1e-6),b=this.perspective.greaterThan(.5).select(this.focal.div(g),this.pxPerWorld),v=S(S(c.mul(b),d.mul(this.pixelRatio)).mul(.5),this.pixelRatio.mul(B/2)).mul(p),T=x(A&&a?4:F?1:0),k=S(v,T.mul(this.pixelRatio)).add(1),C=k.div(S(v,1e-6));let M;X.assign(o.mul(C)),Y.assign(W(C,x(1).div(S(v,1e-6)).mul(this.pixelRatio))),Z.assign(L(t.y,i.alpha,i.selected.select(x(1),x(0)))),$.assign(i.rgb),ee.assign(t.x);let z=null;if(V){const t=I(m(L(0,0,1),this.up)).toVar();y(w(m(L(0,0,1),this.up)).lessThan(1e-4),()=>{t.assign(L(1,0,0))});const s=m(this.up,t),i=c.add(d.mul(g).div(this.focal)).mul(.5).mul(p),n=g.div(this.focal),l=(A?S(i,n.mul(this.pixelRatio).mul(4)):i).add(n),a=W(G[0],G[1]).mul(i).negate(),r=o.mul(l).add(a),h=e.add(t.mul(r.x)).add(s.mul(r.y));X.assign(o.mul(l.div(S(i,1e-6)))),Y.assign(W(l.div(S(i,1e-6)),n.mul(this.pixelRatio).div(S(i,1e-6))));const b=u.mul(O(h,1));te.assign(b.w),A||(z=i.mul(2).lessThan(n)),M=b}else{const e=o.mul(k).add(W(G[0],G[1]).mul(v).negate()).div(l).mul(2).mul(n.w);te.assign(n.w);const t=j?n.z:A?n.w.mul(.05):x(0);M=O(n.xy.add(e),t,n.w)}const E=D?i.alpha.lessThan(.001).or(i.selected.not()):i.alpha.lessThan(.001);return(z?E.or(z):E).select(q(),A&&a?a.pass.window.mul(M):M)})(),K.fragmentNode=v(()=>{const e=X,t=Z.x,i=w(e),o=S(w(W(p(i),g(i))).mul(.5),1e-4).toVar(),n=function(e,t){const s=w(t),i=s.sub(1),o=r(s.sub(.72)).sub(.28),n=S(r(t.x),r(t.y)).sub(.86),l=r(t.x).add(r(t.y)).sub(1).mul(.7071),a=S(r(t.x).mul(.866).add(t.y.mul(.5)).sub(.5),t.y.negate().sub(.75)),h=S(r(t.x).mul(.866).add(r(t.y).mul(.5)),r(t.y)).sub(.9),u=w(t.sub(W(0,.28))).sub(.68),m=S(r(t.x).mul(.94).add(t.y.mul(.34)).sub(.2),t.y.negate().sub(1)),p=S(T(u,m),x(.24).sub(w(t.sub(W(0,.3))))),g=T(S(r(t.x).sub(.28),r(t.y).sub(.95)),S(r(t.y).sub(.28),r(t.x).sub(.95))),b=(t,s,i)=>r(e.sub(t)).lessThan(.5).select(s,i);let v=i;return v=b(IconShape.Ring,o,v),v=b(IconShape.Square,n,v),v=b(IconShape.Diamond,l,v),v=b(IconShape.Triangle,a,v),v=b(IconShape.Hexagon,h,v),v=b(IconShape.Pin,p,v),v=b(IconShape.Cross,g,v),v=b(IconShape.Star,function(e){const t=W(.809016994375,-.587785252292),s=W(-.809016994375,-.587785252292);let i=W(r(e.x),e.y);i=i.sub(t.mul(S(d(t,i),0).mul(2))),i=i.sub(s.mul(S(d(s,i),0).mul(2))),i=W(r(i.x),i.y.sub(1));const o=W(.26450336353139997,-.63594235253125),n=c(d(i,o).div(d(o,o)),0,1);return w(i.sub(o.mul(n))).mul(C(i.y.mul(o.x).sub(i.x.mul(o.y))))}(t),v),v}(t,e),l=x(1).sub(M(o.negate(),o,n));if(A&&a){const s=Y.x,i=t.greaterThanEqual(0).select(S(r(e.x),r(e.y)).greaterThan(s),n.greaterThan(s.sub(1)));return y(i,()=>{b()}),O(x(a.source),ee,j?te:x(.05),1)}if(F){const t=c(x(1).sub(w(e.div(Y.x))),0,1),s=Z.y.mul(t);return y(s.lessThan(.001),()=>{b()}),O(s,0,0,1)}const h=Z.z.greaterThan(.5),u=e=>x(1).sub(M(x(e).sub(o),x(e).add(o),i)),{rim:m,fill:v,ring:f,ringWidth:I,ringAlpha:R}=MANHOLE_COVER,E=u(f+I/2).sub(u(f-I/2)),P=k(x(v),x(1),E.mul(R)),H=$.mul(k(x(1),P,u(m))),V=Y.y.mul(J),N=x(1).sub(M(o.negate(),o,n.add(V))),q=k($.mul(.35),$,J>0?N:x(1)),_=t.lessThan(-.5).and(t.greaterThan(-1.5));let G=_.select(H,q),B=l;if(s){const i=s.image.width/U,n=c(e.mul(.5).add(.5),.5/U,1-.5/U),l=z(s,W(S(t,0).add(n.x).div(i),x(1).sub(n.y))).level(x(0)),a=x(1).sub(M(x(1).sub(o),x(1).add(o),S(r(e.x),r(e.y)))),h=t.greaterThan(-.5);G=h.select(l.xyz.mul($),G),B=h.select(l.w.mul(a),B)}const K=B.mul(Z.y);if(y(K.lessThan(.004),()=>{b()}),D)return O(G,B);const Q=M(V.negate().mul(2.5),V.negate().mul(.5),n),se=_.select(k(this.rimRgb,G,u(m)),k(G,this.rimRgb,Q)),ie=this.outlineMode.greaterThan(.5).select(se,k(G,L(1,1,1),.3));return O(h.select(ie,G),K)})(),K}}const B=[1,1,1],J=[1,1,1,1];
|