This tutorial proceeds, step-by-step, in demonstrating the development of several rifs that augment and/or replace polymesh objects in a Maya scene.
1. Set a project directory, say, maya/projects/default.
Basic PolyMesh Rif
Lisitng 1 provides a barebones python script that implements a rif that will pre-process the polygonal data of each mesh object. The method named "PointsGeneralPolygons" is implemented by the prman.Rif class. Since our custom class is derived from Pixar's prman.Rif class our custom class can override the base class implementation of the "PointsGeneralPolygons" method.
Listing 1 - rif_mesh_geo1.py
Before tinkering with the implementation of "PointsGeneralPolygons" method
we must ensure the customized batch rendering scripts provided in the tutorial
RfM 23: Customizing can apply our custom rifs.
import batch import rif_mesh_geo1 reload(rif_mesh_geo1) rifs = ['rif_it','rif_mesh_geo1' ] batch.render(1,1, rifs)
3. An image similar to figure 1 should appear in the Image Tool ("it") window.
Most of the data that our rifs will use is contained in the python dictionary
of the last arg of the PointsGeneralPolygons method, namely,
The "params" Dictionary
We will begin by printing the keys of the dictionary. Edit the "PointsGeneralPolygons" method.
def PointsGeneralPolygons(self, nloops, nverts, verts, params): print params.keys() # <-- new self.m_ri.PointsGeneralPolygons(nloops, nverts, verts, params)
Execute the code in the Rif_Py tab and two lines of text, one line per poly object, will be echoed in the script editor.
['facevarying float st','vertex point P','facevarying normal N'] ['facevarying float st','vertex point P','facevarying normal N']
Next, we will see what vertex data is referenced by the "vertex point P" key. But before doing so ensure only one object is visible in the viewport, say, the cube. Edit the "PointsGeneralPolygons" method as follows.
def PointsGeneralPolygons(self, nloops, nverts, verts, params): print params['vertex point P'] # <-- new self.m_ri.PointsGeneralPolygons(nloops, nverts, verts, params)
Execute the code in the Rif_Py tab. A tuple that specifies the vertices of the mesh will be echoed in the script editor.
(-0.6695894002914429, -2.1561105251312256, -0.41178059577941895, ...more...)
In total, for a cube, the tuple will contain 24 coordinates ie. 8 vertices x 3 coordinates per vertex.
Indexing into the params dictionary was accomplished using the explicit string
Therefore, the key to the vertex data of the params dictionary is normally using the pre-defined constant ie.
Using the Vertex Data to Place Spheres
Save the following script as rif_mesh_geo2.py and edit the Rif_Py tab so that it imports, reloads and calls the new rif_mesh_geo2 module. For example.
import batch import rif_mesh_geo2 reload(rif_mesh_geo2) rifs = ['rif_it','rif_mesh_geo2'] batch.render(1,1, rifs)
Listing 2 - rif_mesh_geo2.py
Using the new rif should produce an image similar to figure 2.
The next rif shows how the code needed to place geometry at each vertex can be reduced by outputting RenderMan Points - particles.
Using the Vertex Data to Place Points
Save the following script as rif_mesh_geo3.py and edit the Rif_Py tab - the new code
is shown below. Note the use of the
import batch import rif_mesh_geo3 reload(rif_mesh_geo3) rifs = ['rif_it','rif_mesh_geo3.Rif(0.3)' ] batch.render(1,1, rifs)
Listing 3 - rif_mesh_geo3.py
The code demonstrates how an input to control the size of each Point is implemented. Using the new rif should produce an image similar to figure 3.
The next rif shows how polymesh objects in Maya can be "tagged" to either be rendered without additional vertex Points, or rendered only as Points or rendered so that both the base mesh and the additional points appear in the image.
Controlling the Render Mode of Polymesh Objects
Select both polymesh surfaces in Maya and execute the following MEL procedure in the Add_Primvar tab of the script editor.
In the Channels Box (Shapes panel) note a custom channel named
Listing 4 - rif_mesh_geo4.py
Using the new rif should produce an image similar to figure 4.
© 2002- Malcolm Kesson. All rights reserved.