Brushing Up on Katana II
Alan Rosenfeld
3D Lighting Artist | Award Winning Director | Writer | Katana and Unreal Cinematics Lighting | ????Canadian PR
It's been almost four years since I wrote my article, 'Brushing Up on Katana'.?I've been off doing a lot of Unreal work in my off-time while continuing my VFX/Feature Animation Katana/Renderman/Arnold work during the day.?I'm flattered that so many people have been able to gain knowledge from the paper and implement the techniques in their daily work lives.
Introduction
During my holiday break, I wanted to do more brushing up in Katana as I've not touched Python in years and could not remember how to make cool tools in Katana.?I knew getting back into the programing side for Katana, I did not want to touch Qt for creating UI's.?I've seen the techniques I'll demonstrate below at various houses I've worked at, but never knew how they worked.?So I downloaded the latest Katana and Renderman on my home PC, rolled up my sleeves, and got down to business.
I'll link to all the code examples located on the Foundry website in the forum, however, the tools are simple .txt files containing XML code.?Installing the tools could not be more simple.?Open the .txt files, copy, then in the NodeGraph of Katana, Ctrl+V to paste and the node will be created.
Note, not all these types of nodes need to be connected into the tree. Many can sit in blank space in the node graph.
Objectives
The Group Node - Using an Expression
It all starts with the Group node.?It's a container node that we can place other nodes inside and connect them up each other and the input/output.?The default Tab->Group node for our purposes is too generic to be a container for building a UI and adding other nodes to.?For this reason, I've created a tool that gives you a good starting point, AL_GIZMO_TEMPLATE_MAKER.
I'll provide links to the Foundry forum website where you may find the .txt file containing the XML code to cut/paste into the NodeGraph.
This tool, itself a Gizmo, will create a new Gizmo with some default fields. Gizmos are user created nodes to create UI front-ends that allow artists the ability to expand and build upon the toolsets within Katana.
Example Usage: Drive attribute with expression
1) After installing the tool, (simply copy/paste the XML text from the attached .txt file into your nodegraph), press the 'Create Template Gizmo' button.
2) A new node will be generated and placed under your cursor in the nodegraph ready for you to place.
3) Let's drive a field on RenderOutputDefine node. Ctrl+Enter over the NewGizmo_Template node to go inside. Connect in a RenderOutputDefine node within the stream.
4) In the NewGizmo_Template UI, add a string to the MY_GIZMO_STRING field. Example: MyPath
5) RMC (Right-Mouse-Click) over the 'MY_GIZMO_STRING' name and 'Copy' the expression.
6) Back within the NewGizmo_Template, in the RenderOutputDefine, RMC (Right-Mouse-Click) over the 'tempRenderLocation' field Paste->expression. The expression will be added and you can now drive this field with whatever string you put in the 'MY_GIZMO_STRING' field.
That is as basic as it gets.?Now, let's look at a more complex case.?What if you want to pass Parameters from the UI into a Python script and vice versa?
AL_RENDER
This tool allows the artist to render a batch of frames on their local machine. It is a very rudimentary tool with no logging. The tool as written will allow the artist to kill the batch render, but the currently rendering frame will need to finish first.
The artist will set the frame range and press 'Launch Render'.?We need to tell the python code attached to the 'Launch Render' button what frame ranges the artist has chosen.?We'd also like to keep the artist informed of the progress and change the current frame rendering in the UI.
Using the WRENCH->EditUserParameters icon in the upper-right of the AL_RENDER node in the Parameters tab, we'll be able to open up the tools to access the UI.?Press on the WRENCH->WidgetOptions in the upper-left corner above the 'Launch Render' button.
Within the AL_RENDER node UI is a group called 'user'.?This group can contain widgets such as a slider or other groups with stuff in them.?We just need to be smart in naming each Parameter to easily be able to access them within the Python script.
Note here, we are passing the value from the Frame Start slider into the Python code:
frameStart = int(NodegraphAPI.GetNode("AL_RENDER").getParameter('user').getChild('AL_RENDER_FRAME_START').getValue(0))
This reads as: traverse from the top node 'AL_RENDER' down to the group 'user' and further down to the child 'AL_RENDER_FRAME_START'(a number) and get it's value at frame 0.
Where is the child Parameter name being set??If you WRENCH->RenameParameter on the Frame Start, this is where the Paramter name is set.?NOT the visible name you see in the UI.?That is called the 'label'.?To set the 'label', WRENCH->WidgetOptions on the Frame Start.?This will display a 'number' widget with the options set for a slider.?The 'label' field is at the bottom.
Note when you create a new widget and first WRENCH->RenameParameter, for example MY_NEW_PARAMETER, and now WRENCH->WidgetOptions, you will see the 'label' field has already been filled with the Parameter name.?Somewhat helpful, but you'll need to make it pretty here and you can use spaces.
领英推荐
Now, how would I pass a value from the Python script back to the Group UI?
NodegraphAPI.GetNode("AL_RENDER").getParameter('user').getChild('AL_RENDER_MESSAGES').setValue('Render Complete',0)
This reads as: traverse from the top node 'AL_RENDER' down to the group 'user' and further down to the child 'AL_RENDER_MESSAGES' which is a string widget and set it's value at frame 0.
BTW, when you are done editing the Parameters in your Group UI, WRENCH->FinishEditingUserParameters to close it all up and see it pretty.
Multi-Rename - The Next Generation
You will recall from my previous article, 'Brushing Up on Qt Designer - A Case Study', I used Qt to create a UI to allow artists to quickly rename and renumber NodeGraph nodes.?It was clumsy and hard to install.?Introducing the NEW! and IMPROVED! Multi-Rename too, AL_NODEGRAPH_MULTI_RENAME.
I take the tool to a new level and implement it within a Gizmo built from a Group node within Katana. The tool goes one-step further and allows the artists to change the color of their nodes in various ways.?This builds upon the node color tools I first wrote about in my article 'Brushing Up on Katana'.?It's great to recycle code!
The tool is simple to use. Bring in the tool, select the nodes you wish to modify in the NodeGraph, and press a button in the tool. The tool is 'live' in that with your nodes selected, if you keep pressing say, the 'Remove First Character', you will see your nodes names' change in real-time. This tool may be added as a macro too! Lookdev and layout artists should find this tool very valuable.
As an example for building Group node UI's, AL_NODEGRAPH_MULTI_RENAME utilizes passing Parameters back-and-forth between button activation of Python script and the error messages if any from the Python script back to the 'MESSAGE' string field.?WRENCH->EditParameters and open up the UI and take a look at the different buttons and the code they launch.
The 'Execute Node Color Change' utilizes a color picker within the Gizmo itself to select the node color.?While the 'Color By Node Type' will open up a Qt color picker for each node type it finds.
Frame Calculator - AL_FRAME_CALCULATOR
You face this every day as a lighter.?What is the FML of my current shot??What would be the FML if I change the frame range??Do I really have to type in all the frames into the farm render agent??No Virginia, you don't.?Yeah, I just got tired of it too.
AL_FRAME_CALCULATOR attempts to bring together the most needed information for a lighting artist when it comes to frames.?The tool presents at the top, the current shot's information including the FML.?Below that, I present three formats that I've seen most used at houses when sending frames to the farm. (see more you need? ask me and I'll tweak or you can adjust the code on your own.)?These frame list formats are ready to copy/paste right into your farm agent.?I also provide a 'CALCULATED FML', that when you adjust the Frame Start/End sliders below, a new FML will be calculated!
To calculate after you make a slider change, 'PRESS to CALCULATE'.?WRENCH->EditParameters to get at the Parameters and then WRENCH->WidgetOptions on the 'PRESS_TO_CALCULATE' and take a look at the script to see how I did the calucations and passing values into and out of the script.
References and Tips
When working with these Group Node Parameters, you will be playing a lot with what works in an expression and what doesn't.?For example, let's say I want to create a new primitive and place the primitive at a specific place in the Scenegraph and with a specific name based on the Node name.
We can use the 'nodeName' python expression within the expression field.
Then, from within the Group node, in the PrimitiveCreate node 'name' field, we can place the expression:
str('/root/world/geo/BD_PRIMITIVE_GEO/')+getParam("BD_PRIMITIVE.user.BD_PRIMITIVE_primitiveName.BD_PRIMITIAVE_NAME")
This page is the most helpful when it comes to finding these functions to use within an expression:
Don't forget you can also call math operations including noise(), sin(), random().?Here is an example from the AL_NOISE Gizmo.
The formula is: ((noise(frame*Frequency)*Amplitude)+Offset)
((noise(frame*getParam("BD_NOISE.user.BD_NOISE_Frequency"))*getParam("BD_NOISE.user.BD_NOISE_Amplitude"))+getParam("BD_NOISE.user.BD_NOISE_Offset"))
This produces a noise curve such as this:
You will note in the image above, I'm using the expression value from the AL_NOISE to drive a prmanLightShader Intensity attribute. You can visualize with the Curve Tab.
If you wish to muck about with the AL_GIZMO_TEMPLATE_MAKER to add more default children and groups to the Gizmo, check out:
And then this page for getting and setting attributes:
Conclusion
It's been a very enjoyable week knocking about in Katana and Renderman and refreshing my knowledge on creating user tools.?I find the technique of creating UI's in a Group Node is much faster than Qt and opens up to many other artists the ability to quickly create sharable tools. It's also more fun!
Enjoy in Peace.
Alan