Describing Parameter Block----翻译:讲述Parameter Block在max sdk里的故事

来源:互联网 发布:rar破解密码软件 编辑:程序博客网 时间:2024/05/03 03:53

The process of creating a parameter block (PB) can be broken down into two parts.

  • Describing a parameter block. A PB is first described by creating one static instance of a parameter block descriptor. The parameter block descriptor constructor takes a variable amount of arguments that describe the PB. When created, the constructor will automaticly link itself with a plugin class descriptor. Describing a parameter block takes about 95% of the time involved in implementing a parameter block. Understanding how to describe a parameter block is critical.
  • Creating a parameter block. A parameter block is actually created by 3ds Max internally, however the plugin developer must first implement code that will tell Max to automaticly create a PB. The next topic will discuss parameter block creation methods.

创建一个参数块的过程可以分为两个部分:

第一部分:描述参数块。首先一个参数块描述段的静态实例来描述这个参数块。参数块描述段的构造函数用自身的大量参数来描述参数块。当参数块描述段的构造函数创建后,此构造函数会自动和一个插件类的描述段相连接。描述一个参数块占实现一个描述块的百分之九十五的时间。理解怎样描述一个参数块是很重要的。

第二部分:创建参数块。一个参数块是由3ds Max内部创建的。然而一个插件开发者必须首先实现这些代码,这些代码让Max能够自动创建一个参数块。下一节将要讨论参数块创建方法。

 

Describing a Parameter Block

A parameter block descriptor ( pbd ) takes arguments that describe your plugin variables: what type's they are, if they are animatable, what default values to assign to them, and if you want max to handle the front end UI (i.e. If you want Max to automatically create add and remove your rollout, handle window procedures for each of your controls, map each control to a parameter block etc... A time saving choice!).

A pbd constructor takes a variable number of arguments. The arguments are related to the variable types you are defining for your parameter block, and whether you want 3ds Max to automatically create a parameter map for you. Of the arguments that need to be listed, the first five arguments are required. After that, some arguments are included only if you supplied some special flags in the 5th argument. Afterwards, for each control you want to implement a parameter for in the parameter block, you will supply mandatory and optional arguments. At the end of each parameter you will supply the keyword 'end.' At the end of the entire constructor you will also supply one last keyword 'end.'

There is only one parameter block descriptor for every parameter block.

 

一个参数块描述段(.pbd)有许多参数,这些参数描述了你的插件的变量:它们是什么类型的。如果他们是animatable,用什么样的缺省值去赋予他们。如果你想让Max处理前台ui (比如,你想让Max自动创建增加和去除rollout,处理为每个控件对应的窗口处理函数,将每个控件映射到一个参数块等等。。。,时间保存选择)。

 一个参数块构造函数有不同数量的参数。这些参数和一些变量类型相关联,而这些变量类型是为参数描述段而定义的。列举一下一些需要的参数:前5个参数是必须的。第六个参数代表一些特殊的标志符,只有你想用到一些参数时,才添加。之后都是为每一个控件在参数块中实现一个参数,你需要提供必须的和可供选择的参数。在每个参数定义的结尾要添加关键词'end'.在整个构造函数的结尾要提供最后一个关键字'end'.

 对每一个参数块仅有一个参数块描述段。

Prototype of a Parameter Block Descriptor 2 Contructor

This is a short view of the pbd constructor:

static ParamBlockDesc2 ParamBlockDesc2(

    <5 required specifications>,

    <1 optional specification: ONLY IF one of the 5 required is set>,

    <1 optional specification: ONLY IF one of the 5 required is set>,

 

    for each parameter variable control:

        <1 required parameter specification>,

 

        for each parameter specification specify zero or more

            <optional tags that describe each parameter specification>,

    end,

 

    end

)

 

一个参数块描述段2构造函数原型

这里简单介绍一下参数描述段的构造函数:

static ParamBlockDesc2 ParamBlockDesc2(

   <5 个必须的参数说明>

   <1 个可供选择的参数说明:只有当前面5个必须参数中的一个设置后,这个才可用>

   <1 个可供选择的参数说明:只有当前面5个必须参数中的一个设置后,这个才可用>

  

    for 每个参数变量控件:

        <1个必须的参数说明> ,

       

         for 对零个或者多个的参数说明

              < 描述每个参数说明的可供选择的标识 >

     end,

   

      end

)

 

A more detailed view of the pbd constructor: 

详尽介绍参数描述段的构造函数:

ParamBlockDesc2

(

   //5 Required specifications

   BlockID     ID,

   TCHAR*      int_name,

   int        local_name,

   ClassDesc2* cd,

   BYTE        flags,

    

   //ONLY IF P_AUTO_CONSTRUCT is specified above

   //This is the same reference number that is specifies the PB as

   //used in Getreference() and SetReference().

   int reference_number,

    

   //ONLY IF P_AUTO_UI is specified above

   //Automtic UI paramter Map specifications

   int dialog_template_ID,

   int dialog_title_res_ID,

   int flag_mask,

   int rollup_flags,

   ParamMap2UserDlgProc* proc,

  

   //FOR EACH variable [optional] control create a parameter specification:

   //There is one of these parameter specifications for each control.

     ParamID   id,

     TCHAR*    internal_name,

     ParamType type,

     [int      table_size,] //This is optional. Use this argument ONLY IF you use a Tab<> type

     int       flags,

     int      local_name_res_ID,

     //FOR EACH parameter specification, specify zero or more Parameter Tags.

        Parameter Tag

     end, //End for each parameter specification

   end //End for all the variable arguments

);

)

 

Below is a sample Parameter Block from the tutorial How To Write a Geometric Object.

下面是一个关于参数块构造函数的列子,注意看注释。

static ParamBlockDesc2 widget_param_blk (

   //Required arguments ----------------------------

   widget_params, _T("params"), 0, &WidgetDesc,

   //flags

   P_AUTO_CONSTRUCT + P_AUTO_UI,

 

   //Dependent arguments ---------------------------

   //required because P_AUTO_CONSTRUCT was flagged

   //This declares the reference number of the Parameter Block.

   PBLOCK_REF,

   //required because P_AUTO_UI was flagged.

   //This is the Rollout description

   IDD_PANEL, IDS_PARAMS, 0, 0, NULL,

 

   //Parameter Specifications ----------------------

   // For each control create a parameter:

   widget_size,      _T("size"),      TYPE_FLOAT,    P_ANIMATABLE,    IDS_SPIN,

     //3 optional tags

     p_default,      1.0f,

     p_range,      0.0f,1000.0f,

     p_ui,        TYPE_SPINNER,     EDITTYPE_FLOAT, IDC_SIZE_EDIT,   IDC_SIZE_SPIN, 0.50f,

     end,

   widget_left,     _T("Left"),      TYPE_FLOAT,    P_ANIMATABLE,    IDS_SPIN,

     //3 optional tags  

     p_default,      0.0f,

     p_range,      0.0f,100.0f,

     p_ui,        TYPE_SPINNER,     EDITTYPE_UNIVERSE, IDC_LEFT_EDIT,   IDC_LEFT_SPIN, 0.50f,

     end,

   widget_right,     _T("Right"),      TYPE_FLOAT,    P_ANIMATABLE,    IDS_SPIN,

     //3 optional tags  

     p_default,      0.0f,

     p_range,      0.0f,100.0f,

     p_ui,        TYPE_SPINNER,     EDITTYPE_UNIVERSE, IDC_RIGHT_EDIT,   IDC_RIGHT_SPIN, 0.50f,

     end,

   end

);

 

See How To Write a Geometric Object for a more detailed explanation of this parameter block.

This next parameter block example could have been created without all the parameter tags, or the automatic parameter mapping. In which case it would have looked like this:

请看How to Write a Geometric Object中关于参数块的详尽介绍。

接下来的参数块例子是没有参数标识的,或者说没有自动的参数映射。请看下面:

static ParamBlockDesc2 widget_param_blk (

   //Required arguments ----------------------------

   widget_params, _T("params"), 0, &WidgetDesc,

   //flags

   NULL,

 

   //Parameter Specifications ----------------------

   // For each control create a parameter:

   widget_size,      _T("size"),      TYPE_FLOAT,    P_ANIMATABLE,    IDS_SPIN, end,

   widget_left,      _T("Left"),      TYPE_FLOAT,    P_ANIMATABLE,    IDS_SPIN, end,

   widget_right,     _T("Right"),     TYPE_FLOAT,    P_ANIMATABLE,    IDS_SPIN, end,

   end

);

This shows the bare minimum that is required to get a valid (though unusable) parameter block created. The above is a good deal shorter than the original but a lot less usefull, as you will have to manually create a parameter map, and manually map your window controls to the parameters shown above. Also your parameters will get system defined defaults which may not be what you want.

上面的构造函数运用了最少的参数(当然这个参数块未必能用)。上面的例子比原来的参数少了许多,当然也就作用比较少,这样你需要手动的创建一个参数映射图,手动的将窗口控件映射到上面的可见参数上。如果不这样做,你的参数将映射到系统默认的窗口控件上,但这些控件并不是你所想要的。

原创粉丝点击