How to correctly assign triangles to a "Procedural Mesh"
I've watched a lot of tutorials about procedural generating of meshes but none of them actually talks about how to correctly assign triangles with real code, not just assigning the array... I think i understeand how it works the manual-way, the clockwise thing and so on... But after creating a simple test mesh i can't see any pattern in the triangles array.
I made a mesh with a house shape, and the triangles look like this:
int[] triangles = { 0,3,2, 0,2,1, 3,4,2 };
But i can see no pattern in this.
So the question is: Is there any specific algorythm or are there any tutorials / someone can help? Or do i just have to figure it out?
Answer by VesuvianPrime · Jul 29, 2014 at 03:17 PM
Hey Wampir888
What kind of pattern are you looking for? When writing procedural mesh generation logic you're mostly going to be working with triangle strips:
So long as you keep your verts in a good order you can step through the triangles relatively easily. Even at a glance we can see that your triangles will be:
0,1,2
1,3,2
2,3,4
and so on.
Hi, actually i'm looking to make a font based mesh, so its more compilcated, but i have to start from somewhere... The thing i can't unders$$anonymous$$nd is how to write an algorithm that automatically detects which vertices a triangle will be composed of. Lets say i want to create a strip like the one in your image, i have no idea what formula to use in a for loop to get the vertices.
EDIT: Thanks a lot for the reply i now kind of know how it works.
This is a bit old. But VesuvianPrime, you seem to have made a mistake. Given the first triangle of 0,1,2 the second one should be 0,2,3.
Anyway, it's obvious how to write them out manually, but creating an algorithm isn't so simple and I am also interested in a good answer.
Answer by dhurstdev · Dec 24, 2016 at 09:09 AM
I would refer here, you problem is prob. the order you set or normals or you never put the mesh on a GameObject etc...: http://answers.unity3d.com/questions/1207764/creating-a-plane-from-a-plane-equation.html#answer-1288444 & thank @TSLzipper... Also, you can double click the mesh and it will show you num Verts and num Tris... So where they show or now, you can see if those are correct first! GL
Answer by dhurstdev · Dec 24, 2016 at 11:48 PM
I would refer here, you problem is prob. the order you set or normals or you never put the mesh on a GameObject etc...: http://answers.unity3d.com/questions/1207764/creating-a-plane-from-a-plane-equation.html#answer-1288444 & thank @TSLzipper... Also, you can double click the mesh and it will show you num Verts and num Tris... So where they show or now, you can see if those are correct first! GL
Answer by UnPluks · Jan 03, 2017 at 05:08 AM
Hello. For anyone interested, this is what I do. The figure should be seperated into two shapes, a square and a triangle, otherwise it can still be done. First you get all the vertices in order, that would be {0, 3, 4, 2, 1} Then you check groups of 3. so for example, the first three is {0,3,4} so we must "mark" 3 as used. so we have a new group of numbers {0,4,2,1} Then again we take 3 {0,4,2} and mark 4 as used. later you have {0,2,1} thats your last triangle. and you have a valid arrangement. If you want more info you can ask me I can make a tutorial on my Youtube channel "Creagines"
Your answer

Follow this Question
Related Questions
Some triangles are black on a mesh generated by script 1 Answer
How can I remove shooted mesh of object? 0 Answers
Mesh generation triangles issue 0 Answers
Normals and triangles 0 Answers
Vertex Coloured Shader for trianges. 1 Answer