diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000000..2536d66bf13a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/Apps/Sandcastle/gallery/CZML.html b/Apps/Sandcastle/gallery/CZML.html index 0cafcad8932f..5a02e79f2bbb 100644 --- a/Apps/Sandcastle/gallery/CZML.html +++ b/Apps/Sandcastle/gallery/CZML.html @@ -42,8 +42,7 @@ viewer.scene.camera.setView({ destination: Cesium.Cartesian3.fromDegrees(-116.52, 35.02, 95000), orientation: { - heading: 6, - picth: -Cesium.Math.PI_OVER_TWO + heading: 6 } }); }); diff --git a/Apps/Sandcastle/gallery/development/Polylines.html b/Apps/Sandcastle/gallery/development/Polylines.html index 697aa0324ec8..8f55cb627d88 100644 --- a/Apps/Sandcastle/gallery/development/Polylines.html +++ b/Apps/Sandcastle/gallery/development/Polylines.html @@ -99,6 +99,26 @@ material : Cesium.Material.fromType(Cesium.Material.PolylineArrowType) }); Sandcastle.declare(localPolyline); // For highlighting on mouseover in Sandcastle. + + //Polyline using the fade material + var fadingPolyline = polylines.add({ + positions : Cesium.PolylinePipeline.generateCartesianArc({ + positions : Cesium.Cartesian3.fromDegreesArrayHeights([-75, 43, 500000, + -125, 43, 500000]) + }), + width : 5, + material : Cesium.Material.fromType(Cesium.Material.FadeType, { + repeat: false, + fadeInColor: Cesium.Color.CYAN, + fadeOutColor: Cesium.Color.CYAN.withAlpha(0), + time: new Cesium.Cartesian2(0.0, 0.0), + fadeDirection: { + x: true, + y: false + } + }) + }); + Sandcastle.declare(fadingPolyline); // For highlighting on mouseover in Sandcastle. } var viewer = new Cesium.Viewer('cesiumContainer'); diff --git a/Apps/Sandcastle/gallery/development/Polylines.jpg b/Apps/Sandcastle/gallery/development/Polylines.jpg index 85eda029f90b..cb57daf7a81d 100644 Binary files a/Apps/Sandcastle/gallery/development/Polylines.jpg and b/Apps/Sandcastle/gallery/development/Polylines.jpg differ diff --git a/CHANGES.md b/CHANGES.md index 49e7d1d56e5f..51d2bbe3c240 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,13 +5,20 @@ Change Log * Deprecated * The properties `url` and `key` will be removed from `GeocoderViewModel` in 1.31. These properties will be available on geocoder services that support them, like `BingMapsGeocoderService`. +* Breaking changes + * Removed separate `heading`, `pitch`, `roll` parameters from `Transform.headingPitchRollToFixedFrame` and `Transform.headingPitchRollQuaternion`. Pass a `headingPitchRoll` object instead. [#4843](https://github.com/AnalyticalGraphicsInc/cesium/pull/4843) * Added support for custom geocoder services and autocomplete [#4723](https://github.com/AnalyticalGraphicsInc/cesium/pull/4723). * Added [Custom Geocoder Sandcastle example](http://localhost:8080/Apps/Sandcastle/index.html?src=Custom%20Geocoder.html) * Added `GeocoderService`, an interface for geocoders. * Added `BingMapsGeocoderService` implementing the `GeocoderService` interface. * Added `CartographicGeocoderService` implementing the `GeocoderService` interface. * Updated the morph so the default view in Columbus View is now angled. [#3878](https://github.com/AnalyticalGraphicsInc/cesium/issues/3878) +* Fixed bug where `GroundPrimitives` where rendering incorrectly or disappearing at different zoom levels. [#4161](https://github.com/AnalyticalGraphicsInc/cesium/issues/4161) [#4326](https://github.com/AnalyticalGraphicsInc/cesium/issues/4326) * Fixed sky atmosphere from causing incorrect picking and hanging drill picking. [#4783](https://github.com/AnalyticalGraphicsInc/cesium/issues/4783) and [#4784](https://github.com/AnalyticalGraphicsInc/cesium/issues/4784) +* Fixed a bug that could cause a "readyImagery is not actually ready" exception when quickly zooming past the maximum available imagery level of an imagery layer near the poles. +* Fixed a bug that caused all models to use the same highlight color. [#4798] (https://github.com/AnalyticalGraphicsInc/cesium/pull/4798) +* Fixed KML for when color is an empty string [#4826](https://github.com/AnalyticalGraphicsInc/cesium/pull/4826) +* Added support for WMS version 1.3 by using CRS vice SRS query string parameter to request projection. SRS is still used for older versions. ### TODO diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 2354198c1187..480e92375181 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -35,6 +35,8 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Josh Becker](https://github.com/JoshuaStorm) * [Kangning Li](https://github.com/likangning93) * [Erik Andersson](https://github.com/erikmaarten) + * [Austin Eng](https://github.com/austinEng) + * [Shehzan Mohammed](https://github.com/shehzan10) * [NICTA](http://www.nicta.com.au/) * [Chris Cooper](https://github.com/chris-cooper) * [Kevin Ring](https://github.com/kring) @@ -120,3 +122,5 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Abhishek Potnis](https://github.com/abhishekvp) * [Brad Hover](https://github.com/tekhaus) * [Hüseyin Ateş](https://github.com/ateshuseyin) +* [Zsolt Simon](https://github.com/szsolt) +* [Chris Grant](https://github.com/cwgrant) diff --git a/Source/Core/BingMapsGeocoderService.js b/Source/Core/BingMapsGeocoderService.js index 52f73196cf6e..7f9c4fc4ced8 100644 --- a/Source/Core/BingMapsGeocoderService.js +++ b/Source/Core/BingMapsGeocoderService.js @@ -25,8 +25,7 @@ define([ * @constructor * * @param {Object} options Object with the following properties: - * @param {String} [key] A key to use with the Bing Maps geocoding service - * @param {Boolean} autoComplete Indicates whether this service shall be used to fetch auto-complete suggestions + * @param {String} [options.key] A key to use with the Bing Maps geocoding service */ function BingMapsGeocoderService(options) { options = defaultValue(options, defaultValue.EMPTY_OBJECT); diff --git a/Source/Core/Cartesian2.js b/Source/Core/Cartesian2.js index 92e6d6715b8f..d44ed87c4a0f 100644 --- a/Source/Core/Cartesian2.js +++ b/Source/Core/Cartesian2.js @@ -1,11 +1,13 @@ /*global define*/ define([ + './Check', './defaultValue', './defined', './DeveloperError', './freezeObject', './Math' ], function( + Check, defaultValue, defined, DeveloperError, @@ -118,12 +120,8 @@ define([ */ Cartesian2.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('value is required'); - } - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.typeOf.object(value, 'value'); + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -144,9 +142,7 @@ define([ */ Cartesian2.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -168,9 +164,7 @@ define([ */ Cartesian2.packArray = function(array, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); var length = array.length; @@ -195,9 +189,7 @@ define([ */ Cartesian2.unpackArray = function(array, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); var length = array.length; @@ -242,9 +234,7 @@ define([ */ Cartesian2.maximumComponent = function(cartesian) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); //>>includeEnd('debug'); return Math.max(cartesian.x, cartesian.y); @@ -258,9 +248,7 @@ define([ */ Cartesian2.minimumComponent = function(cartesian) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); //>>includeEnd('debug'); return Math.min(cartesian.x, cartesian.y); @@ -276,15 +264,9 @@ define([ */ Cartesian2.minimumByComponent = function(first, second, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(first)) { - throw new DeveloperError('first is required.'); - } - if (!defined(second)) { - throw new DeveloperError('second is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required.'); - } + Check.typeOf.object(first, 'first'); + Check.typeOf.object(second, 'second'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); @@ -304,15 +286,9 @@ define([ */ Cartesian2.maximumByComponent = function(first, second, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(first)) { - throw new DeveloperError('first is required.'); - } - if (!defined(second)) { - throw new DeveloperError('second is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required.'); - } + Check.typeOf.object(first, 'first'); + Check.typeOf.object(second, 'second'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = Math.max(first.x, second.x); @@ -328,9 +304,7 @@ define([ */ Cartesian2.magnitudeSquared = function(cartesian) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); //>>includeEnd('debug'); return cartesian.x * cartesian.x + cartesian.y * cartesian.y; @@ -402,12 +376,8 @@ define([ */ Cartesian2.normalize = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var magnitude = Cartesian2.magnitude(cartesian); @@ -433,12 +403,8 @@ define([ */ Cartesian2.dot = function(left, right) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); //>>includeEnd('debug'); return left.x * right.x + left.y * right.y; @@ -454,15 +420,9 @@ define([ */ Cartesian2.multiplyComponents = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = left.x * right.x; @@ -480,15 +440,9 @@ define([ */ Cartesian2.divideComponents = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = left.x / right.x; @@ -506,15 +460,9 @@ define([ */ Cartesian2.add = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = left.x + right.x; @@ -532,15 +480,9 @@ define([ */ Cartesian2.subtract = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = left.x - right.x; @@ -558,15 +500,9 @@ define([ */ Cartesian2.multiplyByScalar = function(cartesian, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof scalar !== 'number') { - throw new DeveloperError('scalar is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = cartesian.x * scalar; @@ -584,15 +520,9 @@ define([ */ Cartesian2.divideByScalar = function(cartesian, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof scalar !== 'number') { - throw new DeveloperError('scalar is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = cartesian.x / scalar; @@ -609,12 +539,8 @@ define([ */ Cartesian2.negate = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = -cartesian.x; @@ -631,12 +557,8 @@ define([ */ Cartesian2.abs = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = Math.abs(cartesian.x); @@ -656,18 +578,10 @@ define([ */ Cartesian2.lerp = function(start, end, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(start)) { - throw new DeveloperError('start is required.'); - } - if (!defined(end)) { - throw new DeveloperError('end is required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required.'); - } + Check.typeOf.object(start, 'start'); + Check.typeOf.object(end, 'end'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); Cartesian2.multiplyByScalar(end, t, lerpScratch); @@ -686,12 +600,8 @@ define([ */ Cartesian2.angleBetween = function(left, right) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); //>>includeEnd('debug'); Cartesian2.normalize(left, angleBetweenScratch); @@ -709,12 +619,8 @@ define([ */ Cartesian2.mostOrthogonalAxis = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required.'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var f = Cartesian2.normalize(cartesian, mostOrthogonalAxisScratch); diff --git a/Source/Core/Cartesian4.js b/Source/Core/Cartesian4.js index 33627bf01915..a9c8cf13ed32 100644 --- a/Source/Core/Cartesian4.js +++ b/Source/Core/Cartesian4.js @@ -1,11 +1,13 @@ /*global define*/ define([ + './Check', './defaultValue', './defined', './DeveloperError', './freezeObject', './Math' ], function( + Check, defaultValue, defined, DeveloperError, @@ -89,9 +91,7 @@ define([ */ Cartesian4.fromColor = function(color, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(color)) { - throw new DeveloperError('color is required'); - } + Check.typeOf.object(color, 'color'); //>>includeEnd('debug'); if (!defined(result)) { return new Cartesian4(color.red, color.green, color.blue, color.alpha); @@ -145,12 +145,8 @@ define([ */ Cartesian4.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('value is required'); - } - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.typeOf.object(value, 'value'); + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -173,9 +169,7 @@ define([ */ Cartesian4.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -199,9 +193,7 @@ define([ */ Cartesian4.packArray = function(array, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); var length = array.length; @@ -226,9 +218,7 @@ define([ */ Cartesian4.unpackArray = function(array, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); var length = array.length; @@ -273,9 +263,7 @@ define([ */ Cartesian4.maximumComponent = function(cartesian) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); //>>includeEnd('debug'); return Math.max(cartesian.x, cartesian.y, cartesian.z, cartesian.w); @@ -289,9 +277,7 @@ define([ */ Cartesian4.minimumComponent = function(cartesian) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); //>>includeEnd('debug'); return Math.min(cartesian.x, cartesian.y, cartesian.z, cartesian.w); @@ -307,15 +293,9 @@ define([ */ Cartesian4.minimumByComponent = function(first, second, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(first)) { - throw new DeveloperError('first is required.'); - } - if (!defined(second)) { - throw new DeveloperError('second is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required.'); - } + Check.typeOf.object(first, 'first'); + Check.typeOf.object(second, 'second'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = Math.min(first.x, second.x); @@ -336,15 +316,9 @@ define([ */ Cartesian4.maximumByComponent = function(first, second, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(first)) { - throw new DeveloperError('first is required.'); - } - if (!defined(second)) { - throw new DeveloperError('second is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required.'); - } + Check.typeOf.object(first, 'first'); + Check.typeOf.object(second, 'second'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = Math.max(first.x, second.x); @@ -363,9 +337,7 @@ define([ */ Cartesian4.magnitudeSquared = function(cartesian) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); //>>includeEnd('debug'); return cartesian.x * cartesian.x + cartesian.y * cartesian.y + cartesian.z * cartesian.z + cartesian.w * cartesian.w; @@ -398,9 +370,8 @@ define([ */ Cartesian4.distance = function(left, right) { //>>includeStart('debug', pragmas.debug); - if (!defined(left) || !defined(right)) { - throw new DeveloperError('left and right are required.'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); //>>includeEnd('debug'); Cartesian4.subtract(left, right, distanceScratch); @@ -423,9 +394,8 @@ define([ */ Cartesian4.distanceSquared = function(left, right) { //>>includeStart('debug', pragmas.debug); - if (!defined(left) || !defined(right)) { - throw new DeveloperError('left and right are required.'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); //>>includeEnd('debug'); Cartesian4.subtract(left, right, distanceScratch); @@ -441,12 +411,8 @@ define([ */ Cartesian4.normalize = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var magnitude = Cartesian4.magnitude(cartesian); @@ -474,12 +440,8 @@ define([ */ Cartesian4.dot = function(left, right) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); //>>includeEnd('debug'); return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w; @@ -495,15 +457,9 @@ define([ */ Cartesian4.multiplyComponents = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = left.x * right.x; @@ -523,15 +479,9 @@ define([ */ Cartesian4.divideComponents = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = left.x / right.x; @@ -551,15 +501,9 @@ define([ */ Cartesian4.add = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = left.x + right.x; @@ -579,15 +523,9 @@ define([ */ Cartesian4.subtract = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = left.x - right.x; @@ -607,15 +545,9 @@ define([ */ Cartesian4.multiplyByScalar = function(cartesian, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof scalar !== 'number') { - throw new DeveloperError('scalar is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = cartesian.x * scalar; @@ -635,15 +567,9 @@ define([ */ Cartesian4.divideByScalar = function(cartesian, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof scalar !== 'number') { - throw new DeveloperError('scalar is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = cartesian.x / scalar; @@ -662,12 +588,8 @@ define([ */ Cartesian4.negate = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = -cartesian.x; @@ -686,12 +608,8 @@ define([ */ Cartesian4.abs = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = Math.abs(cartesian.x); @@ -713,18 +631,10 @@ define([ */ Cartesian4.lerp = function(start, end, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(start)) { - throw new DeveloperError('start is required.'); - } - if (!defined(end)) { - throw new DeveloperError('end is required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required.'); - } + Check.typeOf.object(start, 'start'); + Check.typeOf.object(end, 'end'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); Cartesian4.multiplyByScalar(end, t, lerpScratch); @@ -742,12 +652,8 @@ define([ */ Cartesian4.mostOrthogonalAxis = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required.'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var f = Cartesian4.normalize(cartesian, mostOrthogonalAxisScratch); diff --git a/Source/Core/Check.js b/Source/Core/Check.js index 5bf150dcab79..f3ce7708f2b7 100644 --- a/Source/Core/Check.js +++ b/Source/Core/Check.js @@ -1,14 +1,10 @@ /*global define*/ define([ - './defaultValue', './defined', - './DeveloperError', - './isArray' + './DeveloperError' ], function( - defaultValue, defined, - DeveloperError, - isArray) { + DeveloperError) { 'use strict'; /** @@ -140,7 +136,7 @@ define([ * @param {String} name The name of the variable being tested * @exception {DeveloperError} test must be typeof 'boolean' */ - Check.typeOf.boolean = function (test, name) { + Check.typeOf.bool = function (test, name) { if (typeof test !== 'boolean') { throw new DeveloperError(getFailedTypeErrorMessage(typeof test, 'boolean', name)); } diff --git a/Source/Core/CircleGeometry.js b/Source/Core/CircleGeometry.js index 8aa557d4c33b..1d938bb2d64e 100644 --- a/Source/Core/CircleGeometry.js +++ b/Source/Core/CircleGeometry.js @@ -68,7 +68,8 @@ define([ extrudedHeight : options.extrudedHeight, granularity : options.granularity, vertexFormat : options.vertexFormat, - stRotation : options.stRotation + stRotation : options.stRotation, + shadowVolume: options.shadowVolume }; this._ellipseGeometry = new EllipseGeometry(ellipseGeometryOptions); this._workerName = 'createCircleGeometry'; @@ -113,7 +114,8 @@ define([ vertexFormat : new VertexFormat(), stRotation : undefined, semiMajorAxis : undefined, - semiMinorAxis : undefined + semiMinorAxis : undefined, + shadowVolume: undefined }; /** @@ -133,6 +135,7 @@ define([ scratchOptions.granularity = ellipseGeometry._granularity; scratchOptions.vertexFormat = VertexFormat.clone(ellipseGeometry._vertexFormat, scratchOptions.vertexFormat); scratchOptions.stRotation = ellipseGeometry._stRotation; + scratchOptions.shadowVolume = ellipseGeometry._shadowVolume; if (!defined(result)) { scratchOptions.radius = ellipseGeometry._semiMajorAxis; @@ -173,7 +176,8 @@ define([ granularity : granularity, extrudedHeight : minHeight, height : maxHeight, - vertexFormat : VertexFormat.POSITION_ONLY + vertexFormat : VertexFormat.POSITION_ONLY, + shadowVolume: true }); }; diff --git a/Source/Core/CorridorGeometry.js b/Source/Core/CorridorGeometry.js index 4fd13ea735a9..49992368288d 100644 --- a/Source/Core/CorridorGeometry.js +++ b/Source/Core/CorridorGeometry.js @@ -561,8 +561,8 @@ define([ function computePositionsExtruded(params, vertexFormat) { var topVertexFormat = new VertexFormat({ - position : vertexFormat.positon, - normal : (vertexFormat.normal || vertexFormat.binormal), + position : vertexFormat.position, + normal : (vertexFormat.normal || vertexFormat.binormal || params.shadowVolume), tangent : vertexFormat.tangent, binormal : (vertexFormat.normal || vertexFormat.binormal), st : vertexFormat.st @@ -590,28 +590,49 @@ define([ newPositions.set(wallPositions, length * 2); attributes.position.values = newPositions; - length /= 3; + attributes = extrudedAttributes(attributes, vertexFormat); + var size = length / 3; + if (params.shadowVolume) { + var topNormals = attributes.normal.values; + length = topNormals.length; + + var extrudeNormals = new Float32Array(length * 6); + for (i = 0; i < length; i ++) { + topNormals[i] = -topNormals[i]; + } + //only get normals for bottom layer that's going to be pushed down + extrudeNormals.set(topNormals, length); //bottom face + extrudeNormals = addWallPositions(topNormals, length*4, extrudeNormals); //bottom wall + attributes.extrudeDirection = new GeometryAttribute({ + componentDatatype : ComponentDatatype.FLOAT, + componentsPerAttribute : 3, + values : extrudeNormals + }); + if (!vertexFormat.normal) { + attributes.normal = undefined; + } + } + var i; var iLength = indices.length; - var twoLength = length + length; - var newIndices = IndexDatatype.createTypedArray(newPositions.length / 3, iLength * 2 + twoLength * 3); + var twoSize = size + size; + var newIndices = IndexDatatype.createTypedArray(newPositions.length / 3, iLength * 2 + twoSize * 3); newIndices.set(indices); var index = iLength; for (i = 0; i < iLength; i += 3) { // bottom indices var v0 = indices[i]; var v1 = indices[i + 1]; var v2 = indices[i + 2]; - newIndices[index++] = v2 + length; - newIndices[index++] = v1 + length; - newIndices[index++] = v0 + length; + newIndices[index++] = v2 + size; + newIndices[index++] = v1 + size; + newIndices[index++] = v0 + size; } - attributes = extrudedAttributes(attributes, vertexFormat); var UL, LL, UR, LR; - for (i = 0; i < twoLength; i += 2) { //wall indices - UL = i + twoLength; - LL = UL + twoLength; + for (i = 0; i < twoSize; i += 2) { //wall indices + UL = i + twoSize; + LL = UL + twoSize; UR = UL + 1; LR = LL + 1; newIndices[index++] = UL; @@ -793,6 +814,7 @@ define([ this._extrudedHeight = defaultValue(options.extrudedHeight, this._height); this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); + this._shadowVolume = defaultValue(options.shadowVolume, false); this._workerName = 'createCorridorGeometry'; this._rectangle = computeRectangle(positions, this._ellipsoid, width, this._cornerType); @@ -800,7 +822,7 @@ define([ * The number of elements used to pack the object into an array. * @type {Number} */ - this.packedLength = 1 + positions.length * Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 5; + this.packedLength = 1 + positions.length * Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 6; } /** @@ -845,7 +867,8 @@ define([ array[startingIndex++] = value._height; array[startingIndex++] = value._extrudedHeight; array[startingIndex++] = value._cornerType; - array[startingIndex] = value._granularity; + array[startingIndex++] = value._granularity; + array[startingIndex] = value._shadowVolume ? 1.0 : 0.0; return array; }; @@ -861,7 +884,8 @@ define([ height : undefined, extrudedHeight : undefined, cornerType : undefined, - granularity : undefined + granularity : undefined, + shadowVolume: undefined }; /** @@ -901,7 +925,8 @@ define([ var height = array[startingIndex++]; var extrudedHeight = array[startingIndex++]; var cornerType = array[startingIndex++]; - var granularity = array[startingIndex]; + var granularity = array[startingIndex++]; + var shadowVolume = array[startingIndex] === 1.0; if (!defined(result)) { scratchOptions.positions = positions; @@ -910,6 +935,7 @@ define([ scratchOptions.extrudedHeight = extrudedHeight; scratchOptions.cornerType = cornerType; scratchOptions.granularity = granularity; + scratchOptions.shadowVolume = shadowVolume; return new CorridorGeometry(scratchOptions); } @@ -922,6 +948,7 @@ define([ result._cornerType = cornerType; result._granularity = granularity; result._rectangle = Rectangle.clone(rectangle); + result._shadowVolume = shadowVolume; return result; }; @@ -962,6 +989,7 @@ define([ height = h; params.height = height; params.extrudedHeight = extrudedHeight; + params.shadowVolume = corridorGeometry._shadowVolume; attr = computePositionsExtruded(params, vertexFormat); } else { var computedPositions = CorridorGeometryLibrary.computePositions(params); @@ -1000,7 +1028,8 @@ define([ granularity : granularity, extrudedHeight : minHeight, height : maxHeight, - vertexFormat : VertexFormat.POSITION_ONLY + vertexFormat : VertexFormat.POSITION_ONLY, + shadowVolume: true }); }; diff --git a/Source/Core/Credit.js b/Source/Core/Credit.js index cd949480e8cd..820e20d7fb3b 100644 --- a/Source/Core/Credit.js +++ b/Source/Core/Credit.js @@ -147,7 +147,7 @@ define([ /** * Returns true if the credits are equal * - * @param {Credit} credits The credit to compare to. + * @param {Credit} credit The credit to compare to. * @returns {Boolean} true if left and right are equal, false otherwise. */ Credit.prototype.equals = function(credit) { diff --git a/Source/Core/EllipseGeometry.js b/Source/Core/EllipseGeometry.js index 59193cf043d3..3faca9185f5d 100644 --- a/Source/Core/EllipseGeometry.js +++ b/Source/Core/EllipseGeometry.js @@ -81,12 +81,15 @@ define([ var ellipsoid = options.ellipsoid; var stRotation = options.stRotation; var size = (extrude) ? positions.length / 3 * 2 : positions.length / 3; + var shadowVolume = options.shadowVolume; var textureCoordinates = (vertexFormat.st) ? new Float32Array(size * 2) : undefined; var normals = (vertexFormat.normal) ? new Float32Array(size * 3) : undefined; var tangents = (vertexFormat.tangent) ? new Float32Array(size * 3) : undefined; var binormals = (vertexFormat.binormal) ? new Float32Array(size * 3) : undefined; + var extrudeNormals = (shadowVolume) ? new Float32Array(size * 3) : undefined; + var textureCoordIndex = 0; // Raise positions to a height above the ellipsoid and compute the @@ -136,44 +139,52 @@ define([ textureCoordinates[textureCoordIndex++] = texCoordScratch.y; } - normal = ellipsoid.geodeticSurfaceNormal(position, normal); + if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.binormal || shadowVolume) { + normal = ellipsoid.geodeticSurfaceNormal(position, normal); - if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.binormal) { - if (vertexFormat.tangent || vertexFormat.binormal) { - tangent = Cartesian3.normalize(Cartesian3.cross(Cartesian3.UNIT_Z, normal, tangent), tangent); - Matrix3.multiplyByVector(textureMatrix, tangent, tangent); + if (shadowVolume) { + extrudeNormals[i + bottomOffset] = -normal.x; + extrudeNormals[i1 + bottomOffset] = -normal.y; + extrudeNormals[i2 + bottomOffset] = -normal.z; } - if (vertexFormat.normal) { - normals[i] = normal.x; - normals[i1] = normal.y; - normals[i2] = normal.z; - if (extrude) { - normals[i + bottomOffset] = -normal.x; - normals[i1 + bottomOffset] = -normal.y; - normals[i2 + bottomOffset] = -normal.z; + + if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.binormal) { + if (vertexFormat.tangent || vertexFormat.binormal) { + tangent = Cartesian3.normalize(Cartesian3.cross(Cartesian3.UNIT_Z, normal, tangent), tangent); + Matrix3.multiplyByVector(textureMatrix, tangent, tangent); + } + if (vertexFormat.normal) { + normals[i] = normal.x; + normals[i1] = normal.y; + normals[i2] = normal.z; + if (extrude) { + normals[i + bottomOffset] = -normal.x; + normals[i1 + bottomOffset] = -normal.y; + normals[i2 + bottomOffset] = -normal.z; + } } - } - if (vertexFormat.tangent) { - tangents[i] = tangent.x; - tangents[i1] = tangent.y; - tangents[i2] = tangent.z; - if (extrude) { - tangents[i + bottomOffset] = -tangent.x; - tangents[i1 + bottomOffset] = -tangent.y; - tangents[i2 + bottomOffset] = -tangent.z; + if (vertexFormat.tangent) { + tangents[i] = tangent.x; + tangents[i1] = tangent.y; + tangents[i2] = tangent.z; + if (extrude) { + tangents[i + bottomOffset] = -tangent.x; + tangents[i1 + bottomOffset] = -tangent.y; + tangents[i2 + bottomOffset] = -tangent.z; + } } - } - if (vertexFormat.binormal) { - binormal = Cartesian3.normalize(Cartesian3.cross(normal, tangent, binormal), binormal); - binormals[i] = binormal.x; - binormals[i1] = binormal.y; - binormals[i2] = binormal.z; - if (extrude) { - binormals[i + bottomOffset] = binormal.x; - binormals[i1 + bottomOffset] = binormal.y; - binormals[i2 + bottomOffset] = binormal.z; + if (vertexFormat.binormal) { + binormal = Cartesian3.normalize(Cartesian3.cross(normal, tangent, binormal), binormal); + binormals[i] = binormal.x; + binormals[i1] = binormal.y; + binormals[i2] = binormal.z; + if (extrude) { + binormals[i + bottomOffset] = binormal.x; + binormals[i1 + bottomOffset] = binormal.y; + binormals[i2 + bottomOffset] = binormal.z; + } } } } @@ -229,6 +240,15 @@ define([ values : binormals }); } + + if (shadowVolume) { + attributes.extrudeDirection = new GeometryAttribute({ + componentDatatype : ComponentDatatype.FLOAT, + componentsPerAttribute : 3, + values : extrudeNormals + }); + } + return attributes; } @@ -371,6 +391,9 @@ define([ var tangents = (vertexFormat.tangent) ? new Float32Array(size * 3) : undefined; var binormals = (vertexFormat.binormal) ? new Float32Array(size * 3) : undefined; + var shadowVolume = options.shadowVolume; + var extrudeNormals = (shadowVolume) ? new Float32Array(size * 3) : undefined; + var textureCoordIndex = 0; // Raise positions to a height above the ellipsoid and compute the @@ -421,6 +444,13 @@ define([ position = ellipsoid.scaleToGeodeticSurface(position, position); extrudedPosition = Cartesian3.clone(position, scratchCartesian2); normal = ellipsoid.geodeticSurfaceNormal(position, normal); + + if (shadowVolume) { + extrudeNormals[i + length] = -normal.x; + extrudeNormals[i1 + length] = -normal.y; + extrudeNormals[i2 + length] = -normal.z; + } + var scaledNormal = Cartesian3.multiplyByScalar(normal, height, scratchCartesian4); position = Cartesian3.add(position, scaledNormal, position); scaledNormal = Cartesian3.multiplyByScalar(normal, extrudedHeight, scaledNormal); @@ -527,6 +557,15 @@ define([ values : binormals }); } + + if (shadowVolume) { + attributes.extrudeDirection = new GeometryAttribute({ + componentDatatype : ComponentDatatype.FLOAT, + componentsPerAttribute : 3, + values : extrudeNormals + }); + } + return attributes; } @@ -724,6 +763,7 @@ define([ this._vertexFormat = VertexFormat.clone(vertexFormat); this._extrudedHeight = defaultValue(extrudedHeight, height); this._extrude = extrude; + this._shadowVolume = defaultValue(options.shadowVolume, false); this._workerName = 'createEllipseGeometry'; this._rectangle = computeRectangle(this._center, this._ellipsoid, semiMajorAxis, semiMinorAxis, this._rotation); @@ -733,7 +773,7 @@ define([ * The number of elements used to pack the object into an array. * @type {Number} */ - EllipseGeometry.packedLength = Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 8; + EllipseGeometry.packedLength = Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 9; /** * Stores the provided instance into the provided array. @@ -775,7 +815,8 @@ define([ array[startingIndex++] = value._height; array[startingIndex++] = value._granularity; array[startingIndex++] = value._extrudedHeight; - array[startingIndex] = value._extrude ? 1.0 : 0.0; + array[startingIndex++] = value._extrude ? 1.0 : 0.0; + array[startingIndex] = value._shadowVolume ? 1.0 : 0.0; return array; }; @@ -794,7 +835,8 @@ define([ stRotation : undefined, height : undefined, granularity : undefined, - extrudedHeight : undefined + extrudedHeight : undefined, + shadowVolume: undefined }; /** @@ -833,7 +875,8 @@ define([ var height = array[startingIndex++]; var granularity = array[startingIndex++]; var extrudedHeight = array[startingIndex++]; - var extrude = array[startingIndex] === 1.0; + var extrude = array[startingIndex++] === 1.0; + var shadowVolume = array[startingIndex] === 1.0; if (!defined(result)) { scratchOptions.height = height; @@ -843,6 +886,7 @@ define([ scratchOptions.rotation = rotation; scratchOptions.semiMajorAxis = semiMajorAxis; scratchOptions.semiMinorAxis = semiMinorAxis; + scratchOptions.shadowVolume = shadowVolume; return new EllipseGeometry(scratchOptions); } @@ -857,6 +901,7 @@ define([ result._granularity = granularity; result._extrudedHeight = extrudedHeight; result._extrude = extrude; + result._shadowVolume = shadowVolume; result._rectangle = Rectangle.clone(rectangle); return result; @@ -890,6 +935,7 @@ define([ if (ellipseGeometry._extrude) { options.extrudedHeight = Math.min(ellipseGeometry._extrudedHeight, ellipseGeometry._height); options.height = Math.max(ellipseGeometry._extrudedHeight, ellipseGeometry._height); + options.shadowVolume = ellipseGeometry._shadowVolume; geometry = computeExtrudedEllipse(options); } else { geometry = computeEllipse(options); @@ -923,7 +969,8 @@ define([ granularity : granularity, extrudedHeight : minHeight, height : maxHeight, - vertexFormat : VertexFormat.POSITION_ONLY + vertexFormat : VertexFormat.POSITION_ONLY, + shadowVolume: true }); }; diff --git a/Source/Core/Ellipsoid.js b/Source/Core/Ellipsoid.js index deca2629e1ae..6f3eba4bcfcb 100644 --- a/Source/Core/Ellipsoid.js +++ b/Source/Core/Ellipsoid.js @@ -208,7 +208,9 @@ define([ /** * Computes an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions. * - * @param {Cartesian3} [radii=Cartesian3.ZERO] The ellipsoid's radius in the x, y, and z directions. + * @param {Cartesian3} [cartesian=Cartesian3.ZERO] The ellipsoid's radius in the x, y, and z directions. + * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new + * instance should be created. * @returns {Ellipsoid} A new Ellipsoid instance. * * @exception {DeveloperError} All radii components must be greater than or equal to zero. diff --git a/Source/Core/EllipsoidGeodesic.js b/Source/Core/EllipsoidGeodesic.js index 8db8aa6ed9b5..4a84a85b7d04 100644 --- a/Source/Core/EllipsoidGeodesic.js +++ b/Source/Core/EllipsoidGeodesic.js @@ -337,6 +337,7 @@ define([ * Provides the location of a point at the indicated portion along the geodesic. * * @param {Number} fraction The portion of the distance between the initial and final points. + * @param {Cartographic} result The object in which to store the result. * @returns {Cartographic} The location of the point along the geodesic. */ EllipsoidGeodesic.prototype.interpolateUsingFraction = function(fraction, result) { @@ -347,6 +348,7 @@ define([ * Provides the location of a point at the indicated distance along the geodesic. * * @param {Number} distance The distance from the inital point to the point of interest along the geodesic + * @param {Cartographic} result The object in which to store the result. * @returns {Cartographic} The location of the point along the geodesic. * * @exception {DeveloperError} start and end must be set before calling function interpolateUsingSurfaceDistance diff --git a/Source/Core/GeometryPipeline.js b/Source/Core/GeometryPipeline.js index c27a9dda80cd..23bbeb25a91a 100644 --- a/Source/Core/GeometryPipeline.js +++ b/Source/Core/GeometryPipeline.js @@ -282,6 +282,9 @@ define([ 'binormal', 'tangent', + // For shadow volumes + 'extrudeDirection', + // From compressing texture coordinates and normals 'compressedAttributes' ]; @@ -1343,7 +1346,7 @@ define([ var toEncode1 = new Cartesian3(); var toEncode2 = new Cartesian3(); var toEncode3 = new Cartesian3(); - + var encodeResult2 = new Cartesian2(); /** * Compresses and packs geometry normal attribute values to save memory. * @@ -1360,53 +1363,89 @@ define([ } //>>includeEnd('debug'); + var extrudeAttribute = geometry.attributes.extrudeDirection; + var i; + var numVertices; + if (defined(extrudeAttribute)) { + //only shadow volumes use extrudeDirection, and shadow volumes use vertexFormat: POSITION_ONLY so we don't need to check other attributes + var extrudeDirections = extrudeAttribute.values; + numVertices = extrudeDirections.length / 3.0; + var compressedDirections = new Float32Array(numVertices * 2); + + var i2 = 0; + for (i = 0; i < numVertices; ++i) { + Cartesian3.fromArray(extrudeDirections, i * 3.0, toEncode1); + if (Cartesian3.equals(toEncode1, Cartesian3.ZERO)) { + i2 += 2; + continue; + } + encodeResult2 = AttributeCompression.octEncodeInRange(toEncode1, 65535, encodeResult2); + compressedDirections[i2++] = encodeResult2.x; + compressedDirections[i2++] = encodeResult2.y; + } + + geometry.attributes.compressedAttributes = new GeometryAttribute({ + componentDatatype : ComponentDatatype.FLOAT, + componentsPerAttribute : 2, + values : compressedDirections + }); + delete geometry.attributes.extrudeDirection; + return geometry; + } + var normalAttribute = geometry.attributes.normal; var stAttribute = geometry.attributes.st; - if (!defined(normalAttribute) && !defined(stAttribute)) { + + var hasNormal = defined(normalAttribute); + var hasSt = defined(stAttribute); + if (!hasNormal && !hasSt) { return geometry; } var tangentAttribute = geometry.attributes.tangent; var binormalAttribute = geometry.attributes.binormal; + var hasTangent = defined(tangentAttribute); + var hasBinormal = defined(binormalAttribute); + var normals; var st; var tangents; var binormals; - if (defined(normalAttribute)) { + if (hasNormal) { normals = normalAttribute.values; } - if (defined(stAttribute)) { + if (hasSt) { st = stAttribute.values; } - if (defined(tangentAttribute)) { + if (hasTangent) { tangents = tangentAttribute.values; } - if (binormalAttribute) { + if (hasBinormal) { binormals = binormalAttribute.values; } - var length = defined(normals) ? normals.length : st.length; - var numComponents = defined(normals) ? 3.0 : 2.0; - var numVertices = length / numComponents; + var length = hasNormal ? normals.length : st.length; + var numComponents = hasNormal ? 3.0 : 2.0; + numVertices = length / numComponents; var compressedLength = numVertices; - var numCompressedComponents = defined(st) && defined(normals) ? 2.0 : 1.0; - numCompressedComponents += defined(tangents) || defined(binormals) ? 1.0 : 0.0; + var numCompressedComponents = hasSt && hasNormal ? 2.0 : 1.0; + numCompressedComponents += hasTangent || hasBinormal ? 1.0 : 0.0; compressedLength *= numCompressedComponents; var compressedAttributes = new Float32Array(compressedLength); var normalIndex = 0; - for (var i = 0; i < numVertices; ++i) { - if (defined(st)) { + for (i = 0; i < numVertices; ++i) { + if (hasSt) { Cartesian2.fromArray(st, i * 2.0, scratchCartesian2); compressedAttributes[normalIndex++] = AttributeCompression.compressTextureCoordinates(scratchCartesian2); } var index = i * 3.0; - if (defined(normals) && defined(tangents) && defined(binormals)) { + if (hasNormal && defined(tangents) && defined(binormals)) { Cartesian3.fromArray(normals, index, toEncode1); Cartesian3.fromArray(tangents, index, toEncode2); Cartesian3.fromArray(binormals, index, toEncode3); @@ -1415,17 +1454,17 @@ define([ compressedAttributes[normalIndex++] = scratchCartesian2.x; compressedAttributes[normalIndex++] = scratchCartesian2.y; } else { - if (defined(normals)) { + if (hasNormal) { Cartesian3.fromArray(normals, index, toEncode1); compressedAttributes[normalIndex++] = AttributeCompression.octEncodeFloat(toEncode1); } - if (defined(tangents)) { + if (hasTangent) { Cartesian3.fromArray(tangents, index, toEncode1); compressedAttributes[normalIndex++] = AttributeCompression.octEncodeFloat(toEncode1); } - if (defined(binormals)) { + if (hasBinormal) { Cartesian3.fromArray(binormals, index, toEncode1); compressedAttributes[normalIndex++] = AttributeCompression.octEncodeFloat(toEncode1); } @@ -1438,16 +1477,16 @@ define([ values : compressedAttributes }); - if (defined(normals)) { + if (hasNormal) { delete geometry.attributes.normal; } - if (defined(st)) { + if (hasSt) { delete geometry.attributes.st; } - if (defined(tangents)) { + if (hasTangent) { delete geometry.attributes.tangent; } - if (defined(binormals)) { + if (hasBinormal) { delete geometry.attributes.binormal; } @@ -1877,8 +1916,8 @@ define([ var s1Scratch = new Cartesian2(); var s2Scratch = new Cartesian2(); - function computeTriangleAttributes(i0, i1, i2, point, positions, normals, binormals, tangents, texCoords, currentAttributes, insertedIndex) { - if (!defined(normals) && !defined(binormals) && !defined(tangents) && !defined(texCoords)) { + function computeTriangleAttributes(i0, i1, i2, point, positions, normals, binormals, tangents, texCoords, extrudeDirections, currentAttributes, insertedIndex) { + if (!defined(normals) && !defined(binormals) && !defined(tangents) && !defined(texCoords) && !defined(extrudeDirections)) { return; } @@ -1903,6 +1942,29 @@ define([ Cartesian3.pack(normal, currentAttributes.normal.values, insertedIndex * 3); } + if (defined(extrudeDirections)) { + var d0 = Cartesian3.fromArray(extrudeDirections, i0 * 3, p0Scratch); + var d1 = Cartesian3.fromArray(extrudeDirections, i1 * 3, p1Scratch); + var d2 = Cartesian3.fromArray(extrudeDirections, i2 * 3, p2Scratch); + + Cartesian3.multiplyByScalar(d0, coords.x, d0); + Cartesian3.multiplyByScalar(d1, coords.y, d1); + Cartesian3.multiplyByScalar(d2, coords.z, d2); + + var direction; + if (!Cartesian3.equals(d0, Cartesian3.ZERO) || !Cartesian3.equals(d1, Cartesian3.ZERO) || !Cartesian3.equals(d2, Cartesian3.ZERO)) { + direction = Cartesian3.add(d0, d1, d0); + Cartesian3.add(direction, d2, direction); + Cartesian3.normalize(direction, direction); + } else { + direction = p0Scratch; + direction.x = 0; + direction.y = 0; + direction.z = 0; + } + Cartesian3.pack(direction, currentAttributes.extrudeDirection.values, insertedIndex * 3); + } + if (defined(binormals)) { var b0 = Cartesian3.fromArray(binormals, i0 * 3, p0Scratch); var b1 = Cartesian3.fromArray(binormals, i1 * 3, p1Scratch); @@ -1982,6 +2044,7 @@ define([ var binormals = (defined(attributes.binormal)) ? attributes.binormal.values : undefined; var tangents = (defined(attributes.tangent)) ? attributes.tangent.values : undefined; var texCoords = (defined(attributes.st)) ? attributes.st.values : undefined; + var extrudeDirections = (defined(attributes.extrudeDirection)) ? attributes.extrudeDirection.values : undefined; var indices = geometry.indices; var eastGeometry = copyGeometryForSplit(geometry); @@ -2035,7 +2098,7 @@ define([ } insertedIndex = insertSplitPoint(currentAttributes, currentIndices, currentIndexMap, indices, resultIndex < 3 ? i + resultIndex : -1, point); - computeTriangleAttributes(i0, i1, i2, point, positions, normals, binormals, tangents, texCoords, currentAttributes, insertedIndex); + computeTriangleAttributes(i0, i1, i2, point, positions, normals, binormals, tangents, texCoords, extrudeDirections, currentAttributes, insertedIndex); } } else { if (defined(result)) { @@ -2055,13 +2118,13 @@ define([ } insertedIndex = insertSplitPoint(currentAttributes, currentIndices, currentIndexMap, indices, i, p0); - computeTriangleAttributes(i0, i1, i2, p0, positions, normals, binormals, tangents, texCoords, currentAttributes, insertedIndex); + computeTriangleAttributes(i0, i1, i2, p0, positions, normals, binormals, tangents, texCoords, extrudeDirections, currentAttributes, insertedIndex); insertedIndex = insertSplitPoint(currentAttributes, currentIndices, currentIndexMap, indices, i + 1, p1); - computeTriangleAttributes(i0, i1, i2, p1, positions, normals, binormals, tangents, texCoords, currentAttributes, insertedIndex); + computeTriangleAttributes(i0, i1, i2, p1, positions, normals, binormals, tangents, texCoords, extrudeDirections, currentAttributes, insertedIndex); insertedIndex = insertSplitPoint(currentAttributes, currentIndices, currentIndexMap, indices, i + 2, p2); - computeTriangleAttributes(i0, i1, i2, p2, positions, normals, binormals, tangents, texCoords, currentAttributes, insertedIndex); + computeTriangleAttributes(i0, i1, i2, p2, positions, normals, binormals, tangents, texCoords, extrudeDirections, currentAttributes, insertedIndex); } } diff --git a/Source/Core/IntersectionTests.js b/Source/Core/IntersectionTests.js index e468763c9ff0..3bde8428fed3 100644 --- a/Source/Core/IntersectionTests.js +++ b/Source/Core/IntersectionTests.js @@ -5,6 +5,7 @@ define([ './defaultValue', './defined', './DeveloperError', + './Interval', './Math', './Matrix3', './QuadraticRealPolynomial', @@ -16,6 +17,7 @@ define([ defaultValue, defined, DeveloperError, + Interval, CesiumMath, Matrix3, QuadraticRealPolynomial, @@ -293,7 +295,7 @@ define([ function raySphere(ray, sphere, result) { if (!defined(result)) { - result = {}; + result = new Interval(); } var origin = ray.origin; @@ -324,8 +326,8 @@ define([ * * @param {Ray} ray The ray. * @param {BoundingSphere} sphere The sphere. - * @param {Object} [result] The result onto which to store the result. - * @returns {Object} An object with the first (start) and the second (stop) intersection scalars for points along the ray or undefined if there are no intersections. + * @param {Interval} [result] The result onto which to store the result. + * @returns {Interval} The interval containing scalar points along the ray or undefined if there are no intersections. */ IntersectionTests.raySphere = function(ray, sphere, result) { //>>includeStart('debug', pragmas.debug); @@ -355,8 +357,8 @@ define([ * @param {Cartesian3} p0 An end point of the line segment. * @param {Cartesian3} p1 The other end point of the line segment. * @param {BoundingSphere} sphere The sphere. - * @param {Object} [result] The result onto which to store the result. - * @returns {Object} An object with the first (start) and the second (stop) intersection scalars for points along the line segment or undefined if there are no intersections. + * @param {Interval} [result] The result onto which to store the result. + * @returns {Interval} The interval containing scalar points along the ray or undefined if there are no intersections. */ IntersectionTests.lineSegmentSphere = function(p0, p1, sphere, result) { //>>includeStart('debug', pragmas.debug); @@ -396,7 +398,7 @@ define([ * * @param {Ray} ray The ray. * @param {Ellipsoid} ellipsoid The ellipsoid. - * @returns {Object} An object with the first (start) and the second (stop) intersection scalars for points along the ray or undefined if there are no intersections. + * @returns {Interval} The interval containing scalar points along the ray or undefined if there are no intersections. */ IntersectionTests.rayEllipsoid = function(ray, ellipsoid) { //>>includeStart('debug', pragmas.debug); @@ -440,10 +442,7 @@ define([ var root0 = temp / w2; var root1 = difference / temp; if (root0 < root1) { - return { - start : root0, - stop : root1 - }; + return new Interval(root0, root1); } return { @@ -453,10 +452,7 @@ define([ } else { // qw2 == product. Repeated roots (2 intersections). var root = Math.sqrt(difference / w2); - return { - start : root, - stop : root - }; + return new Interval(root, root); } } else if (q2 < 1.0) { // Inside ellipsoid (2 intersections). @@ -466,19 +462,13 @@ define([ discriminant = qw * qw - product; temp = -qw + Math.sqrt(discriminant); // Positively valued. - return { - start : 0.0, - stop : temp / w2 - }; + return new Interval(0.0, temp / w2); } else { // q2 == 1.0. On ellipsoid. if (qw < 0.0) { // Looking inward. w2 = Cartesian3.magnitudeSquared(w); - return { - start : 0.0, - stop : -qw / w2 - }; + return new Interval(0.0, -qw / w2); } // qw >= 0.0. Looking outward or tangent. diff --git a/Source/Core/Math.js b/Source/Core/Math.js index 7c9952c522b5..b3bd96701bd4 100644 --- a/Source/Core/Math.js +++ b/Source/Core/Math.js @@ -486,7 +486,7 @@ define([ throw new DeveloperError('angle is required.'); } //>>includeEnd('debug'); - + return CesiumMath.clamp(angle, -1*CesiumMath.PI_OVER_TWO, CesiumMath.PI_OVER_TWO); }; @@ -496,13 +496,13 @@ define([ * @param {Number} angle in radians * @returns {Number} The angle in the range [-CesiumMath.PI, CesiumMath.PI]. */ - CesiumMath.negativePiToPi = function(x) { + CesiumMath.negativePiToPi = function(angle) { //>>includeStart('debug', pragmas.debug); - if (!defined(x)) { - throw new DeveloperError('x is required.'); + if (!defined(angle)) { + throw new DeveloperError('angle is required.'); } //>>includeEnd('debug'); - return CesiumMath.zeroToTwoPi(x + CesiumMath.PI) - CesiumMath.PI; + return CesiumMath.zeroToTwoPi(angle + CesiumMath.PI) - CesiumMath.PI; }; /** @@ -511,14 +511,14 @@ define([ * @param {Number} angle in radians * @returns {Number} The angle in the range [0, CesiumMath.TWO_PI]. */ - CesiumMath.zeroToTwoPi = function(x) { + CesiumMath.zeroToTwoPi = function(angle) { //>>includeStart('debug', pragmas.debug); - if (!defined(x)) { - throw new DeveloperError('x is required.'); + if (!defined(angle)) { + throw new DeveloperError('angle is required.'); } //>>includeEnd('debug'); - var mod = CesiumMath.mod(x, CesiumMath.TWO_PI); - if (Math.abs(mod) < CesiumMath.EPSILON14 && Math.abs(x) > CesiumMath.EPSILON14) { + var mod = CesiumMath.mod(angle, CesiumMath.TWO_PI); + if (Math.abs(mod) < CesiumMath.EPSILON14 && Math.abs(angle) > CesiumMath.EPSILON14) { return CesiumMath.TWO_PI; } return mod; @@ -592,7 +592,7 @@ define([ * @example * //Compute 7!, which is equal to 5040 * var computedFactorial = Cesium.Math.factorial(7); - * + * * @see {@link http://en.wikipedia.org/wiki/Factorial|Factorial on Wikipedia} */ CesiumMath.factorial = function(n) { diff --git a/Source/Core/Matrix2.js b/Source/Core/Matrix2.js index ead1b25b2aa8..ad6bcaa18abc 100644 --- a/Source/Core/Matrix2.js +++ b/Source/Core/Matrix2.js @@ -1,6 +1,7 @@ /*global define*/ define([ './Cartesian2', + './Check', './defaultValue', './defined', './defineProperties', @@ -8,6 +9,7 @@ define([ './freezeObject' ], function( Cartesian2, + Check, defaultValue, defined, defineProperties, @@ -57,13 +59,8 @@ define([ */ Matrix2.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('value is required'); - } - - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.typeOf.object(value, 'value'); + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -86,9 +83,7 @@ define([ */ Matrix2.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -111,18 +106,18 @@ define([ * @param {Matrix2} [result] The object onto which to store the result. * @returns {Matrix2} The modified result parameter or a new Matrix2 instance if one was not provided. (Returns undefined if matrix is undefined) */ - Matrix2.clone = function(values, result) { - if (!defined(values)) { + Matrix2.clone = function(matrix, result) { + if (!defined(matrix)) { return undefined; } if (!defined(result)) { - return new Matrix2(values[0], values[2], - values[1], values[3]); + return new Matrix2(matrix[0], matrix[2], + matrix[1], matrix[3]); } - result[0] = values[0]; - result[1] = values[1]; - result[2] = values[2]; - result[3] = values[3]; + result[0] = matrix[0]; + result[1] = matrix[1]; + result[2] = matrix[2]; + result[3] = matrix[3]; return result; }; @@ -148,9 +143,7 @@ define([ */ Matrix2.fromArray = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -175,9 +168,7 @@ define([ */ Matrix2.fromColumnMajorArray = function(values, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(values)) { - throw new DeveloperError('values parameter is required'); - } + Check.defined(values, 'values'); //>>includeEnd('debug'); return Matrix2.clone(values, result); @@ -193,9 +184,7 @@ define([ */ Matrix2.fromRowMajorArray = function(values, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(values)) { - throw new DeveloperError('values is required.'); - } + Check.defined(values, 'values'); //>>includeEnd('debug'); if (!defined(result)) { @@ -224,9 +213,7 @@ define([ */ Matrix2.fromScale = function(scale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(scale)) { - throw new DeveloperError('scale is required.'); - } + Check.typeOf.object(scale, 'scale'); //>>includeEnd('debug'); if (!defined(result)) { @@ -257,9 +244,7 @@ define([ */ Matrix2.fromUniformScale = function(scale, result) { //>>includeStart('debug', pragmas.debug); - if (typeof scale !== 'number') { - throw new DeveloperError('scale is required.'); - } + Check.typeOf.number(scale, 'scale'); //>>includeEnd('debug'); if (!defined(result)) { @@ -290,9 +275,7 @@ define([ */ Matrix2.fromRotation = function(angle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(angle)) { - throw new DeveloperError('angle is required.'); - } + Check.typeOf.number(angle, 'angle'); //>>includeEnd('debug'); var cosAngle = Math.cos(angle); @@ -320,9 +303,7 @@ define([ */ Matrix2.toArray = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } + Check.typeOf.object(matrix, 'matrix'); //>>includeEnd('debug'); if (!defined(result)) { @@ -353,12 +334,13 @@ define([ */ Matrix2.getElementIndex = function(column, row) { //>>includeStart('debug', pragmas.debug); - if (typeof row !== 'number' || row < 0 || row > 1) { - throw new DeveloperError('row must be 0 or 1.'); - } - if (typeof column !== 'number' || column < 0 || column > 1) { - throw new DeveloperError('column must be 0 or 1.'); - } + Check.typeOf.number(row, 'row'); + Check.numeric.minimum(row, 0); + Check.numeric.maximum(row, 1); + + Check.typeOf.number(column, 'column'); + Check.numeric.minimum(column, 0); + Check.numeric.maximum(column, 1); //>>includeEnd('debug'); return column * 2 + row; @@ -376,15 +358,13 @@ define([ */ Matrix2.getColumn = function(matrix, index, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } - if (typeof index !== 'number' || index < 0 || index > 1) { - throw new DeveloperError('index must be 0 or 1.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 1); + + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var startIndex = index * 2; @@ -409,18 +389,14 @@ define([ */ Matrix2.setColumn = function(matrix, index, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof index !== 'number' || index < 0 || index > 1) { - throw new DeveloperError('index must be 0 or 1.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 1); + + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result = Matrix2.clone(matrix, result); @@ -442,15 +418,13 @@ define([ */ Matrix2.getRow = function(matrix, index, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } - if (typeof index !== 'number' || index < 0 || index > 1) { - throw new DeveloperError('index must be 0 or 1.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 1); + + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var x = matrix[index]; @@ -474,18 +448,14 @@ define([ */ Matrix2.setRow = function(matrix, index, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof index !== 'number' || index < 0 || index > 1) { - throw new DeveloperError('index must be 0 or 1.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 1); + + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result = Matrix2.clone(matrix, result); @@ -505,12 +475,8 @@ define([ */ Matrix2.getScale = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = Cartesian2.magnitude(Cartesian2.fromElements(matrix[0], matrix[1], scratchColumn)); @@ -542,15 +508,9 @@ define([ */ Matrix2.multiply = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var column0Row0 = left[0] * right[0] + left[2] * right[1]; @@ -575,15 +535,9 @@ define([ */ Matrix2.add = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = left[0] + right[0]; @@ -603,15 +557,9 @@ define([ */ Matrix2.subtract = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = left[0] - right[0]; @@ -631,15 +579,9 @@ define([ */ Matrix2.multiplyByVector = function(matrix, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var x = matrix[0] * cartesian.x + matrix[2] * cartesian.y; @@ -660,15 +602,9 @@ define([ */ Matrix2.multiplyByScalar = function(matrix, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (typeof scalar !== 'number') { - throw new DeveloperError('scalar is required and must be a number'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = matrix[0] * scalar; @@ -696,15 +632,9 @@ define([ */ Matrix2.multiplyByScale = function(matrix, scale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(scale)) { - throw new DeveloperError('scale is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(scale, 'scale'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = matrix[0] * scale.x; @@ -723,12 +653,8 @@ define([ */ Matrix2.negate = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = -matrix[0]; @@ -747,12 +673,8 @@ define([ */ Matrix2.transpose = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var column0Row0 = matrix[0]; @@ -776,12 +698,8 @@ define([ */ Matrix2.abs = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = Math.abs(matrix[0]); @@ -832,9 +750,7 @@ define([ */ Matrix2.equalsEpsilon = function(left, right, epsilon) { //>>includeStart('debug', pragmas.debug); - if (typeof epsilon !== 'number') { - throw new DeveloperError('epsilon must be a number'); - } + Check.typeOf.number(epsilon, 'epsilon'); //>>includeEnd('debug'); return (left === right) || diff --git a/Source/Core/Matrix3.js b/Source/Core/Matrix3.js index 2faff37a7283..0b63e2eb9a7a 100644 --- a/Source/Core/Matrix3.js +++ b/Source/Core/Matrix3.js @@ -1,6 +1,7 @@ /*global define*/ define([ './Cartesian3', + './Check', './defaultValue', './defined', './defineProperties', @@ -9,6 +10,7 @@ define([ './Math' ], function( Cartesian3, + Check, defaultValue, defined, defineProperties, @@ -72,13 +74,8 @@ define([ */ Matrix3.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('value is required'); - } - - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.typeOf.object(value, 'value'); + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -106,9 +103,7 @@ define([ */ Matrix3.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -136,24 +131,24 @@ define([ * @param {Matrix3} [result] The object onto which to store the result. * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided. (Returns undefined if matrix is undefined) */ - Matrix3.clone = function(values, result) { - if (!defined(values)) { + Matrix3.clone = function(matrix, result) { + if (!defined(matrix)) { return undefined; } if (!defined(result)) { - return new Matrix3(values[0], values[3], values[6], - values[1], values[4], values[7], - values[2], values[5], values[8]); + return new Matrix3(matrix[0], matrix[3], matrix[6], + matrix[1], matrix[4], matrix[7], + matrix[2], matrix[5], matrix[8]); } - result[0] = values[0]; - result[1] = values[1]; - result[2] = values[2]; - result[3] = values[3]; - result[4] = values[4]; - result[5] = values[5]; - result[6] = values[6]; - result[7] = values[7]; - result[8] = values[8]; + result[0] = matrix[0]; + result[1] = matrix[1]; + result[2] = matrix[2]; + result[3] = matrix[3]; + result[4] = matrix[4]; + result[5] = matrix[5]; + result[6] = matrix[6]; + result[7] = matrix[7]; + result[8] = matrix[8]; return result; }; @@ -180,9 +175,7 @@ define([ */ Matrix3.fromArray = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -212,9 +205,7 @@ define([ */ Matrix3.fromColumnMajorArray = function(values, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(values)) { - throw new DeveloperError('values parameter is required'); - } + Check.defined(values, 'values'); //>>includeEnd('debug'); return Matrix3.clone(values, result); @@ -230,9 +221,7 @@ define([ */ Matrix3.fromRowMajorArray = function(values, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(values)) { - throw new DeveloperError('values is required.'); - } + Check.defined(values, 'values'); //>>includeEnd('debug'); if (!defined(result)) { @@ -261,9 +250,7 @@ define([ */ Matrix3.fromQuaternion = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); //>>includeEnd('debug'); var x2 = quaternion.x * quaternion.x; @@ -315,10 +302,9 @@ define([ */ Matrix3.fromHeadingPitchRoll = function(headingPitchRoll, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(headingPitchRoll)) { - throw new DeveloperError('headingPitchRoll is required'); - } + Check.typeOf.object(headingPitchRoll, 'headingPitchRoll'); //>>includeEnd('debug'); + var cosTheta = Math.cos(-headingPitchRoll.pitch); var cosPsi = Math.cos(-headingPitchRoll.heading); var cosPhi = Math.cos(headingPitchRoll.roll); @@ -371,9 +357,7 @@ define([ */ Matrix3.fromScale = function(scale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(scale)) { - throw new DeveloperError('scale is required.'); - } + Check.typeOf.object(scale, 'scale'); //>>includeEnd('debug'); if (!defined(result)) { @@ -411,9 +395,7 @@ define([ */ Matrix3.fromUniformScale = function(scale, result) { //>>includeStart('debug', pragmas.debug); - if (typeof scale !== 'number') { - throw new DeveloperError('scale is required.'); - } + Check.typeOf.number(scale, 'scale'); //>>includeEnd('debug'); if (!defined(result)) { @@ -438,7 +420,7 @@ define([ /** * Computes a Matrix3 instance representing the cross product equivalent matrix of a Cartesian3 vector. * - * @param {Cartesian3} the vector on the left hand side of the cross product operation. + * @param {Cartesian3} vector the vector on the left hand side of the cross product operation. * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created. * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided. * @@ -451,9 +433,7 @@ define([ */ Matrix3.fromCrossProduct = function(vector, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(vector)) { - throw new DeveloperError('vector is required.'); - } + Check.typeOf.object(vector, 'vector'); //>>includeEnd('debug'); if (!defined(result)) { @@ -490,9 +470,7 @@ define([ */ Matrix3.fromRotationX = function(angle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(angle)) { - throw new DeveloperError('angle is required.'); - } + Check.typeOf.number(angle, 'angle'); //>>includeEnd('debug'); var cosAngle = Math.cos(angle); @@ -533,9 +511,7 @@ define([ */ Matrix3.fromRotationY = function(angle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(angle)) { - throw new DeveloperError('angle is required.'); - } + Check.typeOf.number(angle, 'angle'); //>>includeEnd('debug'); var cosAngle = Math.cos(angle); @@ -576,9 +552,7 @@ define([ */ Matrix3.fromRotationZ = function(angle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(angle)) { - throw new DeveloperError('angle is required.'); - } + Check.typeOf.number(angle, 'angle'); //>>includeEnd('debug'); var cosAngle = Math.cos(angle); @@ -614,9 +588,7 @@ define([ */ Matrix3.toArray = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } + Check.typeOf.object(matrix, 'matrix'); //>>includeEnd('debug'); if (!defined(result)) { @@ -652,12 +624,12 @@ define([ */ Matrix3.getElementIndex = function(column, row) { //>>includeStart('debug', pragmas.debug); - if (typeof row !== 'number' || row < 0 || row > 2) { - throw new DeveloperError('row must be 0, 1, or 2.'); - } - if (typeof column !== 'number' || column < 0 || column > 2) { - throw new DeveloperError('column must be 0, 1, or 2.'); - } + Check.typeOf.number(column, 'column'); + Check.typeOf.number(row, 'row'); + Check.numeric.minimum(row, 0); + Check.numeric.maximum(row, 2); + Check.numeric.minimum(column, 0); + Check.numeric.maximum(column, 2); //>>includeEnd('debug'); return column * 3 + row; @@ -675,16 +647,11 @@ define([ */ Matrix3.getColumn = function(matrix, index, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } - - if (typeof index !== 'number' || index < 0 || index > 2) { - throw new DeveloperError('index must be 0, 1, or 2.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 2); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var startIndex = index * 3; @@ -711,18 +678,12 @@ define([ */ Matrix3.setColumn = function(matrix, index, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof index !== 'number' || index < 0 || index > 2) { - throw new DeveloperError('index must be 0, 1, or 2.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 2); + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result = Matrix3.clone(matrix, result); @@ -745,15 +706,11 @@ define([ */ Matrix3.getRow = function(matrix, index, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } - if (typeof index !== 'number' || index < 0 || index > 2) { - throw new DeveloperError('index must be 0, 1, or 2.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 2); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var x = matrix[index]; @@ -779,18 +736,12 @@ define([ */ Matrix3.setRow = function(matrix, index, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof index !== 'number' || index < 0 || index > 2) { - throw new DeveloperError('index must be 0, 1, or 2.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 2); + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result = Matrix3.clone(matrix, result); @@ -811,12 +762,8 @@ define([ */ Matrix3.getScale = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = Cartesian3.magnitude(Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn)); @@ -849,15 +796,9 @@ define([ */ Matrix3.multiply = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var column0Row0 = left[0] * right[0] + left[3] * right[1] + left[6] * right[2]; @@ -894,15 +835,9 @@ define([ */ Matrix3.add = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = left[0] + right[0]; @@ -927,15 +862,9 @@ define([ */ Matrix3.subtract = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = left[0] - right[0]; @@ -960,15 +889,9 @@ define([ */ Matrix3.multiplyByVector = function(matrix, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var vX = cartesian.x; @@ -995,15 +918,9 @@ define([ */ Matrix3.multiplyByScalar = function(matrix, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (typeof scalar !== 'number') { - throw new DeveloperError('scalar must be a number'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = matrix[0] * scalar; @@ -1036,15 +953,9 @@ define([ */ Matrix3.multiplyByScale = function(matrix, scale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(scale)) { - throw new DeveloperError('scale is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(scale, 'scale'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = matrix[0] * scale.x; @@ -1068,12 +979,8 @@ define([ */ Matrix3.negate = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = -matrix[0]; @@ -1097,12 +1004,8 @@ define([ */ Matrix3.transpose = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var column0Row0 = matrix[0]; @@ -1244,9 +1147,7 @@ define([ */ Matrix3.computeEigenDecomposition = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } + Check.typeOf.object(matrix, 'matrix'); //>>includeEnd('debug'); // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan, @@ -1292,12 +1193,8 @@ define([ */ Matrix3.abs = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = Math.abs(matrix[0]); @@ -1321,9 +1218,7 @@ define([ */ Matrix3.determinant = function(matrix) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } + Check.typeOf.object(matrix, 'matrix'); //>>includeEnd('debug'); var m11 = matrix[0]; @@ -1350,12 +1245,8 @@ define([ */ Matrix3.inverse = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var m11 = matrix[0]; @@ -1425,9 +1316,7 @@ define([ */ Matrix3.equalsEpsilon = function(left, right, epsilon) { //>>includeStart('debug', pragmas.debug); - if (typeof epsilon !== 'number') { - throw new DeveloperError('epsilon must be a number'); - } + Check.typeOf.number(epsilon, 'epsilon'); //>>includeEnd('debug'); return (left === right) || diff --git a/Source/Core/Matrix4.js b/Source/Core/Matrix4.js index 53ed1241f682..0ea3319be262 100644 --- a/Source/Core/Matrix4.js +++ b/Source/Core/Matrix4.js @@ -2,6 +2,7 @@ define([ './Cartesian3', './Cartesian4', + './Check', './defaultValue', './defined', './defineProperties', @@ -13,6 +14,7 @@ define([ ], function( Cartesian3, Cartesian4, + Check, defaultValue, defined, defineProperties, @@ -104,13 +106,8 @@ define([ */ Matrix4.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('value is required'); - } - - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.typeOf.object(value, 'value'); + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -145,9 +142,7 @@ define([ */ Matrix4.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -245,9 +240,7 @@ define([ */ Matrix4.fromColumnMajorArray = function(values, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(values)) { - throw new DeveloperError('values is required'); - } + Check.defined(values, 'values'); //>>includeEnd('debug'); return Matrix4.clone(values, result); @@ -263,9 +256,7 @@ define([ */ Matrix4.fromRowMajorArray = function(values, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(values)) { - throw new DeveloperError('values is required.'); - } + Check.defined(values, 'values'); //>>includeEnd('debug'); if (!defined(result)) { @@ -304,9 +295,7 @@ define([ */ Matrix4.fromRotationTranslation = function(rotation, translation, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rotation)) { - throw new DeveloperError('rotation is required.'); - } + Check.typeOf.object(rotation, 'rotation'); //>>includeEnd('debug'); translation = defaultValue(translation, Cartesian3.ZERO); @@ -356,15 +345,9 @@ define([ */ Matrix4.fromTranslationQuaternionRotationScale = function(translation, rotation, scale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(translation)) { - throw new DeveloperError('translation is required.'); - } - if (!defined(rotation)) { - throw new DeveloperError('rotation is required.'); - } - if (!defined(scale)) { - throw new DeveloperError('scale is required.'); - } + Check.typeOf.object(translation, 'translation'); + Check.typeOf.object(rotation, 'rotation'); + Check.typeOf.object(scale, 'scale'); //>>includeEnd('debug'); if (!defined(result)) { @@ -427,9 +410,7 @@ define([ */ Matrix4.fromTranslationRotationScale = function(translationRotationScale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(translationRotationScale)) { - throw new DeveloperError('translationRotationScale is required.'); - } + Check.typeOf.object(translationRotationScale, 'translationRotationScale'); //>>includeEnd('debug'); return Matrix4.fromTranslationQuaternionRotationScale(translationRotationScale.translation, translationRotationScale.rotation, translationRotationScale.scale, result); @@ -446,9 +427,7 @@ define([ */ Matrix4.fromTranslation = function(translation, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(translation)) { - throw new DeveloperError('translation is required.'); - } + Check.typeOf.object(translation, 'translation'); //>>includeEnd('debug'); return Matrix4.fromRotationTranslation(Matrix3.IDENTITY, translation, result); @@ -471,9 +450,7 @@ define([ */ Matrix4.fromScale = function(scale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(scale)) { - throw new DeveloperError('scale is required.'); - } + Check.typeOf.object(scale, 'scale'); //>>includeEnd('debug'); if (!defined(result)) { @@ -520,9 +497,7 @@ define([ */ Matrix4.fromUniformScale = function(scale, result) { //>>includeStart('debug', pragmas.debug); - if (typeof scale !== 'number') { - throw new DeveloperError('scale is required.'); - } + Check.typeOf.number(scale, 'scale'); //>>includeEnd('debug'); if (!defined(result)) { @@ -564,9 +539,7 @@ define([ */ Matrix4.fromCamera = function(camera, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(camera)) { - throw new DeveloperError('camera is required.'); - } + Check.typeOf.object(camera, 'camera'); //>>includeEnd('debug'); var position = camera.position; @@ -574,15 +547,9 @@ define([ var up = camera.up; //>>includeStart('debug', pragmas.debug); - if (!defined(position)) { - throw new DeveloperError('camera.position is required.'); - } - if (!defined(direction)) { - throw new DeveloperError('camera.direction is required.'); - } - if (!defined(up)) { - throw new DeveloperError('camera.up is required.'); - } + Check.typeOf.object(position, 'camera.position'); + Check.typeOf.object(direction, 'camera.direction'); + Check.typeOf.object(up, 'camera.up'); //>>includeEnd('debug'); Cartesian3.normalize(direction, fromCameraF); @@ -675,9 +642,7 @@ define([ if (far <= 0.0) { throw new DeveloperError('far must be greater than zero.'); } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var bottom = Math.tan(fovY * 0.5); @@ -720,27 +685,13 @@ define([ */ Matrix4.computeOrthographicOffCenter = function(left, right, bottom, top, near, far, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required.'); - } - if (!defined(right)) { - throw new DeveloperError('right is required.'); - } - if (!defined(bottom)) { - throw new DeveloperError('bottom is required.'); - } - if (!defined(top)) { - throw new DeveloperError('top is required.'); - } - if (!defined(near)) { - throw new DeveloperError('near is required.'); - } - if (!defined(far)) { - throw new DeveloperError('far is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.number(left, 'left'); + Check.typeOf.number(right, 'right'); + Check.typeOf.number(bottom, 'bottom'); + Check.typeOf.number(top, 'top'); + Check.typeOf.number(near, 'near'); + Check.typeOf.number(far, 'far'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var a = 1.0 / (right - left); @@ -787,27 +738,13 @@ define([ */ Matrix4.computePerspectiveOffCenter = function(left, right, bottom, top, near, far, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required.'); - } - if (!defined(right)) { - throw new DeveloperError('right is required.'); - } - if (!defined(bottom)) { - throw new DeveloperError('bottom is required.'); - } - if (!defined(top)) { - throw new DeveloperError('top is required.'); - } - if (!defined(near)) { - throw new DeveloperError('near is required.'); - } - if (!defined(far)) { - throw new DeveloperError('far is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.number(left, 'left'); + Check.typeOf.number(right, 'right'); + Check.typeOf.number(bottom, 'bottom'); + Check.typeOf.number(top, 'top'); + Check.typeOf.number(near, 'near'); + Check.typeOf.number(far, 'far'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var column0Row0 = 2.0 * near / (right - left); @@ -850,24 +787,12 @@ define([ */ Matrix4.computeInfinitePerspectiveOffCenter = function(left, right, bottom, top, near, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required.'); - } - if (!defined(right)) { - throw new DeveloperError('right is required.'); - } - if (!defined(bottom)) { - throw new DeveloperError('bottom is required.'); - } - if (!defined(top)) { - throw new DeveloperError('top is required.'); - } - if (!defined(near)) { - throw new DeveloperError('near is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.number(left, 'left'); + Check.typeOf.number(right, 'right'); + Check.typeOf.number(bottom, 'bottom'); + Check.typeOf.number(top, 'top'); + Check.typeOf.number(near, 'near'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var column0Row0 = 2.0 * near / (right - left); @@ -917,9 +842,7 @@ define([ */ Matrix4.computeViewportTransformation = function(viewport, nearDepthRange, farDepthRange, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); viewport = defaultValue(viewport, defaultValue.EMPTY_OBJECT); @@ -973,21 +896,11 @@ define([ */ Matrix4.computeView = function(position, direction, up, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(position)) { - throw new DeveloperError('position is required'); - } - if (!defined(direction)) { - throw new DeveloperError('direction is required'); - } - if (!defined(up)) { - throw new DeveloperError('up is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(position, 'position'); + Check.typeOf.object(direction, 'direction'); + Check.typeOf.object(up, 'up'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = right.x; @@ -1030,9 +943,7 @@ define([ */ Matrix4.toArray = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } + Check.typeOf.object(matrix, 'matrix'); //>>includeEnd('debug'); if (!defined(result)) { @@ -1078,12 +989,13 @@ define([ */ Matrix4.getElementIndex = function(column, row) { //>>includeStart('debug', pragmas.debug); - if (typeof row !== 'number' || row < 0 || row > 3) { - throw new DeveloperError('row must be 0, 1, 2, or 3.'); - } - if (typeof column !== 'number' || column < 0 || column > 3) { - throw new DeveloperError('column must be 0, 1, 2, or 3.'); - } + Check.typeOf.number(row, 'row'); + Check.numeric.minimum(row, 0); + Check.numeric.maximum(row, 3); + + Check.typeOf.number(column, 'column'); + Check.numeric.minimum(column, 0); + Check.numeric.maximum(column, 3); //>>includeEnd('debug'); return column * 4 + row; @@ -1118,16 +1030,13 @@ define([ */ Matrix4.getColumn = function(matrix, index, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } + Check.typeOf.object(matrix, 'matrix'); - if (typeof index !== 'number' || index < 0 || index > 3) { - throw new DeveloperError('index must be 0, 1, 2, or 3.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 3); + + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var startIndex = index * 4; @@ -1171,18 +1080,14 @@ define([ */ Matrix4.setColumn = function(matrix, index, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof index !== 'number' || index < 0 || index > 3) { - throw new DeveloperError('index must be 0, 1, 2, or 3.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 3); + + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result = Matrix4.clone(matrix, result); @@ -1205,15 +1110,9 @@ define([ */ Matrix4.setTranslation = function(matrix, translation, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(translation)) { - throw new DeveloperError('translation is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(translation, 'translation'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = matrix[0]; @@ -1268,16 +1167,13 @@ define([ */ Matrix4.getRow = function(matrix, index, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } + Check.typeOf.object(matrix, 'matrix'); - if (typeof index !== 'number' || index < 0 || index > 3) { - throw new DeveloperError('index must be 0, 1, 2, or 3.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 3); + + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var x = matrix[index]; @@ -1320,18 +1216,14 @@ define([ */ Matrix4.setRow = function(matrix, index, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (typeof index !== 'number' || index < 0 || index > 3) { - throw new DeveloperError('index must be 0, 1, 2, or 3.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + + Check.typeOf.number(index, 'index'); + Check.numeric.minimum(index, 0); + Check.numeric.maximum(index, 3); + + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result = Matrix4.clone(matrix, result); @@ -1353,12 +1245,8 @@ define([ */ Matrix4.getScale = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = Cartesian3.magnitude(Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn)); @@ -1392,15 +1280,9 @@ define([ */ Matrix4.multiply = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var left0 = left[0]; @@ -1486,15 +1368,9 @@ define([ */ Matrix4.add = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = left[0] + right[0]; @@ -1526,15 +1402,9 @@ define([ */ Matrix4.subtract = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = left[0] - right[0]; @@ -1577,15 +1447,9 @@ define([ */ Matrix4.multiplyTransformation = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var left0 = left[0]; @@ -1665,15 +1529,9 @@ define([ */ Matrix4.multiplyByMatrix3 = function(matrix, rotation, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(rotation)) { - throw new DeveloperError('rotation is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(rotation, 'rotation'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var left0 = matrix[0]; @@ -1743,15 +1601,9 @@ define([ */ Matrix4.multiplyByTranslation = function(matrix, translation, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(translation)) { - throw new DeveloperError('translation is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(translation, 'translation'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var x = translation.x; @@ -1805,15 +1657,9 @@ define([ */ Matrix4.multiplyByUniformScale = function(matrix, scale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (typeof scale !== 'number') { - throw new DeveloperError('scale is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.number(scale, 'scale'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); uniformScaleScratch.x = scale; @@ -1844,15 +1690,9 @@ define([ */ Matrix4.multiplyByScale = function(matrix, scale, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(scale)) { - throw new DeveloperError('scale is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(scale, 'scale'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var scaleX = scale.x; @@ -1893,15 +1733,9 @@ define([ */ Matrix4.multiplyByVector = function(matrix, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var vX = cartesian.x; @@ -1939,15 +1773,9 @@ define([ */ Matrix4.multiplyByPointAsVector = function(matrix, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var vX = cartesian.x; @@ -1979,16 +1807,9 @@ define([ */ Matrix4.multiplyByPoint = function(matrix, cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var vX = cartesian.x; @@ -2030,15 +1851,9 @@ define([ */ Matrix4.multiplyByScalar = function(matrix, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (typeof scalar !== 'number') { - throw new DeveloperError('scalar must be a number'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = matrix[0] * scalar; @@ -2084,12 +1899,8 @@ define([ */ Matrix4.negate = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = -matrix[0]; @@ -2135,12 +1946,8 @@ define([ */ Matrix4.transpose = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var matrix1 = matrix[1]; @@ -2178,12 +1985,8 @@ define([ */ Matrix4.abs = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = Math.abs(matrix[0]); @@ -2299,9 +2102,7 @@ define([ */ Matrix4.equalsEpsilon = function(left, right, epsilon) { //>>includeStart('debug', pragmas.debug); - if (typeof epsilon !== 'number') { - throw new DeveloperError('epsilon must be a number'); - } + Check.typeOf.number(epsilon, 'epsilon'); //>>includeEnd('debug'); return (left === right) || @@ -2334,12 +2135,8 @@ define([ */ Matrix4.getTranslation = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = matrix[12]; @@ -2372,12 +2169,8 @@ define([ */ Matrix4.getRotation = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result[0] = matrix[0]; @@ -2411,12 +2204,8 @@ define([ */ Matrix4.inverse = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); // Special case for a zero scale matrix that can occur, for example, @@ -2556,12 +2345,8 @@ define([ */ Matrix4.inverseTransformation = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(matrix, 'matrix'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); //This function is an optimized version of the below 4 lines. diff --git a/Source/Core/OrientedBoundingBox.js b/Source/Core/OrientedBoundingBox.js index 15c6b332ee08..53e0f48e28ee 100644 --- a/Source/Core/OrientedBoundingBox.js +++ b/Source/Core/OrientedBoundingBox.js @@ -199,6 +199,7 @@ define([ /** * Computes an OrientedBoundingBox given extents in the east-north-up space of the tangent plane. * + * @param {Plane} tangentPlane The tangent place corresponding to east-north-up. * @param {Number} minimumX Minimum X extent in tangent plane space. * @param {Number} maximumX Maximum X extent in tangent plane space. * @param {Number} minimumY Minimum Y extent in tangent plane space. diff --git a/Source/Core/PolygonGeometry.js b/Source/Core/PolygonGeometry.js index f8276fa5880b..44c569bde91d 100644 --- a/Source/Core/PolygonGeometry.js +++ b/Source/Core/PolygonGeometry.js @@ -123,7 +123,8 @@ define([ function computeAttributes(options) { var vertexFormat = options.vertexFormat; var geometry = options.geometry; - if (vertexFormat.st || vertexFormat.normal || vertexFormat.tangent || vertexFormat.binormal) { + var shadowVolume = options.shadowVolume; + if (vertexFormat.st || vertexFormat.normal || vertexFormat.tangent || vertexFormat.binormal || shadowVolume) { // PERFORMANCE_IDEA: Compute before subdivision, then just interpolate during subdivision. // PERFORMANCE_IDEA: Compute with createGeometryFromPositions() for fast path when there's no holes. var boundingRectangle = options.boundingRectangle; @@ -153,6 +154,7 @@ define([ } var tangents = vertexFormat.tangent ? new Float32Array(length) : undefined; var binormals = vertexFormat.binormal ? new Float32Array(length) : undefined; + var extrudeNormals = shadowVolume ? new Float32Array(length) : undefined; var textureCoordIndex = 0; var attrIndex = 0; @@ -198,7 +200,7 @@ define([ textureCoordIndex += 2; } - if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.binormal) { + if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.binormal || shadowVolume) { var attrIndex1 = attrIndex + 1; var attrIndex2 = attrIndex + 2; @@ -266,6 +268,15 @@ define([ } } + if (shadowVolume) { + if (wall) { + normal = ellipsoid.geodeticSurfaceNormal(position, normal); + } + extrudeNormals[attrIndex + bottomOffset] = -normal.x; + extrudeNormals[attrIndex1 + bottomOffset] = -normal.y; + extrudeNormals[attrIndex2 + bottomOffset] = -normal.z; + } + if (vertexFormat.tangent) { if (options.wall) { tangents[attrIndex + bottomOffset] = tangent.x; @@ -343,6 +354,14 @@ define([ values : binormals }); } + + if (shadowVolume) { + geometry.attributes.extrudeDirection = new GeometryAttribute({ + componentDatatype : ComponentDatatype.FLOAT, + componentsPerAttribute : 3, + values : extrudeNormals + }); + } } return geometry; } @@ -365,13 +384,13 @@ define([ if (closeTop && closeBottom) { var topBottomPositions = edgePoints.concat(edgePoints); + numPositions = topBottomPositions.length / 3; newIndices = IndexDatatype.createTypedArray(numPositions, indices.length * 2); newIndices.set(indices); var ilength = indices.length; - var length = numPositions / 2; for (i = 0; i < ilength; i += 3) { @@ -579,6 +598,7 @@ define([ this._closeBottom = defaultValue(options.closeBottom, true); this._polygonHierarchy = polygonHierarchy; this._perPositionHeight = perPositionHeight; + this._shadowVolume = defaultValue(options.shadowVolume, false); this._workerName = 'createPolygonGeometry'; var positions = polygonHierarchy.positions; @@ -592,7 +612,7 @@ define([ * The number of elements used to pack the object into an array. * @type {Number} */ - this.packedLength = PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 9; + this.packedLength = PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 10; } /** @@ -693,6 +713,7 @@ define([ array[startingIndex++] = value._perPositionHeight ? 1.0 : 0.0; array[startingIndex++] = value._closeTop ? 1.0 : 0.0; array[startingIndex++] = value._closeBottom ? 1.0 : 0.0; + array[startingIndex++] = value._shadowVolume ? 1.0 : 0.0; array[startingIndex] = value.packedLength; return array; @@ -744,6 +765,7 @@ define([ var perPositionHeight = array[startingIndex++] === 1.0; var closeTop = array[startingIndex++] === 1.0; var closeBottom = array[startingIndex++] === 1.0; + var shadowVolume = array[startingIndex++] === 1.0; var packedLength = array[startingIndex]; if (!defined(result)) { @@ -762,6 +784,7 @@ define([ result._closeTop = closeTop; result._closeBottom = closeBottom; result._rectangle = Rectangle.clone(rectangle); + result._shadowVolume = shadowVolume; result.packedLength = packedLength; return result; }; @@ -824,6 +847,7 @@ define([ if (extrude) { options.top = closeTop; options.bottom = closeBottom; + options.shadowVolume = polygonGeometry._shadowVolume; for (i = 0; i < polygons.length; i++) { geometry = createGeometryFromPositionsExtruded(ellipsoid, polygons[i], granularity, hierarchy[i], perPositionHeight, closeTop, closeBottom, vertexFormat); @@ -904,7 +928,8 @@ define([ perPositionHeight : false, extrudedHeight : minHeight, height : maxHeight, - vertexFormat : VertexFormat.POSITION_ONLY + vertexFormat : VertexFormat.POSITION_ONLY, + shadowVolume: true }); }; diff --git a/Source/Core/PolylinePipeline.js b/Source/Core/PolylinePipeline.js index 99422e918513..51f642a88fd8 100644 --- a/Source/Core/PolylinePipeline.js +++ b/Source/Core/PolylinePipeline.js @@ -202,10 +202,10 @@ define([ /** * Subdivides polyline and raises all points to the specified height. Returns an array of numbers to represent the positions. - * @param {Cartesian3[]} positions The array of type {Cartesian3} representing positions. - * @param {Number|Number[]} [height=0.0] A number or array of numbers representing the heights of each position. - * @param {Number} [granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer. - * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie. + * @param {Cartesian3[]} options.positions The array of type {Cartesian3} representing positions. + * @param {Number|Number[]} [options.height=0.0] A number or array of numbers representing the heights of each position. + * @param {Number} [options.granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer. + * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie. * @returns {Number[]} A new array of positions of type {Number} that have been subdivided and raised to the surface of the ellipsoid. * * @example @@ -289,10 +289,10 @@ define([ /** * Subdivides polyline and raises all points to the specified height. Returns an array of new {Cartesian3} positions. - * @param {Cartesian3[]} positions The array of type {Cartesian3} representing positions. - * @param {Number|Number[]} [height=0.0] A number or array of numbers representing the heights of each position. - * @param {Number} [granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer. - * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie. + * @param {Cartesian3[]} options.positions The array of type {Cartesian3} representing positions. + * @param {Number|Number[]} [options.height=0.0] A number or array of numbers representing the heights of each position. + * @param {Number} [options.granularity = CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer. + * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the positions lie. * @returns {Cartesian3[]} A new array of cartesian3 positions that have been subdivided and raised to the surface of the ellipsoid. * * @example diff --git a/Source/Core/Quaternion.js b/Source/Core/Quaternion.js index bef64c819ff8..ea095baf1e23 100644 --- a/Source/Core/Quaternion.js +++ b/Source/Core/Quaternion.js @@ -1,6 +1,7 @@ /*global define*/ define([ './Cartesian3', + './Check', './defaultValue', './defined', './DeveloperError', @@ -10,6 +11,7 @@ define([ './Matrix3' ], function( Cartesian3, + Check, defaultValue, defined, DeveloperError, @@ -73,12 +75,8 @@ define([ */ Quaternion.fromAxisAngle = function(axis, angle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(axis)) { - throw new DeveloperError('axis is required.'); - } - if (typeof angle !== 'number') { - throw new DeveloperError('angle is required and must be a number.'); - } + Check.typeOf.object(axis, 'axis'); + Check.typeOf.number(angle, 'angle'); //>>includeEnd('debug'); var halfAngle = angle / 2.0; @@ -112,9 +110,7 @@ define([ */ Quaternion.fromRotationMatrix = function(matrix, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(matrix)) { - throw new DeveloperError('matrix is required.'); - } + Check.typeOf.object(matrix, 'matrix'); //>>includeEnd('debug'); var root; @@ -190,15 +186,9 @@ define([ */ Quaternion.fromHeadingPitchRoll = function(heading, pitch, roll, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(heading)) { - throw new DeveloperError('heading is required.'); - } - if (!defined(pitch)) { - throw new DeveloperError('pitch is required.'); - } - if (!defined(roll)) { - throw new DeveloperError('roll is required.'); - } + Check.typeOf.number(heading, 'heading'); + Check.typeOf.number(pitch, 'pitch'); + Check.typeOf.number(roll, 'roll'); //>>includeEnd('debug'); var rollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, roll, scratchHPRQuaternion); @@ -231,13 +221,8 @@ define([ */ Quaternion.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('value is required'); - } - - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.typeOf.object(value, 'value'); + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -260,9 +245,7 @@ define([ */ Quaternion.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -318,7 +301,7 @@ define([ * * @param {Number[]} array The array previously packed for interpolation. * @param {Number[]} sourceArray The original packed array. - * @param {Number} [startingIndex=0] The startingIndex used to convert the array. + * @param {Number} [firstIndex=0] The firstIndex used to convert the array. * @param {Number} [lastIndex=packedArray.length] The lastIndex used to convert the array. * @param {Quaternion} [result] The object into which to store the result. * @returns {Quaternion} The modified result parameter or a new Quaternion instance if one was not provided. @@ -373,12 +356,8 @@ define([ */ Quaternion.conjugate = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = -quaternion.x; @@ -396,9 +375,7 @@ define([ */ Quaternion.magnitudeSquared = function(quaternion) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); //>>includeEnd('debug'); return quaternion.x * quaternion.x + quaternion.y * quaternion.y + quaternion.z * quaternion.z + quaternion.w * quaternion.w; @@ -423,9 +400,7 @@ define([ */ Quaternion.normalize = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var inverseMagnitude = 1.0 / Quaternion.magnitude(quaternion); @@ -450,9 +425,7 @@ define([ */ Quaternion.inverse = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var magnitudeSquared = Quaternion.magnitudeSquared(quaternion); @@ -470,15 +443,9 @@ define([ */ Quaternion.add = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = left.x + right.x; @@ -498,15 +465,9 @@ define([ */ Quaternion.subtract = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = left.x - right.x; @@ -525,12 +486,8 @@ define([ */ Quaternion.negate = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = -quaternion.x; @@ -549,12 +506,8 @@ define([ */ Quaternion.dot = function(left, right) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); //>>includeEnd('debug'); return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w; @@ -570,15 +523,9 @@ define([ */ Quaternion.multiply = function(left, right, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(left)) { - throw new DeveloperError('left is required'); - } - if (!defined(right)) { - throw new DeveloperError('right is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(left, 'left'); + Check.typeOf.object(right, 'right'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var leftX = left.x; @@ -613,15 +560,9 @@ define([ */ Quaternion.multiplyByScalar = function(quaternion, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } - if (typeof scalar !== 'number') { - throw new DeveloperError('scalar is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = quaternion.x * scalar; @@ -641,15 +582,9 @@ define([ */ Quaternion.divideByScalar = function(quaternion, scalar, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } - if (typeof scalar !== 'number') { - throw new DeveloperError('scalar is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); + Check.typeOf.number(scalar, 'scalar'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); result.x = quaternion.x / scalar; @@ -668,12 +603,8 @@ define([ */ Quaternion.computeAxis = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var w = quaternion.w; @@ -698,9 +629,7 @@ define([ */ Quaternion.computeAngle = function(quaternion) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); //>>includeEnd('debug'); if (Math.abs(quaternion.w - 1.0) < CesiumMath.EPSILON6) { @@ -721,18 +650,10 @@ define([ */ Quaternion.lerp = function(start, end, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(start)) { - throw new DeveloperError('start is required.'); - } - if (!defined(end)) { - throw new DeveloperError('end is required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(start, 'start'); + Check.typeOf.object(end, 'end'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); lerpScratch = Quaternion.multiplyByScalar(end, t, lerpScratch); @@ -756,18 +677,10 @@ define([ */ Quaternion.slerp = function(start, end, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(start)) { - throw new DeveloperError('start is required.'); - } - if (!defined(end)) { - throw new DeveloperError('end is required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(start, 'start'); + Check.typeOf.object(end, 'end'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var dot = Quaternion.dot(start, end); @@ -802,12 +715,8 @@ define([ */ Quaternion.log = function(quaternion, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(quaternion, 'quaternion'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var theta = CesiumMath.acosClamped(quaternion.w); @@ -829,12 +738,8 @@ define([ */ Quaternion.exp = function(cartesian, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian)) { - throw new DeveloperError('cartesian is required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(cartesian, 'cartesian'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var theta = Cartesian3.magnitude(cartesian); @@ -871,12 +776,10 @@ define([ */ Quaternion.computeInnerQuadrangle = function(q0, q1, q2, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(q0) || !defined(q1) || !defined(q2)) { - throw new DeveloperError('q0, q1, and q2 are required.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(q0, 'q0'); + Check.typeOf.object(q1, 'q1'); + Check.typeOf.object(q2, 'q2'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var qInv = Quaternion.conjugate(q1, squadScratchQuaternion0); @@ -920,15 +823,12 @@ define([ */ Quaternion.squad = function(q0, q1, s0, s1, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(q0) || !defined(q1) || !defined(s0) || !defined(s1)) { - throw new DeveloperError('q0, q1, s0, and s1 are required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(q0, 'q0'); + Check.typeOf.object(q1, 'q1'); + Check.typeOf.object(s0, 's0'); + Check.typeOf.object(s1, 's1'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var slerp0 = Quaternion.slerp(q0, q1, t, squadScratchQuaternion0); @@ -967,18 +867,10 @@ define([ */ Quaternion.fastSlerp = function(start, end, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(start)) { - throw new DeveloperError('start is required.'); - } - if (!defined(end)) { - throw new DeveloperError('end is required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(start, 'start'); + Check.typeOf.object(end, 'end'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var x = Quaternion.dot(start, end); @@ -1029,15 +921,12 @@ define([ */ Quaternion.fastSquad = function(q0, q1, s0, s1, t, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(q0) || !defined(q1) || !defined(s0) || !defined(s1)) { - throw new DeveloperError('q0, q1, s0, and s1 are required.'); - } - if (typeof t !== 'number') { - throw new DeveloperError('t is required and must be a number.'); - } - if (!defined(result)) { - throw new DeveloperError('result is required'); - } + Check.typeOf.object(q0, 'q0'); + Check.typeOf.object(q1, 'q1'); + Check.typeOf.object(s0, 's0'); + Check.typeOf.object(s1, 's1'); + Check.typeOf.number(t, 't'); + Check.typeOf.object(result, 'result'); //>>includeEnd('debug'); var slerp0 = Quaternion.fastSlerp(q0, q1, t, squadScratchQuaternion0); @@ -1075,9 +964,7 @@ define([ */ Quaternion.equalsEpsilon = function(left, right, epsilon) { //>>includeStart('debug', pragmas.debug); - if (typeof epsilon !== 'number') { - throw new DeveloperError('epsilon is required and must be a number.'); - } + Check.typeOf.number(epsilon, 'epsilon'); //>>includeEnd('debug'); return (left === right) || diff --git a/Source/Core/Rectangle.js b/Source/Core/Rectangle.js index e8b8ea1d1888..bc6a5df3e041 100644 --- a/Source/Core/Rectangle.js +++ b/Source/Core/Rectangle.js @@ -1,6 +1,7 @@ /*global define*/ define([ './Cartographic', + './Check', './defaultValue', './defined', './defineProperties', @@ -10,6 +11,7 @@ define([ './Math' ], function( Cartographic, + Check, defaultValue, defined, defineProperties, @@ -107,13 +109,8 @@ define([ */ Rectangle.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('value is required'); - } - - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.typeOf.object(value, 'value'); + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -136,9 +133,7 @@ define([ */ Rectangle.unpack = function(array, startingIndex, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(array)) { - throw new DeveloperError('array is required'); - } + Check.defined(array, 'array'); //>>includeEnd('debug'); startingIndex = defaultValue(startingIndex, 0); @@ -161,9 +156,7 @@ define([ */ Rectangle.computeWidth = function(rectangle) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required.'); - } + Check.typeOf.object(rectangle, 'rectangle'); //>>includeEnd('debug'); var east = rectangle.east; var west = rectangle.west; @@ -180,9 +173,7 @@ define([ */ Rectangle.computeHeight = function(rectangle) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required.'); - } + Check.typeOf.object(rectangle, 'rectangle'); //>>includeEnd('debug'); return rectangle.north - rectangle.south; }; @@ -227,9 +218,7 @@ define([ */ Rectangle.fromCartographicArray = function(cartographics, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartographics)) { - throw new DeveloperError('cartographics is required.'); - } + Check.defined(cartographics, 'cartographics'); //>>includeEnd('debug'); var west = Number.MAX_VALUE; @@ -284,9 +273,7 @@ define([ */ Rectangle.fromCartesianArray = function(cartesians, ellipsoid, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesians)) { - throw new DeveloperError('cartesians is required.'); - } + Check.defined(cartesians, 'cartesians'); //>>includeEnd('debug'); var west = Number.MAX_VALUE; @@ -404,9 +391,7 @@ define([ */ Rectangle.prototype.equalsEpsilon = function(other, epsilon) { //>>includeStart('debug', pragmas.debug); - if (typeof epsilon !== 'number') { - throw new DeveloperError('epsilon is required and must be a number.'); - } + Check.typeOf.number(epsilon, 'epsilon'); //>>includeEnd('debug'); return defined(other) && @@ -428,45 +413,27 @@ define([ */ Rectangle.validate = function(rectangle) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } + Check.typeOf.object(rectangle, 'rectangle'); var north = rectangle.north; - if (typeof north !== 'number') { - throw new DeveloperError('north is required to be a number.'); - } - - if (north < -CesiumMath.PI_OVER_TWO || north > CesiumMath.PI_OVER_TWO) { - throw new DeveloperError('north must be in the interval [-Pi/2, Pi/2].'); - } + Check.typeOf.number(north, 'north'); + Check.numeric.minimum(north, -CesiumMath.PI_OVER_TWO); + Check.numeric.maximum(north, CesiumMath.PI_OVER_TWO); var south = rectangle.south; - if (typeof south !== 'number') { - throw new DeveloperError('south is required to be a number.'); - } - - if (south < -CesiumMath.PI_OVER_TWO || south > CesiumMath.PI_OVER_TWO) { - throw new DeveloperError('south must be in the interval [-Pi/2, Pi/2].'); - } + Check.typeOf.number(south, 'south'); + Check.numeric.minimum(south, -CesiumMath.PI_OVER_TWO); + Check.numeric.maximum(south, CesiumMath.PI_OVER_TWO); var west = rectangle.west; - if (typeof west !== 'number') { - throw new DeveloperError('west is required to be a number.'); - } - - if (west < -Math.PI || west > Math.PI) { - throw new DeveloperError('west must be in the interval [-Pi, Pi].'); - } + Check.typeOf.number(west, 'west'); + Check.numeric.minimum(west, -Math.PI); + Check.numeric.maximum(west, Math.PI); var east = rectangle.east; - if (typeof east !== 'number') { - throw new DeveloperError('east is required to be a number.'); - } - - if (east < -Math.PI || east > Math.PI) { - throw new DeveloperError('east must be in the interval [-Pi, Pi].'); - } + Check.typeOf.number(east, 'east'); + Check.numeric.minimum(east, -Math.PI); + Check.numeric.maximum(east, Math.PI); //>>includeEnd('debug'); }; @@ -479,9 +446,7 @@ define([ */ Rectangle.southwest = function(rectangle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } + Check.typeOf.object(rectangle, 'rectangle'); //>>includeEnd('debug'); if (!defined(result)) { @@ -502,9 +467,7 @@ define([ */ Rectangle.northwest = function(rectangle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } + Check.typeOf.object(rectangle, 'rectangle'); //>>includeEnd('debug'); if (!defined(result)) { @@ -525,9 +488,7 @@ define([ */ Rectangle.northeast = function(rectangle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } + Check.typeOf.object(rectangle, 'rectangle'); //>>includeEnd('debug'); if (!defined(result)) { @@ -548,9 +509,7 @@ define([ */ Rectangle.southeast = function(rectangle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } + Check.typeOf.object(rectangle, 'rectangle'); //>>includeEnd('debug'); if (!defined(result)) { @@ -571,9 +530,7 @@ define([ */ Rectangle.center = function(rectangle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } + Check.typeOf.object(rectangle, 'rectangle'); //>>includeEnd('debug'); var east = rectangle.east; @@ -610,12 +567,8 @@ define([ */ Rectangle.intersection = function(rectangle, otherRectangle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } - if (!defined(otherRectangle)) { - throw new DeveloperError('otherRectangle is required.'); - } + Check.typeOf.object(rectangle, 'rectangle'); + Check.typeOf.object(otherRectangle, 'otherRectangle'); //>>includeEnd('debug'); var rectangleEast = rectangle.east; @@ -673,12 +626,8 @@ define([ */ Rectangle.simpleIntersection = function(rectangle, otherRectangle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } - if (!defined(otherRectangle)) { - throw new DeveloperError('otherRectangle is required.'); - } + Check.typeOf.object(rectangle, 'rectangle'); + Check.typeOf.object(otherRectangle, 'otherRectangle'); //>>includeEnd('debug'); var west = Math.max(rectangle.west, otherRectangle.west); @@ -711,12 +660,8 @@ define([ */ Rectangle.union = function(rectangle, otherRectangle, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } - if (!defined(otherRectangle)) { - throw new DeveloperError('otherRectangle is required.'); - } + Check.typeOf.object(rectangle, 'rectangle'); + Check.typeOf.object(otherRectangle, 'otherRectangle'); //>>includeEnd('debug'); if (!defined(result)) { @@ -762,12 +707,8 @@ define([ */ Rectangle.expand = function(rectangle, cartographic, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required.'); - } - if (!defined(cartographic)) { - throw new DeveloperError('cartographic is required.'); - } + Check.typeOf.object(rectangle, 'rectangle'); + Check.typeOf.object(cartographic, 'cartographic'); //>>includeEnd('debug'); if (!defined(result)) { @@ -791,12 +732,8 @@ define([ */ Rectangle.contains = function(rectangle, cartographic) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } - if (!defined(cartographic)) { - throw new DeveloperError('cartographic is required.'); - } + Check.typeOf.object(rectangle, 'rectangle'); + Check.typeOf.object(cartographic, 'cartographic'); //>>includeEnd('debug'); var longitude = cartographic.longitude; @@ -831,9 +768,7 @@ define([ */ Rectangle.subsample = function(rectangle, ellipsoid, surfaceHeight, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required'); - } + Check.typeOf.object(rectangle, 'rectangle'); //>>includeEnd('debug'); ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84); diff --git a/Source/Core/RectangleGeometry.js b/Source/Core/RectangleGeometry.js index 420b95cceeb4..4ee7ff3bb69d 100644 --- a/Source/Core/RectangleGeometry.js +++ b/Source/Core/RectangleGeometry.js @@ -330,7 +330,9 @@ define([ return wallTextures; } + var scratchVertexFormat = new VertexFormat(); function constructExtrudedRectangle(options) { + var shadowVolume = options.shadowVolume; var vertexFormat = options.vertexFormat; var surfaceHeight = options.surfaceHeight; var extrudedHeight = options.extrudedHeight; @@ -342,10 +344,15 @@ define([ var ellipsoid = options.ellipsoid; var i; + if (shadowVolume) { + options.vertexFormat = VertexFormat.clone(vertexFormat, scratchVertexFormat); + options.vertexFormat.normal = true; + } var topBottomGeo = constructRectangle(options); if (CesiumMath.equalsEpsilon(minHeight, maxHeight, CesiumMath.EPSILON10)) { return topBottomGeo; } + var topPositions = PolygonPipeline.scaleToGeodeticHeight(topBottomGeo.attributes.position.values, maxHeight, ellipsoid, false); topPositions = new Float64Array(topPositions); var length = topPositions.length; @@ -361,8 +368,9 @@ define([ var binormals = (vertexFormat.binormal) ? new Float32Array(newLength) : undefined; var textures = (vertexFormat.st) ? new Float32Array(newLength/3*2) : undefined; var topSt; + var topNormals; if (vertexFormat.normal) { - var topNormals = topBottomGeo.attributes.normal.values; + topNormals = topBottomGeo.attributes.normal.values; normals.set(topNormals); for (i = 0; i < length; i ++) { topNormals[i] = -topNormals[i]; @@ -370,6 +378,23 @@ define([ normals.set(topNormals, length); topBottomGeo.attributes.normal.values = normals; } + if (shadowVolume) { + topNormals = topBottomGeo.attributes.normal.values; + if (!vertexFormat.normal) { + topBottomGeo.attributes.normal = undefined; + } + var extrudeNormals = new Float32Array(newLength); + for (i = 0; i < length; i ++) { + topNormals[i] = -topNormals[i]; + } + extrudeNormals.set(topNormals, length); //only get normals for bottom layer that's going to be pushed down + topBottomGeo.attributes.extrudeDirection = new GeometryAttribute({ + componentDatatype : ComponentDatatype.FLOAT, + componentsPerAttribute : 3, + values : extrudeNormals + }); + } + if (vertexFormat.tangent) { var topTangents = topBottomGeo.attributes.tangent.values; tangents.set(topTangents); @@ -408,45 +433,76 @@ define([ var wallCount = (perimeterPositions + 4) * 2; var wallPositions = new Float64Array(wallCount * 3); + var wallExtrudeNormals = shadowVolume ? new Float32Array(wallCount * 3) : undefined; var wallTextures = (vertexFormat.st) ? new Float32Array(wallCount * 2) : undefined; var posIndex = 0; var stIndex = 0; + var extrudeNormalIndex = 0; var area = width * height; + var threeI; for (i = 0; i < area; i+=width) { - wallPositions = addWallPositions(wallPositions, posIndex, i*3, topPositions, bottomPositions); + threeI = i * 3; + wallPositions = addWallPositions(wallPositions, posIndex, threeI, topPositions, bottomPositions); posIndex += 6; if (vertexFormat.st) { wallTextures = addWallTextureCoordinates(wallTextures, stIndex, i*2, topSt); stIndex += 4; } + if (shadowVolume) { + extrudeNormalIndex += 3; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI]; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 1]; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 2]; + } } for (i = area-width; i < area; i++) { - wallPositions = addWallPositions(wallPositions, posIndex, i*3, topPositions, bottomPositions); + threeI = i * 3; + wallPositions = addWallPositions(wallPositions, posIndex, threeI, topPositions, bottomPositions); posIndex += 6; if (vertexFormat.st) { wallTextures = addWallTextureCoordinates(wallTextures, stIndex, i*2, topSt); stIndex += 4; } + if (shadowVolume) { + extrudeNormalIndex += 3; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI]; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 1]; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 2]; + } } for (i = area-1; i > 0; i-=width) { - wallPositions = addWallPositions(wallPositions, posIndex, i*3, topPositions, bottomPositions); + threeI = i * 3; + wallPositions = addWallPositions(wallPositions, posIndex, threeI, topPositions, bottomPositions); posIndex += 6; if (vertexFormat.st) { wallTextures = addWallTextureCoordinates(wallTextures, stIndex, i*2, topSt); stIndex += 4; } + if (shadowVolume) { + extrudeNormalIndex += 3; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI]; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 1]; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 2]; + } } for (i = width-1; i >= 0; i--) { - wallPositions = addWallPositions(wallPositions, posIndex, i*3, topPositions, bottomPositions); + threeI = i * 3; + wallPositions = addWallPositions(wallPositions, posIndex, threeI, topPositions, bottomPositions); posIndex += 6; if (vertexFormat.st) { wallTextures = addWallTextureCoordinates(wallTextures, stIndex, i*2, topSt); stIndex += 4; } + if (shadowVolume) { + extrudeNormalIndex += 3; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI]; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 1]; + wallExtrudeNormals[extrudeNormalIndex++] = topNormals[threeI + 2]; + } } var geo = calculateAttributesWall(wallPositions, vertexFormat, ellipsoid); @@ -458,6 +514,13 @@ define([ values : wallTextures }); } + if (shadowVolume) { + geo.attributes.extrudeDirection = new GeometryAttribute({ + componentDatatype : ComponentDatatype.FLOAT, + componentsPerAttribute : 3, + values : wallExtrudeNormals + }); + } var wallIndices = IndexDatatype.createTypedArray(wallCount, perimeterPositions * 6); @@ -582,16 +645,6 @@ define([ options = defaultValue(options, defaultValue.EMPTY_OBJECT); var rectangle = options.rectangle; - var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); - var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); - var surfaceHeight = defaultValue(options.height, 0.0); - var rotation = defaultValue(options.rotation, 0.0); - var stRotation = defaultValue(options.stRotation, 0.0); - var vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); - var extrudedHeight = options.extrudedHeight; - var extrude = defined(extrudedHeight); - var closeTop = defaultValue(options.closeTop, true); - var closeBottom = defaultValue(options.closeBottom, true); //>>includeStart('debug', pragmas.debug); if (!defined(rectangle)) { @@ -603,17 +656,19 @@ define([ } //>>includeEnd('debug'); + var rotation = defaultValue(options.rotation, 0.0); this._rectangle = rectangle; - this._granularity = granularity; - this._ellipsoid = Ellipsoid.clone(ellipsoid); - this._surfaceHeight = surfaceHeight; + this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE); + this._ellipsoid = Ellipsoid.clone(defaultValue(options.ellipsoid, Ellipsoid.WGS84)); + this._surfaceHeight = defaultValue(options.height, 0.0); this._rotation = rotation; - this._stRotation = stRotation; - this._vertexFormat = VertexFormat.clone(vertexFormat); - this._extrudedHeight = defaultValue(extrudedHeight, 0.0); - this._extrude = extrude; - this._closeTop = closeTop; - this._closeBottom = closeBottom; + this._stRotation = defaultValue(options.stRotation, 0.0); + this._vertexFormat = VertexFormat.clone(defaultValue(options.vertexFormat, VertexFormat.DEFAULT)); + this._extrudedHeight = defaultValue(options.extrudedHeight, 0.0); + this._extrude = defined(options.extrudedHeight); + this._closeTop = defaultValue(options.closeTop, true); + this._closeBottom = defaultValue(options.closeBottom, true); + this._shadowVolume = defaultValue(options.shadowVolume, false); this._workerName = 'createRectangleGeometry'; this._rotatedRectangle = computeRectangle(this._rectangle, this._ellipsoid, rotation); } @@ -622,7 +677,7 @@ define([ * The number of elements used to pack the object into an array. * @type {Number} */ - RectangleGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 8; + RectangleGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 9; /** * Stores the provided instance into the provided array. @@ -665,7 +720,8 @@ define([ array[startingIndex++] = value._extrudedHeight; array[startingIndex++] = value._extrude ? 1.0 : 0.0; array[startingIndex++] = value._closeTop ? 1.0 : 0.0; - array[startingIndex] = value._closeBottom ? 1.0 : 0.0; + array[startingIndex++] = value._closeBottom ? 1.0 : 0.0; + array[startingIndex] = value._shadowVolume ? 1.0 : 0.0; return array; }; @@ -673,7 +729,6 @@ define([ var scratchRectangle = new Rectangle(); var scratchRotatedRectangle = new Rectangle(); var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE); - var scratchVertexFormat = new VertexFormat(); var scratchOptions = { rectangle : scratchRectangle, ellipsoid : scratchEllipsoid, @@ -684,7 +739,8 @@ define([ stRotation : undefined, extrudedHeight : undefined, closeTop : undefined, - closeBottom : undefined + closeBottom : undefined, + shadowVolume: undefined }; /** @@ -723,7 +779,8 @@ define([ var extrudedHeight = array[startingIndex++]; var extrude = array[startingIndex++] === 1.0; var closeTop = array[startingIndex++] === 1.0; - var closeBottom = array[startingIndex] === 1.0; + var closeBottom = array[startingIndex++] === 1.0; + var shadowVolume = array[startingIndex] === 1.0; if (!defined(result)) { scratchOptions.granularity = granularity; @@ -733,6 +790,7 @@ define([ scratchOptions.extrudedHeight = extrude ? extrudedHeight : undefined; scratchOptions.closeTop = closeTop; scratchOptions.closeBottom = closeBottom; + scratchOptions.shadowVolume = shadowVolume; return new RectangleGeometry(scratchOptions); } @@ -748,6 +806,7 @@ define([ result._closeTop = closeTop; result._closeBottom = closeBottom; result._rotatedRectangle = rotatedRectangle; + result._shadowVolume = shadowVolume; return result; }; @@ -804,6 +863,7 @@ define([ var boundingSphere; rectangle = rectangleGeometry._rectangle; if (extrude) { + options.shadowVolume = rectangleGeometry._shadowVolume; geometry = constructExtrudedRectangle(options); var topBS = BoundingSphere.fromRectangle3D(rectangle, ellipsoid, surfaceHeight, topBoundingSphere); var bottomBS = BoundingSphere.fromRectangle3D(rectangle, ellipsoid, extrudedHeight, bottomBoundingSphere); @@ -819,7 +879,7 @@ define([ } return new Geometry({ - attributes : new GeometryAttributes(geometry.attributes), + attributes : geometry.attributes, indices : geometry.indices, primitiveType : geometry.primitiveType, boundingSphere : boundingSphere @@ -847,7 +907,8 @@ define([ height : minHeight, closeTop : true, closeBottom : true, - vertexFormat : VertexFormat.POSITION_ONLY + vertexFormat : VertexFormat.POSITION_ONLY, + shadowVolume: true }); }; diff --git a/Source/Core/Simon1994PlanetaryPositions.js b/Source/Core/Simon1994PlanetaryPositions.js index 84cc17a037c3..1a824012333e 100644 --- a/Source/Core/Simon1994PlanetaryPositions.js +++ b/Source/Core/Simon1994PlanetaryPositions.js @@ -509,9 +509,9 @@ define([ * @param {Cartesian3} [result] The object onto which to store the result. * @returns {Cartesian3} Calculated sun position */ - Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame= function(date, result){ - if (!defined(date)) { - date = JulianDate.now(); + Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame= function(julianDate, result){ + if (!defined(julianDate)) { + julianDate = JulianDate.now(); } if (!defined(result)) { @@ -519,11 +519,11 @@ define([ } //first forward transformation - translation = computeSimonEarthMoonBarycenter(date, translation); + translation = computeSimonEarthMoonBarycenter(julianDate, translation); result = Cartesian3.negate(translation, result); //second forward transformation - computeSimonEarth(date, translation); + computeSimonEarth(julianDate, translation); Cartesian3.subtract(result, translation, result); Matrix3.multiplyByVector(axesTransformation, result, result); @@ -538,12 +538,12 @@ define([ * @param {Cartesian3} [result] The object onto which to store the result. * @returns {Cartesian3} Calculated moon position */ - Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame = function(date, result){ - if (!defined(date)) { - date = JulianDate.now(); + Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame = function(julianDate, result){ + if (!defined(julianDate)) { + julianDate = JulianDate.now(); } - result = computeSimonMoon(date, result); + result = computeSimonMoon(julianDate, result); Matrix3.multiplyByVector(axesTransformation, result, result); return result; diff --git a/Source/Core/SphereGeometry.js b/Source/Core/SphereGeometry.js index 4e8ac00ca349..a05f58a854a4 100644 --- a/Source/Core/SphereGeometry.js +++ b/Source/Core/SphereGeometry.js @@ -1,6 +1,7 @@ /*global define*/ define([ './Cartesian3', + './Check', './defaultValue', './defined', './DeveloperError', @@ -8,6 +9,7 @@ define([ './VertexFormat' ], function( Cartesian3, + Check, defaultValue, defined, DeveloperError, @@ -70,9 +72,7 @@ define([ */ SphereGeometry.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('value is required'); - } + Check.typeOf.object(value, 'value'); //>>includeEnd('debug'); return EllipsoidGeometry.pack(value._ellipsoidGeometry, array, startingIndex); diff --git a/Source/Core/SphereOutlineGeometry.js b/Source/Core/SphereOutlineGeometry.js index 1d1a627d19fa..e74f9961e727 100644 --- a/Source/Core/SphereOutlineGeometry.js +++ b/Source/Core/SphereOutlineGeometry.js @@ -1,12 +1,14 @@ /*global define*/ define([ './Cartesian3', + './Check', './defaultValue', './defined', './DeveloperError', './EllipsoidOutlineGeometry' ], function( Cartesian3, + Check, defaultValue, defined, DeveloperError, @@ -68,9 +70,7 @@ define([ */ SphereOutlineGeometry.pack = function(value, array, startingIndex) { //>>includeStart('debug', pragmas.debug); - if (!defined(value)) { - throw new DeveloperError('value is required'); - } + Check.typeOf.object(value, 'value'); //>>includeEnd('debug'); return EllipsoidOutlineGeometry.pack(value._ellipsoidGeometry, array, startingIndex); diff --git a/Source/Core/Spherical.js b/Source/Core/Spherical.js index 0222c247a6cb..b87c7c9466e7 100644 --- a/Source/Core/Spherical.js +++ b/Source/Core/Spherical.js @@ -1,9 +1,11 @@ /*global define*/ define([ + './Check', './defaultValue', './defined', './DeveloperError' ], function( + Check, defaultValue, defined, DeveloperError) { @@ -29,14 +31,12 @@ define([ * Converts the provided Cartesian3 into Spherical coordinates. * * @param {Cartesian3} cartesian3 The Cartesian3 to be converted to Spherical. - * @param {Spherical} [spherical] The object in which the result will be stored, if undefined a new instance will be created. + * @param {Spherical} [result] The object in which the result will be stored, if undefined a new instance will be created. * @returns {Spherical} The modified result parameter, or a new instance if one was not provided. */ Spherical.fromCartesian3 = function(cartesian3, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(cartesian3)) { - throw new DeveloperError('cartesian3 is required'); - } + Check.typeOf.object(cartesian3, 'cartesian3'); //>>includeEnd('debug'); var x = cartesian3.x; @@ -85,9 +85,7 @@ define([ */ Spherical.normalize = function(spherical, result) { //>>includeStart('debug', pragmas.debug); - if (!defined(spherical)) { - throw new DeveloperError('spherical is required'); - } + Check.typeOf.object(spherical, 'spherical'); //>>includeEnd('debug'); if (!defined(result)) { diff --git a/Source/Core/TerrainMesh.js b/Source/Core/TerrainMesh.js index de2534d819c9..4c25c7990ecf 100644 --- a/Source/Core/TerrainMesh.js +++ b/Source/Core/TerrainMesh.js @@ -27,6 +27,7 @@ define([ * @param {Number} [vertexStride=6] The number of components in each vertex. * @param {OrientedBoundingBox} [orientedBoundingBox] A bounding box that completely contains the tile. * @param {TerrainEncoding} encoding Information used to decode the mesh. + * @param {Number} exaggeration The amount that this mesh was exaggerated. * * @private */ diff --git a/Source/Core/TimeIntervalCollection.js b/Source/Core/TimeIntervalCollection.js index bc1c79ebbd38..0dd6e21784aa 100644 --- a/Source/Core/TimeIntervalCollection.js +++ b/Source/Core/TimeIntervalCollection.js @@ -217,8 +217,8 @@ define([ * @param {JulianDate} julianDate The date to check. * @returns {Boolean} true if the collection contains the specified date, false otherwise. */ - TimeIntervalCollection.prototype.contains = function(date) { - return this.indexOf(date) >= 0; + TimeIntervalCollection.prototype.contains = function(julianDate) { + return this.indexOf(julianDate) >= 0; }; var indexOfScratch = new TimeInterval(); diff --git a/Source/Core/Transforms.js b/Source/Core/Transforms.js index b02cd3eb6af2..b9ebfef6f1ff 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -5,9 +5,9 @@ define([ './Cartesian3', './Cartesian4', './Cartographic', + './Check', './defaultValue', './defined', - './deprecationWarning', './DeveloperError', './EarthOrientationParameters', './EarthOrientationParametersSample', @@ -27,9 +27,9 @@ define([ Cartesian3, Cartesian4, Cartographic, + Check, defaultValue, defined, - deprecationWarning, DeveloperError, EarthOrientationParameters, EarthOrientationParametersSample, @@ -473,19 +473,12 @@ define([ * var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); * var transform = Cesium.Transforms.headingPitchRollToFixedFrame(center, hpr); */ - Transforms.headingPitchRollToFixedFrame = function(origin, headingPitchRoll, pitch, roll, ellipsoid, result) { - var heading; - if (typeof headingPitchRoll === 'object') { - // Shift arguments using assignments to encourage JIT optimization. - ellipsoid = pitch; - result = roll; - heading = headingPitchRoll.heading; - pitch = headingPitchRoll.pitch; - roll = headingPitchRoll.roll; - } else { - deprecationWarning('headingPitchRollToFixedFrame', 'headingPitchRollToFixedFrame with separate heading, pitch, and roll arguments was deprecated in 1.27. It will be removed in 1.30. Use a HeadingPitchRoll object.'); - heading = headingPitchRoll; - } + Transforms.headingPitchRollToFixedFrame = function(origin, headingPitchRoll, ellipsoid, result) { + Check.typeOf.object(headingPitchRoll, 'headingPitchRoll'); + var heading = headingPitchRoll.heading; + var pitch = headingPitchRoll.pitch; + var roll = headingPitchRoll.roll; + // checks for required parameters happen in the called functions var hprQuaternion = Quaternion.fromHeadingPitchRoll(heading, pitch, roll, scratchHPRQuaternion); var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, hprQuaternion, scratchScale, scratchHPRMatrix4); @@ -493,7 +486,6 @@ define([ return Matrix4.multiply(result, hprMatrix, result); }; - var scratchHPR = new HeadingPitchRoll(); var scratchENUMatrix4 = new Matrix4(); var scratchHPRMatrix3 = new Matrix3(); @@ -518,22 +510,10 @@ define([ * var hpr = new HeadingPitchRoll(heading, pitch, roll); * var quaternion = Cesium.Transforms.headingPitchRollQuaternion(center, hpr); */ - Transforms.headingPitchRollQuaternion = function(origin, headingPitchRoll, pitch, roll, ellipsoid, result) { - var hpr; - if (typeof headingPitchRoll === 'object') { - // Shift arguments using assignment to encourage JIT optimization. - hpr = headingPitchRoll; - ellipsoid = pitch; - result = roll; - } else { - deprecationWarning('headingPitchRollQuaternion', 'headingPitchRollQuaternion with separate heading, pitch, and roll arguments was deprecated in 1.27. It will be removed in 1.30. Use a HeadingPitchRoll object.'); - scratchHPR.heading = headingPitchRoll; - scratchHPR.pitch = pitch; - scratchHPR.roll = roll; - hpr = scratchHPR; - } + Transforms.headingPitchRollQuaternion = function(origin, headingPitchRoll, ellipsoid, result) { // checks for required parameters happen in the called functions - var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, ellipsoid, scratchENUMatrix4); + Check.typeOf.object(headingPitchRoll, 'headingPitchRoll'); + var transform = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, scratchENUMatrix4); var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3); return Quaternion.fromRotationMatrix(rotation, result); }; diff --git a/Source/Core/VertexFormat.js b/Source/Core/VertexFormat.js index a1709d6c3206..50a8a0c835b2 100644 --- a/Source/Core/VertexFormat.js +++ b/Source/Core/VertexFormat.js @@ -285,7 +285,7 @@ define([ /** * Duplicates a VertexFormat instance. * - * @param {VertexFormat} cartesian The vertex format to duplicate. + * @param {VertexFormat} vertexFormat The vertex format to duplicate. * @param {VertexFormat} [result] The object onto which to store the result. * @returns {VertexFormat} The modified result parameter or a new VertexFormat instance if one was not provided. (Returns undefined if vertexFormat is undefined) */ diff --git a/Source/Core/getImagePixels.js b/Source/Core/getImagePixels.js index f728c81cb164..e65f025eec84 100644 --- a/Source/Core/getImagePixels.js +++ b/Source/Core/getImagePixels.js @@ -14,6 +14,8 @@ define([ * @exports getImagePixels * * @param {Image} image The image to extract pixels from. + * @param {Number} width The width of the image. If not defined, then image.width is assigned. + * @param {Number} height The height of the image. If not defined, then image.height is assigned. * @returns {CanvasPixelArray} The pixels of the image. */ function getImagePixels(image, width, height) { diff --git a/Source/DataSources/CorridorGeometryUpdater.js b/Source/DataSources/CorridorGeometryUpdater.js index 79bf46bca8a7..839d47b534e0 100644 --- a/Source/DataSources/CorridorGeometryUpdater.js +++ b/Source/DataSources/CorridorGeometryUpdater.js @@ -243,7 +243,7 @@ define([ * Gets the property specifying whether the geometry * casts or receives shadows from each light source. * @memberof CorridorGeometryUpdater.prototype - * + * * @type {Property} * @readonly */ @@ -552,6 +552,7 @@ define([ * Creates the dynamic updater to be used when GeometryUpdater#isDynamic is true. * * @param {PrimitiveCollection} primitives The primitive collection to use. + * @param {PrimitiveCollection} groundPrimitives The ground primitives collection to use. * @returns {DynamicGeometryUpdater} The dynamic updater used to update the geometry each frame. * * @exception {DeveloperError} This instance does not represent dynamic geometry. diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index deae371cca05..e2d4cca84f41 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -1854,7 +1854,7 @@ define([ /** * Creates a Promise to a new instance loaded with the provided CZML data. * - * @param {String|Object} data A url or CZML object to be processed. + * @param {String|Object} czml A url or CZML object to be processed. * @param {Object} [options] An object with the following properties: * @param {String} [options.sourceUri] Overrides the url to use for resolving relative links. * @returns {Promise.} A promise that resolves to the new instance once the data is processed. diff --git a/Source/DataSources/DataSourceCollection.js b/Source/DataSources/DataSourceCollection.js index 374b8a0dbe62..ca2e44f2e0a7 100644 --- a/Source/DataSources/DataSourceCollection.js +++ b/Source/DataSources/DataSourceCollection.js @@ -166,6 +166,7 @@ define([ * Gets a data source by index from the collection. * * @param {Number} index the index to retrieve. + * @returns {DataSource} The data source at the specified index. */ DataSourceCollection.prototype.get = function(index) { //>>includeStart('debug', pragmas.debug); diff --git a/Source/DataSources/EllipseGeometryUpdater.js b/Source/DataSources/EllipseGeometryUpdater.js index 59176bb1004a..e47c1a4af98c 100644 --- a/Source/DataSources/EllipseGeometryUpdater.js +++ b/Source/DataSources/EllipseGeometryUpdater.js @@ -246,7 +246,7 @@ define([ * Gets the property specifying whether the geometry * casts or receives shadows from each light source. * @memberof EllipseGeometryUpdater.prototype - * + * * @type {Property} * @readonly */ @@ -566,6 +566,7 @@ define([ * Creates the dynamic updater to be used when GeometryUpdater#isDynamic is true. * * @param {PrimitiveCollection} primitives The primitive collection to use. + * @param {PrimitiveCollection} groundPrimitives The ground primitives collection to use. * @returns {DynamicGeometryUpdater} The dynamic updater used to update the geometry each frame. * * @exception {DeveloperError} This instance does not represent dynamic geometry. diff --git a/Source/DataSources/EntityView.js b/Source/DataSources/EntityView.js index e6653e3fa8d9..b8857df00372 100644 --- a/Source/DataSources/EntityView.js +++ b/Source/DataSources/EntityView.js @@ -258,7 +258,7 @@ define([ * Should be called each animation frame to update the camera * to the latest settings. * @param {JulianDate} time The current animation time. - * @param {BoundingSphere} current bounding sphere of the object. + * @param {BoundingSphere} boundingSphere bounding sphere of the object. * */ EntityView.prototype.update = function(time, boundingSphere) { diff --git a/Source/DataSources/KmlDataSource.js b/Source/DataSources/KmlDataSource.js index 43f4bba6d2c8..bd7636d8abb1 100644 --- a/Source/DataSources/KmlDataSource.js +++ b/Source/DataSources/KmlDataSource.js @@ -489,7 +489,7 @@ define([ var colorOptions = {}; function parseColorString(value, isRandom) { - if (!defined(value)) { + if (!defined(value) || /^\s*$/gm.test(value)) { return undefined; } diff --git a/Source/DataSources/ModelVisualizer.js b/Source/DataSources/ModelVisualizer.js index bd00c0ae9829..a066931b4456 100644 --- a/Source/DataSources/ModelVisualizer.js +++ b/Source/DataSources/ModelVisualizer.js @@ -42,7 +42,6 @@ define([ var defaultColorBlendMode = ColorBlendMode.HIGHLIGHT; var defaultColorBlendAmount = 0.5; - var color = new Color(); var modelMatrixScratch = new Matrix4(); var nodeMatrixScratch = new Matrix4(); @@ -149,9 +148,9 @@ define([ model.shadows = Property.getValueOrDefault(modelGraphics._shadows, time, defaultShadows); model.heightReference = Property.getValueOrDefault(modelGraphics._heightReference, time, defaultHeightReference); model.distanceDisplayCondition = Property.getValueOrUndefined(modelGraphics._distanceDisplayCondition, time); - model.silhouetteColor = Property.getValueOrDefault(modelGraphics.silhouetteColor, time, defaultSilhouetteColor); - model.silhouetteSize = Property.getValueOrDefault(modelGraphics.silhouetteSize, time, defaultSilhouetteSize); - model.color = Property.getValueOrDefault(modelGraphics._color, time, defaultColor, color); + model.silhouetteColor = Property.getValueOrDefault(modelGraphics._silhouetteColor, time, defaultSilhouetteColor, model._silhouetteColor); + model.silhouetteSize = Property.getValueOrDefault(modelGraphics._silhouetteSize, time, defaultSilhouetteSize); + model.color = Property.getValueOrDefault(modelGraphics._color, time, defaultColor, model._color); model.colorBlendMode = Property.getValueOrDefault(modelGraphics._colorBlendMode, time, defaultColorBlendMode); model.colorBlendAmount = Property.getValueOrDefault(modelGraphics._colorBlendAmount, time, defaultColorBlendAmount); diff --git a/Source/DataSources/PolygonGeometryUpdater.js b/Source/DataSources/PolygonGeometryUpdater.js index cd98be03885f..3aac6923c32e 100644 --- a/Source/DataSources/PolygonGeometryUpdater.js +++ b/Source/DataSources/PolygonGeometryUpdater.js @@ -248,7 +248,7 @@ define([ * Gets the property specifying whether the geometry * casts or receives shadows from each light source. * @memberof PolygonGeometryUpdater.prototype - * + * * @type {Property} * @readonly */ @@ -582,6 +582,7 @@ define([ * Creates the dynamic updater to be used when GeometryUpdater#isDynamic is true. * * @param {PrimitiveCollection} primitives The primitive collection to use. + * @param {PrimitiveCollection} groundPrimitives The ground primitive collection to use. * @returns {DynamicGeometryUpdater} The dynamic updater used to update the geometry each frame. * * @exception {DeveloperError} This instance does not represent dynamic geometry. @@ -663,7 +664,7 @@ define([ options.closeBottom = closeBottomValue; var shadows = this._geometryUpdater.shadowsProperty.getValue(time); - + if (Property.getValueOrDefault(polygon.fill, time, true)) { var fillMaterialProperty = geometryUpdater.fillMaterialProperty; var material = MaterialProperty.getValue(time, fillMaterialProperty, this._material); diff --git a/Source/DataSources/Rotation.js b/Source/DataSources/Rotation.js index 467690f24ddb..3f1480576cc1 100755 --- a/Source/DataSources/Rotation.js +++ b/Source/DataSources/Rotation.js @@ -124,7 +124,7 @@ define([ * * @param {Number[]} array The array previously packed for interpolation. * @param {Number[]} sourceArray The original packed array. - * @param {Number} [startingIndex=0] The startingIndex used to convert the array. + * @param {Number} [firstIndex=0] The firstIndex used to convert the array. * @param {Number} [lastIndex=packedArray.length] The lastIndex used to convert the array. * @param {Rotation} [result] The object into which to store the result. * @returns {Rotation} The modified result parameter or a new Rotation instance if one was not provided. diff --git a/Source/DataSources/SampledPositionProperty.js b/Source/DataSources/SampledPositionProperty.js index 1d9062ec7b44..d524d26d60a1 100644 --- a/Source/DataSources/SampledPositionProperty.js +++ b/Source/DataSources/SampledPositionProperty.js @@ -274,8 +274,8 @@ define([ * @param {Number[]} packedSamples The array of packed samples. * @param {JulianDate} [epoch] If any of the dates in packedSamples are numbers, they are considered an offset from this epoch, in seconds. */ - SampledPositionProperty.prototype.addSamplesPackedArray = function(data, epoch) { - this._property.addSamplesPackedArray(data, epoch); + SampledPositionProperty.prototype.addSamplesPackedArray = function(packedSamples, epoch) { + this._property.addSamplesPackedArray(packedSamples, epoch); }; /** diff --git a/Source/Renderer/AutomaticUniforms.js b/Source/Renderer/AutomaticUniforms.js index 6957c7d16db3..6f71025bf1cb 100644 --- a/Source/Renderer/AutomaticUniforms.js +++ b/Source/Renderer/AutomaticUniforms.js @@ -1476,6 +1476,20 @@ define([ getValue : function(uniformState) { return uniformState.fogDensity; } + }), + + /** + * An automatic GLSL uniform scalar representing the geometric tolerance per meter + * + * @alias czm_geometricToleranceOverMeter + * @glslUniform + */ + czm_geometricToleranceOverMeter : new AutomaticUniform({ + size: 1, + datatype: WebGLConstants.FLOAT, + getValue: function(uniformState) { + return uniformState.geometricToleranceOverMeter; + } }) }; diff --git a/Source/Renderer/Buffer.js b/Source/Renderer/Buffer.js index fc4ee4b8bc8c..edb489e7d313 100644 --- a/Source/Renderer/Buffer.js +++ b/Source/Renderer/Buffer.js @@ -145,7 +145,7 @@ define([ * @param {ArrayBufferView} [options.typedArray] A typed array containing the data to copy to the buffer. * @param {Number} [options.sizeInBytes] A Number defining the size of the buffer in bytes. Required if options.typedArray is not given. * @param {BufferUsage} options.usage Specifies the expected usage pattern of the buffer. On some GL implementations, this can significantly affect performance. See {@link BufferUsage}. - * @param {IndexDatatype} indexDatatype The datatype of indices in the buffer. + * @param {IndexDatatype} options.indexDatatype The datatype of indices in the buffer. * @returns {IndexBuffer} The index buffer, ready to be attached to a vertex array. * * @exception {DeveloperError} Must specify either or , but not both. diff --git a/Source/Renderer/ComputeCommand.js b/Source/Renderer/ComputeCommand.js index 8d0231c673bc..1eb7f2a24888 100644 --- a/Source/Renderer/ComputeCommand.js +++ b/Source/Renderer/ComputeCommand.js @@ -108,7 +108,7 @@ define([ /** * Executes the compute command. * - * @param {Context} context The context that processes the compute command. + * @param {Context} computeEngine The context that processes the compute command. */ ComputeCommand.prototype.execute = function(computeEngine) { computeEngine.execute(this); diff --git a/Source/Renderer/UniformState.js b/Source/Renderer/UniformState.js index 49ddc5cd50dd..e0f77ea724d3 100644 --- a/Source/Renderer/UniformState.js +++ b/Source/Renderer/UniformState.js @@ -149,6 +149,9 @@ define([ this._resolutionScale = 1.0; this._fogDensity = undefined; + + this._pixelSizePerMeter = undefined; + this._geometricToleranceOverMeter = undefined; } defineProperties(UniformState.prototype, { @@ -767,6 +770,17 @@ define([ } }, + /** + * A scalar that represents the geometric tolerance per meter + * @memberof UniformStat.prototype + * @type {Number} + */ + geometricToleranceOverMeter: { + get: function() { + return this._geometricToleranceOverMeter; + } + }, + /** * @memberof UniformState.prototype * @type {Pass} @@ -935,6 +949,17 @@ define([ this._frameState = frameState; this._temeToPseudoFixed = Transforms.computeTemeToPseudoFixedMatrix(frameState.time, this._temeToPseudoFixed); + + var fov = camera.frustum.fov; + var viewport = this._viewport; + var pixelSizePerMeter; + if (viewport.height > viewport.width) { + pixelSizePerMeter = Math.tan(0.5 * fov) * 2.0 / viewport.height; + } else { + pixelSizePerMeter = Math.tan(0.5 * fov) * 2.0 / viewport.width; + } + + this._geometricToleranceOverMeter = pixelSizePerMeter * frameState.maximumScreenSpaceError; }; function cleanViewport(uniformState) { diff --git a/Source/Scene/BingMapsImageryProvider.js b/Source/Scene/BingMapsImageryProvider.js index 90368068d2b6..726b209a2104 100644 --- a/Source/Scene/BingMapsImageryProvider.js +++ b/Source/Scene/BingMapsImageryProvider.js @@ -557,7 +557,7 @@ define([ * instances. The array may be empty if no features are found at the given location. * It may also be undefined if picking is not supported. */ - BingMapsImageryProvider.prototype.pickFeatures = function() { + BingMapsImageryProvider.prototype.pickFeatures = function(x, y, level, longitude, latitude) { return undefined; }; diff --git a/Source/Scene/CameraEventAggregator.js b/Source/Scene/CameraEventAggregator.js index 05154071f1fc..78e6e7206451 100644 --- a/Source/Scene/CameraEventAggregator.js +++ b/Source/Scene/CameraEventAggregator.js @@ -252,7 +252,7 @@ define([ * @alias CameraEventAggregator * @constructor * - * @param {Canvas} [element=document] The element to handle events for. + * @param {Canvas} [canvas=document] The element to handle events for. * * @see ScreenSpaceEventHandler */ diff --git a/Source/Scene/CreditDisplay.js b/Source/Scene/CreditDisplay.js index 270a447e7d95..395512488550 100644 --- a/Source/Scene/CreditDisplay.js +++ b/Source/Scene/CreditDisplay.js @@ -270,8 +270,6 @@ define([ /** * Resets the credit display to a beginning of frame state, clearing out current credits. - * - * @param {Credit} credit The credit to display */ CreditDisplay.prototype.beginFrame = function() { this._currentFrameCredits.imageCredits.length = 0; @@ -280,8 +278,6 @@ define([ /** * Sets the credit display to the end of frame state, displaying current credits in the credit container - * - * @param {Credit} credit The credit to display */ CreditDisplay.prototype.endFrame = function() { var textCredits = this._defaultTextCredits.concat(this._currentFrameCredits.textCredits); diff --git a/Source/Scene/FrameState.js b/Source/Scene/FrameState.js index 94b47ab960ff..03a043a8d367 100644 --- a/Source/Scene/FrameState.js +++ b/Source/Scene/FrameState.js @@ -110,6 +110,15 @@ define([ */ this.occluder = undefined; + /** + * The maximum screen-space error used to drive level-of-detail refinement. Higher + * values will provide better performance but lower visual quality. + * + * @type {Number} + * @default 2 + */ + this.maximumScreenSpaceError = undefined; + this.passes = { /** * true if the primitive should update for a render pass, false otherwise. diff --git a/Source/Scene/GoogleEarthImageryProvider.js b/Source/Scene/GoogleEarthImageryProvider.js index c85499489183..40dfc0ea0836 100644 --- a/Source/Scene/GoogleEarthImageryProvider.js +++ b/Source/Scene/GoogleEarthImageryProvider.js @@ -97,7 +97,7 @@ define([ * url : 'https://earth.localdomain', * channel : 1008 * }); - * + * * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} */ function GoogleEarthImageryProvider(options) { @@ -571,7 +571,7 @@ define([ * instances. The array may be empty if no features are found at the given location. * It may also be undefined if picking is not supported. */ - GoogleEarthImageryProvider.prototype.pickFeatures = function() { + GoogleEarthImageryProvider.prototype.pickFeatures = function(x, y, level, longitude, latitude) { return undefined; }; diff --git a/Source/Scene/GridImageryProvider.js b/Source/Scene/GridImageryProvider.js index 9741cc731896..a761703b9c49 100644 --- a/Source/Scene/GridImageryProvider.js +++ b/Source/Scene/GridImageryProvider.js @@ -37,7 +37,7 @@ define([ * @param {Color} [options.color=Color(1.0, 1.0, 1.0, 0.4)] The color to draw grid lines. * @param {Color} [options.glowColor=Color(0.0, 1.0, 0.0, 0.05)] The color to draw glow for grid lines. * @param {Number} [options.glowWidth=6] The width of lines used for rendering the line glow effect. - * @param {Color} [backgroundColor=Color(0.0, 0.5, 0.0, 0.2)] Background fill color. + * @param {Color} [options.backgroundColor=Color(0.0, 0.5, 0.0, 0.2)] Background fill color. * @param {Number} [options.tileWidth=256] The width of the tile for level-of-detail selection purposes. * @param {Number} [options.tileHeight=256] The height of the tile for level-of-detail selection purposes. * @param {Number} [options.canvasSize=256] The size of the canvas used for rendering. @@ -345,7 +345,7 @@ define([ * instances. The array may be empty if no features are found at the given location. * It may also be undefined if picking is not supported. */ - GridImageryProvider.prototype.pickFeatures = function() { + GridImageryProvider.prototype.pickFeatures = function(x, y, level, longitude, latitude) { return undefined; }; diff --git a/Source/Scene/GroundPrimitive.js b/Source/Scene/GroundPrimitive.js index 9939662eea12..eadf4b5cfe50 100644 --- a/Source/Scene/GroundPrimitive.js +++ b/Source/Scene/GroundPrimitive.js @@ -5,6 +5,7 @@ define([ '../Core/Cartesian2', '../Core/Cartesian3', '../Core/Cartographic', + '../Core/clone', '../Core/Color', '../Core/ColorGeometryInstanceAttribute', '../Core/defaultValue', @@ -40,6 +41,7 @@ define([ Cartesian2, Cartesian3, Cartographic, + clone, Color, ColorGeometryInstanceAttribute, defaultValue, @@ -196,9 +198,7 @@ define([ /** * This property is for debugging only; it is not for production use nor is it optimized. *

- * Draws the shadow volume for each geometry in the primitive. Must be true on - * creation for the volumes to be created before the geometry is released or releaseGeometryInstances - * must be false + * Draws the shadow volume for each geometry in the primitive. *

* * @type {Boolean} @@ -206,6 +206,7 @@ define([ * @default false */ this.debugShowShadowVolume = defaultValue(options.debugShowShadowVolume, false); + this._debugShowShadowVolume = false; this._sp = undefined; this._spPick = undefined; @@ -215,7 +216,11 @@ define([ this._rsColorPass = undefined; this._rsPickPass = undefined; - this._uniformMap = {}; + this._uniformMap = { + u_globeMinimumAltitude: function() { + return 55000.0; + } + }; this._boundingVolumes = []; this._boundingVolumes2D = []; @@ -224,7 +229,6 @@ define([ this._readyPromise = when.defer(); this._primitive = undefined; - this._debugPrimitive = undefined; this._maxHeight = undefined; this._minHeight = undefined; @@ -419,91 +423,98 @@ define([ }; } - var stencilPreloadRenderState = { - colorMask : { - red : false, - green : false, - blue : false, - alpha : false - }, - stencilTest : { - enabled : true, - frontFunction : StencilFunction.ALWAYS, - frontOperation : { - fail : StencilOperation.KEEP, - zFail : StencilOperation.DECREMENT_WRAP, - zPass : StencilOperation.DECREMENT_WRAP + function getStencilPreloadRenderState(enableStencil) { + return { + colorMask : { + red : false, + green : false, + blue : false, + alpha : false }, - backFunction : StencilFunction.ALWAYS, - backOperation : { - fail : StencilOperation.KEEP, - zFail : StencilOperation.INCREMENT_WRAP, - zPass : StencilOperation.INCREMENT_WRAP + stencilTest : { + enabled : enableStencil, + frontFunction : StencilFunction.ALWAYS, + frontOperation : { + fail : StencilOperation.KEEP, + zFail : StencilOperation.DECREMENT_WRAP, + zPass : StencilOperation.DECREMENT_WRAP + }, + backFunction : StencilFunction.ALWAYS, + backOperation : { + fail : StencilOperation.KEEP, + zFail : StencilOperation.INCREMENT_WRAP, + zPass : StencilOperation.INCREMENT_WRAP + }, + reference : 0, + mask : ~0 }, - reference : 0, - mask : ~0 - }, - depthTest : { - enabled : false - }, - depthMask : false - }; + depthTest : { + enabled : false + }, + depthMask : false + }; + } - var stencilDepthRenderState = { - colorMask : { - red : false, - green : false, - blue : false, - alpha : false - }, - stencilTest : { - enabled : true, - frontFunction : StencilFunction.ALWAYS, - frontOperation : { - fail : StencilOperation.KEEP, - zFail : StencilOperation.KEEP, - zPass : StencilOperation.INCREMENT_WRAP + function getStencilDepthRenderState(enableStencil) { + return { + colorMask : { + red : false, + green : false, + blue : false, + alpha : false }, - backFunction : StencilFunction.ALWAYS, - backOperation : { - fail : StencilOperation.KEEP, - zFail : StencilOperation.KEEP, - zPass : StencilOperation.DECREMENT_WRAP + stencilTest : { + enabled : enableStencil, + frontFunction : StencilFunction.ALWAYS, + frontOperation : { + fail : StencilOperation.KEEP, + zFail : StencilOperation.KEEP, + zPass : StencilOperation.INCREMENT_WRAP + }, + backFunction : StencilFunction.ALWAYS, + backOperation : { + fail : StencilOperation.KEEP, + zFail : StencilOperation.KEEP, + zPass : StencilOperation.DECREMENT_WRAP + }, + reference : 0, + mask : ~0 }, - reference : 0, - mask : ~0 - }, - depthTest : { - enabled : true, - func : DepthFunction.LESS_OR_EQUAL - }, - depthMask : false - }; + depthTest : { + enabled : true, + func : DepthFunction.LESS_OR_EQUAL + }, + depthMask : false + }; + } - var colorRenderState = { - stencilTest : { - enabled : true, - frontFunction : StencilFunction.NOT_EQUAL, - frontOperation : { - fail : StencilOperation.KEEP, - zFail : StencilOperation.KEEP, - zPass : StencilOperation.DECREMENT_WRAP + + function getColorRenderState(enableStencil) { + return { + stencilTest : { + enabled : enableStencil, + frontFunction : StencilFunction.NOT_EQUAL, + frontOperation : { + fail : StencilOperation.KEEP, + zFail : StencilOperation.KEEP, + zPass : StencilOperation.DECREMENT_WRAP + }, + backFunction : StencilFunction.NOT_EQUAL, + backOperation : { + fail : StencilOperation.KEEP, + zFail : StencilOperation.KEEP, + zPass : StencilOperation.DECREMENT_WRAP + }, + reference : 0, + mask : ~0 }, - backFunction : StencilFunction.NOT_EQUAL, - backOperation : { - fail : StencilOperation.KEEP, - zFail : StencilOperation.KEEP, - zPass : StencilOperation.DECREMENT_WRAP + depthTest : { + enabled : false }, - reference : 0, - mask : ~0 - }, - depthTest : { - enabled : false - }, - depthMask : false, - blending : BlendingState.ALPHA_BLEND - }; + depthMask : false, + blending : BlendingState.ALPHA_BLEND + }; + } var pickRenderState = { stencilTest : { @@ -688,66 +699,96 @@ define([ return BoundingSphere.union(result, scratchBoundingSphere, result); } - function createBoundingVolume(primitive, frameState, geometry) { + function createBoundingVolume(groundPrimitive, frameState, geometry) { var ellipsoid = frameState.mapProjection.ellipsoid; var rectangle = getRectangle(frameState, geometry); // Use an oriented bounding box by default, but switch to a bounding sphere if bounding box creation would fail. if (rectangle.width < CesiumMath.PI) { - var obb = OrientedBoundingBox.fromRectangle(rectangle, primitive._maxHeight, primitive._minHeight, ellipsoid); - primitive._boundingVolumes.push(obb); + var obb = OrientedBoundingBox.fromRectangle(rectangle, groundPrimitive._maxHeight, groundPrimitive._minHeight, ellipsoid); + groundPrimitive._boundingVolumes.push(obb); } else { var highPositions = geometry.attributes.position3DHigh.values; var lowPositions = geometry.attributes.position3DLow.values; - primitive._boundingVolumes.push(BoundingSphere.fromEncodedCartesianVertices(highPositions, lowPositions)); + groundPrimitive._boundingVolumes.push(BoundingSphere.fromEncodedCartesianVertices(highPositions, lowPositions)); } if (!frameState.scene3DOnly) { var projection = frameState.mapProjection; - var boundingVolume = BoundingSphere.fromRectangleWithHeights2D(rectangle, projection, primitive._maxHeight, primitive._minHeight); + var boundingVolume = BoundingSphere.fromRectangleWithHeights2D(rectangle, projection, groundPrimitive._maxHeight, groundPrimitive._minHeight); Cartesian3.fromElements(boundingVolume.center.z, boundingVolume.center.x, boundingVolume.center.y, boundingVolume.center); - primitive._boundingVolumes2D.push(boundingVolume); + groundPrimitive._boundingVolumes2D.push(boundingVolume); } } - function createRenderStates(primitive, context, appearance, twoPasses) { - if (defined(primitive._rsStencilPreloadPass)) { + function createRenderStates(groundPrimitive, context, appearance, twoPasses) { + if (defined(groundPrimitive._rsStencilPreloadPass)) { return; } + var stencilEnabled = !groundPrimitive.debugShowShadowVolume; - primitive._rsStencilPreloadPass = RenderState.fromCache(stencilPreloadRenderState); - primitive._rsStencilDepthPass = RenderState.fromCache(stencilDepthRenderState); - primitive._rsColorPass = RenderState.fromCache(colorRenderState); - primitive._rsPickPass = RenderState.fromCache(pickRenderState); + groundPrimitive._rsStencilPreloadPass = RenderState.fromCache(getStencilPreloadRenderState(stencilEnabled)); + groundPrimitive._rsStencilDepthPass = RenderState.fromCache(getStencilDepthRenderState(stencilEnabled)); + groundPrimitive._rsColorPass = RenderState.fromCache(getColorRenderState(stencilEnabled)); + groundPrimitive._rsPickPass = RenderState.fromCache(pickRenderState); } - function createShaderProgram(primitive, frameState, appearance) { - if (defined(primitive._sp)) { + function modifyForEncodedNormals(primitive, vertexShaderSource) { + if (!primitive.compressVertices) { + return vertexShaderSource; + } + + if (vertexShaderSource.search(/attribute\s+vec3\s+extrudeDirection;/g) !== -1) { + var attributeName = 'compressedAttributes'; + + //only shadow volumes use extrudeDirection, and shadow volumes use vertexFormat: POSITION_ONLY so we don't need to check other attributes + var attributeDecl = 'attribute vec2 ' + attributeName + ';'; + + var globalDecl = 'vec3 extrudeDirection;\n'; + var decode = ' extrudeDirection = czm_octDecode(' + attributeName + ', 65535.0);\n'; + + var modifiedVS = vertexShaderSource; + modifiedVS = modifiedVS.replace(/attribute\s+vec3\s+extrudeDirection;/g, ''); + modifiedVS = ShaderSource.replaceMain(modifiedVS, 'czm_non_compressed_main'); + var compressedMain = + 'void main() \n' + + '{ \n' + + decode + + ' czm_non_compressed_main(); \n' + + '}'; + + return [attributeDecl, globalDecl, modifiedVS, compressedMain].join('\n'); + } + } + + function createShaderProgram(groundPrimitive, frameState, appearance) { + if (defined(groundPrimitive._sp)) { return; } var context = frameState.context; - + var primitive = groundPrimitive._primitive; var vs = ShadowVolumeVS; - vs = primitive._primitive._batchTable.getVertexShaderCallback()(vs); - vs = Primitive._appendShowToShader(primitive._primitive, vs); - vs = Primitive._appendDistanceDisplayConditionToShader(primitive._primitive, vs); - vs = Primitive._modifyShaderPosition(primitive, vs, frameState.scene3DOnly); - vs = Primitive._updateColorAttribute(primitive._primitive, vs); + vs = groundPrimitive._primitive._batchTable.getVertexShaderCallback()(vs); + vs = Primitive._appendShowToShader(primitive, vs); + vs = Primitive._appendDistanceDisplayConditionToShader(primitive, vs); + vs = Primitive._modifyShaderPosition(groundPrimitive, vs, frameState.scene3DOnly); + vs = Primitive._updateColorAttribute(primitive, vs); + vs = modifyForEncodedNormals(primitive, vs); var fs = ShadowVolumeFS; - var attributeLocations = primitive._primitive._attributeLocations; + var attributeLocations = groundPrimitive._primitive._attributeLocations; - primitive._sp = ShaderProgram.replaceCache({ + groundPrimitive._sp = ShaderProgram.replaceCache({ context : context, - shaderProgram : primitive._sp, + shaderProgram : groundPrimitive._sp, vertexShaderSource : vs, fragmentShaderSource : fs, attributeLocations : attributeLocations }); - if (primitive._primitive.allowPicking) { + if (groundPrimitive._primitive.allowPicking) { var vsPick = ShaderSource.createPickVertexShaderSource(vs); vsPick = Primitive._updatePickColorAttribute(vsPick); @@ -755,15 +796,15 @@ define([ sources : [fs], pickColorQualifier : 'varying' }); - primitive._spPick = ShaderProgram.replaceCache({ + groundPrimitive._spPick = ShaderProgram.replaceCache({ context : context, - shaderProgram : primitive._spPick, + shaderProgram : groundPrimitive._spPick, vertexShaderSource : vsPick, fragmentShaderSource : pickFS, attributeLocations : attributeLocations }); } else { - primitive._spPick = ShaderProgram.fromCache({ + groundPrimitive._spPick = ShaderProgram.fromCache({ context : context, vertexShaderSource : vs, fragmentShaderSource : fs, @@ -1007,8 +1048,10 @@ define([ return; } + var that = this; + var primitiveOptions = this._primitiveOptions; + if (!defined(this._primitive)) { - var primitiveOptions = this._primitiveOptions; var ellipsoid = frameState.mapProjection.ellipsoid; var instance; @@ -1082,7 +1125,6 @@ define([ primitiveOptions.geometryInstances = groundInstances; - var that = this; primitiveOptions._createBoundingVolumeFunction = function(frameState, geometry) { createBoundingVolume(that, frameState, geometry); }; @@ -1116,52 +1158,20 @@ define([ }); } - this._primitive.debugShowBoundingVolume = this.debugShowBoundingVolume; - this._primitive.update(frameState); - - if (this.debugShowShadowVolume && !defined(this._debugPrimitive) && defined(this.geometryInstances)) { - var debugInstances = isArray(this.geometryInstances) ? this.geometryInstances : [this.geometryInstances]; - var debugLength = debugInstances.length; - var debugVolumeInstances = new Array(debugLength); - - for (var j = 0 ; j < debugLength; ++j) { - var debugInstance = debugInstances[j]; - var debugGeometry = debugInstance.geometry; - var debugInstanceType = debugGeometry.constructor; - if (defined(debugInstanceType) && defined(debugInstanceType.createShadowVolume)) { - var debugColorArray = debugInstance.attributes.color.value; - var debugColor = Color.fromBytes(debugColorArray[0], debugColorArray[1], debugColorArray[2], debugColorArray[3]); - Color.subtract(new Color(1.0, 1.0, 1.0, 0.0), debugColor, debugColor); - debugVolumeInstances[j] = new GeometryInstance({ - geometry : debugInstanceType.createShadowVolume(debugGeometry, getComputeMinimumHeightFunction(this), getComputeMaximumHeightFunction(this)), - attributes : { - color : ColorGeometryInstanceAttribute.fromColor(debugColor) - }, - id : debugInstance.id, - pickPrimitive : this - }); - } - } - - this._debugPrimitive = new Primitive({ - geometryInstances : debugVolumeInstances, - releaseGeometryInstances : true, - allowPicking : false, - asynchronous : false, - appearance : new PerInstanceColorAppearance({ - flat : true - }) - }); + if (this.debugShowShadowVolume && !this._debugShowShadowVolume && this._ready) { + this._debugShowShadowVolume = true; + this._rsStencilPreloadPass = RenderState.fromCache(getStencilPreloadRenderState(false)); + this._rsStencilDepthPass = RenderState.fromCache(getStencilDepthRenderState(false)); + this._rsColorPass = RenderState.fromCache(getColorRenderState(false)); + } else if (!this.debugShowShadowVolume && this._debugShowShadowVolume) { + this._debugShowShadowVolume = false; + this._rsStencilPreloadPass = RenderState.fromCache(getStencilPreloadRenderState(true)); + this._rsStencilDepthPass = RenderState.fromCache(getStencilDepthRenderState(true)); + this._rsColorPass = RenderState.fromCache(getColorRenderState(true)); } - if (defined(this._debugPrimitive)) { - if (this.debugShowShadowVolume) { - this._debugPrimitive.update(frameState); - } else { - this._debugPrimitive.destroy(); - this._debugPrimitive = undefined; - } - } + this._primitive.debugShowBoundingVolume = this.debugShowBoundingVolume; + this._primitive.update(frameState); }; /** @@ -1233,7 +1243,6 @@ define([ */ GroundPrimitive.prototype.destroy = function() { this._primitive = this._primitive && this._primitive.destroy(); - this._debugPrimitive = this._debugPrimitive && this._debugPrimitive.destroy(); this._sp = this._sp && this._sp.destroy(); this._spPick = this._spPick && this._spPick.destroy(); return destroyObject(this); diff --git a/Source/Scene/ImageryLayer.js b/Source/Scene/ImageryLayer.js index 6f8897daaee1..887d84d5bfc2 100644 --- a/Source/Scene/ImageryLayer.js +++ b/Source/Scene/ImageryLayer.js @@ -576,7 +576,7 @@ define([ if (!defined(clippedImageryRectangle)) { continue; } - + minV = Math.max(0.0, (clippedImageryRectangle.south - terrainRectangle.south) / terrainRectangle.height); // If this is the southern-most imagery tile mapped to this terrain tile, @@ -1073,6 +1073,7 @@ define([ /** * Gets the level with the specified world coordinate spacing between texels, or less. * + * @param {ImageryLayer} layer The imagery layer to use. * @param {Number} texelSpacing The texel spacing for which to find a corresponding level. * @param {Number} latitudeClosestToEquator The latitude closest to the equator that we're concerned with. * @returns {Number} The level with the specified texel spacing or less. diff --git a/Source/Scene/Material.js b/Source/Scene/Material.js index 11a8bf488089..c48952fa276f 100644 --- a/Source/Scene/Material.js +++ b/Source/Scene/Material.js @@ -1381,7 +1381,7 @@ define([ }, translucent : function(material) { var uniforms = material.uniforms; - return (uniforms.fadeInColor.alpha < 1.0) || (uniforms.fadeOutColor.alpha < 0.0); + return (uniforms.fadeInColor.alpha < 1.0) || (uniforms.fadeOutColor.alpha < 1.0); } }); diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 2345ac19b578..0205d33c27a7 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -439,6 +439,7 @@ define([ */ this.silhouetteColor = defaultValue(options.silhouetteColor, Color.RED); this._silhouetteColor = new Color(); + this._silhouetteColorPreviousAlpha = 1.0; this._normalAttributeName = undefined; /** @@ -577,6 +578,7 @@ define([ */ this.color = defaultValue(options.color, Color.WHITE); this._color = new Color(); + this._colorPreviousAlpha = 1.0; /** * Defines how the color blends with the model. @@ -4002,12 +4004,12 @@ define([ } var nodeCommands = model._nodeCommands; - var dirty = alphaDirty(model.color.alpha, model._color.alpha) || - alphaDirty(model.silhouetteColor.alpha, model._silhouetteColor.alpha) || + var dirty = alphaDirty(model.color.alpha, model._colorPreviousAlpha) || + alphaDirty(model.silhouetteColor.alpha, model._silhouetteColorPreviousAlpha) || !defined(nodeCommands[0].silhouetteModelCommand); - Color.clone(model.color, model._color); - Color.clone(model.silhouetteColor, model._silhouetteColor); + model._colorPreviousAlpha = model.color.alpha; + model._silhouetteColorPreviousAlpha = model.silhouetteColor.alpha; if (dirty) { createSilhouetteCommands(model, frameState); diff --git a/Source/Scene/Polyline.js b/Source/Scene/Polyline.js index e88365516fdf..f73352d37eca 100644 --- a/Source/Scene/Polyline.js +++ b/Source/Scene/Polyline.js @@ -41,6 +41,7 @@ define([ * @param {Cartesian3[]} [options.positions] The positions. * @param {Object} [options.id] The user-defined object to be returned when this polyline is picked. * @param {DistanceDisplayCondition} [options.distanceDisplayCondition] The condition specifying at what distance from the camera that this polyline will be displayed. + * @param {PolylineCollection} polylineCollection The renderable polyline collection. * * @see PolylineCollection * diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 88f9d7a77612..6487b9af7815 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -1181,6 +1181,11 @@ define([ frameState.cullingVolume = camera.frustum.computeCullingVolume(camera.positionWC, camera.directionWC, camera.upWC); frameState.occluder = getOccluder(scene); frameState.terrainExaggeration = scene._terrainExaggeration; + if (defined(scene.globe)) { + frameState.maximumScreenSpaceError = scene.globe.maximumScreenSpaceError; + } else { + frameState.maximumScreenSpaceError = 2; + } clearPasses(frameState.passes); } diff --git a/Source/Scene/SingleTileImageryProvider.js b/Source/Scene/SingleTileImageryProvider.js index 258c5a7c526b..4d59f9fbd8e7 100644 --- a/Source/Scene/SingleTileImageryProvider.js +++ b/Source/Scene/SingleTileImageryProvider.js @@ -402,7 +402,7 @@ define([ * instances. The array may be empty if no features are found at the given location. * It may also be undefined if picking is not supported. */ - SingleTileImageryProvider.prototype.pickFeatures = function() { + SingleTileImageryProvider.prototype.pickFeatures = function(x, y, level, longitude, latitude) { return undefined; }; diff --git a/Source/Scene/TileCoordinatesImageryProvider.js b/Source/Scene/TileCoordinatesImageryProvider.js index 71290b1db166..f55e31100cb2 100644 --- a/Source/Scene/TileCoordinatesImageryProvider.js +++ b/Source/Scene/TileCoordinatesImageryProvider.js @@ -283,7 +283,7 @@ define([ * instances. The array may be empty if no features are found at the given location. * It may also be undefined if picking is not supported. */ - TileCoordinatesImageryProvider.prototype.pickFeatures = function() { + TileCoordinatesImageryProvider.prototype.pickFeatures = function(x, y, level, longitude, latitude) { return undefined; }; diff --git a/Source/Scene/TileImagery.js b/Source/Scene/TileImagery.js index ad1e0fd4bd5c..282b44cda6a7 100644 --- a/Source/Scene/TileImagery.js +++ b/Source/Scene/TileImagery.js @@ -65,7 +65,7 @@ define([ // Find some ancestor imagery we can use while this imagery is still loading. var ancestor = loadingImagery.parent; var closestAncestorThatNeedsLoading; - while (defined(ancestor) && ancestor.state !== ImageryState.READY) { + while (defined(ancestor) && (ancestor.state !== ImageryState.READY || (!this.useWebMercatorT && !defined(ancestor.texture)))) { if (ancestor.state !== ImageryState.FAILED && ancestor.state !== ImageryState.INVALID) { // ancestor is still loading closestAncestorThatNeedsLoading = closestAncestorThatNeedsLoading || ancestor; diff --git a/Source/Scene/WebMapServiceImageryProvider.js b/Source/Scene/WebMapServiceImageryProvider.js index fe0a2d9fa217..24e3242d8b7f 100644 --- a/Source/Scene/WebMapServiceImageryProvider.js +++ b/Source/Scene/WebMapServiceImageryProvider.js @@ -132,7 +132,19 @@ define([ } setParameter('layers', options.layers); - setParameter('srs', options.tilingScheme instanceof WebMercatorTilingScheme ? 'EPSG:3857' : 'EPSG:4326'); + + // Use SRS or CRS based on the WMS version. + if (parseFloat(parameters.version) >= 1.3) { + // Use CRS with 1.3.0 and going forward. + // For GeographicTilingScheme, use CRS:84 vice EPSG:4326 to specify lon, lat (x, y) ordering for + // bbox requests. + setParameter('crs', options.tilingScheme instanceof WebMercatorTilingScheme ? 'EPSG:3857' : 'CRS:84'); + } + else { + // SRS for WMS 1.1.0 or 1.1.1. + setParameter('srs', options.tilingScheme instanceof WebMercatorTilingScheme ? 'EPSG:3857' : 'EPSG:4326'); + } + setParameter('bbox', '{westProjected},{southProjected},{eastProjected},{northProjected}'); setParameter('width', '{width}'); setParameter('height', '{height}'); diff --git a/Source/Scene/WebMapTileServiceImageryProvider.js b/Source/Scene/WebMapTileServiceImageryProvider.js index 4ab21cda1a1c..1f2355e9e537 100644 --- a/Source/Scene/WebMapTileServiceImageryProvider.js +++ b/Source/Scene/WebMapTileServiceImageryProvider.js @@ -89,7 +89,7 @@ define([ * credit : new Cesium.Credit('U. S. Geological Survey') * }); * viewer.imageryLayers.addImageryProvider(shadedRelief2); - * + * * @see ArcGisMapServerImageryProvider * @see BingMapsImageryProvider * @see GoogleEarthImageryProvider @@ -459,7 +459,7 @@ define([ * instances. The array may be empty if no features are found at the given location. * It may also be undefined if picking is not supported. */ - WebMapTileServiceImageryProvider.prototype.pickFeatures = function() { + WebMapTileServiceImageryProvider.prototype.pickFeatures = function(x, y, level, longitude, latitude) { return undefined; }; diff --git a/Source/Shaders/Builtin/Functions/octDecode.glsl b/Source/Shaders/Builtin/Functions/octDecode.glsl index 4fe85a220bb6..ce4df362da12 100644 --- a/Source/Shaders/Builtin/Functions/octDecode.glsl +++ b/Source/Shaders/Builtin/Functions/octDecode.glsl @@ -1,3 +1,29 @@ + /** + * Decodes a unit-length vector in 'oct' encoding to a normalized 3-component Cartesian vector. + * The 'oct' encoding is described in "A Survey of Efficient Representations of Independent Unit Vectors", + * Cigolle et al 2014: http://jcgt.org/published/0003/02/01/ + * + * @name czm_octDecode + * @param {vec2} encoded The oct-encoded, unit-length vector + * @param {float} range The maximum value of the SNORM range. The encoded vector is stored in log2(rangeMax+1) bits. + * @returns {vec3} The decoded and normalized vector + */ + vec3 czm_octDecode(vec2 encoded, float range) + { + if (encoded.x == 0.0 && encoded.y == 0.0) { + return vec3(0.0, 0.0, 0.0); + } + + encoded = encoded / range * 2.0 - 1.0; + vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y)); + if (v.z < 0.0) + { + v.xy = (1.0 - abs(v.yx)) * czm_signNotZero(v.xy); + } + + return normalize(v); + } + /** * Decodes a unit-length vector in 'oct' encoding to a normalized 3-component Cartesian vector. * The 'oct' encoding is described in "A Survey of Efficient Representations of Independent Unit Vectors", @@ -9,14 +35,7 @@ */ vec3 czm_octDecode(vec2 encoded) { - encoded = encoded / 255.0 * 2.0 - 1.0; - vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y)); - if (v.z < 0.0) - { - v.xy = (1.0 - abs(v.yx)) * czm_signNotZero(v.xy); - } - - return normalize(v); + return czm_octDecode(encoded, 255.0); } /** diff --git a/Source/Shaders/ShadowVolumeVS.glsl b/Source/Shaders/ShadowVolumeVS.glsl index a97b96c1752b..888eca6500dd 100644 --- a/Source/Shaders/ShadowVolumeVS.glsl +++ b/Source/Shaders/ShadowVolumeVS.glsl @@ -1,8 +1,11 @@ attribute vec3 position3DHigh; attribute vec3 position3DLow; +attribute vec3 extrudeDirection; attribute vec4 color; attribute float batchId; +uniform float u_globeMinimumAltitude; + // emulated noperspective varying float v_WindowZ; varying vec4 v_color; @@ -17,7 +20,11 @@ vec4 depthClampFarPlane(vec4 vertexInClipCoordinates) void main() { v_color = color; - + vec4 position = czm_computePosition(); + float delta = min(u_globeMinimumAltitude, czm_geometricToleranceOverMeter * length(position.xyz)); + + //extrudeDirection is zero for the top layer + position = position + vec4(extrudeDirection * delta, 0.0); gl_Position = depthClampFarPlane(czm_modelViewProjectionRelativeToEye * position); } diff --git a/Source/Widgets/CesiumInspector/CesiumInspectorViewModel.js b/Source/Widgets/CesiumInspector/CesiumInspectorViewModel.js index cf787930de7b..107e0368e755 100644 --- a/Source/Widgets/CesiumInspector/CesiumInspectorViewModel.js +++ b/Source/Widgets/CesiumInspector/CesiumInspectorViewModel.js @@ -70,6 +70,7 @@ define([ * @constructor * * @param {Scene} scene The scene instance to use. + * @param {PerformanceContainer} performanceContainer The instance to use for performance container. * * @exception {DeveloperError} scene is required. */ diff --git a/Source/Widgets/Viewer/viewerPerformanceWatchdogMixin.js b/Source/Widgets/Viewer/viewerPerformanceWatchdogMixin.js index 9b6f57bd98c5..e92ec1e76385 100644 --- a/Source/Widgets/Viewer/viewerPerformanceWatchdogMixin.js +++ b/Source/Widgets/Viewer/viewerPerformanceWatchdogMixin.js @@ -20,6 +20,7 @@ define([ * @exports viewerPerformanceWatchdogMixin * * @param {Viewer} viewer The viewer instance. + * @param {Object} [options] An object with properties. * @param {String} [options.lowFrameRateMessage='This application appears to be performing poorly on your system. Please try using a different web browser or updating your video drivers.'] The * message to display when a low frame rate is detected. The message is interpeted as HTML, so make sure * it comes from a trusted source so that your application is not vulnerable to cross-site scripting attacks. diff --git a/Source/Workers/cesiumWorkerBootstrapper.js b/Source/Workers/cesiumWorkerBootstrapper.js index 955e265dfa96..d955005d42bf 100644 --- a/Source/Workers/cesiumWorkerBootstrapper.js +++ b/Source/Workers/cesiumWorkerBootstrapper.js @@ -178,8 +178,9 @@ var requirejs, require, define; /** * Constructs an error with a pointer to an URL with more information. * @param {String} id the error ID that maps to an ID on a web page. - * @param {String} message human readable error. + * @param {String} msg human readable error. * @param {Error} [err] the original error, if there is one. + * @param {RequireModules} requireModules The modules required but not found. * * @returns {Error} */ diff --git a/Specs/Core/CheckSpec.js b/Specs/Core/CheckSpec.js index 54bcc1cd304b..36c06c062063 100644 --- a/Specs/Core/CheckSpec.js +++ b/Specs/Core/CheckSpec.js @@ -6,27 +6,27 @@ defineSuite([ 'use strict'; describe('type checks', function () { - it('Check.typeOf.boolean does not throw when passed a boolean', function () { + it('Check.typeOf.bool does not throw when passed a boolean', function () { expect(function () { - Check.typeOf.boolean(true); + Check.typeOf.bool(true); }).not.toThrowDeveloperError(); }); it('Check.typeOf.boolean throws when passed a non-boolean', function () { expect(function () { - Check.typeOf.boolean({}, 'mockName'); + Check.typeOf.bool({}, 'mockName'); }).toThrowDeveloperError(); expect(function () { - Check.typeOf.boolean([], 'mockName'); + Check.typeOf.bool([], 'mockName'); }).toThrowDeveloperError(); expect(function () { - Check.typeOf.boolean(1, 'mockName'); + Check.typeOf.bool(1, 'mockName'); }).toThrowDeveloperError(); expect(function () { - Check.typeOf.boolean('snth', 'mockName'); + Check.typeOf.bool('snth', 'mockName'); }).toThrowDeveloperError(); expect(function () { - Check.typeOf.boolean(function () {return true;}, 'mockName'); + Check.typeOf.bool(function () {return true;}, 'mockName'); }).toThrowDeveloperError(); }); diff --git a/Specs/Core/CircleGeometrySpec.js b/Specs/Core/CircleGeometrySpec.js index d41fc2a3c42a..ec7fdac5fb63 100644 --- a/Specs/Core/CircleGeometrySpec.js +++ b/Specs/Core/CircleGeometrySpec.js @@ -178,6 +178,6 @@ defineSuite([ radius : 1.0, stRotation : CesiumMath.PI_OVER_TWO }); - var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, rectangle.west, rectangle.south, rectangle.east, rectangle.north, 1.0, 1.0, 0.0, CesiumMath.PI_OVER_TWO, 0.0, 0.1, 0.0, 0.0]; + var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, rectangle.west, rectangle.south, rectangle.east, rectangle.north, 1.0, 1.0, 0.0, CesiumMath.PI_OVER_TWO, 0.0, 0.1, 0.0, 0.0, 0.0]; createPackableSpecs(CircleGeometry, packableInstance, packedInstance); }); diff --git a/Specs/Core/CorridorGeometrySpec.js b/Specs/Core/CorridorGeometrySpec.js index 1862108eabbc..4bac8615e1ba 100644 --- a/Specs/Core/CorridorGeometrySpec.js +++ b/Specs/Core/CorridorGeometrySpec.js @@ -291,6 +291,6 @@ defineSuite([ packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z); packedInstance.push(1.0, 0.0, 0.0, 0.0, 0.0, 0.0); packedInstance.push(rectangle.west, rectangle.south, rectangle.east, rectangle.north); - packedInstance.push(30000.0, 0.0, 0.0, 2.0, 0.1); + packedInstance.push(30000.0, 0.0, 0.0, 2.0, 0.1, 0.0); createPackableSpecs(CorridorGeometry, corridor, packedInstance); }); diff --git a/Specs/Core/EllipseGeometrySpec.js b/Specs/Core/EllipseGeometrySpec.js index df9f86701a16..0af786c8bf03 100644 --- a/Specs/Core/EllipseGeometrySpec.js +++ b/Specs/Core/EllipseGeometrySpec.js @@ -265,7 +265,7 @@ defineSuite([ semiMinorAxis : 1.0, stRotation : CesiumMath.PI_OVER_TWO }); - var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, rectangle.west, rectangle.south, rectangle.east, rectangle.north, 1.0, 1.0, 0.0, CesiumMath.PI_OVER_TWO, 0.0, 0.1, 0.0, 0.0]; + var packedInstance = [center.x, center.y, center.z, ellipsoid.radii.x, ellipsoid.radii.y, ellipsoid.radii.z, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, rectangle.west, rectangle.south, rectangle.east, rectangle.north, 1.0, 1.0, 0.0, CesiumMath.PI_OVER_TWO, 0.0, 0.1, 0.0, 0.0, 0.0]; createPackableSpecs(EllipseGeometry, packableInstance, packedInstance); }); diff --git a/Specs/Core/PolygonGeometrySpec.js b/Specs/Core/PolygonGeometrySpec.js index 2d2aae6b3d41..d29fdb8bbc43 100644 --- a/Specs/Core/PolygonGeometrySpec.js +++ b/Specs/Core/PolygonGeometrySpec.js @@ -699,6 +699,6 @@ defineSuite([ packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z); packedInstance.push(1.0, 0.0, 0.0, 0.0, 0.0, 0.0); packedInstance.push(rectangle.west, rectangle.south, rectangle.east, rectangle.north); - packedInstance.push(0.0, 0.0, CesiumMath.PI_OVER_THREE, 0.0, 0.0, 1.0, 0, 1, 55); + packedInstance.push(0.0, 0.0, CesiumMath.PI_OVER_THREE, 0.0, 0.0, 1.0, 0, 1, 0, 56); createPackableSpecs(PolygonGeometry, polygon, packedInstance); }); diff --git a/Specs/Core/RectangleGeometrySpec.js b/Specs/Core/RectangleGeometrySpec.js index 5ed3b14f5b39..0e1e51f92d7e 100644 --- a/Specs/Core/RectangleGeometrySpec.js +++ b/Specs/Core/RectangleGeometrySpec.js @@ -349,6 +349,6 @@ defineSuite([ granularity : 1.0, ellipsoid : Ellipsoid.UNIT_SPHERE }); - var packedInstance = [-2.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -2.0, -1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0]; + var packedInstance = [-2.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -2.0, -1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0]; createPackableSpecs(RectangleGeometry, rectangle, packedInstance); }); diff --git a/Specs/Core/TransformsSpec.js b/Specs/Core/TransformsSpec.js index de42f2f68270..1d4682ca3b7a 100644 --- a/Specs/Core/TransformsSpec.js +++ b/Specs/Core/TransformsSpec.js @@ -357,7 +357,7 @@ defineSuite([ var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); var expected = Matrix4.getRotation(transform, new Matrix3()); - var quaternion = Transforms.headingPitchRollQuaternion(origin, heading, pitch, roll, Ellipsoid.UNIT_SPHERE); + var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE); var actual = Matrix3.fromQuaternion(quaternion); expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); }); @@ -388,7 +388,7 @@ defineSuite([ var expected = Matrix4.getRotation(transform, new Matrix3()); var result = new Quaternion(); - var quaternion = Transforms.headingPitchRollQuaternion(origin, heading, pitch, roll, Ellipsoid.UNIT_SPHERE, result); + var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, result); var actual = Matrix3.fromQuaternion(quaternion); expect(quaternion).toBe(result); expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); @@ -923,21 +923,9 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('headingPitchRollToFixedFrame throws without an heading', function() { - expect(function() { - Transforms.headingPitchRollToFixedFrame(Cartesian3.ZERO, undefined, 0.0, 0.0); - }).toThrowDeveloperError(); - }); - - it('headingPitchRollToFixedFrame throws without an pitch', function() { - expect(function() { - Transforms.headingPitchRollToFixedFrame(Cartesian3.ZERO, 0.0, undefined, 0.0); - }).toThrowDeveloperError(); - }); - - it('headingPitchRollToFixedFrame throws without an roll', function() { + it('headingPitchRollToFixedFrame throws without a headingPitchRoll', function() { expect(function() { - Transforms.headingPitchRollToFixedFrame(Cartesian3.ZERO, 0.0, 0.0, undefined); + Transforms.headingPitchRollToFixedFrame(Cartesian3.ZERO, undefined); }).toThrowDeveloperError(); }); diff --git a/Specs/DataSources/KmlDataSourceSpec.js b/Specs/DataSources/KmlDataSourceSpec.js index 6047c568d1a1..5745748e366a 100644 --- a/Specs/DataSources/KmlDataSourceSpec.js +++ b/Specs/DataSources/KmlDataSourceSpec.js @@ -1014,6 +1014,23 @@ defineSuite([ }); }); + it('Styles: empty color', function() { + CesiumMath.setRandomNumberSeed(0); + + var kml = '\ + \ + \ + '; + + return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), options).then(function(dataSource) { + expect(dataSource.entities.values[0].billboard.color).toBeUndefined(); + }); + }); + it('Styles: Applies expected styles to Point geometry', function() { var kml = '\