17

At the 2018 WWDC Apple announced the introduction of new USDZ file format.

In relation to creating USDZ file the following was said:

To create your own usdz files, a usdz_converter has been bundled as part of Xcode 10 beta. Its a command line tool for creating the usdz file from OBJ files, Single-frame Alembic (ABC) files, USD file (either .usda or usd.c)

the basic command line is

xcrun usdz_converter myFile.obj myFile.usdz

I have installed Xcode 10 beta, but have been unable to run or even find usdz_converter in the Xcode 10 beta bundle made available on the 4th June 2018 (build 10L176w).

note: I’m still running on macOS highSierra, I have not installed macOS Mojave 10.14 beta yet... but didn’t think that should be the reason why.

Has anyone else been able to get this xcrun usdz_converter to work?

If so please share the steps.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Clay
  • 1,721
  • 2
  • 10
  • 18
  • 1
    What do you get when you run the command? I don't have a file to try to convert but when I run the command it prints out the usage description so it is at least there. – dan Jun 13 '18 at 21:58
  • 2
    xcrun: error: unable to find utility "usdz_converter", not a developer tool or in PATH – Clay Jun 13 '18 at 22:37
  • 1
    Make sure xcrun is looking in the right place, either by using `xcode-select` to set the active developer directory to the one in the Xcode-beta.app or giving it the full path to `usdz_converter` – dan Jun 13 '18 at 22:45
  • Ok, I have a couple of version of Xcode... so will look into that now. thanks – Clay Jun 13 '18 at 22:46
  • 1
    xcode-select -p /Applications/Xcode.app/Contents/Developer should be /Applications/Xcode-beta 10.app/Contents/Developer - thanks – Clay Jun 13 '18 at 22:49
  • ok this fixed the problem . sudo xcode-select --switch "/Applications/Xcode-beta 10.app/Contents/Developer" – Clay Jun 13 '18 at 22:56

3 Answers3

34

Updated: July 03, 2023.

usdzconvert command in Xcode 15, 14, 13, 12, 11

In macOS Sonoma, Ventura, Monterey, Big Sur and Catalina USDZ converter has a rich set of commands, and supports more input formats for conversion. But before using it you need to download and install USDZ Tools. And don't forget to setup global variables for Python usdz tools. Here's how a new command looks in Terminal:

usdzconvert ~/Desktop/file.gltf -diffuseColor albedo.png -metallic brass.jpg
  • In macOS Sonoma, Ventura, Monterey, Big Sur, Catalina, the default command shell is ZSH.


Create Shell Resource file

If you want to use USDPython tools you need to create a Shell Resource file .zshrc.

For that go to Home area using change directory command in Terminal:

cd /Users/<UserName>

Check whether you are there or not with parent working directory command:

pwd

Then type ls command for listing of directory's content including hidden files:

ls -a

Now you are ready to create a hidden .zshrc file:

touch ~/.zshrc

Open this file using the following command:

open ~/.zshrc

Now you can add these lines into zsh resource file:

export PATH="/Users/yourUserName/usdpython/USD:$PATH"
export PATH="/Users/yourUserName/usdpython/usdzconvert:$PATH"
export PYTHONPATH="/Users/yourUserName/usdpython/USD/lib/python:$PYTHONPATH"

echo "Now I can use USDPython commands here."

Save it and restart Terminal.

usdzconvert is a Python script that converts the following assets into usdz:

  • obj
  • gltf
  • fbx
  • abc
  • usd – you can export it from Maya 2024
  • usda
  • usdc

If you need to use FBX format conversion you have to download and install FBX Python SDK.

Then add to .zshrc file one more line:

export PYTHONPATH="/Applications/Autodesk/FBXPythonSDK/2020.0.1/lib/Python27_ub:$PYTHONPATH"

Save .zshrc file and restart Terminal.

Here's a full list of options you can see in Terminal, typing usdzconvert -h :

# DO NOT USE usdzconvert 0.63 BECAUSE IT CAUSES ERRORS.

# USE usdzconvert 0.66, or usdzconvert 0.65, or usdzconvert 0.64

outputFile                           Output .usd/usda/usdc/usdz files.
-h, --help                           Show this help message and exit.
-f <file>                            Read arguments from <file>
-v                                   Verbose output.
-url <url>                           Add URL metadata
-copyright "copyright message"       Add copyright metadata
-copytextures                        Copy texture files (for .usd/usda/usdc) workflows
-metersPerUnit value                 Set metersPerUnit attribute with float value
-loop                                Set animation loop flag to 1
-no-loop                             Set animation loop flag to 0
-m materialName                      Subsequent material arguments apply to this material.
-iOS12                               Make output file compatible with iOS 12 frameworks
-texCoordSet name                    The name of the texture coordinates to use for current material.
                        
-diffuseColor r,g,b                  Set diffuseColor to constant color r,g,b with values in the range [0 .. 1]
-diffuseColor <file> fr,fg,fb        Use <file> as texture for diffuseColor.
                                     fr,fg,fb: (optional) constant fallback color, with values in the range [0..1].
                        
-normal x,y,z                        Set normal to constant value x,y,z in tangent space [(-1, -1, -1), (1, 1, 1)].
-normal <file> fx,fy,fz              Use <file> as texture for normal.
                                     fx,fy,fz: (optional) constant fallback value, with values in the range [-1..1].
                        
-emissiveColor r,g,b                 Set emissiveColor to constant color r,g,b with values in the range [0..1]
-emissiveColor <file> fr,fg,fb       Use <file> as texture for emissiveColor.
                                     fr,fg,fb: (optional) constant fallback color, with values in the range [0..1].
                        
-metallic c                          Set metallic to constant c, in the range [0..1]
-metallic ch <file> fc               Use <file> as texture for metallic.
                                     ch: (optional) texture color channel (r, g, b or a).
                                     fc: (optional) fallback constant in the range [0..1]
                        
-roughness c                         Set roughness to constant c, in the range [0..1]
-roughness ch <file> fc              Use <file> as texture for roughness.
                                     ch: (optional) texture color channel (r, g, b or a).
                                     fc: (optional) fallback constant in the range [0..1]
                        
-occlusion c                         Set occlusion to constant c, in the range [0..1]
-occlusion ch <file> fc              Use <file> as texture for occlusion.
                                     ch: (optional) texture color channel (r, g, b or a).
                                     fc: (optional) fallback constant in the range [0..1]
                        
-opacity c                           Set opacity to constant c, in the range [0..1]
-opacity ch <file> fc                Use <file> as texture for opacity.
                                     ch: (optional) texture color channel (r, g, b or a).
                                     fc: (optional) fallback constant in the range [0..1]

-clearcoat c                         Set clearcoat to constant c, in the range [0..1]
-clearcoat ch <file> fc              Use <file> as texture for clearcoat.
                                     ch: (optional) texture color channel (r, g, b or a).
                                     fc: (optional) fallback constant in the range [0..1]

-clearcoatRoughness c                Set clearcoat roughness to constant c, in the range [0..1]
-clearcoatRoughness ch <file> fc     Use <file> as texture for clearcoat roughness.
                                     ch: (optional) texture color channel (r, g, b or a).
                                     fc: (optional) fallback constant in the range [0..1]


Reality Converter

Instead of using a command line conversion tool (CLI), you can use a Reality Converter app (GUI). This app makes it easy to convert, view, and customize .usdz models on Mac. Simply drag-and-drop common 3D file formats, such as .obj, .gltf or .fbx, to view the converted .usdz result, customize material properties with your own UV-mapped textures, and edit file metadata. You can even preview your .usdz object under a variety of lighting and environment conditions with built-in IBL options.

enter image description here

For .fbx conversion you have to download and install FBX C++ SDK.

Needed file is FBX SDK 2020.2.1 Clang (Universal Binary).

enter image description here


USDZ Export command in RC and RCP

In Reality Composer 1.5 for Xcode 14/13/12 you can export a usdz model right from Reality Composer's UI. For that you just need to activate a USDZ export in RealityComposer – Preferences menu.

enter image description here

In Reality Composer Pro 1.0 for Xcode 15 simply use File – Export command.


Also you can use AR USD Schemas and, of course, Autodesk Maya 2024 workflow.


Create USDZ file from SCN scene

Another way to generate an USDZ file is to convert it from the SceneKit's scene using the write(to:options:delegate:progressHandler:) instance method. If you need to generate a SCN scene from DAE file (prior to USDZ convertion), use Xcode's Editor menu, and Convert to SCN file format command.

Here's the code:

import SceneKit

class ViewController: UIViewController {

    @IBOutlet var sceneView: ARSCNView!
    let scene = SCNScene(named: "art.scnassets/ship.scn")!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        sceneView.scene = scene
        
        let path = FileManager.default.urls(for: .documentDirectory,
                                             in: .userDomainMask)[0]
                                   .appendingPathComponent("model.usdz")
        
        scene.write(to: path, options: nil, 
              delegate: nil, progressHandler: nil)
        
        print(path)
    }
}

enter image description here

Create SCN scene from USDZ file

In Xcode 15 you can easily convert USDZ to SCN using UI button.

enter image description here



xcrun usdz_converter command in Xcode 10

In macOS Mojave 10.14 and Xcode 10 USDZ converter has a slightly different set of arguments and flags. Here's how an old command looks like in Terminal:

xcrun usdz_converter file.obj file.usdz -color_map color.jpg -ao_map ao.png
  • In macOS Mojave the default command shell is BASH.

Here's a full list of options you can see in Terminal, typing xcrun usdz_converter -h :

-g groupName [groupNames ...]        Apply subsequent material properties to the named group(s).
-m materialName [materialNames ...]  Apply subsequent material properties to the named material(s).
-h                                   Display help.
-a                                   Generate a .usda intermediate file.  Default is .usdc.
-l                                   Leave the intermediate .usd file in the source folder.
-v                                   Verbose output.
-f                    filePath       Read commands from a file.
-texCoordSet          set            The name of the texturemap coordinate set to use if multiple exist (no quotes).
-opacity              o              Floating point value 0.0...1.0

-color_default        r g b a        Floating point values 0.0...1.0
-normal_default       r g b a        Floating point values 0.0...1.0
-emissive_default     r g b a        Floating point values 0.0...1.0
-metallic_default     r g b a        Floating point values 0.0...1.0
-roughness_default    r g b a        Floating point values 0.0...1.0
-ao_default           r g b a        Floating point values 0.0...1.0

-color_map            filePath
-normal_map           filePath
-emissive_map         filePath
-metallic_map         filePath
-roughness_map        filePath
-ao_map               filePath
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 1
    Do you may have any suggestions regarding using just the Python Tool without XCode? – Alberto Tono Jan 13 '21 at 07:26
  • 1
    I am stuck at `Error: failed to import pxr module. Please add path to USD Python bindings to your PYTHONPATH` ... what's the best way to solve this issue? – ChrisB Dec 22 '21 at 20:31
  • 1
    Hi @ChrisB! I renamed the library to `usdpython` and placed it inside Mac's `Home` directory. As you can see, the path is the following: `/Users//usdpython/`. – Andy Jazz Dec 22 '21 at 20:39
  • Thanks @AndyJazz, for the quick answer! I've moved the folder `usdpython` to my `~` folder and adjusted the `.zshrc` paths according to the instructions above to: ``export PATH="/Users/myuser/usdpython/USD:$PATH" export PATH="/Users/myuser/usdpython/usdzconvert:$PATH" export PYTHONPATH="/Users/myuser/usdpython/USD/lib/python:$PYTHONPATH"`` restarted the machine but still get the error. README says it's usdzconvert version 0.64. What else can I try? – ChrisB Dec 22 '21 at 20:54
  • 1
    I've found the solution: You need to open the terminal in Rosetta mode. Then it works. – ChrisB Dec 22 '21 at 22:29
  • For some reason the Rosetta mode fix does not work anymore and I'm back to the error `Error: failed to import pxr module. Please add path to USD Python bindings to your PYTHONPATH` despite having followed above instructions. What's the best way to debug this? I installed it on a brand new Mac, using Python from Homebrew. – ChrisB Aug 21 '22 at 22:00
  • 1
    I've also been trying the `xcrun` option but get: `xcrun: error: unable to find utility "usdz_converter", not a developer tool or in PATH` ... how can I install it or add it to PATH? – ChrisB Aug 21 '22 at 22:05
  • @ChrisB, what version of Xcode and USDTools are you using (trying to run `xcrun` instead of `usdzconvert`) ?? – Andy Jazz Aug 22 '22 at 04:38
8

You have to enable the Xcode 10 command line tools on Xcode > Preferences > Locations

Example

George
  • 25,988
  • 10
  • 79
  • 133
Abraham Torres
  • 141
  • 1
  • 3
0

You have to activate the command line tools in Xcode preferences, in case they're not actived yet (that was my case). See this topic:

How to create a USDZ file?

Matthijs
  • 515
  • 4
  • 8