[csharp] Fixed Bone.yDown being ignored on 4.2 branch. See #1386 (regression).

This commit is contained in:
Harald Csaszar 2024-03-28 12:30:15 +01:00
parent c71c48d303
commit 5631eb9750
4 changed files with 17 additions and 15 deletions

View File

@ -181,7 +181,7 @@ namespace Spine {
Bone parent = this.parent; Bone parent = this.parent;
if (parent == null) { // Root bone. if (parent == null) { // Root bone.
Skeleton skeleton = this.skeleton; Skeleton skeleton = this.skeleton;
float sx = skeleton.scaleX, sy = skeleton.scaleY; float sx = skeleton.scaleX, sy = skeleton.ScaleY;
float rx = (rotation + shearX) * MathUtils.DegRad; float rx = (rotation + shearX) * MathUtils.DegRad;
float ry = (rotation + 90 + shearY) * MathUtils.DegRad; float ry = (rotation + 90 + shearY) * MathUtils.DegRad;
a = (float)Math.Cos(rx) * scaleX * sx; a = (float)Math.Cos(rx) * scaleX * sx;
@ -225,7 +225,7 @@ namespace Spine {
if (s > 0.0001f) { if (s > 0.0001f) {
s = Math.Abs(pa * pd - pb * pc) / s; s = Math.Abs(pa * pd - pb * pc) / s;
pa /= skeleton.scaleX; pa /= skeleton.scaleX;
pc /= skeleton.scaleY; pc /= skeleton.ScaleY;
pb = pc * s; pb = pc * s;
pd = pa * s; pd = pa * s;
prx = MathUtils.Atan2Deg(pc, pa); prx = MathUtils.Atan2Deg(pc, pa);
@ -251,13 +251,13 @@ namespace Spine {
rotation *= MathUtils.DegRad; rotation *= MathUtils.DegRad;
float cos = (float)Math.Cos(rotation), sin = (float)Math.Sin(rotation); float cos = (float)Math.Cos(rotation), sin = (float)Math.Sin(rotation);
float za = (pa * cos + pb * sin) / skeleton.scaleX; float za = (pa * cos + pb * sin) / skeleton.scaleX;
float zc = (pc * cos + pd * sin) / skeleton.scaleY; float zc = (pc * cos + pd * sin) / skeleton.ScaleY;
float s = (float)Math.Sqrt(za * za + zc * zc); float s = (float)Math.Sqrt(za * za + zc * zc);
if (s > 0.00001f) s = 1 / s; if (s > 0.00001f) s = 1 / s;
za *= s; za *= s;
zc *= s; zc *= s;
s = (float)Math.Sqrt(za * za + zc * zc); s = (float)Math.Sqrt(za * za + zc * zc);
if (inherit == Inherit.NoScale && (pa * pd - pb * pc < 0) != (skeleton.scaleX < 0 != skeleton.scaleY < 0)) s = -s; if (inherit == Inherit.NoScale && (pa * pd - pb * pc < 0) != (skeleton.scaleX < 0 != skeleton.ScaleY < 0)) s = -s;
rotation = MathUtils.PI / 2 + MathUtils.Atan2(zc, za); rotation = MathUtils.PI / 2 + MathUtils.Atan2(zc, za);
float zb = (float)Math.Cos(rotation) * s; float zb = (float)Math.Cos(rotation) * s;
float zd = (float)Math.Sin(rotation) * s; float zd = (float)Math.Sin(rotation) * s;
@ -276,8 +276,8 @@ namespace Spine {
} }
a *= skeleton.scaleX; a *= skeleton.scaleX;
b *= skeleton.scaleX; b *= skeleton.scaleX;
c *= skeleton.scaleY; c *= skeleton.ScaleY;
d *= skeleton.scaleY; d *= skeleton.ScaleY;
} }
/// <summary>Sets this bone's local transform to the setup pose.</summary> /// <summary>Sets this bone's local transform to the setup pose.</summary>
@ -287,7 +287,7 @@ namespace Spine {
y = data.y; y = data.y;
rotation = data.rotation; rotation = data.rotation;
scaleX = data.scaleX; scaleX = data.scaleX;
scaleY = data.scaleY; scaleY = data.ScaleY;
shearX = data.shearX; shearX = data.shearX;
shearY = data.shearY; shearY = data.shearY;
inherit = data.inherit; inherit = data.inherit;
@ -335,9 +335,9 @@ namespace Spine {
case Inherit.NoRotationOrReflection: { case Inherit.NoRotationOrReflection: {
float s = Math.Abs(pa * pd - pb * pc) / (pa * pa + pc * pc); float s = Math.Abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
float sa = pa / skeleton.scaleX; float sa = pa / skeleton.scaleX;
float sc = pc / skeleton.scaleY; float sc = pc / skeleton.ScaleY;
pb = -sc * s * skeleton.scaleX; pb = -sc * s * skeleton.scaleX;
pd = sa * s * skeleton.scaleY; pd = sa * s * skeleton.ScaleY;
pid = 1 / (pa * pd - pb * pc); pid = 1 / (pa * pd - pb * pc);
ia = pd * pid; ia = pd * pid;
ib = pb * pid; ib = pb * pid;
@ -347,13 +347,13 @@ namespace Spine {
case Inherit.NoScaleOrReflection: { case Inherit.NoScaleOrReflection: {
float r = rotation * MathUtils.DegRad, cos = (float)Math.Cos(r), sin = (float)Math.Sin(r); float r = rotation * MathUtils.DegRad, cos = (float)Math.Cos(r), sin = (float)Math.Sin(r);
pa = (pa * cos + pb * sin) / skeleton.scaleX; pa = (pa * cos + pb * sin) / skeleton.scaleX;
pc = (pc * cos + pd * sin) / skeleton.scaleY; pc = (pc * cos + pd * sin) / skeleton.ScaleY;
float s = (float)Math.Sqrt(pa * pa + pc * pc); float s = (float)Math.Sqrt(pa * pa + pc * pc);
if (s > 0.00001f) s = 1 / s; if (s > 0.00001f) s = 1 / s;
pa *= s; pa *= s;
pc *= s; pc *= s;
s = (float)Math.Sqrt(pa * pa + pc * pc); s = (float)Math.Sqrt(pa * pa + pc * pc);
if (inherit == Inherit.NoScale && pid < 0 != (skeleton.scaleX < 0 != skeleton.scaleY < 0)) s = -s; if (inherit == Inherit.NoScale && pid < 0 != (skeleton.scaleX < 0 != skeleton.ScaleY < 0)) s = -s;
r = MathUtils.PI / 2 + MathUtils.Atan2(pc, pa); r = MathUtils.PI / 2 + MathUtils.Atan2(pc, pa);
pb = (float)Math.Cos(r) * s; pb = (float)Math.Cos(r) * s;
pd = (float)Math.Sin(r) * s; pd = (float)Math.Sin(r) * s;

View File

@ -183,9 +183,9 @@ namespace Spine {
case Inherit.NoRotationOrReflection: { case Inherit.NoRotationOrReflection: {
float s = Math.Abs(pa * pd - pb * pc) / Math.Max(0.0001f, pa * pa + pc * pc); float s = Math.Abs(pa * pd - pb * pc) / Math.Max(0.0001f, pa * pa + pc * pc);
float sa = pa / bone.skeleton.scaleX; float sa = pa / bone.skeleton.scaleX;
float sc = pc / bone.skeleton.scaleY; float sc = pc / bone.skeleton.ScaleY;
pb = -sc * s * bone.skeleton.scaleX; pb = -sc * s * bone.skeleton.scaleX;
pd = sa * s * bone.skeleton.scaleY; pd = sa * s * bone.skeleton.ScaleY;
rotationIK += MathUtils.Atan2Deg(sc, sa); rotationIK += MathUtils.Atan2Deg(sc, sa);
goto default; // Fall through. goto default; // Fall through.
} }

View File

@ -42,7 +42,9 @@ namespace Spine {
internal ExposedList<IUpdatable> updateCache = new ExposedList<IUpdatable>(); internal ExposedList<IUpdatable> updateCache = new ExposedList<IUpdatable>();
internal Skin skin; internal Skin skin;
internal float r = 1, g = 1, b = 1, a = 1; internal float r = 1, g = 1, b = 1, a = 1;
internal float x, y, scaleX = 1, scaleY = 1, time; internal float x, y, scaleX = 1, time;
/// <summary>Private to enforce usage of ScaleY getter taking Bone.yDown into account.</summary>
private float scaleY = 1;
/// <summary>The skeleton's setup pose data.</summary> /// <summary>The skeleton's setup pose data.</summary>
public SkeletonData Data { get { return data; } } public SkeletonData Data { get { return data; } }

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-csharp", "name": "com.esotericsoftware.spine.spine-csharp",
"displayName": "spine-csharp Runtime", "displayName": "spine-csharp Runtime",
"description": "This plugin provides the spine-csharp core runtime.", "description": "This plugin provides the spine-csharp core runtime.",
"version": "4.2.16", "version": "4.2.17",
"unity": "2018.3", "unity": "2018.3",
"author": { "author": {
"name": "Esoteric Software", "name": "Esoteric Software",