Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void init(File filepath) {
- ArrayList<String> face = new ArrayList<String>();
- Manager vParse = new Manager(new Point());
- System.out.print(filepath);
- filePath = filepath;
- try {
- content = reader.read(filePath);
- } catch (FileNotFoundException ex) {
- Logger.getLogger(OBJ_Model.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(OBJ_Model.class.getName()).log(Level.SEVERE, null, ex);
- }
- String line[] = new String[parser.Compiler(content, "\n").length];
- line=vParse.Compiler(content, "\n");
- ArrayList<String> vertex = new ArrayList<String>();
- //the vertex (string) array
- ArrayList<String> normalvertex = new ArrayList<String>();
- //the array containing the normals (again a string)
- ArrayList<Float[]> points = new ArrayList<Float[]>();
- //the array containing the vertacies in a float
- for(int i=0;i<line.length;i++){
- /*
- /------------------------------------------------------------------------------------------------\
- |this goes through each line and stores the string in an array based on the first few characters.|
- \------------------------------------------------------------------------------------------------/
- */
- String thisLine = line[i];
- boolean found=false;
- int k = 0;
- char startChar = 0;
- boolean endLine=false;
- char seccondChar = 0;
- while(found==false){
- /*
- /--------------------------------------------------------------------------------------------------------\
- |loops until finds non " " character then stores that and the next character in firstChar and secondChar.|
- |if no character is found which is not a space then this goes to the next line. |
- \--------------------------------------------------------------------------------------------------------/
- */
- if(k<thisLine.length()){
- startChar= line[i].toCharArray()[k];
- seccondChar= line[i].toCharArray()[k+1];
- }else{
- endLine=true;
- found = true;
- }
- if(startChar!=' ' && endLine==false){
- found = true;
- }else{
- k++;
- }
- }
- if(endLine==false){
- if(startChar == '#'){
- }else if(startChar == 'v'){
- //then it is a normal or a vertex
- if(seccondChar == 'n'){
- //then it is a normal vertex
- normalvertex.add(thisLine);
- }else if(seccondChar == ' '){
- //then it is a vertex
- vertex.add(thisLine);
- }
- }else if(startChar == 'f'){
- //then it is a face
- face.add(thisLine);
- }
- }
- }
- ArrayList<ArrayList<String>> vertsStr=new ArrayList<ArrayList<String>>();
- for(int i=0; i<vertex.size(); i++){
- /*
- /-----------------------------------------------------------------------------------------------\
- |This tokenizes the vertaicy into x, y, and z. The tokenizer tokenizes based on spaces (v x y z)|
- |x, y, and z are all seperatied by a space. |
- \-----------------------------------------------------------------------------------------------/
- */
- ArrayList<ArrayList<String>> v=new ArrayList<ArrayList<String>>();
- ArrayList<ArrayList<String>> nv=new ArrayList<ArrayList<String>>();
- vertex.set(i,vertex.get(i).substring(1));
- v.add(parser.CompilerArrayList(vertex.get(i), " "));
- vertsStr.add(v.get(0));
- }
- Float[][] verts=new Float[vertsStr.size()][4];
- for(int i = 0; i<vertsStr.size();i++){
- /*
- /------------------------------------------------------------\
- |This converts the string containing x, y, and z into a float|
- \------------------------------------------------------------/
- */
- for(int i2=0; i2<vertsStr.get(i).size();i2++){
- verts[i][i2]=Float.parseFloat(vertsStr.get(i).get(i2));
- }
- }
- ArrayList<ArrayList<String>> faceVerts=new ArrayList<ArrayList<String>>();
- int k=0;
- for(int i=0; i<face.size(); i++){
- /*
- /----------------------------------------------------------------------------------------------\
- |this loops through the faces and finds corasponding vertex index and stores them in an array.|
- |this also checks the validity of the term. |
- \----------------------------------------------------------------------------------------------/
- */
- boolean j = parser.checkValid(face.get(i));
- ArrayList<String> slashComp = new ArrayList<String>();
- if(parser.checkValid(face.get(i))){
- faceVerts.add(parser.CompilerArrayList(face.get(i), " "));
- for(int i2=0; i2<faceVerts.size();i2++){
- slashComp=parser.CompilerArrayList(faceVerts.get(k).get(0),"/");
- facePoints.add(slashComp);
- }
- k++;
- }
- }
- for(int i=0;i<faceVerts.size();i++){
- /*
- /-------------------------------------------------------------------------------------------------------\
- |this loops through the faces and finds corasponding vertex value and stores them in a TEMPORARY array.|
- \-------------------------------------------------------------------------------------------------------/
- */
- ArrayList<ArrayList<Float>> vertPoint=new ArrayList<ArrayList<Float>>();
- if(parser.checkValid(face.get(i))){
- for(int i2=1;i2<faceVerts.get(i).size();i2++){
- ArrayList<Float> xyz=new ArrayList<Float>();
- for(int i3=0; i3<3; i3++){
- String thisFace = faceVerts.get(i).get(i2);
- int index = Integer.parseInt(parser.Compiler(thisFace,"/")[0])-1;
- float thisVert =(verts[index][i3]);
- xyz.add(thisVert);
- }
- vertPoint.add(xyz);
- }
- fp.add(vertPoint);
- }
- }
- final int listSize = fp.size();
- draw= new float[listSize][][];
- for(int i = 0; i < listSize; i++) {
- /*
- /---------------------------------------------------------------------------------\
- |This goes through the fp array and stores the vertacies in an array called "draw"|
- \---------------------------------------------------------------------------------/
- */
- ArrayList<ArrayList<Float>> sublist = fp.get(i);
- final int sublistSize = sublist.size();
- draw[i] = new float[sublistSize][4];
- for(int i2 = 0; i2 < sublistSize; i2++) {
- for(int i3=0;i3<3;i3++){
- draw[i][i2][3]=1f;
- draw[i][i2][i3] = sublist.get(i2).get(i3);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement