[Bf-blender-cvs] [c18d5032055] vr_scene_inspection: Cleanup: Reorganize state structs, naming, unused functions, etc

Julian Eisel noreply at git.blender.org
Tue Mar 10 17:19:57 CET 2020


Commit: c18d503205566b1af07ae135c8cec4c5c96c7d7e
Author: Julian Eisel
Date:   Tue Mar 10 17:17:29 2020 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rBc18d503205566b1af07ae135c8cec4c5c96c7d7e

Cleanup: Reorganize state structs, naming, unused functions, etc

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

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/windowmanager/intern/wm_xr.c

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

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 68c0bde21a8..a8ebd32ad4d 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -146,7 +146,6 @@ void BKE_object_obdata_size_init(struct Object *ob, const float scale);
 void BKE_object_scale_to_mat3(struct Object *ob, float mat[3][3]);
 void BKE_object_rot_to_mat3(const struct Object *ob, float mat[3][3], bool use_drot);
 void BKE_object_mat3_to_rot(struct Object *ob, float mat[3][3], bool use_compat);
-void BKE_object_rot_to_quat(struct Object *ob, float r_quat[4]);
 void BKE_object_to_mat3(struct Object *ob, float mat[3][3]);
 void BKE_object_to_mat4(struct Object *ob, float mat[4][4]);
 void BKE_object_apply_mat4(struct Object *ob,
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index ee4b911a812..20c198f56de 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2129,28 +2129,6 @@ void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat)
   }
 }
 
-void BKE_object_rot_to_quat(Object *ob, float r_quat[4])
-{
-  float quat[4], dquat[4];
-
-  switch (ob->rotmode) {
-    case ROT_MODE_QUAT:
-      copy_v4_v4(quat, ob->quat);
-      copy_v4_v4(dquat, ob->dquat);
-      break;
-    case ROT_MODE_AXISANGLE:
-      axis_angle_to_quat(quat, ob->rotAxis, ob->rotAngle);
-      axis_angle_to_quat(dquat, ob->drotAxis, ob->drotAngle);
-      break;
-    default: /* euler */
-      eulO_to_quat(quat, ob->rot, ob->rotmode);
-      eulO_to_quat(dquat, ob->drot, ob->rotmode);
-      break;
-  }
-
-  mul_qt_qtqt(r_quat, dquat, quat);
-}
-
 void BKE_object_tfm_protected_backup(const Object *ob, ObjectTfmProtectedChannels *obtfm)
 {
 
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index 19e992fb3c1..204bef05699 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -72,27 +72,26 @@ void wm_xr_pose_to_viewmat(const GHOST_XrPose *pose, float r_viewmat[4][4]);
 /* -------------------------------------------------------------------- */
 
 typedef struct bXrRuntimeSessionState {
-  /** The pose (location + rotation) to which eye deltas will be applied to when drawing (world
-   * space). With positional tracking enabled, it should be the same as the base pose, when
-   * disabled it also contains a location delta from the moment the option was toggled. */
-  GHOST_XrPose final_reference_pose;
-  float eye_position_ofs[3]; /* Local/view space. */
+  /** Last known viewer pose (centroid of eyes, in world space) stored for queries. */
+  GHOST_XrPose viewer_pose;
+  /** The last known view matrix, calculated from above's viewer pose. */
+  float viewer_viewmat[4][4];
+  float focal_len;
 
-  /** Copy of bXrSessionSettings.flag created on the last draw call,  */
+  /** Copy of bXrSessionSettings.flag created on the last draw call, stored to detect changes. */
   int prev_settings_flag;
 
-  /* Just a utility "cache" to avoid recalculating things for external queries. */
-  struct {
-    /** Last known viewer location (centroid of eyes, in world space) stored for queries. */
-    GHOST_XrPose viewer_pose;
-    /** The view matrix calculated from above's viewer pose. */
-    float viewer_viewmat[4][4];
-    float focal_len;
-
-    bool is_initialized;
-  } last_known;
+  bool is_initialized;
 } bXrRuntimeSessionState;
 
+typedef struct wmXrDrawData {
+  /** The pose (location + rotation) to which eye deltas will be applied to when drawing (world
+   * space). With positional tracking enabled, it should be the same as the base pose, when
+   * disabled it also contains a location delta from the moment the option was toggled. */
+  GHOST_XrPose reference_pose;
+  float eye_position_ofs[3]; /* Local/view space. */
+} wmXrDrawData;
+
 typedef struct {
   GHOST_TXrGraphicsBinding gpu_binding_type;
   GPUOffScreen *offscreen;
@@ -245,90 +244,95 @@ static void wm_xr_reference_pose_calc(const Scene *scene,
   }
 }
 
-static void wm_xr_runtime_session_state_final_reference_pose_update(
-    bXrRuntimeSessionState *state,
-    const GHOST_XrDrawViewInfo *draw_view,
-    const bXrSessionSettings *settings,
-    const Scene *scene)
+static void wm_xr_draw_data_populate(const bXrRuntimeSessionState *state,
+                                     const GHOST_XrDrawViewInfo *draw_view,
+                                     const bXrSessionSettings *settings,
+                                     const Scene *scene,
+                                     wmXrDrawData *r_draw_data)
 {
   const bool position_tracking_toggled = (state->prev_settings_flag &
                                           XR_SESSION_USE_POSITION_TRACKING) !=
                                          (settings->flag & XR_SESSION_USE_POSITION_TRACKING);
   const bool use_position_tracking = settings->flag & XR_SESSION_USE_POSITION_TRACKING;
 
-  wm_xr_reference_pose_calc(scene, settings, &state->final_reference_pose);
+  wm_xr_reference_pose_calc(scene, settings, &r_draw_data->reference_pose);
 
   if (position_tracking_toggled) {
     if (use_position_tracking) {
-      copy_v3_fl(state->eye_position_ofs, 0.0f);
+      copy_v3_fl(r_draw_data->eye_position_ofs, 0.0f);
     }
     else {
       /* Store the current local offset (local pose) so that we can apply that to the eyes. This
        * way the eyes stay exactly where they are when disabling positional tracking. */
-      copy_v3_v3(state->eye_position_ofs, draw_view->local_pose.position);
+      copy_v3_v3(r_draw_data->eye_position_ofs, draw_view->local_pose.position);
     }
   }
-
-  state->prev_settings_flag = settings->flag;
 }
 
-static void wm_xr_runtime_session_state_info_update(bXrRuntimeSessionState *state,
-                                                    const GHOST_XrDrawViewInfo *draw_view,
-                                                    const bXrSessionSettings *settings)
+/**
+ * Update information that is only stored for external state queries. E.g. for Python API to
+ * request the current (as in, last known) viewer pose.
+ */
+static void wm_xr_runtime_session_state_update(bXrRuntimeSessionState *state,
+                                               const GHOST_XrDrawViewInfo *draw_view,
+                                               const bXrSessionSettings *settings,
+                                               const wmXrDrawData *draw_data)
 {
   GHOST_XrPose viewer_pose;
   const bool use_position_tracking = settings->flag & XR_SESSION_USE_POSITION_TRACKING;
 
   mul_qt_qtqt(viewer_pose.orientation_quat,
-              state->final_reference_pose.orientation_quat,
+              draw_data->reference_pose.orientation_quat,
               draw_view->local_pose.orientation_quat);
-  copy_v3_v3(viewer_pose.position, state->final_reference_pose.position);
-  viewer_pose.position[0] += state->eye_position_ofs[0];
-  viewer_pose.position[1] -= state->eye_position_ofs[2];
-  viewer_pose.position[2] += state->eye_position_ofs[1];
+  copy_v3_v3(viewer_pose.position, draw_data->reference_pose.position);
+  viewer_pose.position[0] += draw_data->eye_position_ofs[0];
+  viewer_pose.position[1] -= draw_data->eye_position_ofs[2];
+  viewer_pose.position[2] += draw_data->eye_position_ofs[1];
   if (use_position_tracking) {
     viewer_pose.position[0] += draw_view->local_pose.position[0];
     viewer_pose.position[1] -= draw_view->local_pose.position[2];
     viewer_pose.position[2] += draw_view->local_pose.position[1];
   }
 
-  state->last_known.viewer_pose = viewer_pose;
-  wm_xr_pose_to_viewmat(&viewer_pose, state->last_known.viewer_viewmat);
+  state->viewer_pose = viewer_pose;
+  wm_xr_pose_to_viewmat(&viewer_pose, state->viewer_viewmat);
   /* No idea why, but multiplying by two seems to make it match the VR view more. */
-  state->last_known.focal_len = 2.0f * fov_to_focallength(draw_view->fov.angle_right -
-                                                              draw_view->fov.angle_left,
-                                                          DEFAULT_SENSOR_WIDTH);
-  state->last_known.is_initialized = true;
+  state->focal_len = 2.0f *
+                     fov_to_focallength(draw_view->fov.angle_right - draw_view->fov.angle_left,
+                                        DEFAULT_SENSOR_WIDTH);
+
+  state->prev_settings_flag = settings->flag;
+  state->is_initialized = true;
 }
 
 void WM_xr_session_state_viewer_location_get(const wmXrData *xr, float r_location[3])
 {
-  if (!WM_xr_session_is_running(xr) || !xr->session_state->last_known.is_initialized) {
+  if (!WM_xr_session_is_running(xr) || !xr->session_state->is_initialized) {
     return;
   }
 
-  copy_v3_v3(r_location, xr->session_state->last_known.viewer_pose.position);
+  copy_v3_v3(r_location, xr->session_state->viewer_pose.position);
 }
 
 void WM_xr_session_state_viewer_rotation_get(const wmXrData *xr, float r_rotation[4])
 {
-  if (!WM_xr_session_is_running(xr) || !xr->session_state->last_known.is_initialized) {
+  if (!WM_xr_session_is_running(xr) || !xr->session_state->is_initialized) {
     return;
   }
 
-  copy_v4_v4(r_rotation, xr->session_state->last_known.viewer_pose.orientation_quat);
+  copy_v4_v4(r_rotation, xr->session_state->viewer_pose.orientation_quat);
 }
 
 void WM_xr_session_state_viewer_matrix_info_get(const wmXrData *xr,
                                                 float r_viewmat[4][4],
                                                 float *r_focal_len)
 {
-  if (!WM_xr_session_is_running(xr) || !xr->session_state->last_known.is_initialized) {
+  if (!WM_xr_session_is_running(xr) || !xr->session_state->is_initialized) {
     return;
   }
 
-  copy_m4_m4(r_viewmat, xr->session_state->last_known.viewer_viewmat);
-  *r_focal_len = xr->session_state->last_known.focal_len;
+  copy_m4_m4(r_viewmat, xr->session_state->viewer_viewmat);
+  *r_focal_len = xr->session_state->focal_len;
 }
 
 /** \} */ /* XR Runtime Session State */
@@ -559,9 +563,9 @@ void wm_xr_pose_to_viewmat(const GHOST_XrPose *pose, float r_viewmat[4][4])
  * reference space and apply its pose onto the active

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list