Support Double Sided Material
The material has the "isDoubleSided" bool parameter. Because some models have double-sided texture settings, the new bool parameter is added to determine whether Gltf 'doubleSided' is enabled. The default value of this parameter is false.
This commit is contained in:
parent
5c3229d6cf
commit
683c9aa8e7
|
@ -459,7 +459,7 @@ static void ReadMesh(
|
||||||
const RawMaterialType materialType =
|
const RawMaterialType materialType =
|
||||||
GetMaterialType(raw, textures, vertexTransparency, skinning.IsSkinned());
|
GetMaterialType(raw, textures, vertexTransparency, skinning.IsSkinned());
|
||||||
const int rawMaterialIndex = raw.AddMaterial(
|
const int rawMaterialIndex = raw.AddMaterial(
|
||||||
materialId, materialName, materialType, textures, rawMatProps, userProperties);
|
materialId, materialName, materialType, textures, rawMatProps, userProperties, false );
|
||||||
|
|
||||||
raw.AddTriangle(
|
raw.AddTriangle(
|
||||||
rawVertexIndices[0],
|
rawVertexIndices[0],
|
||||||
|
|
|
@ -392,9 +392,12 @@ ModelData* Raw2Gltf(
|
||||||
occlusionTexture = simpleTex(RAW_TEXTURE_USAGE_OCCLUSION).get();
|
occlusionTexture = simpleTex(RAW_TEXTURE_USAGE_OCCLUSION).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setting DoubleSided
|
||||||
|
const bool isDoubleSided = material.isDoubleSided;
|
||||||
std::shared_ptr<MaterialData> mData = gltf->materials.hold(new MaterialData(
|
std::shared_ptr<MaterialData> mData = gltf->materials.hold(new MaterialData(
|
||||||
material.name,
|
material.name,
|
||||||
isTransparent,
|
isTransparent,
|
||||||
|
isDoubleSided,
|
||||||
material.info->shadingModel,
|
material.info->shadingModel,
|
||||||
normalTexture,
|
normalTexture,
|
||||||
occlusionTexture,
|
occlusionTexture,
|
||||||
|
|
|
@ -73,6 +73,7 @@ void to_json(json& j, const PBRMetallicRoughness& d) {
|
||||||
MaterialData::MaterialData(
|
MaterialData::MaterialData(
|
||||||
std::string name,
|
std::string name,
|
||||||
bool isTransparent,
|
bool isTransparent,
|
||||||
|
bool isDoubleSided,
|
||||||
const RawShadingModel shadingModel,
|
const RawShadingModel shadingModel,
|
||||||
const TextureData* normalTexture,
|
const TextureData* normalTexture,
|
||||||
const TextureData* occlusionTexture,
|
const TextureData* occlusionTexture,
|
||||||
|
@ -84,6 +85,7 @@ MaterialData::MaterialData(
|
||||||
name(std::move(name)),
|
name(std::move(name)),
|
||||||
shadingModel(shadingModel),
|
shadingModel(shadingModel),
|
||||||
isTransparent(isTransparent),
|
isTransparent(isTransparent),
|
||||||
|
isDoubleSided(isDoubleSided),
|
||||||
normalTexture(Tex::ref(normalTexture)),
|
normalTexture(Tex::ref(normalTexture)),
|
||||||
occlusionTexture(Tex::ref(occlusionTexture)),
|
occlusionTexture(Tex::ref(occlusionTexture)),
|
||||||
emissiveTexture(Tex::ref(emissiveTexture)),
|
emissiveTexture(Tex::ref(emissiveTexture)),
|
||||||
|
@ -94,6 +96,7 @@ MaterialData::MaterialData(
|
||||||
json MaterialData::serialize() const {
|
json MaterialData::serialize() const {
|
||||||
json result = {{"name", name},
|
json result = {{"name", name},
|
||||||
{"alphaMode", isTransparent ? "BLEND" : "OPAQUE"},
|
{"alphaMode", isTransparent ? "BLEND" : "OPAQUE"},
|
||||||
|
{"doubleSided", isDoubleSided},
|
||||||
{"extras",
|
{"extras",
|
||||||
{{"fromFBX",
|
{{"fromFBX",
|
||||||
{{"shadingModel", Describe(shadingModel)},
|
{{"shadingModel", Describe(shadingModel)},
|
||||||
|
|
|
@ -43,6 +43,7 @@ struct MaterialData : Holdable {
|
||||||
MaterialData(
|
MaterialData(
|
||||||
std::string name,
|
std::string name,
|
||||||
bool isTransparent,
|
bool isTransparent,
|
||||||
|
bool isDoubleSided,
|
||||||
RawShadingModel shadingModel,
|
RawShadingModel shadingModel,
|
||||||
const TextureData* normalTexture,
|
const TextureData* normalTexture,
|
||||||
const TextureData* occlusionTexture,
|
const TextureData* occlusionTexture,
|
||||||
|
@ -56,6 +57,7 @@ struct MaterialData : Holdable {
|
||||||
const std::string name;
|
const std::string name;
|
||||||
const RawShadingModel shadingModel;
|
const RawShadingModel shadingModel;
|
||||||
const bool isTransparent;
|
const bool isTransparent;
|
||||||
|
const bool isDoubleSided;
|
||||||
const std::unique_ptr<const Tex> normalTexture;
|
const std::unique_ptr<const Tex> normalTexture;
|
||||||
const std::unique_ptr<const Tex> occlusionTexture;
|
const std::unique_ptr<const Tex> occlusionTexture;
|
||||||
const std::unique_ptr<const Tex> emissiveTexture;
|
const std::unique_ptr<const Tex> emissiveTexture;
|
||||||
|
|
|
@ -142,7 +142,8 @@ int RawModel::AddMaterial(const RawMaterial& material) {
|
||||||
material.type,
|
material.type,
|
||||||
material.textures,
|
material.textures,
|
||||||
material.info,
|
material.info,
|
||||||
material.userProperties);
|
material.userProperties,
|
||||||
|
material.isDoubleSided);
|
||||||
}
|
}
|
||||||
|
|
||||||
int RawModel::AddMaterial(
|
int RawModel::AddMaterial(
|
||||||
|
@ -151,7 +152,8 @@ int RawModel::AddMaterial(
|
||||||
const RawMaterialType materialType,
|
const RawMaterialType materialType,
|
||||||
const int textures[RAW_TEXTURE_USAGE_MAX],
|
const int textures[RAW_TEXTURE_USAGE_MAX],
|
||||||
std::shared_ptr<RawMatProps> materialInfo,
|
std::shared_ptr<RawMatProps> materialInfo,
|
||||||
const std::vector<std::string>& userProperties) {
|
const std::vector<std::string>& userProperties,
|
||||||
|
const bool isDoubleSided ) {
|
||||||
for (size_t i = 0; i < materials.size(); i++) {
|
for (size_t i = 0; i < materials.size(); i++) {
|
||||||
if (materials[i].name != name) {
|
if (materials[i].name != name) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -184,6 +186,7 @@ int RawModel::AddMaterial(
|
||||||
material.type = materialType;
|
material.type = materialType;
|
||||||
material.info = materialInfo;
|
material.info = materialInfo;
|
||||||
material.userProperties = userProperties;
|
material.userProperties = userProperties;
|
||||||
|
material.isDoubleSided = isDoubleSided;
|
||||||
|
|
||||||
for (int i = 0; i < RAW_TEXTURE_USAGE_MAX; i++) {
|
for (int i = 0; i < RAW_TEXTURE_USAGE_MAX; i++) {
|
||||||
material.textures[i] = textures[i];
|
material.textures[i] = textures[i];
|
||||||
|
|
|
@ -258,6 +258,7 @@ struct RawMaterial {
|
||||||
std::shared_ptr<RawMatProps> info;
|
std::shared_ptr<RawMatProps> info;
|
||||||
int textures[RAW_TEXTURE_USAGE_MAX];
|
int textures[RAW_TEXTURE_USAGE_MAX];
|
||||||
std::vector<std::string> userProperties;
|
std::vector<std::string> userProperties;
|
||||||
|
bool isDoubleSided;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum RawLightType {
|
enum RawLightType {
|
||||||
|
@ -370,7 +371,8 @@ class RawModel {
|
||||||
const RawMaterialType materialType,
|
const RawMaterialType materialType,
|
||||||
const int textures[RAW_TEXTURE_USAGE_MAX],
|
const int textures[RAW_TEXTURE_USAGE_MAX],
|
||||||
std::shared_ptr<RawMatProps> materialInfo,
|
std::shared_ptr<RawMatProps> materialInfo,
|
||||||
const std::vector<std::string>& userProperties);
|
const std::vector<std::string>& userProperties,
|
||||||
|
const bool isDoubleSided );
|
||||||
int AddLight(
|
int AddLight(
|
||||||
const char* name,
|
const char* name,
|
||||||
RawLightType lightType,
|
RawLightType lightType,
|
||||||
|
|
Loading…
Reference in New Issue