VertexFormat-563ab2cc.js 9.7 KB

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