Blender  V2.93
deg_builder_relations_impl.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 
24 #pragma once
25 
27 
28 #include "DNA_ID.h"
29 #include "DNA_object_types.h"
30 #include "DNA_rigidbody_types.h"
31 
32 namespace blender {
33 namespace deg {
34 
35 template<typename KeyType>
37 {
38  Node *node = get_node(key);
39  return node != nullptr ? node->get_exit_operation() : nullptr;
40 }
41 
42 template<typename KeyFrom, typename KeyTo>
44  const KeyTo &key_to,
45  const char *description,
46  int flags)
47 {
48  Node *node_from = get_node(key_from);
49  Node *node_to = get_node(key_to);
50  OperationNode *op_from = node_from ? node_from->get_exit_operation() : nullptr;
51  OperationNode *op_to = node_to ? node_to->get_entry_operation() : nullptr;
52  if (op_from && op_to) {
53  return add_operation_relation(op_from, op_to, description, flags);
54  }
55  else {
56  if (!op_from) {
57  /* XXX TODO handle as error or report if needed */
58  fprintf(stderr,
59  "add_relation(%s) - Could not find op_from (%s)\n",
60  description,
61  key_from.identifier().c_str());
62  }
63  else {
64  fprintf(stderr,
65  "add_relation(%s) - Failed, but op_from (%s) was ok\n",
66  description,
67  key_from.identifier().c_str());
68  }
69  if (!op_to) {
70  /* XXX TODO handle as error or report if needed */
71  fprintf(stderr,
72  "add_relation(%s) - Could not find op_to (%s)\n",
73  description,
74  key_to.identifier().c_str());
75  }
76  else {
77  fprintf(stderr,
78  "add_relation(%s) - Failed, but op_to (%s) was ok\n",
79  description,
80  key_to.identifier().c_str());
81  }
82  }
83  return nullptr;
84 }
85 
86 template<typename KeyTo>
88  const KeyTo &key_to,
89  const char *description,
90  int flags)
91 {
92  TimeSourceNode *time_from = get_node(key_from);
93  Node *node_to = get_node(key_to);
94  OperationNode *op_to = node_to ? node_to->get_entry_operation() : nullptr;
95  if (time_from != nullptr && op_to != nullptr) {
96  return add_time_relation(time_from, op_to, description, flags);
97  }
98  return nullptr;
99 }
100 
101 template<typename KeyType>
103  const DepsNodeHandle *handle,
104  const char *description,
105  int flags)
106 {
107  Node *node_from = get_node(key_from);
108  OperationNode *op_from = node_from ? node_from->get_exit_operation() : nullptr;
109  OperationNode *op_to = handle->node->get_entry_operation();
110  if (op_from != nullptr && op_to != nullptr) {
111  return add_operation_relation(op_from, op_to, description, flags);
112  }
113  else {
114  if (!op_from) {
115  fprintf(stderr,
116  "add_node_handle_relation(%s) - Could not find op_from (%s)\n",
117  description,
118  key_from.identifier().c_str());
119  }
120  if (!op_to) {
121  fprintf(stderr,
122  "add_node_handle_relation(%s) - Could not find op_to (%s)\n",
123  description,
124  key_from.identifier().c_str());
125  }
126  }
127  return nullptr;
128 }
129 
131 {
132  if (rbo == nullptr) {
133  return false;
134  }
136  if (rbo->mesh_source != RBO_MESH_BASE) {
137  return true;
138  }
139  }
140  return false;
141 }
142 
143 template<typename KeyTo>
145  const KeyTo &key_to,
146  const char *description,
147  int flags)
148 {
149  if (GS(id->name) == ID_OB) {
150  Object *object = reinterpret_cast<Object *>(id);
153  return add_relation(transform_key, key_to, description, flags);
154  }
155  }
156  ComponentKey transform_key(id, NodeType::TRANSFORM);
157  return add_relation(transform_key, key_to, description, flags);
158 }
159 
160 template<typename KeyType>
162  const char *default_name)
163 {
164  return DepsNodeHandle(this, get_node(key), default_name);
165 }
166 
167 /* Rig compatibility: we check if bone is using local transform as a variable
168  * for driver on itself and ignore those relations to avoid "false-positive"
169  * dependency cycles.
170  */
171 template<typename KeyFrom, typename KeyTo>
173  const KeyTo &key_to)
174 {
175  /* Get operations for requested keys. */
176  Node *node_from = get_node(key_from);
177  Node *node_to = get_node(key_to);
178  if (node_from == nullptr || node_to == nullptr) {
179  return false;
180  }
181  OperationNode *op_from = node_from->get_exit_operation();
182  OperationNode *op_to = node_to->get_entry_operation();
183  if (op_from == nullptr || op_to == nullptr) {
184  return false;
185  }
186  /* Different armatures, bone can't be the same. */
187  if (op_from->owner->owner != op_to->owner->owner) {
188  return false;
189  }
190  /* We are only interested in relations like BONE_DONE -> BONE_LOCAL... */
191  if (!(op_from->opcode == OperationCode::BONE_DONE &&
192  op_to->opcode == OperationCode::BONE_LOCAL)) {
193  return false;
194  }
195  /* ... BUT, we also need to check if it's same bone. */
196  if (op_from->owner->name != op_to->owner->name) {
197  return false;
198  }
199  return true;
200 }
201 
202 template<typename KeyFrom, typename KeyTo>
204  const KeyTo &key_to)
205 {
206  /* Get operations for requested keys. */
207  Node *node_from = get_node(key_from);
208  Node *node_to = get_node(key_to);
209  if (node_from == nullptr || node_to == nullptr) {
210  return false;
211  }
212  OperationNode *op_from = node_from->get_exit_operation();
213  OperationNode *op_to = node_to->get_entry_operation();
214  if (op_from == nullptr || op_to == nullptr) {
215  return false;
216  }
217  /* Check if this is actually a node tree. */
218  if (GS(op_from->owner->owner->id_orig->name) != ID_NT) {
219  return false;
220  }
221  /* Different node trees. */
222  if (op_from->owner->owner != op_to->owner->owner) {
223  return false;
224  }
225  /* We are only interested in relations like BONE_DONE -> BONE_LOCAL... */
226  if (!(op_from->opcode == OperationCode::PARAMETERS_EVAL &&
228  return false;
229  }
230  return true;
231 }
232 
233 } // namespace deg
234 } // namespace blender
#define ELEM(...)
ID and Library types, which are fundamental for sdna.
@ ID_NT
Definition: DNA_ID_enums.h:80
@ ID_OB
Definition: DNA_ID_enums.h:59
Object is a sort of wrapper for general info.
Types and defines for representing Rigid Body entities.
@ RBO_MESH_BASE
@ RB_SHAPE_CONVEXH
@ RB_SHAPE_TRIMESH
Relation * add_depends_on_transform_relation(ID *id, const KeyTo &key_to, const char *description, int flags=0)
TimeSourceNode * get_node(const TimeSourceKey &key) const
bool is_same_nodetree_node_dependency(const KeyFrom &key_from, const KeyTo &key_to)
bool is_same_bone_dependency(const KeyFrom &key_from, const KeyTo &key_to)
Relation * add_node_handle_relation(const KeyType &key_from, const DepsNodeHandle *handle, const char *description, int flags=0)
Relation * add_relation(const KeyFrom &key_from, const KeyTo &key_to, const char *description, int flags=0)
Relation * add_operation_relation(OperationNode *node_from, OperationNode *node_to, const char *description, int flags=0)
OperationNode * find_operation_node(const KeyType &key)
DepsNodeHandle create_node_handle(const KeyType &key, const char *default_name="")
Relation * add_time_relation(TimeSourceNode *timesrc, Node *node_to, const char *description, int flags=0)
OperationNode * node
#define GS(x)
Definition: iris.c:241
static bool rigidbody_object_depends_on_evaluated_geometry(const RigidBodyOb *rbo)
Definition: DNA_ID.h:273
char name[66]
Definition: DNA_ID.h:283
struct RigidBodyOb * rigidbody_object
virtual OperationNode * get_exit_operation()
Definition: deg_node.h:203
virtual OperationNode * get_entry_operation()
Definition: deg_node.h:199
virtual OperationNode * get_entry_operation() override