/** * Populate a renderable's mesh with a face highlight mesh matching the selected triangles array. */ private pb_Renderable BuildFaceMesh(pb_Object pb) { int[] selectedTriangles = pb_Face.AllTriangles(pb.SelectedFaces); Vector3[] v = pbUtil.ValuesWithIndices(pb.vertices, selectedTriangles); pb_Renderable ren = pool.Get(); ren.name = "Faces Renderable"; ren.transform = pb.transform; ren.materials = new Material[] { faceMaterial }; ren.mesh.Clear(); ren.mesh.vertices = v; ren.mesh.normals = v; #if UNITY_5 ren.mesh.uv = null; #else ren.mesh.uv = new Vector2[v.Length]; #endif ren.mesh.triangles = SequentialTriangles(v.Length); return(ren); }
public void AddLineSegments(Vector3[] segments, Color[] colors) { // Because editor scripts are enabled first, pool could still be null // when first request comes in. if (pool == null) { pool = new pb_ObjectPool <Mesh>(1, 4, MeshConstructor, null); } Mesh m = pool.Get(); m.Clear(); m.name = "pb_LineRenderer::Mesh_" + m.GetInstanceID(); m.MarkDynamic(); int vc = segments.Length; int cc = colors.Length; m.vertices = segments; int[] tris = new int[vc]; Color[] col = new Color[vc]; int n = 0; for (int i = 0; i < vc; i++) { tris[i] = i; col[i] = colors[n % cc]; if (i % 2 == 1) { n++; } } m.subMeshCount = 1; m.SetIndices(tris, MeshTopology.Lines, 0); m.uv = new Vector2[m.vertexCount]; m.colors = col; m.hideFlags = pb_Constant.EDITOR_OBJECT_HIDE_FLAGS; gizmos.Add(m); }