[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56710] trunk/blender/source/blender/bmesh /operators/bmo_utils.c: remove BLI_array allocations from uv/color reverse, rotate.
Campbell Barton
ideasman42 at gmail.com
Sun May 12 16:45:09 CEST 2013
Revision: 56710
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56710
Author: campbellbarton
Date: 2013-05-12 14:45:09 +0000 (Sun, 12 May 2013)
Log Message:
-----------
remove BLI_array allocations from uv/color reverse, rotate.
Modified Paths:
--------------
trunk/blender/source/blender/bmesh/operators/bmo_utils.c
Modified: trunk/blender/source/blender/bmesh/operators/bmo_utils.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_utils.c 2013-05-12 14:21:24 UTC (rev 56709)
+++ trunk/blender/source/blender/bmesh/operators/bmo_utils.c 2013-05-12 14:45:09 UTC (rev 56710)
@@ -479,9 +479,10 @@
BMIter l_iter; /* iteration loop */
const bool use_ccw = BMO_slot_bool_get(op->slots_in, "use_ccw");
+ const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
- BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) {
- if (CustomData_has_layer(&(bm->ldata), CD_MLOOPUV)) {
+ if (cd_loop_uv_offset != -1) {
+ BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) {
if (use_ccw == false) { /* same loops direction */
BMLoop *lf; /* current face loops */
MLoopUV *f_luv; /* first face loop uv */
@@ -491,7 +492,7 @@
int n = 0;
BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
/* current loop uv is the previous loop uv */
- MLoopUV *luv = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPUV);
+ MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(lf, cd_loop_uv_offset);
if (n == 0) {
f_luv = luv;
copy_v2_v2(p_uv, luv->uv);
@@ -515,7 +516,7 @@
int n = 0;
BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
/* previous loop uv is the current loop uv */
- luv = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPUV);
+ luv = BM_ELEM_CD_GET_VOID_P(lf, cd_loop_uv_offset);
if (n == 0) {
p_luv = luv;
copy_v2_v2(t_uv, luv->uv);
@@ -537,39 +538,37 @@
* Reverse UVs for a face
**************************************************************************** */
-void bmo_reverse_uvs_exec(BMesh *bm, BMOperator *op)
+static void bm_face_reverse_uvs(BMFace *f, const int cd_loop_uv_offset)
{
- BMOIter fs_iter; /* selected faces iterator */
- BMFace *fs; /* current face */
- BMIter l_iter; /* iteration loop */
- BLI_array_declare(uvs);
- float (*uvs)[2] = NULL;
+ BMIter iter;
+ BMLoop *l;
+ int i;
- BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) {
- if (CustomData_has_layer(&(bm->ldata), CD_MLOOPUV)) {
- BMLoop *lf; /* current face loops */
- int i;
+ float (*uvs)[2] = BLI_array_alloca(uvs, f->len);
- BLI_array_empty(uvs);
- BLI_array_grow_items(uvs, fs->len);
+ BM_ITER_ELEM_INDEX (l, &iter, f, BM_LOOPS_OF_FACE, i) {
+ MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ copy_v2_v2(uvs[i], luv->uv);
+ }
- BM_ITER_ELEM_INDEX (lf, &l_iter, fs, BM_LOOPS_OF_FACE, i) {
- MLoopUV *luv = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPUV);
+ /* now that we have the uvs in the array, reverse! */
+ BM_ITER_ELEM_INDEX (l, &iter, f, BM_LOOPS_OF_FACE, i) {
+ /* current loop uv is the previous loop uv */
+ MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ copy_v2_v2(luv->uv, uvs[(f->len - i - 1)]);
+ }
+}
+void bmo_reverse_uvs_exec(BMesh *bm, BMOperator *op)
+{
+ BMOIter iter;
+ BMFace *f;
+ const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
- /* current loop uv is the previous loop uv */
- copy_v2_v2(uvs[i], luv->uv);
- }
-
- /* now that we have the uvs in the array, reverse! */
- BM_ITER_ELEM_INDEX (lf, &l_iter, fs, BM_LOOPS_OF_FACE, i) {
- /* current loop uv is the previous loop uv */
- MLoopUV *luv = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPUV);
- copy_v2_v2(luv->uv, uvs[(fs->len - i - 1)]);
- }
+ if (cd_loop_uv_offset != -1) {
+ BMO_ITER (f, &iter, op->slots_in, "faces", BM_FACE) {
+ bm_face_reverse_uvs(f, cd_loop_uv_offset);
}
}
-
- BLI_array_free(uvs);
}
/**************************************************************************** *
@@ -583,9 +582,10 @@
BMIter l_iter; /* iteration loop */
const bool use_ccw = BMO_slot_bool_get(op->slots_in, "use_ccw");
+ const int cd_loop_color_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPCOL);
- BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) {
- if (CustomData_has_layer(&(bm->ldata), CD_MLOOPCOL)) {
+ if (cd_loop_color_offset != -1) {
+ BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) {
if (use_ccw == false) { /* same loops direction */
BMLoop *lf; /* current face loops */
MLoopCol *f_lcol; /* first face loop color */
@@ -595,14 +595,14 @@
int n = 0;
BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
/* current loop color is the previous loop color */
- MLoopCol *luv = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL);
+ MLoopCol *lcol = BM_ELEM_CD_GET_VOID_P(lf, cd_loop_color_offset);
if (n == 0) {
- f_lcol = luv;
- p_col = *luv;
+ f_lcol = lcol;
+ p_col = *lcol;
}
else {
- t_col = *luv;
- *luv = p_col;
+ t_col = *lcol;
+ *lcol = p_col;
p_col = t_col;
}
n++;
@@ -619,7 +619,7 @@
int n = 0;
BM_ITER_ELEM (lf, &l_iter, fs, BM_LOOPS_OF_FACE) {
/* previous loop color is the current loop color */
- lcol = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL);
+ lcol = BM_ELEM_CD_GET_VOID_P(lf, cd_loop_color_offset);
if (n == 0) {
p_lcol = lcol;
t_col = *lcol;
@@ -640,37 +640,37 @@
/*************************************************************************** *
* Reverse colors for a face
*************************************************************************** */
-
-void bmo_reverse_colors_exec(BMesh *bm, BMOperator *op)
+static void bm_face_reverse_colors(BMFace *f, const int cd_loop_color_offset)
{
- BMOIter fs_iter; /* selected faces iterator */
- BMFace *fs; /* current face */
- BMIter l_iter; /* iteration loop */
- BLI_array_declare(cols);
- MLoopCol *cols = NULL;
+ BMIter iter;
+ BMLoop *l;
+ int i;
- BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) {
- if (CustomData_has_layer(&(bm->ldata), CD_MLOOPCOL)) {
- BMLoop *lf; /* current face loops */
- int i;
+ MLoopCol *cols = BLI_array_alloca(cols, f->len);
- BLI_array_empty(cols);
- BLI_array_grow_items(cols, fs->len);
+ BM_ITER_ELEM_INDEX (l, &iter, f, BM_LOOPS_OF_FACE, i) {
+ MLoopCol *lcol = BM_ELEM_CD_GET_VOID_P(l, cd_loop_color_offset);
+ cols[i] = *lcol;
+ }
- BM_ITER_ELEM_INDEX (lf, &l_iter, fs, BM_LOOPS_OF_FACE, i) {
- cols[i] = *((MLoopCol *)CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL));
- }
+ /* now that we have the uvs in the array, reverse! */
+ BM_ITER_ELEM_INDEX (l, &iter, f, BM_LOOPS_OF_FACE, i) {
+ /* current loop uv is the previous loop color */
+ MLoopCol *lcol = BM_ELEM_CD_GET_VOID_P(l, cd_loop_color_offset);
+ *lcol = cols[(f->len - i - 1)];
+ }
+}
+void bmo_reverse_colors_exec(BMesh *bm, BMOperator *op)
+{
+ BMOIter iter;
+ BMFace *f;
+ const int cd_loop_color_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPCOL);
- /* now that we have the uvs in the array, reverse! */
- BM_ITER_ELEM_INDEX (lf, &l_iter, fs, BM_LOOPS_OF_FACE, i) {
- /* current loop uv is the previous loop color */
- MLoopCol *lcol = CustomData_bmesh_get(&bm->ldata, lf->head.data, CD_MLOOPCOL);
- *lcol = cols[(fs->len - i - 1)];
- }
+ if (cd_loop_color_offset != -1) {
+ BMO_ITER (f, &iter, op->slots_in, "faces", BM_FACE) {
+ bm_face_reverse_colors(f, cd_loop_color_offset);
}
}
-
- BLI_array_free(cols);
}
More information about the Bf-blender-cvs
mailing list