Advertisement
Guest User

Initiation code

a guest
Sep 21st, 2013
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.95 KB | None | 0 0
  1.     public void init(File filepath) {
  2.         ArrayList<String> face = new ArrayList<String>();
  3.         Manager vParse = new Manager(new Point());
  4.         System.out.print(filepath);
  5.         filePath = filepath;
  6.         try {
  7.             content = reader.read(filePath);
  8.         } catch (FileNotFoundException ex) {
  9.             Logger.getLogger(OBJ_Model.class.getName()).log(Level.SEVERE, null, ex);
  10.         } catch (IOException ex) {
  11.             Logger.getLogger(OBJ_Model.class.getName()).log(Level.SEVERE, null, ex);
  12.         }
  13.         String line[] = new String[parser.Compiler(content, "\n").length];
  14.         line=vParse.Compiler(content, "\n");
  15.         ArrayList<String> vertex = new ArrayList<String>();
  16.         //the vertex (string) array
  17.         ArrayList<String> normalvertex = new ArrayList<String>();
  18.         //the array containing the normals (again a string)
  19.         ArrayList<Float[]> points = new ArrayList<Float[]>();
  20.         //the array containing the vertacies in a float
  21.         for(int i=0;i<line.length;i++){
  22.             /*
  23.             /------------------------------------------------------------------------------------------------\
  24.             |this goes through each line and stores the string in an array based on the first few characters.|
  25.             \------------------------------------------------------------------------------------------------/
  26.             */            
  27.             String thisLine = line[i];
  28.             boolean found=false;
  29.             int k = 0;
  30.             char startChar = 0;
  31.             boolean endLine=false;
  32.             char seccondChar = 0;
  33.             while(found==false){
  34.                 /*
  35.                 /--------------------------------------------------------------------------------------------------------\
  36.                 |loops until finds non " " character then stores that and the next character in firstChar and secondChar.|
  37.                 |if no character is found which is not a space then this goes to the next line.                          |
  38.                 \--------------------------------------------------------------------------------------------------------/
  39.                 */
  40.                 if(k<thisLine.length()){
  41.                     startChar= line[i].toCharArray()[k];
  42.                     seccondChar= line[i].toCharArray()[k+1];                    
  43.                 }else{
  44.                     endLine=true;
  45.                     found = true;
  46.                 }
  47.                 if(startChar!=' ' && endLine==false){
  48.                     found = true;
  49.                 }else{
  50.                     k++;
  51.                 }
  52.             }
  53.             if(endLine==false){
  54.                 if(startChar == '#'){
  55.  
  56.                 }else if(startChar == 'v'){
  57.                     //then it is a normal or a vertex
  58.                     if(seccondChar == 'n'){
  59.                         //then it is a normal vertex
  60.                         normalvertex.add(thisLine);
  61.                     }else if(seccondChar == ' '){
  62.                         //then it is a vertex
  63.                         vertex.add(thisLine);
  64.                     }
  65.                 }else if(startChar == 'f'){
  66.                     //then it is a face
  67.                     face.add(thisLine);
  68.                 }
  69.             }
  70.                    
  71.         }
  72.         ArrayList<ArrayList<String>> vertsStr=new ArrayList<ArrayList<String>>();
  73.         for(int i=0; i<vertex.size(); i++){
  74.             /*
  75.             /-----------------------------------------------------------------------------------------------\
  76.             |This tokenizes the vertaicy into x, y, and z. The tokenizer tokenizes based on spaces (v x y z)|
  77.             |x, y, and z are all seperatied by a space.                                                     |
  78.             \-----------------------------------------------------------------------------------------------/
  79.             */                
  80.             ArrayList<ArrayList<String>> v=new ArrayList<ArrayList<String>>();
  81.             ArrayList<ArrayList<String>> nv=new ArrayList<ArrayList<String>>();
  82.             vertex.set(i,vertex.get(i).substring(1));
  83.             v.add(parser.CompilerArrayList(vertex.get(i), " "));
  84.             vertsStr.add(v.get(0));            
  85.         }
  86.         Float[][] verts=new Float[vertsStr.size()][4];                
  87.         for(int i = 0; i<vertsStr.size();i++){
  88.             /*
  89.             /------------------------------------------------------------\
  90.             |This converts the string containing x, y, and z into a float|
  91.             \------------------------------------------------------------/
  92.             */                            
  93.             for(int i2=0; i2<vertsStr.get(i).size();i2++){
  94.                  verts[i][i2]=Float.parseFloat(vertsStr.get(i).get(i2));
  95.             }
  96.         }
  97.         ArrayList<ArrayList<String>> faceVerts=new ArrayList<ArrayList<String>>();
  98.         int k=0;
  99.  
  100.         for(int i=0; i<face.size(); i++){
  101.             /*
  102.             /----------------------------------------------------------------------------------------------\
  103.             |this loops through the faces and  finds corasponding vertex index and stores them in an array.|
  104.             |this also checks the validity of the term.                                                    |
  105.             \----------------------------------------------------------------------------------------------/
  106.             */            
  107.             boolean j = parser.checkValid(face.get(i));
  108.             ArrayList<String> slashComp = new ArrayList<String>();
  109.             if(parser.checkValid(face.get(i))){
  110.                 faceVerts.add(parser.CompilerArrayList(face.get(i), " "));
  111.                 for(int i2=0; i2<faceVerts.size();i2++){
  112.                     slashComp=parser.CompilerArrayList(faceVerts.get(k).get(0),"/");
  113.                     facePoints.add(slashComp);
  114.                 }
  115.                 k++;
  116.             }
  117.         }
  118.         for(int i=0;i<faceVerts.size();i++){
  119.             /*
  120.             /-------------------------------------------------------------------------------------------------------\
  121.             |this loops through the faces and  finds corasponding vertex value and stores them in a TEMPORARY array.|
  122.             \-------------------------------------------------------------------------------------------------------/
  123.             */                        
  124.           ArrayList<ArrayList<Float>> vertPoint=new ArrayList<ArrayList<Float>>();
  125.  
  126.           if(parser.checkValid(face.get(i))){
  127.  
  128.  
  129.             for(int i2=1;i2<faceVerts.get(i).size();i2++){
  130.                 ArrayList<Float> xyz=new ArrayList<Float>();
  131.                 for(int i3=0; i3<3; i3++){
  132.                     String thisFace = faceVerts.get(i).get(i2);
  133.                     int index = Integer.parseInt(parser.Compiler(thisFace,"/")[0])-1;
  134.                     float thisVert =(verts[index][i3]);                    
  135.                     xyz.add(thisVert);
  136.  
  137.                 }
  138.                 vertPoint.add(xyz);
  139.                
  140.             }
  141.             fp.add(vertPoint);
  142.           }
  143.          
  144.          
  145.         }    
  146.         final int listSize = fp.size();
  147.         draw= new float[listSize][][];
  148.         for(int i = 0; i < listSize; i++) {
  149.             /*
  150.             /---------------------------------------------------------------------------------\
  151.             |This goes through the fp array and stores the vertacies in an array called "draw"|
  152.             \---------------------------------------------------------------------------------/
  153.             */            
  154.             ArrayList<ArrayList<Float>> sublist = fp.get(i);
  155.             final int sublistSize = sublist.size();
  156.             draw[i] = new float[sublistSize][4];
  157.             for(int i2 = 0; i2 < sublistSize; i2++) {
  158.                 for(int i3=0;i3<3;i3++){
  159.                     draw[i][i2][3]=1f;
  160.                     draw[i][i2][i3] = sublist.get(i2).get(i3);
  161.            
  162.                 }
  163.             }
  164.         }        
  165.  
  166.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement