A gpuCache is a single shape in Maya, so it is impossible to assign materials as usual. But we can use RenderMan's Dynamic Rules Editor to assign materials at render-time, with the following limitation:
Open the Dynamic Rules Editor and let's see how it works.
You can either click the double angle bracket icon in the shelf or the Edit RLF File button in the gpuCache's attribute editor. The shelf button edits all scene alembics and the per-node button edits only the RLF associated to that node.
The left-side buttons handle all rule and file management tasks:
Rules are evaluated in the editor's order. To change their order, click in the rule number and drag to the new position.
Enable/disable: when the toggle is green the rule will be evaluated.
Stop/continue: When the icon is a cross, the rule evaluation will stop if this rule is matching. The arrow down icon indicate that subsequent rules will be evaluated even if this rule is matching.
Material: The shading group of the material, which references the surface and displacement shaders.
Attributes: insert or override attribute values. Click the new/edit icon to open the attribute dialog.
Match type: There are 3 matching engines:
Path expression: You can either double-click in the field to type your expression or drag and drop from the alembic node list.
To drag and drop, you must first select the node in the alembic node list. |
Notes: A field to write notes when things get complicated...
A rule can assign: • a material • attributes • or both ! |
In RenderMan, every shape is an instance. This means that an attribute attached to a specific shape will influence all instances of that shape.
If you want to assign an attribute to an instance, create an expression matching the instance's transform. This is particularly important for classic attributes like maxspeculardepth
, maxdiffusedepth
, relativepixelvariance
, etc.
Upgrading RenderMan 22.x RLF files 23.x; the RLF editor must be opened and the Alembic Cache contents need to be read into RFM in the AlembicCache node. This data must be brought into RenderMan for Maya before rendering, if not, it won't upgrade the version automatically and will fail to render the RLF data. Essentially, the RFL editor must be opened before rendering to allow it to recognize and upgrade the RLF file. |
Dynamic rules are written using glob expressions, similar to a shell. See the Dynamic Rules CookBook below for more info.
This is our starting point: the gpuCache node renders with the default material:
We have prepared a number of basic materials to assign. Let's start by assigning the hull_srf
material to the whole teapot and write our first rule:
Edit the expression from this /Rolling_Teapot_Grp/Rolling_Teapot to the below:
/**/Rolling_Teapot |
hull_srfSG
.Now we will shade the rivets on the teapot. We will need a more complicated expression.
Extend the previous expression to match any object containing the word "rivet".
/**/*rivet*/* |
On that model, there are also screws that could use the same material. Copy the expression to match those too.
/**/*screw*/* |
Let's assign a material to the teapot's rings.
We use the same workflow: duplicate the rule, replace "rivet"
with "ring"
and set the Payload to ring_srf
. But it doesn't quite work because, as you can see in the node list, some shapes have both "rivet"
and "ring"
in their name and rivets on the rings are now using the wrong material.
We can change the rule execution order if the result is incorrect (maybe your order is different than mine in the image): if we match rivet first, the matching engine will stop when it finds a match and then only shapes only containing "ring" will match the second rule.
Of course, we have only scratched the surface and we recommend that you read up on Regular Expressions for more sophisticated use.
If you're done shading, select the disk/save RLF (RenderMan Look File) icon. This can be used in the import of the asset to assign the shading nodes each time. This can then be part of your asset publishing scheme.
If you want to import fully shaded assets, there are 2 options:
This is not always very flexible in a pipeline, but may be useful for archiving assets.
The RLF file format does not include material descriptions and you have to make sure that: • All referenced materials exist in your scene. • Output All Shaders is checked in the Advanced section of the render globals. |
Note that you can still override automatic RLF assignments in the scene with the Dynamic Rule Editor ! In that case, the scene RLF rules will be executed before the archive's rules and thus have a chance to override them. |
When you reference multiple RFL files in a scene, you must make sure that all shading nodes have unique names. If you define the same name multiple times, the renderer will use the first in line and you will get unexpected results.
You can export a RLF file by clicking the icon in the RLF Editor, or write a simple Python script that will save the scene's current RLF data to a file:
import rfm2.api.nodes as apinodes def save_scene_rlf(filepath): """Load the rlf data from the rmanGlobals node and save it to a file. Arguments: filepath {str} -- Full path to the final RLF file """ rg = apinodes.rman_globals() if rg: json_str = mc.getAttr('%s.rlfData' % rg) try: with open(filepath, 'w') as fhdl: fhdl.write(data) except Exception, err: print 'Failed to write %s: %s' % (filepath, err) else: print 'Warning: Could not find rmanGlobals node in the scene !' |
Imagine we have a gpuCache node named Rolling_Teapot...
/**/* |
/**/Rolling_Teapot |
/**/*rivet*/* |
/**/ring_*/* |