
|
import sys import os import shutil import Image import string
def BVHFixUp(inBVHName, outBVHName):
print '------- Started BVH Fixup -------' # Arrays and variables numofnodes = 0 NodeArray = list()
#First pass thru the BVH file is to find the number of Nodes (Positions and Rotations)
inBVH = open(inBVHName, 'r') outBVH = open(outBVHName, 'w') #Main Loop counter = 0 totalchannels = 0 numofchannels = 0 motion = 'n' chk = 0 nodecntr = 0 parsestr = 'n' while 1: strin = inBVH.readline() strout = strin if not strin: break #EOF counter = counter + 1 if strin.find('CHANNEL') > 0: stridx = strin.find('S') #print 'Channel at= ', stridx numofchannels = strin[stridx+2:stridx+3] #print 'numofchannels= ', numofchannels if numofchannels == '3': totalchannels = 3 + totalchannels if numofchannels == '6': totalchannels = 6 + totalchannels print 'totalchannels= ', totalchannels if strin.find('Hips') > 0: strout = strin.replace('Hips','Hip') #print 'fixed string= ', strout if strin.find('LHipJoint') > 0: strout = strin.replace('LHipJoint','lButtock') #print 'fixed string= ', strout if strin.find('LeftUpLeg') > 0: strout = strin.replace('LeftUpLeg','Left Thigh') #print 'fixed string= ', strout if strin.find('LeftLeg') > 0: strout = strin.replace('LeftLeg','Left Shin') #print 'fixed string= ', strout if strin.find('LeftFoot') > 0: strout = strin.replace('LeftFoot','Left Foot') #print 'fixed string= ', strout if strin.find('LeftToeBase') > 0: strout = strin.replace('LeftToeBase','lToe') #print 'fixed string= ', strout if strin.find('RHipJoint') > 0: strout = strin.replace('RHipJoint','rButtock') #print 'fixed string= ', strout if strin.find('RightUpLeg') > 0: strout = strin.replace('RightUpLeg','Right Thigh') #print 'fixed string= ', strout if strin.find('RightLeg') > 0: strout = strin.replace('RightLeg','Right Shin') #print 'fixed string= ', strout if strin.find('RightFoot') > 0: strout = strin.replace('RightFoot','Right Foot') #print 'fixed string= ', strout if strin.find('RightToeBase') > 0: strout = strin.replace('RightToeBase','rToe') #print 'fixed string= ', strout if strin.find('LowerBack') > 0: strout = strin.replace('LowerBack','Waist') #print 'fixed string= ', strout if strin.find('Spine') > 0: if strin.find('Spine1') > 0: strout = strin.replace('Spine1','Chest') #print 'fixed string= ', strout else: strout = strin.replace('Spine','Abdomen') #print 'fixed string= ', strout if strin.find('LeftShoulder') > 0: strout = strin.replace('LeftShoulder','Left Collar') #print 'fixed string= ', strout if strin.find('LeftArm') > 0: strout = strin.replace('LeftArm','Left Shoulder') #print 'fixed string= ', strout if strin.find('LeftForeArm') > 0: strout = strin.replace('LeftForeArm','Left Forearm') #print 'fixed string= ', strout if strin.find('LeftHand') > 0: strout = strin.replace('LeftHand','Left Hand') #print 'fixed string= ', strout #if strin.find('LeftFingerBase') > 0: # strout = strin.replace('LeftFingerBase','lMid1') #print 'fixed string= ', strout if strin.find('LThumb') > 0: strout = strin.replace('LThumb','lThumb1') #print 'fixed string= ', strout #if strin.find('LFingers') > 0: # strout = strin.replace('LFingers','lMid3') #print 'f if strin.find('RightShoulder') > 0: strout = strin.replace('RightShoulder','Right Collar') #print 'fixed string= ', strout if strin.find('RightArm') > 0: strout = strin.replace('RightArm','Right Shoulder') #print 'fixed string= ', strout if strin.find('RightForeArm') > 0: strout = strin.replace('RightForeArm','Right Forearm') #print 'fixed string= ', strout if strin.find('RightHand') > 0: strout = strin.replace('RightHand','Right Hand') #print 'fixed string= ', strout #if strin.find('RightFingerBase') > 0: # strout = strin.replace('RightFingerBase','rMid1') #print 'fixed string= ', strout if strin.find('RThumb') > 0: strout = strin.replace('RThumb','rThumb1') #print 'fixed string= ', strout #if strin.find('RFingers') > 0: # strout = strin.replace('RFingers','rMid3') #print 'f if strin.find(':') > 0: print 'found frames' outBVH.write(strout) strin = inBVH.readline() strout = strin outBVH.write(strout) strin = inBVH.readline() strout = strin parsestr = 'y' if parsestr == 'y': begpos = 0 nodecntr = 0 strout = "" while 1: nextspace = strin.find(" ",begpos) if nextspace > 0: nodecntr = nodecntr + 1 val = strin[begpos:nextspace] begpos = nextspace + 1 #print 'val= ', nextspace, ': ', val #print 'node= ', nodecntr, ' val= ', val newval = val #Fix Up Logic - lCollar if nodecntr == 57: newval = float(val) + 0 if nodecntr == 56: newval = float(val) + 1 if nodecntr == 55: newval = float(val) - 24 #Fix Up Logic - lShldr if nodecntr == 60: newval = float(val) + 1 if nodecntr == 59: newval = float(val) - 31 #+6 if nodecntr == 58: newval = float(val) + 37 #+22 #Fix Up Logic - lForeArm if nodecntr == 63: newval = float(val) + 0 if nodecntr == 62: newval = float(val) - 29 if nodecntr == 61: newval = float(val) + 0 #Fix Up Logic - lHand if nodecntr == 66: newval = float(val) + 45 if nodecntr == 65: newval = float(val) - 16 if nodecntr == 64: newval = float(val) - 173 #Fix Up Logic - lmid1 if nodecntr == 69: newval = float(val) + 45 if nodecntr == 68: newval = float(val) - 10 if nodecntr == 67: newval = float(val) - 200 #Fix Up Logic - lmid3 if nodecntr == 72: newval = float(val) - 1 if nodecntr == 71: newval = float(val) + 2 if nodecntr == 70: newval = float(val) - 6 #Fix Up Logic - lThumb if nodecntr == 75: newval = float(val) + 56 if nodecntr == 74: newval = float(val) + 15 if nodecntr == 73: newval = float(val) + 170 #Fix Up Logic - rCollar if nodecntr == 78: newval = float(val) + 0 if nodecntr == 77: newval = float(val) - 1 if nodecntr == 76: newval = float(val) + 24 #Fix Up Logic - rShldr if nodecntr == 81: newval = float(val) - 1 if nodecntr == 80: newval = float(val) + 26 # -6 if nodecntr == 79: newval = float(val) - 37 #-22 #Fix Up Logic - rForeArm if nodecntr == 84: newval = float(val) + 0 if nodecntr == 83: newval = float(val) + 29 if nodecntr == 82: newval = float(val) + 0 #Fix Up Logic - rHand if nodecntr == 87: newval = float(val) - 45 if nodecntr == 86: newval = float(val) + 16 if nodecntr == 85: newval = float(val) + 173 #Fix Up Logic - rmid1 if nodecntr == 90: newval = float(val) - 45 if nodecntr == 89: newval = float(val) + 18 if nodecntr == 88: newval = float(val) + 160 #Fix Up Logic - rmid3 if nodecntr == 93: newval = float(val) + 1 if nodecntr == 92: newval = float(val) - 2 if nodecntr == 91: newval = float(val) + 6 #Fix Up Logic - rThumb if nodecntr == 96: newval = float(val) - 56 if nodecntr == 95: newval = float(val) - 15 if nodecntr == 94: newval = float(val) - 170 #Fix Up Logic - lButtock if nodecntr == 9: newval = float(val) + 2 if nodecntr == 8: newval = float(val) - 12 if nodecntr == 7: newval = float(val) - 30 #Fix Up Logic - lThigh if nodecntr == 12: newval = float(val) + 1 if nodecntr == 11: newval = float(val) + 14 if nodecntr == 10: newval = float(val) + 32 #Fix Up Logic - lShin if nodecntr == 15: newval = float(val) + 4 if nodecntr == 14: newval = float(val) + 2 if nodecntr == 13: newval = float(val) - 4 #Fix Up Logic - lFoot if nodecntr == 18: newval = float(val) - 6 if nodecntr == 17: newval = float(val) - 1 if nodecntr == 16: newval = float(val) + 19 #Fix Up Logic - lToe if nodecntr == 21: newval = float(val) if nodecntr == 20: newval = float(val) if nodecntr == 19: newval = float(val) #Fix Up Logic - rButtock if nodecntr == 24: newval = float(val) + 2 if nodecntr == 23: newval = float(val) + 12 if nodecntr == 22: newval = float(val) + 30 #Fix Up Logic - rThigh if nodecntr == 27: newval = float(val) + 1 if nodecntr == 26: newval = float(val) - 14 if nodecntr == 25: newval = float(val) - 32 #Fix Up Logic - rShin if nodecntr == 30: newval = float(val) + 4 if nodecntr == 29: newval = float(val) - 2 if nodecntr == 28: newval = float(val) + 4 #Fix Up Logic - rFoot if nodecntr == 33: newval = float(val) - 6 if nodecntr == 32: newval = float(val) + 1 if nodecntr == 31: newval = float(val) - 19 #Fix Up Logic - rToe if nodecntr == 36: newval = float(val) if nodecntr == 35: newval = float(val) if nodecntr == 34: newval = float(val) strout = strout + str(newval) + " " else: val = strin[begpos:] nodecntr = nodecntr + 1 strout = strout + str(val) #print 'number of nodes= ', nodecntr break
if counter == 200: print 'strin = ', strin print 'strout = ', strout
outBVH.write(strout)
inBVH.close() outBVH.close()
print '------- Completed BVH Fixup -------'
def main(): print '+++++++++++ BVH Fix Up Start ++++++++++++++++++++++' inBVHName = "" outBVHName = "" argcntr = 0
for arg in sys.argv: argcntr = argcntr + 1 print 'arg = ', arg if argcntr == 2: inBVHName = arg #should be file name if argcntr == 3: outBVHName = arg #should be file name
print 'inBVHName= ', inBVHName print 'outBVHName= ', outBVHName BVHFixUp(inBVHName, outBVHName)
print '+++++++++++++++++ BVH Fix Up End ++++++++++++++++'
main() |