@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.
Files changed (118) hide show
  1. package/GeometryDemo.d.ts +1 -0
  2. package/GeometryDemo.js +1 -0
  3. package/README.md +301 -2
  4. package/common/Colors.d.ts +47 -0
  5. package/common/Colors.js +1 -0
  6. package/common/Disposables.d.ts +7 -0
  7. package/common/Disposables.js +1 -0
  8. package/data/Geometry.d.ts +62 -0
  9. package/data/Geometry.js +1 -0
  10. package/demo/DemoControls.d.ts +68 -0
  11. package/demo/DemoControls.js +1 -0
  12. package/demo/Town.d.ts +115 -0
  13. package/demo/Town.js +1 -0
  14. package/edit/CreateController.d.ts +101 -0
  15. package/edit/CreateController.js +1 -0
  16. package/edit/EditController.d.ts +121 -0
  17. package/edit/EditController.js +1 -0
  18. package/edit/EditHistory.d.ts +46 -0
  19. package/edit/EditHistory.js +1 -0
  20. package/edit/EditShape.d.ts +45 -0
  21. package/edit/EditShape.js +1 -0
  22. package/edit/GeometryController.d.ts +83 -0
  23. package/edit/GeometryController.js +1 -0
  24. package/edit/MeasureController.d.ts +102 -0
  25. package/edit/MeasureController.js +1 -0
  26. package/edit/Sketch.d.ts +73 -0
  27. package/edit/Sketch.js +1 -0
  28. package/edit/Snapper.d.ts +67 -0
  29. package/edit/Snapper.js +1 -0
  30. package/engine/GeometryEngine.d.ts +267 -0
  31. package/engine/GeometryEngine.js +1 -0
  32. package/engine/GeometryFrame.d.ts +91 -0
  33. package/engine/GeometryFrame.js +1 -0
  34. package/engine/GeometryOptions.d.ts +79 -0
  35. package/engine/GeometryOptions.js +1 -0
  36. package/engine/GeometryView.d.ts +192 -0
  37. package/engine/GeometryView.js +1 -0
  38. package/engine/Labels.d.ts +42 -0
  39. package/engine/Labels.js +1 -0
  40. package/engine/MapCamera.d.ts +78 -0
  41. package/engine/MapCamera.js +1 -0
  42. package/event/TypedEventEmitter.d.ts +13 -0
  43. package/event/TypedEventEmitter.js +1 -0
  44. package/index.d.ts +53 -0
  45. package/index.js +1 -0
  46. package/layers/AreaLayer.d.ts +36 -0
  47. package/layers/AreaLayer.js +1 -0
  48. package/layers/GeometryLayer.d.ts +312 -0
  49. package/layers/GeometryLayer.js +1 -0
  50. package/layers/LineLayer.d.ts +48 -0
  51. package/layers/LineLayer.js +1 -0
  52. package/layers/PointLayer.d.ts +42 -0
  53. package/layers/PointLayer.js +1 -0
  54. package/layers/SphereLayer.d.ts +25 -0
  55. package/layers/SphereLayer.js +1 -0
  56. package/layers/TubeLayer.d.ts +52 -0
  57. package/layers/TubeLayer.js +1 -0
  58. package/math/Boolean.d.ts +21 -0
  59. package/math/Boolean.js +1 -0
  60. package/math/FeatureIndex.d.ts +70 -0
  61. package/math/FeatureIndex.js +1 -0
  62. package/math/Geodesy.d.ts +29 -0
  63. package/math/Geodesy.js +1 -0
  64. package/math/Lines.d.ts +115 -0
  65. package/math/Lines.js +1 -0
  66. package/math/Measure.d.ts +71 -0
  67. package/math/Measure.js +1 -0
  68. package/math/Polygons.d.ts +59 -0
  69. package/math/Polygons.js +1 -0
  70. package/math/Projection.d.ts +25 -0
  71. package/math/Projection.js +1 -0
  72. package/math/Relations.d.ts +27 -0
  73. package/math/Relations.js +1 -0
  74. package/math/SpatialIndex.d.ts +36 -0
  75. package/math/SpatialIndex.js +1 -0
  76. package/math/Transform.d.ts +36 -0
  77. package/math/Transform.js +1 -0
  78. package/math/Triangulate.d.ts +19 -0
  79. package/math/Triangulate.js +1 -0
  80. package/math/Vector.d.ts +24 -0
  81. package/math/Vector.js +1 -0
  82. package/package.json +76 -4
  83. package/react/ReactGeometry.d.ts +35 -0
  84. package/react/ReactGeometry.js +1 -0
  85. package/three/CanvasGeometryEngine.d.ts +79 -0
  86. package/three/CanvasGeometryEngine.js +1 -0
  87. package/three/DensityMap.d.ts +31 -0
  88. package/three/DensityMap.js +1 -0
  89. package/three/FeatureLook.d.ts +191 -0
  90. package/three/FeatureLook.js +1 -0
  91. package/three/Ground.d.ts +54 -0
  92. package/three/Ground.js +1 -0
  93. package/three/Halo.d.ts +26 -0
  94. package/three/Halo.js +1 -0
  95. package/three/HostedGeometryEngine.d.ts +57 -0
  96. package/three/HostedGeometryEngine.js +1 -0
  97. package/three/RiaGeometryEngine.d.ts +48 -0
  98. package/three/RiaGeometryEngine.js +1 -0
  99. package/three/Shading.d.ts +42 -0
  100. package/three/Shading.js +1 -0
  101. package/three/Sky.d.ts +27 -0
  102. package/three/Sky.js +1 -0
  103. package/three/Tsl.d.ts +47 -0
  104. package/three/Tsl.js +1 -0
  105. package/three/primitives/Body.d.ts +82 -0
  106. package/three/primitives/Body.js +1 -0
  107. package/three/primitives/GpuAreas.d.ts +72 -0
  108. package/three/primitives/GpuAreas.js +1 -0
  109. package/three/primitives/GpuIcons.d.ts +112 -0
  110. package/three/primitives/GpuIcons.js +1 -0
  111. package/three/primitives/GpuLines.d.ts +198 -0
  112. package/three/primitives/GpuLines.js +1 -0
  113. package/three/primitives/GpuSpheres.d.ts +55 -0
  114. package/three/primitives/GpuSpheres.js +1 -0
  115. package/three/primitives/GpuTubes.d.ts +125 -0
  116. package/three/primitives/GpuTubes.js +1 -0
  117. package/three/primitives/IconAtlas.d.ts +12 -0
  118. package/three/primitives/IconAtlas.js +1 -0
@@ -0,0 +1,24 @@
1
+ import type { Position } from '../data/Geometry';
2
+ /** A point or direction, always three numbers: a position without a height has z 0. */
3
+ export type Vec3 = [number, number, number];
4
+ /** How many of a position's numbers count: 2 measures in x and y only, 3 with the heights. */
5
+ export type Dims = 2 | 3;
6
+ export declare const zOf: (p: Position) => number;
7
+ export declare function vec3(p: Position): Vec3;
8
+ export declare function sub3(a: Position, b: Position): Vec3;
9
+ export declare function add3(a: Position, b: Position): Vec3;
10
+ export declare function scale3(a: Position, s: number): Vec3;
11
+ export declare function dot3(a: Position, b: Position): number;
12
+ export declare function cross3(a: Position, b: Position): Vec3;
13
+ export declare function length3(a: Position): number;
14
+ export declare function normalize3(a: Position): Vec3;
15
+ /** The point a fraction `t` of the way from `a` to `b`. */
16
+ export declare function lerp3(a: Position, b: Position, t: number): Vec3;
17
+ /** The distance between two positions: in 3D, or in x and y alone with `dims` 2. */
18
+ export declare function distanceOf(a: Position, b: Position, dims?: Dims): number;
19
+ /** The 2D cross product of `b - a` and `c - a`: positive where a, b, c turn left (counter-clockwise). */
20
+ export declare function orient2D(a: Position, b: Position, c: Position): number;
21
+ /** Whether two positions are the same, within `epsilon` in each of x, y and z. */
22
+ export declare function samePosition(a: Position, b: Position, epsilon?: number): boolean;
23
+ /** A position with the height of `like`: with a z where `like` has one, without where it has not. */
24
+ export declare function shaped(p: Vec3, like: Position): Position;
package/math/Vector.js ADDED
@@ -0,0 +1 @@
1
+ export const zOf=t=>t[2]??0;export function vec3(t){return[t[0],t[1],t[2]??0]}export function sub3(t,n){return[t[0]-n[0],t[1]-n[1],(t[2]??0)-(n[2]??0)]}export function add3(t,n){return[t[0]+n[0],t[1]+n[1],(t[2]??0)+(n[2]??0)]}export function scale3(t,n){return[t[0]*n,t[1]*n,(t[2]??0)*n]}export function dot3(t,n){return t[0]*n[0]+t[1]*n[1]+(t[2]??0)*(n[2]??0)}export function cross3(t,n){const r=t[2]??0,o=n[2]??0;return[t[1]*o-r*n[1],r*n[0]-t[0]*o,t[0]*n[1]-t[1]*n[0]]}export function length3(t){return Math.hypot(t[0],t[1],t[2]??0)}export function normalize3(t){const n=length3(t);return n>0?[t[0]/n,t[1]/n,(t[2]??0)/n]:[0,0,0]}export function lerp3(t,n,r){const o=t[2]??0;return[t[0]+(n[0]-t[0])*r,t[1]+(n[1]-t[1])*r,o+((n[2]??0)-o)*r]}export function distanceOf(t,n,r=3){const o=n[0]-t[0],e=n[1]-t[1];return 2===r?Math.hypot(o,e):Math.hypot(o,e,(n[2]??0)-(t[2]??0))}export function orient2D(t,n,r){return(n[0]-t[0])*(r[1]-t[1])-(n[1]-t[1])*(r[0]-t[0])}export function samePosition(t,n,r=0){return Math.abs(t[0]-n[0])<=r&&Math.abs(t[1]-n[1])<=r&&Math.abs((t[2]??0)-(n[2]??0))<=r}export function shaped(t,n){return n.length>2?t:[t[0],t[1]]}
package/package.json CHANGED
@@ -1,6 +1,78 @@
1
1
  {
2
2
  "name": "@protomaze/geometry",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Protomaze Geometry: GPU points, lines, tubes and areas in 2D and 3D, styled, filtered, highlighted and picked on the GPU",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/protomaze/geometry.git"
8
+ },
9
+ "homepage": "https://github.com/protomaze/geometry#readme",
10
+ "main": "index.js",
11
+ "types": "index.d.ts",
12
+ "files": [
13
+ "**/*.js",
14
+ "**/*.d.ts"
15
+ ],
16
+ "scripts": {
17
+ "dev": "webpack serve --mode development",
18
+ "check": "tsc -p tsconfig.json --noEmit",
19
+ "test": "rimraf .test-build && tsc -p tsconfig.test.json && node --experimental-require-module --no-warnings --test .test-build/test/",
20
+ "compile": "tsc -p tsconfig.build.json && node dev/fix_extensions.js && node dev/copy_files.js && node dev/minify_files.js",
21
+ "pub": "npm version patch --no-git-tag-version && rimraf build && npm run compile && cd build && npm --registry http://localhost:4873/ publish",
22
+ "deploy": "rimraf build && npm run compile && cd build && npm publish --access public",
23
+ "build": "webpack --mode production && npm run deploy",
24
+ "release": "npm version patch --no-git-tag-version && npm run build",
25
+ "release:minor": "npm version minor --no-git-tag-version && npm run build",
26
+ "release:major": "npm version major --no-git-tag-version && npm run build"
27
+ },
28
+ "keywords": [
29
+ "geometry",
30
+ "gis",
31
+ "webgpu",
32
+ "threejs",
33
+ "tsl",
34
+ "typescript"
35
+ ],
36
+ "author": "Tom Crauwels",
37
+ "dependencies": {
38
+ "earcut": "^3.0.2",
39
+ "polygon-clipping": "^0.15.7"
40
+ },
41
+ "peerDependencies": {
42
+ "react": "^18.2.0",
43
+ "react-dom": "^18.2.0",
44
+ "three": ">=0.178.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "react": {
48
+ "optional": true
49
+ },
50
+ "react-dom": {
51
+ "optional": true
52
+ }
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^20.17.0",
56
+ "@types/react": "18.0.34",
57
+ "@types/react-dom": "18.0.11",
58
+ "@types/three": "0.178.0",
59
+ "copy-webpack-plugin": "^14.0.0",
60
+ "css-loader": "^6.2.0",
61
+ "html-webpack-plugin": "^5.3.2",
62
+ "react": "18.2.0",
63
+ "react-dom": "18.2.0",
64
+ "rimraf": "^6.1.3",
65
+ "style-loader": "^3.2.1",
66
+ "terser": "^5.43.1",
67
+ "three": "0.185.1",
68
+ "ts-loader": "^9.6.2",
69
+ "typescript": "^6.0.3",
70
+ "webpack": "^5.64.4",
71
+ "webpack-cli": "^6.0.1",
72
+ "webpack-dev-server": "^5.2.2"
73
+ },
74
+ "overrides": {
75
+ "@types/scheduler": "< 0.23.0"
76
+ },
77
+ "type": "module"
78
+ }
@@ -0,0 +1,35 @@
1
+ import React, { CSSProperties } from 'react';
2
+ import { GeometryClick, GeometryHit, GeometrySelection, GeometryView, GeometryViewStats } from '../engine/GeometryView';
3
+ import { GeometryViewOptions } from '../engine/GeometryOptions';
4
+ import { CameraState } from '../engine/MapCamera';
5
+ import { GeometryLayer } from '../layers/GeometryLayer';
6
+ import type { GeometryController } from '../edit/GeometryController';
7
+ import { GroundOptions } from '../three/Ground';
8
+ export type ReactGeometryProps = GeometryViewOptions & {
9
+ /** What it draws, bottom first. A layer belongs to one view at a time. */
10
+ layers?: GeometryLayer<any, any>[];
11
+ /** The ground under everything; null for none. */
12
+ ground?: GroundOptions | null;
13
+ /** Flies to every layer once they are in, the first time there are any. */
14
+ fitOnLoad?: boolean;
15
+ /** What has the pointer: drawing, editing, measuring; null or none for the view's own ways. */
16
+ controller?: GeometryController<any> | null;
17
+ onHover?: (hit: GeometryHit | null) => void;
18
+ onClick?: (click: GeometryClick) => void;
19
+ onSelect?: (selection: GeometrySelection) => void;
20
+ onCamera?: (camera: CameraState) => void;
21
+ onFrame?: (stats: GeometryViewStats) => void;
22
+ onReady?: (view: GeometryView) => void;
23
+ className?: string;
24
+ style?: CSSProperties;
25
+ /** The view itself, for code that drives it directly. */
26
+ viewRef?: React.MutableRefObject<GeometryView | null>;
27
+ };
28
+ /**
29
+ * A geometry view in React. It fills its element, so size it there. New options and layers go to
30
+ * the view, which rewrites uniforms and textures for anything of style; nothing below it renders.
31
+ *
32
+ * The view is made when the component mounts and disposed when it unmounts - twice in development
33
+ * under StrictMode, as consumers' apps do: layers come back whole into the second view.
34
+ */
35
+ export declare function ReactGeometry(props: ReactGeometryProps): JSX.Element;
@@ -0,0 +1 @@
1
+ import e,{useEffect as r,useLayoutEffect as t,useRef as n,useState as o}from"react";import{GeometryView as c}from"../engine/GeometryView.js";export function ReactGeometry(a){const{layers:u,ground:i,fitOnLoad:s,controller:y,onHover:f,onClick:m,onSelect:d,onCamera:p,onFrame:h,onReady:v,className:O,style:g,viewRef:j,...b}=a,C=n(null),[k,R]=o(null),w=n({onHover:f,onClick:m,onSelect:d,onCamera:p,onFrame:h,onReady:v});w.current={onHover:f,onClick:m,onSelect:d,onCamera:p,onFrame:h,onReady:v};const A=n(b),E=n(!1);t(()=>{const e=new c(A.current);let r=!0;const t=[e.on("hover",e=>w.current.onHover?.(e)),e.on("click",e=>w.current.onClick?.(e)),e.on("select",e=>w.current.onSelect?.(e)),e.on("camera",e=>w.current.onCamera?.(e)),e.on("frame",e=>w.current.onFrame?.(e))];return e.init(C.current).then(()=>{r&&w.current.onReady?.(e)},e=>console.error("[geometry] The view could not start",e)),R(e),j&&(j.current=e),()=>{r=!1,t.forEach(e=>e()),e.dispose(),j&&(j.current=null),R(null)}},[]);const F=n(b);return t(()=>{if(!k)return;const e={};let r=!1;Object.keys({...F.current,...b}).forEach(t=>{l(F.current[t],b[t])||(e[t]=b[t],r=!0)}),F.current=b,r&&k.setOptions(e)}),t(()=>{k&&k.setGround(i??null)},[k,i]),t(()=>{if(!k)return;const e=u??[];k.getLayers().filter(r=>!e.includes(r)).forEach(e=>k.removeLayer(e)),e.forEach(e=>k.addLayer(e)),s&&!E.current&&e.length>0&&(E.current=!0,k.fit(void 0,0))},[k,u]),t(()=>{k&&k.setController(y??null)},[k,y]),r(()=>()=>{E.current=!1},[]),e.createElement("div",{ref:C,className:O,style:{position:"relative",width:"100%",height:"100%",...g}})}function l(e,r){if(e===r)return!0;if("object"!=typeof e||"object"!=typeof r||null===e||null===r)return!1;if(Array.isArray(e)!==Array.isArray(r))return!1;if(Object.getPrototypeOf(e)!==Object.getPrototypeOf(r))return!1;const t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==Array.prototype)return!1;const n=Object.keys(e);return n.length===Object.keys(r).length&&n.every(t=>l(e[t],r[t]))}
@@ -0,0 +1,79 @@
1
+ import { DepthTexture, Scene } from 'three/webgpu';
2
+ import { FrameInput, GeometryEngine } from '../engine/GeometryEngine';
3
+ import { Sky } from './Sky';
4
+ /** Where a canvas engine's camera comes from each frame: everything of `FrameInput` but the frame's size. */
5
+ export type FrameCamera = Omit<FrameInput, 'width' | 'height' | 'pixelRatio' | 'glDepth'>;
6
+ export interface CanvasGeometryEngineOptions {
7
+ /** Multisampled edges for what is not anti-aliased in its shader (volumes). On by default. */
8
+ antialias?: boolean;
9
+ /** Draw with WebGL 2 even where WebGPU is there. */
10
+ forceWebGL?: boolean;
11
+ /** The colour under everything. */
12
+ background?: string;
13
+ /** The most frame pixels per view pixel drawn: 2 keeps a 4K screen cheap. */
14
+ maxPixelRatio?: number;
15
+ }
16
+ /**
17
+ * The engine on a canvas of its own: a WebGPU renderer, on WebGL 2 where WebGPU is not there.
18
+ *
19
+ * It draws as a host would: first `baseScene` - the ground, a basemap, what stands - into a frame
20
+ * of colour and depth, the depth then being the scene's depth the geometry is ghosted against;
21
+ * then the frame onto the canvas and the geometry over it, as `GeometryEngine` draws it. The
22
+ * camera is the caller's (`setCamera`): a perspective one gets a far plane at infinity and the
23
+ * depth `1 - near / w`, the scene depth every primitive reads.
24
+ *
25
+ * Frames are drawn on demand: `requestRepaint`, or continuously while something animates.
26
+ */
27
+ export declare class CanvasGeometryEngine extends GeometryEngine {
28
+ private readonly options;
29
+ readonly canvas: HTMLCanvasElement;
30
+ /** What the geometry is drawn over, its depth the scene's depth: placed relative to the origin. */
31
+ readonly baseScene: Scene;
32
+ /** The sky behind everything in perspective, in the base. */
33
+ readonly sky: Sky;
34
+ private baseTarget;
35
+ private readonly blitScene;
36
+ private blit;
37
+ private camera3d;
38
+ private scheduled;
39
+ private readonly animators;
40
+ private size;
41
+ private background;
42
+ private initialising;
43
+ constructor(options?: CanvasGeometryEngineOptions);
44
+ protected createDepthTexture(): DepthTexture;
45
+ /** Starts the renderer; frames are drawn from when it is ready. */
46
+ init(): Promise<void>;
47
+ private start;
48
+ /** Where each frame's camera comes from, for a frame `width` by `height` frame pixels. */
49
+ setCamera(camera: (width: number, height: number) => FrameCamera): void;
50
+ setBackground(color: string): void;
51
+ /** The canvas's size in view pixels, and the device's pixels per view pixel. */
52
+ setSize(width: number, height: number, pixelRatio?: number): void;
53
+ /** The size frames are drawn at, in frame pixels. */
54
+ get frameSize(): {
55
+ width: number;
56
+ height: number;
57
+ };
58
+ get viewSize(): {
59
+ width: number;
60
+ height: number;
61
+ pixelRatio: number;
62
+ };
63
+ /** Keeps frames coming while `key` animates something. */
64
+ setAnimating(key: string, animating: boolean): void;
65
+ requestRepaint(): void;
66
+ /** Draws a frame now, rather than at the next animation frame. */
67
+ draw(): void;
68
+ private drewBase;
69
+ private readonly bufferSize;
70
+ /** The base into its frame, and that frame - or the background - onto the canvas. */
71
+ private drawBase;
72
+ private baseDrawn;
73
+ protected depthReady(): boolean;
74
+ dispose(): void;
75
+ /** The base's frame onto the canvas, pixel for pixel. */
76
+ private blitMaterial;
77
+ /** Whether the last frame had a base under it. */
78
+ get hasBase(): boolean;
79
+ }
@@ -0,0 +1 @@
1
+ import{DepthTexture as e,FloatType as t,Mesh as i,NearestFilter as s,PlaneGeometry as a,RenderTarget as h,Scene as r,Vector2 as n,WebGPURenderer as d}from"three/webgpu";import{Fn as o,ivec2 as l,positionGeometry as c,screenCoordinate as u,textureLoad as m,vec4 as g}from"three/tsl";import{GeometryEngine as b}from"../engine/GeometryEngine.js";import{Sky as p}from"./Sky.js";import{disposeMaterial as w,nodeMaterial as f,rawColor as y,unculled as z}from"./Tsl.js";export class CanvasGeometryEngine extends b{constructor(e={}){super(),this.options=e,this.baseScene=new r,this.sky=new p,this.blitScene=new r,this.blit=null,this.camera3d=null,this.scheduled=0,this.animators=new Set,this.size={width:1,height:1,ratio:1},this.background=y("#0b0d10"),this.initialising=null,this.drewBase=!1,this.bufferSize=new n,this.baseDrawn=!1,this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.width="100%",this.canvas.style.height="100%",this.canvas.style.touchAction="none",e.background&&y(e.background,this.background),this.baseScene.add(this.sky.mesh)}createDepthTexture(){const i=new e(1,1,t);return i.minFilter=s,i.magFilter=s,this.baseTarget=new h(1,1,{depthBuffer:!0,generateMipmaps:!1}),this.baseTarget.depthTexture=i,i}init(){return this.initialising??(this.initialising=this.start()),this.initialising}async start(){const e=new d({canvas:this.canvas,antialias:!1!==this.options.antialias,alpha:!1,forceWebGL:!!this.options.forceWebGL});e.setPixelRatio(1),e.info.autoReset=!1,this.adoptRenderer(e),await e.init(),this.disposed||(this.blit=z(new i(new a(2,2),this.blitMaterial())),this.blitScene.add(this.blit),this.ready=!0,this.emit("ready"),this.requestRepaint())}setCamera(e){this.camera3d=e,this.requestRepaint()}setBackground(e){y(e,this.background),this.requestRepaint()}setSize(e,t,i=window.devicePixelRatio||1){const s=Math.min(i,this.options.maxPixelRatio??2);this.size={width:Math.max(1,e),height:Math.max(1,t),ratio:s},this.requestRepaint()}get frameSize(){return{width:Math.max(1,Math.round(this.size.width*this.size.ratio)),height:Math.max(1,Math.round(this.size.height*this.size.ratio))}}get viewSize(){return{width:this.size.width,height:this.size.height,pixelRatio:this.size.ratio}}setAnimating(e,t){t?this.animators.add(e):this.animators.delete(e),t&&this.requestRepaint()}requestRepaint(){this.scheduled||this.disposed||(this.scheduled=requestAnimationFrame(()=>{this.scheduled=0,this.draw(),this.animators.size>0&&this.requestRepaint()}))}draw(){const e=this.renderer;if(!this.ready||!e||!this.camera3d)return;const{width:t,height:i}=this.frameSize,s=e.getDrawingBufferSize(this.bufferSize);s.x===t&&s.y===i||e.setSize(t,i,!1),e.info.reset();const a={...this.camera3d(t,i),width:t,height:i,pixelRatio:this.size.ratio,glDepth:!0},h=this.baseScene.children.some(e=>e.visible);!h||this.baseTarget.width===t&&this.baseTarget.height===i||this.baseTarget.setSize(t,i),this.drewBase=!1;this.renderFrame(a,()=>(this.drawBase(h,e),!0))||this.drawBase(h,e)}drawBase(e,t){if(this.drewBase)return;this.drewBase=!0,t.setClearColor(this.background,1),this.sky.eye.value.copy(this.frame.eye),this.sky.mesh.visible=!this.frame.orthographic,e&&(t.setRenderTarget(this.baseTarget),t.clear(!0,!0,!0),t.render(this.baseScene,this.camera)),t.setRenderTarget(null);const i=t.backend;!this.webgpu&&i?.gl&&i.state?.bindFramebuffer&&i.state.bindFramebuffer(i.gl.FRAMEBUFFER,null),t.clear(!0,!0,!0),e&&this.blit&&t.render(this.blitScene,this.camera),this.baseDrawn=e}depthReady(){return!this.frame.orthographic}dispose(){this.scheduled&&cancelAnimationFrame(this.scheduled),this.scheduled=0,this.animators.clear(),this.baseTarget.dispose(),this.blit&&(this.blit.geometry.dispose(),w(this.blit)),this.sky.dispose(),super.dispose(),this.canvas.remove()}blitMaterial(){const e=f();e.depthTest=!1,e.depthWrite=!1;const t=this.baseTarget.texture;return e.vertexNode=o(()=>g(c.xy,0,1))(),e.fragmentNode=o(()=>m(t,l(u.xy)))(),e}get hasBase(){return this.baseDrawn}}
@@ -0,0 +1,31 @@
1
+ import { Mesh, RenderTarget, Scene } from 'three/webgpu';
2
+ import { ColorRamp } from '../common/Colors';
3
+ /**
4
+ * The heatmap: whatever is in `scene` adds its weight into a half-float target the frame's size,
5
+ * and one full-screen pass (`quad`, in the engine's scene, over everything) colours each pixel's
6
+ * sum with the ramp - as LuciadRIA draws a painter's density. The lines, icons, tubes and spheres
7
+ * put their density meshes in `scene`; the map is drawn whenever one of them is visible.
8
+ */
9
+ export declare class DensityMap {
10
+ readonly scene: Scene;
11
+ readonly quad: Mesh;
12
+ readonly target: RenderTarget<import("three/webgpu").Texture>;
13
+ private readonly colors;
14
+ private colorMap;
15
+ /** The sum that takes the top colour. */
16
+ readonly top: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
17
+ /** The whole map's opacity. */
18
+ readonly opacity: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
19
+ constructor(ramp?: ColorRamp);
20
+ /**
21
+ * The colours to colour the sum with: a ramp from 0 to `top`, or LuciadRIA's `ColorMap`, read
22
+ * from 0 to `top` as it is. Read again only when given another.
23
+ */
24
+ setColorMap(colorMap: ColorRamp, top?: number): void;
25
+ /** Whether anything adds to the map this frame; the colouring pass is shown only then. */
26
+ update(): boolean;
27
+ /** Sums this frame's weights into the target, through `draw`, the engine's draw into a target. */
28
+ draw(width: number, height: number, draw: (scene: Scene, target: RenderTarget) => void): void;
29
+ dispose(): void;
30
+ private material;
31
+ }
@@ -0,0 +1 @@
1
+ import{HalfFloatType as t,Mesh as s,PlaneGeometry as e,RenderTarget as i,Scene as r}from"three/webgpu";import{clamp as o,Discard as a,float as h,Fn as l,If as p,ivec2 as d,positionGeometry as n,screenCoordinate as c,texture as u,textureLoad as m,uniform as g,vec2 as v,vec4 as y}from"three/tsl";import{RAMPS as w,sampleRamp as f}from"../common/Colors.js";import{disposeMaterial as q,nodeMaterial as x,rowTexture as b,unculled as M}from"./Tsl.js";const A=1024;export class DensityMap{constructor(o=w.heat){this.scene=new r,this.target=new i(1,1,{type:t,depthBuffer:!1}),this.colors=b(new Float32Array(4096),!0),this.colorMap=null,this.top=g(64),this.opacity=g(1),this.quad=M(new s(new e(2,2),this.material()),10),this.quad.visible=!1,this.setColorMap(o)}setColorMap(t,s=this.top.value){if(t===this.colorMap&&s===this.top.value)return;this.colorMap=t,this.top.value=s;this.colors.image.data.set(Array.isArray(t)?f(t,A):f(t,A,0,s)),this.colors.needsUpdate=!0}update(){return this.quad.visible=this.scene.children.some(t=>t.visible),this.quad.visible}draw(t,s,e){this.quad.visible&&(this.target.width===t&&this.target.height===s||this.target.setSize(t,s),e(this.scene,this.target))}dispose(){this.target.dispose(),this.colors.dispose(),this.quad.geometry.dispose(),q(this.quad)}material(){const t=x();t.transparent=!0,t.depthTest=!1,t.depthWrite=!1;const s=this.target.texture,e=this.colors;return t.vertexNode=l(()=>y(n.xy,0,1))(),t.fragmentNode=l(()=>{const t=m(s,d(c.xy)).x;p(t.lessThan(.001),()=>{a()});const i=o(t.div(this.top),0,1).mul(1023).add(.5).div(A),r=u(e,v(i,.5)).level(h(0));return y(r.xyz,r.w.mul(this.opacity))})(),t}}
@@ -0,0 +1,191 @@
1
+ import { DataTexture } from 'three/webgpu';
2
+ import { ColorLike, ColorRamp } from '../common/Colors';
3
+ import { N } from './Tsl';
4
+ /**
5
+ * How a feature is drawn, from strongest to weakest: depth and the selection's glow follow it.
6
+ * The numbers are the Ing+ map's `LineState`.
7
+ */
8
+ export declare enum FeatureState {
9
+ Hidden = 0,
10
+ Faded = 1,
11
+ Default = 2,
12
+ Selected = 3
13
+ }
14
+ /** How the features of a category are drawn, by the GPU's category filter. */
15
+ export declare enum CategoryMode {
16
+ Hidden = 0,
17
+ Faded = 1,
18
+ Shown = 2,
19
+ /** Shown and lit, as the selection is: a legend entry pointed at. */
20
+ Lit = 3
21
+ }
22
+ /** Bits of a feature's `flags`: what its primitive draws for it besides its colour and width. */
23
+ export declare const LookFlag: {
24
+ /** `width` in world units (metres) rather than view pixels. */
25
+ readonly Meters: 1;
26
+ /** A line dashed (`GpuLines.dash`). */
27
+ readonly Dashed: 2;
28
+ /** A line with light flowing along it (`GpuLines.flowSpeed`). */
29
+ readonly Flow: 4;
30
+ /** No flow arrow on this line, whatever the primitive draws on the others. */
31
+ readonly NoArrow: 8;
32
+ /** An area hatched rather than filled. */
33
+ readonly Hatch: 16;
34
+ };
35
+ /** A value that is not there: a feature without one takes no part in a range or a ramp. */
36
+ export declare const NO_VALUE = -1e+30;
37
+ /** Categories the GPU filters and colours by, numbered from 0. */
38
+ export declare const MAX_CATEGORIES = 1024;
39
+ export declare const RAMP_STEPS = 256;
40
+ /** One feature's look, as the application gives it; what is left out keeps its value. */
41
+ export interface FeatureLookStyle {
42
+ /** Straight (not premultiplied) colour; its alpha is how strongly the feature shows. */
43
+ color?: ColorLike;
44
+ /** A line's width, an icon's size, a tube's least width on screen, an area's height. */
45
+ width?: number;
46
+ /** `width` in world units rather than view pixels (`LookFlag.Meters`). */
47
+ meters?: boolean;
48
+ /** Other `LookFlag` bits. */
49
+ flags?: number;
50
+ /** A line's real width in world units; an extruded area's base above its ground. */
51
+ realWidth?: number;
52
+ state?: FeatureState;
53
+ /** The finish a body is painted with: an index into the shading's materials. */
54
+ material?: number;
55
+ /** What the feature adds to the density map drawn in, and drawn faded. */
56
+ weight?: number;
57
+ fadedWeight?: number;
58
+ /** Its category, from 0, for the GPU's category filter and colouring; -1 for none. */
59
+ category?: number;
60
+ /** The value a GPU range filter holds it against; `NO_VALUE` or NaN for none. */
61
+ value?: number;
62
+ /** The value a colour ramp colours it by; `NO_VALUE` or NaN for none. */
63
+ colorValue?: number;
64
+ }
65
+ export interface FeatureLookOptions {
66
+ /**
67
+ * Keep a second look per feature for the range drag (`setFail`): what it is drawn as should it
68
+ * fall out of the range. Without, one that falls out is hidden or faded (`rangeOutside`).
69
+ */
70
+ failLooks?: boolean;
71
+ }
72
+ /**
73
+ * Every feature's look on the GPU: colour, width, state, material, density weights, category and
74
+ * values, in float textures indexed by feature, which every primitive drawing those features
75
+ * reads in its vertex shader (`read`). A restyle of any number of features is one upload per
76
+ * texture touched, applied with `commit`, and never a rebuild.
77
+ *
78
+ * What changes often is uniforms, never per feature:
79
+ * - **Hover**: `hoverIndex` lights one feature as the selection is.
80
+ * - **Range filter**: each feature's `value`, held against `rangeLow` and `rangeHigh` while
81
+ * `rangeActive`; a slider drag is two numbers.
82
+ * - **Category filter**: a feature's `category` looks up its mode - hidden, faded, shown, lit -
83
+ * in a table of `MAX_CATEGORIES`; switching a category is one texel.
84
+ * - **Colour by**: the feature's own colour, its category's (`setCategoryColor`), or its
85
+ * `colorValue` through a ramp (`setRamp`).
86
+ * - **Others shaded**: while something is lit, the rest drawn darker (`othersShade`).
87
+ *
88
+ * Several primitives may share one look - an area's fill and its outline, a pipe drawn as a tube
89
+ * in 3D and as a line in 2D - so that they light, filter and colour as one.
90
+ */
91
+ export declare class FeatureLook {
92
+ readonly count: number;
93
+ readonly rows: number;
94
+ readonly colorData: Float32Array;
95
+ readonly styleData: Float32Array;
96
+ readonly extraData: Float32Array;
97
+ readonly valueData: Float32Array;
98
+ readonly failColorData: Float32Array | null;
99
+ readonly failStyleData: Float32Array | null;
100
+ readonly categoryData: Float32Array<ArrayBuffer>;
101
+ readonly rampData: Float32Array<ArrayBuffer>;
102
+ readonly colors: DataTexture;
103
+ readonly styles: DataTexture;
104
+ readonly extras: DataTexture;
105
+ readonly values: DataTexture;
106
+ readonly failColors: DataTexture | null;
107
+ readonly failStyles: DataTexture | null;
108
+ readonly categories: DataTexture;
109
+ readonly ramp: DataTexture;
110
+ /** 1 while a range is applied: the GPU then decides pass or fail per feature. */
111
+ readonly rangeActive: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
112
+ readonly rangeLow: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
113
+ readonly rangeHigh: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
114
+ /** What a feature out of the range becomes: 0 its fail look (`setFail`), 1 hidden, 2 faded. */
115
+ readonly rangeOutside: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
116
+ /** The feature pointed at, -1 for none: drawn lit while `hoverLights`. */
117
+ readonly hoverIndex: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
118
+ readonly hoverLights: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
119
+ /** 1 while the category table applies. */
120
+ readonly categoryActive: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
121
+ /** 0 each feature's own colour, 1 its category's, 2 its `colorValue` through the ramp. */
122
+ readonly colorMode: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
123
+ readonly rampLow: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
124
+ readonly rampHigh: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
125
+ /** What the GPU's filters fade: this much of its alpha left, this much towards grey. */
126
+ readonly fadeOpacity: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
127
+ readonly fadeDesaturate: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
128
+ /** How bright the plain ones are while something is lit, 0 to 1, and towards what (0 black, 1 white). */
129
+ readonly othersShade: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
130
+ readonly othersToward: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
131
+ /** The whole set's opacity. */
132
+ readonly opacity: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
133
+ private dirty;
134
+ /** How many features the look has room for: its textures' whole rows. */
135
+ get capacity(): number;
136
+ constructor(count: number, options?: FeatureLookOptions);
137
+ /** Writes what `style` gives of feature `index`'s look; `commit` uploads it. */
138
+ set(index: number, style: FeatureLookStyle): void;
139
+ setState(index: number, state: FeatureState): void;
140
+ getState(index: number): FeatureState;
141
+ /**
142
+ * The value the range is held against, and whether that is the GPU's to decide: `fixed` 0
143
+ * leaves it to the GPU, 1 has it pass whatever the range, 2 fail.
144
+ */
145
+ setValue(index: number, value: number, fixed?: 0 | 1 | 2): void;
146
+ /** What feature `index` is drawn as should it fall out of the range (`failLooks` only). */
147
+ setFail(index: number, style: Pick<FeatureLookStyle, 'color' | 'width' | 'meters' | 'flags' | 'realWidth' | 'state'>): void;
148
+ /** A category's mode in the GPU's category filter. */
149
+ setCategoryMode(category: number, mode: CategoryMode): void;
150
+ getCategoryMode(category: number): CategoryMode;
151
+ /** A category's colour, for colouring by category (`colorMode` 1). */
152
+ setCategoryColor(category: number, color: ColorLike): void;
153
+ /** The ramp colouring by value uses (`colorMode` 2), from `low` to `high`. */
154
+ setRamp(ramp: ColorRamp, low: number, high: number): void;
155
+ /** Uploads what was written since the last commit; true when anything was. */
156
+ commit(): boolean;
157
+ /** Whether anything is written and not yet committed. */
158
+ get pending(): boolean;
159
+ dispose(): void;
160
+ /**
161
+ * Feature `index`'s look this frame, as nodes for a vertex shader: its own look, unless the
162
+ * range or the category filter puts it lower, lit while pointed at, coloured as the colour
163
+ * mode has it, and shaded while something else is lit.
164
+ */
165
+ read(index: N): FeatureLookNodes;
166
+ }
167
+ /** What `FeatureLook.read` gives a shader. */
168
+ export interface FeatureLookNodes {
169
+ texel: N;
170
+ rgb: N;
171
+ alpha: N;
172
+ state: N;
173
+ width: N;
174
+ flags: N;
175
+ meters: N;
176
+ realWidth: N;
177
+ material: N;
178
+ weight: N;
179
+ selected: N;
180
+ hovered: N;
181
+ plain: N;
182
+ faded: N;
183
+ category: N;
184
+ value: N;
185
+ colorValue: N;
186
+ }
187
+ /**
188
+ * Whether a flags node has a `LookFlag` bit. Rounded first: flags passed on as a varying come out
189
+ * of the interpolation a hair off - 7.99999 for 8 - which, floored, reads as every bit below it.
190
+ */
191
+ export declare function hasFlag(flags: N, bit: number): N;
@@ -0,0 +1 @@
1
+ import{abs as t,clamp as a,dot as e,float as s,floor as r,int as i,ivec2 as o,max as h,min as l,mix as d,texture as n,textureLoad as c,uniform as g,vec2 as y,vec3 as u}from"three/tsl";import{parseColor as f,sampleRamp as v}from"../common/Colors.js";import{featureTexture as V,rowsFor as D,rowTexture as p,texelOf as m}from"./Tsl.js";export var FeatureState;!function(t){t[t.Hidden=0]="Hidden",t[t.Faded=1]="Faded",t[t.Default=2]="Default",t[t.Selected=3]="Selected"}(FeatureState||(FeatureState={}));export var CategoryMode;!function(t){t[t.Hidden=0]="Hidden",t[t.Faded=1]="Faded",t[t.Shown=2]="Shown",t[t.Lit=3]="Lit"}(CategoryMode||(CategoryMode={}));export const LookFlag={Meters:1,Dashed:2,Flow:4,NoArrow:8,Hatch:16};export const NO_VALUE=-1e30;export const MAX_CATEGORIES=1024;export const RAMP_STEPS=256;export class FeatureLook{get capacity(){return 1024*this.rows}constructor(t,a={}){this.categoryData=new Float32Array(4096),this.rampData=new Float32Array(1024),this.rangeActive=g(0),this.rangeLow=g(0),this.rangeHigh=g(0),this.rangeOutside=g(0),this.hoverIndex=g(-1),this.hoverLights=g(1),this.categoryActive=g(0),this.colorMode=g(0),this.rampLow=g(0),this.rampHigh=g(1),this.fadeOpacity=g(.25),this.fadeDesaturate=g(.7),this.othersShade=g(1),this.othersToward=g(0),this.opacity=g(1),this.dirty=0,this.count=t,this.rows=D(t);const e=1024*this.rows*4;this.colorData=new Float32Array(e),this.styleData=new Float32Array(e),this.extraData=new Float32Array(e),this.valueData=new Float32Array(e);for(let t=0;t<e;t+=4)this.extraData[t+1]=1,this.extraData[t+2]=1,this.extraData[t+3]=-1,this.valueData[t+3]=NO_VALUE;this.colors=V(this.colorData,this.rows),this.styles=V(this.styleData,this.rows),this.extras=V(this.extraData,this.rows),this.values=V(this.valueData,this.rows),a.failLooks?(this.failColorData=new Float32Array(e),this.failStyleData=new Float32Array(e),this.failColors=V(this.failColorData,this.rows),this.failStyles=V(this.failStyleData,this.rows)):(this.failColorData=this.failStyleData=null,this.failColors=this.failStyles=null);for(let t=0;t<1024;t++)this.categoryData.set([CategoryMode.Shown,.5,.5,.5],4*t);this.categories=p(this.categoryData),this.rampData.set(v(["#000","#fff"],256)),this.ramp=p(this.rampData,!0)}set(t,a){const e=4*t;if(void 0!==a.color&&(this.colorData.set(f(a.color),e),this.dirty|=1),void 0!==a.width||void 0!==a.meters||void 0!==a.flags||void 0!==a.realWidth||void 0!==a.state){const t=this.styleData;if(void 0!==a.width&&(t[e]=a.width),void 0!==a.meters||void 0!==a.flags){const s=(a.flags??t[e+1]&~LookFlag.Meters)|(a.meters??t[e+1]&LookFlag.Meters?LookFlag.Meters:0);t[e+1]=s}void 0!==a.state&&(t[e+2]=a.state),void 0!==a.realWidth&&(t[e+3]=a.realWidth),this.dirty|=2}if(void 0!==a.material||void 0!==a.weight||void 0!==a.fadedWeight||void 0!==a.category){const t=this.extraData;void 0!==a.material&&(t[e]=a.material),void 0!==a.weight&&(t[e+1]=a.weight),void 0!==a.fadedWeight&&(t[e+2]=a.fadedWeight),void 0!==a.category&&(t[e+3]=a.category<0?-1:a.category),this.dirty|=4}void 0!==a.value&&this.setValue(t,a.value),void 0!==a.colorValue&&(this.valueData[e+3]=Number.isFinite(a.colorValue)?a.colorValue:NO_VALUE,this.dirty|=8)}setState(t,a){this.styleData[4*t+2]=a,this.dirty|=2}getState(t){return this.styleData[4*t+2]}setValue(t,a,e=0){const s=4*t,r=Number.isFinite(a)&&a>NO_VALUE;this.valueData[s]=r?a:0,this.valueData[s+1]=r?1:0,this.valueData[s+2]=e,this.dirty|=8}setFail(t,a){if(!this.failColorData||!this.failStyleData)return;const e=4*t;this.failColorData.set(f(a.color??[0,0,0,0]),e),this.failStyleData[e]=a.width??0,this.failStyleData[e+1]=(a.flags??0)|(a.meters?LookFlag.Meters:0),this.failStyleData[e+2]=a.state??FeatureState.Hidden,this.failStyleData[e+3]=a.realWidth??0,this.dirty|=16}setCategoryMode(t,a){t<0||t>=1024||(this.categoryData[4*t]=a,this.dirty|=32)}getCategoryMode(t){return this.categoryData[4*t]}setCategoryColor(t,a){if(t<0||t>=1024)return;const[e,s,r]=f(a);this.categoryData.set([e,s,r],4*t+1),this.dirty|=32}setRamp(t,a,e){this.rampData.set(v(t,256)),this.rampLow.value=a,this.rampHigh.value=e===a?a+1:e,this.dirty|=64}commit(){return 0!==this.dirty&&(1&this.dirty&&(this.colors.needsUpdate=!0),2&this.dirty&&(this.styles.needsUpdate=!0),4&this.dirty&&(this.extras.needsUpdate=!0),8&this.dirty&&(this.values.needsUpdate=!0),16&this.dirty&&(this.failColors&&(this.failColors.needsUpdate=!0),this.failStyles&&(this.failStyles.needsUpdate=!0)),32&this.dirty&&(this.categories.needsUpdate=!0),64&this.dirty&&(this.ramp.needsUpdate=!0),this.dirty=0,!0)}get pending(){return 0!==this.dirty}dispose(){[this.colors,this.styles,this.extras,this.values,this.failColors,this.failStyles,this.categories,this.ramp].forEach(t=>t?.dispose())}read(r){const g=m(r).toVar(),f=c(this.values,g).toVar(),v=f.y.greaterThan(.5).and(f.x.greaterThanEqual(this.rangeLow)).and(f.x.lessThanEqual(this.rangeHigh)),V=f.z.lessThan(.5).select(v,f.z.lessThan(1.5)).toVar(),D=this.rangeActive.greaterThan(.5).and(V.not()).toVar();let p=c(this.colors,g).toVar(),w=c(this.styles,g).toVar();if(this.failColors&&this.failStyles){const t=D.and(this.rangeOutside.lessThan(.5)).toVar();p=t.select(c(this.failColors,g),p).toVar(),w=t.select(c(this.failStyles,g),w).toVar()}const T=c(this.extras,g).toVar(),x=T.w.toVar(),S=x.greaterThan(-.5).toVar(),F=c(this.categories,o(i(h(x,0)).mod(i(1024)),i(0))).toVar(),C=D.and(this.rangeOutside.greaterThan(.5)).select(this.rangeOutside.greaterThan(1.5).select(s(1),s(0)),s(3)).toVar(),L=this.categoryActive.greaterThan(.5).and(S).toVar(),A=L.and(F.x.lessThan(1.5)).select(F.x,s(3)).toVar(),M=w.z.toVar(),U=l(M,l(C,A)).toVar(),H=U.greaterThan(.5).toVar(),O=t(s(r).sub(this.hoverIndex)).lessThan(.5).and(H).toVar(),E=L.and(F.x.greaterThan(2.5)).and(H),k=O.and(this.hoverLights.greaterThan(.5)).or(E).toVar().select(s(3),U).toVar(),W=f.w.toVar(),b=this.colorMode.greaterThan(.5).and(this.colorMode.lessThan(1.5)).and(S).toVar(),z=this.colorMode.greaterThan(1.5).and(W.greaterThan(-1e29)).toVar(),N=a(W.sub(this.rampLow).div(this.rampHigh.sub(this.rampLow)),0,1),_=n(this.ramp,y(N.mul(255).add(.5).div(256),.5)).level(s(0)).xyz.toVar();let I=b.select(F.yzw,z.select(_,p.xyz)).toVar();const R=k.greaterThan(.5).and(k.lessThan(1.5)).and(M.greaterThan(1.5)).toVar(),j=e(I,u(1/3,1/3,1/3));I=R.select(d(I,u(j,j,j),this.fadeDesaturate),I).toVar();const q=k.greaterThan(1.5).and(k.lessThan(2.5)).toVar(),P=q.select(this.othersShade,s(1)).toVar();I=I.mul(P).add(this.othersToward.mul(s(1).sub(P))).toVar();const G=k.lessThan(.5).select(s(0),p.w.mul(R.select(this.fadeOpacity,s(1))).mul(this.opacity)).toVar(),X=k.greaterThan(1.5).select(T.y,k.greaterThan(.5).select(T.z,s(0))).toVar(),B=w.y.toVar();return{texel:g,rgb:I,alpha:G,state:k,width:w.x.toVar(),flags:B,meters:hasFlag(B,LookFlag.Meters).toVar(),realWidth:w.w.toVar(),material:T.x.toVar(),weight:X,selected:k.greaterThan(2.5).toVar(),hovered:O,plain:q,faded:k.greaterThan(.5).and(k.lessThan(1.5)).toVar(),category:x,value:f.x.toVar(),colorValue:W}}}export function hasFlag(t,a){return r(t.add(.5).div(a)).mod(2).greaterThan(.5)}
@@ -0,0 +1,54 @@
1
+ import { Mesh, Vector3 } from 'three/webgpu';
2
+ import { N } from './Tsl';
3
+ export interface GroundOptions {
4
+ /** Where the picture lies, in world units: min x, min y, max x, max y. The ground reaches far past it. */
5
+ bounds: [number, number, number, number];
6
+ /** Its height, in world units. */
7
+ z?: number;
8
+ color?: string;
9
+ /** A picture laid over it, stretched to its bounds: a basemap, an aerial, a canvas drawn by the application. */
10
+ image?: HTMLCanvasElement | HTMLImageElement | string;
11
+ /** How much of the picture shows over the colour. */
12
+ imageOpacity?: number;
13
+ /** Grid lines every `spacing` world units, and a stronger one every `major` of them. */
14
+ grid?: {
15
+ spacing: number;
16
+ major?: number;
17
+ color?: string;
18
+ opacity?: number;
19
+ } | false;
20
+ /** How far past the bounds the ground reaches, in world units: to the horizon, by default. */
21
+ margin?: number;
22
+ }
23
+ /**
24
+ * A ground plane for a view with nothing under it: drawn in the engine's base, so its depth is the
25
+ * scene's depth - what lies under it is ghosted and haloed. A colour, a picture over its bounds, a
26
+ * grid, reaching far past the picture and fading with distance into the horizon's haze, so it has
27
+ * no edge to see.
28
+ */
29
+ export declare class Ground {
30
+ readonly options: GroundOptions;
31
+ readonly mesh: Mesh;
32
+ private texture;
33
+ readonly color: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<import("three/webgpu").Color>>;
34
+ readonly gridColor: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<Vector3>>;
35
+ readonly gridOpacity: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
36
+ /** The haze the ground fades into with distance, and where it starts and is whole. */
37
+ readonly fogColor: N;
38
+ readonly fogNear: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
39
+ readonly fogFar: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
40
+ /** The camera relative to the origin. */
41
+ readonly eye: N;
42
+ /** The plane's middle relative to the origin. */
43
+ private readonly offset;
44
+ constructor(options: GroundOptions, origin: readonly number[], shared?: {
45
+ eye?: N;
46
+ fog?: N;
47
+ });
48
+ /** Tells the ground the picture changed (a canvas drawn again). */
49
+ refresh(): void;
50
+ /** Fog for a camera this far from what it looks at. */
51
+ setViewDistance(distance: number): void;
52
+ dispose(): void;
53
+ private material;
54
+ }
@@ -0,0 +1 @@
1
+ import{CanvasTexture as t,ClampToEdgeWrapping as e,LinearFilter as i,LinearMipmapLinearFilter as s,Mesh as r,NoColorSpace as o,PlaneGeometry as h,TextureLoader as a,Vector3 as u}from"three/webgpu";import{abs as l,clamp as n,float as d,Fn as g,fract as c,fwidth as m,length as p,max as f,min as x,mix as y,positionLocal as v,smoothstep as w,texture as b,uniform as C,vec2 as O,vec4 as F}from"three/tsl";import{disposeMaterial as M,nodeMaterial as N,rawColor as j}from"./Tsl.js";export class Ground{constructor(l,n,d){this.options=l,this.texture=null,this.color=C(j("#14181d")),this.gridColor=C(new u(1,1,1)),this.gridOpacity=C(.06),this.fogNear=C(1500),this.fogFar=C(9e3),this.offset=C(new u);const[g,c,m,p]=l.bounds,f=Math.max(1,m-g),x=Math.max(1,p-c);if(this.eye=d?.eye??C(new u),this.fogColor=d?.fog??C(j("#18222f")),l.color&&j(l.color,this.color.value),l.grid&&l.grid.color){const t=j(l.grid.color);this.gridColor.value.set(t.r,t.g,t.b)}l.grid&&void 0!==l.grid.opacity&&(this.gridOpacity.value=l.grid.opacity),l.image&&(this.texture="string"==typeof l.image?(new a).load(l.image):new t(l.image),this.texture.colorSpace=o,this.texture.wrapS=this.texture.wrapT=e,this.texture.minFilter=s,this.texture.magFilter=i,this.texture.anisotropy=8),this.offset.value.set((g+m)/2-n[0],(c+p)/2-n[1],(l.z??0)-(n[2]??0));const y=l.margin??Math.max(2e4,8*Math.max(f,x)),v=[f+2*y,x+2*y];this.mesh=new r(new h(v[0],v[1]),this.material(f,x,v[0],v[1])),this.mesh.position.copy(this.offset.value),this.mesh.frustumCulled=!1,this.mesh.renderOrder=-1e3}refresh(){this.texture&&(this.texture.needsUpdate=!0)}setViewDistance(t){this.fogNear.value=1.4*t+600,this.fogFar.value=7*t+4e3}dispose(){this.mesh.geometry.dispose(),M(this.mesh),this.texture?.dispose()}material(t,e,i,s){const r=N();r.transparent=!0,r.depthWrite=!0;const o=this.options,h=o.grid,a=this.texture;return r.colorNode=g(()=>{const r=v.xy;let u=this.color;if(a){const i=r.div(O(t,e)).add(.5),s=x(x(i.x,d(1).sub(i.x)),x(i.y,d(1).sub(i.y))),h=w(0,.03,s),l=b(a,n(i,0,1));u=y(u,l.xyz,l.w.mul(o.imageOpacity??1).mul(h))}if(h){const t=t=>{const e=r.div(t),i=l(c(e.sub(.5)).sub(.5)).div(m(e));return d(1).sub(x(x(i.x,i.y),d(1)))},e=t(h.spacing),i=t(h.spacing*(h.major??10)),s=f(e.mul(this.gridOpacity),i.mul(this.gridOpacity.mul(2.2)));u=y(u,this.gridColor,n(s,0,1))}const g=p(v.add(this.offset).sub(this.eye));u=y(u,this.fogColor,w(this.fogNear,this.fogFar,g));const C=O(i/2,s/2),M=C.sub(l(r)),N=w(0,1,x(M.x.div(C.x),M.y.div(C.y)).mul(8));return F(u,n(N,0,1))})(),r}}
@@ -0,0 +1,26 @@
1
+ import { Mesh, RenderTarget, Scene } from 'three/webgpu';
2
+ /**
3
+ * The dark halo round what is seen through the scene's surface - pipes under the street: their
4
+ * silhouettes where the surface hides them (the bodies' `window` pass, in `scene`), drawn into a
5
+ * mask the frame's size, blurred - the centre and two rings of samples - and laid over the frame in
6
+ * black, under the bodies (`quad`, in the engine's underlay). Soft at its edge and the same
7
+ * wherever silhouettes overlap.
8
+ *
9
+ * The mask has the frame's own pixels: drawn only where the surface hides a body, which this
10
+ * frame's depth decides at each pixel, a smaller mask would read the depth of other pixels.
11
+ */
12
+ export declare class Halo {
13
+ readonly scene: Scene;
14
+ readonly quad: Mesh;
15
+ readonly target: RenderTarget<import("three/webgpu").Texture>;
16
+ /** How far the blur reaches, in frame pixels, and how dark the halo is at most. */
17
+ readonly blur: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
18
+ readonly strength: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
19
+ constructor();
20
+ /** Whether any silhouette is drawn this frame. */
21
+ get active(): boolean;
22
+ /** Draws the silhouettes into the mask, through `draw`, the engine's draw into a target. */
23
+ draw(width: number, height: number, draw: (scene: Scene, target: RenderTarget) => void): void;
24
+ dispose(): void;
25
+ private material;
26
+ }
package/three/Halo.js ADDED
@@ -0,0 +1 @@
1
+ import{LinearFilter as t,Mesh as e,PlaneGeometry as s,RenderTarget as i,Scene as r}from"three/webgpu";import{clamp as h,Discard as a,Fn as n,If as o,positionGeometry as d,screenCoordinate as l,texture as u,uniform as g,vec2 as m,vec4 as c,viewport as p}from"three/tsl";import{disposeMaterial as v,nodeMaterial as x,unculled as f}from"./Tsl.js";export class Halo{constructor(){this.scene=new r,this.target=new i(1,1,{depthBuffer:!1}),this.blur=g(12),this.strength=g(.55),this.target.texture.minFilter=t,this.target.texture.magFilter=t,this.target.texture.generateMipmaps=!1,this.quad=f(new e(new s(2,2),this.material()),-100),this.quad.visible=!1}get active(){return this.scene.children.some(t=>t.visible)}draw(t,e,s){this.quad.visible=this.active,this.quad.visible&&(this.target.width===t&&this.target.height===e||this.target.setSize(t,e),s(this.scene,this.target))}dispose(){this.target.dispose(),this.quad.geometry.dispose(),v(this.quad)}material(){const t=x();t.transparent=!0,t.depthTest=!1,t.depthWrite=!1;const e=this.target.texture,s=this.blur;return t.vertexNode=n(()=>c(d.xy,0,1))(),t.fragmentNode=n(()=>{const t=p.zw,i=l.xy.div(t),r=(r,h)=>u(e,i.add(m(r,h).mul(s).div(t))).x;let n=r(0,0).mul(2),d=2;[.4,1].forEach((t,e)=>{for(let s=0;s<8;s++){const i=(s+.5*e)*Math.PI/4;n=n.add(r(Math.cos(i)*t,Math.sin(i)*t).mul(0===e?1.5:1)),d+=0===e?1.5:1}});const g=h(n.div(d).mul(1.6),0,1).mul(this.strength);return o(g.lessThan(.004),()=>{a()}),c(0,0,0,g)})(),t}}