Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compatibility mode for obj file with mtl file #708

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG-SNAPSHOTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 25 additions & 4 deletions src/main/rtm-patches/jp/ngt/rtm/render/ModelObject.java.patch
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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<String, String> map) {
- public Material[] getMaterials(Map<String, String> map) {
- Map<String, Material> map = this.model.getMaterials();
+ public Material[] getMaterials(Map<String, String> map, boolean objMtlCompatibilityMode) {
+ Map<String, Material> 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<Entry<String, Material>> iterator = map.entrySet().iterator();
Expand Down
Loading