mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
Reduce allocations in MeshOutlineGenerator
This commit is contained in:
parent
fc533cc23d
commit
040bf59b94
@ -212,7 +212,13 @@ csharp_style_prefer_extended_property_pattern = true:suggestion
|
||||
csharp_style_prefer_top_level_statements = false:silent
|
||||
dotnet_diagnostic.CA1309.severity = error
|
||||
dotnet_diagnostic.CA1311.severity = suggestion
|
||||
dotnet_diagnostic.SYSLIB1054.severity = warning
|
||||
dotnet_diagnostic.SYSLIB1054.severity = warning
|
||||
csharp_style_prefer_primary_constructors = false:silent
|
||||
csharp_style_prefer_utf8_string_literals = true:suggestion
|
||||
csharp_style_prefer_readonly_struct = true:suggestion
|
||||
csharp_style_prefer_readonly_struct_member = true:suggestion
|
||||
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
|
||||
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
|
||||
|
||||
[*.{cs,vb}]
|
||||
dotnet_style_coalesce_expression = true:suggestion
|
||||
@ -248,4 +254,5 @@ dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
|
||||
dotnet_style_qualification_for_field = false:silent
|
||||
dotnet_style_qualification_for_property = false:silent
|
||||
dotnet_style_qualification_for_method = false:silent
|
||||
dotnet_style_qualification_for_event = false:silent
|
||||
dotnet_style_qualification_for_event = false:silent
|
||||
dotnet_style_prefer_collection_expression = true:suggestion
|
||||
@ -4,6 +4,11 @@ namespace AssetRipper.Numerics
|
||||
{
|
||||
public static class VectorExtensions
|
||||
{
|
||||
public static Vector2 AsVector2(this Vector3 vector3)
|
||||
{
|
||||
return Unsafe.As<Vector3, Vector2>(ref vector3);
|
||||
}
|
||||
|
||||
public static Vector3 AsVector3(this Vector2 vector2)
|
||||
{
|
||||
return new Vector3(vector2, 0);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using AssetRipper.Assets.Bundles;
|
||||
using AssetRipper.Assets.Collections;
|
||||
using AssetRipper.Assets.Collections;
|
||||
using AssetRipper.SourceGenerated.Classes.ClassID_28;
|
||||
|
||||
namespace AssetRipper.Processing.Textures;
|
||||
|
||||
@ -107,9 +107,7 @@ namespace AssetRipper.Processing.Textures
|
||||
m_RD.SecondaryTextures.Clear();
|
||||
foreach (SecondarySpriteTexture spt in spriteData.SecondaryTextures)
|
||||
{
|
||||
SecondarySpriteTexture newSpt = m_RD.SecondaryTextures.AddNew();
|
||||
newSpt.Name = spt.Name;
|
||||
newSpt.Texture.CopyValues(spt.Texture, converter);
|
||||
m_RD.SecondaryTextures.AddNew().CopyValues(spt, converter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,24 +5,9 @@ namespace AssetRipper.SourceGenerated.Extensions
|
||||
{
|
||||
public sealed class MeshOutlineGenerator
|
||||
{
|
||||
private sealed class Outline
|
||||
private readonly struct Outline
|
||||
{
|
||||
private readonly struct Outside
|
||||
{
|
||||
public Outside(int triIndex, int vertex)
|
||||
{
|
||||
Triangle = triIndex;
|
||||
Member = vertex;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Triangle}:{Member}";
|
||||
}
|
||||
|
||||
public int Triangle { get; }
|
||||
public int Member { get; }
|
||||
}
|
||||
private readonly record struct Outside(int Triangle, int Member);
|
||||
|
||||
public Outline(IReadOnlyList<Vector3i> triangles, int startTriangle)
|
||||
{
|
||||
@ -34,14 +19,14 @@ namespace AssetRipper.SourceGenerated.Extensions
|
||||
|
||||
public void GenerateOutline()
|
||||
{
|
||||
List<int> outline = new();
|
||||
m_outline.Clear();
|
||||
Outside outsider = m_outsiders[0];
|
||||
Vector3i tri = m_triangles[outsider.Triangle];
|
||||
int first = tri.GetValueByMember(outsider.Member);
|
||||
int second = tri.GetValueByMember(outsider.Member + 1);
|
||||
int startTriIndex = outsider.Triangle;
|
||||
outline.Add(first);
|
||||
outline.Add(second);
|
||||
m_outline.Add(first);
|
||||
m_outline.Add(second);
|
||||
|
||||
Vector3i lastTri = tri;
|
||||
int lastMember = outsider.Member + 1;
|
||||
@ -74,10 +59,8 @@ namespace AssetRipper.SourceGenerated.Extensions
|
||||
break;
|
||||
}
|
||||
|
||||
outline.Add(nextVertex);
|
||||
m_outline.Add(nextVertex);
|
||||
}
|
||||
|
||||
GeneratedOutline = outline;
|
||||
}
|
||||
|
||||
public bool IsContain(int triIndex)
|
||||
@ -291,23 +274,18 @@ namespace AssetRipper.SourceGenerated.Extensions
|
||||
}
|
||||
|
||||
public int TriangleCount => m_indexes.Count;
|
||||
public IReadOnlyList<int> GeneratedOutline { get; private set; } = Array.Empty<int>();
|
||||
public IReadOnlyList<int> GeneratedOutline => m_outline;
|
||||
|
||||
private readonly IReadOnlyList<Vector3i> m_triangles;
|
||||
private readonly HashSet<int> m_indexes = new();
|
||||
private readonly List<int> m_outline = new();
|
||||
private readonly List<Outside> m_outsiders = new();
|
||||
}
|
||||
|
||||
public MeshOutlineGenerator(IReadOnlyList<Vector3> vertices, IReadOnlyList<Vector3i> triangles)
|
||||
{
|
||||
if (vertices == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(vertices));
|
||||
}
|
||||
if (triangles == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(triangles));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(vertices);
|
||||
ArgumentNullException.ThrowIfNull(triangles);
|
||||
m_vertices = vertices;
|
||||
foreach (Vector3i triangle in triangles)
|
||||
{
|
||||
@ -320,7 +298,7 @@ namespace AssetRipper.SourceGenerated.Extensions
|
||||
|
||||
public List<Vector2[]> GenerateOutlines()
|
||||
{
|
||||
List<Outline> outlines = new List<Outline>();
|
||||
List<Outline> outlines = new();
|
||||
for (int i = 0; i < m_triangles.Count; i++)
|
||||
{
|
||||
bool isKnown = false;
|
||||
@ -362,17 +340,17 @@ namespace AssetRipper.SourceGenerated.Extensions
|
||||
for (int l = index; l < nextOutline.GeneratedOutline.Count; l++)
|
||||
{
|
||||
int nextVertex = nextOutline.GeneratedOutline[l];
|
||||
resultLine.Add((Vector2f)m_vertices[nextVertex]);
|
||||
resultLine.Add(m_vertices[nextVertex].AsVector2());
|
||||
}
|
||||
for (int m = 0; m < index; m++)
|
||||
{
|
||||
int nextVertex = nextOutline.GeneratedOutline[m];
|
||||
resultLine.Add((Vector2f)m_vertices[nextVertex]);
|
||||
resultLine.Add(m_vertices[nextVertex].AsVector2());
|
||||
}
|
||||
outlines.RemoveAt(k--);
|
||||
}
|
||||
}*/
|
||||
resultLine.Add(ConvertToVector2f(m_vertices[vertex]));
|
||||
resultLine.Add(m_vertices[vertex].AsVector2());
|
||||
}
|
||||
result.Add(resultLine.ToArray());
|
||||
}
|
||||
@ -380,14 +358,12 @@ namespace AssetRipper.SourceGenerated.Extensions
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Vector2 ConvertToVector2f(Vector3 v3) => new Vector2(v3.X, v3.Y);
|
||||
|
||||
private static bool IsValidTriangle(Vector3i triangle)
|
||||
{
|
||||
return triangle.X != triangle.Y && triangle.X != triangle.Z && triangle.Y != triangle.Z;
|
||||
}
|
||||
|
||||
private readonly IReadOnlyList<Vector3> m_vertices;
|
||||
private readonly List<Vector3i> m_triangles = new List<Vector3i>();
|
||||
private readonly List<Vector3i> m_triangles = new();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user