OffsetGeometryInstanceAttribute.js 3.6 KB

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