Fixed constraint copy constructors references the wrong bones.

ref #2511
This commit is contained in:
Nathan Sweet 2024-04-29 12:23:22 -04:00
parent c65f73e873
commit cb4873702d
5 changed files with 32 additions and 35 deletions

View File

@ -54,25 +54,24 @@ public class IkConstraint implements Updatable {
if (data == null) throw new IllegalArgumentException("data cannot be null.");
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
this.data = data;
mix = data.mix;
softness = data.softness;
bendDirection = data.bendDirection;
compress = data.compress;
stretch = data.stretch;
bones = new Array(data.bones.size);
for (BoneData boneData : data.bones)
bones.add(skeleton.bones.get(boneData.index));
target = skeleton.bones.get(data.target.index);
mix = data.mix;
softness = data.softness;
bendDirection = data.bendDirection;
compress = data.compress;
stretch = data.stretch;
}
/** Copy constructor. */
public IkConstraint (IkConstraint constraint) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
data = constraint.data;
bones = new Array(constraint.bones);
target = constraint.target;
public IkConstraint (IkConstraint constraint, Skeleton skeleton) {
this(constraint.data, skeleton);
mix = constraint.mix;
softness = constraint.softness;
bendDirection = constraint.bendDirection;

View File

@ -72,6 +72,7 @@ public class PathConstraint implements Updatable {
bones.add(skeleton.bones.get(boneData.index));
target = skeleton.slots.get(data.target.index);
position = data.position;
spacing = data.spacing;
mixRotate = data.mixRotate;
@ -80,11 +81,9 @@ public class PathConstraint implements Updatable {
}
/** Copy constructor. */
public PathConstraint (PathConstraint constraint) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
data = constraint.data;
bones = new Array(constraint.bones);
target = constraint.target;
public PathConstraint (PathConstraint constraint, Skeleton skeleton) {
this(constraint.data, skeleton);
position = constraint.position;
spacing = constraint.spacing;
mixRotate = constraint.mixRotate;

View File

@ -58,7 +58,9 @@ public class PhysicsConstraint implements Updatable {
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
this.data = data;
this.skeleton = skeleton;
bone = skeleton.bones.get(data.bone.index);
inertia = data.inertia;
strength = data.strength;
damping = data.damping;
@ -69,11 +71,9 @@ public class PhysicsConstraint implements Updatable {
}
/** Copy constructor. */
public PhysicsConstraint (PhysicsConstraint constraint) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
data = constraint.data;
skeleton = constraint.skeleton;
bone = constraint.bone;
public PhysicsConstraint (PhysicsConstraint constraint, Skeleton skeleton) {
this(constraint.data, skeleton);
inertia = constraint.inertia;
strength = constraint.strength;
damping = constraint.damping;

View File

@ -139,19 +139,19 @@ public class Skeleton {
ikConstraints = new Array(skeleton.ikConstraints.size);
for (IkConstraint ikConstraint : skeleton.ikConstraints)
ikConstraints.add(new IkConstraint(ikConstraint));
ikConstraints.add(new IkConstraint(ikConstraint, skeleton));
transformConstraints = new Array(skeleton.transformConstraints.size);
for (TransformConstraint transformConstraint : skeleton.transformConstraints)
transformConstraints.add(new TransformConstraint(transformConstraint));
transformConstraints.add(new TransformConstraint(transformConstraint, skeleton));
pathConstraints = new Array(skeleton.pathConstraints.size);
for (PathConstraint pathConstraint : skeleton.pathConstraints)
pathConstraints.add(new PathConstraint(pathConstraint));
pathConstraints.add(new PathConstraint(pathConstraint, skeleton));
physicsConstraints = new Array(skeleton.physicsConstraints.size);
for (PhysicsConstraint physicsConstraint : skeleton.physicsConstraints)
physicsConstraints.add(new PhysicsConstraint(physicsConstraint));
physicsConstraints.add(new PhysicsConstraint(physicsConstraint, skeleton));
skin = skeleton.skin;
color = new Color(skeleton.color);

View File

@ -53,26 +53,25 @@ public class TransformConstraint implements Updatable {
if (data == null) throw new IllegalArgumentException("data cannot be null.");
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
this.data = data;
mixRotate = data.mixRotate;
mixX = data.mixX;
mixY = data.mixY;
mixScaleX = data.mixScaleX;
mixScaleY = data.mixScaleY;
mixShearY = data.mixShearY;
bones = new Array(data.bones.size);
for (BoneData boneData : data.bones)
bones.add(skeleton.bones.get(boneData.index));
target = skeleton.bones.get(data.target.index);
mixRotate = data.mixRotate;
mixX = data.mixX;
mixY = data.mixY;
mixScaleX = data.mixScaleX;
mixScaleY = data.mixScaleY;
mixShearY = data.mixShearY;
}
/** Copy constructor. */
public TransformConstraint (TransformConstraint constraint) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
data = constraint.data;
bones = new Array(constraint.bones);
target = constraint.target;
public TransformConstraint (TransformConstraint constraint, Skeleton skeleton) {
this(constraint.data, skeleton);
mixRotate = constraint.mixRotate;
mixX = constraint.mixX;
mixY = constraint.mixY;