Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
git subrepo pull VSK_godot
Browse files Browse the repository at this point in the history
subrepo:
  subdir:   "VSK_godot"
  merged:   "055b0dcb5b"
upstream:
  origin:   "https://github.com/V-Sekai/godot.git"
  branch:   "groups-staging-4.3"
  commit:   "055b0dcb5b"
git-subrepo:
  version:  "0.4.6"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "110b9eb"
  • Loading branch information
fire committed Apr 7, 2024
1 parent 903261a commit c36f480
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 110 deletions.
4 changes: 2 additions & 2 deletions VSK_godot/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/V-Sekai/godot.git
branch = groups-staging-4.3
commit = 335bfad53768d675c13f8609f75a3b51ac3306cb
parent = 69483c8a83351c32efa2a55fa04bb41e8fd7c31e
commit = 055b0dcb5bde281f9c5e90cad26aa4fb50e8c9fc
parent = 903261a0820e668f006c23c09dda7dfd2d6b63e8
method = merge
cmdver = 0.4.6
190 changes: 92 additions & 98 deletions VSK_godot/modules/many_bone_ik/src/many_bone_ik_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,6 @@ void ManyBoneIK3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_bone_direction_transform", "index"), &ManyBoneIK3D::get_bone_direction_transform);
ClassDB::bind_method(D_METHOD("set_bone_direction_transform", "index", "transform"), &ManyBoneIK3D::set_bone_direction_transform);
ClassDB::bind_method(D_METHOD("remove_constraint", "index"), &ManyBoneIK3D::remove_constraint);
ClassDB::bind_method(D_METHOD("set_skeleton_node_path", "path"), &ManyBoneIK3D::set_skeleton_node_path);
ClassDB::bind_method(D_METHOD("get_skeleton_node_path"), &ManyBoneIK3D::get_skeleton_node_path);
ClassDB::bind_method(D_METHOD("register_skeleton"), &ManyBoneIK3D::register_skeleton);
ClassDB::bind_method(D_METHOD("reset_constraints"), &ManyBoneIK3D::register_skeleton);
ClassDB::bind_method(D_METHOD("set_dirty"), &ManyBoneIK3D::set_dirty);
Expand Down Expand Up @@ -434,7 +432,6 @@ void ManyBoneIK3D::_bind_methods() {
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);

ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton_node_path"), "set_skeleton_node_path", "get_skeleton_node_path");
ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations_per_frame", PROPERTY_HINT_RANGE, "1,150,1,or_greater"), "set_iterations_per_frame", "get_iterations_per_frame");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "default_damp", PROPERTY_HINT_RANGE, "0.01,180.0,0.1,radians,exp", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_default_damp", "get_default_damp");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "constraint_mode"), "set_constraint_mode", "get_constraint_mode");
Expand Down Expand Up @@ -678,7 +675,7 @@ NodePath ManyBoneIK3D::get_pin_nodepath(int32_t p_effector_index) const {
return effector_template->get_target_node();
}

void ManyBoneIK3D::_execute(real_t delta) {
void ManyBoneIK3D::_process_modification() {
if (!get_skeleton()) {
return;
}
Expand All @@ -689,8 +686,8 @@ void ManyBoneIK3D::_execute(real_t delta) {
set_dirty();
}
if (is_dirty) {
_skeleton_changed(get_skeleton());
is_dirty = false;
_bone_list_changed();
}
if (bone_list.size()) {
Ref<IKNode3D> root_ik_bone = bone_list.write[0]->get_ik_transform();
Expand Down Expand Up @@ -729,67 +726,22 @@ void ManyBoneIK3D::_execute(real_t delta) {
_update_skeleton_bones_transform();
}

void ManyBoneIK3D::_skeleton_changed(Skeleton3D *p_skeleton) {
if (!p_skeleton) {
return;
}
Vector<int32_t> roots = p_skeleton->get_parentless_bones();
if (roots.is_empty()) {
return;
}
bone_list.clear();
segmented_skeletons.clear();
for (BoneId root_bone_index : roots) {
String parentless_bone = p_skeleton->get_bone_name(root_bone_index);
Ref<IKBoneSegment3D> segmented_skeleton = Ref<IKBoneSegment3D>(memnew(IKBoneSegment3D(p_skeleton, parentless_bone, pins, this, nullptr, root_bone_index, -1, stabilize_passes)));
ik_origin.instantiate();
segmented_skeleton->get_root()->get_ik_transform()->set_parent(ik_origin);
segmented_skeleton->generate_default_segments(pins, root_bone_index, -1, this);
Vector<Ref<IKBone3D>> new_bone_list;
segmented_skeleton->create_bone_list(new_bone_list, true, queue_debug_skeleton);
bone_list.append_array(new_bone_list);
Vector<Vector<double>> weight_array;
segmented_skeleton->update_pinned_list(weight_array);
segmented_skeleton->recursive_create_headings_arrays_for(segmented_skeleton);
segmented_skeletons.push_back(segmented_skeleton);
}
_update_ik_bones_transform();
for (Ref<IKBone3D> &ik_bone_3d : bone_list) {
ik_bone_3d->update_default_bone_direction_transform(p_skeleton);
void ManyBoneIK3D::_skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) {
if (p_old) {
if (p_old->is_connected(SNAME("bone_list_changed"), callable_mp(this, &ManyBoneIK3D::_bone_list_changed))) {
p_old->disconnect(SNAME("bone_list_changed"), callable_mp(this, &ManyBoneIK3D::_bone_list_changed));
}
}
for (int constraint_i = 0; constraint_i < constraint_count; ++constraint_i) {
String bone = constraint_names[constraint_i];
BoneId bone_id = p_skeleton->find_bone(bone);
for (Ref<IKBone3D> &ik_bone_3d : bone_list) {
if (ik_bone_3d->get_bone_id() != bone_id) {
continue;
}
Ref<IKKusudama3D> constraint;
constraint.instantiate();
constraint->enable_orientational_limits();

int32_t cone_count = kusudama_limit_cone_count[constraint_i];
const Vector<Vector4> &cones = kusudama_limit_cones[constraint_i];
for (int32_t cone_i = 0; cone_i < cone_count; ++cone_i) {
const Vector4 &cone = cones[cone_i];
Ref<IKLimitCone3D> new_cone;
new_cone.instantiate();
new_cone->set_attached_to(constraint);
new_cone->set_tangent_circle_center_next_1(Vector3(0.0f, -1.0f, 0.0f));
new_cone->set_tangent_circle_center_next_2(Vector3(0.0f, 1.0f, 0.0f));
new_cone->set_radius(MAX(1.0e-38, cone.w));
new_cone->set_control_point(Vector3(cone.x, cone.y, cone.z).normalized());
constraint->add_limit_cone(new_cone);
}

const Vector2 axial_limit = get_kusudama_twist(constraint_i);
constraint->enable_axial_limits();
constraint->set_axial_limits(axial_limit.x, axial_limit.y);
ik_bone_3d->add_constraint(constraint);
constraint->_update_constraint(ik_bone_3d->get_constraint_twist_transform());
break;
if (p_new) {
if (!p_new->is_connected(SNAME("bone_list_changed"), callable_mp(this, &ManyBoneIK3D::_bone_list_changed))) {
p_new->connect(SNAME("bone_list_changed"), callable_mp(this, &ManyBoneIK3D::_bone_list_changed));
}
}
if (is_connected(SNAME("modification_processed"), callable_mp(this, &ManyBoneIK3D::_update_ik_bones_transform))) {
disconnect(SNAME("modification_processed"), callable_mp(this, &ManyBoneIK3D::_update_ik_bones_transform));
}
connect(SNAME("modification_processed"), callable_mp(this, &ManyBoneIK3D::_update_ik_bones_transform));
_bone_list_changed();
}

real_t ManyBoneIK3D::get_pin_weight(int32_t p_pin_index) const {
Expand Down Expand Up @@ -839,41 +791,6 @@ int32_t ManyBoneIK3D::find_constraint(String p_string) const {
return -1;
}

Skeleton3D *ManyBoneIK3D::get_skeleton() const {
Node *node = get_node_or_null(skeleton_node_path);
if (!node) {
return nullptr;
}
return cast_to<Skeleton3D>(node);
}

NodePath ManyBoneIK3D::get_skeleton_node_path() {
return skeleton_node_path;
}

void ManyBoneIK3D::set_skeleton_node_path(NodePath p_skeleton_node_path) {
skeleton_node_path = p_skeleton_node_path;
register_skeleton();
set_dirty(); // Duplicated for ease of verification.
}

void ManyBoneIK3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
set_process_priority(1);
set_process_internal(true);
set_notify_local_transform(true);
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
update_gizmos();
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
_execute(get_process_delta_time());
update_gizmos();
} break;
}
}

void ManyBoneIK3D::remove_constraint(int32_t p_index) {
ERR_FAIL_INDEX(p_index, constraint_count);

Expand Down Expand Up @@ -1161,3 +1078,80 @@ void ManyBoneIK3D::set_pin_target_static(int32_t p_effector_index, bool p_force_
effector_template->set_target_node(NodePath());
set_dirty();
}

void ManyBoneIK3D::_bone_list_changed() {
Skeleton3D *skeleton = get_skeleton();
Vector<int32_t> roots = skeleton->get_parentless_bones();
if (roots.is_empty()) {
return;
}
bone_list.clear();
segmented_skeletons.clear();
for (BoneId root_bone_index : roots) {
String parentless_bone = skeleton->get_bone_name(root_bone_index);
Ref<IKBoneSegment3D> segmented_skeleton = Ref<IKBoneSegment3D>(memnew(IKBoneSegment3D(skeleton, parentless_bone, pins, this, nullptr, root_bone_index, -1, stabilize_passes)));
ik_origin.instantiate();
segmented_skeleton->get_root()->get_ik_transform()->set_parent(ik_origin);
segmented_skeleton->generate_default_segments(pins, root_bone_index, -1, this);
Vector<Ref<IKBone3D>> new_bone_list;
segmented_skeleton->create_bone_list(new_bone_list, true, queue_debug_skeleton);
bone_list.append_array(new_bone_list);
Vector<Vector<double>> weight_array;
segmented_skeleton->update_pinned_list(weight_array);
segmented_skeleton->recursive_create_headings_arrays_for(segmented_skeleton);
segmented_skeletons.push_back(segmented_skeleton);
}
_update_ik_bones_transform();
for (Ref<IKBone3D> &ik_bone_3d : bone_list) {
ik_bone_3d->update_default_bone_direction_transform(skeleton);
}
for (int constraint_i = 0; constraint_i < constraint_count; ++constraint_i) {
String bone = constraint_names[constraint_i];
BoneId bone_id = skeleton->find_bone(bone);
for (Ref<IKBone3D> &ik_bone_3d : bone_list) {
if (ik_bone_3d->get_bone_id() != bone_id) {
continue;
}
Ref<IKKusudama3D> constraint;
constraint.instantiate();
constraint->enable_orientational_limits();

int32_t cone_count = kusudama_limit_cone_count[constraint_i];
const Vector<Vector4> &cones = kusudama_limit_cones[constraint_i];
for (int32_t cone_i = 0; cone_i < cone_count; ++cone_i) {
const Vector4 &cone = cones[cone_i];
Ref<IKLimitCone3D> new_cone;
new_cone.instantiate();
new_cone->set_attached_to(constraint);
new_cone->set_tangent_circle_center_next_1(Vector3(0.0f, -1.0f, 0.0f));
new_cone->set_tangent_circle_center_next_2(Vector3(0.0f, 1.0f, 0.0f));
new_cone->set_radius(MAX(1.0e-38, cone.w));
new_cone->set_control_point(Vector3(cone.x, cone.y, cone.z).normalized());
constraint->add_limit_cone(new_cone);
}

const Vector2 axial_limit = get_kusudama_twist(constraint_i);
constraint->enable_axial_limits();
constraint->set_axial_limits(axial_limit.x, axial_limit.y);
ik_bone_3d->add_constraint(constraint);
constraint->_update_constraint(ik_bone_3d->get_constraint_twist_transform());
break;
}
}
if (queue_debug_skeleton) {
queue_debug_skeleton = false;
}
}

void ManyBoneIK3D::_notification(int32_t p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
set_notify_local_transform(true);
break;
}
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
process_modification();
break;
}
}
}
20 changes: 10 additions & 10 deletions VSK_godot/modules/many_bone_ik/src/many_bone_ik_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
#include "core/math/math_defs.h"
#include "core/math/transform_3d.h"
#include "core/math/vector3.h"
#include "core/object/ref_counted.h"
#include "ik_bone_3d.h"
#include "ik_effector_template_3d.h"
#include "math/ik_node_3d.h"

#include "core/object/ref_counted.h"
#include "scene/3d/skeleton_3d.h"
#include "scene/3d/skeleton_modifier_3d.h"
#include "scene/main/scene_tree.h"

class ManyBoneIK3DState;
class ManyBoneIK3D : public Node3D {
GDCLASS(ManyBoneIK3D, Node3D);
class ManyBoneIK3D : public SkeletonModifier3D {
GDCLASS(ManyBoneIK3D, SkeletonModifier3D);

bool is_constraint_mode = false;
NodePath skeleton_path;
Expand Down Expand Up @@ -81,15 +81,18 @@ class ManyBoneIK3D : public Node3D {
String _get_pin_root_bone(int32_t p_pin_index) const;
bool _is_descendant_of(int bone_i, int parent_bone_i) const;
bool _is_ancestor_of(int potential_ancestor, int bone_idx) const;
void _bone_list_changed();
void _pose_updated();
void _update_ik_bone_pose(int32_t p_bone_idx);

protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
static void _bind_methods();
virtual void _skeleton_changed(Skeleton3D *skeleton);
virtual void _execute(real_t delta);
void _notification(int p_what);
virtual void _process_modification() override;
void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) override;
void _notification(int32_t p_what);

public:
void set_pin_target_static(int32_t p_effector_index, bool p_force_ignore);
Expand All @@ -107,11 +110,8 @@ class ManyBoneIK3D : public Node3D {
void set_constraint_mode(bool p_enabled);
bool get_constraint_mode() const;
bool get_pin_enabled(int32_t p_effector_index) const;
void set_skeleton_node_path(NodePath p_skeleton_node_path);
void register_skeleton();
void reset_constraints();
NodePath get_skeleton_node_path();
Skeleton3D *get_skeleton() const;
Vector<Ref<IKBone3D>> get_bone_list() const;
Vector<Ref<IKBoneSegment3D>> get_segmented_skeletons();
float get_iterations_per_frame() const;
Expand Down

0 comments on commit c36f480

Please sign in to comment.