For this assignment, we were introduced to Python scripting as a method to parse motion capture ASCII files. In this case we used data from the Vicon motion capture system, which can export data into a simply-formatted .txt file.


In the case of a regularly-formatted text file, parsing data from a file with Python is very simple. In this case, since we knew the Vicon system had 41 markers, I just hard-coded the loop iteration value. We must also throw away the left two columns, since they contain frame numbers and real-world time values. The following code segment will read the file and store it as a list of a list of tuples. The inner list represents the data for one marker over the frame range, and the outer list represents all of the markers.

infile = open('jogging.txt', 'r')
lines = infile.readlines()
counter = 41
curveList = []
for i in range(0,counter):
lineNum = 0

for line in lines:
  lineData = line.strip().split(None)
  lineData = lineData[2:]
  if(lineNum > 1):
    for i in range(0,counter):
      curveList[i].append((lineData[3*i], lineData[3*i+2], lineData[3*i+1]))
  lineNum += 1

Once the data is stored, it can be post-processed more effectively, or iterated over to build Python commands to run in Maya. In my case, I had two main objectives: set up a series of spheres with keyframing, and build RIB Archives for RenderMan Blobbies.


The first approach for bringing data into maya involved creating curves from the mocap data and attaching spheres with motion paths. The main drawback to this approach is a lack of user control due to the rigid nature of the motion path constraint and the large number of CVs on each curve. A keyframe-based approach is more flexible and user-friendly. The code below will traverse the curve list and create spheres with keyframes matching the motion capture data.

for curve in curveList:
  object = cmds.sphere()
  for i in range(0,len(curve)):
    cmds.setKeyframe(v=float(curve[i][0]), at='translateX', t=i)
    cmds.setKeyframe(v=float(curve[i][1]), at='translateY', t=i)
    cmds.setKeyframe(v=float(curve[i][2]), at='translateZ', t=i)

Another benefit of the keyframe approach is the ability to modify the existing keyframe data. In the following video, I created a rigid body simulation and based the initial velocities of the spheres on the velocity vector determined by the last couple of frames of translation data. I then combined this baked simulation with the keyframed mocap data.

Ultimately, I opted to bring these spheres into 3DS Max and run a quick FumeFX simulation.