The MAXClass Constructor (SDK)
The MAXClass constructor you should use for static instances is as follows:
MAXClass ( char* cname, // scripter-visible class name
Class_ID cid, // MAX class ID
SClass_ID sid, // MAX superclass ID
MAXSuperClass* superclass, // MAXScript MAXSuperClass
short cflags, // option flags (see below)
... // accessor definitions
);
The cflags value can be one or more of:
md_no_create
This class is not instantiable. Scripts cannot use this class a a constructor. Typically specified on object classes that cannot exist alone (such as spacewarp bindings) but are still accessible in the scripter.
md_use_getref0
md_use_getref1
md_direct_index
These three flags relate to ParamBlock-hosted properties. It turns out that core MAX objects use ParamBlocks in a variety of non-standard ways and these flags basically cover the possibilities. According to the docs, object classes that use a ParamBlock can implement Object::GetParamBlock() to return a pointer to the block. Some MAX classes do and some don’t. All of them stick the block in reference(0) or reference(1), so if the class does not implement GetParamBlock() you can specify md_use_getref0 or md_use_getref1 accordingly. If neither of these flags are specified and there are paramblock accessors defined, MAXScript will use GetParamBlock().
Further, the docs suggest that all classes should implement Object::GetParamBlockIndex() to map logical parameter ID's into ParamBlock indexes. Again, only some of the MAX core classes do this and some of them do it inconsistently. The md_direct_index flag indicates that the parameter IDs in the accessor definitions are direct indexes into the ParamBlock. If not this flag is not specified, MAXScript uses GetParamBlockIndex() to map the given IDs to paramblock indexes.
md_auto_parms
This flag indicates that the properties defined are in addition to any properties that can be discovered by the MAXScript plug-in scanner. This gives you a way to incrementally add definitions for just those properties that are not housed in ParamBlocks or are not properly exposed there.
The property accessor definitions are supplied in the … varargs to the MAXClass constructor. These take the form of tagged lists of specifiers each terminated with an 'end' tag. The tags are enumerated constants defined in MAXObj.h.
The syntax for these is as follows:
property_defs ::= [ <accessors>, ] end
accessors ::= accessors, [ <pb_props>, ] [ <fn_props> ]
pb_props ::= paramblock, { <pb_prop>, } end
pb_prop ::= <name_str> <param_id> <type> [ <default_val> ]
fn_props ::= fns, { <fn_prop>, } end
fn_prop ::= <name_str> <getter_fn> <setter_fn> <type> [<default_val>]
Where:
<param_id> is a ParamBlock parameter ID or ParamBlock index depending on whether the md_direct_index flag was specified.
<type> is one of:
TYPE_MSFLOAT // float
TYPE_INT // integer
TYPE_RGBA // point3 of 0-255 externally, 0-1 internally
TYPE_POINT3
TYPE_BOOL
TYPE_ANGLE // degrees externally, radians internally
TYPE_PCNT_FRAC // percent externall, 0-1 float internally
TYPE_STRING
TYPE_HSV // point3 of 0-255 externally, 0-1 internally
TYPE_COLOR_CHANNEL // 0-255 float externally, 0-1 internally
TYPE_TIMEVALUE // frames externally, tick TimeValue internally
TYPE_UNSPECIFIED
Some of the types imply automatic scaling between scripter visible values and internal parameter values. For example, TYPE_ANGLE causes radians-to-degree conversion on the away out to the scripter for property gets and degrees-to-radians conversion on the way in from the scripter for property sets.
TYPE_UNSPECIFIED can only be used in fns property definitions and means that the accessor functions take care of the type conversions and that there is no default value.
The <default_val> default values must be of the correct C++ type or definition parsing may fail.
Default value C++ type
TYPE_MSFLOAT float
TYPE_INT int
TYPE_RGBA three comma-separated floats
TYPE_POINT3 three comma-separated floats
TYPE_BOOL BOOL
TYPE_ANGLE float
TYPE_PCNT_FRAC float
TYPE_STRING string
TYPE_HSV three comma-separated floats
TYPE_COLOR_CHANNEL float
TYPE_TIMEVALUE float
TYPE_UNSPECIFIED -- no default value --
If you do not wish to specify a default value, perhaps because the property is a synonym for another which already has a default value specified, make the type -ve (put a minus in front of the type code) and leave out the default.
The signature for the getter and setter functions supplied in the fns section is:
Value* getter_fn(ReferenceTarget* obj, Value* prop, TimeValue t,
Interval& valid);
void setter_fn(ReferenceTarget* obj, Value* prop, TimeValue t,
Value* val);
When these functions are invoked by the MAXScript property accessor system, you can be sure the ReferenceTarget parameter points to a MAX object of the Class ID specified in the MAXClass constructor referencing these functions. The TimeValue and Interval parameters are used in the same way as they are on the Control and IParamBlock GetValue() and SetValue() member functions in the MAX SDK.
Here are some more examples:
MAXClass quadpatch
("Quadpatch", Class_ID(PATCHGRID_CLASS_ID, 0), GEOMOBJECT_CLASS_ID,
&geom_class, md_use_getref0 + md_direct_index,
accessors,
paramblock,
"length", PATCHGRID_LENGTH, TYPE_MSFLOAT, 25.0,
"width", PATCHGRID_WIDTH, TYPE_MSFLOAT, 25.0,
"widthsegs", PATCHGRID_WSEGS, TYPE_INT, 1,
"lengthsegs", PATCHGRID_LSEGS, TYPE_INT, 1,
end,
end,
end
);
MAXClass text
("Text", Class_ID(TEXT_CLASS_ID, 0), SHAPE_CLASS_ID, &shape, 0,
accessors,
paramblock,
"size", TEXT_SIZE, TYPE_FLOAT, 100.0,
end,
fns,
"text", get_txt_strng, set_txt_strng, TYPE_UNSPECIFIED,
"font", get_txt_font, set_text_font, TYPE_UNSPECIFIED,
"italic", get_txt_italic, set_txt_italic, TYPE_BOOL, FALSE,
"underline", get_txt_under, set_txt_under, TYPE_BOOL, FALSE,
end,
end,
end
);
The Text class defines both ParamBlock and function-based properties. It is typical only to specify type information for function-based properties when you want to give default values.
These are the MAXSuperClass static instances you can reference in MAXClass constructors. They are externed in the header file "Maxclses.h".
geom_object
modifier
shape
helper_object
spacewarp_object
light_object
camera_object
material_class
texture_map
system_object
utility_plugin
spacewarp_modifier
float_controller
point3_controller
position_controller
quat_controller
rotation_controller
scale_controller
matrix3_controller
morph_controller