Skip to content

Commit

Permalink
Avoid duplicate code.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Feb 9, 2024
1 parent 18a2e44 commit 61a6488
Showing 1 changed file with 5 additions and 76 deletions.
81 changes: 5 additions & 76 deletions src/many_bone_ik_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ void ManyBoneIK3D::_update_skeleton_bones_transform() {

void ManyBoneIK3D::_get_property_list(List<PropertyInfo> *p_list) const {
const Vector<Ref<IKBone3D>> ik_bones = get_bone_list();
RBSet<StringName> existing_pins;
for (int32_t pin_i = 0; pin_i < get_pin_count(); pin_i++) {
const String name = get_pin_bone_name(pin_i);
existing_pins.insert(name);
}
const uint32_t pin_usage = PROPERTY_USAGE_DEFAULT;
p_list->push_back(
PropertyInfo(Variant::INT, "pin_count",
Expand Down Expand Up @@ -210,82 +215,6 @@ void ManyBoneIK3D::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(
PropertyInfo(Variant::TRANSFORM3D, "constraints/" + itos(constraint_i) + "/bone_direction", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE));
}
RBSet<StringName> existing_pins;
for (int32_t pin_i = 0; pin_i < get_pin_count(); pin_i++) {
const String name = get_pin_bone_name(pin_i);
existing_pins.insert(name);
}
p_list->push_back(
PropertyInfo(Variant::INT, "pin_count",
PROPERTY_HINT_RANGE, "0,65536,or_greater", pin_usage | PROPERTY_USAGE_ARRAY | PROPERTY_USAGE_READ_ONLY,
"Pins,pins/"));
for (int pin_i = 0; pin_i < get_pin_count(); pin_i++) {
PropertyInfo effector_name;
effector_name.type = Variant::STRING_NAME;
effector_name.name = "pins/" + itos(pin_i) + "/bone_name";
effector_name.usage = pin_usage;
if (get_skeleton()) {
String names;
for (int bone_i = 0; bone_i < get_skeleton()->get_bone_count(); bone_i++) {
String name = get_skeleton()->get_bone_name(bone_i);
StringName string_name = StringName(name);
if (existing_pins.has(string_name)) {
continue;
}
name += ",";
names += name;
existing_pins.insert(name);
}
effector_name.hint = PROPERTY_HINT_ENUM_SUGGESTION;
effector_name.hint_string = names;
} else {
effector_name.hint = PROPERTY_HINT_NONE;
effector_name.hint_string = "";
}
p_list->push_back(effector_name);
PropertyInfo pin_root_name;
pin_root_name.type = Variant::STRING_NAME;
pin_root_name.name = "pins/" + itos(pin_i) + "/root_bone";
pin_root_name.usage = pin_usage;
String pin_name = get_pin_bone_name(pin_i);
int pin_bone_idx = get_skeleton()->find_bone(pin_name);
if (get_skeleton()) {
String names;
for (int bone_i = 0; bone_i < get_skeleton()->get_bone_count(); bone_i++) {
bool is_parent = _is_ancestor_of(bone_i, pin_bone_idx);
if ((!is_parent || _is_descendant_of(bone_i, pin_bone_idx))) {
continue;
}
String name = get_skeleton()->get_bone_name(bone_i);
StringName string_name = StringName(name);
if (existing_pins.has(string_name)) {
continue;
}
name += ",";
names += name;
existing_pins.insert(name);
}
bool is_root = get_skeleton()->get_bone_parent(pin_bone_idx) == -1;
if (is_root) {
names += pin_name + ",";
existing_pins.insert(pin_name);
}
pin_root_name.hint = PROPERTY_HINT_ENUM_SUGGESTION;
pin_root_name.hint_string = names;
} else {
pin_root_name.hint = PROPERTY_HINT_NONE;
pin_root_name.hint_string = "";
}
p_list->push_back(pin_root_name);
p_list->push_back(
PropertyInfo(Variant::NODE_PATH, "pins/" + itos(pin_i) + "/target_node", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Node3D", pin_usage));
p_list->push_back(
PropertyInfo(Variant::FLOAT, "pins/" + itos(pin_i) + "/passthrough_factor", PROPERTY_HINT_RANGE, "0,1,0.1,or_greater", pin_usage));
p_list->push_back(
PropertyInfo(Variant::FLOAT, "pins/" + itos(pin_i) + "/weight", PROPERTY_HINT_RANGE, "0,1,0.1,or_greater", pin_usage));
p_list->push_back(
PropertyInfo(Variant::VECTOR3, "pins/" + itos(pin_i) + "/direction_priorities", PROPERTY_HINT_RANGE, "0,1,0.1,or_greater", pin_usage));
}
}

bool ManyBoneIK3D::_get(const StringName &p_name, Variant &r_ret) const {
Expand Down

0 comments on commit 61a6488

Please sign in to comment.