Skip to content

Commit

Permalink
Refactor IK Kusudama 3D class
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Dec 2, 2023
1 parent d6355bc commit 8f38392
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 54 deletions.
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
50 changes: 0 additions & 50 deletions src/many_bone_ik_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,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 @@ -370,9 +367,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 @@ -449,8 +443,6 @@ 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_stabilization_passes", "passes"), &ManyBoneIK3D::set_stabilization_passes);
Expand Down Expand Up @@ -1175,45 +1167,3 @@ void ManyBoneIK3D::add_constraint() {
bone_resistance.write[old_count] = 0.0f;
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();
}
}
2 changes: 0 additions & 2 deletions src/many_bone_ik_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,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 8f38392

Please sign in to comment.