Blender V5.0
depsgraph_build.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "BLI_listbase.h"
12#include "BLI_utildefines.h"
13
14#include "DNA_cachefile_types.h"
15#include "DNA_camera_types.h"
17#include "DNA_node_types.h"
18#include "DNA_object_types.h"
19#include "DNA_scene_types.h"
20
21#include "BKE_collection.hh"
22#include "BKE_global.hh"
23#include "BKE_main.hh"
24#include "BKE_scene.hh"
25
26#include "DEG_depsgraph.hh"
29
37
39
44
49
50/* ****************** */
51/* External Build API */
52
53namespace deg = blender::deg;
54
67
68static deg::DepsNodeHandle *get_node_handle(DepsNodeHandle *node_handle)
69{
70 return reinterpret_cast<deg::DepsNodeHandle *>(node_handle);
71}
72
73void DEG_add_scene_relation(DepsNodeHandle *node_handle,
74 Scene *scene,
76 const char *description)
77{
79 deg::ComponentKey comp_key(&scene->id, type);
80 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
81 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
82}
83
84static void add_camera_parameters_relation(DepsNodeHandle *node_handle,
85 Camera *camera,
86 const char *description)
87{
88 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
89 deg::ComponentKey parameters_key(&camera->id, deg::NodeType::PARAMETERS);
90 deg_node_handle->builder->add_node_handle_relation(parameters_key, deg_node_handle, description);
91}
92
93void DEG_add_scene_camera_relation(DepsNodeHandle *node_handle,
94 Scene *scene,
96 const char *description)
97{
98 if (scene->camera != nullptr) {
99 DEG_add_object_relation(node_handle, scene->camera, component, description);
100 if (scene->camera->type == OB_CAMERA) {
102 node_handle, reinterpret_cast<Camera *>(scene->camera->data), description);
103 }
104 }
105
106 /* Like DepsgraphNodeBuilder::build_scene_camera(), we also need to account for other cameras
107 * referenced by markers. */
108 LISTBASE_FOREACH (TimeMarker *, marker, &scene->markers) {
109 if (!ELEM(marker->camera, nullptr, scene->camera)) {
110 DEG_add_object_relation(node_handle, marker->camera, component, description);
111 if (marker->camera->type == OB_CAMERA) {
113 node_handle, reinterpret_cast<Camera *>(marker->camera->data), description);
114 }
115 }
116 }
117}
118
119void DEG_add_object_relation(DepsNodeHandle *node_handle,
120 Object *object,
121 eDepsObjectComponentType component,
122 const char *description)
123{
125 deg::ComponentKey comp_key(&object->id, type);
126 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
127 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
128}
129
134
135void DEG_add_collection_geometry_relation(DepsNodeHandle *node_handle,
136 Collection *collection,
137 const char *description)
138{
139 deg::OperationKey operation_key{
141 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
142 deg_node_handle->builder->add_node_handle_relation(operation_key, deg_node_handle, description);
143}
144
145void DEG_add_collection_geometry_customdata_mask(DepsNodeHandle *node_handle,
146 Collection *collection,
147 const CustomData_MeshMasks *masks)
148{
150 DEG_add_customdata_mask(node_handle, ob, masks);
151 if (ob->type == OB_EMPTY && ob->instance_collection != nullptr) {
152 DEG_add_collection_geometry_customdata_mask(node_handle, ob->instance_collection, masks);
153 }
154 }
156}
157
158void DEG_add_node_tree_output_relation(DepsNodeHandle *node_handle,
159 bNodeTree *node_tree,
160 const char *description)
161{
162 deg::OperationKey ntree_output_key(
164 deg::OperationKey ntree_preprocess_key(&node_tree->id,
167 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
168 deg_node_handle->builder->add_node_handle_relation(
169 ntree_output_key, deg_node_handle, description);
170 deg_node_handle->builder->add_node_handle_relation(
171 ntree_preprocess_key, deg_node_handle, description, deg::RELATION_FLAG_NO_FLUSH);
172}
173
174void DEG_add_object_cache_relation(DepsNodeHandle *node_handle,
175 CacheFile *cache_file,
176 eDepsObjectComponentType component,
177 const char *description)
178{
180 deg::ComponentKey comp_key(&cache_file->id, type);
181 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
182 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
183}
184
185void DEG_add_bone_relation(DepsNodeHandle *node_handle,
186 Object *object,
187 const char *bone_name,
188 eDepsObjectComponentType component,
189 const char *description)
190{
192 deg::ComponentKey comp_key(&object->id, type, bone_name);
193 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
194 deg_node_handle->builder->add_node_handle_relation(comp_key, deg_node_handle, description);
195}
196
197void DEG_add_object_pointcache_relation(DepsNodeHandle *node_handle,
198 Object *object,
199 eDepsObjectComponentType component,
200 const char *description)
201{
203 deg::ComponentKey comp_key(&object->id, type);
204 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
205 deg::DepsgraphRelationBuilder *relation_builder = deg_node_handle->builder;
206 /* Add relation from source to the node handle. */
207 relation_builder->add_node_handle_relation(comp_key, deg_node_handle, description);
208 /* Node deduct point cache component and connect source to it. */
209 ID *id = DEG_get_id_from_handle(node_handle);
211 deg::Relation *rel = relation_builder->add_relation(comp_key, point_cache_key, "Point Cache");
212 if (rel != nullptr) {
214 }
215 else {
216 fprintf(stderr, "Error in point cache relation from %s to ^%s.\n", object->id.name, id->name);
217 }
218}
219
220void DEG_add_generic_id_relation(DepsNodeHandle *node_handle, ID *id, const char *description)
221{
222 deg::OperationKey operation_key(
224 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
225 deg_node_handle->builder->add_node_handle_relation(operation_key, deg_node_handle, description);
226}
227
228void DEG_add_depends_on_transform_relation(DepsNodeHandle *node_handle, const char *description)
229{
230 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
231 deg_node_handle->builder->add_depends_on_transform_relation(deg_node_handle, description);
232}
233
234void DEG_add_special_eval_flag(DepsNodeHandle *node_handle, ID *id, uint32_t flag)
235{
236 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
237 deg_node_handle->builder->add_special_eval_flag(id, flag);
238}
239
240void DEG_add_customdata_mask(DepsNodeHandle *node_handle,
241 Object *object,
242 const CustomData_MeshMasks *masks)
243{
244 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
245 deg_node_handle->builder->add_customdata_mask(object, deg::DEGCustomDataMeshMasks(masks));
246}
247
248ID *DEG_get_id_from_handle(DepsNodeHandle *node_handle)
249{
250 deg::DepsNodeHandle *deg_handle = get_node_handle(node_handle);
251 return deg_handle->node->owner->owner->id_orig;
252}
253
254Depsgraph *DEG_get_graph_from_handle(DepsNodeHandle *node_handle)
255{
256 deg::DepsNodeHandle *deg_node_handle = get_node_handle(node_handle);
257 deg::DepsgraphRelationBuilder *relation_builder = deg_node_handle->builder;
258 return reinterpret_cast<Depsgraph *>(relation_builder->getGraph());
259}
260
261/* ******************** */
262/* Graph Building API's */
263
265{
266 deg::ViewLayerBuilderPipeline builder(graph);
267 builder.build();
268}
269
271{
272 deg::AllObjectsBuilderPipeline builder(graph);
273 builder.build();
274}
275
277{
278 deg::RenderBuilderPipeline builder(graph);
279 builder.build();
280}
281
282void DEG_graph_build_for_compositor_preview(Depsgraph *graph, bNodeTree *nodetree)
283{
284 deg::CompositorBuilderPipeline builder(graph, nodetree);
285 builder.build();
286}
287
289{
290 deg::FromIDsBuilderPipeline builder(graph, ids);
291 builder.build();
292}
293
294void DEG_graph_build_from_collection(Depsgraph *graph, Collection *collection)
295{
296 deg::FromCollectionBuilderPipeline builder(graph, collection);
297 builder.build();
298}
299
300void DEG_graph_tag_relations_update(Depsgraph *graph)
301{
302 DEG_DEBUG_PRINTF(graph, TAG, "%s: Tagging relations for update.\n", __func__);
303 deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(graph);
304 deg_graph->need_update_relations = true;
305
306 /* NOTE: When relations are updated, it's quite possible that we've got new bases in the scene.
307 * This means, we need to re-create flat array of bases in view layer. */
308 /* TODO(sergey): It is expected that bases manipulation tags scene for update to tag bases array
309 * for re-creation. Once it is ensured to happen from all places this implicit tag can be
310 * removed. */
311 deg::IDNode *id_node = deg_graph->find_id_node(&deg_graph->scene->id);
312 if (id_node != nullptr) {
313 graph_id_tag_update(deg_graph->bmain,
314 deg_graph,
315 &deg_graph->scene->id,
318 }
319}
320
321void DEG_graph_relations_update(Depsgraph *graph)
322{
323 deg::Depsgraph *deg_graph = (deg::Depsgraph *)graph;
324 if (!deg_graph->need_update_relations) {
325 /* Graph is up to date, nothing to do. */
326 return;
327 }
329}
330
332{
333 DEG_GLOBAL_DEBUG_PRINTF(TAG, "%s: Tagging relations for update.\n", __func__);
335 DEG_graph_tag_relations_update(reinterpret_cast<Depsgraph *>(depsgraph));
336 }
337}
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
#define LISTBASE_FOREACH(type, var, list)
#define ELEM(...)
eDepsSceneComponentType
@ DEG_SCENE_COMP_ANIMATION
@ DEG_SCENE_COMP_PARAMETERS
@ DEG_SCENE_COMP_SEQUENCER
eDepsObjectComponentType
@ ID_RECALC_HIERARCHY
Definition DNA_ID.h:1158
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
@ OB_EMPTY
@ OB_CAMERA
BPy_StructRNA * depsgraph
Relation * add_depends_on_transform_relation(ID *id, const KeyTo &key_to, const char *description, int flags=0)
void add_customdata_mask(Object *object, const DEGCustomDataMeshMasks &customdata_masks)
Relation * add_node_handle_relation(const KeyType &key_from, const DepsNodeHandle *handle, const char *description, int flags=0)
void add_special_eval_flag(ID *id, uint32_t flag)
Relation * add_relation(const KeyFrom &key_from, const KeyTo &key_to, const char *description, int flags=0)
#define DEG_GLOBAL_DEBUG_PRINTF(type,...)
Definition deg_debug.h:51
#define DEG_DEBUG_PRINTF(depsgraph, type,...)
Definition deg_debug.h:43
void DEG_add_scene_camera_relation(DepsNodeHandle *node_handle, Scene *scene, eDepsObjectComponentType component, const char *description)
void DEG_add_generic_id_relation(DepsNodeHandle *node_handle, ID *id, const char *description)
ID * DEG_get_id_from_handle(DepsNodeHandle *node_handle)
void DEG_relations_tag_update(Main *bmain)
void DEG_add_customdata_mask(DepsNodeHandle *node_handle, Object *object, const CustomData_MeshMasks *masks)
void DEG_graph_build_for_compositor_preview(Depsgraph *graph, bNodeTree *nodetree)
void DEG_add_special_eval_flag(DepsNodeHandle *node_handle, ID *id, uint32_t flag)
static deg::DepsNodeHandle * get_node_handle(DepsNodeHandle *node_handle)
void DEG_add_depends_on_transform_relation(DepsNodeHandle *node_handle, const char *description)
void DEG_graph_build_from_collection(Depsgraph *graph, Collection *collection)
void DEG_add_collection_geometry_relation(DepsNodeHandle *node_handle, Collection *collection, const char *description)
void DEG_add_object_cache_relation(DepsNodeHandle *node_handle, CacheFile *cache_file, eDepsObjectComponentType component, const char *description)
void DEG_graph_build_from_ids(Depsgraph *graph, blender::Span< ID * > ids)
void DEG_graph_tag_relations_update(Depsgraph *graph)
void DEG_add_scene_relation(DepsNodeHandle *node_handle, Scene *scene, eDepsSceneComponentType component, const char *description)
void DEG_add_object_pointcache_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
bool DEG_object_has_geometry_component(Object *object)
void DEG_add_object_relation(DepsNodeHandle *node_handle, Object *object, eDepsObjectComponentType component, const char *description)
void DEG_graph_build_for_all_objects(Depsgraph *graph)
void DEG_add_bone_relation(DepsNodeHandle *node_handle, Object *object, const char *bone_name, eDepsObjectComponentType component, const char *description)
void DEG_graph_build_for_render_pipeline(Depsgraph *graph)
Depsgraph * DEG_get_graph_from_handle(DepsNodeHandle *node_handle)
void DEG_graph_relations_update(Depsgraph *graph)
void DEG_add_collection_geometry_customdata_mask(DepsNodeHandle *node_handle, Collection *collection, const CustomData_MeshMasks *masks)
void DEG_graph_build_from_view_layer(Depsgraph *graph)
void DEG_add_node_tree_output_relation(DepsNodeHandle *node_handle, bNodeTree *node_tree, const char *description)
static void add_camera_parameters_relation(DepsNodeHandle *node_handle, Camera *camera, const char *description)
static deg::NodeType deg_build_scene_component_type(eDepsSceneComponentType component)
Span< Depsgraph * > get_all_registered_graphs(Main *bmain)
NodeType geometry_tag_to_component(const ID *id)
NodeType nodeTypeFromObjectComponent(eDepsObjectComponentType component_type)
Definition deg_node.cc:173
Definition DNA_ID.h:414
char name[258]
Definition DNA_ID.h:432
struct Object * camera
ListBase markers
DepsgraphRelationBuilder * builder
IDNode * find_id_node(const ID *id) const
Definition depsgraph.cc:101
uint8_t flag
Definition wm_window.cc:145