[Bf-blender-cvs] [b574bd6] transform-manipulators: Finish basic transform manipulators for translate

Julian Eisel noreply at git.blender.org
Thu Oct 20 01:20:54 CEST 2016


Commit: b574bd6cf74dd2d4515d7da0c6a620eb9e87f837
Author: Julian Eisel
Date:   Thu Oct 20 01:18:30 2016 +0200
Branches: transform-manipulators
https://developer.blender.org/rBb574bd6cf74dd2d4515d7da0c6a620eb9e87f837

Finish basic transform manipulators for translate

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

M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/space_view3d/view3d_transform_manipulators.c
M	source/blender/editors/transform/transform_orientations.c
M	source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c

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

diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index f5e28df..06d73c9 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -1040,6 +1040,7 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
 		case NC_GPENCIL:
 			if (wmn->data == ND_DATA || ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
 				ED_region_tag_redraw(ar);
+				WM_manipulatormap_tag_refresh(mmap);
 			}
 			break;
 	}
diff --git a/source/blender/editors/space_view3d/view3d_transform_manipulators.c b/source/blender/editors/space_view3d/view3d_transform_manipulators.c
index 1b214e4..8898d49 100644
--- a/source/blender/editors/space_view3d/view3d_transform_manipulators.c
+++ b/source/blender/editors/space_view3d/view3d_transform_manipulators.c
@@ -22,15 +22,20 @@
  *  \ingroup spview3d
  */
 
-#include "BKE_context.h"
 
 #include "BLI_math.h"
 
+#include "BKE_action.h"
+#include "BKE_context.h"
+
+#include "DNA_armature_types.h"
+#include "DNA_gpencil_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_view3d_types.h"
 
+#include "ED_armature.h"
 #include "ED_transform.h"
 
 #include "MEM_guardedalloc.h"
@@ -46,7 +51,7 @@
 
 
 /* axes as index */
-enum {
+enum TransformAxisType {
 	MAN_AXIS_TRANS_X = 0,
 	MAN_AXIS_TRANS_Y,
 	MAN_AXIS_TRANS_Z,
@@ -75,24 +80,22 @@ enum {
 	MAN_AXIS_LAST,
 };
 
-/* axis types */
-enum {
+enum TransformType {
 	MAN_AXES_ALL = 0,
 	MAN_AXES_TRANSLATE,
 	MAN_AXES_ROTATE,
 	MAN_AXES_SCALE,
 };
 
-enum {
-	MAN_CONSTRAINT_X = (1 << 0),
-	MAN_CONSTRAINT_Y = (1 << 1),
-	MAN_CONSTRAINT_Z = (1 << 2),
-};
+/* threshold for testing view aligned manipulator axis */
+#define TW_AXIS_DOT_MIN 0.02f
+#define TW_AXIS_DOT_MAX 0.1f
 
 typedef struct TranformAxisManipulator {
 	/* -- initialized using static array -- */
 
-	int index, type;
+	enum TransformAxisType index;
+	enum TransformType type;
 
 	const char *name;
 	/* op info */
@@ -102,6 +105,7 @@ typedef struct TranformAxisManipulator {
 	/* appearance */
 	int theme_colorid;
 	int manipulator_type;
+	int protectflag; /* the protectflags this axis checks (e.g. OB_LOCK_LOCZ) */
 
 
 	/* -- initialized later -- */
@@ -110,6 +114,15 @@ typedef struct TranformAxisManipulator {
 } TranformAxisManipulator;
 
 /**
+ * Struct for carrying data of transform manipulators as wmManipulatorGroup.customdata.
+ */
+typedef struct TransformManipulatorsInfo {
+	TranformAxisManipulator *axes; /* Array of axes */
+
+	float mat[4][4]; /* Cached loc/rot matrix */
+} TransformManipulatorsInfo;
+
+/**
  * This TranformAxisManipulator array contains all the info we need to initialize, store and identify all
  * transform manipulators. When creating a new group instance we simply create an allocated version of this.
  *
@@ -119,23 +132,35 @@ static TranformAxisManipulator tman_axes[] = {
 	{
 		MAN_AXIS_TRANS_X, MAN_AXES_TRANSLATE,
 		"translate_x", "TRANSFORM_OT_translate", {1, 0, 0},
-		TH_AXIS_X, MANIPULATOR_ARROW_STYLE_NORMAL,
+		TH_AXIS_X, MANIPULATOR_ARROW_STYLE_NORMAL, OB_LOCK_LOCX,
 	},
 	{
 		MAN_AXIS_TRANS_Y, MAN_AXES_TRANSLATE,
 		"translate_y", "TRANSFORM_OT_translate", {0, 1, 0},
-		TH_AXIS_Y, MANIPULATOR_ARROW_STYLE_NORMAL,
+		TH_AXIS_Y, MANIPULATOR_ARROW_STYLE_NORMAL, OB_LOCK_LOCY,
 	},
 	{
 		MAN_AXIS_TRANS_Z, MAN_AXES_TRANSLATE,
 		"translate_z", "TRANSFORM_OT_translate", {0, 0, 1},
-		TH_AXIS_Z, MANIPULATOR_ARROW_STYLE_NORMAL,
+		TH_AXIS_Z, MANIPULATOR_ARROW_STYLE_NORMAL, OB_LOCK_LOCZ,
 	},
 	{0, 0, NULL}
 };
 
 
 /* -------------------------------------------------------------------- */
+/* General helpers */
+
+static void transform_manipulators_info_free(void *customdata)
+{
+	TransformManipulatorsInfo *info = customdata;
+
+	MEM_freeN(info->axes);
+	MEM_freeN(info);
+}
+
+
+/* -------------------------------------------------------------------- */
 /* init callback and helpers */
 
 /**
@@ -162,35 +187,143 @@ static void transform_axis_manipulator_init(TranformAxisManipulator *axis, wmMan
 
 static void transform_manipulatorgroup_init(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
 {
-	TranformAxisManipulator *axes = MEM_callocN(sizeof(tman_axes), __func__);
+	TransformManipulatorsInfo *info = MEM_callocN(sizeof(*info), __func__);
 
-	memcpy(axes, tman_axes, sizeof(tman_axes));
+	info->axes = MEM_callocN(sizeof(tman_axes), STRINGIFY(TranformAxisManipulator));
+	memcpy(info->axes, tman_axes, sizeof(tman_axes));
 
-	for (int i = 0; i < MAN_AXIS_LAST && axes[i].name; i++) {
-		transform_axis_manipulator_init(&axes[i], mgroup);
+	TranformAxisManipulator *axis;
+	for (int i = 0; i < MAN_AXIS_LAST && info->axes[i].name; i++) {
+		axis = &info->axes[i];
+
+		transform_axis_manipulator_init(axis, mgroup);
 	}
 
-	mgroup->customdata = axes;
+	mgroup->customdata = info;
+	mgroup->customdata_free = transform_manipulators_info_free;
 }
 
 
 /* -------------------------------------------------------------------- */
 /* refresh callback and helpers */
 
-static void transform_axis_manipulator_set_color(TranformAxisManipulator *axis)
+static bool transfrom_axis_manipulator_is_visible(TranformAxisManipulator *axis, int protectflag)
 {
-	/* alpha values for normal/highlighted states */
-	const float alpha = 0.6f;
-	const float alpha_hi = 1.0f;
-	float col[4], col_hi[4];
+	return ((axis->protectflag & protectflag) != axis->protectflag);
+}
 
-	UI_GetThemeColor4fv(axis->theme_colorid, col);
-	copy_v4_v4(col_hi, col);
+static int transform_manipulators_protectflag_posemode_get(Object *ob, View3D *v3d)
+{
+	bPoseChannel *pchan;
+	int protectflag = 0;
 
-	col[3] = alpha;
-	col_hi[3] = alpha_hi;
+	if ((v3d->around == V3D_AROUND_ACTIVE) && (pchan = BKE_pose_channel_active(ob))) {
+		if (pchan->bone) {
+			protectflag = pchan->protectflag;
+		}
+	}
+	else {
+		/* use channels to get stats */
+		for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+			Bone *bone = pchan->bone;
+			if (bone && (bone->flag & BONE_TRANSFORM)) {
+				protectflag |= pchan->protectflag;
+			}
+		}
+	}
 
-	WM_manipulator_set_colors(axis->manipulator, col, col_hi);
+	return protectflag;
+}
+
+static int transform_manipulators_protectflag_editmode_get(Object *obedit, View3D *v3d)
+{
+	int protectflag = 0;
+
+	if (obedit->type == OB_ARMATURE) {
+		const bArmature *arm = obedit->data;
+		EditBone *ebo;
+		if ((v3d->around == V3D_AROUND_ACTIVE) && (ebo = arm->act_edbone)) {
+			if (ebo->flag & BONE_EDITMODE_LOCKED) {
+				protectflag = (OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE);
+			}
+		}
+		else {
+			for (ebo = arm->edbo->first; ebo; ebo = ebo->next) {
+				if (EBONE_VISIBLE(arm, ebo)) {
+					if ((ebo->flag & BONE_SELECTED) && (ebo->flag & BONE_EDITMODE_LOCKED)) {
+						protectflag = (OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE);
+						break;
+					}
+				}
+			}
+		}
+	}
+
+	return protectflag;
+}
+
+static int transform_manipulators_protectflag_objectmode_get(const Scene *scene, const View3D *v3d)
+{
+	int protectflag = 0;
+
+	for (Base *base = scene->base.first; base; base = base->next) {
+		if (TESTBASELIB(v3d, base)) {
+			protectflag |= base->object->protectflag;
+		}
+	}
+
+	return protectflag;
+}
+
+static int transform_manipulators_protectflag_get(const bContext *C, View3D *v3d)
+{
+	Scene *scene = CTX_data_scene(C);
+	Object *ob = OBACT, *obedit = CTX_data_edit_object(C);
+	bGPdata *gpd = CTX_data_gpencil_data(C);
+	const bool is_gp_edit = (gpd && (gpd->flag & GP_DATA_STROKE_EDITMODE));
+	int protectflag = 0;
+
+	if (is_gp_edit) {
+		/* pass */
+	}
+	else if (obedit) {
+		protectflag = transform_manipulators_protectflag_editmode_get(obedit, v3d);
+	}
+	else if (ob && (ob->mode & OB_MODE_POSE)) {
+		protectflag = transform_manipulators_protectflag_posemode_get(ob, v3d);
+	}
+	else if (ob && (ob->mode & OB_MODE_ALL_PAINT)) {
+		/* pass */
+	}
+	else {
+		protectflag = transform_manipulators_protectflag_objectmode_get(scene, v3d);
+	}
+
+	return protectflag;
+}
+
+/**
+ * Performs some additional layer checks, #calculateTransformCenter does the rest of them.
+ */
+static bool transform_manipulators_layer_visible(const bContext *C, const View3D *v3d)
+{
+	Scene *scene = CTX_data_scene(C);
+	Object *ob = OBACT;
+	Object *obedit = CTX_data_edit_object(C);
+	bGPdata *gpd = CTX_data_gpencil_data(C);
+	const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE));
+
+	if (is_gp_edit) {
+		/* TODO */
+	}
+	else if (obedit) {
+		return (obedit->lay & v3d->lay) != 0;
+	}
+	else if (ob && (ob->mode & OB_MODE_POSE)) {
+		return (ob->lay & v3d->lay) != 0;
+	}
+
+	return true;
 }
 
 /**
@@ -219,22 +352,28 @@ static bool transform_manipulators_matrix_get(const bContext *C, const View3D *v
 static void transform_manipulatorgroup_refresh(const bContext *C, wmManipulatorGroup *mgroup)
 {
 	View3D *v3d = CTX_wm_view3d(C);
-	TranformAxisManipulator *axes = mgroup->customdata;
+	TransformManipulatorsInfo *info = mgroup->customdata;
 
 	float mat[4][4];
-	const bool visible = transform_manipulators_matrix_get(C, v3d, mat);
+	const bool any_visible = transform_manipulators_layer_visible(C, v3d) &&
+	                         transform_manipulators_matrix_get(C, v3d, mat);
+	const int protectflag = transform_manipulators_protectflag_get(C, v3d);
 
-	for (int i = 0; i < MAN_AXIS_LAST && axes[i].name; i++) {
-		if (visible) {
-			WM_manipulator_set_flag(axes[i].manipulator, WM_MANIPULATOR_HIDDEN, false);
+	copy_m4_m4(info->mat, mat);
+
+	TranformAxisManipulator *axis;
+	for (int i = 0; i < MAN_AXIS_LAST && info->axes[i].name; i++) {
+		axis = &info->axes[i];
+
+		if (any_visible && transfrom_axis_manipulator_is_visible(axis, protectflag)) {
+			WM_manipulator_set_flag(axis->manipulator, WM_MANIPULATOR_HIDDEN, false);
 		}
 		else {
-			WM_manipulator_set_flag(axes[i].manipulator, WM_MANIPULATOR_HIDDEN, true);
+			WM_manipulator_set_flag(axis->manipulator, WM_MANIPULATOR_HIDDEN, true);
 			continue;
 		}
-		WM_arrow_manipulator_set_direction(axes[i].manipulator, mat[i]);
-		WM_manipulator_set_origin(axes[i].manipulator, mat[3]);
-		transform_axis_manipulator_set_color(&axes[i]);
+		WM_arrow_manipulator_set_direction(axis->

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list