mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-25 19:21:26 +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) {
|
void resetUpdate (Skeleton skeleton) {
|
||||||
if (applied.update != skeleton.update) return;
|
if (applied.world != skeleton.update) return;
|
||||||
applied.update = 0;
|
applied.world = 0;
|
||||||
Bone[] children = this.children.items;
|
Bone[] children = this.children.items;
|
||||||
for (int i = 0, n = this.children.size; i < n; i++)
|
for (int i = 0, n = this.children.size; i < n; i++)
|
||||||
children[i].resetUpdate(skeleton);
|
children[i].resetUpdate(skeleton);
|
||||||
|
|||||||
@ -15,12 +15,11 @@ public class BonePose extends BoneLocal implements Update {
|
|||||||
Bone bone;
|
Bone bone;
|
||||||
float a, b, worldX;
|
float a, b, worldX;
|
||||||
float c, d, worldY;
|
float c, d, worldY;
|
||||||
int update;
|
int world, local;
|
||||||
boolean localDirty;
|
|
||||||
|
|
||||||
/** Called by {@link Skeleton#updateCache()} to compute the world transform, if needed. */
|
/** Called by {@link Skeleton#updateCache()} to compute the world transform, if needed. */
|
||||||
public void update (Skeleton skeleton, Physics physics) {
|
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.
|
/** 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
|
* See <a href="https://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine
|
||||||
* Runtimes Guide. */
|
* Runtimes Guide. */
|
||||||
public void updateWorldTransform (Skeleton skeleton) {
|
public void updateWorldTransform (Skeleton skeleton) {
|
||||||
update = skeleton.update;
|
if (local == skeleton.update)
|
||||||
localDirty = false;
|
updateLocalTransform(skeleton);
|
||||||
|
else
|
||||||
|
world = skeleton.update;
|
||||||
|
|
||||||
if (bone.parent == null) { // Root bone.
|
if (bone.parent == null) { // Root bone.
|
||||||
float sx = skeleton.scaleX, sy = skeleton.scaleY;
|
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
|
* 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. */
|
* 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) {
|
public void updateLocalTransform (Skeleton skeleton) {
|
||||||
update = skeleton.update;
|
world = skeleton.update;
|
||||||
localDirty = false;
|
local = 0;
|
||||||
|
|
||||||
if (bone.parent == null) {
|
if (bone.parent == null) {
|
||||||
x = worldX - skeleton.x;
|
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
|
/** When true, the world transform has been modified and the local transform no longer matches. Call
|
||||||
* {@link #updateLocalTransform(Skeleton)} before using the local transform. */
|
* {@link #updateLocalTransform(Skeleton)} before using the local transform. */
|
||||||
public boolean isLocalDirty () {
|
public boolean isLocalDirty (Skeleton skeleton) {
|
||||||
return localDirty;
|
return local == skeleton.update;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Part of the world transform matrix for the X axis. If changed, {@link #updateLocalTransform(Skeleton)} should be called. */
|
/** 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,
|
static public void apply (Skeleton skeleton, BonePose bone, float targetX, float targetY, boolean compress, boolean stretch,
|
||||||
boolean uniform, float alpha) {
|
boolean uniform, float alpha) {
|
||||||
if (bone == null) throw new IllegalArgumentException("bone cannot be null.");
|
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;
|
BonePose p = bone.bone.parent.applied;
|
||||||
float pa = p.a, pb = p.b, pc = p.c, pd = p.d;
|
float pa = p.a, pb = p.b, pc = p.c, pd = p.d;
|
||||||
float rotationIK = -bone.shearX - bone.rotation, tx, ty;
|
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 (parent == null) throw new IllegalArgumentException("parent cannot be null.");
|
||||||
if (child == null) throw new IllegalArgumentException("child 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.inherit != Inherit.normal || child.inherit != Inherit.normal) return;
|
||||||
if (parent.localDirty) parent.updateLocalTransform(skeleton);
|
if (parent.local == skeleton.update) parent.updateLocalTransform(skeleton);
|
||||||
if (child.localDirty) child.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;
|
float px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY, csx = child.scaleX;
|
||||||
int os1, os2, s2;
|
int os1, os2, s2;
|
||||||
if (psx < 0) {
|
if (psx < 0) {
|
||||||
|
|||||||
@ -196,7 +196,7 @@ public class PathConstraint extends Constraint<PathConstraint, PathConstraintDat
|
|||||||
bone.c = sin * a + cos * c;
|
bone.c = sin * a + cos * c;
|
||||||
bone.d = sin * b + cos * d;
|
bone.d = sin * b + cos * d;
|
||||||
}
|
}
|
||||||
bone.localDirty = true;
|
bone.local = skeleton.update;
|
||||||
bone.bone.resetUpdate(skeleton);
|
bone.bone.resetUpdate(skeleton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -263,7 +263,7 @@ public class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
|
|||||||
tx = l * bone.a;
|
tx = l * bone.a;
|
||||||
ty = l * bone.c;
|
ty = l * bone.c;
|
||||||
}
|
}
|
||||||
bone.localDirty = true;
|
bone.local = skeleton.update;
|
||||||
bone.bone.resetUpdate(skeleton);
|
bone.bone.resetUpdate(skeleton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -65,7 +65,7 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
|
|||||||
if (timelines[i] instanceof BoneTimeline timeline) {
|
if (timelines[i] instanceof BoneTimeline timeline) {
|
||||||
Bone bone = bones[timeline.getBoneIndex()];
|
Bone bone = bones[timeline.getBoneIndex()];
|
||||||
bone.resetUpdate(skeleton);
|
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;
|
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;
|
||||||
BonePose source = this.source.applied;
|
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;
|
FromProperty[] fromItems = data.properties.items;
|
||||||
int fn = data.properties.size;
|
int fn = data.properties.size;
|
||||||
BonePose[] bones = this.bones.items;
|
BonePose[] bones = this.bones.items;
|
||||||
for (int i = 0, n = this.bones.size; i < n; i++) {
|
for (int i = 0, n = this.bones.size; i < n; i++) {
|
||||||
BonePose bone = bones[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++) {
|
for (int f = 0; f < fn; f++) {
|
||||||
FromProperty from = fromItems[f];
|
FromProperty from = fromItems[f];
|
||||||
float value = from.value(data, source, localSource) - from.offset;
|
float value = from.value(data, source, localSource) - from.offset;
|
||||||
@ -98,7 +99,7 @@ public class TransformConstraint extends Constraint<TransformConstraint, Transfo
|
|||||||
if (localTarget)
|
if (localTarget)
|
||||||
bone.updateWorldTransform(skeleton);
|
bone.updateWorldTransform(skeleton);
|
||||||
else
|
else
|
||||||
bone.localDirty = true;
|
bone.local = update;
|
||||||
bone.bone.resetUpdate(skeleton);
|
bone.bone.resetUpdate(skeleton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user