-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from 9 commits
8c5dff0
7ec9aa7
567d840
3faddd6
bffea5d
6ee74ec
1ba1225
0f7f5c3
e618d81
273edaf
8aae757
02343dd
163bedf
b431c86
4927aa5
1a510cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,15 +47,20 @@ define([ | |
|
||
var unaryFunctions = { | ||
abs : Math.abs, | ||
sqrt : Math.sqrt, | ||
cos : Math.cos, | ||
sin : Math.sin, | ||
tan : Math.tan, | ||
acos : Math.acos, | ||
asin : Math.asin, | ||
atan : Math.atan, | ||
cos : Math.cos, | ||
degrees : CesiumMath.toDegrees, | ||
radians : CesiumMath.toRadians, | ||
degrees : CesiumMath.toDegrees | ||
sin : Math.sin, | ||
sqrt : Math.sqrt, | ||
tan : Math.tan | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to |
||
}; | ||
|
||
/** | ||
|
@@ -383,6 +388,18 @@ define([ | |
return new Node(ExpressionNodeType.UNARY, call, val); | ||
} else if (call === 'regExp') { | ||
return parseRegex(expression, ast); | ||
} else if (defined(ternaryFunctions[call])) { | ||
//>>includeStart('debug', pragmas.debug); | ||
if (args.length < 3 || args.length > 3) { | ||
throw new DeveloperError('Error: ' + call + ' requires exactly three arguments.'); | ||
} | ||
//>>includeEnd('debug'); | ||
val = [ | ||
createRuntimeAst(expression, args[0]), | ||
createRuntimeAst(expression, args[1]), | ||
createRuntimeAst(expression, args[2]) | ||
]; | ||
return new Node(ExpressionNodeType.TERNARY, call, val); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
//>>includeStart('debug', pragmas.debug); | ||
|
@@ -629,6 +646,8 @@ define([ | |
if (node._value === 'TILES3D_TILESET_TIME') { | ||
node.evaluate = evaluateTime; | ||
} | ||
} else if (node._type === ExpressionNodeType.TERNARY) { | ||
node.evaluate = getEvaluateTernaryFunction(node._value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} else { | ||
node.evaluate = node._evaluateLiteral; | ||
} | ||
|
@@ -645,6 +664,13 @@ define([ | |
}; | ||
} | ||
|
||
function getEvaluateTernaryFunction(call) { | ||
var evaluate = ternaryFunctions[call]; | ||
return function(feature) { | ||
return evaluate(this._left.evaluate(feature)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to also evaluate |
||
}; | ||
} | ||
|
||
Node.prototype._evaluateLiteral = function(frameState, feature) { | ||
return this._value; | ||
}; | ||
|
@@ -1161,12 +1187,6 @@ define([ | |
return 'float(' + left + ')'; | ||
} else if (defined(unaryFunctions[value])) { | ||
return value + '(' + left + ')'; | ||
} else if (value === 'abs') { | ||
return 'abs(' + left + ')'; | ||
} else if (value === 'cos') { | ||
return 'cos(' + left + ')'; | ||
} else if (value === 'sqrt') { | ||
return 'sqrt(' + left + ')'; | ||
} | ||
//>>includeStart('debug', pragmas.debug); | ||
else if ((value === 'isNaN') || (value === 'isFinite') || (value === 'String')) { | ||
|
@@ -1298,6 +1318,11 @@ define([ | |
if (value === 'TILES3D_TILESET_TIME') { | ||
return 'u_tilesetTime'; | ||
} | ||
break; | ||
case ExpressionNodeType.TERNARY: | ||
if (defined(ternaryFunctions[value])) { | ||
return value + '(' + left + ', ' + right + ', ' + test + ')'; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Place this near the unary functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,8 @@ define([ | |
LITERAL_COLOR : 13, | ||
LITERAL_REGEX : 14, | ||
LITERAL_UNDEFINED : 15, | ||
LITERAL_GLOBAL : 16 | ||
LITERAL_GLOBAL : 16, | ||
TERNARY : 17 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Place this above |
||
}; | ||
|
||
return freezeObject(ExpressionNodeType); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constrains?