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 - Ternary Functions #4709

Closed
wants to merge 16 commits into from

Conversation

Dylan-Brown
Copy link
Contributor

@Dylan-Brown Dylan-Brown commented Dec 1, 2016

PR for issue #4694
Code hasn't fully addressed issue; still need to do a few things

  • Evaluate if data driven approach is feasible for clamp and lerp / mix, given my comments in the issue
  • Insert an example into 3D Tiles Point Cloud Styling.html
  • Write tests in ExpressionSpec.js
  • Update 3d-tiles repo's Styling README.md

@Dylan-Brown
Copy link
Contributor Author

@lilleyse I think there's an issue here with the typing; It's not recognizing the 'new Expression(...)', because on the nextline, it's saying something about not being able to get the shader expression for an undefined expression. I'm reading through Expression.js and seeing if there's anything that could hint at what's wrong, but so far I haven't found anything

@lilleyse
Copy link
Contributor

lilleyse commented Dec 5, 2016

The ternaryFunctions check isn't handled in parseCall, which may be the cause of that issue.

createRuntimeAst(expression, args[1]),
createRuntimeAst(expression, args[2])
];
return new Node(ExpressionNodeType.TERNARY, call, val);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of sending the values this should assign the left, right, and test, similar to here: https://github.com/AnalyticalGraphicsInc/cesium/pull/4688/files#diff-113136b97bec6733c699e609394258e1R379

Copy link
Contributor

Choose a reason for hiding this comment

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

And place this block after the unary functions. You may want to wait for #4688 to be merged first to avoid conflicts.

function getEvaluateTernaryFunction(call) {
var evaluate = ternaryFunctions[call];
return function(feature) {
return evaluate(this._left.evaluate(feature));
Copy link
Contributor

Choose a reason for hiding this comment

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

} else if (value === 'cos') {
return 'cos(' + left + ')';
} else if (value === 'sqrt') {
return 'sqrt(' + left + ')';
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch fixing these.

@@ -25,7 +25,8 @@ define([
LITERAL_COLOR : 13,
LITERAL_REGEX : 14,
LITERAL_UNDEFINED : 15,
LITERAL_GLOBAL : 16
LITERAL_GLOBAL : 16,
TERNARY : 17
Copy link
Contributor

Choose a reason for hiding this comment

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

Place this above BINARY and shift all the numbers.

@@ -699,7 +699,7 @@ define([
};

/**
* Constraint a value to lie between two values.
* Constraints a value to lie between two values.
Copy link
Contributor

Choose a reason for hiding this comment

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

Constrains?

degrees : CesiumMath.toDegrees
sin : Math.sin,
sqrt : Math.sqrt,
tan : Math.tan
Copy link
Contributor

Choose a reason for hiding this comment

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

This may need a bit organization just to group cos/sin/tan together and near the acos/asin/atan.


var ternaryFunctions = {
clamp : CesiumMath.clamp,
mix: CesiumMath.lerp
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to mix : CesiumMath.lerp.

case ExpressionNodeType.TERNARY:
if (defined(ternaryFunctions[value])) {
return value + '(' + left + ', ' + right + ', ' + test + ')';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Place this near the unary functions.

Copy link
Contributor Author

@Dylan-Brown Dylan-Brown Dec 7, 2016

Choose a reason for hiding this comment

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

@lilleyse So, now the shader expression test cases are passing, but the test cases for 'evaluates clamp function' and 'evaluates mix function' don't make sense; for mix, "Expected NaN to equal 1." is the error message, and "DeveloperError: max is required." for clamp. These don't make sense to me, since three arguments are passed for clamp and mix doesn't seem to be getting any arguments, given that the result is NaN.

Copy link
Contributor Author

@Dylan-Brown Dylan-Brown Dec 15, 2016

Choose a reason for hiding this comment

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

@lilleyse isExactClass, isClass, getExactClassName are functions that are also now failing in my code. The only other place I see this referernced is in PR #4625
Actually, nevermind, build is passing. Should be done!

LITERAL_UNDEFINED : 15,
LITERAL_GLOBAL : 16
TERNARY : 2,
BINARY : 3,
Copy link
Contributor

Choose a reason for hiding this comment

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

Place ternary after binary.

function getEvaluateTernaryFunction(call) {
var evaluate = ternaryFunctions[call];
return function(feature) {
return evaluate(this._left.evaluate(feature), this._right.evaluate(feature));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be:
return evaluate(this._left.evaluate(feature), this._right.evaluate(feature), this._test.evaluate(feature));

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -647,6 +662,8 @@ define([
if (node._value === 'TILES3D_TILESET_TIME') {
node.evaluate = evaluateTime;
}
} else if (node._type === ExpressionNodeType.TERNARY) {
node.evaluate = getEvaluateTernaryFunction(node._value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Place after binary. Also can you put the unary before binary in this function - not caused by you but it's good for consistency.

@lilleyse
Copy link
Contributor

It lists 132 files as changed. Did you merge master into this at any point?

@Dylan-Brown
Copy link
Contributor Author

@lilleyse I had merged from 3d-tiles, I believe, because I had a merge conflict... I'll try and revert the other changes

@Dylan-Brown
Copy link
Contributor Author

@lilleyse I opened a new PR, #4761, that only includes one commit from me and is otherwise even with 3d-tiles. I must have merged from master in this one; apologies. I am closing this PR and I believe you will find the new one to contain all the code I've written for this one, but without the other files changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants