Difference between revisions of "SFM/Expression Operator"

From Valve Developer Community
< SFM
Jump to: navigation, search
m (Functions)
Line 1: Line 1:
== DmeExpressionOperator ==
+
''DmeExpressionOperator'' is a DmeOperator that writes to its "value" float attribute the evaluated expression stored in its "expr" string attribute.
 
 
DmeExpressionOperator is a DmeOperator that writes to its "value" float attribute the evaluated expression stored in its "expr" string attribute.
 
 
The expression can read other float attributes on the DmeExpressionOperator, and can nest arbitrarily deep.
 
The expression can read other float attributes on the DmeExpressionOperator, and can nest arbitrarily deep.
 
For example, the expression "clamp(distance * cos(angle), 0, 10)" will cause the DmeExpressionOperator to write a value between 0 and 10 into its "value" attribute, depending upon the value of its "distance" and "angle" float attributes.
 
For example, the expression "clamp(distance * cos(angle), 0, 10)" will cause the DmeExpressionOperator to write a value between 0 and 10 into its "value" attribute, depending upon the value of its "distance" and "angle" float attributes.
  
=== Operator Precedence ===
+
== Operator Precedence ==
  
 
* unary operators: + - ! func var
 
* unary operators: + - ! func var
Line 16: Line 14:
 
* ?:
 
* ?:
  
=== Functions ===
+
== Functions ==
 +
 
 +
; dtor(d) : converts degrees to radians
 +
; rtod(r) : converts radians to degrees
  
* dtor(d) : converts degrees to radians
+
; abs(a)    : absolute value
* rtod(r) : converts radians to degrees
+
; floor(a)  : rounds down to the nearest integer
 +
; ceiling(a) : rounds up to the nearest integer
 +
; round(a)   : rounds to the nearest integer
 +
; sgn(a)    : if a < 0 returns -1 else 1
 +
; sqr(a)    : returns a * a
 +
; sqrt(a)   : returns sqrt(a)
  
* abs(a)    : absolute value
+
; sin(a)    : sin(a), a is in degrees
* floor(a)   : rounds down to the nearest integer
+
; asin(a)   : asin(a) returns degrees
* ceiling(a) : rounds up to the nearest integer
+
; cos(a)    : cos(a), a is in degrees
* round(a)   : rounds to the nearest integer
+
; acos(a)   : acos(a) returns degrees
* sgn(a)    : if a < 0 returns -1 else 1
+
; tan(a)     : tan(a), a is in degrees
* sqr(a)     : returns a * a
 
* sqrt(a)   : returns sqrt(a)
 
  
* sin(a)     : sin(a), a is in degrees
+
; exp(a)   : returns the exponential function of a
* asin(a)    : asin(a) returns degrees
+
; log(a)   : returns the natural logarithm of a
* cos(a)    : cos(a), a is in degrees
 
* acos(a)   : acos(a) returns degrees
 
* tan(a)    : tan(a), a is in degrees
 
  
* exp(a)   : returns the exponential function of a
+
; min(a,b)     : if a < b returns a else b
* log(a)   : returns the natural logarithm of a
+
; max(a,b)    : if a > b returns a else b
 +
; atan2(a,b) : atan(a/b) returns degrees (it's Arg(b+ia) actually)
 +
; pow(a,b) : function returns a raised to the power of b
  
* min(a,b)     : if a < b returns a else b
+
; inrange(x,a,b) : if x is between a and b, returns 1 else returns 0
* max(a,b)     : if a > b returns a else b
+
; clamp(x,a,b)   : if x < a returns a else if x > b returns b else returns x
* atan2(a,b) : atan(a/b) returns degrees (it's Arg(b+ia) actually)
 
* pow(a,b) : function returns a raised to the power of b
 
  
* inrange(x,a,b) : if x is between a and b, returns 1 else returns 0
+
; ramp(value,a,b)       : returns 0 -> 1 as value goes from a to b
* clamp(x,a,b)   : if x < a returns a else if x > b returns b else returns x
+
; lerp(factor,a,b)       : returns a -> b as factor goes from 0 to 1
  
* ramp(value,a,b)        : returns 0 -> 1 as value goes from a to b
+
; cramp(value,a,b)        : clamp(ramp(value,a,b),0,1)
* lerp(factor,a,b)      : returns a -> b as factor goes from 0 to 1
+
; clerp(factor,a,b)      : clamp(lerp(factor,a,b),a,b)
  
* cramp(value,a,b)       : clamp(ramp(value,a,b),0,1)
+
; elerp(x,a,b)         : ramp( 3*x*x - 2*x*x*x, a, b)
* clerp(factor,a,b)      : clamp(lerp(factor,a,b),a,b)
 
  
* elerp(x,a,b)         : ramp( 3*x*x - 2*x*x*x, a, b)
+
; noise(a,b,c) : { solid noise pattern (improved perlin noise) indexed with three numbers }
  
* noise(a,b,c) : { solid noise pattern (improved perlin noise) indexed with three numbers }
+
; rescale (X,Xa,Xb,Ya,Yb) : lerp(ramp(X,Xa,Xb),Ya,Yb)
 +
; crescale(X,Xa,Xb,Ya,Yb) : clamp(rescale(X,Xa,Xb,Ya,Yb),Ya,Yb)
  
* rescale (X,Xa,Xb,Ya,Yb) : lerp(ramp(X,Xa,Xb),Ya,Yb)
+
{{shortpagetitle}}
* crescale(X,Xa,Xb,Ya,Yb) : clamp(rescale(X,Xa,Xb,Ya,Yb),Ya,Yb)
+
[[Category:Source Filmmaker]]

Revision as of 00:16, 6 September 2014

DmeExpressionOperator is a DmeOperator that writes to its "value" float attribute the evaluated expression stored in its "expr" string attribute. The expression can read other float attributes on the DmeExpressionOperator, and can nest arbitrarily deep. For example, the expression "clamp(distance * cos(angle), 0, 10)" will cause the DmeExpressionOperator to write a value between 0 and 10 into its "value" attribute, depending upon the value of its "distance" and "angle" float attributes.

Operator Precedence

  • unary operators: + - ! func var
  • * / %
  • + -
  • < > <= >=
  • == !=
  • &&
  • ||
  •  ?:

Functions

dtor(d) 
converts degrees to radians
rtod(r) 
converts radians to degrees
abs(a)  
absolute value
floor(a)  
rounds down to the nearest integer
ceiling(a) 
rounds up to the nearest integer
round(a)  
rounds to the nearest integer
sgn(a)  
if a < 0 returns -1 else 1
sqr(a)  
returns a * a
sqrt(a)  
returns sqrt(a)
sin(a)  
sin(a), a is in degrees
asin(a)  
asin(a) returns degrees
cos(a)  
cos(a), a is in degrees
acos(a)  
acos(a) returns degrees
tan(a)  
tan(a), a is in degrees
exp(a)  
returns the exponential function of a
log(a)  
returns the natural logarithm of a
min(a,b)  
if a < b returns a else b
max(a,b)  
if a > b returns a else b
atan2(a,b) 
atan(a/b) returns degrees (it's Arg(b+ia) actually)
pow(a,b) 
function returns a raised to the power of b
inrange(x,a,b) 
if x is between a and b, returns 1 else returns 0
clamp(x,a,b)  
if x < a returns a else if x > b returns b else returns x
ramp(value,a,b)  
returns 0 -> 1 as value goes from a to b
lerp(factor,a,b)  
returns a -> b as factor goes from 0 to 1
cramp(value,a,b)  
clamp(ramp(value,a,b),0,1)
clerp(factor,a,b)  
clamp(lerp(factor,a,b),a,b)
elerp(x,a,b)  
ramp( 3*x*x - 2*x*x*x, a, b)
noise(a,b,c) 
{ solid noise pattern (improved perlin noise) indexed with three numbers }
rescale (X,Xa,Xb,Ya,Yb) 
lerp(ramp(X,Xa,Xb),Ya,Yb)
crescale(X,Xa,Xb,Ya,Yb) 
clamp(rescale(X,Xa,Xb,Ya,Yb),Ya,Yb)