createPolylineGeometry.js 22 KB

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