[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11981] trunk/blender/source/blender: Patch #6794: Subdivide Multi for Armatures

Joshua Leung aligorith at gmail.com
Sun Sep 9 13:05:22 CEST 2007


Revision: 11981
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11981
Author:   aligorith
Date:     2007-09-09 13:05:21 +0200 (Sun, 09 Sep 2007)

Log Message:
-----------
Patch #6794: Subdivide Multi for Armatures

This patch, by Juho Vepsalainen (BeBraw), introduces subdivide multi functionality for armatures. It lets you specify the number of divisions that selected bones should be divided into. 

I've slightly optimised the code a bit, though the change shouldn't make much of a difference. I've also fixed a minor bug in the menu highlighting, due to duplicate menu event-codes.

Modified Paths:
--------------
    trunk/blender/source/blender/include/BIF_editarmature.h
    trunk/blender/source/blender/src/editarmature.c
    trunk/blender/source/blender/src/editobject.c
    trunk/blender/source/blender/src/header_view3d.c

Modified: trunk/blender/source/blender/include/BIF_editarmature.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editarmature.h	2007-09-08 20:46:31 UTC (rev 11980)
+++ trunk/blender/source/blender/include/BIF_editarmature.h	2007-09-09 11:05:21 UTC (rev 11981)
@@ -85,7 +85,7 @@
 void	deselectall_posearmature (struct Object *ob, int test, int doundo);
 int		draw_armature(struct Base *base, int dt);
 void	extrude_armature(int forked);
-void	subdivide_armature(void);
+void	subdivide_armature(int numcuts);
 
 void	free_editArmature(void);
 
@@ -139,3 +139,4 @@
 
 #endif
 
+

Modified: trunk/blender/source/blender/src/editarmature.c
===================================================================
--- trunk/blender/source/blender/src/editarmature.c	2007-09-08 20:46:31 UTC (rev 11980)
+++ trunk/blender/source/blender/src/editarmature.c	2007-09-09 11:05:21 UTC (rev 11981)
@@ -2133,53 +2133,77 @@
 }
 
 /* context; editmode armature */
-void subdivide_armature(void)
+void subdivide_armature(int numcuts)
 {
 	bArmature *arm= G.obedit->data;
 	EditBone *ebone, *newbone, *tbone, *mbone;
-	int a;
+	int a, i;
 	
+	if(numcuts < 1) return;
+
 	for (mbone = G.edbo.last; mbone; mbone= mbone->prev) {
 		if(arm->layer & mbone->layer) {
 			if(mbone->flag & BONE_SELECTED) {
-				
-				/* take care of mirrored stuff */
-				for(a=0; a<2; a++) {
-					if(a==0) ebone= mbone;
-					else {
-						if(arm->flag & ARM_MIRROR_EDIT)
-							ebone= armature_bone_get_mirrored(mbone);
-						else ebone= NULL;
-					}
-					if(ebone) {
-
-						newbone= MEM_mallocN(sizeof(EditBone), "ebone subdiv");
-						*newbone = *ebone;
-						BLI_addtail(&G.edbo, newbone);
+				for(i=numcuts+1; i>1; i--) {
+					/* compute cut ratio first */
+					float cutratio= 1/(float)i;
+					float cutratioI= 1-cutratio;
+					
+					/* take care of mirrored stuff */
+					for(a=0; a<2; a++) {
+						float val1[3];
+						float val2[3];
+						float val3[3];
 						
-						VecMidf(newbone->head, ebone->head, ebone->tail);
-						VECCOPY(newbone->tail, ebone->tail);
-						VECCOPY(ebone->tail, newbone->head);
-						
-						newbone->rad_head= 0.5*(ebone->rad_head+ebone->rad_tail);
-						ebone->rad_tail= newbone->rad_head;
-
-						newbone->flag |= BONE_CONNECTED;
-						
-						unique_editbone_name (&G.edbo, newbone->name);
-						
-						/* correct parent bones */
-						for (tbone = G.edbo.first; tbone; tbone=tbone->next){
-							if(tbone->parent==ebone)
-								tbone->parent= newbone;
+						/* try to find mirrored bone on a != 0 */
+						if(a) {
+							if(arm->flag & ARM_MIRROR_EDIT)
+								ebone= armature_bone_get_mirrored(mbone);
+							else ebone= NULL;
 						}
-						newbone->parent= ebone;
+						else
+							ebone= mbone;
+							
+						if(ebone) {
+							newbone= MEM_mallocN(sizeof(EditBone), "ebone subdiv");
+							*newbone = *ebone;
+							BLI_addtail(&G.edbo, newbone);
+							
+							/* calculate location of newbone->head */
+							VECCOPY(val1, ebone->head);
+							VECCOPY(val2, ebone->tail);
+							VECCOPY(val3, newbone->head);
+							
+							val3[0]= val1[0]*cutratio+val2[0]*cutratioI;
+							val3[1]= val1[1]*cutratio+val2[1]*cutratioI;
+							val3[2]= val1[2]*cutratio+val2[2]*cutratioI;
+							
+							VECCOPY(newbone->head, val3);
+							VECCOPY(newbone->tail, ebone->tail);
+							VECCOPY(ebone->tail, newbone->head);
+							
+							newbone->rad_head= 0.5*(ebone->rad_head+ebone->rad_tail);
+							ebone->rad_tail= newbone->rad_head;
+							
+							newbone->flag |= BONE_CONNECTED;
+							
+							unique_editbone_name (&G.edbo, newbone->name);
+							
+							/* correct parent bones */
+							for (tbone = G.edbo.first; tbone; tbone=tbone->next){
+								if(tbone->parent==ebone)
+									tbone->parent= newbone;
+							}
+							newbone->parent= ebone;
+						}
 					}
 				}
 			}
 		}
 	}
-	BIF_undo_push("Subdivide");
+	
+	if(numcuts==1) BIF_undo_push("Subdivide");
+	else BIF_undo_push("Subdivide multi");
 }
 
 /* ***************** Pose tools ********************* */

Modified: trunk/blender/source/blender/src/editobject.c
===================================================================
--- trunk/blender/source/blender/src/editobject.c	2007-09-08 20:46:31 UTC (rev 11980)
+++ trunk/blender/source/blender/src/editobject.c	2007-09-09 11:05:21 UTC (rev 11981)
@@ -2508,10 +2508,15 @@
 		DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
 	}
 	else if(G.obedit->type==OB_ARMATURE) {
-		nr= pupmenu("Specials%t|Subdivide %x1|Flip Left-Right Names%x2");
+		nr= pupmenu("Specials%t|Subdivide %x1|Subdivide Multi%x2|Flip Left-Right Names%x3");
 		if(nr==1)
-			subdivide_armature();
-		else if(nr==2)
+			subdivide_armature(1);
+		if(nr==2) {
+			if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
+			waitcursor(1);
+			subdivide_armature(numcuts);
+		}
+		else if(nr==3)
 			armature_flip_names();
 	}
 	else if(G.obedit->type==OB_LATTICE) {

Modified: trunk/blender/source/blender/src/header_view3d.c
===================================================================
--- trunk/blender/source/blender/src/header_view3d.c	2007-09-08 20:46:31 UTC (rev 11980)
+++ trunk/blender/source/blender/src/header_view3d.c	2007-09-09 11:05:21 UTC (rev 11981)
@@ -3672,6 +3672,8 @@
 
 static void do_view3d_edit_armaturemenu(void *arg, int event)
 {
+	static short numcuts= 2;
+
 	switch(event) {
 	
 	case 0: /* Undo Editing */
@@ -3700,11 +3702,16 @@
 		extrude_armature(1);
 		break;
 	case 12: /* subdivide */
-		subdivide_armature();
+		subdivide_armature(1);
 		break;
 	case 13: /* flip left and right names */
 		armature_flip_names();
 		break;
+		break;
+	case 15: /* subdivide multi */
+		if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
+		waitcursor(1);
+		subdivide_armature(numcuts);
 	}
 	allqueue(REDRAWVIEW3D, 0);
 }
@@ -3774,7 +3781,8 @@
 	uiDefBut(block, SEPR, 0, "",				0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
 	
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Subdivide|W, 1",			0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
-	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Flip Left & Right Names|W, 2",	0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Subdivide Multi|W, 2",			0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, "");
+	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Flip Left & Right Names|W, 3",	0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
 	
 	uiDefBut(block, SEPR, 0, "",				0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
 	





More information about the Bf-blender-cvs mailing list