Hi,
I am currently working on A plugin to support A custom model format, but when I apply the triangles to sub meshes, the model disappears. The mesh says the triangles exist, but the faces just completely disappear. They do not render nor appear in the wireframe. Any ideas on what's going on here?
Here is the relevant code:
mesh.vertices = verts.ToArray();
mesh.triangles = tris.ToArray();
mesh.uv = uvs.ToArray();
mesh.normals = normals.ToArray();
mesh.subMeshCount = materials.Count;
// Remove this section and everything works perfectly fine, minus the fact that the mesh only supports one material
for (int i = 0; i < mesh.subMeshCount; i++)
{
List<int> targetTris = new List<int>();
for (int x = 0; x < submeshes.Count; x++)
{
if (submeshes[x] == i)
{ targetTris.Add(submeshes[x]); }
}
mesh.SetTriangles(targetTris, i);
}
//mesh.RecalculateNormals();
mesh.RecalculateTangents();
mesh.RecalculateBounds();
mesh.name = new DirectoryInfo(ctx.assetPath).Name;
mesh.name = mesh.name.Substring(0, mesh.name.Length - 4);
ctx.AddObjectToAsset("mesh", mesh);
foreach (Material mat in materials)
{ ctx.AddObjectToAsset(mat.name, mat); }
GameObject meshObj = new GameObject();
meshObj.AddComponent<MeshFilter>().sharedMesh = mesh;
meshObj.AddComponent<MeshRenderer>().SetSharedMaterials(materials);
ctx.AddObjectToAsset("main", meshObj);
ctx.SetMainObject(meshObj);