@protomaze/geometry 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +71 -48
  2. package/common/Colors.d.ts +1 -2
  3. package/edit/GeometryController.d.ts +1 -1
  4. package/engine/GeometryEngine.d.ts +22 -3
  5. package/engine/GeometryEngine.js +1 -1
  6. package/engine/GeometryFrame.d.ts +3 -6
  7. package/engine/GeometryOptions.d.ts +26 -2
  8. package/engine/GeometryView.d.ts +31 -6
  9. package/engine/GeometryView.js +1 -1
  10. package/index.d.ts +1 -1
  11. package/index.js +1 -1
  12. package/layers/AreaLayer.js +1 -1
  13. package/layers/GeometryLayer.d.ts +33 -7
  14. package/layers/GeometryLayer.js +1 -1
  15. package/layers/LineLayer.d.ts +14 -0
  16. package/layers/LineLayer.js +1 -1
  17. package/layers/SphereLayer.js +1 -1
  18. package/layers/TubeLayer.d.ts +20 -5
  19. package/layers/TubeLayer.js +1 -1
  20. package/math/AxisIndex.d.ts +22 -0
  21. package/math/AxisIndex.js +1 -0
  22. package/package.json +1 -1
  23. package/three/CanvasGeometryEngine.d.ts +0 -3
  24. package/three/CanvasGeometryEngine.js +1 -1
  25. package/three/DensityMap.d.ts +3 -3
  26. package/three/FeatureLook.d.ts +19 -2
  27. package/three/FeatureLook.js +1 -1
  28. package/three/HostedGeometryEngine.d.ts +6 -5
  29. package/three/HostedGeometryEngine.js +1 -1
  30. package/three/Shading.d.ts +1 -1
  31. package/three/primitives/Body.d.ts +1 -1
  32. package/three/primitives/Body.js +1 -1
  33. package/three/primitives/GpuAreas.js +1 -1
  34. package/three/primitives/GpuIcons.d.ts +3 -3
  35. package/three/primitives/GpuIcons.js +1 -1
  36. package/three/primitives/GpuLines.d.ts +2 -2
  37. package/three/primitives/GpuLines.js +1 -1
  38. package/three/primitives/GpuSpheres.js +1 -1
  39. package/three/primitives/GpuTubes.d.ts +0 -2
  40. package/three/primitives/GpuTubes.js +1 -1
  41. package/three/RiaGeometryEngine.d.ts +0 -48
  42. package/three/RiaGeometryEngine.js +0 -1
@@ -1,7 +1,7 @@
1
1
  import { ColorLike, ColorRamp, Rgba } from '../common/Colors';
2
2
  import { GeometryFeature, GeometryId, Bounds3 } from '../data/Geometry';
3
3
  import { GeometryEngine } from '../engine/GeometryEngine';
4
- import { GeometryPrimitive, PickOptions } from '../engine/GeometryFrame';
4
+ import { GeometryOccluder, GeometryPrimitive, PickOptions } from '../engine/GeometryFrame';
5
5
  import { TypedEventEmitter } from '../event/TypedEventEmitter';
6
6
  import { FeatureLook, FeatureLookStyle, FeatureState } from '../three/FeatureLook';
7
7
  import { Lighting } from '../three/Shading';
@@ -9,8 +9,8 @@ import { Lighting } from '../three/Shading';
9
9
  export interface ResolvedHighlight {
10
10
  /** A glow round it (bloomed, or drawn in the line shader), or an outline. */
11
11
  look: 'glow' | 'outline';
12
- /** Where the glow comes from: the bloom pass (soft, over everything) or the line shader (cheap). */
13
- glow: 'bloom' | 'shader';
12
+ /** Where the glow comes from: the bloom pass (soft, over everything), the line shader (cheap), or nowhere. */
13
+ glow: 'bloom' | 'shader' | 'none';
14
14
  outlineColor: Rgba;
15
15
  /** View pixels. */
16
16
  outlineWidth: number;
@@ -21,6 +21,8 @@ export interface ResolvedHighlight {
21
21
  othersToward: number;
22
22
  /** Whether pointing at a feature lights it as the selection is. */
23
23
  hoverLights: boolean;
24
+ /** How opaque a lit feature is whose own style or a filter fades or hides it: drawn lit, only fainter. */
25
+ outsideOpacity: number;
24
26
  }
25
27
  /** What a layer needs of the view it is in. */
26
28
  export interface LayerHost {
@@ -54,12 +56,23 @@ export interface CategorySpec<F> {
54
56
  colors?: Record<string, ColorLike> | readonly ColorLike[];
55
57
  }
56
58
  /** The GPU's range filter: every feature's value, and the range it is held against. */
57
- export interface RangeSpec<F> {
59
+ export interface RangeSpec<F, S = any> {
58
60
  value: (feature: F) => number;
59
61
  low: number;
60
62
  high: number;
61
- /** What falls out of it: hidden, or faded. */
63
+ /** What falls out of it: hidden, or faded. Left for `fail` where it gives a look. */
62
64
  outside?: 'hide' | 'fade';
65
+ /**
66
+ * Whether the range has a say on a feature at all: 0 it does, 1 it passes whatever the range
67
+ * (the other filters keep it), 2 it fails whatever the range (they leave it out). 0 for all
68
+ * by default.
69
+ */
70
+ fixed?: (feature: F) => 0 | 1 | 2;
71
+ /**
72
+ * What a feature looks like out of the range, as a style of the layer's own - instead of
73
+ * hiding or fading it. Written once with the values; the drag then only moves the bounds.
74
+ */
75
+ fail?: (feature: F) => S;
63
76
  }
64
77
  /** What the features are coloured by on the GPU: their style, their category, or a value on a ramp. */
65
78
  export type ColorBySpec<F> = {
@@ -105,6 +118,12 @@ export interface GeometryLayerOptions<F, S> {
105
118
  opacity?: number;
106
119
  /** A name for a legend. */
107
120
  title?: string;
121
+ /**
122
+ * What stands in front and hides the features outright where they lie on or under the ground
123
+ * - a host's mask of buildings and trees, by shape (`GeometryOccluder`). Lines on the ground or
124
+ * in space, tubes and spheres use it.
125
+ */
126
+ occluder?: GeometryOccluder | null;
108
127
  }
109
128
  /** What every style has. */
110
129
  export interface BaseStyle {
@@ -172,6 +191,10 @@ export declare abstract class GeometryLayer<F extends GeometryFeature = Geometry
172
191
  private builds;
173
192
  private boundsCache;
174
193
  constructor(options?: GeometryLayerOptions<F, S>);
194
+ /** What hides the features outright where something stands in front; null for nothing. */
195
+ protected occluder: GeometryOccluder | null;
196
+ /** Another occluder: the layer's geometry is built again for it. */
197
+ setOccluder(occluder: GeometryOccluder | null): void;
175
198
  /**
176
199
  * All the features at once. Drawn already, the layer keeps its compiled shaders and builds
177
200
  * only the new geometry - as for `addFeatures`, `updateFeatures` and `removeFeatures`.
@@ -207,10 +230,10 @@ export declare abstract class GeometryLayer<F extends GeometryFeature = Geometry
207
230
  /** A predicate on the CPU: what fails it is hidden, or faded. Null shows all. */
208
231
  setFilter(filter: ((feature: F) => boolean) | null, outside?: 'hide' | 'fade'): void;
209
232
  /** A range on the GPU; null for none. Every feature's value is written once, at the next frame. */
210
- setRange(range: RangeSpec<F> | null): void;
233
+ setRange(range: RangeSpec<F, S> | null): void;
211
234
  /** Moves the range: two uniforms, nothing per feature. */
212
235
  setRangeBounds(low: number, high: number): void;
213
- getRange(): RangeSpec<F> | null;
236
+ getRange(): RangeSpec<F, S> | null;
214
237
  /** Categories on the GPU; null for none. */
215
238
  setCategories(categories: CategorySpec<F> | null): void;
216
239
  /** One category's mode: one texel. */
@@ -228,6 +251,8 @@ export declare abstract class GeometryLayer<F extends GeometryFeature = Geometry
228
251
  isSelected(id: GeometryId): boolean;
229
252
  /** Lights these features as the selection is, without selecting them: what is pointed at elsewhere. */
230
253
  emphasize(ids: Iterable<GeometryId> | null): void;
254
+ /** Whether any feature is emphasised: what shades the rest, as pointing at one does. */
255
+ isEmphasizing(): boolean;
231
256
  /**
232
257
  * Forces a state on features whatever their style and filters say - faded, hidden or lit as
233
258
  * selected - or, with null, lets them be again. What an editor sets off while it works on them.
@@ -300,6 +325,7 @@ export declare abstract class GeometryLayer<F extends GeometryFeature = Geometry
300
325
  private translucent;
301
326
  private updateLooks;
302
327
  private readonly scratch;
328
+ private readonly failScratch;
303
329
  private writeFeature;
304
330
  private categoryOf;
305
331
  private paletteColor;
@@ -1 +1 @@
1
- import{Mesh as e}from"three/webgpu";import{CATEGORY_COLORS as t,desaturate as i,parseColor as s}from"../common/Colors.js";import{boundsOf as r}from"../data/Geometry.js";import{TypedEventEmitter as h}from"../event/TypedEventEmitter.js";import{CategoryMode as o,FeatureLook as a,FeatureState as n,MAX_CATEGORIES as l,NO_VALUE as d}from"../three/FeatureLook.js";const c={hidden:o.Hidden,faded:o.Faded,shown:o.Shown,lit:o.Lit};let u=0;export class GeometryLayer extends h{constructor(e={}){super(),this.features=[],this.indexOf=new Map,this.host=null,this.primitives=[],this.roles=[],this.pick=null,this.density=!1,this.filter=null,this.filterOutside="hide",this.range=null,this.categories=null,this.categoryIndex=new Map,this.categoryModes=new Map,this.coloring={by:"style"},this.selected=new Set,this.emphasized=new Set,this.hovered=null,this.needsBuild=!0,this.needsRefresh=!1,this.builtOrigin=null,this.overrides=new Map,this.allDirty=!0,this.dirty=new Set,this.removePickSource=null,this.builtFor="",this.builds=new Map,this.boundsCache=null,this.overlay=!1,this.overlayOrder=0,this.translucent=!1,this.scratch={},this.id=e.id??"layer-"+ ++u,this.title=e.title,this.style=e.style,this.visible=e.visible??!0,this.pickable=e.pickable??!0,this.opacity=e.opacity??1,e.features&&this.setFeatures(e.features)}setFeatures(e){this.features=e,this.categoryIndex.clear(),this.featuresChanged()}addFeatures(e){0!==e.length&&(this.features=[...this.features,...e],this.featuresChanged())}updateFeatures(e){if(0===e.length)return;const t=[...this.features];for(const i of e){const e=this.indexOf.get(i.id);void 0===e?t.push(i):t[e]=i}this.features=t,this.featuresChanged()}removeFeatures(e){const t=new Set(e);0!==t.size&&(this.features=this.features.filter(e=>!t.has(e.id)),t.forEach(e=>{this.selected.delete(e),this.emphasized.delete(e),this.overrides.delete(e)}),null!==this.hovered&&t.has(this.hovered)&&this.setHovered(null),this.featuresChanged())}featuresChanged(){this.indexOf.clear(),this.features.forEach((e,t)=>this.indexOf.set(e.id,t)),this.boundsCache=null,this.invalidateGeometry(),this.allDirty=!0,this.emit("change",{what:"features"})}invalidateGeometry(){this.primitives.length>0&&!this.needsBuild?this.needsRefresh=!0:this.needsBuild=!0,this.repaint()}getFeatures(){return this.features}getFeature(e){const t=this.indexOf.get(e);return void 0===t?void 0:this.features[t]}featureAt(e){return this.features[e]}get size(){return this.features.length}bounds(){return this.boundsCache??(this.boundsCache=r(this.features)),this.boundsCache}setStyle(e){this.style=e,this.invalidateAll(),this.emit("change",{what:"style"})}restyle(e){if(e){for(const t of e){const e=this.indexOf.get(t);void 0!==e&&this.dirty.add(e)}this.repaint()}else this.invalidateAll()}styleOf(e,t){const i=this.style;return"function"==typeof i?i(e,t)??{}:i??{}}setVisible(e){e!==this.visible&&(this.visible=e,this.repaint(),this.emit("change",{what:"visibility"}))}isVisible(){return this.visible}setPickable(e){this.pickable=e,this.repaint()}isPickable(){return this.pickable&&this.visible}setOpacity(e){this.opacity=e,this.repaint()}setDensity(e){e!==this.density&&(this.density=e,this.repaint())}get drawsDensity(){return this.density}setFilter(e,t="hide"){this.filter=e,this.filterOutside=t,this.invalidateAll(),this.emit("change",{what:"filter"})}setRange(e){const t=!e||!this.range||e.value!==this.range.value;this.range=e,t&&this.invalidateAll(),this.applyGpuState(),this.emit("change",{what:"filter"})}setRangeBounds(e,t){this.range&&(this.range={...this.range,low:e,high:t},this.applyGpuState(),this.emit("change",{what:"filter"}))}getRange(){return this.range}setCategories(e){this.categories=e,this.categoryIndex.clear(),this.categoryModes.clear(),e?.keys?.forEach((e,t)=>this.categoryIndex.set(String(e),t)),e?.modes&&Object.entries(e.modes).forEach(([e,t])=>this.categoryModes.set(this.categoryOf(e),c[t])),this.invalidateAll(),this.applyGpuState(),this.emit("change",{what:"filter"})}setCategoryMode(e,t){const i=this.categoryOf(String(e));this.categoryModes.set(i,c[t]),this.roles.forEach(e=>e.look.setCategoryMode(i,c[t])),this.repaint(),this.emit("change",{what:"filter"})}getCategoryMode(e){const t=this.categoryIndex.get(String(e)),i=void 0===t?o.Shown:this.categoryModes.get(t)??o.Shown;return Object.keys(c).find(e=>c[e]===i)??"shown"}categoryKeys(){return[...this.categoryIndex.keys()]}categoryColor(e){const t=this.categoryOf(String(e));return s(this.paletteColor(String(e),t))}colorBy(e){const t=this.coloring;this.coloring=e??{by:"style"};"value"in this.coloring&&(!("value"in t)||t.value!==this.coloring.value)&&this.invalidateAll(),this.applyGpuState(),this.emit("change",{what:"style"})}select(e,t="replace"){const i=new Set,s=[...e];"replace"===t&&(this.selected.forEach(e=>i.add(e)),this.selected.clear()),s.forEach(e=>{if(!this.indexOf.has(e))return;const s=this.selected.has(e);"remove"!==t&&("toggle"!==t||!s)?this.selected.add(e):this.selected.delete(e),i.add(e)}),0!==i.size&&(this.restyle(i),this.emit("change",{what:"selection"}))}clearSelection(){0!==this.selected.size&&this.select([],"replace")}selection(){return[...this.selected]}isSelected(e){return this.selected.has(e)}emphasize(e){const t=new Set(e??[]),i=new Set;this.emphasized.forEach(e=>{t.has(e)||i.add(e)}),t.forEach(e=>{this.emphasized.has(e)||i.add(e)}),this.emphasized.clear(),t.forEach(e=>this.emphasized.add(e)),i.size>0&&this.restyle(i)}setOverride(e,t){const i=[],s="hidden"===t?n.Hidden:"faded"===t?n.Faded:n.Selected;for(const r of e)(null===t?this.overrides.delete(r):this.overrides.get(r)!==s)&&i.push(r),null!==t&&this.overrides.set(r,s);i.length>0&&this.restyle(i)}clearOverrides(){const e=[...this.overrides.keys()];this.overrides.clear(),e.length>0&&this.restyle(e)}setHovered(e){if(e===this.hovered)return;this.hovered=e;const t=null===e?-1:this.indexOf.get(e)??-1;this.roles.forEach(e=>{e.look.hoverIndex.value=t}),this.repaint()}getHovered(){return this.hovered}get lit(){return this.selected.size>0||this.emphasized.size>0||null!==this.hovered||[...this.categoryModes.values()].some(e=>e===o.Lit)}hitAt(e){const t=this.features[e];return t&&this.isPickable()?{layer:this,feature:t,id:t.id,index:e}:null}attach(e){this.host=e;const t=e.engine.addPickSource(e=>this.hitAt(e));this.pick={pass:e.engine.pickPass,source:t.id},this.removePickSource=t.remove,this.invalidateBuild()}detach(){this.dropPrimitives(),this.removePickSource?.(),this.removePickSource=null,this.pick=null,this.host=null}dispose(){this.detach()}get wantsBuild(){const e=this.host;if(!e)return!1;const t=this.buildKey(e);return(this.needsBuild||t!==this.builtFor)&&!(this.builds.has(t)&&!this.needsBuild)}beforeRender(e=!0){const t=this.host;if(!t)return;const i=this.buildKey(t);if(this.needsBuild||i!==this.builtFor){if(!e&&this.wantsBuild)return;this.build(t,i)}else this.needsRefresh&&this.refresh(t,i);this.updateLooks(),this.updateMeshes(t)}buildKey(e){return e.mode}addRole(e,t){const i=new a(Math.max(1,this.features.length),t);return this.roles.push({look:i,write:e}),i}invalidateBuild(){this.needsBuild=!0,this.needsRefresh=!1,this.repaint()}setOverlay(e,t=0){e===this.overlay&&t===this.overlayOrder||(this.overlay=e,this.overlayOrder=t,this.invalidateBuild())}canRefresh(){return!0}refresh(e,t){this.needsRefresh=!1,this.dropStashed();const i=this.builtOrigin,s=this.roles.every(e=>e.look.capacity>=Math.max(1,this.features.length));if(!i||0===this.primitives.length||!s||!this.canRefresh())return this.needsBuild=!0,void this.build(e,t);const r=performance.now(),h=this.roles;this.roles=[];let o=[],a=[];try{o=this.createPrimitives(e,i)}finally{a=this.roles,this.roles=h}let n=o.length===this.primitives.length;for(let e=0;n&&e<o.length;e++)n=this.primitives[e].adopt?.(o[e])??!1;if(o.forEach(e=>e.dispose()),a.forEach(e=>e.look.dispose()),!n)return this.needsBuild=!0,void this.build(e,t);this.allDirty=!0,this.applyGpuState();const l=null===this.hovered?-1:this.indexOf.get(this.hovered)??-1;this.roles.forEach(e=>{e.look.hoverIndex.value=l}),this.emit("build",{ms:performance.now()-r,features:this.features.length,instances:this.instanceCount(),refresh:!0})}invalidateAll(){this.allDirty=!0,this.repaint()}repaint(){this.host?.requestRepaint()}build(e,t){const i=performance.now();this.stash(),this.needsBuild&&this.dropPrimitives(),this.needsBuild=!1,this.needsRefresh=!1,this.builtFor=t;const s=this.builds.get(t);if(s){this.builds.delete(t),this.primitives=s.primitives,this.roles=s.roles,this.primitives.forEach(t=>e.engine.attach(t)),this.allDirty=!0,this.applyGpuState();const i=null===this.hovered?-1:this.indexOf.get(this.hovered)??-1;return void this.roles.forEach(e=>{e.look.hoverIndex.value=i})}if(0===this.features.length)return;const r=e.engine.originFor(function(e){for(const t of e){const e=t.geometry;if(e)switch(e.type){case"Point":return e.coordinates;case"MultiPoint":case"LineString":if(e.coordinates.length)return e.coordinates[0];break;case"MultiLineString":case"Polygon":if(e.coordinates[0]?.length)return e.coordinates[0][0];break;case"MultiPolygon":if(e.coordinates[0]?.[0]?.length)return e.coordinates[0][0][0]}}return null}(this.features)??[0,0,0]);this.builtOrigin=r,this.primitives=this.createPrimitives(e,r),this.overlay&&this.primitives.forEach(e=>function(e,t){const i=e.passes();for(const e of[...i.scene??[],...i.underlay??[]]){if(!e)continue;const i=e.material;i.depthTest=!1,i.depthWrite=!1,e.renderOrder=1e5+100*t+e.renderOrder}}(e,this.overlayOrder)),this.primitives.forEach(t=>e.engine.attach(t)),this.allDirty=!0,this.applyGpuState();const h=null===this.hovered?-1:this.indexOf.get(this.hovered)??-1;this.roles.forEach(e=>{e.look.hoverIndex.value=h}),this.emit("build",{ms:performance.now()-i,features:this.features.length,instances:this.instanceCount()})}instanceCount(){return this.primitives.reduce((e,t)=>e+(t.segments??t.count??t.triangles??0),0)}stash(){if(0===this.primitives.length)return;const e=this.host?.engine;this.primitives.forEach(t=>e?.detach(t)),this.builds.set(this.builtFor,{primitives:this.primitives,roles:this.roles}),this.primitives=[],this.roles=[]}dropStashed(){this.builds.forEach(({primitives:e,roles:t})=>{e.forEach(e=>e.dispose()),t.forEach(e=>e.look.dispose())}),this.builds.clear()}dropPrimitives(){const e=this.host?.engine;[{primitives:this.primitives,roles:this.roles},...this.builds.values()].forEach(({primitives:t,roles:i})=>{t.forEach(t=>{e?.detach(t),t.dispose()}),i.forEach(e=>e.look.dispose())}),this.builds.clear(),this.primitives=[],this.roles=[]}stateOf(e,t){if("hidden"===t.state)return n.Hidden;let i="faded"===t.state?n.Faded:n.Default;if(this.filter&&!this.filter(e)){if("hide"===this.filterOutside)return n.Hidden;i=n.Faded}const s=this.overrides.get(e.id);return void 0!==s?s:this.selected.has(e.id)||this.emphasized.has(e.id)?n.Selected:i}colorOf(e,t,r,h){const o=s(e??h),a=o[3]*(t??1);if(r===n.Faded){const e=i(o,.7);return[e[0],e[1],e[2],.25*a]}return[o[0],o[1],o[2],a]}updateLooks(){if(0!==this.roles.length){if(this.allDirty){this.translucent=!1;for(let e=0;e<this.features.length;e++)this.writeFeature(e)}else this.dirty.forEach(e=>this.writeFeature(e));this.allDirty=!1,this.dirty.clear(),this.roles.forEach(e=>e.look.commit())}}writeFeature(e){const t=this.features[e];if(!t)return;const i=this.styleOf(t,e),s=this.stateOf(t,i),r=this.categories?this.categoryOf(this.categories.of(t)):-1,h=this.range?this.range.value(t):d,o="value"in this.coloring?this.coloring.value(t):d;for(const a of this.roles){const n=this.scratch;for(const e in n)delete n[e];a.write(t,e,i,s,n),n.state=n.state??s,n.category=r,n.colorValue=o,a.look.set(e,n),a.look.setValue(e,h);const l=n.color;l&&l[3]>.004&&l[3]<.99&&(this.translucent=!0)}}categoryOf(e){if(null==e)return-1;const t=String(e);let i=this.categoryIndex.get(t);if(void 0===i){if(i=this.categoryIndex.size,i>=l)return-1;this.categoryIndex.set(t,i),this.roles.forEach(e=>{e.look.setCategoryColor(i,this.paletteColor(t,i)),e.look.setCategoryMode(i,this.categoryModes.get(i)??o.Shown)})}return i}paletteColor(e,i){const s=this.categories?.colors;return Array.isArray(s)?s[i%s.length]:s&&s[e]?s[e]:t[i%t.length]}applyGpuState(){for(const{look:e}of this.roles){const t=this.range;e.rangeActive.value=t?1:0,e.rangeLow.value=t?.low??0,e.rangeHigh.value=t?.high??0,e.rangeOutside.value="fade"===t?.outside?2:1,e.categoryActive.value=this.categories?1:0,this.categoryIndex.forEach((t,i)=>{e.setCategoryColor(t,this.paletteColor(i,t)),e.setCategoryMode(t,this.categoryModes.get(t)??o.Shown)});const i=this.coloring;e.colorMode.value="value"in i?2:"category"===i.by?1:0,"value"in i&&e.setRamp(i.ramp,i.domain[0],i.domain[1])}this.repaint()}updateMeshes(t){const i=t.highlight,s=this.visible,r=this.density,h=this.lit,o="outline"===i.look,a=!o&&"bloom"===i.glow,[n,l,d]=i.outlineColor;for(const{look:e}of this.roles)e.opacity.value=this.opacity,e.othersShade.value=i.hoverFades&&t.anyHovered?i.othersShade:1,e.othersToward.value=i.othersToward,e.hoverLights.value=i.hoverLights?1:0;for(const c of this.primitives){const u=c,f=c.passes(),g=(e,t)=>f[e]?.forEach(e=>{e&&(e.visible=t)});g("scene",s&&!r),g("halo",s&&!r),g("pick",s&&this.pickable),g("density",s&&r),g("bloom",s&&!r&&h&&a),u.casingMesh instanceof e&&(u.casingMesh.visible=s&&!r&&h&&o),u.ghostMesh instanceof e&&(u.ghostMesh.visible=s&&!r&&this.translucent),u.glowMode&&(u.glowMode.value=o?2:"shader"===i.glow?1:0),u.outlineRgb&&u.outlineRgb.value.set(n,l,d),u.outlineWidth&&(u.outlineWidth.value=i.outlineWidth),u.outlineMode&&(u.outlineMode.value=o?1:0),u.rimRgb&&u.rimRgb.value.set(n,l,d),u.windowsLit&&void 0!==t.windowsLit&&(u.windowsLit.value=t.windowsLit),u.uniforms?.outlineRgb&&(u.uniforms.outlineRgb.value.set(n,l,d),u.uniforms.outlineWidth.value=i.outlineWidth)}}}export function relative(e,t){return[e[0]-t[0],e[1]-t[1],(e[2]??0)-t[2]]}
1
+ import{Mesh as e}from"three/webgpu";import{CATEGORY_COLORS as t,desaturate as i,parseColor as s}from"../common/Colors.js";import{boundsOf as r}from"../data/Geometry.js";import{TypedEventEmitter as h}from"../event/TypedEventEmitter.js";import{CategoryMode as o,FeatureLook as a,FeatureState as l,MAX_CATEGORIES as n,NO_VALUE as d}from"../three/FeatureLook.js";const c={hidden:o.Hidden,faded:o.Faded,shown:o.Shown,lit:o.Lit};let u=0;export class GeometryLayer extends h{constructor(e={}){super(),this.features=[],this.indexOf=new Map,this.host=null,this.primitives=[],this.roles=[],this.pick=null,this.density=!1,this.filter=null,this.filterOutside="hide",this.range=null,this.categories=null,this.categoryIndex=new Map,this.categoryModes=new Map,this.coloring={by:"style"},this.selected=new Set,this.emphasized=new Set,this.hovered=null,this.needsBuild=!0,this.needsRefresh=!1,this.builtOrigin=null,this.overrides=new Map,this.allDirty=!0,this.dirty=new Set,this.removePickSource=null,this.builtFor="",this.builds=new Map,this.boundsCache=null,this.overlay=!1,this.overlayOrder=0,this.translucent=!1,this.scratch={},this.failScratch={},this.id=e.id??"layer-"+ ++u,this.title=e.title,this.style=e.style,this.visible=e.visible??!0,this.pickable=e.pickable??!0,this.opacity=e.opacity??1,this.occluder=e.occluder??null,e.features&&this.setFeatures(e.features)}setOccluder(e){e!==this.occluder&&(this.occluder=e,this.invalidateBuild())}setFeatures(e){this.features=e,this.categoryIndex.clear(),this.featuresChanged()}addFeatures(e){0!==e.length&&(this.features=[...this.features,...e],this.featuresChanged())}updateFeatures(e){if(0===e.length)return;const t=[...this.features];for(const i of e){const e=this.indexOf.get(i.id);void 0===e?t.push(i):t[e]=i}this.features=t,this.featuresChanged()}removeFeatures(e){const t=new Set(e);0!==t.size&&(this.features=this.features.filter(e=>!t.has(e.id)),t.forEach(e=>{this.selected.delete(e),this.emphasized.delete(e),this.overrides.delete(e)}),null!==this.hovered&&t.has(this.hovered)&&this.setHovered(null),this.featuresChanged())}featuresChanged(){this.indexOf.clear(),this.features.forEach((e,t)=>this.indexOf.set(e.id,t)),this.boundsCache=null,this.invalidateGeometry(),this.allDirty=!0,this.emit("change",{what:"features"})}invalidateGeometry(){this.primitives.length>0&&!this.needsBuild?this.needsRefresh=!0:this.needsBuild=!0,this.repaint()}getFeatures(){return this.features}getFeature(e){const t=this.indexOf.get(e);return void 0===t?void 0:this.features[t]}featureAt(e){return this.features[e]}get size(){return this.features.length}bounds(){return this.boundsCache??(this.boundsCache=r(this.features)),this.boundsCache}setStyle(e){this.style=e,this.invalidateAll(),this.emit("change",{what:"style"})}restyle(e){if(e){for(const t of e){const e=this.indexOf.get(t);void 0!==e&&this.dirty.add(e)}this.repaint()}else this.invalidateAll()}styleOf(e,t){const i=this.style;return"function"==typeof i?i(e,t)??{}:i??{}}setVisible(e){e!==this.visible&&(this.visible=e,this.repaint(),this.emit("change",{what:"visibility"}))}isVisible(){return this.visible}setPickable(e){this.pickable=e,this.repaint()}isPickable(){return this.pickable&&this.visible}setOpacity(e){this.opacity=e,this.repaint()}setDensity(e){e!==this.density&&(this.density=e,this.repaint())}get drawsDensity(){return this.density}setFilter(e,t="hide"){this.filter=e,this.filterOutside=t,this.invalidateAll(),this.emit("change",{what:"filter"})}setRange(e){const t=this.range,i=!e||!t||e.value!==t.value||e.fixed!==t.fixed||e.fail!==t.fail;this.range=e,e?.fail&&this.roles.some(e=>!e.look.failStyles)?this.invalidateBuild():i&&this.invalidateAll(),this.applyGpuState(),this.emit("change",{what:"filter"})}setRangeBounds(e,t){this.range&&(this.range={...this.range,low:e,high:t},this.applyGpuState(),this.emit("change",{what:"filter"}))}getRange(){return this.range}setCategories(e){this.categories=e,this.categoryIndex.clear(),this.categoryModes.clear(),e?.keys?.forEach((e,t)=>this.categoryIndex.set(String(e),t)),e?.modes&&Object.entries(e.modes).forEach(([e,t])=>this.categoryModes.set(this.categoryOf(e),c[t])),this.invalidateAll(),this.applyGpuState(),this.emit("change",{what:"filter"})}setCategoryMode(e,t){const i=this.categoryOf(String(e));this.categoryModes.set(i,c[t]),this.roles.forEach(e=>e.look.setCategoryMode(i,c[t])),this.repaint(),this.emit("change",{what:"filter"})}getCategoryMode(e){const t=this.categoryIndex.get(String(e)),i=void 0===t?o.Shown:this.categoryModes.get(t)??o.Shown;return Object.keys(c).find(e=>c[e]===i)??"shown"}categoryKeys(){return[...this.categoryIndex.keys()]}categoryColor(e){const t=this.categoryOf(String(e));return s(this.paletteColor(String(e),t))}colorBy(e){const t=this.coloring;this.coloring=e??{by:"style"};"value"in this.coloring&&(!("value"in t)||t.value!==this.coloring.value)&&this.invalidateAll(),this.applyGpuState(),this.emit("change",{what:"style"})}select(e,t="replace"){const i=new Set,s=[...e];"replace"===t&&(this.selected.forEach(e=>i.add(e)),this.selected.clear()),s.forEach(e=>{if(!this.indexOf.has(e))return;const s=this.selected.has(e);"remove"!==t&&("toggle"!==t||!s)?this.selected.add(e):this.selected.delete(e),i.add(e)}),0!==i.size&&(this.restyle(i),this.emit("change",{what:"selection"}))}clearSelection(){0!==this.selected.size&&this.select([],"replace")}selection(){return[...this.selected]}isSelected(e){return this.selected.has(e)}emphasize(e){const t=new Set(e??[]),i=new Set;this.emphasized.forEach(e=>{t.has(e)||i.add(e)}),t.forEach(e=>{this.emphasized.has(e)||i.add(e)}),this.emphasized.clear(),t.forEach(e=>this.emphasized.add(e)),i.size>0&&this.restyle(i)}isEmphasizing(){return this.emphasized.size>0}setOverride(e,t){const i=[],s="hidden"===t?l.Hidden:"faded"===t?l.Faded:l.Selected;for(const r of e)(null===t?this.overrides.delete(r):this.overrides.get(r)!==s)&&i.push(r),null!==t&&this.overrides.set(r,s);i.length>0&&this.restyle(i)}clearOverrides(){const e=[...this.overrides.keys()];this.overrides.clear(),e.length>0&&this.restyle(e)}setHovered(e){if(e===this.hovered)return;this.hovered=e;const t=null===e?-1:this.indexOf.get(e)??-1;this.roles.forEach(e=>{e.look.hoverIndex.value=t}),this.repaint()}getHovered(){return this.hovered}get lit(){return this.selected.size>0||this.emphasized.size>0||null!==this.hovered||[...this.categoryModes.values()].some(e=>e===o.Lit)}hitAt(e){const t=this.features[e];return t&&this.isPickable()?{layer:this,feature:t,id:t.id,index:e}:null}attach(e){this.host=e;const t=e.engine.addPickSource(e=>this.hitAt(e));this.pick={pass:e.engine.pickPass,source:t.id},this.removePickSource=t.remove,this.invalidateBuild()}detach(){this.dropPrimitives(),this.removePickSource?.(),this.removePickSource=null,this.pick=null,this.host=null}dispose(){this.detach()}get wantsBuild(){const e=this.host;if(!e)return!1;const t=this.buildKey(e);return(this.needsBuild||t!==this.builtFor)&&!(this.builds.has(t)&&!this.needsBuild)}beforeRender(e=!0){const t=this.host;if(!t)return;const i=this.buildKey(t);if(this.needsBuild||i!==this.builtFor){if(!e&&this.wantsBuild)return;this.build(t,i)}else this.needsRefresh&&this.refresh(t,i);this.updateLooks(),this.updateMeshes(t)}buildKey(e){return e.mode}addRole(e,t){const i=new a(Math.max(1,this.features.length),{...t,failLooks:t?.failLooks||!!this.range?.fail});return this.roles.push({look:i,write:e}),i}invalidateBuild(){this.needsBuild=!0,this.needsRefresh=!1,this.repaint()}setOverlay(e,t=0){e===this.overlay&&t===this.overlayOrder||(this.overlay=e,this.overlayOrder=t,this.invalidateBuild())}canRefresh(){return!0}refresh(e,t){this.needsRefresh=!1,this.dropStashed();const i=this.builtOrigin,s=this.roles.every(e=>e.look.capacity>=Math.max(1,this.features.length));if(!i||0===this.primitives.length||!s||!this.canRefresh())return this.needsBuild=!0,void this.build(e,t);const r=performance.now(),h=this.roles;this.roles=[];let o=[],a=[];try{o=this.createPrimitives(e,i)}finally{a=this.roles,this.roles=h}let l=o.length===this.primitives.length;for(let e=0;l&&e<o.length;e++)l=this.primitives[e].adopt?.(o[e])??!1;if(o.forEach(e=>e.dispose()),a.forEach(e=>e.look.dispose()),!l)return this.needsBuild=!0,void this.build(e,t);this.allDirty=!0,this.applyGpuState();const n=null===this.hovered?-1:this.indexOf.get(this.hovered)??-1;this.roles.forEach(e=>{e.look.hoverIndex.value=n}),this.emit("build",{ms:performance.now()-r,features:this.features.length,instances:this.instanceCount(),refresh:!0})}invalidateAll(){this.allDirty=!0,this.repaint()}repaint(){this.host?.requestRepaint()}build(e,t){const i=performance.now();this.stash(),this.needsBuild&&this.dropPrimitives(),this.needsBuild=!1,this.needsRefresh=!1,this.builtFor=t;const s=this.builds.get(t);if(s){this.builds.delete(t),this.primitives=s.primitives,this.roles=s.roles,this.primitives.forEach(t=>e.engine.attach(t)),this.allDirty=!0,this.applyGpuState();const i=null===this.hovered?-1:this.indexOf.get(this.hovered)??-1;return void this.roles.forEach(e=>{e.look.hoverIndex.value=i})}if(0===this.features.length)return;const r=e.engine.originFor(function(e){for(const t of e){const e=t.geometry;if(e)switch(e.type){case"Point":return e.coordinates;case"MultiPoint":case"LineString":if(e.coordinates.length)return e.coordinates[0];break;case"MultiLineString":case"Polygon":if(e.coordinates[0]?.length)return e.coordinates[0][0];break;case"MultiPolygon":if(e.coordinates[0]?.[0]?.length)return e.coordinates[0][0][0]}}return null}(this.features)??[0,0,0]);this.builtOrigin=r,this.primitives=this.createPrimitives(e,r),this.overlay&&this.primitives.forEach(e=>function(e,t){const i=e.passes();for(const e of[...i.scene??[],...i.underlay??[]]){if(!e)continue;const i=e.material;i.depthTest=!1,i.depthWrite=!1,e.renderOrder=1e5+100*t+e.renderOrder}}(e,this.overlayOrder)),this.primitives.forEach(t=>e.engine.attach(t)),this.allDirty=!0,this.applyGpuState();const h=null===this.hovered?-1:this.indexOf.get(this.hovered)??-1;this.roles.forEach(e=>{e.look.hoverIndex.value=h}),this.emit("build",{ms:performance.now()-i,features:this.features.length,instances:this.instanceCount()})}instanceCount(){return this.primitives.reduce((e,t)=>e+(t.segments??t.count??t.triangles??0),0)}stash(){if(0===this.primitives.length)return;const e=this.host?.engine;this.primitives.forEach(t=>e?.detach(t)),this.builds.set(this.builtFor,{primitives:this.primitives,roles:this.roles}),this.primitives=[],this.roles=[]}dropStashed(){this.builds.forEach(({primitives:e,roles:t})=>{e.forEach(e=>e.dispose()),t.forEach(e=>e.look.dispose())}),this.builds.clear()}dropPrimitives(){const e=this.host?.engine;[{primitives:this.primitives,roles:this.roles},...this.builds.values()].forEach(({primitives:t,roles:i})=>{t.forEach(t=>{e?.detach(t),t.dispose()}),i.forEach(e=>e.look.dispose())}),this.builds.clear(),this.primitives=[],this.roles=[]}stateOf(e,t){let i="hidden"===t.state?l.Hidden:"faded"===t.state?l.Faded:l.Default;if(i!==l.Hidden&&this.filter&&!this.filter(e)&&(i="hide"===this.filterOutside?l.Hidden:l.Faded),i!==l.Hidden){const t=this.overrides.get(e.id);if(void 0!==t)return t}return this.selected.has(e.id)||this.emphasized.has(e.id)?i===l.Hidden?l.SelectedHidden:i===l.Faded?l.SelectedFaded:l.Selected:i}colorOf(e,t,r,h){const o=s(e??h),a=o[3]*(t??1);if(r===l.Faded){const e=i(o,.7);return[e[0],e[1],e[2],.25*a]}return[o[0],o[1],o[2],a]}updateLooks(){if(0!==this.roles.length){if(this.allDirty){this.translucent=!1;for(let e=0;e<this.features.length;e++)this.writeFeature(e)}else this.dirty.forEach(e=>this.writeFeature(e));this.allDirty=!1,this.dirty.clear(),this.roles.forEach(e=>e.look.commit())}}writeFeature(e){const t=this.features[e];if(!t)return;const i=this.styleOf(t,e),s=this.stateOf(t,i),r=this.categories?this.categoryOf(this.categories.of(t)):-1,h=this.range,o=h?h.value(t):d,a=h?.fixed?h.fixed(t):0,n=h?.fail?h.fail(t):null,c=n?this.stateOf(t,n):null,u="value"in this.coloring?this.coloring.value(t):d;for(const h of this.roles){const d=this.scratch;for(const e in d)delete d[e];if(h.write(t,e,i,s,d),d.state=d.state??s,d.category=r,d.colorValue=u,h.look.set(e,d),h.look.setValue(e,o,a),n&&null!==c&&h.look.failStyles){const i=this.failScratch;for(const e in i)delete i[e];h.write(t,e,n,c,i),i.state=i.state??c,h.look.setFail(e,i)}const f=d.color;f&&f[3]>.004&&f[3]<.99&&(this.translucent=!0),s>=l.SelectedFaded&&(this.translucent=!0)}}categoryOf(e){if(null==e)return-1;const t=String(e);let i=this.categoryIndex.get(t);if(void 0===i){if(i=this.categoryIndex.size,i>=n)return-1;this.categoryIndex.set(t,i),this.roles.forEach(e=>{e.look.setCategoryColor(i,this.paletteColor(t,i)),e.look.setCategoryMode(i,this.categoryModes.get(i)??o.Shown)})}return i}paletteColor(e,i){const s=this.categories?.colors;return Array.isArray(s)?s[i%s.length]:s&&s[e]?s[e]:t[i%t.length]}applyGpuState(){for(const{look:e}of this.roles){const t=this.range;e.rangeActive.value=t?1:0,e.rangeLow.value=t?.low??0,e.rangeHigh.value=t?.high??0,e.rangeOutside.value=t?.fail?0:"fade"===t?.outside?2:1,e.categoryActive.value=this.categories?1:0,this.categoryIndex.forEach((t,i)=>{e.setCategoryColor(t,this.paletteColor(i,t)),e.setCategoryMode(t,this.categoryModes.get(t)??o.Shown)});const i=this.coloring;e.colorMode.value="value"in i?2:"category"===i.by?1:0,"value"in i&&e.setRamp(i.ramp,i.domain[0],i.domain[1])}this.repaint()}updateMeshes(t){const i=t.highlight,s=this.visible,r=this.density,h=this.lit,o="outline"===i.look,a=!o&&"bloom"===i.glow,[l,n,d]=i.outlineColor;for(const{look:e}of this.roles)e.opacity.value=this.opacity,e.othersShade.value=i.hoverFades&&t.anyHovered?i.othersShade:1,e.othersToward.value=i.othersToward,e.hoverLights.value=i.hoverLights?1:0,e.outsideOpacity.value=i.outsideOpacity;for(const c of this.primitives){const u=c,f=c.passes(),g=(e,t)=>f[e]?.forEach(e=>{e&&(e.visible=t)});g("scene",s&&!r),g("halo",s&&!r),g("pick",s&&this.pickable),g("density",s&&r),g("bloom",s&&!r&&h&&a),u.casingMesh instanceof e&&(u.casingMesh.visible=s&&!r&&h&&o),u.ghostMesh instanceof e&&(u.ghostMesh.visible=s&&!r&&this.translucent),u.glowMode&&(u.glowMode.value=o?2:"shader"===i.glow?1:0),u.outlineRgb&&u.outlineRgb.value.set(l,n,d),u.outlineWidth&&(u.outlineWidth.value=i.outlineWidth),u.outlineMode&&(u.outlineMode.value=o?1:0),u.rimRgb&&u.rimRgb.value.set(l,n,d),u.windowsLit&&void 0!==t.windowsLit&&(u.windowsLit.value=t.windowsLit),u.uniforms?.outlineRgb&&(u.uniforms.outlineRgb.value.set(l,n,d),u.uniforms.outlineWidth.value=i.outlineWidth)}}}export function relative(e,t){return[e[0]-t[0],e[1]-t[1],(e[2]??0)-t[2]]}
@@ -26,6 +26,13 @@ export interface LineLayerOptions<F> extends GeometryLayerOptions<F, LineStyle>
26
26
  arrows?: boolean;
27
27
  /** How far each line stops short of its start and end, in world units: what stands there. */
28
28
  ends?: (feature: F) => [number, number] | null | undefined;
29
+ /** Whether the lines stop short of their ends (`ends`) now: off while what stands there is not drawn. On by default. */
30
+ endsShown?: boolean;
31
+ /**
32
+ * World units per metre, where the world is not in metres - `mercatorWorldPerMetre` on Web
33
+ * Mercator - for widths in metres. 1 by default.
34
+ */
35
+ worldPerMetre?: number;
29
36
  }
30
37
  /**
31
38
  * Lines - networks, routes, trajectories, outlines - as `GpuLines`: one instanced draw, every
@@ -39,6 +46,13 @@ export declare class LineLayer<F extends GeometryFeature = GeometryFeature> exte
39
46
  resolvedMode(host: LayerHost): 'screen' | 'ground' | 'space';
40
47
  protected buildKey(host: LayerHost): string;
41
48
  protected createPrimitives(host: LayerHost, origin: [number, number, number]): GeometryPrimitive[];
49
+ private endsShown;
50
+ private worldPerMetre;
51
+ /** Whether the lines stop short of their ends: a uniform, nothing rebuilt. */
52
+ setEndsShown(shown: boolean): void;
53
+ /** World units per metre, for widths in metres: a uniform, nothing rebuilt. */
54
+ setWorldPerMetre(worldPerMetre: number): void;
55
+ private applyLineUniforms;
42
56
  beforeRender(): void;
43
57
  private flowing;
44
58
  private flows;
@@ -1 +1 @@
1
- import{linesOf as e}from"../data/Geometry.js";import{FeatureState as t,LookFlag as i}from"../three/FeatureLook.js";import{GpuLines as s}from"../three/primitives/GpuLines.js";import{GeometryLayer as o}from"./GeometryLayer.js";export class LineLayer extends o{constructor(e={}){super(e),this.options=e,this.flowing=null}resolvedMode(e){const t=this.options.mode??"auto";if("2d"===e.mode)return"screen";if("auto"!==t&&"screen"!==t)return t;if("screen"===t)return"space";const i=this.bounds();return Math.abs(i.max[2]-i.min[2])>1e-6||Math.abs(i.max[2])>1e-6?"space":"ground"}buildKey(e){return`${e.mode}|${this.resolvedMode(e)}`}createPrimitives(o,r){const n=this.resolvedMode(o),a=this.features.map(t=>e(t.geometry).filter(e=>e.length>1).map(e=>e.map(e=>({x:e[0]-r[0],y:e[1]-r[1],z:(e[2]??0)-r[2]}))));let l;this.options.ends&&(l=new Float32Array(2*this.features.length),this.features.forEach((e,t)=>{const i=this.options.ends(e);i&&l.set(i,2*t)}));const h=this.addRole((e,s,o,r,n)=>{const a=this.colorOf(o.color,o.opacity,r,"#4cc9f0");n.color=a,n.width=o.width??2,n.meters="m"===o.widthUnit,n.realWidth=o.realWidth??0,n.flags=(o.dashed?i.Dashed:0)|(o.flow?i.Flow:0)|(!1===o.arrow?i.NoArrow:0),n.weight=o.weight??1,n.fadedWeight=.3*(o.weight??1),n.state=r,r===t.Selected&&"faded"===o.state&&(n.color=this.colorOf(o.color,o.opacity,t.Default,"#4cc9f0"))});return[new s(a,{look:h,pick:this.pick??void 0,arrows:!!this.options.arrows,ground:"ground"===n?{up:o.up}:void 0,space:"space"===n,ends:l})]}beforeRender(){super.beforeRender();const e=this.host;e&&this.primitive&&e.setAnimating(`flow:${this.id}`,this.isVisible()&&this.flows())}flows(){return null===this.flowing&&(this.flowing=this.features.some((e,t)=>this.styleOf(e,t).flow)),this.flowing}invalidateAll(){this.flowing=null,super.invalidateAll()}get primitive(){return this.primitives.find(e=>e instanceof s)??null}}
1
+ import{linesOf as e}from"../data/Geometry.js";import{FeatureState as t,isLit as i,LookFlag as s}from"../three/FeatureLook.js";import{GpuLines as o}from"../three/primitives/GpuLines.js";import{GeometryLayer as r}from"./GeometryLayer.js";export class LineLayer extends r{constructor(e={}){super(e),this.options=e,this.endsShown=this.options.endsShown??!0,this.worldPerMetre=this.options.worldPerMetre??1,this.flowing=null}resolvedMode(e){const t=this.options.mode??"auto";if("2d"===e.mode)return"screen";if("auto"!==t&&"screen"!==t)return t;if("screen"===t)return"space";const i=this.bounds();return Math.abs(i.max[2]-i.min[2])>1e-6||Math.abs(i.max[2])>1e-6?"space":"ground"}buildKey(e){return`${e.mode}|${this.resolvedMode(e)}`}createPrimitives(r,n){const h=this.resolvedMode(r),l=this.features.map(t=>e(t.geometry).filter(e=>e.length>1).map(e=>e.map(e=>({x:e[0]-n[0],y:e[1]-n[1],z:(e[2]??0)-n[2]}))));let a;this.options.ends&&(a=new Float32Array(2*this.features.length),this.features.forEach((e,t)=>{const i=this.options.ends(e);i&&a.set(i,2*t)}));const d=this.addRole((e,o,r,n,h)=>{const l=this.colorOf(r.color,r.opacity,n,"#4cc9f0");h.color=l,h.width=r.width??2,h.meters="m"===r.widthUnit,h.realWidth=r.realWidth??0,h.flags=(r.dashed?s.Dashed:0)|(r.flow?s.Flow:0)|(!1===r.arrow?s.NoArrow:0),h.weight=r.weight??1,h.fadedWeight=.3*(r.weight??1),h.state=n,i(n)&&"faded"===r.state&&(h.color=this.colorOf(r.color,r.opacity,t.Default,"#4cc9f0"))}),p=new o(l,{look:d,pick:this.pick??void 0,arrows:!!this.options.arrows,ground:"ground"===h?{up:r.up}:void 0,space:"space"===h,ends:a,occluder:this.occluder});return this.applyLineUniforms(p),[p]}setEndsShown(e){this.endsShown=e,this.primitive&&this.applyLineUniforms(this.primitive),this.repaint()}setWorldPerMetre(e){this.worldPerMetre=e,this.primitive&&this.applyLineUniforms(this.primitive),this.repaint()}applyLineUniforms(e){e.endsShown.value=this.endsShown?1:0,e.worldPerMetre.value=this.worldPerMetre}beforeRender(){super.beforeRender();const e=this.host;e&&this.primitive&&e.setAnimating(`flow:${this.id}`,this.isVisible()&&this.flows())}flows(){return null===this.flowing&&(this.flowing=this.features.some((e,t)=>this.styleOf(e,t).flow)),this.flowing}invalidateAll(){this.flowing=null,super.invalidateAll()}get primitive(){return this.primitives.find(e=>e instanceof o)??null}}
@@ -1 +1 @@
1
- import{pointsOf as e}from"../data/Geometry.js";import{GpuIcons as t,IconShape as i}from"../three/primitives/GpuIcons.js";import{GpuSpheres as o}from"../three/primitives/GpuSpheres.js";import{materialCode as r}from"../three/Shading.js";import{GeometryLayer as s}from"./GeometryLayer.js";export class SphereLayer extends s{constructor(e={}){super(e),this.options=e}createPrimitives(s,h){const n="2d"===s.mode,p=this.addRole((e,t,i,o,s)=>{s.color=this.colorOf(i.color,i.opacity,o,"#f72585"),s.material=r(i.material),s.width=n?2*(this.options.radius?.(e)??.25):i.width??4,s.meters=n,s.weight=i.weight??1,s.fadedWeight=.3*(i.weight??1)});if(n){const o=this.features.flatMap((t,o)=>e(t.geometry).map(e=>({x:e[0]-h[0],y:e[1]-h[1],z:0,cell:i.Circle,index:o})));return[new t(o,null,1,{look:p,pick:this.pick??void 0,minPixels:4,border:.6})]}const c=[];this.features.forEach((t,i)=>{const o=this.options.radius?.(t)??.25,r=this.options.reach?.(t)??0;for(const s of e(t.geometry))c.push({x:s[0]-h[0],y:s[1]-h[1],z:(s[2]??0)-h[2],index:i,radius:o,reach:r})});const a=!1!==this.options.ghost;return a&&s.engine.depthTexture(),[new o(c,{look:p,lighting:s.lighting,pick:this.pick??void 0,sceneDepth:a?s.engine.sceneDepth:null})]}}
1
+ import{pointsOf as e}from"../data/Geometry.js";import{GpuIcons as t,IconShape as i}from"../three/primitives/GpuIcons.js";import{GpuSpheres as o}from"../three/primitives/GpuSpheres.js";import{materialCode as r}from"../three/Shading.js";import{GeometryLayer as s}from"./GeometryLayer.js";export class SphereLayer extends s{constructor(e={}){super(e),this.options=e}createPrimitives(s,h){const n="2d"===s.mode,c=this.addRole((e,t,i,o,s)=>{s.color=this.colorOf(i.color,i.opacity,o,"#f72585"),s.material=r(i.material),s.width=n?2*(this.options.radius?.(e)??.25):i.width??4,s.meters=n,s.weight=i.weight??1,s.fadedWeight=.3*(i.weight??1)});if(n){const o=this.features.flatMap((t,o)=>e(t.geometry).map(e=>({x:e[0]-h[0],y:e[1]-h[1],z:0,cell:i.Circle,index:o})));return[new t(o,null,1,{look:c,pick:this.pick??void 0,minPixels:4,border:.6})]}const p=[];this.features.forEach((t,i)=>{const o=this.options.radius?.(t)??.25,r=this.options.reach?.(t)??0;for(const s of e(t.geometry))p.push({x:s[0]-h[0],y:s[1]-h[1],z:(s[2]??0)-h[2],index:i,radius:o,reach:r})});const a=!1!==this.options.ghost;return a&&s.engine.depthTexture(),[new o(p,{look:c,lighting:s.lighting,pick:this.pick??void 0,sceneDepth:a?s.engine.sceneDepth:null,occluder:this.occluder})]}}
@@ -10,15 +10,26 @@ export interface TubeStyle extends BaseStyle {
10
10
  /** On a 2D map, light running along its line, in the direction of its points. */
11
11
  flow?: boolean;
12
12
  }
13
- /** A standing tube for a point feature: a shaft, a pole, a well. */
14
- export interface TubeStand {
15
- /** Heights of its foot and its top, in world units. */
13
+ /**
14
+ * A standing tube for a point feature - a shaft, a pole, a well - from its foot to its top: two
15
+ * world positions, which on a globe stand along the ellipsoid's up there; or, where z is up, the
16
+ * heights of its foot and top at the point's x and y.
17
+ */
18
+ export type TubeStand = ({
19
+ /** Its foot and its top, as world positions. */
20
+ foot: readonly number[];
21
+ top: readonly number[];
22
+ } | {
23
+ /** The heights of its foot and its top at the point, where z is up. */
16
24
  bottom: number;
17
25
  top: number;
26
+ }) & {
18
27
  radius: number;
19
28
  /** A shaft, its top open for the cover lying there (the default), or closed. */
20
29
  open?: boolean;
21
- }
30
+ };
31
+ /** A stand's foot and top as world positions: given, or at its point's x and y. */
32
+ export declare function standAxis(point: readonly number[], stand: TubeStand): [number[], number[]];
22
33
  export interface TubeLayerOptions<F> extends GeometryLayerOptions<F, TubeStyle> {
23
34
  /** A line feature's cross-section: a radius, or a profile. Round, 0.15 by default. */
24
35
  profile?: (feature: F) => number | Profile;
@@ -30,9 +41,13 @@ export interface TubeLayerOptions<F> extends GeometryLayerOptions<F, TubeStyle>
30
41
  arrows?: boolean;
31
42
  /**
32
43
  * Tubes ending in a shaft are cut back to its wall, and two ending on its axis, or at the same
33
- * point, meet in a mitre. On by default.
44
+ * point, meet in a mitre. On by default. A tube's end is in a shaft where it lies on the
45
+ * shaft's axis - within `joinTolerance` of it, in 3D, so on a globe as on a level world -
46
+ * with the pipes and their shafts in one layer.
34
47
  */
35
48
  join?: boolean;
49
+ /** How far off a shaft's axis a tube's end still ends in it, in world units. 0.05 by default. */
50
+ joinTolerance?: number;
36
51
  /** Ghosted where the scene's surface is in front of them, with a halo. On by default. */
37
52
  ghost?: boolean;
38
53
  /** Covers lying on the open shafts' tops, as a 2D map draws manholes. On by default. */
@@ -1 +1 @@
1
- import{linesOf as t,pointsOf as e}from"../data/Geometry.js";import{LookFlag as o}from"../three/FeatureLook.js";import{GpuIcons as r,IconShape as i}from"../three/primitives/GpuIcons.js";import{GpuLines as n}from"../three/primitives/GpuLines.js";import{GpuTubes as s,joinTubeEnds as p,roundProfile as h}from"../three/primitives/GpuTubes.js";import{materialCode as a}from"../three/Shading.js";import{GeometryLayer as c}from"./GeometryLayer.js";export class TubeLayer extends c{constructor(t={}){super(t),this.options=t}createPrimitives(c,d){const m=this.options,f=new Map,g=(t,e)=>`${Math.round(100*t)},${Math.round(100*e)}`,w=this.features.map(t=>{const o=e(t.geometry)[0],r=o&&m.stand?.(t);return o&&r&&!1!==r.open&&f.set(g(o[0],o[1]),r.radius),o&&r?{point:o,stand:r}:null}),v=this.addRole((t,e,r,i,n)=>{const s=w[e];n.color=this.colorOf(r.color,r.opacity,i,"#4cc9f0"),n.material=a(r.material),n.weight=r.weight??1,n.fadedWeight=.3*(r.weight??1),n.flags=r.flow?o.Flow:0,s?(n.width=2*s.stand.radius,n.meters=!0):(n.width=r.width??2.5,n.meters=!1,n.realWidth=2*l(m.profile?.(t))[0])}),k=[],y=[];if(w.forEach((t,e)=>{t&&!1!==t.stand.open&&!1!==m.covers&&y.push({x:t.point[0]-d[0],y:t.point[1]-d[1],z:t.stand.top-d[2]+.01,cell:i.Cover,index:e})}),"2d"===c.mode){const e=[],o=new Float32Array(2*this.features.length);return this.features.forEach((r,i)=>{e.push(t(r.geometry).filter(t=>t.length>1).map(t=>{const e=t[0],r=t[t.length-1];return o[2*i]=f.get(g(e[0],e[1]))??0,o[2*i+1]=f.get(g(r[0],r[1]))??0,t.map(t=>({x:t[0]-d[0],y:t[1]-d[1],z:0}))}))}),k.push(new n(e,{look:v,pick:this.pick??void 0,arrows:!!m.arrows,ends:o})),y.length>0&&k.push(new r(y.map(t=>({...t,z:0})),null,1,{look:v,pick:this.pick??void 0,minPixels:7})),k}const x=[],j=!1!==m.join;this.features.forEach((e,o)=>{const r=m.reach?.(e)??0,i=w[o];if(i){const{point:t,stand:e}=i;return void x.push({points:[[t[0]-d[0],t[1]-d[1],e.bottom-d[2]],[t[0]-d[0],t[1]-d[1],e.top-d[2]]],index:o,profile:h(e.radius),reach:r,kind:!1===e.open?"column":"shaft"})}const n=l(m.profile?.(e));for(const i of t(e.geometry)){if(i.length<2)continue;let t=i.map(t=>[t[0]-d[0],t[1]-d[1],(t[2]??0)-d[2]]);const e=[0,0];if(j){const o=f.get(g(i[0][0],i[0][1])),r=f.get(g(i[i.length-1][0],i[i.length-1][1]));o&&o>n[0]&&(e[0]=Math.sqrt(o*o-n[0]*n[0]),t=u(t,e[0])),r&&r>n[0]&&(e[1]=Math.sqrt(r*r-n[0]*n[0]),t=u(t.reverse(),e[1]).reverse())}t.length<2||x.push({points:t,index:o,profile:n,reach:r,cuts:e})}}),j&&p(x,.01);const M=!1!==m.ghost;M&&c.engine.depthTexture();const G=new s(x,{look:v,lighting:c.lighting,up:c.up,pick:this.pick??void 0,arrows:!!m.arrows,sceneDepth:M?c.engine.sceneDepth:null});return k.push(G),y.length>0&&k.push(new r(y,null,1,{look:v,pick:this.pick??void 0,orientation:"ground",up:c.up,depth:!0})),k}get primitive(){return this.primitives.find(t=>t instanceof s)??null}}function l(t){return void 0===t?h(.15):"number"==typeof t?h(t):t}function u(t,e){let o=e;for(let e=0;e<t.length-1;e++){const[r,i]=[t[e],t[e+1]],n=Math.hypot(i[0]-r[0],i[1]-r[1],i[2]-r[2]);if(n>o+.001){const s=o/n;return[[r[0]+(i[0]-r[0])*s,r[1]+(i[1]-r[1])*s,r[2]+(i[2]-r[2])*s],...t.slice(e+1)]}o-=n}return t}
1
+ import{linesOf as t,pointsOf as o}from"../data/Geometry.js";import{AxisIndex as e}from"../math/AxisIndex.js";import{LookFlag as r}from"../three/FeatureLook.js";import{GpuIcons as i,IconShape as s}from"../three/primitives/GpuIcons.js";import{GpuLines as n}from"../three/primitives/GpuLines.js";import{GpuTubes as p,joinTubeEnds as h,roundProfile as a}from"../three/primitives/GpuTubes.js";import{materialCode as c}from"../three/Shading.js";import{GeometryLayer as u}from"./GeometryLayer.js";export function standAxis(t,o){return"foot"in o?[[...o.foot],[...o.top]]:[[t[0],t[1],o.bottom],[t[0],t[1],o.top]]}export class TubeLayer extends u{constructor(t={}){super(t),this.options=t}createPrimitives(u,d){const m=this.options,g=[],w=this.features.map(t=>{const e=o(t.geometry)[0],r=e&&m.stand?.(t);if(!e||!r)return null;const[i,s]=standAxis(e,r);return!1!==r.open&&g.push({foot:i,top:s,radius:r.radius}),{stand:r,foot:i,top:s}}),v=new e(g,m.joinTolerance??.05),k=(t,o)=>v.at(t,o)?.radius,x=this.addRole((t,o,e,i,s)=>{const n=w[o];s.color=this.colorOf(e.color,e.opacity,i,"#4cc9f0"),s.material=c(e.material),s.weight=e.weight??1,s.fadedWeight=.3*(e.weight??1),s.flags=e.flow?r.Flow:0,n?(s.width=2*n.stand.radius,s.meters=!0):(s.width=e.width??2.5,s.meters=!1,s.realWidth=2*l(m.profile?.(t))[0])}),y=[],j=[];if(w.forEach((t,o)=>{if(t&&!1!==t.stand.open&&!1!==m.covers){const[e,r,i]=[t.top[0]-t.foot[0],t.top[1]-t.foot[1],(t.top[2]??0)-(t.foot[2]??0)],n=.01/(Math.hypot(e,r,i)||1);j.push({x:t.top[0]+e*n-d[0],y:t.top[1]+r*n-d[1],z:(t.top[2]??0)+i*n-d[2],cell:s.Cover,index:o})}}),"2d"===u.mode){const o=[],e=new Float32Array(2*this.features.length);return this.features.forEach((r,i)=>{o.push(t(r.geometry).filter(t=>t.length>1).map(t=>{const o=t[0],r=t[t.length-1];return e[2*i]=k(o,!0)??0,e[2*i+1]=k(r,!0)??0,t.map(t=>({x:t[0]-d[0],y:t[1]-d[1],z:0}))}))}),y.push(new n(o,{look:x,pick:this.pick??void 0,arrows:!!m.arrows,ends:e})),j.length>0&&y.push(new i(j.map(t=>({...t,z:0})),null,1,{look:x,pick:this.pick??void 0,minPixels:7})),y}const G=[],b=!1!==m.join;this.features.forEach((o,e)=>{const r=m.reach?.(o)??0,i=w[e];if(i){const{stand:t,foot:o,top:s}=i;return void G.push({points:[[o[0]-d[0],o[1]-d[1],(o[2]??0)-d[2]],[s[0]-d[0],s[1]-d[1],(s[2]??0)-d[2]]],index:e,profile:a(t.radius),reach:r,kind:!1===t.open?"column":"shaft"})}const s=l(m.profile?.(o));for(const i of t(o.geometry)){if(i.length<2)continue;let t=i.map(t=>[t[0]-d[0],t[1]-d[1],(t[2]??0)-d[2]]);const o=[0,0];if(b){const e=k(i[0],!1),r=k(i[i.length-1],!1);e&&e>s[0]&&(o[0]=Math.sqrt(e*e-s[0]*s[0]),t=f(t,o[0])),r&&r>s[0]&&(o[1]=Math.sqrt(r*r-s[0]*s[0]),t=f(t.reverse(),o[1]).reverse())}t.length<2||G.push({points:t,index:e,profile:s,reach:r,cuts:o})}}),b&&h(G,.01);const A=!1!==m.ghost;A&&u.engine.depthTexture();const L=new p(G,{look:x,lighting:u.lighting,up:u.up,pick:this.pick??void 0,arrows:!!m.arrows,sceneDepth:A?u.engine.sceneDepth:null,occluder:this.occluder});return y.push(L),j.length>0&&y.push(new i(j,null,1,{look:x,pick:this.pick??void 0,orientation:"ground",up:u.up,depth:!0})),y}get primitive(){return this.primitives.find(t=>t instanceof p)??null}}function l(t){return void 0===t?a(.15):"number"==typeof t?a(t):t}function f(t,o){let e=o;for(let o=0;o<t.length-1;o++){const[r,i]=[t[o],t[o+1]],s=Math.hypot(i[0]-r[0],i[1]-r[1],i[2]-r[2]);if(s>e+.001){const n=e/s;return[[r[0]+(i[0]-r[0])*n,r[1]+(i[1]-r[1])*n,r[2]+(i[2]-r[2])*n],...t.slice(o+1)]}e-=s}return t}
@@ -0,0 +1,22 @@
1
+ /** An axis from its foot to its top - a shaft's, a pole's - and how wide what stands on it is. */
2
+ export interface Axis {
3
+ foot: readonly number[];
4
+ top: readonly number[];
5
+ radius: number;
6
+ }
7
+ /**
8
+ * Axes - shafts standing anywhere, along any direction - found from a point on or near them: what
9
+ * shaft a pipe's end lies in. In 3D a point is on an axis within `tolerance` of the line through
10
+ * it, and no further along it than a radius past either end; on a flat map (`flat`) by its x and y
11
+ * alone, so a line at any height finds the shaft it ends at. Works in any world: level x, y and z
12
+ * up, or geocentric, where a shaft stands along the ellipsoid's up and x, y say nothing by
13
+ * themselves.
14
+ */
15
+ export declare class AxisIndex<A extends Axis = Axis> {
16
+ readonly axes: readonly A[];
17
+ readonly tolerance: number;
18
+ private readonly index;
19
+ constructor(axes: readonly A[], tolerance?: number);
20
+ /** The axis a point lies on - the nearest, where several are in reach - or null. */
21
+ at(p: readonly number[], flat?: boolean): A | null;
22
+ }
@@ -0,0 +1 @@
1
+ import{SpatialIndex as t}from"./SpatialIndex.js";export class AxisIndex{constructor(o,n=.05){this.axes=o,this.tolerance=n,this.index=new t;for(const t of o){const o=n+t.radius;this.index.add(Math.min(t.foot[0],t.top[0])-o,Math.min(t.foot[1],t.top[1])-o,Math.max(t.foot[0],t.top[0])+o,Math.max(t.foot[1],t.top[1])+o)}this.index.finish()}at(t,s=!1){const i=this.tolerance;let a=null,h=1/0;for(const e of this.index.search(t[0]-i,t[1]-i,t[0]+i,t[1]+i)){const r=this.axes[e],c=s?n(t,r):o(t,r);c<=i&&c<h&&(a=r,h=c)}return a}}function o(t,o){const n=o.foot,s=o.top,i=s[0]-n[0],a=s[1]-n[1],h=(s[2]??0)-(n[2]??0),e=Math.hypot(i,a,h),r=t[0]-n[0],c=t[1]-n[1],f=(t[2]??0)-(n[2]??0);if(e<1e-9)return Math.hypot(r,c,f);const p=(r*i+c*a+f*h)/e;if(p<-o.radius||p>e+o.radius)return 1/0;const x=p/e;return Math.hypot(r-i*x,c-a*x,f-h*x)}function n(t,o){const n=o.foot,s=o.top,i=s[0]-n[0],a=s[1]-n[1],h=i*i+a*a,e=t[0]-n[0],r=t[1]-n[1],c=h<1e-18?0:Math.max(0,Math.min(1,(e*i+r*a)/h));return Math.hypot(e-i*c,r-a*c)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protomaze/geometry",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Protomaze Geometry: GPU points, lines, tubes and areas in 2D and 3D, styled, filtered, highlighted and picked on the GPU",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,7 +36,6 @@ export declare class CanvasGeometryEngine extends GeometryEngine {
36
36
  private blit;
37
37
  private camera3d;
38
38
  private scheduled;
39
- private readonly animators;
40
39
  private size;
41
40
  private background;
42
41
  private initialising;
@@ -60,8 +59,6 @@ export declare class CanvasGeometryEngine extends GeometryEngine {
60
59
  height: number;
61
60
  pixelRatio: number;
62
61
  };
63
- /** Keeps frames coming while `key` animates something. */
64
- setAnimating(key: string, animating: boolean): void;
65
62
  requestRepaint(): void;
66
63
  /** Draws a frame now, rather than at the next animation frame. */
67
64
  draw(): void;
@@ -1 +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 o}from"three/webgpu";import{Fn as d,ivec2 as c,positionGeometry as l,screenCoordinate as m,textureLoad as u,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";import{PROTOMAZE_DARK as x}from"../theme/Theme.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(x.background),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 o({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=d(()=>g(l.xy,0,1))(),e.fragmentNode=d(()=>u(t,c(m.xy)))(),e}get hasBase(){return this.baseDrawn}}
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 o}from"three/webgpu";import{Fn as d,ivec2 as c,positionGeometry as l,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";import{PROTOMAZE_DARK as x}from"../theme/Theme.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.size={width:1,height:1,ratio:1},this.background=y(x.background),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 o({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}}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=d(()=>g(l.xy,0,1))(),e.fragmentNode=d(()=>m(t,c(u.xy)))(),e}get hasBase(){return this.baseDrawn}}
@@ -3,7 +3,7 @@ import { ColorRamp } from '../common/Colors';
3
3
  /**
4
4
  * The heatmap: whatever is in `scene` adds its weight into a half-float target the frame's size,
5
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
6
+ * sum with the ramp, as a map draws a density. The lines, icons, tubes and spheres
7
7
  * put their density meshes in `scene`; the map is drawn whenever one of them is visible.
8
8
  */
9
9
  export declare class DensityMap {
@@ -18,8 +18,8 @@ export declare class DensityMap {
18
18
  readonly opacity: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
19
19
  constructor(ramp?: ColorRamp);
20
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.
21
+ * The colours to colour the sum with: a ramp from 0 to `top`, or a colour map with
22
+ * `retrieveColor`, read from 0 to `top` as it is. Read again only when given another.
23
23
  */
24
24
  setColorMap(colorMap: ColorRamp, top?: number): void;
25
25
  /** Whether anything adds to the map this frame; the colouring pass is shown only then. */
@@ -3,14 +3,22 @@ import { ColorLike, ColorRamp } from '../common/Colors';
3
3
  import { N } from './Tsl';
4
4
  /**
5
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
6
  */
8
7
  export declare enum FeatureState {
9
8
  Hidden = 0,
10
9
  Faded = 1,
11
10
  Default = 2,
12
- Selected = 3
11
+ Selected = 3,
12
+ /**
13
+ * Lit - selected or emphasised - where its own style fades it: drawn lit all the same, its
14
+ * glow or its outline behind it, only faded (`outsideOpacity`), to show it is not in view now.
15
+ */
16
+ SelectedFaded = 4,
17
+ /** Lit where its own style hides it: as `SelectedFaded`, and never picked. */
18
+ SelectedHidden = 5
13
19
  }
20
+ /** Whether a state is lit - selected or emphasised - whatever its own style says. */
21
+ export declare function isLit(state: FeatureState | number | undefined): boolean;
14
22
  /** How the features of a category are drawn, by the GPU's category filter. */
15
23
  export declare enum CategoryMode {
16
24
  Hidden = 0,
@@ -127,6 +135,8 @@ export declare class FeatureLook {
127
135
  readonly fadeDesaturate: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
128
136
  /** How bright the plain ones are while something is lit, 0 to 1, and towards what (0 black, 1 white). */
129
137
  readonly othersShade: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
138
+ /** How opaque a lit feature is whose own style or the GPU's filters fade or hide it, 0 to 1. */
139
+ readonly outsideOpacity: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
130
140
  readonly othersToward: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
131
141
  /** The whole set's opacity. */
132
142
  readonly opacity: import("three/tsl").ShaderNodeObject<import("three/webgpu").UniformNode<number>>;
@@ -177,6 +187,13 @@ export interface FeatureLookNodes {
177
187
  material: N;
178
188
  weight: N;
179
189
  selected: N;
190
+ /**
191
+ * How strongly what is lit shows, 0 to 1: 1, or `outsideOpacity` for a lit feature its own
192
+ * style or a filter fades or hides. Body, outline and glow are all drawn at it.
193
+ */
194
+ strength: N;
195
+ /** Whether a pick may hit it: shown, and not lit only where its style hides it. */
196
+ pickable: N;
180
197
  hovered: N;
181
198
  plain: N;
182
199
  faded: N;
@@ -1 +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)}
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 p,rowTexture as D,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",t[t.SelectedFaded=4]="SelectedFaded",t[t.SelectedHidden=5]="SelectedHidden"}(FeatureState||(FeatureState={}));export function isLit(t){return void 0!==t&&t>=FeatureState.Selected}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.outsideOpacity=g(.6),this.othersToward=g(0),this.opacity=g(1),this.dirty=0,this.count=t,this.rows=p(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=D(this.categoryData),this.rampData.set(V(["#000","#fff"],256)),this.ramp=D(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(),p=this.rangeActive.greaterThan(.5).and(v.not()).toVar();let D=c(this.colors,g).toVar(),w=c(this.styles,g).toVar();if(this.failColors&&this.failStyles){const t=p.and(this.rangeOutside.lessThan(.5)).toVar();D=t.select(c(this.failColors,g),D).toVar(),w=t.select(c(this.failStyles,g),w).toVar()}const T=c(this.extras,g).toVar(),S=T.w.toVar(),x=S.greaterThan(-.5).toVar(),F=c(this.categories,o(i(h(S,0)).mod(i(1024)),i(0))).toVar(),L=p.and(this.rangeOutside.greaterThan(.5)).select(this.rangeOutside.greaterThan(1.5).select(s(1),s(0)),s(3)).toVar(),C=this.categoryActive.greaterThan(.5).and(x).toVar(),A=C.and(F.x.lessThan(1.5)).select(F.x,s(3)).toVar(),M=w.z.toVar(),H=l(L,A).toVar(),O=M.greaterThan(2.5).toVar(),U=O.select(s(3),l(M,H)).toVar(),E=O.and(M.greaterThan(3.5).or(H.lessThan(1.5))).toVar(),k=O.and(M.greaterThan(4.5).or(H.lessThan(.5))).toVar(),b=U.greaterThan(.5).toVar(),W=t(s(r).sub(this.hoverIndex)).lessThan(.5).and(b).toVar(),z=C.and(F.x.greaterThan(2.5)).and(b),N=W.and(this.hoverLights.greaterThan(.5)).or(z).toVar(),_=N.select(s(3),U).toVar(),I=E.and(N.not()).select(this.outsideOpacity,s(1)).toVar(),R=f.w.toVar(),j=this.colorMode.greaterThan(.5).and(this.colorMode.lessThan(1.5)).and(x).toVar(),q=this.colorMode.greaterThan(1.5).and(R.greaterThan(-1e29)).toVar(),P=a(R.sub(this.rampLow).div(this.rampHigh.sub(this.rampLow)),0,1),G=n(this.ramp,y(P.mul(255).add(.5).div(256),.5)).level(s(0)).xyz.toVar();let X=j.select(F.yzw,q.select(G,D.xyz)).toVar();const B=_.greaterThan(.5).and(_.lessThan(1.5)).and(M.greaterThan(1.5)).toVar(),J=e(X,u(1/3,1/3,1/3));X=B.select(d(X,u(J,J,J),this.fadeDesaturate),X).toVar();const K=_.greaterThan(1.5).and(_.lessThan(2.5)).toVar(),Q=K.select(this.othersShade,s(1)).toVar();X=X.mul(Q).add(this.othersToward.mul(s(1).sub(Q))).toVar();const Y=_.lessThan(.5).select(s(0),D.w.mul(B.select(this.fadeOpacity,s(1))).mul(this.opacity).mul(I)).toVar(),Z=_.greaterThan(1.5).select(T.y,_.greaterThan(.5).select(T.z,s(0))).toVar(),$=w.y.toVar();return{texel:g,rgb:X,alpha:Y,state:_,width:w.x.toVar(),flags:$,meters:hasFlag($,LookFlag.Meters).toVar(),realWidth:w.w.toVar(),material:T.x.toVar(),weight:Z,selected:_.greaterThan(2.5).toVar(),strength:I,pickable:_.greaterThan(.5).and(k.not()).toVar(),hovered:W,plain:K,faded:_.greaterThan(.5).and(_.lessThan(1.5)).toVar(),category:S,value:f.x.toVar(),colorValue:R}}}export function hasFlag(t,a){return r(t.add(.5).div(a)).mod(2).greaterThan(.5)}
@@ -23,9 +23,10 @@ export interface HostedGeometryEngineOptions {
23
23
  * device and a stand-in context whose "current texture" is the host's colour texture. The
24
24
  * result is painted over the host's GPU layers and under whatever the host puts in the DOM.
25
25
  *
26
- * LuciadRIA 2026 is one host: it renders with WebGPU only and fires "PostRender" with the frame's
27
- * textures (`RiaGeometryEngine` wires it up). This is the Ing+ map's `RiaThreeRenderer`, without
28
- * the map.
26
+ * A host - a map toolkit, a globe - wires it up in a few lines of its own, outside this package:
27
+ * its device (`setDevice` again when it makes a new one), `render` from its after-drawing hook
28
+ * with that frame's textures and camera, and `requestFrame` for its own repaint. A `GeometryView`
29
+ * on it (`new GeometryView({ engine })`) then holds the layers, the highlight and the picking.
29
30
  */
30
31
  export declare class HostedGeometryEngine extends GeometryEngine {
31
32
  private readonly host;
@@ -37,8 +38,8 @@ export declare class HostedGeometryEngine extends GeometryEngine {
37
38
  protected originKey(): string;
38
39
  requestRepaint(): void;
39
40
  /**
40
- * The device to draw with: the host makes a new one at times (LuciadRIA does when the map's
41
- * reference changes, 2D to 3D). Everything made on the old one is dropped with it.
41
+ * The device to draw with: a host may make a new one at times - a map does when it switches
42
+ * between 2D and 3D. Everything made on the old one is dropped with it.
42
43
  */
43
44
  setDevice(device: unknown): void;
44
45
  /**
@@ -1 +1 @@
1
- import{Vector2 as e,WebGPURenderer as t}from"three/webgpu";import{GeometryEngine as i}from"../engine/GeometryEngine.js";export class HostedGeometryEngine extends i{constructor(t){super(),this.host=t,this.target=null,this.depthBroken=!1,this.depthMisses=0,this.size=new e,t.device&&this.setDevice(t.device)}originKey(){return this.host.originKey?.()??"world"}requestRepaint(){if(!this.disposed)try{this.host.requestFrame()}catch{}}setDevice(e){try{this.renderer?.dispose()}catch{}if(this.renderer=null,this.ready=!1,!e||this.disposed)return;const i=new t({device:e,context:{configure(){},unconfigure(){},getCurrentTexture:()=>this.target},alpha:!0,antialias:!1,depth:!0});i.setPixelRatio(1),this.adoptRenderer(i),i.init().then(()=>{this.renderer===i&&(this.ready=!0,this.emit("ready"),this.requestRepaint())},e=>console.error("[geometry] three.js could not start on the host device",e))}render(e,t,i){const r=this.renderer;if(!this.ready||!r)return!1;this.target=e;const h=r.getSize(this.size);h.x===e.width&&h.y===e.height||r.setSize(e.width,e.height,!1);const s={...i,width:e.width,height:e.height},n=this.renderFrame(s,()=>!(this.depthWanted&&!this.depthBroken&&t&&!this.copyDepth(t))||(this.requestRepaint(),!1));return this.target=null,n}depthReady(){return!this.depthBroken}copyDepth(e){const t=this.renderer,i=this.depth;if(!t)return!1;try{i.image.width===e.width&&i.image.height===e.height||(i.image.width=e.width,i.image.height=e.height,i.needsUpdate=!0,t.initTexture(i));const r=t.backend?.get?.(i)?.texture;if(!r){if(t.initTexture(i),++this.depthMisses>3)throw new Error("three.js made no GPU texture for the depth copy");return!1}this.depthMisses=0;const h=t.backend.device,s=h.createCommandEncoder();return s.copyTextureToTexture({texture:e},{texture:r},[e.width,e.height]),h.queue.submit([s.finish()]),!0}catch(e){return console.warn("[geometry] No depth from the host; drawing without occlusion",e),this.depthBroken=!0,!0}}}
1
+ import{Vector2 as e,WebGPURenderer as t}from"three/webgpu";import{GeometryEngine as i}from"../engine/GeometryEngine.js";export class HostedGeometryEngine extends i{constructor(t){super(),this.host=t,this.target=null,this.depthBroken=!1,this.depthMisses=0,this.size=new e,t.device&&this.setDevice(t.device)}originKey(){return this.host.originKey?.()??"world"}requestRepaint(){if(!this.disposed)try{this.host.requestFrame()}catch{}}setDevice(e){try{this.renderer?.dispose()}catch{}if(this.renderer=null,this.ready=!1,!e||this.disposed)return;const i=new t({device:e,context:{configure(){},unconfigure(){},getCurrentTexture:()=>this.target},alpha:!0,antialias:!1,depth:!0});i.setPixelRatio(1),this.adoptRenderer(i),i.init().then(()=>{this.renderer===i&&(this.ready=!0,this.emit("ready"),this.requestRepaint())},e=>console.error("[geometry] three.js could not start on the host device",e))}render(e,t,i){const r=this.renderer;if(!this.ready||!r)return!1;this.target=e;const h=r.getSize(this.size);h.x===e.width&&h.y===e.height||r.setSize(e.width,e.height,!1);const s={...i,width:e.width,height:e.height},n=this.renderFrame(s,()=>!(this.depthWanted&&!this.depthBroken&&t&&!this.copyDepth(t))||(this.requestRepaint(),!1));return this.target=null,this.animators.size>0&&this.requestRepaint(),n}depthReady(){return!this.depthBroken}copyDepth(e){const t=this.renderer,i=this.depth;if(!t)return!1;try{i.image.width===e.width&&i.image.height===e.height||(i.image.width=e.width,i.image.height=e.height,i.needsUpdate=!0,t.initTexture(i));const r=t.backend?.get?.(i)?.texture;if(!r){if(t.initTexture(i),++this.depthMisses>3)throw new Error("three.js made no GPU texture for the depth copy");return!1}this.depthMisses=0;const h=t.backend.device,s=h.createCommandEncoder();return s.copyTextureToTexture({texture:e},{texture:r},[e.width,e.height]),h.queue.submit([s.finish()]),!0}catch(e){return console.warn("[geometry] No depth from the host; drawing without occlusion",e),this.depthBroken=!0,!0}}}
@@ -4,7 +4,7 @@ import { N } from './Tsl';
4
4
  * The finishes bodies are painted in, by `materialCode`, the first for any other; the colour is
5
5
  * the feature's, as paint. `shininess` is how tight the highlight is, `sheen` how bright.
6
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.
7
+ * soft sheen, steel bright, cast iron dull: a network's pipes.
8
8
  */
9
9
  export declare const MATERIALS: {
10
10
  name: string;
@@ -31,7 +31,7 @@ export declare const HALO_GROW = 0.25;
31
31
  export interface BodyOptions {
32
32
  /** The scene's depth: what lies behind it is drawn ghosted (`ghostAlpha`) and haloed. */
33
33
  sceneDepth?: SceneDepth | null;
34
- /** What stands in front and hides a body outright (the Ing+ map's buildings mask). */
34
+ /** What stands in front and hides a body outright: a host's mask of buildings, trees. */
35
35
  occluder?: GeometryOccluder | null;
36
36
  pick?: PickOptions;
37
37
  look?: FeatureLook;
@@ -1 +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)})()}
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 m,vec3 as b,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:m("vec4","vColor"),vNormal:m("vec3","vNormal"),vDistance:m("float","vDistance"),vPosition:m("vec3","vPosition"),vMaterial:m("vec2","vMaterial"),vIndex:m("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:m,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.mul(f.w),1);if("casing"===e)return w(o.outlineRgb,c.select(o.ghostAlpha,d(1)).mul(f.w));const A=r.shade(D.x,m,T,f.xyz),L=c.select(f.w.mul(o.ghostAlpha),f.w);return w(c.select(v(A,b(1,1,1),o.ghostLighten),A),L)})()}
@@ -1 +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}}
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 k,screenCoordinate as M,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(e?a.pickable.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(M.x.add(M.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=k(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(k(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),M=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),M)).mul(m(1).sub(A(m(.8).sub(R),m(.8).add(R),M))),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=k(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.mul(F.w),1):j(g,b)})(),a}}