[Bf-blender-cvs] [78563e9bf12] xr-actions-D9124: XR: Add "controller draw style" session setting
Peter Kim
noreply at git.blender.org
Thu Nov 26 05:33:34 CET 2020
Commit: 78563e9bf12a83d22083645a36ea61d370afaad8
Author: Peter Kim
Date: Wed Nov 25 22:57:33 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rB78563e9bf12a83d22083645a36ea61d370afaad8
XR: Add "controller draw style" session setting
Allows users to choose their preferred controller visualization
(controller local axes or -Z axis ray). The enum can be extended in
the future for additional visualizations.
===================================================================
M source/blender/makesdna/DNA_xr_types.h
M source/blender/makesrna/intern/rna_xr.c
M source/blender/windowmanager/xr/intern/wm_xr_actions.c
M source/blender/windowmanager/xr/intern/wm_xr_draw.c
M source/blender/windowmanager/xr/intern/wm_xr_intern.h
M source/blender/windowmanager/xr/intern/wm_xr_operators.c
M source/blender/windowmanager/xr/intern/wm_xr_session.c
===================================================================
diff --git a/source/blender/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index 49eeeabcd09..9bcd539a8b0 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -40,11 +40,12 @@ typedef struct XrSessionSettings {
/** View3D draw flags (V3D_OFSDRAW_NONE, V3D_OFSDRAW_SHOW_ANNOTATION, ...). */
char draw_flags;
-
- /** The eye (view) that will be used when projecting 3D to 2D (e.g. when performing GPU select).
- */
+ /** Draw style for controller visualization. */
+ char controller_draw_style;
+ /** The eye (view) used when projecting 3D to 2D (e.g. when performing GPU select). */
char selection_eye;
- char _pad2[2];
+
+ char _pad2;
/** Clipping distance. */
float clip_start, clip_end;
@@ -74,6 +75,11 @@ typedef enum eXRSessionBasePoseType {
XR_BASE_POSE_CUSTOM = 2,
} eXRSessionBasePoseType;
+typedef enum eXrSessionControllerDrawStyle {
+ XR_CONTROLLER_DRAW_AXES = 0,
+ XR_CONTROLLER_DRAW_RAY = 1,
+} eXrSessionControllerDrawStyle;
+
typedef enum eXrSessionEye {
XR_EYE_LEFT = 0,
XR_EYE_RIGHT = 1,
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index 7a2b80c5402..6c010f0304c 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -790,6 +790,12 @@ static void rna_def_xr_session_settings(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL},
};
+ static const EnumPropertyItem controller_draw_styles[] = {
+ {XR_CONTROLLER_DRAW_AXES, "AXES", 0, "Axes", "Draw controller's local axes"},
+ {XR_CONTROLLER_DRAW_RAY, "RAY", 0, "Ray", "Draw a ray along controller's -Z axis "},
+ {0, NULL, 0, NULL, NULL},
+ };
+
static const EnumPropertyItem selection_eyes[] = {
{XR_EYE_LEFT, "EYE_LEFT", 0, "Left Eye", "Use the left eye's perspective for VR selection"},
{XR_EYE_RIGHT,
@@ -866,6 +872,13 @@ static void rna_def_xr_session_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Show Custom Overlays", "Show custom VR overlays");
RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
+ prop = RNA_def_property(srna, "controller_draw_style", PROP_ENUM, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_enum_items(prop, controller_draw_styles);
+ RNA_def_property_ui_text(
+ prop, "Controller Draw Style", "Style to use when drawing VR controllers");
+ RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
+
prop = RNA_def_property(srna, "selection_eye", PROP_ENUM, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_enum_items(prop, selection_eyes);
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_actions.c b/source/blender/windowmanager/xr/intern/wm_xr_actions.c
index 70d46f3faf9..12bcc845d2d 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_actions.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_actions.c
@@ -355,8 +355,7 @@ bool WM_xr_active_action_set_set(wmXrData *xr, const char *action_set_name)
xr->runtime->session_state.active_action_set = action_set;
if (action_set->controller_pose_action) {
- wm_xr_session_controller_data_populate(action_set->controller_pose_action,
- &xr->runtime->session_state);
+ wm_xr_session_controller_data_populate(action_set->controller_pose_action, xr);
}
return true;
@@ -379,7 +378,7 @@ bool WM_xr_controller_pose_action_set(wmXrData *xr,
action_set->controller_pose_action = action;
if (action_set == xr->runtime->session_state.active_action_set) {
- wm_xr_session_controller_data_populate(action, &xr->runtime->session_state);
+ wm_xr_session_controller_data_populate(action, xr);
}
return true;
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_draw.c b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
index ef13d0ca320..14d07af0be0 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_draw.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
@@ -32,7 +32,9 @@
#include "GHOST_C-api.h"
+#include "GPU_batch_presets.h"
#include "GPU_immediate.h"
+#include "GPU_matrix.h"
#include "GPU_viewport.h"
#include "WM_api.h"
@@ -174,61 +176,116 @@ void wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view, void *customdata)
void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region), void *customdata)
{
- const wmXrSessionState *state = customdata;
-
- const eGPUDepthTest depth_test_prev = GPU_depth_test_get();
- GPU_depth_test(GPU_DEPTH_ALWAYS);
-
- /* For now, just draw controller axes. In the future this can be replaced
- * with actual controller geometry. */
- GPUVertFormat *format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- GPU_line_width(3.0f);
-
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
-
- const float r[4] = {1.0f, 0.2f, 0.322f, 1.0f};
- const float g[4] = {0.545f, 0.863f, 0.0f, 1.0f};
- const float b[4] = {0.157f, 0.565f, 1.0f, 1.0f};
-
- const float scale = 0.1f;
- float x_axis[3], y_axis[3], z_axis[3];
-
- for (int i = 0; i < 2; ++i) {
- const float(*mat)[4] = state->controllers[i].mat;
-
- normalize_v3_v3(x_axis, mat[0]);
- mul_v3_fl(x_axis, scale);
- add_v3_v3(x_axis, mat[3]);
-
- normalize_v3_v3(y_axis, mat[1]);
- mul_v3_fl(y_axis, scale);
- add_v3_v3(y_axis, mat[3]);
-
- normalize_v3_v3(z_axis, mat[2]);
- mul_v3_fl(z_axis, scale);
- add_v3_v3(z_axis, mat[3]);
-
- immBegin(GPU_PRIM_LINES, 2);
- immUniformColor4fv(r);
- immVertex3fv(pos, mat[3]);
- immVertex3fv(pos, x_axis);
- immEnd();
-
- immBegin(GPU_PRIM_LINES, 2);
- immUniformColor4fv(g);
- immVertex3fv(pos, mat[3]);
- immVertex3fv(pos, y_axis);
- immEnd();
-
- immBegin(GPU_PRIM_LINES, 2);
- immUniformColor4fv(b);
- immVertex3fv(pos, mat[3]);
- immVertex3fv(pos, z_axis);
- immEnd();
+ const wmXrData *xr = customdata;
+ const XrSessionSettings *settings = &xr->session_settings;
+ const wmXrSessionState *state = &xr->runtime->session_state;
+
+ switch (settings->controller_draw_style) {
+ case XR_CONTROLLER_DRAW_AXES: {
+ const float r[4] = {1.0f, 0.2f, 0.322f, 1.0f};
+ const float g[4] = {0.545f, 0.863f, 0.0f, 1.0f};
+ const float b[4] = {0.157f, 0.565f, 1.0f, 1.0f};
+ const float scale = 0.1f;
+ float x_axis[3], y_axis[3], z_axis[3];
+
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ GPU_depth_test(GPU_DEPTH_NONE);
+ GPU_blend(GPU_BLEND_NONE);
+ GPU_line_width(3.0f);
+
+ for (int i = 0; i < 2; ++i) {
+ const float(*mat)[4] = state->controllers[i].mat;
+ normalize_v3_v3(x_axis, mat[0]);
+ mul_v3_fl(x_axis, scale);
+ add_v3_v3(x_axis, mat[3]);
+
+ normalize_v3_v3(y_axis, mat[1]);
+ mul_v3_fl(y_axis, scale);
+ add_v3_v3(y_axis, mat[3]);
+
+ normalize_v3_v3(z_axis, mat[2]);
+ mul_v3_fl(z_axis, scale);
+ add_v3_v3(z_axis, mat[3]);
+
+ immBegin(GPU_PRIM_LINES, 2);
+ immUniformColor4fv(r);
+ immVertex3fv(pos, mat[3]);
+ immVertex3fv(pos, x_axis);
+ immEnd();
+
+ immBegin(GPU_PRIM_LINES, 2);
+ immUniformColor4fv(g);
+ immVertex3fv(pos, mat[3]);
+ immVertex3fv(pos, y_axis);
+ immEnd();
+
+ immBegin(GPU_PRIM_LINES, 2);
+ immUniformColor4fv(b);
+ immVertex3fv(pos, mat[3]);
+ immVertex3fv(pos, z_axis);
+ immEnd();
+ }
+
+ immUnbindProgram();
+ break;
+ }
+ case XR_CONTROLLER_DRAW_RAY: {
+ /* Sphere. */
+ {
+ const float color[4] = {0.5f, 0.5f, 0.5f, 0.5f};
+ 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);
+
+ GPU_depth_test(GPU_DEPTH_NONE);
+ GPU_blend(GPU_BLEND_ALPHA);
+
+ for (int i = 0; i < 2; ++i) {
+ GPU_matrix_push();
+ GPU_matrix_mul(state->controllers[i].mat);
+ GPU_matrix_scale_1f(scale);
+ GPU_batch_draw(sphere);
+ GPU_matrix_pop();
+ }
+ }
+
+ /* Ray. */
+ {
+ const float color[4] = {0.863f, 0.0f, 0.545f, 0.5f};
+ const float scale = settings->clip_end;
+ float ray[3];
+
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor4fv(color);
+
+ GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
+ GPU_line_width(3.0f);
+
+ for (int i = 0; i < 2; ++i) {
+ const float(*mat)[4] = state->controllers[i].mat;
+ normalize_v3_v3(ray, mat[2]);
+ mul_v3_fl(ray, -scale);
+ add_v3_v3(ray, mat[3]);
+
+ immBegin(GPU_PRIM_LINES, 2);
+ immVertex3fv(pos, mat[3]);
+ immVertex3fv(pos, ray);
+ immEnd();
+ }
+
+ immUnbindProgram();
+ }
+ break;
+ }
+ default: {
+ break;
+ }
}
-
- immUnbindProgram();
-
- GPU_depth_test(depth_test_prev);
}
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_intern.h b/source/blender/windowmanager/xr/intern/wm_xr_intern.h
index 7c1d3a56b39..18c9f7b2b4d 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_intern.h
+++ b/source/blender/windowmanager/xr/intern/wm_xr_intern.h
@@ -186,7 +186,7 @@ void wm_xr_session_actions_init(wmXrData *xr);
void wm_xr_session_actions_update(wmXrData *xr);
void wm_xr_session_actions_uninit(wmXrData *xr);
void wm_xr_session_controller_data_populate(const wmXrAction *controller_pose_action,
- wmXrSessionState *state);
+ wmXrData *xr);
void wm_xr_session_controller_data_clear(wmXrSessionState *state);
voi
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list