Depsgraph: Object data separation, armature
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_nodes.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_nodes.h
28  *  \ingroup depsgraph
29  */
30
31 #pragma once
32
33 #include "intern/builder/deg_builder_map.h"
34 #include "intern/depsgraph_types.h"
35
36 #include "DEG_depsgraph.h"
37
38 struct Base;
39 struct bArmature;
40 struct CacheFile;
41 struct Camera;
42 struct bGPdata;
43 struct ListBase;
44 struct GHash;
45 struct ID;
46 struct Image;
47 struct FCurve;
48 struct Collection;
49 struct Key;
50 struct Lamp;
51 struct LayerCollection;
52 struct LightProbe;
53 struct Main;
54 struct Material;
55 struct Mask;
56 struct MTex;
57 struct MovieClip;
58 struct bNodeTree;
59 struct Object;
60 struct ParticleSettings;
61 struct Probe;
62 struct bPoseChannel;
63 struct bConstraint;
64 struct Scene;
65 struct Tex;
66 struct World;
67
68 struct PropertyRNA;
69
70 namespace DEG {
71
72 struct Depsgraph;
73 struct DepsNode;
74 struct IDDepsNode;
75 struct TimeSourceDepsNode;
76 struct ComponentDepsNode;
77 struct OperationDepsNode;
78
79 struct DepsgraphNodeBuilder {
80         DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph);
81         ~DepsgraphNodeBuilder();
82
83         /* For given original ID get ID which is created by CoW system. */
84         ID *get_cow_id(const ID *id_orig) const;
85         /* Similar to above, but for the cases when there is no ID node we create
86          * one.
87          */
88         ID *ensure_cow_id(ID *id_orig);
89
90         /* Helper wrapper function which wraps get_cow_id with a needed type cast. */
91         template<typename T>
92         T *get_cow_datablock(const T *orig) const {
93                 return (T *)get_cow_id(&orig->id);
94         }
95
96         /* For a given COW datablock get corresponding original one. */
97         template<typename T>
98         T *get_orig_datablock(const T *cow) const {
99                 return (T *)cow->id.orig_id;
100         }
101
102         void begin_build();
103         void end_build();
104
105         IDDepsNode *add_id_node(ID *id);
106         IDDepsNode *find_id_node(ID *id);
107         TimeSourceDepsNode *add_time_source();
108
109         ComponentDepsNode *add_component_node(ID *id,
110                                               eDepsNode_Type comp_type,
111                                               const char *comp_name = "");
112
113         OperationDepsNode *add_operation_node(ComponentDepsNode *comp_node,
114                                               const DepsEvalOperationCb& op,
115                                               eDepsOperation_Code opcode,
116                                               const char *name = "",
117                                               int name_tag = -1);
118         OperationDepsNode *add_operation_node(ID *id,
119                                               eDepsNode_Type comp_type,
120                                               const char *comp_name,
121                                               const DepsEvalOperationCb& op,
122                                               eDepsOperation_Code opcode,
123                                               const char *name = "",
124                                               int name_tag = -1);
125         OperationDepsNode *add_operation_node(ID *id,
126                                               eDepsNode_Type comp_type,
127                                               const DepsEvalOperationCb& op,
128                                               eDepsOperation_Code opcode,
129                                               const char *name = "",
130                                               int name_tag = -1);
131
132         OperationDepsNode *ensure_operation_node(ID *id,
133                                                  eDepsNode_Type comp_type,
134                                                  const DepsEvalOperationCb& op,
135                                                  eDepsOperation_Code opcode,
136                                                  const char *name = "",
137                                                  int name_tag = -1);
138
139         bool has_operation_node(ID *id,
140                                 eDepsNode_Type comp_type,
141                                 const char *comp_name,
142                                 eDepsOperation_Code opcode,
143                                 const char *name = "",
144                                 int name_tag = -1);
145
146         OperationDepsNode *find_operation_node(ID *id,
147                                                eDepsNode_Type comp_type,
148                                                const char *comp_name,
149                                                eDepsOperation_Code opcode,
150                                                const char *name = "",
151                                                int name_tag = -1);
152
153         OperationDepsNode *find_operation_node(ID *id,
154                                                eDepsNode_Type comp_type,
155                                                eDepsOperation_Code opcode,
156                                                const char *name = "",
157                                                int name_tag = -1);
158
159         void build_id(ID* id);
160         void build_layer_collections(ListBase *lb);
161         void build_view_layer(Scene *scene,
162                                ViewLayer *view_layer,
163                                eDepsNode_LinkedState_Type linked_state);
164         void build_collection(Collection *collection);
165         void build_object(int base_index,
166                           Object *object,
167                           eDepsNode_LinkedState_Type linked_state);
168         void build_object_flags(int base_index,
169                                 Object *object,
170                                 eDepsNode_LinkedState_Type linked_state);
171         void build_object_data(Object *object);
172         void build_object_data_camera(Object *object);
173         void build_object_data_geometry(Object *object);
174         void build_object_data_geometry_datablock(ID *obdata);
175         void build_object_data_lamp(Object *object);
176         void build_object_data_lightprobe(Object *object);
177         void build_object_transform(Object *object);
178         void build_object_constraints(Object *object);
179         void build_pose_constraints(Object *object, bPoseChannel *pchan, int pchan_index);
180         void build_rigidbody(Scene *scene);
181         void build_particles(Object *object);
182         void build_particle_settings(ParticleSettings *part);
183         void build_cloth(Object *object);
184         void build_animdata(ID *id);
185         void build_driver(ID *id, FCurve *fcurve, int driver_index);
186         void build_driver_variables(ID *id, FCurve *fcurve);
187         void build_driver_id_property(ID *id, const char *rna_path);
188         void build_ik_pose(Object *object,
189                            bPoseChannel *pchan,
190                            bConstraint *con);
191         void build_splineik_pose(Object *object,
192                                  bPoseChannel *pchan,
193                                  bConstraint *con);
194         void build_rig(Object *object);
195         void build_proxy_rig(Object *object);
196         void build_armature(bArmature *armature);
197         void build_shapekeys(Key *key);
198         void build_camera(Camera *camera);
199         void build_lamp(Lamp *lamp);
200         void build_nodetree(bNodeTree *ntree);
201         void build_material(Material *ma);
202         void build_texture(Tex *tex);
203         void build_image(Image *image);
204         void build_world(World *world);
205         void build_compositor(Scene *scene);
206         void build_gpencil(bGPdata *gpd);
207         void build_cachefile(CacheFile *cache_file);
208         void build_mask(Mask *mask);
209         void build_movieclip(MovieClip *clip);
210         void build_lightprobe(LightProbe *probe);
211
212 protected:
213         struct SavedEntryTag {
214                 ID *id;
215                 eDepsNode_Type component_type;
216                 eDepsOperation_Code opcode;
217         };
218         vector<SavedEntryTag> saved_entry_tags_;
219
220         struct BuilderWalkUserData {
221                 DepsgraphNodeBuilder *builder;
222         };
223
224         static void modifier_walk(void *user_data,
225                                   struct Object *object,
226                                   struct ID **idpoin,
227                                   int cb_flag);
228
229         static void constraint_walk(bConstraint *constraint,
230                                     ID **idpoin,
231                                     bool is_reference,
232                                     void *user_data);
233
234         /* State which never changes, same for the whole builder time. */
235         Main *bmain_;
236         Depsgraph *graph_;
237
238         /* State which demotes currently built entities. */
239         Scene *scene_;
240         ViewLayer *view_layer_;
241         int view_layer_index_;
242
243         GHash *cow_id_hash_;
244         BuilderMap built_map_;
245 };
246
247 }  // namespace DEG