Skip to content

Commit 5ebfc8a

Browse files
committed
Merge pull request #95643 from Flynsarmy/get_bone_attach_skele
Add `BoneAttachment3D::get_skeleton()` method
2 parents d9e4585 + 0df7ee3 commit 5ebfc8a

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

doc/classes/BoneAttachment3D.xml

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
Returns the [NodePath] to the external [Skeleton3D] node, if one has been set.
1616
</description>
1717
</method>
18+
<method name="get_skeleton">
19+
<return type="Skeleton3D" />
20+
<description>
21+
Get parent or external [Skeleton3D] node if found.
22+
</description>
23+
</method>
1824
<method name="get_use_external_skeleton" qualifiers="const">
1925
<return type="bool" />
2026
<description>

scene/3d/bone_attachment_3d.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

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

136136
void BoneAttachment3D::_check_bind() {
137-
Skeleton3D *sk = _get_skeleton3d();
137+
Skeleton3D *sk = get_skeleton();
138138

139139
if (sk && !bound) {
140140
if (bone_idx <= -1) {
@@ -148,7 +148,7 @@ void BoneAttachment3D::_check_bind() {
148148
}
149149
}
150150

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

167167
void BoneAttachment3D::_check_unbind() {
168168
if (bound) {
169-
Skeleton3D *sk = _get_skeleton3d();
169+
Skeleton3D *sk = get_skeleton();
170170

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

183183
if (override_pose && !overriding) {
184-
Skeleton3D *sk = _get_skeleton3d();
184+
Skeleton3D *sk = get_skeleton();
185185

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

201201
void BoneAttachment3D::set_bone_name(const String &p_name) {
202202
bone_name = p_name;
203-
Skeleton3D *sk = _get_skeleton3d();
203+
Skeleton3D *sk = get_skeleton();
204204
if (sk) {
205205
set_bone_idx(sk->find_bone(bone_name));
206206
}
@@ -217,7 +217,7 @@ void BoneAttachment3D::set_bone_idx(const int &p_idx) {
217217

218218
bone_idx = p_idx;
219219

220-
Skeleton3D *sk = _get_skeleton3d();
220+
Skeleton3D *sk = get_skeleton();
221221
if (sk) {
222222
if (bone_idx <= -1 || bone_idx >= sk->get_bone_count()) {
223223
WARN_PRINT("Bone index out of range! Cannot connect BoneAttachment to node!");
@@ -247,7 +247,7 @@ void BoneAttachment3D::set_override_pose(bool p_override) {
247247
set_notify_transform(override_pose);
248248
set_process_internal(override_pose);
249249
if (!override_pose && bone_idx >= 0) {
250-
Skeleton3D *sk = _get_skeleton3d();
250+
Skeleton3D *sk = get_skeleton();
251251
if (sk) {
252252
sk->reset_bone_pose(bone_idx);
253253
}
@@ -318,7 +318,7 @@ void BoneAttachment3D::on_skeleton_update() {
318318
}
319319
updating = true;
320320
if (bone_idx >= 0) {
321-
Skeleton3D *sk = _get_skeleton3d();
321+
Skeleton3D *sk = get_skeleton();
322322
if (sk) {
323323
if (!override_pose) {
324324
if (use_external_skeleton) {
@@ -369,6 +369,8 @@ BoneAttachment3D::BoneAttachment3D() {
369369
}
370370

371371
void BoneAttachment3D::_bind_methods() {
372+
ClassDB::bind_method(D_METHOD("get_skeleton"), &BoneAttachment3D::get_skeleton);
373+
372374
ClassDB::bind_method(D_METHOD("set_bone_name", "bone_name"), &BoneAttachment3D::set_bone_name);
373375
ClassDB::bind_method(D_METHOD("get_bone_name"), &BoneAttachment3D::get_bone_name);
374376

scene/3d/bone_attachment_3d.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class BoneAttachment3D : public Node3D {
5757
bool updating = false;
5858
void _transform_changed();
5959
void _update_external_skeleton_cache();
60-
Skeleton3D *_get_skeleton3d();
6160

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

8079
virtual PackedStringArray get_configuration_warnings() const override;
8180

81+
Skeleton3D *get_skeleton();
82+
8283
void set_bone_name(const String &p_name);
8384
String get_bone_name() const;
8485

0 commit comments

Comments
 (0)