py/rna api

- object.modifiers.add()/remove()
- armature.edit_bones.active wasnt named correctly
This commit is contained in:
2009-11-28 13:33:56 +00:00
parent c4933cccfa
commit a2b370dd6f
12 changed files with 97 additions and 25 deletions

View File

@@ -43,8 +43,7 @@ class SubsurfSet(bpy.types.Operator):
return ('FINISHED',) return ('FINISHED',)
# adda new modifier # adda new modifier
bpy.ops.object.modifier_add(type='SUBSURF') # TODO, support adding directly mod = ob.modifiers.new("Subsurf", 'SUBSURF')
mod = ob.modifiers[-1]
mod.levels = level mod.levels = level
return ('FINISHED',) return ('FINISHED',)

View File

@@ -222,7 +222,7 @@ void copy_particle_key(struct ParticleKey *to, struct ParticleKey *from, int tim
void psys_particle_on_emitter(struct ParticleSystemModifierData *psmd, int distr, int index, int index_dmcache, float *fuv, float foffset, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor); void psys_particle_on_emitter(struct ParticleSystemModifierData *psmd, int distr, int index, int index_dmcache, float *fuv, float foffset, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor);
struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct ParticleSystem *psys); struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct ParticleSystem *psys);
void object_add_particle_system(struct Scene *scene, struct Object *ob); struct ModifierData *object_add_particle_system(struct Scene *scene, struct Object *ob, char *name);
void object_remove_particle_system(struct Scene *scene, struct Object *ob); void object_remove_particle_system(struct Scene *scene, struct Object *ob);
struct ParticleSettings *psys_new_settings(char *name, struct Main *main); struct ParticleSettings *psys_new_settings(char *name, struct Main *main);
struct ParticleSettings *psys_copy_settings(struct ParticleSettings *part); struct ParticleSettings *psys_copy_settings(struct ParticleSettings *part);

View File

@@ -3268,14 +3268,14 @@ void psys_mat_hair_to_global(Object *ob, DerivedMesh *dm, short from, ParticleDa
/************************************************/ /************************************************/
/* ParticleSettings handling */ /* ParticleSettings handling */
/************************************************/ /************************************************/
void object_add_particle_system(Scene *scene, Object *ob) ModifierData *object_add_particle_system(Scene *scene, Object *ob, char *name)
{ {
ParticleSystem *psys; ParticleSystem *psys;
ModifierData *md; ModifierData *md;
ParticleSystemModifierData *psmd; ParticleSystemModifierData *psmd;
if(!ob || ob->type != OB_MESH) if(!ob || ob->type != OB_MESH)
return; return NULL;
psys = ob->particlesystem.first; psys = ob->particlesystem.first;
for(; psys; psys=psys->next) for(; psys; psys=psys->next)
@@ -3293,7 +3293,11 @@ void object_add_particle_system(Scene *scene, Object *ob)
strcpy(psys->name, "ParticleSystem"); strcpy(psys->name, "ParticleSystem");
md= modifier_new(eModifierType_ParticleSystem); md= modifier_new(eModifierType_ParticleSystem);
sprintf(md->name, "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
if(name) BLI_strncpy(md->name, name, sizeof(md->name));
else sprintf(md->name, "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
modifier_unique_name(&ob->modifiers, md);
psmd= (ParticleSystemModifierData*) md; psmd= (ParticleSystemModifierData*) md;
psmd->psys=psys; psmd->psys=psys;
BLI_addtail(&ob->modifiers, md); BLI_addtail(&ob->modifiers, md);
@@ -3304,6 +3308,8 @@ void object_add_particle_system(Scene *scene, Object *ob)
DAG_scene_sort(scene); DAG_scene_sort(scene);
DAG_id_flush_update(&ob->id, OB_RECALC_DATA); DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
return md;
} }
void object_remove_particle_system(Scene *scene, Object *ob) void object_remove_particle_system(Scene *scene, Object *ob)
{ {

View File

@@ -121,7 +121,7 @@ enum {
MODIFIER_APPLY_SHAPE, MODIFIER_APPLY_SHAPE,
} eModifier_Apply_Mode; } eModifier_Apply_Mode;
struct ModifierData *ED_object_modifier_add(struct ReportList *reports, struct Scene *scene, struct Object *ob, int type); struct ModifierData *ED_object_modifier_add(struct ReportList *reports, struct Scene *scene, struct Object *ob, char *name, int type);
int ED_object_modifier_remove(struct ReportList *reports, struct Scene *scene, struct Object *ob, struct ModifierData *md); int ED_object_modifier_remove(struct ReportList *reports, struct Scene *scene, struct Object *ob, struct ModifierData *md);
int ED_object_modifier_move_down(struct ReportList *reports, struct Object *ob, struct ModifierData *md); int ED_object_modifier_move_down(struct ReportList *reports, struct Object *ob, struct ModifierData *md);
int ED_object_modifier_move_up(struct ReportList *reports, struct Object *ob, struct ModifierData *md); int ED_object_modifier_move_up(struct ReportList *reports, struct Object *ob, struct ModifierData *md);

View File

@@ -43,6 +43,7 @@
#include "BLI_math.h" #include "BLI_math.h"
#include "BLI_listbase.h" #include "BLI_listbase.h"
#include "BLI_string.h"
#include "BKE_action.h" #include "BKE_action.h"
#include "BKE_curve.h" #include "BKE_curve.h"
@@ -78,7 +79,7 @@
/******************************** API ****************************/ /******************************** API ****************************/
ModifierData *ED_object_modifier_add(ReportList *reports, Scene *scene, Object *ob, int type) ModifierData *ED_object_modifier_add(ReportList *reports, Scene *scene, Object *ob, char *name, int type)
{ {
ModifierData *md=NULL, *new_md=NULL; ModifierData *md=NULL, *new_md=NULL;
ModifierTypeInfo *mti = modifierType_getInfo(type); ModifierTypeInfo *mti = modifierType_getInfo(type);
@@ -94,7 +95,7 @@ ModifierData *ED_object_modifier_add(ReportList *reports, Scene *scene, Object *
/* don't need to worry about the new modifier's name, since that is set to the number /* don't need to worry about the new modifier's name, since that is set to the number
* of particle systems which shouldn't have too many duplicates * of particle systems which shouldn't have too many duplicates
*/ */
object_add_particle_system(scene, ob); new_md = object_add_particle_system(scene, ob, name);
} }
else { else {
/* get new modifier data to add */ /* get new modifier data to add */
@@ -111,7 +112,11 @@ ModifierData *ED_object_modifier_add(ReportList *reports, Scene *scene, Object *
else else
BLI_addtail(&ob->modifiers, new_md); BLI_addtail(&ob->modifiers, new_md);
if(name)
BLI_strncpy(new_md->name, name, sizeof(new_md->name));
/* make sure modifier data has unique name */ /* make sure modifier data has unique name */
modifier_unique_name(&ob->modifiers, new_md); modifier_unique_name(&ob->modifiers, new_md);
/* special cases */ /* special cases */
@@ -148,8 +153,10 @@ int ED_object_modifier_remove(ReportList *reports, Scene *scene, Object *ob, Mod
if(obmd==md) if(obmd==md)
break; break;
if(!obmd) if(!obmd) {
BKE_reportf(reports, RPT_ERROR, "Modifier '%s' not in object '%s'.", ob->id.name, md->name);
return 0; return 0;
}
/* special cases */ /* special cases */
if(md->type == eModifierType_ParticleSystem) { if(md->type == eModifierType_ParticleSystem) {
@@ -482,7 +489,7 @@ static int modifier_add_exec(bContext *C, wmOperator *op)
Object *ob = CTX_data_active_object(C); Object *ob = CTX_data_active_object(C);
int type= RNA_enum_get(op->ptr, "type"); int type= RNA_enum_get(op->ptr, "type");
if(!ED_object_modifier_add(op->reports, scene, ob, type)) if(!ED_object_modifier_add(op->reports, scene, ob, NULL, type))
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);

View File

@@ -620,15 +620,15 @@ static int parent_set_exec(bContext *C, wmOperator *op)
switch (partype) { switch (partype) {
case PAR_CURVE: /* curve deform */ case PAR_CURVE: /* curve deform */
md= ED_object_modifier_add(op->reports, scene, ob, eModifierType_Curve); md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Curve);
((CurveModifierData *)md)->object= par; ((CurveModifierData *)md)->object= par;
break; break;
case PAR_LATTICE: /* lattice deform */ case PAR_LATTICE: /* lattice deform */
md= ED_object_modifier_add(op->reports, scene, ob, eModifierType_Lattice); md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Lattice);
((LatticeModifierData *)md)->object= par; ((LatticeModifierData *)md)->object= par;
break; break;
default: /* armature deform */ default: /* armature deform */
md= ED_object_modifier_add(op->reports, scene, ob, eModifierType_Armature); md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Armature);
((ArmatureModifierData *)md)->object= par; ((ArmatureModifierData *)md)->object= par;
break; break;
} }

View File

@@ -69,7 +69,7 @@ static int particle_system_add_exec(bContext *C, wmOperator *op)
if(!scene || !ob) if(!scene || !ob)
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
object_add_particle_system(scene, ob); object_add_particle_system(scene, ob, NULL);
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
return OPERATOR_FINISHED; return OPERATOR_FINISHED;

View File

@@ -662,7 +662,7 @@ static void rna_def_armature_edit_bones(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_struct_sdna(srna, "bArmature"); RNA_def_struct_sdna(srna, "bArmature");
RNA_def_struct_ui_text(srna, "Armature EditBones", "Collection of armature edit bones."); RNA_def_struct_ui_text(srna, "Armature EditBones", "Collection of armature edit bones.");
prop= RNA_def_property(srna, "edit_bones", PROP_POINTER, PROP_NONE); prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "EditBone"); RNA_def_property_struct_type(prop, "EditBone");
RNA_def_property_pointer_sdna(prop, NULL, "act_edbone"); RNA_def_property_pointer_sdna(prop, NULL, "act_edbone");
RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_flag(prop, PROP_EDITABLE);

View File

@@ -940,13 +940,13 @@ static void rna_Object_active_constraint_set(PointerRNA *ptr, PointerRNA value)
constraints_set_active(&ob->constraints, (bConstraint *)value.data); constraints_set_active(&ob->constraints, (bConstraint *)value.data);
} }
static bConstraint *rna_Object_constraints_new(Object *object, bContext *C, int type) static bConstraint *rna_Object_constraint_new(Object *object, bContext *C, int type)
{ {
WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object); WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object);
return add_ob_constraint(object, NULL, type); return add_ob_constraint(object, NULL, type);
} }
static int rna_Object_constraints_remove(Object *object, bContext *C, int index) static int rna_Object_constraint_remove(Object *object, bContext *C, int index)
{ {
int ok = remove_constraint_index(&object->constraints, index); int ok = remove_constraint_index(&object->constraints, index);
if(ok) { if(ok) {
@@ -957,6 +957,16 @@ static int rna_Object_constraints_remove(Object *object, bContext *C, int index)
return ok; return ok;
} }
static ModifierData *rna_Object_modifier_new(Object *object, bContext *C, ReportList *reports, char *name, int type)
{
return ED_object_modifier_add(reports, CTX_data_scene(C), object, name, type);
}
static void rna_Object_modifier_remove(Object *object, bContext *C, ReportList *reports, ModifierData *md)
{
return ED_object_modifier_remove(reports, CTX_data_scene(C), object, md);
}
#else #else
static void rna_def_vertex_group(BlenderRNA *brna) static void rna_def_vertex_group(BlenderRNA *brna)
@@ -1248,7 +1258,7 @@ static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop)
/* Constraint collection */ /* Constraint collection */
func= RNA_def_function(srna, "new", "rna_Object_constraints_new"); func= RNA_def_function(srna, "new", "rna_Object_constraint_new");
RNA_def_function_flag(func, FUNC_USE_CONTEXT); RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Add a new constraint to this object"); RNA_def_function_ui_description(func, "Add a new constraint to this object");
/* return type */ /* return type */
@@ -1258,7 +1268,7 @@ static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop)
parm= RNA_def_enum(func, "type", constraint_type_items, 1, "", "Constraint type to add."); parm= RNA_def_enum(func, "type", constraint_type_items, 1, "", "Constraint type to add.");
RNA_def_property_flag(parm, PROP_REQUIRED); RNA_def_property_flag(parm, PROP_REQUIRED);
func= RNA_def_function(srna, "remove", "rna_Object_constraints_remove"); func= RNA_def_function(srna, "remove", "rna_Object_constraint_remove");
RNA_def_function_flag(func, FUNC_USE_CONTEXT); RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Remove a constraint from this object."); RNA_def_function_ui_description(func, "Remove a constraint from this object.");
/* return type */ /* return type */
@@ -1269,6 +1279,55 @@ static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_flag(parm, PROP_REQUIRED); RNA_def_property_flag(parm, PROP_REQUIRED);
} }
/* armature.bones.* */
static void rna_def_object_modifiers(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
PropertyRNA *prop;
FunctionRNA *func;
PropertyRNA *parm;
RNA_def_property_srna(cprop, "ObjectModifiers");
srna= RNA_def_struct(brna, "ObjectModifiers", NULL);
RNA_def_struct_sdna(srna, "Object");
RNA_def_struct_ui_text(srna, "Object Modifiers", "Collection of object modifiers.");
#if 0
prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "EditBone");
RNA_def_property_pointer_sdna(prop, NULL, "act_edbone");
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Active EditBone", "Armatures active edit bone.");
//RNA_def_property_update(prop, 0, "rna_Armature_act_editbone_update");
RNA_def_property_pointer_funcs(prop, NULL, "rna_Armature_act_edit_bone_set", NULL);
/* todo, redraw */
// RNA_def_property_collection_active(prop, prop_act);
#endif
/* add target */
func= RNA_def_function(srna, "new", "rna_Object_modifier_new");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
RNA_def_function_ui_description(func, "Add a new bone.");
parm= RNA_def_string(func, "name", "Name", 0, "", "New name for the bone.");
RNA_def_property_flag(parm, PROP_REQUIRED);
/* modifier to add */
parm= RNA_def_enum(func, "type", modifier_type_items, 1, "", "Modifier type to add.");
RNA_def_property_flag(parm, PROP_REQUIRED);
/* return type */
parm= RNA_def_pointer(func, "modifier", "Modifier", "", "Newly created modifier.");
RNA_def_function_return(func, parm);
/* remove target */
func= RNA_def_function(srna, "remove", "rna_Object_modifier_remove");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
RNA_def_function_ui_description(func, "Remove an existing modifier from the object.");
/* target to remove*/
parm= RNA_def_pointer(func, "modifier", "Modifier", "", "Modifier to remove.");
RNA_def_property_flag(parm, PROP_REQUIRED);
}
static void rna_def_object(BlenderRNA *brna) static void rna_def_object(BlenderRNA *brna)
{ {
StructRNA *srna; StructRNA *srna;
@@ -1581,6 +1640,7 @@ static void rna_def_object(BlenderRNA *brna)
prop= RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE); prop= RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "Modifier"); RNA_def_property_struct_type(prop, "Modifier");
RNA_def_property_ui_text(prop, "Modifiers", "Modifiers affecting the geometric data of the Object."); RNA_def_property_ui_text(prop, "Modifiers", "Modifiers affecting the geometric data of the Object.");
rna_def_object_modifiers(brna, prop);
/* game engine */ /* game engine */
prop= RNA_def_property(srna, "game", PROP_POINTER, PROP_NONE); prop= RNA_def_property(srna, "game", PROP_POINTER, PROP_NONE);

View File

@@ -485,7 +485,7 @@ static void rna_FieldSettings_shape_update(bContext *C, PointerRNA *ptr)
if(!md) { if(!md) {
if(pd && (pd->shape == PFIELD_SHAPE_SURFACE) && ELEM(pd->forcefield,PFIELD_GUIDE,PFIELD_TEXTURE)==0) if(pd && (pd->shape == PFIELD_SHAPE_SURFACE) && ELEM(pd->forcefield,PFIELD_GUIDE,PFIELD_TEXTURE)==0)
if(ELEM4(ob->type, OB_MESH, OB_SURF, OB_FONT, OB_CURVE)) if(ELEM4(ob->type, OB_MESH, OB_SURF, OB_FONT, OB_CURVE))
ED_object_modifier_add(NULL, scene, ob, eModifierType_Surface); ED_object_modifier_add(NULL, scene, ob, NULL, eModifierType_Surface);
} }
else { else {
if(!pd || pd->shape != PFIELD_SHAPE_SURFACE) if(!pd || pd->shape != PFIELD_SHAPE_SURFACE)
@@ -620,7 +620,7 @@ static void rna_CollisionSettings_dependency_update(bContext *C, PointerRNA *ptr
/* add/remove modifier as needed */ /* add/remove modifier as needed */
if(ob->pd->deflect && !md) if(ob->pd->deflect && !md)
ED_object_modifier_add(NULL, scene, ob, eModifierType_Collision); ED_object_modifier_add(NULL, scene, ob, NULL, eModifierType_Collision);
else if(!ob->pd->deflect && md) else if(!ob->pd->deflect && md)
ED_object_modifier_remove(NULL, scene, ob, md); ED_object_modifier_remove(NULL, scene, ob, md);

View File

@@ -611,7 +611,7 @@ static void rna_def_pose_channel_constraints(BlenderRNA *brna, PropertyRNA *cpro
/* return type */ /* return type */
parm= RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint."); parm= RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint.");
RNA_def_function_return(func, parm); RNA_def_function_return(func, parm);
/* object to add */ /* constraint to add */
parm= RNA_def_enum(func, "type", constraint_type_items, 1, "", "Constraint type to add."); parm= RNA_def_enum(func, "type", constraint_type_items, 1, "", "Constraint type to add.");
RNA_def_property_flag(parm, PROP_REQUIRED); RNA_def_property_flag(parm, PROP_REQUIRED);

View File

@@ -132,7 +132,7 @@ void ED_node_shader_default(struct Material *ma){}
void ED_screen_animation_timer_update(struct bContext *C, int redraws){} void ED_screen_animation_timer_update(struct bContext *C, int redraws){}
void ED_base_object_select(struct Base *base, short mode){} void ED_base_object_select(struct Base *base, short mode){}
int ED_object_modifier_remove(struct ReportList *reports, struct Scene *scene, struct Object *ob, struct ModifierData *md){return 0;} int ED_object_modifier_remove(struct ReportList *reports, struct Scene *scene, struct Object *ob, struct ModifierData *md){return 0;}
int ED_object_modifier_add(struct ReportList *reports, struct Scene *scene, struct Object *ob, int type){return 0;} int ED_object_modifier_add(struct ReportList *reports, struct Scene *scene, struct Object *ob, char *name, int type){return 0;}
void ED_object_enter_editmode(struct bContext *C, int flag){} void ED_object_enter_editmode(struct bContext *C, int flag){}
void ED_object_exit_editmode(struct bContext *C, int flag){} void ED_object_exit_editmode(struct bContext *C, int flag){}
int uiLayoutGetActive(struct uiLayout *layout){return 0;} int uiLayoutGetActive(struct uiLayout *layout){return 0;}