mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[libgdx] Fixed slider using wrong pose. Use short pose variable for all constraints.
This commit is contained in:
parent
1a6b0cf397
commit
70031018f2
@ -62,14 +62,14 @@ public class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkC
|
|||||||
|
|
||||||
/** Applies the constraint to the constrained bones. */
|
/** Applies the constraint to the constrained bones. */
|
||||||
public void update (Skeleton skeleton, Physics physics) {
|
public void update (Skeleton skeleton, Physics physics) {
|
||||||
IkConstraintPose a = applied;
|
IkConstraintPose p = applied;
|
||||||
if (a.mix == 0) return;
|
if (p.mix == 0) return;
|
||||||
BonePose target = this.target.applied;
|
BonePose target = this.target.applied;
|
||||||
BonePose[] bones = this.bones.items;
|
BonePose[] bones = this.bones.items;
|
||||||
switch (this.bones.size) {
|
switch (this.bones.size) {
|
||||||
case 1 -> apply(skeleton, bones[0], target.worldX, target.worldY, a.compress, a.stretch, data.uniform, 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, a.bendDirection, a.stretch, data.uniform,
|
case 2 -> apply(skeleton, bones[0], bones[1], target.worldX, target.worldY, p.bendDirection, p.stretch, data.uniform,
|
||||||
a.softness, a.mix);
|
p.softness, p.mix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -79,8 +79,8 @@ public class PathConstraint extends Constraint<PathConstraint, PathConstraintDat
|
|||||||
public void update (Skeleton skeleton, Physics physics) {
|
public void update (Skeleton skeleton, Physics physics) {
|
||||||
if (!(slot.applied.attachment instanceof PathAttachment pathAttachment)) return;
|
if (!(slot.applied.attachment instanceof PathAttachment pathAttachment)) return;
|
||||||
|
|
||||||
PathConstraintPose pose = applied;
|
PathConstraintPose p = applied;
|
||||||
float mixRotate = pose.mixRotate, mixX = pose.mixX, mixY = pose.mixY;
|
float mixRotate = p.mixRotate, mixX = p.mixX, mixY = p.mixY;
|
||||||
if (mixRotate == 0 && mixX == 0 && mixY == 0) return;
|
if (mixRotate == 0 && mixX == 0 && mixY == 0) return;
|
||||||
|
|
||||||
PathConstraintData data = this.data;
|
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;
|
int boneCount = this.bones.size, spacesCount = tangents ? boneCount : boneCount + 1;
|
||||||
BonePose[] bones = this.bones.items;
|
BonePose[] bones = this.bones.items;
|
||||||
float[] spaces = this.spaces.setSize(spacesCount), lengths = scale ? this.lengths.setSize(boneCount) : null;
|
float[] spaces = this.spaces.setSize(spacesCount), lengths = scale ? this.lengths.setSize(boneCount) : null;
|
||||||
float spacing = pose.spacing;
|
float spacing = p.spacing;
|
||||||
|
|
||||||
switch (data.spacingMode) {
|
switch (data.spacingMode) {
|
||||||
case percent -> {
|
case percent -> {
|
||||||
@ -149,14 +149,14 @@ public class PathConstraint extends Constraint<PathConstraint, PathConstraintDat
|
|||||||
tip = data.rotateMode == RotateMode.chain;
|
tip = data.rotateMode == RotateMode.chain;
|
||||||
else {
|
else {
|
||||||
tip = false;
|
tip = false;
|
||||||
BonePose p = slot.bone.applied;
|
BonePose bone = slot.bone.applied;
|
||||||
offsetRotation *= p.a * p.d - p.b * p.c > 0 ? degRad : -degRad;
|
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];
|
BonePose bone = bones[i];
|
||||||
bone.worldX += (boneX - bone.worldX) * mixX;
|
bone.worldX += (boneX - bone.worldX) * mixX;
|
||||||
bone.worldY += (boneY - bone.worldY) * mixY;
|
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) {
|
if (scale) {
|
||||||
float length = lengths[i];
|
float length = lengths[i];
|
||||||
if (length >= epsilon) {
|
if (length >= epsilon) {
|
||||||
@ -170,9 +170,9 @@ public class PathConstraint extends Constraint<PathConstraint, PathConstraintDat
|
|||||||
if (mixRotate > 0) {
|
if (mixRotate > 0) {
|
||||||
float a = bone.a, b = bone.b, c = bone.c, d = bone.d, r, cos, sin;
|
float a = bone.a, b = bone.b, c = bone.c, d = bone.d, r, cos, sin;
|
||||||
if (tangents)
|
if (tangents)
|
||||||
r = positions[p - 1];
|
r = positions[ip - 1];
|
||||||
else if (spaces[i + 1] < epsilon)
|
else if (spaces[i + 1] < epsilon)
|
||||||
r = positions[p + 2];
|
r = positions[ip + 2];
|
||||||
else
|
else
|
||||||
r = atan2(dy, dx);
|
r = atan2(dy, dx);
|
||||||
r -= atan2(c, a);
|
r -= atan2(c, a);
|
||||||
|
|||||||
@ -95,8 +95,8 @@ public class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
|
|||||||
|
|
||||||
/** Applies the constraint to the constrained bones. */
|
/** Applies the constraint to the constrained bones. */
|
||||||
public void update (Skeleton skeleton, Physics physics) {
|
public void update (Skeleton skeleton, Physics physics) {
|
||||||
PhysicsConstraintPose pose = applied;
|
PhysicsConstraintPose p = applied;
|
||||||
float mix = pose.mix;
|
float mix = p.mix;
|
||||||
if (mix == 0) return;
|
if (mix == 0) return;
|
||||||
|
|
||||||
boolean x = data.x > 0, y = data.y > 0, rotateOrShearX = data.rotate > 0 || data.shearX > 0, scaleX = data.scaleX > 0;
|
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;
|
ux = bx;
|
||||||
uy = by;
|
uy = by;
|
||||||
} else {
|
} 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);
|
qy = qx * Math.abs(skeleton.scaleY);
|
||||||
qx *= Math.abs(skeleton.scaleX);
|
qx *= Math.abs(skeleton.scaleX);
|
||||||
if (x || y) {
|
if (x || y) {
|
||||||
@ -135,9 +135,9 @@ public class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
|
|||||||
uy = by;
|
uy = by;
|
||||||
}
|
}
|
||||||
if (a >= t) {
|
if (a >= t) {
|
||||||
d = (float)Math.pow(pose.damping, 60 * t);
|
d = (float)Math.pow(p.damping, 60 * t);
|
||||||
float m = pose.massInverse * t, e = pose.strength, w = pose.wind * f * skeleton.scaleX,
|
float m = p.massInverse * t, e = p.strength, w = p.wind * f * skeleton.scaleX,
|
||||||
g = pose.gravity * f * skeleton.scaleY, xs = xOffset, ys = yOffset;
|
g = p.gravity * f * skeleton.scaleY, xs = xOffset, ys = yOffset;
|
||||||
do {
|
do {
|
||||||
if (x) {
|
if (x) {
|
||||||
xVelocity += (w - xOffset * e) * m;
|
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 (r > 0) scaleOffset += (dx * c + dy * s) * i / r;
|
||||||
}
|
}
|
||||||
if (a >= t) {
|
if (a >= t) {
|
||||||
if (d == -1) d = (float)Math.pow(pose.damping, 60 * t);
|
if (d == -1) d = (float)Math.pow(p.damping, 60 * t);
|
||||||
float m = pose.massInverse * t, e = pose.strength, w = pose.wind, g = pose.gravity, h = l / f,
|
float m = p.massInverse * t, e = p.strength, w = p.wind, g = p.gravity, h = l / f, rs = rotateOffset,
|
||||||
rs = rotateOffset, ss = scaleOffset;
|
ss = scaleOffset;
|
||||||
while (true) {
|
while (true) {
|
||||||
a -= t;
|
a -= t;
|
||||||
if (scaleX) {
|
if (scaleX) {
|
||||||
|
|||||||
@ -59,16 +59,17 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update (Skeleton skeleton, Physics physics) {
|
public void update (Skeleton skeleton, Physics physics) {
|
||||||
if (pose.mix == 0) return;
|
SliderPose p = applied;
|
||||||
|
if (p.mix == 0) return;
|
||||||
|
|
||||||
Animation animation = data.animation;
|
Animation animation = data.animation;
|
||||||
if (bone != null) {
|
if (bone != null) {
|
||||||
if (!bone.active) return;
|
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)
|
if (data.loop)
|
||||||
pose.time = animation.duration + (pose.time % animation.duration);
|
p.time = animation.duration + (p.time % animation.duration);
|
||||||
else
|
else
|
||||||
pose.time = Math.max(0, pose.time);
|
p.time = Math.max(0, p.time);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bone[] bones = skeleton.bones.items;
|
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++)
|
for (int i = 0, n = animation.timelines.size; i < n; i++)
|
||||||
if (timelines[i] instanceof BoneTimeline timeline) bones[timeline.getBoneIndex()].applied.modifyLocal(skeleton);
|
if (timelines[i] instanceof BoneTimeline timeline) bones[timeline.getBoneIndex()].applied.modifyLocal(skeleton);
|
||||||
|
|
||||||
SliderPose pose = applied;
|
animation.apply(skeleton, p.time, p.time, data.loop, null, p.mix, data.additive ? MixBlend.add : MixBlend.replace,
|
||||||
animation.apply(skeleton, pose.time, pose.time, data.loop, null, pose.mix, data.additive ? MixBlend.add : MixBlend.replace,
|
|
||||||
MixDirection.in, true);
|
MixDirection.in, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -63,9 +63,8 @@ public class TransformConstraint extends Constraint<TransformConstraint, Transfo
|
|||||||
|
|
||||||
/** Applies the constraint to the constrained bones. */
|
/** Applies the constraint to the constrained bones. */
|
||||||
public void update (Skeleton skeleton, Physics physics) {
|
public void update (Skeleton skeleton, Physics physics) {
|
||||||
TransformConstraintPose pose = applied;
|
TransformConstraintPose p = applied;
|
||||||
if (pose.mixRotate == 0 && pose.mixX == 0 && pose.mixY == 0 && pose.mixScaleX == 0 && pose.mixScaleY == 0
|
if (p.mixRotate == 0 && p.mixX == 0 && p.mixY == 0 && p.mixScaleX == 0 && p.mixScaleY == 0 && p.mixShearY == 0) return;
|
||||||
&& pose.mixShearY == 0) return;
|
|
||||||
|
|
||||||
TransformConstraintData data = this.data;
|
TransformConstraintData data = this.data;
|
||||||
boolean localSource = data.localSource, localTarget = data.localTarget, additive = data.additive, clamp = data.clamp;
|
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;
|
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];
|
||||||
if (to.mix(pose) != 0) {
|
if (to.mix(p) != 0) {
|
||||||
float clamped = to.offset + value * to.scale;
|
float clamped = to.offset + value * to.scale;
|
||||||
if (clamp) {
|
if (clamp) {
|
||||||
if (to.offset < to.max)
|
if (to.offset < to.max)
|
||||||
@ -96,7 +95,7 @@ public class TransformConstraint extends Constraint<TransformConstraint, Transfo
|
|||||||
else
|
else
|
||||||
clamped = clamp(clamped, to.max, to.offset);
|
clamped = clamp(clamped, to.max, to.offset);
|
||||||
}
|
}
|
||||||
to.apply(pose, bone, clamped, localTarget, additive);
|
to.apply(p, bone, clamped, localTarget, additive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user