diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java index 523ac02fd5..b16f042f50 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java @@ -635,6 +635,7 @@ public Material readMaterial(int materialIndex) throws IOException { setDefaultParams(adapter.getMaterial()); } + Integer metallicRoughnessIndex = null; if (pbrMat != null) { adapter.setParam("baseColorFactor", getAsColor(pbrMat, "baseColorFactor", ColorRGBA.White)); adapter.setParam("metallicFactor", getAsFloat(pbrMat, "metallicFactor", 1f)); @@ -642,6 +643,8 @@ public Material readMaterial(int materialIndex) throws IOException { adapter.setParam("baseColorTexture", readTexture(pbrMat.getAsJsonObject("baseColorTexture"))); adapter.setParam("metallicRoughnessTexture", readTexture(pbrMat.getAsJsonObject("metallicRoughnessTexture"))); + JsonObject metallicRoughnessJson = pbrMat.getAsJsonObject("metallicRoughnessTexture"); + metallicRoughnessIndex = metallicRoughnessJson != null ? getAsInteger(metallicRoughnessJson, "index") : null; } adapter.getMaterial().setName(getAsString(matData, "name")); @@ -657,7 +660,13 @@ public Material readMaterial(int materialIndex) throws IOException { if (normal != null) { useNormalsFlag = true; } - adapter.setParam("occlusionTexture", readTexture(matData.getAsJsonObject("occlusionTexture"))); + JsonObject occlusionJson = matData.getAsJsonObject("occlusionTexture"); + Integer occlusionIndex = occlusionJson != null ? getAsInteger(occlusionJson, "index") : null; + if (occlusionIndex != null && occlusionIndex.equals(metallicRoughnessIndex)) { + adapter.getMaterial().setBoolean("AoPackedInMRMap", true); + } else { + adapter.setParam("occlusionTexture", readTexture(matData.getAsJsonObject("occlusionTexture"))); + } adapter.setParam("emissiveTexture", readTexture(matData.getAsJsonObject("emissiveTexture"))); return adapter.getMaterial();