Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2007-09-09 15:05:21 +0400
committerJoshua Leung <aligorith@gmail.com>2007-09-09 15:05:21 +0400
commit8ddbd84240e6d0cd8ca152ff95c473c6b2e9a910 (patch)
treed3416412e3fab932ca6b985900574ce5ab3df709 /source/blender/src
parentb709e2982fca75a7ec21ff595c87b3c5397a2dd9 (diff)
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.
Diffstat (limited to 'source/blender/src')
-rw-r--r--source/blender/src/editarmature.c90
-rw-r--r--source/blender/src/editobject.c11
-rw-r--r--source/blender/src/header_view3d.c12
3 files changed, 75 insertions, 38 deletions
diff --git a/source/blender/src/editarmature.c b/source/blender/src/editarmature.c
index a5b94faf9ae..1b674f404b8 100644
--- a/source/blender/src/editarmature.c
+++ b/source/blender/src/editarmature.c
@@ -2133,53 +2133,77 @@ void extrude_armature(int forked)
}
/* 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);
-
- 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);
+ 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];
- /* 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;
+ }
+ 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;
}
- newbone->parent= ebone;
}
}
}
}
}
- BIF_undo_push("Subdivide");
+
+ if(numcuts==1) BIF_undo_push("Subdivide");
+ else BIF_undo_push("Subdivide multi");
}
/* ***************** Pose tools ********************* */
diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c
index 42cec673219..d4c0f76b656 100644
--- a/source/blender/src/editobject.c
+++ b/source/blender/src/editobject.c
@@ -2508,10 +2508,15 @@ void special_editmenu(void)
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) {
diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c
index 196655cc97a..79c86012276 100644
--- a/source/blender/src/header_view3d.c
+++ b/source/blender/src/header_view3d.c
@@ -3672,6 +3672,8 @@ static uiBlock *view3d_edit_armature_rollmenu(void *arg_unused)
static void do_view3d_edit_armaturemenu(void *arg, int event)
{
+ static short numcuts= 2;
+
switch(event) {
case 0: /* Undo Editing */
@@ -3700,11 +3702,16 @@ static void do_view3d_edit_armaturemenu(void *arg, int event)
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 @@ static uiBlock *view3d_edit_armaturemenu(void *arg_unused)
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, "");