Documentation/Conditional RIB
From PixieWiki
Contents |
[edit] Introduction
Conditional RIB allows a single rib file to be reused in multiple renders with different settings. For example, you might choose to set options or attributes conditionally, or to swap shaders.
This is most often combined with user attributes.
For example:
Option "user" "string mode" "bake" #Option "user" "string mode" "read" IfBegin "$Option:user:mode == 'bake'" Attribute "dice" "rasterorient" 0 Attribute "cull" "backfacing" 0 Attribute "cull" "hidden" 0 Surface "bakingShader" Else Suface "readingShader" IfEnd
[edit] New RIB Commands
IfBegin "<expression>"
All command until either ElseIf, Else or End will only be executed if "<condition>" evaluates to true.
Else
Commands until End will be executed if "<condition>" did not evaluate to true.
ElseIf "<condition>"
Allows complex conditions to be built up.
End
Ends conditional RIB evaluation.
Conditions may be nested.
[edit] Conditions
Conditions can take the following form:
- $variable
- look up an attribute or option
- * / + -
- float or integer aritmetic
- (<expr>)
- evaluate a subexpression
- == != < <= >= >
- evaluate comparison between two expressions, strings may be compared with == or !=
- && || !
- boolean operation on subexpressions (as in C)
- 'string literal'
- a string constant expression
- 123
- a number constant
- defined(variable)
- is an option or attribute defined
- concat(expr1,expr2)
- concatenate two string subexpressions
- $(expr)
- look up a variable who'se name is the result of the string expression expr
Options may be looked up with $Option:<optionname>, and attributes with $Attribute:<attributename>. User options and attributes are therefore $Option:user:<optionname> and $Attribute:user:<optionname> respectively.
[edit] New C Commands
Conditional RIB is also available via the C Ri Interface (in ri.h):
RtVoid RiIfBegin(char *expr, ...), RtVoid RiIfBeginV(char *expr, RtInt n, RtToken tokens[], RtPointer parms[]), RtVoid RiElseIf(char *expr, ...), RtVoid RiElseIfV(char *expr, RtInt n, RtToken tokens[], RtPointer parms[]), RtVoid RiElse(void), RtVoid RiIfEnd(void);