[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57452] trunk/blender/source/blender: expose smooth group calculation to python as Mesh.calc_smooth_groups()

Campbell Barton ideasman42 at gmail.com
Fri Jun 14 11:59:10 CEST 2013


Revision: 57452
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57452
Author:   campbellbarton
Date:     2013-06-14 09:59:09 +0000 (Fri, 14 Jun 2013)
Log Message:
-----------
expose smooth group calculation to python as Mesh.calc_smooth_groups()

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_mesh.h
    trunk/blender/source/blender/blenkernel/intern/mesh.c
    trunk/blender/source/blender/makesrna/intern/rna_mesh_api.c

Modified: trunk/blender/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_mesh.h	2013-06-14 08:59:21 UTC (rev 57451)
+++ trunk/blender/source/blender/blenkernel/BKE_mesh.h	2013-06-14 09:59:09 UTC (rev 57452)
@@ -107,7 +107,8 @@
 
 int *BKE_mesh_calc_smoothgroups(const struct MEdge *medge, const int totedge,
                                 const struct MPoly *mpoly, const int totpoly,
-                                const struct MLoop *mloop, const int totloop);
+                                const struct MLoop *mloop, const int totloop,
+                                int *r_totgroup);
 
 void BKE_mesh_calc_relative_deform(
         const struct MPoly *mpoly, const int totpoly,

Modified: trunk/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mesh.c	2013-06-14 08:59:21 UTC (rev 57451)
+++ trunk/blender/source/blender/blenkernel/intern/mesh.c	2013-06-14 09:59:09 UTC (rev 57452)
@@ -3203,27 +3203,41 @@
 	return total_area;
 }
 
-
+/**
+ * Calculate smooth groups from sharp edges.
+ *
+ * \param r_totgroup The total number of groups, 1 or more.
+ * \return Polygon aligned array of group index values (starting at 1)
+ */
 int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge,
                                 const MPoly *mpoly, const int totpoly,
-                                const MLoop *mloop, const int totloop)
+                                const MLoop *mloop, const int totloop,
+                                int *r_totgroup)
 {
-	int *poly_groups = MEM_callocN(sizeof(int) * totpoly, __func__);
-	int *poly_stack  = MEM_mallocN(sizeof(int) * totpoly, __func__);
+	int *poly_groups;
+	int *poly_stack;
 	STACK_DECLARE(poly_stack);
 
 	int poly_prev = 0;
-	int poly_group_id = 1;
+	int poly_group_id = 0;
 
 	/* map vars */
 	MeshElemMap *edge_poly_map;
 	int *edge_poly_mem;
 
+	if (totpoly == 0) {
+		*r_totgroup = 0;
+		return NULL;
+	}
+
 	BKE_mesh_edge_poly_map_create(&edge_poly_map, &edge_poly_mem,
 	                              medge, totedge,
 	                              mpoly, totpoly,
 	                              mloop, totloop);
 
+	poly_groups = MEM_callocN(sizeof(int) * totpoly, __func__);
+	poly_stack  = MEM_mallocN(sizeof(int) * totpoly, __func__);
+
 	STACK_INIT(poly_stack);
 
 	while (true) {
@@ -3243,6 +3257,9 @@
 		/* start searching from here next time */
 		poly_prev = poly + 1;
 
+		/* group starts at 1 */
+		poly_group_id++;
+
 		poly_groups[poly] = poly_group_id;
 		STACK_PUSH(poly_stack, poly);
 
@@ -3273,8 +3290,6 @@
 				}
 			}
 		}
-
-		poly_group_id++;
 	}
 
 	MEM_freeN(edge_poly_map);
@@ -3283,6 +3298,8 @@
 
 	STACK_FREE(poly_stack);
 
+	*r_totgroup = poly_group_id;
+
 	return poly_groups;
 }
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_mesh_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_mesh_api.c	2013-06-14 08:59:21 UTC (rev 57451)
+++ trunk/blender/source/blender/makesrna/intern/rna_mesh_api.c	2013-06-14 09:59:09 UTC (rev 57452)
@@ -44,6 +44,9 @@
 #include "rna_internal.h"  /* own include */
 
 #ifdef RNA_RUNTIME
+
+#include "DNA_mesh_types.h"
+
 static const char *rna_Mesh_unit_test_compare(struct Mesh *mesh, bContext *C, struct Mesh *mesh2)
 {
 	const char *ret = BKE_mesh_cmp(mesh, mesh2, FLT_EPSILON * 60);
@@ -54,6 +57,18 @@
 	return ret;
 }
 
+void rna_Mesh_calc_smooth_groups(struct Mesh *mesh, int *r_poly_group_len, int **r_poly_group, int *r_group_total)
+{
+	int totgroups;
+
+	*r_poly_group_len = mesh->totpoly;
+	*r_poly_group = BKE_mesh_calc_smoothgroups(
+	                    mesh->medge, mesh->totedge,
+	                    mesh->mpoly, mesh->totpoly,
+	                    mesh->mloop, mesh->totloop,
+	                    r_group_total);
+}
+
 #else
 
 void RNA_api_mesh(StructRNA *srna)
@@ -72,6 +87,15 @@
 	func = RNA_def_function(srna, "calc_tessface", "ED_mesh_calc_tessface");
 	RNA_def_function_ui_description(func, "Calculate face tessellation (supports editmode too)");
 
+	func = RNA_def_function(srna, "calc_smooth_groups", "rna_Mesh_calc_smooth_groups");
+	RNA_def_function_ui_description(func, "Calculate smooth groups from sharp edges");
+	/* return values */
+	parm = RNA_def_int_array(func, "poly_groups", 1, NULL, 0, 0, "", "Smooth Groups", 0, 0);
+	RNA_def_property_flag(parm, PROP_DYNAMIC | PROP_OUTPUT);
+	parm = RNA_def_int(func, "groups", 0, 0, INT_MAX, "groups", "Total number of groups", 0, INT_MAX);
+	RNA_def_property_flag(parm, PROP_OUTPUT);
+
+
 	func = RNA_def_function(srna, "update", "ED_mesh_update");
 	RNA_def_boolean(func, "calc_edges", 0, "Calculate Edges", "Force recalculation of edges");
 	RNA_def_boolean(func, "calc_tessface", 0, "Calculate Tessellation", "Force recalculation of tessellation faces");




More information about the Bf-blender-cvs mailing list