Implement pbrSpecularGlossiness property as Nullable
parent
03cfa04ee4
commit
44757af34a
|
@ -711,12 +711,14 @@ namespace glTF2
|
|||
|
||||
struct PbrSpecularGlossiness
|
||||
{
|
||||
bool on = false;
|
||||
vec4 diffuseFactor;
|
||||
vec3 specularFactor;
|
||||
float glossinessFactor;
|
||||
TextureInfo diffuseTexture;
|
||||
TextureInfo specularGlossinessTexture;
|
||||
TextureInfo specularGlossinessTexture;
|
||||
|
||||
PbrSpecularGlossiness() { SetDefaults(); }
|
||||
void SetDefaults();
|
||||
};
|
||||
|
||||
//! The material appearance of a primitive.
|
||||
|
@ -735,7 +737,7 @@ namespace glTF2
|
|||
bool doubleSided;
|
||||
|
||||
//extension: KHR_materials_pbrSpecularGlossiness
|
||||
PbrSpecularGlossiness pbrSpecularGlossiness;
|
||||
Nullable<PbrSpecularGlossiness> pbrSpecularGlossiness;
|
||||
|
||||
Material() { SetDefaults(); }
|
||||
void Read(Value& obj, Asset& r);
|
||||
|
|
|
@ -790,13 +790,15 @@ inline void Material::Read(Value& material, Asset& r)
|
|||
if (Value* extensions = FindObject(material, "extensions")) {
|
||||
if (r.extensionsUsed.KHR_materials_pbrSpecularGlossiness) {
|
||||
if (Value* pbrSpecularGlossiness = FindObject(*extensions, "KHR_materials_pbrSpecularGlossiness")) {
|
||||
this->pbrSpecularGlossiness.on = true;
|
||||
PbrSpecularGlossiness pbrSG;
|
||||
|
||||
ReadMember(*pbrSpecularGlossiness, "diffuseFactor", this->pbrSpecularGlossiness.diffuseFactor);
|
||||
ReadTextureProperty(r, *pbrSpecularGlossiness, "diffuseTexture", this->pbrSpecularGlossiness.diffuseTexture);
|
||||
ReadTextureProperty(r, *pbrSpecularGlossiness, "specularGlossinessTexture", this->pbrSpecularGlossiness.specularGlossinessTexture);
|
||||
ReadMember(*pbrSpecularGlossiness, "specularFactor", this->pbrSpecularGlossiness.specularFactor);
|
||||
ReadMember(*pbrSpecularGlossiness, "glossinessFactor", this->pbrSpecularGlossiness.glossinessFactor);
|
||||
ReadMember(*pbrSpecularGlossiness, "diffuseFactor", pbrSG.diffuseFactor);
|
||||
ReadTextureProperty(r, *pbrSpecularGlossiness, "diffuseTexture", pbrSG.diffuseTexture);
|
||||
ReadTextureProperty(r, *pbrSpecularGlossiness, "specularGlossinessTexture", pbrSG.specularGlossinessTexture);
|
||||
ReadMember(*pbrSpecularGlossiness, "specularFactor", pbrSG.specularFactor);
|
||||
ReadMember(*pbrSpecularGlossiness, "glossinessFactor", pbrSG.glossinessFactor);
|
||||
|
||||
this->pbrSpecularGlossiness = Nullable<PbrSpecularGlossiness>(pbrSG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -821,11 +823,14 @@ inline void Material::SetDefaults()
|
|||
alphaMode = "OPAQUE";
|
||||
alphaCutoff = 0.5;
|
||||
doubleSided = false;
|
||||
}
|
||||
|
||||
inline void PbrSpecularGlossiness::SetDefaults()
|
||||
{
|
||||
//pbrSpecularGlossiness properties
|
||||
SetVector(pbrSpecularGlossiness.diffuseFactor, defaultDiffuseFactor);
|
||||
SetVector(pbrSpecularGlossiness.specularFactor, defaultSpecularFactor);
|
||||
pbrSpecularGlossiness.glossinessFactor = 1.0;
|
||||
SetVector(diffuseFactor, defaultDiffuseFactor);
|
||||
SetVector(specularFactor, defaultSpecularFactor);
|
||||
glossinessFactor = 1.0;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -324,22 +324,23 @@ namespace glTF2 {
|
|||
Value exts;
|
||||
exts.SetObject();
|
||||
|
||||
if (m.pbrSpecularGlossiness.on) {
|
||||
if (m.pbrSpecularGlossiness.isPresent) {
|
||||
Value pbrSpecularGlossiness;
|
||||
pbrSpecularGlossiness.SetObject();
|
||||
{
|
||||
//pbrSpecularGlossiness
|
||||
WriteVec(pbrSpecularGlossiness, m.pbrSpecularGlossiness.diffuseFactor, "diffuseFactor", defaultDiffuseFactor, w.mAl);
|
||||
WriteVec(pbrSpecularGlossiness, m.pbrSpecularGlossiness.specularFactor, "specularFactor", defaultSpecularFactor, w.mAl);
|
||||
|
||||
if (m.pbrSpecularGlossiness.glossinessFactor != 1) {
|
||||
WriteFloat(obj, m.pbrSpecularGlossiness.glossinessFactor, "glossinessFactor", w.mAl);
|
||||
}
|
||||
PbrSpecularGlossiness &pbrSG = m.pbrSpecularGlossiness.value;
|
||||
|
||||
WriteTex(pbrSpecularGlossiness, m.pbrSpecularGlossiness.diffuseTexture, "diffuseTexture", w.mAl);
|
||||
WriteTex(pbrSpecularGlossiness, m.pbrSpecularGlossiness.specularGlossinessTexture, "specularGlossinessTexture", w.mAl);
|
||||
//pbrSpecularGlossiness
|
||||
WriteVec(pbrSpecularGlossiness, pbrSG.diffuseFactor, "diffuseFactor", defaultDiffuseFactor, w.mAl);
|
||||
WriteVec(pbrSpecularGlossiness, pbrSG.specularFactor, "specularFactor", defaultSpecularFactor, w.mAl);
|
||||
|
||||
if (pbrSG.glossinessFactor != 1) {
|
||||
WriteFloat(obj, pbrSG.glossinessFactor, "glossinessFactor", w.mAl);
|
||||
}
|
||||
|
||||
WriteTex(pbrSpecularGlossiness, pbrSG.diffuseTexture, "diffuseTexture", w.mAl);
|
||||
WriteTex(pbrSpecularGlossiness, pbrSG.specularGlossinessTexture, "specularGlossinessTexture", w.mAl);
|
||||
|
||||
if (!pbrSpecularGlossiness.ObjectEmpty()) {
|
||||
exts.AddMember("KHR_materials_pbrSpecularGlossiness", pbrSpecularGlossiness, w.mAl);
|
||||
}
|
||||
|
|
|
@ -439,12 +439,15 @@ void glTF2Exporter::ExportMaterials()
|
|||
KHR_materials_pbrSpecularGlossiness = true;
|
||||
}
|
||||
|
||||
m->pbrSpecularGlossiness.on = true;
|
||||
GetMatColor(mat, m->pbrSpecularGlossiness.diffuseFactor, "$clr.diffuse", 0, 1);
|
||||
GetMatColor(mat, m->pbrSpecularGlossiness.specularFactor, "$clr.specular", 0, 1);
|
||||
mat->Get("$mat.gltf.glossinessFactor", 0, 0, m->pbrSpecularGlossiness.glossinessFactor);
|
||||
GetMatTex(mat, m->pbrSpecularGlossiness.diffuseTexture, aiTextureType_DIFFUSE, 1);
|
||||
GetMatTex(mat, m->pbrSpecularGlossiness.specularGlossinessTexture, aiTextureType_UNKNOWN, 1);
|
||||
PbrSpecularGlossiness pbrSG;
|
||||
|
||||
GetMatColor(mat, pbrSG.diffuseFactor, "$clr.diffuse", 0, 1);
|
||||
GetMatColor(mat, pbrSG.specularFactor, "$clr.specular", 0, 1);
|
||||
mat->Get("$mat.gltf.glossinessFactor", 0, 0, pbrSG.glossinessFactor);
|
||||
GetMatTex(mat, pbrSG.diffuseTexture, aiTextureType_DIFFUSE, 1);
|
||||
GetMatTex(mat, pbrSG.specularGlossinessTexture, aiTextureType_UNKNOWN, 1);
|
||||
|
||||
m->pbrSpecularGlossiness = Nullable<PbrSpecularGlossiness>(pbrSG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,13 +249,13 @@ void glTF2Importer::ImportMaterials(glTF2::Asset& r)
|
|||
aimat->AddProperty(&mat.alphaCutoff, 1, "$mat.gltf.alphaCutoff");
|
||||
|
||||
//pbrSpecularGlossiness
|
||||
if (mat.pbrSpecularGlossiness.on) {
|
||||
aimat->AddProperty(&mat.pbrSpecularGlossiness.on, 1, "$mat.gltf.pbrSpecularGlossiness.on");
|
||||
SetMaterialColorProperty(r, mat.pbrSpecularGlossiness.diffuseFactor, aimat, "$clr.diffuse", 0, 1);
|
||||
SetMaterialColorProperty(r, mat.pbrSpecularGlossiness.specularFactor, aimat, "$clr.specular", 0, 1);
|
||||
aimat->AddProperty(&mat.pbrSpecularGlossiness.glossinessFactor, 1, "$mat.gltf.pbrSpecularGlossiness.glossinessFactor");
|
||||
SetMaterialTextureProperty(embeddedTexIdxs, r, mat.pbrSpecularGlossiness.diffuseTexture, aimat, aiTextureType_DIFFUSE, 1);
|
||||
SetMaterialTextureProperty(embeddedTexIdxs, r, mat.pbrSpecularGlossiness.specularGlossinessTexture, aimat, aiTextureType_UNKNOWN, 1);
|
||||
if (mat.pbrSpecularGlossiness.isPresent) {
|
||||
aimat->AddProperty(&mat.pbrSpecularGlossiness.isPresent, 1, "$mat.gltf.pbrSpecularGlossiness.on");
|
||||
SetMaterialColorProperty(r, mat.pbrSpecularGlossiness.value.diffuseFactor, aimat, "$clr.diffuse", 0, 1);
|
||||
SetMaterialColorProperty(r, mat.pbrSpecularGlossiness.value.specularFactor, aimat, "$clr.specular", 0, 1);
|
||||
aimat->AddProperty(&mat.pbrSpecularGlossiness.value.glossinessFactor, 1, "$mat.gltf.pbrSpecularGlossiness.glossinessFactor");
|
||||
SetMaterialTextureProperty(embeddedTexIdxs, r, mat.pbrSpecularGlossiness.value.diffuseTexture, aimat, aiTextureType_DIFFUSE, 1);
|
||||
SetMaterialTextureProperty(embeddedTexIdxs, r, mat.pbrSpecularGlossiness.value.specularGlossinessTexture, aimat, aiTextureType_UNKNOWN, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue