[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56646] trunk/blender/source/blender/ editors/mesh/mesh_data.c: avoid using BLI_array_* macros for uv reset.

Campbell Barton ideasman42 at gmail.com
Fri May 10 10:08:20 CEST 2013


Revision: 56646
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56646
Author:   campbellbarton
Date:     2013-05-10 08:08:18 +0000 (Fri, 10 May 2013)
Log Message:
-----------
avoid using BLI_array_* macros for uv reset.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/mesh/mesh_data.c

Modified: trunk/blender/source/blender/editors/mesh/mesh_data.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_data.c	2013-05-10 07:57:35 UTC (rev 56645)
+++ trunk/blender/source/blender/editors/mesh/mesh_data.c	2013-05-10 08:08:18 UTC (rev 56646)
@@ -219,109 +219,107 @@
 	}
 }
 
-/* without bContext, called in uvedit */
-void ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum)
+static void mesh_uv_reset_array(float **fuv, const int len)
 {
-	BMEditMesh *em = me->edit_btmesh;
-	MLoopUV *luv;
-	BLI_array_declare(polylengths);
-	int *polylengths = NULL;
-	BLI_array_declare(uvs);
-	float **uvs = NULL;
-	float **fuvs = NULL;
-	int i, j;
+	if (len == 3) {
+		fuv[0][0] = 0.0;
+		fuv[0][1] = 0.0;
 
-	if (em) {
-		/* Collect BMesh UVs */
+		fuv[1][0] = 1.0;
+		fuv[1][1] = 0.0;
 
-		BMFace *efa;
-		BMLoop *l;
-		BMIter iter, liter;
+		fuv[2][0] = 1.0;
+		fuv[2][1] = 1.0;
+	}
+	else if (len == 4) {
+		fuv[0][0] = 0.0;
+		fuv[0][1] = 0.0;
 
-		BLI_assert(CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV));
+		fuv[1][0] = 1.0;
+		fuv[1][1] = 0.0;
 
-		BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-			if (!BM_elem_flag_test(efa, BM_ELEM_SELECT))
-				continue;
+		fuv[2][0] = 1.0;
+		fuv[2][1] = 1.0;
 
-			i = 0;
-			BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
-				luv = CustomData_bmesh_get_n(&em->bm->ldata, l->head.data, CD_MLOOPUV, layernum);
-				BLI_array_append(uvs, luv->uv);
-				i++;
-			}
+		fuv[3][0] = 0.0;
+		fuv[3][1] = 1.0;
+		/*make sure we ignore 2-sided faces*/
+	}
+	else if (len > 2) {
+		float fac = 0.0f, dfac = 1.0f / (float)len;
+		int i;
 
-			BLI_array_append(polylengths, efa->len);
+		dfac *= (float)M_PI * 2.0f;
+
+		for (i = 0; i < len; i++) {
+			fuv[i][0] = 0.5f * sinf(fac) + 0.5f;
+			fuv[i][1] = 0.5f * cosf(fac) + 0.5f;
+
+			fac += dfac;
 		}
 	}
-	else {
-		/* Collect Mesh UVs */
+}
 
-		MPoly *mp;
-		MLoopUV *mloouv;
+static void mesh_uv_reset_bmface(BMFace *f, const int cd_loop_uv_offset)
+{
+	float **fuv = BLI_array_alloca(fuv, f->len);
+	BMIter liter;
+	BMLoop *l;
+	int i;
 
-		BLI_assert(CustomData_has_layer(&me->ldata, CD_MLOOPUV));
-		mloouv = CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, layernum);
+	BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, i) {
+		fuv[i] = ((MLoopUV *)BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset))->uv;
+	}
 
-		for (j = 0; j < me->totpoly; j++) {
-			mp = &me->mpoly[j];
+	mesh_uv_reset_array(fuv, f->len);
+}
 
-			for (i = 0; i < mp->totloop; i++) {
-				luv = &mloouv[mp->loopstart + i];
-				BLI_array_append(uvs, luv->uv);
-			}
+static void mesh_uv_reset_mface(MPoly *mp, MLoopUV *mloopuv)
+{
+	float **fuv = BLI_array_alloca(fuv, mp->totloop);
+	int i;
 
-			BLI_array_append(polylengths, mp->totloop);
-		}
+	for (i = 0; i < mp->totloop; i++) {
+		fuv[i] = mloopuv[mp->loopstart + i].uv;
 	}
 
-	fuvs = uvs;
-	for (j = 0; j < BLI_array_count(polylengths); j++) {
-		int len = polylengths[j];
+	mesh_uv_reset_array(fuv, mp->totloop);
+}
 
-		if (len == 3) {
-			fuvs[0][0] = 0.0;
-			fuvs[0][1] = 0.0;
-			
-			fuvs[1][0] = 1.0;
-			fuvs[1][1] = 0.0;
+/* without bContext, called in uvedit */
+void ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum)
+{
+	BMEditMesh *em = me->edit_btmesh;
 
-			fuvs[2][0] = 1.0;
-			fuvs[2][1] = 1.0;
-		}
-		else if (len == 4) {
-			fuvs[0][0] = 0.0;
-			fuvs[0][1] = 0.0;
-			
-			fuvs[1][0] = 1.0;
-			fuvs[1][1] = 0.0;
+	if (em) {
+		/* Collect BMesh UVs */
+		const int cd_loop_uv_offset = CustomData_get_n_offset(&em->bm->ldata, CD_MLOOPUV, layernum);
 
-			fuvs[2][0] = 1.0;
-			fuvs[2][1] = 1.0;
+		BMFace *efa;
+		BMIter iter;
 
-			fuvs[3][0] = 0.0;
-			fuvs[3][1] = 1.0;
-			/*make sure we ignore 2-sided faces*/
-		}
-		else if (len > 2) {
-			float fac = 0.0f, dfac = 1.0f / (float)len;
+		BLI_assert(cd_loop_uv_offset != -1);
 
-			dfac *= (float)M_PI * 2.0f;
+		BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+			if (!BM_elem_flag_test(efa, BM_ELEM_SELECT))
+				continue;
 
-			for (i = 0; i < len; i++) {
-				fuvs[i][0] = 0.5f * sinf(fac) + 0.5f;
-				fuvs[i][1] = 0.5f * cosf(fac) + 0.5f;
-
-				fac += dfac;
-			}
+			mesh_uv_reset_bmface(efa, cd_loop_uv_offset);
 		}
-
-		fuvs += len;
 	}
+	else {
+		/* Collect Mesh UVs */
+		MLoopUV *mloopuv;
+		int i;
 
-	BLI_array_free(uvs);
-	BLI_array_free(polylengths);
+		BLI_assert(CustomData_has_layer(&me->ldata, CD_MLOOPUV));
+		mloopuv = CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, layernum);
 
+		for (i = 0; i < me->totpoly; i++) {
+			mesh_uv_reset_mface(&me->mpoly[i], mloopuv);
+		}
+	}
+
 	DAG_id_tag_update(&me->id, 0);
 }
 




More information about the Bf-blender-cvs mailing list