Class ObjectConverter
See Also: Class InterfaceServer, Class Class_ID, Class Object, Class TriObject, Class PatchObject.
class ObjectConverter : public InterfaceServer
Description:
This class is available in release 4.0 and later only.
This virtual class is implemented by applications that want to supply a conversion method from one object type to another. A typical use would be to support conversion of a native 3ds max type (such as TriObject) to a plug-in's object type. There are a set of global functions that can be used with this class. These are documented at the bottom of the topic. One of these is called to register the ObjectConverter with the system.
Note that the registered object converters are called from the methods:
Object::CanConvertToType and Object::ConvertToType.
So for individual objects to support these, they'll need to add the line
if (Object::CanConvertToType(obtype)) return 1;
to the end of their CanConvertToType methods and
if (Object::CanConvertToType(obtype))
return Object::ConvertToType(t, obtype);
to the end of their ConvertToType methods.
Methods:
public:
Prototype:
virtual Class_ID ConvertsFrom()=0;
Remarks:
This method returns the Class ID of the object this converter converts from.
Prototype:
virtual Class_ID ConvertsTo()=0;
Remarks:
This method returns the Class ID of the object this converter converts to.
Prototype:
virtual Object *Convert(Object *from)=0;
Remarks:
This method actually performs the conversion, creating and returning a new object with the class ID specified in ConvertsTo().
Parameters:
Object *from
Points to the object to convert.
Prototype:
virtual void DeleteThis();
Remarks:
This should delete the ObjectConverter if necessary.
Default Implementation:
{}
The following global functions are not part of this class but are available for use:
Function:
bool RegisterObjectConverter(ObjectConverter *conv);
Remarks:
This global function is available in release 4.0 and later only.
Registers an object converter with the system.
Parameters:
ObjectConverter *conv
Points to the ObjectConverter instance to register.
Return Value:
Returns true if the converter could be added; false if not.
Function:
int CanConvertTriObject(Class_ID to);
Remarks:
This global function is available in release 4.0 and later only.
Indicates if a TriObject can convert to the specified class ID.
Note: this actually checks if an Editable Mesh object can convert to the specified type, since an Editable Mesh is what you get when you call CreateNewTriObject ().
This method may be used in an object's CanConvertToType() and ConvertToType() methods. If your object supports conversion to a TriObject, but doesn't support conversion to the given class ID, you can use this method to find out if TriObjects can be used as an "intermediary". If so, you can construct a temporary TriObject, convert it to the given class ID, and call the temporary TriObject's DeleteThis() method.
Parameters:
Class_ID to
The Class ID to convert to.
Return Value:
Nonzero if the TriObject can be converted to the specified objec type; otherwise zero.
Function:
int CanConvertPatchObject(Class_ID to);
Remarks:
This global function is available in release 4.0 and later only.
Indicates if a PatchObject can convert to the specified class ID.
Parameters:
Class_ID to
The Class ID to convert to.
Return Value:
Nonzero if the PatchObject can be converted to the specified objec type; otherwise zero.
Function:
int CanConvertSplineShape(Class_ID to);
Remarks:
This global function is available in release 4.0 and later only.
Indicates if a SplineObject can convert to the specified class ID.
Parameters:
Class_ID to
The Class ID to convert to.
Return Value:
Nonzero if the SplineObject can be converted to the specified objec type; otherwise zero.
Function:
void RegisterStaticEditTri(Object *triob);
Remarks:
This global function is available in release 4.0 and later only.
This method will register the object passed as the editable tri object.
Parameters:
Object *triob
The object to register as the editable tri object.
Function:
void RegisterCollapseType(Class_ID cid, TSTR name, bool canSelfConvert=false);
Remarks:
This global function is available in release 4.0 and later only.
Registers a class ID of an object that the user can collapse other objects to. The type will only appear if the current object returns nonzero from CanConvertTo(cid).
Parameters:
Class_ID cid
The class ID the object will collapse to.
TSTR name
The name of the collapse-to object type (such as "Editable Poly").
bool canSelfConvert=false
Indicates whether an object should be allowed to collapse to itself. (false is generally preferred, so that the collapse-to menu only has relevant entries.)