public static void ExtrudeSection( this IMeshBuilder meshBuilder, IMeshSelection currentSelection, int sectionStart, int sectionEnd, Func <int, Vector3, Vector3> extrudeTranslationFunc) { var sectionSelection = currentSelection.SelectRange(sectionStart, sectionEnd); sectionSelection = meshBuilder.ExtrudeEdge( sectionSelection, extrudeTranslationFunc); var origStart = currentSelection.GetAtVirtualIndex(sectionStart); var origEnd = currentSelection.GetAtVirtualIndex(sectionEnd); for (int i = 0; i < sectionSelection.Count; i++) { var currentSelectionIndex = (sectionStart + i).Wrap(currentSelection.Count - 1); currentSelection[currentSelectionIndex] = sectionSelection[i]; } // If the section selection covers the entire current selection, we don't need to // insert any indices to maintain the link back to the current selection. if (origStart == sectionEnd) { return; } if (sectionStart <= sectionEnd) { currentSelection.Insert(origEnd, sectionEnd + 1); currentSelection.Insert(origStart, sectionStart); } else { currentSelection.Insert(origStart, sectionStart); currentSelection.Insert(origEnd, sectionEnd + 1); } }