Blender V5.3
deg_builder.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include <cstring>
12
13#include "DNA_ID.h"
14#include "DNA_armature_types.h"
15#include "DNA_layer_types.h"
16#include "DNA_modifier_types.h"
17#include "DNA_object_types.h"
18
19#include "BLI_string.hh"
20
21#include "BKE_action.hh"
22#include "BKE_collection.hh"
23#include "BKE_lib_id.hh"
24
25#include "RNA_prototypes.hh"
26
29#include "intern/depsgraph.hh"
37
38#include "DEG_depsgraph.hh"
39
40namespace blender::deg {
41
42bool deg_check_id_in_depsgraph(const Depsgraph *graph, ID *id_orig)
43{
44 IDNode *id_node = graph->find_id_node(id_orig);
45 return id_node != nullptr;
46}
47
49{
50 Object *object_orig = base->base_orig->object;
51 IDNode *id_node = graph->find_id_node(&object_orig->id);
52 if (id_node == nullptr) {
53 return false;
54 }
55 return id_node->has_base;
56}
57
58/* -------------------------------------------------------------------- */
61
63 : bmain_(bmain), graph_(graph), cache_(cache)
64{
65}
66
68{
69 /* Simple check: enabled bases are always part of dependency graph. */
70 const int base_flag = (graph_->mode == DAG_EVAL_VIEWPORT) ? BASE_ENABLED_VIEWPORT :
72
73 if (!graph_->use_visibility_optimization || (base->flag & base_flag)) {
74 return true;
75 }
76
77 /* More involved check: since we don't support dynamic changes in dependency graph topology and
78 * all visible objects are to be part of dependency graph, we pull all objects which has animated
79 * visibility. */
81}
82
84{
85 AnimatedPropertyID property_id;
87 property_id = AnimatedPropertyID(&object->id, RNA_Object, "hide_viewport");
88 }
89 else if (graph_->mode == DAG_EVAL_RENDER) {
90 property_id = AnimatedPropertyID(&object->id, RNA_Object, "hide_render");
91 }
92 else {
93 BLI_assert_msg(0, "Unknown evaluation mode.");
94 return false;
95 }
96 return cache_->isPropertyAnimated(&object->id, property_id);
97}
98
100 const ModifierData *modifier)
101{
102 AnimatedPropertyID property_id;
103 if (graph_->mode == DAG_EVAL_VIEWPORT) {
104 property_id = AnimatedPropertyID(&object->id, RNA_Modifier, (void *)modifier, "show_viewport");
105 }
106 else if (graph_->mode == DAG_EVAL_RENDER) {
107 property_id = AnimatedPropertyID(&object->id, RNA_Modifier, (void *)modifier, "show_render");
108 }
109 else {
110 BLI_assert_msg(0, "Unknown evaluation mode.");
111 return false;
112 }
113 return cache_->isPropertyAnimated(&object->id, property_id);
114}
115
117{
118 BLI_assert(object->type == OB_ARMATURE);
119 bArmature *armature = id_cast<bArmature *>(object->data);
120 if (pchan == nullptr) {
121 return false;
122 }
123 const Bone *bone = pchan->bone_get(*armature);
124 if (bone == nullptr) {
125 return false;
126 }
127 /* We don't really care whether segments are higher than 1 due to static user input (as in,
128 * rigger entered value like 3 manually), or due to animation. In either way we need to create
129 * special evaluation. */
130 if (bone->segments > 1) {
131 return true;
132 }
133 AnimatedPropertyID property_id(
134 &armature->id, RNA_Bone, const_cast<Bone *>(bone), "bbone_segments");
135 /* Check both Object and Armature animation data, because drivers modifying Armature
136 * state could easily be created in the Object AnimData. */
137 return cache_->isPropertyAnimated(&object->id, property_id) ||
138 cache_->isPropertyAnimated(&armature->id, property_id);
139}
140
142 const bPoseChannel *pchan)
143{
144 return check_pchan_has_bbone(object, pchan);
145}
146
147bool DepsgraphBuilder::check_pchan_has_bbone_segments(const Object *object, const char *bone_name)
148{
149 const bPoseChannel *pchan = BKE_pose_channel_find_name(object->pose, bone_name);
150 return check_pchan_has_bbone_segments(object, pchan);
151}
152
154 const PointerRNA &target_prop,
155 const char *rna_path)
156{
157 if (rna_path == nullptr || target_prop.data != scene || target_prop.type != RNA_Scene ||
158 !BLI_str_startswith(rna_path, "camera"))
159 {
160 return nullptr;
161 }
162
163 /* Return the part of the path relative to the camera. */
164 switch (rna_path[6]) {
165 case '.':
166 return rna_path + 7;
167 case '[':
168 return rna_path + 6;
169 default:
170 return nullptr;
171 }
172}
173
175
176/* -------------------------------------------------------------------- */
179
181{
184
185 /* Re-tag IDs for update if it was tagged before the relations
186 * update tag. */
187 for (IDNode *id_node : graph->id_nodes) {
188 const ID_Type id_type = id_node->id_type;
189 ID *id_orig = id_node->id_orig;
190 id_node->finalize_build(graph);
191 int flag = 0;
192 /* Tag rebuild if special evaluation flags changed. */
193 if (id_node->eval_flags != id_node->previous_eval_flags) {
195 }
196 /* Tag rebuild if the custom data mask changed. */
197 if (id_node->customdata_masks != id_node->previous_customdata_masks) {
198 flag |= ID_RECALC_GEOMETRY;
199 }
200 const bool is_expanded = deg_eval_copy_is_expanded(id_node->id_cow);
201 if (!is_expanded) {
203 /* This means ID is being added to the dependency graph first
204 * time, which is similar to "ob-visible-change" */
205 if (id_type == ID_OB) {
207 }
208 if (id_type == ID_NT) {
210 }
211 if (id_type == ID_SCE) {
212 flag |= ID_RECALC_COMPOSITOR;
213 }
214 }
215 else {
216 if (id_type == ID_GR) {
217 /* Collection content might have changed (children collection might have been added or
218 * removed from the graph based on their inclusion and visibility flags). */
220 nullptr, reinterpret_cast<Collection *>(id_node->id_cow), LIB_ID_CREATE_NO_DEG_TAG);
221 }
222 else if (id_type == ID_SCE) {
223 /* During undo the sequence strips might obtain a new session ID, which will disallow the
224 * audio handles to be re-used. Tag for the audio and sequence update to ensure the audio
225 * handles are open.
226 * NOTE: This is not something that should be required, and perhaps indicates a weakness in
227 * design somewhere else. For the cause of the problem check #117760. */
229 }
230 }
231 /* Restore recalc flags from original ID, which could possibly contain recalc flags set by
232 * an operator and then were carried on by the undo system.
233 *
234 * Only do it for active dependency graph, because otherwise modifications to the original
235 * objects might keep affecting the render pipeline. For example, when a Python script is
236 * executed in headless mode it will tag original objects for recalculation, and the flag
237 * will never be reset to 0 because there is no active dependency graph (since the
238 * DEG_ids_clear_recalc() only clears original ID recalc flags for the active depsgraph).
239 *
240 * A bit of a safety is to also consider the accumulated recalc flags from the original
241 * data-block for the first evaluation of the data-block within an inactive graph. */
242 if (graph->is_active || !is_expanded) {
243 flag |= id_orig->recalc;
244 }
245 if (flag != 0) {
246 graph_id_tag_update(bmain, graph, id_node->id_orig, flag, DEG_UPDATE_SOURCE_RELATIONS);
247 }
248 }
249}
250
252
253} // namespace blender::deg
Blender kernel action and pose functionality.
ID and Library types, which are fundamental for SDNA.
Object is a sort of wrapper for general info.
#define BLI_assert_msg(a, msg)
bool isPropertyAnimated(const ID *id, Args... args)
DepsgraphBuilderCache * cache_
Definition deg_builder.h:55
virtual bool check_pchan_has_bbone_segments(const Object *object, const bPoseChannel *pchan)
virtual bool need_pull_base_into_graph(const Base *base)
virtual bool check_pchan_has_bbone(const Object *object, const bPoseChannel *pchan)
virtual bool is_object_visibility_animated(const Object *object)
static const char * get_rna_path_relative_to_scene_camera(const Scene *scene, const PointerRNA &target_prop, const char *rna_path)
DepsgraphBuilder(Main *bmain, Depsgraph *graph, DepsgraphBuilderCache *cache)
virtual bool is_modifier_visibility_animated(const Object *object, const ModifierData *modifier)
void deg_graph_remove_unused_noops(Depsgraph *graph)
bool deg_check_base_in_depsgraph(const Depsgraph *graph, Base *base)
bool deg_eval_copy_is_expanded(const ID *id_cow)
void deg_graph_flush_visibility_flags(Depsgraph *graph)
void deg_graph_build_finalize(Main *bmain, Depsgraph *graph)
bool deg_check_id_in_depsgraph(const Depsgraph *graph, ID *id_orig)
void graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, uint flags, eUpdateSource update_source)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ BASE_ENABLED_VIEWPORT
void BKE_collection_object_cache_free(const Main *bmain, Collection *collection, const int id_create_flag)
@ LIB_ID_CREATE_NO_DEG_TAG
@ DAG_EVAL_VIEWPORT
int bool BLI_str_startswith(const char *__restrict str, const char *__restrict start) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
@ ID_RECALC_AUDIO
Definition DNA_ID.h:1132
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_SEQUENCER_STRIPS
Definition DNA_ID.h:1122
@ ID_RECALC_COMPOSITOR
Definition DNA_ID.h:1161
@ ID_RECALC_NTREE_OUTPUT
Definition DNA_ID.h:1155
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
struct Object * object
struct Base * base_orig
unsigned int recalc
Definition DNA_ID.h:446
StructRNA * type
Definition RNA_types.hh:63
IDNode * find_id_node(const ID *id) const
Definition depsgraph.cc:102
eEvaluationMode mode
Definition depsgraph.hh:145
DEGCustomDataMeshMasks customdata_masks
DEGCustomDataMeshMasks previous_customdata_masks
void finalize_build(Depsgraph *graph)
uint32_t previous_eval_flags