Blender  V2.93
pipeline_from_ids.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) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #include "pipeline_from_ids.h"
21 
22 #include "DNA_layer_types.h"
23 
26 #include "intern/depsgraph.h"
27 
28 namespace blender::deg {
29 
30 namespace {
31 
32 class DepsgraphFromIDsFilter {
33  public:
34  DepsgraphFromIDsFilter(Span<ID *> ids)
35  {
36  ids_.add_multiple(ids);
37  }
38 
39  bool contains(ID *id)
40  {
41  return ids_.contains(id);
42  }
43 
44  protected:
45  Set<ID *> ids_;
46 };
47 
48 class DepsgraphFromIDsNodeBuilder : public DepsgraphNodeBuilder {
49  public:
50  DepsgraphFromIDsNodeBuilder(Main *bmain,
52  DepsgraphBuilderCache *cache,
53  Span<ID *> ids)
54  : DepsgraphNodeBuilder(bmain, graph, cache), filter_(ids)
55  {
56  }
57 
58  bool need_pull_base_into_graph(Base *base) override
59  {
60  if (!filter_.contains(&base->object->id)) {
61  return false;
62  }
64  }
65 
66  void build_object_proxy_group(Object *object, bool is_visible) override
67  {
68  if (object->proxy_group == nullptr) {
69  return;
70  }
71  if (!filter_.contains(&object->proxy_group->id)) {
72  return;
73  }
75  }
76 
77  protected:
78  DepsgraphFromIDsFilter filter_;
79 };
80 
81 class DepsgraphFromIDsRelationBuilder : public DepsgraphRelationBuilder {
82  public:
83  DepsgraphFromIDsRelationBuilder(Main *bmain,
85  DepsgraphBuilderCache *cache,
86  Span<ID *> ids)
87  : DepsgraphRelationBuilder(bmain, graph, cache), filter_(ids)
88  {
89  }
90 
91  bool need_pull_base_into_graph(Base *base) override
92  {
93  if (!filter_.contains(&base->object->id)) {
94  return false;
95  }
97  }
98 
99  void build_object_proxy_group(Object *object) override
100  {
101  if (object->proxy_group == nullptr) {
102  return;
103  }
104  if (!filter_.contains(&object->proxy_group->id)) {
105  return;
106  }
108  }
109 
110  protected:
111  DepsgraphFromIDsFilter filter_;
112 };
113 
114 } // namespace
115 
118 {
119 }
120 
121 unique_ptr<DepsgraphNodeBuilder> FromIDsBuilderPipeline::construct_node_builder()
122 {
123  return std::make_unique<DepsgraphFromIDsNodeBuilder>(bmain_, deg_graph_, &builder_cache_, ids_);
124 }
125 
126 unique_ptr<DepsgraphRelationBuilder> FromIDsBuilderPipeline::construct_relation_builder()
127 {
128  return std::make_unique<DepsgraphFromIDsRelationBuilder>(
129  bmain_, deg_graph_, &builder_cache_, ids_);
130 }
131 
133 {
135  for (ID *id : ids_) {
136  node_builder.build_id(id);
137  }
138 }
139 
141 {
143  for (ID *id : ids_) {
144  relation_builder.build_id(id);
145  }
146 }
147 
148 } // namespace blender::deg
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
virtual bool need_pull_base_into_graph(Base *base)
Definition: deg_builder.cc:80
virtual void build_object_proxy_group(Object *object, bool is_object_visible)
virtual void build_view_layer(Scene *scene, ViewLayer *view_layer, eDepsNode_LinkedState_Type linked_state)
virtual void build_object_proxy_group(Object *object)
virtual void build_relations(DepsgraphRelationBuilder &relation_builder) override
FromIDsBuilderPipeline(::Depsgraph *graph, Span< ID * > ids)
virtual unique_ptr< DepsgraphRelationBuilder > construct_relation_builder() override
virtual unique_ptr< DepsgraphNodeBuilder > construct_node_builder() override
virtual void build_nodes(DepsgraphNodeBuilder &node_builder) override
Depsgraph * graph
DepsgraphNodeBuilder * node_builder
@ DEG_ID_LINKED_DIRECTLY
Definition: deg_node_id.h:46
DepsgraphFromIDsFilter filter_
Set< ID * > ids_
struct Object * object
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
struct Object * proxy_group