[Bf-blender-cvs] [16f49f81dd1] master: Cleanup: 3d view panel median value storage

Campbell Barton noreply at git.blender.org
Sat Jan 5 09:57:21 CET 2019


Commit: 16f49f81dd115ff5323a88309acff194be12609d
Author: Campbell Barton
Date:   Sat Jan 5 12:18:02 2019 +1100
Branches: master
https://developer.blender.org/rB16f49f81dd115ff5323a88309acff194be12609d

Cleanup: 3d view panel median value storage

===================================================================

M	source/blender/editors/space_view3d/view3d_buttons.c

===================================================================

diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c
index 4a66502b438..d68ef5c3fbd 100644
--- a/source/blender/editors/space_view3d/view3d_buttons.c
+++ b/source/blender/editors/space_view3d/view3d_buttons.c
@@ -81,22 +81,49 @@
 
 
 /* ******************* view3d space & buttons ************** */
-#define B_REDR              2
-#define B_OBJECTPANELMEDIAN 1008
-#define B_OBJECTPANEL_DIMS  1009
+enum {
+	B_REDR               = 2,
+	B_TRANSFORM_PANEL_MEDIAN = 1008,
+	B_TRANSFORM_PANEL_DIMS   = 1009,
+};
 
-#define NBR_TRANSFORM_PROPERTIES 8
+/* All must start w/ location */
+
+typedef struct {
+	float location[3];
+} TransformMedian_Generic;
+
+typedef struct {
+	float location[3], bv_weight, be_weight, skin[2], crease;
+} TransformMedian_Mesh;
+
+typedef struct {
+	float location[3], weight, b_weight, radius, tilt;
+} TransformMedian_Curve;
+
+typedef struct {
+	float location[3], weight;
+} TransformMedian_Lattice;
+
+
+typedef union {
+	TransformMedian_Generic generic;
+	TransformMedian_Mesh mesh;
+	TransformMedian_Curve curve;
+	TransformMedian_Lattice lattice;
+} TransformMedian;
 
 /* temporary struct for storing transform properties */
+
 typedef struct {
-	float ob_eul[4];   /* used for quat too... */
-	float ob_scale[3]; /* need temp space due to linked values */
 	float ob_dims_orig[3];
 	float ob_dims[3];
-	short link_scale;
-	float ve_median[NBR_TRANSFORM_PROPERTIES];
+	/* Floats only (treated as an array). */
+	TransformMedian ve_median, median;
 } TransformProperties;
 
+#define TRANSFORM_MEDIAN_ARRAY_LEN (sizeof(TransformMedian) / sizeof(float))
+
 /* Helper function to compute a median changed value,
  * when the value should be clamped in [0.0, 1.0].
  * Returns either 0.0, 1.0 (both can be applied directly), a positive scale factor
@@ -183,39 +210,19 @@ static TransformProperties *v3d_transform_props_ensure(View3D *v3d)
 /* is used for both read and write... */
 static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float lim)
 {
-/* Get rid of those ugly magic numbers, even in a single func they become confusing! */
-/* Location, common to all. */
-/* Next three *must* remain contiguous (used as array)! */
-#define LOC_X        0
-#define LOC_Y        1
-#define LOC_Z        2
-/* Meshes... */
-#define M_BV_WEIGHT  3
-/* Next two *must* remain contiguous (used as array)! */
-#define M_SKIN_X     4
-#define M_SKIN_Y     5
-#define M_BE_WEIGHT  6
-#define M_CREASE     7
-/* Curves... */
-#define C_BWEIGHT    3
-#define C_WEIGHT     4
-#define C_RADIUS     5
-#define C_TILT       6
-/*Lattice... */
-#define L_WEIGHT     4
-
 	uiBlock *block = (layout) ? uiLayoutAbsoluteBlock(layout) : NULL;
 	TransformProperties *tfp = v3d_transform_props_ensure(v3d);
-	float median[NBR_TRANSFORM_PROPERTIES], ve_median[NBR_TRANSFORM_PROPERTIES];
+	TransformMedian median_basis, ve_median_basis;
 	int tot, totedgedata, totcurvedata, totlattdata, totcurvebweight;
 	bool has_meshdata = false;
 	bool has_skinradius = false;
 	PointerRNA data_ptr;
 
-	copy_vn_fl(median, NBR_TRANSFORM_PROPERTIES, 0.0f);
+	copy_vn_fl((float *)&median_basis, TRANSFORM_MEDIAN_ARRAY_LEN, 0.0f);
 	tot = totedgedata = totcurvedata = totlattdata = totcurvebweight = 0;
 
 	if (ob->type == OB_MESH) {
+		TransformMedian_Mesh *median = &median_basis.mesh;
 		Mesh *me = ob->data;
 		BMEditMesh *em = me->edit_btmesh;
 		BMesh *bm = em->bm;
@@ -234,15 +241,15 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 			BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
 				if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
 					tot++;
-					add_v3_v3(&median[LOC_X], eve->co);
+					add_v3_v3(median->location, eve->co);
 
 					if (cd_vert_bweight_offset != -1) {
-						median[M_BV_WEIGHT] += BM_ELEM_CD_GET_FLOAT(eve, cd_vert_bweight_offset);
+						median->bv_weight += BM_ELEM_CD_GET_FLOAT(eve, cd_vert_bweight_offset);
 					}
 
 					if (has_skinradius) {
 						MVertSkin *vs = BM_ELEM_CD_GET_VOID_P(eve, cd_vert_skin_offset);
-						add_v2_v2(&median[M_SKIN_X], vs->radius); /* Third val not used currently. */
+						add_v2_v2(median->skin, vs->radius); /* Third val not used currently. */
 					}
 				}
 			}
@@ -253,11 +260,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 				BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
 					if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
 						if (cd_edge_bweight_offset != -1) {
-							median[M_BE_WEIGHT] += BM_ELEM_CD_GET_FLOAT(eed, cd_edge_bweight_offset);
+							median->be_weight += BM_ELEM_CD_GET_FLOAT(eed, cd_edge_bweight_offset);
 						}
 
 						if (cd_edge_crease_offset != -1) {
-							median[M_CREASE] += BM_ELEM_CD_GET_FLOAT(eed, cd_edge_crease_offset);
+							median->crease += BM_ELEM_CD_GET_FLOAT(eed, cd_edge_crease_offset);
 						}
 
 						totedgedata++;
@@ -272,6 +279,7 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 		has_meshdata = (tot || totedgedata);
 	}
 	else if (ob->type == OB_CURVE || ob->type == OB_SURF) {
+		TransformMedian_Curve *median = &median_basis.curve;
 		Curve *cu = ob->data;
 		Nurb *nu;
 		BPoint *bp;
@@ -288,11 +296,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 				a = nu->pntsu;
 				while (a--) {
 					if (bezt->f2 & SELECT) {
-						add_v3_v3(&median[LOC_X], bezt->vec[1]);
+						add_v3_v3(median->location, bezt->vec[1]);
 						tot++;
-						median[C_WEIGHT] += bezt->weight;
-						median[C_RADIUS] += bezt->radius;
-						median[C_TILT] += bezt->alfa;
+						median->weight += bezt->weight;
+						median->radius += bezt->radius;
+						median->tilt += bezt->alfa;
 						if (!totcurvedata) { /* I.e. first time... */
 							selp = bezt;
 							seltype = &RNA_BezierSplinePoint;
@@ -301,11 +309,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 					}
 					else {
 						if (bezt->f1 & SELECT) {
-							add_v3_v3(&median[LOC_X], bezt->vec[0]);
+							add_v3_v3(median->location, bezt->vec[0]);
 							tot++;
 						}
 						if (bezt->f3 & SELECT) {
-							add_v3_v3(&median[LOC_X], bezt->vec[2]);
+							add_v3_v3(median->location, bezt->vec[2]);
 							tot++;
 						}
 					}
@@ -317,13 +325,13 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 				a = nu->pntsu * nu->pntsv;
 				while (a--) {
 					if (bp->f1 & SELECT) {
-						add_v3_v3(&median[LOC_X], bp->vec);
-						median[C_BWEIGHT] += bp->vec[3];
+						add_v3_v3(median->location, bp->vec);
+						median->b_weight += bp->vec[3];
 						totcurvebweight++;
 						tot++;
-						median[C_WEIGHT] += bp->weight;
-						median[C_RADIUS] += bp->radius;
-						median[C_TILT] += bp->alfa;
+						median->weight += bp->weight;
+						median->radius += bp->radius;
+						median->tilt += bp->alfa;
 						if (!totcurvedata) { /* I.e. first time... */
 							selp = bp;
 							seltype = &RNA_SplinePoint;
@@ -341,6 +349,7 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 	}
 	else if (ob->type == OB_LATTICE) {
 		Lattice *lt = ob->data;
+		TransformMedian_Lattice *median = &median_basis.lattice;
 		BPoint *bp;
 		int a;
 		StructRNA *seltype = NULL;
@@ -350,9 +359,9 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 		bp = lt->editlatt->latt->def;
 		while (a--) {
 			if (bp->f1 & SELECT) {
-				add_v3_v3(&median[LOC_X], bp->vec);
+				add_v3_v3(median->location, bp->vec);
 				tot++;
-				median[L_WEIGHT] += bp->weight;
+				median->weight += bp->weight;
 				if (!totlattdata) { /* I.e. first time... */
 					selp = bp;
 					seltype = &RNA_LatticePoint;
@@ -372,44 +381,48 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 	}
 
 	/* Location, X/Y/Z */
-	mul_v3_fl(&median[LOC_X], 1.0f / (float)tot);
+	mul_v3_fl(median_basis.generic.location, 1.0f / (float)tot);
 	if (v3d->flag & V3D_GLOBAL_STATS)
-		mul_m4_v3(ob->obmat, &median[LOC_X]);
+		mul_m4_v3(ob->obmat, median_basis.generic.location);
 
 	if (has_meshdata) {
+		TransformMedian_Mesh *median = &median_basis.mesh;
 		if (totedgedata) {
-			median[M_CREASE] /= (float)totedgedata;
-			median[M_BE_WEIGHT] /= (float)totedgedata;
+			median->crease /= (float)totedgedata;
+			median->be_weight /= (float)totedgedata;
 		}
 		if (tot) {
-			median[M_BV_WEIGHT] /= (float)tot;
+			median->bv_weight /= (float)tot;
 			if (has_skinradius) {
-				median[M_SKIN_X] /= (float)tot;
-				median[M_SKIN_Y] /= (float)tot;
+				median->skin[0] /= (float)tot;
+				median->skin[1] /= (float)tot;
 			}
 		}
 	}
 	else if (totcurvedata) {
+		TransformMedian_Curve *median = &median_basis.curve;
 		if (totcurvebweight) {
-			median[C_BWEIGHT] /= (float)totcurvebweight;
+			median->b_weight /= (float)totcurvebweight;
 		}
-		median[C_WEIGHT] /= (float)totcurvedata;
-		median[C_RADIUS] /= (float)totcurvedata;
-		median[C_TILT] /= (float)totcurvedata;
+		median->weight /= (float)totcurvedata;
+		median->radius /= (float)totcurvedata;
+		median->tilt /= (float)totcurvedata;
 	}
 	else if (totlattdata) {
-		median[L_WEIGHT] /= (float)totlattdata;
+		TransformMedian_Lattice *median = &median_basis.lattice;
+		median->weight /= (float)totlattdata;
 	}
 
 	if (block) { /* buttons */
 		uiBut *but;
 		int yi = 200;
 		const float tilt_limit = DEG2RADF(21600.0f);
+		const int butw = 200;
 		const int buth = 20 * UI_DPI_FAC;
 		const int but_margin = 2;
 		const char *c;
 
-		memcpy(tfp->ve_median, median, sizeof(tfp->ve_median));
+		memcpy(&tfp->ve_median, &median_basis, sizeof(tfp->ve_median));
 
 		UI_block_align_begin(block);
 		if (tot == 1) {
@@ -420,24 +433,24 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 		}
 		else
 			c = IFACE_("Median:");
-		uiDefBut(block, UI_BTYPE_LABEL, 0, c, 0, yi -= buth, 200, buth, NULL, 0, 0, 0, 0, "");
+		uiDefBut(block, UI_BTYPE_LABEL, 0, c, 0, yi -= buth, butw, buth, NULL, 0, 0, 0, 0, "");
 
 		UI_block_align_begin(block);
 
 		/* Should be no need to translate these. */
-		but = uiDefButF(block, UI_BTYPE_NUM, B_OBJECTPANELMEDIAN, IFACE_("X:"), 0, yi -= buth, 200, buth,


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list