bruce-cesium 7.1.8 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2969,8 +2969,30 @@
2969
2969
  const CESIUM_TIMELINE_INTERVAL_KEY = "_nextspace_timeline_interval";
2970
2970
  const CESIUM_MODEL_SPACE_KEY = "_nextspace_model_space";
2971
2971
  const DEFAULT_LIVE_PADDING_SECONDS = 30 * 60;
2972
- const DEFAULT_BRIGHTNESS_SHIFT = 0.2;
2973
- const DEFAULT_LIGHT_INTENSITY = 3;
2972
+ // Atmosphere shifts are left alone by default. Tuning against a CAD scene showed the lift washing the
2973
+ // sky without helping models, which are lit by the environment map rather than by the atmosphere.
2974
+ const DEFAULT_BRIGHTNESS_SHIFT = 0;
2975
+ /*
2976
+ * Environment lighting defaults, arrived at by tuning against a white CAD model on CesiumJS 1.143.
2977
+ */
2978
+ function neutralEnvironmentMapOptions() {
2979
+ return {
2980
+ groundColor: Cesium.Color.WHITE.clone(),
2981
+ groundAlbedo: 0.26,
2982
+ brightness: 1.5,
2983
+ atmosphereScatteringIntensity: 3.2
2984
+ };
2985
+ }
2986
+ // Sun intensity used when the bookmark's lighting settings name none.
2987
+ const DEFAULT_LIGHT_INTENSITY = 2;
2988
+ // Current shape of a bookmark's lighting settings.
2989
+ const LIGHTING_SETTINGS_VERSION = 2;
2990
+ // Settings we apply when version is unset or <=1 to compensate for newer Cesium looking darker and more yellow.
2991
+ const LIGHT_INTENSITY_COMPENSATION = 1.2;
2992
+ const MAX_COMPENSATED_LIGHT_INTENSITY = 3;
2993
+ // Set by a host that wants something other than the defaults above. Undefined means "not overridden".
2994
+ let overriddenEnvironmentMapOptions;
2995
+ let overriddenImageBasedLighting;
2974
2996
  (function (ViewUtils) {
2975
2997
  function GatherLegacyMapTiles(params) {
2976
2998
  const viewer = params.viewer;
@@ -3338,15 +3360,97 @@
3338
3360
  SCENE.skyAtmosphere.brightnessShift = shift;
3339
3361
  }
3340
3362
  }
3363
+ // The environment map is built from the atmosphere, and lighting it from the scene's own light
3364
+ // rather than from straight above is what stops it reading flat.
3365
+ const CESIUM = Cesium;
3366
+ if (EngineShadesModelsDarker() && SCENE.atmosphere && CESIUM.DynamicAtmosphereLightingType) {
3367
+ SCENE.atmosphere.dynamicLighting = CESIUM.DynamicAtmosphereLightingType.SCENE_LIGHT;
3368
+ }
3341
3369
  }
3342
3370
  ViewUtils.ApplyDefaultBrightness = ApplyDefaultBrightness;
3343
3371
  /**
3344
- * Options handed to every tileset and model this library creates.
3372
+ * Options applied to the environment based lighting of every tileset and model this library creates.
3373
+ * Null leaves CesiumJS's own defaults in place.
3374
+ * @param options eg { enabled: false } to switch the lighting off, or { saturation: 0 } to keep the
3375
+ * lift without the ground bounce tinting untextured geometry.
3376
+ */
3377
+ function SetDefaultEnvironmentMapOptions(options) {
3378
+ overriddenEnvironmentMapOptions = options;
3379
+ }
3380
+ ViewUtils.SetDefaultEnvironmentMapOptions = SetDefaultEnvironmentMapOptions;
3381
+ /**
3382
+ * Whether the host app's CesiumJS is a build that shades models darker than the ones these bookmarks were set up against.
3383
+ * DynamicEnvironmentMapManager arrived with that change, so its presence marks
3345
3384
  */
3346
- function DefaultEnvironmentMapOptions() {
3347
- return { enabled: false };
3385
+ function GetDefaultEnvironmentMapOptions(
3386
+ // Overridable so the tuned values can be asserted without swapping out CesiumJS.
3387
+ engineShadesDarker = EngineShadesModelsDarker()) {
3388
+ if (overriddenEnvironmentMapOptions !== undefined) {
3389
+ return overriddenEnvironmentMapOptions ? { ...overriddenEnvironmentMapOptions } : null;
3390
+ }
3391
+ if (!engineShadesDarker) {
3392
+ return null;
3393
+ }
3394
+ return neutralEnvironmentMapOptions();
3395
+ }
3396
+ ViewUtils.GetDefaultEnvironmentMapOptions = GetDefaultEnvironmentMapOptions;
3397
+ /**
3398
+ * The lighting options every tileset and model this library creates is built with.
3399
+ * Spread into the construction options, since both are read once when a primitive is made.
3400
+ */
3401
+ function DefaultLightingProps(engineShadesDarker = EngineShadesModelsDarker()) {
3402
+ const props = {};
3403
+ const environmentMapOptions = GetDefaultEnvironmentMapOptions(engineShadesDarker);
3404
+ if (environmentMapOptions) {
3405
+ props.environmentMapOptions = environmentMapOptions;
3406
+ }
3407
+ const imageBasedLighting = GetDefaultImageBasedLighting();
3408
+ if (imageBasedLighting) {
3409
+ props.imageBasedLighting = imageBasedLighting;
3410
+ }
3411
+ return props;
3412
+ }
3413
+ ViewUtils.DefaultLightingProps = DefaultLightingProps;
3414
+ /**
3415
+ * ImageBasedLighting applied to every tileset and model this library creates. Null, the default,
3416
+ * leaves CesiumJS's own in place.
3417
+ * @param imageBasedLighting a Cesium.ImageBasedLighting, shared across primitives.
3418
+ */
3419
+ function SetDefaultImageBasedLighting(imageBasedLighting) {
3420
+ overriddenImageBasedLighting = imageBasedLighting;
3421
+ }
3422
+ ViewUtils.SetDefaultImageBasedLighting = SetDefaultImageBasedLighting;
3423
+ function GetDefaultImageBasedLighting() {
3424
+ return overriddenImageBasedLighting || null;
3425
+ }
3426
+ ViewUtils.GetDefaultImageBasedLighting = GetDefaultImageBasedLighting;
3427
+ function EngineShadesModelsDarker() {
3428
+ return typeof Cesium.DynamicEnvironmentMapManager !== "undefined";
3429
+ }
3430
+ ViewUtils.EngineShadesModelsDarker = EngineShadesModelsDarker;
3431
+ /**
3432
+ * Resolves the sun colour and intensity to apply for a bookmark's lighting settings.
3433
+ * @param lighting the bookmark's lighting settings, or null when it carries none.
3434
+ * @returns the colour and intensity to put on the scene light.
3435
+ */
3436
+ function ResolveLightSettings(lighting,
3437
+ // Overridable so both branches can be exercised without swapping out CesiumJS.
3438
+ engineShadesDarker = EngineShadesModelsDarker()) {
3439
+ const raw = lighting === null || lighting === void 0 ? void 0 : lighting.color;
3440
+ const parsed = raw ? Cesium.Color.fromCssColorString(raw) : null;
3441
+ const intensity = Number(lighting === null || lighting === void 0 ? void 0 : lighting.intensity);
3442
+ const named = Number.isFinite(intensity) ? intensity : DEFAULT_LIGHT_INTENSITY;
3443
+ // No settings at all means nothing was carried over from the older engine, so there is nothing
3444
+ // to compensate. A settings object with no version in it is the case that predates the field.
3445
+ const version = Number(lighting === null || lighting === void 0 ? void 0 : lighting.lightingVer);
3446
+ const legacy = lighting != null && (!Number.isFinite(version) || version <= 1);
3447
+ const compensated = Math.min(named * LIGHT_INTENSITY_COMPENSATION, MAX_COMPENSATED_LIGHT_INTENSITY);
3448
+ return {
3449
+ color: parsed || Cesium.Color.WHITE,
3450
+ intensity: legacy && engineShadesDarker ? compensated : named
3451
+ };
3348
3452
  }
3349
- ViewUtils.DefaultEnvironmentMapOptions = DefaultEnvironmentMapOptions;
3453
+ ViewUtils.ResolveLightSettings = ResolveLightSettings;
3350
3454
  function SetGlobeDetails(params) {
3351
3455
  let { viewer, hidden, baseColor } = params;
3352
3456
  const scene = viewer === null || viewer === void 0 ? void 0 : viewer.scene;
@@ -14671,8 +14775,8 @@
14671
14775
  const defaultProps = {
14672
14776
  // "Optimization option. Reduce the screen space error for tiles that are further away from the camera.".
14673
14777
  dynamicScreenSpaceError: true,
14674
- environmentMapOptions: exports.ViewUtils.DefaultEnvironmentMapOptions()
14675
14778
  };
14779
+ Object.assign(defaultProps, exports.ViewUtils.DefaultLightingProps());
14676
14780
  if (noMemoryLimit != true) {
14677
14781
  // "The maximum amount of memory in MB that can be used by the tileset.".
14678
14782
  defaultProps.maximumMemoryUsage = 512;
@@ -21388,7 +21492,7 @@
21388
21492
  }
21389
21493
  this.cTileset = await CESIUM.Cesium3DTileset.fromUrl(proxyRootUrl, {
21390
21494
  showCreditsOnScreen: true,
21391
- environmentMapOptions: exports.ViewUtils.DefaultEnvironmentMapOptions()
21495
+ ...exports.ViewUtils.DefaultLightingProps()
21392
21496
  });
21393
21497
  }
21394
21498
  else {
@@ -22924,7 +23028,7 @@
22924
23028
  const cEntity = this.viewer.entities.add({
22925
23029
  model: {
22926
23030
  uri: lod["ClientFile"].URL,
22927
- environmentMapOptions: exports.ViewUtils.DefaultEnvironmentMapOptions(),
23031
+ ...exports.ViewUtils.DefaultLightingProps(),
22928
23032
  heightReference: Cesium.HeightReference.NONE
22929
23033
  },
22930
23034
  // point: {
@@ -28982,13 +29086,15 @@
28982
29086
  if (lighting == null) {
28983
29087
  lighting = {
28984
29088
  color: Cesium.Color.WHITE.toCssColorString(),
28985
- intensity: DEFAULT_LIGHT_INTENSITY
29089
+ intensity: DEFAULT_LIGHT_INTENSITY,
29090
+ lightingVer: LIGHTING_SETTINGS_VERSION
28986
29091
  };
28987
29092
  }
28988
29093
  const light = viewer.scene.light;
28989
29094
  if (light) {
28990
- light.color = Cesium.Color.fromCssColorString(lighting.color);
28991
- light.intensity = EnsureNumber(lighting.intensity);
29095
+ const resolved = exports.ViewUtils.ResolveLightSettings(lighting);
29096
+ light.color = resolved.color;
29097
+ light.intensity = resolved.intensity;
28992
29098
  }
28993
29099
  exports.ViewUtils.ApplyDefaultBrightness(viewer, EnsureNumber(lighting.brightnessShift, DEFAULT_BRIGHTNESS_SHIFT));
28994
29100
  let quality = bSettings === null || bSettings === void 0 ? void 0 : bSettings.quality;
@@ -38639,7 +38745,7 @@
38639
38745
  id: BModels.ObjectUtils.UId(15),
38640
38746
  model: {
38641
38747
  uri: params.lodUrl,
38642
- environmentMapOptions: exports.ViewUtils.DefaultEnvironmentMapOptions(),
38748
+ ...exports.ViewUtils.DefaultLightingProps(),
38643
38749
  heightReference: heightRef,
38644
38750
  scale: new Cesium.CallbackProperty(() => scale * styleScale, true),
38645
38751
  shadows: Cesium.ShadowMode.ENABLED,
@@ -39282,7 +39388,7 @@
39282
39388
  url: url,
39283
39389
  asynchronous: true,
39284
39390
  scale: scale,
39285
- environmentMapOptions: exports.ViewUtils.DefaultEnvironmentMapOptions()
39391
+ ...exports.ViewUtils.DefaultLightingProps()
39286
39392
  });
39287
39393
  }
39288
39394
  // Older versions of Cesium have a fromGltf method.
@@ -43419,7 +43525,7 @@ void main() {
43419
43525
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
43420
43526
  })(exports.StyleUtils || (exports.StyleUtils = {}));
43421
43527
 
43422
- const VERSION = "7.1.8";
43528
+ const VERSION = "7.2.0";
43423
43529
  /**
43424
43530
  * Updates the environment instance used by bruce-cesium to one specified.
43425
43531
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.
@@ -43452,6 +43558,9 @@ void main() {
43452
43558
  exports.DEFAULT_LIVE_PADDING_SECONDS = DEFAULT_LIVE_PADDING_SECONDS;
43453
43559
  exports.DEFAULT_BRIGHTNESS_SHIFT = DEFAULT_BRIGHTNESS_SHIFT;
43454
43560
  exports.DEFAULT_LIGHT_INTENSITY = DEFAULT_LIGHT_INTENSITY;
43561
+ exports.LIGHTING_SETTINGS_VERSION = LIGHTING_SETTINGS_VERSION;
43562
+ exports.LIGHT_INTENSITY_COMPENSATION = LIGHT_INTENSITY_COMPENSATION;
43563
+ exports.MAX_COMPENSATED_LIGHT_INTENSITY = MAX_COMPENSATED_LIGHT_INTENSITY;
43455
43564
  exports.Draw3dPolygon = Draw3dPolygon;
43456
43565
  exports.Draw3dPolyline = Draw3dPolyline;
43457
43566
  exports.WidgetControlViewBarSearch = WidgetControlViewBarSearch;