Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / sculpt_paint / paint_image_proj.c
index 8586eb42bec22c2e5c2bda3b0f8e4fcdc3a2490f..65f4618e43eb3997ac6be5c2e01be9bd0727ff13 100644 (file)
@@ -64,7 +64,6 @@
 #include "BKE_camera.h"
 #include "BKE_context.h"
 #include "BKE_colortools.h"
 #include "BKE_camera.h"
 #include "BKE_context.h"
 #include "BKE_colortools.h"
-#include "BKE_depsgraph.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_idprop.h"
 #include "BKE_brush.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_idprop.h"
 #include "BKE_brush.h"
@@ -80,6 +79,8 @@
 #include "BKE_scene.h"
 #include "BKE_texture.h"
 
 #include "BKE_scene.h"
 #include "BKE_texture.h"
 
+#include "DEG_depsgraph.h"
+
 #include "UI_interface.h"
 
 #include "ED_mesh.h"
 #include "UI_interface.h"
 
 #include "ED_mesh.h"
@@ -3420,12 +3421,15 @@ static void project_paint_bleed_add_face_user(
 #endif
 
 /* Return true if DM can be painted on, false otherwise */
 #endif
 
 /* Return true if DM can be painted on, false otherwise */
-static bool proj_paint_state_dm_init(ProjPaintState *ps)
+static bool proj_paint_state_dm_init(const bContext *C, ProjPaintState *ps)
 {
 {
+       EvaluationContext eval_ctx;
+       CTX_data_eval_ctx(C, &eval_ctx);
+
        /* Workaround for subsurf selection, try the display mesh first */
        if (ps->source == PROJ_SRC_IMAGE_CAM) {
                /* using render mesh, assume only camera was rendered from */
        /* Workaround for subsurf selection, try the display mesh first */
        if (ps->source == PROJ_SRC_IMAGE_CAM) {
                /* using render mesh, assume only camera was rendered from */
-               ps->dm = mesh_create_derived_render(ps->scene, ps->ob, ps->scene->customdata_mask | CD_MASK_MTFACE);
+               ps->dm = mesh_create_derived_render(&eval_ctx, ps->scene, ps->ob, ps->scene->customdata_mask | CD_MASK_MTFACE);
                ps->dm_release = true;
        }
        else if (ps->ob->derivedFinal &&
                ps->dm_release = true;
        }
        else if (ps->ob->derivedFinal &&
@@ -3437,7 +3441,7 @@ static bool proj_paint_state_dm_init(ProjPaintState *ps)
        }
        else {
                ps->dm = mesh_get_derived_final(
        }
        else {
                ps->dm = mesh_get_derived_final(
-                       ps->scene, ps->ob,
+                       &eval_ctx, ps->scene, ps->ob,
                        ps->scene->customdata_mask | CD_MASK_MTFACE | (ps->do_face_sel ? CD_ORIGINDEX : 0));
                ps->dm_release = true;
        }
                        ps->scene->customdata_mask | CD_MASK_MTFACE | (ps->do_face_sel ? CD_ORIGINDEX : 0));
                ps->dm_release = true;
        }
@@ -3487,7 +3491,7 @@ static void proj_paint_layer_clone_init(
 
        /* use clone mtface? */
        if (ps->do_layer_clone) {
 
        /* use clone mtface? */
        if (ps->do_layer_clone) {
-               const int layer_num = CustomData_get_clone_layer(&((Mesh *)ps->ob->data)->pdata, CD_MTEXPOLY);
+               const int layer_num = CustomData_get_clone_layer(&((Mesh *)ps->ob->data)->ldata, CD_MLOOPUV);
 
                ps->dm_mloopuv_clone = MEM_mallocN(ps->dm_totpoly * sizeof(MLoopUV *), "proj_paint_mtfaces");
 
 
                ps->dm_mloopuv_clone = MEM_mallocN(ps->dm_totpoly * sizeof(MLoopUV *), "proj_paint_mtfaces");
 
@@ -3817,7 +3821,7 @@ static void project_paint_prepare_all_faces(
 
 /* run once per stroke before projection painting */
 static void project_paint_begin(
 
 /* run once per stroke before projection painting */
 static void project_paint_begin(
-        ProjPaintState *ps,
+        const bContext *C, ProjPaintState *ps,
         const bool is_multi_view, const char symmetry_flag)
 {
        ProjPaintLayerClone layer_clone;
         const bool is_multi_view, const char symmetry_flag)
 {
        ProjPaintLayerClone layer_clone;
@@ -3840,7 +3844,7 @@ static void project_paint_begin(
 
        /* paint onto the derived mesh */
        if (ps->is_shared_user == false) {
 
        /* paint onto the derived mesh */
        if (ps->is_shared_user == false) {
-               if (!proj_paint_state_dm_init(ps)) {
+               if (!proj_paint_state_dm_init(C, ps)) {
                        return;
                }
        }
                        return;
                }
        }
@@ -3850,7 +3854,7 @@ static void project_paint_begin(
 
        if (ps->do_layer_stencil || ps->do_stencil_brush) {
                //int layer_num = CustomData_get_stencil_layer(&ps->dm->loopData, CD_MLOOPUV);
 
        if (ps->do_layer_stencil || ps->do_stencil_brush) {
                //int layer_num = CustomData_get_stencil_layer(&ps->dm->loopData, CD_MLOOPUV);
-               int layer_num = CustomData_get_stencil_layer(&((Mesh *)ps->ob->data)->pdata, CD_MTEXPOLY);
+               int layer_num = CustomData_get_stencil_layer(&((Mesh *)ps->ob->data)->ldata, CD_MLOOPUV);
                if (layer_num != -1)
                        ps->dm_mloopuv_stencil = CustomData_get_layer_n(&ps->dm->loopData, CD_MLOOPUV, layer_num);
 
                if (layer_num != -1)
                        ps->dm_mloopuv_stencil = CustomData_get_layer_n(&ps->dm->loopData, CD_MLOOPUV, layer_num);
 
@@ -3938,7 +3942,7 @@ static void project_paint_end(ProjPaintState *ps)
                ProjPaintImage *projIma;
                for (a = 0, projIma = ps->projImages; a < ps->image_tot; a++, projIma++) {
                        BKE_image_release_ibuf(projIma->ima, projIma->ibuf, NULL);
                ProjPaintImage *projIma;
                for (a = 0, projIma = ps->projImages; a < ps->image_tot; a++, projIma++) {
                        BKE_image_release_ibuf(projIma->ima, projIma->ibuf, NULL);
-                       DAG_id_tag_update(&projIma->ima->id, 0);
+                       DEG_id_tag_update(&projIma->ima->id, 0);
                }
        }
 
                }
        }
 
@@ -5024,6 +5028,7 @@ void paint_proj_stroke(
        /* clone gets special treatment here to avoid going through image initialization */
        if (ps_handle->is_clone_cursor_pick) {
                Scene *scene = ps_handle->scene;
        /* clone gets special treatment here to avoid going through image initialization */
        if (ps_handle->is_clone_cursor_pick) {
                Scene *scene = ps_handle->scene;
+               struct Depsgraph *graph = CTX_data_depsgraph(C);
                View3D *v3d = CTX_wm_view3d(C);
                ARegion *ar = CTX_wm_region(C);
                float *cursor = ED_view3d_cursor3d_get(scene, v3d);
                View3D *v3d = CTX_wm_view3d(C);
                ARegion *ar = CTX_wm_region(C);
                float *cursor = ED_view3d_cursor3d_get(scene, v3d);
@@ -5031,8 +5036,9 @@ void paint_proj_stroke(
 
                view3d_operator_needs_opengl(C);
 
 
                view3d_operator_needs_opengl(C);
 
-               if (!ED_view3d_autodist(scene, ar, v3d, mval_i, cursor, false, NULL))
+               if (!ED_view3d_autodist(C, graph, ar, v3d, mval_i, cursor, false, NULL)) {
                        return;
                        return;
+               }
 
                ED_region_tag_redraw(ar);
 
 
                ED_region_tag_redraw(ar);
 
@@ -5210,7 +5216,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m
 
                project_state_init(C, ob, ps, mode);
 
 
                project_state_init(C, ob, ps, mode);
 
-               if (ps->ob == NULL || !(ps->ob->lay & ps->v3d->lay)) {
+               if (ps->ob == NULL) {
                        ps_handle->ps_views_tot = i + 1;
                        goto fail;
                }
                        ps_handle->ps_views_tot = i + 1;
                        goto fail;
                }
@@ -5234,7 +5240,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m
                        PROJ_PAINT_STATE_SHARED_MEMCPY(ps, ps_handle->ps_views[0]);
                }
 
                        PROJ_PAINT_STATE_SHARED_MEMCPY(ps, ps_handle->ps_views[0]);
                }
 
-               project_paint_begin(ps, is_multi_view, symmetry_flag_views[i]);
+               project_paint_begin(C, ps, is_multi_view, symmetry_flag_views[i]);
 
                paint_proj_begin_clone(ps, mouse);
 
 
                paint_proj_begin_clone(ps, mouse);
 
@@ -5312,11 +5318,12 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
 {
        Image *image = BLI_findlink(&CTX_data_main(C)->image, RNA_enum_get(op->ptr, "image"));
        Scene *scene = CTX_data_scene(C);
 {
        Image *image = BLI_findlink(&CTX_data_main(C)->image, RNA_enum_get(op->ptr, "image"));
        Scene *scene = CTX_data_scene(C);
+       SceneLayer *sl = CTX_data_scene_layer(C);
        ProjPaintState ps = {NULL};
        int orig_brush_size;
        IDProperty *idgroup;
        IDProperty *view_data = NULL;
        ProjPaintState ps = {NULL};
        int orig_brush_size;
        IDProperty *idgroup;
        IDProperty *view_data = NULL;
-       Object *ob = OBACT;
+       Object *ob = OBACT_NEW;
        bool uvs, mat, tex;
 
        if (ob == NULL || ob->type != OB_MESH) {
        bool uvs, mat, tex;
 
        if (ob == NULL || ob->type != OB_MESH) {
@@ -5387,7 +5394,7 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
                                 ED_image_undo_restore, ED_image_undo_free, NULL);
 
        /* allocate and initialize spatial data structures */
                                 ED_image_undo_restore, ED_image_undo_free, NULL);
 
        /* allocate and initialize spatial data structures */
-       project_paint_begin(&ps, false, 0);
+       project_paint_begin(C, &ps, false, 0);
 
        if (ps.dm == NULL) {
                BKE_brush_size_set(scene, ps.brush, orig_brush_size);
 
        if (ps.dm == NULL) {
                BKE_brush_size_set(scene, ps.brush, orig_brush_size);
@@ -5445,12 +5452,16 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
        char filename[FILE_MAX];
 
        Scene *scene = CTX_data_scene(C);
        char filename[FILE_MAX];
 
        Scene *scene = CTX_data_scene(C);
+       SceneLayer *sl = CTX_data_scene_layer(C);
+       EvaluationContext eval_ctx;
        ToolSettings *settings = scene->toolsettings;
        int w = settings->imapaint.screen_grab_size[0];
        int h = settings->imapaint.screen_grab_size[1];
        int maxsize;
        char err_out[256] = "unknown";
 
        ToolSettings *settings = scene->toolsettings;
        int w = settings->imapaint.screen_grab_size[0];
        int h = settings->imapaint.screen_grab_size[1];
        int maxsize;
        char err_out[256] = "unknown";
 
+       CTX_data_eval_ctx(C, &eval_ctx);
+
        RNA_string_get(op->ptr, "filepath", filename);
 
        maxsize = GPU_max_texture_size();
        RNA_string_get(op->ptr, "filepath", filename);
 
        maxsize = GPU_max_texture_size();
@@ -5459,7 +5470,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
        if (h > maxsize) h = maxsize;
 
        ibuf = ED_view3d_draw_offscreen_imbuf(
        if (h > maxsize) h = maxsize;
 
        ibuf = ED_view3d_draw_offscreen_imbuf(
-               scene, CTX_wm_view3d(C), CTX_wm_region(C),
+               &eval_ctx, scene, sl, CTX_wm_view3d(C), CTX_wm_region(C),
                w, h, IB_rect, false, R_ALPHAPREMUL, 0, false, NULL,
                NULL, NULL, err_out);
        if (!ibuf) {
                w, h, IB_rect, false, R_ALPHAPREMUL, 0, false, NULL,
                NULL, NULL, err_out);
        if (!ibuf) {
@@ -5593,7 +5604,7 @@ bool BKE_paint_proj_mesh_data_check(Scene *scene, Object *ob, bool *uvs, bool *m
        }
        
        me = BKE_mesh_from_object(ob);
        }
        
        me = BKE_mesh_from_object(ob);
-       layernum = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
+       layernum = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
 
        if (layernum == 0) {
                hasuvs = false;
 
        if (layernum == 0) {
                hasuvs = false;
@@ -5742,7 +5753,7 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
                        BKE_texpaint_slot_refresh_cache(scene, ma);
                        BKE_image_signal(ima, NULL, IMA_SIGNAL_USER_NEW_IMAGE);
                        WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima);
                        BKE_texpaint_slot_refresh_cache(scene, ma);
                        BKE_image_signal(ima, NULL, IMA_SIGNAL_USER_NEW_IMAGE);
                        WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima);
-                       DAG_id_tag_update(&ma->id, 0);
+                       DEG_id_tag_update(&ma->id, 0);
                        ED_area_tag_redraw(CTX_wm_area(C));
                        
                        BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
                        ED_area_tag_redraw(CTX_wm_area(C));
                        
                        BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
@@ -5858,7 +5869,7 @@ static int texture_paint_delete_texture_paint_slot_exec(bContext *C, wmOperator
        ma->mtex[slot->index] = NULL;
        
        BKE_texpaint_slot_refresh_cache(scene, ma);
        ma->mtex[slot->index] = NULL;
        
        BKE_texpaint_slot_refresh_cache(scene, ma);
-       DAG_id_tag_update(&ma->id, 0);
+       DEG_id_tag_update(&ma->id, 0);
        WM_event_add_notifier(C, NC_MATERIAL, ma);
        /* we need a notifier for data change since we change the displayed modifier uvs */
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
        WM_event_add_notifier(C, NC_MATERIAL, ma);
        /* we need a notifier for data change since we change the displayed modifier uvs */
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -5916,7 +5927,7 @@ static int add_simple_uvs_exec(bContext *C, wmOperator *UNUSED(op))
 
        BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
        
 
        BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
        
-       DAG_id_tag_update(ob->data, 0);
+       DEG_id_tag_update(ob->data, 0);
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
        WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, scene);
        return OPERATOR_FINISHED;
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
        WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, scene);
        return OPERATOR_FINISHED;