VertexFormat-030f11ff.js 8.8 KB

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