@@ -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