Ive been looking around on a solution to create and modify shapes from code. All ive found so far is Vectrosity, which i love, and tips on how to create a solution myself.
Problem is
- Vectrocity cannot fill shapes. It will only create lines.
- Doing it myself would mean having to go in depth on how to create meshes and how vector grapvhis work at its core. Which is great! But since its only a hobby of mine and there is so much to explore i would prefer not having to do that. Its full of scary math! (dont argue with me on this, for me it IS scary. Also i havent been able to find an easy explanation of these things).
Is ther anything else i have missed? Would it be possible to create primitive vector shapes and modify the mesh in the code?
I have to do something similar in some code I’m playing around with. You say it’s scary, what in particular scares you? Anything I can help with?
Creating shapes from a mesh needn’t be scary, and it doesn’t require that much maths really.
Define points in space which are you shape corners.
Set the order that these points will be connected (Clockwise for example)
Decide on a method for connecting these points - triangles/lines.
Let Unity do the rest.
int triangleIndices = (3 * (vertices.Length - 2)); // I use triangles so I have 3 * number of vertices to plot
int C0 = 0;
int C1 = 1;
int C2 = 2;
int[] newTriangles = new int[triangleIndices];
for (int i = 0; i < triangleIndices; i+=3)
{
newTriangles[i] = C0; // each triangle will start an end from the origin (centre) of my shape
newTriangles[i+1] = C1;
newTriangles[i+2] = C2;
C1++;
C2++;
}
Mesh mesh = meshFilter.mesh; // get the MeshFilter component of this game object
mesh.vertices = vertices; // set the points in space
mesh.SetIndices(newTriangles, MeshTopology.Triangles, 0); // set the order in which the vertices will be drawn
Thanks for your help! I guess i can try your code and learn by modifying it. Problem is that i cant really grasp what happens or what these triangles really do, so its too abstract at the momen. But ill look into it. 
Not sure of all, but certainly most shapes in computer graphics are made up of stitching together triangles. A good visualisation of the concept is here: http://www.arcsynthesis.org/gltut/Positioning/Tut07%20Primitive%20Drawing.html Take a look at Triangle Fan, that’s the method I am using in that sample code. Another method might be more appropriate for your requirements
1 Like