Renamed visible to active. Added isActive to Updatable/bones/constraints.

This commit is contained in:
NathanSweet 2019-05-07 12:16:18 +02:00
parent b3c2170ed2
commit b71970afa6
10 changed files with 51 additions and 17 deletions

View File

@ -349,7 +349,7 @@ public class Animation {
MixDirection direction) {
Bone bone = skeleton.bones.get(boneIndex);
if (!bone.visible) return;
if (!bone.active) return;
float[] frames = this.frames;
if (time < frames[0]) { // Time is before first frame.
switch (blend) {
@ -447,7 +447,7 @@ public class Animation {
MixDirection direction) {
Bone bone = skeleton.bones.get(boneIndex);
if (!bone.visible) return;
if (!bone.active) return;
float[] frames = this.frames;
if (time < frames[0]) { // Time is before first frame.
switch (blend) {
@ -509,7 +509,7 @@ public class Animation {
MixDirection direction) {
Bone bone = skeleton.bones.get(boneIndex);
if (!bone.visible) return;
if (!bone.active) return;
float[] frames = this.frames;
if (time < frames[0]) { // Time is before first frame.
switch (blend) {
@ -612,7 +612,7 @@ public class Animation {
MixDirection direction) {
Bone bone = skeleton.bones.get(boneIndex);
if (!bone.visible) return;
if (!bone.active) return;
float[] frames = this.frames;
if (time < frames[0]) { // Time is before first frame.
switch (blend) {

View File

@ -348,7 +348,7 @@ public class AnimationState {
}
Bone bone = skeleton.bones.get(timeline.boneIndex);
if (!bone.visible) return;
if (!bone.active) return;
float[] frames = timeline.frames;
float r1, r2;
if (time < frames[0]) { // Time is before first frame.

View File

@ -54,7 +54,7 @@ public class Bone implements Updatable {
float a, b, worldX;
float c, d, worldY;
boolean sorted, visible;
boolean sorted, active;
/** @param parent May be null. */
public Bone (BoneData data, Skeleton skeleton, Bone parent) {
@ -235,6 +235,12 @@ public class Bone implements Updatable {
return children;
}
/** Returns false when the bone has not been computed because {@link BoneData#getSkinRequired()} is true and the
* {@link Skeleton#getSkin() active skin} does not {@link Skin#getBones() contain} this bone. */
public boolean isActive () {
return active;
}
// -- Local transform
/** The local x translation. */

View File

@ -45,6 +45,8 @@ public class IkConstraint implements Updatable {
boolean compress, stretch;
float mix = 1;
boolean active;
public IkConstraint (IkConstraintData data, Skeleton skeleton) {
if (data == null) throw new IllegalArgumentException("data cannot be null.");
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
@ -144,6 +146,10 @@ public class IkConstraint implements Updatable {
this.stretch = stretch;
}
public boolean isActive () {
return active;
}
/** The IK constraint's setup pose data. */
public IkConstraintData getData () {
return data;

View File

@ -51,6 +51,8 @@ public class PathConstraint implements Updatable {
Slot target;
float position, spacing, rotateMix, translateMix;
boolean active;
private final FloatArray spaces = new FloatArray(), positions = new FloatArray();
private final FloatArray world = new FloatArray(), curves = new FloatArray(), lengths = new FloatArray();
private final float[] segments = new float[10];
@ -498,6 +500,10 @@ public class PathConstraint implements Updatable {
this.target = target;
}
public boolean isActive () {
return active;
}
/** The path constraint's setup pose data. */
public PathConstraintData getData () {
return data;

View File

@ -166,7 +166,7 @@ public class Skeleton {
for (int i = 0; i < boneCount; i++) {
Bone bone = (Bone)bones[i];
bone.sorted = bone.data.skinRequired;
bone.visible = !bone.sorted;
bone.active = !bone.sorted;
}
if (skin != null) {
Object[] skinBones = skin.bones.items;
@ -174,7 +174,7 @@ public class Skeleton {
Bone bone = (Bone)bones[((BoneData)skinBones[i]).index];
do {
bone.sorted = false;
bone.visible = true;
bone.active = true;
bone = bone.parent;
} while (bone != null);
}
@ -215,7 +215,8 @@ public class Skeleton {
}
private void sortIkConstraint (IkConstraint constraint) {
if (constraint.data.skinRequired && (skin == null || !skin.constraints.contains(constraint.data, true))) return;
constraint.active = !constraint.data.skinRequired || (skin != null && skin.constraints.contains(constraint.data, true));
if (!constraint.active) return;
Bone target = constraint.target;
sortBone(target);
@ -236,7 +237,8 @@ public class Skeleton {
}
private void sortPathConstraint (PathConstraint constraint) {
if (constraint.data.skinRequired && (skin == null || !skin.constraints.contains(constraint.data, true))) return;
constraint.active = !constraint.data.skinRequired || (skin != null && skin.constraints.contains(constraint.data, true));
if (!constraint.active) return;
Slot slot = constraint.target;
int slotIndex = slot.getData().index;
@ -262,7 +264,8 @@ public class Skeleton {
}
private void sortTransformConstraint (TransformConstraint constraint) {
if (constraint.data.skinRequired && (skin == null || !skin.constraints.contains(constraint.data, true))) return;
constraint.active = !constraint.data.skinRequired || (skin != null && skin.constraints.contains(constraint.data, true));
if (!constraint.active) return;
sortBone(constraint.target);
@ -319,7 +322,7 @@ public class Skeleton {
private void sortReset (Array<Bone> bones) {
for (int i = 0, n = bones.size; i < n; i++) {
Bone bone = bones.get(i);
if (!bone.visible) continue;
if (!bone.active) continue;
if (bone.sorted) sortReset(bone.children);
bone.sorted = false;
}

View File

@ -88,7 +88,7 @@ public class SkeletonRenderer {
Array<Slot> drawOrder = skeleton.drawOrder;
for (int i = 0, n = drawOrder.size; i < n; i++) {
Slot slot = drawOrder.get(i);
if (!slot.bone.visible) continue;
if (!slot.bone.active) continue;
Attachment attachment = slot.attachment;
if (attachment instanceof RegionAttachment) {
RegionAttachment region = (RegionAttachment)attachment;
@ -167,7 +167,7 @@ public class SkeletonRenderer {
Array<Slot> drawOrder = skeleton.drawOrder;
for (int i = 0, n = drawOrder.size; i < n; i++) {
Slot slot = drawOrder.get(i);
if (!slot.bone.visible) continue;
if (!slot.bone.active) continue;
Texture texture = null;
int vertexSize = clipper.isClipping() ? 2 : 5;
Attachment attachment = slot.attachment;
@ -291,7 +291,7 @@ public class SkeletonRenderer {
Array<Slot> drawOrder = skeleton.drawOrder;
for (int i = 0, n = drawOrder.size; i < n; i++) {
Slot slot = drawOrder.get(i);
if (!slot.bone.visible) continue;
if (!slot.bone.active) continue;
Texture texture = null;
int vertexSize = clipper.isClipping() ? 2 : 6;
Attachment attachment = slot.attachment;

View File

@ -84,7 +84,7 @@ public class SkeletonRendererDebug {
if (drawBones) {
for (int i = 0, n = bones.size; i < n; i++) {
Bone bone = bones.get(i);
if (bone.parent == null || !bone.visible) continue;
if (bone.parent == null || !bone.active) continue;
float length = bone.data.length, width = boneWidth;
if (length == 0) {
length = 8;
@ -239,7 +239,7 @@ public class SkeletonRendererDebug {
shapes.setColor(boneOriginColor);
for (int i = 0, n = bones.size; i < n; i++) {
Bone bone = bones.get(i);
if (!bone.visible) continue;
if (!bone.active) continue;
shapes.circle(bone.worldX, bone.worldY, 3 * scale, 8);
}
}

View File

@ -43,6 +43,8 @@ public class TransformConstraint implements Updatable {
final Array<Bone> bones;
Bone target;
float rotateMix, translateMix, scaleMix, shearMix;
boolean active;
final Vector2 temp = new Vector2();
public TransformConstraint (TransformConstraintData data, Skeleton skeleton) {
@ -338,6 +340,10 @@ public class TransformConstraint implements Updatable {
this.shearMix = shearMix;
}
public boolean isActive () {
return active;
}
/** The transform constraint's setup pose data. */
public TransformConstraintData getData () {
return data;

View File

@ -29,6 +29,13 @@
package com.esotericsoftware.spine;
/** The interface for items updated by {@link Skeleton#updateWorldTransform()}. */
public interface Updatable {
public void update ();
/** Returns false when this item has not been updated because a skine is required and the {@link Skeleton#getSkin() active
* skin} does not contain this item.
* @see Skin#getBones()
* @see Skin#getConstraints() */
public boolean isActive ();
}