EllipsoidGraphics.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. import defaultValue from '../Core/defaultValue.js';
  2. import defined from '../Core/defined.js';
  3. import defineProperties from '../Core/defineProperties.js';
  4. import DeveloperError from '../Core/DeveloperError.js';
  5. import Event from '../Core/Event.js';
  6. import createMaterialPropertyDescriptor from './createMaterialPropertyDescriptor.js';
  7. import createPropertyDescriptor from './createPropertyDescriptor.js';
  8. /**
  9. * Describe an ellipsoid or sphere. The center position and orientation are determined by the containing {@link Entity}.
  10. *
  11. * @alias EllipsoidGraphics
  12. * @constructor
  13. *
  14. * @param {Object} [options] Object with the following properties:
  15. * @param {Property} [options.show=true] A boolean Property specifying the visibility of the ellipsoid.
  16. * @param {Property} [options.radii] A {@link Cartesian3} Property specifying the radii of the ellipsoid.
  17. * @param {Property} [options.innerRadii] A {@link Cartesian3} Property specifying the inner radii of the ellipsoid.
  18. * @param {Property} [options.minimumClock=0.0] A Property specifying the minimum clock angle of the ellipsoid.
  19. * @param {Property} [options.maximumClock=2*PI] A Property specifying the maximum clock angle of the ellipsoid.
  20. * @param {Property} [options.minimumCone=0.0] A Property specifying the minimum cone angle of the ellipsoid.
  21. * @param {Property} [options.maximumCone=PI] A Property specifying the maximum cone angle of the ellipsoid.
  22. * @param {Property} [options.heightReference=HeightReference.NONE] A Property specifying what the height from the entity position is relative to.
  23. * @param {Property} [options.fill=true] A boolean Property specifying whether the ellipsoid is filled with the provided material.
  24. * @param {MaterialProperty} [options.material=Color.WHITE] A Property specifying the material used to fill the ellipsoid.
  25. * @param {Property} [options.outline=false] A boolean Property specifying whether the ellipsoid is outlined.
  26. * @param {Property} [options.outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
  27. * @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline.
  28. * @param {Property} [options.stackPartitions=64] A Property specifying the number of stacks.
  29. * @param {Property} [options.slicePartitions=64] A Property specifying the number of radial slices.
  30. * @param {Property} [options.subdivisions=128] A Property specifying the number of samples per outline ring, determining the granularity of the curvature.
  31. * @param {Property} [options.shadows=ShadowMode.DISABLED] An enum Property specifying whether the ellipsoid casts or receives shadows from each light source.
  32. * @param {Property} [options.distanceDisplayCondition] A Property specifying at what distance from the camera that this ellipsoid will be displayed.
  33. *
  34. * @demo {@link https://sandcastle.cesium.com/index.html?src=Spheres%20and%20Ellipsoids.html|Cesium Sandcastle Spheres and Ellipsoids Demo}
  35. */
  36. function EllipsoidGraphics(options) {
  37. this._definitionChanged = new Event();
  38. this._show = undefined;
  39. this._showSubscription = undefined;
  40. this._radii = undefined;
  41. this._radiiSubscription = undefined;
  42. this._innerRadii = undefined;
  43. this._innerRadiiSubscription = undefined;
  44. this._minimumClock = undefined;
  45. this._minimumClockSubscription = undefined;
  46. this._maximumClock = undefined;
  47. this._maximumClockSubscription = undefined;
  48. this._minimumCone = undefined;
  49. this._minimumConeSubscription = undefined;
  50. this._maximumCone = undefined;
  51. this._maximumConeSubscription = undefined;
  52. this._heightReference = undefined;
  53. this._heightReferenceSubscription = undefined;
  54. this._fill = undefined;
  55. this._fillSubscription = undefined;
  56. this._material = undefined;
  57. this._materialSubscription = undefined;
  58. this._outline = undefined;
  59. this._outlineSubscription = undefined;
  60. this._outlineColor = undefined;
  61. this._outlineColorSubscription = undefined;
  62. this._outlineWidth = undefined;
  63. this._outlineWidthSubscription = undefined;
  64. this._stackPartitions = undefined;
  65. this._stackPartitionsSubscription = undefined;
  66. this._slicePartitions = undefined;
  67. this._slicePartitionsSubscription = undefined;
  68. this._subdivisions = undefined;
  69. this._subdivisionsSubscription = undefined;
  70. this._shadows = undefined;
  71. this._shadowsSubscription = undefined;
  72. this._distanceDisplayCondition = undefined;
  73. this._distanceDisplayConditionSubscription = undefined;
  74. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  75. }
  76. defineProperties(EllipsoidGraphics.prototype, {
  77. /**
  78. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  79. * @memberof EllipsoidGraphics.prototype
  80. *
  81. * @type {Event}
  82. * @readonly
  83. */
  84. definitionChanged : {
  85. get : function() {
  86. return this._definitionChanged;
  87. }
  88. },
  89. /**
  90. * Gets or sets the boolean Property specifying the visibility of the ellipsoid.
  91. * @memberof EllipsoidGraphics.prototype
  92. * @type {Property}
  93. * @default true
  94. */
  95. show : createPropertyDescriptor('show'),
  96. /**
  97. * Gets or sets the {@link Cartesian3} {@link Property} specifying the radii of the ellipsoid.
  98. * @memberof EllipsoidGraphics.prototype
  99. * @type {Property}
  100. */
  101. radii : createPropertyDescriptor('radii'),
  102. /**
  103. * Gets or sets the {@link Cartesian3} {@link Property} specifying the inner radii of the ellipsoid.
  104. * @memberof EllipsoidGraphics.prototype
  105. * @type {Property}
  106. * @default radii
  107. */
  108. innerRadii : createPropertyDescriptor('innerRadii'),
  109. /**
  110. * Gets or sets the Property specifying the minimum clock angle of the ellipsoid.
  111. * @memberof EllipsoidGraphics.prototype
  112. * @type {Property}
  113. * @default 0.0
  114. */
  115. minimumClock : createPropertyDescriptor('minimumClock'),
  116. /**
  117. * Gets or sets the Property specifying the maximum clock angle of the ellipsoid.
  118. * @memberof EllipsoidGraphics.prototype
  119. * @type {Property}
  120. * @default 2*PI
  121. */
  122. maximumClock : createPropertyDescriptor('maximumClock'),
  123. /**
  124. * Gets or sets the Property specifying the minimum cone angle of the ellipsoid.
  125. * @memberof EllipsoidGraphics.prototype
  126. * @type {Property}
  127. * @default 0.0
  128. */
  129. minimumCone : createPropertyDescriptor('minimumCone'),
  130. /**
  131. * Gets or sets the Property specifying the maximum cone angle of the ellipsoid.
  132. * @memberof EllipsoidGraphics.prototype
  133. * @type {Property}
  134. * @default PI
  135. */
  136. maximumCone : createPropertyDescriptor('maximumCone'),
  137. /**
  138. * Gets or sets the Property specifying the {@link HeightReference}.
  139. * @memberof EllipsoidGraphics.prototype
  140. * @type {Property}
  141. * @default HeightReference.NONE
  142. */
  143. heightReference : createPropertyDescriptor('heightReference'),
  144. /**
  145. * Gets or sets the boolean Property specifying whether the ellipsoid is filled with the provided material.
  146. * @memberof EllipsoidGraphics.prototype
  147. * @type {Property}
  148. * @default true
  149. */
  150. fill : createPropertyDescriptor('fill'),
  151. /**
  152. * Gets or sets the Property specifying the material used to fill the ellipsoid.
  153. * @memberof EllipsoidGraphics.prototype
  154. * @type {MaterialProperty}
  155. * @default Color.WHITE
  156. */
  157. material : createMaterialPropertyDescriptor('material'),
  158. /**
  159. * Gets or sets the Property specifying whether the ellipsoid is outlined.
  160. * @memberof EllipsoidGraphics.prototype
  161. * @type {Property}
  162. * @default false
  163. */
  164. outline : createPropertyDescriptor('outline'),
  165. /**
  166. * Gets or sets the Property specifying the {@link Color} of the outline.
  167. * @memberof EllipsoidGraphics.prototype
  168. * @type {Property}
  169. * @default Color.BLACK
  170. */
  171. outlineColor : createPropertyDescriptor('outlineColor'),
  172. /**
  173. * Gets or sets the numeric Property specifying the width of the outline.
  174. * @memberof EllipsoidGraphics.prototype
  175. * @type {Property}
  176. * @default 1.0
  177. */
  178. outlineWidth : createPropertyDescriptor('outlineWidth'),
  179. /**
  180. * Gets or sets the Property specifying the number of stacks.
  181. * @memberof EllipsoidGraphics.prototype
  182. * @type {Property}
  183. * @default 64
  184. */
  185. stackPartitions : createPropertyDescriptor('stackPartitions'),
  186. /**
  187. * Gets or sets the Property specifying the number of radial slices per 360 degrees.
  188. * @memberof EllipsoidGraphics.prototype
  189. * @type {Property}
  190. * @default 64
  191. */
  192. slicePartitions : createPropertyDescriptor('slicePartitions'),
  193. /**
  194. * Gets or sets the Property specifying the number of samples per outline ring, determining the granularity of the curvature.
  195. * @memberof EllipsoidGraphics.prototype
  196. * @type {Property}
  197. * @default 128
  198. */
  199. subdivisions : createPropertyDescriptor('subdivisions'),
  200. /**
  201. * Get or sets the enum Property specifying whether the ellipsoid
  202. * casts or receives shadows from each light source.
  203. * @memberof EllipsoidGraphics.prototype
  204. * @type {Property}
  205. * @default ShadowMode.DISABLED
  206. */
  207. shadows : createPropertyDescriptor('shadows'),
  208. /**
  209. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this ellipsoid will be displayed.
  210. * @memberof EllipsoidGraphics.prototype
  211. * @type {Property}
  212. */
  213. distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition')
  214. });
  215. /**
  216. * Duplicates this instance.
  217. *
  218. * @param {EllipsoidGraphics} [result] The object onto which to store the result.
  219. * @returns {EllipsoidGraphics} The modified result parameter or a new instance if one was not provided.
  220. */
  221. EllipsoidGraphics.prototype.clone = function(result) {
  222. if (!defined(result)) {
  223. return new EllipsoidGraphics(this);
  224. }
  225. result.show = this.show;
  226. result.radii = this.radii;
  227. result.innerRadii = this.innerRadii;
  228. result.minimumClock = this.minimumClock;
  229. result.maximumClock = this.maximumClock;
  230. result.minimumCone = this.minimumCone;
  231. result.maximumCone = this.maximumCone;
  232. result.heightReference = this.heightReference;
  233. result.fill = this.fill;
  234. result.material = this.material;
  235. result.outline = this.outline;
  236. result.outlineColor = this.outlineColor;
  237. result.outlineWidth = this.outlineWidth;
  238. result.stackPartitions = this.stackPartitions;
  239. result.slicePartitions = this.slicePartitions;
  240. result.subdivisions = this.subdivisions;
  241. result.shadows = this.shadows;
  242. result.distanceDisplayCondition = this.distanceDisplayCondition;
  243. return result;
  244. };
  245. /**
  246. * Assigns each unassigned property on this object to the value
  247. * of the same property on the provided source object.
  248. *
  249. * @param {EllipsoidGraphics} source The object to be merged into this object.
  250. */
  251. EllipsoidGraphics.prototype.merge = function(source) {
  252. //>>includeStart('debug', pragmas.debug);
  253. if (!defined(source)) {
  254. throw new DeveloperError('source is required.');
  255. }
  256. //>>includeEnd('debug');
  257. this.show = defaultValue(this.show, source.show);
  258. this.radii = defaultValue(this.radii, source.radii);
  259. this.innerRadii = defaultValue(this.innerRadii, source.innerRadii);
  260. this.minimumClock = defaultValue(this.minimumClock, source.minimumClock);
  261. this.maximumClock = defaultValue(this.maximumClock, source.maximumClock);
  262. this.minimumCone = defaultValue(this.minimumCone, source.minimumCone);
  263. this.maximumCone = defaultValue(this.maximumCone, source.maximumCone);
  264. this.heightReference = defaultValue(this.heightReference, source.heightReference);
  265. this.fill = defaultValue(this.fill, source.fill);
  266. this.material = defaultValue(this.material, source.material);
  267. this.outline = defaultValue(this.outline, source.outline);
  268. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  269. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  270. this.stackPartitions = defaultValue(this.stackPartitions, source.stackPartitions);
  271. this.slicePartitions = defaultValue(this.slicePartitions, source.slicePartitions);
  272. this.subdivisions = defaultValue(this.subdivisions, source.subdivisions);
  273. this.shadows = defaultValue(this.shadows, source.shadows);
  274. this.distanceDisplayCondition = defaultValue(this.distanceDisplayCondition, source.distanceDisplayCondition);
  275. };
  276. export default EllipsoidGraphics;