Skip to content

Commit

Permalink
git subrepo pull (merge) modules/many_bone_ik
Browse files Browse the repository at this point in the history
subrepo:
  subdir:   "modules/many_bone_ik"
  merged:   "8dd4a387c2"
upstream:
  origin:   "https://github.com/V-Sekai/many_bone_ik.git"
  branch:   "main"
  commit:   "68812c728d"
git-subrepo:
  version:  "0.4.6"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "110b9eb"
  • Loading branch information
fire committed Nov 5, 2023
2 parents c6e589a + 68812c7 commit 5be5511
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 155 deletions.
31 changes: 0 additions & 31 deletions src/ik_kusudama_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,34 +427,3 @@ Quaternion IKKusudama3D::clamp_to_quadrance_angle(Quaternion p_rotation, double
}
return rotation.slerp(clamped_rotation, over_limit);
}

void IKKusudama3D::set_current_twist_rotation(Ref<IKNode3D> p_godot_skeleton_aligned_transform, Ref<IKNode3D> p_bone_direction, Ref<IKNode3D> p_twist_transform, real_t p_rotation) {
p_rotation = 1 / Math_TAU * p_rotation;
Quaternion align_rot_inv = p_twist_transform->get_global_transform().basis.inverse().get_rotation_quaternion();
Quaternion align_rot = align_rot_inv * p_bone_direction->get_global_transform().basis.get_rotation_quaternion();
Quaternion twist_rotation, swing_rotation;
get_swing_twist(align_rot, Vector3(0, 1, 0), swing_rotation, twist_rotation);
Vector3 axis = (twist_max_vec - twist_min_vec).normalized();
twist_rotation = Quaternion(axis, p_rotation);
Quaternion recomposition = swing_rotation * twist_rotation;
Quaternion parent_global_inverse = p_godot_skeleton_aligned_transform->get_parent()->get_global_transform().basis.inverse().get_rotation_quaternion();
Basis rotation_basis = parent_global_inverse * (recomposition);
Transform3D ik_transform = p_godot_skeleton_aligned_transform->get_transform();
p_godot_skeleton_aligned_transform->set_transform(Transform3D(rotation_basis, ik_transform.origin));
}

real_t IKKusudama3D::get_current_twist_rotation(Ref<IKNode3D> p_godot_skeleton_aligned_transform, Ref<IKNode3D> p_bone_direction, Ref<IKNode3D> p_twist_transform) {
Quaternion global_twist_center = p_twist_transform->get_global_transform().basis.inverse().get_rotation_quaternion() * twist_center_rot;
Quaternion align_rot = global_twist_center * p_bone_direction->get_global_transform().basis.get_rotation_quaternion();
Quaternion twist_rotation, swing_rotation;
get_swing_twist(align_rot, Vector3(0, 1, 0), swing_rotation, twist_rotation);
if (range_angle == 0.0) {
return 0;
}
Vector3 z_axis = Vector3(0.0f, 0.0f, 1.0f);
Vector3 twist_vec = twist_rotation.xform(z_axis);
real_t min_angle = twist_vec.angle_to(twist_min_vec);
real_t max_angle = twist_vec.angle_to(twist_max_vec);
real_t center_angle = (min_angle + max_angle) / 2.0;
return center_angle / Math_TAU;
}
2 changes: 0 additions & 2 deletions src/ik_kusudama_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ class IKKusudama3D : public Resource {
Quaternion &r_twist);

public:
real_t get_current_twist_rotation(Ref<IKNode3D> p_godot_skeleton_aligned_transform, Ref<IKNode3D> p_bone_direction, Ref<IKNode3D> p_twist_transform);
void set_current_twist_rotation(Ref<IKNode3D> p_godot_skeleton_aligned_transform, Ref<IKNode3D> p_bone_direction, Ref<IKNode3D> p_twist_transform, real_t p_rotation);
double angle_to_twist_center(Ref<IKNode3D> bone_direction, Ref<IKNode3D> limiting_axes);
/**
* Presumes the input axes are the bone's localAxes, and rotates
Expand Down
114 changes: 1 addition & 113 deletions src/many_bone_ik_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ void ManyBoneIK3D::_get_property_list(List<PropertyInfo> *p_list) const {
PropertyInfo(Variant::FLOAT, "constraints/" + itos(constraint_i) + "/twist_from", PROPERTY_HINT_RANGE, "-359.9,359.9,0.1,radians,exp", constraint_usage));
p_list->push_back(
PropertyInfo(Variant::FLOAT, "constraints/" + itos(constraint_i) + "/twist_range", PROPERTY_HINT_RANGE, "-359.9,359.9,0.1,radians,exp", constraint_usage));
p_list->push_back(
PropertyInfo(Variant::FLOAT, "constraints/" + itos(constraint_i) + "/twist_current", PROPERTY_HINT_RANGE, "-359.9,359.9,0.1,radians,exp", constraint_usage));
p_list->push_back(
PropertyInfo(Variant::INT, "constraints/" + itos(constraint_i) + "/kusudama_limit_cone_count", PROPERTY_HINT_RANGE, "0,10,1", constraint_usage | PROPERTY_USAGE_ARRAY | PROPERTY_USAGE_READ_ONLY,
"Limit Cones,constraints/" + itos(constraint_i) + "/kusudama_limit_cone/"));
Expand Down Expand Up @@ -281,9 +279,6 @@ bool ManyBoneIK3D::_get(const StringName &p_name, Variant &r_ret) const {
} else if (what == "twist_range") {
r_ret = get_kusudama_twist(index).y;
return true;
} else if (what == "twist_current") {
r_ret = get_kusudama_twist_current(index);
return true;
} else if (what == "kusudama_limit_cone_count") {
r_ret = get_kusudama_limit_cone_count(index);
return true;
Expand Down Expand Up @@ -367,9 +362,6 @@ bool ManyBoneIK3D::_set(const StringName &p_name, const Variant &p_value) {
Vector2 twist_range = get_kusudama_twist(index);
set_kusudama_twist(index, Vector2(twist_range.x, p_value));
return true;
} else if (what == "twist_current") {
set_kusudama_twist_current(index, p_value);
return true;
} else if (what == "kusudama_limit_cone_count") {
set_kusudama_limit_cone_count(index, p_value);
return true;
Expand Down Expand Up @@ -446,16 +438,8 @@ void ManyBoneIK3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_bone_count"), &ManyBoneIK3D::get_bone_count);
ClassDB::bind_method(D_METHOD("set_constraint_mode", "enabled"), &ManyBoneIK3D::set_constraint_mode);
ClassDB::bind_method(D_METHOD("get_constraint_mode"), &ManyBoneIK3D::get_constraint_mode);
ClassDB::bind_method(D_METHOD("get_kusudama_twist_current", "index"), &ManyBoneIK3D::get_kusudama_twist_current);
ClassDB::bind_method(D_METHOD("set_kusudama_twist_current", "twist_current"), &ManyBoneIK3D::get_kusudama_twist_current);
ClassDB::bind_method(D_METHOD("set_ui_selected_bone", "bone"), &ManyBoneIK3D::set_ui_selected_bone);
ClassDB::bind_method(D_METHOD("get_ui_selected_bone"), &ManyBoneIK3D::get_ui_selected_bone);
ClassDB::bind_method(D_METHOD("set_twist_constraint_defaults", "defaults"), &ManyBoneIK3D::set_twist_constraint_defaults);
ClassDB::bind_method(D_METHOD("get_twist_constraint_defaults"), &ManyBoneIK3D::get_twist_constraint_defaults);
ClassDB::bind_method(D_METHOD("set_orientation_constraint_defaults", "defaults"), &ManyBoneIK3D::set_orientation_constraint_defaults);
ClassDB::bind_method(D_METHOD("get_orientation_constraint_defaults"), &ManyBoneIK3D::get_orientation_constraint_defaults);
ClassDB::bind_method(D_METHOD("set_bone_direction_constraint_defaults", "defaults"), &ManyBoneIK3D::set_bone_direction_constraint_defaults);
ClassDB::bind_method(D_METHOD("get_bone_direction_constraint_defaults"), &ManyBoneIK3D::get_bone_direction_constraint_defaults);
ClassDB::bind_method(D_METHOD("set_stabilization_passes", "passes"), &ManyBoneIK3D::set_stabilization_passes);
ClassDB::bind_method(D_METHOD("get_stabilization_passes"), &ManyBoneIK3D::get_stabilization_passes);
ClassDB::bind_method(D_METHOD("set_pin_bone_name", "index", "name"), &ManyBoneIK3D::set_pin_bone_name);
Expand All @@ -466,10 +450,7 @@ void ManyBoneIK3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "constraint_mode"), "set_constraint_mode", "get_constraint_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "ui_selected_bone", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_ui_selected_bone", "get_ui_selected_bone");
ADD_PROPERTY(PropertyInfo(Variant::INT, "stabilization_passes"), "set_stabilization_passes", "get_stabilization_passes");
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "twist_constraint_defaults", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_twist_constraint_defaults", "get_twist_constraint_defaults");
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "orientation_constraint_defaults", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_orientation_constraint_defaults", "get_orientation_constraint_defaults");
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "bone_direction_constraint_defaults", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_bone_direction_constraint_defaults", "get_bone_direction_constraint_defaults");
}
}

ManyBoneIK3D::ManyBoneIK3D() {
}
Expand Down Expand Up @@ -722,12 +703,6 @@ void ManyBoneIK3D::execute(real_t delta) {
if (is_dirty) {
skeleton_changed(get_skeleton());
is_dirty = false;
for (int32_t constraint_i = 0; constraint_i < get_constraint_count(); constraint_i++) {
String constraint_name = get_constraint_name(constraint_i);
twist_constraint_defaults[constraint_name] = get_constraint_twist_transform(constraint_i);
orientation_constraint_defaults[constraint_name] = get_constraint_orientation_transform(constraint_i);
bone_direction_constraint_defaults[constraint_name] = get_bone_direction_transform(constraint_i);
}
}
if (bone_list.size()) {
Ref<IKNode3D> root_ik_bone = bone_list.write[0]->get_ik_transform();
Expand Down Expand Up @@ -822,23 +797,6 @@ void ManyBoneIK3D::skeleton_changed(Skeleton3D *p_skeleton) {
break;
}
}
if (!twist_constraint_defaults.size() && !orientation_constraint_defaults.size() && !bone_direction_constraint_defaults.size()) {
for (Ref<IKBone3D> &ik_bone_3d : bone_list) {
ik_bone_3d->update_default_constraint_transform();
}
for (int32_t constraint_i = 0; constraint_i < get_constraint_count(); ++constraint_i) {
String constraint_name = get_constraint_name(constraint_i);
twist_constraint_defaults[constraint_name] = get_constraint_twist_transform(constraint_i);
orientation_constraint_defaults[constraint_name] = get_constraint_orientation_transform(constraint_i);
bone_direction_constraint_defaults[constraint_name] = get_bone_direction_transform(constraint_i);
}
}
for (int32_t constraint_i = 0; constraint_i < get_constraint_count(); ++constraint_i) {
String constraint_name = get_constraint_name(constraint_i);
set_constraint_twist_transform(constraint_i, twist_constraint_defaults[constraint_name]);
set_constraint_orientation_transform(constraint_i, orientation_constraint_defaults[constraint_name]);
set_bone_direction_transform(constraint_i, bone_direction_constraint_defaults[constraint_name]);
}
if (queue_debug_skeleton) {
queue_debug_skeleton = false;
}
Expand Down Expand Up @@ -1125,9 +1083,6 @@ void ManyBoneIK3D::register_skeleton() {
void ManyBoneIK3D::reset_constraints() {
Skeleton3D *skeleton = get_skeleton();
if (skeleton) {
orientation_constraint_defaults.clear();
twist_constraint_defaults.clear();
bone_direction_constraint_defaults.clear();
int32_t saved_pin_count = get_pin_count();
set_pin_count(0);
set_pin_count(saved_pin_count);
Expand Down Expand Up @@ -1165,32 +1120,6 @@ int32_t ManyBoneIK3D::get_stabilization_passes() {
return stabilize_passes;
}

void ManyBoneIK3D::set_twist_constraint_defaults(Dictionary p_defaults) {
twist_constraint_defaults = p_defaults;
set_dirty();
}

Dictionary ManyBoneIK3D::get_twist_constraint_defaults() {
return twist_constraint_defaults;
}

void ManyBoneIK3D::set_orientation_constraint_defaults(Dictionary p_defaults) {
orientation_constraint_defaults = p_defaults;
}

Dictionary ManyBoneIK3D::get_orientation_constraint_defaults() {
return orientation_constraint_defaults;
}

void ManyBoneIK3D::set_bone_direction_constraint_defaults(Dictionary p_defaults) {
bone_direction_constraint_defaults = p_defaults;
set_dirty();
}

Dictionary ManyBoneIK3D::get_bone_direction_constraint_defaults() {
return bone_direction_constraint_defaults;
}

Transform3D ManyBoneIK3D::get_godot_skeleton_transform_inverse() {
return godot_skeleton_transform_inverse;
}
Expand Down Expand Up @@ -1238,44 +1167,3 @@ void ManyBoneIK3D::add_constraint() {
set_dirty();
}

real_t ManyBoneIK3D::get_kusudama_twist_current(int32_t p_index) const {
ERR_FAIL_INDEX_V(p_index, constraint_names.size(), 0.0f);
String bone_name = constraint_names[p_index];
if (!segmented_skeletons.size()) {
return 0;
}
for (Ref<IKBoneSegment3D> segmented_skeleton : segmented_skeletons) {
if (segmented_skeleton.is_null()) {
continue;
}
Ref<IKBone3D> ik_bone = segmented_skeleton->get_ik_bone(get_skeleton()->find_bone(bone_name));
if (ik_bone.is_null()) {
continue;
}
if (ik_bone->get_constraint().is_null()) {
continue;
}
return ik_bone->get_constraint()->get_current_twist_rotation(ik_bone->get_ik_transform(), ik_bone->get_bone_direction_transform(), ik_bone->get_constraint_twist_transform());
}
return 0;
}

void ManyBoneIK3D::set_kusudama_twist_current(int32_t p_index, real_t p_rotation) {
ERR_FAIL_INDEX(p_index, constraint_names.size());
String bone_name = constraint_names[p_index];
for (Ref<IKBoneSegment3D> segmented_skeleton : segmented_skeletons) {
if (segmented_skeleton.is_null()) {
continue;
}
Ref<IKBone3D> ik_bone = segmented_skeleton->get_ik_bone(get_skeleton()->find_bone(bone_name));
if (ik_bone.is_null()) {
continue;
}
if (ik_bone->get_constraint().is_null()) {
continue;
}
ik_bone->get_constraint()->set_current_twist_rotation(ik_bone->get_ik_transform(), ik_bone->get_bone_direction_transform(), ik_bone->get_constraint_twist_transform(), p_rotation);
ik_bone->set_skeleton_bone_pose(get_skeleton());
notify_property_list_changed();
}
}
9 changes: 0 additions & 9 deletions src/many_bone_ik_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class ManyBoneIK3DState;
class ManyBoneIK3D : public Node3D {
GDCLASS(ManyBoneIK3D, Node3D);

Dictionary twist_constraint_defaults, orientation_constraint_defaults, bone_direction_constraint_defaults;
bool is_constraint_mode = false;
NodePath skeleton_path;
Vector<Ref<IKBoneSegment3D>> segmented_skeletons;
Expand Down Expand Up @@ -105,12 +104,6 @@ class ManyBoneIK3D : public Node3D {
void add_constraint();
void set_stabilization_passes(int32_t p_passes);
int32_t get_stabilization_passes();
void set_twist_constraint_defaults(Dictionary p_defaults);
Dictionary get_twist_constraint_defaults();
void set_orientation_constraint_defaults(Dictionary p_defaults);
Dictionary get_orientation_constraint_defaults();
void set_bone_direction_constraint_defaults(Dictionary p_defaults);
Dictionary get_bone_direction_constraint_defaults();
Transform3D get_godot_skeleton_transform_inverse();
Ref<IKNode3D> get_godot_skeleton_transform();
void set_ui_selected_bone(int32_t p_ui_selected_bone);
Expand Down Expand Up @@ -168,8 +161,6 @@ class ManyBoneIK3D : public Node3D {
void set_kusudama_limit_cone_count(int32_t p_constraint_index, int32_t p_count);
void set_kusudama_limit_cone_center(int32_t p_constraint_index, int32_t p_index, Vector3 p_center);
void set_kusudama_limit_cone_radius(int32_t p_constraint_index, int32_t p_index, float p_radius);
real_t get_kusudama_twist_current(int32_t p_index) const;
void set_kusudama_twist_current(int32_t p_index, real_t p_rotation);
ManyBoneIK3D();
~ManyBoneIK3D();
void set_dirty();
Expand Down

0 comments on commit 5be5511

Please sign in to comment.