Creating a spline generator plugin

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

The plugin source code has been updated to build with VS 2015 and the C4D R19 SDK. It is possible to use earlier SDKs but you may need to alter some function and variable names/definitions.

In this section, we will create a plugin to generate an object - in this case, a spline which will behave exactly like the inbuilt spline primitives in C4D.

This will be a working plugin. Feel free to add and modify it as you like (you'll need to get a plugin ID from Maxon if you are going to release it). What it will do is draw a spline in the shape of a cross - like this:

CrossMaker spline plugin

We want the user to be able to change the width and height of the cross, but there are probably lots of other parameters which could be added. Once you've got the basic framework, that's up to you.

Interface

As always, we'll start with the interface. We want gadgets to let us change the width and height, plus all the things you normally get with a spline primitive. It looks like this:

CrossMaker interface

Of course, as with the channel shader, we need a description resource so it has to be hand-coded. As with the channel shader, we need first to set up the correct directory structure (refer to that section for more information). Here's the resource file:

CONTAINER Ocrossmaker
{
NAME Ocrossmaker;
INCLUDE Obase;
GROUP ID_OBJECTPROPERTIES
{
    GROUP
    {
    REAL CROSS_WIDTH
    {
        UNIT METER; MIN 0.0;
    }
    REAL CROSS_HEIGHT
    {
        UNIT METER; MIN 0.0;
    }
    BUTTON B_RESET_CROSS { }
    SEPARATOR { LINE; }
    }
}
INCLUDE Osplineprimitive;
}

Note that we have two gadgets and a button. What about all the other things, like spline plane, intermediate points, and so on? They are all added simply by the 'INCLUDE Osplineprimitive' line, which adds all those standard controls. We still have to handle them in code, but at least we can forget about adding the interface, and we know it will look identical to all the other spline primitives.

Here's the corresponding header file:

#ifndef _Ocrossmaker_H_
#define _Ocrossmaker_H_
enum
{
    CROSS_WIDTH = 10000,
    CROSS_HEIGHT = 10005,
    B_RESET_CROSS = 10010
};
#endif

And the strings:

STRINGTABLE Ocrossmaker
{
    Ocrossmaker "CrossMaker";

    CROSS_WIDTH "Cross width";
    CROSS_HEIGHT "Cross height";
    B_RESET_CROSS "Reset cross";
}

We also need the files c4d_symbols.h and c4d_strings.str. They are very short, so I'll just list them one after the other:

c4d_symbols.h:

enum
{
    // string table definitions
    IDS_CROSSMAKER = 100000,

    // End of symbol definition
    _DUMMY_ELEMENT_
};

c4d_strings.str:

// C4D-StringResource
// Identifier Text

STRINGTABLE
{
    IDS_CROSSMAKER "Cross Maker";
}

These should be familiar now from the channel shader tutorial. On the next page we'll code the plugin itself.

Page last updated June 23rd 2021