private void read() { InputStream inStream; if (useResource) { inStream = mContext.getResources().openRawResource(this.resourceId); } else { throw new UnsupportedOperationException("Not yet implemented."); } Scanner s = new Scanner(inStream); String newLine; while (s.hasNextLine()) { newLine = s.nextLine(); if (newLine.startsWith("v ")) { Vertex v = new Vertex(); String[] coords = newLine.split(" "); v.x = Float.valueOf(coords[1]); v.y = Float.valueOf(coords[2]); v.z = Float.valueOf(coords[3]); vertices.add(v); } if (newLine.startsWith("vt ")) { Texture t = new Texture(); String[] coords = newLine.split(" "); t.x = Float.valueOf(coords[1]); t.y = Float.valueOf(coords[2]); textures.add(t); } if (newLine.startsWith("vn ")) { Normal n = new Normal(); String[] coords = newLine.split(" "); n.x = Float.valueOf(coords[1]); n.y = Float.valueOf(coords[2]); n.z = Float.valueOf(coords[3]); normals.add(n); } if (newLine.startsWith("f ")) { Face f = new Face(); String[] vertices = newLine.split(" "); for (int i = 1; i < vertices.length; i++) { String[] indices = vertices[i].split("/"); if (!indices[0].equals("")) { f.v[i - 1] = Integer.valueOf(indices[0]); } if (!indices[1].equals("")) { f.vt[i - 1] = Integer.valueOf(indices[1]); } if (!indices[2].equals("")) { f.vn[i - 1] = Integer.valueOf(indices[2]); } } faces.add(f); } } try { inStream.close(); } catch (IOException e) { e.printStackTrace(); } }
public double dot(Normal n) { return (x * n.x() + y * n.y() + z * n.z()); }