From d3c1c9d700e35d1f0c99f3a42f3a5ed586d61d43 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sun, 25 Nov 2018 10:15:34 -0500 Subject: [PATCH 01/71] Update Chappes --- Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html | 9 +++++++-- .../gallery/3D Tiles Point Cloud Classification.html | 2 +- .../Sandcastle/gallery/3D Tiles Point Cloud Shading.html | 2 +- Apps/Sandcastle/gallery/3D Tiles Point Cloud.html | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html b/Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html index b2f15d60f093..c1301aa99505 100644 --- a/Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html +++ b/Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html @@ -55,6 +55,8 @@ selectionIndicator: false }); var scene = viewer.scene; +var cesiumTerrainProvider = Cesium.createWorldTerrain(); +var ellipsoidTerrainProvider = new Cesium.EllipsoidTerrainProvider(); var clipObjects = ['BIM', 'Point Cloud', 'Instanced', 'Model']; var viewModel = { @@ -200,7 +202,7 @@ // Power Plant design model provided by Bentley Systems var bimUrl = Cesium.IonResource.fromAssetId(8564); -var pointCloudUrl = Cesium.IonResource.fromAssetId(5714); +var pointCloudUrl = Cesium.IonResource.fromAssetId(10941); var instancedUrl = '../../SampleData/Cesium3DTiles/Instanced/InstancedOrientation/tileset.json'; var modelUrl = '../../SampleData/models/CesiumAir/Cesium_Air.glb'; @@ -216,12 +218,16 @@ if (newValue === clipObjects[0]) { loadTileset(bimUrl); + viewer.terrainProvider = ellipsoidTerrainProvider; } else if (newValue === clipObjects[1]) { loadTileset(pointCloudUrl); + viewer.terrainProvider = cesiumTerrainProvider; } else if (newValue === clipObjects[2]) { loadTileset(instancedUrl); + viewer.terrainProvider = ellipsoidTerrainProvider; } else { loadModel(modelUrl); + viewer.terrainProvider = ellipsoidTerrainProvider; } }); @@ -244,7 +250,6 @@ targetY = 0.0; tileset = undefined; } - //Sandcastle_End Sandcastle.finishedLoading(); } diff --git a/Apps/Sandcastle/gallery/3D Tiles Point Cloud Classification.html b/Apps/Sandcastle/gallery/3D Tiles Point Cloud Classification.html index f2896d5d5663..ad4439112c44 100644 --- a/Apps/Sandcastle/gallery/3D Tiles Point Cloud Classification.html +++ b/Apps/Sandcastle/gallery/3D Tiles Point Cloud Classification.html @@ -31,7 +31,7 @@ //Point Cloud by Prof. Peter Allen, Columbia University Robotics Lab. Scanning by Alejandro Troccoli and Matei Ciocarlie. var tileset = new Cesium.Cesium3DTileset({ - url: Cesium.IonResource.fromAssetId(5714) + url: Cesium.IonResource.fromAssetId(10941) }); viewer.scene.primitives.add(tileset); diff --git a/Apps/Sandcastle/gallery/3D Tiles Point Cloud Shading.html b/Apps/Sandcastle/gallery/3D Tiles Point Cloud Shading.html index f1ef480f0230..b8d13b8046c4 100644 --- a/Apps/Sandcastle/gallery/3D Tiles Point Cloud Shading.html +++ b/Apps/Sandcastle/gallery/3D Tiles Point Cloud Shading.html @@ -158,7 +158,7 @@ function loadChurch() { // Point Cloud by Prof. Peter Allen, Columbia University Robotics Lab. Scanning by Alejandro Troccoli and Matei Ciocarlie. // This tileset uses additive refinement and has geometric error based on the bounding box size for each tile. - var tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(5714) }); + var tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(10941) }); viewer.scene.primitives.add(tileset); tileset.maximumScreenSpaceError = 1024.0; // For better performance, due to how this tileset treats geometric error. diff --git a/Apps/Sandcastle/gallery/3D Tiles Point Cloud.html b/Apps/Sandcastle/gallery/3D Tiles Point Cloud.html index 4f2c3ceaab2d..b2ed4898b7fd 100644 --- a/Apps/Sandcastle/gallery/3D Tiles Point Cloud.html +++ b/Apps/Sandcastle/gallery/3D Tiles Point Cloud.html @@ -29,7 +29,7 @@ //Point Cloud by Prof. Peter Allen, Columbia University Robotics Lab. Scanning by Alejandro Troccoli and Matei Ciocarlie. var viewer = new Cesium.Viewer('cesiumContainer'); -var tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(5714) }); +var tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(10941) }); viewer.scene.primitives.add(tileset); viewer.zoomTo(tileset); //Sandcastle_End From 7f2cc1eacaab7edc1b09a591cd6e2f11e2889be9 Mon Sep 17 00:00:00 2001 From: Zhihang Yao Date: Fri, 7 Dec 2018 14:51:08 +0100 Subject: [PATCH 02/71] sliced minimumHeights and maximumHeights array --- Source/Scene/Vector3DTilePolygons.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Scene/Vector3DTilePolygons.js b/Source/Scene/Vector3DTilePolygons.js index dd1dce43fba2..0a3b2f3ef82d 100644 --- a/Source/Scene/Vector3DTilePolygons.js +++ b/Source/Scene/Vector3DTilePolygons.js @@ -285,6 +285,9 @@ define([ var minimumHeights = polygons._polygonMinimumHeights; var maximumHeights = polygons._polygonMaximumHeights; if (defined(minimumHeights) && defined(maximumHeights)) { + minimumHeights = arraySlice(minimumHeights); + maximumHeights = arraySlice(maximumHeights); + transferrableObjects.push(minimumHeights.buffer, maximumHeights.buffer); parameters.minimumHeights = minimumHeights; parameters.maximumHeights = maximumHeights; From fe666ce2bd66d5cebe41fc192f51464cc2c0eb0b Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Fri, 7 Dec 2018 19:43:56 +0300 Subject: [PATCH 03/71] refs #5152 option to switch normal shading --- Source/Scene/Cesium3DTileset.js | 20 ++++++++++++++++++++ Source/Scene/PointCloud.js | 20 ++++++++++++++++++-- Source/Scene/PointCloud3DTileContent.js | 4 +++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 8b394390f0b6..10780186ec38 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -20,6 +20,7 @@ define([ '../Core/Resource', '../Core/RuntimeError', '../Core/Transforms', + '../DataSources/ConstantProperty', '../Renderer/ClearCommand', '../Renderer/Pass', '../ThirdParty/when', @@ -65,6 +66,7 @@ define([ Resource, RuntimeError, Transforms, + ConstantProperty, ClearCommand, Pass, when, @@ -293,6 +295,24 @@ define([ */ this.shadows = defaultValue(options.shadows, ShadowMode.ENABLED); + /** + * Determines whether backfaces of points / mesh are hidden + * + * @type {boolean} + * @default false + */ + var backFaceCulling = defaultValue(options.backFaceCulling, false); + this.backFaceCulling = new ConstantProperty(backFaceCulling); + + /** + * Determines whether the tileset is lighted by the sun + * + * @type {boolean} + * @default true + */ + var normalShading = defaultValue(options.normalShading, true); + this.normalShading = new ConstantProperty(normalShading); + /** * Determines if the tileset will be shown. * diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 252764a23f4e..2bfc0b7ef869 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -21,6 +21,7 @@ define([ '../Core/PrimitiveType', '../Core/RuntimeError', '../Core/Transforms', + '../DataSources/ConstantProperty', '../Renderer/Buffer', '../Renderer/BufferUsage', '../Renderer/DrawCommand', @@ -62,6 +63,7 @@ define([ PrimitiveType, RuntimeError, Transforms, + ConstantProperty, Buffer, BufferUsage, DrawCommand, @@ -114,6 +116,8 @@ define([ Check.typeOf.object('options.arrayBuffer', options.arrayBuffer); //>>includeEnd('debug'); + var that = this; + // Hold onto the payload until the render resources are created this._parsedContent = undefined; @@ -147,11 +151,13 @@ define([ // Use per-point normals to hide back-facing points. this.backFaceCulling = false; - this._backFaceCulling = false; + bindProperty(this, "backFaceCulling", options.backFaceCulling); + this._backFaceCulling = this.backFaceCulling; // Whether to enable normal shading this.normalShading = true; - this._normalShading = true; + bindProperty(this, "normalShading", options.normalShading); + this._normalShading = this.normalShading; this._opaqueRenderState = undefined; this._translucentRenderState = undefined; @@ -249,6 +255,16 @@ define([ var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; + function bindProperty(object, field, property) { + if (property) { + var val = property.getValue(); + object[field] = val; + property.definitionChanged.addEventListener(function(newValue) { + object[field] = newValue.getValue(); + }); + } + } + function initialize(pointCloud, options) { var arrayBuffer = options.arrayBuffer; var byteOffset = defaultValue(options.byteOffset, 0); diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index f9cb8caa9855..740627fcdaf4 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -70,7 +70,9 @@ define([ fragmentShaderLoaded : getFragmentShaderLoaded(this), uniformMapLoaded : getUniformMapLoaded(this), batchTableLoaded : getBatchTableLoaded(this), - pickIdLoaded : getPickIdLoaded(this) + pickIdLoaded : getPickIdLoaded(this), + normalShading : tileset.normalShading, + backfaceCulling : tileset.backfaceCulling }); } From a563bda5cab29a3ac32f26bef6fc488a240b4ea1 Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Thu, 13 Dec 2018 19:35:54 +0300 Subject: [PATCH 04/71] codestyle fixes --- Source/Scene/PointCloud.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 2bfc0b7ef869..904e1c61bef5 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -116,8 +116,6 @@ define([ Check.typeOf.object('options.arrayBuffer', options.arrayBuffer); //>>includeEnd('debug'); - var that = this; - // Hold onto the payload until the render resources are created this._parsedContent = undefined; @@ -151,12 +149,12 @@ define([ // Use per-point normals to hide back-facing points. this.backFaceCulling = false; - bindProperty(this, "backFaceCulling", options.backFaceCulling); + bindProperty(this, 'backFaceCulling', options.backFaceCulling); this._backFaceCulling = this.backFaceCulling; // Whether to enable normal shading this.normalShading = true; - bindProperty(this, "normalShading", options.normalShading); + bindProperty(this, 'normalShading', options.normalShading); this._normalShading = this.normalShading; this._opaqueRenderState = undefined; From 39ade84b2b35d870dff588cdca1e21eb288fe2e4 Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Fri, 28 Dec 2018 18:43:40 +0300 Subject: [PATCH 05/71] refs #5152 moved properties to pointCloudShading --- Source/Scene/Cesium3DTileset.js | 18 ------------ Source/Scene/PointCloud.js | 37 +++++++++++++------------ Source/Scene/PointCloud3DTileContent.js | 3 +- Source/Scene/PointCloudShading.js | 16 +++++++++++ Source/Scene/TimeDynamicPointCloud.js | 6 +++- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 10780186ec38..bf211d7dc215 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -295,24 +295,6 @@ define([ */ this.shadows = defaultValue(options.shadows, ShadowMode.ENABLED); - /** - * Determines whether backfaces of points / mesh are hidden - * - * @type {boolean} - * @default false - */ - var backFaceCulling = defaultValue(options.backFaceCulling, false); - this.backFaceCulling = new ConstantProperty(backFaceCulling); - - /** - * Determines whether the tileset is lighted by the sun - * - * @type {boolean} - * @default true - */ - var normalShading = defaultValue(options.normalShading, true); - this.normalShading = new ConstantProperty(normalShading); - /** * Determines if the tileset will be shown. * diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 904e1c61bef5..4a443fbcf911 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -147,14 +147,15 @@ define([ this._quantizedRange = 0.0; this._octEncodedRange = 0.0; + this._pointCloudShading = defaultValue(options.shading, { + backFaceCulling : false, + normalShading : true + }); + // Use per-point normals to hide back-facing points. - this.backFaceCulling = false; - bindProperty(this, 'backFaceCulling', options.backFaceCulling); this._backFaceCulling = this.backFaceCulling; // Whether to enable normal shading - this.normalShading = true; - bindProperty(this, 'normalShading', options.normalShading); this._normalShading = this.normalShading; this._opaqueRenderState = undefined; @@ -248,21 +249,23 @@ define([ set : function(value) { this._boundingSphere = BoundingSphere.clone(value); } + }, + + backFaceCulling : { + get : function() { + return this._pointCloudShading.backFaceCulling; + } + }, + + normalShading : { + get : function() { + return this._pointCloudShading.normalShading; + } } }); var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; - function bindProperty(object, field, property) { - if (property) { - var val = property.getValue(); - object[field] = val; - property.definitionChanged.addEventListener(function(newValue) { - object[field] = newValue.getValue(); - }); - } - } - function initialize(pointCloud, options) { var arrayBuffer = options.arrayBuffer; var byteOffset = defaultValue(options.byteOffset, 0); @@ -1142,6 +1145,7 @@ define([ } else { vs += ' vec3 normal = a_normal; \n'; } + vs += ' vec3 view_normal = czm_normal * normal; \n'; } else { vs += ' vec3 normal = vec3(1.0); \n'; } @@ -1168,8 +1172,7 @@ define([ vs += ' color = color * u_highlightColor; \n'; if (usesNormals && normalShading) { - vs += ' normal = czm_normal * normal; \n' + - ' float diffuseStrength = czm_getLambertDiffuse(czm_sunDirectionEC, normal); \n' + + vs += ' float diffuseStrength = czm_getLambertDiffuse(czm_sunDirectionEC, view_normal); \n' + ' diffuseStrength = max(diffuseStrength, 0.4); \n' + // Apply some ambient lighting ' color.xyz *= diffuseStrength; \n'; } @@ -1178,7 +1181,7 @@ define([ ' gl_Position = czm_modelViewProjection * vec4(position, 1.0); \n'; if (usesNormals && backFaceCulling) { - vs += ' float visible = step(-normal.z, 0.0); \n' + + vs += ' float visible = step(-view_normal.z, 0.0); \n' + ' gl_Position *= visible; \n' + ' gl_PointSize *= visible; \n'; } diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index 740627fcdaf4..875ccf1471c4 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -71,8 +71,7 @@ define([ uniformMapLoaded : getUniformMapLoaded(this), batchTableLoaded : getBatchTableLoaded(this), pickIdLoaded : getPickIdLoaded(this), - normalShading : tileset.normalShading, - backfaceCulling : tileset.backfaceCulling + shading : tileset.pointCloudShading }); } diff --git a/Source/Scene/PointCloudShading.js b/Source/Scene/PointCloudShading.js index f466c038ad8b..49a7bfd6d15f 100644 --- a/Source/Scene/PointCloudShading.js +++ b/Source/Scene/PointCloudShading.js @@ -76,6 +76,22 @@ define([ * @default 1.0 */ this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0); + + /** + * Determines whether backfaces of points / mesh are hidden + * + * @type {boolean} + * @default false + */ + this.backFaceCulling = defaultValue(pointCloudShading.backFaceCulling, false); + + /** + * Determines whether the tileset is lighted by the sun + * + * @type {boolean} + * @default true + */ + this.normalShading = defaultValue(pointCloudShading.normalShading, true); } /** diff --git a/Source/Scene/TimeDynamicPointCloud.js b/Source/Scene/TimeDynamicPointCloud.js index 5ee29f81670f..d385c4519573 100644 --- a/Source/Scene/TimeDynamicPointCloud.js +++ b/Source/Scene/TimeDynamicPointCloud.js @@ -151,6 +151,9 @@ define([ */ this.style = options.style; + this.normalShading = options.normalShading; + this.backFaceCulling = options.backFaceCulling; + /** * The event fired to indicate that a frame failed to load. A frame may fail to load if the * request for its uri fails or processing fails due to invalid content. @@ -420,7 +423,8 @@ define([ cull : true, fragmentShaderLoaded : getFragmentShaderLoaded, uniformMapLoaded : getUniformMapLoaded(that), - pickIdLoaded : getPickIdLoaded + pickIdLoaded : getPickIdLoaded, + shading : that.shading }); return frame.pointCloud.readyPromise; }).otherwise(handleFrameFailure(that, uri)); From 40c5a124a1c4ab32ad58eedaeb907709e185e7f5 Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Fri, 28 Dec 2018 18:49:59 +0300 Subject: [PATCH 06/71] refs #5152 cleaning --- Source/Scene/Cesium3DTileset.js | 2 -- Source/Scene/PointCloud.js | 2 -- Source/Scene/TimeDynamicPointCloud.js | 3 --- 3 files changed, 7 deletions(-) diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index bf211d7dc215..8b394390f0b6 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -20,7 +20,6 @@ define([ '../Core/Resource', '../Core/RuntimeError', '../Core/Transforms', - '../DataSources/ConstantProperty', '../Renderer/ClearCommand', '../Renderer/Pass', '../ThirdParty/when', @@ -66,7 +65,6 @@ define([ Resource, RuntimeError, Transforms, - ConstantProperty, ClearCommand, Pass, when, diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 4a443fbcf911..700734f2b33c 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -21,7 +21,6 @@ define([ '../Core/PrimitiveType', '../Core/RuntimeError', '../Core/Transforms', - '../DataSources/ConstantProperty', '../Renderer/Buffer', '../Renderer/BufferUsage', '../Renderer/DrawCommand', @@ -63,7 +62,6 @@ define([ PrimitiveType, RuntimeError, Transforms, - ConstantProperty, Buffer, BufferUsage, DrawCommand, diff --git a/Source/Scene/TimeDynamicPointCloud.js b/Source/Scene/TimeDynamicPointCloud.js index d385c4519573..e3f74eeb4c40 100644 --- a/Source/Scene/TimeDynamicPointCloud.js +++ b/Source/Scene/TimeDynamicPointCloud.js @@ -151,9 +151,6 @@ define([ */ this.style = options.style; - this.normalShading = options.normalShading; - this.backFaceCulling = options.backFaceCulling; - /** * The event fired to indicate that a frame failed to load. A frame may fail to load if the * request for its uri fails or processing fails due to invalid content. From 756cefd6891c8d3874a777b1ff43a701b71f4fc3 Mon Sep 17 00:00:00 2001 From: hodbauer Date: Sun, 27 Jan 2019 12:31:59 +0200 Subject: [PATCH 07/71] fixed reversing non alphabetic characters on RTL labels --- CHANGES.md | 1 + Source/Scene/Label.js | 21 +++++++++++++++++---- Specs/Scene/LabelCollectionSpec.js | 11 +++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 514dda84cfae..a5f35fb7c00a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,7 @@ Change Log * Improved the performance of `QuantizedMeshTerrainData.interpolateHeight`. [#7508](https://github.com/AnalyticalGraphicsInc/cesium/pull/7508) ##### Fixes :wrench: +* Fixed an issue where RTL labels not reversing correctly non alphabetic characters [#7501](https://github.com/AnalyticalGraphicsInc/cesium/pull/7501) * Fixed 3D Tiles performance regression. [#7482](https://github.com/AnalyticalGraphicsInc/cesium/pull/7482) * Fixed an issue where classification primitives with the `CESIUM_3D_TILE` classification type would render on terrain. [#7422](https://github.com/AnalyticalGraphicsInc/cesium/pull/7422) * Fixed an issue where 3D Tiles would show through the globe. [#7422](https://github.com/AnalyticalGraphicsInc/cesium/pull/7422) diff --git a/Source/Scene/Label.js b/Source/Scene/Label.js index b2fa4c8a4b69..278e7fcdbecd 100644 --- a/Source/Scene/Label.js +++ b/Source/Scene/Label.js @@ -1340,6 +1340,7 @@ define([ var result = ''; for (var i = 0; i < texts.length; i++) { var text = texts[i]; + // first character of the line is a RTL character, so need to manage different cases var rtlDir = rtlChars.test(text.charAt(0)); var parsedText = convertTextToTypes(text, rtlChars); @@ -1347,10 +1348,10 @@ define([ var line = ''; for (var wordIndex = 0; wordIndex < parsedText.length; ++wordIndex) { var subText = parsedText[wordIndex]; - var reverse = subText.Type === textTypes.BRACKETS ? reverseBrackets(subText.Word) : subText.Word; + var reverse = subText.Type === textTypes.BRACKETS ? reverseBrackets(subText.Word) : reverseWord(subText.Word); if (rtlDir) { if (subText.Type === textTypes.RTL) { - line = reverseWord(subText.Word) + line; + line = reverse + line; splicePointer = 0; } else if (subText.Type === textTypes.LTR) { @@ -1358,14 +1359,18 @@ define([ splicePointer += subText.Word.length; } else if (subText.Type === textTypes.WEAK || subText.Type === textTypes.BRACKETS) { + // current word is weak, last one was bracket if (subText.Type === textTypes.WEAK && parsedText[wordIndex - 1].Type === textTypes.BRACKETS) { - line = reverseWord(subText.Word) + line; + line = reverse + line; } + // current word is weak or bracket, last one was rtl else if (parsedText[wordIndex - 1].Type === textTypes.RTL) { line = reverse + line; splicePointer = 0; } + // current word is weak or bracket, there is at least one more word else if (parsedText.length > wordIndex + 1) { + // next word is rtl if (parsedText[wordIndex + 1].Type === textTypes.RTL) { line = reverse + line; splicePointer = 0; @@ -1375,22 +1380,30 @@ define([ splicePointer += subText.Word.length; } } + // current word is weak or bracket, and it the last in this line else { line = spliceWord(line, 0, reverse); } } } + // ltr line, rtl word else if (subText.Type === textTypes.RTL) { - line = spliceWord(line, splicePointer, reverseWord(subText.Word)); + line = spliceWord(line, splicePointer, reverse); } + // ltr line, ltr word else if (subText.Type === textTypes.LTR) { line += subText.Word; splicePointer = line.length; } + // ltr line, weak or bracket word else if (subText.Type === textTypes.WEAK || subText.Type === textTypes.BRACKETS) { + // not first word in line if (wordIndex > 0) { + // last word was rtl if (parsedText[wordIndex - 1].Type === textTypes.RTL) { + // there is at least one more word if (parsedText.length > wordIndex + 1) { + // next word is rtl if (parsedText[wordIndex + 1].Type === textTypes.RTL) { line = spliceWord(line, splicePointer, reverse); } diff --git a/Specs/Scene/LabelCollectionSpec.js b/Specs/Scene/LabelCollectionSpec.js index 9c0df743e2f9..ee6f35e5c726 100644 --- a/Specs/Scene/LabelCollectionSpec.js +++ b/Specs/Scene/LabelCollectionSpec.js @@ -1983,6 +1983,17 @@ defineSuite([ expect(label.text).toEqual(text); expect(label._renderedText).toEqual(expectedText); }); + + it('should reversing correctly non alphabetic characters', function() { + var text = 'A אב: ג\nאב: ג'; + var expectedText = 'A ג :בא\nג :בא'; + var label = labels.add({ + text : text + }); + + expect(label.text).toEqual(text); + expect(label._renderedText).toEqual(expectedText); + }); }); it('computes bounding sphere in 3D', function() { From 98fae384414e1f1a46ec8069f1ae03544093768e Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Thu, 7 Feb 2019 19:22:22 +0300 Subject: [PATCH 08/71] Changed default shading from raw object to PointCloudShading Also some variables renamed, description changed --- Source/Scene/PointCloud.js | 11 ++++------- Source/Scene/PointCloudShading.js | 9 +++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 700734f2b33c..3c5916d46b39 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -145,10 +145,7 @@ define([ this._quantizedRange = 0.0; this._octEncodedRange = 0.0; - this._pointCloudShading = defaultValue(options.shading, { - backFaceCulling : false, - normalShading : true - }); + this._pointCloudShading = defined(options.shading) ? options.shading : new PointCloudShading(); // Use per-point normals to hide back-facing points. this._backFaceCulling = this.backFaceCulling; @@ -1143,7 +1140,7 @@ define([ } else { vs += ' vec3 normal = a_normal; \n'; } - vs += ' vec3 view_normal = czm_normal * normal; \n'; + vs += ' vec3 normalEC = czm_normal * normal; \n'; } else { vs += ' vec3 normal = vec3(1.0); \n'; } @@ -1170,7 +1167,7 @@ define([ vs += ' color = color * u_highlightColor; \n'; if (usesNormals && normalShading) { - vs += ' float diffuseStrength = czm_getLambertDiffuse(czm_sunDirectionEC, view_normal); \n' + + vs += ' float diffuseStrength = czm_getLambertDiffuse(czm_sunDirectionEC, normalEC); \n' + ' diffuseStrength = max(diffuseStrength, 0.4); \n' + // Apply some ambient lighting ' color.xyz *= diffuseStrength; \n'; } @@ -1179,7 +1176,7 @@ define([ ' gl_Position = czm_modelViewProjection * vec4(position, 1.0); \n'; if (usesNormals && backFaceCulling) { - vs += ' float visible = step(-view_normal.z, 0.0); \n' + + vs += ' float visible = step(-normalEC.z, 0.0); \n' + ' gl_Position *= visible; \n' + ' gl_PointSize *= visible; \n'; } diff --git a/Source/Scene/PointCloudShading.js b/Source/Scene/PointCloudShading.js index 49a7bfd6d15f..6ee38183021c 100644 --- a/Source/Scene/PointCloudShading.js +++ b/Source/Scene/PointCloudShading.js @@ -78,17 +78,18 @@ define([ this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0); /** - * Determines whether backfaces of points / mesh are hidden + * Determines whether backfaces of points / mesh are hidden. + * For point cloud this option works only, if data has normals. * - * @type {boolean} + * @type {Boolean} * @default false */ this.backFaceCulling = defaultValue(pointCloudShading.backFaceCulling, false); /** - * Determines whether the tileset is lighted by the sun + * Determines whether a point cloud that contains normals is shaded based on the sun direction. * - * @type {boolean} + * @type {Boolean} * @default true */ this.normalShading = defaultValue(pointCloudShading.normalShading, true); From acf191f7807cc3cbc2d0e5573a10402c914d06af Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Thu, 7 Feb 2019 19:32:46 +0300 Subject: [PATCH 09/71] small description fix --- Source/Scene/PointCloudShading.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Scene/PointCloudShading.js b/Source/Scene/PointCloudShading.js index 6ee38183021c..906a9ee8fe29 100644 --- a/Source/Scene/PointCloudShading.js +++ b/Source/Scene/PointCloudShading.js @@ -78,8 +78,8 @@ define([ this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0); /** - * Determines whether backfaces of points / mesh are hidden. - * For point cloud this option works only, if data has normals. + * Determines whether backfaces of points are hidden. + * This option works only if data has normals included. * * @type {Boolean} * @default false From 737c95e8aab136178263b99fbbf2ee2b2abd78f3 Mon Sep 17 00:00:00 2001 From: hodbauer Date: Thu, 7 Feb 2019 23:37:26 +0200 Subject: [PATCH 10/71] fixed reversing non alphabetic characters on RTL labels updating CHANGES.md --- CHANGES.md | 1 + Source/Scene/Label.js | 21 +++++++++++++++++---- Specs/Scene/LabelCollectionSpec.js | 11 +++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e68ca412ffce..a6c7746569d7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Change Log ##### Fixes :wrench: * Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383) +* Fixed an issue where RTL labels not reversing correctly non alphabetic characters [#7501](https://github.com/AnalyticalGraphicsInc/cesium/pull/7501) * Fixed Node.js support for the `Resource` class and any functionality using it internally. * Fixed an issue where some ground polygons crossing the Prime Meridian would have incorrect bounding rectangles. [#7533](https://github.com/AnalyticalGraphicsInc/cesium/pull/7533) * Fixed an issue where polygons on terrain using rhumb lines where being rendered incorrectly. [#7538](https://github.com/AnalyticalGraphicsInc/cesium/pulls/7538) diff --git a/Source/Scene/Label.js b/Source/Scene/Label.js index b2fa4c8a4b69..278e7fcdbecd 100644 --- a/Source/Scene/Label.js +++ b/Source/Scene/Label.js @@ -1340,6 +1340,7 @@ define([ var result = ''; for (var i = 0; i < texts.length; i++) { var text = texts[i]; + // first character of the line is a RTL character, so need to manage different cases var rtlDir = rtlChars.test(text.charAt(0)); var parsedText = convertTextToTypes(text, rtlChars); @@ -1347,10 +1348,10 @@ define([ var line = ''; for (var wordIndex = 0; wordIndex < parsedText.length; ++wordIndex) { var subText = parsedText[wordIndex]; - var reverse = subText.Type === textTypes.BRACKETS ? reverseBrackets(subText.Word) : subText.Word; + var reverse = subText.Type === textTypes.BRACKETS ? reverseBrackets(subText.Word) : reverseWord(subText.Word); if (rtlDir) { if (subText.Type === textTypes.RTL) { - line = reverseWord(subText.Word) + line; + line = reverse + line; splicePointer = 0; } else if (subText.Type === textTypes.LTR) { @@ -1358,14 +1359,18 @@ define([ splicePointer += subText.Word.length; } else if (subText.Type === textTypes.WEAK || subText.Type === textTypes.BRACKETS) { + // current word is weak, last one was bracket if (subText.Type === textTypes.WEAK && parsedText[wordIndex - 1].Type === textTypes.BRACKETS) { - line = reverseWord(subText.Word) + line; + line = reverse + line; } + // current word is weak or bracket, last one was rtl else if (parsedText[wordIndex - 1].Type === textTypes.RTL) { line = reverse + line; splicePointer = 0; } + // current word is weak or bracket, there is at least one more word else if (parsedText.length > wordIndex + 1) { + // next word is rtl if (parsedText[wordIndex + 1].Type === textTypes.RTL) { line = reverse + line; splicePointer = 0; @@ -1375,22 +1380,30 @@ define([ splicePointer += subText.Word.length; } } + // current word is weak or bracket, and it the last in this line else { line = spliceWord(line, 0, reverse); } } } + // ltr line, rtl word else if (subText.Type === textTypes.RTL) { - line = spliceWord(line, splicePointer, reverseWord(subText.Word)); + line = spliceWord(line, splicePointer, reverse); } + // ltr line, ltr word else if (subText.Type === textTypes.LTR) { line += subText.Word; splicePointer = line.length; } + // ltr line, weak or bracket word else if (subText.Type === textTypes.WEAK || subText.Type === textTypes.BRACKETS) { + // not first word in line if (wordIndex > 0) { + // last word was rtl if (parsedText[wordIndex - 1].Type === textTypes.RTL) { + // there is at least one more word if (parsedText.length > wordIndex + 1) { + // next word is rtl if (parsedText[wordIndex + 1].Type === textTypes.RTL) { line = spliceWord(line, splicePointer, reverse); } diff --git a/Specs/Scene/LabelCollectionSpec.js b/Specs/Scene/LabelCollectionSpec.js index 9c0df743e2f9..ee6f35e5c726 100644 --- a/Specs/Scene/LabelCollectionSpec.js +++ b/Specs/Scene/LabelCollectionSpec.js @@ -1983,6 +1983,17 @@ defineSuite([ expect(label.text).toEqual(text); expect(label._renderedText).toEqual(expectedText); }); + + it('should reversing correctly non alphabetic characters', function() { + var text = 'A אב: ג\nאב: ג'; + var expectedText = 'A ג :בא\nג :בא'; + var label = labels.add({ + text : text + }); + + expect(label.text).toEqual(text); + expect(label._renderedText).toEqual(expectedText); + }); }); it('computes bounding sphere in 3D', function() { From 6f591441fe968243459a49fa03aaef2583d47b28 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 12 Feb 2019 08:57:24 -0500 Subject: [PATCH 11/71] Apply gamma correction to silhouette color --- Source/Scene/Model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index fbf1cfcde784..5f22e191f742 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -3874,7 +3874,7 @@ define([ 'uniform vec4 gltf_silhouetteColor; \n' + 'void main() \n' + '{ \n' + - ' gl_FragColor = gltf_silhouetteColor; \n' + + ' gl_FragColor = czm_gammaCorrect(gltf_silhouetteColor); \n' + '}'; return ShaderProgram.fromCache({ From 55e9514bb16c9d0cc4e960986e9bbb649435a309 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Tue, 12 Feb 2019 09:38:52 -0500 Subject: [PATCH 12/71] Don't use requirejs with minified Cesium. While the improvements in #7514 worked, they were a little more convoluted than they had to be and also caused some weird edge cases where loading Cesium in eval'd Node.js code didn't work. This change avoids using requirejs entirely when loading minified Cesium in Node and adds a smokescreen test to travis that fails in master. This also avoids the odd global workaround I had to put in place previously. I did have to modify the UMD headers for NoSleep.js and purify.js because their preference is to look for Node.js first and not use AMD if it's found, this was the root cause of the failures we were seeing in eval'd code. The smokescreen test I added will fail again if the problem were reintroduced. So overall, this make Cesium a little more node-friendly and just makes things cleaner from our end. --- .travis.yml | 3 ++- Source/ThirdParty/NoSleep.js | 4 ++-- Source/ThirdParty/purify.js | 2 +- Source/main.js | 6 +++--- index.js | 30 +++++++----------------------- 5 files changed, 15 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index 16856c3a2cf7..0c3fb49a68e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,9 @@ script: - npm --silent run test -- --browsers FirefoxHeadless --failTaskOnError --webgl-stub --release --suppressPassed +# Various Node.js smoke-screen tests + - node -e "const Cesium = require('./');" - NODE_ENV=development node index.js - - NODE_ENV=production node index.js - npm --silent run cloc diff --git a/Source/ThirdParty/NoSleep.js b/Source/ThirdParty/NoSleep.js index e5acd0255cf8..2cb7ce1a73cf 100644 --- a/Source/ThirdParty/NoSleep.js +++ b/Source/ThirdParty/NoSleep.js @@ -1,8 +1,8 @@ /*! NoSleep.js v0.7.0 - git.io/vfn01 - Rich Tibbett - MIT license */ (function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') + /* if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); - else if(typeof define === 'function' && define.amd) + else */ if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["NoSleep"] = factory(); diff --git a/Source/ThirdParty/purify.js b/Source/ThirdParty/purify.js index 6254d4513288..e4d0325c8ba9 100644 --- a/Source/ThirdParty/purify.js +++ b/Source/ThirdParty/purify.js @@ -1,5 +1,5 @@ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + // typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.DOMPurify = factory()); }(this, (function () { 'use strict'; diff --git a/Source/main.js b/Source/main.js index f99cf8b54761..8241e659bce5 100644 --- a/Source/main.js +++ b/Source/main.js @@ -6,13 +6,13 @@ require([ ], function( Cesium) { 'use strict'; - /*global self,global*/ + /*global self,module*/ if (typeof window !== 'undefined') { window.Cesium = Cesium; } else if (typeof self !== 'undefined') { self.Cesium = Cesium; - } else if (typeof global !== 'undefined') { - global.Cesium = Cesium; + } else if(typeof module !== 'undefined') { + module.exports = Cesium; } else { console.log('Unable to load Cesium.'); } diff --git a/index.js b/index.js index 40cc36b8fdb1..ea256e508a7e 100644 --- a/index.js +++ b/index.js @@ -2,36 +2,20 @@ 'use strict'; var path = require('path'); -var requirejs = require('requirejs'); -//In explicit development mode, use un-optimized requirejs modules for improved error checking. -if (process.env.NODE_ENV === 'development') { - requirejs.config({ - paths: { - 'Cesium': path.join(__dirname, 'Source') - }, - nodeRequire: require - }); - module.exports = requirejs('Cesium/Cesium'); +// If not explicitly in development mode, use the combined/minified/optimized version of Cesium +if (process.env.NODE_ENV !== 'development') { + module.exports = require(path.join(__dirname, 'Build/Cesium/Cesium')); return; } -//In all other cases, use minified Cesium for performance. +// Otherwise, use un-optimized requirejs modules for improved error checking. +var requirejs = require('requirejs'); requirejs.config({ paths: { - 'Cesium': path.join(__dirname, 'Build/Cesium/Cesium') + 'Cesium': path.join(__dirname, 'Source') }, nodeRequire: require }); -const hadCesiumProperty = global.hasOwnProperty('Cesium'); -const oldCesium = global.Cesium; - -requirejs('Cesium'); -module.exports = global.Cesium; - -if (hadCesiumProperty) { - global.Cesium = oldCesium; -} else { - delete global.Cesium; -} +module.exports = requirejs('Cesium/Cesium'); From 869722a4d4590faa092851bf1750724822e12550 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 14 Feb 2019 10:53:21 -0500 Subject: [PATCH 13/71] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index d36067da186d..6ec1209144ce 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ Change Log * Fixed an issue where some ground polygons crossing the Prime Meridian would have incorrect bounding rectangles. [#7533](https://github.com/AnalyticalGraphicsInc/cesium/pull/7533) * Fixed an issue where polygons on terrain using rhumb lines where being rendered incorrectly. [#7538](https://github.com/AnalyticalGraphicsInc/cesium/pulls/7538) * Fixed an issue with `EllipsoidRhumbLines.findIntersectionWithLongitude` when longitude was IDL. [#7551](https://github.com/AnalyticalGraphicsInc/cesium/issues/7551) +* Fixed model silhouette colors when rendering with high dynamic range. [#7563](https://github.com/AnalyticalGraphicsInc/cesium/pull/7563) ### 1.54 - 2019-02-01 From ad8a8235341e76c06c98faa71412f29f809c2e04 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Fri, 15 Feb 2019 08:50:29 -0500 Subject: [PATCH 14/71] Update all npm packages to latest versions. Closes #7536 --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ddba80dd7b5b..79c5ae7da0a8 100644 --- a/package.json +++ b/package.json @@ -39,10 +39,10 @@ "cloc": "^2.3.3", "compressible": "^2.0.9", "compression": "^1.6.2", - "eslint": "5.12.1", - "eslint-plugin-html": "^5.0.0", + "eslint": "^5.13.0", + "eslint-plugin-html": "^5.0.3", "express": "^4.15.0", - "globby": "^8.0.1", + "globby": "^9.0.0", "glsl-strip-comments": "^1.0.0", "gulp": "^4.0.0", "gulp-insert": "^0.5.0", @@ -53,7 +53,7 @@ "gulp-zip": "^4.0.0", "jasmine-core": "^3.3.0", "jsdoc": "^3.4.3", - "karma": "^3.1.1", + "karma": "^4.0.0", "karma-chrome-launcher": "^2.0.0", "karma-detect-browsers": "^2.2.3", "karma-edge-launcher": "^0.4.2", @@ -70,7 +70,7 @@ "request": "^2.79.0", "rimraf": "^2.6.1", "stream-to-promise": "^2.2.0", - "yargs": "^12.0.2" + "yargs": "^13.2.0" }, "scripts": { "start": "node server.js", From 96cbc181262b0cacba60bee3894dc221c237f693 Mon Sep 17 00:00:00 2001 From: Shehata Date: Mon, 18 Feb 2019 10:56:53 -0500 Subject: [PATCH 15/71] Add feature detection for createImageBitmap --- Source/Core/FeatureDetection.js | 71 +++++++++++++++++++++++++++++- Specs/Core/FeatureDetectionSpec.js | 22 +++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/Source/Core/FeatureDetection.js b/Source/Core/FeatureDetection.js index 6d0d02346d1c..941f7b8a9958 100644 --- a/Source/Core/FeatureDetection.js +++ b/Source/Core/FeatureDetection.js @@ -2,13 +2,11 @@ define([ './defaultValue', './defined', './Fullscreen', - './RuntimeError', '../ThirdParty/when' ], function( defaultValue, defined, Fullscreen, - RuntimeError, when) { 'use strict'; /*global CanvasPixelArray*/ @@ -255,6 +253,71 @@ define([ } } + var supportsCreateImageBitmapResult; + function supportsCreateImageBitmap() { + if (!defined(supportsCreateImageBitmapResult)) { + supportsCreateImageBitmapResult = defined(window.createImageBitmap); + } + + return supportsCreateImageBitmapResult; + } + + var supportsImageBitmapOptionsResult; + var supportsImageBitmapOptionsPromise; + function supportsImageBitmapOptions() { + // Until the HTML folks figure out what to do about this, we need to actually try loading an image to + // know if this browser supports passing options to the createImageBitmap function. + // https://github.com/whatwg/html/pull/4248 + if (defined(supportsImageBitmapOptionsPromise)) { + return supportsImageBitmapOptionsPromise.promise; + } + + supportsImageBitmapOptionsPromise = when.defer(); + + if (!supportsCreateImageBitmap()) { + supportsImageBitmapOptionsResult = false; + supportsImageBitmapOptionsPromise.resolve(supportsImageBitmapOptionsResult); + return supportsImageBitmapOptionsPromise.promise; + } + + var imageDataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWP4////fwAJ+wP9CNHoHgAAAABJRU5ErkJggg=='; + fetch(imageDataUri) + .then(function(response) { + return response.blob(); + }) + .then(function(blob) { + return createImageBitmap(blob, { + imageOrientation: 'flipY' + }); + }) + .then(function(imageBitmap) { + supportsImageBitmapOptionsResult = true; + supportsImageBitmapOptionsPromise.resolve(supportsImageBitmapOptionsResult); + }) + .catch(function() { + supportsImageBitmapOptionsResult = false; + supportsImageBitmapOptionsPromise.resolve(supportsImageBitmapOptionsResult); + }); + + return supportsImageBitmapOptionsPromise.promise; + } + + function supportsImageBitmapOptionsSync() { + if (!defined(supportsImageBitmapOptionsPromise)) { + supportsImageBitmapOptions(); + } + + return supportsImageBitmapOptionsResult; + } + + var supportsFetchApiResult; + function supportsFetchApi() { + if (!defined(supportsFetchApiResult)) { + supportsFetchApiResult = defined(window.fetch); + } + return supportsFetchApiResult; + } + /** * A set of functions to detect whether the current browser supports * various features. @@ -280,6 +343,10 @@ define([ supportsImageRenderingPixelated: supportsImageRenderingPixelated, supportsWebP: supportsWebP, supportsWebPSync: supportsWebPSync, + supportsCreateImageBitmap: supportsCreateImageBitmap, + supportsImageBitmapOptions: supportsImageBitmapOptions, + supportsImageBitmapOptionsSync: supportsImageBitmapOptionsSync, + supportsFetchApi : supportsFetchApi, imageRenderingValue: imageRenderingValue, typedArrayTypes: typedArrayTypes }; diff --git a/Specs/Core/FeatureDetectionSpec.js b/Specs/Core/FeatureDetectionSpec.js index 18c3eabf52b2..b2f84ab7a69c 100644 --- a/Specs/Core/FeatureDetectionSpec.js +++ b/Specs/Core/FeatureDetectionSpec.js @@ -123,4 +123,26 @@ defineSuite([ expect(FeatureDetection.supportsWebPSync()).toEqual(supportsWebP); }); }); + + it('detects fetch API support', function() { + var supportsFetchApi = FeatureDetection.supportsFetchApi(); + expect(typeof supportsFetchApi).toEqual('boolean'); + }); + + it('detects createImageBitmap support', function() { + var supportsCreateImageBitmap = FeatureDetection.supportsCreateImageBitmap(); + expect(typeof supportsCreateImageBitmap).toEqual('boolean'); + }); + + it('detects ImageBitmapOptions support', function() { + if (FeatureDetection.supportsCreateImageBitmap()) { + expect(FeatureDetection.supportsImageBitmapOptionsSync()).not.toBeDefined(); + } + + return FeatureDetection.supportsImageBitmapOptions() + .then(function(supportsImageBitmapOptions) { + expect(typeof supportsImageBitmapOptions).toEqual('boolean'); + expect(FeatureDetection.supportsImageBitmapOptionsSync()).toEqual(supportsImageBitmapOptions); + }); + }); }); From b772d527599c787968ba2d5b3e652811b0e3b82f Mon Sep 17 00:00:00 2001 From: Shehata Date: Mon, 18 Feb 2019 11:38:48 -0500 Subject: [PATCH 16/71] Use image bitmap and flip during fetch --- Source/Core/Resource.js | 84 +++++++++++++++---- Source/Core/loadImageFromTypedArray.js | 25 +++++- .../GoogleEarthEnterpriseImageryProvider.js | 5 +- Source/Scene/Model.js | 9 +- Source/Widgets/Viewer/Viewer.js | 6 ++ 5 files changed, 107 insertions(+), 22 deletions(-) diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index 28a752a2a5c1..6600f8ae9065 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -11,6 +11,7 @@ define([ './deprecationWarning', './DeveloperError', './freezeObject', + './FeatureDetection', './getAbsoluteUri', './getBaseUri', './getExtensionFromUri', @@ -39,6 +40,7 @@ define([ deprecationWarning, DeveloperError, freezeObject, + FeatureDetection, getAbsoluteUri, getBaseUri, getExtensionFromUri, @@ -250,6 +252,7 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. + * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried. * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -336,6 +339,14 @@ define([ this.retryAttempts = defaultValue(options.retryAttempts, 0); this._retryCount = 0; + /** + * Whether to vertically flip the image during fetch and decode. Only applies when requesting + * an image and the browser supports createImageBitmap. + * + * @type {Boolean} + */ + this.flipImage = defaultValue(options.flipImage, true); + var uri = new Uri(options.url); parseQuery(uri, this, true, true); @@ -620,6 +631,7 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). These will be combined with those of the current instance. * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. + * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The function to call when loading the resource fails. * @param {Number} [options.retryAttempts] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -664,6 +676,9 @@ define([ if (defined(options.retryAttempts)) { resource.retryAttempts = options.retryAttempts; } + if (defined(options.flipImage)) { + resource.flipImage = options.flipImage; + } return resource; }; @@ -714,6 +729,7 @@ define([ result.retryCallback = this.retryCallback; result.retryAttempts = this.retryAttempts; result._retryCount = 0; + result.flipImage = this.flipImage; result.request = this.request.clone(); return result; @@ -771,6 +787,7 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. + * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried. * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -815,6 +832,7 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. + * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried. * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -851,6 +869,7 @@ define([ */ Resource.prototype.fetchImage = function (preferBlob) { preferBlob = defaultValue(preferBlob, false); + var flipImage = this.flipImage; checkAndResetRequest(this.request); @@ -860,7 +879,7 @@ define([ // 3. It's a blob URI // 4. It doesn't have request headers and we preferBlob is false if (!xhrBlobSupported || this.isDataUri || this.isBlobUri || (!this.hasHeaders && !preferBlob)) { - return fetchImage(this, true); + return fetchImage(this); } var blobPromise = this.fetchBlob(); @@ -878,7 +897,8 @@ define([ generatedBlob = blob; var blobUrl = window.URL.createObjectURL(blob); generatedBlobResource = new Resource({ - url: blobUrl + url: blobUrl, + flipImage: flipImage }); return fetchImage(generatedBlobResource); @@ -908,6 +928,7 @@ define([ request.url = resource.url; request.requestFunction = function() { var url = resource.url; + var flipImage = resource.flipImage; var crossOrigin = false; // data URIs can't have crossorigin set. @@ -917,7 +938,7 @@ define([ var deferred = when.defer(); - Resource._Implementations.createImage(url, crossOrigin, deferred); + Resource._Implementations.createImage(url, crossOrigin, deferred, flipImage); return deferred.promise; }; @@ -958,6 +979,7 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. + * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried. * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -1378,6 +1400,7 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. + * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried. * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -1755,26 +1778,51 @@ define([ */ Resource._Implementations = {}; - Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - var image = new Image(); + Resource._Implementations.createImage = function(url, crossOrigin, deferred, flipImage) { + var supportsBitmapOptions = FeatureDetection.supportsImageBitmapOptionsSync(); - image.onload = function() { - deferred.resolve(image); - }; + if (FeatureDetection.supportsFetchApi() && FeatureDetection.supportsCreateImageBitmap() && defined(supportsBitmapOptions)) { + fetch(url, { + credentials: (crossOrigin && TrustedServers.contains(url)) ? 'include' : 'same-origin' + }) + .then(function(response) { + // Catch error here https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful + return response.blob(); + }) + .then(function(blob) { + if (!supportsBitmapOptions) { + return createImageBitmap(blob); + } - image.onerror = function(e) { - deferred.reject(e); - }; + return createImageBitmap(blob, { + imageOrientation: flipImage ? 'flipY' : 'none' + }); + }) + .then(function (imageBitmap) { + deferred.resolve(imageBitmap); + }) + .catch(deferred.reject); + } else { + var image = new Image(); - if (crossOrigin) { - if (TrustedServers.contains(url)) { - image.crossOrigin = 'use-credentials'; - } else { - image.crossOrigin = ''; + image.onload = function() { + deferred.resolve(image); + }; + + image.onerror = function(e) { + deferred.reject(e); + }; + + if (crossOrigin) { + if (TrustedServers.contains(url)) { + image.crossOrigin = 'use-credentials'; + } else { + image.crossOrigin = ''; + } } - } - image.src = url; + image.src = url; + } }; function decodeResponse(loadWithHttpResponse, responseType) { diff --git a/Source/Core/loadImageFromTypedArray.js b/Source/Core/loadImageFromTypedArray.js index fa2df18dc4d7..d64f5f781475 100644 --- a/Source/Core/loadImageFromTypedArray.js +++ b/Source/Core/loadImageFromTypedArray.js @@ -1,17 +1,27 @@ define([ '../ThirdParty/when', './Check', + './defined', + './defaultValue', + './FeatureDetection', './Resource' ], function( when, Check, + defined, + defaultValue, + FeatureDetection, Resource) { 'use strict'; /** * @private */ - function loadImageFromTypedArray(uint8Array, format, request) { + function loadImageFromTypedArray(options) { + var uint8Array = options.uint8Array; + var format = options.format; + var request = options.request; + var flipY = defaultValue(options.flipY, true); //>>includeStart('debug', pragmas.debug); Check.typeOf.object('uint8Array', uint8Array); Check.typeOf.string('format', format); @@ -21,6 +31,19 @@ define([ type : format }); + // We can avoid the extra fetch when createImageBitmap is supported. + var supportsBitmapOptions = FeatureDetection.supportsImageBitmapOptionsSync(); + + if (FeatureDetection.supportsCreateImageBitmap() && defined(supportsBitmapOptions)) { + if (supportsBitmapOptions) { + return when(createImageBitmap(blob, { + imageOrientation: flipY ? 'flipY' : 'none' + })); + } + + return when(createImageBitmap(blob)); + } + var blobUrl = window.URL.createObjectURL(blob); var resource = new Resource({ url: blobUrl, diff --git a/Source/Scene/GoogleEarthEnterpriseImageryProvider.js b/Source/Scene/GoogleEarthEnterpriseImageryProvider.js index 5e71d409ef50..38e37358383d 100644 --- a/Source/Scene/GoogleEarthEnterpriseImageryProvider.js +++ b/Source/Scene/GoogleEarthEnterpriseImageryProvider.js @@ -488,7 +488,10 @@ define([ return invalidImage; } - return loadImageFromTypedArray(a, type); + return loadImageFromTypedArray({ + uint8Array: a, + format: type + }); }); }; diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 5f22e191f742..e7d81bdac386 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -1714,7 +1714,8 @@ define([ ++model._loadResources.pendingTextureLoads; var imageResource = model._resource.getDerivedResource({ - url : uri + url : uri, + flipImage : false }); var promise; @@ -2325,7 +2326,11 @@ define([ ++model._loadResources.pendingTextureLoads; } else { var onload = getOnImageCreatedFromTypedArray(loadResources, gltfTexture); - loadImageFromTypedArray(loadResources.getBuffer(bufferView), gltfTexture.mimeType) + loadImageFromTypedArray({ + uint8Array: loadResources.getBuffer(bufferView), + format: gltfTexture.mimeType, + flipY: false + }) .then(onload).otherwise(onerror); ++loadResources.pendingBufferViewToImage; } diff --git a/Source/Widgets/Viewer/Viewer.js b/Source/Widgets/Viewer/Viewer.js index d9664a7bb540..5c286670fb43 100644 --- a/Source/Widgets/Viewer/Viewer.js +++ b/Source/Widgets/Viewer/Viewer.js @@ -10,6 +10,7 @@ define([ '../../Core/DeveloperError', '../../Core/Event', '../../Core/EventHelper', + '../../Core/FeatureDetection', '../../Core/HeadingPitchRange', '../../Core/isArray', '../../Core/Matrix4', @@ -60,6 +61,7 @@ define([ DeveloperError, Event, EventHelper, + FeatureDetection, HeadingPitchRange, isArray, Matrix4, @@ -361,6 +363,10 @@ define([ } //>>includeEnd('debug'); + // We kick off this asynchronous test here so we can start using + // createImageBitmap if it's supported as soon as possible. + FeatureDetection.supportsImageBitmapOptions(); + container = getElement(container); options = defaultValue(options, defaultValue.EMPTY_OBJECT); From dca9ed1accb55fcd753552dbbc69185bf6e2d0b9 Mon Sep 17 00:00:00 2001 From: Shehata Date: Mon, 18 Feb 2019 11:42:26 -0500 Subject: [PATCH 17/71] Add tests for image bitmap scenarios --- Specs/Core/ResourceSpec.js | 141 ++++++++++++++++++++-- Specs/Core/loadImageFromTypedArraySpec.js | 79 +++++++++++- Specs/Renderer/TextureSpec.js | 104 +++++++++++----- 3 files changed, 283 insertions(+), 41 deletions(-) diff --git a/Specs/Core/ResourceSpec.js b/Specs/Core/ResourceSpec.js index cc9bad6ded5a..1357aabbdfb1 100644 --- a/Specs/Core/ResourceSpec.js +++ b/Specs/Core/ResourceSpec.js @@ -2,24 +2,36 @@ defineSuite([ 'Core/Resource', 'Core/defaultValue', 'Core/DefaultProxy', + 'Core/FeatureDetection', 'Core/queryToObject', 'Core/Request', 'Core/RequestErrorEvent', 'Core/RequestScheduler', + 'Core/TrustedServers', + 'Specs/createCanvas', 'ThirdParty/Uri', 'ThirdParty/when' ], function( Resource, defaultValue, DefaultProxy, + FeatureDetection, queryToObject, Request, RequestErrorEvent, RequestScheduler, + TrustedServers, + createCanvas, Uri, when) { 'use strict'; + var dataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2Nk+M/wHwAEBgIA5agATwAAAABJRU5ErkJggg=='; + + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + it('Constructor sets correct properties', function() { var proxy = new DefaultProxy('/proxy/'); var request = new Request(); @@ -1122,26 +1134,141 @@ defineSuite([ }); }); - describe('fetchImage', function() { + it('can load an image preferring blob', function() { + return Resource.fetchImage('./Data/Images/Green.png', true).then(function(loadedImage) { + expect(loadedImage.width).toEqual(1); + expect(loadedImage.height).toEqual(1); + }); + }); - var dataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2Nk+M/wHwAEBgIA5agATwAAAABJRU5ErkJggg=='; + it('can load an image from a data URI', function() { + return Resource.fetchImage(dataUri).then(function(loadedImage) { + expect(loadedImage.width).toEqual(1); + expect(loadedImage.height).toEqual(1); + }); + }); - it('can load an image', function() { + describe('fetchImage with ImageBitmap', function() { + if (!FeatureDetection.supportsCreateImageBitmap()) { + return; + } + + var canvas; + beforeAll(function() { + canvas = createCanvas(1, 2); + }); + + afterAll(function() { + document.body.removeChild(canvas); + }); + + function getColorAtPixel(image, x, y) { + var context = canvas.getContext('2d'); + context.drawImage(image, 0, 0, image.width, image.height); + var imageData = context.getImageData(0, 0, 1, 1); + return [imageData.data[0], imageData.data[1], imageData.data[2], imageData.data[3]]; + } + + it('can load and decode an image', function() { return Resource.fetchImage('./Data/Images/Green.png').then(function(loadedImage) { expect(loadedImage.width).toEqual(1); expect(loadedImage.height).toEqual(1); + expect(loadedImage instanceof ImageBitmap); }); }); - it('can load an image preferring blob', function() { - return Resource.fetchImage('./Data/Images/Green.png', true).then(function(loadedImage) { + it('does not call createImageBitmap when ImageBitmapOptions support is not ready', function() { + spyOn(FeatureDetection, 'supportsImageBitmapOptionsSync').and.returnValue(undefined); + spyOn(window, 'createImageBitmap').and.callThrough(); + + return Resource.fetchImage('./Data/Images/Green.png').then(function(loadedImage) { expect(loadedImage.width).toEqual(1); expect(loadedImage.height).toEqual(1); + expect(window.createImageBitmap).not.toHaveBeenCalled(); + }); + }); + + it('correctly flips image when ImageBitmapOptions are supported', function() { + return Resource.fetchImage({ + url: './Data/Images/BlueOverRed.png', + flipImage: true + }).then(function(loadedImage) { + if (FeatureDetection.supportsImageBitmapOptionsSync()) { + expect(getColorAtPixel(loadedImage, 0, 0)).toEqual([255, 0, 0, 255]); + } else { + expect(getColorAtPixel(loadedImage, 0, 0)).toEqual([0, 0, 255, 255]); + } + }); + }); + + it('correctly loads image without flip when ImageBitmapOptions are supported', function() { + return Resource.fetchImage({ + url: './Data/Images/BlueOverRed.png', + flipImage: false + }).then(function(loadedImage) { + if (FeatureDetection.supportsImageBitmapOptionsSync()) { + expect(getColorAtPixel(loadedImage, 0, 0)).toEqual([0, 0, 255, 255]); + } else { + expect(getColorAtPixel(loadedImage, 0, 0)).toEqual([0, 0, 255, 255]); + } }); }); - it('can load an image from a data URI', function() { - return Resource.fetchImage(dataUri).then(function(loadedImage) { + it('does not pass options when ImageBitmapOptions are not supported', function() { + spyOn(FeatureDetection, 'supportsImageBitmapOptionsSync').and.returnValue(false); + spyOn(window, 'createImageBitmap').and.callThrough(); + + return Resource.fetchImage('./Data/Images/Green.png').then(function(loadedImage) { + expect(window.createImageBitmap).toHaveBeenCalledWith(new Blob()); + }); + }); + + it('rejects the promise when the image errors', function() { + return Resource.fetchImage('http://example.invalid/testuri.png') + .then(function() { + fail('expected promise to reject'); + }) + .otherwise(function(error) { + expect(error).toBeInstanceOf(TypeError); + }); + }); + + it('does not set credentials for untrusted cross-origin images using fetch API', function() { + var fetchSpy = spyOn(window, 'fetch').and.callThrough(); + var url = './Data/Images/Green.png'; + + return Resource.fetchImage(url) + .then(function() { + expect(fetchSpy).toHaveBeenCalledWith(url, { + credentials: 'same-origin' + }); + }); + }); + + it('sets credentials for trusted cross-origin images using fetch API', function() { + var fetchSpy = spyOn(window, 'fetch').and.callThrough(); + spyOn(TrustedServers, 'contains').and.returnValue(true); + var url = 'http://example.invalid/testuri.png'; + + return Resource.fetchImage(url) + .otherwise(function() { + expect(fetchSpy).toHaveBeenCalledWith(url, { + credentials: 'include' + }); + }); + }); + }); + + describe('fetchImage without ImageBitmap', function() { + beforeAll(function() { + // Force it to use the Image constructor since these specs all test + // specific functionality of this code path. For example, the crossOrigin + // restriction does not apply to images loaded with ImageBitmap. + spyOn(FeatureDetection, 'supportsCreateImageBitmap').and.returnValue(false); + }); + + it('can load an image', function() { + return Resource.fetchImage('./Data/Images/Green.png').then(function(loadedImage) { expect(loadedImage.width).toEqual(1); expect(loadedImage.height).toEqual(1); }); diff --git a/Specs/Core/loadImageFromTypedArraySpec.js b/Specs/Core/loadImageFromTypedArraySpec.js index 43e705f6ee49..e21b800bdc38 100644 --- a/Specs/Core/loadImageFromTypedArraySpec.js +++ b/Specs/Core/loadImageFromTypedArraySpec.js @@ -1,24 +1,89 @@ defineSuite([ 'Core/loadImageFromTypedArray', + 'Core/FeatureDetection', 'Core/Resource' ], function( loadImageFromTypedArray, + FeatureDetection, Resource) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + it('can load an image', function() { return Resource.fetchArrayBuffer('./Data/Images/Blue10x10.png').then(function(arrayBuffer) { - var arr = new Uint8Array(arrayBuffer); - return loadImageFromTypedArray(arr, 'image/png').then(function(image) { + var options = { + uint8Array: new Uint8Array(arrayBuffer), + format: 'image/png' + }; + + return loadImageFromTypedArray(options).then(function(image) { + expect(image.width).toEqual(10); + expect(image.height).toEqual(10); + }); + }); + }); + + it('flips image when ImageBitmapOptions are supported', function() { + var options = { + uint8Array: new Uint8Array([67, 101, 115, 105, 117, 109]), // This is an invalid PNG. + format: 'image/png', + flipY: true + }; + spyOn(window, 'createImageBitmap'); + var blob = new Blob([options.uint8Array], { + type : options.format + }); + + return loadImageFromTypedArray(options).then(function() { + if (FeatureDetection.supportsImageBitmapOptionsSync()) { + expect(window.createImageBitmap).toHaveBeenCalledWith(blob, { + imageOrientation: 'flipY' + }); + } else { + expect(window.createImageBitmap).toHaveBeenCalledWith(blob); + } + + options.flipY = false; + window.createImageBitmap.calls.reset(); + return loadImageFromTypedArray(options); + }) + .then(function() { + if (FeatureDetection.supportsImageBitmapOptionsSync()) { + expect(window.createImageBitmap).toHaveBeenCalledWith(blob, { + imageOrientation: 'none' + }); + } else { + expect(window.createImageBitmap).toHaveBeenCalledWith(blob); + } + }); + }); + + it('can load an image when ImageBitmap is not supported', function() { + spyOn(FeatureDetection, 'supportsCreateImageBitmap').and.returnValue(false); + spyOn(window, 'createImageBitmap').and.callThrough(); + return Resource.fetchArrayBuffer('./Data/Images/Blue10x10.png').then(function(arrayBuffer) { + var options = { + uint8Array: new Uint8Array(arrayBuffer), + format: 'image/png' + }; + + return loadImageFromTypedArray(options).then(function(image) { expect(image.width).toEqual(10); expect(image.height).toEqual(10); + expect(window.createImageBitmap).not.toHaveBeenCalled(); }); }); }); it('can not load an invalid image', function() { - var notApng = new Uint8Array([67, 101, 115, 105, 117, 109]); - return loadImageFromTypedArray(notApng, 'image/png').then(function(image) { + var options = { + uint8Array: new Uint8Array([67, 101, 115, 105, 117, 109]), // This is an invalid PNG. + format: 'image/png' + }; + return loadImageFromTypedArray(options).then(function(image) { fail('should not be called'); }).otherwise(function() { }); @@ -26,13 +91,15 @@ defineSuite([ it('Throws without array', function() { expect(function() { - loadImageFromTypedArray(); + loadImageFromTypedArray({}); }).toThrowDeveloperError(); }); it('Throws without format', function() { expect(function() { - loadImageFromTypedArray(new Uint8Array()); + loadImageFromTypedArray({ + uint8Array: new Uint8Array() + }); }).toThrowDeveloperError(); }); }); diff --git a/Specs/Renderer/TextureSpec.js b/Specs/Renderer/TextureSpec.js index ad0bb76976b0..cb8b269c34c8 100644 --- a/Specs/Renderer/TextureSpec.js +++ b/Specs/Renderer/TextureSpec.js @@ -2,6 +2,7 @@ defineSuite([ 'Renderer/Texture', 'Core/Cartesian2', 'Core/Color', + 'Core/FeatureDetection', 'Core/loadKTX', 'Core/PixelFormat', 'Core/Resource', @@ -18,6 +19,7 @@ defineSuite([ Texture, Cartesian2, Color, + FeatureDetection, loadKTX, PixelFormat, Resource, @@ -37,6 +39,7 @@ defineSuite([ var blueImage; var blueAlphaImage; var blueOverRedImage; + var blueOverRedUnflippedImage; var red16x16Image; var greenDXTImage; @@ -55,34 +58,43 @@ defineSuite([ beforeAll(function() { context = createContext(); - - var promises = []; - promises.push(Resource.fetchImage('./Data/Images/Green.png').then(function(image) { - greenImage = image; - })); - promises.push(Resource.fetchImage('./Data/Images/Blue.png').then(function(image) { - blueImage = image; - })); - promises.push(Resource.fetchImage('./Data/Images/BlueAlpha.png').then(function(image) { - blueAlphaImage = image; - })); - promises.push(Resource.fetchImage('./Data/Images/BlueOverRed.png').then(function(image) { - blueOverRedImage = image; - })); - promises.push(Resource.fetchImage('./Data/Images/Red16x16.png').then(function(image) { - red16x16Image = image; - })); - promises.push(loadKTX('./Data/Images/Green4x4DXT1.ktx').then(function(image) { - greenDXTImage = image; - })); - promises.push(loadKTX('./Data/Images/Green4x4PVR.ktx').then(function(image) { - greenPVRImage = image; - })); - promises.push(loadKTX('./Data/Images/Green4x4ETC1.ktx').then(function(image) { - greenETC1Image = image; - })); - - return when.all(promises); + return FeatureDetection.supportsImageBitmapOptions() + .then(function() { + var promises = []; + promises.push(Resource.fetchImage('./Data/Images/Green.png').then(function(image) { + greenImage = image; + })); + promises.push(Resource.fetchImage('./Data/Images/Blue.png').then(function(image) { + blueImage = image; + })); + promises.push(Resource.fetchImage('./Data/Images/BlueAlpha.png').then(function(image) { + blueAlphaImage = image; + })); + promises.push(Resource.fetchImage('./Data/Images/BlueOverRed.png').then(function(image) { + blueOverRedImage = image; + })); + // Turn off the default flipping. + promises.push(Resource.fetchImage({ + url: './Data/Images/BlueOverRed.png', + flipImage: false + }).then(function(image) { + blueOverRedUnflippedImage = image; + })); + promises.push(Resource.fetchImage('./Data/Images/Red16x16.png').then(function(image) { + red16x16Image = image; + })); + promises.push(loadKTX('./Data/Images/Green4x4DXT1.ktx').then(function(image) { + greenDXTImage = image; + })); + promises.push(loadKTX('./Data/Images/Green4x4PVR.ktx').then(function(image) { + greenPVRImage = image; + })); + promises.push(loadKTX('./Data/Images/Green4x4ETC1.ktx').then(function(image) { + greenETC1Image = image; + })); + + return when.all(promises); + }); }); afterAll(function() { @@ -187,6 +199,42 @@ defineSuite([ }).contextToRender([0, 0, 255, 255]); }); + it('can set flip texture only if ImageBitmapOptions is not supported', function() { + var topColor = new Color(0.0, 0.0, 1.0, 1.0); + var bottomColor = new Color(1.0, 0.0, 0.0, 1.0); + if (FeatureDetection.supportsImageBitmapOptionsSync()) { + // When imageBitmapOptions is supported, flipY on texture upload is ignored. + bottomColor = topColor; + } + + texture = new Texture({ + context : context, + source : blueOverRedUnflippedImage, + pixelFormat : PixelFormat.RGBA, + flipY : false + }); + + expect({ + context : context, + fragmentShader : fs, + uniformMap : uniformMap + }).contextToRender(topColor.toBytes()); + + // Flip the texture. + texture = new Texture({ + context : context, + source : blueOverRedUnflippedImage, + pixelFormat : PixelFormat.RGBA, + flipY : true + }); + + expect({ + context : context, + fragmentShader : fs, + uniformMap : uniformMap + }).contextToRender(bottomColor.toBytes()); + }); + it('draws the expected floating-point texture color', function() { if (!context.floatingPointTexture) { return; From 824ceb12e6a38208c44609a034365c78cc55296d Mon Sep 17 00:00:00 2001 From: Shehata Date: Mon, 18 Feb 2019 11:52:43 -0500 Subject: [PATCH 18/71] Update imagery specs to for imagebitmap --- .../ArcGisMapServerImageryProviderSpec.js | 20 ++- Specs/Scene/BillboardCollectionSpec.js | 46 +++-- Specs/Scene/BingMapsImageryProviderSpec.js | 14 +- ...oogleEarthEnterpriseImageryProviderSpec.js | 9 +- .../GoogleEarthEnterpriseMapsProviderSpec.js | 16 +- Specs/Scene/MapboxImageryProviderSpec.js | 22 ++- Specs/Scene/SingleTileImageryProviderSpec.js | 12 +- Specs/Scene/TextureAtlasSpec.js | 164 ++++++++++-------- Specs/Scene/UrlTemplateImageryProviderSpec.js | 48 ++--- .../Scene/WebMapServiceImageryProviderSpec.js | 24 ++- .../WebMapTileServiceImageryProviderSpec.js | 12 +- .../createOpenStreetMapImageryProviderSpec.js | 24 ++- ...createTileMapServiceImageryProviderSpec.js | 20 ++- Specs/isImageOrImageBitmap.js | 19 ++ 14 files changed, 291 insertions(+), 159 deletions(-) create mode 100644 Specs/isImageOrImageBitmap.js diff --git a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js index e9a237bb2b5e..1d0742fe497c 100644 --- a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js +++ b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js @@ -6,6 +6,7 @@ defineSuite([ 'Core/Cartographic', 'Core/DefaultProxy', 'Core/defined', + 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/getAbsoluteUri', 'Core/objectToQuery', @@ -22,6 +23,7 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap', 'ThirdParty/Uri' ], function( ArcGisMapServerImageryProvider, @@ -31,6 +33,7 @@ defineSuite([ Cartographic, DefaultProxy, defined, + FeatureDetection, GeographicTilingScheme, getAbsoluteUri, objectToQuery, @@ -47,9 +50,14 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, + isImageOrImageBitmap, Uri) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + beforeEach(function() { RequestScheduler.clearForSpecs(); }); @@ -225,7 +233,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -302,7 +310,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -355,7 +363,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -419,7 +427,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -475,7 +483,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -609,7 +617,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/BillboardCollectionSpec.js b/Specs/Scene/BillboardCollectionSpec.js index dcfc161d223a..9afcdfa9058c 100644 --- a/Specs/Scene/BillboardCollectionSpec.js +++ b/Specs/Scene/BillboardCollectionSpec.js @@ -6,7 +6,9 @@ defineSuite([ 'Core/Cartesian3', 'Core/CesiumTerrainProvider', 'Core/Color', + 'Core/createGuid', 'Core/DistanceDisplayCondition', + 'Core/FeatureDetection', 'Core/Math', 'Core/NearFarScalar', 'Core/OrthographicOffCenterFrustum', @@ -31,7 +33,9 @@ defineSuite([ Cartesian3, CesiumTerrainProvider, Color, + createGuid, DistanceDisplayCondition, + FeatureDetection, CesiumMath, NearFarScalar, OrthographicOffCenterFrustum, @@ -65,19 +69,23 @@ defineSuite([ context = scene.context; camera = scene.camera; - return when.join( - Resource.fetchImage('./Data/Images/Green2x2.png').then(function(result) { - greenImage = result; - }), - Resource.fetchImage('./Data/Images/Blue2x2.png').then(function(result) { - blueImage = result; - }), - Resource.fetchImage('./Data/Images/White2x2.png').then(function(result) { - whiteImage = result; - }), - Resource.fetchImage('./Data/Images/Blue10x10.png').then(function(result) { - largeBlueImage = result; - })); + return FeatureDetection.supportsImageBitmapOptions() + .then(function() { + return when.join( + Resource.fetchImage('./Data/Images/Green2x2.png').then(function(result) { + greenImage = result; + }), + Resource.fetchImage('./Data/Images/Blue2x2.png').then(function(result) { + blueImage = result; + }), + Resource.fetchImage('./Data/Images/White2x2.png').then(function(result) { + whiteImage = result; + }), + Resource.fetchImage('./Data/Images/Blue10x10.png').then(function(result) { + largeBlueImage = result; + }) + ); + }); }); afterAll(function() { @@ -174,7 +182,7 @@ defineSuite([ expect(b.horizontalOrigin).toEqual(HorizontalOrigin.LEFT); expect(b.verticalOrigin).toEqual(VerticalOrigin.BOTTOM); expect(b.scale).toEqual(2.0); - expect(b.image).toEqual(greenImage.src); + expect(b.image).toEqual(b._imageId); expect(b.color.red).toEqual(1.0); expect(b.color.green).toEqual(2.0); expect(b.color.blue).toEqual(3.0); @@ -221,7 +229,7 @@ defineSuite([ expect(b.horizontalOrigin).toEqual(HorizontalOrigin.LEFT); expect(b.verticalOrigin).toEqual(VerticalOrigin.BOTTOM); expect(b.scale).toEqual(2.0); - expect(b.image).toEqual(greenImage.src); + expect(b.image).toEqual(b._imageId); expect(b.color.red).toEqual(1.0); expect(b.color.green).toEqual(2.0); expect(b.color.blue).toEqual(3.0); @@ -822,7 +830,7 @@ defineSuite([ expect(scene).toRender([0, 255, 0, 255]); - b.setImage(largeBlueImage.src, largeBlueImage); + b.setImage(createGuid(), largeBlueImage); expect(scene).toRender([0, 0, 255, 255]); }); @@ -834,8 +842,10 @@ defineSuite([ expect(scene).toRender([0, 255, 0, 255]); - billboards.textureAtlas.addImage(largeBlueImage.src, largeBlueImage); - b.setImageSubRegion(largeBlueImage.src, new BoundingRectangle(5.0, 5.0, 1.0, 1.0)); + var guid = createGuid(); + + billboards.textureAtlas.addImage(guid, largeBlueImage); + b.setImageSubRegion(guid, new BoundingRectangle(5.0, 5.0, 1.0, 1.0)); expect(scene).toRender([0, 0, 255, 255]); }); diff --git a/Specs/Scene/BingMapsImageryProviderSpec.js b/Specs/Scene/BingMapsImageryProviderSpec.js index d6ad4385659b..31fa49304401 100644 --- a/Specs/Scene/BingMapsImageryProviderSpec.js +++ b/Specs/Scene/BingMapsImageryProviderSpec.js @@ -3,6 +3,7 @@ defineSuite([ 'Core/appendForwardSlash', 'Core/DefaultProxy', 'Core/defined', + 'Core/FeatureDetection', 'Core/queryToObject', 'Core/RequestScheduler', 'Core/Resource', @@ -14,12 +15,14 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap', 'ThirdParty/Uri' ], function( BingMapsImageryProvider, appendForwardSlash, DefaultProxy, defined, + FeatureDetection, queryToObject, RequestScheduler, Resource, @@ -31,9 +34,14 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, + isImageOrImageBitmap, Uri) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + beforeEach(function() { RequestScheduler.clearForSpecs(); }); @@ -362,7 +370,7 @@ defineSuite([ }); return provider.requestImage(0, 0, 0).then(function(image) { - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -393,7 +401,7 @@ defineSuite([ }); return provider.requestImage(0, 0, 0).then(function(image) { - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -482,7 +490,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js index 26d201f4baa1..7fde0a564c6c 100644 --- a/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js @@ -4,6 +4,7 @@ defineSuite([ 'Core/DefaultProxy', 'Core/defaultValue', 'Core/defined', + 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/GoogleEarthEnterpriseMetadata', 'Core/GoogleEarthEnterpriseTileInformation', @@ -16,6 +17,7 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap', 'ThirdParty/Uri', 'ThirdParty/when' ], function( @@ -24,6 +26,7 @@ defineSuite([ DefaultProxy, defaultValue, defined, + FeatureDetection, GeographicTilingScheme, GoogleEarthEnterpriseMetadata, GoogleEarthEnterpriseTileInformation, @@ -36,6 +39,7 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, + isImageOrImageBitmap, Uri, when) { 'use strict'; @@ -46,6 +50,7 @@ defineSuite([ beforeAll(function() { decodeGoogleEarthEnterpriseData.passThroughDataForTesting = true; + return FeatureDetection.supportsImageBitmapOptions(); }); afterAll(function() { @@ -224,7 +229,7 @@ defineSuite([ installFakeImageRequest('http://fake.fake.invalid/flatfile?f1-03-i.1'); return imageryProvider.requestImage(0, 0, 0).then(function(image) { - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -294,7 +299,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js index 4915de445d52..40496cff3975 100644 --- a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js @@ -1,6 +1,7 @@ defineSuite([ 'Scene/GoogleEarthEnterpriseMapsProvider', 'Core/DefaultProxy', + 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/Rectangle', 'Core/RequestScheduler', @@ -10,10 +11,12 @@ defineSuite([ 'Scene/ImageryLayer', 'Scene/ImageryProvider', 'Scene/ImageryState', - 'Specs/pollToPromise' + 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap' ], function( GoogleEarthEnterpriseMapsProvider, DefaultProxy, + FeatureDetection, GeographicTilingScheme, Rectangle, RequestScheduler, @@ -23,9 +26,14 @@ defineSuite([ ImageryLayer, ImageryProvider, ImageryState, - pollToPromise) { + pollToPromise, + isImageOrImageBitmap) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + afterEach(function() { Resource._Implementations.createImage = Resource._DefaultImplementations.createImage; Resource._Implementations.loadWithXhr = Resource._DefaultImplementations.loadWithXhr; @@ -191,7 +199,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -327,7 +335,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/MapboxImageryProviderSpec.js b/Specs/Scene/MapboxImageryProviderSpec.js index f5800da3d40f..eef7fbc1dd49 100644 --- a/Specs/Scene/MapboxImageryProviderSpec.js +++ b/Specs/Scene/MapboxImageryProviderSpec.js @@ -1,6 +1,7 @@ defineSuite([ 'Scene/MapboxImageryProvider', 'Core/DefaultProxy', + 'Core/FeatureDetection', 'Core/Math', 'Core/Rectangle', 'Core/RequestScheduler', @@ -10,10 +11,12 @@ defineSuite([ 'Scene/ImageryLayer', 'Scene/ImageryProvider', 'Scene/ImageryState', - 'Specs/pollToPromise' + 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap' ], function( MapboxImageryProvider, DefaultProxy, + FeatureDetection, CesiumMath, Rectangle, RequestScheduler, @@ -23,9 +26,14 @@ defineSuite([ ImageryLayer, ImageryProvider, ImageryState, - pollToPromise) { + pollToPromise, + isImageOrImageBitmap) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + beforeEach(function() { RequestScheduler.clearForSpecs(); }); @@ -103,7 +111,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -126,7 +134,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -155,7 +163,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -187,7 +195,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -271,7 +279,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/SingleTileImageryProviderSpec.js b/Specs/Scene/SingleTileImageryProviderSpec.js index bd060548b22a..1482014aed4d 100644 --- a/Specs/Scene/SingleTileImageryProviderSpec.js +++ b/Specs/Scene/SingleTileImageryProviderSpec.js @@ -2,6 +2,7 @@ defineSuite([ 'Scene/SingleTileImageryProvider', 'Core/DefaultProxy', 'Core/Ellipsoid', + 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/Rectangle', 'Core/Resource', @@ -10,11 +11,13 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap', 'ThirdParty/when' ], function( SingleTileImageryProvider, DefaultProxy, Ellipsoid, + FeatureDetection, GeographicTilingScheme, Rectangle, Resource, @@ -23,9 +26,14 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, + isImageOrImageBitmap, when) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + afterEach(function() { Resource._Implementations.createImage = Resource._DefaultImplementations.createImage; }); @@ -150,7 +158,7 @@ defineSuite([ return provider.ready; }).then(function() { return when(provider.requestImage(0, 0, 0), function(image) { - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -216,7 +224,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/TextureAtlasSpec.js b/Specs/Scene/TextureAtlasSpec.js index def26465a7ef..ef47f4b813b5 100644 --- a/Specs/Scene/TextureAtlasSpec.js +++ b/Specs/Scene/TextureAtlasSpec.js @@ -2,6 +2,8 @@ defineSuite([ 'Scene/TextureAtlas', 'Core/BoundingRectangle', 'Core/Cartesian2', + 'Core/createGuid', + 'Core/FeatureDetection', 'Core/Math', 'Core/PixelFormat', 'Core/Resource', @@ -11,6 +13,8 @@ defineSuite([ TextureAtlas, BoundingRectangle, Cartesian2, + createGuid, + FeatureDetection, CesiumMath, PixelFormat, Resource, @@ -26,29 +30,39 @@ defineSuite([ var bigRedImage; var bigBlueImage; var bigGreenImage; + var guidArray; beforeAll(function() { scene = createScene(); - - return when.join( - Resource.fetchImage('./Data/Images/Green.png').then(function(image) { - greenImage = image; - }), - Resource.fetchImage('./Data/Images/Green1x4.png').then(function(image) { - tallGreenImage = image; - }), - Resource.fetchImage('./Data/Images/Blue.png').then(function(image) { - blueImage = image; - }), - Resource.fetchImage('./Data/Images/Red16x16.png').then(function(image) { - bigRedImage = image; - }), - Resource.fetchImage('./Data/Images/Blue10x10.png').then(function(image) { - bigBlueImage = image; - }), - Resource.fetchImage('./Data/Images/Green4x4.png').then(function(image) { - bigGreenImage = image; - })); + // Create enough guid's to use throughout these tests. + guidArray = []; + for (var i = 0; i < 4; ++i) { + guidArray.push(createGuid()); + } + + return FeatureDetection.supportsImageBitmapOptions() + .then(function() { + return when.join( + Resource.fetchImage('./Data/Images/Green.png').then(function(image) { + greenImage = image; + }), + Resource.fetchImage('./Data/Images/Green1x4.png').then(function(image) { + tallGreenImage = image; + }), + Resource.fetchImage('./Data/Images/Blue.png').then(function(image) { + blueImage = image; + }), + Resource.fetchImage('./Data/Images/Red16x16.png').then(function(image) { + bigRedImage = image; + }), + Resource.fetchImage('./Data/Images/Blue10x10.png').then(function(image) { + bigBlueImage = image; + }), + Resource.fetchImage('./Data/Images/Green4x4.png').then(function(image) { + bigGreenImage = image; + }) + ); + }); }); afterAll(function() { @@ -87,7 +101,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(greenImage.src, greenImage).then(function(index) { + return atlas.addImage(guidArray[0], greenImage).then(function(index) { expect(index).toEqual(0); expect(atlas.numberOfImages).toEqual(1); @@ -115,7 +129,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(greenImage.src, greenImage).then(function(index) { + return atlas.addImage(guidArray[0], greenImage).then(function(index) { var texture = atlas.texture; var coords = atlas.textureCoordinates[index]; @@ -128,7 +142,7 @@ defineSuite([ context : scene.context }); - return atlas.addImage(greenImage.src, greenImage).then(function(index) { + return atlas.addImage(guidArray[0], greenImage).then(function(index) { expect(index).toEqual(0); expect(atlas.numberOfImages).toEqual(1); @@ -155,7 +169,7 @@ defineSuite([ context : scene.context }); - return atlas.addImage(greenImage.src, greenImage).then(function(index) { + return atlas.addImage(guidArray[0], greenImage).then(function(index) { var texture = atlas.texture; var coords = atlas.textureCoordinates[index]; @@ -170,7 +184,7 @@ defineSuite([ initialSize : new Cartesian2(1.0, 5.0) }); - return atlas.addImage(tallGreenImage.src, tallGreenImage).then(function(index) { + return atlas.addImage(guidArray[0], tallGreenImage).then(function(index) { expect(index).toEqual(0); expect(atlas.numberOfImages).toEqual(1); @@ -197,7 +211,7 @@ defineSuite([ initialSize : new Cartesian2(1.0, 5.0) }); - return atlas.addImage(tallGreenImage.src, tallGreenImage).then(function(index) { + return atlas.addImage(guidArray[0], tallGreenImage).then(function(index) { var texture = atlas.texture; var coords = atlas.textureCoordinates[index]; @@ -213,8 +227,8 @@ defineSuite([ }); var promises = []; - promises.push(atlas.addImage(greenImage.src, greenImage)); - promises.push(atlas.addImage(blueImage.src, blueImage)); + promises.push(atlas.addImage(guidArray[0], greenImage)); + promises.push(atlas.addImage(guidArray[1], blueImage)); return when.all(promises, function(indices) { var greenIndex = indices[0]; @@ -250,8 +264,8 @@ defineSuite([ }); var promises = []; - promises.push(atlas.addImage(greenImage.src, greenImage)); - promises.push(atlas.addImage(blueImage.src, blueImage)); + promises.push(atlas.addImage(guidArray[0], greenImage)); + promises.push(atlas.addImage(guidArray[1], blueImage)); return when.all(promises, function(indices) { var greenIndex = indices[0]; @@ -274,10 +288,10 @@ defineSuite([ }); var promises = []; - promises.push(atlas.addImage(greenImage.src, greenImage)); - promises.push(atlas.addImage(blueImage.src, blueImage)); - promises.push(atlas.addImage(bigRedImage.src, bigRedImage)); - promises.push(atlas.addImage(bigBlueImage.src, bigBlueImage)); + promises.push(atlas.addImage(guidArray[0], greenImage)); + promises.push(atlas.addImage(guidArray[1], blueImage)); + promises.push(atlas.addImage(guidArray[2], bigRedImage)); + promises.push(atlas.addImage(guidArray[3], bigBlueImage)); return when.all(promises, function(indices) { var greenIndex = indices.shift(); @@ -307,10 +321,10 @@ defineSuite([ }); var promises = []; - promises.push(atlas.addImage(greenImage.src, greenImage)); - promises.push(atlas.addImage(blueImage.src, blueImage)); - promises.push(atlas.addImage(bigRedImage.src, bigRedImage)); - promises.push(atlas.addImage(bigBlueImage.src, bigBlueImage)); + promises.push(atlas.addImage(guidArray[0], greenImage)); + promises.push(atlas.addImage(guidArray[1], blueImage)); + promises.push(atlas.addImage(guidArray[2], bigRedImage)); + promises.push(atlas.addImage(guidArray[3], bigBlueImage)); return when.all(promises, function(indices) { var greenIndex = indices.shift(); @@ -361,10 +375,10 @@ defineSuite([ }); var promises = []; - promises.push(atlas.addImage(greenImage.src, greenImage)); - promises.push(atlas.addImage(blueImage.src, blueImage)); - promises.push(atlas.addImage(bigRedImage.src, bigRedImage)); - promises.push(atlas.addImage(bigBlueImage.src, bigBlueImage)); + promises.push(atlas.addImage(guidArray[0], greenImage)); + promises.push(atlas.addImage(guidArray[1], blueImage)); + promises.push(atlas.addImage(guidArray[2], bigRedImage)); + promises.push(atlas.addImage(guidArray[3], bigBlueImage)); return when.all(promises, function(indices) { var greenIndex = indices.shift(); @@ -394,7 +408,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(blueImage.src, blueImage).then(function(blueIndex) { + return atlas.addImage(guidArray[0], blueImage).then(function(blueIndex) { expect(atlas.numberOfImages).toEqual(1); var texture = atlas.texture; @@ -412,7 +426,7 @@ defineSuite([ expect(coordinates[blueIndex].height).toEqual(1.0 / atlasHeight); //Add the big green image - return atlas.addImage(bigGreenImage.src, bigGreenImage).then(function(greenIndex) { + return atlas.addImage(guidArray[1], bigGreenImage).then(function(greenIndex) { expect(atlas.numberOfImages).toEqual(2); var texture = atlas.texture; @@ -445,7 +459,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(blueImage.src, blueImage).then(function(blueIndex) { + return atlas.addImage(guidArray[0], blueImage).then(function(blueIndex) { expect(atlas.numberOfImages).toEqual(1); var texture = atlas.texture; @@ -454,7 +468,7 @@ defineSuite([ var blueCoords = coordinates[blueIndex]; expectToRender(texture, blueCoords, [0, 0, 255, 255]); - return atlas.addImage(bigGreenImage.src, bigGreenImage).then(function(greenIndex) { + return atlas.addImage(guidArray[1], bigGreenImage).then(function(greenIndex) { expect(atlas.numberOfImages).toEqual(2); var texture = atlas.texture; @@ -476,7 +490,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(bigRedImage.src, bigRedImage).then(function(index) { + return atlas.addImage(guidArray[0], bigRedImage).then(function(index) { expect(atlas.numberOfImages).toEqual(1); var texture = atlas.texture; @@ -501,7 +515,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(bigRedImage.src, bigRedImage).then(function(index) { + return atlas.addImage(guidArray[0], bigRedImage).then(function(index) { var texture = atlas.texture; var coords = atlas.textureCoordinates[index]; @@ -516,8 +530,8 @@ defineSuite([ initialSize : new Cartesian2(2, 2) }); - var greenPromise = atlas.addImage(greenImage.src, greenImage); - var bluePromise = atlas.addImage(blueImage.src, blueImage); + var greenPromise = atlas.addImage(guidArray[0], greenImage); + var bluePromise = atlas.addImage(guidArray[1], blueImage); return when.all([greenPromise, bluePromise], function(indices) { var greenIndex = indices.shift(); @@ -552,8 +566,8 @@ defineSuite([ initialSize : new Cartesian2(2, 2) }); - var greenPromise = atlas.addImage(greenImage.src, greenImage); - var bluePromise = atlas.addImage(blueImage.src, blueImage); + var greenPromise = atlas.addImage(guidArray[0], greenImage); + var bluePromise = atlas.addImage(guidArray[1], blueImage); return when.all([greenPromise, bluePromise], function(indices) { var greenIndex = indices.shift(); @@ -577,7 +591,7 @@ defineSuite([ initialSize : new Cartesian2(1.0, 1.0) }); - return atlas.addImage(tallGreenImage.src, tallGreenImage).then(function(index) { + return atlas.addImage(guidArray[0], tallGreenImage).then(function(index) { expect(atlas.numberOfImages).toEqual(1); var texture = atlas.texture; @@ -602,7 +616,7 @@ defineSuite([ initialSize : new Cartesian2(1.0, 1.0) }); - return atlas.addImage(tallGreenImage.src, tallGreenImage).then(function(index) { + return atlas.addImage(guidArray[0], tallGreenImage).then(function(index) { var texture = atlas.texture; var coords = atlas.textureCoordinates[index]; @@ -617,9 +631,9 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - var bluePromise = atlas.addImage(blueImage.src, blueImage); - var bigGreenPromise = atlas.addImage(bigGreenImage.src, bigGreenImage); - var bigRedPromise = atlas.addImage(bigRedImage.src, bigRedImage); + var bluePromise = atlas.addImage(guidArray[0], blueImage); + var bigGreenPromise = atlas.addImage(guidArray[1], bigGreenImage); + var bigRedPromise = atlas.addImage(guidArray[2], bigRedImage); return when.all([bluePromise, bigGreenPromise, bigRedPromise], function(indices) { var blueIndex = indices.shift(); @@ -644,13 +658,13 @@ defineSuite([ initialSize : new Cartesian2(4, 4) }); - return atlas.addImage(blueImage.src, blueImage).then(function(blueIndex) { + return atlas.addImage(guidArray[0], blueImage).then(function(blueIndex) { expect(blueIndex).toEqual(0); - return atlas.addImage(greenImage.src, greenImage).then(function(greenIndex) { + return atlas.addImage(guidArray[1], greenImage).then(function(greenIndex) { expect(greenIndex).toEqual(1); - return atlas.addImage(blueImage.src, blueImage).then(function(index) { + return atlas.addImage(guidArray[0], blueImage).then(function(index) { expect(index).toEqual(blueIndex); expect(atlas.numberOfImages).toEqual(2); @@ -675,12 +689,14 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - atlas.addImage(greenImage.src, greenImage); + var id = guidArray[0]; - var promise1 = atlas.addSubRegion(greenImage.src, new BoundingRectangle(0.0, 0.0, 0.5, 0.5)); - var promise2 = atlas.addSubRegion(greenImage.src, new BoundingRectangle(0.0, 0.5, 0.5, 0.5)); - var promise3 = atlas.addSubRegion(greenImage.src, new BoundingRectangle(0.5, 0.0, 0.5, 0.5)); - var promise4 = atlas.addSubRegion(greenImage.src, new BoundingRectangle(0.5, 0.5, 0.5, 0.5)); + atlas.addImage(id, greenImage); + + var promise1 = atlas.addSubRegion(id, new BoundingRectangle(0.0, 0.0, 0.5, 0.5)); + var promise2 = atlas.addSubRegion(id, new BoundingRectangle(0.0, 0.5, 0.5, 0.5)); + var promise3 = atlas.addSubRegion(id, new BoundingRectangle(0.5, 0.0, 0.5, 0.5)); + var promise4 = atlas.addSubRegion(id, new BoundingRectangle(0.5, 0.5, 0.5, 0.5)); return when.all([promise1, promise2, promise3, promise4], function(indices) { var index1 = indices.shift(); @@ -723,12 +739,14 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - atlas.addImage(greenImage.src, greenImage); + var id = guidArray[0]; + + atlas.addImage(id, greenImage); - var promise1 = atlas.addSubRegion(greenImage.src, new BoundingRectangle(0.0, 0.0, 0.5, 0.5)); - var promise2 = atlas.addSubRegion(greenImage.src, new BoundingRectangle(0.0, 0.5, 0.5, 0.5)); - var promise3 = atlas.addSubRegion(greenImage.src, new BoundingRectangle(0.5, 0.0, 0.5, 0.5)); - var promise4 = atlas.addSubRegion(greenImage.src, new BoundingRectangle(0.5, 0.5, 0.5, 0.5)); + var promise1 = atlas.addSubRegion(id, new BoundingRectangle(0.0, 0.0, 0.5, 0.5)); + var promise2 = atlas.addSubRegion(id, new BoundingRectangle(0.0, 0.5, 0.5, 0.5)); + var promise3 = atlas.addSubRegion(id, new BoundingRectangle(0.5, 0.0, 0.5, 0.5)); + var promise4 = atlas.addSubRegion(id, new BoundingRectangle(0.5, 0.5, 0.5, 0.5)); return when.all([promise1, promise2, promise3, promise4], function(indices) { var index1 = indices.shift(); @@ -738,7 +756,7 @@ defineSuite([ expect(atlas.numberOfImages).toEqual(5); - return atlas.addImage(blueImage.src, blueImage).then(function(blueIndex) { + return atlas.addImage(guidArray[1], blueImage).then(function(blueIndex) { expect(atlas.numberOfImages).toEqual(6); var coordinates = atlas.textureCoordinates; @@ -819,11 +837,11 @@ defineSuite([ var guid1 = atlas.guid; - return atlas.addImage(greenImage.src, greenImage).then(function(index) { + return atlas.addImage(guidArray[0], greenImage).then(function(index) { var guid2 = atlas.guid; expect(guid1).not.toEqual(guid2); - return atlas.addSubRegion(greenImage.src, new BoundingRectangle(0.0, 0.0, 0.5, 0.5)).then(function(index) { + return atlas.addSubRegion(guidArray[0], new BoundingRectangle(0.0, 0.0, 0.5, 0.5)).then(function(index) { var guid3 = atlas.guid; expect(guid2).not.toEqual(guid3); }); diff --git a/Specs/Scene/UrlTemplateImageryProviderSpec.js b/Specs/Scene/UrlTemplateImageryProviderSpec.js index 24070350b008..8158ccc3797a 100644 --- a/Specs/Scene/UrlTemplateImageryProviderSpec.js +++ b/Specs/Scene/UrlTemplateImageryProviderSpec.js @@ -2,6 +2,7 @@ defineSuite([ 'Scene/UrlTemplateImageryProvider', 'Core/DefaultProxy', 'Core/Ellipsoid', + 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/Math', 'Core/Rectangle', @@ -15,11 +16,13 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap', 'ThirdParty/when' ], function( UrlTemplateImageryProvider, DefaultProxy, Ellipsoid, + FeatureDetection, GeographicTilingScheme, CesiumMath, Rectangle, @@ -33,9 +36,14 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, + isImageOrImageBitmap, when) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + beforeEach(function() { RequestScheduler.clearForSpecs(); }); @@ -117,7 +125,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -164,7 +172,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -226,7 +234,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); @@ -252,7 +260,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -281,7 +289,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -310,7 +318,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -339,7 +347,7 @@ defineSuite([ return provider.requestImage(12, 10, 5).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -362,7 +370,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -385,7 +393,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -408,7 +416,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -431,7 +439,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -454,7 +462,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -476,7 +484,7 @@ defineSuite([ return provider.requestImage(3, 0, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -498,7 +506,7 @@ defineSuite([ return provider.requestImage(0, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -520,7 +528,7 @@ defineSuite([ return provider.requestImage(1, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -550,7 +558,7 @@ defineSuite([ return provider.requestImage(1, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -572,7 +580,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -595,7 +603,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -618,7 +626,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -646,7 +654,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); diff --git a/Specs/Scene/WebMapServiceImageryProviderSpec.js b/Specs/Scene/WebMapServiceImageryProviderSpec.js index 887388d89fa2..94d59764d672 100644 --- a/Specs/Scene/WebMapServiceImageryProviderSpec.js +++ b/Specs/Scene/WebMapServiceImageryProviderSpec.js @@ -5,6 +5,7 @@ defineSuite([ 'Core/ClockStep', 'Core/DefaultProxy', 'Core/Ellipsoid', + 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/JulianDate', 'Core/Math', @@ -23,6 +24,7 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap', 'ThirdParty/Uri' ], function( WebMapServiceImageryProvider, @@ -31,6 +33,7 @@ defineSuite([ ClockStep, DefaultProxy, Ellipsoid, + FeatureDetection, GeographicTilingScheme, JulianDate, CesiumMath, @@ -49,9 +52,14 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, + isImageOrImageBitmap, Uri) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + beforeEach(function() { RequestScheduler.clearForSpecs(); }); @@ -412,7 +420,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -452,7 +460,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -495,7 +503,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -535,7 +543,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -578,7 +586,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -621,7 +629,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -664,7 +672,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -822,7 +830,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/WebMapTileServiceImageryProviderSpec.js b/Specs/Scene/WebMapTileServiceImageryProviderSpec.js index 0eb664879f7b..d06d28f6322d 100644 --- a/Specs/Scene/WebMapTileServiceImageryProviderSpec.js +++ b/Specs/Scene/WebMapTileServiceImageryProviderSpec.js @@ -4,6 +4,7 @@ defineSuite([ 'Core/ClockStep', 'Core/Credit', 'Core/DefaultProxy', + 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/JulianDate', 'Core/objectToQuery', @@ -19,6 +20,7 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap', 'ThirdParty/Uri' ], function( WebMapTileServiceImageryProvider, @@ -26,6 +28,7 @@ defineSuite([ ClockStep, Credit, DefaultProxy, + FeatureDetection, GeographicTilingScheme, JulianDate, objectToQuery, @@ -41,9 +44,14 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, + isImageOrImageBitmap, Uri) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + beforeEach(function() { RequestScheduler.clearForSpecs(); }); @@ -364,7 +372,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -414,7 +422,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/createOpenStreetMapImageryProviderSpec.js b/Specs/Scene/createOpenStreetMapImageryProviderSpec.js index 86064b000f57..3d6c327a4f58 100644 --- a/Specs/Scene/createOpenStreetMapImageryProviderSpec.js +++ b/Specs/Scene/createOpenStreetMapImageryProviderSpec.js @@ -1,6 +1,7 @@ defineSuite([ 'Scene/createOpenStreetMapImageryProvider', 'Core/DefaultProxy', + 'Core/FeatureDetection', 'Core/Math', 'Core/Rectangle', 'Core/RequestScheduler', @@ -10,10 +11,12 @@ defineSuite([ 'Scene/ImageryLayer', 'Scene/ImageryState', 'Scene/UrlTemplateImageryProvider', - 'Specs/pollToPromise' + 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap' ], function( createOpenStreetMapImageryProvider, DefaultProxy, + FeatureDetection, CesiumMath, Rectangle, RequestScheduler, @@ -23,9 +26,14 @@ defineSuite([ ImageryLayer, ImageryState, UrlTemplateImageryProvider, - pollToPromise) { + pollToPromise, + isImageOrImageBitmap) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + beforeEach(function() { RequestScheduler.clearForSpecs(); }); @@ -72,7 +80,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -94,7 +102,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -116,7 +124,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -144,7 +152,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -193,7 +201,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -256,7 +264,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/createTileMapServiceImageryProviderSpec.js b/Specs/Scene/createTileMapServiceImageryProviderSpec.js index f68f4651d4d2..f32f7866adf0 100644 --- a/Specs/Scene/createTileMapServiceImageryProviderSpec.js +++ b/Specs/Scene/createTileMapServiceImageryProviderSpec.js @@ -3,6 +3,7 @@ defineSuite([ 'Core/Cartesian2', 'Core/Cartographic', 'Core/DefaultProxy', + 'Core/FeatureDetection', 'Core/GeographicProjection', 'Core/GeographicTilingScheme', 'Core/getAbsoluteUri', @@ -17,12 +18,14 @@ defineSuite([ 'Scene/ImageryState', 'Scene/UrlTemplateImageryProvider', 'Specs/pollToPromise', + 'Specs/isImageOrImageBitmap', 'ThirdParty/when' ], function( createTileMapServiceImageryProvider, Cartesian2, Cartographic, DefaultProxy, + FeatureDetection, GeographicProjection, GeographicTilingScheme, getAbsoluteUri, @@ -37,9 +40,14 @@ defineSuite([ ImageryState, UrlTemplateImageryProvider, pollToPromise, + isImageOrImageBitmap, when) { 'use strict'; + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + beforeEach(function() { RequestScheduler.clearForSpecs(); }); @@ -215,7 +223,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -237,7 +245,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -260,7 +268,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -287,7 +295,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -362,7 +370,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(image)).toBe(true); }); }); }); @@ -422,7 +430,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(imagery.image).toBeInstanceOf(Image); + expect(isImageOrImageBitmap(imagery.image)).toBe(true); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/isImageOrImageBitmap.js b/Specs/isImageOrImageBitmap.js new file mode 100644 index 000000000000..810cf452548c --- /dev/null +++ b/Specs/isImageOrImageBitmap.js @@ -0,0 +1,19 @@ +define([ + 'Core/FeatureDetection' + ], function( + FeatureDetection) { + 'use strict'; + + function isImageOrImageBitmap(image) { + // Many ImageryProvider specs will test if the requested image + // succeeded by checking its instance. Since this may be an Image + // or ImageBitmap, we abstract this check here. + if (FeatureDetection.supportsCreateImageBitmap()) { + return image instanceof ImageBitmap; + } + + return image instanceof Image; + } + + return isImageOrImageBitmap; +}); From e2108db3fbaf99bceb03011ecdb5bffb354f7816 Mon Sep 17 00:00:00 2001 From: Shehata Date: Mon, 18 Feb 2019 12:32:18 -0500 Subject: [PATCH 19/71] Remove unnecessary comment [ci skip] --- Source/Core/Resource.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index 6600f8ae9065..397d1ab39e27 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -1786,7 +1786,6 @@ define([ credentials: (crossOrigin && TrustedServers.contains(url)) ? 'include' : 'same-origin' }) .then(function(response) { - // Catch error here https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful return response.blob(); }) .then(function(blob) { From 7336d9684dff660a63c0a69a8e72dedcca8296c2 Mon Sep 17 00:00:00 2001 From: Shehata Date: Mon, 18 Feb 2019 12:38:21 -0500 Subject: [PATCH 20/71] Update CHANGES [ci skip] --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 4c81820e8f41..81b74c33a539 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Change Log ##### Additions :tada: * `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). +* Add support for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. `Resource` now has a `flipImage` option to vertically flip an image during fetch & decode when `ImageBitmapOptions` are supported. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) ##### Fixes :wrench: * Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383) From e31eae334a4f8ddafe520ff59c0d2bf2ba16a33f Mon Sep 17 00:00:00 2001 From: Shehata Date: Mon, 18 Feb 2019 13:03:23 -0500 Subject: [PATCH 21/71] Make ImageBitmapOptions spec more robust --- Specs/Core/FeatureDetectionSpec.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Specs/Core/FeatureDetectionSpec.js b/Specs/Core/FeatureDetectionSpec.js index b2f84ab7a69c..faf287f39748 100644 --- a/Specs/Core/FeatureDetectionSpec.js +++ b/Specs/Core/FeatureDetectionSpec.js @@ -135,10 +135,6 @@ defineSuite([ }); it('detects ImageBitmapOptions support', function() { - if (FeatureDetection.supportsCreateImageBitmap()) { - expect(FeatureDetection.supportsImageBitmapOptionsSync()).not.toBeDefined(); - } - return FeatureDetection.supportsImageBitmapOptions() .then(function(supportsImageBitmapOptions) { expect(typeof supportsImageBitmapOptions).toEqual('boolean'); From e4c54bb2ed5427bb53e30b3a6dfb8c140d4b0421 Mon Sep 17 00:00:00 2001 From: Kangning Li Date: Mon, 18 Feb 2019 13:40:40 -0500 Subject: [PATCH 22/71] fix vertex shader generation for draco-compressed RGB per-vertex color --- CHANGES.md | 1 + Source/Scene/ModelUtility.js | 9 +- .../BoxVertexColorsDracoRGB.gltf | 213 ++++++++++++++++++ .../BoxVertexColorsDracoRGBA.gltf | 213 ++++++++++++++++++ Specs/Scene/ModelSpec.js | 16 ++ 5 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 Specs/Data/Models/DracoCompression/BoxVertexColorsDracoRGB.gltf create mode 100644 Specs/Data/Models/DracoCompression/BoxVertexColorsDracoRGBA.gltf diff --git a/CHANGES.md b/CHANGES.md index 0bdb0ce31a75..fe350d49b892 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ Change Log * Fixed an issue where polygons on terrain using rhumb lines where being rendered incorrectly. [#7538](https://github.com/AnalyticalGraphicsInc/cesium/pulls/7538) * Fixed an issue with `EllipsoidRhumbLines.findIntersectionWithLongitude` when longitude was IDL. [#7551](https://github.com/AnalyticalGraphicsInc/cesium/issues/7551) * Fixed an issue with ground polylines on globes that use ellipsoids other than WGS84. [#7552](https://github.com/AnalyticalGraphicsInc/cesium/issues/7552) +* Fixed an issue where Draco compressed models with RGB per-vertex color would not load in Cesium. [#7576](https://github.com/AnalyticalGraphicsInc/cesium/issues/7576) ### 1.54 - 2019-02-01 diff --git a/Source/Scene/ModelUtility.js b/Source/Scene/ModelUtility.js index b29376b8f5b6..391ce8ee8efd 100644 --- a/Source/Scene/ModelUtility.js +++ b/Source/Scene/ModelUtility.js @@ -602,6 +602,12 @@ define([ } shader = variableType + ' ' + decodedAttributeVarName + ';\n' + shader; + // The gltf 2.0 COLOR_0 vertex attribute can be VEC4 or VEC3 + var vec3Color = size === 3 && attributeSemantic === 'COLOR_0'; + if (vec3Color) { + shader = replaceAllButFirstInString(shader, decodedAttributeVarName, 'vec4(' + decodedAttributeVarName + ', 1.0)'); + } + // splice decode function into the shader var decode = ''; if (quantization.octEncoded) { @@ -618,9 +624,10 @@ define([ var decodeUniformVarNameMin = decodeUniformVarName + '_min'; shader = 'uniform float ' + decodeUniformVarNameNormConstant + ';\n' + 'uniform ' + variableType + ' ' + decodeUniformVarNameMin + ';\n' + shader; + var attributeVarAccess = vec3Color ? '.xyz' : ''; decode = '\n' + 'void main() {\n' + - ' ' + decodedAttributeVarName + ' = ' + decodeUniformVarNameMin + ' + ' + attributeVarName + ' * ' + decodeUniformVarNameNormConstant + ';\n' + + ' ' + decodedAttributeVarName + ' = ' + decodeUniformVarNameMin + ' + ' + attributeVarName + attributeVarAccess + ' * ' + decodeUniformVarNameNormConstant + ';\n' + ' ' + newMain + '();\n' + '}\n'; } diff --git a/Specs/Data/Models/DracoCompression/BoxVertexColorsDracoRGB.gltf b/Specs/Data/Models/DracoCompression/BoxVertexColorsDracoRGB.gltf new file mode 100644 index 000000000000..d263897a4efc --- /dev/null +++ b/Specs/Data/Models/DracoCompression/BoxVertexColorsDracoRGB.gltf @@ -0,0 +1,213 @@ +{ + "accessors": [ + { + "componentType": 5123, + "count": 36, + "type": "SCALAR" + }, + { + "componentType": 5126, + "count": 24, + "type": "VEC3" + }, + { + "componentType": 5126, + "count": 24, + "type": "VEC3" + }, + { + "componentType": 5126, + "count": 24, + "max": [ + 0.5, + 0.5, + 0.5 + ], + "min": [ + -0.5, + -0.5, + -0.5 + ], + "type": "VEC3" + }, + { + "componentType": 5126, + "count": 24, + "type": "VEC2" + } + ], + "asset": { + "generator": "FBX2glTF", + "version": "2.0" + }, + "bufferViews": [ + { + "buffer": 0, + "byteOffset": 0, + "byteLength": 291 + } + ], + "buffers": [ + { + "name": "BoxVertexColorsDracoRGB", + "byteLength": 292, + "uri": "data:application/octet-stream;base64,RFJBQ08CAgEBAAAACAwDCwAAA2+rFAEBEP8CNUFVBEs7K0acBPS3XVcEAAAA/wAAAgEAAQEAAQIJAwAAAgEACQMAAgIBAwkCAAMCAQEJAwABAwEBAQAJDwEIBwEgARgEAHoAggE8LscrycxCBfwIQmx3gBQoA6BlYwAAAAD/AAAAHekGMAjDNTqgF+43Iv5/PwgBAQEAAgMBQAEAoAIIAAAAAP8/AAAAAAC/AAAAvwAAAL8AAIA/DgUBAQANA5UEG20b3RYDJQkFr5XCIE4AsKoACAAApJoqAFOtAqDqVKurAlDVKgCsApDq1KkApgIMAAAAAQLAQAAAAAD/DwAAAAAAAAAAAAAAAIA/DAYDAQEBAQFAAQD/AwAA/wEAAP8CoUEKAA==" + } + ], + "materials": [ + { + "name": "Default", + "pbrMetallicRoughness": { + "baseColorFactor": [ + 0.800000011920929, + 0.800000011920929, + 0.800000011920929, + 1 + ], + "metallicFactor": 0.100000001490116, + "roughnessFactor": 0.990000005960464 + }, + "emissiveFactor": [ + 0, + 0, + 0 + ], + "alphaMode": "OPAQUE", + "doubleSided": false + } + ], + "meshes": [ + { + "name": "Cube", + "primitives": [ + { + "attributes": { + "COLOR_0": 1, + "NORMAL": 2, + "POSITION": 3, + "TEXCOORD_0": 4 + }, + "indices": 0, + "material": 0, + "mode": 4, + "extensions": { + "KHR_draco_mesh_compression": { + "bufferView": 0, + "attributes": { + "COLOR_0": 0, + "NORMAL": 1, + "POSITION": 2, + "TEXCOORD_0": 3 + } + } + } + } + ] + } + ], + "nodes": [ + { + "children": [ + 1, + 2, + 3 + ], + "name": "RootNode", + "rotation": [ + 0, + 0, + 0, + 1 + ], + "scale": [ + 1, + 1, + 1 + ], + "translation": [ + 0, + 0, + 0 + ] + }, + { + "name": "Mesh", + "rotation": [ + 0, + 0, + 0, + 1 + ], + "scale": [ + 1, + 1, + 1 + ], + "translation": [ + 0, + 0, + 0 + ] + }, + { + "mesh": 0, + "name": "Cube", + "rotation": [ + 0, + 0, + 0, + 1 + ], + "scale": [ + 1, + 1, + 1 + ], + "translation": [ + 0, + 0, + 0 + ] + }, + { + "name": "Texture Group", + "rotation": [ + 0, + 0, + 0, + 1 + ], + "scale": [ + 1, + 1, + 1 + ], + "translation": [ + 0, + 0, + 0 + ] + } + ], + "samplers": [ + { + "wrapS": 10497, + "wrapT": 10497 + } + ], + "scene": 0, + "scenes": [ + { + "name": "Root Scene", + "nodes": [ + 0 + ] + } + ], + "extensionsRequired": [ + "KHR_draco_mesh_compression" + ], + "extensionsUsed": [ + "KHR_draco_mesh_compression" + ] +} diff --git a/Specs/Data/Models/DracoCompression/BoxVertexColorsDracoRGBA.gltf b/Specs/Data/Models/DracoCompression/BoxVertexColorsDracoRGBA.gltf new file mode 100644 index 000000000000..927cb1d07373 --- /dev/null +++ b/Specs/Data/Models/DracoCompression/BoxVertexColorsDracoRGBA.gltf @@ -0,0 +1,213 @@ +{ + "accessors": [ + { + "componentType": 5123, + "count": 36, + "type": "SCALAR" + }, + { + "componentType": 5126, + "count": 24, + "type": "VEC4" + }, + { + "componentType": 5126, + "count": 24, + "type": "VEC3" + }, + { + "componentType": 5126, + "count": 24, + "max": [ + 0.5, + 0.5, + 0.5 + ], + "min": [ + -0.5, + -0.5, + -0.5 + ], + "type": "VEC3" + }, + { + "componentType": 5126, + "count": 24, + "type": "VEC2" + } + ], + "asset": { + "generator": "FBX2glTF", + "version": "2.0" + }, + "bufferViews": [ + { + "buffer": 0, + "byteOffset": 0, + "byteLength": 302 + } + ], + "buffers": [ + { + "name": "BoxVertexColorsDracoRGBA", + "byteLength": 304, + "uri": "data:application/octet-stream;base64,RFJBQ08CAgEBAAAACAwDCwAAA2+rFAEBEP8CNUFVBEs7K0acBPS3XVcEAAAA/wAAAgEAAQEAAQIJBAAAAgEACQMAAgIBAwkCAAMCAQEJAwABAwEBAQAJDwEIBwEgARgEAHoAggEM43I8UElmJhAq4CdAEGIJ3QGSIVAGEqBlYwEAAAAA/wAAAB3pBjAIwzU6oBfuN1HSJzAAAIA/CAEBAQACAwFAAQCgAggAAAAA/z8AAAAAAL8AAAC/AAAAvwAAgD8OBQEBAA0DlQQbbRvdFgMlCQWvlcIgTgCwqgAIAACkmioAU60CoOpUq6sCUNUqAKwCkOrUqQCmAgwAAAABAsBAAAAAAP8PAAAAAAAAAAAAAAAAgD8MBgMBAQEBAUABAP8DAAD/AQAA/wKhQQoAAA==" + } + ], + "materials": [ + { + "name": "Default", + "pbrMetallicRoughness": { + "baseColorFactor": [ + 0.800000011920929, + 0.800000011920929, + 0.800000011920929, + 1 + ], + "metallicFactor": 0.100000001490116, + "roughnessFactor": 0.990000005960464 + }, + "emissiveFactor": [ + 0, + 0, + 0 + ], + "alphaMode": "OPAQUE", + "doubleSided": false + } + ], + "meshes": [ + { + "name": "Cube", + "primitives": [ + { + "attributes": { + "COLOR_0": 1, + "NORMAL": 2, + "POSITION": 3, + "TEXCOORD_0": 4 + }, + "indices": 0, + "material": 0, + "mode": 4, + "extensions": { + "KHR_draco_mesh_compression": { + "bufferView": 0, + "attributes": { + "COLOR_0": 0, + "NORMAL": 1, + "POSITION": 2, + "TEXCOORD_0": 3 + } + } + } + } + ] + } + ], + "nodes": [ + { + "children": [ + 1, + 2, + 3 + ], + "name": "RootNode", + "rotation": [ + 0, + 0, + 0, + 1 + ], + "scale": [ + 1, + 1, + 1 + ], + "translation": [ + 0, + 0, + 0 + ] + }, + { + "name": "Mesh", + "rotation": [ + 0, + 0, + 0, + 1 + ], + "scale": [ + 1, + 1, + 1 + ], + "translation": [ + 0, + 0, + 0 + ] + }, + { + "mesh": 0, + "name": "Cube", + "rotation": [ + 0, + 0, + 0, + 1 + ], + "scale": [ + 1, + 1, + 1 + ], + "translation": [ + 0, + 0, + 0 + ] + }, + { + "name": "Texture Group", + "rotation": [ + 0, + 0, + 0, + 1 + ], + "scale": [ + 1, + 1, + 1 + ], + "translation": [ + 0, + 0, + 0 + ] + } + ], + "samplers": [ + { + "wrapS": 10497, + "wrapT": 10497 + } + ], + "scene": 0, + "scenes": [ + { + "name": "Root Scene", + "nodes": [ + 0 + ] + } + ], + "extensionsRequired": [ + "KHR_draco_mesh_compression" + ], + "extensionsUsed": [ + "KHR_draco_mesh_compression" + ] +} diff --git a/Specs/Scene/ModelSpec.js b/Specs/Scene/ModelSpec.js index 6dfc7b1550f8..d38040b5447c 100644 --- a/Specs/Scene/ModelSpec.js +++ b/Specs/Scene/ModelSpec.js @@ -137,6 +137,8 @@ defineSuite([ var dracoCompressedModelUrl = './Data/Models/DracoCompression/CesiumMilkTruck/CesiumMilkTruck.gltf'; var dracoCompressedModelWithAnimationUrl = './Data/Models/DracoCompression/CesiumMan/CesiumMan.gltf'; var dracoCompressedModelWithLinesUrl = './Data/Models/DracoCompression/BoxWithLines/BoxWithLines.gltf'; + var dracoBoxVertexColorsRGBUrl = './Data/Models/DracoCompression/BoxVertexColorsDracoRGB.gltf'; + var dracoBoxVertexColorsRGBAUrl = './Data/Models/DracoCompression/BoxVertexColorsDracoRGBA.gltf'; var boxGltf2Url = './Data/Models/Box-Gltf-2/Box.gltf'; var boxGltf2WithTechniquesUrl = './Data/Models/Box-Gltf-2-Techniques/Box.gltf'; @@ -2684,6 +2686,20 @@ defineSuite([ }); }); + it('loads draco compressed glTF with RGBA per-vertex color', function() { + return loadModel(dracoBoxVertexColorsRGBAUrl).then(function(m) { + verifyRender(m); + primitives.remove(m); + }); + }); + + it('loads draco compressed glTF with RGB per-vertex color', function() { + return loadModel(dracoBoxVertexColorsRGBUrl).then(function(m) { + verifyRender(m); + primitives.remove(m); + }); + }); + it('does not issue draw commands when ignoreCommands is true', function() { return loadModel(texturedBoxUrl, { ignoreCommands : true From 62a70de8d5257447dd224c50344ec72d2a0a6e4e Mon Sep 17 00:00:00 2001 From: Hannah Date: Tue, 19 Feb 2019 09:46:33 -0500 Subject: [PATCH 23/71] Update CHANGES.md --- CHANGES.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 11097f58d906..e1465f5fdadc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -51,7 +51,6 @@ Change Log * Added support for glTF models with WebP textures using the `EXT_texture_webp` extension. [#7486](https://github.com/AnalyticalGraphicsInc/cesium/pull/7486) ##### Fixes :wrench: -* Fixed an issue where RTL labels not reversing correctly non alphabetic characters [#7501](https://github.com/AnalyticalGraphicsInc/cesium/pull/7501) * Fixed 3D Tiles performance regression. [#7482](https://github.com/AnalyticalGraphicsInc/cesium/pull/7482) * Fixed an issue where classification primitives with the `CESIUM_3D_TILE` classification type would render on terrain. [#7422](https://github.com/AnalyticalGraphicsInc/cesium/pull/7422) * Fixed an issue where 3D Tiles would show through the globe. [#7422](https://github.com/AnalyticalGraphicsInc/cesium/pull/7422) From 3fe7b79d575424021dfcf2492d0014d23de2b6e2 Mon Sep 17 00:00:00 2001 From: Shehata Date: Tue, 19 Feb 2019 09:53:36 -0500 Subject: [PATCH 24/71] Use fetchBlob & remove flipImage in Resource --- CHANGES.md | 2 +- Source/Core/FeatureDetection.js | 11 +-- Source/Core/Resource.js | 79 ++++++++----------- Source/Scene/Model.js | 7 +- Specs/Core/FeatureDetectionSpec.js | 5 -- Specs/Core/ResourceSpec.js | 31 +------- Specs/Core/VRTheWorldTerrainProviderSpec.js | 15 +++- Specs/Renderer/TextureSpec.js | 4 +- .../ArcGisMapServerImageryProviderSpec.js | 12 +-- Specs/Scene/BingMapsImageryProviderSpec.js | 4 +- .../DiscardMissingTileImagePolicySpec.js | 10 ++- .../GoogleEarthEnterpriseMapsProviderSpec.js | 8 +- 12 files changed, 77 insertions(+), 111 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 81b74c33a539..e5c3a928ab79 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ Change Log ##### Additions :tada: * `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). -* Add support for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. `Resource` now has a `flipImage` option to vertically flip an image during fetch & decode when `ImageBitmapOptions` are supported. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) +* Add support for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode when `ImageBitmapOptions` are supported since an `ImageBitmap` cannot be vertically flipped during texture upload. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) ##### Fixes :wrench: * Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383) diff --git a/Source/Core/FeatureDetection.js b/Source/Core/FeatureDetection.js index 941f7b8a9958..6f3647a7b76b 100644 --- a/Source/Core/FeatureDetection.js +++ b/Source/Core/FeatureDetection.js @@ -281,6 +281,8 @@ define([ } var imageDataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWP4////fwAJ+wP9CNHoHgAAAABJRU5ErkJggg=='; + // Use the fetch API here to avoid a circular dependency from including Resource here. + // `fetch` is supported everywhere createImageBitmap is. fetch(imageDataUri) .then(function(response) { return response.blob(); @@ -310,14 +312,6 @@ define([ return supportsImageBitmapOptionsResult; } - var supportsFetchApiResult; - function supportsFetchApi() { - if (!defined(supportsFetchApiResult)) { - supportsFetchApiResult = defined(window.fetch); - } - return supportsFetchApiResult; - } - /** * A set of functions to detect whether the current browser supports * various features. @@ -346,7 +340,6 @@ define([ supportsCreateImageBitmap: supportsCreateImageBitmap, supportsImageBitmapOptions: supportsImageBitmapOptions, supportsImageBitmapOptionsSync: supportsImageBitmapOptionsSync, - supportsFetchApi : supportsFetchApi, imageRenderingValue: imageRenderingValue, typedArrayTypes: typedArrayTypes }; diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index 397d1ab39e27..8416e32464fe 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -252,7 +252,6 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. - * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried. * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -339,14 +338,6 @@ define([ this.retryAttempts = defaultValue(options.retryAttempts, 0); this._retryCount = 0; - /** - * Whether to vertically flip the image during fetch and decode. Only applies when requesting - * an image and the browser supports createImageBitmap. - * - * @type {Boolean} - */ - this.flipImage = defaultValue(options.flipImage, true); - var uri = new Uri(options.url); parseQuery(uri, this, true, true); @@ -631,7 +622,6 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). These will be combined with those of the current instance. * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. - * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The function to call when loading the resource fails. * @param {Number} [options.retryAttempts] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -676,9 +666,6 @@ define([ if (defined(options.retryAttempts)) { resource.retryAttempts = options.retryAttempts; } - if (defined(options.flipImage)) { - resource.flipImage = options.flipImage; - } return resource; }; @@ -729,7 +716,6 @@ define([ result.retryCallback = this.retryCallback; result.retryAttempts = this.retryAttempts; result._retryCount = 0; - result.flipImage = this.flipImage; result.request = this.request.clone(); return result; @@ -787,7 +773,6 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. - * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried. * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -832,7 +817,6 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. - * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried. * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -845,10 +829,13 @@ define([ /** * Asynchronously loads the given image resource. Returns a promise that will resolve to - * an {@link Image} once loaded, or reject if the image failed to load. + * an {@link https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap|ImageBitmap} if the browser supports `createImageBitmap` or otherwise an + * {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement|Image} once loaded, or reject if the image failed to load. * - * @param {Boolean} [preferBlob = false] If true, we will load the image via a blob. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. + * @param {String|Object} options An object with the following properties. + * @param {Boolean} [options.preferBlob=false] If true, we will load the image via a blob. + * @param {Boolean} [options.flipY=true] If true, image will be vertially flipped during decode. Only applies if the browser supports `createImageBitmap`. + * @returns {Promise.|Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. * * * @example @@ -867,9 +854,10 @@ define([ * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} */ - Resource.prototype.fetchImage = function (preferBlob) { - preferBlob = defaultValue(preferBlob, false); - var flipImage = this.flipImage; + Resource.prototype.fetchImage = function (options) { + options = defaultValue(options, {}); + var preferBlob = defaultValue(options.preferBlob, false); + var flipY = defaultValue(options.flipY, true); checkAndResetRequest(this.request); @@ -879,7 +867,7 @@ define([ // 3. It's a blob URI // 4. It doesn't have request headers and we preferBlob is false if (!xhrBlobSupported || this.isDataUri || this.isBlobUri || (!this.hasHeaders && !preferBlob)) { - return fetchImage(this); + return fetchImage(this, flipY); } var blobPromise = this.fetchBlob(); @@ -897,11 +885,10 @@ define([ generatedBlob = blob; var blobUrl = window.URL.createObjectURL(blob); generatedBlobResource = new Resource({ - url: blobUrl, - flipImage: flipImage + url: blobUrl }); - return fetchImage(generatedBlobResource); + return fetchImage(generatedBlobResource, flipY); }) .then(function(image) { if (!defined(image)) { @@ -923,12 +910,11 @@ define([ }); }; - function fetchImage(resource) { + function fetchImage(resource, flipY) { var request = resource.request; request.url = resource.url; request.requestFunction = function() { var url = resource.url; - var flipImage = resource.flipImage; var crossOrigin = false; // data URIs can't have crossorigin set. @@ -938,7 +924,7 @@ define([ var deferred = when.defer(); - Resource._Implementations.createImage(url, crossOrigin, deferred, flipImage); + Resource._Implementations.createImage(url, crossOrigin, deferred, flipY); return deferred.promise; }; @@ -962,7 +948,7 @@ define([ request.state = RequestState.UNISSUED; request.deferred = undefined; - return fetchImage(resource); + return fetchImage(resource, flipY); } return when.reject(e); @@ -979,7 +965,7 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. - * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. + * @param {Boolean} [options.flipY = true] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried. * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -988,7 +974,10 @@ define([ */ Resource.fetchImage = function (options) { var resource = new Resource(options); - return resource.fetchImage(options.preferBlob); + return resource.fetchImage({ + flipY: options.flipY, + preferBlob: options.preferBlob + }); }; /** @@ -1400,7 +1389,6 @@ define([ * @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}). * @param {Object} [options.headers={}] Additional HTTP headers that will be sent. * @param {DefaultProxy} [options.proxy] A proxy to be used when loading the resource. - * @param {Boolean} [options.flipImage] Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports createImageBitmap. * @param {Resource~RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried. * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. @@ -1778,29 +1766,24 @@ define([ */ Resource._Implementations = {}; - Resource._Implementations.createImage = function(url, crossOrigin, deferred, flipImage) { + Resource._Implementations.createImage = function(url, crossOrigin, deferred, flipY) { var supportsBitmapOptions = FeatureDetection.supportsImageBitmapOptionsSync(); - if (FeatureDetection.supportsFetchApi() && FeatureDetection.supportsCreateImageBitmap() && defined(supportsBitmapOptions)) { - fetch(url, { - credentials: (crossOrigin && TrustedServers.contains(url)) ? 'include' : 'same-origin' + if (FeatureDetection.supportsCreateImageBitmap() && defined(supportsBitmapOptions)) { + Resource.fetchBlob({ + url: url }) - .then(function(response) { - return response.blob(); - }) .then(function(blob) { if (!supportsBitmapOptions) { - return createImageBitmap(blob); + return when(createImageBitmap(blob)); } - return createImageBitmap(blob, { - imageOrientation: flipImage ? 'flipY' : 'none' - }); - }) - .then(function (imageBitmap) { - deferred.resolve(imageBitmap); + return when(createImageBitmap(blob, { + imageOrientation: flipY ? 'flipY' : 'none' + })); }) - .catch(deferred.reject); + .then(deferred.resolve) + .otherwise(deferred.reject); } else { var image = new Image(); diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index e7d81bdac386..aa1bbffb94c1 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -1714,8 +1714,7 @@ define([ ++model._loadResources.pendingTextureLoads; var imageResource = model._resource.getDerivedResource({ - url : uri, - flipImage : false + url : uri }); var promise; @@ -1724,7 +1723,9 @@ define([ } else if (crnRegex.test(uri)) { promise = loadCRN(imageResource); } else { - promise = imageResource.fetchImage(); + promise = imageResource.fetchImage({ + flipY: false + }); } promise.then(imageLoad(model, id, imageId)).otherwise(ModelUtility.getFailedLoadFunction(model, 'image', imageResource.url)); } diff --git a/Specs/Core/FeatureDetectionSpec.js b/Specs/Core/FeatureDetectionSpec.js index faf287f39748..a1dd850c005b 100644 --- a/Specs/Core/FeatureDetectionSpec.js +++ b/Specs/Core/FeatureDetectionSpec.js @@ -124,11 +124,6 @@ defineSuite([ }); }); - it('detects fetch API support', function() { - var supportsFetchApi = FeatureDetection.supportsFetchApi(); - expect(typeof supportsFetchApi).toEqual('boolean'); - }); - it('detects createImageBitmap support', function() { var supportsCreateImageBitmap = FeatureDetection.supportsCreateImageBitmap(); expect(typeof supportsCreateImageBitmap).toEqual('boolean'); diff --git a/Specs/Core/ResourceSpec.js b/Specs/Core/ResourceSpec.js index 1357aabbdfb1..3a27fd7380ce 100644 --- a/Specs/Core/ResourceSpec.js +++ b/Specs/Core/ResourceSpec.js @@ -1191,7 +1191,7 @@ defineSuite([ it('correctly flips image when ImageBitmapOptions are supported', function() { return Resource.fetchImage({ url: './Data/Images/BlueOverRed.png', - flipImage: true + flipY: true }).then(function(loadedImage) { if (FeatureDetection.supportsImageBitmapOptionsSync()) { expect(getColorAtPixel(loadedImage, 0, 0)).toEqual([255, 0, 0, 255]); @@ -1204,7 +1204,7 @@ defineSuite([ it('correctly loads image without flip when ImageBitmapOptions are supported', function() { return Resource.fetchImage({ url: './Data/Images/BlueOverRed.png', - flipImage: false + flipY: false }).then(function(loadedImage) { if (FeatureDetection.supportsImageBitmapOptionsSync()) { expect(getColorAtPixel(loadedImage, 0, 0)).toEqual([0, 0, 255, 255]); @@ -1229,32 +1229,7 @@ defineSuite([ fail('expected promise to reject'); }) .otherwise(function(error) { - expect(error).toBeInstanceOf(TypeError); - }); - }); - - it('does not set credentials for untrusted cross-origin images using fetch API', function() { - var fetchSpy = spyOn(window, 'fetch').and.callThrough(); - var url = './Data/Images/Green.png'; - - return Resource.fetchImage(url) - .then(function() { - expect(fetchSpy).toHaveBeenCalledWith(url, { - credentials: 'same-origin' - }); - }); - }); - - it('sets credentials for trusted cross-origin images using fetch API', function() { - var fetchSpy = spyOn(window, 'fetch').and.callThrough(); - spyOn(TrustedServers, 'contains').and.returnValue(true); - var url = 'http://example.invalid/testuri.png'; - - return Resource.fetchImage(url) - .otherwise(function() { - expect(fetchSpy).toHaveBeenCalledWith(url, { - credentials: 'include' - }); + expect(error).toBeInstanceOf(RequestErrorEvent); }); }); }); diff --git a/Specs/Core/VRTheWorldTerrainProviderSpec.js b/Specs/Core/VRTheWorldTerrainProviderSpec.js index 00b0f4f6b953..d1e6d47b6efb 100644 --- a/Specs/Core/VRTheWorldTerrainProviderSpec.js +++ b/Specs/Core/VRTheWorldTerrainProviderSpec.js @@ -1,6 +1,7 @@ defineSuite([ 'Core/VRTheWorldTerrainProvider', 'Core/DefaultProxy', + 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/HeightmapTerrainData', 'Core/Math', @@ -13,6 +14,7 @@ defineSuite([ ], function( VRTheWorldTerrainProvider, DefaultProxy, + FeatureDetection, GeographicTilingScheme, HeightmapTerrainData, CesiumMath, @@ -24,9 +26,16 @@ defineSuite([ when) { 'use strict'; + var imageUrl = 'Data/Images/Red16x16.png'; + beforeEach(function() { RequestScheduler.clearForSpecs(); Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) { + if (url === imageUrl) { + Resource._DefaultImplementations.loadWithXhr(url, responseType, method, data, headers, deferred, overrideMimeType); + return; + } + setTimeout(function() { var parser = new DOMParser(); var xmlString = @@ -60,6 +69,10 @@ defineSuite([ Resource._Implementations.loadWithXhr = Resource._DefaultImplementations.loadWithXhr; }); + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + function createRequest() { return new Request({ throttleByServer : true @@ -239,7 +252,7 @@ defineSuite([ expect(url.indexOf('.tif?cesium=true')).toBeGreaterThanOrEqualTo(0); // Just return any old image. - Resource._DefaultImplementations.createImage('Data/Images/Red16x16.png', crossOrigin, deferred); + Resource._DefaultImplementations.createImage(imageUrl, crossOrigin, deferred); }; var terrainProvider = new VRTheWorldTerrainProvider({ diff --git a/Specs/Renderer/TextureSpec.js b/Specs/Renderer/TextureSpec.js index cb8b269c34c8..99b3dc68e268 100644 --- a/Specs/Renderer/TextureSpec.js +++ b/Specs/Renderer/TextureSpec.js @@ -76,7 +76,7 @@ defineSuite([ // Turn off the default flipping. promises.push(Resource.fetchImage({ url: './Data/Images/BlueOverRed.png', - flipImage: false + flipY: false }).then(function(image) { blueOverRedUnflippedImage = image; })); @@ -199,7 +199,7 @@ defineSuite([ }).contextToRender([0, 0, 255, 255]); }); - it('can set flip texture only if ImageBitmapOptions is not supported', function() { + it('can flip texture only if ImageBitmapOptions is not supported', function() { var topColor = new Color(0.0, 0.0, 1.0, 1.0); var bottomColor = new Color(1.0, 0.0, 0.0, 1.0); if (FeatureDetection.supportsImageBitmapOptionsSync()) { diff --git a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js index 1d0742fe497c..095df47274da 100644 --- a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js +++ b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js @@ -214,8 +214,8 @@ defineSuite([ expect(provider.hasAlphaChannel).toBeDefined(); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url)) { - // load blob url normally + if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { expect(url).toEqual(getAbsoluteUri(baseUrl + 'tile/0/0/0')); @@ -291,8 +291,8 @@ defineSuite([ expect(provider.usingPrecachedTiles).toEqual(true); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url)) { - // load blob url normally + if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { expect(url).toEqual(getAbsoluteUri(baseUrl + 'tile/0/0/0')); @@ -464,8 +464,8 @@ defineSuite([ expect(provider.hasAlphaChannel).toBeDefined(); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url)) { - // load blob url normally + if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { expect(url).toEqual(expectedTileUrl); diff --git a/Specs/Scene/BingMapsImageryProviderSpec.js b/Specs/Scene/BingMapsImageryProviderSpec.js index 31fa49304401..f652ea83c201 100644 --- a/Specs/Scene/BingMapsImageryProviderSpec.js +++ b/Specs/Scene/BingMapsImageryProviderSpec.js @@ -181,8 +181,8 @@ defineSuite([ function installFakeImageRequest(expectedUrl, expectedParams, proxy) { Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url)) { - // load blob url normally + if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { if (defined(expectedUrl)) { diff --git a/Specs/Scene/DiscardMissingTileImagePolicySpec.js b/Specs/Scene/DiscardMissingTileImagePolicySpec.js index 2c5215941a31..f18218944fbf 100644 --- a/Specs/Scene/DiscardMissingTileImagePolicySpec.js +++ b/Specs/Scene/DiscardMissingTileImagePolicySpec.js @@ -1,12 +1,14 @@ defineSuite([ 'Scene/DiscardMissingTileImagePolicy', 'Core/Cartesian2', + 'Core/FeatureDetection', 'Core/Resource', 'Specs/pollToPromise', 'ThirdParty/when' ], function( DiscardMissingTileImagePolicy, Cartesian2, + FeatureDetection, Resource, pollToPromise, when) { @@ -17,6 +19,10 @@ defineSuite([ Resource._Implementations.loadWithXhr = Resource._DefaultImplementations.loadWithXhr; }); + beforeAll(function() { + return FeatureDetection.supportsImageBitmapOptions(); + }); + describe('construction', function() { it('throws if missingImageUrl is not provided', function() { function constructWithoutMissingImageUrl() { @@ -40,8 +46,8 @@ defineSuite([ var missingImageUrl = 'http://some.host.invalid/missingImage.png'; spyOn(Resource._Implementations, 'createImage').and.callFake(function(url, crossOrigin, deferred) { - if (/^blob:/.test(url)) { - // load blob url normally + if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { expect(url).toEqual(missingImageUrl); diff --git a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js index 40496cff3975..1ac41204a074 100644 --- a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js @@ -180,8 +180,8 @@ defineSuite([ expect(provider.credit).toBeInstanceOf(Object); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url)) { - // load blob url normally + if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { expect(url).toEqual('http://example.invalid/query?request=ImageryMaps&channel=1234&version=1&x=0&y=0&z=1'); @@ -298,8 +298,8 @@ defineSuite([ }); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url)) { - // load blob url normally + if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else if (tries === 2) { // Succeed after 2 tries From 5cdd9e1fbabf98e6b010eb008757308831120d06 Mon Sep 17 00:00:00 2001 From: Shehata Date: Tue, 19 Feb 2019 10:54:23 -0500 Subject: [PATCH 25/71] Fix imagery specs on Firefox --- Specs/Scene/ArcGisMapServerImageryProviderSpec.js | 6 +++--- Specs/Scene/BingMapsImageryProviderSpec.js | 2 +- Specs/Scene/DiscardMissingTileImagePolicySpec.js | 2 +- Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js index 095df47274da..7ba901a13cd8 100644 --- a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js +++ b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js @@ -214,7 +214,7 @@ defineSuite([ expect(provider.hasAlphaChannel).toBeDefined(); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { @@ -291,7 +291,7 @@ defineSuite([ expect(provider.usingPrecachedTiles).toEqual(true); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { @@ -464,7 +464,7 @@ defineSuite([ expect(provider.hasAlphaChannel).toBeDefined(); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { diff --git a/Specs/Scene/BingMapsImageryProviderSpec.js b/Specs/Scene/BingMapsImageryProviderSpec.js index f652ea83c201..faf273881718 100644 --- a/Specs/Scene/BingMapsImageryProviderSpec.js +++ b/Specs/Scene/BingMapsImageryProviderSpec.js @@ -181,7 +181,7 @@ defineSuite([ function installFakeImageRequest(expectedUrl, expectedParams, proxy) { Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { diff --git a/Specs/Scene/DiscardMissingTileImagePolicySpec.js b/Specs/Scene/DiscardMissingTileImagePolicySpec.js index f18218944fbf..85b207a0eeaf 100644 --- a/Specs/Scene/DiscardMissingTileImagePolicySpec.js +++ b/Specs/Scene/DiscardMissingTileImagePolicySpec.js @@ -46,7 +46,7 @@ defineSuite([ var missingImageUrl = 'http://some.host.invalid/missingImage.png'; spyOn(Resource._Implementations, 'createImage').and.callFake(function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { diff --git a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js index 1ac41204a074..3c5c7325ea24 100644 --- a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js @@ -180,7 +180,7 @@ defineSuite([ expect(provider.credit).toBeInstanceOf(Object); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { @@ -298,7 +298,7 @@ defineSuite([ }); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsImageBitmapOptionsSync()) { + if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else if (tries === 2) { From 9b58ea4577731a56ffdba31dd41f5b8a4c61533e Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Tue, 19 Feb 2019 14:09:50 -0500 Subject: [PATCH 26/71] Change usage of followSurface to arcType. Add CZML property for it --- Apps/SampleData/simple.czml | 6 +++--- Apps/Sandcastle/gallery/CZML Polyline.html | 2 +- Apps/Sandcastle/gallery/Clamp to Terrain.html | 2 +- Apps/Sandcastle/gallery/Custom DataSource.html | 2 +- .../gallery/Sample Height from 3D Tiles.html | 2 +- Apps/Sandcastle/gallery/Star Burst.html | 2 +- .../gallery/development/Pick From Ray.html | 2 +- Apps/Sandcastle/gallery/development/Polyline.html | 4 ++-- .../gallery/development/Simple Polyline.html | 4 ++-- Source/Core/PolylineGeometry.js | 2 +- Source/Core/SimplePolylineGeometry.js | 2 +- Source/DataSources/CzmlDataSource.js | 7 +++++++ Source/DataSources/KmlDataSource.js | 4 +++- Specs/Core/SimplePolylineGeometrySpec.js | 10 +++++----- Specs/Data/CZML/ValidationDocument.czml | 5 ++++- Specs/DataSources/CzmlDataSourceSpec.js | 6 ++++-- Specs/DataSources/KmlDataSourceSpec.js | 12 +++++++----- Specs/Scene/GeometryRenderingSpec.js | 6 ++++-- Specs/Scene/PolylineColorAppearanceSpec.js | 3 ++- Specs/Scene/PolylineMaterialAppearanceSpec.js | 4 +++- 20 files changed, 54 insertions(+), 33 deletions(-) diff --git a/Apps/SampleData/simple.czml b/Apps/SampleData/simple.czml index 39098a311c5f..073be16a5790 100644 --- a/Apps/SampleData/simple.czml +++ b/Apps/SampleData/simple.czml @@ -122,7 +122,7 @@ } } }, - "followSurface":false, + "arcType":"NONE", "positions":{ "references":[ "Satellite/Geoeye1#position","Satellite/ISS#position" @@ -207,7 +207,7 @@ } } }, - "followSurface":false, + "arcType":"NONE", "positions":{ "references":[ "Facility/AGI#position","Satellite/ISS#position" @@ -232,7 +232,7 @@ } } }, - "followSurface":false, + "arcType":"NONE", "positions":{ "references":[ "Facility/AGI#position","Satellite/Geoeye1/Sensor/Sensor#position" diff --git a/Apps/Sandcastle/gallery/CZML Polyline.html b/Apps/Sandcastle/gallery/CZML Polyline.html index a506213fb7e2..8629392cf01b 100644 --- a/Apps/Sandcastle/gallery/CZML Polyline.html +++ b/Apps/Sandcastle/gallery/CZML Polyline.html @@ -112,7 +112,7 @@ } } }, - "followSurface" : false, + "arcType" : "NONE", "width" : 10 } }, { diff --git a/Apps/Sandcastle/gallery/Clamp to Terrain.html b/Apps/Sandcastle/gallery/Clamp to Terrain.html index fc695c504c9e..0f139299f16a 100644 --- a/Apps/Sandcastle/gallery/Clamp to Terrain.html +++ b/Apps/Sandcastle/gallery/Clamp to Terrain.html @@ -197,7 +197,7 @@ viewer.entities.add({ polyline : { positions : Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(samples), - followSurface : false, + arcType : Cesium.ArcType.NONE, width : 5, material : new Cesium.PolylineOutlineMaterialProperty({ color : Cesium.Color.ORANGE, diff --git a/Apps/Sandcastle/gallery/Custom DataSource.html b/Apps/Sandcastle/gallery/Custom DataSource.html index 9b4c51e8e511..a16afafce250 100644 --- a/Apps/Sandcastle/gallery/Custom DataSource.html +++ b/Apps/Sandcastle/gallery/Custom DataSource.html @@ -319,7 +319,7 @@ var polyline = new Cesium.PolylineGraphics(); polyline.material = new Cesium.ColorMaterialProperty(color); polyline.width = new Cesium.ConstantProperty(2); - polyline.followSurface = new Cesium.ConstantProperty(false); + polyline.arcType = new Cesium.ConstantProperty(Cesium.ArcType.NONE); polyline.positions = new Cesium.ConstantProperty([surfacePosition, heightPosition]); //The polyline instance itself needs to be on an entity. diff --git a/Apps/Sandcastle/gallery/Sample Height from 3D Tiles.html b/Apps/Sandcastle/gallery/Sample Height from 3D Tiles.html index c8ee45d89b89..ec22b0873b7f 100644 --- a/Apps/Sandcastle/gallery/Sample Height from 3D Tiles.html +++ b/Apps/Sandcastle/gallery/Sample Height from 3D Tiles.html @@ -81,7 +81,7 @@ viewer.entities.add({ polyline : { positions : clampedCartesians, - followSurface : false, + arcType : Cesium.ArcType.NONE, width : 2, material : new Cesium.PolylineOutlineMaterialProperty({ color : Cesium.Color.YELLOW diff --git a/Apps/Sandcastle/gallery/Star Burst.html b/Apps/Sandcastle/gallery/Star Burst.html index 9f43819f437b..2677e03355cb 100644 --- a/Apps/Sandcastle/gallery/Star Burst.html +++ b/Apps/Sandcastle/gallery/Star Burst.html @@ -208,7 +208,7 @@ instances.push(new Cesium.GeometryInstance({ geometry : new Cesium.SimplePolylineGeometry({ positions : [starBurstState.center, lines[i]], - followSurface : false, + arcType : Cesium.ArcType.NONE, granularity : Cesium.Math.PI_OVER_FOUR }), attributes : { diff --git a/Apps/Sandcastle/gallery/development/Pick From Ray.html b/Apps/Sandcastle/gallery/development/Pick From Ray.html index 648daf4f343e..c89536a3ad19 100644 --- a/Apps/Sandcastle/gallery/development/Pick From Ray.html +++ b/Apps/Sandcastle/gallery/development/Pick From Ray.html @@ -85,7 +85,7 @@ polyline : { positions : arrowPositions, width : 10, - followSurface : false, + arcType : Cesium.ArcType.NONE, material : new Cesium.PolylineArrowMaterialProperty(Cesium.Color.YELLOW) } }); diff --git a/Apps/Sandcastle/gallery/development/Polyline.html b/Apps/Sandcastle/gallery/development/Polyline.html index e6f13782a0d0..690b0eb74a92 100644 --- a/Apps/Sandcastle/gallery/development/Polyline.html +++ b/Apps/Sandcastle/gallery/development/Polyline.html @@ -52,7 +52,7 @@ // Example 2: Draw a straight blue polyline -// Setting the followSurface option to false will allow +// Setting the arcType option to false will allow // you to draw a straight polyline. Otherwise, it will // curve to the globe surface. scene.primitives.add(new Cesium.Primitive({ @@ -64,7 +64,7 @@ ]), width : 5.0, vertexFormat : Cesium.PolylineColorAppearance.VERTEX_FORMAT, - followSurface: false + arcType: Cesium.ArcType.NONE }), attributes: { color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.BLUE) diff --git a/Apps/Sandcastle/gallery/development/Simple Polyline.html b/Apps/Sandcastle/gallery/development/Simple Polyline.html index b37588a1061e..61324bc37d68 100644 --- a/Apps/Sandcastle/gallery/development/Simple Polyline.html +++ b/Apps/Sandcastle/gallery/development/Simple Polyline.html @@ -53,13 +53,13 @@ } // For per segment coloring, provide the colors options with an // array of colors where the length is equal to the number of positions. -// Setting followSurface to false will draw straight lines. +// Setting arcType to false will draw straight lines. // Otherwise, the polyline curves to the surface of the globe. var perSegmentPolyline = new Cesium.GeometryInstance({ geometry : new Cesium.SimplePolylineGeometry({ positions : positions, colors : colors, - followSurface: false + arcType: Cesium.ArcType.NONE }) }); diff --git a/Source/Core/PolylineGeometry.js b/Source/Core/PolylineGeometry.js index a4232b8833e4..1439124713f7 100644 --- a/Source/Core/PolylineGeometry.js +++ b/Source/Core/PolylineGeometry.js @@ -143,7 +143,7 @@ define([ this._followSurface = defaultValue(options.followSurface, true); if (defined(options.followSurface)) { - deprecationWarning('PolylineGeometry.followSurface', 'PolylineGeometry.followSurface is deprecated and will be removed in Cesium 1.55. Use PolylineGeometry.arcType instead.'); + deprecationWarning('PolylineGeometry.followSurface', 'PolylineGeometry.followSurface is deprecated and will be removed in Cesium 1.57. Use PolylineGeometry.arcType instead.'); options.arcType = options.followSurface ? ArcType.GEODESIC : ArcType.NONE; } this._arcType = defaultValue(options.arcType, ArcType.GEODESIC); diff --git a/Source/Core/SimplePolylineGeometry.js b/Source/Core/SimplePolylineGeometry.js index 65187d9d6c6c..7168c3b6b8ba 100644 --- a/Source/Core/SimplePolylineGeometry.js +++ b/Source/Core/SimplePolylineGeometry.js @@ -128,7 +128,7 @@ define([ this._followSurface = defaultValue(options.followSurface, true); if (defined(options.followSurface)) { - deprecationWarning('PolylineGeometry.followSurface', 'PolylineGeometry.followSurface is deprecated and will be removed in Cesium 1.55. Use PolylineGeometry.arcType instead.'); + deprecationWarning('PolylineGeometry.followSurface', 'PolylineGeometry.followSurface is deprecated and will be removed in Cesium 1.57. Use PolylineGeometry.arcType instead.'); options.arcType = options.followSurface ? ArcType.GEODESIC : ArcType.NONE; } this._arcType = defaultValue(options.arcType, ArcType.GEODESIC); diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index ba3597cad1c6..96eba71a80c2 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -1,4 +1,5 @@ define([ + '../Core/ArcType', '../Core/BoundingRectangle', '../Core/Cartesian2', '../Core/Cartesian3', @@ -86,6 +87,7 @@ define([ './VelocityVectorProperty', './WallGraphics' ], function( + ArcType, BoundingRectangle, Cartesian2, Cartesian3, @@ -501,6 +503,8 @@ define([ } else if (czmlInterval.hasOwnProperty('rgba') || czmlInterval.hasOwnProperty('rgbaf')) { return Color; + } else if (czmlInterval.hasOwnProperty('arcType')) { + return ArcType; } else if (czmlInterval.hasOwnProperty('colorBlendMode')) { return ColorBlendMode; } else if (czmlInterval.hasOwnProperty('cornerType')) { @@ -546,6 +550,8 @@ define([ // The associations in this function need to be kept in sync with the // associations in getPropertyType switch (type) { + case ArcType: + return ArcType[defaultValue(czmlInterval.arcType, czmlInterval)]; case Array: return czmlInterval.array; case Boolean: @@ -1795,6 +1801,7 @@ define([ processMaterialPacketData(polyline, 'material', polylineData.material, interval, sourceUri, entityCollection); processMaterialPacketData(polyline, 'depthFailMaterial', polylineData.depthFailMaterial, interval, sourceUri, entityCollection); processPacketData(Boolean, polyline, 'followSurface', polylineData.followSurface, interval, sourceUri, entityCollection); + processPacketData(ArcType, polyline, 'arcType', polylineData.arcType, interval, sourceUri, entityCollection); processPacketData(Boolean, polyline, 'clampToGround', polylineData.clampToGround, interval, sourceUri, entityCollection); processPacketData(ShadowMode, polyline, 'shadows', polylineData.shadows, interval, sourceUri, entityCollection); processPacketData(DistanceDisplayCondition, polyline, 'distanceDisplayCondition', polylineData.distanceDisplayCondition, interval, sourceUri, entityCollection); diff --git a/Source/DataSources/KmlDataSource.js b/Source/DataSources/KmlDataSource.js index 55f9469e219f..4ef9027a7e3b 100644 --- a/Source/DataSources/KmlDataSource.js +++ b/Source/DataSources/KmlDataSource.js @@ -1,4 +1,5 @@ define([ + '../Core/ArcType', '../Core/AssociativeArray', '../Core/BoundingRectangle', '../Core/Cartesian2', @@ -64,6 +65,7 @@ define([ './TimeIntervalCollectionProperty', './WallGraphics' ], function( + ArcType, AssociativeArray, BoundingRectangle, Cartesian2, @@ -1287,7 +1289,7 @@ define([ entity.polyline = polyline; polyline.positions = createPositionPropertyArrayFromAltitudeMode(coordinates, altitudeMode, gxAltitudeMode, ellipsoid); if (!tessellate || canExtrude) { - polyline.followSurface = false; + polyline.arcType = ArcType.NONE; } } diff --git a/Specs/Core/SimplePolylineGeometrySpec.js b/Specs/Core/SimplePolylineGeometrySpec.js index 193136e948e6..4e951f2c371c 100644 --- a/Specs/Core/SimplePolylineGeometrySpec.js +++ b/Specs/Core/SimplePolylineGeometrySpec.js @@ -116,7 +116,7 @@ defineSuite([ var positions = [new Cartesian3(), new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(2.0, 0.0, 0.0)]; var line = SimplePolylineGeometry.createGeometry(new SimplePolylineGeometry({ positions : positions, - followSurface: false + arcType: ArcType.NONE })); expect(line.attributes.position.values).toEqual([0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 2.0, 0.0, 0.0]); @@ -131,7 +131,7 @@ defineSuite([ var line = SimplePolylineGeometry.createGeometry(new SimplePolylineGeometry({ positions : positions, colors : colors, - followSurface: false + arcType : ArcType.NONE })); expect(line.attributes.color).toBeDefined(); @@ -147,7 +147,7 @@ defineSuite([ positions : positions, colors : colors, colorsPerVertex : true, - followSurface: false + arcType : ArcType.NONE })); expect(line.attributes.color).toBeDefined(); @@ -161,7 +161,7 @@ defineSuite([ positions : positions, colors : [Color.RED, Color.LIME, Color.BLUE], colorsPerVertex : true, - followSurface : false, + arcType : ArcType.NONE, granularity : 11, ellipsoid : new Ellipsoid(12, 13, 14) }); @@ -171,7 +171,7 @@ defineSuite([ line = new SimplePolylineGeometry({ positions : positions, colorsPerVertex : false, - followSurface : false, + arcType : ArcType.NONE, granularity : 11, ellipsoid : new Ellipsoid(12, 13, 14) }); diff --git a/Specs/Data/CZML/ValidationDocument.czml b/Specs/Data/CZML/ValidationDocument.czml index 0bf1a8df0c59..8b959a351d2e 100644 --- a/Specs/Data/CZML/ValidationDocument.czml +++ b/Specs/Data/CZML/ValidationDocument.czml @@ -474,7 +474,7 @@ } } }, - "followSurface":true, + "arcType":"GEODESIC", "shadows":"CAST_ONLY", "depthFailMaterial":{ "solidColor":{ @@ -6313,6 +6313,9 @@ "followSurface":{ "reference":"Constant#polyline.followSurface" }, + "arcType":{ + "reference":"Constant#polyline.arcType" + }, "shadows":{ "reference":"Constant#polyline.shadows" }, diff --git a/Specs/DataSources/CzmlDataSourceSpec.js b/Specs/DataSources/CzmlDataSourceSpec.js index 23e8c16ce113..397f69f870d1 100644 --- a/Specs/DataSources/CzmlDataSourceSpec.js +++ b/Specs/DataSources/CzmlDataSourceSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'DataSources/CzmlDataSource', + 'Core/ArcType', 'Core/BoundingRectangle', 'Core/Cartesian2', 'Core/Cartesian3', @@ -38,6 +39,7 @@ defineSuite([ 'ThirdParty/when' ], function( CzmlDataSource, + ArcType, BoundingRectangle, Cartesian2, Cartesian3, @@ -3775,7 +3777,7 @@ defineSuite([ expect(e.polyline.width.getValue(date)).toEqual(14667.0); expect(e.polyline.granularity.getValue(date)).toEqual(53395.0); expect(e.polyline.material.color.getValue(date)).toEqual(Color.fromBytes(88, 0, 232, 230)); - expect(e.polyline.followSurface.getValue(date)).toEqual(true); + expect(e.polyline.arcType.getValue(date)).toEqual(ArcType.GEODESIC); expect(e.polyline.shadows.getValue(date)).toEqual(ShadowMode.CAST_ONLY); expect(e.polyline.depthFailMaterial.color.getValue(date)).toEqual(Color.fromBytes(197, 195, 115, 198)); expect(e.polyline.distanceDisplayCondition.getValue(date)).toEqual(new DistanceDisplayCondition(5807, 30486)); @@ -4584,7 +4586,7 @@ defineSuite([ expect(e.polyline.width.getValue(date)).toEqual(constant.polyline.width.getValue(date)); expect(e.polyline.granularity.getValue(date)).toEqual(constant.polyline.granularity.getValue(date)); expect(e.polyline.material.color.getValue(date)).toEqual(constant.polyline.material.color.getValue(date)); - expect(e.polyline.followSurface.getValue(date)).toEqual(constant.polyline.followSurface.getValue(date)); + expect(e.polyline.arcType.getValue(date)).toEqual(constant.polyline.arcType.getValue(date)); expect(e.polyline.shadows.getValue(date)).toEqual(constant.polyline.shadows.getValue(date)); expect(e.polyline.depthFailMaterial.color.getValue(date)).toEqual(constant.polyline.depthFailMaterial.color.getValue(date)); expect(e.polyline.distanceDisplayCondition.getValue(date)).toEqual(constant.polyline.distanceDisplayCondition.getValue(date)); diff --git a/Specs/DataSources/KmlDataSourceSpec.js b/Specs/DataSources/KmlDataSourceSpec.js index 628e6fe9755f..58b6afda68a0 100644 --- a/Specs/DataSources/KmlDataSourceSpec.js +++ b/Specs/DataSources/KmlDataSourceSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'DataSources/KmlDataSource', + 'Core/ArcType', 'Core/BoundingRectangle', 'Core/Cartesian2', 'Core/Cartesian3', @@ -38,6 +39,7 @@ defineSuite([ 'ThirdParty/when' ], function( KmlDataSource, + ArcType, BoundingRectangle, Cartesian2, Cartesian3, @@ -2161,7 +2163,7 @@ defineSuite([ expect(polyline).toBeDefined(); expect(polyline.positions).toBeUndefined(); - expect(polyline.followSurface).toBeUndefined(); + expect(polyline.arcType).toBeUndefined(); expect(polyline.width).toBeUndefined(); expect(polyline.show).toBeUndefined(); expect(polyline.material).toBeUndefined(); @@ -2899,7 +2901,7 @@ defineSuite([ var entity = entities[0]; expect(entity.wall).toBeUndefined(); expect(entity.polyline).toBeDefined(); - expect(entity.polyline.followSurface.getValue()).toEqual(false); + expect(entity.polyline.arcType.getValue()).toEqual(ArcType.NONE); }); }); @@ -2923,7 +2925,7 @@ defineSuite([ var positions = entity.polyline.positions.getValue(Iso8601.MINIMUM_VALUE); expect(positions).toEqualEpsilon([Cartesian3.fromDegrees(1, 2), Cartesian3.fromDegrees(4, 5)], CesiumMath.EPSILON10); - expect(entity.polyline.followSurface.getValue()).toEqual(false); + expect(entity.polyline.arcType.getValue()).toEqual(ArcType.NONE); }); }); @@ -2968,7 +2970,7 @@ defineSuite([ expect(entities.length).toEqual(1); var entity = entities[0]; - expect(entity.polyline.followSurface).toBeUndefined(); + expect(entity.polyline.arcType).toBeUndefined(); var positions = entity.polyline.positions.getValue(Iso8601.MINIMUM_VALUE); expect(positions).toEqualEpsilon([Cartesian3.fromDegrees(1, 2), Cartesian3.fromDegrees(4, 5)], CesiumMath.EPSILON10); }); @@ -2991,7 +2993,7 @@ defineSuite([ expect(entities.length).toEqual(1); var entity = entities[0]; - expect(entity.polyline.followSurface).toBeUndefined(); + expect(entity.polyline.arcType).toBeUndefined(); var positions = entity.polyline.positions.getValue(Iso8601.MINIMUM_VALUE); expect(positions).toEqualEpsilon([Cartesian3.fromDegrees(1, 2), Cartesian3.fromDegrees(4, 5)], CesiumMath.EPSILON10); }); diff --git a/Specs/Scene/GeometryRenderingSpec.js b/Specs/Scene/GeometryRenderingSpec.js index d766f50e6894..fb2662ac6159 100644 --- a/Specs/Scene/GeometryRenderingSpec.js +++ b/Specs/Scene/GeometryRenderingSpec.js @@ -1,4 +1,5 @@ defineSuite([ + 'Core/ArcType', 'Core/BoundingSphere', 'Core/BoxGeometry', 'Core/PlaneGeometry', @@ -41,6 +42,7 @@ defineSuite([ 'Specs/createScene', 'Specs/pollToPromise' ], 'Scene/GeometryRendering', function( + ArcType, BoundingSphere, BoxGeometry, PlaneGeometry, @@ -1563,7 +1565,7 @@ defineSuite([ ]), width : 20.0, colors : [new Color(1.0, 0.0, 0.0, 1.0), new Color(0.0, 1.0, 0.0, 1.0)], - followSurface: false + arcType : ArcType.NONE }), id : 'polyline' }); @@ -1582,7 +1584,7 @@ defineSuite([ width : 20.0, colors : [new Color(1.0, 0.0, 0.0, 1.0), new Color(0.0, 1.0, 0.0, 1.0)], colorsPerVertex : true, - followSurface: false + arcType : ArcType.NONE }), id : 'polyline' }); diff --git a/Specs/Scene/PolylineColorAppearanceSpec.js b/Specs/Scene/PolylineColorAppearanceSpec.js index b2983c6d2ba3..a9022cbf42b7 100644 --- a/Specs/Scene/PolylineColorAppearanceSpec.js +++ b/Specs/Scene/PolylineColorAppearanceSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'Scene/PolylineColorAppearance', + 'Core/ArcType', 'Core/Cartesian3', 'Core/Color', 'Core/ColorGeometryInstanceAttribute', @@ -59,7 +60,7 @@ defineSuite([ ], width : 10.0, vertexFormat : PolylineColorAppearance.VERTEX_FORMAT, - followSurface: false + arcType : ArcType.NONE }), attributes : { color : ColorGeometryInstanceAttribute.fromColor(new Color(1.0, 1.0, 0.0, 1.0)) diff --git a/Specs/Scene/PolylineMaterialAppearanceSpec.js b/Specs/Scene/PolylineMaterialAppearanceSpec.js index 8f0250777878..5ae00f21daac 100644 --- a/Specs/Scene/PolylineMaterialAppearanceSpec.js +++ b/Specs/Scene/PolylineMaterialAppearanceSpec.js @@ -1,5 +1,6 @@ defineSuite([ 'Scene/PolylineMaterialAppearance', + 'Core/ArcType', 'Core/Cartesian3', 'Core/GeometryInstance', 'Core/PolylineGeometry', @@ -9,6 +10,7 @@ defineSuite([ 'Specs/createScene' ], function( PolylineMaterialAppearance, + ArcType, Cartesian3, GeometryInstance, PolylineGeometry, @@ -58,7 +60,7 @@ defineSuite([ ], width : 10.0, vertexFormat : PolylineMaterialAppearance.VERTEX_FORMAT, - followSurface: false + arcType : ArcType.NONE }) }), appearance : new PolylineMaterialAppearance({ From 7f3aa0a5e0d742c675de2b452b25c703cbcad0a8 Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Tue, 19 Feb 2019 14:14:35 -0500 Subject: [PATCH 27/71] Update changes.md --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index e1465f5fdadc..1bf5bed856fe 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Change Log ##### Additions :tada: * `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). +* Added support for `arcType` to CZML Data Source. [#7582](https://github.com/AnalyticalGraphicsInc/cesium/issues/7582) ##### Fixes :wrench: * Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383) @@ -19,6 +20,7 @@ Change Log * Fixed model silhouette colors when rendering with high dynamic range. [#7563](https://github.com/AnalyticalGraphicsInc/cesium/pull/7563) * Fixed an issue with ground polylines on globes that use ellipsoids other than WGS84. [#7552](https://github.com/AnalyticalGraphicsInc/cesium/issues/7552) * Fixed an issue where Draco compressed models with RGB per-vertex color would not load in Cesium. [#7576](https://github.com/AnalyticalGraphicsInc/cesium/issues/7576) +* Changed usage of deprecated property `followSurface` to use `arcType`. [#7572](https://github.com/AnalyticalGraphicsInc/cesium/issues/7572) ### 1.54 - 2019-02-01 From af4649dab67c4ba0108a787b4400c843c264ad66 Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Tue, 19 Feb 2019 14:28:03 -0500 Subject: [PATCH 28/71] Fix missing definition for ArcType --- Specs/Scene/PolylineColorAppearanceSpec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Specs/Scene/PolylineColorAppearanceSpec.js b/Specs/Scene/PolylineColorAppearanceSpec.js index a9022cbf42b7..b1fbb025fd85 100644 --- a/Specs/Scene/PolylineColorAppearanceSpec.js +++ b/Specs/Scene/PolylineColorAppearanceSpec.js @@ -11,6 +11,7 @@ defineSuite([ 'Specs/createScene' ], function( PolylineColorAppearance, + ArcType, Cartesian3, Color, ColorGeometryInstanceAttribute, From 112c34574667abae78b476613848112a020eda22 Mon Sep 17 00:00:00 2001 From: Shehata Date: Tue, 19 Feb 2019 17:34:09 -0500 Subject: [PATCH 29/71] Refactor imageBitmapOptions check --- CHANGES.md | 3 + Source/Core/FeatureDetection.js | 52 ------- Source/Core/IonResource.js | 9 +- Source/Core/Resource.js | 100 +++++++++++--- Source/Core/loadImageFromTypedArray.js | 22 +-- Source/Scene/DiscardMissingTileImagePolicy.js | 4 +- Source/Scene/ImageryProvider.js | 4 +- Source/Widgets/Viewer/Viewer.js | 6 - Specs/Core/FeatureDetectionSpec.js | 8 -- Specs/Core/IonResourceSpec.js | 14 +- Specs/Core/ResourceSpec.js | 35 ++--- Specs/Core/VRTheWorldTerrainProviderSpec.js | 6 - Specs/Core/loadImageFromTypedArraySpec.js | 50 +++---- Specs/Renderer/TextureSpec.js | 129 +++++++++--------- .../ArcGisMapServerImageryProviderSpec.js | 7 +- Specs/Scene/BillboardCollectionSpec.js | 33 ++--- Specs/Scene/BingMapsImageryProviderSpec.js | 4 - .../DiscardMissingTileImagePolicySpec.js | 21 ++- ...oogleEarthEnterpriseImageryProviderSpec.js | 3 - .../GoogleEarthEnterpriseMapsProviderSpec.js | 4 - Specs/Scene/MapboxImageryProviderSpec.js | 6 - Specs/Scene/SingleTileImageryProviderSpec.js | 6 - Specs/Scene/TextureAtlasSpec.js | 45 +++--- Specs/Scene/UrlTemplateImageryProviderSpec.js | 6 - .../Scene/WebMapServiceImageryProviderSpec.js | 6 - .../WebMapTileServiceImageryProviderSpec.js | 6 - .../createOpenStreetMapImageryProviderSpec.js | 6 - ...createTileMapServiceImageryProviderSpec.js | 6 - 28 files changed, 277 insertions(+), 324 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e5c3a928ab79..6fade07e29d5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,9 @@ Change Log * `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). * Add support for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode when `ImageBitmapOptions` are supported since an `ImageBitmap` cannot be vertically flipped during texture upload. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) +##### Deprecated :hourglass_flowing_sand: +* `Resource.fetchImage` now takes an options object. Use `resource.fetchImage({ preferBlob: true })` instead of `resource.fetchImage(true)`. The previous function definition will no longer work in 1.56. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) + ##### Fixes :wrench: * Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383) * Fixed Node.js support for the `Resource` class and any functionality using it internally. diff --git a/Source/Core/FeatureDetection.js b/Source/Core/FeatureDetection.js index 6f3647a7b76b..cd0d56800b13 100644 --- a/Source/Core/FeatureDetection.js +++ b/Source/Core/FeatureDetection.js @@ -262,56 +262,6 @@ define([ return supportsCreateImageBitmapResult; } - var supportsImageBitmapOptionsResult; - var supportsImageBitmapOptionsPromise; - function supportsImageBitmapOptions() { - // Until the HTML folks figure out what to do about this, we need to actually try loading an image to - // know if this browser supports passing options to the createImageBitmap function. - // https://github.com/whatwg/html/pull/4248 - if (defined(supportsImageBitmapOptionsPromise)) { - return supportsImageBitmapOptionsPromise.promise; - } - - supportsImageBitmapOptionsPromise = when.defer(); - - if (!supportsCreateImageBitmap()) { - supportsImageBitmapOptionsResult = false; - supportsImageBitmapOptionsPromise.resolve(supportsImageBitmapOptionsResult); - return supportsImageBitmapOptionsPromise.promise; - } - - var imageDataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWP4////fwAJ+wP9CNHoHgAAAABJRU5ErkJggg=='; - // Use the fetch API here to avoid a circular dependency from including Resource here. - // `fetch` is supported everywhere createImageBitmap is. - fetch(imageDataUri) - .then(function(response) { - return response.blob(); - }) - .then(function(blob) { - return createImageBitmap(blob, { - imageOrientation: 'flipY' - }); - }) - .then(function(imageBitmap) { - supportsImageBitmapOptionsResult = true; - supportsImageBitmapOptionsPromise.resolve(supportsImageBitmapOptionsResult); - }) - .catch(function() { - supportsImageBitmapOptionsResult = false; - supportsImageBitmapOptionsPromise.resolve(supportsImageBitmapOptionsResult); - }); - - return supportsImageBitmapOptionsPromise.promise; - } - - function supportsImageBitmapOptionsSync() { - if (!defined(supportsImageBitmapOptionsPromise)) { - supportsImageBitmapOptions(); - } - - return supportsImageBitmapOptionsResult; - } - /** * A set of functions to detect whether the current browser supports * various features. @@ -338,8 +288,6 @@ define([ supportsWebP: supportsWebP, supportsWebPSync: supportsWebPSync, supportsCreateImageBitmap: supportsCreateImageBitmap, - supportsImageBitmapOptions: supportsImageBitmapOptions, - supportsImageBitmapOptionsSync: supportsImageBitmapOptionsSync, imageRenderingValue: imageRenderingValue, typedArrayTypes: typedArrayTypes }; diff --git a/Source/Core/IonResource.js b/Source/Core/IonResource.js index b0800cf4453b..b474f26ca857 100644 --- a/Source/Core/IonResource.js +++ b/Source/Core/IonResource.js @@ -164,8 +164,13 @@ define([ return result; }; - IonResource.prototype.fetchImage = function (preferBlob, allowCrossOrigin) { - return Resource.prototype.fetchImage.call(this, this._isExternal ? preferBlob : true, allowCrossOrigin); + IonResource.prototype.fetchImage = function (options) { + if (!this._isExternal) { + options = defaultValue(options, {}); + options.preferBlob = true; + } + + return Resource.prototype.fetchImage.call(this, options); }; IonResource.prototype._makeRequest = function(options) { diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index 8416e32464fe..6b315d048367 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -376,6 +376,49 @@ define([ }); }; + var supportsImageBitmapOptionsPromise; + /** + * A helper function to check whether createImageBitmap supports passing ImageBitmapOptions. + * + * @returns {Promise} A promise that resolves to true if this browser supports creating an ImageBitmap with options. + * + * @private + */ + Resource.supportsImageBitmapOptions = function() { + // Until the HTML folks figure out what to do about this, we need to actually try loading an image to + // know if this browser supports passing options to the createImageBitmap function. + // https://github.com/whatwg/html/pull/4248 + if (defined(supportsImageBitmapOptionsPromise)) { + return supportsImageBitmapOptionsPromise.promise; + } + + supportsImageBitmapOptionsPromise = when.defer(); + + if (!FeatureDetection.supportsCreateImageBitmap()) { + supportsImageBitmapOptionsPromise.resolve(false); + return supportsImageBitmapOptionsPromise.promise; + } + + var imageDataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWP4////fwAJ+wP9CNHoHgAAAABJRU5ErkJggg=='; + + Resource.fetchBlob({ + url : imageDataUri + }) + .then(function(blob) { + return when(createImageBitmap(blob, { + imageOrientation: 'flipY' + })); + }) + .then(function(imageBitmap) { + supportsImageBitmapOptionsPromise.resolve(true); + }) + .otherwise(function() { + supportsImageBitmapOptionsPromise.resolve(false); + }); + + return supportsImageBitmapOptionsPromise.promise; + }; + defineProperties(Resource, { /** * Returns true if blobs are supported. @@ -855,6 +898,12 @@ define([ * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} */ Resource.prototype.fetchImage = function (options) { + if (defined(options) && typeof options === 'boolean') { + deprecationWarning('fetchImage-parameter-change', 'fetchImage now takes an options object in CesiumJS 1.55. Use resource.fetchImage({ preferBlob: true }) instead of resource.fetchImage(true).'); + options = { + preferBlob : options + }; + } options = defaultValue(options, {}); var preferBlob = defaultValue(options.preferBlob, false); var flipY = defaultValue(options.flipY, true); @@ -875,6 +924,15 @@ define([ return; } + if (FeatureDetection.supportsCreateImageBitmap()) { + return blobPromise + .then(function(blob) { + var deferred = when.defer(); + Resource._Implementations.createImageBitmapFromBlob(blob, deferred, flipY); + return deferred; + }); + } + var generatedBlobResource; var generatedBlob; return blobPromise @@ -882,6 +940,7 @@ define([ if (!defined(blob)) { return; } + generatedBlob = blob; var blobUrl = window.URL.createObjectURL(blob); generatedBlobResource = new Resource({ @@ -1767,24 +1826,7 @@ define([ Resource._Implementations = {}; Resource._Implementations.createImage = function(url, crossOrigin, deferred, flipY) { - var supportsBitmapOptions = FeatureDetection.supportsImageBitmapOptionsSync(); - - if (FeatureDetection.supportsCreateImageBitmap() && defined(supportsBitmapOptions)) { - Resource.fetchBlob({ - url: url - }) - .then(function(blob) { - if (!supportsBitmapOptions) { - return when(createImageBitmap(blob)); - } - - return when(createImageBitmap(blob, { - imageOrientation: flipY ? 'flipY' : 'none' - })); - }) - .then(deferred.resolve) - .otherwise(deferred.reject); - } else { + if (!FeatureDetection.supportsCreateImageBitmap()) { var image = new Image(); image.onload = function() { @@ -1804,9 +1846,31 @@ define([ } image.src = url; + } else { + // createImageBitmap will block the main thread during decode if a blob is not supplied. + Resource.fetchBlob({ + url: url + }).then(function(blob) { + Resource._Implementations.createImageBitmapFromBlob(blob, deferred, flipY); + }).otherwise(deferred.reject); } }; + Resource._Implementations.createImageBitmapFromBlob = function(blob, deferred, flipY) { + Resource.supportsImageBitmapOptions() + .then(function(supportsBitmapOptions) { + if (!supportsBitmapOptions) { + return when(createImageBitmap(blob)); + } + + return when(createImageBitmap(blob, { + imageOrientation: flipY ? 'flipY' : 'none' + })); + }) + .then(deferred.resolve) + .otherwise(deferred.reject); + }; + function decodeResponse(loadWithHttpResponse, responseType) { switch (responseType) { case 'text': diff --git a/Source/Core/loadImageFromTypedArray.js b/Source/Core/loadImageFromTypedArray.js index d64f5f781475..987fc07ae461 100644 --- a/Source/Core/loadImageFromTypedArray.js +++ b/Source/Core/loadImageFromTypedArray.js @@ -31,17 +31,19 @@ define([ type : format }); - // We can avoid the extra fetch when createImageBitmap is supported. - var supportsBitmapOptions = FeatureDetection.supportsImageBitmapOptionsSync(); + // Avoid an extra fetch by just calling createImageBitmap here directly on the blob + // instead of sending it to Resource as a blob URL. + if (FeatureDetection.supportsCreateImageBitmap()) { + return Resource.supportsImageBitmapOptions() + .then(function(supportsBitmapOptions) { + if (supportsBitmapOptions) { + return when(createImageBitmap(blob, { + imageOrientation: flipY ? 'flipY' : 'none' + })); + } - if (FeatureDetection.supportsCreateImageBitmap() && defined(supportsBitmapOptions)) { - if (supportsBitmapOptions) { - return when(createImageBitmap(blob, { - imageOrientation: flipY ? 'flipY' : 'none' - })); - } - - return when(createImageBitmap(blob)); + return when(createImageBitmap(blob)); + }); } var blobUrl = window.URL.createObjectURL(blob); diff --git a/Source/Scene/DiscardMissingTileImagePolicy.js b/Source/Scene/DiscardMissingTileImagePolicy.js index ef4c66a18dfb..a8da9e33f071 100644 --- a/Source/Scene/DiscardMissingTileImagePolicy.js +++ b/Source/Scene/DiscardMissingTileImagePolicy.js @@ -89,7 +89,9 @@ define([ that._isReady = true; } - when(resource.fetchImage(true), success, failure); + when(resource.fetchImage({ + preferBlob : true + }), success, failure); } /** diff --git a/Source/Scene/ImageryProvider.js b/Source/Scene/ImageryProvider.js index 61f49b663a56..55d85bb7bfda 100644 --- a/Source/Scene/ImageryProvider.js +++ b/Source/Scene/ImageryProvider.js @@ -344,7 +344,9 @@ define([ } else if (crnRegex.test(resource)) { return loadCRN(resource); } else if (defined(imageryProvider.tileDiscardPolicy)) { - return resource.fetchImage(true); + return resource.fetchImage({ + preferBlob : true + }); } return resource.fetchImage(); diff --git a/Source/Widgets/Viewer/Viewer.js b/Source/Widgets/Viewer/Viewer.js index 5c286670fb43..d9664a7bb540 100644 --- a/Source/Widgets/Viewer/Viewer.js +++ b/Source/Widgets/Viewer/Viewer.js @@ -10,7 +10,6 @@ define([ '../../Core/DeveloperError', '../../Core/Event', '../../Core/EventHelper', - '../../Core/FeatureDetection', '../../Core/HeadingPitchRange', '../../Core/isArray', '../../Core/Matrix4', @@ -61,7 +60,6 @@ define([ DeveloperError, Event, EventHelper, - FeatureDetection, HeadingPitchRange, isArray, Matrix4, @@ -363,10 +361,6 @@ define([ } //>>includeEnd('debug'); - // We kick off this asynchronous test here so we can start using - // createImageBitmap if it's supported as soon as possible. - FeatureDetection.supportsImageBitmapOptions(); - container = getElement(container); options = defaultValue(options, defaultValue.EMPTY_OBJECT); diff --git a/Specs/Core/FeatureDetectionSpec.js b/Specs/Core/FeatureDetectionSpec.js index a1dd850c005b..2ab1238f288e 100644 --- a/Specs/Core/FeatureDetectionSpec.js +++ b/Specs/Core/FeatureDetectionSpec.js @@ -128,12 +128,4 @@ defineSuite([ var supportsCreateImageBitmap = FeatureDetection.supportsCreateImageBitmap(); expect(typeof supportsCreateImageBitmap).toEqual('boolean'); }); - - it('detects ImageBitmapOptions support', function() { - return FeatureDetection.supportsImageBitmapOptions() - .then(function(supportsImageBitmapOptions) { - expect(typeof supportsImageBitmapOptions).toEqual('boolean'); - expect(FeatureDetection.supportsImageBitmapOptionsSync()).toEqual(supportsImageBitmapOptions); - }); - }); }); diff --git a/Specs/Core/IonResourceSpec.js b/Specs/Core/IonResourceSpec.js index 0baf9e621260..f5f5e2f1d72b 100644 --- a/Specs/Core/IonResourceSpec.js +++ b/Specs/Core/IonResourceSpec.js @@ -225,8 +225,10 @@ defineSuite([ var fetchImage = spyOn(Resource.prototype, 'fetchImage'); var endpointResource = IonResource._createEndpointResource(assetId); var resource = new IonResource(endpoint, endpointResource); - resource.fetchImage(false, true); - expect(fetchImage).toHaveBeenCalledWith(true, true); + resource.fetchImage(); + expect(fetchImage).toHaveBeenCalledWith({ + preferBlob : true + }); }); it('Calls base fetchImage with no changes for external assets', function() { @@ -240,8 +242,12 @@ defineSuite([ var fetchImage = spyOn(Resource.prototype, 'fetchImage'); var endpointResource = IonResource._createEndpointResource(assetId); var resource = new IonResource(externalEndpoint, endpointResource); - resource.fetchImage(false, true); - expect(fetchImage).toHaveBeenCalledWith(false, true); + resource.fetchImage({ + preferBlob : false + }); + expect(fetchImage).toHaveBeenCalledWith({ + preferBlob : false + }); }); describe('retryCallback', function() { diff --git a/Specs/Core/ResourceSpec.js b/Specs/Core/ResourceSpec.js index 3a27fd7380ce..cac4e31efe6f 100644 --- a/Specs/Core/ResourceSpec.js +++ b/Specs/Core/ResourceSpec.js @@ -28,10 +28,6 @@ defineSuite([ var dataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2Nk+M/wHwAEBgIA5agATwAAAABJRU5ErkJggg=='; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - it('Constructor sets correct properties', function() { var proxy = new DefaultProxy('/proxy/'); var request = new Request(); @@ -1177,23 +1173,17 @@ defineSuite([ }); }); - it('does not call createImageBitmap when ImageBitmapOptions support is not ready', function() { - spyOn(FeatureDetection, 'supportsImageBitmapOptionsSync').and.returnValue(undefined); - spyOn(window, 'createImageBitmap').and.callThrough(); - - return Resource.fetchImage('./Data/Images/Green.png').then(function(loadedImage) { - expect(loadedImage.width).toEqual(1); - expect(loadedImage.height).toEqual(1); - expect(window.createImageBitmap).not.toHaveBeenCalled(); - }); - }); - it('correctly flips image when ImageBitmapOptions are supported', function() { + var loadedImage; + return Resource.fetchImage({ url: './Data/Images/BlueOverRed.png', flipY: true - }).then(function(loadedImage) { - if (FeatureDetection.supportsImageBitmapOptionsSync()) { + }).then(function(image) { + loadedImage = image; + return Resource.supportsImageBitmapOptions(); + }).then(function(supportsImageBitmapOptions) { + if (supportsImageBitmapOptions) { expect(getColorAtPixel(loadedImage, 0, 0)).toEqual([255, 0, 0, 255]); } else { expect(getColorAtPixel(loadedImage, 0, 0)).toEqual([0, 0, 255, 255]); @@ -1202,11 +1192,16 @@ defineSuite([ }); it('correctly loads image without flip when ImageBitmapOptions are supported', function() { + var loadedImage; + return Resource.fetchImage({ url: './Data/Images/BlueOverRed.png', flipY: false - }).then(function(loadedImage) { - if (FeatureDetection.supportsImageBitmapOptionsSync()) { + }).then(function(image) { + loadedImage = image; + return Resource.supportsImageBitmapOptions(); + }).then(function(supportsImageBitmapOptions) { + if (supportsImageBitmapOptions) { expect(getColorAtPixel(loadedImage, 0, 0)).toEqual([0, 0, 255, 255]); } else { expect(getColorAtPixel(loadedImage, 0, 0)).toEqual([0, 0, 255, 255]); @@ -1215,7 +1210,7 @@ defineSuite([ }); it('does not pass options when ImageBitmapOptions are not supported', function() { - spyOn(FeatureDetection, 'supportsImageBitmapOptionsSync').and.returnValue(false); + spyOn(Resource, 'supportsImageBitmapOptions').and.returnValue(when.resolve(false)); spyOn(window, 'createImageBitmap').and.callThrough(); return Resource.fetchImage('./Data/Images/Green.png').then(function(loadedImage) { diff --git a/Specs/Core/VRTheWorldTerrainProviderSpec.js b/Specs/Core/VRTheWorldTerrainProviderSpec.js index d1e6d47b6efb..f47a1d52b56a 100644 --- a/Specs/Core/VRTheWorldTerrainProviderSpec.js +++ b/Specs/Core/VRTheWorldTerrainProviderSpec.js @@ -1,7 +1,6 @@ defineSuite([ 'Core/VRTheWorldTerrainProvider', 'Core/DefaultProxy', - 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/HeightmapTerrainData', 'Core/Math', @@ -14,7 +13,6 @@ defineSuite([ ], function( VRTheWorldTerrainProvider, DefaultProxy, - FeatureDetection, GeographicTilingScheme, HeightmapTerrainData, CesiumMath, @@ -69,10 +67,6 @@ defineSuite([ Resource._Implementations.loadWithXhr = Resource._DefaultImplementations.loadWithXhr; }); - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - function createRequest() { return new Request({ throttleByServer : true diff --git a/Specs/Core/loadImageFromTypedArraySpec.js b/Specs/Core/loadImageFromTypedArraySpec.js index e21b800bdc38..052e3f2d5d06 100644 --- a/Specs/Core/loadImageFromTypedArraySpec.js +++ b/Specs/Core/loadImageFromTypedArraySpec.js @@ -8,10 +8,6 @@ defineSuite([ Resource) { 'use strict'; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - it('can load an image', function() { return Resource.fetchArrayBuffer('./Data/Images/Blue10x10.png').then(function(arrayBuffer) { var options = { @@ -36,29 +32,33 @@ defineSuite([ var blob = new Blob([options.uint8Array], { type : options.format }); + var supportsImageBitmapOptions; - return loadImageFromTypedArray(options).then(function() { - if (FeatureDetection.supportsImageBitmapOptionsSync()) { - expect(window.createImageBitmap).toHaveBeenCalledWith(blob, { - imageOrientation: 'flipY' - }); - } else { - expect(window.createImageBitmap).toHaveBeenCalledWith(blob); - } + return loadImageFromTypedArray(options) + .then(Resource.supportsImageBitmapOptions) + .then(function(result) { + supportsImageBitmapOptions = result; + if (supportsImageBitmapOptions) { + expect(window.createImageBitmap).toHaveBeenCalledWith(blob, { + imageOrientation: 'flipY' + }); + } else { + expect(window.createImageBitmap).toHaveBeenCalledWith(blob); + } - options.flipY = false; - window.createImageBitmap.calls.reset(); - return loadImageFromTypedArray(options); - }) - .then(function() { - if (FeatureDetection.supportsImageBitmapOptionsSync()) { - expect(window.createImageBitmap).toHaveBeenCalledWith(blob, { - imageOrientation: 'none' - }); - } else { - expect(window.createImageBitmap).toHaveBeenCalledWith(blob); - } - }); + options.flipY = false; + window.createImageBitmap.calls.reset(); + return loadImageFromTypedArray(options); + }) + .then(function() { + if (supportsImageBitmapOptions) { + expect(window.createImageBitmap).toHaveBeenCalledWith(blob, { + imageOrientation: 'none' + }); + } else { + expect(window.createImageBitmap).toHaveBeenCalledWith(blob); + } + }); }); it('can load an image when ImageBitmap is not supported', function() { diff --git a/Specs/Renderer/TextureSpec.js b/Specs/Renderer/TextureSpec.js index 99b3dc68e268..26e31c931cdf 100644 --- a/Specs/Renderer/TextureSpec.js +++ b/Specs/Renderer/TextureSpec.js @@ -58,43 +58,40 @@ defineSuite([ beforeAll(function() { context = createContext(); - return FeatureDetection.supportsImageBitmapOptions() - .then(function() { - var promises = []; - promises.push(Resource.fetchImage('./Data/Images/Green.png').then(function(image) { - greenImage = image; - })); - promises.push(Resource.fetchImage('./Data/Images/Blue.png').then(function(image) { - blueImage = image; - })); - promises.push(Resource.fetchImage('./Data/Images/BlueAlpha.png').then(function(image) { - blueAlphaImage = image; - })); - promises.push(Resource.fetchImage('./Data/Images/BlueOverRed.png').then(function(image) { - blueOverRedImage = image; - })); - // Turn off the default flipping. - promises.push(Resource.fetchImage({ - url: './Data/Images/BlueOverRed.png', - flipY: false - }).then(function(image) { - blueOverRedUnflippedImage = image; - })); - promises.push(Resource.fetchImage('./Data/Images/Red16x16.png').then(function(image) { - red16x16Image = image; - })); - promises.push(loadKTX('./Data/Images/Green4x4DXT1.ktx').then(function(image) { - greenDXTImage = image; - })); - promises.push(loadKTX('./Data/Images/Green4x4PVR.ktx').then(function(image) { - greenPVRImage = image; - })); - promises.push(loadKTX('./Data/Images/Green4x4ETC1.ktx').then(function(image) { - greenETC1Image = image; - })); - - return when.all(promises); - }); + var promises = []; + promises.push(Resource.fetchImage('./Data/Images/Green.png').then(function(image) { + greenImage = image; + })); + promises.push(Resource.fetchImage('./Data/Images/Blue.png').then(function(image) { + blueImage = image; + })); + promises.push(Resource.fetchImage('./Data/Images/BlueAlpha.png').then(function(image) { + blueAlphaImage = image; + })); + promises.push(Resource.fetchImage('./Data/Images/BlueOverRed.png').then(function(image) { + blueOverRedImage = image; + })); + // Turn off the default flipping. + promises.push(Resource.fetchImage({ + url: './Data/Images/BlueOverRed.png', + flipY: false + }).then(function(image) { + blueOverRedUnflippedImage = image; + })); + promises.push(Resource.fetchImage('./Data/Images/Red16x16.png').then(function(image) { + red16x16Image = image; + })); + promises.push(loadKTX('./Data/Images/Green4x4DXT1.ktx').then(function(image) { + greenDXTImage = image; + })); + promises.push(loadKTX('./Data/Images/Green4x4PVR.ktx').then(function(image) { + greenPVRImage = image; + })); + promises.push(loadKTX('./Data/Images/Green4x4ETC1.ktx').then(function(image) { + greenETC1Image = image; + })); + + return when.all(promises); }); afterAll(function() { @@ -202,37 +199,41 @@ defineSuite([ it('can flip texture only if ImageBitmapOptions is not supported', function() { var topColor = new Color(0.0, 0.0, 1.0, 1.0); var bottomColor = new Color(1.0, 0.0, 0.0, 1.0); - if (FeatureDetection.supportsImageBitmapOptionsSync()) { - // When imageBitmapOptions is supported, flipY on texture upload is ignored. - bottomColor = topColor; - } - texture = new Texture({ - context : context, - source : blueOverRedUnflippedImage, - pixelFormat : PixelFormat.RGBA, - flipY : false - }); + return Resource.supportsImageBitmapOptions() + .then(function(supportsImageBitmapOptions) { + if (supportsImageBitmapOptions) { + // When imageBitmapOptions is supported, flipY on texture upload is ignored. + bottomColor = topColor; + } - expect({ - context : context, - fragmentShader : fs, - uniformMap : uniformMap - }).contextToRender(topColor.toBytes()); + texture = new Texture({ + context : context, + source : blueOverRedUnflippedImage, + pixelFormat : PixelFormat.RGBA, + flipY : false + }); - // Flip the texture. - texture = new Texture({ - context : context, - source : blueOverRedUnflippedImage, - pixelFormat : PixelFormat.RGBA, - flipY : true - }); + expect({ + context : context, + fragmentShader : fs, + uniformMap : uniformMap + }).contextToRender(topColor.toBytes()); - expect({ - context : context, - fragmentShader : fs, - uniformMap : uniformMap - }).contextToRender(bottomColor.toBytes()); + // Flip the texture. + texture = new Texture({ + context : context, + source : blueOverRedUnflippedImage, + pixelFormat : PixelFormat.RGBA, + flipY : true + }); + + expect({ + context : context, + fragmentShader : fs, + uniformMap : uniformMap + }).contextToRender(bottomColor.toBytes()); + }); }); it('draws the expected floating-point texture color', function() { diff --git a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js index 7ba901a13cd8..9cc36109f138 100644 --- a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js +++ b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js @@ -55,7 +55,9 @@ defineSuite([ 'use strict'; beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); + // This suite spies on requests. The test below needs to make a request to a data URI. + // We run it here to avoid interfering with the tests. + return Resource.supportsImageBitmapOptions(); }); beforeEach(function() { @@ -214,8 +216,7 @@ defineSuite([ expect(provider.hasAlphaChannel).toBeDefined(); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { - // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. + if (/^blob:/.test(url)) { Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { expect(url).toEqual(getAbsoluteUri(baseUrl + 'tile/0/0/0')); diff --git a/Specs/Scene/BillboardCollectionSpec.js b/Specs/Scene/BillboardCollectionSpec.js index 9afcdfa9058c..5669be5e5666 100644 --- a/Specs/Scene/BillboardCollectionSpec.js +++ b/Specs/Scene/BillboardCollectionSpec.js @@ -8,7 +8,6 @@ defineSuite([ 'Core/Color', 'Core/createGuid', 'Core/DistanceDisplayCondition', - 'Core/FeatureDetection', 'Core/Math', 'Core/NearFarScalar', 'Core/OrthographicOffCenterFrustum', @@ -35,7 +34,6 @@ defineSuite([ Color, createGuid, DistanceDisplayCondition, - FeatureDetection, CesiumMath, NearFarScalar, OrthographicOffCenterFrustum, @@ -69,23 +67,20 @@ defineSuite([ context = scene.context; camera = scene.camera; - return FeatureDetection.supportsImageBitmapOptions() - .then(function() { - return when.join( - Resource.fetchImage('./Data/Images/Green2x2.png').then(function(result) { - greenImage = result; - }), - Resource.fetchImage('./Data/Images/Blue2x2.png').then(function(result) { - blueImage = result; - }), - Resource.fetchImage('./Data/Images/White2x2.png').then(function(result) { - whiteImage = result; - }), - Resource.fetchImage('./Data/Images/Blue10x10.png').then(function(result) { - largeBlueImage = result; - }) - ); - }); + return when.join( + Resource.fetchImage('./Data/Images/Green2x2.png').then(function(result) { + greenImage = result; + }), + Resource.fetchImage('./Data/Images/Blue2x2.png').then(function(result) { + blueImage = result; + }), + Resource.fetchImage('./Data/Images/White2x2.png').then(function(result) { + whiteImage = result; + }), + Resource.fetchImage('./Data/Images/Blue10x10.png').then(function(result) { + largeBlueImage = result; + }) + ); }); afterAll(function() { diff --git a/Specs/Scene/BingMapsImageryProviderSpec.js b/Specs/Scene/BingMapsImageryProviderSpec.js index faf273881718..0a4b093b6872 100644 --- a/Specs/Scene/BingMapsImageryProviderSpec.js +++ b/Specs/Scene/BingMapsImageryProviderSpec.js @@ -38,10 +38,6 @@ defineSuite([ Uri) { 'use strict'; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - beforeEach(function() { RequestScheduler.clearForSpecs(); }); diff --git a/Specs/Scene/DiscardMissingTileImagePolicySpec.js b/Specs/Scene/DiscardMissingTileImagePolicySpec.js index 85b207a0eeaf..78240aa879e7 100644 --- a/Specs/Scene/DiscardMissingTileImagePolicySpec.js +++ b/Specs/Scene/DiscardMissingTileImagePolicySpec.js @@ -14,15 +14,17 @@ defineSuite([ when) { 'use strict'; + beforeAll(function() { + // This suite spies on requests. The test below needs to make a request to a data URI. + // We run it here to avoid interfering with the tests. + return Resource.supportsImageBitmapOptions(); + }); + afterEach(function() { Resource._Implementations.createImage = Resource._DefaultImplementations.createImage; Resource._Implementations.loadWithXhr = Resource._DefaultImplementations.loadWithXhr; }); - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - describe('construction', function() { it('throws if missingImageUrl is not provided', function() { function constructWithoutMissingImageUrl() { @@ -45,9 +47,9 @@ defineSuite([ it('requests the missing image url', function() { var missingImageUrl = 'http://some.host.invalid/missingImage.png'; + spyOn(Resource._Implementations, 'createImageBitmapFromBlob').and.callThrough(); spyOn(Resource._Implementations, 'createImage').and.callFake(function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { - // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. + if (/^blob:/.test(url)) { Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { expect(url).toEqual(missingImageUrl); @@ -68,7 +70,12 @@ defineSuite([ return pollToPromise(function() { return policy.isReady(); }).then(function() { - expect(Resource._Implementations.createImage).toHaveBeenCalled(); + if (FeatureDetection.supportsCreateImageBitmap()) { + expect(Resource._Implementations.createImageBitmapFromBlob).toHaveBeenCalled(); + } else { + expect(Resource._Implementations.createImage).toHaveBeenCalled(); + } + }); }); }); diff --git a/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js index 7fde0a564c6c..b584b6580ad6 100644 --- a/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js @@ -4,7 +4,6 @@ defineSuite([ 'Core/DefaultProxy', 'Core/defaultValue', 'Core/defined', - 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/GoogleEarthEnterpriseMetadata', 'Core/GoogleEarthEnterpriseTileInformation', @@ -26,7 +25,6 @@ defineSuite([ DefaultProxy, defaultValue, defined, - FeatureDetection, GeographicTilingScheme, GoogleEarthEnterpriseMetadata, GoogleEarthEnterpriseTileInformation, @@ -50,7 +48,6 @@ defineSuite([ beforeAll(function() { decodeGoogleEarthEnterpriseData.passThroughDataForTesting = true; - return FeatureDetection.supportsImageBitmapOptions(); }); afterAll(function() { diff --git a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js index 3c5c7325ea24..4d7a67ca1005 100644 --- a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js @@ -30,10 +30,6 @@ defineSuite([ isImageOrImageBitmap) { 'use strict'; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - afterEach(function() { Resource._Implementations.createImage = Resource._DefaultImplementations.createImage; Resource._Implementations.loadWithXhr = Resource._DefaultImplementations.loadWithXhr; diff --git a/Specs/Scene/MapboxImageryProviderSpec.js b/Specs/Scene/MapboxImageryProviderSpec.js index eef7fbc1dd49..25e854bc4b62 100644 --- a/Specs/Scene/MapboxImageryProviderSpec.js +++ b/Specs/Scene/MapboxImageryProviderSpec.js @@ -1,7 +1,6 @@ defineSuite([ 'Scene/MapboxImageryProvider', 'Core/DefaultProxy', - 'Core/FeatureDetection', 'Core/Math', 'Core/Rectangle', 'Core/RequestScheduler', @@ -16,7 +15,6 @@ defineSuite([ ], function( MapboxImageryProvider, DefaultProxy, - FeatureDetection, CesiumMath, Rectangle, RequestScheduler, @@ -30,10 +28,6 @@ defineSuite([ isImageOrImageBitmap) { 'use strict'; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - beforeEach(function() { RequestScheduler.clearForSpecs(); }); diff --git a/Specs/Scene/SingleTileImageryProviderSpec.js b/Specs/Scene/SingleTileImageryProviderSpec.js index 1482014aed4d..62fba1eca3a1 100644 --- a/Specs/Scene/SingleTileImageryProviderSpec.js +++ b/Specs/Scene/SingleTileImageryProviderSpec.js @@ -2,7 +2,6 @@ defineSuite([ 'Scene/SingleTileImageryProvider', 'Core/DefaultProxy', 'Core/Ellipsoid', - 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/Rectangle', 'Core/Resource', @@ -17,7 +16,6 @@ defineSuite([ SingleTileImageryProvider, DefaultProxy, Ellipsoid, - FeatureDetection, GeographicTilingScheme, Rectangle, Resource, @@ -30,10 +28,6 @@ defineSuite([ when) { 'use strict'; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - afterEach(function() { Resource._Implementations.createImage = Resource._DefaultImplementations.createImage; }); diff --git a/Specs/Scene/TextureAtlasSpec.js b/Specs/Scene/TextureAtlasSpec.js index ef47f4b813b5..54628701f747 100644 --- a/Specs/Scene/TextureAtlasSpec.js +++ b/Specs/Scene/TextureAtlasSpec.js @@ -3,7 +3,6 @@ defineSuite([ 'Core/BoundingRectangle', 'Core/Cartesian2', 'Core/createGuid', - 'Core/FeatureDetection', 'Core/Math', 'Core/PixelFormat', 'Core/Resource', @@ -14,7 +13,6 @@ defineSuite([ BoundingRectangle, Cartesian2, createGuid, - FeatureDetection, CesiumMath, PixelFormat, Resource, @@ -40,29 +38,26 @@ defineSuite([ guidArray.push(createGuid()); } - return FeatureDetection.supportsImageBitmapOptions() - .then(function() { - return when.join( - Resource.fetchImage('./Data/Images/Green.png').then(function(image) { - greenImage = image; - }), - Resource.fetchImage('./Data/Images/Green1x4.png').then(function(image) { - tallGreenImage = image; - }), - Resource.fetchImage('./Data/Images/Blue.png').then(function(image) { - blueImage = image; - }), - Resource.fetchImage('./Data/Images/Red16x16.png').then(function(image) { - bigRedImage = image; - }), - Resource.fetchImage('./Data/Images/Blue10x10.png').then(function(image) { - bigBlueImage = image; - }), - Resource.fetchImage('./Data/Images/Green4x4.png').then(function(image) { - bigGreenImage = image; - }) - ); - }); + return when.join( + Resource.fetchImage('./Data/Images/Green.png').then(function(image) { + greenImage = image; + }), + Resource.fetchImage('./Data/Images/Green1x4.png').then(function(image) { + tallGreenImage = image; + }), + Resource.fetchImage('./Data/Images/Blue.png').then(function(image) { + blueImage = image; + }), + Resource.fetchImage('./Data/Images/Red16x16.png').then(function(image) { + bigRedImage = image; + }), + Resource.fetchImage('./Data/Images/Blue10x10.png').then(function(image) { + bigBlueImage = image; + }), + Resource.fetchImage('./Data/Images/Green4x4.png').then(function(image) { + bigGreenImage = image; + }) + ); }); afterAll(function() { diff --git a/Specs/Scene/UrlTemplateImageryProviderSpec.js b/Specs/Scene/UrlTemplateImageryProviderSpec.js index 8158ccc3797a..0c33d8305d47 100644 --- a/Specs/Scene/UrlTemplateImageryProviderSpec.js +++ b/Specs/Scene/UrlTemplateImageryProviderSpec.js @@ -2,7 +2,6 @@ defineSuite([ 'Scene/UrlTemplateImageryProvider', 'Core/DefaultProxy', 'Core/Ellipsoid', - 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/Math', 'Core/Rectangle', @@ -22,7 +21,6 @@ defineSuite([ UrlTemplateImageryProvider, DefaultProxy, Ellipsoid, - FeatureDetection, GeographicTilingScheme, CesiumMath, Rectangle, @@ -40,10 +38,6 @@ defineSuite([ when) { 'use strict'; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - beforeEach(function() { RequestScheduler.clearForSpecs(); }); diff --git a/Specs/Scene/WebMapServiceImageryProviderSpec.js b/Specs/Scene/WebMapServiceImageryProviderSpec.js index 94d59764d672..d2b6312d2d8f 100644 --- a/Specs/Scene/WebMapServiceImageryProviderSpec.js +++ b/Specs/Scene/WebMapServiceImageryProviderSpec.js @@ -5,7 +5,6 @@ defineSuite([ 'Core/ClockStep', 'Core/DefaultProxy', 'Core/Ellipsoid', - 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/JulianDate', 'Core/Math', @@ -33,7 +32,6 @@ defineSuite([ ClockStep, DefaultProxy, Ellipsoid, - FeatureDetection, GeographicTilingScheme, JulianDate, CesiumMath, @@ -56,10 +54,6 @@ defineSuite([ Uri) { 'use strict'; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - beforeEach(function() { RequestScheduler.clearForSpecs(); }); diff --git a/Specs/Scene/WebMapTileServiceImageryProviderSpec.js b/Specs/Scene/WebMapTileServiceImageryProviderSpec.js index d06d28f6322d..cdff245bf81d 100644 --- a/Specs/Scene/WebMapTileServiceImageryProviderSpec.js +++ b/Specs/Scene/WebMapTileServiceImageryProviderSpec.js @@ -4,7 +4,6 @@ defineSuite([ 'Core/ClockStep', 'Core/Credit', 'Core/DefaultProxy', - 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/JulianDate', 'Core/objectToQuery', @@ -28,7 +27,6 @@ defineSuite([ ClockStep, Credit, DefaultProxy, - FeatureDetection, GeographicTilingScheme, JulianDate, objectToQuery, @@ -48,10 +46,6 @@ defineSuite([ Uri) { 'use strict'; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - beforeEach(function() { RequestScheduler.clearForSpecs(); }); diff --git a/Specs/Scene/createOpenStreetMapImageryProviderSpec.js b/Specs/Scene/createOpenStreetMapImageryProviderSpec.js index 3d6c327a4f58..e097ceff92d2 100644 --- a/Specs/Scene/createOpenStreetMapImageryProviderSpec.js +++ b/Specs/Scene/createOpenStreetMapImageryProviderSpec.js @@ -1,7 +1,6 @@ defineSuite([ 'Scene/createOpenStreetMapImageryProvider', 'Core/DefaultProxy', - 'Core/FeatureDetection', 'Core/Math', 'Core/Rectangle', 'Core/RequestScheduler', @@ -16,7 +15,6 @@ defineSuite([ ], function( createOpenStreetMapImageryProvider, DefaultProxy, - FeatureDetection, CesiumMath, Rectangle, RequestScheduler, @@ -30,10 +28,6 @@ defineSuite([ isImageOrImageBitmap) { 'use strict'; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - beforeEach(function() { RequestScheduler.clearForSpecs(); }); diff --git a/Specs/Scene/createTileMapServiceImageryProviderSpec.js b/Specs/Scene/createTileMapServiceImageryProviderSpec.js index f32f7866adf0..e813f76e3f2b 100644 --- a/Specs/Scene/createTileMapServiceImageryProviderSpec.js +++ b/Specs/Scene/createTileMapServiceImageryProviderSpec.js @@ -3,7 +3,6 @@ defineSuite([ 'Core/Cartesian2', 'Core/Cartographic', 'Core/DefaultProxy', - 'Core/FeatureDetection', 'Core/GeographicProjection', 'Core/GeographicTilingScheme', 'Core/getAbsoluteUri', @@ -25,7 +24,6 @@ defineSuite([ Cartesian2, Cartographic, DefaultProxy, - FeatureDetection, GeographicProjection, GeographicTilingScheme, getAbsoluteUri, @@ -44,10 +42,6 @@ defineSuite([ when) { 'use strict'; - beforeAll(function() { - return FeatureDetection.supportsImageBitmapOptions(); - }); - beforeEach(function() { RequestScheduler.clearForSpecs(); }); From 13e90126c733b1d1ce9b2eb6112efedae8bbb58e Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Wed, 20 Feb 2019 18:30:16 -0500 Subject: [PATCH 30/71] Fix missed comment changes --- Apps/Sandcastle/gallery/development/Polyline.html | 2 +- Apps/Sandcastle/gallery/development/Simple Polyline.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Apps/Sandcastle/gallery/development/Polyline.html b/Apps/Sandcastle/gallery/development/Polyline.html index 690b0eb74a92..f7b2ba49a975 100644 --- a/Apps/Sandcastle/gallery/development/Polyline.html +++ b/Apps/Sandcastle/gallery/development/Polyline.html @@ -52,7 +52,7 @@ // Example 2: Draw a straight blue polyline -// Setting the arcType option to false will allow +// Setting the arcType option to ArcType.NONE will allow // you to draw a straight polyline. Otherwise, it will // curve to the globe surface. scene.primitives.add(new Cesium.Primitive({ diff --git a/Apps/Sandcastle/gallery/development/Simple Polyline.html b/Apps/Sandcastle/gallery/development/Simple Polyline.html index 61324bc37d68..26f214227ec9 100644 --- a/Apps/Sandcastle/gallery/development/Simple Polyline.html +++ b/Apps/Sandcastle/gallery/development/Simple Polyline.html @@ -53,7 +53,7 @@ } // For per segment coloring, provide the colors options with an // array of colors where the length is equal to the number of positions. -// Setting arcType to false will draw straight lines. +// Setting arcType to ArcType.NONE will draw straight lines. // Otherwise, the polyline curves to the surface of the globe. var perSegmentPolyline = new Cesium.GeometryInstance({ geometry : new Cesium.SimplePolylineGeometry({ From f4ab9748e96c8aac753e3f67adb68a1667591f69 Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Wed, 20 Feb 2019 18:30:25 -0500 Subject: [PATCH 31/71] Revert "Update changes.md" This reverts commit 7f3aa0a5e0d742c675de2b452b25c703cbcad0a8. --- CHANGES.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1bf5bed856fe..e1465f5fdadc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,6 @@ Change Log ##### Additions :tada: * `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). -* Added support for `arcType` to CZML Data Source. [#7582](https://github.com/AnalyticalGraphicsInc/cesium/issues/7582) ##### Fixes :wrench: * Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383) @@ -20,7 +19,6 @@ Change Log * Fixed model silhouette colors when rendering with high dynamic range. [#7563](https://github.com/AnalyticalGraphicsInc/cesium/pull/7563) * Fixed an issue with ground polylines on globes that use ellipsoids other than WGS84. [#7552](https://github.com/AnalyticalGraphicsInc/cesium/issues/7552) * Fixed an issue where Draco compressed models with RGB per-vertex color would not load in Cesium. [#7576](https://github.com/AnalyticalGraphicsInc/cesium/issues/7576) -* Changed usage of deprecated property `followSurface` to use `arcType`. [#7572](https://github.com/AnalyticalGraphicsInc/cesium/issues/7572) ### 1.54 - 2019-02-01 From d0653e1878e7c67cdcb8e2a7125af2f19cfeb35d Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Wed, 20 Feb 2019 18:33:33 -0500 Subject: [PATCH 32/71] Add compatibity from polyline.followSurface to polyline.arcType --- Source/DataSources/CzmlDataSource.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index 96eba71a80c2..0506084c17a9 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -1800,8 +1800,17 @@ define([ processPacketData(Number, polyline, 'granularity', polylineData.granularity, interval, sourceUri, entityCollection); processMaterialPacketData(polyline, 'material', polylineData.material, interval, sourceUri, entityCollection); processMaterialPacketData(polyline, 'depthFailMaterial', polylineData.depthFailMaterial, interval, sourceUri, entityCollection); - processPacketData(Boolean, polyline, 'followSurface', polylineData.followSurface, interval, sourceUri, entityCollection); - processPacketData(ArcType, polyline, 'arcType', polylineData.arcType, interval, sourceUri, entityCollection); + // Don't want to break CZML spec to keep this workaround even after followSurface has been deprecated from geometry. + // See https://github.com/AnalyticalGraphicsInc/cesium/pull/7582#discussion_r258695385 + if (defined(polylineData.followSurface) && !defined(polylineData.arcType)) { + if (polyline.followSurface) { + processPacketData(ArcType, polyline, 'arcType', ArcType.GEODESIC, interval, sourceUri, entityCollection); + } else { + processPacketData(ArcType, polyline, 'arcType', ArcType.NONE, interval, sourceUri, entityCollection); + } + } else { + processPacketData(ArcType, polyline, 'arcType', polylineData.arcType, interval, sourceUri, entityCollection); + } processPacketData(Boolean, polyline, 'clampToGround', polylineData.clampToGround, interval, sourceUri, entityCollection); processPacketData(ShadowMode, polyline, 'shadows', polylineData.shadows, interval, sourceUri, entityCollection); processPacketData(DistanceDisplayCondition, polyline, 'distanceDisplayCondition', polylineData.distanceDisplayCondition, interval, sourceUri, entityCollection); From 0cbd2d3bc68bef6fcd994bf7e1ff71739e689aba Mon Sep 17 00:00:00 2001 From: Shehzan Mohammed Date: Wed, 20 Feb 2019 18:39:17 -0500 Subject: [PATCH 33/71] Add arcType property to CZML's polygon process --- Source/DataSources/CzmlDataSource.js | 1 + Specs/Data/CZML/ValidationDocument.czml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index 0506084c17a9..44f6d1318731 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -1771,6 +1771,7 @@ define([ processPacketData(Boolean, polygon, 'perPositionHeight', polygonData.perPositionHeight, interval, sourceUri, entityCollection); processPacketData(Boolean, polygon, 'closeTop', polygonData.closeTop, interval, sourceUri, entityCollection); processPacketData(Boolean, polygon, 'closeBottom', polygonData.closeBottom, interval, sourceUri, entityCollection); + processPacketData(ArcType, polygon, 'arcType', polygonData.arcType, interval, sourceUri, entityCollection); processPacketData(ShadowMode, polygon, 'shadows', polygonData.shadows, interval, sourceUri, entityCollection); processPacketData(DistanceDisplayCondition, polygon, 'distanceDisplayCondition', polygonData.distanceDisplayCondition, interval, sourceUri, entityCollection); processPacketData(Number, polygon, 'zIndex', polygonData.zIndex, interval, sourceUri, entityCollection); diff --git a/Specs/Data/CZML/ValidationDocument.czml b/Specs/Data/CZML/ValidationDocument.czml index 8b959a351d2e..e012e00a4278 100644 --- a/Specs/Data/CZML/ValidationDocument.czml +++ b/Specs/Data/CZML/ValidationDocument.czml @@ -449,6 +449,7 @@ "perPositionHeight":true, "closeTop":true, "closeBottom":true, + "arcType":"GEODESIC", "shadows":"CAST_ONLY", "distanceDisplayCondition":{ "distanceDisplayCondition":[ @@ -6281,6 +6282,9 @@ "closeBottom":{ "reference":"Constant#polygon.closeBottom" }, + "arcType":{ + "reference":"Constant#polygon.arcType" + }, "shadows":{ "reference":"Constant#polygon.shadows" }, From 9e7fea4882a8484b155d4bc69ace9177bd62d63a Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Thu, 21 Feb 2019 13:07:32 -0500 Subject: [PATCH 34/71] Cleanup ImageBitmap implementation --- CHANGES.md | 2 +- Source/Core/FeatureDetection.js | 7 +- Source/Core/IonResource.js | 9 +- Source/Core/Resource.js | 58 ++++---- Source/Core/loadImageFromTypedArray.js | 6 +- Source/Scene/DiscardMissingTileImagePolicy.js | 4 +- .../DiscardMissingTileImagePolicySpec.js | 1 - Specs/Scene/TextureAtlasSpec.js | 132 +++++++++--------- 8 files changed, 109 insertions(+), 110 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6fade07e29d5..5ed21d4e7602 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,10 +5,10 @@ Change Log ##### Breaking Changes :mega: * `czm_materialInput.slope` is now an angle in radians between 0 and pi/2 (flat to vertical), rather than a projected length 1 to 0 (flat to vertical). +* `Resource.fetchImage` now returns an `ImageBitmap` instead of `Image` when supported. This allows for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode when `ImageBitmapOptions` are supported since an `ImageBitmap` cannot be vertically flipped during texture upload. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) ##### Additions :tada: * `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). -* Add support for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode when `ImageBitmapOptions` are supported since an `ImageBitmap` cannot be vertically flipped during texture upload. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) ##### Deprecated :hourglass_flowing_sand: * `Resource.fetchImage` now takes an options object. Use `resource.fetchImage({ preferBlob: true })` instead of `resource.fetchImage(true)`. The previous function definition will no longer work in 1.56. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) diff --git a/Source/Core/FeatureDetection.js b/Source/Core/FeatureDetection.js index cd0d56800b13..9d982e34bce9 100644 --- a/Source/Core/FeatureDetection.js +++ b/Source/Core/FeatureDetection.js @@ -253,13 +253,8 @@ define([ } } - var supportsCreateImageBitmapResult; function supportsCreateImageBitmap() { - if (!defined(supportsCreateImageBitmapResult)) { - supportsCreateImageBitmapResult = defined(window.createImageBitmap); - } - - return supportsCreateImageBitmapResult; + return typeof createImageBitmap === 'function'; } /** diff --git a/Source/Core/IonResource.js b/Source/Core/IonResource.js index b474f26ca857..4a629d563b3b 100644 --- a/Source/Core/IonResource.js +++ b/Source/Core/IonResource.js @@ -166,8 +166,13 @@ define([ IonResource.prototype.fetchImage = function (options) { if (!this._isExternal) { - options = defaultValue(options, {}); - options.preferBlob = true; + var userOptions = options; + options = { + preferBlob : true + }; + if (defined(userOptions)) { + options.flipY = userOptions.flipY; + } } return Resource.prototype.fetchImage.call(this, options); diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index 6b315d048367..304c574b9a6d 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -389,34 +389,32 @@ define([ // know if this browser supports passing options to the createImageBitmap function. // https://github.com/whatwg/html/pull/4248 if (defined(supportsImageBitmapOptionsPromise)) { - return supportsImageBitmapOptionsPromise.promise; + return supportsImageBitmapOptionsPromise; } - supportsImageBitmapOptionsPromise = when.defer(); - if (!FeatureDetection.supportsCreateImageBitmap()) { - supportsImageBitmapOptionsPromise.resolve(false); - return supportsImageBitmapOptionsPromise.promise; + supportsImageBitmapOptionsPromise = when.resolve(false); + return supportsImageBitmapOptionsPromise; } var imageDataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWP4////fwAJ+wP9CNHoHgAAAABJRU5ErkJggg=='; - Resource.fetchBlob({ + supportsImageBitmapOptionsPromise = Resource.fetchBlob({ url : imageDataUri }) .then(function(blob) { - return when(createImageBitmap(blob, { + return createImageBitmap(blob, { imageOrientation: 'flipY' - })); + }); }) .then(function(imageBitmap) { - supportsImageBitmapOptionsPromise.resolve(true); + return true; }) .otherwise(function() { - supportsImageBitmapOptionsPromise.resolve(false); + return false; }); - return supportsImageBitmapOptionsPromise.promise; + return supportsImageBitmapOptionsPromise; }; defineProperties(Resource, { @@ -875,10 +873,10 @@ define([ * an {@link https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap|ImageBitmap} if the browser supports `createImageBitmap` or otherwise an * {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement|Image} once loaded, or reject if the image failed to load. * - * @param {String|Object} options An object with the following properties. + * @param {Object} [options] An object with the following properties. * @param {Boolean} [options.preferBlob=false] If true, we will load the image via a blob. * @param {Boolean} [options.flipY=true] If true, image will be vertially flipped during decode. Only applies if the browser supports `createImageBitmap`. - * @returns {Promise.|Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. + * @returns {Promise.|Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. * * * @example @@ -898,13 +896,13 @@ define([ * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} */ Resource.prototype.fetchImage = function (options) { - if (defined(options) && typeof options === 'boolean') { + if (typeof options === 'boolean') { deprecationWarning('fetchImage-parameter-change', 'fetchImage now takes an options object in CesiumJS 1.55. Use resource.fetchImage({ preferBlob: true }) instead of resource.fetchImage(true).'); options = { preferBlob : options }; } - options = defaultValue(options, {}); + options = defaultValue(options, defaultValue.EMPTY_OBJECT); var preferBlob = defaultValue(options.preferBlob, false); var flipY = defaultValue(options.flipY, true); @@ -927,9 +925,7 @@ define([ if (FeatureDetection.supportsCreateImageBitmap()) { return blobPromise .then(function(blob) { - var deferred = when.defer(); - Resource._Implementations.createImageBitmapFromBlob(blob, deferred, flipY); - return deferred; + return Resource._Implementations.createImageBitmapFromBlob(blob, flipY); }); } @@ -1029,7 +1025,7 @@ define([ * @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up. * @param {Request} [options.request] A Request object that will be used. Intended for internal use only. * @param {Boolean} [options.preferBlob = false] If true, we will load the image via a blob. - * @returns {Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. + * @returns {Promise.|Promise.|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if request.throttle is true and the request does not have high enough priority. */ Resource.fetchImage = function (options) { var resource = new Resource(options); @@ -1847,28 +1843,30 @@ define([ image.src = url; } else { - // createImageBitmap will block the main thread during decode if a blob is not supplied. + // Passing an Image to createImageBitmap will force it to run on the main thread + // since DOM elements don't exist on workers. We convert it to a blob so it's non-blocking. + // See: + // https://bugzilla.mozilla.org/show_bug.cgi?id=1044102#c38 + // https://bugs.chromium.org/p/chromium/issues/detail?id=580202#c10 Resource.fetchBlob({ url: url }).then(function(blob) { - Resource._Implementations.createImageBitmapFromBlob(blob, deferred, flipY); - }).otherwise(deferred.reject); + return Resource._Implementations.createImageBitmapFromBlob(blob, flipY); + }).then(deferred.resolve).otherwise(deferred.reject); } }; - Resource._Implementations.createImageBitmapFromBlob = function(blob, deferred, flipY) { - Resource.supportsImageBitmapOptions() + Resource._Implementations.createImageBitmapFromBlob = function(blob, flipY) { + return Resource.supportsImageBitmapOptions() .then(function(supportsBitmapOptions) { if (!supportsBitmapOptions) { - return when(createImageBitmap(blob)); + return createImageBitmap(blob); } - return when(createImageBitmap(blob, { + return createImageBitmap(blob, { imageOrientation: flipY ? 'flipY' : 'none' - })); - }) - .then(deferred.resolve) - .otherwise(deferred.reject); + }); + }); }; function decodeResponse(loadWithHttpResponse, responseType) { diff --git a/Source/Core/loadImageFromTypedArray.js b/Source/Core/loadImageFromTypedArray.js index 987fc07ae461..7ae09f8a30c8 100644 --- a/Source/Core/loadImageFromTypedArray.js +++ b/Source/Core/loadImageFromTypedArray.js @@ -37,12 +37,12 @@ define([ return Resource.supportsImageBitmapOptions() .then(function(supportsBitmapOptions) { if (supportsBitmapOptions) { - return when(createImageBitmap(blob, { + return createImageBitmap(blob, { imageOrientation: flipY ? 'flipY' : 'none' - })); + }); } - return when(createImageBitmap(blob)); + return createImageBitmap(blob); }); } diff --git a/Source/Scene/DiscardMissingTileImagePolicy.js b/Source/Scene/DiscardMissingTileImagePolicy.js index a8da9e33f071..83c268243026 100644 --- a/Source/Scene/DiscardMissingTileImagePolicy.js +++ b/Source/Scene/DiscardMissingTileImagePolicy.js @@ -89,9 +89,9 @@ define([ that._isReady = true; } - when(resource.fetchImage({ + resource.fetchImage({ preferBlob : true - }), success, failure); + }).then(success).otherwise(failure); } /** diff --git a/Specs/Scene/DiscardMissingTileImagePolicySpec.js b/Specs/Scene/DiscardMissingTileImagePolicySpec.js index 78240aa879e7..d84d40a3a03d 100644 --- a/Specs/Scene/DiscardMissingTileImagePolicySpec.js +++ b/Specs/Scene/DiscardMissingTileImagePolicySpec.js @@ -75,7 +75,6 @@ defineSuite([ } else { expect(Resource._Implementations.createImage).toHaveBeenCalled(); } - }); }); }); diff --git a/Specs/Scene/TextureAtlasSpec.js b/Specs/Scene/TextureAtlasSpec.js index 54628701f747..b22948eb0096 100644 --- a/Specs/Scene/TextureAtlasSpec.js +++ b/Specs/Scene/TextureAtlasSpec.js @@ -28,36 +28,42 @@ defineSuite([ var bigRedImage; var bigBlueImage; var bigGreenImage; - var guidArray; + + var greenGuid; + var tallGreenGuid; + var blueGuid; + var bigRedGuid; + var bigBlueGuid; + var bigGreenGuid; beforeAll(function() { scene = createScene(); - // Create enough guid's to use throughout these tests. - guidArray = []; - for (var i = 0; i < 4; ++i) { - guidArray.push(createGuid()); - } return when.join( Resource.fetchImage('./Data/Images/Green.png').then(function(image) { greenImage = image; + greenGuid = createGuid(); }), Resource.fetchImage('./Data/Images/Green1x4.png').then(function(image) { tallGreenImage = image; + tallGreenGuid = createGuid(); }), Resource.fetchImage('./Data/Images/Blue.png').then(function(image) { blueImage = image; + blueGuid = createGuid(); }), Resource.fetchImage('./Data/Images/Red16x16.png').then(function(image) { bigRedImage = image; + bigRedGuid = createGuid(); }), Resource.fetchImage('./Data/Images/Blue10x10.png').then(function(image) { bigBlueImage = image; + bigBlueGuid = createGuid(); }), Resource.fetchImage('./Data/Images/Green4x4.png').then(function(image) { bigGreenImage = image; - }) - ); + bigGreenGuid = createGuid(); + })); }); afterAll(function() { @@ -96,7 +102,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(guidArray[0], greenImage).then(function(index) { + return atlas.addImage(greenGuid, greenImage).then(function(index) { expect(index).toEqual(0); expect(atlas.numberOfImages).toEqual(1); @@ -124,7 +130,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(guidArray[0], greenImage).then(function(index) { + return atlas.addImage(greenGuid, greenImage).then(function(index) { var texture = atlas.texture; var coords = atlas.textureCoordinates[index]; @@ -137,7 +143,7 @@ defineSuite([ context : scene.context }); - return atlas.addImage(guidArray[0], greenImage).then(function(index) { + return atlas.addImage(greenGuid, greenImage).then(function(index) { expect(index).toEqual(0); expect(atlas.numberOfImages).toEqual(1); @@ -164,7 +170,7 @@ defineSuite([ context : scene.context }); - return atlas.addImage(guidArray[0], greenImage).then(function(index) { + return atlas.addImage(greenGuid, greenImage).then(function(index) { var texture = atlas.texture; var coords = atlas.textureCoordinates[index]; @@ -179,7 +185,7 @@ defineSuite([ initialSize : new Cartesian2(1.0, 5.0) }); - return atlas.addImage(guidArray[0], tallGreenImage).then(function(index) { + return atlas.addImage(tallGreenGuid, tallGreenImage).then(function(index) { expect(index).toEqual(0); expect(atlas.numberOfImages).toEqual(1); @@ -206,7 +212,7 @@ defineSuite([ initialSize : new Cartesian2(1.0, 5.0) }); - return atlas.addImage(guidArray[0], tallGreenImage).then(function(index) { + return atlas.addImage(tallGreenGuid, tallGreenImage).then(function(index) { var texture = atlas.texture; var coords = atlas.textureCoordinates[index]; @@ -222,8 +228,8 @@ defineSuite([ }); var promises = []; - promises.push(atlas.addImage(guidArray[0], greenImage)); - promises.push(atlas.addImage(guidArray[1], blueImage)); + promises.push(atlas.addImage(greenGuid, greenImage)); + promises.push(atlas.addImage(blueGuid, blueImage)); return when.all(promises, function(indices) { var greenIndex = indices[0]; @@ -259,8 +265,8 @@ defineSuite([ }); var promises = []; - promises.push(atlas.addImage(guidArray[0], greenImage)); - promises.push(atlas.addImage(guidArray[1], blueImage)); + promises.push(atlas.addImage(greenGuid, greenImage)); + promises.push(atlas.addImage(blueGuid, blueImage)); return when.all(promises, function(indices) { var greenIndex = indices[0]; @@ -283,10 +289,10 @@ defineSuite([ }); var promises = []; - promises.push(atlas.addImage(guidArray[0], greenImage)); - promises.push(atlas.addImage(guidArray[1], blueImage)); - promises.push(atlas.addImage(guidArray[2], bigRedImage)); - promises.push(atlas.addImage(guidArray[3], bigBlueImage)); + promises.push(atlas.addImage(greenGuid, greenImage)); + promises.push(atlas.addImage(blueGuid, blueImage)); + promises.push(atlas.addImage(bigRedGuid, bigRedImage)); + promises.push(atlas.addImage(bigBlueGuid, bigBlueImage)); return when.all(promises, function(indices) { var greenIndex = indices.shift(); @@ -316,10 +322,10 @@ defineSuite([ }); var promises = []; - promises.push(atlas.addImage(guidArray[0], greenImage)); - promises.push(atlas.addImage(guidArray[1], blueImage)); - promises.push(atlas.addImage(guidArray[2], bigRedImage)); - promises.push(atlas.addImage(guidArray[3], bigBlueImage)); + promises.push(atlas.addImage(greenGuid, greenImage)); + promises.push(atlas.addImage(blueGuid, blueImage)); + promises.push(atlas.addImage(bigRedGuid, bigRedImage)); + promises.push(atlas.addImage(bigBlueGuid, bigBlueImage)); return when.all(promises, function(indices) { var greenIndex = indices.shift(); @@ -370,10 +376,10 @@ defineSuite([ }); var promises = []; - promises.push(atlas.addImage(guidArray[0], greenImage)); - promises.push(atlas.addImage(guidArray[1], blueImage)); - promises.push(atlas.addImage(guidArray[2], bigRedImage)); - promises.push(atlas.addImage(guidArray[3], bigBlueImage)); + promises.push(atlas.addImage(greenGuid, greenImage)); + promises.push(atlas.addImage(blueGuid, blueImage)); + promises.push(atlas.addImage(bigRedGuid, bigRedImage)); + promises.push(atlas.addImage(bigBlueGuid, bigBlueImage)); return when.all(promises, function(indices) { var greenIndex = indices.shift(); @@ -403,7 +409,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(guidArray[0], blueImage).then(function(blueIndex) { + return atlas.addImage(blueGuid, blueImage).then(function(blueIndex) { expect(atlas.numberOfImages).toEqual(1); var texture = atlas.texture; @@ -421,7 +427,7 @@ defineSuite([ expect(coordinates[blueIndex].height).toEqual(1.0 / atlasHeight); //Add the big green image - return atlas.addImage(guidArray[1], bigGreenImage).then(function(greenIndex) { + return atlas.addImage(bigGreenGuid, bigGreenImage).then(function(greenIndex) { expect(atlas.numberOfImages).toEqual(2); var texture = atlas.texture; @@ -454,7 +460,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(guidArray[0], blueImage).then(function(blueIndex) { + return atlas.addImage(blueGuid, blueImage).then(function(blueIndex) { expect(atlas.numberOfImages).toEqual(1); var texture = atlas.texture; @@ -463,7 +469,7 @@ defineSuite([ var blueCoords = coordinates[blueIndex]; expectToRender(texture, blueCoords, [0, 0, 255, 255]); - return atlas.addImage(guidArray[1], bigGreenImage).then(function(greenIndex) { + return atlas.addImage(bigGreenGuid, bigGreenImage).then(function(greenIndex) { expect(atlas.numberOfImages).toEqual(2); var texture = atlas.texture; @@ -485,7 +491,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(guidArray[0], bigRedImage).then(function(index) { + return atlas.addImage(bigRedGuid, bigRedImage).then(function(index) { expect(atlas.numberOfImages).toEqual(1); var texture = atlas.texture; @@ -510,7 +516,7 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - return atlas.addImage(guidArray[0], bigRedImage).then(function(index) { + return atlas.addImage(bigRedGuid, bigRedImage).then(function(index) { var texture = atlas.texture; var coords = atlas.textureCoordinates[index]; @@ -525,8 +531,8 @@ defineSuite([ initialSize : new Cartesian2(2, 2) }); - var greenPromise = atlas.addImage(guidArray[0], greenImage); - var bluePromise = atlas.addImage(guidArray[1], blueImage); + var greenPromise = atlas.addImage(greenGuid, greenImage); + var bluePromise = atlas.addImage(blueGuid, blueImage); return when.all([greenPromise, bluePromise], function(indices) { var greenIndex = indices.shift(); @@ -561,8 +567,8 @@ defineSuite([ initialSize : new Cartesian2(2, 2) }); - var greenPromise = atlas.addImage(guidArray[0], greenImage); - var bluePromise = atlas.addImage(guidArray[1], blueImage); + var greenPromise = atlas.addImage(greenGuid, greenImage); + var bluePromise = atlas.addImage(blueGuid, blueImage); return when.all([greenPromise, bluePromise], function(indices) { var greenIndex = indices.shift(); @@ -586,7 +592,7 @@ defineSuite([ initialSize : new Cartesian2(1.0, 1.0) }); - return atlas.addImage(guidArray[0], tallGreenImage).then(function(index) { + return atlas.addImage(tallGreenGuid, tallGreenImage).then(function(index) { expect(atlas.numberOfImages).toEqual(1); var texture = atlas.texture; @@ -611,7 +617,7 @@ defineSuite([ initialSize : new Cartesian2(1.0, 1.0) }); - return atlas.addImage(guidArray[0], tallGreenImage).then(function(index) { + return atlas.addImage(tallGreenGuid, tallGreenImage).then(function(index) { var texture = atlas.texture; var coords = atlas.textureCoordinates[index]; @@ -626,9 +632,9 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - var bluePromise = atlas.addImage(guidArray[0], blueImage); - var bigGreenPromise = atlas.addImage(guidArray[1], bigGreenImage); - var bigRedPromise = atlas.addImage(guidArray[2], bigRedImage); + var bluePromise = atlas.addImage(blueGuid, blueImage); + var bigGreenPromise = atlas.addImage(bigGreenGuid, bigGreenImage); + var bigRedPromise = atlas.addImage(bigRedGuid, bigRedImage); return when.all([bluePromise, bigGreenPromise, bigRedPromise], function(indices) { var blueIndex = indices.shift(); @@ -653,13 +659,13 @@ defineSuite([ initialSize : new Cartesian2(4, 4) }); - return atlas.addImage(guidArray[0], blueImage).then(function(blueIndex) { + return atlas.addImage(blueGuid, blueImage).then(function(blueIndex) { expect(blueIndex).toEqual(0); - return atlas.addImage(guidArray[1], greenImage).then(function(greenIndex) { + return atlas.addImage(greenGuid, greenImage).then(function(greenIndex) { expect(greenIndex).toEqual(1); - return atlas.addImage(guidArray[0], blueImage).then(function(index) { + return atlas.addImage(blueGuid, blueImage).then(function(index) { expect(index).toEqual(blueIndex); expect(atlas.numberOfImages).toEqual(2); @@ -684,14 +690,12 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - var id = guidArray[0]; - - atlas.addImage(id, greenImage); + atlas.addImage(greenGuid, greenImage); - var promise1 = atlas.addSubRegion(id, new BoundingRectangle(0.0, 0.0, 0.5, 0.5)); - var promise2 = atlas.addSubRegion(id, new BoundingRectangle(0.0, 0.5, 0.5, 0.5)); - var promise3 = atlas.addSubRegion(id, new BoundingRectangle(0.5, 0.0, 0.5, 0.5)); - var promise4 = atlas.addSubRegion(id, new BoundingRectangle(0.5, 0.5, 0.5, 0.5)); + var promise1 = atlas.addSubRegion(greenGuid, new BoundingRectangle(0.0, 0.0, 0.5, 0.5)); + var promise2 = atlas.addSubRegion(greenGuid, new BoundingRectangle(0.0, 0.5, 0.5, 0.5)); + var promise3 = atlas.addSubRegion(greenGuid, new BoundingRectangle(0.5, 0.0, 0.5, 0.5)); + var promise4 = atlas.addSubRegion(greenGuid, new BoundingRectangle(0.5, 0.5, 0.5, 0.5)); return when.all([promise1, promise2, promise3, promise4], function(indices) { var index1 = indices.shift(); @@ -734,14 +738,12 @@ defineSuite([ initialSize : new Cartesian2(1, 1) }); - var id = guidArray[0]; - - atlas.addImage(id, greenImage); + atlas.addImage(greenGuid, greenImage); - var promise1 = atlas.addSubRegion(id, new BoundingRectangle(0.0, 0.0, 0.5, 0.5)); - var promise2 = atlas.addSubRegion(id, new BoundingRectangle(0.0, 0.5, 0.5, 0.5)); - var promise3 = atlas.addSubRegion(id, new BoundingRectangle(0.5, 0.0, 0.5, 0.5)); - var promise4 = atlas.addSubRegion(id, new BoundingRectangle(0.5, 0.5, 0.5, 0.5)); + var promise1 = atlas.addSubRegion(greenGuid, new BoundingRectangle(0.0, 0.0, 0.5, 0.5)); + var promise2 = atlas.addSubRegion(greenGuid, new BoundingRectangle(0.0, 0.5, 0.5, 0.5)); + var promise3 = atlas.addSubRegion(greenGuid, new BoundingRectangle(0.5, 0.0, 0.5, 0.5)); + var promise4 = atlas.addSubRegion(greenGuid, new BoundingRectangle(0.5, 0.5, 0.5, 0.5)); return when.all([promise1, promise2, promise3, promise4], function(indices) { var index1 = indices.shift(); @@ -751,7 +753,7 @@ defineSuite([ expect(atlas.numberOfImages).toEqual(5); - return atlas.addImage(guidArray[1], blueImage).then(function(blueIndex) { + return atlas.addImage(blueGuid, blueImage).then(function(blueIndex) { expect(atlas.numberOfImages).toEqual(6); var coordinates = atlas.textureCoordinates; @@ -832,11 +834,11 @@ defineSuite([ var guid1 = atlas.guid; - return atlas.addImage(guidArray[0], greenImage).then(function(index) { + return atlas.addImage(greenGuid, greenImage).then(function(index) { var guid2 = atlas.guid; expect(guid1).not.toEqual(guid2); - return atlas.addSubRegion(guidArray[0], new BoundingRectangle(0.0, 0.0, 0.5, 0.5)).then(function(index) { + return atlas.addSubRegion(greenGuid, new BoundingRectangle(0.0, 0.0, 0.5, 0.5)).then(function(index) { var guid3 = atlas.guid; expect(guid2).not.toEqual(guid3); }); From bf46f89eefb9055f9ae60575ce324345f63ffa8b Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Thu, 21 Feb 2019 13:31:46 -0500 Subject: [PATCH 35/71] Update CHANGES.md --- CHANGES.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5ed21d4e7602..071871962bad 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,14 +5,15 @@ Change Log ##### Breaking Changes :mega: * `czm_materialInput.slope` is now an angle in radians between 0 and pi/2 (flat to vertical), rather than a projected length 1 to 0 (flat to vertical). -* `Resource.fetchImage` now returns an `ImageBitmap` instead of `Image` when supported. This allows for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode when `ImageBitmapOptions` are supported since an `ImageBitmap` cannot be vertically flipped during texture upload. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) - -##### Additions :tada: -* `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). +* `Resource.fetchImage` now returns an `ImageBitmap` instead of `Image` when supported. This allows for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) ##### Deprecated :hourglass_flowing_sand: * `Resource.fetchImage` now takes an options object. Use `resource.fetchImage({ preferBlob: true })` instead of `resource.fetchImage(true)`. The previous function definition will no longer work in 1.56. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) +##### Additions :tada: +* `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). +* `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode. It is only valid when `ImageBitmapOptions` is supported by the browser. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) + ##### Fixes :wrench: * Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383) * Fixed Node.js support for the `Resource` class and any functionality using it internally. From 1b7454e2db16e3bc9118337ab068f898f9f831d8 Mon Sep 17 00:00:00 2001 From: Jannes Bolling Date: Fri, 22 Feb 2019 18:12:34 +0100 Subject: [PATCH 36/71] use un-optimized requireJS modules if NODE_ENV === 'test' --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ea256e508a7e..34863ca3e744 100644 --- a/index.js +++ b/index.js @@ -3,8 +3,8 @@ var path = require('path'); -// If not explicitly in development mode, use the combined/minified/optimized version of Cesium -if (process.env.NODE_ENV !== 'development') { +// If not explicitly in development or test mode, use the combined/minified/optimized version of Cesium +if (process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test') { module.exports = require(path.join(__dirname, 'Build/Cesium/Cesium')); return; } From 9c9a9e168eebf5cbef3800f5abf2e8fef933c915 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Fri, 22 Feb 2019 21:41:45 -0500 Subject: [PATCH 37/71] Fix the rest of the demos --- .../Classification/PointCloud/content.geom | Bin 856 -> 358 bytes .../Classification/PointCloud/tileset.json | 30 +++++++++--------- .../gallery/3D Tiles Clipping Planes.html | 24 ++++++++------ .../3D Tiles Point Cloud Classification.html | 13 ++++---- .../gallery/3D Tiles Point Cloud Shading.html | 18 +++++++---- .../gallery/3D Tiles Point Cloud.html | 13 ++++++-- 6 files changed, 57 insertions(+), 41 deletions(-) diff --git a/Apps/SampleData/Cesium3DTiles/Classification/PointCloud/content.geom b/Apps/SampleData/Cesium3DTiles/Classification/PointCloud/content.geom index 71a919ea802f32f208189a7195c770c175c59ee8..ae108ba74751e920f5ca171ee4a1010b4ecf9e51 100644 GIT binary patch literal 358 zcmV-s0h#_EiwFP!000003QJGT&t+s_V2EI5U`PPcQj!ZkSF$JNh0 z#6!u-SO+4YWL2${R9TYhpO#jfTB2lSP^+Wl9O>if=i(ZKq8cuUuEWU4qPA9nf#HDz z1UG=NJp%^7E#~#0!f}22+WqqD1RWt_FtcWmY*rZ1tOG!^RLWz}%o1=U)vOGlSvP@Z ztvI_BrWa_A1Icb$AU4nOx%5N(;>AI5bIzVwL$Wzb8K*eve?NKPx~UCVud#73kY*s+ zU+3dzJMPb9I8emw1U3hhW*(FWM8*Lb`+(S-g@NG(&-XA8A0}>50ii)^L0ACFKMTa= zK=m3>^)T@aH1!Tp{w1jS9hV?{nD`7d^#xG=EvWhpQ1vkJ6KLueK>3eg?!O!mS*?_r zqGT1VRFYqwTI7^pQj(u*sH6kohU6E3*hTsIX)xLdCT9#|m?*{8Dkvxb09?XKQCI^2 E01V}&Pyhe` literal 856 zcmYdK&Cg|IU|@(~W?)DF(o>ii7(9S92vjRM`A4`0$NRYYxrcZtSsCj<1eC0*m69q; zQvK7?ic?FJtPE;(l$;}dJpEi;gHTk%1<`dF8ClfUDljlSaDdAI5bIzVwL$W!B|0g?M{(SPlT~iydUSs26Ak6?X6UamcxWn5f zcDCcJbcO@P%uWuV@HJ*)V7So6^bbS}eP_SV3N*&y=fA%oeg@}%FfF&X6vG)fT#M}m``3yV| z{sbu9!3W|0XoaZ1(FLI`dLZ-%DBaNq;TQBX{i{~WOi{9mRw~IaPc3rFFDc2-HB{1p ca6|G7K Date: Mon, 25 Feb 2019 16:07:25 +0100 Subject: [PATCH 38/71] only use optimized cesium build for NODE_ENV production --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 34863ca3e744..4fef4286713d 100644 --- a/index.js +++ b/index.js @@ -3,13 +3,13 @@ var path = require('path'); -// If not explicitly in development or test mode, use the combined/minified/optimized version of Cesium -if (process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test') { +// If in 'production' mode, use the combined/minified/optimized version of Cesium +if (process.env.NODE_ENV === 'production') { module.exports = require(path.join(__dirname, 'Build/Cesium/Cesium')); return; } -// Otherwise, use un-optimized requirejs modules for improved error checking. +// Otherwise, use un-optimized requirejs modules for improved error checking. For example 'development' mode var requirejs = require('requirejs'); requirejs.config({ paths: { From 85af0cfcf1d4e84b5f24bd3e83218bb6ba9a3214 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Mon, 25 Feb 2019 10:52:46 -0500 Subject: [PATCH 39/71] CONTRIBUTORS.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a6cdd86db253..f9ace2bc8e5c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -99,6 +99,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Jannes Bolling](https://github.com/jbo023) * [Arne Schilling](https://github.com/arneschilling) * [Ben Kuster](https://github.com/bkuster) + * [Zhihang Yao](https://github.com/yaozhihang) * [Logilab](https://www.logilab.fr/) * [Florent Cayré](https://github.com/fcayre/) * [webiks](https://www.webiks.com) From 9aa443d4b7b0c588c2ebd93640bcba43f0338a4a Mon Sep 17 00:00:00 2001 From: Hannah Date: Mon, 25 Feb 2019 11:21:03 -0500 Subject: [PATCH 40/71] eslint --- Source/Scene/Vector3DTilePolygons.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/Vector3DTilePolygons.js b/Source/Scene/Vector3DTilePolygons.js index ae507cfe4f0b..1ecedf97e5be 100644 --- a/Source/Scene/Vector3DTilePolygons.js +++ b/Source/Scene/Vector3DTilePolygons.js @@ -287,7 +287,7 @@ define([ if (defined(minimumHeights) && defined(maximumHeights)) { minimumHeights = arraySlice(minimumHeights); maximumHeights = arraySlice(maximumHeights); - + transferrableObjects.push(minimumHeights.buffer, maximumHeights.buffer); parameters.minimumHeights = minimumHeights; parameters.maximumHeights = maximumHeights; From 92263b20add8c74d4af7859413a4328ff0e43b57 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Mon, 25 Feb 2019 11:48:42 -0500 Subject: [PATCH 41/71] rename math comparison functions --- Source/Core/Math.js | 16 +++--- Source/Scene/TerrainFillMesh.js | 16 +++--- Specs/Core/MathSpec.js | 96 ++++++++++++++++----------------- 3 files changed, 64 insertions(+), 64 deletions(-) diff --git a/Source/Core/Math.js b/Source/Core/Math.js index c3c2174221d8..1322788ac124 100644 --- a/Source/Core/Math.js +++ b/Source/Core/Math.js @@ -588,13 +588,13 @@ define([ * absoluteEpsilon of each other, they are considered equal and this function returns false. * * @param {Number} left The first number to compare. - * @param {Number} second The second number to compare. + * @param {Number} right The second number to compare. * @param {Number} absoluteEpsilon The absolute epsilon to use in comparison. * @returns {Boolean} true if left is less than right by more than * absoluteEpsilon. false if left is greater or if the two * values are nearly equal. */ - CesiumMath.leftIsLessThanRight = function(left, right, absoluteEpsilon) { + CesiumMath.lessThan = function(left, right, absoluteEpsilon) { //>>includeStart('debug', pragmas.debug); if (!defined(left)) { throw new DeveloperError('first is required.'); @@ -614,12 +614,12 @@ define([ * absoluteEpsilon of each other, they are considered equal and this function returns true. * * @param {Number} left The first number to compare. - * @param {Number} second The second number to compare. + * @param {Number} right The second number to compare. * @param {Number} absoluteEpsilon The absolute epsilon to use in comparison. * @returns {Boolean} true if left is less than right or if the * the values are nearly equal. */ - CesiumMath.leftIsLessThanOrEqualToRight = function(left, right, absoluteEpsilon) { + CesiumMath.lessThanOrEquals = function(left, right, absoluteEpsilon) { //>>includeStart('debug', pragmas.debug); if (!defined(left)) { throw new DeveloperError('first is required.'); @@ -639,13 +639,13 @@ define([ * absoluteEpsilon of each other, they are considered equal and this function returns false. * * @param {Number} left The first number to compare. - * @param {Number} second The second number to compare. + * @param {Number} right The second number to compare. * @param {Number} absoluteEpsilon The absolute epsilon to use in comparison. * @returns {Boolean} true if left is greater than right by more than * absoluteEpsilon. false if left is less or if the two * values are nearly equal. */ - CesiumMath.leftIsGreaterThanRight = function(left, right, absoluteEpsilon) { + CesiumMath.greaterThan = function(left, right, absoluteEpsilon) { //>>includeStart('debug', pragmas.debug); if (!defined(left)) { throw new DeveloperError('first is required.'); @@ -665,12 +665,12 @@ define([ * absoluteEpsilon of each other, they are considered equal and this function returns true. * * @param {Number} left The first number to compare. - * @param {Number} second The second number to compare. + * @param {Number} right The second number to compare. * @param {Number} absoluteEpsilon The absolute epsilon to use in comparison. * @returns {Boolean} true if left is greater than right or if the * the values are nearly equal. */ - CesiumMath.leftIsGreaterThanOrEqualToRight = function(left, right, absoluteEpsilon) { + CesiumMath.greaterThanOrEquals = function(left, right, absoluteEpsilon) { //>>includeStart('debug', pragmas.debug); if (!defined(left)) { throw new DeveloperError('first is required.'); diff --git a/Source/Scene/TerrainFillMesh.js b/Source/Scene/TerrainFillMesh.js index e047b2568997..1589b056903d 100644 --- a/Source/Scene/TerrainFillMesh.js +++ b/Source/Scene/TerrainFillMesh.js @@ -349,14 +349,14 @@ define([ for (startIndex = 0; startIndex < edgeTiles.length; ++startIndex) { existingTile = edgeTiles[startIndex]; existingRectangle = existingTile.rectangle; - if (CesiumMath.leftIsGreaterThanRight(sourceRectangle.north, existingRectangle.south, epsilon)) { + if (CesiumMath.greaterThan(sourceRectangle.north, existingRectangle.south, epsilon)) { break; } } for (endIndex = startIndex; endIndex < edgeTiles.length; ++endIndex) { existingTile = edgeTiles[endIndex]; existingRectangle = existingTile.rectangle; - if (CesiumMath.leftIsGreaterThanOrEqualToRight(sourceRectangle.south, existingRectangle.north, epsilon)) { + if (CesiumMath.greaterThanOrEquals(sourceRectangle.south, existingRectangle.north, epsilon)) { break; } } @@ -367,14 +367,14 @@ define([ for (startIndex = 0; startIndex < edgeTiles.length; ++startIndex) { existingTile = edgeTiles[startIndex]; existingRectangle = existingTile.rectangle; - if (CesiumMath.leftIsLessThanRight(sourceRectangle.west, existingRectangle.east, epsilon)) { + if (CesiumMath.lessThan(sourceRectangle.west, existingRectangle.east, epsilon)) { break; } } for (endIndex = startIndex; endIndex < edgeTiles.length; ++endIndex) { existingTile = edgeTiles[endIndex]; existingRectangle = existingTile.rectangle; - if (CesiumMath.leftIsLessThanOrEqualToRight(sourceRectangle.east, existingRectangle.west, epsilon)) { + if (CesiumMath.lessThanOrEquals(sourceRectangle.east, existingRectangle.west, epsilon)) { break; } } @@ -385,14 +385,14 @@ define([ for (startIndex = 0; startIndex < edgeTiles.length; ++startIndex) { existingTile = edgeTiles[startIndex]; existingRectangle = existingTile.rectangle; - if (CesiumMath.leftIsLessThanRight(sourceRectangle.south, existingRectangle.north, epsilon)) { + if (CesiumMath.lessThan(sourceRectangle.south, existingRectangle.north, epsilon)) { break; } } for (endIndex = startIndex; endIndex < edgeTiles.length; ++endIndex) { existingTile = edgeTiles[endIndex]; existingRectangle = existingTile.rectangle; - if (CesiumMath.leftIsLessThanOrEqualToRight(sourceRectangle.north, existingRectangle.south, epsilon)) { + if (CesiumMath.lessThanOrEquals(sourceRectangle.north, existingRectangle.south, epsilon)) { break; } } @@ -403,14 +403,14 @@ define([ for (startIndex = 0; startIndex < edgeTiles.length; ++startIndex) { existingTile = edgeTiles[startIndex]; existingRectangle = existingTile.rectangle; - if (CesiumMath.leftIsGreaterThanRight(sourceRectangle.east, existingRectangle.west, epsilon)) { + if (CesiumMath.greaterThan(sourceRectangle.east, existingRectangle.west, epsilon)) { break; } } for (endIndex = startIndex; endIndex < edgeTiles.length; ++endIndex) { existingTile = edgeTiles[endIndex]; existingRectangle = existingTile.rectangle; - if (CesiumMath.leftIsGreaterThanOrEqualToRight(sourceRectangle.west, existingRectangle.east, epsilon)) { + if (CesiumMath.greaterThanOrEquals(sourceRectangle.west, existingRectangle.east, epsilon)) { break; } } diff --git a/Specs/Core/MathSpec.js b/Specs/Core/MathSpec.js index fba21c6269d2..c2ec6b6d3578 100644 --- a/Specs/Core/MathSpec.js +++ b/Specs/Core/MathSpec.js @@ -254,107 +254,107 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('leftIsLessThanRight works', function() { - expect(CesiumMath.leftIsLessThanRight(1.0, 2.0, 0.2)).toBe(true); - expect(CesiumMath.leftIsLessThanRight(2.0, 1.0, 0.2)).toBe(false); - expect(CesiumMath.leftIsLessThanRight(1.0, 1.0, 0.2)).toBe(false); - expect(CesiumMath.leftIsLessThanRight(1.0, 1.2, 0.2)).toBe(false); - expect(CesiumMath.leftIsLessThanRight(1.2, 1.0, 0.2)).toBe(false); + it('lessThan works', function() { + expect(CesiumMath.lessThan(1.0, 2.0, 0.2)).toBe(true); + expect(CesiumMath.lessThan(2.0, 1.0, 0.2)).toBe(false); + expect(CesiumMath.lessThan(1.0, 1.0, 0.2)).toBe(false); + expect(CesiumMath.lessThan(1.0, 1.2, 0.2)).toBe(false); + expect(CesiumMath.lessThan(1.2, 1.0, 0.2)).toBe(false); }); - it('leftIsLessThanRight throws for undefined left', function() { + it('lessThan throws for undefined left', function() { expect(function() { - CesiumMath.leftIsLessThanRight(undefined, 5.0, CesiumMath.EPSILON16); + CesiumMath.lessThan(undefined, 5.0, CesiumMath.EPSILON16); }).toThrowDeveloperError(); }); - it('leftIsLessThanRight throws for undefined right', function() { + it('lessThan throws for undefined right', function() { expect(function() { - CesiumMath.leftIsLessThanRight(1.0, undefined, CesiumMath.EPSILON16); + CesiumMath.lessThan(1.0, undefined, CesiumMath.EPSILON16); }).toThrowDeveloperError(); }); - it('leftIsLessThanRight throws for undefined absoluteEpsilon', function() { + it('lessThan throws for undefined absoluteEpsilon', function() { expect(function() { - CesiumMath.leftIsLessThanRight(1.0, 5.0, undefined); + CesiumMath.lessThan(1.0, 5.0, undefined); }).toThrowDeveloperError(); }); - it('leftIsLessThanOrEqualToRight works', function() { - expect(CesiumMath.leftIsLessThanOrEqualToRight(1.0, 2.0, 0.2)).toBe(true); - expect(CesiumMath.leftIsLessThanOrEqualToRight(2.0, 1.0, 0.2)).toBe(false); - expect(CesiumMath.leftIsLessThanOrEqualToRight(1.0, 1.0, 0.2)).toBe(true); - expect(CesiumMath.leftIsLessThanOrEqualToRight(1.0, 1.2, 0.2)).toBe(true); - expect(CesiumMath.leftIsLessThanOrEqualToRight(1.2, 1.0, 0.2)).toBe(true); + it('lessThanOrEquals works', function() { + expect(CesiumMath.lessThanOrEquals(1.0, 2.0, 0.2)).toBe(true); + expect(CesiumMath.lessThanOrEquals(2.0, 1.0, 0.2)).toBe(false); + expect(CesiumMath.lessThanOrEquals(1.0, 1.0, 0.2)).toBe(true); + expect(CesiumMath.lessThanOrEquals(1.0, 1.2, 0.2)).toBe(true); + expect(CesiumMath.lessThanOrEquals(1.2, 1.0, 0.2)).toBe(true); }); - it('leftIsLessThanOrEqualToRight throws for undefined left', function() { + it('lessThanOrEquals throws for undefined left', function() { expect(function() { - CesiumMath.leftIsLessThanOrEqualToRight(undefined, 5.0, CesiumMath.EPSILON16); + CesiumMath.lessThanOrEquals(undefined, 5.0, CesiumMath.EPSILON16); }).toThrowDeveloperError(); }); - it('leftIsLessThanOrEqualToRight throws for undefined right', function() { + it('lessThanOrEquals throws for undefined right', function() { expect(function() { - CesiumMath.leftIsLessThanOrEqualToRight(1.0, undefined, CesiumMath.EPSILON16); + CesiumMath.lessThanOrEquals(1.0, undefined, CesiumMath.EPSILON16); }).toThrowDeveloperError(); }); - it('leftIsLessThanOrEqualToRight throws for undefined absoluteEpsilon', function() { + it('lessThanOrEquals throws for undefined absoluteEpsilon', function() { expect(function() { - CesiumMath.leftIsLessThanOrEqualToRight(1.0, 5.0, undefined); + CesiumMath.lessThanOrEquals(1.0, 5.0, undefined); }).toThrowDeveloperError(); }); - it('leftIsGreaterThanRight works', function() { - expect(CesiumMath.leftIsGreaterThanRight(1.0, 2.0, 0.2)).toBe(false); - expect(CesiumMath.leftIsGreaterThanRight(2.0, 1.0, 0.2)).toBe(true); - expect(CesiumMath.leftIsGreaterThanRight(1.0, 1.0, 0.2)).toBe(false); - expect(CesiumMath.leftIsGreaterThanRight(1.0, 1.2, 0.2)).toBe(false); - expect(CesiumMath.leftIsGreaterThanRight(1.2, 1.0, 0.2)).toBe(false); + it('greaterThan works', function() { + expect(CesiumMath.greaterThan(1.0, 2.0, 0.2)).toBe(false); + expect(CesiumMath.greaterThan(2.0, 1.0, 0.2)).toBe(true); + expect(CesiumMath.greaterThan(1.0, 1.0, 0.2)).toBe(false); + expect(CesiumMath.greaterThan(1.0, 1.2, 0.2)).toBe(false); + expect(CesiumMath.greaterThan(1.2, 1.0, 0.2)).toBe(false); }); - it('leftIsGreaterThanRight throws for undefined left', function() { + it('greaterThan throws for undefined left', function() { expect(function() { - CesiumMath.leftIsGreaterThanRight(undefined, 5.0, CesiumMath.EPSILON16); + CesiumMath.greaterThan(undefined, 5.0, CesiumMath.EPSILON16); }).toThrowDeveloperError(); }); - it('leftIsGreaterThanRight throws for undefined right', function() { + it('greaterThan throws for undefined right', function() { expect(function() { - CesiumMath.leftIsGreaterThanRight(1.0, undefined, CesiumMath.EPSILON16); + CesiumMath.greaterThan(1.0, undefined, CesiumMath.EPSILON16); }).toThrowDeveloperError(); }); - it('leftIsGreaterThanRight throws for undefined absoluteEpsilon', function() { + it('greaterThan throws for undefined absoluteEpsilon', function() { expect(function() { - CesiumMath.leftIsGreaterThanRight(1.0, 5.0, undefined); + CesiumMath.greaterThan(1.0, 5.0, undefined); }).toThrowDeveloperError(); }); - it('leftIsGreaterThanOrEqualToRight works', function() { - expect(CesiumMath.leftIsGreaterThanOrEqualToRight(1.0, 2.0, 0.2)).toBe(false); - expect(CesiumMath.leftIsGreaterThanOrEqualToRight(2.0, 1.0, 0.2)).toBe(true); - expect(CesiumMath.leftIsGreaterThanOrEqualToRight(1.0, 1.0, 0.2)).toBe(true); - expect(CesiumMath.leftIsGreaterThanOrEqualToRight(1.0, 1.2, 0.2)).toBe(true); - expect(CesiumMath.leftIsGreaterThanOrEqualToRight(1.2, 1.0, 0.2)).toBe(true); + it('greaterThanOrEquals works', function() { + expect(CesiumMath.greaterThanOrEquals(1.0, 2.0, 0.2)).toBe(false); + expect(CesiumMath.greaterThanOrEquals(2.0, 1.0, 0.2)).toBe(true); + expect(CesiumMath.greaterThanOrEquals(1.0, 1.0, 0.2)).toBe(true); + expect(CesiumMath.greaterThanOrEquals(1.0, 1.2, 0.2)).toBe(true); + expect(CesiumMath.greaterThanOrEquals(1.2, 1.0, 0.2)).toBe(true); }); - it('leftIsGreaterThanOrEqualToRight throws for undefined left', function() { + it('greaterThanOrEquals throws for undefined left', function() { expect(function() { - CesiumMath.leftIsGreaterThanOrEqualToRight(undefined, 5.0, CesiumMath.EPSILON16); + CesiumMath.greaterThanOrEquals(undefined, 5.0, CesiumMath.EPSILON16); }).toThrowDeveloperError(); }); - it('leftIsGreaterThanOrEqualToRight throws for undefined right', function() { + it('greaterThanOrEquals throws for undefined right', function() { expect(function() { - CesiumMath.leftIsGreaterThanOrEqualToRight(1.0, undefined, CesiumMath.EPSILON16); + CesiumMath.greaterThanOrEquals(1.0, undefined, CesiumMath.EPSILON16); }).toThrowDeveloperError(); }); - it('leftIsGreaterThanOrEqualToRight throws for undefined absoluteEpsilon', function() { + it('greaterThanOrEquals throws for undefined absoluteEpsilon', function() { expect(function() { - CesiumMath.leftIsGreaterThanOrEqualToRight(1.0, 5.0, undefined); + CesiumMath.greaterThanOrEquals(1.0, 5.0, undefined); }).toThrowDeveloperError(); }); From d913ab8d0c3bf0ff6a9fb33c47353bfd76d30547 Mon Sep 17 00:00:00 2001 From: Jannes Bolling Date: Wed, 27 Feb 2019 17:29:16 +0100 Subject: [PATCH 42/71] fix PolygonOutlineGeometry indices range --- CHANGES.md | 1 + Source/Core/PolygonOutlineGeometry.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index e1465f5fdadc..4d5ea98efa9c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ Change Log * Fixed model silhouette colors when rendering with high dynamic range. [#7563](https://github.com/AnalyticalGraphicsInc/cesium/pull/7563) * Fixed an issue with ground polylines on globes that use ellipsoids other than WGS84. [#7552](https://github.com/AnalyticalGraphicsInc/cesium/issues/7552) * Fixed an issue where Draco compressed models with RGB per-vertex color would not load in Cesium. [#7576](https://github.com/AnalyticalGraphicsInc/cesium/issues/7576) +* Fixed an issue where the outline geometry for extruded Polygons didn't calculate the correct indices. [#7599](https://github.com/AnalyticalGraphicsInc/cesium/issues/7599) ### 1.54 - 2019-02-01 diff --git a/Source/Core/PolygonOutlineGeometry.js b/Source/Core/PolygonOutlineGeometry.js index 180c19e0dbec..1dcc9c32094e 100644 --- a/Source/Core/PolygonOutlineGeometry.js +++ b/Source/Core/PolygonOutlineGeometry.js @@ -197,7 +197,7 @@ define([ var cornersLength = corners.length; var indicesSize = ((length * 2) + cornersLength) * 2; - var indices = IndexDatatype.createTypedArray(length, indicesSize); + var indices = IndexDatatype.createTypedArray(length + cornersLength, indicesSize); index = 0; for (i = 0; i < length; ++i) { From e3b83a36838e3b386e84db871e95571a979bf309 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Thu, 28 Feb 2019 10:25:53 -0500 Subject: [PATCH 43/71] Fix PostProcessStageLibrary specs --- Specs/Scene/PostProcessStageLibrarySpec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Specs/Scene/PostProcessStageLibrarySpec.js b/Specs/Scene/PostProcessStageLibrarySpec.js index 1d73cd5cd5b9..13aea8c8ce3e 100644 --- a/Specs/Scene/PostProcessStageLibrarySpec.js +++ b/Specs/Scene/PostProcessStageLibrarySpec.js @@ -53,6 +53,7 @@ defineSuite([ scene.postProcessStages.fxaa.enabled = false; scene.postProcessStages.bloom.enabled = false; scene.postProcessStages.ambientOcclusion.enabled = false; + scene.renderForSpecs(); }); var model; From 02100579d993f7b107d146ddc5c769ad50dbabe8 Mon Sep 17 00:00:00 2001 From: Scott Hunter Date: Thu, 28 Feb 2019 15:58:17 -0500 Subject: [PATCH 44/71] Fix handling of CZML followSurface, which is implemented in terms of arcType. This introduces a new AdapterProperty concept in CzmlDataSource, which uses CallbackProperty to adapt a property of one type into another type, regardless of whether the property is time-varying or not. --- Source/DataSources/CzmlDataSource.js | 31 +++++++++----- Specs/DataSources/CzmlDataSourceSpec.js | 56 +++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 11 deletions(-) diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index 44f6d1318731..38535592c168 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -44,6 +44,7 @@ define([ '../ThirdParty/when', './BillboardGraphics', './BoxGraphics', + './CallbackProperty', './ColorMaterialProperty', './CompositeMaterialProperty', './CompositePositionProperty', @@ -132,6 +133,7 @@ define([ when, BillboardGraphics, BoxGraphics, + CallbackProperty, ColorMaterialProperty, CompositeMaterialProperty, CompositePositionProperty, @@ -213,6 +215,12 @@ define([ throw new RuntimeError(JSON.stringify(packetData) + ' is not valid CZML.'); } + function createAdapterProperty(property, adapterFunction) { + return new CallbackProperty(function(time, result) { + return adapterFunction(property.getValue(time, result)); + }, property.isConstant); + } + var scratchCartesian = new Cartesian3(); var scratchSpherical = new Spherical(); var scratchCartographic = new Cartographic(); @@ -1777,6 +1785,10 @@ define([ processPacketData(Number, polygon, 'zIndex', polygonData.zIndex, interval, sourceUri, entityCollection); } + function adaptFollowSurfaceToArcType(followSurface) { + return followSurface ? ArcType.GEODESIC : ArcType.NONE; + } + function processPolyline(entity, packet, entityCollection, sourceUri) { var polylineData = packet.polyline; if (!defined(polylineData)) { @@ -1801,21 +1813,18 @@ define([ processPacketData(Number, polyline, 'granularity', polylineData.granularity, interval, sourceUri, entityCollection); processMaterialPacketData(polyline, 'material', polylineData.material, interval, sourceUri, entityCollection); processMaterialPacketData(polyline, 'depthFailMaterial', polylineData.depthFailMaterial, interval, sourceUri, entityCollection); - // Don't want to break CZML spec to keep this workaround even after followSurface has been deprecated from geometry. - // See https://github.com/AnalyticalGraphicsInc/cesium/pull/7582#discussion_r258695385 - if (defined(polylineData.followSurface) && !defined(polylineData.arcType)) { - if (polyline.followSurface) { - processPacketData(ArcType, polyline, 'arcType', ArcType.GEODESIC, interval, sourceUri, entityCollection); - } else { - processPacketData(ArcType, polyline, 'arcType', ArcType.NONE, interval, sourceUri, entityCollection); - } - } else { - processPacketData(ArcType, polyline, 'arcType', polylineData.arcType, interval, sourceUri, entityCollection); - } + processPacketData(ArcType, polyline, 'arcType', polylineData.arcType, interval, sourceUri, entityCollection); processPacketData(Boolean, polyline, 'clampToGround', polylineData.clampToGround, interval, sourceUri, entityCollection); processPacketData(ShadowMode, polyline, 'shadows', polylineData.shadows, interval, sourceUri, entityCollection); processPacketData(DistanceDisplayCondition, polyline, 'distanceDisplayCondition', polylineData.distanceDisplayCondition, interval, sourceUri, entityCollection); processPacketData(Number, polyline, 'zIndex', polylineData.zIndex, interval, sourceUri, entityCollection); + + // for backwards compatibility, adapt CZML followSurface to arcType. + if (defined(polylineData.followSurface) && !defined(polylineData.arcType)) { + var tempObj = {}; + processPacketData(Boolean, tempObj, 'followSurface', polylineData.followSurface, interval, sourceUri, entityCollection); + polyline.arcType = createAdapterProperty(tempObj.followSurface, adaptFollowSurfaceToArcType); + } } function processRectangle(entity, packet, entityCollection, sourceUri) { diff --git a/Specs/DataSources/CzmlDataSourceSpec.js b/Specs/DataSources/CzmlDataSourceSpec.js index 397f69f870d1..e4db657f7f12 100644 --- a/Specs/DataSources/CzmlDataSourceSpec.js +++ b/Specs/DataSources/CzmlDataSourceSpec.js @@ -3589,6 +3589,62 @@ defineSuite([ }); }); + it('converts followSurface to arcType for backwards compatibility', function() { + var packet = [{ + id : 'document', + version : '1.0' + }, { + id : 'followSurface-false', + polyline : { + followSurface : false + } + }, { + id : 'followSurface-true', + polyline : { + followSurface : true + } + }, { + id : 'followSurface-time-varying', + polyline : { + followSurface : [{ + interval : '2013-01-01T00:00:00Z/2013-01-01T01:00:00Z', + boolean : true + }, { + interval : '2013-01-01T01:00:00Z/2013-01-01T02:00:00Z', + boolean : false + }] + } + }, { + id : 'arcType-overrides-followSurface', + polyline : { + followSurface : true, + arcType: 'RHUMB' + } + }]; + + var dataSource = new CzmlDataSource(); + return dataSource.load(packet).then(function(dataSource) { + var date = JulianDate.now(); + + var entity = dataSource.entities.getById('followSurface-false'); + expect(entity.polyline.arcType.isConstant).toBe(true); + expect(entity.polyline.arcType.getValue(date)).toBe(ArcType.NONE); + + entity = dataSource.entities.getById('followSurface-true'); + expect(entity.polyline.arcType.isConstant).toBe(true); + expect(entity.polyline.arcType.getValue(date)).toBe(ArcType.GEODESIC); + + entity = dataSource.entities.getById('followSurface-time-varying'); + expect(entity.polyline.arcType.isConstant).toBe(false); + expect(entity.polyline.arcType.getValue(JulianDate.fromIso8601('2013-01-01T00:00:00Z'))).toBe(ArcType.GEODESIC); + expect(entity.polyline.arcType.getValue(JulianDate.fromIso8601('2013-01-01T01:00:00Z'))).toBe(ArcType.NONE); + + entity = dataSource.entities.getById('arcType-overrides-followSurface'); + expect(entity.polyline.arcType.isConstant).toBe(true); + expect(entity.polyline.arcType.getValue(date)).toBe(ArcType.RHUMB); + }); + }); + // The below test was generated, along with ValidationDocument.czml, // by the czml-writer ValidationDocumentationGenerator. // https://github.com/AnalyticalGraphicsInc/czml-writer/blob/master/DotNet/GenerateFromSchema/ValidationDocumentGenerator.cs From 4e89d8a5bb44217a80c700cb5f370d8e853a0d71 Mon Sep 17 00:00:00 2001 From: Scott Hunter Date: Thu, 28 Feb 2019 16:04:55 -0500 Subject: [PATCH 45/71] fix documentation error. --- Source/DataSources/PolylineGraphics.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/DataSources/PolylineGraphics.js b/Source/DataSources/PolylineGraphics.js index 775ee15b2437..2b019a79f895 100644 --- a/Source/DataSources/PolylineGraphics.js +++ b/Source/DataSources/PolylineGraphics.js @@ -149,7 +149,6 @@ define([ * Gets or sets the {@link ArcType} Property specifying whether the line segments should be great arcs, rhumb lines or linearly connected. * @memberof PolylineGraphics.prototype * @type {Property} - * @deprecated This property has been deprecated. Use {@link PolylineGraphics#arcType} instead. * @default ArcType.GEODESIC */ arcType : createPropertyDescriptor('arcType'), From bf8d0716f0f42a5fe33593d2db532a170c11883e Mon Sep 17 00:00:00 2001 From: Scott Hunter Date: Thu, 28 Feb 2019 16:08:29 -0500 Subject: [PATCH 46/71] Update CHANGES --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4d5ea98efa9c..f5cd3437b3ce 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Change Log ##### Additions :tada: * `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). +* Added CZML `arcType` support for `polyline` and `polygon`, which supersedes `followSurface`. `followSurface` is still supported for compatibility with existing documents. [#7582](https://github.com/AnalyticalGraphicsInc/cesium/pull/7582) ##### Fixes :wrench: * Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383) @@ -19,7 +20,7 @@ Change Log * Fixed model silhouette colors when rendering with high dynamic range. [#7563](https://github.com/AnalyticalGraphicsInc/cesium/pull/7563) * Fixed an issue with ground polylines on globes that use ellipsoids other than WGS84. [#7552](https://github.com/AnalyticalGraphicsInc/cesium/issues/7552) * Fixed an issue where Draco compressed models with RGB per-vertex color would not load in Cesium. [#7576](https://github.com/AnalyticalGraphicsInc/cesium/issues/7576) -* Fixed an issue where the outline geometry for extruded Polygons didn't calculate the correct indices. [#7599](https://github.com/AnalyticalGraphicsInc/cesium/issues/7599) +* Fixed an issue where the outline geometry for extruded Polygons didn't calculate the correct indices. [#7599](https://github.com/AnalyticalGraphicsInc/cesium/issues/7599) ### 1.54 - 2019-02-01 From 3df3700b746f17971082386f465476430dc424ec Mon Sep 17 00:00:00 2001 From: Scott Hunter Date: Thu, 28 Feb 2019 17:11:45 -0500 Subject: [PATCH 47/71] Update CZML validation document and specs. --- Specs/Data/CZML/ValidationDocument.czml | 90 ++++++++++++++++++++----- Specs/DataSources/CzmlDataSourceSpec.js | 52 ++++++++++---- 2 files changed, 111 insertions(+), 31 deletions(-) diff --git a/Specs/Data/CZML/ValidationDocument.czml b/Specs/Data/CZML/ValidationDocument.czml index e012e00a4278..9437da5b20ea 100644 --- a/Specs/Data/CZML/ValidationDocument.czml +++ b/Specs/Data/CZML/ValidationDocument.czml @@ -153,7 +153,8 @@ "distanceDisplayCondition":[ 15797,46507 ] - } + }, + "zIndex":59315 }, "cylinder":{ "show":true, @@ -218,7 +219,8 @@ "distanceDisplayCondition":[ 27813,30828 ] - } + }, + "zIndex":3341 }, "ellipsoid":{ "show":true, @@ -425,6 +427,7 @@ 39143,2200,6408,27161,33386,62338 ] }, + "arcType":"RHUMB", "height":26391, "extrudedHeight":15922, "stRotation":2555, @@ -449,13 +452,13 @@ "perPositionHeight":true, "closeTop":true, "closeBottom":true, - "arcType":"GEODESIC", "shadows":"CAST_ONLY", "distanceDisplayCondition":{ "distanceDisplayCondition":[ 5989,26104 ] - } + }, + "zIndex":31269 }, "polyline":{ "show":true, @@ -464,6 +467,7 @@ 23333,31067,17529,57924,41186,31648 ] }, + "arcType":"RHUMB", "width":14667, "granularity":53395, "material":{ @@ -475,7 +479,6 @@ } } }, - "arcType":"GEODESIC", "shadows":"CAST_ONLY", "depthFailMaterial":{ "solidColor":{ @@ -490,7 +493,9 @@ "distanceDisplayCondition":[ 5807,30486 ] - } + }, + "clampToGround":true, + "zIndex":17658 }, "rectangle":{ "show":true, @@ -526,7 +531,8 @@ "distanceDisplayCondition":[ 21388,23379 ] - } + }, + "zIndex":445 }, "wall":{ "show":true, @@ -5906,6 +5912,9 @@ }, "distanceDisplayCondition":{ "reference":"Constant#corridor.distanceDisplayCondition" + }, + "zIndex":{ + "reference":"Constant#corridor.zIndex" } }, "cylinder":{ @@ -6005,6 +6014,9 @@ }, "distanceDisplayCondition":{ "reference":"Constant#ellipse.distanceDisplayCondition" + }, + "zIndex":{ + "reference":"Constant#ellipse.zIndex" } }, "ellipsoid":{ @@ -6242,6 +6254,9 @@ "ConstantPosition1#position","ConstantPosition2#position" ] }, + "arcType":{ + "reference":"Constant#polygon.arcType" + }, "height":{ "reference":"Constant#polygon.height" }, @@ -6282,14 +6297,14 @@ "closeBottom":{ "reference":"Constant#polygon.closeBottom" }, - "arcType":{ - "reference":"Constant#polygon.arcType" - }, "shadows":{ "reference":"Constant#polygon.shadows" }, "distanceDisplayCondition":{ "reference":"Constant#polygon.distanceDisplayCondition" + }, + "zIndex":{ + "reference":"Constant#polygon.zIndex" } }, "polyline":{ @@ -6301,6 +6316,9 @@ "ConstantPosition1#position","ConstantPosition2#position" ] }, + "arcType":{ + "reference":"Constant#polyline.arcType" + }, "width":{ "reference":"Constant#polyline.width" }, @@ -6314,12 +6332,6 @@ } } }, - "followSurface":{ - "reference":"Constant#polyline.followSurface" - }, - "arcType":{ - "reference":"Constant#polyline.arcType" - }, "shadows":{ "reference":"Constant#polyline.shadows" }, @@ -6332,6 +6344,12 @@ }, "distanceDisplayCondition":{ "reference":"Constant#polyline.distanceDisplayCondition" + }, + "clampToGround":{ + "reference":"Constant#polyline.clampToGround" + }, + "zIndex":{ + "reference":"Constant#polyline.zIndex" } }, "rectangle":{ @@ -6380,6 +6398,9 @@ }, "distanceDisplayCondition":{ "reference":"Constant#rectangle.distanceDisplayCondition" + }, + "zIndex":{ + "reference":"Constant#rectangle.zIndex" } }, "wall":{ @@ -9048,6 +9069,13 @@ 0,10884,63530, 3600,20076,27683 ] + }, + "zIndex":{ + "epoch":"2016-06-17T12:00:00Z", + "number":[ + 0,36068, + 3600,60697 + ] } }, "cylinder":{ @@ -9207,6 +9235,13 @@ 0,38393,63947, 3600,29119,43121 ] + }, + "zIndex":{ + "epoch":"2016-06-17T12:00:00Z", + "number":[ + 0,8989, + 3600,52730 + ] } }, "ellipsoid":{ @@ -9588,6 +9623,13 @@ 0,22140,31962, 3600,3927,22422 ] + }, + "zIndex":{ + "epoch":"2016-06-17T12:00:00Z", + "number":[ + 0,37357, + 3600,64769 + ] } }, "polyline":{ @@ -9633,6 +9675,13 @@ 0,4857,10258, 3600,36588,47246 ] + }, + "zIndex":{ + "epoch":"2016-06-17T12:00:00Z", + "number":[ + 0,55130, + 3600,15491 + ] } }, "rectangle":{ @@ -9709,6 +9758,13 @@ 0,24813,30560, 3600,34617,40071 ] + }, + "zIndex":{ + "epoch":"2016-06-17T12:00:00Z", + "number":[ + 0,27256, + 3600,53581 + ] } }, "wall":{ @@ -16204,4 +16260,4 @@ } } } -] +] \ No newline at end of file diff --git a/Specs/DataSources/CzmlDataSourceSpec.js b/Specs/DataSources/CzmlDataSourceSpec.js index e4db657f7f12..ff98df5d49e7 100644 --- a/Specs/DataSources/CzmlDataSourceSpec.js +++ b/Specs/DataSources/CzmlDataSourceSpec.js @@ -3715,6 +3715,7 @@ defineSuite([ expect(e.corridor.outlineWidth.getValue(date)).toEqual(9132.0); expect(e.corridor.shadows.getValue(date)).toEqual(ShadowMode.CAST_ONLY); expect(e.corridor.distanceDisplayCondition.getValue(date)).toEqual(new DistanceDisplayCondition(15797, 46507)); + expect(e.corridor.zIndex.getValue(date)).toEqual(59315); expect(e.cylinder.show.getValue(date)).toEqual(true); expect(e.cylinder.length.getValue(date)).toEqual(33298.0); expect(e.cylinder.topRadius.getValue(date)).toEqual(16245.0); @@ -3724,8 +3725,8 @@ defineSuite([ expect(e.cylinder.outline.getValue(date)).toEqual(true); expect(e.cylinder.outlineColor.getValue(date)).toEqual(Color.fromBytes(4, 90, 209, 96)); expect(e.cylinder.outlineWidth.getValue(date)).toEqual(64018.0); - expect(e.cylinder.numberOfVerticalLines.getValue(date)).toEqual(38567.0); - expect(e.cylinder.slices.getValue(date)).toEqual(39979.0); + expect(e.cylinder.numberOfVerticalLines.getValue(date)).toEqual(38567); + expect(e.cylinder.slices.getValue(date)).toEqual(39979); expect(e.cylinder.shadows.getValue(date)).toEqual(ShadowMode.CAST_ONLY); expect(e.cylinder.distanceDisplayCondition.getValue(date)).toEqual(new DistanceDisplayCondition(43860, 52395)); expect(e.ellipse.show.getValue(date)).toEqual(true); @@ -3741,9 +3742,10 @@ defineSuite([ expect(e.ellipse.outline.getValue(date)).toEqual(true); expect(e.ellipse.outlineColor.getValue(date)).toEqual(Color.fromBytes(160, 82, 145, 104)); expect(e.ellipse.outlineWidth.getValue(date)).toEqual(8839.0); - expect(e.ellipse.numberOfVerticalLines.getValue(date)).toEqual(38878.0); + expect(e.ellipse.numberOfVerticalLines.getValue(date)).toEqual(38878); expect(e.ellipse.shadows.getValue(date)).toEqual(ShadowMode.CAST_ONLY); expect(e.ellipse.distanceDisplayCondition.getValue(date)).toEqual(new DistanceDisplayCondition(27813, 30828)); + expect(e.ellipse.zIndex.getValue(date)).toEqual(3341); expect(e.ellipsoid.show.getValue(date)).toEqual(true); expect(e.ellipsoid.radii.getValue(date)).toEqual(new Cartesian3(15638, 24381, 37983)); expect(e.ellipsoid.fill.getValue(date)).toEqual(true); @@ -3753,7 +3755,7 @@ defineSuite([ expect(e.ellipsoid.outlineWidth.getValue(date)).toEqual(47507.0); expect(e.ellipsoid.stackPartitions.getValue(date)).toEqual(54278); expect(e.ellipsoid.slicePartitions.getValue(date)).toEqual(28562); - expect(e.ellipsoid.subdivisions.getValue(date)).toEqual(14008.0); + expect(e.ellipsoid.subdivisions.getValue(date)).toEqual(14008); expect(e.ellipsoid.shadows.getValue(date)).toEqual(ShadowMode.CAST_ONLY); expect(e.ellipsoid.distanceDisplayCondition.getValue(date)).toEqual(new DistanceDisplayCondition(3293, 56793)); expect(e.label.show.getValue(date)).toEqual(true); @@ -3814,6 +3816,7 @@ defineSuite([ expect(e.point.disableDepthTestDistance.getValue(date)).toEqual(9675.0); expect(e.polygon.show.getValue(date)).toEqual(true); expect(e.polygon.hierarchy.getValue(date)).toEqual([ new Cartesian3(39143, 2200, 6408), new Cartesian3(27161, 33386, 62338) ]); + expect(e.polygon.arcType.getValue(date)).toEqual(ArcType.RHUMB); expect(e.polygon.height.getValue(date)).toEqual(26391.0); expect(e.polygon.extrudedHeight.getValue(date)).toEqual(15922.0); expect(e.polygon.stRotation.getValue(date)).toEqual(2555.0); @@ -3828,15 +3831,18 @@ defineSuite([ expect(e.polygon.closeBottom.getValue(date)).toEqual(true); expect(e.polygon.shadows.getValue(date)).toEqual(ShadowMode.CAST_ONLY); expect(e.polygon.distanceDisplayCondition.getValue(date)).toEqual(new DistanceDisplayCondition(5989, 26104)); + expect(e.polygon.zIndex.getValue(date)).toEqual(31269); expect(e.polyline.show.getValue(date)).toEqual(true); expect(e.polyline.positions.getValue(date)).toEqual([ new Cartesian3(23333, 31067, 17529), new Cartesian3(57924, 41186, 31648) ]); + expect(e.polyline.arcType.getValue(date)).toEqual(ArcType.RHUMB); expect(e.polyline.width.getValue(date)).toEqual(14667.0); expect(e.polyline.granularity.getValue(date)).toEqual(53395.0); expect(e.polyline.material.color.getValue(date)).toEqual(Color.fromBytes(88, 0, 232, 230)); - expect(e.polyline.arcType.getValue(date)).toEqual(ArcType.GEODESIC); expect(e.polyline.shadows.getValue(date)).toEqual(ShadowMode.CAST_ONLY); expect(e.polyline.depthFailMaterial.color.getValue(date)).toEqual(Color.fromBytes(197, 195, 115, 198)); expect(e.polyline.distanceDisplayCondition.getValue(date)).toEqual(new DistanceDisplayCondition(5807, 30486)); + expect(e.polyline.clampToGround.getValue(date)).toEqual(true); + expect(e.polyline.zIndex.getValue(date)).toEqual(17658); expect(e.rectangle.show.getValue(date)).toEqual(true); expect(e.rectangle.coordinates.getValue(date)).toEqual(new Rectangle(1.13325368272577, 0.703573207377445, 0.756676249095309, 0.339217858685931)); expect(e.rectangle.height.getValue(date)).toEqual(20608.0); @@ -3851,6 +3857,7 @@ defineSuite([ expect(e.rectangle.outlineWidth.getValue(date)).toEqual(59794.0); expect(e.rectangle.shadows.getValue(date)).toEqual(ShadowMode.CAST_ONLY); expect(e.rectangle.distanceDisplayCondition.getValue(date)).toEqual(new DistanceDisplayCondition(21388, 23379)); + expect(e.rectangle.zIndex.getValue(date)).toEqual(445); expect(e.wall.show.getValue(date)).toEqual(true); expect(e.wall.positions.getValue(date)).toEqual([ new Cartesian3(21681, 40276, 30621), new Cartesian3(3959, 61967, 19442) ]); expect(e.wall.minimumHeights.getValue(date)).toEqual([ 49466, 44737 ]); @@ -4524,6 +4531,7 @@ defineSuite([ expect(e.corridor.outlineWidth.getValue(date)).toEqual(constant.corridor.outlineWidth.getValue(date)); expect(e.corridor.shadows.getValue(date)).toEqual(constant.corridor.shadows.getValue(date)); expect(e.corridor.distanceDisplayCondition.getValue(date)).toEqual(constant.corridor.distanceDisplayCondition.getValue(date)); + expect(e.corridor.zIndex.getValue(date)).toEqual(constant.corridor.zIndex.getValue(date)); expect(e.cylinder.show.getValue(date)).toEqual(constant.cylinder.show.getValue(date)); expect(e.cylinder.length.getValue(date)).toEqual(constant.cylinder.length.getValue(date)); expect(e.cylinder.topRadius.getValue(date)).toEqual(constant.cylinder.topRadius.getValue(date)); @@ -4553,6 +4561,7 @@ defineSuite([ expect(e.ellipse.numberOfVerticalLines.getValue(date)).toEqual(constant.ellipse.numberOfVerticalLines.getValue(date)); expect(e.ellipse.shadows.getValue(date)).toEqual(constant.ellipse.shadows.getValue(date)); expect(e.ellipse.distanceDisplayCondition.getValue(date)).toEqual(constant.ellipse.distanceDisplayCondition.getValue(date)); + expect(e.ellipse.zIndex.getValue(date)).toEqual(constant.ellipse.zIndex.getValue(date)); expect(e.ellipsoid.show.getValue(date)).toEqual(constant.ellipsoid.show.getValue(date)); expect(e.ellipsoid.radii.getValue(date)).toEqual(constant.ellipsoid.radii.getValue(date)); expect(e.ellipsoid.fill.getValue(date)).toEqual(constant.ellipsoid.fill.getValue(date)); @@ -4623,6 +4632,7 @@ defineSuite([ expect(e.point.disableDepthTestDistance.getValue(date)).toEqual(constant.point.disableDepthTestDistance.getValue(date)); expect(e.polygon.show.getValue(date)).toEqual(constant.polygon.show.getValue(date)); expect(e.polygon.hierarchy.getValue(date)).toEqual([dataSource.entities.getById('ConstantPosition1').position.getValue(date), dataSource.entities.getById('ConstantPosition2').position.getValue(date)]); + expect(e.polygon.arcType.getValue(date)).toEqual(constant.polygon.arcType.getValue(date)); expect(e.polygon.height.getValue(date)).toEqual(constant.polygon.height.getValue(date)); expect(e.polygon.extrudedHeight.getValue(date)).toEqual(constant.polygon.extrudedHeight.getValue(date)); expect(e.polygon.stRotation.getValue(date)).toEqual(constant.polygon.stRotation.getValue(date)); @@ -4637,15 +4647,18 @@ defineSuite([ expect(e.polygon.closeBottom.getValue(date)).toEqual(constant.polygon.closeBottom.getValue(date)); expect(e.polygon.shadows.getValue(date)).toEqual(constant.polygon.shadows.getValue(date)); expect(e.polygon.distanceDisplayCondition.getValue(date)).toEqual(constant.polygon.distanceDisplayCondition.getValue(date)); + expect(e.polygon.zIndex.getValue(date)).toEqual(constant.polygon.zIndex.getValue(date)); expect(e.polyline.show.getValue(date)).toEqual(constant.polyline.show.getValue(date)); expect(e.polyline.positions.getValue(date)).toEqual([dataSource.entities.getById('ConstantPosition1').position.getValue(date), dataSource.entities.getById('ConstantPosition2').position.getValue(date)]); + expect(e.polyline.arcType.getValue(date)).toEqual(constant.polyline.arcType.getValue(date)); expect(e.polyline.width.getValue(date)).toEqual(constant.polyline.width.getValue(date)); expect(e.polyline.granularity.getValue(date)).toEqual(constant.polyline.granularity.getValue(date)); expect(e.polyline.material.color.getValue(date)).toEqual(constant.polyline.material.color.getValue(date)); - expect(e.polyline.arcType.getValue(date)).toEqual(constant.polyline.arcType.getValue(date)); expect(e.polyline.shadows.getValue(date)).toEqual(constant.polyline.shadows.getValue(date)); expect(e.polyline.depthFailMaterial.color.getValue(date)).toEqual(constant.polyline.depthFailMaterial.color.getValue(date)); expect(e.polyline.distanceDisplayCondition.getValue(date)).toEqual(constant.polyline.distanceDisplayCondition.getValue(date)); + expect(e.polyline.clampToGround.getValue(date)).toEqual(constant.polyline.clampToGround.getValue(date)); + expect(e.polyline.zIndex.getValue(date)).toEqual(constant.polyline.zIndex.getValue(date)); expect(e.rectangle.show.getValue(date)).toEqual(constant.rectangle.show.getValue(date)); expect(e.rectangle.coordinates.getValue(date)).toEqual(constant.rectangle.coordinates.getValue(date)); expect(e.rectangle.height.getValue(date)).toEqual(constant.rectangle.height.getValue(date)); @@ -4660,6 +4673,7 @@ defineSuite([ expect(e.rectangle.outlineWidth.getValue(date)).toEqual(constant.rectangle.outlineWidth.getValue(date)); expect(e.rectangle.shadows.getValue(date)).toEqual(constant.rectangle.shadows.getValue(date)); expect(e.rectangle.distanceDisplayCondition.getValue(date)).toEqual(constant.rectangle.distanceDisplayCondition.getValue(date)); + expect(e.rectangle.zIndex.getValue(date)).toEqual(constant.rectangle.zIndex.getValue(date)); expect(e.wall.show.getValue(date)).toEqual(constant.wall.show.getValue(date)); expect(e.wall.positions.getValue(date)).toEqual([dataSource.entities.getById('ConstantPosition1').position.getValue(date), dataSource.entities.getById('ConstantPosition2').position.getValue(date)]); expect(e.wall.minimumHeights.getValue(date)).toEqual([dataSource.entities.getById('ConstantDouble1').billboard.scale.getValue(date), dataSource.entities.getById('ConstantDouble2').billboard.scale.getValue(date)]); @@ -5015,6 +5029,8 @@ defineSuite([ expect(e.corridor.outlineWidth.getValue(documentStopDate)).toEqual(57820.0); expect(e.corridor.distanceDisplayCondition.getValue(documentStartDate)).toEqual(new DistanceDisplayCondition(10884, 63530)); expect(e.corridor.distanceDisplayCondition.getValue(documentStopDate)).toEqual(new DistanceDisplayCondition(20076, 27683)); + expect(e.corridor.zIndex.getValue(documentStartDate)).toEqual(36068); + expect(e.corridor.zIndex.getValue(documentStopDate)).toEqual(60697); expect(e.cylinder.length.getValue(documentStartDate)).toEqual(30241.0); expect(e.cylinder.length.getValue(documentStopDate)).toEqual(48364.0); expect(e.cylinder.topRadius.getValue(documentStartDate)).toEqual(62881.0); @@ -5027,10 +5043,10 @@ defineSuite([ expect(e.cylinder.outlineColor.getValue(documentStopDate)).toEqual(Color.fromBytes(237, 75, 59, 51)); expect(e.cylinder.outlineWidth.getValue(documentStartDate)).toEqual(36483.0); expect(e.cylinder.outlineWidth.getValue(documentStopDate)).toEqual(32586.0); - expect(e.cylinder.numberOfVerticalLines.getValue(documentStartDate)).toEqual(45816.0); - expect(e.cylinder.numberOfVerticalLines.getValue(documentStopDate)).toEqual(42247.0); - expect(e.cylinder.slices.getValue(documentStartDate)).toEqual(46140.0); - expect(e.cylinder.slices.getValue(documentStopDate)).toEqual(53530.0); + expect(e.cylinder.numberOfVerticalLines.getValue(documentStartDate)).toEqual(45816); + expect(e.cylinder.numberOfVerticalLines.getValue(documentStopDate)).toEqual(42247); + expect(e.cylinder.slices.getValue(documentStartDate)).toEqual(46140); + expect(e.cylinder.slices.getValue(documentStopDate)).toEqual(53530); expect(e.cylinder.distanceDisplayCondition.getValue(documentStartDate)).toEqual(new DistanceDisplayCondition(2783, 57220)); expect(e.cylinder.distanceDisplayCondition.getValue(documentStopDate)).toEqual(new DistanceDisplayCondition(13855, 50230)); expect(e.ellipse.semiMajorAxis.getValue(documentStartDate)).toEqual(13136.0); @@ -5053,10 +5069,12 @@ defineSuite([ expect(e.ellipse.outlineColor.getValue(documentStopDate)).toEqual(Color.fromBytes(236, 100, 22, 203)); expect(e.ellipse.outlineWidth.getValue(documentStartDate)).toEqual(60636.0); expect(e.ellipse.outlineWidth.getValue(documentStopDate)).toEqual(24194.0); - expect(e.ellipse.numberOfVerticalLines.getValue(documentStartDate)).toEqual(52822.0); - expect(e.ellipse.numberOfVerticalLines.getValue(documentStopDate)).toEqual(45768.0); + expect(e.ellipse.numberOfVerticalLines.getValue(documentStartDate)).toEqual(52822); + expect(e.ellipse.numberOfVerticalLines.getValue(documentStopDate)).toEqual(45768); expect(e.ellipse.distanceDisplayCondition.getValue(documentStartDate)).toEqual(new DistanceDisplayCondition(38393, 63947)); expect(e.ellipse.distanceDisplayCondition.getValue(documentStopDate)).toEqual(new DistanceDisplayCondition(29119, 43121)); + expect(e.ellipse.zIndex.getValue(documentStartDate)).toEqual(8989); + expect(e.ellipse.zIndex.getValue(documentStopDate)).toEqual(52730); expect(e.ellipsoid.radii.getValue(documentStartDate)).toEqual(new Cartesian3(5183, 10004, 13863)); expect(e.ellipsoid.radii.getValue(documentStopDate)).toEqual(new Cartesian3(39497, 12186, 45103)); expect(e.ellipsoid.material.color.getValue(documentStartDate)).toEqual(Color.fromBytes(137, 128, 194, 84)); @@ -5069,8 +5087,8 @@ defineSuite([ expect(e.ellipsoid.stackPartitions.getValue(documentStopDate)).toEqual(39170); expect(e.ellipsoid.slicePartitions.getValue(documentStartDate)).toEqual(50327); expect(e.ellipsoid.slicePartitions.getValue(documentStopDate)).toEqual(4672); - expect(e.ellipsoid.subdivisions.getValue(documentStartDate)).toEqual(10225.0); - expect(e.ellipsoid.subdivisions.getValue(documentStopDate)).toEqual(53957.0); + expect(e.ellipsoid.subdivisions.getValue(documentStartDate)).toEqual(10225); + expect(e.ellipsoid.subdivisions.getValue(documentStopDate)).toEqual(53957); expect(e.ellipsoid.distanceDisplayCondition.getValue(documentStartDate)).toEqual(new DistanceDisplayCondition(11751, 59227)); expect(e.ellipsoid.distanceDisplayCondition.getValue(documentStopDate)).toEqual(new DistanceDisplayCondition(4769, 41441)); expect(e.label.scale.getValue(documentStartDate)).toEqual(40153.0); @@ -5159,6 +5177,8 @@ defineSuite([ expect(e.polygon.outlineWidth.getValue(documentStopDate)).toEqual(41508.0); expect(e.polygon.distanceDisplayCondition.getValue(documentStartDate)).toEqual(new DistanceDisplayCondition(22140, 31962)); expect(e.polygon.distanceDisplayCondition.getValue(documentStopDate)).toEqual(new DistanceDisplayCondition(3927, 22422)); + expect(e.polygon.zIndex.getValue(documentStartDate)).toEqual(37357); + expect(e.polygon.zIndex.getValue(documentStopDate)).toEqual(64769); expect(e.polyline.width.getValue(documentStartDate)).toEqual(60367.0); expect(e.polyline.width.getValue(documentStopDate)).toEqual(31077.0); expect(e.polyline.granularity.getValue(documentStartDate)).toEqual(62537.0); @@ -5169,6 +5189,8 @@ defineSuite([ expect(e.polyline.depthFailMaterial.color.getValue(documentStopDate)).toEqual(Color.fromBytes(76, 105, 5, 67)); expect(e.polyline.distanceDisplayCondition.getValue(documentStartDate)).toEqual(new DistanceDisplayCondition(4857, 10258)); expect(e.polyline.distanceDisplayCondition.getValue(documentStopDate)).toEqual(new DistanceDisplayCondition(36588, 47246)); + expect(e.polyline.zIndex.getValue(documentStartDate)).toEqual(55130); + expect(e.polyline.zIndex.getValue(documentStopDate)).toEqual(15491); expect(e.rectangle.coordinates.getValue(documentStartDate)).toEqual(new Rectangle(0.392205830501108, 1.04907471338688, 0.00211010473645246, 0.064281089310235)); expect(e.rectangle.coordinates.getValue(documentStopDate)).toEqual(new Rectangle(0.523469985903937, 0.229690388867811, 0.399550037703662, 0.48478405941078)); expect(e.rectangle.height.getValue(documentStartDate)).toEqual(56388.0); @@ -5189,6 +5211,8 @@ defineSuite([ expect(e.rectangle.outlineWidth.getValue(documentStopDate)).toEqual(33933.0); expect(e.rectangle.distanceDisplayCondition.getValue(documentStartDate)).toEqual(new DistanceDisplayCondition(24813, 30560)); expect(e.rectangle.distanceDisplayCondition.getValue(documentStopDate)).toEqual(new DistanceDisplayCondition(34617, 40071)); + expect(e.rectangle.zIndex.getValue(documentStartDate)).toEqual(27256); + expect(e.rectangle.zIndex.getValue(documentStopDate)).toEqual(53581); expect(e.wall.granularity.getValue(documentStartDate)).toEqual(64428.0); expect(e.wall.granularity.getValue(documentStopDate)).toEqual(25333.0); expect(e.wall.material.color.getValue(documentStartDate)).toEqual(Color.fromBytes(31, 188, 250, 46)); From 2d61eb012136c6019c1bfb37825463fffda6b9f1 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 1 Mar 2019 10:03:04 -0500 Subject: [PATCH 48/71] update for 1.55 --- Source/Core/Ion.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Ion.js b/Source/Core/Ion.js index da842defd437..180df00b75c1 100644 --- a/Source/Core/Ion.js +++ b/Source/Core/Ion.js @@ -9,7 +9,7 @@ define([ 'use strict'; var defaultTokenCredit; - var defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxMmRjYjRlZS05YjAzLTRmYTQtOTIxZS0wMjgzZjVjOGYxMzYiLCJpZCI6MjU5LCJzY29wZXMiOlsiYXNyIiwiZ2MiXSwiaWF0IjoxNTQ5MDM0MjI0fQ.Ree22k5kI_uYMLsV4a9L4INmNjE1VNxMQV0s3AOCcSs'; + var defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkZDJhY2VhYy0wYzljLTRiNWUtYmNhOC04OTQyZDk1YmZhMDkiLCJpZCI6MjU5LCJzY29wZXMiOlsiYXNyIiwiZ2MiXSwiaWF0IjoxNTUxNDUyMjc4fQ.B5BkE4TUBja1yOnT9sC6t8rrWghvVep21tzBq6r7aHo'; /** * Default settings for accessing the Cesium ion API. diff --git a/package.json b/package.json index 79c5ae7da0a8..57b8700b03b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cesium", - "version": "1.54.0", + "version": "1.55.0", "description": "CesiumJS is a JavaScript library for creating 3D globes and 2D maps in a web browser without a plugin.", "homepage": "http://cesiumjs.org", "license": "Apache-2.0", From 869cdd7573620e8bece43e9fe9562c4c475cf37b Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 1 Mar 2019 11:40:27 -0500 Subject: [PATCH 49/71] Fix FeatureDetection supportsWebP --- Source/Core/FeatureDetection.js | 53 ++++++++++++++++++----------- Source/Scene/ClassificationModel.js | 5 +-- Source/Scene/Model.js | 5 +-- Specs/Core/FeatureDetectionSpec.js | 16 +++++++-- Specs/Scene/ModelSpec.js | 8 ++++- 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/Source/Core/FeatureDetection.js b/Source/Core/FeatureDetection.js index 6d0d02346d1c..e124819f342e 100644 --- a/Source/Core/FeatureDetection.js +++ b/Source/Core/FeatureDetection.js @@ -1,12 +1,16 @@ define([ './defaultValue', './defined', + './defineProperties', + './DeveloperError', './Fullscreen', './RuntimeError', '../ThirdParty/when' ], function( defaultValue, defined, + defineProperties, + DeveloperError, Fullscreen, RuntimeError, when) { @@ -203,44 +207,54 @@ define([ return supportsImageRenderingPixelated() ? imageRenderingValueResult : undefined; } - var supportsWebPResult; - var supportsWebPPromise; function supportsWebP() { + //>>includeStart('debug', pragmas.debug); + if (!supportsWebP.initialized) { + throw new DeveloperError('You must call FeatureDetection.supportsWebP.initialize and wait for the promise to resolve before calling FeatureDetection.supportsWebP'); + } + //>>includeEnd('debug'); + return supportsWebP._result; + } + supportsWebP._promise = undefined; + supportsWebP._result = undefined; + supportsWebP.initialize = function() { // From https://developers.google.com/speed/webp/faq#how_can_i_detect_browser_support_for_webp - if (defined(supportsWebPPromise)) { - return supportsWebPPromise.promise; + if (defined(supportsWebP._promise)) { + return supportsWebP._promise; } - supportsWebPPromise = when.defer(); + var supportsWebPDeferred = when.defer(); + supportsWebP._promise = supportsWebPDeferred.promise; if (isEdge()) { // Edge's WebP support with WebGL is incomplete. // See bug report: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/19221241/ - supportsWebPResult = false; - supportsWebPPromise.resolve(supportsWebPResult); + supportsWebP._result = false; + supportsWebPDeferred.resolve(supportsWebP._result); + return supportsWebPDeferred.promise; } var image = new Image(); image.onload = function () { - supportsWebPResult = (image.width > 0) && (image.height > 0); - supportsWebPPromise.resolve(supportsWebPResult); + supportsWebP._result = (image.width > 0) && (image.height > 0); + supportsWebPDeferred.resolve(supportsWebP._result); }; image.onerror = function () { - supportsWebPResult = false; - supportsWebPPromise.resolve(supportsWebPResult); + supportsWebP._result = false; + supportsWebPDeferred.resolve(supportsWebP._result); }; image.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'; - return supportsWebPPromise.promise; - } - - function supportsWebPSync() { - if (!defined(supportsWebPPromise)) { - supportsWebP(); + return supportsWebPDeferred.promise; + }; + defineProperties(supportsWebP, { + initialized: { + get: function() { + return defined(supportsWebP._result); + } } - return supportsWebPResult; - } + }); var typedArrayTypes = []; if (typeof ArrayBuffer !== 'undefined') { @@ -279,7 +293,6 @@ define([ supportsPointerEvents : supportsPointerEvents, supportsImageRenderingPixelated: supportsImageRenderingPixelated, supportsWebP: supportsWebP, - supportsWebPSync: supportsWebPSync, imageRenderingValue: imageRenderingValue, typedArrayTypes: typedArrayTypes }; diff --git a/Source/Scene/ClassificationModel.js b/Source/Scene/ClassificationModel.js index 7cc5de623291..0c2053e5bf39 100644 --- a/Source/Scene/ClassificationModel.js +++ b/Source/Scene/ClassificationModel.js @@ -958,10 +958,11 @@ define([ return; } - var supportsWebP = FeatureDetection.supportsWebPSync(); - if (!defined(supportsWebP)) { + if (!FeatureDetection.supportsWebP.initialized) { + FeatureDetection.supportsWebP.initialize(); return; } + var supportsWebP = FeatureDetection.supportsWebP(); if ((this._state === ModelState.NEEDS_LOAD) && defined(this.gltf)) { this._state = ModelState.LOADING; diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 5f22e191f742..096628247372 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -4303,10 +4303,11 @@ define([ return; } - var supportsWebP = FeatureDetection.supportsWebPSync(); - if (!defined(supportsWebP)) { + if (!FeatureDetection.supportsWebP.initialized) { + FeatureDetection.supportsWebP.initialize(); return; } + var supportsWebP = FeatureDetection.supportsWebP(); var context = frameState.context; this._defaultTexture = context.defaultTexture; diff --git a/Specs/Core/FeatureDetectionSpec.js b/Specs/Core/FeatureDetectionSpec.js index 18c3eabf52b2..630faf531ef6 100644 --- a/Specs/Core/FeatureDetectionSpec.js +++ b/Specs/Core/FeatureDetectionSpec.js @@ -116,11 +116,23 @@ defineSuite([ } }); + it('supportWebP throws when it has not been initialized', function() { + FeatureDetection.supportsWebP._promise = undefined; + FeatureDetection.supportsWebP._result = undefined; + expect(function() { + FeatureDetection.supportsWebP(); + }).toThrowDeveloperError(); + }); + it('detects WebP support', function() { - return FeatureDetection.supportsWebP() + FeatureDetection.supportsWebP._promise = undefined; + FeatureDetection.supportsWebP._result = undefined; + + return FeatureDetection.supportsWebP.initialize() .then(function(supportsWebP) { expect(typeof supportsWebP).toEqual('boolean'); - expect(FeatureDetection.supportsWebPSync()).toEqual(supportsWebP); + expect(FeatureDetection.supportsWebP()).toEqual(supportsWebP); }); }); + }); diff --git a/Specs/Scene/ModelSpec.js b/Specs/Scene/ModelSpec.js index d38040b5447c..890c5c3db4ea 100644 --- a/Specs/Scene/ModelSpec.js +++ b/Specs/Scene/ModelSpec.js @@ -174,6 +174,7 @@ defineSuite([ modelPromises.push(loadModel(riggedFigureUrl).then(function(model) { riggedFigureModel = model; })); + modelPromises.push(FeatureDetection.supportsWebP.initialize()); return when.all(modelPromises); }); @@ -980,7 +981,8 @@ defineSuite([ }); it('Throws for EXT_texture_webp if browser does not support WebP', function() { - spyOn(FeatureDetection, 'supportsWebPSync').and.returnValue(false); + var supportsWebP = FeatureDetection.supportsWebP._result; + FeatureDetection.supportsWebP._result = false; return Resource.fetchJson(texturedBoxWebpUrl).then(function(gltf) { gltf.extensionsRequired = ['EXT_texture_webp']; var model = primitives.add(new Model({ @@ -991,6 +993,7 @@ defineSuite([ scene.renderForSpecs(); }).toThrowRuntimeError(); primitives.remove(model); + FeatureDetection.supportsWebP._result = supportsWebP; }); }); @@ -1206,6 +1209,9 @@ defineSuite([ }); it('renders textured box with WebP texture', function() { + if (!FeatureDetection.supportsWebP()) { + return; + } return loadModel(texturedBoxWebpUrl, { incrementallyLoadTextures : false }).then(function(m) { From dc77ddcde0f23217ff95ff1542bd206d65346b59 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 1 Mar 2019 11:52:28 -0500 Subject: [PATCH 50/71] fix rhumb lines in IE --- Source/Core/EllipsoidRhumbLine.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Core/EllipsoidRhumbLine.js b/Source/Core/EllipsoidRhumbLine.js index b79b449a7389..06c4ea8bcb45 100644 --- a/Source/Core/EllipsoidRhumbLine.js +++ b/Source/Core/EllipsoidRhumbLine.js @@ -20,6 +20,13 @@ define([ CesiumMath) { 'use strict'; + function sign(value) { + if (value < 0) { + return -1; + } + return 1; + } + function calculateM(ellipticity, major, latitude) { if (ellipticity === 0.0) { // sphere return major * latitude; @@ -417,7 +424,7 @@ define([ intersectionLongitude = CesiumMath.negativePiToPi(intersectionLongitude); if (CesiumMath.equalsEpsilon(Math.abs(intersectionLongitude), Math.PI, CesiumMath.EPSILON14)) { - intersectionLongitude = Math.sign(start.longitude) * Math.PI; + intersectionLongitude = sign(start.longitude) * Math.PI; } if (!defined(result)) { @@ -437,7 +444,7 @@ define([ } result.longitude = intersectionLongitude; - result.latitude = CesiumMath.PI_OVER_TWO * Math.sign(CesiumMath.PI_OVER_TWO - heading); + result.latitude = CesiumMath.PI_OVER_TWO * sign(CesiumMath.PI_OVER_TWO - heading); result.height = 0; return result; } From 6ea9c5f833b7ab0286e048cfd846c8f6f32278c6 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 1 Mar 2019 13:24:35 -0500 Subject: [PATCH 51/71] use CesiumMath.sign --- Source/Core/EllipsoidRhumbLine.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Source/Core/EllipsoidRhumbLine.js b/Source/Core/EllipsoidRhumbLine.js index 06c4ea8bcb45..fbf04272319b 100644 --- a/Source/Core/EllipsoidRhumbLine.js +++ b/Source/Core/EllipsoidRhumbLine.js @@ -20,13 +20,6 @@ define([ CesiumMath) { 'use strict'; - function sign(value) { - if (value < 0) { - return -1; - } - return 1; - } - function calculateM(ellipticity, major, latitude) { if (ellipticity === 0.0) { // sphere return major * latitude; @@ -424,7 +417,7 @@ define([ intersectionLongitude = CesiumMath.negativePiToPi(intersectionLongitude); if (CesiumMath.equalsEpsilon(Math.abs(intersectionLongitude), Math.PI, CesiumMath.EPSILON14)) { - intersectionLongitude = sign(start.longitude) * Math.PI; + intersectionLongitude = CesiumMath.sign(start.longitude) * Math.PI; } if (!defined(result)) { @@ -444,7 +437,7 @@ define([ } result.longitude = intersectionLongitude; - result.latitude = CesiumMath.PI_OVER_TWO * sign(CesiumMath.PI_OVER_TWO - heading); + result.latitude = CesiumMath.PI_OVER_TWO * CesiumMath.sign(CesiumMath.PI_OVER_TWO - heading); result.height = 0; return result; } From f3caa601ec64eae100e0cd4dc0b3667f2a71b85e Mon Sep 17 00:00:00 2001 From: Hannah Date: Fri, 1 Mar 2019 14:34:50 -0500 Subject: [PATCH 52/71] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index f5cd3437b3ce..e616b8483691 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ Change Log * `czm_materialInput.slope` is now an angle in radians between 0 and pi/2 (flat to vertical), rather than a projected length 1 to 0 (flat to vertical). ##### Additions :tada: +* Updated terrain and imagery rendering, resulting in terrain/imagery loading ~33% faster and using ~33% less data [#7061](https://github.com/AnalyticalGraphicsInc/cesium/pull/7061) * `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). * Added CZML `arcType` support for `polyline` and `polygon`, which supersedes `followSurface`. `followSurface` is still supported for compatibility with existing documents. [#7582](https://github.com/AnalyticalGraphicsInc/cesium/pull/7582) From f1ee4eedaed418ec60c1558d32a572e1ffaf7ed4 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Mon, 4 Mar 2019 11:22:37 -0500 Subject: [PATCH 53/71] Tweak wording for requestRenderMode --- Source/Widgets/Viewer/Viewer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Widgets/Viewer/Viewer.js b/Source/Widgets/Viewer/Viewer.js index d9664a7bb540..f35612ad9f0a 100644 --- a/Source/Widgets/Viewer/Viewer.js +++ b/Source/Widgets/Viewer/Viewer.js @@ -299,7 +299,7 @@ define([ * @param {ShadowMode} [options.terrainShadows=ShadowMode.RECEIVE_ONLY] Determines if the terrain casts or receives shadows from the sun. * @param {MapMode2D} [options.mapMode2D=MapMode2D.INFINITE_SCROLL] Determines if the 2D map is rotatable or can be scrolled infinitely in the horizontal direction. * @param {Boolean} [options.projectionPicker=false] If set to true, the ProjectionPicker widget will be created. - * @param {Boolean} [options.requestRenderMode=false] If true, rendering a frame will only occur when needed as determined by changes within the scene. Enabling improves performance of the application, but requires using {@link Scene#requestRender} to render a new frame explicitly in this mode. This will be necessary in many cases after making changes to the scene in other parts of the API. See {@link https://cesium.com/blog/2018/01/24/cesium-scene-rendering-performance/|Improving Performance with Explicit Rendering}. + * @param {Boolean} [options.requestRenderMode=false] If true, rendering a frame will only occur when needed as determined by changes within the scene. Enabling reduces the CPU/GPU usage of your application and uses less battery on mobile, but requires using {@link Scene#requestRender} to render a new frame explicitly in this mode. This will be necessary in many cases after making changes to the scene in other parts of the API. See {@link https://cesium.com/blog/2018/01/24/cesium-scene-rendering-performance/|Improving Performance with Explicit Rendering}. * @param {Number} [options.maximumRenderTimeChange=0.0] If requestRenderMode is true, this value defines the maximum change in simulation time allowed before a render is requested. See {@link https://cesium.com/blog/2018/01/24/cesium-scene-rendering-performance/|Improving Performance with Explicit Rendering}. * * @exception {DeveloperError} Element with id "container" does not exist in the document. From 0964441df2b822b4812bd4a35d806a244de90f2c Mon Sep 17 00:00:00 2001 From: Shehata Date: Mon, 4 Mar 2019 17:48:13 -0500 Subject: [PATCH 54/71] Move ImageBitmap changes to 1.56 --- CHANGES.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index dedff621e21a..73dc545ddd72 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,19 +1,25 @@ Change Log ========== -### 1.55 - 2019-03-01 +### 1.56 - 2019-04-01 ##### Breaking Changes :mega: -* `czm_materialInput.slope` is now an angle in radians between 0 and pi/2 (flat to vertical), rather than a projected length 1 to 0 (flat to vertical). * `Resource.fetchImage` now returns an `ImageBitmap` instead of `Image` when supported. This allows for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) ##### Deprecated :hourglass_flowing_sand: * `Resource.fetchImage` now takes an options object. Use `resource.fetchImage({ preferBlob: true })` instead of `resource.fetchImage(true)`. The previous function definition will no longer work in 1.56. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) ##### Additions :tada: -* `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). * `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode. It is only valid when `ImageBitmapOptions` is supported by the browser. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) +### 1.55 - 2019-03-01 + +##### Breaking Changes :mega: +* `czm_materialInput.slope` is now an angle in radians between 0 and pi/2 (flat to vertical), rather than a projected length 1 to 0 (flat to vertical). + +##### Additions :tada: +* `czm_materialInput.aspect` was added as an angle in radians between 0 and 2pi (east, north, west to south). + ##### Fixes :wrench: * Fixed an issue where models would cause a crash on load if some primitives were Draco encoded and others were not. [#7383](https://github.com/AnalyticalGraphicsInc/cesium/issues/7383) * Fixed an issue where RTL labels not reversing correctly non alphabetic characters [#7501](https://github.com/AnalyticalGraphicsInc/cesium/pull/7501) From 0b878e73b183d5129c225bd416b2cb1189d1d68c Mon Sep 17 00:00:00 2001 From: Shehata Date: Mon, 4 Mar 2019 18:48:31 -0500 Subject: [PATCH 55/71] Only use createImageBitmap when options are supported --- Source/Core/Resource.js | 94 +++++++++++++------ Source/Core/loadImageFromTypedArray.js | 15 +-- Specs/Core/ResourceSpec.js | 11 ++- .../ArcGisMapServerImageryProviderSpec.js | 4 +- Specs/Scene/BingMapsImageryProviderSpec.js | 2 +- .../DiscardMissingTileImagePolicySpec.js | 2 +- ...oogleEarthEnterpriseImageryProviderSpec.js | 5 +- .../GoogleEarthEnterpriseMapsProviderSpec.js | 10 +- Specs/isImageOrImageBitmap.js | 8 +- 9 files changed, 98 insertions(+), 53 deletions(-) diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index 304c574b9a6d..25b99ca6114e 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -376,6 +376,7 @@ define([ }); }; + var supportsImageBitmapOptionsResult; var supportsImageBitmapOptionsPromise; /** * A helper function to check whether createImageBitmap supports passing ImageBitmapOptions. @@ -393,7 +394,8 @@ define([ } if (!FeatureDetection.supportsCreateImageBitmap()) { - supportsImageBitmapOptionsPromise = when.resolve(false); + supportsImageBitmapOptionsResult = false; + supportsImageBitmapOptionsPromise = when.resolve(supportsImageBitmapOptionsResult); return supportsImageBitmapOptionsPromise; } @@ -408,15 +410,32 @@ define([ }); }) .then(function(imageBitmap) { - return true; + supportsImageBitmapOptionsResult = true; + return supportsImageBitmapOptionsResult; }) .otherwise(function() { - return false; + supportsImageBitmapOptionsResult = false; + return supportsImageBitmapOptionsResult; }); return supportsImageBitmapOptionsPromise; }; + /** + * Same as Resource.supportsImageBitmapOptions but synchronous. If the result is not ready, returns undefined. + * + * @returns {Boolean} True if this browser supports creating an ImageBitmap with options. + * + * @private + */ + Resource.supportsImageBitmapOptionsSync = function() { + if (!defined(supportsImageBitmapOptionsPromise)) { + Resource.supportsImageBitmapOptions(); + } + + return supportsImageBitmapOptionsResult; + }; + defineProperties(Resource, { /** * Returns true if blobs are supported. @@ -1821,39 +1840,54 @@ define([ */ Resource._Implementations = {}; - Resource._Implementations.createImage = function(url, crossOrigin, deferred, flipY) { - if (!FeatureDetection.supportsCreateImageBitmap()) { - var image = new Image(); + function loadImageElement(url, crossOrigin, deferred) { + var image = new Image(); - image.onload = function() { - deferred.resolve(image); - }; + image.onload = function() { + deferred.resolve(image); + }; - image.onerror = function(e) { - deferred.reject(e); - }; + image.onerror = function(e) { + deferred.reject(e); + }; - if (crossOrigin) { - if (TrustedServers.contains(url)) { - image.crossOrigin = 'use-credentials'; - } else { - image.crossOrigin = ''; - } + if (crossOrigin) { + if (TrustedServers.contains(url)) { + image.crossOrigin = 'use-credentials'; + } else { + image.crossOrigin = ''; } + } - image.src = url; - } else { - // Passing an Image to createImageBitmap will force it to run on the main thread - // since DOM elements don't exist on workers. We convert it to a blob so it's non-blocking. - // See: - // https://bugzilla.mozilla.org/show_bug.cgi?id=1044102#c38 - // https://bugs.chromium.org/p/chromium/issues/detail?id=580202#c10 - Resource.fetchBlob({ - url: url - }).then(function(blob) { - return Resource._Implementations.createImageBitmapFromBlob(blob, flipY); - }).then(deferred.resolve).otherwise(deferred.reject); + image.src = url; + } + + Resource._Implementations.createImage = function(url, crossOrigin, deferred, flipY) { + if (!FeatureDetection.supportsCreateImageBitmap()) { + loadImageElement(url, crossOrigin, deferred); + return; } + + // Passing an Image to createImageBitmap will force it to run on the main thread + // since DOM elements don't exist on workers. We convert it to a blob so it's non-blocking. + // See: + // https://bugzilla.mozilla.org/show_bug.cgi?id=1044102#c38 + // https://bugs.chromium.org/p/chromium/issues/detail?id=580202#c10 + Resource.supportsImageBitmapOptions() + .then(function(result) { + // We can only use ImageBitmap if we can flip on decode. + // See: https://github.com/AnalyticalGraphicsInc/cesium/pull/7579#issuecomment-466146898 + if (!result) { + loadImageElement(url, crossOrigin, deferred); + return; + } + + Resource.fetchBlob({ + url: url + }).then(function(blob) { + return Resource._Implementations.createImageBitmapFromBlob(blob, flipY); + }).then(deferred.resolve).otherwise(deferred.reject); + }); }; Resource._Implementations.createImageBitmapFromBlob = function(blob, flipY) { diff --git a/Source/Core/loadImageFromTypedArray.js b/Source/Core/loadImageFromTypedArray.js index 7ae09f8a30c8..857fdae18844 100644 --- a/Source/Core/loadImageFromTypedArray.js +++ b/Source/Core/loadImageFromTypedArray.js @@ -33,17 +33,10 @@ define([ // Avoid an extra fetch by just calling createImageBitmap here directly on the blob // instead of sending it to Resource as a blob URL. - if (FeatureDetection.supportsCreateImageBitmap()) { - return Resource.supportsImageBitmapOptions() - .then(function(supportsBitmapOptions) { - if (supportsBitmapOptions) { - return createImageBitmap(blob, { - imageOrientation: flipY ? 'flipY' : 'none' - }); - } - - return createImageBitmap(blob); - }); + if (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync()) { + return when(createImageBitmap(blob, { + imageOrientation: flipY ? 'flipY' : 'none' + })); } var blobUrl = window.URL.createObjectURL(blob); diff --git a/Specs/Core/ResourceSpec.js b/Specs/Core/ResourceSpec.js index cac4e31efe6f..8cf4b4cbf5e5 100644 --- a/Specs/Core/ResourceSpec.js +++ b/Specs/Core/ResourceSpec.js @@ -1165,6 +1165,13 @@ defineSuite([ return [imageData.data[0], imageData.data[1], imageData.data[2], imageData.data[3]]; } + it('can call supportsImageBitmapOptions and supportsImageBitmapOptionsSync', function() { + return Resource.supportsImageBitmapOptions() + .then(function(result) { + expect(Resource.supportsImageBitmapOptionsSync()).toEqual(result); + }); + }); + it('can load and decode an image', function() { return Resource.fetchImage('./Data/Images/Green.png').then(function(loadedImage) { expect(loadedImage.width).toEqual(1); @@ -1209,12 +1216,12 @@ defineSuite([ }); }); - it('does not pass options when ImageBitmapOptions are not supported', function() { + it('does not use ImageBitmap when ImageBitmapOptions are not supported', function() { spyOn(Resource, 'supportsImageBitmapOptions').and.returnValue(when.resolve(false)); spyOn(window, 'createImageBitmap').and.callThrough(); return Resource.fetchImage('./Data/Images/Green.png').then(function(loadedImage) { - expect(window.createImageBitmap).toHaveBeenCalledWith(new Blob()); + expect(window.createImageBitmap).not.toHaveBeenCalledWith(); }); }); diff --git a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js index 9cc36109f138..f5ef14c6bbec 100644 --- a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js +++ b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js @@ -292,7 +292,7 @@ defineSuite([ expect(provider.usingPrecachedTiles).toEqual(true); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { + if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { @@ -465,7 +465,7 @@ defineSuite([ expect(provider.hasAlphaChannel).toBeDefined(); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { + if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { diff --git a/Specs/Scene/BingMapsImageryProviderSpec.js b/Specs/Scene/BingMapsImageryProviderSpec.js index 0a4b093b6872..591078729dc9 100644 --- a/Specs/Scene/BingMapsImageryProviderSpec.js +++ b/Specs/Scene/BingMapsImageryProviderSpec.js @@ -177,7 +177,7 @@ defineSuite([ function installFakeImageRequest(expectedUrl, expectedParams, proxy) { Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { + if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { diff --git a/Specs/Scene/DiscardMissingTileImagePolicySpec.js b/Specs/Scene/DiscardMissingTileImagePolicySpec.js index d84d40a3a03d..2f303bf9d21b 100644 --- a/Specs/Scene/DiscardMissingTileImagePolicySpec.js +++ b/Specs/Scene/DiscardMissingTileImagePolicySpec.js @@ -70,7 +70,7 @@ defineSuite([ return pollToPromise(function() { return policy.isReady(); }).then(function() { - if (FeatureDetection.supportsCreateImageBitmap()) { + if ((FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { expect(Resource._Implementations.createImageBitmapFromBlob).toHaveBeenCalled(); } else { expect(Resource._Implementations.createImage).toHaveBeenCalled(); diff --git a/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js index b584b6580ad6..68d98060d4f8 100644 --- a/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js @@ -4,6 +4,7 @@ defineSuite([ 'Core/DefaultProxy', 'Core/defaultValue', 'Core/defined', + 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/GoogleEarthEnterpriseMetadata', 'Core/GoogleEarthEnterpriseTileInformation', @@ -25,6 +26,7 @@ defineSuite([ DefaultProxy, defaultValue, defined, + FeatureDetection, GeographicTilingScheme, GoogleEarthEnterpriseMetadata, GoogleEarthEnterpriseTileInformation, @@ -44,6 +46,7 @@ defineSuite([ beforeEach(function() { RequestScheduler.clearForSpecs(); + return Resource.supportsImageBitmapOptions(); }); beforeAll(function() { @@ -86,7 +89,7 @@ defineSuite([ function installFakeImageRequest(expectedUrl, proxy) { Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url)) { + if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { // load blob url normally Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { diff --git a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js index 4d7a67ca1005..2b3be052cd94 100644 --- a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js @@ -30,6 +30,12 @@ defineSuite([ isImageOrImageBitmap) { 'use strict'; + beforeAll(function() { + // This suite spies on requests. The test below needs to make a request to a data URI. + // We run it here to avoid interfering with the tests. + return Resource.supportsImageBitmapOptions(); + }); + afterEach(function() { Resource._Implementations.createImage = Resource._DefaultImplementations.createImage; Resource._Implementations.loadWithXhr = Resource._DefaultImplementations.loadWithXhr; @@ -176,7 +182,7 @@ defineSuite([ expect(provider.credit).toBeInstanceOf(Object); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { + if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { @@ -294,7 +300,7 @@ defineSuite([ }); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || FeatureDetection.supportsCreateImageBitmap()) { + if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else if (tries === 2) { diff --git a/Specs/isImageOrImageBitmap.js b/Specs/isImageOrImageBitmap.js index 810cf452548c..5604e91a8e08 100644 --- a/Specs/isImageOrImageBitmap.js +++ b/Specs/isImageOrImageBitmap.js @@ -1,14 +1,16 @@ define([ - 'Core/FeatureDetection' + 'Core/FeatureDetection', + 'Core/Resource' ], function( - FeatureDetection) { + FeatureDetection, + Resource) { 'use strict'; function isImageOrImageBitmap(image) { // Many ImageryProvider specs will test if the requested image // succeeded by checking its instance. Since this may be an Image // or ImageBitmap, we abstract this check here. - if (FeatureDetection.supportsCreateImageBitmap()) { + if (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync()) { return image instanceof ImageBitmap; } From d2cc1733275bf5d4d5218dab5f82c9ae713d86ab Mon Sep 17 00:00:00 2001 From: Shehata Date: Mon, 4 Mar 2019 19:06:04 -0500 Subject: [PATCH 56/71] Fix Firefox specs --- Source/Core/Resource.js | 2 +- Specs/Core/ResourceSpec.js | 25 ++++++++++++++ Specs/Core/loadImageFromTypedArraySpec.js | 40 ++++++++++------------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index 25b99ca6114e..a38f28e3f538 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -941,7 +941,7 @@ define([ return; } - if (FeatureDetection.supportsCreateImageBitmap()) { + if (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync()) { return blobPromise .then(function(blob) { return Resource._Implementations.createImageBitmapFromBlob(blob, flipY); diff --git a/Specs/Core/ResourceSpec.js b/Specs/Core/ResourceSpec.js index 8cf4b4cbf5e5..8f70d443a149 100644 --- a/Specs/Core/ResourceSpec.js +++ b/Specs/Core/ResourceSpec.js @@ -1152,6 +1152,7 @@ defineSuite([ var canvas; beforeAll(function() { canvas = createCanvas(1, 2); + return Resource.supportsImageBitmapOptions(); }); afterAll(function() { @@ -1166,6 +1167,10 @@ defineSuite([ } it('can call supportsImageBitmapOptions and supportsImageBitmapOptionsSync', function() { + if (!Resource.supportsImageBitmapOptionsSync()) { + return; + } + return Resource.supportsImageBitmapOptions() .then(function(result) { expect(Resource.supportsImageBitmapOptionsSync()).toEqual(result); @@ -1173,6 +1178,10 @@ defineSuite([ }); it('can load and decode an image', function() { + if (!Resource.supportsImageBitmapOptionsSync()) { + return; + } + return Resource.fetchImage('./Data/Images/Green.png').then(function(loadedImage) { expect(loadedImage.width).toEqual(1); expect(loadedImage.height).toEqual(1); @@ -1181,6 +1190,10 @@ defineSuite([ }); it('correctly flips image when ImageBitmapOptions are supported', function() { + if (!Resource.supportsImageBitmapOptionsSync()) { + return; + } + var loadedImage; return Resource.fetchImage({ @@ -1199,6 +1212,10 @@ defineSuite([ }); it('correctly loads image without flip when ImageBitmapOptions are supported', function() { + if (!Resource.supportsImageBitmapOptionsSync()) { + return; + } + var loadedImage; return Resource.fetchImage({ @@ -1217,6 +1234,10 @@ defineSuite([ }); it('does not use ImageBitmap when ImageBitmapOptions are not supported', function() { + if (!Resource.supportsImageBitmapOptionsSync()) { + return; + } + spyOn(Resource, 'supportsImageBitmapOptions').and.returnValue(when.resolve(false)); spyOn(window, 'createImageBitmap').and.callThrough(); @@ -1226,6 +1247,10 @@ defineSuite([ }); it('rejects the promise when the image errors', function() { + if (!Resource.supportsImageBitmapOptionsSync()) { + return; + } + return Resource.fetchImage('http://example.invalid/testuri.png') .then(function() { fail('expected promise to reject'); diff --git a/Specs/Core/loadImageFromTypedArraySpec.js b/Specs/Core/loadImageFromTypedArraySpec.js index 052e3f2d5d06..16013ee3bd06 100644 --- a/Specs/Core/loadImageFromTypedArraySpec.js +++ b/Specs/Core/loadImageFromTypedArraySpec.js @@ -22,7 +22,7 @@ defineSuite([ }); }); - it('flips image when ImageBitmapOptions are supported', function() { + it('flips image only when flipY is true', function() { var options = { uint8Array: new Uint8Array([67, 101, 115, 105, 117, 109]), // This is an invalid PNG. format: 'image/png', @@ -32,32 +32,28 @@ defineSuite([ var blob = new Blob([options.uint8Array], { type : options.format }); - var supportsImageBitmapOptions; - return loadImageFromTypedArray(options) - .then(Resource.supportsImageBitmapOptions) + return Resource.supportsImageBitmapOptions() .then(function(result) { - supportsImageBitmapOptions = result; - if (supportsImageBitmapOptions) { - expect(window.createImageBitmap).toHaveBeenCalledWith(blob, { - imageOrientation: 'flipY' - }); - } else { - expect(window.createImageBitmap).toHaveBeenCalledWith(blob); + if (!result) { + return; } - options.flipY = false; - window.createImageBitmap.calls.reset(); - return loadImageFromTypedArray(options); - }) - .then(function() { - if (supportsImageBitmapOptions) { - expect(window.createImageBitmap).toHaveBeenCalledWith(blob, { - imageOrientation: 'none' + return loadImageFromTypedArray(options) + .then(function() { + expect(window.createImageBitmap).toHaveBeenCalledWith(blob, { + imageOrientation: 'flipY' + }); + + window.createImageBitmap.calls.reset(); + options.flipY = false; + return loadImageFromTypedArray(options); + }) + .then(function() { + expect(window.createImageBitmap).toHaveBeenCalledWith(blob, { + imageOrientation: 'none' + }); }); - } else { - expect(window.createImageBitmap).toHaveBeenCalledWith(blob); - } }); }); From 9c73afb4fe76464ae0f7d945c5424fdd68060ef9 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 5 Mar 2019 10:03:16 -0500 Subject: [PATCH 57/71] Fix BlendFunction.ONE_MINUS_CONSTANT_COLOR --- CHANGES.md | 5 +++++ Source/Scene/BlendFunction.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index e616b8483691..8cea9b58cb51 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,11 @@ Change Log ========== +### 1.56 - 2019-04-01 + +##### Fixes :wrench: +* Fixed the value for `BlendFunction.ONE_MINUS_CONSTANT_COLOR`. + ### 1.55 - 2019-03-01 ##### Breaking Changes :mega: diff --git a/Source/Scene/BlendFunction.js b/Source/Scene/BlendFunction.js index fd7a0d196762..f1d17c7b4952 100644 --- a/Source/Scene/BlendFunction.js +++ b/Source/Scene/BlendFunction.js @@ -106,7 +106,7 @@ define([ * @type {Number} * @constant */ - ONE_MINUS_CONSTANT_COLOR : WebGLConstants.ONE_MINUS_CONSTANT_ALPHA, + ONE_MINUS_CONSTANT_COLOR : WebGLConstants.ONE_MINUS_CONSTANT_COLOR, /** * The blend factor is the constant alpha. From 4faadd266b75b7b357c2f9b7fbcb2f7fae1af0f6 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 5 Mar 2019 10:07:02 -0500 Subject: [PATCH 58/71] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 8cea9b58cb51..d9cc6fca297f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ Change Log ### 1.56 - 2019-04-01 ##### Fixes :wrench: -* Fixed the value for `BlendFunction.ONE_MINUS_CONSTANT_COLOR`. +* Fixed the value for `BlendFunction.ONE_MINUS_CONSTANT_COLOR`. [#7624](https://github.com/AnalyticalGraphicsInc/cesium/pull/7624) ### 1.55 - 2019-03-01 From a6324e2bcf8b3547b4adb589e7ee789321997678 Mon Sep 17 00:00:00 2001 From: Shehata Date: Fri, 8 Mar 2019 16:22:38 -0500 Subject: [PATCH 59/71] Remove FeatureDetection.supportsCreateImageBitmap --- Source/Core/FeatureDetection.js | 5 -- Source/Core/Resource.js | 82 +++++++++---------- Source/Core/loadImageFromTypedArray.js | 15 ++-- Specs/Core/FeatureDetectionSpec.js | 5 -- Specs/Core/ResourceSpec.js | 43 +++------- Specs/Core/loadImageFromTypedArraySpec.js | 12 +-- .../ArcGisMapServerImageryProviderSpec.js | 14 ++-- Specs/Scene/BingMapsImageryProviderSpec.js | 14 +++- .../DiscardMissingTileImagePolicySpec.js | 12 +-- ...oogleEarthEnterpriseImageryProviderSpec.js | 14 ++-- .../GoogleEarthEnterpriseMapsProviderSpec.js | 14 ++-- Specs/isImageOrImageBitmap.js | 7 +- 12 files changed, 107 insertions(+), 130 deletions(-) diff --git a/Source/Core/FeatureDetection.js b/Source/Core/FeatureDetection.js index 4392946224b3..620fafa3f8d5 100644 --- a/Source/Core/FeatureDetection.js +++ b/Source/Core/FeatureDetection.js @@ -267,10 +267,6 @@ define([ } } - function supportsCreateImageBitmap() { - return typeof createImageBitmap === 'function'; - } - /** * A set of functions to detect whether the current browser supports * various features. @@ -295,7 +291,6 @@ define([ supportsPointerEvents : supportsPointerEvents, supportsImageRenderingPixelated: supportsImageRenderingPixelated, supportsWebP: supportsWebP, - supportsCreateImageBitmap: supportsCreateImageBitmap, imageRenderingValue: imageRenderingValue, typedArrayTypes: typedArrayTypes }; diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index a38f28e3f538..9034d45d0a7b 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -376,7 +376,6 @@ define([ }); }; - var supportsImageBitmapOptionsResult; var supportsImageBitmapOptionsPromise; /** * A helper function to check whether createImageBitmap supports passing ImageBitmapOptions. @@ -393,9 +392,8 @@ define([ return supportsImageBitmapOptionsPromise; } - if (!FeatureDetection.supportsCreateImageBitmap()) { - supportsImageBitmapOptionsResult = false; - supportsImageBitmapOptionsPromise = when.resolve(supportsImageBitmapOptionsResult); + if (typeof createImageBitmap !== 'function') { + supportsImageBitmapOptionsPromise = when.resolve(false); return supportsImageBitmapOptionsPromise; } @@ -410,32 +408,15 @@ define([ }); }) .then(function(imageBitmap) { - supportsImageBitmapOptionsResult = true; - return supportsImageBitmapOptionsResult; + return true; }) .otherwise(function() { - supportsImageBitmapOptionsResult = false; - return supportsImageBitmapOptionsResult; + return false; }); return supportsImageBitmapOptionsPromise; }; - /** - * Same as Resource.supportsImageBitmapOptions but synchronous. If the result is not ready, returns undefined. - * - * @returns {Boolean} True if this browser supports creating an ImageBitmap with options. - * - * @private - */ - Resource.supportsImageBitmapOptionsSync = function() { - if (!defined(supportsImageBitmapOptionsPromise)) { - Resource.supportsImageBitmapOptions(); - } - - return supportsImageBitmapOptionsResult; - }; - defineProperties(Resource, { /** * Returns true if blobs are supported. @@ -916,7 +897,7 @@ define([ */ Resource.prototype.fetchImage = function (options) { if (typeof options === 'boolean') { - deprecationWarning('fetchImage-parameter-change', 'fetchImage now takes an options object in CesiumJS 1.55. Use resource.fetchImage({ preferBlob: true }) instead of resource.fetchImage(true).'); + deprecationWarning('fetchImage-parameter-change', 'fetchImage now takes an options object in CesiumJS 1.56. Use resource.fetchImage({ preferBlob: true }) instead of resource.fetchImage(true).'); options = { preferBlob : options }; @@ -941,21 +922,21 @@ define([ return; } - if (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync()) { - return blobPromise - .then(function(blob) { - return Resource._Implementations.createImageBitmapFromBlob(blob, flipY); - }); - } - + var supportsImageBitmap; var generatedBlobResource; var generatedBlob; - return blobPromise + return Resource.supportsImageBitmapOptions() + .then(function(result) { + supportsImageBitmap = result; + return blobPromise; + }) .then(function(blob) { if (!defined(blob)) { return; } - + if (supportsImageBitmap) { + return Resource._Implementations.createImageBitmapFromBlob(blob, flipY); + } generatedBlob = blob; var blobUrl = window.URL.createObjectURL(blob); generatedBlobResource = new Resource({ @@ -968,6 +949,9 @@ define([ if (!defined(image)) { return; } + if (supportsImageBitmap) { + return image; + } window.URL.revokeObjectURL(generatedBlobResource.url); // This is because the blob object is needed for DiscardMissingTileImagePolicy @@ -1863,11 +1847,6 @@ define([ } Resource._Implementations.createImage = function(url, crossOrigin, deferred, flipY) { - if (!FeatureDetection.supportsCreateImageBitmap()) { - loadImageElement(url, crossOrigin, deferred); - return; - } - // Passing an Image to createImageBitmap will force it to run on the main thread // since DOM elements don't exist on workers. We convert it to a blob so it's non-blocking. // See: @@ -1882,18 +1861,31 @@ define([ return; } - Resource.fetchBlob({ + return Resource.fetchBlob({ url: url - }).then(function(blob) { - return Resource._Implementations.createImageBitmapFromBlob(blob, flipY); - }).then(deferred.resolve).otherwise(deferred.reject); - }); + }); + }) + .then(function(blob) { + if (!defined(blob)) { + return; + } + + return Resource._Implementations.createImageBitmapFromBlob(blob, flipY); + }) + .then(function(imageBitmap) { + if (!defined(imageBitmap)) { + return; + } + + deferred.resolve(imageBitmap); + }) + .otherwise(deferred.reject); }; Resource._Implementations.createImageBitmapFromBlob = function(blob, flipY) { return Resource.supportsImageBitmapOptions() - .then(function(supportsBitmapOptions) { - if (!supportsBitmapOptions) { + .then(function(result) { + if (!result) { return createImageBitmap(blob); } diff --git a/Source/Core/loadImageFromTypedArray.js b/Source/Core/loadImageFromTypedArray.js index 857fdae18844..0ee8cc375c01 100644 --- a/Source/Core/loadImageFromTypedArray.js +++ b/Source/Core/loadImageFromTypedArray.js @@ -31,24 +31,19 @@ define([ type : format }); - // Avoid an extra fetch by just calling createImageBitmap here directly on the blob - // instead of sending it to Resource as a blob URL. - if (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync()) { - return when(createImageBitmap(blob, { - imageOrientation: flipY ? 'flipY' : 'none' - })); - } - var blobUrl = window.URL.createObjectURL(blob); var resource = new Resource({ url: blobUrl, request: request }); - return resource.fetchImage() + return resource.fetchImage({ + flipY : flipY + }) .then(function(image) { window.URL.revokeObjectURL(blobUrl); return image; - }, function(error) { + }) + .otherwise(function(error) { window.URL.revokeObjectURL(blobUrl); return when.reject(error); }); diff --git a/Specs/Core/FeatureDetectionSpec.js b/Specs/Core/FeatureDetectionSpec.js index 85490be8bd6a..eb8d4d909d8d 100644 --- a/Specs/Core/FeatureDetectionSpec.js +++ b/Specs/Core/FeatureDetectionSpec.js @@ -134,9 +134,4 @@ defineSuite([ expect(FeatureDetection.supportsWebP()).toEqual(supportsWebP); }); }); - - it('detects createImageBitmap support', function() { - var supportsCreateImageBitmap = FeatureDetection.supportsCreateImageBitmap(); - expect(typeof supportsCreateImageBitmap).toEqual('boolean'); - }); }); diff --git a/Specs/Core/ResourceSpec.js b/Specs/Core/ResourceSpec.js index 8f70d443a149..9203cd4e9c93 100644 --- a/Specs/Core/ResourceSpec.js +++ b/Specs/Core/ResourceSpec.js @@ -2,7 +2,6 @@ defineSuite([ 'Core/Resource', 'Core/defaultValue', 'Core/DefaultProxy', - 'Core/FeatureDetection', 'Core/queryToObject', 'Core/Request', 'Core/RequestErrorEvent', @@ -15,7 +14,6 @@ defineSuite([ Resource, defaultValue, DefaultProxy, - FeatureDetection, queryToObject, Request, RequestErrorEvent, @@ -27,6 +25,14 @@ defineSuite([ 'use strict'; var dataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2Nk+M/wHwAEBgIA5agATwAAAABJRU5ErkJggg=='; + var supportsImageBitmapOptions; + + beforeAll(function() { + return Resource.supportsImageBitmapOptions() + .then(function(result) { + supportsImageBitmapOptions = result; + }); + }); it('Constructor sets correct properties', function() { var proxy = new DefaultProxy('/proxy/'); @@ -1145,14 +1151,13 @@ defineSuite([ }); describe('fetchImage with ImageBitmap', function() { - if (!FeatureDetection.supportsCreateImageBitmap()) { + if (!supportsImageBitmapOptions) { return; } var canvas; beforeAll(function() { canvas = createCanvas(1, 2); - return Resource.supportsImageBitmapOptions(); }); afterAll(function() { @@ -1166,22 +1171,14 @@ defineSuite([ return [imageData.data[0], imageData.data[1], imageData.data[2], imageData.data[3]]; } - it('can call supportsImageBitmapOptions and supportsImageBitmapOptionsSync', function() { - if (!Resource.supportsImageBitmapOptionsSync()) { - return; - } - + it('can call supportsImageBitmapOptions', function() { return Resource.supportsImageBitmapOptions() .then(function(result) { - expect(Resource.supportsImageBitmapOptionsSync()).toEqual(result); + expect(typeof result).toEqual('boolean'); }); }); it('can load and decode an image', function() { - if (!Resource.supportsImageBitmapOptionsSync()) { - return; - } - return Resource.fetchImage('./Data/Images/Green.png').then(function(loadedImage) { expect(loadedImage.width).toEqual(1); expect(loadedImage.height).toEqual(1); @@ -1190,10 +1187,6 @@ defineSuite([ }); it('correctly flips image when ImageBitmapOptions are supported', function() { - if (!Resource.supportsImageBitmapOptionsSync()) { - return; - } - var loadedImage; return Resource.fetchImage({ @@ -1212,10 +1205,6 @@ defineSuite([ }); it('correctly loads image without flip when ImageBitmapOptions are supported', function() { - if (!Resource.supportsImageBitmapOptionsSync()) { - return; - } - var loadedImage; return Resource.fetchImage({ @@ -1234,10 +1223,6 @@ defineSuite([ }); it('does not use ImageBitmap when ImageBitmapOptions are not supported', function() { - if (!Resource.supportsImageBitmapOptionsSync()) { - return; - } - spyOn(Resource, 'supportsImageBitmapOptions').and.returnValue(when.resolve(false)); spyOn(window, 'createImageBitmap').and.callThrough(); @@ -1247,10 +1232,6 @@ defineSuite([ }); it('rejects the promise when the image errors', function() { - if (!Resource.supportsImageBitmapOptionsSync()) { - return; - } - return Resource.fetchImage('http://example.invalid/testuri.png') .then(function() { fail('expected promise to reject'); @@ -1266,7 +1247,7 @@ defineSuite([ // Force it to use the Image constructor since these specs all test // specific functionality of this code path. For example, the crossOrigin // restriction does not apply to images loaded with ImageBitmap. - spyOn(FeatureDetection, 'supportsCreateImageBitmap').and.returnValue(false); + spyOn(Resource, 'supportsImageBitmapOptions').and.returnValue(when.resolve(false)); }); it('can load an image', function() { diff --git a/Specs/Core/loadImageFromTypedArraySpec.js b/Specs/Core/loadImageFromTypedArraySpec.js index 16013ee3bd06..05c0f59826d8 100644 --- a/Specs/Core/loadImageFromTypedArraySpec.js +++ b/Specs/Core/loadImageFromTypedArraySpec.js @@ -1,11 +1,11 @@ defineSuite([ 'Core/loadImageFromTypedArray', - 'Core/FeatureDetection', - 'Core/Resource' + 'Core/Resource', + 'ThirdParty/when' ], function( loadImageFromTypedArray, - FeatureDetection, - Resource) { + Resource, + when) { 'use strict'; it('can load an image', function() { @@ -28,7 +28,7 @@ defineSuite([ format: 'image/png', flipY: true }; - spyOn(window, 'createImageBitmap'); + spyOn(window, 'createImageBitmap').and.returnValue(when.resolve({})); var blob = new Blob([options.uint8Array], { type : options.format }); @@ -58,7 +58,7 @@ defineSuite([ }); it('can load an image when ImageBitmap is not supported', function() { - spyOn(FeatureDetection, 'supportsCreateImageBitmap').and.returnValue(false); + spyOn(Resource, 'supportsImageBitmapOptions').and.returnValue(when.resolve(false)); spyOn(window, 'createImageBitmap').and.callThrough(); return Resource.fetchArrayBuffer('./Data/Images/Blue10x10.png').then(function(arrayBuffer) { var options = { diff --git a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js index f5ef14c6bbec..cc6b5fb372f7 100644 --- a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js +++ b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js @@ -6,7 +6,6 @@ defineSuite([ 'Core/Cartographic', 'Core/DefaultProxy', 'Core/defined', - 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/getAbsoluteUri', 'Core/objectToQuery', @@ -33,7 +32,6 @@ defineSuite([ Cartographic, DefaultProxy, defined, - FeatureDetection, GeographicTilingScheme, getAbsoluteUri, objectToQuery, @@ -54,10 +52,14 @@ defineSuite([ Uri) { 'use strict'; + var supportsImageBitmapOptions; beforeAll(function() { - // This suite spies on requests. The test below needs to make a request to a data URI. + // This suite spies on requests. Resource.supportsImageBitmapOptions needs to make a request to a data URI. // We run it here to avoid interfering with the tests. - return Resource.supportsImageBitmapOptions(); + return Resource.supportsImageBitmapOptions() + .then(function(result) { + supportsImageBitmapOptions = result; + }); }); beforeEach(function() { @@ -292,7 +294,7 @@ defineSuite([ expect(provider.usingPrecachedTiles).toEqual(true); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { + if (/^blob:/.test(url) || supportsImageBitmapOptions) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { @@ -465,7 +467,7 @@ defineSuite([ expect(provider.hasAlphaChannel).toBeDefined(); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { + if (/^blob:/.test(url) || supportsImageBitmapOptions) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { diff --git a/Specs/Scene/BingMapsImageryProviderSpec.js b/Specs/Scene/BingMapsImageryProviderSpec.js index 591078729dc9..2d9a06f31184 100644 --- a/Specs/Scene/BingMapsImageryProviderSpec.js +++ b/Specs/Scene/BingMapsImageryProviderSpec.js @@ -3,7 +3,6 @@ defineSuite([ 'Core/appendForwardSlash', 'Core/DefaultProxy', 'Core/defined', - 'Core/FeatureDetection', 'Core/queryToObject', 'Core/RequestScheduler', 'Core/Resource', @@ -22,7 +21,6 @@ defineSuite([ appendForwardSlash, DefaultProxy, defined, - FeatureDetection, queryToObject, RequestScheduler, Resource, @@ -38,6 +36,16 @@ defineSuite([ Uri) { 'use strict'; + var supportsImageBitmapOptions; + beforeAll(function() { + // This suite spies on requests. Resource.supportsImageBitmapOptions needs to make a request to a data URI. + // We run it here to avoid interfering with the tests. + return Resource.supportsImageBitmapOptions() + .then(function(result) { + supportsImageBitmapOptions = result; + }); + }); + beforeEach(function() { RequestScheduler.clearForSpecs(); }); @@ -177,7 +185,7 @@ defineSuite([ function installFakeImageRequest(expectedUrl, expectedParams, proxy) { Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { + if (/^blob:/.test(url) || supportsImageBitmapOptions) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { diff --git a/Specs/Scene/DiscardMissingTileImagePolicySpec.js b/Specs/Scene/DiscardMissingTileImagePolicySpec.js index 2f303bf9d21b..0cb9cd5bf040 100644 --- a/Specs/Scene/DiscardMissingTileImagePolicySpec.js +++ b/Specs/Scene/DiscardMissingTileImagePolicySpec.js @@ -1,23 +1,25 @@ defineSuite([ 'Scene/DiscardMissingTileImagePolicy', 'Core/Cartesian2', - 'Core/FeatureDetection', 'Core/Resource', 'Specs/pollToPromise', 'ThirdParty/when' ], function( DiscardMissingTileImagePolicy, Cartesian2, - FeatureDetection, Resource, pollToPromise, when) { 'use strict'; + var supportsImageBitmapOptions; beforeAll(function() { - // This suite spies on requests. The test below needs to make a request to a data URI. + // This suite spies on requests. Resource.supportsImageBitmapOptions needs to make a request to a data URI. // We run it here to avoid interfering with the tests. - return Resource.supportsImageBitmapOptions(); + return Resource.supportsImageBitmapOptions() + .then(function(result) { + supportsImageBitmapOptions = result; + }); }); afterEach(function() { @@ -70,7 +72,7 @@ defineSuite([ return pollToPromise(function() { return policy.isReady(); }).then(function() { - if ((FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { + if (supportsImageBitmapOptions) { expect(Resource._Implementations.createImageBitmapFromBlob).toHaveBeenCalled(); } else { expect(Resource._Implementations.createImage).toHaveBeenCalled(); diff --git a/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js index 68d98060d4f8..55a0a7a6c070 100644 --- a/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js @@ -4,7 +4,6 @@ defineSuite([ 'Core/DefaultProxy', 'Core/defaultValue', 'Core/defined', - 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/GoogleEarthEnterpriseMetadata', 'Core/GoogleEarthEnterpriseTileInformation', @@ -26,7 +25,6 @@ defineSuite([ DefaultProxy, defaultValue, defined, - FeatureDetection, GeographicTilingScheme, GoogleEarthEnterpriseMetadata, GoogleEarthEnterpriseTileInformation, @@ -46,11 +44,17 @@ defineSuite([ beforeEach(function() { RequestScheduler.clearForSpecs(); - return Resource.supportsImageBitmapOptions(); }); + var supportsImageBitmapOptions; beforeAll(function() { decodeGoogleEarthEnterpriseData.passThroughDataForTesting = true; + // This suite spies on requests. Resource.supportsImageBitmapOptions needs to make a request to a data URI. + // We run it here to avoid interfering with the tests. + return Resource.supportsImageBitmapOptions() + .then(function(result) { + supportsImageBitmapOptions = result; + }); }); afterAll(function() { @@ -89,7 +93,7 @@ defineSuite([ function installFakeImageRequest(expectedUrl, proxy) { Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { + if (/^blob:/.test(url) || supportsImageBitmapOptions) { // load blob url normally Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { @@ -106,7 +110,7 @@ defineSuite([ }; Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) { - if (defined(expectedUrl)) { + if (defined(expectedUrl) && !/^blob:/.test(url)) { if (proxy) { var uri = new Uri(url); url = decodeURIComponent(uri.query); diff --git a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js index 2b3be052cd94..32924b25b4ee 100644 --- a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js @@ -1,7 +1,6 @@ defineSuite([ 'Scene/GoogleEarthEnterpriseMapsProvider', 'Core/DefaultProxy', - 'Core/FeatureDetection', 'Core/GeographicTilingScheme', 'Core/Rectangle', 'Core/RequestScheduler', @@ -16,7 +15,6 @@ defineSuite([ ], function( GoogleEarthEnterpriseMapsProvider, DefaultProxy, - FeatureDetection, GeographicTilingScheme, Rectangle, RequestScheduler, @@ -30,10 +28,14 @@ defineSuite([ isImageOrImageBitmap) { 'use strict'; + var supportsImageBitmapOptions; beforeAll(function() { - // This suite spies on requests. The test below needs to make a request to a data URI. + // This suite spies on requests. Resource.supportsImageBitmapOptions needs to make a request to a data URI. // We run it here to avoid interfering with the tests. - return Resource.supportsImageBitmapOptions(); + return Resource.supportsImageBitmapOptions() + .then(function(result) { + supportsImageBitmapOptions = result; + }); }); afterEach(function() { @@ -182,7 +184,7 @@ defineSuite([ expect(provider.credit).toBeInstanceOf(Object); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { + if (/^blob:/.test(url) || supportsImageBitmapOptions) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else { @@ -300,7 +302,7 @@ defineSuite([ }); Resource._Implementations.createImage = function(url, crossOrigin, deferred) { - if (/^blob:/.test(url) || (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync())) { + if (/^blob:/.test(url) || supportsImageBitmapOptions) { // If ImageBitmap is supported, we expect a loadWithXhr request to fetch it as a blob. Resource._DefaultImplementations.createImage(url, crossOrigin, deferred); } else if (tries === 2) { diff --git a/Specs/isImageOrImageBitmap.js b/Specs/isImageOrImageBitmap.js index 5604e91a8e08..bc1cdd86f024 100644 --- a/Specs/isImageOrImageBitmap.js +++ b/Specs/isImageOrImageBitmap.js @@ -10,11 +10,12 @@ define([ // Many ImageryProvider specs will test if the requested image // succeeded by checking its instance. Since this may be an Image // or ImageBitmap, we abstract this check here. - if (FeatureDetection.supportsCreateImageBitmap() && Resource.supportsImageBitmapOptionsSync()) { - return image instanceof ImageBitmap; + var isImageBitmap = false; + if (typeof createImageBitmap === 'function') { + isImageBitmap = image instanceof ImageBitmap; } - return image instanceof Image; + return isImageBitmap || image instanceof Image; } return isImageOrImageBitmap; From 7753644736ad59e8029041b31c11696f55f6e9e6 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Sun, 10 Mar 2019 15:01:08 -0400 Subject: [PATCH 60/71] Replace isImageOrImageBitmap with a Jasmine matcher. --- .../ArcGisMapServerImageryProviderSpec.js | 14 +++---- Specs/Scene/BingMapsImageryProviderSpec.js | 8 ++-- ...oogleEarthEnterpriseImageryProviderSpec.js | 6 +-- .../GoogleEarthEnterpriseMapsProviderSpec.js | 10 ++--- Specs/Scene/MapboxImageryProviderSpec.js | 16 ++++--- Specs/Scene/SingleTileImageryProviderSpec.js | 6 +-- Specs/Scene/UrlTemplateImageryProviderSpec.js | 42 +++++++++---------- .../Scene/WebMapServiceImageryProviderSpec.js | 18 ++++---- .../WebMapTileServiceImageryProviderSpec.js | 6 +-- .../createOpenStreetMapImageryProviderSpec.js | 18 ++++---- ...createTileMapServiceImageryProviderSpec.js | 14 +++---- Specs/addDefaultMatchers.js | 15 +++++++ Specs/isImageOrImageBitmap.js | 22 ---------- 13 files changed, 83 insertions(+), 112 deletions(-) delete mode 100644 Specs/isImageOrImageBitmap.js diff --git a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js index cc6b5fb372f7..5f9de1335532 100644 --- a/Specs/Scene/ArcGisMapServerImageryProviderSpec.js +++ b/Specs/Scene/ArcGisMapServerImageryProviderSpec.js @@ -22,7 +22,6 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap', 'ThirdParty/Uri' ], function( ArcGisMapServerImageryProvider, @@ -48,7 +47,6 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, - isImageOrImageBitmap, Uri) { 'use strict'; @@ -236,7 +234,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -313,7 +311,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -366,7 +364,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -430,7 +428,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -486,7 +484,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -620,7 +618,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/BingMapsImageryProviderSpec.js b/Specs/Scene/BingMapsImageryProviderSpec.js index 2d9a06f31184..9edec91049e3 100644 --- a/Specs/Scene/BingMapsImageryProviderSpec.js +++ b/Specs/Scene/BingMapsImageryProviderSpec.js @@ -14,7 +14,6 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap', 'ThirdParty/Uri' ], function( BingMapsImageryProvider, @@ -32,7 +31,6 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, - isImageOrImageBitmap, Uri) { 'use strict'; @@ -374,7 +372,7 @@ defineSuite([ }); return provider.requestImage(0, 0, 0).then(function(image) { - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -405,7 +403,7 @@ defineSuite([ }); return provider.requestImage(0, 0, 0).then(function(image) { - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -494,7 +492,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js index 55a0a7a6c070..9ea083b002b9 100644 --- a/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js @@ -16,7 +16,6 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap', 'ThirdParty/Uri', 'ThirdParty/when' ], function( @@ -37,7 +36,6 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, - isImageOrImageBitmap, Uri, when) { 'use strict'; @@ -233,7 +231,7 @@ defineSuite([ installFakeImageRequest('http://fake.fake.invalid/flatfile?f1-03-i.1'); return imageryProvider.requestImage(0, 0, 0).then(function(image) { - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -303,7 +301,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js index 32924b25b4ee..64f694d07486 100644 --- a/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js +++ b/Specs/Scene/GoogleEarthEnterpriseMapsProviderSpec.js @@ -10,8 +10,7 @@ defineSuite([ 'Scene/ImageryLayer', 'Scene/ImageryProvider', 'Scene/ImageryState', - 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap' + 'Specs/pollToPromise' ], function( GoogleEarthEnterpriseMapsProvider, DefaultProxy, @@ -24,8 +23,7 @@ defineSuite([ ImageryLayer, ImageryProvider, ImageryState, - pollToPromise, - isImageOrImageBitmap) { + pollToPromise) { 'use strict'; var supportsImageBitmapOptions; @@ -203,7 +201,7 @@ defineSuite([ }; return provider.requestImage(0, 0, 0).then(function(image) { - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -339,7 +337,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/MapboxImageryProviderSpec.js b/Specs/Scene/MapboxImageryProviderSpec.js index 25e854bc4b62..8c7accf28541 100644 --- a/Specs/Scene/MapboxImageryProviderSpec.js +++ b/Specs/Scene/MapboxImageryProviderSpec.js @@ -10,8 +10,7 @@ defineSuite([ 'Scene/ImageryLayer', 'Scene/ImageryProvider', 'Scene/ImageryState', - 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap' + 'Specs/pollToPromise' ], function( MapboxImageryProvider, DefaultProxy, @@ -24,8 +23,7 @@ defineSuite([ ImageryLayer, ImageryProvider, ImageryState, - pollToPromise, - isImageOrImageBitmap) { + pollToPromise) { 'use strict'; beforeEach(function() { @@ -105,7 +103,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -128,7 +126,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -157,7 +155,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -189,7 +187,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -273,7 +271,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/SingleTileImageryProviderSpec.js b/Specs/Scene/SingleTileImageryProviderSpec.js index 62fba1eca3a1..e4e78e226a0e 100644 --- a/Specs/Scene/SingleTileImageryProviderSpec.js +++ b/Specs/Scene/SingleTileImageryProviderSpec.js @@ -10,7 +10,6 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap', 'ThirdParty/when' ], function( SingleTileImageryProvider, @@ -24,7 +23,6 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, - isImageOrImageBitmap, when) { 'use strict'; @@ -152,7 +150,7 @@ defineSuite([ return provider.ready; }).then(function() { return when(provider.requestImage(0, 0, 0), function(image) { - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -218,7 +216,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/UrlTemplateImageryProviderSpec.js b/Specs/Scene/UrlTemplateImageryProviderSpec.js index 0c33d8305d47..a4f635b55de7 100644 --- a/Specs/Scene/UrlTemplateImageryProviderSpec.js +++ b/Specs/Scene/UrlTemplateImageryProviderSpec.js @@ -15,7 +15,6 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap', 'ThirdParty/when' ], function( UrlTemplateImageryProvider, @@ -34,7 +33,6 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, - isImageOrImageBitmap, when) { 'use strict'; @@ -119,7 +117,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -166,7 +164,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -228,7 +226,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); @@ -254,7 +252,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -283,7 +281,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -312,7 +310,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -341,7 +339,7 @@ defineSuite([ return provider.requestImage(12, 10, 5).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -364,7 +362,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -387,7 +385,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -410,7 +408,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -433,7 +431,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -456,7 +454,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -478,7 +476,7 @@ defineSuite([ return provider.requestImage(3, 0, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -500,7 +498,7 @@ defineSuite([ return provider.requestImage(0, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -522,7 +520,7 @@ defineSuite([ return provider.requestImage(1, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -552,7 +550,7 @@ defineSuite([ return provider.requestImage(1, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -574,7 +572,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -597,7 +595,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -620,7 +618,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -648,7 +646,7 @@ defineSuite([ return provider.requestImage(3, 1, 2).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); diff --git a/Specs/Scene/WebMapServiceImageryProviderSpec.js b/Specs/Scene/WebMapServiceImageryProviderSpec.js index d2b6312d2d8f..11d77419f8e2 100644 --- a/Specs/Scene/WebMapServiceImageryProviderSpec.js +++ b/Specs/Scene/WebMapServiceImageryProviderSpec.js @@ -23,7 +23,6 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap', 'ThirdParty/Uri' ], function( WebMapServiceImageryProvider, @@ -50,7 +49,6 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, - isImageOrImageBitmap, Uri) { 'use strict'; @@ -414,7 +412,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -454,7 +452,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -497,7 +495,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -537,7 +535,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -580,7 +578,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -623,7 +621,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -666,7 +664,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -824,7 +822,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/WebMapTileServiceImageryProviderSpec.js b/Specs/Scene/WebMapTileServiceImageryProviderSpec.js index cdff245bf81d..29d3ee1cdd53 100644 --- a/Specs/Scene/WebMapTileServiceImageryProviderSpec.js +++ b/Specs/Scene/WebMapTileServiceImageryProviderSpec.js @@ -19,7 +19,6 @@ defineSuite([ 'Scene/ImageryProvider', 'Scene/ImageryState', 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap', 'ThirdParty/Uri' ], function( WebMapTileServiceImageryProvider, @@ -42,7 +41,6 @@ defineSuite([ ImageryProvider, ImageryState, pollToPromise, - isImageOrImageBitmap, Uri) { 'use strict'; @@ -366,7 +364,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -416,7 +414,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/createOpenStreetMapImageryProviderSpec.js b/Specs/Scene/createOpenStreetMapImageryProviderSpec.js index e097ceff92d2..7d0648fdaf4b 100644 --- a/Specs/Scene/createOpenStreetMapImageryProviderSpec.js +++ b/Specs/Scene/createOpenStreetMapImageryProviderSpec.js @@ -10,8 +10,7 @@ defineSuite([ 'Scene/ImageryLayer', 'Scene/ImageryState', 'Scene/UrlTemplateImageryProvider', - 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap' + 'Specs/pollToPromise' ], function( createOpenStreetMapImageryProvider, DefaultProxy, @@ -24,8 +23,7 @@ defineSuite([ ImageryLayer, ImageryState, UrlTemplateImageryProvider, - pollToPromise, - isImageOrImageBitmap) { + pollToPromise) { 'use strict'; beforeEach(function() { @@ -74,7 +72,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -96,7 +94,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -118,7 +116,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -146,7 +144,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -195,7 +193,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -258,7 +256,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/Scene/createTileMapServiceImageryProviderSpec.js b/Specs/Scene/createTileMapServiceImageryProviderSpec.js index e813f76e3f2b..f7b59938de4d 100644 --- a/Specs/Scene/createTileMapServiceImageryProviderSpec.js +++ b/Specs/Scene/createTileMapServiceImageryProviderSpec.js @@ -17,7 +17,6 @@ defineSuite([ 'Scene/ImageryState', 'Scene/UrlTemplateImageryProvider', 'Specs/pollToPromise', - 'Specs/isImageOrImageBitmap', 'ThirdParty/when' ], function( createTileMapServiceImageryProvider, @@ -38,7 +37,6 @@ defineSuite([ ImageryState, UrlTemplateImageryProvider, pollToPromise, - isImageOrImageBitmap, when) { 'use strict'; @@ -217,7 +215,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -239,7 +237,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -262,7 +260,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -289,7 +287,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -364,7 +362,7 @@ defineSuite([ return provider.requestImage(0, 0, 0).then(function(image) { expect(Resource._Implementations.createImage).toHaveBeenCalled(); - expect(isImageOrImageBitmap(image)).toBe(true); + expect(image).toBeImageOrImageBitmap(); }); }); }); @@ -424,7 +422,7 @@ defineSuite([ return pollToPromise(function() { return imagery.state === ImageryState.RECEIVED; }).then(function() { - expect(isImageOrImageBitmap(imagery.image)).toBe(true); + expect(imagery.image).toBeImageOrImageBitmap(); expect(tries).toEqual(2); imagery.releaseReference(); }); diff --git a/Specs/addDefaultMatchers.js b/Specs/addDefaultMatchers.js index a6afb9868210..e8e3716816e9 100644 --- a/Specs/addDefaultMatchers.js +++ b/Specs/addDefaultMatchers.js @@ -576,6 +576,21 @@ define([ }; }, + toBeImageOrImageBitmap : function(util, customEqualityTesters) { + return { + compare : function(actual) { + if (typeof createImageBitmap !== 'function') { + return { + pass : actual instanceof Image + }; + } + + return { + pass : actual instanceof ImageBitmap || actual instanceof Image + }; + } + }; + }, toThrowDeveloperError : makeThrowFunction(debug, DeveloperError, 'DeveloperError'), toThrowRuntimeError : makeThrowFunction(true, RuntimeError, 'RuntimeError'), diff --git a/Specs/isImageOrImageBitmap.js b/Specs/isImageOrImageBitmap.js deleted file mode 100644 index bc1cdd86f024..000000000000 --- a/Specs/isImageOrImageBitmap.js +++ /dev/null @@ -1,22 +0,0 @@ -define([ - 'Core/FeatureDetection', - 'Core/Resource' - ], function( - FeatureDetection, - Resource) { - 'use strict'; - - function isImageOrImageBitmap(image) { - // Many ImageryProvider specs will test if the requested image - // succeeded by checking its instance. Since this may be an Image - // or ImageBitmap, we abstract this check here. - var isImageBitmap = false; - if (typeof createImageBitmap === 'function') { - isImageBitmap = image instanceof ImageBitmap; - } - - return isImageBitmap || image instanceof Image; - } - - return isImageOrImageBitmap; -}); From 9f72348fdcb1c3c4ae2f44850d81270c74f9de47 Mon Sep 17 00:00:00 2001 From: ggetz Date: Tue, 12 Mar 2019 10:14:17 -0400 Subject: [PATCH 61/71] Fix globe material example typo --- Apps/Sandcastle/gallery/Globe Materials.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Apps/Sandcastle/gallery/Globe Materials.html b/Apps/Sandcastle/gallery/Globe Materials.html index 7814aae68752..658df0a828a7 100644 --- a/Apps/Sandcastle/gallery/Globe Materials.html +++ b/Apps/Sandcastle/gallery/Globe Materials.html @@ -200,8 +200,8 @@ if (selectedShading === 'elevation') { material = getElevationContourMaterial(); shadingUniforms = material.materials.elevationRampMaterial.uniforms; - shadingUniforms.minHeight = minHeight; - shadingUniforms.maxHeight = maxHeight; + shadingUniforms.minimumHeight = minHeight; + shadingUniforms.maximumHeight = maxHeight; contourUniforms = material.materials.contourMaterial.uniforms; } else if (selectedShading === 'slope') { material = getSlopeContourMaterial(); @@ -221,8 +221,8 @@ } else if (selectedShading === 'elevation') { material = Cesium.Material.fromType('ElevationRamp'); shadingUniforms = material.uniforms; - shadingUniforms.minHeight = minHeight; - shadingUniforms.maxHeight = maxHeight; + shadingUniforms.minimumHeight = minHeight; + shadingUniforms.maximumHeight = maxHeight; } else if (selectedShading === 'slope') { material = Cesium.Material.fromType('SlopeRamp'); shadingUniforms = material.uniforms; From 4485246aed05421c7f420540ed34ca79928eed4a Mon Sep 17 00:00:00 2001 From: Alexander Popiak Date: Tue, 12 Mar 2019 16:58:32 +0100 Subject: [PATCH 62/71] call prepareVertexAttribute with a name so the error message is informative --- Source/Scene/PointCloud.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index c297f51138d3..15719dab9d07 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -516,7 +516,7 @@ define([ return boundingSphere; } - function prepareVertexAttribute(typedArray) { + function prepareVertexAttribute(typedArray, name) { // WebGL does not support UNSIGNED_INT, INT, or DOUBLE vertex attributes. Convert these to FLOAT. var componentDatatype = ComponentDatatype.fromTypedArray(typedArray); if (componentDatatype === ComponentDatatype.INT || componentDatatype === ComponentDatatype.UNSIGNED_INT || componentDatatype === ComponentDatatype.DOUBLE) { @@ -573,7 +573,7 @@ define([ for (var name in styleableProperties) { if (styleableProperties.hasOwnProperty(name)) { var property = styleableProperties[name]; - var typedArray = prepareVertexAttribute(property.typedArray); + var typedArray = prepareVertexAttribute(property.typedArray, name); componentsPerAttribute = property.componentCount; componentDatatype = ComponentDatatype.fromTypedArray(typedArray); @@ -634,7 +634,7 @@ define([ var batchIdsVertexBuffer; if (hasBatchIds) { - batchIds = prepareVertexAttribute(batchIds); + batchIds = prepareVertexAttribute(batchIds, "batchIds"); batchIdsVertexBuffer = Buffer.createVertexBuffer({ context : context, typedArray : batchIds, From 53b32ac741861ca518660867af8681e42e50292f Mon Sep 17 00:00:00 2001 From: Alexander Popiak Date: Tue, 12 Mar 2019 17:07:39 +0100 Subject: [PATCH 63/71] add apopiak to contributors.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f9ace2bc8e5c..31ede3782b4b 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -204,3 +204,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Mirco Kroon](https://github.com/mircokroon) * [Rikku-x](https://github.com/Rikku-x) * [Adrien David](https://github.com/adridavid) +* [Alexander Popiak](https://github.com/apopiak) From 77d69331a5572c1298cb005adea6cdbd8b88b775 Mon Sep 17 00:00:00 2001 From: Alexander Popiak Date: Tue, 12 Mar 2019 18:04:26 +0100 Subject: [PATCH 64/71] use single quotes --- Source/Scene/PointCloud.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 15719dab9d07..8816562442b4 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -634,7 +634,7 @@ define([ var batchIdsVertexBuffer; if (hasBatchIds) { - batchIds = prepareVertexAttribute(batchIds, "batchIds"); + batchIds = prepareVertexAttribute(batchIds, 'batchIds'); batchIdsVertexBuffer = Buffer.createVertexBuffer({ context : context, typedArray : batchIds, From 9942dd1d2fd9da8ade30628881b29dcddbe45af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Wed, 13 Mar 2019 15:23:19 -0400 Subject: [PATCH 65/71] Documentation fixes --- Source/Core/TerrainProvider.js | 1 + Source/DataSources/PolylineGeometryUpdater.js | 2 +- Source/DataSources/PolylineGraphics.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Core/TerrainProvider.js b/Source/Core/TerrainProvider.js index efa99393e8de..b91d1343a293 100644 --- a/Source/Core/TerrainProvider.js +++ b/Source/Core/TerrainProvider.js @@ -229,6 +229,7 @@ define([ /** * Makes sure we load availability data for a tile + * @function * * @param {Number} x The X coordinate of the tile for which to request geometry. * @param {Number} y The Y coordinate of the tile for which to request geometry. diff --git a/Source/DataSources/PolylineGeometryUpdater.js b/Source/DataSources/PolylineGeometryUpdater.js index 4dfbea77392d..48d58ccffe29 100644 --- a/Source/DataSources/PolylineGeometryUpdater.js +++ b/Source/DataSources/PolylineGeometryUpdater.js @@ -344,7 +344,7 @@ define([ /** * Gets the zindex * @type {Number} - * @memberof GroundGeometryUpdater.prototype + * @memberof PolylineGeometryUpdater.prototype * @readonly */ zIndex: { diff --git a/Source/DataSources/PolylineGraphics.js b/Source/DataSources/PolylineGraphics.js index 2b019a79f895..215b033565f2 100644 --- a/Source/DataSources/PolylineGraphics.js +++ b/Source/DataSources/PolylineGraphics.js @@ -196,7 +196,7 @@ define([ /** * Gets or sets the zIndex Property specifying the ordering of the polyline. Only has an effect if `clampToGround` is true and polylines on terrain is supported. - * @memberof RectangleGraphics.prototype + * @memberof PolylineGraphics.prototype * @type {ConstantProperty} * @default 0 */ From 2570c8c5a1a7c509d01ce35a0464ebc442177101 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 14 Mar 2019 13:30:30 -0400 Subject: [PATCH 66/71] Added options to doc --- Source/Scene/PointCloudShading.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Scene/PointCloudShading.js b/Source/Scene/PointCloudShading.js index 906a9ee8fe29..ba5baf55c2be 100644 --- a/Source/Scene/PointCloudShading.js +++ b/Source/Scene/PointCloudShading.js @@ -18,6 +18,8 @@ define([ * @param {Boolean} [options.eyeDomeLighting=true] When true, use eye dome lighting when drawing with point attenuation. * @param {Number} [options.eyeDomeLightingStrength=1.0] Increasing this value increases contrast on slopes and edges. * @param {Number} [options.eyeDomeLightingRadius=1.0] Increase the thickness of contours from eye dome lighting. + * @param {Boolean} [options.backFaceCulling=false] Determines whether back-facing points are hidden. This option works only if data has normals included. + * @param {Boolean} [options.normalShading=true] Determines whether a point cloud that contains normals is shaded based on the sun direction. * * @alias PointCloudShading * @constructor @@ -78,7 +80,7 @@ define([ this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0); /** - * Determines whether backfaces of points are hidden. + * Determines whether back-facing points are hidden. * This option works only if data has normals included. * * @type {Boolean} From c3076a12df391118a994ddd7de94a960c1284a18 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 14 Mar 2019 13:33:33 -0400 Subject: [PATCH 67/71] Updated CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 9115b1783f55..a328b9eabd67 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Change Log ##### Additions :tada: * `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode. It is only valid when `ImageBitmapOptions` is supported by the browser. [#7579](https://github.com/AnalyticalGraphicsInc/cesium/pull/7579) +* Added `backFaceCulling` and `normalShading` options to `PointCloudShading`. Both options are only applicable for point clouds containing normals. [#7399](https://github.com/AnalyticalGraphicsInc/cesium/pull/7399) ##### Fixes :wrench: * Fixed the value for `BlendFunction.ONE_MINUS_CONSTANT_COLOR`. [#7624](https://github.com/AnalyticalGraphicsInc/cesium/pull/7624) From 667fa58c6697ed46fa96c4ecb9add36ab10a167c Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 14 Mar 2019 14:18:16 -0400 Subject: [PATCH 68/71] Some changes --- Source/Scene/PointCloud.js | 20 ++++---------------- Source/Scene/PointCloud3DTileContent.js | 16 ++++++++++------ Source/Scene/TimeDynamicPointCloud.js | 19 ++++++++++--------- Specs/Scene/PointCloudShadingSpec.js | 8 +++++++- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Source/Scene/PointCloud.js b/Source/Scene/PointCloud.js index 64c2c295d068..490605e6b775 100644 --- a/Source/Scene/PointCloud.js +++ b/Source/Scene/PointCloud.js @@ -147,13 +147,13 @@ define([ this._quantizedRange = 0.0; this._octEncodedRange = 0.0; - this._pointCloudShading = defined(options.shading) ? options.shading : new PointCloudShading(); - // Use per-point normals to hide back-facing points. - this._backFaceCulling = this.backFaceCulling; + this.backFaceCulling = false; + this._backFaceCulling = false; // Whether to enable normal shading - this._normalShading = this.normalShading; + this.normalShading = true; + this._normalShading = true; this._opaqueRenderState = undefined; this._translucentRenderState = undefined; @@ -246,18 +246,6 @@ define([ set : function(value) { this._boundingSphere = BoundingSphere.clone(value); } - }, - - backFaceCulling : { - get : function() { - return this._pointCloudShading.backFaceCulling; - } - }, - - normalShading : { - get : function() { - return this._pointCloudShading.normalShading; - } } }); diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index 875ccf1471c4..bfd994b978e3 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -14,6 +14,7 @@ define([ './Cesium3DTileFeature', './Cesium3DTileRefine', './PointCloud', + './PointCloudShading', './SceneMode' ], function( Color, @@ -31,6 +32,7 @@ define([ Cesium3DTileFeature, Cesium3DTileRefine, PointCloud, + PointCloudShading, SceneMode) { 'use strict'; @@ -70,8 +72,7 @@ define([ fragmentShaderLoaded : getFragmentShaderLoaded(this), uniformMapLoaded : getUniformMapLoaded(this), batchTableLoaded : getBatchTableLoaded(this), - pickIdLoaded : getPickIdLoaded(this), - shading : tileset.pointCloudShading + pickIdLoaded : getPickIdLoaded(this) }); } @@ -271,9 +272,11 @@ define([ } }; + var defaultShading = new PointCloudShading(); + PointCloud3DTileContent.prototype.update = function(tileset, frameState) { var pointCloud = this._pointCloud; - var pointCloudShading = tileset.pointCloudShading; + var pointCloudShading = defaultValue(tileset.pointCloudShading, defaultShading); var tile = this._tile; var batchTable = this._batchTable; var mode = frameState.mode; @@ -301,7 +304,6 @@ define([ this._styleDirty = false; pointCloud.clippingPlanesOriginMatrix = tileset.clippingPlanesOriginMatrix; - pointCloud.style = defined(batchTable) ? undefined : tileset.style; pointCloud.styleDirty = styleDirty; pointCloud.modelMatrix = tile.computedTransform; @@ -311,9 +313,11 @@ define([ pointCloud.clippingPlanes = clippingPlanes; pointCloud.isClipped = defined(clippingPlanes) && clippingPlanes.enabled && tile._isClipped; pointCloud.clippingPlanesDirty = tile.clippingPlanesDirty; - pointCloud.attenuation = defined(pointCloudShading) ? pointCloudShading.attenuation : false; + pointCloud.attenuation = pointCloudShading.attenuation; + pointCloud.backFaceCulling = pointCloudShading.backFaceCulling; + pointCloud.normalShading = pointCloudShading.normalShading; pointCloud.geometricError = getGeometricError(this); - pointCloud.geometricErrorScale = defined(pointCloudShading) ? pointCloudShading.geometricErrorScale : 1.0; + pointCloud.geometricErrorScale = pointCloudShading.geometricErrorScale; if (defined(pointCloudShading) && defined(pointCloudShading.maximumAttenuation)) { pointCloud.maximumAttenuation = pointCloudShading.maximumAttenuation; } else if (tile.refine === Cesium3DTileRefine.ADD) { diff --git a/Source/Scene/TimeDynamicPointCloud.js b/Source/Scene/TimeDynamicPointCloud.js index e3f74eeb4c40..3add0294640f 100644 --- a/Source/Scene/TimeDynamicPointCloud.js +++ b/Source/Scene/TimeDynamicPointCloud.js @@ -420,8 +420,7 @@ define([ cull : true, fragmentShaderLoaded : getFragmentShaderLoaded, uniformMapLoaded : getUniformMapLoaded(that), - pickIdLoaded : getPickIdLoaded, - shading : that.shading + pickIdLoaded : getPickIdLoaded }); return frame.pointCloud.readyPromise; }).otherwise(handleFrameFailure(that, uri)); @@ -491,7 +490,10 @@ define([ return 10.0; } + var defaultShading = new PointCloudShading(); + function renderFrame(that, frame, updateState, frameState) { + var shading = defaultValue(that.shading, defaultShading); var pointCloud = frame.pointCloud; var transform = defaultValue(frame.transform, Matrix4.IDENTITY); pointCloud.modelMatrix = Matrix4.multiplyTransformation(that.modelMatrix, transform, scratchModelMatrix); @@ -500,14 +502,13 @@ define([ pointCloud.shadows = that.shadows; pointCloud.clippingPlanes = that._clippingPlanes; pointCloud.isClipped = updateState.isClipped; + pointCloud.attenuation = shading.attenuation; + pointCloud.backFaceCulling = shading.backFaceCulling; + pointCloud.normalShading = shading.normalShading; + pointCloud.geometricError = getGeometricError(that, pointCloud); + pointCloud.geometricErrorScale = shading.geometricErrorScale; + pointCloud.maximumAttenuation = getMaximumAttenuation(that); - var shading = that.shading; - if (defined(shading)) { - pointCloud.attenuation = shading.attenuation; - pointCloud.geometricError = getGeometricError(that, pointCloud); - pointCloud.geometricErrorScale = shading.geometricErrorScale; - pointCloud.maximumAttenuation = getMaximumAttenuation(that); - } pointCloud.update(frameState); frame.touchedFrameNumber = frameState.frameNumber; } diff --git a/Specs/Scene/PointCloudShadingSpec.js b/Specs/Scene/PointCloudShadingSpec.js index a08282804630..ffac43d24946 100644 --- a/Specs/Scene/PointCloudShadingSpec.js +++ b/Specs/Scene/PointCloudShadingSpec.js @@ -15,13 +15,17 @@ defineSuite([ expect(pointCloudShading.eyeDomeLighting).toEqual(true); expect(pointCloudShading.eyeDomeLightingStrength).toEqual(1.0); expect(pointCloudShading.eyeDomeLightingRadius).toEqual(1.0); + expect(pointCloudShading.backFaceCulling).toEqual(false); + expect(pointCloudShading.normalShading).toEqual(true); var options = { geometricErrorScale : 2.0, maximumAttenuation : 16, baseResolution : 0.1, eyeDomeLightingStrength : 0.1, - eyeDomeLightingRadius : 2.0 + eyeDomeLightingRadius : 2.0, + backFaceCulling : true, + normalShading : false }; pointCloudShading = new PointCloudShading(options); expect(pointCloudShading.attenuation).toEqual(false); @@ -31,6 +35,8 @@ defineSuite([ expect(pointCloudShading.eyeDomeLighting).toEqual(true); expect(pointCloudShading.eyeDomeLightingStrength).toEqual(options.eyeDomeLightingStrength); expect(pointCloudShading.eyeDomeLightingRadius).toEqual(options.eyeDomeLightingRadius); + expect(pointCloudShading.backFaceCulling).toEqual(options.backFaceCulling); + expect(pointCloudShading.normalShading).toEqual(options.normalShading); }); it('provides a method for checking if point cloud shading is supported', function() { From 5045510b347f2cd3b598d2c9bb73e0b3130961a6 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 14 Mar 2019 14:25:06 -0400 Subject: [PATCH 69/71] Fix test --- Specs/Scene/PointCloud3DTileContentSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Specs/Scene/PointCloud3DTileContentSpec.js b/Specs/Scene/PointCloud3DTileContentSpec.js index 4ad043335eea..c41613d0ce8b 100644 --- a/Specs/Scene/PointCloud3DTileContentSpec.js +++ b/Specs/Scene/PointCloud3DTileContentSpec.js @@ -464,7 +464,7 @@ defineSuite([ expect(scene).toPickAndCall(function(result) { // Set culling to true - content._pointCloud.backFaceCulling = true; + tileset.pointCloudShading.backFaceCulling = true; expect(scene).toPickAndCall(function(result) { picked = result; @@ -487,7 +487,7 @@ defineSuite([ } // Set culling to false - content._pointCloud.backFaceCulling = false; + tileset.pointCloudShading.backFaceCulling = false; expect(scene).toPickAndCall(function(result) { picked = result; From 515851ecb82c1a66458ce938f36078670d4d7095 Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Fri, 15 Mar 2019 13:57:32 +0100 Subject: [PATCH 70/71] HeadingPitchRoll.fromQuaternion clamps pitch asin --- Source/Core/HeadingPitchRoll.js | 2 +- Specs/Core/HeadingPitchRollSpec.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/Core/HeadingPitchRoll.js b/Source/Core/HeadingPitchRoll.js index b934f6d04f3e..1fd9f692aaa6 100644 --- a/Source/Core/HeadingPitchRoll.js +++ b/Source/Core/HeadingPitchRoll.js @@ -50,7 +50,7 @@ define([ var numeratorHeading = 2 * (quaternion.w * quaternion.z + quaternion.x * quaternion.y); result.heading = -Math.atan2(numeratorHeading, denominatorHeading); result.roll = Math.atan2(numeratorRoll, denominatorRoll); - result.pitch = -Math.asin(test); + result.pitch = -CesiumMath.asinClamped(test); return result; }; diff --git a/Specs/Core/HeadingPitchRollSpec.js b/Specs/Core/HeadingPitchRollSpec.js index 81d2aefb856b..4569f75ac38c 100644 --- a/Specs/Core/HeadingPitchRollSpec.js +++ b/Specs/Core/HeadingPitchRollSpec.js @@ -51,6 +51,12 @@ defineSuite([ } }); + it('it should return the correct pitch, even with a quaternion rounding error', function() { + var q = new Quaternion(8.801218199179452e-17, -0.7071067801637715, -8.801218315071006e-17, -0.7071067822093238); + var result = HeadingPitchRoll.fromQuaternion(q); + expect(result.pitch).toEqual(-(Math.PI / 2)); + }); + it('conversion from degrees', function() { var testingTab = [ [0, 0, 0], From 6892f16f5b28b44c83f6f2825bccc29affcffe8a Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Fri, 15 Mar 2019 14:05:31 +0100 Subject: [PATCH 71/71] CHANGES.md --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index a328b9eabd67..684205004fc8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,8 @@ Change Log ##### Fixes :wrench: * Fixed the value for `BlendFunction.ONE_MINUS_CONSTANT_COLOR`. [#7624](https://github.com/AnalyticalGraphicsInc/cesium/pull/7624) +* Fixed `HeadingPitchRoll.pitch` being `NaN` when using `.fromQuaternion` do to a rounding error +for pitches close to +/- 90°. [#7654](https://github.com/AnalyticalGraphicsInc/cesium/pull/7654) ### 1.55 - 2019-03-01