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) { ...

Get Cardboard VR Projects for Android now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.