1

I want to get the coordinates of joints of a skeleton. The following is the main code I used.

obj = bpy.context.object
obj_bone = bpy.context.object.data.bones
for f in range(scene.frame_start, scene.frame_end):
  scene.frame_set(f)
  verts = [obj.matrix_world @ obj_bone[i].head_local for i in range(31)]

But the coordinates of joints are the same between frames, seems the obj_bone only gets the coordinates in EDIT mode, how to get coordinates for all frames?

blender987
  • 23
  • 5
  • See this answer for code; but the summary is that if you look at the armature's .pose.bones instead of .data.bones you get the position of the bones in pose mode. – Marty Fouts Oct 15 '21 at 03:50
  • Thanks marty. I tried pose.bones[i].head, but this coordinates are relative to its parent, unlike data.bones, it has attribute "head_local", which is relative to the armature, thus I can use "obj.matrix_world @ obj_bone[i].head_local" to get the world coordinates of bones. How to go from pose.bones[i].head coordinates to world coordinates? – blender987 Oct 15 '21 at 05:53

1 Answers1

1

The problem is solved. According to marty's comment, I use pose.bones instead of data.bones and the world coordinates of bones are calculated as follows:

obj = bpy.context.object
pb = obj.pose.bones["Neck1"]
obj.matrix_world @ pb.matrix @ pb.location

more details see How to get posebone global location

blender987
  • 23
  • 5