diff options
Diffstat (limited to 'source')
8 files changed, 45 insertions, 27 deletions
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc index ce3b2538274..04cb8d12a0c 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc @@ -42,8 +42,9 @@ #include "BLI_string.h" extern "C" { -#include "DNA_node_types.h" +#include "DNA_freestyle_types.h" #include "DNA_layer_types.h" +#include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" @@ -155,6 +156,12 @@ void DepsgraphNodeBuilder::build_view_layer( if (view_layer->mat_override != NULL) { build_material(view_layer->mat_override); } + /* Freestyle collections. */ + LISTBASE_FOREACH (FreestyleLineSet *, fls, &view_layer->freestyle_config.linesets) { + if (fls->group != NULL) { + build_collection(NULL, fls->group); + } + } /* Collections. */ add_operation_node(&scene->id, DEG_NODE_TYPE_LAYER_COLLECTIONS, diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc index f77d47874a2..200ac4531c6 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc @@ -136,6 +136,12 @@ void DepsgraphRelationBuilder::build_view_layer(Scene *scene, ViewLayer *view_la if (view_layer->mat_override != NULL) { build_material(view_layer->mat_override); } + /* Freestyle collections. */ + LISTBASE_FOREACH (FreestyleLineSet *, fls, &view_layer->freestyle_config.linesets) { + if (fls->group != NULL) { + build_collection(NULL, NULL, fls->group); + } + } /* Build all set scenes. */ if (scene->set != NULL) { ViewLayer *set_view_layer = BKE_view_layer_default_render(scene->set); diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp index 5ae04698a73..ea11e64e775 100644 --- a/source/blender/freestyle/intern/application/Controller.cpp +++ b/source/blender/freestyle/intern/application/Controller.cpp @@ -232,9 +232,9 @@ bool Controller::hitViewMapCache() return false; } -int Controller::LoadMesh(Render *re, ViewLayer *view_layer) +int Controller::LoadMesh(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) { - BlenderFileLoader loader(re, view_layer); + BlenderFileLoader loader(re, view_layer, depsgraph); loader.setRenderMonitor(_pRenderMonitor); diff --git a/source/blender/freestyle/intern/application/Controller.h b/source/blender/freestyle/intern/application/Controller.h index 0304c18b8a6..80c7d8656a3 100644 --- a/source/blender/freestyle/intern/application/Controller.h +++ b/source/blender/freestyle/intern/application/Controller.h @@ -68,7 +68,7 @@ public: //soc void init_options(); - int LoadMesh(Render *re, ViewLayer *view_layer); + int LoadMesh(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph); int Load3DSFile(const char *iFileName); void CloseFile(); void ComputeViewMap(); diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index 8a4fa91d650..4d77962bdfa 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -32,10 +32,10 @@ namespace Freestyle { -BlenderFileLoader::BlenderFileLoader(Render *re, ViewLayer *view_layer) +BlenderFileLoader::BlenderFileLoader(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) { _re = re; - _view_layer = view_layer; + _depsgraph = depsgraph; _Scene = NULL; _numFacesRead = 0; #if 0 @@ -79,11 +79,6 @@ NodeGroup *BlenderFileLoader::Load() _z_offset = 0.f; } - ViewLayer *view_layer = (ViewLayer*)BLI_findstring(&_re->scene->view_layers, _view_layer->name, offsetof(ViewLayer, name)); - Depsgraph *depsgraph = DEG_graph_new(_re->scene, view_layer, DAG_EVAL_RENDER); - - BKE_scene_graph_update_tagged(depsgraph, _re->main); - #if 0 if (G.debug & G_DEBUG_FREESTYLE) { cout << "Frustum: l " << _viewplane_left << " r " << _viewplane_right @@ -95,7 +90,7 @@ NodeGroup *BlenderFileLoader::Load() int id = 0; DEG_OBJECT_ITER_BEGIN( - depsgraph, ob, + _depsgraph, ob, DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET | DEG_ITER_OBJECT_FLAG_VISIBLE | @@ -111,7 +106,7 @@ NodeGroup *BlenderFileLoader::Load() bool apply_modifiers = false; bool calc_undeformed = false; - Mesh *mesh = BKE_mesh_new_from_object(depsgraph, + Mesh *mesh = BKE_mesh_new_from_object(_depsgraph, _re->main, _re->scene, ob, @@ -125,8 +120,6 @@ NodeGroup *BlenderFileLoader::Load() } DEG_OBJECT_ITER_END; - DEG_graph_free(depsgraph); - // Return the built scene. return _Scene; } diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h index 2fcf4373bba..8fb95ad7e37 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h @@ -89,7 +89,7 @@ class BlenderFileLoader { public: /*! Builds a MaxFileLoader */ - BlenderFileLoader(Render *re, ViewLayer *view_layer); + BlenderFileLoader(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph); virtual ~BlenderFileLoader(); /*! Loads the 3D scene and returns a pointer to the scene root node */ @@ -124,7 +124,7 @@ protected: unsigned n; }; Render *_re; - ViewLayer *_view_layer; + Depsgraph *_depsgraph; NodeGroup *_Scene; unsigned _numFacesRead; #if 0 diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index 3486980fa65..470b1151391 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -51,6 +51,7 @@ extern "C" { #include "BKE_global.h" #include "BKE_library.h" #include "BKE_linestyle.h" +#include "BKE_scene.h" #include "BKE_text.h" #include "BLT_translation.h" @@ -62,6 +63,8 @@ extern "C" { #include "BPY_extern.h" +#include "DEG_depsgraph_query.h" + #include "renderpipeline.h" #include "FRS_freestyle.h" @@ -282,13 +285,13 @@ static bool test_edge_type_conditions(struct edge_type_condition *conditions, return true; } -static void prepare(Render *re, ViewLayer *view_layer) +static void prepare(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph) { // load mesh re->i.infostr = IFACE_("Freestyle: Mesh loading"); re->stats_draw(re->sdh, &re->i); re->i.infostr = NULL; - if (controller->LoadMesh(re, view_layer)) // returns if scene cannot be loaded or if empty + if (controller->LoadMesh(re, view_layer, depsgraph)) // returns if scene cannot be loaded or if empty return; if (re->test_break(re->tbh)) return; @@ -606,12 +609,17 @@ Render *FRS_do_stroke_rendering(Render *re, ViewLayer *view_layer, int render) cout << "----------------------------------------------------------" << endl; } + /* Create depsgraph and evaluate scene. */ + ViewLayer *scene_view_layer = (ViewLayer*)BLI_findstring(&re->scene->view_layers, view_layer->name, offsetof(ViewLayer, name)); + Depsgraph *depsgraph = DEG_graph_new(re->scene, scene_view_layer, DAG_EVAL_RENDER); + BKE_scene_graph_update_tagged(depsgraph, re->main); + // prepare Freestyle: // - load mesh // - add style modules // - set parameters // - compute view map - prepare(re, view_layer); + prepare(re, view_layer, depsgraph); if (re->test_break(re->tbh)) { controller->CloseFile(); @@ -626,7 +634,7 @@ Render *FRS_do_stroke_rendering(Render *re, ViewLayer *view_layer, int render) re->i.infostr = IFACE_("Freestyle: Stroke rendering"); re->stats_draw(re->sdh, &re->i); re->i.infostr = NULL; - g_freestyle.scene = re->scene; + g_freestyle.scene = DEG_get_evaluated_scene(depsgraph); int strokeCount = controller->DrawStrokes(); if (strokeCount > 0) { freestyle_render = controller->RenderStrokes(re, true); @@ -643,6 +651,8 @@ Render *FRS_do_stroke_rendering(Render *re, ViewLayer *view_layer, int render) } } + DEG_graph_free(depsgraph); + return freestyle_render; } diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 35c85bb3292..8b815539d22 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -1335,19 +1335,21 @@ static void add_freestyle(Render *re, int render) /* releases temporary scenes and renders for Freestyle stroke rendering */ static void free_all_freestyle_renders(void) { - Render *re1, *freestyle_render; - Scene *freestyle_scene; + Render *re1; LinkData *link; for (re1= RenderGlobal.renderlist.first; re1; re1= re1->next) { for (link = (LinkData *)re1->freestyle_renders.first; link; link = link->next) { - freestyle_render = (Render *)link->data; + Render *freestyle_render = (Render *)link->data; if (freestyle_render) { - freestyle_scene = freestyle_render->scene; + Scene *freestyle_scene = freestyle_render->scene; RE_FreeRender(freestyle_render); - BKE_libblock_unlink(re1->freestyle_bmain, freestyle_scene, false, false); - BKE_id_free(re1->freestyle_bmain, freestyle_scene); + + if (freestyle_scene) { + BKE_libblock_unlink(re1->freestyle_bmain, freestyle_scene, false, false); + BKE_id_free(re1->freestyle_bmain, freestyle_scene); + } } } BLI_freelistN(&re1->freestyle_renders); |