createPolylineGeometry.js 27 KB

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