About Me

BSc 3D Computer Animation student, currently at SMU in Wales. Love 3D obviously, as well as digital painting, video/film, photography, special effects... the list goes on. Need to know anything else, just e-mail me!

Thursday 3 March 2011

What I am currently working on today...


# TOM ROWELL - TRAFFIK PYTHON PROTOTPYE
import maya.cmds as cmds #REMEMBER TO UNCOMMENT FOR MAYA TESTING!!
import time, sched
vehicles = []
sceneLength = 0
timeIncrement = 0.0
sceneFPS = 0

class Vehicle:

id = 0
type = 'unused'
currentPath = 0
nextPath = 0
geometryObject = 'unused'
motionPath = 'unused'
ADL1 = 'unused'
ADL2 = 'unused'
ADL3 = 'unused'

def __init__(self):
self.geometryObject = cmds.polyCube()
for x in range(1, 4):
currentNode = cmds.createNode('addDoubleLinear')
exec("self.ADL" + str(x) + " = currentNode")

exec("cmds.connectAttr( \'" + self.ADL1 + ".output\', \'" + self.geometryObject[0] + ".translateX\')")
exec("cmds.connectAttr( \'" + self.ADL2 + ".output\', \'" + self.geometryObject[0] + ".translateY\')")
exec("cmds.connectAttr( \'" + self.ADL3 + ".output\', \'" + self.geometryObject[0] + ".translateZ\')")

exec("cmds.connectAttr( \'" + self.geometryObject[0] + ".transMinusRotatePivotX\', \'" + self.ADL1 + ".input1\')")
exec("cmds.connectAttr( \'" + self.geometryObject[0] + ".transMinusRotatePivotY\', \'" + self.ADL2 + ".input1\')")
exec("cmds.connectAttr( \'" + self.geometryObject[0] + ".transMinusRotatePivotZ\', \'" + self.ADL3 + ".input1\')")

self.motionPath = cmds.createNode('motionPath')
exec("cmds.setAttr(\'" + self.motionPath + ".fractionMode\', 1)")
exec("cmds.connectAttr(\'" + self.motionPath + ".xCoordinate\', \'" + self.ADL1 + ".input2\')")
exec("cmds.connectAttr(\'" + self.motionPath + ".yCoordinate\', \'" + self.ADL2 + ".input2\')")
exec("cmds.connectAttr(\'" + self.motionPath + ".zCoordinate\', \'" + self.ADL3 + ".input2\')")

def queryVehicle(self):
print ("\n==Current Vehicle Query==")
print ("ID: " + str(self.id))
print ("Type: " + self.type)
print ("Geo Obj: " + str(self.geometryObject[0]))
print ("ADL1: " + self.ADL1)
print ("ADL2: " + self.ADL2)
print ("ADL3: " + self.ADL3)
print ("==END OF VEHICLE QUERY==\n")

def attachToPath(self, path):
print ("Attaching to path on curve \'" + path + "\'") # debug line
exec("cmds.setAttr(\'" + self.motionPath + ".uValue\', 0)")
exec("cmds.connectAttr(\'" + path + ".worldSpace[0]\', \'" + self.motionPath + ".geometryPath\')")
exec("cmds.connectAttr(\'" + self.motionPath + ".message\', \'" + self.geometryObject[0] + ".specifiedManipLocation\')")
exec("cmds.connectAttr(\'" + self.motionPath + ".rotateOrder\', \'" + self.geometryObject[0] + ".rotateOrder\')")
exec("cmds.connectAttr(\'" + self.motionPath + ".rotateX\', \'" + self.geometryObject[0] + ".rotateX\')")
exec("cmds.connectAttr(\'" + self.motionPath + ".rotateY\', \'" + self.geometryObject[0] + ".rotateY\')")
exec("cmds.connectAttr(\'" + self.motionPath + ".rotateZ\', \'" + self.geometryObject[0] + ".rotateZ\')")

# reserved for future additions

def testVariables():
global currentPath
print ("Test variable is: " + str(currentPath))

def initVehicle( x ):
global vehicles
newV = Vehicle()
newV.id = x
vehicles.extend([newV]) # add a new vehicle to the end of the list

def findVehicle( x ):
global vehicles
for v in vehicles:
if v.id == x: return v

def getSceneLength():
global sceneLength
global sceneFPS
sceneLength = cmds.playbackOptions( query = True, maxTime = True ) # get max length of scene
sceneFPS = cmds.currentUnit( query = True, time = True ) # get fps of scene
if sceneFPS == "game": sceneFPS = 15.0
if sceneFPS == "film": sceneFPS = 24.0
if sceneFPS == "pal": sceneFPS = 25.0
if sceneFPS == "ntsc": sceneFPS = 30.0
if sceneFPS == "show": sceneFPS = 48.0
if sceneFPS == "palf": sceneFPS = 50.0
if sceneFPS == "ntscf": sceneFPS = 60.0
sceneLength = sceneLength / sceneFPS # generate scene time in seconds
return sceneLength # return scene time in seconds

def runSimulation(simLength):
cmds.currentTime( 0.0, edit = True)
printTime()
print ("Running a " + str(simLength) + " second length simulation\n")
simCounter = sched.scheduler(time.time, time.sleep)
runTime = simLength * 100
print ("This equals " + str(runTime) + "centiseconds\n")
printTime()
for x in range(0, runTime):
simCounter.enter(0.01, 1, doSim, ())
simCounter.run()
printTime()

def doSim():
global sceneFPS
global timeIncrement
timeIncrement = sceneFPS / 100
newSceneTime = cmds.currentTime(query = True) + timeIncrement
print newSceneTime
cmds.currentTime( newSceneTime, edit = True)
print "\nAdding a bit!"


def printTime():
currentTime = time.strftime("%H:%M:%S", time.gmtime())
print currentTime

getSceneLength()
runSimulation(getSceneLength())

# === everything beneath this line is testing related ====

# initVehicle(1)
# findVehicle(1).queryVehicle()
# findVehicle(1).attachToPath('curve1')

# initVehicle(2)
# findVehicle(2).queryVehicle()
# findVehicle(2).attachToPath('curve2')


# mass creation testing - comment out between tests

No comments:

Post a Comment