createPolylineGeometry.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.97
  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(['./defaultValue-a6eb9f34', './Matrix2-ab676047', './ArcType-b714639b', './arrayRemoveDuplicates-63722a6f', './Transforms-c78c4637', './Color-a393f044', './ComponentDatatype-e06f4e16', './RuntimeError-1088cc64', './GeometryAttribute-4f02e2ad', './GeometryAttributes-aff51037', './IndexDatatype-c2232ebd', './PolylinePipeline-3b0ed402', './VertexFormat-65fd4be5', './_commonjsHelpers-89c9b271', './combine-7cf28d88', './WebGLConstants-d81b330d', './EllipsoidGeodesic-f7721517', './EllipsoidRhumbLine-34574f75', './IntersectionTests-f96cd46d', './Plane-c985a1d2'], (function (defaultValue, Matrix2, ArcType, arrayRemoveDuplicates, Transforms, Color, ComponentDatatype, RuntimeError, GeometryAttribute, GeometryAttributes, IndexDatatype, PolylinePipeline, VertexFormat, _commonjsHelpers, combine, WebGLConstants, EllipsoidGeodesic, EllipsoidRhumbLine, IntersectionTests, Plane) { 'use strict';
  26. const scratchInterpolateColorsArray = [];
  27. function interpolateColors(p0, p1, color0, color1, numPoints) {
  28. const colors = scratchInterpolateColorsArray;
  29. colors.length = numPoints;
  30. let i;
  31. const r0 = color0.red;
  32. const g0 = color0.green;
  33. const b0 = color0.blue;
  34. const a0 = color0.alpha;
  35. const r1 = color1.red;
  36. const g1 = color1.green;
  37. const b1 = color1.blue;
  38. const a1 = color1.alpha;
  39. if (Color.Color.equals(color0, color1)) {
  40. for (i = 0; i < numPoints; i++) {
  41. colors[i] = Color.Color.clone(color0);
  42. }
  43. return colors;
  44. }
  45. const redPerVertex = (r1 - r0) / numPoints;
  46. const greenPerVertex = (g1 - g0) / numPoints;
  47. const bluePerVertex = (b1 - b0) / numPoints;
  48. const alphaPerVertex = (a1 - a0) / numPoints;
  49. for (i = 0; i < numPoints; i++) {
  50. colors[i] = new Color.Color(
  51. r0 + i * redPerVertex,
  52. g0 + i * greenPerVertex,
  53. b0 + i * bluePerVertex,
  54. a0 + i * alphaPerVertex
  55. );
  56. }
  57. return colors;
  58. }
  59. /**
  60. * A description of a polyline modeled as a line strip; the first two positions define a line segment,
  61. * and each additional position defines a line segment from the previous position. The polyline is capable of
  62. * displaying with a material.
  63. *
  64. * @alias PolylineGeometry
  65. * @constructor
  66. *
  67. * @param {Object} options Object with the following properties:
  68. * @param {Cartesian3[]} options.positions An array of {@link Cartesian3} defining the positions in the polyline as a line strip.
  69. * @param {Number} [options.width=1.0] The width in pixels.
  70. * @param {Color[]} [options.colors] An Array of {@link Color} defining the per vertex or per segment colors.
  71. * @param {Boolean} [options.colorsPerVertex=false] A boolean that determines whether the colors will be flat across each segment of the line or interpolated across the vertices.
  72. * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of line the polyline segments must follow.
  73. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude if options.arcType is not ArcType.NONE. Determines the number of positions in the buffer.
  74. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  75. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
  76. *
  77. * @exception {DeveloperError} At least two positions are required.
  78. * @exception {DeveloperError} width must be greater than or equal to one.
  79. * @exception {DeveloperError} colors has an invalid length.
  80. *
  81. * @see PolylineGeometry#createGeometry
  82. *
  83. * @demo {@link https://sandcastle.cesium.com/index.html?src=Polyline.html|Cesium Sandcastle Polyline Demo}
  84. *
  85. * @example
  86. * // A polyline with two connected line segments
  87. * const polyline = new Cesium.PolylineGeometry({
  88. * positions : Cesium.Cartesian3.fromDegreesArray([
  89. * 0.0, 0.0,
  90. * 5.0, 0.0,
  91. * 5.0, 5.0
  92. * ]),
  93. * width : 10.0
  94. * });
  95. * const geometry = Cesium.PolylineGeometry.createGeometry(polyline);
  96. */
  97. function PolylineGeometry(options) {
  98. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  99. const positions = options.positions;
  100. const colors = options.colors;
  101. const width = defaultValue.defaultValue(options.width, 1.0);
  102. const colorsPerVertex = defaultValue.defaultValue(options.colorsPerVertex, false);
  103. //>>includeStart('debug', pragmas.debug);
  104. if (!defaultValue.defined(positions) || positions.length < 2) {
  105. throw new RuntimeError.DeveloperError("At least two positions are required.");
  106. }
  107. if (typeof width !== "number") {
  108. throw new RuntimeError.DeveloperError("width must be a number");
  109. }
  110. if (
  111. defaultValue.defined(colors) &&
  112. ((colorsPerVertex && colors.length < positions.length) ||
  113. (!colorsPerVertex && colors.length < positions.length - 1))
  114. ) {
  115. throw new RuntimeError.DeveloperError("colors has an invalid length.");
  116. }
  117. //>>includeEnd('debug');
  118. this._positions = positions;
  119. this._colors = colors;
  120. this._width = width;
  121. this._colorsPerVertex = colorsPerVertex;
  122. this._vertexFormat = VertexFormat.VertexFormat.clone(
  123. defaultValue.defaultValue(options.vertexFormat, VertexFormat.VertexFormat.DEFAULT)
  124. );
  125. this._arcType = defaultValue.defaultValue(options.arcType, ArcType.ArcType.GEODESIC);
  126. this._granularity = defaultValue.defaultValue(
  127. options.granularity,
  128. ComponentDatatype.CesiumMath.RADIANS_PER_DEGREE
  129. );
  130. this._ellipsoid = Matrix2.Ellipsoid.clone(
  131. defaultValue.defaultValue(options.ellipsoid, Matrix2.Ellipsoid.WGS84)
  132. );
  133. this._workerName = "createPolylineGeometry";
  134. let numComponents = 1 + positions.length * Matrix2.Cartesian3.packedLength;
  135. numComponents += defaultValue.defined(colors) ? 1 + colors.length * Color.Color.packedLength : 1;
  136. /**
  137. * The number of elements used to pack the object into an array.
  138. * @type {Number}
  139. */
  140. this.packedLength =
  141. numComponents + Matrix2.Ellipsoid.packedLength + VertexFormat.VertexFormat.packedLength + 4;
  142. }
  143. /**
  144. * Stores the provided instance into the provided array.
  145. *
  146. * @param {PolylineGeometry} value The value to pack.
  147. * @param {Number[]} array The array to pack into.
  148. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  149. *
  150. * @returns {Number[]} The array that was packed into
  151. */
  152. PolylineGeometry.pack = function (value, array, startingIndex) {
  153. //>>includeStart('debug', pragmas.debug);
  154. if (!defaultValue.defined(value)) {
  155. throw new RuntimeError.DeveloperError("value is required");
  156. }
  157. if (!defaultValue.defined(array)) {
  158. throw new RuntimeError.DeveloperError("array is required");
  159. }
  160. //>>includeEnd('debug');
  161. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  162. let i;
  163. const positions = value._positions;
  164. let length = positions.length;
  165. array[startingIndex++] = length;
  166. for (i = 0; i < length; ++i, startingIndex += Matrix2.Cartesian3.packedLength) {
  167. Matrix2.Cartesian3.pack(positions[i], array, startingIndex);
  168. }
  169. const colors = value._colors;
  170. length = defaultValue.defined(colors) ? colors.length : 0.0;
  171. array[startingIndex++] = length;
  172. for (i = 0; i < length; ++i, startingIndex += Color.Color.packedLength) {
  173. Color.Color.pack(colors[i], array, startingIndex);
  174. }
  175. Matrix2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  176. startingIndex += Matrix2.Ellipsoid.packedLength;
  177. VertexFormat.VertexFormat.pack(value._vertexFormat, array, startingIndex);
  178. startingIndex += VertexFormat.VertexFormat.packedLength;
  179. array[startingIndex++] = value._width;
  180. array[startingIndex++] = value._colorsPerVertex ? 1.0 : 0.0;
  181. array[startingIndex++] = value._arcType;
  182. array[startingIndex] = value._granularity;
  183. return array;
  184. };
  185. const scratchEllipsoid = Matrix2.Ellipsoid.clone(Matrix2.Ellipsoid.UNIT_SPHERE);
  186. const scratchVertexFormat = new VertexFormat.VertexFormat();
  187. const scratchOptions = {
  188. positions: undefined,
  189. colors: undefined,
  190. ellipsoid: scratchEllipsoid,
  191. vertexFormat: scratchVertexFormat,
  192. width: undefined,
  193. colorsPerVertex: undefined,
  194. arcType: undefined,
  195. granularity: undefined,
  196. };
  197. /**
  198. * Retrieves an instance from a packed array.
  199. *
  200. * @param {Number[]} array The packed array.
  201. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  202. * @param {PolylineGeometry} [result] The object into which to store the result.
  203. * @returns {PolylineGeometry} The modified result parameter or a new PolylineGeometry instance if one was not provided.
  204. */
  205. PolylineGeometry.unpack = function (array, startingIndex, result) {
  206. //>>includeStart('debug', pragmas.debug);
  207. if (!defaultValue.defined(array)) {
  208. throw new RuntimeError.DeveloperError("array is required");
  209. }
  210. //>>includeEnd('debug');
  211. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  212. let i;
  213. let length = array[startingIndex++];
  214. const positions = new Array(length);
  215. for (i = 0; i < length; ++i, startingIndex += Matrix2.Cartesian3.packedLength) {
  216. positions[i] = Matrix2.Cartesian3.unpack(array, startingIndex);
  217. }
  218. length = array[startingIndex++];
  219. const colors = length > 0 ? new Array(length) : undefined;
  220. for (i = 0; i < length; ++i, startingIndex += Color.Color.packedLength) {
  221. colors[i] = Color.Color.unpack(array, startingIndex);
  222. }
  223. const ellipsoid = Matrix2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  224. startingIndex += Matrix2.Ellipsoid.packedLength;
  225. const vertexFormat = VertexFormat.VertexFormat.unpack(
  226. array,
  227. startingIndex,
  228. scratchVertexFormat
  229. );
  230. startingIndex += VertexFormat.VertexFormat.packedLength;
  231. const width = array[startingIndex++];
  232. const colorsPerVertex = array[startingIndex++] === 1.0;
  233. const arcType = array[startingIndex++];
  234. const granularity = array[startingIndex];
  235. if (!defaultValue.defined(result)) {
  236. scratchOptions.positions = positions;
  237. scratchOptions.colors = colors;
  238. scratchOptions.width = width;
  239. scratchOptions.colorsPerVertex = colorsPerVertex;
  240. scratchOptions.arcType = arcType;
  241. scratchOptions.granularity = granularity;
  242. return new PolylineGeometry(scratchOptions);
  243. }
  244. result._positions = positions;
  245. result._colors = colors;
  246. result._ellipsoid = Matrix2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  247. result._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat, result._vertexFormat);
  248. result._width = width;
  249. result._colorsPerVertex = colorsPerVertex;
  250. result._arcType = arcType;
  251. result._granularity = granularity;
  252. return result;
  253. };
  254. const scratchCartesian3 = new Matrix2.Cartesian3();
  255. const scratchPosition = new Matrix2.Cartesian3();
  256. const scratchPrevPosition = new Matrix2.Cartesian3();
  257. const scratchNextPosition = new Matrix2.Cartesian3();
  258. /**
  259. * Computes the geometric representation of a polyline, including its vertices, indices, and a bounding sphere.
  260. *
  261. * @param {PolylineGeometry} polylineGeometry A description of the polyline.
  262. * @returns {Geometry|undefined} The computed vertices and indices.
  263. */
  264. PolylineGeometry.createGeometry = function (polylineGeometry) {
  265. const width = polylineGeometry._width;
  266. const vertexFormat = polylineGeometry._vertexFormat;
  267. let colors = polylineGeometry._colors;
  268. const colorsPerVertex = polylineGeometry._colorsPerVertex;
  269. const arcType = polylineGeometry._arcType;
  270. const granularity = polylineGeometry._granularity;
  271. const ellipsoid = polylineGeometry._ellipsoid;
  272. let i;
  273. let j;
  274. let k;
  275. const removedIndices = [];
  276. let positions = arrayRemoveDuplicates.arrayRemoveDuplicates(
  277. polylineGeometry._positions,
  278. Matrix2.Cartesian3.equalsEpsilon,
  279. false,
  280. removedIndices
  281. );
  282. if (defaultValue.defined(colors) && removedIndices.length > 0) {
  283. let removedArrayIndex = 0;
  284. let nextRemovedIndex = removedIndices[0];
  285. colors = colors.filter(function (color, index) {
  286. let remove = false;
  287. if (colorsPerVertex) {
  288. remove =
  289. index === nextRemovedIndex || (index === 0 && nextRemovedIndex === 1);
  290. } else {
  291. remove = index + 1 === nextRemovedIndex;
  292. }
  293. if (remove) {
  294. removedArrayIndex++;
  295. nextRemovedIndex = removedIndices[removedArrayIndex];
  296. return false;
  297. }
  298. return true;
  299. });
  300. }
  301. let positionsLength = positions.length;
  302. // A width of a pixel or less is not a valid geometry, but in order to support external data
  303. // that may have errors we treat this as an empty geometry.
  304. if (positionsLength < 2 || width <= 0.0) {
  305. return undefined;
  306. }
  307. if (arcType === ArcType.ArcType.GEODESIC || arcType === ArcType.ArcType.RHUMB) {
  308. let subdivisionSize;
  309. let numberOfPointsFunction;
  310. if (arcType === ArcType.ArcType.GEODESIC) {
  311. subdivisionSize = ComponentDatatype.CesiumMath.chordLength(
  312. granularity,
  313. ellipsoid.maximumRadius
  314. );
  315. numberOfPointsFunction = PolylinePipeline.PolylinePipeline.numberOfPoints;
  316. } else {
  317. subdivisionSize = granularity;
  318. numberOfPointsFunction = PolylinePipeline.PolylinePipeline.numberOfPointsRhumbLine;
  319. }
  320. const heights = PolylinePipeline.PolylinePipeline.extractHeights(positions, ellipsoid);
  321. if (defaultValue.defined(colors)) {
  322. let colorLength = 1;
  323. for (i = 0; i < positionsLength - 1; ++i) {
  324. colorLength += numberOfPointsFunction(
  325. positions[i],
  326. positions[i + 1],
  327. subdivisionSize
  328. );
  329. }
  330. const newColors = new Array(colorLength);
  331. let newColorIndex = 0;
  332. for (i = 0; i < positionsLength - 1; ++i) {
  333. const p0 = positions[i];
  334. const p1 = positions[i + 1];
  335. const c0 = colors[i];
  336. const numColors = numberOfPointsFunction(p0, p1, subdivisionSize);
  337. if (colorsPerVertex && i < colorLength) {
  338. const c1 = colors[i + 1];
  339. const interpolatedColors = interpolateColors(
  340. p0,
  341. p1,
  342. c0,
  343. c1,
  344. numColors
  345. );
  346. const interpolatedColorsLength = interpolatedColors.length;
  347. for (j = 0; j < interpolatedColorsLength; ++j) {
  348. newColors[newColorIndex++] = interpolatedColors[j];
  349. }
  350. } else {
  351. for (j = 0; j < numColors; ++j) {
  352. newColors[newColorIndex++] = Color.Color.clone(c0);
  353. }
  354. }
  355. }
  356. newColors[newColorIndex] = Color.Color.clone(colors[colors.length - 1]);
  357. colors = newColors;
  358. scratchInterpolateColorsArray.length = 0;
  359. }
  360. if (arcType === ArcType.ArcType.GEODESIC) {
  361. positions = PolylinePipeline.PolylinePipeline.generateCartesianArc({
  362. positions: positions,
  363. minDistance: subdivisionSize,
  364. ellipsoid: ellipsoid,
  365. height: heights,
  366. });
  367. } else {
  368. positions = PolylinePipeline.PolylinePipeline.generateCartesianRhumbArc({
  369. positions: positions,
  370. granularity: subdivisionSize,
  371. ellipsoid: ellipsoid,
  372. height: heights,
  373. });
  374. }
  375. }
  376. positionsLength = positions.length;
  377. const size = positionsLength * 4.0 - 4.0;
  378. const finalPositions = new Float64Array(size * 3);
  379. const prevPositions = new Float64Array(size * 3);
  380. const nextPositions = new Float64Array(size * 3);
  381. const expandAndWidth = new Float32Array(size * 2);
  382. const st = vertexFormat.st ? new Float32Array(size * 2) : undefined;
  383. const finalColors = defaultValue.defined(colors) ? new Uint8Array(size * 4) : undefined;
  384. let positionIndex = 0;
  385. let expandAndWidthIndex = 0;
  386. let stIndex = 0;
  387. let colorIndex = 0;
  388. let position;
  389. for (j = 0; j < positionsLength; ++j) {
  390. if (j === 0) {
  391. position = scratchCartesian3;
  392. Matrix2.Cartesian3.subtract(positions[0], positions[1], position);
  393. Matrix2.Cartesian3.add(positions[0], position, position);
  394. } else {
  395. position = positions[j - 1];
  396. }
  397. Matrix2.Cartesian3.clone(position, scratchPrevPosition);
  398. Matrix2.Cartesian3.clone(positions[j], scratchPosition);
  399. if (j === positionsLength - 1) {
  400. position = scratchCartesian3;
  401. Matrix2.Cartesian3.subtract(
  402. positions[positionsLength - 1],
  403. positions[positionsLength - 2],
  404. position
  405. );
  406. Matrix2.Cartesian3.add(positions[positionsLength - 1], position, position);
  407. } else {
  408. position = positions[j + 1];
  409. }
  410. Matrix2.Cartesian3.clone(position, scratchNextPosition);
  411. let color0, color1;
  412. if (defaultValue.defined(finalColors)) {
  413. if (j !== 0 && !colorsPerVertex) {
  414. color0 = colors[j - 1];
  415. } else {
  416. color0 = colors[j];
  417. }
  418. if (j !== positionsLength - 1) {
  419. color1 = colors[j];
  420. }
  421. }
  422. const startK = j === 0 ? 2 : 0;
  423. const endK = j === positionsLength - 1 ? 2 : 4;
  424. for (k = startK; k < endK; ++k) {
  425. Matrix2.Cartesian3.pack(scratchPosition, finalPositions, positionIndex);
  426. Matrix2.Cartesian3.pack(scratchPrevPosition, prevPositions, positionIndex);
  427. Matrix2.Cartesian3.pack(scratchNextPosition, nextPositions, positionIndex);
  428. positionIndex += 3;
  429. const direction = k - 2 < 0 ? -1.0 : 1.0;
  430. expandAndWidth[expandAndWidthIndex++] = 2 * (k % 2) - 1; // expand direction
  431. expandAndWidth[expandAndWidthIndex++] = direction * width;
  432. if (vertexFormat.st) {
  433. st[stIndex++] = j / (positionsLength - 1);
  434. st[stIndex++] = Math.max(expandAndWidth[expandAndWidthIndex - 2], 0.0);
  435. }
  436. if (defaultValue.defined(finalColors)) {
  437. const color = k < 2 ? color0 : color1;
  438. finalColors[colorIndex++] = Color.Color.floatToByte(color.red);
  439. finalColors[colorIndex++] = Color.Color.floatToByte(color.green);
  440. finalColors[colorIndex++] = Color.Color.floatToByte(color.blue);
  441. finalColors[colorIndex++] = Color.Color.floatToByte(color.alpha);
  442. }
  443. }
  444. }
  445. const attributes = new GeometryAttributes.GeometryAttributes();
  446. attributes.position = new GeometryAttribute.GeometryAttribute({
  447. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  448. componentsPerAttribute: 3,
  449. values: finalPositions,
  450. });
  451. attributes.prevPosition = new GeometryAttribute.GeometryAttribute({
  452. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  453. componentsPerAttribute: 3,
  454. values: prevPositions,
  455. });
  456. attributes.nextPosition = new GeometryAttribute.GeometryAttribute({
  457. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  458. componentsPerAttribute: 3,
  459. values: nextPositions,
  460. });
  461. attributes.expandAndWidth = new GeometryAttribute.GeometryAttribute({
  462. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  463. componentsPerAttribute: 2,
  464. values: expandAndWidth,
  465. });
  466. if (vertexFormat.st) {
  467. attributes.st = new GeometryAttribute.GeometryAttribute({
  468. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  469. componentsPerAttribute: 2,
  470. values: st,
  471. });
  472. }
  473. if (defaultValue.defined(finalColors)) {
  474. attributes.color = new GeometryAttribute.GeometryAttribute({
  475. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  476. componentsPerAttribute: 4,
  477. values: finalColors,
  478. normalize: true,
  479. });
  480. }
  481. const indices = IndexDatatype.IndexDatatype.createTypedArray(size, positionsLength * 6 - 6);
  482. let index = 0;
  483. let indicesIndex = 0;
  484. const length = positionsLength - 1.0;
  485. for (j = 0; j < length; ++j) {
  486. indices[indicesIndex++] = index;
  487. indices[indicesIndex++] = index + 2;
  488. indices[indicesIndex++] = index + 1;
  489. indices[indicesIndex++] = index + 1;
  490. indices[indicesIndex++] = index + 2;
  491. indices[indicesIndex++] = index + 3;
  492. index += 4;
  493. }
  494. return new GeometryAttribute.Geometry({
  495. attributes: attributes,
  496. indices: indices,
  497. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  498. boundingSphere: Transforms.BoundingSphere.fromPoints(positions),
  499. geometryType: GeometryAttribute.GeometryType.POLYLINES,
  500. });
  501. };
  502. function createPolylineGeometry(polylineGeometry, offset) {
  503. if (defaultValue.defined(offset)) {
  504. polylineGeometry = PolylineGeometry.unpack(polylineGeometry, offset);
  505. }
  506. polylineGeometry._ellipsoid = Matrix2.Ellipsoid.clone(polylineGeometry._ellipsoid);
  507. return PolylineGeometry.createGeometry(polylineGeometry);
  508. }
  509. return createPolylineGeometry;
  510. }));