* Fix MTL issue where "Tr 0" could cause model to be invisible even though illum index specifies that it shouldn't use transparency

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8327 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 13 years ago
parent d38b469de6
commit 97a9b4ee00
  1. 40
      engine/src/core-plugins/com/jme3/scene/plugins/MTLLoader.java
  2. 23
      engine/src/core-plugins/com/jme3/scene/plugins/OBJLoader.java

@ -46,6 +46,7 @@ import java.io.File;
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;
@ -69,6 +70,9 @@ public class MTLLoader implements AssetLoader {
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;
@ -91,8 +95,14 @@ public class MTLLoader implements AssetLoader {
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(){
@ -100,6 +110,9 @@ public class MTLLoader implements AssetLoader {
diffuse.set(ColorRGBA.LightGray);
specular.set(ColorRGBA.Black);
shininess = 16;
disallowTransparency = false;
disallowAmbient = false;
disallowSpecular = false;
shadeless = false;
transparent = false;
matName = null;
@ -113,7 +126,7 @@ public class MTLLoader implements AssetLoader {
protected void createMaterial(){
Material material;
if (alpha < 1f){
if (alpha < 1f && transparent && !disallowTransparency){
diffuse.a = alpha;
}
@ -136,7 +149,7 @@ public class MTLLoader implements AssetLoader {
if (alphaMap != null) material.setTexture("AlphaMap", alphaMap);
}
if (transparent){
if (transparent && !disallowTransparency){
material.setTransparent(true);
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
material.getAdditionalRenderState().setAlphaTest(true);
@ -181,7 +194,7 @@ public class MTLLoader implements AssetLoader {
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);
@ -201,7 +214,7 @@ public class MTLLoader implements AssetLoader {
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);
@ -231,6 +244,17 @@ public class MTLLoader implements AssetLoader {
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:
@ -244,10 +268,10 @@ public class MTLLoader implements AssetLoader {
}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;

@ -59,6 +59,7 @@ import java.util.ArrayList;
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;
@ -323,7 +324,11 @@ public final class OBJLoader implements AssetLoader {
// 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
@ -336,8 +341,14 @@ public final class OBJLoader implements AssetLoader {
}
}
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{
@ -348,7 +359,7 @@ public final class OBJLoader implements AssetLoader {
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());
@ -372,11 +383,11 @@ public final class OBJLoader implements AssetLoader {
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;

Loading…
Cancel
Save