[libgdx] Fixed transform constraints and sliders when runtime skeleton scale is used.

This commit is contained in:
Nathan Sweet 2025-06-18 14:50:52 -04:00
parent ee701ed488
commit 317aa13c87
3 changed files with 22 additions and 15 deletions

View File

@ -65,7 +65,8 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
if (bone != null) { if (bone != null) {
if (!bone.active) return; if (!bone.active) return;
if (data.local) bone.applied.validateLocalTransform(skeleton); if (data.local) bone.applied.validateLocalTransform(skeleton);
p.time = data.offset + (data.property.value(bone.applied, data.local, offsets) - data.property.offset) * data.scale; p.time = data.offset
+ (data.property.value(skeleton, bone.applied, data.local, offsets) - data.property.offset) * data.scale;
if (data.loop) if (data.loop)
p.time = animation.duration + (p.time % animation.duration); p.time = animation.duration + (p.time % animation.duration);
else else

View File

@ -82,7 +82,7 @@ public class TransformConstraint extends Constraint<TransformConstraint, Transfo
bone.modifyWorld(update); bone.modifyWorld(update);
for (int f = 0; f < fn; f++) { for (int f = 0; f < fn; f++) {
FromProperty from = fromItems[f]; FromProperty from = fromItems[f];
float value = from.value(source, localSource, offsets) - from.offset; float value = from.value(skeleton, source, localSource, offsets) - from.offset;
ToProperty[] toItems = from.to.items; ToProperty[] toItems = from.to.items;
for (int t = 0, tn = from.to.size; t < tn; t++) { for (int t = 0, tn = from.to.size; t < tn; t++) {
ToProperty to = toItems[t]; ToProperty to = toItems[t];

View File

@ -172,7 +172,7 @@ public class TransformConstraintData extends ConstraintData<TransformConstraint,
public final Array<ToProperty> to = new Array(true, 1, ToProperty[]::new); public final Array<ToProperty> to = new Array(true, 1, ToProperty[]::new);
/** Reads this property from the specified bone. */ /** Reads this property from the specified bone. */
abstract public float value (BonePose source, boolean local, float[] offsets); abstract public float value (Skeleton skeleton, BonePose source, boolean local, float[] offsets);
} }
/** Constrained property for a {@link TransformConstraint}. */ /** Constrained property for a {@link TransformConstraint}. */
@ -194,9 +194,9 @@ public class TransformConstraintData extends ConstraintData<TransformConstraint,
} }
static public class FromRotate extends FromProperty { static public class FromRotate extends FromProperty {
public float value (BonePose source, boolean local, float[] offsets) { public float value (Skeleton skeleton, BonePose source, boolean local, float[] offsets) {
if (local) return source.rotation + offsets[ROTATION]; if (local) return source.rotation + offsets[ROTATION];
float value = atan2(source.c, source.a) * radDeg float value = atan2(source.c / skeleton.scaleY, source.a / skeleton.scaleX) * radDeg
+ (source.a * source.d - source.b * source.c > 0 ? offsets[ROTATION] : -offsets[ROTATION]); + (source.a * source.d - source.b * source.c > 0 ? offsets[ROTATION] : -offsets[ROTATION]);
if (value < 0) value += 360; if (value < 0) value += 360;
return value; return value;
@ -231,8 +231,8 @@ public class TransformConstraintData extends ConstraintData<TransformConstraint,
} }
static public class FromX extends FromProperty { static public class FromX extends FromProperty {
public float value (BonePose source, boolean local, float[] offsets) { public float value (Skeleton skeleton, BonePose source, boolean local, float[] offsets) {
return local ? source.x + offsets[X] : offsets[X] * source.a + offsets[Y] * source.b + source.worldX; return local ? source.x + offsets[X] : (offsets[X] * source.a + offsets[Y] * source.b + source.worldX) / skeleton.scaleX;
} }
} }
@ -253,8 +253,8 @@ public class TransformConstraintData extends ConstraintData<TransformConstraint,
} }
static public class FromY extends FromProperty { static public class FromY extends FromProperty {
public float value (BonePose source, boolean local, float[] offsets) { public float value (Skeleton skeleton, BonePose source, boolean local, float[] offsets) {
return local ? source.y + offsets[Y] : offsets[X] * source.c + offsets[Y] * source.d + source.worldY; return local ? source.y + offsets[Y] : (offsets[X] * source.c + offsets[Y] * source.d + source.worldY) / skeleton.scaleY;
} }
} }
@ -275,8 +275,10 @@ public class TransformConstraintData extends ConstraintData<TransformConstraint,
} }
static public class FromScaleX extends FromProperty { static public class FromScaleX extends FromProperty {
public float value (BonePose source, boolean local, float[] offsets) { public float value (Skeleton skeleton, BonePose source, boolean local, float[] offsets) {
return (local ? source.scaleX : (float)Math.sqrt(source.a * source.a + source.c * source.c)) + offsets[SCALEX]; if (local) return source.scaleX + offsets[SCALEX];
float a = source.a / skeleton.scaleX, c = source.c / skeleton.scaleY;
return (float)Math.sqrt(a * a + c * c) + offsets[SCALEX];
} }
} }
@ -306,8 +308,10 @@ public class TransformConstraintData extends ConstraintData<TransformConstraint,
} }
static public class FromScaleY extends FromProperty { static public class FromScaleY extends FromProperty {
public float value (BonePose source, boolean local, float[] offsets) { public float value (Skeleton skeleton, BonePose source, boolean local, float[] offsets) {
return (local ? source.scaleY : (float)Math.sqrt(source.b * source.b + source.d * source.d)) + offsets[SCALEY]; if (local) return source.scaleY + offsets[SCALEY];
float b = source.b / skeleton.scaleX, d = source.d / skeleton.scaleY;
return (float)Math.sqrt(b * b + d * d) + offsets[SCALEY];
} }
} }
@ -337,8 +341,10 @@ public class TransformConstraintData extends ConstraintData<TransformConstraint,
} }
static public class FromShearY extends FromProperty { static public class FromShearY extends FromProperty {
public float value (BonePose source, boolean local, float[] offsets) { public float value (Skeleton skeleton, BonePose source, boolean local, float[] offsets) {
return (local ? source.shearY : (atan2(source.d, source.b) - atan2(source.c, source.a)) * radDeg - 90) + offsets[SHEARY]; if (local) return source.shearY + offsets[SHEARY];
float sx = 1 / skeleton.scaleX, sy = 1 / skeleton.scaleY;
return (atan2(source.d * sy, source.b * sx) - atan2(source.c * sy, source.a * sx)) * radDeg - 90 + offsets[SHEARY];
} }
} }