我在 HoloLens 应用程序上工作,我想渲染一些简单的多边形。每个多边形标记一个限制区域。
我使用网格来解决此任务,在统一播放器上它工作正常,但在 HoloLens 上它不显示网格。HoloLens 是否因为空间映射而忽略了网格,或者有人知道这个问题吗?
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);
}