[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22181] branches/blender2.5/blender/source /blender: 2.5 MetaBalls and UI

Jiri Hnidek jiri.hnidek at tul.cz
Mon Aug 3 16:40:10 CEST 2009


Revision: 22181
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22181
Author:   jiri
Date:     2009-08-03 16:40:10 +0200 (Mon, 03 Aug 2009)

Log Message:
-----------
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

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_mball.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/mball.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/drawobject.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_meta.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_mball.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_mball.h	2009-08-03 14:38:15 UTC (rev 22180)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_mball.h	2009-08-03 14:40:10 UTC (rev 22181)
@@ -164,6 +164,7 @@
 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);

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/mball.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/mball.c	2009-08-03 14:38:15 UTC (rev 22180)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/mball.c	2009-08-03 14:40:10 UTC (rev 22181)
@@ -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 @@
 	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

Modified: branches/blender2.5/blender/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_view3d/drawobject.c	2009-08-03 14:38:15 UTC (rev 22180)
+++ branches/blender2.5/blender/source/blender/editors/space_view3d/drawobject.c	2009-08-03 14:40:10 UTC (rev 22181)
@@ -4399,7 +4399,7 @@
 	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);
 	}

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_meta.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_meta.c	2009-08-03 14:38:15 UTC (rev 22180)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_meta.c	2009-08-03 14:40:10 UTC (rev 22181)
@@ -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"
@@ -51,7 +52,25 @@
 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);
 	
 	WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, obedit);
 	DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
@@ -80,59 +99,59 @@
 	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 @@
 	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");





More information about the Bf-blender-cvs mailing list