mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
[libgdx] Fixed local dirty flag.
This commit is contained in:
parent
f0c61be159
commit
2a52efd437
@ -67,8 +67,8 @@ public class Bone extends PosedActive<BoneData, BoneLocal, BonePose> {
|
||||
}
|
||||
|
||||
void resetUpdate (Skeleton skeleton) {
|
||||
if (applied.update != skeleton.update) return;
|
||||
applied.update = 0;
|
||||
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);
|
||||
|
||||
@ -15,12 +15,11 @@ public class BonePose extends BoneLocal implements Update {
|
||||
Bone bone;
|
||||
float a, b, worldX;
|
||||
float c, d, worldY;
|
||||
int update;
|
||||
boolean localDirty;
|
||||
int world, local;
|
||||
|
||||
/** Called by {@link Skeleton#updateCache()} to compute the world transform, if needed. */
|
||||
public void update (Skeleton skeleton, Physics physics) {
|
||||
if (update != skeleton.update) updateWorldTransform(skeleton);
|
||||
if (world != skeleton.update) updateWorldTransform(skeleton);
|
||||
}
|
||||
|
||||
/** Computes the world transform using the parent bone's applied pose and this pose. Child bones are not updated.
|
||||
@ -28,8 +27,10 @@ public class BonePose extends BoneLocal implements Update {
|
||||
* See <a href="https://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine
|
||||
* Runtimes Guide. */
|
||||
public void updateWorldTransform (Skeleton skeleton) {
|
||||
update = skeleton.update;
|
||||
localDirty = false;
|
||||
if (local == skeleton.update)
|
||||
updateLocalTransform(skeleton);
|
||||
else
|
||||
world = skeleton.update;
|
||||
|
||||
if (bone.parent == null) { // Root bone.
|
||||
float sx = skeleton.scaleX, sy = skeleton.scaleY;
|
||||
@ -138,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) {
|
||||
update = skeleton.update;
|
||||
localDirty = false;
|
||||
world = skeleton.update;
|
||||
local = 0;
|
||||
|
||||
if (bone.parent == null) {
|
||||
x = worldX - skeleton.x;
|
||||
@ -220,8 +221,8 @@ 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 () {
|
||||
return localDirty;
|
||||
public boolean isLocalDirty (Skeleton skeleton) {
|
||||
return local == skeleton.update;
|
||||
}
|
||||
|
||||
/** Part of the world transform matrix for the X axis. If changed, {@link #updateLocalTransform(Skeleton)} should be called. */
|
||||
|
||||
@ -114,7 +114,7 @@ public class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkC
|
||||
static public void apply (Skeleton skeleton, BonePose bone, float targetX, float targetY, boolean compress, boolean stretch,
|
||||
boolean uniform, float alpha) {
|
||||
if (bone == null) throw new IllegalArgumentException("bone cannot be null.");
|
||||
if (bone.localDirty) bone.updateLocalTransform(skeleton);
|
||||
if (bone.local == skeleton.update) bone.updateLocalTransform(skeleton);
|
||||
BonePose p = bone.bone.parent.applied;
|
||||
float pa = p.a, pb = p.b, pc = p.c, pd = p.d;
|
||||
float rotationIK = -bone.shearX - bone.rotation, tx, ty;
|
||||
@ -177,8 +177,8 @@ public class IkConstraint extends Constraint<IkConstraint, IkConstraintData, IkC
|
||||
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.localDirty) parent.updateLocalTransform(skeleton);
|
||||
if (child.localDirty) child.updateLocalTransform(skeleton);
|
||||
if (parent.local == skeleton.update) parent.updateLocalTransform(skeleton);
|
||||
if (child.local == skeleton.update) child.updateLocalTransform(skeleton);
|
||||
float px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY, csx = child.scaleX;
|
||||
int os1, os2, s2;
|
||||
if (psx < 0) {
|
||||
|
||||
@ -196,7 +196,7 @@ public class PathConstraint extends Constraint<PathConstraint, PathConstraintDat
|
||||
bone.c = sin * a + cos * c;
|
||||
bone.d = sin * b + cos * d;
|
||||
}
|
||||
bone.localDirty = true;
|
||||
bone.local = skeleton.update;
|
||||
bone.bone.resetUpdate(skeleton);
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ public class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
|
||||
tx = l * bone.a;
|
||||
ty = l * bone.c;
|
||||
}
|
||||
bone.localDirty = true;
|
||||
bone.local = skeleton.update;
|
||||
bone.bone.resetUpdate(skeleton);
|
||||
}
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
|
||||
if (timelines[i] instanceof BoneTimeline timeline) {
|
||||
Bone bone = bones[timeline.getBoneIndex()];
|
||||
bone.resetUpdate(skeleton);
|
||||
if (bone.applied.localDirty) bone.applied.updateLocalTransform(skeleton);
|
||||
if (bone.applied.local == skeleton.update) bone.applied.updateLocalTransform(skeleton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,13 +70,14 @@ public class TransformConstraint extends Constraint<TransformConstraint, Transfo
|
||||
TransformConstraintData data = this.data;
|
||||
boolean localSource = data.localSource, localTarget = data.localTarget, additive = data.additive, clamp = data.clamp;
|
||||
BonePose source = this.source.applied;
|
||||
if (localSource && source.localDirty) source.updateLocalTransform(skeleton);
|
||||
int update = skeleton.update;
|
||||
if (localSource && source.local == skeleton.update) source.updateLocalTransform(skeleton);
|
||||
FromProperty[] fromItems = data.properties.items;
|
||||
int fn = data.properties.size;
|
||||
BonePose[] bones = this.bones.items;
|
||||
for (int i = 0, n = this.bones.size; i < n; i++) {
|
||||
BonePose bone = bones[i];
|
||||
if (localTarget && bone.localDirty) bone.updateLocalTransform(skeleton);
|
||||
if (localTarget && bone.local == update) bone.updateLocalTransform(skeleton);
|
||||
for (int f = 0; f < fn; f++) {
|
||||
FromProperty from = fromItems[f];
|
||||
float value = from.value(data, source, localSource) - from.offset;
|
||||
@ -98,7 +99,7 @@ public class TransformConstraint extends Constraint<TransformConstraint, Transfo
|
||||
if (localTarget)
|
||||
bone.updateWorldTransform(skeleton);
|
||||
else
|
||||
bone.localDirty = true;
|
||||
bone.local = update;
|
||||
bone.bone.resetUpdate(skeleton);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user