Re: 3D loaders - 2 questions
Posted by jfpauly on Nov 10, 2024; 2:27pm
URL: https://forum.jogamp.org/3D-loaders-2-questions-tp4043577p4043613.html
Code changed in ObjectFileMaterials class
___________________________________________
method assignMaterial()
// Change code to always set specular and LightingEnable 03/02/2017 ****
if (objFilMat.Ks != null) { // Set specular color.
mat.setSpecularColor(objFilMat.Ks);
}
mat.setLightingEnable(true); // hard coded 03/02/2017 ****
____________________________________________________________________________
method readMapKd()
* Change structure and remove code for files other than usual
* change test for null texture image name
public void readMapKd(ObjectFileParser objParse) {
objParse.lowerCaseMode(false); // Filenames are case sensitive
String tFile = null; // Get name of texture file (skip path)
do {
objParse.getToken();
if (objParse.ttype == ObjectFileParser.TT_WORD) {
tFile = objParse.sval;
}
} while (objParse.ttype != ObjectFileParser.TT_EOL);
objParse.lowerCaseMode(true);
// some material files have lines with map_kd token but no filename. ****
// the next test has been changed (null pointer exeception). ****
if (tFile == null ) {
objParse.skipToNextLine();
return;
}
TextureLoader t = null;
if (fromUrl) { // inetrnet file
try {
t = new TextureLoader(new URL(basePath + tFile), "RGB", TextureLoader.GENERATE_MIPMAP, null);
} catch (MalformedURLException ex) {
Logger.getLogger(NewObjectFileMaterials.class.getName()).log(Level.SEVERE, null, ex);
}
} else { // local file
String theFile = basePath + "\\" + tFile;
File img = new File(theFile);
if (img.exists()) {
t = new TextureLoader(theFile, "RGB", TextureLoader.GENERATE_MIPMAP, null);
} else { // wrong file name
JOptionPane.showMessageDialog(this, theFile + " not found");
return;
}
}
if (t == null) {
objParse.skipToNextLine();
JOptionPane.showMessageDialog(this, "null textureLoader");
return;
}
Texture2D texture = (Texture2D) t.getTexture();
if (texture == null) {
objParse.skipToNextLine();
JOptionPane.showMessageDialog(this, "null texture");
return;
}
cur.t = texture;
} // End of readMapKd
_________________________________________________________________________________
method readMaterialFile()
* Add test to skip unknown tokens
......
else if (st.sval.equals("bump")) {
st.skipToNextLine();
} else st.skipToNextLine(); // skip unknown token. Added 22/02/2017
_______________