[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10731] trunk/blender/source/blender/src/ editarmature.c: Plumifero's wishlist:

Chris Want cwant at ualberta.ca
Thu May 17 23:28:34 CEST 2007


Revision: 10731
          https://svn.blender.org//revision/?rev=10731&view=rev
Author:   hos
Date:     2007-05-17 23:28:33 +0200 (Thu, 17 May 2007)

Log Message:
-----------
Plumifero's wishlist:

* When duplicating bones that have constraints (edit mode),
duplicate them too with TARGET field updated.

This is code that I wrote a few years ago before the armature
refactor. It is simple code that compiles and seems to work fine,
but should be checked by Ton or somebody else with better knowledge
of the current armature system.

Usage description, (stolen from the first time this code was
committed):

"Duplicating bones in edit mode now also duplicates the constraints
associated with that bone ... if the constraint subtarget bone is
also duplicated the new constraint points to this new bone as it's
subtarget."

Modified Paths:
--------------
    trunk/blender/source/blender/src/editarmature.c

Modified: trunk/blender/source/blender/src/editarmature.c
===================================================================
--- trunk/blender/source/blender/src/editarmature.c	2007-05-17 17:15:22 UTC (rev 10730)
+++ trunk/blender/source/blender/src/editarmature.c	2007-05-17 21:28:33 UTC (rev 10731)
@@ -1539,6 +1539,54 @@
 }
 
 
+static EditBone *get_named_editbone(char *name)
+{
+	EditBone  *eBone;
+
+	if (name)
+		for (eBone=G.edbo.first; eBone; eBone=eBone->next){
+			if (!strcmp (name, eBone->name))
+				return eBone;
+		}
+
+	return NULL;
+}
+
+static void update_dup_subtarget(EditBone *dupBone)
+{
+	/* If an edit bone has been duplicated, lets
+	 * update it's constraints if the subtarget
+	 * they point to has also been duplicated
+	 */
+	EditBone     *oldtarget, *newtarget;
+	bPoseChannel *chan;
+	bConstraint  *curcon;
+	ListBase     *conlist;
+	char         *subname;
+
+
+	if ( (chan = verify_pose_channel(OBACT->pose, dupBone->name)) )
+		if ( (conlist = &chan->constraints) )
+			for (curcon = conlist->first; curcon; curcon=curcon->next) {
+				/* does this constraint have a subtarget in
+				 * this armature?
+				 */
+				subname = get_con_subtarget_name(curcon, G.obedit);
+				oldtarget = get_named_editbone(subname);
+				if (oldtarget)
+					/* was the subtarget bone duplicated too? If
+					 * so, update the constraint to point at the 
+					 * duplicate of the old subtarget.
+					 */
+					if (oldtarget->flag & BONE_SELECTED){
+						newtarget = (EditBone*) oldtarget->temp;
+						strcpy(subname, newtarget->name);
+					}
+			}
+	
+}
+
+
 void adduplicate_armature(void)
 {
 	bArmature *arm= G.obedit->data;
@@ -1570,7 +1618,24 @@
 				/* Lets duplicate the list of constraits that the
 					* current bone has.
 					*/
-				/* temporal removed (ton) */
+				if (OBACT->pose) {
+					bPoseChannel *chanold, *channew;
+					ListBase     *listold, *listnew;
+
+					chanold = verify_pose_channel (OBACT->pose, curBone->name);
+					if (chanold) {
+						listold = &chanold->constraints;
+						if (listold){
+							channew = 
+								verify_pose_channel(OBACT->pose, eBone->name);
+							if (channew) {
+								listnew = &channew->constraints;
+								copy_constraints (listnew, listold);
+							}
+						}
+					}
+				}
+
 			}
 		}
 	}
@@ -1603,8 +1668,8 @@
 				
 				/* Lets try to fix any constraint subtargets that might
 					have been duplicated */
-				/* temporal removed (ton) */
-			}			
+				update_dup_subtarget(eBone);
+			}
 		}
 	} 
 	





More information about the Bf-blender-cvs mailing list