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