Blender V5.0
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 (!deg_graph_->use_visibility_optimization || (base->flag & base_flag)) {
89 ids_.add(&base->object->id);
90 }
91 }
92}
93
94std::unique_ptr<DepsgraphNodeBuilder> FromCollectionBuilderPipeline::construct_node_builder()
95{
96 return std::make_unique<DepsgraphFromCollectionIDsNodeBuilder>(
98}
99
100std::unique_ptr<DepsgraphRelationBuilder> FromCollectionBuilderPipeline::
102{
103 return std::make_unique<DepsgraphFromCollectionIDsRelationBuilder>(
105}
106
108{
110 for (ID *id : ids_) {
111 node_builder.build_id(id, true);
112 }
113}
114
116{
118 for (ID *id : ids_) {
119 relation_builder.build_id(id);
120 }
121}
122
123} // namespace blender::deg
Base * BKE_collection_or_layer_objects(const Scene *scene, ViewLayer *view_layer, Collection *collection)
@ DAG_EVAL_RENDER
struct ID ID
@ BASE_ENABLED_RENDER
@ BASE_ENABLED_VIEWPORT
struct Base Base
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
void build_relations(DepsgraphRelationBuilder &relation_builder) override
std::unique_ptr< DepsgraphRelationBuilder > construct_relation_builder() override
FromCollectionBuilderPipeline(::Depsgraph *graph, Collection *collection)
std::unique_ptr< DepsgraphNodeBuilder > construct_node_builder() override
bool contains(const VArray< bool > &varray, const IndexMask &indices_to_check, bool value)
struct Base * next
short flag
struct Object * object
Definition DNA_ID.h:414