From e9c15504324f7daad19b0910b99385ac5e8c9a8e Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Mon, 3 Aug 2009 14:40:10 +0000 Subject: [PATCH] 2.5 MetaBalls and UI * Added callback function for some metaball properties: When some properties (wiresize, threshold, update flags) of metaball are changed, then these properties are copied to all metaballs in the group (all metaballs with same base name). This is important to "share" some properties between metaballs, because polygonisation of metaball is influenced only by properties of base metaball and base metaball can be changed. * Improved drawing of selected Metaball objects --- source/blender/blenkernel/BKE_mball.h | 1 + source/blender/blenkernel/intern/mball.c | 49 +++++++++++++++++-- .../blender/editors/space_view3d/drawobject.c | 2 +- source/blender/makesrna/intern/rna_meta.c | 40 +++++++++++---- 4 files changed, 77 insertions(+), 15 deletions(-) diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h index ba78aa0682d..ff9ac693ba8 100644 --- a/source/blender/blenkernel/BKE_mball.h +++ b/source/blender/blenkernel/BKE_mball.h @@ -164,6 +164,7 @@ struct MetaBall *copy_mball(struct MetaBall *mb); void make_local_mball(struct MetaBall *mb); void tex_space_mball(struct Object *ob); float *make_orco_mball(struct Object *ob); +void copy_mball_properties(struct Scene *scene, struct Object *active_object); struct Object *find_basis_mball(struct Scene *scene, struct Object *ob); int is_basis_mball(struct Object *ob); void metaball_polygonize(struct Scene *scene, struct Object *ob); diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index c7058d7d8db..3ca7dac4bc9 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -69,10 +69,10 @@ /* Global variables */ -float thresh= 0.6f; -int totelem=0; -MetaElem **mainb; -octal_tree *metaball_tree = NULL; +static float thresh= 0.6f; +static int totelem=0; +static MetaElem **mainb; +static octal_tree *metaball_tree = NULL; /* Functions */ void unlink_mball(MetaBall *mb) @@ -280,6 +280,47 @@ int is_basis_mball(Object *ob) return 1; } +/* \brief copy some properties from object to other metaball object with same base name + * + * When some properties (wiresize, threshold, update flags) of metaball are changed, then this properties + * are copied to all metaballs in same "group" (metaballs with same base name: MBall, + * MBall.001, MBall.002, etc). The most important is to copy properties to the base metaball, + * because this metaball influence polygonisation of metaballs. */ +void copy_mball_properties(Scene *scene, Object *active_object) +{ + Base *base; + Object *ob; + MetaBall *active_mball = (MetaBall*)active_object->data; + int basisnr, obnr; + char basisname[32], obname[32]; + + splitIDname(active_object->id.name+2, basisname, &basisnr); + + /* XXX recursion check, see scene.c, just too simple code this next_object() */ + if(F_ERROR==next_object(scene, 0, 0, 0)) + return; + + while(next_object(scene, 1, &base, &ob)) { + if (ob->type==OB_MBALL) { + if(ob!=active_object){ + splitIDname(ob->id.name+2, obname, &obnr); + + /* Object ob has to be in same "group" ... it means, that it has to have + * same base of its name */ + if(strcmp(obname, basisname)==0){ + MetaBall *mb= ob->data; + + /* Copy properties from selected/edited metaball */ + mb->wiresize= active_mball->wiresize; + mb->rendersize= active_mball->rendersize; + mb->thresh= active_mball->thresh; + mb->flag= active_mball->flag; + } + } + } + } +} + /** \brief This function finds basic MetaBall. * * Basic MetaBall doesn't include any number at the end of diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 24306fa6298..f9d46cff9e6 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -4399,7 +4399,7 @@ static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, if(ml==NULL) return 1; /* in case solid draw, reset wire colors */ - if(mb->editelems && (ob->flag & SELECT)) { + if(ob->flag & SELECT) { if(ob==OBACT) UI_ThemeColor(TH_ACTIVE); else UI_ThemeColor(TH_SELECT); } diff --git a/source/blender/makesrna/intern/rna_meta.c b/source/blender/makesrna/intern/rna_meta.c index 17193f313f5..e142bc4b2aa 100644 --- a/source/blender/makesrna/intern/rna_meta.c +++ b/source/blender/makesrna/intern/rna_meta.c @@ -37,6 +37,7 @@ #include "DNA_scene_types.h" #include "DNA_object_types.h" +#include "BKE_mball.h" #include "BKE_depsgraph.h" #include "WM_types.h" @@ -49,6 +50,24 @@ static int rna_Meta_texspace_editable(PointerRNA *ptr) } static void rna_MetaBall_update_data(bContext *C, PointerRNA *ptr) +{ + Scene *scene= CTX_data_scene(C); + Object *active_object = CTX_data_active_object(C); + Object *obedit= CTX_data_edit_object(C); + + if(obedit) { + copy_mball_properties(scene, obedit); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, obedit); + DAG_object_flush_update(scene, obedit, OB_RECALC_DATA); + } + else if(active_object) { + copy_mball_properties(scene, active_object); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, active_object); + DAG_object_flush_update(scene, active_object, OB_RECALC_DATA); + } +} + +static void rna_MetaElem_update_data(bContext *C, PointerRNA *ptr) { Scene *scene= CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); @@ -80,59 +99,59 @@ void rna_def_metaelement(BlenderRNA *brna) prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, prop_type_items); RNA_def_property_ui_text(prop, "Type", "Metaball types."); - RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); + RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); /* number values */ prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_VECTOR); RNA_def_property_float_sdna(prop, NULL, "x"); RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Location", ""); - RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); + RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); prop= RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_ROTATION); RNA_def_property_float_sdna(prop, NULL, "quat"); RNA_def_property_ui_text(prop, "Rotation", ""); - RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); + RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); prop= RNA_def_property(srna, "radius", PROP_FLOAT, PROP_UNSIGNED); RNA_def_property_float_sdna(prop, NULL, "rad"); RNA_def_property_ui_text(prop, "Radius", ""); - RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); + RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); prop= RNA_def_property(srna, "sizex", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "expx"); RNA_def_property_range(prop, 0.0f, 20.0f); RNA_def_property_ui_text(prop, "Size X", "Size of element, use of components depends on element type."); - RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); + RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); prop= RNA_def_property(srna, "sizey", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "expy"); RNA_def_property_range(prop, 0.0f, 20.0f); RNA_def_property_ui_text(prop, "Size Y", "Size of element, use of components depends on element type."); - RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); + RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); prop= RNA_def_property(srna, "sizez", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "expz"); RNA_def_property_range(prop, 0.0f, 20.0f); RNA_def_property_ui_text(prop, "Size Z", "Size of element, use of components depends on element type."); - RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); + RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); prop= RNA_def_property(srna, "stiffness", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "s"); RNA_def_property_range(prop, 0.0f, 10.0f); RNA_def_property_ui_text(prop, "Stiffness", "Stiffness defines how much of the element to fill."); - RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); + RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); /* flags */ prop= RNA_def_property(srna, "negative", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", MB_NEGATIVE); RNA_def_property_ui_text(prop, "Negative", "Set metaball as negative one."); - RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); + RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); prop= RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", MB_HIDE); RNA_def_property_ui_text(prop, "Hide", "Hide element."); - RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); + RNA_def_property_update(prop, 0, "rna_MetaElem_update_data"); } void rna_def_metaball(BlenderRNA *brna) @@ -176,6 +195,7 @@ void rna_def_metaball(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "rendersize"); RNA_def_property_range(prop, 0.050f, 1.0f); RNA_def_property_ui_text(prop, "Render Size", "Polygonization resolution in rendering."); + RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); prop= RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "thresh");