chore: GeodesicMesh use enum instead of string

master
hoba 10 months ago
parent c2607a257a
commit 8c799bb3c2
  1. 74
      Assets/UltraCombos.Metamesh/Editor/GeodesicMesh.cs

@ -1,10 +1,17 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
namespace Metamesh namespace Metamesh
{ {
public enum Rotation
{
Unknown,
A,
B,
O,
}
public class PrimaryIsoTriangle public class PrimaryIsoTriangle
{ {
private int m; private int m;
@ -104,7 +111,7 @@ namespace Metamesh
n1 = n / g; n1 = n / g;
int fr; //face to the right of current face int fr; //face to the right of current face
string rot; //rotation about which vertex for fr Rotation rot; //rotation about which vertex for fr
int O; int O;
int A; int A;
int B; int B;
@ -153,28 +160,28 @@ namespace Metamesh
} }
this.IDATA.edgematch = new List<(int, string, int, string)> this.IDATA.edgematch = new List<(int, Rotation, int, Rotation)>
{ {
(1, "B", 0, ""), (1, Rotation.B, 0, Rotation.Unknown),
(2, "B", 0, ""), (2, Rotation.B, 0, Rotation.Unknown),
(3, "B", 0, ""), (3, Rotation.B, 0, Rotation.Unknown),
(4, "B", 0, ""), (4, Rotation.B, 0, Rotation.Unknown),
(0, "B", 0, ""), (0, Rotation.B, 0, Rotation.Unknown),
(10, "O", 14, "A"), (10, Rotation.O, 14, Rotation.A),
(11, "O", 10, "A"), (11, Rotation.O, 10, Rotation.A),
(12, "O", 11, "A"), (12, Rotation.O, 11, Rotation.A),
(13, "O", 12, "A"), (13, Rotation.O, 12, Rotation.A),
(14, "O", 13, "A"), (14, Rotation.O, 13, Rotation.A),
(0, "O", 0, ""), (0, Rotation.O, 0, Rotation.Unknown),
(1, "O", 0, ""), (1, Rotation.O, 0, Rotation.Unknown),
(2, "O", 0, ""), (2, Rotation.O, 0, Rotation.Unknown),
(3, "O", 0, ""), (3, Rotation.O, 0, Rotation.Unknown),
(4, "O", 0, ""), (4, Rotation.O, 0, Rotation.Unknown),
(19, "B", 5, "A"), (19, Rotation.B, 5, Rotation.A),
(15, "B", 6, "A"), (15, Rotation.B, 6, Rotation.A),
(16, "B", 7, "A"), (16, Rotation.B, 7, Rotation.A),
(17, "B", 8, "A"), (17, Rotation.B, 8, Rotation.A),
(18, "B", 9, "A"), (18, Rotation.B, 9, Rotation.A),
}; };
/***edges AB to OB***** rotation about B*/ /***edges AB to OB***** rotation about B*/
@ -214,7 +221,7 @@ namespace Metamesh
//for edge vertices //for edge vertices
fr = this.IDATA.edgematch[f].Item1; fr = this.IDATA.edgematch[f].Item1;
rot = this.IDATA.edgematch[f].Item2; rot = this.IDATA.edgematch[f].Item2;
if (rot == "B") if (rot == Rotation.B)
{ {
for (var i = 1; i < g; i++) for (var i = 1; i < g; i++)
{ {
@ -228,7 +235,7 @@ namespace Metamesh
} }
} }
if (rot == "O") if (rot == Rotation.O)
{ {
for (var i = 1; i < g; i++) for (var i = 1; i < g; i++)
{ {
@ -244,7 +251,7 @@ namespace Metamesh
fr = this.IDATA.edgematch[f].Item3; fr = this.IDATA.edgematch[f].Item3;
rot = this.IDATA.edgematch[f].Item4; rot = this.IDATA.edgematch[f].Item4;
if (rot == "A") if (rot == Rotation.A)
{ {
for (var i = 1; i < g; i++) for (var i = 1; i < g; i++)
{ {
@ -625,7 +632,7 @@ namespace Metamesh
public string category; public string category;
public Dictionary<int, Vector3> vertex; public Dictionary<int, Vector3> vertex;
public List<List<int>> face; public List<List<int>> face;
public List<(int, string, int, string)> edgematch; public List<(int, Rotation, int, Rotation)> edgematch;
public PolyhedronData( public PolyhedronData(
string name, string name,
@ -754,7 +761,7 @@ namespace Metamesh
nearTo[12].Add(new List<int> { i, close[i][0] }); nearTo[12].Add(new List<int> { i, close[i][0] });
} }
} }
var near = Enumerable.Range(0, 12).ToDictionary(i => i); var near = Enumerable.Range(0, 12).ToDictionary(i => i);
var nearIndex = 12; var nearIndex = 12;
for (var i = 0; i < 12; i++) for (var i = 0; i < 12; i++)
@ -857,7 +864,8 @@ namespace Metamesh
if (goldbergPolyhedronData.face.Count <= m) if (goldbergPolyhedronData.face.Count <= m)
{ {
if (goldbergPolyhedronData.face.Count != m) if (goldbergPolyhedronData.face.Count != m)
Debug.LogWarning($"goldbergPolyhedronData.face.Count != m: {goldbergPolyhedronData.face.Count} != {m}"); Debug.LogWarning(
$"goldbergPolyhedronData.face.Count != m: {goldbergPolyhedronData.face.Count} != {m}");
goldbergPolyhedronData.face.Add(tempFace); goldbergPolyhedronData.face.Add(tempFace);
} }
else else
@ -921,17 +929,17 @@ namespace Metamesh
{ {
primTri.MapToFace(f, geodesicData); primTri.MapToFace(f, geodesicData);
geodesicData.InnerToData(f, primTri); geodesicData.InnerToData(f, primTri);
if (primTri.IDATA.edgematch[f].Item2 == "B") if (primTri.IDATA.edgematch[f].Item2 == Rotation.B)
{ {
geodesicData.MapABOBtoDATA(f, primTri); geodesicData.MapABOBtoDATA(f, primTri);
} }
if (primTri.IDATA.edgematch[f].Item2 == "O") if (primTri.IDATA.edgematch[f].Item2 == Rotation.O)
{ {
geodesicData.MapOBOAtoDATA(f, primTri); geodesicData.MapOBOAtoDATA(f, primTri);
} }
if (primTri.IDATA.edgematch[f].Item4 == "A") if (primTri.IDATA.edgematch[f].Item4 == Rotation.A)
{ {
geodesicData.MapBAOAtoDATA(f, primTri); geodesicData.MapBAOAtoDATA(f, primTri);
} }