I work on a HoloLens application and i want to render some simple polygons. Each polygon marks a restricted area.
I used a mesh to solve this task, at the unity player it works fine but on HoloLens it doesn't display the mesh. Does the HoloLens ignore the mesh because of the spatial mapping or have anybody an idea for this problem?
Vector3[] AllVertices = polygonCoordinates.ToArray();
for (int i = 0; i < AllVertices.Length-3; i = i + 2)
{
GameObject polygonGameObject = new GameObject("Polygon");
Mesh mesh = new Mesh();
polygonGameObject.transform.SetParent(polygonContainer.transform, true);
MeshFilter meshFilter = (MeshFilter)polygonGameObject.AddComponent(typeof(MeshFilter));
//Styles for Mesh
MeshRenderer renderer = polygonGameObject.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
renderer.material.shader = Shader.Find("Particles/Additive");
Texture2D tex = new Texture2D(1, 1);
tex.SetPixel(0, 0, Color.red);
tex.Apply();
renderer.material.mainTexture = tex;
renderer.material.color = Color.red;
Vector3[] vertices = new Vector3[4];
vertices[0] = AllVertices[i];
vertices[1] = AllVertices[i+1];
vertices[2] = AllVertices[i+2];
vertices[3] = AllVertices[i+3];
mesh.vertices = vertices;
int[] tri = new int[6];
//Upper triangle
tri[0] = 0;
tri[1] = 1;
tri[2] = 2;
//Lower triangle
tri[3] = 2;
tri[4] = 1;
tri[5] = 3;
mesh.triangles = tri;
//Normals for nice rendering
Vector3[] normals = new Vector3[4];
normals[0] = -Vector3.forward;
normals[1] = -Vector3.forward;
normals[2] = -Vector3.forward;
normals[3] = -Vector3.forward;
mesh.normals = normals;
//For texture
Vector2[] uv = new Vector2[4];
uv[0] = new Vector2(0, 0);
uv[1] = new Vector2(1, 0);
uv[2] = new Vector2(0, 1);
uv[3] = new Vector2(1, 1);
mesh.uv = uv;
mesh.RecalculateNormals();
meshFilter.mesh = mesh;
GameObject.Instantiate(polygonGameObject);
}