@margoengine/points 0.0.0-stage → 1.0.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 (62) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +876 -2
  4. package/dist/attributes-DNc-1pdr.js +256 -0
  5. package/dist/attributes.d.ts +48 -0
  6. package/dist/clip.d.ts +55 -0
  7. package/dist/clip.js +122 -0
  8. package/dist/cloud-B4O_G-Df.js +545 -0
  9. package/dist/cloud.d.ts +155 -0
  10. package/dist/color.d.ts +1 -0
  11. package/dist/copc-write.d.ts +95 -0
  12. package/dist/copc-write.js +318 -0
  13. package/dist/copc.d.ts +55 -0
  14. package/dist/copc.js +127 -0
  15. package/dist/depth-video.d.ts +98 -0
  16. package/dist/depth-video.js +164 -0
  17. package/dist/e57.d.ts +163 -0
  18. package/dist/e57.js +624 -0
  19. package/dist/frame.d.ts +14 -0
  20. package/dist/index.d.ts +16 -0
  21. package/dist/index.js +1246 -0
  22. package/dist/las.d.ts +213 -0
  23. package/dist/las.js +500 -0
  24. package/dist/laz-encode-CHXgHra_.js +446 -0
  25. package/dist/laz-encode.d.ts +14 -0
  26. package/dist/laz-model-DCphHLqH.js +385 -0
  27. package/dist/laz-model.d.ts +47 -0
  28. package/dist/laz-write.d.ts +46 -0
  29. package/dist/laz-write.js +75 -0
  30. package/dist/laz.d.ts +50 -0
  31. package/dist/laz.js +645 -0
  32. package/dist/material.d.ts +167 -0
  33. package/dist/math.d.ts +103 -0
  34. package/dist/octree.d.ts +182 -0
  35. package/dist/octree.js +360 -0
  36. package/dist/pick.d.ts +76 -0
  37. package/dist/pick.js +192 -0
  38. package/dist/plugin.d.ts +235 -0
  39. package/dist/potree-las-RC8sjbYU.js +1 -0
  40. package/dist/potree-las.d.ts +1 -0
  41. package/dist/potree.d.ts +70 -0
  42. package/dist/potree.js +451 -0
  43. package/dist/range-BQuJAjUM.js +23 -0
  44. package/dist/range.d.ts +4 -0
  45. package/dist/screen-door-CALlYs39.js +7 -0
  46. package/dist/shaders-DCnbvb0-.js +282 -0
  47. package/dist/shaders.d.ts +52 -0
  48. package/dist/shared/fog.d.ts +33 -0
  49. package/dist/shared/pass.d.ts +53 -0
  50. package/dist/shared/selection-mask.d.ts +52 -0
  51. package/dist/shared/style-expression.d.ts +18 -0
  52. package/dist/sprites.d.ts +78 -0
  53. package/dist/storage-limit.d.ts +6 -0
  54. package/dist/style.d.ts +124 -0
  55. package/dist/style.js +709 -0
  56. package/dist/surfels.d.ts +95 -0
  57. package/dist/surfels.js +538 -0
  58. package/dist/survey-DToZwkJv.js +46 -0
  59. package/dist/survey.d.ts +10 -0
  60. package/dist/tier-BcFbLPVT.js +91 -0
  61. package/dist/tier.d.ts +6 -0
  62. package/package.json +102 -4
@@ -0,0 +1,282 @@
1
+ import { n as e } from "./screen-door-CALlYs39.js";
2
+ import { MargoError as t } from "@margoengine/math/errors";
3
+ import { LinearToSRGB as n, parseColor as r } from "@margoengine/math/color";
4
+ //#region ../shared/view.js
5
+ function i(e, t) {
6
+ let n = t.position, r = t.up ?? [
7
+ 0,
8
+ 1,
9
+ 0
10
+ ], i = n[0] - t.target[0], a = n[1] - t.target[1], o = n[2] - t.target[2], s = Math.abs(i), c = Math.abs(a), l = Math.abs(o), u = s > c ? s : c, d = u > l ? u : l, f;
11
+ if (s === Infinity || c === Infinity || l === Infinity) f = Infinity;
12
+ else if (s !== s || c !== c || l !== l) f = s + c + l;
13
+ else if (d === 0) f = 0;
14
+ else {
15
+ let e = s / d * (s / d), t = c / d * (c / d), n = e + t - e - t, r = l / d * (l / d) - n;
16
+ f = Math.sqrt(e + t + r) * d;
17
+ }
18
+ i /= f, a /= f, o /= f;
19
+ let p = r[1] * o - r[2] * a, m = r[2] * i - r[0] * o, h = r[0] * a - r[1] * i, g = Math.abs(p), _ = Math.abs(m), v = Math.abs(h), y = g > _ ? g : _, b = y > v ? y : v, x;
20
+ if (g === Infinity || _ === Infinity || v === Infinity) x = Infinity;
21
+ else if (g !== g || _ !== _ || v !== v) x = g + _ + v;
22
+ else if (b === 0) x = 0;
23
+ else {
24
+ let e = g / b * (g / b), t = _ / b * (_ / b), n = e + t - e - t, r = v / b * (v / b) - n;
25
+ x = Math.sqrt(e + t + r) * b;
26
+ }
27
+ if (!f || !x) throw RangeError("Invalid camera view; pass distinct eye and target and another up vector");
28
+ p /= x, m /= x, h /= x;
29
+ let S = a * h - o * m, C = o * p - i * h, w = i * m - a * p;
30
+ return e[0] = p, e[1] = S, e[2] = i, e[3] = 0, e[4] = m, e[5] = C, e[6] = a, e[7] = 0, e[8] = h, e[9] = w, e[10] = o, e[11] = 0, e[12] = -p * n[0] - m * n[1] - h * n[2], e[13] = -S * n[0] - C * n[1] - w * n[2], e[14] = -i * n[0] - a * n[1] - o * n[2], e[15] = 1, e;
31
+ }
32
+ //#endregion
33
+ //#region src/frame.ts
34
+ function a(e, t) {
35
+ let n = e?.clientWidth;
36
+ return n ? t / n : 1;
37
+ }
38
+ function o(e, t, n, r, a, o) {
39
+ let s = n.matrix, c = !(s[3] || s[7] || s[11]);
40
+ if (e.set(s, 0), e[16] = r, e[17] = a, c) e[18] = .5 * a * Math.hypot(s[1], s[5], s[9]);
41
+ else {
42
+ let t = s[3] * s[3] + s[7] * s[7] + s[11] * s[11], n = (s[1] * s[3] + s[5] * s[7] + s[9] * s[11]) / t;
43
+ e[18] = .5 * a * Math.hypot(s[1] - n * s[3], s[5] - n * s[7], s[9] - n * s[11]) / Math.sqrt(t);
44
+ }
45
+ e[19] = o.endsWith("-srgb") || o.includes("float") ? 0 : 1, c ? (e[20] = 0, e[21] = Math.hypot(s[2], s[6], s[10]), e[22] = 1, e[23] = 1) : (e[20] = n.near / (n.far - n.near), e[21] = n.far * n.near / (n.far - n.near), e[22] = n.near, e[23] = 0);
46
+ let l = i(t, n);
47
+ return e[24] = l[0], e[25] = l[4], e[26] = l[8], e[28] = l[1], e[29] = l[5], e[30] = l[9], e[31] = 0, e[32] = l[2], e[33] = l[6], e[34] = l[10], e[35] = 0, c;
48
+ }
49
+ //#endregion
50
+ //#region ../shared/fog.js
51
+ var s = (e, t) => `
52
+ struct MargoFog {color:vec4f,params:vec4f,eye:vec4f}
53
+ @group(${e}) @binding(${t}) var<uniform> margoFog:MargoFog;
54
+ fn fogAmount(p:vec3f)->f32 {
55
+ let d=distance(p,margoFog.eye.xyz);let q=margoFog.params;
56
+ let amount=select(clamp((d-q.x)/max(q.y-q.x,1e-6),0.0,1.0),1.0-exp(-q.z*q.z*d*d),q.z>0.0);
57
+ return amount*exp(-q.w*max(p.y-margoFog.color.w,0.0));
58
+ }
59
+ `, c = (e, t, n, r) => {
60
+ let i = e === void 0 ? t : e;
61
+ if (typeof i != "number" || !Number.isFinite(i) || i < r) throw RangeError(`Fog ${n} is ${String(i)}; pass a finite number${r === 0 ? ", 0 or more" : ""}`);
62
+ return i;
63
+ };
64
+ function l(e) {
65
+ if (e !== null && (typeof e != "object" || Array.isArray(e))) throw TypeError("Fog must be an object with Fog fields; pass an environment Fog, such an object or null");
66
+ return e && u(e, [
67
+ 0,
68
+ 0,
69
+ 0
70
+ ], /* @__PURE__ */ new Float32Array(12)), e;
71
+ }
72
+ function u(e, t, i, a = !1) {
73
+ let o = e.enabled ?? !0;
74
+ if (typeof o != "boolean") throw TypeError(`Fog enabled is ${String(o)}; pass true or false`);
75
+ let s = c(e.height, 0, "height", -Infinity), l = c(e.near, 1, "near", 0), u = c(e.far, 1e3, "far", 0), d = c(e.density, 0, "density", 0), f = c(e.heightFalloff, 0, "heightFalloff", 0);
76
+ if (r(e.color ?? "#ffffff", i, 0), a) for (let e = 0; e < 3; e++) i[e] = n(i[e]);
77
+ i[3] = s, i[4] = l, i[5] = u, i[6] = d, i[7] = f, o || (i.fill(0, 0, 8), i[4] = i[5] = 34028234663852886e22), i[8] = t[0], i[9] = t[1], i[10] = t[2], i[11] = 0;
78
+ }
79
+ //#endregion
80
+ //#region ../shared/pass.js
81
+ var d = /* @__PURE__ */ Object.freeze({
82
+ color: {
83
+ srcFactor: "src-alpha",
84
+ dstFactor: "one-minus-src-alpha",
85
+ operation: "add"
86
+ },
87
+ alpha: {
88
+ srcFactor: "one",
89
+ dstFactor: "one-minus-src-alpha",
90
+ operation: "add"
91
+ }
92
+ });
93
+ function f(e, t, n, r, i) {
94
+ let a = e.includes("var<private> margoCoverage:u32");
95
+ return `\n@fragment fn transparent(${t}${a ? ",@builtin(sample_mask) margoMask:u32" : ""})->MargoTransparent {${a ? "margoCoverage=margoMask;" : ""}return margoTransparentAt(${n},${r},${i});}\n`;
96
+ }
97
+ function p() {
98
+ return {
99
+ hook: void 0,
100
+ released: void 0,
101
+ set(e, t) {
102
+ return this.hook = e, this.released = t, () => {
103
+ this.hook === e && (this.hook = this.released = void 0);
104
+ };
105
+ }
106
+ };
107
+ }
108
+ //#endregion
109
+ //#region ../shared/selection-mask-wgsl.js
110
+ var m = (e, t) => `
111
+ @group(${e}) @binding(${t}) var<storage,read> margoMask:array<u32>;
112
+ fn margoMaskPresent()->bool{return margoMask[3]==1u;}
113
+ fn margoMaskOn(i:u32)->bool{return ((margoMask[4u+(i>>5u)]>>(i&31u))&1u)!=0u;}
114
+ fn margoMaskHidden(on:bool)->bool{return !on&&margoMask[0]==2u;}
115
+ fn margoMaskColor(c:vec4f,on:bool)->vec4f{
116
+ let l=max(c.rgb,vec3f(0.0));
117
+ var s=select(1.055*pow(l,vec3f(1.0/2.4))-0.055,l*12.92,l<=vec3f(0.0031308));
118
+ if(on){if(margoMask[0]!=1u){return c;}let h=unpack4x8unorm(margoMask[2]);s=mix(s,h.rgb,h.a);}
119
+ else{s*=bitcast<f32>(margoMask[1]);}
120
+ return vec4f(select(pow((s+0.055)/1.055,vec3f(2.4)),s/12.92,s<=vec3f(0.04045)),c.a);
121
+ }
122
+ `, h = {
123
+ colors: 1,
124
+ sizes: 2,
125
+ world: 4,
126
+ round: 8,
127
+ map: 16,
128
+ sphere: 32,
129
+ direct: 64,
130
+ srgbColors: 128,
131
+ floatColors: 256,
132
+ mask: 512
133
+ }, g = `
134
+ fn pointColor(p:u32)->vec4f{
135
+ var c:vec4f;
136
+ if(has(${h.floatColors}u)){
137
+ let q=p*4u;
138
+ c=vec4f(bitcast<f32>(colors[q]),bitcast<f32>(colors[q+1u]),bitcast<f32>(colors[q+2u]),bitcast<f32>(colors[q+3u]));
139
+ } else {c=unpack4x8unorm(colors[p]);}
140
+ return vec4f(select(c.rgb,toLinear(c.rgb),has(${h.srgbColors}u)),c.a);
141
+ }
142
+ `, _ = "\nstruct Frame{viewProj:mat4x4f,viewport:vec4f,depth:vec4f,right:vec4f,up:vec4f,back:vec4f}\n@group(0) @binding(0) var<uniform> frame:Frame;\nfn toLinear(c:vec3f)->vec3f{return select(pow((c+0.055)/1.055,vec3f(2.4)),c/12.92,c<=vec3f(0.04045));}\n\nfn encode(c:vec4f)->vec4f{\n if(frame.viewport.w<0.5){return c;}\n let l=max(c.rgb,vec3f(0.0));\n return vec4f(select(1.055*pow(l,vec3f(1.0/2.4))-0.055,l*12.92,l<=vec3f(0.0031308)),c.a);\n}\n\nconst CORNERS=array<vec2f,4>(vec2f(-1.0,-1.0),vec2f(1.0,-1.0),vec2f(-1.0,1.0),vec2f(1.0,1.0));\n", v = _ + e + `
143
+ struct Cloud{model:mat4x4f,color:vec4f,size:vec4f,flags:vec4u,pad:vec4f,planes:array<vec4f,6>}
144
+ @group(1) @binding(0) var<uniform> cloud:Cloud;
145
+ @group(1) @binding(1) var<storage,read> positions:array<f32>;
146
+ @group(1) @binding(2) var<storage,read> colors:array<u32>;
147
+ @group(1) @binding(3) var<storage,read> sizes:array<f32>;
148
+ @group(1) @binding(4) var<storage,read> order:array<u32>;
149
+ @group(1) @binding(5) var map:texture_2d<f32>;
150
+ @group(1) @binding(6) var mapSampler:sampler;
151
+ ${m(1, 7)}
152
+ struct VOut{
153
+ @builtin(position) clip:vec4f,
154
+ @location(0) color:vec4f,
155
+ @location(1) quad:vec2f,
156
+ @location(2) @interpolate(flat) info:vec4f,
157
+ @location(3) @interpolate(flat) center:vec3f,
158
+ }
159
+ fn has(bit:u32)->bool{return (cloud.flags.x&bit)!=0u;}
160
+ ${g}
161
+ @vertex fn vertex(@builtin(vertex_index) vi:u32,@builtin(instance_index) slot:u32)->VOut{
162
+ var out:VOut;
163
+ var p=slot;
164
+ if(!has(${h.direct}u)){p=order[slot];}
165
+ let world=cloud.model*vec4f(positions[p*3u],positions[p*3u+1u],positions[p*3u+2u],1.0);
166
+ var clip=frame.viewProj*world;
167
+ if(!(clip.w>1e-6)){out.clip=vec4f(0.0,0.0,-1.0,1.0);return out;}
168
+ var size=cloud.size.x;
169
+ if(has(${h.sizes}u)){size*=sizes[p];}
170
+ var px=select(size,size*frame.viewport.z/clip.w,has(${h.world}u));
171
+ px=clamp(px,cloud.size.y,cloud.size.z);
172
+ let radius=0.5*px;
173
+
174
+ let extent=radius+select(0.0,1.0,has(${h.round}u)||has(${h.sphere}u));
175
+ let corner=CORNERS[vi];
176
+ clip=vec4f(clip.xy+corner*extent*2.0/frame.viewport.xy*clip.w,clip.zw);
177
+ var color=cloud.color;
178
+ if(has(${h.colors}u)){color*=pointColor(p);}
179
+
180
+ if(has(${h.mask}u)){let on=margoMaskOn(p);if(margoMaskHidden(on)){out.clip=vec4f(0.0,0.0,-1.0,1.0);return out;}color=margoMaskColor(color,on);}
181
+ out.clip=clip;out.color=color;out.quad=corner*extent;
182
+ out.info=vec4f(radius,select(clip.w,1.0+(1.0-clip.z)/frame.depth.y,frame.depth.w>0.5),radius*clip.w/frame.viewport.z,0.0);
183
+ out.center=world.xyz;
184
+ return out;
185
+ }
186
+
187
+ struct Surface{color:vec4f,nz:f32}
188
+ fn surface(i:VOut)->Surface{
189
+ if(cloud.flags.z!=0u||cloud.flags.w!=1065353216u){let fade=(f32(margoDitherRank(i.clip.xy))+0.5)/16.0;
190
+ if(fade<bitcast<f32>(cloud.flags.z)||fade>=bitcast<f32>(cloud.flags.w)){discard;}}
191
+ let r=max(i.info.x,1e-4);
192
+ let uv=vec2f(0.5+0.5*i.quad.x/r,0.5-0.5*i.quad.y/r);
193
+
194
+ let dims=vec2f(textureDimensions(map));
195
+ let texel=textureSampleLevel(map,mapSampler,clamp(uv,vec2f(0.0),vec2f(1.0)),max(log2(max(dims.x,dims.y)/(2.0*r)),0.0));
196
+ var color=i.color;
197
+ if(has(${h.map}u)){color*=texel;}
198
+ if(color.a<cloud.size.w){discard;}
199
+ var s:Surface;s.nz=1.0;
200
+ if(has(${h.round}u)||has(${h.sphere}u)){
201
+ let d=length(i.quad);
202
+ let coverage=clamp(r+0.5-d,0.0,1.0);
203
+ if(coverage<=0.0){discard;}
204
+ color.a*=coverage;
205
+ if(has(${h.sphere}u)){
206
+ let n2=i.quad/r;
207
+ s.nz=sqrt(max(1.0-dot(n2,n2),0.0));
208
+ let n=frame.right.xyz*n2.x+frame.up.xyz*n2.y+frame.back.xyz*s.nz;
209
+ let l=normalize(frame.right.xyz*-0.35+frame.up.xyz*0.45+frame.back.xyz*0.82);
210
+ color=vec4f(color.rgb*(0.3+0.7*max(dot(n,l),0.0)),color.a);
211
+ }
212
+ } else if(any(abs(i.quad)>vec2f(r))){discard;}
213
+
214
+
215
+ let clipCount=cloud.flags.y&0xffffu;
216
+ if(clipCount>0u){
217
+ let wp=i.center+(frame.right.xyz*i.quad.x+frame.up.xyz*i.quad.y)*(i.info.z/r)
218
+ +frame.back.xyz*select(0.0,s.nz*i.info.z,has(${h.sphere}u));
219
+ var clipBehind=0u;
220
+ for(var p=0u;p<clipCount;p++){if(dot(cloud.planes[p].xyz,wp)+cloud.planes[p].w<0.0){clipBehind++;}}
221
+ if(select(clipBehind>0u,clipBehind==clipCount,(cloud.flags.y&65536u)!=0u)){discard;}
222
+ }
223
+ s.color=encode(color);
224
+ return s;
225
+ }
226
+
227
+ fn sphereDepth(i:VOut,nz:f32)->f32{
228
+ let w=max(i.info.y-i.info.z*nz,frame.depth.z);
229
+ return clamp(select(-frame.depth.x+frame.depth.y/w,1.0-(w-1.0)*frame.depth.y,frame.depth.w>0.5),0.0,1.0);
230
+ }
231
+ struct EdlOut{@location(0) color:vec4f,@location(1) depth:f32}
232
+ struct SphereOut{@location(0) color:vec4f,@builtin(frag_depth) depth:f32}
233
+ struct SphereEdlOut{@location(0) color:vec4f,@location(1) edl:f32,@builtin(frag_depth) depth:f32}
234
+ @fragment fn fragment(i:VOut)->@location(0) vec4f{return surface(i).color;}
235
+ @fragment fn fragmentEdl(i:VOut)->EdlOut{let s=surface(i);return EdlOut(s.color,i.info.y);}
236
+ @fragment fn fragmentSphere(i:VOut)->SphereOut{let s=surface(i);return SphereOut(s.color,sphereDepth(i,s.nz));}
237
+ @fragment fn fragmentSphereEdl(i:VOut)->SphereEdlOut{
238
+ let s=surface(i);
239
+ return SphereEdlOut(s.color,max(i.info.y-i.info.z*s.nz,frame.depth.z),sphereDepth(i,s.nz));
240
+ }
241
+ `, y = _ + "\nstruct Batch{model:mat4x4f,color:vec4f,params:vec4f,planes:array<vec4f,6>}\n@group(1) @binding(0) var<uniform> batch:Batch;\n@group(1) @binding(1) var<storage,read> sprites:array<vec4f>;\n@group(1) @binding(2) var map:texture_2d<f32>;\n@group(1) @binding(3) var mapSampler:sampler;\nstruct VOut{@builtin(position) clip:vec4f,@location(0) color:vec4f,@location(1) uv:vec2f,@location(2) world:vec3f}\n\n@vertex fn vertex(@builtin(vertex_index) vi:u32,@builtin(instance_index) ii:u32)->VOut{\n var out:VOut;\n let a=sprites[ii*4u];let b=sprites[ii*4u+1u];let rect=sprites[ii*4u+2u];let tint=sprites[ii*4u+3u];\n let q=CORNERS[vi]*0.5+0.5;\n let angle=a.w+batch.params.x;\n let local=(q-b.zw)*b.xy;\n let offset=vec2f(local.x*cos(angle)-local.y*sin(angle),local.x*sin(angle)+local.y*cos(angle));\n var world=batch.model*vec4f(a.xyz,1.0);\n var clip:vec4f;\n\n var wp=world.xyz;\n if(batch.params.z>0.0){\n clip=frame.viewProj*world;\n clip=vec4f(clip.xy+offset*batch.params.z*2.0/frame.viewport.xy*clip.w,clip.zw);\n } else {\n wp=world.xyz+frame.right.xyz*offset.x+frame.up.xyz*offset.y;\n clip=frame.viewProj*vec4f(wp,1.0);\n }\n out.clip=clip;out.world=wp;\n out.uv=mix(rect.xy,rect.zw,vec2f(q.x,1.0-q.y));\n out.color=batch.color*tint;\n return out;\n}\n@fragment fn fragment(i:VOut)->@location(0) vec4f{\n\n let dims=vec2f(textureDimensions(map));\n let dx=dpdx(i.uv)*dims;let dy=dpdy(i.uv)*dims;\n let texel=textureSampleLevel(map,mapSampler,i.uv,max(0.5*log2(max(max(dot(dx,dx),dot(dy,dy)),1e-12)),0.0));\n let color=i.color*texel;\n if(color.a<batch.params.y||color.a<=0.0){discard;}\n\n let clipCount=u32(abs(batch.params.w));var clipBehind=0u;\n for(var p=0u;p<clipCount;p++){if(dot(batch.planes[p].xyz,i.world)+batch.planes[p].w<0.0){clipBehind++;}}\n if(clipCount>0u&&select(clipBehind>0u,clipBehind==clipCount,batch.params.w<0.0)){discard;}\n return encode(color);\n}\n", b = {
242
+ point: [
243
+ ["@location(2) @interpolate(flat) info:vec4f,", "@location(2) @interpolate(flat) info:vec4f,@location(4) @interpolate(flat) fog:f32,"],
244
+ ["out.clip=clip;out.color=color;out.quad=corner*extent;", "out.clip=clip;out.color=color;out.quad=corner*extent;out.fog=fogAmount(world.xyz);"],
245
+ ["s.color=encode(color);", "s.color=encode(fogged(color,i.fog));"]
246
+ ],
247
+ sprite: [["return encode(color);", "return encode(fogged(color,fogAmount(i.world)));"]]
248
+ }, x = "@fragment fn fragment(i:VOut)->@location(0) vec4f{";
249
+ function S(e, n, r) {
250
+ let i = r === void 0 ? e === "point" ? v : y : E(e, r);
251
+ if (e === "sprite") {
252
+ if (i.split(x).length !== 2) throw new t("unsupported", "Sprite transparency needs the shader it was written for; update its edit");
253
+ i = i.replace(x, "fn margoShade(i:VOut)->vec4f{");
254
+ }
255
+ return n + i + "fn margoViewDepth(p:vec4f)->f32{return select(1.0/p.w,frame.right.w+(1.0-p.z)/frame.depth.y,frame.depth.w>0.5);}\n" + f(n, "i:VOut", e === "point" ? "surface(i).color" : "margoShade(i)", "i.clip", "margoViewDepth(i.clip)");
256
+ }
257
+ var C = "\nfn packDepth(d:f32)->vec4f{\n let b=bitcast<u32>(d);\n return vec4f(f32(b&255u),f32((b>>8u)&255u),f32((b>>16u)&255u),f32(b>>24u))/255.0;\n}\nfn unpackDepth(c:vec4f)->f32{\n let b=vec4u(round(c*255.0));\n return bitcast<f32>(b.x|(b.y<<8u)|(b.z<<16u)|(b.w<<24u));\n}\n";
258
+ function w(e, n) {
259
+ let r = e;
260
+ for (let [e, i] of n) {
261
+ if (r.split(e).length !== 2) throw new t("unsupported", `Points needs the shaders it was written for; no ${e} to edit.`);
262
+ r = r.replace(e, i);
263
+ }
264
+ return r;
265
+ }
266
+ var T = (e) => w(e, [
267
+ ["struct EdlOut{@location(0) color:vec4f,@location(1) depth:f32}", "struct EdlOut{@location(0) color:vec4f,@location(1) depth:vec4f}"],
268
+ ["@location(1) edl:f32,@builtin(frag_depth)", "@location(1) edl:vec4f,@builtin(frag_depth)"],
269
+ ["return EdlOut(s.color,i.info.y);", "return EdlOut(s.color,packDepth(i.info.y));"],
270
+ ["return SphereEdlOut(s.color,max(i.info.y-i.info.z*s.nz,frame.depth.z),sphereDepth(i,s.nz));", "return SphereEdlOut(s.color,packDepth(max(i.info.y-i.info.z*s.nz,frame.depth.z)),sphereDepth(i,s.nz));"]
271
+ ]) + C;
272
+ function E(e, n) {
273
+ let r = e === "point" ? v : y;
274
+ for (let [n, i] of b[e]) {
275
+ if (r.split(n).length !== 2) throw new t("unsupported", "Points fog needs the shaders it was written for; update the fog edits with them");
276
+ r = r.replace(n, i);
277
+ }
278
+ return r + s(2, 0) + (n ? "fn fogged(c:vec4f,a:f32)->vec4f{return vec4f(c.rgb*(1.0-a),c.a);}" : "fn fogged(c:vec4f,a:f32)->vec4f{return vec4f(mix(c.rgb,margoFog.color.rgb,a),c.a);}");
279
+ }
280
+ var D = "\n@group(0) @binding(0) var depths:texture_2d<f32>;\n@group(0) @binding(1) var<uniform> params:vec4f;\n\nconst RING=array<vec2f,8>(vec2f(1.0,0.0),vec2f(0.70710678,0.70710678),vec2f(0.0,1.0),vec2f(-0.70710678,0.70710678),\n vec2f(-1.0,0.0),vec2f(-0.70710678,-0.70710678),vec2f(0.0,-1.0),vec2f(0.70710678,-0.70710678));\n\n\n\nconst GAIN=32.0;\n@vertex fn vertex(@builtin(vertex_index) i:u32)->@builtin(position) vec4f{\n\n return vec4f(f32(i&1u)*4.0-1.0,f32(i>>1u)*4.0-1.0,0.0,1.0);\n}\n\nfn nearer(c:f32,n:f32)->f32{\n if(n<=0.0){return 0.0;}\n if(params.z>0.0){return max(0.0,(c-n)*params.z);}\n return max(0.0,log2(c)-log2(n));\n}\n@fragment fn fragment(@builtin(position) position:vec4f)->@location(0) vec4f{\n let p=vec2i(position.xy);\n let c=textureLoad(depths,p,0).r;\n if(c<=0.0){discard;}\n let last=vec2i(textureDimensions(depths))-1;\n var sum=0.0;\n for(var k=0;k<8;k++){\n let q=clamp(p+vec2i(round(RING[k]*params.y)),vec2i(0),last);\n sum+=nearer(c,textureLoad(depths,q,0).r);\n }\n let shade=exp(-GAIN*params.x*sum/8.0);\n return vec4f(shade,shade,shade,1.0);\n}\n";
281
+ //#endregion
282
+ export { o as _, _ as a, v as c, d, p as f, a as g, u as h, E as i, y as l, s as m, C as n, T as o, l as p, D as r, g as s, h as t, S as u };
@@ -0,0 +1,52 @@
1
+ /** Flag bits of `Cloud.flags.x`, shared by the plugin and the point shader. */
2
+ export declare const FLAG: {
3
+ readonly colors: 1;
4
+ readonly sizes: 2;
5
+ readonly world: 4;
6
+ readonly round: 8;
7
+ readonly map: 16;
8
+ readonly sphere: 32;
9
+ readonly direct: 64;
10
+ readonly srgbColors: 128;
11
+ readonly floatColors: 256;
12
+ readonly mask: 512;
13
+ };
14
+ /** WGSL: the colour of point `p`, from `colors` (as RGBA8 or float32) in linear, for shaders with `has` and `colors`. */
15
+ export declare const pointColorWgsl: string;
16
+ /**
17
+ * Bytes of the shared frame uniform, the per-cloud uniform and the per-batch sprite uniform. Both per-draw uniforms end
18
+ * with 6 clipping planes: the cloud's at byte 128 (count in `flags.y`), the batch's at byte 96 (count in `params.w`).
19
+ */
20
+ export declare const FRAME_BYTES = 144, CLOUD_BYTES = 224, SPRITE_BYTES = 192;
21
+ /** The frame uniform at group 0 with colour helpers and the quad corners, shared by the point, sprite and surfel shaders. */
22
+ export declare const frameWgsl: string;
23
+ /** Point cloud shader: one instanced quad per point, read from storage buffers through the shuffled slot order. */
24
+ export declare const pointShader: string;
25
+ /** Sprite shader: camera-facing instanced quads. */
26
+ export declare const spriteShader: string;
27
+ /**
28
+ * The point or sprite shader (fogged when `additive` is given: whether it blends additively) with its colour feeding a
29
+ * transparency hook whose `declarations` sit at group 3. The fragment's position w is 1 / clip w, the view depth of a
30
+ * perspective camera; an orthographic one counts it from the near plane.
31
+ */
32
+ export declare function surfaceShader(kind: 'point' | 'sprite', declarations: string, additive?: boolean): string;
33
+ /**
34
+ * A depth as the four bytes of its float, for a target at the compatibility level: r32float cannot be multisampled
35
+ * there and rgba8unorm can. No blending or resolve touches these targets, so the bytes come back exact.
36
+ */
37
+ export declare const depthPacking: string;
38
+ /** `code` with each edit made once; a shader that no longer holds the text is a bug here, not a missed edit. */
39
+ export declare function edited(code: string, edits: readonly (readonly [string, string])[]): string;
40
+ /** `code`, a point shader, with its eye-dome depth output packed by {@link depthPacking}. */
41
+ export declare const packedDepthPoints: (code: string) => string;
42
+ /** The point (`kind` 'point') or sprite shader with scene fog at group 2, for normal or additive blending. */
43
+ export declare function foggedShader(kind: 'point' | 'sprite', additive: boolean): string;
44
+ /**
45
+ * Eye-dome lighting pass (C. Boucheny, PhD thesis, Universite Joseph Fourier, 2009; Boucheny and Ribes, Kitware
46
+ * Source Quarterly, 2011): a full-screen triangle whose output multiplies the scene colour. Each covered pixel compares
47
+ * its depth with 8 neighbours on a ring of `params.y` pixels; neighbours nearer the viewer add their depth step,
48
+ * measured in log2 units (perspective, `params.z` = 0) or as a linear step times `params.z` (orthographic). The shade
49
+ * is `exp(-32 * params.x * mean step)`, so flat areas keep their colour and silhouettes darken.
50
+ * Group 0: binding 0 the r32float depths (0 = no point), binding 1 `params` (strength, radius, orthographic scale, 0).
51
+ */
52
+ export declare const edlShader: string;
@@ -0,0 +1,33 @@
1
+ import type { ColorInput } from '@margoengine/math/color';
2
+
3
+ /**
4
+ * Fog as `@margoengine/environment`'s `Fog` exposes it: pass that Fog, or any object with these fields. Read every
5
+ * frame, so changing the Fog changes the fog at once. Missing fields take Fog's defaults. A negative or non-finite
6
+ * distance, density or falloff (or a non-finite height) throws a RangeError, a malformed colour a TypeError or
7
+ * RangeError, a non-boolean `enabled` a TypeError.
8
+ */
9
+ export interface FogLike {
10
+ /** Fog colour: hex is sRGB, `[r, g, b]` linear. Default '#ffffff'. */
11
+ readonly color?: ColorInput;
12
+ /** Linear fog start distance from the camera. Default 1. */
13
+ readonly near?: number;
14
+ /** Linear fog end distance, where fog is full. Default 1000. */
15
+ readonly far?: number;
16
+ /** Above 0 selects exponential-squared fog `1 - exp(-(density * distance)^2)`. Default 0. */
17
+ readonly density?: number;
18
+ /** Height fog: fog thins by `exp(-heightFalloff * (y - height))` above world height `height`. Default 0 (off). */
19
+ readonly heightFalloff?: number;
20
+ /** World height below which fog is at full strength. Default 0. */
21
+ readonly height?: number;
22
+ /** False mixes in no fog; switching never recompiles. Default true. */
23
+ readonly enabled?: boolean;
24
+ }
25
+
26
+ /** Bytes of the fog uniform: colour and height, near/far/density/falloff, camera position. */
27
+ export const FOG_BYTES: 48;
28
+ /** WGSL: the fog uniform at `@group(group) @binding(binding)` and `fogAmount(world position)`, 0 (clear) to 1. */
29
+ export function fogWgsl(group: number, binding: number): string;
30
+ /** Throws when `fog` is neither null nor an object; `setFog` calls it so a wrong argument fails where it is passed. */
31
+ export function checkFog(fog: FogLike | null): FogLike | null;
32
+ /** Validates `fog` and writes the 12-float fog uniform into `out` (colour sRGB-encoded with `encode`). */
33
+ export function writeFog(fog: FogLike, eye: ArrayLike<number>, out: Float32Array, encode?: boolean): void;
@@ -0,0 +1,53 @@
1
+ /** A reusable pass descriptor drawing over the frame: colour load/store, depth and stencil read only. */
2
+ export function overlayPass(): GPURenderPassDescriptor & {
3
+ colorAttachments: [GPURenderPassColorAttachment];
4
+ depthStencilAttachment: GPURenderPassDepthStencilAttachment;
5
+ };
6
+ /** {@link overlayPass} that also loads and stores depth. */
7
+ export function overlayDepthPass(): GPURenderPassDescriptor & {
8
+ colorAttachments: [GPURenderPassColorAttachment];
9
+ depthStencilAttachment: GPURenderPassDepthStencilAttachment;
10
+ };
11
+ /** Straight (non-premultiplied) alpha blending. */
12
+ export const alphaBlend: GPUBlendState;
13
+ /** Straight alpha blending that leaves the target's alpha channel unchanged: precipitation and other overlays drawn into a frame. */
14
+ export const overlayBlend: GPUBlendState;
15
+
16
+ /** `mesh` when it is null or a core mesh handle (checked live); else a TypeError. */
17
+ export function attachableMesh<M extends { check(): void } | null>(mesh: M): M;
18
+ /**
19
+ * What an order-independent pass offers an effect that is no PBR surface (particles, splats, points), in place of
20
+ * gltf/pbr's transparency hook. Same contract, but `surface` declares `fn margoTransparentAt(color:vec4f,clip:vec4f,
21
+ * depth:f32)->MargoTransparent`: `clip` is the fragment's position builtin, `depth` its view depth.
22
+ */
23
+ export interface SurfaceTransparency {
24
+ /** Module-scope WGSL: `struct MargoTransparent` (one output per target), `margoTransparentAt` and its bindings in `group`. */
25
+ surface(group: number): string;
26
+ /** Layout of those bindings, for an effect with explicit pipeline layouts. */
27
+ readonly layout: readonly GPUBindGroupLayoutEntry[];
28
+ /** Entries for those bindings. */
29
+ bindings(): GPUBindGroupEntry[];
30
+ /** True: declarations hold `override margoKind:u32`, 0 normal, 1 additive; additive surfaces may draw here. */
31
+ readonly blends?: boolean;
32
+ /** Colour targets of the transparent pass, in `MargoTransparent` location order. */
33
+ readonly targets: readonly GPUColorTargetState[];
34
+ /** This frame's transparent pass, begun on the first draw and ended by the owner. */
35
+ begin(): GPURenderPassEncoder;
36
+ }
37
+ /** The fragment entry `transparent` of an effect under a transparency hook: `inputs` are its parameters, the rest WGSL expressions. */
38
+ export function surfaceEntry(declarations: string, inputs: string, color: string, clip: string, depth: string): string;
39
+ /** Holds an effect's transparency hook: `set` takes it and `released`, and returns the remover. */
40
+ export function transparencySlot(): {
41
+ hook?: SurfaceTransparency;
42
+ released?: () => void;
43
+ set(hook: SurfaceTransparency, released?: () => void): () => void;
44
+ };
45
+ /** `hook`'s pass with `pipeline` set, `group` at group 0 and the hook's bindings at group 1, for an effect with an auto layout. */
46
+ export function surfacePass(
47
+ device: GPUDevice,
48
+ hook: SurfaceTransparency,
49
+ pipeline: GPURenderPipeline,
50
+ group: GPUBindGroup,
51
+ ): GPURenderPassEncoder;
52
+ /** The WGSL `make(group)` builds for bind group `group`, made once per group and kept in `cache`. */
53
+ export function groupCode(cache: Map<number, string>, group: number, make: (group: number) => string): string;
@@ -0,0 +1,52 @@
1
+ /** How a selection mask shows unselected and selected elements. */
2
+ export interface MaskStyle {
3
+ /**
4
+ * 'fade' darkens unselected elements to `fade` of their displayed sRGB colour; 'highlight' does that and also moves
5
+ * selected elements `highlightAmount` of the way to `highlight`; 'filter' hides unselected elements. Default 'fade'.
6
+ */
7
+ readonly mode?: 'fade' | 'highlight' | 'filter';
8
+ /** Displayed brightness of unselected elements, in [0, 1]. Default 0.12. */
9
+ readonly fade?: number;
10
+ /** Highlight colour, linear `[r, g, b]`, stored as 8-bit sRGB. Default `[1, 0.4508, 0.0194]` (#ffb326). */
11
+ readonly highlight?: readonly [number, number, number];
12
+ /** How far selected elements move to `highlight`, in [0, 1], stored in 8 bits. Default 0.7. */
13
+ readonly highlightAmount?: number;
14
+ }
15
+
16
+ export const MASK_HEADER: 4;
17
+ export function writeMaskHeader(words: Uint32Array, style: Required<MaskStyle>): Uint32Array;
18
+ export function writeMaskBits(words: Uint32Array, values: ArrayLike<number | boolean>, start?: number): Uint32Array;
19
+ /**
20
+ * The displayed sRGB colour of element `index` (and, for a segment, element `other` too) under the packed mask
21
+ * `words`, exactly as the shader draws it, or null when the mask hides it. `rgb` is its sRGB colour in 0..1 without
22
+ * the mask.
23
+ */
24
+ export function maskColor(
25
+ words: Uint32Array | null,
26
+ rgb: ArrayLike<number>,
27
+ index: number,
28
+ other?: number,
29
+ ): number[] | null;
30
+
31
+ /**
32
+ * The selection mask of a point cloud or line: `setMask` (in each class) packs it, the rest is shared. The mask is a
33
+ * 4-word style header, then one bit an element.
34
+ */
35
+ export abstract class SelectionMasked {
36
+ /** Element count the mask covers. */
37
+ abstract readonly count: number;
38
+ /** The selection mask (see `setMask`): a 4-word style header, then one bit an element; or null. */
39
+ mask: Uint32Array | null;
40
+ /** Bumped when the mask bits or style change, so the next frame uploads them once. @internal */
41
+ maskVersion: number;
42
+ /** How the mask shows elements: mode 'fade' (default), 'highlight' or 'filter', fade 0.12, highlight [1, 0.4508, 0.0194] (#ffb326) at 0.7. */
43
+ get maskStyle(): Readonly<Required<MaskStyle>>;
44
+ /** Changes how the mask shows elements, without touching its bits. */
45
+ setMaskStyle(style: MaskStyle): this;
46
+ /** Overwrites the mask of elements `start ..`; one upload of the mask at the next frame. */
47
+ updateMask(start: number, values: ArrayLike<number | boolean>): this;
48
+ /** Whether element `index` is selected by the mask; true without a mask. */
49
+ isSelected(index: number): boolean;
50
+ /** Validates `style` and makes it the mask style, for `setMask`. @internal */
51
+ takeMaskStyle(style?: MaskStyle): Readonly<Required<MaskStyle>>;
52
+ }
@@ -0,0 +1,18 @@
1
+ /** A style value: number, boolean, string, null, undefined, a vector (an array of numbers) or a regular expression. */
2
+ export type StyleValue = unknown;
3
+ /** Reads one property or point semantic (`POSITION`, `COLOR`, ...) by name. */
4
+ export type StyleRead = (name: string) => StyleValue;
5
+ /** A compiled expression: evaluate it with a property reader. */
6
+ export type StyleEvaluator = (read: StyleRead) => StyleValue;
7
+ /** An expression, a literal, or an ordered list of `[test, result]` conditions. */
8
+ export type StyleSource =
9
+ | string
10
+ | number
11
+ | boolean
12
+ | { conditions: readonly (readonly [string, string | number | boolean])[] };
13
+ /** A style vector holding `values`. */
14
+ export declare function vector(values: ArrayLike<number>): number[];
15
+ /** Compiles one expression. Throws MargoError `state` on a syntax error. */
16
+ export declare function expression(source: string): StyleEvaluator;
17
+ /** Compiles one style property; `fallback` when it is omitted, undefined when no condition is true. */
18
+ export declare function styleProperty(value: StyleSource | undefined, fallback: StyleValue): StyleEvaluator;
@@ -0,0 +1,78 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { Mesh } from '@margoengine/core';
3
+ import { type ColorInput } from './color.js';
4
+ import { SpriteMaterial, type SpriteMaterialOptions } from './material.js';
5
+ import type { PointOwner } from './cloud.js';
6
+ /** Floats per sprite in `SpriteBatch.data`: position xyz, rotation, size wh, center xy, uv rect, linear RGBA. */
7
+ export declare const SPRITE_STRIDE = 16;
8
+ /** Properties of one sprite in a `SpriteBatch`, for `add` and `set`. */
9
+ export interface SpriteOptions {
10
+ /** Local position (the batch's matrix or attached mesh applies). Default [0, 0, 0]. */
11
+ position?: readonly [number, number, number];
12
+ /** Width and height, or one number for a square. World units or CSS pixels per `material.sizeUnits`. Default 1. */
13
+ size?: number | readonly [number, number];
14
+ /** Radians counterclockwise in the screen plane, added to `material.rotation`. Default 0. */
15
+ rotation?: number;
16
+ /** Pivot inside the quad: [0.5, 0.5] is the middle, [0, 0] the bottom left, [1, 1] the top right. Default [0.5, 0.5]. */
17
+ center?: readonly [number, number];
18
+ /** Multiplies the material color. Same formats as materials. Default white. */
19
+ color?: ColorInput;
20
+ /** Alpha multiplier. Default 1. */
21
+ opacity?: number;
22
+ /** Atlas rectangle [u0, v0, u1, v1] with the origin at the top left of the image (see `atlasRect`). Default [0, 0, 1, 1]. */
23
+ uv?: readonly [number, number, number, number];
24
+ }
25
+ /** Options for `new SpriteBatch(...)`. */
26
+ export interface SpriteBatchOptions {
27
+ /** A shared material or options for a new one. Default a new `SpriteMaterial`. */
28
+ material?: SpriteMaterial | SpriteMaterialOptions;
29
+ /** Initial capacity; the batch grows by doubling. Must be a positive integer (RangeError otherwise). Default 64. */
30
+ capacity?: number;
31
+ /** Sprites to add right away. */
32
+ sprites?: readonly SpriteOptions[];
33
+ /** Label for debugging. Default ''. */
34
+ name?: string;
35
+ }
36
+ /**
37
+ * Camera-facing textured quads drawn with one instanced draw call, all sharing a
38
+ * `SpriteMaterial`. Sprites are addressed by index.
39
+ */
40
+ export declare class SpriteBatch {
41
+ name: string;
42
+ visible: boolean;
43
+ /** Column-major model matrix applied to sprite positions when not attached to a mesh. */
44
+ readonly matrix: Float32Array<ArrayBuffer>;
45
+ readonly material: SpriteMaterial;
46
+ /** Instance data, `SPRITE_STRIDE` floats per sprite. Call `markDirty` after writing to it directly. */
47
+ data: Float32Array;
48
+ /** Bumped when the instance buffer must be reallocated. @internal */
49
+ structure: number;
50
+ /** Pending `[start, end)` sprite ranges. @internal */
51
+ readonly dirty: Array<[number, number]>;
52
+ private used;
53
+ private mesh;
54
+ private owner?;
55
+ constructor(options?: SpriteBatchOptions);
56
+ /** Number of sprites. */
57
+ get count(): number;
58
+ get capacity(): number;
59
+ get attachedMesh(): Mesh | null;
60
+ /** Follow a core mesh's world matrix and visibility. */
61
+ attach(mesh: Mesh | null): this;
62
+ /** Appends a sprite and returns its index. */
63
+ add(sprite?: SpriteOptions): number;
64
+ /** Changes some properties of sprite `index`; the rest stay. */
65
+ set(index: number, sprite: SpriteOptions): this;
66
+ /** Removes sprite `index` by moving the last sprite into its slot. Returns the old index of the moved sprite, or -1. */
67
+ remove(index: number): number;
68
+ clear(): this;
69
+ /** Marks sprites `start .. start + count` changed after direct writes to `data`. */
70
+ markDirty(start?: number, count?: number): this;
71
+ /** Detaches from the plugin and frees GPU buffers. */
72
+ dispose(): void;
73
+ [Symbol.dispose]: () => void;
74
+ /** @internal */
75
+ bind(owner: PointOwner | undefined): void;
76
+ private check;
77
+ private write;
78
+ }
@@ -0,0 +1,6 @@
1
+ import type { PointCloud } from './cloud.js';
2
+ /**
3
+ * Every per-point buffer of a cloud is one storage binding, so the widest one bounds the point count: 12 B positions
4
+ * (and surfel normals), 4 B rgba8 or 16 B float colours. Throws before any buffer exists, naming the real ceiling.
5
+ */
6
+ export declare function checkStorage(cloud: PointCloud, limits: GPUSupportedLimits, normals: number): void;