This is a pretty naive approach, so it won’t be fast to run the script – but it’s totally doable. In a hardcore version you would not want to run xform
on every vertex, instead you would use the API – but it’s not worth optimizing until the users complain.
Here’s an example version you can run on a scene with just a cube:
def set_animation (object, start_frame, end_frame, point_list):
# set keyframe on initial positions
cmds.currentTime(start_frame)
cmds.setKeyframe(object, t=start_frame, at='pnts')
cmds.currentTime(end_frame)
# loop through indexed list of points
for index, p in enumerate(point_list):
cmds.xform("{0}.vtx[{1}]".format(object, index), t=p, a=True, ws =True)
# set end positions
cmds.setKeyframe(object, t = end_frame, at='pnts')
points = ((1,1,1), (2,2,1), (3,1,0), (2,2,2), (3,3,3), (1,2,3))
set_animation ('pCube1', 2, 10, points)
In a working version you would get points
from the text file as a list of 3-number tuples, corresponding to the maya vertex indices (ie, the first 3 numbers are vertex 0, the second 3 vertex 1, and so on).