Fix T60133: texture paint external editing not working
authorPhilipp Oeser <info@graphics-engineer.com>
Wed, 23 Jan 2019 14:00:58 +0000 (15:00 +0100)
committerPhilipp Oeser <info@graphics-engineer.com>
Thu, 24 Jan 2019 14:34:44 +0000 (15:34 +0100)
Operator relys on 3DView and was failing from Topbar and Properties
Editor. Now tries to find the biggest 3DView and uses that.

Reviewers: brecht

Maniphest Tasks: T60133

Differential Revision: https://developer.blender.org/D4215

source/blender/editors/sculpt_paint/paint_image_proj.c

index 0a972e7..c6584a0 100644 (file)
@@ -79,6 +79,7 @@
 #include "BKE_paint.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
+#include "BKE_screen.h"
 #include "BKE_texture.h"
 
 #include "DEG_depsgraph.h"
@@ -5607,6 +5608,15 @@ void PAINT_OT_project_image(wmOperatorType *ot)
        ot->prop = prop;
 }
 
+static bool texture_paint_image_from_view_poll(bContext *C)
+{
+       if (BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0) == NULL) {
+               CTX_wm_operator_poll_msg_set(C, "No 3D viewport found to create image from");
+               return false;
+       }
+       return true;
+}
+
 static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
 {
        Image *image;
@@ -5617,13 +5627,24 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
        Depsgraph *depsgraph = CTX_data_depsgraph(C);
        Scene *scene = CTX_data_scene(C);
        ToolSettings *settings = scene->toolsettings;
-       View3D *v3d = CTX_wm_view3d(C);
-       RegionView3D *rv3d = CTX_wm_region_view3d(C);
        int w = settings->imapaint.screen_grab_size[0];
        int h = settings->imapaint.screen_grab_size[1];
        int maxsize;
        char err_out[256] = "unknown";
 
+       ScrArea *sa = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0);
+       if (!sa) {
+               BKE_report(op->reports, RPT_ERROR, "No 3D viewport found to create image from");
+               return OPERATOR_CANCELLED;
+       }
+       View3D *v3d = sa->spacedata.first;
+       ARegion *ar = BKE_area_find_region_active_win(sa);
+       if (!ar) {
+               BKE_report(op->reports, RPT_ERROR, "No 3D viewport found to create image from");
+               return OPERATOR_CANCELLED;
+       }
+       RegionView3D *rv3d = ar->regiondata;
+
        RNA_string_get(op->ptr, "filepath", filename);
 
        maxsize = GPU_max_texture_size();
@@ -5633,7 +5654,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
 
        ibuf = ED_view3d_draw_offscreen_imbuf(
                depsgraph, scene, v3d->shading.type,
-               v3d, CTX_wm_region(C),
+               v3d, ar,
                w, h, IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL,
                NULL, err_out);
        if (!ibuf) {
@@ -5680,11 +5701,11 @@ void PAINT_OT_image_from_view(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Image from View";
        ot->idname = "PAINT_OT_image_from_view";
-       ot->description = "Make an image from the current 3D view for re-projection";
+       ot->description = "Make an image from biggest 3D view for re-projection";
 
        /* api callbacks */
        ot->exec = texture_paint_image_from_view_exec;
-       ot->poll = ED_operator_region_view3d_active;
+       ot->poll = texture_paint_image_from_view_poll;
 
        /* flags */
        ot->flag = OPTYPE_REGISTER;