Frame-By-Frame vertex data?

Hey all! I am currently using Blender 2.56 and I’m wondering how to get vertex data for an object on a frame-by-frame basis? (I’m trying to make my own 3D model type that uses frame-based animation.) What I mean by that is, say… okay, I set up keyframes in Blender, make my cube object move from point A to point B. I’d like to get what the vertices of that cube are for each frame in that animation.

Any help would be appreciated!

Thanks! :smiley:

I think, in any Blender, the moves between 2 keyframes are linear and proportional. Meaning, if you look at just one vertex, and it is in keyframe1 at a vector a and the same vertex is in keyframe2 located at a vector b, and provided you know how many steps are between a and b, then you can calculate the position for n-th step by adding n*delta to vector a, where delta is the vector (b-a)/number_of_steps.

Sooooooooo you can calculate ALL intermediate data for each vertex positions.

Regards,

Now when you say getting the difference of those two vectors for vertices, don’t the verts have to be different then? The issue I’m having now is that the verts are all staying the same for each frame when I pull them up in python, despite any keyframes that are set.

Bump! (Not to annoy, just trying to figure this out.)

Well, I had in mind that a and b are vectors representing position of one and the same vertex in two consecutive keyframes. In the general situation they are different as your body (object) is moving around. Frankly, I can explain my suggested approach in more details but now I realise that it is a bit restrictive because it works only when your IPO curves are set to linear. Normally, IPO-curves are set “bezier” that makes the direct calculation (w/o running the animation itself) a rather difficult exercise.

I guess you’re getting this and here’s a simple example: suppose you have the default cube which in your animation moves 4 units towards the positive direction of X-axis in 11 frames. Let’s look at the vertex 0… In the first keyframe (cube’s default position 0,0,0) it has coordinates (1,1,-1). In the second keyframe its coordinates are to be (5,1,-1), right? And you have 10 frames between the first and the second keyframe, hence there are 9 intermediate frames which you’d like to have the vertex 0 position (coordinates). In case of linear IPOs, you can find the intermediate position just by adding N-times of unit delta vector (the vertex move between two adjacent frames) having in mind that delta vector is 1/10 of the total displacement, i.e. (0.4,0,0). Thus the position of vertex 0 in the 2-nd frame shall be (1.4,1,-1), etc.

More difficult would be to get the positions in case your IPOs are bezier curves. In such a case, you can do one of those: (1) take the value of the IPO curve that corresponds to the desired frame, then calculate the difference to the initial position and get the NEW position (coordinates); or (2) fake a run of your animation by a cycle which sets the desired frame, makes a REFRESH & UPDATE to you mesh object, then directly get the coordinates you need as they’ve been calculated by Blender during the REFRESH & UPDATE process, then move to the next desired frame and so on till the end of your frame interval of interest. Looking at your second post, I guess you ARE NOT changing the frames so that your Python code reports no difference in coordinates, i.e. no move. The error is that you’re just thinking that your code takes the values of the next frame while you’re practically staying in just one frame… Im NOT providing you a solution, cause I dont know which version of Blender you’re using. I am currently still with 2.49b as it gives me ALL functionally I need and I’d like to go a bit in deep with the Python on 2.49b which is NO possible with these ever-changing APIs for 2.5x that - on top of everything - are NOT compatible with the earlier versions of Python, huh :wink:

Regards,

To illustrate the method (2), I deleted ALL unnecessary objects, IPOs and code off one of my old-project files (made on 2.46).

So on your default cube, called “Cube”, you have IPOS like this (equivalent to translating the cube 4 units on X-axis only):


and the code:

from Blender import *

sce = Scene.GetCurrent()
ob = Object.Get("Cube")
me = ob.getData(mesh=1)
context = sce.getRenderingContext()

Scene.Render.EnableDispWin()
fb = context.sFrame
fe = context.eFrame
print fb,fe
print "=========================="
for i in range(fe-fb+1):
    fc = fb+i
    context.cFrame = fc
    Window.EditMode(1)
    Window.EditMode(0)
    Redraw()
    co = me.verts[0].co*ob.matrix
    print fc,co

Scene.Render.CloseRenderWindow()
print    

that prints data onto console as follows:

1 11
==========================
1 [1.000000, 1.000000, -1.000000](vector)
2 [1.099293, 1.000000, -1.000000](vector)
3 [1.384420, 1.000000, -1.000000](vector)
4 [1.826415, 1.000000, -1.000000](vector)
5 [2.382903, 1.000000, -1.000000](vector)
6 [3.000000, 1.000000, -1.000000](vector)
7 [3.617097, 1.000000, -1.000000](vector)
8 [4.173585, 1.000000, -1.000000](vector)
9 [4.615581, 1.000000, -1.000000](vector)
10 [4.900707, 1.000000, -1.000000](vector)
11 [5.000000, 1.000000, -1.000000](vector)

Here’s the .blend itself (working on 2.46 and 2.49b)

Regards,