CylinderGraphics.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. * @memberof CylinderGraphics.prototype
  144. * @type {Property|undefined}
  145. * @default 1.0
  146. */
  147. outlineWidth: createPropertyDescriptor("outlineWidth"),
  148. /**
  149. * Gets or sets the Property specifying the number of vertical lines to draw along the perimeter for the outline.
  150. * @memberof CylinderGraphics.prototype
  151. * @type {Property|undefined}
  152. * @default 16
  153. */
  154. numberOfVerticalLines: createPropertyDescriptor("numberOfVerticalLines"),
  155. /**
  156. * Gets or sets the Property specifying the number of edges around the perimeter of the cylinder.
  157. * @memberof CylinderGraphics.prototype
  158. * @type {Property|undefined}
  159. * @default 128
  160. */
  161. slices: createPropertyDescriptor("slices"),
  162. /**
  163. * Get or sets the enum Property specifying whether the cylinder
  164. * casts or receives shadows from light sources.
  165. * @memberof CylinderGraphics.prototype
  166. * @type {Property|undefined}
  167. * @default ShadowMode.DISABLED
  168. */
  169. shadows: createPropertyDescriptor("shadows"),
  170. /**
  171. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this cylinder will be displayed.
  172. * @memberof CylinderGraphics.prototype
  173. * @type {Property|undefined}
  174. */
  175. distanceDisplayCondition: createPropertyDescriptor(
  176. "distanceDisplayCondition"
  177. ),
  178. });
  179. /**
  180. * Duplicates this instance.
  181. *
  182. * @param {CylinderGraphics} [result] The object onto which to store the result.
  183. * @returns {CylinderGraphics} The modified result parameter or a new instance if one was not provided.
  184. */
  185. CylinderGraphics.prototype.clone = function (result) {
  186. if (!defined(result)) {
  187. return new CylinderGraphics(this);
  188. }
  189. result.show = this.show;
  190. result.length = this.length;
  191. result.topRadius = this.topRadius;
  192. result.bottomRadius = this.bottomRadius;
  193. result.heightReference = this.heightReference;
  194. result.fill = this.fill;
  195. result.material = this.material;
  196. result.outline = this.outline;
  197. result.outlineColor = this.outlineColor;
  198. result.outlineWidth = this.outlineWidth;
  199. result.numberOfVerticalLines = this.numberOfVerticalLines;
  200. result.slices = this.slices;
  201. result.shadows = this.shadows;
  202. result.distanceDisplayCondition = this.distanceDisplayCondition;
  203. return result;
  204. };
  205. /**
  206. * Assigns each unassigned property on this object to the value
  207. * of the same property on the provided source object.
  208. *
  209. * @param {CylinderGraphics} source The object to be merged into this object.
  210. */
  211. CylinderGraphics.prototype.merge = function (source) {
  212. //>>includeStart('debug', pragmas.debug);
  213. if (!defined(source)) {
  214. throw new DeveloperError("source is required.");
  215. }
  216. //>>includeEnd('debug');
  217. this.show = defaultValue(this.show, source.show);
  218. this.length = defaultValue(this.length, source.length);
  219. this.topRadius = defaultValue(this.topRadius, source.topRadius);
  220. this.bottomRadius = defaultValue(this.bottomRadius, source.bottomRadius);
  221. this.heightReference = defaultValue(
  222. this.heightReference,
  223. source.heightReference
  224. );
  225. this.fill = defaultValue(this.fill, source.fill);
  226. this.material = defaultValue(this.material, source.material);
  227. this.outline = defaultValue(this.outline, source.outline);
  228. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  229. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  230. this.numberOfVerticalLines = defaultValue(
  231. this.numberOfVerticalLines,
  232. source.numberOfVerticalLines
  233. );
  234. this.slices = defaultValue(this.slices, source.slices);
  235. this.shadows = defaultValue(this.shadows, source.shadows);
  236. this.distanceDisplayCondition = defaultValue(
  237. this.distanceDisplayCondition,
  238. source.distanceDisplayCondition
  239. );
  240. };
  241. export default CylinderGraphics;