Merge branch 'master' into blender2.8
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 11 Jun 2018 12:39:38 +0000 (14:39 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 11 Jun 2018 12:39:38 +0000 (14:39 +0200)
Conflicts:
intern/cycles/blender/blender_object.cpp
source/blender/alembic/intern/abc_exporter.cc
source/blender/alembic/intern/abc_mball.cc
source/blender/alembic/intern/abc_mball.h
source/blender/blenkernel/BKE_anim.h
source/blender/blenkernel/BKE_displist.h
source/blender/blenkernel/BKE_dynamicpaint.h
source/blender/blenkernel/BKE_group.h
source/blender/blenkernel/BKE_mball.h
source/blender/blenkernel/BKE_mball_tessellate.h
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/BKE_scene.h
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/dynamicpaint.c
source/blender/blenkernel/intern/group.c
source/blender/blenkernel/intern/mball.c
source/blender/blenkernel/intern/mball_tessellate.c
source/blender/blenkernel/intern/mesh_convert.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/object_dupli.c
source/blender/blenkernel/intern/object_update.c
source/blender/blenkernel/intern/pointcache.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/smoke.c
source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
source/blender/depsgraph/intern/builder/deg_builder_relations.cc
source/blender/editors/include/ED_object.h
source/blender/editors/object/object_add.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_modifier.c
source/blender/editors/physics/dynamicpaint_ops.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt_uv.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_snap_object.c
source/blender/editors/util/ed_util.c
source/blender/gpu/intern/gpu_material.c
source/blender/makesrna/intern/rna_meta.c
source/blender/makesrna/intern/rna_object_api.c
source/blender/modifiers/intern/MOD_dynamicpaint.c
source/blenderplayer/bad_level_call_stubs/stubs.c

25 files changed:
1  2 
source/blender/blenkernel/BKE_displist.h
source/blender/blenkernel/BKE_dynamicpaint.h
source/blender/blenkernel/BKE_global.h
source/blender/blenkernel/BKE_mball_tessellate.h
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/dynamicpaint.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/mball_tessellate.c
source/blender/blenkernel/intern/object_dupli.c
source/blender/blenkernel/intern/object_update.c
source/blender/blenkernel/intern/paint.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/smoke.c
source/blender/editors/include/ED_image.h
source/blender/editors/include/ED_object.h
source/blender/editors/object/object_edit.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/sculpt_paint/sculpt_uv.c
source/blender/editors/util/ed_util.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c

@@@ -57,11 -57,12 +57,12 @@@ enum 
  
  /* prototypes */
  
- struct Scene;
- struct Object;
- struct ListBase;
 +struct Depsgraph;
  struct DerivedMesh;
 -struct EvaluationContext;
+ struct ListBase;
+ struct Main;
+ struct Object;
+ struct Scene;
  
  /* used for curves, nurbs, mball, importing */
  typedef struct DispList {
   *  \ingroup bke
   */
  
 -struct EvaluationContext;
 +struct Depsgraph;
+ struct Main;
  struct Scene;
 +struct ViewLayer;
  
  /* Actual surface point       */
  typedef struct PaintSurfaceData {
@@@ -86,7 -87,10 +87,9 @@@ struct DynamicPaintSurface *get_activeS
  
  /* image sequence baking */
  int dynamicPaint_createUVSurface(struct Scene *scene, struct DynamicPaintSurface *surface, float *progress, short *do_update);
- int dynamicPaint_calculateFrame(struct DynamicPaintSurface *surface, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *cObject, int frame);
+ int dynamicPaint_calculateFrame(
 -        struct Main *bmain,
 -        struct EvaluationContext *eval_ctx, struct DynamicPaintSurface *surface, struct Scene *scene,
 -        struct Object *cObject, int frame);
++        struct DynamicPaintSurface *surface, struct Depsgraph *depsgraph,
++        struct Scene *scene, struct Object *cObject, int frame);
  void dynamicPaint_outputSurfaceImage(struct DynamicPaintSurface *surface, char *filename, short output_layer);
  
  /* PaintPoint state */
@@@ -23,7 -23,8 +23,8 @@@
  /** \file BKE_mball_tessellate.h
   *  \ingroup bke
   */
 -struct EvaluationContext;
 +struct Depsgraph;
+ struct Main;
  struct Object;
  struct Scene;
  
@@@ -245,28 -223,19 +245,26 @@@ void BKE_object_eval_transform_all
          struct Scene *scene,
          struct Object *object);
  
 -void BKE_object_handle_data_update(
 -        struct Main *bmain,
 -        struct EvaluationContext *eval_ctx,
 -        struct Scene *scene,
 -        struct Object *ob);
 -void BKE_object_handle_update(
 -        struct Main *bmain,
 -        struct EvaluationContext *eval_ctx,
 +void BKE_object_eval_update_shading(
 +        struct Depsgraph *depsgraph,
 +        struct Object *object);
 +void BKE_object_data_select_update(
 +        struct Depsgraph *depsgraph,
 +        struct ID *object_data);
 +
 +void BKE_object_eval_flush_base_flags(
 +        struct Depsgraph *depsgraph,
 +        struct Scene *scene, const int view_layer_index,
 +        struct Object *object, int base_index,
 +        const bool is_from_set);
 +
- void BKE_object_handle_data_update(
-         struct Depsgraph *depsgraph,
++void BKE_object_handle_data_update(struct Depsgraph *depsgraph,
          struct Scene *scene,
          struct Object *ob);
- void BKE_object_handle_update(
-         struct Depsgraph *depsgraph,
++void BKE_object_handle_update(struct Depsgraph *depsgraph,
 +        struct Scene *scene, struct Object *ob);
  void BKE_object_handle_update_ex(
 -        struct Main *bmain,
 -        struct EvaluationContext *eval_ctx,
 +        struct Depsgraph *depsgraph,
          struct Scene *scene, struct Object *ob,
          struct RigidBodyWorld *rbw,
          const bool do_proxy_update);
Simple merge
  #include "BKE_displist.h"
  #include "BKE_cdderivedmesh.h"
  #include "BKE_object.h"
 +#include "BKE_library.h"
+ #include "BKE_main.h"
  #include "BKE_mball.h"
  #include "BKE_mball_tessellate.h"
 +#include "BKE_mesh.h"
  #include "BKE_curve.h"
  #include "BKE_key.h"
  #include "BKE_anim.h"
@@@ -3645,7 -3746,7 +3645,7 @@@ static void dynamic_paint_brush_velocit
  }
  
  static void dynamicPaint_brushMeshCalculateVelocity(
-         struct Depsgraph *depsgraph, Scene *scene,
 -        Main *bmain, EvaluationContext *eval_ctx, Scene *scene,
++        Depsgraph *depsgraph, Scene *scene,
          Object *ob, DynamicPaintBrushSettings *brush, Vec3f **brushVel, float timescale)
  {
        float prev_obmat[4][4];
  }
  
  /* calculate velocity for object center point */
- static void dynamicPaint_brushObjectCalculateVelocity(struct Depsgraph *depsgraph, Scene *scene, Object *ob, Vec3f *brushVel, float timescale)
+ static void dynamicPaint_brushObjectCalculateVelocity(
 -        Main *bmain, EvaluationContext *eval_ctx, Scene *scene, Object *ob, Vec3f *brushVel, float timescale)
++        Depsgraph *depsgraph, Scene *scene, Object *ob, Vec3f *brushVel, float timescale)
  {
        float prev_obmat[4][4];
        float cur_loc[3] = {0.0f}, prev_loc[3] = {0.0f};
@@@ -4096,9 -4210,12 +4097,9 @@@ static void dynamic_paint_paint_mesh_ce
        }
  }
  
- static int dynamicPaint_paintMesh(struct Depsgraph *depsgraph, DynamicPaintSurface *surface,
 -static int dynamicPaint_paintMesh(Main *bmain,
 -                                  EvaluationContext *eval_ctx,
 -                                  DynamicPaintSurface *surface,
++static int dynamicPaint_paintMesh(Depsgraph *depsgraph, DynamicPaintSurface *surface,
                                    DynamicPaintBrushSettings *brush,
                                    Object *brushOb,
 -                                  BrushMaterials *bMats,
                                    Scene *scene,
                                    float timescale)
  {
@@@ -4584,8 -4718,8 +4585,8 @@@ static void dynamic_paint_paint_single_
  }
  
  static int dynamicPaint_paintSinglePoint(
-         struct Depsgraph *depsgraph, DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush,
 -        Main *bmain, EvaluationContext *eval_ctx, DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush,
 -        Object *brushOb, BrushMaterials *bMats, Scene *scene, float timescale)
++        Depsgraph *depsgraph, DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush,
 +        Object *brushOb, Scene *scene, float timescale)
  {
        PaintSurfaceData *sData = surface->data;
        float brush_radius = brush->paint_distance * surface->radius_scale;
@@@ -5882,7 -6016,9 +5883,9 @@@ static int dynamicPaint_generateBakeDat
  /*
   * Do Dynamic Paint step. Paints scene brush objects of current state/frame to the surface.
   */
- static int dynamicPaint_doStep(struct Depsgraph *depsgraph, Scene *scene, Object *ob, DynamicPaintSurface *surface, float timescale, float subframe)
+ static int dynamicPaint_doStep(
 -        Main *bmain, EvaluationContext *eval_ctx, Scene *scene,
++        Depsgraph *depsgraph, Scene *scene,
+         Object *ob, DynamicPaintSurface *surface, float timescale, float subframe)
  {
        PaintSurfaceData *sData = surface->data;
        PaintBakeData *bData = sData->bData;
  
  #include "BKE_global.h"
  
- #include "BKE_scene.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_displist.h"
+ #include "BKE_main.h"
  #include "BKE_mball_tessellate.h"  /* own include */
+ #include "BKE_scene.h"
  
 +#include "DEG_depsgraph.h"
 +#include "DEG_depsgraph_query.h"
 +
  #include "BLI_strict_flags.h"
  
  /* experimental (faster) normal calculation */
@@@ -98,15 -97,19 +98,17 @@@ typedef struct DupliGenerator 
  static const DupliGenerator *get_dupli_generator(const DupliContext *ctx);
  
  /* create initial context for root object */
- static void init_context(DupliContext *r_ctx, Depsgraph *depsgraph, Scene *scene, Object *ob, float space_mat[4][4])
+ static void init_context(
 -        DupliContext *r_ctx, Main *bmain, EvaluationContext *eval_ctx,
 -        Scene *scene, Object *ob, float space_mat[4][4], bool update)
++        DupliContext *r_ctx, Depsgraph *depsgraph,
++        Scene *scene, Object *ob, float space_mat[4][4])
  {
 -      r_ctx->eval_ctx = eval_ctx;
 -      r_ctx->bmain = bmain;
 +      r_ctx->depsgraph = depsgraph;
        r_ctx->scene = scene;
 -      /* don't allow BKE_object_handle_update for viewport during render, can crash */
 -      r_ctx->do_update = update && !(G.is_rendering && eval_ctx->mode != DAG_EVAL_RENDER);
 -      r_ctx->animated = false;
 -      r_ctx->group = NULL;
 +      r_ctx->view_layer = DEG_get_evaluated_view_layer(depsgraph);
 +      r_ctx->collection = NULL;
  
        r_ctx->object = ob;
 +      r_ctx->obedit = OBEDIT_FROM_OBACT(ob);
        if (space_mat)
                copy_m4_m4(r_ctx->space_mat, space_mat);
        else
  #include "BLI_blenlib.h"
  #include "BLI_utildefines.h"
  #include "BLI_math.h"
 -#include "BLI_threads.h"
  
- #include "BKE_global.h"
+ #include "BKE_animsys.h"
  #include "BKE_armature.h"
  #include "BKE_action.h"
  #include "BKE_constraint.h"
 -#include "BKE_depsgraph.h"
 +#include "BKE_curve.h"
  #include "BKE_DerivedMesh.h"
- #include "BKE_animsys.h"
  #include "BKE_displist.h"
+ #include "BKE_editmesh.h"
  #include "BKE_effect.h"
+ #include "BKE_global.h"
+ #include "BKE_image.h"
  #include "BKE_key.h"
  #include "BKE_lamp.h"
  #include "BKE_lattice.h"
- #include "BKE_editmesh.h"
 +#include "BKE_library.h"
+ #include "BKE_main.h"
+ #include "BKE_material.h"
++#include "BKE_mball.h"
++#include "BKE_mesh.h"
  #include "BKE_object.h"
  #include "BKE_particle.h"
  #include "BKE_pointcache.h"
  #include "BKE_scene.h"
- #include "BKE_material.h"
- #include "BKE_mball.h"
- #include "BKE_mesh.h"
- #include "BKE_image.h"
  
 +#include "MEM_guardedalloc.h"
 +
  #include "DEG_depsgraph.h"
 +#include "DEG_depsgraph_query.h"
  
 -static ThreadMutex material_lock = BLI_MUTEX_INITIALIZER;
  
 -void BKE_object_eval_local_transform(EvaluationContext *UNUSED(eval_ctx),
 -                                     Object *ob)
 +void BKE_object_eval_local_transform(Depsgraph *depsgraph, Object *ob)
  {
 -      DEG_debug_print_eval(__func__, ob->id.name, ob);
 +      DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
  
        /* calculate local matrix */
        BKE_object_to_mat4(ob, ob->obmat);
@@@ -954,9 -972,8 +954,8 @@@ Scene *BKE_scene_set_name(Main *bmain, 
  }
  
  /* Used by metaballs, return *all* objects (including duplis) existing in the scene (including scene's sets) */
- int BKE_scene_base_iter_next(
-         Depsgraph *depsgraph, SceneBaseIter *iter,
 -int BKE_scene_base_iter_next(Main *bmain, EvaluationContext *eval_ctx, SceneBaseIter *iter,
 -                             Scene **scene, int val, Base **base, Object **ob)
++int BKE_scene_base_iter_next(Depsgraph *depsgraph, SceneBaseIter *iter,
 +        Scene **scene, int val, Base **base, Object **ob)
  {
        bool run_again = true;
        
@@@ -2108,7 -2106,8 +2108,8 @@@ BLI_INLINE void apply_inflow_fields(Smo
        }
  }
  
- static void update_flowsfluids(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt)
+ static void update_flowsfluids(
 -        Main *bmain, EvaluationContext *eval_ctx, Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt)
++        struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt)
  {
        Object **flowobjs = NULL;
        EmissionMap *emaps = NULL;
@@@ -2562,7 -2563,9 +2563,9 @@@ static void update_effectors(struct Dep
        pdEndEffectors(&effectors);
  }
  
- static void step(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh *domain_dm, float fps)
+ static void step(
 -        Main *bmain, EvaluationContext *eval_ctx,
++        Depsgraph *depsgraph,
+         Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh *domain_dm, float fps)
  {
        SmokeDomainSettings *sds = smd->domain;
        /* stability values copied from wturbulence.cpp */
@@@ -137,11 -126,11 +137,11 @@@ bool ED_object_editmode_calc_active_cen
  
  
  void ED_object_vpaintmode_enter_ex(
-         struct Depsgraph *depsgraph, struct wmWindowManager *wm,
 -        struct Main *bmain, struct wmWindowManager *wm,
++        struct Main *bmain, struct Depsgraph *depsgraph, struct wmWindowManager *wm,
          struct Scene *scene, struct Object *ob);
  void ED_object_vpaintmode_enter(struct bContext *C);
  void ED_object_wpaintmode_enter_ex(
-         struct Depsgraph *depsgraph, struct wmWindowManager *wm,
 -        struct Main *bmain, struct wmWindowManager *wm,
++        struct Main *bmain, struct Depsgraph *depsgraph, struct wmWindowManager *wm,
          struct Scene *scene, struct Object *ob);
  void ED_object_wpaintmode_enter(struct bContext *C);
  
@@@ -462,23 -648,9 +462,23 @@@ static int editmode_toggle_exec(bContex
        }
        else {
                ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
 +              if ((obact->mode & mode_flag) == 0) {
 +                      FOREACH_OBJECT_BEGIN(view_layer, ob)
 +                      {
 +                              if ((ob != obact) && (ob->type == obact->type)) {
 +                                      ED_object_editmode_exit_ex(bmain, scene, ob, EM_FREEDATA | EM_WAITCURSOR);
 +                              }
 +                      }
 +                      FOREACH_OBJECT_END;
 +              }
        }
-       ED_space_image_uv_sculpt_update(CTX_wm_manager(C), scene);
 +
+       ED_space_image_uv_sculpt_update(bmain, CTX_wm_manager(C), scene);
  
 +      WM_msg_publish_rna_prop(mbus, &obact->id, obact, Object, mode);
 +
 +      WM_toolsystem_update_from_context_view3d(C);
 +
        return OPERATOR_FINISHED;
  }
  
@@@ -739,26 -708,22 +739,26 @@@ static void toggle_paint_cursor(bContex
   * purpose is to make sure the paint cursor is shown if paint
   * mode is enabled in the image editor. the paint poll will
   * ensure that the cursor is hidden when not in paint mode */
- void ED_space_image_paint_update(wmWindowManager *wm, Scene *scene)
+ void ED_space_image_paint_update(Main *bmain, wmWindowManager *wm, Scene *scene)
  {
        ToolSettings *settings = scene->toolsettings;
 -      wmWindow *win;
 -      ScrArea *sa;
        ImagePaintSettings *imapaint = &settings->imapaint;
        bool enabled = false;
  
 -      for (win = wm->windows.first; win; win = win->next)
 -              for (sa = win->screen->areabase.first; sa; sa = sa->next)
 -                      if (sa->spacetype == SPACE_IMAGE)
 -                              if (((SpaceImage *)sa->spacedata.first)->mode == SI_MODE_PAINT)
 +      for (wmWindow *win = wm->windows.first; win; win = win->next) {
 +              bScreen *screen = WM_window_get_active_screen(win);
 +
 +              for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 +                      if (sa->spacetype == SPACE_IMAGE) {
 +                              if (((SpaceImage *)sa->spacedata.first)->mode == SI_MODE_PAINT) {
                                        enabled = true;
 +                              }
 +                      }
 +              }
 +      }
  
        if (enabled) {
-               BKE_paint_init(scene, ePaintTexture2D, PAINT_CURSOR_TEXTURE_PAINT);
+               BKE_paint_init(bmain, scene, ePaintTexture2D, PAINT_CURSOR_TEXTURE_PAINT);
  
                paint_cursor_start_explicit(&imapaint->paint, wm, image_paint_poll);
        }
@@@ -54,8 -54,8 +54,7 @@@
  
  #include "BKE_brush.h"
  #include "BKE_context.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_deform.h"
- #include "BKE_global.h"
  #include "BKE_main.h"
  #include "BKE_mesh.h"
  #include "BKE_mesh_mapping.h"
@@@ -1062,7 -1032,9 +1061,8 @@@ static void vertex_paint_init_session_d
   * \{ */
  
  static void ed_vwpaintmode_enter_generic(
-         Depsgraph *depsgraph, wmWindowManager *wm, Scene *scene,
 -        Main *bmain,
 -        wmWindowManager *wm,
 -        Scene *scene,
++        Main *bmain, Depsgraph *depsgraph,
++        wmWindowManager *wm, Scene *scene,
          Object *ob, const eObjectMode mode_flag)
  {
        ob->mode |= mode_flag;
  }
  
  void ED_object_vpaintmode_enter_ex(
-         Depsgraph *depsgraph, wmWindowManager *wm,
 -        Main *bmain, wmWindowManager *wm,
++        Main *bmain, Depsgraph *depsgraph, wmWindowManager *wm,
          Scene *scene, Object *ob)
  {
        ed_vwpaintmode_enter_generic(
-               depsgraph, wm, scene, ob, OB_MODE_VERTEX_PAINT);
 -              bmain, wm, scene, ob, OB_MODE_VERTEX_PAINT);
++              bmain, depsgraph, wm, scene, ob, OB_MODE_VERTEX_PAINT);
  }
  void ED_object_vpaintmode_enter(struct bContext *C)
  {
+       Main *bmain = CTX_data_main(C);
 +      Depsgraph *depsgraph = CTX_data_depsgraph(C);
        wmWindowManager *wm = CTX_wm_manager(C);
        Scene *scene = CTX_data_scene(C);
        Object *ob = CTX_data_active_object(C);
-       ED_object_vpaintmode_enter_ex(depsgraph, wm, scene, ob);
 -      ED_object_vpaintmode_enter_ex(bmain, wm, scene, ob);
++      ED_object_vpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob);
  }
  
  void ED_object_wpaintmode_enter_ex(
-         Depsgraph *depsgraph, wmWindowManager *wm,
 -        Main *bmain, wmWindowManager *wm,
++        Main *bmain, Depsgraph *depsgraph, wmWindowManager *wm,
          Scene *scene, Object *ob)
  {
        ed_vwpaintmode_enter_generic(
-               depsgraph, wm, scene, ob, OB_MODE_WEIGHT_PAINT);
 -              bmain, wm, scene, ob, OB_MODE_WEIGHT_PAINT);
++              bmain, depsgraph, wm, scene, ob, OB_MODE_WEIGHT_PAINT);
  }
  void ED_object_wpaintmode_enter(struct bContext *C)
  {
+       Main *bmain = CTX_data_main(C);
 +      Depsgraph *depsgraph = CTX_data_depsgraph(C);
        wmWindowManager *wm = CTX_wm_manager(C);
        Scene *scene = CTX_data_scene(C);
        Object *ob = CTX_data_active_object(C);
-       ED_object_wpaintmode_enter_ex(depsgraph, wm, scene, ob);
 -      ED_object_wpaintmode_enter_ex(bmain, wm, scene, ob);
++      ED_object_wpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob);
  }
  
  /** \} */
@@@ -1234,7 -1192,7 +1236,8 @@@ void ED_object_wpaintmode_exit(struct b
   */
  static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op)
  {
+       Main *bmain = CTX_data_main(C);
 +      struct wmMsgBus *mbus = CTX_wm_message_bus(C);
        Object *ob = CTX_data_active_object(C);
        const int mode_flag = OB_MODE_WEIGHT_PAINT;
        const bool is_mode_set = (ob->mode & mode_flag) != 0;
                ED_object_wpaintmode_exit_ex(ob);
        }
        else {
 +              Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
                wmWindowManager *wm = CTX_wm_manager(C);
-               ED_object_wpaintmode_enter_ex(depsgraph, wm, scene, ob);
 -              ED_object_wpaintmode_enter_ex(bmain, wm, scene, ob);
++              ED_object_wpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob);
        }
  
        /* Weightpaint works by overriding colors in mesh,
@@@ -2371,7 -2320,7 +2374,8 @@@ void PAINT_OT_weight_paint(wmOperatorTy
   */
  static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op)
  {
+       Main *bmain = CTX_data_main(C);
 +      struct wmMsgBus *mbus = CTX_wm_message_bus(C);
        Object *ob = CTX_data_active_object(C);
        const int mode_flag = OB_MODE_VERTEX_PAINT;
        const bool is_mode_set = (ob->mode & mode_flag) != 0;
                ED_object_vpaintmode_exit_ex(ob);
        }
        else {
 +              Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
                wmWindowManager *wm = CTX_wm_manager(C);
-               ED_object_vpaintmode_enter_ex(depsgraph, wm, scene, ob);
 -              ED_object_vpaintmode_enter_ex(bmain, wm, scene, ob);
++              ED_object_vpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob);
        }
  
 +      BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL);
 +
        /* update modifier stack for mapping requirements */
 -      DAG_id_tag_update(&me->id, 0);
 +      DEG_id_tag_update(&me->id, 0);
  
        WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
  
  #include "DNA_meshdata_types.h"
  
  #include "BKE_brush.h"
- #include "BKE_paint.h"
  #include "BKE_colortools.h"
  #include "BKE_context.h"
- #include "BKE_mesh_mapping.h"
  #include "BKE_customdata.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_editmesh.h"
+ #include "BKE_main.h"
+ #include "BKE_mesh_mapping.h"
+ #include "BKE_paint.h"
  
 +#include "DEG_depsgraph.h"
 +
  #include "ED_screen.h"
  #include "ED_image.h"
  #include "ED_mesh.h"
@@@ -126,11 -116,8 +126,11 @@@ void ED_editors_init(bContext *C
        }
  
        /* image editor paint mode */
 -      if (sce) {
 -              ED_space_image_paint_update(bmain, wm, sce);
 +      {
 +              Scene *sce = CTX_data_scene(C);
 +              if (sce) {
-                       ED_space_image_paint_update(wm, sce);
++                      ED_space_image_paint_update(bmain, wm, sce);
 +              }
        }
  
        SWAP(int, reports->flag, reports_flag_prev);
@@@ -642,41 -602,113 +642,41 @@@ static void rna_GPencilBrush_name_set(P
  
  static void rna_SpaceImageEditor_uv_sculpt_update(Main *bmain, Scene *scene, PointerRNA *UNUSED(ptr))
  {
-       ED_space_image_uv_sculpt_update(bmain->wm.first, scene);
+       ED_space_image_uv_sculpt_update(bmain, bmain->wm.first, scene);
  }
  
 -static int rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
 -{
 -      Scene *scene = (Scene *)ptr->data;
 -      Base *base;
 -
 -      for (base = scene->base.first; base; base = base->next) {
 -              if (STREQLEN(base->object->id.name + 2, key, sizeof(base->object->id.name) - 2)) {
 -                      *r_ptr = rna_pointer_inherit_refine(ptr, &RNA_ObjectBase, base);
 -                      return true;
 -              }
 -      }
 -
 -      return false;
 -}
 -
 -static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter)
 -{
 -      ListBaseIterator *internal = &iter->internal.listbase;
  
 -      /* we are actually iterating a Base list, so override get */
 -      return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((Base *)internal->link)->object);
 -}
 +/* Read-only Iterator of all the scene objects. */
  
 -static Base *rna_Scene_object_link(Scene *scene, Main *UNUSED(bmain), bContext *C, ReportList *reports, Object *ob)
 +static void rna_Scene_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
  {
 -      Scene *scene_act = CTX_data_scene(C);
 -      Base *base;
 -
 -      if (BKE_scene_base_find(scene, ob)) {
 -              BKE_reportf(reports, RPT_ERROR, "Object '%s' is already in scene '%s'", ob->id.name + 2, scene->id.name + 2);
 -              return NULL;
 -      }
 -
 -      base = BKE_scene_base_add(scene, ob);
 -      id_us_plus(&ob->id);
 -
 -      /* this is similar to what object_add_type and BKE_object_add do */
 -      base->lay = scene->lay;
 -
 -      /* when linking to an inactive scene don't touch the layer */
 -      if (scene == scene_act)
 -              ob->lay = base->lay;
 -
 -      /* TODO(sergey): Only update relations for the current scene. */
 -      DAG_relations_tag_update(CTX_data_main(C));
 -      DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
 -
 -      /* slows down importers too much, run scene.update() */
 -      /* DAG_srelations_tag_update(bmain); */
 -
 -      WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene);
 +      Scene *scene = (Scene *)ptr->data;
 +      iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
  
 -      return base;
 +      ((BLI_Iterator *)iter->internal.custom)->valid = true;
 +      BKE_scene_objects_iterator_begin(iter->internal.custom, (void *)scene);
 +      iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
  }
  
 -static void rna_Scene_object_unlink(Scene *scene, Main *bmain, ReportList *reports, Object *ob)
 +static void rna_Scene_objects_next(CollectionPropertyIterator *iter)
  {
 -      Base *base = BKE_scene_base_find(scene, ob);
 -      if (!base) {
 -              BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in this scene '%s'", ob->id.name + 2, scene->id.name + 2);
 -              return;
 -      }
 -      if (base == scene->basact && ob->mode != OB_MODE_OBJECT) {
 -              BKE_reportf(reports, RPT_ERROR, "Object '%s' must be in object mode to unlink", ob->id.name + 2);
 -              return;
 -      }
 -      if (scene->basact == base) {
 -              scene->basact = NULL;
 -      }
 -
 -      BKE_scene_base_unlink(scene, base);
 -      MEM_freeN(base);
 -
 -      id_us_min(&ob->id);
 -
 -      /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */
 -      DAG_relations_tag_update(bmain);
 -
 -      WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene);
 +      BKE_scene_objects_iterator_next(iter->internal.custom);
 +      iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
  }
  
 -static void rna_Scene_skgen_etch_template_set(PointerRNA *ptr, PointerRNA value)
 +static void rna_Scene_objects_end(CollectionPropertyIterator *iter)
  {
 -      ToolSettings *ts = (ToolSettings *)ptr->data;
 -      if (value.data && ((Object *)value.data)->type == OB_ARMATURE)
 -              ts->skgen_template = value.data;
 -      else
 -              ts->skgen_template = NULL;
 +      BKE_scene_objects_iterator_end(iter->internal.custom);
 +      MEM_freeN(iter->internal.custom);
  }
  
 -static PointerRNA rna_Scene_active_object_get(PointerRNA *ptr)
 +static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter)
  {
 -      Scene *scene = (Scene *)ptr->data;
 -      return rna_pointer_inherit_refine(ptr, &RNA_Object, scene->basact ? scene->basact->object : NULL);
 +      Object *ob = ((BLI_Iterator *)iter->internal.custom)->current;
 +      return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ob);
  }
  
 -static void rna_Scene_active_object_set(PointerRNA *ptr, PointerRNA value)
 -{
 -      Scene *scene = (Scene *)ptr->data;
 -      if (value.data)
 -              scene->basact = BKE_scene_base_find(scene, (Object *)value.data);
 -      else
 -              scene->basact = NULL;
 -}
 +/* End of read-only Iterator of all the scene objects. */
  
  static void rna_Scene_set_set(PointerRNA *ptr, PointerRNA value)
  {