createPlaneOutlineGeometry.js 5.5 KB

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