bruce-cesium 7.9.1 → 7.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/bruce-cesium.es5.js +941 -143
  2. package/dist/bruce-cesium.es5.js.map +1 -1
  3. package/dist/bruce-cesium.umd.js +939 -140
  4. package/dist/bruce-cesium.umd.js.map +1 -1
  5. package/dist/lib/bruce-cesium.js +1 -1
  6. package/dist/lib/internal/cesium-patch-pick-splat.js +127 -0
  7. package/dist/lib/internal/cesium-patch-pick-splat.js.map +1 -0
  8. package/dist/lib/internal/cesium-patch-pick-through-ground.js +155 -0
  9. package/dist/lib/internal/cesium-patch-pick-through-ground.js.map +1 -0
  10. package/dist/lib/internal/cesium-patch-splat-order.js +73 -0
  11. package/dist/lib/internal/cesium-patch-splat-order.js.map +1 -0
  12. package/dist/lib/rendering/displaced-surface-primitive.js +17 -0
  13. package/dist/lib/rendering/displaced-surface-primitive.js.map +1 -1
  14. package/dist/lib/rendering/entity-render-engine-model3d.js +10 -10
  15. package/dist/lib/rendering/entity-render-engine-model3d.js.map +1 -1
  16. package/dist/lib/rendering/entity-render-engine-point.js +6 -6
  17. package/dist/lib/rendering/entity-render-engine-point.js.map +1 -1
  18. package/dist/lib/rendering/entity-render-engine-polygon.js +30 -12
  19. package/dist/lib/rendering/entity-render-engine-polygon.js.map +1 -1
  20. package/dist/lib/rendering/entity-render-engine-polyline.js +4 -4
  21. package/dist/lib/rendering/entity-render-engine-polyline.js.map +1 -1
  22. package/dist/lib/rendering/menu-item-manager.js +16 -2
  23. package/dist/lib/rendering/menu-item-manager.js.map +1 -1
  24. package/dist/lib/rendering/menu-item-style-overlay.js +51 -11
  25. package/dist/lib/rendering/menu-item-style-overlay.js.map +1 -1
  26. package/dist/lib/rendering/menu-item-styles.js +9 -1
  27. package/dist/lib/rendering/menu-item-styles.js.map +1 -1
  28. package/dist/lib/rendering/render-managers/entities/entities-loaded-render-manager.js +1 -1
  29. package/dist/lib/rendering/render-managers/entities/entities-loaded-render-manager.js.map +1 -1
  30. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js +1 -1
  31. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js.map +1 -1
  32. package/dist/lib/rendering/tileset-styler.js +14 -9
  33. package/dist/lib/rendering/tileset-styler.js.map +1 -1
  34. package/dist/lib/rendering/visuals-register.js +74 -6
  35. package/dist/lib/rendering/visuals-register.js.map +1 -1
  36. package/dist/lib/rendering/xgrids-render-engine.js +3 -0
  37. package/dist/lib/rendering/xgrids-render-engine.js.map +1 -1
  38. package/dist/lib/utils/drawing-utils.js +241 -75
  39. package/dist/lib/utils/drawing-utils.js.map +1 -1
  40. package/dist/lib/viewer/camera-controls.js +134 -1
  41. package/dist/lib/viewer/camera-controls.js.map +1 -1
  42. package/dist/lib/viewer/viewer-utils.js +6 -0
  43. package/dist/lib/viewer/viewer-utils.js.map +1 -1
  44. package/dist/types/bruce-cesium.d.ts +1 -1
  45. package/dist/types/internal/cesium-patch-pick-splat.d.ts +8 -0
  46. package/dist/types/internal/cesium-patch-pick-through-ground.d.ts +7 -0
  47. package/dist/types/internal/cesium-patch-splat-order.d.ts +2 -0
  48. package/dist/types/rendering/displaced-surface-primitive.d.ts +6 -2
  49. package/dist/types/rendering/menu-item-manager.d.ts +1 -0
  50. package/dist/types/rendering/menu-item-style-overlay.d.ts +22 -4
  51. package/dist/types/rendering/tileset-styler.d.ts +1 -0
  52. package/dist/types/rendering/visuals-register.d.ts +11 -0
  53. package/dist/types/utils/drawing-utils.d.ts +7 -1
  54. package/dist/types/viewer/camera-controls.d.ts +4 -0
  55. package/package.json +1 -1
@@ -111,6 +111,406 @@
111
111
  MeasureUtils.MeasurePolygon = MeasurePolygon;
112
112
  })(exports.MeasureUtils || (exports.MeasureUtils = {}));
113
113
 
114
+ /*
115
+ * Makes pickPosition return an opaque primitive drawn through the ground, not the ground above it, with occlusion off.
116
+ */
117
+ const PICK_THROUGH_GROUND_PATCH_KEY = "_nextspacePickThroughGroundPatch";
118
+ // What the patch saw of the pick depth copy, read by GetPickDepthKind.
119
+ const PICK_DEPTH_KIND_KEY = "_nextspacePickDepthKind";
120
+ // From CesiumJS 1.118 the pick depth copy merges the globe's depth in; only that shader names this variable.
121
+ const MERGE_MARK = "globeDepthPacked";
122
+ // Before 1.118 the copy is a plain repack of the scene depth.
123
+ const LEGACY_MARK = "czm_packDepth(texture";
124
+ /*
125
+ * The merge CesiumJS uses, except that a scene depth farther than the globe is kept unless it is the depth plane.
126
+ */
127
+ const PICK_THROUGH_GROUND_FS = `uniform highp sampler2D colorTexture;
128
+ uniform vec4 u_nextspaceDepthPlane;
129
+ uniform vec2 u_nextspaceFlags;
130
+ in vec2 v_textureCoordinates;
131
+ vec3 nextspaceEye(float depth)
132
+ {
133
+ vec2 uv = (gl_FragCoord.xy - czm_viewport.xy) / czm_viewport.zw;
134
+ if (u_nextspaceFlags.y > 0.5) {
135
+ float fromCamera = pow(2.0, depth * czm_log2FarDepthFromNearPlusOne) - 1.0 + czm_currentFrustum.x;
136
+ vec4 q = czm_inverseProjection * vec4(2.0 * uv - 1.0, 0.0, 1.0);
137
+ vec3 d = q.xyz / q.w;
138
+ return d * (fromCamera / -d.z);
139
+ }
140
+ vec4 e = czm_windowToEyeCoordinates(vec4(gl_FragCoord.xy, depth, 1.0));
141
+ return e.xyz / e.w;
142
+ }
143
+ void main()
144
+ {
145
+ vec4 globeDepthPacked = texture(czm_globeDepthTexture, v_textureCoordinates);
146
+ float globeDepth = czm_unpackDepth(globeDepthPacked);
147
+ float depth = texture(colorTexture, v_textureCoordinates).r;
148
+ bool sceneDepth = depth > 0.0 && depth < 1.0;
149
+ bool keepScene = globeDepth <= 0.0 || globeDepth >= 1.0 || depth < globeDepth && sceneDepth;
150
+ if (!keepScene && sceneDepth && u_nextspaceFlags.x > 0.5) {
151
+ vec3 p = nextspaceEye(depth);
152
+ keepScene = abs(dot(u_nextspaceDepthPlane.xyz, p) + u_nextspaceDepthPlane.w) > max(0.5, 0.002 * length(p));
153
+ }
154
+ out_FragColor = keepScene ? czm_packDepth(depth) : globeDepthPacked;
155
+ }
156
+ `;
157
+ /*
158
+ * The depth plane CesiumJS draws once the globe's depth is cleared, as a unit-normal plane in world coordinates.
159
+ */
160
+ function GetDepthPlaneWorld(cameraPosition, radii, offset, result) {
161
+ // Mirrors DepthPlane's computeDepthQuad: the plane through the limb, in the ellipsoid's scaled space.
162
+ const rx = radii.x + offset;
163
+ const ry = radii.y + offset;
164
+ const rz = radii.z + offset;
165
+ const qx = cameraPosition.x / rx;
166
+ const qy = cameraPosition.y / ry;
167
+ const qz = cameraPosition.z / rz;
168
+ const qm = Math.sqrt(qx * qx + qy * qy + qz * qz);
169
+ const nx = qx / qm / rx;
170
+ const ny = qy / qm / ry;
171
+ const nz = qz / qm / rz;
172
+ const nm = Math.sqrt(nx * nx + ny * ny + nz * nz);
173
+ return Cesium.Cartesian4.fromElements(nx / nm, ny / nm, nz / nm, -(1 / qm) / nm, result);
174
+ }
175
+ /*
176
+ * Moves a world plane into eye coordinates, keeping its normal unit length so distances stay in metres.
177
+ */
178
+ function GetPlaneEye(planeWorld, inverseView, result) {
179
+ const transposed = Cesium.Matrix4.transpose(inverseView, new Cesium.Matrix4());
180
+ Cesium.Matrix4.multiplyByVector(transposed, planeWorld, result);
181
+ const m = Math.sqrt(result.x * result.x + result.y * result.y + result.z * result.z);
182
+ return Cesium.Cartesian4.divideByScalar(result, m, result);
183
+ }
184
+ /*
185
+ * What the viewer's pick depth holds, as far as the patch has seen.
186
+ */
187
+ function GetPickDepthKind(viewer) {
188
+ var _a, _b, _c;
189
+ return (_c = (_b = (_a = viewer === null || viewer === void 0 ? void 0 : viewer.scene) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b[PICK_DEPTH_KIND_KEY]) !== null && _c !== void 0 ? _c : "unknown";
190
+ }
191
+ /*
192
+ * Patches the viewer's pick depth copy so a primitive seen through the ground picks itself.
193
+ */
194
+ function InstallPickThroughGroundPatch(viewer) {
195
+ var _a, _b, _c;
196
+ const scene = viewer === null || viewer === void 0 ? void 0 : viewer.scene;
197
+ const context = scene === null || scene === void 0 ? void 0 : scene.context;
198
+ if (!context || typeof context.createViewportQuadCommand !== "function") {
199
+ return false;
200
+ }
201
+ if (context[PICK_THROUGH_GROUND_PATCH_KEY]) {
202
+ return true;
203
+ }
204
+ const plane = new Cesium.Cartesian4();
205
+ const planeWorld = new Cesium.Cartesian4();
206
+ const flags = new Cesium.Cartesian2();
207
+ const updatePlane = () => {
208
+ var _a, _b, _c, _d;
209
+ const env = scene._environmentState;
210
+ const camera = scene.camera;
211
+ const on = Boolean((env === null || env === void 0 ? void 0 : env.clearGlobeDepth) &&
212
+ (env === null || env === void 0 ? void 0 : env.useDepthPlane) &&
213
+ ((_a = camera === null || camera === void 0 ? void 0 : camera.frustum) === null || _a === void 0 ? void 0 : _a.fov) != null &&
214
+ scene.mode === Cesium.SceneMode.SCENE3D &&
215
+ scene.globe);
216
+ flags.x = on ? 1 : 0;
217
+ flags.y = ((_b = scene.frameState) === null || _b === void 0 ? void 0 : _b.useLogDepth) ? 1 : 0;
218
+ if (on) {
219
+ const offset = (_d = (_c = scene._depthPlane) === null || _c === void 0 ? void 0 : _c._ellipsoidOffset) !== null && _d !== void 0 ? _d : 0;
220
+ GetDepthPlaneWorld(camera.positionWC, scene.globe.ellipsoid.radii, offset, planeWorld);
221
+ GetPlaneEye(planeWorld, camera.inverseViewMatrix, plane);
222
+ }
223
+ };
224
+ const original = context.createViewportQuadCommand;
225
+ context.createViewportQuadCommand = function (fragmentShaderSource, overrides) {
226
+ try {
227
+ if (typeof fragmentShaderSource === "string" && (overrides === null || overrides === void 0 ? void 0 : overrides.uniformMap)) {
228
+ if (fragmentShaderSource.includes(MERGE_MARK) && overrides.uniformMap.colorTexture) {
229
+ context[PICK_DEPTH_KIND_KEY] = "merged";
230
+ overrides.uniformMap.u_nextspaceDepthPlane = () => {
231
+ updatePlane();
232
+ return plane;
233
+ };
234
+ overrides.uniformMap.u_nextspaceFlags = () => flags;
235
+ fragmentShaderSource = PICK_THROUGH_GROUND_FS;
236
+ context[PICK_DEPTH_KIND_KEY] = "through-ground";
237
+ }
238
+ else if (fragmentShaderSource.includes(LEGACY_MARK) && overrides.uniformMap.u_texture) {
239
+ context[PICK_DEPTH_KIND_KEY] = "legacy";
240
+ }
241
+ }
242
+ }
243
+ catch (e) {
244
+ console.error("Failed to patch the pick depth merge.", e);
245
+ }
246
+ return original.call(this, fragmentShaderSource, overrides);
247
+ };
248
+ // A pick depth made before this point rebuilds its copy on the next frame.
249
+ for (const view of [scene.view, scene.defaultView]) {
250
+ for (const pickDepth of (_a = view === null || view === void 0 ? void 0 : view.pickDepths) !== null && _a !== void 0 ? _a : []) {
251
+ if (pickDepth === null || pickDepth === void 0 ? void 0 : pickDepth._copyDepthCommand) {
252
+ (_c = (_b = pickDepth._copyDepthCommand.shaderProgram) === null || _b === void 0 ? void 0 : _b.destroy) === null || _c === void 0 ? void 0 : _c.call(_b);
253
+ pickDepth._copyDepthCommand = undefined;
254
+ }
255
+ }
256
+ }
257
+ context[PICK_THROUGH_GROUND_PATCH_KEY] = true;
258
+ return true;
259
+ }
260
+
261
+ /*
262
+ * Makes XGrids splats pick only where they are visibly drawn, not across their faint halos.
263
+ */
264
+ const PICK_SPLAT_PATCH_KEY = "_nextspacePickSplatPatch";
265
+ // The XGrids SDK compiles its splat shaders with this define.
266
+ const SPLAT_DEFINE = "LccShader";
267
+ // CesiumJS's derived pick shader keeps every fragment with any alpha at all.
268
+ const ANY_ALPHA = /(out_FragColor|out_FragData_0|gl_FragColor)\.a == 0\.0/;
269
+ /*
270
+ * The least opacity a splat fragment needs to be picked; tuned against the SDK's own raycast on real scans.
271
+ */
272
+ const SPLAT_PICK_MIN_ALPHA = 0.25;
273
+ /*
274
+ * Raises the alpha a derived splat "pick" shader needs before it keeps a fragment, returning whether it did.
275
+ */
276
+ function FixSplatPick(keyword, options) {
277
+ const fragment = options === null || options === void 0 ? void 0 : options.fragmentShaderSource;
278
+ const defines = fragment === null || fragment === void 0 ? void 0 : fragment.defines;
279
+ const sources = fragment === null || fragment === void 0 ? void 0 : fragment.sources;
280
+ if (keyword !== "pick" ||
281
+ !Array.isArray(defines) ||
282
+ !Array.isArray(sources) ||
283
+ !defines.includes(SPLAT_DEFINE) ||
284
+ !sources.some(x => typeof x === "string" && ANY_ALPHA.test(x))) {
285
+ return false;
286
+ }
287
+ fragment.sources = sources.map(x => typeof x === "string" ? x.replace(ANY_ALPHA, `$1.a < ${SPLAT_PICK_MIN_ALPHA.toFixed(3)}`) : x);
288
+ return true;
289
+ }
290
+ /*
291
+ * Whether a pick result is an XGrids splat mesh rather than a Cesium primitive or Entity.
292
+ */
293
+ function IsSplatPick(picked) {
294
+ var _a;
295
+ return Boolean(picked &&
296
+ typeof picked.id === "string" &&
297
+ typeof ((_a = picked.primitive) === null || _a === void 0 ? void 0 : _a.splatCount) === "number");
298
+ }
299
+ /*
300
+ * Patches a viewer's shader cache so splat pick shaders drop their near-transparent fragments.
301
+ */
302
+ function InstallPickSplatPatch(viewer) {
303
+ var _a, _b;
304
+ const cache = (_b = (_a = viewer === null || viewer === void 0 ? void 0 : viewer.scene) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.shaderCache;
305
+ if (!cache || typeof cache.createDerivedShaderProgram !== "function") {
306
+ return false;
307
+ }
308
+ if (cache[PICK_SPLAT_PATCH_KEY]) {
309
+ return true;
310
+ }
311
+ const original = cache.createDerivedShaderProgram;
312
+ cache.createDerivedShaderProgram = function (shaderProgram, keyword, options) {
313
+ try {
314
+ FixSplatPick(keyword, options);
315
+ }
316
+ catch (e) {
317
+ console.error("Failed to fix a splat pick shader.", e);
318
+ }
319
+ return original.call(this, shaderProgram, keyword, options);
320
+ };
321
+ cache[PICK_SPLAT_PATCH_KEY] = true;
322
+ return true;
323
+ }
324
+ // The XGrids render objects drawn on a viewer, so picking only looks for splats when there are some.
325
+ const SPLATS_KEY = "_nextspaceSplats";
326
+ /*
327
+ * Records that a splat render object is drawn on, or removed from, a viewer.
328
+ */
329
+ function TrackSplats(viewer, renderObject, drawn) {
330
+ var _a;
331
+ if (!viewer || !renderObject) {
332
+ return;
333
+ }
334
+ const set = (_a = viewer[SPLATS_KEY]) !== null && _a !== void 0 ? _a : (viewer[SPLATS_KEY] = new Set());
335
+ if (drawn) {
336
+ set.add(renderObject);
337
+ }
338
+ else {
339
+ set.delete(renderObject);
340
+ }
341
+ }
342
+ /*
343
+ * Whether any XGrids splats are drawn on a viewer.
344
+ */
345
+ function HasSplats(viewer) {
346
+ var _a;
347
+ return Boolean((_a = viewer === null || viewer === void 0 ? void 0 : viewer[SPLATS_KEY]) === null || _a === void 0 ? void 0 : _a.size);
348
+ }
349
+ /*
350
+ * Whether pick results for splats follow what is visibly drawn, so a splat can be trusted to hide what is behind it.
351
+ */
352
+ function IsSplatPickVisible(viewer) {
353
+ var _a, _b, _c;
354
+ return Boolean((_c = (_b = (_a = viewer === null || viewer === void 0 ? void 0 : viewer.scene) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.shaderCache) === null || _c === void 0 ? void 0 : _c[PICK_SPLAT_PATCH_KEY]);
355
+ }
356
+ /*
357
+ * Whether the SDK raycasts splats as opacity-weighted ellipsoids (usePrecisionRaycast) rather than points.
358
+ */
359
+ function IsSplatRaycastPrecise(viewer) {
360
+ var _a, _b;
361
+ const set = viewer === null || viewer === void 0 ? void 0 : viewer[SPLATS_KEY];
362
+ if (!(set === null || set === void 0 ? void 0 : set.size)) {
363
+ return false;
364
+ }
365
+ for (const object of Array.from(set)) {
366
+ try {
367
+ if ((_b = (_a = object === null || object === void 0 ? void 0 : object.getCurrentConfig) === null || _a === void 0 ? void 0 : _a.call(object)) === null || _b === void 0 ? void 0 : _b.usePrecisionRaycast) {
368
+ return true;
369
+ }
370
+ }
371
+ catch (e) {
372
+ // A disposed scan has no config; the others still answer.
373
+ }
374
+ }
375
+ return false;
376
+ }
377
+
378
+ const ACCURATE_PICK_KEY = "_nextspaceAccuratePick";
379
+ // A repeat pick at the same pixel within this long, with the camera still, returns the last result.
380
+ const ACCURATE_PICK_CACHE_MS = 3000;
381
+ // Beyond this a splat raycast gives up; matches what Navigator always asked the SDK for.
382
+ const SPLAT_MAX_DISTANCE = 1000;
383
+ // A point raycast this thin still finds a splat a pixel covers at close range without catching ones beside it.
384
+ const SPLAT_MIN_RADIUS = 0.005;
385
+ // A precise raycast only uses the radius to shortlist splats before testing their ellipsoids.
386
+ const SPLAT_PRECISE_SHORTLIST = 0.5;
387
+ /*
388
+ * Whether a cached accurate pick still answers: the same pixel, a still camera and recent enough.
389
+ */
390
+ function isCacheValid(cache, camera, cursor, pickOnly) {
391
+ if (cache.pickOnly !== pickOnly || performance.now() - cache.time > ACCURATE_PICK_CACHE_MS) {
392
+ return false;
393
+ }
394
+ // Same pixel only; a neighbour's answer steps a pointer-following cursor and corrupts normals read from picks.
395
+ if (Cesium.Cartesian2.distanceSquared(cursor, cache.cursor) >= 0.25) {
396
+ return false;
397
+ }
398
+ const p = camera.positionWC;
399
+ const q = cache.cameraPosition;
400
+ if (Math.abs(p.x - q.x) > 2 || Math.abs(p.y - q.y) > 2 || Math.abs(p.z - q.z) > 2) {
401
+ return false;
402
+ }
403
+ const cos = Cesium.Cartesian3.dot(camera.directionWC, cache.cameraDirection) /
404
+ (Cesium.Cartesian3.magnitude(camera.directionWC) * Cesium.Cartesian3.magnitude(cache.cameraDirection));
405
+ if (Math.acos(Math.min(1, cos)) > Cesium.Math.toRadians(5)) {
406
+ return false;
407
+ }
408
+ const width = camera.frustum instanceof Cesium.OrthographicFrustum ? camera.frustum.width : null;
409
+ return width === cache.frustumWidth || (width != null && cache.frustumWidth != null && Math.abs(width - cache.frustumWidth) < 1e-6);
410
+ }
411
+ /*
412
+ * Whether pickPosition is right over the ground with occlusion off: CesiumJS 1.118+, unknown before a first frame.
413
+ */
414
+ function isPickPositionFixed(viewer) {
415
+ const kind = GetPickDepthKind(viewer);
416
+ return kind === "through-ground" || kind === "merged";
417
+ }
418
+ /*
419
+ * Whether the terrain provider can answer a globe pick yet.
420
+ */
421
+ function isTerrainReady(viewer) {
422
+ return Boolean(viewer.terrainProvider && viewer.terrainProvider["ready"] != false);
423
+ }
424
+ /*
425
+ * The size of one screen pixel at a distance from the camera, in metres.
426
+ */
427
+ function pixelSizeAt(scene, distance) {
428
+ const height = scene.canvas.clientHeight;
429
+ const frustum = scene.camera.frustum;
430
+ if (frustum instanceof Cesium.OrthographicFrustum) {
431
+ return frustum.width / Math.max(1, scene.canvas.clientWidth);
432
+ }
433
+ const fovy = frustum === null || frustum === void 0 ? void 0 : frustum.fovy;
434
+ if (!height || !fovy) {
435
+ return 0;
436
+ }
437
+ return 2 * distance * Math.tan(fovy / 2) / height;
438
+ }
439
+ /*
440
+ * Whether a pick result is something pickOnly positions land on: a tileset, a model or an Entity with a model.
441
+ */
442
+ function isPositionObject(object) {
443
+ const entity = (object === null || object === void 0 ? void 0 : object.id) instanceof Cesium.Entity ? object.id : null;
444
+ return Boolean(object instanceof Cesium.Cesium3DTileFeature ||
445
+ object instanceof Cesium.Cesium3DTileset ||
446
+ (object === null || object === void 0 ? void 0 : object.primitive) instanceof Cesium.Cesium3DTileset ||
447
+ (object === null || object === void 0 ? void 0 : object.primitive) instanceof Cesium.Model ||
448
+ (entity === null || entity === void 0 ? void 0 : entity.model));
449
+ }
450
+ /*
451
+ * The front-most pickOnly object under a cursor, skipping ignored ones; drillPick only when there are any to skip.
452
+ */
453
+ function pickObject(scene, cursor, ignored) {
454
+ if (!(ignored === null || ignored === void 0 ? void 0 : ignored.length)) {
455
+ return isPositionObject(scene.pick(cursor, 1, 1));
456
+ }
457
+ const objects = scene.drillPick(cursor, ignored.length + 1, 3, 3);
458
+ for (const object of objects) {
459
+ const owner = (object === null || object === void 0 ? void 0 : object.id) instanceof Cesium.Entity ? object.id : object;
460
+ if (ignored.includes(owner) || ignored.includes(object)) {
461
+ continue;
462
+ }
463
+ return isPositionObject(object);
464
+ }
465
+ return false;
466
+ }
467
+ /*
468
+ * Workarounds for CesiumJS before 1.118, whose pickPosition hit the depth plane over the ground (cesium#4368).
469
+ */
470
+ function legacyPick(viewer, cursor, pixel, pickOnly, ignored) {
471
+ var _a, _b, _c, _d, _e;
472
+ const scene = viewer.scene;
473
+ let pos3d = null;
474
+ if (!pickOnly && ((_a = scene.globe) === null || _a === void 0 ? void 0 : _a.depthTestAgainstTerrain)) {
475
+ pos3d = (_b = scene.pickPosition(pixel)) !== null && _b !== void 0 ? _b : null;
476
+ }
477
+ else {
478
+ if (!pickOnly) {
479
+ pos3d = (_c = scene.pickPosition(pixel)) !== null && _c !== void 0 ? _c : null;
480
+ }
481
+ if (pos3d) {
482
+ const carto = Cesium.Cartographic.fromCartesian(pos3d);
483
+ if (!carto || carto.height < 0) {
484
+ pos3d = null;
485
+ }
486
+ }
487
+ if (!pos3d) {
488
+ if (scene.pickPositionSupported && pickObject(scene, cursor, ignored)) {
489
+ pos3d = (_d = scene.pickPosition(pixel)) !== null && _d !== void 0 ? _d : null;
490
+ }
491
+ if (!pickOnly && !pos3d && scene.globe && isTerrainReady(viewer)) {
492
+ const ray = scene.camera.getPickRay(cursor);
493
+ pos3d = ray ? ((_e = scene.globe.pick(ray, scene)) !== null && _e !== void 0 ? _e : null) : null;
494
+ }
495
+ }
496
+ }
497
+ // A tileset the depth missed can still be found by rendering along the ray.
498
+ if (!pos3d && scene.mode === Cesium.SceneMode.SCENE3D && typeof scene.pickFromRay === "function") {
499
+ const picked = scene.pick(cursor, 1, 1);
500
+ if (picked instanceof Cesium.Cesium3DTileFeature || (picked === null || picked === void 0 ? void 0 : picked.primitive) instanceof Cesium.Cesium3DTileset) {
501
+ try {
502
+ const hit = scene.pickFromRay(scene.camera.getPickRay(cursor), []);
503
+ if ((hit === null || hit === void 0 ? void 0 : hit.position) && BModels.Cartes.ValidateCartes3(hit.position)) {
504
+ pos3d = hit.position;
505
+ }
506
+ }
507
+ catch (e) {
508
+ console.error(e);
509
+ }
510
+ }
511
+ }
512
+ return pos3d;
513
+ }
114
514
  const [C3] = [Cesium.Cartesian3];
115
515
  function getT(t, alpha, p0, p1) {
116
516
  const d = C3.subtract(p1, p0, new C3);
@@ -441,91 +841,119 @@
441
841
  return pos3d;
442
842
  }
443
843
  DrawingUtils.EnsurePosHeight = EnsurePosHeight;
844
+ /*
845
+ * The splat surface under a screen position when a splat is front-most there, raycast no further than behind.
846
+ */
847
+ function GetSplatPosition(params) {
848
+ const { viewer, cursor, behind } = params;
849
+ if (!HasSplats(viewer) || typeof LCCRender === "undefined") {
850
+ return null;
851
+ }
852
+ const scene = viewer.scene;
853
+ if (!IsSplatPick(scene.pick(cursor, 1, 1))) {
854
+ return null;
855
+ }
856
+ const ray = scene.camera.getPickRay(cursor);
857
+ if (!ray) {
858
+ return null;
859
+ }
860
+ const maxDistance = behind ? Cesium.Cartesian3.distance(ray.origin, behind) : SPLAT_MAX_DISTANCE;
861
+ const precise = IsSplatRaycastPrecise(viewer);
862
+ // A point raycast is a cylinder, so make it a pixel wide where it ends; nearer it is wider than a pixel.
863
+ const radius = precise ? SPLAT_PRECISE_SHORTLIST : Math.max(SPLAT_MIN_RADIUS, pixelSizeAt(scene, Math.min(maxDistance, SPLAT_MAX_DISTANCE)));
864
+ let hit = null;
865
+ try {
866
+ if (typeof LCCRender.raycastFromOrigin === "function") {
867
+ const query = {
868
+ origin: { x: ray.origin.x, y: ray.origin.y, z: ray.origin.z },
869
+ direction: { x: ray.direction.x, y: ray.direction.y, z: ray.direction.z },
870
+ maxDistance,
871
+ radius
872
+ };
873
+ if (precise) {
874
+ query.opacityThreshold = SPLAT_PICK_MIN_ALPHA;
875
+ }
876
+ hit = LCCRender.raycastFromOrigin(query);
877
+ }
878
+ else if (typeof LCCRender.raycast === "function") {
879
+ hit = LCCRender.raycast({ evt: cursor, maxDistance, radius });
880
+ }
881
+ }
882
+ catch (e) {
883
+ console.error("Failed to raycast splats.", e);
884
+ return null;
885
+ }
886
+ if (!hit || !isFinite(hit.x) || !isFinite(hit.y) || !isFinite(hit.z)) {
887
+ return null;
888
+ }
889
+ return new Cesium.Cartesian3(hit.x, hit.y, hit.z);
890
+ }
891
+ DrawingUtils.GetSplatPosition = GetSplatPosition;
892
+ /*
893
+ * Moves a window position to its drawing-buffer pixel's centre, where pickPosition reads the depth.
894
+ */
895
+ function PixelCentre(scene, cursor) {
896
+ const xScale = scene.drawingBufferWidth / scene.canvas.clientWidth;
897
+ const yScale = scene.drawingBufferHeight / scene.canvas.clientHeight;
898
+ if (!isFinite(xScale) || !isFinite(yScale) || !xScale || !yScale) {
899
+ return new Cesium.Cartesian2(cursor.x, cursor.y);
900
+ }
901
+ return new Cesium.Cartesian2((Math.floor(cursor.x * xScale) + 0.5) / xScale, (Math.floor(cursor.y * yScale) + 0.5) / yScale);
902
+ }
903
+ DrawingUtils.PixelCentre = PixelCentre;
444
904
  /**
445
905
  * Returns an accurate 3d position from a given screen position.
446
906
  * @param viewer
447
907
  * @param cursor
448
908
  * @returns
449
909
  */
450
- DrawingUtils.GetAccuratePosition = (() => {
451
- let cachedPick = null;
452
- let cacheTimestamp = null;
453
- let cachedCameraState = null;
454
- let cachedPickOnlyState = null;
455
- return (viewer, cursor, pickOnly = false, ignoredPickOnly) => {
456
- const scene = viewer.scene;
457
- const camera = scene.camera;
458
- // Check if we can use cached position.
459
- if (cachedPick && cacheTimestamp && cachedPickOnlyState === pickOnly) {
460
- const timeElapsed = Date.now() - cacheTimestamp;
461
- const isWithinCacheDuration = timeElapsed < 3000; // 3 seconds
462
- const isNearPreviousPick = Cesium.Cartesian2.distanceSquared(cursor, cachedPick.cursor) < 9; // 3 pixels
463
- const directionDot = Cesium.Cartesian3.dot(camera.directionWC, cachedCameraState.direction);
464
- const directionLengths = Cesium.Cartesian3.magnitude(camera.directionWC) * Cesium.Cartesian3.magnitude(cachedCameraState.direction);
465
- const angle = Math.acos(directionDot / directionLengths);
466
- const hasCameraMoved = Math.abs(camera.positionWC.x - cachedCameraState.position.x) > 2 || // 2 meters
467
- Math.abs(camera.positionWC.y - cachedCameraState.position.y) > 2 ||
468
- angle > Cesium.Math.toRadians(5); // 5 degrees
469
- if (isWithinCacheDuration && isNearPreviousPick && !hasCameraMoved) {
470
- return cachedPick.position;
471
- }
472
- }
473
- // Actual picking logic
474
- // https://community.cesium.com/t/scene-pick-returning-point-inside-the-globe/18940/9
475
- let pos3d = null;
476
- // Means we can accurately pick right now.
477
- if (!pickOnly && scene.globe.depthTestAgainstTerrain) {
478
- pos3d = scene.pickPosition(cursor);
479
- }
480
- // Means we cannot guarantee an accurate pick.
481
- // We want to prioritize pick-position when we can, so we'll try use it and if the result is sus then we'll use some fallbacks.
482
- else {
483
- if (!pickOnly) {
484
- pos3d = scene.pickPosition(cursor);
485
- }
486
- if (Cesium.defined(pos3d)) {
487
- const carto = Cesium.Cartographic.fromCartesian(pos3d);
488
- if (!Cesium.defined(carto) || carto.height < 0) {
489
- pos3d = null;
490
- }
491
- }
492
- if (!Cesium.defined(pos3d)) {
493
- pos3d = null;
494
- const ray = scene.camera.getPickRay(cursor);
495
- if (scene.pickPositionSupported) {
496
- const pickedObjects = scene.drillPick(cursor, !(ignoredPickOnly === null || ignoredPickOnly === void 0 ? void 0 : ignoredPickOnly.length) ? 1 : ignoredPickOnly.length + 1, 3, 3);
497
- for (let i = 0; i < pickedObjects.length; i++) {
498
- let object = pickedObjects[i];
499
- object = (object && object.id && object.id instanceof Cesium.Entity ? object.id : object);
500
- if (object &&
501
- (!ignoredPickOnly || !ignoredPickOnly.includes(object)) &&
502
- (object instanceof Cesium.Cesium3DTileFeature ||
503
- object instanceof Cesium.Cesium3DTileset ||
504
- (object instanceof Cesium.Entity && object.model))) {
505
- pos3d = scene.pickPosition(cursor);
506
- break;
507
- }
508
- }
509
- }
510
- if (!pickOnly && !Cesium.defined(pos3d)) {
511
- pos3d = scene.globe.pick(ray, scene);
512
- }
513
- }
910
+ function GetAccuratePosition(viewer, cursor, pickOnly = false, ignoredPickOnly) {
911
+ var _a, _b, _c, _d;
912
+ const scene = viewer === null || viewer === void 0 ? void 0 : viewer.scene;
913
+ // A hidden viewer's canvas has no size, and picking it throws from a frustum of NaN.
914
+ if (!scene || !((_a = scene.canvas) === null || _a === void 0 ? void 0 : _a.clientWidth) || !((_b = scene.canvas) === null || _b === void 0 ? void 0 : _b.clientHeight)) {
915
+ return null;
916
+ }
917
+ const camera = scene.camera;
918
+ const canCache = !(ignoredPickOnly === null || ignoredPickOnly === void 0 ? void 0 : ignoredPickOnly.length);
919
+ const cache = viewer[ACCURATE_PICK_KEY];
920
+ if (canCache && cache && isCacheValid(cache, camera, cursor, pickOnly)) {
921
+ return cache.position;
922
+ }
923
+ const pixel = PixelCentre(scene, cursor);
924
+ let pos3d = null;
925
+ if (!isPickPositionFixed(viewer)) {
926
+ pos3d = legacyPick(viewer, cursor, pixel, pickOnly, ignoredPickOnly);
927
+ }
928
+ else if (pickOnly) {
929
+ if (pickObject(scene, cursor, ignoredPickOnly)) {
930
+ pos3d = (_c = scene.pickPosition(pixel)) !== null && _c !== void 0 ? _c : null;
931
+ }
932
+ }
933
+ else {
934
+ // The pick depth holds the globe here too, so no depth means no ground drawn; a globe pick only costs.
935
+ pos3d = (_d = scene.pickPosition(pixel)) !== null && _d !== void 0 ? _d : null;
936
+ }
937
+ if (!pickOnly) {
938
+ const splat = GetSplatPosition({ viewer, cursor, behind: pos3d !== null && pos3d !== void 0 ? pos3d : undefined });
939
+ if (splat) {
940
+ pos3d = splat;
514
941
  }
515
- // Update cache.
516
- cachedPick = {
942
+ }
943
+ if (canCache) {
944
+ viewer[ACCURATE_PICK_KEY] = {
517
945
  position: pos3d,
518
- cursor: cursor.clone()
519
- };
520
- cacheTimestamp = Date.now();
521
- cachedCameraState = {
522
- position: camera.positionWC.clone(),
523
- direction: camera.directionWC.clone()
946
+ cursor: cursor.clone(),
947
+ pickOnly,
948
+ time: performance.now(),
949
+ cameraPosition: camera.positionWC.clone(),
950
+ cameraDirection: camera.directionWC.clone(),
951
+ frustumWidth: camera.frustum instanceof Cesium.OrthographicFrustum ? camera.frustum.width : null
524
952
  };
525
- cachedPickOnlyState = pickOnly;
526
- return pos3d;
527
- };
528
- })();
953
+ }
954
+ return pos3d;
955
+ }
956
+ DrawingUtils.GetAccuratePosition = GetAccuratePosition;
529
957
  /**
530
958
  * Smooths a given set of points.
531
959
  * @param points
@@ -1214,6 +1642,126 @@
1214
1642
  const horizon = Math.sqrt(2 * ellipsoidOf(state).maximumRadius * Math.max(height, 0));
1215
1643
  return Math.max(PLAUSIBLE_PICK_FLOOR, height * 10, horizon * 1.5);
1216
1644
  }
1645
+ // Window radii, in drawing buffer pixels, searched for the surface around a gap between point cloud points.
1646
+ const GAP_RADII = [2, 4, 8, 12];
1647
+ // A pick this many times farther than the surface around it, plus the slack in metres, looked through a gap.
1648
+ const GAP_FARTHER = 1.5;
1649
+ const GAP_SLACK = 0.5;
1650
+ // Directions around the centre, and how many must hold nearer pixels for the centre to be surrounded.
1651
+ const GAP_SECTORS = 8;
1652
+ const GAP_SECTORS_NEAR = 6;
1653
+ const PACKED_DEPTH = new Cesium.Cartesian4(1, 1 / 255, 1 / 65025, 1 / 16581375);
1654
+ /*
1655
+ * Distances along the view axis drawn around a window position, rows bottom-up, Infinity where nothing is drawn.
1656
+ */
1657
+ function readDepthDistances(scene, position, radius) {
1658
+ var _a, _b, _c, _d, _e;
1659
+ const view = (_a = scene._view) !== null && _a !== void 0 ? _a : scene.view;
1660
+ const frustums = view === null || view === void 0 ? void 0 : view.frustumCommandsList;
1661
+ if (!(frustums === null || frustums === void 0 ? void 0 : frustums.length) ||
1662
+ typeof ((_b = scene._picking) === null || _b === void 0 ? void 0 : _b.getPickDepth) !== "function" ||
1663
+ typeof ((_c = scene.context) === null || _c === void 0 ? void 0 : _c.readPixels) !== "function") {
1664
+ return null;
1665
+ }
1666
+ const bufferX = position.x * scene.drawingBufferWidth / scene.canvas.clientWidth;
1667
+ const bufferY = position.y * scene.drawingBufferHeight / scene.canvas.clientHeight;
1668
+ if (!Number.isFinite(bufferX) || !Number.isFinite(bufferY)) {
1669
+ return null;
1670
+ }
1671
+ const x = Math.floor(bufferX) - radius;
1672
+ // The same row pickPosition reads for this position, so a pixel found here is the one it then returns.
1673
+ const y = Math.floor(scene.drawingBufferHeight - bufferY) - radius;
1674
+ const width = 2 * radius + 1;
1675
+ const logDepth = Boolean((_d = scene.frameState) === null || _d === void 0 ? void 0 : _d.useLogDepth);
1676
+ const distances = new Float64Array(width * width).fill(Infinity);
1677
+ // Farthest frustum first, so a nearer frustum's depth overwrites it.
1678
+ for (let f = frustums.length - 1; f >= 0; f--) {
1679
+ const framebuffer = (_e = scene._picking.getPickDepth(scene, f)) === null || _e === void 0 ? void 0 : _e.framebuffer;
1680
+ if (!framebuffer) {
1681
+ continue;
1682
+ }
1683
+ const near = frustums[f].near;
1684
+ const far = frustums[f].far;
1685
+ const pixels = scene.context.readPixels({ x, y, width, height: width, framebuffer });
1686
+ for (let i = 0; i < distances.length; i++) {
1687
+ const o = 4 * i;
1688
+ const packed = pixels[o] * PACKED_DEPTH.x + pixels[o + 1] * PACKED_DEPTH.y +
1689
+ pixels[o + 2] * PACKED_DEPTH.z + pixels[o + 3] * PACKED_DEPTH.w;
1690
+ const depth = packed / 255;
1691
+ if (depth > 0 && depth < 1) {
1692
+ // Undoes CesiumJS's logarithmic depth, or the perspective projection's depth when that is off.
1693
+ distances[i] = logDepth ?
1694
+ Math.pow(2, depth * Math.log2(far - near + 1)) - 1 + near :
1695
+ 2 * near * far / ((far + near) - (2 * depth - 1) * (far - near));
1696
+ }
1697
+ }
1698
+ }
1699
+ return distances;
1700
+ }
1701
+ /*
1702
+ * Offsets of the surface pixel around the centre for each radius where clearly nearer pixels surround it.
1703
+ */
1704
+ function FindGapSurfaces(distances, radius) {
1705
+ const width = 2 * radius + 1;
1706
+ const centre = distances[radius * width + radius];
1707
+ const found = [];
1708
+ for (const r of GAP_RADII) {
1709
+ if (r > radius) {
1710
+ break;
1711
+ }
1712
+ const near = [];
1713
+ const sectors = new Set();
1714
+ for (let dy = -r; dy <= r; dy++) {
1715
+ for (let dx = -r; dx <= r; dx++) {
1716
+ const distance = distances[(radius + dy) * width + (radius + dx)];
1717
+ // Nearer by the same margin that later decides the centre looked through a gap.
1718
+ if ((dx || dy) && distance * GAP_FARTHER + GAP_SLACK < centre) {
1719
+ near.push([distance, dx, dy]);
1720
+ const turn = (Math.atan2(dy, dx) + Math.PI) / (2 * Math.PI);
1721
+ sectors.add(Math.floor(turn * GAP_SECTORS) % GAP_SECTORS);
1722
+ }
1723
+ }
1724
+ }
1725
+ // An object's silhouette covers half the directions at most; points around a gap cover nearly all of them.
1726
+ if (sectors.size >= GAP_SECTORS_NEAR) {
1727
+ near.sort((a, b) => a[0] - b[0]);
1728
+ // The middle of the near pixels by distance stands for the surface, past stray points in front of it.
1729
+ const surface = near[Math.floor(near.length / 2)];
1730
+ found.push({ dx: surface[1], dy: surface[2] });
1731
+ }
1732
+ }
1733
+ return found;
1734
+ }
1735
+ /*
1736
+ * The point cloud surface around a pick that looked through a gap between its points, or null when it did not.
1737
+ */
1738
+ function fillGap(scene, position, picked) {
1739
+ const radius = GAP_RADII[GAP_RADII.length - 1];
1740
+ let distances = null;
1741
+ try {
1742
+ distances = readDepthDistances(scene, position, radius);
1743
+ }
1744
+ catch (e) {
1745
+ return null;
1746
+ }
1747
+ if (!distances) {
1748
+ return null;
1749
+ }
1750
+ const eye = scene.camera.positionWC;
1751
+ const pickedDistance = picked ? Cesium.Cartesian3.distance(eye, picked) : Infinity;
1752
+ const xScale = scene.canvas.clientWidth / scene.drawingBufferWidth;
1753
+ const yScale = scene.canvas.clientHeight / scene.drawingBufferHeight;
1754
+ for (const { dx, dy } of FindGapSurfaces(distances, radius)) {
1755
+ // Buffer rows run bottom-up, window rows top-down.
1756
+ const surface = scene.pickPosition(new Cesium.Cartesian2(position.x + dx * xScale, position.y - dy * yScale));
1757
+ if (!surface) {
1758
+ continue;
1759
+ }
1760
+ const distance = Cesium.Cartesian3.distance(eye, surface);
1761
+ return pickedDistance > distance * GAP_FARTHER + GAP_SLACK ? surface : null;
1762
+ }
1763
+ return null;
1764
+ }
1217
1765
  /*
1218
1766
  * The point under a screen position: what is drawn there, else the ground plane, else a point at the last distance.
1219
1767
  */
@@ -1234,7 +1782,18 @@
1234
1782
  picked = null;
1235
1783
  }
1236
1784
  }
1785
+ // Splats write no depth, so without this the camera turns and zooms about whatever is behind them.
1786
+ const ahead = isAhead(camera, picked) ? picked : undefined;
1787
+ const splat = exports.DrawingUtils.GetSplatPosition({ viewer, cursor: position, behind: ahead });
1788
+ if (splat) {
1789
+ return { point: splat, source: "pick", ground: false };
1790
+ }
1237
1791
  const plausible = plausibleDistance(state);
1792
+ // A click between point cloud points sees the background; turning or zooming about that throws the camera far off.
1793
+ const surface = scene.pickPositionSupported ? fillGap(scene, position, ahead !== null && ahead !== void 0 ? ahead : null) : null;
1794
+ if (isAhead(camera, surface) && Cesium.Cartesian3.distance(surface, camera.positionWC) < plausible) {
1795
+ return { point: surface, source: "pick", ground: false };
1796
+ }
1238
1797
  if (isAhead(camera, picked) && Cesium.Cartesian3.distance(picked, camera.positionWC) < plausible) {
1239
1798
  return { point: picked, source: "pick", ground: isGroundPick(state, position) };
1240
1799
  }
@@ -13501,6 +14060,25 @@
13501
14060
  VisualRegisterCuller.MarkShouldRecheck = MarkShouldRecheck;
13502
14061
  })(exports.VisualRegisterCuller || (exports.VisualRegisterCuller = {}));
13503
14062
 
14063
+ // A splat this close in front of a visual still lets it be picked, so scans laid over models do not steal clicks.
14064
+ const SPLAT_HIDES_MIN = 0.25;
14065
+ const SPLAT_HIDES_RATIO = 0.01;
14066
+ /*
14067
+ * Whether a drilled splat's visible surface lies clearly in front of what the depth shows at the cursor.
14068
+ */
14069
+ function isSplatInFront(viewer, cursor, behind) {
14070
+ // The drill found a splat somewhere in its area; this asks again at the cursor's own pixel.
14071
+ const hit = exports.DrawingUtils.GetSplatPosition({ viewer, cursor });
14072
+ if (!hit) {
14073
+ return false;
14074
+ }
14075
+ if (!behind) {
14076
+ return true;
14077
+ }
14078
+ const eye = viewer.scene.camera.positionWC;
14079
+ const visual = Cesium.Cartesian3.distance(eye, behind);
14080
+ return Cesium.Cartesian3.distance(eye, hit) < visual - Math.max(SPLAT_HIDES_MIN, visual * SPLAT_HIDES_RATIO);
14081
+ }
13504
14082
  function isTilesetFeatureAlive(visual) {
13505
14083
  var _a, _b;
13506
14084
  const cTileset = visual === null || visual === void 0 ? void 0 : visual.tileset;
@@ -13710,7 +14288,7 @@
13710
14288
  }
13711
14289
  }
13712
14290
  function updateEntity(viewer, entityId, register, refresh, cache = {}) {
13713
- var _a, _b, _c;
14291
+ var _a, _b, _c, _d;
13714
14292
  if (!entityId) {
13715
14293
  // What are we doing?
13716
14294
  return;
@@ -13797,7 +14375,8 @@
13797
14375
  }
13798
14376
  }
13799
14377
  if (refresh === true || (refresh !== false && (refresh === null || refresh === void 0 ? void 0 : refresh.opacity))) {
13800
- let effectiveOpacity = state.opacity;
14378
+ // An Entity's own opacity wins over the one its menu item's bookmark style asks for.
14379
+ let effectiveOpacity = (_b = state.opacity) !== null && _b !== void 0 ? _b : register.GetMenuItemOpacity(rego.menuItemId);
13801
14380
  if ((effectiveOpacity == null || effectiveOpacity == 1) && !state.isolated && visible) {
13802
14381
  if (cache.isolationOpacity === undefined) {
13803
14382
  cache.isolationOpacity = register.GetIsolationOpacity();
@@ -13828,14 +14407,14 @@
13828
14407
  exports.EntityLabel.Attach({
13829
14408
  rego,
13830
14409
  viewer,
13831
- api: (_b = register.ApiGetters) === null || _b === void 0 ? void 0 : _b.GetBruceApi(),
14410
+ api: (_c = register.ApiGetters) === null || _c === void 0 ? void 0 : _c.GetBruceApi(),
13832
14411
  visualRegister: register,
13833
14412
  options: labelGroup ? labelGroup.options : register.GetLabelDefaults(),
13834
14413
  groupId: labelGroup === null || labelGroup === void 0 ? void 0 : labelGroup.groupId,
13835
14414
  persistent: true
13836
14415
  });
13837
14416
  }
13838
- else if (!visible || ((_c = exports.EntityLabel.GetLabel({ rego })) === null || _c === void 0 ? void 0 : _c.Persistent)) {
14417
+ else if (!visible || ((_d = exports.EntityLabel.GetLabel({ rego })) === null || _d === void 0 ? void 0 : _d.Persistent)) {
13839
14418
  exports.EntityLabel.Detatch({
13840
14419
  rego, force: true
13841
14420
  });
@@ -14001,6 +14580,8 @@
14001
14580
  // When no Menu Item ID is set, then the second key is a blank string.
14002
14581
  // If an Entity ID state is set without a Menu Item ID, then it acts as a default for all Menu Items.
14003
14582
  this.states = {};
14583
+ // Opacity a whole menu item is drawn at, from its bookmark style; never a saved state.
14584
+ this.menuItemOpacities = new Map();
14004
14585
  // Queue of Entity updates to process in batches to avoid overloading the render loop.
14005
14586
  this.updateQueue = [];
14006
14587
  // Mirrors updateQueue for O(1) "already queued" checks.
@@ -14985,7 +15566,7 @@
14985
15566
  return;
14986
15567
  }
14987
15568
  this.dimmingDirty = false;
14988
- const dimming = Object.values(this.states).some(states => Object.values(states).some(state => state.isolated || (state.opacity != null && state.opacity < 1)));
15569
+ const dimming = Object.values(this.states).some(states => Object.values(states).some(state => state.isolated || (state.opacity != null && state.opacity < 1))) || this.menuItemOpacities.size > 0;
14989
15570
  if (!exports.CesiumEntityStyler.SetDimming(this.viewer, this.id, dimming)) {
14990
15571
  return;
14991
15572
  }
@@ -16335,9 +16916,25 @@
16335
16916
  const width = Math.ceil(EnsureNumber(params.width, 5));
16336
16917
  const height = Math.ceil(EnsureNumber(params.height, 5));
16337
16918
  const pickLimit = Math.ceil(EnsureNumber(params.pickLimit, 5));
16338
- const picked = this.viewer.scene.drillPick(new Cesium.Cartesian2(cursor.x, cursor.y), pickLimit, width, height);
16919
+ const scene = this.viewer.scene;
16920
+ const position = new Cesium.Cartesian2(cursor.x, cursor.y);
16921
+ // Splats are only trusted to hide what is behind them once their pick follows what is visibly drawn.
16922
+ const splatsHide = HasSplats(this.viewer) && IsSplatPickVisible(this.viewer);
16923
+ // Read before drillPick, which leaves pickPosition reading its own pick pass.
16924
+ const behind = splatsHide ? scene.pickPosition(exports.DrawingUtils.PixelCentre(scene, position)) : null;
16925
+ let splatChecked = false;
16926
+ const picked = scene.drillPick(position, pickLimit, width, height);
16339
16927
  for (let i = 0; i < picked.length; i++) {
16340
16928
  const object = picked[i];
16929
+ if (splatsHide && IsSplatPick(object)) {
16930
+ if (!found.length && !splatChecked) {
16931
+ splatChecked = true;
16932
+ if (isSplatInFront(this.viewer, position, behind)) {
16933
+ break;
16934
+ }
16935
+ }
16936
+ continue;
16937
+ }
16341
16938
  const entity = (object && object.id && object.id instanceof Cesium.Entity ? object.id : object);
16342
16939
  const visual = entity;
16343
16940
  if (((_a = visual === null || visual === void 0 ? void 0 : visual._register) === null || _a === void 0 ? void 0 : _a.Id) == this.id) {
@@ -16555,6 +17152,34 @@
16555
17152
  }
16556
17153
  return (totalOpacity && totalTicks) ? (totalOpacity / totalTicks) : totalOpacity != null && typeof totalOpacity == "number" ? totalOpacity : 1;
16557
17154
  }
17155
+ /**
17156
+ * Draws every Entity of a menu item at this opacity unless it has its own; null puts them back.
17157
+ * It is not a visual state, so a Bookmark save does not store it per Entity.
17158
+ */
17159
+ SetMenuItemOpacity(params) {
17160
+ var _a, _b, _c;
17161
+ const { menuItemId, opacity } = params;
17162
+ const wanted = typeof opacity === "number" && opacity >= 0 && opacity < 1 ? opacity : null;
17163
+ if (((_a = this.menuItemOpacities.get(menuItemId)) !== null && _a !== void 0 ? _a : null) === wanted) {
17164
+ return;
17165
+ }
17166
+ if (wanted == null) {
17167
+ this.menuItemOpacities.delete(menuItemId);
17168
+ }
17169
+ else {
17170
+ this.menuItemOpacities.set(menuItemId, wanted);
17171
+ }
17172
+ this.dimmingDirty = true;
17173
+ const entityIds = new Set(this.GetRegos({ menuItemId }).map(rego => rego.entityId).filter(Boolean));
17174
+ entityIds.forEach(entityId => this.queueUpdate({ entityId, refresh: { opacity: true } }));
17175
+ if (params.requestRender !== false) {
17176
+ (_c = (_b = this.viewer) === null || _b === void 0 ? void 0 : _b.scene) === null || _c === void 0 ? void 0 : _c.requestRender();
17177
+ }
17178
+ }
17179
+ GetMenuItemOpacity(menuItemId) {
17180
+ var _a;
17181
+ return menuItemId ? ((_a = this.menuItemOpacities.get(menuItemId)) !== null && _a !== void 0 ? _a : null) : null;
17182
+ }
16558
17183
  ClearOpacity(params) {
16559
17184
  const clearedIds = new Set();
16560
17185
  this.ForEachState((state) => {
@@ -16922,18 +17547,57 @@
16922
17547
  BModels.MenuItem.EType.EntitiesLoaded,
16923
17548
  BModels.MenuItem.EType.DataLab
16924
17549
  ];
17550
+ // The row every Entities render manager draws an item with when it names none.
17551
+ const DEFAULT_ZOOM_ROW = {
17552
+ MinZoom: 0,
17553
+ MaxZoom: 200000,
17554
+ DisplayType: BModels.ZoomControl.EDisplayType.Model3D,
17555
+ LODCategoryID: "glb",
17556
+ LODLevel: 0,
17557
+ StyleID: 0
17558
+ };
17559
+ // Instructions an overlay carries that are not style fields, so a merge never copies them onto a style.
17560
+ const INSTRUCTION_KEYS = ["types", "expandSources", "opacity"];
16925
17561
  /**
16926
- * Returns the base style with each field the overlay sets laid over it.
17562
+ * Returns the base style with each field the overlay sets laid over it, then its style for the Entity Type when given.
16927
17563
  */
16928
- function Merge(base, overlay) {
16929
- var _a, _b;
17564
+ function Merge(base, overlay, entityTypeId) {
17565
+ var _a;
16930
17566
  if (!overlay) {
16931
17567
  return base;
16932
17568
  }
16933
- const merged = { ...(base !== null && base !== void 0 ? base : {}) };
17569
+ const merged = layFields({ ...(base !== null && base !== void 0 ? base : {}) }, overlay);
17570
+ const typed = entityTypeId ? (_a = overlay.types) === null || _a === void 0 ? void 0 : _a[entityTypeId] : null;
17571
+ return typed ? layFields(merged, typed) : merged;
17572
+ }
17573
+ MenuItemStyleOverlay.Merge = Merge;
17574
+ /**
17575
+ * Returns whether an overlay paints a model fill, for the layer or for any Entity Type in it.
17576
+ */
17577
+ function SetsModelFill(overlay) {
17578
+ var _a;
17579
+ if (!overlay) {
17580
+ return false;
17581
+ }
17582
+ const types = Object.values((_a = overlay.types) !== null && _a !== void 0 ? _a : {});
17583
+ return [overlay, ...types].some(style => { var _a; return isSet((_a = style === null || style === void 0 ? void 0 : style.modelStyle) === null || _a === void 0 ? void 0 : _a.fillColor); });
17584
+ }
17585
+ MenuItemStyleOverlay.SetsModelFill = SetsModelFill;
17586
+ /**
17587
+ * Returns whether an overlay asks for attributes read from the Entities' sources.
17588
+ */
17589
+ function ExpandsSources(overlay) {
17590
+ return Boolean(overlay === null || overlay === void 0 ? void 0 : overlay.expandSources);
17591
+ }
17592
+ MenuItemStyleOverlay.ExpandsSources = ExpandsSources;
17593
+ /*
17594
+ * Lays each style field an overlay sets onto a copy already taken, leaving its instructions behind.
17595
+ */
17596
+ function layFields(merged, overlay) {
17597
+ var _a, _b;
16934
17598
  for (const key of Object.keys(overlay)) {
16935
17599
  const value = overlay[key];
16936
- if (!isSet(value)) {
17600
+ if (INSTRUCTION_KEYS.includes(key) || !isSet(value)) {
16937
17601
  continue;
16938
17602
  }
16939
17603
  if (isPlainObject(value)) {
@@ -16949,12 +17613,11 @@
16949
17613
  }
16950
17614
  return merged;
16951
17615
  }
16952
- MenuItemStyleOverlay.Merge = Merge;
16953
17616
  /**
16954
- * Returns the overlay a zoom control row carries laid over the style it resolved.
17617
+ * Returns the overlay a zoom control row carries laid over the style it resolved, for an Entity of the given type.
16955
17618
  */
16956
- function ApplyRow(style, row) {
16957
- return Merge(style, row === null || row === void 0 ? void 0 : row.StyleOverlay);
17619
+ function ApplyRow(style, row, entityTypeId) {
17620
+ return Merge(style, row === null || row === void 0 ? void 0 : row.StyleOverlay, entityTypeId);
16958
17621
  }
16959
17622
  MenuItemStyleOverlay.ApplyRow = ApplyRow;
16960
17623
  /**
@@ -16993,7 +17656,7 @@
16993
17656
  * Returns a copy carrying the overlay, or the item itself when it cannot take one and carries none.
16994
17657
  */
16995
17658
  function With(item, overlay) {
16996
- var _a;
17659
+ var _a, _b;
16997
17660
  const target = Supports(item) ? overlay : null;
16998
17661
  if (!target && !Get(item)) {
16999
17662
  return item;
@@ -17009,9 +17672,11 @@
17009
17672
  return next;
17010
17673
  }
17011
17674
  const zItem = item;
17675
+ // An item with no rows is drawn on the render managers' own default row, which has to carry the overlay too.
17676
+ const rows = ((_a = zItem.CameraZoomSettings) === null || _a === void 0 ? void 0 : _a.length) || !target ? ((_b = zItem.CameraZoomSettings) !== null && _b !== void 0 ? _b : []) : [{ ...DEFAULT_ZOOM_ROW }];
17012
17677
  return {
17013
17678
  ...zItem,
17014
- CameraZoomSettings: ((_a = zItem.CameraZoomSettings) !== null && _a !== void 0 ? _a : []).map(row => {
17679
+ CameraZoomSettings: rows.map(row => {
17015
17680
  const next = { ...row };
17016
17681
  if (target) {
17017
17682
  next.StyleOverlay = target;
@@ -17213,6 +17878,8 @@
17213
17878
  this.scenario = 0;
17214
17879
  // Indicates that we should expand the sources of the Entity.
17215
17880
  this.expandSources = false;
17881
+ // What the item itself asks for, which an overlay reading sourced attributes can only add to.
17882
+ this.ownExpandSources = false;
17216
17883
  // Indicates that we are retrieving historic records.
17217
17884
  // This means that the current scene's time is included in the request.
17218
17885
  this.historic = false;
@@ -17278,8 +17945,9 @@
17278
17945
  this.applyStyles = Boolean(applyStyles);
17279
17946
  }
17280
17947
  if (expandSources != null) {
17281
- this.expandSources = expandSources;
17948
+ this.ownExpandSources = expandSources;
17282
17949
  }
17950
+ this.expandSources = this.ownExpandSources || exports.MenuItemStyleOverlay.ExpandsSources(this.styleOverlay);
17283
17951
  if (fallbackStyleId != null) {
17284
17952
  this.fallbackStyleId = fallbackStyleId;
17285
17953
  }
@@ -17416,11 +18084,13 @@
17416
18084
  this.historic = params.historic;
17417
18085
  }
17418
18086
  if (params.expandSources != null) {
17419
- if (this.expandSources != params.expandSources) {
17420
- this.shouldUpdateRegoStates = true;
17421
- }
17422
- this.expandSources = params.expandSources;
18087
+ this.ownExpandSources = params.expandSources;
18088
+ }
18089
+ const expandSources = this.ownExpandSources || exports.MenuItemStyleOverlay.ExpandsSources(this.styleOverlay);
18090
+ if (this.expandSources != expandSources) {
18091
+ this.shouldUpdateRegoStates = true;
17423
18092
  }
18093
+ this.expandSources = expandSources;
17424
18094
  // Reload styles.
17425
18095
  if (this.loaded) {
17426
18096
  this.styledEntityIds.clear();
@@ -17495,12 +18165,12 @@
17495
18165
  * Replaces the tileset's own colours while an overlay sets a model fill, so features show exactly what it maps to.
17496
18166
  */
17497
18167
  applyOverlayBlend() {
17498
- var _a, _b, _c, _d;
18168
+ var _a, _b;
17499
18169
  if (!this.cTileset || ((_b = (_a = this.cTileset).isDestroyed) === null || _b === void 0 ? void 0 : _b.call(_a))) {
17500
18170
  return;
17501
18171
  }
17502
- const fill = (_d = (_c = this.styleOverlay) === null || _c === void 0 ? void 0 : _c.modelStyle) === null || _d === void 0 ? void 0 : _d.fillColor;
17503
- const colours = Array.isArray(fill) ? fill.length > 0 : fill != null;
18172
+ // A fill for one Entity Type replaces too, as does a hide, which is a fully transparent fill.
18173
+ const colours = exports.MenuItemStyleOverlay.SetsModelFill(this.styleOverlay);
17504
18174
  if (colours && this.blendBeforeOverlay == null) {
17505
18175
  this.blendBeforeOverlay = this.cTileset.colorBlendMode;
17506
18176
  this.cTileset.colorBlendMode = Cesium.Cesium3DTileColorBlendMode.REPLACE;
@@ -17976,7 +18646,7 @@
17976
18646
  style = (_b = this.fallbackStyle) === null || _b === void 0 ? void 0 : _b.Settings;
17977
18647
  styleId = this.fallbackStyleId != null ? Number(this.fallbackStyleId) : null;
17978
18648
  }
17979
- style = exports.MenuItemStyleOverlay.Merge(style, this.styleOverlay);
18649
+ style = exports.MenuItemStyleOverlay.Merge(style, this.styleOverlay, entityTypeId);
17980
18650
  if (!style || !((_c = style === null || style === void 0 ? void 0 : style.modelStyle) === null || _c === void 0 ? void 0 : _c.customize)) {
17981
18651
  return { settings: null, styleId: null };
17982
18652
  }
@@ -22383,7 +23053,7 @@
22383
23053
  console.error(e);
22384
23054
  }
22385
23055
  }
22386
- style = exports.MenuItemStyleOverlay.ApplyRow(style, zoomItem);
23056
+ style = exports.MenuItemStyleOverlay.ApplyRow(style, zoomItem, entityTypeId);
22387
23057
  const pStyle = (_g = style === null || style === void 0 ? void 0 : style.polygonStyle) !== null && _g !== void 0 ? _g : {};
22388
23058
  const lStyle = (_h = style === null || style === void 0 ? void 0 : style.polylineStyle) !== null && _h !== void 0 ? _h : {};
22389
23059
  const polygonsClamped = ((_j = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _j === void 0 ? void 0 : _j.id) == null ? true : ((_k = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _k === void 0 ? void 0 : _k.id) == 0;
@@ -23484,7 +24154,7 @@
23484
24154
  if (!style) {
23485
24155
  style = zoomItem === null || zoomItem === void 0 ? void 0 : zoomItem.Style;
23486
24156
  }
23487
- style = exports.MenuItemStyleOverlay.ApplyRow(style, zoomItem);
24157
+ style = exports.MenuItemStyleOverlay.ApplyRow(style, zoomItem, entityTypeId);
23488
24158
  const pStyle = (_h = style === null || style === void 0 ? void 0 : style.polygonStyle) !== null && _h !== void 0 ? _h : {};
23489
24159
  const lStyle = (_j = style === null || style === void 0 ? void 0 : style.polylineStyle) !== null && _j !== void 0 ? _j : {};
23490
24160
  const polygonsClamped = ((_k = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _k === void 0 ? void 0 : _k.id) == null ? true : ((_l = pStyle === null || pStyle === void 0 ? void 0 : pStyle.altitudeOption) === null || _l === void 0 ? void 0 : _l.id) == 0;
@@ -30436,6 +31106,7 @@
30436
31106
  if (typeof obj.setLodAutoLevelUp === "function") {
30437
31107
  obj.setLodAutoLevelUp(true);
30438
31108
  }
31109
+ TrackSplats(viewer, obj, true);
30439
31110
  return obj;
30440
31111
  }
30441
31112
  XGridsRenderEngine.Render = Render;
@@ -30470,6 +31141,7 @@
30470
31141
  console.warn("[XGridsRenderEngine] Remove() LCCRender library not available.");
30471
31142
  return;
30472
31143
  }
31144
+ TrackSplats(viewer, renderObject, false);
30473
31145
  LCCRender.unload(renderObject);
30474
31146
  }
30475
31147
  XGridsRenderEngine.Remove = Remove;
@@ -34955,7 +35627,15 @@
34955
35627
  if (laid == null) {
34956
35628
  return next;
34957
35629
  }
34958
- return exports.MenuItemStyleOverlay.WithItemStyle(next, itemStyle);
35630
+ // These two only run a Styler with Apply Styles on, and a bookmark that lays colours on one needs them drawn; opacity alone does not.
35631
+ const inline = exports.MenuItemStyleOverlay.GetItemStyle(alternation);
35632
+ const drawsStyle = inline
35633
+ ? Object.keys(inline).some(key => key !== "opacity" && key !== "expandSources")
35634
+ : exports.MenuItemStyleOverlay.GetItemStyleId(alternation) != null;
35635
+ const styled = drawsStyle && (next.Type === BModels.MenuItem.EType.ArbTileset || next.Type === BModels.MenuItem.EType.EntityTileset) && !next.ApplyStyles
35636
+ ? { ...next, ApplyStyles: true }
35637
+ : next;
35638
+ return exports.MenuItemStyleOverlay.WithItemStyle(styled, itemStyle);
34959
35639
  }
34960
35640
  MenuItemStyles.ApplyAlternation = ApplyAlternation;
34961
35641
  /**
@@ -35706,6 +36386,7 @@
35706
36386
  }
35707
36387
  }
35708
36388
  if (rItem.renderManager && !((_g = rItem.renderManager) === null || _g === void 0 ? void 0 : _g.Disposed)) {
36389
+ this.syncItemOpacity(rItem);
35709
36390
  (_h = this.onUpdate) === null || _h === void 0 ? void 0 : _h.Trigger({ isEnabling: true, itemId: rItem.id });
35710
36391
  }
35711
36392
  return rItem.id;
@@ -35716,7 +36397,7 @@
35716
36397
  * @param params
35717
36398
  */
35718
36399
  RemoveItemById(params) {
35719
- var _a, _b;
36400
+ var _a, _b, _c;
35720
36401
  let { menuItemId: id, recursive, allowHandoff } = params;
35721
36402
  if (this.viewer.isDestroyed()) {
35722
36403
  return;
@@ -35751,8 +36432,9 @@
35751
36432
  }
35752
36433
  this.ClearSeriesSegments(item.id);
35753
36434
  }
36435
+ (_b = this.visualsRegister) === null || _b === void 0 ? void 0 : _b.SetMenuItemOpacity({ menuItemId: item.id, opacity: null, requestRender: false });
35754
36436
  this.items = this.items.filter(x => x.id !== id);
35755
- (_b = this.onUpdate) === null || _b === void 0 ? void 0 : _b.Trigger({ isEnabling: false, itemId: item.id });
36437
+ (_c = this.onUpdate) === null || _c === void 0 ? void 0 : _c.Trigger({ isEnabling: false, itemId: item.id });
35756
36438
  }
35757
36439
  }
35758
36440
  /**
@@ -35791,6 +36473,7 @@
35791
36473
  const next = exports.MenuItemStyleOverlay.With(chosen, this.getEffectiveOverlay(chosen, this.styleOverlay));
35792
36474
  rItem.renderManager.SwapStyle(next);
35793
36475
  rItem.item = next;
36476
+ this.syncItemOpacity(rItem);
35794
36477
  (_a = this.onUpdate) === null || _a === void 0 ? void 0 : _a.Trigger({ isEnabling: true, itemId: rItem.id });
35795
36478
  return true;
35796
36479
  }
@@ -35830,9 +36513,18 @@
35830
36513
  }
35831
36514
  rItem.renderManager.SwapStyle(next);
35832
36515
  rItem.item = next;
36516
+ this.syncItemOpacity(rItem);
35833
36517
  (_c = this.onUpdate) === null || _c === void 0 ? void 0 : _c.Trigger({ isEnabling: true, itemId: rItem.id });
35834
36518
  }
35835
36519
  }
36520
+ /*
36521
+ * Draws an item at the opacity its bookmark style asks for, or opaque again once none is asked.
36522
+ */
36523
+ syncItemOpacity(rItem) {
36524
+ var _a, _b;
36525
+ const wanted = (_a = exports.MenuItemStyleOverlay.GetItemStyle(rItem.item)) === null || _a === void 0 ? void 0 : _a.opacity;
36526
+ (_b = this.visualsRegister) === null || _b === void 0 ? void 0 : _b.SetMenuItemOpacity({ menuItemId: rItem.id, opacity: typeof wanted === "number" ? wanted : null });
36527
+ }
35836
36528
  /**
35837
36529
  * Lays an inline style or any Style record on one enabled item under the scene-wide one; neither clears it.
35838
36530
  */
@@ -35856,6 +36548,7 @@
35856
36548
  const next = exports.MenuItemStyleOverlay.With(styled, this.getEffectiveOverlay(styled, this.styleOverlay));
35857
36549
  rItem.renderManager.SwapStyle(next);
35858
36550
  rItem.item = next;
36551
+ this.syncItemOpacity(rItem);
35859
36552
  (_a = this.onUpdate) === null || _a === void 0 ? void 0 : _a.Trigger({ isEnabling: true, itemId: rItem.id });
35860
36553
  return true;
35861
36554
  }
@@ -35905,6 +36598,7 @@
35905
36598
  const next = exports.MenuItemStyleOverlay.With(rItem.item, effective);
35906
36599
  rItem.renderManager.SwapStyle(next);
35907
36600
  rItem.item = next;
36601
+ this.syncItemOpacity(rItem);
35908
36602
  (_b = this.onUpdate) === null || _b === void 0 ? void 0 : _b.Trigger({ isEnabling: true, itemId: rItem.id });
35909
36603
  }
35910
36604
  }
@@ -48879,6 +49573,72 @@
48879
49573
  return true;
48880
49574
  }
48881
49575
 
49576
+ /*
49577
+ * Draws XGrids splats after the opaque meshes, so a mesh drawn later cannot paint over nearer splats.
49578
+ */
49579
+ const SPLAT_ORDER_PATCH_KEY = "_nextspaceSplatOrderPatch";
49580
+ /*
49581
+ * Whether a command is one of the XGrids SDK's splat draws.
49582
+ */
49583
+ function isSplatCommand(command) {
49584
+ var _a;
49585
+ return typeof ((_a = command === null || command === void 0 ? void 0 : command.owner) === null || _a === void 0 ? void 0 : _a.splatCount) === "number";
49586
+ }
49587
+ /*
49588
+ * Moves splat draws to the end of the opaque pass, keeping everything else in order, and returns how many moved.
49589
+ */
49590
+ function OrderSplatCommands(list, opaquePass) {
49591
+ const splats = [];
49592
+ let kept = 0;
49593
+ for (let i = 0; i < list.length; i++) {
49594
+ const command = list[i];
49595
+ if (isSplatCommand(command)) {
49596
+ splats.push(command);
49597
+ }
49598
+ else {
49599
+ list[kept++] = command;
49600
+ }
49601
+ }
49602
+ if (!splats.length) {
49603
+ return 0;
49604
+ }
49605
+ list.length = kept;
49606
+ for (const command of splats) {
49607
+ command.pass = opaquePass;
49608
+ list.push(command);
49609
+ }
49610
+ return splats.length;
49611
+ }
49612
+ /*
49613
+ * Patches a viewer's primitive update so splat draws come after its opaque meshes.
49614
+ */
49615
+ function InstallSplatOrderPatch(viewer) {
49616
+ var _a, _b;
49617
+ const primitives = (_a = viewer === null || viewer === void 0 ? void 0 : viewer.scene) === null || _a === void 0 ? void 0 : _a.primitives;
49618
+ const opaquePass = (_b = Cesium.Pass) === null || _b === void 0 ? void 0 : _b.OPAQUE;
49619
+ if (!primitives || typeof primitives.update !== "function" || typeof opaquePass !== "number") {
49620
+ return false;
49621
+ }
49622
+ if (primitives[SPLAT_ORDER_PATCH_KEY]) {
49623
+ return true;
49624
+ }
49625
+ const original = primitives.update;
49626
+ primitives.update = function (frameState) {
49627
+ original.call(this, frameState);
49628
+ if (!HasSplats(viewer)) {
49629
+ return;
49630
+ }
49631
+ try {
49632
+ OrderSplatCommands(frameState.commandList, opaquePass);
49633
+ }
49634
+ catch (e) {
49635
+ console.error("Failed to order splat draws.", e);
49636
+ }
49637
+ };
49638
+ primitives[SPLAT_ORDER_PATCH_KEY] = true;
49639
+ return true;
49640
+ }
49641
+
48882
49642
  const CESIUM_VIEWER_MANAGER_KEY = "_cesiumViewerManager";
48883
49643
  const CESIUM_VIEWER_EVENT_TRACKER_KEY = "_cesiumViewerEventTracker";
48884
49644
  const BACKGROUND_RENDERING_KEY = "_backgroundRendering";
@@ -48965,6 +49725,9 @@
48965
49725
  backgroundRendering(viewer);
48966
49726
  InstallPickLightingPatch(viewer);
48967
49727
  InstallPickGroundPatch(viewer);
49728
+ InstallPickSplatPatch(viewer);
49729
+ InstallPickThroughGroundPatch(viewer);
49730
+ InstallSplatOrderPatch(viewer);
48968
49731
  if (cameraControls != false) {
48969
49732
  exports.CameraControls.Attach(viewer);
48970
49733
  if (exports.ViewUtils.GetModelSpace(viewer)) {
@@ -52645,7 +53408,7 @@
52645
53408
  * @returns
52646
53409
  */
52647
53410
  async function RenderGroup(params) {
52648
- var _a, _b, _c, _d, _e;
53411
+ var _a, _b, _c, _d, _e, _f;
52649
53412
  const api = params.apiGetter.getApi();
52650
53413
  const cEntities = new Map();
52651
53414
  // Gathering tags in case styling needs it.
@@ -52677,7 +53440,7 @@
52677
53440
  const entity = params.entities[i];
52678
53441
  const zoomItem = params.zoomItems[entity.Bruce.ID];
52679
53442
  const ownStyle = (!params.offline && zoomItem.StyleID != -1) ? (_a = (await getStyle$1(api, entity, zoomItem.StyleID))) === null || _a === void 0 ? void 0 : _a.Settings : zoomItem.Style;
52680
- const style = exports.MenuItemStyleOverlay.ApplyRow(ownStyle, zoomItem);
53443
+ const style = exports.MenuItemStyleOverlay.ApplyRow(ownStyle, zoomItem, (_b = entity.Bruce) === null || _b === void 0 ? void 0 : _b["EntityType.ID"]);
52681
53444
  // Pass through tags that may be needed for styling.
52682
53445
  const tagIds = entity.Bruce["Layer.ID"];
52683
53446
  const tags = [];
@@ -52689,11 +53452,11 @@
52689
53452
  }
52690
53453
  }
52691
53454
  }
52692
- const pStyle = (_b = style === null || style === void 0 ? void 0 : style.pointStyle) !== null && _b !== void 0 ? _b : {};
53455
+ const pStyle = (_c = style === null || style === void 0 ? void 0 : style.pointStyle) !== null && _c !== void 0 ? _c : {};
52693
53456
  let rego = null;
52694
53457
  // Only used for historic tracks right now.
52695
53458
  // So won't bother getting it if we don't have historic data.
52696
- if ((_c = params.entitiesHistoric) === null || _c === void 0 ? void 0 : _c[entity.Bruce.ID]) {
53459
+ if ((_d = params.entitiesHistoric) === null || _d === void 0 ? void 0 : _d[entity.Bruce.ID]) {
52697
53460
  rego = params.visualRegister.GetRego({
52698
53461
  entityId: entity.Bruce.ID,
52699
53462
  menuItemId: params.menuItemId
@@ -52708,8 +53471,8 @@
52708
53471
  apiGetter: params.apiGetter,
52709
53472
  maxDistance: zoomItem.MaxZoom,
52710
53473
  minDistance: zoomItem.MinZoom,
52711
- rendered: (_d = params.rendered) === null || _d === void 0 ? void 0 : _d.get(entity.Bruce.ID),
52712
- entityHistoric: (_e = params.entitiesHistoric) === null || _e === void 0 ? void 0 : _e[entity.Bruce.ID],
53474
+ rendered: (_e = params.rendered) === null || _e === void 0 ? void 0 : _e.get(entity.Bruce.ID),
53475
+ entityHistoric: (_f = params.entitiesHistoric) === null || _f === void 0 ? void 0 : _f[entity.Bruce.ID],
52713
53476
  entityHistoricDrawTrack: params.entityHistoricDrawTrack,
52714
53477
  fullStyle: style,
52715
53478
  rego: rego
@@ -53535,7 +54298,7 @@
53535
54298
  * @returns
53536
54299
  */
53537
54300
  async function RenderGroup(params) {
53538
- var _a, _b, _c, _d, _e, _f, _g, _h;
54301
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
53539
54302
  const api = params.apiGetter.getApi();
53540
54303
  await api.Loading;
53541
54304
  const cEntities = new Map();
@@ -53573,7 +54336,7 @@
53573
54336
  const entity = params.entities[i];
53574
54337
  const zoomItem = params.zoomItems[entity.Bruce.ID];
53575
54338
  const ownStyle = (!params.offline && zoomItem.StyleID != -1) ? (_a = (await getStyle$2(api, entity, zoomItem.StyleID))) === null || _a === void 0 ? void 0 : _a.Settings : zoomItem.Style;
53576
- const style = exports.MenuItemStyleOverlay.ApplyRow(ownStyle, zoomItem);
54339
+ const style = exports.MenuItemStyleOverlay.ApplyRow(ownStyle, zoomItem, (_b = entity.Bruce) === null || _b === void 0 ? void 0 : _b["EntityType.ID"]);
53577
54340
  // Pass through tags that may be needed for styling.
53578
54341
  const tagIds = entity.Bruce["Layer.ID"];
53579
54342
  const tags = [];
@@ -53585,7 +54348,7 @@
53585
54348
  }
53586
54349
  }
53587
54350
  }
53588
- const mStyle = (_b = style === null || style === void 0 ? void 0 : style.modelStyle) !== null && _b !== void 0 ? _b : {};
54351
+ const mStyle = (_c = style === null || style === void 0 ? void 0 : style.modelStyle) !== null && _c !== void 0 ? _c : {};
53589
54352
  let group = mStyle.lodGroup ? BModels.Calculator.GetString(mStyle.lodGroup, entity, tags) : null;
53590
54353
  if (!group) {
53591
54354
  group = "DEFAULT";
@@ -53612,8 +54375,8 @@
53612
54375
  for (let i = 0; i < params.entities.length; i++) {
53613
54376
  const entity = params.entities[i];
53614
54377
  const zoomItem = params.zoomItems[entity.Bruce.ID];
53615
- const ownStyle = (!params.offline && zoomItem.StyleID != -1) ? (_c = (await getStyle$2(api, entity, zoomItem.StyleID))) === null || _c === void 0 ? void 0 : _c.Settings : zoomItem.Style;
53616
- const style = exports.MenuItemStyleOverlay.ApplyRow(ownStyle, zoomItem);
54378
+ const ownStyle = (!params.offline && zoomItem.StyleID != -1) ? (_d = (await getStyle$2(api, entity, zoomItem.StyleID))) === null || _d === void 0 ? void 0 : _d.Settings : zoomItem.Style;
54379
+ const style = exports.MenuItemStyleOverlay.ApplyRow(ownStyle, zoomItem, (_e = entity.Bruce) === null || _e === void 0 ? void 0 : _e["EntityType.ID"]);
53617
54380
  const lod = lodData.find(x => x.entityId == entity.Bruce.ID);
53618
54381
  if (!(lod === null || lod === void 0 ? void 0 : lod.clientFileId)) {
53619
54382
  continue;
@@ -53632,21 +54395,21 @@
53632
54395
  let rego = null;
53633
54396
  // Only used for historic tracks right now.
53634
54397
  // So won't bother getting it if we don't have historic data.
53635
- if ((_d = params.entitiesHistoric) === null || _d === void 0 ? void 0 : _d[entity.Bruce.ID]) {
54398
+ if ((_f = params.entitiesHistoric) === null || _f === void 0 ? void 0 : _f[entity.Bruce.ID]) {
53636
54399
  rego = params.visualRegister.GetRego({
53637
54400
  entityId: entity.Bruce.ID,
53638
54401
  menuItemId: params.menuItemId
53639
54402
  });
53640
54403
  }
53641
- const mStyle = (_e = style === null || style === void 0 ? void 0 : style.modelStyle) !== null && _e !== void 0 ? _e : {};
54404
+ const mStyle = (_g = style === null || style === void 0 ? void 0 : style.modelStyle) !== null && _g !== void 0 ? _g : {};
53642
54405
  const cEntity = Render({
53643
- rendered: (_f = params.rendered) === null || _f === void 0 ? void 0 : _f.get(entity.Bruce.ID),
54406
+ rendered: (_h = params.rendered) === null || _h === void 0 ? void 0 : _h.get(entity.Bruce.ID),
53644
54407
  entity: entity,
53645
- entityHistoric: (_g = params.entitiesHistoric) === null || _g === void 0 ? void 0 : _g[entity.Bruce.ID],
54408
+ entityHistoric: (_j = params.entitiesHistoric) === null || _j === void 0 ? void 0 : _j[entity.Bruce.ID],
53646
54409
  style: mStyle,
53647
54410
  tags: tags,
53648
54411
  viewer: params.viewer,
53649
- lodUrl: (_h = lod.url) !== null && _h !== void 0 ? _h : BModels.ClientFile.GetUrl({
54412
+ lodUrl: (_k = lod.url) !== null && _k !== void 0 ? _k : BModels.ClientFile.GetUrl({
53650
54413
  api,
53651
54414
  fileId: lod.clientFileId,
53652
54415
  viaCdn: true
@@ -54149,7 +54912,7 @@
54149
54912
  * @returns
54150
54913
  */
54151
54914
  async function RenderGroup(params) {
54152
- var _a, _b, _c;
54915
+ var _a, _b, _c, _d;
54153
54916
  const api = params.apiGetter.getApi();
54154
54917
  const cEntities = new Map();
54155
54918
  // Gathering tags in case styling needs it.
@@ -54181,7 +54944,7 @@
54181
54944
  const entity = params.entities[i];
54182
54945
  const zoomItem = params.zoomItems[entity.Bruce.ID];
54183
54946
  const ownStyle = (!params.offline && zoomItem.StyleID != -1) ? (_a = (await getStyle$3(api, entity, zoomItem.StyleID))) === null || _a === void 0 ? void 0 : _a.Settings : zoomItem.Style;
54184
- const style = exports.MenuItemStyleOverlay.ApplyRow(ownStyle, zoomItem);
54947
+ const style = exports.MenuItemStyleOverlay.ApplyRow(ownStyle, zoomItem, (_b = entity.Bruce) === null || _b === void 0 ? void 0 : _b["EntityType.ID"]);
54185
54948
  // Pass through tags that may be needed for styling.
54186
54949
  const tagIds = entity.Bruce["Layer.ID"];
54187
54950
  const tags = [];
@@ -54193,7 +54956,7 @@
54193
54956
  }
54194
54957
  }
54195
54958
  }
54196
- const lStyle = (_b = style === null || style === void 0 ? void 0 : style.polylineStyle) !== null && _b !== void 0 ? _b : {};
54959
+ const lStyle = (_c = style === null || style === void 0 ? void 0 : style.polylineStyle) !== null && _c !== void 0 ? _c : {};
54197
54960
  const cEntity = Render({
54198
54961
  entity: entity,
54199
54962
  style: lStyle,
@@ -54201,7 +54964,7 @@
54201
54964
  viewer: params.viewer,
54202
54965
  maxDistance: zoomItem.MaxZoom,
54203
54966
  minDistance: zoomItem.MinZoom,
54204
- rendered: (_c = params.rendered) === null || _c === void 0 ? void 0 : _c.get(entity.Bruce.ID)
54967
+ rendered: (_d = params.rendered) === null || _d === void 0 ? void 0 : _d.get(entity.Bruce.ID)
54205
54968
  });
54206
54969
  if (cEntity) {
54207
54970
  const name = await getName$2(api, entity, params.offline);
@@ -57520,6 +58283,23 @@ void main() {
57520
58283
  GetPlacementKey() {
57521
58284
  return [this.groundPixels ? 1 : 0, this.baseHeight, this.exaggeration, this.followGround ? 1 : 0].join("|");
57522
58285
  }
58286
+ /**
58287
+ * Repaints the sheet with new colours, keeping its geometry and the frames it is reading.
58288
+ */
58289
+ SetRamp(rampStops, lowColor, highColor) {
58290
+ const pixels = RampLookup(rampStops || null, lowColor || DEFAULT_LOW_COLOR, highColor || DEFAULT_HIGH_COLOR);
58291
+ // A re-render with the same colours keeps the texture it already has.
58292
+ if (this.rampPixels && pixels.length === this.rampPixels.length && pixels.every((value, i) => value === this.rampPixels[i])) {
58293
+ return;
58294
+ }
58295
+ this.rampPixels = pixels;
58296
+ this.maskFillValue = firstOpaqueStop(this.rampPixels);
58297
+ // Rebuilt from the new pixels on the next frame.
58298
+ if (this.rampTexture) {
58299
+ this.rampTexture.destroy();
58300
+ this.rampTexture = null;
58301
+ }
58302
+ }
57523
58303
  /**
57524
58304
  * The ramp the sheet is painted with, as 256 RGBA steps across the value range.
57525
58305
  */
@@ -58272,6 +59052,8 @@ void main() {
58272
59052
  const EXTRUSION_ANIMATOR_KEY = "TextureFrameSeriesAnimator.ExtrusionAnimator";
58273
59053
  const TEXTURE_VALUE_LABELS_KEY = "TextureValueLabels.Overlay";
58274
59054
  const DISPLACED_SURFACE_KEY = "DisplacedSurfacePrimitive.Surface";
59055
+ // Whether the surface's animator was built hiding the baseline, which it cannot change afterwards.
59056
+ const EXTRUSION_BASELINE_KEY = "TextureFrameSeriesAnimator.ExtrusionBaseline";
58275
59057
  (function (EntityRenderEnginePolygon) {
58276
59058
  /**
58277
59059
  * The height reference a polygon is actually drawn with.
@@ -58826,7 +59608,7 @@ void main() {
58826
59608
  }
58827
59609
  EntityRenderEnginePolygon.Render = Render;
58828
59610
  async function RenderGroup(params) {
58829
- var _a, _b, _c, _d;
59611
+ var _a, _b, _c, _d, _e;
58830
59612
  const api = params.apiGetter.getApi();
58831
59613
  const cEntities = new Map();
58832
59614
  // Gathering tags in case styling needs it.
@@ -58858,7 +59640,7 @@ void main() {
58858
59640
  const entity = params.entities[i];
58859
59641
  const zoomItem = params.zoomItems[entity.Bruce.ID];
58860
59642
  const ownStyle = (!params.offline && zoomItem.StyleID != -1) ? (_a = (await getStyle$4(api, entity, zoomItem.StyleID))) === null || _a === void 0 ? void 0 : _a.Settings : zoomItem.Style;
58861
- const style = exports.MenuItemStyleOverlay.ApplyRow(ownStyle, zoomItem);
59643
+ const style = exports.MenuItemStyleOverlay.ApplyRow(ownStyle, zoomItem, (_b = entity.Bruce) === null || _b === void 0 ? void 0 : _b["EntityType.ID"]);
58862
59644
  // Pass through tags that may be needed for styling.
58863
59645
  const tagIds = entity.Bruce["Layer.ID"];
58864
59646
  const tags = [];
@@ -58870,7 +59652,7 @@ void main() {
58870
59652
  }
58871
59653
  }
58872
59654
  }
58873
- const pStyle = (_b = style === null || style === void 0 ? void 0 : style.polygonStyle) !== null && _b !== void 0 ? _b : {};
59655
+ const pStyle = (_c = style === null || style === void 0 ? void 0 : style.polygonStyle) !== null && _c !== void 0 ? _c : {};
58874
59656
  let cEntity = null;
58875
59657
  try {
58876
59658
  cEntity = await Render({
@@ -58884,14 +59666,14 @@ void main() {
58884
59666
  // Temporarily disabling re-using graphics for polygons as they have some bugs, and
58885
59667
  // they don't support any animation yet.
58886
59668
  // rendered: null
58887
- rendered: (_c = params.rendered) === null || _c === void 0 ? void 0 : _c.get(entity.Bruce.ID),
59669
+ rendered: (_d = params.rendered) === null || _d === void 0 ? void 0 : _d.get(entity.Bruce.ID),
58888
59670
  menuItemId: params.menuItemId,
58889
59671
  visualRegister: params.visualRegister,
58890
59672
  onSeriesDiscovered: params.onSeriesDiscovered
58891
59673
  });
58892
59674
  }
58893
59675
  catch (e) {
58894
- console.error(`Polygon.RenderGroup: failed to render entity ${((_d = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _d === void 0 ? void 0 : _d.ID) || "<NONE>"}:`, e);
59676
+ console.error(`Polygon.RenderGroup: failed to render entity ${((_e = entity === null || entity === void 0 ? void 0 : entity.Bruce) === null || _e === void 0 ? void 0 : _e.ID) || "<NONE>"}:`, e);
58895
59677
  }
58896
59678
  if (cEntity) {
58897
59679
  const name = await getName$3(api, entity, params.offline);
@@ -59103,10 +59885,15 @@ void main() {
59103
59885
  const placement = surfacePlacement(entity, heightRef, extrusionArchive && exports.TextureFrameSeriesAnimator.IsDatumHeight(extrusionArchive.metadata));
59104
59886
  // Whether the surface follows terrain is baked into its ground sampling, so a change there has
59105
59887
  // to rebuild rather than update in place.
59106
- if (reusable && existingSurface.GetFollowsGround() === placement.followGround) {
59888
+ // The baseline mask is read by the animator as it is built, so a change there rebuilds too.
59889
+ const baselineKept = cEntity[EXTRUSION_BASELINE_KEY] === Boolean(style.maskTextureBaseline);
59890
+ if (reusable && baselineKept && existingSurface.GetFollowsGround() === placement.followGround) {
59107
59891
  existingSurface.SetBaseHeight(placement.baseHeight);
59108
59892
  existingSurface.SetExaggeration(exaggerationFor(style));
59109
59893
  existingSurface.SetWater(waterFor(style));
59894
+ // A restyle that only recolours, such as a bookmark's own ramp, repaints in place.
59895
+ const ramp = surfaceRamp(style.textureColorMask, extrusionArchive.metadata);
59896
+ existingSurface.SetRamp(ramp.rampStops, ramp.lowColor, ramp.highColor);
59110
59897
  return;
59111
59898
  }
59112
59899
  disposeDisplacedSurface(cEntity, viewer);
@@ -59133,7 +59920,8 @@ void main() {
59133
59920
  maskBaseline: style.maskTextureBaseline
59134
59921
  });
59135
59922
  cEntity[EXTRUSION_ANIMATOR_KEY] = animator;
59136
- const mask = style.textureColorMask;
59923
+ cEntity[EXTRUSION_BASELINE_KEY] = Boolean(style.maskTextureBaseline);
59924
+ const ramp = surfaceRamp(style.textureColorMask, extrusionArchive.metadata);
59137
59925
  const surface = new exports.DisplacedSurfacePrimitive.Surface({
59138
59926
  extent,
59139
59927
  // The grid has to be walked the way the raster was sampled, or the surface skews across the extent.
@@ -59147,18 +59935,28 @@ void main() {
59147
59935
  packedValue: exports.TextureFrameSeriesAnimator.IsPackedValue(extrusionArchive.metadata),
59148
59936
  exaggeration: exaggerationFor(style),
59149
59937
  water: waterFor(style),
59938
+ lowColor: ramp.lowColor,
59939
+ highColor: ramp.highColor,
59940
+ rampStops: ramp.rampStops
59941
+ });
59942
+ surface.BindAnimator(animator);
59943
+ viewer.scene.primitives.add(surface);
59944
+ cEntity[DISPLACED_SURFACE_KEY] = surface;
59945
+ }
59946
+ /*
59947
+ * The colours a displaced surface paints with, from the style's mask.
59948
+ */
59949
+ function surfaceRamp(mask, metadata) {
59950
+ return {
59150
59951
  lowColor: mask ? BModels.Color.ColorFromStr(mask.minColor) : null,
59151
59952
  highColor: mask ? BModels.Color.ColorFromStr(mask.maxColor) : null,
59152
59953
  // Normalised the same way the animator normalises them, so the surface and the flat drape
59153
59954
  // agree about which values the style hides.
59154
59955
  rampStops: ((mask && mask.points) || []).map((stop) => ({
59155
- position: exports.TextureFrameSeriesAnimator.NormalisePosition(extrusionArchive.metadata, stop.position),
59956
+ position: exports.TextureFrameSeriesAnimator.NormalisePosition(metadata, stop.position),
59156
59957
  color: BModels.Color.ColorFromStr(stop.color)
59157
59958
  })).filter((stop) => Boolean(stop.color))
59158
- });
59159
- surface.BindAnimator(animator);
59160
- viewer.scene.primitives.add(surface);
59161
- cEntity[DISPLACED_SURFACE_KEY] = surface;
59959
+ };
59162
59960
  }
59163
59961
  /**
59164
59962
  * Turns the polygon's altitude option into the two things the displaced surface needs:
@@ -61126,7 +61924,7 @@ void main() {
61126
61924
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
61127
61925
  })(exports.StyleUtils || (exports.StyleUtils = {}));
61128
61926
 
61129
- const VERSION = "7.9.1";
61927
+ const VERSION = "7.9.3";
61130
61928
  /**
61131
61929
  * Updates the environment instance used by bruce-cesium to one specified.
61132
61930
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.
@@ -61167,6 +61965,7 @@ void main() {
61167
61965
  exports.LIGHTING_SETTINGS_VERSION = LIGHTING_SETTINGS_VERSION;
61168
61966
  exports.LIGHT_INTENSITY_COMPENSATION = LIGHT_INTENSITY_COMPENSATION;
61169
61967
  exports.MAX_COMPENSATED_LIGHT_INTENSITY = MAX_COMPENSATED_LIGHT_INTENSITY;
61968
+ exports.FindGapSurfaces = FindGapSurfaces;
61170
61969
  exports.Draw3dPolygon = Draw3dPolygon;
61171
61970
  exports.Draw3dPolyline = Draw3dPolyline;
61172
61971
  exports.WidgetControlViewBarSearch = WidgetControlViewBarSearch;