[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24185] trunk/blender/source/blender: Proportional edit for object mode.

Martin Poirier theeth at yahoo.com
Fri Oct 30 18:48:50 CET 2009


Revision: 24185
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24185
Author:   theeth
Date:     2009-10-30 18:48:50 +0100 (Fri, 30 Oct 2009)

Log Message:
-----------
Proportional edit for object mode.

Limitations:

1) Parents and children of selected objects are excluded from the pool (siblings are ok) Making it work with that would required unparenting and reparenting after transform, that would turn nasty really quick.

2) Does not support Connected (this could be done through parent links, but see 3 first).

3) Parent relationships in affected objects aren't taken into account. When parent and children in the area of effect, remember that the children will also take the motion of the parents (with additive results). This could perhaps be fixed, but it could be nasty.


Other stuff:
New BASE_EDITABLE macro that checks if base is editable (like TESTBASELIB except it doesn't check for selection)
Add scene parameter to TESTBASELIB_BGMODE macro (using it from current scope is nasty)

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/multires.c
    trunk/blender/source/blender/editors/object/object_ops.c
    trunk/blender/source/blender/editors/space_view3d/view3d_header.c
    trunk/blender/source/blender/editors/transform/transform_conversions.c
    trunk/blender/source/blender/editors/transform/transform_generics.c
    trunk/blender/source/blender/makesdna/DNA_object_types.h
    trunk/blender/source/blender/makesdna/DNA_scene_types.h

Modified: trunk/blender/source/blender/blenkernel/intern/multires.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/multires.c	2009-10-30 17:23:40 UTC (rev 24184)
+++ trunk/blender/source/blender/blenkernel/intern/multires.c	2009-10-30 17:48:50 UTC (rev 24185)
@@ -101,7 +101,7 @@
 	/* First find the highest level of subdivision */
 	base = FIRSTBASE;
 	while(base) {
-		if(TESTBASELIB_BGMODE(v3d, base) && base->object->type==OB_MESH) {
+		if(TESTBASELIB_BGMODE(v3d, scene, base) && base->object->type==OB_MESH) {
 			ModifierData *md;
 			for(md = base->object->modifiers.first; md; md = md->next) {
 				if(md->type == eModifierType_Multires) {
@@ -124,7 +124,7 @@
 	/* Subdivide all the displacements to the highest level */
 	base = FIRSTBASE;
 	while(base) {
-		if(TESTBASELIB_BGMODE(v3d, base) && base->object->type==OB_MESH) {
+		if(TESTBASELIB_BGMODE(v3d, scene, base) && base->object->type==OB_MESH) {
 			ModifierData *md = NULL;
 			MultiresModifierData *mmd = NULL;
 

Modified: trunk/blender/source/blender/editors/object/object_ops.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_ops.c	2009-10-30 17:23:40 UTC (rev 24184)
+++ trunk/blender/source/blender/editors/object/object_ops.c	2009-10-30 17:48:50 UTC (rev 24185)
@@ -196,7 +196,8 @@
 	ot= WM_operatortype_append_macro("OBJECT_OT_duplicate_move", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
 	if(ot) {
 		WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
-		WM_operatortype_macro_define(ot, "TFM_OT_translate");
+		otmacro= WM_operatortype_macro_define(ot, "TFM_OT_translate");
+		RNA_enum_set(otmacro->ptr, "proportional", PROP_EDIT_OFF);
 	}
 
 	/* grr, should be able to pass options on... */
@@ -204,7 +205,8 @@
 	if(ot) {
 		otmacro= WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
 		RNA_boolean_set(otmacro->ptr, "linked", 1);
-		WM_operatortype_macro_define(ot, "TFM_OT_translate");
+		otmacro= WM_operatortype_macro_define(ot, "TFM_OT_translate");
+		RNA_enum_set(otmacro->ptr, "proportional", PROP_EDIT_OFF);
 	}
 }
 
@@ -238,6 +240,9 @@
 	keymap= WM_keymap_find(keyconf, "Object Mode", 0, 0);
 	keymap->poll= object_mode_poll;
 	
+	/* object mode supports PET now */
+	ED_object_generic_keymap(keyconf, keymap, TRUE);
+
 	WM_keymap_add_item(keymap, "OBJECT_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
 	WM_keymap_add_item(keymap, "OBJECT_OT_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
 	WM_keymap_add_item(keymap, "OBJECT_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0);

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_header.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_header.c	2009-10-30 17:23:40 UTC (rev 24184)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_header.c	2009-10-30 17:48:50 UTC (rev 24185)
@@ -2162,7 +2162,7 @@
 		}
 	
 		/* proportional falloff */
-		if((obedit && (obedit->type == OB_MESH || obedit->type == OB_CURVE || obedit->type == OB_SURF || obedit->type == OB_LATTICE)) || (ob && ob->mode & OB_MODE_PARTICLE_EDIT)) {
+		if((obedit == NULL || (obedit->type == OB_MESH || obedit->type == OB_CURVE || obedit->type == OB_SURF || obedit->type == OB_LATTICE)) || (ob && ob->mode & OB_MODE_PARTICLE_EDIT)) {
 		
 			uiBlockBeginAlign(block);
 			uiDefIconTextButS(block, ICONTEXTROW,B_REDR, ICON_PROP_OFF, "Proportional %t|Off %x0|On %x1|Connected %x2", xco,yco,XIC+10,YIC, &(ts->proportional), 0, 1.0, 0, 0, "Proportional Edit Falloff (Hotkeys: O, Alt O) ");

Modified: trunk/blender/source/blender/editors/transform/transform_conversions.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_conversions.c	2009-10-30 17:23:40 UTC (rev 24184)
+++ trunk/blender/source/blender/editors/transform/transform_conversions.c	2009-10-30 17:48:50 UTC (rev 24185)
@@ -4314,7 +4314,7 @@
 /* it deselects Bases, so we have to call the clear function always after */
 static void set_trans_object_base_flags(bContext *C, TransInfo *t)
 {
-	Scene *scene = CTX_data_scene(C);
+	Scene *scene = t->scene;
 	View3D *v3d = t->view;
 
 	/*
@@ -4339,7 +4339,7 @@
 	for (base= scene->base.first; base; base= base->next) {
 		base->flag &= ~BA_WAS_SEL;
 
-		if(TESTBASELIB_BGMODE(v3d, base)) {
+		if(TESTBASELIB_BGMODE(v3d, scene, base)) {
 			Object *ob= base->object;
 			Object *parsel= ob->parent;
 
@@ -4351,12 +4351,10 @@
 
 			if(parsel)
 			{
-				if ((t->mode == TFM_ROTATION || t->mode == TFM_TRACKBALL)  && t->around == V3D_LOCAL)
-				{
+				/* rotation around local centers are allowed to propagate */
+				if ((t->mode == TFM_ROTATION || t->mode == TFM_TRACKBALL)  && t->around == V3D_LOCAL) {
 					base->flag |= BA_TRANSFORM_CHILD;
-				}
-				else
-				{
+				} else {
 					base->flag &= ~SELECT;
 					base->flag |= BA_WAS_SEL;
 				}
@@ -4379,6 +4377,86 @@
 	}
 }
 
+static int mark_children(Object *ob)
+{
+	if (ob->flag & (SELECT|BA_TRANSFORM_CHILD))
+		return 1;
+
+	if (ob->parent)
+	{
+		if (mark_children(ob->parent))
+		{
+			ob->flag |= BA_TRANSFORM_CHILD;
+			return 1;
+		}
+	}
+	
+	return 0;
+}
+
+static int count_proportional_objects(TransInfo *t)
+{
+	int total = 0;
+	Scene *scene = t->scene;
+	View3D *v3d = t->view;
+	Base *base;
+
+	/* rotations around local centers are allowed to propagate, so we take all objects */
+	if (!((t->mode == TFM_ROTATION || t->mode == TFM_TRACKBALL)  && t->around == V3D_LOCAL))
+	{
+		/* mark all parents */
+		for (base= scene->base.first; base; base= base->next) {
+			if(TESTBASELIB_BGMODE(v3d, scene, base)) {
+				Object *parent = base->object->parent;
+	
+				/* flag all parents */
+				while(parent) {
+					parent->flag |= BA_TRANSFORM_PARENT;
+					parent = parent->parent;
+				}
+			}
+		}
+
+		/* mark all children */
+		for (base= scene->base.first; base; base= base->next) {
+			/* all base not already selected or marked that is editable */
+			if ((base->object->flag & (SELECT|BA_TRANSFORM_CHILD|BA_TRANSFORM_PARENT)) == 0 && BASE_EDITABLE_BGMODE(v3d, scene, base))
+			{
+				mark_children(base->object);
+			}
+		}
+	}
+	
+	for (base= scene->base.first; base; base= base->next) {
+		Object *ob= base->object;
+
+		/* if base is not selected, not a parent of selection or not a child of selection and it is editable */
+		if ((ob->flag & (SELECT|BA_TRANSFORM_CHILD|BA_TRANSFORM_PARENT)) == 0 && BASE_EDITABLE_BGMODE(v3d, scene, base))
+		{
+
+			/* used for flush, depgraph will change recalcs if needed :) */
+			ob->recalc |= OB_RECALC_OB;
+
+			total += 1;
+		}
+	}
+	
+
+	/* all recalc flags get flushed to all layers, so a layer flip later on works fine */
+	DAG_scene_flush_update(t->scene, -1, 0);
+
+	/* and we store them temporal in base (only used for transform code) */
+	/* this because after doing updates, the object->recalc is cleared */
+	for (base= scene->base.first; base; base= base->next) {
+		if(base->object->recalc & OB_RECALC_OB)
+			base->flag |= BA_HAS_RECALC_OB;
+		if(base->object->recalc & OB_RECALC_DATA)
+			base->flag |= BA_HAS_RECALC_DATA;
+	}
+
+	return total;
+}
+
 static void clear_trans_object_base_flags(TransInfo *t)
 {
 	Scene *sce = t->scene;
@@ -4389,7 +4467,7 @@
 		if(base->flag & BA_WAS_SEL)
 			base->flag |= SELECT;
 
-		base->flag &= ~(BA_WAS_SEL|BA_HAS_RECALC_OB|BA_HAS_RECALC_DATA|BA_DO_IPO|BA_TRANSFORM_CHILD);
+		base->flag &= ~(BA_WAS_SEL|BA_HAS_RECALC_OB|BA_HAS_RECALC_DATA|BA_DO_IPO|BA_TRANSFORM_CHILD|BA_TRANSFORM_PARENT);
 	}
 }
 
@@ -4972,19 +5050,23 @@
 {
 	TransData *td = NULL;
 	TransDataExtension *tx;
-//	IpoKey *ik;
-//	ListBase elems;
+	int propmode = t->flag & T_PROP_EDIT;
 
 	set_trans_object_base_flags(C, t);
 
 	/* count */
 	t->total= CTX_DATA_COUNT(C, selected_objects);
-
+	
 	if(!t->total) {
 		/* clear here, main transform function escapes too */
 		clear_trans_object_base_flags(t);
 		return;
 	}
+	
+	if (propmode)
+	{
+		t->total += count_proportional_objects(t);
+	}
 
 	td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransOb");
 	tx = t->ext = MEM_callocN(t->total*sizeof(TransDataExtension), "TransObExtension");
@@ -5015,6 +5097,30 @@
 		tx++;
 	}
 	CTX_DATA_END;
+	
+	if (propmode)
+	{
+		Scene *scene = t->scene;
+		View3D *v3d = t->view;
+		Base *base;
+
+		for (base= scene->base.first; base; base= base->next) {
+			Object *ob= base->object;
+
+			/* if base is not selected, not a parent of selection or not a child of selection and it is editable */
+			if ((ob->flag & (SELECT|BA_TRANSFORM_CHILD|BA_TRANSFORM_PARENT)) == 0 && BASE_EDITABLE_BGMODE(v3d, scene, base))
+			{
+				td->protectflag= ob->protectflag;
+				td->ext = tx;
+				td->rotOrder= ob->rotmode;
+				
+				ObjectToTransData(C, t, td, ob);
+				td->val = NULL;
+				td++;
+				tx++;
+			}
+		}
+	}
 }
 
 /* transcribe given node into TransData2D for Transforming */
@@ -5145,6 +5251,8 @@
 			printf("edit type not implemented!\n");
 		}
 
+		t->flag |= T_EDIT|T_POINTS;
+
 		if(t->data && t->flag & T_PROP_EDIT) {
 			if (ELEM(t->obedit->type, OB_CURVE, OB_MESH)) {
 				sort_trans_data(t);	// makes selected become first in array
@@ -5158,8 +5266,6 @@
 			}
 		}
 
-		t->flag |= T_EDIT|T_POINTS;
-
 		/* exception... hackish, we want bonesize to use bone orientation matrix (ton) */
 		if(t->mode==TFM_BONESIZE) {
 			t->flag &= ~(T_EDIT|T_POINTS);
@@ -5190,22 +5296,27 @@
 	else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT) 
 		&& PE_start_edit(PE_get_current(scene, ob))) {
 		createTransParticleVerts(C, t);
+		t->flag |= T_POINTS;
 
 		if(t->data && t->flag & T_PROP_EDIT) {
 			sort_trans_data(t);	// makes selected become first in array
 			set_prop_dist(t, 1);
 			sort_trans_data_dist(t);
 		}
-
-		t->flag |= T_POINTS;
 	}
 	else {
-		t->flag &= ~T_PROP_EDIT; /* no proportional edit in object mode */
+		// t->flag &= ~T_PROP_EDIT; /* no proportional edit in object mode */
 		t->options |= CTX_NO_PET;
 		
 		createTransObject(C, t);
 		t->flag |= T_OBJECT;
 
+		if(t->data && t->flag & T_PROP_EDIT) {
+			// selected objects are already first, no need to presort
+			set_prop_dist(t, 1);
+			sort_trans_data_dist(t);
+		}
+
 		if (t->ar->regiontype == RGN_TYPE_WINDOW)
 		{
 			View3D *v3d = t->view;

Modified: trunk/blender/source/blender/editors/transform/transform_generics.c
===================================================================

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list