createPlaneOutlineGeometry.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './defaultValue-f2e68450', './Math-fa6e45cb', './Cartesian2-2a723276', './defineProperties-6f7a50f2', './Transforms-65aba0a4', './RuntimeError-ad75c885', './WebGLConstants-497deb20', './ComponentDatatype-69643096', './GeometryAttribute-ed359d71', './when-ee12a2cb', './GeometryAttributes-eecc9f43'], function (defined, Check, freezeObject, defaultValue, _Math, Cartesian2, defineProperties, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, when, GeometryAttributes) { '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. Check.Check.defined('value', value);
  29. Check.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. Check.Check.defined('array', array);
  44. //>>includeEnd('debug');
  45. if (!defined.defined(result)) {
  46. return new PlaneOutlineGeometry();
  47. }
  48. return result;
  49. };
  50. var min = new Cartesian2.Cartesian3(-0.5, -0.5, 0.0);
  51. var max = new Cartesian2.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. var attributes = new GeometryAttributes.GeometryAttributes();
  59. var indices = new Uint16Array(4 * 2);
  60. var 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(Cartesian2.Cartesian3.ZERO, Math.sqrt(2.0))
  91. });
  92. };
  93. function createPlaneOutlineGeometry(planeGeometry, offset) {
  94. if (defined.defined(offset)) {
  95. planeGeometry = PlaneOutlineGeometry.unpack(planeGeometry, offset);
  96. }
  97. return PlaneOutlineGeometry.createGeometry(planeGeometry);
  98. }
  99. return createPlaneOutlineGeometry;
  100. });