Skip to content

Commit f92a73f

Browse files
authored
Fix #1412 (GltfLoader does not support AO packed in MetallicRoughnessMap) (#1880)
1 parent 478af32 commit f92a73f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,16 @@ public Material readMaterial(int materialIndex) throws IOException {
635635
setDefaultParams(adapter.getMaterial());
636636
}
637637

638+
Integer metallicRoughnessIndex = null;
638639
if (pbrMat != null) {
639640
adapter.setParam("baseColorFactor", getAsColor(pbrMat, "baseColorFactor", ColorRGBA.White));
640641
adapter.setParam("metallicFactor", getAsFloat(pbrMat, "metallicFactor", 1f));
641642
adapter.setParam("roughnessFactor", getAsFloat(pbrMat, "roughnessFactor", 1f));
642643
adapter.setParam("baseColorTexture", readTexture(pbrMat.getAsJsonObject("baseColorTexture")));
643644
adapter.setParam("metallicRoughnessTexture",
644645
readTexture(pbrMat.getAsJsonObject("metallicRoughnessTexture")));
646+
JsonObject metallicRoughnessJson = pbrMat.getAsJsonObject("metallicRoughnessTexture");
647+
metallicRoughnessIndex = metallicRoughnessJson != null ? getAsInteger(metallicRoughnessJson, "index") : null;
645648
}
646649

647650
adapter.getMaterial().setName(getAsString(matData, "name"));
@@ -657,7 +660,13 @@ public Material readMaterial(int materialIndex) throws IOException {
657660
if (normal != null) {
658661
useNormalsFlag = true;
659662
}
660-
adapter.setParam("occlusionTexture", readTexture(matData.getAsJsonObject("occlusionTexture")));
663+
JsonObject occlusionJson = matData.getAsJsonObject("occlusionTexture");
664+
Integer occlusionIndex = occlusionJson != null ? getAsInteger(occlusionJson, "index") : null;
665+
if (occlusionIndex != null && occlusionIndex.equals(metallicRoughnessIndex)) {
666+
adapter.getMaterial().setBoolean("AoPackedInMRMap", true);
667+
} else {
668+
adapter.setParam("occlusionTexture", readTexture(matData.getAsJsonObject("occlusionTexture")));
669+
}
661670
adapter.setParam("emissiveTexture", readTexture(matData.getAsJsonObject("emissiveTexture")));
662671

663672
return adapter.getMaterial();

0 commit comments

Comments
 (0)