Fix freestyle renders not including some types of animation.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 24 Jan 2019 06:08:19 +0000 (07:08 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 24 Jan 2019 15:46:11 +0000 (16:46 +0100)
Freestyle Python scripts need to get the evaluated view layer and scene,
not the original one.

source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc
source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
source/blender/freestyle/intern/application/Controller.cpp
source/blender/freestyle/intern/application/Controller.h
source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h
source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
source/blender/render/intern/source/pipeline.c

index ce3b253..04cb8d1 100644 (file)
@@ -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,
index f77d478..200ac45 100644 (file)
@@ -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);
index 5ae0469..ea11e64 100644 (file)
@@ -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);
 
index 0304c18..80c7d86 100644 (file)
@@ -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();
index 8a4fa91..4d77962 100644 (file)
 
 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;
 }
index 2fcf437..8fb95ad 100644 (file)
@@ -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
index 3486980..470b115 100644 (file)
@@ -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;
 }
 
index 35c85bb..8b81553 100644 (file)
@@ -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);