| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 | import Check from "../Core/Check.js";import Color from "../Core/Color.js";import defaultValue from "../Core/defaultValue.js";import defined from "../Core/defined.js";import destroyObject from "../Core/destroyObject.js";import DeveloperError from "../Core/DeveloperError.js";import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js";import Event from "../Core/Event.js";import Iso8601 from "../Core/Iso8601.js";import oneTimeWarning from "../Core/oneTimeWarning.js";import ClassificationType from "../Scene/ClassificationType.js";import ShadowMode from "../Scene/ShadowMode.js";import ColorMaterialProperty from "./ColorMaterialProperty.js";import ConstantProperty from "./ConstantProperty.js";import Entity from "./Entity.js";import Property from "./Property.js";const defaultMaterial = new ColorMaterialProperty(Color.WHITE);const defaultShow = new ConstantProperty(true);const defaultFill = new ConstantProperty(true);const defaultOutline = new ConstantProperty(false);const defaultOutlineColor = new ConstantProperty(Color.BLACK);const defaultShadows = new ConstantProperty(ShadowMode.DISABLED);const defaultDistanceDisplayCondition = new ConstantProperty(  new DistanceDisplayCondition());const defaultClassificationType = new ConstantProperty(ClassificationType.BOTH);/** * An abstract class for updating geometry entities. * @alias GeometryUpdater * @constructor * * @param {Object} options An object with the following properties: * @param {Entity} options.entity The entity containing the geometry to be visualized. * @param {Scene} options.scene The scene where visualization is taking place. * @param {Object} options.geometryOptions Options for the geometry * @param {String} options.geometryPropertyName The geometry property name * @param {String[]} options.observedPropertyNames The entity properties this geometry cares about */function GeometryUpdater(options) {  //>>includeStart('debug', pragmas.debug);  Check.defined("options.entity", options.entity);  Check.defined("options.scene", options.scene);  Check.defined("options.geometryOptions", options.geometryOptions);  Check.defined("options.geometryPropertyName", options.geometryPropertyName);  Check.defined("options.observedPropertyNames", options.observedPropertyNames);  //>>includeEnd('debug');  const entity = options.entity;  const geometryPropertyName = options.geometryPropertyName;  this._entity = entity;  this._scene = options.scene;  this._fillEnabled = false;  this._isClosed = false;  this._onTerrain = false;  this._dynamic = false;  this._outlineEnabled = false;  this._geometryChanged = new Event();  this._showProperty = undefined;  this._materialProperty = undefined;  this._showOutlineProperty = undefined;  this._outlineColorProperty = undefined;  this._outlineWidth = 1.0;  this._shadowsProperty = undefined;  this._distanceDisplayConditionProperty = undefined;  this._classificationTypeProperty = undefined;  this._options = options.geometryOptions;  this._geometryPropertyName = geometryPropertyName;  this._id = `${geometryPropertyName}-${entity.id}`;  this._observedPropertyNames = options.observedPropertyNames;  this._supportsMaterialsforEntitiesOnTerrain = Entity.supportsMaterialsforEntitiesOnTerrain(    options.scene  );}Object.defineProperties(GeometryUpdater.prototype, {  /**   * Gets the unique ID associated with this updater   * @memberof GeometryUpdater.prototype   * @type {String}   * @readonly   */  id: {    get: function () {      return this._id;    },  },  /**   * Gets the entity associated with this geometry.   * @memberof GeometryUpdater.prototype   *   * @type {Entity}   * @readonly   */  entity: {    get: function () {      return this._entity;    },  },  /**   * Gets a value indicating if the geometry has a fill component.   * @memberof GeometryUpdater.prototype   *   * @type {Boolean}   * @readonly   */  fillEnabled: {    get: function () {      return this._fillEnabled;    },  },  /**   * Gets a value indicating if fill visibility varies with simulation time.   * @memberof GeometryUpdater.prototype   *   * @type {Boolean}   * @readonly   */  hasConstantFill: {    get: function () {      return (        !this._fillEnabled ||        (!defined(this._entity.availability) &&          Property.isConstant(this._showProperty) &&          Property.isConstant(this._fillProperty))      );    },  },  /**   * Gets the material property used to fill the geometry.   * @memberof GeometryUpdater.prototype   *   * @type {MaterialProperty}   * @readonly   */  fillMaterialProperty: {    get: function () {      return this._materialProperty;    },  },  /**   * Gets a value indicating if the geometry has an outline component.   * @memberof GeometryUpdater.prototype   *   * @type {Boolean}   * @readonly   */  outlineEnabled: {    get: function () {      return this._outlineEnabled;    },  },  /**   * Gets a value indicating if the geometry has an outline component.   * @memberof GeometryUpdater.prototype   *   * @type {Boolean}   * @readonly   */  hasConstantOutline: {    get: function () {      return (        !this._outlineEnabled ||        (!defined(this._entity.availability) &&          Property.isConstant(this._showProperty) &&          Property.isConstant(this._showOutlineProperty))      );    },  },  /**   * Gets the {@link Color} property for the geometry outline.   * @memberof GeometryUpdater.prototype   *   * @type {Property}   * @readonly   */  outlineColorProperty: {    get: function () {      return this._outlineColorProperty;    },  },  /**   * Gets the constant with of the geometry outline, in pixels.   * This value is only valid if isDynamic is false.   * @memberof GeometryUpdater.prototype   *   * @type {Number}   * @readonly   */  outlineWidth: {    get: function () {      return this._outlineWidth;    },  },  /**   * Gets the property specifying whether the geometry   * casts or receives shadows from light sources.   * @memberof GeometryUpdater.prototype   *   * @type {Property}   * @readonly   */  shadowsProperty: {    get: function () {      return this._shadowsProperty;    },  },  /**   * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this geometry will be displayed.   * @memberof GeometryUpdater.prototype   *   * @type {Property}   * @readonly   */  distanceDisplayConditionProperty: {    get: function () {      return this._distanceDisplayConditionProperty;    },  },  /**   * Gets or sets the {@link ClassificationType} Property specifying if this geometry will classify terrain, 3D Tiles, or both when on the ground.   * @memberof GeometryUpdater.prototype   *   * @type {Property}   * @readonly   */  classificationTypeProperty: {    get: function () {      return this._classificationTypeProperty;    },  },  /**   * Gets a value indicating if the geometry is time-varying.   * If true, all visualization is delegated to a DynamicGeometryUpdater   * returned by GeometryUpdater#createDynamicUpdater.   * @memberof GeometryUpdater.prototype   *   * @type {Boolean}   * @readonly   */  isDynamic: {    get: function () {      return this._dynamic;    },  },  /**   * Gets a value indicating if the geometry is closed.   * This property is only valid for static geometry.   * @memberof GeometryUpdater.prototype   *   * @type {Boolean}   * @readonly   */  isClosed: {    get: function () {      return this._isClosed;    },  },  /**   * Gets a value indicating if the geometry should be drawn on terrain.   * @memberof EllipseGeometryUpdater.prototype   *   * @type {Boolean}   * @readonly   */  onTerrain: {    get: function () {      return this._onTerrain;    },  },  /**   * Gets an event that is raised whenever the public properties   * of this updater change.   * @memberof GeometryUpdater.prototype   *   * @type {Boolean}   * @readonly   */  geometryChanged: {    get: function () {      return this._geometryChanged;    },  },});/** * Checks if the geometry is outlined at the provided time. * * @param {JulianDate} time The time for which to retrieve visibility. * @returns {Boolean} true if geometry is outlined at the provided time, false otherwise. */GeometryUpdater.prototype.isOutlineVisible = function (time) {  const entity = this._entity;  const visible =    this._outlineEnabled &&    entity.isAvailable(time) &&    this._showProperty.getValue(time) &&    this._showOutlineProperty.getValue(time);  return defaultValue(visible, false);};/** * Checks if the geometry is filled at the provided time. * * @param {JulianDate} time The time for which to retrieve visibility. * @returns {Boolean} true if geometry is filled at the provided time, false otherwise. */GeometryUpdater.prototype.isFilled = function (time) {  const entity = this._entity;  const visible =    this._fillEnabled &&    entity.isAvailable(time) &&    this._showProperty.getValue(time) &&    this._fillProperty.getValue(time);  return defaultValue(visible, false);};/** * Creates the geometry instance which represents the fill of the geometry. * * @function * @param {JulianDate} time The time to use when retrieving initial attribute values. * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry. * * @exception {DeveloperError} This instance does not represent a filled geometry. */GeometryUpdater.prototype.createFillGeometryInstance =  DeveloperError.throwInstantiationError;/** * Creates the geometry instance which represents the outline of the geometry. * * @function * @param {JulianDate} time The time to use when retrieving initial attribute values. * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry. * * @exception {DeveloperError} This instance does not represent an outlined geometry. */GeometryUpdater.prototype.createOutlineGeometryInstance =  DeveloperError.throwInstantiationError;/** * Returns true if this object was destroyed; otherwise, false. * * @returns {Boolean} True if this object was destroyed; otherwise, false. */GeometryUpdater.prototype.isDestroyed = function () {  return false;};/** * Destroys and resources used by the object.  Once an object is destroyed, it should not be used. * * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called. */GeometryUpdater.prototype.destroy = function () {  destroyObject(this);};/** * @param {Entity} entity * @param {Object} geometry * @private */GeometryUpdater.prototype._isHidden = function (entity, geometry) {  const show = geometry.show;  return (    defined(show) && show.isConstant && !show.getValue(Iso8601.MINIMUM_VALUE)  );};/** * @param {Entity} entity * @param {Object} geometry * @private */GeometryUpdater.prototype._isOnTerrain = function (entity, geometry) {  return false;};/** * @param {GeometryOptions} options * @private */GeometryUpdater.prototype._getIsClosed = function (options) {  return true;};/** * @param {Entity} entity * @param {Object} geometry * @private */GeometryUpdater.prototype._isDynamic = DeveloperError.throwInstantiationError;/** * @param {Entity} entity * @param {Object} geometry * @private */GeometryUpdater.prototype._setStaticOptions =  DeveloperError.throwInstantiationError;/** * @param {Entity} entity * @param {String} propertyName * @param {*} newValue * @param {*} oldValue * @private */GeometryUpdater.prototype._onEntityPropertyChanged = function (  entity,  propertyName,  newValue,  oldValue) {  if (this._observedPropertyNames.indexOf(propertyName) === -1) {    return;  }  const geometry = this._entity[this._geometryPropertyName];  if (!defined(geometry)) {    if (this._fillEnabled || this._outlineEnabled) {      this._fillEnabled = false;      this._outlineEnabled = false;      this._geometryChanged.raiseEvent(this);    }    return;  }  const fillProperty = geometry.fill;  const fillEnabled =    defined(fillProperty) && fillProperty.isConstant      ? fillProperty.getValue(Iso8601.MINIMUM_VALUE)      : true;  const outlineProperty = geometry.outline;  let outlineEnabled = defined(outlineProperty);  if (outlineEnabled && outlineProperty.isConstant) {    outlineEnabled = outlineProperty.getValue(Iso8601.MINIMUM_VALUE);  }  if (!fillEnabled && !outlineEnabled) {    if (this._fillEnabled || this._outlineEnabled) {      this._fillEnabled = false;      this._outlineEnabled = false;      this._geometryChanged.raiseEvent(this);    }    return;  }  const show = geometry.show;  if (this._isHidden(entity, geometry)) {    if (this._fillEnabled || this._outlineEnabled) {      this._fillEnabled = false;      this._outlineEnabled = false;      this._geometryChanged.raiseEvent(this);    }    return;  }  this._materialProperty = defaultValue(geometry.material, defaultMaterial);  this._fillProperty = defaultValue(fillProperty, defaultFill);  this._showProperty = defaultValue(show, defaultShow);  this._showOutlineProperty = defaultValue(geometry.outline, defaultOutline);  this._outlineColorProperty = outlineEnabled    ? defaultValue(geometry.outlineColor, defaultOutlineColor)    : undefined;  this._shadowsProperty = defaultValue(geometry.shadows, defaultShadows);  this._distanceDisplayConditionProperty = defaultValue(    geometry.distanceDisplayCondition,    defaultDistanceDisplayCondition  );  this._classificationTypeProperty = defaultValue(    geometry.classificationType,    defaultClassificationType  );  this._fillEnabled = fillEnabled;  const onTerrain =    this._isOnTerrain(entity, geometry) &&    (this._supportsMaterialsforEntitiesOnTerrain ||      this._materialProperty instanceof ColorMaterialProperty);  if (outlineEnabled && onTerrain) {    oneTimeWarning(oneTimeWarning.geometryOutlines);    outlineEnabled = false;  }  this._onTerrain = onTerrain;  this._outlineEnabled = outlineEnabled;  if (this._isDynamic(entity, geometry)) {    if (!this._dynamic) {      this._dynamic = true;      this._geometryChanged.raiseEvent(this);    }  } else {    this._setStaticOptions(entity, geometry);    this._isClosed = this._getIsClosed(this._options);    const outlineWidth = geometry.outlineWidth;    this._outlineWidth = defined(outlineWidth)      ? outlineWidth.getValue(Iso8601.MINIMUM_VALUE)      : 1.0;    this._dynamic = false;    this._geometryChanged.raiseEvent(this);  }};/** * Creates the dynamic updater to be used when GeometryUpdater#isDynamic is true. * * @param {PrimitiveCollection} primitives The primitive collection to use. * @param {PrimitiveCollection} [groundPrimitives] The primitive collection to use for ground primitives. * * @returns {DynamicGeometryUpdater} The dynamic updater used to update the geometry each frame. * * @exception {DeveloperError} This instance does not represent dynamic geometry. * @private */GeometryUpdater.prototype.createDynamicUpdater = function (  primitives,  groundPrimitives) {  //>>includeStart('debug', pragmas.debug);  Check.defined("primitives", primitives);  Check.defined("groundPrimitives", groundPrimitives);  if (!this._dynamic) {    throw new DeveloperError(      "This instance does not represent dynamic geometry."    );  }  //>>includeEnd('debug');  return new this.constructor.DynamicGeometryUpdater(    this,    primitives,    groundPrimitives  );};export default GeometryUpdater;
 |