About the material loader. It's really simple stuff (mtl is a String that contains the mtl-file's content as text):
Map<String, Object[]> mats = new HashMap<String, Object[]>();
StringTokenizer st = new StringTokenizer(mtl, "\n");
String matName = null;
RGBColor col = null;
String texture = null;
String texture2 = null;
float[] cols = new float[3];
boolean next = true;
String line = null;
Float trans = null;
TextureManager texMan = TextureManager.getInstance();
int mode = 0;
while (st.hasMoreTokens()) {
if (next) {
line = st.nextToken().trim();
}
switch (mode) {
case (0): {
if (line.startsWith("newmtl ")) {
matName = line.substring(7).trim();
mode = 1;
next = true;
col = null;
texture = null;
trans = null;
Logger.log("Processing new material " + matName + "!", Logger.MESSAGE);
}
break;
}
case (1): {
String lLine = line.toLowerCase();
if (lLine.startsWith("kd ")) {
String sub = lLine.substring(3).trim();
StringTokenizer st2 = new StringTokenizer(sub, " ");
int ind = 0;
while (st2.hasMoreTokens() && ind < 3) {
String c = st2.nextToken();
try {
cols[ind] = Float.valueOf(c).floatValue();
} catch (Exception e) {
cols[ind] = 1;
Logger.log("Error in MTL-file near: " + line, Logger.ERROR);
}
ind++;
}
col = new RGBColor((int) (cols[0] * 255f), (int) (cols[1] * 255f), (int) (cols[2] * 255f));
} else {
if ((lLine.startsWith("map_kd") || lLine.startsWith("map_ka")) && line.length() > 7) {
// Textur
if (lLine.startsWith("map_kd")) {
texture = removeBogusData(line.substring(7).trim());
if (!texMan.containsTexture(texture)) {
texMan.addTexture(texture);
Logger.log("Texture named " + texture + " added to TextureManager!", Logger.MESSAGE);
}
} else {
texture2 = removeBogusData(line.substring(7).trim());
if (!texMan.containsTexture(texture2)) {
texMan.addTexture(texture2);
Logger.log("Texture named " + texture2 + " added to TextureManager!", Logger.MESSAGE);
}
}
} else {
if (lLine.startsWith("d ")) {
float tt = -1;
try {
tt = Float.parseFloat(line.substring(2).trim());
} catch (Exception e) {
}
if (tt != -1 && tt != 1) {
trans = Float.valueOf(tt);
}
} else {
if (lLine.startsWith("newmtl")) {
mode = 0;
next = false;
}
}
}
}
break;
}
}
if (!next || !st.hasMoreTokens()) {
mats.put(matName, new Object[] { col, texture, trans });
}
}