Skip to content

Commit fbb1dd7

Browse files
authored
Merge pull request #5412 from SunBlack/Extent_Cesium3DTileStyle_setters
Extent setters in Cesium3DTileStyle
2 parents 9f80e6c + 2f2ac1c commit fbb1dd7

File tree

5 files changed

+247
-86
lines changed

5 files changed

+247
-86
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Change Log
77
* The function `Quaternion.fromHeadingPitchRoll(heading, pitch, roll, result)` was removed. Use `Quaternion.fromHeadingPitchRoll(hpr, result)` instead where `hpr` is a `HeadingPitchRoll`.
88
* 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`).
99
* 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`).
10+
* The `color`, `show`, and `pointSize` properties of `Cesium3DTileStyle` are no longer initialized with default values.
1011
* Deprecated
1112
* `Scene/CullingVolume` is deprecated and will be removed in 1.38. Use `Core/CullingVolume`.
1213
* `Scene/OrthographicFrustum` is deprecated and will be removed in 1.38. Use `Core/OrthographicFrustum`.
@@ -17,6 +18,7 @@ Change Log
1718
* Fixed issue where composite 3D Tiles that contained instanced 3D Tiles with an external model reference would fail to download the model.
1819
* Added behavior to `Cesium3DTilesInspector` that selects the first tileset hovered over if no tilest is specified. [#5139](https://github.com/AnalyticalGraphicsInc/cesium/issues/5139)
1920
* Added ability to provide a `width` and `height` to `scene.pick`. [#5602](https://github.com/AnalyticalGraphicsInc/cesium/pull/5602)
21+
* 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)
2022
* Added setter for `KmlDataSource.name` to specify a name for the datasource [#5660](https://github.com/AnalyticalGraphicsInc/cesium/pull/5660).
2123
* Added setter for `GeoJsonDataSource.name` to specify a name for the datasource [#5653](https://github.com/AnalyticalGraphicsInc/cesium/issues/5653)
2224
* Fixed issue where scene would blink when labels were added. [#5537](https://github.com/AnalyticalGraphicsInc/cesium/issues/5537)

Source/Scene/Cesium3DTileBatchTable.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ define([
6868
StencilOperation) {
6969
'use strict';
7070

71+
var DEFAULT_COLOR_VALUE = Color.WHITE;
72+
var DEFAULT_SHOW_VALUE = true;
73+
7174
/**
7275
* @private
7376
*/
@@ -414,7 +417,7 @@ define([
414417
Check.typeOf.object('color', color);
415418
//>>includeEnd('debug');
416419

417-
if (Color.equals(color, Color.WHITE) && !defined(this._batchValues)) {
420+
if (Color.equals(color, DEFAULT_COLOR_VALUE) && !defined(this._batchValues)) {
418421
// Avoid allocating since the default is white
419422
return;
420423
}
@@ -475,7 +478,7 @@ define([
475478
//>>includeEnd('debug');
476479

477480
if (!defined(this._batchValues)) {
478-
return Color.clone(Color.WHITE, result);
481+
return Color.clone(DEFAULT_COLOR_VALUE, result);
479482
}
480483

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

496499
Cesium3DTileBatchTable.prototype.applyStyle = function(frameState, style) {
497500
if (!defined(style)) {
498-
this.setAllColor(Color.WHITE);
501+
this.setAllColor(DEFAULT_COLOR_VALUE);
499502
this.setAllShow(true);
500503
return;
501504
}
@@ -504,8 +507,8 @@ define([
504507
var length = this.featuresLength;
505508
for (var i = 0; i < length; ++i) {
506509
var feature = content.getFeature(i);
507-
var color = style.color.evaluateColor(frameState, feature, scratchColor);
508-
var show = style.show.evaluate(frameState, feature);
510+
var color = defined(style.color) ? style.color.evaluateColor(frameState, feature, scratchColor) : DEFAULT_COLOR_VALUE;
511+
var show = defined(style.show) ? style.show.evaluate(frameState, feature) : DEFAULT_SHOW_VALUE;
509512
this.setColor(i, color);
510513
this.setShow(i, show);
511514
}

Source/Scene/Cesium3DTileStyle.js

+104-53
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ define([
2222
Expression) {
2323
'use strict';
2424

25-
var DEFAULT_JSON_COLOR_EXPRESSION = 'color("#ffffff")';
26-
var DEFAULT_JSON_BOOLEAN_EXPRESSION = true;
27-
var DEFAULT_JSON_NUMBER_EXPRESSION = 1.0;
28-
2925
/**
3026
* A style that is applied to a {@link Cesium3DTileset}.
3127
* <p>
@@ -95,49 +91,13 @@ define([
9591

9692
styleJson = defaultValue(styleJson, defaultValue.EMPTY_OBJECT);
9793

98-
that._colorShaderFunctionReady = !defined(styleJson.color);
99-
that._showShaderFunctionReady = !defined(styleJson.show);
100-
that._pointSizeShaderFunctionReady = !defined(styleJson.pointSize);
101-
102-
var colorExpression = defaultValue(styleJson.color, DEFAULT_JSON_COLOR_EXPRESSION);
103-
var showExpression = defaultValue(styleJson.show, DEFAULT_JSON_BOOLEAN_EXPRESSION);
104-
var pointSizeExpression = defaultValue(styleJson.pointSize, DEFAULT_JSON_NUMBER_EXPRESSION);
105-
106-
var defines = styleJson.defines;
107-
108-
var color;
109-
if (typeof colorExpression === 'string') {
110-
color = new Expression(colorExpression, defines);
111-
} else if (defined(colorExpression.conditions)) {
112-
color = new ConditionsExpression(colorExpression, defines);
113-
}
114-
115-
that._color = color;
116-
117-
var show;
118-
if (typeof showExpression === 'boolean') {
119-
show = new Expression(String(showExpression), defines);
120-
} else if (typeof showExpression === 'string') {
121-
show = new Expression(showExpression, defines);
122-
} else if (defined(showExpression.conditions)) {
123-
show = new ConditionsExpression(showExpression, defines);
124-
}
125-
126-
that._show = show;
127-
128-
var pointSize;
129-
if (typeof pointSizeExpression === 'number') {
130-
pointSize = new Expression(String(pointSizeExpression), defines);
131-
} else if (typeof pointSizeExpression === 'string') {
132-
pointSize = new Expression(pointSizeExpression, defines);
133-
} else if (defined(pointSizeExpression.conditions)) {
134-
pointSize = new ConditionsExpression(pointSizeExpression, defines);
135-
}
136-
137-
that._pointSize = pointSize;
94+
that.color = styleJson.color;
95+
that.show = styleJson.show;
96+
that.pointSize = styleJson.pointSize;
13897

13998
var meta = {};
14099
if (defined(styleJson.meta)) {
100+
var defines = styleJson.defines;
141101
var metaJson = defaultValue(styleJson.meta, defaultValue.EMPTY_OBJECT);
142102
for (var property in metaJson) {
143103
if (metaJson.hasOwnProperty(property)) {
@@ -209,7 +169,8 @@ define([
209169
},
210170

211171
/**
212-
* Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>show</code> property.
172+
* 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.
173+
* The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
213174
* <p>
214175
* The expression must return or convert to a <code>Boolean</code>.
215176
* </p>
@@ -234,6 +195,28 @@ define([
234195
* return true;
235196
* }
236197
* };
198+
*
199+
* @example
200+
* var style = new Cesium.Cesium3DTileStyle();
201+
* // Override show expression with a boolean
202+
* style.show = true;
203+
* };
204+
*
205+
* @example
206+
* var style = new Cesium.Cesium3DTileStyle();
207+
* // Override show expression with a string
208+
* style.show = '${Height} > 0';
209+
* };
210+
*
211+
* @example
212+
* var style = new Cesium.Cesium3DTileStyle();
213+
* // Override show expression with a condition
214+
* style.show = {
215+
* conditions: [
216+
* ['${height} > 2', 'false'],
217+
* ['true', 'true']
218+
* ];
219+
* };
237220
*/
238221
show : {
239222
get : function() {
@@ -246,13 +229,25 @@ define([
246229
return this._show;
247230
},
248231
set : function(value) {
232+
var defines = defaultValue(this._style, defaultValue.EMPTY_OBJECT).defines;
233+
if (!defined(value)) {
234+
this._show = undefined;
235+
} else if (typeof value === 'boolean') {
236+
this._show = new Expression(String(value));
237+
} else if (typeof value === 'string') {
238+
this._show = new Expression(value, defines);
239+
} else if (defined(value.conditions)) {
240+
this._show = new ConditionsExpression(value, defines);
241+
} else {
242+
this._show = value;
243+
}
249244
this._showShaderFunctionReady = false;
250-
this._show = value;
251245
}
252246
},
253247

254248
/**
255-
* Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>color</code> property.
249+
* 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.
250+
* The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
256251
* <p>
257252
* The expression must return a <code>Color</code>.
258253
* </p>
@@ -277,6 +272,21 @@ define([
277272
* return Cesium.Color.clone(Cesium.Color.WHITE, result);
278273
* }
279274
* };
275+
*
276+
* @example
277+
* var style = new Cesium.Cesium3DTileStyle();
278+
* // Override color expression with a string
279+
* style.color = 'color("blue")';
280+
*
281+
* @example
282+
* var style = new Cesium.Cesium3DTileStyle();
283+
* // Override color expression with a condition
284+
* style.color = {
285+
* conditions : [
286+
* ['${height} > 2', 'color("cyan")'],
287+
* ['true', 'color("blue")']
288+
* ]
289+
* };
280290
*/
281291
color : {
282292
get : function() {
@@ -289,13 +299,23 @@ define([
289299
return this._color;
290300
},
291301
set : function(value) {
302+
var defines = defaultValue(this._style, defaultValue.EMPTY_OBJECT).defines;
303+
if (!defined(value)) {
304+
this._color = undefined;
305+
} else if (typeof value === 'string') {
306+
this._color = new Expression(value, defines);
307+
} else if (defined(value.conditions)) {
308+
this._color = new ConditionsExpression(value, defines);
309+
} else {
310+
this._color = value;
311+
}
292312
this._colorShaderFunctionReady = false;
293-
this._color = value;
294313
}
295314
},
296315

297316
/**
298-
* Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>pointSize</code> property.
317+
* 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.
318+
* The getter will return the internal {@link Expression} or {@link ConditionsExpression}, which may differ from the value provided to the setter.
299319
* <p>
300320
* The expression must return or convert to a <code>Number</code>.
301321
* </p>
@@ -320,6 +340,26 @@ define([
320340
* return 1.0;
321341
* }
322342
* };
343+
*
344+
* @example
345+
* var style = new Cesium.Cesium3DTileStyle();
346+
* // Override pointSize expression with a number
347+
* style.pointSize = 1.0;
348+
*
349+
* @example
350+
* var style = new Cesium.Cesium3DTileStyle();
351+
* // Override pointSize expression with a string
352+
* style.pointSize = '${height} / 10';
353+
*
354+
* @example
355+
* var style = new Cesium.Cesium3DTileStyle();
356+
* // Override pointSize expression with a condition
357+
* style.pointSize = {
358+
* conditions : [
359+
* ['${height} > 2', '1.0'],
360+
* ['true', '2.0']
361+
* ]
362+
* };
323363
*/
324364
pointSize : {
325365
get : function() {
@@ -332,8 +372,19 @@ define([
332372
return this._pointSize;
333373
},
334374
set : function(value) {
375+
var defines = defaultValue(this._style, defaultValue.EMPTY_OBJECT).defines;
376+
if (!defined(value)) {
377+
this._pointSize = undefined;
378+
} else if (typeof value === 'number') {
379+
this._pointSize = new Expression(String(value));
380+
} else if (typeof value === 'string') {
381+
this._pointSize = new Expression(value, defines);
382+
} else if (defined(value.conditions)) {
383+
this._pointSize = new ConditionsExpression(value, defines);
384+
} else {
385+
this._pointSize = value;
386+
}
335387
this._pointSizeShaderFunctionReady = false;
336-
this._pointSize = value;
337388
}
338389
},
339390

@@ -389,7 +440,7 @@ define([
389440
}
390441

391442
this._colorShaderFunctionReady = true;
392-
this._colorShaderFunction = this.color.getShaderFunction(functionName, attributePrefix, shaderState, 'vec4');
443+
this._colorShaderFunction = defined(this.color) ? this.color.getShaderFunction(functionName, attributePrefix, shaderState, 'vec4') : undefined;
393444
return this._colorShaderFunction;
394445
};
395446

@@ -411,7 +462,7 @@ define([
411462
}
412463

413464
this._showShaderFunctionReady = true;
414-
this._showShaderFunction = this.show.getShaderFunction(functionName, attributePrefix, shaderState, 'bool');
465+
this._showShaderFunction = defined(this.show) ? this.show.getShaderFunction(functionName, attributePrefix, shaderState, 'bool') : undefined;
415466
return this._showShaderFunction;
416467
};
417468

@@ -433,7 +484,7 @@ define([
433484
}
434485

435486
this._pointSizeShaderFunctionReady = true;
436-
this._pointSizeShaderFunction = this.pointSize.getShaderFunction(functionName, attributePrefix, shaderState, 'float');
487+
this._pointSizeShaderFunction = defined(this.pointSize) ? this.pointSize.getShaderFunction(functionName, attributePrefix, shaderState, 'float') : undefined;
437488
return this._pointSizeShaderFunction;
438489
};
439490

Source/Widgets/Cesium3DTilesInspector/Cesium3DTilesInspectorViewModel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ define([
10141014
// Restore original color to feature that is no longer selected
10151015
var frameState = this._scene.frameState;
10161016
if (!this.colorize && defined(this._style)) {
1017-
currentFeature.color = this._style.color.evaluateColor(frameState, currentFeature, scratchColor);
1017+
currentFeature.color = defined(this._style.color) ? this._style.color.evaluateColor(frameState, currentFeature, scratchColor) : Color.WHITE;
10181018
} else {
10191019
currentFeature.color = oldColor;
10201020
}

0 commit comments

Comments
 (0)