section 6 - creating an object plugin (part 1)

1  2  3  4  »  

In an earlier tutorial we created a spline generator plugin. In this one, I want to give a simple example of how to write a polygon object generator.

As before, this is a working plugin. You can modify and add to it as much as you like. Just remember to get a unique plugin ID from Maxon if you intend to use it and especially if you are going to let other users have it.

The object will be a very simple one - a diamond shape. Think a pyramid mirrored vertically. Not every exciting but it shows the bare bones. Here's what it iwill look like:

Diamond object

As you can see, it's a simple shape with two resizing handles for the height and width. The interface for this object is extremely simple:

Diamond interface

There are just two parameters, the width and height. The resource file is correspondingly simple:

    NAME Odiamond;
    INCLUDE Obase;

No great surprises here. I won't add the header or string table files, they are so simple. Likewise the c4d_symbols.h and c4d_strings.str files. You can see all these in the archive which you can download for reference.

The code is in two .cpp files and one header. Here's the header in full:

header file diamond.h

// Diamond ObjectData plugin
// diamond.h

// plugin ID
#ifndef ID_DIAMOND
#define ID_DIAMOND 100008 // <----- be sure to get a unique plugin DI from Maxon if you intend to develop and use this plugin!!!

// constants
#define HANDLES 2

// forward declarations
Bool RegisterDiamond(void);

// object generator class
class Diamond : public ObjectData
    INSTANCEOF(Diamond, ObjectData);


    virtual void GetHandle(BaseObject *op, LONG i, HandleInfo &info);
    virtual void SetHandle(BaseObject *op, LONG i, Vector p, const HandleInfo &info);
    virtual DRAWRESULT Draw(BaseObject *op, DRAWPASS drawpass, BaseDraw *bd, BaseDrawHelp *bh);

    virtual BaseObject* GetVirtualObjects(BaseObject *op, HierarchyHelp *hh);
    virtual Bool Init(GeListNode *node);
    virtual void GetDimension(BaseObject *op, Vector *mp, Vector *rad);
    virtual LONG GetHandleCount(BaseObject *op);

    BaseObject* GenerateObject(Vector *padr, LONG pcnt, LONG vcnt, BaseThread *bt);

    static NodeData* Alloc(void) { return gNew Diamond; }

The only really new thing here is that we override the virtual function GetVirtualObjects(). This function is at the core of any object plugin which generates an object. There are also some other virtual function to do with the resizing handles and a member function which will actually generate the polygon object.

On the next page we'll look at the C++ source code and how it works.

1  2  3  4  »