Pixar USD - feliyur/exercises GitHub Wiki

Installation

Instructions here https://github.com/PixarAnimationStudios/USD/blob/release/README.md#getting-and-building-the-code (accessed Jan 2022).

On python 3.7 / Ubuntu 18.04, had to

pip install pyside2
pip install PyOpenGL

Then clone and run the installation

> git clone https://github.com/PixarAnimationStudios/USD
Cloning into 'USD'...

> python USD/build_scripts/build_usd.py /usr/local/USD
...
STATUS: Installing boost...
STATUS: Installing TBB...
STATUS: Installing OpenSubdiv...
STATUS: Installing USD...

Success! To use USD, please ensure that you have:

    The following in your PYTHONPATH environment variable:
    /opt/USD/lib/python

    The following in your PATH environment variable:
    /opt/USD/bin

Added /opt/USD/bin to .bashrc. Added the other one to the end of my python virtual environment activation script (<virtualenv dir>/bin/activate) to make it available inside the virtual environment.

After adding the env vars, get them defined by source .bashrc (and re-activate your virtualenv if relevant), then can test if everything went well with

python -c 'import pxr'

which should succeed.

Tutorials

NVIDIA tutorial for ISAAC: https://developer.nvidia.com/usd/tutorials

PIXAR tutorials: https://graphics.pixar.com/usd/release/tut_usd_tutorials.html

Basic usage in python - Listing objects, getting object translation

Tested with Pixar Kitchen_set free environment. To obtain it:

wget https://graphics.pixar.com/usd/files/Kitchen_set.zip? -O Kitchen_set.zip
unzip Kitchen_set.zip

Now, load it using pxr

from pxr import Usd

# Load the scene
stage = Usd.Stage.Open('Kitchen_set/Kitchen_set.usd')

Can list scene contents using

> stage.FindLoadable()
[Sdf.Path('/Kitchen_set/Arch_grp/Kitchen_1'),                                                             
 Sdf.Path('/Kitchen_set/Props_grp/Ceiling_grp/CeilingLight_1'),                                           
 Sdf.Path('/Kitchen_set/Props_grp/DiningTable_grp/ChairB_1'),                                             
 Sdf.Path('/Kitchen_set/Props_grp/DiningTable_grp/ChairB_2'),                                             
 Sdf.Path('/Kitchen_set/Props_grp/DiningTable_grp/KitchenTable_1'),                                       
 Sdf.Path('/Kitchen_set/Props_grp/DiningTable_grp/TableTop_grp/CerealBowl_grp/BowlD_1'),                  
 Sdf.Path('/Kitchen_set/Props_grp/DiningTable_grp/TableTop_grp/CerealBowl_grp/Cheerios_grp/CheerioA_1'),  
 Sdf.Path('/Kitchen_set/Props_grp/DiningTable_grp/TableTop_grp/CerealBowl_grp/Cheerios_grp/CheerioA_10'), 
... 
 Sdf.Path('/Kitchen_set/Props_grp/West_grp/TinCanA_2'),
 Sdf.Path('/Kitchen_set/Props_grp/West_grp/WestWall_grp/FramePictureB_1'),
 Sdf.Path('/Kitchen_set/Props_grp/West_grp/WestWall_grp/FramePictureD_1'),
 Sdf.Path('/Kitchen_set/Props_grp/West_grp/WestWall_grp/FramePictureOval_1'),
 Sdf.Path('/Kitchen_set/Props_grp/West_grp/WestWall_grp/PaperLarge_1'),
 Sdf.Path('/Kitchen_set/Props_grp/West_grp/WestWall_grp/PaperSmall_1'),
 Sdf.Path('/Kitchen_set/Props_grp/West_grp/WestWall_grp/ShellSmall_1'),
 Sdf.Path('/Kitchen_set/Props_grp/West_grp/WestWall_grp/ShellSmall_2')]


Get the kitchen table Prim(itive):

> table_prim = stage.GetPrimAtPath('/Kitchen_set/Props_grp/DiningTable_grp/KitchenTable_1')
> table_prim.GetAttributes()
[Usd.Prim(</Kitchen_set/Props_grp/DiningTable_grp/KitchenTable_1>).GetAttribute('purpose'),
 Usd.Prim(</Kitchen_set/Props_grp/DiningTable_grp/KitchenTable_1>).GetAttribute('visibility'),
 Usd.Prim(</Kitchen_set/Props_grp/DiningTable_grp/KitchenTable_1>).GetAttribute('xformOp:translate'),
 Usd.Prim(</Kitchen_set/Props_grp/DiningTable_grp/KitchenTable_1>).GetAttribute('xformOpOrder')]

To Get the position:

> from pxr import UsdGeom
> op = UsdGeom.XformOp(table_prim.GetAttribute('xformOp:translate'))
> op.Get()
Gf.Vec3d(148.60921478271484, -165.71975326538086, -0.1450519561767578)

Or

> table_prim.GetAttribute('xformOp:translate').Get()
Gf.Vec3d(148.60921478271484, -165.71975326538086, -0.1450519561767578)

Another way to achieve the same thing + get also the orientation:

> xform = UsdGeom.Xform(table_prim)
> xform.ComputeLocalToWorldTransform(time=0)
Gf.Matrix4d(1.0, 0.0, 0.0, 0.0,
            0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 1.0, 0.0,
            148.60921478271484, -165.71975326538086, -0.1450519561767578, 1.0)