accessing location of a path-animated object

If I animate an object using keyframe animation, it is relatively straightforward for a python script to be able to access the location, rotation, and so forth.

However if the object is animated with path animation, with a curve object as the parent, I’m having trouble being able to access the actual location of the object as it moves along the path.

For example if I animate a camera using path animation, I’d lilke to be able to export the camera position so I can generate a Terragen script. This is what the blend2ter script does, but it only works for keyframe animation.

Does anyone know how do extract the position of a path animated object?

If you access the object matrix instead of LocX, Y and Z you can get it to work. I did just that in my Walk.o.matic script - have a look at it here —>

Hopefully you can extract the info you need by looking at the source.

Thanks that helped a lot. I’ve made good progress but am now stuck on the format of the matrix information. Is it documented somewhere? I cant’ seem to find it.

From your source and experimenting it seems matrix[3] contains X,Y,and Z information. But I also need the rotation information too. It appears it’s contained in matrix[0] and matrix[1] but the format is, I believe, different from what’s returned with object.RotX, RotY, and RotZ. I can write a converter fairly easily once I know the format.

Does anyone know where the format of the fields in matrix are documented?

thanks again :slight_smile:

I’m afraid the rotations are stored as quaternions. And I don’t know more about those than the word ‘quaternions’ =)

no, they are not quaternions, it’s just a “standard” transformation matrix including rotation, size and location.

That having been said, the format is more or less like this:

matrix[0][:3] is the X axis in the object’s space
matrix[1][:3] is the Y axis in the object’s space
matrix[2][:3] is the Z axis in the object’s space

all those axis include scalling, so don’t be surprise to have values like

matrix[0][:3] = [1, 0, 3]

for example

to extract the Euler angles from the matrix, you have to use back engineering, which, sadly, can sometimes lead to unwanted behavior (gimbal locks).

I hope that helps a bit


I sure appreciate your replies. I’m happy to report the script is working just fine - I used the matrix data plus a conversion I found elsewhere on this forum. Below are the lines I had to change in the blend2ter script. Now I can path-animate a camera and even have it track a second path animated object and the script works just fine - i.e, it properly outputs the camera position and rotation to a Terragen script file.

Only minor problem now is to update the script to run with 2.26/2.27 as I had to revert back to 2.20 to run this script (this should be easy however I’m just learning python)


Mod’s to Guy’s fine blend2ter script to support path-animated cameras:

camera = Blender.Object.Get(“Camera”)

# extract rotation component from matrix 

mtx = [list(camera.matrix[0][:3]), list(camera.matrix[1][:3]), list(camera.matrix[2][:3])]
angle_y = -asin(max(min(mtx[0][2], 1.0), -1.0)) 
C = cos(angle_y) 
if C!=0.0: C = 1.0/C
angle_x = atan2(mtx[1][2] * C, mtx[2][2] * C)
angle_z = atan2(mtx[0][1] * C, mtx[0][0] * C) 

camerax=camera.matrix[3][0] 	#campos x
cameray=camera.matrix[3][1]	#campos y
cameraz=camera.matrix[3][2]	#campos z
camerarotx=angle_x	# => camp
cameraroty=angle_y	# => camb
camerarotz=angle_z	# => camh

print 'current frame: ', blenderframe
print '[X,Y,Z] = ',camerax,cameray,cameraz
print '[rotX,rotY,rotZ] = ', angle_x,angle_y,angle_z

Note to self: Don’t assume a lot of stuff about things I have no idea about…

Note to self: Don’t assume a lot of stuff about things I have no idea about…[/quote]

actually, it’s not like you were 100% wrong. Quaternions are used to express rotations, but in Blender, they are only used for Bones.