obj/MtlMaterial.java
/**
	 * @param file a .mtl file
	 * @return An {@link ArrayList} of all of the materials defined in file.
	 * @throws IOException
	 */
@param file a .mtl file
@return An  ArrayList of all of the materials defined in file.
@param file a . mtl file @return An ArrayList of all of the materials defined in file .
public static List<MtlMaterial> loadMtls(File file) throws IOException {
		List<MtlMaterial> materials = new ArrayList<MtlMaterial>();
		BufferedReader br = new BufferedReader(new FileReader(file));
		String name = null;
		FloatColor ambient = null;
		FloatColor diffuse = null;
		FloatColor specular = null;
		float wSpec = 0;
		float dissolve = 0;
		float refraction = 1f;
		boolean[] illuminationModels = new boolean[11];
		String line;
		boolean firstMtl = true;
		if (!file.getPath().substring(file.getPath().lastIndexOf('.')).equals(".mtl")) {
			throw new InvalidParameterException("File is not .mtl");
		}
		while ((line = br.readLine()) != null) {
			String[] splitStr = line.split("\\s");
			if (line.isEmpty()) {
				continue;
			}
			if (line.trim().startsWith("#")) {
				continue;
			}
			if (splitStr[0].equals("Ka") || splitStr[0].equals("Kd") || splitStr[0].equals("Ks")) {
				float r = Float.parseFloat(splitStr[1]);
				float g = Float.parseFloat(splitStr[2]);
				float b = Float.parseFloat(splitStr[3]);
				switch(splitStr[0]) {
					case "Ka":
						ambient = new FloatColor(r, g, b);
						break;
					case "Kd":
						diffuse = new FloatColor(r, g, b);
						break;
					case "Ks":
						specular = new FloatColor(r, g, b);
						break;
				}
			} else if (splitStr[0].equals("Ns") || splitStr[0].equals("d") || splitStr[0].equals("Tr") || splitStr[0].equals("Ni")) {
				float arg = Float.parseFloat(splitStr[1]);
				switch (splitStr[0]) {
					case "Ns":
						wSpec = arg;
						break;
					case "d":
						dissolve = arg;
						if (splitStr[1].equals("-halo")) {
						}
						break;
					 (alternative key)
					case "Tr":
						dissolve = arg;
						break;
					case "Ni":
						refraction = arg;
						break;
					default:
						break;
				}
			} else {
				switch (splitStr[0]) {
					case "newmtl":
						if (firstMtl) {
							firstMtl = false;
							name = splitStr[1];
						} else {
							materials.add(new MtlMaterial(name, ambient, diffuse, specular, wSpec, dissolve, refraction, illuminationModels));
							name = splitStr[1];
							ambient = null;
							diffuse = null;
							specular = null;
							wSpec = 0;
							dissolve = 0;
							refraction = 1f;
							illuminationModels = new boolean[11];
						}
						break;
					case "illum":
						int temp = Integer.parseInt(splitStr[1]);
						if (temp >= 0 && temp <= 10) {
							illuminationModels[temp] = true;
						}
						break;
					default:
						break;
				}
			}
		}
		if (!firstMtl) {
			materials.add(new MtlMaterial(name, ambient, diffuse, specular, wSpec, dissolve, refraction, illuminationModels));
		}
		br.close();
		return materials;
	}
public static List < MtlMaterial > loadMtls ( File file ) throws IOException { List < MtlMaterial > materials = new ArrayList < MtlMaterial > ( ) ; BufferedReader br = new BufferedReader ( new FileReader ( file ) ) ; String name = null ; FloatColor ambient = null ; FloatColor diffuse = null ; FloatColor specular = null ; float wSpec = 0 ; float dissolve = 0 ; float refraction = 1f ; boolean [ ] illuminationModels = new boolean [ 11 ] ; String line ; boolean firstMtl = true ; if ( ! file . getPath ( ) . substring ( file . getPath ( ) . lastIndexOf ( '.' ) ) . equals ( ".mtl" ) ) { throw new InvalidParameterException ( "File is not .mtl" ) ; } while ( ( line = br . readLine ( ) ) != null ) { String [ ] splitStr = line . split ( "\\s" ) ; if ( line . isEmpty ( ) ) { continue ; } if ( line . trim ( ) . startsWith ( "#" ) ) { continue ; } if ( splitStr [ 0 ] . equals ( "Ka" ) || splitStr [ 0 ] . equals ( "Kd" ) || splitStr [ 0 ] . equals ( "Ks" ) ) { float r = Float . parseFloat ( splitStr [ 1 ] ) ; float g = Float . parseFloat ( splitStr [ 2 ] ) ; float b = Float . parseFloat ( splitStr [ 3 ] ) ; switch ( splitStr [ 0 ] ) { case "Ka" : ambient = new FloatColor ( r , g , b ) ; break ; case "Kd" : diffuse = new FloatColor ( r , g , b ) ; break ; case "Ks" : specular = new FloatColor ( r , g , b ) ; break ; } } else if ( splitStr [ 0 ] . equals ( "Ns" ) || splitStr [ 0 ] . equals ( "d" ) || splitStr [ 0 ] . equals ( "Tr" ) || splitStr [ 0 ] . equals ( "Ni" ) ) { float arg = Float . parseFloat ( splitStr [ 1 ] ) ; switch ( splitStr [ 0 ] ) { case "Ns" : wSpec = arg ; break ; case "d" : dissolve = arg ; if ( splitStr [ 1 ] . equals ( "-halo" ) ) { } break ; case "Tr" : dissolve = arg ; break ; case "Ni" : refraction = arg ; break ; default : break ; } } else { switch ( splitStr [ 0 ] ) { case "newmtl" : if ( firstMtl ) { firstMtl = false ; name = splitStr [ 1 ] ; } else { materials . add ( new MtlMaterial ( name , ambient , diffuse , specular , wSpec , dissolve , refraction , illuminationModels ) ) ; name = splitStr [ 1 ] ; ambient = null ; diffuse = null ; specular = null ; wSpec = 0 ; dissolve = 0 ; refraction = 1f ; illuminationModels = new boolean [ 11 ] ; } break ; case "illum" : int temp = Integer . parseInt ( splitStr [ 1 ] ) ; if ( temp >= 0 && temp <= 10 ) { illuminationModels [ temp ] = true ; } break ; default : break ; } } } if ( ! firstMtl ) { materials . add ( new MtlMaterial ( name , ambient , diffuse , specular , wSpec , dissolve , refraction , illuminationModels ) ) ; } br . close ( ) ; return materials ; }
@param file a .mtl file
 @return An {@link ArrayList} of all of the materials defined in file.
@param file a . mtl file @return An { @link ArrayList } of all of the materials defined in file .
//If line is empty //If line is comment //TODO //If line's arguments is three floats //Ambient color //Diffuse color //Specular color //Weighted specular coefficient //Transparency //TODO //Transparency (alternative key) //Optical density (Index of refraction) //TODO //Material definition //Set default values //Illumination model