Hello,
I am using Vectrosity to draw some some shapes on screen run time. I also need to fill these shapes and none of them are really trivial shapes. So after doing some research I figured the best way would be to do it by creating a runtime mesh. Now this almost works for me but has a big issue.
This is my process.

I have defined my complex shapes as a set of 2D vertices that I extracted from Illustrator. These vertices I feed to the Vectrosity’s Catmul spline function to create my shapes.

I then project these vertices in the real space using ScreenToWorldPoint to get 3D vertices.

I then pass these vertices to a program that Triangulates these points to a mesh (I use the classic Triangulate script on wiki)

I then clean up a little and align
Now all this works well if the camera is not rotated and the forward vector of the camera is orthogonal to the XY plane. The moment I rotate the camera the alignment of the mesh and the vector lines is completely gone.
Here is the image of the vectorline and mesh when the camera is not rotated
[645341.jpg*_64534]
And here is the image when the camera is rotated
[645352.jpg*_64535]
Here is the function that projects the point into 3D space
void DrawPolygon () {
Vector2[] tempVerts = new Vector2[allLinePoints.Count];
for(int i=0; i<allLinePoints.Count; i++) {
Vector3 projectedPoint = Camera.main.ScreenToWorldPoint(new Vector3(allLinePoints_.x, allLinePoints*.y, 10.0f));*_
_ tempVerts = new Vector2(projectedPoint.x, projectedPoint.y);_
* }*
* polyTarget.SendMessage(“Create”, tempVerts);*
* }*
This message is sent to a generic Triangulation script. Here it is
using UnityEngine;
using System.Collections;
using System.Linq;
public class CreatePolygon : MonoBehaviour {
* public Material meshMaterial;*
* public void Create (Vector2[] verts) {*
* Triangulator tr = new Triangulator (verts);*
* int[] indices = tr.Triangulate ();*
* // Create the Vector3 vertices*
* Vector3[] vertices = new Vector3[verts.Length];*
* for (int i=0; i<vertices.Length; i++) {*
vertices = new Vector3(verts_.x, verts*.y, 0);
}*_
* // Create the mesh*
* Mesh msh = new Mesh();*
* msh.vertices = vertices;*
* msh.triangles = indices;*
* msh.RecalculateNormals();*
* msh.RecalculateBounds();*
* // Set up game object with mesh;*
* gameObject.AddComponent(typeof(MeshRenderer));*
* MeshFilter filter = gameObject.AddComponent(typeof(MeshFilter)) as MeshFilter;*
* filter.mesh = msh;*
* GetComponent ().material = meshMaterial;*
* StartCoroutine (FlipNormal ());*
* }*
* public void ResetMesh (Vector2[] verts) {*
* Triangulator tr = new Triangulator (verts);*
* int[] indices = tr.Triangulate ();*
* // Create the Vector3 vertices*
* Vector3[] vertices = new Vector3[verts.Length];*
* for (int i=0; i<vertices.Length; i++) {*
vertices = new Vector3(verts_.x, verts*.y, 0);
}*_
* // Create the mesh*
* Mesh msh = new Mesh();*
* msh.vertices = vertices;*
* msh.triangles = indices;*
* msh.RecalculateNormals();*
* msh.RecalculateBounds();*
* // Set up game object with mesh;*
* MeshFilter filter = GetComponent ();*
* filter.mesh = msh;*
* GetComponent ().material = meshMaterial;*
* StartCoroutine (FlipNormal ());*
* }*
* IEnumerator FlipNormal() {*
* yield return new WaitForSeconds (0.1f);*
* Mesh mesh = (GetComponent () as MeshFilter).mesh;*
* mesh.uv = mesh.uv.Select(o => new Vector2(1  o.x, o.y)).ToArray();*
* mesh.triangles = mesh.triangles.Reverse().ToArray();*
* }*
}
Now this seems to be an obvious problem to have but I am just not being able to crack it. I have a feeling the solution is some mathematics that is completely escaping me right now. Can someone please help and point me to the right direction. I need to be able to align the mesh to the outline even when the camera is rotated.
Thanks
*
*