Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature reactive Cesium3DTileStyle.style object #7573

Merged
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change Log

##### Breaking Changes :mega:
* `Resource.fetchImage` now returns an `ImageBitmap` instead of `Image` when supported. This allows for decoding images while fetching using `createImageBitmap` to greatly speed up texture upload and decrease frame drops when loading models with large textures. [#7579](https:/AnalyticalGraphicsInc/cesium/pull/7579)
* `Cesium3DTileStyle.style` now has an empty `Object` as its default value, instead of `undefined`. [#7567](https:/AnalyticalGraphicsInc/cesium/issues/7567)

##### Deprecated :hourglass_flowing_sand:
* `Resource.fetchImage` now takes an options object. Use `resource.fetchImage({ preferBlob: true })` instead of `resource.fetchImage(true)`. The previous function definition will no longer work in 1.57. [#7579](https:/AnalyticalGraphicsInc/cesium/pull/7579)
Expand All @@ -13,6 +14,7 @@ Change Log
* `Resource.fetchImage` now has a `flipY` option to vertically flip an image during fetch & decode. It is only valid when `ImageBitmapOptions` is supported by the browser. [#7579](https:/AnalyticalGraphicsInc/cesium/pull/7579)
* Added `backFaceCulling` and `normalShading` options to `PointCloudShading`. Both options are only applicable for point clouds containing normals. [#7399](https:/AnalyticalGraphicsInc/cesium/pull/7399)
* Added support for touch and hold gesture. The touch and hold delay can be customized by updating `ScreenSpaceEventHandler.touchHoldDelayMilliseconds`. [#7286](https:/AnalyticalGraphicsInc/cesium/pull/7286)
* `Cesium3DTileStyle.style` reacts to updates and represents the current state of the style. [#7567](https:/AnalyticalGraphicsInc/cesium/issues/7567)

##### Fixes :wrench:
* Fixed the value for `BlendFunction.ONE_MINUS_CONSTANT_COLOR`. [#7624](https:/AnalyticalGraphicsInc/cesium/pull/7624)
Expand Down
47 changes: 42 additions & 5 deletions Source/Scene/Cesium3DTileStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ define([
* @see {@link https:/AnalyticalGraphicsInc/3d-tiles/tree/master/specification/Styling|3D Tiles Styling language}
*/
function Cesium3DTileStyle(style) {
this._style = undefined;
this._style = {};
this._ready = false;

this._show = undefined;
Expand Down Expand Up @@ -112,9 +112,8 @@ define([
}

function setup(that, styleJson) {
that._style = clone(styleJson, true);

styleJson = defaultValue(styleJson, defaultValue.EMPTY_OBJECT);
styleJson = defaultValue(clone(styleJson, true), that._style);
that._style = styleJson;

that.show = styleJson.show;
that.color = styleJson.color;
Expand Down Expand Up @@ -161,6 +160,7 @@ define([

function getExpression(tileStyle, value) {
var defines = defaultValue(tileStyle._style, defaultValue.EMPTY_OBJECT).defines;

if (!defined(value)) {
return undefined;
} else if (typeof value === 'boolean' || typeof value === 'number') {
Expand All @@ -173,6 +173,17 @@ define([
return value;
}

function getJsonFromExpression(expression) {
if (!defined(expression)) {
return undefined;
} else if (defined(expression.expression)) {
return expression.expression;
} else if (defined(expression.conditionsExpression)) {
return clone(expression.conditionsExpression, true);
}
return expression;
}

defineProperties(Cesium3DTileStyle.prototype, {
/**
* Gets the object defining the style using the
Expand All @@ -183,7 +194,7 @@ define([
* @type {Object}
* @readonly
*
* @default undefined
* @default {}
*
* @exception {DeveloperError} The style is not loaded. Use Cesium3DTileStyle.readyPromise or wait for Cesium3DTileStyle.ready to be true.
*/
Expand Down Expand Up @@ -295,6 +306,7 @@ define([
},
set : function(value) {
this._show = getExpression(this, value);
this._style.show = getJsonFromExpression(this._show);
this._showShaderFunctionReady = false;
}
},
Expand Down Expand Up @@ -357,6 +369,7 @@ define([
},
set : function(value) {
this._color = getExpression(this, value);
this._style.color = getJsonFromExpression(this._color);
this._colorShaderFunctionReady = false;
}
},
Expand Down Expand Up @@ -424,6 +437,7 @@ define([
},
set : function(value) {
this._pointSize = getExpression(this, value);
this._style.pointSize = getJsonFromExpression(this._pointSize);
this._pointSizeShaderFunctionReady = false;
}
},
Expand Down Expand Up @@ -473,6 +487,7 @@ define([
},
set : function(value) {
this._pointOutlineColor = getExpression(this, value);
this._style.pointOutlineColor = getJsonFromExpression(this._pointOutlineColor);
}
},

Expand Down Expand Up @@ -521,6 +536,7 @@ define([
},
set : function(value) {
this._pointOutlineWidth = getExpression(this, value);
this._style.pointOutlineWidth = getJsonFromExpression(this._pointOutlineWidth);
}
},

Expand Down Expand Up @@ -569,6 +585,7 @@ define([
},
set : function(value) {
this._labelColor = getExpression(this, value);
this._style.labelColor = getJsonFromExpression(this._labelColor);
}
},

Expand Down Expand Up @@ -617,6 +634,7 @@ define([
},
set : function(value) {
this._labelOutlineColor = getExpression(this, value);
this._style.labelOutlineColor = getJsonFromExpression(this._labelOutlineColor);
}
},

Expand Down Expand Up @@ -665,6 +683,7 @@ define([
},
set : function(value) {
this._labelOutlineWidth = getExpression(this, value);
this._style.labelOutlineWidth = getJsonFromExpression(this._labelOutlineWidth);
}
},

Expand Down Expand Up @@ -713,6 +732,7 @@ define([
},
set : function(value) {
this._font = getExpression(this, value);
this._style.font = getJsonFromExpression(this._font);
}
},

Expand Down Expand Up @@ -761,6 +781,7 @@ define([
},
set : function(value) {
this._labelStyle = getExpression(this, value);
this._style.labelStyle = getJsonFromExpression(this._labelStyle);
}
},

Expand Down Expand Up @@ -809,6 +830,7 @@ define([
},
set : function(value) {
this._labelText = getExpression(this, value);
this._style.labelText = getJsonFromExpression(this._labelText);
}
},

Expand Down Expand Up @@ -857,6 +879,7 @@ define([
},
set : function(value) {
this._backgroundColor = getExpression(this, value);
this._style.backgroundColor = getJsonFromExpression(this._backgroundColor);
}
},

Expand Down Expand Up @@ -896,6 +919,7 @@ define([
},
set : function(value) {
this._backgroundPadding = getExpression(this, value);
this._style.backgroundPadding = getJsonFromExpression(this._backgroundPadding);
}
},

Expand Down Expand Up @@ -944,6 +968,7 @@ define([
},
set : function(value) {
this._backgroundEnabled = getExpression(this, value);
this._style.backgroundEnabled = getJsonFromExpression(this._backgroundEnabled);
}
},

Expand Down Expand Up @@ -983,6 +1008,7 @@ define([
},
set : function(value) {
this._scaleByDistance = getExpression(this, value);
this._style.scaleByDistance = getJsonFromExpression(this._scaleByDistance);
}
},

Expand Down Expand Up @@ -1022,6 +1048,7 @@ define([
},
set : function(value) {
this._translucencyByDistance = getExpression(this, value);
this._style.translucencyByDistance = getJsonFromExpression(this._translucencyByDistance);
}
},

Expand Down Expand Up @@ -1061,6 +1088,7 @@ define([
},
set : function(value) {
this._distanceDisplayCondition = getExpression(this, value);
this._style.distanceDisplayCondition = getJsonFromExpression(this._distanceDisplayCondition);
}
},

Expand Down Expand Up @@ -1109,6 +1137,7 @@ define([
},
set : function(value) {
this._heightOffset = getExpression(this, value);
this._style.heightOffset = getJsonFromExpression(this._heightOffset);
}
},

Expand Down Expand Up @@ -1157,6 +1186,7 @@ define([
},
set : function(value) {
this._anchorLineEnabled = getExpression(this, value);
this._style.anchorLineEnabled = getJsonFromExpression(this._anchorLineEnabled);
}
},

Expand Down Expand Up @@ -1205,6 +1235,7 @@ define([
},
set : function(value) {
this._anchorLineColor = getExpression(this, value);
this._style.anchorLineColor = getJsonFromExpression(this._anchorLineColor);
}
},

Expand Down Expand Up @@ -1253,6 +1284,7 @@ define([
},
set : function(value) {
this._image = getExpression(this, value);
this._style.image = getJsonFromExpression(this._image);
}
},

Expand Down Expand Up @@ -1292,6 +1324,7 @@ define([
},
set : function(value) {
this._disableDepthTestDistance = getExpression(this, value);
this._style.disableDepthTestDistance = getJsonFromExpression(this._disableDepthTestDistance);
}
},

Expand Down Expand Up @@ -1340,6 +1373,7 @@ define([
},
set : function(value) {
this._horizontalOrigin = getExpression(this, value);
this._style.horizontalOrigin = getJsonFromExpression(this._horizontalOrigin);
}
},

Expand Down Expand Up @@ -1388,6 +1422,7 @@ define([
},
set : function(value) {
this._verticalOrigin = getExpression(this, value);
this._style.verticalOrigin = getJsonFromExpression(this._verticalOrigin);
}
},

Expand Down Expand Up @@ -1436,6 +1471,7 @@ define([
},
set : function(value) {
this._labelHorizontalOrigin = getExpression(this, value);
this._style.labelHorizontalOrigin = getJsonFromExpression(this._labelHorizontalOrigin);
}
},

Expand Down Expand Up @@ -1484,6 +1520,7 @@ define([
},
set : function(value) {
this._labelVerticalOrigin = getExpression(this, value);
this._style.labelVerticalOrigin = getJsonFromExpression(this._labelVerticalOrigin);
}
},

Expand Down
Loading