mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-15 11:31:37 +08:00
[libgdx] Store bones indices on animation for sliders.
This commit is contained in:
parent
0f4abc0aab
commit
79d9438132
@ -36,6 +36,7 @@ import static com.esotericsoftware.spine.utils.SpineUtils.*;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
import com.badlogic.gdx.utils.IntArray;
|
||||
import com.badlogic.gdx.utils.Null;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
|
||||
@ -49,15 +50,18 @@ import com.esotericsoftware.spine.attachments.VertexAttachment;
|
||||
/** Stores a list of timelines to animate a skeleton's pose over time. */
|
||||
public class Animation {
|
||||
final String name;
|
||||
float duration;
|
||||
Array<Timeline> timelines;
|
||||
final ObjectSet<String> timelineIds;
|
||||
float duration;
|
||||
final IntArray bones;
|
||||
|
||||
public Animation (String name, Array<Timeline> timelines, float duration) {
|
||||
if (name == null) throw new IllegalArgumentException("name cannot be null.");
|
||||
this.name = name;
|
||||
this.duration = duration;
|
||||
timelineIds = new ObjectSet(timelines.size << 1);
|
||||
int n = timelines.size << 1;
|
||||
timelineIds = new ObjectSet(n);
|
||||
bones = new IntArray(n);
|
||||
setTimelines(timelines);
|
||||
}
|
||||
|
||||
@ -72,9 +76,14 @@ public class Animation {
|
||||
|
||||
int n = timelines.size;
|
||||
timelineIds.clear(n << 1);
|
||||
bones.clear();
|
||||
Timeline[] items = timelines.items;
|
||||
for (int i = 0; i < n; i++)
|
||||
timelineIds.addAll(items[i].getPropertyIds());
|
||||
for (int i = 0; i < n; i++) {
|
||||
Timeline timeline = items[i];
|
||||
timelineIds.addAll(timeline.getPropertyIds());
|
||||
if (timeline instanceof BoneTimeline boneTimeline) bones.add(boneTimeline.getBoneIndex());
|
||||
}
|
||||
bones.shrink();
|
||||
}
|
||||
|
||||
/** Returns true if this animation contains a timeline with any of the specified property IDs. */
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
|
||||
package com.esotericsoftware.spine;
|
||||
|
||||
import com.esotericsoftware.spine.Animation.BoneTimeline;
|
||||
import com.esotericsoftware.spine.Animation.ConstraintTimeline;
|
||||
import com.esotericsoftware.spine.Animation.MixBlend;
|
||||
import com.esotericsoftware.spine.Animation.MixDirection;
|
||||
@ -75,9 +74,9 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
|
||||
|
||||
if (p.mix != 1) {
|
||||
Bone[] bones = skeleton.bones.items;
|
||||
Timeline[] timelines = animation.timelines.items;
|
||||
for (int i = 0, n = animation.timelines.size; i < n; i++)
|
||||
if (timelines[i] instanceof BoneTimeline timeline) bones[timeline.getBoneIndex()].applied.modifyLocal(skeleton);
|
||||
int[] indices = animation.bones.items;
|
||||
for (int i = 0, n = animation.bones.size; i < n; i++)
|
||||
bones[indices[i]].applied.modifyLocal(skeleton);
|
||||
}
|
||||
|
||||
animation.apply(skeleton, p.time, p.time, data.loop, null, p.mix, data.additive ? MixBlend.add : MixBlend.replace,
|
||||
@ -88,20 +87,23 @@ public class Slider extends Constraint<Slider, SliderData, SliderPose> {
|
||||
if (bone != null && !data.local) skeleton.sortBone(bone);
|
||||
skeleton.updateCache.add(this);
|
||||
|
||||
Timeline[] timelines = data.animation.timelines.items;
|
||||
Bone[] bones = skeleton.bones.items;
|
||||
int[] indices = data.animation.bones.items;
|
||||
for (int i = 0, n = data.animation.bones.size; i < n; i++) {
|
||||
Bone bone = bones[indices[i]];
|
||||
bone.sorted = false;
|
||||
skeleton.sortReset(bone.children);
|
||||
skeleton.constrained(bone);
|
||||
}
|
||||
|
||||
Timeline[] timelines = data.animation.timelines.items;
|
||||
Slot[] slots = skeleton.slots.items;
|
||||
Constraint[] constraints = skeleton.constraints.items;
|
||||
PhysicsConstraint[] physics = skeleton.physics.items;
|
||||
int physicsCount = skeleton.physics.size;
|
||||
for (int i = 0, n = data.animation.timelines.size; i < n; i++) {
|
||||
Timeline t = timelines[i];
|
||||
if (t instanceof BoneTimeline timeline) {
|
||||
Bone bone = bones[timeline.getBoneIndex()];
|
||||
bone.sorted = false;
|
||||
skeleton.sortReset(bone.children);
|
||||
skeleton.constrained(bone);
|
||||
} else if (t instanceof SlotTimeline timeline)
|
||||
if (t instanceof SlotTimeline timeline)
|
||||
skeleton.constrained(slots[timeline.getSlotIndex()]);
|
||||
else if (t instanceof PhysicsConstraintTimeline timeline) {
|
||||
if (timeline.constraintIndex == -1) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user