[Bf-blender-cvs] [c4f65fa5da4] xr-controller-support: Cleanup

Peter Kim noreply at git.blender.org
Sun Oct 3 05:40:40 CEST 2021


Commit: c4f65fa5da4c1f3498316da3eac7c0b43b218fd6
Author: Peter Kim
Date:   Sun Oct 3 12:11:10 2021 +0900
Branches: xr-controller-support
https://developer.blender.org/rBc4f65fa5da4c1f3498316da3eac7c0b43b218fd6

Cleanup

- Use doxygen style comments
- Improve comment for XR region type
- Improve RNA descriptions for XR nav location/rotation/scale
- Split controller draw callback into separate model and aim functions

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

M	intern/ghost/intern/GHOST_XrControllerModel.cpp
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/xr/intern/wm_xr_draw.c

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

diff --git a/intern/ghost/intern/GHOST_XrControllerModel.cpp b/intern/ghost/intern/GHOST_XrControllerModel.cpp
index 99a58199a0a..659bf8555f3 100644
--- a/intern/ghost/intern/GHOST_XrControllerModel.cpp
+++ b/intern/ghost/intern/GHOST_XrControllerModel.cpp
@@ -53,8 +53,10 @@ struct GHOST_XrPrimitive {
   std::vector<uint32_t> indices;
 };
 
-/* Validate that an accessor does not go out of bounds of the buffer view that it references and
-   that the buffer view does not exceed the bounds of the buffer that it references. */
+/**
+ * Validate that an accessor does not go out of bounds of the buffer view that it references and
+ * that the buffer view does not exceed the bounds of the buffer that it references
+ */
 static void validate_accessor(const tinygltf::Accessor &accessor,
                               const tinygltf::BufferView &buffer_view,
                               const tinygltf::Buffer &buffer,
@@ -135,9 +137,10 @@ static void load_attribute_accessor(const tinygltf::Model &gltf_model,
   }
 }
 
-/* Reads index data from a glTF primitive into a GHOST_XrPrimitive. glTF indices may be 8bit,
-   16bit or 32bit integers. This will coalesce indices from the source type(s) into a 32bit
-   integer. */
+/**
+ * Reads index data from a glTF primitive into a GHOST_XrPrimitive. glTF indices may be 8bit, 16bit
+ * or 32bit integers. This will coalesce indices from the source type(s) into a 32bit integer.
+ */
 template<typename TSrcIndex>
 static void read_indices(const tinygltf::Accessor &accessor,
                          const tinygltf::BufferView &buffer_view,
@@ -173,7 +176,9 @@ static void read_indices(const tinygltf::Accessor &accessor,
   }
 }
 
-/* Reads index data from a glTF primitive into a GHOST_XrPrimitive. */
+/**
+ * Reads index data from a glTF primitive into a GHOST_XrPrimitive.
+ */
 static void load_index_accessor(const tinygltf::Model &gltf_model,
                                 const tinygltf::Accessor &accessor,
                                 GHOST_XrPrimitive &primitive)
@@ -227,7 +232,9 @@ static GHOST_XrPrimitive read_primitive(const tinygltf::Model &gltf_model,
   return primitive;
 }
 
-/* Calculate node local and world transforms. */
+/**
+ * Calculate node local and world transforms.
+ */
 static void calc_node_transforms(const tinygltf::Node &gltf_node,
                                  const float parent_transform[4][4],
                                  float r_local_transform[4][4],
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index ce5b93088b6..42dd6d2181b 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -666,7 +666,8 @@ typedef enum eRegionType {
   RGN_TYPE_EXECUTE = 10,
   RGN_TYPE_FOOTER = 11,
   RGN_TYPE_TOOL_HEADER = 12,
-  /* Region representing an XR headset's display (internally, corresponds to an XR surface). */
+  /* Region type used exclusively by internal code and add-ons to register draw callbacks to the XR
+     context (surface, mirror view). Does not represent any real region. */
   RGN_TYPE_XR = 13,
 
 #define RGN_TYPE_LEN (RGN_TYPE_XR + 1)
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index d1ff031f1e6..f64b6c5daca 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -2261,18 +2261,26 @@ static void rna_def_xr_session_state(BlenderRNA *brna)
   RNA_def_property_array(prop, 3);
   RNA_def_property_float_funcs(
       prop, "rna_XrSessionState_nav_location_get", "rna_XrSessionState_nav_location_set", NULL);
-  RNA_def_property_ui_text(prop, "Navigation Location", "VR navigation location in world space");
+  RNA_def_property_ui_text(
+      prop,
+      "Navigation Location",
+      "Location offset to apply to base pose when determining viewer location");
 
   prop = RNA_def_property(srna, "navigation_rotation", PROP_FLOAT, PROP_QUATERNION);
   RNA_def_property_array(prop, 4);
   RNA_def_property_float_funcs(
       prop, "rna_XrSessionState_nav_rotation_get", "rna_XrSessionState_nav_rotation_set", NULL);
-  RNA_def_property_ui_text(prop, "Navigation Rotation", "VR navigation rotation in world space");
+  RNA_def_property_ui_text(
+      prop,
+      "Navigation Rotation",
+      "Rotation offset to apply to base pose when determining viewer rotation");
 
   prop = RNA_def_property(srna, "navigation_scale", PROP_FLOAT, PROP_NONE);
   RNA_def_property_float_funcs(
       prop, "rna_XrSessionState_nav_scale_get", "rna_XrSessionState_nav_scale_set", NULL);
-  RNA_def_property_ui_text(prop, "Navigation Scale", "VR navigation scale in world space");
+  RNA_def_property_ui_text(prop,
+                           "Navigation Scale",
+                           "Scale multiplier to apply to base pose when determining viewer scale");
 }
 
 /** \} */
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_draw.c b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
index bbbf7a16c9f..3287e29cdcf 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_draw.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
@@ -244,162 +244,164 @@ static GPUBatch *wm_xr_controller_model_batch_create(GHOST_XrContextHandle xr_co
   return GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, ibo, GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX);
 }
 
-void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region), void *customdata)
+static void wm_xr_controller_model_draw(const XrSessionSettings *settings,
+                                        GHOST_XrContextHandle xr_context,
+                                        wmXrSessionState *state)
 {
-  const wmXrData *xr = customdata;
-  const XrSessionSettings *settings = &xr->session_settings;
-  wmXrSessionState *state = &xr->runtime->session_state;
-
-  /* Model. */
-  {
-    GHOST_XrContextHandle xr_context = xr->runtime->context;
-    GHOST_XrControllerModelData model_data;
-    float color[4];
-
-    switch (settings->controller_draw_style) {
-      case XR_CONTROLLER_DRAW_DARK:
-      case XR_CONTROLLER_DRAW_DARK_RAY:
-        color[0] = color[1] = color[2] = 0.0f, color[3] = 0.4f;
-        break;
-      case XR_CONTROLLER_DRAW_LIGHT:
-      case XR_CONTROLLER_DRAW_LIGHT_RAY:
-        color[0] = 0.422f, color[1] = 0.438f, color[2] = 0.446f, color[3] = 0.4f;
-        break;
-    }
-
-    GPU_depth_test(GPU_DEPTH_NONE);
-    GPU_blend(GPU_BLEND_ALPHA);
+  GHOST_XrControllerModelData model_data;
 
-    LISTBASE_FOREACH (wmXrController *, controller, &state->controllers) {
-      GPUBatch *model = controller->model;
-      if (!model) {
-        model = controller->model = wm_xr_controller_model_batch_create(
-            xr_context, controller->subaction_path);
-      }
+  float color[4];
+  switch (settings->controller_draw_style) {
+    case XR_CONTROLLER_DRAW_DARK:
+    case XR_CONTROLLER_DRAW_DARK_RAY:
+      color[0] = color[1] = color[2] = 0.0f, color[3] = 0.4f;
+      break;
+    case XR_CONTROLLER_DRAW_LIGHT:
+    case XR_CONTROLLER_DRAW_LIGHT_RAY:
+      color[0] = 0.422f, color[1] = 0.438f, color[2] = 0.446f, color[3] = 0.4f;
+      break;
+  }
 
-      if (model &&
-          GHOST_XrGetControllerModelData(xr_context, controller->subaction_path, &model_data) &&
-          model_data.count_components > 0) {
-        GPU_batch_program_set_builtin(model, GPU_SHADER_3D_UNIFORM_COLOR);
-        GPU_batch_uniform_4fv(model, "color", color);
+  GPU_depth_test(GPU_DEPTH_NONE);
+  GPU_blend(GPU_BLEND_ALPHA);
 
-        GPU_matrix_push();
-        GPU_matrix_mul(controller->grip_mat);
-        for (unsigned int component_idx = 0; component_idx < model_data.count_components;
-             ++component_idx) {
-          const GHOST_XrControllerModelComponent *component =
-              &model_data.components[component_idx];
-          GPU_matrix_push();
-          GPU_matrix_mul(component->transform);
-          GPU_batch_draw_range(model,
-                               model->elem ? component->index_offset : component->vertex_offset,
-                               model->elem ? component->index_count : component->vertex_count);
-          GPU_matrix_pop();
-        }
-        GPU_matrix_pop();
-      }
-      else {
-        /* Fallback. */
-        const float scale = 0.05f;
-        GPUBatch *sphere = GPU_batch_preset_sphere(2);
-        GPU_batch_program_set_builtin(sphere, GPU_SHADER_3D_UNIFORM_COLOR);
-        GPU_batch_uniform_4fv(sphere, "color", color);
+  LISTBASE_FOREACH (wmXrController *, controller, &state->controllers) {
+    GPUBatch *model = controller->model;
+    if (!model) {
+      model = controller->model = wm_xr_controller_model_batch_create(xr_context,
+                                                                      controller->subaction_path);
+    }
 
+    if (model &&
+        GHOST_XrGetControllerModelData(xr_context, controller->subaction_path, &model_data) &&
+        model_data.count_components > 0) {
+      GPU_batch_program_set_builtin(model, GPU_SHADER_3D_UNIFORM_COLOR);
+      GPU_batch_uniform_4fv(model, "color", color);
+
+      GPU_matrix_push();
+      GPU_matrix_mul(controller->grip_mat);
+      for (unsigned int component_idx = 0; component_idx < model_data.count_components;
+           ++component_idx) {
+        const GHOST_XrControllerModelComponent *component = &model_data.components[component_idx];
         GPU_matrix_push();
-        GPU_matrix_mul(controller->grip_mat);
-        GPU_matrix_scale_1f(scale);
-        GPU_batch_draw(sphere);
+        GPU_matrix_mul(component->transform);
+        GPU_batch_draw_range(model,
+                             model->elem ? component->index_offset : component->vertex_offset,
+                             model->elem ? component->index_count : component->vertex_count);
         GPU_matrix_pop();
       }
+      GPU_matrix_pop();
     }
-  }
-
-  /* Aim. */
-  {
-    bool draw_ray;
-
-    switch (settings->controller_draw_style) {
-      case XR_CONTROLLER_DRAW_DARK:
-      case XR_CONTROLLER_DRAW_LIGHT:
-        draw_ray = false;
-        break;
-      case XR_CONTROLLER_DRAW_DARK_RAY:
-      case XR_CONTROLLER_DRAW_LIGHT_RAY:
-        draw_ray = true;


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list