Skip to content

Commit b2e414d

Browse files
authored
Merge pull request #708 from fixrtm/fix-obj-mtl-compatibility
fix: compatibility mode for obj file with mtl file
2 parents 041db1b + 2afd108 commit b2e414d

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

CHANGELOG-SNAPSHOTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The changelog for 2.0.23 and earlier is generated by [anatawa12's fork of `auto-
1818
### Removed
1919

2020
### Fixed
21+
- Compatibility problem with mtl file with uppercase chars `#708`
22+
- If your modelpack has `mtl` file with uppercase, your modelpack will fail to load.
2123

2224
### Security
2325

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Thanks to prepare-changelog.sh, we have some macros.
2525
### Removed
2626

2727
### Fixed
28+
- Compatibility problem with mtl file with uppercase chars `#708`
29+
- If your modelpack has `mtl` file with uppercase, your modelpack will fail to load.
2830

2931
### Security
3032

src/main/rtm-patches/jp/ngt/rtm/render/ModelObject.java.patch

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
--- a/jp/ngt/rtm/render/ModelObject.java
22
+++ b/jp/ngt/rtm/render/ModelObject.java
3-
@@ -92,10 +92,19 @@
3+
@@ -42,11 +42,12 @@
4+
private int program;
5+
6+
public ModelObject(ModelConfig.ModelSource par1, ModelSetBase par2, PartsRenderer par3, Object... args) {
7+
String s = par1.modelFile;
8+
this.model = ModelPackManager.INSTANCE.loadModel(s, 4, true, par2.getConfig(), par2.md5);
9+
- Material[] amaterial = this.getMaterials(this.getTextureMap(par1.textures));
10+
+ boolean objMtlCompatibilityMode = FileType.OBJ.match(s) && !s.equals(s.toLowerCase(java.util.Locale.ROOT));
11+
+ Material[] amaterial = this.getMaterials(this.getTextureMap(par1.textures), objMtlCompatibilityMode);
12+
this.textures = new TextureSet[amaterial.length];
13+
boolean flag = false;
14+
boolean flag1 = false;
15+
int i = amaterial.length != par1.textures.length ? 1 : amaterial.length;
16+
17+
@@ -92,10 +93,19 @@
418
this.alphaBlend = false;
519
this.useTexture = true;
620
this.renderer = this.getPartsRenderer((String)null, par1);
@@ -20,18 +34,25 @@
2034
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])});
2135
}
2236

23-
@@ -241,17 +250,17 @@
37+
@@ -240,18 +250,22 @@
38+
this.renderer.render(entity, pass, partialTick);
2439
}
2540

2641
}
2742

28-
public Material[] getMaterials(Map<String, String> map) {
43+
- public Material[] getMaterials(Map<String, String> map) {
2944
- Map<String, Material> map = this.model.getMaterials();
45+
+ public Material[] getMaterials(Map<String, String> map, boolean objMtlCompatibilityMode) {
3046
+ Map<String, Material> map1 = this.model.getMaterials();
3147
Material[] amaterial;
3248
- if (map.isEmpty()) {
49+
- amaterial = new Material[]{new Material((byte)0, ModelPackManager.INSTANCE.getResource(map.get("default")))};
50+
+
3351
+ if (map1.isEmpty()) {
34-
amaterial = new Material[]{new Material((byte)0, ModelPackManager.INSTANCE.getResource(map.get("default")))};
52+
+ amaterial = new Material[]{new Material((byte) 0, ModelPackManager.INSTANCE.getResource(map.get("default")))};
53+
+ } else if (objMtlCompatibilityMode && map.size() == 1 && map.containsKey("default")) {
54+
+ // For compatibility, for default-only material, we think map1 is empty
55+
+ amaterial = new Material[]{new Material((byte) 0, ModelPackManager.INSTANCE.getResource(map.get("default")))};
3556
} else {
3657
- amaterial = new Material[map.size()];
3758
- Iterator<Entry<String, Material>> iterator = map.entrySet().iterator();

0 commit comments

Comments
 (0)