What I am currently working on today...
# TOM ROWELL - TRAFFIK PYTHON PROTOTPYEimport maya.cmds as cmds #REMEMBER TO UNCOMMENT FOR MAYA TESTING!!import time, schedvehicles = []sceneLength = 0timeIncrement = 0.0sceneFPS = 0class Vehicle:id = 0type = 'unused'currentPath = 0nextPath = 0geometryObject = '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 lineexec("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 additionsdef testVariables():global currentPathprint ("Test variable is: " + str(currentPath))def initVehicle( x ):global vehiclesnewV = Vehicle()newV.id = xvehicles.extend([newV]) # add a new vehicle to the end of the listdef findVehicle( x ):global vehiclesfor v in vehicles:if v.id == x: return vdef getSceneLength():global sceneLengthglobal sceneFPSsceneLength = cmds.playbackOptions( query = True, maxTime = True ) # get max length of scenesceneFPS = cmds.currentUnit( query = True, time = True ) # get fps of sceneif sceneFPS == "game": sceneFPS = 15.0if sceneFPS == "film": sceneFPS = 24.0if sceneFPS == "pal": sceneFPS = 25.0if sceneFPS == "ntsc": sceneFPS = 30.0if sceneFPS == "show": sceneFPS = 48.0if sceneFPS == "palf": sceneFPS = 50.0if sceneFPS == "ntscf": sceneFPS = 60.0sceneLength = sceneLength / sceneFPS # generate scene time in secondsreturn sceneLength # return scene time in secondsdef 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 * 100print ("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 sceneFPSglobal timeIncrementtimeIncrement = sceneFPS / 100newSceneTime = cmds.currentTime(query = True) + timeIncrementprint newSceneTimecmds.currentTime( newSceneTime, edit = True)print "\nAdding a bit!"def printTime():currentTime = time.strftime("%H:%M:%S", time.gmtime())print currentTimegetSceneLength()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