Hello, and thank you for your support!
On 10/18/2018 at 11:14 AM, TeaTreeTim said:
That mesh class you linked is pretty stupid
Yes, I linked it to show what I have available, so basically nothing. It also shows what I need to feed to the class to make a mesh appear. What I need is to fill the Mesh.vertices[] and the Mesh.triangles[].
To make my questions more precise: (They mainly revolve arround the structure/architecture of data storage)
1. In what fashion do I index the vertices? Is there some "best practice" amongst graphic programmers?
I just finished my Bachelor of Arts (Digital Media), so my programming-skills are mainly self-educated. I focus on Artificial Intelligence.
2. Is there a fitting, elegant algorithm already existing that matches the indices of the vertices[]-array to the triangles[]-array?
3. (Partly answered) How do I store the information for later usage in the pathfinder?
This is what I got so far (creating a flat hexagon in C#):
using UnityEngine;
public class D_HexTile : MonoBehaviour
{
public float mSize = 1f;
public Material mMaterial;
void CreateHex()
{
gameObject.AddComponent<MeshFilter>();
gameObject.AddComponent<MeshRenderer>();
Mesh mesh = GetComponent<MeshFilter>().mesh;
mesh.Clear();
// === Vertices ===
Vector3[] vertices = new Vector3[7];
vertices[0] = transform.position;
for(int i = 1; i < vertices.Length; i++)
{
vertices[i] = GetCorner(transform.position, mSize, i - 1);
}
mesh.vertices = vertices;
// === Triangles ===
int[] triangles = new int[6 * 3];
int triNum = 1;
for(int l = 0; l < triangles.Length; l++)
{
if (l % 3 == 0)
{
triangles[l] = 0;
}
else if(l % 3 == 1)
{
triangles[l] = 1 + (triNum % 6);
}
else if(l % 3 == 2)
{
triangles[l] = triNum;
triNum++;
}
}
mesh.vertices = vertices;
mesh.triangles = triangles;
}
private Vector3 GetCorner(Vector3 center, float size, int i)
{
float angleDeg = 60f * i;
float angleRad = Mathf.Deg2Rad * angleDeg;
return new Vector3(center.x + size * Mathf.Cos(angleRad),
center.y,
center.z + size * Mathf.Sin(angleRad));
}
}
I omitted parts for UV's and normals. I show this to give an example usage of the Mesh-class ... Now I have to feed it.
So, this is obviously not enough. GetCorners() will suffice for the hexagon corners, but using the midpoints by doing vector-math for sub-devided triangles (as you suggested) seems more appropriate. So, now I have to deal with the questions above.
I can't seem to wrap my mind arround what question to prioritize first. The answer to question 2. depends on how I deal with 1. and 3.
If I want the indices stored in a certain way, I will have to traverse the QuadTree / BinaryTree in a certain way (whatever that will look like).
The other way arround: When I store the sub-devided triangles in a certain way, they may predefine the indices of the vertices.
On 10/18/2018 at 12:08 PM, Gnollrunner said:
I use a data structure with explicit edges, which are shared by neighboring triangles. trangles are stored in a quadtree.
I found this idea very inspiring and would like to know more. I will probably need the edges more often than the faces (pathfinding).
Do I understand this correctly, when I say the following?
I have a List of edges. When it is just the hexagon, I have 12 of them. 6 of those contain data for two triangles, the other 6 have only one triangle (the outer edges). I thereby have 3 references to any one triangle. When I call SubdevideTri() on any triangle, it will tell all three edges to SubdevideEdge() and then .... .... well, this is where my brain locks up ....
To the point: @Gnollrunner Could you ellaborate on how you did this?
How is your data stored? Do the edges contain the corners and the triangles? Why do I need the triangles stored in a QuadTree, when I already have their reference in the edges, stored in 6 BinaryTrees? What about the new edges "in between" midpoints?
Or is the QuadTree of triangles the "dominant" storage? Do the triangles reference the edges? Do I really need the BinaryTree in that case?
Or do you do both, to simplify access?
I will try things out a bit and come back to you.
On 10/18/2018 at 5:29 PM, ninnghazad said:
the number of unique vertices per triangle per level of subdivision (not per hex) should be integer sequence https://oeis.org/A028401
Valueable knowledge, thank you for this!
Thanks again for your support! Cheers!