bruce-cesium 7.9.0 → 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.
- package/dist/bruce-cesium.es5.js +772 -86
- package/dist/bruce-cesium.es5.js.map +1 -1
- package/dist/bruce-cesium.umd.js +770 -83
- package/dist/bruce-cesium.umd.js.map +1 -1
- package/dist/lib/bruce-cesium.js +1 -1
- package/dist/lib/internal/cesium-patch-pick-splat.js +127 -0
- package/dist/lib/internal/cesium-patch-pick-splat.js.map +1 -0
- package/dist/lib/internal/cesium-patch-pick-through-ground.js +155 -0
- package/dist/lib/internal/cesium-patch-pick-through-ground.js.map +1 -0
- package/dist/lib/internal/cesium-patch-splat-order.js +73 -0
- package/dist/lib/internal/cesium-patch-splat-order.js.map +1 -0
- package/dist/lib/rendering/render-managers/common/entity-label.js +4 -4
- package/dist/lib/rendering/render-managers/common/entity-label.js.map +1 -1
- package/dist/lib/rendering/visuals-register.js +60 -2
- package/dist/lib/rendering/visuals-register.js.map +1 -1
- package/dist/lib/rendering/xgrids-render-engine.js +3 -0
- package/dist/lib/rendering/xgrids-render-engine.js.map +1 -1
- package/dist/lib/utils/drawing-utils.js +241 -75
- package/dist/lib/utils/drawing-utils.js.map +1 -1
- package/dist/lib/viewer/camera-controls.js +134 -1
- package/dist/lib/viewer/camera-controls.js.map +1 -1
- package/dist/lib/viewer/viewer-utils.js +6 -0
- package/dist/lib/viewer/viewer-utils.js.map +1 -1
- package/dist/types/bruce-cesium.d.ts +1 -1
- package/dist/types/internal/cesium-patch-pick-splat.d.ts +8 -0
- package/dist/types/internal/cesium-patch-pick-through-ground.d.ts +7 -0
- package/dist/types/internal/cesium-patch-splat-order.d.ts +2 -0
- package/dist/types/rendering/visuals-register.d.ts +3 -0
- package/dist/types/utils/drawing-utils.d.ts +7 -1
- package/dist/types/viewer/camera-controls.d.ts +4 -0
- package/package.json +1 -1
package/dist/bruce-cesium.umd.js
CHANGED
|
@@ -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
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
//
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
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
|
-
|
|
516
|
-
|
|
942
|
+
}
|
|
943
|
+
if (canCache) {
|
|
944
|
+
viewer[ACCURATE_PICK_KEY] = {
|
|
517
945
|
position: pos3d,
|
|
518
|
-
cursor: cursor.clone()
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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
|
-
|
|
526
|
-
|
|
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
|
}
|
|
@@ -11097,7 +11656,7 @@
|
|
|
11097
11656
|
* If one exists then the action is ignored.
|
|
11098
11657
|
*/
|
|
11099
11658
|
function Attach(params) {
|
|
11100
|
-
var _a, _b, _c;
|
|
11659
|
+
var _a, _b, _c, _d;
|
|
11101
11660
|
const { rego, viewer, pos3d, visualRegister, api, options, groupId } = params;
|
|
11102
11661
|
if (!rego || !viewer) {
|
|
11103
11662
|
return;
|
|
@@ -11108,8 +11667,8 @@
|
|
|
11108
11667
|
return Attach({
|
|
11109
11668
|
...params,
|
|
11110
11669
|
pos3d: undefined,
|
|
11111
|
-
options: (_a =
|
|
11112
|
-
groupId: (
|
|
11670
|
+
options: group ? group.options : (_b = (_a = visualRegister.GetLabelDefaults) === null || _a === void 0 ? void 0 : _a.call(visualRegister)) !== null && _b !== void 0 ? _b : options,
|
|
11671
|
+
groupId: (_c = group === null || group === void 0 ? void 0 : group.groupId) !== null && _c !== void 0 ? _c : groupId,
|
|
11113
11672
|
persistent: true
|
|
11114
11673
|
});
|
|
11115
11674
|
}
|
|
@@ -11119,7 +11678,7 @@
|
|
|
11119
11678
|
if (rego[EntityLabel.ATTACH_KEY].Persistent && params.persistent !== true && !groupId) {
|
|
11120
11679
|
return rego[EntityLabel.ATTACH_KEY];
|
|
11121
11680
|
}
|
|
11122
|
-
rego[EntityLabel.ATTACH_KEY].Persistent = (
|
|
11681
|
+
rego[EntityLabel.ATTACH_KEY].Persistent = (_d = params.persistent) !== null && _d !== void 0 ? _d : Boolean(groupId);
|
|
11123
11682
|
rego[EntityLabel.ATTACH_KEY].Configure(options, groupId);
|
|
11124
11683
|
return rego[EntityLabel.ATTACH_KEY];
|
|
11125
11684
|
}
|
|
@@ -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;
|
|
@@ -13830,7 +14408,7 @@
|
|
|
13830
14408
|
viewer,
|
|
13831
14409
|
api: (_b = register.ApiGetters) === null || _b === void 0 ? void 0 : _b.GetBruceApi(),
|
|
13832
14410
|
visualRegister: register,
|
|
13833
|
-
options: labelGroup
|
|
14411
|
+
options: labelGroup ? labelGroup.options : register.GetLabelDefaults(),
|
|
13834
14412
|
groupId: labelGroup === null || labelGroup === void 0 ? void 0 : labelGroup.groupId,
|
|
13835
14413
|
persistent: true
|
|
13836
14414
|
});
|
|
@@ -14013,6 +14591,8 @@
|
|
|
14013
14591
|
this.menuItemSources = new Map();
|
|
14014
14592
|
// Set when the data source order no longer matches the zIndexes seen, so it is re-applied once.
|
|
14015
14593
|
this.sourceOrderDirty = false;
|
|
14594
|
+
// The look of labelled Entities no label group holds.
|
|
14595
|
+
this.labelDefaults = null;
|
|
14016
14596
|
// Stops following what is simulated, so labels can read it again when it changes.
|
|
14017
14597
|
this.simulationRemoval = null;
|
|
14018
14598
|
this.shadowsRemoval = null;
|
|
@@ -16333,9 +16913,25 @@
|
|
|
16333
16913
|
const width = Math.ceil(EnsureNumber(params.width, 5));
|
|
16334
16914
|
const height = Math.ceil(EnsureNumber(params.height, 5));
|
|
16335
16915
|
const pickLimit = Math.ceil(EnsureNumber(params.pickLimit, 5));
|
|
16336
|
-
const
|
|
16916
|
+
const scene = this.viewer.scene;
|
|
16917
|
+
const position = new Cesium.Cartesian2(cursor.x, cursor.y);
|
|
16918
|
+
// Splats are only trusted to hide what is behind them once their pick follows what is visibly drawn.
|
|
16919
|
+
const splatsHide = HasSplats(this.viewer) && IsSplatPickVisible(this.viewer);
|
|
16920
|
+
// Read before drillPick, which leaves pickPosition reading its own pick pass.
|
|
16921
|
+
const behind = splatsHide ? scene.pickPosition(exports.DrawingUtils.PixelCentre(scene, position)) : null;
|
|
16922
|
+
let splatChecked = false;
|
|
16923
|
+
const picked = scene.drillPick(position, pickLimit, width, height);
|
|
16337
16924
|
for (let i = 0; i < picked.length; i++) {
|
|
16338
16925
|
const object = picked[i];
|
|
16926
|
+
if (splatsHide && IsSplatPick(object)) {
|
|
16927
|
+
if (!found.length && !splatChecked) {
|
|
16928
|
+
splatChecked = true;
|
|
16929
|
+
if (isSplatInFront(this.viewer, position, behind)) {
|
|
16930
|
+
break;
|
|
16931
|
+
}
|
|
16932
|
+
}
|
|
16933
|
+
continue;
|
|
16934
|
+
}
|
|
16339
16935
|
const entity = (object && object.id && object.id instanceof Cesium.Entity ? object.id : object);
|
|
16340
16936
|
const visual = entity;
|
|
16341
16937
|
if (((_a = visual === null || visual === void 0 ? void 0 : visual._register) === null || _a === void 0 ? void 0 : _a.Id) == this.id) {
|
|
@@ -16867,6 +17463,25 @@
|
|
|
16867
17463
|
var _a;
|
|
16868
17464
|
return (_a = this.labelGroups) === null || _a === void 0 ? void 0 : _a.Resolve(entityId, menuItemId);
|
|
16869
17465
|
}
|
|
17466
|
+
/*
|
|
17467
|
+
* How a labelled Entity in no label group is drawn, such as an account's default look; null draws plain text.
|
|
17468
|
+
*/
|
|
17469
|
+
SetLabelDefaults(options) {
|
|
17470
|
+
if (this.disposed) {
|
|
17471
|
+
return;
|
|
17472
|
+
}
|
|
17473
|
+
const next = options ? { ...options } : null;
|
|
17474
|
+
if (JSON.stringify(next) === JSON.stringify(this.labelDefaults)) {
|
|
17475
|
+
return;
|
|
17476
|
+
}
|
|
17477
|
+
this.labelDefaults = next;
|
|
17478
|
+
for (const entityId of this.GetLabelled()) {
|
|
17479
|
+
this.queueUpdate({ entityId, refresh: false });
|
|
17480
|
+
}
|
|
17481
|
+
}
|
|
17482
|
+
GetLabelDefaults() {
|
|
17483
|
+
return this.labelDefaults ? { ...this.labelDefaults } : null;
|
|
17484
|
+
}
|
|
16870
17485
|
/*
|
|
16871
17486
|
* Called by a group label once it is on screen, so its entity's default image is read only when it can be seen.
|
|
16872
17487
|
*/
|
|
@@ -30415,6 +31030,7 @@
|
|
|
30415
31030
|
if (typeof obj.setLodAutoLevelUp === "function") {
|
|
30416
31031
|
obj.setLodAutoLevelUp(true);
|
|
30417
31032
|
}
|
|
31033
|
+
TrackSplats(viewer, obj, true);
|
|
30418
31034
|
return obj;
|
|
30419
31035
|
}
|
|
30420
31036
|
XGridsRenderEngine.Render = Render;
|
|
@@ -30449,6 +31065,7 @@
|
|
|
30449
31065
|
console.warn("[XGridsRenderEngine] Remove() LCCRender library not available.");
|
|
30450
31066
|
return;
|
|
30451
31067
|
}
|
|
31068
|
+
TrackSplats(viewer, renderObject, false);
|
|
30452
31069
|
LCCRender.unload(renderObject);
|
|
30453
31070
|
}
|
|
30454
31071
|
XGridsRenderEngine.Remove = Remove;
|
|
@@ -48858,6 +49475,72 @@
|
|
|
48858
49475
|
return true;
|
|
48859
49476
|
}
|
|
48860
49477
|
|
|
49478
|
+
/*
|
|
49479
|
+
* Draws XGrids splats after the opaque meshes, so a mesh drawn later cannot paint over nearer splats.
|
|
49480
|
+
*/
|
|
49481
|
+
const SPLAT_ORDER_PATCH_KEY = "_nextspaceSplatOrderPatch";
|
|
49482
|
+
/*
|
|
49483
|
+
* Whether a command is one of the XGrids SDK's splat draws.
|
|
49484
|
+
*/
|
|
49485
|
+
function isSplatCommand(command) {
|
|
49486
|
+
var _a;
|
|
49487
|
+
return typeof ((_a = command === null || command === void 0 ? void 0 : command.owner) === null || _a === void 0 ? void 0 : _a.splatCount) === "number";
|
|
49488
|
+
}
|
|
49489
|
+
/*
|
|
49490
|
+
* Moves splat draws to the end of the opaque pass, keeping everything else in order, and returns how many moved.
|
|
49491
|
+
*/
|
|
49492
|
+
function OrderSplatCommands(list, opaquePass) {
|
|
49493
|
+
const splats = [];
|
|
49494
|
+
let kept = 0;
|
|
49495
|
+
for (let i = 0; i < list.length; i++) {
|
|
49496
|
+
const command = list[i];
|
|
49497
|
+
if (isSplatCommand(command)) {
|
|
49498
|
+
splats.push(command);
|
|
49499
|
+
}
|
|
49500
|
+
else {
|
|
49501
|
+
list[kept++] = command;
|
|
49502
|
+
}
|
|
49503
|
+
}
|
|
49504
|
+
if (!splats.length) {
|
|
49505
|
+
return 0;
|
|
49506
|
+
}
|
|
49507
|
+
list.length = kept;
|
|
49508
|
+
for (const command of splats) {
|
|
49509
|
+
command.pass = opaquePass;
|
|
49510
|
+
list.push(command);
|
|
49511
|
+
}
|
|
49512
|
+
return splats.length;
|
|
49513
|
+
}
|
|
49514
|
+
/*
|
|
49515
|
+
* Patches a viewer's primitive update so splat draws come after its opaque meshes.
|
|
49516
|
+
*/
|
|
49517
|
+
function InstallSplatOrderPatch(viewer) {
|
|
49518
|
+
var _a, _b;
|
|
49519
|
+
const primitives = (_a = viewer === null || viewer === void 0 ? void 0 : viewer.scene) === null || _a === void 0 ? void 0 : _a.primitives;
|
|
49520
|
+
const opaquePass = (_b = Cesium.Pass) === null || _b === void 0 ? void 0 : _b.OPAQUE;
|
|
49521
|
+
if (!primitives || typeof primitives.update !== "function" || typeof opaquePass !== "number") {
|
|
49522
|
+
return false;
|
|
49523
|
+
}
|
|
49524
|
+
if (primitives[SPLAT_ORDER_PATCH_KEY]) {
|
|
49525
|
+
return true;
|
|
49526
|
+
}
|
|
49527
|
+
const original = primitives.update;
|
|
49528
|
+
primitives.update = function (frameState) {
|
|
49529
|
+
original.call(this, frameState);
|
|
49530
|
+
if (!HasSplats(viewer)) {
|
|
49531
|
+
return;
|
|
49532
|
+
}
|
|
49533
|
+
try {
|
|
49534
|
+
OrderSplatCommands(frameState.commandList, opaquePass);
|
|
49535
|
+
}
|
|
49536
|
+
catch (e) {
|
|
49537
|
+
console.error("Failed to order splat draws.", e);
|
|
49538
|
+
}
|
|
49539
|
+
};
|
|
49540
|
+
primitives[SPLAT_ORDER_PATCH_KEY] = true;
|
|
49541
|
+
return true;
|
|
49542
|
+
}
|
|
49543
|
+
|
|
48861
49544
|
const CESIUM_VIEWER_MANAGER_KEY = "_cesiumViewerManager";
|
|
48862
49545
|
const CESIUM_VIEWER_EVENT_TRACKER_KEY = "_cesiumViewerEventTracker";
|
|
48863
49546
|
const BACKGROUND_RENDERING_KEY = "_backgroundRendering";
|
|
@@ -48944,6 +49627,9 @@
|
|
|
48944
49627
|
backgroundRendering(viewer);
|
|
48945
49628
|
InstallPickLightingPatch(viewer);
|
|
48946
49629
|
InstallPickGroundPatch(viewer);
|
|
49630
|
+
InstallPickSplatPatch(viewer);
|
|
49631
|
+
InstallPickThroughGroundPatch(viewer);
|
|
49632
|
+
InstallSplatOrderPatch(viewer);
|
|
48947
49633
|
if (cameraControls != false) {
|
|
48948
49634
|
exports.CameraControls.Attach(viewer);
|
|
48949
49635
|
if (exports.ViewUtils.GetModelSpace(viewer)) {
|
|
@@ -61105,7 +61791,7 @@ void main() {
|
|
|
61105
61791
|
StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
|
|
61106
61792
|
})(exports.StyleUtils || (exports.StyleUtils = {}));
|
|
61107
61793
|
|
|
61108
|
-
const VERSION = "7.9.
|
|
61794
|
+
const VERSION = "7.9.2";
|
|
61109
61795
|
/**
|
|
61110
61796
|
* Updates the environment instance used by bruce-cesium to one specified.
|
|
61111
61797
|
* This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.
|
|
@@ -61146,6 +61832,7 @@ void main() {
|
|
|
61146
61832
|
exports.LIGHTING_SETTINGS_VERSION = LIGHTING_SETTINGS_VERSION;
|
|
61147
61833
|
exports.LIGHT_INTENSITY_COMPENSATION = LIGHT_INTENSITY_COMPENSATION;
|
|
61148
61834
|
exports.MAX_COMPENSATED_LIGHT_INTENSITY = MAX_COMPENSATED_LIGHT_INTENSITY;
|
|
61835
|
+
exports.FindGapSurfaces = FindGapSurfaces;
|
|
61149
61836
|
exports.Draw3dPolygon = Draw3dPolygon;
|
|
61150
61837
|
exports.Draw3dPolyline = Draw3dPolyline;
|
|
61151
61838
|
exports.WidgetControlViewBarSearch = WidgetControlViewBarSearch;
|