feat: add new Metamesh features and refactor code structure

master
hoba 10 months ago
parent 4d9a9bb733
commit 2fd67b7b29
  1. 12
      Assets/Main.unity
  2. 5
      Assets/Resources/New GoldbergPolyhedron.gph.meta
  3. 4
      Assets/Resources/New Material.mat
  4. 1
      Assets/Scripts/.keep
  5. 67
      Assets/Scripts/Editor/IsoVector.cs
  6. 2
      Assets/Scripts/Editor/IsoVector.cs.meta
  7. 8
      Assets/UltraCombos.Metamesh.meta
  8. 2
      Assets/UltraCombos.Metamesh/Editor.meta
  9. 123
      Assets/UltraCombos.Metamesh/Editor/GeodesicMesh.cs
  10. 0
      Assets/UltraCombos.Metamesh/Editor/GeodesicMesh.cs.meta
  11. 0
      Assets/UltraCombos.Metamesh/Editor/GoldbergBuilder.cs
  12. 0
      Assets/UltraCombos.Metamesh/Editor/GoldbergBuilder.cs.meta
  13. 2
      Assets/UltraCombos.Metamesh/Editor/GoldbergPolyhedronImporter.cs
  14. 0
      Assets/UltraCombos.Metamesh/Editor/GoldbergPolyhedronImporter.cs.meta
  15. 18
      Assets/UltraCombos.Metamesh/Editor/UltraCombos.Metamesh.Editor.asmdef
  16. 7
      Assets/UltraCombos.Metamesh/Editor/UltraCombos.Metamesh.Editor.asmdef.meta
  17. 8
      Assets/UltraCombos.Metamesh/Runtime.meta
  18. 0
      Assets/UltraCombos.Metamesh/Runtime/Extensions.cs
  19. 0
      Assets/UltraCombos.Metamesh/Runtime/Extensions.cs.meta
  20. 14
      Assets/UltraCombos.Metamesh/Runtime/UltraCombos.Metamesh.Runtime.asmdef
  21. 7
      Assets/UltraCombos.Metamesh/Runtime/UltraCombos.Metamesh.Runtime.asmdef.meta

@ -171,6 +171,10 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: New Metamesh value: New Metamesh
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8980549144392899874, guid: f5e4c28eb4672d24ca584d5456a268e7, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []
@ -1029,15 +1033,15 @@ PrefabInstance:
m_Modifications: m_Modifications:
- target: {fileID: -364223573239433514, guid: 666014e54879dc1479f1c29bea163dd4, type: 3} - target: {fileID: -364223573239433514, guid: 666014e54879dc1479f1c29bea163dd4, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: 0.5482712 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 666014e54879dc1479f1c29bea163dd4, type: 3} - target: {fileID: -364223573239433514, guid: 666014e54879dc1479f1c29bea163dd4, type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: 2.7895133 value: 2.5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 666014e54879dc1479f1c29bea163dd4, type: 3} - target: {fileID: -364223573239433514, guid: 666014e54879dc1479f1c29bea163dd4, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 0.8493496 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -364223573239433514, guid: 666014e54879dc1479f1c29bea163dd4, type: 3} - target: {fileID: -364223573239433514, guid: 666014e54879dc1479f1c29bea163dd4, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
@ -2112,7 +2116,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 2147483647 m_StaticEditorFlags: 2147483647
m_IsActive: 1 m_IsActive: 0
--- !u!23 &7499497021674395898 --- !u!23 &7499497021674395898
MeshRenderer: MeshRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

@ -9,8 +9,7 @@ ScriptedImporter:
assetBundleVariant: assetBundleVariant:
script: {fileID: 11500000, guid: 80f1e0e8eacc4a945b07bba9e3065c99, type: 3} script: {fileID: 11500000, guid: 80f1e0e8eacc4a945b07bba9e3065c99, type: 3}
radius: 1 radius: 1
subdivision: 4 m: 16
m: 1 n: 1
n: 0
generateLightmapUVs: 0 generateLightmapUVs: 0
readWriteMeshes: 0 readWriteMeshes: 0

@ -114,12 +114,12 @@ Material:
- _GlossMapScale: 0 - _GlossMapScale: 0
- _Glossiness: 0 - _Glossiness: 0
- _GlossyReflections: 0 - _GlossyReflections: 0
- _Metallic: 0 - _Metallic: 0.923
- _OcclusionStrength: 1 - _OcclusionStrength: 1
- _Parallax: 0.005 - _Parallax: 0.005
- _QueueOffset: 0 - _QueueOffset: 0
- _ReceiveShadows: 1 - _ReceiveShadows: 1
- _Smoothness: 0.5 - _Smoothness: 0.862
- _SmoothnessTextureChannel: 0 - _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1 - _SpecularHighlights: 1
- _SrcBlend: 1 - _SrcBlend: 1

@ -1,67 +0,0 @@
using UnityEngine;
namespace Metamesh
{
public class IsoVector
{
public int x;
public int y;
public IsoVector(int x, int y)
{
this.x = x;
this.y = y;
}
public IsoVector Clone()
{
return new IsoVector(x, y);
}
public IsoVector Rotate60About(IsoVector other)
{
var x = this.x;
this.x = other.x + other.y - this.y;
this.y = x + this.y - other.x;
return this;
}
public IsoVector RotateNeg60About(IsoVector other)
{
var x = this.x;
this.x = x + this.y - other.y;
this.y = other.x + other.y - x;
return this;
}
public IsoVector Rotate120(int m, int n)
{
var x = this.x;
this.x = m - x - this.y;
this.y = n + x;
return this;
}
public IsoVector RotateNeg120(int m, int n)
{
var x = this.x;
this.x = this.y - n;
this.y = m + n - x - this.y;
return this;
}
public Vector3 ToCartesianOrigin(IsoVector origin, float isoGridSize)
{
var point = Vector3.zero;
point.x = origin.x + 2 * this.x * isoGridSize + this.y * isoGridSize;
point.y = origin.y + Mathf.Sqrt(3) * this.y * isoGridSize;
return point;
}
public static IsoVector Zero()
{
return new IsoVector(0, 0);
}
}
}

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 1b57a079742a0234e892f0128b45703f

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2f059aeacfc85304fbbf6dc410c48f4e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 97b79f4815ec35242a5fcedb042271b8 guid: 188d2369623379f41a59c1c727bbd035
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

@ -34,20 +34,20 @@ namespace Metamesh
public PolyhedronData IDATA = new PolyhedronData( public PolyhedronData IDATA = new PolyhedronData(
"icosahedron", "icosahedron",
"Regular", "Regular",
new List<Vector3> new Dictionary<int, Vector3>
{ {
new Vector3(0, PHI, -1), {0,new Vector3(0, PHI, -1)},
new Vector3(-PHI, 1, 0), {1,new Vector3(-PHI, 1, 0)},
new Vector3(-1, 0, -PHI), {2,new Vector3(-1, 0, -PHI)},
new Vector3(1, 0, -PHI), {3,new Vector3(1, 0, -PHI)},
new Vector3(PHI, 1, 0), {4,new Vector3(PHI, 1, 0)},
new Vector3(0, PHI, 1), {5,new Vector3(0, PHI, 1)},
new Vector3(-1, 0, PHI), {6,new Vector3(-1, 0, PHI)},
new Vector3(-PHI, -1, 0), {7,new Vector3(-PHI, -1, 0)},
new Vector3(0, -PHI, -1), {8,new Vector3(0, -PHI, -1)},
new Vector3(PHI, -1, 0), {9,new Vector3(PHI, -1, 0)},
new Vector3(1, 0, PHI), {10,new Vector3(1, 0, PHI)},
new Vector3(0, -PHI, 1), {11,new Vector3(0, -PHI, 1)},
}, },
new List<List<int>> new List<List<int>>
{ {
@ -464,12 +464,10 @@ namespace Metamesh
var tempVec = x * this.cartesian[i].x + y * this.cartesian[i].y + O; var tempVec = x * this.cartesian[i].x + y * this.cartesian[i].y + O;
//mapped[i] = tempVec; //mapped[i] = tempVec;
idx = faceNb + "|" + this.vertices[i].x + "|" + this.vertices[i].y; idx = faceNb + "|" + this.vertices[i].x + "|" + this.vertices[i].y;
while (this.vecToidx[idx] >= geodesicData.vertex.Count)
geodesicData.vertex.Add(Vector3.zero);
geodesicData.vertex[this.vecToidx[idx]] = tempVec; geodesicData.vertex[this.vecToidx[idx]] = tempVec;
} }
} }
public PrimaryIsoTriangle Build(int m, int n) public PrimaryIsoTriangle Build(int m, int n)
{ {
var vertices = new List<Vector2Int>(); var vertices = new List<Vector2Int>();
@ -641,14 +639,14 @@ namespace Metamesh
{ {
public string name; public string name;
public string category; public string category;
public List<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, string, int, string)> edgematch;
public PolyhedronData( public PolyhedronData(
string name, string name,
string category, string category,
List<Vector3> vertex, Dictionary<int, Vector3> vertex,
List<List<int>> face List<List<int>> face
) )
{ {
@ -669,7 +667,7 @@ namespace Metamesh
private GeodesicData( private GeodesicData(
string name, string name,
string category, string category,
List<Vector3> vertex, Dictionary<int, Vector3> vertex,
List<List<int>> face List<List<int>> face
) : base(name, category, vertex, face) ) : base(name, category, vertex, face)
{ {
@ -705,7 +703,7 @@ namespace Metamesh
{ primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]] }); { primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]] });
} }
} }
private void MapOBOAtoDATA(int faceNb, PrimaryIsoTriangle primTri) private void MapOBOAtoDATA(int faceNb, PrimaryIsoTriangle primTri)
{ {
var fr = primTri.IDATA.edgematch[faceNb].Item1; var fr = primTri.IDATA.edgematch[faceNb].Item1;
@ -728,7 +726,7 @@ namespace Metamesh
{ primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]] }); { primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]] });
} }
} }
private void MapBAOAtoDATA(int faceNb, PrimaryIsoTriangle primTri) private void MapBAOAtoDATA(int faceNb, PrimaryIsoTriangle primTri)
{ {
var fr = primTri.IDATA.edgematch[faceNb].Item3; var fr = primTri.IDATA.edgematch[faceNb].Item3;
@ -751,7 +749,7 @@ namespace Metamesh
{ primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]] }); { primTri.vecToidx[temp[0]], primTri.vecToidx[temp[1]], primTri.vecToidx[temp[2]] });
} }
} }
private void OrderData(PrimaryIsoTriangle primTri) private void OrderData(PrimaryIsoTriangle primTri)
{ {
var nearTo = new Dictionary<int, List<List<int>>>(); var nearTo = new Dictionary<int, List<List<int>>>();
@ -775,30 +773,42 @@ 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).ToList(); //var near = Enumerable.Range(0, 12).ToList();
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++)
{ {
nearTo[i].Sort((a, b) => { return a[1].CompareTo(b[1]); }); nearTo[i].Sort((a, b) => { return a[1].CompareTo(b[1]); });
foreach (var item in nearTo[i]) foreach (var item in nearTo[i])
{ {
near[item[0]] = nearIndex++; near[item[0]] = nearIndex++;
} }
} }
foreach (var item in nearTo[12]) foreach (var item in nearTo[12])
{ {
near[item[0]] = nearIndex++; near[item[0]] = nearIndex++;
} }
// TODO
/*
this.vertex = this.vertex this.vertex = this.vertex
.Select((v, i) => (Vertex: v, SortKey: near[i])) .Select((v, i) => (Vertex: v, SortKey: near[i]))
.OrderBy(x => x.SortKey) .OrderBy(x => x.SortKey)
.Select(x => x.Vertex) .Select(x => x.Vertex)
.ToList(); .ToList();
*/
var values = this.vertex.Values
.Select((v, i) => (Vertex: v, SortKey: near[i]))
.OrderBy(x => x.SortKey)
.Select(x => x.Vertex)
.ToArray();
var keys = this.vertex.Keys.ToArray();
for (int i = 0; i < keys.Length; ++i)
{
this.vertex[keys[i]] = values[i];
}
for (var i = 0; i < this.face.Count; i++) for (var i = 0; i < this.face.Count; i++)
{ {
@ -850,7 +860,7 @@ namespace Metamesh
public PolyhedronData ToGoldbergPolyhedronData() public PolyhedronData ToGoldbergPolyhedronData()
{ {
var goldbergPolyhedronData = var goldbergPolyhedronData =
new PolyhedronData("GeoDual", "Goldberg", new List<Vector3>(), new List<List<int>>()); new PolyhedronData("GeoDual", "Goldberg", new Dictionary<int, Vector3>(), new List<List<int>>());
goldbergPolyhedronData.name = "GD dual"; goldbergPolyhedronData.name = "GD dual";
var verticesNb = this.vertex.Count; var verticesNb = this.vertex.Count;
var map = new List<int>[verticesNb]; var map = new List<int>[verticesNb];
@ -901,17 +911,7 @@ namespace Metamesh
cz += vertex.z; cz += vertex.z;
} }
var tempVertex = new Vector3(cx / 3, cy / 3, cz / 3); goldbergPolyhedronData.vertex[el] = 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
{
goldbergPolyhedronData.vertex[el] = tempVertex;
}
} }
; ;
@ -926,20 +926,20 @@ namespace Metamesh
var geodesicData = new GeodesicData( var geodesicData = new GeodesicData(
"Geodesic-m-n", "Geodesic-m-n",
"Geodesic", "Geodesic",
new List<Vector3>() new Dictionary<int, Vector3>()
{ {
new Vector3(0, PHI, -1), {0, new Vector3(0, PHI, -1)},
new Vector3(-PHI, 1, 0), {1,new Vector3(-PHI, 1, 0)},
new Vector3(-1, 0, -PHI), {2,new Vector3(-1, 0, -PHI)},
new Vector3(1, 0, -PHI), {3,new Vector3(1, 0, -PHI)},
new Vector3(PHI, 1, 0), {4,new Vector3(PHI, 1, 0)},
new Vector3(0, PHI, 1), {5,new Vector3(0, PHI, 1)},
new Vector3(-1, 0, PHI), {6,new Vector3(-1, 0, PHI)},
new Vector3(-PHI, -1, 0), {7,new Vector3(-PHI, -1, 0)},
new Vector3(0, -PHI, -1), {8,new Vector3(0, -PHI, -1)},
new Vector3(PHI, -1, 0), {9,new Vector3(PHI, -1, 0)},
new Vector3(1, 0, PHI), {10,new Vector3(1, 0, PHI)},
new Vector3(0, -PHI, 1), {11,new Vector3(0, -PHI, 1)},
}, },
new List<List<int>>() new List<List<int>>()
); );
@ -973,17 +973,12 @@ namespace Metamesh
geodesicData.OrderData(primTri); geodesicData.OrderData(primTri);
var radius = 1f; var radius = 1f;
geodesicData.vertex = geodesicData.vertex.Select((el) => var keys = geodesicData.vertex.Keys.ToArray();
{ foreach (var key in keys)
var a = el.x; {
var b = el.y; var el = geodesicData.vertex[key];
var c = el.z; geodesicData.vertex[key] = el * radius / el.magnitude;
var d = Mathf.Sqrt(a * a + b * b + c * c); }
//el[0] *= radius / d;
//el[1] *= radius / d;
//el[2] *= radius / d;
return el * radius / d;
}).ToList();
return geodesicData; return geodesicData;
} }

@ -64,7 +64,7 @@ namespace Metamesh
mesh.SetIndices(indices, MeshTopology.Triangles, 0); mesh.SetIndices(indices, MeshTopology.Triangles, 0);
mesh.RecalculateBounds(); mesh.RecalculateBounds();
mesh.RecalculateNormals(); //mesh.RecalculateNormals();
if (generateLightmapUVs) Unwrapping.GenerateSecondaryUVSet(mesh); if (generateLightmapUVs) Unwrapping.GenerateSecondaryUVSet(mesh);
mesh.UploadMeshData(!readWriteMeshes); mesh.UploadMeshData(!readWriteMeshes);

@ -0,0 +1,18 @@
{
"name": "UltraCombos.Metamesh.Editor",
"rootNamespace": "UltraCombos.Metamesh",
"references": [
"GUID:83ed26dc2742d6d45a9a2c56bf6c7ae8"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 175a0da299bd7024fab52ceee6ed562c
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 21b017472defa2a41882f6b2709a230f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,14 @@
{
"name": "UltraCombos.Metamesh.Runtime",
"rootNamespace": "UltraCombos.Metamesh",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 83ed26dc2742d6d45a9a2c56bf6c7ae8
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: