WallGeometryUpdater.js 8.5 KB

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