mfedorov

Hi! When using skeleton backer, the keys are baked in every frame. Considering that the Spine fourth version uses curves as in the Unity, is it possible to bake keys in curves? Thank you!
Benutzeravatar
mfedorov
  • Beiträge: 287

Harald

mfedorov hat geschrieben:Spine fourth version uses curves as in the Unity
Unfortunately curves are not all the same (Spine uses Bezier curves, Unity seems to use Hermite splines at least in some parts, in general it's undocumented). The only way to guarantee equal evaluation is to have a keyframe at (or very close to) the sampled timepoint.

A side note: previous Spine versions also always used curves, these were just not exposed with a curve editor interface.

There is also a related forum thread from 2014 on the the Unity forums:
https://answers.unity.com/questions/623318/how-to-convert-cubic-bezier-curve-into-animationcu.html
In general it was of course always possible to create an imprecise approximation, but that would require you to modify the existing SkeletonBaker source code accordingly, and the results might be too bad to be useful.
Benutzeravatar
Harald

Harri
  • Beiträge: 4335

mfedorov

Thank you!

---

Harald, please tell me how to get curve data (cx1, cy1, cx2, cy2) for a specific bone on a specific frame. I only see Transforms properties such as (Translation, Rotation, Scale, etc.) in skeleton.Data.Bone.Items[timeline.BoneIndex]. Thanks a lot!
Benutzeravatar
mfedorov
  • Beiträge: 287

Harald

the line skeleton.Data.Bone.Items[timeline.BoneIndex] contains the bone data, which is the setup pose. You want to access the timeline.frames and timeline.curves array values instead which contains the frame animation data. Then you will need to interpret (or evaluate) the curves float array accordingly as each Timeline subclass Apply does (e.g. TranslateTimeline.Apply()). Here the frames array stores key-frame values (time and value) and the curve values store linear curve segments between those key-frames, like e.g. [frame i] [segment_0] [segment_1]..[segment_7] [segment_8] [frame i + 1].

On how to read and reconstruct the Bezier curve values and tangents, you can check out and set a breakpoint at e.g. Animation.cs : line 585 which is accessing the frames and curves array accordingly.

The following image shows the curve array content for a TranslateTimeline of a simple json test file with two bezier curve keys that just move a bone in x direction and have horizontal curve handles:

curve-help.png


Note that here the actual curve values start at index 2 for a Bezier curve, where the offset is curveType - BEZIER // (4 - 2) as accessed by this line:
x = GetBezierValue(time, i, VALUE1, curveType - BEZIER);
The Bezier curve values are stored as linear segments (9 segments) that lie between the first and second key values. It's always time, value pairs, summing up to 18 float values per curve. So at a TranslateTimeline curve (x and y) the curve contains 2 * 18 curve segment values between the key values, which are stored at the frames float array.

To reconstruct the tangents you would now e.g. use the first and last curve segment values in relation to the frame values that they lie next to:
accessing time values:
[frame_i] [segment_0] ... [segment_8] [frame i + 1]
accessing value, the index is +1 higher:
[frame_i + 1] [segment_0 + 1] ... [segment_8 + 1] [frame_i + 1]
Here at a bezier curve, the segment_0 array index location would be 2 so you access it as curves[2]
(time = curves[2], value = curves[2 + 1]).
The segment_8 array index location would be 2 + 8 * 2 = 18 so you access it as curves[18]
(time = curves[18], value = curves[18 + 1]).

Then you can calculate the time and value delta to get the first and last tangents.
Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.
Benutzeravatar
Harald

Harri
  • Beiträge: 4335

Nate

I can't help but think of a skeleton version of the Swedish chef. :D

Benutzeravatar
Nate

Nate
  • Beiträge: 12136

Harald

:lol:
Benutzeravatar
Harald

Harri
  • Beiträge: 4335

mfedorov

Amazing info! Thank you very much!
Benutzeravatar
mfedorov
  • Beiträge: 287


Zurück zu Unity