import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
+import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
protected String matName;
protected float alpha = 1;
protected boolean transparent = false;
+ protected boolean disallowTransparency = false;
+ protected boolean disallowAmbient = false;
+ protected boolean disallowSpecular = false;
public void reset(){
scan = null;
return result;
}
- protected void skipLine(){
- scan.skip(".*\r{0,1}\n");
+ protected boolean skipLine(){
+ try {
+ scan.skip(".*\r{0,1}\n");
+ return true;
+ } catch (NoSuchElementException ex){
+ // EOF
+ return false;
+ }
}
protected void resetMaterial(){
diffuse.set(ColorRGBA.LightGray);
specular.set(ColorRGBA.Black);
shininess = 16;
+ disallowTransparency = false;
+ disallowAmbient = false;
+ disallowSpecular = false;
shadeless = false;
transparent = false;
matName = null;
protected void createMaterial(){
Material material;
- if (alpha < 1f){
+ if (alpha < 1f && transparent && !disallowTransparency){
diffuse.a = alpha;
}
if (alphaMap != null) material.setTexture("AlphaMap", alphaMap);
}
- if (transparent){
+ if (transparent && !disallowTransparency){
material.setTransparent(true);
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
material.getAdditionalRenderState().setAlphaTest(true);
String cmd = scan.next().toLowerCase();
if (cmd.startsWith("#")){
// skip entire comment until next line
- skipLine();
+ return skipLine();
}else if (cmd.equals("newmtl")){
String name = scan.next();
startMaterial(name);
transparent = true;
}else if (cmd.equals("map_ka")){
// ignore it for now
- skipLine();
+ return skipLine();
}else if (cmd.equals("map_kd")){
String path = nextStatement();
diffuseMap = loadTexture(path);
case 0:
// no lighting
shadeless = true;
+ disallowTransparency = true;
+ break;
+ case 1:
+ disallowSpecular = true;
+ disallowTransparency = true;
+ break;
+ case 2:
+ case 3:
+ case 5:
+ case 8:
+ disallowTransparency = true;
break;
case 4:
case 6:
}else if (cmd.equals("ke") || cmd.equals("ni")){
// Ni: index of refraction - unsupported in jME
// Ke: emission color
- skipLine();
+ return skipLine();
}else{
logger.log(Level.WARNING, "Unknown statement in MTL! {0}", cmd);
- skipLine();
+ return skipLine();
}
return true;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map.Entry;
+import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
// NOTE: Cut off any relative/absolute paths
name = new File(name).getName();
- matList = (MaterialList) assetManager.loadAsset(key.getFolder() + name);
+ try {
+ matList = (MaterialList) assetManager.loadAsset(key.getFolder() + name);
+ } catch (AssetNotFoundException ex){
+ throw new AssetNotFoundException("Cannot find material " + name + " for model " + key.getName());
+ }
if (matList != null){
// create face lists for every material
}
}
- protected void nextStatement(){
- scan.skip(".*\r{0,1}\n");
+ protected boolean nextStatement(){
+ try {
+ scan.skip(".*\r{0,1}\n");
+ return true;
+ } catch (NoSuchElementException ex){
+ // EOF
+ return false;
+ }
}
protected boolean readLine() throws IOException{
String cmd = scan.next();
if (cmd.startsWith("#")){
// skip entire comment until next line
- nextStatement();
+ return nextStatement();
}else if (cmd.equals("v")){
// vertex position
verts.add(readVector3());
String mtllib = scan.nextLine().trim();
loadMtlLib(mtllib);
}else if (cmd.equals("s") || cmd.equals("g")){
- nextStatement();
+ return nextStatement();
}else{
// skip entire command until next line
logger.log(Level.WARNING, "Unknown statement in OBJ! {0}", cmd);
- nextStatement();
+ return nextStatement();
}
return true;