Creating a polygon object plugin

Note: applicable to R19 and earlier versions. Some code may be applicable to later versions of C4D.

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:

CONTAINER Odiamond
{
    NAME Odiamond;
    INCLUDE Obase;
    GROUP ID_OBJECTPROPERTIES
    {
        REAL DIAMOND_WIDTH { UNIT METER; MIN 0.0; }
        REAL DIAMOND_HEIGHT { UNIT METER; MIN 0.0; }
    }
}

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!!!
#endif

// constants
#define HANDLES 2
#define DEFAULT_DIAMOND_WIDTH 200
#define DEFAULT_DIAMOND_HEIGHT 400

// forward declarations
Bool RegisterDiamond(void);

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

public:

    virtual void GetHandle(BaseObject *op, Int32 i, HandleInfo &info);
    virtual void SetHandle(BaseObject *op, Int32 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 Int32 GetHandleCount(BaseObject *op);

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

    static NodeData* Alloc(void) { return NewObjClear(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.

Page last updated June 23rd 2021