Render Your Own 3D Model in QCAR

Teapot 3D Model

Note: this article is short and doesn’t give detailed answers as much as I would have liked. I started writing it a while ago and realized it had never been published. I haven’t worked with QCAR for a couple of months now, so the subject isn’t so fresh in my mind anymore. Here it goes…

I’ve worked with QCAR for about two months earlier this summer. Using the library is very easy, and it gives pretty good results in terms of responsiveness and robustness. But because my knowledge of OpenGL is very limited, my worst problem has been importing my own 3D model and making it render correctly (with textures and proper lighting).

Use Blender to triangulate

First, mobile devices don’t run the standard OpenGL library, they run OpenGL ES. This means 3D models have to be triangulated or they won’t render at all. Triangulation is the process of dividing all polygons into triangles.

Blender is a free open source 3D graphics application. It can easily be installed on any Ubuntu version by installing the package named blender. Using Blender you’ll be able to triangulate your model when exporting to an .obj file. Then you’ll have to export the .obj file to a .h, which finally can be imported into your QCAR/Android project. This might be “great” for testing, but in the long term, you’ll run into dozens of problems of lighting, reflection, animation, etc.

Texture dimensions

A problem you might run into is using badly dimensioned textures. This problem was kind of hard to find for me as you only get runtime fatal errors which don’t give any relevant detail. But you need to know that almost all mobile devices will only take squares and 2×1 / 1×2 rectangles for texture files. For example, these dimensions would work: 512 x 512, 32 x16 and 128 x 256 pixels. These would not : 1024 x 16, 512 x 64 pixels. Another thing with textures: depending on models, there are limits to the total number of texture files you can load at the same time in an application, and there are limits to their dimensions (1024, 512, and 256 pixels).

I recommend using Unity

According to Wikipedia, “Unity is an integrated authoring tool for creating 3D video games or other interactive content such as architectural visualizations or real-time 3D animations.” In other words: it makes A LOT OF STUFF much better and much faster than an OpenGL developer (or a whole team) would do. What are the downsides? Size (approximately 16 to 20 MB when correctly compiled), cost ($400 for the Android license), and finally, support is not as good on Android as it is on iOS. More information available on Unity’s website.

Even if Unity’s solution isn’t perfect (are there any perfect solutions anyway?), it is in my opinion a million times better than working with your own 3D model and custom OpenGL ES. You’ll be able to simplify your model(s) to enhance performance (which is very important on mobile devices), lighting and other visual effects will be much easier to create, etc. Overall, you’ll get a much better result for way less effort. Everyone wins!

Please visit QCAR’s developer site for SDK download, documentation on how to start a QCAR project, how to integrate the Unity extension, and more.

5 Comments

  1. How did you draw the 3d model? Using glDrawElements requires some indices, and using the script I see no indices array or something? Can you please explain how did you do it?
    Thanks in advance.

    • Matt

      February 1, 2012 at 5:16 pm

      The code you’re looking for is located in the jni folder of your project, based on the assumption you’re using Qualcomm’s example project/code. This folder contains .cpp files with native OpenGL API calls. Those will indices/vertices found in the included .h file. But they are basic OpenGL calls with no advanced texture or light management, so the results are kinda poor. This is why I recommend using Unity. Hope this helps you a little.

  2. Can u please write video tutorial explaining from scratch how to create then draw your own model over marker.

    • Matt

      February 17, 2012 at 11:21 am

      Hi. I agree that would be of great help, but it’s impossible for me to do that right now. I simply don’t have enough free time, and I haven’t worked on Android for 6 months. If you have specific questions, I’ll do my best to answer them though. Thanks a lot for reading!

    • Is there some one have helpful Tutorial, for Android Unity, QCAR to display custom model over marker? please mail me on go4mfarooq@gmail.com

Leave a Reply

Your email address will not be published.

*

© 2018 Evil Coding Monkey

Theme by Anders NorenUp ↑