add support for khr_materials_sheen during export

pull/3550/head
Danny Kabrane 2020-12-21 14:34:16 +01:00
parent 0fdda99ea1
commit aa9d6ce7b7
3 changed files with 40 additions and 0 deletions

View File

@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* glTF Extensions Support:
* KHR_materials_pbrSpecularGlossiness: full
* KHR_materials_unlit: full
* KHR_materials_sheen: full
*/
#ifndef GLTF2ASSETWRITER_H_INC
#define GLTF2ASSETWRITER_H_INC

View File

@ -417,6 +417,25 @@ namespace glTF2 {
exts.AddMember("KHR_materials_unlit", unlit, w.mAl);
}
if (m.materialSheen.isPresent) {
Value materialSheen(rapidjson::Type::kObjectType);
MaterialSheen &sheen = m.materialSheen.value;
WriteVec(materialSheen, sheen.sheenColorFactor, "sheenColorFactor", defaultSheenFactor, w.mAl);
if (sheen.sheenRoughnessFactor != 0.f) {
WriteFloat(materialSheen, sheen.sheenRoughnessFactor, "sheenRoughnessFactor", w.mAl);
}
WriteTex(materialSheen, sheen.sheenColorTexture, "sheenColorTexture", w.mAl);
WriteTex(materialSheen, sheen.sheenRoughnessTexture, "sheenRoughnessTexture", w.mAl);
if (!materialSheen.ObjectEmpty()) {
exts.AddMember("KHR_materials_sheen", materialSheen, w.mAl);
}
}
if (!exts.ObjectEmpty()) {
obj.AddMember("extensions", exts, w.mAl);
}
@ -808,6 +827,10 @@ namespace glTF2 {
if (this->mAsset.extensionsUsed.KHR_materials_unlit) {
exts.PushBack(StringRef("KHR_materials_unlit"), mAl);
}
if (this->mAsset.extensionsUsed.KHR_materials_sheen) {
exts.PushBack(StringRef("KHR_materials_sheen"), mAl);
}
}
if (!exts.Empty())

View File

@ -714,6 +714,22 @@ void glTF2Exporter::ExportMaterials()
mAsset->extensionsUsed.KHR_materials_unlit = true;
m->unlit = true;
}
bool hasMaterialSheen = false;
mat->Get(AI_MATKEY_GLTF_MATERIAL_SHEEN, hasMaterialSheen);
if (hasMaterialSheen) {
mAsset->extensionsUsed.KHR_materials_sheen = true;
MaterialSheen sheen;
GetMatColor(mat, sheen.sheenColorFactor, AI_MATKEY_GLTF_MATERIAL_SHEEN_COLOR_FACTOR);
mat->Get(AI_MATKEY_GLTF_MATERIAL_SHEEN_ROUGHNESS_FACTOR, sheen.sheenRoughnessFactor);
GetMatTex(mat, sheen.sheenColorTexture, AI_MATKEY_GLTF_MATERIAL_SHEEN_COLOR_TEXTURE);
GetMatTex(mat, sheen.sheenRoughnessTexture, AI_MATKEY_GLTF_MATERIAL_SHEEN_ROUGHNESS_TEXTURE);
m->materialSheen = Nullable<MaterialSheen>(sheen);
}
}
}