public void CopyMarkedPolys(DMesh src, bool all = false, bool tag_new = false) { // Tag all the src verts in marked polys List <int> old_vert_index = new List <int>(); List <int> new_vert_index = new List <int>(); src.TagAllVerts(false); ClearAllMarkedPoly(); foreach (DPoly dp in src.polygon) { if (dp.marked || all) { for (int i = 0; i < dp.num_verts; i++) { src.vert_info[dp.vert[i]].tag = true; } } } // Copy all tagged verts to me // - And create lists for conversion for (int i = 0; i < src.vertex.Count; i++) { if (src.vert_info[i].tag) { old_vert_index.Add(i); new_vert_index.Add(vertex.Count); vertex.Add(src.vertex[i]); vert_info.Add(new DVert()); } } // Copy all marked polys to me (converting vert idxs in process) foreach (DPoly old_dp in src.polygon) { if (old_dp.marked || all) { DPoly new_dp = new DPoly(old_dp); polygon.Add(new_dp); new_dp.marked = true; new_dp.tag = tag_new; for (int i = 0; i < new_dp.num_verts; i++) { int old_index = new_dp.vert[i]; old_index = FindIdxInList(old_index, old_vert_index); if (old_index > -1 && old_index < new_vert_index.Count) { new_dp.vert[i] = new_vert_index[old_index]; } else { Utility.DebugPopup("This is bad, copy-paste failed", "ERROR!"); } } } } }