mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
parent
eada9e756b
commit
4e34c0bae1
@ -80,11 +80,8 @@ public class IkConstraint implements Updatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Applies the constraint to the constrained bones. */
|
/** Applies the constraint to the constrained bones. */
|
||||||
public void apply () {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update () {
|
public void update () {
|
||||||
|
if (mix == 0) return;
|
||||||
Bone target = this.target;
|
Bone target = this.target;
|
||||||
Object[] bones = this.bones.items;
|
Object[] bones = this.bones.items;
|
||||||
switch (this.bones.size) {
|
switch (this.bones.size) {
|
||||||
@ -228,10 +225,6 @@ public class IkConstraint implements Updatable {
|
|||||||
float alpha) {
|
float alpha) {
|
||||||
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 (alpha == 0) {
|
|
||||||
child.updateWorldTransform();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!parent.appliedValid) parent.updateAppliedTransform();
|
if (!parent.appliedValid) parent.updateAppliedTransform();
|
||||||
if (!child.appliedValid) child.updateAppliedTransform();
|
if (!child.appliedValid) child.updateAppliedTransform();
|
||||||
float px = parent.ax, py = parent.ay, psx = parent.ascaleX, sx = psx, psy = parent.ascaleY, csx = child.ascaleX;
|
float px = parent.ax, py = parent.ay, psx = parent.ascaleX, sx = psx, psy = parent.ascaleY, csx = child.ascaleX;
|
||||||
|
|||||||
@ -88,10 +88,6 @@ public class PathConstraint implements Updatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Applies the constraint to the constrained bones. */
|
/** Applies the constraint to the constrained bones. */
|
||||||
public void apply () {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update () {
|
public void update () {
|
||||||
Attachment attachment = target.attachment;
|
Attachment attachment = target.attachment;
|
||||||
if (!(attachment instanceof PathAttachment)) return;
|
if (!(attachment instanceof PathAttachment)) return;
|
||||||
|
|||||||
@ -56,7 +56,6 @@ public class Skeleton {
|
|||||||
final Array<TransformConstraint> transformConstraints;
|
final Array<TransformConstraint> transformConstraints;
|
||||||
final Array<PathConstraint> pathConstraints;
|
final Array<PathConstraint> pathConstraints;
|
||||||
final Array<Updatable> updateCache = new Array();
|
final Array<Updatable> updateCache = new Array();
|
||||||
final Array<Bone> updateCacheReset = new Array();
|
|
||||||
@Null Skin skin;
|
@Null Skin skin;
|
||||||
final Color color;
|
final Color color;
|
||||||
float time;
|
float time;
|
||||||
@ -161,7 +160,6 @@ public class Skeleton {
|
|||||||
public void updateCache () {
|
public void updateCache () {
|
||||||
Array<Updatable> updateCache = this.updateCache;
|
Array<Updatable> updateCache = this.updateCache;
|
||||||
updateCache.clear();
|
updateCache.clear();
|
||||||
updateCacheReset.clear();
|
|
||||||
|
|
||||||
int boneCount = bones.size;
|
int boneCount = bones.size;
|
||||||
Object[] bones = this.bones.items;
|
Object[] bones = this.bones.items;
|
||||||
@ -227,16 +225,18 @@ public class Skeleton {
|
|||||||
Array<Bone> constrained = constraint.bones;
|
Array<Bone> constrained = constraint.bones;
|
||||||
Bone parent = constrained.first();
|
Bone parent = constrained.first();
|
||||||
sortBone(parent);
|
sortBone(parent);
|
||||||
|
if (constrained.size == 1) {
|
||||||
if (constrained.size > 1) {
|
updateCache.add(constraint);
|
||||||
|
sortReset(parent.children);
|
||||||
|
} else {
|
||||||
Bone child = constrained.peek();
|
Bone child = constrained.peek();
|
||||||
if (!updateCache.contains(child, true)) updateCacheReset.add(child);
|
sortBone(child);
|
||||||
|
|
||||||
|
updateCache.add(constraint);
|
||||||
|
|
||||||
|
sortReset(parent.children);
|
||||||
|
child.sorted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCache.add(constraint);
|
|
||||||
|
|
||||||
sortReset(parent.children);
|
|
||||||
constrained.peek().sorted = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sortPathConstraint (PathConstraint constraint) {
|
private void sortPathConstraint (PathConstraint constraint) {
|
||||||
@ -280,7 +280,7 @@ public class Skeleton {
|
|||||||
for (int i = 0; i < boneCount; i++) {
|
for (int i = 0; i < boneCount; i++) {
|
||||||
Bone child = (Bone)constrained[i];
|
Bone child = (Bone)constrained[i];
|
||||||
sortBone(child.parent);
|
sortBone(child.parent);
|
||||||
if (!updateCache.contains(child, true)) updateCacheReset.add(child);
|
sortBone(child);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < boneCount; i++)
|
for (int i = 0; i < boneCount; i++)
|
||||||
@ -342,21 +342,6 @@ public class Skeleton {
|
|||||||
* See <a href="http://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine
|
* See <a href="http://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine
|
||||||
* Runtimes Guide. */
|
* Runtimes Guide. */
|
||||||
public void updateWorldTransform () {
|
public void updateWorldTransform () {
|
||||||
// This partial update avoids computing the world transform for constrained bones when 1) the bone is not updated
|
|
||||||
// before the constraint, 2) the constraint only needs to access the applied local transform, and 3) the constraint calls
|
|
||||||
// updateWorldTransform.
|
|
||||||
Object[] updateCacheReset = this.updateCacheReset.items;
|
|
||||||
for (int i = 0, n = this.updateCacheReset.size; i < n; i++) {
|
|
||||||
Bone bone = (Bone)updateCacheReset[i];
|
|
||||||
bone.ax = bone.x;
|
|
||||||
bone.ay = bone.y;
|
|
||||||
bone.arotation = bone.rotation;
|
|
||||||
bone.ascaleX = bone.scaleX;
|
|
||||||
bone.ascaleY = bone.scaleY;
|
|
||||||
bone.ashearX = bone.shearX;
|
|
||||||
bone.ashearY = bone.shearY;
|
|
||||||
bone.appliedValid = true;
|
|
||||||
}
|
|
||||||
Object[] updateCache = this.updateCache.items;
|
Object[] updateCache = this.updateCache.items;
|
||||||
for (int i = 0, n = this.updateCache.size; i < n; i++)
|
for (int i = 0, n = this.updateCache.size; i < n; i++)
|
||||||
((Updatable)updateCache[i]).update();
|
((Updatable)updateCache[i]).update();
|
||||||
@ -369,22 +354,6 @@ public class Skeleton {
|
|||||||
* Runtimes Guide. */
|
* Runtimes Guide. */
|
||||||
public void updateWorldTransform (Bone parent) {
|
public void updateWorldTransform (Bone parent) {
|
||||||
if (parent == null) throw new IllegalArgumentException("parent cannot be null.");
|
if (parent == null) throw new IllegalArgumentException("parent cannot be null.");
|
||||||
// This partial update avoids computing the world transform for constrained bones when:
|
|
||||||
// 1) the bone is not updated before the constraint,
|
|
||||||
// 2) the constraint only needs to access the applied local transform, and
|
|
||||||
// 3) the constraint calls updateWorldTransform.
|
|
||||||
Object[] updateCacheReset = this.updateCacheReset.items;
|
|
||||||
for (int i = 0, n = this.updateCacheReset.size; i < n; i++) {
|
|
||||||
Bone bone = (Bone)updateCacheReset[i];
|
|
||||||
bone.ax = bone.x;
|
|
||||||
bone.ay = bone.y;
|
|
||||||
bone.arotation = bone.rotation;
|
|
||||||
bone.ascaleX = bone.scaleX;
|
|
||||||
bone.ascaleY = bone.scaleY;
|
|
||||||
bone.ashearX = bone.shearX;
|
|
||||||
bone.ashearY = bone.shearY;
|
|
||||||
bone.appliedValid = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply the parent bone transform to the root bone. The root bone always inherits scale, rotation and reflection.
|
// Apply the parent bone transform to the root bone. The root bone always inherits scale, rotation and reflection.
|
||||||
Bone rootBone = getRootBone();
|
Bone rootBone = getRootBone();
|
||||||
|
|||||||
@ -77,11 +77,8 @@ public class TransformConstraint implements Updatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Applies the constraint to the constrained bones. */
|
/** Applies the constraint to the constrained bones. */
|
||||||
public void apply () {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update () {
|
public void update () {
|
||||||
|
if (rotateMix == 0 && translateMix == 0 && scaleMix == 0 && shearMix == 0) return;
|
||||||
if (data.local) {
|
if (data.local) {
|
||||||
if (data.relative)
|
if (data.relative)
|
||||||
applyRelativeLocal();
|
applyRelativeLocal();
|
||||||
@ -97,7 +94,6 @@ public class TransformConstraint implements Updatable {
|
|||||||
|
|
||||||
private void applyAbsoluteWorld () {
|
private void applyAbsoluteWorld () {
|
||||||
float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
|
float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
|
||||||
if (rotateMix == 0 && translateMix == 0 && scaleMix == 0 && shearMix == 0) return;
|
|
||||||
Bone target = this.target;
|
Bone target = this.target;
|
||||||
float ta = target.a, tb = target.b, tc = target.c, td = target.d;
|
float ta = target.a, tb = target.b, tc = target.c, td = target.d;
|
||||||
float degRadReflect = ta * td - tb * tc > 0 ? degRad : -degRad;
|
float degRadReflect = ta * td - tb * tc > 0 ? degRad : -degRad;
|
||||||
@ -157,7 +153,6 @@ public class TransformConstraint implements Updatable {
|
|||||||
|
|
||||||
private void applyRelativeWorld () {
|
private void applyRelativeWorld () {
|
||||||
float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
|
float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
|
||||||
if (rotateMix == 0 && translateMix == 0 && scaleMix == 0 && shearMix == 0) return;
|
|
||||||
Bone target = this.target;
|
Bone target = this.target;
|
||||||
float ta = target.a, tb = target.b, tc = target.c, td = target.d;
|
float ta = target.a, tb = target.b, tc = target.c, td = target.d;
|
||||||
float degRadReflect = ta * td - tb * tc > 0 ? degRad : -degRad;
|
float degRadReflect = ta * td - tb * tc > 0 ? degRad : -degRad;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user