ShowGeometryInstanceAttribute.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import ComponentDatatype from "./ComponentDatatype.js";
  2. import defaultValue from "./defaultValue.js";
  3. import defined from "./defined.js";
  4. import DeveloperError from "./DeveloperError.js";
  5. /**
  6. * Value and type information for per-instance geometry attribute that determines if the geometry instance will be shown.
  7. *
  8. * @alias ShowGeometryInstanceAttribute
  9. * @constructor
  10. *
  11. * @param {boolean} [show=true] Determines if the geometry instance will be shown.
  12. *
  13. *
  14. * @example
  15. * const instance = new Cesium.GeometryInstance({
  16. * geometry : new Cesium.BoxGeometry({
  17. * vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,
  18. * minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0),
  19. * maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0)
  20. * }),
  21. * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
  22. * Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),
  23. * id : 'box',
  24. * attributes : {
  25. * show : new Cesium.ShowGeometryInstanceAttribute(false)
  26. * }
  27. * });
  28. *
  29. * @see GeometryInstance
  30. * @see GeometryInstanceAttribute
  31. */
  32. function ShowGeometryInstanceAttribute(show) {
  33. show = defaultValue(show, true);
  34. /**
  35. * The values for the attributes stored in a typed array.
  36. *
  37. * @type Uint8Array
  38. *
  39. * @default [1.0]
  40. */
  41. this.value = ShowGeometryInstanceAttribute.toValue(show);
  42. }
  43. Object.defineProperties(ShowGeometryInstanceAttribute.prototype, {
  44. /**
  45. * The datatype of each component in the attribute, e.g., individual elements in
  46. * {@link ColorGeometryInstanceAttribute#value}.
  47. *
  48. * @memberof ShowGeometryInstanceAttribute.prototype
  49. *
  50. * @type {ComponentDatatype}
  51. * @readonly
  52. *
  53. * @default {@link ComponentDatatype.UNSIGNED_BYTE}
  54. */
  55. componentDatatype: {
  56. get: function () {
  57. return ComponentDatatype.UNSIGNED_BYTE;
  58. },
  59. },
  60. /**
  61. * The number of components in the attributes, i.e., {@link ColorGeometryInstanceAttribute#value}.
  62. *
  63. * @memberof ShowGeometryInstanceAttribute.prototype
  64. *
  65. * @type {number}
  66. * @readonly
  67. *
  68. * @default 1
  69. */
  70. componentsPerAttribute: {
  71. get: function () {
  72. return 1;
  73. },
  74. },
  75. /**
  76. * When <code>true</code> and <code>componentDatatype</code> is an integer format,
  77. * indicate that the components should be mapped to the range [0, 1] (unsigned)
  78. * or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  79. *
  80. * @memberof ShowGeometryInstanceAttribute.prototype
  81. *
  82. * @type {boolean}
  83. * @readonly
  84. *
  85. * @default true
  86. */
  87. normalize: {
  88. get: function () {
  89. return false;
  90. },
  91. },
  92. });
  93. /**
  94. * Converts a boolean show to a typed array that can be used to assign a show attribute.
  95. *
  96. * @param {boolean} show The show value.
  97. * @param {Uint8Array} [result] The array to store the result in, if undefined a new instance will be created.
  98. * @returns {Uint8Array} The modified result parameter or a new instance if result was undefined.
  99. *
  100. * @example
  101. * const attributes = primitive.getGeometryInstanceAttributes('an id');
  102. * attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true, attributes.show);
  103. */
  104. ShowGeometryInstanceAttribute.toValue = function (show, result) {
  105. //>>includeStart('debug', pragmas.debug);
  106. if (!defined(show)) {
  107. throw new DeveloperError("show is required.");
  108. }
  109. //>>includeEnd('debug');
  110. if (!defined(result)) {
  111. return new Uint8Array([show]);
  112. }
  113. result[0] = show;
  114. return result;
  115. };
  116. export default ShowGeometryInstanceAttribute;