「Dev:Source/Modifiers/Adding」の版間の差分
(added declaration after struct definition in DNA_modifier_types.h) |
細 (1版 をインポートしました) |
(相違点なし)
|
2018年6月29日 (金) 04:51時点における最新版
目次
- 1 Notes on Adding a New Modifier
- 1.1 source/blender/makesdna/DNA_modifier_types.h
- 1.2 source/blender/makesrna/RNA_access.h
- 1.3 source/blender/makesrna/intern/rna_modifier.c
- 1.4 source/blender/modifiers/MOD_modifiertypes.h
- 1.5 source/blender/modifiers/intern/MOD_util.c
- 1.6 source/blender/modifiers/intern/MOD_foobar.c
- 1.7 source/blender/modifiers/CMakeLists.txt
- 1.8 release/scripts/startup/bl_ui/properties_data_modifier.py
Notes on Adding a New Modifier
source/blender/makesdna/DNA_modifier_types.h
Add a new modifier name to the ModifierType list, e.g. eModifierType_FooBar. Make sure the new entry comes before NUM_MODIFIER_TYPES, but does not modify the ordinal for any other modifier.
I'm not sure that this is 100% required for every possible modifier, but usually you will want to add a new modifier struct to the end of the file:
typedef struct FooBarModifierData {
ModifierData modifier;
/* modifier-specific data goes here; remember to add pad if necessary! */
}FooBarModifierData;
This is also a good place to declare flag enumerations and the like.
source/blender/makesrna/RNA_access.h
Add a new StructRNA declaration, e.g. extern StructRNA RNA_FooBarModifier;.
source/blender/makesrna/intern/rna_modifier.c
Add the new modifier to the modifier_type_items array. There are currently four categories it can go under: Modify, Generate, Deform, and Simulate. Entries within a category should be in alphabetical order.
{eModifierType_FooBar, "FOO_BAR", ICON_MODIFIER, "Foo Bar", ""},
Add a RNA define funcion for the new modifier, rna_def_modifier functions are in alphabetical order.
static void rna_def_modifier_foobar(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "FooBarModifier", "Modifier");
RNA_def_struct_ui_text(srna, "FooBar Modifier", "It's a foo modifier");
RNA_def_struct_sdna(srna, "FooBarModifierData");
RNA_def_struct_ui_icon(srna, ICON_MODIFIER);
}
In function rna_Modifier_refine, add a new case for the modifier struct:
case eModifierType_FooBar:
return &RNA_FooBarModifier;
source/blender/modifiers/MOD_modifiertypes.h
Add a new ModifierTypeInfo declaration, e.g. extern ModifierTypeInfo modifierType_FooBar;
source/blender/modifiers/intern/MOD_util.c
Add a new INIT_TYPE line, e.g. INIT_TYPE(FooBar);.
source/blender/modifiers/intern/MOD_foobar.c
Add a new source file to contain your modifier's code, e.g. MOD_foobar.c.
This source file must contain at least the ModifierTypeInfo definition for your modifier:
ModifierTypeInfo modifierType_FooBar = {
/* name */ "Foo Bar",
/* structName */ "FooBarModifierData",
/* structSize */ sizeof(FooBarModifierData),
/* type */ eModifierTypeType_Constructive,
/* flags */ eModifierTypeFlag_AcceptsMesh,
/* copyData */ NULL,
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
/* initData */ NULL,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ NULL,
/* updateDepgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
};
Most of the function pointers can be set to NULL if you don't need it. You probably do want to set the applyModifier function pointer though, in order to output a new DerivedMesh.
source/blender/modifiers/CMakeLists.txt
Add the new file to the SRC variable, e.g. intern/MOD_foobar.c
release/scripts/startup/bl_ui/properties_data_modifier.py
Add a new method to the DATA_PT_modifiers class:
def FOOBAR(self, layout, ob, md):
pass