diff --git a/Source/Scene/Batched3DModel3DTileContent.js b/Source/Scene/Batched3DModel3DTileContent.js index 11bf088f2f2f..68fab243dc29 100644 --- a/Source/Scene/Batched3DModel3DTileContent.js +++ b/Source/Scene/Batched3DModel3DTileContent.js @@ -10,15 +10,10 @@ define([ '../Core/DeveloperError', '../Core/getAbsoluteUri', '../Core/getBaseUri', - '../Core/getMagic', '../Core/getStringFromTypedArray', - '../Core/loadArrayBuffer', - '../Core/Request', - '../Core/RequestScheduler', '../Core/RequestType', '../ThirdParty/when', './Cesium3DTileBatchTable', - './Cesium3DTileContentState', './Cesium3DTileFeature', './Cesium3DTileFeatureTable', './getAttributeOrUniformBySemantic', @@ -34,15 +29,10 @@ define([ DeveloperError, getAbsoluteUri, getBaseUri, - getMagic, getStringFromTypedArray, - loadArrayBuffer, - Request, - RequestScheduler, RequestType, when, Cesium3DTileBatchTable, - Cesium3DTileContentState, Cesium3DTileFeature, Cesium3DTileFeatureTable, getAttributeOrUniformBySemantic, @@ -59,7 +49,7 @@ define([ * * @private */ - function Batched3DModel3DTileContent(tileset, tile, url) { + function Batched3DModel3DTileContent(tileset, tile, url, arrayBuffer, byteOffset) { this._model = undefined; this._url = url; this._tileset = tileset; @@ -68,14 +58,12 @@ define([ /** * The following properties are part of the {@link Cesium3DTileContent} interface. */ - this.state = Cesium3DTileContentState.UNLOADED; this.batchTable = undefined; this.featurePropertiesDirty = false; - this._contentReadyToProcessPromise = when.defer(); - this._readyPromise = when.defer(); - this._featuresLength = 0; this._features = undefined; + + initialize(this, arrayBuffer, byteOffset); } // This can be overridden for testing purposes @@ -87,7 +75,7 @@ define([ */ featuresLength : { get : function() { - return this._featuresLength; + return this.batchTable.featuresLength; } }, @@ -105,10 +93,7 @@ define([ */ trianglesLength : { get : function() { - if (defined(this._model)) { - return this._model.trianglesLength; - } - return 0; + return this._model.trianglesLength; } }, @@ -117,10 +102,7 @@ define([ */ vertexMemorySizeInBytes : { get : function() { - if (defined(this._model)) { - return this._model.vertexMemorySizeInBytes; - } - return 0; + return this._model.vertexMemorySizeInBytes; } }, @@ -129,10 +111,7 @@ define([ */ textureMemorySizeInBytes : { get : function() { - if (defined(this._model)) { - return this._model.textureMemorySizeInBytes; - } - return 0; + return this._model.textureMemorySizeInBytes; } }, @@ -141,10 +120,7 @@ define([ */ batchTableMemorySizeInBytes : { get : function() { - if (defined(this.batchTable)) { - return this.batchTable.memorySizeInBytes; - } - return 0; + return this.batchTable.memorySizeInBytes; } }, @@ -157,28 +133,19 @@ define([ } }, - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - contentReadyToProcessPromise : { - get : function() { - return this._contentReadyToProcessPromise.promise; - } - }, - /** * Part of the {@link Cesium3DTileContent} interface. */ readyPromise : { get : function() { - return this._readyPromise.promise; + return this._model.readyPromise; } } }); function createFeatures(content) { var tileset = content._tileset; - var featuresLength = content._featuresLength; + var featuresLength = content.featuresLength; if (!defined(content._features) && (featuresLength > 0)) { var features = new Array(featuresLength); for (var i = 0; i < featuresLength; ++i) { @@ -199,7 +166,7 @@ define([ * Part of the {@link Cesium3DTileContent} interface. */ Batched3DModel3DTileContent.prototype.getFeature = function(batchId) { - var featuresLength = this._featuresLength; + var featuresLength = this.featuresLength; //>>includeStart('debug', pragmas.debug); if (!defined(batchId) || (batchId < 0) || (batchId >= featuresLength)) { throw new DeveloperError('batchId is required and between zero and featuresLength - 1 (' + (featuresLength - 1) + ').'); @@ -212,38 +179,6 @@ define([ var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Batched3DModel3DTileContent.prototype.request = function() { - var that = this; - - var distance = this._tile.distanceToCamera; - var promise = RequestScheduler.schedule(new Request({ - url : this._url, - server : this._tile.requestServer, - requestFunction : loadArrayBuffer, - type : RequestType.TILES3D, - distance : distance - })); - - if (!defined(promise)) { - return false; - } - - this.state = Cesium3DTileContentState.LOADING; - promise.then(function(arrayBuffer) { - if (that.isDestroyed()) { - return when.reject('tileset is destroyed'); - } - that.initialize(arrayBuffer); - }).otherwise(function(error) { - that.state = Cesium3DTileContentState.FAILED; - that._readyPromise.reject(error); - }); - return true; - }; - function getBatchIdAttributeName(gltf) { var batchIdAttributeName = getAttributeOrUniformBySemantic(gltf, '_BATCHID'); if (!defined(batchIdAttributeName)) { @@ -285,21 +220,17 @@ define([ }; } - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Batched3DModel3DTileContent.prototype.initialize = function(arrayBuffer, byteOffset) { + function initialize(content, arrayBuffer, byteOffset) { + var tileset = content._tileset; + var tile = content._tile; + var basePath = getAbsoluteUri(getBaseUri(content._url, true)); + var byteStart = defaultValue(byteOffset, 0); byteOffset = byteStart; var uint8Array = new Uint8Array(arrayBuffer); - var magic = getMagic(uint8Array, byteOffset); - if (magic !== 'b3dm') { - throw new DeveloperError('Invalid Batched 3D Model. Expected magic=b3dm. Read magic=' + magic); - } - var view = new DataView(arrayBuffer); - byteOffset += sizeOfUint32; // Skip magic number + byteOffset += sizeOfUint32; // Skip magic //>>includeStart('debug', pragmas.debug); var version = view.getUint32(byteOffset, true); @@ -371,7 +302,6 @@ define([ batchLength = featureTable.getGlobalProperty('BATCH_LENGTH', ComponentDatatype.UNSIGNED_INT); featureTable.featuresLength = batchLength; - this._featuresLength = batchLength; var batchTableJson; var batchTableBinary; @@ -394,48 +324,35 @@ define([ } } - var batchTable = new Cesium3DTileBatchTable(this, batchLength, batchTableJson, batchTableBinary); - this.batchTable = batchTable; + var batchTable = new Cesium3DTileBatchTable(content, batchLength, batchTableJson, batchTableBinary); + content.batchTable = batchTable; var gltfByteLength = byteStart + byteLength - byteOffset; var gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength); // PERFORMANCE_IDEA: patch the shader on demand, e.g., the first time show/color changes. // The pick shader still needs to be patched. - var model = new Model({ + content._model = new Model({ gltf : gltfView, cull : false, // The model is already culled by the 3D tiles releaseGltfJson : true, // Models are unique and will not benefit from caching so save memory - basePath : getAbsoluteUri(getBaseUri(this._url, true)), - modelMatrix : this._tile.computedTransform, - upAxis : this._tileset._gltfUpAxis, - shadows: this._tileset.shadows, - debugWireframe: this._tileset.debugWireframe, + basePath : basePath, + requestType : RequestType.TILES3D, + modelMatrix : tile.computedTransform, + upAxis : tileset._gltfUpAxis, + shadows: tileset.shadows, + debugWireframe: tileset.debugWireframe, incrementallyLoadTextures : false, - pickPrimitive : this._tileset, - vertexShaderLoaded : getVertexShaderCallback(this), - fragmentShaderLoaded : getFragmentShaderCallback(this), + pickPrimitive : tileset, + vertexShaderLoaded : getVertexShaderCallback(content), + fragmentShaderLoaded : getFragmentShaderCallback(content), uniformMapLoaded : batchTable.getUniformMapCallback(), - pickVertexShaderLoaded : getPickVertexShaderCallback(this), + pickVertexShaderLoaded : getPickVertexShaderCallback(content), pickFragmentShaderLoaded : batchTable.getPickFragmentShaderCallback(), pickUniformMapLoaded : batchTable.getPickUniformMapCallback(), addBatchIdToGeneratedShaders : (batchLength > 0) // If the batch table has values in it, generated shaders will need a batchId attribute }); - - this._model = model; - this.state = Cesium3DTileContentState.PROCESSING; - this._contentReadyToProcessPromise.resolve(this); - - var that = this; - - model.readyPromise.then(function(model) { - that.state = Cesium3DTileContentState.READY; - that._readyPromise.resolve(that); - }).otherwise(function(error) { - that.state = Cesium3DTileContentState.FAILED; - that._readyPromise.reject(error); - }); - }; + } /** * Part of the {@link Cesium3DTileContent} interface. @@ -469,7 +386,6 @@ define([ 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 ae1a1c0787e6..ba0c0cfaaedd 100644 --- a/Source/Scene/Cesium3DTile.js +++ b/Source/Scene/Cesium3DTile.js @@ -13,16 +13,22 @@ define([ '../Core/DeveloperError', '../Core/GeometryInstance', '../Core/getExtensionFromUri', + '../Core/getMagic', + '../Core/getStringFromTypedArray', '../Core/Intersect', '../Core/joinUrls', + '../Core/loadArrayBuffer', '../Core/Matrix3', '../Core/Matrix4', '../Core/OrientedBoundingBox', '../Core/Rectangle', '../Core/RectangleOutlineGeometry', + '../Core/Request', '../Core/RequestScheduler', + '../Core/RequestType', '../Core/SphereOutlineGeometry', '../ThirdParty/Uri', + '../ThirdParty/when', './Cesium3DTileChildrenVisibility', './Cesium3DTileContentFactory', './Cesium3DTileContentState', @@ -50,16 +56,22 @@ define([ DeveloperError, GeometryInstance, getExtensionFromUri, + getMagic, + getStringFromTypedArray, Intersect, joinUrls, + loadArrayBuffer, Matrix3, Matrix4, OrientedBoundingBox, Rectangle, RectangleOutlineGeometry, + Request, RequestScheduler, + RequestType, SphereOutlineGeometry, Uri, + when, Cesium3DTileChildrenVisibility, Cesium3DTileContentFactory, Cesium3DTileContentState, @@ -163,17 +175,6 @@ define([ */ this.children = []; - /** - * Descendant tiles that need to be visible before this tile can refine. For example, if - * a child is empty (such as for accelerating culling), its descendants with content would - * be added here. This array is generated during runtime in {@link Cesium3DTileset#loadTileset}. - * If a tiles's children all have content, this is left undefined. - * - * @type {Array} - * @readonly - */ - this.descendantsWithContent = undefined; - /** * This tile's parent or undefined if this tile is the root. *

@@ -187,54 +188,45 @@ define([ */ this.parent = parent; - var hasContent; - var hasTilesetContent; + var content; + var hasEmptyContent; + var contentState; + var contentUrl; var requestServer; - var createContent; if (defined(contentHeader)) { - var contentUrl = contentHeader.url; - var url = joinUrls(baseUrl, contentUrl); - requestServer = RequestScheduler.getRequestServer(url); - var type = getExtensionFromUri(url); - var contentFactory = Cesium3DTileContentFactory[type]; - - if (type === 'json') { - hasContent = false; - hasTilesetContent = true; - } else { - hasContent = true; - hasTilesetContent = false; - } - - //>>includeStart('debug', pragmas.debug); - if (!defined(contentFactory)) { - throw new DeveloperError('Unknown tile content type, ' + type + ', for ' + url); - } - //>>includeEnd('debug'); - - var that = this; - createContent = function() { - return contentFactory(tileset, that, url); - }; + hasEmptyContent = false; + contentState = Cesium3DTileContentState.UNLOADED; + contentUrl = joinUrls(baseUrl, contentHeader.url); + requestServer = RequestScheduler.getRequestServer(contentUrl); } else { - hasContent = false; - hasTilesetContent = false; - - createContent = function() { - return new Empty3DTileContent(); - }; + content = new Empty3DTileContent(); + hasEmptyContent = true; + contentState = Cesium3DTileContentState.READY; } - this._createContent = createContent; - this._content = createContent(); + this._content = content; + this._contentUrl = contentUrl; + this._contentState = contentState; + this._contentReadyToProcessPromise = undefined; + this._contentReadyPromise = undefined; this._requestServer = requestServer; /** - * When true, the tile has content. This does not imply that the content is loaded. + * When true, the tile has no content. + * + * @type {Boolean} + * @readonly + * + * @private + */ + this.hasEmptyContent = hasEmptyContent; + + /** + * When true, the tile's content is renderable. *

- * When a tile's content points to a external tileset, the tile is not considered to have content. + * This is false until the tile's content is loaded. *

* * @type {Boolean} @@ -242,17 +234,20 @@ define([ * * @private */ - this.hasContent = hasContent; + this.hasRenderableContent = false; /** * When true, the tile's content points to an external tileset. + *

+ * This is false until the tile's content is loaded. + *

* * @type {Boolean} * @readonly * * @private */ - this.hasTilesetContent = hasTilesetContent; + this.hasTilesetContent = false; /** * The corresponding node in the cache replacement list. @@ -426,7 +421,7 @@ define([ */ contentReady : { get : function() { - return this._content.state === Cesium3DTileContentState.READY; + return this._contentState === Cesium3DTileContentState.READY; } }, @@ -441,7 +436,47 @@ define([ */ contentUnloaded : { get : function() { - return this._content.state === Cesium3DTileContentState.UNLOADED; + return this._contentState === Cesium3DTileContentState.UNLOADED; + } + }, + + /** + * Gets the promise that will be resolved when the tile's content is ready to process. + * This happens after the content is downloaded but before the content is ready + * to render. + *

+ * The promise remains undefined until the tile's content is requested. + *

+ * + * @type {Promise.} + * @readonly + * + * @private + */ + contentReadyToProcessPromise : { + get : function() { + if (defined(this._contentReadyToProcessPromise)) { + return this._contentReadyToProcessPromise.promise; + } + } + }, + + /** + * Gets the promise that will be resolved when the tile's content is ready to render. + *

+ * The promise remains undefined until the tile's content is requested. + *

+ * + * @type {Promise.} + * @readonly + * + * @private + */ + contentReadyPromise : { + get : function() { + if (defined(this._contentReadyPromise)) { + return this._contentReadyPromise.promise; + } } } }); @@ -455,7 +490,69 @@ define([ * @private */ Cesium3DTile.prototype.requestContent = function() { - this._content.request(); + var that = this; + + if (this.hasEmptyContent) { + return false; + } + + if (!this.canRequestContent()) { + return false; + } + + var distance = this.distanceToCamera; + var promise = RequestScheduler.schedule(new Request({ + url : this._contentUrl, + server : this._requestServer, + requestFunction : loadArrayBuffer, + type : RequestType.TILES3D, + distance : distance + })); + + if (!defined(promise)) { + return false; + } + + this._contentState = Cesium3DTileContentState.LOADING; + this._contentReadyToProcessPromise = when.defer(); + this._contentReadyPromise = when.defer(); + + promise.then(function(arrayBuffer) { + if (that.isDestroyed()) { + return when.reject('tileset is destroyed'); + } + var uint8Array = new Uint8Array(arrayBuffer); + var magic = getMagic(uint8Array); + var contentFactory = Cesium3DTileContentFactory[magic]; + var content; + + if (defined(contentFactory)) { + content = contentFactory(that._tileset, that, that._contentUrl, arrayBuffer, 0); + that.hasRenderableContent = true; + } else { + // The content may be json instead + content = Cesium3DTileContentFactory.json(that._tileset, that, that._contentUrl, arrayBuffer, 0); + that.hasTilesetContent = true; + } + + that._content = content; + that._contentState = Cesium3DTileContentState.PROCESSING; + that._contentReadyToProcessPromise.resolve(content); + + content.readyPromise.then(function(content) { + that._contentState = Cesium3DTileContentState.READY; + that._contentReadyPromise.resolve(content); + }).otherwise(function(error) { + that._contentState = Cesium3DTileContentState.FAILED; + that._contentReadyPromise.reject(error); + }); + }).otherwise(function(error) { + that._contentState = Cesium3DTileContentState.FAILED; + that._contentReadyPromise.reject(error); + that._contentReadyToProcessPromise.reject(error); + }); + + return true; }; /** @@ -481,8 +578,14 @@ define([ * @private */ Cesium3DTile.prototype.unloadContent = function() { + if (!this.hasRenderableContent) { + return; + } + this._content = this._content && this._content.destroy(); - this._content = this._createContent(); + this._contentState = Cesium3DTileContentState.UNLOADED; + this._contentReadyToProcessPromise = undefined; + this._contentReadyPromise = undefined; this.replacementNode = undefined; @@ -534,7 +637,7 @@ define([ * * @private */ - Cesium3DTile.prototype.contentsVisibility = function(frameState) { + Cesium3DTile.prototype.contentVisibility = function(frameState) { // Assumes the tile's bounding volume intersects the culling volume already, so // just return Intersect.INSIDE if there is no content bounding volume. if (!defined(this._contentBoundingVolume)) { diff --git a/Source/Scene/Cesium3DTileContent.js b/Source/Scene/Cesium3DTileContent.js index d5fe0bbdefc7..c06afb803012 100644 --- a/Source/Scene/Cesium3DTileContent.js +++ b/Source/Scene/Cesium3DTileContent.js @@ -26,22 +26,12 @@ define([ * @see Tileset3DTileContent * @see Empty3DTileContent */ - function Cesium3DTileContent(tileset, tile, url) { + function Cesium3DTileContent(tileset, tile, url, arrayBuffer, byteOffset) { // Private members are not exposed in the public Cesium API, but derived classes // need to implement them. The scope should be treated like C#'s internal. When // we're ready, we'll add these members to the public API so users can implement // new tile formats. - /** - * The current state of the tile's content. - * - * @type {Cesium3DTileContentState} - * @readonly - * - * @private - */ - this.state = undefined; - /** * Gets the batch table texture for this tile. * @@ -121,28 +111,28 @@ define([ }, /** - * Gets the tile's batch table memory in bytes. + * Gets the tile's texture memory in bytes. * * @memberof Cesium3DTileContent.prototype * * @type {Number} * @readonly */ - batchTableMemorySizeInBytes : { + textureMemorySizeInBytes : { get : function() { DeveloperError.throwInstantiationError(); } }, /** - * Gets the tile's texture memory in bytes. + * Gets the tile's batch table memory in bytes. * * @memberof Cesium3DTileContent.prototype * * @type {Number} * @readonly */ - textureMemorySizeInBytes : { + batchTableMemorySizeInBytes : { get : function() { DeveloperError.throwInstantiationError(); } @@ -152,7 +142,7 @@ define([ * Gets the array of {@link Cesium3DTileContent} objects that represent the * content a composite's inner tiles, which can also be composites. * - * @memberof Composite3DTileContent.prototype + * @memberof Cesium3DTileContent.prototype * * @type {Array} * @readonly @@ -163,29 +153,13 @@ define([ } }, - /** - * Gets the promise that will be resolved when the tile's content is ready to process. - * This happens after the content is downloaded but before the content is ready - * to render. - * - * @type {Promise.} - * @readonly - * - * @private - */ - contentReadyToProcessPromise : { - get : function() { - DeveloperError.throwInstantiationError(); - } - }, - /** * Gets the promise that will be resolved when the tile's content is ready to render. * + * @memberof Cesium3DTileContent.prototype + * * @type {Promise.} * @readonly - * - * @private */ readyPromise : { get : function() { @@ -220,42 +194,6 @@ define([ DeveloperError.throwInstantiationError(); }; - /** - * Requests the tile's content. - *

- * The request may not be made if the Cesium Request Scheduler can't prioritize it. - *

- *

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

- * - * @returns {Boolean} Whether the request was initiated. May be false if the RequestScheduler is full. - * - * @private - */ - Cesium3DTileContent.prototype.request = function() { - DeveloperError.throwInstantiationError(); - }; - - /** - * Parses the tile's content's array buffer and initializes the content. This does not - * necessarily move the state to READY since WebGL resource creation may be - * amortized over several frames. - *

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

- * - * @param {Object} arrayBuffer The array buffer containing the contents payload. - * @param {Number} byteOffset The zero-based offset, in bytes, into the array buffer. - * - * @private - */ - Cesium3DTileContent.prototype.initialize = function(arrayBuffer, byteOffset) { - DeveloperError.throwInstantiationError(); - }; - /** * Called when {@link Cesium3DTileset#debugColorizeTiles} changes. *

diff --git a/Source/Scene/Cesium3DTileContentFactory.js b/Source/Scene/Cesium3DTileContentFactory.js index 4a1b14fad74e..b4e9471511e2 100644 --- a/Source/Scene/Cesium3DTileContentFactory.js +++ b/Source/Scene/Cesium3DTileContentFactory.js @@ -20,23 +20,23 @@ define([ * @private */ var Cesium3DTileContentFactory = { - b3dm : function(tileset, tile, url) { - return new Batched3DModel3DTileContent(tileset, tile, url); + b3dm : function(tileset, tile, url, arrayBuffer, byteOffset) { + return new Batched3DModel3DTileContent(tileset, tile, url, arrayBuffer, byteOffset); }, - pnts : function(tileset, tile, url) { - return new PointCloud3DTileContent(tileset, tile, url); + pnts : function(tileset, tile, url, arrayBuffer, byteOffset) { + return new PointCloud3DTileContent(tileset, tile, url, arrayBuffer, byteOffset); }, - i3dm : function(tileset, tile, url) { - return new Instanced3DModel3DTileContent(tileset, tile, url); + i3dm : function(tileset, tile, url, arrayBuffer, byteOffset) { + return new Instanced3DModel3DTileContent(tileset, tile, url, arrayBuffer, byteOffset); }, - cmpt : function(tileset, tile, url) { + cmpt : function(tileset, tile, url, arrayBuffer, byteOffset) { // Send in the factory in order to avoid a cyclical dependency - return new Composite3DTileContent(tileset, tile, url, Cesium3DTileContentFactory); + return new Composite3DTileContent(tileset, tile, url, arrayBuffer, byteOffset, Cesium3DTileContentFactory); }, - json : function(tileset, tile, url) { - return new Tileset3DTileContent(tileset, tile, url); + json : function(tileset, tile, url, arrayBuffer, byteOffset) { + return new Tileset3DTileContent(tileset, tile, url, arrayBuffer, byteOffset); } }; return Cesium3DTileContentFactory; -}); \ No newline at end of file +}); diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 801e202191df..27ed62414e58 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -500,14 +500,19 @@ define([ this._readyPromise = when.defer(); var that = this; - this.loadTileset(tilesetUrl).then(function(data) { - var tilesetJson = data.tilesetJson; + + // We don't know the distance of the tileset until tileset.json is loaded, so use the default distance for now + RequestScheduler.request(tilesetUrl, loadJson, undefined, RequestType.TILES3D).then(function(tilesetJson) { + if (that.isDestroyed()) { + return when.reject('tileset is destroyed'); + } + that._root = that.loadTileset(tilesetUrl, tilesetJson); + var gltfUpAxis = defined(tilesetJson.asset.gltfUpAxis) ? Axis.fromName(tilesetJson.asset.gltfUpAxis) : Axis.Y; that._asset = tilesetJson.asset; that._properties = tilesetJson.properties; that._geometricError = tilesetJson.geometricError; that._gltfUpAxis = gltfUpAxis; - that._root = data.root; that._readyPromise.resolve(that); }).otherwise(function(error) { that._readyPromise.reject(error); @@ -996,92 +1001,80 @@ define([ * * @private */ - Cesium3DTileset.prototype.loadTileset = function(tilesetUrl, parentTile) { - var that = this; - - // We don't know the distance of the tileset until tiles.json is loaded, so use the default distance for now - return RequestScheduler.request(tilesetUrl, loadJson, undefined, RequestType.TILES3D).then(function(tilesetJson) { - if (that.isDestroyed()) { - return when.reject('tileset is destroyed'); - } - - if (!defined(tilesetJson.asset) || (tilesetJson.asset.version !== '0.0')) { - throw new DeveloperError('The tileset must be 3D Tiles version 0.0. See https://github.com/AnalyticalGraphicsInc/3d-tiles#spec-status'); - } + Cesium3DTileset.prototype.loadTileset = function(tilesetUrl, tilesetJson, parentTile) { + if (!defined(tilesetJson.asset) || (tilesetJson.asset.version !== '0.0')) { + throw new DeveloperError('The tileset must be 3D Tiles version 0.0. See https://github.com/AnalyticalGraphicsInc/3d-tiles#spec-status'); + } - var stats = that._statistics; + var stats = this._statistics; - // Append the version to the baseUrl - var hasVersionQuery = /[?&]v=/.test(tilesetUrl); - if (!hasVersionQuery) { - var versionQuery = '?v=' + defaultValue(tilesetJson.asset.tilesetVersion, '0.0'); - that._baseUrl = joinUrls(that._baseUrl, versionQuery); - tilesetUrl = joinUrls(tilesetUrl, versionQuery, false); - } + // Append the version to the baseUrl + var hasVersionQuery = /[?&]v=/.test(tilesetUrl); + if (!hasVersionQuery) { + var versionQuery = '?v=' + defaultValue(tilesetJson.asset.tilesetVersion, '0.0'); + this._baseUrl = joinUrls(this._baseUrl, versionQuery); + tilesetUrl = joinUrls(tilesetUrl, versionQuery, false); + } - // A tileset.json referenced from a tile may exist in a different directory than the root tileset. - // Get the baseUrl relative to the external tileset. - var baseUrl = getBaseUri(tilesetUrl, true); - var rootTile = new Cesium3DTile(that, baseUrl, tilesetJson.root, parentTile); + // A tileset.json referenced from a tile may exist in a different directory than the root tileset. + // Get the baseUrl relative to the external tileset. + var baseUrl = getBaseUri(tilesetUrl, true); + var rootTile = new Cesium3DTile(this, baseUrl, tilesetJson.root, parentTile); - // If there is a parentTile, add the root of the currently loading tileset - // to parentTile's children, and update its _depth. - if (defined(parentTile)) { - parentTile.children.push(rootTile); - rootTile._depth = parentTile._depth + 1; - } + // If there is a parentTile, add the root of the currently loading tileset + // to parentTile's children, and update its _depth. + if (defined(parentTile)) { + parentTile.children.push(rootTile); + rootTile._depth = parentTile._depth + 1; + } - ++stats.numberTotal; + ++stats.numberTotal; - var stack = []; - stack.push({ - header : tilesetJson.root, - cesium3DTile : rootTile - }); + var stack = []; + stack.push({ + header : tilesetJson.root, + cesium3DTile : rootTile + }); - while (stack.length > 0) { - var tile = stack.pop(); - var tile3D = tile.cesium3DTile; - var children = tile.header.children; - if (defined(children)) { - var length = children.length; - for (var k = 0; k < length; ++k) { - var childHeader = children[k]; - var childTile = new Cesium3DTile(that, baseUrl, childHeader, tile3D); - tile3D.children.push(childTile); - childTile._depth = tile3D._depth + 1; - ++stats.numberTotal; - stack.push({ - header : childHeader, - cesium3DTile : childTile - }); - } + while (stack.length > 0) { + var tile = stack.pop(); + var tile3D = tile.cesium3DTile; + var children = tile.header.children; + if (defined(children)) { + var length = children.length; + for (var k = 0; k < length; ++k) { + var childHeader = children[k]; + var childTile = new Cesium3DTile(this, baseUrl, childHeader, tile3D); + tile3D.children.push(childTile); + childTile._depth = tile3D._depth + 1; + ++stats.numberTotal; + stack.push({ + header : childHeader, + cesium3DTile : childTile + }); } - Cesium3DTileOptimizations.checkChildrenWithinParent(tile3D, true); - - // Create a load heap, one for each unique server. We can only make limited requests to a given - // server so it is unnecessary to keep a queue of all tiles needed to be loaded. - // Instead of creating a list of all tiles to load and then sorting it entirely to find the best ones, - // we keep just a heap so we have the best `maximumRequestsPerServer` to load. The order of these does - // not matter much as we will try to load them all. - // The heap approach is a O(n log k) to find the best tiles for loading. - var requestServer = tile3D.requestServer; - if (defined(requestServer)) { - if (!defined(that._requestHeaps[requestServer])) { - var heap = new Heap(sortForLoad); - that._requestHeaps[requestServer] = heap; - heap.maximumSize = RequestScheduler.maximumRequestsPerServer; - heap.reserve(heap.maximumSize); - } - tile3D._requestHeap = that._requestHeaps[requestServer]; + } + Cesium3DTileOptimizations.checkChildrenWithinParent(tile3D, true); + + // Create a load heap, one for each unique server. We can only make limited requests to a given + // server so it is unnecessary to keep a queue of all tiles needed to be loaded. + // Instead of creating a list of all tiles to load and then sorting it entirely to find the best ones, + // we keep just a heap so we have the best `maximumRequestsPerServer` to load. The order of these does + // not matter much as we will try to load them all. + // The heap approach is a O(n log k) to find the best tiles for loading. + var requestServer = tile3D.requestServer; + if (defined(requestServer)) { + if (!defined(this._requestHeaps[requestServer])) { + var heap = new Heap(sortForLoad); + this._requestHeaps[requestServer] = heap; + heap.maximumSize = RequestScheduler.maximumRequestsPerServer; + heap.reserve(heap.maximumSize); } + tile3D._requestHeap = this._requestHeaps[requestServer]; } + } - return { - tilesetJson : tilesetJson, - root : rootTile - }; - }); + return rootTile; }; var scratchPositionNormal = new Cartesian3(); @@ -1237,23 +1230,25 @@ define([ if (!outOfCore) { return; } - if (!tile.canRequestContent()) { + + if (tile.hasEmptyContent) { return; } - tile.requestContent(); - var stats = tileset._statistics; - if (!tile.contentUnloaded) { - ++stats.numberOfPendingRequests; + var requested = tile.requestContent(); - var removeFunction = removeFromProcessingQueue(tileset, tile); - tile.content.contentReadyToProcessPromise.then(addToProcessingQueue(tileset, tile)).otherwise(removeFunction); - tile.content.readyPromise.then(removeFunction).otherwise(removeFunction); - } else { + if (!requested) { ++stats.numberOfAttemptedRequests; + return; } + + ++stats.numberOfPendingRequests; + + var removeFunction = removeFromProcessingQueue(tileset, tile); + tile.contentReadyToProcessPromise.then(addToProcessingQueue(tileset, tile)); + tile.contentReadyPromise.then(removeFunction).otherwise(removeFunction); } function selectTile(tileset, tile, frameState) { @@ -1261,7 +1256,7 @@ define([ // zoomed into a neighborhood and can cull the skyscrapers in the root node. if (tile.contentReady && ( (tile.visibilityPlaneMask === CullingVolume.MASK_INSIDE) || - (tile.contentsVisibility(frameState) !== Intersect.OUTSIDE) + (tile.contentVisibility(frameState) !== Intersect.OUTSIDE) )) { tileset._selectedTiles.push(tile); @@ -1338,8 +1333,8 @@ define([ var original = finalQueue.get(i); var tile = original; // traverse up the tree to find a ready ancestor - if (tile.hasContent || tile.hasTilesetContent) { // could be Empty3DTileContent - while (defined(tile) && !(tile.hasContent && tile.contentReady)) { + if (!tile.hasEmptyContent) { + while (defined(tile) && !(tile.hasRenderableContent && tile.contentReady)) { if (!tile.contentReady) { tileset._hasMixedContent = true; } @@ -1520,7 +1515,7 @@ define([ function selectionHeuristic(tileset, ancestor, tile) { var skipLevels = tileset.skipLODs ? tileset._skipLevels : 0; var skipSSEFactor = tileset.skipLODs ? tileset.skipSSEFactor : 0.1; - return (ancestor !== tile && tile.hasContent && !tileset.immediatelyLoadDesiredLOD) && + return (ancestor !== tile && !tile.hasEmptyContent && !tileset.immediatelyLoadDesiredLOD) && (tile._sse < ancestor._sse / skipSSEFactor) && (tile._depth > ancestor._depth + skipLevels); } @@ -1605,12 +1600,7 @@ define([ var loadSiblings = tileset.loadSiblings; if (tile.hasTilesetContent) { - loadTile(tile); - if (!tile.contentReady) { - finalQueue.push(tile); - } else { - updateAndPushChildren(tileset, tile, frameState, stack, loadSiblings, outOfCore); - } + updateAndPushChildren(tileset, tile, frameState, stack, loadSiblings, outOfCore); } else { if (tile.refine === Cesium3DTileRefine.ADD) { loadAndAddToQueue(tileset, tile, finalQueue); @@ -1738,7 +1728,7 @@ define([ // Remove from processing queue tileset._processingQueue.splice(index, 1); --tileset._statistics.numberProcessing; - if (tile.hasContent) { + if (tile.hasRenderableContent) { // RESEARCH_IDEA: ability to unload tiles (without content) for an // external tileset when all the tiles are unloaded. ++tileset._statistics.numberContentReady; diff --git a/Source/Scene/Composite3DTileContent.js b/Source/Scene/Composite3DTileContent.js index 7bbc5d4b7350..d58dc192a44c 100644 --- a/Source/Scene/Composite3DTileContent.js +++ b/Source/Scene/Composite3DTileContent.js @@ -10,8 +10,7 @@ define([ '../Core/Request', '../Core/RequestScheduler', '../Core/RequestType', - '../ThirdParty/when', - './Cesium3DTileContentState' + '../ThirdParty/when' ], function( defaultValue, defined, @@ -23,8 +22,7 @@ define([ Request, RequestScheduler, RequestType, - when, - Cesium3DTileContentState) { + when) { 'use strict'; /** @@ -37,21 +35,20 @@ define([ * * @private */ - function Composite3DTileContent(tileset, tile, url, factory) { + function Composite3DTileContent(tileset, tile, url, arrayBuffer, byteOffset, factory) { this._url = url; this._tileset = tileset; this._tile = tile; this._contents = []; - this._factory = factory; /** * The following properties are part of the {@link Cesium3DTileContent} interface. */ - this.state = Cesium3DTileContentState.UNLOADED; this.batchTable = undefined; - this._contentReadyToProcessPromise = when.defer(); this._readyPromise = when.defer(); + + initialize(this, arrayBuffer, byteOffset, factory); } defineProperties(Composite3DTileContent.prototype, { @@ -145,15 +142,6 @@ define([ } }, - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - contentReadyToProcessPromise : { - get : function() { - return this._contentReadyToProcessPromise.promise; - } - }, - /** * Part of the {@link Cesium3DTileContent} interface. */ @@ -182,53 +170,12 @@ define([ var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Composite3DTileContent.prototype.request = function() { - var that = this; - - var distance = this._tile.distanceToCamera; - var promise = RequestScheduler.schedule(new Request({ - url : this._url, - server : this._tile.requestServer, - requestFunction : loadArrayBuffer, - type : RequestType.TILES3D, - distance : distance - })); - - if (!defined(promise)) { - return false; - } - - this.state = Cesium3DTileContentState.LOADING; - promise.then(function(arrayBuffer) { - if (that.isDestroyed()) { - return when.reject('tileset is destroyed'); - } - that.initialize(arrayBuffer); - }).otherwise(function(error) { - that.state = Cesium3DTileContentState.FAILED; - that._readyPromise.reject(error); - }); - return true; - }; - - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Composite3DTileContent.prototype.initialize = function(arrayBuffer, byteOffset) { + function initialize(content, arrayBuffer, byteOffset, factory) { byteOffset = defaultValue(byteOffset, 0); var uint8Array = new Uint8Array(arrayBuffer); - var magic = getMagic(uint8Array, byteOffset); - if (magic !== 'cmpt') { - throw new DeveloperError('Invalid Composite Tile. Expected magic=cmpt. Read magic=' + magic); - } - var view = new DataView(arrayBuffer); - - byteOffset += sizeOfUint32; // Skip magic number + byteOffset += sizeOfUint32; // Skip magic //>>includeStart('debug', pragmas.debug); var version = view.getUint32(byteOffset, true); @@ -244,9 +191,6 @@ define([ var tilesLength = view.getUint32(byteOffset, true); byteOffset += sizeOfUint32; - this.state = Cesium3DTileContentState.PROCESSING; - this._contentReadyToProcessPromise.resolve(this); - var contentPromises = []; for (var i = 0; i < tilesLength; ++i) { @@ -255,13 +199,12 @@ define([ // Tile byte length is stored after magic and version var tileByteLength = view.getUint32(byteOffset + sizeOfUint32 * 2, true); - var contentFactory = this._factory[tileType]; + var contentFactory = factory[tileType]; if (defined(contentFactory)) { - var content = contentFactory(this._tileset, this._tile, this._url); - content.initialize(arrayBuffer, byteOffset); - this._contents.push(content); - contentPromises.push(content.readyPromise); + var innerContent = contentFactory(content._tileset, content._tile, content._url, arrayBuffer, byteOffset); + content._contents.push(innerContent); + contentPromises.push(innerContent.readyPromise); } else { throw new DeveloperError('Unknown tile content type, ' + tileType + ', inside Composite tile'); } @@ -269,16 +212,12 @@ define([ byteOffset += tileByteLength; } - var that = this; - when.all(contentPromises).then(function() { - that.state = Cesium3DTileContentState.READY; - that._readyPromise.resolve(that); + content._readyPromise.resolve(content); }).otherwise(function(error) { - that.state = Cesium3DTileContentState.FAILED; - that._readyPromise.reject(error); + content._readyPromise.reject(error); }); - }; + } /** * Part of the {@link Cesium3DTileContent} interface. @@ -294,11 +233,11 @@ define([ /** * Part of the {@link Cesium3DTileContent} interface. */ - Composite3DTileContent.prototype.update = function(tileset, context, frameState, commandList) { + Composite3DTileContent.prototype.update = function(tileset, frameState) { var contents = this._contents; var length = contents.length; for (var i = 0; i < length; ++i) { - contents[i].update(tileset, context, frameState, commandList); + contents[i].update(tileset, frameState); } }; diff --git a/Source/Scene/Empty3DTileContent.js b/Source/Scene/Empty3DTileContent.js index 503577a7811c..724647d2a81e 100644 --- a/Source/Scene/Empty3DTileContent.js +++ b/Source/Scene/Empty3DTileContent.js @@ -1,14 +1,10 @@ /*global define*/ define([ '../Core/defineProperties', - '../Core/destroyObject', - '../ThirdParty/when', - './Cesium3DTileContentState' + '../Core/destroyObject' ], function( defineProperties, - destroyObject, - when, - Cesium3DTileContentState) { + destroyObject) { 'use strict'; /** @@ -25,20 +21,8 @@ define([ /** * The following properties are part of the {@link Cesium3DTileContent} interface. */ - this.state = undefined; this.batchTable = undefined; this.featurePropertiesDirty = false; - - this._contentReadyToProcessPromise = when.defer(); - this._readyPromise = when.defer(); - - // Transition into the PROCESSING state. - this.state = Cesium3DTileContentState.PROCESSING; - this._contentReadyToProcessPromise.resolve(this); - - // Transition into the READY state. - this.state = Cesium3DTileContentState.READY; - this._readyPromise.resolve(this); } defineProperties(Empty3DTileContent.prototype, { @@ -105,21 +89,12 @@ define([ } }, - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - contentReadyToProcessPromise : { - get : function() { - return this._contentReadyToProcessPromise.promise; - } - }, - /** * Part of the {@link Cesium3DTileContent} interface. */ readyPromise : { get : function() { - return this._readyPromise.promise; + return undefined; } } }); @@ -140,18 +115,6 @@ define([ return undefined; }; - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Empty3DTileContent.prototype.request = function() { - }; - - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Empty3DTileContent.prototype.initialize = function(arrayBuffer, byteOffset) { - }; - /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Source/Scene/Instanced3DModel3DTileContent.js b/Source/Scene/Instanced3DModel3DTileContent.js index 9e9c543b1373..f12a093106ce 100644 --- a/Source/Scene/Instanced3DModel3DTileContent.js +++ b/Source/Scene/Instanced3DModel3DTileContent.js @@ -13,23 +13,18 @@ define([ '../Core/Ellipsoid', '../Core/getAbsoluteUri', '../Core/getBaseUri', - '../Core/getMagic', '../Core/getStringFromTypedArray', '../Core/joinUrls', - '../Core/loadArrayBuffer', '../Core/Math', '../Core/Matrix3', '../Core/Matrix4', '../Core/Quaternion', - '../Core/Request', - '../Core/RequestScheduler', '../Core/RequestType', '../Core/Transforms', '../Core/TranslationRotationScale', '../ThirdParty/Uri', '../ThirdParty/when', './Cesium3DTileBatchTable', - './Cesium3DTileContentState', './Cesium3DTileFeature', './Cesium3DTileFeatureTable', './ModelInstanceCollection' @@ -47,23 +42,18 @@ define([ Ellipsoid, getAbsoluteUri, getBaseUri, - getMagic, getStringFromTypedArray, joinUrls, - loadArrayBuffer, CesiumMath, Matrix3, Matrix4, Quaternion, - Request, - RequestScheduler, RequestType, Transforms, TranslationRotationScale, Uri, when, Cesium3DTileBatchTable, - Cesium3DTileContentState, Cesium3DTileFeature, Cesium3DTileFeatureTable, ModelInstanceCollection) { @@ -79,7 +69,7 @@ define([ * * @private */ - function Instanced3DModel3DTileContent(tileset, tile, url) { + function Instanced3DModel3DTileContent(tileset, tile, url, arrayBuffer, byteOffset) { this._modelInstanceCollection = undefined; this._url = url; this._tileset = tileset; @@ -88,13 +78,12 @@ define([ /** * The following properties are part of the {@link Cesium3DTileContent} interface. */ - this.state = Cesium3DTileContentState.UNLOADED; this.batchTable = undefined; this.featurePropertiesDirty = false; - this._contentReadyToProcessPromise = when.defer(); - this._readyPromise = when.defer(); this._features = undefined; + + initialize(this, arrayBuffer, byteOffset); } defineProperties(Instanced3DModel3DTileContent.prototype, { @@ -103,11 +92,7 @@ define([ */ featuresLength : { get : function() { - if (defined(this._modelInstanceCollection)) { - return this._modelInstanceCollection.length; - } else { - return 0; - } + return this.batchTable.featuresLength; } }, @@ -125,9 +110,9 @@ define([ */ trianglesLength : { get : function() { - var collection = this._modelInstanceCollection; - if (defined(collection) && defined(collection._model)) { - return collection._model.trianglesLength; + var model = this._modelInstanceCollection._model; + if (defined(model)) { + return model.trianglesLength; } return 0; } @@ -138,9 +123,9 @@ define([ */ vertexMemorySizeInBytes : { get : function() { - var collection = this._modelInstanceCollection; - if (defined(collection) && defined(collection._model)) { - return collection._model.vertexMemorySizeInBytes; + var model = this._modelInstanceCollection._model; + if (defined(model)) { + return model.vertexMemorySizeInBytes; } return 0; } @@ -151,9 +136,9 @@ define([ */ textureMemorySizeInBytes : { get : function() { - var collection = this._modelInstanceCollection; - if (defined(collection) && defined(collection._model)) { - return collection._model.textureMemorySizeInBytes; + var model = this._modelInstanceCollection._model; + if (defined(model)) { + return model.textureMemorySizeInBytes; } return 0; } @@ -164,10 +149,7 @@ define([ */ batchTableMemorySizeInBytes : { get : function() { - if (defined(this.batchTable)) { - return this.batchTable.memorySizeInBytes; - } - return 0; + return this.batchTable.memorySizeInBytes; } }, @@ -180,21 +162,12 @@ define([ } }, - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - contentReadyToProcessPromise : { - get : function() { - return this._contentReadyToProcessPromise.promise; - } - }, - /** * Part of the {@link Cesium3DTileContent} interface. */ readyPromise : { get : function() { - return this._readyPromise.promise; + return this._modelInstanceCollection.readyPromise; } } }); @@ -235,55 +208,16 @@ define([ var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Instanced3DModel3DTileContent.prototype.request = function() { - var that = this; - var distance = this._tile.distanceToCamera; - var promise = RequestScheduler.schedule(new Request({ - url : this._url, - server : this._tile.requestServer, - requestFunction : loadArrayBuffer, - type : RequestType.TILES3D, - distance : distance - })); - - if (!defined(promise)) { - return false; - } - - this.state = Cesium3DTileContentState.LOADING; - promise.then(function(arrayBuffer) { - if (that.isDestroyed()) { - return when.reject('tileset is destroyed'); - } - that.initialize(arrayBuffer); - }).otherwise(function(error) { - that.state = Cesium3DTileContentState.FAILED; - that._readyPromise.reject(error); - }); - return true; - }; - - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Instanced3DModel3DTileContent.prototype.initialize = function(arrayBuffer, byteOffset) { + function initialize(content, arrayBuffer, byteOffset) { var byteStart = defaultValue(byteOffset, 0); byteOffset = defaultValue(byteOffset, 0); var uint8Array = new Uint8Array(arrayBuffer); - var magic = getMagic(uint8Array, byteOffset); - if (magic !== 'i3dm') { - throw new DeveloperError('Invalid Instanced 3D Model. Expected magic=i3dm. Read magic=' + magic); - } - var view = new DataView(arrayBuffer); - byteOffset += sizeOfUint32; // Skip magic number + byteOffset += sizeOfUint32; // Skip magic - var version = view.getUint32(byteOffset, true); //>>includeStart('debug', pragmas.debug); + var version = view.getUint32(byteOffset, true); if (version !== 1) { throw new DeveloperError('Only Instanced 3D Model version 1 is supported. Version ' + version + ' is not.'); } @@ -351,7 +285,7 @@ define([ } } - this.batchTable = new Cesium3DTileBatchTable(this, instancesLength, batchTableJson, batchTableBinary); + content.batchTable = new Cesium3DTileBatchTable(content, instancesLength, batchTableJson, batchTableBinary); var gltfByteLength = byteStart + byteLength - byteOffset; //>>includeStart('debug', pragmas.debug); @@ -365,22 +299,22 @@ define([ // Create model instance collection var collectionOptions = { instances : new Array(instancesLength), - batchTable : this.batchTable, + batchTable : content.batchTable, cull : false, // Already culled by 3D Tiles url : undefined, requestType : RequestType.TILES3D, gltf : undefined, basePath : undefined, incrementallyLoadTextures : false, - upAxis : this._tileset._gltfUpAxis + upAxis : content._tileset._gltfUpAxis }; if (gltfFormat === 0) { var gltfUrl = getStringFromTypedArray(gltfView); - collectionOptions.url = getAbsoluteUri(joinUrls(getBaseUri(this._url, true), gltfUrl)); + collectionOptions.url = getAbsoluteUri(joinUrls(getBaseUri(content._url, true), gltfUrl)); } else { collectionOptions.gltf = gltfView; - collectionOptions.basePath = getBaseUri(this._url, true); + collectionOptions.basePath = getAbsoluteUri(getBaseUri(content._url, true)); } var eastNorthUp = featureTable.getGlobalProperty('EAST_NORTH_UP'); @@ -513,21 +447,8 @@ define([ }; } - var modelInstanceCollection = new ModelInstanceCollection(collectionOptions); - this._modelInstanceCollection = modelInstanceCollection; - this.state = Cesium3DTileContentState.PROCESSING; - this._contentReadyToProcessPromise.resolve(this); - - var that = this; - - modelInstanceCollection.readyPromise.then(function(modelInstanceCollection) { - that.state = Cesium3DTileContentState.READY; - that._readyPromise.resolve(that); - }).otherwise(function(error) { - that.state = Cesium3DTileContentState.FAILED; - that._readyPromise.reject(error); - }); - }; + content._modelInstanceCollection = new ModelInstanceCollection(collectionOptions); + } /** * Part of the {@link Cesium3DTileContent} interface. diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 8f6360e91f1b..c9b233c6e031 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -4290,7 +4290,7 @@ define([ var extensionsUsed = model.gltf.extensionsUsed; if (defined(extensionsUsed)) { var extensionsUsedCount = extensionsUsed.length; - for (var index=0;index>includeEnd('debug'); - this._quantizedVolumeScale = Cartesian3.unpack(quantizedVolumeScale); + content._quantizedVolumeScale = Cartesian3.unpack(quantizedVolumeScale); var quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET'); //>>includeStart('debug', pragmas.debug); @@ -418,7 +357,7 @@ define([ throw new DeveloperError('Global property: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.'); } //>>includeEnd('debug'); - this._quantizedVolumeOffset = Cartesian3.unpack(quantizedVolumeOffset); + content._quantizedVolumeOffset = Cartesian3.unpack(quantizedVolumeOffset); } //>>includeStart('debug', pragmas.debug); @@ -442,13 +381,13 @@ define([ isRGB565 = true; } else if (defined(featureTableJson.CONSTANT_RGBA)) { var constantRGBA = featureTable.getGlobalProperty('CONSTANT_RGBA'); - this._constantColor = Color.fromBytes(constantRGBA[0], constantRGBA[1], constantRGBA[2], constantRGBA[3], this._constantColor); + content._constantColor = Color.fromBytes(constantRGBA[0], constantRGBA[1], constantRGBA[2], constantRGBA[3], content._constantColor); } else { // Use a default constant color - this._constantColor = Color.clone(Color.DARKGRAY, this._constantColor); + content._constantColor = Color.clone(Color.DARKGRAY, content._constantColor); } - this._isTranslucent = isTranslucent; + content._isTranslucent = isTranslucent; // Get the normals var normals; @@ -486,7 +425,7 @@ define([ // Copy the batchTableBinary section and let the underlying ArrayBuffer be freed batchTableBinary = new Uint8Array(batchTableBinary); } - this.batchTable = new Cesium3DTileBatchTable(this, batchLength, batchTableJson, batchTableBinary); + content.batchTable = new Cesium3DTileBatchTable(content, batchLength, batchTableJson, batchTableBinary); } // If points are not batched and there are per-point properties, use these properties for styling purposes @@ -508,25 +447,22 @@ define([ } } - this._parsedContent = { + content._parsedContent = { positions : positions, colors : colors, normals : normals, batchIds : batchIds, styleableProperties : styleableProperties }; - this._pointsLength = pointsLength; - - this._isQuantized = isQuantized; - this._isOctEncoded16P = isOctEncoded16P; - this._isRGB565 = isRGB565; - this._hasColors = defined(colors); - this._hasNormals = defined(normals); - this._hasBatchIds = defined(batchIds); - - this.state = Cesium3DTileContentState.PROCESSING; - this._contentReadyToProcessPromise.resolve(this); - }; + content._pointsLength = pointsLength; + + content._isQuantized = isQuantized; + content._isOctEncoded16P = isOctEncoded16P; + content._isRGB565 = isRGB565; + content._hasColors = defined(colors); + content._hasNormals = defined(normals); + content._hasBatchIds = defined(batchIds); + } var positionLocation = 0; var colorLocation = 1; @@ -1210,8 +1146,6 @@ define([ createShaders(this, frameState, tileset.style); updateModelMatrix = true; - // Set state to ready - this.state = Cesium3DTileContentState.READY; this._readyPromise.resolve(this); this._parsedContent = undefined; // Unload } diff --git a/Source/Scene/Tileset3DTileContent.js b/Source/Scene/Tileset3DTileContent.js index 4110b9cf525a..d8ebf3c62e48 100644 --- a/Source/Scene/Tileset3DTileContent.js +++ b/Source/Scene/Tileset3DTileContent.js @@ -1,16 +1,20 @@ /*global define*/ define([ + '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', '../Core/destroyObject', - '../ThirdParty/when', - './Cesium3DTileContentState' + '../Core/DeveloperError', + '../Core/getStringFromTypedArray', + '../ThirdParty/when' ], function( + defaultValue, defined, defineProperties, destroyObject, - when, - Cesium3DTileContentState) { + DeveloperError, + getStringFromTypedArray, + when) { 'use strict'; /** @@ -23,7 +27,7 @@ define([ * * @private */ - function Tileset3DTileContent(tileset, tile, url) { + function Tileset3DTileContent(tileset, tile, url, arrayBuffer, byteOffset) { this._tileset = tileset; this._tile = tile; this._url = url; @@ -31,12 +35,12 @@ define([ /** * The following properties are part of the {@link Cesium3DTileContent} interface. */ - this.state = Cesium3DTileContentState.UNLOADED; this.batchTable = undefined; this.featurePropertiesDirty = false; - this._contentReadyToProcessPromise = when.defer(); this._readyPromise = when.defer(); + + initialize(this, arrayBuffer, byteOffset); } defineProperties(Tileset3DTileContent.prototype, { @@ -103,15 +107,6 @@ define([ } }, - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - contentReadyToProcessPromise : { - get : function() { - return this._contentReadyToProcessPromise.promise; - } - }, - /** * Part of the {@link Cesium3DTileContent} interface. */ @@ -122,6 +117,23 @@ define([ } }); + function initialize(content, arrayBuffer, byteOffset) { + byteOffset = defaultValue(byteOffset, 0); + var uint8Array = new Uint8Array(arrayBuffer); + var jsonString = getStringFromTypedArray(uint8Array, byteOffset); + var tilesetJson; + + try { + tilesetJson = JSON.parse(jsonString); + } catch (error) { + content._readyPromise.reject(new DeveloperError('Invalid tile content.')); + return; + } + + content._tileset.loadTileset(content._url, tilesetJson, content._tile); + content._readyPromise.resolve(content); + } + /** * Part of the {@link Cesium3DTileContent} interface. Tileset3DTileContent * always returns false since a tile of this type does not have any features. @@ -138,31 +150,6 @@ define([ return undefined; }; - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Tileset3DTileContent.prototype.request = function() { - var that = this; - - this.state = Cesium3DTileContentState.LOADING; - this._tileset.loadTileset(this._url, this._tile).then(function() { - that.state = Cesium3DTileContentState.PROCESSING; - that._contentReadyToProcessPromise.resolve(that); - that.state = Cesium3DTileContentState.READY; - that._readyPromise.resolve(that); - }).otherwise(function(error) { - that.state = Cesium3DTileContentState.FAILED; - that._readyPromise.reject(error); - }); - return true; - }; - - /** - * Part of the {@link Cesium3DTileContent} interface. - */ - Tileset3DTileContent.prototype.initialize = function(arrayBuffer, byteOffset) { - }; - /** * Part of the {@link Cesium3DTileContent} interface. */ diff --git a/Specs/Cesium3DTilesTester.js b/Specs/Cesium3DTilesTester.js index 5cda788679af..245cba12ec9b 100644 --- a/Specs/Cesium3DTilesTester.js +++ b/Specs/Cesium3DTilesTester.js @@ -123,19 +123,16 @@ define([ Cesium3DTilesTester.loadTileExpectError = function(scene, arrayBuffer, type) { var tileset = {}; var url = ''; - var content = Cesium3DTileContentFactory[type](tileset, mockTile, url); expect(function() { - content.initialize(arrayBuffer); + var content = Cesium3DTileContentFactory[type](tileset, mockTile, url, arrayBuffer, type); content.update(tileset, scene.frameState); }).toThrowDeveloperError(); - return content; }; Cesium3DTilesTester.loadTile = function(scene, arrayBuffer, type) { var tileset = {}; var url = ''; - var content = Cesium3DTileContentFactory[type](tileset, mockTile, url); - content.initialize(arrayBuffer); + var content = Cesium3DTileContentFactory[type](tileset, mockTile, url, arrayBuffer, 0); content.update(tileset, scene.frameState); return content; }; @@ -148,30 +145,13 @@ define([ baseUrl : counter++ }; var url = ''; - var content = Cesium3DTileContentFactory[type](tileset, mockTile, url); - content.initialize(arrayBuffer); + var content = Cesium3DTileContentFactory[type](tileset, mockTile, url, arrayBuffer, 0); content.update(tileset, scene.frameState); return content.readyPromise.then(function(content) { fail('should not resolve'); }).otherwise(function(error) { - expect(content.state).toEqual(Cesium3DTileContentState.FAILED); - }); - }; - - Cesium3DTilesTester.rejectsReadyPromiseOnFailedRequest = function(type) { - var tileset = { - loadTileset : Cesium3DTileset.prototype.loadTileset - }; - var url = 'invalid'; - var content = Cesium3DTileContentFactory[type](tileset, mockTile, url); - content.request(); - - return content.readyPromise.then(function(content) { - fail('should not resolve'); - }).otherwise(function(error) { - expect(content.state).toEqual(Cesium3DTileContentState.FAILED); - expect(error.statusCode).toEqual(404); + expect(error).toBeDefined(); }); }; @@ -179,7 +159,7 @@ define([ return Cesium3DTilesTester.loadTileset(scene, url).then(function(tileset) { var content = tileset._root.content; return content.readyPromise.then(function(content) { - expect(content.state).toEqual(Cesium3DTileContentState.READY); + expect(content).toBeDefined(); }); }); }; @@ -193,25 +173,6 @@ define([ }); }; - Cesium3DTilesTester.tileDestroysBeforeLoad = function(scene, url) { - var tileset = scene.primitives.add(new Cesium3DTileset({ - url : url - })); - scene.renderForSpecs(); - return tileset.readyPromise.then(function(tileset) { - var content = tileset._root.content; - scene.renderForSpecs(); // Request root - scene.primitives.remove(tileset); - - return content.readyPromise.then(function(content) { - fail('should not resolve'); - }).otherwise(function(error) { - expect(content.state).toEqual(Cesium3DTileContentState.FAILED); - return content; - }); - }); - }; - Cesium3DTilesTester.generateBatchedTileBuffer = function(options) { // Procedurally generate the tile array buffer for testing purposes options = defaultValue(options, defaultValue.EMPTY_OBJECT); diff --git a/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/lr.b3dm b/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/lr.b3dm deleted file mode 100644 index f052e259f078..000000000000 Binary files a/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/lr.b3dm and /dev/null differ diff --git a/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/tileset.json b/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/tileset.json deleted file mode 100644 index d02001feed73..000000000000 --- a/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/tileset.json +++ /dev/null @@ -1,104 +0,0 @@ -{ - "asset": { - "version": "0.0" - }, - "properties": { - "id": { - "minimum": 0, - "maximum": 9 - }, - "Longitude": { - "minimum": -1.3197192952275933, - "maximum": -1.319644104024109 - }, - "Latitude": { - "minimum": 0.698848878034009, - "maximum": 0.6989046192460953 - }, - "Height": { - "minimum": 6.191855065524578, - "maximum": 13.992324123159051 - } - }, - "geometricError": 70, - "root": { - "boundingVolume": { - "region": [ - -1.3197209591796106, - 0.6988424218, - -1.3196390408203893, - 0.6989055782, - 0, - 20 - ] - }, - "geometricError": 70, - "refine": "add", - "children": [ - { - "boundingVolume": { - "region": [ - -1.3197209591796106, - 0.6988424218, - -1.31968, - 0.698874, - 0, - 20 - ] - }, - "geometricError": 0, - "content": { - "url": "invalid.b3dm" - } - }, - { - "boundingVolume": { - "region": [ - -1.31968, - 0.6988424218, - -1.3196390408203893, - 0.698874, - 0, - 20 - ] - }, - "geometricError": 0, - "content": { - "url": "lr.b3dm" - } - }, - { - "boundingVolume": { - "region": [ - -1.31968, - 0.698874, - -1.3196390408203893, - 0.6989055782, - 0, - 20 - ] - }, - "geometricError": 0, - "content": { - "url": "ur.b3dm" - } - }, - { - "boundingVolume": { - "region": [ - -1.3197209591796106, - 0.698874, - -1.31968, - 0.6989055782, - 0, - 20 - ] - }, - "geometricError": 0, - "content": { - "url": "ul.b3dm" - } - } - ] - } -} diff --git a/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/ul.b3dm b/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/ul.b3dm deleted file mode 100644 index a386047150bb..000000000000 Binary files a/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/ul.b3dm and /dev/null differ diff --git a/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/ur.b3dm b/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/ur.b3dm deleted file mode 100644 index 24a6c3e4abdb..000000000000 Binary files a/Specs/Data/Cesium3DTiles/Tilesets/TilesetInvalid/ur.b3dm and /dev/null differ diff --git a/Specs/Scene/Batched3DModel3DTileContentSpec.js b/Specs/Scene/Batched3DModel3DTileContentSpec.js index f7235fc84ae6..39c680b2b758 100644 --- a/Specs/Scene/Batched3DModel3DTileContentSpec.js +++ b/Specs/Scene/Batched3DModel3DTileContentSpec.js @@ -62,18 +62,11 @@ defineSuite([ scene.primitives.removeAll(); }); - it('throws with invalid magic', function() { - var arrayBuffer = Cesium3DTilesTester.generateBatchedTileBuffer({ - magic : [120, 120, 120, 120] - }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'b3dm'); - }); - it('throws with invalid version', function() { var arrayBuffer = Cesium3DTilesTester.generateBatchedTileBuffer({ - version: 2 + version : 2 }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'b3dm'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'b3dm'); }); it('recognizes the legacy 20-byte header', function() { @@ -112,17 +105,13 @@ defineSuite([ it('throws with empty gltf', function() { // Expect to throw DeveloperError in Model due to invalid gltf magic var arrayBuffer = Cesium3DTilesTester.generateBatchedTileBuffer(); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'b3dm'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'b3dm'); }); it('resolves readyPromise', function() { return Cesium3DTilesTester.resolvesReadyPromise(scene, withoutBatchTableUrl); }); - it('rejects readyPromise on failed request', function() { - return Cesium3DTilesTester.rejectsReadyPromiseOnFailedRequest('b3dm'); - }); - it('renders with batch table', function() { return Cesium3DTilesTester.loadTileset(scene, withBatchTableUrl).then(function(tileset) { Cesium3DTilesTester.expectRenderTileset(scene, tileset); @@ -276,8 +265,4 @@ defineSuite([ return Cesium3DTilesTester.tileDestroys(scene, withoutBatchTableUrl); }); - it('destroys before loading finishes', function() { - return Cesium3DTilesTester.tileDestroysBeforeLoad(scene, withoutBatchTableUrl); - }); - }, 'WebGL'); diff --git a/Specs/Scene/Cesium3DTileProviderSpec.js b/Specs/Scene/Cesium3DTileContentSpec.js similarity index 58% rename from Specs/Scene/Cesium3DTileProviderSpec.js rename to Specs/Scene/Cesium3DTileContentSpec.js index 234cf1c9dd31..fddc7249aa7a 100644 --- a/Specs/Scene/Cesium3DTileProviderSpec.js +++ b/Specs/Scene/Cesium3DTileContentSpec.js @@ -10,9 +10,27 @@ defineSuite([ expect(function() { return content.featuresLength; }).toThrowDeveloperError(); + expect(function() { + return content.pointsLength; + }).toThrowDeveloperError(); + expect(function() { + return content.trianglesLength; + }).toThrowDeveloperError(); + expect(function() { + return content.vertexMemorySizeInBytes; + }).toThrowDeveloperError(); + expect(function() { + return content.textureMemorySizeInBytes; + }).toThrowDeveloperError(); + expect(function() { + return content.batchTableMemorySizeInBytes; + }).toThrowDeveloperError(); expect(function() { return content.innerContents; }).toThrowDeveloperError(); + expect(function() { + return content.readyPromise; + }).toThrowDeveloperError(); expect(function() { return content.hasProperty(0, 'height'); }).toThrowDeveloperError(); @@ -20,10 +38,10 @@ defineSuite([ return content.getFeature(0); }).toThrowDeveloperError(); expect(function() { - content.request(); + content.applyDebugSettings(); }).toThrowDeveloperError(); expect(function() { - content.initialize(); + content.applyStyleWithShader(); }).toThrowDeveloperError(); expect(function() { content.update(); diff --git a/Specs/Scene/Cesium3DTileSpec.js b/Specs/Scene/Cesium3DTileSpec.js index 806db5c39227..a594c06604a6 100644 --- a/Specs/Scene/Cesium3DTileSpec.js +++ b/Specs/Scene/Cesium3DTileSpec.js @@ -5,6 +5,7 @@ defineSuite([ 'Core/clone', 'Core/defined', 'Core/HeadingPitchRoll', + 'Core/loadWithXhr', 'Core/Math', 'Core/Matrix3', 'Core/Matrix4', @@ -20,6 +21,7 @@ defineSuite([ clone, defined, HeadingPitchRoll, + loadWithXhr, CesiumMath, Matrix3, Matrix4, @@ -115,18 +117,6 @@ defineSuite([ } }; - var tileWithInvalidExtension = { - geometricError : 1, - refine : 'replace', - children : [], - content : { - url : '0/0.xxxx' - }, - boundingVolume: { - box : [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] - } - }; - var mockTileset = { debugShowBoundingVolume : true, debugShowViewerRequestVolume : true, @@ -143,12 +133,6 @@ defineSuite([ return Matrix4.pack(transformMatrix, new Array(16)); } - it('throws if content has an unsupported extension', function() { - expect(function() { - return new Cesium3DTile(mockTileset, '/some_url', tileWithInvalidExtension, undefined); - }).toThrowDeveloperError(); - }); - it('destroys', function() { var tile = new Cesium3DTile(mockTileset, '/some_url', tileWithBoundingSphere, undefined); expect(tile.isDestroyed()).toEqual(false); diff --git a/Specs/Scene/Cesium3DTilesetSpec.js b/Specs/Scene/Cesium3DTilesetSpec.js index e29a22aaad73..c544b6700709 100644 --- a/Specs/Scene/Cesium3DTilesetSpec.js +++ b/Specs/Scene/Cesium3DTilesetSpec.js @@ -62,9 +62,6 @@ defineSuite([ // Parent tile with content and four child tiles with content var tilesetUrl = './Data/Cesium3DTiles/Tilesets/Tileset/'; - // One child points to an invalid url - var tilesetInvalidUrl = './Data/Cesium3DTiles/Tilesets/TilesetInvalid/'; - // Parent tile with no content and four child tiles with content var tilesetEmptyRootUrl = './Data/Cesium3DTiles/Tilesets/TilesetEmptyRoot/'; @@ -104,7 +101,7 @@ defineSuite([ // 1 tile with opaque and translucent features var translucentOpaqueMixUrl = './Data/Cesium3DTiles/Batched/BatchedTranslucentOpaqueMix/'; - // Root tile is transformed from local space to wgs84, child tile is rotated, scales, and translated locally + // Root tile is transformed from local space to wgs84, child tile is rotated, scaled, and translated locally var tilesetWithTransformsUrl = './Data/Cesium3DTiles/Tilesets/TilesetWithTransforms'; // Root tile with 4 b3dm children and 1 pnts child with a viewer request volume @@ -184,7 +181,6 @@ defineSuite([ var tileset = scene.primitives.add(new Cesium3DTileset({ url : 'invalid.json' })); - scene.renderForSpecs(); return tileset.readyPromise.then(function() { fail('should not resolve'); }).otherwise(function(error) { @@ -194,8 +190,8 @@ defineSuite([ it('rejects readyPromise with invalid tileset version', function() { var tilesetJson = { - "asset" : { - "version" : "2.0" + asset : { + version : 2.0 } }; @@ -271,7 +267,6 @@ defineSuite([ expect(tileset._geometricError).toEqual(240.0); expect(tileset._root).toBeDefined(); - expect(tileset._root.descendantsWithContent).toBeUndefined(); expect(tileset.url).toEqual(tilesetUrl); }); }); @@ -324,36 +319,51 @@ defineSuite([ }).toThrowDeveloperError(); }); + it('requests tile with invalid magic', function() { + var invalidMagicBuffer = Cesium3DTilesTester.generateBatchedTileBuffer({ + magic : [120, 120, 120, 120] + }); + var tileset = scene.primitives.add(new Cesium3DTileset({ + url : tilesetUrl + })); + return tileset.readyPromise.then(function(tileset) { + // Start spying after the tileset json has been loaded + spyOn(loadWithXhr, 'load').and.callFake(function(url, responseType, method, data, headers, deferred, overrideMimeType) { + deferred.resolve(invalidMagicBuffer); + }); + scene.renderForSpecs(); // Request root + var root = tileset._root; + return root.contentReadyPromise.then(function() { + fail('should not resolve'); + }).otherwise(function(error) { + expect(error.message).toBe('Invalid tile content.'); + expect(root._contentState).toEqual(Cesium3DTileContentState.FAILED); + }); + }); + }); + it('handles failed tile requests', function() { viewRootOnly(); - return Cesium3DTilesTester.loadTileset(scene, tilesetInvalidUrl).then(function(tileset) { - viewAllTiles(); - scene.renderForSpecs(); - var stats = tileset._statistics; - expect(stats.numberOfPendingRequests).toEqual(4); - expect(stats.numberProcessing).toEqual(0); - - return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - expect(stats.numberOfPendingRequests).toEqual(0); - expect(stats.numberProcessing).toEqual(0); - - // Check that one tile has failed - var children = tileset._root.children; - var length = children.length; - var failedTiles = 0; - for (var i = 0; i < length; ++i) { - if (children[i].content.state === Cesium3DTileContentState.FAILED) { - ++failedTiles; - } - } - expect(failedTiles).toEqual(1); + var tileset = scene.primitives.add(new Cesium3DTileset({ + url : tilesetUrl + })); + return tileset.readyPromise.then(function(tileset) { + // Start spying after the tileset json has been loaded + spyOn(loadWithXhr, 'load').and.callFake(function(url, responseType, method, data, headers, deferred, overrideMimeType) { + deferred.reject(); + }); + scene.renderForSpecs(); // Request root + var root = tileset._root; + return root.contentReadyPromise.then(function() { + fail('should not resolve'); + }).otherwise(function(error) { + expect(root._contentState).toEqual(Cesium3DTileContentState.FAILED); }); }); }); it('renders tileset', function() { return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; expect(stats.visited).toEqual(5); expect(stats.numberOfCommands).toEqual(5); @@ -383,7 +393,6 @@ defineSuite([ it('renders tileset with empty root tile', function() { return Cesium3DTilesTester.loadTileset(scene, tilesetEmptyRootUrl).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; expect(stats.visited).toEqual(5); expect(stats.numberOfCommands).toEqual(4); // Empty tile doesn't issue a command @@ -419,7 +428,6 @@ defineSuite([ // Wait for all tiles to load and check that they are all visited and rendered return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.visited).toEqual(5); expect(stats.numberOfCommands).toEqual(5); expect(stats.numberOfPendingRequests).toEqual(0); @@ -438,7 +446,6 @@ defineSuite([ expect(stats.numberOfTrianglesSelected).toEqual(0); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.numberOfFeaturesSelected).toEqual(features); expect(stats.numberOfFeaturesLoaded).toEqual(features); expect(stats.numberOfPointsSelected).toEqual(points); @@ -455,7 +462,6 @@ defineSuite([ expect(stats.numberOfTrianglesSelected).toEqual(0); tileset.trimLoadedTiles(); - scene.renderForSpecs(); expect(stats.numberOfFeaturesSelected).toEqual(0); @@ -623,7 +629,6 @@ defineSuite([ it('does not process tileset when screen space error is not met', function() { return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; expect(stats.visited).toEqual(5); expect(stats.numberOfCommands).toEqual(5); @@ -638,7 +643,6 @@ defineSuite([ it('does not select tiles when outside of view frustum', function() { return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; expect(stats.visited).toEqual(5); expect(stats.numberOfCommands).toEqual(5); @@ -658,7 +662,6 @@ defineSuite([ // Root tile has a content box that is half the extents of its box // Expect to cull root tile and three child tiles return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; expect(stats.visited).toEqual(5); expect(stats.numberOfCommands).toEqual(5); @@ -718,7 +721,6 @@ defineSuite([ function testDynamicScreenSpaceError(url, distance) { return Cesium3DTilesTester.loadTileset(scene, url).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; // Horizon view, only root is visible @@ -773,11 +775,9 @@ defineSuite([ }); it('additive refinement - selects root when sse is met', function() { + viewRootOnly(); return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { // Meets screen space error, only root tile is rendered - viewRootOnly(); - scene.renderForSpecs(); - var stats = tileset._statistics; expect(stats.visited).toEqual(1); expect(stats.numberOfCommands).toEqual(1); @@ -787,9 +787,6 @@ defineSuite([ it('additive refinement - selects all tiles when sse is not met', function() { return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { // Does not meet screen space error, all tiles are visible - viewAllTiles(); - scene.renderForSpecs(); - var stats = tileset._statistics; expect(stats.visited).toEqual(5); expect(stats.numberOfCommands).toEqual(5); @@ -798,7 +795,6 @@ defineSuite([ it('additive refinement - use parent\'s geometric error on child\'s box for early refinement', function() { return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; expect(stats.visited).toEqual(5); expect(stats.numberOfCommands).toEqual(5); @@ -830,11 +826,11 @@ defineSuite([ }); it('replacement refinement - selects root when sse is met', function() { + viewRootOnly(); return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { tileset._root.refine = Cesium3DTileRefine.REPLACE; // Meets screen space error, only root tile is rendered - viewRootOnly(); scene.renderForSpecs(); var stats = tileset._statistics; @@ -848,7 +844,6 @@ defineSuite([ tileset._root.refine = Cesium3DTileRefine.REPLACE; // Does not meet screen space error, child tiles replace root tile - viewAllTiles(); scene.renderForSpecs(); var stats = tileset._statistics; @@ -918,15 +913,13 @@ defineSuite([ var stats = tileset._statistics; var root = tileset._root; - return when.join(root.children[0].readyPromise, root.children[1].readyPromise).then(function() { + return when.join(root.children[0].contentReadyPromise, root.children[1].contentReadyPromise).then(function() { // Even though root's children are loaded, the grandchildren need to be loaded before it becomes refinable - scene.renderForSpecs(); expect(numberOfChildrenWithoutContent(root)).toEqual(0); // Children are loaded expect(stats.numberOfCommands).toEqual(3); // Stencil, root backfaces, root expect(stats.numberOfPendingRequests).toEqual(4); // Loading grandchildren return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.numberOfCommands).toEqual(4); // Render children }); }); @@ -944,18 +937,14 @@ defineSuite([ viewRootOnly(); return Cesium3DTilesTester.loadTileset(scene, tilesetReplacement2Url).then(function(tileset) { - scene.renderForSpecs(); - var stats = tileset._statistics; return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.numberOfCommands).toEqual(1); setZoom(5.0); // Zoom into the last tile, when it is ready the root is refinable scene.renderForSpecs(); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.numberOfCommands).toEqual(2); // Renders two content tiles }); }); @@ -973,21 +962,19 @@ defineSuite([ viewRootOnly(); return Cesium3DTilesTester.loadTileset(scene, tilesetReplacement3Url).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; var root = tileset._root; expect(stats.numberOfCommands).toEqual(1); viewAllTiles(); scene.renderForSpecs(); - return root.children[0].content.readyPromise.then(function() { + return root.children[0].contentReadyPromise.then(function() { // The external tileset json is loaded, but the external tileset isn't. scene.renderForSpecs(); expect(stats.numberOfCommands).toEqual(2); // Stencil + Render root expect(stats.numberOfPendingRequests).toEqual(4); // Loading child content tiles return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(root.selected).toEqual(false); expect(stats.numberOfCommands).toEqual(4); // Render child content tiles }); @@ -1001,7 +988,6 @@ defineSuite([ // R A R A // return Cesium3DTilesTester.loadTileset(scene, tilesetRefinementMix).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; expect(stats.visited).toEqual(7); expect(stats.numberOfCommands).toEqual(6); @@ -1083,8 +1069,6 @@ defineSuite([ scene.renderForSpecs(); // wait for load because geometric error has changed return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function(tileset) { - scene.renderForSpecs(); - expect(childRoot.visibility(scene.frameState, CullingVolume.MASK_INDETERMINATE)).not.toEqual(CullingVolume.MASK_OUTSIDE); expect(childRoot.children[0].visibility(scene.frameState, CullingVolume.MASK_INDETERMINATE)).not.toEqual(CullingVolume.MASK_OUTSIDE); @@ -1111,8 +1095,6 @@ defineSuite([ var root = tileset._root; var childRoot = root.children[0]; - scene.renderForSpecs(); - expect(childRoot.visibility(scene.frameState, CullingVolume.MASK_INDETERMINATE)).not.toEqual(CullingVolume.MASK_OUTSIDE); expect(childRoot.children[0].visibility(scene.frameState, CullingVolume.MASK_INDETERMINATE)).not.toEqual(CullingVolume.MASK_OUTSIDE); @@ -1140,11 +1122,8 @@ defineSuite([ var childRoot = root.children[0]; childRoot.geometricError = 0; - scene.renderForSpecs(); // wait for load because geometric error has changed return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function(tileset) { - scene.renderForSpecs(); - expect(childRoot.visibility(scene.frameState, CullingVolume.MASK_INDETERMINATE)).not.toEqual(CullingVolume.MASK_OUTSIDE); expect(childRoot.children[0].visibility(scene.frameState, CullingVolume.MASK_INDETERMINATE)).not.toEqual(CullingVolume.MASK_OUTSIDE); @@ -1170,7 +1149,6 @@ defineSuite([ // R A R A // return Cesium3DTilesTester.loadTileset(scene, tilesetRefinementMix).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; expect(stats.visited).toEqual(7); expect(stats.numberOfCommands).toEqual(6); @@ -1184,13 +1162,14 @@ defineSuite([ return Cesium3DTilesTester.loadTileset(scene, tilesetOfTilesetsUrl).then(function(tileset) { // Root points to an external tileset.json and has no children until it is requested var root = tileset._root; - expect(root.hasTilesetContent).toEqual(true); expect(root.children.length).toEqual(0); // Set view so that root's content is requested viewRootOnly(); scene.renderForSpecs(); - return root.content.readyPromise.then(function() { + return root.contentReadyPromise.then(function() { + expect(root.hasTilesetContent).toEqual(true); + // Root has one child now, the root of the external tileset expect(root.children.length).toEqual(1); @@ -1200,7 +1179,7 @@ defineSuite([ expect(root.refine).toEqual(subtreeRoot.refine); expect(root.contentBoundingVolume.boundingVolume).toEqual(subtreeRoot.contentBoundingVolume.boundingVolume); - // Check that Subtree root has 4 children + // Check that subtree root has 4 children expect(subtreeRoot.hasTilesetContent).toEqual(false); expect(subtreeRoot.children.length).toEqual(4); }); @@ -1226,7 +1205,7 @@ defineSuite([ viewRootOnly(); scene.renderForSpecs(); - return tileset._root.content.readyPromise; + return tileset._root.contentReadyPromise; }).then(function() { //Make sure tileset2.json was requested with query parameters and version var queryParamsWithVersion = queryParams + '&v=0.0'; @@ -1237,7 +1216,6 @@ defineSuite([ it('renders tileset with external tileset.json', function() { return Cesium3DTilesTester.loadTileset(scene, tilesetOfTilesetsUrl).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; expect(stats.visited).toEqual(7); // Visits two tiles with tileset content, five tiles with b3dm content expect(stats.numberOfCommands).toEqual(5); // Render the five tiles with b3dm content @@ -1411,7 +1389,7 @@ defineSuite([ viewRootOnly(); scene.renderForSpecs(); // Request root expect(tileset._statistics.numberOfPendingRequests).toEqual(1); - return tileset._root.content.contentReadyToProcessPromise.then(function() { + return tileset._root.contentReadyToProcessPromise.then(function() { scene.pickForSpecs(); expect(spy).not.toHaveBeenCalled(); scene.renderForSpecs(); @@ -1455,7 +1433,6 @@ defineSuite([ tileset.loadProgress.addEventListener(spyUpdate); viewRootOnly(); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(spyUpdate.calls.count()).toEqual(3); expect(spyUpdate.calls.allArgs()).toEqual(results); }); @@ -1537,7 +1514,6 @@ defineSuite([ viewNothing(); return Cesium3DTilesTester.loadTileset(scene, tilesetOfTilesetsUrl).then(function(tileset) { var root = tileset._root; - var content = root.content; viewRootOnly(); scene.renderForSpecs(); // Request external tileset.json @@ -1546,7 +1522,7 @@ defineSuite([ expect(stats.numberOfPendingRequests).toEqual(1); scene.primitives.remove(tileset); - return content.readyPromise.then(function(root) { + return root.contentReadyPromise.then(function(root) { fail('should not resolve'); }).otherwise(function(error) { // Expect the root to not have added any children from the external tileset.json @@ -1557,19 +1533,18 @@ defineSuite([ }); it('destroys before tile finishes loading', function() { - viewNothing(); - return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) { + var tileset = scene.primitives.add(new Cesium3DTileset({ + url : tilesetUrl + })); + return tileset.readyPromise.then(function(tileset) { var root = tileset._root; - var content = root.content; - - viewRootOnly(); scene.renderForSpecs(); // Request root scene.primitives.remove(tileset); - return content.readyPromise.then(function(root) { + return root.contentReadyPromise.then(function(content) { fail('should not resolve'); }).otherwise(function(error) { - expect(content.state).toEqual(Cesium3DTileContentState.FAILED); + expect(root._contentState).toBe(Cesium3DTileContentState.FAILED); expect(RequestScheduler.getNumberOfAvailableRequests()).toEqual(RequestScheduler.maximumRequests); }); }); @@ -1982,7 +1957,6 @@ defineSuite([ viewAllTiles(); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.numberOfCommands).toEqual(5); expect(stats.numberContentReady).toEqual(5); // Five loaded tiles }); @@ -2014,7 +1988,6 @@ defineSuite([ viewAllTiles(); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.numberOfCommands).toEqual(5); expect(stats.numberContentReady).toEqual(5); // Five loaded tiles }); @@ -2043,7 +2016,6 @@ defineSuite([ viewAllTiles(); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.numberOfCommands).toEqual(5); expect(stats.numberContentReady).toEqual(5); }); @@ -2075,7 +2047,6 @@ defineSuite([ viewAllTiles(); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.numberOfCommands).toEqual(5); expect(stats.numberContentReady).toEqual(5); @@ -2107,7 +2078,6 @@ defineSuite([ viewAllTiles(); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.numberOfCommands).toEqual(4); expect(stats.numberContentReady).toEqual(4); }); @@ -2144,7 +2114,6 @@ defineSuite([ viewAllTiles(); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function() { - scene.renderForSpecs(); expect(stats.numberOfCommands).toEqual(4); expect(stats.numberContentReady).toEqual(5); }); @@ -2230,7 +2199,6 @@ defineSuite([ var i3dmCommands = scene.context.instancedArrays ? 1 : 25; // When instancing is not supported there is one command per instance var totalCommands = b3dmCommands + i3dmCommands; return Cesium3DTilesTester.loadTileset(scene, tilesetWithTransformsUrl).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; var root = tileset._root; var rootTransform = Matrix4.unpack(root._header.transform); @@ -2289,13 +2257,12 @@ defineSuite([ it('adds stencil clear command first when unresolved', function() { viewRootOnly(); return Cesium3DTilesTester.loadTileset(scene, tilesetReplacement3Url).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; var root = tileset._root; viewAllTiles(); scene.renderForSpecs(); - return root.children[0].content.readyPromise.then(function() { + return root.children[0].contentReadyPromise.then(function() { scene.renderForSpecs(); // 1 for root tiles, 1 for stencil clear expect(stats.numberOfCommands).toEqual(2); @@ -2313,13 +2280,12 @@ defineSuite([ scene.camera.moveDown(200.0); return Cesium3DTilesTester.loadTileset(scene, tilesetReplacement3Url).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; var root = tileset._root; viewAllTiles(); scene.renderForSpecs(); - return root.children[0].content.readyPromise.then(function() { + return root.children[0].contentReadyPromise.then(function() { scene.renderForSpecs(); // 2 for root tile, 1 for child, 1 for stencil clear expect(stats.numberOfCommands).toEqual(4); @@ -2342,13 +2308,12 @@ defineSuite([ it('does not create duplicate backface commands if no selected descendants', function() { viewRootOnly(); return Cesium3DTilesTester.loadTileset(scene, tilesetReplacement3Url).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; var root = tileset._root; viewAllTiles(); scene.renderForSpecs(); - return root.children[0].content.readyPromise.then(function() { + return root.children[0].contentReadyPromise.then(function() { scene.renderForSpecs(); // 1 for root tile, 1 for stencil clear expect(stats.numberOfCommands).toEqual(2); @@ -2374,7 +2339,6 @@ defineSuite([ it('does not add stencil clear command or backface commands when fully resolved', function() { viewAllTiles(); return Cesium3DTilesTester.loadTileset(scene, tilesetReplacement3Url).then(function(tileset) { - scene.renderForSpecs(); var stats = tileset._statistics; expect(stats.numberOfCommands).toEqual(tileset._selectedTiles.length); @@ -2395,12 +2359,10 @@ defineSuite([ return Cesium3DTilesTester.loadTileset(scene, tilesetReplacement3Url, {loadSiblings : false}).then(function(tileset) { var stats = tileset._statistics; - scene.renderForSpecs(); expect(stats.numberContentReady).toBe(2); tileset.loadSiblings = true; scene.renderForSpecs(); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function(tileset) { - scene.renderForSpecs(); expect(stats.numberContentReady).toBe(5); }); }); @@ -2418,18 +2380,14 @@ defineSuite([ skipLevels : 0 })); return Cesium3DTilesTester.waitForReady(scene, tileset).then(function(tileset) { - scene.renderForSpecs(); - return tileset._root.content.readyPromise.then(function() { + return tileset._root.contentReadyPromise.then(function() { tileset._root.children[0].refine = Cesium3DTileRefine.REPLACE; return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function(tileset) { var stats = tileset._statistics; - scene.renderForSpecs(); expect(stats.numberContentReady).toBe(1); tileset.immediatelyLoadDesiredLOD = false; - scene.renderForSpecs(); return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function(tileset) { - scene.renderForSpecs(); expect(stats.numberContentReady).toBe(2); }); }); @@ -2447,8 +2405,7 @@ defineSuite([ })); return Cesium3DTilesTester.waitForReady(scene, tileset).then(function(tileset) { - scene.renderForSpecs(); - return tileset._root.content.readyPromise.then(function() { + return tileset._root.contentReadyPromise.then(function() { tileset._root.children[0].refine = Cesium3DTileRefine.REPLACE; return Cesium3DTilesTester.waitForTilesLoaded(scene, tileset).then(function(tileset) { var stats = tileset._statistics; diff --git a/Specs/Scene/Composite3DTileContentSpec.js b/Specs/Scene/Composite3DTileContentSpec.js index 91a22662c17c..6c0111372c8a 100644 --- a/Specs/Scene/Composite3DTileContentSpec.js +++ b/Specs/Scene/Composite3DTileContentSpec.js @@ -81,18 +81,11 @@ defineSuite([ }); } - it('throws with invalid magic', function() { - var arrayBuffer = Cesium3DTilesTester.generateCompositeTileBuffer({ - magic : [120, 120, 120, 120] - }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'cmpt'); - }); - it('throws with invalid version', function() { var arrayBuffer = Cesium3DTilesTester.generateCompositeTileBuffer({ version : 2 }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'cmpt'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'cmpt'); }); it('throws with invalid inner tile content type', function() { @@ -101,7 +94,7 @@ defineSuite([ magic : [120, 120, 120, 120] })] }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'cmpt'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'cmpt'); }); it('resolves readyPromise', function() { @@ -121,10 +114,6 @@ defineSuite([ return Cesium3DTilesTester.rejectsReadyPromiseOnError(scene, arrayBuffer, 'cmpt'); }); - it('rejects readyPromise on failed request', function() { - return Cesium3DTilesTester.rejectsReadyPromiseOnFailedRequest('cmpt'); - }); - it('renders composite', function() { return Cesium3DTilesTester.loadTileset(scene, compositeUrl).then(expectRenderComposite); }); @@ -137,8 +126,4 @@ defineSuite([ return Cesium3DTilesTester.tileDestroys(scene, compositeUrl); }); - it('destroys before loading finishes', function() { - return Cesium3DTilesTester.tileDestroysBeforeLoad(scene, compositeUrl); - }); - }, 'WebGL'); diff --git a/Specs/Scene/Empty3DTileContentSpec.js b/Specs/Scene/Empty3DTileContentSpec.js index f47af925719a..669a3fafc586 100644 --- a/Specs/Scene/Empty3DTileContentSpec.js +++ b/Specs/Scene/Empty3DTileContentSpec.js @@ -1,21 +1,10 @@ /*global defineSuite*/ defineSuite([ - 'Scene/Empty3DTileContent', - 'Scene/Cesium3DTileContentState' + 'Scene/Empty3DTileContent' ], function( - Empty3DTileContent, - Cesium3DTileContentState) { + Empty3DTileContent) { 'use strict'; - it('resolves readyPromise', function() { - var content = new Empty3DTileContent(); - content.request(); - content.update(); - return content.readyPromise.then(function(content) { - expect(content.state).toEqual(Cesium3DTileContentState.READY); - }); - }); - it('destroys', function() { var content = new Empty3DTileContent(); expect(content.isDestroyed()).toEqual(false); diff --git a/Specs/Scene/Instanced3DModel3DTileContentSpec.js b/Specs/Scene/Instanced3DModel3DTileContentSpec.js index 20241b8172d2..f5f6fd95d99e 100644 --- a/Specs/Scene/Instanced3DModel3DTileContentSpec.js +++ b/Specs/Scene/Instanced3DModel3DTileContentSpec.js @@ -67,31 +67,24 @@ defineSuite([ scene.primitives.removeAll(); }); - it('throws with invalid magic', function() { - var arrayBuffer = Cesium3DTilesTester.generateInstancedTileBuffer({ - magic : [120, 120, 120, 120] - }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'i3dm'); - }); - it('throws with invalid format', function() { var arrayBuffer = Cesium3DTilesTester.generateInstancedTileBuffer({ gltfFormat : 2 }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'i3dm'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'i3dm'); }); it('throws with invalid version', function() { var arrayBuffer = Cesium3DTilesTester.generateInstancedTileBuffer({ version : 2 }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'i3dm'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'i3dm'); }); it('throws with empty gltf', function() { // Expect to throw DeveloperError in Model due to invalid gltf magic var arrayBuffer = Cesium3DTilesTester.generateInstancedTileBuffer(); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'i3dm'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'i3dm'); }); it('resolves readyPromise', function() { @@ -109,38 +102,6 @@ defineSuite([ return Cesium3DTilesTester.rejectsReadyPromiseOnError(scene, arrayBuffer, 'i3dm'); }); - it('rejects readyPromise on failed request', function() { - return Cesium3DTilesTester.rejectsReadyPromiseOnFailedRequest('i3dm'); - }); - - var mockTile = { - contentBoundingVolume : new TileBoundingSphere(), - _header : { - content : { - boundingVolume : { - sphere : [0.0, 0.0, 0.0, 1.0] - } - } - } - }; - - it('loads with no instances, but does not become ready', function() { - var arrayBuffer = Cesium3DTilesTester.generateInstancedTileBuffer({ - featuresLength : 0, - gltfUri : '../Data/Models/Box/CesiumBoxTest.gltf' - }); - - var tileset = {}; - var url = ''; - var instancedTile = new Instanced3DModel3DTileContent(tileset, mockTile, url); - instancedTile.initialize(arrayBuffer); - // Expect the tile to never reach the ready state due to returning early in ModelInstanceCollection - for (var i = 0; i < 10; ++i) { - instancedTile.update(tileset, scene.frameState); - expect(instancedTile.state).toEqual(Cesium3DTileContentState.PROCESSING); - } - }); - it('renders with external gltf', function() { return Cesium3DTilesTester.loadTileset(scene, gltfExternalUrl).then(function(tileset) { Cesium3DTilesTester.expectRenderTileset(scene, tileset); @@ -349,8 +310,4 @@ defineSuite([ return Cesium3DTilesTester.tileDestroys(scene, withoutBatchTableUrl); }); - it('destroys before loading finishes', function() { - return Cesium3DTilesTester.tileDestroysBeforeLoad(scene, withoutBatchTableUrl); - }); - }, 'WebGL'); diff --git a/Specs/Scene/PointCloud3DTileContentSpec.js b/Specs/Scene/PointCloud3DTileContentSpec.js index 8cbaf3b946de..dc66d8a9ee53 100644 --- a/Specs/Scene/PointCloud3DTileContentSpec.js +++ b/Specs/Scene/PointCloud3DTileContentSpec.js @@ -81,25 +81,18 @@ defineSuite([ scene.primitives.removeAll(); }); - it('throws with invalid magic', function() { - var arrayBuffer = Cesium3DTilesTester.generatePointCloudTileBuffer({ - magic : [120, 120, 120, 120] - }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); - }); - it('throws with invalid version', function() { var arrayBuffer = Cesium3DTilesTester.generatePointCloudTileBuffer({ version: 2 }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); }); it('throws if featureTableJsonByteLength is 0', function() { var arrayBuffer = Cesium3DTilesTester.generatePointCloudTileBuffer({ featureTableJsonByteLength : 0 }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); }); it('throws if the feature table does not contain POINTS_LENGTH', function() { @@ -110,7 +103,7 @@ defineSuite([ } } }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); }); it('throws if the feature table does not contain POSITION or POSITION_QUANTIZED', function() { @@ -119,7 +112,7 @@ defineSuite([ POINTS_LENGTH : 1 } }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); }); it('throws if the positions are quantized and the feature table does not contain QUANTIZED_VOLUME_SCALE', function() { @@ -132,7 +125,7 @@ defineSuite([ QUANTIZED_VOLUME_OFFSET : [0.0, 0.0, 0.0] } }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); }); it('throws if the positions are quantized and the feature table does not contain QUANTIZED_VOLUME_OFFSET', function() { @@ -145,7 +138,7 @@ defineSuite([ QUANTIZED_VOLUME_SCALE : [1.0, 1.0, 1.0] } }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); }); it('throws if the BATCH_ID semantic is defined but BATCHES_LENGTH is not', function() { @@ -156,7 +149,7 @@ defineSuite([ BATCH_ID : [0, 1] } }); - return Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); + Cesium3DTilesTester.loadTileExpectError(scene, arrayBuffer, 'pnts'); }); it('BATCH_ID semantic uses componentType of UNSIGNED_SHORT by default', function() { @@ -176,10 +169,6 @@ defineSuite([ return Cesium3DTilesTester.resolvesReadyPromise(scene, pointCloudRGBUrl); }); - it('rejects readyPromise on failed request', function() { - return Cesium3DTilesTester.rejectsReadyPromiseOnFailedRequest('pnts'); - }); - it('renders point cloud with rgb colors', function() { return Cesium3DTilesTester.loadTileset(scene, pointCloudRGBUrl).then(function(tileset) { Cesium3DTilesTester.expectRender(scene, tileset); @@ -701,8 +690,4 @@ defineSuite([ return Cesium3DTilesTester.tileDestroys(scene, pointCloudRGBUrl); }); - it('destroys before loading finishes', function() { - return Cesium3DTilesTester.tileDestroysBeforeLoad(scene, pointCloudRGBUrl); - }); - }, 'WebGL'); diff --git a/Specs/Scene/Tileset3DTileContentSpec.js b/Specs/Scene/Tileset3DTileContentSpec.js index c7d0bf486374..0e563e41ff3a 100644 --- a/Specs/Scene/Tileset3DTileContentSpec.js +++ b/Specs/Scene/Tileset3DTileContentSpec.js @@ -41,16 +41,8 @@ defineSuite([ return Cesium3DTilesTester.resolvesReadyPromise(scene, tilesetOfTilesetsUrl); }); - it('rejects readyPromise on failed request', function() { - return Cesium3DTilesTester.rejectsReadyPromiseOnFailedRequest('json'); - }); - it('destroys', function() { return Cesium3DTilesTester.tileDestroys(scene, tilesetOfTilesetsUrl); }); - it('destroys before loading finishes', function() { - return Cesium3DTilesTester.tileDestroysBeforeLoad(scene, tilesetOfTilesetsUrl); - }); - }, 'WebGL'); diff --git a/Specs/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspectorSpec.js b/Specs/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspectorSpec.js index 515f06791f72..89fb13dcb429 100644 --- a/Specs/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspectorSpec.js +++ b/Specs/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspectorSpec.js @@ -1,16 +1,16 @@ /*global defineSuite*/ defineSuite([ 'Widgets/Cesium3DTilesInspector/Cesium3DTilesInspector', - 'Scene/Cesium3DTileset', - 'Specs/createScene', 'Core/Ellipsoid', - 'Scene/Globe' + 'Scene/Cesium3DTileset', + 'Scene/Globe', + 'Specs/createScene' ], function( Cesium3DTilesInspector, - Cesium3DTileset, - createScene, Ellipsoid, - Globe) { + Cesium3DTileset, + Globe, + createScene) { 'use strict'; // Parent tile with content and four child tiles with content