LapisSea

Untitled

Aug 13th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. private static void loadMlt(Map<String,IMaterial> materials, String lin, String name) throws IOException{
  2.         String mtllib=lin.substring("mtllib".length()).trim();
  3.        
  4.         String path;
  5.         int pos=name.lastIndexOf('/');
  6.         if(pos==-1) path="models/"+mtllib;
  7.         else path="models/"+name.substring(0, pos+1)+mtllib;
  8.        
  9.         try(InputStream mtlSrc=UtilM.getResource(path)){
  10.            
  11.             if(mtlSrc==null){
  12.                 LogUtil.println("Model mtl file", path, "does not exist!");
  13.                 return;
  14.             }
  15.            
  16.             PairM<Material,Integer> mat=new PairM<>(null, 0);
  17.            
  18.             lines(mtlSrc, line->{
  19.                 if(line.isEmpty()||line.charAt(0)=='#') return;
  20.                
  21.                 if(line.startsWith("newmtl ")){
  22.                     mat.obj1=new Material(mat.obj2++, line.substring("newmtl ".length()));
  23.                    
  24.                     materials.put(mat.obj1.getName(), mat.obj1);
  25.                     return;
  26.                 }
  27.                 Material mater=mat.obj1;
  28.                
  29.                 if(mater!=null){
  30.                     // @formatter:off
  31.                     switch(line.charAt(0)){
  32.                     case 'K':
  33.                         switch(line.charAt(1)){
  34.                         case 'a':mater.getAmbient() .load(line, 3);break;
  35.                         case 'd':mater.getDiffuse() .load(line, 3);break;
  36.                         case 's':mater.getSpecular().load(line, 3);break;
  37.                         case 'e':mater.getEmission().load(line, 3);break;
  38.                         }
  39.                         break;
  40.                     case 'N':
  41.                         if(line.charAt(1)=='s') mater.setShineDamper(Float.parseFloat(line.split(" ")[1]));
  42.                         break;
  43.                     case 'd':mater.setShineDamper(Float.parseFloat(line.split(" ")[1]));break;
  44.                     default:
  45.                         if(line.startsWith("jelly ")) mater.setJelly(MathUtil.snap(Float.parseFloat(line.substring("jelly ".length())), 0, 1));
  46.                     }
  47.                     // @formatter:on
  48.                 }
  49.             });
  50.            
  51.         }
  52.     }
Add Comment
Please, Sign In to add comment