VertexFormat-fbb91dc7.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './defaultValue-f2e68450'], function (exports, defined, Check, freezeObject, defaultValue) { 'use strict';
  3. /**
  4. * A vertex format defines what attributes make up a vertex. A VertexFormat can be provided
  5. * to a {@link Geometry} to request that certain properties be computed, e.g., just position,
  6. * position and normal, etc.
  7. *
  8. * @param {Object} [options] An object with boolean properties corresponding to VertexFormat properties as shown in the code example.
  9. *
  10. * @alias VertexFormat
  11. * @constructor
  12. *
  13. * @example
  14. * // Create a vertex format with position and 2D texture coordinate attributes.
  15. * var format = new Cesium.VertexFormat({
  16. * position : true,
  17. * st : true
  18. * });
  19. *
  20. * @see Geometry#attributes
  21. * @see Packable
  22. */
  23. function VertexFormat(options) {
  24. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  25. /**
  26. * When <code>true</code>, the vertex has a 3D position attribute.
  27. * <p>
  28. * 64-bit floating-point (for precision). 3 components per attribute.
  29. * </p>
  30. *
  31. * @type Boolean
  32. *
  33. * @default false
  34. */
  35. this.position = defaultValue.defaultValue(options.position, false);
  36. /**
  37. * When <code>true</code>, the vertex has a normal attribute (normalized), which is commonly used for lighting.
  38. * <p>
  39. * 32-bit floating-point. 3 components per attribute.
  40. * </p>
  41. *
  42. * @type Boolean
  43. *
  44. * @default false
  45. */
  46. this.normal = defaultValue.defaultValue(options.normal, false);
  47. /**
  48. * When <code>true</code>, the vertex has a 2D texture coordinate attribute.
  49. * <p>
  50. * 32-bit floating-point. 2 components per attribute
  51. * </p>
  52. *
  53. * @type Boolean
  54. *
  55. * @default false
  56. */
  57. this.st = defaultValue.defaultValue(options.st, false);
  58. /**
  59. * When <code>true</code>, the vertex has a bitangent attribute (normalized), which is used for tangent-space effects like bump mapping.
  60. * <p>
  61. * 32-bit floating-point. 3 components per attribute.
  62. * </p>
  63. *
  64. * @type Boolean
  65. *
  66. * @default false
  67. */
  68. this.bitangent = defaultValue.defaultValue(options.bitangent, false);
  69. /**
  70. * When <code>true</code>, the vertex has a tangent attribute (normalized), which is used for tangent-space effects like bump mapping.
  71. * <p>
  72. * 32-bit floating-point. 3 components per attribute.
  73. * </p>
  74. *
  75. * @type Boolean
  76. *
  77. * @default false
  78. */
  79. this.tangent = defaultValue.defaultValue(options.tangent, false);
  80. /**
  81. * When <code>true</code>, the vertex has an RGB color attribute.
  82. * <p>
  83. * 8-bit unsigned byte. 3 components per attribute.
  84. * </p>
  85. *
  86. * @type Boolean
  87. *
  88. * @default false
  89. */
  90. this.color = defaultValue.defaultValue(options.color, false);
  91. }
  92. /**
  93. * An immutable vertex format with only a position attribute.
  94. *
  95. * @type {VertexFormat}
  96. * @constant
  97. *
  98. * @see VertexFormat#position
  99. */
  100. VertexFormat.POSITION_ONLY = freezeObject.freezeObject(new VertexFormat({
  101. position : true
  102. }));
  103. /**
  104. * An immutable vertex format with position and normal attributes.
  105. * This is compatible with per-instance color appearances like {@link PerInstanceColorAppearance}.
  106. *
  107. * @type {VertexFormat}
  108. * @constant
  109. *
  110. * @see VertexFormat#position
  111. * @see VertexFormat#normal
  112. */
  113. VertexFormat.POSITION_AND_NORMAL = freezeObject.freezeObject(new VertexFormat({
  114. position : true,
  115. normal : true
  116. }));
  117. /**
  118. * An immutable vertex format with position, normal, and st attributes.
  119. * This is compatible with {@link MaterialAppearance} when {@link MaterialAppearance#materialSupport}
  120. * is <code>TEXTURED/code>.
  121. *
  122. * @type {VertexFormat}
  123. * @constant
  124. *
  125. * @see VertexFormat#position
  126. * @see VertexFormat#normal
  127. * @see VertexFormat#st
  128. */
  129. VertexFormat.POSITION_NORMAL_AND_ST = freezeObject.freezeObject(new VertexFormat({
  130. position : true,
  131. normal : true,
  132. st : true
  133. }));
  134. /**
  135. * An immutable vertex format with position and st attributes.
  136. * This is compatible with {@link EllipsoidSurfaceAppearance}.
  137. *
  138. * @type {VertexFormat}
  139. * @constant
  140. *
  141. * @see VertexFormat#position
  142. * @see VertexFormat#st
  143. */
  144. VertexFormat.POSITION_AND_ST = freezeObject.freezeObject(new VertexFormat({
  145. position : true,
  146. st : true
  147. }));
  148. /**
  149. * An immutable vertex format with position and color attributes.
  150. *
  151. * @type {VertexFormat}
  152. * @constant
  153. *
  154. * @see VertexFormat#position
  155. * @see VertexFormat#color
  156. */
  157. VertexFormat.POSITION_AND_COLOR = freezeObject.freezeObject(new VertexFormat({
  158. position : true,
  159. color : true
  160. }));
  161. /**
  162. * An immutable vertex format with well-known attributes: position, normal, st, tangent, and bitangent.
  163. *
  164. * @type {VertexFormat}
  165. * @constant
  166. *
  167. * @see VertexFormat#position
  168. * @see VertexFormat#normal
  169. * @see VertexFormat#st
  170. * @see VertexFormat#tangent
  171. * @see VertexFormat#bitangent
  172. */
  173. VertexFormat.ALL = freezeObject.freezeObject(new VertexFormat({
  174. position : true,
  175. normal : true,
  176. st : true,
  177. tangent : true,
  178. bitangent : true
  179. }));
  180. /**
  181. * An immutable vertex format with position, normal, and st attributes.
  182. * This is compatible with most appearances and materials; however
  183. * normal and st attributes are not always required. When this is
  184. * known in advance, another <code>VertexFormat</code> should be used.
  185. *
  186. * @type {VertexFormat}
  187. * @constant
  188. *
  189. * @see VertexFormat#position
  190. * @see VertexFormat#normal
  191. */
  192. VertexFormat.DEFAULT = VertexFormat.POSITION_NORMAL_AND_ST;
  193. /**
  194. * The number of elements used to pack the object into an array.
  195. * @type {Number}
  196. */
  197. VertexFormat.packedLength = 6;
  198. /**
  199. * Stores the provided instance into the provided array.
  200. *
  201. * @param {VertexFormat} value The value to pack.
  202. * @param {Number[]} array The array to pack into.
  203. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  204. *
  205. * @returns {Number[]} The array that was packed into
  206. */
  207. VertexFormat.pack = function(value, array, startingIndex) {
  208. //>>includeStart('debug', pragmas.debug);
  209. if (!defined.defined(value)) {
  210. throw new Check.DeveloperError('value is required');
  211. }
  212. if (!defined.defined(array)) {
  213. throw new Check.DeveloperError('array is required');
  214. }
  215. //>>includeEnd('debug');
  216. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  217. array[startingIndex++] = value.position ? 1.0 : 0.0;
  218. array[startingIndex++] = value.normal ? 1.0 : 0.0;
  219. array[startingIndex++] = value.st ? 1.0 : 0.0;
  220. array[startingIndex++] = value.tangent ? 1.0 : 0.0;
  221. array[startingIndex++] = value.bitangent ? 1.0 : 0.0;
  222. array[startingIndex] = value.color ? 1.0 : 0.0;
  223. return array;
  224. };
  225. /**
  226. * Retrieves an instance from a packed array.
  227. *
  228. * @param {Number[]} array The packed array.
  229. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  230. * @param {VertexFormat} [result] The object into which to store the result.
  231. * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided.
  232. */
  233. VertexFormat.unpack = function(array, startingIndex, result) {
  234. //>>includeStart('debug', pragmas.debug);
  235. if (!defined.defined(array)) {
  236. throw new Check.DeveloperError('array is required');
  237. }
  238. //>>includeEnd('debug');
  239. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  240. if (!defined.defined(result)) {
  241. result = new VertexFormat();
  242. }
  243. result.position = array[startingIndex++] === 1.0;
  244. result.normal = array[startingIndex++] === 1.0;
  245. result.st = array[startingIndex++] === 1.0;
  246. result.tangent = array[startingIndex++] === 1.0;
  247. result.bitangent = array[startingIndex++] === 1.0;
  248. result.color = array[startingIndex] === 1.0;
  249. return result;
  250. };
  251. /**
  252. * Duplicates a VertexFormat instance.
  253. *
  254. * @param {VertexFormat} vertexFormat The vertex format to duplicate.
  255. * @param {VertexFormat} [result] The object onto which to store the result.
  256. * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided. (Returns undefined if vertexFormat is undefined)
  257. */
  258. VertexFormat.clone = function(vertexFormat, result) {
  259. if (!defined.defined(vertexFormat)) {
  260. return undefined;
  261. }
  262. if (!defined.defined(result)) {
  263. result = new VertexFormat();
  264. }
  265. result.position = vertexFormat.position;
  266. result.normal = vertexFormat.normal;
  267. result.st = vertexFormat.st;
  268. result.tangent = vertexFormat.tangent;
  269. result.bitangent = vertexFormat.bitangent;
  270. result.color = vertexFormat.color;
  271. return result;
  272. };
  273. exports.VertexFormat = VertexFormat;
  274. });