GeometryAttribute-9be2d2e5.js 24 KB

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