13.1.1.1 The IGeometry protocol

Every GeomObject that supports the IGeometry protocol can be exported as RIB. If the geometry does not support the protocol it will be ignored.

The IGeometry protocol only specifies the presence of one method:

render( matid)
Creates Ri geometry requests for the geometry that has the material with id matid assigned to it. The geometry should be created in the local coordinate system of the GeomObject. The primitive variables should also be exported. The method can assume that there is already an enclosing RiAttributeBegin()/RiAttributeEnd() block around the call.

Here is an example of an adapter class that implements the IGeometry protocol for the SphereGeom (which knows nothing about RenderMan):

import protocols
from ri import *

# Adapter class that implements the IGeometry protocol on behalf of the SphereGeom class
class SphereAdapter:

    protocols.advise(instancesProvide=[IGeometry], asAdapterForTypes=[SphereGeom])
    
    def __init__(self, spheregeom, proto):
        self.geom = spheregeom

    def render(self, matid):
        # A sphere can only have one single material
	if matid==0:
            r = self.geom.radius
            RiSphere(r, -r, r, 360)