[Bf-blender-cvs] [54327bf] transform-manipulators: Some cleanups/refactors for transform manipulators
Julian Eisel
noreply at git.blender.org
Mon Oct 24 01:40:21 CEST 2016
Commit: 54327bf6f14bfcd63766395801cf392a7ca760f0
Author: Julian Eisel
Date: Mon Oct 24 01:39:48 2016 +0200
Branches: transform-manipulators
https://developer.blender.org/rB54327bf6f14bfcd63766395801cf392a7ca760f0
Some cleanups/refactors for transform manipulators
===================================================================
M source/blender/editors/include/ED_transform.h
M source/blender/editors/mesh/editmesh_bevel.c
M source/blender/editors/mesh/editmesh_inset.c
M source/blender/editors/space_view3d/view3d_edit.c
M source/blender/editors/space_view3d/view3d_transform_manipulators.c
M source/blender/editors/transform/transform.c
===================================================================
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index a77d9ab..9443e59 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -102,12 +102,6 @@ enum TfmMode {
#define CTX_PAINT_CURVE (1 << 8)
#define CTX_GPENCIL_STROKES (1 << 9)
-/* Standalone call to get the transformation center corresponding to the current situation
- * returns 1 if successful, 0 otherwise (usually means there's no selection)
- * (if 0 is returns, *vec is unmodified)
- * */
-bool calculateTransformCenter(struct bContext *C, int centerMode, float cent3d[3], float cent2d[2]);
-
struct TransInfo;
struct Base;
struct Scene;
@@ -134,6 +128,11 @@ void ED_getLocalTransformOrientationMatrix(const struct bContext *C, float orien
void ED_getTransformOrientationMatrix(
const struct bContext *C, const char orientation_type, const short around,
float r_orientation_mat[3][3]);
+/* Standalone call to get the transformation center corresponding to the current situation
+ * returns 1 if successful, 0 otherwise (usually means there's no selection)
+ * (if 0 is returns, *vec is unmodified)
+ * */
+bool ED_calculateTransformCenter(struct bContext *C, int centerMode, float cent3d[3], float cent2d[2]);
int BIF_countTransformOrientation(const struct bContext *C);
diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c
index a81add7..2a78d8e 100644
--- a/source/blender/editors/mesh/editmesh_bevel.c
+++ b/source/blender/editors/mesh/editmesh_bevel.c
@@ -329,7 +329,7 @@ static int edbm_bevel_invoke(bContext *C, wmOperator *op, const wmEvent *event)
opdata = op->customdata;
/* initialize mouse values */
- if (!calculateTransformCenter(C, V3D_AROUND_CENTER_MEAN, center_3d, opdata->mcenter)) {
+ if (!ED_calculateTransformCenter(C, V3D_AROUND_CENTER_MEAN, center_3d, opdata->mcenter)) {
/* in this case the tool will likely do nothing,
* ideally this will never happen and should be checked for above */
opdata->mcenter[0] = opdata->mcenter[1] = 0;
diff --git a/source/blender/editors/mesh/editmesh_inset.c b/source/blender/editors/mesh/editmesh_inset.c
index 3e0747f..73b1b5b 100644
--- a/source/blender/editors/mesh/editmesh_inset.c
+++ b/source/blender/editors/mesh/editmesh_inset.c
@@ -284,7 +284,7 @@ static int edbm_inset_invoke(bContext *C, wmOperator *op, const wmEvent *event)
opdata = op->customdata;
/* initialize mouse values */
- if (!calculateTransformCenter(C, V3D_AROUND_CENTER_MEAN, center_3d, opdata->mcenter)) {
+ if (!ED_calculateTransformCenter(C, V3D_AROUND_CENTER_MEAN, center_3d, opdata->mcenter)) {
/* in this case the tool will likely do nothing,
* ideally this will never happen and should be checked for above */
opdata->mcenter[0] = opdata->mcenter[1] = 0;
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 2178b44..6004817 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -635,7 +635,7 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
Object *ob_act = OBACT;
if (ob_act && (ob_act->mode & OB_MODE_ALL_PAINT) &&
- /* with weight-paint + pose-mode, fall through to using calculateTransformCenter */
+ /* with weight-paint + pose-mode, fall through to using ED_calculateTransformCenter */
((ob_act->mode & OB_MODE_WEIGHT_PAINT) && BKE_object_pose_armature_get(ob_act)) == 0)
{
/* in case of sculpting use last average stroke position as a rotation
@@ -702,7 +702,7 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
}
else {
/* If there's no selection, lastofs is unmodified and last value since static */
- is_set = calculateTransformCenter(C, V3D_AROUND_CENTER_MEAN, lastofs, NULL);
+ is_set = ED_calculateTransformCenter(C, V3D_AROUND_CENTER_MEAN, lastofs, NULL);
}
copy_v3_v3(r_dyn_ofs, lastofs);
diff --git a/source/blender/editors/space_view3d/view3d_transform_manipulators.c b/source/blender/editors/space_view3d/view3d_transform_manipulators.c
index be8a76f..59206dd 100644
--- a/source/blender/editors/space_view3d/view3d_transform_manipulators.c
+++ b/source/blender/editors/space_view3d/view3d_transform_manipulators.c
@@ -22,7 +22,6 @@
* \ingroup spview3d
*/
-
#include "BLI_math.h"
#include "BKE_action.h"
@@ -50,36 +49,6 @@
#include "WM_types.h"
-/* axes as index */
-enum TransformAxisType {
- MAN_AXIS_TRANS_X = 0,
- MAN_AXIS_TRANS_Y,
- MAN_AXIS_TRANS_Z,
- MAN_AXIS_TRANS_C,
-
- MAN_AXIS_ROT_X,
- MAN_AXIS_ROT_Y,
- MAN_AXIS_ROT_Z,
- MAN_AXIS_ROT_C,
- MAN_AXIS_ROT_T, /* trackball rotation */
-
- MAN_AXIS_SCALE_X,
- MAN_AXIS_SCALE_Y,
- MAN_AXIS_SCALE_Z,
- MAN_AXIS_SCALE_C,
-
- /* special */
- MAN_AXIS_TRANS_XY,
- MAN_AXIS_TRANS_YZ,
- MAN_AXIS_TRANS_ZX,
-
- MAN_AXIS_SCALE_XY,
- MAN_AXIS_SCALE_YZ,
- MAN_AXIS_SCALE_ZX,
-
- MAN_AXIS_LAST,
-};
-
/* threshold for testing view aligned axis manipulator */
#define TRANSFORM_MAN_AXIS_DOT_MIN 0.02f
#define TRANSFORM_MAN_AXIS_DOT_MAX 0.1f
@@ -87,24 +56,42 @@ enum TransformAxisType {
#define TRANSFORM_MAN_AXIS_LINE_WIDTH 2.0f
/**
+ * Transform axis type that can be used as index.
+ */
+enum TransformAxisType {
+ /* single axes */
+ TRANSFORM_AXIS_X = 0,
+ TRANSFORM_AXIS_Y = 1,
+ TRANSFORM_AXIS_Z = 2,
+
+ /* mulitple axes */
+ TRANSFORM_AXIS_VIEW = 3,
+ TRANSFORM_AXIS_XY = 4,
+ TRANSFORM_AXIS_YZ = 5,
+ TRANSFORM_AXIS_ZX = 6,
+};
+
+/**
* Struct for carrying data of transform manipulators as wmManipulatorGroup.customdata.
*/
typedef struct TransformManipulatorsInfo {
struct TranformAxisManipulator *axes; /* Array of axes */
- wmManipulatorGroup *mgroup;
float mat[4][4]; /* Cached loc/rot matrix */
} TransformManipulatorsInfo;
-typedef wmManipulator *TransformManipulatorInitFunc(const TransformManipulatorsInfo *,
- struct TranformAxisManipulator *);
-typedef void TransformManipulatorUpdateFunc(const bContext *, const TransformManipulatorsInfo *,
- const struct TranformAxisManipulator *);
+/* Callback types */
+typedef wmManipulator *TransformManipulatorInitFunc(struct TranformAxisManipulator *, wmManipulatorGroup *mgroup);
+typedef void TransformManipulatorUpdateFunc(
+ const bContext *, const TransformManipulatorsInfo *, const struct TranformAxisManipulator *);
+/**
+ * Struct that allows us to store info for each transform axis manipulator in a rather generic way.
+ */
typedef struct TranformAxisManipulator {
/* -- initialized using static array -- */
- enum TransformAxisType index;
+ enum TransformAxisType axis_type;
int transform_type; /* View3d->twtype */
/* per-manipulator callbacks for initializing/updating data */
@@ -123,103 +110,129 @@ typedef struct TranformAxisManipulator {
int manipulator_style;
- /* -- initialized later -- */
-
+ /* The manipulator that represents this axis */
wmManipulator *manipulator;
} TranformAxisManipulator;
-static TransformManipulatorInitFunc manipulator_arrow_init;
-static TransformManipulatorUpdateFunc manipulator_arrow_draw_prepare;
-static TransformManipulatorInitFunc manipulator_dial_init;
-static TransformManipulatorUpdateFunc manipulator_dial_refresh;
-static TransformManipulatorUpdateFunc manipulator_view_dial_draw_prepare;
+
+/* -------------------------------------------------------------------- */
+/* Manipulator init/update callbacks */
+
+static wmManipulator *manipulator_arrow_init(TranformAxisManipulator *axis, wmManipulatorGroup *mgroup)
+{
+ return WM_arrow_manipulator_new(mgroup, axis->name, axis->manipulator_style);
+}
+
+static wmManipulator *manipulator_dial_init(TranformAxisManipulator *axis, wmManipulatorGroup *mgroup)
+{
+ return WM_dial_manipulator_new(mgroup, axis->name, axis->manipulator_style);
+}
+
+static void manipulator_dial_refresh(
+ const bContext *UNUSED(C), const TransformManipulatorsInfo *info, const TranformAxisManipulator *axis)
+{
+ WM_dial_manipulator_set_up_vector(axis->manipulator, info->mat[axis->axis_type]);
+}
+
+static void manipulator_arrow_draw_prepare(
+ const bContext *UNUSED(C), const TransformManipulatorsInfo *info, const TranformAxisManipulator *axis)
+{
+ WM_arrow_manipulator_set_direction(axis->manipulator, info->mat[axis->axis_type]);
+}
+
+static void manipulator_view_dial_draw_prepare(
+ const bContext *C, const TransformManipulatorsInfo *UNUSED(info), const TranformAxisManipulator *axis)
+{
+ RegionView3D *rv3d = CTX_wm_region_view3d(C);
+ WM_dial_manipulator_set_up_vector(axis->manipulator, rv3d->viewinv[2]);
+}
+
+
+/* -------------------------------------------------------------------- */
+/* General helpers */
/**
* 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.
*
- * \note Order matches drawing order! (TODO: How should drawing order and index work together?)
+ * \note Order matches drawing order!
*/
static TranformAxisManipulator tman_axes[] = {
{
- MAN_AXIS_TRANS_X, V3D_MANIP_TRANSLATE,
+ TRANSFORM_AXIS_X, V3D_MANIP_TRANSLATE,
manipulator_arrow_init, NULL, manipulator_arrow_draw_prepare,
"translate_x", {1, 0, 0}, OB_LOCK_LOCX,
1.0f, TRANSFORM_MAN_AXIS_LINE_WIDTH, TH_AXIS_X, MANIPULATOR_ARROW_STYLE_CONE,
},
{
- MAN_AXIS_TRANS_Y, V3D_MANIP_TRANSLATE,
+ TRANSFORM_AXIS_Y, V3D_MANIP_TRANSLATE,
manipulator_arrow_init, NULL, manipulator_arrow_draw_prepare,
"translate_y", {0, 1, 0}, OB_LOCK_LOCY,
1.0f, TRANSFORM_MAN_AXIS_LINE_WIDTH, TH_AXIS_Y, MANIPULATOR_ARROW_STYLE_CONE,
},
{
- MAN_AXIS_TRANS_Z, V3D_MANIP_TRANSLATE,
+ TRANSFORM_AXIS_Z, V3D_MANIP_TRANSLATE,
manipulator_arrow_init, NULL, manipulator_arrow_draw_prepare,
"translate_z", {0, 0, 1}, OB_LOCK_LOCZ,
1.0f, TRANSFORM_MAN_AXIS_LINE_WIDTH, TH_AXIS_Z, MANIPULATOR_ARROW_STYLE_CONE,
},
{
- MAN_AXIS_TRANS_C, V3D_MANIP_TRANSLATE,
+ TRANSFORM_AXIS_VIEW,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list