createPlaneGeometry.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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', './VertexFormat-e46f29d6', './_commonjsHelpers-3aae1032-f55dc0c4', './combine-761d9c3f', './WebGLConstants-7dccdc96'], (function (defaultValue, Transforms, Matrix2, RuntimeError, ComponentDatatype, GeometryAttribute, GeometryAttributes, VertexFormat, _commonjsHelpers3aae1032, combine, WebGLConstants) { 'use strict';
  3. /**
  4. * Describes geometry representing a plane centered at the origin, with a unit width and length.
  5. *
  6. * @alias PlaneGeometry
  7. * @constructor
  8. *
  9. * @param {Object} [options] Object with the following properties:
  10. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  11. *
  12. * @example
  13. * const planeGeometry = new Cesium.PlaneGeometry({
  14. * vertexFormat : Cesium.VertexFormat.POSITION_ONLY
  15. * });
  16. */
  17. function PlaneGeometry(options) {
  18. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  19. const vertexFormat = defaultValue.defaultValue(options.vertexFormat, VertexFormat.VertexFormat.DEFAULT);
  20. this._vertexFormat = vertexFormat;
  21. this._workerName = "createPlaneGeometry";
  22. }
  23. /**
  24. * The number of elements used to pack the object into an array.
  25. * @type {Number}
  26. */
  27. PlaneGeometry.packedLength = VertexFormat.VertexFormat.packedLength;
  28. /**
  29. * Stores the provided instance into the provided array.
  30. *
  31. * @param {PlaneGeometry} value The value to pack.
  32. * @param {Number[]} array The array to pack into.
  33. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  34. *
  35. * @returns {Number[]} The array that was packed into
  36. */
  37. PlaneGeometry.pack = function (value, array, startingIndex) {
  38. //>>includeStart('debug', pragmas.debug);
  39. RuntimeError.Check.typeOf.object("value", value);
  40. RuntimeError.Check.defined("array", array);
  41. //>>includeEnd('debug');
  42. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  43. VertexFormat.VertexFormat.pack(value._vertexFormat, array, startingIndex);
  44. return array;
  45. };
  46. const scratchVertexFormat = new VertexFormat.VertexFormat();
  47. const scratchOptions = {
  48. vertexFormat: scratchVertexFormat,
  49. };
  50. /**
  51. * Retrieves an instance from a packed array.
  52. *
  53. * @param {Number[]} array The packed array.
  54. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  55. * @param {PlaneGeometry} [result] The object into which to store the result.
  56. * @returns {PlaneGeometry} The modified result parameter or a new PlaneGeometry instance if one was not provided.
  57. */
  58. PlaneGeometry.unpack = function (array, startingIndex, result) {
  59. //>>includeStart('debug', pragmas.debug);
  60. RuntimeError.Check.defined("array", array);
  61. //>>includeEnd('debug');
  62. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  63. const vertexFormat = VertexFormat.VertexFormat.unpack(
  64. array,
  65. startingIndex,
  66. scratchVertexFormat
  67. );
  68. if (!defaultValue.defined(result)) {
  69. return new PlaneGeometry(scratchOptions);
  70. }
  71. result._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat, result._vertexFormat);
  72. return result;
  73. };
  74. const min = new Matrix2.Cartesian3(-0.5, -0.5, 0.0);
  75. const max = new Matrix2.Cartesian3(0.5, 0.5, 0.0);
  76. /**
  77. * Computes the geometric representation of a plane, including its vertices, indices, and a bounding sphere.
  78. *
  79. * @param {PlaneGeometry} planeGeometry A description of the plane.
  80. * @returns {Geometry|undefined} The computed vertices and indices.
  81. */
  82. PlaneGeometry.createGeometry = function (planeGeometry) {
  83. const vertexFormat = planeGeometry._vertexFormat;
  84. const attributes = new GeometryAttributes.GeometryAttributes();
  85. let indices;
  86. let positions;
  87. if (vertexFormat.position) {
  88. // 4 corner points. Duplicated 3 times each for each incident edge/face.
  89. positions = new Float64Array(4 * 3);
  90. // +z face
  91. positions[0] = min.x;
  92. positions[1] = min.y;
  93. positions[2] = 0.0;
  94. positions[3] = max.x;
  95. positions[4] = min.y;
  96. positions[5] = 0.0;
  97. positions[6] = max.x;
  98. positions[7] = max.y;
  99. positions[8] = 0.0;
  100. positions[9] = min.x;
  101. positions[10] = max.y;
  102. positions[11] = 0.0;
  103. attributes.position = new GeometryAttribute.GeometryAttribute({
  104. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  105. componentsPerAttribute: 3,
  106. values: positions,
  107. });
  108. if (vertexFormat.normal) {
  109. const normals = new Float32Array(4 * 3);
  110. // +z face
  111. normals[0] = 0.0;
  112. normals[1] = 0.0;
  113. normals[2] = 1.0;
  114. normals[3] = 0.0;
  115. normals[4] = 0.0;
  116. normals[5] = 1.0;
  117. normals[6] = 0.0;
  118. normals[7] = 0.0;
  119. normals[8] = 1.0;
  120. normals[9] = 0.0;
  121. normals[10] = 0.0;
  122. normals[11] = 1.0;
  123. attributes.normal = new GeometryAttribute.GeometryAttribute({
  124. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  125. componentsPerAttribute: 3,
  126. values: normals,
  127. });
  128. }
  129. if (vertexFormat.st) {
  130. const texCoords = new Float32Array(4 * 2);
  131. // +z face
  132. texCoords[0] = 0.0;
  133. texCoords[1] = 0.0;
  134. texCoords[2] = 1.0;
  135. texCoords[3] = 0.0;
  136. texCoords[4] = 1.0;
  137. texCoords[5] = 1.0;
  138. texCoords[6] = 0.0;
  139. texCoords[7] = 1.0;
  140. attributes.st = new GeometryAttribute.GeometryAttribute({
  141. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  142. componentsPerAttribute: 2,
  143. values: texCoords,
  144. });
  145. }
  146. if (vertexFormat.tangent) {
  147. const tangents = new Float32Array(4 * 3);
  148. // +z face
  149. tangents[0] = 1.0;
  150. tangents[1] = 0.0;
  151. tangents[2] = 0.0;
  152. tangents[3] = 1.0;
  153. tangents[4] = 0.0;
  154. tangents[5] = 0.0;
  155. tangents[6] = 1.0;
  156. tangents[7] = 0.0;
  157. tangents[8] = 0.0;
  158. tangents[9] = 1.0;
  159. tangents[10] = 0.0;
  160. tangents[11] = 0.0;
  161. attributes.tangent = new GeometryAttribute.GeometryAttribute({
  162. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  163. componentsPerAttribute: 3,
  164. values: tangents,
  165. });
  166. }
  167. if (vertexFormat.bitangent) {
  168. const bitangents = new Float32Array(4 * 3);
  169. // +z face
  170. bitangents[0] = 0.0;
  171. bitangents[1] = 1.0;
  172. bitangents[2] = 0.0;
  173. bitangents[3] = 0.0;
  174. bitangents[4] = 1.0;
  175. bitangents[5] = 0.0;
  176. bitangents[6] = 0.0;
  177. bitangents[7] = 1.0;
  178. bitangents[8] = 0.0;
  179. bitangents[9] = 0.0;
  180. bitangents[10] = 1.0;
  181. bitangents[11] = 0.0;
  182. attributes.bitangent = new GeometryAttribute.GeometryAttribute({
  183. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  184. componentsPerAttribute: 3,
  185. values: bitangents,
  186. });
  187. }
  188. // 2 triangles
  189. indices = new Uint16Array(2 * 3);
  190. // +z face
  191. indices[0] = 0;
  192. indices[1] = 1;
  193. indices[2] = 2;
  194. indices[3] = 0;
  195. indices[4] = 2;
  196. indices[5] = 3;
  197. }
  198. return new GeometryAttribute.Geometry({
  199. attributes: attributes,
  200. indices: indices,
  201. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  202. boundingSphere: new Transforms.BoundingSphere(Matrix2.Cartesian3.ZERO, Math.sqrt(2.0)),
  203. });
  204. };
  205. function createPlaneGeometry(planeGeometry, offset) {
  206. if (defaultValue.defined(offset)) {
  207. planeGeometry = PlaneGeometry.unpack(planeGeometry, offset);
  208. }
  209. return PlaneGeometry.createGeometry(planeGeometry);
  210. }
  211. return createPlaneGeometry;
  212. }));