Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[godot] getting bounding box of slot #2490

Open
proggen-com opened this issue Mar 25, 2024 · 0 comments
Open

[godot] getting bounding box of slot #2490

proggen-com opened this issue Mar 25, 2024 · 0 comments
Assignees

Comments

@proggen-com
Copy link

In spine-godot it's not possible to get the bounding box of a slot. The SpineMesh2D doesn't expose anything that can be used to calculate the bounds. Internally it does calculate the bounds, so with this little patch it's possible to get them in the GDScript:

diff --git a/spine-godot/spine_godot/SpineSprite.cpp b/spine-godot/spine_godot/SpineSprite.cpp
index 7be358db7..45ad2a16f 100644
--- a/spine-godot/spine_godot/SpineSprite.cpp
+++ b/spine-godot/spine_godot/SpineSprite.cpp
@@ -123,6 +123,7 @@ void SpineMesh2D::_notification(int what) {
 }

 void SpineMesh2D::_bind_methods() {
+       ClassDB::bind_method(D_METHOD("get_mesh_rid"), &SpineMesh2D::get_mesh_rid);
 }

 void SpineMesh2D::update_mesh(const Vector<Point2> &vertices,
diff --git a/spine-godot/spine_godot/SpineSprite.h b/spine-godot/spine_godot/SpineSprite.h
index 06ca2f7b0..33eac6e76 100644
--- a/spine-godot/spine_godot/SpineSprite.h
+++ b/spine-godot/spine_godot/SpineSprite.h
@@ -95,6 +95,9 @@ public:
                }
        }
 #endif
+       RID get_mesh_rid() {
+               return mesh;
+       }

        void update_mesh(const Vector<Point2> &vertices,
                                         const Vector<Point2> &uvs,

It exposes the internal mesh RID to GDScript, then with the RenderingServer you can fetch the bounds:

var mesh = $SpineSprite.get_child(index)
var internal_mesh_rid = mesh.get_mesh_rid()
var mesh_aabb = RenderingServer.mesh_get_custom_aabb(internal_mesh_rid)

Drawback is that this bounding box is calculated after a render, so to use it you probably need to wait for something like:

await get_tree().process_frame

Perhaps there is a cleaner way to implement this, or expose a get_bounds() to the SpineSlot ?

@badlogic badlogic self-assigned this Mar 28, 2024
@badlogic badlogic changed the title spine-godot getting bounding box of slot [godot] getting bounding box of slot Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants