Code Monkey home page Code Monkey logo

gltf-to-usdz-research's Introduction

glTF to USDZ research

Research and proof of concept of converting glTF to USDZ for AR Quick Look (iOS 12+).

Reasoning

Even though I think the intentions of Apple / Pixar are great with the open source USD pipeline I think we as an industry should be relying more on truly open formats that are not controlled by a single entity. Installing USD is cumbersome, requires a lot of disk space and is completely overkill for most situations (if your goal is to convert some 3D models to USDZ and show them using AR Quick Look). I'm hoping that as we get closer to the public release of iOS 12 more tools will pop up that directly convert to USDZ so that we can get cross-platform support.

In order to move away from using the USD pipeline solution offered by Pixar I think it would be wise to try and manipulate the intermediary readeable USDA format. Unfortunately there are very little examples available of USDA files.

The general idea is to dynamically generate / manipulate the intermediary a general USDA file-structure and pass that to the usdz-converter to handle the further conversion to USDZ.

After some work, debugging and friendly help from @domenicopanacea and @virakri I got it to work. Most of the findings on OBJ support come from @trayser who posted details regarding OBJ to USDZ conversion on developers.apple.com. The OBJ files that are generated by gltf-to-usdz only use the supported tags as mentioned by @trayser.

Please note that this is just an experimental setup and should be seen as a proof of concept. As it stands I've only tested it with the DamagedHelmet glTF asset included in /assets/. You will very likely run into issues with the current code.

My goal of this research is to inspire others to make proper converters that handle all the complexities.

Live demo

Live demo

Screenshot

Limitations

  • .glb files are not yet accepted. Please use glTF files with seperate textures.

  • Only the first mesh in the glTF file will be parsed and exported. Make sure you merge all meshes.

  • Only glTF files with external textures are currently handled (as opposed to embedded base64 encoded textures).

  • Animations from the glTF are not yet transferred, it seems possible to transfer skeleton animation and regular transformations. Unfortunately due to the shadow being baked on the first frame of the animation you can't really do large moving animations. Besides that the filesize increases quite dramatically. It is not recommended to have animations that move a character away from the origin as it results in tracking problems. Your best bet are micro-animations that enhance a character or model instead of large animations.

To do

  • Convert the example USDZ examples to USDA structures by converting USDC to USDA. Unfortunately I think this requires the installation of the USD pipeline and the use of usdcat.

    Thanks to @wave-electron the USDC's of the examples of the AR Quick Look gallery have been converted to USDA. Due to copyright concerns I unfortunately won't be able to upload them to this repo. I've had a look at them and for the most part look very similar compared to the USDA file generated by gltf-to-usdz. I've since also been able to convert the examples myself using usdcat.

Installation

  • Make sure you have Node.js installed

  • Upgrade your operating system to macOS High Sierra 10.13.4 or newer

  • Download Xcode 10 beta and put it in /Applications/

https://developer.apple.com/download/
  • Link to the beta version instead of the normal version
sudo xcode-select --switch /Applications/Xcode-beta.app
  • Construct a new .usda using gltf-to-usdz and run it through the usdz_converter
node ./bin/gltf-to-usdz.js -i ./assets/DamagedHelmet/DamagedHelmet.gltf -o ./assets/DamagedHelmet.usda -s 10.0 && xcrun usdz_converter ./assets/DamagedHelmet.usda ./assets/DamagedHelmet-`date +"%H-%M-%S"`.usdz
  • On succes the following should be outputted to the console
2018-06-20 17:21:23.364 usdz_converter[82749:13335731]


Converting asset file 'DamagedHelmet.usda' ...

In order to see the contents of the outputted USDZ change the extension to .zip and unzip it. You will see a .usdc and several textures (if the original glTF file had textures).

Development

In order to install USD on MacOS please follow the following instructions:

  • Upgrade your operating system to macOS High Sierra 10.13.4 or newer

  • Download Xcode 10 beta and put it in /Applications/

https://developer.apple.com/download/
  • Link to the beta version instead of the normal version
sudo xcode-select --switch /Applications/Xcode-beta.app
  • Install Cmake and QT. If you get any issues during compiling or installing you might have to install QT5.
brew install cmake
brew install qt@4
  • Install PyOpenGL
pip install PyOpenGL
  • Install PySide2
pip install --index-url=http://download.qt.io/snapshots/ci/pyside/5.9/latest/ pyside2 --trusted-host download.qt.io
  • Update OpenImageIO release version from Release-1.7.14.zip to Release-1.8.12.zip and add the following section in build_scripts/build_usd.py as mentioned as a solution by @robpieke to an earlier Python crash I was experiencing.
diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py
index 37fb2a5e..3c940b3b 100644
--- a/build_scripts/build_usd.py
+++ b/build_scripts/build_usd.py
@@ -692,7 +692,7 @@ PTEX = Dependency("Ptex", InstallPtex, "include/PtexVersion.h")
 ############################################################
 # OpenImageIO

-OIIO_URL = "https://github.com/OpenImageIO/oiio/archive/Release-1.7.14.zip"
+OIIO_URL = "https://github.com/OpenImageIO/oiio/archive/Release-1.8.12.zip"

 def InstallOpenImageIO(context, force):
     with CurrentWorkingDirectory(DownloadURL(OIIO_URL, context, force)):
@@ -855,6 +855,12 @@ def InstallUSD(context):

         if context.buildPython:
             extraArgs.append('-DPXR_ENABLE_PYTHON_SUPPORT=ON')
+            if MacOS():
+                import distutils.sysconfig
+                pyLibPath = distutils.sysconfig.get_config_var('LIBDIR')
+                pyIncPath = distutils.sysconfig.get_config_var('INCLUDEPY')
+                extraArgs.append('-DPYTHON_LIBRARY=' + pyLibPath + '/libpython2.7.dylib')
+                extraArgs.append('-DPYTHON_INCLUDE_DIR=' + pyIncPath)
         else:
             extraArgs.append('-DPXR_ENABLE_PYTHON_SUPPORT=OFF')
  • Run python USD/build_scripts/build_usd.py BUILD, it will take roughly 1 hour the first time you build because of all the dependencies that need to be compiled, resulting in the following output if succesfully installed:
โžœ  pixar python USD/build_scripts/build_usd.py BUILD

Building with settings:
  USD source directory          /Users/timvanscherpenzeel/Projects/pixar/USD
  USD install directory         /Users/timvanscherpenzeel/Projects/pixar/BUILD
  3rd-party source directory    /Users/timvanscherpenzeel/Projects/pixar/BUILD/src
  3rd-party install directory   /Users/timvanscherpenzeel/Projects/pixar/BUILD
  Build directory               /Users/timvanscherpenzeel/Projects/pixar/BUILD/build
  CMake generator               Default
  Downloader                    curl

  Building                      Shared libraries
    Imaging                     On
      Ptex support:             Off
    UsdImaging                  On
    Python support              On
    Documentation               Off
    Tests                       Off
    Alembic Plugin              Off
      HDF5 support:             Off
    Maya Plugin                 Off
    Katana Plugin               Off
    Houdini Plugin              Off

    Dependencies                zlib, boost, TBB, JPEG, TIFF, PNG, OpenEXR, GLEW, OpenImageIO, OpenSubdiv

STATUS: Installing zlib...
STATUS: Installing boost...
STATUS: Installing TBB...
STATUS: Installing JPEG...
STATUS: Installing TIFF...
STATUS: Installing PNG...
STATUS: Installing OpenEXR...
STATUS: Installing GLEW...
STATUS: Installing OpenImageIO...
STATUS: Installing OpenSubdiv...
STATUS: Installing USD...

Success! To use USD, please ensure that you have:

    The following in your PYTHONPATH environment variable:
    /Users/timvanscherpenzeel/Projects/pixar/BUILD/lib/python

    The following in your PATH environment variable:
    /Users/timvanscherpenzeel/Projects/pixar/BUILD/bin

Taking apart a USDZ file

To take apart a USDZ file one should follow the following steps:

  1. Follow the steps mentioned in Development to install USD
  2. Change the extension of the usdz file from .usdz to .zip
  3. Unzip the file using Archive Utility (comes with MacOS) or likely any other unzipping tool

The folder will contain the included textures seperated out and a .udsc file.

  1. Now use usdcat to convert the USDC file to readeable USDA: usdcat input.usdc -o output.usda

The resulting USDA file will contain the mesh data.

Resources

Contributing

As it is my goal to create a community project I welcome you to submit any pull requests or open a ticket if you spot an issue. Please be aware that as of now the project is in a very experimental state and only serves as a proof of concept so there are probably lots of things wrong and the code is far from clean.

Licence

gltf-to-usdz is released under the MIT licence.

gltf-to-usdz-research's People

Contributors

enzyme69 avatar ox avatar timvanscherpenzeel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gltf-to-usdz-research's Issues

Update fileLoader to read bin/texture files from remote URL

Hi,

I saw that you have already abstracted a fileLoader (which currently is just a fs wrapper): could that mean that you are planning to add support for automatic remote file download in this project? This would make this converter extremely flexible, and directly usable for our needs, since we are internally using glTFs with remote assets stored on Amazon S3.

I am aware the http[s]:// URIs are in fact not clearly part of the glTF 2.0 standard, but we decided that for web purposes it made a lot more sense to keep assets separate, especially because we have a lot of cases where many assets are shared between different models.

Thanks for the awesome work in any case!

Tips on converting GLTF + BIN + Textures?

I am testing some GLTF model from Sketchfab, so far I have no luck...

For example:
https://sketchfab.com/models/1a9db900738d44298b0bc59f68123393

The Skull model has GLTF file + BIN + textures.

When converting, I can't seem to get the proper result, the USDA and USDZ generated has no mesh...

192-168-1-4:gltf-to-usdz-master jimmygunawan$ node ./bin/gltf-to-usdz.js -i ./assets/skull/scene.gltf -o ./assets/skull.usda -s 10.0 && xcrun usdz_converter ./assets/skull.usda ./assets/skull-`date +"%H-%M-%S"`.usdz
componentType is unknown
Written file to ./assets/scene_baseColorTexture.jpg
Written file to ./assets/scene_normalTexture.jpg
Written file to ./assets/skull.usda
Written file to ./assets/scene.obj
usd_converter converting file: ./assets/skull.usda
converted usdz file: ./assets/skull-22-55-38.usdz
Warning (secondary thread): in UsdObjTranslateObjToUsd at line 235 of /BuildRoot/Library/Caches/com.apple.xbs/Sources/3DAssetTools/3DAssetTools-14207.5/external/ModelKit/extern/usd/pxr/usd/usdObj/translator.cpp -- No valid groups were found, no mesh translation will occur.
Warning: in _ReportErrors at line 2601 of /BuildRoot/Library/Caches/com.apple.xbs/Sources/3DAssetTools/3DAssetTools-14207.5/external/ModelKit/extern/usd/pxr/usd/usd/stage.cpp -- Instantiating stage:
    Unresolved  path </model> on prim @assets/skull.usda@,@anon:0x7fbcb744b0f0:skull-session.usda@</Mesh_0>.

Warning: in UsdObjTranslateObjToUsd at line 235 of /Library/Caches/com.apple.xbs/Sources/ModelKit/ModelKit-1.94.23/ModelKit/extern/usd/pxr/usd/usdObj/translator.cpp -- No valid groups were found, no mesh translation will occur.
Warning: in _ReportErrors at line 2601 of /Library/Caches/com.apple.xbs/Sources/ModelKit/ModelKit-1.94.23/ModelKit/extern/usd/pxr/usd/usd/stage.cpp -- Instantiating stage:
    Unresolved  path </model> on prim @/Users/jimmygunawan/gltf-to-usdz-master/assets/skull_$$usd_converter$$_.usdc@,@anon:0x7fbcb8b4d4b0:skull_$$usd_converter$$_-session.usda@</Mesh_0>.

Cannot find GLTF Validator

I am not actually very familiar with node.js, but I downloaded your github and run the command, but keep getting the same error:

192-168-1-4:gltf-to-usdz-master jimmygunawan$ node ./bin/gltf-to-usdz.js
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'gltf-validator'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Users/jimmygunawan/gltf-to-usdz-master/lib/index.js:5:23)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

Animation Support?

Wondering if there has been any progress on supporting animation. I use blender. Would be nice to be able to create an animated usdz with free software.

componentType 5125 is unknown

Can't convert this model can you help me out?

It gives me this error while converting to usda. "componentType 5125 is unknown"

And then the usda to usdz converter says: "There are 0 vertices in this asset file 'shoe.usda'."

shoe.zip

Discussion

Hi Tim,

Firstly, thanks for sharing everything you've done with USDZ recently. There is a lack of information on this new format, I haven't found anything on creating a USDZ animation except the usda example of the spinning top in the pixar usd docs.

Just wanted to let you know that I successfully installed USD on my mac system version 10.13.5 today.

usdcat is converting between the usda -> usdc
usdview is working with gui.

It was a struggle getting the thing to build... it took nearly the whole day.

I followed your build instruction, however, at one stage during the build it complained about qt5 missing so I installed that as well. I also had other build problems because I screwed with

  sudo xcode-select --switch /Applications/Xcode-beta.app

as my version was name /Applications/Xcode-beta 10.app

screenshot

Anyway, thought I'd share just to let you know it does build eventually on Mac!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.