Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/3d/chain_ik_3d.cpp
14709 views
1
/**************************************************************************/
2
/* chain_ik_3d.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 "chain_ik_3d.h"
32
33
bool ChainIK3D::_set(const StringName &p_path, const Variant &p_value) {
34
String path = p_path;
35
36
if (path.begins_with("settings/")) {
37
int which = path.get_slicec('/', 1).to_int();
38
String what = path.get_slicec('/', 2);
39
ERR_FAIL_INDEX_V(which, (int)settings.size(), false);
40
41
if (what == "root_bone_name") {
42
set_root_bone_name(which, p_value);
43
} else if (what == "root_bone") {
44
set_root_bone(which, p_value);
45
} else if (what == "end_bone_name") {
46
set_end_bone_name(which, p_value);
47
} else if (what == "end_bone") {
48
String opt = path.get_slicec('/', 3);
49
if (opt.is_empty()) {
50
set_end_bone(which, p_value);
51
} else if (opt == "direction") {
52
set_end_bone_direction(which, static_cast<BoneDirection>((int)p_value));
53
} else if (opt == "length") {
54
set_end_bone_length(which, p_value);
55
} else {
56
return false;
57
}
58
} else if (what == "extend_end_bone") {
59
set_extend_end_bone(which, p_value);
60
} else if (what == "joint_count") {
61
set_joint_count(which, p_value);
62
} else if (what == "joints") {
63
int idx = path.get_slicec('/', 3).to_int();
64
String prop = path.get_slicec('/', 4);
65
if (prop == "bone_name") {
66
set_joint_bone_name(which, idx, p_value);
67
} else if (prop == "bone") {
68
set_joint_bone(which, idx, p_value);
69
} else {
70
return false;
71
}
72
} else {
73
return false;
74
}
75
}
76
return true;
77
}
78
79
bool ChainIK3D::_get(const StringName &p_path, Variant &r_ret) const {
80
String path = p_path;
81
82
if (path.begins_with("settings/")) {
83
int which = path.get_slicec('/', 1).to_int();
84
String what = path.get_slicec('/', 2);
85
ERR_FAIL_INDEX_V(which, (int)settings.size(), false);
86
87
if (what == "root_bone_name") {
88
r_ret = get_root_bone_name(which);
89
} else if (what == "root_bone") {
90
r_ret = get_root_bone(which);
91
} else if (what == "end_bone_name") {
92
r_ret = get_end_bone_name(which);
93
} else if (what == "end_bone") {
94
String opt = path.get_slicec('/', 3);
95
if (opt.is_empty()) {
96
r_ret = get_end_bone(which);
97
} else if (opt == "direction") {
98
r_ret = (int)get_end_bone_direction(which);
99
} else if (opt == "length") {
100
r_ret = get_end_bone_length(which);
101
} else {
102
return false;
103
}
104
} else if (what == "extend_end_bone") {
105
r_ret = is_end_bone_extended(which);
106
} else if (what == "joint_count") {
107
r_ret = get_joint_count(which);
108
} else if (what == "joints") {
109
int idx = path.get_slicec('/', 3).to_int();
110
String prop = path.get_slicec('/', 4);
111
if (prop == "bone_name") {
112
r_ret = get_joint_bone_name(which, idx);
113
} else if (prop == "bone") {
114
r_ret = get_joint_bone(which, idx);
115
} else {
116
return false;
117
}
118
} else {
119
return false;
120
}
121
}
122
return true;
123
}
124
125
void ChainIK3D::get_property_list(List<PropertyInfo> *p_list) const {
126
String enum_hint;
127
Skeleton3D *skeleton = get_skeleton();
128
if (skeleton) {
129
enum_hint = skeleton->get_concatenated_bone_names();
130
}
131
132
LocalVector<PropertyInfo> props;
133
134
for (uint32_t i = 0; i < settings.size(); i++) {
135
String path = "settings/" + itos(i) + "/";
136
props.push_back(PropertyInfo(Variant::STRING, path + "root_bone_name", PROPERTY_HINT_ENUM_SUGGESTION, enum_hint));
137
props.push_back(PropertyInfo(Variant::INT, path + "root_bone", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR));
138
props.push_back(PropertyInfo(Variant::STRING, path + "end_bone_name", PROPERTY_HINT_ENUM_SUGGESTION, enum_hint));
139
props.push_back(PropertyInfo(Variant::INT, path + "end_bone", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR));
140
props.push_back(PropertyInfo(Variant::BOOL, path + "extend_end_bone"));
141
props.push_back(PropertyInfo(Variant::INT, path + "end_bone/direction", PROPERTY_HINT_ENUM, SkeletonModifier3D::get_hint_bone_direction()));
142
props.push_back(PropertyInfo(Variant::FLOAT, path + "end_bone/length", PROPERTY_HINT_RANGE, "0,1,0.001,or_greater,suffix:m"));
143
props.push_back(PropertyInfo(Variant::INT, path + "joint_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_ARRAY, "Joints," + path + "joints/,static,const"));
144
for (uint32_t j = 0; j < chain_settings[i]->joints.size(); j++) {
145
String joint_path = path + "joints/" + itos(j) + "/";
146
props.push_back(PropertyInfo(Variant::STRING, joint_path + "bone_name", PROPERTY_HINT_ENUM_SUGGESTION, enum_hint, PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_READ_ONLY));
147
props.push_back(PropertyInfo(Variant::INT, joint_path + "bone", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_READ_ONLY));
148
}
149
}
150
151
for (PropertyInfo &p : props) {
152
_validate_dynamic_prop(p);
153
p_list->push_back(p);
154
}
155
}
156
157
void ChainIK3D::_validate_dynamic_prop(PropertyInfo &p_property) const {
158
PackedStringArray split = p_property.name.split("/");
159
if (split.size() > 2 && split[0] == "settings") {
160
int which = split[1].to_int();
161
162
// Extended end bone option.
163
bool force_hide = false;
164
if (split[2] == "extend_end_bone" && get_end_bone(which) == -1) {
165
p_property.usage = PROPERTY_USAGE_NONE;
166
force_hide = true;
167
}
168
if (force_hide || (split[2] == "end_bone" && !is_end_bone_extended(which) && split.size() > 3)) {
169
p_property.usage = PROPERTY_USAGE_NONE;
170
}
171
}
172
}
173
174
// Setting.
175
176
void ChainIK3D::set_root_bone_name(int p_index, const String &p_bone_name) {
177
ERR_FAIL_INDEX(p_index, (int)settings.size());
178
chain_settings[p_index]->root_bone.name = p_bone_name;
179
Skeleton3D *sk = get_skeleton();
180
if (sk) {
181
set_root_bone(p_index, sk->find_bone(chain_settings[p_index]->root_bone.name));
182
}
183
}
184
185
String ChainIK3D::get_root_bone_name(int p_index) const {
186
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), String());
187
return chain_settings[p_index]->root_bone.name;
188
}
189
190
void ChainIK3D::set_root_bone(int p_index, int p_bone) {
191
ERR_FAIL_INDEX(p_index, (int)settings.size());
192
bool changed = chain_settings[p_index]->root_bone.bone != p_bone;
193
chain_settings[p_index]->root_bone.bone = p_bone;
194
Skeleton3D *sk = get_skeleton();
195
if (sk) {
196
if (chain_settings[p_index]->root_bone.bone <= -1 || chain_settings[p_index]->root_bone.bone >= sk->get_bone_count()) {
197
WARN_PRINT("Root bone index out of range!");
198
chain_settings[p_index]->root_bone.bone = -1;
199
} else {
200
chain_settings[p_index]->root_bone.name = sk->get_bone_name(chain_settings[p_index]->root_bone.bone);
201
}
202
}
203
if (changed) {
204
_update_joints(p_index);
205
}
206
}
207
208
int ChainIK3D::get_root_bone(int p_index) const {
209
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), -1);
210
return chain_settings[p_index]->root_bone.bone;
211
}
212
213
void ChainIK3D::set_end_bone_name(int p_index, const String &p_bone_name) {
214
ERR_FAIL_INDEX(p_index, (int)settings.size());
215
chain_settings[p_index]->end_bone.name = p_bone_name;
216
Skeleton3D *sk = get_skeleton();
217
if (sk) {
218
set_end_bone(p_index, sk->find_bone(chain_settings[p_index]->end_bone.name));
219
}
220
}
221
222
String ChainIK3D::get_end_bone_name(int p_index) const {
223
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), String());
224
return chain_settings[p_index]->end_bone.name;
225
}
226
227
void ChainIK3D::set_end_bone(int p_index, int p_bone) {
228
ERR_FAIL_INDEX(p_index, (int)settings.size());
229
bool changed = chain_settings[p_index]->end_bone.bone != p_bone;
230
chain_settings[p_index]->end_bone.bone = p_bone;
231
Skeleton3D *sk = get_skeleton();
232
if (sk) {
233
if (chain_settings[p_index]->end_bone.bone <= -1 || chain_settings[p_index]->end_bone.bone >= sk->get_bone_count()) {
234
WARN_PRINT("End bone index out of range!");
235
chain_settings[p_index]->end_bone.bone = -1;
236
} else {
237
chain_settings[p_index]->end_bone.name = sk->get_bone_name(chain_settings[p_index]->end_bone.bone);
238
}
239
}
240
if (changed) {
241
_update_joints(p_index);
242
}
243
notify_property_list_changed();
244
}
245
246
int ChainIK3D::get_end_bone(int p_index) const {
247
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), -1);
248
return chain_settings[p_index]->end_bone.bone;
249
}
250
251
void ChainIK3D::set_extend_end_bone(int p_index, bool p_enabled) {
252
ERR_FAIL_INDEX(p_index, (int)settings.size());
253
chain_settings[p_index]->extend_end_bone = p_enabled;
254
_make_simulation_dirty(p_index);
255
Skeleton3D *sk = get_skeleton();
256
if (sk && !chain_settings[p_index]->joints.is_empty()) {
257
_validate_axis(sk, p_index, chain_settings[p_index]->joints.size() - 1);
258
}
259
notify_property_list_changed();
260
#ifdef TOOLS_ENABLED
261
_make_gizmo_dirty();
262
#endif // TOOLS_ENABLED
263
}
264
265
bool ChainIK3D::is_end_bone_extended(int p_index) const {
266
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), false);
267
return chain_settings[p_index]->extend_end_bone;
268
}
269
270
void ChainIK3D::set_end_bone_direction(int p_index, BoneDirection p_bone_direction) {
271
ERR_FAIL_INDEX(p_index, (int)settings.size());
272
chain_settings[p_index]->end_bone_direction = p_bone_direction;
273
Skeleton3D *sk = get_skeleton();
274
if (sk && !chain_settings[p_index]->joints.is_empty()) {
275
_validate_axis(sk, p_index, chain_settings[p_index]->joints.size() - 1);
276
}
277
#ifdef TOOLS_ENABLED
278
_make_gizmo_dirty();
279
#endif // TOOLS_ENABLED
280
if (mutable_bone_axes) {
281
return; // Chain dir will be recaluclated in _update_bone_axis().
282
}
283
_make_simulation_dirty(p_index);
284
}
285
286
SkeletonModifier3D::BoneDirection ChainIK3D::get_end_bone_direction(int p_index) const {
287
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), BONE_DIRECTION_FROM_PARENT);
288
return chain_settings[p_index]->end_bone_direction;
289
}
290
291
void ChainIK3D::set_end_bone_length(int p_index, float p_length) {
292
ERR_FAIL_INDEX(p_index, (int)settings.size());
293
float old = chain_settings[p_index]->end_bone_length;
294
chain_settings[p_index]->end_bone_length = p_length;
295
#ifdef TOOLS_ENABLED
296
_make_gizmo_dirty();
297
#endif // TOOLS_ENABLED
298
if (mutable_bone_axes && Math::is_zero_approx(old) == Math::is_zero_approx(p_length)) {
299
return; // If chain size is not changed, length will be recaluclated in _update_bone_axis().
300
}
301
_make_simulation_dirty(p_index);
302
}
303
304
float ChainIK3D::get_end_bone_length(int p_index) const {
305
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), 0);
306
return chain_settings[p_index]->end_bone_length;
307
}
308
309
// Individual joints.
310
311
void ChainIK3D::set_joint_bone_name(int p_index, int p_joint, const String &p_bone_name) {
312
// Exists only for indicate bone name on the inspector, no needs to make dirty joint array.
313
ERR_FAIL_INDEX(p_index, (int)settings.size());
314
LocalVector<BoneJoint> &joints = chain_settings[p_index]->joints;
315
ERR_FAIL_INDEX(p_joint, (int)joints.size());
316
joints[p_joint].name = p_bone_name;
317
Skeleton3D *sk = get_skeleton();
318
if (sk) {
319
set_joint_bone(p_index, p_joint, sk->find_bone(joints[p_joint].name));
320
}
321
}
322
323
String ChainIK3D::get_joint_bone_name(int p_index, int p_joint) const {
324
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), String());
325
const LocalVector<BoneJoint> &joints = chain_settings[p_index]->joints;
326
ERR_FAIL_INDEX_V(p_joint, (int)joints.size(), String());
327
return joints[p_joint].name;
328
}
329
330
void ChainIK3D::set_joint_bone(int p_index, int p_joint, int p_bone) {
331
ERR_FAIL_INDEX(p_index, (int)settings.size());
332
LocalVector<BoneJoint> &joints = chain_settings[p_index]->joints;
333
ERR_FAIL_INDEX(p_joint, (int)joints.size());
334
joints[p_joint].bone = p_bone;
335
Skeleton3D *sk = get_skeleton();
336
if (sk) {
337
if (joints[p_joint].bone <= -1 || joints[p_joint].bone >= sk->get_bone_count()) {
338
WARN_PRINT("Joint bone index out of range!");
339
joints[p_joint].bone = -1;
340
} else {
341
joints[p_joint].name = sk->get_bone_name(joints[p_joint].bone);
342
}
343
}
344
}
345
346
int ChainIK3D::get_joint_bone(int p_index, int p_joint) const {
347
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), -1);
348
const LocalVector<BoneJoint> &joints = chain_settings[p_index]->joints;
349
ERR_FAIL_INDEX_V(p_joint, (int)joints.size(), -1);
350
return joints[p_joint].bone;
351
}
352
353
void ChainIK3D::set_joint_count(int p_index, int p_count) {
354
ERR_FAIL_INDEX(p_index, (int)settings.size());
355
ERR_FAIL_COND(p_count < 0);
356
LocalVector<BoneJoint> &joints = chain_settings[p_index]->joints;
357
joints.resize(p_count);
358
_set_joint_count(p_index, p_count);
359
notify_property_list_changed();
360
}
361
362
void ChainIK3D::_set_joint_count(int p_index, int p_count) {
363
//
364
}
365
366
int ChainIK3D::get_joint_count(int p_index) const {
367
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), 0);
368
const LocalVector<BoneJoint> &joints = chain_settings[p_index]->joints;
369
return joints.size();
370
}
371
372
void ChainIK3D::_bind_methods() {
373
// Setting.
374
ClassDB::bind_method(D_METHOD("set_root_bone_name", "index", "bone_name"), &ChainIK3D::set_root_bone_name);
375
ClassDB::bind_method(D_METHOD("get_root_bone_name", "index"), &ChainIK3D::get_root_bone_name);
376
ClassDB::bind_method(D_METHOD("set_root_bone", "index", "bone"), &ChainIK3D::set_root_bone);
377
ClassDB::bind_method(D_METHOD("get_root_bone", "index"), &ChainIK3D::get_root_bone);
378
379
ClassDB::bind_method(D_METHOD("set_end_bone_name", "index", "bone_name"), &ChainIK3D::set_end_bone_name);
380
ClassDB::bind_method(D_METHOD("get_end_bone_name", "index"), &ChainIK3D::get_end_bone_name);
381
ClassDB::bind_method(D_METHOD("set_end_bone", "index", "bone"), &ChainIK3D::set_end_bone);
382
ClassDB::bind_method(D_METHOD("get_end_bone", "index"), &ChainIK3D::get_end_bone);
383
384
ClassDB::bind_method(D_METHOD("set_extend_end_bone", "index", "enabled"), &ChainIK3D::set_extend_end_bone);
385
ClassDB::bind_method(D_METHOD("is_end_bone_extended", "index"), &ChainIK3D::is_end_bone_extended);
386
ClassDB::bind_method(D_METHOD("set_end_bone_direction", "index", "bone_direction"), &ChainIK3D::set_end_bone_direction);
387
ClassDB::bind_method(D_METHOD("get_end_bone_direction", "index"), &ChainIK3D::get_end_bone_direction);
388
ClassDB::bind_method(D_METHOD("set_end_bone_length", "index", "length"), &ChainIK3D::set_end_bone_length);
389
ClassDB::bind_method(D_METHOD("get_end_bone_length", "index"), &ChainIK3D::get_end_bone_length);
390
391
// Individual joints.
392
ClassDB::bind_method(D_METHOD("get_joint_bone_name", "index", "joint"), &ChainIK3D::get_joint_bone_name);
393
ClassDB::bind_method(D_METHOD("get_joint_bone", "index", "joint"), &ChainIK3D::get_joint_bone);
394
395
ClassDB::bind_method(D_METHOD("get_joint_count", "index"), &ChainIK3D::get_joint_count);
396
}
397
398
void ChainIK3D::_validate_bone_names() {
399
for (uint32_t i = 0; i < settings.size(); i++) {
400
// Prior bone name.
401
if (!chain_settings[i]->root_bone.name.is_empty()) {
402
set_root_bone_name(i, chain_settings[i]->root_bone.name);
403
} else if (chain_settings[i]->root_bone.bone != -1) {
404
set_root_bone(i, chain_settings[i]->root_bone.bone);
405
}
406
// Prior bone name.
407
if (!chain_settings[i]->end_bone.name.is_empty()) {
408
set_end_bone_name(i, chain_settings[i]->end_bone.name);
409
} else if (chain_settings[i]->end_bone.bone != -1) {
410
set_end_bone(i, chain_settings[i]->end_bone.bone);
411
}
412
}
413
}
414
415
void ChainIK3D::_validate_axes(Skeleton3D *p_skeleton) const {
416
for (uint32_t i = 0; i < settings.size(); i++) {
417
for (uint32_t j = 0; j < chain_settings[i]->joints.size(); j++) {
418
_validate_axis(p_skeleton, i, j);
419
}
420
}
421
}
422
423
void ChainIK3D::_validate_axis(Skeleton3D *p_skeleton, int p_index, int p_joint) const {
424
//
425
}
426
427
void ChainIK3D::_make_all_joints_dirty() {
428
for (uint32_t i = 0; i < settings.size(); i++) {
429
_update_joints(i);
430
}
431
}
432
433
void ChainIK3D::_update_joints(int p_index) {
434
_make_simulation_dirty(p_index);
435
436
#ifdef TOOLS_ENABLED
437
update_gizmos(); // To clear invalid setting.
438
#endif // TOOLS_ENABLED
439
440
Skeleton3D *sk = get_skeleton();
441
int current_bone = chain_settings[p_index]->end_bone.bone;
442
int root_bone = chain_settings[p_index]->root_bone.bone;
443
if (!sk || current_bone < 0 || root_bone < 0) {
444
set_joint_count(p_index, 0);
445
return;
446
}
447
448
// Validation.
449
bool valid = false;
450
while (current_bone >= 0) {
451
if (current_bone == root_bone) {
452
valid = true;
453
break;
454
}
455
current_bone = sk->get_bone_parent(current_bone);
456
}
457
458
if (!valid) {
459
set_joint_count(p_index, 0);
460
ERR_FAIL_EDMSG("End bone must be the same as or a child of the root bone.");
461
}
462
463
Vector<int> new_joints;
464
current_bone = chain_settings[p_index]->end_bone.bone;
465
while (current_bone != root_bone) {
466
new_joints.push_back(current_bone);
467
current_bone = sk->get_bone_parent(current_bone);
468
}
469
new_joints.push_back(current_bone);
470
new_joints.reverse();
471
472
set_joint_count(p_index, new_joints.size());
473
for (uint32_t i = 0; i < new_joints.size(); i++) {
474
set_joint_bone(p_index, i, new_joints[i]);
475
}
476
477
if (sk) {
478
_validate_axes(sk);
479
}
480
481
#ifdef TOOLS_ENABLED
482
_make_gizmo_dirty();
483
#endif // TOOLS_ENABLED
484
}
485
486
void ChainIK3D::_process_ik(Skeleton3D *p_skeleton, double p_delta) {
487
//
488
}
489
490
#ifdef TOOLS_ENABLED
491
void ChainIK3D::_update_mutable_info() {
492
if (!is_inside_tree()) {
493
return;
494
}
495
Skeleton3D *skeleton = get_skeleton();
496
if (!skeleton) {
497
for (uint32_t i = 0; i < settings.size(); i++) {
498
chain_settings[i]->root_global_rest = Transform3D();
499
}
500
}
501
bool changed = false;
502
for (uint32_t i = 0; i < settings.size(); i++) {
503
int root_bone = chain_settings[i]->root_bone.bone;
504
if (root_bone < 0) {
505
continue;
506
}
507
Transform3D new_tr = get_bone_global_rest_mutable(skeleton, root_bone);
508
changed = changed || !chain_settings[i]->root_global_rest.is_equal_approx(new_tr);
509
chain_settings[i]->root_global_rest = new_tr;
510
}
511
if (changed) {
512
_make_gizmo_dirty();
513
}
514
}
515
516
Transform3D ChainIK3D::get_bone_global_rest_mutable(Skeleton3D *p_skeleton, int p_bone) {
517
int current = p_bone;
518
Transform3D accum;
519
int parent = p_skeleton->get_bone_parent(current);
520
if (parent >= 0) {
521
accum = p_skeleton->get_bone_global_rest(parent);
522
}
523
Transform3D tr = p_skeleton->get_bone_rest(current);
524
// Note:
525
// Chain IK gizmo might not be able to retrieve this pose in SkeletonModifier update process.
526
// So the gizmo uses bone_vector insteads but parent of root bone doesn't have bone_vector.
527
// Then, we needs to cache this pose in IK node.
528
tr.origin = p_skeleton->get_bone_pose_position(current);
529
accum *= tr;
530
return accum;
531
}
532
533
Transform3D ChainIK3D::get_chain_root_global_rest(int p_index) {
534
ERR_FAIL_INDEX_V(p_index, (int)settings.size(), Transform3D());
535
return chain_settings[p_index]->root_global_rest;
536
}
537
538
Vector3 ChainIK3D::get_bone_vector(int p_index, int p_joint) const {
539
return Vector3();
540
}
541
#endif // TOOLS_ENABLED
542
543
ChainIK3D::~ChainIK3D() {
544
clear_settings();
545
}
546
547