Blender  V3.3
rna_depsgraph.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stdlib.h>
8 
9 #include "BLI_path_util.h"
10 #include "BLI_utildefines.h"
11 
12 #include "RNA_define.h"
13 #include "RNA_enum_types.h"
14 
15 #include "rna_internal.h"
16 
17 #include "DNA_object_types.h"
18 
19 #include "DEG_depsgraph.h"
20 
21 #define STATS_MAX_SIZE 16384
22 
23 #ifdef RNA_RUNTIME
24 
25 # ifdef WITH_PYTHON
26 # include "BPY_extern.h"
27 # endif
28 
29 # include "BLI_iterator.h"
30 # include "BLI_math.h"
31 
32 # include "RNA_access.h"
33 
34 # include "BKE_duplilist.h"
35 # include "BKE_object.h"
36 # include "BKE_scene.h"
37 
38 # include "DEG_depsgraph_build.h"
39 # include "DEG_depsgraph_debug.h"
40 # include "DEG_depsgraph_query.h"
41 
42 # include "MEM_guardedalloc.h"
43 
44 /* **************** Object Instance **************** */
45 
46 typedef struct RNA_DepsgraphIterator {
47  BLI_Iterator iter;
48 # ifdef WITH_PYTHON
52  void *py_instance;
53 # endif
54 } RNA_DepsgraphIterator;
55 
56 # ifdef WITH_PYTHON
57 void **rna_DepsgraphIterator_instance(PointerRNA *ptr)
58 {
59  RNA_DepsgraphIterator *di = ptr->data;
60  return &di->py_instance;
61 }
62 # endif
63 
64 static PointerRNA rna_DepsgraphObjectInstance_object_get(PointerRNA *ptr)
65 {
66  RNA_DepsgraphIterator *di = ptr->data;
67  return rna_pointer_inherit_refine(ptr, &RNA_Object, di->iter.current);
68 }
69 
70 static int rna_DepsgraphObjectInstance_is_instance_get(PointerRNA *ptr)
71 {
72  RNA_DepsgraphIterator *di = ptr->data;
73  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
74  return (deg_iter->dupli_object_current != NULL);
75 }
76 
77 static PointerRNA rna_DepsgraphObjectInstance_instance_object_get(PointerRNA *ptr)
78 {
79  RNA_DepsgraphIterator *di = ptr->data;
80  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
81  Object *instance_object = NULL;
82  if (deg_iter->dupli_object_current != NULL) {
83  instance_object = deg_iter->dupli_object_current->ob;
84  }
85  return rna_pointer_inherit_refine(ptr, &RNA_Object, instance_object);
86 }
87 
88 static bool rna_DepsgraphObjectInstance_show_self_get(PointerRNA *ptr)
89 {
90  RNA_DepsgraphIterator *di = ptr->data;
91  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
92  int ob_visibility = BKE_object_visibility(di->iter.current, deg_iter->eval_mode);
93  return (ob_visibility & OB_VISIBLE_SELF) != 0;
94 }
95 
96 static bool rna_DepsgraphObjectInstance_show_particles_get(PointerRNA *ptr)
97 {
98  RNA_DepsgraphIterator *di = ptr->data;
99  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
100  int ob_visibility = BKE_object_visibility(di->iter.current, deg_iter->eval_mode);
101  return (ob_visibility & OB_VISIBLE_PARTICLES) != 0;
102 }
103 
104 static PointerRNA rna_DepsgraphObjectInstance_parent_get(PointerRNA *ptr)
105 {
106  RNA_DepsgraphIterator *di = ptr->data;
107  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
108  Object *dupli_parent = NULL;
109  if (deg_iter->dupli_object_current != NULL) {
110  dupli_parent = deg_iter->dupli_parent;
111  }
112  return rna_pointer_inherit_refine(ptr, &RNA_Object, dupli_parent);
113 }
114 
115 static PointerRNA rna_DepsgraphObjectInstance_particle_system_get(PointerRNA *ptr)
116 {
117  RNA_DepsgraphIterator *di = ptr->data;
118  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
119  struct ParticleSystem *particle_system = NULL;
120  if (deg_iter->dupli_object_current != NULL) {
121  particle_system = deg_iter->dupli_object_current->particle_system;
122  }
123  return rna_pointer_inherit_refine(ptr, &RNA_ParticleSystem, particle_system);
124 }
125 
126 static void rna_DepsgraphObjectInstance_persistent_id_get(PointerRNA *ptr, int *persistent_id)
127 {
128  RNA_DepsgraphIterator *di = ptr->data;
129  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
130  if (deg_iter->dupli_object_current != NULL) {
131  memcpy(persistent_id,
133  sizeof(deg_iter->dupli_object_current->persistent_id));
134  }
135  else {
136  memset(persistent_id, 0, sizeof(deg_iter->dupli_object_current->persistent_id));
137  }
138 }
139 
140 static unsigned int rna_DepsgraphObjectInstance_random_id_get(PointerRNA *ptr)
141 {
142  RNA_DepsgraphIterator *di = ptr->data;
143  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
144  if (deg_iter->dupli_object_current != NULL) {
145  return deg_iter->dupli_object_current->random_id;
146  }
147  else {
148  return 0;
149  }
150 }
151 
152 static void rna_DepsgraphObjectInstance_matrix_world_get(PointerRNA *ptr, float *mat)
153 {
154  RNA_DepsgraphIterator *di = ptr->data;
155  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
156  if (deg_iter->dupli_object_current != NULL) {
157  copy_m4_m4((float(*)[4])mat, deg_iter->dupli_object_current->mat);
158  }
159  else {
160  /* We can return actual object's matrix here, no reason to return identity matrix
161  * when this is not actually an instance... */
162  Object *ob = (Object *)di->iter.current;
163  copy_m4_m4((float(*)[4])mat, ob->obmat);
164  }
165 }
166 
167 static void rna_DepsgraphObjectInstance_orco_get(PointerRNA *ptr, float *orco)
168 {
169  RNA_DepsgraphIterator *di = ptr->data;
170  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
171  if (deg_iter->dupli_object_current != NULL) {
172  copy_v3_v3(orco, deg_iter->dupli_object_current->orco);
173  }
174  else {
175  zero_v3(orco);
176  }
177 }
178 
179 static void rna_DepsgraphObjectInstance_uv_get(PointerRNA *ptr, float *uv)
180 {
181  RNA_DepsgraphIterator *di = ptr->data;
182  DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data;
183  if (deg_iter->dupli_object_current != NULL) {
184  copy_v2_v2(uv, deg_iter->dupli_object_current->uv);
185  }
186  else {
187  zero_v2(uv);
188  }
189 }
190 
191 /* ******************** Sorted ***************** */
192 
193 static int rna_Depsgraph_mode_get(PointerRNA *ptr)
194 {
196  return DEG_get_mode(depsgraph);
197 }
198 
199 /* ******************** Updates ***************** */
200 
201 static PointerRNA rna_DepsgraphUpdate_id_get(PointerRNA *ptr)
202 {
203  return rna_pointer_inherit_refine(ptr, &RNA_ID, ptr->data);
204 }
205 
206 static bool rna_DepsgraphUpdate_is_updated_transform_get(PointerRNA *ptr)
207 {
208  ID *id = ptr->data;
209  return ((id->recalc & ID_RECALC_TRANSFORM) != 0);
210 }
211 
212 static bool rna_DepsgraphUpdate_is_updated_shading_get(PointerRNA *ptr)
213 {
214  /* Assume any animated parameters can affect shading, we don't have fine
215  * grained enough updates to distinguish this. */
216  ID *id = ptr->data;
217  return ((id->recalc & (ID_RECALC_SHADING | ID_RECALC_ANIMATION)) != 0);
218 }
219 
220 static bool rna_DepsgraphUpdate_is_updated_geometry_get(PointerRNA *ptr)
221 {
222  ID *id = ptr->data;
223  if (id->recalc & ID_RECALC_GEOMETRY) {
224  return true;
225  }
226  if (GS(id->name) != ID_OB) {
227  return false;
228  }
229  Object *object = (Object *)id;
230  ID *data = object->data;
231  if (data == NULL) {
232  return false;
233  }
234  return ((data->recalc & ID_RECALC_ALL) != 0);
235 }
236 
237 /* **************** Depsgraph **************** */
238 
239 static void rna_Depsgraph_debug_relations_graphviz(Depsgraph *depsgraph, const char *filename)
240 {
241  FILE *f = fopen(filename, "w");
242  if (f == NULL) {
243  return;
244  }
245  DEG_debug_relations_graphviz(depsgraph, f, "Depsgraph");
246  fclose(f);
247 }
248 
249 static void rna_Depsgraph_debug_stats_gnuplot(Depsgraph *depsgraph,
250  const char *filename,
251  const char *output_filename)
252 {
253  FILE *f = fopen(filename, "w");
254  if (f == NULL) {
255  return;
256  }
257  DEG_debug_stats_gnuplot(depsgraph, f, "Timing Statistics", output_filename);
258  fclose(f);
259 }
260 
261 static void rna_Depsgraph_debug_tag_update(Depsgraph *depsgraph)
262 {
264 }
265 
266 static void rna_Depsgraph_debug_stats(Depsgraph *depsgraph, char *result)
267 {
268  size_t outer, ops, rels;
269  DEG_stats_simple(depsgraph, &outer, &ops, &rels);
272  "Approx %zu Operations, %zu Relations, %zu Outer Nodes",
273  ops,
274  rels,
275  outer);
276 }
277 
278 static void rna_Depsgraph_update(Depsgraph *depsgraph, Main *bmain, ReportList *reports)
279 {
281  BKE_report(reports, RPT_ERROR, "Dependency graph update requested during evaluation");
282  return;
283  }
284 
285 # ifdef WITH_PYTHON
286  /* Allow drivers to be evaluated */
288 # endif
289 
291 
292 # ifdef WITH_PYTHON
294 # endif
295 }
296 
297 /* Iteration over objects, simple version */
298 
299 static void rna_Depsgraph_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
300 {
301  iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
302  DEGObjectIterData *data = MEM_callocN(sizeof(DEGObjectIterData), __func__);
303 
304  data->graph = (Depsgraph *)ptr->data;
307 
308  ((BLI_Iterator *)iter->internal.custom)->valid = true;
310  iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
311 }
312 
313 static void rna_Depsgraph_objects_next(CollectionPropertyIterator *iter)
314 {
316  iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
317 }
318 
319 static void rna_Depsgraph_objects_end(CollectionPropertyIterator *iter)
320 {
322  MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
323  MEM_freeN(iter->internal.custom);
324 }
325 
326 static PointerRNA rna_Depsgraph_objects_get(CollectionPropertyIterator *iter)
327 {
328  Object *ob = ((BLI_Iterator *)iter->internal.custom)->current;
329  return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ob);
330 }
331 
332 /* Iteration over objects, extended version
333  *
334  * Contains extra information about duplicator and persistent ID.
335  */
336 
337 /* XXX Ugly python seems to query next item of an iterator before using current one (see T57558).
338  * This forces us to use that nasty ping-pong game between two sets of iterator data,
339  * so that previous one remains valid memory for python to access to. Yuck.
340  */
341 typedef struct RNA_Depsgraph_Instances_Iterator {
342  RNA_DepsgraphIterator iterators[2];
343  DEGObjectIterData deg_data[2];
344  DupliObject dupli_object_current[2];
345  int counter;
346 } RNA_Depsgraph_Instances_Iterator;
347 
348 static void rna_Depsgraph_object_instances_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
349 {
350  RNA_Depsgraph_Instances_Iterator *di_it = iter->internal.custom = MEM_callocN(sizeof(*di_it),
351  __func__);
352 
353  DEGObjectIterData *data = &di_it->deg_data[0];
354  data->graph = (Depsgraph *)ptr->data;
357 
358  di_it->iterators[0].iter.valid = true;
359  DEG_iterator_objects_begin(&di_it->iterators[0].iter, data);
360  iter->valid = di_it->iterators[0].iter.valid;
361 }
362 
363 static void rna_Depsgraph_object_instances_next(CollectionPropertyIterator *iter)
364 {
365  RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *)
366  iter->internal.custom;
367 
368  /* We need to copy current iterator status to next one being worked on. */
369  di_it->iterators[(di_it->counter + 1) % 2].iter = di_it->iterators[di_it->counter % 2].iter;
370  di_it->deg_data[(di_it->counter + 1) % 2] = di_it->deg_data[di_it->counter % 2];
371  di_it->counter++;
372 
373  di_it->iterators[di_it->counter % 2].iter.data = &di_it->deg_data[di_it->counter % 2];
374  DEG_iterator_objects_next(&di_it->iterators[di_it->counter % 2].iter);
375  /* Dupli_object_current is also temp memory generated during the iterations,
376  * it may be freed when last item has been iterated,
377  * so we have same issue as with the iterator itself:
378  * we need to keep a local copy, which memory remains valid a bit longer,
379  * for Python accesses to work. */
380  if (di_it->deg_data[di_it->counter % 2].dupli_object_current != NULL) {
381  di_it->dupli_object_current[di_it->counter % 2] =
382  *di_it->deg_data[di_it->counter % 2].dupli_object_current;
383  di_it->deg_data[di_it->counter % 2].dupli_object_current =
384  &di_it->dupli_object_current[di_it->counter % 2];
385  }
386  iter->valid = di_it->iterators[di_it->counter % 2].iter.valid;
387 }
388 
389 static void rna_Depsgraph_object_instances_end(CollectionPropertyIterator *iter)
390 {
391  RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *)
392  iter->internal.custom;
393  for (int i = 0; i < ARRAY_SIZE(di_it->iterators); i++) {
394  RNA_DepsgraphIterator *di = &di_it->iterators[i];
395  DEG_iterator_objects_end(&di->iter);
396 
397 # ifdef WITH_PYTHON
398  if (di->py_instance) {
399  BPY_DECREF_RNA_INVALIDATE(di->py_instance);
400  }
401 # endif
402  }
403 
404  MEM_freeN(di_it);
405 }
406 
407 static PointerRNA rna_Depsgraph_object_instances_get(CollectionPropertyIterator *iter)
408 {
409  RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *)
410  iter->internal.custom;
411  RNA_DepsgraphIterator *di = &di_it->iterators[di_it->counter % 2];
412  return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphObjectInstance, di);
413 }
414 
415 /* Iteration over evaluated IDs */
416 
417 static void rna_Depsgraph_ids_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
418 {
419  iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
420  DEGIDIterData *data = MEM_callocN(sizeof(DEGIDIterData), __func__);
421 
422  data->graph = (Depsgraph *)ptr->data;
423 
424  ((BLI_Iterator *)iter->internal.custom)->valid = true;
426  iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
427 }
428 
429 static void rna_Depsgraph_ids_next(CollectionPropertyIterator *iter)
430 {
432  iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
433 }
434 
435 static void rna_Depsgraph_ids_end(CollectionPropertyIterator *iter)
436 {
438  MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
439  MEM_freeN(iter->internal.custom);
440 }
441 
442 static PointerRNA rna_Depsgraph_ids_get(CollectionPropertyIterator *iter)
443 {
444  ID *id = ((BLI_Iterator *)iter->internal.custom)->current;
445  return rna_pointer_inherit_refine(&iter->parent, &RNA_ID, id);
446 }
447 
448 static void rna_Depsgraph_updates_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
449 {
450  iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
451  DEGIDIterData *data = MEM_callocN(sizeof(DEGIDIterData), __func__);
452 
453  data->graph = (Depsgraph *)ptr->data;
454  data->only_updated = true;
455 
456  ((BLI_Iterator *)iter->internal.custom)->valid = true;
458  iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
459 }
460 
461 static PointerRNA rna_Depsgraph_updates_get(CollectionPropertyIterator *iter)
462 {
463  ID *id = ((BLI_Iterator *)iter->internal.custom)->current;
464  return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphUpdate, id);
465 }
466 
467 static ID *rna_Depsgraph_id_eval_get(Depsgraph *depsgraph, ID *id_orig)
468 {
469  return DEG_get_evaluated_id(depsgraph, id_orig);
470 }
471 
472 static bool rna_Depsgraph_id_type_updated(Depsgraph *depsgraph, int id_type)
473 {
474  return DEG_id_type_updated(depsgraph, id_type);
475 }
476 
477 static PointerRNA rna_Depsgraph_scene_get(PointerRNA *ptr)
478 {
481  PointerRNA newptr;
482  RNA_pointer_create(&scene->id, &RNA_Scene, scene, &newptr);
483  return newptr;
484 }
485 
486 static PointerRNA rna_Depsgraph_view_layer_get(PointerRNA *ptr)
487 {
491  PointerRNA newptr;
492  RNA_pointer_create(&scene->id, &RNA_ViewLayer, view_layer, &newptr);
493  return newptr;
494 }
495 
496 static PointerRNA rna_Depsgraph_scene_eval_get(PointerRNA *ptr)
497 {
499  Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
500  PointerRNA newptr;
501  RNA_pointer_create(&scene_eval->id, &RNA_Scene, scene_eval, &newptr);
502  return newptr;
503 }
504 
505 static PointerRNA rna_Depsgraph_view_layer_eval_get(PointerRNA *ptr)
506 {
508  Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
510  PointerRNA newptr;
511  RNA_pointer_create(&scene_eval->id, &RNA_ViewLayer, view_layer_eval, &newptr);
512  return newptr;
513 }
514 
515 #else
516 
518 {
519  StructRNA *srna;
520  PropertyRNA *prop;
521 
522  srna = RNA_def_struct(brna, "DepsgraphObjectInstance", NULL);
524  "Dependency Graph Object Instance",
525  "Extended information about dependency graph object iterator "
526  "(Warning: All data here is 'evaluated' one, not original .blend IDs)");
527 
528 # ifdef WITH_PYTHON
529  RNA_def_struct_register_funcs(srna, NULL, NULL, "rna_DepsgraphIterator_instance");
530 # endif
531 
532  prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
533  RNA_def_property_struct_type(prop, "Object");
534  RNA_def_property_ui_text(prop, "Object", "Evaluated object the iterator points to");
536  RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_object_get", NULL, NULL, NULL);
537 
538  prop = RNA_def_property(srna, "show_self", PROP_BOOLEAN, PROP_NONE);
541  prop, "Show Self", "The object geometry itself should be visible in the render");
542  RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_show_self_get", NULL);
543 
544  prop = RNA_def_property(srna, "show_particles", PROP_BOOLEAN, PROP_NONE);
547  prop, "Show Particles", "Particles part of the object should be visible in the render");
548  RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_show_particles_get", NULL);
549 
550  prop = RNA_def_property(srna, "is_instance", PROP_BOOLEAN, PROP_NONE);
553  prop, "Is Instance", "Denotes if the object is generated by another object");
554  RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_is_instance_get", NULL);
555 
556  prop = RNA_def_property(srna, "instance_object", PROP_POINTER, PROP_NONE);
557  RNA_def_property_struct_type(prop, "Object");
559  prop, "Instance Object", "Evaluated object which is being instanced by this iterator");
562  prop, "rna_DepsgraphObjectInstance_instance_object_get", NULL, NULL, NULL);
563 
564  prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
565  RNA_def_property_struct_type(prop, "Object");
567  prop, "Parent", "If the object is an instance, the parent object that generated it");
569  RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_parent_get", NULL, NULL, NULL);
570 
571  prop = RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE);
572  RNA_def_property_struct_type(prop, "ParticleSystem");
575  prop, "Particle System", "Evaluated particle system that this object was instanced from");
577  prop, "rna_DepsgraphObjectInstance_particle_system_get", NULL, NULL, NULL);
578 
579  prop = RNA_def_property(srna, "persistent_id", PROP_INT, PROP_NONE);
581  prop,
582  "Persistent ID",
583  "Persistent identifier for inter-frame matching of objects with motion blur");
586  RNA_def_property_int_funcs(prop, "rna_DepsgraphObjectInstance_persistent_id_get", NULL, NULL);
587 
588  prop = RNA_def_property(srna, "random_id", PROP_INT, PROP_UNSIGNED);
591  prop, "Instance Random ID", "Random id for this instance, typically for randomized shading");
592  RNA_def_property_int_funcs(prop, "rna_DepsgraphObjectInstance_random_id_get", NULL, NULL);
593 
594  prop = RNA_def_property(srna, "matrix_world", PROP_FLOAT, PROP_MATRIX);
597  RNA_def_property_ui_text(prop, "Generated Matrix", "Generated transform matrix in world space");
598  RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_matrix_world_get", NULL, NULL);
599 
600  prop = RNA_def_property(srna, "orco", PROP_FLOAT, PROP_TRANSLATION);
602  RNA_def_property_array(prop, 3);
604  prop, "Generated Coordinates", "Generated coordinates in parent object space");
605  RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_orco_get", NULL, NULL);
606 
607  prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
608  RNA_def_property_ui_text(prop, "UV Coordinates", "UV coordinates in parent object space");
609  RNA_def_property_array(prop, 2);
611  RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_uv_get", NULL, NULL);
612 }
613 
615 {
616  StructRNA *srna;
617  PropertyRNA *prop;
618 
619  srna = RNA_def_struct(brna, "DepsgraphUpdate", NULL);
620  RNA_def_struct_ui_text(srna, "Dependency Graph Update", "Information about ID that was updated");
621 
622  prop = RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE);
623  RNA_def_property_struct_type(prop, "ID");
624  RNA_def_property_ui_text(prop, "ID", "Updated data-block");
626  RNA_def_property_pointer_funcs(prop, "rna_DepsgraphUpdate_id_get", NULL, NULL, NULL);
627 
628  /* Use term 'is_updated' instead of 'is_dirty' here because this is a signal
629  * that users of the depsgraph may want to update their data (render engines for eg). */
630 
631  prop = RNA_def_property(srna, "is_updated_transform", PROP_BOOLEAN, PROP_NONE);
633  RNA_def_property_ui_text(prop, "Transform", "Object transformation is updated");
634  RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_updated_transform_get", NULL);
635 
636  prop = RNA_def_property(srna, "is_updated_geometry", PROP_BOOLEAN, PROP_NONE);
638  RNA_def_property_ui_text(prop, "Geometry", "Object geometry is updated");
639  RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_updated_geometry_get", NULL);
640 
641  prop = RNA_def_property(srna, "is_updated_shading", PROP_BOOLEAN, PROP_NONE);
643  RNA_def_property_ui_text(prop, "Shading", "Object shading is updated");
644  RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_updated_shading_get", NULL);
645 }
646 
647 static void rna_def_depsgraph(BlenderRNA *brna)
648 {
649  StructRNA *srna;
650  FunctionRNA *func;
651  PropertyRNA *parm;
652  PropertyRNA *prop;
653 
654  static EnumPropertyItem enum_depsgraph_mode_items[] = {
655  {DAG_EVAL_VIEWPORT, "VIEWPORT", 0, "Viewport", "Viewport non-rendered mode"},
656  {DAG_EVAL_RENDER, "RENDER", 0, "Render", "Render"},
657  {0, NULL, 0, NULL, NULL},
658  };
659 
660  srna = RNA_def_struct(brna, "Depsgraph", NULL);
661  RNA_def_struct_ui_text(srna, "Dependency Graph", "");
662 
663  prop = RNA_def_enum(srna, "mode", enum_depsgraph_mode_items, 0, "Mode", "Evaluation mode");
665  RNA_def_property_enum_funcs(prop, "rna_Depsgraph_mode_get", NULL, NULL);
666 
667  /* Debug helpers. */
668 
669  func = RNA_def_function(
670  srna, "debug_relations_graphviz", "rna_Depsgraph_debug_relations_graphviz");
672  func, "filename", NULL, FILE_MAX, "File Name", "Output path for the graphviz debug file");
674 
675  func = RNA_def_function(srna, "debug_stats_gnuplot", "rna_Depsgraph_debug_stats_gnuplot");
677  func, "filename", NULL, FILE_MAX, "File Name", "Output path for the gnuplot debug file");
679  parm = RNA_def_string_file_path(func,
680  "output_filename",
681  NULL,
682  FILE_MAX,
683  "Output File Name",
684  "File name where gnuplot script will save the result");
686 
687  func = RNA_def_function(srna, "debug_tag_update", "rna_Depsgraph_debug_tag_update");
688 
689  func = RNA_def_function(srna, "debug_stats", "rna_Depsgraph_debug_stats");
690  RNA_def_function_ui_description(func, "Report the number of elements in the Dependency Graph");
691  /* weak!, no way to return dynamic string type */
692  parm = RNA_def_string(func, "result", NULL, STATS_MAX_SIZE, "result", "");
693  RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */
694  RNA_def_function_output(func, parm);
695 
696  /* Updates. */
697 
698  func = RNA_def_function(srna, "update", "rna_Depsgraph_update");
700  func,
701  "Re-evaluate any modified data-blocks, for example for animation or modifiers. "
702  "This invalidates all references to evaluated data-blocks from this dependency graph.");
704 
705  /* Queries for original data-blocks (the ones depsgraph is built for). */
706 
707  prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
708  RNA_def_property_struct_type(prop, "Scene");
709  RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_get", NULL, NULL, NULL);
711  RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
712 
713  prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
714  RNA_def_property_struct_type(prop, "ViewLayer");
715  RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_get", NULL, NULL, NULL);
718  prop, "View Layer", "Original view layer dependency graph is built for");
719 
720  /* Queries for evaluated data-blocks (the ones depsgraph is evaluating). */
721 
722  func = RNA_def_function(srna, "id_eval_get", "rna_Depsgraph_id_eval_get");
723  parm = RNA_def_pointer(
724  func, "id", "ID", "", "Original ID to get evaluated complementary part for");
726  parm = RNA_def_pointer(func, "id_eval", "ID", "", "Evaluated ID for the given original one");
727  RNA_def_function_return(func, parm);
728 
729  func = RNA_def_function(srna, "id_type_updated", "rna_Depsgraph_id_type_updated");
730  parm = RNA_def_enum(func, "id_type", rna_enum_id_type_items, 0, "ID Type", "");
732  parm = RNA_def_boolean(func,
733  "updated",
734  false,
735  "Updated",
736  "True if any datablock with this type was added, updated or removed");
737  RNA_def_function_return(func, parm);
738 
739  prop = RNA_def_property(srna, "scene_eval", PROP_POINTER, PROP_NONE);
740  RNA_def_property_struct_type(prop, "Scene");
741  RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_eval_get", NULL, NULL, NULL);
743  RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
744 
745  prop = RNA_def_property(srna, "view_layer_eval", PROP_POINTER, PROP_NONE);
746  RNA_def_property_struct_type(prop, "ViewLayer");
747  RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_eval_get", NULL, NULL, NULL);
750  prop, "View Layer", "Original view layer dependency graph is built for");
751 
752  /* Iterators. */
753 
754  prop = RNA_def_property(srna, "ids", PROP_COLLECTION, PROP_NONE);
755  RNA_def_property_struct_type(prop, "ID");
757  "rna_Depsgraph_ids_begin",
758  "rna_Depsgraph_ids_next",
759  "rna_Depsgraph_ids_end",
760  "rna_Depsgraph_ids_get",
761  NULL,
762  NULL,
763  NULL,
764  NULL);
765  RNA_def_property_ui_text(prop, "IDs", "All evaluated data-blocks");
766 
767  prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
768  RNA_def_property_struct_type(prop, "Object");
770  "rna_Depsgraph_objects_begin",
771  "rna_Depsgraph_objects_next",
772  "rna_Depsgraph_objects_end",
773  "rna_Depsgraph_objects_get",
774  NULL,
775  NULL,
776  NULL,
777  NULL);
778  RNA_def_property_ui_text(prop, "Objects", "Evaluated objects in the dependency graph");
779 
780  prop = RNA_def_property(srna, "object_instances", PROP_COLLECTION, PROP_NONE);
781  RNA_def_property_struct_type(prop, "DepsgraphObjectInstance");
783  "rna_Depsgraph_object_instances_begin",
784  "rna_Depsgraph_object_instances_next",
785  "rna_Depsgraph_object_instances_end",
786  "rna_Depsgraph_object_instances_get",
787  NULL,
788  NULL,
789  NULL,
790  NULL);
792  "Object Instances",
793  "All object instances to display or render "
794  "(Warning: Only use this as an iterator, never as a sequence, "
795  "and do not keep any references to its items)");
796 
797  prop = RNA_def_property(srna, "updates", PROP_COLLECTION, PROP_NONE);
798  RNA_def_property_struct_type(prop, "DepsgraphUpdate");
800  "rna_Depsgraph_updates_begin",
801  "rna_Depsgraph_ids_next",
802  "rna_Depsgraph_ids_end",
803  "rna_Depsgraph_updates_get",
804  NULL,
805  NULL,
806  NULL,
807  NULL);
808  RNA_def_property_ui_text(prop, "Updates", "Updates to data-blocks");
809 }
810 
812 {
815  rna_def_depsgraph(brna);
816 }
817 
818 #endif
General operations, lookup, etc. for blender objects.
@ OB_VISIBLE_SELF
Definition: BKE_object.h:150
@ OB_VISIBLE_PARTICLES
Definition: BKE_object.h:151
int BKE_object_visibility(const struct Object *ob, int dag_eval_mode)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
void BKE_scene_graph_update_tagged(struct Depsgraph *depsgraph, struct Main *bmain)
Definition: scene.cc:2648
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:77
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
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define ARRAY_SIZE(arr)
#define BPy_BEGIN_ALLOW_THREADS
Definition: BPY_extern.h:54
void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr)
#define BPy_END_ALLOW_THREADS
Definition: BPY_extern.h:58
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
@ DAG_EVAL_RENDER
Definition: DEG_depsgraph.h:46
@ DAG_EVAL_VIEWPORT
Definition: DEG_depsgraph.h:45
bool DEG_is_evaluating(const struct Depsgraph *depsgraph)
Definition: depsgraph.cc:306
void DEG_graph_tag_relations_update(struct Depsgraph *graph)
void DEG_debug_relations_graphviz(const struct Depsgraph *graph, FILE *fp, const char *label)
void DEG_stats_simple(const struct Depsgraph *graph, size_t *r_outer, size_t *r_operations, size_t *r_relations)
void DEG_debug_stats_gnuplot(const struct Depsgraph *graph, FILE *fp, const char *label, const char *output_filename)
void DEG_iterator_objects_next(struct BLI_Iterator *iter)
struct Scene * DEG_get_input_scene(const Depsgraph *graph)
void DEG_iterator_ids_begin(struct BLI_Iterator *iter, DEGIDIterData *data)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
void DEG_iterator_ids_end(struct BLI_Iterator *iter)
struct ID * DEG_get_evaluated_id(const struct Depsgraph *depsgraph, struct ID *id)
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
@ DEG_ITER_OBJECT_FLAG_VISIBLE
@ DEG_ITER_OBJECT_FLAG_DUPLI
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
struct ViewLayer * DEG_get_evaluated_view_layer(const struct Depsgraph *graph)
void DEG_iterator_objects_end(struct BLI_Iterator *iter)
void DEG_iterator_objects_begin(struct BLI_Iterator *iter, DEGObjectIterData *data)
void DEG_iterator_ids_next(struct BLI_Iterator *iter)
struct ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
bool DEG_id_type_updated(const struct Depsgraph *depsgraph, short id_type)
struct Scene * DEG_get_evaluated_scene(const struct Depsgraph *graph)
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:771
@ ID_RECALC_SHADING
Definition: DNA_ID.h:811
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:794
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:791
@ ID_RECALC_ALL
Definition: DNA_ID.h:891
@ ID_OB
Definition: DNA_ID_enums.h:47
Object is a sort of wrapper for general info.
#define MAX_DUPLI_RECUR
Read Guarded memory(de)allocation.
@ PARM_REQUIRED
Definition: RNA_types.h:352
@ FUNC_USE_REPORTS
Definition: RNA_types.h:663
@ FUNC_USE_MAIN
Definition: RNA_types.h:661
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_BOOLEAN
Definition: RNA_types.h:59
@ PROP_INT
Definition: RNA_types.h:60
@ PROP_POINTER
Definition: RNA_types.h:64
@ PROP_COLLECTION
Definition: RNA_types.h:65
@ PROP_THICK_WRAP
Definition: RNA_types.h:285
@ PROP_ANIMATABLE
Definition: RNA_types.h:202
@ PROP_EDITABLE
Definition: RNA_types.h:189
@ PROP_MATRIX
Definition: RNA_types.h:158
@ PROP_NONE
Definition: RNA_types.h:126
@ PROP_TRANSLATION
Definition: RNA_types.h:154
@ PROP_UNSIGNED
Definition: RNA_types.h:142
return(oflags[bm->toolflag_index].f &oflag) !=0
const char * output_filename
Scene scene
const Depsgraph * depsgraph
#define GS(x)
Definition: iris.c:225
ccl_gpu_kernel_postfix ccl_global int * counter
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
const EnumPropertyItem rna_enum_id_type_items[]
Definition: rna_ID.c:33
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:186
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4170
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4312
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3126
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1645
PropertyRNA * RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3711
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4273
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)
Definition: rna_define.c:3420
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1237
void RNA_def_function_output(FunctionRNA *UNUSED(func), PropertyRNA *ret)
Definition: rna_define.c:4337
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
Definition: rna_define.c:2944
void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg, const char *instance)
Definition: rna_define.c:1172
void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
Definition: rna_define.c:1598
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1539
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1772
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4347
const int rna_matrix_dimsize_4x4[]
Definition: rna_define.c:1595
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
Definition: rna_define.c:3224
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4342
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1495
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
Definition: rna_define.c:3385
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1028
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3028
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3687
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3783
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1518
void RNA_def_depsgraph(BlenderRNA *brna)
#define STATS_MAX_SIZE
Definition: rna_depsgraph.c:21
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::@1147 internal
eEvaluationMode eval_mode
struct Object * dupli_parent
struct DupliObject * dupli_object_current
float uv[2]
Definition: BKE_duplilist.h:38
float mat[4][4]
Definition: BKE_duplilist.h:37
struct ParticleSystem * particle_system
Definition: BKE_duplilist.h:48
int persistent_id[8]
Definition: BKE_duplilist.h:45
float orco[3]
Definition: BKE_duplilist.h:38
struct Object * ob
Definition: BKE_duplilist.h:34
unsigned int random_id
Definition: BKE_duplilist.h:51
Definition: DNA_ID.h:368
int recalc
Definition: DNA_ID.h:390
char name[66]
Definition: DNA_ID.h:378
Definition: BKE_main.h:121
float obmat[4][4]
void * data
Definition: RNA_types.h:38
PointerRNA * ptr
Definition: wm_files.c:3480