Channel Mod Math Multi

From The Foundry MODO SDK wiki
Revision as of 23:53, 11 September 2013 by Adissid (Talk | contribs)

Jump to: navigation, search

Channel Mod Math Multi is a basic example plugin. This wiki page is intended as a walkthrough of the code in order to help you better understand the SDK.

This plugin is a channel modifier that takes in input and performs mathematical inputs on them. This is further explained in the functionality section below.


Below, We have three cubes that the math multi is acting upon. The modifier is taking in one cube's x-coordinate(3m) and the other's y-coordinate(3m). The result is being exported to the z-coordinate of the cube in the middle

Mathmulti shot1.png

The untransformed cubes

Mathmulti shot2.png

Here, the two inputs are being added together

Mathmulti shot3.png

Here, the two inputs are being multiplied together

Mathmulti shot4.png

Here, the two inputs are being divided

Mathmulti shot5.png

The difference of the two inputs is being taken here.

Code Walkthrough

Class Declarations

We want to have this class write out to the log, so we inherit from CLxLuxologyLogMessage.

class CMathMultiLog : public CLxLuxologyLogMessage
       CMathMultiLog () : CLxLuxologyLogMessage ("cmMathMulti") { }

       const char *	 GetFormat  () { return "Math Multiple Object"; }

To create an instance of the Math Multi object we need to implement the Math Multi Package object so we inherit from CLxPackageInstance. We also need to modify channels as part of our instance, so we inherit from CLxImpl_ChannelModItem.

class CMathMultiInstance
       public CLxImpl_PackageInstance,
       public CLxImpl_ChannelModItem
       CMathMultiLog		 log;
       CMathMultiPackage	*src_pkg;
       CLxUser_Item		 m_item;
       ILxUnknownID		 inst_ifc;

       LxResult		 pins_Initialize (ILxUnknownID item, ILxUnknownID super);
       void			 pins_Cleanup (void);
       LxResult		 pins_SynthName (char *buf, unsigned len);
       unsigned int		 cmod_Flags (ILxUnknownID item, unsigned int index);
       LxResult		 cmod_Allocate (
                                       ILxUnknownID cmod,
                                       ILxUnknownID eval,
                                       ILxUnknownID item,
                                       void **ppvData);
       void			 cmod_Cleanup (void *data);
       LxResult		 cmod_Evaluate (ILxUnknownID cmod, ILxUnknownID attr, void *data);

To set up our object we need a package, so we have this class inherit from CLxImpl_Package.

class CMathMultiPackage : public CLxImpl_Package
       static LXtTagInfoDesc		 descInfo[];
       CLxPolymorph<CMathMultiInstance> chanmod_factory;
       CMathMultiPackage ();

       LxResult		pkg_SetupChannels (ILxUnknownID addChan);
       LxResult		pkg_TestInterface (const LXtGUID *guid);
       LxResult		pkg_Attach (void **ppvObj);

Server Tags

Servers tags are examined when the server is initialized, and give information about the server. We set the tags in this case by taking descinfo[] arrays and associating the relevant data with the corresponding flags.

The tags here indicate that the CMathMultisPackage class is dependent on the chanmodify SuperType with the internal name of cmMathMulti.

LXtTagInfoDesc	 CMathMultiPackage::descInfo[] = {
       { LXsPKG_SUPERTYPE,	"chanModify"	},
       { LXsSRV_LOGSUBSYSTEM,	"cmMathMulti"	},
       { 0 }


Intialize is called when we add the plugin to modo, and is the utility that exports the server.

Our initialize function indicates that we will be exporting one server dependent on the CMathMultiPackage class that uses the Package and StaticDesc interfaces as well as being names cmMathMulti.

initialize ()
       CLxGenericPolymorph		*srv;

       srv = new CLxPolymorph<CMathMultiPackage>;
       srv->AddInterface (new CLxIfc_Package          <CMathMultiPackage>);
       srv->AddInterface (new CLxIfc_StaticDesc       <CMathMultiPackage>);
       thisModule.AddServer ("cmMathMulti", srv);


This function evaluates the modifiers we have used on the given channels.

CMathMultiInstance::cmod_Evaluate (
        ILxUnknownID		 cmod,		// ILxChannelModifierID
        ILxUnknownID		 attr,		// ILxAttributesID
        void			*data)		// User Data

This function creates factories to export CMathMultiInstance.

CMathMultiPackage::CMathMultiPackage ()