merge from master
[blender.git] / source / blender / makesrna / intern / rna_scene_api.c
index 3043e636b318b72be47638dee2bc741f966758f7..212578cf3f03b6ce0396e52d02173daee6edf2c6 100644 (file)
@@ -60,7 +60,6 @@ const EnumPropertyItem rna_enum_abc_compression_items[] = {
 #ifdef RNA_RUNTIME
 
 #include "BKE_animsys.h"
 #ifdef RNA_RUNTIME
 
 #include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
 #include "BKE_editmesh.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
 #include "BKE_editmesh.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
@@ -86,8 +85,17 @@ static void rna_Scene_frame_set(Scene *scene, Main *bmain, int frame, float subf
        BPy_BEGIN_ALLOW_THREADS;
 #endif
 
        BPy_BEGIN_ALLOW_THREADS;
 #endif
 
-       /* It's possible that here we're including layers which were never visible before. */
-       BKE_scene_update_for_newframe_ex(bmain->eval_ctx, bmain, scene, (1 << 20) - 1, true);
+       for (ViewLayer *view_layer = scene->view_layers.first;
+            view_layer != NULL;
+            view_layer = view_layer->next)
+       {
+               Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
+               BKE_scene_graph_update_for_newframe(bmain->eval_ctx,
+                                                   depsgraph,
+                                                   bmain,
+                                                   scene,
+                                                   view_layer);
+       }
 
 #ifdef WITH_PYTHON
        BPy_END_ALLOW_THREADS;
 
 #ifdef WITH_PYTHON
        BPy_END_ALLOW_THREADS;
@@ -99,7 +107,7 @@ static void rna_Scene_frame_set(Scene *scene, Main *bmain, int frame, float subf
         * redrawing while the data is being modified for render */
        if (!G.is_rendering) {
                /* cant use NC_SCENE|ND_FRAME because this causes wm_event_do_notifiers to call
         * redrawing while the data is being modified for render */
        if (!G.is_rendering) {
                /* cant use NC_SCENE|ND_FRAME because this causes wm_event_do_notifiers to call
-                * BKE_scene_update_for_newframe which will loose any un-keyed changes [#24690] */
+                * BKE_scene_graph_update_for_newframe which will loose any un-keyed changes [#24690] */
                /* WM_main_add_notifier(NC_SCENE|ND_FRAME, scene); */
                
                /* instead just redraw the views */
                /* WM_main_add_notifier(NC_SCENE|ND_FRAME, scene); */
                
                /* instead just redraw the views */
@@ -109,10 +117,10 @@ static void rna_Scene_frame_set(Scene *scene, Main *bmain, int frame, float subf
 
 static void rna_Scene_uvedit_aspect(Scene *scene, Object *ob, float *aspect)
 {
 
 static void rna_Scene_uvedit_aspect(Scene *scene, Object *ob, float *aspect)
 {
-       if ((ob->type == OB_MESH) && (ob->mode == OB_MODE_EDIT)) {
-               BMEditMesh *em;
-               em = BKE_editmesh_from_object(ob);
-               if (EDBM_mtexpoly_check(em)) {
+       if (ob->type == OB_MESH) {
+               /* Will be NULL when not in editmode */
+               BMEditMesh *em = BKE_editmesh_from_object(ob);
+               if (EDBM_uv_check(em)) {
                        ED_uvedit_get_aspect(scene, ob, em->bm, aspect, aspect + 1);
                        return;
                }
                        ED_uvedit_get_aspect(scene, ob, em->bm, aspect, aspect + 1);
                        return;
                }
@@ -127,7 +135,17 @@ static void rna_Scene_update_tagged(Scene *scene, Main *bmain)
        BPy_BEGIN_ALLOW_THREADS;
 #endif
 
        BPy_BEGIN_ALLOW_THREADS;
 #endif
 
-       BKE_scene_update_tagged(bmain->eval_ctx, bmain, scene);
+       for (ViewLayer *view_layer = scene->view_layers.first;
+            view_layer != NULL;
+            view_layer = view_layer->next)
+       {
+               Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
+               BKE_scene_graph_update_tagged(bmain->eval_ctx,
+                                             depsgraph,
+                                             bmain,
+                                             scene,
+                                             view_layer);
+       }
 
 #ifdef WITH_PYTHON
        BPy_END_ALLOW_THREADS;
 
 #ifdef WITH_PYTHON
        BPy_END_ALLOW_THREADS;
@@ -153,14 +171,24 @@ static void rna_SceneRender_get_frame_path(RenderData *rd, int frame, int previe
 }
 
 static void rna_Scene_ray_cast(
 }
 
 static void rna_Scene_ray_cast(
-        Scene *scene, float origin[3], float direction[3], float ray_dist,
+        Scene *scene, ViewLayer *view_layer, const char *engine_id,
+        float origin[3], float direction[3], float ray_dist,
         int *r_success, float r_location[3], float r_normal[3], int *r_index,
         Object **r_ob, float r_obmat[16])
 {
         int *r_success, float r_location[3], float r_normal[3], int *r_index,
         Object **r_ob, float r_obmat[16])
 {
+       RenderEngineType *engine_type;
+
+       if (engine_id == NULL || engine_id[0] == '\0') {
+               engine_type = RE_engines_find(scene->view_render.engine_id);
+       }
+       else {
+               engine_type = RE_engines_find(engine_id);
+       }
+
        normalize_v3(direction);
 
        SnapObjectContext *sctx = ED_transform_snap_object_context_create(
        normalize_v3(direction);
 
        SnapObjectContext *sctx = ED_transform_snap_object_context_create(
-               G.main, scene, 0);
+               G.main, scene, view_layer, engine_type, 0);
 
        bool ret = ED_transform_snap_object_project_ray_ex(
                sctx,
 
        bool ret = ED_transform_snap_object_project_ray_ex(
                sctx,
@@ -292,6 +320,9 @@ void RNA_api_scene(StructRNA *srna)
        /* Ray Cast */
        func = RNA_def_function(srna, "ray_cast", "rna_Scene_ray_cast");
        RNA_def_function_ui_description(func, "Cast a ray onto in object space");
        /* Ray Cast */
        func = RNA_def_function(srna, "ray_cast", "rna_Scene_ray_cast");
        RNA_def_function_ui_description(func, "Cast a ray onto in object space");
+       parm = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "Scene Layer");
+       RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+       parm = RNA_def_string(func, "engine", NULL, MAX_NAME, "Engine", "Render engine, use scene one by default");
        /* ray start and end */
        parm = RNA_def_float_vector(func, "origin", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
        RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
        /* ray start and end */
        parm = RNA_def_float_vector(func, "origin", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
        RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
@@ -317,6 +348,7 @@ void RNA_api_scene(StructRNA *srna)
        parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
        RNA_def_function_output(func, parm);
 
        parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
        RNA_def_function_output(func, parm);
 
+
 #ifdef WITH_ALEMBIC
        /* XXX Deprecated, will be removed in 2.8 in favour of calling the export operator. */
        func = RNA_def_function(srna, "alembic_export", "rna_Scene_alembic_export");
 #ifdef WITH_ALEMBIC
        /* XXX Deprecated, will be removed in 2.8 in favour of calling the export operator. */
        func = RNA_def_function(srna, "alembic_export", "rna_Scene_alembic_export");