Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void loadMlt(Map<String,IMaterial> materials, String lin, String name) throws IOException{
- String mtllib=lin.substring("mtllib".length()).trim();
- String path;
- int pos=name.lastIndexOf('/');
- if(pos==-1) path="models/"+mtllib;
- else path="models/"+name.substring(0, pos+1)+mtllib;
- try(InputStream mtlSrc=UtilM.getResource(path)){
- if(mtlSrc==null){
- LogUtil.println("Model mtl file", path, "does not exist!");
- return;
- }
- PairM<Material,Integer> mat=new PairM<>(null, 0);
- lines(mtlSrc, line->{
- if(line.isEmpty()||line.charAt(0)=='#') return;
- if(line.startsWith("newmtl ")){
- mat.obj1=new Material(mat.obj2++, line.substring("newmtl ".length()));
- materials.put(mat.obj1.getName(), mat.obj1);
- return;
- }
- Material mater=mat.obj1;
- if(mater!=null){
- // @formatter:off
- switch(line.charAt(0)){
- case 'K':
- switch(line.charAt(1)){
- case 'a':mater.getAmbient() .load(line, 3);break;
- case 'd':mater.getDiffuse() .load(line, 3);break;
- case 's':mater.getSpecular().load(line, 3);break;
- case 'e':mater.getEmission().load(line, 3);break;
- }
- break;
- case 'N':
- if(line.charAt(1)=='s') mater.setShineDamper(Float.parseFloat(line.split(" ")[1]));
- break;
- case 'd':mater.setShineDamper(Float.parseFloat(line.split(" ")[1]));break;
- default:
- if(line.startsWith("jelly ")) mater.setJelly(MathUtil.snap(Float.parseFloat(line.substring("jelly ".length())), 0, 1));
- }
- // @formatter:on
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment