- Home /
How to make mesh having array of vertices?
How to make mesh having array of vertices positions (and faces) so normals of faces will face outside (i.e. mesh will be visible)? I need it to my CSG alghorithm.
//edit: To be more specific, here what my structures are:
Vector3 faces[20][3]
First array index is face number, second index is face's vertex number. Vertices are stored as their positions in 3d space.
Answer by Flynn · Jan 09, 2013 at 10:50 AM
If I understand your requirements, this should work:
Vector3[] vertices = new Vector3[faces.Length*3];
int[] tris = new Vector3[faces.Length*3];
for (int i = 0; i < faces.Length;)
{
for (int j = 0; j < faces[i].Length; j++)
{
vertices[i*3 + j] = nvaces[i,j];
tris[i*3 + j] = i*3 + j;
}
}
mesh.vertices = vertices;
mesh.triangles = tris;
This assumes that your faces always have exactly 3 vertices.
What CSG algorithms are you using out of curiosity? I have been been interested from afar in CSG for a while now
No, that's not it. I need a way to make face normals facing outside of mesh, so it will be visible and not turned outside in. //edit: As for Algorithm, I'm making my own as all available are too slow for my purposes.
Your answer
Follow this Question
Related Questions
Mesh collider on procedurally generated mesh 1 Answer
Mesh Collider on a 2D mesh creating a 3D box? 0 Answers
How do i make an object move around a 3D mesh? 1 Answer
Multiple Cars not working 1 Answer
Adaptive Mesh 1 Answer