Shader Assignments
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 limitations:
- IPR material edits don't work when using Dynamic Rules
- Any rule change will require an IPR restart to take effect.
- These limitations will be lifted in an upcoming release.
In-scene shading
Open the Dynamic Rules Editor (the double angle bracket icon) and let's see how it works.
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:
Assign a base material to part of an archive
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:
Match sub-strings in a hierarchy
Now we will shade the rivets on the teapot. We will need a more complicated expression.
- Duplicate the first rule
- Right-click on the rule number (0 in our case) and select Duplicate Rules (the copy icon just below the "-" minus icon).
Extend the previous expression to match any object containing the word "rivet".
- The second ** means the rivet object can be nested at any level under the teapot
- * rivet * matches if rivet appears in node name. "rivet", "Arivet" and "Brivet2" would all match.
On that model, there are also screws that could use the same material. Copy the expression to match those too.
Rule execution order
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.
- Position the cursor over the rule's number and left-button-drag rule 1 (rivets) above rule 0 (ring).
- Render to check.
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.
Self-contained Asset Shading
If you want to import fully shaded assets, there are 2 options:
- When RfM finds a RLF file in the same location and with the same name as the archive, it will automatically apply it.
- This is not always very flexible in a pipeline, but may be useful for archiving assets.
- If the RLF File Name field of a gpuCache node contains a path to a RLF file, RfM will apply it to that gpuCache node.
- It becomes easy to script look assignment and updating.
Notes about RLF export
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 !'