Procedural Primitives
Placing a Blobby


return to main index

Code:
    PlaceBlobbyProc.cpp
    pp_place_blobby.py
    Download code_PlaceBlobby.zip
    Download sample Maya project MayaPlaceBlobby.zip



Introduction

This tutorial provides an explanation of how a Blobby, generated by a procedural primitive written in C, can be rendered so that its individual "blobs" are located at the vertices of a polymesh. The reader should review the following tutorials,
    C++ Development Environment
    Procedural Primitives: Getting Started
    Procedural Primitives: Adding an Interface



Figure 1 (rollover)



How is a Blobby Specified?

In RIB a Blobby consisting of 3 blobs would be specified as follows,

Blobby 3
    [1001 0
     1001 16
     1001 32
     0 3   0 1 2]
    [1 0 0 0  0 1 0 0  0 0 1 0 -0.5  0.2  0.0 1
     1 0 0 0  0 1 0 0  0 0 1 0  0.9  0.5  0.0 1
     1 0 0 0  0 1 0 0  0 0 1 0  0.5 -0.5  0.0 1]
    [""]

In the 'C' language a Blobby is specified as.

RiBlobby ( RtInt num_blobs, RtInt total_num_codes, RtInt codes[], 
           RtInt num_matrix_values, RtFloat matrix_values[],
           RtInt num_strings, RtString strings[], NULL);

The diagram shown below, figure 2, illustrates the relationship between the sample values of the RIB version of a Blobby and their use with RiBlobby function.



Figure 2



The Procedural Primitive Code

Open the PlaceBlobbyProc.cpp file and build the DSO using the keyboard shortcut Alt + e or Control + e.

A DSO (dynamic shared object) called PlaceBlobbyProc.dll (Windows) or PlaceBlobbyProc.so (OSX and Linux) will be created either in the same folder as the PlaceBlobbyProc.cpp, or, if Cutter's preferences have been set as described in the tutorial, C++ Development Environment, the DSO will can be found in,
    maya/rfm_scripts/proc_prims
folder.

The Python Code

Copy or move the pp_place_blobby.py script to either your
    maya/script folder, or your
    maya/rfm_scripts folder.


Using the Scripts in Maya

Either use the Maya scene provided in the MayaPlaceBlobby.zip or follow these instructions.

Assuming a project directory called "PlaceBlobby" has been set in Maya, create a simple polymesh object such as a torus. From the RenderMan menu choose Archive->Create Procedural Node.



Figure 3


In Maya's outliner choose, Display->Shapes.



Figure 4


Parent the RenderManProgram node to the torus.



Figure 5


In the outliner select the RenderManProgramShape shape node. In the Attribute Editor for the RenderManProgramShape choose,
    Attributes->Add Attributes...



Figure 6


Create a float attribute named "scale",
a string attribute named "target", and
a boolean attribute named "use_local_space".

Make sure the names are lower case and that "Override nice name" is checked and that the nice name is also lower case. The new attributes will appear at the bottom of the panel. Make sure they have reasonable default values.



Figure 6


Connecting the Interface

As shown in figure 6 use the browse button for the DSO Name: and locate the PlaceBlobbyProc.dll or PlaceBlobbyProc.so file.

A small python script will be used to update the RenderManProgramShape Data textfield when the values of the custom float, string and boolean attributes are adjusted. Copy and paste the following code into the Pre Shape Python Script text field.


import rfm2.api.strings as apistr; import pp_place_blobby; pp_place_blobby.setDataStr(apistr.expand_string("<shape>"))

Note the code must be pasted as a single line of text.

When the scene is rendered the line of code in the Pre Shape Python Script text field will call the module implemented by the pp_place_blobby.py script.

The module queries the custom attributes and obtains a list of the coordinates of the vertices of the "target" object, say, pTorus1. The data is converted to a string and assigned to the Data text field. The RfM plugin passes the text to the PlaceBlobbyProc.so (or .dll).

The ConvertParameters() procedure of the procedural primitive converts the text back into numeric values. The Subdivide() procedure uses the numeric values, "packaged" in a structure (effectively a small database), to create a Blobby.





Because the vertices of the target object are evaluated before each frame is rendered the positions of the spheres are always "bound" to the shape of the polymesh.







© 2002- Malcolm Kesson. All rights reserved.