Module Pose
[hide private]
[frames] | no frames]

Source Code for Module Pose

  1  # Blender.Object.Pose module 
  2   
  3  """ 
  4  The Blender.Object.Pose submodule. 
  5   
  6  Pose 
  7  ==== 
  8   
  9  This module provides access to B{Pose} objects in Blender.  This Pose is the  
 10  current object-level (as opposed to armature-data level) transformation. 
 11   
 12  Example:: 
 13          import Blender 
 14          from Blender import * 
 15   
 16   
 17          scn= Scene.GetCurrent() 
 18   
 19          # New Armature 
 20          arm_data= Armature.New('myArmature') 
 21          print arm_data 
 22          arm_ob = scn.objects.new(arm_data) 
 23          arm_data.makeEditable() 
 24   
 25   
 26          # Add 4 bones 
 27          ebones = [Armature.Editbone(), Armature.Editbone(), Armature.Editbone(), Armature.Editbone()] 
 28   
 29          # Name the editbones 
 30          ebones[0].name = 'Bone.001' 
 31          ebones[1].name = 'Bone.002' 
 32          ebones[2].name = 'Bone.003' 
 33          ebones[3].name = 'Bone.004' 
 34   
 35          # Assign the editbones to the armature 
 36          for eb in ebones: 
 37                  arm_data.bones[eb.name]= eb 
 38   
 39          # Set the locations of the bones 
 40          ebones[0].head= Mathutils.Vector(0,0,0) 
 41          ebones[0].tail= Mathutils.Vector(0,0,1) 
 42          ebones[1].head= Mathutils.Vector(0,0,1) 
 43          ebones[1].tail= Mathutils.Vector(0,0,2) 
 44          ebones[2].head= Mathutils.Vector(0,0,2) 
 45          ebones[2].tail= Mathutils.Vector(0,0,3) 
 46          ebones[3].head= Mathutils.Vector(0,0,3) 
 47          ebones[3].tail= Mathutils.Vector(0,0,4) 
 48   
 49          ebones[1].parent= ebones[0] 
 50          ebones[2].parent= ebones[1] 
 51          ebones[3].parent= ebones[2] 
 52   
 53          arm_data.update() 
 54          # Done with editing the armature 
 55   
 56   
 57          # Assign the pose animation 
 58          pose = arm_ob.getPose() 
 59   
 60          act = arm_ob.getAction() 
 61          if not act: # Add a pose action if we dont have one 
 62                  act = Armature.NLA.NewAction() 
 63                  act.setActive(arm_ob) 
 64   
 65          xbones=arm_ob.data.bones.values() 
 66          pbones = pose.bones.values() 
 67          print xbones 
 68          print pbones 
 69   
 70   
 71          frame = 1 
 72          for pbone in pbones: # set bones to no rotation 
 73                  pbone.quat[:] = 1.000,0.000,0.000,0.0000 
 74                  pbone.insertKey(arm_ob, frame, Object.Pose.ROT) 
 75   
 76          # Set a different rotation at frame 25 
 77          pbones[0].quat[:] = 1.000,0.1000,0.2000,0.20000 
 78          pbones[1].quat[:] = 1.000,0.6000,0.5000,0.40000 
 79          pbones[2].quat[:] = 1.000,0.1000,0.3000,0.40000 
 80          pbones[3].quat[:] = 1.000,-0.2000,-0.3000,0.30000 
 81   
 82          frame = 25 
 83          for i in xrange(4): 
 84                  pbones[i].insertKey(arm_ob, frame, Object.Pose.ROT) 
 85   
 86          pbones[0].quat[:] = 1.000,0.000,0.000,0.0000 
 87          pbones[1].quat[:] = 1.000,0.000,0.000,0.0000 
 88          pbones[2].quat[:] = 1.000,0.000,0.000,0.0000 
 89          pbones[3].quat[:] = 1.000,0.000,0.000,0.0000 
 90   
 91   
 92          frame = 50       
 93          for pbone in pbones: # set bones to no rotation 
 94                  pbone.quat[:] = 1.000,0.000,0.000,0.0000 
 95                  pbone.insertKey(arm_ob, frame, Object.Pose.ROT) 
 96   
 97   
 98   
 99  @var ROT:  
100  @type ROT: Constant 
101  @var LOC:  
102  @type LOC: Constant 
103  @var SIZE:  
104  @type SIZE: Constant 
105  """ 
106   
107 -class Pose:
108 """ 109 The Pose object 110 =============== 111 This object gives access to Pose-specific data in Blender. 112 @ivar bones: A Dictionary of PosePoseBones (PoseDict) that make up this Pose. 113 @type bones: PoseDict Object 114 """ 115
116 - def update():
117 """ 118 Save all changes and update the Pose. 119 @rtype: None 120 """
121
122 -class PoseBonesDict:
123 """ 124 The PoseBonesDict object 125 ======================== 126 This object gives dictionary like access to the PoseBones in a Pose. 127 It is internal to blender but is called as 'Pose.bones' 128 """ 129
130 - def items():
131 """ 132 Return the key, value pairs in this dictionary 133 @rtype: string, PosePoseBone 134 @return: All strings, and PosePoseBones in the Pose (in that order) 135 """
136
137 - def keys():
138 """ 139 Return the keys in this dictionary 140 @rtype: string 141 @return: All strings representing the PosePoseBone names 142 """
143
144 - def values():
145 """ 146 Return the values in this dictionary 147 @rtype: BPy_PoseBone 148 @return: All PosePoseBones in this dictionary 149 """
150
151 -class PoseBone:
152 """ 153 The PoseBone object 154 =================== 155 This object gives access to PoseBone-specific data in Blender. 156 @ivar name: The name of this PoseBone. 157 @type name: String 158 @ivar loc: The change in location for this PoseBone. this is the equivilent of bone.getLoc() in the old 2.3x python api. 159 @type loc: Vector object 160 @ivar size: The change in size for this PoseBone (no change is 1,1,1) 161 @type size: Vector object 162 @ivar quat: The change in rotation for this PoseBone. 163 @type quat: Quaternion object 164 @ivar head: The final head location for this PoseBone. (not settable) 165 @type head: Vector object 166 @ivar tail: The final tail location for this PoseBone. (not settable) 167 @type tail: Vector object 168 @ivar sel: The selection state of this bone 169 @type sel: Boolean 170 @ivar parent: The parent of this posebone (not settable) 171 @type parent: posebone or None 172 @ivar displayObject: The object to display in place of the bone. (custom bones) 173 @type displayObject: Object or None 174 @ivar localMatrix: The matrix combination of rot/size/loc. 175 @type localMatrix: Matrix object 176 @ivar poseMatrix: The total transformation of this PoseBone including constraints. 177 178 This matrix is in armature space, for the current worldspace location of this pose bone, multiply 179 it with its objects worldspace matrix. 180 181 eg. pose_bone.poseMatrix * object.matrixWorld 182 183 Setting the poseMatrix only sets the loc/size/rot, before constraints are applied (similar to actions). 184 After setting pose matrix, run pose.update() to re-evaluate the pose and see the changes in the 3d view. 185 186 @type poseMatrix: Matrix object 187 @type constraints: BPy_ConstraintSeq 188 @ivar constraints: a sequence of constraints for the object 189 @type limitmin: 3-item sequence 190 @ivar limitmin: The x,y,z minimum limits on rotation when part of an IK 191 @type limitmax: 3-item sequence 192 @ivar limitmax: The x,y,z maximum limits on rotation when part of an IK 193 194 @type hasIK: bool 195 @ivar hasIK: True if this pose bone is a part of an IK (readonly), when False, other IK related values have no affect. 196 197 @type stretch: float 198 @ivar stretch: The amount to stretch to the ik target when part of an IK [0.0 - 1.0] 199 200 @type stiffX: float 201 @ivar stiffX: The x stiffness when part of an IK [0.0 - 0.990] 202 @type stiffY: float 203 @ivar stiffY: The x stiffness when part of an IK [0.0 - 0.990] 204 @type stiffZ: float 205 @ivar stiffZ: The x stiffness when part of an IK [0.0 - 0.990] 206 207 @type limitX: bool 208 @ivar limitX: Limit rotation over X axis when part of an IK. 209 @type limitY: bool 210 @ivar limitY: Limit rotation over Y axis when part of an IK. 211 @type limitZ: bool 212 @ivar limitZ: Limit rotation over Z axis when part of an IK. 213 214 @type lockXRot: bool 215 @ivar lockXRot: Disable X DoF when part of an IK. 216 @type lockYRot: bool 217 @ivar lockYRot: Disable Y DoF when part of an IK. 218 @type lockZRot: bool 219 @ivar lockZRot: Disable Z DoF when part of an IK. 220 @ivar layerMask: Layer bitmask 221 Example:: 222 # set bone to layers 14 and 16 223 bone.layerMask = (1<<13) + (1<<15) 224 @type layerMask: Int 225 """ 226
227 - def insertKey(parentObject, frameNumber, type = "[Pose.LOC, Pose.ROT, Pose.SIZE]", fast = False):
228 """ 229 Insert a pose key for this PoseBone at a frame. 230 @type parentObject: Object object 231 @param parentObject: The object the pose came from. 232 @type frameNumber: integer 233 @param frameNumber: The frame number to insert the pose key on. 234 @type type: Constant object 235 @param type: Optional argumentm. 236 Can be any combination of 3 Module constants: 237 - Pose.LOC 238 - Pose.ROT (This adds keyframes to the quat ipo, since quaternions are used for pose bone rotation) 239 - Pose.SIZE 240 If this argument is omitted all keys will be added. 241 @type fast: Bool 242 @param fast: If enabled, the IPOs will not be recalculated, speeds up adding many keyframes at once. 243 @rtype: None 244 """
245