Blender  V2.93
DEG_depsgraph_query.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
26 #pragma once
27 
28 #include "BLI_iterator.h"
29 
30 #include "DEG_depsgraph.h"
31 #include "DEG_depsgraph_build.h"
32 
33 /* Needed for the instance iterator. */
34 #include "DNA_object_types.h"
35 
36 struct BLI_Iterator;
38 struct Depsgraph;
39 struct DupliObject;
40 struct ID;
41 struct ListBase;
42 struct PointerRNA;
43 struct Scene;
44 struct ViewLayer;
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /* *********************** DEG input data ********************* */
51 
52 /* Get scene that depsgraph was built for. */
54 
55 /* Get view layer that depsgraph was built for. */
57 
58 /* Get bmain that depsgraph was built for. */
59 struct Main *DEG_get_bmain(const Depsgraph *graph);
60 
61 /* Get evaluation mode that depsgraph was built for. */
63 
64 /* Get time that depsgraph is being evaluated or was last evaluated at. */
65 float DEG_get_ctime(const Depsgraph *graph);
66 
67 /* ********************* DEG evaluated data ******************* */
68 
69 /* Check if given ID type was tagged for update. */
70 bool DEG_id_type_updated(const struct Depsgraph *depsgraph, short id_type);
72 
73 /* Check if given ID type is present in the depsgraph */
74 bool DEG_id_type_any_exists(const struct Depsgraph *depsgraph, short id_type);
75 
76 /* Get additional evaluation flags for the given ID. */
78 
79 /* Get additional mesh CustomData_MeshMasks flags for the given object. */
81  struct Object *object,
82  struct CustomData_MeshMasks *r_mask);
83 
84 /* Get scene at its evaluated state.
85  *
86  * Technically, this is a copied-on-written and fully evaluated version of the input scene.
87  * This function will check that the data-block has been expanded (and copied) from the original
88  * one. Assert will happen if it's not. */
90 
91 /* Get view layer at its evaluated state.
92  * This is a shortcut for accessing active view layer from evaluated scene. */
94 
95 /* Get evaluated version of object for given original one. */
96 struct Object *DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object);
97 
98 /* Get evaluated version of given ID datablock. */
99 struct ID *DEG_get_evaluated_id(const struct Depsgraph *depsgraph, struct ID *id);
100 
101 /* Get evaluated version of data pointed to by RNA pointer */
103  struct PointerRNA *ptr,
104  struct PointerRNA *r_ptr_eval);
105 
106 /* Get original version of object for given evaluated one. */
107 struct Object *DEG_get_original_object(struct Object *object);
108 
109 /* Get original version of given evaluated ID datablock. */
110 struct ID *DEG_get_original_id(struct ID *id);
111 
112 /* Check whether given ID is an original,
113  *
114  * Original IDs are considered all the IDs which are not covered by copy-on-write system and are
115  * not out-of-main localized data-blocks. */
116 bool DEG_is_original_id(const struct ID *id);
117 bool DEG_is_original_object(const struct Object *object);
118 
119 /* Opposite of the above.
120  *
121  * If the data-block is not original it must be evaluated, and vice versa. */
122 bool DEG_is_evaluated_id(const struct ID *id);
123 bool DEG_is_evaluated_object(const struct Object *object);
124 
125 /* Check whether depsgraph os fully evaluated. This includes the following checks:
126  * - Relations are up-to-date.
127  * - Nothing is tagged for update. */
128 bool DEG_is_fully_evaluated(const struct Depsgraph *depsgraph);
129 
130 /* ************************ DEG object iterators ********************* */
131 
132 enum {
138 };
139 
140 typedef struct DEGObjectIterData {
141  struct Depsgraph *graph;
142  int flag;
143 
144  struct Scene *scene;
145 
147 
148  /* **** Iteration over geometry components **** */
149 
150  /* The object whose components we currently iterate over.
151  * This might point to #temp_dupli_object. */
153  /* Some identifier that is used to determine which geometry component should be returned next. */
155  /* Temporary storage for an object that is created from a component. */
157 
158  /* **** Iteration over dupli-list. *** */
159 
160  /* Object which created the dupli-list. */
162  /* List of duplicated objects. */
164  /* Next duplicated object to step into. */
166  /* Corresponds to current object: current iterator object is evaluated from
167  * this duplicated object. */
169  /* Temporary storage to report fully populated DNA to the render engine or
170  * other users of the iterator. */
171  struct Object temp_dupli_object;
172 
173  /* **** Iteration over ID nodes **** */
175  size_t num_id_nodes;
177 
179 void DEG_iterator_objects_next(struct BLI_Iterator *iter);
180 void DEG_iterator_objects_end(struct BLI_Iterator *iter);
181 
187 #define DEG_OBJECT_ITER_BEGIN(graph_, instance_, flag_) \
188  { \
189  DEGObjectIterData data_ = { \
190  graph_, \
191  flag_, \
192  }; \
193 \
194  ITER_BEGIN (DEG_iterator_objects_begin, \
195  DEG_iterator_objects_next, \
196  DEG_iterator_objects_end, \
197  &data_, \
198  Object *, \
199  instance_)
200 
201 #define DEG_OBJECT_ITER_END \
202  ITER_END; \
203  } \
204  ((void)0)
205 
209 #define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(graph_, instance_) \
210  DEG_OBJECT_ITER_BEGIN (graph_, \
211  instance_, \
212  DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | \
213  DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET | DEG_ITER_OBJECT_FLAG_VISIBLE | \
214  DEG_ITER_OBJECT_FLAG_DUPLI)
215 
216 #define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END DEG_OBJECT_ITER_END
217 
218 /* ************************ DEG ID iterators ********************* */
219 
220 typedef struct DEGIDIterData {
221  struct Depsgraph *graph;
223 
225  size_t num_id_nodes;
227 
229 void DEG_iterator_ids_next(struct BLI_Iterator *iter);
231 
232 /* ************************ DEG traversal ********************* */
233 
234 typedef void (*DEGForeachIDCallback)(ID *id, void *user_data);
237  void *user_data);
238 
239 /* NOTE: Modifies runtime flags in depsgraph nodes, so can not be used in
240  * parallel. Keep an eye on that!
241  */
243  const ID *id,
245  void *user_data);
247  const ID *id,
249  void *user_data);
250 
251 /* Starts traversal from given component of the given ID, invokes callback for every other
252  * component which is directly on indirectly dependent on the source one. */
253 enum {
254  /* Ignore transform solvers which depends on multiple inputs and affects final transform.
255  * Is used for cases like snapping objects which are part of a rigid body simulation:
256  * without this there will be "false-positive" dependencies between transform components of
257  * objects:
258  *
259  * object 1 transform before solver ---> solver ------> object 1 final transform
260  * object 2 transform before solver -----^ \------> object 2 final transform
261  */
263 };
265  const ID *id,
266  eDepsObjectComponentType source_component_type,
267  int flags,
269  void *user_data);
270 
272 
273 #ifdef __cplusplus
274 } /* extern "C" */
275 #endif
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:126
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
eEvaluationMode
Definition: DEG_depsgraph.h:60
eDepsObjectComponentType
void DEG_iterator_objects_next(struct BLI_Iterator *iter)
float DEG_get_ctime(const Depsgraph *graph)
void DEG_foreach_dependent_ID_component(const Depsgraph *depsgraph, const ID *id, eDepsObjectComponentType source_component_type, int flags, DEGForeachIDComponentCallback callback, void *user_data)
struct Scene * DEG_get_input_scene(const Depsgraph *graph)
void DEG_iterator_ids_begin(struct BLI_Iterator *iter, DEGIDIterData *data)
@ DEG_FOREACH_COMPONENT_IGNORE_TRANSFORM_SOLVERS
bool DEG_is_fully_evaluated(const struct Depsgraph *depsgraph)
bool DEG_id_type_any_exists(const struct Depsgraph *depsgraph, short id_type)
struct DEGIDIterData DEGIDIterData
void DEG_get_evaluated_rna_pointer(const struct Depsgraph *depsgraph, struct PointerRNA *ptr, struct PointerRNA *r_ptr_eval)
void DEG_foreach_ID(const Depsgraph *depsgraph, DEGForeachIDCallback callback, void *user_data)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
bool DEG_id_type_any_updated(const struct Depsgraph *depsgraph)
void DEG_iterator_ids_end(struct BLI_Iterator *iter)
struct Object * DEG_get_original_object(struct Object *object)
bool DEG_is_original_object(const struct Object *object)
uint32_t DEG_get_eval_flags_for_id(const struct Depsgraph *graph, struct ID *id)
bool DEG_is_original_id(const struct ID *id)
struct ID * DEG_get_evaluated_id(const struct Depsgraph *depsgraph, struct ID *id)
bool DEG_is_evaluated_object(const struct Object *object)
void DEG_foreach_dependent_ID(const Depsgraph *depsgraph, const ID *id, DEGForeachIDCallback callback, void *user_data)
struct ViewLayer * DEG_get_evaluated_view_layer(const struct Depsgraph *graph)
void DEG_iterator_objects_end(struct BLI_Iterator *iter)
struct ID * DEG_get_original_id(struct ID *id)
bool DEG_is_evaluated_id(const struct ID *id)
void DEG_iterator_objects_begin(struct BLI_Iterator *iter, DEGObjectIterData *data)
void DEG_iterator_ids_next(struct BLI_Iterator *iter)
struct Main * DEG_get_bmain(const Depsgraph *graph)
void(* DEGForeachIDComponentCallback)(ID *id, eDepsObjectComponentType component, void *user_data)
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
@ DEG_ITER_OBJECT_FLAG_VISIBLE
@ DEG_ITER_OBJECT_FLAG_DUPLI
@ DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
struct ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
bool DEG_id_type_updated(const struct Depsgraph *depsgraph, short id_type)
void(* DEGForeachIDCallback)(ID *id, void *user_data)
void DEG_get_customdata_mask_for_object(const struct Depsgraph *graph, struct Object *object, struct CustomData_MeshMasks *r_mask)
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
void DEG_foreach_ancestor_ID(const Depsgraph *depsgraph, const ID *id, DEGForeachIDCallback callback, void *user_data)
struct DEGObjectIterData DEGObjectIterData
struct Scene * DEG_get_evaluated_scene(const struct Depsgraph *graph)
Object is a sort of wrapper for general info.
Depsgraph * graph
const Depsgraph * depsgraph
void * user_data
DEGForeachIDComponentCallback callback
unsigned int uint32_t
Definition: stdint.h:83
struct Depsgraph * graph
eEvaluationMode eval_mode
struct Object temp_geometry_component_object
struct Object temp_dupli_object
struct Object * geometry_component_owner
struct Depsgraph * graph
struct DupliObject * dupli_object_next
struct Object * dupli_parent
struct ListBase * dupli_list
struct DupliObject * dupli_object_current
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
PointerRNA * ptr
Definition: wm_files.c:3157