HDK
|
The OP_Parameters class (parent of OP_Node) provides basic functionality for using parameters. It contains a PRM_ParmList object which owns an array of PRM_Parm objects. Each PRM_Parm object can have a number of components. Each parameter component has an optional channel (CH_Channel class). For example, the Translate parameter "t" has 3 components with channel names "tx", "ty", and "tz" respectively.
Given a node, parameters can be looked up either by name or by index. The recommended approach is to always look up parameters by name. The parameter name to index translation is fairly fast since it uses hash tables.
The value of a particular parameter can be obtained using the various parameter evaluation functions in OP_Parameters. To set the value on parameter component, use the various parameter setting functions.
In both cases, it is also necessary to supply the evaluation time. Often times, this information is already given to you as explicit function parameter, or indirectly via an OP_Context parameter. If given an OP_Context object, simply use OP_Context::getTime(). In absence of this, you can obtain the current evaluation time via the CHgetEvalTime() function.
When evaluating parameters, there are always two forms of each eval function: one explicitly supplying the "thread" id parameter, and another that simply uses SYSgetSTID() as the thread id. If you have an OP_Context parameter, you can use the explicit thread id version of the eval function by passing it the return value of OP_Context::getThread().
Multi-parms are dynamically sized parameters. Each multi-parm has a variable number of child instances. Each multi-parm child instance itself consists of a fixed number of parameters (defined by the same array of PRM_Template objects). To determine how many child instances a multi-parm has, simply evaluate the multi-parm as an integer value. In order to identify the instances, the token name of the child parameters must include a pound (#) character when the multi-parm is being defined. If the child multi-parm instance also contains a multi-parm, then the instance parameters of the "nested" multi-parm must include an additional pound (#) character. In general, a parameter token name must have exactly one pound (#) character for each of its parent multi-parms.
When new multi-parm child instance parameters are created, the pound (#) character is substituted with the instance index as the actual parameter name. Note that the starting index can be any arbitrary number but it is usually 0 or 1.
In OP_Parameters, there are Inst
versions of the eval
and set
functions specifically geared for multi-parms (eg. OP_Parameters::evalFloatInst() and OP_Parameters::setFloatInst()). These functions take an array of instance indices (inst
parameter), along with the length of the array (nestlevel
parameter). The nestlevel
parameter for these functions default to 1 so that for non-nested multi-parms, we can simply pass it the address of our single instance index.
Let's take an example from the BlendShapes SOP which has a multi-parm named "nblends" (label "Blends"). Its multi-parm instance has just one parameter named "weight#".
Ramp parameters are multi-parms that semantically represent a lookup function. Given a parametric value between 0 and 1, the ramp lookup returns an interpolated value using an array of "ramp points" as a curve. Ramp parameters have a special graphical user interface in the parameter pane and also have a standardized child instance parameter list where each instance contains the data for a ramp point. There are two different ramp types: color or float. They differ in their parameter pane user interface as well as in their instance parameter list. In scripting, and in the HDK, they can be manipulated like any other multi-parm.
To perform a lookup using a ramp parameter, OP_Parameters::updateRampFromMultiParm() provides a means of marshaling the data into a UT_Ramp object. If you modify a UT_Ramp object, you can transfer it back to the ramp parameter via OP_Parameters::updateMultiParmFromRamp().