[Bf-blender-cvs] [e38a0b37486] blender2.8: Shrinkwrap Constraint: implement projection features from the modifier.

Alexander Gavrilov noreply at git.blender.org
Mon Oct 1 14:51:07 CEST 2018


Commit: e38a0b3748683a35601c256053f716ad8b57002f
Author: Alexander Gavrilov
Date:   Sun Jul 8 13:47:26 2018 +0300
Branches: blender2.8
https://developer.blender.org/rBe38a0b3748683a35601c256053f716ad8b57002f

Shrinkwrap Constraint: implement projection features from the modifier.

Allow raycasting in two directions and culling front or back faces.

Also implement a new Invert Cull option in both constraint and
modifier that can be used to aim for faces aligned with the project
axis direction when raycasting both ways.

Reviewers: mont29

Differential Revision: https://developer.blender.org/D3737

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

M	release/scripts/startup/bl_ui/properties_constraint.py
M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/intern/constraint.c
M	source/blender/blenkernel/intern/shrinkwrap.c
M	source/blender/makesdna/DNA_constraint_types.h
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_constraint.c
M	source/blender/makesrna/intern/rna_modifier.c

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

diff --git a/release/scripts/startup/bl_ui/properties_constraint.py b/release/scripts/startup/bl_ui/properties_constraint.py
index c76f3255d97..ea3b5f000ec 100644
--- a/release/scripts/startup/bl_ui/properties_constraint.py
+++ b/release/scripts/startup/bl_ui/properties_constraint.py
@@ -758,6 +758,15 @@ class ConstraintButtonsPanel:
             split.label(text="Axis Space:")
             rowsub = split.row()
             rowsub.prop(con, "project_axis_space", text="")
+            split = layout.split(factor=0.4)
+            split.label(text="Face Culling:")
+            rowsub = split.row()
+            rowsub.prop(con, "cull_face", expand=True)
+            row = layout.row()
+            row.prop(con, "use_project_opposite")
+            rowsub = row.row()
+            rowsub.active = con.use_project_opposite and con.cull_face != 'OFF'
+            rowsub.prop(con, "use_invert_cull")
             layout.prop(con, "project_limit")
 
     def DAMPED_TRACK(self, context, layout, con):
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 3e7dce6d34c..b7c2f232102 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -848,6 +848,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
             col.prop(md, "use_negative_direction")
             col.prop(md, "use_positive_direction")
 
+            subcol = col.column()
+            subcol.active = md.use_negative_direction and md.cull_face != 'OFF'
+            subcol.prop(md, "use_invert_cull")
+
             col = split.column()
             col.label(text="Cull Faces:")
             col.prop(md, "cull_face", expand=True)
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index b1a7c98dc9c..575f534c7ca 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -3533,8 +3533,24 @@ static void shrinkwrap_get_tarmat(struct Depsgraph *depsgraph, bConstraint *con,
 						break;
 					}
 
-					if (BKE_shrinkwrap_project_normal(0, co, no, 0.0f, &transform, treeData.tree,
-					                                  &hit, treeData.raycast_callback, &treeData) == false)
+					char cull_mode = scon->flag & CON_SHRINKWRAP_PROJECT_CULL_MASK;
+
+					BKE_shrinkwrap_project_normal(cull_mode, co, no, 0.0f, &transform, treeData.tree,
+					                              &hit, treeData.raycast_callback, &treeData);
+
+					if (scon->flag & CON_SHRINKWRAP_PROJECT_OPPOSITE) {
+						float inv_no[3];
+						negate_v3_v3(inv_no, no);
+
+						if ((scon->flag & CON_SHRINKWRAP_PROJECT_INVERT_CULL) && (cull_mode != 0)) {
+							cull_mode ^= CON_SHRINKWRAP_PROJECT_CULL_MASK;
+						}
+
+						BKE_shrinkwrap_project_normal(cull_mode, co, inv_no, 0.0f, &transform, treeData.tree,
+						                              &hit, treeData.raycast_callback, &treeData);
+					}
+
+					if (hit.index < 0)
 					{
 						fail = true;
 						break;
diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c
index 21b21d6ddd8..5408c07adf1 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.c
+++ b/source/blender/blenkernel/intern/shrinkwrap.c
@@ -240,7 +240,7 @@ bool BKE_shrinkwrap_project_normal(
 			BLI_space_transform_invert_normal(transf, hit_tmp.no);
 		}
 
-		if (options & (MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE | MOD_SHRINKWRAP_CULL_TARGET_BACKFACE)) {
+		if (options & MOD_SHRINKWRAP_CULL_TARGET_MASK) {
 			/* apply backface */
 			const float dot = dot_v3v3(dir, hit_tmp.no);
 			if (((options & MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE) && dot <= 0.0f) ||
@@ -341,6 +341,12 @@ static void shrinkwrap_calc_normal_projection_cb_ex(
 		float inv_no[3];
 		negate_v3_v3(inv_no, tmp_no);
 
+		char options = calc->smd->shrinkOpts;
+
+		if ((options & MOD_SHRINKWRAP_INVERT_CULL_TARGET) && (options & MOD_SHRINKWRAP_CULL_TARGET_MASK)) {
+			options ^= MOD_SHRINKWRAP_CULL_TARGET_MASK;
+		}
+
 		if (aux_tree) {
 			BKE_shrinkwrap_project_normal(
 			        0, tmp_co, inv_no, 0.0,
@@ -349,7 +355,7 @@ static void shrinkwrap_calc_normal_projection_cb_ex(
 		}
 
 		BKE_shrinkwrap_project_normal(
-		        calc->smd->shrinkOpts, tmp_co, inv_no, 0.0,
+		        options, tmp_co, inv_no, 0.0,
 		        &calc->local2target, targ_tree, hit,
 		        targ_callback, treeData);
 	}
diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h
index e7d9e1fa7dd..a92899deaa8 100644
--- a/source/blender/makesdna/DNA_constraint_types.h
+++ b/source/blender/makesdna/DNA_constraint_types.h
@@ -429,7 +429,8 @@ typedef struct bShrinkwrapConstraint {
 	char		projAxisSpace;	/* space to project axis in */
 	float		projLimit;		/* distance to search */
 	char		shrinkMode;		/* inside/outside/on surface (see MOD shrinkwrap) */
-	char 		pad[3];
+	char		flag;			/* options */
+	char 		pad[2];
 } bShrinkwrapConstraint;
 
 /* Follow Track constraints */
@@ -635,6 +636,21 @@ typedef enum eTrackToAxis_Modes {
 	TRACK_nZ	= 5
 } eTrackToAxis_Modes;
 
+/* Shrinkwrap flags */
+typedef enum eShrinkwrap_Flags {
+	/* Also raycast in the opposite direction. */
+	CON_SHRINKWRAP_PROJECT_OPPOSITE     	= (1 << 0),
+	/* Invert the cull mode when projecting opposite. */
+	CON_SHRINKWRAP_PROJECT_INVERT_CULL  	= (1 << 1),
+
+	/* Ignore front faces in project; same value as MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE */
+	CON_SHRINKWRAP_PROJECT_CULL_FRONTFACE	= (1 << 3),
+	/* Ignore back faces in project; same value as MOD_SHRINKWRAP_CULL_TARGET_BACKFACE */
+	CON_SHRINKWRAP_PROJECT_CULL_BACKFACE	= (1 << 4),
+} eShrinkwrap_Flags;
+
+#define CON_SHRINKWRAP_PROJECT_CULL_MASK (CON_SHRINKWRAP_PROJECT_CULL_FRONTFACE | CON_SHRINKWRAP_PROJECT_CULL_BACKFACE)
+
 /* FollowPath flags */
 typedef enum eFollowPath_Flags {
 	FOLLOWPATH_FOLLOW	= (1<<0),
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 811373e626c..9f7b09b4a18 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -920,8 +920,11 @@ enum {
 #endif
 
 	MOD_SHRINKWRAP_INVERT_VGROUP         = (1 << 6),
+	MOD_SHRINKWRAP_INVERT_CULL_TARGET    = (1 << 7),
 };
 
+#define MOD_SHRINKWRAP_CULL_TARGET_MASK (MOD_SHRINKWRAP_CULL_TARGET_FRONTFACE | MOD_SHRINKWRAP_CULL_TARGET_BACKFACE)
+
 /* Shrinkwrap->projAxis */
 enum {
 	MOD_SHRINKWRAP_PROJECT_OVER_NORMAL   = 0,        /* projection over normal is used if no axis is selected */
diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c
index 39966983a8a..ba87d08fdac 100644
--- a/source/blender/makesrna/intern/rna_constraint.c
+++ b/source/blender/makesrna/intern/rna_constraint.c
@@ -396,6 +396,20 @@ static void rna_SplineIKConstraint_joint_bindings_set(PointerRNA *ptr, const flo
 	memcpy(ikData->points, values, ikData->numpoints * sizeof(float));
 }
 
+static int rna_ShrinkwrapConstraint_face_cull_get(PointerRNA *ptr)
+{
+	bConstraint *con = (bConstraint *)ptr->data;
+	bShrinkwrapConstraint *swc = (bShrinkwrapConstraint *)con->data;
+	return swc->flag & CON_SHRINKWRAP_PROJECT_CULL_MASK;
+}
+
+static void rna_ShrinkwrapConstraint_face_cull_set(struct PointerRNA *ptr, int value)
+{
+	bConstraint *con = (bConstraint *)ptr->data;
+	bShrinkwrapConstraint *swc = (bShrinkwrapConstraint *)con->data;
+	swc->flag = (swc->flag & ~CON_SHRINKWRAP_PROJECT_CULL_MASK) | value;
+}
+
 static bool rna_Constraint_cameraObject_poll(PointerRNA *ptr, PointerRNA value)
 {
 	Object *ob = (Object *)value.data;
@@ -1916,6 +1930,13 @@ static void rna_def_constraint_shrinkwrap(BlenderRNA *brna)
 		{0, NULL, 0, NULL, NULL}
 	};
 
+	static const EnumPropertyItem shrink_face_cull_items[] = {
+		{0, "OFF", 0, "Off", "No culling"},
+		{CON_SHRINKWRAP_PROJECT_CULL_FRONTFACE, "FRONT", 0, "Front", "No projection when in front of the face"},
+		{CON_SHRINKWRAP_PROJECT_CULL_BACKFACE, "BACK", 0, "Back", "No projection when behind the face"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	srna = RNA_def_struct(brna, "ShrinkwrapConstraint", "Constraint");
 	RNA_def_struct_ui_text(srna, "Shrinkwrap Constraint", "Create constraint-based shrinkwrap relationship");
 	RNA_def_struct_sdna_from(srna, "bShrinkwrapConstraint", "data");
@@ -1965,6 +1986,25 @@ static void rna_def_constraint_shrinkwrap(BlenderRNA *brna)
 	RNA_def_property_ui_range(prop, 0.0f, 100.0f, 10, 3);
 	RNA_def_property_ui_text(prop, "Project Distance", "Limit the distance used for projection (zero disables)");
 	RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
+
+	prop = RNA_def_property(srna, "use_project_opposite", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", CON_SHRINKWRAP_PROJECT_OPPOSITE);
+	RNA_def_property_ui_text(prop, "Project Opposite", "Project in both specified and opposite directions");
+	RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
+
+	prop = RNA_def_property(srna, "cull_face", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "flag");
+	RNA_def_property_enum_items(prop, shrink_face_cull_items);
+	RNA_def_property_enum_funcs(prop, "rna_ShrinkwrapConstraint_face_cull_get",
+	                            "rna_ShrinkwrapConstraint_face_cull_set", NULL);
+	RNA_def_property_ui_text(prop, "Face Cull",
+	                         "Stop vertices from projecting to a face on the target when facing towards/away");
+	RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
+
+	prop = RNA_def_property(srna, "use_invert_cull", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", CON_SHRINKWRAP_PROJECT_INVERT_CULL);
+	RNA_def_property_ui_text(prop, "Invert Cull", "When projecting in the opposite direction invert the face cull mode");
+	RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
 }
 
 static void rna_def_constraint_damped_track(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
ind

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list