Merge pull request #1971 from gstanlo/unlit_gltf
Read and write the KHR_materials_unlit glTF/2.0 extension.pull/1966/head^2
commit
2281822339
|
@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
*
|
||||
* glTF Extensions Support:
|
||||
* KHR_materials_pbrSpecularGlossiness full
|
||||
* KHR_materials_unlit full
|
||||
*/
|
||||
#ifndef GLTF2ASSET_H_INC
|
||||
#define GLTF2ASSET_H_INC
|
||||
|
@ -741,6 +742,9 @@ namespace glTF2
|
|||
//extension: KHR_materials_pbrSpecularGlossiness
|
||||
Nullable<PbrSpecularGlossiness> pbrSpecularGlossiness;
|
||||
|
||||
//extension: KHR_materials_unlit
|
||||
bool unlit;
|
||||
|
||||
Material() { SetDefaults(); }
|
||||
void Read(Value& obj, Asset& r);
|
||||
void SetDefaults();
|
||||
|
@ -1037,6 +1041,7 @@ namespace glTF2
|
|||
struct Extensions
|
||||
{
|
||||
bool KHR_materials_pbrSpecularGlossiness;
|
||||
bool KHR_materials_unlit;
|
||||
|
||||
} extensionsUsed;
|
||||
|
||||
|
|
|
@ -860,6 +860,8 @@ inline void Material::Read(Value& material, Asset& r)
|
|||
this->pbrSpecularGlossiness = Nullable<PbrSpecularGlossiness>(pbrSG);
|
||||
}
|
||||
}
|
||||
|
||||
unlit = nullptr != FindObject(*extensions, "KHR_materials_unlit");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -882,6 +884,7 @@ inline void Material::SetDefaults()
|
|||
alphaMode = "OPAQUE";
|
||||
alphaCutoff = 0.5;
|
||||
doubleSided = false;
|
||||
unlit = false;
|
||||
}
|
||||
|
||||
inline void PbrSpecularGlossiness::SetDefaults()
|
||||
|
@ -1253,6 +1256,7 @@ inline void Asset::ReadExtensionsUsed(Document& doc)
|
|||
if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true;
|
||||
|
||||
CHECK_EXT(KHR_materials_pbrSpecularGlossiness);
|
||||
CHECK_EXT(KHR_materials_unlit);
|
||||
|
||||
#undef CHECK_EXT
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
*
|
||||
* glTF Extensions Support:
|
||||
* KHR_materials_pbrSpecularGlossiness: full
|
||||
* KHR_materials_unlit: full
|
||||
*/
|
||||
#ifndef GLTF2ASSETWRITER_H_INC
|
||||
#define GLTF2ASSETWRITER_H_INC
|
||||
|
|
|
@ -343,6 +343,12 @@ namespace glTF2 {
|
|||
}
|
||||
}
|
||||
|
||||
if (m.unlit) {
|
||||
Value unlit;
|
||||
unlit.SetObject();
|
||||
exts.AddMember("KHR_materials_unlit", unlit, w.mAl);
|
||||
}
|
||||
|
||||
if (!exts.ObjectEmpty()) {
|
||||
obj.AddMember("extensions", exts, w.mAl);
|
||||
}
|
||||
|
@ -683,6 +689,10 @@ namespace glTF2 {
|
|||
if (this->mAsset.extensionsUsed.KHR_materials_pbrSpecularGlossiness) {
|
||||
exts.PushBack(StringRef("KHR_materials_pbrSpecularGlossiness"), mAl);
|
||||
}
|
||||
|
||||
if (this->mAsset.extensionsUsed.KHR_materials_unlit) {
|
||||
exts.PushBack(StringRef("KHR_materials_unlit"), mAl);
|
||||
}
|
||||
}
|
||||
|
||||
if (!exts.Empty())
|
||||
|
|
|
@ -526,6 +526,12 @@ void glTF2Exporter::ExportMaterials()
|
|||
|
||||
m->pbrSpecularGlossiness = Nullable<PbrSpecularGlossiness>(pbrSG);
|
||||
}
|
||||
|
||||
bool unlit;
|
||||
if (mat->Get(AI_MATKEY_GLTF_UNLIT, unlit) == AI_SUCCESS && unlit) {
|
||||
mAsset->extensionsUsed.KHR_materials_unlit = true;
|
||||
m->unlit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -281,6 +281,9 @@ static aiMaterial* ImportMaterial(std::vector<int>& embeddedTexIdxs, Asset& r, M
|
|||
|
||||
SetMaterialTextureProperty(embeddedTexIdxs, r, pbrSG.specularGlossinessTexture, aimat, aiTextureType_SPECULAR);
|
||||
}
|
||||
if (mat.unlit) {
|
||||
aimat->AddProperty(&mat.unlit, 1, AI_MATKEY_GLTF_UNLIT);
|
||||
}
|
||||
|
||||
return aimat;
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#define AI_MATKEY_GLTF_ALPHACUTOFF "$mat.gltf.alphaCutoff", 0, 0
|
||||
#define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS "$mat.gltf.pbrSpecularGlossiness", 0, 0
|
||||
#define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_GLOSSINESS_FACTOR "$mat.gltf.pbrMetallicRoughness.glossinessFactor", 0, 0
|
||||
#define AI_MATKEY_GLTF_UNLIT "$mat.gltf.unlit", 0, 0
|
||||
|
||||
#define _AI_MATKEY_GLTF_TEXTURE_TEXCOORD_BASE "$tex.file.texCoord"
|
||||
#define _AI_MATKEY_GLTF_MAPPINGNAME_BASE "$tex.mappingname"
|
||||
|
|
Loading…
Reference in New Issue