You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.9 KiB
74 lines
1.9 KiB
package com.mykaruga.models.wavefront.parser.mtl;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.util.Hashtable;
|
|
|
|
|
|
import org.newdawn.slick.util.ResourceLoader;
|
|
|
|
import com.mykaruga.models.wavefront.loader.Material;
|
|
import com.mykaruga.models.wavefront.loader.RenderModel;
|
|
import com.mykaruga.models.wavefront.parser.LineParser;
|
|
|
|
|
|
|
|
public class MaterialFileParser extends LineParser {
|
|
|
|
Hashtable<String, Material> materials = new Hashtable<String, Material>();
|
|
private RenderModel object;
|
|
private MtlLineParserFactory parserFactory = null;
|
|
|
|
public MaterialFileParser(RenderModel object) {
|
|
this.object = object;
|
|
this.parserFactory = new MtlLineParserFactory(object);
|
|
}
|
|
|
|
@Override
|
|
public void incoporateResults(RenderModel wavefrontObject) {
|
|
// Material are directly added by the parser, no need to do anything here...
|
|
}
|
|
|
|
@Override
|
|
public void parse() {
|
|
String filename = words[1];
|
|
|
|
String pathToMTL = object.getContextfolder() + filename;
|
|
|
|
InputStream fileInput = ResourceLoader.getResourceAsStream(pathToMTL);
|
|
if (fileInput == null) {
|
|
// Could not find the file in the jar.
|
|
try {
|
|
File file = new File(pathToMTL);
|
|
if (file.exists()) fileInput = new FileInputStream(file);
|
|
} catch (Exception e2) {
|
|
e2.printStackTrace();
|
|
}
|
|
}
|
|
|
|
try {
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(fileInput));
|
|
|
|
String currentLine = null;
|
|
while ((currentLine = in.readLine()) != null) {
|
|
|
|
LineParser parser = parserFactory.getLineParser(currentLine);
|
|
parser.parse();
|
|
parser.incoporateResults(object);
|
|
}
|
|
|
|
if (in != null) in.close();
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
throw new RuntimeException("Error parsing " + pathToMTL);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
} |