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