createPlaneOutlineGeometry.js 3.8 KB

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