GeometryAttribute-2ecf73f6.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './Matrix2-fc7e9822', './RuntimeError-c581ca93', './defaultValue-94c3e563', './WebGLConstants-7dccdc96', './Transforms-a076dbe6'], (function (exports, Matrix2, RuntimeError, defaultValue, WebGLConstants, Transforms) { 'use strict';
  3. /**
  4. * @private
  5. */
  6. const GeometryType = {
  7. NONE: 0,
  8. TRIANGLES: 1,
  9. LINES: 2,
  10. POLYLINES: 3,
  11. };
  12. var GeometryType$1 = Object.freeze(GeometryType);
  13. /**
  14. * The type of a geometric primitive, i.e., points, lines, and triangles.
  15. *
  16. * @enum {Number}
  17. */
  18. const PrimitiveType = {
  19. /**
  20. * Points primitive where each vertex (or index) is a separate point.
  21. *
  22. * @type {Number}
  23. * @constant
  24. */
  25. POINTS: WebGLConstants.WebGLConstants.POINTS,
  26. /**
  27. * Lines primitive where each two vertices (or indices) is a line segment. Line segments are not necessarily connected.
  28. *
  29. * @type {Number}
  30. * @constant
  31. */
  32. LINES: WebGLConstants.WebGLConstants.LINES,
  33. /**
  34. * Line loop primitive where each vertex (or index) after the first connects a line to
  35. * the previous vertex, and the last vertex implicitly connects to the first.
  36. *
  37. * @type {Number}
  38. * @constant
  39. */
  40. LINE_LOOP: WebGLConstants.WebGLConstants.LINE_LOOP,
  41. /**
  42. * Line strip primitive where each vertex (or index) after the first connects a line to the previous vertex.
  43. *
  44. * @type {Number}
  45. * @constant
  46. */
  47. LINE_STRIP: WebGLConstants.WebGLConstants.LINE_STRIP,
  48. /**
  49. * Triangles primitive where each three vertices (or indices) is a triangle. Triangles do not necessarily share edges.
  50. *
  51. * @type {Number}
  52. * @constant
  53. */
  54. TRIANGLES: WebGLConstants.WebGLConstants.TRIANGLES,
  55. /**
  56. * Triangle strip primitive where each vertex (or index) after the first two connect to
  57. * the previous two vertices forming a triangle. For example, this can be used to model a wall.
  58. *
  59. * @type {Number}
  60. * @constant
  61. */
  62. TRIANGLE_STRIP: WebGLConstants.WebGLConstants.TRIANGLE_STRIP,
  63. /**
  64. * Triangle fan primitive where each vertex (or index) after the first two connect to
  65. * the previous vertex and the first vertex forming a triangle. For example, this can be used
  66. * to model a cone or circle.
  67. *
  68. * @type {Number}
  69. * @constant
  70. */
  71. TRIANGLE_FAN: WebGLConstants.WebGLConstants.TRIANGLE_FAN,
  72. };
  73. /**
  74. * @private
  75. */
  76. PrimitiveType.isLines = function (primitiveType) {
  77. return (
  78. primitiveType === PrimitiveType.LINES ||
  79. primitiveType === PrimitiveType.LINE_LOOP ||
  80. primitiveType === PrimitiveType.LINE_STRIP
  81. );
  82. };
  83. /**
  84. * @private
  85. */
  86. PrimitiveType.isTriangles = function (primitiveType) {
  87. return (
  88. primitiveType === PrimitiveType.TRIANGLES ||
  89. primitiveType === PrimitiveType.TRIANGLE_STRIP ||
  90. primitiveType === PrimitiveType.TRIANGLE_FAN
  91. );
  92. };
  93. /**
  94. * @private
  95. */
  96. PrimitiveType.validate = function (primitiveType) {
  97. return (
  98. primitiveType === PrimitiveType.POINTS ||
  99. primitiveType === PrimitiveType.LINES ||
  100. primitiveType === PrimitiveType.LINE_LOOP ||
  101. primitiveType === PrimitiveType.LINE_STRIP ||
  102. primitiveType === PrimitiveType.TRIANGLES ||
  103. primitiveType === PrimitiveType.TRIANGLE_STRIP ||
  104. primitiveType === PrimitiveType.TRIANGLE_FAN
  105. );
  106. };
  107. var PrimitiveType$1 = Object.freeze(PrimitiveType);
  108. /**
  109. * A geometry representation with attributes forming vertices and optional index data
  110. * defining primitives. Geometries and an {@link Appearance}, which describes the shading,
  111. * can be assigned to a {@link Primitive} for visualization. A <code>Primitive</code> can
  112. * be created from many heterogeneous - in many cases - geometries for performance.
  113. * <p>
  114. * Geometries can be transformed and optimized using functions in {@link GeometryPipeline}.
  115. * </p>
  116. *
  117. * @alias Geometry
  118. * @constructor
  119. *
  120. * @param {Object} options Object with the following properties:
  121. * @param {GeometryAttributes} options.attributes Attributes, which make up the geometry's vertices.
  122. * @param {PrimitiveType} [options.primitiveType=PrimitiveType.TRIANGLES] The type of primitives in the geometry.
  123. * @param {Uint16Array|Uint32Array} [options.indices] Optional index data that determines the primitives in the geometry.
  124. * @param {BoundingSphere} [options.boundingSphere] An optional bounding sphere that fully enclosed the geometry.
  125. *
  126. * @see PolygonGeometry
  127. * @see RectangleGeometry
  128. * @see EllipseGeometry
  129. * @see CircleGeometry
  130. * @see WallGeometry
  131. * @see SimplePolylineGeometry
  132. * @see BoxGeometry
  133. * @see EllipsoidGeometry
  134. *
  135. * @demo {@link https://sandcastle.cesium.com/index.html?src=Geometry%20and%20Appearances.html|Geometry and Appearances Demo}
  136. *
  137. * @example
  138. * // Create geometry with a position attribute and indexed lines.
  139. * const positions = new Float64Array([
  140. * 0.0, 0.0, 0.0,
  141. * 7500000.0, 0.0, 0.0,
  142. * 0.0, 7500000.0, 0.0
  143. * ]);
  144. *
  145. * const geometry = new Cesium.Geometry({
  146. * attributes : {
  147. * position : new Cesium.GeometryAttribute({
  148. * componentDatatype : Cesium.ComponentDatatype.DOUBLE,
  149. * componentsPerAttribute : 3,
  150. * values : positions
  151. * })
  152. * },
  153. * indices : new Uint16Array([0, 1, 1, 2, 2, 0]),
  154. * primitiveType : Cesium.PrimitiveType.LINES,
  155. * boundingSphere : Cesium.BoundingSphere.fromVertices(positions)
  156. * });
  157. */
  158. function Geometry(options) {
  159. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  160. //>>includeStart('debug', pragmas.debug);
  161. RuntimeError.Check.typeOf.object("options.attributes", options.attributes);
  162. //>>includeEnd('debug');
  163. /**
  164. * Attributes, which make up the geometry's vertices. Each property in this object corresponds to a
  165. * {@link GeometryAttribute} containing the attribute's data.
  166. * <p>
  167. * Attributes are always stored non-interleaved in a Geometry.
  168. * </p>
  169. * <p>
  170. * There are reserved attribute names with well-known semantics. The following attributes
  171. * are created by a Geometry (depending on the provided {@link VertexFormat}.
  172. * <ul>
  173. * <li><code>position</code> - 3D vertex position. 64-bit floating-point (for precision). 3 components per attribute. See {@link VertexFormat#position}.</li>
  174. * <li><code>normal</code> - Normal (normalized), commonly used for lighting. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#normal}.</li>
  175. * <li><code>st</code> - 2D texture coordinate. 32-bit floating-point. 2 components per attribute. See {@link VertexFormat#st}.</li>
  176. * <li><code>bitangent</code> - Bitangent (normalized), used for tangent-space effects like bump mapping. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#bitangent}.</li>
  177. * <li><code>tangent</code> - Tangent (normalized), used for tangent-space effects like bump mapping. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#tangent}.</li>
  178. * </ul>
  179. * </p>
  180. * <p>
  181. * The following attribute names are generally not created by a Geometry, but are added
  182. * to a Geometry by a {@link Primitive} or {@link GeometryPipeline} functions to prepare
  183. * the geometry for rendering.
  184. * <ul>
  185. * <li><code>position3DHigh</code> - High 32 bits for encoded 64-bit position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  186. * <li><code>position3DLow</code> - Low 32 bits for encoded 64-bit position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  187. * <li><code>position3DHigh</code> - High 32 bits for encoded 64-bit 2D (Columbus view) position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  188. * <li><code>position2DLow</code> - Low 32 bits for encoded 64-bit 2D (Columbus view) position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  189. * <li><code>color</code> - RGBA color (normalized) usually from {@link GeometryInstance#color}. 32-bit floating-point. 4 components per attribute.</li>
  190. * <li><code>pickColor</code> - RGBA color used for picking. 32-bit floating-point. 4 components per attribute.</li>
  191. * </ul>
  192. * </p>
  193. *
  194. * @type GeometryAttributes
  195. *
  196. * @default undefined
  197. *
  198. *
  199. * @example
  200. * geometry.attributes.position = new Cesium.GeometryAttribute({
  201. * componentDatatype : Cesium.ComponentDatatype.FLOAT,
  202. * componentsPerAttribute : 3,
  203. * values : new Float32Array(0)
  204. * });
  205. *
  206. * @see GeometryAttribute
  207. * @see VertexFormat
  208. */
  209. this.attributes = options.attributes;
  210. /**
  211. * Optional index data that - along with {@link Geometry#primitiveType} -
  212. * determines the primitives in the geometry.
  213. *
  214. * @type Array
  215. *
  216. * @default undefined
  217. */
  218. this.indices = options.indices;
  219. /**
  220. * The type of primitives in the geometry. This is most often {@link PrimitiveType.TRIANGLES},
  221. * but can varying based on the specific geometry.
  222. *
  223. * @type PrimitiveType
  224. *
  225. * @default undefined
  226. */
  227. this.primitiveType = defaultValue.defaultValue(
  228. options.primitiveType,
  229. PrimitiveType$1.TRIANGLES
  230. );
  231. /**
  232. * An optional bounding sphere that fully encloses the geometry. This is
  233. * commonly used for culling.
  234. *
  235. * @type BoundingSphere
  236. *
  237. * @default undefined
  238. */
  239. this.boundingSphere = options.boundingSphere;
  240. /**
  241. * @private
  242. */
  243. this.geometryType = defaultValue.defaultValue(options.geometryType, GeometryType$1.NONE);
  244. /**
  245. * @private
  246. */
  247. this.boundingSphereCV = options.boundingSphereCV;
  248. /**
  249. * Used for computing the bounding sphere for geometry using the applyOffset vertex attribute
  250. * @private
  251. */
  252. this.offsetAttribute = options.offsetAttribute;
  253. }
  254. /**
  255. * Computes the number of vertices in a geometry. The runtime is linear with
  256. * respect to the number of attributes in a vertex, not the number of vertices.
  257. *
  258. * @param {Geometry} geometry The geometry.
  259. * @returns {Number} The number of vertices in the geometry.
  260. *
  261. * @example
  262. * const numVertices = Cesium.Geometry.computeNumberOfVertices(geometry);
  263. */
  264. Geometry.computeNumberOfVertices = function (geometry) {
  265. //>>includeStart('debug', pragmas.debug);
  266. RuntimeError.Check.typeOf.object("geometry", geometry);
  267. //>>includeEnd('debug');
  268. let numberOfVertices = -1;
  269. for (const property in geometry.attributes) {
  270. if (
  271. geometry.attributes.hasOwnProperty(property) &&
  272. defaultValue.defined(geometry.attributes[property]) &&
  273. defaultValue.defined(geometry.attributes[property].values)
  274. ) {
  275. const attribute = geometry.attributes[property];
  276. const num = attribute.values.length / attribute.componentsPerAttribute;
  277. //>>includeStart('debug', pragmas.debug);
  278. if (numberOfVertices !== num && numberOfVertices !== -1) {
  279. throw new RuntimeError.DeveloperError(
  280. "All attribute lists must have the same number of attributes."
  281. );
  282. }
  283. //>>includeEnd('debug');
  284. numberOfVertices = num;
  285. }
  286. }
  287. return numberOfVertices;
  288. };
  289. const rectangleCenterScratch = new Matrix2.Cartographic();
  290. const enuCenterScratch = new Matrix2.Cartesian3();
  291. const fixedFrameToEnuScratch = new Matrix2.Matrix4();
  292. const boundingRectanglePointsCartographicScratch = [
  293. new Matrix2.Cartographic(),
  294. new Matrix2.Cartographic(),
  295. new Matrix2.Cartographic(),
  296. ];
  297. const boundingRectanglePointsEnuScratch = [
  298. new Matrix2.Cartesian2(),
  299. new Matrix2.Cartesian2(),
  300. new Matrix2.Cartesian2(),
  301. ];
  302. const points2DScratch = [new Matrix2.Cartesian2(), new Matrix2.Cartesian2(), new Matrix2.Cartesian2()];
  303. const pointEnuScratch = new Matrix2.Cartesian3();
  304. const enuRotationScratch = new Transforms.Quaternion();
  305. const enuRotationMatrixScratch = new Matrix2.Matrix4();
  306. const rotation2DScratch = new Matrix2.Matrix2();
  307. /**
  308. * For remapping texture coordinates when rendering GroundPrimitives with materials.
  309. * GroundPrimitive texture coordinates are computed to align with the cartographic coordinate system on the globe.
  310. * However, EllipseGeometry, RectangleGeometry, and PolygonGeometry all bake rotations to per-vertex texture coordinates
  311. * using different strategies.
  312. *
  313. * This method is used by EllipseGeometry and PolygonGeometry to approximate the same visual effect.
  314. * We encapsulate rotation and scale by computing a "transformed" texture coordinate system and computing
  315. * a set of reference points from which "cartographic" texture coordinates can be remapped to the "transformed"
  316. * system using distances to lines in 2D.
  317. *
  318. * This approximation becomes less accurate as the covered area increases, especially for GroundPrimitives near the poles,
  319. * but is generally reasonable for polygons and ellipses around the size of USA states.
  320. *
  321. * RectangleGeometry has its own version of this method that computes remapping coordinates using cartographic space
  322. * as an intermediary instead of local ENU, which is more accurate for large-area rectangles.
  323. *
  324. * @param {Cartesian3[]} positions Array of positions outlining the geometry
  325. * @param {Number} stRotation Texture coordinate rotation.
  326. * @param {Ellipsoid} ellipsoid Ellipsoid for projecting and generating local vectors.
  327. * @param {Rectangle} boundingRectangle Bounding rectangle around the positions.
  328. * @returns {Number[]} An array of 6 numbers specifying [minimum point, u extent, v extent] as points in the "cartographic" system.
  329. * @private
  330. */
  331. Geometry._textureCoordinateRotationPoints = function (
  332. positions,
  333. stRotation,
  334. ellipsoid,
  335. boundingRectangle
  336. ) {
  337. let i;
  338. // Create a local east-north-up coordinate system centered on the polygon's bounding rectangle.
  339. // Project the southwest, northwest, and southeast corners of the bounding rectangle into the plane of ENU as 2D points.
  340. // These are the equivalents of (0,0), (0,1), and (1,0) in the texture coordiante system computed in ShadowVolumeAppearanceFS,
  341. // aka "ENU texture space."
  342. const rectangleCenter = Matrix2.Rectangle.center(
  343. boundingRectangle,
  344. rectangleCenterScratch
  345. );
  346. const enuCenter = Matrix2.Cartographic.toCartesian(
  347. rectangleCenter,
  348. ellipsoid,
  349. enuCenterScratch
  350. );
  351. const enuToFixedFrame = Transforms.Transforms.eastNorthUpToFixedFrame(
  352. enuCenter,
  353. ellipsoid,
  354. fixedFrameToEnuScratch
  355. );
  356. const fixedFrameToEnu = Matrix2.Matrix4.inverse(
  357. enuToFixedFrame,
  358. fixedFrameToEnuScratch
  359. );
  360. const boundingPointsEnu = boundingRectanglePointsEnuScratch;
  361. const boundingPointsCarto = boundingRectanglePointsCartographicScratch;
  362. boundingPointsCarto[0].longitude = boundingRectangle.west;
  363. boundingPointsCarto[0].latitude = boundingRectangle.south;
  364. boundingPointsCarto[1].longitude = boundingRectangle.west;
  365. boundingPointsCarto[1].latitude = boundingRectangle.north;
  366. boundingPointsCarto[2].longitude = boundingRectangle.east;
  367. boundingPointsCarto[2].latitude = boundingRectangle.south;
  368. let posEnu = pointEnuScratch;
  369. for (i = 0; i < 3; i++) {
  370. Matrix2.Cartographic.toCartesian(boundingPointsCarto[i], ellipsoid, posEnu);
  371. posEnu = Matrix2.Matrix4.multiplyByPointAsVector(fixedFrameToEnu, posEnu, posEnu);
  372. boundingPointsEnu[i].x = posEnu.x;
  373. boundingPointsEnu[i].y = posEnu.y;
  374. }
  375. // Rotate each point in the polygon around the up vector in the ENU by -stRotation and project into ENU as 2D.
  376. // Compute the bounding box of these rotated points in the 2D ENU plane.
  377. // Rotate the corners back by stRotation, then compute their equivalents in the ENU texture space using the corners computed earlier.
  378. const rotation = Transforms.Quaternion.fromAxisAngle(
  379. Matrix2.Cartesian3.UNIT_Z,
  380. -stRotation,
  381. enuRotationScratch
  382. );
  383. const textureMatrix = Matrix2.Matrix3.fromQuaternion(
  384. rotation,
  385. enuRotationMatrixScratch
  386. );
  387. const positionsLength = positions.length;
  388. let enuMinX = Number.POSITIVE_INFINITY;
  389. let enuMinY = Number.POSITIVE_INFINITY;
  390. let enuMaxX = Number.NEGATIVE_INFINITY;
  391. let enuMaxY = Number.NEGATIVE_INFINITY;
  392. for (i = 0; i < positionsLength; i++) {
  393. posEnu = Matrix2.Matrix4.multiplyByPointAsVector(
  394. fixedFrameToEnu,
  395. positions[i],
  396. posEnu
  397. );
  398. posEnu = Matrix2.Matrix3.multiplyByVector(textureMatrix, posEnu, posEnu);
  399. enuMinX = Math.min(enuMinX, posEnu.x);
  400. enuMinY = Math.min(enuMinY, posEnu.y);
  401. enuMaxX = Math.max(enuMaxX, posEnu.x);
  402. enuMaxY = Math.max(enuMaxY, posEnu.y);
  403. }
  404. const toDesiredInComputed = Matrix2.Matrix2.fromRotation(
  405. stRotation,
  406. rotation2DScratch
  407. );
  408. const points2D = points2DScratch;
  409. points2D[0].x = enuMinX;
  410. points2D[0].y = enuMinY;
  411. points2D[1].x = enuMinX;
  412. points2D[1].y = enuMaxY;
  413. points2D[2].x = enuMaxX;
  414. points2D[2].y = enuMinY;
  415. const boundingEnuMin = boundingPointsEnu[0];
  416. const boundingPointsWidth = boundingPointsEnu[2].x - boundingEnuMin.x;
  417. const boundingPointsHeight = boundingPointsEnu[1].y - boundingEnuMin.y;
  418. for (i = 0; i < 3; i++) {
  419. const point2D = points2D[i];
  420. // rotate back
  421. Matrix2.Matrix2.multiplyByVector(toDesiredInComputed, point2D, point2D);
  422. // Convert point into east-north texture coordinate space
  423. point2D.x = (point2D.x - boundingEnuMin.x) / boundingPointsWidth;
  424. point2D.y = (point2D.y - boundingEnuMin.y) / boundingPointsHeight;
  425. }
  426. const minXYCorner = points2D[0];
  427. const maxYCorner = points2D[1];
  428. const maxXCorner = points2D[2];
  429. const result = new Array(6);
  430. Matrix2.Cartesian2.pack(minXYCorner, result);
  431. Matrix2.Cartesian2.pack(maxYCorner, result, 2);
  432. Matrix2.Cartesian2.pack(maxXCorner, result, 4);
  433. return result;
  434. };
  435. /**
  436. * Values and type information for geometry attributes. A {@link Geometry}
  437. * generally contains one or more attributes. All attributes together form
  438. * the geometry's vertices.
  439. *
  440. * @alias GeometryAttribute
  441. * @constructor
  442. *
  443. * @param {Object} [options] Object with the following properties:
  444. * @param {ComponentDatatype} [options.componentDatatype] The datatype of each component in the attribute, e.g., individual elements in values.
  445. * @param {Number} [options.componentsPerAttribute] A number between 1 and 4 that defines the number of components in an attributes.
  446. * @param {Boolean} [options.normalize=false] When <code>true</code> and <code>componentDatatype</code> is an integer format, indicate that the components should be mapped to the range [0, 1] (unsigned) or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  447. * @param {number[]|Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} [options.values] The values for the attributes stored in a typed array.
  448. *
  449. * @exception {DeveloperError} options.componentsPerAttribute must be between 1 and 4.
  450. *
  451. *
  452. * @example
  453. * const geometry = new Cesium.Geometry({
  454. * attributes : {
  455. * position : new Cesium.GeometryAttribute({
  456. * componentDatatype : Cesium.ComponentDatatype.FLOAT,
  457. * componentsPerAttribute : 3,
  458. * values : new Float32Array([
  459. * 0.0, 0.0, 0.0,
  460. * 7500000.0, 0.0, 0.0,
  461. * 0.0, 7500000.0, 0.0
  462. * ])
  463. * })
  464. * },
  465. * primitiveType : Cesium.PrimitiveType.LINE_LOOP
  466. * });
  467. *
  468. * @see Geometry
  469. */
  470. function GeometryAttribute(options) {
  471. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  472. //>>includeStart('debug', pragmas.debug);
  473. if (!defaultValue.defined(options.componentDatatype)) {
  474. throw new RuntimeError.DeveloperError("options.componentDatatype is required.");
  475. }
  476. if (!defaultValue.defined(options.componentsPerAttribute)) {
  477. throw new RuntimeError.DeveloperError("options.componentsPerAttribute is required.");
  478. }
  479. if (
  480. options.componentsPerAttribute < 1 ||
  481. options.componentsPerAttribute > 4
  482. ) {
  483. throw new RuntimeError.DeveloperError(
  484. "options.componentsPerAttribute must be between 1 and 4."
  485. );
  486. }
  487. if (!defaultValue.defined(options.values)) {
  488. throw new RuntimeError.DeveloperError("options.values is required.");
  489. }
  490. //>>includeEnd('debug');
  491. /**
  492. * The datatype of each component in the attribute, e.g., individual elements in
  493. * {@link GeometryAttribute#values}.
  494. *
  495. * @type ComponentDatatype
  496. *
  497. * @default undefined
  498. */
  499. this.componentDatatype = options.componentDatatype;
  500. /**
  501. * A number between 1 and 4 that defines the number of components in an attributes.
  502. * For example, a position attribute with x, y, and z components would have 3 as
  503. * shown in the code example.
  504. *
  505. * @type Number
  506. *
  507. * @default undefined
  508. *
  509. * @example
  510. * attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
  511. * attribute.componentsPerAttribute = 3;
  512. * attribute.values = new Float32Array([
  513. * 0.0, 0.0, 0.0,
  514. * 7500000.0, 0.0, 0.0,
  515. * 0.0, 7500000.0, 0.0
  516. * ]);
  517. */
  518. this.componentsPerAttribute = options.componentsPerAttribute;
  519. /**
  520. * When <code>true</code> and <code>componentDatatype</code> is an integer format,
  521. * indicate that the components should be mapped to the range [0, 1] (unsigned)
  522. * or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  523. * <p>
  524. * This is commonly used when storing colors using {@link ComponentDatatype.UNSIGNED_BYTE}.
  525. * </p>
  526. *
  527. * @type Boolean
  528. *
  529. * @default false
  530. *
  531. * @example
  532. * attribute.componentDatatype = Cesium.ComponentDatatype.UNSIGNED_BYTE;
  533. * attribute.componentsPerAttribute = 4;
  534. * attribute.normalize = true;
  535. * attribute.values = new Uint8Array([
  536. * Cesium.Color.floatToByte(color.red),
  537. * Cesium.Color.floatToByte(color.green),
  538. * Cesium.Color.floatToByte(color.blue),
  539. * Cesium.Color.floatToByte(color.alpha)
  540. * ]);
  541. */
  542. this.normalize = defaultValue.defaultValue(options.normalize, false);
  543. /**
  544. * The values for the attributes stored in a typed array. In the code example,
  545. * every three elements in <code>values</code> defines one attributes since
  546. * <code>componentsPerAttribute</code> is 3.
  547. *
  548. * @type {number[]|Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array}
  549. *
  550. * @default undefined
  551. *
  552. * @example
  553. * attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
  554. * attribute.componentsPerAttribute = 3;
  555. * attribute.values = new Float32Array([
  556. * 0.0, 0.0, 0.0,
  557. * 7500000.0, 0.0, 0.0,
  558. * 0.0, 7500000.0, 0.0
  559. * ]);
  560. */
  561. this.values = options.values;
  562. }
  563. exports.Geometry = Geometry;
  564. exports.GeometryAttribute = GeometryAttribute;
  565. exports.GeometryType = GeometryType$1;
  566. exports.PrimitiveType = PrimitiveType$1;
  567. }));