[Bf-blender-cvs] [98ab0f173c8] blender-v2.81-release: Mesh: add API functions for poly & loop removal

Campbell Barton noreply at git.blender.org
Sun Oct 20 09:25:59 CEST 2019


Commit: 98ab0f173c8c5c9f34af22f9e8748e0101cc6dd1
Author: Campbell Barton
Date:   Sun Oct 20 18:09:41 2019 +1100
Branches: blender-v2.81-release
https://developer.blender.org/rB98ab0f173c8c5c9f34af22f9e8748e0101cc6dd1

Mesh: add API functions for poly & loop removal

These existed for verts & edges, add for API completeness.
Also add ED_mesh_geometry_clear,
needed to reduce memory for edit-mesh separate.

===================================================================

M	source/blender/editors/include/ED_mesh.h
M	source/blender/editors/mesh/mesh_data.c
M	source/blender/makesrna/intern/rna_mesh.c

===================================================================

diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index d8d62ad6f08..fc7b0d8be8f 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -380,17 +380,17 @@ float ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vert
 void ED_vgroup_vert_active_mirror(struct Object *ob, int def_nr);
 
 /* mesh_data.c */
-#if 0
-void ED_mesh_geometry_add(
-    struct Mesh *mesh, struct ReportList *reports, int verts, int edges, int faces);
-#endif
-void ED_mesh_polys_add(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_verts_add(struct Mesh *mesh, struct ReportList *reports, int count);
 void ED_mesh_edges_add(struct Mesh *mesh, struct ReportList *reports, int count);
 void ED_mesh_loops_add(struct Mesh *mesh, struct ReportList *reports, int count);
-void ED_mesh_vertices_add(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_polys_add(struct Mesh *mesh, struct ReportList *reports, int count);
 
+void ED_mesh_verts_remove(struct Mesh *mesh, struct ReportList *reports, int count);
 void ED_mesh_edges_remove(struct Mesh *mesh, struct ReportList *reports, int count);
-void ED_mesh_vertices_remove(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_loops_remove(struct Mesh *mesh, struct ReportList *reports, int count);
+void ED_mesh_polys_remove(struct Mesh *mesh, struct ReportList *reports, int count);
+
+void ED_mesh_geometry_clear(struct Mesh *mesh);
 
 void ED_mesh_update(struct Mesh *mesh, struct bContext *C, bool calc_edges, bool calc_edges_loose);
 
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index a0d424e083c..7007ff29401 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -1023,73 +1023,104 @@ static void mesh_add_polys(Mesh *mesh, int len)
   mesh->totpoly = totpoly;
 }
 
-static void mesh_remove_verts(Mesh *mesh, int len)
+/* -------------------------------------------------------------------- */
+/** \name Add Geometry
+ * \{ */
+
+void ED_mesh_verts_add(Mesh *mesh, ReportList *reports, int count)
 {
-  int totvert;
+  if (mesh->edit_mesh) {
+    BKE_report(reports, RPT_ERROR, "Cannot add vertices in edit mode");
+    return;
+  }
+  mesh_add_verts(mesh, count);
+}
 
-  if (len == 0) {
+void ED_mesh_edges_add(Mesh *mesh, ReportList *reports, int count)
+{
+  if (mesh->edit_mesh) {
+    BKE_report(reports, RPT_ERROR, "Cannot add edges in edit mode");
     return;
   }
+  mesh_add_edges(mesh, count);
+}
 
-  totvert = mesh->totvert - len;
-  CustomData_free_elem(&mesh->vdata, totvert, len);
+void ED_mesh_loops_add(Mesh *mesh, ReportList *reports, int count)
+{
+  if (mesh->edit_mesh) {
+    BKE_report(reports, RPT_ERROR, "Cannot add loops in edit mode");
+    return;
+  }
+  mesh_add_loops(mesh, count);
+}
 
-  /* set final vertex list size */
+void ED_mesh_polys_add(Mesh *mesh, ReportList *reports, int count)
+{
+  if (mesh->edit_mesh) {
+    BKE_report(reports, RPT_ERROR, "Cannot add polygons in edit mode");
+    return;
+  }
+  mesh_add_polys(mesh, count);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Remove Geometry
+ * \{ */
+
+static void mesh_remove_verts(Mesh *mesh, int len)
+{
+  if (len == 0) {
+    return;
+  }
+  const int totvert = mesh->totvert - len;
+  CustomData_free_elem(&mesh->vdata, totvert, len);
   mesh->totvert = totvert;
 }
 
 static void mesh_remove_edges(Mesh *mesh, int len)
 {
-  int totedge;
-
   if (len == 0) {
     return;
   }
-
-  totedge = mesh->totedge - len;
+  const int totedge = mesh->totedge - len;
   CustomData_free_elem(&mesh->edata, totedge, len);
-
   mesh->totedge = totedge;
 }
 
-#if 0
-void ED_mesh_geometry_add(Mesh *mesh, ReportList *reports, int verts, int edges, int faces)
+static void mesh_remove_loops(Mesh *mesh, int len)
 {
-  if (mesh->edit_mesh) {
-    BKE_report(reports, RPT_ERROR, "Cannot add geometry in edit mode");
+  if (len == 0) {
     return;
   }
-
-  if (verts) {
-    mesh_add_verts(mesh, verts);
-  }
-  if (edges) {
-    mesh_add_edges(mesh, edges);
-  }
-  if (faces) {
-    mesh_add_faces(mesh, faces);
-  }
+  const int totloop = mesh->totloop - len;
+  CustomData_free_elem(&mesh->ldata, totloop, len);
+  mesh->totloop = totloop;
 }
-#endif
 
-void ED_mesh_edges_add(Mesh *mesh, ReportList *reports, int count)
+static void mesh_remove_polys(Mesh *mesh, int len)
 {
-  if (mesh->edit_mesh) {
-    BKE_report(reports, RPT_ERROR, "Cannot add edges in edit mode");
+  if (len == 0) {
     return;
   }
-
-  mesh_add_edges(mesh, count);
+  const int totpoly = mesh->totpoly - len;
+  CustomData_free_elem(&mesh->pdata, totpoly, len);
+  mesh->totpoly = totpoly;
 }
 
-void ED_mesh_vertices_add(Mesh *mesh, ReportList *reports, int count)
+void ED_mesh_verts_remove(Mesh *mesh, ReportList *reports, int count)
 {
   if (mesh->edit_mesh) {
-    BKE_report(reports, RPT_ERROR, "Cannot add vertices in edit mode");
+    BKE_report(reports, RPT_ERROR, "Cannot remove vertices in edit mode");
+    return;
+  }
+  else if (count > mesh->totvert) {
+    BKE_report(reports, RPT_ERROR, "Cannot remove more vertices than the mesh contains");
     return;
   }
 
-  mesh_add_verts(mesh, count);
+  mesh_remove_verts(mesh, count);
 }
 
 void ED_mesh_edges_remove(Mesh *mesh, ReportList *reports, int count)
@@ -1106,40 +1137,44 @@ void ED_mesh_edges_remove(Mesh *mesh, ReportList *reports, int count)
   mesh_remove_edges(mesh, count);
 }
 
-void ED_mesh_vertices_remove(Mesh *mesh, ReportList *reports, int count)
+void ED_mesh_loops_remove(Mesh *mesh, ReportList *reports, int count)
 {
   if (mesh->edit_mesh) {
-    BKE_report(reports, RPT_ERROR, "Cannot remove vertices in edit mode");
+    BKE_report(reports, RPT_ERROR, "Cannot remove loops in edit mode");
     return;
   }
-  else if (count > mesh->totvert) {
-    BKE_report(reports, RPT_ERROR, "Cannot remove more vertices than the mesh contains");
+  else if (count > mesh->totloop) {
+    BKE_report(reports, RPT_ERROR, "Cannot remove more loops than the mesh contains");
     return;
   }
 
-  mesh_remove_verts(mesh, count);
+  mesh_remove_loops(mesh, count);
 }
 
-void ED_mesh_loops_add(Mesh *mesh, ReportList *reports, int count)
+void ED_mesh_polys_remove(Mesh *mesh, ReportList *reports, int count)
 {
   if (mesh->edit_mesh) {
-    BKE_report(reports, RPT_ERROR, "Cannot add loops in edit mode");
+    BKE_report(reports, RPT_ERROR, "Cannot remove polys in edit mode");
+    return;
+  }
+  else if (count > mesh->totpoly) {
+    BKE_report(reports, RPT_ERROR, "Cannot remove more polys than the mesh contains");
     return;
   }
 
-  mesh_add_loops(mesh, count);
+  mesh_remove_polys(mesh, count);
 }
 
-void ED_mesh_polys_add(Mesh *mesh, ReportList *reports, int count)
+void ED_mesh_geometry_clear(Mesh *mesh)
 {
-  if (mesh->edit_mesh) {
-    BKE_report(reports, RPT_ERROR, "Cannot add polygons in edit mode");
-    return;
-  }
-
-  mesh_add_polys(mesh, count);
+  mesh_remove_verts(mesh, mesh->totvert);
+  mesh_remove_edges(mesh, mesh->totedge);
+  mesh_remove_loops(mesh, mesh->totloop);
+  mesh_remove_polys(mesh, mesh->totpoly);
 }
 
+/** \} */
+
 void ED_mesh_report_mirror_ex(wmOperator *op, int totmirr, int totfail, char selectmode)
 {
   const char *elem_type;
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index d5fc422a9f9..31829145b5a 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -2232,13 +2232,13 @@ static void rna_def_mesh_vertices(BlenderRNA *brna, PropertyRNA *cprop)
   RNA_def_struct_sdna(srna, "Mesh");
   RNA_def_struct_ui_text(srna, "Mesh Vertices", "Collection of mesh vertices");
 
-  func = RNA_def_function(srna, "add", "ED_mesh_vertices_add");
+  func = RNA_def_function(srna, "add", "ED_mesh_verts_add");
   RNA_def_function_flag(func, FUNC_USE_REPORTS);
   parm = RNA_def_int(
       func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
 #  if 0 /* BMESH_TODO Remove until BMesh merge */
-  func = RNA_def_function(srna, "remove", "ED_mesh_vertices_remove");
+  func = RNA_def_function(srna, "remove", "ED_mesh_verts_remove");
   RNA_def_function_flag(func, FUNC_USE_REPORTS);
   RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to remove", 0, INT_MAX);
 #  endif



More information about the Bf-blender-cvs mailing list