diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-10-08 20:02:49 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-10-08 20:02:49 +0400 |
commit | 0ba84b7124e17eda444d8fca856f2e5c252a59f0 (patch) | |
tree | 2034bf78113c666f471c5cae27be7b444add03f0 /source | |
parent | a62b806d70a8d4f9dacaa55aa32e9b00fee654e2 (diff) |
Operator to define render border from rendered image editor
This way it is possible to define render border directly from the image editor,
which is useful for at least three things:
- If viewport is really optimized out (simplified etc) then it might be hard to
guess which exact area you're mainly interested now.
- No need to switch to the viewport to do render border tweaks, could be useful
when doing compositing.
- If one need to look at particular pixel(s) which is real handy for debugging
render engines (both Cycles and BI).
Reviewers: campbellbarton, venomgfx
Reviewed By: venomgfx
Differential Revision: https://developer.blender.org/D820
Diffstat (limited to 'source')
4 files changed, 94 insertions, 0 deletions
diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h index 74a0a18b0c8..aecc43f4fdf 100644 --- a/source/blender/editors/space_image/image_intern.h +++ b/source/blender/editors/space_image/image_intern.h @@ -92,6 +92,8 @@ void IMAGE_OT_curves_point_set(struct wmOperatorType *ot); void IMAGE_OT_change_frame(struct wmOperatorType *ot); void IMAGE_OT_read_renderlayers(struct wmOperatorType *ot); +void IMAGE_OT_render_border(struct wmOperatorType *ot); +void IMAGE_OT_clear_render_border(struct wmOperatorType *ot); /* image_panels.c */ struct ImageUser *ntree_get_active_iuser(struct bNodeTree *ntree); diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 58b56e99119..df556f94f28 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -3101,3 +3101,88 @@ void IMAGE_OT_read_renderlayers(wmOperatorType *ot) /* flags */ ot->flag = 0; } + +/* ********************* Render border operator ****************** */ + +static int render_border_exec(bContext *C, wmOperator *op) +{ + ARegion *ar = CTX_wm_region(C); + Scene *scene = CTX_data_scene(C); + rctf border; + + /* get rectangle from operator */ + WM_operator_properties_border_to_rctf(op, &border); + UI_view2d_region_to_view_rctf(&ar->v2d, &border, &border); + + /* actually set border */ + CLAMP(border.xmin, 0.0f, 1.0f); + CLAMP(border.ymin, 0.0f, 1.0f); + CLAMP(border.xmax, 0.0f, 1.0f); + CLAMP(border.ymax, 0.0f, 1.0f); + scene->r.border = border; + + /* drawing a border surrounding the entire camera view switches off border rendering + * or the border covers no pixels */ + if ((border.xmin <= 0.0f && border.xmax >= 1.0f && + border.ymin <= 0.0f && border.ymax >= 1.0f) || + (border.xmin == border.xmax || border.ymin == border.ymax)) + { + scene->r.mode &= ~R_BORDER; + } + else { + scene->r.mode |= R_BORDER; + } + + WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, NULL); + + return OPERATOR_FINISHED; + +} + +void IMAGE_OT_render_border(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Render Border"; + ot->description = "Set the boundaries of the border render and enable border render"; + ot->idname = "IMAGE_OT_render_border"; + + /* api callbacks */ + ot->invoke = WM_border_select_invoke; + ot->exec = render_border_exec; + ot->modal = WM_border_select_modal; + ot->cancel = WM_border_select_cancel; + ot->poll = image_cycle_render_slot_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* rna */ + WM_operator_properties_border(ot); +} + +/* ********************* Clear render border operator ****************** */ + +static int clear_render_border_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Scene *scene = CTX_data_scene(C); + scene->r.mode &= ~R_BORDER; + WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, NULL); + BLI_rctf_init(&scene->r.border, 0.0f, 1.0f, 0.0f, 1.0f); + return OPERATOR_FINISHED; + +} + +void IMAGE_OT_clear_render_border(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Render Border"; + ot->description = "Clear the boundaries of the border render and disable border render"; + ot->idname = "IMAGE_OT_clear_render_border"; + + /* api callbacks */ + ot->exec = clear_render_border_exec; + ot->poll = image_cycle_render_slot_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index ab616bf592f..9cb82d8ca9d 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -257,6 +257,8 @@ static void image_operatortypes(void) WM_operatortype_append(IMAGE_OT_change_frame); WM_operatortype_append(IMAGE_OT_read_renderlayers); + WM_operatortype_append(IMAGE_OT_render_border); + WM_operatortype_append(IMAGE_OT_clear_render_border); } static void image_keymap(struct wmKeyConfig *keyconf) @@ -343,6 +345,10 @@ static void image_keymap(struct wmKeyConfig *keyconf) kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0); RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point"); RNA_string_set(kmi->ptr, "value", "CURSOR"); + + /* render border */ + WM_keymap_add_item(keymap, "IMAGE_OT_render_border", BKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "IMAGE_OT_clear_render_border", BKEY, KM_PRESS, KM_CTRL | KM_ALT, 0); } /* dropboxes */ diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index b9a79a85455..016446e0a63 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -4740,6 +4740,7 @@ static void gesture_border_modal_keymap(wmKeyConfig *keyconf) WM_modalkeymap_assign(keymap, "VIEW3D_OT_render_border"); WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_border"); WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom_border"); /* XXX TODO: zoom border should perhaps map rightmouse to zoom out instead of in+cancel */ + WM_modalkeymap_assign(keymap, "IMAGE_OT_render_border"); } /* zoom to border modal operators */ |