OffsetGeometryInstanceAttribute.js 4.2 KB

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