2

Anyone aware of how to create usdz from obj on the fly? Our application creates an obj file using a third party library and for using the QLPreviewController we need to convert it to usdz format. There are ways to do that using the terminal but wondering if there is any way to do it programmatically?

1 Answers1

0

An engineer on my team figured this out last week! Creating USDZ files is funny right now - currently we can fake it by saving a USDC file and... renaming the extension!

First you'll want to load the .obj file at filePath as an MDLAsset

NSURL *url = [NSURL fileURLWithPath:filePath];
MDLAsset *asset = [[MDLAsset alloc]initWithURL:url];

ensure the MDLAsset can write the desired extensions usdc is supported (USD binary format)

if([MDLAsset canExportFileExtension:@"usdc"]){
  NSLog(@"able to export as usdc");

  // save the usdc file
  [asset exportAssetToURL:usdcUrl];
}

rename the usdc to usdz because that's all it takes

NSError *renameErr;
NSFileManager *fm = [[NSFileManager alloc] init];
BOOL mvResult = [fm moveItemAtPath:usdcPath toPath:usdzPath error:& renameErr];
if(! mvResult){
  NSLog(@"Error renaming usdz file: %@", [renameErr localizedDescription]);
}

Hope this helps until Apple can give us a more thorough how-to. If you want to read a more long form breakdown of this - https://www.scandy.co/blog/how-to-export-simple-3d-objects-as-usdz-on-ios

gtfargo
  • 337
  • 2
  • 5