home
contents
resume
showreel
portfolio

resources
renderman
maya
massive
houdini

friends
professor malcolm kesson
professor ron bernard
aleksander rodic
andrew dehner
billy dongyoon jang
kiki poh
sandro blattner
zahari dichev

contact
01. 912 . 272 . 2209
davekcw@yahoo.com.sg
Mel, Python and Renderman I - Python curves
This project explores further the possibilities of RIB archives, by using python as a middle man to write data outside of Maya's limitations and generating procedural RIB archives. In this case, the subject of interest in procedural curves tapered to look like grass.

Notes!
This project may differ from the initial assignment writeup written for Professor Malcolm Kesson. It would have been edited to also reflect my later experiences, clearer tutorial techniques/codes and also later advancements made to the projects as well.
   
Introduction

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

In this assignment, we continue from the demonstration by our Professor in the variances and use of python versus mel scripting. Building upon earlier concepts of rib replacement seen in Renderman's pre-shape nodes. We too take similar actions in python. Except instead of using Maya itself, I have decided to keep the code between Python and Renderman without the use of Maya. The application of which would later present itself in further experimentation as we discover the use of Python in both Maya and Renderman environments.

As a requirement, we are requested to use basic techniques in python to create random curves. These demonstration seems to be a re-representation towards how we apply the use of procedures, loops and variables that we have learnt from earlier assignments... Not deciding to stray too far away from the course requirements, but instead to spend more time on the experiementaion between the differences of Python, Mel and RSL, I have decided to create grass for this assignment.

The Conceptual Technique
In Professor Kesson's demonstration and through exercises, we know that Renderman itself seems able to only read its own primary language as it processes files for rendering. The bridge between Maya and Renderman itself comes from the special set of Ri commands which does not exist in Python the same way as earlier practiced. Thus, in order to render in renderman with objects created in Python, we have only two options -

The Python in Maya Technique
Python Generated Rib File Technique

Obviously, the first technique is pretty straightforward considering that Maya itself has a set of Python commands. By simply using these commands in the Maya environment itself, we can create objects in a macro like technique which Renderman will be able to read via the normal Maya to Prman bridge that it is equipped with. This technique has a huge variety of benefits with the most important being the visual previewing elements which is crucial and important to artist who are essentially more visually inclined. However its main flaws being the memory restraints in rendering and probably the lack of a pre-Shape python node of which would require Mel-scripting to facilitate.

The second technique is obviously more textually inclined. Artist will not beable to preview what they assume to be existing in a invisible spatial plane. However its benefits being that Maya itself can be totally negated. Memory contraints caused by Maya itself would also become less significant - only to be affect by the OS itself than rather any other 3rd party programs. Of which, the second technique will be the workflow that I shall examine at the start.

The Python to Renderman Technique
As we all know, Renderman renders with information written in RIB files. Thus the process of this technique means the use of a procedural Python script which will generate a specific RIB file of which Renderman can process. From the example code below, we can see that the normal codes of proc cubeOfSphereV2(string $path; int $num; float $rad) has become a simplified def cubeOfSphereV2(path,num.rad) as it shifts from Mel to Python.

 

This script generally uses random seeds and random attributes within the python random script to generate random coordinates. Coordinates of which would be written into a empty file as determined by the path variable. These lines of information are actually RSL languages. Just as it is similar to the way we use string to generate automatic expressions in Maya using Mel, we find ourselves using python's file script to create rib files for renderman.

Using this same idea, we can proceed in the creation of Rib files filled with random curves. And to begin that, we first need to know the Rib eqivalent for a curve command.

 
 

The RIB "Curves" Command
In using this command, I have realized a few crucial elements. When using cubic beziers, we need to understand that the 4 vertice equivalent is the same as having two vertices and two bezier handles. Thus there should only be 2 width values and 2 colors values. Thus we should always bear in mind that he minimum number of points in a bezier should always be four and that every increment of this bezier should be added in 3s... Thus resulting in 4, 7, 10, 13, 16, 19 etc etc. Which would respectively provide the slots 2, 3, 4, 5, 6, 7 etc etc for keying in additional attributes such as width and color. In rendering grass, it is obvious that my widthA and widthB should result in a taper and that my grass will always positively grow in a positive Y direction. Thus, to randomize my curves, I should only add a randomizing variable towards the X and Z position of my vertices.

 
 

Therefore, using the same script. I have rewritten a script that would create the random looking grass.

 

 

The pyCurves Script
To better understand, let me sum up the controllable data of this script:-

Path - this determines where the RIB file will be generated
Num - this determines the number of grass blades to generate
Jitter - this is the amount by which the randomized grass will distort and variate
Height - this is the incremental value which determines the height of the grass
Hvar - this is a variance value which adds to the height of the grass, making them uneven
Scal - this is the boundary of the grass plane
Colvar - this is the value by which the grass will variate in color by
Xval - this value determines the common shift of the grass to create wind-like effects

It is also important to note that at this point, because the use of Sine and Cosine rules are vastly different especially in that the module cmath has to be loaded in python, I have decided to temporarily create a Xval which will shift the grass manually for now. My next intentions is to completely merge this concept of the python code into Maya which will allow users keyframing abilities which will add to the result.

The renderman scene file used to render the grass can be found in the image below:-

 
 

Below are some further examples of the grass renders.

 
 

The Next Step
Next, I will be implementing the full addition of the sine wave curve to create a wave-like animation of the grass as they move in a simulated wind environment. Also, I am looking at how I can implement this in Maya using Renderman's pre-shape node and Mel's "python" coding. Hopefully I will beable to apply this on random points of any objects in Maya space which will render out as curves in Renderman for the purpose of grass, hair and fur simulation.

With some success, I was able to bind the python code into Renderman's preShape Mel Node using the python() command in mel to procedurally import and generate the rib required for the frame while using simple getAttr commands to retrieve user set values from Maya Custom Attributes. This method was chosen because of the ease in setting frames, visualizing animation curves, easy proxy viewing from object of influence and lastly no more Maya reboot just to load Rman files.

Using a simple cmath,sin(phase) and random.random(), I was able to create a sine base wave determined by the user inputs and the grass's relative position from the 0,0,0 cartesian axis. Thus :-

 

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

   


 
dave kin chang wei - visual effects artist / technical director - davekcw@yahoo.com.sg - www.kamid.net