Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-06-14 13:59:09 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-06-14 13:59:09 +0400
commit05ad8c2dc9c708580540e7aadb67b900a52e442e (patch)
tree908f03e9797b1f35afd586849c734b1ec64fdaa3
parent49065fcbe8ddd90c3f8053ca87552433ddd1298d (diff)
expose smooth group calculation to python as Mesh.calc_smooth_groups()
-rw-r--r--source/blender/blenkernel/BKE_mesh.h3
-rw-r--r--source/blender/blenkernel/intern/mesh.c31
-rw-r--r--source/blender/makesrna/intern/rna_mesh_api.c24
3 files changed, 50 insertions, 8 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 4f4a5a0c693..edbf4da33ac 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -107,7 +107,8 @@ void BKE_mesh_calc_poly_angles(struct MPoly *mpoly, struct MLoop *loopstart,
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,
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index aa45c8fd0aa..3bb2d6fdba4 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -3203,27 +3203,41 @@ static float mesh_calc_poly_planar_area_centroid(MPoly *mpoly, MLoop *loopstart,
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 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge,
/* 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 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge,
}
}
}
-
- poly_group_id++;
}
MEM_freeN(edge_poly_map);
@@ -3283,6 +3298,8 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge,
STACK_FREE(poly_stack);
+ *r_totgroup = poly_group_id;
+
return poly_groups;
}
diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c
index 696ee8cbfa0..985e8761488 100644
--- a/source/blender/makesrna/intern/rna_mesh_api.c
+++ b/source/blender/makesrna/intern/rna_mesh_api.c
@@ -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 @@ static const char *rna_Mesh_unit_test_compare(struct Mesh *mesh, bContext *C, st
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 @@ void RNA_api_mesh(StructRNA *srna)
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");