Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/2d/skeleton/skeleton_modification_2d_ccdik.cpp
9904 views
1
/**************************************************************************/
2
/* skeleton_modification_2d_ccdik.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "skeleton_modification_2d_ccdik.h"
32
#include "scene/2d/skeleton_2d.h"
33
34
bool SkeletonModification2DCCDIK::_set(const StringName &p_path, const Variant &p_value) {
35
String path = p_path;
36
37
if (path.begins_with("joint_data/")) {
38
int which = path.get_slicec('/', 1).to_int();
39
String what = path.get_slicec('/', 2);
40
ERR_FAIL_INDEX_V(which, ccdik_data_chain.size(), false);
41
42
if (what == "bone2d_node") {
43
set_ccdik_joint_bone2d_node(which, p_value);
44
} else if (what == "bone_index") {
45
set_ccdik_joint_bone_index(which, p_value);
46
} else if (what == "rotate_from_joint") {
47
set_ccdik_joint_rotate_from_joint(which, p_value);
48
} else if (what == "enable_constraint") {
49
set_ccdik_joint_enable_constraint(which, p_value);
50
} else if (what == "constraint_angle_min") {
51
set_ccdik_joint_constraint_angle_min(which, Math::deg_to_rad(float(p_value)));
52
} else if (what == "constraint_angle_max") {
53
set_ccdik_joint_constraint_angle_max(which, Math::deg_to_rad(float(p_value)));
54
} else if (what == "constraint_angle_invert") {
55
set_ccdik_joint_constraint_angle_invert(which, p_value);
56
} else if (what == "constraint_in_localspace") {
57
set_ccdik_joint_constraint_in_localspace(which, p_value);
58
}
59
#ifdef TOOLS_ENABLED
60
else if (what.begins_with("editor_draw_gizmo")) {
61
set_ccdik_joint_editor_draw_gizmo(which, p_value);
62
}
63
#endif // TOOLS_ENABLED
64
else {
65
return false;
66
}
67
}
68
#ifdef TOOLS_ENABLED
69
else if (path.begins_with("editor/draw_gizmo")) {
70
set_editor_draw_gizmo(p_value);
71
}
72
#endif // TOOLS_ENABLED
73
else {
74
return false;
75
}
76
77
return true;
78
}
79
80
bool SkeletonModification2DCCDIK::_get(const StringName &p_path, Variant &r_ret) const {
81
String path = p_path;
82
83
if (path.begins_with("joint_data/")) {
84
int which = path.get_slicec('/', 1).to_int();
85
String what = path.get_slicec('/', 2);
86
ERR_FAIL_INDEX_V(which, ccdik_data_chain.size(), false);
87
88
if (what == "bone2d_node") {
89
r_ret = get_ccdik_joint_bone2d_node(which);
90
} else if (what == "bone_index") {
91
r_ret = get_ccdik_joint_bone_index(which);
92
} else if (what == "rotate_from_joint") {
93
r_ret = get_ccdik_joint_rotate_from_joint(which);
94
} else if (what == "enable_constraint") {
95
r_ret = get_ccdik_joint_enable_constraint(which);
96
} else if (what == "constraint_angle_min") {
97
r_ret = Math::rad_to_deg(get_ccdik_joint_constraint_angle_min(which));
98
} else if (what == "constraint_angle_max") {
99
r_ret = Math::rad_to_deg(get_ccdik_joint_constraint_angle_max(which));
100
} else if (what == "constraint_angle_invert") {
101
r_ret = get_ccdik_joint_constraint_angle_invert(which);
102
} else if (what == "constraint_in_localspace") {
103
r_ret = get_ccdik_joint_constraint_in_localspace(which);
104
}
105
#ifdef TOOLS_ENABLED
106
else if (what.begins_with("editor_draw_gizmo")) {
107
r_ret = get_ccdik_joint_editor_draw_gizmo(which);
108
}
109
#endif // TOOLS_ENABLED
110
else {
111
return false;
112
}
113
}
114
#ifdef TOOLS_ENABLED
115
else if (path.begins_with("editor/draw_gizmo")) {
116
r_ret = get_editor_draw_gizmo();
117
}
118
#endif // TOOLS_ENABLED
119
else {
120
return false;
121
}
122
123
return true;
124
}
125
126
void SkeletonModification2DCCDIK::_get_property_list(List<PropertyInfo> *p_list) const {
127
for (int i = 0; i < ccdik_data_chain.size(); i++) {
128
String base_string = "joint_data/" + itos(i) + "/";
129
130
p_list->push_back(PropertyInfo(Variant::INT, base_string + "bone_index", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
131
p_list->push_back(PropertyInfo(Variant::NODE_PATH, base_string + "bone2d_node", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Bone2D", PROPERTY_USAGE_DEFAULT));
132
p_list->push_back(PropertyInfo(Variant::BOOL, base_string + "rotate_from_joint", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
133
134
p_list->push_back(PropertyInfo(Variant::BOOL, base_string + "enable_constraint", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
135
if (ccdik_data_chain[i].enable_constraint) {
136
p_list->push_back(PropertyInfo(Variant::FLOAT, base_string + "constraint_angle_min", PROPERTY_HINT_RANGE, "-360, 360, 0.01", PROPERTY_USAGE_DEFAULT));
137
p_list->push_back(PropertyInfo(Variant::FLOAT, base_string + "constraint_angle_max", PROPERTY_HINT_RANGE, "-360, 360, 0.01", PROPERTY_USAGE_DEFAULT));
138
p_list->push_back(PropertyInfo(Variant::BOOL, base_string + "constraint_angle_invert", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
139
p_list->push_back(PropertyInfo(Variant::BOOL, base_string + "constraint_in_localspace", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
140
}
141
142
#ifdef TOOLS_ENABLED
143
if (Engine::get_singleton()->is_editor_hint()) {
144
p_list->push_back(PropertyInfo(Variant::BOOL, base_string + "editor_draw_gizmo", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
145
}
146
#endif // TOOLS_ENABLED
147
}
148
149
#ifdef TOOLS_ENABLED
150
if (Engine::get_singleton()->is_editor_hint()) {
151
p_list->push_back(PropertyInfo(Variant::BOOL, "editor/draw_gizmo", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
152
}
153
#endif // TOOLS_ENABLED
154
}
155
156
void SkeletonModification2DCCDIK::_execute(float p_delta) {
157
ERR_FAIL_COND_MSG(!stack || !is_setup || stack->skeleton == nullptr,
158
"Modification is not setup and therefore cannot execute!");
159
if (!enabled) {
160
return;
161
}
162
163
if (target_node_cache.is_null()) {
164
WARN_PRINT_ONCE("Target cache is out of date. Attempting to update...");
165
update_target_cache();
166
return;
167
}
168
if (tip_node_cache.is_null()) {
169
WARN_PRINT_ONCE("Tip cache is out of date. Attempting to update...");
170
update_tip_cache();
171
return;
172
}
173
174
Node2D *target = ObjectDB::get_instance<Node2D>(target_node_cache);
175
if (!target || !target->is_inside_tree()) {
176
ERR_PRINT_ONCE("Target node is not in the scene tree. Cannot execute modification!");
177
return;
178
}
179
180
Node2D *tip = ObjectDB::get_instance<Node2D>(tip_node_cache);
181
if (!tip || !tip->is_inside_tree()) {
182
ERR_PRINT_ONCE("Tip node is not in the scene tree. Cannot execute modification!");
183
return;
184
}
185
186
for (int i = 0; i < ccdik_data_chain.size(); i++) {
187
_execute_ccdik_joint(i, target, tip);
188
}
189
}
190
191
void SkeletonModification2DCCDIK::_execute_ccdik_joint(int p_joint_idx, Node2D *p_target, Node2D *p_tip) {
192
CCDIK_Joint_Data2D ccdik_data = ccdik_data_chain[p_joint_idx];
193
if (ccdik_data.bone_idx < 0 || ccdik_data.bone_idx > stack->skeleton->get_bone_count()) {
194
ERR_PRINT_ONCE("2D CCDIK joint: bone index not found!");
195
return;
196
}
197
198
Bone2D *operation_bone = stack->skeleton->get_bone(ccdik_data.bone_idx);
199
Transform2D operation_transform = operation_bone->get_global_transform();
200
201
if (ccdik_data.rotate_from_joint) {
202
// To rotate from the joint, simply look at the target!
203
operation_transform.set_rotation(
204
operation_transform.looking_at(p_target->get_global_position()).get_rotation() - operation_bone->get_bone_angle());
205
} else {
206
// How to rotate from the tip: get the difference of rotation needed from the tip to the target, from the perspective of the joint.
207
// Because we are only using the offset, we do not need to account for the bone angle of the Bone2D node.
208
float joint_to_tip = p_tip->get_global_position().angle_to_point(operation_transform.get_origin());
209
float joint_to_target = p_target->get_global_position().angle_to_point(operation_transform.get_origin());
210
operation_transform.set_rotation(
211
operation_transform.get_rotation() + (joint_to_target - joint_to_tip));
212
}
213
214
// Reset scale
215
operation_transform.set_scale(operation_bone->get_global_scale());
216
217
// Apply constraints in globalspace:
218
if (ccdik_data.enable_constraint && !ccdik_data.constraint_in_localspace) {
219
operation_transform.set_rotation(clamp_angle(operation_transform.get_rotation(), ccdik_data.constraint_angle_min, ccdik_data.constraint_angle_max, ccdik_data.constraint_angle_invert));
220
}
221
222
// Convert from a global transform to a delta and then apply the delta to the local transform.
223
operation_bone->set_global_transform(operation_transform);
224
operation_transform = operation_bone->get_transform();
225
226
// Apply constraints in localspace:
227
if (ccdik_data.enable_constraint && ccdik_data.constraint_in_localspace) {
228
operation_transform.set_rotation(clamp_angle(operation_transform.get_rotation(), ccdik_data.constraint_angle_min, ccdik_data.constraint_angle_max, ccdik_data.constraint_angle_invert));
229
}
230
231
// Set the local pose override, and to make sure child bones are also updated, set the transform of the bone.
232
stack->skeleton->set_bone_local_pose_override(ccdik_data.bone_idx, operation_transform, stack->strength, true);
233
operation_bone->set_transform(operation_transform);
234
operation_bone->notification(operation_bone->NOTIFICATION_TRANSFORM_CHANGED);
235
}
236
237
void SkeletonModification2DCCDIK::_setup_modification(SkeletonModificationStack2D *p_stack) {
238
stack = p_stack;
239
240
if (stack != nullptr) {
241
is_setup = true;
242
update_target_cache();
243
update_tip_cache();
244
}
245
}
246
247
void SkeletonModification2DCCDIK::_draw_editor_gizmo() {
248
if (!enabled || !is_setup) {
249
return;
250
}
251
252
for (int i = 0; i < ccdik_data_chain.size(); i++) {
253
if (!ccdik_data_chain[i].editor_draw_gizmo) {
254
continue;
255
}
256
257
Bone2D *operation_bone = stack->skeleton->get_bone(ccdik_data_chain[i].bone_idx);
258
editor_draw_angle_constraints(operation_bone, ccdik_data_chain[i].constraint_angle_min, ccdik_data_chain[i].constraint_angle_max,
259
ccdik_data_chain[i].enable_constraint, ccdik_data_chain[i].constraint_in_localspace, ccdik_data_chain[i].constraint_angle_invert);
260
}
261
}
262
263
void SkeletonModification2DCCDIK::update_target_cache() {
264
if (!is_setup || !stack) {
265
if (is_setup) {
266
ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
267
}
268
return;
269
}
270
271
target_node_cache = ObjectID();
272
if (stack->skeleton) {
273
if (stack->skeleton->is_inside_tree()) {
274
if (stack->skeleton->has_node(target_node)) {
275
Node *node = stack->skeleton->get_node(target_node);
276
ERR_FAIL_COND_MSG(!node || stack->skeleton == node,
277
"Cannot update target cache: node is this modification's skeleton or cannot be found!");
278
ERR_FAIL_COND_MSG(!node->is_inside_tree(),
279
"Cannot update target cache: node is not in the scene tree!");
280
target_node_cache = node->get_instance_id();
281
}
282
}
283
}
284
}
285
286
void SkeletonModification2DCCDIK::update_tip_cache() {
287
if (!is_setup || !stack) {
288
if (is_setup) {
289
ERR_PRINT_ONCE("Cannot update tip cache: modification is not properly setup!");
290
}
291
return;
292
}
293
294
tip_node_cache = ObjectID();
295
if (stack->skeleton) {
296
if (stack->skeleton->is_inside_tree()) {
297
if (stack->skeleton->has_node(tip_node)) {
298
Node *node = stack->skeleton->get_node(tip_node);
299
ERR_FAIL_COND_MSG(!node || stack->skeleton == node,
300
"Cannot update tip cache: node is this modification's skeleton or cannot be found!");
301
ERR_FAIL_COND_MSG(!node->is_inside_tree(),
302
"Cannot update tip cache: node is not in the scene tree!");
303
tip_node_cache = node->get_instance_id();
304
}
305
}
306
}
307
}
308
309
void SkeletonModification2DCCDIK::ccdik_joint_update_bone2d_cache(int p_joint_idx) {
310
ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "Cannot update bone2d cache: joint index out of range!");
311
if (!is_setup || !stack) {
312
if (is_setup) {
313
ERR_PRINT_ONCE("Cannot update CCDIK Bone2D cache: modification is not properly setup!");
314
}
315
return;
316
}
317
318
ccdik_data_chain.write[p_joint_idx].bone2d_node_cache = ObjectID();
319
if (stack->skeleton) {
320
if (stack->skeleton->is_inside_tree()) {
321
if (stack->skeleton->has_node(ccdik_data_chain[p_joint_idx].bone2d_node)) {
322
Node *node = stack->skeleton->get_node(ccdik_data_chain[p_joint_idx].bone2d_node);
323
ERR_FAIL_COND_MSG(!node || stack->skeleton == node,
324
"Cannot update CCDIK joint " + itos(p_joint_idx) + " Bone2D cache: node is this modification's skeleton or cannot be found!");
325
ERR_FAIL_COND_MSG(!node->is_inside_tree(),
326
"Cannot update CCDIK joint " + itos(p_joint_idx) + " Bone2D cache: node is not in the scene tree!");
327
ccdik_data_chain.write[p_joint_idx].bone2d_node_cache = node->get_instance_id();
328
329
Bone2D *bone = Object::cast_to<Bone2D>(node);
330
if (bone) {
331
ccdik_data_chain.write[p_joint_idx].bone_idx = bone->get_index_in_skeleton();
332
} else {
333
ERR_FAIL_MSG("CCDIK joint " + itos(p_joint_idx) + " Bone2D cache: Nodepath to Bone2D is not a Bone2D node!");
334
}
335
}
336
}
337
}
338
}
339
340
void SkeletonModification2DCCDIK::set_target_node(const NodePath &p_target_node) {
341
target_node = p_target_node;
342
update_target_cache();
343
}
344
345
NodePath SkeletonModification2DCCDIK::get_target_node() const {
346
return target_node;
347
}
348
349
void SkeletonModification2DCCDIK::set_tip_node(const NodePath &p_tip_node) {
350
tip_node = p_tip_node;
351
update_tip_cache();
352
}
353
354
NodePath SkeletonModification2DCCDIK::get_tip_node() const {
355
return tip_node;
356
}
357
358
void SkeletonModification2DCCDIK::set_ccdik_data_chain_length(int p_length) {
359
ccdik_data_chain.resize(p_length);
360
notify_property_list_changed();
361
}
362
363
int SkeletonModification2DCCDIK::get_ccdik_data_chain_length() {
364
return ccdik_data_chain.size();
365
}
366
367
void SkeletonModification2DCCDIK::set_ccdik_joint_bone2d_node(int p_joint_idx, const NodePath &p_target_node) {
368
ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "CCDIK joint out of range!");
369
ccdik_data_chain.write[p_joint_idx].bone2d_node = p_target_node;
370
ccdik_joint_update_bone2d_cache(p_joint_idx);
371
372
notify_property_list_changed();
373
}
374
375
NodePath SkeletonModification2DCCDIK::get_ccdik_joint_bone2d_node(int p_joint_idx) const {
376
ERR_FAIL_INDEX_V_MSG(p_joint_idx, ccdik_data_chain.size(), NodePath(), "CCDIK joint out of range!");
377
return ccdik_data_chain[p_joint_idx].bone2d_node;
378
}
379
380
void SkeletonModification2DCCDIK::set_ccdik_joint_bone_index(int p_joint_idx, int p_bone_idx) {
381
ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "CCCDIK joint out of range!");
382
ERR_FAIL_COND_MSG(p_bone_idx < 0, "Bone index is out of range: The index is too low!");
383
384
if (is_setup) {
385
if (stack->skeleton) {
386
ERR_FAIL_INDEX_MSG(p_bone_idx, stack->skeleton->get_bone_count(), "Passed-in Bone index is out of range!");
387
ccdik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
388
ccdik_data_chain.write[p_joint_idx].bone2d_node_cache = stack->skeleton->get_bone(p_bone_idx)->get_instance_id();
389
ccdik_data_chain.write[p_joint_idx].bone2d_node = stack->skeleton->get_path_to(stack->skeleton->get_bone(p_bone_idx));
390
} else {
391
WARN_PRINT("Cannot verify the CCDIK joint " + itos(p_joint_idx) + " bone index for this modification...");
392
ccdik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
393
}
394
} else {
395
ccdik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
396
}
397
398
notify_property_list_changed();
399
}
400
401
int SkeletonModification2DCCDIK::get_ccdik_joint_bone_index(int p_joint_idx) const {
402
ERR_FAIL_INDEX_V_MSG(p_joint_idx, ccdik_data_chain.size(), -1, "CCDIK joint out of range!");
403
return ccdik_data_chain[p_joint_idx].bone_idx;
404
}
405
406
void SkeletonModification2DCCDIK::set_ccdik_joint_rotate_from_joint(int p_joint_idx, bool p_rotate_from_joint) {
407
ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "CCDIK joint out of range!");
408
ccdik_data_chain.write[p_joint_idx].rotate_from_joint = p_rotate_from_joint;
409
}
410
411
bool SkeletonModification2DCCDIK::get_ccdik_joint_rotate_from_joint(int p_joint_idx) const {
412
ERR_FAIL_INDEX_V_MSG(p_joint_idx, ccdik_data_chain.size(), false, "CCDIK joint out of range!");
413
return ccdik_data_chain[p_joint_idx].rotate_from_joint;
414
}
415
416
void SkeletonModification2DCCDIK::set_ccdik_joint_enable_constraint(int p_joint_idx, bool p_constraint) {
417
ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "CCDIK joint out of range!");
418
ccdik_data_chain.write[p_joint_idx].enable_constraint = p_constraint;
419
notify_property_list_changed();
420
421
#ifdef TOOLS_ENABLED
422
if (stack && is_setup) {
423
stack->set_editor_gizmos_dirty(true);
424
}
425
#endif // TOOLS_ENABLED
426
}
427
428
bool SkeletonModification2DCCDIK::get_ccdik_joint_enable_constraint(int p_joint_idx) const {
429
ERR_FAIL_INDEX_V_MSG(p_joint_idx, ccdik_data_chain.size(), false, "CCDIK joint out of range!");
430
return ccdik_data_chain[p_joint_idx].enable_constraint;
431
}
432
433
void SkeletonModification2DCCDIK::set_ccdik_joint_constraint_angle_min(int p_joint_idx, float p_angle_min) {
434
ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "CCDIK joint out of range!");
435
ccdik_data_chain.write[p_joint_idx].constraint_angle_min = p_angle_min;
436
437
#ifdef TOOLS_ENABLED
438
if (stack && is_setup) {
439
stack->set_editor_gizmos_dirty(true);
440
}
441
#endif // TOOLS_ENABLED
442
}
443
444
float SkeletonModification2DCCDIK::get_ccdik_joint_constraint_angle_min(int p_joint_idx) const {
445
ERR_FAIL_INDEX_V_MSG(p_joint_idx, ccdik_data_chain.size(), 0.0, "CCDIK joint out of range!");
446
return ccdik_data_chain[p_joint_idx].constraint_angle_min;
447
}
448
449
void SkeletonModification2DCCDIK::set_ccdik_joint_constraint_angle_max(int p_joint_idx, float p_angle_max) {
450
ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "CCDIK joint out of range!");
451
ccdik_data_chain.write[p_joint_idx].constraint_angle_max = p_angle_max;
452
453
#ifdef TOOLS_ENABLED
454
if (stack && is_setup) {
455
stack->set_editor_gizmos_dirty(true);
456
}
457
#endif // TOOLS_ENABLED
458
}
459
460
float SkeletonModification2DCCDIK::get_ccdik_joint_constraint_angle_max(int p_joint_idx) const {
461
ERR_FAIL_INDEX_V_MSG(p_joint_idx, ccdik_data_chain.size(), 0.0, "CCDIK joint out of range!");
462
return ccdik_data_chain[p_joint_idx].constraint_angle_max;
463
}
464
465
void SkeletonModification2DCCDIK::set_ccdik_joint_constraint_angle_invert(int p_joint_idx, bool p_invert) {
466
ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "CCDIK joint out of range!");
467
ccdik_data_chain.write[p_joint_idx].constraint_angle_invert = p_invert;
468
469
#ifdef TOOLS_ENABLED
470
if (stack && is_setup) {
471
stack->set_editor_gizmos_dirty(true);
472
}
473
#endif // TOOLS_ENABLED
474
}
475
476
bool SkeletonModification2DCCDIK::get_ccdik_joint_constraint_angle_invert(int p_joint_idx) const {
477
ERR_FAIL_INDEX_V_MSG(p_joint_idx, ccdik_data_chain.size(), false, "CCDIK joint out of range!");
478
return ccdik_data_chain[p_joint_idx].constraint_angle_invert;
479
}
480
481
void SkeletonModification2DCCDIK::set_ccdik_joint_constraint_in_localspace(int p_joint_idx, bool p_constraint_in_localspace) {
482
ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "CCDIK joint out of range!");
483
ccdik_data_chain.write[p_joint_idx].constraint_in_localspace = p_constraint_in_localspace;
484
485
#ifdef TOOLS_ENABLED
486
if (stack && is_setup) {
487
stack->set_editor_gizmos_dirty(true);
488
}
489
#endif // TOOLS_ENABLED
490
}
491
492
bool SkeletonModification2DCCDIK::get_ccdik_joint_constraint_in_localspace(int p_joint_idx) const {
493
ERR_FAIL_INDEX_V_MSG(p_joint_idx, ccdik_data_chain.size(), false, "CCDIK joint out of range!");
494
return ccdik_data_chain[p_joint_idx].constraint_in_localspace;
495
}
496
497
void SkeletonModification2DCCDIK::set_ccdik_joint_editor_draw_gizmo(int p_joint_idx, bool p_draw_gizmo) {
498
ERR_FAIL_INDEX_MSG(p_joint_idx, ccdik_data_chain.size(), "CCDIK joint out of range!");
499
ccdik_data_chain.write[p_joint_idx].editor_draw_gizmo = p_draw_gizmo;
500
501
#ifdef TOOLS_ENABLED
502
if (stack && is_setup) {
503
stack->set_editor_gizmos_dirty(true);
504
}
505
#endif // TOOLS_ENABLED
506
}
507
508
bool SkeletonModification2DCCDIK::get_ccdik_joint_editor_draw_gizmo(int p_joint_idx) const {
509
ERR_FAIL_INDEX_V_MSG(p_joint_idx, ccdik_data_chain.size(), false, "CCDIK joint out of range!");
510
return ccdik_data_chain[p_joint_idx].editor_draw_gizmo;
511
}
512
513
void SkeletonModification2DCCDIK::_bind_methods() {
514
ClassDB::bind_method(D_METHOD("set_target_node", "target_nodepath"), &SkeletonModification2DCCDIK::set_target_node);
515
ClassDB::bind_method(D_METHOD("get_target_node"), &SkeletonModification2DCCDIK::get_target_node);
516
ClassDB::bind_method(D_METHOD("set_tip_node", "tip_nodepath"), &SkeletonModification2DCCDIK::set_tip_node);
517
ClassDB::bind_method(D_METHOD("get_tip_node"), &SkeletonModification2DCCDIK::get_tip_node);
518
519
ClassDB::bind_method(D_METHOD("set_ccdik_data_chain_length", "length"), &SkeletonModification2DCCDIK::set_ccdik_data_chain_length);
520
ClassDB::bind_method(D_METHOD("get_ccdik_data_chain_length"), &SkeletonModification2DCCDIK::get_ccdik_data_chain_length);
521
522
ClassDB::bind_method(D_METHOD("set_ccdik_joint_bone2d_node", "joint_idx", "bone2d_nodepath"), &SkeletonModification2DCCDIK::set_ccdik_joint_bone2d_node);
523
ClassDB::bind_method(D_METHOD("get_ccdik_joint_bone2d_node", "joint_idx"), &SkeletonModification2DCCDIK::get_ccdik_joint_bone2d_node);
524
ClassDB::bind_method(D_METHOD("set_ccdik_joint_bone_index", "joint_idx", "bone_idx"), &SkeletonModification2DCCDIK::set_ccdik_joint_bone_index);
525
ClassDB::bind_method(D_METHOD("get_ccdik_joint_bone_index", "joint_idx"), &SkeletonModification2DCCDIK::get_ccdik_joint_bone_index);
526
ClassDB::bind_method(D_METHOD("set_ccdik_joint_rotate_from_joint", "joint_idx", "rotate_from_joint"), &SkeletonModification2DCCDIK::set_ccdik_joint_rotate_from_joint);
527
ClassDB::bind_method(D_METHOD("get_ccdik_joint_rotate_from_joint", "joint_idx"), &SkeletonModification2DCCDIK::get_ccdik_joint_rotate_from_joint);
528
ClassDB::bind_method(D_METHOD("set_ccdik_joint_enable_constraint", "joint_idx", "enable_constraint"), &SkeletonModification2DCCDIK::set_ccdik_joint_enable_constraint);
529
ClassDB::bind_method(D_METHOD("get_ccdik_joint_enable_constraint", "joint_idx"), &SkeletonModification2DCCDIK::get_ccdik_joint_enable_constraint);
530
ClassDB::bind_method(D_METHOD("set_ccdik_joint_constraint_angle_min", "joint_idx", "angle_min"), &SkeletonModification2DCCDIK::set_ccdik_joint_constraint_angle_min);
531
ClassDB::bind_method(D_METHOD("get_ccdik_joint_constraint_angle_min", "joint_idx"), &SkeletonModification2DCCDIK::get_ccdik_joint_constraint_angle_min);
532
ClassDB::bind_method(D_METHOD("set_ccdik_joint_constraint_angle_max", "joint_idx", "angle_max"), &SkeletonModification2DCCDIK::set_ccdik_joint_constraint_angle_max);
533
ClassDB::bind_method(D_METHOD("get_ccdik_joint_constraint_angle_max", "joint_idx"), &SkeletonModification2DCCDIK::get_ccdik_joint_constraint_angle_max);
534
ClassDB::bind_method(D_METHOD("set_ccdik_joint_constraint_angle_invert", "joint_idx", "invert"), &SkeletonModification2DCCDIK::set_ccdik_joint_constraint_angle_invert);
535
ClassDB::bind_method(D_METHOD("get_ccdik_joint_constraint_angle_invert", "joint_idx"), &SkeletonModification2DCCDIK::get_ccdik_joint_constraint_angle_invert);
536
537
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target_nodepath", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Node2D"), "set_target_node", "get_target_node");
538
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "tip_nodepath", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Node2D"), "set_tip_node", "get_tip_node");
539
ADD_PROPERTY(PropertyInfo(Variant::INT, "ccdik_data_chain_length", PROPERTY_HINT_RANGE, "0, 100, 1"), "set_ccdik_data_chain_length", "get_ccdik_data_chain_length");
540
}
541
542
SkeletonModification2DCCDIK::SkeletonModification2DCCDIK() {
543
stack = nullptr;
544
is_setup = false;
545
enabled = true;
546
editor_draw_gizmo = true;
547
}
548
549
SkeletonModification2DCCDIK::~SkeletonModification2DCCDIK() {
550
}
551
552