Blender  V2.93
deg_builder_nodes_view_layer.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
27 
28 #include <cstdio>
29 #include <cstdlib>
30 
31 #include "MEM_guardedalloc.h"
32 
33 #include "BLI_blenlib.h"
34 #include "BLI_string.h"
35 #include "BLI_utildefines.h"
36 
37 #include "DNA_collection_types.h"
38 #include "DNA_freestyle_types.h"
39 #include "DNA_layer_types.h"
40 #include "DNA_linestyle_types.h"
41 #include "DNA_node_types.h"
42 #include "DNA_object_types.h"
43 #include "DNA_scene_types.h"
44 
45 #include "BKE_layer.h"
46 #include "BKE_main.h"
47 #include "BKE_node.h"
48 
49 #include "DEG_depsgraph.h"
50 #include "DEG_depsgraph_build.h"
51 
53 #include "intern/depsgraph.h"
54 #include "intern/depsgraph_type.h"
55 #include "intern/node/deg_node.h"
58 
59 namespace blender::deg {
60 
62 {
63  const int restrict_flag = (graph_->mode == DAG_EVAL_VIEWPORT) ? COLLECTION_RESTRICT_VIEWPORT :
65 
66  for (LayerCollection *lc = (LayerCollection *)lb->first; lc; lc = lc->next) {
67  if (lc->collection->flag & restrict_flag) {
68  continue;
69  }
70  if ((lc->flag & LAYER_COLLECTION_EXCLUDE) == 0) {
71  build_collection(lc, lc->collection);
72  }
73  build_layer_collections(&lc->layer_collections);
74  }
75 }
76 
78 {
79  if (fls->group != nullptr) {
80  build_collection(nullptr, fls->group);
81  }
82  if (fls->linestyle != nullptr) {
84  }
85 }
86 
88  ViewLayer *view_layer,
89  eDepsNode_LinkedState_Type linked_state)
90 {
91  /* NOTE: Pass view layer index of 0 since after scene CoW there is
92  * only one view layer in there. */
94  /* Scene ID block. */
96  id_node->linked_state = linked_state;
97  /* Time source. */
99  /* Setup currently building context. */
100  scene_ = scene;
101  view_layer_ = view_layer;
102  /* Get pointer to a CoW version of scene ID. */
103  Scene *scene_cow = get_cow_datablock(scene);
104  /* Scene objects. */
105  /* NOTE: Base is used for function bindings as-is, so need to pass CoW base,
106  * but object is expected to be an original one. Hence we go into some
107  * tricks here iterating over the view layer. */
108  int base_index = 0;
109  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
110  /* object itself */
111  if (need_pull_base_into_graph(base)) {
112  /* NOTE: We consider object visible even if it's currently
113  * restricted by the base/restriction flags. Otherwise its drivers
114  * will never be evaluated.
115  *
116  * TODO(sergey): Need to go more granular on visibility checks. */
117  build_object(base_index, base->object, linked_state, true);
118  base_index++;
119  }
120  }
122  if (scene->camera != nullptr) {
124  }
125  /* Rigidbody. */
126  if (scene->rigidbody_world != nullptr) {
128  }
129  /* Scene's animation and drivers. */
130  if (scene->adt != nullptr) {
132  }
133  /* World. */
134  if (scene->world != nullptr) {
136  }
137  /* Cache file. */
138  LISTBASE_FOREACH (CacheFile *, cachefile, &bmain_->cachefiles) {
139  build_cachefile(cachefile);
140  }
141  /* Masks. */
143  build_mask(mask);
144  }
145  /* Movie clips. */
147  build_movieclip(clip);
148  }
149  /* Material override. */
150  if (view_layer->mat_override != nullptr) {
151  build_material(view_layer->mat_override);
152  }
153  /* Freestyle linesets. */
156  }
157  /* Sequencer. */
158  if (linked_state == DEG_ID_LINKED_DIRECTLY) {
161  }
162  /* Collections. */
166  [view_layer_index = view_layer_index_, scene_cow](::Depsgraph *depsgraph) {
167  BKE_layer_eval_view_layer_indexed(depsgraph, scene_cow, view_layer_index);
168  });
169  /* Parameters evaluation for scene relations mainly. */
172  /* Build all set scenes. */
173  if (scene->set != nullptr) {
174  ViewLayer *set_view_layer = BKE_view_layer_default_render(scene->set);
175  build_view_layer(scene->set, set_view_layer, DEG_ID_LINKED_VIA_SET);
176  }
177 }
178 
179 } // namespace blender::deg
struct ViewLayer * BKE_view_layer_default_render(const struct Scene *scene)
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
@ DAG_EVAL_VIEWPORT
Definition: DEG_depsgraph.h:61
Object groups, one object can be in many groups at once.
@ COLLECTION_RESTRICT_RENDER
@ COLLECTION_RESTRICT_VIEWPORT
@ LAYER_COLLECTION_EXCLUDE
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
virtual bool need_pull_base_into_graph(Base *base)
Definition: deg_builder.cc:80
virtual void build_scene_parameters(Scene *scene)
virtual void build_scene_sequencer(Scene *scene)
virtual void build_world(World *world)
virtual void build_object(int base_index, Object *object, eDepsNode_LinkedState_Type linked_state, bool is_visible)
virtual void build_freestyle_linestyle(FreestyleLineStyle *linestyle)
virtual void build_cachefile(CacheFile *cache_file)
OperationNode * add_operation_node(ComponentNode *comp_node, OperationCode opcode, const DepsEvalOperationCb &op=nullptr, const char *name="", int name_tag=-1)
virtual void build_scene_audio(Scene *scene)
virtual void build_material(Material *ma)
virtual void build_collection(LayerCollection *from_layer_collection, Collection *collection)
virtual void build_rigidbody(Scene *scene)
virtual void build_freestyle_lineset(FreestyleLineSet *fls)
virtual void build_movieclip(MovieClip *clip)
virtual void build_layer_collections(ListBase *lb)
virtual void build_view_layer(Scene *scene, ViewLayer *view_layer, eDepsNode_LinkedState_Type linked_state)
virtual void build_scene_compositor(Scene *scene)
T * get_cow_datablock(const T *orig) const
const IDNode * id_node
Scene scene
const Depsgraph * depsgraph
eDepsNode_LinkedState_Type
Definition: deg_node_id.h:40
@ DEG_ID_LINKED_INDIRECTLY
Definition: deg_node_id.h:42
@ DEG_ID_LINKED_VIA_SET
Definition: deg_node_id.h:44
@ DEG_ID_LINKED_DIRECTLY
Definition: deg_node_id.h:46
struct Collection * group
struct FreestyleLineStyle * linestyle
void * first
Definition: DNA_listBase.h:47
ListBase masks
Definition: BKE_main.h:178
ListBase movieclips
Definition: BKE_main.h:177
ListBase cachefiles
Definition: BKE_main.h:180
struct RigidBodyWorld * rigidbody_world
struct AnimData * adt
struct Object * camera
struct World * world
struct Scene * set
struct FreestyleConfig freestyle_config
ListBase layer_collections
ListBase object_bases
struct Material * mat_override
eEvaluationMode mode
Definition: depsgraph.h:136
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)