From 861697c9e55bad362fc493e263fe966095744b37 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Wed, 11 Sep 2019 08:22:53 +0200 Subject: Cycles: Initial Support For Local View This diff will add support for local view to Cycles rendered preview mode. Currently the implementation shows same results as EEVEE does. This entails a difference with Blender 2.79, where lights were automatically added to the local view. {T69780} describes this should be solved before the next release. This patch also solves missing `owner_id` issues when using the RNA CPP Api from Cycles. Cycles didn't provide the `owner_id` making some functionality fail, what then was worked around in Blender. It also fixes an issue in `makesrna` where incorrect CPP code was generated when only `PARM_RNAPTR` was provided. An optional `view_layer` parameter is added to the `Object.local_view_get` method to reduce lookups. Reviewed By: brecht Differential Revision: https://developer.blender.org/D5753 --- source/blender/makesrna/intern/makesrna.c | 6 ++++ source/blender/makesrna/intern/rna_object_api.c | 43 +++++++++++++++++-------- source/blender/makesrna/intern/rna_space.c | 5 --- 3 files changed, 36 insertions(+), 18 deletions(-) (limited to 'source/blender/makesrna') diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 968baca3517..f531eb7f494 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -2539,6 +2539,12 @@ static void rna_def_struct_function_call_impl_cpp(FILE *f, StructRNA *srna, Func rna_safe_id(dp->prop->identifier)); } } + else if (dp->prop->flag_parameter & PARM_RNAPTR) { + fprintf(f, + "(::%s *) &%s", + rna_parameter_type_name(dp->prop), + rna_safe_id(dp->prop->identifier)); + } else { fprintf(f, "(::%s *) %s.ptr.data", diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 5bec6f0c7d3..e26c430eb16 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -221,32 +221,43 @@ static bool rna_Object_indirect_only_get(Object *ob, bContext *C, ViewLayer *vie return ((base->flag & BASE_INDIRECT_ONLY) != 0); } -static Base *rna_Object_local_view_property_helper( - bScreen *sc, View3D *v3d, Object *ob, ReportList *reports, Scene **r_scene) +static Base *rna_Object_local_view_property_helper(bScreen *sc, + View3D *v3d, + ViewLayer *view_layer, + Object *ob, + ReportList *reports, + Scene **r_scene) { + wmWindow *win = NULL; if (v3d->localvd == NULL) { BKE_report(reports, RPT_ERROR, "Viewport not in local view"); return NULL; } - wmWindow *win = ED_screen_window_find(sc, G_MAIN->wm.first); - ViewLayer *view_layer = WM_window_get_active_view_layer(win); + if (view_layer == NULL) { + win = ED_screen_window_find(sc, G_MAIN->wm.first); + view_layer = WM_window_get_active_view_layer(win); + } + Base *base = BKE_view_layer_base_find(view_layer, ob); if (base == NULL) { BKE_reportf( reports, RPT_WARNING, "Object %s not in view layer %s", ob->id.name + 2, view_layer->name); } - if (r_scene) { + if (r_scene != NULL && win != NULL) { *r_scene = win->scene; } return base; } -static bool rna_Object_local_view_get(Object *ob, ReportList *reports, PointerRNA *v3d_ptr) +static bool rna_Object_local_view_get(Object *ob, + ReportList *reports, + PointerRNA *v3d_ptr, + ViewLayer *view_layer) { bScreen *sc = (bScreen *)v3d_ptr->owner_id; View3D *v3d = v3d_ptr->data; - Base *base = rna_Object_local_view_property_helper(sc, v3d, ob, reports, NULL); + Base *base = rna_Object_local_view_property_helper(sc, v3d, view_layer, ob, reports, NULL); if (base == NULL) { return false; /* Error reported. */ } @@ -261,7 +272,7 @@ static void rna_Object_local_view_set(Object *ob, bScreen *sc = (bScreen *)v3d_ptr->owner_id; View3D *v3d = v3d_ptr->data; Scene *scene; - Base *base = rna_Object_local_view_property_helper(sc, v3d, ob, reports, &scene); + Base *base = rna_Object_local_view_property_helper(sc, v3d, NULL, ob, reports, &scene); if (base == NULL) { return; /* Error reported. */ } @@ -276,7 +287,8 @@ static void rna_Object_local_view_set(Object *ob, } } -/* Convert a given matrix from a space to another (using the object and/or a bone as reference). */ +/* Convert a given matrix from a space to another (using the object and/or a bone as + * reference). */ static void rna_Object_mat_convert_space(Object *ob, ReportList *reports, bPoseChannel *pchan, @@ -466,8 +478,8 @@ static int mesh_looptri_to_poly_index(Mesh *me_eval, const MLoopTri *lt) return index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly; } -/* TOOD(sergey): Make the Python API more clear that evaluation might happen, or requite passing - * fully evaluated depsgraph. */ +/* TOOD(sergey): Make the Python API more clear that evaluation might happen, or requite + * passing fully evaluated depsgraph. */ static Object *eval_object_ensure(Object *ob, bContext *C, ReportList *reports, @@ -505,8 +517,8 @@ static void rna_Object_ray_cast(Object *ob, { bool success = false; - /* TODO(sergey): This isn't very reliable check. It is possible to have non-NULL pointer but - * which is out of date, and possibly dangling one. */ + /* TODO(sergey): This isn't very reliable check. It is possible to have non-NULL pointer + * but which is out of date, and possibly dangling one. */ if (ob->runtime.mesh_eval == NULL && (ob = eval_object_ensure(ob, C, reports, rnaptr_depsgraph)) == NULL) { return; @@ -806,6 +818,11 @@ void RNA_api_object(StructRNA *srna) RNA_def_function_flag(func, FUNC_USE_REPORTS); parm = RNA_def_pointer(func, "viewport", "SpaceView3D", "", "Viewport in local view"); RNA_def_parameter_flags(parm, 0, PARM_RNAPTR | PARM_REQUIRED); + parm = RNA_def_pointer(func, + "view_layer", + "ViewLayer", + "", + "Optional ViewLayer. Preferably passed for additional performance"); parm = RNA_def_boolean(func, "result", 0, "", "Object local view state"); RNA_def_function_return(func, parm); diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index da30abb6e7a..718b34e5570 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -988,11 +988,6 @@ static Scene *rna_3DViewShading_scene(PointerRNA *ptr) { /* Get scene, depends if using 3D view or OpenGL render settings. */ ID *id = ptr->owner_id; - if (!id) { - /* When accessed from an external render engine the id.data is NULL - * This might be missing from the RNA CPP Api */ - return NULL; - } if (GS(id->name) == ID_SCE) { return (Scene *)id; } -- cgit v1.2.3