Backported from Godot 4: New and improved IK system for Skeleton3D
This PR and commit adds a new IK system for 3D with the Skeleton3D node
that adds several new IK solvers, as well as additional changes and functionality
for making bone manipulation in Godot easier.
This work was sponsored by GSoC 2020 and TwistedTwigleg
Full list of changes:
* Adds a SkeletonModification3D resource
* This resource is the base where all IK code is written and executed
* Adds a SkeletonModificationStack3D resource
* This node oversees the execution of the modifications and acts as a bridge of sorts for the modifications to the Skeleton3D node
* Adds SkeletonModification3D resources for LookAt, CCDIK, FABRIK, Jiggle, and TwoBoneIK
* Each modification is in it's own file
* Several changes to Skeletons, listed below:
* Added local_pose_override, which acts just like global_pose_override but keeps bone-child relationships intract
* So if you move a bone using local_pose_override, all of the bones that are children will also be moved. This is different than global_pose_override, which only affects the individual bone
* Internally bones keep track of their children. This removes the need of a processing list, makes it possible to update just a few select bones at a time, and makes it easier to traverse down the bone chain
* Additional functions added for converting from world transform to global poses, global poses to local poses, and all the same changes but backwards (local to global, global to world). This makes it much easier to work with bone transforms without needing to think too much about how to convert them.
* New signal added, bone_pose_changed, that can be used to tell if a specific bone changed its transform. Needed for BoneAttachment3D
* Added functions for getting the forward position of a bone
* BoneAttachment3D node refactored heavily
* BoneAttachment3D node is now completely standalone in its functionality.
* This makes the code easier and less interconnected, as well as allowing them to function properly without being direct children of Skeleton3D nodes
* BoneAttachment3D now can be set either using the index or the bone name.
* BoneAttachment3D nodes can now set the bone transform instead of just following it. This is disabled by default for compatibility
* BoneAttachment3D now shows a warning when not configured correctly
* Added rotate_to_align function in Basis
* Added class reference documentation for all changes
- TwistedTwigleg
https://github.com/godotengine/godot/commit/5ffed49907618e3c7e7e2bddddcc8449d0b090a6
Note: It still needs some work.
2022-08-10 01:01:38 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* skeleton_modification_stack_3d.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#include "skeleton_modification_stack_3d.h"
|
|
|
|
#include "scene/3d/skeleton.h"
|
|
|
|
|
|
|
|
#include "skeleton_modification_3d.h"
|
|
|
|
|
|
|
|
///////////////////////////////////////
|
|
|
|
// ModificationStack3D
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::_get_property_list(List<PropertyInfo> *p_list) const {
|
2022-08-10 11:34:12 +02:00
|
|
|
for (int i = 0; i < modifications.size(); i++) {
|
Backported from Godot 4: New and improved IK system for Skeleton3D
This PR and commit adds a new IK system for 3D with the Skeleton3D node
that adds several new IK solvers, as well as additional changes and functionality
for making bone manipulation in Godot easier.
This work was sponsored by GSoC 2020 and TwistedTwigleg
Full list of changes:
* Adds a SkeletonModification3D resource
* This resource is the base where all IK code is written and executed
* Adds a SkeletonModificationStack3D resource
* This node oversees the execution of the modifications and acts as a bridge of sorts for the modifications to the Skeleton3D node
* Adds SkeletonModification3D resources for LookAt, CCDIK, FABRIK, Jiggle, and TwoBoneIK
* Each modification is in it's own file
* Several changes to Skeletons, listed below:
* Added local_pose_override, which acts just like global_pose_override but keeps bone-child relationships intract
* So if you move a bone using local_pose_override, all of the bones that are children will also be moved. This is different than global_pose_override, which only affects the individual bone
* Internally bones keep track of their children. This removes the need of a processing list, makes it possible to update just a few select bones at a time, and makes it easier to traverse down the bone chain
* Additional functions added for converting from world transform to global poses, global poses to local poses, and all the same changes but backwards (local to global, global to world). This makes it much easier to work with bone transforms without needing to think too much about how to convert them.
* New signal added, bone_pose_changed, that can be used to tell if a specific bone changed its transform. Needed for BoneAttachment3D
* Added functions for getting the forward position of a bone
* BoneAttachment3D node refactored heavily
* BoneAttachment3D node is now completely standalone in its functionality.
* This makes the code easier and less interconnected, as well as allowing them to function properly without being direct children of Skeleton3D nodes
* BoneAttachment3D now can be set either using the index or the bone name.
* BoneAttachment3D nodes can now set the bone transform instead of just following it. This is disabled by default for compatibility
* BoneAttachment3D now shows a warning when not configured correctly
* Added rotate_to_align function in Basis
* Added class reference documentation for all changes
- TwistedTwigleg
https://github.com/godotengine/godot/commit/5ffed49907618e3c7e7e2bddddcc8449d0b090a6
Note: It still needs some work.
2022-08-10 01:01:38 +02:00
|
|
|
p_list->push_back(
|
|
|
|
PropertyInfo(Variant::OBJECT, "modifications/" + itos(i),
|
|
|
|
PROPERTY_HINT_RESOURCE_TYPE,
|
|
|
|
"SkeletonModification3D",
|
|
|
|
PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkeletonModificationStack3D::_set(const StringName &p_path, const Variant &p_value) {
|
|
|
|
String path = p_path;
|
|
|
|
|
|
|
|
if (path.begins_with("modifications/")) {
|
|
|
|
int mod_idx = path.get_slicec('/', 1).to_int();
|
|
|
|
set_modification(mod_idx, p_value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkeletonModificationStack3D::_get(const StringName &p_path, Variant &r_ret) const {
|
|
|
|
String path = p_path;
|
|
|
|
|
|
|
|
if (path.begins_with("modifications/")) {
|
|
|
|
int mod_idx = path.get_slicec('/', 1).to_int();
|
|
|
|
r_ret = get_modification(mod_idx);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::setup() {
|
|
|
|
if (is_setup) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skeleton != nullptr) {
|
|
|
|
is_setup = true;
|
2022-08-10 11:34:12 +02:00
|
|
|
for (int i = 0; i < modifications.size(); i++) {
|
Backported from Godot 4: New and improved IK system for Skeleton3D
This PR and commit adds a new IK system for 3D with the Skeleton3D node
that adds several new IK solvers, as well as additional changes and functionality
for making bone manipulation in Godot easier.
This work was sponsored by GSoC 2020 and TwistedTwigleg
Full list of changes:
* Adds a SkeletonModification3D resource
* This resource is the base where all IK code is written and executed
* Adds a SkeletonModificationStack3D resource
* This node oversees the execution of the modifications and acts as a bridge of sorts for the modifications to the Skeleton3D node
* Adds SkeletonModification3D resources for LookAt, CCDIK, FABRIK, Jiggle, and TwoBoneIK
* Each modification is in it's own file
* Several changes to Skeletons, listed below:
* Added local_pose_override, which acts just like global_pose_override but keeps bone-child relationships intract
* So if you move a bone using local_pose_override, all of the bones that are children will also be moved. This is different than global_pose_override, which only affects the individual bone
* Internally bones keep track of their children. This removes the need of a processing list, makes it possible to update just a few select bones at a time, and makes it easier to traverse down the bone chain
* Additional functions added for converting from world transform to global poses, global poses to local poses, and all the same changes but backwards (local to global, global to world). This makes it much easier to work with bone transforms without needing to think too much about how to convert them.
* New signal added, bone_pose_changed, that can be used to tell if a specific bone changed its transform. Needed for BoneAttachment3D
* Added functions for getting the forward position of a bone
* BoneAttachment3D node refactored heavily
* BoneAttachment3D node is now completely standalone in its functionality.
* This makes the code easier and less interconnected, as well as allowing them to function properly without being direct children of Skeleton3D nodes
* BoneAttachment3D now can be set either using the index or the bone name.
* BoneAttachment3D nodes can now set the bone transform instead of just following it. This is disabled by default for compatibility
* BoneAttachment3D now shows a warning when not configured correctly
* Added rotate_to_align function in Basis
* Added class reference documentation for all changes
- TwistedTwigleg
https://github.com/godotengine/godot/commit/5ffed49907618e3c7e7e2bddddcc8449d0b090a6
Note: It still needs some work.
2022-08-10 01:01:38 +02:00
|
|
|
if (!modifications[i].is_valid()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
modifications.write[i]->setup_modification(this);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
WARN_PRINT("Cannot setup SkeletonModificationStack3D: no skeleton set!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::execute(real_t p_delta, int p_execution_mode) {
|
|
|
|
ERR_FAIL_COND_MSG(!is_setup || skeleton == nullptr || is_queued_for_deletion(),
|
|
|
|
"Modification stack is not properly setup and therefore cannot execute!");
|
|
|
|
|
|
|
|
if (!skeleton->is_inside_tree()) {
|
|
|
|
ERR_PRINT_ONCE("Skeleton is not inside SceneTree! Cannot execute modification!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-10 11:34:12 +02:00
|
|
|
for (int i = 0; i < modifications.size(); i++) {
|
Backported from Godot 4: New and improved IK system for Skeleton3D
This PR and commit adds a new IK system for 3D with the Skeleton3D node
that adds several new IK solvers, as well as additional changes and functionality
for making bone manipulation in Godot easier.
This work was sponsored by GSoC 2020 and TwistedTwigleg
Full list of changes:
* Adds a SkeletonModification3D resource
* This resource is the base where all IK code is written and executed
* Adds a SkeletonModificationStack3D resource
* This node oversees the execution of the modifications and acts as a bridge of sorts for the modifications to the Skeleton3D node
* Adds SkeletonModification3D resources for LookAt, CCDIK, FABRIK, Jiggle, and TwoBoneIK
* Each modification is in it's own file
* Several changes to Skeletons, listed below:
* Added local_pose_override, which acts just like global_pose_override but keeps bone-child relationships intract
* So if you move a bone using local_pose_override, all of the bones that are children will also be moved. This is different than global_pose_override, which only affects the individual bone
* Internally bones keep track of their children. This removes the need of a processing list, makes it possible to update just a few select bones at a time, and makes it easier to traverse down the bone chain
* Additional functions added for converting from world transform to global poses, global poses to local poses, and all the same changes but backwards (local to global, global to world). This makes it much easier to work with bone transforms without needing to think too much about how to convert them.
* New signal added, bone_pose_changed, that can be used to tell if a specific bone changed its transform. Needed for BoneAttachment3D
* Added functions for getting the forward position of a bone
* BoneAttachment3D node refactored heavily
* BoneAttachment3D node is now completely standalone in its functionality.
* This makes the code easier and less interconnected, as well as allowing them to function properly without being direct children of Skeleton3D nodes
* BoneAttachment3D now can be set either using the index or the bone name.
* BoneAttachment3D nodes can now set the bone transform instead of just following it. This is disabled by default for compatibility
* BoneAttachment3D now shows a warning when not configured correctly
* Added rotate_to_align function in Basis
* Added class reference documentation for all changes
- TwistedTwigleg
https://github.com/godotengine/godot/commit/5ffed49907618e3c7e7e2bddddcc8449d0b090a6
Note: It still needs some work.
2022-08-10 01:01:38 +02:00
|
|
|
if (!modifications[i].is_valid()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modifications[i]->get_execution_mode() == p_execution_mode) {
|
|
|
|
modifications.write[i]->execute(p_delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::enable_all_modifications(bool p_enabled) {
|
2022-08-10 11:34:12 +02:00
|
|
|
for (int i = 0; i < modifications.size(); i++) {
|
Backported from Godot 4: New and improved IK system for Skeleton3D
This PR and commit adds a new IK system for 3D with the Skeleton3D node
that adds several new IK solvers, as well as additional changes and functionality
for making bone manipulation in Godot easier.
This work was sponsored by GSoC 2020 and TwistedTwigleg
Full list of changes:
* Adds a SkeletonModification3D resource
* This resource is the base where all IK code is written and executed
* Adds a SkeletonModificationStack3D resource
* This node oversees the execution of the modifications and acts as a bridge of sorts for the modifications to the Skeleton3D node
* Adds SkeletonModification3D resources for LookAt, CCDIK, FABRIK, Jiggle, and TwoBoneIK
* Each modification is in it's own file
* Several changes to Skeletons, listed below:
* Added local_pose_override, which acts just like global_pose_override but keeps bone-child relationships intract
* So if you move a bone using local_pose_override, all of the bones that are children will also be moved. This is different than global_pose_override, which only affects the individual bone
* Internally bones keep track of their children. This removes the need of a processing list, makes it possible to update just a few select bones at a time, and makes it easier to traverse down the bone chain
* Additional functions added for converting from world transform to global poses, global poses to local poses, and all the same changes but backwards (local to global, global to world). This makes it much easier to work with bone transforms without needing to think too much about how to convert them.
* New signal added, bone_pose_changed, that can be used to tell if a specific bone changed its transform. Needed for BoneAttachment3D
* Added functions for getting the forward position of a bone
* BoneAttachment3D node refactored heavily
* BoneAttachment3D node is now completely standalone in its functionality.
* This makes the code easier and less interconnected, as well as allowing them to function properly without being direct children of Skeleton3D nodes
* BoneAttachment3D now can be set either using the index or the bone name.
* BoneAttachment3D nodes can now set the bone transform instead of just following it. This is disabled by default for compatibility
* BoneAttachment3D now shows a warning when not configured correctly
* Added rotate_to_align function in Basis
* Added class reference documentation for all changes
- TwistedTwigleg
https://github.com/godotengine/godot/commit/5ffed49907618e3c7e7e2bddddcc8449d0b090a6
Note: It still needs some work.
2022-08-10 01:01:38 +02:00
|
|
|
if (!modifications[i].is_valid()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
modifications.write[i]->set_enabled(p_enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<SkeletonModification3D> SkeletonModificationStack3D::get_modification(int p_mod_idx) const {
|
|
|
|
const int modifications_size = modifications.size();
|
|
|
|
ERR_FAIL_INDEX_V(p_mod_idx, modifications_size, nullptr);
|
|
|
|
return modifications[p_mod_idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::add_modification(Ref<SkeletonModification3D> p_mod) {
|
|
|
|
ERR_FAIL_COND(p_mod.is_null());
|
|
|
|
p_mod->setup_modification(this);
|
|
|
|
modifications.push_back(p_mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::delete_modification(int p_mod_idx) {
|
|
|
|
const int modifications_size = modifications.size();
|
|
|
|
ERR_FAIL_INDEX(p_mod_idx, modifications_size);
|
|
|
|
modifications.remove(p_mod_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::set_modification(int p_mod_idx, Ref<SkeletonModification3D> p_mod) {
|
|
|
|
const int modifications_size = modifications.size();
|
|
|
|
ERR_FAIL_INDEX(p_mod_idx, modifications_size);
|
|
|
|
|
|
|
|
if (p_mod == nullptr) {
|
|
|
|
modifications.remove(p_mod_idx);
|
|
|
|
} else {
|
|
|
|
p_mod->setup_modification(this);
|
|
|
|
modifications.write[p_mod_idx] = p_mod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::set_modification_count(int p_count) {
|
|
|
|
ERR_FAIL_COND_MSG(p_count < 0, "Modification count cannot be less than zero.");
|
|
|
|
modifications.resize(p_count);
|
|
|
|
property_list_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
int SkeletonModificationStack3D::get_modification_count() const {
|
|
|
|
return modifications.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::set_skeleton(Skeleton *p_skeleton) {
|
|
|
|
skeleton = p_skeleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
Skeleton *SkeletonModificationStack3D::get_skeleton() const {
|
|
|
|
return skeleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkeletonModificationStack3D::get_is_setup() const {
|
|
|
|
return is_setup;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::set_enabled(bool p_enabled) {
|
|
|
|
enabled = p_enabled;
|
|
|
|
|
|
|
|
if (!enabled && is_setup && skeleton != nullptr) {
|
|
|
|
skeleton->clear_bones_local_pose_override();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkeletonModificationStack3D::get_enabled() const {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::set_strength(real_t p_strength) {
|
|
|
|
ERR_FAIL_COND_MSG(p_strength < 0, "Strength cannot be less than zero!");
|
|
|
|
ERR_FAIL_COND_MSG(p_strength > 1, "Strength cannot be more than one!");
|
|
|
|
strength = p_strength;
|
|
|
|
}
|
|
|
|
|
|
|
|
real_t SkeletonModificationStack3D::get_strength() const {
|
|
|
|
return strength;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonModificationStack3D::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("setup"), &SkeletonModificationStack3D::setup);
|
|
|
|
ClassDB::bind_method(D_METHOD("execute", "delta", "execution_mode"), &SkeletonModificationStack3D::execute);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("enable_all_modifications", "enabled"), &SkeletonModificationStack3D::enable_all_modifications);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_modification", "mod_idx"), &SkeletonModificationStack3D::get_modification);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_modification", "modification"), &SkeletonModificationStack3D::add_modification);
|
|
|
|
ClassDB::bind_method(D_METHOD("delete_modification", "mod_idx"), &SkeletonModificationStack3D::delete_modification);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_modification", "mod_idx", "modification"), &SkeletonModificationStack3D::set_modification);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_modification_count", "count"), &SkeletonModificationStack3D::set_modification_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_modification_count"), &SkeletonModificationStack3D::get_modification_count);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_is_setup"), &SkeletonModificationStack3D::get_is_setup);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &SkeletonModificationStack3D::set_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_enabled"), &SkeletonModificationStack3D::get_enabled);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_strength", "strength"), &SkeletonModificationStack3D::set_strength);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_strength"), &SkeletonModificationStack3D::get_strength);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_skeleton"), &SkeletonModificationStack3D::get_skeleton);
|
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "get_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "0, 1, 0.001"), "set_strength", "get_strength");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "modification_count", PROPERTY_HINT_RANGE, "0, 100, 1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_modification_count", "get_modification_count");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkeletonModificationStack3D::SkeletonModificationStack3D() {
|
Ported from Godot4: New and improved IK system for Skeleton2D
This PR and commit adds a new IK system for 2D with the Skeleton2D node
that adds several new IK solvers, a way to control bones in a Skeleton2D
node similar to that in Skeleton3D. It also adds additional changes
and functionality.
This work was sponsored by GSoC 2020 and TwistedTwigleg.
Full list of changes:
* Adds a SkeletonModifier2D resource
* This resource is the base where all IK code is written and executed
* Has a function for clamping angles, since it is so commonly used
* Modifiers are unique when duplicated so it works with instancing
* Adds a SkeletonModifierStack2D resource
* This resource manages a series of SkeletonModification2Ds
* This is what the Skeleton2D directly interfaces with to make IK possible
* Adds SkeletonModifier2D resources for LookAt, CCDIK, FABRIK, Jiggle, and TwoBoneIK
* Each modification is in its own file
* There is also a SkeletonModifier2D resource that acts as a stack for using multiple stacks together
* Adds a PhysicalBone2D node
* Works similar to the PhysicalBone3D node, but uses a RigidBody2D node
* Changes to Skeleton2D listed below:
* Skeleton2D now holds a single SkeletonModificationStack2D for IK
* Skeleton2D now has a local_pose_override, which overrides the Bone2D position similar to how the overrides work in Skeleton3D
* Changes to Bone2D listed below:
* The default_length property has been changed to length. Length is the length of the bone to its child bone node
* New bone_angle property, which is the angle the bone has to its first child bone node
* Bone2D caches its transform when not modified by IK for IK interpolation purposes
* Bone2D draws its own editor gizmo, though this is stated to change in the future
* Changes to CanvasItemEditor listed below:
* Bone2D gizmo drawing code removed
* The 2D IK code is removed. Now Bone2D is the only bone system for 2D
* Transform2D now has a looking_at function for rotating to face a position
* Two new node notifications: NOTIFICATION_EDITOR_PRE_SAVE and NOTIFICATION_EDITOR_POST_SAVE
* These notifications only are called in the editor right before and after saving a scene
* Needed for not saving the IK position when executing IK in the editor
* Documentation for all the changes listed above.
- TwistedTwigleg
https://github.com/godotengine/godot/commit/8aa3c2f0918707c2243b86ac53c02c27ceb9a266
2022-08-18 18:47:30 +02:00
|
|
|
modifications_count = 0;
|
Backported from Godot 4: New and improved IK system for Skeleton3D
This PR and commit adds a new IK system for 3D with the Skeleton3D node
that adds several new IK solvers, as well as additional changes and functionality
for making bone manipulation in Godot easier.
This work was sponsored by GSoC 2020 and TwistedTwigleg
Full list of changes:
* Adds a SkeletonModification3D resource
* This resource is the base where all IK code is written and executed
* Adds a SkeletonModificationStack3D resource
* This node oversees the execution of the modifications and acts as a bridge of sorts for the modifications to the Skeleton3D node
* Adds SkeletonModification3D resources for LookAt, CCDIK, FABRIK, Jiggle, and TwoBoneIK
* Each modification is in it's own file
* Several changes to Skeletons, listed below:
* Added local_pose_override, which acts just like global_pose_override but keeps bone-child relationships intract
* So if you move a bone using local_pose_override, all of the bones that are children will also be moved. This is different than global_pose_override, which only affects the individual bone
* Internally bones keep track of their children. This removes the need of a processing list, makes it possible to update just a few select bones at a time, and makes it easier to traverse down the bone chain
* Additional functions added for converting from world transform to global poses, global poses to local poses, and all the same changes but backwards (local to global, global to world). This makes it much easier to work with bone transforms without needing to think too much about how to convert them.
* New signal added, bone_pose_changed, that can be used to tell if a specific bone changed its transform. Needed for BoneAttachment3D
* Added functions for getting the forward position of a bone
* BoneAttachment3D node refactored heavily
* BoneAttachment3D node is now completely standalone in its functionality.
* This makes the code easier and less interconnected, as well as allowing them to function properly without being direct children of Skeleton3D nodes
* BoneAttachment3D now can be set either using the index or the bone name.
* BoneAttachment3D nodes can now set the bone transform instead of just following it. This is disabled by default for compatibility
* BoneAttachment3D now shows a warning when not configured correctly
* Added rotate_to_align function in Basis
* Added class reference documentation for all changes
- TwistedTwigleg
https://github.com/godotengine/godot/commit/5ffed49907618e3c7e7e2bddddcc8449d0b090a6
Note: It still needs some work.
2022-08-10 01:01:38 +02:00
|
|
|
}
|
2022-08-10 10:17:02 +02:00
|
|
|
|
|
|
|
SkeletonModificationStack3D::~SkeletonModificationStack3D() {
|
|
|
|
}
|