PlaneOutlineGeometry.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import BoundingSphere from "./BoundingSphere.js";
  2. import Cartesian3 from "./Cartesian3.js";
  3. import Check from "./Check.js";
  4. import ComponentDatatype from "./ComponentDatatype.js";
  5. import defined from "./defined.js";
  6. import Geometry from "./Geometry.js";
  7. import GeometryAttribute from "./GeometryAttribute.js";
  8. import GeometryAttributes from "./GeometryAttributes.js";
  9. import PrimitiveType from "./PrimitiveType.js";
  10. /**
  11. * Describes geometry representing the outline of a plane centered at the origin, with a unit width and length.
  12. *
  13. * @alias PlaneOutlineGeometry
  14. * @constructor
  15. *
  16. */
  17. function PlaneOutlineGeometry() {
  18. this._workerName = "createPlaneOutlineGeometry";
  19. }
  20. /**
  21. * The number of elements used to pack the object into an array.
  22. * @type {number}
  23. */
  24. PlaneOutlineGeometry.packedLength = 0;
  25. /**
  26. * Stores the provided instance into the provided array.
  27. *
  28. * @param {PlaneOutlineGeometry} value The value to pack.
  29. * @param {number[]} array The array to pack into.
  30. *
  31. * @returns {number[]} The array that was packed into
  32. */
  33. PlaneOutlineGeometry.pack = function (value, array) {
  34. //>>includeStart('debug', pragmas.debug);
  35. Check.defined("value", value);
  36. Check.defined("array", array);
  37. //>>includeEnd('debug');
  38. return array;
  39. };
  40. /**
  41. * Retrieves an instance from a packed array.
  42. *
  43. * @param {number[]} array The packed array.
  44. * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
  45. * @param {PlaneOutlineGeometry} [result] The object into which to store the result.
  46. * @returns {PlaneOutlineGeometry} The modified result parameter or a new PlaneOutlineGeometry instance if one was not provided.
  47. */
  48. PlaneOutlineGeometry.unpack = function (array, startingIndex, result) {
  49. //>>includeStart('debug', pragmas.debug);
  50. Check.defined("array", array);
  51. //>>includeEnd('debug');
  52. if (!defined(result)) {
  53. return new PlaneOutlineGeometry();
  54. }
  55. return result;
  56. };
  57. const min = new Cartesian3(-0.5, -0.5, 0.0);
  58. const max = new Cartesian3(0.5, 0.5, 0.0);
  59. /**
  60. * Computes the geometric representation of an outline of a plane, including its vertices, indices, and a bounding sphere.
  61. *
  62. * @returns {Geometry|undefined} The computed vertices and indices.
  63. */
  64. PlaneOutlineGeometry.createGeometry = function () {
  65. const attributes = new GeometryAttributes();
  66. const indices = new Uint16Array(4 * 2);
  67. const positions = new Float64Array(4 * 3);
  68. positions[0] = min.x;
  69. positions[1] = min.y;
  70. positions[2] = min.z;
  71. positions[3] = max.x;
  72. positions[4] = min.y;
  73. positions[5] = min.z;
  74. positions[6] = max.x;
  75. positions[7] = max.y;
  76. positions[8] = min.z;
  77. positions[9] = min.x;
  78. positions[10] = max.y;
  79. positions[11] = min.z;
  80. attributes.position = new GeometryAttribute({
  81. componentDatatype: ComponentDatatype.DOUBLE,
  82. componentsPerAttribute: 3,
  83. values: positions,
  84. });
  85. indices[0] = 0;
  86. indices[1] = 1;
  87. indices[2] = 1;
  88. indices[3] = 2;
  89. indices[4] = 2;
  90. indices[5] = 3;
  91. indices[6] = 3;
  92. indices[7] = 0;
  93. return new Geometry({
  94. attributes: attributes,
  95. indices: indices,
  96. primitiveType: PrimitiveType.LINES,
  97. boundingSphere: new BoundingSphere(Cartesian3.ZERO, Math.sqrt(2.0)),
  98. });
  99. };
  100. export default PlaneOutlineGeometry;