From 916947a2143c754146b393b310d760190d039d2b Mon Sep 17 00:00:00 2001 From: Austin Eng <213reeses@gmail.com> Date: Tue, 10 Jan 2017 13:47:55 -0500 Subject: [PATCH 1/4] add functions to apply wireframe to 3DTilesets --- Apps/Sandcastle/gallery/3D Tiles.html | 4 ++++ Source/Scene/Batched3DModel3DTileContent.js | 5 +++++ Source/Scene/Cesium3DTile.js | 9 +++++++++ Source/Scene/Cesium3DTileBatchTable.js | 10 ++++++++++ Source/Scene/Cesium3DTileContent.js | 13 +++++++++++++ Source/Scene/Cesium3DTileset.js | 12 ++++++++++++ Source/Scene/Composite3DTileContent.js | 11 +++++++++++ Source/Scene/Empty3DTileContent.js | 6 ++++++ Source/Scene/Instanced3DModel3DTileContent.js | 7 +++++++ Source/Scene/PointCloud3DTileContent.js | 6 ++++++ Source/Scene/Tileset3DTileContent.js | 6 ++++++ 11 files changed, 89 insertions(+) diff --git a/Apps/Sandcastle/gallery/3D Tiles.html b/Apps/Sandcastle/gallery/3D Tiles.html index 02d63e7a2564..8ea2b02afe50 100644 --- a/Apps/Sandcastle/gallery/3D Tiles.html +++ b/Apps/Sandcastle/gallery/3D Tiles.html @@ -375,6 +375,10 @@ tileset.debugColorizeTiles = !tileset.debugColorizeTiles; }); +Sandcastle.addToolbarButton('Wireframe on/off', function() { + tileset.debugWireframe = !tileset.debugWireframe; +}); + Sandcastle.addToolbarButton('BV on/off', function() { tileset.debugShowBoundingVolume = !tileset.debugShowBoundingVolume; }); diff --git a/Source/Scene/Batched3DModel3DTileContent.js b/Source/Scene/Batched3DModel3DTileContent.js index d51112ba0ed6..662adb0bef5d 100644 --- a/Source/Scene/Batched3DModel3DTileContent.js +++ b/Source/Scene/Batched3DModel3DTileContent.js @@ -343,6 +343,11 @@ define([ this.batchTable.setAllColor(color); }; + Batched3DModel3DTileContent.prototype.applyWireframe = function(enabled) { + this._model.debugWireframe = enabled; + + }; + /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Source/Scene/Cesium3DTile.js b/Source/Scene/Cesium3DTile.js index fbfa74444225..b8af69c43086 100644 --- a/Source/Scene/Cesium3DTile.js +++ b/Source/Scene/Cesium3DTile.js @@ -325,6 +325,7 @@ define([ this._debugViewerRequestVolume = undefined; this._debugColor = new Color.fromRandom({ alpha : 1.0 }); this._debugColorizeTiles = false; + this._debugWireframe = false; } defineProperties(Cesium3DTile.prototype, { @@ -701,6 +702,14 @@ define([ tile._debugColorizeTiles = false; tile._content.applyDebugSettings(false, tile._debugColor); } + + if (tileset.debugWireframe && !tile._debugWireframe) { + tile._debugWireframe = true; + tile._content.applyWireframe(true); + } else if (!tileset.debugWireframe && tile._debugWireframe) { + tile._debugWireframe = false; + tile._content.applyWireframe(false); + } } /** diff --git a/Source/Scene/Cesium3DTileBatchTable.js b/Source/Scene/Cesium3DTileBatchTable.js index efe89fd96694..55e2af4e68f7 100644 --- a/Source/Scene/Cesium3DTileBatchTable.js +++ b/Source/Scene/Cesium3DTileBatchTable.js @@ -1202,6 +1202,15 @@ define([ } } + function updateDerivedCommandsWireframe(derivedCommands, command) { + for (var name in derivedCommands) { + if (derivedCommands.hasOwnProperty(name)) { + var derivedCommand = derivedCommands[name]; + derivedCommand.primitiveType = command.primitiveType; + } + } + } + Cesium3DTileBatchTable.prototype.getAddCommand = function() { var styleCommandsNeeded = getStyleCommandsNeeded(this); @@ -1220,6 +1229,7 @@ define([ } updateDerivedCommandsShadows(derivedCommands, command); + updateDerivedCommandsWireframe(derivedCommands, command); // If the command was originally opaque: // * If the styling applied to the tile is all opaque, use the original command diff --git a/Source/Scene/Cesium3DTileContent.js b/Source/Scene/Cesium3DTileContent.js index e63d77075858..3800efbb51e8 100644 --- a/Source/Scene/Cesium3DTileContent.js +++ b/Source/Scene/Cesium3DTileContent.js @@ -199,6 +199,19 @@ define([ DeveloperError.throwInstantiationError(); }; + /** + * Called when {@link Cesium3DTileset#debugWireframe} changes. + *

+ * This is used to implement the Cesium3DTileContent interface, but is + * not part of the public Cesium API. + *

+ * + * @private + */ + Cesium3DTileContent.prototype.applyWireframe = function(enabled) { + DeveloperError.throwInstantiationError(); + }; + /** * Apply a style to the content using a shader instead of a batch table. Currently this is only * applicable for {@link PointCloud3DTileContent}. diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 4379f3724184..386d48a25b52 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -94,6 +94,7 @@ define([ * @param {Boolean} [options.debugShowPickStatistics=false] For debugging only. Determines if rendering statistics for picking are output to the console. * @param {Boolean} [options.debugFreezeFrame=false] For debugging only. Determines if only the tiles from last frame should be used for rendering. * @param {Boolean} [options.debugColorizeTiles=false] For debugging only. When true, assigns a random color to each tile. + * @param {Boolean} [options.debugWireframe=false] For debugging only. When true, render's each tile's content as a wireframe. * @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile. * @param {Boolean} [options.debugShowContentBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile's content. * @param {Boolean} [options.debugShowViewerRequestVolume=false] For debugging only. When true, renders the viewer request volume for each tile. @@ -323,6 +324,17 @@ define([ */ this.debugColorizeTiles = defaultValue(options.debugColorizeTiles, false); + /** + * This property is for debugging only; it is not optimized for production use. + *

+ * When true, renders each tile's content as a wireframe + *

+ * + * @type {Boolean} + * @default false + */ + this.debugWireframe = defaultValue(options.debugWireframe, false); + /** * This property is for debugging only; it is not optimized for production use. *

diff --git a/Source/Scene/Composite3DTileContent.js b/Source/Scene/Composite3DTileContent.js index 6dd61495b387..6e406e3afd1f 100644 --- a/Source/Scene/Composite3DTileContent.js +++ b/Source/Scene/Composite3DTileContent.js @@ -245,6 +245,17 @@ define([ } }; + /** + * Part of the {@link Cesium3DTileContent} interface. + */ + Composite3DTileContent.prototype.applyWireframe = function(enabled) { + var contents = this._contents; + var length = contents.length; + for (var i = 0; i < length; ++i) { + contents[i].applyWireframe(enabled); + } + }; + /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Source/Scene/Empty3DTileContent.js b/Source/Scene/Empty3DTileContent.js index 65b45ade6d1b..52c20fc312d1 100644 --- a/Source/Scene/Empty3DTileContent.js +++ b/Source/Scene/Empty3DTileContent.js @@ -113,6 +113,12 @@ define([ Empty3DTileContent.prototype.applyDebugSettings = function(enabled, color) { }; + /** + * Part of the {@link Cesium3DTileContent} interface. + */ + Empty3DTileContent.prototype.applyWireframe = function(enabled) { + }; + /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Source/Scene/Instanced3DModel3DTileContent.js b/Source/Scene/Instanced3DModel3DTileContent.js index ba28211378ab..a126f6062f88 100644 --- a/Source/Scene/Instanced3DModel3DTileContent.js +++ b/Source/Scene/Instanced3DModel3DTileContent.js @@ -470,6 +470,13 @@ define([ this.batchTable.setAllColor(color); }; + /** + * Part of the {@link Cesium3DTileContent} interface. + */ + Instanced3DModel3DTileContent.prototype.applyWireframe = function(enabled) { + this._modelInstanceCollection.debugWireframe = enabled; + }; + /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index e00cea225aec..3898a88bc6a3 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -1117,6 +1117,12 @@ define([ this._highlightColor = enabled ? color : Color.WHITE; }; + /** + * Part of the {@link Cesium3DTileContent} interface. + */ + PointCloud3DTileContent.prototype.applyWireframe = function(enabled) { + }; + /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Source/Scene/Tileset3DTileContent.js b/Source/Scene/Tileset3DTileContent.js index 49a7daba114a..c74e6222789e 100644 --- a/Source/Scene/Tileset3DTileContent.js +++ b/Source/Scene/Tileset3DTileContent.js @@ -124,6 +124,12 @@ define([ Tileset3DTileContent.prototype.applyDebugSettings = function(enabled, color) { }; + /** + * Part of the {@link Cesium3DTileContent} interface. + */ + Tileset3DTileContent.prototype.applyWireframe = function(enabled) { + }; + /** * Part of the {@link Cesium3DTileContent} interface. */ From 188cae7fa939614f7d78f16e4cecb1178491a62b Mon Sep 17 00:00:00 2001 From: Austin Eng <213reeses@gmail.com> Date: Tue, 10 Jan 2017 15:02:30 -0500 Subject: [PATCH 2/4] add debugWireframe test for 3DTileset --- Source/Scene/Batched3DModel3DTileContent.js | 1 - Specs/Scene/Cesium3DTilesetSpec.js | 23 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Source/Scene/Batched3DModel3DTileContent.js b/Source/Scene/Batched3DModel3DTileContent.js index 662adb0bef5d..5ce08e047213 100644 --- a/Source/Scene/Batched3DModel3DTileContent.js +++ b/Source/Scene/Batched3DModel3DTileContent.js @@ -345,7 +345,6 @@ define([ Batched3DModel3DTileContent.prototype.applyWireframe = function(enabled) { this._model.debugWireframe = enabled; - }; /** diff --git a/Specs/Scene/Cesium3DTilesetSpec.js b/Specs/Scene/Cesium3DTilesetSpec.js index 9d4139bc8a5d..c02a1aa0ab37 100644 --- a/Specs/Scene/Cesium3DTilesetSpec.js +++ b/Specs/Scene/Cesium3DTilesetSpec.js @@ -7,6 +7,7 @@ defineSuite([ 'Core/HeadingPitchRange', 'Core/loadWithXhr', 'Core/Matrix4', + 'Core/PrimitiveType', 'Core/RequestScheduler', 'Renderer/ContextLimits', 'Scene/Cesium3DTile', @@ -27,6 +28,7 @@ defineSuite([ HeadingPitchRange, loadWithXhr, Matrix4, + PrimitiveType, RequestScheduler, ContextLimits, Cesium3DTile, @@ -939,6 +941,27 @@ defineSuite([ }); }); + it('debugWireframe', function() { + // More precise test is in Cesium3DTileBatchTableSpec + return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { + viewRootOnly(); + tileset.debugWireframe = true; + scene.renderForSpecs(); + var commands = scene.frameState.commandList; + var i; + for (i = 0; i < commands.length; ++i) { + expect(commands[i].primitiveType).toEqual(PrimitiveType.LINES); + } + + tileset.debugWireframe = false; + scene.renderForSpecs(); + commands = scene.frameState.commandList; + for (i = 0; i < commands.length; ++i) { + expect(commands[i].primitiveType).toEqual(PrimitiveType.TRIANGLES); + } + }); + }); + it('debugShowBoundingVolume', function() { return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { viewRootOnly(); From 3010fce6f26c7a8e825457fe87619875dc938ad9 Mon Sep 17 00:00:00 2001 From: Austin Eng <213reeses@gmail.com> Date: Wed, 11 Jan 2017 09:22:26 -0500 Subject: [PATCH 3/4] simplify debugWireframe to update every frame --- Source/Scene/Batched3DModel3DTileContent.js | 8 +++----- Source/Scene/Cesium3DTile.js | 8 -------- Source/Scene/Cesium3DTileBatchTable.js | 13 ++----------- Source/Scene/Cesium3DTileContent.js | 13 ------------- Source/Scene/Composite3DTileContent.js | 11 ----------- Source/Scene/Empty3DTileContent.js | 6 ------ Source/Scene/Instanced3DModel3DTileContent.js | 8 +------- Source/Scene/PointCloud3DTileContent.js | 6 ------ Source/Scene/Tileset3DTileContent.js | 7 +------ Specs/Scene/Cesium3DTilesetSpec.js | 6 +++--- 10 files changed, 10 insertions(+), 76 deletions(-) diff --git a/Source/Scene/Batched3DModel3DTileContent.js b/Source/Scene/Batched3DModel3DTileContent.js index 5ce08e047213..2200331a1cdf 100644 --- a/Source/Scene/Batched3DModel3DTileContent.js +++ b/Source/Scene/Batched3DModel3DTileContent.js @@ -310,6 +310,7 @@ define([ basePath : getBaseUri(this._url), modelMatrix : this._tile.computedTransform, shadows: this._tileset.shadows, + debugWireframe: this._tileset.debugWireframe, incrementallyLoadTextures : false, vertexShaderLoaded : getVertexShaderCallback(this), fragmentShaderLoaded : getFragmentShaderCallback(this), @@ -342,11 +343,7 @@ define([ color = enabled ? color : Color.WHITE; this.batchTable.setAllColor(color); }; - - Batched3DModel3DTileContent.prototype.applyWireframe = function(enabled) { - this._model.debugWireframe = enabled; - }; - + /** * Part of the {@link Cesium3DTileContent} interface. */ @@ -369,6 +366,7 @@ define([ this.batchTable.update(tileset, frameState); this._model.modelMatrix = this._tile.computedTransform; this._model.shadows = this._tileset.shadows; + this._model.debugWireframe = this._tileset.debugWireframe; this._model.update(frameState); frameState.addCommand = oldAddCommand; diff --git a/Source/Scene/Cesium3DTile.js b/Source/Scene/Cesium3DTile.js index b8af69c43086..a492d8577559 100644 --- a/Source/Scene/Cesium3DTile.js +++ b/Source/Scene/Cesium3DTile.js @@ -702,14 +702,6 @@ define([ tile._debugColorizeTiles = false; tile._content.applyDebugSettings(false, tile._debugColor); } - - if (tileset.debugWireframe && !tile._debugWireframe) { - tile._debugWireframe = true; - tile._content.applyWireframe(true); - } else if (!tileset.debugWireframe && tile._debugWireframe) { - tile._debugWireframe = false; - tile._content.applyWireframe(false); - } } /** diff --git a/Source/Scene/Cesium3DTileBatchTable.js b/Source/Scene/Cesium3DTileBatchTable.js index 55e2af4e68f7..481d7140e591 100644 --- a/Source/Scene/Cesium3DTileBatchTable.js +++ b/Source/Scene/Cesium3DTileBatchTable.js @@ -1192,20 +1192,12 @@ define([ OPAQUE_AND_TRANSLUCENT : 2 }; - function updateDerivedCommandsShadows(derivedCommands, command) { + function updateDerivedCommands(derivedCommands, command) { for (var name in derivedCommands) { if (derivedCommands.hasOwnProperty(name)) { var derivedCommand = derivedCommands[name]; derivedCommand.castShadows = command.castShadows; derivedCommand.receiveShadows = command.receiveShadows; - } - } - } - - function updateDerivedCommandsWireframe(derivedCommands, command) { - for (var name in derivedCommands) { - if (derivedCommands.hasOwnProperty(name)) { - var derivedCommand = derivedCommands[name]; derivedCommand.primitiveType = command.primitiveType; } } @@ -1228,8 +1220,7 @@ define([ derivedCommands.front = deriveTranslucentCommand(command, CullFace.BACK); } - updateDerivedCommandsShadows(derivedCommands, command); - updateDerivedCommandsWireframe(derivedCommands, command); + updateDerivedCommands(derivedCommands, command); // If the command was originally opaque: // * If the styling applied to the tile is all opaque, use the original command diff --git a/Source/Scene/Cesium3DTileContent.js b/Source/Scene/Cesium3DTileContent.js index 3800efbb51e8..e63d77075858 100644 --- a/Source/Scene/Cesium3DTileContent.js +++ b/Source/Scene/Cesium3DTileContent.js @@ -199,19 +199,6 @@ define([ DeveloperError.throwInstantiationError(); }; - /** - * Called when {@link Cesium3DTileset#debugWireframe} changes. - *

- * This is used to implement the Cesium3DTileContent interface, but is - * not part of the public Cesium API. - *

- * - * @private - */ - Cesium3DTileContent.prototype.applyWireframe = function(enabled) { - DeveloperError.throwInstantiationError(); - }; - /** * Apply a style to the content using a shader instead of a batch table. Currently this is only * applicable for {@link PointCloud3DTileContent}. diff --git a/Source/Scene/Composite3DTileContent.js b/Source/Scene/Composite3DTileContent.js index 6e406e3afd1f..6dd61495b387 100644 --- a/Source/Scene/Composite3DTileContent.js +++ b/Source/Scene/Composite3DTileContent.js @@ -245,17 +245,6 @@ define([ } }; - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Composite3DTileContent.prototype.applyWireframe = function(enabled) { - var contents = this._contents; - var length = contents.length; - for (var i = 0; i < length; ++i) { - contents[i].applyWireframe(enabled); - } - }; - /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Source/Scene/Empty3DTileContent.js b/Source/Scene/Empty3DTileContent.js index 52c20fc312d1..65b45ade6d1b 100644 --- a/Source/Scene/Empty3DTileContent.js +++ b/Source/Scene/Empty3DTileContent.js @@ -113,12 +113,6 @@ define([ Empty3DTileContent.prototype.applyDebugSettings = function(enabled, color) { }; - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Empty3DTileContent.prototype.applyWireframe = function(enabled) { - }; - /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Source/Scene/Instanced3DModel3DTileContent.js b/Source/Scene/Instanced3DModel3DTileContent.js index a126f6062f88..572a5e5a632c 100644 --- a/Source/Scene/Instanced3DModel3DTileContent.js +++ b/Source/Scene/Instanced3DModel3DTileContent.js @@ -470,13 +470,6 @@ define([ this.batchTable.setAllColor(color); }; - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Instanced3DModel3DTileContent.prototype.applyWireframe = function(enabled) { - this._modelInstanceCollection.debugWireframe = enabled; - }; - /** * Part of the {@link Cesium3DTileContent} interface. */ @@ -499,6 +492,7 @@ define([ this.batchTable.update(tileset, frameState); this._modelInstanceCollection.transform = this._tile.computedTransform; this._modelInstanceCollection.shadows = this._tileset.shadows; + this._modelInstanceCollection.debugWireframe = this._tileset.debugWireframe; this._modelInstanceCollection.update(frameState); frameState.addCommand = oldAddCommand; diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index 3898a88bc6a3..e00cea225aec 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -1117,12 +1117,6 @@ define([ this._highlightColor = enabled ? color : Color.WHITE; }; - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - PointCloud3DTileContent.prototype.applyWireframe = function(enabled) { - }; - /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Source/Scene/Tileset3DTileContent.js b/Source/Scene/Tileset3DTileContent.js index c74e6222789e..fda851413943 100644 --- a/Source/Scene/Tileset3DTileContent.js +++ b/Source/Scene/Tileset3DTileContent.js @@ -123,12 +123,7 @@ define([ */ Tileset3DTileContent.prototype.applyDebugSettings = function(enabled, color) { }; - - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Tileset3DTileContent.prototype.applyWireframe = function(enabled) { - }; + /** * Part of the {@link Cesium3DTileContent} interface. diff --git a/Specs/Scene/Cesium3DTilesetSpec.js b/Specs/Scene/Cesium3DTilesetSpec.js index c02a1aa0ab37..3fbb5271d2ec 100644 --- a/Specs/Scene/Cesium3DTilesetSpec.js +++ b/Specs/Scene/Cesium3DTilesetSpec.js @@ -942,21 +942,21 @@ defineSuite([ }); it('debugWireframe', function() { - // More precise test is in Cesium3DTileBatchTableSpec return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { viewRootOnly(); tileset.debugWireframe = true; scene.renderForSpecs(); var commands = scene.frameState.commandList; + var length = commands.length; var i; - for (i = 0; i < commands.length; ++i) { + for (i = 0; i < length; ++i) { expect(commands[i].primitiveType).toEqual(PrimitiveType.LINES); } tileset.debugWireframe = false; scene.renderForSpecs(); commands = scene.frameState.commandList; - for (i = 0; i < commands.length; ++i) { + for (i = 0; i < length; ++i) { expect(commands[i].primitiveType).toEqual(PrimitiveType.TRIANGLES); } }); From cc734cce24a61cd4916a4863a2bd59a580c5db97 Mon Sep 17 00:00:00 2001 From: Austin Eng <213reeses@gmail.com> Date: Wed, 11 Jan 2017 14:57:27 -0500 Subject: [PATCH 4/4] cleanup whitespace --- Source/Scene/Batched3DModel3DTileContent.js | 2 +- Source/Scene/Cesium3DTile.js | 1 - Source/Scene/Tileset3DTileContent.js | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/Scene/Batched3DModel3DTileContent.js b/Source/Scene/Batched3DModel3DTileContent.js index 2200331a1cdf..1fd6ce2dddc2 100644 --- a/Source/Scene/Batched3DModel3DTileContent.js +++ b/Source/Scene/Batched3DModel3DTileContent.js @@ -343,7 +343,7 @@ define([ color = enabled ? color : Color.WHITE; this.batchTable.setAllColor(color); }; - + /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Source/Scene/Cesium3DTile.js b/Source/Scene/Cesium3DTile.js index a492d8577559..fbfa74444225 100644 --- a/Source/Scene/Cesium3DTile.js +++ b/Source/Scene/Cesium3DTile.js @@ -325,7 +325,6 @@ define([ this._debugViewerRequestVolume = undefined; this._debugColor = new Color.fromRandom({ alpha : 1.0 }); this._debugColorizeTiles = false; - this._debugWireframe = false; } defineProperties(Cesium3DTile.prototype, { diff --git a/Source/Scene/Tileset3DTileContent.js b/Source/Scene/Tileset3DTileContent.js index fda851413943..49a7daba114a 100644 --- a/Source/Scene/Tileset3DTileContent.js +++ b/Source/Scene/Tileset3DTileContent.js @@ -123,7 +123,6 @@ define([ */ Tileset3DTileContent.prototype.applyDebugSettings = function(enabled, color) { }; - /** * Part of the {@link Cesium3DTileContent} interface.