google / usd_from_gltf

Apache License 2.0
547 stars 85 forks source link

USD from glTF

Library, command-line tool, and import plugin for converting glTF models to [USD] (https://graphics.pixar.com/usd/docs/index.html) formatted assets for display in AR Quick Look.

Please note that this is not an officially supported Google product.

This is a C++ native library that serves as an alternative to existing scripted solutions. Its main benefits are improved compatibility with iOS and conversion speed (see Compatibility and Performance). It is treating USDZ as a transmission format rather than an interchange format. For more information about transmission and interchange file formats see here.

TLDR: Install it, then convert with: usd_from_gltf <source.gltf> <destination.usdz>

Background

glTF is a transmission format for 3D assets that is well suited to the web and mobile devices by removing data that is not important for efficient display of assets. USD is an interchange format that can be used for file editing in Digital Content Creation tools (ie. Maya).

However, iOS Quick Look supports displaying USDZ files with a subset of the USD file specification. This tool converts glTF files to USDZ for display in Quick Look, attempting to emulate as much of glTF’s functionality as possible in iOS Quick Look runtime.

The emulation process is lossy. For example, to support double sided glTF materials, the geometry is doubled. This allows the converted glTF to display correctly on iOS, but importing back into a DCC application will not be the same data as the original source file.

This tool specifically addresses the use case of converting a file from glTF->USDZ->QuickLook. Going DCC->glTF optimizes the asset for runtime viewing, and may lose information if the converted USDZ is imported back in the DCC tool, like subdivision surfaces.

When converting glTF->USD->DCC, Apple's USDPython tools will better preserve the data in the glTF file at the cost of not having the same compatibility with existing versions of iOS Quick Look.

Installation Steps

Using the Command-Line Tool

The command-line tool is called usd_from_gltf and is in the {UFG_BUILD}/bin directory. Run it with (use --help for full documentation):

usd_from_gltf <source.gltf> <destination.usdz>

Batch Converting and Testing

The library contains {UFG_SRC}/tools/ufgbatch/ufgbatch.py to facilitate batch conversion. Run it with (use --help for full documentation):

python {UFG_SRC}/tools/ufgbatch/ufgbatch.py my_tests.csv --exe "{UFG_BUILD}/bin/usd_from_gltf"

Each input CSV contains a list of conversion tasks of the form:

name,path/to/input.gltf,dir/to/output/usd[, optional usd_from_gltf flags]

The library also contains {UFG_SRC}/tools/ufgbatch/ufgtest.py to facilitate testing, and preview deployment. Run it with (use --help for full documentation):

python {UFG_SRC}/tools/ufgbatch/ufgtest.py my_tests.csv --exe "{UFG_BUILD}/bin/usd_from_gltf"

For development and testing, the ufgtest.py has a couple additional features:

Using the Library

The converter can be linked with other applications using the libraries in {UFG_BUILD}/lib/ufg. Call ufg::ConvertGltfToUsd to convert a glTF file to USD.

Using the Import Plugin

The plugin isn't necessary for conversion, but it's useful for previewing glTF files in UsdView.

To use it, set the PXR_PLUGINPATH_NAME environment variable to the directory containing plugInfo.json. See ufginstall script output for the path.

Compatibility

While USD is a general-purpose format, this library focuses on compatibility with AR Quick Look. The AR Quick Look renderer only supports a subset of the glTF 2.0 specification though, so there are several limitations. Where reasonable, missing features are emulated in an effort to reproduce glTF files as faithfully as possible on iOS. The emulation can be lossy process and the output is not well suited as an interchange format.

Key Features

Emulated Functionality for AR Quick Look

Several rendering features of glTF are not currently supported in AR Quick Look, but they are emulated where reasonable. The emulated features are:

Features Unsupported by AR Quick Look

These features are not supported in AR Quick Look, and cannot be reasonably supported by the converter.

Rendering Differences Between glTF and AR Quick Look

The AR Quick Look renderer does not precisely match the rendering model described by the glTF spec, but it is reasonably close. There are a few exceptions:

Potential solutions to unsupported issues

Performance

usd_from_gltf is roughly 10-15x faster than current alternatives.

The bulk of the conversion time is spent in image processing and recompression, necessary for emulating otherwise unsupported functionality in AR Quick Look.

Primary Optimizations

Benchmarks

Each benchmark was run 3 times on a Xeon E5-1650 @ 3.50GHz with 6 cores, 2x hyperthreaded for 12 hardware threads.

Converting 55 glTF sample models to USDZ:

Converting 28 complex skinned and animated glTF models to USDZ:

Troubleshooting

If you are having trouble building or running usd_from_gltf, please follow the steps below.