createPlaneOutlineGeometry.js 3.9 KB

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