bruce-cesium 7.9.1 → 7.9.2

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 (28) hide show
  1. package/dist/bruce-cesium.es5.js +746 -81
  2. package/dist/bruce-cesium.es5.js.map +1 -1
  3. package/dist/bruce-cesium.umd.js +744 -78
  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/visuals-register.js +38 -1
  13. package/dist/lib/rendering/visuals-register.js.map +1 -1
  14. package/dist/lib/rendering/xgrids-render-engine.js +3 -0
  15. package/dist/lib/rendering/xgrids-render-engine.js.map +1 -1
  16. package/dist/lib/utils/drawing-utils.js +241 -75
  17. package/dist/lib/utils/drawing-utils.js.map +1 -1
  18. package/dist/lib/viewer/camera-controls.js +134 -1
  19. package/dist/lib/viewer/camera-controls.js.map +1 -1
  20. package/dist/lib/viewer/viewer-utils.js +6 -0
  21. package/dist/lib/viewer/viewer-utils.js.map +1 -1
  22. package/dist/types/bruce-cesium.d.ts +1 -1
  23. package/dist/types/internal/cesium-patch-pick-splat.d.ts +8 -0
  24. package/dist/types/internal/cesium-patch-pick-through-ground.d.ts +7 -0
  25. package/dist/types/internal/cesium-patch-splat-order.d.ts +2 -0
  26. package/dist/types/utils/drawing-utils.d.ts +7 -1
  27. package/dist/types/viewer/camera-controls.d.ts +4 -0
  28. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import * as Cesium from 'cesium';
2
- import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, Math as Math$1, Cartesian3, JulianDate, Quaternion, Transforms, HeadingPitchRoll, HeightReference, Matrix4, ShaderSource, Ellipsoid, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, Cartesian2, Cartesian4, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, PixelDatatype, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, ConstantPositionProperty, DistanceDisplayCondition, ClassificationType, ArcType, CornerType, ColorBlendMode, Model, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, SceneMode, IntersectionTests, Ray, SceneTransforms, HorizontalOrigin, VerticalOrigin, NearFarScalar, Matrix3, KmlDataSource, FeatureDetection, GeoJsonDataSource, Cesium3DTileStyle, HeadingPitchRange, Ion, IonResource, Cesium3DTileColorBlendMode, Cesium3DTileset, OrthographicFrustum, EasingFunction, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, Intersect, WebGLConstants, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, PolygonPipeline, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, PrimitiveCollection, ShadowMode, PolylineCollection, LabelCollection, LabelStyle, Material, CustomDataSource, GeometryInstance, Event, CesiumInspector, ClockRange, DynamicEnvironmentMapManager, ScreenSpaceEventHandler, ScreenSpaceEventType, CameraEventType, Plane, OrientedBoundingBox, Fullscreen, CzmlDataSource } from 'cesium';
3
- import { Cartes, LRUCache, Carto, ProjectViewTile, EntityHistoricData, BruceEvent, DelayQueue, Entity as Entity$1, EntityTag, PathUtils, ClientFile, ENVIRONMENT, EntityAttachmentType, EntityRelationType, EntityType, Tileset, Calculator, DataLab, Style, ObjectUtils, MenuItem, AccountConcept, RecordChangeFeed, Geometry as Geometry$1, EntityLod, UrlUtils, Bounds, ClientFileValueMap, Color as Color$1, ProjectView, ProjectViewBookmark, ZoomControl, Assembly, EntityCoords, Api, EntityRelation, BruceApi, EntitySource, Camera, ProgramKey, ProjectViewLegacyTile, Account, AccountLimits, Session, EntityAttachment, EntityAttribute, MathUtils, ProjectViewBookmarkGroup } from 'bruce-models';
2
+ import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, Math as Math$1, Cartesian3, JulianDate, Quaternion, Transforms, HeadingPitchRoll, HeightReference, Matrix4, ConstantPositionProperty, DistanceDisplayCondition, HorizontalOrigin, VerticalOrigin, ClassificationType, ColorBlendMode, Model, ShaderSource, Ellipsoid, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, Cartesian2, Cartesian4, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, PixelDatatype, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, ArcType, CornerType, SceneMode, IntersectionTests, Ray, SceneTransforms, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, NearFarScalar, Matrix3, KmlDataSource, GeoJsonDataSource, FeatureDetection, Cesium3DTileStyle, HeadingPitchRange, Ion, IonResource, Cesium3DTileColorBlendMode, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, OrthographicFrustum, EasingFunction, Cesium3DTileset, WebGLConstants, Intersect, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, PolygonPipeline, EllipsoidGeodesic, sampleTerrainMostDetailed, ShadowMode, CustomDataSource, GeometryInstance, PrimitiveCollection, PolylineCollection, LabelCollection, LabelStyle, Material, CesiumInspector, defined, ClockRange, DynamicEnvironmentMapManager, Event, CameraEventType, Plane, OrientedBoundingBox, ScreenSpaceEventHandler, ScreenSpaceEventType, Fullscreen, CzmlDataSource } from 'cesium';
3
+ import { Cartes, LRUCache, Carto, ProjectViewTile, EntityHistoricData, BruceEvent, DelayQueue, Entity as Entity$1, EntityTag, PathUtils, ClientFile, ENVIRONMENT, EntityAttachmentType, EntityRelationType, EntityType, Tileset, Calculator, DataLab, Style, ObjectUtils, MenuItem, AccountConcept, RecordChangeFeed, Api, EntityLod, UrlUtils, Geometry as Geometry$1, ProjectView, ProjectViewBookmark, ZoomControl, Bounds, ClientFileValueMap, Color as Color$1, Assembly, EntityCoords, BruceApi, EntityRelation, EntitySource, ProgramKey, ProjectViewLegacyTile, Camera, Account, AccountLimits, Session, EntityAttachment, EntityAttribute, MathUtils, ProjectViewBookmarkGroup } from 'bruce-models';
4
4
 
5
5
  /**
6
6
  * Ensures a number is returned from a given value.
@@ -110,6 +110,406 @@ var MeasureUtils;
110
110
  MeasureUtils.MeasurePolygon = MeasurePolygon;
111
111
  })(MeasureUtils || (MeasureUtils = {}));
112
112
 
113
+ /*
114
+ * Makes pickPosition return an opaque primitive drawn through the ground, not the ground above it, with occlusion off.
115
+ */
116
+ const PICK_THROUGH_GROUND_PATCH_KEY = "_nextspacePickThroughGroundPatch";
117
+ // What the patch saw of the pick depth copy, read by GetPickDepthKind.
118
+ const PICK_DEPTH_KIND_KEY = "_nextspacePickDepthKind";
119
+ // From CesiumJS 1.118 the pick depth copy merges the globe's depth in; only that shader names this variable.
120
+ const MERGE_MARK = "globeDepthPacked";
121
+ // Before 1.118 the copy is a plain repack of the scene depth.
122
+ const LEGACY_MARK = "czm_packDepth(texture";
123
+ /*
124
+ * The merge CesiumJS uses, except that a scene depth farther than the globe is kept unless it is the depth plane.
125
+ */
126
+ const PICK_THROUGH_GROUND_FS = `uniform highp sampler2D colorTexture;
127
+ uniform vec4 u_nextspaceDepthPlane;
128
+ uniform vec2 u_nextspaceFlags;
129
+ in vec2 v_textureCoordinates;
130
+ vec3 nextspaceEye(float depth)
131
+ {
132
+ vec2 uv = (gl_FragCoord.xy - czm_viewport.xy) / czm_viewport.zw;
133
+ if (u_nextspaceFlags.y > 0.5) {
134
+ float fromCamera = pow(2.0, depth * czm_log2FarDepthFromNearPlusOne) - 1.0 + czm_currentFrustum.x;
135
+ vec4 q = czm_inverseProjection * vec4(2.0 * uv - 1.0, 0.0, 1.0);
136
+ vec3 d = q.xyz / q.w;
137
+ return d * (fromCamera / -d.z);
138
+ }
139
+ vec4 e = czm_windowToEyeCoordinates(vec4(gl_FragCoord.xy, depth, 1.0));
140
+ return e.xyz / e.w;
141
+ }
142
+ void main()
143
+ {
144
+ vec4 globeDepthPacked = texture(czm_globeDepthTexture, v_textureCoordinates);
145
+ float globeDepth = czm_unpackDepth(globeDepthPacked);
146
+ float depth = texture(colorTexture, v_textureCoordinates).r;
147
+ bool sceneDepth = depth > 0.0 && depth < 1.0;
148
+ bool keepScene = globeDepth <= 0.0 || globeDepth >= 1.0 || depth < globeDepth && sceneDepth;
149
+ if (!keepScene && sceneDepth && u_nextspaceFlags.x > 0.5) {
150
+ vec3 p = nextspaceEye(depth);
151
+ keepScene = abs(dot(u_nextspaceDepthPlane.xyz, p) + u_nextspaceDepthPlane.w) > max(0.5, 0.002 * length(p));
152
+ }
153
+ out_FragColor = keepScene ? czm_packDepth(depth) : globeDepthPacked;
154
+ }
155
+ `;
156
+ /*
157
+ * The depth plane CesiumJS draws once the globe's depth is cleared, as a unit-normal plane in world coordinates.
158
+ */
159
+ function GetDepthPlaneWorld(cameraPosition, radii, offset, result) {
160
+ // Mirrors DepthPlane's computeDepthQuad: the plane through the limb, in the ellipsoid's scaled space.
161
+ const rx = radii.x + offset;
162
+ const ry = radii.y + offset;
163
+ const rz = radii.z + offset;
164
+ const qx = cameraPosition.x / rx;
165
+ const qy = cameraPosition.y / ry;
166
+ const qz = cameraPosition.z / rz;
167
+ const qm = Math.sqrt(qx * qx + qy * qy + qz * qz);
168
+ const nx = qx / qm / rx;
169
+ const ny = qy / qm / ry;
170
+ const nz = qz / qm / rz;
171
+ const nm = Math.sqrt(nx * nx + ny * ny + nz * nz);
172
+ return Cartesian4.fromElements(nx / nm, ny / nm, nz / nm, -(1 / qm) / nm, result);
173
+ }
174
+ /*
175
+ * Moves a world plane into eye coordinates, keeping its normal unit length so distances stay in metres.
176
+ */
177
+ function GetPlaneEye(planeWorld, inverseView, result) {
178
+ const transposed = Matrix4.transpose(inverseView, new Matrix4());
179
+ Matrix4.multiplyByVector(transposed, planeWorld, result);
180
+ const m = Math.sqrt(result.x * result.x + result.y * result.y + result.z * result.z);
181
+ return Cartesian4.divideByScalar(result, m, result);
182
+ }
183
+ /*
184
+ * What the viewer's pick depth holds, as far as the patch has seen.
185
+ */
186
+ function GetPickDepthKind(viewer) {
187
+ var _a, _b, _c;
188
+ 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";
189
+ }
190
+ /*
191
+ * Patches the viewer's pick depth copy so a primitive seen through the ground picks itself.
192
+ */
193
+ function InstallPickThroughGroundPatch(viewer) {
194
+ var _a, _b, _c;
195
+ const scene = viewer === null || viewer === void 0 ? void 0 : viewer.scene;
196
+ const context = scene === null || scene === void 0 ? void 0 : scene.context;
197
+ if (!context || typeof context.createViewportQuadCommand !== "function") {
198
+ return false;
199
+ }
200
+ if (context[PICK_THROUGH_GROUND_PATCH_KEY]) {
201
+ return true;
202
+ }
203
+ const plane = new Cartesian4();
204
+ const planeWorld = new Cartesian4();
205
+ const flags = new Cartesian2();
206
+ const updatePlane = () => {
207
+ var _a, _b, _c, _d;
208
+ const env = scene._environmentState;
209
+ const camera = scene.camera;
210
+ const on = Boolean((env === null || env === void 0 ? void 0 : env.clearGlobeDepth) &&
211
+ (env === null || env === void 0 ? void 0 : env.useDepthPlane) &&
212
+ ((_a = camera === null || camera === void 0 ? void 0 : camera.frustum) === null || _a === void 0 ? void 0 : _a.fov) != null &&
213
+ scene.mode === SceneMode.SCENE3D &&
214
+ scene.globe);
215
+ flags.x = on ? 1 : 0;
216
+ flags.y = ((_b = scene.frameState) === null || _b === void 0 ? void 0 : _b.useLogDepth) ? 1 : 0;
217
+ if (on) {
218
+ const offset = (_d = (_c = scene._depthPlane) === null || _c === void 0 ? void 0 : _c._ellipsoidOffset) !== null && _d !== void 0 ? _d : 0;
219
+ GetDepthPlaneWorld(camera.positionWC, scene.globe.ellipsoid.radii, offset, planeWorld);
220
+ GetPlaneEye(planeWorld, camera.inverseViewMatrix, plane);
221
+ }
222
+ };
223
+ const original = context.createViewportQuadCommand;
224
+ context.createViewportQuadCommand = function (fragmentShaderSource, overrides) {
225
+ try {
226
+ if (typeof fragmentShaderSource === "string" && (overrides === null || overrides === void 0 ? void 0 : overrides.uniformMap)) {
227
+ if (fragmentShaderSource.includes(MERGE_MARK) && overrides.uniformMap.colorTexture) {
228
+ context[PICK_DEPTH_KIND_KEY] = "merged";
229
+ overrides.uniformMap.u_nextspaceDepthPlane = () => {
230
+ updatePlane();
231
+ return plane;
232
+ };
233
+ overrides.uniformMap.u_nextspaceFlags = () => flags;
234
+ fragmentShaderSource = PICK_THROUGH_GROUND_FS;
235
+ context[PICK_DEPTH_KIND_KEY] = "through-ground";
236
+ }
237
+ else if (fragmentShaderSource.includes(LEGACY_MARK) && overrides.uniformMap.u_texture) {
238
+ context[PICK_DEPTH_KIND_KEY] = "legacy";
239
+ }
240
+ }
241
+ }
242
+ catch (e) {
243
+ console.error("Failed to patch the pick depth merge.", e);
244
+ }
245
+ return original.call(this, fragmentShaderSource, overrides);
246
+ };
247
+ // A pick depth made before this point rebuilds its copy on the next frame.
248
+ for (const view of [scene.view, scene.defaultView]) {
249
+ for (const pickDepth of (_a = view === null || view === void 0 ? void 0 : view.pickDepths) !== null && _a !== void 0 ? _a : []) {
250
+ if (pickDepth === null || pickDepth === void 0 ? void 0 : pickDepth._copyDepthCommand) {
251
+ (_c = (_b = pickDepth._copyDepthCommand.shaderProgram) === null || _b === void 0 ? void 0 : _b.destroy) === null || _c === void 0 ? void 0 : _c.call(_b);
252
+ pickDepth._copyDepthCommand = undefined;
253
+ }
254
+ }
255
+ }
256
+ context[PICK_THROUGH_GROUND_PATCH_KEY] = true;
257
+ return true;
258
+ }
259
+
260
+ /*
261
+ * Makes XGrids splats pick only where they are visibly drawn, not across their faint halos.
262
+ */
263
+ const PICK_SPLAT_PATCH_KEY = "_nextspacePickSplatPatch";
264
+ // The XGrids SDK compiles its splat shaders with this define.
265
+ const SPLAT_DEFINE = "LccShader";
266
+ // CesiumJS's derived pick shader keeps every fragment with any alpha at all.
267
+ const ANY_ALPHA = /(out_FragColor|out_FragData_0|gl_FragColor)\.a == 0\.0/;
268
+ /*
269
+ * The least opacity a splat fragment needs to be picked; tuned against the SDK's own raycast on real scans.
270
+ */
271
+ const SPLAT_PICK_MIN_ALPHA = 0.25;
272
+ /*
273
+ * Raises the alpha a derived splat "pick" shader needs before it keeps a fragment, returning whether it did.
274
+ */
275
+ function FixSplatPick(keyword, options) {
276
+ const fragment = options === null || options === void 0 ? void 0 : options.fragmentShaderSource;
277
+ const defines = fragment === null || fragment === void 0 ? void 0 : fragment.defines;
278
+ const sources = fragment === null || fragment === void 0 ? void 0 : fragment.sources;
279
+ if (keyword !== "pick" ||
280
+ !Array.isArray(defines) ||
281
+ !Array.isArray(sources) ||
282
+ !defines.includes(SPLAT_DEFINE) ||
283
+ !sources.some(x => typeof x === "string" && ANY_ALPHA.test(x))) {
284
+ return false;
285
+ }
286
+ fragment.sources = sources.map(x => typeof x === "string" ? x.replace(ANY_ALPHA, `$1.a < ${SPLAT_PICK_MIN_ALPHA.toFixed(3)}`) : x);
287
+ return true;
288
+ }
289
+ /*
290
+ * Whether a pick result is an XGrids splat mesh rather than a Cesium primitive or Entity.
291
+ */
292
+ function IsSplatPick(picked) {
293
+ var _a;
294
+ return Boolean(picked &&
295
+ typeof picked.id === "string" &&
296
+ typeof ((_a = picked.primitive) === null || _a === void 0 ? void 0 : _a.splatCount) === "number");
297
+ }
298
+ /*
299
+ * Patches a viewer's shader cache so splat pick shaders drop their near-transparent fragments.
300
+ */
301
+ function InstallPickSplatPatch(viewer) {
302
+ var _a, _b;
303
+ 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;
304
+ if (!cache || typeof cache.createDerivedShaderProgram !== "function") {
305
+ return false;
306
+ }
307
+ if (cache[PICK_SPLAT_PATCH_KEY]) {
308
+ return true;
309
+ }
310
+ const original = cache.createDerivedShaderProgram;
311
+ cache.createDerivedShaderProgram = function (shaderProgram, keyword, options) {
312
+ try {
313
+ FixSplatPick(keyword, options);
314
+ }
315
+ catch (e) {
316
+ console.error("Failed to fix a splat pick shader.", e);
317
+ }
318
+ return original.call(this, shaderProgram, keyword, options);
319
+ };
320
+ cache[PICK_SPLAT_PATCH_KEY] = true;
321
+ return true;
322
+ }
323
+ // The XGrids render objects drawn on a viewer, so picking only looks for splats when there are some.
324
+ const SPLATS_KEY = "_nextspaceSplats";
325
+ /*
326
+ * Records that a splat render object is drawn on, or removed from, a viewer.
327
+ */
328
+ function TrackSplats(viewer, renderObject, drawn) {
329
+ var _a;
330
+ if (!viewer || !renderObject) {
331
+ return;
332
+ }
333
+ const set = (_a = viewer[SPLATS_KEY]) !== null && _a !== void 0 ? _a : (viewer[SPLATS_KEY] = new Set());
334
+ if (drawn) {
335
+ set.add(renderObject);
336
+ }
337
+ else {
338
+ set.delete(renderObject);
339
+ }
340
+ }
341
+ /*
342
+ * Whether any XGrids splats are drawn on a viewer.
343
+ */
344
+ function HasSplats(viewer) {
345
+ var _a;
346
+ return Boolean((_a = viewer === null || viewer === void 0 ? void 0 : viewer[SPLATS_KEY]) === null || _a === void 0 ? void 0 : _a.size);
347
+ }
348
+ /*
349
+ * Whether pick results for splats follow what is visibly drawn, so a splat can be trusted to hide what is behind it.
350
+ */
351
+ function IsSplatPickVisible(viewer) {
352
+ var _a, _b, _c;
353
+ 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]);
354
+ }
355
+ /*
356
+ * Whether the SDK raycasts splats as opacity-weighted ellipsoids (usePrecisionRaycast) rather than points.
357
+ */
358
+ function IsSplatRaycastPrecise(viewer) {
359
+ var _a, _b;
360
+ const set = viewer === null || viewer === void 0 ? void 0 : viewer[SPLATS_KEY];
361
+ if (!(set === null || set === void 0 ? void 0 : set.size)) {
362
+ return false;
363
+ }
364
+ for (const object of Array.from(set)) {
365
+ try {
366
+ 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) {
367
+ return true;
368
+ }
369
+ }
370
+ catch (e) {
371
+ // A disposed scan has no config; the others still answer.
372
+ }
373
+ }
374
+ return false;
375
+ }
376
+
377
+ const ACCURATE_PICK_KEY = "_nextspaceAccuratePick";
378
+ // A repeat pick at the same pixel within this long, with the camera still, returns the last result.
379
+ const ACCURATE_PICK_CACHE_MS = 3000;
380
+ // Beyond this a splat raycast gives up; matches what Navigator always asked the SDK for.
381
+ const SPLAT_MAX_DISTANCE = 1000;
382
+ // A point raycast this thin still finds a splat a pixel covers at close range without catching ones beside it.
383
+ const SPLAT_MIN_RADIUS = 0.005;
384
+ // A precise raycast only uses the radius to shortlist splats before testing their ellipsoids.
385
+ const SPLAT_PRECISE_SHORTLIST = 0.5;
386
+ /*
387
+ * Whether a cached accurate pick still answers: the same pixel, a still camera and recent enough.
388
+ */
389
+ function isCacheValid(cache, camera, cursor, pickOnly) {
390
+ if (cache.pickOnly !== pickOnly || performance.now() - cache.time > ACCURATE_PICK_CACHE_MS) {
391
+ return false;
392
+ }
393
+ // Same pixel only; a neighbour's answer steps a pointer-following cursor and corrupts normals read from picks.
394
+ if (Cartesian2.distanceSquared(cursor, cache.cursor) >= 0.25) {
395
+ return false;
396
+ }
397
+ const p = camera.positionWC;
398
+ const q = cache.cameraPosition;
399
+ if (Math.abs(p.x - q.x) > 2 || Math.abs(p.y - q.y) > 2 || Math.abs(p.z - q.z) > 2) {
400
+ return false;
401
+ }
402
+ const cos = Cartesian3.dot(camera.directionWC, cache.cameraDirection) /
403
+ (Cartesian3.magnitude(camera.directionWC) * Cartesian3.magnitude(cache.cameraDirection));
404
+ if (Math.acos(Math.min(1, cos)) > Math$1.toRadians(5)) {
405
+ return false;
406
+ }
407
+ const width = camera.frustum instanceof OrthographicFrustum ? camera.frustum.width : null;
408
+ return width === cache.frustumWidth || (width != null && cache.frustumWidth != null && Math.abs(width - cache.frustumWidth) < 1e-6);
409
+ }
410
+ /*
411
+ * Whether pickPosition is right over the ground with occlusion off: CesiumJS 1.118+, unknown before a first frame.
412
+ */
413
+ function isPickPositionFixed(viewer) {
414
+ const kind = GetPickDepthKind(viewer);
415
+ return kind === "through-ground" || kind === "merged";
416
+ }
417
+ /*
418
+ * Whether the terrain provider can answer a globe pick yet.
419
+ */
420
+ function isTerrainReady(viewer) {
421
+ return Boolean(viewer.terrainProvider && viewer.terrainProvider["ready"] != false);
422
+ }
423
+ /*
424
+ * The size of one screen pixel at a distance from the camera, in metres.
425
+ */
426
+ function pixelSizeAt(scene, distance) {
427
+ const height = scene.canvas.clientHeight;
428
+ const frustum = scene.camera.frustum;
429
+ if (frustum instanceof OrthographicFrustum) {
430
+ return frustum.width / Math.max(1, scene.canvas.clientWidth);
431
+ }
432
+ const fovy = frustum === null || frustum === void 0 ? void 0 : frustum.fovy;
433
+ if (!height || !fovy) {
434
+ return 0;
435
+ }
436
+ return 2 * distance * Math.tan(fovy / 2) / height;
437
+ }
438
+ /*
439
+ * Whether a pick result is something pickOnly positions land on: a tileset, a model or an Entity with a model.
440
+ */
441
+ function isPositionObject(object) {
442
+ const entity = (object === null || object === void 0 ? void 0 : object.id) instanceof Entity ? object.id : null;
443
+ return Boolean(object instanceof Cesium3DTileFeature ||
444
+ object instanceof Cesium3DTileset ||
445
+ (object === null || object === void 0 ? void 0 : object.primitive) instanceof Cesium3DTileset ||
446
+ (object === null || object === void 0 ? void 0 : object.primitive) instanceof Model ||
447
+ (entity === null || entity === void 0 ? void 0 : entity.model));
448
+ }
449
+ /*
450
+ * The front-most pickOnly object under a cursor, skipping ignored ones; drillPick only when there are any to skip.
451
+ */
452
+ function pickObject(scene, cursor, ignored) {
453
+ if (!(ignored === null || ignored === void 0 ? void 0 : ignored.length)) {
454
+ return isPositionObject(scene.pick(cursor, 1, 1));
455
+ }
456
+ const objects = scene.drillPick(cursor, ignored.length + 1, 3, 3);
457
+ for (const object of objects) {
458
+ const owner = (object === null || object === void 0 ? void 0 : object.id) instanceof Entity ? object.id : object;
459
+ if (ignored.includes(owner) || ignored.includes(object)) {
460
+ continue;
461
+ }
462
+ return isPositionObject(object);
463
+ }
464
+ return false;
465
+ }
466
+ /*
467
+ * Workarounds for CesiumJS before 1.118, whose pickPosition hit the depth plane over the ground (cesium#4368).
468
+ */
469
+ function legacyPick(viewer, cursor, pixel, pickOnly, ignored) {
470
+ var _a, _b, _c, _d, _e;
471
+ const scene = viewer.scene;
472
+ let pos3d = null;
473
+ if (!pickOnly && ((_a = scene.globe) === null || _a === void 0 ? void 0 : _a.depthTestAgainstTerrain)) {
474
+ pos3d = (_b = scene.pickPosition(pixel)) !== null && _b !== void 0 ? _b : null;
475
+ }
476
+ else {
477
+ if (!pickOnly) {
478
+ pos3d = (_c = scene.pickPosition(pixel)) !== null && _c !== void 0 ? _c : null;
479
+ }
480
+ if (pos3d) {
481
+ const carto = Cartographic.fromCartesian(pos3d);
482
+ if (!carto || carto.height < 0) {
483
+ pos3d = null;
484
+ }
485
+ }
486
+ if (!pos3d) {
487
+ if (scene.pickPositionSupported && pickObject(scene, cursor, ignored)) {
488
+ pos3d = (_d = scene.pickPosition(pixel)) !== null && _d !== void 0 ? _d : null;
489
+ }
490
+ if (!pickOnly && !pos3d && scene.globe && isTerrainReady(viewer)) {
491
+ const ray = scene.camera.getPickRay(cursor);
492
+ pos3d = ray ? ((_e = scene.globe.pick(ray, scene)) !== null && _e !== void 0 ? _e : null) : null;
493
+ }
494
+ }
495
+ }
496
+ // A tileset the depth missed can still be found by rendering along the ray.
497
+ if (!pos3d && scene.mode === SceneMode.SCENE3D && typeof scene.pickFromRay === "function") {
498
+ const picked = scene.pick(cursor, 1, 1);
499
+ if (picked instanceof Cesium3DTileFeature || (picked === null || picked === void 0 ? void 0 : picked.primitive) instanceof Cesium3DTileset) {
500
+ try {
501
+ const hit = scene.pickFromRay(scene.camera.getPickRay(cursor), []);
502
+ if ((hit === null || hit === void 0 ? void 0 : hit.position) && Cartes.ValidateCartes3(hit.position)) {
503
+ pos3d = hit.position;
504
+ }
505
+ }
506
+ catch (e) {
507
+ console.error(e);
508
+ }
509
+ }
510
+ }
511
+ return pos3d;
512
+ }
113
513
  const [C3] = [Cartesian3];
114
514
  function getT(t, alpha, p0, p1) {
115
515
  const d = C3.subtract(p1, p0, new C3);
@@ -441,91 +841,119 @@ var DrawingUtils;
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 ? 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 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 Cartesian2(cursor.x, cursor.y);
900
+ }
901
+ return new 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 = Cartesian2.distanceSquared(cursor, cachedPick.cursor) < 9; // 3 pixels
463
- const directionDot = Cartesian3.dot(camera.directionWC, cachedCameraState.direction);
464
- const directionLengths = Cartesian3.magnitude(camera.directionWC) * 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 > Math$1.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 (defined(pos3d)) {
487
- const carto = Cartographic.fromCartesian(pos3d);
488
- if (!defined(carto) || carto.height < 0) {
489
- pos3d = null;
490
- }
491
- }
492
- if (!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 Entity ? object.id : object);
500
- if (object &&
501
- (!ignoredPickOnly || !ignoredPickOnly.includes(object)) &&
502
- (object instanceof Cesium3DTileFeature ||
503
- object instanceof Cesium3DTileset ||
504
- (object instanceof Entity && object.model))) {
505
- pos3d = scene.pickPosition(cursor);
506
- break;
507
- }
508
- }
509
- }
510
- if (!pickOnly && !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 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
@@ -1218,6 +1646,126 @@ function plausibleDistance(state) {
1218
1646
  const horizon = Math.sqrt(2 * ellipsoidOf(state).maximumRadius * Math.max(height, 0));
1219
1647
  return Math.max(PLAUSIBLE_PICK_FLOOR, height * 10, horizon * 1.5);
1220
1648
  }
1649
+ // Window radii, in drawing buffer pixels, searched for the surface around a gap between point cloud points.
1650
+ const GAP_RADII = [2, 4, 8, 12];
1651
+ // A pick this many times farther than the surface around it, plus the slack in metres, looked through a gap.
1652
+ const GAP_FARTHER = 1.5;
1653
+ const GAP_SLACK = 0.5;
1654
+ // Directions around the centre, and how many must hold nearer pixels for the centre to be surrounded.
1655
+ const GAP_SECTORS = 8;
1656
+ const GAP_SECTORS_NEAR = 6;
1657
+ const PACKED_DEPTH = new Cartesian4(1, 1 / 255, 1 / 65025, 1 / 16581375);
1658
+ /*
1659
+ * Distances along the view axis drawn around a window position, rows bottom-up, Infinity where nothing is drawn.
1660
+ */
1661
+ function readDepthDistances(scene, position, radius) {
1662
+ var _a, _b, _c, _d, _e;
1663
+ const view = (_a = scene._view) !== null && _a !== void 0 ? _a : scene.view;
1664
+ const frustums = view === null || view === void 0 ? void 0 : view.frustumCommandsList;
1665
+ if (!(frustums === null || frustums === void 0 ? void 0 : frustums.length) ||
1666
+ typeof ((_b = scene._picking) === null || _b === void 0 ? void 0 : _b.getPickDepth) !== "function" ||
1667
+ typeof ((_c = scene.context) === null || _c === void 0 ? void 0 : _c.readPixels) !== "function") {
1668
+ return null;
1669
+ }
1670
+ const bufferX = position.x * scene.drawingBufferWidth / scene.canvas.clientWidth;
1671
+ const bufferY = position.y * scene.drawingBufferHeight / scene.canvas.clientHeight;
1672
+ if (!Number.isFinite(bufferX) || !Number.isFinite(bufferY)) {
1673
+ return null;
1674
+ }
1675
+ const x = Math.floor(bufferX) - radius;
1676
+ // The same row pickPosition reads for this position, so a pixel found here is the one it then returns.
1677
+ const y = Math.floor(scene.drawingBufferHeight - bufferY) - radius;
1678
+ const width = 2 * radius + 1;
1679
+ const logDepth = Boolean((_d = scene.frameState) === null || _d === void 0 ? void 0 : _d.useLogDepth);
1680
+ const distances = new Float64Array(width * width).fill(Infinity);
1681
+ // Farthest frustum first, so a nearer frustum's depth overwrites it.
1682
+ for (let f = frustums.length - 1; f >= 0; f--) {
1683
+ const framebuffer = (_e = scene._picking.getPickDepth(scene, f)) === null || _e === void 0 ? void 0 : _e.framebuffer;
1684
+ if (!framebuffer) {
1685
+ continue;
1686
+ }
1687
+ const near = frustums[f].near;
1688
+ const far = frustums[f].far;
1689
+ const pixels = scene.context.readPixels({ x, y, width, height: width, framebuffer });
1690
+ for (let i = 0; i < distances.length; i++) {
1691
+ const o = 4 * i;
1692
+ const packed = pixels[o] * PACKED_DEPTH.x + pixels[o + 1] * PACKED_DEPTH.y +
1693
+ pixels[o + 2] * PACKED_DEPTH.z + pixels[o + 3] * PACKED_DEPTH.w;
1694
+ const depth = packed / 255;
1695
+ if (depth > 0 && depth < 1) {
1696
+ // Undoes CesiumJS's logarithmic depth, or the perspective projection's depth when that is off.
1697
+ distances[i] = logDepth ?
1698
+ Math.pow(2, depth * Math.log2(far - near + 1)) - 1 + near :
1699
+ 2 * near * far / ((far + near) - (2 * depth - 1) * (far - near));
1700
+ }
1701
+ }
1702
+ }
1703
+ return distances;
1704
+ }
1705
+ /*
1706
+ * Offsets of the surface pixel around the centre for each radius where clearly nearer pixels surround it.
1707
+ */
1708
+ function FindGapSurfaces(distances, radius) {
1709
+ const width = 2 * radius + 1;
1710
+ const centre = distances[radius * width + radius];
1711
+ const found = [];
1712
+ for (const r of GAP_RADII) {
1713
+ if (r > radius) {
1714
+ break;
1715
+ }
1716
+ const near = [];
1717
+ const sectors = new Set();
1718
+ for (let dy = -r; dy <= r; dy++) {
1719
+ for (let dx = -r; dx <= r; dx++) {
1720
+ const distance = distances[(radius + dy) * width + (radius + dx)];
1721
+ // Nearer by the same margin that later decides the centre looked through a gap.
1722
+ if ((dx || dy) && distance * GAP_FARTHER + GAP_SLACK < centre) {
1723
+ near.push([distance, dx, dy]);
1724
+ const turn = (Math.atan2(dy, dx) + Math.PI) / (2 * Math.PI);
1725
+ sectors.add(Math.floor(turn * GAP_SECTORS) % GAP_SECTORS);
1726
+ }
1727
+ }
1728
+ }
1729
+ // An object's silhouette covers half the directions at most; points around a gap cover nearly all of them.
1730
+ if (sectors.size >= GAP_SECTORS_NEAR) {
1731
+ near.sort((a, b) => a[0] - b[0]);
1732
+ // The middle of the near pixels by distance stands for the surface, past stray points in front of it.
1733
+ const surface = near[Math.floor(near.length / 2)];
1734
+ found.push({ dx: surface[1], dy: surface[2] });
1735
+ }
1736
+ }
1737
+ return found;
1738
+ }
1739
+ /*
1740
+ * The point cloud surface around a pick that looked through a gap between its points, or null when it did not.
1741
+ */
1742
+ function fillGap(scene, position, picked) {
1743
+ const radius = GAP_RADII[GAP_RADII.length - 1];
1744
+ let distances = null;
1745
+ try {
1746
+ distances = readDepthDistances(scene, position, radius);
1747
+ }
1748
+ catch (e) {
1749
+ return null;
1750
+ }
1751
+ if (!distances) {
1752
+ return null;
1753
+ }
1754
+ const eye = scene.camera.positionWC;
1755
+ const pickedDistance = picked ? Cartesian3.distance(eye, picked) : Infinity;
1756
+ const xScale = scene.canvas.clientWidth / scene.drawingBufferWidth;
1757
+ const yScale = scene.canvas.clientHeight / scene.drawingBufferHeight;
1758
+ for (const { dx, dy } of FindGapSurfaces(distances, radius)) {
1759
+ // Buffer rows run bottom-up, window rows top-down.
1760
+ const surface = scene.pickPosition(new Cartesian2(position.x + dx * xScale, position.y - dy * yScale));
1761
+ if (!surface) {
1762
+ continue;
1763
+ }
1764
+ const distance = Cartesian3.distance(eye, surface);
1765
+ return pickedDistance > distance * GAP_FARTHER + GAP_SLACK ? surface : null;
1766
+ }
1767
+ return null;
1768
+ }
1221
1769
  /*
1222
1770
  * The point under a screen position: what is drawn there, else the ground plane, else a point at the last distance.
1223
1771
  */
@@ -1238,7 +1786,18 @@ function pickTarget(state, position) {
1238
1786
  picked = null;
1239
1787
  }
1240
1788
  }
1789
+ // Splats write no depth, so without this the camera turns and zooms about whatever is behind them.
1790
+ const ahead = isAhead(camera, picked) ? picked : undefined;
1791
+ const splat = DrawingUtils.GetSplatPosition({ viewer, cursor: position, behind: ahead });
1792
+ if (splat) {
1793
+ return { point: splat, source: "pick", ground: false };
1794
+ }
1241
1795
  const plausible = plausibleDistance(state);
1796
+ // A click between point cloud points sees the background; turning or zooming about that throws the camera far off.
1797
+ const surface = scene.pickPositionSupported ? fillGap(scene, position, ahead !== null && ahead !== void 0 ? ahead : null) : null;
1798
+ if (isAhead(camera, surface) && Cartesian3.distance(surface, camera.positionWC) < plausible) {
1799
+ return { point: surface, source: "pick", ground: false };
1800
+ }
1242
1801
  if (isAhead(camera, picked) && Cartesian3.distance(picked, camera.positionWC) < plausible) {
1243
1802
  return { point: picked, source: "pick", ground: isGroundPick(state, position) };
1244
1803
  }
@@ -13522,6 +14081,25 @@ var VisualRegisterCuller;
13522
14081
  VisualRegisterCuller.MarkShouldRecheck = MarkShouldRecheck;
13523
14082
  })(VisualRegisterCuller || (VisualRegisterCuller = {}));
13524
14083
 
14084
+ // A splat this close in front of a visual still lets it be picked, so scans laid over models do not steal clicks.
14085
+ const SPLAT_HIDES_MIN = 0.25;
14086
+ const SPLAT_HIDES_RATIO = 0.01;
14087
+ /*
14088
+ * Whether a drilled splat's visible surface lies clearly in front of what the depth shows at the cursor.
14089
+ */
14090
+ function isSplatInFront(viewer, cursor, behind) {
14091
+ // The drill found a splat somewhere in its area; this asks again at the cursor's own pixel.
14092
+ const hit = DrawingUtils.GetSplatPosition({ viewer, cursor });
14093
+ if (!hit) {
14094
+ return false;
14095
+ }
14096
+ if (!behind) {
14097
+ return true;
14098
+ }
14099
+ const eye = viewer.scene.camera.positionWC;
14100
+ const visual = Cartesian3.distance(eye, behind);
14101
+ return Cartesian3.distance(eye, hit) < visual - Math.max(SPLAT_HIDES_MIN, visual * SPLAT_HIDES_RATIO);
14102
+ }
13525
14103
  function isTilesetFeatureAlive(visual) {
13526
14104
  var _a, _b;
13527
14105
  const cTileset = visual === null || visual === void 0 ? void 0 : visual.tileset;
@@ -16360,9 +16938,25 @@ var VisualsRegister;
16360
16938
  const width = Math.ceil(EnsureNumber(params.width, 5));
16361
16939
  const height = Math.ceil(EnsureNumber(params.height, 5));
16362
16940
  const pickLimit = Math.ceil(EnsureNumber(params.pickLimit, 5));
16363
- const picked = this.viewer.scene.drillPick(new Cartesian2(cursor.x, cursor.y), pickLimit, width, height);
16941
+ const scene = this.viewer.scene;
16942
+ const position = new Cartesian2(cursor.x, cursor.y);
16943
+ // Splats are only trusted to hide what is behind them once their pick follows what is visibly drawn.
16944
+ const splatsHide = HasSplats(this.viewer) && IsSplatPickVisible(this.viewer);
16945
+ // Read before drillPick, which leaves pickPosition reading its own pick pass.
16946
+ const behind = splatsHide ? scene.pickPosition(DrawingUtils.PixelCentre(scene, position)) : null;
16947
+ let splatChecked = false;
16948
+ const picked = scene.drillPick(position, pickLimit, width, height);
16364
16949
  for (let i = 0; i < picked.length; i++) {
16365
16950
  const object = picked[i];
16951
+ if (splatsHide && IsSplatPick(object)) {
16952
+ if (!found.length && !splatChecked) {
16953
+ splatChecked = true;
16954
+ if (isSplatInFront(this.viewer, position, behind)) {
16955
+ break;
16956
+ }
16957
+ }
16958
+ continue;
16959
+ }
16366
16960
  const entity = (object && object.id && object.id instanceof Entity ? object.id : object);
16367
16961
  const visual = entity;
16368
16962
  if (((_a = visual === null || visual === void 0 ? void 0 : visual._register) === null || _a === void 0 ? void 0 : _a.Id) == this.id) {
@@ -30512,6 +31106,7 @@ var XGridsRenderEngine;
30512
31106
  if (typeof obj.setLodAutoLevelUp === "function") {
30513
31107
  obj.setLodAutoLevelUp(true);
30514
31108
  }
31109
+ TrackSplats(viewer, obj, true);
30515
31110
  return obj;
30516
31111
  }
30517
31112
  XGridsRenderEngine.Render = Render;
@@ -30546,6 +31141,7 @@ var XGridsRenderEngine;
30546
31141
  console.warn("[XGridsRenderEngine] Remove() LCCRender library not available.");
30547
31142
  return;
30548
31143
  }
31144
+ TrackSplats(viewer, renderObject, false);
30549
31145
  LCCRender.unload(renderObject);
30550
31146
  }
30551
31147
  XGridsRenderEngine.Remove = Remove;
@@ -49008,6 +49604,72 @@ function InstallPickGroundPatch(viewer) {
49008
49604
  return true;
49009
49605
  }
49010
49606
 
49607
+ /*
49608
+ * Draws XGrids splats after the opaque meshes, so a mesh drawn later cannot paint over nearer splats.
49609
+ */
49610
+ const SPLAT_ORDER_PATCH_KEY = "_nextspaceSplatOrderPatch";
49611
+ /*
49612
+ * Whether a command is one of the XGrids SDK's splat draws.
49613
+ */
49614
+ function isSplatCommand(command) {
49615
+ var _a;
49616
+ return typeof ((_a = command === null || command === void 0 ? void 0 : command.owner) === null || _a === void 0 ? void 0 : _a.splatCount) === "number";
49617
+ }
49618
+ /*
49619
+ * Moves splat draws to the end of the opaque pass, keeping everything else in order, and returns how many moved.
49620
+ */
49621
+ function OrderSplatCommands(list, opaquePass) {
49622
+ const splats = [];
49623
+ let kept = 0;
49624
+ for (let i = 0; i < list.length; i++) {
49625
+ const command = list[i];
49626
+ if (isSplatCommand(command)) {
49627
+ splats.push(command);
49628
+ }
49629
+ else {
49630
+ list[kept++] = command;
49631
+ }
49632
+ }
49633
+ if (!splats.length) {
49634
+ return 0;
49635
+ }
49636
+ list.length = kept;
49637
+ for (const command of splats) {
49638
+ command.pass = opaquePass;
49639
+ list.push(command);
49640
+ }
49641
+ return splats.length;
49642
+ }
49643
+ /*
49644
+ * Patches a viewer's primitive update so splat draws come after its opaque meshes.
49645
+ */
49646
+ function InstallSplatOrderPatch(viewer) {
49647
+ var _a, _b;
49648
+ const primitives = (_a = viewer === null || viewer === void 0 ? void 0 : viewer.scene) === null || _a === void 0 ? void 0 : _a.primitives;
49649
+ const opaquePass = (_b = Pass) === null || _b === void 0 ? void 0 : _b.OPAQUE;
49650
+ if (!primitives || typeof primitives.update !== "function" || typeof opaquePass !== "number") {
49651
+ return false;
49652
+ }
49653
+ if (primitives[SPLAT_ORDER_PATCH_KEY]) {
49654
+ return true;
49655
+ }
49656
+ const original = primitives.update;
49657
+ primitives.update = function (frameState) {
49658
+ original.call(this, frameState);
49659
+ if (!HasSplats(viewer)) {
49660
+ return;
49661
+ }
49662
+ try {
49663
+ OrderSplatCommands(frameState.commandList, opaquePass);
49664
+ }
49665
+ catch (e) {
49666
+ console.error("Failed to order splat draws.", e);
49667
+ }
49668
+ };
49669
+ primitives[SPLAT_ORDER_PATCH_KEY] = true;
49670
+ return true;
49671
+ }
49672
+
49011
49673
  const CESIUM_VIEWER_MANAGER_KEY = "_cesiumViewerManager";
49012
49674
  const CESIUM_VIEWER_EVENT_TRACKER_KEY = "_cesiumViewerEventTracker";
49013
49675
  const BACKGROUND_RENDERING_KEY = "_backgroundRendering";
@@ -49095,6 +49757,9 @@ var ViewerUtils;
49095
49757
  backgroundRendering(viewer);
49096
49758
  InstallPickLightingPatch(viewer);
49097
49759
  InstallPickGroundPatch(viewer);
49760
+ InstallPickSplatPatch(viewer);
49761
+ InstallPickThroughGroundPatch(viewer);
49762
+ InstallSplatOrderPatch(viewer);
49098
49763
  if (cameraControls != false) {
49099
49764
  CameraControls.Attach(viewer);
49100
49765
  if (ViewUtils.GetModelSpace(viewer)) {
@@ -61296,7 +61961,7 @@ var StyleUtils;
61296
61961
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
61297
61962
  })(StyleUtils || (StyleUtils = {}));
61298
61963
 
61299
- const VERSION = "7.9.1";
61964
+ const VERSION = "7.9.2";
61300
61965
  /**
61301
61966
  * Updates the environment instance used by bruce-cesium to one specified.
61302
61967
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.
@@ -61313,5 +61978,5 @@ const getENVIRONMENT = () => {
61313
61978
  return ENVIRONMENT;
61314
61979
  };
61315
61980
 
61316
- export { VERSION, setENVIRONMENT, getENVIRONMENT, ClusterItems, PointClustering, PointClusterSize, CesiumAnimatedInOut, DisplacedSurfacePrimitive, CesiumAnimatedProperty, isStyleChanged, isOutlineChanged$1 as isOutlineChanged, StyleEffective, EntityRenderEngine, EntityRenderEngineModel3d, EntityRenderEnginePoint, extractMetadataFromFileUrl, EntityRenderEnginePolygon, EntityRenderEnginePolyline, TextureFrameSeriesAnimator, TextureValueLabels, MenuItemCreator, MenuItemManager, MenuItemStyles, MenuItemStyleOverlay, CesiumParabola, EntityLabel, EntityLabelGroup, LiveCursor, SharedGetters, EntitySimulation, DataSourceStaticKmlManager, DataLabRenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, AssemblyRenderManager, GoogleSearchRenderManager, RelationsRenderManager, RenderManager, TilesetArbRenderManager, TilesetCadRenderManager, TilesetEntitiesRenderManager, TilesetGooglePhotosRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TileRenderEngine, createTileset, TilesetRenderEngine, ViewRenderEngine, VisualRegisterCuller, VisualsRegister, XGridsRenderEngine, CesiumEntityStyler, DrawingUtils, EntityUtils, MeasureUtils, StyleUtils, CESIUM_INSPECTOR_KEY, CESIUM_TIMELINE_KEY, CESIUM_TIMELINE_LIVE_KEY, CESIUM_TIMELINE_LIVE_PADDING_KEY, CESIUM_TIMELINE_INTERVAL_KEY, CESIUM_MODEL_SPACE_KEY, CESIUM_MODEL_SPACE_POSITIONING_KEY, DEFAULT_LIVE_PADDING_SECONDS, DEFAULT_BRIGHTNESS_SHIFT, DEFAULT_LIGHT_INTENSITY, LIGHTING_SETTINGS_VERSION, LIGHT_INTENSITY_COMPENSATION, MAX_COMPENSATED_LIGHT_INTENSITY, ViewUtils, CesiumMapGrid, GltfGenerator, GltfGizmo, DeviceProfile, CesiumViewMonitor, CameraControls, ViewGroundArea, ViewerEventTracker, ViewerUtils, Draw3dPolygon, Draw3dPolyline, MeasureCreator, Walkthrough, WidgetControlViewBar, WidgetControlViewBarSearch, WidgetLeftPanelTab, WidgetLeftPanelTabBookmarks, WidgetLeftPanelTabDashboard, EMenuItemState, WidgetLeftPanelTabMenuItems, Widget, VIEWER_BOOKMARKS_WIDGET_KEY, WidgetBookmarks, WidgetBranding, ECursor, WidgetCursorBar, WidgetEmbeddedInfoView, WidgetInfoView, VIEWER_LEFT_PANEL_WIDGET_KEY, VIEWER_LEFT_PANEL_CSS_VAR_LEFT, CreateTabIconSvg, WidgetLeftPanel, WidgetNavCompass$$1 as WidgetNavCompass, VIEWER_VIEW_BAR_WIDGET_KEY, WidgetViewBar };
61981
+ export { VERSION, setENVIRONMENT, getENVIRONMENT, ClusterItems, PointClustering, PointClusterSize, CesiumAnimatedInOut, DisplacedSurfacePrimitive, CesiumAnimatedProperty, isStyleChanged, isOutlineChanged$1 as isOutlineChanged, StyleEffective, EntityRenderEngine, EntityRenderEngineModel3d, EntityRenderEnginePoint, extractMetadataFromFileUrl, EntityRenderEnginePolygon, EntityRenderEnginePolyline, TextureFrameSeriesAnimator, TextureValueLabels, MenuItemCreator, MenuItemManager, MenuItemStyles, MenuItemStyleOverlay, CesiumParabola, EntityLabel, EntityLabelGroup, LiveCursor, SharedGetters, EntitySimulation, DataSourceStaticKmlManager, DataLabRenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, AssemblyRenderManager, GoogleSearchRenderManager, RelationsRenderManager, RenderManager, TilesetArbRenderManager, TilesetCadRenderManager, TilesetEntitiesRenderManager, TilesetGooglePhotosRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TileRenderEngine, createTileset, TilesetRenderEngine, ViewRenderEngine, VisualRegisterCuller, VisualsRegister, XGridsRenderEngine, CesiumEntityStyler, DrawingUtils, EntityUtils, MeasureUtils, StyleUtils, CESIUM_INSPECTOR_KEY, CESIUM_TIMELINE_KEY, CESIUM_TIMELINE_LIVE_KEY, CESIUM_TIMELINE_LIVE_PADDING_KEY, CESIUM_TIMELINE_INTERVAL_KEY, CESIUM_MODEL_SPACE_KEY, CESIUM_MODEL_SPACE_POSITIONING_KEY, DEFAULT_LIVE_PADDING_SECONDS, DEFAULT_BRIGHTNESS_SHIFT, DEFAULT_LIGHT_INTENSITY, LIGHTING_SETTINGS_VERSION, LIGHT_INTENSITY_COMPENSATION, MAX_COMPENSATED_LIGHT_INTENSITY, ViewUtils, CesiumMapGrid, GltfGenerator, GltfGizmo, DeviceProfile, CesiumViewMonitor, CameraControls, FindGapSurfaces, ViewGroundArea, ViewerEventTracker, ViewerUtils, Draw3dPolygon, Draw3dPolyline, MeasureCreator, Walkthrough, WidgetControlViewBar, WidgetControlViewBarSearch, WidgetLeftPanelTab, WidgetLeftPanelTabBookmarks, WidgetLeftPanelTabDashboard, EMenuItemState, WidgetLeftPanelTabMenuItems, Widget, VIEWER_BOOKMARKS_WIDGET_KEY, WidgetBookmarks, WidgetBranding, ECursor, WidgetCursorBar, WidgetEmbeddedInfoView, WidgetInfoView, VIEWER_LEFT_PANEL_WIDGET_KEY, VIEWER_LEFT_PANEL_CSS_VAR_LEFT, CreateTabIconSvg, WidgetLeftPanel, WidgetNavCompass$$1 as WidgetNavCompass, VIEWER_VIEW_BAR_WIDGET_KEY, WidgetViewBar };
61317
61982
  //# sourceMappingURL=bruce-cesium.es5.js.map