GeometryAttribute-eeb38987.js 24 KB

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