Convert Wavefront .OBJ files to .USDZ from an iOS device in Swift.
With the introduction of the USDZ format and iOS 12, Apple provided guidance only for creating .usdz
files using their macOS commandline tool:
xcrun usdz_converter Tyrannosaurus.obj Tyrannosaurus.usdz
-g TyrannosaurusMesh
-color_map Tyrannosaurus_Color.png
-metallic_map Tyrannosaurus_Metallic.png
-roughness_map Tyrannosaurus_Roughness.png
-normal_map . Tyrannosaurus_Normal.png
-emissive_map Tyrannosaurus_Emissive.png
Thanks to the discovery from the folks at scandy, there is a means to create USDZ files from iOS itself.
Copy the MDLAsset+usdz.swift
file into your Xcode project.
let objAsset = MDLAsset(url: objUrl)
let destinationFileUrl = URL(fileURLWithPath: "path/Scene.usdz")
objAsset.exportToUSDZ(destinationFileUrl: destinationFileUrl)
obj2usdz
is available under the MIT license, see the LICENSE file for more information.