GeometryInstanceAttribute.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import defaultValue from './defaultValue.js';
  2. import defined from './defined.js';
  3. import DeveloperError from './DeveloperError.js';
  4. /**
  5. * Values and type information for per-instance geometry attributes.
  6. *
  7. * @alias GeometryInstanceAttribute
  8. * @constructor
  9. *
  10. * @param {Object} options Object with the following properties:
  11. * @param {ComponentDatatype} options.componentDatatype The datatype of each component in the attribute, e.g., individual elements in values.
  12. * @param {Number} options.componentsPerAttribute A number between 1 and 4 that defines the number of components in an attributes.
  13. * @param {Boolean} [options.normalize=false] When <code>true</code> and <code>componentDatatype</code> is an integer format, indicate that the components should be mapped to the range [0, 1] (unsigned) or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  14. * @param {Number[]} options.value The value for the attribute.
  15. *
  16. * @exception {DeveloperError} options.componentsPerAttribute must be between 1 and 4.
  17. *
  18. *
  19. * @example
  20. * var instance = new Cesium.GeometryInstance({
  21. * geometry : Cesium.BoxGeometry.fromDimensions({
  22. * dimensions : new Cesium.Cartesian3(1000000.0, 1000000.0, 500000.0)
  23. * }),
  24. * modelMatrix : Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
  25. * Cesium.Cartesian3.fromDegrees(0.0, 0.0)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),
  26. * id : 'box',
  27. * attributes : {
  28. * color : new Cesium.GeometryInstanceAttribute({
  29. * componentDatatype : Cesium.ComponentDatatype.UNSIGNED_BYTE,
  30. * componentsPerAttribute : 4,
  31. * normalize : true,
  32. * value : [255, 255, 0, 255]
  33. * })
  34. * }
  35. * });
  36. *
  37. * @see ColorGeometryInstanceAttribute
  38. * @see ShowGeometryInstanceAttribute
  39. * @see DistanceDisplayConditionGeometryInstanceAttribute
  40. */
  41. function GeometryInstanceAttribute(options) {
  42. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  43. //>>includeStart('debug', pragmas.debug);
  44. if (!defined(options.componentDatatype)) {
  45. throw new DeveloperError('options.componentDatatype is required.');
  46. }
  47. if (!defined(options.componentsPerAttribute)) {
  48. throw new DeveloperError('options.componentsPerAttribute is required.');
  49. }
  50. if (options.componentsPerAttribute < 1 || options.componentsPerAttribute > 4) {
  51. throw new DeveloperError('options.componentsPerAttribute must be between 1 and 4.');
  52. }
  53. if (!defined(options.value)) {
  54. throw new DeveloperError('options.value is required.');
  55. }
  56. //>>includeEnd('debug');
  57. /**
  58. * The datatype of each component in the attribute, e.g., individual elements in
  59. * {@link GeometryInstanceAttribute#value}.
  60. *
  61. * @type ComponentDatatype
  62. *
  63. * @default undefined
  64. */
  65. this.componentDatatype = options.componentDatatype;
  66. /**
  67. * A number between 1 and 4 that defines the number of components in an attributes.
  68. * For example, a position attribute with x, y, and z components would have 3 as
  69. * shown in the code example.
  70. *
  71. * @type Number
  72. *
  73. * @default undefined
  74. *
  75. * @example
  76. * show : new Cesium.GeometryInstanceAttribute({
  77. * componentDatatype : Cesium.ComponentDatatype.UNSIGNED_BYTE,
  78. * componentsPerAttribute : 1,
  79. * normalize : true,
  80. * value : [1.0]
  81. * })
  82. */
  83. this.componentsPerAttribute = options.componentsPerAttribute;
  84. /**
  85. * When <code>true</code> and <code>componentDatatype</code> is an integer format,
  86. * indicate that the components should be mapped to the range [0, 1] (unsigned)
  87. * or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  88. * <p>
  89. * This is commonly used when storing colors using {@link ComponentDatatype.UNSIGNED_BYTE}.
  90. * </p>
  91. *
  92. * @type Boolean
  93. *
  94. * @default false
  95. *
  96. * @example
  97. * attribute.componentDatatype = Cesium.ComponentDatatype.UNSIGNED_BYTE;
  98. * attribute.componentsPerAttribute = 4;
  99. * attribute.normalize = true;
  100. * attribute.value = [
  101. * Cesium.Color.floatToByte(color.red),
  102. * Cesium.Color.floatToByte(color.green),
  103. * Cesium.Color.floatToByte(color.blue),
  104. * Cesium.Color.floatToByte(color.alpha)
  105. * ];
  106. */
  107. this.normalize = defaultValue(options.normalize, false);
  108. /**
  109. * The values for the attributes stored in a typed array. In the code example,
  110. * every three elements in <code>values</code> defines one attributes since
  111. * <code>componentsPerAttribute</code> is 3.
  112. *
  113. * @type {Number[]}
  114. *
  115. * @default undefined
  116. *
  117. * @example
  118. * show : new Cesium.GeometryInstanceAttribute({
  119. * componentDatatype : Cesium.ComponentDatatype.UNSIGNED_BYTE,
  120. * componentsPerAttribute : 1,
  121. * normalize : true,
  122. * value : [1.0]
  123. * })
  124. */
  125. this.value = options.value;
  126. }
  127. export default GeometryInstanceAttribute;