GeometryAttribute-a466e9c7.js 23 KB

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