Coding the spline generator plugin

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
#ifndef ID_CROSSMAKER
#define ID_CROSSMAKER 1000005
#endif

// forward declarations
Bool RegisterCrossMaker(void);

// data structure for the cross
struct cCross
{
public:
    Float crossWidth;
    Float crossHeight;
};

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

public:
    virtual Bool Init(GeListNode *node);
    virtual Bool Message(GeListNode *node, Int32 type, void *data);
    virtual SplineObject* GetContour(BaseObject *op, BaseDocument *doc, Float lod, BaseThread *bt);
    static NodeData* Alloc(void) {return NewObjClear(CrossMaker); }

    SplineObject* GenerateCross(cCross ACross);
    static void OrientObject(SplineObject* op, Int32 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.

Page last updated June 23rd 2021