PolylineVolumeGeometryUpdater.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 PolylineVolumeGeometry from '../Core/PolylineVolumeGeometry.js';
  10. import PolylineVolumeOutlineGeometry from '../Core/PolylineVolumeOutlineGeometry.js';
  11. import ShowGeometryInstanceAttribute from '../Core/ShowGeometryInstanceAttribute.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 PolylineVolumeGeometryOptions(entity) {
  20. this.id = entity;
  21. this.vertexFormat = undefined;
  22. this.polylinePositions = undefined;
  23. this.shapePositions = undefined;
  24. this.cornerType = undefined;
  25. this.granularity = undefined;
  26. }
  27. /**
  28. * A {@link GeometryUpdater} for polyline volumes.
  29. * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.
  30. * @alias PolylineVolumeGeometryUpdater
  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 PolylineVolumeGeometryUpdater(entity, scene) {
  37. GeometryUpdater.call(this, {
  38. entity : entity,
  39. scene : scene,
  40. geometryOptions : new PolylineVolumeGeometryOptions(entity),
  41. geometryPropertyName : 'polylineVolume',
  42. observedPropertyNames : ['availability', 'polylineVolume']
  43. });
  44. this._onEntityPropertyChanged(entity, 'polylineVolume', entity.polylineVolume, undefined);
  45. }
  46. if (defined(Object.create)) {
  47. PolylineVolumeGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);
  48. PolylineVolumeGeometryUpdater.prototype.constructor = PolylineVolumeGeometryUpdater;
  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. PolylineVolumeGeometryUpdater.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 PolylineVolumeGeometry(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. PolylineVolumeGeometryUpdater.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 PolylineVolumeOutlineGeometry(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. PolylineVolumeGeometryUpdater.prototype._isHidden = function(entity, polylineVolume) {
  128. return !defined(polylineVolume.positions) || !defined(polylineVolume.shape) || GeometryUpdater.prototype._isHidden.call(this, entity, polylineVolume);
  129. };
  130. PolylineVolumeGeometryUpdater.prototype._isDynamic = function(entity, polylineVolume) {
  131. return !polylineVolume.positions.isConstant || //
  132. !polylineVolume.shape.isConstant || //
  133. !Property.isConstant(polylineVolume.granularity) || //
  134. !Property.isConstant(polylineVolume.outlineWidth) || //
  135. !Property.isConstant(polylineVolume.cornerType);
  136. };
  137. PolylineVolumeGeometryUpdater.prototype._setStaticOptions = function(entity, polylineVolume) {
  138. var granularity = polylineVolume.granularity;
  139. var cornerType = polylineVolume.cornerType;
  140. var options = this._options;
  141. var isColorMaterial = this._materialProperty instanceof ColorMaterialProperty;
  142. options.vertexFormat = isColorMaterial ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
  143. options.polylinePositions = polylineVolume.positions.getValue(Iso8601.MINIMUM_VALUE, options.polylinePositions);
  144. options.shapePositions = polylineVolume.shape.getValue(Iso8601.MINIMUM_VALUE, options.shape);
  145. options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined;
  146. options.cornerType = defined(cornerType) ? cornerType.getValue(Iso8601.MINIMUM_VALUE) : undefined;
  147. };
  148. PolylineVolumeGeometryUpdater.DynamicGeometryUpdater = DynamicPolylineVolumeGeometryUpdater;
  149. /**
  150. * @private
  151. */
  152. function DynamicPolylineVolumeGeometryUpdater(geometryUpdater, primitives, groundPrimitives) {
  153. DynamicGeometryUpdater.call(this, geometryUpdater, primitives, groundPrimitives);
  154. }
  155. if (defined(Object.create)) {
  156. DynamicPolylineVolumeGeometryUpdater.prototype = Object.create(DynamicGeometryUpdater.prototype);
  157. DynamicPolylineVolumeGeometryUpdater.prototype.constructor = DynamicPolylineVolumeGeometryUpdater;
  158. }
  159. DynamicPolylineVolumeGeometryUpdater.prototype._isHidden = function(entity, polylineVolume, time) {
  160. var options = this._options;
  161. return !defined(options.polylinePositions) || !defined(options.shapePositions) || DynamicGeometryUpdater.prototype._isHidden.call(this, entity, polylineVolume, time);
  162. };
  163. DynamicPolylineVolumeGeometryUpdater.prototype._setOptions = function(entity, polylineVolume, time) {
  164. var options = this._options;
  165. options.polylinePositions = Property.getValueOrUndefined(polylineVolume.positions, time, options.polylinePositions);
  166. options.shapePositions = Property.getValueOrUndefined(polylineVolume.shape, time);
  167. options.granularity = Property.getValueOrUndefined(polylineVolume.granularity, time);
  168. options.cornerType = Property.getValueOrUndefined(polylineVolume.cornerType, time);
  169. };
  170. export default PolylineVolumeGeometryUpdater;