Skip to content

Commit

Permalink
custom error message when texture map is missing, fixes #3990
Browse files Browse the repository at this point in the history
  • Loading branch information
codeanticode committed May 11, 2016
1 parent 9f1d298 commit 49a4c81
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions core/src/processing/core/PShapeOBJ.java
Expand Up @@ -216,7 +216,6 @@ static protected void parseOBJ(PApplet parent, String path,
1 - Float.valueOf(parts[2]).
floatValue());
texcoords.add(tempv);
PApplet.println(texcoords.size(), tempv);
readvt = true;
} else if (parts[0].equals("o")) {
// Object name is ignored, for now.
Expand All @@ -229,7 +228,7 @@ static protected void parseOBJ(PApplet parent, String path,
}
BufferedReader mreader = parent.createReader(fn);
if (mreader != null) {
parseMTL(parent, path, mreader, materials, mtlTable);
parseMTL(parent, fn, path, mreader, materials, mtlTable);
mreader.close();
}
}
Expand Down Expand Up @@ -318,7 +317,7 @@ static protected void parseOBJ(PApplet parent, String path,
}


static protected void parseMTL(PApplet parent, String path,
static protected void parseMTL(PApplet parent, String mtlfn, String path,
BufferedReader reader,
ArrayList<OBJMaterial> materials,
Map<String, Integer> materialsHash) {
Expand Down Expand Up @@ -347,7 +346,17 @@ static protected void parseMTL(PApplet parent, String path,
// Relative file name, adding the base path.
texname = path + File.separator + texname;
}
currentMtl.kdMap = parent.loadImage(texname);

File file = new File(parent.dataPath(texname));
if (file.exists()) {
currentMtl.kdMap = parent.loadImage(texname);
} else {
System.err.println("The texture map \"" + texname + "\" " +
"in the materials definition file \"" + mtlfn + "\" " +
"is missing or inaccessible, make sure " +
"the URL is valid or that the file has been " +
"added to your sketch and is readable.");
}
} else if (parts[0].equals("Ka") && parts.length > 3) {
// The ambient color of the material
currentMtl.ka.x = Float.valueOf(parts[1]).floatValue();
Expand Down

0 comments on commit 49a4c81

Please sign in to comment.