diff options
author | Peter Kim <pk15950@gmail.com> | 2021-10-12 10:18:05 +0300 |
---|---|---|
committer | Peter Kim <pk15950@gmail.com> | 2021-10-12 10:18:05 +0300 |
commit | 9dda65455b54336fe3efef91eba9e41866dac1c1 (patch) | |
tree | 2f8fd6edf8d190e018b63c6b6bdacb38ab7905bd /source/blender/editors | |
parent | cfa59b3fabe729e49a57154ce21c5a4b88aa5812 (diff) |
XR Controller Support Step 4: Controller Drawing
Addresses T77127 (Controller Drawing).
Adds VR controller visualization and custom drawing via draw
handlers. Add-ons can draw to the XR surface (headset display) and
mirror window by adding a View3D draw handler of region type 'XR' and
draw type 'POST_VIEW'. Controller drawing and custom overlays can be
toggled individually as XR session options, which will be added in a
future update to the VR Scene Inspection add-on.
For the actual drawing, the OpenXR XR_MSFT_controller_model extension
is used to load a glTF model provided by the XR runtime. The model's
vertex data is then used to create a GPUBatch in the XR session
state. Finally, this batch is drawn via the XR surface draw handler
mentioned above.
For runtimes that do not support the controller model extension, a
a simple fallback shape (sphere) is drawn instead.
Reviewed By: Severin, fclem
Differential Revision: https://developer.blender.org/D10948
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_space_api.h | 5 | ||||
-rw-r--r-- | source/blender/editors/include/ED_view3d_offscreen.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_api/spacetypes.c | 14 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/space_view3d.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 48 |
5 files changed, 58 insertions, 17 deletions
diff --git a/source/blender/editors/include/ED_space_api.h b/source/blender/editors/include/ED_space_api.h index 1a3aa7e5496..958df8f7707 100644 --- a/source/blender/editors/include/ED_space_api.h +++ b/source/blender/editors/include/ED_space_api.h @@ -72,8 +72,9 @@ void *ED_region_draw_cb_activate(struct ARegionType *art, void (*draw)(const struct bContext *, struct ARegion *, void *), void *customdata, int type); -void ED_region_draw_cb_draw(const struct bContext *, struct ARegion *, int); -void ED_region_draw_cb_exit(struct ARegionType *, void *); +void ED_region_draw_cb_draw(const struct bContext *C, struct ARegion *region, int type); +void ED_region_surface_draw_cb_draw(struct ARegionType *art, int type); +void ED_region_draw_cb_exit(struct ARegionType *art, void *handle); void ED_region_draw_cb_remove_by_type(struct ARegionType *art, void *draw_fn, void (*free)(void *)); diff --git a/source/blender/editors/include/ED_view3d_offscreen.h b/source/blender/editors/include/ED_view3d_offscreen.h index c490e96031f..8b695e61a35 100644 --- a/source/blender/editors/include/ED_view3d_offscreen.h +++ b/source/blender/editors/include/ED_view3d_offscreen.h @@ -60,7 +60,7 @@ void ED_view3d_draw_offscreen(struct Depsgraph *depsgraph, void ED_view3d_draw_offscreen_simple(struct Depsgraph *depsgraph, struct Scene *scene, struct View3DShading *shading_override, - int drawtype, + eDrawType drawtype, int winx, int winy, unsigned int draw_flags, @@ -68,6 +68,7 @@ void ED_view3d_draw_offscreen_simple(struct Depsgraph *depsgraph, const float winmat[4][4], float clip_start, float clip_end, + bool is_xr_surface, bool is_image_render, bool draw_background, const char *viewname, diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c index 3da283089c5..149067a94fe 100644 --- a/source/blender/editors/space_api/spacetypes.c +++ b/source/blender/editors/space_api/spacetypes.c @@ -264,9 +264,9 @@ void ED_region_draw_cb_exit(ARegionType *art, void *handle) } } -void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type) +static void ed_region_draw_cb_draw(const bContext *C, ARegion *region, ARegionType *art, int type) { - LISTBASE_FOREACH_MUTABLE (RegionDrawCB *, rdc, ®ion->type->drawcalls) { + LISTBASE_FOREACH_MUTABLE (RegionDrawCB *, rdc, &art->drawcalls) { if (rdc->type == type) { rdc->draw(C, region, rdc->customdata); @@ -276,6 +276,16 @@ void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type) } } +void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type) +{ + ed_region_draw_cb_draw(C, region, region->type, type); +} + +void ED_region_surface_draw_cb_draw(ARegionType *art, int type) +{ + ed_region_draw_cb_draw(NULL, NULL, art, type); +} + void ED_region_draw_cb_remove_by_type(ARegionType *art, void *draw_fn, void (*free)(void *)) { LISTBASE_FOREACH_MUTABLE (RegionDrawCB *, rdc, &art->drawcalls) { diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index f68a4d78a00..bedc24a6287 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -1798,5 +1798,10 @@ void ED_spacetype_view3d(void) art = ED_area_type_hud(st->spaceid); BLI_addhead(&st->regiontypes, art); + /* regions: xr */ + art = MEM_callocN(sizeof(ARegionType), "spacetype view3d xr region"); + art->regionid = RGN_TYPE_XR; + BLI_addhead(&st->regiontypes, art); + BKE_spacetype_register(st); } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 733ec7e81cd..4da24888e1d 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -339,7 +339,16 @@ static void view3d_xr_mirror_setup(const wmWindowManager *wm, } view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, NULL, rect); - /* Reset overridden View3D data */ + /* Set draw flags. */ + SET_FLAG_FROM_TEST(v3d->flag2, + (wm->xr.session_settings.draw_flags & V3D_OFSDRAW_XR_SHOW_CONTROLLERS) != 0, + V3D_XR_SHOW_CONTROLLERS); + SET_FLAG_FROM_TEST(v3d->flag2, + (wm->xr.session_settings.draw_flags & V3D_OFSDRAW_XR_SHOW_CUSTOM_OVERLAYS) != + 0, + V3D_XR_SHOW_CUSTOM_OVERLAYS); + + /* Reset overridden View3D data. */ v3d->lens = lens_old; } #endif /* WITH_XR_OPENXR */ @@ -1757,6 +1766,7 @@ void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph, const float winmat[4][4], float clip_start, float clip_end, + bool is_xr_surface, bool is_image_render, bool draw_background, const char *viewname, @@ -1786,23 +1796,37 @@ void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph, v3d.shading.flag = V3D_SHADING_SCENE_WORLD | V3D_SHADING_SCENE_LIGHTS; } - if (draw_flags & V3D_OFSDRAW_SHOW_ANNOTATION) { - v3d.flag2 |= V3D_SHOW_ANNOTATION; + if ((draw_flags & ~V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS) == V3D_OFSDRAW_NONE) { + v3d.flag2 = V3D_HIDE_OVERLAYS; } - if (draw_flags & V3D_OFSDRAW_SHOW_GRIDFLOOR) { - v3d.gridflag |= V3D_SHOW_FLOOR | V3D_SHOW_X | V3D_SHOW_Y; - v3d.grid = 1.0f; - v3d.gridlines = 16; - v3d.gridsubdiv = 10; - - /* Show grid, disable other overlays (set all available _HIDE_ flags). */ + else { + if (draw_flags & V3D_OFSDRAW_SHOW_ANNOTATION) { + v3d.flag2 |= V3D_SHOW_ANNOTATION; + } + if (draw_flags & V3D_OFSDRAW_SHOW_GRIDFLOOR) { + v3d.gridflag |= V3D_SHOW_FLOOR | V3D_SHOW_X | V3D_SHOW_Y; + v3d.grid = 1.0f; + v3d.gridlines = 16; + v3d.gridsubdiv = 10; + } + if (draw_flags & V3D_OFSDRAW_SHOW_SELECTION) { + v3d.flag |= V3D_SELECT_OUTLINE; + } + if (draw_flags & V3D_OFSDRAW_XR_SHOW_CONTROLLERS) { + v3d.flag2 |= V3D_XR_SHOW_CONTROLLERS; + } + if (draw_flags & V3D_OFSDRAW_XR_SHOW_CUSTOM_OVERLAYS) { + v3d.flag2 |= V3D_XR_SHOW_CUSTOM_OVERLAYS; + } + /* Disable other overlays (set all available _HIDE_ flags). */ v3d.overlay.flag |= V3D_OVERLAY_HIDE_CURSOR | V3D_OVERLAY_HIDE_TEXT | V3D_OVERLAY_HIDE_MOTION_PATHS | V3D_OVERLAY_HIDE_BONES | V3D_OVERLAY_HIDE_OBJECT_XTRAS | V3D_OVERLAY_HIDE_OBJECT_ORIGINS; v3d.flag |= V3D_HIDE_HELPLINES; } - else { - v3d.flag2 = V3D_HIDE_OVERLAYS; + + if (is_xr_surface) { + v3d.flag |= V3D_XR_SESSION_SURFACE; } rv3d.persp = RV3D_PERSP; |