VertexFormat-e46f29d6.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defaultValue-94c3e563', './RuntimeError-c581ca93'], (function (exports, defaultValue, RuntimeError) { '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. * const 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 = Object.freeze(
  101. new VertexFormat({
  102. position: true,
  103. })
  104. );
  105. /**
  106. * An immutable vertex format with position and normal attributes.
  107. * This is compatible with per-instance color appearances like {@link PerInstanceColorAppearance}.
  108. *
  109. * @type {VertexFormat}
  110. * @constant
  111. *
  112. * @see VertexFormat#position
  113. * @see VertexFormat#normal
  114. */
  115. VertexFormat.POSITION_AND_NORMAL = Object.freeze(
  116. new VertexFormat({
  117. position: true,
  118. normal: true,
  119. })
  120. );
  121. /**
  122. * An immutable vertex format with position, normal, and st attributes.
  123. * This is compatible with {@link MaterialAppearance} when {@link MaterialAppearance#materialSupport}
  124. * is <code>TEXTURED/code>.
  125. *
  126. * @type {VertexFormat}
  127. * @constant
  128. *
  129. * @see VertexFormat#position
  130. * @see VertexFormat#normal
  131. * @see VertexFormat#st
  132. */
  133. VertexFormat.POSITION_NORMAL_AND_ST = Object.freeze(
  134. new VertexFormat({
  135. position: true,
  136. normal: true,
  137. st: true,
  138. })
  139. );
  140. /**
  141. * An immutable vertex format with position and st attributes.
  142. * This is compatible with {@link EllipsoidSurfaceAppearance}.
  143. *
  144. * @type {VertexFormat}
  145. * @constant
  146. *
  147. * @see VertexFormat#position
  148. * @see VertexFormat#st
  149. */
  150. VertexFormat.POSITION_AND_ST = Object.freeze(
  151. new VertexFormat({
  152. position: true,
  153. st: true,
  154. })
  155. );
  156. /**
  157. * An immutable vertex format with position and color attributes.
  158. *
  159. * @type {VertexFormat}
  160. * @constant
  161. *
  162. * @see VertexFormat#position
  163. * @see VertexFormat#color
  164. */
  165. VertexFormat.POSITION_AND_COLOR = Object.freeze(
  166. new VertexFormat({
  167. position: true,
  168. color: true,
  169. })
  170. );
  171. /**
  172. * An immutable vertex format with well-known attributes: position, normal, st, tangent, and bitangent.
  173. *
  174. * @type {VertexFormat}
  175. * @constant
  176. *
  177. * @see VertexFormat#position
  178. * @see VertexFormat#normal
  179. * @see VertexFormat#st
  180. * @see VertexFormat#tangent
  181. * @see VertexFormat#bitangent
  182. */
  183. VertexFormat.ALL = Object.freeze(
  184. new VertexFormat({
  185. position: true,
  186. normal: true,
  187. st: true,
  188. tangent: true,
  189. bitangent: true,
  190. })
  191. );
  192. /**
  193. * An immutable vertex format with position, normal, and st attributes.
  194. * This is compatible with most appearances and materials; however
  195. * normal and st attributes are not always required. When this is
  196. * known in advance, another <code>VertexFormat</code> should be used.
  197. *
  198. * @type {VertexFormat}
  199. * @constant
  200. *
  201. * @see VertexFormat#position
  202. * @see VertexFormat#normal
  203. */
  204. VertexFormat.DEFAULT = VertexFormat.POSITION_NORMAL_AND_ST;
  205. /**
  206. * The number of elements used to pack the object into an array.
  207. * @type {Number}
  208. */
  209. VertexFormat.packedLength = 6;
  210. /**
  211. * Stores the provided instance into the provided array.
  212. *
  213. * @param {VertexFormat} value The value to pack.
  214. * @param {Number[]} array The array to pack into.
  215. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  216. *
  217. * @returns {Number[]} The array that was packed into
  218. */
  219. VertexFormat.pack = function (value, array, startingIndex) {
  220. //>>includeStart('debug', pragmas.debug);
  221. if (!defaultValue.defined(value)) {
  222. throw new RuntimeError.DeveloperError("value is required");
  223. }
  224. if (!defaultValue.defined(array)) {
  225. throw new RuntimeError.DeveloperError("array is required");
  226. }
  227. //>>includeEnd('debug');
  228. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  229. array[startingIndex++] = value.position ? 1.0 : 0.0;
  230. array[startingIndex++] = value.normal ? 1.0 : 0.0;
  231. array[startingIndex++] = value.st ? 1.0 : 0.0;
  232. array[startingIndex++] = value.tangent ? 1.0 : 0.0;
  233. array[startingIndex++] = value.bitangent ? 1.0 : 0.0;
  234. array[startingIndex] = value.color ? 1.0 : 0.0;
  235. return array;
  236. };
  237. /**
  238. * Retrieves an instance from a packed array.
  239. *
  240. * @param {Number[]} array The packed array.
  241. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  242. * @param {VertexFormat} [result] The object into which to store the result.
  243. * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided.
  244. */
  245. VertexFormat.unpack = function (array, startingIndex, result) {
  246. //>>includeStart('debug', pragmas.debug);
  247. if (!defaultValue.defined(array)) {
  248. throw new RuntimeError.DeveloperError("array is required");
  249. }
  250. //>>includeEnd('debug');
  251. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  252. if (!defaultValue.defined(result)) {
  253. result = new VertexFormat();
  254. }
  255. result.position = array[startingIndex++] === 1.0;
  256. result.normal = array[startingIndex++] === 1.0;
  257. result.st = array[startingIndex++] === 1.0;
  258. result.tangent = array[startingIndex++] === 1.0;
  259. result.bitangent = array[startingIndex++] === 1.0;
  260. result.color = array[startingIndex] === 1.0;
  261. return result;
  262. };
  263. /**
  264. * Duplicates a VertexFormat instance.
  265. *
  266. * @param {VertexFormat} vertexFormat The vertex format to duplicate.
  267. * @param {VertexFormat} [result] The object onto which to store the result.
  268. * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided. (Returns undefined if vertexFormat is undefined)
  269. */
  270. VertexFormat.clone = function (vertexFormat, result) {
  271. if (!defaultValue.defined(vertexFormat)) {
  272. return undefined;
  273. }
  274. if (!defaultValue.defined(result)) {
  275. result = new VertexFormat();
  276. }
  277. result.position = vertexFormat.position;
  278. result.normal = vertexFormat.normal;
  279. result.st = vertexFormat.st;
  280. result.tangent = vertexFormat.tangent;
  281. result.bitangent = vertexFormat.bitangent;
  282. result.color = vertexFormat.color;
  283. return result;
  284. };
  285. exports.VertexFormat = VertexFormat;
  286. }));