[Bf-blender-cvs] [c9c23a3e44c] master: RNA: add 3D cursor matrix attribute

Campbell Barton noreply at git.blender.org
Thu May 16 05:50:52 CEST 2019


Commit: c9c23a3e44c0648d37396bbb19236e881d33e2cc
Author: Campbell Barton
Date:   Thu May 16 13:38:33 2019 +1000
Branches: master
https://developer.blender.org/rBc9c23a3e44c0648d37396bbb19236e881d33e2cc

RNA: add 3D cursor matrix attribute

Avoids having to check rotation modes to get the orientation.

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

M	source/blender/blenkernel/BKE_scene.h
M	source/blender/blenkernel/intern/scene.c
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/mesh/editmesh_add_gizmo.c
M	source/blender/editors/space_view3d/view3d_utils.c
M	source/blender/editors/transform/transform_gizmo_3d.c
M	source/blender/editors/transform/transform_orientations.c
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index 75ff5eace3c..581df648add 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -240,6 +240,11 @@ void BKE_scene_cursor_quat_to_rot(struct View3DCursor *cursor,
                                   const float quat[4],
                                   bool use_compat);
 
+void BKE_scene_cursor_to_mat4(const struct View3DCursor *cursor, float mat[4][4]);
+void BKE_scene_cursor_from_mat4(struct View3DCursor *cursor,
+                                const float mat[4][4],
+                                bool use_compat);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 714261ce4ab..a1e6aa6c4d6 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -2386,4 +2386,20 @@ void BKE_scene_cursor_quat_to_rot(View3DCursor *cursor, const float quat[4], boo
   }
 }
 
+void BKE_scene_cursor_to_mat4(const View3DCursor *cursor, float mat[4][4])
+{
+  float mat3[3][3];
+  BKE_scene_cursor_rot_to_mat3(cursor, mat3);
+  copy_m4_m3(mat, mat3);
+  copy_v3_v3(mat[3], cursor->location);
+}
+
+void BKE_scene_cursor_from_mat4(View3DCursor *cursor, const float mat[4][4], bool use_compat)
+{
+  float mat3[3][3];
+  copy_m3_m4(mat3, mat);
+  BKE_scene_cursor_mat3_to_rot(cursor, mat3, use_compat);
+  copy_v3_v3(cursor->location, mat[3]);
+}
+
 /** \} */
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 3503d38ad92..8974f3d6374 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -108,8 +108,6 @@ enum eV3DCursorOrient {
 void ED_view3d_background_color_get(const struct Scene *scene,
                                     const struct View3D *v3d,
                                     float r_color[3]);
-void ED_view3d_cursor3d_calc_mat3(const struct Scene *scene, float mat[3][3]);
-void ED_view3d_cursor3d_calc_mat4(const struct Scene *scene, float mat[4][4]);
 void ED_view3d_cursor3d_position(struct bContext *C,
                                  const int mval[2],
                                  const bool use_depth,
diff --git a/source/blender/editors/mesh/editmesh_add_gizmo.c b/source/blender/editors/mesh/editmesh_add_gizmo.c
index 839ee186016..f6729fb56e1 100644
--- a/source/blender/editors/mesh/editmesh_add_gizmo.c
+++ b/source/blender/editors/mesh/editmesh_add_gizmo.c
@@ -29,6 +29,7 @@
 
 #include "BKE_context.h"
 #include "BKE_editmesh.h"
+#include "BKE_scene.h"
 
 #include "ED_gizmo_library.h"
 #include "ED_gizmo_utils.h"
@@ -75,7 +76,7 @@ static void calc_initial_placement_point_from_view(bContext *C,
 
   float cursor_matrix[4][4];
   float orient_matrix[3][3];
-  ED_view3d_cursor3d_calc_mat4(scene, cursor_matrix);
+  BKE_scene_cursor_to_mat4(&scene->cursor, cursor_matrix);
 
   float dots[3] = {
       dot_v3v3(rv3d->viewinv[2], cursor_matrix[0]),
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index 91313657f59..bb8c1a40a05 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -86,21 +86,6 @@ void ED_view3d_background_color_get(const Scene *scene, const View3D *v3d, float
   UI_GetThemeColor3fv(TH_BACK, r_color);
 }
 
-void ED_view3d_cursor3d_calc_mat3(const Scene *scene, float mat[3][3])
-{
-  const View3DCursor *cursor = &scene->cursor;
-  BKE_scene_cursor_rot_to_mat3(cursor, mat);
-}
-
-void ED_view3d_cursor3d_calc_mat4(const Scene *scene, float mat[4][4])
-{
-  const View3DCursor *cursor = &scene->cursor;
-  float mat3[3][3];
-  BKE_scene_cursor_rot_to_mat3(cursor, mat3);
-  copy_m4_m3(mat, mat3);
-  copy_v3_v3(mat[3], cursor->location);
-}
-
 Camera *ED_view3d_camera_data_get(View3D *v3d, RegionView3D *rv3d)
 {
   /* establish the camera object,
diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c
index 35fda39e8dc..e43379dc358 100644
--- a/source/blender/editors/transform/transform_gizmo_3d.c
+++ b/source/blender/editors/transform/transform_gizmo_3d.c
@@ -703,7 +703,7 @@ void ED_transform_calc_orientation_from_type_ex(const bContext *C,
       break;
     }
     case V3D_ORIENT_CURSOR: {
-      ED_view3d_cursor3d_calc_mat3(scene, r_mat);
+      BKE_scene_cursor_rot_to_mat3(&scene->cursor, r_mat);
       ok = true;
       break;
     }
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c
index e16579aba64..70bb2bf98a6 100644
--- a/source/blender/editors/transform/transform_orientations.c
+++ b/source/blender/editors/transform/transform_orientations.c
@@ -485,7 +485,7 @@ void initTransformOrientation(bContext *C, TransInfo *t)
       break;
     case V3D_ORIENT_CURSOR: {
       BLI_strncpy(t->spacename, IFACE_("cursor"), sizeof(t->spacename));
-      ED_view3d_cursor3d_calc_mat3(t->scene, t->spacemtx);
+      BKE_scene_cursor_rot_to_mat3(&t->scene->cursor, t->spacemtx);
       break;
     }
     case V3D_ORIENT_CUSTOM_MATRIX:
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index ed9db684cd4..b7399202624 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -1849,6 +1849,20 @@ static void rna_View3DCursor_rotation_axis_angle_set(PointerRNA *ptr, const floa
   copy_v3_v3(cursor->rotation_axis, &value[1]);
 }
 
+static void rna_View3DCursor_matrix_get(PointerRNA *ptr, float *values)
+{
+  const View3DCursor *cursor = ptr->data;
+  BKE_scene_cursor_to_mat4(cursor, (float(*)[4])values);
+}
+
+static void rna_View3DCursor_matrix_set(PointerRNA *ptr, const float *values)
+{
+  View3DCursor *cursor = ptr->data;
+  float unit_mat[4][4];
+  normalize_m4_m4(unit_mat, (const float(*)[4])values);
+  BKE_scene_cursor_from_mat4(cursor, unit_mat, false);
+}
+
 static char *rna_View3DCursor_path(PointerRNA *UNUSED(ptr))
 {
   return BLI_strdup("cursor");
@@ -2586,6 +2600,14 @@ static void rna_def_view3d_cursor(BlenderRNA *brna)
   RNA_def_property_enum_funcs(prop, NULL, "rna_View3DCursor_rotation_mode_set", NULL);
   RNA_def_property_ui_text(prop, "Rotation Mode", "");
   RNA_def_property_update(prop, NC_WINDOW, NULL);
+
+  /* Matrix access to avoid having to check current rotation mode. */
+  prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
+  RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
+  RNA_def_property_flag(prop, PROP_THICK_WRAP); /* no reference to original data */
+  RNA_def_property_ui_text(prop, "Transform Matrix", "Matrix combining loc/rot of the cursor");
+  RNA_def_property_float_funcs(
+      prop, "rna_View3DCursor_matrix_get", "rna_View3DCursor_matrix_set", NULL);
 }
 
 static void rna_def_tool_settings(BlenderRNA *brna)



More information about the Bf-blender-cvs mailing list