Depsgraph: Object data separation, armature
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_relations.h
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  * The Original Code is Copyright (C) 2013 Blender Foundation.
19  * All rights reserved.
20  *
21  * Original Author: Lukas Toenne
22  * Contributor(s): None Yet
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/intern/builder/deg_builder_relations.h
28  *  \ingroup depsgraph
29  */
30
31 #pragma once
32
33 #include <cstdio>
34 #include <cstring>
35
36 #include "intern/depsgraph_types.h"
37
38 #include "DNA_ID.h"
39
40 #include "RNA_access.h"
41 #include "RNA_types.h"
42
43 #include "BLI_utildefines.h"
44 #include "BLI_string.h"
45
46 #include "intern/builder/deg_builder_map.h"
47 #include "intern/nodes/deg_node.h"
48 #include "intern/nodes/deg_node_component.h"
49 #include "intern/nodes/deg_node_operation.h"
50
51 struct Base;
52 struct bArmature;
53 struct bGPdata;
54 struct CacheFile;
55 struct Camera;
56 struct ListBase;
57 struct GHash;
58 struct ID;
59 struct FCurve;
60 struct Collection;
61 struct Key;
62 struct Lamp;
63 struct LayerCollection;
64 struct LightProbe;
65 struct Main;
66 struct Mask;
67 struct Material;
68 struct MTex;
69 struct ModifierData;
70 struct MovieClip;
71 struct bNodeTree;
72 struct Object;
73 struct bPoseChannel;
74 struct bConstraint;
75 struct ParticleSystem;
76 struct ParticleSettings;
77 struct Scene;
78 struct ViewLayer;
79 struct Tex;
80 struct World;
81 struct EffectorWeights;
82
83 struct PropertyRNA;
84
85 namespace DEG {
86
87 struct Depsgraph;
88 struct DepsNode;
89 struct DepsNodeHandle;
90 struct DepsRelation;
91 struct RootDepsNode;
92 struct IDDepsNode;
93 struct TimeSourceDepsNode;
94 struct ComponentDepsNode;
95 struct OperationDepsNode;
96 struct RootPChanMap;
97
98 struct TimeSourceKey
99 {
100         TimeSourceKey();
101         TimeSourceKey(ID *id);
102
103         string identifier() const;
104
105         ID *id;
106 };
107
108 struct ComponentKey
109 {
110         ComponentKey();
111         ComponentKey(ID *id, eDepsNode_Type type, const char *name = "");
112
113         string identifier() const;
114
115         ID *id;
116         eDepsNode_Type type;
117         const char *name;
118 };
119
120 struct OperationKey
121 {
122         OperationKey();
123         OperationKey(ID *id,
124                      eDepsNode_Type component_type,
125                      const char *name,
126                      int name_tag = -1);
127         OperationKey(ID *id,
128                      eDepsNode_Type component_type,
129                      const char *component_name,
130                      const char *name,
131                      int name_tag);
132
133         OperationKey(ID *id,
134                      eDepsNode_Type component_type,
135                      eDepsOperation_Code opcode);
136         OperationKey(ID *id,
137                      eDepsNode_Type component_type,
138                      const char *component_name,
139                      eDepsOperation_Code opcode);
140
141         OperationKey(ID *id,
142                      eDepsNode_Type component_type,
143                      eDepsOperation_Code opcode,
144                      const char *name,
145                      int name_tag = -1);
146         OperationKey(ID *id,
147                      eDepsNode_Type component_type,
148                      const char *component_name,
149                      eDepsOperation_Code opcode,
150                      const char *name,
151                      int name_tag = -1);
152
153         string identifier() const;
154
155         ID *id;
156         eDepsNode_Type component_type;
157         const char *component_name;
158         eDepsOperation_Code opcode;
159         const char *name;
160         int name_tag;
161 };
162
163 struct RNAPathKey
164 {
165         /* NOTE: see depsgraph_build.cpp for implementation */
166         RNAPathKey(ID *id, const char *path);
167
168         RNAPathKey(ID *id, const PointerRNA &ptr, PropertyRNA *prop);
169
170         string identifier() const;
171
172         ID *id;
173         PointerRNA ptr;
174         PropertyRNA *prop;
175 };
176
177 struct DepsgraphRelationBuilder
178 {
179         DepsgraphRelationBuilder(Main *bmain, Depsgraph *graph);
180
181         void begin_build();
182
183         template <typename KeyFrom, typename KeyTo>
184         DepsRelation *add_relation(const KeyFrom& key_from,
185                                    const KeyTo& key_to,
186                                    const char *description,
187                                    bool check_unique = false);
188
189         template <typename KeyTo>
190         DepsRelation *add_relation(const TimeSourceKey& key_from,
191                                    const KeyTo& key_to,
192                                    const char *description,
193                                    bool check_unique = false);
194
195         template <typename KeyType>
196         DepsRelation *add_node_handle_relation(const KeyType& key_from,
197                                                const DepsNodeHandle *handle,
198                                                const char *description,
199                                                bool check_unique = false);
200
201         void build_id(ID *id);
202         void build_layer_collections(ListBase *lb);
203         void build_view_layer(Scene *scene, ViewLayer *view_layer);
204         void build_collection(Object *object, Collection *collection);
205         void build_object(Base *base, Object *object);
206         void build_object_flags(Base *base, Object *object);
207         void build_object_data(Object *object);
208         void build_object_data_camera(Object *object);
209         void build_object_data_geometry(Object *object);
210         void build_object_data_geometry_datablock(ID *obdata);
211         void build_object_data_lamp(Object *object);
212         void build_object_data_lightprobe(Object *object);
213         void build_object_parent(Object *object);
214         void build_constraints(ID *id,
215                                eDepsNode_Type component_type,
216                                const char *component_subdata,
217                                ListBase *constraints,
218                                RootPChanMap *root_map);
219         void build_animdata(ID *id);
220         void build_animdata_curves(ID *id);
221         void build_animdata_curves_targets(ID *id,
222                                            ComponentKey &adt_key,
223                                            OperationDepsNode *operation_from,
224                                            ListBase *curves);
225         void build_animdata_nlastrip_targets(ID *id,
226                                              ComponentKey &adt_key,
227                                              OperationDepsNode *operation_from,
228                                              ListBase *strips);
229         void build_animdata_drivers(ID *id);
230         void build_driver(ID *id, FCurve *fcurve);
231         void build_driver_data(ID *id, FCurve *fcurve);
232         void build_driver_variables(ID *id, FCurve *fcurve);
233         void build_world(World *world);
234         void build_rigidbody(Scene *scene);
235         void build_particles(Object *object);
236         void build_particle_settings(ParticleSettings *part);
237         void build_particles_visualization_object(Object *object,
238                                                   ParticleSystem *psys,
239                                                   Object *draw_object);
240         void build_cloth(Object *object, ModifierData *md);
241         void build_ik_pose(Object *object,
242                            bPoseChannel *pchan,
243                            bConstraint *con,
244                            RootPChanMap *root_map);
245         void build_splineik_pose(Object *object,
246                                  bPoseChannel *pchan,
247                                  bConstraint *con,
248                                  RootPChanMap *root_map);
249         void build_rig(Object *object);
250         void build_proxy_rig(Object *object);
251         void build_shapekeys(ID *obdata, Key *key);
252         void build_armature(bArmature *armature);
253         void build_camera(Camera *camera);
254         void build_lamp(Lamp *lamp);
255         void build_nodetree(bNodeTree *ntree);
256         void build_material(Material *ma);
257         void build_texture(Tex *tex);
258         void build_compositor(Scene *scene);
259         void build_gpencil(bGPdata *gpd);
260         void build_cachefile(CacheFile *cache_file);
261         void build_mask(Mask *mask);
262         void build_movieclip(MovieClip *clip);
263         void build_lightprobe(LightProbe *probe);
264
265         void build_nested_datablock(ID *owner, ID *id);
266         void build_nested_nodetree(ID *owner, bNodeTree *ntree);
267         void build_nested_shapekey(ID *owner, Key *key);
268
269         void add_collision_relations(const OperationKey &key,
270                                      Scene *scene,
271                                      Object *object,
272                                      Collection *collection,
273                                      bool dupli,
274                                      const char *name);
275         void add_forcefield_relations(const OperationKey &key,
276                                       Scene *scene,
277                                       Object *object,
278                                       ParticleSystem *psys,
279                                       EffectorWeights *eff,
280                                       bool add_absorption, const char *name);
281
282         void build_copy_on_write_relations();
283         void build_copy_on_write_relations(IDDepsNode *id_node);
284
285         template <typename KeyType>
286         OperationDepsNode *find_operation_node(const KeyType &key);
287
288         Depsgraph *getGraph();
289
290 protected:
291         TimeSourceDepsNode *get_node(const TimeSourceKey &key) const;
292         ComponentDepsNode *get_node(const ComponentKey &key) const;
293         OperationDepsNode *get_node(const OperationKey &key) const;
294         DepsNode *get_node(const RNAPathKey &key) const;
295
296         OperationDepsNode *find_node(const OperationKey &key) const;
297         bool has_node(const OperationKey &key) const;
298
299         DepsRelation *add_time_relation(TimeSourceDepsNode *timesrc,
300                                         DepsNode *node_to,
301                                         const char *description,
302                                         bool check_unique = false);
303         DepsRelation *add_operation_relation(OperationDepsNode *node_from,
304                                              OperationDepsNode *node_to,
305                                              const char *description,
306                                              bool check_unique = false);
307
308         template <typename KeyType>
309         DepsNodeHandle create_node_handle(const KeyType& key,
310                                           const char *default_name = "");
311
312         /* TODO(sergey): All those is_same* functions are to be generalized. */
313
314         /* Check whether two keys correponds to the same bone from same armature.
315          *
316          * This is used by drivers relations builder to avoid possible fake
317          * dependency cycle when one bone property drives another property of the
318          * same bone.
319          */
320         template <typename KeyFrom, typename KeyTo>
321         bool is_same_bone_dependency(const KeyFrom& key_from, const KeyTo& key_to);
322
323         /* Similar to above, but used to check whether driver is using node from
324          * the same node tree as a driver variable.
325          */
326         template <typename KeyFrom, typename KeyTo>
327         bool is_same_nodetree_node_dependency(const KeyFrom& key_from,
328                                               const KeyTo& key_to);
329
330         /* Similar to above, but used to check whether driver is using key from
331          * the same key datablock as a driver variable.
332          */
333         template <typename KeyFrom, typename KeyTo>
334         bool is_same_shapekey_dependency(const KeyFrom& key_from,
335                                          const KeyTo& key_to);
336
337 private:
338         struct BuilderWalkUserData {
339                 DepsgraphRelationBuilder *builder;
340         };
341
342         static void modifier_walk(void *user_data,
343                                   struct Object *object,
344                                   struct ID **idpoin,
345                                   int cb_flag);
346
347         static void constraint_walk(bConstraint *con,
348                                     ID **idpoin,
349                                     bool is_reference,
350                                     void *user_data);
351
352         /* State which never changes, same for the whole builder time. */
353         Main *bmain_;
354         Depsgraph *graph_;
355
356         /* State which demotes currently built entities. */
357         Scene *scene_;
358
359         BuilderMap built_map_;
360 };
361
362 struct DepsNodeHandle
363 {
364         DepsNodeHandle(DepsgraphRelationBuilder *builder,
365                        OperationDepsNode *node,
366                        const char *default_name = "")
367                 : builder(builder),
368                   node(node),
369                   default_name(default_name)
370         {
371                 BLI_assert(node != NULL);
372         }
373
374         DepsgraphRelationBuilder *builder;
375         OperationDepsNode *node;
376         const char *default_name;
377 };
378
379 }  // namespace DEG
380
381
382 #include "intern/builder/deg_builder_relations_impl.h"