4.4 cri -- RenderMan binding for direct access to a renderer

The cri module is an alternative version of the ri module that uses the Python ctypes module to interface a renderer directly. The ctypes module is a foreign function library that is part of the standard Python libraries since Python 2.54.1. With previous versions of Python, the module has to be installed separately. The module can be used in combination with any renderer that implements the RenderMan API in a shared library. Using this module instead of the ri module has a number of advantages:

The disadvantage of using this module is that it depends on an external dynamic library that must implement the actual functionality. This means if you have not installed a renderer that ships with such a library you cannot use the module.

Before any RenderMan function can be used, a library has to be loaded using the loadRI() function. The returned module-like object can then be used just like the ri module.

loadRI( libName)
Load a RenderMan library and return a module-like handle to it. libName is the name of a shared library that implements the RenderMan interface. The name can either be an absolute file name or just the name of the library (without suffix or "lib" prefix) in which case the function tries to find the library file itself. The return value is an object that can be used like a module, i.e. it contains all RenderMan functions, constants, etc. If libName is None or the empty string, the return value is just a reference to the ri module.

import cgkit.cri

ri = cgkit.cri.loadRI("3delight")

ri.RiBegin(ri.RI_NULL)
ri.RiWorldBegin()
ri.RiSurface("plastic")
ri.RiSphere(1,-1,1,360)
ri.RiWorldEnd()
ri.RiEnd()

The RenderMan function names can either be used with or without the "Ri" prefix. So the following is equivalent to the above:

ri.Begin(ri.RI_NULL)
ri.WorldBegin()
ri.Surface("plastic")
ri.Sphere(1,-1,1,360)
ri.WorldEnd()
ri.End()

The following table lists the library names for some renderers that are known to work with this module:

Renderer Library Name
3Delight 3delight
Aqsis aqsislib / ri2rib
Pixie ri

importRINames( ri, ns)
Import the RenderMan names into the given namespace. ri is the module-like object that was returned by loadRI() and ns is a dictionary containing a module namespace (such as globals()) that will receive the "imported" symbols. Only the names with the "Ri" prefix will be available. Example:

ri = cgkit.cri.loadRI("3delight")
cgkit.cri.importRINames(ri, globals())

RiBegin(RI_NULL)
RiWorldBegin()
RiSurface("plastic")
RiSphere(1,-1,1,360)
RiWorldEnd()
RiEnd()



Footnotes

... 2.54.1
Python 2.5 is embedded in Maya 2008 and Houdini 9, whereas Maya 8.5 still uses Python 2.4.



Subsections