EllipseGeometryUpdater.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. const scratchColor = new Color();
  25. const defaultOffset = Cartesian3.ZERO;
  26. const offsetScratch = new Cartesian3();
  27. const 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(
  63. GroundGeometryUpdater.prototype
  64. );
  65. EllipseGeometryUpdater.prototype.constructor = EllipseGeometryUpdater;
  66. }
  67. /**
  68. * Creates the geometry instance which represents the fill of the geometry.
  69. *
  70. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  71. * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.
  72. *
  73. * @exception {DeveloperError} This instance does not represent a filled geometry.
  74. */
  75. EllipseGeometryUpdater.prototype.createFillGeometryInstance = function (time) {
  76. //>>includeStart('debug', pragmas.debug);
  77. Check.defined("time", time);
  78. if (!this._fillEnabled) {
  79. throw new DeveloperError(
  80. "This instance does not represent a filled geometry."
  81. );
  82. }
  83. //>>includeEnd('debug');
  84. const entity = this._entity;
  85. const isAvailable = entity.isAvailable(time);
  86. const attributes = {
  87. show: new ShowGeometryInstanceAttribute(
  88. isAvailable &&
  89. entity.isShowing &&
  90. this._showProperty.getValue(time) &&
  91. this._fillProperty.getValue(time)
  92. ),
  93. distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
  94. this._distanceDisplayConditionProperty.getValue(time)
  95. ),
  96. offset: undefined,
  97. color: undefined,
  98. };
  99. if (this._materialProperty instanceof ColorMaterialProperty) {
  100. let currentColor;
  101. if (
  102. defined(this._materialProperty.color) &&
  103. (this._materialProperty.color.isConstant || isAvailable)
  104. ) {
  105. currentColor = this._materialProperty.color.getValue(time, scratchColor);
  106. }
  107. if (!defined(currentColor)) {
  108. currentColor = Color.WHITE;
  109. }
  110. attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);
  111. }
  112. if (defined(this._options.offsetAttribute)) {
  113. attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(
  114. Property.getValueOrDefault(
  115. this._terrainOffsetProperty,
  116. time,
  117. defaultOffset,
  118. offsetScratch
  119. )
  120. );
  121. }
  122. return new GeometryInstance({
  123. id: entity,
  124. geometry: new EllipseGeometry(this._options),
  125. attributes: attributes,
  126. });
  127. };
  128. /**
  129. * Creates the geometry instance which represents the outline of the geometry.
  130. *
  131. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  132. * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.
  133. *
  134. * @exception {DeveloperError} This instance does not represent an outlined geometry.
  135. */
  136. EllipseGeometryUpdater.prototype.createOutlineGeometryInstance = function (
  137. time
  138. ) {
  139. //>>includeStart('debug', pragmas.debug);
  140. Check.defined("time", time);
  141. if (!this._outlineEnabled) {
  142. throw new DeveloperError(
  143. "This instance does not represent an outlined geometry."
  144. );
  145. }
  146. //>>includeEnd('debug');
  147. const entity = this._entity;
  148. const isAvailable = entity.isAvailable(time);
  149. const outlineColor = Property.getValueOrDefault(
  150. this._outlineColorProperty,
  151. time,
  152. Color.BLACK,
  153. scratchColor
  154. );
  155. const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(
  156. time
  157. );
  158. const attributes = {
  159. show: new ShowGeometryInstanceAttribute(
  160. isAvailable &&
  161. entity.isShowing &&
  162. this._showProperty.getValue(time) &&
  163. this._showOutlineProperty.getValue(time)
  164. ),
  165. color: ColorGeometryInstanceAttribute.fromColor(outlineColor),
  166. distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
  167. distanceDisplayCondition
  168. ),
  169. offset: undefined,
  170. };
  171. if (defined(this._options.offsetAttribute)) {
  172. attributes.offset = OffsetGeometryInstanceAttribute.fromCartesian3(
  173. Property.getValueOrDefault(
  174. this._terrainOffsetProperty,
  175. time,
  176. defaultOffset,
  177. offsetScratch
  178. )
  179. );
  180. }
  181. return new GeometryInstance({
  182. id: entity,
  183. geometry: new EllipseOutlineGeometry(this._options),
  184. attributes: attributes,
  185. });
  186. };
  187. EllipseGeometryUpdater.prototype._computeCenter = function (time, result) {
  188. return Property.getValueOrUndefined(this._entity.position, time, result);
  189. };
  190. EllipseGeometryUpdater.prototype._isHidden = function (entity, ellipse) {
  191. const position = entity.position;
  192. return (
  193. !defined(position) ||
  194. !defined(ellipse.semiMajorAxis) ||
  195. !defined(ellipse.semiMinorAxis) ||
  196. GeometryUpdater.prototype._isHidden.call(this, entity, ellipse)
  197. );
  198. };
  199. EllipseGeometryUpdater.prototype._isDynamic = function (entity, ellipse) {
  200. return (
  201. !entity.position.isConstant || //
  202. !ellipse.semiMajorAxis.isConstant || //
  203. !ellipse.semiMinorAxis.isConstant || //
  204. !Property.isConstant(ellipse.rotation) || //
  205. !Property.isConstant(ellipse.height) || //
  206. !Property.isConstant(ellipse.extrudedHeight) || //
  207. !Property.isConstant(ellipse.granularity) || //
  208. !Property.isConstant(ellipse.stRotation) || //
  209. !Property.isConstant(ellipse.outlineWidth) || //
  210. !Property.isConstant(ellipse.numberOfVerticalLines) || //
  211. !Property.isConstant(ellipse.zIndex) || //
  212. (this._onTerrain &&
  213. !Property.isConstant(this._materialProperty) &&
  214. !(this._materialProperty instanceof ColorMaterialProperty))
  215. );
  216. };
  217. EllipseGeometryUpdater.prototype._setStaticOptions = function (
  218. entity,
  219. ellipse
  220. ) {
  221. let heightValue = Property.getValueOrUndefined(
  222. ellipse.height,
  223. Iso8601.MINIMUM_VALUE
  224. );
  225. const heightReferenceValue = Property.getValueOrDefault(
  226. ellipse.heightReference,
  227. Iso8601.MINIMUM_VALUE,
  228. HeightReference.NONE
  229. );
  230. let extrudedHeightValue = Property.getValueOrUndefined(
  231. ellipse.extrudedHeight,
  232. Iso8601.MINIMUM_VALUE
  233. );
  234. const extrudedHeightReferenceValue = Property.getValueOrDefault(
  235. ellipse.extrudedHeightReference,
  236. Iso8601.MINIMUM_VALUE,
  237. HeightReference.NONE
  238. );
  239. if (defined(extrudedHeightValue) && !defined(heightValue)) {
  240. heightValue = 0;
  241. }
  242. const options = this._options;
  243. options.vertexFormat =
  244. this._materialProperty instanceof ColorMaterialProperty
  245. ? PerInstanceColorAppearance.VERTEX_FORMAT
  246. : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
  247. options.center = entity.position.getValue(
  248. Iso8601.MINIMUM_VALUE,
  249. options.center
  250. );
  251. options.semiMajorAxis = ellipse.semiMajorAxis.getValue(
  252. Iso8601.MINIMUM_VALUE,
  253. options.semiMajorAxis
  254. );
  255. options.semiMinorAxis = ellipse.semiMinorAxis.getValue(
  256. Iso8601.MINIMUM_VALUE,
  257. options.semiMinorAxis
  258. );
  259. options.rotation = Property.getValueOrUndefined(
  260. ellipse.rotation,
  261. Iso8601.MINIMUM_VALUE
  262. );
  263. options.granularity = Property.getValueOrUndefined(
  264. ellipse.granularity,
  265. Iso8601.MINIMUM_VALUE
  266. );
  267. options.stRotation = Property.getValueOrUndefined(
  268. ellipse.stRotation,
  269. Iso8601.MINIMUM_VALUE
  270. );
  271. options.numberOfVerticalLines = Property.getValueOrUndefined(
  272. ellipse.numberOfVerticalLines,
  273. Iso8601.MINIMUM_VALUE
  274. );
  275. options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(
  276. heightValue,
  277. heightReferenceValue,
  278. extrudedHeightValue,
  279. extrudedHeightReferenceValue
  280. );
  281. options.height = GroundGeometryUpdater.getGeometryHeight(
  282. heightValue,
  283. heightReferenceValue
  284. );
  285. extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(
  286. extrudedHeightValue,
  287. extrudedHeightReferenceValue
  288. );
  289. if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {
  290. extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(
  291. EllipseGeometry.computeRectangle(options, scratchRectangle)
  292. ).minimumTerrainHeight;
  293. }
  294. options.extrudedHeight = extrudedHeightValue;
  295. };
  296. EllipseGeometryUpdater.DynamicGeometryUpdater = DynamicEllipseGeometryUpdater;
  297. /**
  298. * @private
  299. */
  300. function DynamicEllipseGeometryUpdater(
  301. geometryUpdater,
  302. primitives,
  303. groundPrimitives
  304. ) {
  305. DynamicGeometryUpdater.call(
  306. this,
  307. geometryUpdater,
  308. primitives,
  309. groundPrimitives
  310. );
  311. }
  312. if (defined(Object.create)) {
  313. DynamicEllipseGeometryUpdater.prototype = Object.create(
  314. DynamicGeometryUpdater.prototype
  315. );
  316. DynamicEllipseGeometryUpdater.prototype.constructor = DynamicEllipseGeometryUpdater;
  317. }
  318. DynamicEllipseGeometryUpdater.prototype._isHidden = function (
  319. entity,
  320. ellipse,
  321. time
  322. ) {
  323. const options = this._options;
  324. return (
  325. !defined(options.center) ||
  326. !defined(options.semiMajorAxis) ||
  327. !defined(options.semiMinorAxis) ||
  328. DynamicGeometryUpdater.prototype._isHidden.call(this, entity, ellipse, time)
  329. );
  330. };
  331. DynamicEllipseGeometryUpdater.prototype._setOptions = function (
  332. entity,
  333. ellipse,
  334. time
  335. ) {
  336. const options = this._options;
  337. let heightValue = Property.getValueOrUndefined(ellipse.height, time);
  338. const heightReferenceValue = Property.getValueOrDefault(
  339. ellipse.heightReference,
  340. time,
  341. HeightReference.NONE
  342. );
  343. let extrudedHeightValue = Property.getValueOrUndefined(
  344. ellipse.extrudedHeight,
  345. time
  346. );
  347. const extrudedHeightReferenceValue = Property.getValueOrDefault(
  348. ellipse.extrudedHeightReference,
  349. time,
  350. HeightReference.NONE
  351. );
  352. if (defined(extrudedHeightValue) && !defined(heightValue)) {
  353. heightValue = 0;
  354. }
  355. options.center = Property.getValueOrUndefined(
  356. entity.position,
  357. time,
  358. options.center
  359. );
  360. options.semiMajorAxis = Property.getValueOrUndefined(
  361. ellipse.semiMajorAxis,
  362. time
  363. );
  364. options.semiMinorAxis = Property.getValueOrUndefined(
  365. ellipse.semiMinorAxis,
  366. time
  367. );
  368. options.rotation = Property.getValueOrUndefined(ellipse.rotation, time);
  369. options.granularity = Property.getValueOrUndefined(ellipse.granularity, time);
  370. options.stRotation = Property.getValueOrUndefined(ellipse.stRotation, time);
  371. options.numberOfVerticalLines = Property.getValueOrUndefined(
  372. ellipse.numberOfVerticalLines,
  373. time
  374. );
  375. options.offsetAttribute = GroundGeometryUpdater.computeGeometryOffsetAttribute(
  376. heightValue,
  377. heightReferenceValue,
  378. extrudedHeightValue,
  379. extrudedHeightReferenceValue
  380. );
  381. options.height = GroundGeometryUpdater.getGeometryHeight(
  382. heightValue,
  383. heightReferenceValue
  384. );
  385. extrudedHeightValue = GroundGeometryUpdater.getGeometryExtrudedHeight(
  386. extrudedHeightValue,
  387. extrudedHeightReferenceValue
  388. );
  389. if (extrudedHeightValue === GroundGeometryUpdater.CLAMP_TO_GROUND) {
  390. extrudedHeightValue = ApproximateTerrainHeights.getMinimumMaximumHeights(
  391. EllipseGeometry.computeRectangle(options, scratchRectangle)
  392. ).minimumTerrainHeight;
  393. }
  394. options.extrudedHeight = extrudedHeightValue;
  395. };
  396. export default EllipseGeometryUpdater;