/// <summary> /// Split edge in half /// </summary> /// <param name="m">Polymesh</param> /// <param name="eh">Edge Handle</param> /// <returns>New Half-edge Handle for the new Edge</returns> public static int SplitEdge(PolyMesh m, int eh) { int heh = m.GetHalfedgeEdgeH(eh, 0); int opp_heh = m.GetHalfedgeEdgeH(eh, 1); int new_heh, opp_new_heh, t_heh; int vh, vh1 = m.GetEndVertexH(heh); Vector3 midP = m.GetPoint(vh1); midP += m.GetPoint(m.GetEndVertexH(opp_heh)); midP *= 0.5f; // new vertex vh = m.AddVertex(midP); // Re-link mesh entities if (m.IsBoundaryEdge(eh)) { for (t_heh = heh; m.GetNextHalfedgeH(t_heh) != opp_heh; t_heh = m.GetOppositeHalfedgeH(m.GetNextHalfedgeH(t_heh))) { } } else { for (t_heh = m.GetNextHalfedgeH(opp_heh); m.GetNextHalfedgeH(t_heh) != opp_heh; t_heh = m.GetNextHalfedgeH(t_heh)) { } } new_heh = m.NewEdge(vh, vh1); opp_new_heh = m.GetOppositeHalfedgeH(new_heh); m.SetVertexH(heh, vh); m.SetNextHalfedgeH(t_heh, opp_new_heh); m.SetNextHalfedgeH(new_heh, m.GetNextHalfedgeH(heh)); m.SetNextHalfedgeH(heh, new_heh); m.SetNextHalfedgeH(opp_new_heh, opp_heh); if (m.GetFaceH(opp_heh).isValidHandle()) { m.SetFaceH(opp_new_heh, m.GetFaceH(opp_heh)); m.SetHalfedgeFaceH(m.GetFaceH(opp_new_heh), opp_new_heh); } m.SetFaceH(new_heh, m.GetFaceH(heh)); m.SetHalfedgeVertexH(vh, new_heh); m.SetHalfedgeFaceH(m.GetFaceH(heh), heh); m.SetHalfedgeVertexH(vh1, opp_new_heh); // Never forget this, when playing with the topology m.AdjustOutgoingHalfedge(vh); m.AdjustOutgoingHalfedge(vh1); return(new_heh); }