Commit: 86c0ee80209cdd52e4b360ffcf854144922ac2e6
Author: Campbell Barton
Date: Tue Feb 26 00:58:35 2019 +1100
Branches: master
https://developer.blender.org/rB86c0ee80209cdd52e4b360ffcf854144922ac2e6
3D View: support for editing cursor rotation
Add buttons for editing the cursor rotation as well as rotation modes,
similar to object and pose bones.
===================================================================
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/blenkernel/BKE_scene.h
M source/blender/blenkernel/intern/scene.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/versioning_280.c
M source/blender/draw/intern/draw_view.c
M source/blender/editors/space_view3d/view3d_edit.c
M source/blender/editors/space_view3d/view3d_utils.c
M source/blender/editors/transform/transform_conversions.c
M source/blender/makesdna/DNA_view3d_types.h
M source/blender/makesrna/intern/rna_scene.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d.py
b/release/scripts/startup/bl_ui/space_view3d.py
index 29333ddb2d5..cfbbde4f195 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4329,6 +4329,14 @@ class VIEW3D_PT_view3d_cursor(Panel):
scene = context.scene
layout.column().prop(scene, "cursor_location", text="Location")
+ rotation_mode = scene.cursor_rotation_mode
+ if rotation_mode == 'QUATERNION':
+ layout.column().prop(scene, "cursor_rotation_quaternion",
text="Rotation")
+ elif rotation_mode == 'AXIS_ANGLE':
+ layout.column().prop(scene, "cursor_rotation_axis_angle",
text="Rotation")
+ else:
+ layout.column().prop(scene, "cursor_rotation_euler",
text="Rotation")
+ layout.row().prop(scene, "cursor_rotation_mode")
class VIEW3D_PT_collections(Panel):
diff --git a/source/blender/blenkernel/BKE_scene.h
b/source/blender/blenkernel/BKE_scene.h
index 7638f8c95d5..a0525a4e9f7 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -36,6 +36,7 @@ struct RenderData;
struct Scene;
struct TransformOrientation;
struct UnitSettings;
+struct View3DCursor;
struct ViewLayer;
struct ViewRender;
struct WorkSpace;
@@ -201,6 +202,12 @@ struct TransformOrientation
*BKE_scene_transform_orientation_find(
int BKE_scene_transform_orientation_get_index(
const struct Scene *scene, const struct TransformOrientation
*orientation);
+void BKE_scene_cursor_rot_to_mat3(const struct View3DCursor *cursor, float
mat[3][3]);
+void BKE_scene_cursor_mat3_to_rot(struct View3DCursor *cursor, const float
mat[3][3], bool use_compat);
+
+void BKE_scene_cursor_rot_to_quat(const struct View3DCursor *cursor, float
quat[4]);
+void BKE_scene_cursor_quat_to_rot(struct View3DCursor *cursor, const float
quat[4], bool use_compat);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/scene.c
b/source/blender/blenkernel/intern/scene.c
index b055c3695bc..c73c6ef6ac2 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -547,7 +547,10 @@ void BKE_scene_init(Scene *sce)
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(sce, id));
- unit_qt(sce->cursor.rotation);
+
+ sce->cursor.rotation_mode = ROT_MODE_XYZ;
+ sce->cursor.rotation_quaternion[0] = 1.0f;
+ sce->cursor.rotation_axis[1] = 1.0f;
sce->r.mode = R_OSA;
sce->r.cfra = 1;
@@ -2242,3 +2245,97 @@ int BKE_scene_transform_orientation_get_index(
}
/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/** \name Scene Cursor Rotation
+ *
+ * Matches #BKE_object_rot_to_mat3 and #BKE_object_mat3_to_rot.
+ * \{ */
+
+void BKE_scene_cursor_rot_to_mat3(const View3DCursor *cursor, float mat[3][3])
+{
+ if (cursor->rotation_mode > 0) {
+ eulO_to_mat3(mat, cursor->rotation_euler,
cursor->rotation_mode);
+ }
+ else if (cursor->rotation_mode == ROT_MODE_AXISANGLE) {
+ axis_angle_to_mat3(mat, cursor->rotation_axis,
cursor->rotation_angle);
+ }
+ else {
+ float tquat[4];
+ normalize_qt_qt(tquat, cursor->rotation_quaternion);
+ quat_to_mat3(mat, tquat);
+ }
+}
+
+void BKE_scene_cursor_rot_to_quat(const View3DCursor *cursor, float quat[4])
+{
+ if (cursor->rotation_mode > 0) {
+ eulO_to_quat(quat, cursor->rotation_euler,
cursor->rotation_mode);
+ }
+ else if (cursor->rotation_mode == ROT_MODE_AXISANGLE) {
+ axis_angle_to_quat(quat, cursor->rotation_axis,
cursor->rotation_angle);
+ }
+ else {
+ normalize_qt_qt(quat, cursor->rotation_quaternion);
+ }
+}
+
+void BKE_scene_cursor_mat3_to_rot(View3DCursor *cursor, const float mat[3][3],
bool use_compat)
+{
+ BLI_ASSERT_UNIT_M3(mat);
+
+ switch (cursor->rotation_mode) {
+ case ROT_MODE_QUAT:
+ {
+ mat3_normalized_to_quat(cursor->rotation_quaternion,
mat);
+ break;
+ }
+ case ROT_MODE_AXISANGLE:
+ {
+ mat3_to_axis_angle(cursor->rotation_axis,
&cursor->rotation_angle, mat);
+ break;
+ }
+ default:
+ {
+ if (use_compat) {
+ mat3_to_compatible_eulO(cursor->rotation_euler,
cursor->rotation_euler, cursor->rotation_mode, mat);
+ }
+ else {
+ mat3_to_eulO(cursor->rotation_euler,
cursor->rotation_mode, mat);
+ }
+ break;
+ }
+ }
+}
+
+void BKE_scene_cursor_quat_to_rot(View3DCursor *cursor, const float quat[4],
bool use_compat)
+{
+ BLI_ASSERT_UNIT_QUAT(quat);
+
+ switch (cursor->rotation_mode) {
+ case ROT_MODE_QUAT:
+ {
+ copy_qt_qt(cursor->rotation_quaternion, quat);
+ break;
+ }
+ case ROT_MODE_AXISANGLE:
+ {
+ quat_to_axis_angle(cursor->rotation_axis,
&cursor->rotation_angle, quat);
+ break;
+ }
+ default:
+ {
+ if (use_compat) {
+ quat_to_compatible_eulO(cursor->rotation_euler,
cursor->rotation_euler, cursor->rotation_mode, quat);
+ }
+ else {
+ quat_to_eulO(cursor->rotation_euler,
cursor->rotation_mode, quat);
+ }
+ break;
+ }
+ }
+}
+
+
+/** \} */
diff --git a/source/blender/blenloader/intern/readfile.c
b/source/blender/blenloader/intern/readfile.c
index 7c455c7c20f..e9053d55390 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8086,8 +8086,8 @@ void blo_lib_link_restore(Main *oldmain, Main *newmain,
wmWindowManager *curwm,
BKE_workspace_active_set(win->workspace_hook, workspace);
/* keep cursor location through undo */
- copy_v3_v3(win->scene->cursor.location,
oldscene->cursor.location);
- copy_qt_qt(win->scene->cursor.rotation,
oldscene->cursor.rotation);
+ memcpy(&win->scene->cursor, &oldscene->cursor,
sizeof(win->scene->cursor));
+
lib_link_window_scene_data_restore(win, win->scene,
cur_view_layer);
BLI_assert(win->screen == NULL);
diff --git a/source/blender/blenloader/intern/versioning_280.c
b/source/blender/blenloader/intern/versioning_280.c
index 5234efdce03..0c0b4f6c364 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1336,12 +1336,6 @@ void blo_do_versions_280(FileData *fd, Library
*UNUSED(lib), Main *bmain)
}
}
}
-
- if (!DNA_struct_find(fd->filesdna, "View3DCursor")) {
- for (Scene *scene = bmain->scene.first; scene; scene =
scene->id.next) {
- unit_qt(scene->cursor.rotation);
- }
- }
}
if (!MAIN_VERSION_ATLEAST(bmain, 280, 14)) {
@@ -2821,5 +2815,15 @@ void blo_do_versions_280(FileData *fd, Library
*UNUSED(lib), Main *bmain)
}
}
}
+
+ if (!DNA_struct_elem_find(fd->filesdna, "View3DCursor",
"short", "rotation_mode")) {
+ for (Scene *scene = bmain->scene.first; scene; scene =
scene->id.next) {
+ if (is_zero_v3(scene->cursor.rotation_axis)) {
+ scene->cursor.rotation_mode =
ROT_MODE_XYZ;
+ scene->cursor.rotation_quaternion[0] =
1.0f;
+ scene->cursor.rotation_axis[1] = 1.0f;
+ }
+ }
+ }
}
}
diff --git a/source/blender/draw/intern/draw_view.c
b/source/blender/draw/intern/draw_view.c
index 2426e98ec84..9bc4e7e8470 100644
--- a/source/blender/draw/intern/draw_view.c
+++ b/source/blender/draw/intern/draw_view.c
@@ -201,12 +201,18 @@ void DRW_draw_cursor(void)
if (is_cursor_visible(draw_ctx, scene, view_layer)) {
int co[2];
+
+ /* Get cursor data into quaternion form */
const View3DCursor *cursor = &scene->cursor;
+
if (ED_view3d_project_int_global(
ar, cursor->location, co, V3D_PROJ_TEST_NOP |
V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK)
{
RegionView3D *rv3d = ar->regiondata;
+ float cursor_quat[4];
+ BKE_scene_cursor_rot_to_quat(cursor, cursor_quat);
+
/* Draw nice Anti Aliased cursor. */
GPU_line_width(1.0f);
glEnable(GL_BLEND);
@@ -214,7 +220,12 @@ void DRW_draw_cursor(void)
float eps = 1e-5f;
rv3d->viewquat[0] = -rv3d->viewquat[0];
- const bool is_aligned = compare_v4v4(cursor->rotation,
rv3d->viewquat, eps);
+ bool is_aligned = compare_v4v4(cursor_quat,
rv3d->viewquat, eps);
+ if (is_aligned == false) {
+ float tquat[4];
+ rotation_between_quats_to_quat(tquat,
rv3d->viewquat, cursor_quat);
+ is_aligned = tquat[0] - eps < -1.0f;
+ }
rv3d->viewquat[0] = -rv3d->viewquat[0];
/* Draw lines */
@@ -241,7 +252,7 @@ void DRW_draw_cursor(void)
for (int axis = 0; axis < 3; axis++) {
float axis_vec[3] = {0};
axis_vec[axis] = scale;
- mul_qt_v3(cursor->rotation, axis_vec);
+ mul_qt_v3(cursor_quat, axis_vec);
CURSOR_EDGE(axis_vec, axis, +);
CURSOR_EDGE(axis_vec, axis, -);
}
diff --git a/source/blender/editors/space_view3d/view3d_edit.c
b/source/blender/editors/space_view3d/view3d_edit.c
index 9adcd4c264a..c84e8d9da20 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -2712,7 +2712,10 @@ static int view3d_all_exec(bContext *C, wmOperator *op)
zero_v3(min);
zero_v3(max);
zero_v3(cursor->location);
- unit_qt(cursor->rotation);
+ unit_qt(cursor->rotation_quaternion);
+ zero_v3(cursor->rotation_euler);
+ ARRAY_SET_ITEMS(cursor->rotation_axis, 0.0f, 1.0f, 0.0f);
+ cursor->rotation_angle = 0.0f;
}
else {
INIT_MINMAX(min, max);
@@ -4762,10 +4765,30 @@ void ED_view3d_cursor3d_update(
View3DCursor *cursor_curr = &scene->cursor;
View3DCursor cursor_prev = *cursor_curr;
- ED_view3d_cursor3d_position_rotation(
- C, mval,
- use_depth, orientation,
- cursor_curr->location, cursor_curr->rotation);
+ {
+ float quat[4], quat_prev[4];
+ BKE_scene_cursor_rot_to_quat(cursor_curr, quat);
+ copy_qt_qt(quat_prev, quat);
+ ED_view3d_cursor3d_position_rotation(
+ C, mval,
+ use_depth, orientation,
+ cursor_curr->location, quat);
+
+ if (!equals_v4v4(quat_prev, quat)) {
+ if ((cursor_curr->rotation_mode == ROT_MODE_AXISANGLE)
&&
+ RV3D_VIEW_IS_AXIS(rv3d->view))
+ {
+ float tmat[3][3], cmat[3][3];
+ quat_to_mat3(tmat, quat);
+ negate_v3_v3(cursor_curr->rotation_axis,
tmat[2]);
+ axis_angle_to_mat3(cmat,
cursor_curr->rotation_axis, 0.0f);
+ cursor_curr->rotation_angle =
angle_signed_on_axis_v3v3_v3(cmat[0], tmat[0], cursor_curr->rotation_axis);
+ }
+ else {
+ BKE_scene_cursor_quat_to_rot(cursor_curr, quat,
true);
+
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs