CylinderGraphics.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import defaultValue from "../Core/defaultValue.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import Event from "../Core/Event.js";
  5. import createMaterialPropertyDescriptor from "./createMaterialPropertyDescriptor.js";
  6. import createPropertyDescriptor from "./createPropertyDescriptor.js";
  7. /**
  8. * @typedef {Object} CylinderGraphics.ConstructorOptions
  9. *
  10. * Initialization options for the CylinderGraphics constructor
  11. *
  12. * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the cylinder.
  13. * @property {Property | number} [length] A numeric Property specifying the length of the cylinder.
  14. * @property {Property | number} [topRadius] A numeric Property specifying the radius of the top of the cylinder.
  15. * @property {Property | number} [bottomRadius] A numeric Property specifying the radius of the bottom of the cylinder.
  16. * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height from the entity position is relative to.
  17. * @property {Property | boolean} [fill=true] A boolean Property specifying whether the cylinder is filled with the provided material.
  18. * @property {MaterialProperty | Color} [material=Color.WHITE] A Property specifying the material used to fill the cylinder.
  19. * @property {Property | boolean} [outline=false] A boolean Property specifying whether the cylinder is outlined.
  20. * @property {Property | Color} [outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
  21. * @property {Property | number} [outlineWidth=1.0] A numeric Property specifying the width of the outline.
  22. * @property {Property | number} [numberOfVerticalLines=16] A numeric Property specifying the number of vertical lines to draw along the perimeter for the outline.
  23. * @property {Property | number} [slices=128] The number of edges around the perimeter of the cylinder.
  24. * @property {Property | ShadowMode} [shadows=ShadowMode.DISABLED] An enum Property specifying whether the cylinder casts or receives shadows from light sources.
  25. * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this cylinder will be displayed.
  26. */
  27. /**
  28. * Describes a cylinder, truncated cone, or cone defined by a length, top radius, and bottom radius.
  29. * The center position and orientation are determined by the containing {@link Entity}.
  30. *
  31. * @alias CylinderGraphics
  32. * @constructor
  33. *
  34. * @param {CylinderGraphics.ConstructorOptions} [options] Object describing initialization options
  35. */
  36. function CylinderGraphics(options) {
  37. this._definitionChanged = new Event();
  38. this._show = undefined;
  39. this._showSubscription = undefined;
  40. this._length = undefined;
  41. this._lengthSubscription = undefined;
  42. this._topRadius = undefined;
  43. this._topRadiusSubscription = undefined;
  44. this._bottomRadius = undefined;
  45. this._bottomRadiusSubscription = undefined;
  46. this._heightReference = undefined;
  47. this._heightReferenceSubscription = undefined;
  48. this._fill = undefined;
  49. this._fillSubscription = undefined;
  50. this._material = undefined;
  51. this._materialSubscription = undefined;
  52. this._outline = undefined;
  53. this._outlineSubscription = undefined;
  54. this._outlineColor = undefined;
  55. this._outlineColorSubscription = undefined;
  56. this._outlineWidth = undefined;
  57. this._outlineWidthSubscription = undefined;
  58. this._numberOfVerticalLines = undefined;
  59. this._numberOfVerticalLinesSubscription = undefined;
  60. this._slices = undefined;
  61. this._slicesSubscription = undefined;
  62. this._shadows = undefined;
  63. this._shadowsSubscription = undefined;
  64. this._distanceDisplayCondition = undefined;
  65. this._distanceDisplayConditionSubscription = undefined;
  66. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  67. }
  68. Object.defineProperties(CylinderGraphics.prototype, {
  69. /**
  70. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  71. * @memberof CylinderGraphics.prototype
  72. *
  73. * @type {Event}
  74. * @readonly
  75. */
  76. definitionChanged: {
  77. get: function () {
  78. return this._definitionChanged;
  79. },
  80. },
  81. /**
  82. * Gets or sets the boolean Property specifying the visibility of the cylinder.
  83. * @memberof CylinderGraphics.prototype
  84. * @type {Property|undefined}
  85. * @default true
  86. */
  87. show: createPropertyDescriptor("show"),
  88. /**
  89. * Gets or sets the numeric Property specifying the length of the cylinder.
  90. * @memberof CylinderGraphics.prototype
  91. * @type {Property|undefined}
  92. */
  93. length: createPropertyDescriptor("length"),
  94. /**
  95. * Gets or sets the numeric Property specifying the radius of the top of the cylinder.
  96. * @memberof CylinderGraphics.prototype
  97. * @type {Property|undefined}
  98. */
  99. topRadius: createPropertyDescriptor("topRadius"),
  100. /**
  101. * Gets or sets the numeric Property specifying the radius of the bottom of the cylinder.
  102. * @memberof CylinderGraphics.prototype
  103. * @type {Property|undefined}
  104. */
  105. bottomRadius: createPropertyDescriptor("bottomRadius"),
  106. /**
  107. * Gets or sets the Property specifying the {@link HeightReference}.
  108. * @memberof CylinderGraphics.prototype
  109. * @type {Property|undefined}
  110. * @default HeightReference.NONE
  111. */
  112. heightReference: createPropertyDescriptor("heightReference"),
  113. /**
  114. * Gets or sets the boolean Property specifying whether the cylinder is filled with the provided material.
  115. * @memberof CylinderGraphics.prototype
  116. * @type {Property|undefined}
  117. * @default true
  118. */
  119. fill: createPropertyDescriptor("fill"),
  120. /**
  121. * Gets or sets the Property specifying the material used to fill the cylinder.
  122. * @memberof CylinderGraphics.prototype
  123. * @type {MaterialProperty|undefined}
  124. * @default Color.WHITE
  125. */
  126. material: createMaterialPropertyDescriptor("material"),
  127. /**
  128. * Gets or sets the boolean Property specifying whether the cylinder is outlined.
  129. * @memberof CylinderGraphics.prototype
  130. * @type {Property|undefined}
  131. * @default false
  132. */
  133. outline: createPropertyDescriptor("outline"),
  134. /**
  135. * Gets or sets the Property specifying the {@link Color} of the outline.
  136. * @memberof CylinderGraphics.prototype
  137. * @type {Property|undefined}
  138. * @default Color.BLACK
  139. */
  140. outlineColor: createPropertyDescriptor("outlineColor"),
  141. /**
  142. * Gets or sets the numeric Property specifying the width of the outline.
  143. * <p>
  144. * Note: This property will be ignored on all major browsers on Windows platforms. For details, see (@link https://github.com/CesiumGS/cesium/issues/40}.
  145. * </p>
  146. * @memberof CylinderGraphics.prototype
  147. * @type {Property|undefined}
  148. * @default 1.0
  149. */
  150. outlineWidth: createPropertyDescriptor("outlineWidth"),
  151. /**
  152. * Gets or sets the Property specifying the number of vertical lines to draw along the perimeter for the outline.
  153. * @memberof CylinderGraphics.prototype
  154. * @type {Property|undefined}
  155. * @default 16
  156. */
  157. numberOfVerticalLines: createPropertyDescriptor("numberOfVerticalLines"),
  158. /**
  159. * Gets or sets the Property specifying the number of edges around the perimeter of the cylinder.
  160. * @memberof CylinderGraphics.prototype
  161. * @type {Property|undefined}
  162. * @default 128
  163. */
  164. slices: createPropertyDescriptor("slices"),
  165. /**
  166. * Get or sets the enum Property specifying whether the cylinder
  167. * casts or receives shadows from light sources.
  168. * @memberof CylinderGraphics.prototype
  169. * @type {Property|undefined}
  170. * @default ShadowMode.DISABLED
  171. */
  172. shadows: createPropertyDescriptor("shadows"),
  173. /**
  174. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this cylinder will be displayed.
  175. * @memberof CylinderGraphics.prototype
  176. * @type {Property|undefined}
  177. */
  178. distanceDisplayCondition: createPropertyDescriptor(
  179. "distanceDisplayCondition"
  180. ),
  181. });
  182. /**
  183. * Duplicates this instance.
  184. *
  185. * @param {CylinderGraphics} [result] The object onto which to store the result.
  186. * @returns {CylinderGraphics} The modified result parameter or a new instance if one was not provided.
  187. */
  188. CylinderGraphics.prototype.clone = function (result) {
  189. if (!defined(result)) {
  190. return new CylinderGraphics(this);
  191. }
  192. result.show = this.show;
  193. result.length = this.length;
  194. result.topRadius = this.topRadius;
  195. result.bottomRadius = this.bottomRadius;
  196. result.heightReference = this.heightReference;
  197. result.fill = this.fill;
  198. result.material = this.material;
  199. result.outline = this.outline;
  200. result.outlineColor = this.outlineColor;
  201. result.outlineWidth = this.outlineWidth;
  202. result.numberOfVerticalLines = this.numberOfVerticalLines;
  203. result.slices = this.slices;
  204. result.shadows = this.shadows;
  205. result.distanceDisplayCondition = this.distanceDisplayCondition;
  206. return result;
  207. };
  208. /**
  209. * Assigns each unassigned property on this object to the value
  210. * of the same property on the provided source object.
  211. *
  212. * @param {CylinderGraphics} source The object to be merged into this object.
  213. */
  214. CylinderGraphics.prototype.merge = function (source) {
  215. //>>includeStart('debug', pragmas.debug);
  216. if (!defined(source)) {
  217. throw new DeveloperError("source is required.");
  218. }
  219. //>>includeEnd('debug');
  220. this.show = defaultValue(this.show, source.show);
  221. this.length = defaultValue(this.length, source.length);
  222. this.topRadius = defaultValue(this.topRadius, source.topRadius);
  223. this.bottomRadius = defaultValue(this.bottomRadius, source.bottomRadius);
  224. this.heightReference = defaultValue(
  225. this.heightReference,
  226. source.heightReference
  227. );
  228. this.fill = defaultValue(this.fill, source.fill);
  229. this.material = defaultValue(this.material, source.material);
  230. this.outline = defaultValue(this.outline, source.outline);
  231. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  232. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  233. this.numberOfVerticalLines = defaultValue(
  234. this.numberOfVerticalLines,
  235. source.numberOfVerticalLines
  236. );
  237. this.slices = defaultValue(this.slices, source.slices);
  238. this.shadows = defaultValue(this.shadows, source.shadows);
  239. this.distanceDisplayCondition = defaultValue(
  240. this.distanceDisplayCondition,
  241. source.distanceDisplayCondition
  242. );
  243. };
  244. export default CylinderGraphics;