| 
									
										
										
										
											2004-05-02 14:29:31 +00:00
										 |  |  | # Blender.Armature.NLA module and the Action PyType object | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | The Blender.Armature.NLA submodule. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NLA | 
					
						
							|  |  |  | === | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This module provides access to B{Action} objects in Blender.  Actions are a series of keyframes/Ipo curves | 
					
						
							|  |  |  | that define the movement of a bone. Actions are linked to objects of type armature. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Example:: | 
					
						
							|  |  |  |   import Blender | 
					
						
							|  |  |  |   from Blender import * | 
					
						
							|  |  |  |   from Blender.Armature import * | 
					
						
							|  |  |  |   from Blender.Armature.Bone import * | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   armObj = Object.New('Armature', "Armature_obj") | 
					
						
							|  |  |  |   armData = Armature.New() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   bn1=Blender.Armature.Bone.New("bone1") | 
					
						
							|  |  |  |   bn1.setHead(0.0,0.0,0.0) | 
					
						
							|  |  |  |   bn1.setTail(2.0,1.0,0.0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   bn2=Blender.Armature.Bone.New("bone2") | 
					
						
							|  |  |  |   bn2.setHead(3.0,2.0,1.0) | 
					
						
							|  |  |  |   bn2.setTail(4.0,4.0,1.0) | 
					
						
							|  |  |  |   bn2.setRoll(.5) | 
					
						
							|  |  |  |   bn2.setParent(bn1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   armData.addBone(bn1) | 
					
						
							|  |  |  |   armData.addBone(bn2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   armObj.link(armData) | 
					
						
							|  |  |  |   scn = Blender.Scene.getCurrent() | 
					
						
							|  |  |  |   scn.link(armObj) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   armObj.makeDisplayList() | 
					
						
							|  |  |  |   Blender.Window.RedrawAll() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   action = Blender.Armature.NLA.NewAction() | 
					
						
							|  |  |  |   action.setActive(armObj) | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   bn2.setPose([ROT,LOC,SIZE])   | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   context = scn.getRenderingContext() | 
					
						
							|  |  |  |   context.currentFrame(2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   quat = Blender.Mathutils.Quaternion([1,2,3,4]) | 
					
						
							|  |  |  |   bn2.setQuat(quat) | 
					
						
							|  |  |  |   bn2.setLoc([3,4,5]) | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   bn2.setPose([ROT,LOC,SIZE]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   print action.name | 
					
						
							|  |  |  |   action2 = Blender.Armature.NLA.CopyAction(action) | 
					
						
							|  |  |  |   action2.name = "Copy" | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | @type Flags: readonly dictionary | 
					
						
							|  |  |  | @var Flags: Constant dict used by the L{ActionStrip.flag} attribute. | 
					
						
							|  |  |  | It is a bitmask and settings are ORed together. | 
					
						
							|  |  |  |   - SELECT: action strip is selected in NLA window | 
					
						
							| 
									
										
										
										
											2006-07-12 14:27:13 +00:00
										 |  |  |   - STRIDE_PATH: play action based on path position and stride. | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  |   - HOLD: continue displaying the last frame past the end of the strip | 
					
						
							|  |  |  |   - ACTIVE: action strip is active in NLA window | 
					
						
							|  |  |  |   - LOCK_ACTION: action start/end are automatically mapped to strip duration | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @type StrideAxes: readonly dictionary | 
					
						
							|  |  |  | @var StrideAxes: Constant dict used by the L{ActionStrip.strideAxis} attribute. | 
					
						
							|  |  |  | Values are STRIDEAXIS_X, STRIDEAXIS_Y, and STRIDEAXIS_Z. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @type Modes: readonly dictionary | 
					
						
							|  |  |  | @var Modes: Constant dict used by the L{ActionStrip.mode} attribute. | 
					
						
							|  |  |  | Currently the only value is MODE_ADD. | 
					
						
							| 
									
										
										
										
											2004-05-02 14:29:31 +00:00
										 |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def NewAction  (name = 'DefaultAction'): | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  |   Create a new Action object. | 
					
						
							|  |  |  |   @type name: string | 
					
						
							|  |  |  |   @param name: The Action name. | 
					
						
							|  |  |  |   @rtype: PyAction | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  | def CopyAction (action): | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  |   Copy an action and it's keyframes | 
					
						
							|  |  |  |   @type action: PyAction | 
					
						
							|  |  |  |   @param action: The action to be copied. | 
					
						
							|  |  |  |   @rtype: PyAction | 
					
						
							|  |  |  |   @return: A copied action | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def GetActions (): | 
					
						
							|  |  |  |   """
 | 
					
						
							| 
									
										
										
										
											2004-05-25 03:26:29 +00:00
										 |  |  |   Get all actions and return them as a Key : Value Dictionary. | 
					
						
							|  |  |  |   @rtype: Dictionary of PyActions | 
					
						
							| 
									
										
										
										
											2004-05-02 14:29:31 +00:00
										 |  |  |   @return: All the actions in blender | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  | class Action: | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  |   The Action object | 
					
						
							|  |  |  |   ================= | 
					
						
							|  |  |  |     This object gives access to Action-specific data in Blender. | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def getName(): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Get the name of this Action. | 
					
						
							|  |  |  |     @rtype: string | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |   def setName(name): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Set the name of this Action. | 
					
						
							|  |  |  |     @type name: string | 
					
						
							|  |  |  |     @param name: The new name | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |   def setActive(object): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Set this action as the current action for an object. | 
					
						
							|  |  |  |     @type object: PyObject  | 
					
						
							|  |  |  |     @param object: The object whose action is to be set | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |   def getChannelIpo(channel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Get the Ipo for the named channel in this action | 
					
						
							|  |  |  |     @type channel: string | 
					
						
							|  |  |  |     @param channel: The name of a channel in this action | 
					
						
							| 
									
										
										
										
											2006-04-21 20:31:27 +00:00
										 |  |  |     @rtype: PyIpo or None | 
					
						
							| 
									
										
										
										
											2004-05-02 14:29:31 +00:00
										 |  |  |     @return: the Ipo for the channel | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2006-05-21 21:04:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def getFrameNumbers(): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Gets the frame numbers at which a key was inserted into this action | 
					
						
							|  |  |  |     @rtype: PyList | 
					
						
							|  |  |  |     @return: a list of ints | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2004-05-02 14:29:31 +00:00
										 |  |  |      | 
					
						
							|  |  |  |   def removeChannel(channel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Remove a named channel from this action | 
					
						
							|  |  |  |     @type channel: string | 
					
						
							|  |  |  |     @param channel: The name of a channel in this action to be removed | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2004-05-15 03:02:11 +00:00
										 |  |  |   def getAllChannelIpos(): | 
					
						
							| 
									
										
										
										
											2004-05-02 14:29:31 +00:00
										 |  |  |     """
 | 
					
						
							|  |  |  |     Get the all the Ipos for this action | 
					
						
							| 
									
										
										
										
											2006-04-21 20:31:27 +00:00
										 |  |  |     @rtype: Dictionary [channel : PyIpo or None] | 
					
						
							| 
									
										
										
										
											2004-05-02 14:29:31 +00:00
										 |  |  |     @return: the Ipos for all the channels in the action | 
					
						
							| 
									
										
										
										
											2006-04-21 20:31:27 +00:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ActionStrips: | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  |   The ActionStrips object | 
					
						
							|  |  |  |   ======================= | 
					
						
							|  |  |  |   This object gives access to sequence of L{ActionStrip} objects for | 
					
						
							|  |  |  |   a particular Object. | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def __getitem__(index): | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2006-08-31 16:30:14 +00:00
										 |  |  |     This operator returns one of the action strips in the stack. | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  |     @type index: int | 
					
						
							| 
									
										
										
										
											2006-08-31 16:30:14 +00:00
										 |  |  |     @return: an action strip object | 
					
						
							|  |  |  |     @rtype: ActionStrip | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  |     @raise KeyError: index was out of range | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def __len__(): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Returns the number of action strips for the object. | 
					
						
							| 
									
										
										
										
											2006-08-31 16:30:14 +00:00
										 |  |  |     @return: number of action strips | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  |     @rtype: int | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def append(action): | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2006-07-12 14:27:13 +00:00
										 |  |  |     Appends a new action to the end of the action strip sequence. | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  |     @type action: L{Action<NLA.Action>} | 
					
						
							|  |  |  |     @param action: the action to use in the action strip | 
					
						
							| 
									
										
										
										
											2006-08-31 16:30:14 +00:00
										 |  |  |     @rtype: ActionStrip | 
					
						
							|  |  |  |     @return: the new action strip | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def remove(actionstrip): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Remove an action strip from this object's actionstrip sequence. | 
					
						
							|  |  |  |     @type actionstrip: an action strip from this sequence to remove. | 
					
						
							|  |  |  |     @note: Accessing attributes of the action strip after it is removed will  | 
					
						
							|  |  |  |     throw an exception. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def moveDown(actionstrip): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Move the action strip down in the object's actionstrip sequence. | 
					
						
							|  |  |  |     @type actionstrip: an action strip from this sequence. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  |   def moveUp(actionstrip): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Move the action strip up in the object's actionstrip sequence. | 
					
						
							|  |  |  |     @type actionstrip: an action strip from this sequence. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ActionStrip: | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  |   The ActionStrip object | 
					
						
							|  |  |  |   ====================== | 
					
						
							|  |  |  |   This object gives access to a particular action strip. | 
					
						
							|  |  |  |   @ivar action: Action associated with the strip. | 
					
						
							|  |  |  |   @type action: BPy Action object | 
					
						
							|  |  |  |   @ivar stripStart: Starting frame of the strip. | 
					
						
							|  |  |  |   @type stripStart: float  | 
					
						
							|  |  |  |   @ivar stripEnd: Ending frame of the strip. | 
					
						
							|  |  |  |   @type stripEnd: float  | 
					
						
							|  |  |  |   @ivar actionStart: Starting frame of the action. | 
					
						
							|  |  |  |   @type actionStart: float  | 
					
						
							|  |  |  |   @ivar actionEnd: Ending frame of the action. | 
					
						
							|  |  |  |   @type actionEnd: float  | 
					
						
							|  |  |  |   @ivar repeat: The number of times to repeat the action range. | 
					
						
							|  |  |  |   @type repeat: float  | 
					
						
							|  |  |  |   @ivar mode: Controls the ActionStrip mode.  See L{Modes} for | 
					
						
							|  |  |  |   valid values. | 
					
						
							|  |  |  |   @type mode: int | 
					
						
							|  |  |  |   @ivar flag: Controls various ActionStrip attributes.  Values can be ORed. | 
					
						
							|  |  |  |   See L{Flags} for valid values. | 
					
						
							|  |  |  |   @type flag: int | 
					
						
							|  |  |  |   @ivar strideAxis: Dominant axis for stride bone. See L{StrideAxes} for | 
					
						
							|  |  |  |   valid values. | 
					
						
							|  |  |  |   @type strideAxis: int  | 
					
						
							|  |  |  |   @ivar strideLength: Distance covered by one complete cycle of the action | 
					
						
							|  |  |  |   specified in the Action Range. | 
					
						
							|  |  |  |   @type strideLength: float  | 
					
						
							|  |  |  |   @ivar strideBone: Name of Bone used for stride | 
					
						
							|  |  |  |   @type strideBone: string  | 
					
						
							| 
									
										
										
										
											2006-08-31 16:30:14 +00:00
										 |  |  |   @ivar groupTarget: Armature object within DupliGroup for local animation | 
					
						
							|  |  |  |   @type groupTarget: object | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  |   @ivar blendIn: Number of frames of motion blending. | 
					
						
							|  |  |  |   @type blendIn: float  | 
					
						
							|  |  |  |   @ivar blendOut: Number of frames of ease-out. | 
					
						
							|  |  |  |   @type blendOut: float  | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def resetActionLimits(): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Activates the functionality found in NLA Strip menu under "Reset  Action | 
					
						
							|  |  |  |     Start/End". This method restores the values of ActionStart and | 
					
						
							|  |  |  |     ActionEnd to  their defaults, usually the first and last frames within | 
					
						
							|  |  |  |     an action  that contain keys. | 
					
						
							| 
									
										
										
										
											2006-07-12 14:27:13 +00:00
										 |  |  |     @rtype: None | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def resetStripSize(): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Activates the functionality found in NLA Strip menu under "Reset  Strip | 
					
						
							| 
									
										
										
										
											2006-08-31 16:30:14 +00:00
										 |  |  |     Size".  This method resets the action strip size to its creation values. | 
					
						
							| 
									
										
										
										
											2006-07-12 14:27:13 +00:00
										 |  |  |     @rtype: None | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def snapToFrame(): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Activates the functionality found in NLA Strip menu under "Snap to Frame". | 
					
						
							|  |  |  |     This function snaps the ends of the action strip to the nearest whole | 
					
						
							|  |  |  |     numbered frame. | 
					
						
							| 
									
										
										
										
											2006-07-12 14:27:13 +00:00
										 |  |  |     @rtype: None | 
					
						
							| 
									
										
										
										
											2006-05-22 14:19:52 +00:00
										 |  |  |     """
 |