/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package taboedie; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; /** * * @author Ruud */ public class OBJImporter { public List vertices = new ArrayList<>(); public OBJImporter(String file) { readFile(file); } private void readFile(String file) { try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(file); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { Vector3 vertex = Vector3.ZERO(); String vertexString[] = strLine.split(" "); if((vertexString.length > 3) && "v".equals(vertexString[0])) { vertex.x = Float.parseFloat(vertexString[2]); vertex.y = Float.parseFloat(vertexString[3]); vertex.z = Float.parseFloat(vertexString[4]); System.out.println(vertex.toString()); vertices.add(vertex); } // Print the content on the console } //Close the input stream in.close(); }catch (IOException e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } public void renderImport() { } }