SFM/Expression Operator: Difference between revisions

From Valve Developer Community
< SFM
Jump to navigation Jump to search
(SFM Expression Operator)
 
m (clean up, added orphan, deadend tags)
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== DmeExpressionOperator ==
{{Multiple issues|
{{Dead end|date=January 2024}}
{{Orphan|date=January 2024}}
}}


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 expression 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 19:
* ?:
* ?:


=== Functions ===
== Functions ==


* dtor(d) : converts degrees to radians
; dtor(d) : converts degrees to radians
* rtod(r) : converts radians to degrees
; rtod(r) : converts radians to degrees


* abs(a)    : absolute value
; abs(a)    : absolute value
* floor(a)  : rounds down to the nearest integer
; floor(a)  : rounds down to the nearest integer
* ceiling(a) : rounds up to the nearest integer
; ceiling(a) : rounds up to the nearest integer
* round(a)  : rounds to the nearest integer
; round(a)  : rounds to the nearest integer
* sgn(a)    : if a < 0 returns -1 else 1
; sgn(a)    : if a < 0 returns -1 else 1
* sqr(a)    : returns a * a
; sqr(a)    : returns a * a
* sqrt(a)    : returns sqrt(a)
; sqrt(a)    : returns sqrt(a)


* sin(a)    : sin(a), a is in degrees
; sin(a)    : sin(a), a is in degrees
* asin(a)    : asin(a) returns degrees
; asin(a)    : asin(a) returns degrees
* cos(a)    : cos(a), a is in degrees
; cos(a)    : cos(a), a is in degrees
* acos(a)    : acos(a) returns degrees
; acos(a)    : acos(a) returns degrees
* tan(a)    : tan(a), a is in degrees
; tan(a)    : tan(a), a is in degrees


* exp(a)  : returns the exponential function of a
; exp(a)  : returns the exponential function of a
* log(a)  : returns the natural logarithm of a
; log(a)  : returns the natural logarithm of a


* min(a,b)    : if a < b returns a else b
; min(a,b)    : if a < b returns a else b
* max(a,b)    : if a > b returns a else b
; max(a,b)    : if a > b returns a else b
* atan2(a,b) : atan2(a/b) returns degrees
; atan2(a,b) : atan(a/b) returns radians (it's Arg(b+ia) actually)
* pow(a,b) : function returns a raised to the power of b
; 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
; inrange(x,a,b) : if x is between a and b, returns 1 else returns 0
* clamp(x,a,b)  : see bound() above
; 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
; ramp(value,a,b)        : returns 0 -> 1 as value goes from a to b
* lerp(factor,a,b)      : returns a -> b as value goes from 0 to 1
; 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)
; cramp(value,a,b)        : clamp(ramp(value,a,b),0,1)
* clerp(factor,a,b)      : clamp(lerp(factor,a,b),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)
; 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)
; 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)
; crescale(X,Xa,Xb,Ya,Yb) : clamp(rescale(X,Xa,Xb,Ya,Yb),Ya,Yb)
 
*'''Note''' : arithmetic priorites may not work as intended (for instance, 0-0+3 = -3), so adding brackets might be needed.
 
{{shortpagetitle}}
 
[[Category:Source Filmmaker]]

Latest revision as of 10:10, 21 January 2024

Wikipedia - Letter.png
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)
Dead End - Icon.png
This article has no Wikipedia icon links to other VDC articles. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024

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 radians (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)
  • Note : arithmetic priorites may not work as intended (for instance, 0-0+3 = -3), so adding brackets might be needed.