createPlaneOutlineGeometry.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.97
  5. *
  6. * Copyright 2011-2022 Cesium Contributors
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * Columbus View (Pat. Pend.)
  21. *
  22. * Portions licensed separately.
  23. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  24. */
  25. define(['./defaultValue-a6eb9f34', './Transforms-c78c4637', './Matrix2-ab676047', './RuntimeError-1088cc64', './ComponentDatatype-e06f4e16', './GeometryAttribute-4f02e2ad', './GeometryAttributes-aff51037', './_commonjsHelpers-89c9b271', './combine-7cf28d88', './WebGLConstants-d81b330d'], (function (defaultValue, Transforms, Matrix2, RuntimeError, ComponentDatatype, GeometryAttribute, GeometryAttributes, _commonjsHelpers, combine, WebGLConstants) { 'use strict';
  26. /**
  27. * Describes geometry representing the outline of a plane centered at the origin, with a unit width and length.
  28. *
  29. * @alias PlaneOutlineGeometry
  30. * @constructor
  31. *
  32. */
  33. function PlaneOutlineGeometry() {
  34. this._workerName = "createPlaneOutlineGeometry";
  35. }
  36. /**
  37. * The number of elements used to pack the object into an array.
  38. * @type {Number}
  39. */
  40. PlaneOutlineGeometry.packedLength = 0;
  41. /**
  42. * Stores the provided instance into the provided array.
  43. *
  44. * @param {PlaneOutlineGeometry} value The value to pack.
  45. * @param {Number[]} array The array to pack into.
  46. *
  47. * @returns {Number[]} The array that was packed into
  48. */
  49. PlaneOutlineGeometry.pack = function (value, array) {
  50. //>>includeStart('debug', pragmas.debug);
  51. RuntimeError.Check.defined("value", value);
  52. RuntimeError.Check.defined("array", array);
  53. //>>includeEnd('debug');
  54. return array;
  55. };
  56. /**
  57. * Retrieves an instance from a packed array.
  58. *
  59. * @param {Number[]} array The packed array.
  60. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  61. * @param {PlaneOutlineGeometry} [result] The object into which to store the result.
  62. * @returns {PlaneOutlineGeometry} The modified result parameter or a new PlaneOutlineGeometry instance if one was not provided.
  63. */
  64. PlaneOutlineGeometry.unpack = function (array, startingIndex, result) {
  65. //>>includeStart('debug', pragmas.debug);
  66. RuntimeError.Check.defined("array", array);
  67. //>>includeEnd('debug');
  68. if (!defaultValue.defined(result)) {
  69. return new PlaneOutlineGeometry();
  70. }
  71. return result;
  72. };
  73. const min = new Matrix2.Cartesian3(-0.5, -0.5, 0.0);
  74. const max = new Matrix2.Cartesian3(0.5, 0.5, 0.0);
  75. /**
  76. * Computes the geometric representation of an outline of a plane, including its vertices, indices, and a bounding sphere.
  77. *
  78. * @returns {Geometry|undefined} The computed vertices and indices.
  79. */
  80. PlaneOutlineGeometry.createGeometry = function () {
  81. const attributes = new GeometryAttributes.GeometryAttributes();
  82. const indices = new Uint16Array(4 * 2);
  83. const positions = new Float64Array(4 * 3);
  84. positions[0] = min.x;
  85. positions[1] = min.y;
  86. positions[2] = min.z;
  87. positions[3] = max.x;
  88. positions[4] = min.y;
  89. positions[5] = min.z;
  90. positions[6] = max.x;
  91. positions[7] = max.y;
  92. positions[8] = min.z;
  93. positions[9] = min.x;
  94. positions[10] = max.y;
  95. positions[11] = min.z;
  96. attributes.position = new GeometryAttribute.GeometryAttribute({
  97. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  98. componentsPerAttribute: 3,
  99. values: positions,
  100. });
  101. indices[0] = 0;
  102. indices[1] = 1;
  103. indices[2] = 1;
  104. indices[3] = 2;
  105. indices[4] = 2;
  106. indices[5] = 3;
  107. indices[6] = 3;
  108. indices[7] = 0;
  109. return new GeometryAttribute.Geometry({
  110. attributes: attributes,
  111. indices: indices,
  112. primitiveType: GeometryAttribute.PrimitiveType.LINES,
  113. boundingSphere: new Transforms.BoundingSphere(Matrix2.Cartesian3.ZERO, Math.sqrt(2.0)),
  114. });
  115. };
  116. function createPlaneOutlineGeometry(planeGeometry, offset) {
  117. if (defaultValue.defined(offset)) {
  118. planeGeometry = PlaneOutlineGeometry.unpack(planeGeometry, offset);
  119. }
  120. return PlaneOutlineGeometry.createGeometry(planeGeometry);
  121. }
  122. return createPlaneOutlineGeometry;
  123. }));