Set alphaMode, baseColorFactor opacity when model’s opacity isn’t 1
authorDaniel Hritzkiv <daniel.hritzkiv@gmail.com>
Wed, 6 Sep 2017 18:17:24 +0000 (14:17 -0400)
committerDaniel Hritzkiv <daniel.hritzkiv@gmail.com>
Mon, 11 Sep 2017 15:02:14 +0000 (11:02 -0400)
code/glTF2Exporter.cpp

index a5c74fd..9130c75 100644 (file)
@@ -433,7 +433,17 @@ void glTF2Exporter::ExportMaterials()
 
         mat->Get(AI_MATKEY_TWOSIDED, m->doubleSided);
         mat->Get(AI_MATKEY_GLTF_ALPHACUTOFF, m->alphaCutoff);
-        mat->Get(AI_MATKEY_GLTF_ALPHAMODE, m->alphaMode);
+
+        if (mat->Get(AI_MATKEY_GLTF_ALPHAMODE, m->alphaMode) != AI_SUCCESS) {
+            float opacity;
+
+            if (mat->Get(AI_MATKEY_OPACITY, opacity) == AI_SUCCESS) {
+                if (opacity < 1) {
+                    m->alphaMode = "MASK";
+                    m->pbrMetallicRoughness.baseColorFactor[3] *= opacity;
+                }
+            }
+        }
 
         bool hasPbrSpecularGlossiness;
         mat->Get(AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS, hasPbrSpecularGlossiness);