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 9783abd
Show file tree
Hide file tree
Showing 59 changed files with 431 additions and 337 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
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
8 changes: 4 additions & 4 deletions Source/DataSources/CylinderGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ define([
* @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline.
* @param {Property} [options.numberOfVerticalLines=16] A numeric Property specifying the number of vertical lines to draw along the perimeter for the outline.
* @param {Property} [options.slices=128] The number of edges around the perimeter of the cylinder.
* @param {Property} [options.shadows=false] A boolean Property specifying whether the cylinder casts and receives shadows from each light source.
* @param {Property} [options.shadows=ShadowMode.DISABLED] An enum Property specifying whether the cylinder casts or receives shadows from each light source.
*/
function CylinderGraphics(options) {
this._length = undefined;
Expand Down Expand Up @@ -168,11 +168,11 @@ define([
outlineWidth : createPropertyDescriptor('outlineWidth'),

/**
* Get or sets the boolean Property specifying whether the cylinder
* casts and receives shadows from each light source.
* Get or sets the enum Property specifying whether the cylinder
* casts or receives shadows from each light source.
* @memberof CylinderGraphics.prototype
* @type {Property}
* @default false
* @default ShadowMode.DISABLED
*/
shadows : createPropertyDescriptor('shadows')
});
Expand Down
Loading

0 comments on commit 9783abd

Please sign in to comment.