Object Vertex Animation Help

Hi chaps,

I am building a script that takes in a set of vertices and has the co-ordinates at different key frames. The aim is to move the object based on the vertices locations in an animation…so for example it creates a object with 8 vertices, sets the current frame to 30 and moves the vertices along x by 5.

The mesh seems to move location OK but the object location doesnt change (the dot stays at 0,0,0). Can anyone tell me how to set the object location to the mesh location?
I have tried setting the IPO to the first vertex but the mesh then stays relative.

Sample input:

Sample code moving the mesh:
def createFrame(p,xl,yl,zl,time):
oGet = Object.Get ( “newOb” )
m = oBot.getData(mesh=1)
v = m.verts[p]
v.co = Blender.Mathutils.Vector(int(xl), int(yl), int(zl))
if p==“7”:

But I dont know what I should put for the next part of the IPO. I need to record the mesh location.

Any ideas? Ive been pulling my hair out the last 2 days :o

Thanks, J

There is a difference between the object and the mesh.
The object contains information on what kind of object it is (lamp, mesh, empty, etc), its location and what data block (which mesh, in your case) is linked to it.
The mesh contains the data of the vertices, faces, etc. It also contains the vertex locations.

So where do things show up in the 3d-view? An example:
You have an object located at 5,0,0 (5 units along the x-axis). This is where the object’s dot is shown in the 3d-view. Its mesh has a vertex with the location 10,0,0. Then this vertex is displayed at 15,0,0
So the vertex location is relative to the object’s location.

So what is it you would like to achieve? Do you want to:
1 - Move the object (this moves everything, both the vertices and the object’s dot)
2 - Move the mesh (so the vertices), but keep the object location (the dot) at the original location
3 - Move only the object dot, but keep the vertices at their original locations in the 3d-view

Some additional questions:
Do you want to move all vertices by the same amount, or do you wish to move for example vertex A by 5 and vertex B by 6?
In your sample input, what does the 2.0 stand for? Is it a frame number, or a time in seconds?

Hey man,

Thanks for getting back to me and for the clarification. The input file only has the vertex locations and I dont want to have to calculate the relative location of the object I just want to move the vertices if you see what I mean.

Ideally when I would want 1 to happen bust based on the new vertex location. But 2 would be fine as long as it moved smoothly between the transformations. 3 is definitely not what I am after.

Any ideas?

Below you can find a script to do what you want.

import bpy
import Blender
from Blender import *

# reading values from text file
file = open("C:/Path/To/My/Input/File/vertex_movement_input.txt")
lines = file.readlines()
keys = []
for l in lines:
    for k in l.strip().split('('):
        if k:
            k = k.strip('()').split(',')
            key = map(lambda x: float(x), k)
            key[0] = int(k[0])

# getting and preparing scene data
ob = bpy.data.objects['Cube']
me = ob.getData(mesh = True)
fps = bpy.data.scenes.active.getRenderingContext().fps
if me.key:

# creating the shapes
old_frame = keys[0][0]
orig_frame = Blender.Get('curframe')
keyframes = [int(old_frame*fps)]
Blender.Set('curframe', int(old_frame*fps))
for k in keys:
    if k[0] != old_frame:
        old_frame = k[0]
        Blender.Set('curframe', int(old_frame*fps))
    me.verts[k[-1]].co = Mathutils.Vector(k[3:0:-1])

# setting up the ipos
ipo = Ipo.New('Key', 'KeyIpo')
me.key.ipo = ipo
for i in range(len(me.key.ipo.curveConsts)):
    icu = ipo.addCurve(me.key.ipo.curveConsts[i])
    icu.interpolation = IpoCurve.InterpTypes.LINEAR
    if i != 0:
        icu.append((float(keyframes[i-1]), 0.0))
    icu.append((float(keyframes[i]), 1.0))
    if i != len(me.key.ipo.curveConsts)-1:
        icu.append((float(keyframes[i+1]), 0.0))

# cleaning up
Blender.Set('curframe', orig_frame)

Obviously you have to change the path (in line 6 of the script) to the input file with the vertex coordinates. You can test the script with the input below (just save it as a .txt) and the blender default scene.

(0,5,5,0,0.0)(1,5,0,0,0.0)(2,0,0,0,0.0)(3,0,5,0,0.0)(4,5,5,5,0.0)(5,5,0,5,0.0)(6,0,0,5,0.0)(7,0,5,5, 0.0)
(0,10,5,0,2.0)(1,10,0,0,2.0)(2,05,0,0,2.0)(3,5,5,0,2.0)(4,10,5,5,2.0)(5,10,0,5,2.0)(6,05,0,5,2.0)(7,05,5,5, 2.0)
(0,15,5,0,4.0)(1,15,0,0,4.0)(2,10,0,0,4.0)(3,10,5,0,4.0)(4,20,5,5,4.0)(5,20,0,5,4.0)(6,15,0,5,4.0)(7,15,5,5, 4.0)

If you want to move another object than the default cube, you have to change the name in line 21 of the script.