Blender  V2.93
deg_builder.cc
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) 2016 Blender Foundation.
17  * All rights reserved.
18  */
19 
25 
26 #include <cstring>
27 
28 #include "DNA_ID.h"
29 #include "DNA_anim_types.h"
30 #include "DNA_armature_types.h"
31 #include "DNA_layer_types.h"
32 #include "DNA_object_types.h"
33 
34 #include "BLI_stack.h"
35 #include "BLI_utildefines.h"
36 
37 #include "BKE_action.h"
38 
41 #include "intern/depsgraph.h"
43 #include "intern/depsgraph_tag.h"
44 #include "intern/depsgraph_type.h"
46 #include "intern/node/deg_node.h"
50 
51 #include "DEG_depsgraph.h"
52 
53 namespace blender::deg {
54 
56 {
57  IDNode *id_node = graph->find_id_node(id_orig);
58  return id_node != nullptr;
59 }
60 
62 {
63  Object *object_orig = base->base_orig->object;
64  IDNode *id_node = graph->find_id_node(&object_orig->id);
65  if (id_node == nullptr) {
66  return false;
67  }
68  return id_node->has_base;
69 }
70 
71 /*******************************************************************************
72  * Base class for builders.
73  */
74 
76  : bmain_(bmain), graph_(graph), cache_(cache)
77 {
78 }
79 
81 {
82  /* Simple check: enabled bases are always part of dependency graph. */
83  const int base_flag = (graph_->mode == DAG_EVAL_VIEWPORT) ? BASE_ENABLED_VIEWPORT :
85  if (base->flag & base_flag) {
86  return true;
87  }
88  /* More involved check: since we don't support dynamic changes in dependency graph topology and
89  * all visible objects are to be part of dependency graph, we pull all objects which has animated
90  * visibility. */
91  Object *object = base->object;
92  AnimatedPropertyID property_id;
93  if (graph_->mode == DAG_EVAL_VIEWPORT) {
94  property_id = AnimatedPropertyID(&object->id, &RNA_Object, "hide_viewport");
95  }
96  else if (graph_->mode == DAG_EVAL_RENDER) {
97  property_id = AnimatedPropertyID(&object->id, &RNA_Object, "hide_render");
98  }
99  else {
100  BLI_assert(!"Unknown evaluation mode.");
101  return false;
102  }
103  return cache_->isPropertyAnimated(&object->id, property_id);
104 }
105 
107 {
108  BLI_assert(object->type == OB_ARMATURE);
109  if (pchan == nullptr || pchan->bone == nullptr) {
110  return false;
111  }
112  /* We don't really care whether segments are higher than 1 due to static user input (as in,
113  * rigger entered value like 3 manually), or due to animation. In either way we need to create
114  * special evaluation. */
115  if (pchan->bone->segments > 1) {
116  return true;
117  }
118  bArmature *armature = static_cast<bArmature *>(object->data);
119  AnimatedPropertyID property_id(&armature->id, &RNA_Bone, pchan->bone, "bbone_segments");
120  /* Check both Object and Armature animation data, because drivers modifying Armature
121  * state could easily be created in the Object AnimData. */
122  return cache_->isPropertyAnimated(&object->id, property_id) ||
123  cache_->isPropertyAnimated(&armature->id, property_id);
124 }
125 
127 {
128  /* Proxies don't have BONE_SEGMENTS */
129  if (ID_IS_LINKED(object) && object->proxy_from != nullptr) {
130  return false;
131  }
132  return check_pchan_has_bbone(object, pchan);
133 }
134 
135 bool DepsgraphBuilder::check_pchan_has_bbone_segments(Object *object, const char *bone_name)
136 {
137  const bPoseChannel *pchan = BKE_pose_channel_find_name(object->pose, bone_name);
138  return check_pchan_has_bbone_segments(object, pchan);
139 }
140 
141 /*******************************************************************************
142  * Builder finalizer.
143  */
144 
145 namespace {
146 
147 void deg_graph_build_flush_visibility(Depsgraph *graph)
148 {
149  enum {
150  DEG_NODE_VISITED = (1 << 0),
151  };
152 
153  BLI_Stack *stack = BLI_stack_new(sizeof(OperationNode *), "DEG flush layers stack");
154  for (IDNode *id_node : graph->id_nodes) {
155  for (ComponentNode *comp_node : id_node->components.values()) {
156  comp_node->affects_directly_visible |= id_node->is_directly_visible;
157  }
158  }
159  for (OperationNode *op_node : graph->operations) {
160  op_node->custom_flags = 0;
161  op_node->num_links_pending = 0;
162  for (Relation *rel : op_node->outlinks) {
163  if ((rel->from->type == NodeType::OPERATION) && (rel->flag & RELATION_FLAG_CYCLIC) == 0) {
164  ++op_node->num_links_pending;
165  }
166  }
167  if (op_node->num_links_pending == 0) {
168  BLI_stack_push(stack, &op_node);
169  op_node->custom_flags |= DEG_NODE_VISITED;
170  }
171  }
172  while (!BLI_stack_is_empty(stack)) {
173  OperationNode *op_node;
174  BLI_stack_pop(stack, &op_node);
175  /* Flush layers to parents. */
176  for (Relation *rel : op_node->inlinks) {
177  if (rel->from->type == NodeType::OPERATION) {
178  OperationNode *op_from = (OperationNode *)rel->from;
179  op_from->owner->affects_directly_visible |= op_node->owner->affects_directly_visible;
180  }
181  }
182  /* Schedule parent nodes. */
183  for (Relation *rel : op_node->inlinks) {
184  if (rel->from->type == NodeType::OPERATION) {
185  OperationNode *op_from = (OperationNode *)rel->from;
186  if ((rel->flag & RELATION_FLAG_CYCLIC) == 0) {
187  BLI_assert(op_from->num_links_pending > 0);
188  --op_from->num_links_pending;
189  }
190  if ((op_from->num_links_pending == 0) && (op_from->custom_flags & DEG_NODE_VISITED) == 0) {
191  BLI_stack_push(stack, &op_from);
192  op_from->custom_flags |= DEG_NODE_VISITED;
193  }
194  }
195  }
196  }
197  BLI_stack_free(stack);
198 }
199 
200 } // namespace
201 
203 {
204  /* Make sure dependencies of visible ID datablocks are visible. */
205  deg_graph_build_flush_visibility(graph);
207 
208  /* Re-tag IDs for update if it was tagged before the relations
209  * update tag. */
210  for (IDNode *id_node : graph->id_nodes) {
211  ID *id_orig = id_node->id_orig;
213  int flag = 0;
214  /* Tag rebuild if special evaluation flags changed. */
217  }
218  /* Tag rebuild if the custom data mask changed. */
220  flag |= ID_RECALC_GEOMETRY;
221  }
223  flag |= ID_RECALC_COPY_ON_WRITE;
224  /* This means ID is being added to the dependency graph first
225  * time, which is similar to "ob-visible-change" */
226  if (GS(id_orig->name) == ID_OB) {
228  }
229  }
230  /* Restore recalc flags from original ID, which could possibly contain recalc flags set by
231  * an operator and then were carried on by the undo system. */
232  flag |= id_orig->recalc;
233  if (flag != 0) {
235  }
236  }
237 }
238 
239 } // namespace blender::deg
Blender kernel action and pose functionality.
struct bPoseChannel * BKE_pose_channel_find_name(const struct bPose *pose, const char *name)
#define BLI_assert(a)
Definition: BLI_assert.h:58
void BLI_stack_pop(BLI_Stack *stack, void *dst) ATTR_NONNULL()
Definition: stack.c:175
void BLI_stack_push(BLI_Stack *stack, const void *src) ATTR_NONNULL()
Definition: stack.c:163
bool BLI_stack_is_empty(const BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: stack.c:310
void BLI_stack_free(BLI_Stack *stack) ATTR_NONNULL()
Definition: stack.c:114
#define BLI_stack_new(esize, descr)
@ DAG_EVAL_RENDER
Definition: DEG_depsgraph.h:62
@ DAG_EVAL_VIEWPORT
Definition: DEG_depsgraph.h:61
ID and Library types, which are fundamental for sdna.
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:599
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
@ ID_OB
Definition: DNA_ID_enums.h:59
@ BASE_ENABLED_RENDER
@ BASE_ENABLED_VIEWPORT
Object is a sort of wrapper for general info.
@ OB_ARMATURE
StructRNA RNA_Bone
StructRNA RNA_Object
bool isPropertyAnimated(ID *id, Args... args)
DepsgraphBuilderCache * cache_
Definition: deg_builder.h:55
virtual bool check_pchan_has_bbone(Object *object, const bPoseChannel *pchan)
Definition: deg_builder.cc:106
virtual bool check_pchan_has_bbone_segments(Object *object, const bPoseChannel *pchan)
Definition: deg_builder.cc:126
virtual bool need_pull_base_into_graph(Base *base)
Definition: deg_builder.cc:80
DepsgraphBuilder(Main *bmain, Depsgraph *graph, DepsgraphBuilderCache *cache)
Definition: deg_builder.cc:75
Depsgraph * graph
const IDNode * id_node
#define GS(x)
Definition: iris.c:241
void deg_graph_remove_unused_noops(Depsgraph *graph)
bool deg_check_base_in_depsgraph(const Depsgraph *graph, Base *base)
Definition: deg_builder.cc:61
void deg_graph_build_finalize(Main *bmain, Depsgraph *graph)
Definition: deg_builder.cc:202
bool deg_copy_on_write_is_expanded(const ID *id_cow)
void graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag, eUpdateSource update_source)
bool deg_check_id_in_depsgraph(const Depsgraph *graph, ID *id_orig)
Definition: deg_builder.cc:55
@ DEG_UPDATE_SOURCE_RELATIONS
short flag
struct Object * object
struct Base * base_orig
short segments
Definition: DNA_ID.h:273
int recalc
Definition: DNA_ID.h:295
char name[66]
Definition: DNA_ID.h:283
Definition: BKE_main.h:116
struct bPose * pose
struct Object * proxy_from
struct Bone * bone
IDNode * find_id_node(const ID *id) const
Definition: depsgraph.cc:112
OperationNodes operations
Definition: depsgraph.h:126
eEvaluationMode mode
Definition: depsgraph.h:136
IDDepsNodes id_nodes
Definition: depsgraph.h:103
DEGCustomDataMeshMasks customdata_masks
Definition: deg_node_id.h:105
DEGCustomDataMeshMasks previous_customdata_masks
Definition: deg_node_id.h:106
Map< ComponentIDKey, ComponentNode * > components
Definition: deg_node_id.h:96
void finalize_build(Depsgraph *graph)
Definition: deg_node_id.cc:195
uint32_t previous_eval_flags
Definition: deg_node_id.h:102