mirror of
https://github.com/maxartz15/VertexAnimation.git
synced 2024-12-05 01:30:44 +01:00
Small MeshSimplifier optimalization.
List -> Array. Skip LOD when quality is 1.
This commit is contained in:
parent
bc8aa08193
commit
43049094af
@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Linq;
|
||||
|
||||
namespace TAO.VertexAnimation.Editor
|
||||
{
|
||||
|
@ -11,7 +11,13 @@ namespace TAO.VertexAnimation
|
||||
for (int lm = 0; lm < lodMeshes.Length; lm++)
|
||||
{
|
||||
lodMeshes[lm] = mesh.Copy();
|
||||
lodMeshes[lm] = lodMeshes[lm].Simplify(quality[lm]);
|
||||
|
||||
// Only simplify when needed.
|
||||
if (quality[lm] < 1.0f)
|
||||
{
|
||||
lodMeshes[lm] = lodMeshes[lm].Simplify(quality[lm]);
|
||||
}
|
||||
|
||||
lodMeshes[lm].name = string.Format("{0}_LOD{1}", lodMeshes[lm].name, lm);
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ namespace TAO.VertexAnimation
|
||||
// UVs (UV0, UV1, ..., UV7)
|
||||
// Other...
|
||||
|
||||
public List<Vector3> vertices = new List<Vector3>(3);
|
||||
public List<Vector3> normals = new List<Vector3>(3);
|
||||
public Vector3[] vertices = new Vector3[3];
|
||||
public Vector3[] normals = new Vector3[3];
|
||||
public Dictionary<int, List<Vector2>> uvs = new Dictionary<int, List<Vector2>>();
|
||||
|
||||
public float Perimeter()
|
||||
@ -46,7 +46,7 @@ namespace TAO.VertexAnimation
|
||||
float distance = Mathf.Infinity;
|
||||
int closestVertex = -1;
|
||||
|
||||
for (int v = 0; v < vertices.Count; v++)
|
||||
for (int v = 0; v < vertices.Length; v++)
|
||||
{
|
||||
if (vertices[v] != vertex)
|
||||
{
|
||||
@ -83,7 +83,7 @@ namespace TAO.VertexAnimation
|
||||
if (sourceTriangle != this)
|
||||
{
|
||||
Vector3 sourceVertex = sourceTriangle.vertices[sourceVertexIndex];
|
||||
int index = vertices.IndexOf(sourceVertex);
|
||||
int index = System.Array.IndexOf(vertices, sourceVertex);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
@ -156,9 +156,9 @@ namespace TAO.VertexAnimation
|
||||
{
|
||||
List<Triangle> triangles = new List<Triangle>();
|
||||
|
||||
List<Vector3> verts = new List<Vector3>(mesh.vertices);
|
||||
List<Vector3> normals = new List<Vector3>(mesh.normals);
|
||||
List<int> tris = new List<int>(mesh.triangles);
|
||||
Vector3[] verts = mesh.vertices;
|
||||
Vector3[] normals = mesh.normals;
|
||||
int[] tris = mesh.triangles;
|
||||
|
||||
Dictionary<int, List<Vector2>> uvs = new Dictionary<int, List<Vector2>>();
|
||||
for (int u = 0; u < 8; u++)
|
||||
@ -172,17 +172,17 @@ namespace TAO.VertexAnimation
|
||||
}
|
||||
}
|
||||
|
||||
for (int t = 0; t < tris.Count; t += 3)
|
||||
for (int t = 0; t < tris.Length; t += 3)
|
||||
{
|
||||
Triangle tri = new Triangle();
|
||||
|
||||
tri.vertices.Add(verts[tris[t + 0]]);
|
||||
tri.vertices.Add(verts[tris[t + 1]]);
|
||||
tri.vertices.Add(verts[tris[t + 2]]);
|
||||
tri.vertices[0] = verts[tris[t + 0]];
|
||||
tri.vertices[1] = verts[tris[t + 1]];
|
||||
tri.vertices[2] = verts[tris[t + 2]];
|
||||
|
||||
tri.normals.Add(normals[tris[t + 0]]);
|
||||
tri.normals.Add(normals[tris[t + 1]]);
|
||||
tri.normals.Add(normals[tris[t + 2]]);
|
||||
tri.normals[0] = normals[tris[t + 0]];
|
||||
tri.normals[1] = normals[tris[t + 1]];
|
||||
tri.normals[2] = normals[tris[t + 2]];
|
||||
|
||||
foreach (var uv in uvs)
|
||||
{
|
||||
@ -215,14 +215,14 @@ namespace TAO.VertexAnimation
|
||||
mesh.Clear();
|
||||
|
||||
List<Vector3> vertices = new List<Vector3>(triangles.Count * 3);
|
||||
List<int> tris = new List<int>(triangles.Count * 3);
|
||||
List<Vector3> normals = new List<Vector3>(triangles.Count * 3);
|
||||
List<int> tris = new List<int>(triangles.Count * 3);
|
||||
Dictionary<int, List<Vector2>> uvs = new Dictionary<int, List<Vector2>>();
|
||||
|
||||
int skipped = 0;
|
||||
for (int t = 0; t < triangles.Count; t++)
|
||||
{
|
||||
for (int v = 0; v < triangles[t].vertices.Count; v++)
|
||||
for (int v = 0; v < triangles[t].vertices.Length; v++)
|
||||
{
|
||||
// Check for existing matching vert.
|
||||
int vIndex = vertices.IndexOf(triangles[t].vertices[v]);
|
||||
|
Loading…
Reference in New Issue
Block a user