Python vs. C++
We will push as much code as possible to the python side for the following reasons:
- No need to (re)compile python : code transfers easily from one Maya version to another.
- Python development is faster than C++
- Many of our C++ dependencies (json/xml parsers, etc) are just part of Python's standard library.
- Everything in Maya is now accessible through Python.
- We can even do lightweight API work (we are using a new and faster python API).
- It makes a lot of our code more approachable to our more advanced users who may need to fix a crippling bug "right here, right now".
- Finally, we will get rid of most of the MEL code, but that goes without saying.
Installing
NOTE: RFM tries to ignore environment variables and build a clean environment to operate in maya. You may have to delete old maya module files.
- Build the project.
- Launch Maya
- First ever launch:
- Open
Windows -> Settings/Preferences -> Plugin Manager
- Click
Browse
- Navigate to
${workspace}/_publish/${toolchain}/RenderManForMaya-22.x/plugins
- Load
RenderMan_for_Maya.py
- Subsequent launches
- The plugin will be available in
Windows -> Settings/Preferences -> Plugin Manager
. You can either set it to auto-load or load it via a script or manually.
Startup sequence
- Load RenderMan_for_Maya.py
- setup_environment()
- use _rfm_directory() to get the current file's location (RenderMan_for_Maya.py) and use that to set RFMTREE.
- import rfm2
- initializePlugin()
Components
Maya Plugin
RenderMan_for_Maya.py
Python module
- rfm2: The main module containing most of the plugin's code.
- api: Public API for scripting RFM2.
- config: The configuration module created at startup.
- extensions: Extension attribute management.
- maya_node: Maya node registration using python's dynamic typing.
- render: Render functions.
- renderer: Register RenderMan as a renderer in the Maya UI.
- nodes: json node description files with validation schema.
- ui: User interface code
- ae_template: Attribute Editor templates
- aov: The AOV UI in the render globals.
- callbacks: Maya callbacks for HyperShade integration, etc.
- common: main classes defining regular UI widgets.
- file_dialog: Our file dialog callbacks to open, save, etc.
- page: Organise widgets in pages/groups/tabs
- prefs: Maya preferences UI and prefs API
- utils: UI utilities
- widgets: sets up UI widgets
- utils: Various utilities
- env: Environment variables access
- filepath: Cross platform file paths
- json_file: Read/write json files
- node_desc: Store a node description
- vp: Maya Viewport code
- pxr_light: MPxGeometryOverride dynamic classes for lights
- vp2: Functions to build vertex and index buffers
Debuging the python code
RenderMan_for_Maya.py is already setup for debugging in vscode:
- In RenderMan_for_Maya.py, set
vsc_remote_dbg
to True
.
- Load RenderMan_for_Maya.py. It will take longer to load when
vsc_remote_dbg = True
, so I turn it back off when I am done and restart maya so it takes (There is no way to kill the connection once it's been enabled).
- In vscode, set up your debugging config:
- Open your launch.json by clicking the cog icon on the right side of the DEBUG menu.
- In launch.json, insert a new configuration for your Maya version:
{
"name": "Maya 2017",
"type": "python",
"request": "attach",
"localRoot": "${workspaceRoot}",
"remoteRoot": "${workspaceRoot}",
"secret": "rfm2",
"host": "localhost",
"port": 3000
}
- save launch.json
- Select you config's name in the DEBUG menu ('Maya 2017' in this case).
- Set you breakpoints. etc.
- Press the green start icon and you should see the debugging bar at the top of the editing window (and the info bar at the bottom will turn orange)
- Make crazy things in maya and start debugging !