Add an InputStream constructor to WavefrontObject

It is said that Resource Packs will return InputStreams. And I like putting my models into texture packs which, obviously, give InputStreams rather than URLs.
This commit is contained in:
James 2013-06-19 15:57:44 -06:00
parent dac97174ff
commit af2b5eb6f6

View file

@ -49,20 +49,32 @@ public class WavefrontObject implements IModelCustom
public WavefrontObject(String fileName, URL resource) throws ModelFormatException public WavefrontObject(String fileName, URL resource) throws ModelFormatException
{ {
this.fileName = fileName; this.fileName = fileName;
loadObjModel(resource);
try
{
loadObjModel(resource.openStream());
}
catch (IOException e)
{
throw new ModelFormatException("IO Exception reading model format", e);
}
} }
private void loadObjModel(URL fileURL) throws ModelFormatException public WavefrontObject(String filename, InputStream inputStream) throws ModelFormatException
{
this.fileName = filename;
loadObjModel(inputStream);
}
private void loadObjModel(InputStream inputStream) throws ModelFormatException
{ {
BufferedReader reader = null; BufferedReader reader = null;
InputStream inputStream = null;
String currentLine = null; String currentLine = null;
int lineCount = 0; int lineCount = 0;
try try
{ {
inputStream = fileURL.openStream();
reader = new BufferedReader(new InputStreamReader(inputStream)); reader = new BufferedReader(new InputStreamReader(inputStream));
while ((currentLine = reader.readLine()) != null) while ((currentLine = reader.readLine()) != null)