WallGeometryUpdater.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import Check from '../Core/Check.js';
  2. import Color from '../Core/Color.js';
  3. import ColorGeometryInstanceAttribute from '../Core/ColorGeometryInstanceAttribute.js';
  4. import defined from '../Core/defined.js';
  5. import DeveloperError from '../Core/DeveloperError.js';
  6. import DistanceDisplayConditionGeometryInstanceAttribute from '../Core/DistanceDisplayConditionGeometryInstanceAttribute.js';
  7. import GeometryInstance from '../Core/GeometryInstance.js';
  8. import Iso8601 from '../Core/Iso8601.js';
  9. import ShowGeometryInstanceAttribute from '../Core/ShowGeometryInstanceAttribute.js';
  10. import WallGeometry from '../Core/WallGeometry.js';
  11. import WallOutlineGeometry from '../Core/WallOutlineGeometry.js';
  12. import MaterialAppearance from '../Scene/MaterialAppearance.js';
  13. import PerInstanceColorAppearance from '../Scene/PerInstanceColorAppearance.js';
  14. import ColorMaterialProperty from './ColorMaterialProperty.js';
  15. import DynamicGeometryUpdater from './DynamicGeometryUpdater.js';
  16. import GeometryUpdater from './GeometryUpdater.js';
  17. import Property from './Property.js';
  18. var scratchColor = new Color();
  19. function WallGeometryOptions(entity) {
  20. this.id = entity;
  21. this.vertexFormat = undefined;
  22. this.positions = undefined;
  23. this.minimumHeights = undefined;
  24. this.maximumHeights = undefined;
  25. this.granularity = undefined;
  26. }
  27. /**
  28. * A {@link GeometryUpdater} for walls.
  29. * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.
  30. * @alias WallGeometryUpdater
  31. * @constructor
  32. *
  33. * @param {Entity} entity The entity containing the geometry to be visualized.
  34. * @param {Scene} scene The scene where visualization is taking place.
  35. */
  36. function WallGeometryUpdater(entity, scene) {
  37. GeometryUpdater.call(this, {
  38. entity : entity,
  39. scene : scene,
  40. geometryOptions : new WallGeometryOptions(entity),
  41. geometryPropertyName : 'wall',
  42. observedPropertyNames : ['availability', 'wall']
  43. });
  44. this._onEntityPropertyChanged(entity, 'wall', entity.wall, undefined);
  45. }
  46. if (defined(Object.create)) {
  47. WallGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);
  48. WallGeometryUpdater.prototype.constructor = WallGeometryUpdater;
  49. }
  50. /**
  51. * Creates the geometry instance which represents the fill of the geometry.
  52. *
  53. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  54. * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.
  55. *
  56. * @exception {DeveloperError} This instance does not represent a filled geometry.
  57. */
  58. WallGeometryUpdater.prototype.createFillGeometryInstance = function(time) {
  59. //>>includeStart('debug', pragmas.debug);
  60. Check.defined('time', time);
  61. if (!this._fillEnabled) {
  62. throw new DeveloperError('This instance does not represent a filled geometry.');
  63. }
  64. //>>includeEnd('debug');
  65. var entity = this._entity;
  66. var isAvailable = entity.isAvailable(time);
  67. var attributes;
  68. var color;
  69. var show = new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time));
  70. var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time);
  71. var distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition);
  72. if (this._materialProperty instanceof ColorMaterialProperty) {
  73. var currentColor;
  74. if (defined(this._materialProperty.color) && (this._materialProperty.color.isConstant || isAvailable)) {
  75. currentColor = this._materialProperty.color.getValue(time, scratchColor);
  76. }
  77. if (!defined(currentColor)) {
  78. currentColor = Color.WHITE;
  79. }
  80. color = ColorGeometryInstanceAttribute.fromColor(currentColor);
  81. attributes = {
  82. show : show,
  83. distanceDisplayCondition : distanceDisplayConditionAttribute,
  84. color : color
  85. };
  86. } else {
  87. attributes = {
  88. show : show,
  89. distanceDisplayCondition : distanceDisplayConditionAttribute
  90. };
  91. }
  92. return new GeometryInstance({
  93. id : entity,
  94. geometry : new WallGeometry(this._options),
  95. attributes : attributes
  96. });
  97. };
  98. /**
  99. * Creates the geometry instance which represents the outline of the geometry.
  100. *
  101. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  102. * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.
  103. *
  104. * @exception {DeveloperError} This instance does not represent an outlined geometry.
  105. */
  106. WallGeometryUpdater.prototype.createOutlineGeometryInstance = function(time) {
  107. //>>includeStart('debug', pragmas.debug);
  108. Check.defined('time', time);
  109. if (!this._outlineEnabled) {
  110. throw new DeveloperError('This instance does not represent an outlined geometry.');
  111. }
  112. //>>includeEnd('debug');
  113. var entity = this._entity;
  114. var isAvailable = entity.isAvailable(time);
  115. var outlineColor = Property.getValueOrDefault(this._outlineColorProperty, time, Color.BLACK, scratchColor);
  116. var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time);
  117. return new GeometryInstance({
  118. id : entity,
  119. geometry : new WallOutlineGeometry(this._options),
  120. attributes : {
  121. show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)),
  122. color : ColorGeometryInstanceAttribute.fromColor(outlineColor),
  123. distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition)
  124. }
  125. });
  126. };
  127. WallGeometryUpdater.prototype._isHidden = function(entity, wall) {
  128. return !defined(wall.positions) || GeometryUpdater.prototype._isHidden.call(this, entity, wall);
  129. };
  130. WallGeometryUpdater.prototype._getIsClosed = function(options) {
  131. return false;
  132. };
  133. WallGeometryUpdater.prototype._isDynamic = function(entity, wall) {
  134. return !wall.positions.isConstant || //
  135. !Property.isConstant(wall.minimumHeights) || //
  136. !Property.isConstant(wall.maximumHeights) || //
  137. !Property.isConstant(wall.outlineWidth) || //
  138. !Property.isConstant(wall.granularity);
  139. };
  140. WallGeometryUpdater.prototype._setStaticOptions = function(entity, wall) {
  141. var minimumHeights = wall.minimumHeights;
  142. var maximumHeights = wall.maximumHeights;
  143. var granularity = wall.granularity;
  144. var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty;
  145. var options = this._options;
  146. options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
  147. options.positions = wall.positions.getValue(Iso8601.MINIMUM_VALUE, options.positions);
  148. options.minimumHeights = defined(minimumHeights) ? minimumHeights.getValue(Iso8601.MINIMUM_VALUE, options.minimumHeights) : undefined;
  149. options.maximumHeights = defined(maximumHeights) ? maximumHeights.getValue(Iso8601.MINIMUM_VALUE, options.maximumHeights) : undefined;
  150. options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined;
  151. };
  152. WallGeometryUpdater.DynamicGeometryUpdater = DynamicWallGeometryUpdater;
  153. /**
  154. * @private
  155. */
  156. function DynamicWallGeometryUpdater(geometryUpdater, primitives, groundPrimitives) {
  157. DynamicGeometryUpdater.call(this, geometryUpdater, primitives, groundPrimitives);
  158. }
  159. if (defined(Object.create)) {
  160. DynamicWallGeometryUpdater.prototype = Object.create(DynamicGeometryUpdater.prototype);
  161. DynamicWallGeometryUpdater.prototype.constructor = DynamicWallGeometryUpdater;
  162. }
  163. DynamicWallGeometryUpdater.prototype._isHidden = function(entity, wall, time) {
  164. return !defined(this._options.positions) || DynamicGeometryUpdater.prototype._isHidden.call(this, entity, wall, time);
  165. };
  166. DynamicWallGeometryUpdater.prototype._setOptions = function(entity, wall, time) {
  167. var options = this._options;
  168. options.positions = Property.getValueOrUndefined(wall.positions, time, options.positions);
  169. options.minimumHeights = Property.getValueOrUndefined(wall.minimumHeights, time, options.minimumHeights);
  170. options.maximumHeights = Property.getValueOrUndefined(wall.maximumHeights, time, options.maximumHeights);
  171. options.granularity = Property.getValueOrUndefined(wall.granularity, time);
  172. };
  173. export default WallGeometryUpdater;