O'Reilly logo

Cardboard VR Projects for Android by Matt Schoen, Jonathan Linowes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parse OBJ models

The parseObj method will open the resource file as an InputStream. It reads one line at a time, parsing the command and data, building the model's list of vertices, normals, and indexes. Then, we build the buffers from the data.

First, at the top of the ModelObject class, declare variables for the data lists:

    Vector<Short> faces=new Vector<Short>();
    Vector<Short> vtPointer=new Vector<Short>();
    Vector<Short> vnPointer=new Vector<Short>();
    Vector<Float> v=new Vector<Float>();
    Vector<Float> vn=new Vector<Float>();
    Vector<Material> materials=null;

Let's write parseObj with placeholders for helper methods. We open the file, process each line, build the buffers, and handle potential IO errors:

 void parseObj(InputStream inputStream) { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required