Blender V4.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
6
7#include "BKE_collection.hh"
8
9#include "DNA_layer_types.h"
10
11#include "DEG_depsgraph.hh"
12
15#include "intern/depsgraph.hh"
16
17namespace blender::deg {
18
19namespace {
20
21class DepsgraphFromCollectionIDsFilter {
22 public:
23 DepsgraphFromCollectionIDsFilter(const Set<ID *> &ids) : ids_(ids) {}
24
25 bool contains(ID *id)
26 {
27 return ids_.contains(id);
28 }
29
30 protected:
31 const Set<ID *> &ids_;
32};
33
34class DepsgraphFromCollectionIDsNodeBuilder : public DepsgraphNodeBuilder {
35 public:
36 DepsgraphFromCollectionIDsNodeBuilder(Main *bmain,
37 Depsgraph *graph,
38 DepsgraphBuilderCache *cache,
39 const Set<ID *> &ids)
40 : DepsgraphNodeBuilder(bmain, graph, cache), filter_(ids)
41 {
42 }
43
44 bool need_pull_base_into_graph(const Base *base) override
45 {
46 if (!filter_.contains(&base->object->id)) {
47 return false;
48 }
50 }
51
52 protected:
53 DepsgraphFromCollectionIDsFilter filter_;
54};
55
56class DepsgraphFromCollectionIDsRelationBuilder : public DepsgraphRelationBuilder {
57 public:
58 DepsgraphFromCollectionIDsRelationBuilder(Main *bmain,
59 Depsgraph *graph,
60 DepsgraphBuilderCache *cache,
61 const Set<ID *> &ids)
62 : DepsgraphRelationBuilder(bmain, graph, cache), filter_(ids)
63 {
64 }
65
66 bool need_pull_base_into_graph(const Base *base) override
67 {
68 if (!filter_.contains(&base->object->id)) {
69 return false;
70 }
72 }
73
74 protected:
75 DepsgraphFromCollectionIDsFilter filter_;
76};
77
78} // namespace
79
81 Collection *collection)
83{
85 const int base_flag = (deg_graph_->mode == DAG_EVAL_RENDER) ? BASE_ENABLED_RENDER :
87 for (; base; base = base->next) {
88 if (base->flag & base_flag) {
89 ids_.add(&base->object->id);
90 }
91 }
92}
93
95{
96 return std::make_unique<DepsgraphFromCollectionIDsNodeBuilder>(
98}
99
101{
102 return std::make_unique<DepsgraphFromCollectionIDsRelationBuilder>(
104}
105
107{
109 for (ID *id : ids_) {
110 node_builder.build_id(id, true);
111 }
112}
113
115{
117 for (ID *id : ids_) {
118 relation_builder.build_id(id);
119 }
120}
121
122} // namespace blender::deg
Base * BKE_collection_or_layer_objects(const Scene *scene, ViewLayer *view_layer, Collection *collection)
@ DAG_EVAL_RENDER
@ BASE_ENABLED_RENDER
@ BASE_ENABLED_VIEWPORT
bool add(const Key &key)
Definition BLI_set.hh:248
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)
virtual unique_ptr< DepsgraphNodeBuilder > construct_node_builder() override
virtual unique_ptr< DepsgraphRelationBuilder > construct_relation_builder() override
virtual void build_nodes(DepsgraphNodeBuilder &node_builder) override
virtual void build_relations(DepsgraphRelationBuilder &relation_builder) override
FromCollectionBuilderPipeline(::Depsgraph *graph, Collection *collection)
const Set< ID * > & ids_
DepsgraphFromCollectionIDsFilter filter_
struct Base * next
short flag
struct Object * object
Definition DNA_ID.h:413
eEvaluationMode mode
Definition depsgraph.hh:136