piemonte / obj2usdz

🦖 obj2usdz, convert .OBJ files to .USDZ on iOS
MIT License
64 stars 8 forks source link
3d arkit augmented-reality ios modelio obj pixar usd usdz wavefront

obj2usdz

Create .USDZ files from iOS itself in Swift.

Note

Since WWDC19, it's now possible to write usdz files natively using SceneKit. (thanks @cpheinrich)

This repo shared an older technique prior to it's the current recommended method:

import SceneKit
import ModelIO

let asset = MDLAsset(url: objPath)
let scene = SCNScene(mdlAsset: asset)
scene.write(to: <your-usdz-file-path>, delegate: nil)

Recommended at WWDC19

Previous Technique

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

Exporting to .USDZ

Copy the MDLAsset+usdz.swift file into your Xcode project and create .USDZ in the following way:

let objAsset = MDLAsset(url: objUrl)

let destinationFileUrl = URL(fileURLWithPath: "path/Scene.usdz")
objAsset.exportToUSDZ(destinationFileUrl: destinationFileUrl)

Resources

License

obj2usdz is available under the MIT license, see the LICENSE file for more information.