Python Particles - RenderMan & Maya

main index


This challenge will enable you to explore several basic concepts of python programming:
- use of lists
- use of loops
- use of mathematical expressions
- use of tests
- writing of files

The challenge will also introduce you to two techniques by which particles can be procedurally created.

The first technique, unique to Pixar's rendering system called RenderMan, involves writing what is generally referred to in the visual effects industry as a pre-baked rib file. Rib files contain text that describe geometric entities, such as a collection of particles, in a format that conforms to the rules of a scripting language known as Pixar's 3D Scene Description Language. Rib files of the type that you will create using your own custom python scripts can be referenced by Maya. Although the particles defined by a rib file cannot be pre-viewed in Maya's viewport they can be rendered by Pixar's renderer called PRMan.

The second technique involves writing a python script that when executed in Maya's script editor will generate particles that will appear in the viewport as a regular Maya object.

RenderMan Particles

To successfully complete this part of the challenge you will write two python scripts. The first script will contain at least 5 procedures. Each procedure will produce a list of 3D points that describe of the positions of an arbitary number of "particles" that form a specific shape. For example, the following python script implements a procedure called cubic().

#------------------------- --------------------    
import random
import math
def cubic(num_points, side):
    data = []
    count = 0
    half_side = side/2
    while count < num_points:
        x = random.uniform(-half_side, half_side)
        y = random.uniform(-half_side, half_side)
        z = random.uniform(-half_side, half_side)
        data.append( (x,y,z) )
        count += 1    
    return data

You are expected to implement the following procedures,

    spherical(num_points, radius)
    cylindrical(num_points, radius, height)
    box(num_points, width, length, height)
    cone(num_points, radius, height)

The second python script will use the first script to generate particle positions that will be written to a rib file. An example implementation is shown next.

#---------------------- --------------------
import gen_points
def writeCubic(rib_path, num_particles, side, particle_width):
    data = gen_points.cubic(num_particles, side)
    half_side = side/2

    rib_out = open(rib_path, 'w')
    # Maya will use the bounding box dimensions to
    # represent the particles as a simple box.
    #                                                minX,      minY,      minZ,       maxX,     maxY,     maxZ
    rib_out.write('##bbox: %s %s %s %s %s %s \n' % (-half_side,-half_side,-half_side,  half_side,half_side,half_side))
    rib_out.write('Points "P" [\n')
    for x,y,z in data:
        rib_out.write('%1.3f %1.3f %1.3f\n' % (x,y,z))
    rib_out.write('] "constantwidth" [%1.3f]\n' % particle_width)

A pre-baked rib file that describes a very simple collection of particles would look as follows. The rib files that you will produce may define many thousands of particles.

##bbox: -3 -3 -3 3 3 3 
Points "P" [
-0.752 2.126 0.999
-0.027 2.452 -0.492
0.333 -2.494 -0.612
] "constantwidth" [0.050]

How pre-baked rib files are used in Maya will be demonstrated during our zoom sessions. You are expected to add following 4 procedures to the script,

    writeSpherical(rib_path, num_points, radius, particle_width)
    writeCylindrical(rib_path, num_points, radius, height, particle_width)
    writeBox(rib_path, num_points, width, length, height, particle_width)
    writeCone(rib_path, num_points, radius, height, particle_width)

Maya Particles

To successfully complete this part of the challenge you will write only one python script. For example, the next code snippet implements a procedure called cubicCloud().

#-------------------- -----------------------
import maya.cmds as cmds
import gen_points
def cubicCloud(num_particles, side):
    # Use the gen_points module to create a list of points
    data = gen_points.cubic(num_particles, side)
    # Use Maya's python command to add the cubic particle
    # cloud to the viewport. Capture and return the name of 
    # the particle system. 
    return cmds.particle(p=data)[0]

You are expected to implement and add following procedures to the maya_particles script,

    sphericalCloud(num_points, radius)
    cylindricalCloud(num_points, radius, height)
    boxCloud(num_points, width, length, height)
    conicalCloud(num_points, radius, height)

How the procedures implemented by your maya_particles script are used in Maya will be demonstrated during our zoom sessions.

What is Expected?

The technical breakdown on your web page should show the following.
1     at least one rendered image of each of the RenderMan particle shapes,
2     at least one rendered image of each of the Maya particle shapes,
3     a technical breakdown that explains how the images were created.


The following categories will be used for grading your work.


Below Average


Above Average

  Demonstrates creativity




  Technical breakdown








  Self evaluation