diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-04-06 17:24:34 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-04-06 17:24:34 +0400 |
commit | acfc0ea5111bcab5ea5795187d08b2f6ec5addaa (patch) | |
tree | d9fb7e477ac551859ca95c1f0482eca8b3af1077 /source/blender/bmesh/intern | |
parent | 72d0cc1f6123900f5593cd0fe428568f5aa7f682 (diff) | |
parent | 2ed2226ee753cc6a7a19806d99772efa61af897f (diff) |
svn merge ^/trunk/blender -r55815:55840
Diffstat (limited to 'source/blender/bmesh/intern')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_interp.c | 6 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_opdefines.c | 59 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operator_api.h | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.c | 25 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.h | 7 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators_private.h | 4 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.c | 28 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.h | 1 |
8 files changed, 113 insertions, 19 deletions
diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c index d0ab0ea5d60..6edbae0831e 100644 --- a/source/blender/bmesh/intern/bmesh_interp.c +++ b/source/blender/bmesh/intern/bmesh_interp.c @@ -36,12 +36,12 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_customdata.h" -#include "BKE_multires.h" - #include "BLI_array.h" #include "BLI_math.h" +#include "BKE_customdata.h" +#include "BKE_multires.h" + #include "bmesh.h" #include "intern/bmesh_private.h" diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 7583332c4db..a84958f6827 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -1500,12 +1500,34 @@ static BMOpDefine bmo_solidify_def = { }; /* - * Face Inset. + * Face Inset (Individual). * - * Inset or outset faces. + * Insets individual faces. */ -static BMOpDefine bmo_inset_def = { - "inset", +static BMOpDefine bmo_inset_individual_def = { + "inset_individual", + /* slots_in */ + {{"faces", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}}, /* input faces */ + {"thickness", BMO_OP_SLOT_FLT}, + {"depth", BMO_OP_SLOT_FLT}, + {"use_even_offset", BMO_OP_SLOT_BOOL}, + {{'\0'}}, + }, + /* slots_out */ + {{"faces.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}}, /* output faces */ + {{'\0'}}, + }, + bmo_inset_individual_exec, + 0 +}; + +/* + * Face Inset (Regions). + * + * Inset or outset face regions. + */ +static BMOpDefine bmo_inset_region_def = { + "inset_region", /* slots_in */ {{"faces", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}}, /* input faces */ {"use_boundary", BMO_OP_SLOT_BOOL}, @@ -1520,7 +1542,7 @@ static BMOpDefine bmo_inset_def = { {{"faces.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}}, /* output faces */ {{'\0'}}, }, - bmo_inset_exec, + bmo_inset_region_exec, 0 }; @@ -1549,6 +1571,29 @@ static BMOpDefine bmo_wireframe_def = { 0 }; +/* + * Pokes a face. + * + * Splits a face into a triangle fan. + */ +static BMOpDefine bmo_poke_def = { + "poke", + /* slots_in */ + {{"faces", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}}, /* input faces */ + {"offset", BMO_OP_SLOT_FLT}, /* center vertex offset along normal */ + {"center_mode", BMO_OP_SLOT_INT}, /* calculation mode for center vertex */ + {"use_relative_offset", BMO_OP_SLOT_BOOL}, /* apply offset */ + {{'\0'}}, + }, + /* slots_out */ + {{"verts.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT}}, /* output verts */ + {"faces.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}}, /* output faces */ + {{'\0'}}, + }, + bmo_poke_exec, + 0 +}; + #ifdef WITH_BULLET /* * Convex Hull @@ -1647,13 +1692,15 @@ const BMOpDefine *bmo_opdefines[] = { &bmo_extrude_face_region_def, &bmo_extrude_vert_indiv_def, &bmo_find_doubles_def, - &bmo_inset_def, + &bmo_inset_individual_def, + &bmo_inset_region_def, &bmo_join_triangles_def, &bmo_mesh_to_bmesh_def, &bmo_mirror_def, &bmo_object_load_bmesh_def, &bmo_pointmerge_def, &bmo_pointmerge_facedata_def, + &bmo_poke_def, &bmo_recalc_face_normals_def, &bmo_region_extend_def, &bmo_remove_doubles_def, diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h index 180bc53c2e3..c72accbc605 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api.h +++ b/source/blender/bmesh/intern/bmesh_operator_api.h @@ -482,6 +482,8 @@ typedef struct BMOElemMapping { extern const int BMO_OPSLOT_TYPEINFO[BMO_OP_SLOT_TOTAL_TYPES]; +int BMO_opcode_from_opname(const char *opname); + #ifdef __cplusplus } #endif diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index a358623834f..1d20f94c51c 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -47,7 +47,6 @@ static void bmo_flag_layer_free(BMesh *bm); static void bmo_flag_layer_clear(BMesh *bm); static int bmo_name_to_slotcode(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier); static int bmo_name_to_slotcode_check(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier); -static int bmo_opname_to_opcode(const char *opname); static const char *bmo_error_messages[] = { NULL, @@ -145,7 +144,7 @@ static void bmo_op_slots_init(const BMOSlotType *slot_types, BMOpSlot *slot_args */ void BMO_op_init(BMesh *bm, BMOperator *op, const int flag, const char *opname) { - int opcode = bmo_opname_to_opcode(opname); + int opcode = BMO_opcode_from_opname(opname); #ifdef DEBUG BM_ELEM_INDEX_VALIDATE(bm, "pre bmo", opname); @@ -1522,20 +1521,27 @@ static int bmo_name_to_slotcode_check(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], cons return i; } -static int bmo_opname_to_opcode(const char *opname) +int BMO_opcode_from_opname(const char *opname) { - int i; - for (i = 0; i < bmo_opdefines_total; i++) { - if (STREQ(opname, bmo_opdefines[i]->opname)) { + const unsigned int tot = bmo_opdefines_total; + unsigned int i; + for (i = 0; i < tot; i++) { + if (STREQ(bmo_opdefines[i]->opname, opname)) { return i; } } - - fprintf(stderr, "%s: could not find bmesh slot for name %s! (bmesh internal error)\n", __func__, opname); return -1; } +static int BMO_opcode_from_opname_check(const char *opname) +{ + int i = BMO_opcode_from_opname(opname); + if (i == -1) + fprintf(stderr, "%s: could not find bmesh slot for name %s! (bmesh internal error)\n", __func__, opname); + return i; +} + /** * \brief Format Strings for #BMOperator Initialization. * @@ -1628,10 +1634,11 @@ bool BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *_fmt, fmt += i + (noslot ? 0 : 1); - i = bmo_opname_to_opcode(opname); + i = BMO_opcode_from_opname_check(opname); if (i == -1) { MEM_freeN(ofmt); + BLI_assert(0); return false; } diff --git a/source/blender/bmesh/intern/bmesh_operators.h b/source/blender/bmesh/intern/bmesh_operators.h index 16b38c340ff..ff0fc285dc3 100644 --- a/source/blender/bmesh/intern/bmesh_operators.h +++ b/source/blender/bmesh/intern/bmesh_operators.h @@ -95,6 +95,13 @@ enum { VPATH_SELECT_TOPOLOGICAL }; +/* Poke face center calculation */ +enum { + BMOP_POKE_MEAN_WEIGHTED = 0, + BMOP_POKE_MEAN, + BMOP_POKE_BOUNDS +}; + extern const BMOpDefine *bmo_opdefines[]; extern const int bmo_opdefines_total; diff --git a/source/blender/bmesh/intern/bmesh_operators_private.h b/source/blender/bmesh/intern/bmesh_operators_private.h index 79e688bd5ff..2a67407b261 100644 --- a/source/blender/bmesh/intern/bmesh_operators_private.h +++ b/source/blender/bmesh/intern/bmesh_operators_private.h @@ -65,7 +65,8 @@ void bmo_extrude_edge_only_exec(BMesh *bm, BMOperator *op); void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op); void bmo_extrude_vert_indiv_exec(BMesh *bm, BMOperator *op); void bmo_find_doubles_exec(BMesh *bm, BMOperator *op); -void bmo_inset_exec(BMesh *bm, BMOperator *op); +void bmo_inset_individual_exec(BMesh *bm, BMOperator *op); +void bmo_inset_region_exec(BMesh *bm, BMOperator *op); void bmo_join_triangles_exec(BMesh *bm, BMOperator *op); void bmo_mesh_to_bmesh_exec(BMesh *bm, BMOperator *op); void bmo_mirror_exec(BMesh *bm, BMOperator *op); @@ -73,6 +74,7 @@ void bmo_object_load_bmesh_exec(BMesh *bm, BMOperator *op); void bmo_pointmerge_exec(BMesh *bm, BMOperator *op); void bmo_pointmerge_facedata_exec(BMesh *bm, BMOperator *op); void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op); +void bmo_poke_exec(BMesh *bm, BMOperator *op); void bmo_region_extend_exec(BMesh *bm, BMOperator *op); void bmo_remove_doubles_exec(BMesh *bm, BMOperator *op); void bmo_reverse_colors_exec(BMesh *bm, BMOperator *op); diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index d235aaaa622..525dd5b1f9c 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -337,6 +337,34 @@ void BM_face_calc_center_mean(BMFace *f, float r_cent[3]) } /** + * computes the center of a face, using the mean average + * weighted by edge length + */ +void BM_face_calc_center_mean_weighted(BMFace *f, float r_cent[3]) +{ + BMLoop *l_iter; + BMLoop *l_first; + float totw = 0.0f; + float w_prev; + + zero_v3(r_cent); + + + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + w_prev = BM_edge_calc_length(l_iter->prev->e); + do { + const float w_curr = BM_edge_calc_length(l_iter->e); + const float w = (w_curr + w_prev); + madd_v3_v3fl(r_cent, l_iter->v->co, w); + totw += w; + w_prev = w_curr; + } while ((l_iter = l_iter->next) != l_first); + + if (totw != 0.0f) + mul_v3_fl(r_cent, 1.0f / (float) totw); +} + +/** * COMPUTE POLY PLANE * * Projects a set polygon's vertices to diff --git a/source/blender/bmesh/intern/bmesh_polygon.h b/source/blender/bmesh/intern/bmesh_polygon.h index c439a41f672..d857ba77fe7 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.h +++ b/source/blender/bmesh/intern/bmesh_polygon.h @@ -37,6 +37,7 @@ float BM_face_calc_area(BMFace *f); float BM_face_calc_perimeter(BMFace *f); void BM_face_calc_center_bounds(BMFace *f, float center[3]); void BM_face_calc_center_mean(BMFace *f, float center[3]); +void BM_face_calc_center_mean_weighted(BMFace *f, float center[3]); void BM_face_normal_update(BMFace *f); void BM_face_normal_update_vcos(BMesh *bm, BMFace *f, float no[3], |