From de6ba128468d2ec6ac6acc36fd9ec992a83cf2b5 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Fri, 9 Jun 2017 18:07:00 -0400 Subject: [PATCH 1/7] Cleanup --- .../3D Tiles Batch Table Hierarchy.html | 2 +- Source/Core/ManagedArray.js | 2 +- Source/Scene/AttributeType.js | 74 +++ Source/Scene/Batched3DModel3DTileContent.js | 61 ++- Source/Scene/Cesium3DTile.js | 216 ++++---- Source/Scene/Cesium3DTileBatchTable.js | 111 ++-- Source/Scene/Cesium3DTileContentFactory.js | 3 +- Source/Scene/Cesium3DTileFeature.js | 20 +- Source/Scene/Cesium3DTileStyle.js | 7 + Source/Scene/Cesium3DTileset.js | 48 +- Source/Scene/Cesium3DTilesetStatistics.js | 12 +- Source/Scene/Cesium3DTilesetTraversal.js | 24 +- Source/Scene/Composite3DTileContent.js | 49 +- Source/Scene/ConditionsExpression.js | 5 +- Source/Scene/Empty3DTileContent.js | 39 +- Source/Scene/Expression.js | 473 ++++++------------ Source/Scene/Instanced3DModel3DTileContent.js | 93 ++-- Source/Scene/Model.js | 10 +- Source/Scene/ModelAnimationCache.js | 14 +- Source/Scene/ModelInstanceCollection.js | 28 +- Source/Scene/PointCloud3DTileContent.js | 96 ++-- Source/Scene/TileBoundingSphere.js | 4 - Source/Scene/TileOrientedBoundingBox.js | 15 +- Source/Scene/Tileset3DTileContent.js | 45 +- .../Cesium3DTilesInspector.js | 148 +++--- .../Cesium3DTilesInspectorViewModel.js | 6 +- Specs/Cesium3DTilesTester.js | 4 +- Specs/Core/ManagedArraySpec.js | 32 +- Specs/Scene/Cesium3DTileBatchTableSpec.js | 4 +- Specs/Scene/Cesium3DTileSpec.js | 24 + Specs/Scene/Cesium3DTilesetSpec.js | 98 ++-- Specs/Scene/ExpressionSpec.js | 414 +++++++-------- Specs/Scene/ModelInstanceCollectionSpec.js | 15 + Specs/Scene/ModelSpec.js | 17 + Specs/Scene/PointCloud3DTileContentSpec.js | 6 +- 35 files changed, 1120 insertions(+), 1099 deletions(-) create mode 100644 Source/Scene/AttributeType.js diff --git a/Apps/Sandcastle/gallery/3D Tiles Batch Table Hierarchy.html b/Apps/Sandcastle/gallery/3D Tiles Batch Table Hierarchy.html index 8fbc87da0402..fa158754e4af 100644 --- a/Apps/Sandcastle/gallery/3D Tiles Batch Table Hierarchy.html +++ b/Apps/Sandcastle/gallery/3D Tiles Batch Table Hierarchy.html @@ -148,7 +148,7 @@ ["${suffix} === 'knob'", "color('yellow')"], ["${suffix} === ''", "color('lime')"], ["${suffix} === null", "color('gray')"], - ["true", "color('blue'"] + ["true", "color('blue')"] ] } }); diff --git a/Source/Core/ManagedArray.js b/Source/Core/ManagedArray.js index 4ddaba516348..ec172bec83f1 100644 --- a/Source/Core/ManagedArray.js +++ b/Source/Core/ManagedArray.js @@ -49,7 +49,7 @@ define([ * @type Array * @readonly */ - internalArray : { + values : { get : function() { return this._array; } diff --git a/Source/Scene/AttributeType.js b/Source/Scene/AttributeType.js new file mode 100644 index 000000000000..fb380f843b26 --- /dev/null +++ b/Source/Scene/AttributeType.js @@ -0,0 +1,74 @@ +/*global define*/ +define([ + '../Core/freezeObject' + ], function( + freezeObject) { + 'use strict'; + + /** + * An enum describing the attribute type for glTF and 3D Tiles. + * + * @exports AttributeType + * + * @private + */ + var AttributeType = { + /** + * The attribute is a single component. + * + * @type {String} + * @constant + */ + SCALAR : 'SCALAR', + + /** + * The attribute is a two-component vector. + * + * @type {String} + * @constant + */ + VEC2 : 'VEC2', + + /** + * The attribute is a three-component vector. + * + * @type {String} + * @constant + */ + VEC3 : 'VEC3', + + /** + * The attribute is a four-component vector. + * + * @type {String} + * @constant + */ + VEC4 : 'VEC4', + + /** + * The attribute is a 2x2 matrix. + * + * @type {String} + * @constant + */ + MAT2 : 'MAT2', + + /** + * The attribute is a 3x3 matrix. + * + * @type {String} + * @constant + */ + MAT3 : 'MAT3', + + /** + * The attribute is a 4x4 matrix. + * + * @type {String} + * @constant + */ + MAT4 : 'MAT4' + }; + + return freezeObject(AttributeType); +}); diff --git a/Source/Scene/Batched3DModel3DTileContent.js b/Source/Scene/Batched3DModel3DTileContent.js index bf48b8a2485e..89242d471486 100644 --- a/Source/Scene/Batched3DModel3DTileContent.js +++ b/Source/Scene/Batched3DModel3DTileContent.js @@ -7,10 +7,12 @@ define([ '../Core/deprecationWarning', '../Core/destroyObject', '../Core/DeveloperError', + '../Core/FeatureDetection', '../Core/getAbsoluteUri', '../Core/getBaseUri', '../Core/getStringFromTypedArray', '../Core/RequestType', + '../Core/RuntimeError', './Cesium3DTileBatchTable', './Cesium3DTileFeature', './Cesium3DTileFeatureTable', @@ -24,10 +26,12 @@ define([ deprecationWarning, destroyObject, DeveloperError, + FeatureDetection, getAbsoluteUri, getBaseUri, getStringFromTypedArray, RequestType, + RuntimeError, Cesium3DTileBatchTable, Cesium3DTileFeature, Cesium3DTileFeatureTable, @@ -35,10 +39,19 @@ define([ Model) { 'use strict'; + // Bail out if the browser doesn't support typed arrays, to prevent the setup function + // from failing, since we won't be able to create a WebGL context anyway. + if (!FeatureDetection.supportsTypedArrays()) { + return {}; + } + /** * Represents the contents of a * {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/TileFormats/Batched3DModel/README.md|Batched 3D Model} * tile in a {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/README.md|3D Tiles} tileset. + *

+ * Implements the {@link Cesium3DTileContent} interface. + *

* * @alias Batched3DModel3DTileContent * @constructor @@ -54,7 +67,7 @@ define([ this._features = undefined; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featurePropertiesDirty */ this.featurePropertiesDirty = false; @@ -66,7 +79,7 @@ define([ defineProperties(Batched3DModel3DTileContent.prototype, { /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featuresLength */ featuresLength : { get : function() { @@ -75,7 +88,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#pointsLength */ pointsLength : { get : function() { @@ -84,7 +97,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#trianglesLength */ trianglesLength : { get : function() { @@ -93,7 +106,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#geometryByteLength */ geometryByteLength : { get : function() { @@ -102,7 +115,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#texturesByteLength */ texturesByteLength : { get : function() { @@ -111,7 +124,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#batchTableByteLength */ batchTableByteLength : { get : function() { @@ -120,7 +133,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#innerContents */ innerContents : { get : function() { @@ -129,7 +142,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#readyPromise */ readyPromise : { get : function() { @@ -138,7 +151,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tileset */ tileset : { get : function() { @@ -147,7 +160,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tile */ tile : { get : function() { @@ -156,7 +169,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#url */ url: { get: function() { @@ -165,7 +178,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#batchTable */ batchTable : { get : function() { @@ -229,12 +242,10 @@ define([ var view = new DataView(arrayBuffer); byteOffset += sizeOfUint32; // Skip magic - //>>includeStart('debug', pragmas.debug); var version = view.getUint32(byteOffset, true); if (version !== 1) { - throw new DeveloperError('Only Batched 3D Model version 1 is supported. Version ' + version + ' is not.'); + throw new RuntimeError('Only Batched 3D Model version 1 is supported. Version ' + version + ' is not.'); } - //>>includeEnd('debug'); byteOffset += sizeOfUint32; var byteLength = view.getUint32(byteOffset, true); @@ -324,11 +335,9 @@ define([ content._batchTable = batchTable; var gltfByteLength = byteStart + byteLength - byteOffset; - //>>includeStart('debug', pragmas.debug); if (gltfByteLength === 0) { - throw new DeveloperError('glTF byte length is zero, i3dm must have a glTF to instance.'); + throw new RuntimeError('glTF byte length is zero, i3dm must have a glTF to instance.'); } - //>>includeEnd('debug'); var gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength); var pickObject = { @@ -373,14 +382,14 @@ define([ } /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#hasProperty */ Batched3DModel3DTileContent.prototype.hasProperty = function(batchId, name) { return this._batchTable.hasProperty(batchId, name); }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#getFeature */ Batched3DModel3DTileContent.prototype.getFeature = function(batchId) { var featuresLength = this.featuresLength; @@ -395,7 +404,7 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyDebugSettings */ Batched3DModel3DTileContent.prototype.applyDebugSettings = function(enabled, color) { color = enabled ? color : Color.WHITE; @@ -407,14 +416,14 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyStyle */ Batched3DModel3DTileContent.prototype.applyStyle = function(frameState, style) { this._batchTable.applyStyle(frameState, style); }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#update */ Batched3DModel3DTileContent.prototype.update = function(tileset, frameState) { var commandStart = frameState.commandList.length; @@ -436,14 +445,14 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#isDestroyed */ Batched3DModel3DTileContent.prototype.isDestroyed = function() { return false; }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#destroy */ Batched3DModel3DTileContent.prototype.destroy = function() { this._model = this._model && this._model.destroy(); diff --git a/Source/Scene/Cesium3DTile.js b/Source/Scene/Cesium3DTile.js index 6882c312a2c5..a40fdd45fde9 100644 --- a/Source/Scene/Cesium3DTile.js +++ b/Source/Scene/Cesium3DTile.js @@ -18,6 +18,7 @@ define([ '../Core/Request', '../Core/RequestScheduler', '../Core/RequestType', + '../Core/RuntimeError', '../ThirdParty/when', './Cesium3DTileChildrenVisibility', './Cesium3DTileContentFactory', @@ -48,6 +49,7 @@ define([ Request, RequestScheduler, RequestType, + RuntimeError, when, Cesium3DTileChildrenVisibility, Cesium3DTileContentFactory, @@ -99,9 +101,9 @@ define([ if (defined(contentHeader) && defined(contentHeader.boundingVolume)) { // Non-leaf tiles may have a content bounding-volume, which is a tight-fit bounding volume - // around only the models in the tile. This box is useful for culling for rendering, + // around only the features in the tile. This box is useful for culling for rendering, // but not for culling for traversing the tree since it does not guarantee spatial coherence, i.e., - // since it only bounds models in the tile, not the entire tile, children may be + // since it only bounds features in the tile, not the entire tile, children may be // outside of this box. contentBoundingVolume = this.createBoundingVolume(contentHeader.boundingVolume, computedTransform); } @@ -123,6 +125,10 @@ define([ */ this.geometricError = header.geometricError; + if (!defined(this.geometricError)) { + throw new RuntimeError('geometricError must be defined'); + } + var refine; if (defined(header.refine)) { refine = (header.refine === 'replace') ? Cesium3DTileRefine.REPLACE : Cesium3DTileRefine.ADD; @@ -134,7 +140,7 @@ define([ } /** - * Specifies if additive or replacement refinement is used when traversing this tile for rendering. + * Specifies the type of refinment that is used when traversing this tile for rendering. * * @type {Cesium3DTileRefine} * @readonly @@ -143,9 +149,9 @@ define([ this.refine = refine; /** - * An array of {@link Cesium3DTile} objects that are this tile's children. + * Gets the tile's children. * - * @type {Array} + * @type {Cesium3DTile[]} * @readonly */ this.children = []; @@ -268,7 +274,6 @@ define([ */ this.selected = false; - /** * The time when a style was last applied to this tile. * @@ -405,6 +410,8 @@ define([ }, /** + * The server that will take the request for the tile's content. + * * @readonly * @private */ @@ -569,6 +576,14 @@ define([ } } + function getContentFailedFunction(tile) { + return function(error) { + tile._contentState = Cesium3DTileContentState.FAILED; + tile._contentReadyPromise.reject(error); + tile._contentReadyToProcessPromise.reject(error); + }; + } + /** * Requests the tile's content. *

@@ -617,10 +632,13 @@ define([ this.expireDate = undefined; } + var contentFailedFunction = getContentFailedFunction(this); + promise.then(function(arrayBuffer) { if (that.isDestroyed()) { // Tile is unloaded before the content finishes loading - return when.reject('tile is destroyed'); + contentFailedFunction(); + return; } var uint8Array = new Uint8Array(arrayBuffer); var magic = getMagic(uint8Array); @@ -640,10 +658,11 @@ define([ that._contentState = Cesium3DTileContentState.PROCESSING; that._contentReadyToProcessPromise.resolve(content); - content.readyPromise.then(function(content) { + return content.readyPromise.then(function(content) { if (that.isDestroyed()) { // Tile is unloaded before the content finishes processing - return when.reject('tile is destroyed'); + contentFailedFunction(); + return; } updateExpireDate(that); @@ -652,22 +671,14 @@ define([ 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); - }); + }).otherwise(contentFailedFunction); return true; }; /** - * Unloads the tile's content and returns the tile's state to the state of when - * it was first created, before its content was loaded. + * Unloads the tile's content. * * @private */ @@ -764,7 +775,7 @@ define([ return boundingVolume.distanceToCamera(frameState); }; - var scratchCartesian = new Cartesian3(); + var scratchToTileCenter = new Cartesian3(); /** * Computes the distance from the center of the tile's bounding volume to the camera. @@ -775,8 +786,9 @@ define([ * @private */ Cesium3DTile.prototype.distanceToTileCenter = function(frameState) { - var boundingVolume = getBoundingVolume(this, frameState).boundingVolume; - var toCenter = Cartesian3.subtract(boundingVolume.center, frameState.camera.positionWC, scratchCartesian); + var tileBoundingVolume = getBoundingVolume(this, frameState); + var boundingVolume = tileBoundingVolume.boundingVolume; // Gets the underlying OrientedBoundingBox or BoundingSphere + var toCenter = Cartesian3.subtract(boundingVolume.center, frameState.camera.positionWC, scratchToTileCenter); var distance = Cartesian3.magnitude(toCenter); Cartesian3.divideByScalar(toCenter, distance, toCenter); var dot = Cartesian3.dot(frameState.camera.directionWC, toCenter); @@ -793,11 +805,7 @@ define([ */ Cesium3DTile.prototype.insideViewerRequestVolume = function(frameState) { var viewerRequestVolume = this._viewerRequestVolume; - if (!defined(viewerRequestVolume)) { - return true; - } - - return (viewerRequestVolume.distanceToCamera(frameState) === 0.0); + return !defined(viewerRequestVolume) || (viewerRequestVolume.distanceToCamera(frameState) === 0.0); }; var scratchMatrix = new Matrix3(); @@ -806,6 +814,53 @@ define([ var scratchCenter = new Cartesian3(); var scratchRectangle = new Rectangle(); + function createBox(box, transform, result) { + var center = Cartesian3.fromElements(box[0], box[1], box[2], scratchCenter); + var halfAxes = Matrix3.fromArray(box, 3, scratchHalfAxes); + + // Find the transformed center and halfAxes + center = Matrix4.multiplyByPoint(transform, center, center); + var rotationScale = Matrix4.getRotation(transform, scratchMatrix); + halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes); + + if (defined(result)) { + result.update(center, halfAxes); + return result; + } + return new TileOrientedBoundingBox(center, halfAxes); + } + + function createRegion(region, result) { + var rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle); + + if (defined(result)) { + // Don't update regions when the transform changes + return result; + } + return new TileBoundingRegion({ + rectangle : rectangleRegion, + minimumHeight : region[4], + maximumHeight : region[5] + }); + } + + function createSphere(sphere, transform, result) { + var center = Cartesian3.fromElements(sphere[0], sphere[1], sphere[2], scratchCenter); + var radius = sphere[3]; + + // Find the transformed center and radius + center = Matrix4.multiplyByPoint(transform, center, center); + var scale = Matrix4.getScale(transform, scratchScale); + var uniformScale = Cartesian3.maximumComponent(scale); + radius *= uniformScale; + + if (defined(result)) { + result.update(center, radius); + return result; + } + return new TileBoundingSphere(center, radius); + } + /** * Create a bounding volume from the tile's bounding volume header. * @@ -818,52 +873,19 @@ define([ * @private */ Cesium3DTile.prototype.createBoundingVolume = function(boundingVolumeHeader, transform, result) { - var center; + if (!defined(boundingVolumeHeader)) { + throw new RuntimeError('boundingVolume must be defined'); + } if (defined(boundingVolumeHeader.box)) { - var box = boundingVolumeHeader.box; - center = Cartesian3.fromElements(box[0], box[1], box[2], scratchCenter); - var halfAxes = Matrix3.fromArray(box, 3, scratchHalfAxes); - - // Find the transformed center and halfAxes - center = Matrix4.multiplyByPoint(transform, center, center); - var rotationScale = Matrix4.getRotation(transform, scratchMatrix); - halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes); - - if (defined(result)) { - result.update(center, halfAxes); - return result; - } - return new TileOrientedBoundingBox(center, halfAxes); - } else if (defined(boundingVolumeHeader.region)) { - var region = boundingVolumeHeader.region; - var rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle); - - if (defined(result)) { - // Don't update regions when the transform changes - return result; - } - return new TileBoundingRegion({ - rectangle : rectangleRegion, - minimumHeight : region[4], - maximumHeight : region[5] - }); - } else if (defined(boundingVolumeHeader.sphere)) { - var sphere = boundingVolumeHeader.sphere; - center = Cartesian3.fromElements(sphere[0], sphere[1], sphere[2], scratchCenter); - var radius = sphere[3]; - - // Find the transformed center and radius - center = Matrix4.multiplyByPoint(transform, center, center); - var scale = Matrix4.getScale(transform, scratchScale); - var uniformScale = Cartesian3.maximumComponent(scale); - radius *= uniformScale; - - if (defined(result)) { - result.update(center, radius); - return result; - } - return new TileBoundingSphere(center, radius); + return createBox(boundingVolumeHeader.box, transform, result); + } + if (defined(boundingVolumeHeader.region)) { + return createRegion(boundingVolumeHeader.region, transform, result); + } + if (defined(boundingVolumeHeader.sphere)) { + return createSphere(boundingVolumeHeader.sphere, transform, result); } + throw new RuntimeError('boundingVolume must contain a sphere, region, or box'); }; var scratchTransform = new Matrix4(); @@ -877,25 +899,28 @@ define([ parentTransform = defaultValue(parentTransform, Matrix4.IDENTITY); var computedTransform = Matrix4.multiply(parentTransform, this.transform, scratchTransform); var transformChanged = !Matrix4.equals(computedTransform, this.computedTransform); - if (transformChanged) { - Matrix4.clone(computedTransform, this.computedTransform); - - // Update the bounding volumes - var header = this._header; - var content = this._header.content; - this._boundingVolume = this.createBoundingVolume(header.boundingVolume, computedTransform, this._boundingVolume); - if (defined(this._contentBoundingVolume)) { - this._contentBoundingVolume = this.createBoundingVolume(content.boundingVolume, computedTransform, this._contentBoundingVolume); - } - if (defined(this._viewerRequestVolume)) { - this._viewerRequestVolume = this.createBoundingVolume(header.viewerRequestVolume, computedTransform, this._viewerRequestVolume); - } - // Destroy the debug bounding volumes. They will be generated fresh. - this._debugBoundingVolume = this._debugBoundingVolume && this._debugBoundingVolume.destroy(); - this._debugContentBoundingVolume = this._debugContentBoundingVolume && this._debugContentBoundingVolume.destroy(); - this._debugViewerRequestVolume = this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy(); + if (!transformChanged) { + return; } + + Matrix4.clone(computedTransform, this.computedTransform); + + // Update the bounding volumes + var header = this._header; + var content = this._header.content; + this._boundingVolume = this.createBoundingVolume(header.boundingVolume, computedTransform, this._boundingVolume); + if (defined(this._contentBoundingVolume)) { + this._contentBoundingVolume = this.createBoundingVolume(content.boundingVolume, computedTransform, this._contentBoundingVolume); + } + if (defined(this._viewerRequestVolume)) { + this._viewerRequestVolume = this.createBoundingVolume(header.viewerRequestVolume, computedTransform, this._viewerRequestVolume); + } + + // Destroy the debug bounding volumes. They will be generated fresh. + this._debugBoundingVolume = this._debugBoundingVolume && this._debugBoundingVolume.destroy(); + this._debugContentBoundingVolume = this._debugContentBoundingVolume && this._debugContentBoundingVolume.destroy(); + this._debugViewerRequestVolume = this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy(); }; function applyDebugSettings(tile, tileset, frameState) { @@ -955,13 +980,18 @@ define([ var content = tile._content; var expiredContent = tile._expiredContent; - if (defined(expiredContent) && !tile.contentReady) { - // Render the expired content while the content loads - expiredContent.update(tileset, frameState); - return; + if (defined(expiredContent)) { + if (!tile.contentReady) { + // Render the expired content while the content loads + expiredContent.update(tileset, frameState); + return; + } else { + // New content is ready, destroy expired content + tile._expiredContent.destroy(); + tile._expiredContent = undefined; + } } - tile._expiredContent = tile._expiredContent && tile._expiredContent.destroy(); content.update(tileset, frameState); } diff --git a/Source/Scene/Cesium3DTileBatchTable.js b/Source/Scene/Cesium3DTileBatchTable.js index 3c16c0422ba4..4e0923211703 100644 --- a/Source/Scene/Cesium3DTileBatchTable.js +++ b/Source/Scene/Cesium3DTileBatchTable.js @@ -14,6 +14,7 @@ define([ '../Core/DeveloperError', '../Core/Math', '../Core/PixelFormat', + '../Core/RuntimeError', '../Renderer/ContextLimits', '../Renderer/DrawCommand', '../Renderer/Pass', @@ -24,6 +25,7 @@ define([ '../Renderer/Texture', '../Renderer/TextureMagnificationFilter', '../Renderer/TextureMinificationFilter', + './AttributeType', './BlendingState', './Cesium3DTileColorBlendMode', './CullFace', @@ -45,6 +47,7 @@ define([ DeveloperError, CesiumMath, PixelFormat, + RuntimeError, ContextLimits, DrawCommand, Pass, @@ -55,6 +58,7 @@ define([ Texture, TextureMagnificationFilter, TextureMinificationFilter, + AttributeType, BlendingState, Cesium3DTileColorBlendMode, CullFace, @@ -164,8 +168,8 @@ define([ var parentIdsLength = instancesLength; if (defined(classIds.byteOffset)) { - classIds.componentType = defaultValue(classIds.componentType, 'UNSIGNED_SHORT'); - classIds.type = 'SCALAR'; + classIds.componentType = defaultValue(classIds.componentType, ComponentDatatype.UNSIGNED_SHORT); + classIds.type = AttributeType.SCALAR; binaryAccessor = getBinaryAccessor(classIds); classIds = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + classIds.byteOffset, instancesLength); } @@ -173,8 +177,8 @@ define([ var parentIndexes; if (defined(parentCounts)) { if (defined(parentCounts.byteOffset)) { - parentCounts.componentType = defaultValue(parentCounts.componentType, 'UNSIGNED_SHORT'); - parentCounts.type = 'SCALAR'; + parentCounts.componentType = defaultValue(parentCounts.componentType, ComponentDatatype.UNSIGNED_SHORT); + parentCounts.type = AttributeType.SCALAR; binaryAccessor = getBinaryAccessor(parentCounts); parentCounts = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + parentCounts.byteOffset, instancesLength); } @@ -186,13 +190,11 @@ define([ } } - if (defined(parentIds)) { - if (defined(parentIds.byteOffset)) { - parentIds.componentType = defaultValue(parentIds.componentType, 'UNSIGNED_SHORT'); - parentIds.type = 'SCALAR'; - binaryAccessor = getBinaryAccessor(parentIds); - parentIds = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + parentIds.byteOffset, parentIdsLength); - } + if (defined(parentIds) && defined(parentIds.byteOffset)) { + parentIds.componentType = defaultValue(parentIds.componentType, ComponentDatatype.UNSIGNED_SHORT); + parentIds.type = AttributeType.SCALAR; + binaryAccessor = getBinaryAccessor(parentIds); + parentIds = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + parentIds.byteOffset, parentIdsLength); } var classesLength = classes.length; @@ -276,48 +278,43 @@ define([ Cesium3DTileBatchTable.getBinaryProperties = function(featuresLength, json, binary) { var binaryProperties; - if (defined(json)) { - for (var name in json) { - if (json.hasOwnProperty(name)) { - var property = json[name]; - var byteOffset = property.byteOffset; - if (defined(byteOffset)) { - // This is a binary property - var componentType = ComponentDatatype.fromName(property.componentType); - var type = property.type; - //>>includeStart('debug', pragmas.debug); - if (!defined(componentType)) { - throw new DeveloperError('componentType is required.'); - } - if (!defined(type)) { - throw new DeveloperError('type is required.'); - } - if (!defined(binary)) { - throw new DeveloperError('Property ' + name + ' requires a batch table binary.'); - } - //>>includeEnd('debug'); - - var binaryAccessor = getBinaryAccessor(property); - var componentCount = binaryAccessor.componentsPerAttribute; - var classType = binaryAccessor.classType; - var typedArray = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + byteOffset, featuresLength); - - if (!defined(binaryProperties)) { - binaryProperties = {}; - } - - // Store any information needed to access the binary data, including the typed array, - // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4). - binaryProperties[name] = { - typedArray : typedArray, - componentCount : componentCount, - type : classType - }; + for (var name in json) { + if (json.hasOwnProperty(name)) { + var property = json[name]; + var byteOffset = property.byteOffset; + if (defined(byteOffset)) { + // This is a binary property + var componentType = ComponentDatatype.fromName(property.componentType); + var type = property.type; + if (!defined(componentType)) { + throw new RuntimeError('componentType is required.'); + } + if (!defined(type)) { + throw new RuntimeError('type is required.'); } + if (!defined(binary)) { + throw new RuntimeError('Property ' + name + ' requires a batch table binary.'); + } + + var binaryAccessor = getBinaryAccessor(property); + var componentCount = binaryAccessor.componentsPerAttribute; + var classType = binaryAccessor.classType; + var typedArray = binaryAccessor.createArrayBufferView(binary.buffer, binary.byteOffset + byteOffset, featuresLength); + + if (!defined(binaryProperties)) { + binaryProperties = {}; + } + + // Store any information needed to access the binary data, including the typed array, + // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4). + binaryProperties[name] = { + typedArray : typedArray, + componentCount : componentCount, + type : classType + }; } } } - return binaryProperties; }; function getByteLength(batchTable) { @@ -391,7 +388,6 @@ define([ var featuresLength = this.featuresLength; for (var i = 0; i < featuresLength; ++i) { - // PERFORMANCE_IDEA: duplicate part of setColor here to factor things out of the loop this.setShow(i, show); } }; @@ -479,7 +475,6 @@ define([ var featuresLength = this.featuresLength; for (var i = 0; i < featuresLength; ++i) { - // PERFORMANCE_IDEA: duplicate part of setColor here to factor things out of the loop this.setColor(i, color); } }; @@ -600,32 +595,26 @@ define([ } function traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback) { - while (true) { // eslint-disable-line no-constant-condition + var hasParent = true; + while (hasParent) { var result = endConditionCallback(hierarchy, instanceIndex); if (defined(result)) { // The end condition was met, stop the traversal and return the result return result; } var parentId = hierarchy.parentIds[instanceIndex]; - if (parentId === instanceIndex) { - // Stop the traversal when the instance has no parent (its parentId equals itself) - break; - } + hasParent = parentId !== instanceIndex; instanceIndex = parentId; } } - function traverseHierarchyNoParents(hierarchy, instanceIndex, endConditionCallback) { - return endConditionCallback(hierarchy, instanceIndex); - } - function traverseHierarchy(hierarchy, instanceIndex, endConditionCallback) { // Traverse over the hierarchy and process each instance with the endConditionCallback. // When the endConditionCallback returns a value, the traversal stops and that value is returned. var parentCounts = hierarchy.parentCounts; var parentIds = hierarchy.parentIds; if (!defined(parentIds)) { - return traverseHierarchyNoParents(hierarchy, instanceIndex, endConditionCallback); + return endConditionCallback(hierarchy, instanceIndex); } else if (defined(parentCounts)) { return traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback); } diff --git a/Source/Scene/Cesium3DTileContentFactory.js b/Source/Scene/Cesium3DTileContentFactory.js index b4e9471511e2..c90d50b4917b 100644 --- a/Source/Scene/Cesium3DTileContentFactory.js +++ b/Source/Scene/Cesium3DTileContentFactory.js @@ -14,8 +14,7 @@ define([ 'use strict'; /** - * Maps a tile's extension (and a tile's magic field in its header) to a new - * content object for the tile's payload. + * Maps a tile's magic field in its header to a new content object for the tile's payload. * * @private */ diff --git a/Source/Scene/Cesium3DTileFeature.js b/Source/Scene/Cesium3DTileFeature.js index b6659b273f80..c63d92ba3f36 100644 --- a/Source/Scene/Cesium3DTileFeature.js +++ b/Source/Scene/Cesium3DTileFeature.js @@ -45,15 +45,6 @@ define([ this._content = content; this._batchId = batchId; this._color = undefined; // for calling getColor - - /** - * All objects returned by {@link Scene#pick} have a primitive property. - * - * @type {Cesium3DTileset} - * - * @private - */ - this.primitive = tileset; } defineProperties(Cesium3DTileFeature.prototype, { @@ -113,6 +104,17 @@ define([ get : function() { return this._content; } + }, + + /** + * All objects returned by {@link Scene#pick} have a primitive property. + * + * @type {Cesium3DTileset} + */ + primitive : { + get : function() { + return this._content.tileset; + } } }); diff --git a/Source/Scene/Cesium3DTileStyle.js b/Source/Scene/Cesium3DTileStyle.js index 9dd78cb8cb36..38e5b7e2601e 100644 --- a/Source/Scene/Cesium3DTileStyle.js +++ b/Source/Scene/Cesium3DTileStyle.js @@ -50,6 +50,13 @@ define([ * description : '"Building id ${id} has height ${Height}."' * } * }); + * + * @example + * tileset.style = new Cesium.Cesium3DTileStyle({ + * color : 'vec4(${Temperature})', + * pointSize : '${Temperature} * 2.0' + * }); + */ function Cesium3DTileStyle(data) { this._style = undefined; diff --git a/Source/Scene/Cesium3DTileset.js b/Source/Scene/Cesium3DTileset.js index 26d03238ea08..d1e322eb4182 100644 --- a/Source/Scene/Cesium3DTileset.js +++ b/Source/Scene/Cesium3DTileset.js @@ -23,6 +23,7 @@ define([ '../Core/Matrix4', '../Core/RequestScheduler', '../Core/RequestType', + '../Core/RuntimeError', '../Renderer/ClearCommand', '../Renderer/Pass', '../ThirdParty/when', @@ -35,6 +36,7 @@ define([ './Cesium3DTilesetTraversal', './Cesium3DTileStyleEngine', './LabelCollection', + './SceneMode', './ShadowMode', './TileBoundingRegion', './TileBoundingSphere', @@ -63,6 +65,7 @@ define([ Matrix4, RequestScheduler, RequestType, + RuntimeError, ClearCommand, Pass, when, @@ -75,6 +78,7 @@ define([ Cesium3DTilesetTraversal, Cesium3DTileStyleEngine, LabelCollection, + SceneMode, ShadowMode, TileBoundingRegion, TileBoundingSphere, @@ -442,7 +446,7 @@ define([ * processed and is ready to render. *

* The number of pending tile requests, numberOfPendingRequests, and number of tiles - * processing, numberProcessing are passed to the event listener. + * processing, numberOfTilesProcessing are passed to the event listener. *

*

* This event is fired at the end of the frame after the scene is rendered. @@ -452,13 +456,13 @@ define([ * @default new Event() * * @example - * tileset.loadProgress.addEventListener(function(numberOfPendingRequests, numberProcessing) { - * if ((numberOfPendingRequests === 0) && (numberProcessing === 0)) { + * tileset.loadProgress.addEventListener(function(numberOfPendingRequests, numberOfTilesProcessing) { + * if ((numberOfPendingRequests === 0) && (numberOfTilesProcessing === 0)) { * console.log('Stopped loading'); * return; * } * - * console.log('Loading: requests: ' + numberOfPendingRequests + ', processing: ' + numberProcessing); + * console.log('Loading: requests: ' + numberOfPendingRequests + ', processing: ' + numberOfTilesProcessing); * }); */ this.loadProgress = new Event(); @@ -1128,12 +1132,10 @@ define([ */ Cesium3DTileset.prototype.loadTileset = function(tilesetUrl, tilesetJson, parentTile) { var asset = tilesetJson.asset; - //>>includeStart('debug', pragmas.debug); Check.typeOf.object('tilesetJson.asset', asset); if (asset.version !== '0.0' && asset.version !== '1.0') { - throw new DeveloperError('The tileset must be 3D Tiles version 0.0 or 1.0. See https://github.com/AnalyticalGraphicsInc/3d-tiles#spec-status'); + throw new RuntimeError('The tileset must be 3D Tiles version 0.0 or 1.0. See https://github.com/AnalyticalGraphicsInc/3d-tiles#spec-status'); } - //>>includeEnd('debug'); var statistics = this._statistics; @@ -1157,7 +1159,7 @@ define([ rootTile._depth = parentTile._depth + 1; } - ++statistics.numberTotal; + ++statistics.numberOfTilesTotal; var stack = []; stack.push({ @@ -1176,7 +1178,7 @@ define([ var childTile = new Cesium3DTile(this, basePath, childHeader, tile3D); tile3D.children.push(childTile); childTile._depth = tile3D._depth + 1; - ++statistics.numberTotal; + ++statistics.numberOfTilesTotal; stack.push({ header : childHeader, tile3D : childTile @@ -1330,7 +1332,7 @@ define([ if (expired) { if (tile.hasRenderableContent) { statistics.decrementLoadCounts(tile.content); - --tileset._statistics.numberContentReady; + --tileset._statistics.numberOfTilesWithContentReady; } else if (tile.hasTilesetContent) { destroySubtree(tileset, tile); } @@ -1360,7 +1362,7 @@ define([ tileset._processingQueue.push(tile); --tileset._statistics.numberOfPendingRequests; - ++tileset._statistics.numberProcessing; + ++tileset._statistics.numberOfTilesProcessing; }; } @@ -1370,13 +1372,13 @@ define([ if (index >= 0) { // Remove from processing queue tileset._processingQueue.splice(index, 1); - --tileset._statistics.numberProcessing; + --tileset._statistics.numberOfTilesProcessing; if (tile.hasRenderableContent) { // RESEARCH_IDEA: ability to unload tiles (without content) for an // external tileset when all the tiles are unloaded. tileset._statistics.incrementLoadCounts(tile.content); - ++tileset._statistics.numberContentReady; + ++tileset._statistics.numberOfTilesWithContentReady; // Add to the tile cache. Previously expired tiles are already in the cache. if (!defined(tile.replacementNode)) { @@ -1570,7 +1572,7 @@ define([ * of an object, they will always be drawn while loading, even if backface culling is enabled. */ - var backfaceCommands = tileset._backfaceCommands.internalArray; + var backfaceCommands = tileset._backfaceCommands.values; var addedCommandsLength = (lengthAfterUpdate - lengthBeforeUpdate); var backfaceCommandsLength = backfaceCommands.length; @@ -1615,7 +1617,7 @@ define([ if (tile !== root) { unloadTileFromCache(tileset, tile); tile.destroy(); - --statistics.numberTotal; + --statistics.numberOfTilesTotal; } } root.children = []; @@ -1634,7 +1636,7 @@ define([ tileUnload.raiseEvent(tile); replacementList.remove(node); statistics.decrementLoadCounts(tile.content); - --statistics.numberContentReady; + --statistics.numberOfTilesWithContentReady; } function unloadTiles(tileset) { @@ -1681,19 +1683,19 @@ define([ var statistics = tileset._statistics; var statisticsLast = tileset._statisticsLastColor; var numberOfPendingRequests = statistics.numberOfPendingRequests; - var numberProcessing = statistics.numberProcessing; + var numberOfTilesProcessing = statistics.numberOfTilesProcessing; var lastNumberOfPendingRequest = statisticsLast.numberOfPendingRequests; - var lastNumberProcessing = statisticsLast.numberProcessing; + var lastNumberOfTilesProcessing = statisticsLast.numberOfTilesProcessing; - var progressChanged = (numberOfPendingRequests !== lastNumberOfPendingRequest) || (numberProcessing !== lastNumberProcessing); + var progressChanged = (numberOfPendingRequests !== lastNumberOfPendingRequest) || (numberOfTilesProcessing !== lastNumberOfTilesProcessing); if (progressChanged) { frameState.afterRender.push(function() { - tileset.loadProgress.raiseEvent(numberOfPendingRequests, numberProcessing); + tileset.loadProgress.raiseEvent(numberOfPendingRequests, numberOfTilesProcessing); }); } - tileset._tilesLoaded = (statistics.numberOfPendingRequests === 0) && (statistics.numberProcessing === 0) && (statistics.numberOfAttemptedRequests === 0); + tileset._tilesLoaded = (statistics.numberOfPendingRequests === 0) && (statistics.numberOfTilesProcessing === 0) && (statistics.numberOfAttemptedRequests === 0); if (progressChanged && tileset._tilesLoaded) { frameState.afterRender.push(function() { @@ -1714,6 +1716,10 @@ define([ * */ Cesium3DTileset.prototype.update = function(frameState) { + if (frameState.mode === SceneMode.MORPHING) { + return; + } + if (!this.show || !this.ready) { return; } diff --git a/Source/Scene/Cesium3DTilesetStatistics.js b/Source/Scene/Cesium3DTilesetStatistics.js index 07383a35e976..85442f395427 100644 --- a/Source/Scene/Cesium3DTilesetStatistics.js +++ b/Source/Scene/Cesium3DTilesetStatistics.js @@ -16,9 +16,9 @@ define([ this.numberOfCommands = 0; this.numberOfAttemptedRequests = 0; this.numberOfPendingRequests = 0; - this.numberProcessing = 0; - this.numberContentReady = 0; // Number of tiles with content loaded, does not include empty tiles - this.numberTotal = 0; // Number of tiles in tileset.json (and other tileset.json files as they are loaded) + this.numberOfTilesProcessing = 0; + this.numberOfTilesWithContentReady = 0; // Number of tiles with content loaded, does not include empty tiles + this.numberOfTilesTotal = 0; // Number of tiles in tileset.json (and other tileset.json files as they are loaded) // Features statistics this.numberOfFeaturesSelected = 0; // Number of features rendered this.numberOfFeaturesLoaded = 0; // Number of features in memory @@ -97,9 +97,9 @@ define([ result.selected = statistics.selected; result.numberOfAttemptedRequests = statistics.numberOfAttemptedRequests; result.numberOfPendingRequests = statistics.numberOfPendingRequests; - result.numberProcessing = statistics.numberProcessing; - result.numberContentReady = statistics.numberContentReady; - result.numberTotal = statistics.numberTotal; + result.numberOfTilesProcessing = statistics.numberOfTilesProcessing; + result.numberOfTilesWithContentReady = statistics.numberOfTilesWithContentReady; + result.numberOfTilesTotal = statistics.numberOfTilesTotal; result.numberOfFeaturesSelected = statistics.numberOfFeaturesSelected; result.numberOfFeaturesLoaded = statistics.numberOfFeaturesLoaded; result.numberOfPointsSelected = statistics.numberOfPointsSelected; diff --git a/Source/Scene/Cesium3DTilesetTraversal.js b/Source/Scene/Cesium3DTilesetTraversal.js index 55b8eb30a36c..31f536fefd93 100644 --- a/Source/Scene/Cesium3DTilesetTraversal.js +++ b/Source/Scene/Cesium3DTilesetTraversal.js @@ -231,7 +231,7 @@ define([ function selectTile(tileset, tile, frameState) { // There may also be a tight box around just the tile's contents, e.g., for a city, we may be - // zoomed into a neighborhood and can cull the skyscrapers in the root node. + // zoomed into a neighborhood and can cull the skyscrapers in the root tile. if (tile.contentAvailable && ( (tile._visibilityPlaneMask === CullingVolume.MASK_INSIDE) || (tile.contentVisibility(frameState) !== Intersect.OUTSIDE) @@ -670,7 +670,7 @@ define([ function getScreenSpaceError(tileset, geometricError, tile, frameState) { if (geometricError === 0.0) { - // Leaf nodes do not have any error so save the computation + // Leaf tiles do not have any error so save the computation return 0.0; } @@ -745,9 +745,9 @@ define([ while (stack.length > 0) { maxLength = Math.max(maxLength, stack.length); - var node = stack.pop(); - options.visitStart(node); - var children = options.getChildren(node); + var tile = stack.pop(); + options.visitStart(tile); + var children = options.getChildren(tile); var isNativeArray = !defined(children.get); var length = children.length; for (var i = 0; i < length; ++i) { @@ -759,9 +759,9 @@ define([ } if (length === 0 && defined(options.leafHandler)) { - options.leafHandler(node); + options.leafHandler(tile); } - options.visitEnd(node); + options.visitEnd(tile); } stack.trim(maxLength); @@ -781,9 +781,9 @@ define([ maxLength = Math.max(maxLength, length); for (var i = 0; i < length; ++i) { - var node = queue1.get(i); - options.visitStart(node); - var children = options.getChildren(node); + var tile = queue1.get(i); + options.visitStart(tile); + var children = options.getChildren(tile); var isNativeArray = !defined(children.get); var childrenLength = children.length; for (var j = 0; j < childrenLength; ++j) { @@ -795,9 +795,9 @@ define([ } if (childrenLength === 0 && defined(options.leafHandler)) { - options.leafHandler(node); + options.leafHandler(tile); } - options.visitEnd(node); + options.visitEnd(tile); } queue1.length = 0; diff --git a/Source/Scene/Composite3DTileContent.js b/Source/Scene/Composite3DTileContent.js index 470f29a05137..39b0cf0ab799 100644 --- a/Source/Scene/Composite3DTileContent.js +++ b/Source/Scene/Composite3DTileContent.js @@ -4,23 +4,34 @@ define([ '../Core/defined', '../Core/defineProperties', '../Core/destroyObject', - '../Core/DeveloperError', + '../Core/FeatureDetection', '../Core/getMagic', + '../Core/RuntimeError', '../ThirdParty/when' ], function( defaultValue, defined, defineProperties, destroyObject, - DeveloperError, + FeatureDetection, getMagic, + RuntimeError, when) { 'use strict'; + // Bail out if the browser doesn't support typed arrays, to prevent the setup function + // from failing, since we won't be able to create a WebGL context anyway. + if (!FeatureDetection.supportsTypedArrays()) { + return {}; + } + /** * Represents the contents of a * {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/TileFormats/Composite/README.md|Composite} * tile in a {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/README.md|3D Tiles} tileset. + *

+ * Implements the {@link Cesium3DTileContent} interface. + *

* * @alias Composite3DTileContent * @constructor @@ -39,7 +50,7 @@ define([ defineProperties(Composite3DTileContent.prototype, { /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featurePropertiesDirty */ featurePropertiesDirty : { get : function() { @@ -123,8 +134,7 @@ define([ }, /** - * Gets the array of {@link Cesium3DTileContent} objects that represent the - * content of the composite's inner tiles, which can also be composites. + * @inheritdoc Cesium3DTileContent#innerContents */ innerContents : { get : function() { @@ -133,7 +143,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#readyPromise */ readyPromise : { get : function() { @@ -142,7 +152,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tileset */ tileset : { get : function() { @@ -151,7 +161,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tile */ tile : { get : function() { @@ -160,7 +170,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#url */ url : { get : function() { @@ -188,12 +198,10 @@ define([ var view = new DataView(arrayBuffer); byteOffset += sizeOfUint32; // Skip magic - //>>includeStart('debug', pragmas.debug); var version = view.getUint32(byteOffset, true); if (version !== 1) { - throw new DeveloperError('Only Composite Tile version 1 is supported. Version ' + version + ' is not.'); + throw new RuntimeError('Only Composite Tile version 1 is supported. Version ' + version + ' is not.'); } - //>>includeEnd('debug'); byteOffset += sizeOfUint32; // Skip byteLength @@ -216,12 +224,9 @@ define([ var innerContent = contentFactory(content._tileset, content._tile, content._url, arrayBuffer, byteOffset); content._contents.push(innerContent); contentPromises.push(innerContent.readyPromise); + } else { + throw new RuntimeError('Unknown tile content type, ' + tileType + ', inside Composite tile'); } - //>>includeStart('debug', pragmas.debug); - else { - throw new DeveloperError('Unknown tile content type, ' + tileType + ', inside Composite tile'); - } - //>>includeEnd('debug'); byteOffset += tileByteLength; } @@ -250,7 +255,7 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyDebugSettings */ Composite3DTileContent.prototype.applyDebugSettings = function(enabled, color) { var contents = this._contents; @@ -261,7 +266,7 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyStyle */ Composite3DTileContent.prototype.applyStyle = function(frameState, style) { var contents = this._contents; @@ -272,7 +277,7 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#update */ Composite3DTileContent.prototype.update = function(tileset, frameState) { var contents = this._contents; @@ -283,14 +288,14 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#isDestroyed */ Composite3DTileContent.prototype.isDestroyed = function() { return false; }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#destroy */ Composite3DTileContent.prototype.destroy = function() { var contents = this._contents; diff --git a/Source/Scene/ConditionsExpression.js b/Source/Scene/ConditionsExpression.js index 8ff9253049fd..c5fa40afa089 100644 --- a/Source/Scene/ConditionsExpression.js +++ b/Source/Scene/ConditionsExpression.js @@ -156,13 +156,10 @@ define([ var length = conditions.length; for (var i = 0; i < length; ++i) { var statement = conditions[i]; + var condition = statement.condition.getShaderExpression(attributePrefix, shaderState); var expression = statement.expression.getShaderExpression(attributePrefix, shaderState); - if (!defined(condition) || !defined(expression)) { - return undefined; - } - // Build the if/else chain from the list of conditions shaderFunction += ' ' + ((i === 0) ? 'if' : 'else if') + ' (' + condition + ') \n' + diff --git a/Source/Scene/Empty3DTileContent.js b/Source/Scene/Empty3DTileContent.js index 82db01cc533b..f463c70d9ce1 100644 --- a/Source/Scene/Empty3DTileContent.js +++ b/Source/Scene/Empty3DTileContent.js @@ -11,6 +11,9 @@ define([ * Represents empty content for tiles in a * {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/README.md|3D Tiles} tileset that * do not have content, e.g., because they are used to optimize hierarchical culling. + *

+ * Implements the {@link Cesium3DTileContent} interface. + *

* * @alias Empty3DTileContent * @constructor @@ -22,14 +25,14 @@ define([ this._tile = tile; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featurePropertiesDirty */ this.featurePropertiesDirty = false; } defineProperties(Empty3DTileContent.prototype, { /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featuresLength */ featuresLength : { get : function() { @@ -38,7 +41,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#pointsLength */ pointsLength : { get : function() { @@ -47,7 +50,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#trianglesLength */ trianglesLength : { get : function() { @@ -56,7 +59,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#geometryByteLength */ geometryByteLength : { get : function() { @@ -65,7 +68,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#texturesByteLength */ texturesByteLength : { get : function() { @@ -74,7 +77,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#batchTableByteLength */ batchTableByteLength : { get : function() { @@ -83,7 +86,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#innerContents */ innerContents : { get : function() { @@ -92,7 +95,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#readyPromise */ readyPromise : { get : function() { @@ -101,7 +104,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tileset */ tileset : { get : function() { @@ -110,7 +113,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tile */ tile : { get : function() { @@ -119,7 +122,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#url */ url: { get: function() { @@ -128,7 +131,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#batchTable */ batchTable : { get : function() { @@ -154,32 +157,32 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyDebugSettings */ Empty3DTileContent.prototype.applyDebugSettings = function(enabled, color) { }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyStyle */ Empty3DTileContent.prototype.applyStyle = function(frameState, style) { }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#update */ Empty3DTileContent.prototype.update = function(tileset, frameState) { }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#isDestroyed */ Empty3DTileContent.prototype.isDestroyed = function() { return false; }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#destroy */ Empty3DTileContent.prototype.destroy = function() { return destroyObject(this); diff --git a/Source/Scene/Expression.js b/Source/Scene/Expression.js index bb2c7d2cd920..0c04cc30f4ae 100644 --- a/Source/Scene/Expression.js +++ b/Source/Scene/Expression.js @@ -7,9 +7,9 @@ define([ '../Core/Color', '../Core/defined', '../Core/defineProperties', - '../Core/DeveloperError', '../Core/isArray', '../Core/Math', + '../Core/RuntimeError', '../ThirdParty/jsep', './ExpressionNodeType' ], function( @@ -20,9 +20,9 @@ define([ Color, defined, defineProperties, - DeveloperError, isArray, CesiumMath, + RuntimeError, jsep, ExpressionNodeType) { 'use strict'; @@ -65,9 +65,7 @@ define([ try { ast = jsep(expression); } catch (e) { - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError(e); - //>>includeEnd('debug'); + throw new RuntimeError(e); } this._runtimeAst = createRuntimeAst(this, ast); @@ -105,7 +103,7 @@ define([ * @returns {Boolean|Number|String|RegExp|Cartesian2|Cartesian3|Cartesian4} The result of evaluating the expression. */ Expression.prototype.evaluate = function(frameState, feature) { - ScratchStorage.reset(); + scratchStorage.reset(); var result = this._runtimeAst.evaluate(frameState, feature); if ((result instanceof Cartesian2) || (result instanceof Cartesian3) || (result instanceof Cartesian4)) { return result.clone(); @@ -124,7 +122,7 @@ define([ * @returns {Color} The modified result parameter or a new Color instance if one was not provided. */ Expression.prototype.evaluateColor = function(frameState, feature, result) { - ScratchStorage.reset(); + scratchStorage.reset(); var color = this._runtimeAst.evaluate(frameState, feature); return Color.fromCartesian4(color, result); }; @@ -144,9 +142,6 @@ define([ */ Expression.prototype.getShaderFunction = function(functionName, attributePrefix, shaderState, returnType) { var shaderExpression = this.getShaderExpression(attributePrefix, shaderState); - if (!defined(shaderExpression)) { - return undefined; - } shaderExpression = returnType + ' ' + functionName + '() \n' + '{ \n' + @@ -181,46 +176,46 @@ define([ var scratchColor = new Color(); - var ScratchStorage = { - scratchArrayIndex : 0, - scratchArrayArray : [[]], - scratchCartesian2Index : 0, - scratchCartesian3Index : 0, - scratchCartesian4Index : 0, - scratchCartesian2Array : [new Cartesian2()], - scratchCartesian3Array : [new Cartesian3()], - scratchCartesian4Array : [new Cartesian4()], + var scratchStorage = { + arrayIndex : 0, + arrayArray : [[]], + cartesian2Index : 0, + cartesian3Index : 0, + cartesian4Index : 0, + cartesian2Array : [new Cartesian2()], + cartesian3Array : [new Cartesian3()], + cartesian4Array : [new Cartesian4()], reset : function() { - this.scratchArrayIndex = 0; - this.scratchCartesian2Index = 0; - this.scratchCartesian3Index = 0; - this.scratchCartesian4Index = 0; + this.arrayIndex = 0; + this.cartesian2Index = 0; + this.cartesian3Index = 0; + this.cartesian4Index = 0; }, getArray : function() { - if (this.scratchArrayIndex >= this.scratchArrayArray.length) { - this.scratchArrayArray.push([]); + if (this.arrayIndex >= this.arrayArray.length) { + this.arrayArray.push([]); } - var scratchArray = this.scratchArrayArray[this.scratchArrayIndex++]; - scratchArray.length = 0; - return scratchArray; + var array = this.arrayArray[this.arrayIndex++]; + array.length = 0; + return array; }, getCartesian2 : function() { - if (this.scratchCartesian2Index >= this.scratchCartesian2Array.length) { - this.scratchCartesian2Array.push(new Cartesian2()); + if (this.cartesian2Index >= this.cartesian2Array.length) { + this.cartesian2Array.push(new Cartesian2()); } - return this.scratchCartesian2Array[this.scratchCartesian2Index++]; + return this.cartesian2Array[this.cartesian2Index++]; }, getCartesian3 : function() { - if (this.scratchCartesian3Index >= this.scratchCartesian3Array.length) { - this.scratchCartesian3Array.push(new Cartesian3()); + if (this.cartesian3Index >= this.cartesian3Array.length) { + this.cartesian3Array.push(new Cartesian3()); } - return this.scratchCartesian3Array[this.scratchCartesian3Index++]; + return this.cartesian3Array[this.cartesian3Index++]; }, getCartesian4 : function() { - if (this.scratchCartesian4Index >= this.scratchCartesian4Array.length) { - this.scratchCartesian4Array.push(new Cartesian4()); + if (this.cartesian4Index >= this.cartesian4Array.length) { + this.cartesian4Array.push(new Cartesian4()); } - return this.scratchCartesian4Array[this.scratchCartesian4Index++]; + return this.cartesian4Array[this.cartesian4Index++]; } }; @@ -280,15 +275,13 @@ define([ if (typeof left === 'number') { return operation(left); } else if (left instanceof Cartesian2) { - return Cartesian2.fromElements(operation(left.x), operation(left.y), ScratchStorage.getCartesian2()); + return Cartesian2.fromElements(operation(left.x), operation(left.y), scratchStorage.getCartesian2()); } else if (left instanceof Cartesian3) { - return Cartesian3.fromElements(operation(left.x), operation(left.y), operation(left.z), ScratchStorage.getCartesian3()); + return Cartesian3.fromElements(operation(left.x), operation(left.y), operation(left.z), scratchStorage.getCartesian3()); } else if (left instanceof Cartesian4) { - return Cartesian4.fromElements(operation(left.x), operation(left.y), operation(left.z), operation(left.w), ScratchStorage.getCartesian4()); + return Cartesian4.fromElements(operation(left.x), operation(left.y), operation(left.z), operation(left.w), scratchStorage.getCartesian4()); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Function "' + call + '" requires a vector or number argument. Argument is ' + left + '.'); - //>>includeEnd('debug'); + throw new RuntimeError('Function "' + call + '" requires a vector or number argument. Argument is ' + left + '.'); }; } @@ -298,27 +291,25 @@ define([ if (typeof left === 'number') { return operation(left, right); } else if (left instanceof Cartesian2) { - return Cartesian2.fromElements(operation(left.x, right), operation(left.y, right), ScratchStorage.getCartesian2()); + return Cartesian2.fromElements(operation(left.x, right), operation(left.y, right), scratchStorage.getCartesian2()); } else if (left instanceof Cartesian3) { - return Cartesian3.fromElements(operation(left.x, right), operation(left.y, right), operation(left.z, right), ScratchStorage.getCartesian3()); + return Cartesian3.fromElements(operation(left.x, right), operation(left.y, right), operation(left.z, right), scratchStorage.getCartesian3()); } else if (left instanceof Cartesian4) { - return Cartesian4.fromElements(operation(left.x, right), operation(left.y, right), operation(left.z, right), operation(left.w, right), ScratchStorage.getCartesian4()); + return Cartesian4.fromElements(operation(left.x, right), operation(left.y, right), operation(left.z, right), operation(left.w, right), scratchStorage.getCartesian4()); } } if (typeof left === 'number' && typeof right === 'number') { return operation(left, right); } else if (left instanceof Cartesian2 && right instanceof Cartesian2) { - return Cartesian2.fromElements(operation(left.x, right.x), operation(left.y, right.y), ScratchStorage.getCartesian2()); + return Cartesian2.fromElements(operation(left.x, right.x), operation(left.y, right.y), scratchStorage.getCartesian2()); } else if (left instanceof Cartesian3 && right instanceof Cartesian3) { - return Cartesian3.fromElements(operation(left.x, right.x), operation(left.y, right.y), operation(left.z, right.z), ScratchStorage.getCartesian3()); + return Cartesian3.fromElements(operation(left.x, right.x), operation(left.y, right.y), operation(left.z, right.z), scratchStorage.getCartesian3()); } else if (left instanceof Cartesian4 && right instanceof Cartesian4) { - return Cartesian4.fromElements(operation(left.x, right.x), operation(left.y, right.y), operation(left.z, right.z), operation(left.w, right.w), ScratchStorage.getCartesian4()); + return Cartesian4.fromElements(operation(left.x, right.x), operation(left.y, right.y), operation(left.z, right.z), operation(left.w, right.w), scratchStorage.getCartesian4()); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Function "' + call + '" requires vector or number arguments of matching types. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); + throw new RuntimeError('Function "' + call + '" requires vector or number arguments of matching types. Arguments are ' + left + ' and ' + right + '.'); }; } @@ -328,27 +319,25 @@ define([ if (typeof left === 'number' && typeof right === 'number') { return operation(left, right, test); } else if (left instanceof Cartesian2 && right instanceof Cartesian2) { - return Cartesian2.fromElements(operation(left.x, right.x, test), operation(left.y, right.y, test), ScratchStorage.getCartesian2()); + return Cartesian2.fromElements(operation(left.x, right.x, test), operation(left.y, right.y, test), scratchStorage.getCartesian2()); } else if (left instanceof Cartesian3 && right instanceof Cartesian3) { - return Cartesian3.fromElements(operation(left.x, right.x, test), operation(left.y, right.y, test), operation(left.z, right.z, test), ScratchStorage.getCartesian3()); + return Cartesian3.fromElements(operation(left.x, right.x, test), operation(left.y, right.y, test), operation(left.z, right.z, test), scratchStorage.getCartesian3()); } else if (left instanceof Cartesian4 && right instanceof Cartesian4) { - return Cartesian4.fromElements(operation(left.x, right.x, test), operation(left.y, right.y, test), operation(left.z, right.z, test), operation(left.w, right.w, test), ScratchStorage.getCartesian4()); + return Cartesian4.fromElements(operation(left.x, right.x, test), operation(left.y, right.y, test), operation(left.z, right.z, test), operation(left.w, right.w, test), scratchStorage.getCartesian4()); } } if (typeof left === 'number' && typeof right === 'number' && typeof test === 'number') { return operation(left, right, test); } else if (left instanceof Cartesian2 && right instanceof Cartesian2 && test instanceof Cartesian2) { - return Cartesian2.fromElements(operation(left.x, right.x, test.x), operation(left.y, right.y, test.y), ScratchStorage.getCartesian2()); + return Cartesian2.fromElements(operation(left.x, right.x, test.x), operation(left.y, right.y, test.y), scratchStorage.getCartesian2()); } else if (left instanceof Cartesian3 && right instanceof Cartesian3 && test instanceof Cartesian3) { - return Cartesian3.fromElements(operation(left.x, right.x, test.x), operation(left.y, right.y, test.y), operation(left.z, right.z, test.z), ScratchStorage.getCartesian3()); + return Cartesian3.fromElements(operation(left.x, right.x, test.x), operation(left.y, right.y, test.y), operation(left.z, right.z, test.z), scratchStorage.getCartesian3()); } else if (left instanceof Cartesian4 && right instanceof Cartesian4 && test instanceof Cartesian4) { - return Cartesian4.fromElements(operation(left.x, right.x, test.x), operation(left.y, right.y, test.y), operation(left.z, right.z, test.z), operation(left.w, right.w, test.w), ScratchStorage.getCartesian4()); + return Cartesian4.fromElements(operation(left.x, right.x, test.x), operation(left.y, right.y, test.y), operation(left.z, right.z, test.z), operation(left.w, right.w, test.w), scratchStorage.getCartesian4()); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Function "' + call + '" requires vector or number arguments of matching types. Arguments are ' + left + ', ' + right + ', and ' + test + '.'); - //>>includeEnd('debug'); + throw new RuntimeError('Function "' + call + '" requires vector or number arguments of matching types. Arguments are ' + left + ', ' + right + ', and ' + test + '.'); }; } @@ -363,25 +352,21 @@ define([ return Cartesian4.magnitude(left); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Function "' + call + '" requires a vector or number argument. Argument is ' + left + '.'); - //>>includeEnd('debug'); + throw new RuntimeError('Function "' + call + '" requires a vector or number argument. Argument is ' + left + '.'); } function normalize(call, left) { if (typeof left === 'number') { return 1.0; } else if (left instanceof Cartesian2) { - return Cartesian2.normalize(left, ScratchStorage.getCartesian2()); + return Cartesian2.normalize(left, scratchStorage.getCartesian2()); } else if (left instanceof Cartesian3) { - return Cartesian3.normalize(left, ScratchStorage.getCartesian3()); + return Cartesian3.normalize(left, scratchStorage.getCartesian3()); } else if (left instanceof Cartesian4) { - return Cartesian4.normalize(left, ScratchStorage.getCartesian4()); + return Cartesian4.normalize(left, scratchStorage.getCartesian4()); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Function "' + call + '" requires a vector or number argument. Argument is ' + left + '.'); - //>>includeEnd('debug'); + throw new RuntimeError('Function "' + call + '" requires a vector or number argument. Argument is ' + left + '.'); } function distance(call, left, right) { @@ -395,9 +380,7 @@ define([ return Cartesian4.distance(left, right); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Function "' + call + '" requires vector or number arguments of matching types. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); + throw new RuntimeError('Function "' + call + '" requires vector or number arguments of matching types. Arguments are ' + left + ' and ' + right + '.'); } function dot(call, left, right) { @@ -411,19 +394,15 @@ define([ return Cartesian4.dot(left, right); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Function "' + call + '" requires vector or number arguments of matching types. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); + throw new RuntimeError('Function "' + call + '" requires vector or number arguments of matching types. Arguments are ' + left + ' and ' + right + '.'); } function cross(call, left, right) { if (left instanceof Cartesian3 && right instanceof Cartesian3) { - return Cartesian3.cross(left, right, ScratchStorage.getCartesian3()); + return Cartesian3.cross(left, right, scratchStorage.getCartesian3()); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Function "' + call + '" requires vec3 arguments. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); + throw new RuntimeError('Function "' + call + '" requires vec3 arguments. Arguments are ' + left + ' and ' + right + '.'); } function Node(type, value, left, right, test) { @@ -483,11 +462,9 @@ define([ } else { result += exp.substr(0, i); var j = exp.indexOf('}'); - //>>includeStart('debug', pragmas.debug); if (j < 0) { - throw new DeveloperError('Unmatched {.'); + throw new RuntimeError('Unmatched {.'); } - //>>includeEnd('debug'); result += "czm_" + exp.substr(i + 2, j - (i + 2)); exp = exp.substr(j + 1); i = exp.indexOf('${'); @@ -525,11 +502,9 @@ define([ var object = ast.callee.object; if (call === 'test' || call === 'exec') { // Make sure this is called on a valid type - //>>includeStart('debug', pragmas.debug); if (object.callee.name !== 'regExp') { - throw new DeveloperError(call + ' is not a function.'); + throw new RuntimeError(call + ' is not a function.'); } - //>>includeEnd('debug'); if (argsLength === 0) { if (call === 'test') { return new Node(ExpressionNodeType.LITERAL_BOOLEAN, false); @@ -545,9 +520,7 @@ define([ return new Node(ExpressionNodeType.FUNCTION_CALL, call, val); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Unexpected function call "' + call + '".'); - //>>includeEnd('debug'); + throw new RuntimeError('Unexpected function call "' + call + '".'); } // Non-member function calls @@ -563,11 +536,9 @@ define([ } return new Node(ExpressionNodeType.LITERAL_COLOR, call, [val]); } else if (call === 'rgb' || call === 'hsl') { - //>>includeStart('debug', pragmas.debug); if (argsLength < 3) { - throw new DeveloperError(call + ' requires three arguments.'); + throw new RuntimeError(call + ' requires three arguments.'); } - //>>includeEnd('debug'); val = [ createRuntimeAst(expression, args[0]), createRuntimeAst(expression, args[1]), @@ -575,11 +546,9 @@ define([ ]; return new Node(ExpressionNodeType.LITERAL_COLOR, call, val); } else if (call === 'rgba' || call === 'hsla') { - //>>includeStart('debug', pragmas.debug); if (argsLength < 4) { - throw new DeveloperError(call + ' requires four arguments.'); + throw new RuntimeError(call + ' requires four arguments.'); } - //>>includeEnd('debug'); val = [ createRuntimeAst(expression, args[0]), createRuntimeAst(expression, args[1]), @@ -605,43 +574,33 @@ define([ val = createRuntimeAst(expression, args[0]); return new Node(ExpressionNodeType.UNARY, call, val); } else if (call === 'isExactClass' || call === 'isClass') { - //>>includeStart('debug', pragmas.debug); if (argsLength < 1 || argsLength > 1) { - throw new DeveloperError(call + ' requires exactly one argument.'); + throw new RuntimeError(call + ' requires exactly one argument.'); } - //>>includeEnd('debug'); val = createRuntimeAst(expression, args[0]); return new Node(ExpressionNodeType.UNARY, call, val); } else if (call === 'getExactClassName') { - //>>includeStart('debug', pragmas.debug); if (argsLength > 0) { - throw new DeveloperError(call + ' does not take any argument.'); + throw new RuntimeError(call + ' does not take any argument.'); } - //>>includeEnd('debug'); return new Node(ExpressionNodeType.UNARY, call); } else if (defined(unaryFunctions[call])) { - //>>includeStart('debug', pragmas.debug); if (argsLength !== 1) { - throw new DeveloperError(call + ' requires exactly one argument.'); + throw new RuntimeError(call + ' requires exactly one argument.'); } - //>>includeEnd('debug'); val = createRuntimeAst(expression, args[0]); return new Node(ExpressionNodeType.UNARY, call, val); } else if (defined(binaryFunctions[call])) { - //>>includeStart('debug', pragmas.debug); if (argsLength !== 2) { - throw new DeveloperError(call + ' requires exactly two arguments.'); + throw new RuntimeError(call + ' requires exactly two arguments.'); } - //>>includeEnd('debug'); left = createRuntimeAst(expression, args[0]); right = createRuntimeAst(expression, args[1]); return new Node(ExpressionNodeType.BINARY, call, left, right); } else if (defined(ternaryFunctions[call])) { - //>>includeStart('debug', pragmas.debug); if (argsLength !== 3) { - throw new DeveloperError(call + ' requires exactly three arguments.'); + throw new RuntimeError(call + ' requires exactly three arguments.'); } - //>>includeEnd('debug'); left = createRuntimeAst(expression, args[0]); right = createRuntimeAst(expression, args[1]); var test = createRuntimeAst(expression, args[2]); @@ -668,9 +627,7 @@ define([ return parseRegex(expression, ast); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Unexpected function call "' + call + '".'); - //>>includeEnd('debug'); + throw new RuntimeError('Unexpected function call "' + call + '".'); } function parseRegex(expression, ast) { @@ -690,9 +647,7 @@ define([ try { exp = new RegExp(replaceBackslashes(String(pattern._value)), flags._value); } catch (e) { - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError(e); - //>>includeEnd('debug'); + throw new RuntimeError(e); } return new Node(ExpressionNodeType.LITERAL_REGEX, exp); } @@ -704,9 +659,7 @@ define([ try { exp = new RegExp(replaceBackslashes(String(pattern._value))); } catch (e) { - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError(e); - //>>includeEnd('debug'); + throw new RuntimeError(e); } return new Node(ExpressionNodeType.LITERAL_REGEX, exp); } @@ -729,9 +682,7 @@ define([ return new Node(ExpressionNodeType.LITERAL_UNDEFINED, undefined); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError(ast.name + ' is not defined.'); - //>>includeEnd('debug'); + throw new RuntimeError(ast.name + ' is not defined.'); } function parseMathConstant(ast) { @@ -789,9 +740,7 @@ define([ if (unaryOperators.indexOf(op) > -1) { node = new Node(ExpressionNodeType.UNARY, op, child); } else { - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Unexpected operator "' + op + '".'); - //>>includeEnd('debug'); + throw new RuntimeError('Unexpected operator "' + op + '".'); } } else if (ast.type === 'BinaryExpression') { op = ast.operator; @@ -800,9 +749,7 @@ define([ if (binaryOperators.indexOf(op) > -1) { node = new Node(ExpressionNodeType.BINARY, op, left, right); } else { - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Unexpected operator "' + op + '".'); - //>>includeEnd('debug'); + throw new RuntimeError('Unexpected operator "' + op + '".'); } } else if (ast.type === 'LogicalExpression') { op = ast.operator; @@ -824,15 +771,12 @@ define([ val[i] = createRuntimeAst(expression, ast.elements[i]); } node = new Node(ExpressionNodeType.ARRAY, val); - } - //>>includeStart('debug', pragmas.debug); - else if (ast.type === 'Compound') { + } else if (ast.type === 'Compound') { // empty expression or multiple expressions - throw new DeveloperError('Provide exactly one expression.'); - } else { - throw new DeveloperError('Cannot parse expression.'); + throw new RuntimeError('Provide exactly one expression.'); + } else { + throw new RuntimeError('Cannot parse expression.'); } - //>>includeEnd('debug'); return node; } @@ -1014,14 +958,14 @@ define([ args[3].evaluate(frameState, feature), color); } - return Cartesian4.fromColor(color, ScratchStorage.getCartesian4()); + return Cartesian4.fromColor(color, scratchStorage.getCartesian4()); }; Node.prototype._evaluateLiteralVector = function(frameState, feature) { // Gather the components that make up the vector, which includes components from interior vectors. // For example vec3(1, 2, 3) or vec3(vec2(1, 2), 3) are both valid. // - // If the number of components does not equal the vector's size, then a DeveloperError is thrown - with two exceptions: + // If the number of components does not equal the vector's size, then a RuntimeError is thrown - with two exceptions: // 1. A vector may be constructed from a larger vector and drop the extra components. // 2. A vector may be constructed from a single component - vec3(1) will become vec3(1, 1, 1). // @@ -1031,7 +975,7 @@ define([ // vec3(1, 2, 3, 4) // too many components // vec2(vec4(1), 1) // too many components - var components = ScratchStorage.getArray(); + var components = scratchStorage.getArray(); var call = this._value; var args = this._left; var argsLength = args.length; @@ -1045,26 +989,21 @@ define([ components.push(value.x, value.y, value.z); } else if (value instanceof Cartesian4) { components.push(value.x, value.y, value.z, value.w); + } else { + throw new RuntimeError(call + ' argument must be a vector or number. Argument is ' + value + '.'); } - //>>includeStart('debug', pragmas.debug); - else { - throw new DeveloperError(call + ' argument must be a vector or number. Argument is ' + value + '.'); - } - //>>includeEnd('debug'); } var componentsLength = components.length; var vectorLength = parseInt(call.charAt(3)); - //>>includeStart('debug', pragmas.debug); if (componentsLength === 0) { - throw new DeveloperError('Invalid ' + call + ' constructor. No valid arguments.'); + throw new RuntimeError('Invalid ' + call + ' constructor. No valid arguments.'); } else if ((componentsLength < vectorLength) && (componentsLength > 1)) { - throw new DeveloperError('Invalid ' + call + ' constructor. Not enough arguments.'); + throw new RuntimeError('Invalid ' + call + ' constructor. Not enough arguments.'); } else if ((componentsLength > vectorLength) && (argsLength > 1)) { - throw new DeveloperError('Invalid ' + call + ' constructor. Too many arguments.'); + throw new RuntimeError('Invalid ' + call + ' constructor. Too many arguments.'); } - //>>includeEnd('debug'); if (componentsLength === 1) { // Add the same component 3 more times @@ -1073,11 +1012,11 @@ define([ } if (call === 'vec2') { - return Cartesian2.fromArray(components, 0, ScratchStorage.getCartesian2()); + return Cartesian2.fromArray(components, 0, scratchStorage.getCartesian2()); } else if (call === 'vec3') { - return Cartesian3.fromArray(components, 0, ScratchStorage.getCartesian3()); + return Cartesian3.fromArray(components, 0, scratchStorage.getCartesian3()); } else if (call === 'vec4') { - return Cartesian4.fromArray(components, 0, ScratchStorage.getCartesian4()); + return Cartesian4.fromArray(components, 0, scratchStorage.getCartesian4()); } }; @@ -1175,40 +1114,33 @@ define([ Node.prototype._evaluateNot = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if (typeof left !== 'boolean') { - throw new DeveloperError('Operator "!" requires a boolean argument. Argument is ' + left + '.'); + throw new RuntimeError('Operator "!" requires a boolean argument. Argument is ' + left + '.'); } - //>>includeEnd('debug'); return !left; }; Node.prototype._evaluateNegative = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); if (left instanceof Cartesian2) { - return Cartesian2.negate(left, ScratchStorage.getCartesian2()); + return Cartesian2.negate(left, scratchStorage.getCartesian2()); } else if (left instanceof Cartesian3) { - return Cartesian3.negate(left, ScratchStorage.getCartesian3()); + return Cartesian3.negate(left, scratchStorage.getCartesian3()); } else if (left instanceof Cartesian4) { - return Cartesian4.negate(left, ScratchStorage.getCartesian4()); + return Cartesian4.negate(left, scratchStorage.getCartesian4()); } else if (typeof left === 'number') { return -left; + } else { + throw new RuntimeError('Operator "-" requires a vector or number argument. Argument is ' + left + '.'); } - - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Operator "-" requires a vector or number argument. Argument is ' + left + '.'); - //>>includeEnd('debug'); - return -left; // eslint-disable-line no-unreachable }; Node.prototype._evaluatePositive = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if (!((left instanceof Cartesian2) || (left instanceof Cartesian3) || (left instanceof Cartesian4) || (typeof left === 'number'))) { - throw new DeveloperError('Operator "+" requires a vector or number argument. Argument is ' + left + '.'); + throw new RuntimeError('Operator "+" requires a vector or number argument. Argument is ' + left + '.'); } - //>>includeEnd('debug'); return left; }; @@ -1217,11 +1149,9 @@ define([ var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if ((typeof left !== 'number') || (typeof right !== 'number')) { - throw new DeveloperError('Operator "<" requires number arguments. Arguments are ' + left + ' and ' + right + '.'); + throw new RuntimeError('Operator "<" requires number arguments. Arguments are ' + left + ' and ' + right + '.'); } - //>>includeEnd('debug'); return left < right; }; @@ -1230,11 +1160,9 @@ define([ var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if ((typeof left !== 'number') || (typeof right !== 'number')) { - throw new DeveloperError('Operator "<=" requires number arguments. Arguments are ' + left + ' and ' + right + '.'); + throw new RuntimeError('Operator "<=" requires number arguments. Arguments are ' + left + ' and ' + right + '.'); } - //>>includeEnd('debug'); return left <= right; }; @@ -1243,11 +1171,9 @@ define([ var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if ((typeof left !== 'number') || (typeof right !== 'number')) { - throw new DeveloperError('Operator ">" requires number arguments. Arguments are ' + left + ' and ' + right + '.'); + throw new RuntimeError('Operator ">" requires number arguments. Arguments are ' + left + ' and ' + right + '.'); } - //>>includeEnd('debug'); return left > right; }; @@ -1256,22 +1182,18 @@ define([ var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if ((typeof left !== 'number') || (typeof right !== 'number')) { - throw new DeveloperError('Operator ">=" requires number arguments. Arguments are ' + left + ' and ' + right + '.'); + throw new RuntimeError('Operator ">=" requires number arguments. Arguments are ' + left + ' and ' + right + '.'); } - //>>includeEnd('debug'); return left >= right; }; Node.prototype._evaluateOr = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if (typeof left !== 'boolean') { - throw new DeveloperError('Operator "||" requires boolean arguments. First argument is ' + left + '.'); + throw new RuntimeError('Operator "||" requires boolean arguments. First argument is ' + left + '.'); } - //>>includeEnd('debug'); // short circuit the expression if (left) { @@ -1279,21 +1201,18 @@ define([ } var right = this._right.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if (typeof right !== 'boolean') { - throw new DeveloperError('Operator "||" requires boolean arguments. Second argument is ' + right + '.'); + throw new RuntimeError('Operator "||" requires boolean arguments. Second argument is ' + right + '.'); } - //>>includeEnd('debug'); + return left || right; }; Node.prototype._evaluateAnd = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if (typeof left !== 'boolean') { - throw new DeveloperError('Operator "&&" requires boolean arguments. First argument is ' + left + '.'); + throw new RuntimeError('Operator "&&" requires boolean arguments. First argument is ' + left + '.'); } - //>>includeEnd('debug'); // short circuit the expression if (!left) { @@ -1301,11 +1220,10 @@ define([ } var right = this._right.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if (typeof right !== 'boolean') { - throw new DeveloperError('Operator "&&" requires boolean arguments. Second argument is ' + right + '.'); + throw new RuntimeError('Operator "&&" requires boolean arguments. Second argument is ' + right + '.'); } - //>>includeEnd('debug'); + return left && right; }; @@ -1313,11 +1231,11 @@ define([ var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { - return Cartesian2.add(left, right, ScratchStorage.getCartesian2()); + return Cartesian2.add(left, right, scratchStorage.getCartesian2()); } else if ((right instanceof Cartesian3) && (left instanceof Cartesian3)) { - return Cartesian3.add(left, right, ScratchStorage.getCartesian3()); + return Cartesian3.add(left, right, scratchStorage.getCartesian3()); } else if ((right instanceof Cartesian4) && (left instanceof Cartesian4)) { - return Cartesian4.add(left, right, ScratchStorage.getCartesian4()); + return Cartesian4.add(left, right, scratchStorage.getCartesian4()); } else if ((typeof left === 'string') || (typeof right === 'string')) { // If only one argument is a string the other argument calls its toString function. return left + right; @@ -1325,109 +1243,89 @@ define([ return left + right; } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Operator "+" requires vector or number arguments of matching types, or at least one string argument. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); - - return left + right; // eslint-disable-line no-unreachable + throw new RuntimeError('Operator "+" requires vector or number arguments of matching types, or at least one string argument. Arguments are ' + left + ' and ' + right + '.'); }; Node.prototype._evaluateMinus = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { - return Cartesian2.subtract(left, right, ScratchStorage.getCartesian2()); + return Cartesian2.subtract(left, right, scratchStorage.getCartesian2()); } else if ((right instanceof Cartesian3) && (left instanceof Cartesian3)) { - return Cartesian3.subtract(left, right, ScratchStorage.getCartesian3()); + return Cartesian3.subtract(left, right, scratchStorage.getCartesian3()); } else if ((right instanceof Cartesian4) && (left instanceof Cartesian4)) { - return Cartesian4.subtract(left, right, ScratchStorage.getCartesian4()); + return Cartesian4.subtract(left, right, scratchStorage.getCartesian4()); } else if ((typeof left === 'number') && (typeof right === 'number')) { return left - right; } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Operator "-" requires vector or number arguments of matching types. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); - - return left - right; // eslint-disable-line no-unreachable + throw new RuntimeError('Operator "-" requires vector or number arguments of matching types. Arguments are ' + left + ' and ' + right + '.'); }; Node.prototype._evaluateTimes = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { - return Cartesian2.multiplyComponents(left, right, ScratchStorage.getCartesian2()); + return Cartesian2.multiplyComponents(left, right, scratchStorage.getCartesian2()); } else if ((right instanceof Cartesian2) && (typeof left === 'number')) { - return Cartesian2.multiplyByScalar(right, left, ScratchStorage.getCartesian2()); + return Cartesian2.multiplyByScalar(right, left, scratchStorage.getCartesian2()); } else if ((left instanceof Cartesian2) && (typeof right === 'number')) { - return Cartesian2.multiplyByScalar(left, right, ScratchStorage.getCartesian2()); + return Cartesian2.multiplyByScalar(left, right, scratchStorage.getCartesian2()); } else if ((right instanceof Cartesian3) && (left instanceof Cartesian3)) { - return Cartesian3.multiplyComponents(left, right, ScratchStorage.getCartesian3()); + return Cartesian3.multiplyComponents(left, right, scratchStorage.getCartesian3()); } else if ((right instanceof Cartesian3) && (typeof left === 'number')) { - return Cartesian3.multiplyByScalar(right, left, ScratchStorage.getCartesian3()); + return Cartesian3.multiplyByScalar(right, left, scratchStorage.getCartesian3()); } else if ((left instanceof Cartesian3) && (typeof right === 'number')) { - return Cartesian3.multiplyByScalar(left, right, ScratchStorage.getCartesian3()); + return Cartesian3.multiplyByScalar(left, right, scratchStorage.getCartesian3()); } else if ((right instanceof Cartesian4) && (left instanceof Cartesian4)) { - return Cartesian4.multiplyComponents(left, right, ScratchStorage.getCartesian4()); + return Cartesian4.multiplyComponents(left, right, scratchStorage.getCartesian4()); } else if ((right instanceof Cartesian4) && (typeof left === 'number')) { - return Cartesian4.multiplyByScalar(right, left, ScratchStorage.getCartesian4()); + return Cartesian4.multiplyByScalar(right, left, scratchStorage.getCartesian4()); } else if ((left instanceof Cartesian4) && (typeof right === 'number')) { - return Cartesian4.multiplyByScalar(left, right, ScratchStorage.getCartesian4()); + return Cartesian4.multiplyByScalar(left, right, scratchStorage.getCartesian4()); } else if ((typeof left === 'number') && (typeof right === 'number')) { return left * right; } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Operator "*" requires vector or number arguments. If both arguments are vectors they must be matching types. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); - - return left * right; // eslint-disable-line no-unreachable + throw new RuntimeError('Operator "*" requires vector or number arguments. If both arguments are vectors they must be matching types. Arguments are ' + left + ' and ' + right + '.'); }; Node.prototype._evaluateDivide = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { - return Cartesian2.divideComponents(left, right, ScratchStorage.getCartesian2()); + return Cartesian2.divideComponents(left, right, scratchStorage.getCartesian2()); } else if ((left instanceof Cartesian2) && (typeof right === 'number')) { - return Cartesian2.divideByScalar(left, right, ScratchStorage.getCartesian2()); + return Cartesian2.divideByScalar(left, right, scratchStorage.getCartesian2()); } else if ((right instanceof Cartesian3) && (left instanceof Cartesian3)) { - return Cartesian3.divideComponents(left, right, ScratchStorage.getCartesian3()); + return Cartesian3.divideComponents(left, right, scratchStorage.getCartesian3()); } else if ((left instanceof Cartesian3) && (typeof right === 'number')) { - return Cartesian3.divideByScalar(left, right, ScratchStorage.getCartesian3()); + return Cartesian3.divideByScalar(left, right, scratchStorage.getCartesian3()); } else if ((right instanceof Cartesian4) && (left instanceof Cartesian4)) { - return Cartesian4.divideComponents(left, right, ScratchStorage.getCartesian4()); + return Cartesian4.divideComponents(left, right, scratchStorage.getCartesian4()); } else if ((left instanceof Cartesian4) && (typeof right === 'number')) { - return Cartesian4.divideByScalar(left, right, ScratchStorage.getCartesian4()); + return Cartesian4.divideByScalar(left, right, scratchStorage.getCartesian4()); } else if ((typeof left === 'number') && (typeof right === 'number')) { return left / right; } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Operator "/" requires vector or number arguments of matching types, or a number as the second argument. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); - - return left / right; // eslint-disable-line no-unreachable + throw new RuntimeError('Operator "/" requires vector or number arguments of matching types, or a number as the second argument. Arguments are ' + left + ' and ' + right + '.'); }; Node.prototype._evaluateMod = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { - return Cartesian2.fromElements(left.x % right.x, left.y % right.y, ScratchStorage.getCartesian2()); + return Cartesian2.fromElements(left.x % right.x, left.y % right.y, scratchStorage.getCartesian2()); } else if ((right instanceof Cartesian3) && (left instanceof Cartesian3)) { - return Cartesian3.fromElements(left.x % right.x, left.y % right.y, left.z % right.z, ScratchStorage.getCartesian3()); + return Cartesian3.fromElements(left.x % right.x, left.y % right.y, left.z % right.z, scratchStorage.getCartesian3()); } else if ((right instanceof Cartesian4) && (left instanceof Cartesian4)) { - return Cartesian4.fromElements(left.x % right.x, left.y % right.y, left.z % right.z, left.w % right.w, ScratchStorage.getCartesian4()); + return Cartesian4.fromElements(left.x % right.x, left.y % right.y, left.z % right.z, left.w % right.w, scratchStorage.getCartesian4()); } else if ((typeof left === 'number') && (typeof right === 'number')) { return left % right; } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Operator "%" requires vector or number arguments of matching types. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); - - return left % right; // eslint-disable-line no-unreachable + throw new RuntimeError('Operator "%" requires vector or number arguments of matching types. Arguments are ' + left + ' and ' + right + '.'); }; Node.prototype._evaluateEqualsStrict = function(frameState, feature) { @@ -1455,11 +1353,9 @@ define([ Node.prototype._evaluateConditional = function(frameState, feature) { var test = this._test.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if (typeof test !== 'boolean') { - throw new DeveloperError('Conditional argument of conditional expression must be a boolean. Argument is ' + test + '.'); + throw new RuntimeError('Conditional argument of conditional expression must be a boolean. Argument is ' + test + '.'); } - //>>includeEnd('debug'); if (test) { return this._left.evaluate(frameState, feature); @@ -1511,9 +1407,7 @@ define([ try { exp = new RegExp(pattern, flags); } catch (e) { - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError(e); - //>>includeEnd('debug'); + throw new RuntimeError(e); } return exp; }; @@ -1522,11 +1416,9 @@ define([ var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if (!((left instanceof RegExp) && (typeof right === 'string'))) { - throw new DeveloperError('RegExp.test requires the first argument to be a RegExp and the second argument to be a string. Arguments are ' + left + ' and ' + right + '.'); + throw new RuntimeError('RegExp.test requires the first argument to be a RegExp and the second argument to be a string. Arguments are ' + left + ' and ' + right + '.'); } - //>>includeEnd('debug'); return left.test(right); }; @@ -1541,11 +1433,7 @@ define([ return right.test(left); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Operator "=~" requires one RegExp argument and one string argument. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); - - return false; // eslint-disable-line no-unreachable + throw new RuntimeError('Operator "=~" requires one RegExp argument and one string argument. Arguments are ' + left + ' and ' + right + '.'); }; Node.prototype._evaluateRegExpNotMatch = function(frameState, feature) { @@ -1558,22 +1446,16 @@ define([ return !(right.test(left)); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Operator "!~" requires one RegExp argument and one string argument. Arguments are ' + left + ' and ' + right + '.'); - //>>includeEnd('debug'); - - return false; // eslint-disable-line no-unreachable + throw new RuntimeError('Operator "!~" requires one RegExp argument and one string argument. Arguments are ' + left + ' and ' + right + '.'); }; Node.prototype._evaluateRegExpExec = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - //>>includeStart('debug', pragmas.debug); if (!((left instanceof RegExp) && (typeof right === 'string'))) { - throw new DeveloperError('RegExp.exec requires the first argument to be a RegExp and the second argument to be a string. Arguments are ' + left + ' and ' + right + '.'); + throw new RuntimeError('RegExp.exec requires the first argument to be a RegExp and the second argument to be a string. Arguments are ' + left + ' and ' + right + '.'); } - //>>includeEnd('debug'); var exec = left.exec(right); if (!defined(exec)) { @@ -1587,11 +1469,8 @@ define([ if ((left instanceof RegExp) || (left instanceof Cartesian2) || (left instanceof Cartesian3) || (left instanceof Cartesian4)) { return String(left); } - //>>includeStart('debug', pragmas.debug); - else { - throw new DeveloperError('Unexpected function call "' + this._value + '".'); - } - //>>includeEnd('debug'); + + throw new RuntimeError('Unexpected function call "' + this._value + '".'); }; function convertHSLToRGB(ast) { @@ -1657,12 +1536,7 @@ define([ var length = array.length; var expressions = new Array(length); for (var i = 0; i < length; ++i) { - var shader = array[i].getShaderExpression(attributePrefix, shaderState, parent); - if (!defined(shader)) { - // If any of the expressions are not valid, the array is not valid - return undefined; - } - expressions[i] = shader; + expressions[i] = array[i].getShaderExpression(attributePrefix, shaderState, parent); } return expressions; } @@ -1683,35 +1557,19 @@ define([ } else { left = this._left.getShaderExpression(attributePrefix, shaderState, this); } - if (!defined(left)) { - // If the left side is not valid shader code, then the expression is not valid - return undefined; - } } if (defined(this._right)) { right = this._right.getShaderExpression(attributePrefix, shaderState, this); - if (!defined(right)) { - // If the right side is not valid shader code, then the expression is not valid - return undefined; - } } if (defined(this._test)) { test = this._test.getShaderExpression(attributePrefix, shaderState, this); - if (!defined(test)) { - // If the test is not valid shader code, then the expression is not valid - return undefined; - } } if (isArray(this._value)) { // For ARRAY type value = getExpressionArray(this._value, attributePrefix, shaderState, this); - if (!defined(value)) { - // If the values are not valid shader code, then the expression is not valid - return undefined; - } } switch (type) { @@ -1728,11 +1586,7 @@ define([ } else if (defined(unaryFunctions[value])) { return value + '(' + left + ')'; } else if ((value === 'isNaN') || (value === 'isFinite') || (value === 'String') || (value === 'isExactClass') || (value === 'isClass') || (value === 'getExactClassName')) { - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Error generating style shader: "' + value + '" is not supported.'); - //>>includeEnd('debug'); - // Return undefined when not in debug. Tell esLint to ignore this line. - return undefined; // eslint-disable-line no-unreachable + throw new RuntimeError('Error generating style shader: "' + value + '" is not supported.'); } else if (defined(unaryFunctions[value])) { return value + '(' + left + ')'; } @@ -1772,9 +1626,7 @@ define([ } return left + '[int(' + right + ')]'; case ExpressionNodeType.FUNCTION_CALL: - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Error generating style shader: "' + value + '" is not supported.'); - //>>includeEnd('debug'); + throw new RuntimeError('Error generating style shader: "' + value + '" is not supported.'); case ExpressionNodeType.ARRAY: if (value.length === 4) { return 'vec4(' + value[0] + ', ' + value[1] + ', ' + value[2] + ', ' + value[3] + ')'; @@ -1783,24 +1635,13 @@ define([ } else if (value.length === 2) { return 'vec2(' + value[0] + ', ' + value[1] + ')'; } - //>>includeStart('debug', pragmas.debug); - else { - throw new DeveloperError('Error generating style shader: Invalid array length. Array length should be 2, 3, or 4.'); - } - //>>includeEnd('debug'); - break; // eslint-disable-line no-unreachable + throw new RuntimeError('Error generating style shader: Invalid array length. Array length should be 2, 3, or 4.'); case ExpressionNodeType.REGEX: - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Error generating style shader: Regular expressions are not supported.'); - //>>includeEnd('debug'); + throw new RuntimeError('Error generating style shader: Regular expressions are not supported.'); case ExpressionNodeType.VARIABLE_IN_STRING: - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Error generating style shader: Converting a variable to a string is not supported.'); - //>>includeEnd('debug'); + throw new RuntimeError('Error generating style shader: Converting a variable to a string is not supported.'); case ExpressionNodeType.LITERAL_NULL: - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Error generating style shader: null is not supported.'); - //>>includeEnd('debug'); + throw new RuntimeError('Error generating style shader: null is not supported.'); case ExpressionNodeType.LITERAL_BOOLEAN: return value ? 'true' : 'false'; case ExpressionNodeType.LITERAL_NUMBER: @@ -1817,9 +1658,7 @@ define([ if (defined(color)) { return colorToVec3(color); } - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Error generating style shader: String literals are not supported.'); - //>>includeEnd('debug'); + throw new RuntimeError('Error generating style shader: String literals are not supported.'); case ExpressionNodeType.LITERAL_COLOR: var args = left; if (value === 'color') { @@ -1886,13 +1725,9 @@ define([ vectorExpression += ')'; return vectorExpression; case ExpressionNodeType.LITERAL_REGEX: - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Error generating style shader: Regular expressions are not supported.'); - //>>includeEnd('debug'); + throw new RuntimeError('Error generating style shader: Regular expressions are not supported.'); case ExpressionNodeType.LITERAL_UNDEFINED: - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Error generating style shader: undefined is not supported.'); - //>>includeEnd('debug'); + throw new RuntimeError('Error generating style shader: undefined is not supported.'); case ExpressionNodeType.BUILTIN_VARIABLE: if (value === 'tiles3d_tileset_time') { return 'u_tilesetTime'; diff --git a/Source/Scene/Instanced3DModel3DTileContent.js b/Source/Scene/Instanced3DModel3DTileContent.js index c80acf8874aa..a4c347774a88 100644 --- a/Source/Scene/Instanced3DModel3DTileContent.js +++ b/Source/Scene/Instanced3DModel3DTileContent.js @@ -9,6 +9,7 @@ define([ '../Core/defineProperties', '../Core/destroyObject', '../Core/DeveloperError', + '../Core/FeatureDetection', '../Core/Ellipsoid', '../Core/getAbsoluteUri', '../Core/getBaseUri', @@ -18,6 +19,7 @@ define([ '../Core/Matrix4', '../Core/Quaternion', '../Core/RequestType', + '../Core/RuntimeError', '../Core/Transforms', '../Core/TranslationRotationScale', './Cesium3DTileBatchTable', @@ -34,6 +36,7 @@ define([ defineProperties, destroyObject, DeveloperError, + FeatureDetection, Ellipsoid, getAbsoluteUri, getBaseUri, @@ -43,6 +46,7 @@ define([ Matrix4, Quaternion, RequestType, + RuntimeError, Transforms, TranslationRotationScale, Cesium3DTileBatchTable, @@ -51,10 +55,19 @@ define([ ModelInstanceCollection) { 'use strict'; + // Bail out if the browser doesn't support typed arrays, to prevent the setup function + // from failing, since we won't be able to create a WebGL context anyway. + if (!FeatureDetection.supportsTypedArrays()) { + return {}; + } + /** * Represents the contents of a * {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/TileFormats/Instanced3DModel/README.md|Instanced 3D Model} * tile in a {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/README.md|3D Tiles} tileset. + *

+ * Implements the {@link Cesium3DTileContent} interface. + *

* * @alias Instanced3DModel3DTileContent * @constructor @@ -70,7 +83,7 @@ define([ this._features = undefined; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featurePropertiesDirty */ this.featurePropertiesDirty = false; @@ -79,7 +92,7 @@ define([ defineProperties(Instanced3DModel3DTileContent.prototype, { /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featuresLength */ featuresLength : { get : function() { @@ -88,7 +101,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#pointsLength */ pointsLength : { get : function() { @@ -97,7 +110,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#trianglesLength */ trianglesLength : { get : function() { @@ -110,7 +123,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#geometryByteLength */ geometryByteLength : { get : function() { @@ -123,7 +136,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#texturesByteLength */ texturesByteLength : { get : function() { @@ -136,7 +149,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#batchTableByteLength */ batchTableByteLength : { get : function() { @@ -145,7 +158,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#innerContents */ innerContents : { get : function() { @@ -154,7 +167,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#readyPromise */ readyPromise : { get : function() { @@ -163,7 +176,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tileset */ tileset : { get : function() { @@ -172,7 +185,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tile */ tile : { get : function() { @@ -181,7 +194,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#url */ url: { get: function() { @@ -190,7 +203,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#batchTable */ batchTable : { get : function() { @@ -211,23 +224,19 @@ define([ var view = new DataView(arrayBuffer); byteOffset += sizeOfUint32; // Skip magic - //>>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.'); + throw new RuntimeError('Only Instanced 3D Model version 1 is supported. Version ' + version + ' is not.'); } - //>>includeEnd('debug'); byteOffset += sizeOfUint32; var byteLength = view.getUint32(byteOffset, true); byteOffset += sizeOfUint32; var featureTableJsonByteLength = view.getUint32(byteOffset, true); - //>>includeStart('debug', pragmas.debug); if (featureTableJsonByteLength === 0) { - throw new DeveloperError('featureTableJsonByteLength is zero, the feature table must be defined.'); + throw new RuntimeError('featureTableJsonByteLength is zero, the feature table must be defined.'); } - //>>includeEnd('debug'); byteOffset += sizeOfUint32; var featureTableBinaryByteLength = view.getUint32(byteOffset, true); @@ -240,11 +249,9 @@ define([ byteOffset += sizeOfUint32; var gltfFormat = view.getUint32(byteOffset, true); - //>>includeStart('debug', pragmas.debug); if (gltfFormat !== 1 && gltfFormat !== 0) { - throw new DeveloperError('Only glTF format 0 (uri) or 1 (embedded) are supported. Format ' + gltfFormat + ' is not.'); + throw new RuntimeError('Only glTF format 0 (uri) or 1 (embedded) are supported. Format ' + gltfFormat + ' is not.'); } - //>>includeEnd('debug'); byteOffset += sizeOfUint32; var featureTableString = getStringFromTypedArray(uint8Array, byteOffset, featureTableJsonByteLength); @@ -258,11 +265,9 @@ define([ var instancesLength = featureTable.getGlobalProperty('INSTANCES_LENGTH'); featureTable.featuresLength = instancesLength; - //>>includeStart('debug', pragmas.debug); if (!defined(instancesLength)) { - throw new DeveloperError('Feature table global property: INSTANCES_LENGTH must be defined'); + throw new RuntimeError('Feature table global property: INSTANCES_LENGTH must be defined'); } - //>>includeEnd('debug'); var batchTableJson; var batchTableBinary; @@ -283,11 +288,9 @@ define([ content._batchTable = new Cesium3DTileBatchTable(content, instancesLength, batchTableJson, batchTableBinary); var gltfByteLength = byteStart + byteLength - byteOffset; - //>>includeStart('debug', pragmas.debug); if (gltfByteLength === 0) { - throw new DeveloperError('glTF byte length is zero, i3dm must have a glTF to instance.'); + throw new RuntimeError('glTF byte length is zero, i3dm must have a glTF to instance.'); } - //>>includeEnd('debug'); var gltfView = new Uint8Array(arrayBuffer, byteOffset, gltfByteLength); byteOffset += gltfByteLength; @@ -337,23 +340,17 @@ define([ if (!defined(position)) { position = instancePositionArray; var positionQuantized = featureTable.getProperty('POSITION_QUANTIZED', ComponentDatatype.UNSIGNED_SHORT, 3, i, propertyScratch1); - //>>includeStart('debug', pragmas.debug); if (!defined(positionQuantized)) { - throw new DeveloperError('Either POSITION or POSITION_QUANTIZED must be defined for each instance.'); + throw new RuntimeError('Either POSITION or POSITION_QUANTIZED must be defined for each instance.'); } - //>>includeEnd('debug'); var quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', ComponentDatatype.FLOAT, 3); - //>>includeStart('debug', pragmas.debug); if (!defined(quantizedVolumeOffset)) { - throw new DeveloperError('Global property: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.'); + throw new RuntimeError('Global property: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.'); } - //>>includeEnd('debug'); var quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', ComponentDatatype.FLOAT, 3); - //>>includeStart('debug', pragmas.debug); if (!defined(quantizedVolumeScale)) { - throw new DeveloperError('Global property: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.'); + throw new RuntimeError('Global property: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.'); } - //>>includeEnd('debug'); for (var j = 0; j < 3; j++) { position[j] = (positionQuantized[j] / 65535.0 * quantizedVolumeScale[j]) + quantizedVolumeOffset[j]; } @@ -369,11 +366,9 @@ define([ var normalRight = featureTable.getProperty('NORMAL_RIGHT', ComponentDatatype.FLOAT, 3, i, propertyScratch2); var hasCustomOrientation = false; if (defined(normalUp)) { - //>>includeStart('debug', pragmas.debug); if (!defined(normalRight)) { - throw new DeveloperError('To define a custom orientation, both NORMAL_UP and NORMAL_RIGHT must be defined.'); + throw new RuntimeError('To define a custom orientation, both NORMAL_UP and NORMAL_RIGHT must be defined.'); } - //>>includeEnd('debug'); Cartesian3.unpack(normalUp, 0, instanceNormalUp); Cartesian3.unpack(normalRight, 0, instanceNormalRight); hasCustomOrientation = true; @@ -381,11 +376,9 @@ define([ var octNormalUp = featureTable.getProperty('NORMAL_UP_OCT32P', ComponentDatatype.UNSIGNED_SHORT, 2, i, propertyScratch1); var octNormalRight = featureTable.getProperty('NORMAL_RIGHT_OCT32P', ComponentDatatype.UNSIGNED_SHORT, 2, i, propertyScratch2); if (defined(octNormalUp)) { - //>>includeStart('debug', pragmas.debug); if (!defined(octNormalRight)) { - throw new DeveloperError('To define a custom orientation with oct-encoded vectors, both NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P must be defined.'); + throw new RuntimeError('To define a custom orientation with oct-encoded vectors, both NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P must be defined.'); } - //>>includeEnd('debug'); AttributeCompression.octDecodeInRange(octNormalUp[0], octNormalUp[1], 65535, instanceNormalUp); AttributeCompression.octDecodeInRange(octNormalRight[0], octNormalRight[1], 65535, instanceNormalRight); hasCustomOrientation = true; @@ -452,14 +445,14 @@ define([ } /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#hasProperty */ Instanced3DModel3DTileContent.prototype.hasProperty = function(batchId, name) { return this._batchTable.hasProperty(batchId, name); }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#getFeature */ Instanced3DModel3DTileContent.prototype.getFeature = function(batchId) { var featuresLength = this.featuresLength; @@ -474,7 +467,7 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyDebugSettings */ Instanced3DModel3DTileContent.prototype.applyDebugSettings = function(enabled, color) { color = enabled ? color : Color.WHITE; @@ -482,14 +475,14 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyStyle */ Instanced3DModel3DTileContent.prototype.applyStyle = function(frameState, style) { this._batchTable.applyStyle(frameState, style); }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#update */ Instanced3DModel3DTileContent.prototype.update = function(tileset, frameState) { var commandStart = frameState.commandList.length; @@ -511,14 +504,14 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#isDestroyed */ Instanced3DModel3DTileContent.prototype.isDestroyed = function() { return false; }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#destroy */ Instanced3DModel3DTileContent.prototype.destroy = function() { this._modelInstanceCollection = this._modelInstanceCollection && this._modelInstanceCollection.destroy(); diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index dec4a918b8e3..ada2e26973d2 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -54,6 +54,7 @@ define([ '../ThirdParty/gltfDefaults', '../ThirdParty/Uri', '../ThirdParty/when', + './AttributeType', './Axis', './BlendingState', './ColorBlendMode', @@ -124,6 +125,7 @@ define([ gltfDefaults, Uri, when, + AttributeType, Axis, BlendingState, ColorBlendMode, @@ -3265,19 +3267,19 @@ define([ var uniformVariable = 'gltf_u_dec_' + attribute.toLowerCase(); switch (a.type) { - case 'SCALAR': + case AttributeType.SCALAR: uniformMap[uniformVariable] = getMat2UniformFunction(decodeMatrix, model).func; setUniforms[uniformVariable] = true; break; - case 'VEC2': + case AttributeType.VEC2: uniformMap[uniformVariable] = getMat3UniformFunction(decodeMatrix, model).func; setUniforms[uniformVariable] = true; break; - case 'VEC3': + case AttributeType.VEC3: uniformMap[uniformVariable] = getMat4UniformFunction(decodeMatrix, model).func; setUniforms[uniformVariable] = true; break; - case 'VEC4': + case AttributeType.VEC4: // VEC4 attributes are split into scale and translate because there is no mat5 in GLSL var uniformVariableScale = uniformVariable + '_scale'; var uniformVariableTranslate = uniformVariable + '_translate'; diff --git a/Source/Scene/ModelAnimationCache.js b/Source/Scene/ModelAnimationCache.js index ddaf05142bb1..ad78f54b5f18 100644 --- a/Source/Scene/ModelAnimationCache.js +++ b/Source/Scene/ModelAnimationCache.js @@ -7,6 +7,7 @@ define([ '../Core/Quaternion', '../Core/QuaternionSpline', '../Core/WebGLConstants', + './AttributeType', './getBinaryAccessor' ], function( Cartesian3, @@ -16,6 +17,7 @@ define([ Quaternion, QuaternionSpline, WebGLConstants, + AttributeType, getBinaryAccessor) { 'use strict'; @@ -70,15 +72,15 @@ define([ var typedArray = getBinaryAccessor(accessor).createArrayBufferView(buffer.buffer, buffer.byteOffset + accessor.byteOffset, count); var i; - if ((componentType === WebGLConstants.FLOAT) && (type === 'SCALAR')) { + if ((componentType === WebGLConstants.FLOAT) && (type === AttributeType.SCALAR)) { values = typedArray; } - else if ((componentType === WebGLConstants.FLOAT) && (type === 'VEC3')) { + else if ((componentType === WebGLConstants.FLOAT) && (type === AttributeType.VEC3)) { values = new Array(count); for (i = 0; i < count; ++i) { values[i] = Cartesian3.fromArray(typedArray, 3 * i); } - } else if ((componentType === WebGLConstants.FLOAT) && (type === 'VEC4')) { + } else if ((componentType === WebGLConstants.FLOAT) && (type === AttributeType.VEC4)) { values = new Array(count); for (i = 0; i < count; ++i) { var byteOffset = 4 * i; @@ -135,12 +137,12 @@ define([ var type = accessor.type; if (sampler.interpolation === 'LINEAR') { - if ((componentType === WebGLConstants.FLOAT) && (type === 'VEC3')) { + if ((componentType === WebGLConstants.FLOAT) && (type === AttributeType.VEC3)) { spline = new LinearSpline({ times : times, points : controlPoints }); - } else if ((componentType === WebGLConstants.FLOAT) && (type === 'VEC4')) { + } else if ((componentType === WebGLConstants.FLOAT) && (type === AttributeType.VEC4)) { spline = new QuaternionSpline({ times : times, points : controlPoints @@ -183,7 +185,7 @@ define([ var typedArray = getBinaryAccessor(accessor).createArrayBufferView(buffer.buffer, buffer.byteOffset + accessor.byteOffset, count); matrices = new Array(count); - if ((componentType === WebGLConstants.FLOAT) && (type === 'MAT4')) { + if ((componentType === WebGLConstants.FLOAT) && (type === AttributeType.MAT4)) { for (var i = 0; i < count; ++i) { matrices[i] = Matrix4.fromArray(typedArray, 16 * i); } diff --git a/Source/Scene/ModelInstanceCollection.js b/Source/Scene/ModelInstanceCollection.js index 865dffd16699..c3a26c5614c0 100644 --- a/Source/Scene/ModelInstanceCollection.js +++ b/Source/Scene/ModelInstanceCollection.js @@ -12,6 +12,7 @@ define([ '../Core/DeveloperError', '../Core/Matrix4', '../Core/PrimitiveType', + '../Core/RuntimeError', '../Core/Transforms', '../Renderer/Buffer', '../Renderer/BufferUsage', @@ -36,6 +37,7 @@ define([ DeveloperError, Matrix4, PrimitiveType, + RuntimeError, Transforms, Buffer, BufferUsage, @@ -114,12 +116,12 @@ define([ this._instances = createInstances(this, options.instances); - // When the model instance collection is backed by an instanced 3d-tile, + // When the model instance collection is backed by an i3dm tile, // use its batch table resources to modify the shaders, attributes, and uniform maps. this._batchTable = options.batchTable; this._model = undefined; - this._vertexBufferData = undefined; // Hold onto the vertex buffer data when dynamic is true + this._vertexBufferTypedArray = undefined; // Hold onto the vertex buffer contents when dynamic is true this._vertexBuffer = undefined; this._batchIdBuffer = undefined; this._instancedUniformsByProgram = undefined; @@ -252,12 +254,10 @@ define([ if (supportedSemantics.indexOf(semantic) > -1) { uniformMap[uniformName] = semantic; } else { - //>>includeStart('debug', pragmas.debug); - throw new DeveloperError('Shader program cannot be optimized for instancing. ' + + throw new RuntimeError('Shader program cannot be optimized for instancing. ' + 'Parameter "' + parameter + '" in program "' + programName + '" uses unsupported semantic "' + semantic + '"' ); - //>>includeEnd('debug'); } } } @@ -471,19 +471,19 @@ define([ }; } - function getVertexBufferData(collection) { + function getVertexBufferTypedArray(collection) { var instances = collection._instances; var instancesLength = collection.length; var collectionCenter = collection._center; var vertexSizeInFloats = 12; - var bufferData = collection._vertexBufferData; + var bufferData = collection._vertexBufferTypedArray; if (!defined(bufferData)) { bufferData = new Float32Array(instancesLength * vertexSizeInFloats); } if (collection._dynamic) { // Hold onto the buffer data so we don't have to allocate new memory every frame. - collection._vertexBufferData = bufferData; + collection._vertexBufferTypedArray = bufferData; } for (var i = 0; i < instancesLength; ++i) { @@ -553,17 +553,17 @@ define([ }); } - var vertexBufferData = getVertexBufferData(collection); + var vertexBufferTypedArray = getVertexBufferTypedArray(collection); collection._vertexBuffer = Buffer.createVertexBuffer({ context : context, - typedArray : vertexBufferData, + typedArray : vertexBufferTypedArray, usage : dynamic ? BufferUsage.STREAM_DRAW : BufferUsage.STATIC_DRAW }); } function updateVertexBuffer(collection) { - var vertexBufferData = getVertexBufferData(collection); - collection._vertexBuffer.copyFromArrayView(vertexBufferData); + var vertexBufferTypedArray = getVertexBufferTypedArray(collection); + collection._vertexBuffer.copyFromArrayView(vertexBufferTypedArray); } function createPickIds(collection, context) { @@ -879,6 +879,10 @@ define([ } ModelInstanceCollection.prototype.update = function(frameState) { + if (frameState.mode === SceneMode.MORPHING) { + return; + } + if (!this.show) { return; } diff --git a/Source/Scene/PointCloud3DTileContent.js b/Source/Scene/PointCloud3DTileContent.js index f7497eb5101d..5bd4e5e0318c 100644 --- a/Source/Scene/PointCloud3DTileContent.js +++ b/Source/Scene/PointCloud3DTileContent.js @@ -10,10 +10,12 @@ define([ '../Core/defineProperties', '../Core/destroyObject', '../Core/DeveloperError', + '../Core/FeatureDetection', '../Core/getStringFromTypedArray', '../Core/Matrix4', '../Core/oneTimeWarning', '../Core/PrimitiveType', + '../Core/RuntimeError', '../Core/Transforms', '../Renderer/Buffer', '../Renderer/BufferUsage', @@ -41,10 +43,12 @@ define([ defineProperties, destroyObject, DeveloperError, + FeatureDetection, getStringFromTypedArray, Matrix4, oneTimeWarning, PrimitiveType, + RuntimeError, Transforms, Buffer, BufferUsage, @@ -63,10 +67,19 @@ define([ ShadowMode) { 'use strict'; + // Bail out if the browser doesn't support typed arrays, to prevent the setup function + // from failing, since we won't be able to create a WebGL context anyway. + if (!FeatureDetection.supportsTypedArrays()) { + return {}; + } + /** * Represents the contents of a * {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/TileFormats/PointCloud/README.md|Points} * tile in a {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/README.md|3D Tiles} tileset. + *

+ * Implements the {@link Cesium3DTileContent} interface. + *

* * @alias PointCloud3DTileContent * @constructor @@ -121,7 +134,7 @@ define([ this._features = undefined; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featurePropertiesDirty */ this.featurePropertiesDirty = false; @@ -130,7 +143,7 @@ define([ defineProperties(PointCloud3DTileContent.prototype, { /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featuresLength */ featuresLength : { get : function() { @@ -142,7 +155,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#pointsLength */ pointsLength : { get : function() { @@ -151,7 +164,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#trianglesLength */ trianglesLength : { get : function() { @@ -160,7 +173,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#geometryByteLength */ geometryByteLength : { get : function() { @@ -169,7 +182,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#texturesByteLength */ texturesByteLength : { get : function() { @@ -178,7 +191,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#batchTableByteLength */ batchTableByteLength : { get : function() { @@ -190,7 +203,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#innerContents */ innerContents : { get : function() { @@ -199,7 +212,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#readyPromise */ readyPromise : { get : function() { @@ -208,7 +221,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tileset */ tileset : { get : function() { @@ -217,7 +230,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tile */ tile : { get : function() { @@ -226,7 +239,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#url */ url : { get : function() { @@ -235,7 +248,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#batchTable */ batchTable : { get : function() { @@ -253,23 +266,19 @@ define([ var view = new DataView(arrayBuffer); byteOffset += sizeOfUint32; // Skip magic - //>>includeStart('debug', pragmas.debug); var version = view.getUint32(byteOffset, true); if (version !== 1) { - throw new DeveloperError('Only Point Cloud tile version 1 is supported. Version ' + version + ' is not.'); + throw new RuntimeError('Only Point Cloud tile version 1 is supported. Version ' + version + ' is not.'); } - //>>includeEnd('debug'); byteOffset += sizeOfUint32; // Skip byteLength byteOffset += sizeOfUint32; var featureTableJsonByteLength = view.getUint32(byteOffset, true); - //>>includeStart('debug', pragmas.debug); if (featureTableJsonByteLength === 0) { - throw new DeveloperError('Feature table must have a byte length greater than zero'); + throw new RuntimeError('Feature table must have a byte length greater than zero'); } - //>>includeEnd('debug'); byteOffset += sizeOfUint32; var featureTableBinaryByteLength = view.getUint32(byteOffset, true); @@ -308,11 +317,9 @@ define([ var pointsLength = featureTable.getGlobalProperty('POINTS_LENGTH'); featureTable.featuresLength = pointsLength; - //>>includeStart('debug', pragmas.debug); if (!defined(pointsLength)) { - throw new DeveloperError('Feature table global property: POINTS_LENGTH must be defined'); + throw new RuntimeError('Feature table global property: POINTS_LENGTH must be defined'); } - //>>includeEnd('debug'); // Get the positions var positions; @@ -329,27 +336,21 @@ define([ isQuantized = true; var quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', ComponentDatatype.FLOAT, 3); - //>>includeStart('debug', pragmas.debug); if (!defined(quantizedVolumeScale)) { - throw new DeveloperError('Global property: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.'); + throw new RuntimeError('Global property: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.'); } - //>>includeEnd('debug'); content._quantizedVolumeScale = Cartesian3.unpack(quantizedVolumeScale); var quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', ComponentDatatype.FLOAT, 3); - //>>includeStart('debug', pragmas.debug); if (!defined(quantizedVolumeOffset)) { - throw new DeveloperError('Global property: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.'); + throw new RuntimeError('Global property: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.'); } - //>>includeEnd('debug'); content._quantizedVolumeOffset = Cartesian3.unpack(quantizedVolumeOffset); } - //>>includeStart('debug', pragmas.debug); if (!defined(positions)) { - throw new DeveloperError('Either POSITION or POSITION_QUANTIZED must be defined.'); + throw new RuntimeError('Either POSITION or POSITION_QUANTIZED must be defined.'); } - //>>includeEnd('debug'); // Get the colors var colors; @@ -391,11 +392,9 @@ define([ batchIds = featureTable.getPropertyArray('BATCH_ID', ComponentDatatype.UNSIGNED_SHORT, 1); var batchLength = featureTable.getGlobalProperty('BATCH_LENGTH'); - //>>includeStart('debug', pragmas.debug); if (!defined(batchLength)) { - throw new DeveloperError('Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.'); + throw new RuntimeError('Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.'); } - //>>includeEnd('debug'); if (defined(batchTableBinary)) { // Copy the batchTableBinary section and let the underlying ArrayBuffer be freed @@ -837,11 +836,9 @@ define([ // Split default properties from user properties var userProperties = styleableProperties.filter(function(property) { return defaultProperties.indexOf(property) === -1; }); - //>>includeStart('debug', pragmas.debug); if (usesNormalSemantic && !hasNormals) { - throw new DeveloperError('Style references the NORMAL semantic but the point cloud does not have normals'); + throw new RuntimeError('Style references the NORMAL semantic but the point cloud does not have normals'); } - //>>includeEnd('debug'); // Disable vertex attributes that aren't used in the style, enable attributes that are var styleableShaderAttributes = content._styleableShaderAttributes; @@ -880,11 +877,9 @@ define([ for (i = 0; i < length; ++i) { name = userProperties[i]; attribute = styleableShaderAttributes[name]; - //>>includeStart('debug', pragmas.debug); if (!defined(attribute)) { - throw new DeveloperError('Style references a property "' + name + '" that does not exist or is not styleable.'); + throw new RuntimeError('Style references a property "' + name + '" that does not exist or is not styleable.'); } - //>>includeEnd('debug'); var componentCount = attribute.componentCount; var attributeName = 'czm_tiles3d_style_' + name; @@ -1080,13 +1075,8 @@ define([ // Check if the shader compiles correctly. If not there is likely a syntax error with the style. drawCommand.shaderProgram._bind(); } catch (error) { - //>>includeStart('debug', pragmas.debug); // Turn the RuntimeError into a DeveloperError and rephrase it. - throw new DeveloperError('Error generating style shader: this may be caused by a type mismatch, index out-of-bounds, or other syntax error.'); - //>>includeEnd('debug'); - - // In release silently ignore and recreate the shader without a style. Tell esLint to ignore this line. - createShaders(content, frameState, undefined); // eslint-disable-line no-unreachable + throw new RuntimeError('Error generating style shader: this may be caused by a type mismatch, index out-of-bounds, or other syntax error.'); } } @@ -1103,7 +1093,7 @@ define([ } /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#hasProperty */ PointCloud3DTileContent.prototype.hasProperty = function(batchId, name) { if (defined(this._batchTable)) { @@ -1118,7 +1108,7 @@ define([ * In this context a feature refers to a group of points that share the same BATCH_ID. * For example all the points that represent a door in a house point cloud would be a feature. * - * Features are backed by a batch table, and can be colored, shown/hidden, picked, etc like features + * Features are backed by a batch table and can be colored, shown/hidden, picked, etc like features * in b3dm and i3dm. * * When the BATCH_ID semantic is omitted and the point cloud stores per-point properties, they @@ -1139,14 +1129,14 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyDebugSettings */ PointCloud3DTileContent.prototype.applyDebugSettings = function(enabled, color) { this._highlightColor = enabled ? color : Color.WHITE; }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyStyle */ PointCloud3DTileContent.prototype.applyStyle = function(frameState, style) { if (defined(this._batchTable)) { @@ -1160,7 +1150,7 @@ define([ var scratchComputedMatrixIn2D = new Matrix4(); /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#update */ PointCloud3DTileContent.prototype.update = function(tileset, frameState) { var modelMatrix = this._tile.computedTransform; @@ -1243,14 +1233,14 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#isDestroyed */ PointCloud3DTileContent.prototype.isDestroyed = function() { return false; }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#destroy */ PointCloud3DTileContent.prototype.destroy = function() { var command = this._drawCommand; diff --git a/Source/Scene/TileBoundingSphere.js b/Source/Scene/TileBoundingSphere.js index bce9e30bbaf0..2f99c5e4d2e7 100644 --- a/Source/Scene/TileBoundingSphere.js +++ b/Source/Scene/TileBoundingSphere.js @@ -130,8 +130,6 @@ define([ * * @param {Cartesian3} center The center of the bounding sphere. * @param {Number} radius The radius of the bounding sphere. - * - * @private */ TileBoundingSphere.prototype.update = function(center, radius) { Cartesian3.clone(center, this._boundingSphere.center); @@ -143,8 +141,6 @@ define([ * * @param {Color} color The desired color of the primitive's mesh * @return {Primitive} - * - * @private */ TileBoundingSphere.prototype.createDebugVolume = function(color) { //>>includeStart('debug', pragmas.debug); diff --git a/Source/Scene/TileOrientedBoundingBox.js b/Source/Scene/TileOrientedBoundingBox.js index 8cb504880468..06943b54898a 100644 --- a/Source/Scene/TileOrientedBoundingBox.js +++ b/Source/Scene/TileOrientedBoundingBox.js @@ -86,6 +86,17 @@ define([ return Math.sqrt(this._orientedBoundingBox.distanceSquaredTo(frameState.camera.positionWC)); }; + /** + * Calculates the distance between the tile's center and the camera. + * + * @param {FrameState} frameState The frame state. + * @return {Number} The distance between the tile's center and the camera, in meters. + */ + TileOrientedBoundingBox.prototype.distanceFromCenterToCamera = function(frameState) { + DeveloperError.throwInstantiationError(); + }; + + /** * Determines which side of a plane this box is located. * @@ -109,8 +120,6 @@ define([ * @param {Matrix3} halfAxes The three orthogonal half-axes of the bounding box. * Equivalently, the transformation matrix, to rotate and scale a 2x2x2 * cube centered at the origin. - * - * @private */ TileOrientedBoundingBox.prototype.update = function(center, halfAxes) { Cartesian3.clone(center, this._orientedBoundingBox.center); @@ -123,8 +132,6 @@ define([ * * @param {Color} color The desired color of the primitive's mesh * @return {Primitive} - * - * @private */ TileOrientedBoundingBox.prototype.createDebugVolume = function(color) { //>>includeStart('debug', pragmas.debug); diff --git a/Source/Scene/Tileset3DTileContent.js b/Source/Scene/Tileset3DTileContent.js index 77c7f25f247c..e258f23c577a 100644 --- a/Source/Scene/Tileset3DTileContent.js +++ b/Source/Scene/Tileset3DTileContent.js @@ -3,15 +3,15 @@ define([ '../Core/defaultValue', '../Core/defineProperties', '../Core/destroyObject', - '../Core/DeveloperError', '../Core/getStringFromTypedArray', + '../Core/RuntimeError', '../ThirdParty/when' ], function( defaultValue, defineProperties, destroyObject, - DeveloperError, getStringFromTypedArray, + RuntimeError, when) { 'use strict'; @@ -19,6 +19,9 @@ define([ * Represents content for a tile in a * {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/README.md|3D Tiles} tileset whose * content points to another 3D Tiles tileset. + *

+ * Implements the {@link Cesium3DTileContent} interface. + *

* * @alias Tileset3DTileContent * @constructor @@ -32,7 +35,7 @@ define([ this._readyPromise = when.defer(); /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featurePropertiesDirty */ this.featurePropertiesDirty = false; @@ -41,7 +44,7 @@ define([ defineProperties(Tileset3DTileContent.prototype, { /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#featuresLength */ featuresLength : { get : function() { @@ -50,7 +53,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#pointsLength */ pointsLength : { get : function() { @@ -59,7 +62,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#trianglesLength */ trianglesLength : { get : function() { @@ -68,7 +71,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#geometryByteLength */ geometryByteLength : { get : function() { @@ -77,7 +80,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#texturesByteLength */ texturesByteLength : { get : function() { @@ -86,7 +89,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#batchTableByteLength */ batchTableByteLength : { get : function() { @@ -95,7 +98,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#innerContents */ innerContents : { get : function() { @@ -104,7 +107,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#readyPromise */ readyPromise : { get : function() { @@ -113,7 +116,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tileset */ tileset : { get : function() { @@ -122,7 +125,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#tile */ tile : { get : function() { @@ -131,7 +134,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#url */ url : { get : function() { @@ -140,7 +143,7 @@ define([ }, /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#batchTable */ batchTable : { get : function() { @@ -158,7 +161,7 @@ define([ try { tilesetJson = JSON.parse(jsonString); } catch (error) { - content._readyPromise.reject(new DeveloperError('Invalid tile content.')); + content._readyPromise.reject(new RuntimeError('Invalid tile content.')); return; } @@ -183,32 +186,32 @@ define([ }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyDebugSettings */ Tileset3DTileContent.prototype.applyDebugSettings = function(enabled, color) { }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#applyStyle */ Tileset3DTileContent.prototype.applyStyle = function(frameState, style) { }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#update */ Tileset3DTileContent.prototype.update = function(tileset, frameState) { }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#isDestroyed */ Tileset3DTileContent.prototype.isDestroyed = function() { return false; }; /** - * Part of the {@link Cesium3DTileContent} interface. + * @inheritdoc Cesium3DTileContent#destroy */ Tileset3DTileContent.prototype.destroy = function() { return destroyObject(this); diff --git a/Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspector.js b/Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspector.js index 60d49a386750..8c90f59d6a67 100644 --- a/Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspector.js +++ b/Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspector.js @@ -19,80 +19,6 @@ define([ Cesium3DTilesInspectorViewModel) { 'use strict'; - function makeSection(name, visibleProp, toggleProp, contents) { - var toggle = document.createElement('span'); - toggle.className = 'cesium-cesiumInspector-toggleSwitch'; - toggle.setAttribute('data-bind', 'text: ' + visibleProp + ' ? "-" : "+", click: ' + toggleProp); - - var header = document.createElement('div'); - header.className = 'cesium-cesiumInspector-sectionHeader'; - header.appendChild(toggle); - header.appendChild(document.createTextNode(name)); - - var section = document.createElement('div'); - section.className = 'cesium-cesiumInspector-section'; - section.setAttribute('data-bind', 'css: {"cesium-cesiumInspector-show" : ' + visibleProp + ', "cesium-cesiumInspector-hide" : !' + visibleProp + '}'); - section.appendChild(contents); - - var panel = document.createElement('div'); - panel.className = 'cesium-cesiumInspector-dropDown'; - panel.appendChild(header); - panel.appendChild(section); - - return panel; - } - - function makeCheckbox(property, text) { - var checkbox = document.createElement('input'); - checkbox.type = 'checkbox'; - checkbox.setAttribute('data-bind', 'checked: ' + property); - - var container = document.createElement('div'); - container.appendChild(checkbox); - container.appendChild(document.createTextNode(text)); - - return container; - } - - function makeRangeInput(property, min, max, step, text, displayProperty) { - displayProperty = defaultValue(displayProperty, property); - var input = document.createElement('input'); - input.setAttribute('data-bind', 'value: ' + displayProperty); - input.type = 'number'; - - var slider = document.createElement('input'); - slider.type = 'range'; - slider.min = min; - slider.max = max; - slider.step = step; - slider.setAttribute('data-bind', 'valueUpdate: "input", value: ' + property); - - var wrapper = document.createElement('div'); - wrapper.appendChild(slider); - - var container = document.createElement('div'); - container.className = 'cesium-cesiumInspector-slider'; - container.appendChild(document.createTextNode(text)); - container.appendChild(input); - container.appendChild(wrapper); - - return container; - } - - function makeButton(action, text, active) { - var button = document.createElement('button'); - button.type = 'button'; - button.textContent = text; - button.className = 'cesium-cesiumInspector-pickButton'; - var binding = 'click: ' + action; - if (defined(active)) { - binding += ', css: {"cesium-cesiumInspector-pickButtonHighlight" : ' + active + '}'; - } - button.setAttribute('data-bind', binding); - - return button; - } - /** * Inspector widget to aid in debugging 3D Tiles * @@ -280,5 +206,79 @@ define([ return destroyObject(this); }; + function makeSection(name, visibleProp, toggleProp, contents) { + var toggle = document.createElement('span'); + toggle.className = 'cesium-cesiumInspector-toggleSwitch'; + toggle.setAttribute('data-bind', 'text: ' + visibleProp + ' ? "-" : "+", click: ' + toggleProp); + + var header = document.createElement('div'); + header.className = 'cesium-cesiumInspector-sectionHeader'; + header.appendChild(toggle); + header.appendChild(document.createTextNode(name)); + + var section = document.createElement('div'); + section.className = 'cesium-cesiumInspector-section'; + section.setAttribute('data-bind', 'css: {"cesium-cesiumInspector-show" : ' + visibleProp + ', "cesium-cesiumInspector-hide" : !' + visibleProp + '}'); + section.appendChild(contents); + + var panel = document.createElement('div'); + panel.className = 'cesium-cesiumInspector-dropDown'; + panel.appendChild(header); + panel.appendChild(section); + + return panel; + } + + function makeCheckbox(property, text) { + var checkbox = document.createElement('input'); + checkbox.type = 'checkbox'; + checkbox.setAttribute('data-bind', 'checked: ' + property); + + var container = document.createElement('div'); + container.appendChild(checkbox); + container.appendChild(document.createTextNode(text)); + + return container; + } + + function makeRangeInput(property, min, max, step, text, displayProperty) { + displayProperty = defaultValue(displayProperty, property); + var input = document.createElement('input'); + input.setAttribute('data-bind', 'value: ' + displayProperty); + input.type = 'number'; + + var slider = document.createElement('input'); + slider.type = 'range'; + slider.min = min; + slider.max = max; + slider.step = step; + slider.setAttribute('data-bind', 'valueUpdate: "input", value: ' + property); + + var wrapper = document.createElement('div'); + wrapper.appendChild(slider); + + var container = document.createElement('div'); + container.className = 'cesium-cesiumInspector-slider'; + container.appendChild(document.createTextNode(text)); + container.appendChild(input); + container.appendChild(wrapper); + + return container; + } + + function makeButton(action, text, active) { + var button = document.createElement('button'); + button.type = 'button'; + button.textContent = text; + button.className = 'cesium-cesiumInspector-pickButton'; + var binding = 'click: ' + action; + if (defined(active)) { + binding += ', css: {"cesium-cesiumInspector-pickButtonHighlight" : ' + active + '}'; + } + button.setAttribute('data-bind', binding); + + return button; + } + return Cesium3DTilesInspector; }); diff --git a/Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspectorViewModel.js b/Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspectorViewModel.js index efb1b48589cb..0e7687bfb609 100644 --- a/Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspectorViewModel.js +++ b/Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspectorViewModel.js @@ -78,11 +78,11 @@ define([ // --- Cache/loading statistics '
  • Requests: ' + statistics.numberOfPendingRequests.toLocaleString() + '
  • ' + '
  • Attempted: ' + statistics.numberOfAttemptedRequests.toLocaleString() + '
  • ' + - '
  • Processing: ' + statistics.numberProcessing.toLocaleString() + '
  • ' + - '
  • Content Ready: ' + statistics.numberContentReady.toLocaleString() + '
  • ' + + '
  • Processing: ' + statistics.numberOfTilesProcessing.toLocaleString() + '
  • ' + + '
  • Content Ready: ' + statistics.numberOfTilesWithContentReady.toLocaleString() + '
  • ' + // Total number of tiles includes tiles without content, so "Ready" may never reach // "Total." Total also will increase when a tile with a tileset.json content is loaded. - '
  • Total: ' + statistics.numberTotal.toLocaleString() + '
  • '; + '
  • Total: ' + statistics.numberOfTilesTotal.toLocaleString() + '
  • '; s += ''; s += '