EllipseGeometryUpdater.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import ApproximateTerrainHeights from '../Core/ApproximateTerrainHeights.js';
  2. import Cartesian3 from '../Core/Cartesian3.js';
  3. import Check from '../Core/Check.js';
  4. import Color from '../Core/Color.js';
  5. import ColorGeometryInstanceAttribute from '../Core/ColorGeometryInstanceAttribute.js';
  6. import defined from '../Core/defined.js';
  7. import DeveloperError from '../Core/DeveloperError.js';
  8. import DistanceDisplayConditionGeometryInstanceAttribute from '../Core/DistanceDisplayConditionGeometryInstanceAttribute.js';
  9. import EllipseGeometry from '../Core/EllipseGeometry.js';
  10. import EllipseOutlineGeometry from '../Core/EllipseOutlineGeometry.js';
  11. import GeometryInstance from '../Core/GeometryInstance.js';
  12. import Iso8601 from '../Core/Iso8601.js';
  13. import OffsetGeometryInstanceAttribute from '../Core/OffsetGeometryInstanceAttribute.js';
  14. import Rectangle from '../Core/Rectangle.js';
  15. import ShowGeometryInstanceAttribute from '../Core/ShowGeometryInstanceAttribute.js';
  16. import HeightReference from '../Scene/HeightReference.js';
  17. import MaterialAppearance from '../Scene/MaterialAppearance.js';
  18. import PerInstanceColorAppearance from '../Scene/PerInstanceColorAppearance.js';
  19. import ColorMaterialProperty from './ColorMaterialProperty.js';
  20. import DynamicGeometryUpdater from './DynamicGeometryUpdater.js';
  21. import GeometryUpdater from './GeometryUpdater.js';
  22. import GroundGeometryUpdater from './GroundGeometryUpdater.js';
  23. import Property from './Property.js';
  24. var scratchColor = new Color();
  25. var defaultOffset = Cartesian3.ZERO;
  26. var offsetScratch = new Cartesian3();
  27. var scratchRectangle = new Rectangle();
  28. function EllipseGeometryOptions(entity) {
  29. this.id = entity;
  30. this.vertexFormat = undefined;
  31. this.center = undefined;
  32. this.semiMajorAxis = undefined;
  33. this.semiMinorAxis = undefined;
  34. this.rotation = undefined;
  35. this.height = undefined;
  36. this.extrudedHeight = undefined;
  37. this.granularity = undefined;
  38. this.stRotation = undefined;
  39. this.numberOfVerticalLines = undefined;
  40. this.offsetAttribute = undefined;
  41. }
  42. /**
  43. * A {@link GeometryUpdater} for ellipses.
  44. * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.
  45. * @alias EllipseGeometryUpdater
  46. * @constructor
  47. *
  48. * @param {Entity} entity The entity containing the geometry to be visualized.
  49. * @param {Scene} scene The scene where visualization is taking place.
  50. */
  51. function EllipseGeometryUpdater(entity, scene) {
  52. GroundGeometryUpdater.call(this, {
  53. entity : entity,
  54. scene : scene,
  55. geometryOptions : new EllipseGeometryOptions(entity),
  56. geometryPropertyName : 'ellipse',
  57. observedPropertyNames : ['availability', 'position', 'ellipse']
  58. });
  59. this._onEntityPropertyChanged(entity, 'ellipse', entity.ellipse, undefined);
  60. }
  61. if (defined(Object.create)) {
  62. EllipseGeometryUpdater.prototype = Object.create(GroundGeometryUpdater.prototype);
  63. EllipseGeometryUpdater.prototype.constructor = EllipseGeometryUpdater;
  64. }
  65. /**
  66. * Creates the geometry instance which represents the fill of the geometry.
  67. *
  68. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  69. * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.
  70. *
  71. * @exception {DeveloperError} This instance does not represent a filled geometry.
  72. */
  73. EllipseGeometryUpdater.prototype.createFillGeometryInstance = function(time) {
  74. //>>includeStart('debug', pragmas.debug);
  75. Check.defined('time', time);
  76. if (!this._fillEnabled) {
  77. throw new DeveloperError('This instance does not represent a filled geometry.');
  78. }
  79. //>>includeEnd('debug');
  80. var entity = this._entity;
  81. var isAvailable = entity.isAvailable(time);
  82. var attributes = {
  83. show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._fillProperty.getValue(time)),
  84. distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(this._distanceDisplayConditionProperty.getValue(time)),
  85. offset : undefined,
  86. color : undefined
  87. };
  88. if (this._materialProperty instanceof ColorMaterialProperty) {
  89. var currentColor;
  90. if (defined(this._materialProperty.color) && (this._materialProperty.color.isConstant || isAvailable)) {
  91. currentColor = this._materialProperty.color.getValue(time, scratchColor);
  92. }
  93. if (!defined(currentColor)) {
  94. currentColor = Color.WHITE;
  95. }
  96. attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);
  97. }
  98. if (defined(this._options.offsetAttribute)) {
  99. attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch));
  100. }
  101. return new GeometryInstance({
  102. id : entity,
  103. geometry : new EllipseGeometry(this._options),
  104. attributes : attributes
  105. });
  106. };
  107. /**
  108. * Creates the geometry instance which represents the outline of the geometry.
  109. *
  110. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  111. * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.
  112. *
  113. * @exception {DeveloperError} This instance does not represent an outlined geometry.
  114. */
  115. EllipseGeometryUpdater.prototype.createOutlineGeometryInstance = function(time) {
  116. //>>includeStart('debug', pragmas.debug);
  117. Check.defined('time', time);
  118. if (!this._outlineEnabled) {
  119. throw new DeveloperError('This instance does not represent an outlined geometry.');
  120. }
  121. //>>includeEnd('debug');
  122. var entity = this._entity;
  123. var isAvailable = entity.isAvailable(time);
  124. var outlineColor = Property.getValueOrDefault(this._outlineColorProperty, time, Color.BLACK, scratchColor);
  125. var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time);
  126. var attributes = {
  127. show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)),
  128. color : ColorGeometryInstanceAttribute.fromColor(outlineColor),
  129. distanceDisplayCondition : DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition),
  130. offset : undefined
  131. };
  132. if (defined(this._options.offsetAttribute)) {
  133. attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(Property.getValueOrDefault(this._terrainOffsetProperty, time, defaultOffset, offsetScratch));
  134. }
  135. return new GeometryInstance({
  136. id : entity,
  137. geometry : new EllipseOutlineGeometry(this._options),
  138. attributes : attributes
  139. });
  140. };
  141. EllipseGeometryUpdater.prototype._computeCenter = function(time, result) {
  142. return Property.getValueOrUndefined(this._entity.position, time, result);
  143. };
  144. EllipseGeometryUpdater.prototype._isHidden = function(entity, ellipse) {
  145. var position = entity.position;
  146. return !defined(position) || !defined(ellipse.semiMajorAxis) || !defined(ellipse.semiMinorAxis) || GeometryUpdater.prototype._isHidden.call(this, entity, ellipse);
  147. };
  148. EllipseGeometryUpdater.prototype._isDynamic = function(entity, ellipse) {
  149. return !entity.position.isConstant || //
  150. !ellipse.semiMajorAxis.isConstant || //
  151. !ellipse.semiMinorAxis.isConstant || //
  152. !Property.isConstant(ellipse.rotation) || //
  153. !Property.isConstant(ellipse.height) || //
  154. !Property.isConstant(ellipse.extrudedHeight) || //
  155. !Property.isConstant(ellipse.granularity) || //
  156. !Property.isConstant(ellipse.stRotation) || //
  157. !Property.isConstant(ellipse.outlineWidth) || //
  158. !Property.isConstant(ellipse.numberOfVerticalLines) || //
  159. !Property.isConstant(ellipse.zIndex) || //
  160. (this._onTerrain && !Property.isConstant(this._materialProperty));
  161. };
  162. EllipseGeometryUpdater.prototype._setStaticOptions = function(entity, ellipse) {
  163. var heightValue = Property.getValueOrUndefined(ellipse.height, Iso8601.MINIMUM_VALUE);
  164. var heightReferenceValue = Property.getValueOrDefault(ellipse.heightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE);
  165. var extrudedHeightValue = Property.getValueOrUndefined(ellipse.extrudedHeight, Iso8601.MINIMUM_VALUE);
  166. var extrudedHeightReferenceValue = Property.getValueOrDefault(ellipse.extrudedHeightReference, Iso8601.MINIMUM_VALUE, HeightReference.NONE);
  167. if (defined(extrudedHeightValue) && !defined(heightValue)) {
  168. heightValue = 0;
  169. }
  170. var options = this._options;
  171. options.vertexFormat = (this._materialProperty instanceof ColorMaterialProperty) ? PerInstanceColorAppearance.VERTEX_FORMAT : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
  172. options.center = entity.position.getValue(Iso8601.MINIMUM_VALUE, options.center);
  173. options.semiMajorAxis = ellipse.semiMajorAxis.getValue(Iso8601.MINIMUM_VALUE, options.semiMajorAxis);
  174. options.semiMinorAxis = ellipse.semiMinorAxis.getValue(Iso8601.MINIMUM_VALUE, options.semiMinorAxis);
  175. options.rotation = Property.getValueOrUndefined(ellipse.rotation, Iso8601.MINIMUM_VALUE);
  176. options.granularity = Property.getValueOrUndefined(ellipse.granularity, Iso8601.MINIMUM_VALUE);
  177. options.stRotation = Property.getValueOrUndefined(ellipse.stRotation, Iso8601.MINIMUM_VALUE);
  178. options.numberOfVerticalLines = Property.getValueOrUndefined(ellipse.numberOfVerticalLines, Iso8601.MINIMUM_VALUE);
  179. options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightValue, heightReferenceValue, extrudedHeightValue, extrudedHeightReferenceValue);
  180. options.height = GroundGeometryUpdater.getGeometryHeight(heightValue, heightReferenceValue);
  181. extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(extrudedHeightValue, extrudedHeightReferenceValue);
  182. if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {
  183. extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(EllipseGeometry.computeRectangle(options, scratchRectangle)).minimumTerrainHeight;
  184. }
  185. options.extrudedHeight = extrudedHeightValue;
  186. };
  187. EllipseGeometryUpdater.DynamicGeometryUpdater = DynamicEllipseGeometryUpdater;
  188. /**
  189. * @private
  190. */
  191. function DynamicEllipseGeometryUpdater(geometryUpdater, primitives, groundPrimitives) {
  192. DynamicGeometryUpdater.call(this, geometryUpdater, primitives, groundPrimitives);
  193. }
  194. if (defined(Object.create)) {
  195. DynamicEllipseGeometryUpdater.prototype = Object.create(DynamicGeometryUpdater.prototype);
  196. DynamicEllipseGeometryUpdater.prototype.constructor = DynamicEllipseGeometryUpdater;
  197. }
  198. DynamicEllipseGeometryUpdater.prototype._isHidden = function(entity, ellipse, time) {
  199. var options = this._options;
  200. return !defined(options.center) || !defined(options.semiMajorAxis) || !defined(options.semiMinorAxis) || DynamicGeometryUpdater.prototype._isHidden.call(this, entity, ellipse, time);
  201. };
  202. DynamicEllipseGeometryUpdater.prototype._setOptions = function(entity, ellipse, time) {
  203. var options = this._options;
  204. var heightValue = Property.getValueOrUndefined(ellipse.height, time);
  205. var heightReferenceValue = Property.getValueOrDefault(ellipse.heightReference, time, HeightReference.NONE);
  206. var extrudedHeightValue = Property.getValueOrUndefined(ellipse.extrudedHeight, time);
  207. var extrudedHeightReferenceValue = Property.getValueOrDefault(ellipse.extrudedHeightReference, time, HeightReference.NONE);
  208. if (defined(extrudedHeightValue) && !defined(heightValue)) {
  209. heightValue = 0;
  210. }
  211. options.center = Property.getValueOrUndefined(entity.position, time, options.center);
  212. options.semiMajorAxis = Property.getValueOrUndefined(ellipse.semiMajorAxis, time);
  213. options.semiMinorAxis = Property.getValueOrUndefined(ellipse.semiMinorAxis, time);
  214. options.rotation = Property.getValueOrUndefined(ellipse.rotation, time);
  215. options.granularity = Property.getValueOrUndefined(ellipse.granularity, time);
  216. options.stRotation = Property.getValueOrUndefined(ellipse.stRotation, time);
  217. options.numberOfVerticalLines = Property.getValueOrUndefined(ellipse.numberOfVerticalLines, time);
  218. options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(heightValue, heightReferenceValue, extrudedHeightValue, extrudedHeightReferenceValue);
  219. options.height = GroundGeometryUpdater.getGeometryHeight(heightValue, heightReferenceValue);
  220. extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(extrudedHeightValue, extrudedHeightReferenceValue);
  221. if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {
  222. extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(EllipseGeometry.computeRectangle(options, scratchRectangle)).minimumTerrainHeight;
  223. }
  224. options.extrudedHeight = extrudedHeightValue;
  225. };
  226. export default EllipseGeometryUpdater;