Skip to content

Commit

Permalink
Revert "Expose the segmented skeleton."
Browse files Browse the repository at this point in the history
This reverts commit 41b4d8a.
  • Loading branch information
fire committed Jan 8, 2023
1 parent 41b4d8a commit cb3ca28
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 147 deletions.
2 changes: 1 addition & 1 deletion modules/many_bone_ik/doc_classes/IKBoneSegment3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<tutorials>
</tutorials>
<methods>
<method name="find_ik_bone" qualifiers="const">
<method name="get_ik_bone" qualifiers="const">
<return type="IKBone3D" />
<param index="0" name="bone" type="int" />
<description>
Expand Down
8 changes: 3 additions & 5 deletions modules/many_bone_ik/editor/many_bone_ik_3d_gizmo_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include "many_bone_ik_3d_gizmo_plugin.h"

#include "core/variant/typed_array.h"
#include "modules/many_bone_ik/src/ik_kusudama_3d.h"

#include "core/io/resource_saver.h"
Expand Down Expand Up @@ -98,9 +97,8 @@ void ManyBoneIK3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Vector<int> bones_to_process = many_bone_ik_skeleton->get_parentless_bones();
int bones_to_process_i = 0;
Vector<BoneId> processing_bones;
TypedArray<IKBoneSegment3D> bone_segments = many_bone_ik->get_child_segments();
for (int32_t segment_i = 0; segment_i < bone_segments.size(); segment_i++) {
Ref<IKBoneSegment3D> bone_segment = bone_segments[segment_i];
Vector<Ref<IKBoneSegment3D>> bone_segments = many_bone_ik->get_segmented_skeletons();
for (Ref<IKBoneSegment3D> bone_segment : bone_segments) {
if (bone_segment.is_null()) {
continue;
}
Expand All @@ -115,7 +113,7 @@ void ManyBoneIK3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
}
Color current_bone_color = bone_color;
for (BoneId bone_i : bones_to_process) {
Ref<IKBone3D> ik_bone = bone_segment->find_ik_bone(bone_i);
Ref<IKBone3D> ik_bone = bone_segment->get_ik_bone(bone_i);
if (ik_bone.is_null()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ void ManyBoneIK3DHandleGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Vector<int> bones_to_process = many_bone_ik_skeleton->get_parentless_bones();
int bones_to_process_i = 0;
Vector<BoneId> processing_bones;
TypedArray<IKBoneSegment3D> bone_segments = many_bone_ik->get_child_segments();
for (int32_t segment_i = 0; segment_i < bone_segments.size(); segment_i++) {
Ref<IKBoneSegment3D> bone_segment = bone_segments[segment_i];
Vector<Ref<IKBoneSegment3D>> bone_segments = many_bone_ik->get_segmented_skeletons();
for (Ref<IKBoneSegment3D> bone_segment : bone_segments) {
if (bone_segment.is_null()) {
continue;
}
Expand All @@ -114,7 +113,7 @@ void ManyBoneIK3DHandleGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
}
Color current_bone_color = bone_color;
for (BoneId bone_i : bones_to_process) {
Ref<IKBone3D> ik_bone = bone_segment->find_ik_bone(bone_i);
Ref<IKBone3D> ik_bone = bone_segment->get_ik_bone(bone_i);
if (ik_bone.is_null()) {
continue;
}
Expand Down
90 changes: 22 additions & 68 deletions modules/many_bone_ik/src/ik_bone_segment_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@

#include "ik_bone_segment_3d.h"

#include "core/object/object.h"
#include "ik_effector_3d.h"
#include "ik_kusudama_3d.h"
#include "ik_limit_cone_3d.h"
#include "many_bone_ik_3d.h"
#include "math/ik_node_3d.h"
#include "scene/3d/skeleton_3d.h"

Ref<IKBone3D> IKBoneSegment3D::get_root() {
Ref<IKBone3D> IKBoneSegment3D::get_root() const {
return root;
}
Ref<IKBone3D> IKBoneSegment3D::get_tip() const {
Expand All @@ -50,7 +49,7 @@ bool IKBoneSegment3D::is_pinned() const {
return tip->is_pinned();
}

TypedArray<IKBoneSegment3D> IKBoneSegment3D::get_child_segments() const {
Vector<Ref<IKBoneSegment3D>> IKBoneSegment3D::get_child_segments() const {
return child_segments;
}

Expand Down Expand Up @@ -78,12 +77,7 @@ void IKBoneSegment3D::generate_default_segments_from_root(Vector<Ref<IKEffectorT
} else if (children.size() == 1) {
BoneId bone_id = children[0];
Ref<IKBone3D> next = Ref<IKBone3D>(memnew(IKBone3D(skeleton->get_bone_name(bone_id), skeleton, temp_tip, p_pins, p_many_bone_ik->get_default_damp(), p_many_bone_ik)));
Ref<IKBoneSegment3D> root_segment;
Ref<IKBoneSegment3D> current_segment = Ref<IKBoneSegment3D>(this);
while (current_segment.is_valid()) {
root_segment = current_segment;
current_segment = current_segment->get_parent_segment();
}
root_segment->bone_map[bone_id] = next;
temp_tip = next;
} else {
break;
Expand All @@ -101,8 +95,7 @@ void IKBoneSegment3D::generate_default_segments_from_root(Vector<Ref<IKEffectorT
void IKBoneSegment3D::create_bone_list(Vector<Ref<IKBone3D>> &p_list, bool p_recursive, bool p_debug_skeleton) const {
if (p_recursive) {
for (int32_t child_i = 0; child_i < child_segments.size(); child_i++) {
Ref<IKBoneSegment3D> segment = child_segments[child_i];
segment->create_bone_list(p_list, p_recursive, p_debug_skeleton);
child_segments[child_i]->create_bone_list(p_list, p_recursive, p_debug_skeleton);
}
}
Ref<IKBone3D> current_bone = tip;
Expand Down Expand Up @@ -146,9 +139,8 @@ void IKBoneSegment3D::update_pinned_list(Vector<Vector<real_t>> &r_weights) {
effector_list.push_back(tip->get_pin());
}
if (passthrough_factor > 0.0) {
for (int32_t segment_i = 0; segment_i < child_segments.size(); segment_i++) {
Ref<IKBoneSegment3D> segment = child_segments[segment_i];
effector_list.append_array(segment->effector_list);
for (Ref<IKBoneSegment3D> child : child_segments) {
effector_list.append_array(child->effector_list);
}
}
}
Expand Down Expand Up @@ -270,8 +262,7 @@ void IKBoneSegment3D::update_tip_headings(Ref<IKBone3D> p_for_bone, PackedVector
}

void IKBoneSegment3D::segment_solver(const Vector<float> &p_damp, float p_default_damp, bool p_constraint_mode) {
for (int32_t segment_i = 0; segment_i < child_segments.size(); segment_i++) {
Ref<IKBoneSegment3D> child = child_segments[segment_i];
for (Ref<IKBoneSegment3D> child : child_segments) {
if (child.is_null()) {
continue;
}
Expand Down Expand Up @@ -304,18 +295,7 @@ void IKBoneSegment3D::qcp_solver(const Vector<float> &p_damp, float p_default_da

void IKBoneSegment3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_pinned"), &IKBoneSegment3D::is_pinned);
ClassDB::bind_method(D_METHOD("find_ik_bone", "bone"), &IKBoneSegment3D::find_ik_bone);
ClassDB::bind_method(D_METHOD("get_root"), &IKBoneSegment3D::get_root);
ClassDB::bind_method(D_METHOD("get_default_stabilizing_pass_count"), &IKBoneSegment3D::get_default_stabilizing_pass_count);
ClassDB::bind_method(D_METHOD("set_default_stabilizing_pass_count", "count"), &IKBoneSegment3D::set_default_stabilizing_pass_count);
ClassDB::bind_method(D_METHOD("set_child_segments", "segment"), &IKBoneSegment3D::set_child_segments);
ClassDB::bind_method(D_METHOD("get_child_segments"), &IKBoneSegment3D::get_child_segments);
ClassDB::bind_method(D_METHOD("set_parent_segment", "segment"), &IKBoneSegment3D::set_parent_segment);
ClassDB::bind_method(D_METHOD("get_parent_segment"), &IKBoneSegment3D::get_parent_segment);

ADD_PROPERTY(PropertyInfo(Variant::INT, "stabilizing_pass_count"), "set_default_stabilizing_pass_count", "get_default_stabilizing_pass_count");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "child_segments", PROPERTY_HINT_ARRAY_TYPE, "IKBoneSegment3D"), "set_child_segments", "get_child_segments");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "parent_segment", PROPERTY_HINT_RESOURCE_TYPE, "IKBoneSegment3D"), "set_parent_segment", "get_parent_segment");
ClassDB::bind_method(D_METHOD("get_ik_bone", "bone"), &IKBoneSegment3D::get_ik_bone);
}

Ref<IKBoneSegment3D> IKBoneSegment3D::get_parent_segment() {
Expand All @@ -324,10 +304,16 @@ Ref<IKBoneSegment3D> IKBoneSegment3D::get_parent_segment() {

IKBoneSegment3D::IKBoneSegment3D(Skeleton3D *p_skeleton, StringName p_root_bone_name, Vector<Ref<IKEffectorTemplate3D>> &p_pins, ManyBoneIK3D *p_many_bone_ik, const Ref<IKBoneSegment3D> &p_parent,
BoneId p_root, BoneId p_tip) {
root = p_root;
tip = p_tip;
skeleton = p_skeleton;
root = Ref<IKBone3D>(memnew(IKBone3D(p_root_bone_name, p_skeleton, p_parent, p_pins, Math_PI, p_many_bone_ik)));

if (p_parent.is_valid()) {
root_segment = p_parent->root_segment;
} else {
root_segment = Ref<IKBoneSegment3D>(this);
}
root_segment->bone_map[root->get_bone_id()] = root;
if (p_parent.is_valid()) {
parent_segment = p_parent;
root->set_parent(p_parent->get_tip());
Expand All @@ -346,19 +332,11 @@ Vector<Ref<IKBone3D>> IKBoneSegment3D::get_bone_list() const {
return bones;
}

Ref<IKBone3D> IKBoneSegment3D::find_ik_bone(BoneId p_bone) const {
Ref<IKBoneSegment3D> root_segment;
Ref<IKBoneSegment3D> current_segment = Ref<IKBoneSegment3D>(this);
while (current_segment.is_valid()) {
root_segment = current_segment;
current_segment = current_segment->get_parent_segment();
}
for (Ref<IKBone3D> current_bone : root_segment->bones) {
if (current_bone->get_bone_id() == p_bone) {
return current_bone;
}
Ref<IKBone3D> IKBoneSegment3D::get_ik_bone(BoneId p_bone) const {
if (!bone_map.has(p_bone)) {
return Ref<IKBone3D>();
}
return Ref<IKBone3D>();
return bone_map[p_bone];
}

void IKBoneSegment3D::create_headings_arrays() {
Expand Down Expand Up @@ -434,39 +412,15 @@ void IKBoneSegment3D::recursive_create_penalty_array(Ref<IKBoneSegment3D> p_bone
r_pinned_bones.push_back(current_tip);
current_falloff = pin->get_passthrough_factor();
}
TypedArray<IKBoneSegment3D> bone_segments = p_bone_segment->get_child_segments();
for (int32_t segment_i = 0; segment_i < bone_segments.size(); segment_i++) {
Ref<IKBoneSegment3D> s = bone_segments[segment_i];
for (Ref<IKBoneSegment3D> s : p_bone_segment->get_child_segments()) {
recursive_create_penalty_array(s, r_penalty_array, r_pinned_bones, p_falloff * current_falloff);
}
}
}

void IKBoneSegment3D::recursive_create_headings_arrays_for(Ref<IKBoneSegment3D> p_bone_segment) {
p_bone_segment->create_headings_arrays();
TypedArray<IKBoneSegment3D> segments = p_bone_segment->get_child_segments();
for (int32_t segment_i = 0; segment_i < segments.size(); segment_i++) {
Ref<IKBoneSegment3D> segment = segments[segment_i];
recursive_create_headings_arrays_for(segment);
for (Ref<IKBoneSegment3D> segments : p_bone_segment->get_child_segments()) {
recursive_create_headings_arrays_for(segments);
}
}

void IKBoneSegment3D::set_child_segments(TypedArray<IKBoneSegment3D> p_child_segments) {
child_segments = p_child_segments;
}

void IKBoneSegment3D::set_default_stabilizing_pass_count(int32_t p_count) {
default_stabilizing_pass_count = p_count;
}

int32_t IKBoneSegment3D::get_default_stabilizing_pass_count() {
return default_stabilizing_pass_count;
}

void IKBoneSegment3D::set_tip(Ref<IKBone3D> p_tip) {
tip = p_tip;
}

void IKBoneSegment3D::set_parent_segment(Ref<IKBoneSegment3D> p_parent_segment) {
parent_segment = p_parent_segment;
}
18 changes: 6 additions & 12 deletions modules/many_bone_ik/src/ik_bone_segment_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class IKBoneSegment3D : public Resource {
Ref<IKBone3D> tip;
Vector<Ref<IKBone3D>> bones;
Vector<Ref<IKBone3D>> pinned_bones;
TypedArray<IKBoneSegment3D> child_segments; // Contains only direct child chains that end with effectors or have child that end with effectors
Vector<Ref<IKBoneSegment3D>> child_segments; // Contains only direct child chains that end with effectors or have child that end with effectors
Ref<IKBoneSegment3D> parent_segment;
Ref<IKBoneSegment3D> root_segment;
Vector<Ref<IKEffector3D>> effector_list;
PackedVector3Array target_headings;
PackedVector3Array tip_headings;
Expand All @@ -71,34 +72,27 @@ class IKBoneSegment3D : public Resource {
void qcp_solver(const Vector<float> &p_damp, float p_default_damp, bool p_translate, bool p_constraint_mode);
void update_optimal_rotation(Ref<IKBone3D> p_for_bone, real_t p_damp, bool p_translate, bool p_constraint_mode);
float get_manual_msd(const PackedVector3Array &r_htip, const PackedVector3Array &r_htarget, const Vector<real_t> &p_weights);
HashMap<BoneId, Ref<IKBone3D>> bone_map;

protected:
static void _bind_methods();

public:
Ref<IKBone3D> get_root();
int32_t get_default_stabilizing_pass_count();
void set_default_stabilizing_pass_count(int32_t p_count);
const double evec_prec = static_cast<double>(1E-6);
const double eval_prec = static_cast<double>(1E-11);
static Quaternion clamp_to_quadrance_angle(Quaternion p_quat, real_t p_cos_half_angle);
static void recursive_create_headings_arrays_for(Ref<IKBoneSegment3D> p_bone_segment);
void create_headings_arrays();
void recursive_create_penalty_array(Ref<IKBoneSegment3D> p_bone_segment, Vector<Vector<real_t>> &r_penalty_array, Vector<Ref<IKBone3D>> &r_pinned_bones, real_t p_falloff);
Ref<IKBoneSegment3D> get_parent_segment();
void set_parent_segment(Ref<IKBoneSegment3D> p_parent_segment);
void segment_solver(const Vector<float> &p_damp, float p_default_damp, bool p_constraint_mode);
Ref<IKBone3D> get_root() const;
Ref<IKBone3D> get_tip() const;
void set_tip(Ref<IKBone3D> p_tip);
bool is_pinned() const;
TypedArray<IKBoneSegment3D> get_child_segments() const;
void set_child_segments(TypedArray<IKBoneSegment3D> p_child_segments);
Vector<Ref<IKBoneSegment3D>> get_child_segments() const;
void create_bone_list(Vector<Ref<IKBone3D>> &p_list, bool p_recursive = false, bool p_debug_skeleton = false) const;
Vector<Ref<IKBone3D>> get_bone_list() const;
void set_bone_list(Vector<Ref<IKBone3D>> p_bone_list) {
bones = p_bone_list;
}
Ref<IKBone3D> find_ik_bone(BoneId p_bone) const;
Ref<IKBone3D> get_ik_bone(BoneId p_bone) const;
void generate_default_segments_from_root(Vector<Ref<IKEffectorTemplate3D>> &p_pins, BoneId p_root_bone, BoneId p_tip_bone, ManyBoneIK3D *p_many_bone_ik);
void update_pinned_list(Vector<Vector<real_t>> &r_weights);
IKBoneSegment3D() {}
Expand Down
2 changes: 1 addition & 1 deletion modules/many_bone_ik/src/ik_effector_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool IKEffector3D::get_target_node_rotation() const {
return use_target_node_rotation;
}

Ref<IKBone3D> IKEffector3D::find_ik_bone_3d() const {
Ref<IKBone3D> IKEffector3D::get_ik_bone_3d() const {
return for_bone;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/many_bone_ik/src/ik_effector_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class IKEffector3D : public Resource {
Transform3D get_target_global_transform() const;
void set_target_node_rotation(bool p_use);
bool get_target_node_rotation() const;
Ref<IKBone3D> find_ik_bone_3d() const;
Ref<IKBone3D> get_ik_bone_3d() const;
bool is_following_translation_only() const;
int32_t update_effector_target_headings(PackedVector3Array *p_headings, int32_t p_index, Ref<IKBone3D> p_for_bone, const Vector<real_t> *p_weights) const;
int32_t update_effector_tip_headings(PackedVector3Array *p_headings, int32_t p_index, Ref<IKBone3D> p_for_bone, bool p_is_uniform) const;
Expand Down
Loading

0 comments on commit cb3ca28

Please sign in to comment.