[cgkit-commits] cgkit2 render.py,1.7,1.8 changelog.txt,1.55,1.56
Brought to you by:
mbaas
From: Matthias B. <mb...@us...> - 2005-10-16 12:31:54
|
Update of /cvsroot/cgkit/cgkit2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24363 Modified Files: render.py changelog.txt Log Message: Added support for tiled rendering. Index: changelog.txt =================================================================== RCS file: /cvsroot/cgkit/cgkit2/changelog.txt,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** changelog.txt 7 Oct 2005 15:48:04 -0000 1.55 --- changelog.txt 16 Oct 2005 12:31:45 -0000 1.56 *************** *** 8,14 **** --- 8,27 ---- - New module stitch.py that can stitch together images that were rendered with RiCropWindow(). The file can also be used as a command line utility. + - render.py: An image can now be rendered in tiles by specifying the + global 'tiles' parameter. The output image is automatically stitched + back together. Note: Currently, this feature is only meant to be used + with renders that only contain one frame block which outputs an image + (i.e. the tiling will not be applied on shadow maps and any map generation + pass will be done again for each tile). + - RIBExport: The Globals section can have a 'rib' parameter containing raw + RIB requests. This string is added to the output RIB stream before the + frames. + - RIBExport: The output parameter can also contain a list of output specifiers + (i.e. containing the parameters for RiDisplay() calls). Bug fixes/enhancements: + - RIBExport: The pixel filter can now be set via a global option. + - ri.py: Speedup when processing parameter lists that contain vec3 objects. - ri.py: Floats are now written using str() instead of repr(), this means they are often shorter (e.g. 0.1 instead of 0.10000000000000001). Index: render.py =================================================================== RCS file: /cvsroot/cgkit/cgkit2/render.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** render.py 20 Sep 2005 13:40:07 -0000 1.7 --- render.py 16 Oct 2005 12:31:45 -0000 1.8 *************** *** 24,28 **** """Render tool.""" ! import sys, os, optparse, glob, time from cgkit.ri import * from cgkit.riutil import * --- 24,28 ---- """Render tool.""" ! import sys, os, os.path, optparse, glob, time from cgkit.ri import * from cgkit.riutil import * *************** *** 33,36 **** --- 33,37 ---- from cgkit.cmds import * from cgkit.tool import Tool + from cgkit import stitch *************** *** 44,47 **** --- 45,135 ---- + # RenderManager + class RenderManager: + """Process rendering jobs. + """ + + def __init__(self): + """Constructor. + """ + pass + + # render + def render(self, renderer, workingdir, rib, tiles=None, outname=None, callback=None): + """Queue a render job. + + renderer: Rendering tool set + workingdir: Change into this dir before rendering + rib: The RIB file (relative to workingdir) + tiles: Tile specification for rendering in tiles + outname: Output file name + callback: Gets called when the job is done + + If an image is rendered in tiles the rib file must not contain + any RiDisplay() calls (unless they only append to the list of + devices). This is because the output file name has to be modified + so that there is no name clash for the individual tiles. + + Return value: Job id + """ + renderer, slcompiler, textool = renderers[renderer] + # Store the current directory + prev_dir = os.getcwd() + # Change to the working directory + workingdir = os.path.abspath(workingdir) + os.chdir(workingdir) + + # Render... + if tiles==None: + tiles = ((),()) + + xsplits = [0.0]+list(tiles[0])+[1.0] + ysplits = [0.0]+list(tiles[1])+[1.0] + numtiles = (len(xsplits)-1)*(len(ysplits)-1) + for j in range(len(ysplits)-1): + for i in range(len(xsplits)-1): + options = [] + tileout = None + RiBegin(renderer) + # Render in tiles? then add the -crop option + if numtiles>1: + x1,x2 = xsplits[i],xsplits[i+1] + y1,y2 = ysplits[j],ysplits[j+1] + options += ["-crop %s %s %s %s"%(x1,x2,y1,y2)] + RiCropWindow(x1,x2,y1,y2) + n,e = os.path.splitext(outname) + tileout = "%s_%s_%s_%s_%s%s"%(n,x1,x2,y1,y2,e) + mode = getScene().getGlobal("displaymode", RI_RGB) + RiDisplay(tileout, RI_FILE, mode) + # cmd = " ".join(["%s"%renderer]+options+["%s"%rib]) + # print cmd + # sys.stdout.flush() + # Invoke the renderer + # os.system(cmd) + if numtiles>1: + n = j*(len(xsplits)-1)+i+1 + print "Rendering tile %d/%d..."%(n,numtiles) + sys.stdout.flush() + RiReadArchive("main.rib") + RiEnd() + + # Stitch the tiles... + if numtiles>1: + print "Stitching..." + try: + stitch.stitch(outname, removetiles=True, infostream=sys.stdout) + except IOError, e: + print "ERROR:",e + + # Restore the current directory... + os.chdir(prev_dir) + + if callback!=None: + callback() + + return 1 + + + class RenderException(Exception): pass *************** *** 88,100 **** while 1: print 'Exporting %s...'%ribname t1 = time.time() framenr = int(round(timer.frame)) # Determine output name ! if self.time_end==None: ! outname = output ! else: ! name, ext = os.path.splitext(output) ! outname = "%s%04d%s"%(name, framenr, ext) # Determine the model to bake... --- 176,186 ---- while 1: print 'Exporting %s...'%ribname + sys.stdout.flush() t1 = time.time() framenr = int(round(timer.frame)) # Determine output name ! if self.time_end!=None: ! output = self.appendFrameNr(output, framenr) # Determine the model to bake... *************** *** 110,118 **** print "Please specify a bake model using the 'bakemodel' global" sys.exit(1) ! # Create RIB & shaders save(ribname, camera = self.cam, ! output = outname, output_framebuffer = (self.time_end==None), bake = self.options.bake, --- 196,211 ---- print "Please specify a bake model using the 'bakemodel' global" sys.exit(1) ! ! # Render in tiles? ! tiles = scene.getGlobal("tiles", None) ! if tiles==None: ! _output = output ! else: ! _output = None ! # Create RIB & shaders save(ribname, camera = self.cam, ! output = _output, output_framebuffer = (self.time_end==None), bake = self.options.bake, *************** *** 124,127 **** --- 217,221 ---- if os.path.exists("shaders"): print "Compiling shaders..." + sys.stdout.flush() oldpath = os.getcwd() os.chdir("shaders") *************** *** 133,141 **** # Render print 'Rendering "%s" (frame %d)...'%(outname, framenr) ! os.system("%s %s"%(renderer, ribname)) t3 = time.time() print "Rendering time:",self.time2str(t3-t2) # Increase time --- 227,244 ---- # Render + outname = self.outputName(output) print 'Rendering "%s" (frame %d)...'%(outname, framenr) ! sys.stdout.flush() ! rendermgr = RenderManager() ! rendermgr.render(renderer = self.options.renderer, ! workingdir = ".", ! rib = ribname, ! tiles = tiles, ! outname = outname) ! # os.system("%s %s"%(renderer, ribname)) t3 = time.time() print "Rendering time:",self.time2str(t3-t2) + sys.stdout.flush() # Increase time *************** *** 146,149 **** --- 249,304 ---- break + # appendFrameNr + def appendFrameNr(self, output, framenr): + """Append the frame number to all outputs. + + The return value is the same than output except that the file names + have an appended frame number. + """ + # No output? + if output==None: + return None + # Is output a string? (i.e. the output file name) + elif isinstance(output, types.StringTypes): + return self._appendFrameNr(output, framenr) + # User specified output specs? (output must already be a list + # of specs) + else: + res = [] + for name,type,mode,params in output: + name = self._appendFrameNr(name,framenr) + res.append((name,type,mode,params)) + return res + + # _appendFrameNr + def _appendFrameNr(self, filename, framenr): + """Append the frame number to a file name. + + Returns the new file name. + """ + name, ext = os.path.splitext(filename) + return "%s%04d%s"%(name, framenr, ext) + + # outputName + def outputName(self, output): + """Return the output file name. + + output is the 'output' parameter. + """ + # No output? + if output==None: + return "" + # Is output a string? (i.e. the output file name) + elif isinstance(output, types.StringTypes): + return output + # User specified output specs? (output must already be a list + # of specs) + else: + if len(output)>0: + return output[0][0] + else: + return "" + + # compileSL def compileSL(self, slcompiler): |