cesium/packages/engine/Source/DataSources/StaticGroundGeometryPerMate...

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

457 lines
15 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 AssociativeArray from "../Core/AssociativeArray.js";
import defined from "../Core/defined.js";
import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js";
import DistanceDisplayConditionGeometryInstanceAttribute from "../Core/DistanceDisplayConditionGeometryInstanceAttribute.js";
import RectangleCollisionChecker from "../Core/RectangleCollisionChecker.js";
import ShowGeometryInstanceAttribute from "../Core/ShowGeometryInstanceAttribute.js";
import GroundPrimitive from "../Scene/GroundPrimitive.js";
import ShadowVolumeAppearance from "../Scene/ShadowVolumeAppearance.js";
import BoundingSphereState from "./BoundingSphereState.js";
import ColorMaterialProperty from "./ColorMaterialProperty.js";
import MaterialProperty from "./MaterialProperty.js";
import Property from "./Property.js";
2020-04-17 08:31:36 +08:00
const distanceDisplayConditionScratch = new DistanceDisplayCondition();
2018-04-27 11:40:51 +08:00
const defaultDistanceDisplayCondition = new DistanceDisplayCondition();
2020-04-17 08:31:36 +08:00
// Encapsulates a Primitive and all the entities that it represents.
function Batch(
primitives,
classificationType,
appearanceType,
materialProperty,
usingSphericalTextureCoordinates,
zIndex,
) {
this.primitives = primitives; // scene level primitive collection (each Batch manages its own Primitive from this collection)
this.classificationType = classificationType;
this.appearanceType = appearanceType;
this.materialProperty = materialProperty;
this.updaters = new AssociativeArray(); // GeometryUpdaters that manage the visual representation of the primitive.
this.createPrimitive = true;
2018-03-30 06:52:55 +08:00
this.primitive = undefined; // a GroundPrimitive encapsulating all the entities
this.oldPrimitive = undefined; // a GroundPrimitive that is being replaced by the current primitive, but will still be shown until the current primitive is ready.
this.geometry = new AssociativeArray();
this.material = undefined;
this.updatersWithAttributes = new AssociativeArray();
this.attributes = new AssociativeArray();
this.subscriptions = new AssociativeArray();
this.showsUpdated = new AssociativeArray();
2018-04-27 11:40:51 +08:00
this.usingSphericalTextureCoordinates = usingSphericalTextureCoordinates;
2018-05-22 04:07:05 +08:00
this.zIndex = zIndex;
2018-04-06 03:59:35 +08:00
this.rectangleCollisionCheck = new RectangleCollisionChecker();
2020-04-17 08:31:36 +08:00
}
Batch.prototype.overlapping = function (rectangle) {
2018-04-06 03:59:35 +08:00
return this.rectangleCollisionCheck.collides(rectangle);
2020-04-17 08:31:36 +08:00
};
2018-05-02 23:10:38 +08:00
// Check if the given updater's material is compatible with this batch
Batch.prototype.isMaterial = function (updater) {
const material = this.materialProperty;
const updaterMaterial = updater.fillMaterialProperty;
2020-04-17 08:31:36 +08:00
if (
2018-03-30 06:52:55 +08:00
updaterMaterial === material ||
(updaterMaterial instanceof ColorMaterialProperty &&
material instanceof ColorMaterialProperty)
2020-04-17 08:31:36 +08:00
) {
return true;
2020-04-17 08:31:36 +08:00
}
return defined(material) && material.equals(updaterMaterial);
};
2020-04-17 08:31:36 +08:00
/**
* Adds an updater to the Batch, and signals for a new Primitive to be created on the next update.
* @param {JulianDate} time
* @param {GeometryUpdater} updater
* @param {GeometryInstance} geometryInstance
2025-07-08 23:34:55 +08:00
* @private
*/
2018-05-02 23:10:38 +08:00
Batch.prototype.add = function (time, updater, geometryInstance) {
const id = updater.id;
this.updaters.set(id, updater);
2018-03-30 06:52:55 +08:00
this.geometry.set(id, geometryInstance);
2018-05-02 23:10:38 +08:00
this.rectangleCollisionCheck.insert(id, geometryInstance.geometry.rectangle);
2018-04-27 11:40:51 +08:00
// Updaters with dynamic attributes must be tracked separately, may exit the batch
if (
!updater.hasConstantFill ||
!updater.fillMaterialProperty.isConstant ||
2018-03-30 06:52:55 +08:00
!Property.isConstant(updater.distanceDisplayConditionProperty)
) {
this.updatersWithAttributes.set(id, updater);
2020-04-17 08:31:36 +08:00
} else {
const that = this;
2018-03-30 06:52:55 +08:00
// Listen for show changes. These will be synchronized in updateShows.
this.subscriptions.set(
2020-04-17 08:31:36 +08:00
id,
updater.entity.definitionChanged.addEventListener(
2018-03-30 06:52:55 +08:00
function (entity, propertyName, newValue, oldValue) {
if (propertyName === "isShowing") {
that.showsUpdated.set(updater.id, updater);
}
2020-04-17 08:31:36 +08:00
},
2024-09-20 23:24:24 +08:00
),
);
2020-04-17 08:31:36 +08:00
}
this.createPrimitive = true;
2020-04-17 08:31:36 +08:00
};
/**
* Remove an updater from the Batch, and potentially signals for a new Primitive to be created
* on the next update.
* @param {GeometryUpdater} updater
2025-07-08 00:15:00 +08:00
* @returns true if the updater was removed, false if it was not found.
2025-07-08 23:34:55 +08:00
* @private
*/
Batch.prototype.remove = function (updater) {
const id = updater.id;
const geometryInstance = this.geometry.get(id);
this.createPrimitive = this.geometry.remove(id) || this.createPrimitive;
2018-03-30 06:52:55 +08:00
if (this.updaters.remove(id)) {
2018-04-06 03:59:35 +08:00
this.rectangleCollisionCheck.remove(
2018-03-30 06:52:55 +08:00
id,
geometryInstance.geometry.rectangle,
2020-04-17 08:31:36 +08:00
);
this.updatersWithAttributes.remove(id);
2018-03-30 06:52:55 +08:00
const unsubscribe = this.subscriptions.get(id);
if (defined(unsubscribe)) {
unsubscribe();
this.subscriptions.remove(id);
2020-04-17 08:31:36 +08:00
}
2018-05-22 04:23:19 +08:00
return true;
2020-04-17 08:31:36 +08:00
}
2018-05-22 04:23:19 +08:00
return false;
2020-04-17 08:31:36 +08:00
};
/**
* Update a Batch, creating a new primitive, if necessary, or swapping out an old primitive for a new one that's ready.
* A new primitive is created whenever an updater is added to or removed from a Batch.
* @param {JulianDate} time
* @returns a boolean indicating whether the Batch was updated.
2025-07-08 23:34:55 +08:00
* @private
*/
2018-03-30 06:52:55 +08:00
Batch.prototype.update = function (time) {
let isUpdated = true;
let primitive = this.primitive;
const primitives = this.primitives;
2018-03-30 06:52:55 +08:00
const geometries = this.geometry.values;
2020-04-17 08:31:36 +08:00
let i;
2018-04-06 03:59:35 +08:00
if (this.createPrimitive) {
const geometriesLength = geometries.length;
2018-04-27 11:40:51 +08:00
if (geometriesLength > 0) {
if (defined(primitive)) {
2018-04-27 11:40:51 +08:00
// Keep a handle to the old primitive so it can be removed when the updated version is ready.
if (!defined(this.oldPrimitive)) {
this.oldPrimitive = primitive;
} else {
2018-04-27 11:40:51 +08:00
// For if the new primitive changes again before it is ready.
primitives.remove(primitive);
}
}
2020-04-17 08:31:36 +08:00
this.material = MaterialProperty.getValue(
time,
this.materialProperty,
this.material,
);
2020-04-17 08:31:36 +08:00
primitive = new GroundPrimitive({
2018-04-27 11:40:51 +08:00
show: false,
asynchronous: true,
geometryInstances: geometries.slice(),
appearance: new this.appearanceType({
material: this.material,
2018-05-22 04:07:05 +08:00
// translucent and closed properties overridden
}),
classificationType: this.classificationType,
});
2020-04-17 08:31:36 +08:00
primitives.add(primitive, this.zIndex);
isUpdated = false;
} else {
if (defined(primitive)) {
primitives.remove(primitive);
2018-04-27 11:40:51 +08:00
primitive = undefined;
}
const oldPrimitive = this.oldPrimitive;
if (defined(oldPrimitive)) {
primitives.remove(oldPrimitive);
this.oldPrimitive = undefined;
}
}
this.attributes.removeAll();
this.primitive = primitive;
this.createPrimitive = false;
} else if (defined(primitive) && primitive.ready) {
2018-04-27 11:40:51 +08:00
primitive.show = true;
if (defined(this.oldPrimitive)) {
primitives.remove(this.oldPrimitive);
this.oldPrimitive = undefined;
}
this.material = MaterialProperty.getValue(
time,
this.materialProperty,
this.material,
2020-04-17 08:31:36 +08:00
);
this.primitive.appearance.material = this.material;
2020-04-17 08:31:36 +08:00
const updatersWithAttributes = this.updatersWithAttributes.values;
const length = updatersWithAttributes.length;
for (i = 0; i < length; i++) {
const updater = updatersWithAttributes[i];
const entity = updater.entity;
const instance = this.geometry.get(updater.id);
2020-04-17 08:31:36 +08:00
let attributes = this.attributes.get(instance.id.id);
if (!defined(attributes)) {
attributes = primitive.getGeometryInstanceAttributes(instance.id);
this.attributes.set(instance.id.id, attributes);
2020-04-17 08:31:36 +08:00
}
const show =
entity.isShowing && (updater.hasConstantFill || updater.isFilled(time));
const currentShow = attributes.show[0] === 1;
if (show !== currentShow) {
attributes.show = ShowGeometryInstanceAttribute.toValue(
2020-04-17 08:31:36 +08:00
show,
attributes.show,
2020-04-17 08:31:36 +08:00
);
}
const distanceDisplayConditionProperty =
updater.distanceDisplayConditionProperty;
if (!Property.isConstant(distanceDisplayConditionProperty)) {
2018-04-27 11:40:51 +08:00
const distanceDisplayCondition = Property.getValueOrDefault(
distanceDisplayConditionProperty,
2020-04-17 08:31:36 +08:00
time,
defaultDistanceDisplayCondition,
2018-04-27 11:40:51 +08:00
distanceDisplayConditionScratch,
2020-04-17 08:31:36 +08:00
);
if (
!DistanceDisplayCondition.equals(
distanceDisplayCondition,
attributes._lastDistanceDisplayCondition,
2020-04-17 08:31:36 +08:00
)
) {
attributes._lastDistanceDisplayCondition =
DistanceDisplayCondition.clone(
distanceDisplayCondition,
attributes._lastDistanceDisplayCondition,
);
attributes.distanceDisplayCondition =
DistanceDisplayConditionGeometryInstanceAttribute.toValue(
distanceDisplayCondition,
attributes.distanceDisplayCondition,
2020-04-17 08:31:36 +08:00
);
}
}
}
2018-04-27 11:40:51 +08:00
this.updateShows(primitive);
2018-05-02 23:10:38 +08:00
} else if (defined(primitive) && !primitive.ready) {
isUpdated = false;
2020-04-17 08:31:36 +08:00
}
2018-05-02 23:10:38 +08:00
return isUpdated;
};
2020-04-17 08:31:36 +08:00
Batch.prototype.updateShows = function (primitive) {
const showsUpdated = this.showsUpdated.values;
const length = showsUpdated.length;
for (let i = 0; i < length; i++) {
const updater = showsUpdated[i];
const entity = updater.entity;
const instance = this.geometry.get(updater.id);
2022-01-22 00:26:25 +08:00
let attributes = this.attributes.get(instance.id.id);
if (!defined(attributes)) {
attributes = primitive.getGeometryInstanceAttributes(instance.id);
this.attributes.set(instance.id.id, attributes);
}
const show = entity.isShowing;
const currentShow = attributes.show[0] === 1;
if (show !== currentShow) {
attributes.show = ShowGeometryInstanceAttribute.toValue(
2020-04-17 08:31:36 +08:00
show,
attributes.show,
2020-04-17 08:31:36 +08:00
);
instance.attributes.show.value[0] = attributes.show[0];
2020-04-17 08:31:36 +08:00
}
}
this.showsUpdated.removeAll();
2020-04-17 08:31:36 +08:00
};
Batch.prototype.contains = function (updater) {
return this.updaters.contains(updater.id);
};
2020-04-17 08:31:36 +08:00
Batch.prototype.getBoundingSphere = function (updater, result) {
const primitive = this.primitive;
if (!primitive.ready) {
return BoundingSphereState.PENDING;
2020-04-17 08:31:36 +08:00
}
const attributes = primitive.getGeometryInstanceAttributes(updater.entity);
2020-04-17 08:31:36 +08:00
if (
!defined(attributes) ||
!defined(attributes.boundingSphere) ||
(defined(attributes.show) && attributes.show[0] === 0)
2020-04-17 08:31:36 +08:00
) {
return BoundingSphereState.FAILED;
2020-04-17 08:31:36 +08:00
}
attributes.boundingSphere.clone(result);
return BoundingSphereState.DONE;
2020-04-17 08:31:36 +08:00
};
/**
* Removes a Batch's primitive (and oldPrimitive, if it exists).
2025-07-08 23:34:55 +08:00
* @private
*/
Batch.prototype.destroy = function () {
const primitive = this.primitive;
const primitives = this.primitives;
if (defined(primitive)) {
primitives.remove(primitive);
2020-04-17 08:31:36 +08:00
}
const oldPrimitive = this.oldPrimitive;
if (defined(oldPrimitive)) {
primitives.remove(oldPrimitive);
2020-04-17 08:31:36 +08:00
}
};
/**
* A container of Batch objects of ground geometry primitives, where a Batch is grouped by material,
* texture coordinate type, and spatial overlap.
2025-07-08 01:01:13 +08:00
* @private
2020-04-17 08:31:36 +08:00
*/
function StaticGroundGeometryPerMaterialBatch(
primitives,
classificationType,
appearanceType,
2020-04-17 08:31:36 +08:00
) {
this._items = []; // array of Batch objects, each containing representing a primitive and a set of updaters that manage the visual representation of the primitive.
this._primitives = primitives; // scene level primitive collection
this._classificationType = classificationType;
this._appearanceType = appearanceType;
2020-04-17 08:31:36 +08:00
}
/**
* Adds an geometry updater to a Batch. Tries to find a preexisting compatible Batch, or else creates a new Batch.
* Used by Visualizer classes to add and update (remove->add) a primitive's Updater set.
*
* @param {JulianDate} time
* @param {GeometryUpdater} updater A GeometryUpdater that manages the visual representation of a primitive.
2025-07-08 23:34:55 +08:00
* @private
*/
StaticGroundGeometryPerMaterialBatch.prototype.add = function (time, updater) {
const items = this._items;
const length = items.length;
2018-03-30 06:52:55 +08:00
const geometryInstance = updater.createFillGeometryInstance(time);
2018-04-27 11:40:51 +08:00
const usingSphericalTextureCoordinates =
ShadowVolumeAppearance.shouldUseSphericalCoordinates(
2018-04-06 03:59:35 +08:00
geometryInstance.geometry.rectangle,
2020-04-17 08:31:36 +08:00
);
2018-05-22 04:07:05 +08:00
const zIndex = Property.getValueOrDefault(updater.zIndex, 0);
2018-05-02 23:10:38 +08:00
// Check if the Entity represented by the updater can be placed in an existing batch. Requirements:
// * compatible material (same material or same color)
// * same type of texture coordinates (spherical vs. planar)
// * conservatively non-overlapping with any entities in the existing batch
2018-03-30 06:52:55 +08:00
for (let i = 0; i < length; ++i) {
const item = items[i];
2020-04-17 08:31:36 +08:00
if (
2018-03-30 06:52:55 +08:00
item.isMaterial(updater) &&
2018-05-22 04:07:05 +08:00
item.usingSphericalTextureCoordinates ===
usingSphericalTextureCoordinates &&
item.zIndex === zIndex &&
!item.overlapping(geometryInstance.geometry.rectangle)
2020-04-17 08:31:36 +08:00
) {
2018-03-30 06:52:55 +08:00
item.add(time, updater, geometryInstance);
2020-04-17 08:31:36 +08:00
return;
}
}
2018-05-02 23:10:38 +08:00
// If a compatible batch wasn't found, create a new batch.
const batch = new Batch(
this._primitives,
this._classificationType,
this._appearanceType,
updater.fillMaterialProperty,
usingSphericalTextureCoordinates,
2020-04-17 08:31:36 +08:00
zIndex,
);
2018-03-30 06:52:55 +08:00
batch.add(time, updater, geometryInstance);
items.push(batch);
2020-04-17 08:31:36 +08:00
};
/**
* Removes an updater from a Batch. Defers potential deletion until the next update.
* @param {GeometryUpdater} updater A GeometryUpdater that manages the visual representation of a primitive.
2025-07-08 23:34:55 +08:00
* @private
*/
StaticGroundGeometryPerMaterialBatch.prototype.remove = function (updater) {
const items = this._items;
const length = items.length;
for (let i = length - 1; i >= 0; i--) {
const item = items[i];
if (item.remove(updater)) {
// If the item is now empty, delete it (deferred until the next update,
// in case a new updater is added to the same item first).
2020-04-17 08:31:36 +08:00
break;
}
}
};
/**
* Updates all the items (Batches) in the collection, and deletes any that are empty.
* @param {JulianDate} time
* @returns a boolean indicating whether any of the items (Batches) were updated.
2025-07-08 23:34:55 +08:00
* @private
*/
StaticGroundGeometryPerMaterialBatch.prototype.update = function (time) {
2020-04-17 08:31:36 +08:00
let i;
const items = this._items;
const length = items.length;
2020-04-17 08:31:36 +08:00
for (i = length - 1; i >= 0; i--) {
const item = items[i];
if (item.updaters.length === 0) {
items.splice(i, 1);
item.destroy();
2020-04-17 08:31:36 +08:00
}
}
let isUpdated = true;
2018-05-02 23:10:38 +08:00
for (i = 0; i < items.length; i++) {
isUpdated = items[i].update(time) && isUpdated;
2020-04-17 08:31:36 +08:00
}
return isUpdated;
2020-04-17 08:31:36 +08:00
};
StaticGroundGeometryPerMaterialBatch.prototype.getBoundingSphere = function (
updater,
result,
2020-04-17 08:31:36 +08:00
) {
const items = this._items;
const length = items.length;
for (let i = 0; i < length; i++) {
const item = items[i];
if (item.contains(updater)) {
return item.getBoundingSphere(updater, result);
}
}
return BoundingSphereState.FAILED;
};
2020-04-17 08:31:36 +08:00
StaticGroundGeometryPerMaterialBatch.prototype.removeAllPrimitives =
function () {
const items = this._items;
const length = items.length;
for (let i = 0; i < length; i++) {
items[i].destroy();
}
this._items.length = 0;
};
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 StaticGroundGeometryPerMaterialBatch;