@protomaze/geometry 0.2.0 → 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 (39) hide show
  1. package/README.md +69 -47
  2. package/common/Colors.d.ts +1 -2
  3. package/edit/GeometryController.d.ts +1 -1
  4. package/engine/GeometryEngine.d.ts +22 -3
  5. package/engine/GeometryEngine.js +1 -1
  6. package/engine/GeometryFrame.d.ts +3 -6
  7. package/engine/GeometryOptions.d.ts +26 -2
  8. package/engine/GeometryView.d.ts +31 -6
  9. package/engine/GeometryView.js +1 -1
  10. package/index.d.ts +0 -1
  11. package/index.js +1 -1
  12. package/layers/AreaLayer.js +1 -1
  13. package/layers/GeometryLayer.d.ts +33 -7
  14. package/layers/GeometryLayer.js +1 -1
  15. package/layers/LineLayer.d.ts +14 -0
  16. package/layers/LineLayer.js +1 -1
  17. package/layers/SphereLayer.js +1 -1
  18. package/layers/TubeLayer.js +1 -1
  19. package/package.json +1 -1
  20. package/three/CanvasGeometryEngine.d.ts +0 -3
  21. package/three/CanvasGeometryEngine.js +1 -1
  22. package/three/DensityMap.d.ts +3 -3
  23. package/three/FeatureLook.d.ts +19 -2
  24. package/three/FeatureLook.js +1 -1
  25. package/three/HostedGeometryEngine.d.ts +6 -5
  26. package/three/HostedGeometryEngine.js +1 -1
  27. package/three/Shading.d.ts +1 -1
  28. package/three/primitives/Body.d.ts +1 -1
  29. package/three/primitives/Body.js +1 -1
  30. package/three/primitives/GpuAreas.js +1 -1
  31. package/three/primitives/GpuIcons.d.ts +3 -3
  32. package/three/primitives/GpuIcons.js +1 -1
  33. package/three/primitives/GpuLines.d.ts +2 -2
  34. package/three/primitives/GpuLines.js +1 -1
  35. package/three/primitives/GpuSpheres.js +1 -1
  36. package/three/primitives/GpuTubes.d.ts +0 -2
  37. package/three/primitives/GpuTubes.js +1 -1
  38. package/three/RiaGeometryEngine.d.ts +0 -48
  39. package/three/RiaGeometryEngine.js +0 -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()}}