Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rna_depsgraph.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 88a1873c17fe82360432cb8420f249f64acaf9a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor(s): Blender Foundation (2014).
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/makesrna/intern/rna_depsgraph.c
 *  \ingroup RNA
 */

#include <stdlib.h>

#include "BLI_utildefines.h"
#include "BLI_path_util.h"

#include "RNA_define.h"
#include "RNA_enum_types.h"

#include "rna_internal.h"

#include "DEG_depsgraph.h"

#include "DNA_object_types.h"

#ifdef RNA_RUNTIME

#include "BLI_iterator.h"
#include "BKE_report.h"

#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_debug.h"
#include "DEG_depsgraph_query.h"

#include "MEM_guardedalloc.h"

/* **************** Depsgraph **************** */

static PointerRNA rna_DepsgraphIter_object_get(PointerRNA *ptr)
{
	BLI_Iterator *iterator = ptr->data;
	return rna_pointer_inherit_refine(ptr, &RNA_Object, iterator->current);
}

static PointerRNA rna_DepsgraphIter_instance_object_get(PointerRNA *ptr)
{
	BLI_Iterator *iterator = ptr->data;
	DEGObjectsIteratorData *deg_iter = (DEGObjectsIteratorData *)iterator->data;
	Object *instance_object = NULL;
	if (deg_iter->dupli_object_current != NULL) {
		instance_object = deg_iter->dupli_object_current->ob;
	}
	return rna_pointer_inherit_refine(ptr, &RNA_Object, instance_object);
}

static PointerRNA rna_DepsgraphIter_parent_get(PointerRNA *ptr)
{
	BLI_Iterator *iterator = ptr->data;
	DEGObjectsIteratorData *deg_iter = (DEGObjectsIteratorData *)iterator->data;
	Object *dupli_parent = NULL;
	if (deg_iter->dupli_object_current != NULL) {
		dupli_parent = deg_iter->dupli_parent;
	}
	return rna_pointer_inherit_refine(ptr, &RNA_Object, dupli_parent);
}

static void rna_DepsgraphIter_persistent_id_get(PointerRNA *ptr, int *persistent_id)
{
	BLI_Iterator *iterator = ptr->data;
	DEGObjectsIteratorData *deg_iter = (DEGObjectsIteratorData *)iterator->data;
	memcpy(persistent_id, deg_iter->dupli_object_current->persistent_id,
	       sizeof(deg_iter->dupli_object_current->persistent_id));
}

static void rna_DepsgraphIter_orco_get(PointerRNA *ptr, float *orco)
{
	BLI_Iterator *iterator = ptr->data;
	DEGObjectsIteratorData *deg_iter = (DEGObjectsIteratorData *)iterator->data;
	memcpy(orco, deg_iter->dupli_object_current->orco,
	       sizeof(deg_iter->dupli_object_current->orco));
}

static unsigned int rna_DepsgraphIter_random_id_get(PointerRNA *ptr)
{
	BLI_Iterator *iterator = ptr->data;
	DEGObjectsIteratorData *deg_iter = (DEGObjectsIteratorData *)iterator->data;
	return deg_iter->dupli_object_current->random_id;
}

static void rna_DepsgraphIter_uv_get(PointerRNA *ptr, float *uv)
{
	BLI_Iterator *iterator = ptr->data;
	DEGObjectsIteratorData *deg_iter = (DEGObjectsIteratorData *)iterator->data;
	memcpy(uv, deg_iter->dupli_object_current->uv,
	       sizeof(deg_iter->dupli_object_current->uv));
}

static int rna_DepsgraphIter_is_instance_get(PointerRNA *ptr)
{
	BLI_Iterator *iterator = ptr->data;
	DEGObjectsIteratorData *deg_iter = (DEGObjectsIteratorData *)iterator->data;
	return (deg_iter->dupli_object_current != NULL);
}

/* **************** Depsgraph **************** */

static void rna_Depsgraph_debug_graphviz(Depsgraph *graph, const char *filename)
{
	FILE *f = fopen(filename, "w");
	if (f == NULL)
		return;

	DEG_debug_graphviz(graph, f, "Depsgraph", false);

	fclose(f);
}

static void rna_Depsgraph_debug_rebuild(Depsgraph *UNUSED(graph), bContext *C)
{
	Main *bmain = CTX_data_main(C);
	EvaluationContext eval_ctx;
	Scene *sce;

	CTX_data_eval_ctx(C, &eval_ctx);

	DEG_relations_tag_update(bmain);
	for (sce = bmain->scene.first; sce; sce = sce->id.next) {
		DEG_scene_relations_rebuild(bmain, sce);
		DEG_graph_on_visible_update(bmain, sce);
	}
}

static void rna_Depsgraph_debug_stats(Depsgraph *graph, ReportList *reports)
{
	size_t outer, ops, rels;

	DEG_stats_simple(graph, &outer, &ops, &rels);

	// XXX: report doesn't seem to work
	printf("Approx %lu Operations, %lu Relations, %lu Outer Nodes\n",
	       ops, rels, outer);

	BKE_reportf(reports, RPT_WARNING, "Approx. %lu Operations, %lu Relations, %lu Outer Nodes",
	            ops, rels, outer);
}

/* Iteration over objects, simple version */

static void rna_Depsgraph_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
	DEGObjectsIteratorData *data = MEM_callocN(sizeof(DEGObjectsIteratorData), __func__);

	data->graph = (Depsgraph *)ptr->data;
	data->flag = DEG_OBJECT_ITER_FLAG_SET;

	DEG_objects_iterator_begin(iter->internal.custom, data);
	iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
}

static void rna_Depsgraph_objects_next(CollectionPropertyIterator *iter)
{
	DEG_objects_iterator_next(iter->internal.custom);
	iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
}

static void rna_Depsgraph_objects_end(CollectionPropertyIterator *iter)
{
	DEG_objects_iterator_end(iter->internal.custom);
	MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
	MEM_freeN(iter->internal.custom);
}

static PointerRNA rna_Depsgraph_objects_get(CollectionPropertyIterator *iter)
{
	Object *ob = ((BLI_Iterator *)iter->internal.custom)->current;
	return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ob);
}

/* Iteration over objects, extended version
 *
 * Contains extra information about duplicator and persistent ID.
 */

static void rna_Depsgraph_duplis_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
	DEGObjectsIteratorData *data = MEM_callocN(sizeof(DEGObjectsIteratorData), __func__);

	data->graph = (Depsgraph *)ptr->data;
	data->flag = DEG_OBJECT_ITER_FLAG_ALL;

	DEG_objects_iterator_begin(iter->internal.custom, data);
	iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
}

static void rna_Depsgraph_duplis_next(CollectionPropertyIterator *iter)
{
	DEG_objects_iterator_next(iter->internal.custom);
	iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
}

static void rna_Depsgraph_duplis_end(CollectionPropertyIterator *iter)
{
	DEG_objects_iterator_end(iter->internal.custom);
	MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
	MEM_freeN(iter->internal.custom);
}

static PointerRNA rna_Depsgraph_duplis_get(CollectionPropertyIterator *iter)
{
	BLI_Iterator *iterator = (BLI_Iterator *)iter->internal.custom;
	return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphIter, iterator);
}

static ID *rna_Depsgraph_evaluated_id_get(Depsgraph *depsgraph, ID *id_orig)
{
	return DEG_get_evaluated_id(depsgraph, id_orig);
}

#else

static void rna_def_depsgraph_iter(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "DepsgraphIter", NULL);
	RNA_def_struct_ui_text(srna, "Dependency Graph Iterator",
	                       "Extended information about dependency graph object iterator");

	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_ui_text(prop, "Object", "Object the iterator points to");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
	RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_object_get", NULL, NULL, NULL);

	prop = RNA_def_property(srna, "instance_object", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_ui_text(prop, "Instance Object", "Object which is being instanced by this iterator");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
	RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_instance_object_get", NULL, NULL, NULL);

	prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_ui_text(prop, "Parent", "Parent of the duplication list");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
	RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_parent_get", NULL, NULL, NULL);

	prop = RNA_def_property(srna, "persistent_id", PROP_INT, PROP_NONE);
	RNA_def_property_ui_text(prop, "Persistent ID",
	                         "Persistent identifier for inter-frame matching of objects with motion blur");
	RNA_def_property_array(prop, 2 * MAX_DUPLI_RECUR);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
	RNA_def_property_int_funcs(prop, "rna_DepsgraphIter_persistent_id_get", NULL, NULL);

	prop = RNA_def_property(srna, "orco", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
	/* Seems system is not smart enough to figure that getter function should return
	 * array for PROP_TRANSLATION.
	 */
	RNA_def_property_array(prop, 3);
	RNA_def_property_ui_text(prop, "Generated Coordinates", "Generated coordinates in parent object space");
	RNA_def_property_float_funcs(prop, "rna_DepsgraphIter_orco_get", NULL, NULL);

	prop = RNA_def_property(srna, "random_id", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Dupli random id", "Random id for this dupli object");
	RNA_def_property_int_funcs(prop, "rna_DepsgraphIter_random_id_get", NULL, NULL);

	prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
	RNA_def_property_ui_text(prop, "UV Coordinates", "UV coordinates in parent object space");
	RNA_def_property_array(prop, 2);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
	RNA_def_property_float_funcs(prop, "rna_DepsgraphIter_uv_get", NULL, NULL);

	prop = RNA_def_property(srna, "is_instance", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Is Instance", "Denotes whether the object is ocming from dupli-list");
	RNA_def_property_boolean_funcs(prop, "rna_DepsgraphIter_is_instance_get", NULL);
}

static void rna_def_depsgraph(BlenderRNA *brna)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *parm;
	PropertyRNA *prop;

	srna = RNA_def_struct(brna, "Depsgraph", NULL);
	RNA_def_struct_ui_text(srna, "Dependency Graph", "");

	func = RNA_def_function(srna, "debug_graphviz", "rna_Depsgraph_debug_graphviz");
	parm = RNA_def_string_file_path(func, "filename", NULL, FILE_MAX, "File Name",
	                                "File in which to store graphviz debug output");
	RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);

	func = RNA_def_function(srna, "debug_rebuild", "rna_Depsgraph_debug_rebuild");
	RNA_def_function_flag(func, FUNC_USE_CONTEXT);

	func = RNA_def_function(srna, "debug_stats", "rna_Depsgraph_debug_stats");
	RNA_def_function_ui_description(func, "Report the number of elements in the Dependency Graph");
	RNA_def_function_flag(func, FUNC_USE_REPORTS);

	prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_collection_funcs(prop,
	                                  "rna_Depsgraph_objects_begin",
	                                  "rna_Depsgraph_objects_next",
	                                  "rna_Depsgraph_objects_end",
	                                  "rna_Depsgraph_objects_get",
	                                  NULL, NULL, NULL, NULL);

	func = RNA_def_function(srna, "evaluated_id_get", "rna_Depsgraph_evaluated_id_get");
	parm = RNA_def_pointer(func, "id", "ID", "", "Original ID to get evaluated complementary part for");
	RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
	parm = RNA_def_pointer(func, "evaluated_id", "ID", "", "Evaluated ID for the given original one");
	RNA_def_function_return(func, parm);

	/* TODO(sergey): Find a better name. */
	prop = RNA_def_property(srna, "duplis", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "DepsgraphIter");
	RNA_def_property_collection_funcs(prop,
	                                  "rna_Depsgraph_duplis_begin",
	                                  "rna_Depsgraph_duplis_next",
	                                  "rna_Depsgraph_duplis_end",
	                                  "rna_Depsgraph_duplis_get",
	                                  NULL, NULL, NULL, NULL);
}

void RNA_def_depsgraph(BlenderRNA *brna)
{
	rna_def_depsgraph_iter(brna);
	rna_def_depsgraph(brna);
}

#endif