13#include <fmt/format.h>
39#include "RNA_prototypes.hh"
62 if (captures_prop ==
nullptr) {
102 float4 capture_orientation;
106 GHOST_XrPose capture_pose;
107 capture_pose.is_active =
true;
108 copy_v3_v3(capture_pose.position, capture_location);
109 copy_qt_qt(capture_pose.orientation_quat, capture_orientation);
118 .position = capture_location,
119 .orientation_quat = capture_orientation,
125 return std::make_optional(capture);
135 pose.is_active =
true;
152 return "/user/hand/left";
154 return "/user/hand/right";
177 switch (
state->viewfinder.active_mode) {
179 return "active_action_live";
181 return "active_action_playback";
183 return "active_action_confirm";
191 switch (
state->viewfinder.active_mode) {
193 return int(
state->viewfinder.active_action_live);
195 return int(
state->viewfinder.active_action_playback);
197 return int(
state->viewfinder.active_action_confirm);
206 wmXrActionData *actiondata =
static_cast<wmXrActionData *
>(
event->customdata);
220 const float render_x = scene_render_settings->
xsch * scene_render_settings->
xasp;
221 const float render_y = scene_render_settings->
ysch * scene_render_settings->
yasp;
222 const float render_aspect_ratio = render_y / render_x;
224 constexpr float minimum_width = 4.3f;
226 const float viewfinder_height = viewfinder_width * render_aspect_ratio;
228 rctf viewfinder_rect = {};
229 BLI_rctf_resize(&viewfinder_rect, viewfinder_width, viewfinder_height);
231 return viewfinder_rect;
242 const float viewfinder_height,
247 if (!viewfinder_controller) {
252 constexpr float base_controller_offset = -0.1f;
254 const float viewfinder_vertical_offset = base_controller_offset + height_offset;
257 float viewfinder_mat[4][4];
259 translate_m4(viewfinder_mat, 0.0f, 0.0f, viewfinder_vertical_offset);
267 float raw_capture_mat[4][4],
268 float r_smoothed_mat[4][4])
272 float raw_capture_position[3];
273 float raw_capture_orientation_quat[4];
274 mat4_to_loc_quat(raw_capture_position, raw_capture_orientation_quat, raw_capture_mat);
277 const double delta_t = current_time -
state->viewfinder.smoothing_delta_t;
280 constexpr double delta_t_threshold = 0.25;
282 if (
state->viewfinder.smoothing_delta_t != 0.0 && delta_t < delta_t_threshold) {
284 constexpr float movement_smoothing_speed = 25.0f;
285 const float clamped_delta =
min_ff(delta_t, 0.1f);
286 const float factor = 1.0f -
exp(-clamped_delta * movement_smoothing_speed);
289 state->viewfinder.capture_position,
290 raw_capture_position,
293 state->viewfinder.capture_orientation_quat,
294 raw_capture_orientation_quat,
300 copy_qt_qt(
state->viewfinder.capture_orientation_quat, raw_capture_orientation_quat);
303 state->viewfinder.smoothing_delta_t = current_time;
324 float viewfinder_render_viewmat[4][4] = {};
326 Camera *cam_render_data =
state->viewfinder.render_cam_data_id;
333 switch (
state->viewfinder.active_mode) {
338 float raw_capture_mat[4][4];
346 float viewfinder_capture_mat[4][4];
349 invert_m4_m4(viewfinder_render_viewmat, viewfinder_capture_mat);
351 cam_render_params.
lens =
state->viewfinder.capture_lens_focal;
354 cam_render_data->dof.aperture_fstop =
state->viewfinder.capture_dof_fstop;
355 cam_render_data->dof.focus_distance =
state->viewfinder.capture_dof_distance;
362 if (!capture.has_value()) {
369 cam_render_params.
lens = capture->lens_focal;
372 cam_render_data->dof.focus_distance = capture->dof_distance;
373 cam_render_data->dof.aperture_fstop = capture->dof_fstop;
386 render_settings->
xsch,
387 render_settings->
ysch,
388 render_settings->
xasp,
389 render_settings->
yasp);
397 float viewfinder_winmat[4][4];
413 Object viewfinder_cam_ob = {};
415 viewfinder_cam_ob.
data = id_cast<ID *>(cam_render_data);
420 &viewfinder_shading_settings,
427 viewfinder_draw_flags,
428 viewfinder_render_viewmat,
439 state->viewfinder.offscreen,
440 state->viewfinder.viewport);
459 const int2 win_size = {1600 * 2, 900 * 2};
460 const rcti winrct = {0, win_size[0] - 1, 0, win_size[1] - 1};
490 button_to_pixelrect(&rect, ®ion, block, &but);
493 draw_button(
C, ®ion, &style, &but, &rect);
523 const float tab_width =
UI_UNIT_X * 10.5f;
536 button_func_pushed_state_set(but, [&
state](
const ui::Button &) ->
bool {
540 but = uiDefBut(block,
551 button_func_pushed_state_set(but, [&
state](
const ui::Button &) ->
bool {
567 const std::string settings_left_side_label = fmt::format(
568 "Show active capture in space: {}",
569 state->viewfinder.playback_show_active_capture_in_space_enabled ?
"on" :
"off");
570 layout.
label(settings_left_side_label.c_str(), ICON_NONE);
573 layout.
label(
"Confirm: Delete this shot?", ICON_NONE);
596 std::string settings_right_side_label;
597 switch (
state->viewfinder.active_mode) {
600 settings_right_side_label = fmt::format(
601 "{:\xe2\x80\x87>3}mm DoF: {} d: {:\xe2\x80\x87<4.1f} f {:\xe2\x80\x87<3.1f}",
602 state->viewfinder.capture_lens_focal,
603 state->viewfinder.capture_dof_enabled ?
"on " :
"off",
604 state->viewfinder.capture_dof_distance,
605 state->viewfinder.capture_dof_fstop);
610 if (captures_len > 0) {
611 const int width = captures_len >= 10 ? 2 : 1;
612 const char *pad_prefix = captures_len < 10 ?
" " :
"";
613 settings_right_side_label = fmt::format(
"{}{:\xe2\x80\x87>{}} / {:\xe2\x80\x87>{}}",
626 layout.
label(settings_right_side_label.c_str(), ICON_NONE);
646 const char *active_action_label;
648 layout.
label(active_action_label, ICON_NONE);
706 layout.
label(
"No shots captured yet.", ICON_NONE);
716 const rctf &viewfinder_rect)
719 const auto draw_block = [&](BlockFuncPtr block_func,
float x_off,
float y_off) {
730 const float mode_tabs_x = viewfinder_rect.
xmin - 0.15f;
731 const float mode_tabs_y = viewfinder_rect.
ymax + 0.45f;
735 const float settings_left_label_x = viewfinder_rect.
xmin + 0.05f;
737 viewfinder_rect.
xmax - 3.7f :
738 viewfinder_rect.
xmax - 0.8f;
739 const float settings_label_y = viewfinder_rect.
ymax + 0.47f;
746 const float action_label_x = viewfinder_rect.
xmin + 0.05f;
747 const float action_label_y = viewfinder_rect.
ymin - 0.15f;
749 float action_enum_x = 0.0f;
750 switch (
state->viewfinder.active_mode) {
752 action_enum_x = viewfinder_rect.
xmax - 1.6f;
755 action_enum_x = viewfinder_rect.
xmax - 1.2f;
758 action_enum_x = viewfinder_rect.
xmax - 0.8f;
764 const float action_enum_y = viewfinder_rect.
ymin - 0.15f;
769 constexpr float missing_label_x = -1.1f;
770 constexpr float missing_label_y = 0.1f;
785 state->viewfinder.playback_show_active_capture_in_space_enabled ==
false)
791 if (!capture.has_value()) {
795 float capture_mat[4][4];
801 constexpr float sensor_fit_fac = 36 * 2;
802 const float focal = capture->lens_focal / sensor_fit_fac;
806 const float render_x = render_settings->
xsch * render_settings->
xasp;
807 const float render_y = render_settings->
ysch * render_settings->
yasp;
808 const float aspect_x = render_x < render_y ? render_x / render_y : 1;
809 const float aspect_y = render_x > render_y ? render_y / render_x : 1;
811 constexpr float base_aspect = 1.0f / 4.0f;
812 const float aspect[2] = {aspect_x * base_aspect, aspect_y * base_aspect};
814 const float corners[4][3] = {
815 {-aspect[0], -aspect[1], -focal},
816 {aspect[0], -aspect[1], -focal},
817 {aspect[0], aspect[1], -focal},
818 {-aspect[0], aspect[1], -focal},
821 constexpr float color[4] = {0.25f, 0.81f, 1.0f, 1.0f};
841 for (
int i = 0; i < 4; i++) {
851 for (
int i = 0; i < 4; i++) {
874 float background_col[3];
877 rctf background_rect = viewfinder_rect;
881 rctf outline_rect = viewfinder_rect;
884 rctf tabs_bg_rect = {.xmin = background_rect.
xmin,
885 .xmax = background_rect.
xmin + 4.55f,
886 .ymin = background_rect.
ymax - 0.3f,
887 .ymax = background_rect.
ymax + 0.45f};
912 const float color[4])
934 const rctf &viewfinder_rect)
946 constexpr rctf tex_uv = {0.0f, 1.0f, 0.0f, 1.0f};
947 constexpr float tex_color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
953 const rctf &viewfinder_rect)
961 const float width =
min_ff(logo_width, logo_height * logo_aspect);
963 rctf logo_rect = viewfinder_rect;
967 const rctf tex_uv = {1.0f, 0.0f, 0.0f, 1.0f};
980 rctf capture_rect = vf_rect;
1015 constexpr float base_col[4] = {1.0f, 1.0f, 0.0f, 0.8f};
1016 constexpr float focus_hit_col[4] = {0.0f, 1.0f, 1.0f, 0.8f};
1017 constexpr float focus_miss_col[4] = {1.0f, 0.0f, 0.0f, 0.8f};
1020 constexpr double focus_hit_time = 0.15;
1022 state->viewfinder.last_focus_hit_time;
1024 const float *crosshair_col = base_col;
1027 if (last_focus_hit_delta < focus_hit_time) {
1028 crosshair_col =
state->viewfinder.last_focus_hit_success ? focus_hit_col : focus_miss_col;
1034 immVertex2f(pos, center_x - crosshair_size, center_y);
1035 immVertex2f(pos, center_x + crosshair_size, center_y);
1037 immVertex2f(pos, center_x, center_y - crosshair_size);
1038 immVertex2f(pos, center_x, center_y + crosshair_size);
1047 const rctf &viewfinder_rect)
1051 state->viewfinder.last_flash_trigger_time = 0.0;
1055 constexpr double flash_duration_sec = 0.4;
1056 constexpr float full_flash_alpha = 0.3f;
1059 state->viewfinder.last_flash_trigger_time;
1061 if (last_flash_delta < flash_duration_sec) {
1062 const float flash_progress = last_flash_delta / flash_duration_sec;
1063 const float flash_alpha =
interpf(0.0f, full_flash_alpha, flash_progress);
1072 viewfinder_rect.
xmin,
1073 viewfinder_rect.
ymin,
1074 viewfinder_rect.
xmax,
1075 viewfinder_rect.
ymax);
1092 float viewfinder_mat[4][4];
Camera data-block and utility functions.
Platform independent time functions.
#define BLI_assert_unreachable()
#define SET_FLAG_FROM_TEST(value, test, flag)
constexpr const char * c_str() const
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
void get_color_3fv(int colorid, float col[3])
@ BLOCK_THEME_STYLE_POPUP
void widgetbase_draw_cache_begin()
void block_flag_enable(Block *block, int flag)
const uiStyle * style_get_dpi()
void widgetbase_draw_cache_end()
Block * block_begin(const bContext *C, ARegion *region, std::string name, EmbossType emboss)
void block_theme_style_set(Block *block, char theme_style)
void block_end(const bContext *C, Block *block, bool postpone_callbacks=false)
void draw_roundbox_3fv_alpha(const rctf *rect, bool filled, float rad, const float col[3], float alpha)
Layout & block_layout(Block *block, LayoutDirection direction, LayoutType type, int x, int y, int size, int em, int padding, const uiStyle *style)
void draw_roundbox_4fv(const rctf *rect, bool filled, float rad, const float col[4])
MINLINE float min_ff(float a, float b)
static float wm_xr_viewfinder_get_pp_overscan(const XrSessionSettings *settings)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static ui::Block * wm_xr_viewfinder_ui_settings_left_label_block(const bContext *C, const wmXrSessionState *state)
static void wm_xr_viewfinder_ui_draw_texture(gpu::Texture *texture, const rctf &rect, const rctf &uv, const float color[4])
void wm_xr_pose_to_mat(const GHOST_XrPose *pose, float r_mat[4][4])
void mat4_to_loc_quat(float loc[3], float quat[4], const float wmat[4][4])
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void GPU_matrix_scale_1f(float factor)
MINLINE void copy_v3_v3(float r[3], const float a[3])
PointerRNA RNA_id_pointer_create(ID *id)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
bool wm_xr_viewfinder_operator_event_match_hand(bContext *C, const wmEvent *event)
@ XR_VIEWFINDER_MODE_CONFIRM
@ XR_VIEWFINDER_MODE_PLAYBACK
@ XR_VIEWFINDER_MODE_LIVE
GPUVertFormat * immVertexFormat()
bool RNA_property_enum_name(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_name)
static rctf wm_xr_viewfinder_get_rect(const bContext *C, const XrSessionSettings *settings)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
static void wm_xr_viewfinder_gizmo_draw_capture_camera(const bContext *C, wmXrSessionState *state)
void BLI_rctf_resize(struct rctf *rect, float x, float y)
bContext * WM_xr_session_context_get(const wmXrData *xr)
void immBegin(GPUPrimType, uint vertex_len)
void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy)
static int wm_xr_viewfinder_get_active_action_idx(const wmXrSessionState *state)
@ V3D_OFSDRAW_SHOW_SELECTION
@ V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS
@ V3D_OFSDRAW_XR_SHOW_CONTROLLERS
@ V3D_OFSDRAW_XR_SHOW_CUSTOM_OVERLAYS
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
void GPU_depth_mask(bool depth)
@ GPU_SAMPLER_FILTERING_LINEAR
void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
void immUniformColor4fv(const float rgba[4])
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
static void wm_xr_viewfinder_ui_draw_background(const rctf &viewfinder_rect)
static ui::Block * wm_xr_viewfinder_ui_action_label_block(const bContext *C, const wmXrSessionState *state)
@ V3D_SHADING_DEPTH_OF_FIELD
static ui::Block * wm_xr_viewfinder_ui_mode_tabs_block(const bContext *C, const wmXrSessionState *state)
static GHOST_XrPose wm_xr_location_scouting_capture_to_ghost_pose(const XrLocationScoutingCapture &capture)
void GPU_matrix_mul(const float m[4][4])
@ GPU_BLEND_ALPHA_PREMULT
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
static ui::Block * wm_xr_viewfinder_ui_block_begin(const bContext *C, ui::EmbossType emboss)
VecBase< float, 4 > float4
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
@ XR_VIEWFINDER_HAND_LEFT
@ XR_VIEWFINDER_HAND_RIGHT
void BKE_camera_params_compute_matrix(CameraParams *params)
void wm_xr_viewfinder_render_view(wmXrData *xr_data)
void BLI_rctf_mul(struct rctf *rect, float factor)
static void wm_xr_viewfinder_ui_draw_capture_flash(wmXrSessionState *state, const rctf &viewfinder_rect)
VecBase< int32_t, 2 > int2
void immUniform1f(const char *name, float x)
bool wm_xr_location_scouting_is_captures_empty(Scene *scene)
void immVertex2f(uint attr_id, float x, float y)
void copy_qt_qt(float q[4], const float a[4])
void GPU_viewport_size_get_f(float coords[4])
void immAttr4fv(uint attr_id, const float data[4])
void interp_qt_qtqt(float q[4], const float a[4], const float b[4], float t)
@ GPU_SHADER_3D_POLYLINE_FLAT_COLOR
@ GPU_SHADER_3D_IMAGE_COLOR
@ GPU_SHADER_3D_UNIFORM_COLOR
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
wmWindowManager * CTX_wm_manager(const bContext *C)
@ XR_VIEWFINDER_ACTION_LIVE_APERTURE
@ XR_VIEWFINDER_ACTION_LIVE_DOF
@ XR_VIEWFINDER_ACTION_LIVE_LENS
@ XR_VIEWFINDER_ACTION_LIVE_FOCUS
static void wm_xr_viewfinder_transform_update_smoothed(wmXrSessionState *state, float raw_capture_mat[4][4], float r_smoothed_mat[4][4])
int GPU_texture_width(const gpu::Texture *texture)
void immUniformColor4f(float r, float g, float b, float a)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph, Scene *scene, View3DShading *shading_override, bContext *context, eDrawType drawtype, int object_type_exclude_viewport_override, int object_type_exclude_select_override, int winx, int winy, unsigned int draw_flags, const float viewmat[4][4], const float winmat[4][4], float clip_start, float clip_end, float xr_vignette_aperture, bool is_xr_surface, bool is_image_render, bool draw_background, const char *viewname, bool do_color_management, Object *camera_override, GPUOffScreen *ofs, GPUViewport *viewport)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void immRectf_with_texco(uint pos, uint tex_coord, const rctf &p, const rctf &uv)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void immBindTextureSampler(const char *name, gpu::Texture *tex, GPUSamplerState state)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
static ui::Block * wm_xr_viewfinder_ui_action_enum_block(const bContext *C, const wmXrSessionState *state)
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_collection_is_empty(PointerRNA *ptr, PropertyRNA *prop)
void immVertex3fv(uint attr_id, const float data[3])
void rotate_m4(float mat[4][4], char axis, float angle)
gpu::Texture * GPU_offscreen_color_texture(const GPUOffScreen *offscreen)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
void wm_xr_pose_to_imat(const GHOST_XrPose *pose, float r_imat[4][4])
void wm_xr_viewfinder_draw(const bContext *C, const XrSessionSettings *settings, wmXrSessionState *state)
int GPU_texture_height(const gpu::Texture *texture)
static ui::Block * wm_xr_viewfinder_ui_missing_captures_label_block(const bContext *C, const wmXrSessionState *state)
static void wm_xr_viewfinder_ui_draw_capture_overlays(const XrSessionSettings *settings, const wmXrSessionState *state, const rctf &vf_rect)
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
static void wm_xr_viewfinder_ui_draw_backside_logo_texture(const wmXrSessionState *state, const rctf &viewfinder_rect)
static void wm_xr_viewfinder_ui_draw_view_texture(const bContext *C, const wmXrSessionState *state, const rctf &viewfinder_rect)
bool RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
static void wm_xr_viewfinder_ui_block_draw(const bContext *C, ui::Block *block)
void BLI_rctf_translate(struct rctf *rect, float x, float y)
MINLINE float interpf(float target, float origin, float t)
double BLI_time_now_seconds()
void wmGetProjectionMatrix(float mat[4][4], const rcti *winrct)
static wmXrController * wm_xr_viewfinder_get_controller(const XrSessionSettings *settings, const wmXrSessionState *state)
Scene * CTX_data_scene(const bContext *C)
void immUniform2fv(const char *name, const float data[2])
void immVertex3f(uint attr_id, float x, float y, float z)
void GPU_blend(GPUBlend blend)
std::optional< XrLocationScoutingCapture > wm_xr_location_scouting_get_active_capture(Scene *scene)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void GPU_matrix_translate_3f(float x, float y, float z)
static StringRefNull wm_xr_viewfinder_get_active_mode_str(const wmXrSessionState *state)
VecBase< float, 3 > float3
void BKE_camera_params_init(CameraParams *params)
static void wm_xr_viewfinder_ui_draw_widgets(const bContext *C, const wmXrSessionState *state, const rctf &viewfinder_rect)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
void GPU_depth_test(GPUDepthTest test)
static bool wm_xr_viewfinder_get_capture_mat(const XrSessionSettings *settings, const wmXrSessionState *state, const float viewfinder_height, float r_mat[4][4])
static ui::Layout & wm_xr_viewfinder_ui_layout(ui::Block *block)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
void BLI_rctf_pad(struct rctf *rect, float pad_x, float pad_y)
void quat_to_mat4(float m[4][4], const float q[4])
static const char * wm_xr_viewfinder_get_hand_user_path(const XrSessionSettings *settings)
static ui::Block * wm_xr_viewfinder_ui_settings_right_label_block(const bContext *C, const wmXrSessionState *state)
float viewfinder_passepartout_overscan
int object_type_exclude_select
char viewfinder_crosshair_enabled
int object_type_exclude_viewport
struct View3DShading shading
float viewfinder_passepartout_opacity
std::ranges::transform_view< std::ranges::ref_view< const Vector< std::unique_ptr< Button > > >, Button &(*)(const std::unique_ptr< Button > &)> buttons() const
void enabled_set(bool enabled)
void label(StringRef name, int icon)
void ui_units_x_set(float width)
void scale_x_set(float scale)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void scale_y_set(float scale)
void prop_enum(PointerRNA *ptr, PropertyRNA *prop, int value, std::optional< StringRefNull > name, int icon)
XrSessionSettings session_settings
struct wmXrRuntimeData * runtime
wmXrSessionState session_state
static constexpr int view_resolution
static constexpr float accent_color[4]
static constexpr float xr_ui_unit_fac