Skip to content

Commit 842cbf3

Browse files
committed
fix regression in PShapeOBJ
1 parent 3cee8e5 commit 842cbf3

File tree

1 file changed

+10
-36
lines changed

1 file changed

+10
-36
lines changed

core/src/processing/core/PShapeOBJ.java

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
package processing.core;
2424

2525
import java.io.BufferedReader;
26-
import java.io.File;
2726
import java.util.ArrayList;
2827
import java.util.HashMap;
2928
import java.util.Map;
@@ -46,20 +45,17 @@ public class PShapeOBJ extends PShape {
4645
* Initializes a new OBJ Object with the given filename.
4746
*/
4847
public PShapeOBJ(PApplet parent, String filename) {
49-
this(parent, parent.createReader(filename), getBasePath(parent, filename));
48+
this(parent, parent.createReader(filename));
5049
}
5150

52-
public PShapeOBJ(PApplet parent, BufferedReader reader) {
53-
this(parent, reader, "");
54-
}
5551

56-
public PShapeOBJ(PApplet parent, BufferedReader reader, String basePath) {
52+
public PShapeOBJ(PApplet parent, BufferedReader reader) {
5753
ArrayList<OBJFace> faces = new ArrayList<OBJFace>();
5854
ArrayList<OBJMaterial> materials = new ArrayList<OBJMaterial>();
5955
ArrayList<PVector> coords = new ArrayList<PVector>();
6056
ArrayList<PVector> normals = new ArrayList<PVector>();
6157
ArrayList<PVector> texcoords = new ArrayList<PVector>();
62-
parseOBJ(parent, basePath, reader,
58+
parseOBJ(parent, reader,
6359
faces, materials, coords, normals, texcoords);
6460

6561
// The OBJ geometry is stored with each face in a separate child shape.
@@ -172,7 +168,7 @@ protected void addChildren(ArrayList<OBJFace> faces,
172168
}
173169

174170

175-
static protected void parseOBJ(PApplet parent, String path,
171+
static protected void parseOBJ(PApplet parent,
176172
BufferedReader reader,
177173
ArrayList<OBJFace> faces,
178174
ArrayList<OBJMaterial> materials,
@@ -242,15 +238,12 @@ static protected void parseOBJ(PApplet parent, String path,
242238
} else if (parts[0].equals("o")) {
243239
// Object name is ignored, for now.
244240
} else if (parts[0].equals("mtllib")) {
241+
245242
if (parts[1] != null) {
246243
String fn = parts[1];
247-
if (fn.indexOf(File.separator) == -1 && !path.equals("")) {
248-
// Relative file name, adding the base path.
249-
fn = path + File.separator + fn;
250-
}
251244
BufferedReader mreader = parent.createReader(fn);
252245
if (mreader != null) {
253-
parseMTL(parent, fn, path, mreader, materials, mtlTable);
246+
parseMTL(parent, fn, mreader, materials, mtlTable);
254247
mreader.close();
255248
}
256249
}
@@ -339,7 +332,7 @@ static protected void parseOBJ(PApplet parent, String path,
339332
}
340333

341334

342-
static protected void parseMTL(PApplet parent, String mtlfn, String path,
335+
static protected void parseMTL(PApplet parent, String mtlfn,
343336
BufferedReader reader,
344337
ArrayList<OBJMaterial> materials,
345338
Map<String, Integer> materialsHash) {
@@ -364,15 +357,8 @@ static protected void parseMTL(PApplet parent, String mtlfn, String path,
364357
if (parts[0].equals("map_Kd") && parts.length > 1) {
365358
// Loading texture map.
366359
String texname = parts[1];
367-
if (texname.indexOf(File.separator) == -1 && !path.equals("")) {
368-
// Relative file name, adding the base path.
369-
texname = path + File.separator + texname;
370-
}
371-
372-
File file = new File(parent.dataPath(texname));
373-
if (file.exists()) {
374-
currentMtl.kdMap = parent.loadImage(texname);
375-
} else {
360+
currentMtl.kdMap = parent.loadImage(texname);
361+
if (currentMtl.kdMap == null) {
376362
System.err.println("The texture map \"" + texname + "\" " +
377363
"in the materials definition file \"" + mtlfn + "\" " +
378364
"is missing or inaccessible, make sure " +
@@ -452,18 +438,6 @@ static protected class OBJFace {
452438
}
453439

454440

455-
static protected String getBasePath(PApplet parent, String filename) {
456-
// Obtaining the path
457-
File file = new File(parent.dataPath(filename));
458-
if (!file.exists()) {
459-
file = parent.sketchFile(filename);
460-
}
461-
String absolutePath = file.getAbsolutePath();
462-
return absolutePath.substring(0,
463-
absolutePath.lastIndexOf(File.separator));
464-
}
465-
466-
467441
// Stores a material defined in an MTL file.
468442
static protected class OBJMaterial {
469443
String name;
@@ -488,4 +462,4 @@ static protected class OBJMaterial {
488462
kdMap = null;
489463
}
490464
}
491-
}
465+
}

0 commit comments

Comments
 (0)