#define _MESSIAH_FULL_API #include <messiah_main.h>
_MAINPLUGIN_FILE
before including messiah_main.h. We only defined that along with _MESSIAH_FULL_API
in the previous tutorial because we put everything in one file, since we're splitting things up here we'll hold off on defining that symbol until we get to PluginMain.c. The next thing we'll need to do in this header is declare our module's Access Notification message handler, we'll call it NormScaleAccess: FX_ACCESSFUNC(NormScaleAccess);
#define _MESSIAH_FULL_API #include <messiah_main.h> FX_ACCESSFUNC(NormScaleAccess); typedef struct { FXdouble scale; } NormScaleState;
_MAINPLUGIN_FILE.
Next we'll start the registration process, filling in a few gaps as we go: _pluginEntry { // Get all API components and do initial plugin setup _MESSIAH_PLUGIN_ALL("Norm_Scale"); // Describe the effect in English fxModuleDescription("Scale a mesh's points along their normals", FX_NOFLAG); // Register the effect fxModuleRegister( FX_MODTYPE_EFFECT, "NormScale", &NormScaleAccess, FX_NOFLAG); return FX_PLUGIN_OK; }
// Request AN messages fxModuleAccess(ACCESS_OBJECT, O_CREATE|O_DESTROY, FX_NOFLAG); fxModuleAccess(ACCESS_SYSTEM, S_MODULE_INIT, FX_NOFLAG); fxModuleAccess(ACCESS_PROCESS, P_POST_POINT_DISPLACE, FX_NOFLAG);
#define _MAINPLUGIN_FILE #include "NormScale.h" _pluginEntry // FXint messiahEntry(FXchar pname[256], FXvoid *api_func, FXint api, FXint program, const FXchar *rev) { // Get all API components and do initial plugin setup _MESSIAH_PLUGIN_ALL("Norm_Scale"); // Describe the effect in English fxModuleDescription("Scale a mesh's points along their normals", FX_NOFLAG); // Request AN messages fxModuleAccess(ACCESS_OBJECT, O_CREATE|O_DESTROY, FX_NOFLAG); fxModuleAccess(ACCESS_SYSTEM, S_MODULE_INIT, FX_NOFLAG); fxModuleAccess(ACCESS_PROCESS, P_POST_POINT_DISPLACE, FX_NOFLAG); // Register the effect fxModuleRegister( FX_MODTYPE_EFFECT, "NormScale", &NormScaleAccess, FX_NOFLAG); return FX_PLUGIN_OK; } _pluginExit // FXvoid messiahExit(FXvoid) { }
#include "NormScale.h" FX_ACCESSFUNC(NormScaleAccess) // FXint f(FX_AccessInfo *ai, FXentity ID, FXint level, FXint64 entry) { switch( level ) { case ACCESS_OBJECT: switch( entry ) { case O_CREATE: { }// O_CREATE break; case O_DESTROY: { }// O_DESTROY break; } // switch entry }// switch level return ENTRY_OK; }
FXeffect
variable that has function scope and cast the ID argument to that variable: FX_ACCESSFUNC(NormScaleAccess) { FXeffect effect = (FXeffect)ID; //... }
FX_ACCESSFUNC(NormScaleAccess) { FXeffect effect = (FXeffect)ID; NormScaleState * state = NULL; //... }
if( !(state = (NormScaleState *)calloc(1, sizeof(NormScaleState))) ) return ENTRY_CONTINUE; fxObjectSetTypeData( effect, state, FX_NOFLAG );
scale
member of our NormScaleState structure: fxChannelSetup( effect, "factor", FX_CHAN_0, FX_CHANTYPE_VALUE, state->scale, 0.0, 0.0, FX_NOFLAG); fxChannelDataLink( effect, FX_CHAN_0, FX_ARG_DOUBLE, &state->scale, FX_NOFLAG);
case O_DESTROY: { if( state = fxObjectGetTypeData( effect, FX_NOFLAG ) ) { free(state); fxObjectSetTypeData( effect, NULL, FX_NOFLAG); } }// O_DESTROY break;
case S_MODULE_INIT: { fxInitEffectManipulator(FX_MANIPULATOR_SLIDER, FX_NOFLAG); fxInitEffectColor((FXubyte)200, (FXubyte)220, (FXubyte)0); fxInitEffectTool(FX_TOOLTYPE_NULL, FX_NOFLAG); }// S_MODULE_INIT break;
case ACCESS_PROCESS: switch( entry ) { case P_POST_POINT_DISPLACE: { if( state = fxObjectGetTypeData( effect, FX_NOFLAG ) ) { // Process each target, EffectScan() is called once for each attached target fxEffectTargetScan( effect, &EffectScan, state, FX_NOFLAG ); } }// P_POST_POINT_DISPLACE break; }// ACCESS_PROCESS break;
static FX_DISPLACESCAN(DisplaceScan, NormScaleState, state) // FXint f(FX_DisplacePoint *p, dt *ed) { //... return FX_TRUE; } static FX_EFFECTSCAN(EffectScan, NormScaleState, state) // FXint f(FXeffect effect, FXtool tool, FXobject target, dt *ed) { // Process each point in target, DisplaceScan() gets called once for each point fxDisplaceScan( target, FX_NULLID, FX_NOFLAG, &DisplaceScan, state, FX_NOFLAG ); return FX_TRUE; }
static FX_DISPLACESCAN(DisplaceScan, NormScaleState, state) // FXint f(FX_DisplacePoint *p, dt *ed) { FXdouble norm[3]; fxMeshPointNormal( p->objID, p->ID, norm, FX_NOFLAG ); p->new_pos[0] = p->cur_pos[0] + (state->scale * norm[0]); p->new_pos[1] = p->cur_pos[1] + (state->scale * norm[1]); p->new_pos[2] = p->cur_pos[2] + (state->scale * norm[2]); return FX_TRUE; }
objID
member and the index of the point being displaced is indicated by the ID
member. The normal is then stored in our local variable norm. We then set the p->new_pos to the value of our displaced point. We're adding the displacement value to p->cur_pos so that our effect will work with any effects that already deformed this target object. If we didn't add this value our effect would override any prior effects (i.e. ones that appear hight in the list of effects in messiah's Setup->Effects list).
© 2003 pmG WorldWide,
LLC.
|
Last
Updated on Thu Jul 10 04:49:37 2003
|