CumulusCloud.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. import Cartesian2 from "../Core/Cartesian2.js";
  2. import Cartesian3 from "../Core/Cartesian3.js";
  3. import Check from "../Core/Check.js";
  4. import Color from "../Core/Color.js";
  5. import defaultValue from "../Core/defaultValue.js";
  6. import defined from "../Core/defined.js";
  7. /**
  8. * A cumulus cloud billboard positioned in the 3D scene, that is created and rendered using a {@link CloudCollection}.
  9. * A cloud is created and its initial properties are set by calling {@link CloudCollection#add}.
  10. * and {@link CloudCollection#remove}.
  11. * <br /><br />
  12. * <div align='center'>
  13. * <img src='Images/CumulusCloud.png' width='400' height='300' /><br />
  14. * Example cumulus clouds
  15. * </div>
  16. * @alias CumulusCloud
  17. *
  18. * @performance Similar to {@link Billboard}, reading a property, e.g., {@link CumulusCloud#show},
  19. * takes constant time. Assigning to a property is constant time but results in
  20. * CPU to GPU traffic when {@link CloudCollection#update} is called. The per-cloud traffic is
  21. * the same regardless of how many properties were updated. If most clouds in a collection need to be
  22. * updated, it may be more efficient to clear the collection with {@link CloudCollection#removeAll}
  23. * and add new clouds instead of modifying each one.
  24. *
  25. * @see CloudCollection
  26. * @see CloudCollection#add
  27. *
  28. * @internalConstructor
  29. * @class
  30. *
  31. * @demo {@link https://sandcastle.cesium.com/index.html?src=Cloud%20Parameters.html|Cesium Sandcastle Cloud Parameters Demo}
  32. */
  33. function CumulusCloud(options, cloudCollection) {
  34. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  35. this._show = defaultValue(options.show, true);
  36. this._position = Cartesian3.clone(
  37. defaultValue(options.position, Cartesian3.ZERO)
  38. );
  39. if (!defined(options.scale) && defined(options.maximumSize)) {
  40. this._maximumSize = Cartesian3.clone(options.maximumSize);
  41. this._scale = new Cartesian2(this._maximumSize.x, this._maximumSize.y);
  42. } else {
  43. this._scale = Cartesian2.clone(
  44. defaultValue(options.scale, new Cartesian2(20.0, 12.0))
  45. );
  46. const defaultMaxSize = new Cartesian3(
  47. this._scale.x,
  48. this._scale.y,
  49. Math.min(this._scale.x, this._scale.y) / 1.5
  50. );
  51. this._maximumSize = Cartesian3.clone(
  52. defaultValue(options.maximumSize, defaultMaxSize)
  53. );
  54. }
  55. this._slice = defaultValue(options.slice, -1.0);
  56. this._color = Color.clone(defaultValue(options.color, Color.WHITE));
  57. this._brightness = defaultValue(options.brightness, 1.0);
  58. this._cloudCollection = cloudCollection;
  59. this._index = -1; // Used by CloudCollection
  60. }
  61. const SHOW_INDEX = (CumulusCloud.SHOW_INDEX = 0);
  62. const POSITION_INDEX = (CumulusCloud.POSITION_INDEX = 1);
  63. const SCALE_INDEX = (CumulusCloud.SCALE_INDEX = 2);
  64. const MAXIMUM_SIZE_INDEX = (CumulusCloud.MAXIMUM_SIZE_INDEX = 3);
  65. const SLICE_INDEX = (CumulusCloud.SLICE_INDEX = 4);
  66. const BRIGHTNESS_INDEX = (CumulusCloud.BRIGHTNESS_INDEX = 5);
  67. const COLOR_INDEX = (CumulusCloud.COLOR_INDEX = 6);
  68. CumulusCloud.NUMBER_OF_PROPERTIES = 7;
  69. function makeDirty(cloud, propertyChanged) {
  70. const cloudCollection = cloud._cloudCollection;
  71. if (defined(cloudCollection)) {
  72. cloudCollection._updateCloud(cloud, propertyChanged);
  73. cloud._dirty = true;
  74. }
  75. }
  76. Object.defineProperties(CumulusCloud.prototype, {
  77. /**
  78. * Determines if this cumulus cloud will be shown. Use this to hide or show a cloud, instead
  79. * of removing it and re-adding it to the collection.
  80. * @memberof CumulusCloud.prototype
  81. * @type {Boolean}
  82. * @default true
  83. */
  84. show: {
  85. get: function () {
  86. return this._show;
  87. },
  88. set: function (value) {
  89. //>>includeStart('debug', pragmas.debug);
  90. Check.typeOf.bool("value", value);
  91. //>>includeEnd('debug');
  92. if (this._show !== value) {
  93. this._show = value;
  94. makeDirty(this, SHOW_INDEX);
  95. }
  96. },
  97. },
  98. /**
  99. * Gets or sets the Cartesian position of this cumulus cloud.
  100. * @memberof CumulusCloud.prototype
  101. * @type {Cartesian3}
  102. */
  103. position: {
  104. get: function () {
  105. return this._position;
  106. },
  107. set: function (value) {
  108. //>>includeStart('debug', pragmas.debug)
  109. Check.typeOf.object("value", value);
  110. //>>includeEnd('debug');
  111. const position = this._position;
  112. if (!Cartesian3.equals(position, value)) {
  113. Cartesian3.clone(value, position);
  114. makeDirty(this, POSITION_INDEX);
  115. }
  116. },
  117. },
  118. /**
  119. * <p>Gets or sets the scale of the cumulus cloud billboard in meters.
  120. * The <code>scale</code> property will affect the size of the billboard,
  121. * but not the cloud's actual appearance.</p>
  122. * <div align='center'>
  123. * <table border='0' cellpadding='5'><tr>
  124. * <td align='center'>
  125. * <code>cloud.scale = new Cesium.Cartesian2(12, 8);</code><br/>
  126. * <img src='Images/CumulusCloud.scalex12y8.png' width='250' height='158' />
  127. * </td>
  128. * <td align='center'>
  129. * <code>cloud.scale = new Cesium.Cartesian2(24, 10);</code><br/>
  130. * <img src='Images/CumulusCloud.scalex24y10.png' width='250' height='158' />
  131. * </td>
  132. * </tr></table>
  133. * </div>
  134. *
  135. * <p>To modify the cloud's appearance, modify its <code>maximumSize</code>
  136. * and <code>slice</code> properties.</p>
  137. * @memberof CumulusCloud.prototype
  138. * @type {Cartesian2}
  139. *
  140. * @see CumulusCloud#maximumSize
  141. * @see CumulusCloud#slice
  142. */
  143. scale: {
  144. get: function () {
  145. return this._scale;
  146. },
  147. set: function (value) {
  148. //>>includeStart('debug', pragmas.debug)
  149. Check.typeOf.object("value", value);
  150. //>>includeEnd('debug');
  151. const scale = this._scale;
  152. if (!Cartesian2.equals(scale, value)) {
  153. Cartesian2.clone(value, scale);
  154. makeDirty(this, SCALE_INDEX);
  155. }
  156. },
  157. },
  158. /**
  159. * <p>Gets or sets the maximum size of the cumulus cloud rendered on the billboard.
  160. * This defines a maximum ellipsoid volume that the cloud can appear in.
  161. * Rather than guaranteeing a specific size, this specifies a boundary for the
  162. * cloud to appear in, and changing it can affect the shape of the cloud.</p>
  163. * <p>Changing the z-value of <code>maximumSize</code> has the most dramatic effect
  164. * on the cloud's appearance because it changes the depth of the cloud, and thus the
  165. * positions at which the cloud-shaping texture is sampled.</p>
  166. * <div align='center'>
  167. * <table border='0' cellpadding='5'>
  168. * <tr>
  169. * <td align='center'>
  170. * <code>cloud.maximumSize = new Cesium.Cartesian3(14, 9, 10);</code><br/>
  171. * <img src='Images/CumulusCloud.maximumSizex14y9z10.png' width='250' height='158' />
  172. * </td>
  173. * <td align='center'>
  174. * <code>cloud.maximumSize.x = 25;</code><br/>
  175. * <img src='Images/CumulusCloud.maximumSizex25.png' width='250' height='158' />
  176. * </td>
  177. * </tr>
  178. * <tr>
  179. * <td align='center'>
  180. * <code>cloud.maximumSize.y = 5;</code><br/>
  181. * <img src='Images/CumulusCloud.maximumSizey5.png' width='250' height='158' />
  182. * </td>
  183. * <td align='center'>
  184. * <code>cloud.maximumSize.z = 17;</code><br/>
  185. * <img src='Images/CumulusCloud.maximumSizez17.png' width='250' height='158' />
  186. * </td>
  187. * </tr>
  188. * </table>
  189. * </div>
  190. *
  191. * <p>To modify the billboard's actual size, modify the cloud's <code>scale</code> property.</p>
  192. * @memberof CumulusCloud.prototype
  193. * @type {Cartesian3}
  194. *
  195. * @see CumulusCloud#scale
  196. */
  197. maximumSize: {
  198. get: function () {
  199. return this._maximumSize;
  200. },
  201. set: function (value) {
  202. //>>includeStart('debug', pragmas.debug)
  203. Check.typeOf.object("value", value);
  204. //>>includeEnd('debug');
  205. const maximumSize = this._maximumSize;
  206. if (!Cartesian3.equals(maximumSize, value)) {
  207. Cartesian3.clone(value, maximumSize);
  208. makeDirty(this, MAXIMUM_SIZE_INDEX);
  209. }
  210. },
  211. },
  212. /**
  213. * Sets the color of the cloud
  214. * @memberof CumulusCloud.prototype
  215. * @type {Color}
  216. * @default Color.WHITE
  217. */
  218. color: {
  219. get: function () {
  220. return this._color;
  221. },
  222. set: function (value) {
  223. //>>includeStart('debug', pragmas.debug)
  224. Check.typeOf.object("value", value);
  225. //>>includeEnd('debug');
  226. const color = this._color;
  227. if (!Color.equals(color, value)) {
  228. Color.clone(value, color);
  229. makeDirty(this, COLOR_INDEX);
  230. }
  231. },
  232. },
  233. /**
  234. * <p>Gets or sets the "slice" of the cloud that is rendered on the billboard, i.e.
  235. * the specific cross-section of the cloud chosen for the billboard's appearance.
  236. * Given a value between 0 and 1, the slice specifies how deeply into the cloud
  237. * to intersect based on its maximum size in the z-direction.</p>
  238. * <div align='center'>
  239. * <table border='0' cellpadding='5'><tr>
  240. * <td align='center'><code>cloud.slice = 0.32;</code><br/><img src='Images/CumulusCloud.slice0.32.png' width='250' height='158' /></td>
  241. * <td align='center'><code>cloud.slice = 0.5;</code><br/><img src='Images/CumulusCloud.slice0.5.png' width='250' height='158' /></td>
  242. * <td align='center'><code>cloud.slice = 0.6;</code><br/><img src='Images/CumulusCloud.slice0.6.png' width='250' height='158' /></td>
  243. * </tr></table>
  244. * </div>
  245. *
  246. * <br />
  247. * <p>Due to the nature in which this slice is calculated,
  248. * values below <code>0.2</code> may result in cross-sections that are too small,
  249. * and the edge of the ellipsoid will be visible. Similarly, values above <code>0.7</code>
  250. * will cause the cloud to appear smaller. Values outside the range <code>[0.1, 0.9]</code>
  251. * should be avoided entirely because they do not produce desirable results.</p>
  252. *
  253. * <div align='center'>
  254. * <table border='0' cellpadding='5'><tr>
  255. * <td align='center'><code>cloud.slice = 0.08;</code><br/><img src='Images/CumulusCloud.slice0.08.png' width='250' height='158' /></td>
  256. * <td align='center'><code>cloud.slice = 0.8;</code><br/><img src='Images/CumulusCloud.slice0.8.png' width='250' height='158' /></td>
  257. * </tr></table>
  258. * </div>
  259. *
  260. * <p>If <code>slice</code> is set to a negative number, the cloud will not render a cross-section.
  261. * Instead, it will render the outside of the ellipsoid that is visible. For clouds with
  262. * small values of `maximumSize.z`, this can produce good-looking results, but for larger
  263. * clouds, this can result in a cloud that is undesirably warped to the ellipsoid volume.</p>
  264. *
  265. * <div align='center'>
  266. * <table border='0' cellpadding='5'><tr>
  267. * <td align='center'>
  268. * <code>cloud.slice = -1.0;<br/>cloud.maximumSize.z = 18;</code><br/>
  269. * <img src='Images/CumulusCloud.slice-1z18.png' width='250' height='158' />
  270. * </td>
  271. * <td align='center'>
  272. * <code>cloud.slice = -1.0;<br/>cloud.maximumSize.z = 30;</code><br/>
  273. * <img src='Images/CumulusCloud.slice-1z30.png' width='250' height='158' /></td>
  274. * </tr></table>
  275. * </div>
  276. *
  277. * @memberof CumulusCloud.prototype
  278. * @type {Number}
  279. * @default -1.0
  280. */
  281. slice: {
  282. get: function () {
  283. return this._slice;
  284. },
  285. set: function (value) {
  286. //>>includeStart('debug', pragmas.debug)
  287. Check.typeOf.number("value", value);
  288. //>>includeEnd('debug');
  289. const slice = this._slice;
  290. if (slice !== value) {
  291. this._slice = value;
  292. makeDirty(this, SLICE_INDEX);
  293. }
  294. },
  295. },
  296. /**
  297. * Gets or sets the brightness of the cloud. This can be used to give clouds
  298. * a darker, grayer appearance.
  299. * <br /><br />
  300. * <div align='center'>
  301. * <table border='0' cellpadding='5'><tr>
  302. * <td align='center'><code>cloud.brightness = 1.0;</code><br/><img src='Images/CumulusCloud.brightness1.png' width='250' height='158' /></td>
  303. * <td align='center'><code>cloud.brightness = 0.6;</code><br/><img src='Images/CumulusCloud.brightness0.6.png' width='250' height='158' /></td>
  304. * <td align='center'><code>cloud.brightness = 0.0;</code><br/><img src='Images/CumulusCloud.brightness0.png' width='250' height='158' /></td>
  305. * </tr></table>
  306. * </div>
  307. * @memberof CumulusCloud.prototype
  308. * @type {Number}
  309. * @default 1.0
  310. */
  311. brightness: {
  312. get: function () {
  313. return this._brightness;
  314. },
  315. set: function (value) {
  316. //>>includeStart('debug', pragmas.debug)
  317. Check.typeOf.number("value", value);
  318. //>>includeEnd('debug');
  319. const brightness = this._brightness;
  320. if (brightness !== value) {
  321. this._brightness = value;
  322. makeDirty(this, BRIGHTNESS_INDEX);
  323. }
  324. },
  325. },
  326. });
  327. CumulusCloud.prototype._destroy = function () {
  328. this._cloudCollection = undefined;
  329. };
  330. export default CumulusCloud;