From f51b173eaf2f5ca71202b47231629c3c6c393949 Mon Sep 17 00:00:00 2001 From: manuelrmo Date: Sat, 17 Dec 2022 04:33:55 -0800 Subject: [PATCH] Update for the glTF loader to detect when AO map is packed in MR map --- .../java/com/jme3/scene/plugins/gltf/GltfLoader.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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();