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