Clean up.

This commit is contained in:
NathanSweet 2014-08-30 17:03:35 +02:00
parent ed55a831d7
commit e81806bb08
5 changed files with 25 additions and 24 deletions

View File

@ -145,7 +145,7 @@ public class Animation {
static public interface Timeline {
/** Sets the value(s) for the specified time.
* @param events May be null. */
* @param events May be null to not collect fired events. */
public void apply (Skeleton skeleton, float lastTime, float time, Array<Event> events, float alpha);
}

View File

@ -91,7 +91,7 @@ public class IkConstraint {
static public void apply (Bone bone, float targetX, float targetY, float alpha) {
float parentRotation = (!bone.data.inheritRotation || bone.parent == null) ? 0 : bone.parent.worldRotation;
float rotation = bone.rotation;
float rotationIK = (float)Math.atan2(targetY - bone.getWorldY(), targetX - bone.getWorldX()) * radDeg - parentRotation;
float rotationIK = (float)Math.atan2(targetY - bone.worldY, targetX - bone.worldX) * radDeg - parentRotation;
bone.rotationIK = rotation + (rotationIK - rotation) * alpha;
}

View File

@ -39,9 +39,9 @@ public class Skeleton {
final SkeletonData data;
final Array<Bone> bones;
final Array<Slot> slots;
Array<Slot> drawOrder;
final Array<IkConstraint> ikConstraints;
private final Array<Array<Bone>> updateBonesCache = new Array();
Array<Slot> drawOrder;
Skin skin;
final Color color;
float time;
@ -365,7 +365,7 @@ public class Skeleton {
}
public void setFlipX (boolean flipX) {
// if (this.flipX == flipX) return;
if (this.flipX == flipX) return;
this.flipX = flipX;
Array<Bone> bones = this.bones;
for (int i = 0, n = bones.size; i < n; i++)
@ -385,6 +385,7 @@ public class Skeleton {
}
public void setFlip (boolean flipX, boolean flipY) {
if (this.flipX == flipX && this.flipY == flipY) return;
Array<Bone> bones = this.bones;
for (int i = 0, n = bones.size; i < n; i++) {
Bone bone = bones.get(i);

View File

@ -128,7 +128,7 @@ public class SkeletonBinary {
boneData.length = input.readFloat() * scale;
boneData.inheritScale = input.readBoolean();
boneData.inheritRotation = input.readBoolean();
if (nonessential) Color.rgba8888ToColor(boneData.getColor(), input.readInt());
if (nonessential) Color.rgba8888ToColor(boneData.color, input.readInt());
skeletonData.bones.add(boneData);
}
@ -148,22 +148,22 @@ public class SkeletonBinary {
String slotName = input.readString();
BoneData boneData = skeletonData.bones.get(input.readInt(true));
SlotData slotData = new SlotData(slotName, boneData);
Color.rgba8888ToColor(slotData.getColor(), input.readInt());
Color.rgba8888ToColor(slotData.color, input.readInt());
slotData.attachmentName = input.readString();
slotData.additiveBlending = input.readBoolean();
skeletonData.getSlots().add(slotData);
skeletonData.slots.add(slotData);
}
// Default skin.
Skin defaultSkin = readSkin(input, "default", nonessential);
if (defaultSkin != null) {
skeletonData.defaultSkin = defaultSkin;
skeletonData.getSkins().add(defaultSkin);
skeletonData.skins.add(defaultSkin);
}
// Skins.
for (int i = 0, n = input.readInt(true); i < n; i++)
skeletonData.getSkins().add(readSkin(input, input.readString(), nonessential));
skeletonData.skins.add(readSkin(input, input.readString(), nonessential));
// Events.
for (int i = 0, n = input.readInt(true); i < n; i++) {
@ -171,7 +171,7 @@ public class SkeletonBinary {
eventData.intValue = input.readInt(false);
eventData.floatValue = input.readFloat();
eventData.stringValue = input.readString();
skeletonData.getEvents().add(eventData);
skeletonData.events.add(eventData);
}
// Animations.
@ -412,7 +412,7 @@ public class SkeletonBinary {
IkConstraintData ikConstraint = skeletonData.findIkConstraint(input.readString());
int frameCount = input.readInt(true);
IkConstraintTimeline timeline = new IkConstraintTimeline(frameCount);
timeline.setIkConstraintIndex(skeletonData.getIkConstraints().indexOf(ikConstraint, true));
timeline.ikConstraintIndex = skeletonData.getIkConstraints().indexOf(ikConstraint, true);
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readByte());
if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
@ -528,7 +528,7 @@ public class SkeletonBinary {
}
timelines.shrink();
skeletonData.getAnimations().add(new Animation(name, timelines, duration));
skeletonData.animations.add(new Animation(name, timelines, duration));
}
private void readCurve (DataInput input, int frameIndex, CurveTimeline timeline) throws IOException {

View File

@ -120,7 +120,7 @@ public class SkeletonJson {
String color = boneMap.getString("color", null);
if (color != null) boneData.getColor().set(Color.valueOf(color));
skeletonData.getBones().add(boneData);
skeletonData.bones.add(boneData);
}
// IK constraints.
@ -131,17 +131,17 @@ public class SkeletonJson {
String boneName = boneMap.asString();
BoneData bone = skeletonData.findBone(boneName);
if (bone == null) throw new SerializationException("IK bone not found: " + boneName);
ikConstraintData.getBones().add(bone);
ikConstraintData.bones.add(bone);
}
String targetName = ikMap.getString("target");
ikConstraintData.setTarget(skeletonData.findBone(targetName));
if (ikConstraintData.getTarget() == null) throw new SerializationException("Target bone not found: " + targetName);
ikConstraintData.target = skeletonData.findBone(targetName);
if (ikConstraintData.target == null) throw new SerializationException("Target bone not found: " + targetName);
ikConstraintData.setBendDirection(ikMap.getBoolean("bendPositive", true) ? 1 : -1);
ikConstraintData.setMix(ikMap.getFloat("mix", 1));
ikConstraintData.bendDirection = ikMap.getBoolean("bendPositive", true) ? 1 : -1;
ikConstraintData.mix = ikMap.getFloat("mix", 1);
skeletonData.getIkConstraints().add(ikConstraintData);
skeletonData.ikConstraints.add(ikConstraintData);
}
// Slots.
@ -159,7 +159,7 @@ public class SkeletonJson {
slotData.additiveBlending = slotMap.getBoolean("additive", false);
skeletonData.getSlots().add(slotData);
skeletonData.slots.add(slotData);
}
// Skins.
@ -173,7 +173,7 @@ public class SkeletonJson {
if (attachment != null) skin.addAttachment(slotIndex, entry.name, attachment);
}
}
skeletonData.getSkins().add(skin);
skeletonData.skins.add(skin);
if (skin.name.equals("default")) skeletonData.defaultSkin = skin;
}
@ -183,7 +183,7 @@ public class SkeletonJson {
eventData.intValue = eventMap.getInt("int", 0);
eventData.floatValue = eventMap.getFloat("float", 0f);
eventData.stringValue = eventMap.getString("string", null);
skeletonData.getEvents().add(eventData);
skeletonData.events.add(eventData);
}
// Animations.
@ -385,7 +385,7 @@ public class SkeletonJson {
for (JsonValue ikMap = map.getChild("ik"); ikMap != null; ikMap = ikMap.next) {
IkConstraintData ikConstraint = skeletonData.findIkConstraint(ikMap.name);
IkConstraintTimeline timeline = new IkConstraintTimeline(ikMap.size);
timeline.setIkConstraintIndex(skeletonData.getIkConstraints().indexOf(ikConstraint, true));
timeline.ikConstraintIndex = skeletonData.getIkConstraints().indexOf(ikConstraint, true);
int frameIndex = 0;
for (JsonValue valueMap = ikMap.child; valueMap != null; valueMap = valueMap.next) {
timeline.setFrame(frameIndex, valueMap.getFloat("time"), valueMap.getFloat("mix"),
@ -507,7 +507,7 @@ public class SkeletonJson {
}
timelines.shrink();
skeletonData.getAnimations().add(new Animation(name, timelines, duration));
skeletonData.animations.add(new Animation(name, timelines, duration));
}
void readCurve (CurveTimeline timeline, int frameIndex, JsonValue valueMap) {