[libgdx] Fixed slider using wrong pose. Use short pose variable for all constraints.

This commit is contained in:
Nathan Sweet 2025-05-08 23:35:15 -04:00
parent 1a6b0cf397
commit 70031018f2
5 changed files with 33 additions and 34 deletions

View File

@ -62,14 +62,14 @@ public class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkC
/** Applies the constraint to the constrained bones. */
public void update (Skeleton skeleton, Physics physics) {
IkConstraintPose a = applied;
if (a.mix == 0) return;
IkConstraintPose p = applied;
if (p.mix == 0) return;
BonePose target = this.target.applied;
BonePose[] bones = this.bones.items;
switch (this.bones.size) {
case 1 -> apply(skeleton, bones[0], target.worldX, target.worldY, a.compress, a.stretch, data.uniform, a.mix);
case 2 -> apply(skeleton, bones[0], bones[1], target.worldX, target.worldY, a.bendDirection, a.stretch, data.uniform,
a.softness, a.mix);
case 1 -> apply(skeleton, bones[0], target.worldX, target.worldY, p.compress, p.stretch, data.uniform, p.mix);
case 2 -> apply(skeleton, bones[0], bones[1], target.worldX, target.worldY, p.bendDirection, p.stretch, data.uniform,
p.softness, p.mix);
}
}

View File

@ -79,8 +79,8 @@ public class PathConstraint extends Constraint<PathConstraint, PathConstraintDat
public void update (Skeleton skeleton, Physics physics) {
if (!(slot.applied.attachment instanceof PathAttachment pathAttachment)) return;
PathConstraintPose pose = applied;
float mixRotate = pose.mixRotate, mixX = pose.mixX, mixY = pose.mixY;
PathConstraintPose p = applied;
float mixRotate = p.mixRotate, mixX = p.mixX, mixY = p.mixY;
if (mixRotate == 0 && mixX == 0 && mixY == 0) return;
PathConstraintData data = this.data;
@ -88,7 +88,7 @@ public class PathConstraint extends Constraint<PathConstraint, PathConstraintDat
int boneCount = this.bones.size, spacesCount = tangents ? boneCount : boneCount + 1;
BonePose[] bones = this.bones.items;
float[] spaces = this.spaces.setSize(spacesCount), lengths = scale ? this.lengths.setSize(boneCount) : null;
float spacing = pose.spacing;
float spacing = p.spacing;
switch (data.spacingMode) {
case percent -> {
@ -149,14 +149,14 @@ public class PathConstraint extends Constraint<PathConstraint, PathConstraintDat
tip = data.rotateMode == RotateMode.chain;
else {
tip = false;
BonePose p = slot.bone.applied;
offsetRotation *= p.a * p.d - p.b * p.c > 0 ? degRad : -degRad;
BonePose bone = slot.bone.applied;
offsetRotation *= bone.a * bone.d - bone.b * bone.c > 0 ? degRad : -degRad;
}
for (int i = 0, p = 3, u = skeleton.update; i < boneCount; i++, p += 3) {
for (int i = 0, ip = 3, u = skeleton.update; i < boneCount; i++, ip += 3) {
BonePose bone = bones[i];
bone.worldX += (boneX - bone.worldX) * mixX;
bone.worldY += (boneY - bone.worldY) * mixY;
float x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
float x = positions[ip], y = positions[ip + 1], dx = x - boneX, dy = y - boneY;
if (scale) {
float length = lengths[i];
if (length >= epsilon) {
@ -170,9 +170,9 @@ public class PathConstraint extends Constraint<PathConstraint, PathConstraintDat
if (mixRotate > 0) {
float a = bone.a, b = bone.b, c = bone.c, d = bone.d, r, cos, sin;
if (tangents)
r = positions[p - 1];
r = positions[ip - 1];
else if (spaces[i + 1] < epsilon)
r = positions[p + 2];
r = positions[ip + 2];
else
r = atan2(dy, dx);
r -= atan2(c, a);

View File

@ -95,8 +95,8 @@ public class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
/** Applies the constraint to the constrained bones. */
public void update (Skeleton skeleton, Physics physics) {
PhysicsConstraintPose pose = applied;
float mix = pose.mix;
PhysicsConstraintPose p = applied;
float mix = p.mix;
if (mix == 0) return;
boolean x = data.x > 0, y = data.y > 0, rotateOrShearX = data.rotate > 0 || data.shearX > 0, scaleX = data.scaleX > 0;
@ -120,7 +120,7 @@ public class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
ux = bx;
uy = by;
} else {
float a = remaining, i = pose.inertia, f = skeleton.data.referenceScale, d = -1, qx = data.limit * delta,
float a = remaining, i = p.inertia, f = skeleton.data.referenceScale, d = -1, qx = data.limit * delta,
qy = qx * Math.abs(skeleton.scaleY);
qx *= Math.abs(skeleton.scaleX);
if (x || y) {
@ -135,9 +135,9 @@ public class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
uy = by;
}
if (a >= t) {
d = (float)Math.pow(pose.damping, 60 * t);
float m = pose.massInverse * t, e = pose.strength, w = pose.wind * f * skeleton.scaleX,
g = pose.gravity * f * skeleton.scaleY, xs = xOffset, ys = yOffset;
d = (float)Math.pow(p.damping, 60 * t);
float m = p.massInverse * t, e = p.strength, w = p.wind * f * skeleton.scaleX,
g = p.gravity * f * skeleton.scaleY, xs = xOffset, ys = yOffset;
do {
if (x) {
xVelocity += (w - xOffset * e) * m;
@ -187,9 +187,9 @@ public class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
if (r > 0) scaleOffset += (dx * c + dy * s) * i / r;
}
if (a >= t) {
if (d == -1) d = (float)Math.pow(pose.damping, 60 * t);
float m = pose.massInverse * t, e = pose.strength, w = pose.wind, g = pose.gravity, h = l / f,
rs = rotateOffset, ss = scaleOffset;
if (d == -1) d = (float)Math.pow(p.damping, 60 * t);
float m = p.massInverse * t, e = p.strength, w = p.wind, g = p.gravity, h = l / f, rs = rotateOffset,
ss = scaleOffset;
while (true) {
a -= t;
if (scaleX) {

View File

@ -59,16 +59,17 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
}
public void update (Skeleton skeleton, Physics physics) {
if (pose.mix == 0) return;
SliderPose p = applied;
if (p.mix == 0) return;
Animation animation = data.animation;
if (bone != null) {
if (!bone.active) return;
pose.time = (data.property.value(bone.applied, data.local, offsets) - data.property.offset) * data.scale;
p.time = (data.property.value(bone.applied, data.local, offsets) - data.property.offset) * data.scale;
if (data.loop)
pose.time = animation.duration + (pose.time % animation.duration);
p.time = animation.duration + (p.time % animation.duration);
else
pose.time = Math.max(0, pose.time);
p.time = Math.max(0, p.time);
}
Bone[] bones = skeleton.bones.items;
@ -76,8 +77,7 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
for (int i = 0, n = animation.timelines.size; i < n; i++)
if (timelines[i] instanceof BoneTimeline timeline) bones[timeline.getBoneIndex()].applied.modifyLocal(skeleton);
SliderPose pose = applied;
animation.apply(skeleton, pose.time, pose.time, data.loop, null, pose.mix, data.additive ? MixBlend.add : MixBlend.replace,
animation.apply(skeleton, p.time, p.time, data.loop, null, p.mix, data.additive ? MixBlend.add : MixBlend.replace,
MixDirection.in, true);
}

View File

@ -63,9 +63,8 @@ public class TransformConstraint extends Constraint<TransformConstraint, Transfo
/** Applies the constraint to the constrained bones. */
public void update (Skeleton skeleton, Physics physics) {
TransformConstraintPose pose = applied;
if (pose.mixRotate == 0 && pose.mixX == 0 && pose.mixY == 0 && pose.mixScaleX == 0 && pose.mixScaleY == 0
&& pose.mixShearY == 0) return;
TransformConstraintPose p = applied;
if (p.mixRotate == 0 && p.mixX == 0 && p.mixY == 0 && p.mixScaleX == 0 && p.mixScaleY == 0 && p.mixShearY == 0) return;
TransformConstraintData data = this.data;
boolean localSource = data.localSource, localTarget = data.localTarget, additive = data.additive, clamp = data.clamp;
@ -88,7 +87,7 @@ public class TransformConstraint extends Constraint<TransformConstraint, Transfo
ToProperty[] toItems = from.to.items;
for (int t = 0, tn = from.to.size; t < tn; t++) {
ToProperty to = toItems[t];
if (to.mix(pose) != 0) {
if (to.mix(p) != 0) {
float clamped = to.offset + value * to.scale;
if (clamp) {
if (to.offset < to.max)
@ -96,7 +95,7 @@ public class TransformConstraint extends Constraint<TransformConstraint, Transfo
else
clamped = clamp(clamped, to.max, to.offset);
}
to.apply(pose, bone, clamped, localTarget, additive);
to.apply(p, bone, clamped, localTarget, additive);
}
}
}