Skip to content

Commit

Permalink
Merge pull request #5412 from SunBlack/Extent_Cesium3DTileStyle_setters
Browse files Browse the repository at this point in the history
Extent setters in Cesium3DTileStyle
  • Loading branch information
lilleyse authored Jul 25, 2017
2 parents 9f80e6c + 2f2ac1c commit fbb1dd7
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 86 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Change Log
* The function `Quaternion.fromHeadingPitchRoll(heading, pitch, roll, result)` was removed. Use `Quaternion.fromHeadingPitchRoll(hpr, result)` instead where `hpr` is a `HeadingPitchRoll`.
* The function `Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, result)` was removed. Use `Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result)` instead where `fixedFrameTransform` is a a 4x4 transformation matrix (see `Transforms.localFrameToFixedFrameGenerator`).
* The function `Transforms.headingPitchRollQuaternion(origin, headingPitchRoll, ellipsoid, result)` was removed. Use `Transforms.headingPitchRollQuaternion(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result)` instead where `fixedFrameTransform` is a a 4x4 transformation matrix (see `Transforms.localFrameToFixedFrameGenerator`).
* The `color`, `show`, and `pointSize` properties of `Cesium3DTileStyle` are no longer initialized with default values.
* Deprecated
* `Scene/CullingVolume` is deprecated and will be removed in 1.38. Use `Core/CullingVolume`.
* `Scene/OrthographicFrustum` is deprecated and will be removed in 1.38. Use `Core/OrthographicFrustum`.
Expand All @@ -17,6 +18,7 @@ Change Log
* Fixed issue where composite 3D Tiles that contained instanced 3D Tiles with an external model reference would fail to download the model.
* Added behavior to `Cesium3DTilesInspector` that selects the first tileset hovered over if no tilest is specified. [#5139](https://github.com/AnalyticalGraphicsInc/cesium/issues/5139)
* Added ability to provide a `width` and `height` to `scene.pick`. [#5602](https://github.com/AnalyticalGraphicsInc/cesium/pull/5602)
* Added ability to set a style's `color`, `show`, or `pointSize` with a string or object literal. `show` may also take a boolean and `pointSize` may take a number. [#5412](https://github.com/AnalyticalGraphicsInc/cesium/pull/5412)
* Added setter for `KmlDataSource.name` to specify a name for the datasource [#5660](https://github.com/AnalyticalGraphicsInc/cesium/pull/5660).
* Added setter for `GeoJsonDataSource.name` to specify a name for the datasource [#5653](https://github.com/AnalyticalGraphicsInc/cesium/issues/5653)
* Fixed issue where scene would blink when labels were added. [#5537](https://github.com/AnalyticalGraphicsInc/cesium/issues/5537)
Expand Down
13 changes: 8 additions & 5 deletions Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ define([
StencilOperation) {
'use strict';

var DEFAULT_COLOR_VALUE = Color.WHITE;
var DEFAULT_SHOW_VALUE = true;

/**
* @private
*/
Expand Down Expand Up @@ -414,7 +417,7 @@ define([
Check.typeOf.object('color', color);
//>>includeEnd('debug');

if (Color.equals(color, Color.WHITE) && !defined(this._batchValues)) {
if (Color.equals(color, DEFAULT_COLOR_VALUE) && !defined(this._batchValues)) {
// Avoid allocating since the default is white
return;
}
Expand Down Expand Up @@ -475,7 +478,7 @@ define([
//>>includeEnd('debug');

if (!defined(this._batchValues)) {
return Color.clone(Color.WHITE, result);
return Color.clone(DEFAULT_COLOR_VALUE, result);
}

var batchValues = this._batchValues;
Expand All @@ -495,7 +498,7 @@ define([

Cesium3DTileBatchTable.prototype.applyStyle = function(frameState, style) {
if (!defined(style)) {
this.setAllColor(Color.WHITE);
this.setAllColor(DEFAULT_COLOR_VALUE);
this.setAllShow(true);
return;
}
Expand All @@ -504,8 +507,8 @@ define([
var length = this.featuresLength;
for (var i = 0; i < length; ++i) {
var feature = content.getFeature(i);
var color = style.color.evaluateColor(frameState, feature, scratchColor);
var show = style.show.evaluate(frameState, feature);
var color = defined(style.color) ? style.color.evaluateColor(frameState, feature, scratchColor) : DEFAULT_COLOR_VALUE;
var show = defined(style.show) ? style.show.evaluate(frameState, feature) : DEFAULT_SHOW_VALUE;
this.setColor(i, color);
this.setShow(i, show);
}
Expand Down
157 changes: 104 additions & 53 deletions Source/Scene/Cesium3DTileStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ define([
Expression) {
'use strict';

var DEFAULT_JSON_COLOR_EXPRESSION = 'color("#ffffff")';
var DEFAULT_JSON_BOOLEAN_EXPRESSION = true;
var DEFAULT_JSON_NUMBER_EXPRESSION = 1.0;

/**
* A style that is applied to a {@link Cesium3DTileset}.
* <p>
Expand Down Expand Up @@ -95,49 +91,13 @@ define([

styleJson = defaultValue(styleJson, defaultValue.EMPTY_OBJECT);

that._colorShaderFunctionReady = !defined(styleJson.color);
that._showShaderFunctionReady = !defined(styleJson.show);
that._pointSizeShaderFunctionReady = !defined(styleJson.pointSize);

var colorExpression = defaultValue(styleJson.color, DEFAULT_JSON_COLOR_EXPRESSION);
var showExpression = defaultValue(styleJson.show, DEFAULT_JSON_BOOLEAN_EXPRESSION);
var pointSizeExpression = defaultValue(styleJson.pointSize, DEFAULT_JSON_NUMBER_EXPRESSION);

var defines = styleJson.defines;

var color;
if (typeof colorExpression === 'string') {
color = new Expression(colorExpression, defines);
} else if (defined(colorExpression.conditions)) {
color = new ConditionsExpression(colorExpression, defines);
}

that._color = color;

var show;
if (typeof showExpression === 'boolean') {
show = new Expression(String(showExpression), defines);
} else if (typeof showExpression === 'string') {
show = new Expression(showExpression, defines);
} else if (defined(showExpression.conditions)) {
show = new ConditionsExpression(showExpression, defines);
}

that._show = show;

var pointSize;
if (typeof pointSizeExpression === 'number') {
pointSize = new Expression(String(pointSizeExpression), defines);
} else if (typeof pointSizeExpression === 'string') {
pointSize = new Expression(pointSizeExpression, defines);
} else if (defined(pointSizeExpression.conditions)) {
pointSize = new ConditionsExpression(pointSizeExpression, defines);
}

that._pointSize = pointSize;
that.color = styleJson.color;
that.show = styleJson.show;
that.pointSize = styleJson.pointSize;

var meta = {};
if (defined(styleJson.meta)) {
var defines = styleJson.defines;
var metaJson = defaultValue(styleJson.meta, defaultValue.EMPTY_OBJECT);
for (var property in metaJson) {
if (metaJson.hasOwnProperty(property)) {
Expand Down Expand Up @@ -209,7 +169,8 @@ define([
},

/**
* Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>show</code> property.
* Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>show</code> property. Alternatively a boolean, string, or object defining a show style can be used.
* The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
* <p>
* The expression must return or convert to a <code>Boolean</code>.
* </p>
Expand All @@ -234,6 +195,28 @@ define([
* return true;
* }
* };
*
* @example
* var style = new Cesium.Cesium3DTileStyle();
* // Override show expression with a boolean
* style.show = true;
* };
*
* @example
* var style = new Cesium.Cesium3DTileStyle();
* // Override show expression with a string
* style.show = '${Height} > 0';
* };
*
* @example
* var style = new Cesium.Cesium3DTileStyle();
* // Override show expression with a condition
* style.show = {
* conditions: [
* ['${height} > 2', 'false'],
* ['true', 'true']
* ];
* };
*/
show : {
get : function() {
Expand All @@ -246,13 +229,25 @@ define([
return this._show;
},
set : function(value) {
var defines = defaultValue(this._style, defaultValue.EMPTY_OBJECT).defines;
if (!defined(value)) {
this._show = undefined;
} else if (typeof value === 'boolean') {
this._show = new Expression(String(value));
} else if (typeof value === 'string') {
this._show = new Expression(value, defines);
} else if (defined(value.conditions)) {
this._show = new ConditionsExpression(value, defines);
} else {
this._show = value;
}
this._showShaderFunctionReady = false;
this._show = value;
}
},

/**
* Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>color</code> property.
* Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>color</code> property. Alternatively a string or object defining a color style can be used.
* The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
* <p>
* The expression must return a <code>Color</code>.
* </p>
Expand All @@ -277,6 +272,21 @@ define([
* return Cesium.Color.clone(Cesium.Color.WHITE, result);
* }
* };
*
* @example
* var style = new Cesium.Cesium3DTileStyle();
* // Override color expression with a string
* style.color = 'color("blue")';
*
* @example
* var style = new Cesium.Cesium3DTileStyle();
* // Override color expression with a condition
* style.color = {
* conditions : [
* ['${height} > 2', 'color("cyan")'],
* ['true', 'color("blue")']
* ]
* };
*/
color : {
get : function() {
Expand All @@ -289,13 +299,23 @@ define([
return this._color;
},
set : function(value) {
var defines = defaultValue(this._style, defaultValue.EMPTY_OBJECT).defines;
if (!defined(value)) {
this._color = undefined;
} else if (typeof value === 'string') {
this._color = new Expression(value, defines);
} else if (defined(value.conditions)) {
this._color = new ConditionsExpression(value, defines);
} else {
this._color = value;
}
this._colorShaderFunctionReady = false;
this._color = value;
}
},

/**
* Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>pointSize</code> property.
* Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>pointSize</code> property. Alternatively a number, string, or object defining a pointSize style can be used.
* The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
* <p>
* The expression must return or convert to a <code>Number</code>.
* </p>
Expand All @@ -320,6 +340,26 @@ define([
* return 1.0;
* }
* };
*
* @example
* var style = new Cesium.Cesium3DTileStyle();
* // Override pointSize expression with a number
* style.pointSize = 1.0;
*
* @example
* var style = new Cesium.Cesium3DTileStyle();
* // Override pointSize expression with a string
* style.pointSize = '${height} / 10';
*
* @example
* var style = new Cesium.Cesium3DTileStyle();
* // Override pointSize expression with a condition
* style.pointSize = {
* conditions : [
* ['${height} > 2', '1.0'],
* ['true', '2.0']
* ]
* };
*/
pointSize : {
get : function() {
Expand All @@ -332,8 +372,19 @@ define([
return this._pointSize;
},
set : function(value) {
var defines = defaultValue(this._style, defaultValue.EMPTY_OBJECT).defines;
if (!defined(value)) {
this._pointSize = undefined;
} else if (typeof value === 'number') {
this._pointSize = new Expression(String(value));
} else if (typeof value === 'string') {
this._pointSize = new Expression(value, defines);
} else if (defined(value.conditions)) {
this._pointSize = new ConditionsExpression(value, defines);
} else {
this._pointSize = value;
}
this._pointSizeShaderFunctionReady = false;
this._pointSize = value;
}
},

Expand Down Expand Up @@ -389,7 +440,7 @@ define([
}

this._colorShaderFunctionReady = true;
this._colorShaderFunction = this.color.getShaderFunction(functionName, attributePrefix, shaderState, 'vec4');
this._colorShaderFunction = defined(this.color) ? this.color.getShaderFunction(functionName, attributePrefix, shaderState, 'vec4') : undefined;
return this._colorShaderFunction;
};

Expand All @@ -411,7 +462,7 @@ define([
}

this._showShaderFunctionReady = true;
this._showShaderFunction = this.show.getShaderFunction(functionName, attributePrefix, shaderState, 'bool');
this._showShaderFunction = defined(this.show) ? this.show.getShaderFunction(functionName, attributePrefix, shaderState, 'bool') : undefined;
return this._showShaderFunction;
};

Expand All @@ -433,7 +484,7 @@ define([
}

this._pointSizeShaderFunctionReady = true;
this._pointSizeShaderFunction = this.pointSize.getShaderFunction(functionName, attributePrefix, shaderState, 'float');
this._pointSizeShaderFunction = defined(this.pointSize) ? this.pointSize.getShaderFunction(functionName, attributePrefix, shaderState, 'float') : undefined;
return this._pointSizeShaderFunction;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ define([
// Restore original color to feature that is no longer selected
var frameState = this._scene.frameState;
if (!this.colorize && defined(this._style)) {
currentFeature.color = this._style.color.evaluateColor(frameState, currentFeature, scratchColor);
currentFeature.color = defined(this._style.color) ? this._style.color.evaluateColor(frameState, currentFeature, scratchColor) : Color.WHITE;
} else {
currentFeature.color = oldColor;
}
Expand Down
Loading

0 comments on commit fbb1dd7

Please sign in to comment.