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 be36021349..0a0c0403c2 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2021 jMonkeyEngine + * Copyright (c) 2009-2022 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -222,6 +222,7 @@ private Texture parseTextureType(final VarType type, final String value) { // If there is only one token on the value, it must be the path to the texture. if (textureValues.size() == 1) { textureKey = new TextureKey(textureValues.get(0), false); + textureKey.setGenerateMips(true); } else { String texturePath = value.trim(); @@ -256,6 +257,8 @@ private Texture parseTextureType(final VarType type, final String value) { textureKey = new TextureKey(textureValues.get(textureValues.size() - 1), false); } + textureKey.setGenerateMips(true); + // Apply texture options to the texture key if (!textureOptionValues.isEmpty()) { for (final TextureOptionValue textureOptionValue : textureOptionValues) { @@ -276,8 +279,6 @@ private Texture parseTextureType(final VarType type, final String value) { break; } - textureKey.setGenerateMips(true); - Texture texture; try { @@ -861,6 +862,13 @@ private enum TextureOption { * Applies a {@link com.jme3.texture.Texture.MinFilter} to the texture. */ Min { + + @Override + public void applyToTextureKey(final String option, final TextureKey textureKey) { + Texture.MinFilter minFilter = Texture.MinFilter.valueOf(option); + textureKey.setGenerateMips(minFilter.usesMipMapLevels()); + } + @Override public void applyToTexture(final String option, final Texture texture) { texture.setMinFilter(Texture.MinFilter.valueOf(option)); 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 8dc756686e..7126d94fa8 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 @@ -87,8 +87,8 @@ public void oldStyleTextureParameters_shouldBeSupported() throws Exception { final Texture textureOldStyle = Mockito.mock(Texture.class); final Texture textureOldStyleUsingQuotes = Mockito.mock(Texture.class); - final TextureKey textureKeyUsingQuotes = setupMockForTexture("OldStyleUsingQuotes", "old style using quotes/texture.png", true, textureOldStyleUsingQuotes); - final TextureKey textureKeyOldStyle = setupMockForTexture("OldStyle", "old style/texture.png", true, textureOldStyle); + final TextureKey textureKeyUsingQuotes = setupMockForTexture("OldStyleUsingQuotes", "old style using quotes/texture.png", true, true, textureOldStyleUsingQuotes); + final TextureKey textureKeyOldStyle = setupMockForTexture("OldStyle", "old style/texture.png", true, true, textureOldStyle); j3MLoader.load(assetInfo); @@ -111,14 +111,14 @@ public void newStyleTextureParameters_shouldBeSupported() throws Exception { 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); - setupMockForTexture("Repeat", "repeat.png", false, textureRepeat); - setupMockForTexture("RepeatAxis", "repeat-axis.png", false, textureRepeatAxis); - setupMockForTexture("Min", "min.png", false, textureMin); - setupMockForTexture("Mag", "mag.png", false, textureMag); - setupMockForTexture("Combined", "combined.png", true, textureCombined); - setupMockForTexture("LooksLikeOldStyle", "oldstyle.png", true, textureLooksLikeOldStyle); + final TextureKey textureKeyNoParameters = setupMockForTexture("Empty", "empty.png", false, true, textureNoParameters); + final TextureKey textureKeyFlip = setupMockForTexture("Flip", "flip.png", true, true, textureFlip); + setupMockForTexture("Repeat", "repeat.png", false, true, textureRepeat); + setupMockForTexture("RepeatAxis", "repeat-axis.png", false, true, textureRepeatAxis); + setupMockForTexture("Min", "min.png", false, true, textureMin); + setupMockForTexture("Mag", "mag.png", false, true, textureMag); + setupMockForTexture("Combined", "combined.png", true, false, textureCombined); + setupMockForTexture("LooksLikeOldStyle", "oldstyle.png", true, true, textureLooksLikeOldStyle); j3MLoader.load(assetInfo); @@ -135,11 +135,11 @@ public void newStyleTextureParameters_shouldBeSupported() throws Exception { verify(textureCombined).setWrap(Texture.WrapMode.Repeat); } - private TextureKey setupMockForTexture(final String paramName, final String path, final boolean flipY, final Texture texture) { + private TextureKey setupMockForTexture(final String paramName, final String path, final boolean flipY, boolean generateMips, final Texture texture) { when(materialDef.getMaterialParam(paramName)).thenReturn(new MatParamTexture(VarType.Texture2D, paramName, texture, null)); final TextureKey textureKey = new TextureKey(path, flipY); - textureKey.setGenerateMips(true); + textureKey.setGenerateMips(generateMips); when(assetManager.loadTexture(textureKey)).thenReturn(texture); diff --git a/jme3-plugins/src/main/java/com/jme3/material/plugin/export/material/J3MOutputCapsule.java b/jme3-plugins/src/main/java/com/jme3/material/plugin/export/material/J3MOutputCapsule.java index fd2c0bbfbd..950466b4ba 100644 --- a/jme3-plugins/src/main/java/com/jme3/material/plugin/export/material/J3MOutputCapsule.java +++ b/jme3-plugins/src/main/java/com/jme3/material/plugin/export/material/J3MOutputCapsule.java @@ -1,3 +1,34 @@ +/* + * Copyright (c) 2009-2022 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ package com.jme3.material.plugin.export.material; import com.jme3.asset.TextureKey; @@ -140,11 +171,7 @@ protected static String formatMatParamTexture(MatParamTexture param) { ret.append(formatWrapMode(tex, Texture.WrapAxis.R)); //Min and Mag filter - Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps; - if (tex.getImage().hasMipmaps() || (key != null && key.isGenerateMips())) { - def = Texture.MinFilter.Trilinear; - } - if (tex.getMinFilter() != def) { + if (tex.getMinFilter() != Texture.MinFilter.Trilinear) { ret.append("Min").append(tex.getMinFilter().name()).append(" "); } diff --git a/jme3-plugins/src/test/java/com/jme3/material/plugin/TestMaterialWrite.java b/jme3-plugins/src/test/java/com/jme3/material/plugin/TestMaterialWrite.java index be8fc3573b..e5dfa75965 100644 --- a/jme3-plugins/src/test/java/com/jme3/material/plugin/TestMaterialWrite.java +++ b/jme3-plugins/src/test/java/com/jme3/material/plugin/TestMaterialWrite.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2016 jMonkeyEngine + * Copyright (c) 2009-2022 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,6 +34,7 @@ import com.jme3.asset.AssetInfo; import com.jme3.asset.AssetKey; import com.jme3.asset.AssetManager; +import com.jme3.asset.TextureKey; import com.jme3.material.Material; import com.jme3.material.RenderState; import com.jme3.material.plugin.export.material.J3MExporter; @@ -76,7 +77,7 @@ public void testWriteMat() throws Exception { mat.setFloat("Shininess", 2.5f); - Texture tex = assetManager.loadTexture("Common/Textures/MissingTexture.png"); + Texture tex = assetManager.loadTexture(new TextureKey("Common/Textures/MissingTexture.png", true)); tex.setMagFilter(Texture.MagFilter.Nearest); tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps); tex.setWrap(Texture.WrapAxis.S, Texture.WrapMode.Repeat);