diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java index 9254b9c84..82bffa40c 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java @@ -65,12 +65,4 @@ public class Bone extends PosedActive { public Array getChildren () { return children; } - - void resetUpdate (Skeleton skeleton) { - if (applied.world != skeleton.update) return; - applied.world = 0; - Bone[] children = this.children.items; - for (int i = 0, n = this.children.size; i < n; i++) - children[i].resetUpdate(skeleton); - } } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BonePose.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BonePose.java index 38ff9cf62..555cebf5e 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BonePose.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/BonePose.java @@ -139,8 +139,8 @@ public class BonePose extends BoneLocal implements Update { * Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. The local transform after * calling this method is equivalent to the local transform used to compute the world transform, but may not be identical. */ public void updateLocalTransform (Skeleton skeleton) { - world = skeleton.update; local = 0; + world = skeleton.update; if (bone.parent == null) { x = worldX - skeleton.x; @@ -219,10 +219,33 @@ public class BonePose extends BoneLocal implements Update { } } - /** When true, the world transform has been modified and the local transform no longer matches. Call - * {@link #updateLocalTransform(Skeleton)} before using the local transform. */ - public boolean isLocalDirty (Skeleton skeleton) { - return local == skeleton.update; + /** If the world transform has been modified and the local transform no longer matches, {@link #updateLocalTransform(Skeleton)} + * is called. */ + public void validateLocalTransform (Skeleton skeleton) { + if (local == skeleton.update) updateLocalTransform(skeleton); + } + + void modifyLocal (Skeleton skeleton) { + if (local == skeleton.update) updateLocalTransform(skeleton); + world = 0; + resetWorld(skeleton.update); + } + + void modifyWorld (int update) { + local = update; + world = update; + resetWorld(update); + } + + void resetWorld (int update) { + Bone[] children = bone.children.items; + for (int i = 0, n = bone.children.size; i < n; i++) { + BonePose child = children[i].applied; + if (child.world == update) { + child.world = 0; + child.resetWorld(update); + } + } } /** Part of the world transform matrix for the X axis. If changed, {@link #updateLocalTransform(Skeleton)} should be called. */ diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java index 11508ed58..82ef24230 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java @@ -76,19 +76,12 @@ public class IkConstraint extends Constraint 1) skeleton.constrained(bones.items[1].bone); } boolean isSourceActive () { @@ -112,9 +105,9 @@ public class IkConstraint extends Constraint { @@ -160,25 +153,23 @@ public class IkConstraint extends Constraint 0.0001f) { float dd = tx * tx + ty * ty; if ((compress && dd < b * b) || (stretch && dd > b * b)) { - float s = ((float)Math.sqrt(dd) / b - 1) * alpha + 1; + float s = ((float)Math.sqrt(dd) / b - 1) * mix + 1; bone.scaleX *= s; if (uniform) bone.scaleY *= s; } } } - bone.updateWorldTransform(skeleton); - bone.bone.resetUpdate(skeleton); } /** Applies 2 bone IK. The target is specified in the world coordinate system. * @param child A direct descendant of the parent bone. */ static public void apply (Skeleton skeleton, BonePose parent, BonePose child, float targetX, float targetY, int bendDir, - boolean stretch, boolean uniform, float softness, float alpha) { + boolean stretch, boolean uniform, float softness, float mix) { if (parent == null) throw new IllegalArgumentException("parent cannot be null."); if (child == null) throw new IllegalArgumentException("child cannot be null."); if (parent.inherit != Inherit.normal || child.inherit != Inherit.normal) return; - if (parent.local == skeleton.update) parent.updateLocalTransform(skeleton); - if (child.local == skeleton.update) child.updateLocalTransform(skeleton); + parent.modifyLocal(skeleton); + child.modifyLocal(skeleton); float px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY, csx = child.scaleX; int os1, os2, s2; if (psx < 0) { @@ -218,10 +209,8 @@ public class IkConstraint extends Constraint 180) a2 -= 360; else if (a2 < -180) // a2 += 360; - child.rotation += a2 * alpha; - child.updateWorldTransform(skeleton); - parent.bone.resetUpdate(skeleton); + child.rotation += a2 * mix; } } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java index dab82c1a1..e9458fd26 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java @@ -152,7 +152,7 @@ public class PathConstraint extends Constraint 0 ? degRad : -degRad; } - for (int i = 0, p = 3; i < boneCount; i++, p += 3) { + for (int i = 0, p = 3, u = skeleton.update; i < boneCount; i++, p += 3) { BonePose bone = bones[i]; bone.worldX += (boneX - bone.worldX) * mixX; bone.worldY += (boneY - bone.worldY) * mixY; @@ -196,8 +196,7 @@ public class PathConstraint extends Constraint { pose.time = Math.max(0, pose.time); } - SliderData data = this.data; - Timeline[] timelines = animation.timelines.items; - int timelineCount = animation.timelines.size; Bone[] bones = skeleton.bones.items; - if (pose.mix == 1) { - for (int i = 0; i < timelineCount; i++) - if (timelines[i] instanceof BoneTimeline timeline) bones[timeline.getBoneIndex()].resetUpdate(skeleton); - } else { - for (int i = 0; i < timelineCount; i++) { - if (timelines[i] instanceof BoneTimeline timeline) { - Bone bone = bones[timeline.getBoneIndex()]; - bone.resetUpdate(skeleton); - if (bone.applied.local == skeleton.update) bone.applied.updateLocalTransform(skeleton); - } - } - } + Timeline[] timelines = animation.timelines.items; + 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, @@ -93,35 +81,32 @@ public class Slider extends Constraint { } void sort (Skeleton skeleton) { - Timeline[] timelines = data.animation.timelines.items; - int timelineCount = data.animation.timelines.size; - Bone[] bones = skeleton.bones.items; - for (int i = 0; i < timelineCount; i++) - if (timelines[i] instanceof BoneTimeline timeline) skeleton.sortBone(bones[timeline.getBoneIndex()]); - + if (bone != null && !data.local) skeleton.sortBone(bone); skeleton.updateCache.add(this); + Timeline[] timelines = data.animation.timelines.items; + Bone[] bones = skeleton.bones.items; Slot[] slots = skeleton.slots.items; Constraint[] constraints = skeleton.constraints.items; PhysicsConstraint[] physics = skeleton.physics.items; int physicsCount = skeleton.physics.size; - for (int i = 0; i < timelineCount; i++) { + for (int i = 0, n = data.animation.timelines.size; i < n; i++) { Timeline t = timelines[i]; if (t instanceof BoneTimeline timeline) { Bone bone = bones[timeline.getBoneIndex()]; - skeleton.resetCache(bone); - skeleton.sortReset(bone.children); bone.sorted = false; + skeleton.sortReset(bone.children); + skeleton.constrained(bone); } else if (t instanceof SlotTimeline timeline) - skeleton.resetCache(slots[timeline.getSlotIndex()]); + skeleton.constrained(slots[timeline.getSlotIndex()]); else if (t instanceof PhysicsConstraintTimeline timeline) { if (timeline.constraintIndex == -1) { for (int ii = 0; ii < physicsCount; ii++) - skeleton.resetCache(physics[ii]); + skeleton.constrained(physics[ii]); } else - skeleton.resetCache(constraints[timeline.constraintIndex]); + skeleton.constrained(constraints[timeline.constraintIndex]); } else if (t instanceof ConstraintTimeline timeline) // - skeleton.resetCache(constraints[timeline.getConstraintIndex()]); + skeleton.constrained(constraints[timeline.getConstraintIndex()]); } } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/TransformConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/TransformConstraint.java index c7428e009..24b22aac7 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/TransformConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/TransformConstraint.java @@ -72,13 +72,16 @@ public class TransformConstraint extends Constraint