| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * $Id$ | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version.  | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Ton Roosendaal, Blender Foundation '05, full recode. | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  |  *				 Joshua Leung | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * support for animation modes - Reevan McKay | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <stddef.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_arithb.h"
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							|  |  |  | #include "BLI_dynstr.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												2.5: Blender "Animato" - New Animation System 
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action. 
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves. 
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still) 
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
											
										 
											2009-01-17 03:12:50 +00:00
										 |  |  | #include "DNA_anim_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | #include "DNA_action_types.h"
 | 
					
						
							|  |  |  | #include "DNA_armature_types.h"
 | 
					
						
							|  |  |  | #include "DNA_constraint_types.h"
 | 
					
						
							|  |  |  | #include "DNA_curve_types.h"
 | 
					
						
							|  |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							|  |  |  | #include "DNA_meshdata_types.h"
 | 
					
						
							|  |  |  | #include "DNA_modifier_types.h"
 | 
					
						
							|  |  |  | #include "DNA_object_types.h"
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							|  |  |  | #include "DNA_screen_types.h"
 | 
					
						
							|  |  |  | #include "DNA_view3d_types.h"
 | 
					
						
							|  |  |  | #include "DNA_userdef_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | #include "BKE_animsys.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | #include "BKE_action.h"
 | 
					
						
							|  |  |  | #include "BKE_armature.h"
 | 
					
						
							|  |  |  | #include "BKE_blender.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-10 14:19:14 +00:00
										 |  |  | #include "BKE_context.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | #include "BKE_constraint.h"
 | 
					
						
							|  |  |  | #include "BKE_deform.h"
 | 
					
						
							|  |  |  | #include "BKE_depsgraph.h"
 | 
					
						
							|  |  |  | #include "BKE_displist.h"
 | 
					
						
							| 
									
										
											  
											
												2.5: Blender "Animato" - New Animation System 
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action. 
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves. 
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still) 
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
											
										 
											2009-01-17 03:12:50 +00:00
										 |  |  | #include "BKE_fcurve.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | #include "BKE_global.h"
 | 
					
						
							|  |  |  | #include "BKE_modifier.h"
 | 
					
						
							|  |  |  | #include "BKE_object.h"
 | 
					
						
							|  |  |  | #include "BKE_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | #include "BKE_report.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BIF_gl.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-01 19:53:24 +00:00
										 |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | #include "RNA_define.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | #include "ED_armature.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-10 14:19:14 +00:00
										 |  |  | #include "ED_anim_api.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | #include "ED_keyframing.h"
 | 
					
						
							|  |  |  | #include "ED_object.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-10 14:19:14 +00:00
										 |  |  | #include "ED_mesh.h"
 | 
					
						
							| 
									
										
										
										
											2009-02-16 17:18:24 +00:00
										 |  |  | #include "ED_screen.h"
 | 
					
						
							| 
									
										
										
										
											2009-07-08 16:17:47 +00:00
										 |  |  | #include "ED_transform.h" /* for autokey TFM_TRANSLATION, etc */
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | #include "ED_view3d.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | #include "UI_interface.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | #include "armature_intern.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************* XXX *************** */ | 
					
						
							|  |  |  | static int pupmenu() {return 0;} | 
					
						
							|  |  |  | static void error() {}; | 
					
						
							|  |  |  | static void BIF_undo_push() {} | 
					
						
							|  |  |  | static void countall() {} | 
					
						
							|  |  |  | static void autokeyframe_pose_cb_func() {} | 
					
						
							|  |  |  | /* ************* XXX *************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-05 03:28:07 +00:00
										 |  |  | /* This function is used to indicate that a bone is selected and needs keyframes inserted */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | void set_pose_keys (Object *ob) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bArmature *arm= ob->data; | 
					
						
							|  |  |  | 	bPoseChannel *chan; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ob->pose){ | 
					
						
							|  |  |  | 		for (chan=ob->pose->chanbase.first; chan; chan=chan->next){ | 
					
						
							|  |  |  | 			Bone *bone= chan->bone; | 
					
						
							| 
									
										
										
										
											2009-02-05 03:28:07 +00:00
										 |  |  | 			if ((bone) && (bone->flag & BONE_SELECTED) && (arm->layer & bone->layer)) | 
					
						
							|  |  |  | 				chan->flag |= POSE_KEY;	 | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				chan->flag &= ~POSE_KEY; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-05 03:28:07 +00:00
										 |  |  | /* This function is used to process the necessary updates for */ | 
					
						
							| 
									
										
										
										
											2009-02-01 19:53:24 +00:00
										 |  |  | void ED_armature_enter_posemode(bContext *C, Base *base) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-01-05 19:32:04 +00:00
										 |  |  | 	Object *ob= base->object; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-01-05 19:32:04 +00:00
										 |  |  | 	if (ob->id.lib){ | 
					
						
							|  |  |  | 		error ("Can't pose libdata"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-01-05 19:32:04 +00:00
										 |  |  | 	switch (ob->type){ | 
					
						
							|  |  |  | 		case OB_ARMATURE: | 
					
						
							| 
									
										
										
										
											2009-09-08 02:09:14 +00:00
										 |  |  | 			ob->restore_mode = ob->mode; | 
					
						
							| 
									
										
										
										
											2009-08-16 03:24:23 +00:00
										 |  |  | 			ob->mode |= OB_MODE_POSE; | 
					
						
							| 
									
										
										
										
											2009-01-05 19:32:04 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2009-02-20 20:39:27 +00:00
										 |  |  | 			WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_POSE, NULL); | 
					
						
							| 
									
										
										
										
											2009-02-01 19:53:24 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2009-01-05 19:32:04 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-08-16 02:35:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-08 02:09:14 +00:00
										 |  |  | 	//ED_object_toggle_modes(C, ob->mode);
 | 
					
						
							| 
									
										
										
										
											2009-01-05 19:32:04 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-01 19:53:24 +00:00
										 |  |  | void ED_armature_exit_posemode(bContext *C, Base *base) | 
					
						
							| 
									
										
										
										
											2009-01-05 19:32:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if(base) { | 
					
						
							|  |  |  | 		Object *ob= base->object; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-09-08 02:09:14 +00:00
										 |  |  | 		ob->restore_mode = ob->mode; | 
					
						
							| 
									
										
										
										
											2009-08-16 03:24:23 +00:00
										 |  |  | 		ob->mode &= ~OB_MODE_POSE; | 
					
						
							| 
									
										
										
										
											2009-02-01 19:53:24 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL); | 
					
						
							| 
									
										
										
										
											2009-01-05 19:32:04 +00:00
										 |  |  | 	}	 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* if a selected or active bone is protected, throw error (oonly if warn==1) and return 1 */ | 
					
						
							|  |  |  | /* only_selected==1 : the active bone is allowed to be protected */ | 
					
						
							|  |  |  | static short pose_has_protected_selected(Object *ob, short only_selected, short warn) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* check protection */ | 
					
						
							|  |  |  | 	if (ob->proxy) { | 
					
						
							|  |  |  | 		bPoseChannel *pchan; | 
					
						
							|  |  |  | 		bArmature *arm= ob->data; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 			if (pchan->bone && (pchan->bone->layer & arm->layer)) { | 
					
						
							|  |  |  | 				if (pchan->bone->layer & arm->layer_protected) { | 
					
						
							|  |  |  | 					if (only_selected && (pchan->bone->flag & BONE_ACTIVE)); | 
					
						
							|  |  |  | 					else if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED))  | 
					
						
							|  |  |  | 					   break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (pchan) { | 
					
						
							|  |  |  | 			if (warn) error("Cannot change Proxy protected bones"); | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* only for real IK, not for auto-IK */ | 
					
						
							| 
									
										
										
										
											2009-01-05 19:32:04 +00:00
										 |  |  | int ED_pose_channel_in_IK_chain(Object *ob, bPoseChannel *pchan) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	bConstraint *con; | 
					
						
							|  |  |  | 	Bone *bone; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* No need to check if constraint is active (has influence),
 | 
					
						
							|  |  |  | 	 * since all constraints with CONSTRAINT_IK_AUTO are active */ | 
					
						
							|  |  |  | 	for(con= pchan->constraints.first; con; con= con->next) { | 
					
						
							|  |  |  | 		if(con->type==CONSTRAINT_TYPE_KINEMATIC) { | 
					
						
							|  |  |  | 			bKinematicConstraint *data= con->data; | 
					
						
							|  |  |  | 			if((data->flag & CONSTRAINT_IK_AUTO)==0) | 
					
						
							|  |  |  | 				return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for(bone= pchan->bone->childbase.first; bone; bone= bone->next) { | 
					
						
							|  |  |  | 		pchan= get_pose_channel(ob->pose, bone->name); | 
					
						
							| 
									
										
										
										
											2009-01-05 19:32:04 +00:00
										 |  |  | 		if(pchan && ED_pose_channel_in_IK_chain(ob, pchan)) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 			return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ********************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | /* For the object with pose/action: update paths for those that have got them
 | 
					
						
							|  |  |  |  * This should selectively update paths that exist... | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * To be called from various tools that do incremental updates  | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	bArmature *arm; | 
					
						
							|  |  |  | 	bPoseChannel *pchan; | 
					
						
							|  |  |  | 	Base *base; | 
					
						
							|  |  |  | 	float *fp; | 
					
						
							|  |  |  | 	int cfra; | 
					
						
							|  |  |  | 	int sfra, efra; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	/* sanity checks */ | 
					
						
							|  |  |  | 	if ELEM(NULL, ob, ob->pose) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	arm= ob->data; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* set frame values */ | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	cfra = CFRA; | 
					
						
							|  |  |  | 	sfra = efra = cfra;  | 
					
						
							|  |  |  | 	for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		if ((pchan->bone) && (arm->layer & pchan->bone->layer)) { | 
					
						
							|  |  |  | 			if (pchan->path) { | 
					
						
							|  |  |  | 				/* if the pathsf and pathef aren't initialised, abort! */ | 
					
						
							|  |  |  | 				if (ELEM(0, pchan->pathsf, pchan->pathef))	 | 
					
						
							|  |  |  | 					return; | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				/* try to increase area to do (only as much as needed) */ | 
					
						
							|  |  |  | 				sfra= MIN2(sfra, pchan->pathsf); | 
					
						
							|  |  |  | 				efra= MAX2(efra, pchan->pathef); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	if (efra <= sfra) return; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* hack: for unsaved files, set OB_RECALC so that paths can get calculated */ | 
					
						
							|  |  |  | 	if ((ob->recalc & OB_RECALC)==0) { | 
					
						
							|  |  |  | 		ob->recalc |= OB_RECALC; | 
					
						
							| 
									
										
										
										
											2009-01-10 14:19:14 +00:00
										 |  |  | 		ED_anim_object_flush_update(C, ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2009-01-10 14:19:14 +00:00
										 |  |  | 		ED_anim_object_flush_update(C, ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	/* calculate path over requested range */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	for (CFRA=sfra; CFRA<=efra; CFRA++) { | 
					
						
							|  |  |  | 		/* do all updates */ | 
					
						
							|  |  |  | 		for (base= FIRSTBASE; base; base= base->next) { | 
					
						
							|  |  |  | 			if (base->object->recalc) { | 
					
						
							|  |  |  | 				int temp= base->object->recalc; | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 				 | 
					
						
							|  |  |  | 				if (base->object->adt) | 
					
						
							|  |  |  | 					BKE_animsys_evaluate_animdata(&base->object->id, base->object->adt, (float)CFRA, ADT_RECALC_ALL); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				/* update object */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				object_handle_update(scene, base->object); | 
					
						
							|  |  |  | 				base->object->recalc= temp; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 			if ((pchan->bone) && (arm->layer & pchan->bone->layer)) { | 
					
						
							|  |  |  | 				if (pchan->path) { | 
					
						
							|  |  |  | 					/* only update if:
 | 
					
						
							|  |  |  | 					 *	- in range of this pchan's existing path | 
					
						
							|  |  |  | 					 *	- ... insert evil filtering/optimising conditions here... | 
					
						
							|  |  |  | 					 */ | 
					
						
							|  |  |  | 					if (IN_RANGE(CFRA, pchan->pathsf, pchan->pathef)) { | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 						fp= pchan->path+3*(CFRA-sfra); | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						if (arm->pathflag & ARM_PATH_HEADS) {  | 
					
						
							|  |  |  | 							VECCOPY(fp, pchan->pose_head); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						else { | 
					
						
							|  |  |  | 							VECCOPY(fp, pchan->pose_tail); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						Mat4MulVecfl(ob->obmat, fp); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	/* reset flags */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	CFRA= cfra; | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	ob->pose->flag &= ~POSE_RECALCPATHS; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flush one final time - to restore to the original state */ | 
					
						
							|  |  |  | 	for (base= FIRSTBASE; base; base= base->next) { | 
					
						
							|  |  |  | 		if (base->object->recalc) { | 
					
						
							|  |  |  | 			int temp= base->object->recalc; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			if (base->object->adt) | 
					
						
							|  |  |  | 				BKE_animsys_evaluate_animdata(&base->object->id, base->object->adt, (float)CFRA, ADT_RECALC_ALL); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			object_handle_update(scene, base->object); | 
					
						
							|  |  |  | 			base->object->recalc= temp; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | /* --------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* For the object with pose/action: create path curves for selected bones 
 | 
					
						
							|  |  |  |  * This recalculates the WHOLE path within the pchan->pathsf and pchan->pathef range | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | static int pose_calculate_paths_exec (bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	wmWindow *win= CTX_wm_window(C); | 
					
						
							|  |  |  | 	ScrArea *sa= CTX_wm_area(C); | 
					
						
							|  |  |  | 	Scene *scene= CTX_data_scene(C); | 
					
						
							|  |  |  | 	Object *ob; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	bArmature *arm; | 
					
						
							|  |  |  | 	bPoseChannel *pchan; | 
					
						
							|  |  |  | 	Base *base; | 
					
						
							|  |  |  | 	float *fp; | 
					
						
							|  |  |  | 	int cfra; | 
					
						
							|  |  |  | 	int sfra, efra; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	/* since this call may also be used from the buttons window, we need to check for where to get the object */ | 
					
						
							|  |  |  | 	if (sa->spacetype == SPACE_BUTS)  | 
					
						
							|  |  |  | 		ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	/* only continue if there's an object */ | 
					
						
							|  |  |  | 	if ELEM(NULL, ob, ob->pose) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	arm= ob->data; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	/* version patch for older files here (do_versions patch too complicated) */ | 
					
						
							|  |  |  | 	if ((arm->pathsf == 0) || (arm->pathef == 0)) { | 
					
						
							|  |  |  | 		arm->pathsf = SFRA; | 
					
						
							|  |  |  | 		arm->pathef = EFRA; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (arm->pathsize == 0) { | 
					
						
							|  |  |  | 		arm->pathsize = 1; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	/* get frame values to use */ | 
					
						
							|  |  |  | 	cfra= CFRA; | 
					
						
							|  |  |  | 	sfra = arm->pathsf; | 
					
						
							|  |  |  | 	efra = arm->pathef; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (efra <= sfra) { | 
					
						
							|  |  |  | 		BKE_report(op->reports, RPT_ERROR, "Can't calculate paths when pathlen <= 0"); | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* hack: for unsaved files, set OB_RECALC so that paths can get calculated */ | 
					
						
							|  |  |  | 	if ((ob->recalc & OB_RECALC)==0) { | 
					
						
							|  |  |  | 		ob->recalc |= OB_RECALC; | 
					
						
							| 
									
										
										
										
											2009-01-10 14:19:14 +00:00
										 |  |  | 		ED_anim_object_flush_update(C, ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2009-01-10 14:19:14 +00:00
										 |  |  | 		ED_anim_object_flush_update(C, ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	/* alloc the path cache arrays */ | 
					
						
							|  |  |  | 	for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		if ((pchan->bone) && (pchan->bone->flag & BONE_SELECTED)) { | 
					
						
							|  |  |  | 			if (arm->layer & pchan->bone->layer) { | 
					
						
							|  |  |  | 				pchan->pathlen= efra-sfra+1; | 
					
						
							|  |  |  | 				pchan->pathsf= sfra; | 
					
						
							|  |  |  | 				pchan->pathef= efra+1; | 
					
						
							|  |  |  | 				if (pchan->path) | 
					
						
							|  |  |  | 					MEM_freeN(pchan->path); | 
					
						
							|  |  |  | 				pchan->path= MEM_callocN(3*pchan->pathlen*sizeof(float), "pchan path"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* step through frame range sampling the values */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	for (CFRA=sfra; CFRA<=efra; CFRA++) { | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 		/* for each frame we calculate, update time-cursor... (may be too slow) */ | 
					
						
							|  |  |  | 		WM_timecursor(win, CFRA); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		/* do all updates */ | 
					
						
							|  |  |  | 		for (base= FIRSTBASE; base; base= base->next) { | 
					
						
							|  |  |  | 			if (base->object->recalc) { | 
					
						
							|  |  |  | 				int temp= base->object->recalc; | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 				 | 
					
						
							|  |  |  | 				if (base->object->adt) | 
					
						
							|  |  |  | 					BKE_animsys_evaluate_animdata(&base->object->id, base->object->adt, (float)CFRA, ADT_RECALC_ALL); | 
					
						
							|  |  |  | 				 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				object_handle_update(scene, base->object); | 
					
						
							|  |  |  | 				base->object->recalc= temp; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 			if ((pchan->bone) && (pchan->bone->flag & BONE_SELECTED)) { | 
					
						
							|  |  |  | 				if (arm->layer & pchan->bone->layer) { | 
					
						
							|  |  |  | 					if (pchan->path) { | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 						fp= pchan->path+3*(CFRA-sfra); | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						if (arm->pathflag & ARM_PATH_HEADS) {  | 
					
						
							|  |  |  | 							VECCOPY(fp, pchan->pose_head); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						else { | 
					
						
							|  |  |  | 							VECCOPY(fp, pchan->pose_tail); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						Mat4MulVecfl(ob->obmat, fp); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	/* restore original cursor */ | 
					
						
							|  |  |  | 	WM_cursor_restore(win); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	/* reset current frame, and clear flags */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	CFRA= cfra; | 
					
						
							|  |  |  | 	ob->pose->flag &= ~POSE_RECALCPATHS; | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flush one final time - to restore to the original state */ | 
					
						
							|  |  |  | 	for (base= FIRSTBASE; base; base= base->next) { | 
					
						
							|  |  |  | 		if (base->object->recalc) { | 
					
						
							|  |  |  | 			int temp= base->object->recalc; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			if (base->object->adt) | 
					
						
							|  |  |  | 				BKE_animsys_evaluate_animdata(&base->object->id, base->object->adt, (float)CFRA, ADT_RECALC_ALL); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			object_handle_update(scene, base->object); | 
					
						
							|  |  |  | 			base->object->recalc= temp; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* notifiers for updates */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED;  | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | void POSE_OT_paths_calculate (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Calculate Bone Paths"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_paths_calculate"; | 
					
						
							|  |  |  | 	ot->description= "Calculate paths for the selected bones."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec= pose_calculate_paths_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* --------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | /* for the object with pose/action: clear path curves for selected bones only */ | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | void ED_pose_clear_paths(Object *ob) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	bPoseChannel *pchan; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	if ELEM(NULL, ob, ob->pose) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* free the path blocks */ | 
					
						
							|  |  |  | 	for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		if ((pchan->bone) && (pchan->bone->flag & BONE_SELECTED)) { | 
					
						
							|  |  |  | 			if (pchan->path) { | 
					
						
							|  |  |  | 				MEM_freeN(pchan->path); | 
					
						
							|  |  |  | 				pchan->path= NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* operator callback for this */ | 
					
						
							|  |  |  | static int pose_clear_paths_exec (bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ScrArea *sa= CTX_wm_area(C); | 
					
						
							|  |  |  | 	Object *ob; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* since this call may also be used from the buttons window, we need to check for where to get the object */ | 
					
						
							|  |  |  | 	if (sa->spacetype == SPACE_BUTS)  | 
					
						
							|  |  |  | 		ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	/* only continue if there's an object */ | 
					
						
							|  |  |  | 	if ELEM(NULL, ob, ob->pose) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* for now, just call the API function for this (which is shared with backend functions) */ | 
					
						
							|  |  |  | 	ED_pose_clear_paths(ob); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* notifiers for updates */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED;  | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void POSE_OT_paths_clear (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Clear Bone Paths"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_paths_clear"; | 
					
						
							|  |  |  | 	ot->description= "Clear path caches for selected bones."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec= pose_clear_paths_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-24 12:27:42 +00:00
										 |  |  | /* ******************* Select Constraint Target Operator ************* */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | // XXX this function is to be removed when the other stuff is recoded
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | void pose_select_constraint_target(Scene *scene) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit= scene->obedit; // XXX context
 | 
					
						
							|  |  |  | 	Object *ob= OBACT; | 
					
						
							|  |  |  | 	bArmature *arm= ob->data; | 
					
						
							|  |  |  | 	bPoseChannel *pchan; | 
					
						
							|  |  |  | 	bConstraint *con; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* paranoia checks */ | 
					
						
							|  |  |  | 	if (!ob && !ob->pose) return; | 
					
						
							| 
									
										
										
										
											2009-08-16 03:24:23 +00:00
										 |  |  | 	if (ob==obedit || (ob->mode & OB_MODE_POSE)==0) return; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		if (arm->layer & pchan->bone->layer) { | 
					
						
							|  |  |  | 			if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) { | 
					
						
							|  |  |  | 				for (con= pchan->constraints.first; con; con= con->next) { | 
					
						
							|  |  |  | 					bConstraintTypeInfo *cti= constraint_get_typeinfo(con); | 
					
						
							|  |  |  | 					ListBase targets = {NULL, NULL}; | 
					
						
							|  |  |  | 					bConstraintTarget *ct; | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					if (cti && cti->get_constraint_targets) { | 
					
						
							|  |  |  | 						cti->get_constraint_targets(con, &targets); | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						for (ct= targets.first; ct; ct= ct->next) { | 
					
						
							|  |  |  | 							if ((ct->tar == ob) && (ct->subtarget[0])) { | 
					
						
							|  |  |  | 								bPoseChannel *pchanc= get_pose_channel(ob->pose, ct->subtarget); | 
					
						
							|  |  |  | 								if(pchanc) | 
					
						
							|  |  |  | 									pchanc->bone->flag |= BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						if (cti->flush_constraint_targets) | 
					
						
							|  |  |  | 							cti->flush_constraint_targets(con, &targets, 1); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	BIF_undo_push("Select constraint target"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-08 15:34:41 +00:00
										 |  |  | static int pose_select_constraint_target_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	bArmature *arm= ob->data; | 
					
						
							|  |  |  | 	bPoseChannel *pchan; | 
					
						
							|  |  |  | 	bConstraint *con; | 
					
						
							|  |  |  | 	int found= 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		if (arm->layer & pchan->bone->layer) { | 
					
						
							|  |  |  | 			if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) { | 
					
						
							|  |  |  | 				for (con= pchan->constraints.first; con; con= con->next) { | 
					
						
							|  |  |  | 					bConstraintTypeInfo *cti= constraint_get_typeinfo(con); | 
					
						
							|  |  |  | 					ListBase targets = {NULL, NULL}; | 
					
						
							|  |  |  | 					bConstraintTarget *ct; | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					if (cti && cti->get_constraint_targets) { | 
					
						
							|  |  |  | 						cti->get_constraint_targets(con, &targets); | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						for (ct= targets.first; ct; ct= ct->next) { | 
					
						
							|  |  |  | 							if ((ct->tar == ob) && (ct->subtarget[0])) { | 
					
						
							|  |  |  | 								bPoseChannel *pchanc= get_pose_channel(ob->pose, ct->subtarget); | 
					
						
							|  |  |  | 								if(pchanc) { | 
					
						
							|  |  |  | 									pchanc->bone->flag |= BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL; | 
					
						
							|  |  |  | 									found= 1; | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						if (cti->flush_constraint_targets) | 
					
						
							|  |  |  | 							cti->flush_constraint_targets(con, &targets, 1); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(!found) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, ob); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void POSE_OT_select_constraint_target(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Select Constraint Target"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_select_constraint_target"; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec= pose_select_constraint_target_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-16 17:18:24 +00:00
										 |  |  | /* ******************* select hierarchy operator ************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int pose_select_hierarchy_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-02-16 17:18:24 +00:00
										 |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	bArmature *arm= ob->data; | 
					
						
							|  |  |  | 	bPoseChannel *pchan; | 
					
						
							|  |  |  | 	Bone *curbone, *pabone, *chbone; | 
					
						
							| 
									
										
										
										
											2009-02-16 17:18:24 +00:00
										 |  |  | 	int direction = RNA_enum_get(op->ptr, "direction"); | 
					
						
							| 
									
										
										
										
											2009-03-29 04:34:20 +00:00
										 |  |  | 	int add_to_sel = RNA_boolean_get(op->ptr, "extend"); | 
					
						
							| 
									
										
										
										
											2009-07-08 15:34:41 +00:00
										 |  |  | 	int found= 0; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		curbone= pchan->bone; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (arm->layer & curbone->layer) { | 
					
						
							|  |  |  | 			if (curbone->flag & (BONE_ACTIVE)) { | 
					
						
							|  |  |  | 				if (direction == BONE_SELECT_PARENT) { | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 					if (pchan->parent == NULL) continue; | 
					
						
							|  |  |  | 					else pabone= pchan->parent->bone; | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					if ((arm->layer & pabone->layer) && !(pabone->flag & BONE_HIDDEN_P)) { | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						if (!add_to_sel) curbone->flag &= ~BONE_SELECTED; | 
					
						
							|  |  |  | 						curbone->flag &= ~BONE_ACTIVE; | 
					
						
							|  |  |  | 						pabone->flag |= (BONE_ACTIVE|BONE_SELECTED); | 
					
						
							| 
									
										
										
										
											2009-07-08 15:34:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						found= 1; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else { // BONE_SELECT_CHILD
 | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 					if (pchan->child == NULL) continue; | 
					
						
							|  |  |  | 					else chbone = pchan->child->bone; | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					if ((arm->layer & chbone->layer) && !(chbone->flag & BONE_HIDDEN_P)) { | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 						if (!add_to_sel) curbone->flag &= ~BONE_SELECTED; | 
					
						
							|  |  |  | 						curbone->flag &= ~BONE_ACTIVE; | 
					
						
							|  |  |  | 						chbone->flag |= (BONE_ACTIVE|BONE_SELECTED); | 
					
						
							| 
									
										
										
										
											2009-07-08 15:34:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						found= 1; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-02-16 17:18:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-08 15:34:41 +00:00
										 |  |  | 	if(!found) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-16 17:18:24 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, ob); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void POSE_OT_select_hierarchy(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static EnumPropertyItem direction_items[]= { | 
					
						
							| 
									
										
										
										
											2009-06-16 00:52:21 +00:00
										 |  |  | 	{BONE_SELECT_PARENT, "PARENT", 0, "Select Parent", ""}, | 
					
						
							|  |  |  | 	{BONE_SELECT_CHILD, "CHILD", 0, "Select Child", ""}, | 
					
						
							|  |  |  | 	{0, NULL, 0, NULL, NULL} | 
					
						
							| 
									
										
										
										
											2009-02-16 17:18:24 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Select Hierarchy"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_select_hierarchy"; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec= pose_select_hierarchy_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_enum(ot->srna, "direction", direction_items, | 
					
						
							|  |  |  | 				 BONE_SELECT_PARENT, "Direction", ""); | 
					
						
							| 
									
										
										
										
											2009-03-29 04:34:20 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "extend", 0, "Add to Selection", ""); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void pose_copy_menu(Scene *scene) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit= scene->obedit; // XXX context
 | 
					
						
							|  |  |  | 	Object *ob= OBACT; | 
					
						
							|  |  |  | 	bArmature *arm= ob->data; | 
					
						
							|  |  |  | 	bPoseChannel *pchan, *pchanact; | 
					
						
							|  |  |  | 	short nr=0; | 
					
						
							|  |  |  | 	int i=0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* paranoia checks */ | 
					
						
							|  |  |  | 	if (ELEM(NULL, ob, ob->pose)) return; | 
					
						
							| 
									
										
										
										
											2009-08-16 03:24:23 +00:00
										 |  |  | 	if ((ob==obedit) || (ob->mode & OB_MODE_POSE)==0) return; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* find active */ | 
					
						
							|  |  |  | 	for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		if (pchan->bone->flag & BONE_ACTIVE)  | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (pchan==NULL) return; | 
					
						
							|  |  |  | 	pchanact= pchan; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* if proxy-protected bones selected, some things (such as locks + displays) shouldn't be changable, 
 | 
					
						
							|  |  |  | 	 * but for constraints (just add local constraints) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (pose_has_protected_selected(ob, 1, 0)) { | 
					
						
							|  |  |  | 		i= BLI_countlist(&(pchanact->constraints)); /* if there are 24 or less, allow for the user to select constraints */ | 
					
						
							|  |  |  | 		if (i < 25) | 
					
						
							|  |  |  | 			nr= pupmenu("Copy Pose Attributes %t|Local Location%x1|Local Rotation%x2|Local Size%x3|%l|Visual Location %x9|Visual Rotation%x10|Visual Size%x11|%l|Constraints (All)%x4|Constraints...%x5"); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			nr= pupmenu("Copy Pose Attributes %t|Local Location%x1|Local Rotation%x2|Local Size%x3|%l|Visual Location %x9|Visual Rotation%x10|Visual Size%x11|%l|Constraints (All)%x4"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		i= BLI_countlist(&(pchanact->constraints)); /* if there are 24 or less, allow for the user to select constraints */ | 
					
						
							|  |  |  | 		if (i < 25) | 
					
						
							|  |  |  | 			nr= pupmenu("Copy Pose Attributes %t|Local Location%x1|Local Rotation%x2|Local Size%x3|%l|Visual Location %x9|Visual Rotation%x10|Visual Size%x11|%l|Constraints (All)%x4|Constraints...%x5|%l|Transform Locks%x6|IK Limits%x7|Bone Shape%x8"); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			nr= pupmenu("Copy Pose Attributes %t|Local Location%x1|Local Rotation%x2|Local Size%x3|%l|Visual Location %x9|Visual Rotation%x10|Visual Size%x11|%l|Constraints (All)%x4|%l|Transform Locks%x6|IK Limits%x7|Bone Shape%x8"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (nr <= 0)  | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (nr != 5)  { | 
					
						
							|  |  |  | 		for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 			if ( (arm->layer & pchan->bone->layer) && | 
					
						
							|  |  |  | 				 (pchan->bone->flag & BONE_SELECTED) && | 
					
						
							|  |  |  | 				 (pchan != pchanact) )  | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				switch (nr) { | 
					
						
							|  |  |  | 					case 1: /* Local Location */ | 
					
						
							|  |  |  | 						VECCOPY(pchan->loc, pchanact->loc); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 2: /* Local Rotation */ | 
					
						
							|  |  |  | 						QUATCOPY(pchan->quat, pchanact->quat); | 
					
						
							| 
									
										
										
										
											2009-09-02 00:42:12 +00:00
										 |  |  | 						VECCOPY(pchan->eul, pchanact->eul); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					case 3: /* Local Size */ | 
					
						
							|  |  |  | 						VECCOPY(pchan->size, pchanact->size); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 4: /* All Constraints */ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						ListBase tmp_constraints = {NULL, NULL}; | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						/* copy constraints to tmpbase and apply 'local' tags before 
 | 
					
						
							|  |  |  | 						 * appending to list of constraints for this channel | 
					
						
							|  |  |  | 						 */ | 
					
						
							|  |  |  | 						copy_constraints(&tmp_constraints, &pchanact->constraints); | 
					
						
							|  |  |  | 						if ((ob->proxy) && (pchan->bone->layer & arm->layer_protected)) { | 
					
						
							|  |  |  | 							bConstraint *con; | 
					
						
							|  |  |  | 							 | 
					
						
							|  |  |  | 							/* add proxy-local tags */ | 
					
						
							|  |  |  | 							for (con= tmp_constraints.first; con; con= con->next) | 
					
						
							|  |  |  | 								con->flag |= CONSTRAINT_PROXY_LOCAL; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						addlisttolist(&pchan->constraints, &tmp_constraints); | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						/* update flags (need to add here, not just copy) */ | 
					
						
							|  |  |  | 						pchan->constflag |= pchanact->constflag; | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						if (ob->pose) | 
					
						
							|  |  |  | 							ob->pose->flag |= POSE_RECALC; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 6: /* Transform Locks */ | 
					
						
							|  |  |  | 						pchan->protectflag = pchanact->protectflag; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 7: /* IK (DOF) settings */ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						pchan->ikflag = pchanact->ikflag; | 
					
						
							|  |  |  | 						VECCOPY(pchan->limitmin, pchanact->limitmin); | 
					
						
							|  |  |  | 						VECCOPY(pchan->limitmax, pchanact->limitmax); | 
					
						
							|  |  |  | 						VECCOPY(pchan->stiffness, pchanact->stiffness); | 
					
						
							|  |  |  | 						pchan->ikstretch= pchanact->ikstretch; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 8: /* Custom Bone Shape */ | 
					
						
							|  |  |  | 						pchan->custom = pchanact->custom; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 9: /* Visual Location */ | 
					
						
							|  |  |  | 						armature_loc_pose_to_bone(pchan, pchanact->pose_mat[3], pchan->loc); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 10: /* Visual Rotation */ | 
					
						
							|  |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2009-09-02 00:42:12 +00:00
										 |  |  | 						float delta_mat[4][4]; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 						 | 
					
						
							|  |  |  | 						armature_mat_pose_to_bone(pchan, pchanact->pose_mat, delta_mat); | 
					
						
							| 
									
										
										
										
											2009-09-02 00:42:12 +00:00
										 |  |  | 						 | 
					
						
							| 
									
										
										
										
											2009-09-11 12:44:09 +00:00
										 |  |  | 						if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { | 
					
						
							|  |  |  | 							float tmp_quat[4]; | 
					
						
							|  |  |  | 							 | 
					
						
							|  |  |  | 							/* need to convert to quat first (in temp var)... */ | 
					
						
							|  |  |  | 							Mat4ToQuat(delta_mat, tmp_quat); | 
					
						
							|  |  |  | 							QuatToAxisAngle(tmp_quat, &pchan->quat[1], &pchan->quat[0]); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						else if (pchan->rotmode == PCHAN_ROT_QUAT) | 
					
						
							| 
									
										
										
										
											2009-09-02 00:42:12 +00:00
										 |  |  | 							Mat4ToQuat(delta_mat, pchan->quat); | 
					
						
							| 
									
										
										
										
											2009-09-11 12:44:09 +00:00
										 |  |  | 						else | 
					
						
							|  |  |  | 							Mat4ToEulO(delta_mat, pchan->eul, pchan->rotmode); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 11: /* Visual Size */ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						float delta_mat[4][4], size[4]; | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						armature_mat_pose_to_bone(pchan, pchanact->pose_mat, delta_mat); | 
					
						
							|  |  |  | 						Mat4ToSize(delta_mat, size); | 
					
						
							|  |  |  | 						VECCOPY(pchan->size, size); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}  | 
					
						
							|  |  |  | 	else { /* constraints, optional (note: max we can have is 24 constraints) */ | 
					
						
							|  |  |  | 		bConstraint *con, *con_back; | 
					
						
							|  |  |  | 		int const_toggle[24]; | 
					
						
							|  |  |  | 		ListBase const_copy = {NULL, NULL}; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		BLI_duplicatelist(&const_copy, &(pchanact->constraints)); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* build the puplist of constraints */ | 
					
						
							|  |  |  | 		for (con = pchanact->constraints.first, i=0; con; con=con->next, i++){ | 
					
						
							|  |  |  | 			const_toggle[i]= 1; | 
					
						
							|  |  |  | //			add_numbut(i, TOG|INT, con->name, 0, 0, &(const_toggle[i]), "");
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | //		if (!do_clever_numbuts("Select Constraints", i, REDRAW)) {
 | 
					
						
							|  |  |  | //			BLI_freelistN(&const_copy);
 | 
					
						
							|  |  |  | //			return;
 | 
					
						
							|  |  |  | //		}
 | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* now build a new listbase from the options selected */ | 
					
						
							|  |  |  | 		for (i=0, con=const_copy.first; con; i++) { | 
					
						
							|  |  |  | 			/* if not selected, free/remove it from the list */ | 
					
						
							|  |  |  | 			if (!const_toggle[i]) { | 
					
						
							|  |  |  | 				con_back= con->next; | 
					
						
							|  |  |  | 				BLI_freelinkN(&const_copy, con); | 
					
						
							|  |  |  | 				con= con_back; | 
					
						
							|  |  |  | 			}  | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				con= con->next; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* Copy the temo listbase to the selected posebones */ | 
					
						
							|  |  |  | 		for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 			if ( (arm->layer & pchan->bone->layer) && | 
					
						
							|  |  |  | 				 (pchan->bone->flag & BONE_SELECTED) && | 
					
						
							|  |  |  | 				 (pchan!=pchanact) )  | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				ListBase tmp_constraints = {NULL, NULL}; | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				/* copy constraints to tmpbase and apply 'local' tags before 
 | 
					
						
							|  |  |  | 				 * appending to list of constraints for this channel | 
					
						
							|  |  |  | 				 */ | 
					
						
							|  |  |  | 				copy_constraints(&tmp_constraints, &const_copy); | 
					
						
							|  |  |  | 				if ((ob->proxy) && (pchan->bone->layer & arm->layer_protected)) { | 
					
						
							|  |  |  | 					bConstraint *con; | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					/* add proxy-local tags */ | 
					
						
							|  |  |  | 					for (con= tmp_constraints.first; con; con= con->next) | 
					
						
							|  |  |  | 						con->flag |= CONSTRAINT_PROXY_LOCAL; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				addlisttolist(&pchan->constraints, &tmp_constraints); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				/* update flags (need to add here, not just copy) */ | 
					
						
							|  |  |  | 				pchan->constflag |= pchanact->constflag; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		BLI_freelistN(&const_copy); | 
					
						
							|  |  |  | 		update_pose_constraint_flags(ob->pose); /* we could work out the flags but its simpler to do this */ | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (ob->pose) | 
					
						
							|  |  |  | 			ob->pose->flag |= POSE_RECALC; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
											  
											
												2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
  NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
  notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
  should only be used for notifying about changes in space data,
  we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
											
										 
											2009-09-04 20:51:09 +00:00
										 |  |  | 	DAG_id_flush_update(&ob->id, OB_RECALC_DATA);	// and all its relations
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	BIF_undo_push("Copy Pose Attributes"); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ******************** copy/paste pose ********************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | /* Global copy/paste buffer for pose - cleared on start/end session + before every copy operation */ | 
					
						
							|  |  |  | static bPose *g_posebuf = NULL; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void free_posebuf(void)  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (g_posebuf) { | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 		/* was copied without constraints */ | 
					
						
							|  |  |  | 		BLI_freelistN(&g_posebuf->chanbase); | 
					
						
							|  |  |  | 		MEM_freeN(g_posebuf); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	g_posebuf=NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | /* ---- */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | static int pose_copy_exec (bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* sanity checking */ | 
					
						
							|  |  |  | 	if ELEM(NULL, ob, ob->pose) { | 
					
						
							|  |  |  | 		BKE_report(op->reports, RPT_ERROR, "No Pose to Copy"); | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 	/* free existing pose buffer */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	free_posebuf(); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 	/* sets chan->flag to POSE_KEY if bone selected, then copy those bones to the buffer */ | 
					
						
							|  |  |  | 	set_pose_keys(ob);   | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	copy_pose(&g_posebuf, ob->pose, 0); | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | void POSE_OT_copy (wmOperatorType *ot)  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Copy Pose"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_copy"; | 
					
						
							|  |  |  | 	ot->description= "Copies the current pose of the selected bones to copy/paste buffer."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec= pose_copy_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flag */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | /* ---- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int pose_paste_exec (bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 	Scene *scene= CTX_data_scene(C); | 
					
						
							|  |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	bPoseChannel *chan, *pchan; | 
					
						
							|  |  |  | 	char name[32]; | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 	int flip= RNA_boolean_get(op->ptr, "flipped"); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 	/* sanity checks */ | 
					
						
							|  |  |  | 	if ELEM(NULL, ob, ob->pose) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 	if (g_posebuf == NULL) { | 
					
						
							|  |  |  | 		BKE_report(op->reports, RPT_ERROR, "Copy buffer is empty"); | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 	/* Safely merge all of the channels in the buffer pose into any existing pose */ | 
					
						
							|  |  |  | 	for (chan= g_posebuf->chanbase.first; chan; chan=chan->next) { | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		if (chan->flag & POSE_KEY) { | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 			/* get the name - if flipping, we must flip this first */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 			BLI_strncpy(name, chan->name, sizeof(name)); | 
					
						
							|  |  |  | 			if (flip) | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 				bone_flip_name(name, 0);		/* 0 = don't strip off number extensions */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				 | 
					
						
							|  |  |  | 			/* only copy when channel exists, poses are not meant to add random channels to anymore */ | 
					
						
							|  |  |  | 			pchan= get_pose_channel(ob->pose, name); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			if (pchan) { | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 				/* only loc rot size 
 | 
					
						
							|  |  |  | 				 *	- only copies transform info for the pose  | 
					
						
							|  |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				VECCOPY(pchan->loc, chan->loc); | 
					
						
							|  |  |  | 				VECCOPY(pchan->size, chan->size); | 
					
						
							|  |  |  | 				pchan->flag= chan->flag; | 
					
						
							|  |  |  | 				 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 				/* check if rotation modes are compatible (i.e. do they need any conversions) */ | 
					
						
							|  |  |  | 				if (pchan->rotmode == chan->rotmode) { | 
					
						
							|  |  |  | 					/* copy the type of rotation in use */ | 
					
						
							| 
									
										
										
										
											2009-09-02 00:42:12 +00:00
										 |  |  | 					if (pchan->rotmode > 0) { | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 						VECCOPY(pchan->eul, chan->eul); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					else { | 
					
						
							|  |  |  | 						QUATCOPY(pchan->quat, chan->quat); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-09-02 00:42:12 +00:00
										 |  |  | 				else if (pchan->rotmode > 0) { | 
					
						
							| 
									
										
										
										
											2009-09-12 05:06:28 +00:00
										 |  |  | 					/* quat/axis-angle to euler */ | 
					
						
							|  |  |  | 					if (chan->rotmode == PCHAN_ROT_AXISANGLE) | 
					
						
							|  |  |  | 						AxisAngleToEulO(&chan->quat[1], chan->quat[0], pchan->eul, pchan->rotmode); | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 						QuatToEulO(chan->quat, pchan->eul, pchan->rotmode); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { | 
					
						
							|  |  |  | 					/* quat/euler to axis angle */ | 
					
						
							|  |  |  | 					if (chan->rotmode > 0) | 
					
						
							|  |  |  | 						EulOToAxisAngle(chan->eul, chan->rotmode, &pchan->quat[1], &pchan->quat[0]); | 
					
						
							|  |  |  | 					else	 | 
					
						
							|  |  |  | 						QuatToAxisAngle(chan->quat, &pchan->quat[1], &pchan->quat[0]); | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							| 
									
										
										
										
											2009-09-12 05:06:28 +00:00
										 |  |  | 					/* euler/axis-angle to quat */ | 
					
						
							|  |  |  | 					if (chan->rotmode > 0) | 
					
						
							|  |  |  | 						EulOToQuat(chan->eul, chan->rotmode, pchan->quat); | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 						AxisAngleToQuat(pchan->quat, &chan->quat[1], chan->quat[0]); | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				/* paste flipped pose? */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				if (flip) { | 
					
						
							|  |  |  | 					pchan->loc[0]*= -1; | 
					
						
							|  |  |  | 					 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 					/* has to be done as eulers... */ | 
					
						
							| 
									
										
										
										
											2009-09-02 00:42:12 +00:00
										 |  |  | 					if (pchan->rotmode > 0) { | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 						pchan->eul[1] *= -1; | 
					
						
							|  |  |  | 						pchan->eul[2] *= -1; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2009-09-12 05:06:28 +00:00
										 |  |  | 					else if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { | 
					
						
							|  |  |  | 						float eul[3]; | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						AxisAngleToEulO(&pchan->quat[1], pchan->quat[0], eul, EULER_ORDER_DEFAULT); | 
					
						
							|  |  |  | 						eul[1]*= -1; | 
					
						
							|  |  |  | 						eul[2]*= -1; | 
					
						
							|  |  |  | 						EulOToAxisAngle(eul, EULER_ORDER_DEFAULT, &pchan->quat[1], &pchan->quat[0]); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 					else { | 
					
						
							|  |  |  | 						float eul[3]; | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 						QuatToEul(pchan->quat, eul); | 
					
						
							|  |  |  | 						eul[1]*= -1; | 
					
						
							|  |  |  | 						eul[2]*= -1; | 
					
						
							|  |  |  | 						EulToQuat(eul, pchan->quat); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				 | 
					
						
							| 
									
										
											  
											
												2.5: Blender "Animato" - New Animation System 
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action. 
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves. 
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still) 
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
											
										 
											2009-01-17 03:12:50 +00:00
										 |  |  | #if 0 // XXX old animation system
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				if (autokeyframe_cfra_can_key(ob)) { | 
					
						
							|  |  |  | 					ID *id= &ob->id; | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					/* Set keys on pose */ | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 					// TODO: make these use keyingsets....
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 					if (chan->flag & POSE_ROT) { | 
					
						
							|  |  |  | 						insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X, 0); | 
					
						
							|  |  |  | 						insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y, 0); | 
					
						
							|  |  |  | 						insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z, 0); | 
					
						
							|  |  |  | 						insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W, 0); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					if (chan->flag & POSE_SIZE) { | 
					
						
							|  |  |  | 						insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_X, 0); | 
					
						
							|  |  |  | 						insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Y, 0); | 
					
						
							|  |  |  | 						insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Z, 0); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					if (chan->flag & POSE_LOC) { | 
					
						
							|  |  |  | 						insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_X, 0); | 
					
						
							|  |  |  | 						insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y, 0); | 
					
						
							|  |  |  | 						insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z, 0); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					/* clear any unkeyed tags */ | 
					
						
							|  |  |  | 					if (chan->bone) | 
					
						
							|  |  |  | 						chan->bone->flag &= ~BONE_UNKEYED; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					/* add unkeyed tags */ | 
					
						
							|  |  |  | 					if (chan->bone) | 
					
						
							|  |  |  | 						chan->bone->flag |= BONE_UNKEYED; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
											  
											
												2.5: Blender "Animato" - New Animation System 
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action. 
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves. 
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still) 
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
											
										 
											2009-01-17 03:12:50 +00:00
										 |  |  | #endif // XXX old animation system
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Update event for pose and deformation children */ | 
					
						
							| 
									
										
											  
											
												2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
  NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
  notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
  should only be used for notifying about changes in space data,
  we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
											
										 
											2009-09-04 20:51:09 +00:00
										 |  |  | 	DAG_id_flush_update(&ob->id, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-02-16 03:01:56 +00:00
										 |  |  | 	if (IS_AUTOKEY_ON(scene)) { | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | // XXX		remake_action_ipos(ob->action);
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* need to trick depgraph, action is not allowed to execute on pose */ | 
					
						
							|  |  |  | 		where_is_pose(scene, ob); | 
					
						
							|  |  |  | 		ob->recalc= 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* notifiers for updates */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE|ND_TRANSFORM, ob); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 13:12:40 +00:00
										 |  |  | void POSE_OT_paste (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Paste Pose"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_paste"; | 
					
						
							|  |  |  | 	ot->description= "Pastes the stored pose on to the current pose."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec= pose_paste_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flag */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "flipped", 0, "Flipped on X-Axis", ""); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ********************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* context weightpaint and deformer in posemode */ | 
					
						
							|  |  |  | void pose_adds_vgroups(Scene *scene, Object *meshobj, int heatweights) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | // XXX	extern VPaint Gwp;         /* from vpaint */
 | 
					
						
							|  |  |  | 	Object *poseobj= modifiers_isDeformedByArmature(meshobj); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-16 03:24:23 +00:00
										 |  |  | 	if(poseobj==NULL || (poseobj->mode & OB_MODE_POSE)==0) { | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		error("The active object must have a deforming armature in pose mode"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX	add_verts_to_dgroups(meshobj, poseobj, heatweights, (Gwp.flag & VP_MIRROR_X));
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(heatweights) | 
					
						
							|  |  |  | 		BIF_undo_push("Apply Bone Heat Weights to Vertex Groups"); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		BIF_undo_push("Apply Bone Envelopes to Vertex Groups"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// and all its relations
 | 
					
						
							| 
									
										
											  
											
												2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
  NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
  notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
  should only be used for notifying about changes in space data,
  we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
											
										 
											2009-09-04 20:51:09 +00:00
										 |  |  | 	DAG_id_flush_update(&meshobj->id, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ********************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int pose_group_add_exec (bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	ScrArea *sa= CTX_wm_area(C); | 
					
						
							|  |  |  | 	Object *ob; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* since this call may also be used from the buttons window, we need to check for where to get the object */ | 
					
						
							|  |  |  | 	if (sa->spacetype == SPACE_BUTS)  | 
					
						
							|  |  |  | 		ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	/* only continue if there's an object */ | 
					
						
							|  |  |  | 	if (ob == NULL) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* for now, just call the API function for this */ | 
					
						
							|  |  |  | 	pose_add_group(ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* notifiers for updates */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void POSE_OT_group_add (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Add Bone Group"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_group_add"; | 
					
						
							|  |  |  | 	ot->description= "Add a new bone group."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec= pose_group_add_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int pose_group_remove_exec (bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	ScrArea *sa= CTX_wm_area(C); | 
					
						
							|  |  |  | 	Object *ob; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* since this call may also be used from the buttons window, we need to check for where to get the object */ | 
					
						
							|  |  |  | 	if (sa->spacetype == SPACE_BUTS)  | 
					
						
							|  |  |  | 		ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ob= CTX_data_active_object(C); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* only continue if there's an object */ | 
					
						
							|  |  |  | 	if (ob == NULL) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* for now, just call the API function for this */ | 
					
						
							|  |  |  | 	pose_remove_group(ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* notifiers for updates */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | void POSE_OT_group_remove (wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Remove Bone Group"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_group_remove"; | 
					
						
							|  |  |  | 	ot->description= "Removes the active bone group."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec= pose_group_remove_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* invoke callback which presents a list of bone-groups for the user to choose from */ | 
					
						
							|  |  |  | static int pose_groups_menu_invoke (bContext *C, wmOperator *op, wmEvent *evt) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ScrArea *sa= CTX_wm_area(C); | 
					
						
							|  |  |  | 	Object *ob; | 
					
						
							|  |  |  | 	bPose *pose; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	uiPopupMenu *pup; | 
					
						
							|  |  |  | 	uiLayout *layout; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	bActionGroup *grp; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* since this call may also be used from the buttons window, we need to check for where to get the object */ | 
					
						
							|  |  |  | 	if (sa->spacetype == SPACE_BUTS)  | 
					
						
							|  |  |  | 		ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 		ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* only continue if there's an object, and a pose there too */ | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	if (ELEM(NULL, ob, ob->pose))  | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	pose= ob->pose; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* if there's no active group (or active is invalid), create a new menu to find it */ | 
					
						
							|  |  |  | 	if (pose->active_group <= 0) { | 
					
						
							|  |  |  | 		/* create a new menu, and start populating it with group names */ | 
					
						
							|  |  |  | 		pup= uiPupMenuBegin(C, op->type->name, 0); | 
					
						
							|  |  |  | 		layout= uiPupMenuLayout(pup); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 		/* special entry - allow to create new group, then use that 
 | 
					
						
							|  |  |  | 		 *	(not to be used for removing though) | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (strstr(op->idname, "assign")) { | 
					
						
							|  |  |  | 			uiItemIntO(layout, "New Group", 0, op->idname, "type", 0); | 
					
						
							|  |  |  | 			uiItemS(layout); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* add entries for each group */ | 
					
						
							|  |  |  | 		for (grp= pose->agroups.first, i=1; grp; grp=grp->next, i++) | 
					
						
							|  |  |  | 			uiItemIntO(layout, grp->name, 0, op->idname, "type", i); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 		/* finish building the menu, and process it (should result in calling self again) */ | 
					
						
							|  |  |  | 		uiPupMenuEnd(C, pup); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* just use the active group index, and call the exec callback for the calling operator */ | 
					
						
							|  |  |  | 		RNA_int_set(op->ptr, "type", pose->active_group); | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 		return op->type->exec(C, op); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Assign selected pchans to the bone group that the user selects */ | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | static int pose_group_assign_exec (bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	ScrArea *sa= CTX_wm_area(C); | 
					
						
							|  |  |  | 	Object *ob; | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	bArmature *arm; | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	bPose *pose; | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	bPoseChannel *pchan; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	short done= 0; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* since this call may also be used from the buttons window, we need to check for where to get the object */ | 
					
						
							|  |  |  | 	if (sa->spacetype == SPACE_BUTS)  | 
					
						
							|  |  |  | 		ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* only continue if there's an object, and a pose there too */ | 
					
						
							|  |  |  | 	if (ELEM(NULL, ob, ob->pose)) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	arm= ob->data; | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	pose= ob->pose; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	/* set the active group number to the one from operator props 
 | 
					
						
							|  |  |  | 	 * 	- if 0 after this, make a new group... | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	pose->active_group= RNA_int_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	if (pose->active_group == 0) | 
					
						
							|  |  |  | 		pose_add_group(ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* add selected bones to group then */ | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	// NOTE: unfortunately, we cannot use the context-iterators here, since they might not be defined...
 | 
					
						
							|  |  |  | 	// CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) 
 | 
					
						
							|  |  |  | 	for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		/* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */ | 
					
						
							|  |  |  | 		// NOTE: sync this view3d_context() in space_view3d.c
 | 
					
						
							|  |  |  | 		if ((pchan->bone) && (arm->layer & pchan->bone->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) { | 
					
						
							|  |  |  | 			if (pchan->bone->flag & (BONE_SELECTED|BONE_ACTIVE)) { | 
					
						
							|  |  |  | 				pchan->agrp_index= pose->active_group; | 
					
						
							|  |  |  | 				done= 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* notifiers for updates */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* report done status */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	if (done) | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | void POSE_OT_group_assign (wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Add Selected to Bone Group"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_group_assign"; | 
					
						
							|  |  |  | 	ot->description= "Add selected bones to the chosen bone group."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->invoke= pose_groups_menu_invoke; | 
					
						
							|  |  |  | 	ot->exec= pose_group_assign_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "type", 0, 0, 10, "Bone Group Index", "", 0, INT_MAX); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int pose_group_unassign_exec (bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ScrArea *sa= CTX_wm_area(C); | 
					
						
							|  |  |  | 	Object *ob; | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	bArmature *arm; | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	bPose *pose; | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	bPoseChannel *pchan; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	short done= 0; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* since this call may also be used from the buttons window, we need to check for where to get the object */ | 
					
						
							|  |  |  | 	if (sa->spacetype == SPACE_BUTS)  | 
					
						
							|  |  |  | 		ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ob= CTX_data_active_object(C); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* only continue if there's an object, and a pose there too */ | 
					
						
							|  |  |  | 	if (ELEM(NULL, ob, ob->pose)) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	pose= ob->pose; | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	arm= ob->data; | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* add selected bones to ungroup then */ | 
					
						
							| 
									
										
										
										
											2009-07-21 12:38:01 +00:00
										 |  |  | 	// NOTE: unfortunately, we cannot use the context-iterators here, since they might not be defined...
 | 
					
						
							|  |  |  | 	// CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) 
 | 
					
						
							|  |  |  | 	for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		/* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */ | 
					
						
							|  |  |  | 		// NOTE: sync this view3d_context() in space_view3d.c
 | 
					
						
							|  |  |  | 		if ((pchan->bone) && (arm->layer & pchan->bone->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) { | 
					
						
							|  |  |  | 			if (pchan->bone->flag & (BONE_SELECTED|BONE_ACTIVE)) { | 
					
						
							|  |  |  | 				if (pchan->agrp_index) { | 
					
						
							|  |  |  | 					pchan->agrp_index= 0; | 
					
						
							|  |  |  | 					done= 1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* notifiers for updates */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	/* report done status */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	if (done) | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void POSE_OT_group_unassign (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Remove Selected from Bone Groups"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_group_unassign"; | 
					
						
							|  |  |  | 	ot->description= "Add selected bones from all bone groups"; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec= pose_group_unassign_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ----------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int pose_groupOps_menu_invoke (bContext *C, wmOperator *op, wmEvent *evt) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	uiPopupMenu *pup= uiPupMenuBegin(C, op->type->name, 0); | 
					
						
							|  |  |  | 	uiLayout *layout= uiPupMenuLayout(pup); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* sanity check - must have object with pose */ | 
					
						
							|  |  |  | 	if ELEM(NULL, ob, ob->pose) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* get mode of action */ | 
					
						
							|  |  |  | 	if (CTX_DATA_COUNT(C, selected_pchans)) { | 
					
						
							|  |  |  | 		/* if selected bone(s), include options to add/remove to active group */ | 
					
						
							|  |  |  | 		uiItemO(layout, "Add Selected to Active Group", 0, "POSE_OT_group_assign"); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		uiItemS(layout); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		uiItemO(layout, "Remove Selected from All Groups", 0, "POSE_OT_group_unassign"); | 
					
						
							|  |  |  | 		uiItemO(layout, "Remove Active Group", 0, "POSE_OT_group_remove"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* no selected bones - so just options for groups management */ | 
					
						
							|  |  |  | 		uiItemO(layout, "Add New Group", 0, "POSE_OT_group_add"); | 
					
						
							|  |  |  | 		uiItemO(layout, "Remove Active Group", 0, "POSE_OT_group_remove"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-07-21 10:18:08 +00:00
										 |  |  | 	return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void POSE_OT_groups_menu (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Bone Group Tools"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_groups_menu"; | 
					
						
							|  |  |  | 	ot->description= "Menu displaying available tools for Bone Groups."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks (only invoke needed) */ | 
					
						
							|  |  |  | 	ot->invoke= pose_groupOps_menu_invoke; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ********************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static short pose_select_same_group (Object *ob) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bPose *pose= (ob)? ob->pose : NULL; | 
					
						
							|  |  |  | 	bArmature *arm= (ob)? ob->data : NULL; | 
					
						
							|  |  |  | 	bPoseChannel *pchan, *chan; | 
					
						
							|  |  |  | 	short changed= 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (ELEM3(NULL, ob, pose, arm)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* loop in loop... bad and slow! */ | 
					
						
							|  |  |  | 	for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		if (arm->layer & pchan->bone->layer) { | 
					
						
							|  |  |  | 			if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) { | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				/* only if group matches (and is not selected or current bone) */ | 
					
						
							|  |  |  | 				for (chan= ob->pose->chanbase.first; chan; chan= chan->next) { | 
					
						
							|  |  |  | 					if (arm->layer & chan->bone->layer) { | 
					
						
							|  |  |  | 						if (pchan->agrp_index == chan->agrp_index) { | 
					
						
							|  |  |  | 							chan->bone->flag |= BONE_SELECTED; | 
					
						
							|  |  |  | 							changed= 1; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return changed; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static short pose_select_same_layer (Object *ob) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bPose *pose= (ob)? ob->pose : NULL; | 
					
						
							|  |  |  | 	bArmature *arm= (ob)? ob->data : NULL; | 
					
						
							|  |  |  | 	bPoseChannel *pchan; | 
					
						
							|  |  |  | 	short layers= 0, changed= 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (ELEM3(NULL, ob, pose, arm)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* figure out what bones are selected */ | 
					
						
							|  |  |  | 	for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		if (arm->layer & pchan->bone->layer) { | 
					
						
							|  |  |  | 			if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) { | 
					
						
							|  |  |  | 				layers |= pchan->bone->layer; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (layers == 0)  | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	/* select bones that are on same layers as layers flag */ | 
					
						
							|  |  |  | 	for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		if (arm->layer & pchan->bone->layer) { | 
					
						
							|  |  |  | 			if (layers & pchan->bone->layer) { | 
					
						
							|  |  |  | 				pchan->bone->flag |= BONE_SELECTED; | 
					
						
							|  |  |  | 				changed= 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return changed; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void pose_select_grouped (Scene *scene, short nr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	short changed = 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (nr == 1) 		changed= pose_select_same_group(OBACT); | 
					
						
							|  |  |  | 	else if (nr == 2)	changed= pose_select_same_layer(OBACT); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (changed) { | 
					
						
							|  |  |  | 		countall(); | 
					
						
							|  |  |  | 		BIF_undo_push("Select Grouped"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Shift-G in 3D-View while in PoseMode */ | 
					
						
							|  |  |  | void pose_select_grouped_menu (Scene *scene) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	short nr; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* here we go */ | 
					
						
							|  |  |  | 	nr= pupmenu("Select Grouped%t|In Same Group%x1|In Same Layer%x2"); | 
					
						
							|  |  |  | 	pose_select_grouped(scene, nr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ********************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | static int pose_flip_names_exec (bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	bArmature *arm; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	char newname[32]; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* paranoia checks */ | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	if (ELEM(NULL, ob, ob->pose))  | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	arm= ob->data; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	/* loop through selected bones, auto-naming them */ | 
					
						
							|  |  |  | 	CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		BLI_strncpy(newname, pchan->name, sizeof(newname)); | 
					
						
							|  |  |  | 		bone_flip_name(newname, 1);	// 1 = do strip off number extensions
 | 
					
						
							|  |  |  | 		ED_armature_bone_rename(arm, pchan->name, newname); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	CTX_DATA_END; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* since we renamed stuff... */ | 
					
						
							| 
									
										
											  
											
												2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
  NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
  notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
  should only be used for notifying about changes in space data,
  we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
											
										 
											2009-09-04 20:51:09 +00:00
										 |  |  | 	DAG_id_flush_update(&ob->id, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* note, notifier might evolve */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | void POSE_OT_flip_names (wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Flip Names"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_flip_names"; | 
					
						
							|  |  |  | 	ot->description= "Flips (and corrects) the names of selected bones."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec= pose_flip_names_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int pose_autoside_names_exec (bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	bArmature *arm; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	char newname[32]; | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	short axis= RNA_enum_get(op->ptr, "axis"); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* paranoia checks */ | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	if (ELEM(NULL, ob, ob->pose))  | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	arm= ob->data; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	/* loop through selected bones, auto-naming them */ | 
					
						
							|  |  |  | 	CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		BLI_strncpy(newname, pchan->name, sizeof(newname)); | 
					
						
							|  |  |  | 		bone_autoside_name(newname, 1, axis, pchan->bone->head[axis], pchan->bone->tail[axis]); | 
					
						
							|  |  |  | 		ED_armature_bone_rename(arm, pchan->name, newname); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	CTX_DATA_END; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 	/* since we renamed stuff... */ | 
					
						
							| 
									
										
											  
											
												2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
  NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
  notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
  should only be used for notifying about changes in space data,
  we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
											
										 
											2009-09-04 20:51:09 +00:00
										 |  |  | 	DAG_id_flush_update(&ob->id, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* note, notifier might evolve */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void POSE_OT_autoside_names (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static EnumPropertyItem axis_items[]= { | 
					
						
							|  |  |  |  		{0, "XAXIS", 0, "X-Axis", "Left/Right"}, | 
					
						
							|  |  |  | 		{1, "YAXIS", 0, "Y-Axis", "Front/Back"}, | 
					
						
							|  |  |  | 		{2, "ZAXIS", 0, "Z-Axis", "Top/Bottom"}, | 
					
						
							|  |  |  | 		{0, NULL, 0, NULL, NULL}}; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "AutoName by Axis"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_autoside_names"; | 
					
						
							|  |  |  | 	ot->description= "Automatically renames the selected bones according to which side of the target axis they fall on."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->invoke= WM_menu_invoke; | 
					
						
							|  |  |  | 	ot->exec= pose_autoside_names_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* settings */ | 
					
						
							|  |  |  | 	RNA_def_enum(ot->srna, "axis", axis_items, 0, "Axis", "Axis tag names with."); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-24 13:02:16 +00:00
										 |  |  | /* ********************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | /* context active object, or weightpainted object with armature in posemode */ | 
					
						
							|  |  |  | void pose_activate_flipped_bone(Scene *scene) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob= OBACT; | 
					
						
							|  |  |  | 	bArmature *arm= ob->data; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(ob==NULL) return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-15 21:46:25 +00:00
										 |  |  | 	if(ob->mode && OB_MODE_WEIGHT_PAINT) { | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		ob= modifiers_isDeformedByArmature(ob); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-08-16 03:24:23 +00:00
										 |  |  | 	if(ob && (ob->mode & OB_MODE_POSE)) { | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		bPoseChannel *pchan, *pchanf; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 			if(arm->layer & pchan->bone->layer) { | 
					
						
							|  |  |  | 				if(pchan->bone->flag & BONE_ACTIVE) | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(pchan) { | 
					
						
							|  |  |  | 			char name[32]; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			BLI_strncpy(name, pchan->name, 32); | 
					
						
							|  |  |  | 			bone_flip_name(name, 1);	// 0 = do not strip off number extensions
 | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			pchanf= get_pose_channel(ob->pose, name); | 
					
						
							|  |  |  | 			if(pchanf && pchanf!=pchan) { | 
					
						
							|  |  |  | 				pchan->bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE); | 
					
						
							|  |  |  | 				pchanf->bone->flag |= (BONE_SELECTED|BONE_ACTIVE); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 				/* in weightpaint we select the associated vertex group too */ | 
					
						
							| 
									
										
										
										
											2009-08-15 21:46:25 +00:00
										 |  |  | 				if(ob->mode & OB_MODE_WEIGHT_PAINT) { | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | 					ED_vgroup_select_by_name(OBACT, name); | 
					
						
							| 
									
										
											  
											
												2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
  NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
  notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
  should only be used for notifying about changes in space data,
  we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
											
										 
											2009-09-04 20:51:09 +00:00
										 |  |  | 					DAG_id_flush_update(&OBACT->id, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				 | 
					
						
							| 
									
										
										
										
											2009-02-05 03:28:07 +00:00
										 |  |  | 				// XXX notifiers need to be sent to other editors to update
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				 | 
					
						
							|  |  |  | 			}			 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ********************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Present a popup to get the layers that should be used */ | 
					
						
							|  |  |  | // TODO: move to wm?
 | 
					
						
							|  |  |  | static uiBlock *wm_layers_select_create_menu(bContext *C, ARegion *ar, void *arg_op) | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 	wmOperator *op= arg_op; | 
					
						
							|  |  |  | 	uiBlock *block; | 
					
						
							|  |  |  | 	uiLayout *layout; | 
					
						
							|  |  |  | 	uiStyle *style= U.uistyles.first; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 	block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS); | 
					
						
							|  |  |  | 	uiBlockClearFlag(block, UI_BLOCK_LOOP); | 
					
						
							|  |  |  | 	uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 	layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 150, 20, style); | 
					
						
							|  |  |  | 		uiItemL(layout, op->type->name, 0); | 
					
						
							|  |  |  | 		uiTemplateLayers(layout, op->ptr, "layers"); /* must have a property named layers setup */ | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 	uiPopupBoundsBlock(block, 4.0f, 0, 0); | 
					
						
							|  |  |  | 	uiEndBlock(C, block); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return block; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Present a popup to get the layers that should be used */ | 
					
						
							|  |  |  | static int pose_armature_layers_invoke (bContext *C, wmOperator *op, wmEvent *evt) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	bArmature *arm= (ob)? ob->data : NULL; | 
					
						
							|  |  |  | 	PointerRNA ptr; | 
					
						
							|  |  |  | 	int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* sanity checking */ | 
					
						
							|  |  |  | 	if (arm == NULL) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 	/* get RNA pointer to armature data to use that to retrieve the layers as ints to init the operator */ | 
					
						
							|  |  |  | 	RNA_id_pointer_create((ID *)arm, &ptr); | 
					
						
							|  |  |  | 	RNA_boolean_get_array(&ptr, "layer", layers); | 
					
						
							|  |  |  | 	RNA_boolean_set_array(op->ptr, "layers", layers); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 		/* part to sync with other similar operators... */ | 
					
						
							|  |  |  | 	/* pass on operator, so return modal */ | 
					
						
							|  |  |  | 	uiPupBlockOperator(C, wm_layers_select_create_menu, op, WM_OP_EXEC_DEFAULT); | 
					
						
							|  |  |  | 	return OPERATOR_RUNNING_MODAL|OPERATOR_PASS_THROUGH; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Set the visible layers for the active armature (edit and pose modes) */ | 
					
						
							|  |  |  | static int pose_armature_layers_exec (bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	bArmature *arm= (ob)? ob->data : NULL; | 
					
						
							|  |  |  | 	PointerRNA ptr; | 
					
						
							|  |  |  | 	int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* get the values set in the operator properties */ | 
					
						
							|  |  |  | 	RNA_boolean_get_array(op->ptr, "layers", layers); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* get pointer for armature, and write data there... */ | 
					
						
							|  |  |  | 	RNA_id_pointer_create((ID *)arm, &ptr); | 
					
						
							|  |  |  | 	RNA_boolean_set_array(&ptr, "layer", layers); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* note, notifier might evolve */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void POSE_OT_armature_layers (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Change Armature Layers"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_armature_layers"; | 
					
						
							|  |  |  | 	ot->description= "Change the visible armature layers."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* callbacks */ | 
					
						
							|  |  |  | 	ot->invoke= pose_armature_layers_invoke; | 
					
						
							|  |  |  | 	ot->exec= pose_armature_layers_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers to make visible."); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ARMATURE_OT_armature_layers (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Change Armature Layers"; | 
					
						
							|  |  |  | 	ot->idname= "ARMATURE_OT_armature_layers"; | 
					
						
							|  |  |  | 	ot->description= "Change the visible armature layers."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* callbacks */ | 
					
						
							|  |  |  | 	ot->invoke= pose_armature_layers_invoke; | 
					
						
							|  |  |  | 	ot->exec= pose_armature_layers_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_editarmature; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers to make visible."); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Present a popup to get the layers that should be used */ | 
					
						
							|  |  |  | static int pose_bone_layers_invoke (bContext *C, wmOperator *op, wmEvent *evt) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* get layers that are active already */ | 
					
						
							|  |  |  | 	memset(&layers, 0, sizeof(layers)); /* set all layers to be off by default */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pchans)  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		short bit; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 		/* loop over the bits for this pchan's layers, adding layers where they're needed */ | 
					
						
							|  |  |  | 		for (bit= 0; bit < 16; bit++) { | 
					
						
							|  |  |  | 			if (pchan->bone->layer & (1<<bit)) | 
					
						
							|  |  |  | 				layers[bit]= 1; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 	CTX_DATA_END; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* copy layers to operator */ | 
					
						
							|  |  |  | 	RNA_boolean_set_array(op->ptr, "layers", layers); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 		/* part to sync with other similar operators... */ | 
					
						
							|  |  |  | 	/* pass on operator, so return modal */ | 
					
						
							|  |  |  | 	uiPupBlockOperator(C, wm_layers_select_create_menu, op, WM_OP_EXEC_DEFAULT); | 
					
						
							|  |  |  | 	return OPERATOR_RUNNING_MODAL|OPERATOR_PASS_THROUGH; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Set the visible layers for the active armature (edit and pose modes) */ | 
					
						
							|  |  |  | static int pose_bone_layers_exec (bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	bArmature *arm= (ob)? ob->data : NULL; | 
					
						
							|  |  |  | 	PointerRNA ptr; | 
					
						
							|  |  |  | 	int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* get the values set in the operator properties */ | 
					
						
							|  |  |  | 	RNA_boolean_get_array(op->ptr, "layers", layers); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* set layers of pchans based on the values set in the operator props */ | 
					
						
							|  |  |  | 	CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pchans)  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		/* get pointer for pchan, and write flags this way */ | 
					
						
							|  |  |  | 		RNA_pointer_create((ID *)arm, &RNA_Bone, pchan->bone, &ptr); | 
					
						
							|  |  |  | 		RNA_boolean_set_array(&ptr, "layer", layers); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	CTX_DATA_END; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* note, notifier might evolve */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void POSE_OT_bone_layers (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Change Bone Layers"; | 
					
						
							|  |  |  | 	ot->idname= "POSE_OT_bone_layers"; | 
					
						
							|  |  |  | 	ot->description= "Change the layers that the selected bones belong to."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* callbacks */ | 
					
						
							|  |  |  | 	ot->invoke= pose_bone_layers_invoke; | 
					
						
							|  |  |  | 	ot->exec= pose_bone_layers_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_posemode; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers that bone belongs to."); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Present a popup to get the layers that should be used */ | 
					
						
							|  |  |  | static int armature_bone_layers_invoke (bContext *C, wmOperator *op, wmEvent *evt) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* get layers that are active already */ | 
					
						
							|  |  |  | 	memset(&layers, 0, sizeof(layers)); /* set all layers to be off by default */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones)  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		short bit; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 		/* loop over the bits for this pchan's layers, adding layers where they're needed */ | 
					
						
							|  |  |  | 		for (bit= 0; bit < 16; bit++) { | 
					
						
							|  |  |  | 			if (ebone->layer & (1<<bit)) | 
					
						
							|  |  |  | 				layers[bit]= 1; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 	CTX_DATA_END; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* copy layers to operator */ | 
					
						
							|  |  |  | 	RNA_boolean_set_array(op->ptr, "layers", layers); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 		/* part to sync with other similar operators... */ | 
					
						
							|  |  |  | 	/* pass on operator, so return modal */ | 
					
						
							|  |  |  | 	uiPupBlockOperator(C, wm_layers_select_create_menu, op, WM_OP_EXEC_DEFAULT); | 
					
						
							|  |  |  | 	return OPERATOR_RUNNING_MODAL|OPERATOR_PASS_THROUGH; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Set the visible layers for the active armature (edit and pose modes) */ | 
					
						
							|  |  |  | static int armature_bone_layers_exec (bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob= CTX_data_active_object(C); | 
					
						
							|  |  |  | 	bArmature *arm= (ob)? ob->data : NULL; | 
					
						
							|  |  |  | 	PointerRNA ptr; | 
					
						
							|  |  |  | 	int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* get the values set in the operator properties */ | 
					
						
							|  |  |  | 	RNA_boolean_get_array(op->ptr, "layers", layers); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* set layers of pchans based on the values set in the operator props */ | 
					
						
							|  |  |  | 	CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones)  | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		/* get pointer for pchan, and write flags this way */ | 
					
						
							|  |  |  | 		RNA_pointer_create((ID *)arm, &RNA_EditBone, ebone, &ptr); | 
					
						
							|  |  |  | 		RNA_boolean_set_array(&ptr, "layers", layers); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	CTX_DATA_END; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* note, notifier might evolve */ | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ARMATURE_OT_bone_layers (wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name= "Change Bone Layers"; | 
					
						
							|  |  |  | 	ot->idname= "ARMATURE_OT_bone_layers"; | 
					
						
							|  |  |  | 	ot->description= "Change the layers that the selected bones belong to."; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* callbacks */ | 
					
						
							|  |  |  | 	ot->invoke= armature_bone_layers_invoke; | 
					
						
							|  |  |  | 	ot->exec= armature_bone_layers_exec; | 
					
						
							|  |  |  | 	ot->poll= ED_operator_editarmature; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers that bone belongs to."); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-26 11:01:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-17 14:56:12 +00:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  | // XXX old sys
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | /* for use with pose_relax only */ | 
					
						
							|  |  |  | static int pose_relax_icu(struct IpoCurve *icu, float framef, float *val, float *frame_prev, float *frame_next) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!icu) { | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	}  | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		BezTriple *bezt = icu->bezt; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		BezTriple *bezt_prev=NULL, *bezt_next=NULL; | 
					
						
							|  |  |  | 		float w1, w2, wtot; | 
					
						
							|  |  |  | 		int i; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		for (i=0; i < icu->totvert; i++, bezt++) { | 
					
						
							|  |  |  | 			if (bezt->vec[1][0] < framef - 0.5) { | 
					
						
							|  |  |  | 				bezt_prev = bezt; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (bezt_prev==NULL) return 0; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* advance to the next, dont need to advance i */ | 
					
						
							|  |  |  | 		bezt = bezt_prev+1; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		for (; i < icu->totvert; i++, bezt++) { | 
					
						
							|  |  |  | 			if (bezt->vec[1][0] > framef + 0.5) { | 
					
						
							|  |  |  | 				bezt_next = bezt; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (bezt_next==NULL) return 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 		if (val) { | 
					
						
							|  |  |  | 			w1 = framef - bezt_prev->vec[1][0]; | 
					
						
							|  |  |  | 			w2 = bezt_next->vec[1][0] - framef; | 
					
						
							|  |  |  | 			wtot = w1 + w2; | 
					
						
							|  |  |  | 			w1=w1/wtot; | 
					
						
							|  |  |  | 			w2=w2/wtot; | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 			val = (bezt_prev->vec[1][1] * w2) + (bezt_next->vec[1][1] * w1); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 			/* apply the value with a hard coded 6th */ | 
					
						
							|  |  |  | 			*val = (((bezt_prev->vec[1][1] * w2) + (bezt_next->vec[1][1] * w1)) + (*val * 5.0f)) / 6.0f; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (frame_prev)	*frame_prev = bezt_prev->vec[1][0]; | 
					
						
							|  |  |  | 		if (frame_next)	*frame_next = bezt_next->vec[1][0]; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-01-17 14:56:12 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void pose_relax(Scene *scene) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob = OBACT; | 
					
						
							|  |  |  | 	bPose *pose; | 
					
						
							|  |  |  | 	bAction *act; | 
					
						
							|  |  |  | 	bArmature *arm; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-01-17 14:56:12 +00:00
										 |  |  | //	IpoCurve *icu_w, *icu_x, *icu_y, *icu_z;
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	bPoseChannel *pchan; | 
					
						
							| 
									
										
										
										
											2009-01-17 14:56:12 +00:00
										 |  |  | //	bActionChannel *achan;
 | 
					
						
							|  |  |  | //	float framef = F_CFRA;
 | 
					
						
							|  |  |  | //	float frame_prev, frame_next;
 | 
					
						
							|  |  |  | //	float quat_prev[4], quat_next[4], quat_interp[4], quat_orig[4];
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	int do_scale = 0; | 
					
						
							|  |  |  | 	int do_loc = 0; | 
					
						
							|  |  |  | 	int do_quat = 0; | 
					
						
							|  |  |  | 	int flag = 0; | 
					
						
							| 
									
										
										
										
											2009-01-17 14:56:12 +00:00
										 |  |  | //	int do_x, do_y, do_z;
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (!ob) return; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	pose = ob->pose; | 
					
						
							|  |  |  | 	act = ob->action; | 
					
						
							|  |  |  | 	arm = (bArmature *)ob->data; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (!pose || !act || !arm) return; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	for (pchan=pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		pchan->bone->flag &= ~BONE_TRANSFORM; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (pchan->bone->layer & arm->layer) { | 
					
						
							|  |  |  | 			if (pchan->bone->flag & BONE_SELECTED) { | 
					
						
							|  |  |  | 				/* do we have an ipo curve? */ | 
					
						
							| 
									
										
											  
											
												2.5: Blender "Animato" - New Animation System 
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action. 
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves. 
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still) 
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
											
										 
											2009-01-17 03:12:50 +00:00
										 |  |  | #if 0 // XXX old animation system
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 				achan= get_action_channel(act, pchan->name); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				if (achan && achan->ipo) { | 
					
						
							|  |  |  | 					/*calc_ipo(achan->ipo, ctime);*/ | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					do_x = pose_relax_icu(find_ipocurve(achan->ipo, AC_LOC_X), framef, &pchan->loc[0], NULL, NULL); | 
					
						
							|  |  |  | 					do_y = pose_relax_icu(find_ipocurve(achan->ipo, AC_LOC_Y), framef, &pchan->loc[1], NULL, NULL); | 
					
						
							|  |  |  | 					do_z = pose_relax_icu(find_ipocurve(achan->ipo, AC_LOC_Z), framef, &pchan->loc[2], NULL, NULL); | 
					
						
							|  |  |  | 					do_loc += do_x + do_y + do_z; | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					do_x = pose_relax_icu(find_ipocurve(achan->ipo, AC_SIZE_X), framef, &pchan->size[0], NULL, NULL); | 
					
						
							|  |  |  | 					do_y = pose_relax_icu(find_ipocurve(achan->ipo, AC_SIZE_Y), framef, &pchan->size[1], NULL, NULL); | 
					
						
							|  |  |  | 					do_z = pose_relax_icu(find_ipocurve(achan->ipo, AC_SIZE_Z), framef, &pchan->size[2], NULL, NULL); | 
					
						
							|  |  |  | 					do_scale += do_x + do_y + do_z; | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 					if(	((icu_w = find_ipocurve(achan->ipo, AC_QUAT_W))) && | 
					
						
							|  |  |  | 						((icu_x = find_ipocurve(achan->ipo, AC_QUAT_X))) && | 
					
						
							|  |  |  | 						((icu_y = find_ipocurve(achan->ipo, AC_QUAT_Y))) && | 
					
						
							|  |  |  | 						((icu_z = find_ipocurve(achan->ipo, AC_QUAT_Z))) ) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						/* use the quatw keyframe as a basis for others */ | 
					
						
							|  |  |  | 						if (pose_relax_icu(icu_w, framef, NULL, &frame_prev, &frame_next)) { | 
					
						
							|  |  |  | 							/* get 2 quats */ | 
					
						
							|  |  |  | 							quat_prev[0] = eval_icu(icu_w, frame_prev); | 
					
						
							|  |  |  | 							quat_prev[1] = eval_icu(icu_x, frame_prev); | 
					
						
							|  |  |  | 							quat_prev[2] = eval_icu(icu_y, frame_prev); | 
					
						
							|  |  |  | 							quat_prev[3] = eval_icu(icu_z, frame_prev); | 
					
						
							|  |  |  | 							 | 
					
						
							|  |  |  | 							quat_next[0] = eval_icu(icu_w, frame_next); | 
					
						
							|  |  |  | 							quat_next[1] = eval_icu(icu_x, frame_next); | 
					
						
							|  |  |  | 							quat_next[2] = eval_icu(icu_y, frame_next); | 
					
						
							|  |  |  | 							quat_next[3] = eval_icu(icu_z, frame_next); | 
					
						
							|  |  |  | 							 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 							/* apply the setting, completely smooth */ | 
					
						
							|  |  |  | 							QuatInterpol(pchan->quat, quat_prev, quat_next, (framef-frame_prev) / (frame_next-frame_prev) ); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 							/* tricky interpolation */ | 
					
						
							|  |  |  | 							QuatInterpol(quat_interp, quat_prev, quat_next, (framef-frame_prev) / (frame_next-frame_prev) ); | 
					
						
							|  |  |  | 							QUATCOPY(quat_orig, pchan->quat); | 
					
						
							|  |  |  | 							QuatInterpol(pchan->quat, quat_orig, quat_interp, 1.0f/6.0f); | 
					
						
							|  |  |  | 							/* done */ | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 							do_quat++; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 					/* apply BONE_TRANSFORM tag so that autokeying will pick it up */ | 
					
						
							|  |  |  | 					pchan->bone->flag |= BONE_TRANSFORM; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
											  
											
												2.5: Blender "Animato" - New Animation System 
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action. 
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves. 
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still) 
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
											
										 
											2009-01-17 03:12:50 +00:00
										 |  |  | 				 | 
					
						
							|  |  |  | #endif // XXX old animation system
 | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* do auto-keying */ | 
					
						
							|  |  |  | 	if (do_loc)		flag |= TFM_TRANSLATION; | 
					
						
							|  |  |  | 	if (do_scale)	flag |= TFM_RESIZE; | 
					
						
							|  |  |  | 	if (do_quat)	flag |= TFM_ROTATION; | 
					
						
							|  |  |  | 	autokeyframe_pose_cb_func(ob, flag, 0); | 
					
						
							|  |  |  | 	  | 
					
						
							|  |  |  | 	/* clear BONE_TRANSFORM flags */ | 
					
						
							|  |  |  | 	for (pchan=pose->chanbase.first; pchan; pchan= pchan->next) | 
					
						
							|  |  |  | 		pchan->bone->flag &= ~ BONE_TRANSFORM; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* do depsgraph flush */ | 
					
						
							| 
									
										
											  
											
												2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
  NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
  notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
  should only be used for notifying about changes in space data,
  we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
											
										 
											2009-09-04 20:51:09 +00:00
										 |  |  | 	DAG_id_flush_update(&ob->id, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	BIF_undo_push("Relax Pose"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* for use in insertkey, ensure rotation goes other way around */ | 
					
						
							|  |  |  | void pose_flipquats(Scene *scene) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob = OBACT; | 
					
						
							|  |  |  | 	bArmature *arm= ob->data; | 
					
						
							|  |  |  | 	bPoseChannel *pchan; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(ob->pose==NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* find sel bones */ | 
					
						
							|  |  |  | 	for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 		if(pchan->bone && (pchan->bone->flag & BONE_SELECTED) && (pchan->bone->layer & arm->layer)) { | 
					
						
							|  |  |  | 			/* quaternions have 720 degree range */ | 
					
						
							|  |  |  | 			pchan->quat[0]= -pchan->quat[0]; | 
					
						
							|  |  |  | 			pchan->quat[1]= -pchan->quat[1]; | 
					
						
							|  |  |  | 			pchan->quat[2]= -pchan->quat[2]; | 
					
						
							|  |  |  | 			pchan->quat[3]= -pchan->quat[3]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* do autokey */ | 
					
						
							|  |  |  | 	autokeyframe_pose_cb_func(ob, TFM_ROTATION, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* context: active channel */ | 
					
						
							|  |  |  | void pose_special_editmenu(Scene *scene) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 	Object *obedit= scene->obedit; // XXX context
 | 
					
						
							|  |  |  | 	Object *ob= OBACT; | 
					
						
							|  |  |  | 	short nr; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* paranoia checks */ | 
					
						
							|  |  |  | 	if(!ob && !ob->pose) return; | 
					
						
							| 
									
										
										
										
											2009-08-16 03:24:23 +00:00
										 |  |  | 	if(ob==obedit || (ob->mode & OB_MODE_POSE)==0) return; | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	nr= pupmenu("Specials%t|Select Constraint Target%x1|Flip Left-Right Names%x2|Calculate Paths%x3|Clear Paths%x4|Clear User Transform %x5|Relax Pose %x6|%l|AutoName Left-Right%x7|AutoName Front-Back%x8|AutoName Top-Bottom%x9"); | 
					
						
							|  |  |  | 	if(nr==1) { | 
					
						
							|  |  |  | 		pose_select_constraint_target(scene); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(nr==2) { | 
					
						
							|  |  |  | 		pose_flip_names(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(nr==3) { | 
					
						
							| 
									
										
										
										
											2009-01-10 14:19:14 +00:00
										 |  |  | 		pose_calculate_path(C, ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if(nr==4) { | 
					
						
							|  |  |  | 		pose_clear_paths(ob); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(nr==5) { | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 		pose_clear_user_transforms(scene, ob); | 
					
						
							| 
									
										
										
										
											2009-01-05 15:19:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if(nr==6) { | 
					
						
							|  |  |  | 		pose_relax(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(ELEM3(nr, 7, 8, 9)) { | 
					
						
							|  |  |  | 		pose_autoside_names(nr-7); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | /* Restore selected pose-bones to 'action'-defined pose */ | 
					
						
							|  |  |  | void pose_clear_user_transforms(Scene *scene, Object *ob) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bArmature *arm= ob->data; | 
					
						
							|  |  |  | 	bPoseChannel *pchan; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (ob->pose == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 	/* if the object has an action, restore pose to the pose defined by the action by clearing pose on selected bones */ | 
					
						
							|  |  |  | 	if (ob->action) { | 
					
						
							|  |  |  | 		/* find selected bones */ | 
					
						
							|  |  |  | 		for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { | 
					
						
							|  |  |  | 			if (pchan->bone && (pchan->bone->flag & BONE_SELECTED) && (pchan->bone->layer & arm->layer)) { | 
					
						
							|  |  |  | 				/* just clear the BONE_UNKEYED flag, allowing this bone to get overwritten by actions again */ | 
					
						
							|  |  |  | 				pchan->bone->flag &= ~BONE_UNKEYED; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		/* clear pose locking flag 
 | 
					
						
							|  |  |  | 		 *	- this will only clear the user-defined pose in the selected bones, where BONE_UNKEYED has been cleared | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		ob->pose->flag |= POSE_DO_UNLOCK; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* no action, so restore entire pose to rest pose (cannot restore only selected bones) */ | 
					
						
							|  |  |  | 		rest_pose(ob->pose); | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
											  
											
												2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
  NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
  notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
  should only be used for notifying about changes in space data,
  we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
											
										 
											2009-09-04 20:51:09 +00:00
										 |  |  | 	DAG_id_flush_update(&ob->id, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 	BIF_undo_push("Clear User Transform"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-09-29 04:00:42 +00:00
										 |  |  | 
 |