section 4 - creating an object (spline) generator plugin (part 2)

«  1  2  3  »  

Important! The code below is compatible with C4D R11. If you are working with R11.5 or R12, please note that you may have to change some function names and parameters for it to compile.

The code for starting up the plugin is contained in main.cpp, but this is so similar to the channel shader plugin that I won't list it here. You can download it in the source file archive for the plugin. It's worth looking at the header file crossmaker.h though, because it's a little different.

header file crossmaker.h

// CrossMaker
// crossmaker.h

// plugin ID is for testing only
#define ID_CROSSMAKER 1000005

// forward declarations
Bool RegisterCrossMaker(void);

// data structure for the cross
struct Cross
    Real crossWidth;
    Real crossHeight;

// CrossMaker class
class CrossMaker : public ObjectData
    INSTANCEOF(CrossMaker, ObjectData)

    virtual Bool Init(GeListNode *node);
    virtual Bool Message(GeListNode *node, LONG type, void *data);
    virtual SplineObject* GetContour(BaseObject *op, BaseDocument *doc, Real lod, BaseThread *bt);
    static NodeData* Alloc(void) {return gNew CrossMaker; }

        SplineObject* GenerateCross(Cross ACross);
    static void OrientObject(SplineObject* op, LONG plane, Bool reverse);
    void ResetValues(GeListNode *node);

A few things to note about this. There are three virtual functions we have to supply code for, but the only new one is GetContour(), which we'll look at on the next page. Then we have the usual static function Alloc() to allocate a new instance of the plugin class. We also have three functions we supply, GenerateCross(), OrientObject(), and ResetValues(), which are explained on the next page. Finally, there is another static function, OrientObject(), which will get the default orientation of a spline primitive. It has to be static because we call this before a spline object has been generated.

Note that we also have a small data structure called 'Cross'. This will hold all the parameters we need to determine how the cross will be drawn. There are only two here, but in a more complex plugin there could be a lot more, and keeping them all in one structure is a very convenient way to pass the data to any functions we write.

The only other thing to point out is the 'INSTANCEOF(CrossMaker, ObjectData)' line. This is just a macro that in this case redefines (using a typedef) 'ObjectData' as 'SUPER'. This is very convenient if you need to call a base object's equivalent function at the end of one of the virtual functions we implement. In fact we don't need to do that here, but you will in some cases - this macro is used quite a lot in the SDK examples, check these out to see how it's used.

On the next page we will implement the actual code for the plugin.

Back to the main tutorials page

«  1  2  3  »