PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
5.99k stars 1.18k forks source link

How to create iOS build #700

Open zeman-88 opened 5 years ago

zeman-88 commented 5 years ago

I would like to create an iOS build of the USD system so that I can export SCNScene assets from my app as USDZ files, but I don't know how to do that.

The built-in Model I/O API produces USD and USDA files in which the material information is lost, so I would like to write my own implementation that exports SceneKit files to USDZ using the library.

One solution would be to create an exporter to USDA and then somehow convert that to USDC off the device, but it would be great to be able to do everything on-device and that would be easy to implement if one could build the USD packages for iOS and use them to build a SceneKit to USDZ exporter.

spiffmon commented 5 years ago

There are several things about USD's build/install structure and certain features that are problematic for iOS. Apple currently applies some patches with implications/limitations for their iOS build. There definitely is interest in figuring out how to accommodate those needs in the stock USD build, but it involves at least one significant project that we don't yet have on our roadmap, and I can't speak for Apple.

--spiff

On Mon, Nov 19, 2018 at 9:51 AM zeman-88 notifications@github.com wrote:

I would like to create an iOS build of the USD system so that I can export SCNScene assets from my app as USDZ files, but I don't know how to do that.

The built-in Model I/O API produces USD and USDA files in which the material information is lost, so I would like to write my own implementation that exports SceneKit files to USDZ using the library.

One solution would be to create an exporter to USDA and then somehow convert that to USDC off the device, but it would be great to be able to do everything on-device and that would be easy to implement if one could build the USD packages for iOS and use them to build a SceneKit to USDZ exporter.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PixarAnimationStudios/USD/issues/700, or mute the thread https://github.com/notifications/unsubscribe-auth/AF7qaFMmQKUf0pkGGF3uwFwJ1QLA-Tb0ks5uwu-KgaJpZM4Ypmh4 .

zeman-88 commented 5 years ago

@spiffmon thanks for the input; yes, in fact as I glanced through the cmake and build script code it looks like it wouldn't be straightforward to port it to iOS; e.g. the dependency on TBB.

I hope this gets integrated soon, as, in my opinion, the ability to edit a scene on mobile devices, say in AR, and then export it to USDZ, would be fantastic.

jtran56 commented 5 years ago

Filed as internal issue #USD-4924.

spiffmon commented 5 years ago

Agreed, @zeman-88, it would definitely be cool for apps to be able to create their own usdz files "natively". I don't know if the mechanics are practical enough, but we just found out about this cool service that will make usdz files for you online; don't know if the API is public and scriptable: https://www.vectary.com/3d-modeling-how-to/how-to-create-usdz-file-for-ar-online/

--spiff

On Mon, Nov 19, 2018 at 10:25 AM zeman-88 notifications@github.com wrote:

@spiffmon https://github.com/spiffmon thank for the input; yes, in fact as I glanced through the cmake and build script code it looks like it wouldn't be straightforward to port it to iOS; e.g. the dependency on TBB.

I hope this gets integrated soon, as, in my opinion, the ability to edit a scene on a mobile devices, say in AR, and then export it to USDZ, would be fantastic.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PixarAnimationStudios/USD/issues/700#issuecomment-439993361, or mute the thread https://github.com/notifications/unsubscribe-auth/AF7qaB44VK5X8CzclWbeM8nBtv741bUxks5uwveWgaJpZM4Ypmh4 .

zeman-88 commented 5 years ago

Thanks for the link @spiffmon , I'll take a look, but from a first glance it doesn't look scriptable. However, the upload-then-retrieve pipeline seems the easiest one at the moment, so maybe I'll create a simple API for that. One of the issues I see with this is that USD at the moment doesn't consume Collada files natively, so one cannot even go that easily from SCNScene -> Collada -> USD. I guess I'd have to also write a Collada -> USD parser.

Thanks for filing the issue @jtran56 , if it gets addressed (i.e. we get an iOS build of at least the Stage and USD packages), I'd be happy to work on the SCNScene -> USD front-end myself and then integrate it back in the main repo.

usmanredsoft-zz commented 5 years ago

Kindly upload Pixar USD maya Xcode project source?

MikeCernea commented 2 years ago

Hello, I am trying to achieve a similar task to what @zeman-88 started this thread back in 2018: export USDZ files on iOS.

I already have a working code that can export usdz meshes that runs on Windows and Linux, but I was only able to do that using shared libraries(.dll and .so).

There are two problems that I do not know how to overcome:

Anyone can point me in the right direction ?

HackerFoo commented 2 years ago

@MikeCernea I've found a way to generate USDZ files on iOS, although it's not ideal. My app can export to glTF, so:

  1. Export to glTF (as a .glb)
  2. Use GLTFSceneKit to load the glb.
  3. Use SceneKit to write the .usdz

Here's the Swift code that I use, which I license under the APL 2.0:

@_cdecl("convert_glb_to_usdz")
func convert_glb_to_usdz(_ path: UnsafePointer<CChar>) -> Bool {
    do {
        let base_url = URL(fileURLWithPath: String(cString: path))
        print("base_url: \(base_url)")
        let glb_url = base_url.appendingPathExtension("glb")
        let usdz_url = base_url.appendingPathExtension("usdz")
        let fileManager = FileManager.default
        try? fileManager.removeItem(at: usdz_url)
        if !fileManager.fileExists(atPath: glb_url.path) {
            return false
        }
        let sceneSource = GLTFSceneSource(url: glb_url)
        let scene = try sceneSource.scene()
        scene.rootNode.enumerateHierarchy({(node, stop) in
                                              if let material = node.geometry?.firstMaterial {
                                                  material.lightingModel = .physicallyBased
                                              }
                                          })
        scene.write(to: usdz_url, delegate: nil)
        return true
    } catch {
        print("\(error.localizedDescription)")
        return false
    }
}

This is called from some code written in Rust. Even though it's not much code, it took a long time to figure this out. It's not documented that SCNScene.write can write to USDZ. If you're already using SceneKit, exporting to USDZ is trivial.

There are also limitations, like this doesn't support vertex colors IIRC.