From e55e17ba4b402f1249337f7ace8a74f4ff71d2f7 Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Wed, 11 May 2011 18:48:14 +0000 Subject: [PATCH] * Fix issue with MTL map_** statements provided with arguments git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7487 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/scene/plugins/MTLLoader.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/engine/src/core-plugins/com/jme3/scene/plugins/MTLLoader.java b/engine/src/core-plugins/com/jme3/scene/plugins/MTLLoader.java index 6c1a3c812..be7edad6e 100644 --- a/engine/src/core-plugins/com/jme3/scene/plugins/MTLLoader.java +++ b/engine/src/core-plugins/com/jme3/scene/plugins/MTLLoader.java @@ -70,10 +70,11 @@ public class MTLLoader implements AssetLoader { return v; } - protected void nextStatement(){ + protected String nextStatement(){ scan.useDelimiter("\n"); - scan.next(); + String result = scan.next(); scan.useDelimiter("\\p{javaWhitespace}+"); + return result; } protected void startMaterial(String name){ @@ -87,6 +88,11 @@ public class MTLLoader implements AssetLoader { } protected Texture loadTexture(String path){ + String[] split = path.trim().split("\\p{javaWhitespace}+"); + + // will crash if path is an empty string + path = split[split.length-1]; + String name = new File(path).getName(); TextureKey key = new TextureKey(folderName + name); key.setGenerateMips(true); @@ -139,12 +145,13 @@ public class MTLLoader implements AssetLoader { } }else if (cmd.equals("map_ka")){ // ignore it for now + nextStatement(); }else if (cmd.equals("map_kd")){ - String path = scan.next(); + String path = nextStatement(); material.setTexture("DiffuseMap", loadTexture(path)); }else if (cmd.equals("map_bump") || cmd.equals("bump")){ if (material.getParam("NormalMap") == null){ - String path = scan.next(); + String path = nextStatement(); Texture texture = loadTexture(path); if (texture != null){ material.setTexture("NormalMap", texture); @@ -154,7 +161,7 @@ public class MTLLoader implements AssetLoader { } } }else if (cmd.equals("map_ks")){ - String path = scan.next(); + String path = nextStatement(); Texture texture = loadTexture(path); if (texture != null){ material.setTexture("SpecularMap", texture);