Skip to content

Commit

Permalink
Add BoneAttachment3D::get_skeleton() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Flynsarmy committed Aug 16, 2024
1 parent 96be44c commit 0df7ee3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 6 additions & 0 deletions doc/classes/BoneAttachment3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
Returns the [NodePath] to the external [Skeleton3D] node, if one has been set.
</description>
</method>
<method name="get_skeleton">
<return type="Skeleton3D" />
<description>
Get parent or external [Skeleton3D] node if found.
</description>
</method>
<method name="get_use_external_skeleton" qualifiers="const">
<return type="bool" />
<description>
Expand Down
20 changes: 11 additions & 9 deletions scene/3d/bone_attachment_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

void BoneAttachment3D::_validate_property(PropertyInfo &p_property) const {
if (p_property.name == "bone_name") {
// Because it is a constant function, we cannot use the _get_skeleton_3d function.
// Because it is a constant function, we cannot use the get_skeleton function.
const Skeleton3D *parent = nullptr;
if (use_external_skeleton) {
if (external_skeleton_node_cache.is_valid()) {
Expand Down Expand Up @@ -134,7 +134,7 @@ void BoneAttachment3D::_update_external_skeleton_cache() {
}

void BoneAttachment3D::_check_bind() {
Skeleton3D *sk = _get_skeleton3d();
Skeleton3D *sk = get_skeleton();

if (sk && !bound) {
if (bone_idx <= -1) {
Expand All @@ -148,7 +148,7 @@ void BoneAttachment3D::_check_bind() {
}
}

Skeleton3D *BoneAttachment3D::_get_skeleton3d() {
Skeleton3D *BoneAttachment3D::get_skeleton() {
if (use_external_skeleton) {
if (external_skeleton_node_cache.is_valid()) {
return Object::cast_to<Skeleton3D>(ObjectDB::get_instance(external_skeleton_node_cache));
Expand All @@ -166,7 +166,7 @@ Skeleton3D *BoneAttachment3D::_get_skeleton3d() {

void BoneAttachment3D::_check_unbind() {
if (bound) {
Skeleton3D *sk = _get_skeleton3d();
Skeleton3D *sk = get_skeleton();

if (sk) {
sk->disconnect(SceneStringName(skeleton_updated), callable_mp(this, &BoneAttachment3D::on_skeleton_update));
Expand All @@ -181,7 +181,7 @@ void BoneAttachment3D::_transform_changed() {
}

if (override_pose && !overriding) {
Skeleton3D *sk = _get_skeleton3d();
Skeleton3D *sk = get_skeleton();

ERR_FAIL_NULL_MSG(sk, "Cannot override pose: Skeleton not found!");
ERR_FAIL_INDEX_MSG(bone_idx, sk->get_bone_count(), "Cannot override pose: Bone index is out of range!");
Expand All @@ -200,7 +200,7 @@ void BoneAttachment3D::_transform_changed() {

void BoneAttachment3D::set_bone_name(const String &p_name) {
bone_name = p_name;
Skeleton3D *sk = _get_skeleton3d();
Skeleton3D *sk = get_skeleton();
if (sk) {
set_bone_idx(sk->find_bone(bone_name));
}
Expand All @@ -217,7 +217,7 @@ void BoneAttachment3D::set_bone_idx(const int &p_idx) {

bone_idx = p_idx;

Skeleton3D *sk = _get_skeleton3d();
Skeleton3D *sk = get_skeleton();
if (sk) {
if (bone_idx <= -1 || bone_idx >= sk->get_bone_count()) {
WARN_PRINT("Bone index out of range! Cannot connect BoneAttachment to node!");
Expand Down Expand Up @@ -247,7 +247,7 @@ void BoneAttachment3D::set_override_pose(bool p_override) {
set_notify_transform(override_pose);
set_process_internal(override_pose);
if (!override_pose && bone_idx >= 0) {
Skeleton3D *sk = _get_skeleton3d();
Skeleton3D *sk = get_skeleton();
if (sk) {
sk->reset_bone_pose(bone_idx);
}
Expand Down Expand Up @@ -318,7 +318,7 @@ void BoneAttachment3D::on_skeleton_update() {
}
updating = true;
if (bone_idx >= 0) {
Skeleton3D *sk = _get_skeleton3d();
Skeleton3D *sk = get_skeleton();
if (sk) {
if (!override_pose) {
if (use_external_skeleton) {
Expand Down Expand Up @@ -369,6 +369,8 @@ BoneAttachment3D::BoneAttachment3D() {
}

void BoneAttachment3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_skeleton"), &BoneAttachment3D::get_skeleton);

ClassDB::bind_method(D_METHOD("set_bone_name", "bone_name"), &BoneAttachment3D::set_bone_name);
ClassDB::bind_method(D_METHOD("get_bone_name"), &BoneAttachment3D::get_bone_name);

Expand Down
3 changes: 2 additions & 1 deletion scene/3d/bone_attachment_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class BoneAttachment3D : public Node3D {
bool updating = false;
void _transform_changed();
void _update_external_skeleton_cache();
Skeleton3D *_get_skeleton3d();

protected:
void _validate_property(PropertyInfo &p_property) const;
Expand All @@ -79,6 +78,8 @@ class BoneAttachment3D : public Node3D {

virtual PackedStringArray get_configuration_warnings() const override;

Skeleton3D *get_skeleton();

void set_bone_name(const String &p_name);
String get_bone_name() const;

Expand Down

0 comments on commit 0df7ee3

Please sign in to comment.