public void Build(Material defaultMaterial) { //Clear our large arrays if (mtlLines != null) { Array.Clear(mtlLines, 0, mtlLines.Length); } Array.Clear(objLines, 0, objLines.Length); var materialLibrary = new Dictionary <string, Material>(); if (!string.IsNullOrEmpty(mtllib) && materialDataSlots != null) { foreach (MaterialData md in materialDataSlots) { if (materialLibrary.ContainsKey(md.Name)) { Debug.LogWarning("Duplicate material found: " + md.Name + ". ignored repeated occurences"); continue; } materialLibrary.Add(md.Name, GetMaterial(md, defaultMaterial)); } } var gameObjects = new GameObject[buffer.NumberOfObjects]; if (buffer.NumberOfObjects == 1) { //Single gameobject, single mesh gameObject.AddComponent(typeof(MeshFilter)); gameObject.AddComponent(typeof(MeshRenderer)); gameObjects[0] = gameObject; } else if (buffer.NumberOfObjects > 1) { for (int i = 0; i < buffer.NumberOfObjects; i++) { //Multi object with nested children var go = new GameObject(); go.transform.parent = gameObject.transform; go.AddComponent(typeof(MeshFilter)); go.AddComponent(typeof(MeshRenderer)); gameObjects[i] = go; } } buffer.Trace(); buffer.PopulateMeshes(gameObjects, materialLibrary, defaultMaterial); }