[csharp] Fix Transform constraint import scale.

This commit is contained in:
Harald Csaszar 2025-04-09 12:15:04 +02:00
parent 90bfdba422
commit 60a34ef995
2 changed files with 24 additions and 18 deletions

View File

@ -271,39 +271,41 @@ namespace Spine {
data.clamp = (flags & 16) != 0;
FromProperty[] froms = data.properties.Resize(nn = flags >> 5).Items;
for (int ii = 0, tn; ii < nn; ii++) {
float fromScale = 1.0f;
FromProperty from;
switch (input.ReadSByte()) {
case 0: from = new FromRotate(); break;
case 1: from = new FromX(); break;
case 2: from = new FromY(); break;
case 1: from = new FromX(); fromScale = scale; break;
case 2: from = new FromY(); fromScale = scale; break;
case 3: from = new FromScaleX(); break;
case 4: from = new FromScaleY(); break;
case 5: from = new FromShearY(); break;
default: from = null; break;
};
from.offset = input.ReadFloat() * scale;
from.offset = input.ReadFloat() * fromScale;
ToProperty[] tos = from.to.Resize(tn = input.ReadSByte()).Items;
for (int t = 0; t < tn; t++) {
float toScale = 1.0f;
ToProperty to;
switch (input.ReadSByte()) {
case 0: to = new ToRotate(); break;
case 1: to = new ToX(); break;
case 2: to = new ToY(); break;
case 1: to = new ToX(); toScale = scale; break;
case 2: to = new ToY(); toScale = scale; break;
case 3: to = new ToScaleX(); break;
case 4: to = new ToScaleY(); break;
case 5: to = new ToShearY(); break;
default: to = null; break;
};
to.offset = input.ReadFloat() * scale;
to.max = input.ReadFloat() * scale;
to.scale = input.ReadFloat();
to.offset = input.ReadFloat() * toScale;
to.max = input.ReadFloat() * toScale;
to.scale = input.ReadFloat() * (toScale / fromScale);
tos[t] = to;
}
froms[ii] = from;
}
flags = input.Read();
if ((flags & 1) != 0) data.offsetX = input.ReadFloat();
if ((flags & 2) != 0) data.offsetY = input.ReadFloat();
if ((flags & 1) != 0) data.offsetX = input.ReadFloat() * scale;
if ((flags & 2) != 0) data.offsetY = input.ReadFloat() * scale;
if ((flags & 4) != 0) data.mixRotate = input.ReadFloat();
if ((flags & 8) != 0) data.mixX = input.ReadFloat();
if ((flags & 16) != 0) data.mixY = input.ReadFloat();

View File

@ -249,23 +249,25 @@ namespace Spine {
var fromEntry = (Dictionary<string, Object>)fromEntryObject.Value;
string fromEntryName = fromEntryObject.Key;
float fromScale = 1.0f;
FromProperty from;
switch (fromEntryName) {
case "rotate": from = new FromRotate(); break;
case "x": from = new FromX(); break;
case "y": from = new FromY(); break;
case "x": from = new FromX(); fromScale = scale; break;
case "y": from = new FromY(); fromScale = scale; break;
case "scaleX": from = new FromScaleX(); break;
case "scaleY": from = new FromScaleY(); break;
case "shearY": from = new FromShearY(); break;
default: throw new Exception("Invalid transform constraint from property: " + fromEntryName);
};
from.offset = GetFloat(fromEntry, "offset", 0) * scale;
from.offset = GetFloat(fromEntry, "offset", 0) * fromScale;
if (fromEntry.ContainsKey("to")) {
foreach (KeyValuePair<string, Object> toEntryObject in (Dictionary<string, Object>)fromEntry["to"]) {
var toEntry = (Dictionary<string, Object>)toEntryObject.Value;
string toEntryName = toEntryObject.Key;
float toScale = 1.0f;
ToProperty to;
switch (toEntryName) {
case "rotate": {
@ -276,11 +278,13 @@ namespace Spine {
case "x": {
x = true;
to = new ToX();
toScale = scale;
break;
}
case "y": {
y = true;
to = new ToY();
toScale = scale;
break;
}
case "scaleX": {
@ -300,9 +304,9 @@ namespace Spine {
}
default: throw new Exception("Invalid transform constraint to property: " + toEntryName);
}
to.offset = GetFloat(toEntry, "offset", 0) * scale;
to.max = GetFloat(toEntry, "max", 1) * scale;
to.scale = GetFloat(toEntry, "scale");
to.offset = GetFloat(toEntry, "offset", 0) * toScale;
to.max = GetFloat(toEntry, "max", 1) * toScale;
to.scale = GetFloat(toEntry, "scale") * (toScale / fromScale);
from.to.Add(to);
}
}
@ -310,8 +314,8 @@ namespace Spine {
}
}
data.offsetX = GetFloat(constraintMap, "x", 0);
data.offsetY = GetFloat(constraintMap, "y", 0);
data.offsetX = GetFloat(constraintMap, "x", 0) * scale;
data.offsetY = GetFloat(constraintMap, "y", 0) * scale;
if (rotate) data.mixRotate = GetFloat(constraintMap, "mixRotate", 1);
if (x) data.mixX = GetFloat(constraintMap, "mixX", 1);
if (y) data.mixY = GetFloat(constraintMap, "mixY", data.mixX);