jakubdev

Hello,

I try to get bounds from skeleton with Bounding Bounds set up.

Important thing is that animation start without any image and in half of timeline its in his full size.

.getBounds() without any argument returns all values, but they are wrong. Screen examples are below. Black rectangle represents AABB of skill, but when I call getBounds with offset, sizes and vertices it returns only x, y, width, height without left, top, right ,bottom. No error in console. Code called:
skeleton.getBounds({x: xCord, yCord}, {x: skeletonWidth, y: skeletonHeigth, Float32Array of vertices})
updateWorldTransform() is called every cords change for skeleton and all bones.

Array obtained by
skeleton.findSlot("S4-icewall").attachment.vertices
and how it looks:
Nemaš dopuštenje za pregledavanje privit(a)ka dodan(og)ih postu.
jakubdev
  • Postovi: 11

Nate

jakubdev je napisao/la:.getBounds() without any argument returns all values, but they are wrong.
You need to provide it arguments and the method doesn't return a value (it changes the arguments provided).
https://github.com/EsotericSoftware/spine-runtimes/blob/4.0/spine-ts/spine-core/src/Skeleton.ts#L592

This code is invalid JavaScript:
skeleton.getBounds({x: xCord, yCord}, {x: skeletonWidth, y: skeletonHeigth, Float32Array of vertices})
The fields of the arguments specified are written by the method. There is no need to pass in objects with particular values. You should not use any values from the third parameter after calling the method, it is used internally as a temporary buffer.

Call the method like this:
var offset = new spine.Vector2();
var size = new spine.Vector2();
skeleton.getBounds(offset, size, []);
You'll need skeleton.updateWorldTransform(); before getting the bounds.

Hopefully that helps. I couldn't make much sense of what you posted. Please post the relevant parts of your actual code if you are still having trouble.
Avatar
Nate

Nate
  • Postovi: 11942

jakubdev

It works ,but problem is it gets bounds from frame 1 of animation. It is at start invisible and in about half of timeline its in full size. Can I somehow getBounds from middle of animation?
jakubdev
  • Postovi: 11

Nate

You would need to set the local pose of the skeleton at the animation time you care about, call Skeleton updateWorldTransform so the world pose is computed from the local pose, then call Skeleton getBounds to get the bounds of the world pose.

In the Spine web player we step through an animation 100 times, doing as described above for each time step. You can see the code for that here:
https://github.com/EsotericSoftware/spine-runtimes/blob/4.0/spine-ts/spine-player/src/Player.ts#L748-L750

This gives us the maximal bounds for the whole animation, which we then use to adjust the camera so we can play the animation without it going off screen. It's possible the 100 steps miss the largest pose, but it's pretty close.
Avatar
Nate

Nate
  • Postovi: 11942


Natrag na Runtimes