diff --git a/Assets/Scripts/Editor/GeodesicMesh.cs b/Assets/Scripts/Editor/GeodesicMesh.cs index f165cd4..d71a160 100644 --- a/Assets/Scripts/Editor/GeodesicMesh.cs +++ b/Assets/Scripts/Editor/GeodesicMesh.cs @@ -303,8 +303,8 @@ namespace Metamesh this.coau = (m + n) / LSQD; this.cobu = -n / LSQD; - this.coav = (-thirdR3 * (m - n)) / LSQD; - this.cobv = (thirdR3 * (2 * m + n)) / LSQD; + this.coav = -thirdR3 * (m - n) / LSQD; + this.cobv = thirdR3 * (2 * m + n) / LSQD; } public void CreateInnerFacets() @@ -392,14 +392,15 @@ namespace Metamesh public void MapABOBtoOBOA() { - var point = new Vector2Int(0, 0); + //var point = new Vector2Int(0, 0); for (var i = 0; i < this.isoVecsABOB.Count; i++) { var temp = new List(); for (var j = 0; j < 3; j++) { - point.x = this.isoVecsABOB[i][j].x; - point.y = this.isoVecsABOB[i][j].y; + //point.x = this.isoVecsABOB[i][j].x; + //point.y = this.isoVecsABOB[i][j].y; + var point = this.isoVecsABOB[i][j]; if (this.vertexTypes[i][j] == 0) { point = point.RotateNeg120(this.m, this.n); @@ -414,14 +415,15 @@ namespace Metamesh public void MapABOBtoBAOA() { - var point = new Vector2Int(0, 0); + //var point = new Vector2Int(0, 0); for (var i = 0; i < this.isoVecsABOB.Count; i++) { var temp = new List(); for (var j = 0; j < 3; j++) { - point.x = this.isoVecsABOB[i][j].x; - point.y = this.isoVecsABOB[i][j].y; + //point.x = this.isoVecsABOB[i][j].x; + //point.y = this.isoVecsABOB[i][j].y; + var point = this.isoVecsABOB[i][j]; if (this.vertexTypes[i][j] == 1) { point = point.Rotate120(this.m, this.n); @@ -514,9 +516,9 @@ namespace Metamesh } //order vertices by x and then y - vertices.Sort((a, b) => { return a.x - b.x; }); + vertices.Sort((a, b) => { return a.x.CompareTo(b.x); }); - vertices.Sort((a, b) => { return a.y - b.y; }); + vertices.Sort((a, b) => { return a.y.CompareTo(b.y); }); var min = Enumerable.Repeat(int.MaxValue, m + n + 1).ToList(); var max = Enumerable.Repeat(int.MinValue, m + n + 1).ToList(); @@ -566,7 +568,7 @@ namespace Metamesh var dist = -1; for (var i = 0; i < len; i++) { - cartesian[i] = vertices[i].ToCartesianOrigin(new Vector2Int(0, 0), 0.5f); + cartesian[i] = vertices[i].ToCartesianOrigin(Vector2Int.zero, 0.5f); distFromO[i] = DistFrom(vertices[i], "O"); distFromA[i] = DistFrom(vertices[i], "A"); distFromB[i] = DistFrom(vertices[i], "B"); @@ -779,7 +781,7 @@ namespace Metamesh var nearIndex = 12; for (var i = 0; i < 12; i++) { - nearTo[i].Sort((a, b) => { return a[1] - b[1]; }); + nearTo[i].Sort((a, b) => { return a[1].CompareTo(b[1]); }); foreach (var item in nearTo[i]) { @@ -876,6 +878,8 @@ namespace Metamesh var tempFace = this.SetOrder(m, new List(map[m])); if (goldbergPolyhedronData.face.Count <= m) { + if (goldbergPolyhedronData.face.Count != m) + Debug.Log($"goldbergPolyhedronData.face.Count != m: {goldbergPolyhedronData.face.Count} != {m}"); goldbergPolyhedronData.face.Add(tempFace); } else @@ -900,6 +904,8 @@ namespace Metamesh var tempVertex = new Vector3(cx / 3, cy / 3, cz / 3); if (goldbergPolyhedronData.vertex.Count <= el) { + if (goldbergPolyhedronData.face.Count != el) + Debug.Log($"goldbergPolyhedronData.face.Count != el: {goldbergPolyhedronData.face.Count} != {el}"); goldbergPolyhedronData.vertex.Add(tempVertex); } else @@ -969,14 +975,14 @@ namespace Metamesh var radius = 1f; geodesicData.vertex = geodesicData.vertex.Select((el) => { - var a = el[0]; - var b = el[1]; - var c = el[2]; + var a = el.x; + var b = el.y; + var c = el.z; var d = Mathf.Sqrt(a * a + b * b + c * c); - el[0] *= radius / d; - el[1] *= radius / d; - el[2] *= radius / d; - return el; + //el[0] *= radius / d; + //el[1] *= radius / d; + //el[2] *= radius / d; + return el * radius / d; }).ToList(); return geodesicData; diff --git a/Assets/Scripts/Editor/GoldbergBuilder.cs b/Assets/Scripts/Editor/GoldbergBuilder.cs index fba7930..432c041 100644 --- a/Assets/Scripts/Editor/GoldbergBuilder.cs +++ b/Assets/Scripts/Editor/GoldbergBuilder.cs @@ -28,7 +28,7 @@ namespace Metamesh public List uvs; } - private VertexData CreateGoldbergVertexData(GoldbergVertexDataOption options, PolyhedronData goldbergData) + private static VertexData CreateGoldbergVertexData(GoldbergVertexDataOption options, PolyhedronData goldbergData) { var size = options.size; var sizeX = options.sizeX;// || size || 1; @@ -92,7 +92,7 @@ namespace Metamesh }; } - public VertexData CreateGoldberg(GoldbergCreationOption options) + public static VertexData CreateGoldberg(GoldbergCreationOption options) { var size = options.size; var sizeX = options.sizeX;// || size || 1; diff --git a/Assets/Scripts/Editor/GoldbergPolyhedronImporter.cs b/Assets/Scripts/Editor/GoldbergPolyhedronImporter.cs index b53c9af..c10abee 100644 --- a/Assets/Scripts/Editor/GoldbergPolyhedronImporter.cs +++ b/Assets/Scripts/Editor/GoldbergPolyhedronImporter.cs @@ -4,7 +4,6 @@ using UnityEditor; using UnityEditor.AssetImporters; using UnityEngine; using UnityEngine.Rendering; -using static Metamesh.GoldbergBuilder; namespace Metamesh { @@ -12,7 +11,6 @@ namespace Metamesh public class GoldbergPolyhedronImporter : ScriptedImporter { [SerializeField] float radius = 1; - [SerializeField, Min(2)] uint subdivision = 2; [SerializeField, Min(1)] int m = 1; [SerializeField, Min(0)] int n = 0; @@ -49,13 +47,13 @@ namespace Metamesh name = "Mesh" }; - var builder = new GoldbergBuilder(); - var options = new GoldbergCreationOption() + var options = new GoldbergBuilder.GoldbergCreationOption() { + size = radius, m = m, n = n, }; - var data = builder.CreateGoldberg(options); + var data = GoldbergBuilder.CreateGoldberg(options); var vertices = data.vertices; var normals = data.normals; var indices = data.indices;