From d8385f2db1571a9e1700cca33f580493c9fe5d91 Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Tue, 6 Aug 2013 17:48:54 -0400 Subject: [PATCH 1/9] Add TerrainInspector app. --- Apps/TerrainInspector/TerrainInspector.css | 126 +++++++++++++++++++++ Apps/TerrainInspector/index.html | 102 +++++++++++++++++ Source/Scene/CentralBodySurface.js | 42 ++++++- Source/Scene/TerrainProvider.js | 20 +++- Source/Scene/Tile.js | 18 ++- 5 files changed, 299 insertions(+), 9 deletions(-) create mode 100644 Apps/TerrainInspector/TerrainInspector.css create mode 100644 Apps/TerrainInspector/index.html diff --git a/Apps/TerrainInspector/TerrainInspector.css b/Apps/TerrainInspector/TerrainInspector.css new file mode 100644 index 000000000000..b098bfa808a4 --- /dev/null +++ b/Apps/TerrainInspector/TerrainInspector.css @@ -0,0 +1,126 @@ +@import url(../../../Source/Widgets/widgets.css); + +body { + background: #000; + color: #eee; + font-family: sans-serif; + font-size: 9pt; + padding: 0; + margin: 0; + width: 100%; + height: 100%; + overflow: hidden; +} + +.fullSize { + display: block; + position: absolute; + top: 0; + left: 0; + border: none; + width: 100%; + height: 100%; +} + +#loadingOverlay { + position: absolute; + top: 0; + left: 0; + opacity: 0.9; + width: 100%; + height: 100%; + display: none; +} + +.sandcastle-loading #loadingOverlay { + display: block; +} + +#loadingOverlay h1 { + text-align: center; + position: relative; + top: 50%; + margin-top: -0.5em; +} + +#toolbar { + margin: 5px; + padding: 2px 5px; + position: absolute; +} + +.top,.bottom { + display: block; + position: absolute; + border: none; + width: 100%; + height: 50%; + box-sizing: border-box; +} + +.top { + top: 0; + left: 0; + border-bottom: solid 2px #888; +} + +.bottom { + bottom: 0; + left: 0; +} + +#topToolbar,#bottomToolbar { + margin: 5px; + padding: 2px 5px; + position: absolute; + left: 0; +} + +#topToolbar { + top: 0; +} + +#bottomToolbar { + top: 50%; +} + +.button { + -moz-box-shadow:inset 0px 1px 0px 0px #ffffff; + -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff; + box-shadow:inset 0px 1px 0px 0px #ffffff; + + background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #f9f9f9), color-stop(1, #dedede)); + background:-moz-linear-gradient(top, #f9f9f9 5%, #dedede 100%); + background:-webkit-linear-gradient(top, #f9f9f9 5%, #dedede 100%); + background:-o-linear-gradient(top, #f9f9f9 5%, #dedede 100%); + background:-ms-linear-gradient(top, #f9f9f9 5%, #dedede 100%); + background:linear-gradient(to bottom, #f9f9f9 5%, #dedede 100%); + + border-radius:3px; + border:1px solid #dcdcdc; + display:inline-block; + padding:5px 10px; + margin:3px; + text-decoration:none; + text-shadow:0px 1px 0px #ffffff; +} + +.button:hover { + background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #dedede), color-stop(1, #f9f9f9)); + background:-moz-linear-gradient(top, #dedede 5%, #f9f9f9 100%); + background:-webkit-linear-gradient(top, #dedede 5%, #f9f9f9 100%); + background:-o-linear-gradient(top, #dedede 5%, #f9f9f9 100%); + background:-ms-linear-gradient(top, #dedede 5%, #f9f9f9 100%); + background:linear-gradient(to bottom, #dedede 5%, #f9f9f9 100%); +} + +.button:active { + position:relative; + top:1px; +} + +.claro .dijitTitlePaneContentOuter { + background-color: rgba(255, 255, 255, 0.7); + color: black; + text-shadow: 0 0 5px #fff; +} \ No newline at end of file diff --git a/Apps/TerrainInspector/index.html b/Apps/TerrainInspector/index.html new file mode 100644 index 000000000000..0e6a60272379 --- /dev/null +++ b/Apps/TerrainInspector/index.html @@ -0,0 +1,102 @@ + + + + + + + Terrain Inspector + + + + + + + +
+
+
+
+
+
+ + + diff --git a/Source/Scene/CentralBodySurface.js b/Source/Scene/CentralBodySurface.js index aceb516566fc..1164ed3fa9b0 100644 --- a/Source/Scene/CentralBodySurface.js +++ b/Source/Scene/CentralBodySurface.js @@ -21,7 +21,8 @@ define([ './SceneMode', './TerrainProvider', './TileReplacementQueue', - './TileState' + './TileState', + '../ThirdParty/when' ], function( defaultValue, destroyObject, @@ -44,7 +45,8 @@ define([ SceneMode, TerrainProvider, TileReplacementQueue, - TileState) { + TileState, + when) { "use strict"; /** @@ -96,6 +98,7 @@ define([ this._debug = { enableDebugOutput : false, + wireframe : false, boundingSphereTile : undefined, maxDepth : 0, @@ -983,10 +986,18 @@ define([ command.shaderProgram = shaderSet.getShaderProgram(context, tileSetIndex, applyBrightness, applyContrast, applyHue, applySaturation, applyGamma, applyAlpha); command.renderState = renderState; - command.primitiveType = TerrainProvider.wireframe ? PrimitiveType.LINES : PrimitiveType.TRIANGLES; + command.primitiveType = PrimitiveType.TRIANGLES; command.vertexArray = tile.vertexArray; command.uniformMap = uniformMap; + if (surface._debug.wireframe) { + createWireframeVertexArrayIfNecessary(context, surface, tile); + if (typeof tile.wireframeVertexArray !== 'undefined') { + command.vertexArray = tile.wireframeVertexArray; + command.primitiveType = PrimitiveType.LINES; + } + } + var boundingVolume = tile.boundingSphere3D; if (frameState.mode !== SceneMode.SCENE3D) { @@ -1008,5 +1019,30 @@ define([ tileCommands.length = Math.max(0, tileCommandIndex + 1); } + function createWireframeVertexArrayIfNecessary(context, surface, tile) { + if (typeof tile.wireframeVertexArray !== 'undefined') { + return; + } + + if (typeof tile.meshForWireframePromise !== 'undefined') { + return; + } + + tile.meshForWireframePromise = tile.terrainData.createMesh(surface._terrainProvider.getTilingScheme(), tile.x, tile.y, tile.level); + if (typeof tile.meshForWireframePromise === 'undefined') { + // deferrred + return; + } + + var vertexArray = tile.vertexArray; + + when(tile.meshForWireframePromise, function(mesh) { + if (tile.vertexArray === vertexArray) { + tile.wireframeVertexArray = TerrainProvider.createWireframeVertexArray(context, tile.vertexArray, mesh); + tile.meshForWireframePromise = undefined; + } + }); + } + return CentralBodySurface; }); diff --git a/Source/Scene/TerrainProvider.js b/Source/Scene/TerrainProvider.js index dfd76e35c6bb..c9e0de7c18e1 100644 --- a/Source/Scene/TerrainProvider.js +++ b/Source/Scene/TerrainProvider.js @@ -37,8 +37,6 @@ define([ textureCoordinates : 1 }; - TerrainProvider.wireframe = false; - var regularGridIndexArrays = []; TerrainProvider.getRegularGridIndices = function(width, height) { @@ -132,9 +130,6 @@ define([ var indexBuffer = indexBuffers[context.getId()]; if (typeof indexBuffer === 'undefined' || indexBuffer.isDestroyed()) { var indices = buffers.indices; - if (TerrainProvider.wireframe) { - indices = trianglesToLines(buffers.indices); - } indexBuffer = context.createIndexBuffer(indices, BufferUsage.STATIC_DRAW, IndexDatatype.UNSIGNED_SHORT); indexBuffer.setVertexArrayDestroyable(false); indexBuffer.referenceCount = 1; @@ -147,6 +142,21 @@ define([ tileTerrain.vertexArray = context.createVertexArray(attributes, indexBuffer); }; + /** + * Creates a vertex array for wireframe rendering of a terrain tile. + * + * @param {Context} context The context in which to create the vertex array. + * @param {VertexArray} vertexArray The existing, non-wireframe vertex array. The new vertex array + * will share vertex buffers with this existing one. + * @param {TerrainMesh} terrainMesh The terrain mesh containing non-wireframe indices. + * @returns {VertexArray} The vertex array for wireframe rendering. + */ + TerrainProvider.createWireframeVertexArray = function(context, vertexArray, terrainMesh) { + var wireframeIndices = trianglesToLines(terrainMesh.indices); + var wireframeIndexBuffer = context.createIndexBuffer(wireframeIndices, BufferUsage.STATIC_DRAW, IndexDatatype.UNSIGNED_SHORT); + return context.createVertexArray(vertexArray._attributes, wireframeIndexBuffer); + }; + /** * Specifies the quality of terrain created from heightmaps. A value of 1.0 will * ensure that adjacent heightmap vertices are separated by no more than diff --git a/Source/Scene/Tile.js b/Source/Scene/Tile.js index dc7b94f7eab3..e836cb611666 100644 --- a/Source/Scene/Tile.js +++ b/Source/Scene/Tile.js @@ -310,8 +310,10 @@ define([ }; Tile.prototype.freeVertexArray = function() { + var indexBuffer; + if (typeof this.vertexArray !== 'undefined') { - var indexBuffer = this.vertexArray.getIndexBuffer(); + indexBuffer = this.vertexArray.getIndexBuffer(); this.vertexArray.destroy(); this.vertexArray = undefined; @@ -323,6 +325,20 @@ define([ } } } + + if (typeof this.wireframeVertexArray !== 'undefined') { + indexBuffer = this.wireframeVertexArray.getIndexBuffer(); + + this.wireframeVertexArray.destroy(); + this.wireframeVertexArray = undefined; + + if (!indexBuffer.isDestroyed() && typeof indexBuffer.referenceCount !== 'undefined') { + --indexBuffer.referenceCount; + if (indexBuffer.referenceCount === 0) { + indexBuffer.destroy(); + } + } + } }; Tile.prototype.processStateMachine = function(context, terrainProvider, imageryLayerCollection) { From 6df7530c70d482eb18e602a43243f3dcf9e77b61 Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Tue, 6 Aug 2013 20:44:11 -0400 Subject: [PATCH 2/9] Enable terrain and fix a race condition. The race could makes tiles sometimes not show up as wireframe when they should. --- Apps/TerrainInspector/index.html | 4 ++++ Source/Scene/CentralBodySurface.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Apps/TerrainInspector/index.html b/Apps/TerrainInspector/index.html index 0e6a60272379..6204a05b258f 100644 --- a/Apps/TerrainInspector/index.html +++ b/Apps/TerrainInspector/index.html @@ -52,6 +52,10 @@ }); centralBody.terrainProvider = mesh;*/ + + centralBody.terrainProvider = new Cesium.CesiumTerrainProvider({ + url : 'http://cesium.agi.com/smallterrain' + }); var tp = new TitlePane({ title: 'Terrain Debugging', diff --git a/Source/Scene/CentralBodySurface.js b/Source/Scene/CentralBodySurface.js index 1164ed3fa9b0..5ad15bccb455 100644 --- a/Source/Scene/CentralBodySurface.js +++ b/Source/Scene/CentralBodySurface.js @@ -1039,8 +1039,8 @@ define([ when(tile.meshForWireframePromise, function(mesh) { if (tile.vertexArray === vertexArray) { tile.wireframeVertexArray = TerrainProvider.createWireframeVertexArray(context, tile.vertexArray, mesh); - tile.meshForWireframePromise = undefined; } + tile.meshForWireframePromise = undefined; }); } From 463e944dde495751857586f93e921a32a6009387 Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Tue, 6 Aug 2013 22:04:11 -0400 Subject: [PATCH 3/9] Show bounding spheres and render only selected. --- Apps/TerrainInspector/index.html | 137 +++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 8 deletions(-) diff --git a/Apps/TerrainInspector/index.html b/Apps/TerrainInspector/index.html index 6204a05b258f..dab831acea1b 100644 --- a/Apps/TerrainInspector/index.html +++ b/Apps/TerrainInspector/index.html @@ -33,11 +33,13 @@ 'Cesium', 'dojo/dom-construct', 'dijit/TitlePane', + 'dijit/form/Button', 'dijit/form/CheckBox' ], function( Cesium, domConstruct, TitlePane, + Button, CheckBox) { "use strict"; @@ -67,39 +69,158 @@ domConstruct.place('Wireframe\ Suspend LOD update\ - Show tile coordinates', 'debuggingTable'); + Show tile coordinates\ + \ + None\ +  \ +  \ + Show bounding sphere of selected tile\ + Render selected tile only', 'debuggingTable'); new CheckBox({ checked: centralBody._surface.wireframe, onChange: function(b) { - centralBody._surface._debug.wireframe = !centralBody._surface._debug.wireframe; + centralBody._surface._debug.wireframe = b; } }).placeAt('wireFrameToggle'); - new CheckBox({ + var suspendLodCheckbox = new CheckBox({ checked: centralBody._surface._debug.suspendLodUpdate, onChange: function(b) { - centralBody._surface._debug.suspendLodUpdate = !centralBody._surface._debug.suspendLodUpdate; - + centralBody._surface._debug.suspendLodUpdate = b; + if (!b) { + renderSelectedTileOnlyCheckbox.set("checked", false); + } } - }).placeAt('updateLodToggle'); + }); + suspendLodCheckbox.placeAt('updateLodToggle'); var tileBoundariesLayer; new CheckBox({ checked: typeof tileBoundariesLayer !== 'undefined', onChange: function(b) { - if (typeof tileBoundariesLayer === 'undefined') { + if (b && typeof tileBoundariesLayer === 'undefined') { tileBoundariesLayer = centralBody.getImageryLayers().addImageryProvider(new Cesium.TileCoordinatesImageryProvider({ + tilingScheme : centralBody.terrainProvider.getTilingScheme() })); - } else { + } else if (!b && typeof tileBoundariesLayer !== 'undefined') { centralBody.getImageryLayers().remove(tileBoundariesLayer); tileBoundariesLayer = undefined; } } }).placeAt('showTileCoordinatesToggle'); + + var selectingTile = false; + var showBoundingSphere = true; + var selectedTile; + var renderSelectedTileOnly = false; + + function selectTile(event) { + selectedTile = undefined; + + var ellipsoid = centralBody.getEllipsoid(); + var cartesian = scene.getCamera().controller.pickEllipsoid({x: event.clientX, y: event.clientY}, ellipsoid); + + if (typeof cartesian !== 'undefined') { + var cartographic = ellipsoid.cartesianToCartographic(cartesian); + + // Find a tile containing this position. + + var tilesRendered = centralBody._surface._tilesToRenderByTextureCount; + for (var textureCount = 0; !selectedTile && textureCount < tilesRendered.length; ++textureCount) { + var tilesRenderedByTextureCount = tilesRendered[textureCount]; + if (typeof tilesRenderedByTextureCount === 'undefined') { + continue; + } + + for (var tileIndex = 0; !selectedTile && tileIndex < tilesRenderedByTextureCount.length; ++tileIndex) { + var tile = tilesRenderedByTextureCount[tileIndex]; + if (tile.extent.contains(cartographic)) { + selectedTile = tile; + } + } + } + } + + var text; + var sw; + var ne; + if (selectedTile) { + text = 'L: ' + selectedTile.level + ' X: ' + selectedTile.x + ' Y: ' + selectedTile.y; + sw = 'SW corner: ' + selectedTile.extent.west + ', ' + selectedTile.extent.south; + ne = 'NE corner: ' + selectedTile.extent.east + ', ' + selectedTile.extent.north; + } else { + text = 'None'; + sw = ' '; + ne = ' ' + } + + if (showBoundingSphere) { + centralBody._surface._debug.boundingSphereTile = selectedTile; + } + + document.getElementById('selectedTileLabel').innerHTML = text; + document.getElementById('selectedTileExtentSWLabel').innerHTML = sw; + document.getElementById('selectedTileExtentNELabel').innerHTML = ne; + + viewer.cesiumWidget.canvas.removeEventListener('mousedown', selectTile, false); + selectingTile = false; + } + + new Button({ + label: "Select tile...", + showLabel: true, + onClick: function() { + selectingTile = !selectingTile; + if (selectingTile) { + document.getElementById("selectedTileLabel").innerHTML = 'Click a tile!'; + viewer.cesiumWidget.canvas.addEventListener('mousedown', selectTile, false); + } else { + viewer.cesiumWidget.canvas.removeEventListener('mousedown', selectTile, false); + } + } + }).placeAt('selectTileButton'); + + new CheckBox({ + checked: showBoundingSphere, + onChange: function(b) { + showBoundingSphere = b; + if (!showBoundingSphere) { + centralBody._surface._debug.boundingSphereTile = undefined; + } else { + centralBody._surface._debug.boundingSphereTile = selectedTile; + } + } + }).placeAt('boundingSphereToggle'); + + var renderSelectedTileOnlyCheckbox = new CheckBox({ + checked: renderSelectedTileOnly, + onChange: function(b) { + if (!b) { + suspendLodCheckbox.set("checked", false); + } else { + suspendLodCheckbox.set("checked", true); + centralBody._surface._tilesToRenderByTextureCount = []; + + if (typeof selectedTile !== 'undefined') { + var readyTextureCount = 0; + var tileImageryCollection = selectedTile.imagery; + for (var i = 0, len = tileImageryCollection.length; i < len; ++i) { + var tileImagery = tileImageryCollection[i]; + if (typeof tileImagery.readyImagery !== 'undefined' && tileImagery.readyImagery.imageryLayer.alpha !== 0.0) { + ++readyTextureCount; + } + } + + centralBody._surface._tilesToRenderByTextureCount[readyTextureCount] = [selectedTile]; + } + } + } + }); + renderSelectedTileOnlyCheckbox.placeAt('renderSelectedTileOnlyToggle'); }); From 26083a618300aa917103c18b91132a29e74f01d0 Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Wed, 14 Aug 2013 21:49:08 -0400 Subject: [PATCH 4/9] Remove commented-out code. --- Apps/TerrainInspector/index.html | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Apps/TerrainInspector/index.html b/Apps/TerrainInspector/index.html index dab831acea1b..f1279f3a91ee 100644 --- a/Apps/TerrainInspector/index.html +++ b/Apps/TerrainInspector/index.html @@ -49,12 +49,6 @@ var centralBody = scene.getPrimitives().getCentralBody(); centralBody.depthTestAgainstTerrain = true; - /*var mesh = new Cesium.CesiumMeshTerrainProvider({ - url : 'http://172.16.37.34/mesh' - }); - - centralBody.terrainProvider = mesh;*/ - centralBody.terrainProvider = new Cesium.CesiumTerrainProvider({ url : 'http://cesium.agi.com/smallterrain' }); From 565c371ec7c037fb339d9cb39c876b27576836d4 Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Fri, 16 Aug 2013 22:07:56 -0400 Subject: [PATCH 5/9] Changes suggested by Scott. --- Apps/TerrainInspector/TerrainInspector.css | 2 +- Apps/TerrainInspector/index.html | 23 ++++++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Apps/TerrainInspector/TerrainInspector.css b/Apps/TerrainInspector/TerrainInspector.css index b098bfa808a4..f801c5b8bf16 100644 --- a/Apps/TerrainInspector/TerrainInspector.css +++ b/Apps/TerrainInspector/TerrainInspector.css @@ -1,4 +1,4 @@ -@import url(../../../Source/Widgets/widgets.css); +@import url(../../Source/Widgets/widgets.css); body { background: #000; diff --git a/Apps/TerrainInspector/index.html b/Apps/TerrainInspector/index.html index f1279f3a91ee..0cfbf5c30806 100644 --- a/Apps/TerrainInspector/index.html +++ b/Apps/TerrainInspector/index.html @@ -9,19 +9,16 @@ var dojoConfig = { baseUrl : '../../Source', packages: [ - { name: 'dojo', location: '../../ThirdParty/dojo-release-1.9.1/dojo' }, - { name: 'dijit', location: '../../ThirdParty/dojo-release-1.9.1/dijit' } + { name: 'dojo', location: '../ThirdParty/dojo-release-1.9.1/dojo' }, + { name: 'dijit', location: '../ThirdParty/dojo-release-1.9.1/dijit' } ] }; + - -
@@ -93,13 +90,13 @@ var tileBoundariesLayer; new CheckBox({ - checked: typeof tileBoundariesLayer !== 'undefined', + checked: Cesium.defined(tileBoundariesLayer), onChange: function(b) { - if (b && typeof tileBoundariesLayer === 'undefined') { + if (b && !Cesium.defined(tileBoundariesLayer)) { tileBoundariesLayer = centralBody.getImageryLayers().addImageryProvider(new Cesium.TileCoordinatesImageryProvider({ tilingScheme : centralBody.terrainProvider.getTilingScheme() })); - } else if (!b && typeof tileBoundariesLayer !== 'undefined') { + } else if (!b && Cesium.defined(tileBoundariesLayer)) { centralBody.getImageryLayers().remove(tileBoundariesLayer); tileBoundariesLayer = undefined; } @@ -118,7 +115,7 @@ var ellipsoid = centralBody.getEllipsoid(); var cartesian = scene.getCamera().controller.pickEllipsoid({x: event.clientX, y: event.clientY}, ellipsoid); - if (typeof cartesian !== 'undefined') { + if (Cesium.defined(cartesian)) { var cartographic = ellipsoid.cartesianToCartographic(cartesian); // Find a tile containing this position. @@ -126,7 +123,7 @@ var tilesRendered = centralBody._surface._tilesToRenderByTextureCount; for (var textureCount = 0; !selectedTile && textureCount < tilesRendered.length; ++textureCount) { var tilesRenderedByTextureCount = tilesRendered[textureCount]; - if (typeof tilesRenderedByTextureCount === 'undefined') { + if (!Cesium.defined(tilesRenderedByTextureCount)) { continue; } @@ -199,12 +196,12 @@ suspendLodCheckbox.set("checked", true); centralBody._surface._tilesToRenderByTextureCount = []; - if (typeof selectedTile !== 'undefined') { + if (Cesium.defined(selectedTile)) { var readyTextureCount = 0; var tileImageryCollection = selectedTile.imagery; for (var i = 0, len = tileImageryCollection.length; i < len; ++i) { var tileImagery = tileImageryCollection[i]; - if (typeof tileImagery.readyImagery !== 'undefined' && tileImagery.readyImagery.imageryLayer.alpha !== 0.0) { + if (Cesium.defined(tileImagery.readyImagery) && tileImagery.readyImagery.imageryLayer.alpha !== 0.0) { ++readyTextureCount; } } From 3964d3b69dc8c0440e9459a6d71e201d66835ecd Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Fri, 16 Aug 2013 22:19:23 -0400 Subject: [PATCH 6/9] Move javascript to a separate file. --- Apps/TerrainInspector/TerrainInspector.js | 187 +++++++++++++++++++++ Apps/TerrainInspector/index.html | 193 +--------------------- 2 files changed, 188 insertions(+), 192 deletions(-) create mode 100644 Apps/TerrainInspector/TerrainInspector.js diff --git a/Apps/TerrainInspector/TerrainInspector.js b/Apps/TerrainInspector/TerrainInspector.js new file mode 100644 index 000000000000..e40d8b0361cb --- /dev/null +++ b/Apps/TerrainInspector/TerrainInspector.js @@ -0,0 +1,187 @@ +require([ + 'Cesium', + 'dojo/dom-construct', + 'dijit/TitlePane', + 'dijit/form/Button', + 'dijit/form/CheckBox' +], function( + Cesium, + domConstruct, + TitlePane, + Button, + CheckBox) { + "use strict"; + + var viewer = new Cesium.Viewer('cesiumContainer'); + + var scene = viewer.scene; + var centralBody = scene.getPrimitives().getCentralBody(); + centralBody.depthTestAgainstTerrain = true; + + centralBody.terrainProvider = new Cesium.CesiumTerrainProvider({ + url : 'http://cesium.agi.com/smallterrain' + }); + + var tp = new TitlePane({ + title: 'Terrain Debugging', + id:'title-pane', + content: '
', + open: true + }); + document.getElementById("toolbar").appendChild(tp.domNode); + + domConstruct.place('Wireframe\ + Suspend LOD update\ + Show tile coordinates\ + \ + None\ +  \ +  \ + Show bounding sphere of selected tile\ + Render selected tile only', 'debuggingTable'); + + new CheckBox({ + checked: centralBody._surface.wireframe, + onChange: function(b) { + centralBody._surface._debug.wireframe = b; + + } + }).placeAt('wireFrameToggle'); + + var suspendLodCheckbox = new CheckBox({ + checked: centralBody._surface._debug.suspendLodUpdate, + onChange: function(b) { + centralBody._surface._debug.suspendLodUpdate = b; + if (!b) { + renderSelectedTileOnlyCheckbox.set("checked", false); + } + } + }); + suspendLodCheckbox.placeAt('updateLodToggle'); + + var tileBoundariesLayer; + + new CheckBox({ + checked: Cesium.defined(tileBoundariesLayer), + onChange: function(b) { + if (b && !Cesium.defined(tileBoundariesLayer)) { + tileBoundariesLayer = centralBody.getImageryLayers().addImageryProvider(new Cesium.TileCoordinatesImageryProvider({ + tilingScheme : centralBody.terrainProvider.getTilingScheme() + })); + } else if (!b && Cesium.defined(tileBoundariesLayer)) { + centralBody.getImageryLayers().remove(tileBoundariesLayer); + tileBoundariesLayer = undefined; + } + + } + }).placeAt('showTileCoordinatesToggle'); + + var selectingTile = false; + var showBoundingSphere = true; + var selectedTile; + var renderSelectedTileOnly = false; + + function selectTile(event) { + selectedTile = undefined; + + var ellipsoid = centralBody.getEllipsoid(); + var cartesian = scene.getCamera().controller.pickEllipsoid({x: event.clientX, y: event.clientY}, ellipsoid); + + if (Cesium.defined(cartesian)) { + var cartographic = ellipsoid.cartesianToCartographic(cartesian); + + // Find a tile containing this position. + + var tilesRendered = centralBody._surface._tilesToRenderByTextureCount; + for (var textureCount = 0; !selectedTile && textureCount < tilesRendered.length; ++textureCount) { + var tilesRenderedByTextureCount = tilesRendered[textureCount]; + if (!Cesium.defined(tilesRenderedByTextureCount)) { + continue; + } + + for (var tileIndex = 0; !selectedTile && tileIndex < tilesRenderedByTextureCount.length; ++tileIndex) { + var tile = tilesRenderedByTextureCount[tileIndex]; + if (tile.extent.contains(cartographic)) { + selectedTile = tile; + } + } + } + } + + var text; + var sw; + var ne; + if (selectedTile) { + text = 'L: ' + selectedTile.level + ' X: ' + selectedTile.x + ' Y: ' + selectedTile.y; + sw = 'SW corner: ' + selectedTile.extent.west + ', ' + selectedTile.extent.south; + ne = 'NE corner: ' + selectedTile.extent.east + ', ' + selectedTile.extent.north; + } else { + text = 'None'; + sw = ' '; + ne = ' ' + } + + if (showBoundingSphere) { + centralBody._surface._debug.boundingSphereTile = selectedTile; + } + + document.getElementById('selectedTileLabel').innerHTML = text; + document.getElementById('selectedTileExtentSWLabel').innerHTML = sw; + document.getElementById('selectedTileExtentNELabel').innerHTML = ne; + + viewer.cesiumWidget.canvas.removeEventListener('mousedown', selectTile, false); + selectingTile = false; + } + + new Button({ + label: "Select tile...", + showLabel: true, + onClick: function() { + selectingTile = !selectingTile; + if (selectingTile) { + document.getElementById("selectedTileLabel").innerHTML = 'Click a tile!'; + viewer.cesiumWidget.canvas.addEventListener('mousedown', selectTile, false); + } else { + viewer.cesiumWidget.canvas.removeEventListener('mousedown', selectTile, false); + } + } + }).placeAt('selectTileButton'); + + new CheckBox({ + checked: showBoundingSphere, + onChange: function(b) { + showBoundingSphere = b; + if (!showBoundingSphere) { + centralBody._surface._debug.boundingSphereTile = undefined; + } else { + centralBody._surface._debug.boundingSphereTile = selectedTile; + } + } + }).placeAt('boundingSphereToggle'); + + var renderSelectedTileOnlyCheckbox = new CheckBox({ + checked: renderSelectedTileOnly, + onChange: function(b) { + if (!b) { + suspendLodCheckbox.set("checked", false); + } else { + suspendLodCheckbox.set("checked", true); + centralBody._surface._tilesToRenderByTextureCount = []; + + if (Cesium.defined(selectedTile)) { + var readyTextureCount = 0; + var tileImageryCollection = selectedTile.imagery; + for (var i = 0, len = tileImageryCollection.length; i < len; ++i) { + var tileImagery = tileImageryCollection[i]; + if (Cesium.defined(tileImagery.readyImagery) && tileImagery.readyImagery.imageryLayer.alpha !== 0.0) { + ++readyTextureCount; + } + } + + centralBody._surface._tilesToRenderByTextureCount[readyTextureCount] = [selectedTile]; + } + } + } + }); + renderSelectedTileOnlyCheckbox.placeAt('renderSelectedTileOnlyToggle'); +}); diff --git a/Apps/TerrainInspector/index.html b/Apps/TerrainInspector/index.html index 0cfbf5c30806..270ec922956e 100644 --- a/Apps/TerrainInspector/index.html +++ b/Apps/TerrainInspector/index.html @@ -15,204 +15,13 @@ }; +
-
-
-
- From 51fc78455fed5ec880c0148872dfb3981a40989f Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Fri, 16 Aug 2013 22:22:28 -0400 Subject: [PATCH 7/9] Use defined function. --- Source/Scene/CentralBodySurface.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Scene/CentralBodySurface.js b/Source/Scene/CentralBodySurface.js index 86d413cc2456..e88952268df1 100644 --- a/Source/Scene/CentralBodySurface.js +++ b/Source/Scene/CentralBodySurface.js @@ -996,7 +996,7 @@ define([ if (surface._debug.wireframe) { createWireframeVertexArrayIfNecessary(context, surface, tile); - if (typeof tile.wireframeVertexArray !== 'undefined') { + if (defined(tile.wireframeVertexArray)) { command.vertexArray = tile.wireframeVertexArray; command.primitiveType = PrimitiveType.LINES; } @@ -1024,16 +1024,16 @@ define([ } function createWireframeVertexArrayIfNecessary(context, surface, tile) { - if (typeof tile.wireframeVertexArray !== 'undefined') { + if (defined(tile.wireframeVertexArray)) { return; } - if (typeof tile.meshForWireframePromise !== 'undefined') { + if (defined(tile.meshForWireframePromise)) { return; } tile.meshForWireframePromise = tile.terrainData.createMesh(surface._terrainProvider.getTilingScheme(), tile.x, tile.y, tile.level); - if (typeof tile.meshForWireframePromise === 'undefined') { + if (!defined(tile.meshForWireframePromise)) { // deferrred return; } From cc2724446627db388dba5f27fd1ea5bfb5a0223e Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Fri, 16 Aug 2013 22:27:20 -0400 Subject: [PATCH 8/9] Fix warnings. --- Apps/TerrainInspector/TerrainInspector.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Apps/TerrainInspector/TerrainInspector.js b/Apps/TerrainInspector/TerrainInspector.js index e40d8b0361cb..c7dcc0a688fa 100644 --- a/Apps/TerrainInspector/TerrainInspector.js +++ b/Apps/TerrainInspector/TerrainInspector.js @@ -1,3 +1,4 @@ +/*global require,document*/ require([ 'Cesium', 'dojo/dom-construct', @@ -117,8 +118,8 @@ require([ ne = 'NE corner: ' + selectedTile.extent.east + ', ' + selectedTile.extent.north; } else { text = 'None'; - sw = ' '; - ne = ' ' + sw = ' '; + ne = ' '; } if (showBoundingSphere) { From 777decc23669fd650737c84b0895d83574211eeb Mon Sep 17 00:00:00 2001 From: mramato Date: Tue, 20 Aug 2013 21:18:23 -0400 Subject: [PATCH 9/9] Add Terrain Inspector to index.html. --- index.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.html b/index.html index 22ed716ba0a2..b2e67588d21f 100644 --- a/index.html +++ b/index.html @@ -27,6 +27,9 @@
  • Sandcastle
  • +
  • + Terrain Inspector +
  • Timeline Demo