@protomaze/geometry 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/GeometryDemo.js +1 -1
  2. package/README.md +129 -47
  3. package/common/Colors.d.ts +1 -2
  4. package/common/Colors.js +1 -1
  5. package/demo/DemoControls.d.ts +13 -3
  6. package/demo/DemoControls.js +1 -1
  7. package/edit/CreateController.js +1 -1
  8. package/edit/EditController.js +1 -1
  9. package/edit/GeometryController.d.ts +7 -1
  10. package/edit/MeasureController.js +1 -1
  11. package/edit/Sketch.d.ts +19 -2
  12. package/edit/Sketch.js +1 -1
  13. package/engine/GeometryEngine.d.ts +22 -3
  14. package/engine/GeometryEngine.js +1 -1
  15. package/engine/GeometryFrame.d.ts +3 -6
  16. package/engine/GeometryOptions.d.ts +48 -4
  17. package/engine/GeometryOptions.js +1 -1
  18. package/engine/GeometryView.d.ts +48 -6
  19. package/engine/GeometryView.js +1 -1
  20. package/engine/Labels.d.ts +9 -0
  21. package/engine/Labels.js +1 -1
  22. package/index.d.ts +1 -1
  23. package/index.js +1 -1
  24. package/layers/AreaLayer.js +1 -1
  25. package/layers/GeometryLayer.d.ts +33 -7
  26. package/layers/GeometryLayer.js +1 -1
  27. package/layers/LineLayer.d.ts +14 -0
  28. package/layers/LineLayer.js +1 -1
  29. package/layers/SphereLayer.js +1 -1
  30. package/layers/TubeLayer.js +1 -1
  31. package/package.json +1 -1
  32. package/theme/Theme.d.ts +125 -0
  33. package/theme/Theme.js +1 -0
  34. package/three/CanvasGeometryEngine.d.ts +1 -4
  35. package/three/CanvasGeometryEngine.js +1 -1
  36. package/three/DensityMap.d.ts +3 -3
  37. package/three/FeatureLook.d.ts +19 -2
  38. package/three/FeatureLook.js +1 -1
  39. package/three/Ground.d.ts +5 -0
  40. package/three/Ground.js +1 -1
  41. package/three/HostedGeometryEngine.d.ts +6 -5
  42. package/three/HostedGeometryEngine.js +1 -1
  43. package/three/Shading.d.ts +1 -1
  44. package/three/primitives/Body.d.ts +1 -1
  45. package/three/primitives/Body.js +1 -1
  46. package/three/primitives/GpuAreas.js +1 -1
  47. package/three/primitives/GpuIcons.d.ts +3 -3
  48. package/three/primitives/GpuIcons.js +1 -1
  49. package/three/primitives/GpuLines.d.ts +2 -2
  50. package/three/primitives/GpuLines.js +1 -1
  51. package/three/primitives/GpuSpheres.js +1 -1
  52. package/three/primitives/GpuTubes.d.ts +0 -2
  53. package/three/primitives/GpuTubes.js +1 -1
  54. package/three/RiaGeometryEngine.d.ts +0 -48
  55. package/three/RiaGeometryEngine.js +0 -1
@@ -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 d}from"three/webgpu";import{Fn as o,ivec2 as l,positionGeometry as c,screenCoordinate as u,textureLoad as m,vec4 as g}from"three/tsl";import{GeometryEngine as b}from"../engine/GeometryEngine.js";import{Sky as p}from"./Sky.js";import{disposeMaterial as w,nodeMaterial as f,rawColor as y,unculled as z}from"./Tsl.js";export class CanvasGeometryEngine extends b{constructor(e={}){super(),this.options=e,this.baseScene=new r,this.sky=new p,this.blitScene=new r,this.blit=null,this.camera3d=null,this.scheduled=0,this.animators=new Set,this.size={width:1,height:1,ratio:1},this.background=y("#0b0d10"),this.initialising=null,this.drewBase=!1,this.bufferSize=new n,this.baseDrawn=!1,this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.width="100%",this.canvas.style.height="100%",this.canvas.style.touchAction="none",e.background&&y(e.background,this.background),this.baseScene.add(this.sky.mesh)}createDepthTexture(){const i=new e(1,1,t);return i.minFilter=s,i.magFilter=s,this.baseTarget=new h(1,1,{depthBuffer:!0,generateMipmaps:!1}),this.baseTarget.depthTexture=i,i}init(){return this.initialising??(this.initialising=this.start()),this.initialising}async start(){const e=new d({canvas:this.canvas,antialias:!1!==this.options.antialias,alpha:!1,forceWebGL:!!this.options.forceWebGL});e.setPixelRatio(1),e.info.autoReset=!1,this.adoptRenderer(e),await e.init(),this.disposed||(this.blit=z(new i(new a(2,2),this.blitMaterial())),this.blitScene.add(this.blit),this.ready=!0,this.emit("ready"),this.requestRepaint())}setCamera(e){this.camera3d=e,this.requestRepaint()}setBackground(e){y(e,this.background),this.requestRepaint()}setSize(e,t,i=window.devicePixelRatio||1){const s=Math.min(i,this.options.maxPixelRatio??2);this.size={width:Math.max(1,e),height:Math.max(1,t),ratio:s},this.requestRepaint()}get frameSize(){return{width:Math.max(1,Math.round(this.size.width*this.size.ratio)),height:Math.max(1,Math.round(this.size.height*this.size.ratio))}}get viewSize(){return{width:this.size.width,height:this.size.height,pixelRatio:this.size.ratio}}setAnimating(e,t){t?this.animators.add(e):this.animators.delete(e),t&&this.requestRepaint()}requestRepaint(){this.scheduled||this.disposed||(this.scheduled=requestAnimationFrame(()=>{this.scheduled=0,this.draw(),this.animators.size>0&&this.requestRepaint()}))}draw(){const e=this.renderer;if(!this.ready||!e||!this.camera3d)return;const{width:t,height:i}=this.frameSize,s=e.getDrawingBufferSize(this.bufferSize);s.x===t&&s.y===i||e.setSize(t,i,!1),e.info.reset();const a={...this.camera3d(t,i),width:t,height:i,pixelRatio:this.size.ratio,glDepth:!0},h=this.baseScene.children.some(e=>e.visible);!h||this.baseTarget.width===t&&this.baseTarget.height===i||this.baseTarget.setSize(t,i),this.drewBase=!1;this.renderFrame(a,()=>(this.drawBase(h,e),!0))||this.drawBase(h,e)}drawBase(e,t){if(this.drewBase)return;this.drewBase=!0,t.setClearColor(this.background,1),this.sky.eye.value.copy(this.frame.eye),this.sky.mesh.visible=!this.frame.orthographic,e&&(t.setRenderTarget(this.baseTarget),t.clear(!0,!0,!0),t.render(this.baseScene,this.camera)),t.setRenderTarget(null);const i=t.backend;!this.webgpu&&i?.gl&&i.state?.bindFramebuffer&&i.state.bindFramebuffer(i.gl.FRAMEBUFFER,null),t.clear(!0,!0,!0),e&&this.blit&&t.render(this.blitScene,this.camera),this.baseDrawn=e}depthReady(){return!this.frame.orthographic}dispose(){this.scheduled&&cancelAnimationFrame(this.scheduled),this.scheduled=0,this.animators.clear(),this.baseTarget.dispose(),this.blit&&(this.blit.geometry.dispose(),w(this.blit)),this.sky.dispose(),super.dispose(),this.canvas.remove()}blitMaterial(){const e=f();e.depthTest=!1,e.depthWrite=!1;const t=this.baseTarget.texture;return e.vertexNode=o(()=>g(c.xy,0,1))(),e.fragmentNode=o(()=>m(t,l(u.xy)))(),e}get hasBase(){return this.baseDrawn}}
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)}
package/three/Ground.d.ts CHANGED
@@ -45,6 +45,11 @@ export declare class Ground {
45
45
  eye?: N;
46
46
  fog?: N;
47
47
  });
48
+ /** The ground's colour and its grid's, as CSS colours: a view's theme, changed while it is drawn. */
49
+ setColors(colors: {
50
+ color?: string;
51
+ grid?: string;
52
+ }): void;
48
53
  /** Tells the ground the picture changed (a canvas drawn again). */
49
54
  refresh(): void;
50
55
  /** Fog for a camera this far from what it looks at. */
package/three/Ground.js CHANGED
@@ -1 +1 @@
1
- import{CanvasTexture as t,ClampToEdgeWrapping as e,LinearFilter as i,LinearMipmapLinearFilter as s,Mesh as r,NoColorSpace as o,PlaneGeometry as h,TextureLoader as a,Vector3 as u}from"three/webgpu";import{abs as l,clamp as n,float as d,Fn as g,fract as c,fwidth as m,length as p,max as f,min as x,mix as y,positionLocal as v,smoothstep as w,texture as b,uniform as C,vec2 as O,vec4 as F}from"three/tsl";import{disposeMaterial as M,nodeMaterial as N,rawColor as j}from"./Tsl.js";export class Ground{constructor(l,n,d){this.options=l,this.texture=null,this.color=C(j("#14181d")),this.gridColor=C(new u(1,1,1)),this.gridOpacity=C(.06),this.fogNear=C(1500),this.fogFar=C(9e3),this.offset=C(new u);const[g,c,m,p]=l.bounds,f=Math.max(1,m-g),x=Math.max(1,p-c);if(this.eye=d?.eye??C(new u),this.fogColor=d?.fog??C(j("#18222f")),l.color&&j(l.color,this.color.value),l.grid&&l.grid.color){const t=j(l.grid.color);this.gridColor.value.set(t.r,t.g,t.b)}l.grid&&void 0!==l.grid.opacity&&(this.gridOpacity.value=l.grid.opacity),l.image&&(this.texture="string"==typeof l.image?(new a).load(l.image):new t(l.image),this.texture.colorSpace=o,this.texture.wrapS=this.texture.wrapT=e,this.texture.minFilter=s,this.texture.magFilter=i,this.texture.anisotropy=8),this.offset.value.set((g+m)/2-n[0],(c+p)/2-n[1],(l.z??0)-(n[2]??0));const y=l.margin??Math.max(2e4,8*Math.max(f,x)),v=[f+2*y,x+2*y];this.mesh=new r(new h(v[0],v[1]),this.material(f,x,v[0],v[1])),this.mesh.position.copy(this.offset.value),this.mesh.frustumCulled=!1,this.mesh.renderOrder=-1e3}refresh(){this.texture&&(this.texture.needsUpdate=!0)}setViewDistance(t){this.fogNear.value=1.4*t+600,this.fogFar.value=7*t+4e3}dispose(){this.mesh.geometry.dispose(),M(this.mesh),this.texture?.dispose()}material(t,e,i,s){const r=N();r.transparent=!0,r.depthWrite=!0;const o=this.options,h=o.grid,a=this.texture;return r.colorNode=g(()=>{const r=v.xy;let u=this.color;if(a){const i=r.div(O(t,e)).add(.5),s=x(x(i.x,d(1).sub(i.x)),x(i.y,d(1).sub(i.y))),h=w(0,.03,s),l=b(a,n(i,0,1));u=y(u,l.xyz,l.w.mul(o.imageOpacity??1).mul(h))}if(h){const t=t=>{const e=r.div(t),i=l(c(e.sub(.5)).sub(.5)).div(m(e));return d(1).sub(x(x(i.x,i.y),d(1)))},e=t(h.spacing),i=t(h.spacing*(h.major??10)),s=f(e.mul(this.gridOpacity),i.mul(this.gridOpacity.mul(2.2)));u=y(u,this.gridColor,n(s,0,1))}const g=p(v.add(this.offset).sub(this.eye));u=y(u,this.fogColor,w(this.fogNear,this.fogFar,g));const C=O(i/2,s/2),M=C.sub(l(r)),N=w(0,1,x(M.x.div(C.x),M.y.div(C.y)).mul(8));return F(u,n(N,0,1))})(),r}}
1
+ import{CanvasTexture as t,ClampToEdgeWrapping as e,LinearFilter as i,LinearMipmapLinearFilter as s,Mesh as r,NoColorSpace as o,PlaneGeometry as h,TextureLoader as a,Vector3 as l}from"three/webgpu";import{abs as u,clamp as d,float as g,Fn as n,fract as c,fwidth as m,length as p,max as f,min as x,mix as y,positionLocal as v,smoothstep as w,texture as b,uniform as C,vec2 as O,vec4 as F}from"three/tsl";import{disposeMaterial as M,nodeMaterial as N,rawColor as j}from"./Tsl.js";export class Ground{constructor(u,d,g){this.options=u,this.texture=null,this.color=C(j("#14181d")),this.gridColor=C(new l(1,1,1)),this.gridOpacity=C(.06),this.fogNear=C(1500),this.fogFar=C(9e3),this.offset=C(new l);const[n,c,m,p]=u.bounds,f=Math.max(1,m-n),x=Math.max(1,p-c);if(this.eye=g?.eye??C(new l),this.fogColor=g?.fog??C(j("#18222f")),u.color&&j(u.color,this.color.value),u.grid&&u.grid.color){const t=j(u.grid.color);this.gridColor.value.set(t.r,t.g,t.b)}u.grid&&void 0!==u.grid.opacity&&(this.gridOpacity.value=u.grid.opacity),u.image&&(this.texture="string"==typeof u.image?(new a).load(u.image):new t(u.image),this.texture.colorSpace=o,this.texture.wrapS=this.texture.wrapT=e,this.texture.minFilter=s,this.texture.magFilter=i,this.texture.anisotropy=8),this.offset.value.set((n+m)/2-d[0],(c+p)/2-d[1],(u.z??0)-(d[2]??0));const y=u.margin??Math.max(2e4,8*Math.max(f,x)),v=[f+2*y,x+2*y];this.mesh=new r(new h(v[0],v[1]),this.material(f,x,v[0],v[1])),this.mesh.position.copy(this.offset.value),this.mesh.frustumCulled=!1,this.mesh.renderOrder=-1e3}setColors(t){if(t.color&&j(t.color,this.color.value),t.grid){const e=j(t.grid);this.gridColor.value.set(e.r,e.g,e.b)}}refresh(){this.texture&&(this.texture.needsUpdate=!0)}setViewDistance(t){this.fogNear.value=1.4*t+600,this.fogFar.value=7*t+4e3}dispose(){this.mesh.geometry.dispose(),M(this.mesh),this.texture?.dispose()}material(t,e,i,s){const r=N();r.transparent=!0,r.depthWrite=!0;const o=this.options,h=o.grid,a=this.texture;return r.colorNode=n(()=>{const r=v.xy;let l=this.color;if(a){const i=r.div(O(t,e)).add(.5),s=x(x(i.x,g(1).sub(i.x)),x(i.y,g(1).sub(i.y))),h=w(0,.03,s),u=b(a,d(i,0,1));l=y(l,u.xyz,u.w.mul(o.imageOpacity??1).mul(h))}if(h){const t=t=>{const e=r.div(t),i=u(c(e.sub(.5)).sub(.5)).div(m(e));return g(1).sub(x(x(i.x,i.y),g(1)))},e=t(h.spacing),i=t(h.spacing*(h.major??10)),s=f(e.mul(this.gridOpacity),i.mul(this.gridOpacity.mul(2.2)));l=y(l,this.gridColor,d(s,0,1))}const n=p(v.add(this.offset).sub(this.eye));l=y(l,this.fogColor,w(this.fogNear,this.fogFar,n));const C=O(i/2,s/2),M=C.sub(u(r)),N=w(0,1,x(M.x.div(C.x),M.y.div(C.y)).mul(8));return F(l,d(N,0,1))})(),r}}
@@ -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}}
@@ -32,7 +32,7 @@ export type IconShapeName = Lowercase<keyof typeof IconShape>;
32
32
  export declare function iconShapeOf(name: IconShapeName | string): number;
33
33
  /** The cell that stands for the manhole cover, drawn rather than sampled. */
34
34
  export declare const COVER_CELL: -1;
35
- /** The manhole cover as the Ing+ map draws it: rim, fill, ring and its width and strength. */
35
+ /** The manhole cover: rim, fill, ring and its width and strength. */
36
36
  export declare const MANHOLE_COVER: {
37
37
  rim: number;
38
38
  fill: number;
@@ -61,7 +61,7 @@ export interface GpuIconsOptions {
61
61
  }
62
62
  /**
63
63
  * Icons and markers, every one an instanced quad, drawn after the lines so a line never covers
64
- * one: facing the screen at a size in world units (a metre on the map, the Ing+ map's manholes)
64
+ * one: facing the screen at a size in world units (a metre on the map, a manhole's)
65
65
  * or in pixels, or lying on the ground at their real size. Their picture from an atlas
66
66
  * (`iconAtlas`), or a shape drawn in the shader - the manhole cover, circles, rings, squares,
67
67
  * diamonds, triangles, hexagons, pins, crosses, stars - crisp however close. Their look is the
@@ -100,7 +100,7 @@ export declare class GpuIcons implements GeometryPrimitive {
100
100
  /**
101
101
  * How strongly icon `index` shows, 0 for not at all, whether it is selected, the colour it is
102
102
  * tinted with (straight RGB, 0 to 1), and whether it is in the set - shaded while something
103
- * else is lit (`othersShade`). The Ing+ map's way to style an icon.
103
+ * else is lit (`othersShade`).
104
104
  */
105
105
  setState(index: number, alpha: number, selected: boolean, tint?: number[], inSet?: boolean): void;
106
106
  /** Uploads what setState wrote. */
@@ -1 +1 @@
1
- import{DoubleSide as e,InstancedBufferAttribute as t,InstancedBufferGeometry as s,LessDepth as i,LessEqualDepth as o,Mesh as n,NoBlending as l,Vector3 as a}from"three/webgpu";import{abs as r,attribute as h,cameraProjectionMatrix as u,clamp as c,cross as m,dot as d,dFdx as p,dFdy as g,Discard as b,float as x,Fn as v,If as y,int as f,length as w,max as S,min as T,mix as k,normalize as I,positionGeometry as R,sign as C,smoothstep as M,texture as z,uniform as A,varyingProperty as E,vec2 as W,vec3 as L,vec4 as O,viewport as P}from"three/tsl";import{FeatureLook as F,FeatureState as D}from"../FeatureLook.js";import{additive as H,adoptGeometry as V,centredQuad as j,disposeMaterial as N,GONE as q,nodeMaterial as _,unculled as G}from"../Tsl.js";import{ICON_CELL as U}from"./IconAtlas.js";export const IconShape={Cover:-1,Circle:-2,Ring:-3,Square:-4,Diamond:-5,Triangle:-6,Hexagon:-7,Pin:-8,Cross:-9,Star:-10};export function iconShapeOf(e){const t=Object.keys(IconShape).find(t=>t.toLowerCase()===e.toLowerCase());return t?IconShape[t]:IconShape.Circle}export const COVER_CELL=IconShape.Cover;export const MANHOLE_COVER={rim:.8,fill:.5,ring:.55,ringWidth:.06,ringAlpha:.7};export class GpuIcons{constructor(e,i,o,l){this.size=o,this.pxPerWorld=A(1),this.pixelRatio=A(1),this.perspective=A(0),this.focal=A(1e3),this.outlineMode=A(0),this.rimRgb=A(new a(.92,.91,.88)),this.litScale=A(1.15),this.up=A(new a(0,0,1));const r=l&&"pass"in l?{pick:l}:l??{};if(this.options=r,r.up&&this.up.value.set(r.up[0],r.up[1],r.up[2]).normalize(),this.count=e.length,this.look=r.look??new F(e.length),!r.look){for(let t=0;t<e.length;t++)this.look.set(t,{color:J,state:D.Default});this.look.commit()}const h=new Float32Array(3*e.length),u=new Float32Array(2*e.length);e.forEach((e,t)=>{h[3*t]=e.x,h[3*t+1]=e.y,h[3*t+2]=e.z,u[2*t]=e.index??t,u[2*t+1]=e.cell});const c=j(new s);c.setAttribute("aCentre",new t(h,3)),c.setAttribute("aIcon",new t(u,2)),c.instanceCount=e.length,this.mesh=G(new n(c,this.material("solid",i)),3),this.pickMesh=r.pick?G(new n(c,this.material("pick",i)),3):null,this.bloomMesh=G(new n(c,this.material("bloom",i))),this.densityMesh=G(new n(c,this.material("density",i))),this.densityMesh.visible=!1}get othersShade(){return this.look.othersShade}get othersToward(){return this.look.othersToward}passes(){return{scene:[this.mesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){this.pxPerWorld.value=e.pxPerWorld,this.pixelRatio.value=e.pixelRatio,this.perspective.value=!1===e.orthographic?1:0,e.focal&&(this.focal.value=e.focal)}setState(e,t,s,i=B,o=!1){this.look.set(e,{color:[i[0],i[1],i[2],t],state:t<=0?D.Hidden:s?D.Selected:o?D.Default:D.Faded,weight:t,fadedWeight:t})}commit(){this.look.commit()}meshes(){return[this.mesh,this.bloomMesh,this.pickMesh,this.densityMesh]}adopt(e){return!!(e instanceof GpuIcons&&V(this.meshes(),e.meshes()))&&(this.count=e.count,!0)}dispose(){this.mesh.geometry.dispose(),this.meshes().forEach(N),this.options.look||this.look.dispose()}material(t,s){const n=this.options,a=n.pick,A="pick"===t,F="density"===t,D="bloom"===t,V="ground"===n.orientation,j=!!n.depth||V,N="pixels"===n.sizeUnit,G=n.anchor??[0,0],B=n.minPixels??0,J=n.border??1,K=_();K.transparent=!A,K.side=e,K.depthTest=A||j&&!F,K.depthWrite=A,K.depthFunc=A&&!j?i:o,A&&(K.blending=l),F&&H(K);const Q=this.look,X=E("vec2","vCorner"),Y=E("vec2","vScale"),Z=E("vec3","vIcon"),$=E("vec3","vTint"),ee=E("float","vIndex"),te=E("float","vDistance");return K.vertexNode=v(()=>{const e=h("aCentre","vec3"),t=h("aIcon","vec2"),s=f(t.x),i=Q.read(s),o=R.xy,n=u.mul(O(e,1)),l=A&&a?a.pass.frameSize:P.zw,r=i.width.greaterThan(0),c=r.and(i.meters).select(i.width,x(N?0:this.size)),d=r.and(i.meters.not()).select(i.width,x(N?this.size:0)),p=i.selected.and(x(D||F||A?0:1).greaterThan(.5)).select(this.litScale,x(1)),g=S(n.w,1e-6),b=this.perspective.greaterThan(.5).select(this.focal.div(g),this.pxPerWorld),v=S(S(c.mul(b),d.mul(this.pixelRatio)).mul(.5),this.pixelRatio.mul(B/2)).mul(p),T=x(A&&a?4:F?1:0),k=S(v,T.mul(this.pixelRatio)).add(1),C=k.div(S(v,1e-6));let M;X.assign(o.mul(C)),Y.assign(W(C,x(1).div(S(v,1e-6)).mul(this.pixelRatio))),Z.assign(L(t.y,i.alpha,i.selected.select(x(1),x(0)))),$.assign(i.rgb),ee.assign(t.x);let z=null;if(V){const t=I(m(L(0,0,1),this.up)).toVar();y(w(m(L(0,0,1),this.up)).lessThan(1e-4),()=>{t.assign(L(1,0,0))});const s=m(this.up,t),i=c.add(d.mul(g).div(this.focal)).mul(.5).mul(p),n=g.div(this.focal),l=(A?S(i,n.mul(this.pixelRatio).mul(4)):i).add(n),a=W(G[0],G[1]).mul(i).negate(),r=o.mul(l).add(a),h=e.add(t.mul(r.x)).add(s.mul(r.y));X.assign(o.mul(l.div(S(i,1e-6)))),Y.assign(W(l.div(S(i,1e-6)),n.mul(this.pixelRatio).div(S(i,1e-6))));const b=u.mul(O(h,1));te.assign(b.w),A||(z=i.mul(2).lessThan(n)),M=b}else{const e=o.mul(k).add(W(G[0],G[1]).mul(v).negate()).div(l).mul(2).mul(n.w);te.assign(n.w);const t=j?n.z:A?n.w.mul(.05):x(0);M=O(n.xy.add(e),t,n.w)}const E=D?i.alpha.lessThan(.001).or(i.selected.not()):i.alpha.lessThan(.001);return(z?E.or(z):E).select(q(),A&&a?a.pass.window.mul(M):M)})(),K.fragmentNode=v(()=>{const e=X,t=Z.x,i=w(e),o=S(w(W(p(i),g(i))).mul(.5),1e-4).toVar(),n=function(e,t){const s=w(t),i=s.sub(1),o=r(s.sub(.72)).sub(.28),n=S(r(t.x),r(t.y)).sub(.86),l=r(t.x).add(r(t.y)).sub(1).mul(.7071),a=S(r(t.x).mul(.866).add(t.y.mul(.5)).sub(.5),t.y.negate().sub(.75)),h=S(r(t.x).mul(.866).add(r(t.y).mul(.5)),r(t.y)).sub(.9),u=w(t.sub(W(0,.28))).sub(.68),m=S(r(t.x).mul(.94).add(t.y.mul(.34)).sub(.2),t.y.negate().sub(1)),p=S(T(u,m),x(.24).sub(w(t.sub(W(0,.3))))),g=T(S(r(t.x).sub(.28),r(t.y).sub(.95)),S(r(t.y).sub(.28),r(t.x).sub(.95))),b=(t,s,i)=>r(e.sub(t)).lessThan(.5).select(s,i);let v=i;return v=b(IconShape.Ring,o,v),v=b(IconShape.Square,n,v),v=b(IconShape.Diamond,l,v),v=b(IconShape.Triangle,a,v),v=b(IconShape.Hexagon,h,v),v=b(IconShape.Pin,p,v),v=b(IconShape.Cross,g,v),v=b(IconShape.Star,function(e){const t=W(.809016994375,-.587785252292),s=W(-.809016994375,-.587785252292);let i=W(r(e.x),e.y);i=i.sub(t.mul(S(d(t,i),0).mul(2))),i=i.sub(s.mul(S(d(s,i),0).mul(2))),i=W(r(i.x),i.y.sub(1));const o=W(.26450336353139997,-.63594235253125),n=c(d(i,o).div(d(o,o)),0,1);return w(i.sub(o.mul(n))).mul(C(i.y.mul(o.x).sub(i.x.mul(o.y))))}(t),v),v}(t,e),l=x(1).sub(M(o.negate(),o,n));if(A&&a){const s=Y.x,i=t.greaterThanEqual(0).select(S(r(e.x),r(e.y)).greaterThan(s),n.greaterThan(s.sub(1)));return y(i,()=>{b()}),O(x(a.source),ee,j?te:x(.05),1)}if(F){const t=c(x(1).sub(w(e.div(Y.x))),0,1),s=Z.y.mul(t);return y(s.lessThan(.001),()=>{b()}),O(s,0,0,1)}const h=Z.z.greaterThan(.5),u=e=>x(1).sub(M(x(e).sub(o),x(e).add(o),i)),{rim:m,fill:v,ring:f,ringWidth:I,ringAlpha:R}=MANHOLE_COVER,E=u(f+I/2).sub(u(f-I/2)),P=k(x(v),x(1),E.mul(R)),H=$.mul(k(x(1),P,u(m))),V=Y.y.mul(J),N=x(1).sub(M(o.negate(),o,n.add(V))),q=k($.mul(.35),$,J>0?N:x(1)),_=t.lessThan(-.5).and(t.greaterThan(-1.5));let G=_.select(H,q),B=l;if(s){const i=s.image.width/U,n=c(e.mul(.5).add(.5),.5/U,1-.5/U),l=z(s,W(S(t,0).add(n.x).div(i),x(1).sub(n.y))).level(x(0)),a=x(1).sub(M(x(1).sub(o),x(1).add(o),S(r(e.x),r(e.y)))),h=t.greaterThan(-.5);G=h.select(l.xyz.mul($),G),B=h.select(l.w.mul(a),B)}const K=B.mul(Z.y);if(y(K.lessThan(.004),()=>{b()}),D)return O(G,B);const Q=M(V.negate().mul(2.5),V.negate().mul(.5),n),se=_.select(k(this.rimRgb,G,u(m)),k(G,this.rimRgb,Q)),ie=this.outlineMode.greaterThan(.5).select(se,k(G,L(1,1,1),.3));return O(h.select(ie,G),K)})(),K}}const B=[1,1,1],J=[1,1,1,1];
1
+ import{DoubleSide as e,InstancedBufferAttribute as t,InstancedBufferGeometry as s,LessDepth as i,LessEqualDepth as o,Mesh as n,NoBlending as l,Vector3 as a}from"three/webgpu";import{abs as r,attribute as h,cameraProjectionMatrix as u,clamp as c,cross as m,dot as d,dFdx as p,dFdy as g,Discard as b,float as x,Fn as v,If as y,int as f,length as w,max as S,min as T,mix as k,normalize as I,positionGeometry as R,sign as C,smoothstep as M,texture as z,uniform as A,varyingProperty as E,vec2 as W,vec3 as L,vec4 as O,viewport as P}from"three/tsl";import{FeatureLook as F,FeatureState as D}from"../FeatureLook.js";import{additive as H,adoptGeometry as V,centredQuad as j,disposeMaterial as N,GONE as q,nodeMaterial as _,unculled as G}from"../Tsl.js";import{ICON_CELL as U}from"./IconAtlas.js";export const IconShape={Cover:-1,Circle:-2,Ring:-3,Square:-4,Diamond:-5,Triangle:-6,Hexagon:-7,Pin:-8,Cross:-9,Star:-10};export function iconShapeOf(e){const t=Object.keys(IconShape).find(t=>t.toLowerCase()===e.toLowerCase());return t?IconShape[t]:IconShape.Circle}export const COVER_CELL=IconShape.Cover;export const MANHOLE_COVER={rim:.8,fill:.5,ring:.55,ringWidth:.06,ringAlpha:.7};export class GpuIcons{constructor(e,i,o,l){this.size=o,this.pxPerWorld=A(1),this.pixelRatio=A(1),this.perspective=A(0),this.focal=A(1e3),this.outlineMode=A(0),this.rimRgb=A(new a(.92,.91,.88)),this.litScale=A(1.15),this.up=A(new a(0,0,1));const r=l&&"pass"in l?{pick:l}:l??{};if(this.options=r,r.up&&this.up.value.set(r.up[0],r.up[1],r.up[2]).normalize(),this.count=e.length,this.look=r.look??new F(e.length),!r.look){for(let t=0;t<e.length;t++)this.look.set(t,{color:J,state:D.Default});this.look.commit()}const h=new Float32Array(3*e.length),u=new Float32Array(2*e.length);e.forEach((e,t)=>{h[3*t]=e.x,h[3*t+1]=e.y,h[3*t+2]=e.z,u[2*t]=e.index??t,u[2*t+1]=e.cell});const c=j(new s);c.setAttribute("aCentre",new t(h,3)),c.setAttribute("aIcon",new t(u,2)),c.instanceCount=e.length,this.mesh=G(new n(c,this.material("solid",i)),3),this.pickMesh=r.pick?G(new n(c,this.material("pick",i)),3):null,this.bloomMesh=G(new n(c,this.material("bloom",i))),this.densityMesh=G(new n(c,this.material("density",i))),this.densityMesh.visible=!1}get othersShade(){return this.look.othersShade}get othersToward(){return this.look.othersToward}passes(){return{scene:[this.mesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){this.pxPerWorld.value=e.pxPerWorld,this.pixelRatio.value=e.pixelRatio,this.perspective.value=!1===e.orthographic?1:0,e.focal&&(this.focal.value=e.focal)}setState(e,t,s,i=B,o=!1){this.look.set(e,{color:[i[0],i[1],i[2],t],state:t<=0?D.Hidden:s?D.Selected:o?D.Default:D.Faded,weight:t,fadedWeight:t})}commit(){this.look.commit()}meshes(){return[this.mesh,this.bloomMesh,this.pickMesh,this.densityMesh]}adopt(e){return!!(e instanceof GpuIcons&&V(this.meshes(),e.meshes()))&&(this.count=e.count,!0)}dispose(){this.mesh.geometry.dispose(),this.meshes().forEach(N),this.options.look||this.look.dispose()}material(t,s){const n=this.options,a=n.pick,A="pick"===t,F="density"===t,D="bloom"===t,V="ground"===n.orientation,j=!!n.depth||V,N="pixels"===n.sizeUnit,G=n.anchor??[0,0],B=n.minPixels??0,J=n.border??1,K=_();K.transparent=!A,K.side=e,K.depthTest=A||j&&!F,K.depthWrite=A,K.depthFunc=A&&!j?i:o,A&&(K.blending=l),F&&H(K);const Q=this.look,X=E("vec2","vCorner"),Y=E("vec2","vScale"),Z=E("vec3","vIcon"),$=E("vec3","vTint"),ee=E("float","vIndex"),te=E("float","vDistance");return K.vertexNode=v(()=>{const e=h("aCentre","vec3"),t=h("aIcon","vec2"),s=f(t.x),i=Q.read(s),o=R.xy,n=u.mul(O(e,1)),l=A&&a?a.pass.frameSize:P.zw,r=i.width.greaterThan(0),c=r.and(i.meters).select(i.width,x(N?0:this.size)),d=r.and(i.meters.not()).select(i.width,x(N?this.size:0)),p=i.selected.and(x(D||F||A?0:1).greaterThan(.5)).select(this.litScale,x(1)),g=S(n.w,1e-6),b=this.perspective.greaterThan(.5).select(this.focal.div(g),this.pxPerWorld),v=S(S(c.mul(b),d.mul(this.pixelRatio)).mul(.5),this.pixelRatio.mul(B/2)).mul(p),T=x(A&&a?4:F?1:0),k=S(v,T.mul(this.pixelRatio)).add(1),C=k.div(S(v,1e-6));let M;X.assign(o.mul(C)),Y.assign(W(C,x(1).div(S(v,1e-6)).mul(this.pixelRatio))),Z.assign(L(t.y,i.alpha,i.selected.select(x(1),x(0)))),$.assign(i.rgb),ee.assign(t.x);let z=null;if(V){const t=I(m(L(0,0,1),this.up)).toVar();y(w(m(L(0,0,1),this.up)).lessThan(1e-4),()=>{t.assign(L(1,0,0))});const s=m(this.up,t),i=c.add(d.mul(g).div(this.focal)).mul(.5).mul(p),n=g.div(this.focal),l=(A?S(i,n.mul(this.pixelRatio).mul(4)):i).add(n),a=W(G[0],G[1]).mul(i).negate(),r=o.mul(l).add(a),h=e.add(t.mul(r.x)).add(s.mul(r.y));X.assign(o.mul(l.div(S(i,1e-6)))),Y.assign(W(l.div(S(i,1e-6)),n.mul(this.pixelRatio).div(S(i,1e-6))));const b=u.mul(O(h,1));te.assign(b.w),A||(z=i.mul(2).lessThan(n)),M=b}else{const e=o.mul(k).add(W(G[0],G[1]).mul(v).negate()).div(l).mul(2).mul(n.w);te.assign(n.w);const t=j?n.z:A?n.w.mul(.05):x(0);M=O(n.xy.add(e),t,n.w)}const E=(D?i.alpha.lessThan(.001).or(i.selected.not()):i.alpha.lessThan(.001)).or(A?i.pickable.not():x(0).greaterThan(1));return(z?E.or(z):E).select(q(),A&&a?a.pass.window.mul(M):M)})(),K.fragmentNode=v(()=>{const e=X,t=Z.x,i=w(e),o=S(w(W(p(i),g(i))).mul(.5),1e-4).toVar(),n=function(e,t){const s=w(t),i=s.sub(1),o=r(s.sub(.72)).sub(.28),n=S(r(t.x),r(t.y)).sub(.86),l=r(t.x).add(r(t.y)).sub(1).mul(.7071),a=S(r(t.x).mul(.866).add(t.y.mul(.5)).sub(.5),t.y.negate().sub(.75)),h=S(r(t.x).mul(.866).add(r(t.y).mul(.5)),r(t.y)).sub(.9),u=w(t.sub(W(0,.28))).sub(.68),m=S(r(t.x).mul(.94).add(t.y.mul(.34)).sub(.2),t.y.negate().sub(1)),p=S(T(u,m),x(.24).sub(w(t.sub(W(0,.3))))),g=T(S(r(t.x).sub(.28),r(t.y).sub(.95)),S(r(t.y).sub(.28),r(t.x).sub(.95))),b=(t,s,i)=>r(e.sub(t)).lessThan(.5).select(s,i);let v=i;return v=b(IconShape.Ring,o,v),v=b(IconShape.Square,n,v),v=b(IconShape.Diamond,l,v),v=b(IconShape.Triangle,a,v),v=b(IconShape.Hexagon,h,v),v=b(IconShape.Pin,p,v),v=b(IconShape.Cross,g,v),v=b(IconShape.Star,function(e){const t=W(.809016994375,-.587785252292),s=W(-.809016994375,-.587785252292);let i=W(r(e.x),e.y);i=i.sub(t.mul(S(d(t,i),0).mul(2))),i=i.sub(s.mul(S(d(s,i),0).mul(2))),i=W(r(i.x),i.y.sub(1));const o=W(.26450336353139997,-.63594235253125),n=c(d(i,o).div(d(o,o)),0,1);return w(i.sub(o.mul(n))).mul(C(i.y.mul(o.x).sub(i.x.mul(o.y))))}(t),v),v}(t,e),l=x(1).sub(M(o.negate(),o,n));if(A&&a){const s=Y.x,i=t.greaterThanEqual(0).select(S(r(e.x),r(e.y)).greaterThan(s),n.greaterThan(s.sub(1)));return y(i,()=>{b()}),O(x(a.source),ee,j?te:x(.05),1)}if(F){const t=c(x(1).sub(w(e.div(Y.x))),0,1),s=Z.y.mul(t);return y(s.lessThan(.001),()=>{b()}),O(s,0,0,1)}const h=Z.z.greaterThan(.5),u=e=>x(1).sub(M(x(e).sub(o),x(e).add(o),i)),{rim:m,fill:v,ring:f,ringWidth:I,ringAlpha:R}=MANHOLE_COVER,E=u(f+I/2).sub(u(f-I/2)),P=k(x(v),x(1),E.mul(R)),H=$.mul(k(x(1),P,u(m))),V=Y.y.mul(J),N=x(1).sub(M(o.negate(),o,n.add(V))),q=k($.mul(.35),$,J>0?N:x(1)),_=t.lessThan(-.5).and(t.greaterThan(-1.5));let G=_.select(H,q),B=l;if(s){const i=s.image.width/U,n=c(e.mul(.5).add(.5),.5/U,1-.5/U),l=z(s,W(S(t,0).add(n.x).div(i),x(1).sub(n.y))).level(x(0)),a=x(1).sub(M(x(1).sub(o),x(1).add(o),S(r(e.x),r(e.y)))),h=t.greaterThan(-.5);G=h.select(l.xyz.mul($),G),B=h.select(l.w.mul(a),B)}const K=B.mul(Z.y);if(y(K.lessThan(.004),()=>{b()}),D)return O(G,K);const Q=M(V.negate().mul(2.5),V.negate().mul(.5),n),se=_.select(k(this.rimRgb,G,u(m)),k(G,this.rimRgb,Q)),ie=this.outlineMode.greaterThan(.5).select(se,k(G,L(1,1,1),.3));return O(h.select(ie,G),K)})(),K}}const B=[1,1,1],J=[1,1,1,1];
@@ -3,7 +3,7 @@ import { GeometryFrame, GeometryOccluder, GeometryPasses, GeometryPrimitive, Pic
3
3
  import { FeatureLook, FeatureState } from '../FeatureLook';
4
4
  /** The outline look's white (#EBE8E0), as the shader takes it. */
5
5
  export declare const OUTLINE_RGB: [number, number, number];
6
- /** How one feature's line is drawn: the Ing+ map's style, written into the shared look. */
6
+ /** How one feature's line is drawn, written into the shared look. */
7
7
  export interface LineFeatureStyle {
8
8
  /** Straight (not premultiplied) RGBA, 0..1. */
9
9
  color: [number, number, number, number];
@@ -19,7 +19,7 @@ export interface LineFeatureStyle {
19
19
  /** Other `LookFlag` bits: dashed, flowing, no arrow. */
20
20
  flags?: number;
21
21
  }
22
- /** The Ing+ map's name for a feature's state. */
22
+ /** A feature's state, by the name the lines take it under. */
23
23
  export declare const LineState: typeof FeatureState;
24
24
  export type LineState = FeatureState;
25
25
  /** A polyline in the engine's origin-relative world coordinates. */
@@ -1 +1 @@
1
- import{DoubleSide as e,InstancedBufferAttribute as t,InstancedBufferGeometry as s,LessDepth as a,LessEqualDepth as r,Mesh as l,NoBlending as o,Vector2 as i,Vector3 as n}from"three/webgpu";import{abs as h,attribute as u,cameraProjectionMatrix as d,clamp as c,cross as m,dFdx as g,dFdy as w,Discard as p,float as T,Fn as b,fract as f,If as v,int as x,length as y,max as V,min as M,mix as S,normalize as k,positionGeometry as E,screenCoordinate as W,smoothstep as z,uniform as R,varyingProperty as A,vec2 as L,vec3 as q,vec4 as H,viewport as C}from"three/tsl";import{FeatureLook as F,FeatureState as N,hasFlag as _,LookFlag as G}from"../FeatureLook.js";import{additive as I,adoptGeometry as O,disposeMaterial as P,GONE as D,nodeMaterial as Q,segmentQuad as U,unculled as j}from"../Tsl.js";export const OUTLINE_RGB=[235/255,232/255,224/255];export const LineState=N;export const ARROW_LENGTH=16;export const ARROW_MIN_HALF_HEIGHT=3;export const ARROW_OUTLINE=1.5;export class GpuLines{constructor(e,a={}){this.options=a,this.pickMesh=null,this.featureCount=R(1),this.pxPerWorld=R(1),this.pixelRatio=R(1),this.rank=R(0),this.glowMode=R(1),this.outlineRgb=R(new n(...OUTLINE_RGB)),this.outlineWidth=R(2),this.glowWidth=R(6),this.focal=R(1e3),this.near=R(.3),this.worldPerMetre=R(1),this.endsShown=R(1),this.dash=R(new i(10,6)),this.flowSpacing=R(48),this.flowSpeed=R(60),this.time=R(0),this.up=R(new n(0,0,1)),a.ground&&this.up.value.set(a.ground.up[0],a.ground.up[1],a.ground.up[2]).normalize();const r=e.length;this.look=a.look??new F(r,{failLooks:!0}),this.featureCount.value=Math.max(1,r);let o=0;for(const t of e)for(const e of t)o+=Math.max(0,e.length-1);this.segments=o;const h=new Float32Array(3*o),u=new Float32Array(3*o),d=new Float32Array(4*o),c=new Float32Array(2*o),m=a.ends;let g=0;e.forEach((e,t)=>e.forEach(s=>{let a=0;for(let e=1;e<s.length;e++)a+=J(s[e-1],s[e]);let r=0;for(let l=1;l<s.length;l++){const o=s[l-1],i=s[l],n=J(o,i);h[3*g]=o.x,h[3*g+1]=o.y,h[3*g+2]=o.z,u[3*g]=i.x,u[3*g+1]=i.y,u[3*g+2]=i.z,d[4*g]=t,d[4*g+1]=r,d[4*g+2]=r+n,d[4*g+3]=a,m&&1===e.length&&(c[2*g]=m[2*t]||0,c[2*g+1]=m[2*t+1]||0),r+=n,g++}}));const w=U(new s);w.setAttribute("segStart",new t(h,3)),w.setAttribute("segEnd",new t(u,3)),w.setAttribute("segMeta",new t(d,4)),w.setAttribute("segTrim",new t(c,2)),w.instanceCount=o,this.mesh=j(new l(w,this.createMaterial(r,"core"))),this.fringeMesh=j(new l(w,this.createMaterial(r,"fringe")),1),this.bloomMesh=j(new l(w,this.createMaterial(r,"bloom"))),this.casingMesh=j(new l(w,this.createMaterial(r,"casing")),-1),this.casingMesh.visible=!1,a.pick&&(this.pickMesh=j(new l(w,this.createMaterial(r,"pick")))),this.densityMesh=j(new l(w,this.createMaterial(r,"density"))),this.densityMesh.visible=!1}get dragActive(){return this.look.rangeActive}get dragLow(){return this.look.rangeLow}get dragHigh(){return this.look.rangeHigh}get othersShade(){return this.look.othersShade}get othersToward(){return this.look.othersToward}passes(){return{scene:[this.casingMesh,this.mesh,this.fringeMesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){this.pxPerWorld.value=e.pxPerWorld,this.pixelRatio.value=e.pixelRatio,this.near.value=e.near,e.focal&&(this.focal.value=e.focal),void 0!==e.time&&(this.time.value=e.time)}setStyle(e,t){this.look.set(e,{color:t.color,width:t.width,flags:(t.flags??0)&~G.Meters,meters:t.meters,state:t.state,realWidth:t.realWidth,weight:t.color[3],fadedWeight:t.color[3]})}commit(){this.look.commit()}setDragStyle(e,t,s,a){this.look.setFail(e,{color:t.color,width:t.width,meters:t.meters,state:t.state,realWidth:t.realWidth,flags:t.flags}),this.look.setValue(e,s,a)}commitDrag(){this.look.commit()}meshes(){return[this.mesh,this.fringeMesh,this.bloomMesh,this.casingMesh,this.pickMesh,this.densityMesh]}adopt(e){return!!(e instanceof GpuLines&&O(this.meshes(),e.meshes()))&&(this.segments=e.segments,this.featureCount.value=e.featureCount.value,!0)}dispose(){this.mesh.geometry.dispose(),this.meshes().forEach(P),this.options.look||this.look.dispose()}createMaterial(t,s){const l="bloom"===s,i="casing"===s,n="pick"===s,d="density"===s,m=this.options.pick,k=!!this.options.ground,E=!k&&!!this.options.space,R=!1!==this.options.arrows,F=k||E?this.options.occluder:null,N=Q();N.transparent=!n,n&&(N.blending=o),N.side=e,N.depthTest=!0,N.depthWrite="fringe"!==s,N.depthFunc="fringe"===s||i||E?r:a,d&&I(N);const O=this.look,{rank:P,glowMode:U}=this,j=l||i,B=this.featureCount,J=A("vec2","vLocal"),K=A("float","vW"),X=A("vec4","vSegment"),Y=A("vec4","vColor"),Z=A("vec4","vExtra"),$=A("float","vDistance"),ee=A("float","vIndex"),te=A("vec3","vCut"),se=A("vec2","vJoin"),ae=A("vec3","vAlong");return N.vertexNode=b(()=>{const e=u("segStart","vec3"),t=u("segEnd","vec3"),s=u("segMeta","vec4"),a=x(s.x),r=O.read(a),o=r.state,h=r.selected,c=h.and(U.greaterThan(.5)).and(T(l||d?0:1).greaterThan(.5)),g=R?_(r.flags,G.NoArrow):T(1).greaterThan(0),w=u("segTrim","vec2").mul(this.endsShown),p=n?4:0,b=k?this.groundQuad(e,t,s,w,r.width,r.meters,r.realWidth,c,p,g):this.screenQuad(e,t,s,w,r.width,r.meters,r.realWidth,c,n&&m?m.pass.frameSize:C.zw,p,d,g,E);te.assign(q(w.x.greaterThan(0).select(b.cutStart,T(-1e9)),w.y.greaterThan(0).select(b.cutEnd,T(1e9)),b.arrowHalf)),J.assign(b.local.mul(b.w)),K.assign(b.w),X.assign(H(b.segLength,b.halfWidth,b.arrowCentre,b.arrowSize)),Y.assign(H(r.rgb,r.alpha));const f=s.y.lessThanEqual(0).select(this.endsShown,T(0)),v=s.z.greaterThanEqual(s.w).select(this.endsShown,T(0));Z.assign(H(b.glow,b.step,f,v)),se.assign(L(s.y.lessThanEqual(0).select(T(1),T(0)),s.z.greaterThanEqual(s.w).select(T(1),T(0)))),ee.assign(s.x),ae.assign(q(r.flags,b.alongStart,b.pixel));const y=T(.9).sub(o.mul(.25)).sub(P.mul(.04)).sub(s.x.div(B).mul(.03));$.assign(k||E?b.clip.w:y);const V=i?T(.24):y,M=o.lessThan(.5).or(T(j?1:0).greaterThan(.5).and(h.not())).or(d?r.weight.lessThan(.001):T(0).greaterThan(1)).or(b.gone).or(T(i&&(k||E)?1:0).greaterThan(.5)),S=b.clip,W=k||E?S:H(S.xy,V.mul(S.w),S.w);return M.select(D(),n&&m?m.pass.window.mul(W):W)})(),N.fragmentNode=b(()=>{const e=J.div(K).toVar(),t=e.x,a=e.y,r=X.x,l=X.y;if(n&&m){const e=y(L(t.sub(c(t,0,r)),a)).greaterThan(l).or(t.lessThan(te.x)).or(t.greaterThan(te.y)),s=F?e.or(F.hides($,W.xy.add(m.pass.origin))):e;return v(s.toVar(),()=>{p()}),H(T(m.source),ee,$,1)}const o=X.z,u=X.w,b=k?y(L(g(t),w(t))).mul(.5).toVar():T(.5),x=k?y(L(g(a),w(a))).mul(.5).toVar():T(.5);F&&v(F.hides($).toVar(),()=>{p()});const E=c(t,0,r),R=y(L(t.sub(E),a)).toVar(),A=Z.x,C=T(1).sub(Z.z.mul(z(b.negate(),b,t.negate()))),N=T(1).sub(Z.w.mul(z(b.negate(),b,t.sub(r)))),I=z(b.negate(),b,t.sub(te.x)).mul(z(b.negate(),b,te.y.sub(t))),O=C.mul(N).mul(I).toVar(),P=V(b,x).mul(2).toVar(),D=ae.y.add(t).div(V(ae.z,1e-6)).toVar(),Q=this.dash.x.add(this.dash.y).mul(this.pixelRatio),U=f(D.div(Q)).mul(Q),j=M(U,this.dash.x.mul(this.pixelRatio).sub(U)),B=_(ae.x,G.Dashed).select(c(j.add(.5),0,1),T(1)),re=T(1).sub(z(l.sub(x),l.add(x),R)).mul(O).mul(B).toVar();if(d){const e=t.greaterThanEqual(0).or(se.x.greaterThan(.5)).and(t.lessThan(r).or(se.y.greaterThan(.5))).select(Y.a.mul(re),T(0));return v(e.lessThan(.001),()=>{p()}),H(e,0,0,1)}const le=t.sub(o.sub(u.mul(.5))),oe=te.z.mul(T(1).sub(le.div(u))),ie=M(M(le,u.sub(le)),oe.sub(h(a))).toVar(),ne=t.greaterThanEqual(b.negate()).and(t.lessThanEqual(r.add(b))).select(T(1),T(0)),he=c(ie.div(P).add(.5),0,1).mul(ne).toVar(),ue=c(ie.div(P).add(this.pixelRatio.mul(1.5)).add(.5),0,1).mul(ne).toVar(),de=S(q(0,0,0),Y.rgb,he.div(V(ue,.001))),ce=V(re,ue).toVar(),me=A.greaterThan(0),ge=T(1).sub(z(l,l.add(A),R)),we=this.glowMode.greaterThan(1.5),pe=l.add(this.outlineWidth.mul(this.pixelRatio).mul(P)),Te=T(1).sub(z(pe.sub(P.mul(.5)),pe.add(P.mul(.5)),R)).mul(O);if(i)return v(Te.lessThan(.01),()=>{p()}),H(this.outlineRgb,Te);const be=me.select(we.select(T(0),ge.mul(ge).mul(.55)),T(0)),fe=V(ce,be),ve="fringe"===s?fe.lessThan(.01).or(fe.greaterThanEqual(.5)):"core"===s?fe.lessThan(.5):fe.lessThan(.01);v(ve,()=>{p()});const xe=ue.greaterThan(.01).select(de,Y.rgb).toVar(),ye=_(ae.x,G.Flow),Ve=this.flowSpacing.mul(this.pixelRatio),Me=f(D.sub(this.time.mul(this.flowSpeed).mul(this.pixelRatio)).div(Ve)),Se=ye.select(z(.55,.95,Me).mul(T(1).sub(z(.95,1,Me))),T(0)),ke=S(xe,q(1,1,1),Se.mul(.65)).toVar(),Ee=S(ke,q(1,1,1),S(T(.6),T(.4),ce)),We=me.select(we.select(ke,Ee),ke);return H(We,Y.a.mul(fe))})(),N}screenQuad(e,t,s,a,r,l,o,i,n,h=0,u=!1,m,g=!1){const{pxPerWorld:w,pixelRatio:p,worldPerMetre:b,focal:f}=this,x=d.mul(H(e,1)).toVar(),M=d.mul(H(t,1)).toVar(),k=this.near.mul(1.01);g&&(v(x.w.lessThan(k),()=>{x.assign(S(x,M,c(k.sub(x.w).div(M.w.sub(x.w)),0,1)))}),v(M.w.lessThan(k),()=>{M.assign(S(M,x,c(k.sub(M.w).div(x.w.sub(M.w)),0,1)))}));const W=x.xy.div(x.w).mul(.5).add(.5).mul(n).toVar(),z=M.xy.div(M.w).mul(.5).add(.5).mul(n).toVar().sub(W).toVar(),R=y(z).toVar(),A=R.greaterThan(1e-6).select(z.div(V(R,1e-6)),L(1,0)).toVar(),q=L(A.y.negate(),A.x).toVar(),C=E.y.greaterThan(.5),F=C.select(M.w,x.w).toVar(),N=g?f.div(V(F,1e-6)):w,_=l.select(r.mul(N),r.mul(p)).toVar(),G=V(V(_,o.mul(b).mul(N)),p.mul(2*h)).toVar(),I=G.mul(.5).toVar(),O=i.select(p.mul(this.glowWidth),T(0)).toVar(),{arrowHalf:P,arrowSize:D,step:Q,outline:U}=B(_,p),j=V(s.z.sub(s.y),1e-6),J=g?R.div(j):w.toVar(),K=s.w.mul(J),X=s.w.mul(.5),Y=D.mul(.5).add(Q).add(G).div(J),Z=X.greaterThanEqual(s.y.sub(Y)).and(X.lessThan(s.z.add(Y))).and(K.greaterThanEqual(D.mul(3).add(Q.mul(2)))).and(T(u?0:1).greaterThan(.5)).and(m.not()),$=Z.select(X.sub(s.y).mul(J),T(-1e6)).toVar(),ee=V(I,Z.select(P.add(U),T(0))).add(V(O,this.outlineWidth.mul(p))).add(1),te=V(ee,Z.select(D.mul(.5).add(U).add(1),T(0))).toVar(),se=a.x.mul(b).sub(s.y).mul(J),ae=s.w.sub(a.y.mul(b)).sub(s.y).mul(J),re=E.x,le=C.select(R.add(te),te.negate()).toVar(),oe=W.add(A.mul(le)).add(q.mul(re.mul(ee))).div(n).mul(2).sub(1),ie=g?H(oe.mul(F),C.select(M.z,x.z),F):H(oe,0,1),ne=g?x.w.lessThan(k).and(M.w.lessThan(k)):T(0).greaterThan(1);return{clip:ie,w:g?F:T(1),local:L(le,re.mul(ee)),segLength:R,halfWidth:I,arrowCentre:$,arrowSize:D,arrowHalf:P,glow:O,step:Q,cutStart:se,cutEnd:ae,alongStart:s.y.mul(J),pixel:T(1),gone:ne}}groundQuad(e,t,s,a,r,l,o,i,n=0,h){const{pixelRatio:u,focal:g,up:w}=this,p=T(.05),b=t.sub(e).toVar(),f=y(b),v=b.div(V(f,1e-6)).toVar(),x=m(w,v),M=y(x).greaterThan(1e-4).select(k(x),k(m(v,q(1,0,0)))).toVar(),W=d.mul(H(e,1)).w.toVar(),z=d.mul(H(t,1)).w.toVar(),R=W.lessThan(p).and(z.lessThan(p)),A=c(p.sub(W).div(z.sub(W)),0,1),C=W.lessThan(p).select(A,T(0)).mul(f).toVar(),F=z.lessThan(p).select(A,T(1)).mul(f).toVar(),N=e=>(e=>V(S(W,z,e.div(V(f,1e-6))),p))(e).div(g),_=e=>l.select(r,r.mul(u).mul(e)),G=e=>V(V(_(e),o),u.mul(2*n).mul(e)),I=s.w.mul(.5),O=N(I.sub(s.y)).toVar(),{arrowHalf:P,arrowSize:D,step:Q}=B(_(O),u.mul(O)),U=D.mul(.5).add(Q).add(G(O)),j=I.greaterThanEqual(s.y.sub(U)).and(I.lessThan(s.z.add(U))).and(s.w.greaterThanEqual(D.mul(3).add(Q.mul(2)))).and(h.not()),J=j.select(I.sub(s.y),T(-1e6)).toVar(),K=E.x,X=E.y.greaterThan(.5),Y=e=>{const t=G(e),s=u.mul(1.5).mul(e);return V(t.mul(.5),j.select(P.add(s),T(0))).add(i.select(u.mul(this.glowWidth).mul(e),T(0))).add(e)},Z=X.select(F,C).toVar(),$=N(Z),ee=X.select(F.lessThan(f),C.greaterThan(0)).select(T(0),V(Y($),j.select(D.mul(.5).add($),T(0)))),te=X.select(Z.add(ee),Z.sub(ee)).toVar(),se=N(te).toVar(),ae=G(se),re=K.mul(Y(se)),le=e.add(v.mul(te)).add(M.mul(re));return{clip:d.mul(H(le,1)),w:T(1),local:L(te,re),segLength:f,halfWidth:ae.mul(.5),arrowCentre:J,arrowSize:D,arrowHalf:P,glow:i.select(u.mul(this.glowWidth).mul(se),T(0)),step:Q,cutStart:a.x.sub(s.y),cutEnd:s.w.sub(a.y).sub(s.y),alongStart:s.y,pixel:N(f.mul(.5)),gone:R}}}function B(e,t){const s=V(e,t.mul(3)),a=t.mul(16);return{arrowHalf:s,arrowSize:a,step:a.mul(.25),outline:t.mul(1.5)}}function J(e,t){return Math.hypot(t.x-e.x,t.y-e.y,t.z-e.z)}
1
+ import{DoubleSide as e,InstancedBufferAttribute as t,InstancedBufferGeometry as s,LessDepth as a,LessEqualDepth as r,Mesh as l,NoBlending as o,Vector2 as i,Vector3 as n}from"three/webgpu";import{abs as h,attribute as u,cameraProjectionMatrix as d,clamp as c,cross as m,dFdx as g,dFdy as w,Discard as p,float as T,Fn as b,fract as f,If as v,int as x,length as y,max as V,min as M,mix as k,normalize as S,positionGeometry as E,screenCoordinate as W,smoothstep as z,uniform as R,varyingProperty as A,vec2 as L,vec3 as q,vec4 as H,viewport as C}from"three/tsl";import{FeatureLook as F,FeatureState as N,hasFlag as _,LookFlag as G}from"../FeatureLook.js";import{additive as I,adoptGeometry as O,disposeMaterial as P,GONE as D,nodeMaterial as Q,segmentQuad as U,unculled as j}from"../Tsl.js";export const OUTLINE_RGB=[235/255,232/255,224/255];export const LineState=N;export const ARROW_LENGTH=16;export const ARROW_MIN_HALF_HEIGHT=3;export const ARROW_OUTLINE=1.5;export class GpuLines{constructor(e,a={}){this.options=a,this.pickMesh=null,this.featureCount=R(1),this.pxPerWorld=R(1),this.pixelRatio=R(1),this.rank=R(0),this.glowMode=R(1),this.outlineRgb=R(new n(...OUTLINE_RGB)),this.outlineWidth=R(2),this.glowWidth=R(6),this.focal=R(1e3),this.near=R(.3),this.worldPerMetre=R(1),this.endsShown=R(1),this.dash=R(new i(10,6)),this.flowSpacing=R(48),this.flowSpeed=R(60),this.time=R(0),this.up=R(new n(0,0,1)),a.ground&&this.up.value.set(a.ground.up[0],a.ground.up[1],a.ground.up[2]).normalize();const r=e.length;this.look=a.look??new F(r,{failLooks:!0}),this.featureCount.value=Math.max(1,r);let o=0;for(const t of e)for(const e of t)o+=Math.max(0,e.length-1);this.segments=o;const h=new Float32Array(3*o),u=new Float32Array(3*o),d=new Float32Array(4*o),c=new Float32Array(2*o),m=a.ends;let g=0;e.forEach((e,t)=>e.forEach(s=>{let a=0;for(let e=1;e<s.length;e++)a+=J(s[e-1],s[e]);let r=0;for(let l=1;l<s.length;l++){const o=s[l-1],i=s[l],n=J(o,i);h[3*g]=o.x,h[3*g+1]=o.y,h[3*g+2]=o.z,u[3*g]=i.x,u[3*g+1]=i.y,u[3*g+2]=i.z,d[4*g]=t,d[4*g+1]=r,d[4*g+2]=r+n,d[4*g+3]=a,m&&1===e.length&&(c[2*g]=m[2*t]||0,c[2*g+1]=m[2*t+1]||0),r+=n,g++}}));const w=U(new s);w.setAttribute("segStart",new t(h,3)),w.setAttribute("segEnd",new t(u,3)),w.setAttribute("segMeta",new t(d,4)),w.setAttribute("segTrim",new t(c,2)),w.instanceCount=o,this.mesh=j(new l(w,this.createMaterial(r,"core"))),this.fringeMesh=j(new l(w,this.createMaterial(r,"fringe")),1),this.bloomMesh=j(new l(w,this.createMaterial(r,"bloom"))),this.casingMesh=j(new l(w,this.createMaterial(r,"casing")),-1),this.casingMesh.visible=!1,a.pick&&(this.pickMesh=j(new l(w,this.createMaterial(r,"pick")))),this.densityMesh=j(new l(w,this.createMaterial(r,"density"))),this.densityMesh.visible=!1}get dragActive(){return this.look.rangeActive}get dragLow(){return this.look.rangeLow}get dragHigh(){return this.look.rangeHigh}get othersShade(){return this.look.othersShade}get othersToward(){return this.look.othersToward}passes(){return{scene:[this.casingMesh,this.mesh,this.fringeMesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){this.pxPerWorld.value=e.pxPerWorld,this.pixelRatio.value=e.pixelRatio,this.near.value=e.near,e.focal&&(this.focal.value=e.focal),void 0!==e.time&&(this.time.value=e.time)}setStyle(e,t){this.look.set(e,{color:t.color,width:t.width,flags:(t.flags??0)&~G.Meters,meters:t.meters,state:t.state,realWidth:t.realWidth,weight:t.color[3],fadedWeight:t.color[3]})}commit(){this.look.commit()}setDragStyle(e,t,s,a){this.look.setFail(e,{color:t.color,width:t.width,meters:t.meters,state:t.state,realWidth:t.realWidth,flags:t.flags}),this.look.setValue(e,s,a)}commitDrag(){this.look.commit()}meshes(){return[this.mesh,this.fringeMesh,this.bloomMesh,this.casingMesh,this.pickMesh,this.densityMesh]}adopt(e){return!!(e instanceof GpuLines&&O(this.meshes(),e.meshes()))&&(this.segments=e.segments,this.featureCount.value=e.featureCount.value,!0)}dispose(){this.mesh.geometry.dispose(),this.meshes().forEach(P),this.options.look||this.look.dispose()}createMaterial(t,s){const l="bloom"===s,i="casing"===s,n="pick"===s,d="density"===s,m=this.options.pick,S=!!this.options.ground,E=!S&&!!this.options.space,R=!1!==this.options.arrows,F=S||E?this.options.occluder:null,N=Q();N.transparent=!n,n&&(N.blending=o),N.side=e,N.depthTest=!0,N.depthWrite="fringe"!==s,N.depthFunc="fringe"===s||i||E?r:a,d&&I(N);const O=this.look,{rank:P,glowMode:U}=this,j=l||i,B=this.featureCount,J=A("vec2","vLocal"),K=A("float","vW"),X=A("vec4","vSegment"),Y=A("vec4","vColor"),Z=A("vec4","vExtra"),$=A("float","vDistance"),ee=A("float","vIndex"),te=A("vec3","vCut"),se=A("vec2","vJoin"),ae=A("vec3","vAlong");return N.vertexNode=b(()=>{const e=u("segStart","vec3"),t=u("segEnd","vec3"),s=u("segMeta","vec4"),a=x(s.x),r=O.read(a),o=r.state,h=r.selected,c=h.and(U.greaterThan(.5)).and(T(l||d?0:1).greaterThan(.5)),g=R?_(r.flags,G.NoArrow):T(1).greaterThan(0),w=u("segTrim","vec2").mul(this.endsShown),p=n?4:0,b=S?this.groundQuad(e,t,s,w,r.width,r.meters,r.realWidth,c,p,g):this.screenQuad(e,t,s,w,r.width,r.meters,r.realWidth,c,n&&m?m.pass.frameSize:C.zw,p,d,g,E);te.assign(q(w.x.greaterThan(0).select(b.cutStart,T(-1e9)),w.y.greaterThan(0).select(b.cutEnd,T(1e9)),b.arrowHalf)),J.assign(b.local.mul(b.w)),K.assign(b.w),X.assign(H(b.segLength,b.halfWidth,b.arrowCentre,b.arrowSize)),Y.assign(H(r.rgb,r.alpha));const f=s.y.lessThanEqual(0).select(this.endsShown,T(0)),v=s.z.greaterThanEqual(s.w).select(this.endsShown,T(0));Z.assign(H(b.glow,b.step,f,v)),se.assign(L(s.y.lessThanEqual(0).select(T(1),T(0)),s.z.greaterThanEqual(s.w).select(T(1),T(0)))),ee.assign(s.x),ae.assign(q(r.flags,b.alongStart,b.pixel));const y=T(.9).sub(o.mul(.25)).sub(P.mul(.04)).sub(s.x.div(B).mul(.03));$.assign(S||E?b.clip.w:y);const V=i?T(.24):y,M=o.lessThan(.5).or(T(j?1:0).greaterThan(.5).and(h.not())).or(d?r.weight.lessThan(.001):T(0).greaterThan(1)).or(n?r.pickable.not():T(0).greaterThan(1)).or(b.gone).or(T(i&&(S||E)?1:0).greaterThan(.5)),k=b.clip,W=S||E?k:H(k.xy,V.mul(k.w),k.w);return M.select(D(),n&&m?m.pass.window.mul(W):W)})(),N.fragmentNode=b(()=>{const e=J.div(K).toVar(),t=e.x,a=e.y,r=X.x,l=X.y;if(n&&m){const e=y(L(t.sub(c(t,0,r)),a)).greaterThan(l).or(t.lessThan(te.x)).or(t.greaterThan(te.y)),s=F?e.or(F.hides($,W.xy.add(m.pass.origin))):e;return v(s.toVar(),()=>{p()}),H(T(m.source),ee,$,1)}const o=X.z,u=X.w,b=S?y(L(g(t),w(t))).mul(.5).toVar():T(.5),x=S?y(L(g(a),w(a))).mul(.5).toVar():T(.5);F&&v(F.hides($).toVar(),()=>{p()});const E=c(t,0,r),R=y(L(t.sub(E),a)).toVar(),A=Z.x,C=T(1).sub(Z.z.mul(z(b.negate(),b,t.negate()))),N=T(1).sub(Z.w.mul(z(b.negate(),b,t.sub(r)))),I=z(b.negate(),b,t.sub(te.x)).mul(z(b.negate(),b,te.y.sub(t))),O=C.mul(N).mul(I).toVar(),P=V(b,x).mul(2).toVar(),D=ae.y.add(t).div(V(ae.z,1e-6)).toVar(),Q=this.dash.x.add(this.dash.y).mul(this.pixelRatio),U=f(D.div(Q)).mul(Q),j=M(U,this.dash.x.mul(this.pixelRatio).sub(U)),B=_(ae.x,G.Dashed).select(c(j.add(.5),0,1),T(1)),re=T(1).sub(z(l.sub(x),l.add(x),R)).mul(O).mul(B).toVar();if(d){const e=t.greaterThanEqual(0).or(se.x.greaterThan(.5)).and(t.lessThan(r).or(se.y.greaterThan(.5))).select(Y.a.mul(re),T(0));return v(e.lessThan(.001),()=>{p()}),H(e,0,0,1)}const le=t.sub(o.sub(u.mul(.5))),oe=te.z.mul(T(1).sub(le.div(u))),ie=M(M(le,u.sub(le)),oe.sub(h(a))).toVar(),ne=t.greaterThanEqual(b.negate()).and(t.lessThanEqual(r.add(b))).select(T(1),T(0)),he=c(ie.div(P).add(.5),0,1).mul(ne).toVar(),ue=c(ie.div(P).add(this.pixelRatio.mul(1.5)).add(.5),0,1).mul(ne).toVar(),de=k(q(0,0,0),Y.rgb,he.div(V(ue,.001))),ce=V(re,ue).toVar(),me=A.greaterThan(0),ge=T(1).sub(z(l,l.add(A),R)),we=this.glowMode.greaterThan(1.5),pe=l.add(this.outlineWidth.mul(this.pixelRatio).mul(P)),Te=T(1).sub(z(pe.sub(P.mul(.5)),pe.add(P.mul(.5)),R)).mul(O);if(i){const e=Te.mul(Y.a);return v(e.lessThan(.01),()=>{p()}),H(this.outlineRgb,e)}const be=me.select(we.select(T(0),ge.mul(ge).mul(.55)),T(0)),fe=V(ce,be),ve="fringe"===s?fe.lessThan(.01).or(fe.greaterThanEqual(.5)):"core"===s?fe.lessThan(.5):fe.lessThan(.01);v(ve,()=>{p()});const xe=ue.greaterThan(.01).select(de,Y.rgb).toVar(),ye=_(ae.x,G.Flow),Ve=this.flowSpacing.mul(this.pixelRatio),Me=f(D.sub(this.time.mul(this.flowSpeed).mul(this.pixelRatio)).div(Ve)),ke=ye.select(z(.55,.95,Me).mul(T(1).sub(z(.95,1,Me))),T(0)),Se=k(xe,q(1,1,1),ke.mul(.65)).toVar(),Ee=k(Se,q(1,1,1),k(T(.6),T(.4),ce)),We=me.select(we.select(Se,Ee),Se);return H(We,Y.a.mul(fe))})(),N}screenQuad(e,t,s,a,r,l,o,i,n,h=0,u=!1,m,g=!1){const{pxPerWorld:w,pixelRatio:p,worldPerMetre:b,focal:f}=this,x=d.mul(H(e,1)).toVar(),M=d.mul(H(t,1)).toVar(),S=this.near.mul(1.01);g&&(v(x.w.lessThan(S),()=>{x.assign(k(x,M,c(S.sub(x.w).div(M.w.sub(x.w)),0,1)))}),v(M.w.lessThan(S),()=>{M.assign(k(M,x,c(S.sub(M.w).div(x.w.sub(M.w)),0,1)))}));const W=x.xy.div(x.w).mul(.5).add(.5).mul(n).toVar(),z=M.xy.div(M.w).mul(.5).add(.5).mul(n).toVar().sub(W).toVar(),R=y(z).toVar(),A=R.greaterThan(1e-6).select(z.div(V(R,1e-6)),L(1,0)).toVar(),q=L(A.y.negate(),A.x).toVar(),C=E.y.greaterThan(.5),F=C.select(M.w,x.w).toVar(),N=g?f.div(V(F,1e-6)):w,_=l.select(r.mul(N),r.mul(p)).toVar(),G=V(V(_,o.mul(b).mul(N)),p.mul(2*h)).toVar(),I=G.mul(.5).toVar(),O=i.select(p.mul(this.glowWidth),T(0)).toVar(),{arrowHalf:P,arrowSize:D,step:Q,outline:U}=B(_,p),j=V(s.z.sub(s.y),1e-6),J=g?R.div(j):w.toVar(),K=s.w.mul(J),X=s.w.mul(.5),Y=D.mul(.5).add(Q).add(G).div(J),Z=X.greaterThanEqual(s.y.sub(Y)).and(X.lessThan(s.z.add(Y))).and(K.greaterThanEqual(D.mul(3).add(Q.mul(2)))).and(T(u?0:1).greaterThan(.5)).and(m.not()),$=Z.select(X.sub(s.y).mul(J),T(-1e6)).toVar(),ee=V(I,Z.select(P.add(U),T(0))).add(V(O,this.outlineWidth.mul(p))).add(1),te=V(ee,Z.select(D.mul(.5).add(U).add(1),T(0))).toVar(),se=a.x.mul(b).sub(s.y).mul(J),ae=s.w.sub(a.y.mul(b)).sub(s.y).mul(J),re=E.x,le=C.select(R.add(te),te.negate()).toVar(),oe=W.add(A.mul(le)).add(q.mul(re.mul(ee))).div(n).mul(2).sub(1),ie=g?H(oe.mul(F),C.select(M.z,x.z),F):H(oe,0,1),ne=g?x.w.lessThan(S).and(M.w.lessThan(S)):T(0).greaterThan(1);return{clip:ie,w:g?F:T(1),local:L(le,re.mul(ee)),segLength:R,halfWidth:I,arrowCentre:$,arrowSize:D,arrowHalf:P,glow:O,step:Q,cutStart:se,cutEnd:ae,alongStart:s.y.mul(J),pixel:T(1),gone:ne}}groundQuad(e,t,s,a,r,l,o,i,n=0,h){const{pixelRatio:u,focal:g,up:w}=this,p=T(.05),b=t.sub(e).toVar(),f=y(b),v=b.div(V(f,1e-6)).toVar(),x=m(w,v),M=y(x).greaterThan(1e-4).select(S(x),S(m(v,q(1,0,0)))).toVar(),W=d.mul(H(e,1)).w.toVar(),z=d.mul(H(t,1)).w.toVar(),R=W.lessThan(p).and(z.lessThan(p)),A=c(p.sub(W).div(z.sub(W)),0,1),C=W.lessThan(p).select(A,T(0)).mul(f).toVar(),F=z.lessThan(p).select(A,T(1)).mul(f).toVar(),N=e=>(e=>V(k(W,z,e.div(V(f,1e-6))),p))(e).div(g),_=e=>l.select(r,r.mul(u).mul(e)),G=e=>V(V(_(e),o),u.mul(2*n).mul(e)),I=s.w.mul(.5),O=N(I.sub(s.y)).toVar(),{arrowHalf:P,arrowSize:D,step:Q}=B(_(O),u.mul(O)),U=D.mul(.5).add(Q).add(G(O)),j=I.greaterThanEqual(s.y.sub(U)).and(I.lessThan(s.z.add(U))).and(s.w.greaterThanEqual(D.mul(3).add(Q.mul(2)))).and(h.not()),J=j.select(I.sub(s.y),T(-1e6)).toVar(),K=E.x,X=E.y.greaterThan(.5),Y=e=>{const t=G(e),s=u.mul(1.5).mul(e);return V(t.mul(.5),j.select(P.add(s),T(0))).add(i.select(u.mul(this.glowWidth).mul(e),T(0))).add(e)},Z=X.select(F,C).toVar(),$=N(Z),ee=X.select(F.lessThan(f),C.greaterThan(0)).select(T(0),V(Y($),j.select(D.mul(.5).add($),T(0)))),te=X.select(Z.add(ee),Z.sub(ee)).toVar(),se=N(te).toVar(),ae=G(se),re=K.mul(Y(se)),le=e.add(v.mul(te)).add(M.mul(re));return{clip:d.mul(H(le,1)),w:T(1),local:L(te,re),segLength:f,halfWidth:ae.mul(.5),arrowCentre:J,arrowSize:D,arrowHalf:P,glow:i.select(u.mul(this.glowWidth).mul(se),T(0)),step:Q,cutStart:a.x.sub(s.y),cutEnd:s.w.sub(a.y).sub(s.y),alongStart:s.y,pixel:N(f.mul(.5)),gone:R}}}function B(e,t){const s=V(e,t.mul(3)),a=t.mul(16);return{arrowHalf:s,arrowSize:a,step:a.mul(.25),outline:t.mul(1.5)}}function J(e,t){return Math.hypot(t.x-e.x,t.y-e.y,t.z-e.z)}
@@ -1 +1 @@
1
- import{Float32BufferAttribute as e,InstancedBufferAttribute as t,InstancedBufferGeometry as s,Mesh as i}from"three/webgpu";import{attribute as o,cameraProjectionMatrix as h,float as n,Fn as a,int as r,max as l,mix as m,positionGeometry as c,uniform as p,vec2 as u,vec3 as d,vec4 as g}from"three/tsl";import{FeatureLook as w}from"../FeatureLook.js";import{Lighting as M}from"../Shading.js";import{adoptGeometry as f,disposeMaterial as y,GONE as v,unculled as x}from"../Tsl.js";import{bodyFragment as b,bodyMaterial as k,bodyUniforms as T,bodyVaryings as I,HALO_GROW as A,pixelSize as P}from"./Body.js";export class GpuSpheres{constructor(o,h={}){this.options=h,this.uniforms=T(),this.near=p(.3),this.look=h.look??new w(h.count??o.reduce((e,t)=>Math.max(e,t.index+1),0)),this.lighting=h.lighting??new M;const n=function(i,[o,h]){const n=[],a=[];for(let e=0;e<=o;e++){const t=e/o*Math.PI;for(let e=0;e<=h;e++){const s=e/h*2*Math.PI;n.push(Math.sin(t)*Math.cos(s),Math.sin(t)*Math.sin(s),Math.cos(t))}}for(let e=0;e<o;e++)for(let t=0;t<h;t++){const s=e*(h+1)+t,i=s+h+1;a.push(s,i,s+1,s+1,i,i+1)}const r=i.length,l=new Float32Array(3*r),m=new Float32Array(3*r);i.forEach((e,t)=>{l[3*t]=e.x,l[3*t+1]=e.y,l[3*t+2]=e.z,m[3*t]=e.index,m[3*t+1]=e.radius,m[3*t+2]=e.reach??0});const c=new s;return c.setAttribute("position",new e(n,3)),c.setIndex(a),c.setAttribute("aCentre",new t(l,3)),c.setAttribute("aInfo",new t(m,3)),c.instanceCount=r,c}(o,h.detail??[10,16]);this.mesh=x(new i(n,this.material("solid"))),this.haloMesh=h.sceneDepth?x(new i(n,this.material("window"))):null,this.bloomMesh=x(new i(n,this.material("bloom"))),this.bloomMesh.visible=!1,this.pickMesh=h.pick?x(new i(n,this.material("pick"))):null,this.densityMesh=x(new i(n,this.material("density"))),this.densityMesh.visible=!1}passes(){return{scene:[this.mesh],halo:[this.haloMesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){const t=this.uniforms;t.pixelRatio.value=e.pixelRatio,t.pxPerWorld.value=e.pxPerWorld,t.orthographic.value=e.orthographic?1:0,e.focal&&(t.focal.value=e.focal),this.near.value=e.near,e.eye&&this.lighting.eye.value.copy(e.eye)}meshes(){return[this.mesh,this.haloMesh,this.bloomMesh,this.pickMesh,this.densityMesh]}adopt(e){return e instanceof GpuSpheres&&f(this.meshes(),e.meshes())}dispose(){this.mesh.geometry.dispose(),this.meshes().forEach(y),this.options.look||this.look.dispose()}material(e){const t="pick"===e,s=k(e),i=this.uniforms,{vColor:p,vNormal:w,vDistance:M,vPosition:f,vMaterial:y,vIndex:x}=I(),T=this.options.pick;return s.vertexNode=a(()=>{const s=o("aCentre","vec3"),a=o("aInfo","vec3"),b=c,k=this.look.read(r(a.x)),I=k.selected,j=I.select(l(k.alpha,n(1)),k.alpha),C=I.select(m(k.rgb,d(1,1,1),i.litMix),k.rgb),F=l(h.mul(g(s,1)).w,this.near),N=P(i,F).mul(i.pixelRatio),R=l(N.mul(k.width).mul(.5),t?N.mul(4):n(0)),S=l(a.y,R),W="window"===e?n(A):"casing"===e?N.mul(i.outlineWidth):n(0),z=s.add(b.mul(S.add(W))),D=h.mul(g(z,1));p.assign(g(C,"density"===e?k.weight:j)),w.assign(b),M.assign(D.w),f.assign(z),x.assign(a.x),y.assign(u(k.material,I.select(n(1),n(0))));const E=a.z;return j.lessThan(.001).or(E.greaterThan(0).and(D.w.greaterThan(E))).or("bloom"===e?I.not():n(0).greaterThan(1)).or("density"===e?k.weight.lessThan(.001):n(0).greaterThan(1)).select(v(),t&&T?T.pass.window.mul(D):D)})(),s.fragmentNode=b(e,this.options,i,this.lighting),s}}
1
+ import{Float32BufferAttribute as e,InstancedBufferAttribute as t,InstancedBufferGeometry as s,Mesh as i}from"three/webgpu";import{attribute as o,cameraProjectionMatrix as h,float as n,Fn as a,int as r,max as l,mix as m,positionGeometry as c,uniform as p,vec2 as u,vec3 as d,vec4 as g}from"three/tsl";import{FeatureLook as w}from"../FeatureLook.js";import{Lighting as M}from"../Shading.js";import{adoptGeometry as f,disposeMaterial as y,GONE as v,unculled as b}from"../Tsl.js";import{bodyFragment as x,bodyMaterial as k,bodyUniforms as T,bodyVaryings as I,HALO_GROW as A,pixelSize as P}from"./Body.js";export class GpuSpheres{constructor(o,h={}){this.options=h,this.uniforms=T(),this.near=p(.3),this.look=h.look??new w(h.count??o.reduce((e,t)=>Math.max(e,t.index+1),0)),this.lighting=h.lighting??new M;const n=function(i,[o,h]){const n=[],a=[];for(let e=0;e<=o;e++){const t=e/o*Math.PI;for(let e=0;e<=h;e++){const s=e/h*2*Math.PI;n.push(Math.sin(t)*Math.cos(s),Math.sin(t)*Math.sin(s),Math.cos(t))}}for(let e=0;e<o;e++)for(let t=0;t<h;t++){const s=e*(h+1)+t,i=s+h+1;a.push(s,i,s+1,s+1,i,i+1)}const r=i.length,l=new Float32Array(3*r),m=new Float32Array(3*r);i.forEach((e,t)=>{l[3*t]=e.x,l[3*t+1]=e.y,l[3*t+2]=e.z,m[3*t]=e.index,m[3*t+1]=e.radius,m[3*t+2]=e.reach??0});const c=new s;return c.setAttribute("position",new e(n,3)),c.setIndex(a),c.setAttribute("aCentre",new t(l,3)),c.setAttribute("aInfo",new t(m,3)),c.instanceCount=r,c}(o,h.detail??[10,16]);this.mesh=b(new i(n,this.material("solid"))),this.haloMesh=h.sceneDepth?b(new i(n,this.material("window"))):null,this.bloomMesh=b(new i(n,this.material("bloom"))),this.bloomMesh.visible=!1,this.pickMesh=h.pick?b(new i(n,this.material("pick"))):null,this.densityMesh=b(new i(n,this.material("density"))),this.densityMesh.visible=!1}passes(){return{scene:[this.mesh],halo:[this.haloMesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){const t=this.uniforms;t.pixelRatio.value=e.pixelRatio,t.pxPerWorld.value=e.pxPerWorld,t.orthographic.value=e.orthographic?1:0,e.focal&&(t.focal.value=e.focal),this.near.value=e.near,e.eye&&this.lighting.eye.value.copy(e.eye)}meshes(){return[this.mesh,this.haloMesh,this.bloomMesh,this.pickMesh,this.densityMesh]}adopt(e){return e instanceof GpuSpheres&&f(this.meshes(),e.meshes())}dispose(){this.mesh.geometry.dispose(),this.meshes().forEach(y),this.options.look||this.look.dispose()}material(e){const t="pick"===e,s=k(e),i=this.uniforms,{vColor:p,vNormal:w,vDistance:M,vPosition:f,vMaterial:y,vIndex:b}=I(),T=this.options.pick;return s.vertexNode=a(()=>{const s=o("aCentre","vec3"),a=o("aInfo","vec3"),x=c,k=this.look.read(r(a.x)),I=k.selected,j=I.select(k.strength,k.alpha),C=I.select(m(k.rgb,d(1,1,1),i.litMix),k.rgb),F=l(h.mul(g(s,1)).w,this.near),N=P(i,F).mul(i.pixelRatio),R=l(N.mul(k.width).mul(.5),t?N.mul(4):n(0)),S=l(a.y,R),W="window"===e?n(A):"casing"===e?N.mul(i.outlineWidth):n(0),z=s.add(x.mul(S.add(W))),D=h.mul(g(z,1));p.assign(g(C,"density"===e?k.weight:j)),w.assign(x),M.assign(D.w),f.assign(z),b.assign(a.x),y.assign(u(k.material,I.select(n(1),n(0))));const E=a.z;return j.lessThan(.001).or(E.greaterThan(0).and(D.w.greaterThan(E))).or("bloom"===e?I.not():n(0).greaterThan(1)).or("density"===e?k.weight.lessThan(.001):n(0).greaterThan(1)).or(t?k.pickable.not():n(0).greaterThan(1)).select(v(),t&&T?T.pass.window.mul(D):D)})(),s.fragmentNode=x(e,this.options,i,this.lighting),s}}
@@ -60,8 +60,6 @@ export interface GpuTubesOptions extends BodyOptions {
60
60
  * Painted in the feature's colour with its material's finish (`Lighting`). Behind the scene's
61
61
  * surface (`sceneDepth`) drawn ghosted, and outlined by the engine's halo from the `window` pass.
62
62
  * Selected ones lit, bloomed or outlined (`casingMesh`); picked by their shape, mitres and all.
63
- *
64
- * The Ing+ map's 3D sewer network, made general.
65
63
  */
66
64
  export declare class GpuTubes implements GeometryPrimitive {
67
65
  private readonly options;
@@ -1 +1 @@
1
- import{DoubleSide as e,Float32BufferAttribute as t,InstancedBufferAttribute as s,InstancedBufferGeometry as n,Mesh as a,Vector3 as r}from"three/webgpu";import{abs as o,attribute as i,cameraProjectionMatrix as l,clamp as h,cross as u,Discard as c,dot as d,float as m,Fn as p,If as f,int as g,length as w,max as b,min as y,mix as v,normalize as M,positionGeometry as x,sign as T,uniform as A,varyingProperty as k,vec2 as z,vec3 as E,vec4 as S,viewport as F}from"three/tsl";import{FeatureLook as I}from"../FeatureLook.js";import{Lighting as R}from"../Shading.js";import{adoptGeometry as j,disposeMaterial as C,GONE as P,nodeMaterial as N,unculled as q}from"../Tsl.js";import{bodyFragment as W,bodyMaterial as X,bodyUniforms as Y,bodyVaryings as B,HALO_GROW as D,pixelSize as G}from"./Body.js";import{ARROW_LENGTH as V,ARROW_MIN_HALF_HEIGHT as $,ARROW_OUTLINE as L}from"./GpuLines.js";export function roundProfile(e){return[e,e,e]}export function boxProfile(e,t,s=.5){return[e/2,t/2,Math.min(e,t)/2*s]}const U={line:0,shaft:1,column:2};export class GpuTubes{constructor(e,o={}){this.options=o,this.arrowMesh=null,this.uniforms=Y(),this.near=A(.3),this.shaftReach=A(1e9),this.up=A(new r(0,0,1)),this.look=o.look??new I(o.count??e.reduce((e,t)=>Math.max(e,t.index+1),0)),this.lighting=o.lighting??new R,o.up&&(this.up.value.set(o.up[0],o.up[1],o.up[2]).normalize(),o.lighting||this.lighting.setUp(o.up));const i=function(e){let t=0;for(const s of e)t+=Math.max(0,s.points.length-1);const s={count:t,starts:new Float32Array(3*t),ends:new Float32Array(3*t),infos:new Float32Array(4*t),shapes:new Float32Array(4*t),befores:new Float32Array(3*t),afters:new Float32Array(3*t)};let n=0;for(const t of e){const e=t.points,a=e.length-1,r=U[t.kind??"line"],o=t.cuts??[0,0];for(let i=1;i<=a;i++){const l=e[i-1],h=e[i];s.starts[3*n]=l[0],s.starts[3*n+1]=l[1],s.starts[3*n+2]=l[2]??0,s.ends[3*n]=h[0],s.ends[3*n+1]=h[1],s.ends[3*n+2]=h[2]??0,s.infos[4*n]=t.index,s.infos[4*n+1]=1===i?o[0]:0,s.infos[4*n+2]=t.reach??0,s.infos[4*n+3]=r,s.shapes[4*n]=t.profile[0],s.shapes[4*n+1]=t.profile[1],s.shapes[4*n+2]=t.profile[2],s.shapes[4*n+3]=i===a?o[1]:0;const u=1===i?t.before:e[i-2],c=i===a?t.after:e[i+1];H(s.befores,n,u,l),H(s.afters,n,h,c),n++}}return s}(e);this.segments=i.count;const l=function(e){const a=function(){const e=[];return[[1,1],[-1,1],[-1,-1],[1,-1]].forEach(([t,s],n)=>{for(let a=0;a<=4;a++){const r=(n+a/4)*Math.PI/2;e.push({x:Math.cos(r),y:Math.sin(r),cornerX:t,cornerY:s})}}),e.push(e[0]),e}(),r=a.length-1,o=[],i=[],l=[];for(const e of a)o.push(e.x,e.y,0,e.x,e.y,1),i.push(e.cornerX,e.cornerY,0,e.cornerX,e.cornerY,0);for(let e=0;e<r;e++){const t=2*e;l.push(t,t+2,t+1,t+1,t+2,t+3)}for(const[e,t]of[[0,-1],[1,1]]){const s=o.length/3;o.push(0,0,e),i.push(0,0,t);for(const s of a)o.push(s.x,s.y,e),i.push(s.cornerX,s.cornerY,1e-4*t);for(let e=0;e<r;e++){const n=s+1+e;t>0?l.push(s,n,n+1):l.push(s,n+1,n)}}const h=new n;return h.setAttribute("position",new t(o,3)),h.setAttribute("cornerCap",new t(i,3)),h.setIndex(l),h.setAttribute("aStart",new s(e.starts,3)),h.setAttribute("aEnd",new s(e.ends,3)),h.setAttribute("aInfo",new s(e.infos,4)),h.setAttribute("aShape",new s(e.shapes,4)),h.setAttribute("aBefore",new s(e.befores,3)),h.setAttribute("aAfter",new s(e.afters,3)),h.instanceCount=e.count,h}(i);if(this.mesh=q(new a(l,this.cylinderMaterial("solid"))),this.haloMesh=o.sceneDepth?q(new a(l,this.cylinderMaterial("window"))):null,this.bloomMesh=q(new a(l,this.cylinderMaterial("bloom"))),this.bloomMesh.visible=!1,this.casingMesh=q(new a(l,this.cylinderMaterial("casing")),-1),this.casingMesh.visible=!1,this.pickMesh=o.pick?q(new a(l,this.cylinderMaterial("pick"))):null,this.densityMesh=q(new a(l,this.cylinderMaterial("density"))),this.densityMesh.visible=!1,o.arrows){const r=function(e){const t=e.filter(e=>"line"===(e.kind??"line")&&e.points.length>1);let s=0;for(const e of t)s+=e.points.length-1;const n={count:s,starts:new Float32Array(3*s),ends:new Float32Array(3*s),infos:new Float32Array(4*s),metas:new Float32Array(3*s)};let a=0;for(const e of t){const t=e.points;let s=0;for(let e=1;e<t.length;e++)s+=J(t[e-1],t[e]);let r=0;for(let o=1;o<t.length;o++){const[i,l]=[t[o-1],t[o]],h=J(i,l);n.starts.set([i[0],i[1],i[2]??0],3*a),n.ends.set([l[0],l[1],l[2]??0],3*a),n.infos.set([e.index,2*e.profile[0],e.reach??0,0],4*a),n.metas.set([r,r+h,s],3*a),r+=h,a++}}return n}(e);r.count>0&&(this.arrowMesh=q(new a(function(e){const a=new n;return a.setAttribute("position",new t([-1,0,0,1,0,0,1,1,0,-1,0,0,1,1,0,-1,1,0],3)),a.setAttribute("aStart",new s(e.starts,3)),a.setAttribute("aEnd",new s(e.ends,3)),a.setAttribute("aInfo",new s(e.infos,4)),a.setAttribute("aMeta",new s(e.metas,3)),a.instanceCount=e.count,a}(r),this.arrowMaterial()),1))}}passes(){return{scene:[this.casingMesh,this.mesh,this.arrowMesh],halo:[this.haloMesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){const t=this.uniforms;t.pixelRatio.value=e.pixelRatio,t.pxPerWorld.value=e.pxPerWorld,t.orthographic.value=e.orthographic?1:0,e.focal&&(t.focal.value=e.focal),this.near.value=e.near,e.eye&&this.lighting.eye.value.copy(e.eye)}meshes(){return[this.mesh,this.haloMesh,this.bloomMesh,this.casingMesh,this.pickMesh,this.densityMesh,this.arrowMesh]}adopt(e){return!!(e instanceof GpuTubes&&j(this.meshes(),e.meshes()))&&(this.segments=e.segments,!0)}dispose(){this.mesh.geometry.dispose(),this.arrowMesh?.geometry.dispose(),this.meshes().forEach(C),this.options.look||this.look.dispose()}cylinderMaterial(e){const t="pick"===e,s=X(e),{up:n,near:a,look:r}=this,h=this.uniforms,{vColor:c,vNormal:f,vDistance:x,vPosition:A,vMaterial:k,vIndex:F}=B(),I=this.options.pick;return s.vertexNode=p(()=>{const s=i("aStart","vec3"),p=i("aEnd","vec3"),R=i("aInfo","vec4"),j=i("aShape","vec4"),C=i("position","vec3"),N=i("cornerCap","vec3"),q=N.xy,W=N.z,X=i("aBefore","vec3"),Y=i("aAfter","vec3"),B=r.read(g(R.x)),V=B.selected,$=V.select(b(B.alpha,m(1)),B.alpha),L=V.select(v(B.rgb,E(1,1,1),h.litMix),B.rgb),U=R.w.lessThan(.5),H=b(l.mul(S(s.add(p.sub(s).mul(C.z)),1)).w,a),J=G(h,H).mul(h.pixelRatio),K=B.width.mul(V.select(m(1.5),B.faded.select(m(.5),m(1)))),O="window"===e?m(0):U.select(J.mul(K).mul(.5),m(0)),Q=b(j.x,O),Z=b(j.y,O),_=b(j.z,O),ee=t?b(J.mul(4).sub(y(Q,Z)),0):"casing"===e?J.mul(h.outlineWidth):m("window"===e?D:0),te=Q.add(ee),se=Z.add(ee),ne=_.add(ee),ae=p.sub(s),re=M(ae),oe=C.z.greaterThan(.5),ie=oe.select(j.w,R.y),le="density"===e?m(0):b(te,se),he=ie.greaterThan(0).and(H.greaterThan(this.shaftReach)).select(ie.add(le),m(0)),ue=oe.select(he,he.negate()),ce=R.w.greaterThan(.5).or(o(d(re,n)).greaterThan(.95)),de=M(ce.select(u(re,E(1,0,0)),u(re,n))),me=u(re,de),pe=de.mul(C.x).add(me.mul(C.y)),fe=q.x.mul(te.sub(ne)).add(C.x.mul(ne)),ge=q.y.mul(se.sub(ne)).add(C.y.mul(ne)),we=de.mul(fe).add(me.mul(ge)).mul(m(1).sub(o(W))),be=oe.select(Y,X),ye=M(oe.select(re.add(Y),X.add(re))),ve=w(be).greaterThan(.5).select(d(we,ye).negate().div(b(d(re,ye),.26)),m(0)),Me=t?ce.select(ee,m(0)):m(0),xe=s.add(ae.mul(C.z)).add(re.mul(ve.add(ue).add(C.z.mul(2).sub(1).mul(Me)))).add(we),Te=l.mul(S(xe,1)),Ae=l.mul(S(xe.add(M(xe.sub(this.lighting.eye)).mul(b(te,se).mul(2))),1)),ke="casing"===e?S(Te.x,Te.y,Ae.z.div(Ae.w).mul(Te.w),Te.w):Te;c.assign(S(L,"density"===e?B.weight:$)),f.assign(o(W).greaterThan(1e-5).select(re.mul(T(W)),pe)),x.assign(ke.w),A.assign(xe),F.assign(R.x),k.assign(z(B.material,V.select(m(1),m(0))));const ze=R.z;return $.lessThan(.001).or(ze.greaterThan(0).and(ke.w.greaterThan(ze))).or(w(ae).lessThan(1e-4)).or("bloom"===e||"casing"===e?V.not():m(0).greaterThan(1)).or("density"===e?B.weight.lessThan(.001):m(0).greaterThan(1)).or("window"===e?m(0).greaterThan(1):R.w.greaterThan(.5).and(R.w.lessThan(1.5)).and(W.greaterThan(0))).select(P(),t&&I?I.pass.window.mul(ke):ke)})(),s.fragmentNode=W(e,this.options,h,this.lighting),s}arrowMaterial(){const t=N();t.transparent=!0,t.side=e,t.depthTest=!0,t.depthWrite=!1;const s=this.options.occluder,n=this.uniforms,{near:a,look:r}=this,u=k("vec4","vColor"),d=k("float","vDistance"),T=k("float","vAcross"),A=k("vec3","vArrow"),I=k("float","vSegment");return t.vertexNode=p(()=>{const e=i("aInfo","vec4"),t=g(e.x),s=r.read(t),o=l.mul(S(i("aStart","vec3"),1)).toVar(),c=l.mul(S(i("aEnd","vec3"),1)).toVar(),p=a.mul(1.5);f(o.w.lessThan(p),()=>{o.assign(v(o,c,h(p.sub(o.w).div(c.w.sub(o.w)),0,1)))}),f(c.w.lessThan(p),()=>{c.assign(v(c,o,h(p.sub(c.w).div(o.w.sub(c.w)),0,1)))});const y=F.zw,k=o.xy.div(o.w).mul(.5).add(.5).mul(y),R=c.xy.div(c.w).mul(.5).add(.5).mul(y),j=R.sub(k),C=M(w(j).greaterThan(1e-6).select(j,z(1,0))),N=z(C.y.negate(),C.x),q=x.y.greaterThan(.5),W=q.select(c.w,o.w),X=i("aMeta","vec3"),Y=w(j),B=Y.div(b(X.y.sub(X.x),.001)),D=n.pixelRatio,G=b(s.width,m($)).mul(D),U=D.mul(V),H=U.mul(.25),J=X.z.mul(.5),K=U.mul(.5).add(H).div(b(B,1e-6)),O=J.greaterThanEqual(X.x.sub(K)).and(J.lessThan(X.y.add(K))).and(X.z.mul(B).greaterThanEqual(U.mul(3).add(H.mul(2)))),Q=J.sub(X.x).mul(B),Z=G.add(D.mul(L+1)),_=q.select(R,k).add(N.mul(x.x.mul(Z)));u.assign(S(s.rgb,s.alpha)),d.assign(W),T.assign(x.x.mul(Z)),A.assign(E(q.select(Y,m(0)),G,Q)),I.assign(Y);const ee=o.w.lessThan(p).and(c.w.lessThan(p)),te=e.z,se=ee.or(s.alpha.lessThan(.001)).or(s.faded).or(te.greaterThan(0).and(W.greaterThan(te))).or(O.not()),ne=v(i("aStart","vec3"),i("aEnd","vec3"),h(Q.div(b(Y,1e-6)),0,1)),ae=l.mul(S(ne.add(M(this.lighting.eye.sub(ne)).mul(e.y.add(.05))),1)),re=ae.z.div(b(ae.w,1e-6));return se.select(P(),S(_.div(y).mul(2).sub(1),re,1))})(),t.fragmentNode=p(()=>{s&&f(s.hides(d).toVar(),()=>{c()});const e=n.pixelRatio,t=A.x,a=o(T),r=A.y,i=e.mul(V),l=t.sub(A.z.sub(i.mul(.5))),p=r.mul(m(1).sub(l.div(i))),g=y(y(l,i.sub(l)),p.sub(a)),w=t.greaterThanEqual(-.5).and(t.lessThanEqual(I.add(.5))).select(m(1),m(0)),M=h(g.add(.5),0,1).mul(w),x=h(g.add(e.mul(L)).add(.5),0,1).mul(w);return f(x.lessThan(.002),()=>{c()}),S(v(E(0,0,0),u.xyz,M.div(b(x,.001))),x.mul(u.w))})(),t}}export function joinTubeEnds(e,t=.001){const s=e=>`${Math.round(e[0]/t)},${Math.round(e[1]/t)},${Math.round((e[2]??0)/t)}`,n=new Map;return e.forEach(e=>{if("line"!==(e.kind??"line")||e.points.length<2)return;const t=s(e.points[0]),a=s(e.points[e.points.length-1]);n.set(t,[...n.get(t)??[],{tube:e,atStart:!0}]),n.set(a,[...n.get(a)??[],{tube:e,atStart:!1}])}),n.forEach(e=>{if(2!==e.length)return;const[t,s]=e,n=e=>e.atStart?e.tube.points[1]:e.tube.points[e.tube.points.length-2],a=(e,t)=>{var s,n;e.atStart?(s=e.tube).before??(s.before=t):(n=e.tube).after??(n.after=t)};a(t,n(s)),a(s,n(t))}),e}function H(e,t,s,n){if(!s||!n)return;const a=n[0]-s[0],r=n[1]-s[1],o=(n[2]??0)-(s[2]??0),i=Math.hypot(a,r,o);i<=1e-6||(e[3*t]=a/i,e[3*t+1]=r/i,e[3*t+2]=o/i)}function J(e,t){return Math.hypot(t[0]-e[0],t[1]-e[1],(t[2]??0)-(e[2]??0))}
1
+ import{DoubleSide as e,Float32BufferAttribute as t,InstancedBufferAttribute as s,InstancedBufferGeometry as n,Mesh as a,Vector3 as r}from"three/webgpu";import{abs as o,attribute as i,cameraProjectionMatrix as l,clamp as h,cross as u,Discard as c,dot as d,float as m,Fn as p,If as f,int as g,length as w,max as b,min as y,mix as v,normalize as M,positionGeometry as x,sign as T,uniform as A,varyingProperty as k,vec2 as z,vec3 as E,vec4 as S,viewport as F}from"three/tsl";import{FeatureLook as I}from"../FeatureLook.js";import{Lighting as R}from"../Shading.js";import{adoptGeometry as j,disposeMaterial as C,GONE as P,nodeMaterial as N,unculled as q}from"../Tsl.js";import{bodyFragment as W,bodyMaterial as X,bodyUniforms as Y,bodyVaryings as B,HALO_GROW as D,pixelSize as G}from"./Body.js";import{ARROW_LENGTH as V,ARROW_MIN_HALF_HEIGHT as $,ARROW_OUTLINE as L}from"./GpuLines.js";export function roundProfile(e){return[e,e,e]}export function boxProfile(e,t,s=.5){return[e/2,t/2,Math.min(e,t)/2*s]}const U={line:0,shaft:1,column:2};export class GpuTubes{constructor(e,o={}){this.options=o,this.arrowMesh=null,this.uniforms=Y(),this.near=A(.3),this.shaftReach=A(1e9),this.up=A(new r(0,0,1)),this.look=o.look??new I(o.count??e.reduce((e,t)=>Math.max(e,t.index+1),0)),this.lighting=o.lighting??new R,o.up&&(this.up.value.set(o.up[0],o.up[1],o.up[2]).normalize(),o.lighting||this.lighting.setUp(o.up));const i=function(e){let t=0;for(const s of e)t+=Math.max(0,s.points.length-1);const s={count:t,starts:new Float32Array(3*t),ends:new Float32Array(3*t),infos:new Float32Array(4*t),shapes:new Float32Array(4*t),befores:new Float32Array(3*t),afters:new Float32Array(3*t)};let n=0;for(const t of e){const e=t.points,a=e.length-1,r=U[t.kind??"line"],o=t.cuts??[0,0];for(let i=1;i<=a;i++){const l=e[i-1],h=e[i];s.starts[3*n]=l[0],s.starts[3*n+1]=l[1],s.starts[3*n+2]=l[2]??0,s.ends[3*n]=h[0],s.ends[3*n+1]=h[1],s.ends[3*n+2]=h[2]??0,s.infos[4*n]=t.index,s.infos[4*n+1]=1===i?o[0]:0,s.infos[4*n+2]=t.reach??0,s.infos[4*n+3]=r,s.shapes[4*n]=t.profile[0],s.shapes[4*n+1]=t.profile[1],s.shapes[4*n+2]=t.profile[2],s.shapes[4*n+3]=i===a?o[1]:0;const u=1===i?t.before:e[i-2],c=i===a?t.after:e[i+1];H(s.befores,n,u,l),H(s.afters,n,h,c),n++}}return s}(e);this.segments=i.count;const l=function(e){const a=function(){const e=[];return[[1,1],[-1,1],[-1,-1],[1,-1]].forEach(([t,s],n)=>{for(let a=0;a<=4;a++){const r=(n+a/4)*Math.PI/2;e.push({x:Math.cos(r),y:Math.sin(r),cornerX:t,cornerY:s})}}),e.push(e[0]),e}(),r=a.length-1,o=[],i=[],l=[];for(const e of a)o.push(e.x,e.y,0,e.x,e.y,1),i.push(e.cornerX,e.cornerY,0,e.cornerX,e.cornerY,0);for(let e=0;e<r;e++){const t=2*e;l.push(t,t+2,t+1,t+1,t+2,t+3)}for(const[e,t]of[[0,-1],[1,1]]){const s=o.length/3;o.push(0,0,e),i.push(0,0,t);for(const s of a)o.push(s.x,s.y,e),i.push(s.cornerX,s.cornerY,1e-4*t);for(let e=0;e<r;e++){const n=s+1+e;t>0?l.push(s,n,n+1):l.push(s,n+1,n)}}const h=new n;return h.setAttribute("position",new t(o,3)),h.setAttribute("cornerCap",new t(i,3)),h.setIndex(l),h.setAttribute("aStart",new s(e.starts,3)),h.setAttribute("aEnd",new s(e.ends,3)),h.setAttribute("aInfo",new s(e.infos,4)),h.setAttribute("aShape",new s(e.shapes,4)),h.setAttribute("aBefore",new s(e.befores,3)),h.setAttribute("aAfter",new s(e.afters,3)),h.instanceCount=e.count,h}(i);if(this.mesh=q(new a(l,this.cylinderMaterial("solid"))),this.haloMesh=o.sceneDepth?q(new a(l,this.cylinderMaterial("window"))):null,this.bloomMesh=q(new a(l,this.cylinderMaterial("bloom"))),this.bloomMesh.visible=!1,this.casingMesh=q(new a(l,this.cylinderMaterial("casing")),-1),this.casingMesh.visible=!1,this.pickMesh=o.pick?q(new a(l,this.cylinderMaterial("pick"))):null,this.densityMesh=q(new a(l,this.cylinderMaterial("density"))),this.densityMesh.visible=!1,o.arrows){const r=function(e){const t=e.filter(e=>"line"===(e.kind??"line")&&e.points.length>1);let s=0;for(const e of t)s+=e.points.length-1;const n={count:s,starts:new Float32Array(3*s),ends:new Float32Array(3*s),infos:new Float32Array(4*s),metas:new Float32Array(3*s)};let a=0;for(const e of t){const t=e.points;let s=0;for(let e=1;e<t.length;e++)s+=J(t[e-1],t[e]);let r=0;for(let o=1;o<t.length;o++){const[i,l]=[t[o-1],t[o]],h=J(i,l);n.starts.set([i[0],i[1],i[2]??0],3*a),n.ends.set([l[0],l[1],l[2]??0],3*a),n.infos.set([e.index,2*e.profile[0],e.reach??0,0],4*a),n.metas.set([r,r+h,s],3*a),r+=h,a++}}return n}(e);r.count>0&&(this.arrowMesh=q(new a(function(e){const a=new n;return a.setAttribute("position",new t([-1,0,0,1,0,0,1,1,0,-1,0,0,1,1,0,-1,1,0],3)),a.setAttribute("aStart",new s(e.starts,3)),a.setAttribute("aEnd",new s(e.ends,3)),a.setAttribute("aInfo",new s(e.infos,4)),a.setAttribute("aMeta",new s(e.metas,3)),a.instanceCount=e.count,a}(r),this.arrowMaterial()),1))}}passes(){return{scene:[this.casingMesh,this.mesh,this.arrowMesh],halo:[this.haloMesh],bloom:[this.bloomMesh],pick:[this.pickMesh],density:[this.densityMesh]}}setFrame(e){const t=this.uniforms;t.pixelRatio.value=e.pixelRatio,t.pxPerWorld.value=e.pxPerWorld,t.orthographic.value=e.orthographic?1:0,e.focal&&(t.focal.value=e.focal),this.near.value=e.near,e.eye&&this.lighting.eye.value.copy(e.eye)}meshes(){return[this.mesh,this.haloMesh,this.bloomMesh,this.casingMesh,this.pickMesh,this.densityMesh,this.arrowMesh]}adopt(e){return!!(e instanceof GpuTubes&&j(this.meshes(),e.meshes()))&&(this.segments=e.segments,!0)}dispose(){this.mesh.geometry.dispose(),this.arrowMesh?.geometry.dispose(),this.meshes().forEach(C),this.options.look||this.look.dispose()}cylinderMaterial(e){const t="pick"===e,s=X(e),{up:n,near:a,look:r}=this,h=this.uniforms,{vColor:c,vNormal:f,vDistance:x,vPosition:A,vMaterial:k,vIndex:F}=B(),I=this.options.pick;return s.vertexNode=p(()=>{const s=i("aStart","vec3"),p=i("aEnd","vec3"),R=i("aInfo","vec4"),j=i("aShape","vec4"),C=i("position","vec3"),N=i("cornerCap","vec3"),q=N.xy,W=N.z,X=i("aBefore","vec3"),Y=i("aAfter","vec3"),B=r.read(g(R.x)),V=B.selected,$=V.select(B.strength,B.alpha),L=V.select(v(B.rgb,E(1,1,1),h.litMix),B.rgb),U=R.w.lessThan(.5),H=b(l.mul(S(s.add(p.sub(s).mul(C.z)),1)).w,a),J=G(h,H).mul(h.pixelRatio),K=B.width.mul(V.select(m(1.5),B.faded.select(m(.5),m(1)))),O="window"===e?m(0):U.select(J.mul(K).mul(.5),m(0)),Q=b(j.x,O),Z=b(j.y,O),_=b(j.z,O),ee=t?b(J.mul(4).sub(y(Q,Z)),0):"casing"===e?J.mul(h.outlineWidth):m("window"===e?D:0),te=Q.add(ee),se=Z.add(ee),ne=_.add(ee),ae=p.sub(s),re=M(ae),oe=C.z.greaterThan(.5),ie=oe.select(j.w,R.y),le="density"===e?m(0):b(te,se),he=ie.greaterThan(0).and(H.greaterThan(this.shaftReach)).select(ie.add(le),m(0)),ue=oe.select(he,he.negate()),ce=R.w.greaterThan(.5).or(o(d(re,n)).greaterThan(.95)),de=M(ce.select(u(re,E(1,0,0)),u(re,n))),me=u(re,de),pe=de.mul(C.x).add(me.mul(C.y)),fe=q.x.mul(te.sub(ne)).add(C.x.mul(ne)),ge=q.y.mul(se.sub(ne)).add(C.y.mul(ne)),we=de.mul(fe).add(me.mul(ge)).mul(m(1).sub(o(W))),be=oe.select(Y,X),ye=M(oe.select(re.add(Y),X.add(re))),ve=w(be).greaterThan(.5).select(d(we,ye).negate().div(b(d(re,ye),.26)),m(0)),Me=t?ce.select(ee,m(0)):m(0),xe=s.add(ae.mul(C.z)).add(re.mul(ve.add(ue).add(C.z.mul(2).sub(1).mul(Me)))).add(we),Te=l.mul(S(xe,1)),Ae=l.mul(S(xe.add(M(xe.sub(this.lighting.eye)).mul(b(te,se).mul(2))),1)),ke="casing"===e?S(Te.x,Te.y,Ae.z.div(Ae.w).mul(Te.w),Te.w):Te;c.assign(S(L,"density"===e?B.weight:$)),f.assign(o(W).greaterThan(1e-5).select(re.mul(T(W)),pe)),x.assign(ke.w),A.assign(xe),F.assign(R.x),k.assign(z(B.material,V.select(m(1),m(0))));const ze=R.z;return $.lessThan(.001).or(ze.greaterThan(0).and(ke.w.greaterThan(ze))).or(w(ae).lessThan(1e-4)).or("bloom"===e||"casing"===e?V.not():m(0).greaterThan(1)).or("density"===e?B.weight.lessThan(.001):m(0).greaterThan(1)).or(t?B.pickable.not():m(0).greaterThan(1)).or("window"===e?m(0).greaterThan(1):R.w.greaterThan(.5).and(R.w.lessThan(1.5)).and(W.greaterThan(0))).select(P(),t&&I?I.pass.window.mul(ke):ke)})(),s.fragmentNode=W(e,this.options,h,this.lighting),s}arrowMaterial(){const t=N();t.transparent=!0,t.side=e,t.depthTest=!0,t.depthWrite=!1;const s=this.options.occluder,n=this.uniforms,{near:a,look:r}=this,u=k("vec4","vColor"),d=k("float","vDistance"),T=k("float","vAcross"),A=k("vec3","vArrow"),I=k("float","vSegment");return t.vertexNode=p(()=>{const e=i("aInfo","vec4"),t=g(e.x),s=r.read(t),o=l.mul(S(i("aStart","vec3"),1)).toVar(),c=l.mul(S(i("aEnd","vec3"),1)).toVar(),p=a.mul(1.5);f(o.w.lessThan(p),()=>{o.assign(v(o,c,h(p.sub(o.w).div(c.w.sub(o.w)),0,1)))}),f(c.w.lessThan(p),()=>{c.assign(v(c,o,h(p.sub(c.w).div(o.w.sub(c.w)),0,1)))});const y=F.zw,k=o.xy.div(o.w).mul(.5).add(.5).mul(y),R=c.xy.div(c.w).mul(.5).add(.5).mul(y),j=R.sub(k),C=M(w(j).greaterThan(1e-6).select(j,z(1,0))),N=z(C.y.negate(),C.x),q=x.y.greaterThan(.5),W=q.select(c.w,o.w),X=i("aMeta","vec3"),Y=w(j),B=Y.div(b(X.y.sub(X.x),.001)),D=n.pixelRatio,G=b(s.width,m($)).mul(D),U=D.mul(V),H=U.mul(.25),J=X.z.mul(.5),K=U.mul(.5).add(H).div(b(B,1e-6)),O=J.greaterThanEqual(X.x.sub(K)).and(J.lessThan(X.y.add(K))).and(X.z.mul(B).greaterThanEqual(U.mul(3).add(H.mul(2)))),Q=J.sub(X.x).mul(B),Z=G.add(D.mul(L+1)),_=q.select(R,k).add(N.mul(x.x.mul(Z)));u.assign(S(s.rgb,s.alpha)),d.assign(W),T.assign(x.x.mul(Z)),A.assign(E(q.select(Y,m(0)),G,Q)),I.assign(Y);const ee=o.w.lessThan(p).and(c.w.lessThan(p)),te=e.z,se=ee.or(s.alpha.lessThan(.001)).or(s.faded).or(te.greaterThan(0).and(W.greaterThan(te))).or(O.not()),ne=v(i("aStart","vec3"),i("aEnd","vec3"),h(Q.div(b(Y,1e-6)),0,1)),ae=l.mul(S(ne.add(M(this.lighting.eye.sub(ne)).mul(e.y.add(.05))),1)),re=ae.z.div(b(ae.w,1e-6));return se.select(P(),S(_.div(y).mul(2).sub(1),re,1))})(),t.fragmentNode=p(()=>{s&&f(s.hides(d).toVar(),()=>{c()});const e=n.pixelRatio,t=A.x,a=o(T),r=A.y,i=e.mul(V),l=t.sub(A.z.sub(i.mul(.5))),p=r.mul(m(1).sub(l.div(i))),g=y(y(l,i.sub(l)),p.sub(a)),w=t.greaterThanEqual(-.5).and(t.lessThanEqual(I.add(.5))).select(m(1),m(0)),M=h(g.add(.5),0,1).mul(w),x=h(g.add(e.mul(L)).add(.5),0,1).mul(w);return f(x.lessThan(.002),()=>{c()}),S(v(E(0,0,0),u.xyz,M.div(b(x,.001))),x.mul(u.w))})(),t}}export function joinTubeEnds(e,t=.001){const s=e=>`${Math.round(e[0]/t)},${Math.round(e[1]/t)},${Math.round((e[2]??0)/t)}`,n=new Map;return e.forEach(e=>{if("line"!==(e.kind??"line")||e.points.length<2)return;const t=s(e.points[0]),a=s(e.points[e.points.length-1]);n.set(t,[...n.get(t)??[],{tube:e,atStart:!0}]),n.set(a,[...n.get(a)??[],{tube:e,atStart:!1}])}),n.forEach(e=>{if(2!==e.length)return;const[t,s]=e,n=e=>e.atStart?e.tube.points[1]:e.tube.points[e.tube.points.length-2],a=(e,t)=>{var s,n;e.atStart?(s=e.tube).before??(s.before=t):(n=e.tube).after??(n.after=t)};a(t,n(s)),a(s,n(t))}),e}function H(e,t,s,n){if(!s||!n)return;const a=n[0]-s[0],r=n[1]-s[1],o=(n[2]??0)-(s[2]??0),i=Math.hypot(a,r,o);i<=1e-6||(e[3*t]=a/i,e[3*t+1]=r/i,e[3*t+2]=o/i)}function J(e,t){return Math.hypot(t[0]-e[0],t[1]-e[1],(t[2]??0)-(e[2]??0))}
@@ -1,48 +0,0 @@
1
- import { HostedGeometryEngine } from './HostedGeometryEngine';
2
- /**
3
- * What the engine uses of a LuciadRIA `WebGLMap`, typed by shape so this package needs no RIA:
4
- * RIA 2026's map, which renders with WebGPU only, fits it as it is.
5
- */
6
- export interface RiaMapLike {
7
- webGPUDevice?: unknown;
8
- reference: {
9
- identifier: string;
10
- };
11
- camera: {
12
- viewProjectionMatrix: ArrayLike<number>;
13
- near: number;
14
- eye: {
15
- x: number;
16
- y: number;
17
- z: number;
18
- };
19
- fovY?: number;
20
- height?: number;
21
- };
22
- viewSize: [number, number] | number[];
23
- on(event: 'WebGPUDeviceChanged' | 'PostRender', callback: (...args: any[]) => void): {
24
- remove(): void;
25
- };
26
- invalidate(): void;
27
- }
28
- /**
29
- * The engine on a LuciadRIA map: draws into the map's own frame on "PostRender", with its device,
30
- * camera and depth, over every GPU layer and under the map's HTML labels. One per map (`of`).
31
- *
32
- * The Ing+ map's `RiaThreeRenderer` is this: `scene`, `underlayScene`, `bloomScene`,
33
- * `pickScene`, `pickPass`, `density`, `frame`, `setOrigin`, `getOrigin`, `depthTexture`,
34
- * `onBeforeRender`, `onBeforeDraw`, `requestRepaint`, `renderToTarget`, `addPickSource` and
35
- * `pick` are all here with the same meaning; `pick` gives the point hit as numbers in the map's
36
- * reference, for the map to make a `Point` of.
37
- */
38
- export declare class RiaGeometryEngine extends HostedGeometryEngine {
39
- private readonly map;
40
- /** The one engine of this map, made on first use. */
41
- static of(map: RiaMapLike): RiaGeometryEngine;
42
- /** The map's engine if something has made one, without making it. */
43
- static existing(map: RiaMapLike): RiaGeometryEngine | null;
44
- private handles;
45
- constructor(map: RiaMapLike);
46
- private renderMap;
47
- dispose(): void;
48
- }
@@ -1 +0,0 @@
1
- import{HostedGeometryEngine as e}from"./HostedGeometryEngine.js";const t=new WeakMap;export class RiaGeometryEngine extends e{static of(e){let i=t.get(e);return i||(i=new RiaGeometryEngine(e),t.set(e,i)),i}static existing(e){return t.get(e)??null}constructor(e){super({device:e.webGPUDevice,requestFrame:()=>{const t=e._viewPaintingStrategy;t?.repaint?t.repaint():e.invalidate()},originKey:()=>e.reference.identifier.toLowerCase()}),this.map=e,this.handles=[],this.handles.push(e.on("WebGPUDeviceChanged",()=>this.setDevice(e.webGPUDevice)),e.on("PostRender",(e,t)=>this.renderMap(e,t)))}renderMap(e,t){const i=this.map,n=e.width/Math.max(1,i.viewSize[0]),r=i.camera,s=(r.fovY??60)*Math.PI/180,a="epsg:4978"===i.reference.identifier.toLowerCase();this.render(e,t,{viewProjection:r.viewProjectionMatrix,glDepth:!0,near:r.near,pixelRatio:n,geocentric:a,focal:a&&r.height?r.height*n/2/Math.tan(s/2):void 0,eye:[r.eye.x,r.eye.y,r.eye.z]})}dispose(){this.handles.forEach(e=>e.remove()),this.handles=[],t.delete(this.map),super.dispose()}}