0
$\begingroup$

I would like to know if it is possible to get the real coordinates of a bone's head and tail when the armature is rotated. I already got something working with translations of armature but can't figure out how to do it when a rotation is applied.

To demonstrate what I want I created two cubes that will be moved to the bone's head and tail. Here is the code :

import bpy
armature = bpy.data.objects["Armature"]
bname = 'bone_2'
bone = armature.pose.bones[bname]

tail = bone.tail + armature.location
head = bone.head + armature.location


bpy.data.objects['head'].location = head
bpy.data.objects['tail'].location = tail

And here is the result without rotation and with rotation:

Bone without rotation Bone with rotation

Thanks for your help!

$\endgroup$

1 Answer 1

0
$\begingroup$

Use matrix instead of position:

import bpy
armature = bpy.data.objects["Armature"]
bname = 'bone_2'
bone = armature.pose.bones[bname]

tail = armature.matrix_world @ bone.tail 
head = armature.matrix_world @ bone.head 


bpy.data.objects['head'].location = head
bpy.data.objects['tail'].location = tail
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .