CylinderGraphics.js 11 KB

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