[Bf-blender-cvs] [a2ad1b4e88e] soc-2017-normal-tools: Added invalidate for transform ops.

Rohan Rathi noreply at git.blender.org
Tue Jun 20 19:34:01 CEST 2017


Commit: a2ad1b4e88e155fa0b7457312373c49eeb13754d
Author: Rohan Rathi
Date:   Tue Jun 20 23:03:32 2017 +0530
Branches: soc-2017-normal-tools
https://developer.blender.org/rBa2ad1b4e88e155fa0b7457312373c49eeb13754d

Added invalidate for transform ops.

Can now keep clnors when transform ops are applied. As now invalidation for each function is harder to keep track of, Added a function which rebuilds all the lnor spaces in the mesh when BM_lnorspace_rebuild is called to detect if any unmarked spaces are rebuilt.

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

M	source/blender/bmesh/intern/bmesh_mesh.c
M	source/blender/bmesh/intern/bmesh_mesh.h
M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_ops.c

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

diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index e1d110fb486..f6c5e1d7b17 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -1034,6 +1034,7 @@ void BM_lnorspace_invalidate(BMesh *bm, bool inval_all)
 			}
 		}
 	}
+	bm->spacearr_dirty |= BM_SPACEARR_DIRTY;
 }
 
 void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor)
@@ -1096,6 +1097,10 @@ void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor)
 	}
 	MEM_freeN(oldnors);
 	bm->spacearr_dirty &= ~(BM_SPACEARR_DIRTY | BM_SPACEARR_DIRTY_ALL);
+
+#ifdef DEBUG
+	BM_lnorspace_err(bm);
+#endif
 }
 
 void BM_lnorspace_update(BMesh *bm)
@@ -1114,6 +1119,52 @@ void BM_lnorspace_update(BMesh *bm)
 	MEM_freeN(lnors);
 }
 
+/* Auxillary function only used by rebuild to detect if any spaces were not marked in invalidate.
+   Reports error if any of the lnor spaces change after rebuilding, meaning that the all possible
+   lnor spaces to be rebuilt were not correctly marked */
+static void BM_lnorspace_err(BMesh *bm)
+{
+	bm->spacearr_dirty |= BM_SPACEARR_DIRTY_ALL;
+	bool clear = true;
+
+	MLoopNorSpaceArray *temp = MEM_callocN(sizeof(*temp), "__func__");
+	temp->lspacearr = NULL;
+
+	BKE_lnor_spacearr_init(temp, bm->totloop);
+
+	temp->lspacearr = MEM_callocN(sizeof(MLoopNorSpace *) * bm->totloop, "__func__");
+
+	for (int i = 0; i < bm->totloop; i++) {
+		temp->lspacearr[i] = BKE_lnor_space_create(temp);
+		memcpy(temp->lspacearr[i], bm->lnor_spacearr->lspacearr[i], sizeof(MLoopNorSpace));
+	}
+	
+	int cd_loop_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL);
+	float(*lnors)[3] = MEM_callocN(sizeof(*lnors) * bm->totloop, "__func__");
+	BM_loops_calc_normal_vcos(bm, NULL, NULL, NULL, true, M_PI, lnors, bm->lnor_spacearr, NULL, cd_loop_clnors_offset, true);
+
+	for (int i = 0; i < bm->totloop; i++) {
+		int j = 0;
+		j += compare_ff(temp->lspacearr[i]->ref_alpha, bm->lnor_spacearr->lspacearr[i]->ref_alpha, 1.0f - 1e-4f);
+		j += compare_ff(temp->lspacearr[i]->ref_beta, bm->lnor_spacearr->lspacearr[i]->ref_beta, 1.0f - 1e-4f);
+		j += compare_v3v3(temp->lspacearr[i]->vec_lnor, bm->lnor_spacearr->lspacearr[i]->vec_lnor, 1.0f - 1e-4f);
+		j += compare_v3v3(temp->lspacearr[i]->vec_ortho, bm->lnor_spacearr->lspacearr[i]->vec_ortho, 1.0f - 1e-4f);
+		j += compare_v3v3(temp->lspacearr[i]->vec_ref, bm->lnor_spacearr->lspacearr[i]->vec_ref, 1.0f - 1e-4f);
+
+		if (j != 5) {
+			clear = false;
+			break;
+		}
+	}
+	BKE_lnor_spacearr_free(temp);
+	MEM_freeN(temp);
+	MEM_freeN(lnors);
+	BLI_assert(clear);
+
+	bm->spacearr_dirty &= ~BM_SPACEARR_DIRTY_ALL;
+
+}
+
 int BM_total_loop_select(BMesh *bm)
 {
 	int r_sel = 0;
diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h
index b74394276eb..499be9c0508 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.h
+++ b/source/blender/bmesh/intern/bmesh_mesh.h
@@ -56,6 +56,7 @@ void BM_lnorspacearr_store(BMesh *bm, float (*r_lnors)[3]);
 void BM_lnorspace_invalidate(BMesh *bm, bool inval_all);
 void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor);
 void BM_lnorspace_update(BMesh *bm);
+static void BM_lnorspace_err(BMesh *bm);
 
 /* Loop Generics */
 int BM_total_loop_select(BMesh *bm);
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index a575fe4bfaf..9db0d632d8f 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -150,6 +150,7 @@ int BIF_countTransformOrientation(const struct bContext *C);
 #define P_NO_DEFAULTS   (1 << 10)
 #define P_NO_TEXSPACE   (1 << 11)
 #define P_GPENCIL_EDIT  (1 << 12)
+#define P_CLNOR_INVALIDATE (1 << 13)
 
 void Transform_Properties(struct wmOperatorType *ot, int flags);
 
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index c694a5649df..4f8bcdcf47b 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -88,6 +88,7 @@
 #include "UI_resources.h"
 
 #include "RNA_access.h"
+#include "RNA_define.h"
 
 #include "BLF_api.h"
 #include "BLT_translation.h"
@@ -2392,6 +2393,35 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
 		t->flag |= T_AUTOVALUES;
 	}
 
+	if ((prop = RNA_struct_find_property(op->ptr, "preserve_clnor"))) {
+		if (t->obedit && t->obedit->type == OB_MESH && (((Mesh *)(t->obedit->data))->flag & ME_AUTOSMOOTH)) {
+
+			BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+			RNA_def_property_clear_flag(prop, PROP_HIDDEN);
+			bool all_select = false;
+
+			if (ELEM(t->mode, TFM_TRANSLATION, TFM_ROTATION, TFM_RESIZE)) {
+				if (em->bm->totvertsel == em->bm->totvert) {	//Currently only used for 3 most frequent transform ops, can include more ops		
+					all_select = true;							//No need to invalidate if whole mesh is selected
+				}
+			}
+			if (!all_select) {
+				if (!em->bm->lnor_spacearr) {
+					BM_lnorspace_update(em->bm);
+				}
+				BM_lnorspace_invalidate(em->bm, false);
+
+				if (t->flag & T_MODAL) {
+					RNA_boolean_set(op->ptr, "preserve_clnor", false);
+				}
+				const bool preserve_clnor = RNA_boolean_get(op->ptr, "preserve_clnor");
+				if (preserve_clnor) {
+					t->flag |= T_CLNOR_REBUILD;
+				}
+			}
+		}
+	}
+
 	t->context = NULL;
 
 	return 1;
@@ -2452,6 +2482,10 @@ int transformEnd(bContext *C, TransInfo *t)
 			restoreTransObjects(t); // calls recalcData()
 		}
 		else {
+			if (t->flag & T_CLNOR_REBUILD) {
+				BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+				BM_lnorspace_rebuild(em->bm, true);
+			}
 			exit_code = OPERATOR_FINISHED;
 		}
 
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index c5677182789..3d5d9ddfaa3 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -533,6 +533,8 @@ typedef struct TransInfo {
 	/* alternative transformation. used to add offset to tracking markers */
 #define T_ALT_TRANSFORM		(1 << 24)
 
+#define T_CLNOR_REBUILD		(1 << 25)
+
 /* TransInfo->modifiers */
 #define	MOD_CONSTRAINT_SELECT	0x01
 #define	MOD_PRECISION			0x02
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index bc10b59ee8f..ebf6bcdb15f 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -576,6 +576,11 @@ void Transform_Properties(struct wmOperatorType *ot, int flags)
 		prop = RNA_def_boolean(ot->srna, "use_accurate", 0, "Accurate", "Use accurate transformation");
 		RNA_def_property_flag(prop, PROP_HIDDEN);
 	}
+
+	if (flags & P_CLNOR_INVALIDATE) {
+		prop = RNA_def_boolean(ot->srna, "preserve_clnor", 0, "Keep custom normal", "Keep custom normal during transform");
+		RNA_def_property_flag(prop, PROP_HIDDEN);
+	}
 }
 
 static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
@@ -595,7 +600,7 @@ static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
 
 	RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
 
-	Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS | P_GPENCIL_EDIT);
+	Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS | P_GPENCIL_EDIT | P_CLNOR_INVALIDATE);
 }
 
 static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
@@ -615,7 +620,7 @@ static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
 
 	RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
 
-	Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_GPENCIL_EDIT);
+	Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_GPENCIL_EDIT | P_CLNOR_INVALIDATE);
 }
 
 static int skin_resize_poll(bContext *C)
@@ -666,7 +671,7 @@ static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
 	/* Maybe we could use float_vector_xyz here too? */
 	RNA_def_float_rotation(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
 
-	Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
+	Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CLNOR_INVALIDATE);
 }
 
 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
@@ -686,7 +691,7 @@ static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
 
 	RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
 
-	Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_GPENCIL_EDIT);
+	Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_GPENCIL_EDIT | P_CLNOR_INVALIDATE);
 }
 
 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
@@ -729,7 +734,7 @@ static void TRANSFORM_OT_bend(struct wmOperatorType *ot)
 
 	RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
 
-	Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
+	Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CLNOR_INVALIDATE);
 }
 
 static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
@@ -749,7 +754,7 @@ static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
 
 	RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
 
-	Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
+	Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CLNOR_INVALIDATE);
 	// XXX Shear axis?
 }
 
@@ -770,7 +775,7 @@ static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
 
 	RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
 
-	Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
+	Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_CLNOR_INVALIDATE);
 }
 
 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
@@ -792,7 +797,7 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list