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?
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 contains X,Y,and Z information. But I also need the rotation information too. It appears it’s contained in matrix and matrix 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?
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[:3]), list(camera.matrix[:3]), list(camera.matrix[:3])]
angle_y = -asin(max(min(mtx, 1.0), -1.0))
C = cos(angle_y)
if C!=0.0: C = 1.0/C
angle_x = atan2(mtx * C, mtx * C)
angle_z = atan2(mtx * C, mtx * C)
camerax=camera.matrix #campos x
cameray=camera.matrix #campos y
cameraz=camera.matrix #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