Merge branch 'feature/negative-model-import-reverse-winding' of https://github.com/GaryMcWhorter/FlaxEngine into GaryMcWhorter-feature/negative-model-import-reverse-winding
This commit is contained in:
@@ -765,6 +765,8 @@ bool ModelTool::ImportDataAssimp(const String& path, ModelData& data, Options& o
|
|||||||
flags |= aiProcess_FixInfacingNormals | aiProcess_GenSmoothNormals;
|
flags |= aiProcess_FixInfacingNormals | aiProcess_GenSmoothNormals;
|
||||||
if (options.CalculateTangents)
|
if (options.CalculateTangents)
|
||||||
flags |= aiProcess_CalcTangentSpace;
|
flags |= aiProcess_CalcTangentSpace;
|
||||||
|
if (options.ReverseWindingOrder)
|
||||||
|
flags &= ~aiProcess_FlipWindingOrder;
|
||||||
if (options.OptimizeMeshes)
|
if (options.OptimizeMeshes)
|
||||||
flags |= aiProcess_OptimizeMeshes | aiProcess_SplitLargeMeshes | aiProcess_ImproveCacheLocality;
|
flags |= aiProcess_OptimizeMeshes | aiProcess_SplitLargeMeshes | aiProcess_ImproveCacheLocality;
|
||||||
if (options.MergeMeshes)
|
if (options.MergeMeshes)
|
||||||
|
|||||||
@@ -385,6 +385,19 @@ bool ProcessMesh(ImporterData& data, FbxMesh* fbxMesh, MeshData& mesh, String& e
|
|||||||
mesh.Indices[i] = fbxIndices[i];
|
mesh.Indices[i] = fbxIndices[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.Options.ReverseWindingOrder)
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < vertexCount; i += 3)
|
||||||
|
{
|
||||||
|
Swap(meshIndices[i + 1], meshIndices[i + 2]);
|
||||||
|
Swap(meshPositions[i + 1], meshPositions[i + 2]);
|
||||||
|
if (meshNormals)
|
||||||
|
Swap(meshNormals[i + 1], meshNormals[i + 2]);
|
||||||
|
if (meshTangents)
|
||||||
|
Swap(meshTangents[i + 1], meshTangents[i + 2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Texture coordinates
|
// Texture coordinates
|
||||||
FbxGeometryElementUV* texcoords = fbxMesh->GetElementUV(0);
|
FbxGeometryElementUV* texcoords = fbxMesh->GetElementUV(0);
|
||||||
if (texcoords)
|
if (texcoords)
|
||||||
|
|||||||
@@ -775,6 +775,24 @@ bool ProcessMesh(ModelData& result, OpenFbxImporterData& data, const ofbx::Mesh*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reverse winding order
|
||||||
|
if (data.Options.ReverseWindingOrder)
|
||||||
|
{
|
||||||
|
uint32* meshIndices = mesh.Indices.Get();
|
||||||
|
Float3* meshPositions = mesh.Positions.Get();
|
||||||
|
Float3* meshNormals = mesh.Normals.HasItems() ? mesh.Normals.Get() : nullptr;
|
||||||
|
Float3* meshTangents = mesh.Tangents.HasItems() ? mesh.Tangents.Get() : nullptr;
|
||||||
|
|
||||||
|
for (int i = 0; i < vertexCount; i += 3) {
|
||||||
|
Swap(meshIndices[i + 1], meshIndices[i + 2]);
|
||||||
|
Swap(meshPositions[i + 1], meshPositions[i + 2]);
|
||||||
|
if (meshNormals)
|
||||||
|
Swap(meshNormals[i + 1], meshNormals[i + 2]);
|
||||||
|
if (meshTangents)
|
||||||
|
Swap(meshTangents[i + 1], meshTangents[i + 2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Lightmap UVs
|
// Lightmap UVs
|
||||||
if (data.Options.LightmapUVsSource == ModelLightmapUVsSource::Disable)
|
if (data.Options.LightmapUVsSource == ModelLightmapUVsSource::Disable)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -667,6 +667,7 @@ void ModelTool::Options::Serialize(SerializeStream& stream, const void* otherObj
|
|||||||
SERIALIZE(FlipNormals);
|
SERIALIZE(FlipNormals);
|
||||||
SERIALIZE(CalculateTangents);
|
SERIALIZE(CalculateTangents);
|
||||||
SERIALIZE(SmoothingTangentsAngle);
|
SERIALIZE(SmoothingTangentsAngle);
|
||||||
|
SERIALIZE(ReverseWindingOrder);
|
||||||
SERIALIZE(OptimizeMeshes);
|
SERIALIZE(OptimizeMeshes);
|
||||||
SERIALIZE(MergeMeshes);
|
SERIALIZE(MergeMeshes);
|
||||||
SERIALIZE(ImportLODs);
|
SERIALIZE(ImportLODs);
|
||||||
@@ -717,6 +718,7 @@ void ModelTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifi
|
|||||||
DESERIALIZE(FlipNormals);
|
DESERIALIZE(FlipNormals);
|
||||||
DESERIALIZE(CalculateTangents);
|
DESERIALIZE(CalculateTangents);
|
||||||
DESERIALIZE(SmoothingTangentsAngle);
|
DESERIALIZE(SmoothingTangentsAngle);
|
||||||
|
DESERIALIZE(ReverseWindingOrder);
|
||||||
DESERIALIZE(OptimizeMeshes);
|
DESERIALIZE(OptimizeMeshes);
|
||||||
DESERIALIZE(MergeMeshes);
|
DESERIALIZE(MergeMeshes);
|
||||||
DESERIALIZE(ImportLODs);
|
DESERIALIZE(ImportLODs);
|
||||||
|
|||||||
@@ -170,6 +170,9 @@ public:
|
|||||||
// Specifies the maximum angle (in degrees) that may be between two vertex tangents before their tangents and bi-tangents are smoothed. The default value is 45.
|
// Specifies the maximum angle (in degrees) that may be between two vertex tangents before their tangents and bi-tangents are smoothed. The default value is 45.
|
||||||
API_FIELD(Attributes="EditorOrder(45), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowSmoothingTangentsAngle)), Limit(0, 45, 0.1f)")
|
API_FIELD(Attributes="EditorOrder(45), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowSmoothingTangentsAngle)), Limit(0, 45, 0.1f)")
|
||||||
float SmoothingTangentsAngle = 45.0f;
|
float SmoothingTangentsAngle = 45.0f;
|
||||||
|
// If checked, the winding order of the vertices will be reversed.
|
||||||
|
API_FIELD(Attributes="EditorOrder(47), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))")
|
||||||
|
bool ReverseWindingOrder = false;
|
||||||
// Enable/disable meshes geometry optimization.
|
// Enable/disable meshes geometry optimization.
|
||||||
API_FIELD(Attributes="EditorOrder(50), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))")
|
API_FIELD(Attributes="EditorOrder(50), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))")
|
||||||
bool OptimizeMeshes = true;
|
bool OptimizeMeshes = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user