Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Latest commit

 

History

History
57 lines (39 loc) · 1.98 KB

README.md

File metadata and controls

57 lines (39 loc) · 1.98 KB

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.