gumroad_01short_spacer_01

Sample Projects

Python: Distribute Objects on Surface Using Texture

This code applies an object or objects to the surface of another object using a texture to control placement and scale.  Dark areas of the texture will reduce the scale, and lighter areas yield larger objects.  The tool allows users to clamp the minimum and maximum values, and additional controls to randomize placement, rotation, and scale of the objects.  There is also a setting to cull objects on faces below a specific brightness value.  To use the tool, the user selects and loads the objects to place, as well as the target surface, changes values if necessary, and presses the Distribute Geo button.

The tool works by iterating over each face of the target surface, gathering the vertex numbers and corresponding UVs, and averages the texel values for each UV associated with the face.  Then it selects an object to place, aligns the object to the face normal (if requested) and moves the object to the center of the face.   Once the object is placed it is translated, rotated, and scaled, according to the settings in the UI.

Download distributeObjectsOnSurface.py

Download sample Maya file (spike face example below)

short_spacer_01

Here is the UI, next to a scene where buildings are placed on a plane according to the texture.

city_02

short_spacer_01

In this example,  trees are added to a mountain.

mountain

short_spacer_01

The tool can interpret both artist-created textures and procedural 2D textures.  It can also preserve the original rotation of the objects, or orient them to follow the normals of the target surface.

face_spikes_03spacer

Python: Directory-Wide Automated Poly Reduction Tool

The following Python code is a tool for reducing poly counts on meshes across an entire directory.  This tool uses Maya’s reduce feature.  The code prompts the user to select a directory and a reduction percentage.  In order to easily review the changes, a screen shot is taken before and after the operation.  Output image resolution is exposed in the tool.  In the event the user would like to review the results before committing the changes, the tool provides a preview option.  Screen shots are taken and geometry is reduced, but no changes are saved.  The images are saved by default in the root of the selected directory, which the user can open directly from the tool.

Download polyReductionTool.py

poly_reduction_02

spacer

Python: Texture Remap Tool

The following Python code works by getting all the textures in a scene, querying the user for a new texture directory, and setting the textureFileName attribute for each file to the new address.  The tool has a find and replace option, and will create an error report of failed assignments if requested.  The attached file has three folders, each with textures.  The files in the first two folders are named the same, but the files in the third folder have been renamed.

Download textureRemapTool.py

Download Sample Files

texture_remap

spacer

Teaching Examples

The following projects are intended to help students learn and understand basic elements of scripting, including variables, lists, loops, attributes, and utilities.

short_spacer_01

Unity – C#  Exploding Cubes

Download ExplodingCubes Project Files

 

Color Polygons by Area

The following MEL code analyzes a selected piece of polygonal geometry to get the area of each face. The faces are then sorted into tenth percentiles, and assigned to a one of ten colored materials. The smallest faces are colored dark purple, then blue, green, and so on up to the largest faces, which are assigned to a red material. (note – this code will only work on contiguous pieces of geometry)

Download polyColor.mel
short_spacer_01
horse_faces_01

spacer

Spheres That Don’t Touch

The following Python code creates randomly positioned spheres, making sure none touch.  The user is prompted for a number of tries and the sphere radius. After the code is finished, the result is printed on the screen.  The code works by randomly creating spheres, and testing the distance between each new sphere and all existing sphere.  If the new sphere touches any existing sphere, it’s deleted.  Otherwise, it is added to the list of existing spheres to test against on the next try.
Download sphereGen.py
short_spacer_01
sphere_result_01

spacer

Dynamically Animated Spheres

The following MEL code creates a grid of child spheres whose scale is modified by a master sphere. The master sphere is dynamically animated using a nail constraint and turbulence field. The closer the master sphere gets to the child spheres, the larger they become. This is done by connecting a distanceBetween node to the master sphere and the scale attributes of each sphere.

Download spheresAnimated.mel

spacer

character_art_02spacerphotos_04spacerfine_art_04spacertutorials