ning-y / Palantir

An Android application visualising proteins in augmented reality!
https://play.google.com/store/apps/details?id=io.ningyuan.palantir
MIT License
4 stars 4 forks source link

Dynamically generate binary glTF files from Wavefront .obj files #4

Closed ning-y closed 5 years ago

ning-y commented 5 years ago
          vmd             gradle task
  .pdb ---------> .obj -----------------> .sfa/.sfb

Based off the above envisioned pipeline for files representing 3D models, before I get into the conversion with vmd, I should tackle the conversion from .obj to .sfa/.sfb. This is currently handled by a gradle task, but eventually when users add models either through

I will have to produce .sfa/.sfb files during run-time.

ning-y commented 5 years ago

It seems to be a difficult task to generate Sceneform asset files during runtime, since Google's Sceneform is closed sourced, so there's no Java API exposed for that. There is a gradle task for .obj to .sfa/.sfb, of course, but to call gradle tasks from Java seems a tad bit messy.

Fortunately, Sceneform supports loading 3D models from .glTF on runtime, so I'll just use that. Unfortunately, .glTF is not a render option in VMD, so I'll have to convert its rendered .obj to .glTF. The pipeline now looks as follows,

         vmd           jgltf-obj         
  .pdb -------> .obj -------------> .glTF

where jgltf-obj is a Java library for .obj to .glTF conversion I found here.

ning-y commented 5 years ago

Another hiccup: the Sceneform library cannot handle all glTF files. It fails on glTF files with embedded resources (see https://github.com/google-ar/sceneform-android-sdk/issues/473).

Instead, convert Wavefront .obj files to binary glTF files (*.glb), which Sceneform seems to handle better. Fortunately, jgltf-obj also handles conversions from Wavefront .obj to binary glTF. The pipeline is now,

         vmd           jgltf-obj         
  .pdb -------> .obj -------------> .glb