cesium/packages/engine/Source/Core/BoxOutlineGeometry.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

313 lines
9.3 KiB
JavaScript
Raw Permalink Normal View History

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 BoundingSphere from "./BoundingSphere.js";
import Cartesian3 from "./Cartesian3.js";
import Check from "./Check.js";
import ComponentDatatype from "./ComponentDatatype.js";
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 Geometry from "./Geometry.js";
import GeometryAttribute from "./GeometryAttribute.js";
import GeometryAttributes from "./GeometryAttributes.js";
import GeometryOffsetAttribute from "./GeometryOffsetAttribute.js";
import PrimitiveType from "./PrimitiveType.js";
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
const diffScratch = new Cartesian3();
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
/**
* A description of the outline of a cube centered at the origin.
2013-08-01 00:08:05 +08:00
*
* @alias BoxOutlineGeometry
2013-08-01 00:08:05 +08:00
* @constructor
*
* @param {object} options Object with the following properties:
2015-10-15 00:06:13 +08:00
* @param {Cartesian3} options.minimum The minimum x, y, and z coordinates of the box.
* @param {Cartesian3} options.maximum The maximum x, y, and z coordinates of the box.
2013-08-01 00:08:05 +08:00
*
2014-05-17 02:29:02 +08:00
* @see BoxOutlineGeometry.fromDimensions
* @see BoxOutlineGeometry.createGeometry
* @see Packable
*
2013-08-01 00:08:05 +08:00
* @example
* const box = new Cesium.BoxOutlineGeometry({
2015-10-15 00:06:13 +08:00
* maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0),
* minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0)
2013-08-01 00:08:05 +08:00
* });
* const geometry = Cesium.BoxOutlineGeometry.createGeometry(box);
2013-08-01 00:08:05 +08:00
*/
function BoxOutlineGeometry(options) {
options = options ?? Frozen.EMPTY_OBJECT;
2020-04-17 08:31:36 +08:00
2015-10-15 00:06:13 +08:00
const min = options.minimum;
const max = options.maximum;
2020-04-17 08:31:36 +08:00
2013-12-31 04:37:32 +08:00
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("min", min);
Check.typeOf.object("max", max);
if (
defined(options.offsetAttribute) &&
options.offsetAttribute === GeometryOffsetAttribute.TOP
) {
throw new DeveloperError(
"GeometryOffsetAttribute.TOP is not a supported options.offsetAttribute for this geometry.",
);
}
2013-12-31 04:37:32 +08:00
//>>includeEnd('debug');
2020-04-17 08:31:36 +08:00
2013-09-20 09:51:15 +08:00
this._min = Cartesian3.clone(min);
this._max = Cartesian3.clone(max);
this._offsetAttribute = options.offsetAttribute;
this._workerName = "createBoxOutlineGeometry";
}
2020-04-17 08:31:36 +08:00
/**
* Creates an outline of a cube centered at the origin given its dimensions.
*
* @param {object} options Object with the following properties:
* @param {Cartesian3} options.dimensions The width, depth, and height of the box stored in the x, y, and z coordinates of the <code>Cartesian3</code>, respectively.
2015-08-07 03:53:19 +08:00
* @returns {BoxOutlineGeometry}
*
* @exception {DeveloperError} All dimensions components must be greater than or equal to zero.
2016-07-29 02:57:56 +08:00
*
2020-04-17 08:31:36 +08:00
*
* @example
* const box = Cesium.BoxOutlineGeometry.fromDimensions({
2014-01-18 03:54:12 +08:00
* dimensions : new Cesium.Cartesian3(500000.0, 500000.0, 500000.0)
* });
* const geometry = Cesium.BoxOutlineGeometry.createGeometry(box);
2016-07-29 02:57:56 +08:00
*
* @see BoxOutlineGeometry.createGeometry
*/
BoxOutlineGeometry.fromDimensions = function (options) {
options = options ?? Frozen.EMPTY_OBJECT;
const dimensions = options.dimensions;
2020-04-17 08:31:36 +08:00
2013-12-31 04:37:32 +08:00
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("dimensions", dimensions);
Check.typeOf.number.greaterThanOrEquals("dimensions.x", dimensions.x, 0);
Check.typeOf.number.greaterThanOrEquals("dimensions.y", dimensions.y, 0);
Check.typeOf.number.greaterThanOrEquals("dimensions.z", dimensions.z, 0);
2013-12-31 04:37:32 +08:00
//>>includeEnd('debug');
2020-04-17 08:31:36 +08:00
2014-05-30 03:06:30 +08:00
const corner = Cartesian3.multiplyByScalar(dimensions, 0.5, new Cartesian3());
2020-04-17 08:31:36 +08:00
2015-10-15 00:17:31 +08:00
return new BoxOutlineGeometry({
minimum: Cartesian3.negate(corner, new Cartesian3()),
maximum: corner,
offsetAttribute: options.offsetAttribute,
2015-10-15 00:17:31 +08:00
});
2015-10-15 00:06:13 +08:00
};
2020-04-17 08:31:36 +08:00
2015-10-15 00:06:13 +08:00
/**
* Creates an outline of a cube from the dimensions of an AxisAlignedBoundingBox.
*
* @param {AxisAlignedBoundingBox} boundingBox A description of the AxisAlignedBoundingBox.
* @returns {BoxOutlineGeometry}
*
*
*
2015-10-15 00:06:13 +08:00
* @example
* const aabb = Cesium.AxisAlignedBoundingBox.fromPoints(Cesium.Cartesian3.fromDegreesArray([
2015-10-15 00:06:13 +08:00
* -72.0, 40.0,
* -70.0, 35.0,
* -75.0, 30.0,
* -70.0, 30.0,
* -68.0, 40.0
* ]));
* const box = Cesium.BoxOutlineGeometry.fromAxisAlignedBoundingBox(aabb);
2016-07-29 02:57:56 +08:00
*
* @see BoxOutlineGeometry.createGeometry
2015-10-15 00:06:13 +08:00
*/
BoxOutlineGeometry.fromAxisAlignedBoundingBox = function (boundingBox) {
2016-10-25 00:47:49 +08:00
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("boundindBox", boundingBox);
2016-10-25 00:47:49 +08:00
//>>includeEnd('debug');
2020-04-17 08:31:36 +08:00
2015-10-15 00:17:31 +08:00
return new BoxOutlineGeometry({
2015-10-15 00:06:13 +08:00
minimum: boundingBox.minimum,
maximum: boundingBox.maximum,
2015-10-15 00:17:31 +08:00
});
};
2020-04-17 08:31:36 +08:00
/**
* The number of elements used to pack the object into an array.
* @type {number}
*/
BoxOutlineGeometry.packedLength = 2 * Cartesian3.packedLength + 1;
2020-04-17 08:31:36 +08:00
/**
* Stores the provided instance into the provided array.
*
2015-08-17 23:23:22 +08:00
* @param {BoxOutlineGeometry} value The value to pack.
* @param {number[]} array The array to pack into.
* @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
2016-08-01 20:57:41 +08:00
*
* @returns {number[]} The array that was packed into
*/
BoxOutlineGeometry.pack = function (value, array, startingIndex) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("value", value);
Check.defined("array", array);
//>>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
Cartesian3.pack(value._min, array, startingIndex);
Cartesian3.pack(value._max, array, startingIndex + Cartesian3.packedLength);
2025-03-04 03:03:53 +08:00
array[startingIndex + Cartesian3.packedLength * 2] =
value._offsetAttribute ?? -1;
2020-04-17 08:31:36 +08:00
2016-07-29 02:57:56 +08:00
return array;
};
2020-04-17 08:31:36 +08:00
const scratchMin = new Cartesian3();
const scratchMax = new Cartesian3();
const scratchOptions = {
2015-10-15 00:06:13 +08:00
minimum: scratchMin,
maximum: scratchMax,
offsetAttribute: undefined,
};
2020-04-17 08:31:36 +08:00
/**
* Retrieves an instance from a packed array.
*
* @param {number[]} array The packed array.
* @param {number} [startingIndex=0] The starting index of the element to be unpacked.
* @param {BoxOutlineGeometry} [result] The object into which to store the result.
2015-08-05 06:17:24 +08:00
* @returns {BoxOutlineGeometry} The modified result parameter or a new BoxOutlineGeometry instance if one was not provided.
*/
BoxOutlineGeometry.unpack = function (array, startingIndex, result) {
//>>includeStart('debug', pragmas.debug);
Check.defined("array", array);
//>>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
const min = Cartesian3.unpack(array, startingIndex, scratchMin);
const max = Cartesian3.unpack(
array,
startingIndex + Cartesian3.packedLength,
scratchMax,
);
const offsetAttribute = array[startingIndex + Cartesian3.packedLength * 2];
2020-04-17 08:31:36 +08:00
if (!defined(result)) {
scratchOptions.offsetAttribute =
offsetAttribute === -1 ? undefined : offsetAttribute;
return new BoxOutlineGeometry(scratchOptions);
}
2020-04-17 08:31:36 +08:00
result._min = Cartesian3.clone(min, result._min);
result._max = Cartesian3.clone(max, result._max);
result._offsetAttribute =
offsetAttribute === -1 ? undefined : offsetAttribute;
2020-04-17 08:31:36 +08:00
return result;
};
2020-04-17 08:31:36 +08:00
/**
* Computes the geometric representation of an outline of a box, including its vertices, indices, and a bounding sphere.
*
* @param {BoxOutlineGeometry} boxGeometry A description of the box outline.
* @returns {Geometry|undefined} The computed vertices and indices.
*/
BoxOutlineGeometry.createGeometry = function (boxGeometry) {
const min = boxGeometry._min;
const max = boxGeometry._max;
2020-04-17 08:31:36 +08:00
if (Cartesian3.equals(min, max)) {
return;
}
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
const attributes = new GeometryAttributes();
2013-08-13 01:48:53 +08:00
const indices = new Uint16Array(12 * 2);
const positions = new Float64Array(8 * 3);
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
positions[0] = min.x;
positions[1] = min.y;
positions[2] = min.z;
positions[3] = max.x;
positions[4] = min.y;
positions[5] = min.z;
positions[6] = max.x;
positions[7] = max.y;
positions[8] = min.z;
positions[9] = min.x;
positions[10] = max.y;
positions[11] = min.z;
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
positions[12] = min.x;
positions[13] = min.y;
positions[14] = max.z;
positions[15] = max.x;
positions[16] = min.y;
positions[17] = max.z;
positions[18] = max.x;
positions[19] = max.y;
positions[20] = max.z;
positions[21] = min.x;
positions[22] = max.y;
positions[23] = max.z;
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
attributes.position = new GeometryAttribute({
componentDatatype: ComponentDatatype.DOUBLE,
componentsPerAttribute: 3,
values: positions,
});
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
// top
indices[0] = 4;
indices[1] = 5;
indices[2] = 5;
indices[3] = 6;
indices[4] = 6;
indices[5] = 7;
indices[6] = 7;
indices[7] = 4;
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
// bottom
indices[8] = 0;
indices[9] = 1;
indices[10] = 1;
indices[11] = 2;
indices[12] = 2;
indices[13] = 3;
indices[14] = 3;
indices[15] = 0;
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
// left
indices[16] = 0;
indices[17] = 4;
indices[18] = 1;
indices[19] = 5;
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
//right
indices[20] = 2;
indices[21] = 6;
indices[22] = 3;
indices[23] = 7;
2020-04-17 08:31:36 +08:00
2013-08-01 00:08:05 +08:00
const diff = Cartesian3.subtract(max, min, diffScratch);
const radius = Cartesian3.magnitude(diff) * 0.5;
2020-04-17 08:31:36 +08:00
if (defined(boxGeometry._offsetAttribute)) {
const length = positions.length;
const offsetValue =
boxGeometry._offsetAttribute === GeometryOffsetAttribute.NONE ? 0 : 1;
const applyOffset = new Uint8Array(length / 3).fill(offsetValue);
attributes.applyOffset = new GeometryAttribute({
componentDatatype: ComponentDatatype.UNSIGNED_BYTE,
componentsPerAttribute: 1,
values: applyOffset,
});
}
2020-04-17 08:31:36 +08:00
return new Geometry({
attributes: attributes,
indices: indices,
primitiveType: PrimitiveType.LINES,
boundingSphere: new BoundingSphere(Cartesian3.ZERO, radius),
offsetAttribute: boxGeometry._offsetAttribute,
});
2013-08-01 00:08:05 +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 BoxOutlineGeometry;