Creating an Omniverse USD app from the Connect Sample

Creating a Windows USD App from the Omniverse Connect Sample

This post describes how to create a simple application that will open a USD stage located on an Omniverse Nucleus server. Once the stage is open it will simply report the stage up-axis, the stage linear units, and list all of the prim node paths.

  • Video Overview
    Here’s a link to a video that walks through these directions (if videos are your thing).

  • Download the Connect Sample

    Directions for downloading the Connect Sample and finding where it is installed are in the Omniverse Connect Sample Launcher docs.

  • Create a Windows Console App

    Use the “Create a new project” Console App template in Visual Studio to generate a “Hello World” console application.

  • Dependencies for Omniverse Client Library and USD

    Both the Omniverse Client Library and NVIDIA’s modified USD SDK are required, so the first thing to do is to copy them into the project structure of the simple app.

    From the Connect Sample root folder, these two folders should be copied (after the dependencies are fetched using either prebuild.bat or build.bat:

    • _build\target-deps\nv_usd
    • _build\target-deps\omni_client_library

    Both of these dependencies contain symbolic links, so care must be taken when copying them into the simple app’s folders. Robocopy does a good job of deep-copying symbolic links. The deps folder will hold the USD and Client Library dependencies for the application. Note that in this case the simple project is located in the X:\tmp\OmniUSDReader directory.

    • robocopy /S _build\target-deps\nv_usd X:\tmp\OmniUSDReader\deps\nv_usd
    • robocopy /S _build\target-deps\omni_client_library X:\tmp\OmniUSDReader\deps\omni_client_library
  • Project Settings

    Because this application uses USD, that also means it uses Boost and TBB which require libraries, preprocessor definitions, and additional options. Also note that we only provide the 64 bit x64 platform binaries, so don’t try to build for the 32 bit platform in Visual Studio.

  1. Additional Library Directories:
  • Debug
    • deps\nv_usd\debug\lib;deps\omni_client_library\debug
  • Release
    • deps\nv_usd\release\lib;deps\omni_client_library\release
  1. Additional Dependencies:

    • Debug
      • ar.lib;arch.lib;gf.lib;js.lib;kind.lib;pcp.lib;plug.lib;sdf.lib;tf.lib;trace.lib;usd.lib;usdGeom.lib;vt.lib;work.lib;usdShade.lib;usdLux.lib;omniclient.lib;python37.lib;boost_python37-vc141-mt-gd-x64-1_68.lib
    • Release
      • ar.lib;arch.lib;gf.lib;js.lib;kind.lib;pcp.lib;plug.lib;sdf.lib;tf.lib;trace.lib;usd.lib;usdGeom.lib;vt.lib;work.lib;usdShade.lib;usdLux.lib;omniclient.lib;python37.lib;boost_python37-vc141-mt-x64-1_68.lib
    • Note that the boost python library is the only difference between debug and release

  2. C/C++ Additional Options (to silence warnings):

    • /wd4244 /wd4305
  3. C/C++ Additional Include Directories:

    • Debug
      • deps\nv_usd\debug\include;deps\omni_client_library\include
    • Release
      • deps\nv_usd\release\include;deps\omni_client_library\include
  4. C/C++ Preprocessor Definitions:

    • Debug
      • BOOST_ALL_DYN_LINK;TBB_USE_DEBUG=1;NOMINMAX
    • Release
      • BOOST_ALL_DYN_LINK;TBB_USE_DEBUG=0;NOMINMAX
  • Post-build Event to Copying Runtime Dependencies

    There are a lot of runtime dependencies, to make things easy they are simply copied to the same folder as the output executable. A batch file that runs after the app is built makes this convenient and free of errors.

    The copy_binary_deps.bat script is run after each build and puts the runtime dependencies in the correct place:

  1. Post-Build Event
    • Debug
      • scripts\copy_binary_deps.bat debug $(OutputPath)
    • Release
      • scripts\copy_binary_deps.bat release $(OutputPath)
@echo off
:: copy the USD and OmniClient libs to the $(OutputPath)
:: parameters:
:: 1. debug or release
:: 2. $(OutputPath)
set BUILD_CONFIG=%1
set OUTPUT_PATH=%2
set RC_OPTS=/NP /NJH /NJS /NS /NC /NFL /NDL

echo Copying deps\nv_usd\%BUILD_CONFIG%\lib contents to %OUTPUT_PATH%
robocopy /S deps\nv_usd\%BUILD_CONFIG%\lib %OUTPUT_PATH% %RC_OPTS%
echo Copying deps\omni_client_library\%BUILD_CONFIG% contents to %OUTPUT_PATH%
robocopy /S deps\omni_client_library\%BUILD_CONFIG% %OUTPUT_PATH% %RC_OPTS%
exit /B 0
  • Simple App Overview

    The application performs a few simple things:

    • Expects one argument, the path to a USD stage
      • Acceptable forms:
        • omniverse://localhost/Users/test/helloworld.usd
        • C:\USD\helloworld.usd
        • A relative path based on the CWD of the program (helloworld.usd)
    • Initialize Omniverse
      • Set the Omniverse Client log callback
      • Set the Omniverse Client log level
      • Initialize the Omniverse Client library
      • Register an Omniverse Client status callback
    • Open the USD stage
    • Print the stage’s up-axis
    • Print the stage’s linear units, or “meters per unit” setting
    • Traverse the stage prims and print the path of each one
    • Destroy the stage object
    • Shutdown the Omniverse Client library
  • Sources
    OmniUSDReader.cpp (4.9 KB)
    copy_binary_deps.bat (529 Bytes)

2 Likes

Patrick Palmer was gracious enough to codify my steps into cmake project files and modules. This is useful for those adding Omniverse Connectors into a larger existing C++ structured project. This is a lightweight cmake integration at this point but enough to get started.