Skip to content

Commit

Permalink
Added shadows property to entities
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jun 8, 2016
1 parent 6959c80 commit 4942533
Show file tree
Hide file tree
Showing 52 changed files with 715 additions and 161 deletions.
37 changes: 11 additions & 26 deletions Apps/Sandcastle/gallery/Shadows.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@
viewer.shadows = !viewer.shadows;
});

Sandcastle.addToolbarButton('Toggle Model Shadows', function() {
for (i = 0; i < entitiesLength; ++i) {
entities[i].model.shadows = !entities[i].model.shadows;
}
});

Sandcastle.addToolbarButton('Toggle Terrain Shadows', function() {
viewer.terrainShadows = !viewer.terrainShadows;
});
Expand Down Expand Up @@ -220,34 +226,13 @@
}
}]);

function setShadows(castShadows, receiveShadows) {
var entityShadows = true;
Sandcastle.addToolbarButton('Entity Shadows', function() {
entityShadows = !entityShadows;
for (i = 0; i < entitiesLength; ++i) {
entities[i].model.castShadows = castShadows;
entities[i].model.receiveShadows = receiveShadows;
}
}

Sandcastle.addToolbarMenu([{
text : 'Entity Shadows',
onselect : function() {
setShadows(true, true);
}
}, {
text : 'Cast Only',
onselect : function() {
setShadows(true, false);
}
}, {
text : 'Receive Only',
onselect : function() {
setShadows(false, true);
entities[i].model.shadows = entityShadows;
}
}, {
text : 'Off',
onselect : function() {
setShadows(false, false);
}
}]);
});

setLocation(locations.Exton);
setEntity(cesiumAir);
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Change Log
* 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 CZML support for Box, Corridor and Cylinder
* Added `shadows` property to the entity API for models, boxes, corridors, cylinders, ellipses, ellipsoids, polygons, polylines, polyline volumes, rectangles, and walls. [#4005](https://github.com/AnalyticalGraphicsInc/cesium/pull/4005)

### 1.22 - 2016-06-01

Expand Down
26 changes: 24 additions & 2 deletions Source/DataSources/BoxGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ define([
var defaultFill = new ConstantProperty(true);
var defaultOutline = new ConstantProperty(false);
var defaultOutlineColor = new ConstantProperty(Color.BLACK);
var defaultShadows = new ConstantProperty(false);
var scratchColor = new Color();

function GeometryOptions(entity) {
Expand Down Expand Up @@ -90,6 +91,7 @@ define([
this._showOutlineProperty = undefined;
this._outlineColorProperty = undefined;
this._outlineWidth = 1.0;
this._shadowsProperty = undefined;
this._options = new GeometryOptions(entity);
this._onEntityPropertyChanged(entity, 'box', entity.box, undefined);
}
Expand Down Expand Up @@ -217,6 +219,19 @@ define([
return this._outlineWidth;
}
},
/**
* Gets the boolean property specifying whether the geometry
* casts and receives shadows from each light source.
* @memberof BoxGeometryUpdater.prototype
*
* @type {Property}
* @readonly
*/
shadowsProperty : {
get : function() {
return this._shadowsProperty;
}
},
/**
* Gets a value indicating if the geometry is time-varying.
* If true, all visualization is delegated to the {@link DynamicGeometryUpdater}
Expand Down Expand Up @@ -436,6 +451,7 @@ define([
this._showProperty = defaultValue(show, defaultShow);
this._showOutlineProperty = defaultValue(box.outline, defaultOutline);
this._outlineColorProperty = outlineEnabled ? defaultValue(box.outlineColor, defaultOutlineColor) : undefined;
this._shadowsProperty = defaultValue(box.shadows, defaultShadows);

var outlineWidth = box.outlineWidth;

Expand Down Expand Up @@ -521,6 +537,8 @@ define([

options.dimensions = dimensions;

var shadows = this._geometryUpdater.shadowsProperty.getValue(time);

if (Property.getValueOrDefault(box.fill, time, true)) {
var material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, this._material);
this._material = material;
Expand All @@ -539,7 +557,9 @@ define([
modelMatrix : modelMatrix
}),
appearance : appearance,
asynchronous : false
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
}));
}

Expand All @@ -566,7 +586,9 @@ define([
lineWidth : geometryUpdater._scene.clampLineWidth(outlineWidth)
}
}),
asynchronous : false
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
}));
}
};
Expand Down
16 changes: 15 additions & 1 deletion Source/DataSources/BoxGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +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.
*
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Box.html|Cesium Sandcastle Box Demo}
*/
Expand All @@ -49,6 +50,8 @@ define([
this._outlineColorSubscription = undefined;
this._outlineWidth = undefined;
this._outlineWidthSubscription = undefined;
this._shadows = undefined;
this._shadowsSubscription = undefined;
this._definitionChanged = new Event();

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
Expand Down Expand Up @@ -120,7 +123,16 @@ define([
* @type {Property}
* @default 1.0
*/
outlineWidth : createPropertyDescriptor('outlineWidth')
outlineWidth : createPropertyDescriptor('outlineWidth'),

/**
* Get or sets the boolean Property specifying whether the box
* casts and receives shadows from each light source.
* @memberof BoxGraphics.prototype
* @type {Property}
* @default false
*/
shadows : createPropertyDescriptor('shadows')
});

/**
Expand All @@ -140,6 +152,7 @@ define([
result.outline = this.outline;
result.outlineColor = this.outlineColor;
result.outlineWidth = this.outlineWidth;
result.shadows = this.shadows;
return result;
};

Expand All @@ -163,6 +176,7 @@ define([
this.outline = defaultValue(this.outline, source.outline);
this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
this.shadows = defaultValue(this.shadows, source.shadows);
};

return BoxGraphics;
Expand Down
26 changes: 24 additions & 2 deletions Source/DataSources/CorridorGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ define([
var defaultFill = new ConstantProperty(true);
var defaultOutline = new ConstantProperty(false);
var defaultOutlineColor = new ConstantProperty(Color.BLACK);
var defaultShadows = new ConstantProperty(false);
var scratchColor = new Color();

function GeometryOptions(entity) {
Expand Down Expand Up @@ -96,6 +97,7 @@ define([
this._showOutlineProperty = undefined;
this._outlineColorProperty = undefined;
this._outlineWidth = 1.0;
this._shadowsProperty = undefined;
this._options = new GeometryOptions(entity);
this._onEntityPropertyChanged(entity, 'corridor', entity.corridor, undefined);
}
Expand Down Expand Up @@ -223,6 +225,19 @@ define([
return this._outlineWidth;
}
},
/**
* Gets the boolean property specifying whether the geometry
* casts and receives shadows from each light source.
* @memberof CorridorGeometryUpdater.prototype
*
* @type {Property}
* @readonly
*/
shadowsProperty : {
get : function() {
return this._shadowsProperty;
}
},
/**
* Gets a value indicating if the geometry is time-varying.
* If true, all visualization is delegated to the {@link DynamicGeometryUpdater}
Expand Down Expand Up @@ -442,6 +457,7 @@ define([
this._showProperty = defaultValue(show, defaultShow);
this._showOutlineProperty = defaultValue(corridor.outline, defaultOutline);
this._outlineColorProperty = outlineEnabled ? defaultValue(corridor.outlineColor, defaultOutlineColor) : undefined;
this._shadowsProperty = defaultValue(corridor.shadows, defaultShadows);

var height = corridor.height;
var extrudedHeight = corridor.extrudedHeight;
Expand Down Expand Up @@ -546,6 +562,8 @@ define([
options.granularity = Property.getValueOrUndefined(corridor.granularity, time);
options.cornerType = Property.getValueOrUndefined(corridor.cornerType, time);

var shadows = this._geometryUpdater.shadowsProperty.getValue(time);

if (!defined(corridor.fill) || corridor.fill.getValue(time)) {
var material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, this._material);
this._material = material;
Expand All @@ -563,7 +581,9 @@ define([
geometry : new CorridorGeometry(options)
}),
appearance : appearance,
asynchronous : false
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
}));
}

Expand All @@ -589,7 +609,9 @@ define([
lineWidth : geometryUpdater._scene.clampLineWidth(outlineWidth)
}
}),
asynchronous : false
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
}));
}
};
Expand Down
16 changes: 15 additions & 1 deletion Source/DataSources/CorridorGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +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.
*
* @see Entity
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Corridor.html|Cesium Sandcastle Corridor Demo}
Expand Down Expand Up @@ -67,6 +68,8 @@ define([
this._outlineColorSubscription = undefined;
this._outlineWidth = undefined;
this._outlineWidthSubscription = undefined;
this._shadows = undefined;
this._shadowsSubscription = undefined;
this._definitionChanged = new Event();

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
Expand Down Expand Up @@ -178,7 +181,16 @@ define([
* @type {Property}
* @default CornerType.ROUNDED
*/
cornerType : createPropertyDescriptor('cornerType')
cornerType : createPropertyDescriptor('cornerType'),

/**
* Get or sets the boolean Property specifying whether the corridor
* casts and receives shadows from each light source.
* @memberof CorridorGraphics.prototype
* @type {Property}
* @default false
*/
shadows : createPropertyDescriptor('shadows')
});

/**
Expand All @@ -203,6 +215,7 @@ define([
result.outlineColor = this.outlineColor;
result.outlineWidth = this.outlineWidth;
result.cornerType = this.cornerType;
result.shadows = this.shadows;
return result;
};

Expand Down Expand Up @@ -231,6 +244,7 @@ define([
this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
this.cornerType = defaultValue(this.cornerType, source.cornerType);
this.shadows = defaultValue(this.shadows, source.shadows);
};

return CorridorGraphics;
Expand Down
26 changes: 24 additions & 2 deletions Source/DataSources/CylinderGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +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 scratchColor = new Color();

Expand Down Expand Up @@ -97,6 +98,7 @@ define([
this._showOutlineProperty = undefined;
this._outlineColorProperty = undefined;
this._outlineWidth = 1.0;
this._shadowsProperty = undefined;
this._options = new GeometryOptions(entity);
this._onEntityPropertyChanged(entity, 'cylinder', entity.cylinder, undefined);
}
Expand Down Expand Up @@ -224,6 +226,19 @@ define([
return this._outlineWidth;
}
},
/**
* Gets the boolean property specifying whether the geometry
* casts and receives shadows from each light source.
* @memberof CylinderGeometryUpdater.prototype
*
* @type {Property}
* @readonly
*/
shadowsProperty : {
get : function() {
return this._shadowsProperty;
}
},
/**
* Gets a value indicating if the geometry is time-varying.
* If true, all visualization is delegated to the {@link DynamicGeometryUpdater}
Expand Down Expand Up @@ -446,6 +461,7 @@ define([
this._showProperty = defaultValue(show, defaultShow);
this._showOutlineProperty = defaultValue(cylinder.outline, defaultOutline);
this._outlineColorProperty = outlineEnabled ? defaultValue(cylinder.outlineColor, defaultOutlineColor) : undefined;
this._shadowsProperty = defaultValue(cylinder.shadows, defaultShadows);

var slices = cylinder.slices;
var outlineWidth = cylinder.outlineWidth;
Expand Down Expand Up @@ -547,6 +563,8 @@ define([
options.slices = Property.getValueOrUndefined(cylinder.slices, time);
options.numberOfVerticalLines = Property.getValueOrUndefined(cylinder.numberOfVerticalLines, time);

var shadows = this._geometryUpdater.shadowsProperty.getValue(time);

if (Property.getValueOrDefault(cylinder.fill, time, true)) {
var material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, this._material);
this._material = material;
Expand All @@ -565,7 +583,9 @@ define([
modelMatrix : modelMatrix
}),
appearance : appearance,
asynchronous : false
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
}));
}

Expand All @@ -592,7 +612,9 @@ define([
lineWidth : geometryUpdater._scene.clampLineWidth(outlineWidth)
}
}),
asynchronous : false
asynchronous : false,
castShadows : shadows,
receiveShadows : shadows
}));
}
};
Expand Down
Loading

0 comments on commit 4942533

Please sign in to comment.