From 56771becd0fefd1102795cb4c9c82b53f2ed7d2e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 13 Mar 2013 05:33:23 +0000 Subject: [PATCH] code cleanup: remove bmesh subdivide header, all definitions can be included in bmo_subdivide.c. also only initialize random numbers when fractal option is set. --- source/blender/bmesh/CMakeLists.txt | 1 - .../blender/bmesh/operators/bmo_subdivide.c | 59 ++++++++++++--- .../blender/bmesh/operators/bmo_subdivide.h | 72 ------------------- 3 files changed, 51 insertions(+), 81 deletions(-) delete mode 100644 source/blender/bmesh/operators/bmo_subdivide.h diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt index aa1fb2dda46..16e271e5d58 100644 --- a/source/blender/bmesh/CMakeLists.txt +++ b/source/blender/bmesh/CMakeLists.txt @@ -57,7 +57,6 @@ set(SRC operators/bmo_smooth_laplacian.c operators/bmo_symmetrize.c operators/bmo_subdivide.c - operators/bmo_subdivide.h operators/bmo_triangulate.c operators/bmo_unsubdivide.c operators/bmo_utils.c diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index edd7b50b9a3..88e903c1651 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -40,7 +40,47 @@ #include "intern/bmesh_operators_private.h" /* own include */ -#include "bmo_subdivide.h" /* own include */ +typedef struct SubDParams { + int numcuts; + float smooth; + float fractal; + float along_normal; + //int beauty; + bool use_smooth; + bool use_sphere; + bool use_fractal; + int seed; + int origkey; /* shapekey holding displaced vertex coordinates for current geometry */ + BMOperator *op; + BMOpSlot *slot_edge_percents; /* BMO_slot_get(params->op->slots_in, "edge_percents"); */ + BMOpSlot *slot_custom_patterns; /* BMO_slot_get(params->op->slots_in, "custom_patterns"); */ + float fractal_ofs[3]; +} SubDParams; + +typedef void (*subd_pattern_fill_fp)(BMesh *bm, BMFace *face, BMVert **verts, + const SubDParams *params); + +/* + * note: this is a pattern-based edge subdivider. + * it tries to match a pattern to edge selections on faces, + * then executes functions to cut them. + */ +typedef struct SubDPattern { + int seledges[20]; /* selected edges mask, for splitting */ + + /* verts starts at the first new vert cut, not the first vert in the face */ + subd_pattern_fill_fp connectexec; + int len; /* total number of verts, before any subdivision */ +} SubDPattern; + +/* generic subdivision rules: + * + * - two selected edges in a face should make a link + * between them. + * + * - one edge should do, what? make pretty topology, or just + * split the edge only? + */ /* flags for all elements share a common bitfield space */ #define SUBD_SPLIT 1 @@ -151,7 +191,7 @@ static void alter_co(BMesh *bm, BMVert *v, BMEdge *UNUSED(origed), const SubDPar mid_v3_v3v3(normal, vsta->no, vend->no); ortho_basis_v3v3_v3(base1, base2, normal); - add_v3_v3v3(co2, v->co, params->off); + add_v3_v3v3(co2, v->co, params->fractal_ofs); mul_v3_fl(co2, 10.0f); tvec[0] = fac * (BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 2) - 0.5f); @@ -731,9 +771,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) use_grid_fill = BMO_slot_bool_get(op->slots_in, "use_grid_fill"); use_only_quads = BMO_slot_bool_get(op->slots_in, "use_only_quads"); use_sphere = BMO_slot_bool_get(op->slots_in, "use_sphere"); - - BLI_srandom(seed); - + patterns[1] = NULL; /* straight cut is patterns[1] == NULL */ switch (cornertype) { @@ -790,9 +828,14 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) params.use_fractal = (fractal != 0.0f); params.use_sphere = use_sphere; params.origkey = skey; - params.off[0] = (float)BLI_drand() * 200.0f; - params.off[1] = (float)BLI_drand() * 200.0f; - params.off[2] = (float)BLI_drand() * 200.0f; + + if (params.use_fractal) { + BLI_srandom(seed); + + params.fractal_ofs[0] = (float)BLI_drand() * 200.0f; + params.fractal_ofs[1] = (float)BLI_drand() * 200.0f; + params.fractal_ofs[2] = (float)BLI_drand() * 200.0f; + } BMO_slot_map_to_flag(bm, op->slots_in, "custom_patterns", BM_FACE, FACE_CUSTOMFILL); diff --git a/source/blender/bmesh/operators/bmo_subdivide.h b/source/blender/bmesh/operators/bmo_subdivide.h deleted file mode 100644 index 529075aab02..00000000000 --- a/source/blender/bmesh/operators/bmo_subdivide.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Contributor(s): Joseph Eagar. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/bmesh/operators/bmo_subdivide.h - * \ingroup bmesh - */ - -#ifndef __BMO_SUBDIVIDE_H__ -#define __BMO_SUBDIVIDE_H__ - -typedef struct SubDParams { - int numcuts; - float smooth; - float fractal; - float along_normal; - //int beauty; - short use_smooth; - short use_sphere; - short use_fractal; - int seed; - int origkey; /* shapekey holding displaced vertex coordinates for current geometry */ - BMOperator *op; - BMOpSlot *slot_edge_percents; /* BMO_slot_get(params->op->slots_in, "edge_percents"); */ - BMOpSlot *slot_custom_patterns; /* BMO_slot_get(params->op->slots_in, "custom_patterns"); */ - float off[3]; -} SubDParams; - -typedef void (*subd_pattern_fill_fp)(BMesh *bm, BMFace *face, BMVert **verts, - const SubDParams *params); - -/* - * note: this is a pattern-based edge subdivider. - * it tries to match a pattern to edge selections on faces, - * then executes functions to cut them. - */ -typedef struct SubDPattern { - int seledges[20]; /* selected edges mask, for splitting */ - - /* verts starts at the first new vert cut, not the first vert in the face */ - subd_pattern_fill_fp connectexec; - int len; /* total number of verts, before any subdivision */ -} SubDPattern; - -/* generic subdivision rules: - * - * - two selected edges in a face should make a link - * between them. - * - * - one edge should do, what? make pretty topology, or just - * split the edge only? - */ - -#endif /* __BMO_SUBDIVIDE_H__ */