Creating Parameter Blocks

Parameter blocks are covered in detail in the Parameter Blocks section of the documentation. This section walks through the parameter block construction used by the widget how-to sample. See the file howto/objects/widget/widget.cpp .

Defining Parameter Block and Parameter Identifiers

The first step in creating a parameter block is to define identifiers for the parameter blocks and individual parameters. This is usually done by creating enumerations.

The enumerated value that identifies the different parameter block is:

enum { widget_params };

The next set of enumerated values identify the individual parameters:

enum {
  widget_size,
  widget_left,
  widget_right
};

Describing the Parameter Block

The next step in creating a parameter block is to create a parameter block descriptor. This is done using a ParamBlockDesc2. The Widget samples declares a static ParamBlockDesc2 object named widget_param_blk.

The following is the first component of the parameter block:

 
1    static  ParamBlockDesc2 widget_param_blk ( widget_params, _T("params"), 0, &WidgetDesc,
2        P_AUTO_CONSTRUCT + P_AUTO_UI, PBLOCK_REF,
3         //rollout
4         IDD_PANEL, IDS_PARAMS, 0, 0, NULL,
5         // params
6         widget_size,         _T("size"),         TYPE_FLOAT,     P_ANIMATABLE,     IDS_SPIN,
7            p_default,       0.1f,
8            p_range,         0.0f,1000.0f,
9            p_ui,            TYPE_SPINNER,       EDITTYPE_FLOAT, IDC_EDIT,    IDC_SPIN, 0.50f,
10           p_end,

Line 1

static  ParamBlockDesc2 widget_param_blk ( widget_params, _T("params"), 0, &WidgetDesc,

The first four arguments are required. They describe the plug-in to 3ds Max, and register a rollout control to display your parameters.

widget_params
This the parameter block ID.

_T("params")
This is a string containing a name that the parameter block uses internally.

0
This the resource ID of the localized string in the resource's string table.

&WidgetDesc
The is the address of a ClassDesc2 object that describes the plug-in.

Line 2

P_AUTO_CONSTRUCT + P_AUTO_UI, PBLOCK_REF,

The optional arguments on the second line are telling 3ds Max to automatically handle the user interface.

Lines 3-4

//rollout
IDD_PANEL, IDS_PARAMS, 0, 0, NULL,

The rollout comment points to more optional arguments.

Lines 5-10

5         // params
6         widget_size,   _T("size"), TYPE_FLOAT, P_ANIMATABLE, IDS_SPIN,
7            p_default, 0.1f,
8            p_range,   0.0f, 1000.0f,
9            p_ui,      TYPE_SPINNER, EDITTYPE_FLOAT, IDC_SIZE_EDIT, IDC_SIZE_SPIN, 0.50f,
10           p_end,

The individual parameter specification for the widget size begins after the comment. A parameter block descriptor can be a variable number of individual parameter specs, ours at this point holds only one.

The rest of the parameter block describes the two other parameter: widget_left and widget_right.

    widget_left,   _T("Left"), TYPE_FLOAT, P_ANIMATABLE, IDS_SPIN,
        p_default, 0.0f,
        p_range,   0.0f,100.0f,
        p_ui,      TYPE_SPINNER, EDITTYPE_UNIVERSE,IDC_LEFT_EDIT, IDC_LEFT_SPIN, 0.50f,
        p_end,
    widget_right,  _T("Right"),  TYPE_FLOAT,     P_ANIMATABLE,     IDS_SPIN,
        p_default, 0.0f,
        p_range,   0.0f,100.0f,
        p_ui,      TYPE_SPINNER, EDITTYPE_UNIVERSE, IDC_RIGHT_EDIT,    IDC_RIGHT_SPIN, 0.50f,
        p_end,

The end of the entire parameter block is indicated by an additional p_end parameter tag.

    p_end
    );

Creating the IParamBlock2

The final step in creating a parameter block is to instantiate the IParamBlock2 object. If we set the P_AUTO_CONSTRUCT flag in the ParamBlockDesc2 constructor the construction is handled by 3ds Max. However the method ClassDesc2::MakeAutoParamBlocks() must be called in a plug-in's constructor:

Widget::Widget()
{
  WidgetDesc.MakeAutoParamBlocks(this);
}

Once 3ds Max creates the parameter block is will call Animatable::SetReference() (implemented by your plug-in) passing the parameter block as a ReferenceTarget parameter.