parent
41f8a5ef03
commit
74479426a7
|
@ -0,0 +1 @@
|
||||||
|
build/
|
|
@ -852,6 +852,9 @@ ModelData *Raw2Gltf(
|
||||||
diffuseTex.get(), diffuseFactor, specGlossTex.get(), specularFactor, glossiness));
|
diffuseTex.get(), diffuseFactor, specGlossTex.get(), specularFactor, glossiness));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextureData *normalTexture = simpleTex(RAW_TEXTURE_USAGE_NORMAL).get();
|
||||||
|
TextureData *emissiveTexture = simpleTex(RAW_TEXTURE_USAGE_EMISSIVE).get();
|
||||||
|
|
||||||
std::shared_ptr<KHRCommonMats> khrComMat;
|
std::shared_ptr<KHRCommonMats> khrComMat;
|
||||||
if (options.useKHRMatCom) {
|
if (options.useKHRMatCom) {
|
||||||
float shininess;
|
float shininess;
|
||||||
|
@ -905,12 +908,38 @@ ModelData *Raw2Gltf(
|
||||||
diffuseTex.get(), diffuseFactor,
|
diffuseTex.get(), diffuseFactor,
|
||||||
simpleTex(RAW_TEXTURE_USAGE_SPECULAR).get(), specularFactor));
|
simpleTex(RAW_TEXTURE_USAGE_SPECULAR).get(), specularFactor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<KHRCmnConstantMaterial> khrCmnConstantMat;
|
||||||
|
if (options.useKHRMatCmnConstant) {
|
||||||
|
normalTexture = nullptr;
|
||||||
|
|
||||||
|
emissiveTexture = nullptr;
|
||||||
|
emissiveFactor = Vec3f(0.00f, 0.00f, 0.00f);
|
||||||
|
|
||||||
|
Vec4f diffuseFactor;
|
||||||
|
std::shared_ptr<TextureData> baseColorTex;
|
||||||
|
|
||||||
|
if (material.info->shadingModel == RAW_SHADING_MODEL_PBR_MET_ROUGH) {
|
||||||
|
RawMetRoughMatProps *props = (RawMetRoughMatProps *) material.info.get();
|
||||||
|
diffuseFactor = props->diffuseFactor;
|
||||||
|
baseColorTex = simpleTex(RAW_TEXTURE_USAGE_ALBEDO);
|
||||||
|
} else {
|
||||||
|
RawTraditionalMatProps *props = ((RawTraditionalMatProps *) material.info.get());
|
||||||
|
diffuseFactor = props->diffuseFactor;
|
||||||
|
baseColorTex = simpleTex(RAW_TEXTURE_USAGE_DIFFUSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
pbrMetRough.reset(new PBRMetallicRoughness(baseColorTex.get(), nullptr, diffuseFactor, 0.0f, 1.0f));
|
||||||
|
|
||||||
|
khrCmnConstantMat.reset(new KHRCmnConstantMaterial());
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<MaterialData> mData = gltf->materials.hold(
|
std::shared_ptr<MaterialData> mData = gltf->materials.hold(
|
||||||
new MaterialData(
|
new MaterialData(
|
||||||
material.name, isTransparent,
|
material.name, isTransparent,
|
||||||
simpleTex(RAW_TEXTURE_USAGE_NORMAL).get(), simpleTex(RAW_TEXTURE_USAGE_EMISSIVE).get(),
|
normalTexture, emissiveTexture,
|
||||||
emissiveFactor * emissiveIntensity,
|
emissiveFactor * emissiveIntensity,
|
||||||
khrComMat, pbrMetRough, pbrSpecGloss));
|
khrComMat, khrCmnConstantMat, pbrMetRough, pbrSpecGloss));
|
||||||
materialsByName[materialHash(material)] = mData;
|
materialsByName[materialHash(material)] = mData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1188,6 +1217,9 @@ ModelData *Raw2Gltf(
|
||||||
extensionsRequired.push_back(KHR_MATERIALS_COMMON);
|
extensionsRequired.push_back(KHR_MATERIALS_COMMON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (options.useKHRMatCmnConstant) {
|
||||||
|
extensionsUsed.push_back(KHR_MATERIALS_CMN_CONSTANT);
|
||||||
|
}
|
||||||
if (options.usePBRSpecGloss) {
|
if (options.usePBRSpecGloss) {
|
||||||
extensionsUsed.push_back(KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS);
|
extensionsUsed.push_back(KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS);
|
||||||
if (!options.useKHRMatCom && !options.usePBRMetRough) {
|
if (!options.useKHRMatCom && !options.usePBRMetRough) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ using json = nlohmann::basic_json<workaround_fifo_map>;
|
||||||
|
|
||||||
static const std::string KHR_DRACO_MESH_COMPRESSION = "KHR_draco_mesh_compression";
|
static const std::string KHR_DRACO_MESH_COMPRESSION = "KHR_draco_mesh_compression";
|
||||||
static const std::string KHR_MATERIALS_COMMON = "KHR_materials_common";
|
static const std::string KHR_MATERIALS_COMMON = "KHR_materials_common";
|
||||||
|
static const std::string KHR_MATERIALS_CMN_CONSTANT = "KHR_materials_unlit";
|
||||||
static const std::string KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS = "KHR_materials_pbrSpecularGlossiness";
|
static const std::string KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS = "KHR_materials_pbrSpecularGlossiness";
|
||||||
|
|
||||||
static const std::string extBufferFilename = "buffer.bin";
|
static const std::string extBufferFilename = "buffer.bin";
|
||||||
|
@ -54,6 +55,8 @@ struct GltfOptions
|
||||||
bool useDraco;
|
bool useDraco;
|
||||||
/** Whether to use KHR_materials_common to extend materials definitions. */
|
/** Whether to use KHR_materials_common to extend materials definitions. */
|
||||||
bool useKHRMatCom;
|
bool useKHRMatCom;
|
||||||
|
/** Whether to use KHR_materials_cmnConstant to extend materials definitions. */
|
||||||
|
bool useKHRMatCmnConstant;
|
||||||
/** Whether to populate the pbrMetallicRoughness substruct in materials. */
|
/** Whether to populate the pbrMetallicRoughness substruct in materials. */
|
||||||
bool usePBRMetRough;
|
bool usePBRMetRough;
|
||||||
/** Whether to use KHR_materials_pbrSpecularGlossiness to extend material definitions. */
|
/** Whether to use KHR_materials_pbrSpecularGlossiness to extend material definitions. */
|
||||||
|
|
|
@ -93,6 +93,15 @@ void to_json(json &j, const KHRCommonMats &d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KHRCmnConstantMaterial::KHRCmnConstantMaterial()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void to_json(json &j, const KHRCmnConstantMaterial &d)
|
||||||
|
{
|
||||||
|
j = json({});
|
||||||
|
}
|
||||||
|
|
||||||
PBRSpecularGlossiness::PBRSpecularGlossiness(
|
PBRSpecularGlossiness::PBRSpecularGlossiness(
|
||||||
const TextureData *diffuseTexture, const Vec4f &diffuseFactor,
|
const TextureData *diffuseTexture, const Vec4f &diffuseFactor,
|
||||||
const TextureData *specularGlossinessTexture, const Vec3f &specularFactor,
|
const TextureData *specularGlossinessTexture, const Vec3f &specularFactor,
|
||||||
|
@ -161,6 +170,7 @@ MaterialData::MaterialData(
|
||||||
std::string name, bool isTransparent, const TextureData *normalTexture,
|
std::string name, bool isTransparent, const TextureData *normalTexture,
|
||||||
const TextureData *emissiveTexture, const Vec3f & emissiveFactor,
|
const TextureData *emissiveTexture, const Vec3f & emissiveFactor,
|
||||||
std::shared_ptr<KHRCommonMats> const khrCommonMats,
|
std::shared_ptr<KHRCommonMats> const khrCommonMats,
|
||||||
|
std::shared_ptr<KHRCmnConstantMaterial> const khrCmnConstantMaterial,
|
||||||
std::shared_ptr<PBRMetallicRoughness> const pbrMetallicRoughness,
|
std::shared_ptr<PBRMetallicRoughness> const pbrMetallicRoughness,
|
||||||
std::shared_ptr<PBRSpecularGlossiness> const pbrSpecularGlossiness)
|
std::shared_ptr<PBRSpecularGlossiness> const pbrSpecularGlossiness)
|
||||||
: Holdable(),
|
: Holdable(),
|
||||||
|
@ -170,6 +180,7 @@ MaterialData::MaterialData(
|
||||||
emissiveTexture(Tex::ref(emissiveTexture)),
|
emissiveTexture(Tex::ref(emissiveTexture)),
|
||||||
emissiveFactor(std::move(emissiveFactor)),
|
emissiveFactor(std::move(emissiveFactor)),
|
||||||
khrCommonMats(khrCommonMats),
|
khrCommonMats(khrCommonMats),
|
||||||
|
khrCmnConstantMaterial(khrCmnConstantMaterial),
|
||||||
pbrMetallicRoughness(pbrMetallicRoughness),
|
pbrMetallicRoughness(pbrMetallicRoughness),
|
||||||
pbrSpecularGlossiness(pbrSpecularGlossiness) {}
|
pbrSpecularGlossiness(pbrSpecularGlossiness) {}
|
||||||
|
|
||||||
|
@ -192,11 +203,14 @@ json MaterialData::serialize() const
|
||||||
if (pbrMetallicRoughness != nullptr) {
|
if (pbrMetallicRoughness != nullptr) {
|
||||||
result["pbrMetallicRoughness"] = *pbrMetallicRoughness;
|
result["pbrMetallicRoughness"] = *pbrMetallicRoughness;
|
||||||
}
|
}
|
||||||
if (khrCommonMats != nullptr || pbrSpecularGlossiness != nullptr) {
|
if (khrCommonMats != nullptr || khrCmnConstantMaterial != nullptr || pbrSpecularGlossiness != nullptr) {
|
||||||
json extensions = { };
|
json extensions = { };
|
||||||
if (khrCommonMats != nullptr) {
|
if (khrCommonMats != nullptr) {
|
||||||
extensions[KHR_MATERIALS_COMMON] = *khrCommonMats;
|
extensions[KHR_MATERIALS_COMMON] = *khrCommonMats;
|
||||||
}
|
}
|
||||||
|
if (khrCmnConstantMaterial != nullptr) {
|
||||||
|
extensions[KHR_MATERIALS_CMN_CONSTANT] = *khrCmnConstantMaterial;
|
||||||
|
}
|
||||||
if (pbrSpecularGlossiness != nullptr) {
|
if (pbrSpecularGlossiness != nullptr) {
|
||||||
extensions[KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS] = *pbrSpecularGlossiness;
|
extensions[KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS] = *pbrSpecularGlossiness;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,11 @@ struct KHRCommonMats
|
||||||
const Vec3f specularFactor;
|
const Vec3f specularFactor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct KHRCmnConstantMaterial
|
||||||
|
{
|
||||||
|
KHRCmnConstantMaterial();
|
||||||
|
};
|
||||||
|
|
||||||
struct PBRSpecularGlossiness
|
struct PBRSpecularGlossiness
|
||||||
{
|
{
|
||||||
PBRSpecularGlossiness(
|
PBRSpecularGlossiness(
|
||||||
|
@ -86,6 +91,7 @@ struct MaterialData : Holdable
|
||||||
std::string name, bool isTransparent, const TextureData *normalTexture,
|
std::string name, bool isTransparent, const TextureData *normalTexture,
|
||||||
const TextureData *emissiveTexture, const Vec3f &emissiveFactor,
|
const TextureData *emissiveTexture, const Vec3f &emissiveFactor,
|
||||||
std::shared_ptr<KHRCommonMats> const khrCommonMats,
|
std::shared_ptr<KHRCommonMats> const khrCommonMats,
|
||||||
|
std::shared_ptr<KHRCmnConstantMaterial> const khrCmnConstantMaterial,
|
||||||
std::shared_ptr<PBRMetallicRoughness> const pbrMetallicRoughness,
|
std::shared_ptr<PBRMetallicRoughness> const pbrMetallicRoughness,
|
||||||
std::shared_ptr<PBRSpecularGlossiness> const pbrSpecularGlossiness);
|
std::shared_ptr<PBRSpecularGlossiness> const pbrSpecularGlossiness);
|
||||||
|
|
||||||
|
@ -97,13 +103,15 @@ struct MaterialData : Holdable
|
||||||
const std::unique_ptr<const Tex> emissiveTexture;
|
const std::unique_ptr<const Tex> emissiveTexture;
|
||||||
const Vec3f emissiveFactor;
|
const Vec3f emissiveFactor;
|
||||||
|
|
||||||
const std::shared_ptr<const KHRCommonMats> khrCommonMats;
|
const std::shared_ptr<const KHRCommonMats> khrCommonMats;
|
||||||
const std::shared_ptr<const PBRMetallicRoughness> pbrMetallicRoughness;
|
const std::shared_ptr<const KHRCmnConstantMaterial> khrCmnConstantMaterial;
|
||||||
const std::shared_ptr<const PBRSpecularGlossiness> pbrSpecularGlossiness;
|
const std::shared_ptr<const PBRMetallicRoughness> pbrMetallicRoughness;
|
||||||
|
const std::shared_ptr<const PBRSpecularGlossiness> pbrSpecularGlossiness;
|
||||||
};
|
};
|
||||||
|
|
||||||
void to_json(json &j, const Tex &data);
|
void to_json(json &j, const Tex &data);
|
||||||
void to_json(json &j, const KHRCommonMats &d);
|
void to_json(json &j, const KHRCommonMats &d);
|
||||||
|
void to_json(json &j, const KHRCmnConstantMaterial &d);
|
||||||
void to_json(json &j, const PBRSpecularGlossiness &d);
|
void to_json(json &j, const PBRSpecularGlossiness &d);
|
||||||
void to_json(json &j, const PBRMetallicRoughness &d);
|
void to_json(json &j, const PBRMetallicRoughness &d);
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ int main(int argc, char *argv[])
|
||||||
false, // embedResources
|
false, // embedResources
|
||||||
false, // useDraco
|
false, // useDraco
|
||||||
false, // useKHRMatCom
|
false, // useKHRMatCom
|
||||||
|
false, // useKHRMatCmnConstant
|
||||||
false, // usePBRMetRough
|
false, // usePBRMetRough
|
||||||
false, // usePBRSpecGloss
|
false, // usePBRSpecGloss
|
||||||
false, // useBlendShapeNormals
|
false, // useBlendShapeNormals
|
||||||
|
@ -77,6 +78,9 @@ int main(int argc, char *argv[])
|
||||||
(
|
(
|
||||||
"khr-materials-common", "(WIP) Use KHR_materials_common extensions to specify Unlit/Lambert/Blinn/Phong shaders.",
|
"khr-materials-common", "(WIP) Use KHR_materials_common extensions to specify Unlit/Lambert/Blinn/Phong shaders.",
|
||||||
cxxopts::value<bool>(gltfOptions.useKHRMatCom))
|
cxxopts::value<bool>(gltfOptions.useKHRMatCom))
|
||||||
|
(
|
||||||
|
"khr-materials-cmnConstant", "(WIP) Use KHR_materials_cmnConstant extension to specify Unlit shader.",
|
||||||
|
cxxopts::value<bool>(gltfOptions.useKHRMatCmnConstant))
|
||||||
(
|
(
|
||||||
"pbr-metallic-roughness", "(WIP) Try to glean glTF 2.0 native PBR attributes from the FBX.",
|
"pbr-metallic-roughness", "(WIP) Try to glean glTF 2.0 native PBR attributes from the FBX.",
|
||||||
cxxopts::value<bool>(gltfOptions.usePBRMetRough))
|
cxxopts::value<bool>(gltfOptions.usePBRMetRough))
|
||||||
|
@ -129,7 +133,7 @@ Copyright (c) 2016-2017 Oculus VR, LLC.
|
||||||
verboseOutput = true;
|
verboseOutput = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gltfOptions.useKHRMatCom && !gltfOptions.usePBRSpecGloss && !gltfOptions.usePBRMetRough) {
|
if (!gltfOptions.useKHRMatCmnConstant && !gltfOptions.useKHRMatCom && !gltfOptions.usePBRSpecGloss && !gltfOptions.usePBRMetRough) {
|
||||||
if (verboseOutput) {
|
if (verboseOutput) {
|
||||||
fmt::printf("Defaulting to --pbr-metallic-roughness material support.\n");
|
fmt::printf("Defaulting to --pbr-metallic-roughness material support.\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue