From 9f9cb824cd5d8b77e614b7dad3913bcb3cd534d3 Mon Sep 17 00:00:00 2001 From: Daniel Johansson Date: Mon, 7 Mar 2016 16:38:43 +0000 Subject: [PATCH] Fixed an issue with J3MLoader thinking certain texture path patterns with new texture options still looked like old style and hence ignoring new options and getting the texture path wrong. --- .../com/jme3/material/plugins/J3MLoader.java | 22 +++++++++++++++---- .../jme3/material/plugins/J3MLoaderTest.java | 2 ++ .../resources/texture-parameters-newstyle.j3m | 3 ++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java b/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java index 13a8e0232..d289b42c0 100644 --- a/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java +++ b/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java @@ -169,9 +169,23 @@ public class J3MLoader implements AssetLoader { return matchList; } - private boolean isTexturePathDeclaredTheTraditionalWay(final int numberOfValues, final int numberOfTextureOptions, final String texturePath) { - return (numberOfValues > 1 && (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Flip ") || - texturePath.startsWith("Repeat ") || texturePath.startsWith("Repeat Flip "))) || numberOfTextureOptions == 0; + private boolean isTexturePathDeclaredTheTraditionalWay(final List optionValues, final String texturePath) { + final boolean startsWithOldStyle = texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Flip ") || + texturePath.startsWith("Repeat ") || texturePath.startsWith("Repeat Flip "); + + if (!startsWithOldStyle) { + return false; + } + + if (optionValues.size() == 1 && (optionValues.get(0).textureOption == TextureOption.Flip || optionValues.get(0).textureOption == TextureOption.Repeat)) { + return true; + } else if (optionValues.size() == 2 && optionValues.get(0).textureOption == TextureOption.Flip && optionValues.get(1).textureOption == TextureOption.Repeat) { + return true; + } else if (optionValues.size() == 2 && optionValues.get(0).textureOption == TextureOption.Repeat && optionValues.get(1).textureOption == TextureOption.Flip) { + return true; + } + + return false; } private Texture parseTextureType(final VarType type, final String value) { @@ -187,7 +201,7 @@ public class J3MLoader implements AssetLoader { String texturePath = value.trim(); // If there are no valid "new" texture options specified but the path is split into several parts, lets parse the old way. - if (isTexturePathDeclaredTheTraditionalWay(textureValues.size(), textureOptionValues.size(), texturePath)) { + if (isTexturePathDeclaredTheTraditionalWay(textureOptionValues, texturePath)) { boolean flipY = false; if (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Repeat Flip ")) { diff --git a/jme3-core/src/test/java/com/jme3/material/plugins/J3MLoaderTest.java b/jme3-core/src/test/java/com/jme3/material/plugins/J3MLoaderTest.java index 6438baaac..f45eb9bdf 100644 --- a/jme3-core/src/test/java/com/jme3/material/plugins/J3MLoaderTest.java +++ b/jme3-core/src/test/java/com/jme3/material/plugins/J3MLoaderTest.java @@ -80,6 +80,7 @@ public class J3MLoaderTest { final Texture textureMin = Mockito.mock(Texture.class); final Texture textureMag = Mockito.mock(Texture.class); final Texture textureCombined = Mockito.mock(Texture.class); + final Texture textureLooksLikeOldStyle = Mockito.mock(Texture.class); final TextureKey textureKeyNoParameters = setupMockForTexture("Empty", "empty.png", false, textureNoParameters); final TextureKey textureKeyFlip = setupMockForTexture("Flip", "flip.png", true, textureFlip); @@ -88,6 +89,7 @@ public class J3MLoaderTest { setupMockForTexture("Min", "min.png", false, textureMin); setupMockForTexture("Mag", "mag.png", false, textureMag); setupMockForTexture("Combined", "combined.png", true, textureCombined); + setupMockForTexture("LooksLikeOldStyle", "oldstyle.png", true, textureLooksLikeOldStyle); j3MLoader.load(assetInfo); diff --git a/jme3-core/src/test/resources/texture-parameters-newstyle.j3m b/jme3-core/src/test/resources/texture-parameters-newstyle.j3m index a7619d948..e4b15ad4a 100644 --- a/jme3-core/src/test/resources/texture-parameters-newstyle.j3m +++ b/jme3-core/src/test/resources/texture-parameters-newstyle.j3m @@ -6,6 +6,7 @@ Material Test : matdef.j3md { Min: MinTrilinear "min.png" Mag: MagBilinear "mag.png" RepeatAxis: WrapRepeat_T "repeat-axis.png" - Combined: MagNearest MinBilinearNoMipMaps Flip WrapRepeat "combined.png" + Combined: Flip MagNearest MinBilinearNoMipMaps WrapRepeat "combined.png" + LooksLikeOldStyle: Flip WrapRepeat "oldstyle.png" } } \ No newline at end of file