#!usr/bin/python ##################################################### # Author: Kenneth Stojevich # # Program: Maya to Renderman command line script. # # This script takes in an array of arguments # # from the command line and then execute the # # command line version of Pixar's Renderman to # # render out a Maya scene. # # Date: 03/11/2006 # ##################################################### # Import the required modules needed for the script import getopt, sys, re, os, commands ################################################# # The MTOR class which will setup and execute # # everything we need to u do basic Renderman # # functions. # ################################################# class MTOR: ################################################# # Initializer function to setup defaults for # # the MTOR class. # ################################################# def __init__(self): self.RENDERMODE = 0 self.firstFrame = 1 self.lastFrame = 10 self.numFrames = self.lastFrame - self.firstFrame self.blurFactor = 0 self.image = "" self.imageDir = "" self.directory = "/home/prMan/images" self.display = "it" self.camera = "perspective" self.scene = "" ################################################# # Sets up the all the required elements of this # # class with the arguments passed in from the # # main. # ################################################# def setupMTOR(self, arguments=[]): if (len(arguments) == 0): print self.helpMe() sys.exit() try: opts, args = getopt.getopt(arguments, "hd:rf:l:b:i:c:p:", ["help", "display=", "render", "first=", "last=", "blur=", "image", "camera=", "display="]) except getopt.GetoptError: self.helpMe() sys.exit() for o, a in opts: if (o == "-h" or o == "--help"): self.helpMe() sys.exit() elif (o == "-r" or o == "--render"): self.RENDERMODE = 1 elif (o == "-f" or o == "--first"): self.firstFrame = a elif (o == "-l" or o == "--last"): self.lastFrame = a self.lastFrame = int(self.lastFrame) - int(self.firstFrame) elif (o == "-b" or o == "--blur"): self.blurFactor = a elif (o == "-p" or o == "--display"): self.display = a elif (o == "-c" or o == "--camera"): self.camera = a elif (o == "-i" or o == "--image"): self.image = a self.dirInfo = os.path.split(self.image) self.imageDir = self.dirInfo[0] self.image = self.dirInfo[1] self.directory = self.imageDir + "/" + self.image + "/" self.validateImageDir() self.scene = sys.argv.pop() if (self.scene == ""): self.helpMe() sys.exit() ################################################# # Help function to display basic terminology and# # assistance for the user if something is given # # incorrectly or they just want help. # ################################################# def helpMe(self): print "Command options: [-d] [-r] [-f] [-l] [-b] [-p] [-i] [-s] [-h]" print " [--dir] [--render] [--first] [--last] [--blur] [--display] [--image] [--show] [--help]" print "" print "USAGE: [-d] [--dir] Set directory to store RIBs in" print " [-r] [--render] Render the scene" print " [-f] [--first] First frame (ex: 1)" print " [-l] [--last] Last frame (ex: 10)" print " [-b] [--blur] Add motion blur to scene (ex: 300)" print " [-i] [--image] Image to render to (ex: \\dir\\myImage.tif)" print " [-p] [--display] Set display type" print " Display types possible: it, framebuffer, file, tiff, openexr, alias, mayaiff" print " targa, sgif, picio, softimage. Default is \"it\"" print " [-s] [--show] Show the images rendered in IT" print " [-c] [--camera] Camera to render to (ex: myCam)" print " [-h] [--help] You are reading it right now" print "" print "Example of use: " print 'MTOR RIB Gen: python Main.py -r -f 1 -l 5 -i /home/images light2.mb' print "" print 'Render Scene: python Main.py -r -r -f 1 -l 5 -b 180 -r -i /home/images light2.mb' ################################################# # Verify the directory the user gave and if not # # it creates it. # ################################################# def validateImageDir(self): # See if the directory exists if (os.path.exists(self.imageDir)): # directory exists print "Directory exists" else: # Create directory if it doesn't exist os.mkdir(self.imageDir) print "Directory created: " + self.imageDir ################################################# # Generate the RIBs # ################################################# def MTORBatch(self): print self.scene batch = "mtor -scene " + self.scene + " -cmd projDir " + self.directory + " -cmd rg dspyName " + self.image + " -cmd genWorklist " + str(self.firstFrame) + " " + self.camera + " " + str(self.lastFrame) batchThis = 'echo "setenv PATH /opt/pixar/rat-6.5.1-maya7.0/bin; ' + batch + '" | tcsh' print batchThis print batch mayaFile = commands.getoutput('echo "setenv PATH /opt/pixar/rat-6.5.1-maya7.0/bin; ' + batch + '" | tcsh') print mayaFile ################################################# # Render the scene. # ################################################# def MTORRender(self): renderScene = "" if (self.blurFactor > 0): renderScene = "mtor -scene " + self.scene + " -wsroot " + self.directory + " -cmd rg dspyServer " + self.display + " -cmd rg dspyName " + self.image + " -cmd rg doMotionBlur 1 -cmd rg shutterAngle " + self.blurFactor + " -cmd render " + self.directory + "\*.\*" + str(self.firstFrame) + ".rib " + str(self.lastFrame) else: renderScene = "mtor -scene " + self.scene + " -wsroot " + self.directory + " -cmd rg dspyServer " + self.display + " -cmd rg dspyName " + self.image + " -cmd render " + self.directory + "\*.\*" + str(self.firstFrame) + ".rib " + str(self.lastFrame) print renderScene self.MTORBatch() renderThis = 'echo "setenv PATH /opt/pixar/rat-6.5.1-maya7.0/bin; ' + renderScene + '" | tcsh' print renderThis mayaRender = commands.getoutput('echo "setenv PATH /opt/pixar/rat-6.5.1-maya7.0/bin; ' + renderScene + '" | tcsh') print mayaRender return 0 ################################################# # Execute the script. # ################################################# def execute(self): if (self.RENDERMODE == 0): self.MTORBatch() else: self.MTORRender()