From b61e0dc2818ba9fa2b34a1ddf74de0a91a19a943 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Fri, 23 Dec 2022 13:27:58 +0330 Subject: [PATCH 1/8] Get texture mips generation flag from MinFilter specified in j3m file. --- .../java/com/jme3/material/plugins/J3MLoader.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 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 be36021349..777858bf79 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 @@ -276,8 +276,6 @@ private Texture parseTextureType(final VarType type, final String value) { break; } - textureKey.setGenerateMips(true); - Texture texture; try { @@ -861,6 +859,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)); From f574a82b95d19fa601f595f631186b732c26b561 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Fri, 23 Dec 2022 13:35:44 +0330 Subject: [PATCH 2/8] Update copyright date. --- .../src/plugins/java/com/jme3/material/plugins/J3MLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 777858bf79..b5175687fe 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 From 151f12a85d39ec30be1d567a73791a51bcdc51a8 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Fri, 23 Dec 2022 19:33:28 +0330 Subject: [PATCH 3/8] Fix J3MLoaderTest failing. --- .../jme3/material/plugins/J3MLoaderTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) 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..a8412ddcea 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, false, textureOldStyleUsingQuotes); + final TextureKey textureKeyOldStyle = setupMockForTexture("OldStyle", "old style/texture.png", true, false, 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, false, textureNoParameters); + final TextureKey textureKeyFlip = setupMockForTexture("Flip", "flip.png", true, false, textureFlip); + setupMockForTexture("Repeat", "repeat.png", false, false, textureRepeat); + setupMockForTexture("RepeatAxis", "repeat-axis.png", false, false, textureRepeatAxis); + setupMockForTexture("Min", "min.png", false, true, textureMin); + setupMockForTexture("Mag", "mag.png", false, false, textureMag); + setupMockForTexture("Combined", "combined.png", true, false, textureCombined); + setupMockForTexture("LooksLikeOldStyle", "oldstyle.png", true, false, 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); From 0bc7a2c2c1bc4719965b31d917e94f0eeae81e8e Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Fri, 23 Dec 2022 20:22:32 +0330 Subject: [PATCH 4/8] Fix TestMaterialWrite failing. --- .../test/java/com/jme3/material/plugin/TestMaterialWrite.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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..f7ada01f24 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 @@ -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); From d75e5662c6a5e51679804a1bb6131faca0b7b038 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Fri, 23 Dec 2022 20:24:56 +0330 Subject: [PATCH 5/8] Update copyright date. --- .../test/java/com/jme3/material/plugin/TestMaterialWrite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f7ada01f24..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 From dfadc51043289aa18d30ef4215c013208e5ee7f6 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Sun, 25 Dec 2022 18:31:54 +0330 Subject: [PATCH 6/8] Use Trilinear if no min filter is specified in j3m file. --- .../plugins/java/com/jme3/material/plugins/J3MLoader.java | 3 +++ .../material/plugin/export/material/J3MOutputCapsule.java | 6 +----- 2 files changed, 4 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 b5175687fe..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 @@ -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) { 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..1010f39691 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 @@ -140,11 +140,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(" "); } From 2aa447a4ec4f1c9d19fa6ff384ab331af6477867 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Sun, 25 Dec 2022 18:33:36 +0330 Subject: [PATCH 7/8] Add copyright note in J3MOutputCapsule. --- .../export/material/J3MOutputCapsule.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 1010f39691..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; From 7e774315cafdfcf39e458e42e1b71f685894dfa9 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Sun, 25 Dec 2022 20:11:45 +0330 Subject: [PATCH 8/8] Fix J3MLoaderTest failing. --- .../com/jme3/material/plugins/J3MLoaderTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 a8412ddcea..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, false, textureOldStyleUsingQuotes); - final TextureKey textureKeyOldStyle = setupMockForTexture("OldStyle", "old style/texture.png", true, false, 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, false, textureNoParameters); - final TextureKey textureKeyFlip = setupMockForTexture("Flip", "flip.png", true, false, textureFlip); - setupMockForTexture("Repeat", "repeat.png", false, false, textureRepeat); - setupMockForTexture("RepeatAxis", "repeat-axis.png", false, false, textureRepeatAxis); + 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, false, textureMag); + setupMockForTexture("Mag", "mag.png", false, true, textureMag); setupMockForTexture("Combined", "combined.png", true, false, textureCombined); - setupMockForTexture("LooksLikeOldStyle", "oldstyle.png", true, false, textureLooksLikeOldStyle); + setupMockForTexture("LooksLikeOldStyle", "oldstyle.png", true, true, textureLooksLikeOldStyle); j3MLoader.load(assetInfo);