From 62ac943e3108ad5f70cd5349cd5f1cef98138313 Mon Sep 17 00:00:00 2001 From: Andrew Hale Date: Fri, 20 Jan 2012 02:10:09 +0000 Subject: - Added functions to remove mesh vertices, edges and faces. These functions remove a specified number of elements from the end of their respective arrays. For example, removing two vertices removes the last two vertices of the mesh. - Minor fixes to descriptions of add edge and add face functions. --- source/blender/editors/mesh/mesh_data.c | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'source/blender/editors/mesh') diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index e40c806fd17..7f599fb3458 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -695,6 +695,49 @@ static void mesh_add_faces(Mesh *mesh, int len) mesh->totface= totface; } +static void mesh_remove_verts(Mesh *mesh, int len) +{ + CustomData vdata; + int totvert; + + if(len == 0) + return; + + totvert= mesh->totvert - len; + CustomData_free_elem(&mesh->vdata, totvert, len); + + /* set final vertex list size */ + mesh->totvert= totvert; +} + +static void mesh_remove_edges(Mesh *mesh, int len) +{ + CustomData edata; + int totedge; + + if(len == 0) + return; + + totedge= mesh->totedge - len; + CustomData_free_elem(&mesh->edata, totedge, len); + + mesh->totedge= totedge; +} + +static void mesh_remove_faces(Mesh *mesh, int len) +{ + CustomData fdata; + int totface; + + if(len == 0) + return; + + totface= mesh->totface - len; /* new face count */ + CustomData_free_elem(&mesh->fdata, totface, len); + + mesh->totface= totface; +} + /* void ED_mesh_geometry_add(Mesh *mesh, ReportList *reports, int verts, int edges, int faces) { @@ -742,6 +785,48 @@ void ED_mesh_vertices_add(Mesh *mesh, ReportList *reports, int count) mesh_add_verts(mesh, count); } +void ED_mesh_faces_remove(Mesh *mesh, ReportList *reports, int count) +{ + if(mesh->edit_mesh) { + BKE_report(reports, RPT_ERROR, "Can't remove faces in edit mode"); + return; + } + else if(count > mesh->totface) { + BKE_report(reports, RPT_ERROR, "Can't remove more faces than the mesh contains"); + return; + } + + mesh_remove_faces(mesh, count); +} + +void ED_mesh_edges_remove(Mesh *mesh, ReportList *reports, int count) +{ + if(mesh->edit_mesh) { + BKE_report(reports, RPT_ERROR, "Can't remove edges in edit mode"); + return; + } + else if(count > mesh->totedge) { + BKE_report(reports, RPT_ERROR, "Can't remove more edges than the mesh contains"); + return; + } + + mesh_remove_edges(mesh, count); +} + +void ED_mesh_vertices_remove(Mesh *mesh, ReportList *reports, int count) +{ + if(mesh->edit_mesh) { + BKE_report(reports, RPT_ERROR, "Can't remove vertices in edit mode"); + return; + } + else if(count > mesh->totvert) { + BKE_report(reports, RPT_ERROR, "Can't remove more vertices than the mesh contains"); + return; + } + + mesh_remove_verts(mesh, count); +} + void ED_mesh_calc_normals(Mesh *me) { mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL); -- cgit v1.2.3