From e862db599c56e582c9bab424a0bedd0b1637bfb0 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 2 Aug 2016 10:45:46 -0400 Subject: [PATCH] Added back deprecated properties --- .../gallery/development/Shadows.html | 18 ++----- CHANGES.md | 1 - Source/DataSources/CzmlDataSource.js | 2 + Source/DataSources/ModelGraphics.js | 28 ++++++++++ Source/DataSources/ModelVisualizer.js | 11 +++- Source/Scene/Globe.js | 42 +++++++++++++++ Source/Scene/Model.js | 54 ++++++++++++++++++- Source/Scene/Primitive.js | 50 ++++++++++++++++- Source/Scene/ShadowMode.js | 17 +++++- Source/Widgets/CesiumWidget/CesiumWidget.js | 10 +++- Source/Widgets/Viewer/Viewer.js | 9 +++- 11 files changed, 220 insertions(+), 22 deletions(-) diff --git a/Apps/Sandcastle/gallery/development/Shadows.html b/Apps/Sandcastle/gallery/development/Shadows.html index fcabf8475502..2bd2f4c3a484 100644 --- a/Apps/Sandcastle/gallery/development/Shadows.html +++ b/Apps/Sandcastle/gallery/development/Shadows.html @@ -358,18 +358,6 @@ freeformLightCamera.lookAt(center, offset); } -function getShadowMode(castShadows, receiveShadows) { - if (castShadows && receiveShadows) { - return Cesium.ShadowMode.ENABLED; - } else if (castShadows) { - return Cesium.ShadowMode.CAST_ONLY; - } else if (receiveShadows) { - return Cesium.ShadowMode.RECEIVE_ONLY; - } else { - return Cesium.ShadowMode.DISABLED; - } -} - function updateSettings() { shadowMap.maximumDistance = Number(viewModel.distance); shadowMap._pointLightRadius = Number(viewModel.radius); @@ -402,7 +390,7 @@ // Force all derived commands to update shadowMap.dirty = true; - globe.shadows = getShadowMode(viewModel.terrainCast, viewModel.terrainReceive); + globe.shadows = Cesium.ShadowMode.fromCastReceive(viewModel.terrainCast, viewModel.terrainReceive); globe.show = viewModel.globe; scene.skyAtmosphere.show = viewModel.globe; } @@ -721,7 +709,7 @@ if (Cesium.defined(picked) && Cesium.defined(picked.primitive)) { var castShadows = Cesium.ShadowMode.castShadows(picked.primitive.shadows); var receiveShadows = Cesium.ShadowMode.receiveShadows(picked.primitive.shadows); - picked.primitive.shadows = getShadowMode(!castShadows, receiveShadows); + picked.primitive.shadows = Cesium.ShadowMode.fromCastReceive(!castShadows, receiveShadows); } }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK); @@ -731,7 +719,7 @@ if (Cesium.defined(picked)) { var castShadows = Cesium.ShadowMode.castShadows(picked.primitive.shadows); var receiveShadows = Cesium.ShadowMode.receiveShadows(picked.primitive.shadows); - picked.primitive.shadows = getShadowMode(castShadows, !receiveShadows); + picked.primitive.shadows = Cesium.ShadowMode.fromCastReceive(castShadows, !receiveShadows); } }, Cesium.ScreenSpaceEventType.MIDDLE_DOUBLE_CLICK); diff --git a/CHANGES.md b/CHANGES.md index 9bfc68a726e1..9fd26c02ec75 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,7 +6,6 @@ Change Log * Deprecated * Deprecated `castShadows` and `receiveShadows` properties from `Model`, `Primitive`, and `Globe`. They will be removed in 1.26. Use `shadows` instead with the `ShadowMode` enum, e.g. `model.shadows = ShadowMode.ENABLED`. * `Viewer.terrainShadows` now uses the `ShadowMode` enum instead of a Boolean, e.g. `viewer.terrainShadows = ShadowMode.RECEIVE_ONLY`. Boolean support will be dropped in 1.26. - * Entity `model.shadows` now uses the `ShadowMode` enum instead of a Boolean, e.g. `entity.model.shadows = ShadowMode.ENABLED`. Boolean support will be dropped in 1.26. * Added `shadows` property to the entity API for `Box`, `Corridor`, `Cylinder`, `Ellipse`, `Ellipsoid`, `Polygon`, `Polyline`, `PoylineVolume`, `Rectangle`, and `Wall`. [#4005](https://github.com/AnalyticalGraphicsInc/cesium/pull/4005) ### 1.24 - 2016-08-01 diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index c0e24b9180d8..706049c9fc25 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -1409,6 +1409,8 @@ define([ processPacketData(Number, model, 'maximumScale', modelData.maximumScale, interval, sourceUri, entityCollection); processPacketData(Boolean, model, 'incrementallyLoadTextures', modelData.incrementallyLoadTextures, interval, sourceUri, entityCollection); processPacketData(Boolean, model, 'runAnimations', modelData.runAnimations, interval, sourceUri, entityCollection); + processPacketData(Boolean, model, 'castShadows', modelData.castShadows, interval, sourceUri, entityCollection); + processPacketData(Boolean, model, 'receiveShadows', modelData.receiveShadows, interval, sourceUri, entityCollection); processPacketData(ShadowMode, model, 'shadows', modelData.shadows, interval, sourceUri, entityCollection); processPacketData(HeightReference, model, 'heightReference', modelData.heightReference, interval, sourceUri, entityCollection); diff --git a/Source/DataSources/ModelGraphics.js b/Source/DataSources/ModelGraphics.js index 992cebf0c09e..e0b5ceb10794 100644 --- a/Source/DataSources/ModelGraphics.js +++ b/Source/DataSources/ModelGraphics.js @@ -47,6 +47,8 @@ define([ * @param {Property} [options.incrementallyLoadTextures=true] Determine if textures may continue to stream in after the model is loaded. * @param {Property} [options.runAnimations=true] A boolean Property specifying if glTF animations specified in the model should be started. * @param {Property} [options.nodeTransformations] An object, where keys are names of nodes, and values are {@link TranslationRotationScale} Properties describing the transformation to apply to that node. + * @param {Property} [options.castShadows=true] Deprecated, use options.shadows instead. A boolean Property specifying whether the model casts shadows from each light source. + * @param {Property} [options.receiveShadows=true] Deprecated, use options.shadows instead. A boolean Property specifying whether the model receives shadows from shadow casters in the scene. * @param {Property} [options.shadows=ShadowMode.ENABLED] An enum Property specifying whether the model casts or receives shadows from each light source. * @param {Property} [options.heightReference=HeightReference.NONE] A Property specifying what the height is relative to. * @@ -64,6 +66,10 @@ define([ this._maximumScaleSubscription = undefined; this._incrementallyLoadTextures = undefined; this._incrementallyLoadTexturesSubscription = undefined; + this._castShadows = undefined; + this._castShadowsSubscription = undefined; + this._receiveShadows = undefined; + this._receiveShadowsSubscription = undefined; this._shadows = undefined; this._shadowsSubscription = undefined; this._uri = undefined; @@ -138,6 +144,24 @@ define([ */ incrementallyLoadTextures : createPropertyDescriptor('incrementallyLoadTextures'), + /** + * Get or sets the boolean Property specifying whether the model + * casts shadows from each light source. + * @memberof ModelGraphics.prototype + * @type {Property} + * @deprecated + */ + castShadows : createPropertyDescriptor('castShadows'), + + /** + * Get or sets the boolean Property specifying whether the model + * receives shadows from shadow casters in the scene. + * @memberof ModelGraphics.prototype + * @type {Property} + * @deprecated + */ + receiveShadows : createPropertyDescriptor('receiveShadows'), + /** * Get or sets the enum Property specifying whether the model * casts or receives shadows from each light source. @@ -194,6 +218,8 @@ define([ result.minimumPixelSize = this.minimumPixelSize; result.maximumScale = this.maximumScale; result.incrementallyLoadTextures = this.incrementallyLoadTextures; + result.castShadows = this.castShadows; + result.receiveShadows = this.receiveShadows; result.shadows = this.shadows; result.uri = this.uri; result.runAnimations = this.runAnimations; @@ -221,6 +247,8 @@ define([ this.minimumPixelSize = defaultValue(this.minimumPixelSize, source.minimumPixelSize); this.maximumScale = defaultValue(this.maximumScale, source.maximumScale); this.incrementallyLoadTextures = defaultValue(this.incrementallyLoadTextures, source.incrementallyLoadTextures); + this.castShadows = defaultValue(this.castShadows, source.castShadows); + this.receiveShadows = defaultValue(this.receiveShadows, source.receiveShadows); this.shadows = defaultValue(this.shadows, source.shadows); this.uri = defaultValue(this.uri, source.uri); this.runAnimations = defaultValue(this.runAnimations, source.runAnimations); diff --git a/Source/DataSources/ModelVisualizer.js b/Source/DataSources/ModelVisualizer.js index 9300baba46fa..fde2fedcb7f8 100644 --- a/Source/DataSources/ModelVisualizer.js +++ b/Source/DataSources/ModelVisualizer.js @@ -131,12 +131,21 @@ define([ modelHash[entity.id] = modelData; } + var shadows = defaultShadows; + if (defined(modelGraphics._shadows)) { + shadows = Property.getValueOrDefault(modelGraphics._shadows, time, defaultShadows); + } else if (defined(modelGraphics._castShadows) || defined(modelGraphics._receiveShadows)) { + var castShadows = Property.getValueOrDefault(modelGraphics._castShadows, time, true); + var receiveShadows = Property.getValueOrDefault(modelGraphics.receiveShadows, time, true); + shadows = ShadowMode.fromCastReceive(castShadows, receiveShadows); + } + model.show = true; model.scale = Property.getValueOrDefault(modelGraphics._scale, time, defaultScale); model.minimumPixelSize = Property.getValueOrDefault(modelGraphics._minimumPixelSize, time, defaultMinimumPixelSize); model.maximumScale = Property.getValueOrUndefined(modelGraphics._maximumScale, time); - model.shadows = Property.getValueOrDefault(modelGraphics._shadows, time, defaultShadows); model.modelMatrix = Matrix4.clone(modelMatrix, model.modelMatrix); + model.shadows = shadows; model.heightReference = Property.getValueOrDefault(modelGraphics._heightReference, time, defaultHeightReference); if (model.ready) { diff --git a/Source/Scene/Globe.js b/Source/Scene/Globe.js index e84b483997b0..e16b87fba3bc 100644 --- a/Source/Scene/Globe.js +++ b/Source/Scene/Globe.js @@ -7,6 +7,7 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', + '../Core/deprecationWarning', '../Core/destroyObject', '../Core/DeveloperError', '../Core/Ellipsoid', @@ -37,6 +38,7 @@ define([ defaultValue, defined, defineProperties, + deprecationWarning, destroyObject, DeveloperError, Ellipsoid, @@ -279,6 +281,46 @@ define([ get: function() { return this._surface.tileLoadProgressEvent; } + }, + + /** + * Determines whether the globe casts shadows from each light source. + * + * @memberof Globe.prototype + * @type {Boolean} + * @deprecated + */ + castShadows : { + get : function() { + deprecationWarning('Globe.castShadows', 'Globe.castShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Globe.shadows instead.'); + return ShadowMode.castShadows(this.shadows); + }, + set : function(value) { + deprecationWarning('Globe.castShadows', 'Globe.castShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Globe.shadows instead.'); + var castShadows = value; + var receiveShadows = ShadowMode.receiveShadows(this.shadows); + this.shadows = ShadowMode.fromCastReceive(castShadows, receiveShadows); + } + }, + + /** + * Determines whether the globe receives shadows from shadow casters in the scene. + * + * @memberof Globe.prototype + * @type {Boolean} + * @deprecated + */ + receiveShadows : { + get : function() { + deprecationWarning('Globe.receiveShadows', 'Globe.receiveShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Globe.shadows instead.'); + return ShadowMode.receiveShadows(this.shadows); + }, + set : function(value) { + deprecationWarning('Globe.receiveShadows', 'Globe.receiveShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Globe.shadows instead.'); + var castShadows = ShadowMode.castShadows(this.shadows); + var receiveShadows = value; + this.shadows = ShadowMode.fromCastReceive(castShadows, receiveShadows); + } } }); diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index b0ff76b6f845..189a5ccdc634 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -12,6 +12,7 @@ define([ '../Core/defined', '../Core/defineProperties', '../Core/destroyObject', + '../Core/deprecationWarning', '../Core/DeveloperError', '../Core/FeatureDetection', '../Core/getAbsoluteUri', @@ -71,6 +72,7 @@ define([ defined, defineProperties, destroyObject, + deprecationWarning, DeveloperError, FeatureDetection, getAbsoluteUri, @@ -313,6 +315,8 @@ define([ * @param {Boolean} [options.allowPicking=true] When true, each glTF mesh and primitive is pickable with {@link Scene#pick}. * @param {Boolean} [options.incrementallyLoadTextures=true] Determine if textures may continue to stream in after the model is loaded. * @param {Boolean} [options.asynchronous=true] Determines if model WebGL resource creation will be spread out over several frames or block until completion once all glTF files are loaded. + * @param {Boolean} [options.castShadows=true] Deprecated, use options.shadows instead. Determines whether the model casts shadows from each light source. + * @param {Boolean} [options.receiveShadows=true] Deprecated, use options.shadows instead. Determines whether the model receives shadows from shadow casters in the scene. * @param {ShadowMode} [options.shadows=ShadowMode.ENABLED] Determines whether the model casts or receives shadows from each light source. * @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. Draws the bounding sphere for each draw command in the model. * @param {Boolean} [options.debugWireframe=false] For debugging only. Draws the model in wireframe. @@ -503,6 +507,10 @@ define([ this._incrementallyLoadTextures = defaultValue(options.incrementallyLoadTextures, true); this._asynchronous = defaultValue(options.asynchronous, true); + // Deprecated options + var castShadows = defaultValue(options.castShadows, true); + var receiveShadows = defaultValue(options.receiveShadows, true); + /** * Determines whether the model casts or receives shadows from each light source. * @@ -510,7 +518,7 @@ define([ * * @default ShadowMode.ENABLED */ - this.shadows = defaultValue(options.shadows, ShadowMode.ENABLED); + this.shadows = defaultValue(options.shadows, ShadowMode.fromCastReceive(castShadows, receiveShadows)); this._shadows = this.shadows; /** @@ -859,6 +867,50 @@ define([ get : function() { return this._dirty; } + }, + + /** + * Determines whether the model casts shadows from each light source. + * + * @memberof Model.prototype + * + * @type {Boolean} + * + * @deprecated + */ + castShadows : { + get : function() { + deprecationWarning('Model.castShadows', 'Model.castShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Model.shadows instead.'); + return ShadowMode.castShadows(this.shadows); + }, + set : function(value) { + deprecationWarning('Model.castShadows', 'Model.castShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Model.shadows instead.'); + var castShadows = value; + var receiveShadows = ShadowMode.receiveShadows(this.shadows); + this.shadows = ShadowMode.fromCastReceive(castShadows, receiveShadows); + } + }, + + /** + * Determines whether the model receives shadows from shadow casters in the scene. + * + * @memberof Model.prototype + * + * @type {Boolean} + * + * @deprecated + */ + receiveShadows : { + get : function() { + deprecationWarning('Model.receiveShadows', 'Model.receiveShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Model.shadows instead.'); + return ShadowMode.receiveShadows(this.shadows); + }, + set : function(value) { + deprecationWarning('Model.receiveShadows', 'Model.receiveShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Model.shadows instead.'); + var castShadows = ShadowMode.castShadows(this.shadows); + var receiveShadows = value; + this.shadows = ShadowMode.fromCastReceive(castShadows, receiveShadows); + } } }); diff --git a/Source/Scene/Primitive.js b/Source/Scene/Primitive.js index b939397d79c0..995078d0fe1b 100644 --- a/Source/Scene/Primitive.js +++ b/Source/Scene/Primitive.js @@ -9,6 +9,7 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/defineProperties', + '../Core/deprecationWarning', '../Core/destroyObject', '../Core/DeveloperError', '../Core/FeatureDetection', @@ -45,6 +46,7 @@ define([ defaultValue, defined, defineProperties, + deprecationWarning, destroyObject, DeveloperError, FeatureDetection, @@ -110,6 +112,8 @@ define([ * @param {Boolean} [options.cull=true] When true, the renderer frustum culls and horizon culls the primitive's commands based on their bounding volume. Set this to false for a small performance gain if you are manually culling the primitive. * @param {Boolean} [options.asynchronous=true] Determines if the primitive will be created asynchronously or block until ready. * @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown. + * @param {Boolean} [options.castShadows=true] Deprecated, use options.shadows instead. Determines whether the primitive casts shadows from each light source. + * @param {Boolean} [options.receiveShadows=true] Deprecated, use options.shadows instead. Determines whether the primitive receives shadows from shadow casters in the scene. * @param {ShadowMode} [options.shadows=ShadowMode.DISABLED] Determines whether this primitive casts or receives shadows from each light source. * * @example @@ -284,6 +288,10 @@ define([ } //>>includeEnd('debug'); + // Deprecated options + var castShadows = defaultValue(options.castShadows, false); + var receiveShadows = defaultValue(options.receiveShadows, false); + /** * Determines whether this primitive casts or receives shadows from each light source. * @@ -291,7 +299,7 @@ define([ * * @default ShadowMode.DISABLED */ - this.shadows = defaultValue(options.shadows, ShadowMode.DISABLED); + this.shadows = defaultValue(options.shadows, ShadowMode.fromCastReceive(castShadows, receiveShadows)); this._translucent = undefined; @@ -467,6 +475,46 @@ define([ get : function() { return this._readyPromise.promise; } + }, + + /** + * Determines whether the primitive casts shadows from each light source. + * + * @memberof Primitive.prototype + * @type {Boolean} + * @deprecated + */ + castShadows : { + get : function() { + deprecationWarning('Primitive.castShadows', 'Primitive.castShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Primitive.shadows instead.'); + return ShadowMode.castShadows(this.shadows); + }, + set : function(value) { + deprecationWarning('Primitive.castShadows', 'Primitive.castShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Primitive.shadows instead.'); + var castShadows = value; + var receiveShadows = ShadowMode.receiveShadows(this.shadows); + this.shadows = ShadowMode.fromCastReceive(castShadows, receiveShadows); + } + }, + + /** + * Determines whether the primitive receives shadows from shadow casters in the scene. + * + * @memberof Primitive.prototype + * @type {Boolean} + * @deprecated + */ + receiveShadows : { + get : function() { + deprecationWarning('Primitive.receiveShadows', 'Primitive.receiveShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Primitive.shadows instead.'); + return ShadowMode.receiveShadows(this.shadows); + }, + set : function(value) { + deprecationWarning('Primitive.receiveShadows', 'Primitive.receiveShadows was deprecated in Cesium 1.25. It will be removed in 1.26. Use Primitive.shadows instead.'); + var castShadows = ShadowMode.castShadows(this.shadows); + var receiveShadows = value; + this.shadows = ShadowMode.fromCastReceive(castShadows, receiveShadows); + } } }); diff --git a/Source/Scene/ShadowMode.js b/Source/Scene/ShadowMode.js index fe093980b48e..68983ad7febd 100644 --- a/Source/Scene/ShadowMode.js +++ b/Source/Scene/ShadowMode.js @@ -63,6 +63,21 @@ define([ ShadowMode.receiveShadows = function(shadowMode) { return (shadowMode === ShadowMode.ENABLED) || (shadowMode === ShadowMode.RECEIVE_ONLY); }; - + + /** + * @private + */ + ShadowMode.fromCastReceive = function(castShadows, receiveShadows) { + if (castShadows && receiveShadows) { + return ShadowMode.ENABLED; + } else if (castShadows) { + return ShadowMode.CAST_ONLY; + } else if (receiveShadows) { + return ShadowMode.RECEIVE_ONLY; + } else { + return ShadowMode.DISABLED; + } + }; + return freezeObject(ShadowMode); }); diff --git a/Source/Widgets/CesiumWidget/CesiumWidget.js b/Source/Widgets/CesiumWidget/CesiumWidget.js index 8e2da0c334a3..2e6c6f6e38ff 100644 --- a/Source/Widgets/CesiumWidget/CesiumWidget.js +++ b/Source/Widgets/CesiumWidget/CesiumWidget.js @@ -282,7 +282,15 @@ define([ } if (globe !== false) { scene.globe = globe; - scene.globe.shadows = defaultValue(options.terrainShadows, ShadowMode.RECEIVE_ONLY); + // If the passed in value is a boolean, convert to the ShadowMode enum. + var terrainShadows = options.terrainShadows; + if (terrainShadows === true) { + scene.globe.shadows = ShadowMode.ENABLED; + } else if (terrainShadows === false) { + scene.globe.shadows = ShadowMode.RECEIVE_ONLY; + } else { + scene.globe.shadows = defaultValue(terrainShadows, ShadowMode.RECEIVE_ONLY); + } } var skyBox = options.skyBox; diff --git a/Source/Widgets/Viewer/Viewer.js b/Source/Widgets/Viewer/Viewer.js index 3b780eae4d53..8bf59948fc4f 100644 --- a/Source/Widgets/Viewer/Viewer.js +++ b/Source/Widgets/Viewer/Viewer.js @@ -974,7 +974,14 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to return this.scene.globe.shadows; }, set : function(value) { - this.scene.globe.shadows = value; + // If the passed in value is a boolean, convert to the ShadowMode enum. + if (value === true) { + this.scene.globe.shadows = ShadowMode.ENABLED; + } else if (value === false) { + this.scene.globe.shadows = ShadowMode.RECEIVE_ONLY; + } else { + this.scene.globe.shadows = value; + } } },