[libgdx] Nicen things up for porting.

This commit is contained in:
Nathan Sweet 2025-06-12 15:56:13 -04:00
parent 427452c007
commit e2ee1ab458
3 changed files with 26 additions and 22 deletions

View File

@ -7,16 +7,16 @@ abstract public class Posed< //
A extends P> { A extends P> {
final D data; final D data;
final P pose; final A pose;
final A constrained; final A constrained;
A applied; A applied;
public Posed (D data, P pose, A constrained) { public Posed (D data, A pose, A constrained) {
if (data == null) throw new IllegalArgumentException("data cannot be null."); if (data == null) throw new IllegalArgumentException("data cannot be null.");
this.data = data; this.data = data;
this.pose = pose; this.pose = pose;
this.constrained = constrained; this.constrained = constrained;
applied = (A)pose; applied = pose;
} }
public void setupPose () { public void setupPose () {
@ -36,6 +36,18 @@ abstract public class Posed< //
return applied; return applied;
} }
void pose () {
applied = pose;
}
void constrained () {
applied = constrained;
}
void reset () {
constrained.set(pose);
}
public String toString () { public String toString () {
return data.name; return data.name;
} }

View File

@ -9,7 +9,7 @@ abstract public class PosedActive< //
boolean active; boolean active;
public PosedActive (D data, P pose, A constrained) { public PosedActive (D data, A pose, A constrained) {
super(data, pose, constrained); super(data, pose, constrained);
setupPose(); setupPose();
} }

View File

@ -155,10 +155,8 @@ public class Skeleton {
resetCache.clear(); resetCache.clear();
Slot[] slots = this.slots.items; Slot[] slots = this.slots.items;
for (int i = 0, n = this.slots.size; i < n; i++) { for (int i = 0, n = this.slots.size; i < n; i++)
Slot slot = slots[i]; slots[i].pose();
slot.applied = slot.pose;
}
int boneCount = bones.size; int boneCount = bones.size;
Bone[] bones = this.bones.items; Bone[] bones = this.bones.items;
@ -166,7 +164,7 @@ public class Skeleton {
Bone bone = bones[i]; Bone bone = bones[i];
bone.sorted = bone.data.skinRequired; bone.sorted = bone.data.skinRequired;
bone.active = !bone.sorted; bone.active = !bone.sorted;
bone.applied = (BonePose)bone.pose; bone.pose();
} }
if (skin != null) { if (skin != null) {
BoneData[] skinBones = skin.bones.items; BoneData[] skinBones = skin.bones.items;
@ -182,10 +180,8 @@ public class Skeleton {
Constraint[] constraints = this.constraints.items; Constraint[] constraints = this.constraints.items;
int n = this.constraints.size; int n = this.constraints.size;
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++)
Constraint constraint = constraints[i]; constraints[i].pose();
constraint.applied = constraint.pose;
}
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
Constraint<?, ?, ?> constraint = constraints[i]; Constraint<?, ?, ?> constraint = constraints[i];
constraint.active = constraint.isSourceActive() constraint.active = constraint.isSourceActive()
@ -204,7 +200,7 @@ public class Skeleton {
void constrained (Posed object) { void constrained (Posed object) {
if (object.pose == object.applied) { if (object.pose == object.applied) {
object.applied = object.constrained; object.constrained();
resetCache.add(object); resetCache.add(object);
} }
} }
@ -236,10 +232,8 @@ public class Skeleton {
update++; update++;
Posed[] resetCache = this.resetCache.items; Posed[] resetCache = this.resetCache.items;
for (int i = 0, n = this.resetCache.size; i < n; i++) { for (int i = 0, n = this.resetCache.size; i < n; i++)
Posed object = resetCache[i]; resetCache[i].reset();
object.applied.set(object.pose);
}
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++)
@ -257,10 +251,8 @@ public class Skeleton {
update++; update++;
Posed[] resetCache = this.resetCache.items; Posed[] resetCache = this.resetCache.items;
for (int i = 0, n = this.resetCache.size; i < n; i++) { for (int i = 0, n = this.resetCache.size; i < n; i++)
Posed object = resetCache[i]; resetCache[i].reset();
object.applied.set(object.pose);
}
// 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.
BonePose rootBone = getRootBone().applied; BonePose rootBone = getRootBone().applied;