PolylineVolumeGeometryUpdater.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. const 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(
  45. entity,
  46. "polylineVolume",
  47. entity.polylineVolume,
  48. undefined
  49. );
  50. }
  51. if (defined(Object.create)) {
  52. PolylineVolumeGeometryUpdater.prototype = Object.create(
  53. GeometryUpdater.prototype
  54. );
  55. PolylineVolumeGeometryUpdater.prototype.constructor = PolylineVolumeGeometryUpdater;
  56. }
  57. /**
  58. * Creates the geometry instance which represents the fill of the geometry.
  59. *
  60. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  61. * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.
  62. *
  63. * @exception {DeveloperError} This instance does not represent a filled geometry.
  64. */
  65. PolylineVolumeGeometryUpdater.prototype.createFillGeometryInstance = function (
  66. time
  67. ) {
  68. //>>includeStart('debug', pragmas.debug);
  69. Check.defined("time", time);
  70. if (!this._fillEnabled) {
  71. throw new DeveloperError(
  72. "This instance does not represent a filled geometry."
  73. );
  74. }
  75. //>>includeEnd('debug');
  76. const entity = this._entity;
  77. const isAvailable = entity.isAvailable(time);
  78. let attributes;
  79. let color;
  80. const show = new ShowGeometryInstanceAttribute(
  81. isAvailable &&
  82. entity.isShowing &&
  83. this._showProperty.getValue(time) &&
  84. this._fillProperty.getValue(time)
  85. );
  86. const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(
  87. time
  88. );
  89. const distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
  90. distanceDisplayCondition
  91. );
  92. if (this._materialProperty instanceof ColorMaterialProperty) {
  93. let currentColor;
  94. if (
  95. defined(this._materialProperty.color) &&
  96. (this._materialProperty.color.isConstant || isAvailable)
  97. ) {
  98. currentColor = this._materialProperty.color.getValue(time, scratchColor);
  99. }
  100. if (!defined(currentColor)) {
  101. currentColor = Color.WHITE;
  102. }
  103. color = ColorGeometryInstanceAttribute.fromColor(currentColor);
  104. attributes = {
  105. show: show,
  106. distanceDisplayCondition: distanceDisplayConditionAttribute,
  107. color: color,
  108. };
  109. } else {
  110. attributes = {
  111. show: show,
  112. distanceDisplayCondition: distanceDisplayConditionAttribute,
  113. };
  114. }
  115. return new GeometryInstance({
  116. id: entity,
  117. geometry: new PolylineVolumeGeometry(this._options),
  118. attributes: attributes,
  119. });
  120. };
  121. /**
  122. * Creates the geometry instance which represents the outline of the geometry.
  123. *
  124. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  125. * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.
  126. *
  127. * @exception {DeveloperError} This instance does not represent an outlined geometry.
  128. */
  129. PolylineVolumeGeometryUpdater.prototype.createOutlineGeometryInstance = function (
  130. time
  131. ) {
  132. //>>includeStart('debug', pragmas.debug);
  133. Check.defined("time", time);
  134. if (!this._outlineEnabled) {
  135. throw new DeveloperError(
  136. "This instance does not represent an outlined geometry."
  137. );
  138. }
  139. //>>includeEnd('debug');
  140. const entity = this._entity;
  141. const isAvailable = entity.isAvailable(time);
  142. const outlineColor = Property.getValueOrDefault(
  143. this._outlineColorProperty,
  144. time,
  145. Color.BLACK,
  146. scratchColor
  147. );
  148. const distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(
  149. time
  150. );
  151. return new GeometryInstance({
  152. id: entity,
  153. geometry: new PolylineVolumeOutlineGeometry(this._options),
  154. attributes: {
  155. show: new ShowGeometryInstanceAttribute(
  156. isAvailable &&
  157. entity.isShowing &&
  158. this._showProperty.getValue(time) &&
  159. this._showOutlineProperty.getValue(time)
  160. ),
  161. color: ColorGeometryInstanceAttribute.fromColor(outlineColor),
  162. distanceDisplayCondition: DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(
  163. distanceDisplayCondition
  164. ),
  165. },
  166. });
  167. };
  168. PolylineVolumeGeometryUpdater.prototype._isHidden = function (
  169. entity,
  170. polylineVolume
  171. ) {
  172. return (
  173. !defined(polylineVolume.positions) ||
  174. !defined(polylineVolume.shape) ||
  175. GeometryUpdater.prototype._isHidden.call(this, entity, polylineVolume)
  176. );
  177. };
  178. PolylineVolumeGeometryUpdater.prototype._isDynamic = function (
  179. entity,
  180. polylineVolume
  181. ) {
  182. return (
  183. !polylineVolume.positions.isConstant || //
  184. !polylineVolume.shape.isConstant || //
  185. !Property.isConstant(polylineVolume.granularity) || //
  186. !Property.isConstant(polylineVolume.outlineWidth) || //
  187. !Property.isConstant(polylineVolume.cornerType)
  188. );
  189. };
  190. PolylineVolumeGeometryUpdater.prototype._setStaticOptions = function (
  191. entity,
  192. polylineVolume
  193. ) {
  194. const granularity = polylineVolume.granularity;
  195. const cornerType = polylineVolume.cornerType;
  196. const options = this._options;
  197. const isColorMaterial =
  198. this._materialProperty instanceof ColorMaterialProperty;
  199. options.vertexFormat = isColorMaterial
  200. ? PerInstanceColorAppearance.VERTEX_FORMAT
  201. : MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat;
  202. options.polylinePositions = polylineVolume.positions.getValue(
  203. Iso8601.MINIMUM_VALUE,
  204. options.polylinePositions
  205. );
  206. options.shapePositions = polylineVolume.shape.getValue(
  207. Iso8601.MINIMUM_VALUE,
  208. options.shape
  209. );
  210. options.granularity = defined(granularity)
  211. ? granularity.getValue(Iso8601.MINIMUM_VALUE)
  212. : undefined;
  213. options.cornerType = defined(cornerType)
  214. ? cornerType.getValue(Iso8601.MINIMUM_VALUE)
  215. : undefined;
  216. };
  217. PolylineVolumeGeometryUpdater.DynamicGeometryUpdater = DynamicPolylineVolumeGeometryUpdater;
  218. /**
  219. * @private
  220. */
  221. function DynamicPolylineVolumeGeometryUpdater(
  222. geometryUpdater,
  223. primitives,
  224. groundPrimitives
  225. ) {
  226. DynamicGeometryUpdater.call(
  227. this,
  228. geometryUpdater,
  229. primitives,
  230. groundPrimitives
  231. );
  232. }
  233. if (defined(Object.create)) {
  234. DynamicPolylineVolumeGeometryUpdater.prototype = Object.create(
  235. DynamicGeometryUpdater.prototype
  236. );
  237. DynamicPolylineVolumeGeometryUpdater.prototype.constructor = DynamicPolylineVolumeGeometryUpdater;
  238. }
  239. DynamicPolylineVolumeGeometryUpdater.prototype._isHidden = function (
  240. entity,
  241. polylineVolume,
  242. time
  243. ) {
  244. const options = this._options;
  245. return (
  246. !defined(options.polylinePositions) ||
  247. !defined(options.shapePositions) ||
  248. DynamicGeometryUpdater.prototype._isHidden.call(
  249. this,
  250. entity,
  251. polylineVolume,
  252. time
  253. )
  254. );
  255. };
  256. DynamicPolylineVolumeGeometryUpdater.prototype._setOptions = function (
  257. entity,
  258. polylineVolume,
  259. time
  260. ) {
  261. const options = this._options;
  262. options.polylinePositions = Property.getValueOrUndefined(
  263. polylineVolume.positions,
  264. time,
  265. options.polylinePositions
  266. );
  267. options.shapePositions = Property.getValueOrUndefined(
  268. polylineVolume.shape,
  269. time
  270. );
  271. options.granularity = Property.getValueOrUndefined(
  272. polylineVolume.granularity,
  273. time
  274. );
  275. options.cornerType = Property.getValueOrUndefined(
  276. polylineVolume.cornerType,
  277. time
  278. );
  279. };
  280. export default PolylineVolumeGeometryUpdater;