Refactor enum flags with __underlying_type and new EnumHasAnyFlags/EnumHasAllFlags
Fixes #832 Closes #886
This commit is contained in:
@@ -195,9 +195,9 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo
|
||||
ADD_FEATURE(LightmapFeature);
|
||||
if (materialInfo.BlendMode == MaterialBlendMode::Opaque)
|
||||
ADD_FEATURE(DeferredShadingFeature);
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && (materialInfo.FeaturesFlags & MaterialFeaturesFlags::DisableDistortion) == 0)
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && (materialInfo.FeaturesFlags & MaterialFeaturesFlags::DisableDistortion) == MaterialFeaturesFlags::None)
|
||||
ADD_FEATURE(DistortionFeature);
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && (materialInfo.FeaturesFlags & MaterialFeaturesFlags::GlobalIllumination) != 0)
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && EnumHasAnyFlags(materialInfo.FeaturesFlags, MaterialFeaturesFlags::GlobalIllumination))
|
||||
ADD_FEATURE(GlobalIlluminationFeature);
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque)
|
||||
ADD_FEATURE(ForwardShadingFeature);
|
||||
@@ -209,9 +209,9 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo
|
||||
ADD_FEATURE(DeferredShadingFeature);
|
||||
break;
|
||||
case MaterialDomain::Particle:
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && (materialInfo.FeaturesFlags & MaterialFeaturesFlags::DisableDistortion) == 0)
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && (materialInfo.FeaturesFlags & MaterialFeaturesFlags::DisableDistortion) == MaterialFeaturesFlags::None)
|
||||
ADD_FEATURE(DistortionFeature);
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && (materialInfo.FeaturesFlags & MaterialFeaturesFlags::GlobalIllumination) != 0)
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && EnumHasAnyFlags(materialInfo.FeaturesFlags, MaterialFeaturesFlags::GlobalIllumination))
|
||||
ADD_FEATURE(GlobalIlluminationFeature);
|
||||
ADD_FEATURE(ForwardShadingFeature);
|
||||
break;
|
||||
@@ -330,15 +330,15 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo
|
||||
|
||||
// Normalize and transform to world space if need to
|
||||
_writer.Write(TEXT("\t{0}.TangentNormal = normalize({0}.TangentNormal);\n"), materialVarPS.Value);
|
||||
if ((baseLayer->FeaturesFlags & MaterialFeaturesFlags::InputWorldSpaceNormal) == 0)
|
||||
{
|
||||
_writer.Write(TEXT("\t{0}.WorldNormal = normalize(TransformTangentVectorToWorld(input, {0}.TangentNormal));\n"), materialVarPS.Value);
|
||||
}
|
||||
else
|
||||
if (EnumHasAllFlags(baseLayer->FeaturesFlags, MaterialFeaturesFlags::InputWorldSpaceNormal))
|
||||
{
|
||||
_writer.Write(TEXT("\t{0}.WorldNormal = {0}.TangentNormal;\n"), materialVarPS.Value);
|
||||
_writer.Write(TEXT("\t{0}.TangentNormal = normalize(TransformWorldVectorToTangent(input, {0}.WorldNormal));\n"), materialVarPS.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_writer.Write(TEXT("\t{0}.WorldNormal = normalize(TransformTangentVectorToWorld(input, {0}.TangentNormal));\n"), materialVarPS.Value);
|
||||
}
|
||||
|
||||
// Clamp values
|
||||
_writer.Write(TEXT("\t{0}.Metalness = saturate({0}.Metalness);\n"), materialVarPS.Value);
|
||||
@@ -421,7 +421,7 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo
|
||||
_writer.Write(TEXT("#define MATERIAL_MASK_THRESHOLD ({0})\n"), baseLayer->MaskThreshold);
|
||||
_writer.Write(TEXT("#define CUSTOM_VERTEX_INTERPOLATORS_COUNT ({0})\n"), _vsToPsInterpolants.Count());
|
||||
_writer.Write(TEXT("#define MATERIAL_OPACITY_THRESHOLD ({0})\n"), baseLayer->OpacityThreshold);
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && !(materialInfo.FeaturesFlags & MaterialFeaturesFlags::DisableReflections) && materialInfo.FeaturesFlags & MaterialFeaturesFlags::ScreenSpaceReflections)
|
||||
if (materialInfo.BlendMode != MaterialBlendMode::Opaque && !(materialInfo.FeaturesFlags & MaterialFeaturesFlags::DisableReflections) && EnumHasAnyFlags(materialInfo.FeaturesFlags, MaterialFeaturesFlags::ScreenSpaceReflections))
|
||||
{
|
||||
// Inject depth and color buffers for Screen Space Reflections used by transparent material
|
||||
auto sceneDepthTexture = findOrAddSceneTexture(MaterialSceneTextures::SceneDepth);
|
||||
|
||||
@@ -352,7 +352,7 @@ bool ProcessMesh(ImportedModelData& result, AssimpImporterData& data, const aiMe
|
||||
}
|
||||
|
||||
// Blend Indices and Blend Weights
|
||||
if (aMesh->mNumBones > 0 && aMesh->mBones && result.Types & ImportDataTypes::Skeleton)
|
||||
if (aMesh->mNumBones > 0 && aMesh->mBones && EnumHasAnyFlags(result.Types, ImportDataTypes::Skeleton))
|
||||
{
|
||||
const int32 vertexCount = mesh.Positions.Count();
|
||||
mesh.BlendIndices.Resize(vertexCount);
|
||||
@@ -433,7 +433,7 @@ bool ProcessMesh(ImportedModelData& result, AssimpImporterData& data, const aiMe
|
||||
}
|
||||
|
||||
// Blend Shapes
|
||||
if (aMesh->mNumAnimMeshes > 0 && result.Types & ImportDataTypes::Skeleton && data.Options.ImportBlendShapes)
|
||||
if (aMesh->mNumAnimMeshes > 0 && EnumHasAnyFlags(result.Types, ImportDataTypes::Skeleton) && data.Options.ImportBlendShapes)
|
||||
{
|
||||
mesh.BlendShapes.EnsureCapacity(aMesh->mNumAnimMeshes);
|
||||
for (unsigned int animMeshIndex = 0; animMeshIndex < aMesh->mNumAnimMeshes; animMeshIndex++)
|
||||
@@ -524,7 +524,7 @@ bool ImportMaterials(ImportedModelData& result, AssimpImporterData& data, String
|
||||
materialSlot.Name = String(aName.C_Str()).TrimTrailing();
|
||||
materialSlot.AssetID = Guid::Empty;
|
||||
|
||||
if (result.Types & ImportDataTypes::Materials)
|
||||
if (EnumHasAnyFlags(result.Types, ImportDataTypes::Materials))
|
||||
{
|
||||
aiColor3D aColor;
|
||||
if (aMaterial->Get(AI_MATKEY_COLOR_DIFFUSE, aColor) == AI_SUCCESS)
|
||||
@@ -536,7 +536,7 @@ bool ImportMaterials(ImportedModelData& result, AssimpImporterData& data, String
|
||||
if (aMaterial->Get(AI_MATKEY_OPACITY, aFloat) == AI_SUCCESS)
|
||||
materialSlot.Opacity.Value = aFloat;
|
||||
|
||||
if (result.Types & ImportDataTypes::Textures)
|
||||
if (EnumHasAnyFlags(result.Types, ImportDataTypes::Textures))
|
||||
{
|
||||
ImportMaterialTexture(result, data, aMaterial, aiTextureType_DIFFUSE, materialSlot.Diffuse.TextureIndex, TextureEntry::TypeHint::ColorRGB);
|
||||
ImportMaterialTexture(result, data, aMaterial, aiTextureType_EMISSIVE, materialSlot.Emissive.TextureIndex, TextureEntry::TypeHint::ColorRGB);
|
||||
@@ -641,8 +641,8 @@ bool ModelTool::ImportDataAssimp(const char* path, ImportedModelData& data, Opti
|
||||
AssimpInited = true;
|
||||
LOG(Info, "Assimp {0}.{1}.{2}", aiGetVersionMajor(), aiGetVersionMinor(), aiGetVersionRevision());
|
||||
}
|
||||
bool importMeshes = (data.Types & ImportDataTypes::Geometry) != 0;
|
||||
bool importAnimations = (data.Types & ImportDataTypes::Animations) != 0;
|
||||
bool importMeshes = EnumHasAnyFlags(data.Types, ImportDataTypes::Geometry);
|
||||
bool importAnimations = EnumHasAnyFlags(data.Types, ImportDataTypes::Animations);
|
||||
context = New<AssimpImporterData>(path, options);
|
||||
|
||||
// Setup import flags
|
||||
@@ -704,7 +704,7 @@ bool ModelTool::ImportDataAssimp(const char* path, ImportedModelData& data, Opti
|
||||
}
|
||||
|
||||
// Import geometry
|
||||
if (data.Types & ImportDataTypes::Geometry && context->Scene->HasMeshes())
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Geometry) && context->Scene->HasMeshes())
|
||||
{
|
||||
const int meshCount = context->Scene->mNumMeshes;
|
||||
if (options.SplitObjects && options.ObjectIndex == -1)
|
||||
@@ -747,7 +747,7 @@ bool ModelTool::ImportDataAssimp(const char* path, ImportedModelData& data, Opti
|
||||
}
|
||||
|
||||
// Import skeleton
|
||||
if (data.Types & ImportDataTypes::Skeleton)
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Skeleton))
|
||||
{
|
||||
data.Skeleton.Nodes.Resize(context->Nodes.Count(), false);
|
||||
for (int32 i = 0; i < context->Nodes.Count(); i++)
|
||||
@@ -777,7 +777,7 @@ bool ModelTool::ImportDataAssimp(const char* path, ImportedModelData& data, Opti
|
||||
}
|
||||
|
||||
// Import animations
|
||||
if (data.Types & ImportDataTypes::Animations && context->Scene->HasAnimations())
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Animations) && context->Scene->HasAnimations())
|
||||
{
|
||||
const int32 animCount = (int32)context->Scene->mNumAnimations;
|
||||
if (options.SplitObjects && options.ObjectIndex == -1)
|
||||
@@ -825,7 +825,7 @@ bool ModelTool::ImportDataAssimp(const char* path, ImportedModelData& data, Opti
|
||||
}
|
||||
|
||||
// Import nodes
|
||||
if (data.Types & ImportDataTypes::Nodes)
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Nodes))
|
||||
{
|
||||
data.Nodes.Resize(context->Nodes.Count());
|
||||
for (int32 i = 0; i < context->Nodes.Count(); i++)
|
||||
|
||||
@@ -219,11 +219,11 @@ struct OpenFbxImporterData
|
||||
if (mat)
|
||||
material.Name = String(mat->name).TrimTrailing();
|
||||
|
||||
if (mat && result.Types & ImportDataTypes::Materials)
|
||||
if (mat && EnumHasAnyFlags(result.Types, ImportDataTypes::Materials))
|
||||
{
|
||||
material.Diffuse.Color = ToColor(mat->getDiffuseColor());
|
||||
|
||||
if (result.Types & ImportDataTypes::Textures)
|
||||
if (EnumHasAnyFlags(result.Types, ImportDataTypes::Textures))
|
||||
{
|
||||
ImportMaterialTexture(result, mat, ofbx::Texture::DIFFUSE, material.Diffuse.TextureIndex, TextureEntry::TypeHint::ColorRGB);
|
||||
ImportMaterialTexture(result, mat, ofbx::Texture::EMISSIVE, material.Emissive.TextureIndex, TextureEntry::TypeHint::ColorRGB);
|
||||
@@ -698,7 +698,7 @@ bool ProcessMesh(ImportedModelData& result, OpenFbxImporterData& data, const ofb
|
||||
}
|
||||
|
||||
// Blend Indices and Blend Weights
|
||||
if (skin && skin->getClusterCount() > 0 && result.Types & ImportDataTypes::Skeleton)
|
||||
if (skin && skin->getClusterCount() > 0 && EnumHasAnyFlags(result.Types, ImportDataTypes::Skeleton))
|
||||
{
|
||||
mesh.BlendIndices.Resize(vertexCount);
|
||||
mesh.BlendWeights.Resize(vertexCount);
|
||||
@@ -764,7 +764,7 @@ bool ProcessMesh(ImportedModelData& result, OpenFbxImporterData& data, const ofb
|
||||
}
|
||||
|
||||
// Blend Shapes
|
||||
if (blendShape && blendShape->getBlendShapeChannelCount() > 0 && result.Types & ImportDataTypes::Skeleton && data.Options.ImportBlendShapes)
|
||||
if (blendShape && blendShape->getBlendShapeChannelCount() > 0 && EnumHasAnyFlags(result.Types, ImportDataTypes::Skeleton) && data.Options.ImportBlendShapes)
|
||||
{
|
||||
mesh.BlendShapes.EnsureCapacity(blendShape->getBlendShapeChannelCount());
|
||||
for (int32 channelIndex = 0; channelIndex < blendShape->getBlendShapeChannelCount(); channelIndex++)
|
||||
@@ -1130,7 +1130,7 @@ bool ModelTool::ImportDataOpenFBX(const char* path, ImportedModelData& data, Opt
|
||||
return true;
|
||||
}
|
||||
ofbx::u64 loadFlags = 0;
|
||||
if (data.Types & ImportDataTypes::Geometry)
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Geometry))
|
||||
loadFlags |= (ofbx::u64)ofbx::LoadFlags::TRIANGULATE;
|
||||
else
|
||||
loadFlags |= (ofbx::u64)ofbx::LoadFlags::IGNORE_GEOMETRY;
|
||||
@@ -1160,7 +1160,7 @@ bool ModelTool::ImportDataOpenFBX(const char* path, ImportedModelData& data, Opt
|
||||
LOG(Info, "Imported scene: Up={0}, Front={1}, Right={2}", context->Up, context->Front, context->Right);
|
||||
|
||||
// Extract embedded textures
|
||||
if (data.Types & ImportDataTypes::Textures)
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Textures))
|
||||
{
|
||||
String outputPath;
|
||||
for (int i = 0, c = scene->getEmbeddedDataCount(); i < c; i++)
|
||||
@@ -1229,7 +1229,7 @@ bool ModelTool::ImportDataOpenFBX(const char* path, ImportedModelData& data, Opt
|
||||
DeleteMe<OpenFbxImporterData> contextCleanup(options.SplitContext ? nullptr : context);
|
||||
|
||||
// Build final skeleton bones hierarchy before importing meshes
|
||||
if (data.Types & ImportDataTypes::Skeleton)
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Skeleton))
|
||||
{
|
||||
if (ImportBones(*context, errorMsg))
|
||||
{
|
||||
@@ -1241,7 +1241,7 @@ bool ModelTool::ImportDataOpenFBX(const char* path, ImportedModelData& data, Opt
|
||||
}
|
||||
|
||||
// Import geometry (meshes and materials)
|
||||
if (data.Types & ImportDataTypes::Geometry && context->Scene->getMeshCount() > 0)
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Geometry) && context->Scene->getMeshCount() > 0)
|
||||
{
|
||||
const int meshCount = context->Scene->getMeshCount();
|
||||
if (options.SplitObjects && options.ObjectIndex == -1)
|
||||
@@ -1284,7 +1284,7 @@ bool ModelTool::ImportDataOpenFBX(const char* path, ImportedModelData& data, Opt
|
||||
}
|
||||
|
||||
// Import skeleton
|
||||
if (data.Types & ImportDataTypes::Skeleton)
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Skeleton))
|
||||
{
|
||||
data.Skeleton.Nodes.Resize(context->Nodes.Count(), false);
|
||||
for (int32 i = 0; i < context->Nodes.Count(); i++)
|
||||
@@ -1324,7 +1324,7 @@ bool ModelTool::ImportDataOpenFBX(const char* path, ImportedModelData& data, Opt
|
||||
}
|
||||
|
||||
// Import animations
|
||||
if (data.Types & ImportDataTypes::Animations)
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Animations))
|
||||
{
|
||||
const int animCount = context->Scene->getAnimationStackCount();
|
||||
if (options.SplitObjects && options.ObjectIndex == -1)
|
||||
@@ -1367,7 +1367,7 @@ bool ModelTool::ImportDataOpenFBX(const char* path, ImportedModelData& data, Opt
|
||||
}
|
||||
|
||||
// Import nodes
|
||||
if (data.Types & ImportDataTypes::Nodes)
|
||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Nodes))
|
||||
{
|
||||
data.Nodes.Resize(context->Nodes.Count());
|
||||
for (int32 i = 0; i < context->Nodes.Count(); i++)
|
||||
|
||||
@@ -482,7 +482,7 @@ bool ModelTool::ImportData(const String& path, ImportedModelData& data, Options&
|
||||
}
|
||||
|
||||
// Flip normals of the imported geometry
|
||||
if (options.FlipNormals && data.Types & ImportDataTypes::Geometry)
|
||||
if (options.FlipNormals && EnumHasAnyFlags(data.Types, ImportDataTypes::Geometry))
|
||||
{
|
||||
for (auto& lod : data.LODs)
|
||||
{
|
||||
@@ -795,7 +795,7 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
|
||||
auto& texture = data.Textures[i];
|
||||
|
||||
// Auto-import textures
|
||||
if (autoImportOutput.IsEmpty() || (data.Types & ImportDataTypes::Textures) == 0 || texture.FilePath.IsEmpty())
|
||||
if (autoImportOutput.IsEmpty() || (data.Types & ImportDataTypes::Textures) == ImportDataTypes::None || texture.FilePath.IsEmpty())
|
||||
continue;
|
||||
String filename = StringUtils::GetFileNameWithoutExtension(texture.FilePath);
|
||||
for (int32 j = filename.Length() - 1; j >= 0; j--)
|
||||
@@ -842,7 +842,7 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
|
||||
material.Name = TEXT("Material ") + StringUtils::ToString(i);
|
||||
|
||||
// Auto-import materials
|
||||
if (autoImportOutput.IsEmpty() || (data.Types & ImportDataTypes::Materials) == 0 || !material.UsesProperties())
|
||||
if (autoImportOutput.IsEmpty() || (data.Types & ImportDataTypes::Materials) == ImportDataTypes::None || !material.UsesProperties())
|
||||
continue;
|
||||
auto filename = material.Name;
|
||||
for (int32 j = filename.Length() - 1; j >= 0; j--)
|
||||
|
||||
@@ -19,6 +19,8 @@ class JsonWriter;
|
||||
/// </summary>
|
||||
enum class ImportDataTypes : int32
|
||||
{
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Imports materials and meshes.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user