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

3D Tiles - Point Cloud Styling #4336

Merged
merged 31 commits into from Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
41fc014
pnts shader styling
lilleyse Sep 19, 2016
46d00e3
Merge branch '3d-tiles' into pnts-styling
lilleyse Sep 20, 2016
8e98836
Organization
lilleyse Sep 20, 2016
b7c2dfd
Rearrange shader construction
lilleyse Sep 20, 2016
cc1c4e6
Reorganize parameters and support ARRAY type
lilleyse Sep 27, 2016
5cb1088
Change conditions from an object to an array
lilleyse Sep 27, 2016
758ebb2
Change how result params are used
lilleyse Sep 27, 2016
9d2838e
Stricter type comparisons
lilleyse Sep 27, 2016
096b15b
Reset scratch index for Expression.evaluate
lilleyse Sep 28, 2016
976f32f
Fix tests
lilleyse Sep 28, 2016
953f9be
Merge branch '3d-tiles' into pnts-styling
lilleyse Sep 28, 2016
1fd4b27
Calculate literal colors right away
lilleyse Sep 28, 2016
dbd681d
Limit array length
lilleyse Sep 28, 2016
75beb23
Added Point Cloud Styling sandcastle
lilleyse Sep 28, 2016
72ee217
Add back TODO
lilleyse Sep 28, 2016
88903d5
More detailed shader error messages, removed type-checking errors in …
lilleyse Sep 29, 2016
62ecd50
Revert ExpressionSpec
lilleyse Sep 29, 2016
7754b66
Reorganzation of styleContent
lilleyse Sep 29, 2016
cab3705
Add BATCH_ID comment
lilleyse Sep 30, 2016
464cee8
Added ability to style based on POSITION, COLOR, and NORMAL semantics
lilleyse Sep 30, 2016
18be9d6
Support DOUBLE, INT, and UNSIGNED_INT point cloud style properties
lilleyse Sep 30, 2016
079d6f6
Added tests
lilleyse Oct 4, 2016
6d8a879
Tweak test for OIT
lilleyse Oct 10, 2016
84d8ff7
Log warning for float conversion
lilleyse Oct 10, 2016
a217024
Style point size
lilleyse Oct 10, 2016
55cf834
Change === to == and !== to !=
lilleyse Oct 10, 2016
8823472
Rename size to pointSize
lilleyse Oct 18, 2016
c04ff78
Support both === and !==
lilleyse Oct 18, 2016
f0f86ad
Merge branch '3d-tiles' into pnts-styling
lilleyse Oct 18, 2016
83efc1b
Fix styling edge case
lilleyse Oct 18, 2016
45d96d8
Merge branch '3d-tiles' into pnts-styling
lilleyse Oct 18, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Apps/Sandcastle/gallery/3D Tiles Point Cloud Styling.html
Expand Up @@ -129,6 +129,11 @@
color : "rgb(${POSITION}[0] * 255, ${POSITION}[1] * 255, ${POSITION}[2] * 255)"
});

addStyle('Style point size', {
color : "color('red')",
size : "${temperature} * 10"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call this size? Why not call it precisely what it is: pointSize, and in the reference doc explain that it defines the point size in pixels when styling point cloud tiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was a generic name would be good for other sizeable things thing billboards. If fine with either way.

});

function setStyle(style) {
tileset.style = new Cesium.Cesium3DTileStyle(style);
}
Expand Down
86 changes: 86 additions & 0 deletions Source/Scene/Cesium3DTileStyle.js
Expand Up @@ -27,6 +27,7 @@ define([

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

/**
* Evaluates an expression defined using the
Expand Down Expand Up @@ -60,12 +61,15 @@ define([
this._readyPromise = when.defer();
this._color = undefined;
this._show = undefined;
this._size = undefined;
this._meta = undefined;

this._colorShaderFunction = undefined;
this._showShaderFunction = undefined;
this._sizeShaderFunction = undefined;
this._colorShaderFunctionReady = false;
this._showShaderFunctionReady = false;
this._sizeShaderFunctionReady = false;

var style = this;
if (typeof data === 'string') {
Expand Down Expand Up @@ -96,8 +100,13 @@ define([
that._showShaderFunctionReady = true;
}

if (!defined(styleJson.size)) {
that._sizeShaderFunctionReady = true;
}

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

var color;
if (typeof(colorExpression) === 'string') {
Expand All @@ -119,6 +128,17 @@ define([

that._show = show;

var size;
if (typeof(sizeExpression) === 'number') {
size = new Expression(String(sizeExpression));
} else if (typeof(sizeExpression) === 'string') {
size = new Expression(sizeExpression);
} else if (defined(sizeExpression.conditions)) {
size = new ConditionsExpression(sizeExpression);
}

that._size = size;

var meta = {};
if (defined(styleJson.meta)) {
var metaJson = defaultValue(styleJson.meta, defaultValue.EMPTY_OBJECT);
Expand Down Expand Up @@ -279,6 +299,50 @@ define([
}
},

/**
* Gets or sets the {@link StyleExpression} object used to evaluate the style's <code>size</code> property.
* <p>
* The expression must return or convert to a <code>Number</code>.
* </p>
*
* @memberof Cesium3DTileStyle.prototype
*
* @type {StyleExpression}
*
* @exception {DeveloperError} The style is not loaded. Use Cesium3DTileStyle.readyPromise or wait for Cesium3DTileStyle.ready to be true.
*
* @example
* var style = new Cesium3DTileStyle({
* size : '(${Temperature} > 90) ? 2.0 : 1.0'
* });
* style.size.evaluate(feature); // returns a Number
*
* @example
* var style = new Cesium.Cesium3DTileStyle();
* // Override size expression with a custom function
* style.size = {
* evaluate : function(feature) {
* return 1.0;
* }
* };
*
* @see {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/Styling|3D Tiles Styling language}
*/
size : {
get : function() {
//>>includeStart('debug', pragmas.debug);
if (!this._ready) {
throw new DeveloperError('The style is not loaded. Use Cesium3DTileStyle.readyPromise or wait for Cesium3DTileStyle.ready to be true.');
}
//>>includeEnd('debug');

return this._size;
},
set : function(value) {
this._size = value;
}
},

/**
* Gets or sets the object containing application-specific expression that can be explicitly
* evaluated, e.g., for display in a UI.
Expand Down Expand Up @@ -359,5 +423,27 @@ define([
return this._showShaderFunction;
};

/**
* Gets the size shader function for this style.
*
* @param {String} functionName Name to give to the generated function.
* @param {String} attributePrefix Prefix that is added to any variable names to access vertex attributes.
* @param {Object} shaderState Stores information about the generated shader function, including whether it is translucent.
*
* @returns {String} The shader function.
*
* @private
*/
Cesium3DTileStyle.prototype.getSizeShaderFunction = function(functionName, attributePrefix, shaderState) {
if (this._sizeShaderFunctionReady) {
// Return the cached result, may be undefined
return this._sizeShaderFunction;
}

this._sizeShaderFunctionReady = true;
this._sizeShaderFunction = this.size.getShaderFunction(functionName, attributePrefix, shaderState, 'float');
return this._sizeShaderFunction;
};

return Cesium3DTileStyle;
});
6 changes: 2 additions & 4 deletions Source/Scene/Cesium3DTileStyleEngine.js
Expand Up @@ -2,13 +2,11 @@
define([
'../Core/Color',
'../Core/defined',
'../Core/defineProperties',
'./PointCloud3DTileContent'
'../Core/defineProperties'
], function(
Color,
defined,
defineProperties,
PointCloud3DTileContent) {
defineProperties) {
'use strict';

/**
Expand Down
21 changes: 19 additions & 2 deletions Source/Scene/PointCloud3DTileContent.js
Expand Up @@ -820,6 +820,7 @@ define([

var colorStyleFunction;
var showStyleFunction;
var sizeStyleFunction;
var styleTranslucent = isTranslucent;

if (hasBatchTable) {
Expand All @@ -833,13 +834,15 @@ define([
};
colorStyleFunction = style.getColorShaderFunction('getColorFromStyle', 'czm_tiles3d_style_', shaderState);
showStyleFunction = style.getShowShaderFunction('getShowFromStyle', 'czm_tiles3d_style_', shaderState);
sizeStyleFunction = style.getSizeShaderFunction('getSizeFromStyle', 'czm_tiles3d_style_', shaderState);
styleTranslucent = shaderState.translucent;
}

content._styleTranslucent = styleTranslucent;

var hasColorStyle = defined(colorStyleFunction);
var hasShowStyle = defined(showStyleFunction);
var hasSizeStyle = defined(sizeStyleFunction);

// Get the properties in use by the style
var styleableProperties = [];
Expand All @@ -855,6 +858,11 @@ define([
getStyleableSemantics(showStyleFunction, styleableSemantics);
showStyleFunction = modifyStyleFunction(showStyleFunction);
}
if (hasSizeStyle) {
getStyleableProperties(sizeStyleFunction, styleableProperties);
getStyleableSemantics(sizeStyleFunction, styleableSemantics);
sizeStyleFunction = modifyStyleFunction(sizeStyleFunction);
}

var usesColorSemantic = styleableSemantics.indexOf('COLOR') >= 0;
var usesNormalSemantic = styleableSemantics.indexOf('NORMAL') >= 0;
Expand Down Expand Up @@ -966,6 +974,10 @@ define([
vs += showStyleFunction;
}

if (hasSizeStyle) {
vs += sizeStyleFunction;
}

vs += 'void main() \n' +
'{ \n';

Expand Down Expand Up @@ -1012,6 +1024,12 @@ define([
vs += ' float show = float(getShowFromStyle(position, color, normal)); \n';
}

if (hasSizeStyle) {
vs += ' gl_PointSize = getSizeFromStyle(position, color, normal); \n';
} else {
vs += ' gl_PointSize = u_pointSize; \n';
}

vs += ' color = color * u_highlightColor; \n';

if (hasNormals) {
Expand All @@ -1022,8 +1040,7 @@ define([
}

vs += ' v_color = color; \n' +
' gl_Position = czm_modelViewProjection * vec4(position, 1.0); \n' +
' gl_PointSize = u_pointSize; \n';
' gl_Position = czm_modelViewProjection * vec4(position, 1.0); \n';

if (hasNormals && backFaceCulling) {
vs += ' float visible = step(-normal.z, 0.0); \n' +
Expand Down
3 changes: 2 additions & 1 deletion Specs/Data/Cesium3DTiles/Style/style.json
@@ -1,4 +1,5 @@
{
"color" : "color('red')",
"show" : "${id} < 100"
"show" : "${id} < 100",
"size" : "${id} / 100"
}