I need to get position and rotation of a object relatively to it’s parent. First oddity, I faced to, was that in blender local coordinates is something diferent, than coordinates from parent’s center, but seems like coordinates from world at the moment of linking. Why is it so?
Anyway. I wrote this script to get local rotation. It works, but maybe there is a better way to do it?
import Mathutils
def getworldaxis(obj):
ornt = obj.worldOrientation
clmn0 = ornt[0]
clmn1 = ornt[1]
clmn2 = ornt[2]
matrix1 = Mathutils.Matrix([clmn0[0],clmn1[0],clmn2[0]],[clmn0[1],clmn1[1],clmn2[1]],[clmn0[2],clmn1[2],clmn2[2]])
matrixEuler= matrix1.toEuler()
return matrixEuler
def getlocalaxis(obj):
parent = obj.parent
objaxis = getworldaxis(obj)
parentaxis = getworldaxis(parent)
axx = objaxis[0] - parentaxis[0]
axy = objaxis[1] - parentaxis[1]
axz = objaxis[2] - parentaxis[2]
localaxis = Mathutils.Euler( axx , axy, axz)
return localaxis
And now i also need local position, considering parent’s rotation. How to get it? Maybe someone was faced with a similar task?