Improve mesh loading

This commit is contained in:
VaDiM
2025-08-27 05:25:01 +03:00
parent ae3b5169df
commit 963cd6546b
10 changed files with 104 additions and 28 deletions

View File

@ -175,15 +175,17 @@ namespace AssetStudioCLI
private static bool ExportMesh(AssetItem item, string exportPath)
{
var m_Mesh = (Mesh)item.Asset;
m_Mesh.ProcessData();
if (m_Mesh.m_VertexCount <= 0)
return false;
if (!TryExportFile(exportPath, item, ".obj", out var exportFullPath))
return false;
var sb = new StringBuilder();
sb.AppendLine("g " + m_Mesh.m_Name);
#region Vertices
if (m_Mesh.m_Vertices == null || m_Mesh.m_Vertices.Length == 0)
{
return false;
@ -199,11 +201,9 @@ namespace AssetStudioCLI
{
sb.Append($"v {-m_Mesh.m_Vertices[v * c]} {m_Mesh.m_Vertices[v * c + 1]} {m_Mesh.m_Vertices[v * c + 2]}\r\n");
}
#endregion
#region UV
if (m_Mesh.m_UV0?.Length > 0)
{
c = 4;
@ -221,11 +221,9 @@ namespace AssetStudioCLI
sb.AppendFormat("vt {0} {1}\r\n", m_Mesh.m_UV0[v * c], m_Mesh.m_UV0[v * c + 1]);
}
}
#endregion
#region Normals
if (m_Mesh.m_Normals?.Length > 0)
{
if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 3)
@ -242,11 +240,9 @@ namespace AssetStudioCLI
sb.AppendFormat("vn {0} {1} {2}\r\n", -m_Mesh.m_Normals[v * c], m_Mesh.m_Normals[v * c + 1], m_Mesh.m_Normals[v * c + 2]);
}
}
#endregion
#region Face
int sum = 0;
for (var i = 0; i < m_Mesh.m_SubMeshes.Count; i++)
{
@ -260,7 +256,6 @@ namespace AssetStudioCLI
sum = end;
}
#endregion
sb.Replace("NaN", "0");