Viewing an apartment in 3D on the web
Using Unity3D, we built a 3D model viewer for the web and iPad. Unlike many Unity applications, our models live on our server and are dynamically loaded into the Unity viewer when the user wants to view that model.
In addition to the Unity viewer, our models are also used by our backend Lua-based processing pipeline. In this blog post, we'll explain what format we picked for storing models and why we picked it.
There are a large number of possible formats. For example, Sketchfab supports 25 native formats: ".blend, .obj, .dae, .ply, and much more!"
When we were thinking about format, a couple things were important to us:
Unity's proprietary format for streaming assets. Like a zip file, one AssetBundle can contain multiple assets of different file types. Unlike a zip file, AssetBundles cannot easily be "unzipped". AssetBundles have a small file size and load speedily into Unity. AssetBundles can be cached to Unity's cache folder on the client. Bundles built for web cannot be loaded on iOS and vice versa. A Unity Pro license and a Unity iOS Advanced license are required for building web and iOS bundles, respectively. iOS bundles must be built on a Mac.
An open format, OBJs are considered to be "universally accepted". OBJs are simple text files that are easy to open and read. Raw data from our 3D scanner comes in this format. There are several scipts for loading a Unity model from an OBJ. OBJs are large because each line represents one thing — a vertex, a face, etc. Loading an OBJ into Unity takes a long time.
Google's open format for storing and exchanging structured data across languages and platforms. Usually compared to XML, JSON, and more recently, Thrift, protocol buffers are compact and efficient — "think XML, but smaller, faster, and simpler." There are libraries for protocol buffers in many languages and protocol buffers need an external, user-defined schema to serialize and deserialize data.
Here is a summary of the strengths and weaknesses of each format.
In the end, we picked protocol buffers. Although they were only infrequently the best, they were never the worst. Next time we'll talk about some unexpected hiccups with using protobufs, Unity, and iOS.