Blender V5.3
deg_builder_relations_impl.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
14
15#include <iostream>
16
17#include "DNA_ID.h"
18#include "DNA_rigidbody_types.h"
19
20namespace blender::deg {
21
22template<typename KeyType>
24{
25 Node *node = get_node(key);
26 return node != nullptr ? node->get_exit_operation() : nullptr;
27}
28
29template<typename KeyFrom, typename KeyTo>
31 const KeyTo &key_to,
32 const char *description,
33 int flags)
34{
35 Node *node_from = get_node(key_from);
36 Node *node_to = get_node(key_to);
37 OperationNode *op_from = node_from ? node_from->get_exit_operation() : nullptr;
38 OperationNode *op_to = node_to ? node_to->get_entry_operation() : nullptr;
39
40 if (op_from && op_to) {
41 return add_operation_relation(op_from, op_to, description, flags);
42 }
43
44 /* TODO(sergey): Report error in the interface. */
45
46 std::cerr << "--------------------------------------------------------------------\n";
47 std::cerr << "Failed to add relation \"" << description << "\"\n";
48
49 if (!op_from) {
50 std::cerr << "Could not find op_from: " << key_from.identifier() << "\n";
51 }
52
53 if (!op_to) {
54 std::cerr << "Could not find op_to: " << key_to.identifier() << "\n";
55 }
56
57 if (!stack_.is_empty()) {
58 std::cerr << "\nTrace:\n\n";
59 stack_.print_backtrace(std::cerr);
60 std::cerr << "\n";
61 }
62
63 return nullptr;
64}
65
66template<typename KeyTo>
68 const KeyTo &key_to,
69 const char *description,
70 int flags)
71{
72 TimeSourceNode *time_from = get_node(key_from);
73 Node *node_to = get_node(key_to);
74 OperationNode *op_to = node_to ? node_to->get_entry_operation() : nullptr;
75 if (time_from != nullptr && op_to != nullptr) {
76 return add_time_relation(time_from, op_to, description, flags);
77 }
78 return nullptr;
79}
80
81template<typename KeyType>
82 requires(!std::is_same_v<KeyType, TimeSourceKey>)
84 const DepsNodeHandle *handle,
85 const char *description,
86 int flags)
87{
88 Node *node_from = get_node(key_from);
89 OperationNode *op_from = node_from ? node_from->get_exit_operation() : nullptr;
90 OperationNode *op_to = handle->node->get_entry_operation();
91 if (op_from != nullptr && op_to != nullptr) {
92 return add_operation_relation(op_from, op_to, description, flags);
93 }
94 if (!op_from) {
95 fprintf(stderr,
96 "add_node_handle_relation(%s) - Could not find op_from (%s)\n",
97 description,
98 key_from.identifier().c_str());
99 }
100 if (!op_to) {
101 fprintf(stderr,
102 "add_node_handle_relation(%s) - Could not find op_to (%s)\n",
103 description,
104 key_from.identifier().c_str());
105 }
106
107 return nullptr;
108}
109
111{
112 if (rbo == nullptr) {
113 return false;
114 }
116 if (rbo->mesh_source != RBO_MESH_BASE) {
117 return true;
118 }
119 }
120 return false;
121}
122
123template<typename KeyTo>
125 const KeyTo &key_to,
126 const char *description,
127 int flags)
128{
129 if (GS(id->name) == ID_OB) {
130 Object *object = reinterpret_cast<Object *>(id);
133 return add_relation(transform_key, key_to, description, flags);
134 }
135 }
136 ComponentKey transform_key(id, NodeType::TRANSFORM);
137 return add_relation(transform_key, key_to, description, flags);
138}
139
140template<typename KeyType>
142 const char *default_name)
143{
144 return DepsNodeHandle(this, get_node(key), default_name);
145}
146
147/* Rig compatibility: we check if bone is using local transform as a variable
148 * for driver on itself and ignore those relations to avoid "false-positive"
149 * dependency cycles.
150 */
151template<typename KeyFrom, typename KeyTo>
153 const KeyTo &key_to)
154{
155 /* Get operations for requested keys. */
156 Node *node_from = get_node(key_from);
157 Node *node_to = get_node(key_to);
158 if (node_from == nullptr || node_to == nullptr) {
159 return false;
160 }
161 OperationNode *op_from = node_from->get_exit_operation();
162 OperationNode *op_to = node_to->get_entry_operation();
163 if (op_from == nullptr || op_to == nullptr) {
164 return false;
165 }
166 /* Different armatures, bone can't be the same. */
167 if (op_from->owner->owner != op_to->owner->owner) {
168 return false;
169 }
170 /* We are only interested in relations like BONE_DONE -> BONE_LOCAL... */
171 if (!(op_from->opcode == OperationCode::BONE_DONE && op_to->opcode == OperationCode::BONE_LOCAL))
172 {
173 return false;
174 }
175 /* ... BUT, we also need to check if it's same bone. */
176 if (op_from->owner->name != op_to->owner->name) {
177 return false;
178 }
179 return true;
180}
181
182template<typename KeyFrom, typename KeyTo>
184 const KeyTo &key_to)
185{
186 /* Get operations for requested keys. */
187 Node *node_from = get_node(key_from);
188 Node *node_to = get_node(key_to);
189 if (node_from == nullptr || node_to == nullptr) {
190 return false;
191 }
192 OperationNode *op_from = node_from->get_exit_operation();
193 OperationNode *op_to = node_to->get_entry_operation();
194 if (op_from == nullptr || op_to == nullptr) {
195 return false;
196 }
197 /* Check if this is actually a node tree. */
198 if (GS(op_from->owner->owner->id_orig->name) != ID_NT) {
199 return false;
200 }
201 /* Different node trees. */
202 if (op_from->owner->owner != op_to->owner->owner) {
203 return false;
204 }
205 /* We are only interested in relations like BONE_DONE -> BONE_LOCAL... */
206 if (!(op_from->opcode == OperationCode::PARAMETERS_EVAL &&
208 {
209 return false;
210 }
211 return true;
212}
213
214} // namespace blender::deg
ID and Library types, which are fundamental for SDNA.
Types and defines for representing Rigid Body entities.
#define ELEM(...)
Relation * add_node_handle_relation(const KeyType &key_from, const DepsNodeHandle *handle, const char *description, int flags=0)
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_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)
static bool rigidbody_object_depends_on_evaluated_geometry(const RigidBodyOb *rbo)
ID_Type GS(const char *name)
Definition DNA_ID.h:410
char name[258]
Definition DNA_ID.h:433
eRigidBody_MeshSource mesh_source
DepsNodeHandle(DepsgraphRelationBuilder *builder, OperationNode *node, const char *default_name="")
virtual OperationNode * get_entry_operation()
Definition deg_node.hh:209
std::string name
Definition deg_node.hh:186
virtual OperationNode * get_exit_operation()
Definition deg_node.hh:213
OperationNode * get_entry_operation() override