From f41dc7b16add50ec0e8eafbbb53a60b47bb708ee Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Fri, 3 Nov 2023 21:14:10 +0900 Subject: [PATCH 1/2] fix: compatibility mode for obj file with mtl file --- .../jp/ngt/rtm/render/ModelObject.java.patch | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/rtm-patches/jp/ngt/rtm/render/ModelObject.java.patch b/src/main/rtm-patches/jp/ngt/rtm/render/ModelObject.java.patch index 161aef03..e15e95e7 100644 --- a/src/main/rtm-patches/jp/ngt/rtm/render/ModelObject.java.patch +++ b/src/main/rtm-patches/jp/ngt/rtm/render/ModelObject.java.patch @@ -1,6 +1,20 @@ --- a/jp/ngt/rtm/render/ModelObject.java +++ b/jp/ngt/rtm/render/ModelObject.java -@@ -92,10 +92,19 @@ +@@ -42,11 +42,12 @@ + private int program; + + public ModelObject(ModelConfig.ModelSource par1, ModelSetBase par2, PartsRenderer par3, Object... args) { + String s = par1.modelFile; + this.model = ModelPackManager.INSTANCE.loadModel(s, 4, true, par2.getConfig(), par2.md5); +- Material[] amaterial = this.getMaterials(this.getTextureMap(par1.textures)); ++ boolean objMtlCompatibilityMode = FileType.OBJ.match(s) && !s.equals(s.toLowerCase(java.util.Locale.ROOT)); ++ Material[] amaterial = this.getMaterials(this.getTextureMap(par1.textures), objMtlCompatibilityMode); + this.textures = new TextureSet[amaterial.length]; + boolean flag = false; + boolean flag1 = false; + int i = amaterial.length != par1.textures.length ? 1 : amaterial.length; + +@@ -92,10 +93,19 @@ this.alphaBlend = false; this.useTexture = true; this.renderer = this.getPartsRenderer((String)null, par1); @@ -20,18 +34,25 @@ DUMMY = new ModelObject(ModelLoader.loadModel(new ResourceLocationCustom("models/ModelContainer_19g.obj"), VecAccuracy.LOW, new Object[0]), new TextureSet[]{new TextureSet(new Material((byte)0, ModelPackManager.INSTANCE.getResource("textures/container/19g_JRF_0.png")), 0, false, false, new String[0])}); } -@@ -241,17 +250,17 @@ +@@ -240,18 +250,22 @@ + this.renderer.render(entity, pass, partialTick); } } - public Material[] getMaterials(Map map) { +- public Material[] getMaterials(Map map) { - Map map = this.model.getMaterials(); ++ public Material[] getMaterials(Map map, boolean objMtlCompatibilityMode) { + Map map1 = this.model.getMaterials(); Material[] amaterial; - if (map.isEmpty()) { +- amaterial = new Material[]{new Material((byte)0, ModelPackManager.INSTANCE.getResource(map.get("default")))}; ++ + if (map1.isEmpty()) { - amaterial = new Material[]{new Material((byte)0, ModelPackManager.INSTANCE.getResource(map.get("default")))}; ++ amaterial = new Material[]{new Material((byte) 0, ModelPackManager.INSTANCE.getResource(map.get("default")))}; ++ } else if (objMtlCompatibilityMode && map.size() == 1 && map.containsKey("default")) { ++ // For compatibility, for default-only material, we think map1 is empty ++ amaterial = new Material[]{new Material((byte) 0, ModelPackManager.INSTANCE.getResource(map.get("default")))}; } else { - amaterial = new Material[map.size()]; - Iterator> iterator = map.entrySet().iterator(); From 2afd1080ac7c173b08fb4cacfc7afa1c46d36947 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Fri, 3 Nov 2023 21:17:18 +0900 Subject: [PATCH 2/2] docs(changelog): Compatibility problem with mtl file with uppercase chars --- CHANGELOG-SNAPSHOTS.md | 2 ++ CHANGELOG.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG-SNAPSHOTS.md b/CHANGELOG-SNAPSHOTS.md index d5b84081..8896104e 100644 --- a/CHANGELOG-SNAPSHOTS.md +++ b/CHANGELOG-SNAPSHOTS.md @@ -18,6 +18,8 @@ The changelog for 2.0.23 and earlier is generated by [anatawa12's fork of `auto- ### Removed ### Fixed +- Compatibility problem with mtl file with uppercase chars `#708` + - If your modelpack has `mtl` file with uppercase, your modelpack will fail to load. ### Security diff --git a/CHANGELOG.md b/CHANGELOG.md index 494398df..6f9dea2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ Thanks to prepare-changelog.sh, we have some macros. ### Removed ### Fixed +- Compatibility problem with mtl file with uppercase chars `#708` + - If your modelpack has `mtl` file with uppercase, your modelpack will fail to load. ### Security