Difference between revisions of "Channel Mod Linear Blend"

From The Foundry MODO SDK wiki
Jump to: navigation, search
Line 6: Line 6:
  
 
===Class Declarations===
 
===Class Declarations===
 +
 +
We want to have this class write out to the log, so we inherit from [[FAQ#Q:_How_do_I_write_to_the_log.3F|CLxLuxologyLogMessage]].
  
 
  class CLinearBlendLog : public CLxLuxologyLogMessage
 
  class CLinearBlendLog : public CLxLuxologyLogMessage
Line 15: Line 17:
 
  };
 
  };
  
We want to have this class write out to the log, so we inherit from [[FAQ#Q:_How_do_I_write_to_the_log.3F|CLxLuxologyLogMessage]].
+
To create an instance of the Linear Blend object we need to implement the Linear Blend Package object so we inherit from [[Package_(lx-package.hpp)#Instance_Interface|CLxPackageInstance]]. We also need to modify channels as part of our instance, so we inherit from [[Chanmod_(lx-chanmod.hpp)#ILxChannelModItem_Interface|CLxImpl_ChannelModItem]].
  
 
  class CLinearBlendInstance
 
  class CLinearBlendInstance
Line 43: Line 45:
 
  };
 
  };
  
To create an instance of the Linear Blend object we need to implement the Linear Blend Package object so we inherit from [[Package_(lx-package.hpp)#Instance_Interface|CLxPackageInstance]]. We also need to modify channels as part of our instance, so we inherit from [[Chanmod_(lx-chanmod.hpp)#ILxChannelModItem_Interface|CLxImpl_ChannelModItem]].
+
To set up our object we need a [[Package_Object|package]], so we have this class inherit from CLxImpl_Package.
  
 
  class CLinearBlendPackage : public CLxImpl_Package
 
  class CLinearBlendPackage : public CLxImpl_Package
Line 57: Line 59:
 
         LxResult pkg_Attach (void **ppvObj);
 
         LxResult pkg_Attach (void **ppvObj);
 
  };
 
  };
 
To set up our object we need a [[Package_Object|package]], so we have this class inherit from CLxImpl_Package.
 
  
 
===[[Server_Tags |Server Tags]]===
 
===[[Server_Tags |Server Tags]]===
 +
 +
The tags here indicate that the CSimpleKinematicsPackage class is dependent on the chanmodify SuperType with the internal name of cmSimpleKinematics.
  
 
  LXtTagInfoDesc CLinearBlendPackage::descInfo[] = {
 
  LXtTagInfoDesc CLinearBlendPackage::descInfo[] = {
Line 67: Line 69:
 
         { 0 }
 
         { 0 }
 
  };
 
  };
 
The tags here indicate that the CSimpleKinematicsPackage class is dependent on the chanmodify SuperType with the internal name of cmSimpleKinematics.
 
  
 
===[[Initialize_(index)|Initialize]]===
 
===[[Initialize_(index)|Initialize]]===
 +
 +
Our initialize function indicates that we will be exporting one server dependent on the CSimpleKinematicsPackage class that uses the Package and StaticDesc interfaces as well as being names cmSimpleKinematics.
  
 
         void
 
         void
Line 82: Line 84:
 
         thisModule.AddServer ("cmLinearBlend", srv);
 
         thisModule.AddServer ("cmLinearBlend", srv);
 
  }
 
  }
 
Our initialize function indicates that we will be exporting one server dependent on the CSimpleKinematicsPackage class that uses the Package and StaticDesc interfaces as well as being names cmSimpleKinematics.
 
  
 
===Implementations===
 
===Implementations===
 +
 +
This function evaluates the modifiers we have used on the given channels.
  
 
         LxResult  
 
         LxResult  
Line 115: Line 117:
 
  }
 
  }
  
This function evaluates the modifiers we have used on the given channels.
+
We create [[Factory_Object|factories]] here to export CLinearBlendInstance.
 
   
 
   
 
  CLinearBlendPackage::CLinearBlendPackage ()
 
  CLinearBlendPackage::CLinearBlendPackage ()
Line 122: Line 124:
 
         chanmod_factory.AddInterface (new CLxIfc_ChannelModItem<CLinearBlendInstance>);
 
         chanmod_factory.AddInterface (new CLxIfc_ChannelModItem<CLinearBlendInstance>);
 
  }
 
  }
 
We create [[Factory_Object|factories]] here to export CLinearBlendInstance.
 

Revision as of 21:54, 10 September 2013

Channel Mod Linear Blend 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.

When installed, this plugin adds the Linear Blend channel modifier, which allows you to take two channel inputs and combine them into a single output.

Code Walkthrough

Class Declarations

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

class CLinearBlendLog : public CLxLuxologyLogMessage
{
   public:
       CLinearBlendLog () : CLxLuxologyLogMessage ("cmLinearBlend") { }

       const char *	 GetFormat  () { return "Linear Blend Object"; }
};

To create an instance of the Linear Blend object we need to implement the Linear Blend 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 CLinearBlendInstance
       :
       public CLxImpl_PackageInstance,
       public CLxImpl_ChannelModItem
{
       CLinearBlendLog		 log;
        
   public:
       CLinearBlendPackage	*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 CLinearBlendPackage : public CLxImpl_Package
{
   public:
       static LXtTagInfoDesc			descInfo[];
       CLxPolymorph<CLinearBlendInstance>	chanmod_factory;
         
       CLinearBlendPackage ();

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

Server Tags

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

LXtTagInfoDesc	 CLinearBlendPackage::descInfo[] = {
       { LXsPKG_SUPERTYPE,	"chanModify"	},
       { LXsSRV_LOGSUBSYSTEM,	"cmLinearBlend"	},
       { 0 }
};

Initialize

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

       void
initialize ()
{
       CLxGenericPolymorph		*srv;

       srv = new CLxPolymorph<CLinearBlendPackage>;
       srv->AddInterface (new CLxIfc_Package          <CLinearBlendPackage>);
       srv->AddInterface (new CLxIfc_StaticDesc       <CLinearBlendPackage>);
       thisModule.AddServer ("cmLinearBlend", srv);
}

Implementations

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

       LxResult 
CLinearBlendInstance::cmod_Evaluate (
       ILxUnknownID		 cmod,		// ILxChannelModifierID
       ILxUnknownID		 attr,		// ILxAttributesID
       void			*data)		
{
       CLxLoc_ChannelModifier	 chanMod (cmod);
       double			 dValA, dValB, dVal, blend;
        
//	log.Info ("cmod_Evaluate Method");
        
       chanMod.ReadInputFloat (attr, 0, &dValA);
       chanMod.ReadInputFloat (attr, 1, &dValB);
        
       // Read the blend value and clamp between zero and one.
       chanMod.ReadInputFloat (attr, 2, &blend);
       if (blend < 0.0)
               blend = 0.0;
       else if (blend > 1.0)
               blend = 1.0;
        
       dVal = dValA + blend * (dValB - dValA);
        
       chanMod.WriteOutputFloat (attr, 0, dVal);
         
       return LXe_OK;
}

We create factories here to export CLinearBlendInstance.

CLinearBlendPackage::CLinearBlendPackage ()
{
       chanmod_factory.AddInterface (new CLxIfc_PackageInstance<CLinearBlendInstance>);
       chanmod_factory.AddInterface (new CLxIfc_ChannelModItem<CLinearBlendInstance>);
}