Python Particles


main index



Introduction

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 (logic) tests
- writing of files
The challenge will introduce you to two techniques by which particles can be procedurally created.


Technique 1: MEL Particles

This technique involves coding two python scripts. The first script (gen_coords.py) will generate positional data that will be used the second python script (mel_particles.py) to write a .mel file that will contain a MEL particle command. For example,

particle -p x y z -p x y z;

where x y z specify the positions of two particles. When the .mel file is sourced the particles will appear in the viewport.

The gen_coords.py script will implement at least 5 procedures. Each procedure will produce a list consisting of an arbitary number of x,y,z coordinates. An example implementaton is shown below.

#------------------------- gen_coords.py --------------------    
import random
import math
  
def cubic(num_coords, side):
    data = []
    count = 0
    half_side = side/2
    while count < num_coords:
        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)

An example implementation of the second python script (mel_particles.py) is shown next. Both the gen_coords.py and the mel_particles.py MUST be saved in your maya/scripts folder.


#---------------------- mel_particles.py --------------------
import gen_coords
  
def writeCubic(mel_path, num_particles, side):
    data = gen_coordss.cubic(num_particles, side)

    mel_out = open(mel_path, 'w')
    mel_out.write('particle\n')
    
    for x,y,z in data:
        mel_out.write('-p %1.3f %1.3f %1.3f\n' % (x,y,z))
        
    mel_out.write(';\n')
    mel_out.close()
#------------------------------------------------------------ 

The mel_particles.py script should implement the following procedures,

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

How the procedures implemented by your gen_coords.py and mel_particles.py scripts are used will be demonstrated during our zoom sessions.



Technique 2: 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().


#-------------------- maya_particles.py -----------------------
import maya.cmds as cmds
import gen_coords
  
def cubicCloud(num_particles, side):
    # Use the gen_coords module to create a list of points
    data = gen_coords.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 Maya particle shapes,
2     a technical breakdown that explains how the images were created.



Grading

The following categories will be used for grading your work.


Criteria

Below Average

Average

Above Average

  Demonstrates creativity

 

 

 

  Technical breakdown

 

 

 

  Research/investigation

 

 

 

  Self evaluation