Using Maya / Hodini versions of USD
USD in DCC Tools
Each DCC tool ships with it’s own implementation of USD, this is to ensure that the version of USD that ships with the tool is compatible with the features of the tool, this can also include custom plugins and features that are not available in the main USD distribution such as Renderers and DCC specific features.
To use these custom versions of USD we need to setup specific environment paths and variables to get thing to work nicely, we also need to use the correct python version (mayapy / hython ) to ensure everything works.
Houdini Setup
For houdini it is quite simple to use, we just need to use the houdini_setup_bash script to setup the environment for us.
cd /opt/hfs20.5.332/
source houdini_setup_bash
This should give you full access to all the usd command line tools and the python API, you can test it using the hython repl as follows:
from pxr import Usd
print("USD Build Info:", Usd.GetVersion())
USD Build Info: (0, 24, 3)
We can add this as a tab to the Gnome Shell, I discussed how to do this in a
post here. We can open up the terminal Preferences add a new profile and set the command to be /public/devel/24-25/bin/houshell.sh
make sure you set the shell to be a login shell to get the correct environment. (I also change the background colour to differentiate this shell from the others)
The script being run is quite simple and could be adapted for other uses if needed.
#!/usr/bin/env bash
cd /opt/hfs20.5.332/
source houdini_setup_bash
export PS1="[\u@\h \W]\$"
cd $HOME
$SHELL
Maya Setup
The maya setup is a little more complex as there is not equivalent setup script to houdini_setup_bash. We also need to do some extra setup with the mayapy python environment to ensure that some essential packages are installed.
The script is as follows and can be setup as a new profile on the gnome shell as before but use the command /public/devel/24-25/bin/mayashell.sh
The script is as follows and I will describe the steps below.
#!/usr/bin/env bash
# Function to check and install Python packages
check_and_install_package() {
local package=$1
mayapy -c "import $package" 2>/dev/null || mayapy -m pip install $package
}
# Function to set up environment variables
setup_environment() {
export USD_ROOT=/opt/autodesk/mayausd/maya2023/0.20.0_202211021008-b68700b/mayausd/USD
export PATH=/opt/autodesk/maya/bin:$USD_ROOT/bin:$PATH
export PYTHONPATH=$USD_ROOT/lib/python:$PYTHONPATH
export LD_LIBRARY_PATH=/opt/autodesk/maya/lib:$USD_ROOT/plugins/usd:$LD_LIBRARY_PATH
export PS1="[\u@\h \W]\$"
}
# Function to create aliases for USD tools
create_usd_aliases() {
local aliases=(
"usddumpcrate='mayapy $USD_ROOT/bin/usddumpcrate'"
"usdzip='mayapy $USD_ROOT/bin/usdzip'"
"usdtree='mayapy $USD_ROOT/bin/usdtree'"
"usdchecker='mayapy $USD_ROOT/bin/usdchecker'"
"usdrecord='mayapy $USD_ROOT/bin/usdrecord'"
"usdstitch='mayapy $USD_ROOT/bin/usdstitch'"
"usddiff='mayapy $USD_ROOT/bin/usddiff'"
"usdresolve='mayapy $USD_ROOT/bin/usdresolve'"
"usdview='mayapy $USD_ROOT/bin/usdview'"
"usdgenschemafromsdr='mayapy $USD_ROOT/bin/usdgenschemafromsdr'"
"usdedit='mayapy $USD_ROOT/bin/usdedit'"
"usdcat='mayapy $USD_ROOT/bin/usdcat'"
"testusdview='mayapy $USD_ROOT/bin/testusdview'"
"usdstitchclips='mayapy $USD_ROOT/bin/usdstitchclips'"
"usdGenSchema='mayapy $USD_ROOT/bin/usdGenSchema'"
)
for alias in "${aliases[@]}"; do
echo "alias $alias"
done
}
# Main script execution
setup_environment
# Check and install required Python packages
check_and_install_package "OpenGL"
check_and_install_package "numpy"
# Ensure aliases are available in interactive sessions
shopt -s expand_aliases
# Create USD tool aliases and start a new shell session with the configured environment
cd $HOME
exec $SHELL --rcfile <(echo "source ~/.bashrc; $(create_usd_aliases)")
The setup_environment()
function sets up the environment variables for the USD tools and the maya binary, we also need to set the python path to include the USD python libraries It also sets the PS1 prompt to something more useful.
The check_and_install_package()
function is a simple function that checks if a python package is installed and if not installs it. This is used to ensure that the OpenGL and Numpy packages are installed.
This is needed because some of the USD tools require these packages to be installed (such as usdview). Note this will take a little time to install the first time you run the shell but subsequent runs will not install anything.
The create_usd_aliases()
function creates aliases for the USD tools that are available in the maya version of USD. This is required as the all these tools are python scripts with the shebang line set to the mayapy binary. This means that we need to run the scripts with mayapy to ensure that the correct python environment is used as the path to mayapy is not found in interactive shells.
These values are set as a string variable so we can pass it to the $SHELL command via the –rcfile option to setup our shell with custom aliases as well as your standard .bashrc file.
We can now run mayapy and test the USD version as follows:
from pxr import Usd
print("USD Build Info:", Usd.GetVersion())
>>> USD Build Info: (0, 21, 11)
As you can see this is a different version than the one houdini gives us.
Conclusions
This is setup to work in the NCCA labs. It is possible to setup your own scripts to do this on your own machine, but you will need to adjust the paths to match your own setup / OS.