Thanks for the update SAITO. But I added an extra bit to the material loader. I'm not sure if anyone else will find this useful but here goes. The mtl file contains an absolute path to the texture applied to the model. I had a lot of obj files and I needed to make sure that they would only load the files that were in the processing data folder. So I added a bit of code that stripped out the end filename from the path string. here it is.
All this code lives in OBJModel.java
first a boolean and a couple of functions need to be added to the class OBJModel
Quote:
boolean flagLocalTexture = false;
public void enableLocalTexture() {
flagLocalTexture = true;
}
public void disableLocalTexture() {
flagLocalTexture = false;
}
Next this code is dropped into the mtl file parser. It replaces the current section that reads the map_Kd line. It's located in the void parseMTL(BufferedReader bread) function.
Quote:
else if (elements[0].equals("map_Kd")&& elements.length > 1) {
//--------------------------------------------------- start MattD(polymonkey) hack
if(!flagLocalTexture){
debug.println("\ttexture diffuse '" + elements[1] +"'");
}
String texname = elements[1];
if(flagLocalTexture){
int p1 = 0;
String slash = "\\";
while (p1 != -1){
p1 = texname.indexOf(slash);
texname = texname.substring(p1+1);
}
debug.println("\tlocal texture diffuse '" + texname +"'");
}
//--------------------------------------------------- end MattD(polymonkey) hack
currentMtl.map_Kd = parent.loadImage(texname);
}
So after all that if you do this
Quote:
OBJModel model;
void setup()
{
model = new OBJModel(this);
model.enableLocalTexture();
model.load("dma.obj");
}
Then it will only load the texture files that are in the data directory with the obj and mtl file.
Hope people find this useful. And SAITO it's a great lib, I've really enjoyed messing around with it. It's been a great learning experience.
MattD(polymonkey)