Added import option to reverse winding order
This commit is contained in:
@@ -765,6 +765,10 @@ bool ModelTool::ImportDataAssimp(const String& path, ModelData& data, Options& o
|
||||
flags |= aiProcess_FixInfacingNormals | aiProcess_GenSmoothNormals;
|
||||
if (options.CalculateTangents)
|
||||
flags |= aiProcess_CalcTangentSpace;
|
||||
if (options.ReverseWindingOrder)
|
||||
// actually we need to remove this flag
|
||||
// flags |= aiProcess_FlipWindingOrder;
|
||||
flags &= ~aiProcess_FlipWindingOrder;
|
||||
if (options.OptimizeMeshes)
|
||||
flags |= aiProcess_OptimizeMeshes | aiProcess_SplitLargeMeshes | aiProcess_ImproveCacheLocality;
|
||||
if (options.MergeMeshes)
|
||||
|
||||
@@ -385,6 +385,19 @@ bool ProcessMesh(ImporterData& data, FbxMesh* fbxMesh, MeshData& mesh, String& e
|
||||
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
|
||||
FbxGeometryElementUV* texcoords = fbxMesh->GetElementUV(0);
|
||||
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
|
||||
if (data.Options.LightmapUVsSource == ModelLightmapUVsSource::Disable)
|
||||
{
|
||||
|
||||
@@ -667,6 +667,7 @@ void ModelTool::Options::Serialize(SerializeStream& stream, const void* otherObj
|
||||
SERIALIZE(FlipNormals);
|
||||
SERIALIZE(CalculateTangents);
|
||||
SERIALIZE(SmoothingTangentsAngle);
|
||||
SERIALIZE(ReverseWindingOrder);
|
||||
SERIALIZE(OptimizeMeshes);
|
||||
SERIALIZE(MergeMeshes);
|
||||
SERIALIZE(ImportLODs);
|
||||
@@ -717,6 +718,7 @@ void ModelTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifi
|
||||
DESERIALIZE(FlipNormals);
|
||||
DESERIALIZE(CalculateTangents);
|
||||
DESERIALIZE(SmoothingTangentsAngle);
|
||||
DESERIALIZE(ReverseWindingOrder);
|
||||
DESERIALIZE(OptimizeMeshes);
|
||||
DESERIALIZE(MergeMeshes);
|
||||
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.
|
||||
API_FIELD(Attributes="EditorOrder(45), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowSmoothingTangentsAngle)), Limit(0, 45, 0.1f)")
|
||||
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.
|
||||
API_FIELD(Attributes="EditorOrder(50), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))")
|
||||
bool OptimizeMeshes = true;
|
||||
|
||||
Reference in New Issue
Block a user