Migrate Cesium to ES6 Modules
See https://github.com/AnalyticalGraphicsInc/cesium/pull/8224 for details.
eslint
There are a handful of new .eslintrc.json files, mostly to identify the files that are still AMD modules (Sandcastle/Workers). These are needed because you can't change the parser type with a comment directive (since the parser is the thing reading the file). We can finally detect unusued modules! So those have all been cleaned up as well.
requirejs -> rollup & clean-css
requirejs, almond, and karma-requirejs have all been removed. We now use rollup for building and minifying (via uglify) JS code and clean-css for css. These changes are fairly straight-forward and just involve calling rollup instead of requirejs in the build process.
Overall build time is significantly faster. CI is ~11 minutes compared to ~17 in master. Running makeZipFile on my machine takes 69 seconds compared to 112 seconds in master. There's probably plenty of room for additional optimization here too.
We wrote an published a small npm module, rollup-plugin-strip-pragma, for stripping the requirejs pragmas we use out of the release builds. This is maintained in the Tools/rollup-plugin-strip-pragma directory.
As for what we produce. The built version of Cesium is now a UMD module. So it should work anywhere that hasn't made the jump to ES6 yet. For users that were already using the "legacy" combined/minified approach, nothing changes.
One awesome thing about roll-up is that it compiles all of the workers at once and automatically detects shared codes and generates separate bundles under the hood. This means the size of our worker modules shrink dramatically and Cesium itself will load them much faster. The total minified/gzipped size of all workers in master is 2.6 MB compared to 225 KB in this branch! This should be most noticeable on demos like Geometry & Appearances which load lots of workers for the various geometry typs.
roll-up is also used to build Cesium Viewer, which is now an ES6 app.
We use clean-css via gulp and it is also a straightforward change from requirejs that requires no special mention.
Workers
While the spec allows for ES6 Web Workers, no browser actually supports them yet. That means we needed a way to get our workers into non-ES6 form. Thankfully, roll-up can generate AMD modules, which means we now have a build step to compile our Worker source code back into AMD and use the existing TaskProcessor to load and execute them. This build step is part of the standard build task and is called createWorkers. During development, these "built" workers are un-optimized so you can still debug them and read the code.
Since there is a build step, that means if you are changing code that affects a worker, you need to re-run build, or you can use the build-watch task to do it automatically.
The ES6 versions of Worker code has moved into Source/WorkersES6 and we build the workers into their "old home" of Source/Workers. cesiumWorkerBootstrapper and transferTypedArrayTest which were already non-AMD ES5 scripts remain living in the Workers directory.
Surprisingly little was changed about TaskProcessor or the worker system in general, especially considering that I thought this would be one of the major hurdles.
ThirdParty
A lot of our ThirdParty either already had a hand-written wrapper for AMD (which I updated to ES6) or had UMD which created problems when importing the same code in both Node and the browser. I basically had to update the wrapper of every third-party library to fix these problems. In some cases I updated the library version itself (Autolinker, topojson). Nothing to be too concerned about, but future clean-up would be using npm versions of these libraries and auto-generating the wrappers as needed so we don't hand-edit things.
Sandcastle
Sandcastle is eternal and manages to live another day in it's ancient requirejs/dojo 1.x form. Sandcastle now automatically uses the ES6 version of Cesium if it is available and fallsback to the ES5 unminified version if it is now. The built version of Sandcastle always uses CesiumUnminified, just like master. This means Sandcastle still works in IE11 if you run the combine step first (or use the relase zip)
Removed Cesium usage from Sandcastle proper, since it wasn't really needed
Generate a VERSION propertyin the gallery index since Cesium is no longer being included.
Remove requirejs from Sandcastle bucket
Update bucket to use the built version of Cesium if it is available by fallbackto the ES6 version during development.
Standalone.html was also updated
There's a bit of room for further clean-up here, but I think this gets us into master. I did not rename bucket-requirejs.html because I'm pretty sure it would break previously shared demos. We can put in some backwards compatible code later on if we want. (But I'd rather just see a full Sandcastle rewrite).
Specs
Specs are now all ES6, except for TestWorkers, which remain standard JS worker modules. This means you can no longer run the unbuilt unit tests in IE11. No changes for Chrome and Firefox.
Since the specs use ES6 modules and built Cesium is an ES5 UMD, I added a build-specs build step which generates a combined ES5 version of the specs which rely on Cesium as a global variable. We then inject these files into jasmine instead of the standard specs and everything works exactly as it did before. SpecRunner.html has been updated to inject the correct version of the script depending on the build/release query parameters.
The Specs must always use Cesium by importing Source/Cesium.js, this is so we can replace it with the built Cesium as describe above.
There's a bunch of room for clean-up here, such as unifying our two copies of jasmine into a single helper file, but I didn't want to start doing that clean-up as part of this already overly big PR. The important thing is that we can still test the built version and still test on IE/Edge as needed.
I also found and fixed two bugs that were causing failing unit tests, one in BingMapsImageryProviderSpec.js (which was overwriting createImage andnot setting it back) and ShadowVolumeAppearance.js (which had a module level caching bug). I think these may have been the cause of random CI failures in master as well, but only time will tell.
For coverage, we had to switch to karma-coverage-istanbul-instrumenter for native ES6 support, but that's it.
Finally, I updated appveryor to build Cesium and run the built tests under IE. We still don't fail the build for IE, but we should probably fix that if we want to keep it going.
NodeJS
When NODE_ENV is production, we now require in the minified CesiumJS directly, which works great because it's now a UMD module. Otherwise, we use the excellant esmpackage to load individual modules, it was a fairly straightforward swap from our old requirejs usage. We could probably drop esm too if we don't care about debugging or if we provie source maps at some point.
2019-10-03 23:51:23 +08:00
|
|
|
import ArcType from "./ArcType.js";
|
|
|
|
|
import arrayRemoveDuplicates from "./arrayRemoveDuplicates.js";
|
|
|
|
|
import BoundingSphere from "./BoundingSphere.js";
|
|
|
|
|
import Cartesian3 from "./Cartesian3.js";
|
|
|
|
|
import Color from "./Color.js";
|
|
|
|
|
import ComponentDatatype from "./ComponentDatatype.js";
|
2025-03-12 05:50:04 +08:00
|
|
|
import Frozen from "./Frozen.js";
|
Migrate Cesium to ES6 Modules
See https://github.com/AnalyticalGraphicsInc/cesium/pull/8224 for details.
eslint
There are a handful of new .eslintrc.json files, mostly to identify the files that are still AMD modules (Sandcastle/Workers). These are needed because you can't change the parser type with a comment directive (since the parser is the thing reading the file). We can finally detect unusued modules! So those have all been cleaned up as well.
requirejs -> rollup & clean-css
requirejs, almond, and karma-requirejs have all been removed. We now use rollup for building and minifying (via uglify) JS code and clean-css for css. These changes are fairly straight-forward and just involve calling rollup instead of requirejs in the build process.
Overall build time is significantly faster. CI is ~11 minutes compared to ~17 in master. Running makeZipFile on my machine takes 69 seconds compared to 112 seconds in master. There's probably plenty of room for additional optimization here too.
We wrote an published a small npm module, rollup-plugin-strip-pragma, for stripping the requirejs pragmas we use out of the release builds. This is maintained in the Tools/rollup-plugin-strip-pragma directory.
As for what we produce. The built version of Cesium is now a UMD module. So it should work anywhere that hasn't made the jump to ES6 yet. For users that were already using the "legacy" combined/minified approach, nothing changes.
One awesome thing about roll-up is that it compiles all of the workers at once and automatically detects shared codes and generates separate bundles under the hood. This means the size of our worker modules shrink dramatically and Cesium itself will load them much faster. The total minified/gzipped size of all workers in master is 2.6 MB compared to 225 KB in this branch! This should be most noticeable on demos like Geometry & Appearances which load lots of workers for the various geometry typs.
roll-up is also used to build Cesium Viewer, which is now an ES6 app.
We use clean-css via gulp and it is also a straightforward change from requirejs that requires no special mention.
Workers
While the spec allows for ES6 Web Workers, no browser actually supports them yet. That means we needed a way to get our workers into non-ES6 form. Thankfully, roll-up can generate AMD modules, which means we now have a build step to compile our Worker source code back into AMD and use the existing TaskProcessor to load and execute them. This build step is part of the standard build task and is called createWorkers. During development, these "built" workers are un-optimized so you can still debug them and read the code.
Since there is a build step, that means if you are changing code that affects a worker, you need to re-run build, or you can use the build-watch task to do it automatically.
The ES6 versions of Worker code has moved into Source/WorkersES6 and we build the workers into their "old home" of Source/Workers. cesiumWorkerBootstrapper and transferTypedArrayTest which were already non-AMD ES5 scripts remain living in the Workers directory.
Surprisingly little was changed about TaskProcessor or the worker system in general, especially considering that I thought this would be one of the major hurdles.
ThirdParty
A lot of our ThirdParty either already had a hand-written wrapper for AMD (which I updated to ES6) or had UMD which created problems when importing the same code in both Node and the browser. I basically had to update the wrapper of every third-party library to fix these problems. In some cases I updated the library version itself (Autolinker, topojson). Nothing to be too concerned about, but future clean-up would be using npm versions of these libraries and auto-generating the wrappers as needed so we don't hand-edit things.
Sandcastle
Sandcastle is eternal and manages to live another day in it's ancient requirejs/dojo 1.x form. Sandcastle now automatically uses the ES6 version of Cesium if it is available and fallsback to the ES5 unminified version if it is now. The built version of Sandcastle always uses CesiumUnminified, just like master. This means Sandcastle still works in IE11 if you run the combine step first (or use the relase zip)
Removed Cesium usage from Sandcastle proper, since it wasn't really needed
Generate a VERSION propertyin the gallery index since Cesium is no longer being included.
Remove requirejs from Sandcastle bucket
Update bucket to use the built version of Cesium if it is available by fallbackto the ES6 version during development.
Standalone.html was also updated
There's a bit of room for further clean-up here, but I think this gets us into master. I did not rename bucket-requirejs.html because I'm pretty sure it would break previously shared demos. We can put in some backwards compatible code later on if we want. (But I'd rather just see a full Sandcastle rewrite).
Specs
Specs are now all ES6, except for TestWorkers, which remain standard JS worker modules. This means you can no longer run the unbuilt unit tests in IE11. No changes for Chrome and Firefox.
Since the specs use ES6 modules and built Cesium is an ES5 UMD, I added a build-specs build step which generates a combined ES5 version of the specs which rely on Cesium as a global variable. We then inject these files into jasmine instead of the standard specs and everything works exactly as it did before. SpecRunner.html has been updated to inject the correct version of the script depending on the build/release query parameters.
The Specs must always use Cesium by importing Source/Cesium.js, this is so we can replace it with the built Cesium as describe above.
There's a bunch of room for clean-up here, such as unifying our two copies of jasmine into a single helper file, but I didn't want to start doing that clean-up as part of this already overly big PR. The important thing is that we can still test the built version and still test on IE/Edge as needed.
I also found and fixed two bugs that were causing failing unit tests, one in BingMapsImageryProviderSpec.js (which was overwriting createImage andnot setting it back) and ShadowVolumeAppearance.js (which had a module level caching bug). I think these may have been the cause of random CI failures in master as well, but only time will tell.
For coverage, we had to switch to karma-coverage-istanbul-instrumenter for native ES6 support, but that's it.
Finally, I updated appveryor to build Cesium and run the built tests under IE. We still don't fail the build for IE, but we should probably fix that if we want to keep it going.
NodeJS
When NODE_ENV is production, we now require in the minified CesiumJS directly, which works great because it's now a UMD module. Otherwise, we use the excellant esmpackage to load individual modules, it was a fairly straightforward swap from our old requirejs usage. We could probably drop esm too if we don't care about debugging or if we provie source maps at some point.
2019-10-03 23:51:23 +08:00
|
|
|
import defined from "./defined.js";
|
|
|
|
|
import DeveloperError from "./DeveloperError.js";
|
|
|
|
|
import Ellipsoid from "./Ellipsoid.js";
|
|
|
|
|
import Geometry from "./Geometry.js";
|
|
|
|
|
import GeometryAttribute from "./GeometryAttribute.js";
|
|
|
|
|
import GeometryAttributes from "./GeometryAttributes.js";
|
|
|
|
|
import GeometryType from "./GeometryType.js";
|
|
|
|
|
import IndexDatatype from "./IndexDatatype.js";
|
|
|
|
|
import CesiumMath from "./Math.js";
|
|
|
|
|
import PolylinePipeline from "./PolylinePipeline.js";
|
|
|
|
|
import PrimitiveType from "./PrimitiveType.js";
|
|
|
|
|
import VertexFormat from "./VertexFormat.js";
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-18 05:29:56 +08:00
|
|
|
const scratchInterpolateColorsArray = [];
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-18 05:29:56 +08:00
|
|
|
function interpolateColors(p0, p1, color0, color1, numPoints) {
|
|
|
|
|
const colors = scratchInterpolateColorsArray;
|
|
|
|
|
colors.length = numPoints;
|
2014-07-09 03:03:52 +08:00
|
|
|
let i;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-07-09 03:03:52 +08:00
|
|
|
const r0 = color0.red;
|
|
|
|
|
const g0 = color0.green;
|
|
|
|
|
const b0 = color0.blue;
|
|
|
|
|
const a0 = color0.alpha;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-07-09 03:03:52 +08:00
|
|
|
const r1 = color1.red;
|
|
|
|
|
const g1 = color1.green;
|
|
|
|
|
const b1 = color1.blue;
|
|
|
|
|
const a1 = color1.alpha;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-07-09 03:03:52 +08:00
|
|
|
if (Color.equals(color0, color1)) {
|
|
|
|
|
for (i = 0; i < numPoints; i++) {
|
|
|
|
|
colors[i] = Color.clone(color0);
|
|
|
|
|
}
|
|
|
|
|
return colors;
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2014-07-09 03:03:52 +08:00
|
|
|
const redPerVertex = (r1 - r0) / numPoints;
|
|
|
|
|
const greenPerVertex = (g1 - g0) / numPoints;
|
|
|
|
|
const bluePerVertex = (b1 - b0) / numPoints;
|
|
|
|
|
const alphaPerVertex = (a1 - a0) / numPoints;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-07-09 03:03:52 +08:00
|
|
|
for (i = 0; i < numPoints; i++) {
|
|
|
|
|
colors[i] = new Color(
|
|
|
|
|
r0 + i * redPerVertex,
|
|
|
|
|
g0 + i * greenPerVertex,
|
|
|
|
|
b0 + i * bluePerVertex,
|
|
|
|
|
a0 + i * alphaPerVertex,
|
2020-04-17 08:31:36 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 03:03:52 +08:00
|
|
|
return colors;
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
/**
|
2013-09-05 02:14:53 +08:00
|
|
|
* A description of a polyline modeled as a line strip; the first two positions define a line segment,
|
|
|
|
|
* and each additional position defines a line segment from the previous position. The polyline is capable of
|
|
|
|
|
* displaying with a material.
|
|
|
|
|
*
|
|
|
|
|
* @alias PolylineGeometry
|
|
|
|
|
* @constructor
|
|
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {object} options Object with the following properties:
|
2014-05-21 23:07:34 +08:00
|
|
|
* @param {Cartesian3[]} options.positions An array of {@link Cartesian3} defining the positions in the polyline as a line strip.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number} [options.width=1.0] The width in pixels.
|
2014-05-22 01:05:58 +08:00
|
|
|
* @param {Color[]} [options.colors] An Array of {@link Color} defining the per vertex or per segment colors.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @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.
|
2019-01-24 10:38:25 +08:00
|
|
|
* @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of line the polyline segments must follow.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @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.
|
2016-04-12 04:02:02 +08:00
|
|
|
* @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
|
2024-05-20 22:19:14 +08:00
|
|
|
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.default] The ellipsoid to be used as a reference.
|
2013-09-05 02:14:53 +08:00
|
|
|
*
|
|
|
|
|
* @exception {DeveloperError} At least two positions are required.
|
2013-09-07 02:58:30 +08:00
|
|
|
* @exception {DeveloperError} width must be greater than or equal to one.
|
2013-09-05 02:14:53 +08:00
|
|
|
* @exception {DeveloperError} colors has an invalid length.
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2015-08-05 06:17:24 +08:00
|
|
|
* @see PolylineGeometry#createGeometry
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2013-09-07 08:09:23 +08:00
|
|
|
* @demo {@link https://sandcastle.cesium.com/index.html?src=Polyline.html|Cesium Sandcastle Polyline Demo}
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2013-09-07 08:09:23 +08:00
|
|
|
* @example
|
2013-09-05 02:14:53 +08:00
|
|
|
* // A polyline with two connected line segments
|
2022-01-29 00:32:07 +08:00
|
|
|
* const polyline = new Cesium.PolylineGeometry({
|
2013-09-07 08:09:23 +08:00
|
|
|
* positions : Cesium.Cartesian3.fromDegreesArray([
|
2014-05-14 05:41:52 +08:00
|
|
|
* 0.0, 0.0,
|
|
|
|
|
* 5.0, 0.0,
|
|
|
|
|
* 5.0, 5.0
|
2020-04-17 08:31:36 +08:00
|
|
|
* ]),
|
|
|
|
|
* width : 10.0
|
|
|
|
|
* });
|
2022-01-29 00:32:07 +08:00
|
|
|
* const geometry = Cesium.PolylineGeometry.createGeometry(polyline);
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2013-09-07 08:09:23 +08:00
|
|
|
function PolylineGeometry(options) {
|
2025-03-12 05:50:04 +08:00
|
|
|
options = options ?? Frozen.EMPTY_OBJECT;
|
2013-09-04 07:06:16 +08:00
|
|
|
const positions = options.positions;
|
2013-09-07 08:09:23 +08:00
|
|
|
const colors = options.colors;
|
2025-03-04 03:03:53 +08:00
|
|
|
const width = options.width ?? 1.0;
|
|
|
|
|
const colorsPerVertex = options.colorsPerVertex ?? false;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2013-09-04 07:06:16 +08:00
|
|
|
if (!defined(positions) || positions.length < 2) {
|
2014-12-19 09:44:13 +08:00
|
|
|
throw new DeveloperError("At least two positions are required.");
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2016-11-01 17:29:09 +08:00
|
|
|
if (typeof width !== "number") {
|
|
|
|
|
throw new DeveloperError("width must be a number");
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
if (
|
2014-12-23 08:57:38 +08:00
|
|
|
defined(colors) &&
|
2019-01-15 03:27:05 +08:00
|
|
|
((colorsPerVertex && colors.length < positions.length) ||
|
2015-03-02 12:26:29 +08:00
|
|
|
(!colorsPerVertex && colors.length < positions.length - 1))
|
2020-04-17 08:31:36 +08:00
|
|
|
) {
|
2013-09-07 08:09:23 +08:00
|
|
|
throw new DeveloperError("colors has an invalid length.");
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2013-09-05 02:14:53 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-09-05 02:14:53 +08:00
|
|
|
this._positions = positions;
|
2014-12-19 09:44:13 +08:00
|
|
|
this._colors = colors;
|
|
|
|
|
this._width = width;
|
2015-03-02 12:26:29 +08:00
|
|
|
this._colorsPerVertex = colorsPerVertex;
|
2015-01-01 06:57:11 +08:00
|
|
|
this._vertexFormat = VertexFormat.clone(
|
2025-03-04 03:03:53 +08:00
|
|
|
options.vertexFormat ?? VertexFormat.DEFAULT,
|
2020-04-17 08:31:36 +08:00
|
|
|
);
|
|
|
|
|
|
2025-03-04 03:03:53 +08:00
|
|
|
this._arcType = options.arcType ?? ArcType.GEODESIC;
|
|
|
|
|
this._granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE;
|
|
|
|
|
this._ellipsoid = Ellipsoid.clone(options.ellipsoid ?? Ellipsoid.default);
|
2013-09-05 02:14:53 +08:00
|
|
|
this._workerName = "createPolylineGeometry";
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2019-10-10 00:39:09 +08:00
|
|
|
let numComponents = 1 + positions.length * Cartesian3.packedLength;
|
|
|
|
|
numComponents += defined(colors) ? 1 + colors.length * Color.packedLength : 1;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
|
|
|
|
/**
|
2019-10-10 00:39:09 +08:00
|
|
|
* The number of elements used to pack the object into an array.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @type {number}
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2014-12-23 08:57:38 +08:00
|
|
|
this.packedLength =
|
2019-10-10 00:39:09 +08:00
|
|
|
numComponents + Ellipsoid.packedLength + VertexFormat.packedLength + 4;
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-10-10 00:39:09 +08:00
|
|
|
* Stores the provided instance into the provided array.
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2019-10-10 00:39:09 +08:00
|
|
|
* @param {PolylineGeometry} value The value to pack.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number[]} array The array to pack into.
|
|
|
|
|
* @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
|
2013-09-05 02:14:53 +08:00
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {number[]} The array that was packed into
|
2014-01-18 03:54:12 +08:00
|
|
|
*/
|
|
|
|
|
PolylineGeometry.pack = function (value, array, startingIndex) {
|
|
|
|
|
//>>includeStart('debug', pragmas.debug);
|
|
|
|
|
if (!defined(value)) {
|
|
|
|
|
throw new DeveloperError("value is required");
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2014-12-19 09:44:13 +08:00
|
|
|
if (!defined(array)) {
|
2014-05-14 05:41:52 +08:00
|
|
|
throw new DeveloperError("array is required");
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2014-05-14 05:41:52 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2025-03-04 03:03:53 +08:00
|
|
|
startingIndex = startingIndex ?? 0;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
|
|
|
|
let i;
|
|
|
|
|
|
2014-05-14 05:41:52 +08:00
|
|
|
const positions = value._positions;
|
2014-12-19 09:44:13 +08:00
|
|
|
let length = positions.length;
|
|
|
|
|
array[startingIndex++] = length;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-05-14 05:41:52 +08:00
|
|
|
for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {
|
|
|
|
|
Cartesian3.pack(positions[i], array, startingIndex);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
const colors = value._colors;
|
2013-09-05 02:14:53 +08:00
|
|
|
length = defined(colors) ? colors.length : 0.0;
|
2014-12-19 09:44:13 +08:00
|
|
|
array[startingIndex++] = length;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
for (i = 0; i < length; ++i, startingIndex += Color.packedLength) {
|
|
|
|
|
Color.pack(colors[i], array, startingIndex);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
Ellipsoid.pack(value._ellipsoid, array, startingIndex);
|
|
|
|
|
startingIndex += Ellipsoid.packedLength;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
VertexFormat.pack(value._vertexFormat, array, startingIndex);
|
|
|
|
|
startingIndex += VertexFormat.packedLength;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-09-05 02:14:53 +08:00
|
|
|
array[startingIndex++] = value._width;
|
|
|
|
|
array[startingIndex++] = value._colorsPerVertex ? 1.0 : 0.0;
|
2019-01-24 10:38:25 +08:00
|
|
|
array[startingIndex++] = value._arcType;
|
2014-12-19 09:44:13 +08:00
|
|
|
array[startingIndex] = value._granularity;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2016-07-29 02:57:56 +08:00
|
|
|
return array;
|
2013-09-05 02:14:53 +08:00
|
|
|
};
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-01-18 03:54:12 +08:00
|
|
|
const scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);
|
2015-01-01 06:57:11 +08:00
|
|
|
const scratchVertexFormat = new VertexFormat();
|
|
|
|
|
const scratchOptions = {
|
2014-01-18 03:54:12 +08:00
|
|
|
positions: undefined,
|
|
|
|
|
colors: undefined,
|
2015-01-01 06:57:11 +08:00
|
|
|
ellipsoid: scratchEllipsoid,
|
|
|
|
|
vertexFormat: scratchVertexFormat,
|
|
|
|
|
width: undefined,
|
2015-03-02 12:26:29 +08:00
|
|
|
colorsPerVertex: undefined,
|
2019-01-24 10:38:25 +08:00
|
|
|
arcType: undefined,
|
2014-01-18 03:54:12 +08:00
|
|
|
granularity: undefined,
|
2020-04-17 08:31:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2014-12-19 09:44:13 +08:00
|
|
|
* Retrieves an instance from a packed array.
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @param {number[]} array The packed array.
|
|
|
|
|
* @param {number} [startingIndex=0] The starting index of the element to be unpacked.
|
2014-01-18 03:54:12 +08:00
|
|
|
* @param {PolylineGeometry} [result] The object into which to store the result.
|
|
|
|
|
* @returns {PolylineGeometry} The modified result parameter or a new PolylineGeometry instance if one was not provided.
|
2013-09-04 07:06:16 +08:00
|
|
|
*/
|
2015-12-12 09:31:44 +08:00
|
|
|
PolylineGeometry.unpack = function (array, startingIndex, result) {
|
2013-12-31 04:37:32 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2013-09-04 07:06:16 +08:00
|
|
|
if (!defined(array)) {
|
|
|
|
|
throw new DeveloperError("array is required");
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2013-09-04 07:06:16 +08:00
|
|
|
//>>includeEnd('debug');
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2025-03-04 03:03:53 +08:00
|
|
|
startingIndex = startingIndex ?? 0;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
|
|
|
|
let i;
|
|
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
let length = array[startingIndex++];
|
|
|
|
|
const positions = new Array(length);
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2015-03-02 12:26:29 +08:00
|
|
|
for (i = 0; i < length; ++i, startingIndex += Cartesian3.packedLength) {
|
|
|
|
|
positions[i] = Cartesian3.unpack(array, startingIndex);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2015-03-02 12:26:29 +08:00
|
|
|
length = array[startingIndex++];
|
|
|
|
|
const colors = length > 0 ? new Array(length) : undefined;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2015-03-02 12:26:29 +08:00
|
|
|
for (i = 0; i < length; ++i, startingIndex += Color.packedLength) {
|
|
|
|
|
colors[i] = Color.unpack(array, startingIndex);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2013-09-07 08:09:23 +08:00
|
|
|
const ellipsoid = Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
|
|
|
|
|
startingIndex += Ellipsoid.packedLength;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2015-01-01 06:57:11 +08:00
|
|
|
const vertexFormat = VertexFormat.unpack(
|
2020-04-17 08:31:36 +08:00
|
|
|
array,
|
2015-01-01 06:57:11 +08:00
|
|
|
startingIndex,
|
|
|
|
|
scratchVertexFormat,
|
2020-04-17 08:31:36 +08:00
|
|
|
);
|
2013-09-07 08:09:23 +08:00
|
|
|
startingIndex += VertexFormat.packedLength;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
const width = array[startingIndex++];
|
2013-09-07 08:09:23 +08:00
|
|
|
const colorsPerVertex = array[startingIndex++] === 1.0;
|
2013-12-31 04:37:32 +08:00
|
|
|
const arcType = array[startingIndex++];
|
2014-12-19 09:44:13 +08:00
|
|
|
const granularity = array[startingIndex];
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-12-31 04:37:32 +08:00
|
|
|
if (!defined(result)) {
|
2013-09-04 07:06:16 +08:00
|
|
|
scratchOptions.positions = positions;
|
2013-09-07 08:09:23 +08:00
|
|
|
scratchOptions.colors = colors;
|
2013-09-04 07:06:16 +08:00
|
|
|
scratchOptions.width = width;
|
2015-03-02 12:26:29 +08:00
|
|
|
scratchOptions.colorsPerVertex = colorsPerVertex;
|
2015-01-01 06:57:11 +08:00
|
|
|
scratchOptions.arcType = arcType;
|
|
|
|
|
scratchOptions.granularity = granularity;
|
|
|
|
|
return new PolylineGeometry(scratchOptions);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
result._positions = positions;
|
|
|
|
|
result._colors = colors;
|
2015-01-01 06:57:11 +08:00
|
|
|
result._ellipsoid = Ellipsoid.clone(ellipsoid, result._ellipsoid);
|
|
|
|
|
result._vertexFormat = VertexFormat.clone(vertexFormat, result._vertexFormat);
|
|
|
|
|
result._width = width;
|
2019-01-24 10:38:25 +08:00
|
|
|
result._colorsPerVertex = colorsPerVertex;
|
|
|
|
|
result._arcType = arcType;
|
2014-07-09 03:03:52 +08:00
|
|
|
result._granularity = granularity;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
return result;
|
2020-04-17 08:31:36 +08:00
|
|
|
};
|
|
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
const scratchCartesian3 = new Cartesian3();
|
|
|
|
|
const scratchPosition = new Cartesian3();
|
2014-07-09 03:03:52 +08:00
|
|
|
const scratchPrevPosition = new Cartesian3();
|
2013-09-04 07:06:16 +08:00
|
|
|
const scratchNextPosition = new Cartesian3();
|
2020-04-17 08:31:36 +08:00
|
|
|
|
|
|
|
|
/**
|
2014-07-09 03:03:52 +08:00
|
|
|
* Computes the geometric representation of a polyline, including its vertices, indices, and a bounding sphere.
|
2020-04-17 08:31:36 +08:00
|
|
|
*
|
2015-01-01 06:57:11 +08:00
|
|
|
* @param {PolylineGeometry} polylineGeometry A description of the polyline.
|
|
|
|
|
* @returns {Geometry|undefined} The computed vertices and indices.
|
2020-04-17 08:31:36 +08:00
|
|
|
*/
|
2015-01-01 06:57:11 +08:00
|
|
|
PolylineGeometry.createGeometry = function (polylineGeometry) {
|
|
|
|
|
const width = polylineGeometry._width;
|
2015-01-06 04:26:18 +08:00
|
|
|
const vertexFormat = polylineGeometry._vertexFormat;
|
2014-12-19 09:44:13 +08:00
|
|
|
let colors = polylineGeometry._colors;
|
2015-03-02 12:26:29 +08:00
|
|
|
const colorsPerVertex = polylineGeometry._colorsPerVertex;
|
2019-01-24 10:38:25 +08:00
|
|
|
const arcType = polylineGeometry._arcType;
|
2014-12-19 09:44:13 +08:00
|
|
|
const granularity = polylineGeometry._granularity;
|
2014-07-09 04:53:35 +08:00
|
|
|
const ellipsoid = polylineGeometry._ellipsoid;
|
2022-01-22 00:26:25 +08:00
|
|
|
|
2020-04-17 08:31:36 +08:00
|
|
|
let i;
|
|
|
|
|
let j;
|
|
|
|
|
let k;
|
2022-01-22 00:26:25 +08:00
|
|
|
|
2021-07-14 04:09:04 +08:00
|
|
|
const removedIndices = [];
|
2014-12-19 09:44:13 +08:00
|
|
|
let positions = arrayRemoveDuplicates(
|
2016-03-26 00:17:35 +08:00
|
|
|
polylineGeometry._positions,
|
2021-07-14 04:09:04 +08:00
|
|
|
Cartesian3.equalsEpsilon,
|
|
|
|
|
false,
|
|
|
|
|
removedIndices,
|
2020-04-17 08:31:36 +08:00
|
|
|
);
|
2021-07-14 04:09:04 +08:00
|
|
|
|
|
|
|
|
if (defined(colors) && removedIndices.length > 0) {
|
|
|
|
|
let removedArrayIndex = 0;
|
|
|
|
|
let nextRemovedIndex = removedIndices[0];
|
2021-07-15 04:59:47 +08:00
|
|
|
colors = colors.filter(function (color, index) {
|
2021-07-19 22:57:15 +08:00
|
|
|
let remove = false;
|
|
|
|
|
if (colorsPerVertex) {
|
|
|
|
|
remove =
|
|
|
|
|
index === nextRemovedIndex || (index === 0 && nextRemovedIndex === 1);
|
|
|
|
|
} else {
|
|
|
|
|
remove = index + 1 === nextRemovedIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (remove) {
|
2021-07-15 04:59:47 +08:00
|
|
|
removedArrayIndex++;
|
|
|
|
|
nextRemovedIndex = removedIndices[removedArrayIndex];
|
|
|
|
|
return false;
|
2021-07-14 04:09:04 +08:00
|
|
|
}
|
2021-07-15 04:59:47 +08:00
|
|
|
return true;
|
|
|
|
|
});
|
2021-07-14 04:09:04 +08:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
let positionsLength = positions.length;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
// A width of a pixel or less is not a valid geometry, but in order to support external data
|
|
|
|
|
// that may have errors we treat this as an empty geometry.
|
|
|
|
|
if (positionsLength < 2 || width <= 0.0) {
|
|
|
|
|
return undefined;
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2019-01-24 10:38:25 +08:00
|
|
|
if (arcType === ArcType.GEODESIC || arcType === ArcType.RHUMB) {
|
2019-01-23 02:46:46 +08:00
|
|
|
let subdivisionSize;
|
2014-12-19 09:44:13 +08:00
|
|
|
let numberOfPointsFunction;
|
2019-01-24 10:38:25 +08:00
|
|
|
if (arcType === ArcType.GEODESIC) {
|
2014-12-19 09:44:13 +08:00
|
|
|
subdivisionSize = CesiumMath.chordLength(
|
2019-01-23 02:46:46 +08:00
|
|
|
granularity,
|
2014-12-19 09:44:13 +08:00
|
|
|
ellipsoid.maximumRadius,
|
2020-04-17 08:31:36 +08:00
|
|
|
);
|
2019-01-23 02:46:46 +08:00
|
|
|
numberOfPointsFunction = PolylinePipeline.numberOfPoints;
|
2020-04-17 08:31:36 +08:00
|
|
|
} else {
|
2019-01-23 02:46:46 +08:00
|
|
|
subdivisionSize = granularity;
|
|
|
|
|
numberOfPointsFunction = PolylinePipeline.numberOfPointsRhumbLine;
|
2015-12-12 09:31:44 +08:00
|
|
|
}
|
2014-12-19 09:44:13 +08:00
|
|
|
|
|
|
|
|
const heights = PolylinePipeline.extractHeights(positions, ellipsoid);
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
if (defined(colors)) {
|
|
|
|
|
let colorLength = 1;
|
|
|
|
|
for (i = 0; i < positionsLength - 1; ++i) {
|
|
|
|
|
colorLength += numberOfPointsFunction(
|
|
|
|
|
positions[i],
|
|
|
|
|
positions[i + 1],
|
|
|
|
|
subdivisionSize,
|
|
|
|
|
);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
const newColors = new Array(colorLength);
|
|
|
|
|
let newColorIndex = 0;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
for (i = 0; i < positionsLength - 1; ++i) {
|
|
|
|
|
const p0 = positions[i];
|
|
|
|
|
const p1 = positions[i + 1];
|
|
|
|
|
const c0 = colors[i];
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
const numColors = numberOfPointsFunction(p0, p1, subdivisionSize);
|
2015-03-02 12:26:29 +08:00
|
|
|
if (colorsPerVertex && i < colorLength) {
|
2015-01-01 06:57:11 +08:00
|
|
|
const c1 = colors[i + 1];
|
|
|
|
|
const interpolatedColors = interpolateColors(
|
|
|
|
|
p0,
|
|
|
|
|
p1,
|
|
|
|
|
c0,
|
|
|
|
|
c1,
|
|
|
|
|
numColors,
|
|
|
|
|
);
|
2015-03-02 12:26:29 +08:00
|
|
|
const interpolatedColorsLength = interpolatedColors.length;
|
2014-12-19 09:44:13 +08:00
|
|
|
for (j = 0; j < interpolatedColorsLength; ++j) {
|
2015-08-05 06:17:24 +08:00
|
|
|
newColors[newColorIndex++] = interpolatedColors[j];
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2015-08-05 06:17:24 +08:00
|
|
|
} else {
|
2014-12-19 09:44:13 +08:00
|
|
|
for (j = 0; j < numColors; ++j) {
|
|
|
|
|
newColors[newColorIndex++] = Color.clone(c0);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2014-12-19 09:44:13 +08:00
|
|
|
}
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2014-12-19 09:44:13 +08:00
|
|
|
|
|
|
|
|
newColors[newColorIndex] = Color.clone(colors[colors.length - 1]);
|
|
|
|
|
colors = newColors;
|
|
|
|
|
|
2014-12-23 08:57:38 +08:00
|
|
|
scratchInterpolateColorsArray.length = 0;
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2014-12-19 09:44:13 +08:00
|
|
|
|
|
|
|
|
if (arcType === ArcType.GEODESIC) {
|
|
|
|
|
positions = PolylinePipeline.generateCartesianArc({
|
2019-01-23 02:46:46 +08:00
|
|
|
positions: positions,
|
2014-12-19 09:44:13 +08:00
|
|
|
minDistance: subdivisionSize,
|
2019-01-23 02:46:46 +08:00
|
|
|
ellipsoid: ellipsoid,
|
|
|
|
|
height: heights,
|
2020-04-17 08:31:36 +08:00
|
|
|
});
|
|
|
|
|
} else {
|
2019-01-23 02:46:46 +08:00
|
|
|
positions = PolylinePipeline.generateCartesianRhumbArc({
|
|
|
|
|
positions: positions,
|
|
|
|
|
granularity: subdivisionSize,
|
|
|
|
|
ellipsoid: ellipsoid,
|
|
|
|
|
height: heights,
|
2020-04-17 08:31:36 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
positionsLength = positions.length;
|
2014-12-18 05:29:56 +08:00
|
|
|
const size = positionsLength * 4.0 - 4.0;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
const finalPositions = new Float64Array(size * 3);
|
|
|
|
|
const prevPositions = new Float64Array(size * 3);
|
|
|
|
|
const nextPositions = new Float64Array(size * 3);
|
2014-12-19 09:44:13 +08:00
|
|
|
const expandAndWidth = new Float32Array(size * 2);
|
|
|
|
|
const st = vertexFormat.st ? new Float32Array(size * 2) : undefined;
|
2013-09-07 08:09:23 +08:00
|
|
|
const finalColors = defined(colors) ? new Uint8Array(size * 4) : undefined;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
let positionIndex = 0;
|
|
|
|
|
let expandAndWidthIndex = 0;
|
|
|
|
|
let stIndex = 0;
|
2014-12-19 09:44:13 +08:00
|
|
|
let colorIndex = 0;
|
2013-09-04 07:06:16 +08:00
|
|
|
let position;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
for (j = 0; j < positionsLength; ++j) {
|
2013-09-04 07:06:16 +08:00
|
|
|
if (j === 0) {
|
2014-12-19 09:44:13 +08:00
|
|
|
position = scratchCartesian3;
|
|
|
|
|
Cartesian3.subtract(positions[0], positions[1], position);
|
|
|
|
|
Cartesian3.add(positions[0], position, position);
|
|
|
|
|
} else {
|
2013-09-04 07:06:16 +08:00
|
|
|
position = positions[j - 1];
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2014-12-19 09:44:13 +08:00
|
|
|
|
2015-01-01 06:57:11 +08:00
|
|
|
Cartesian3.clone(position, scratchPrevPosition);
|
|
|
|
|
Cartesian3.clone(positions[j], scratchPosition);
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2015-01-01 06:57:11 +08:00
|
|
|
if (j === positionsLength - 1) {
|
2015-03-02 12:26:29 +08:00
|
|
|
position = scratchCartesian3;
|
|
|
|
|
Cartesian3.subtract(
|
2013-09-04 07:06:16 +08:00
|
|
|
positions[positionsLength - 1],
|
2015-03-02 12:26:29 +08:00
|
|
|
positions[positionsLength - 2],
|
2020-04-17 08:31:36 +08:00
|
|
|
position,
|
|
|
|
|
);
|
2019-01-24 10:38:25 +08:00
|
|
|
Cartesian3.add(positions[positionsLength - 1], position, position);
|
|
|
|
|
} else {
|
2015-01-01 06:57:11 +08:00
|
|
|
position = positions[j + 1];
|
2014-12-19 09:44:13 +08:00
|
|
|
}
|
|
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
Cartesian3.clone(position, scratchNextPosition);
|
2014-12-17 04:34:06 +08:00
|
|
|
|
2019-01-23 02:46:46 +08:00
|
|
|
let color0, color1;
|
2019-01-15 03:27:05 +08:00
|
|
|
if (defined(finalColors)) {
|
|
|
|
|
if (j !== 0 && !colorsPerVertex) {
|
2019-01-23 02:46:46 +08:00
|
|
|
color0 = colors[j - 1];
|
2020-04-17 08:31:36 +08:00
|
|
|
} else {
|
2019-01-15 03:27:05 +08:00
|
|
|
color0 = colors[j];
|
2019-01-23 02:46:46 +08:00
|
|
|
}
|
2014-07-09 03:03:52 +08:00
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
if (j !== positionsLength - 1) {
|
2013-09-07 08:09:23 +08:00
|
|
|
color1 = colors[j];
|
|
|
|
|
}
|
2013-09-04 07:06:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const startK = j === 0 ? 2 : 0;
|
|
|
|
|
const endK = j === positionsLength - 1 ? 2 : 4;
|
|
|
|
|
|
2013-09-07 08:09:23 +08:00
|
|
|
for (k = startK; k < endK; ++k) {
|
|
|
|
|
Cartesian3.pack(scratchPosition, finalPositions, positionIndex);
|
|
|
|
|
Cartesian3.pack(scratchPrevPosition, prevPositions, positionIndex);
|
|
|
|
|
Cartesian3.pack(scratchNextPosition, nextPositions, positionIndex);
|
|
|
|
|
positionIndex += 3;
|
|
|
|
|
|
2014-12-18 05:29:56 +08:00
|
|
|
const direction = k - 2 < 0 ? -1.0 : 1.0;
|
|
|
|
|
expandAndWidth[expandAndWidthIndex++] = 2 * (k % 2) - 1; // expand direction
|
2014-10-31 04:41:22 +08:00
|
|
|
expandAndWidth[expandAndWidthIndex++] = direction * width;
|
|
|
|
|
|
|
|
|
|
if (vertexFormat.st) {
|
|
|
|
|
st[stIndex++] = j / (positionsLength - 1);
|
|
|
|
|
st[stIndex++] = Math.max(expandAndWidth[expandAndWidthIndex - 2], 0.0);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
2014-10-31 04:41:22 +08:00
|
|
|
|
|
|
|
|
if (defined(finalColors)) {
|
|
|
|
|
const color = k < 2 ? color0 : color1;
|
2013-09-04 07:06:16 +08:00
|
|
|
|
2013-09-07 08:09:23 +08:00
|
|
|
finalColors[colorIndex++] = Color.floatToByte(color.red);
|
|
|
|
|
finalColors[colorIndex++] = Color.floatToByte(color.green);
|
|
|
|
|
finalColors[colorIndex++] = Color.floatToByte(color.blue);
|
|
|
|
|
finalColors[colorIndex++] = Color.floatToByte(color.alpha);
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
const attributes = new GeometryAttributes();
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
attributes.position = new GeometryAttribute({
|
|
|
|
|
componentDatatype: ComponentDatatype.DOUBLE,
|
|
|
|
|
componentsPerAttribute: 3,
|
|
|
|
|
values: finalPositions,
|
2020-04-17 08:31:36 +08:00
|
|
|
});
|
|
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
attributes.prevPosition = new GeometryAttribute({
|
|
|
|
|
componentDatatype: ComponentDatatype.DOUBLE,
|
|
|
|
|
componentsPerAttribute: 3,
|
|
|
|
|
values: prevPositions,
|
2020-04-17 08:31:36 +08:00
|
|
|
});
|
|
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
attributes.nextPosition = new GeometryAttribute({
|
|
|
|
|
componentDatatype: ComponentDatatype.DOUBLE,
|
|
|
|
|
componentsPerAttribute: 3,
|
2013-09-10 01:53:49 +08:00
|
|
|
values: nextPositions,
|
2020-04-17 08:31:36 +08:00
|
|
|
});
|
|
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
attributes.expandAndWidth = new GeometryAttribute({
|
|
|
|
|
componentDatatype: ComponentDatatype.FLOAT,
|
|
|
|
|
componentsPerAttribute: 2,
|
|
|
|
|
values: expandAndWidth,
|
2020-04-17 08:31:36 +08:00
|
|
|
});
|
|
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
if (vertexFormat.st) {
|
|
|
|
|
attributes.st = new GeometryAttribute({
|
|
|
|
|
componentDatatype: ComponentDatatype.FLOAT,
|
|
|
|
|
componentsPerAttribute: 2,
|
2020-04-17 08:31:36 +08:00
|
|
|
values: st,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-07 08:09:23 +08:00
|
|
|
if (defined(finalColors)) {
|
|
|
|
|
attributes.color = new GeometryAttribute({
|
|
|
|
|
componentDatatype: ComponentDatatype.UNSIGNED_BYTE,
|
|
|
|
|
componentsPerAttribute: 4,
|
|
|
|
|
values: finalColors,
|
|
|
|
|
normalize: true,
|
2020-04-17 08:31:36 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 05:29:56 +08:00
|
|
|
const indices = IndexDatatype.createTypedArray(size, positionsLength * 6 - 6);
|
2013-09-04 07:06:16 +08:00
|
|
|
let index = 0;
|
|
|
|
|
let indicesIndex = 0;
|
2014-12-18 05:29:56 +08:00
|
|
|
const length = positionsLength - 1.0;
|
2014-10-31 04:41:22 +08:00
|
|
|
for (j = 0; j < length; ++j) {
|
|
|
|
|
indices[indicesIndex++] = index;
|
|
|
|
|
indices[indicesIndex++] = index + 2;
|
|
|
|
|
indices[indicesIndex++] = index + 1;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-10-31 04:41:22 +08:00
|
|
|
indices[indicesIndex++] = index + 1;
|
|
|
|
|
indices[indicesIndex++] = index + 2;
|
|
|
|
|
indices[indicesIndex++] = index + 3;
|
2020-04-17 08:31:36 +08:00
|
|
|
|
2014-12-19 09:44:13 +08:00
|
|
|
index += 4;
|
2020-04-17 08:31:36 +08:00
|
|
|
}
|
|
|
|
|
|
2013-09-04 07:06:16 +08:00
|
|
|
return new Geometry({
|
|
|
|
|
attributes: attributes,
|
|
|
|
|
indices: indices,
|
|
|
|
|
primitiveType: PrimitiveType.TRIANGLES,
|
2014-11-05 05:09:57 +08:00
|
|
|
boundingSphere: BoundingSphere.fromPoints(positions),
|
|
|
|
|
geometryType: GeometryType.POLYLINES,
|
2013-09-04 07:06:16 +08:00
|
|
|
});
|
|
|
|
|
};
|
Migrate Cesium to ES6 Modules
See https://github.com/AnalyticalGraphicsInc/cesium/pull/8224 for details.
eslint
There are a handful of new .eslintrc.json files, mostly to identify the files that are still AMD modules (Sandcastle/Workers). These are needed because you can't change the parser type with a comment directive (since the parser is the thing reading the file). We can finally detect unusued modules! So those have all been cleaned up as well.
requirejs -> rollup & clean-css
requirejs, almond, and karma-requirejs have all been removed. We now use rollup for building and minifying (via uglify) JS code and clean-css for css. These changes are fairly straight-forward and just involve calling rollup instead of requirejs in the build process.
Overall build time is significantly faster. CI is ~11 minutes compared to ~17 in master. Running makeZipFile on my machine takes 69 seconds compared to 112 seconds in master. There's probably plenty of room for additional optimization here too.
We wrote an published a small npm module, rollup-plugin-strip-pragma, for stripping the requirejs pragmas we use out of the release builds. This is maintained in the Tools/rollup-plugin-strip-pragma directory.
As for what we produce. The built version of Cesium is now a UMD module. So it should work anywhere that hasn't made the jump to ES6 yet. For users that were already using the "legacy" combined/minified approach, nothing changes.
One awesome thing about roll-up is that it compiles all of the workers at once and automatically detects shared codes and generates separate bundles under the hood. This means the size of our worker modules shrink dramatically and Cesium itself will load them much faster. The total minified/gzipped size of all workers in master is 2.6 MB compared to 225 KB in this branch! This should be most noticeable on demos like Geometry & Appearances which load lots of workers for the various geometry typs.
roll-up is also used to build Cesium Viewer, which is now an ES6 app.
We use clean-css via gulp and it is also a straightforward change from requirejs that requires no special mention.
Workers
While the spec allows for ES6 Web Workers, no browser actually supports them yet. That means we needed a way to get our workers into non-ES6 form. Thankfully, roll-up can generate AMD modules, which means we now have a build step to compile our Worker source code back into AMD and use the existing TaskProcessor to load and execute them. This build step is part of the standard build task and is called createWorkers. During development, these "built" workers are un-optimized so you can still debug them and read the code.
Since there is a build step, that means if you are changing code that affects a worker, you need to re-run build, or you can use the build-watch task to do it automatically.
The ES6 versions of Worker code has moved into Source/WorkersES6 and we build the workers into their "old home" of Source/Workers. cesiumWorkerBootstrapper and transferTypedArrayTest which were already non-AMD ES5 scripts remain living in the Workers directory.
Surprisingly little was changed about TaskProcessor or the worker system in general, especially considering that I thought this would be one of the major hurdles.
ThirdParty
A lot of our ThirdParty either already had a hand-written wrapper for AMD (which I updated to ES6) or had UMD which created problems when importing the same code in both Node and the browser. I basically had to update the wrapper of every third-party library to fix these problems. In some cases I updated the library version itself (Autolinker, topojson). Nothing to be too concerned about, but future clean-up would be using npm versions of these libraries and auto-generating the wrappers as needed so we don't hand-edit things.
Sandcastle
Sandcastle is eternal and manages to live another day in it's ancient requirejs/dojo 1.x form. Sandcastle now automatically uses the ES6 version of Cesium if it is available and fallsback to the ES5 unminified version if it is now. The built version of Sandcastle always uses CesiumUnminified, just like master. This means Sandcastle still works in IE11 if you run the combine step first (or use the relase zip)
Removed Cesium usage from Sandcastle proper, since it wasn't really needed
Generate a VERSION propertyin the gallery index since Cesium is no longer being included.
Remove requirejs from Sandcastle bucket
Update bucket to use the built version of Cesium if it is available by fallbackto the ES6 version during development.
Standalone.html was also updated
There's a bit of room for further clean-up here, but I think this gets us into master. I did not rename bucket-requirejs.html because I'm pretty sure it would break previously shared demos. We can put in some backwards compatible code later on if we want. (But I'd rather just see a full Sandcastle rewrite).
Specs
Specs are now all ES6, except for TestWorkers, which remain standard JS worker modules. This means you can no longer run the unbuilt unit tests in IE11. No changes for Chrome and Firefox.
Since the specs use ES6 modules and built Cesium is an ES5 UMD, I added a build-specs build step which generates a combined ES5 version of the specs which rely on Cesium as a global variable. We then inject these files into jasmine instead of the standard specs and everything works exactly as it did before. SpecRunner.html has been updated to inject the correct version of the script depending on the build/release query parameters.
The Specs must always use Cesium by importing Source/Cesium.js, this is so we can replace it with the built Cesium as describe above.
There's a bunch of room for clean-up here, such as unifying our two copies of jasmine into a single helper file, but I didn't want to start doing that clean-up as part of this already overly big PR. The important thing is that we can still test the built version and still test on IE/Edge as needed.
I also found and fixed two bugs that were causing failing unit tests, one in BingMapsImageryProviderSpec.js (which was overwriting createImage andnot setting it back) and ShadowVolumeAppearance.js (which had a module level caching bug). I think these may have been the cause of random CI failures in master as well, but only time will tell.
For coverage, we had to switch to karma-coverage-istanbul-instrumenter for native ES6 support, but that's it.
Finally, I updated appveryor to build Cesium and run the built tests under IE. We still don't fail the build for IE, but we should probably fix that if we want to keep it going.
NodeJS
When NODE_ENV is production, we now require in the minified CesiumJS directly, which works great because it's now a UMD module. Otherwise, we use the excellant esmpackage to load individual modules, it was a fairly straightforward swap from our old requirejs usage. We could probably drop esm too if we don't care about debugging or if we provie source maps at some point.
2019-10-03 23:51:23 +08:00
|
|
|
export default PolylineGeometry;
|