createPlaneGeometry.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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', './VertexFormat-fbb91dc7'], function (defined, Check, freezeObject, defaultValue, _Math, Cartesian2, defineProperties, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, when, GeometryAttributes, VertexFormat) { '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. * var 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. var 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. Check.Check.typeOf.object('value', value);
  40. Check.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. var scratchVertexFormat = new VertexFormat.VertexFormat();
  47. var 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. Check.Check.defined('array', array);
  61. //>>includeEnd('debug');
  62. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  63. var vertexFormat = VertexFormat.VertexFormat.unpack(array, startingIndex, scratchVertexFormat);
  64. if (!defined.defined(result)) {
  65. return new PlaneGeometry(scratchOptions);
  66. }
  67. result._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat, result._vertexFormat);
  68. return result;
  69. };
  70. var min = new Cartesian2.Cartesian3(-0.5, -0.5, 0.0);
  71. var max = new Cartesian2.Cartesian3( 0.5, 0.5, 0.0);
  72. /**
  73. * Computes the geometric representation of a plane, including its vertices, indices, and a bounding sphere.
  74. *
  75. * @param {PlaneGeometry} planeGeometry A description of the plane.
  76. * @returns {Geometry|undefined} The computed vertices and indices.
  77. */
  78. PlaneGeometry.createGeometry = function(planeGeometry) {
  79. var vertexFormat = planeGeometry._vertexFormat;
  80. var attributes = new GeometryAttributes.GeometryAttributes();
  81. var indices;
  82. var positions;
  83. if (vertexFormat.position) {
  84. // 4 corner points. Duplicated 3 times each for each incident edge/face.
  85. positions = new Float64Array(4 * 3);
  86. // +z face
  87. positions[0] = min.x;
  88. positions[1] = min.y;
  89. positions[2] = 0.0;
  90. positions[3] = max.x;
  91. positions[4] = min.y;
  92. positions[5] = 0.0;
  93. positions[6] = max.x;
  94. positions[7] = max.y;
  95. positions[8] = 0.0;
  96. positions[9] = min.x;
  97. positions[10] = max.y;
  98. positions[11] = 0.0;
  99. attributes.position = new GeometryAttribute.GeometryAttribute({
  100. componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
  101. componentsPerAttribute : 3,
  102. values : positions
  103. });
  104. if (vertexFormat.normal) {
  105. var normals = new Float32Array(4 * 3);
  106. // +z face
  107. normals[0] = 0.0;
  108. normals[1] = 0.0;
  109. normals[2] = 1.0;
  110. normals[3] = 0.0;
  111. normals[4] = 0.0;
  112. normals[5] = 1.0;
  113. normals[6] = 0.0;
  114. normals[7] = 0.0;
  115. normals[8] = 1.0;
  116. normals[9] = 0.0;
  117. normals[10] = 0.0;
  118. normals[11] = 1.0;
  119. attributes.normal = new GeometryAttribute.GeometryAttribute({
  120. componentDatatype : ComponentDatatype.ComponentDatatype.FLOAT,
  121. componentsPerAttribute : 3,
  122. values : normals
  123. });
  124. }
  125. if (vertexFormat.st) {
  126. var texCoords = new Float32Array(4 * 2);
  127. // +z face
  128. texCoords[0] = 0.0;
  129. texCoords[1] = 0.0;
  130. texCoords[2] = 1.0;
  131. texCoords[3] = 0.0;
  132. texCoords[4] = 1.0;
  133. texCoords[5] = 1.0;
  134. texCoords[6] = 0.0;
  135. texCoords[7] = 1.0;
  136. attributes.st = new GeometryAttribute.GeometryAttribute({
  137. componentDatatype : ComponentDatatype.ComponentDatatype.FLOAT,
  138. componentsPerAttribute : 2,
  139. values : texCoords
  140. });
  141. }
  142. if (vertexFormat.tangent) {
  143. var tangents = new Float32Array(4 * 3);
  144. // +z face
  145. tangents[0] = 1.0;
  146. tangents[1] = 0.0;
  147. tangents[2] = 0.0;
  148. tangents[3] = 1.0;
  149. tangents[4] = 0.0;
  150. tangents[5] = 0.0;
  151. tangents[6] = 1.0;
  152. tangents[7] = 0.0;
  153. tangents[8] = 0.0;
  154. tangents[9] = 1.0;
  155. tangents[10] = 0.0;
  156. tangents[11] = 0.0;
  157. attributes.tangent = new GeometryAttribute.GeometryAttribute({
  158. componentDatatype : ComponentDatatype.ComponentDatatype.FLOAT,
  159. componentsPerAttribute : 3,
  160. values : tangents
  161. });
  162. }
  163. if (vertexFormat.bitangent) {
  164. var bitangents = new Float32Array(4 * 3);
  165. // +z face
  166. bitangents[0] = 0.0;
  167. bitangents[1] = 1.0;
  168. bitangents[2] = 0.0;
  169. bitangents[3] = 0.0;
  170. bitangents[4] = 1.0;
  171. bitangents[5] = 0.0;
  172. bitangents[6] = 0.0;
  173. bitangents[7] = 1.0;
  174. bitangents[8] = 0.0;
  175. bitangents[9] = 0.0;
  176. bitangents[10] = 1.0;
  177. bitangents[11] = 0.0;
  178. attributes.bitangent = new GeometryAttribute.GeometryAttribute({
  179. componentDatatype : ComponentDatatype.ComponentDatatype.FLOAT,
  180. componentsPerAttribute : 3,
  181. values : bitangents
  182. });
  183. }
  184. // 2 triangles
  185. indices = new Uint16Array(2 * 3);
  186. // +z face
  187. indices[0] = 0;
  188. indices[1] = 1;
  189. indices[2] = 2;
  190. indices[3] = 0;
  191. indices[4] = 2;
  192. indices[5] = 3;
  193. }
  194. return new GeometryAttribute.Geometry({
  195. attributes : attributes,
  196. indices : indices,
  197. primitiveType : GeometryAttribute.PrimitiveType.TRIANGLES,
  198. boundingSphere : new Transforms.BoundingSphere(Cartesian2.Cartesian3.ZERO, Math.sqrt(2.0))
  199. });
  200. };
  201. function createPlaneGeometry(planeGeometry, offset) {
  202. if (defined.defined(offset)) {
  203. planeGeometry = PlaneGeometry.unpack(planeGeometry, offset);
  204. }
  205. return PlaneGeometry.createGeometry(planeGeometry);
  206. }
  207. return createPlaneGeometry;
  208. });