Skip to content

Commit

Permalink
Updated entity and primitive layers to use shadow enums
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jun 26, 2016
1 parent 3069cf1 commit 9b20891
Show file tree
Hide file tree
Showing 62 changed files with 476 additions and 362 deletions.
22 changes: 15 additions & 7 deletions Apps/Sandcastle/gallery/Shadows.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
infoBox : false,
selectionIndicator : false,
shadows : true,
terrainShadows : true
terrainShadows : Cesium.ShadowMode.ENABLED
});

viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
Expand Down Expand Up @@ -91,7 +91,7 @@
box : {
dimensions : new Cesium.Cartesian3(10.0, 10.0, 10.0),
material : Cesium.Color.RED,
shadows : true
shadows : Cesium.ShadowMode.ENABLED
}
});

Expand All @@ -109,7 +109,7 @@
material : checkerMaterial,
outline : true,
outlineColor : Cesium.Color.RED,
shadows : true
shadows : Cesium.ShadowMode.ENABLED
}
});

Expand All @@ -121,7 +121,7 @@
material : Cesium.Color.BLUE.withAlpha(0.5),
slicePartitions : 24,
stackPartitions : 36,
shadows : true
shadows : Cesium.ShadowMode.ENABLED
}
});

Expand Down Expand Up @@ -230,9 +230,13 @@
viewer.shadows = !viewer.shadows;
});

var entityShadows = true;
var entityShadows = Cesium.ShadowMode.ENABLED;
Sandcastle.addToolbarButton('Toggle Entity Shadows', function() {
entityShadows = !entityShadows;
if (entityShadows === Cesium.ShadowMode.ENABLED) {
entityShadows = Cesium.ShadowMode.DISABLED;
} else {
entityShadows = Cesium.ShadowMode.ENABLED;
}
for (i = 0; i < entitiesLength; ++i) {
var entity = entities[i];
var visual = entity.model || entity.box || entity.ellipsoid;
Expand All @@ -241,7 +245,11 @@
});

Sandcastle.addToolbarButton('Toggle Terrain Shadows', function() {
viewer.terrainShadows = !viewer.terrainShadows;
if (viewer.terrainShadows === Cesium.ShadowMode.ENABLED) {
viewer.terrainShadows = Cesium.ShadowMode.DISABLED;
} else {
viewer.terrainShadows = Cesium.ShadowMode.ENABLED;
}
});

Sandcastle.addToolbarButton('Soft Shadows', function() {
Expand Down
32 changes: 22 additions & 10 deletions Apps/Sandcastle/gallery/development/Shadows.html
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@
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);
Expand Down Expand Up @@ -390,8 +402,7 @@
// Force all derived commands to update
shadowMap.dirty = true;

globe.castShadows = viewModel.terrainCast;
globe.receiveShadows = viewModel.terrainReceive;
globe.shadows = getShadowMode(viewModel.terrainCast, viewModel.terrainReceive);
globe.show = viewModel.globe;
scene.skyAtmosphere.show = viewModel.globe;
}
Expand Down Expand Up @@ -639,8 +650,7 @@
}),
asynchronous : false,
rtcCenter : boxGeometry.boundingSphere.center,
castShadows : true,
receiveShadows : true
shadows : Cesium.ShadowMode.ENABLED
});

scene.primitives.add(box);
Expand All @@ -665,8 +675,7 @@
closed : true
}),
asynchronous : false,
castShadows : true,
receiveShadows : true
shadows : Cesium.ShadowMode.ENABLED
});

scene.primitives.add(box);
Expand All @@ -691,8 +700,7 @@
closed : true
}),
asynchronous : false,
castShadows : true,
receiveShadows : true
shadows : Cesium.ShadowMode.ENABLED
});

scene.primitives.add(sphere);
Expand All @@ -711,15 +719,19 @@
handler.setInputAction(function(movement) {
var picked = scene.pick(movement.position);
if (Cesium.defined(picked) && Cesium.defined(picked.primitive)) {
picked.primitive.castShadows = !picked.primitive.castShadows;
var castShadows = Cesium.ShadowMode.castShadows(picked.primitive.shadows);
var receiveShadows = Cesium.ShadowMode.receiveShadows(picked.primitive.shadows);
picked.primitive.shadows = getShadowMode(!castShadows, receiveShadows);
}
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);

// Double middle click object to turn receiveShadows on/off
handler.setInputAction(function(movement) {
var picked = scene.pick(movement.position);
if (Cesium.defined(picked)) {
picked.primitive.receiveShadows = !picked.primitive.receiveShadows;
var castShadows = Cesium.ShadowMode.castShadows(picked.primitive.shadows);
var receiveShadows = Cesium.ShadowMode.receiveShadows(picked.primitive.shadows);
picked.primitive.shadows = getShadowMode(castShadows, !receiveShadows);
}
}, Cesium.ScreenSpaceEventType.MIDDLE_DOUBLE_CLICK);

Expand Down
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ Change Log

### 1.23 - 2016-07-01

* Breaking changes
* Removed `castShadows` and `receiveShadows` properties from `Model`, `Primitive`, and `Globe`. 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`.
* Entity `model.shadows` now uses the `ShadowMode` enum instead of a Boolean, e.g. `entity.model.shadows = ShadowMode.ENABLED`.
* Add a `rotatable2D` option to to `Scene`, `CesiumWidget` and `Viewer` to enable a rotatable map in 2D. [#3897](https://github.com/AnalyticalGraphicsInc/cesium/issues/3897)
* `Camera.setView` and `Camera.flyTo` will now use the `orientation.heading` parameter in 2D if the map is rotatable.
* Made changes to KML processing that allows for some incorrect KML (specifically KML that reuses IDs) to still be parsed correctly
* Added `packArray` and `unpackArray` functions to `Cartesian2`, `Cartesian3`, and `Cartesian4`.
* Fix some large polygon triangulations. [#2788](https://github.com/AnalyticalGraphicsInc/cesium/issues/2788)
* Improved performance and accuracy of polygon triangulation by using the [earcut](https://github.com/mapbox/earcut) library. Loading a GeoJSON with polygons for each country was 2x faster.
* Added `shadows` property to the entity API for `Box`, `Corridor`, `Cylinder`, `Ellipse`, `Ellipsoid`, `Model`, `Polygon`, `Polyline`, `PoylineVolume`, `Rectangle`, and `Wall`. [#4005](https://github.com/AnalyticalGraphicsInc/cesium/pull/4005)
* 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)
* Added CZML support for `Box`, `Corridor` and `Cylinder`. Added new CZML properties:
* `Billboard`: `width`, `height`, `scaleByDistance`, `translucencyByDistance`, `pixelOffsetScaleByDistance`, `imageSubRegion`
* `Label`: `translucencyByDistance`, `pixelOffsetScaleByDistance`
Expand Down
14 changes: 7 additions & 7 deletions Source/DataSources/BoxGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ define([
'../Scene/MaterialAppearance',
'../Scene/PerInstanceColorAppearance',
'../Scene/Primitive',
'../Scene/ShadowMode',
'./ColorMaterialProperty',
'./ConstantProperty',
'./dynamicGeometryGetBoundingSphere',
Expand All @@ -38,6 +39,7 @@ define([
MaterialAppearance,
PerInstanceColorAppearance,
Primitive,
ShadowMode,
ColorMaterialProperty,
ConstantProperty,
dynamicGeometryGetBoundingSphere,
Expand All @@ -50,7 +52,7 @@ define([
var defaultFill = new ConstantProperty(true);
var defaultOutline = new ConstantProperty(false);
var defaultOutlineColor = new ConstantProperty(Color.BLACK);
var defaultShadows = new ConstantProperty(false);
var defaultShadows = new ConstantProperty(ShadowMode.DISABLED);
var scratchColor = new Color();

function GeometryOptions(entity) {
Expand Down Expand Up @@ -220,8 +222,8 @@ define([
}
},
/**
* Gets the boolean property specifying whether the geometry
* casts and receives shadows from each light source.
* Gets the property specifying whether the geometry
* casts or receives shadows from each light source.
* @memberof BoxGeometryUpdater.prototype
*
* @type {Property}
Expand Down Expand Up @@ -558,8 +560,7 @@ define([
}),
appearance : appearance,
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
shadows : shadows
}));
}

Expand Down Expand Up @@ -587,8 +588,7 @@ define([
}
}),
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
shadows : shadows
}));
}
};
Expand Down
8 changes: 4 additions & 4 deletions Source/DataSources/BoxGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ define([
* @param {Property} [options.outline=false] A boolean Property specifying whether the box is outlined.
* @param {Property} [options.outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
* @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline.
* @param {Property} [options.shadows=false] A boolean Property specifying whether the box casts and receives shadows from each light source.
* @param {Property} [options.shadows=ShadowMode.DISABLED] An enum Property specifying whether the box casts or receives shadows from each light source.
*
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Box.html|Cesium Sandcastle Box Demo}
*/
Expand Down Expand Up @@ -126,11 +126,11 @@ define([
outlineWidth : createPropertyDescriptor('outlineWidth'),

/**
* Get or sets the boolean Property specifying whether the box
* casts and receives shadows from each light source.
* Get or sets the enum Property specifying whether the box
* casts or receives shadows from each light source.
* @memberof BoxGraphics.prototype
* @type {Property}
* @default false
* @default ShadowMode.DISABLED
*/
shadows : createPropertyDescriptor('shadows')
});
Expand Down
14 changes: 7 additions & 7 deletions Source/DataSources/CorridorGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ define([
'../Scene/MaterialAppearance',
'../Scene/PerInstanceColorAppearance',
'../Scene/Primitive',
'../Scene/ShadowMode',
'./ColorMaterialProperty',
'./ConstantProperty',
'./dynamicGeometryGetBoundingSphere',
Expand All @@ -38,6 +39,7 @@ define([
MaterialAppearance,
PerInstanceColorAppearance,
Primitive,
ShadowMode,
ColorMaterialProperty,
ConstantProperty,
dynamicGeometryGetBoundingSphere,
Expand All @@ -50,7 +52,7 @@ define([
var defaultFill = new ConstantProperty(true);
var defaultOutline = new ConstantProperty(false);
var defaultOutlineColor = new ConstantProperty(Color.BLACK);
var defaultShadows = new ConstantProperty(false);
var defaultShadows = new ConstantProperty(ShadowMode.DISABLED);
var scratchColor = new Color();

function GeometryOptions(entity) {
Expand Down Expand Up @@ -226,8 +228,8 @@ define([
}
},
/**
* Gets the boolean property specifying whether the geometry
* casts and receives shadows from each light source.
* Gets the property specifying whether the geometry
* casts or receives shadows from each light source.
* @memberof CorridorGeometryUpdater.prototype
*
* @type {Property}
Expand Down Expand Up @@ -582,8 +584,7 @@ define([
}),
appearance : appearance,
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
shadows : shadows
}));
}

Expand All @@ -610,8 +611,7 @@ define([
}
}),
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
shadows : shadows
}));
}
};
Expand Down
8 changes: 4 additions & 4 deletions Source/DataSources/CorridorGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ define([
* @param {Property} [options.outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
* @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline.
* @param {Property} [options.granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the distance between each latitude and longitude.
* @param {Property} [options.shadows=false] A boolean Property specifying whether the corridor casts and receives shadows from each light source.
* @param {Property} [options.shadows=ShadowMode.DISABLED] An enum Property specifying whether the corridor casts or receives shadows from each light source.
*
* @see Entity
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Corridor.html|Cesium Sandcastle Corridor Demo}
Expand Down Expand Up @@ -184,11 +184,11 @@ define([
cornerType : createPropertyDescriptor('cornerType'),

/**
* Get or sets the boolean Property specifying whether the corridor
* casts and receives shadows from each light source.
* Get or sets the enum Property specifying whether the corridor
* casts or receives shadows from each light source.
* @memberof CorridorGraphics.prototype
* @type {Property}
* @default false
* @default ShadowMode.DISABLED
*/
shadows : createPropertyDescriptor('shadows')
});
Expand Down
14 changes: 7 additions & 7 deletions Source/DataSources/CylinderGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define([
'../Scene/MaterialAppearance',
'../Scene/PerInstanceColorAppearance',
'../Scene/Primitive',
'../Scene/ShadowMode',
'./ColorMaterialProperty',
'./ConstantProperty',
'./dynamicGeometryGetBoundingSphere',
Expand All @@ -40,6 +41,7 @@ define([
MaterialAppearance,
PerInstanceColorAppearance,
Primitive,
ShadowMode,
ColorMaterialProperty,
ConstantProperty,
dynamicGeometryGetBoundingSphere,
Expand All @@ -52,7 +54,7 @@ define([
var defaultFill = new ConstantProperty(true);
var defaultOutline = new ConstantProperty(false);
var defaultOutlineColor = new ConstantProperty(Color.BLACK);
var defaultShadows = new ConstantProperty(false);
var defaultShadows = new ConstantProperty(ShadowMode.DISABLED);

var scratchColor = new Color();

Expand Down Expand Up @@ -227,8 +229,8 @@ define([
}
},
/**
* Gets the boolean property specifying whether the geometry
* casts and receives shadows from each light source.
* Gets the property specifying whether the geometry
* casts or receives shadows from each light source.
* @memberof CylinderGeometryUpdater.prototype
*
* @type {Property}
Expand Down Expand Up @@ -584,8 +586,7 @@ define([
}),
appearance : appearance,
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
shadows : shadows
}));
}

Expand Down Expand Up @@ -613,8 +614,7 @@ define([
}
}),
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
shadows : shadows
}));
}
};
Expand Down
Loading

0 comments on commit 9b20891

Please sign in to comment.