Add KHR_materials_transmission during export

pull/3552/head
Danny Kabrane 2020-12-23 10:43:21 +01:00
parent 2b097c1e73
commit 383c97e380
3 changed files with 35 additions and 0 deletions

View File

@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* KHR_materials_unlit: full
* KHR_materials_sheen: full
* KHR_materials_clearcoat: full
* KHR_materials_transmission: full
*/
#ifndef GLTF2ASSETWRITER_H_INC
#define GLTF2ASSETWRITER_H_INC

View File

@ -458,6 +458,22 @@ namespace glTF2 {
}
}
if (m.materialTransmission.isPresent) {
Value materialTransmission(rapidjson::Type::kObjectType);
MaterialTransmission &transmission = m.materialTransmission.value;
if (transmission.transmissionFactor != 0.f) {
WriteFloat(materialTransmission, transmission.transmissionFactor, "transmissionFactor", w.mAl);
}
WriteTex(materialTransmission, transmission.transmissionTexture, "transmissionTexture", w.mAl);
if (!materialTransmission.ObjectEmpty()) {
exts.AddMember("KHR_materials_transmission", materialTransmission, w.mAl);
}
}
if (!exts.ObjectEmpty()) {
obj.AddMember("extensions", exts, w.mAl);
}
@ -857,6 +873,10 @@ namespace glTF2 {
if (this->mAsset.extensionsUsed.KHR_materials_clearcoat) {
exts.PushBack(StringRef("KHR_materials_clearcoat"), mAl);
}
if (this->mAsset.extensionsUsed.KHR_materials_transmission) {
exts.PushBack(StringRef("KHR_materials_transmission"), mAl);
}
}
if (!exts.Empty())

View File

@ -747,6 +747,20 @@ void glTF2Exporter::ExportMaterials()
m->materialClearcoat = Nullable<MaterialClearcoat>(clearcoat);
}
bool hasMaterialTransmission = false;
mat->Get(AI_MATKEY_GLTF_MATERIAL_TRANSMISSION, hasMaterialTransmission);
if (hasMaterialTransmission) {
mAsset->extensionsUsed.KHR_materials_transmission = true;
MaterialTransmission transmission;
mat->Get(AI_MATKEY_GLTF_MATERIAL_TRANSMISSION_FACTOR, transmission.transmissionFactor);
GetMatTex(mat, transmission.transmissionTexture, AI_MATKEY_GLTF_MATERIAL_TRANSMISSION_TEXTURE);
m->materialTransmission = Nullable<MaterialTransmission>(transmission);
}
}
}