#!/usr/bin/python # Simon Bunker # June 2008 import sys, os from optparse import OptionParser from cgkit.ri import * def isRIB(x): return x.endswith(".rib") # only handles horizontal fill, square pixels def getScreenWindow(width, height): aspectRatio = float(height) / float(width); RiScreenWindow(-1, 1, -aspectRatio, aspectRatio) def ribgen(basepath, width, height): for frame in range(1,360): filename = "teapot.%04d" % frame RiBegin(basepath+"/"+filename+".rib") RiFrameBegin(frame) RiFormat(width, height,1.0) getScreenWindow(width, height) RiProjection(RI_PERSPECTIVE, fov=45) RiDisplay(basepath+"/"+filename+".tif", RI_FILE, RI_RGB) RiShadingRate(1) RiPixelSamples(2, 2) RiWorldBegin() RiTransform ([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ]) RiTranslate(0,-1, 2) RiRotate(-20, 1, 0, 0) # distant global light RiTransformBegin RiConcatTransform ([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]) RiLightSource("distantlight", intensity=1.2, lightcolor=(1, 1, 1)) RiTransformEnd # ambient light RiTransformBegin RiConcatTransform ([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]) RiLightSource("ambientlight", intensity=0.504043, lightcolor=(1, 1, 1 )) RiTransformEnd RiAttributeBegin() RiColor([1,0,0]) RiSurface("plastic") RiRotate(frame, 0, 1, 0) RiRotate(-90, 1, 0, 0) RiGeometry("teapot") RiAttributeEnd() RiWorldEnd() RiFrameEnd() RiEnd() def render(basepath): for ribfile in filter( isRIB, sorted(os.listdir(basepath))): os.system("/usr/bin/lp "+os.path.abspath(ribfile)) if __name__ == "__main__": basepath = os.getcwd() parser = OptionParser() parser.add_option("-g", "--generate", action="store_true", dest="ribgen", help="Generate teapot turntable RIB files.") (opts, args) = parser.parse_args() if opts.ribgen is True: ribgen(basepath, 320, 240) else: render(basepath)