def move(ipo, origin, destination, startframe, framespan, proxob, xdir, xdist, forward):
# ipo - what ipo to write points to origin - the location (3Dpoint) to start at
# destination - the location to end up at startframe - frame to set the first curvepoint at
# framespan - total number of frames for the move proxob - the proxy/reference object
# xdir - pos or neg offset along proxy X-axis xdist - how much to offset along proxy X-axis
writeCurvePoint(ipo, startframe, origin)
if AL==1 or origin!=destination:
# Write curvepoints for LiftPeak and LiftPeakTime:
# Pretty hackish formulae for proxyTime here... But they do work, so wtf...
lpProxyTime = startframe + (LPT*framespan*2)-framespan*0.25
lpRealTime = startframe+(framespan+MSD)*LPT
lpLocation = getElevation(proxob, lpProxyTime, LA, LP, xdir, xdist, forward)
writeCurvePoint(ipo, lpRealTime, lpLocation)
# Write curvepoints for MidPeak and MidPeakTime:
mpProxyTime = startframe + (MPT*framespan*2)-framespan*0.25
mpRealTime = startframe+(framespan+MSD)*MPT
mpLocation = getElevation(proxob, mpProxyTime, LA, MP, xdir, xdist, forward)
writeCurvePoint(ipo, mpRealTime, mpLocation)
# Write curvepoints for FinalPeak and FinalPeakTime:
fpProxyTime = startframe + (FPT*framespan*2)-framespan*0.25
fpRealTime = startframe+(framespan+MSD)*FPT
fpLocation = getElevation(proxob, fpProxyTime, LA, FP, xdir, xdist, forward)
writeCurvePoint(ipo, fpRealTime, fpLocation)
writeCurvePoint(ipo, startframe+framespan+MSD, destination)
return (startframe+framespan, destination)
def hold(ipo, location, startframe, framespan):
# ipo - what ipo to write points to # location - the position (3Dpoint) to hold at
# startframe - the first frame in the hold sequence # framespan - total number of frames to hold
writeCurvePoint(ipo, startframe+MSD, location)
writeCurvePoint(ipo, startframe+framespan, location)
return (startframe+framespan, location)
def recalculator(assignedTargets, targ1, targ2, basetarg):
# rewrites some globals based on the current arrangement of the empties:
loc1 = targ1.getLocation()
loc2 = targ2.getLocation()
loc3 = basetarg.getLocation()
# HEEL_SEPARATION:
if assignedTargets=='heels':
print 'Default heel empties found. Recalculating:'
global HS
HS = dist3(loc1, loc2)
print 'HEEL_SEPARATION set to',HS
if assignedTargets=='flats':
print 'Default foot look-at targets found. Reusing.'
global HEEL_TO_FLAT_DISTANCE
HEEL_TO_FLAT_DISTANCE = dist3(loc2, loc3)
print 'HEEL_TO_FLAT_DISTANCE set to', HEEL_TO_FLAT_DISTANCE
if assignedTargets=='tlats':
print 'Default toe look-at targets found. Reusing.'
global FLAT_TO_TLAT_DISTANCE
FLAT_TO_TLAT_DISTANCE = dist3(loc2, loc3)
print 'FLAT_TO_TLAT_DISTANCE set to',FLAT_TO_TLAT_DISTANCE
def doIt(forwardOffset, addCenter, whatsUp, firstName, secondName):
print
print 'Currently processing:',whatsUp
# Start building the IPO for the right foot:
ffootipo = makeIPO('rfoot', 'Linear', 'Constant')
cpf = currentProxyFrame = FF
# make first step (only half as far as the others):
ffootloc = getOffset(proxy, cpf, 1, HS/2, forwardOffset)
ffootframe = cpf
targetloc = getOffset(proxy, cpf+MT, 1, HS/2, forwardOffset)
ffootframe, ffootloc = move(ffootipo, ffootloc, targetloc, ffootframe, MT/2,proxy, 1, HS/2, forwardOffset)
ffootframe, ffootloc = hold(ffootipo, ffootloc, ffootframe, LT)
# now make the rest of the steps (full length):
done = 0
while not done:
cpf += CT
targetloc = getOffset(proxy, cpf+MT, 1, HS/2, forwardOffset)
ffootframe, ffootloc = move(ffootipo, ffootloc, targetloc, ffootframe, MT,proxy, 1, HS/2, forwardOffset)
ffootframe, ffootloc = hold(ffootipo, ffootloc, ffootframe, LT)
if cpf>LF:
done=1
# Then we'll build the IPO for the left foot:
sfootipo = makeIPO('lfoot', 'Linear', 'Constant')
cpf = currentProxyFrame = FF
# this one starts in hold-mode (waits for right foot to finish)
sfootloc = getOffset(proxy, cpf, -1, HS/2, forwardOffset)
sfootframe = cpf
sfootframe, sfootloc = hold(sfootipo, sfootloc, cpf, MT/2)
done = 0
while not done:
cpf += CT
targetloc = getOffset(proxy, cpf, -1, HS/2, forwardOffset)
sfootframe, sfootloc = move(sfootipo, sfootloc, targetloc, sfootframe, MT,proxy, -1, HS/2, forwardOffset)
sfootframe, sfootloc = hold(sfootipo, sfootloc, sfootframe, LT)
if cpf>LF:
done=1
if addCenter:
# And to finish it off, let's put something in the middle of this:
# This will simply add a third target floating above the proxy.
# It will respect the specified lift axis, hence useful as parent for an armature
ctargetipo = makeIPO('center', 'Linear', 'Constant')
for cframe in range(FF, LF):
targetloc = getLiftAxisOffset(proxy, cframe, CTDLA, CTD)
writeCurvePoint(ctargetipo, cframe, targetloc)
# Finished. Add or reuse empties and link them to their respective IPOblocks.
leftikt = TryGetObject(firstName)
leftnew = 0
if leftikt==None:
leftikt = Object.New('Empty')
leftnew = 1
rightikt = TryGetObject(secondName)
rightnew = 0
if rightikt==None:
rightikt = Object.New('Empty')
rightnew = 1
leftikt.name = firstName
rightikt.name = secondName
print 'Targets',leftikt,rightikt
if addCenter:
centertarget = TryGetObject(TARGET_CENTRE)
centernew = 0
if centertarget==None:
centertarget = Object.New('Empty')
centernew = 1
centertarget.name = TARGET_CENTRE
print 'Centertarget',centertarget
centertarget.Layer = Layer
if centernew:
scene.link(centertarget)
#MDR: 'SetIPO' was 'link'...
centertarget.setIpo(ctargetipo)
leftikt.Layer = Layer
rightikt.Layer = Layer
if leftnew:
scene.link(leftikt)
if rightnew:
scene.link(rightikt)
#MDR: Ditto... 'setIpo' was 'link'...
leftikt.setIpo(sfootipo)
rightikt.setIpo(ffootipo)
print whatsUp,'IPO:s',sfootipo,ffootipo
print '---------------------------------------------------------'
sys.stdout.flush()
#########################################
# if everything's OK, let's get to work #
#########################################
if status=='OK':
currentUserFrame = scene.getRenderingContext().currentFrame()
# grab any walkomat empties left in the scene:
oldleftheel =TryGetObject(HEEL_LEFT)
oldrightheel =TryGetObject(HEEL_RIGHT)
oldleftflat =TryGetObject(FLAT_LEFT)
oldrightflat =TryGetObject(FLAT_RIGHT)
oldlefttlat =TryGetObject(TLAT_LEFT)
oldrighttlat=TryGetObject(TLAT_RIGHT)
emptyipo = makeIPO('emptydummy', 'Linear', 'Constant')
# recalculate if there were any such empties:
if oldleftheel!=None and oldrightheel!=None:
# assign an empty IPO first to clear any anim:
# why isn't there some 'unlink' function somewhere???
#
# MDR: These 'setIpo' calls were 'link' ....
#
oldleftheel.setIpo(emptyipo)
oldrightheel.setIpo(emptyipo)
recalculator('heels', oldleftheel, oldrightheel, oldrightheel)
if oldleftflat!=None and oldrightflat!=None:
oldleftflat.setIpo(emptyipo)
oldrightflat.setIpo(emptyipo)
recalculator('flats', oldleftflat, oldrightflat, oldrightheel)
if oldlefttlat!=None and oldrighttlat!=None:
oldlefttlat.setIpo(emptyipo)
oldrighttlat.setIpo(emptyipo)
recalculator('tlats', oldlefttlat, oldrighttlat, oldrightflat)
# first pass, heel targets:
doIt(0, 1, 'Heel targets', HEEL_LEFT, HEEL_RIGHT)
#second pass, foot look-at targets:
LP = FLATLP
MP = FLATMP
FP = FLATFP
doIt(HEEL_TO_FLAT_DISTANCE, 0, 'Foot look-at targets', FLAT_LEFT, FLAT_RIGHT)
#third pass, toe look-at targets:
LP = TLATLP
MP = TLATMP
FP = TLATFP
doIt(HEEL_TO_FLAT_DISTANCE+FLAT_TO_TLAT_DISTANCE, 0, 'Toe look-at targets', TLAT_LEFT, TLAT_RIGHT)
# At last, as a friendly gesture, restore the frame to whatever the user
# was looking at before running the script, and refresh the screens:
scene.getRenderingContext().currentFrame(currentUserFrame)
Window.RedrawAll()
print 'Processing completed.'
print 'Thank you for using Walk-O-Matic :D'
sys.stdout.flush()
###################################################
# if things are not right, print some dying words:#
###################################################
if status!='OK':
print ''
print 'Walk-o-matic is sadly forced to report that'
print 'it could not go to work properly.'
print 'Cause of termination: ',status
print 'Please consult the documentation regarding proper use.'
sys.stdout.flush()