Fix inconsistent/broken Cycles object visibility for instances.
[blender.git] / source / blender / makesrna / intern / rna_depsgraph.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation (2014).
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/makesrna/intern/rna_depsgraph.c
24  *  \ingroup RNA
25  */
26
27 #include <stdlib.h>
28
29 #include "BLI_utildefines.h"
30 #include "BLI_path_util.h"
31
32 #include "RNA_define.h"
33 #include "RNA_enum_types.h"
34
35 #include "rna_internal.h"
36
37 #include "DNA_object_types.h"
38
39 #include "DEG_depsgraph.h"
40
41 #define STATS_MAX_SIZE 16384
42
43 #ifdef RNA_RUNTIME
44
45 #include "BLI_iterator.h"
46 #include "BLI_math.h"
47
48 #include "BKE_anim.h"
49 #include "BKE_object.h"
50
51 #include "DEG_depsgraph_build.h"
52 #include "DEG_depsgraph_debug.h"
53 #include "DEG_depsgraph_query.h"
54
55 #include "MEM_guardedalloc.h"
56
57 /* **************** Object Instance **************** */
58
59 static PointerRNA rna_DepsgraphObjectInstance_object_get(PointerRNA *ptr)
60 {
61         BLI_Iterator *iterator = ptr->data;
62         return rna_pointer_inherit_refine(ptr, &RNA_Object, iterator->current);
63 }
64
65 static int rna_DepsgraphObjectInstance_is_instance_get(PointerRNA *ptr)
66 {
67         BLI_Iterator *iterator = ptr->data;
68         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
69         return (deg_iter->dupli_object_current != NULL);
70 }
71
72 static PointerRNA rna_DepsgraphObjectInstance_instance_object_get(PointerRNA *ptr)
73 {
74         BLI_Iterator *iterator = ptr->data;
75         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
76         Object *instance_object = NULL;
77         if (deg_iter->dupli_object_current != NULL) {
78                 instance_object = deg_iter->dupli_object_current->ob;
79         }
80         return rna_pointer_inherit_refine(ptr, &RNA_Object, instance_object);
81 }
82
83 static bool rna_DepsgraphObjectInstance_show_self_get(PointerRNA *ptr)
84 {
85         BLI_Iterator *iterator = ptr->data;
86         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
87         int ob_visibility = BKE_object_visibility(iterator->current, deg_iter->eval_mode);
88         return (ob_visibility & OB_VISIBLE_SELF) != 0;
89 }
90
91 static bool rna_DepsgraphObjectInstance_show_particles_get(PointerRNA *ptr)
92 {
93         BLI_Iterator *iterator = ptr->data;
94         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
95         int ob_visibility = BKE_object_visibility(iterator->current, deg_iter->eval_mode);
96         return (ob_visibility & OB_VISIBLE_PARTICLES) != 0;
97 }
98
99 static PointerRNA rna_DepsgraphObjectInstance_parent_get(PointerRNA *ptr)
100 {
101         BLI_Iterator *iterator = ptr->data;
102         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
103         Object *dupli_parent = NULL;
104         if (deg_iter->dupli_object_current != NULL) {
105                 dupli_parent = deg_iter->dupli_parent;
106         }
107         return rna_pointer_inherit_refine(ptr, &RNA_Object, dupli_parent);
108 }
109
110 static PointerRNA rna_DepsgraphObjectInstance_particle_system_get(PointerRNA *ptr)
111 {
112         BLI_Iterator *iterator = ptr->data;
113         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
114         struct ParticleSystem *particle_system = NULL;
115         if (deg_iter->dupli_object_current != NULL) {
116                 particle_system = deg_iter->dupli_object_current->particle_system;
117         }
118         return rna_pointer_inherit_refine(ptr, &RNA_ParticleSystem, particle_system);
119 }
120
121 static void rna_DepsgraphObjectInstance_persistent_id_get(PointerRNA *ptr, int *persistent_id)
122 {
123         BLI_Iterator *iterator = ptr->data;
124         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
125         if (deg_iter->dupli_object_current != NULL) {
126                 memcpy(persistent_id, deg_iter->dupli_object_current->persistent_id,
127                        sizeof(deg_iter->dupli_object_current->persistent_id));
128         }
129         else {
130                 memset(persistent_id, 0, sizeof(deg_iter->dupli_object_current->persistent_id));
131         }
132 }
133
134 static unsigned int rna_DepsgraphObjectInstance_random_id_get(PointerRNA *ptr)
135 {
136         BLI_Iterator *iterator = ptr->data;
137         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
138         if (deg_iter->dupli_object_current != NULL) {
139                 return deg_iter->dupli_object_current->random_id;
140         }
141         else {
142                 return 0;
143         }
144 }
145
146 static void rna_DepsgraphObjectInstance_matrix_world_get(PointerRNA *ptr, float *mat)
147 {
148         BLI_Iterator *iterator = ptr->data;
149         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
150         if (deg_iter->dupli_object_current != NULL) {
151                 copy_m4_m4((float(*)[4])mat, deg_iter->dupli_object_current->mat);
152         }
153         else {
154                 unit_m4((float(*)[4])mat);
155         }
156 }
157
158 static void rna_DepsgraphObjectInstance_orco_get(PointerRNA *ptr, float *orco)
159 {
160         BLI_Iterator *iterator = ptr->data;
161         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
162         if (deg_iter->dupli_object_current != NULL) {
163                 copy_v3_v3(orco, deg_iter->dupli_object_current->orco);
164         }
165         else {
166                 zero_v3(orco);
167         }
168 }
169
170 static void rna_DepsgraphObjectInstance_uv_get(PointerRNA *ptr, float *uv)
171 {
172         BLI_Iterator *iterator = ptr->data;
173         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
174         if (deg_iter->dupli_object_current != NULL) {
175                 copy_v2_v2(uv, deg_iter->dupli_object_current->uv);
176         }
177         else {
178                 zero_v2(uv);
179         }
180 }
181
182 /* ******************** Sorted  ***************** */
183
184 static int rna_Depsgraph_mode_get(PointerRNA *ptr)
185 {
186         Depsgraph *depsgraph = ptr->data;
187         return DEG_get_mode(depsgraph);
188 }
189
190 /* ******************** Updates ***************** */
191
192 static PointerRNA rna_DepsgraphUpdate_id_get(PointerRNA *ptr)
193 {
194         return rna_pointer_inherit_refine(ptr, &RNA_ID, ptr->data);
195 }
196
197 static bool rna_DepsgraphUpdate_is_updated_transform_get(PointerRNA *ptr)
198 {
199         ID *id = ptr->data;
200         return ((id->recalc & ID_RECALC_TRANSFORM) != 0);
201 }
202
203 static bool rna_DepsgraphUpdate_is_updated_geometry_get(PointerRNA *ptr)
204 {
205         ID *id = ptr->data;
206         if (id->recalc & ID_RECALC_GEOMETRY) {
207                 return true;
208         }
209         if (GS(id->name) != ID_OB) {
210                 return false;
211         }
212         Object *object = (Object *)id;
213         ID *data = object->data;
214         if (data == NULL) {
215                 return false;
216         }
217         return ((data->recalc & ID_RECALC_ALL) != 0);
218 }
219
220 /* **************** Depsgraph **************** */
221
222 static void rna_Depsgraph_debug_relations_graphviz(Depsgraph *depsgraph,
223                                                    const char *filename)
224 {
225         FILE *f = fopen(filename, "w");
226         if (f == NULL) {
227                 return;
228         }
229         DEG_debug_relations_graphviz(depsgraph, f, "Depsgraph");
230         fclose(f);
231 }
232
233 static void rna_Depsgraph_debug_stats_gnuplot(Depsgraph *depsgraph,
234                                               const char *filename,
235                                               const char *output_filename)
236 {
237         FILE *f = fopen(filename, "w");
238         if (f == NULL) {
239                 return;
240         }
241         DEG_debug_stats_gnuplot(depsgraph, f, "Timing Statistics", output_filename);
242         fclose(f);
243 }
244
245 static void rna_Depsgraph_debug_tag_update(Depsgraph *depsgraph)
246 {
247         DEG_graph_tag_relations_update(depsgraph);
248 }
249
250 static void rna_Depsgraph_debug_stats(Depsgraph *depsgraph, char *result)
251 {
252         size_t outer, ops, rels;
253         DEG_stats_simple(depsgraph, &outer, &ops, &rels);
254         BLI_snprintf(result, STATS_MAX_SIZE,
255                     "Approx %lu Operations, %lu Relations, %lu Outer Nodes",
256                      ops, rels, outer);
257 }
258
259 /* Iteration over objects, simple version */
260
261 static void rna_Depsgraph_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
262 {
263         iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
264         DEGObjectIterData *data = MEM_callocN(sizeof(DEGObjectIterData), __func__);
265
266         data->graph = (Depsgraph *)ptr->data;
267         data->flag = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
268                      DEG_ITER_OBJECT_FLAG_VISIBLE |
269                      DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
270
271         ((BLI_Iterator *)iter->internal.custom)->valid = true;
272         DEG_iterator_objects_begin(iter->internal.custom, data);
273         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
274 }
275
276 static void rna_Depsgraph_objects_next(CollectionPropertyIterator *iter)
277 {
278         DEG_iterator_objects_next(iter->internal.custom);
279         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
280 }
281
282 static void rna_Depsgraph_objects_end(CollectionPropertyIterator *iter)
283 {
284         DEG_iterator_objects_end(iter->internal.custom);
285         MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
286         MEM_freeN(iter->internal.custom);
287 }
288
289 static PointerRNA rna_Depsgraph_objects_get(CollectionPropertyIterator *iter)
290 {
291         Object *ob = ((BLI_Iterator *)iter->internal.custom)->current;
292         return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ob);
293 }
294
295 /* Iteration over objects, extended version
296  *
297  * Contains extra information about duplicator and persistent ID.
298  */
299
300 /* XXX Ugly python seems to query next item of an iterator before using current one (see T57558).
301  * This forces us to use that nasty ping-pong game between two sets of iterator data, so that previous one remains
302  * valid memory for python to access to. Yuck.
303  */
304 typedef struct RNA_Depsgraph_Instances_Iterator
305 {
306         BLI_Iterator iterators[2];
307         DEGObjectIterData deg_data[2];
308         int counter;
309 } RNA_Depsgraph_Instances_Iterator;
310
311 static void rna_Depsgraph_object_instances_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
312 {
313         RNA_Depsgraph_Instances_Iterator *di_it = iter->internal.custom = MEM_callocN(sizeof(*di_it), __func__);
314
315         DEGObjectIterData *data = &di_it->deg_data[0];
316         data->graph = (Depsgraph *)ptr->data;
317         data->flag = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
318                      DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
319                      DEG_ITER_OBJECT_FLAG_VISIBLE |
320                      DEG_ITER_OBJECT_FLAG_DUPLI;
321
322         di_it->iterators[0].valid = true;
323         DEG_iterator_objects_begin(&di_it->iterators[0], data);
324         iter->valid = di_it->iterators[0].valid;
325 }
326
327 static void rna_Depsgraph_object_instances_next(CollectionPropertyIterator *iter)
328 {
329         RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *)iter->internal.custom;
330
331         /* We need to copy current iterator status to next one beeing worked on. */
332         di_it->iterators[(di_it->counter + 1) % 2] = di_it->iterators[di_it->counter % 2];
333         di_it->deg_data[(di_it->counter + 1) % 2] = di_it->deg_data[di_it->counter % 2];
334         di_it->counter++;
335
336         di_it->iterators[di_it->counter % 2].data = &di_it->deg_data[di_it->counter % 2];
337         DEG_iterator_objects_next(&di_it->iterators[di_it->counter % 2]);
338         iter->valid = di_it->iterators[di_it->counter % 2].valid;
339 }
340
341 static void rna_Depsgraph_object_instances_end(CollectionPropertyIterator *iter)
342 {
343         RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *)iter->internal.custom;
344         DEG_iterator_objects_end(&di_it->iterators[0]);
345         DEG_iterator_objects_end(&di_it->iterators[1]);
346         MEM_freeN(di_it);
347 }
348
349 static PointerRNA rna_Depsgraph_object_instances_get(CollectionPropertyIterator *iter)
350 {
351         RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *)iter->internal.custom;
352         BLI_Iterator *iterator = &di_it->iterators[di_it->counter % 2];
353         return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphObjectInstance, iterator);
354 }
355
356 /* Iteration over evaluated IDs */
357
358 static void rna_Depsgraph_ids_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
359 {
360         iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
361         DEGIDIterData *data = MEM_callocN(sizeof(DEGIDIterData), __func__);
362
363         data->graph = (Depsgraph *)ptr->data;
364
365         ((BLI_Iterator *)iter->internal.custom)->valid = true;
366         DEG_iterator_ids_begin(iter->internal.custom, data);
367         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
368 }
369
370 static void rna_Depsgraph_ids_next(CollectionPropertyIterator *iter)
371 {
372         DEG_iterator_ids_next(iter->internal.custom);
373         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
374 }
375
376 static void rna_Depsgraph_ids_end(CollectionPropertyIterator *iter)
377 {
378         DEG_iterator_ids_end(iter->internal.custom);
379         MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
380         MEM_freeN(iter->internal.custom);
381 }
382
383 static PointerRNA rna_Depsgraph_ids_get(CollectionPropertyIterator *iter)
384 {
385         ID *id = ((BLI_Iterator *)iter->internal.custom)->current;
386         return rna_pointer_inherit_refine(&iter->parent, &RNA_ID, id);
387 }
388
389 static void rna_Depsgraph_updates_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
390 {
391         iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
392         DEGIDIterData *data = MEM_callocN(sizeof(DEGIDIterData), __func__);
393
394         data->graph = (Depsgraph *)ptr->data;
395         data->only_updated = true;
396
397         ((BLI_Iterator *)iter->internal.custom)->valid = true;
398         DEG_iterator_ids_begin(iter->internal.custom, data);
399         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
400 }
401
402 static PointerRNA rna_Depsgraph_updates_get(CollectionPropertyIterator *iter)
403 {
404         ID *id = ((BLI_Iterator *)iter->internal.custom)->current;
405         return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphUpdate, id);
406 }
407
408 static ID *rna_Depsgraph_id_eval_get(Depsgraph *depsgraph, ID *id_orig)
409 {
410         return DEG_get_evaluated_id(depsgraph, id_orig);
411 }
412
413 static bool rna_Depsgraph_id_type_updated(Depsgraph *depsgraph, int id_type)
414 {
415         return DEG_id_type_updated(depsgraph, id_type);
416 }
417
418 static PointerRNA rna_Depsgraph_scene_get(PointerRNA *ptr)
419 {
420         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
421         Scene *scene = DEG_get_input_scene(depsgraph);
422         return rna_pointer_inherit_refine(ptr, &RNA_Scene, scene);
423 }
424
425 static PointerRNA rna_Depsgraph_view_layer_get(PointerRNA *ptr)
426 {
427         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
428         ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
429         return rna_pointer_inherit_refine(ptr, &RNA_ViewLayer, view_layer);
430 }
431
432 static PointerRNA rna_Depsgraph_scene_eval_get(PointerRNA *ptr)
433 {
434         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
435         Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
436         return rna_pointer_inherit_refine(ptr, &RNA_Scene, scene_eval);
437 }
438
439 static PointerRNA rna_Depsgraph_view_layer_eval_get(PointerRNA *ptr)
440 {
441         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
442         ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
443         return rna_pointer_inherit_refine(ptr, &RNA_ViewLayer, view_layer_eval);
444 }
445
446 #else
447
448 static void rna_def_depsgraph_instance(BlenderRNA *brna)
449 {
450         StructRNA *srna;
451         PropertyRNA *prop;
452
453         srna = RNA_def_struct(brna, "DepsgraphObjectInstance", NULL);
454         RNA_def_struct_ui_text(srna, "Dependency Graph Object Instance",
455                                "Extended information about dependency graph object iterator "
456                                "(WARNING: all data here is *evaluated* one, not original .blend IDs...)");
457
458         prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
459         RNA_def_property_struct_type(prop, "Object");
460         RNA_def_property_ui_text(prop, "Object", "Evaluated object the iterator points to");
461         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
462         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_object_get", NULL, NULL, NULL);
463
464         prop = RNA_def_property(srna, "show_self", PROP_BOOLEAN, PROP_NONE);
465         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
466         RNA_def_property_ui_text(prop, "Show Self", "The object geometry itself should be visible in the render");
467         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_show_self_get", NULL);
468
469         prop = RNA_def_property(srna, "show_particles", PROP_BOOLEAN, PROP_NONE);
470         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
471         RNA_def_property_ui_text(prop, "Show Particles", "Particles part of the object should be visible in the render");
472         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_show_particles_get", NULL);
473
474         prop = RNA_def_property(srna, "is_instance", PROP_BOOLEAN, PROP_NONE);
475         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
476         RNA_def_property_ui_text(prop, "Is Instance", "Denotes if the object is generated by another object");
477         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_is_instance_get", NULL);
478
479         prop = RNA_def_property(srna, "instance_object", PROP_POINTER, PROP_NONE);
480         RNA_def_property_struct_type(prop, "Object");
481         RNA_def_property_ui_text(prop, "Instance Object", "Evaluated object which is being instanced by this iterator");
482         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
483         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_instance_object_get", NULL, NULL, NULL);
484
485         prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
486         RNA_def_property_struct_type(prop, "Object");
487         RNA_def_property_ui_text(prop, "Parent", "If the object is an instance, the parent object that generated it");
488         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
489         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_parent_get", NULL, NULL, NULL);
490
491         prop = RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE);
492         RNA_def_property_struct_type(prop, "ParticleSystem");
493         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
494         RNA_def_property_ui_text(prop, "Particle System", "Evaluated particle system that this object was instanced from");
495         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_particle_system_get", NULL, NULL, NULL);
496
497         prop = RNA_def_property(srna, "persistent_id", PROP_INT, PROP_NONE);
498         RNA_def_property_ui_text(prop, "Persistent ID",
499                                  "Persistent identifier for inter-frame matching of objects with motion blur");
500         RNA_def_property_array(prop, 2 * MAX_DUPLI_RECUR);
501         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
502         RNA_def_property_int_funcs(prop, "rna_DepsgraphObjectInstance_persistent_id_get", NULL, NULL);
503
504         prop = RNA_def_property(srna, "random_id", PROP_INT, PROP_UNSIGNED);
505         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
506         RNA_def_property_ui_text(prop, "Dupli random id", "Random id for this instance, typically for randomized shading");
507         RNA_def_property_int_funcs(prop, "rna_DepsgraphObjectInstance_random_id_get", NULL, NULL);
508
509         prop = RNA_def_property(srna, "matrix_world", PROP_FLOAT, PROP_MATRIX);
510         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
511         RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
512         RNA_def_property_ui_text(prop, "Generated Matrix", "Generated transform matrix in world space");
513         RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_matrix_world_get", NULL, NULL);
514
515         prop = RNA_def_property(srna, "orco", PROP_FLOAT, PROP_TRANSLATION);
516         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
517         RNA_def_property_array(prop, 3);
518         RNA_def_property_ui_text(prop, "Generated Coordinates", "Generated coordinates in parent object space");
519         RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_orco_get", NULL, NULL);
520
521         prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
522         RNA_def_property_ui_text(prop, "UV Coordinates", "UV coordinates in parent object space");
523         RNA_def_property_array(prop, 2);
524         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
525         RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_uv_get", NULL, NULL);
526 }
527
528 static void rna_def_depsgraph_update(BlenderRNA *brna)
529 {
530         StructRNA *srna;
531         PropertyRNA *prop;
532
533         srna = RNA_def_struct(brna, "DepsgraphUpdate", NULL);
534         RNA_def_struct_ui_text(srna, "Dependency Graph Update",
535                                "Information about ID that was updated");
536
537         prop = RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE);
538         RNA_def_property_struct_type(prop, "ID");
539         RNA_def_property_ui_text(prop, "ID", "Updated datablock");
540         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
541         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphUpdate_id_get", NULL, NULL, NULL);
542
543         /* Use term 'is_updated' instead of 'is_dirty' here because this is a signal
544          * that users of the depsgraph may want to update their data (render engines for eg). */
545
546         prop = RNA_def_property(srna, "is_updated_transform", PROP_BOOLEAN, PROP_NONE);
547         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
548         RNA_def_property_ui_text(prop, "Transform", "Object transformation is updated");
549         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_updated_transform_get", NULL);
550
551         prop = RNA_def_property(srna, "is_updated_geometry", PROP_BOOLEAN, PROP_NONE);
552         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
553         RNA_def_property_ui_text(prop, "Geometry", "Object geometry is updated");
554         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_updated_geometry_get", NULL);
555 }
556
557 static void rna_def_depsgraph(BlenderRNA *brna)
558 {
559         StructRNA *srna;
560         FunctionRNA *func;
561         PropertyRNA *parm;
562         PropertyRNA *prop;
563
564         static EnumPropertyItem enum_depsgraph_mode_items[] = {
565                 {DAG_EVAL_VIEWPORT, "VIEWPORT", 0, "Viewport", "Viewport non-rendered mode"},
566                 {DAG_EVAL_RENDER, "RENDER", 0, "Render", "Render"},
567                 {0, NULL, 0, NULL, NULL}
568         };
569
570         srna = RNA_def_struct(brna, "Depsgraph", NULL);
571         RNA_def_struct_ui_text(srna, "Dependency Graph", "");
572
573         prop = RNA_def_enum(srna, "mode", enum_depsgraph_mode_items, 0, "Mode", "Evaluation mode");
574         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
575         RNA_def_property_enum_funcs(prop, "rna_Depsgraph_mode_get", NULL, NULL);
576
577         /* Debug helpers. */
578
579         func = RNA_def_function(srna, "debug_relations_graphviz", "rna_Depsgraph_debug_relations_graphviz");
580         parm = RNA_def_string_file_path(func, "filename", NULL, FILE_MAX, "File Name",
581                                         "File in which to store graphviz debug output");
582         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
583
584         func = RNA_def_function(srna, "debug_stats_gnuplot", "rna_Depsgraph_debug_stats_gnuplot");
585         parm = RNA_def_string_file_path(func, "filename", NULL, FILE_MAX, "File Name",
586                                         "File in which to store graphviz debug output");
587         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
588         parm = RNA_def_string_file_path(func, "output_filename", NULL, FILE_MAX, "Output File Name",
589                                         "File name where gnuplot script will save the result");
590         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
591
592         func = RNA_def_function(srna, "debug_tag_update", "rna_Depsgraph_debug_tag_update");
593
594         func = RNA_def_function(srna, "debug_stats", "rna_Depsgraph_debug_stats");
595         RNA_def_function_ui_description(func, "Report the number of elements in the Dependency Graph");
596         /* weak!, no way to return dynamic string type */
597         parm = RNA_def_string(func, "result", NULL, STATS_MAX_SIZE, "result", "");
598         RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */
599         RNA_def_function_output(func, parm);
600
601         /* Queries for original datablockls (the ones depsgraph is built for). */
602
603         prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
604         RNA_def_property_struct_type(prop, "Scene");
605         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_get", NULL, NULL, NULL);
606         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
607         RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
608
609         prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
610         RNA_def_property_struct_type(prop, "ViewLayer");
611         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_get", NULL, NULL, NULL);
612         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
613         RNA_def_property_ui_text(prop, "View Layer", "Original view layer dependency graph is built for");
614
615         /* Queries for evaluated datablockls (the ones depsgraph is evaluating). */
616
617         func = RNA_def_function(srna, "id_eval_get", "rna_Depsgraph_id_eval_get");
618         parm = RNA_def_pointer(func, "id", "ID", "", "Original ID to get evaluated complementary part for");
619         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
620         parm = RNA_def_pointer(func, "id_eval", "ID", "", "Evaluated ID for the given original one");
621         RNA_def_function_return(func, parm);
622
623         func = RNA_def_function(srna, "id_type_updated", "rna_Depsgraph_id_type_updated");
624         parm = RNA_def_enum(func, "id_type", rna_enum_id_type_items, 0, "ID Type", "");
625         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
626         parm = RNA_def_boolean(func, "updated", false, "Updated", "True if any datablock with this type was added, updated or removed");
627         RNA_def_function_return(func, parm);
628
629         prop = RNA_def_property(srna, "scene_eval", PROP_POINTER, PROP_NONE);
630         RNA_def_property_struct_type(prop, "Scene");
631         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_eval_get", NULL, NULL, NULL);
632         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
633         RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
634
635         prop = RNA_def_property(srna, "view_layer_eval", PROP_POINTER, PROP_NONE);
636         RNA_def_property_struct_type(prop, "ViewLayer");
637         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_eval_get", NULL, NULL, NULL);
638         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
639         RNA_def_property_ui_text(prop, "View Layer", "Original view layer dependency graph is built for");
640
641         /* Iterators. */
642
643         prop = RNA_def_property(srna, "ids", PROP_COLLECTION, PROP_NONE);
644         RNA_def_property_struct_type(prop, "ID");
645         RNA_def_property_collection_funcs(prop,
646                                           "rna_Depsgraph_ids_begin",
647                                           "rna_Depsgraph_ids_next",
648                                           "rna_Depsgraph_ids_end",
649                                           "rna_Depsgraph_ids_get",
650                                           NULL, NULL, NULL, NULL);
651         RNA_def_property_ui_text(prop, "IDs", "All evaluated datablocks");
652
653         prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
654         RNA_def_property_struct_type(prop, "Object");
655         RNA_def_property_collection_funcs(prop,
656                                           "rna_Depsgraph_objects_begin",
657                                           "rna_Depsgraph_objects_next",
658                                           "rna_Depsgraph_objects_end",
659                                           "rna_Depsgraph_objects_get",
660                                           NULL, NULL, NULL, NULL);
661         RNA_def_property_ui_text(prop, "Objects", "Evaluated objects in the dependency graph");
662
663         prop = RNA_def_property(srna, "object_instances", PROP_COLLECTION, PROP_NONE);
664         RNA_def_property_struct_type(prop, "DepsgraphObjectInstance");
665         RNA_def_property_collection_funcs(prop,
666                                           "rna_Depsgraph_object_instances_begin",
667                                           "rna_Depsgraph_object_instances_next",
668                                           "rna_Depsgraph_object_instances_end",
669                                           "rna_Depsgraph_object_instances_get",
670                                           NULL, NULL, NULL, NULL);
671         RNA_def_property_ui_text(prop, "Object Instances", "All object instances to display or render");
672
673         prop = RNA_def_property(srna, "updates", PROP_COLLECTION, PROP_NONE);
674         RNA_def_property_struct_type(prop, "DepsgraphUpdate");
675         RNA_def_property_collection_funcs(prop,
676                                           "rna_Depsgraph_updates_begin",
677                                           "rna_Depsgraph_ids_next",
678                                           "rna_Depsgraph_ids_end",
679                                           "rna_Depsgraph_updates_get",
680                                           NULL, NULL, NULL, NULL);
681         RNA_def_property_ui_text(prop, "Updates", "Updates to datablocks");
682 }
683
684 void RNA_def_depsgraph(BlenderRNA *brna)
685 {
686         rna_def_depsgraph_instance(brna);
687         rna_def_depsgraph_update(brna);
688         rna_def_depsgraph(brna);
689 }
690
691 #endif