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

depsgraph_build.h « intern « depsgraph « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c5b04ec299c3e42b18cdc7a246216a7efdc7a772 (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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/*
 * ***** 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.
 *
 * The Original Code is Copyright (C) 2013 Blender Foundation.
 * All rights reserved.
 *
 * Original Author: Lukas Toenne
 * Contributor(s): None Yet
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/depsgraph/intern/depsgraph_build.h
 *  \ingroup depsgraph
 */

#ifndef __DEPSGRAPH_BUILD_H__
#define __DEPSGRAPH_BUILD_H__

struct Base;
struct bGPdata;
struct ListBase;
struct GHash;
struct ID;
struct FCurve;
struct Group;
struct Key;
struct Main;
struct Material;
struct MTex;
struct bNodeTree;
struct Object;
struct bPoseChannel;
struct bConstraint;
struct Scene;
struct Tex;
struct World;

struct PropertyRNA;

struct Depsgraph;
struct DepsNode;
struct DepsNodeHandle;
struct RootDepsNode;
struct SubgraphDepsNode;
struct IDDepsNode;
struct TimeSourceDepsNode;
struct ComponentDepsNode;
struct OperationDepsNode;
struct RootPChanMap;

struct DepsgraphNodeBuilder {
	DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph);
	~DepsgraphNodeBuilder();

	RootDepsNode *add_root_node();
	IDDepsNode *add_id_node(ID *id);
	TimeSourceDepsNode *add_time_source(ID *id);

	ComponentDepsNode *add_component_node(ID *id, eDepsNode_Type comp_type, const string &comp_name = "");

	OperationDepsNode *add_operation_node(ComponentDepsNode *comp_node, eDepsOperation_Type optype,
	                                      DepsEvalOperationCb op, eDepsOperation_Code opcode, const string &description = "");
	OperationDepsNode *add_operation_node(ID *id, eDepsNode_Type comp_type, const string &comp_name, eDepsOperation_Type optype,
	                                      DepsEvalOperationCb op, eDepsOperation_Code opcode, const string &description = "");
	OperationDepsNode *add_operation_node(ID *id, eDepsNode_Type comp_type, eDepsOperation_Type optype,
	                                      DepsEvalOperationCb op, eDepsOperation_Code opcode, const string &description = "")
	{
		return add_operation_node(id, comp_type, "", optype, op, opcode, description);
	}

	bool has_operation_node(ID *id, eDepsNode_Type comp_type, const string &comp_name,
	                        eDepsOperation_Code opcode, const string &description = "");

	OperationDepsNode *find_operation_node(ID *id,
	                                       eDepsNode_Type comp_type,
	                                       const string &comp_name,
	                                       eDepsOperation_Code opcode,
	                                       const string &description = "");

	OperationDepsNode *find_operation_node(ID *id,
	                                       eDepsNode_Type comp_type,
	                                       eDepsOperation_Code opcode,
	                                       const string &description = "")
	{
		return find_operation_node(id, comp_type, "", opcode, description);
	}

	void build_scene(Main *bmain, Scene *scene);
	SubgraphDepsNode *build_subgraph(Group *group);
	void build_group(Scene *scene, Base *base, Group *group);
	void build_object(Scene *scene, Base *base, Object *ob);
	void build_object_transform(Scene *scene, Object *ob);
	void build_object_constraints(Scene *scene, Object *ob);
	void build_pose_constraints(Object *ob, bPoseChannel *pchan);
	void build_rigidbody(Scene *scene);
	void build_particles(Scene *scene, Object *ob);
	void build_animdata(ID *id);
	OperationDepsNode *build_driver(ID *id, FCurve *fcurve);
	void build_ik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con);
	void build_splineik_pose(Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con);
	void build_rig(Scene *scene, Object *ob);
	void build_proxy_rig(Object *ob);
	void build_shapekeys(Key *key);
	void build_obdata_geom(Scene *scene, Object *ob);
	void build_camera(Object *ob);
	void build_lamp(Object *ob);
	void build_nodetree(DepsNode *owner_node, bNodeTree *ntree);
	void build_material(DepsNode *owner_node, Material *ma);
	void build_texture(DepsNode *owner_node, Tex *tex);
	void build_texture_stack(DepsNode *owner_node, MTex **texture_stack);
	void build_world(World *world);
	void build_compositor(Scene *scene);
	void build_gpencil(bGPdata *gpd);

private:
	Main *m_bmain;
	Depsgraph *m_graph;
};

struct RootKey
{
	RootKey() {}
};

struct TimeSourceKey
{
	TimeSourceKey() : id(NULL) {}
	TimeSourceKey(ID *id) : id(id) {}

	string identifier() const
	{
		return string("TimeSourceKey");
	}

	ID *id;
};

struct ComponentKey
{
	ComponentKey() :
	    id(NULL), type(DEPSNODE_TYPE_UNDEFINED), name("")
	{}
	ComponentKey(ID *id, eDepsNode_Type type, const string &name = "") :
	    id(id), type(type), name(name)
	{}

	string identifier() const
	{
		const char *idname = (id) ? id->name : "<None>";

		char typebuf[5];
		sprintf(typebuf, "%d", type);

		return string("ComponentKey(") + idname + ", " + typebuf + ", '" + name + "')";
	}

	ID *id;
	eDepsNode_Type type;
	string name;
};

struct OperationKey
{
	OperationKey() :
	    id(NULL), component_type(DEPSNODE_TYPE_UNDEFINED), component_name(""), opcode(DEG_OPCODE_OPERATION), name("")
	{}

	OperationKey(ID *id, eDepsNode_Type component_type, const string &name) :
	    id(id), component_type(component_type), component_name(""), opcode(DEG_OPCODE_OPERATION), name(name)
	{}
	OperationKey(ID *id, eDepsNode_Type component_type, const string &component_name, const string &name) :
	    id(id), component_type(component_type), component_name(component_name), opcode(DEG_OPCODE_OPERATION), name(name)
	{}

	OperationKey(ID *id, eDepsNode_Type component_type, eDepsOperation_Code opcode) :
	    id(id), component_type(component_type), component_name(""), opcode(opcode), name("")
	{}
	OperationKey(ID *id, eDepsNode_Type component_type, const string &component_name, eDepsOperation_Code opcode) :
	    id(id), component_type(component_type), component_name(component_name), opcode(opcode), name("")
	{}

	OperationKey(ID *id, eDepsNode_Type component_type, eDepsOperation_Code opcode, const string &name) :
	    id(id), component_type(component_type), component_name(""), opcode(opcode), name(name)
	{}
	OperationKey(ID *id, eDepsNode_Type component_type, const string &component_name, eDepsOperation_Code opcode, const string &name) :
	    id(id), component_type(component_type), component_name(component_name), opcode(opcode), name(name)
	{}

	string identifier() const
	{
		char typebuf[5];
		sprintf(typebuf, "%d", component_type);

		return string("OperationKey(") + "t: " + typebuf + ", cn: '" + component_name + "', c: " + DEG_OPNAMES[opcode] + ", n: '" + name + "')";
	}


	ID *id;
	eDepsNode_Type component_type;
	string component_name;
	eDepsOperation_Code opcode;
	string name;
};

struct RNAPathKey
{
	// Note: see depsgraph_build.cpp for implementation
	RNAPathKey(ID *id, const char *path);

	RNAPathKey(ID *id, const PointerRNA &ptr, PropertyRNA *prop) :
	    id(id), ptr(ptr), prop(prop)
	{}

	string identifier() const
	{
		const char *id_name   = (id) ?  id->name : "<No ID>";
		const char *prop_name = (prop) ? RNA_property_identifier(prop) : "<No Prop>";

		return string("RnaPathKey(") + "id: " + id_name + ", prop: " + prop_name +  "')";
	}


	ID *id;
	PointerRNA ptr;
	PropertyRNA *prop;
};

struct DepsgraphRelationBuilder
{
	DepsgraphRelationBuilder(Depsgraph *graph);

	template <typename KeyFrom, typename KeyTo>
	void add_relation(const KeyFrom &key_from, const KeyTo &key_to,
	                  eDepsRelation_Type type, const char *description);

	template <typename KeyTo>
	void add_relation(const TimeSourceKey &key_from, const KeyTo &key_to,
	                  eDepsRelation_Type type, const char *description);

	template <typename KeyType>
	void add_node_handle_relation(const KeyType &key_from, const DepsNodeHandle *handle,
	                              eDepsRelation_Type type, const char *description);

	void build_scene(Main *bmain, Scene *scene);
	void build_group(Main *bmain, Scene *scene, Object *object, Group *group);
	void build_object(Main *bmain, Scene *scene, Object *ob);
	void build_object_parent(Object *ob);
	void build_constraints(Scene *scene, ID *id, eDepsNode_Type component_type, const char *component_subdata,
	                       ListBase *constraints, RootPChanMap *root_map);
	void build_animdata(ID *id);
	void build_driver(ID *id, FCurve *fcurve);
	void build_world(World *world);
	void build_rigidbody(Scene *scene);
	void build_particles(Scene *scene, Object *ob);
	void build_ik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con, RootPChanMap *root_map);
	void build_splineik_pose(Object *ob, bPoseChannel *pchan, bConstraint *con, RootPChanMap *root_map);
	void build_rig(Scene *scene, Object *ob);
	void build_proxy_rig(Object *ob);
	void build_shapekeys(ID *obdata, Key *key);
	void build_obdata_geom(Main *bmain, Scene *scene, Object *ob);
	void build_camera(Object *ob);
	void build_lamp(Object *ob);
	void build_nodetree(ID *owner, bNodeTree *ntree);
	void build_material(ID *owner, Material *ma);
	void build_texture(ID *owner, Tex *tex);
	void build_texture_stack(ID *owner, MTex **texture_stack);
	void build_compositor(Scene *scene);
	void build_gpencil(ID *owner, bGPdata *gpd);

protected:
	RootDepsNode *find_node(const RootKey &key) const;
	TimeSourceDepsNode *find_node(const TimeSourceKey &key) const;
	ComponentDepsNode *find_node(const ComponentKey &key) const;
	OperationDepsNode *find_node(const OperationKey &key) const;
	DepsNode *find_node(const RNAPathKey &key) const;
	OperationDepsNode *has_node(const OperationKey &key) const;

	void add_time_relation(TimeSourceDepsNode *timesrc, DepsNode *node_to, const char *description);
	void add_operation_relation(OperationDepsNode *node_from, OperationDepsNode *node_to,
	                            eDepsRelation_Type type, const char *description);

	template <typename KeyType>
	DepsNodeHandle create_node_handle(const KeyType &key, const string &default_name = "");

	bool needs_animdata_node(ID *id);

private:
	Depsgraph *m_graph;
};

struct DepsNodeHandle
{
	DepsNodeHandle(DepsgraphRelationBuilder *builder, OperationDepsNode *node, const string &default_name = "") :
	    builder(builder),
	    node(node),
	    default_name(default_name)
	{
		BLI_assert(node != NULL);
	}

	DepsgraphRelationBuilder *builder;
	OperationDepsNode *node;
	const string &default_name;
};

/* Utilities for Builders ----------------------------------------------------- */

/* Get unique identifier for FCurves and Drivers */
string deg_fcurve_id_name(const FCurve *fcu);

template <typename KeyFrom, typename KeyTo>
void DepsgraphRelationBuilder::add_relation(const KeyFrom &key_from,
                                            const KeyTo &key_to,
                                            eDepsRelation_Type type,
                                            const char *description)
{
	DepsNode *node_from = find_node(key_from);
	DepsNode *node_to = find_node(key_to);
	OperationDepsNode *op_from = node_from ? node_from->get_exit_operation() : NULL;
	OperationDepsNode *op_to = node_to ? node_to->get_entry_operation() : NULL;
	if (op_from && op_to) {
		add_operation_relation(op_from, op_to, type, description);
	}
	else {
		if (!op_from) {
			/* XXX TODO handle as error or report if needed */
			fprintf(stderr, "add_relation(%d, %s) - Could not find op_from (%s)\n",
			        type, description, key_from.identifier().c_str());
		}
		else {
			fprintf(stderr, "add_relation(%d, %s) - Failed, but op_from (%s) was ok\n",
			        type, description, key_from.identifier().c_str());
		}
		if (!op_to) {
			/* XXX TODO handle as error or report if needed */
			fprintf(stderr, "add_relation(%d, %s) - Could not find op_to (%s)\n",
			        type, description, key_to.identifier().c_str());
		}
		else {
			fprintf(stderr, "add_relation(%d, %s) - Failed, but op_to (%s) was ok\n",
			        type, description, key_to.identifier().c_str());
		}
	}
}

template <typename KeyTo>
void DepsgraphRelationBuilder::add_relation(const TimeSourceKey &key_from,
                                            const KeyTo &key_to,
                                            eDepsRelation_Type type,
                                            const char *description)
{
	(void)type;  /* Ignored in release builds. */
	BLI_assert(type == DEPSREL_TYPE_TIME);
	TimeSourceDepsNode *time_from = find_node(key_from);
	DepsNode *node_to = find_node(key_to);
	OperationDepsNode *op_to = node_to ? node_to->get_entry_operation() : NULL;
	if (time_from && op_to) {
		add_time_relation(time_from, op_to, description);
	}
	else {
	}
}

template <typename KeyType>
void DepsgraphRelationBuilder::add_node_handle_relation(const KeyType &key_from,
                                                        const DepsNodeHandle *handle,
                                                        eDepsRelation_Type type,
                                                        const char *description)
{
	DepsNode *node_from = find_node(key_from);
	OperationDepsNode *op_from = node_from ? node_from->get_exit_operation() : NULL;
	OperationDepsNode *op_to = handle->node->get_entry_operation();
	if (op_from && op_to) {
		add_operation_relation(op_from, op_to, type, description);
	}
	else {
		if (!op_from) {
			/* XXX TODO handle as error or report if needed */
		}
		if (!op_to) {
			/* XXX TODO handle as error or report if needed */
		}
	}
}

template <typename KeyType>
DepsNodeHandle DepsgraphRelationBuilder::create_node_handle(const KeyType &key,
                                                            const string &default_name)
{
	return DepsNodeHandle(this, find_node(key), default_name);
}

#endif  /* __DEPSGRAPH_BUILD_H__ */