How to Create a Custom Modifier in Blender


Some extensions for Blender, the free open source 3D content creation suite are better off implemented as custom modifiers. So what does it take to actually create your own? I am glad you asked as I will make an attempt to point you in the right direction.

Modifiers can be accessed through the properties panel. Access to the panel is identified by the wrench Icon. Creating your very own custom modifier in Blender involved editing quite a number of files. This tutorial refers to the Blender 2.5 Beta series. I also do not guarantee that there will be no changes to the current source as there is still plenty of work being done in the Blender 2.5 source code. To get a copy of the Blender 2.5 Beta source code you can go to http://www.blender.org/download/source-code/ chose your download location.

Getting Started

The modifier C source code files are located in the following directory in the blender source.

source/blender/modifiers/intern

The first thing you can do is browse through a few of the existing modifiers to familiarize yourself with them and get a general idea of the file structures. You do not need to spend too much time here.

Get an existing modifier such as MOD_none.c and rename it to your own modifier choice while maintaining the same naming convention. So if we use Sobbayi as our modifier name the would copy the file to MOD_sobbayi.c in the same location.

source/blender/modifiers/intern/MOD_sobbayi.c

Within this file you will make a few changes to the ModifierTypeInfo structure to the tune of this example

ModifierTypeInfo modifierType_Sobbayi = {
/* name */              "Sobbayi",
/* structName */        "sobbayiModifierData",
/* structSize */        sizeof(sbbayiModifierData),
/* type */              eModifierType_None,
/* flags */             eModifierTypeFlag_AcceptsMesh
| eModifierTypeFlag_AcceptsCVs,

/* copyData */          0,
/* deformVerts */       0,
/* deformVertsEM */     0,
/* deformMatricesEM */  0,
/* applyModifier */     0,
/* applyModifierEM */   0,
/* initData */          0,
/* requiredDataMask */  0,
/* freeData */          0,
/* isDisabled */        isDisabled,
/* updateDepgraph */    0,
/* dependsOnTime */     0,
/* dependsOnNormals */	0,
/* foreachObjectLink */ 0,
/* foreachIDLink */     0,
};

The eModifierType_None in the structure above should not be used with your modifier as it is there as a placeholder. The available choices are eModifierTypeType_OnlyDeform, eModifierTypeType_Constructive and eModifierTypeType_Nonconstructive.

For the ModifierTypeFlag you have the following options.

  • eModifierTypeFlag_AcceptsMesh
  • eModifierTypeFlag_AcceptsCVs
  • eModifierTypeFlag_SupportsMapping
  • eModifierTypeFlag_SupportsEditmode
  • eModifierTypeFlag_EnableInEditmode for modifiers that support editmode and if it should be enabled by default
  • eModifierTypeFlag_RequiresOriginalData used for modifiers that require original data and so cannot be placed after any non-deformative modifier
  • eModifierTypeFlag_UsesPointCache used for modifiers that support pointcache, so we can check to see if it has files we need to deal with
  • eModifierTypeFlag_Single used for physics modifiers. There can only be one per type
  • eModifierTypeFlag_NoUserAdd This means the modifier can’t be added manually by user

The rest of the entries in the ModifierTypeInfo structure will either be 0 or the value stated in the comments.

The next Blender source file you need to modify is

source/blender/modifiers/intern/MOD_util.c

After around line 184 put the following line there.

INIT_TYPE(Sobbayi);

Then your Blender Custom Modifier needs to be added into the CMakeList.txt file found here

source/blender/modifiers/CMakeLists.txt

You do this by adding the following code are line 76.

intern/MOD_sobbayi.c

Your ModifierTypeInfo structure called modifierType_Sobbayi needs to be declared. This can be done in the file located at

source/blender/modifiers/MOD_modifiertypes.h

Go to around line 69 and add the following code.

extern ModifierTypeInfo modifierType_Sobbayi;

In the file located at

source/blender/makesdna/DNA_modifier_types.h

Just about line 69 you need to add the following code.

eModifierType_Sobbayi,

This is not to be confused with the type entry in the ModifierTypeInfo structure above. In the same file somewhere around line 718 below the ScrewModifierData or anywhere in between the typedef struct definitions you can add this entry. This will also depend on how you want to use your custom Blender Modifier.

typedef struct SobbayiModifierData {

ModifierData modifier;

} SobbayiModifierData;

In the file rna_modifier.c located here.

source/blender/makesrna/intern/rna_modifier.c

around line 87, you will need to add the following code.

{eModifierType_Sobbaiy, "SOBBAYI", ICON_MOD_PHYSICS, "Sobbayi", ""},

for the ICON_MOD_PHYSICS, I have used an existing definition.

Again in the same file scroll down to about line 2087 or around there you will need to add this static function.

static void rna_def_modifier_sobbayi(BlenderRNA *brna)
{
StructRNA *srna;

srna= RNA_def_struct(brna, "SobbayiModifier", "Modifier");
RNA_def_struct_ui_text(srna, "Sobbayi Modifier", "Sobbayi modifier stuff to be done");
RNA_def_struct_sdna(srna, "SobbayiModifierData");
RNA_def_struct_ui_icon(srna, ICON_MOD_PHYSICS);
}

Of course ther is more to the available entire which I cant define here since they depend on the what you want your modifier to do. You can look at the file at other examples.

Still in the same file you will need to add the following code

rna_def_modifier_sobbayi(brna);

around line 2335.

We then hope on over to the Python file properties_data_modifier.py. This file can be found in the following location.

../release/scripts/ui/properties_data_modifier.py

Here at around line 697 we are going to add the following code. The code wil vary depending on your modifier

def SOBBAYI(self, layout, ob, md):
layout.label(text="Ask Sobbayi for details")

You can browse the Python file to see options that can be used here.

Of course this custom Blender Modifier does nothing. That is where you come in. This guide leaves a few details out but is definitely a head start and a pointer in the right direction.

Happy Blender coding.

 

 

Leave a Reply

    © 2003, 2012 Sobbayi Tech

Home Sobbayi.com

Switch to our mobile site