Blender V5.3
rna_depsgraph.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "BLI_path_utils.hh"
12
13#include "RNA_define.hh"
14#include "RNA_enum_types.hh"
15
16#include "rna_internal.hh"
17
18#include "BKE_duplilist.hh"
19
20#include "DEG_depsgraph.hh"
21
22#define STATS_MAX_SIZE 16384
23
24#ifdef RNA_RUNTIME
25
26# ifdef WITH_PYTHON
27# include "BPY_extern.hh"
28# endif
29
30# include "BLI_iterator.hh"
31# include "BLI_math_matrix_c.hh"
32# include "BLI_math_vector_c.hh"
33# include "BLI_string.hh"
34
35# include "DNA_scene_types.h"
36
37# include "RNA_access.hh"
38
39# include "BKE_object.hh"
40# include "BKE_report.hh"
41# include "BKE_scene.hh"
42
43# include "DEG_depsgraph_build.hh"
44# include "DEG_depsgraph_debug.hh"
45# include "DEG_depsgraph_query.hh"
46
47# include "MEM_guardedalloc.h"
48
49namespace blender {
50
51/* **************** Object Instance **************** */
52
53struct RNA_DepsgraphIterator {
54 BLI_Iterator iter;
55# ifdef WITH_PYTHON
60 void *py_instance;
61# endif
62};
63
64# ifdef WITH_PYTHON
65void **rna_DepsgraphIterator_instance(PointerRNA *ptr)
66{
67 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
68 return &di->py_instance;
69}
70# endif
71
72static PointerRNA rna_DepsgraphObjectInstance_object_get(PointerRNA *ptr)
73{
74 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
75 return RNA_id_pointer_create(reinterpret_cast<ID *>(di->iter.current));
76}
77
78static bool rna_DepsgraphObjectInstance_is_instance_get(PointerRNA *ptr)
79{
80 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
81 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
82 return (deg_iter->dupli_object_current != nullptr);
83}
84
85static PointerRNA rna_DepsgraphObjectInstance_instance_object_get(PointerRNA *ptr)
86{
87 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
88 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
89 Object *instance_object = nullptr;
90 if (deg_iter->dupli_object_current != nullptr) {
91 instance_object = deg_iter->dupli_object_current->ob;
92 }
93 return RNA_id_pointer_create(reinterpret_cast<ID *>(instance_object));
94}
95
96static bool rna_DepsgraphObjectInstance_show_self_get(PointerRNA *ptr)
97{
98 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
99 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
100 int ob_visibility = BKE_object_visibility(static_cast<const Object *>(di->iter.current),
101 deg_iter->eval_mode);
102 return (ob_visibility & OB_VISIBLE_SELF) != 0;
103}
104
105static bool rna_DepsgraphObjectInstance_show_particles_get(PointerRNA *ptr)
106{
107 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
108 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
109 int ob_visibility = BKE_object_visibility(static_cast<const Object *>(di->iter.current),
110 deg_iter->eval_mode);
111 return (ob_visibility & OB_VISIBLE_PARTICLES) != 0;
112}
113
114static PointerRNA rna_DepsgraphObjectInstance_parent_get(PointerRNA *ptr)
115{
116 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
117 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
118 Object *dupli_parent = nullptr;
119 if (deg_iter->dupli_object_current != nullptr) {
120 dupli_parent = deg_iter->dupli_parent;
121 }
122 return RNA_id_pointer_create(reinterpret_cast<ID *>(dupli_parent));
123}
124
125static PointerRNA rna_DepsgraphObjectInstance_particle_system_get(PointerRNA *ptr)
126{
127 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
128 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
129 ParticleSystem *particle_system = nullptr;
130 if (deg_iter->dupli_object_current != nullptr) {
131 particle_system = deg_iter->dupli_object_current->particle_system;
132 }
133 return RNA_pointer_create_with_parent(*ptr, RNA_ParticleSystem, particle_system);
134}
135
136static void rna_DepsgraphObjectInstance_persistent_id_get(PointerRNA *ptr, int *persistent_id)
137{
138 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
139 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
140 if (deg_iter->dupli_object_current != nullptr) {
141 memcpy(persistent_id,
142 deg_iter->dupli_object_current->persistent_id,
143 sizeof(deg_iter->dupli_object_current->persistent_id));
144 }
145 else {
146 memset(persistent_id, 0, sizeof(deg_iter->dupli_object_current->persistent_id));
147 }
148}
149
150static int rna_DepsgraphObjectInstance_random_id_get(PointerRNA *ptr)
151{
152 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
153 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
154 if (deg_iter->dupli_object_current != nullptr) {
155 return int(deg_iter->dupli_object_current->random_id);
156 }
157 return 0;
158}
159
160static void rna_DepsgraphObjectInstance_matrix_world_get(PointerRNA *ptr, float *mat)
161{
162 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
163 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
164 if (deg_iter->dupli_object_current != nullptr) {
165 copy_m4_m4(reinterpret_cast<float (*)[4]>(mat), deg_iter->dupli_object_current->mat);
166 }
167 else {
168 /* We can return actual object's matrix here, no reason to return identity matrix
169 * when this is not actually an instance... */
170 Object *ob = static_cast<Object *>(di->iter.current);
171 copy_m4_m4(reinterpret_cast<float (*)[4]>(mat), ob->object_to_world().ptr());
172 }
173}
174
175static void rna_DepsgraphObjectInstance_orco_get(PointerRNA *ptr, float *orco)
176{
177 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
178 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
179 if (deg_iter->dupli_object_current != nullptr) {
180 copy_v3_v3(orco, deg_iter->dupli_object_current->orco);
181 }
182 else {
183 zero_v3(orco);
184 }
185}
186
187static void rna_DepsgraphObjectInstance_uv_get(PointerRNA *ptr, float *uv)
188{
189 RNA_DepsgraphIterator *di = static_cast<RNA_DepsgraphIterator *>(ptr->data);
190 DEGObjectIterData *deg_iter = static_cast<DEGObjectIterData *>(di->iter.data);
191 if (deg_iter->dupli_object_current != nullptr) {
192 copy_v2_v2(uv, deg_iter->dupli_object_current->uv);
193 }
194 else {
195 zero_v2(uv);
196 }
197}
198
199/* ******************** Sorted ***************** */
200
201static int rna_Depsgraph_mode_get(PointerRNA *ptr)
202{
203 Depsgraph *depsgraph = static_cast<Depsgraph *>(ptr->data);
204 return DEG_get_mode(depsgraph);
205}
206
207/* ******************** Updates ***************** */
208
209static PointerRNA rna_DepsgraphUpdate_id_get(PointerRNA *ptr)
210{
211 return RNA_id_pointer_create(reinterpret_cast<ID *>(ptr->data));
212}
213
214static bool rna_DepsgraphUpdate_is_updated_transform_get(PointerRNA *ptr)
215{
216 ID *id = static_cast<ID *>(ptr->data);
217 return ((id->recalc & ID_RECALC_TRANSFORM) != 0);
218}
219
220static bool rna_DepsgraphUpdate_is_updated_shading_get(PointerRNA *ptr)
221{
222 /* Assume any animated parameters can affect shading, we don't have fine
223 * grained enough updates to distinguish this. */
224 ID *id = static_cast<ID *>(ptr->data);
225 return ((id->recalc & (ID_RECALC_SHADING | ID_RECALC_ANIMATION)) != 0);
226}
227
228static bool rna_DepsgraphUpdate_is_updated_geometry_get(PointerRNA *ptr)
229{
230 ID *id = static_cast<ID *>(ptr->data);
231 if (id->recalc & ID_RECALC_GEOMETRY) {
232 return true;
233 }
234 if (GS(id->name) != ID_OB) {
235 return false;
236 }
237 Object *object = id_cast<Object *>(id);
238 ID *data = object->data;
239 if (data == nullptr) {
240 return false;
241 }
242 return ((data->recalc & ID_RECALC_ALL) != 0);
243}
244
245/* **************** Depsgraph **************** */
246
247static void rna_Depsgraph_debug_relations_graphviz(Depsgraph *depsgraph,
248 const char *filepath,
249 const char **r_str,
250 int *r_len)
251{
252 const std::string dot_str = DEG_debug_graph_to_dot(*depsgraph, "Depsgraph");
253 *r_len = dot_str.size();
254 *r_str = BLI_strdup(dot_str.c_str());
255
256 if (filepath) {
257 FILE *f = fopen(filepath, "w");
258 if (f == nullptr) {
259 return;
260 }
261 fprintf(f, "%s", dot_str.c_str());
262 fclose(f);
263 }
264}
265
266static void rna_Depsgraph_debug_stats_gnuplot(Depsgraph *depsgraph,
267 const char *filepath,
268 const char *output_filepath)
269{
270 FILE *f = fopen(filepath, "w");
271 if (f == nullptr) {
272 return;
273 }
274 DEG_debug_stats_gnuplot(depsgraph, f, "Timing Statistics", output_filepath);
275 fclose(f);
276}
277
278static void rna_Depsgraph_debug_tag_update(Depsgraph *depsgraph)
279{
281}
282
283static void rna_Depsgraph_debug_stats(Depsgraph *depsgraph, char *result)
284{
285 size_t outer, ops, rels;
286 DEG_stats_simple(depsgraph, &outer, &ops, &rels);
289 "Approx %zu Operations, %zu Relations, %zu Outer Nodes",
290 ops,
291 rels,
292 outer);
293}
294
295static void rna_Depsgraph_update(Depsgraph *depsgraph, Main *bmain, ReportList *reports)
296{
297 if (DEG_is_evaluating(depsgraph)) {
298 BKE_report(reports, RPT_ERROR, "Dependency graph update requested during evaluation");
299 return;
300 }
301
302# ifdef WITH_PYTHON
303 /* Allow drivers to be evaluated */
305# endif
306
307 BKE_scene_graph_update_tagged(depsgraph, bmain);
308
309# ifdef WITH_PYTHON
311# endif
312}
313
314/* Iteration over objects, simple version */
315
316static void rna_Depsgraph_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
317{
318 iter->internal.custom = MEM_new_zeroed<BLI_Iterator>(__func__);
319 DEGObjectIterData *data = MEM_new<DEGObjectIterData>(__func__);
320 DEGObjectIterSettings *deg_iter_settings = MEM_new_zeroed<DEGObjectIterSettings>(__func__);
321 deg_iter_settings->depsgraph = static_cast<Depsgraph *>(ptr->data);
324
325 data->settings = deg_iter_settings;
326 data->graph = deg_iter_settings->depsgraph;
327 data->flag = deg_iter_settings->flags;
328
329 (static_cast<BLI_Iterator *>(iter->internal.custom))->valid = true;
330 DEG_iterator_objects_begin(static_cast<BLI_Iterator *>(iter->internal.custom), data);
331 iter->valid = (static_cast<BLI_Iterator *>(iter->internal.custom))->valid;
332}
333
334static void rna_Depsgraph_objects_next(CollectionPropertyIterator *iter)
335{
336 DEG_iterator_objects_next(static_cast<BLI_Iterator *>(iter->internal.custom));
337 iter->valid = (static_cast<BLI_Iterator *>(iter->internal.custom))->valid;
338}
339
340static void rna_Depsgraph_objects_end(CollectionPropertyIterator *iter)
341{
342 BLI_Iterator *bli_iter = static_cast<BLI_Iterator *>(iter->internal.custom);
343 DEGObjectIterData *data = static_cast<DEGObjectIterData *>(bli_iter->data);
344 DEG_iterator_objects_end(bli_iter);
345 MEM_delete(data->settings);
346 MEM_delete(data);
347 MEM_delete(bli_iter);
348}
349
350static PointerRNA rna_Depsgraph_objects_get(CollectionPropertyIterator *iter)
351{
352 Object *ob = static_cast<Object *>(
353 (static_cast<BLI_Iterator *>(iter->internal.custom))->current);
354 return RNA_id_pointer_create(reinterpret_cast<ID *>(ob));
355}
356
357/* Iteration over objects, extended version
358 *
359 * Contains extra information about duplicator and persistent ID.
360 */
361
362/* XXX Ugly python seems to query next item of an iterator before using current one (see #57558).
363 * This forces us to use that nasty ping-pong game between two sets of iterator data,
364 * so that previous one remains valid memory for python to access to. Yuck.
365 */
366struct RNA_Depsgraph_Instances_Iterator {
367 RNA_DepsgraphIterator iterators[2];
368 DEGObjectIterData deg_data[2];
369 DupliObject dupli_object_current[2];
370 int counter;
371};
372
373static void rna_Depsgraph_object_instances_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
374{
375 RNA_Depsgraph_Instances_Iterator *di_it = MEM_new<RNA_Depsgraph_Instances_Iterator>(__func__);
376 iter->internal.custom = di_it;
377 DEGObjectIterSettings *deg_iter_settings = MEM_new_zeroed<DEGObjectIterSettings>(__func__);
378 deg_iter_settings->depsgraph = static_cast<Depsgraph *>(ptr->data);
379 deg_iter_settings->flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
382
383 DEGObjectIterData *data = &di_it->deg_data[0];
384 data->settings = deg_iter_settings;
385 data->graph = deg_iter_settings->depsgraph;
386 data->flag = deg_iter_settings->flags;
387
388 di_it->iterators[0].iter.valid = true;
389 DEG_iterator_objects_begin(&di_it->iterators[0].iter, data);
390 iter->valid = di_it->iterators[0].iter.valid;
391}
392
393static void rna_Depsgraph_object_instances_next(CollectionPropertyIterator *iter)
394{
395 RNA_Depsgraph_Instances_Iterator *di_it = static_cast<RNA_Depsgraph_Instances_Iterator *>(
396 iter->internal.custom);
397
398 /* We need to copy current iterator status to next one being worked on. */
399 di_it->iterators[(di_it->counter + 1) % 2].iter = di_it->iterators[di_it->counter % 2].iter;
400 di_it->deg_data[(di_it->counter + 1) % 2].transfer_from(di_it->deg_data[di_it->counter % 2]);
401 di_it->counter++;
402
403 di_it->iterators[di_it->counter % 2].iter.data = &di_it->deg_data[di_it->counter % 2];
404 DEG_iterator_objects_next(&di_it->iterators[di_it->counter % 2].iter);
405 /* Dupli_object_current is also temp memory generated during the iterations,
406 * it may be freed when last item has been iterated,
407 * so we have same issue as with the iterator itself:
408 * we need to keep a local copy, which memory remains valid a bit longer,
409 * for Python accesses to work. */
410 if (di_it->deg_data[di_it->counter % 2].dupli_object_current != nullptr) {
411 di_it->dupli_object_current[di_it->counter % 2] =
412 *di_it->deg_data[di_it->counter % 2].dupli_object_current;
413 di_it->deg_data[di_it->counter % 2].dupli_object_current =
414 &di_it->dupli_object_current[di_it->counter % 2];
415 }
416 iter->valid = di_it->iterators[di_it->counter % 2].iter.valid;
417}
418
419static void rna_Depsgraph_object_instances_end(CollectionPropertyIterator *iter)
420{
421 RNA_Depsgraph_Instances_Iterator *di_it = static_cast<RNA_Depsgraph_Instances_Iterator *>(
422 iter->internal.custom);
423 for (int i = 0; i < ARRAY_SIZE(di_it->iterators); i++) {
424 RNA_DepsgraphIterator *di = &di_it->iterators[i];
425 DEGObjectIterData *data = &di_it->deg_data[i];
426 if (i == 0) {
427 /* Is shared between both iterators. */
428 MEM_delete(data->settings);
429 }
430 DEG_iterator_objects_end(&di->iter);
431
432# ifdef WITH_PYTHON
433 if (di->py_instance) {
434 BPY_DECREF_RNA_INVALIDATE(di->py_instance);
435 }
436# endif
437 }
438
439 MEM_delete(di_it);
440}
441
442static PointerRNA rna_Depsgraph_object_instances_get(CollectionPropertyIterator *iter)
443{
444 RNA_Depsgraph_Instances_Iterator *di_it = static_cast<RNA_Depsgraph_Instances_Iterator *>(
445 iter->internal.custom);
446 RNA_DepsgraphIterator *di = &di_it->iterators[di_it->counter % 2];
447 return RNA_pointer_create_with_parent(iter->parent, RNA_DepsgraphObjectInstance, di);
448}
449
450/* Iteration over evaluated IDs */
451
452static void rna_Depsgraph_ids_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
453{
454 iter->internal.custom = MEM_new_zeroed<BLI_Iterator>(__func__);
455 DEGIDIterData *data = MEM_new_zeroed<DEGIDIterData>(__func__);
456
457 data->graph = static_cast<Depsgraph *>(ptr->data);
458
459 (static_cast<BLI_Iterator *>(iter->internal.custom))->valid = true;
460 DEG_iterator_ids_begin(static_cast<BLI_Iterator *>(iter->internal.custom), data);
461 iter->valid = (static_cast<BLI_Iterator *>(iter->internal.custom))->valid;
462}
463
464static void rna_Depsgraph_ids_next(CollectionPropertyIterator *iter)
465{
466 DEG_iterator_ids_next(static_cast<BLI_Iterator *>(iter->internal.custom));
467 iter->valid = (static_cast<BLI_Iterator *>(iter->internal.custom))->valid;
468}
469
470static void rna_Depsgraph_ids_end(CollectionPropertyIterator *iter)
471{
472 BLI_Iterator *bli_iter = static_cast<BLI_Iterator *>(iter->internal.custom);
473 DEG_iterator_ids_end(bli_iter);
474 MEM_delete(static_cast<DEGIDIterData *>(bli_iter->data));
475 MEM_delete(bli_iter);
476}
477
478static PointerRNA rna_Depsgraph_ids_get(CollectionPropertyIterator *iter)
479{
480 ID *id = static_cast<ID *>((static_cast<BLI_Iterator *>(iter->internal.custom))->current);
481 return RNA_id_pointer_create(id);
482}
483
484static void rna_Depsgraph_updates_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
485{
486 iter->internal.custom = MEM_new_zeroed<BLI_Iterator>(__func__);
487 DEGIDIterData *data = MEM_new_zeroed<DEGIDIterData>(__func__);
488
489 data->graph = static_cast<Depsgraph *>(ptr->data);
490 data->only_updated = true;
491
492 (static_cast<BLI_Iterator *>(iter->internal.custom))->valid = true;
493 DEG_iterator_ids_begin(static_cast<BLI_Iterator *>(iter->internal.custom), data);
494 iter->valid = (static_cast<BLI_Iterator *>(iter->internal.custom))->valid;
495}
496
497static PointerRNA rna_Depsgraph_updates_get(CollectionPropertyIterator *iter)
498{
499 ID *id = static_cast<ID *>((static_cast<BLI_Iterator *>(iter->internal.custom))->current);
500 return RNA_pointer_create_with_parent(iter->parent, RNA_DepsgraphUpdate, id);
501}
502
503static ID *rna_Depsgraph_id_eval_get(Depsgraph *depsgraph, ID *id_orig)
504{
505 return DEG_get_evaluated(depsgraph, id_orig);
506}
507
508static bool rna_Depsgraph_id_type_updated(Depsgraph *depsgraph, int id_type)
509{
510 return DEG_id_type_updated(depsgraph, id_type);
511}
512
513static PointerRNA rna_Depsgraph_scene_get(PointerRNA *ptr)
514{
515 Depsgraph *depsgraph = static_cast<Depsgraph *>(ptr->data);
516 Scene *scene = DEG_get_input_scene(depsgraph);
517 PointerRNA newptr = RNA_id_pointer_create(&scene->id);
518 return newptr;
519}
520
521static PointerRNA rna_Depsgraph_view_layer_get(PointerRNA *ptr)
522{
523 Depsgraph *depsgraph = static_cast<Depsgraph *>(ptr->data);
524 Scene *scene = DEG_get_input_scene(depsgraph);
525 ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
526 PointerRNA newptr = RNA_pointer_create_id_subdata(scene->id, RNA_ViewLayer, view_layer);
527 return newptr;
528}
529
530static PointerRNA rna_Depsgraph_scene_eval_get(PointerRNA *ptr)
531{
532 Depsgraph *depsgraph = static_cast<Depsgraph *>(ptr->data);
533 Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
534 PointerRNA newptr = RNA_id_pointer_create(&scene_eval->id);
535 return newptr;
536}
537
538static PointerRNA rna_Depsgraph_view_layer_eval_get(PointerRNA *ptr)
539{
540 Depsgraph *depsgraph = static_cast<Depsgraph *>(ptr->data);
541 Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
542 ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
543 PointerRNA newptr = RNA_pointer_create_id_subdata(
544 scene_eval->id, RNA_ViewLayer, view_layer_eval);
545 return newptr;
546}
547
548} // namespace blender
549
550#else
551
552namespace blender {
553
555{
556 StructRNA *srna;
557 PropertyRNA *prop;
558
559 srna = RNA_def_struct(brna, "DepsgraphObjectInstance", nullptr);
561 "Dependency Graph Object Instance",
562 "Extended information about dependency graph object iterator "
563 "(Warning: All data here is 'evaluated' one, not original .blend IDs)");
564
565# ifdef WITH_PYTHON
566 RNA_def_struct_register_funcs(srna, nullptr, nullptr, "rna_DepsgraphIterator_instance");
567# endif
568
569 prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
570 RNA_def_property_struct_type(prop, "Object");
571 RNA_def_property_ui_text(prop, "Object", "Evaluated object the iterator points to");
574 prop, "rna_DepsgraphObjectInstance_object_get", nullptr, nullptr, nullptr);
575
576 prop = RNA_def_property(srna, "show_self", PROP_BOOLEAN, PROP_NONE);
579 prop, "Show Self", "The object geometry itself should be visible in the render");
580 RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_show_self_get", nullptr);
581
582 prop = RNA_def_property(srna, "show_particles", PROP_BOOLEAN, PROP_NONE);
585 prop, "Show Particles", "Particles part of the object should be visible in the render");
586 RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_show_particles_get", nullptr);
587
588 prop = RNA_def_property(srna, "is_instance", PROP_BOOLEAN, PROP_NONE);
591 prop, "Is Instance", "Denotes if the object is generated by another object");
592 RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_is_instance_get", nullptr);
593
594 prop = RNA_def_property(srna, "instance_object", PROP_POINTER, PROP_NONE);
595 RNA_def_property_struct_type(prop, "Object");
597 prop, "Instance Object", "Evaluated object which is being instanced by this iterator");
600 prop, "rna_DepsgraphObjectInstance_instance_object_get", nullptr, nullptr, nullptr);
601
602 prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
603 RNA_def_property_struct_type(prop, "Object");
605 prop, "Parent", "If the object is an instance, the parent object that generated it");
608 prop, "rna_DepsgraphObjectInstance_parent_get", nullptr, nullptr, nullptr);
609
610 prop = RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE);
611 RNA_def_property_struct_type(prop, "ParticleSystem");
614 prop, "Particle System", "Evaluated particle system that this object was instanced from");
616 prop, "rna_DepsgraphObjectInstance_particle_system_get", nullptr, nullptr, nullptr);
617
618 prop = RNA_def_property(srna, "persistent_id", PROP_INT, PROP_NONE);
620 prop,
621 "Persistent ID",
622 "Persistent identifier for inter-frame matching of objects with motion blur");
626 prop, "rna_DepsgraphObjectInstance_persistent_id_get", nullptr, nullptr);
627
628 prop = RNA_def_property(srna, "random_id", PROP_INT, PROP_UNSIGNED);
631 prop, "Instance Random ID", "Random id for this instance, typically for randomized shading");
632 RNA_def_property_int_funcs(prop, "rna_DepsgraphObjectInstance_random_id_get", nullptr, nullptr);
633
634 prop = RNA_def_property(srna, "matrix_world", PROP_FLOAT, PROP_MATRIX);
637 RNA_def_property_ui_text(prop, "Generated Matrix", "Generated transform matrix in world space");
639 prop, "rna_DepsgraphObjectInstance_matrix_world_get", nullptr, nullptr);
640
641 prop = RNA_def_property(srna, "orco", PROP_FLOAT, PROP_TRANSLATION);
643 RNA_def_property_array(prop, 3);
645 prop, "Generated Coordinates", "Generated coordinates in parent object space");
646 RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_orco_get", nullptr, nullptr);
647
648 prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
649 RNA_def_property_ui_text(prop, "UV Coordinates", "UV coordinates in parent object space");
650 RNA_def_property_array(prop, 2);
652 RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_uv_get", nullptr, nullptr);
653}
654
656{
657 StructRNA *srna;
658 PropertyRNA *prop;
659
660 srna = RNA_def_struct(brna, "DepsgraphUpdate", nullptr);
661 RNA_def_struct_ui_text(srna, "Dependency Graph Update", "Information about ID that was updated");
662
663 prop = RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE);
665 RNA_def_property_ui_text(prop, "ID", "Updated data-block");
667 RNA_def_property_pointer_funcs(prop, "rna_DepsgraphUpdate_id_get", nullptr, nullptr, nullptr);
668
669 /* Use term 'is_updated' instead of 'is_dirty' here because this is a signal
670 * that users of the depsgraph may want to update their data (render engines for eg). */
671
672 prop = RNA_def_property(srna, "is_updated_transform", PROP_BOOLEAN, PROP_NONE);
674 RNA_def_property_ui_text(prop, "Transform", "Object transformation is updated");
675 RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_updated_transform_get", nullptr);
676
677 prop = RNA_def_property(srna, "is_updated_geometry", PROP_BOOLEAN, PROP_NONE);
679 RNA_def_property_ui_text(prop, "Geometry", "Object geometry is updated");
680 RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_updated_geometry_get", nullptr);
681
682 prop = RNA_def_property(srna, "is_updated_shading", PROP_BOOLEAN, PROP_NONE);
684 RNA_def_property_ui_text(prop, "Shading", "Object shading is updated");
685 RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_updated_shading_get", nullptr);
686}
687
689{
690 StructRNA *srna;
691 FunctionRNA *func;
692 PropertyRNA *parm;
693 PropertyRNA *prop;
694
695 static const EnumPropertyItem enum_depsgraph_mode_items[] = {
696 {DAG_EVAL_VIEWPORT, "VIEWPORT", 0, "Viewport", "Viewport non-rendered mode"},
697 {DAG_EVAL_RENDER, "RENDER", 0, "Render", "Render"},
698 {0, nullptr, 0, nullptr, nullptr},
699 };
700
701 srna = RNA_def_struct(brna, "Depsgraph", nullptr);
702 RNA_def_struct_ui_text(srna, "Dependency Graph", "");
703
704 prop = RNA_def_enum(srna, "mode", enum_depsgraph_mode_items, 0, "Mode", "Evaluation mode");
706 RNA_def_property_enum_funcs(prop, "rna_Depsgraph_mode_get", nullptr, nullptr);
707
708 /* Debug helpers. */
709
710 func = RNA_def_function(
711 srna, "debug_relations_graphviz", "rna_Depsgraph_debug_relations_graphviz");
712 parm = RNA_def_string_file_path(func,
713 "filepath",
714 nullptr,
715 FILE_MAX,
716 "File Name",
717 "Optional output path for the graphviz debug file");
718 parm = RNA_def_string(func, "dot_graph", nullptr, INT32_MAX, "Dot Graph", "Graph in dot format");
721 RNA_def_function_output(func, parm);
722
723 func = RNA_def_function(srna, "debug_stats_gnuplot", "rna_Depsgraph_debug_stats_gnuplot");
725 func, "filepath", nullptr, FILE_MAX, "File Name", "Output path for the gnuplot debug file");
727 parm = RNA_def_string_file_path(func,
728 "output_filepath",
729 nullptr,
730 FILE_MAX,
731 "Output File Name",
732 "File name where gnuplot script will save the result");
734
735 func = RNA_def_function(srna, "debug_tag_update", "rna_Depsgraph_debug_tag_update");
736
737 func = RNA_def_function(srna, "debug_stats", "rna_Depsgraph_debug_stats");
738 RNA_def_function_ui_description(func, "Report the number of elements in the Dependency Graph");
739 /* weak!, no way to return dynamic string type */
740 parm = RNA_def_string(func, "result", nullptr, STATS_MAX_SIZE, "result", "");
742 parm, PROP_THICK_WRAP, ParameterFlag(0)); /* needed for string return value */
743 RNA_def_function_output(func, parm);
744
745 /* Updates. */
746
747 func = RNA_def_function(srna, "update", "rna_Depsgraph_update");
749 func,
750 "Re-evaluate any modified data-blocks, for example for animation or modifiers. "
751 "This invalidates all references to evaluated data-blocks from this dependency graph.");
753
754 /* Queries for original data-blocks (the ones depsgraph is built for). */
755
756 prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
757 RNA_def_property_struct_type(prop, "Scene");
758 RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_get", nullptr, nullptr, nullptr);
760 RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
761
762 prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
763 RNA_def_property_struct_type(prop, "ViewLayer");
764 RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_get", nullptr, nullptr, nullptr);
767 prop, "View Layer", "Original view layer dependency graph is built for");
768
769 /* Queries for evaluated data-blocks (the ones depsgraph is evaluating). */
770
771 func = RNA_def_function(srna, "id_eval_get", "rna_Depsgraph_id_eval_get");
772 parm = RNA_def_pointer(
773 func, "id", "ID", "", "Original ID to get evaluated complementary part for");
775 parm = RNA_def_pointer(func, "id_eval", "ID", "", "Evaluated ID for the given original one");
776 RNA_def_function_return(func, parm);
777
778 func = RNA_def_function(srna, "id_type_updated", "rna_Depsgraph_id_type_updated");
779 parm = RNA_def_enum(func, "id_type", rna_enum_id_type_items, 0, "ID Type", "");
781 parm = RNA_def_boolean(func,
782 "updated",
783 false,
784 "Updated",
785 "True if any data-block with this type was added, updated or removed");
786 RNA_def_function_return(func, parm);
787
788 prop = RNA_def_property(srna, "scene_eval", PROP_POINTER, PROP_NONE);
789 RNA_def_property_struct_type(prop, "Scene");
790 RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_eval_get", nullptr, nullptr, nullptr);
792 RNA_def_property_ui_text(prop, "Scene", "Scene at its evaluated state");
793
794 prop = RNA_def_property(srna, "view_layer_eval", PROP_POINTER, PROP_NONE);
795 RNA_def_property_struct_type(prop, "ViewLayer");
797 prop, "rna_Depsgraph_view_layer_eval_get", nullptr, nullptr, nullptr);
799 RNA_def_property_ui_text(prop, "View Layer", "View layer at its evaluated state");
800
801 /* Iterators. */
802
803 prop = RNA_def_property(srna, "ids", PROP_COLLECTION, PROP_NONE);
807 "rna_Depsgraph_ids_begin",
808 "rna_Depsgraph_ids_next",
809 "rna_Depsgraph_ids_end",
810 "rna_Depsgraph_ids_get",
811 nullptr,
812 nullptr,
813 nullptr,
814 nullptr);
815 RNA_def_property_ui_text(prop, "IDs", "All evaluated data-blocks");
816
817 prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
818 RNA_def_property_struct_type(prop, "Object");
821 "rna_Depsgraph_objects_begin",
822 "rna_Depsgraph_objects_next",
823 "rna_Depsgraph_objects_end",
824 "rna_Depsgraph_objects_get",
825 nullptr,
826 nullptr,
827 nullptr,
828 nullptr);
829 RNA_def_property_ui_text(prop, "Objects", "Evaluated objects in the dependency graph");
830
831 prop = RNA_def_property(srna, "object_instances", PROP_COLLECTION, PROP_NONE);
832 RNA_def_property_struct_type(prop, "DepsgraphObjectInstance");
835 "rna_Depsgraph_object_instances_begin",
836 "rna_Depsgraph_object_instances_next",
837 "rna_Depsgraph_object_instances_end",
838 "rna_Depsgraph_object_instances_get",
839 nullptr,
840 nullptr,
841 nullptr,
842 nullptr);
844 "Object Instances",
845 "All object instances to display or render "
846 "(Warning: Only use this as an iterator, never as a sequence, "
847 "and do not keep any references to its items)");
848
849 prop = RNA_def_property(srna, "updates", PROP_COLLECTION, PROP_NONE);
850 RNA_def_property_struct_type(prop, "DepsgraphUpdate");
853 "rna_Depsgraph_updates_begin",
854 "rna_Depsgraph_ids_next",
855 "rna_Depsgraph_ids_end",
856 "rna_Depsgraph_updates_get",
857 nullptr,
858 nullptr,
859 nullptr,
860 nullptr);
861 RNA_def_property_ui_text(prop, "Updates", "Updates to data-blocks");
862}
863
870
871} // namespace blender
872
873#endif
General operations, lookup, etc. for blender objects.
#define INT32_MAX
#define FILE_MAX
#define BPy_BEGIN_ALLOW_THREADS
Definition BPY_extern.hh:52
#define BPy_END_ALLOW_THREADS
Definition BPY_extern.hh:56
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
Read Blender memory allocation and freeing.
Definition scene.h:133
void * MEM_new_zeroed(size_t len, const char *str)
Definition mallocn.cc:114
ccl_device_inline void copy_v3_v3(ccl_private float *r, const float3 val)
BMesh Iterators.
void DEG_graph_tag_relations_update(Depsgraph *graph)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
PropertyRNA * RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr)
void DEG_iterator_ids_end(BLI_Iterator *iter)
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
const EnumPropertyItem rna_enum_id_type_items[]
Definition rna_ID.cc:33
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_function_output(FunctionRNA *, PropertyRNA *ret)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void DEG_debug_stats_gnuplot(const Depsgraph *graph, FILE *fp, const char *label, const char *output_filename)
PointerRNA RNA_id_pointer_create(ID *id)
static void rna_def_depsgraph_instance(BlenderRNA *brna)
void DEG_iterator_objects_next(BLI_Iterator *iter)
MINLINE void copy_v2_v2(float r[2], const float a[2])
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
@ FUNC_USE_REPORTS
@ FUNC_USE_MAIN
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_flag_hide_from_ui_workaround(PropertyRNA *prop)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_depsgraph(BlenderRNA *brna)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
void DEG_stats_simple(const Depsgraph *graph, size_t *r_outer, size_t *r_operations, size_t *r_relations)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_COLLECTION
Definition RNA_types.hh:216
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
int BKE_object_visibility(const Object *ob, int dag_eval_mode)
Definition object.cc:2063
void DEG_iterator_ids_next(BLI_Iterator *iter)
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2867
@ DAG_EVAL_VIEWPORT
std::string DEG_debug_graph_to_dot(const Depsgraph &graph, StringRef label)
ViewLayer * DEG_get_evaluated_view_layer(const Depsgraph *graph)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
void DEG_iterator_objects_end(BLI_Iterator *iter)
MINLINE void zero_v3(float r[3])
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg, const char *instance)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
constexpr int MAX_DUPLI_RECUR
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
static void rna_def_depsgraph_update(BlenderRNA *brna)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
@ ID_RECALC_ALL
Definition DNA_ID.h:1190
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_SHADING
Definition DNA_ID.h:1094
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_DYNAMIC
Definition RNA_types.hh:498
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
@ PROP_ANIMATABLE
Definition RNA_types.hh:389
Scene * DEG_get_input_scene(const Depsgraph *graph)
PointerRNA RNA_pointer_create_id_subdata(ID &id, StructRNA *type, void *data)
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
bool DEG_id_type_updated(const Depsgraph *depsgraph, short id_type)
void DEG_iterator_ids_begin(BLI_Iterator *iter, DEGIDIterData *data)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void DEG_iterator_objects_begin(BLI_Iterator *iter, DEGObjectIterData *data)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ PROP_TRANSLATION
Definition RNA_types.hh:318
@ PROP_MATRIX
Definition RNA_types.hh:322
@ PROP_UNSIGNED
Definition RNA_types.hh:306
@ PARM_REQUIRED
Definition RNA_types.hh:631
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
bool DEG_is_evaluating(const Depsgraph *depsgraph)
Definition depsgraph.cc:318
void RNA_def_property_array(PropertyRNA *prop, int length)
MINLINE void zero_v2(float r[2])
const int rna_matrix_dimsize_4x4[]
static void rna_def_depsgraph(BlenderRNA *brna)
@ OB_VISIBLE_PARTICLES
@ OB_VISIBLE_SELF
#define STATS_MAX_SIZE