Blender V5.3
pipeline_from_collection.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "BKE_collection.hh"
12
13#include "DNA_layer_types.h"
14
15#include "DEG_depsgraph.hh"
17
20#include "intern/depsgraph.hh"
21
22namespace blender::deg {
23
24namespace {
25
26class DepsgraphFromCollectionIDsFilter {
27 public:
28 DepsgraphFromCollectionIDsFilter(const Set<ID *> &ids) : ids_(ids) {}
29
30 bool contains(ID *id)
31 {
32 return ids_.contains(id);
33 }
34
35 protected:
36 const Set<ID *> &ids_;
37};
38
39class DepsgraphFromCollectionIDsNodeBuilder : public DepsgraphNodeBuilder {
40 public:
41 DepsgraphFromCollectionIDsNodeBuilder(Main *bmain,
42 Depsgraph *graph,
43 DepsgraphBuilderCache *cache,
44 const Set<ID *> &ids)
45 : DepsgraphNodeBuilder(bmain, graph, cache), filter_(ids)
46 {
47 }
48
49 bool need_pull_base_into_graph(const Base *base) override
50 {
51 if (!filter_.contains(&base->object->id)) {
52 return false;
53 }
55 }
56
57 protected:
58 DepsgraphFromCollectionIDsFilter filter_;
59};
60
61class DepsgraphFromCollectionIDsRelationBuilder : public DepsgraphRelationBuilder {
62 public:
63 DepsgraphFromCollectionIDsRelationBuilder(Main *bmain,
64 Depsgraph *graph,
65 DepsgraphBuilderCache *cache,
66 const Set<ID *> &ids)
67 : DepsgraphRelationBuilder(bmain, graph, cache), filter_(ids)
68 {
69 }
70
71 bool need_pull_base_into_graph(const Base *base) override
72 {
73 if (!filter_.contains(&base->object->id)) {
74 return false;
75 }
77 }
78
79 protected:
80 DepsgraphFromCollectionIDsFilter filter_;
81};
82
83} // namespace
84
86 Collection *collection)
88{
90 *DEG_get_bmain(graph), scene_, view_layer_, collection);
91 const int base_flag = (deg_graph_->mode == DAG_EVAL_RENDER) ? BASE_ENABLED_RENDER :
93 for (; base; base = base->next) {
94 if (!deg_graph_->use_visibility_optimization || (base->flag & base_flag)) {
95 ids_.add(&base->object->id);
96 }
97 }
98}
99
100std::unique_ptr<DepsgraphNodeBuilder> FromCollectionBuilderPipeline::construct_node_builder()
101{
102 return std::make_unique<DepsgraphFromCollectionIDsNodeBuilder>(
104}
105
106std::unique_ptr<DepsgraphRelationBuilder> FromCollectionBuilderPipeline::
108{
109 return std::make_unique<DepsgraphFromCollectionIDsRelationBuilder>(
111}
112
114{
116 for (ID *id : ids_) {
117 node_builder.build_id(id, true);
118 }
119}
120
122{
124 for (ID *id : ids_) {
125 relation_builder.build_id(id);
126 }
127}
128
129} // namespace blender::deg
virtual bool need_pull_base_into_graph(const Base *base)
virtual void build_id(ID *id, bool force_be_visible=false)
virtual void build_view_layer(Scene *scene, ViewLayer *view_layer, eDepsNode_LinkedState_Type linked_state)
virtual void build_view_layer(Scene *scene, ViewLayer *view_layer, eDepsNode_LinkedState_Type linked_state)
void build_nodes(DepsgraphNodeBuilder &node_builder) override
FromCollectionBuilderPipeline(blender::Depsgraph *graph, Collection *collection)
void build_relations(DepsgraphRelationBuilder &relation_builder) override
std::unique_ptr< DepsgraphRelationBuilder > construct_relation_builder() override
std::unique_ptr< DepsgraphNodeBuilder > construct_node_builder() override
bool contains(const VArray< bool > &varray, const IndexMask &indices_to_check, bool value)
@ BASE_ENABLED_VIEWPORT
Main * DEG_get_bmain(const Depsgraph *graph)
Base * BKE_collection_or_layer_objects(const Main &bmain, const Scene *scene, ViewLayer *view_layer, Collection *collection)
struct Object * object
struct Base * next
eEvaluationMode mode
Definition depsgraph.hh:145